@@ -1,1325 +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 | from multiprocessing import Process, Queue, cpu_count |
|
11 | from multiprocessing import Process, Queue, cpu_count | |
12 |
|
12 | |||
13 | import schainpy |
|
13 | import schainpy | |
14 | import schainpy.admin |
|
14 | import schainpy.admin | |
15 |
|
15 | |||
16 | from xml.etree.ElementTree import ElementTree, Element, SubElement, tostring |
|
16 | from xml.etree.ElementTree import ElementTree, Element, SubElement, tostring | |
17 | from xml.dom import minidom |
|
17 | from xml.dom import minidom | |
18 |
|
18 | |||
19 | from schainpy.model import * |
|
19 | from schainpy.model import * | |
20 | from time import sleep |
|
20 | from time import sleep | |
21 |
|
21 | |||
22 | def prettify(elem): |
|
22 | def prettify(elem): | |
23 | """Return a pretty-printed XML string for the Element. |
|
23 | """Return a pretty-printed XML string for the Element. | |
24 | """ |
|
24 | """ | |
25 | rough_string = tostring(elem, 'utf-8') |
|
25 | rough_string = tostring(elem, 'utf-8') | |
26 | reparsed = minidom.parseString(rough_string) |
|
26 | reparsed = minidom.parseString(rough_string) | |
27 | return reparsed.toprettyxml(indent=" ") |
|
27 | return reparsed.toprettyxml(indent=" ") | |
28 |
|
28 | |||
29 | def multiSchain(child, nProcess=cpu_count(), startDate=None, endDate=None, by_day=False): |
|
29 | def multiSchain(child, nProcess=cpu_count(), startDate=None, endDate=None, by_day=False): | |
30 | skip = 0 |
|
30 | skip = 0 | |
31 | cursor = 0 |
|
31 | cursor = 0 | |
32 | nFiles = None |
|
32 | nFiles = None | |
33 | processes = [] |
|
33 | processes = [] | |
34 |
|
||||
35 |
|
||||
36 |
|
||||
37 |
|
||||
38 | dt1 = datetime.datetime.strptime(startDate, '%Y/%m/%d') |
|
34 | dt1 = datetime.datetime.strptime(startDate, '%Y/%m/%d') | |
39 | dt2 = datetime.datetime.strptime(endDate, '%Y/%m/%d') |
|
35 | dt2 = datetime.datetime.strptime(endDate, '%Y/%m/%d') | |
40 | days = (dt2 - dt1).days |
|
36 | days = (dt2 - dt1).days | |
41 |
|
37 | |||
42 | for day in range(days+1): |
|
38 | for day in range(days+1): | |
43 | skip = 0 |
|
39 | skip = 0 | |
44 | cursor = 0 |
|
40 | cursor = 0 | |
45 | q = Queue() |
|
41 | q = Queue() | |
46 | processes = [] |
|
42 | processes = [] | |
47 | dt = (dt1 + datetime.timedelta(day)).strftime('%Y/%m/%d') |
|
43 | dt = (dt1 + datetime.timedelta(day)).strftime('%Y/%m/%d') | |
48 | firstProcess = Process(target=child, args=(cursor, skip, q, dt)) |
|
44 | firstProcess = Process(target=child, args=(cursor, skip, q, dt)) | |
49 | firstProcess.start() |
|
45 | firstProcess.start() | |
50 | if by_day: |
|
46 | if by_day: | |
51 | continue |
|
47 | continue | |
52 | nFiles = q.get() |
|
48 | nFiles = q.get() | |
53 | firstProcess.terminate() |
|
49 | firstProcess.terminate() | |
54 | skip = int(math.ceil(nFiles/nProcess)) |
|
50 | skip = int(math.ceil(nFiles/nProcess)) | |
55 | while True: |
|
51 | while True: | |
56 | processes.append(Process(target=child, args=(cursor, skip, q, dt))) |
|
52 | processes.append(Process(target=child, args=(cursor, skip, q, dt))) | |
57 | processes[cursor].start() |
|
53 | processes[cursor].start() | |
58 | if nFiles < cursor*skip: |
|
54 | if nFiles < cursor*skip: | |
59 | break |
|
55 | break | |
60 | cursor += 1 |
|
56 | cursor += 1 | |
61 |
|
57 | |||
62 | def beforeExit(exctype, value, trace): |
|
58 | def beforeExit(exctype, value, trace): | |
63 | for process in processes: |
|
59 | for process in processes: | |
64 | process.terminate() |
|
60 | process.terminate() | |
65 | process.join() |
|
61 | process.join() | |
66 | print traceback.print_tb(trace) |
|
62 | print traceback.print_tb(trace) | |
67 |
|
63 | |||
68 | sys.excepthook = beforeExit |
|
64 | sys.excepthook = beforeExit | |
69 |
|
65 | |||
70 | for process in processes: |
|
66 | for process in processes: | |
71 | process.join() |
|
67 | process.join() | |
72 | process.terminate() |
|
68 | process.terminate() | |
73 | sys.exit() |
|
69 | sys.exit() | |
74 |
|
70 | |||
75 |
|
71 | |||
76 | class ParameterConf(): |
|
72 | class ParameterConf(): | |
77 |
|
73 | |||
78 | id = None |
|
74 | id = None | |
79 | name = None |
|
75 | name = None | |
80 | value = None |
|
76 | value = None | |
81 | format = None |
|
77 | format = None | |
82 |
|
78 | |||
83 | __formated_value = None |
|
79 | __formated_value = None | |
84 |
|
80 | |||
85 | ELEMENTNAME = 'Parameter' |
|
81 | ELEMENTNAME = 'Parameter' | |
86 |
|
82 | |||
87 | def __init__(self): |
|
83 | def __init__(self): | |
88 |
|
84 | |||
89 | self.format = 'str' |
|
85 | self.format = 'str' | |
90 |
|
86 | |||
91 | def getElementName(self): |
|
87 | def getElementName(self): | |
92 |
|
88 | |||
93 | return self.ELEMENTNAME |
|
89 | return self.ELEMENTNAME | |
94 |
|
90 | |||
95 | def getValue(self): |
|
91 | def getValue(self): | |
96 |
|
92 | |||
97 | value = self.value |
|
93 | value = self.value | |
98 | format = self.format |
|
94 | format = self.format | |
99 |
|
95 | |||
100 | if self.__formated_value != None: |
|
96 | if self.__formated_value != None: | |
101 |
|
97 | |||
102 | return self.__formated_value |
|
98 | return self.__formated_value | |
103 |
|
99 | |||
104 | if format == 'obj': |
|
100 | if format == 'obj': | |
105 | return value |
|
101 | return value | |
106 |
|
102 | |||
107 | if format == 'str': |
|
103 | if format == 'str': | |
108 | self.__formated_value = str(value) |
|
104 | self.__formated_value = str(value) | |
109 | return self.__formated_value |
|
105 | return self.__formated_value | |
110 |
|
106 | |||
111 | if value == '': |
|
107 | if value == '': | |
112 | raise ValueError, "%s: This parameter value is empty" %self.name |
|
108 | raise ValueError, "%s: This parameter value is empty" %self.name | |
113 |
|
109 | |||
114 | if format == 'list': |
|
110 | if format == 'list': | |
115 | strList = value.split(',') |
|
111 | strList = value.split(',') | |
116 |
|
112 | |||
117 | self.__formated_value = strList |
|
113 | self.__formated_value = strList | |
118 |
|
114 | |||
119 | return self.__formated_value |
|
115 | return self.__formated_value | |
120 |
|
116 | |||
121 | if format == 'intlist': |
|
117 | if format == 'intlist': | |
122 | """ |
|
118 | """ | |
123 | Example: |
|
119 | Example: | |
124 | value = (0,1,2) |
|
120 | value = (0,1,2) | |
125 | """ |
|
121 | """ | |
126 |
|
122 | |||
127 | new_value = ast.literal_eval(value) |
|
123 | new_value = ast.literal_eval(value) | |
128 |
|
124 | |||
129 | if type(new_value) not in (tuple, list): |
|
125 | if type(new_value) not in (tuple, list): | |
130 | new_value = [int(new_value)] |
|
126 | new_value = [int(new_value)] | |
131 |
|
127 | |||
132 | self.__formated_value = new_value |
|
128 | self.__formated_value = new_value | |
133 |
|
129 | |||
134 | return self.__formated_value |
|
130 | return self.__formated_value | |
135 |
|
131 | |||
136 | if format == 'floatlist': |
|
132 | if format == 'floatlist': | |
137 | """ |
|
133 | """ | |
138 | Example: |
|
134 | Example: | |
139 | value = (0.5, 1.4, 2.7) |
|
135 | value = (0.5, 1.4, 2.7) | |
140 | """ |
|
136 | """ | |
141 |
|
137 | |||
142 | new_value = ast.literal_eval(value) |
|
138 | new_value = ast.literal_eval(value) | |
143 |
|
139 | |||
144 | if type(new_value) not in (tuple, list): |
|
140 | if type(new_value) not in (tuple, list): | |
145 | new_value = [float(new_value)] |
|
141 | new_value = [float(new_value)] | |
146 |
|
142 | |||
147 | self.__formated_value = new_value |
|
143 | self.__formated_value = new_value | |
148 |
|
144 | |||
149 | return self.__formated_value |
|
145 | return self.__formated_value | |
150 |
|
146 | |||
151 | if format == 'date': |
|
147 | if format == 'date': | |
152 | strList = value.split('/') |
|
148 | strList = value.split('/') | |
153 | intList = [int(x) for x in strList] |
|
149 | intList = [int(x) for x in strList] | |
154 | date = datetime.date(intList[0], intList[1], intList[2]) |
|
150 | date = datetime.date(intList[0], intList[1], intList[2]) | |
155 |
|
151 | |||
156 | self.__formated_value = date |
|
152 | self.__formated_value = date | |
157 |
|
153 | |||
158 | return self.__formated_value |
|
154 | return self.__formated_value | |
159 |
|
155 | |||
160 | if format == 'time': |
|
156 | if format == 'time': | |
161 | strList = value.split(':') |
|
157 | strList = value.split(':') | |
162 | intList = [int(x) for x in strList] |
|
158 | intList = [int(x) for x in strList] | |
163 | time = datetime.time(intList[0], intList[1], intList[2]) |
|
159 | time = datetime.time(intList[0], intList[1], intList[2]) | |
164 |
|
160 | |||
165 | self.__formated_value = time |
|
161 | self.__formated_value = time | |
166 |
|
162 | |||
167 | return self.__formated_value |
|
163 | return self.__formated_value | |
168 |
|
164 | |||
169 | if format == 'pairslist': |
|
165 | if format == 'pairslist': | |
170 | """ |
|
166 | """ | |
171 | Example: |
|
167 | Example: | |
172 | value = (0,1),(1,2) |
|
168 | value = (0,1),(1,2) | |
173 | """ |
|
169 | """ | |
174 |
|
170 | |||
175 | new_value = ast.literal_eval(value) |
|
171 | new_value = ast.literal_eval(value) | |
176 |
|
172 | |||
177 | if type(new_value) not in (tuple, list): |
|
173 | if type(new_value) not in (tuple, list): | |
178 | 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 | |
179 |
|
175 | |||
180 | if type(new_value[0]) not in (tuple, list): |
|
176 | if type(new_value[0]) not in (tuple, list): | |
181 | if len(new_value) != 2: |
|
177 | if len(new_value) != 2: | |
182 | 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 | |
183 | new_value = [new_value] |
|
179 | new_value = [new_value] | |
184 |
|
180 | |||
185 | for thisPair in new_value: |
|
181 | for thisPair in new_value: | |
186 | if len(thisPair) != 2: |
|
182 | if len(thisPair) != 2: | |
187 | 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 | |
188 |
|
184 | |||
189 | self.__formated_value = new_value |
|
185 | self.__formated_value = new_value | |
190 |
|
186 | |||
191 | return self.__formated_value |
|
187 | return self.__formated_value | |
192 |
|
188 | |||
193 | if format == 'multilist': |
|
189 | if format == 'multilist': | |
194 | """ |
|
190 | """ | |
195 | Example: |
|
191 | Example: | |
196 | value = (0,1,2),(3,4,5) |
|
192 | value = (0,1,2),(3,4,5) | |
197 | """ |
|
193 | """ | |
198 | multiList = ast.literal_eval(value) |
|
194 | multiList = ast.literal_eval(value) | |
199 |
|
195 | |||
200 | if type(multiList[0]) == int: |
|
196 | if type(multiList[0]) == int: | |
201 | multiList = ast.literal_eval("(" + value + ")") |
|
197 | multiList = ast.literal_eval("(" + value + ")") | |
202 |
|
198 | |||
203 | self.__formated_value = multiList |
|
199 | self.__formated_value = multiList | |
204 |
|
200 | |||
205 | return self.__formated_value |
|
201 | return self.__formated_value | |
206 |
|
202 | |||
207 | if format == 'bool': |
|
203 | if format == 'bool': | |
208 | value = int(value) |
|
204 | value = int(value) | |
209 |
|
205 | |||
210 | if format == 'int': |
|
206 | if format == 'int': | |
211 | value = float(value) |
|
207 | value = float(value) | |
212 |
|
208 | |||
213 | format_func = eval(format) |
|
209 | format_func = eval(format) | |
214 |
|
210 | |||
215 | self.__formated_value = format_func(value) |
|
211 | self.__formated_value = format_func(value) | |
216 |
|
212 | |||
217 | return self.__formated_value |
|
213 | return self.__formated_value | |
218 |
|
214 | |||
219 | def updateId(self, new_id): |
|
215 | def updateId(self, new_id): | |
220 |
|
216 | |||
221 | self.id = str(new_id) |
|
217 | self.id = str(new_id) | |
222 |
|
218 | |||
223 | def setup(self, id, name, value, format='str'): |
|
219 | def setup(self, id, name, value, format='str'): | |
224 |
|
220 | |||
225 | self.id = str(id) |
|
221 | self.id = str(id) | |
226 | self.name = name |
|
222 | self.name = name | |
227 | if format == 'obj': |
|
223 | if format == 'obj': | |
228 | self.value = value |
|
224 | self.value = value | |
229 | else: |
|
225 | else: | |
230 | self.value = str(value) |
|
226 | self.value = str(value) | |
231 | self.format = str.lower(format) |
|
227 | self.format = str.lower(format) | |
232 |
|
228 | |||
233 | self.getValue() |
|
229 | self.getValue() | |
234 |
|
230 | |||
235 | return 1 |
|
231 | return 1 | |
236 |
|
232 | |||
237 | def update(self, name, value, format='str'): |
|
233 | def update(self, name, value, format='str'): | |
238 |
|
234 | |||
239 | self.name = name |
|
235 | self.name = name | |
240 | self.value = str(value) |
|
236 | self.value = str(value) | |
241 | self.format = format |
|
237 | self.format = format | |
242 |
|
238 | |||
243 | def makeXml(self, opElement): |
|
239 | def makeXml(self, opElement): | |
244 | if self.name not in ('queue',): |
|
240 | if self.name not in ('queue',): | |
245 | parmElement = SubElement(opElement, self.ELEMENTNAME) |
|
241 | parmElement = SubElement(opElement, self.ELEMENTNAME) | |
246 | parmElement.set('id', str(self.id)) |
|
242 | parmElement.set('id', str(self.id)) | |
247 | parmElement.set('name', self.name) |
|
243 | parmElement.set('name', self.name) | |
248 | parmElement.set('value', self.value) |
|
244 | parmElement.set('value', self.value) | |
249 | parmElement.set('format', self.format) |
|
245 | parmElement.set('format', self.format) | |
250 |
|
246 | |||
251 | def readXml(self, parmElement): |
|
247 | def readXml(self, parmElement): | |
252 |
|
248 | |||
253 | self.id = parmElement.get('id') |
|
249 | self.id = parmElement.get('id') | |
254 | self.name = parmElement.get('name') |
|
250 | self.name = parmElement.get('name') | |
255 | self.value = parmElement.get('value') |
|
251 | self.value = parmElement.get('value') | |
256 | self.format = str.lower(parmElement.get('format')) |
|
252 | self.format = str.lower(parmElement.get('format')) | |
257 |
|
253 | |||
258 | #Compatible with old signal chain version |
|
254 | #Compatible with old signal chain version | |
259 | if self.format == 'int' and self.name == 'idfigure': |
|
255 | if self.format == 'int' and self.name == 'idfigure': | |
260 | self.name = 'id' |
|
256 | self.name = 'id' | |
261 |
|
257 | |||
262 | def printattr(self): |
|
258 | def printattr(self): | |
263 |
|
259 | |||
264 | 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) | |
265 |
|
261 | |||
266 | class OperationConf(): |
|
262 | class OperationConf(): | |
267 |
|
263 | |||
268 | id = None |
|
264 | id = None | |
269 | name = None |
|
265 | name = None | |
270 | priority = None |
|
266 | priority = None | |
271 | type = None |
|
267 | type = None | |
272 |
|
268 | |||
273 | parmConfObjList = [] |
|
269 | parmConfObjList = [] | |
274 |
|
270 | |||
275 | ELEMENTNAME = 'Operation' |
|
271 | ELEMENTNAME = 'Operation' | |
276 |
|
272 | |||
277 | def __init__(self): |
|
273 | def __init__(self): | |
278 |
|
274 | |||
279 | self.id = '0' |
|
275 | self.id = '0' | |
280 | self.name = None |
|
276 | self.name = None | |
281 | self.priority = None |
|
277 | self.priority = None | |
282 | self.type = 'self' |
|
278 | self.type = 'self' | |
283 |
|
279 | |||
284 |
|
280 | |||
285 | def __getNewId(self): |
|
281 | def __getNewId(self): | |
286 |
|
282 | |||
287 | return int(self.id)*10 + len(self.parmConfObjList) + 1 |
|
283 | return int(self.id)*10 + len(self.parmConfObjList) + 1 | |
288 |
|
284 | |||
289 | def updateId(self, new_id): |
|
285 | def updateId(self, new_id): | |
290 |
|
286 | |||
291 | self.id = str(new_id) |
|
287 | self.id = str(new_id) | |
292 |
|
288 | |||
293 | n = 1 |
|
289 | n = 1 | |
294 | for parmObj in self.parmConfObjList: |
|
290 | for parmObj in self.parmConfObjList: | |
295 |
|
291 | |||
296 | idParm = str(int(new_id)*10 + n) |
|
292 | idParm = str(int(new_id)*10 + n) | |
297 | parmObj.updateId(idParm) |
|
293 | parmObj.updateId(idParm) | |
298 |
|
294 | |||
299 | n += 1 |
|
295 | n += 1 | |
300 |
|
296 | |||
301 | def getElementName(self): |
|
297 | def getElementName(self): | |
302 |
|
298 | |||
303 | return self.ELEMENTNAME |
|
299 | return self.ELEMENTNAME | |
304 |
|
300 | |||
305 | def getParameterObjList(self): |
|
301 | def getParameterObjList(self): | |
306 |
|
302 | |||
307 | return self.parmConfObjList |
|
303 | return self.parmConfObjList | |
308 |
|
304 | |||
309 | def getParameterObj(self, parameterName): |
|
305 | def getParameterObj(self, parameterName): | |
310 |
|
306 | |||
311 | for parmConfObj in self.parmConfObjList: |
|
307 | for parmConfObj in self.parmConfObjList: | |
312 |
|
308 | |||
313 | if parmConfObj.name != parameterName: |
|
309 | if parmConfObj.name != parameterName: | |
314 | continue |
|
310 | continue | |
315 |
|
311 | |||
316 | return parmConfObj |
|
312 | return parmConfObj | |
317 |
|
313 | |||
318 | return None |
|
314 | return None | |
319 |
|
315 | |||
320 | def getParameterObjfromValue(self, parameterValue): |
|
316 | def getParameterObjfromValue(self, parameterValue): | |
321 |
|
317 | |||
322 | for parmConfObj in self.parmConfObjList: |
|
318 | for parmConfObj in self.parmConfObjList: | |
323 |
|
319 | |||
324 | if parmConfObj.getValue() != parameterValue: |
|
320 | if parmConfObj.getValue() != parameterValue: | |
325 | continue |
|
321 | continue | |
326 |
|
322 | |||
327 | return parmConfObj.getValue() |
|
323 | return parmConfObj.getValue() | |
328 |
|
324 | |||
329 | return None |
|
325 | return None | |
330 |
|
326 | |||
331 | def getParameterValue(self, parameterName): |
|
327 | def getParameterValue(self, parameterName): | |
332 |
|
328 | |||
333 | parameterObj = self.getParameterObj(parameterName) |
|
329 | parameterObj = self.getParameterObj(parameterName) | |
334 |
|
330 | |||
335 | # if not parameterObj: |
|
331 | # if not parameterObj: | |
336 | # return None |
|
332 | # return None | |
337 |
|
333 | |||
338 | value = parameterObj.getValue() |
|
334 | value = parameterObj.getValue() | |
339 |
|
335 | |||
340 | return value |
|
336 | return value | |
341 |
|
337 | |||
342 |
|
338 | |||
343 | def getKwargs(self): |
|
339 | def getKwargs(self): | |
344 |
|
340 | |||
345 | kwargs = {} |
|
341 | kwargs = {} | |
346 |
|
342 | |||
347 | for parmConfObj in self.parmConfObjList: |
|
343 | for parmConfObj in self.parmConfObjList: | |
348 | if self.name == 'run' and parmConfObj.name == 'datatype': |
|
344 | if self.name == 'run' and parmConfObj.name == 'datatype': | |
349 | continue |
|
345 | continue | |
350 |
|
346 | |||
351 | kwargs[parmConfObj.name] = parmConfObj.getValue() |
|
347 | kwargs[parmConfObj.name] = parmConfObj.getValue() | |
352 |
|
348 | |||
353 | return kwargs |
|
349 | return kwargs | |
354 |
|
350 | |||
355 | def setup(self, id, name, priority, type): |
|
351 | def setup(self, id, name, priority, type): | |
356 |
|
352 | |||
357 | self.id = str(id) |
|
353 | self.id = str(id) | |
358 | self.name = name |
|
354 | self.name = name | |
359 | self.type = type |
|
355 | self.type = type | |
360 | self.priority = priority |
|
356 | self.priority = priority | |
361 |
|
357 | |||
362 | self.parmConfObjList = [] |
|
358 | self.parmConfObjList = [] | |
363 |
|
359 | |||
364 | def removeParameters(self): |
|
360 | def removeParameters(self): | |
365 |
|
361 | |||
366 | for obj in self.parmConfObjList: |
|
362 | for obj in self.parmConfObjList: | |
367 | del obj |
|
363 | del obj | |
368 |
|
364 | |||
369 | self.parmConfObjList = [] |
|
365 | self.parmConfObjList = [] | |
370 |
|
366 | |||
371 | def addParameter(self, name, value, format='str'): |
|
367 | def addParameter(self, name, value, format='str'): | |
372 |
|
368 | |||
373 | id = self.__getNewId() |
|
369 | id = self.__getNewId() | |
374 |
|
370 | |||
375 | parmConfObj = ParameterConf() |
|
371 | parmConfObj = ParameterConf() | |
376 | if not parmConfObj.setup(id, name, value, format): |
|
372 | if not parmConfObj.setup(id, name, value, format): | |
377 | return None |
|
373 | return None | |
378 |
|
374 | |||
379 | self.parmConfObjList.append(parmConfObj) |
|
375 | self.parmConfObjList.append(parmConfObj) | |
380 |
|
376 | |||
381 | return parmConfObj |
|
377 | return parmConfObj | |
382 |
|
378 | |||
383 | def changeParameter(self, name, value, format='str'): |
|
379 | def changeParameter(self, name, value, format='str'): | |
384 |
|
380 | |||
385 | parmConfObj = self.getParameterObj(name) |
|
381 | parmConfObj = self.getParameterObj(name) | |
386 | parmConfObj.update(name, value, format) |
|
382 | parmConfObj.update(name, value, format) | |
387 |
|
383 | |||
388 | return parmConfObj |
|
384 | return parmConfObj | |
389 |
|
385 | |||
390 | def makeXml(self, procUnitElement): |
|
386 | def makeXml(self, procUnitElement): | |
391 |
|
387 | |||
392 | opElement = SubElement(procUnitElement, self.ELEMENTNAME) |
|
388 | opElement = SubElement(procUnitElement, self.ELEMENTNAME) | |
393 | opElement.set('id', str(self.id)) |
|
389 | opElement.set('id', str(self.id)) | |
394 | opElement.set('name', self.name) |
|
390 | opElement.set('name', self.name) | |
395 | opElement.set('type', self.type) |
|
391 | opElement.set('type', self.type) | |
396 | opElement.set('priority', str(self.priority)) |
|
392 | opElement.set('priority', str(self.priority)) | |
397 |
|
393 | |||
398 | for parmConfObj in self.parmConfObjList: |
|
394 | for parmConfObj in self.parmConfObjList: | |
399 | parmConfObj.makeXml(opElement) |
|
395 | parmConfObj.makeXml(opElement) | |
400 |
|
396 | |||
401 | def readXml(self, opElement): |
|
397 | def readXml(self, opElement): | |
402 |
|
398 | |||
403 | self.id = opElement.get('id') |
|
399 | self.id = opElement.get('id') | |
404 | self.name = opElement.get('name') |
|
400 | self.name = opElement.get('name') | |
405 | self.type = opElement.get('type') |
|
401 | self.type = opElement.get('type') | |
406 | self.priority = opElement.get('priority') |
|
402 | self.priority = opElement.get('priority') | |
407 |
|
403 | |||
408 | #Compatible with old signal chain version |
|
404 | #Compatible with old signal chain version | |
409 | #Use of 'run' method instead 'init' |
|
405 | #Use of 'run' method instead 'init' | |
410 | if self.type == 'self' and self.name == 'init': |
|
406 | if self.type == 'self' and self.name == 'init': | |
411 | self.name = 'run' |
|
407 | self.name = 'run' | |
412 |
|
408 | |||
413 | self.parmConfObjList = [] |
|
409 | self.parmConfObjList = [] | |
414 |
|
410 | |||
415 | parmElementList = opElement.iter(ParameterConf().getElementName()) |
|
411 | parmElementList = opElement.iter(ParameterConf().getElementName()) | |
416 |
|
412 | |||
417 | for parmElement in parmElementList: |
|
413 | for parmElement in parmElementList: | |
418 | parmConfObj = ParameterConf() |
|
414 | parmConfObj = ParameterConf() | |
419 | parmConfObj.readXml(parmElement) |
|
415 | parmConfObj.readXml(parmElement) | |
420 |
|
416 | |||
421 | #Compatible with old signal chain version |
|
417 | #Compatible with old signal chain version | |
422 | #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 | |
423 | if self.type != 'self' and self.name == 'Plot': |
|
419 | if self.type != 'self' and self.name == 'Plot': | |
424 | if parmConfObj.format == 'str' and parmConfObj.name == 'type': |
|
420 | if parmConfObj.format == 'str' and parmConfObj.name == 'type': | |
425 | self.name = parmConfObj.value |
|
421 | self.name = parmConfObj.value | |
426 | continue |
|
422 | continue | |
427 |
|
423 | |||
428 | self.parmConfObjList.append(parmConfObj) |
|
424 | self.parmConfObjList.append(parmConfObj) | |
429 |
|
425 | |||
430 | def printattr(self): |
|
426 | def printattr(self): | |
431 |
|
427 | |||
432 | print "%s[%s]: name = %s, type = %s, priority = %s" %(self.ELEMENTNAME, |
|
428 | print "%s[%s]: name = %s, type = %s, priority = %s" %(self.ELEMENTNAME, | |
433 | self.id, |
|
429 | self.id, | |
434 | self.name, |
|
430 | self.name, | |
435 | self.type, |
|
431 | self.type, | |
436 | self.priority) |
|
432 | self.priority) | |
437 |
|
433 | |||
438 | for parmConfObj in self.parmConfObjList: |
|
434 | for parmConfObj in self.parmConfObjList: | |
439 | parmConfObj.printattr() |
|
435 | parmConfObj.printattr() | |
440 |
|
436 | |||
441 | def createObject(self, plotter_queue=None): |
|
437 | def createObject(self, plotter_queue=None): | |
442 |
|
438 | |||
443 |
|
439 | |||
444 | if self.type == 'self': |
|
440 | if self.type == 'self': | |
445 | raise ValueError, "This operation type cannot be created" |
|
441 | raise ValueError, "This operation type cannot be created" | |
446 |
|
442 | |||
447 | if self.type == 'plotter': |
|
443 | if self.type == 'plotter': | |
448 | #Plotter(plotter_name) |
|
444 | #Plotter(plotter_name) | |
449 | if not plotter_queue: |
|
445 | if not plotter_queue: | |
450 | 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)" | |
451 |
|
447 | |||
452 | opObj = Plotter(self.name, plotter_queue) |
|
448 | opObj = Plotter(self.name, plotter_queue) | |
453 |
|
449 | |||
454 | if self.type == 'external' or self.type == 'other': |
|
450 | if self.type == 'external' or self.type == 'other': | |
455 |
|
451 | |||
456 | className = eval(self.name) |
|
452 | className = eval(self.name) | |
457 | kwargs = self.getKwargs() |
|
453 | kwargs = self.getKwargs() | |
458 |
|
454 | |||
459 | opObj = className(**kwargs) |
|
455 | opObj = className(**kwargs) | |
460 |
|
456 | |||
461 | return opObj |
|
457 | return opObj | |
462 |
|
458 | |||
463 |
|
459 | |||
464 | class ProcUnitConf(): |
|
460 | class ProcUnitConf(): | |
465 |
|
461 | |||
466 | id = None |
|
462 | id = None | |
467 | name = None |
|
463 | name = None | |
468 | datatype = None |
|
464 | datatype = None | |
469 | inputId = None |
|
465 | inputId = None | |
470 | parentId = None |
|
466 | parentId = None | |
471 |
|
467 | |||
472 | opConfObjList = [] |
|
468 | opConfObjList = [] | |
473 |
|
469 | |||
474 | procUnitObj = None |
|
470 | procUnitObj = None | |
475 | opObjList = [] |
|
471 | opObjList = [] | |
476 |
|
472 | |||
477 | ELEMENTNAME = 'ProcUnit' |
|
473 | ELEMENTNAME = 'ProcUnit' | |
478 |
|
474 | |||
479 | def __init__(self): |
|
475 | def __init__(self): | |
480 |
|
476 | |||
481 | self.id = None |
|
477 | self.id = None | |
482 | self.datatype = None |
|
478 | self.datatype = None | |
483 | self.name = None |
|
479 | self.name = None | |
484 | self.inputId = None |
|
480 | self.inputId = None | |
485 |
|
481 | |||
486 | self.opConfObjList = [] |
|
482 | self.opConfObjList = [] | |
487 |
|
483 | |||
488 | self.procUnitObj = None |
|
484 | self.procUnitObj = None | |
489 | self.opObjDict = {} |
|
485 | self.opObjDict = {} | |
490 |
|
486 | |||
491 | def __getPriority(self): |
|
487 | def __getPriority(self): | |
492 |
|
488 | |||
493 | return len(self.opConfObjList)+1 |
|
489 | return len(self.opConfObjList)+1 | |
494 |
|
490 | |||
495 | def __getNewId(self): |
|
491 | def __getNewId(self): | |
496 |
|
492 | |||
497 | return int(self.id)*10 + len(self.opConfObjList) + 1 |
|
493 | return int(self.id)*10 + len(self.opConfObjList) + 1 | |
498 |
|
494 | |||
499 | def getElementName(self): |
|
495 | def getElementName(self): | |
500 |
|
496 | |||
501 | return self.ELEMENTNAME |
|
497 | return self.ELEMENTNAME | |
502 |
|
498 | |||
503 | def getId(self): |
|
499 | def getId(self): | |
504 |
|
500 | |||
505 | return self.id |
|
501 | return self.id | |
506 |
|
502 | |||
507 | def updateId(self, new_id, parentId=parentId): |
|
503 | def updateId(self, new_id, parentId=parentId): | |
508 |
|
504 | |||
509 |
|
505 | |||
510 | new_id = int(parentId)*10 + (int(self.id) % 10) |
|
506 | new_id = int(parentId)*10 + (int(self.id) % 10) | |
511 | new_inputId = int(parentId)*10 + (int(self.inputId) % 10) |
|
507 | new_inputId = int(parentId)*10 + (int(self.inputId) % 10) | |
512 |
|
508 | |||
513 | #If this proc unit has not inputs |
|
509 | #If this proc unit has not inputs | |
514 | if self.inputId == '0': |
|
510 | if self.inputId == '0': | |
515 | new_inputId = 0 |
|
511 | new_inputId = 0 | |
516 |
|
512 | |||
517 | n = 1 |
|
513 | n = 1 | |
518 | for opConfObj in self.opConfObjList: |
|
514 | for opConfObj in self.opConfObjList: | |
519 |
|
515 | |||
520 | idOp = str(int(new_id)*10 + n) |
|
516 | idOp = str(int(new_id)*10 + n) | |
521 | opConfObj.updateId(idOp) |
|
517 | opConfObj.updateId(idOp) | |
522 |
|
518 | |||
523 | n += 1 |
|
519 | n += 1 | |
524 |
|
520 | |||
525 | self.parentId = str(parentId) |
|
521 | self.parentId = str(parentId) | |
526 | self.id = str(new_id) |
|
522 | self.id = str(new_id) | |
527 | self.inputId = str(new_inputId) |
|
523 | self.inputId = str(new_inputId) | |
528 |
|
524 | |||
529 |
|
525 | |||
530 | def getInputId(self): |
|
526 | def getInputId(self): | |
531 |
|
527 | |||
532 | return self.inputId |
|
528 | return self.inputId | |
533 |
|
529 | |||
534 | def getOperationObjList(self): |
|
530 | def getOperationObjList(self): | |
535 |
|
531 | |||
536 | return self.opConfObjList |
|
532 | return self.opConfObjList | |
537 |
|
533 | |||
538 | def getOperationObj(self, name=None): |
|
534 | def getOperationObj(self, name=None): | |
539 |
|
535 | |||
540 | for opConfObj in self.opConfObjList: |
|
536 | for opConfObj in self.opConfObjList: | |
541 |
|
537 | |||
542 | if opConfObj.name != name: |
|
538 | if opConfObj.name != name: | |
543 | continue |
|
539 | continue | |
544 |
|
540 | |||
545 | return opConfObj |
|
541 | return opConfObj | |
546 |
|
542 | |||
547 | return None |
|
543 | return None | |
548 |
|
544 | |||
549 | def getOpObjfromParamValue(self, value=None): |
|
545 | def getOpObjfromParamValue(self, value=None): | |
550 |
|
546 | |||
551 | for opConfObj in self.opConfObjList: |
|
547 | for opConfObj in self.opConfObjList: | |
552 | if opConfObj.getParameterObjfromValue(parameterValue=value) != value: |
|
548 | if opConfObj.getParameterObjfromValue(parameterValue=value) != value: | |
553 | continue |
|
549 | continue | |
554 | return opConfObj |
|
550 | return opConfObj | |
555 | return None |
|
551 | return None | |
556 |
|
552 | |||
557 | def getProcUnitObj(self): |
|
553 | def getProcUnitObj(self): | |
558 |
|
554 | |||
559 | return self.procUnitObj |
|
555 | return self.procUnitObj | |
560 |
|
556 | |||
561 | def setup(self, id, name, datatype, inputId, parentId=None): |
|
557 | def setup(self, id, name, datatype, inputId, parentId=None): | |
562 |
|
558 | |||
563 | #Compatible with old signal chain version |
|
559 | #Compatible with old signal chain version | |
564 | if datatype==None and name==None: |
|
560 | if datatype==None and name==None: | |
565 | raise ValueError, "datatype or name should be defined" |
|
561 | raise ValueError, "datatype or name should be defined" | |
566 |
|
562 | |||
567 | if name==None: |
|
563 | if name==None: | |
568 | if 'Proc' in datatype: |
|
564 | if 'Proc' in datatype: | |
569 | name = datatype |
|
565 | name = datatype | |
570 | else: |
|
566 | else: | |
571 | name = '%sProc' %(datatype) |
|
567 | name = '%sProc' %(datatype) | |
572 |
|
568 | |||
573 | if datatype==None: |
|
569 | if datatype==None: | |
574 | datatype = name.replace('Proc','') |
|
570 | datatype = name.replace('Proc','') | |
575 |
|
571 | |||
576 | self.id = str(id) |
|
572 | self.id = str(id) | |
577 | self.name = name |
|
573 | self.name = name | |
578 | self.datatype = datatype |
|
574 | self.datatype = datatype | |
579 | self.inputId = inputId |
|
575 | self.inputId = inputId | |
580 | self.parentId = parentId |
|
576 | self.parentId = parentId | |
581 |
|
577 | |||
582 | self.opConfObjList = [] |
|
578 | self.opConfObjList = [] | |
583 |
|
579 | |||
584 | self.addOperation(name='run', optype='self') |
|
580 | self.addOperation(name='run', optype='self') | |
585 |
|
581 | |||
586 | def removeOperations(self): |
|
582 | def removeOperations(self): | |
587 |
|
583 | |||
588 | for obj in self.opConfObjList: |
|
584 | for obj in self.opConfObjList: | |
589 | del obj |
|
585 | del obj | |
590 |
|
586 | |||
591 | self.opConfObjList = [] |
|
587 | self.opConfObjList = [] | |
592 | self.addOperation(name='run') |
|
588 | self.addOperation(name='run') | |
593 |
|
589 | |||
594 | def addParameter(self, **kwargs): |
|
590 | def addParameter(self, **kwargs): | |
595 | ''' |
|
591 | ''' | |
596 | Add parameters to "run" operation |
|
592 | Add parameters to "run" operation | |
597 | ''' |
|
593 | ''' | |
598 | opObj = self.opConfObjList[0] |
|
594 | opObj = self.opConfObjList[0] | |
599 |
|
595 | |||
600 | opObj.addParameter(**kwargs) |
|
596 | opObj.addParameter(**kwargs) | |
601 |
|
597 | |||
602 | return opObj |
|
598 | return opObj | |
603 |
|
599 | |||
604 | def addOperation(self, name, optype='self'): |
|
600 | def addOperation(self, name, optype='self'): | |
605 |
|
601 | |||
606 | id = self.__getNewId() |
|
602 | id = self.__getNewId() | |
607 | priority = self.__getPriority() |
|
603 | priority = self.__getPriority() | |
608 |
|
604 | |||
609 | opConfObj = OperationConf() |
|
605 | opConfObj = OperationConf() | |
610 | opConfObj.setup(id, name=name, priority=priority, type=optype) |
|
606 | opConfObj.setup(id, name=name, priority=priority, type=optype) | |
611 |
|
607 | |||
612 | self.opConfObjList.append(opConfObj) |
|
608 | self.opConfObjList.append(opConfObj) | |
613 |
|
609 | |||
614 | return opConfObj |
|
610 | return opConfObj | |
615 |
|
611 | |||
616 | def makeXml(self, projectElement): |
|
612 | def makeXml(self, projectElement): | |
617 |
|
613 | |||
618 | procUnitElement = SubElement(projectElement, self.ELEMENTNAME) |
|
614 | procUnitElement = SubElement(projectElement, self.ELEMENTNAME) | |
619 | procUnitElement.set('id', str(self.id)) |
|
615 | procUnitElement.set('id', str(self.id)) | |
620 | procUnitElement.set('name', self.name) |
|
616 | procUnitElement.set('name', self.name) | |
621 | procUnitElement.set('datatype', self.datatype) |
|
617 | procUnitElement.set('datatype', self.datatype) | |
622 | procUnitElement.set('inputId', str(self.inputId)) |
|
618 | procUnitElement.set('inputId', str(self.inputId)) | |
623 |
|
619 | |||
624 | for opConfObj in self.opConfObjList: |
|
620 | for opConfObj in self.opConfObjList: | |
625 | opConfObj.makeXml(procUnitElement) |
|
621 | opConfObj.makeXml(procUnitElement) | |
626 |
|
622 | |||
627 | def readXml(self, upElement): |
|
623 | def readXml(self, upElement): | |
628 |
|
624 | |||
629 | self.id = upElement.get('id') |
|
625 | self.id = upElement.get('id') | |
630 | self.name = upElement.get('name') |
|
626 | self.name = upElement.get('name') | |
631 | self.datatype = upElement.get('datatype') |
|
627 | self.datatype = upElement.get('datatype') | |
632 | self.inputId = upElement.get('inputId') |
|
628 | self.inputId = upElement.get('inputId') | |
633 |
|
629 | |||
634 | if self.ELEMENTNAME == "ReadUnit": |
|
630 | if self.ELEMENTNAME == "ReadUnit": | |
635 | self.datatype = self.datatype.replace("Reader", "") |
|
631 | self.datatype = self.datatype.replace("Reader", "") | |
636 |
|
632 | |||
637 | if self.ELEMENTNAME == "ProcUnit": |
|
633 | if self.ELEMENTNAME == "ProcUnit": | |
638 | self.datatype = self.datatype.replace("Proc", "") |
|
634 | self.datatype = self.datatype.replace("Proc", "") | |
639 |
|
635 | |||
640 | if self.inputId == 'None': |
|
636 | if self.inputId == 'None': | |
641 | self.inputId = '0' |
|
637 | self.inputId = '0' | |
642 |
|
638 | |||
643 | self.opConfObjList = [] |
|
639 | self.opConfObjList = [] | |
644 |
|
640 | |||
645 | opElementList = upElement.iter(OperationConf().getElementName()) |
|
641 | opElementList = upElement.iter(OperationConf().getElementName()) | |
646 |
|
642 | |||
647 | for opElement in opElementList: |
|
643 | for opElement in opElementList: | |
648 | opConfObj = OperationConf() |
|
644 | opConfObj = OperationConf() | |
649 | opConfObj.readXml(opElement) |
|
645 | opConfObj.readXml(opElement) | |
650 | self.opConfObjList.append(opConfObj) |
|
646 | self.opConfObjList.append(opConfObj) | |
651 |
|
647 | |||
652 | def printattr(self): |
|
648 | def printattr(self): | |
653 |
|
649 | |||
654 | print "%s[%s]: name = %s, datatype = %s, inputId = %s" %(self.ELEMENTNAME, |
|
650 | print "%s[%s]: name = %s, datatype = %s, inputId = %s" %(self.ELEMENTNAME, | |
655 | self.id, |
|
651 | self.id, | |
656 | self.name, |
|
652 | self.name, | |
657 | self.datatype, |
|
653 | self.datatype, | |
658 | self.inputId) |
|
654 | self.inputId) | |
659 |
|
655 | |||
660 | for opConfObj in self.opConfObjList: |
|
656 | for opConfObj in self.opConfObjList: | |
661 | opConfObj.printattr() |
|
657 | opConfObj.printattr() | |
662 |
|
658 | |||
663 |
|
659 | |||
664 | def getKwargs(self): |
|
660 | def getKwargs(self): | |
665 |
|
661 | |||
666 | opObj = self.opConfObjList[0] |
|
662 | opObj = self.opConfObjList[0] | |
667 | kwargs = opObj.getKwargs() |
|
663 | kwargs = opObj.getKwargs() | |
668 |
|
664 | |||
669 | return kwargs |
|
665 | return kwargs | |
670 |
|
666 | |||
671 | def createObjects(self, plotter_queue=None): |
|
667 | def createObjects(self, plotter_queue=None): | |
672 |
|
668 | |||
673 | className = eval(self.name) |
|
669 | className = eval(self.name) | |
674 | kwargs = self.getKwargs() |
|
670 | kwargs = self.getKwargs() | |
675 | procUnitObj = className(**kwargs) |
|
671 | procUnitObj = className(**kwargs) | |
676 |
|
672 | |||
677 | for opConfObj in self.opConfObjList: |
|
673 | for opConfObj in self.opConfObjList: | |
678 |
|
674 | |||
679 | if opConfObj.type=='self' and self.name=='run': |
|
675 | if opConfObj.type=='self' and self.name=='run': | |
680 | continue |
|
676 | continue | |
681 | elif opConfObj.type=='self': |
|
677 | elif opConfObj.type=='self': | |
682 | procUnitObj.addOperationKwargs(opConfObj.id, **opConfObj.getKwargs()) |
|
678 | procUnitObj.addOperationKwargs(opConfObj.id, **opConfObj.getKwargs()) | |
683 | continue |
|
679 | continue | |
684 |
|
680 | |||
685 | opObj = opConfObj.createObject(plotter_queue) |
|
681 | opObj = opConfObj.createObject(plotter_queue) | |
686 |
|
682 | |||
687 | self.opObjDict[opConfObj.id] = opObj |
|
683 | self.opObjDict[opConfObj.id] = opObj | |
688 |
|
684 | |||
689 | procUnitObj.addOperation(opObj, opConfObj.id) |
|
685 | procUnitObj.addOperation(opObj, opConfObj.id) | |
690 |
|
686 | |||
691 | self.procUnitObj = procUnitObj |
|
687 | self.procUnitObj = procUnitObj | |
692 |
|
688 | |||
693 | return procUnitObj |
|
689 | return procUnitObj | |
694 |
|
690 | |||
695 | def run(self): |
|
691 | def run(self): | |
696 |
|
692 | |||
697 | is_ok = False |
|
693 | is_ok = False | |
698 |
|
694 | |||
699 | for opConfObj in self.opConfObjList: |
|
695 | for opConfObj in self.opConfObjList: | |
700 |
|
696 | |||
701 | kwargs = {} |
|
697 | kwargs = {} | |
702 | for parmConfObj in opConfObj.getParameterObjList(): |
|
698 | for parmConfObj in opConfObj.getParameterObjList(): | |
703 | if opConfObj.name == 'run' and parmConfObj.name == 'datatype': |
|
699 | if opConfObj.name == 'run' and parmConfObj.name == 'datatype': | |
704 | continue |
|
700 | continue | |
705 |
|
701 | |||
706 | kwargs[parmConfObj.name] = parmConfObj.getValue() |
|
702 | kwargs[parmConfObj.name] = parmConfObj.getValue() | |
707 |
|
703 | |||
708 | #ini = time.time() |
|
704 | #ini = time.time() | |
709 |
|
705 | |||
710 | #print "\tRunning the '%s' operation with %s" %(opConfObj.name, opConfObj.id) |
|
706 | #print "\tRunning the '%s' operation with %s" %(opConfObj.name, opConfObj.id) | |
711 | sts = self.procUnitObj.call(opType = opConfObj.type, |
|
707 | sts = self.procUnitObj.call(opType = opConfObj.type, | |
712 | opName = opConfObj.name, |
|
708 | opName = opConfObj.name, | |
713 | opId = opConfObj.id, |
|
709 | opId = opConfObj.id, | |
714 | ) |
|
710 | ) | |
715 |
|
711 | |||
716 | # total_time = time.time() - ini |
|
712 | # total_time = time.time() - ini | |
717 | # |
|
713 | # | |
718 | # if total_time > 0.002: |
|
714 | # if total_time > 0.002: | |
719 | # 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) | |
720 |
|
716 | |||
721 | is_ok = is_ok or sts |
|
717 | is_ok = is_ok or sts | |
722 |
|
718 | |||
723 | return is_ok |
|
719 | return is_ok | |
724 |
|
720 | |||
725 | def close(self): |
|
721 | def close(self): | |
726 |
|
722 | |||
727 | for opConfObj in self.opConfObjList: |
|
723 | for opConfObj in self.opConfObjList: | |
728 | if opConfObj.type == 'self': |
|
724 | if opConfObj.type == 'self': | |
729 | continue |
|
725 | continue | |
730 |
|
726 | |||
731 | opObj = self.procUnitObj.getOperationObj(opConfObj.id) |
|
727 | opObj = self.procUnitObj.getOperationObj(opConfObj.id) | |
732 | opObj.close() |
|
728 | opObj.close() | |
733 |
|
729 | |||
734 | self.procUnitObj.close() |
|
730 | self.procUnitObj.close() | |
735 |
|
731 | |||
736 | return |
|
732 | return | |
737 |
|
733 | |||
738 | class ReadUnitConf(ProcUnitConf): |
|
734 | class ReadUnitConf(ProcUnitConf): | |
739 |
|
735 | |||
740 | path = None |
|
736 | path = None | |
741 | startDate = None |
|
737 | startDate = None | |
742 | endDate = None |
|
738 | endDate = None | |
743 | startTime = None |
|
739 | startTime = None | |
744 | endTime = None |
|
740 | endTime = None | |
745 |
|
741 | |||
746 | ELEMENTNAME = 'ReadUnit' |
|
742 | ELEMENTNAME = 'ReadUnit' | |
747 |
|
743 | |||
748 | def __init__(self): |
|
744 | def __init__(self): | |
749 |
|
745 | |||
750 | self.id = None |
|
746 | self.id = None | |
751 | self.datatype = None |
|
747 | self.datatype = None | |
752 | self.name = None |
|
748 | self.name = None | |
753 | self.inputId = None |
|
749 | self.inputId = None | |
754 |
|
750 | |||
755 | self.parentId = None |
|
751 | self.parentId = None | |
756 |
|
752 | |||
757 | self.opConfObjList = [] |
|
753 | self.opConfObjList = [] | |
758 | self.opObjList = [] |
|
754 | self.opObjList = [] | |
759 |
|
755 | |||
760 | def getElementName(self): |
|
756 | def getElementName(self): | |
761 |
|
757 | |||
762 | return self.ELEMENTNAME |
|
758 | return self.ELEMENTNAME | |
763 |
|
759 | |||
764 | 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): | |
765 |
|
761 | |||
766 | #Compatible with old signal chain version |
|
762 | #Compatible with old signal chain version | |
767 | if datatype==None and name==None: |
|
763 | if datatype==None and name==None: | |
768 | raise ValueError, "datatype or name should be defined" |
|
764 | raise ValueError, "datatype or name should be defined" | |
769 |
|
765 | |||
770 | if name==None: |
|
766 | if name==None: | |
771 | if 'Reader' in datatype: |
|
767 | if 'Reader' in datatype: | |
772 | name = datatype |
|
768 | name = datatype | |
773 | else: |
|
769 | else: | |
774 | name = '%sReader' %(datatype) |
|
770 | name = '%sReader' %(datatype) | |
775 |
|
771 | |||
776 | if datatype==None: |
|
772 | if datatype==None: | |
777 | datatype = name.replace('Reader','') |
|
773 | datatype = name.replace('Reader','') | |
778 |
|
774 | |||
779 | self.id = id |
|
775 | self.id = id | |
780 | self.name = name |
|
776 | self.name = name | |
781 | self.datatype = datatype |
|
777 | self.datatype = datatype | |
782 |
|
778 | |||
783 | self.path = os.path.abspath(path) |
|
779 | self.path = os.path.abspath(path) | |
784 | self.startDate = startDate |
|
780 | self.startDate = startDate | |
785 | self.endDate = endDate |
|
781 | self.endDate = endDate | |
786 | self.startTime = startTime |
|
782 | self.startTime = startTime | |
787 | self.endTime = endTime |
|
783 | self.endTime = endTime | |
788 |
|
784 | |||
789 | self.inputId = '0' |
|
785 | self.inputId = '0' | |
790 | self.parentId = parentId |
|
786 | self.parentId = parentId | |
791 | self.queue = queue |
|
787 | self.queue = queue | |
792 | self.addRunOperation(**kwargs) |
|
788 | self.addRunOperation(**kwargs) | |
793 |
|
789 | |||
794 | 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): | |
795 |
|
791 | |||
796 | #Compatible with old signal chain version |
|
792 | #Compatible with old signal chain version | |
797 | if datatype==None and name==None: |
|
793 | if datatype==None and name==None: | |
798 | raise ValueError, "datatype or name should be defined" |
|
794 | raise ValueError, "datatype or name should be defined" | |
799 |
|
795 | |||
800 | if name==None: |
|
796 | if name==None: | |
801 | if 'Reader' in datatype: |
|
797 | if 'Reader' in datatype: | |
802 | name = datatype |
|
798 | name = datatype | |
803 | else: |
|
799 | else: | |
804 | name = '%sReader' %(datatype) |
|
800 | name = '%sReader' %(datatype) | |
805 |
|
801 | |||
806 | if datatype==None: |
|
802 | if datatype==None: | |
807 | datatype = name.replace('Reader','') |
|
803 | datatype = name.replace('Reader','') | |
808 |
|
804 | |||
809 | self.datatype = datatype |
|
805 | self.datatype = datatype | |
810 | self.name = name |
|
806 | self.name = name | |
811 | self.path = path |
|
807 | self.path = path | |
812 | self.startDate = startDate |
|
808 | self.startDate = startDate | |
813 | self.endDate = endDate |
|
809 | self.endDate = endDate | |
814 | self.startTime = startTime |
|
810 | self.startTime = startTime | |
815 | self.endTime = endTime |
|
811 | self.endTime = endTime | |
816 |
|
812 | |||
817 | self.inputId = '0' |
|
813 | self.inputId = '0' | |
818 | self.parentId = parentId |
|
814 | self.parentId = parentId | |
819 |
|
815 | |||
820 | self.updateRunOperation(**kwargs) |
|
816 | self.updateRunOperation(**kwargs) | |
821 |
|
817 | |||
822 | def removeOperations(self): |
|
818 | def removeOperations(self): | |
823 |
|
819 | |||
824 | for obj in self.opConfObjList: |
|
820 | for obj in self.opConfObjList: | |
825 | del obj |
|
821 | del obj | |
826 |
|
822 | |||
827 | self.opConfObjList = [] |
|
823 | self.opConfObjList = [] | |
828 |
|
824 | |||
829 | def addRunOperation(self, **kwargs): |
|
825 | def addRunOperation(self, **kwargs): | |
830 |
|
826 | |||
831 | opObj = self.addOperation(name = 'run', optype = 'self') |
|
827 | opObj = self.addOperation(name = 'run', optype = 'self') | |
832 |
|
828 | |||
833 | opObj.addParameter(name='datatype' , value=self.datatype, format='str') |
|
829 | opObj.addParameter(name='datatype' , value=self.datatype, format='str') | |
834 | opObj.addParameter(name='path' , value=self.path, format='str') |
|
830 | opObj.addParameter(name='path' , value=self.path, format='str') | |
835 | opObj.addParameter(name='startDate' , value=self.startDate, format='date') |
|
831 | opObj.addParameter(name='startDate' , value=self.startDate, format='date') | |
836 | opObj.addParameter(name='endDate' , value=self.endDate, format='date') |
|
832 | opObj.addParameter(name='endDate' , value=self.endDate, format='date') | |
837 | opObj.addParameter(name='startTime' , value=self.startTime, format='time') |
|
833 | opObj.addParameter(name='startTime' , value=self.startTime, format='time') | |
838 | opObj.addParameter(name='endTime' , value=self.endTime, format='time') |
|
834 | opObj.addParameter(name='endTime' , value=self.endTime, format='time') | |
839 | opObj.addParameter(name='queue' , value=self.queue, format='obj') |
|
835 | opObj.addParameter(name='queue' , value=self.queue, format='obj') | |
840 |
|
836 | |||
841 | for key, value in kwargs.items(): |
|
837 | for key, value in kwargs.items(): | |
842 | opObj.addParameter(name=key, value=value, format=type(value).__name__) |
|
838 | opObj.addParameter(name=key, value=value, format=type(value).__name__) | |
843 |
|
839 | |||
844 | return opObj |
|
840 | return opObj | |
845 |
|
841 | |||
846 | def updateRunOperation(self, **kwargs): |
|
842 | def updateRunOperation(self, **kwargs): | |
847 |
|
843 | |||
848 | opObj = self.getOperationObj(name = 'run') |
|
844 | opObj = self.getOperationObj(name = 'run') | |
849 | opObj.removeParameters() |
|
845 | opObj.removeParameters() | |
850 |
|
846 | |||
851 | opObj.addParameter(name='datatype' , value=self.datatype, format='str') |
|
847 | opObj.addParameter(name='datatype' , value=self.datatype, format='str') | |
852 | opObj.addParameter(name='path' , value=self.path, format='str') |
|
848 | opObj.addParameter(name='path' , value=self.path, format='str') | |
853 | opObj.addParameter(name='startDate' , value=self.startDate, format='date') |
|
849 | opObj.addParameter(name='startDate' , value=self.startDate, format='date') | |
854 | opObj.addParameter(name='endDate' , value=self.endDate, format='date') |
|
850 | opObj.addParameter(name='endDate' , value=self.endDate, format='date') | |
855 | opObj.addParameter(name='startTime' , value=self.startTime, format='time') |
|
851 | opObj.addParameter(name='startTime' , value=self.startTime, format='time') | |
856 | opObj.addParameter(name='endTime' , value=self.endTime, format='time') |
|
852 | opObj.addParameter(name='endTime' , value=self.endTime, format='time') | |
857 |
|
853 | |||
858 | for key, value in kwargs.items(): |
|
854 | for key, value in kwargs.items(): | |
859 | opObj.addParameter(name=key, value=value, format=type(value).__name__) |
|
855 | opObj.addParameter(name=key, value=value, format=type(value).__name__) | |
860 |
|
856 | |||
861 | return opObj |
|
857 | return opObj | |
862 |
|
858 | |||
863 | # def makeXml(self, projectElement): |
|
859 | # def makeXml(self, projectElement): | |
864 | # |
|
860 | # | |
865 | # procUnitElement = SubElement(projectElement, self.ELEMENTNAME) |
|
861 | # procUnitElement = SubElement(projectElement, self.ELEMENTNAME) | |
866 | # procUnitElement.set('id', str(self.id)) |
|
862 | # procUnitElement.set('id', str(self.id)) | |
867 | # procUnitElement.set('name', self.name) |
|
863 | # procUnitElement.set('name', self.name) | |
868 | # procUnitElement.set('datatype', self.datatype) |
|
864 | # procUnitElement.set('datatype', self.datatype) | |
869 | # procUnitElement.set('inputId', str(self.inputId)) |
|
865 | # procUnitElement.set('inputId', str(self.inputId)) | |
870 | # |
|
866 | # | |
871 | # for opConfObj in self.opConfObjList: |
|
867 | # for opConfObj in self.opConfObjList: | |
872 | # opConfObj.makeXml(procUnitElement) |
|
868 | # opConfObj.makeXml(procUnitElement) | |
873 |
|
869 | |||
874 | def readXml(self, upElement): |
|
870 | def readXml(self, upElement): | |
875 |
|
871 | |||
876 | self.id = upElement.get('id') |
|
872 | self.id = upElement.get('id') | |
877 | self.name = upElement.get('name') |
|
873 | self.name = upElement.get('name') | |
878 | self.datatype = upElement.get('datatype') |
|
874 | self.datatype = upElement.get('datatype') | |
879 | self.inputId = upElement.get('inputId') |
|
875 | self.inputId = upElement.get('inputId') | |
880 |
|
876 | |||
881 | if self.ELEMENTNAME == "ReadUnit": |
|
877 | if self.ELEMENTNAME == "ReadUnit": | |
882 | self.datatype = self.datatype.replace("Reader", "") |
|
878 | self.datatype = self.datatype.replace("Reader", "") | |
883 |
|
879 | |||
884 | if self.inputId == 'None': |
|
880 | if self.inputId == 'None': | |
885 | self.inputId = '0' |
|
881 | self.inputId = '0' | |
886 |
|
882 | |||
887 | self.opConfObjList = [] |
|
883 | self.opConfObjList = [] | |
888 |
|
884 | |||
889 | opElementList = upElement.iter(OperationConf().getElementName()) |
|
885 | opElementList = upElement.iter(OperationConf().getElementName()) | |
890 |
|
886 | |||
891 | for opElement in opElementList: |
|
887 | for opElement in opElementList: | |
892 | opConfObj = OperationConf() |
|
888 | opConfObj = OperationConf() | |
893 | opConfObj.readXml(opElement) |
|
889 | opConfObj.readXml(opElement) | |
894 | self.opConfObjList.append(opConfObj) |
|
890 | self.opConfObjList.append(opConfObj) | |
895 |
|
891 | |||
896 | if opConfObj.name == 'run': |
|
892 | if opConfObj.name == 'run': | |
897 | self.path = opConfObj.getParameterValue('path') |
|
893 | self.path = opConfObj.getParameterValue('path') | |
898 | self.startDate = opConfObj.getParameterValue('startDate') |
|
894 | self.startDate = opConfObj.getParameterValue('startDate') | |
899 | self.endDate = opConfObj.getParameterValue('endDate') |
|
895 | self.endDate = opConfObj.getParameterValue('endDate') | |
900 | self.startTime = opConfObj.getParameterValue('startTime') |
|
896 | self.startTime = opConfObj.getParameterValue('startTime') | |
901 | self.endTime = opConfObj.getParameterValue('endTime') |
|
897 | self.endTime = opConfObj.getParameterValue('endTime') | |
902 |
|
898 | |||
903 | class Project(): |
|
899 | class Project(): | |
904 |
|
900 | |||
905 | id = None |
|
901 | id = None | |
906 | name = None |
|
902 | name = None | |
907 | description = None |
|
903 | description = None | |
908 | filename = None |
|
904 | filename = None | |
909 |
|
905 | |||
910 | procUnitConfObjDict = None |
|
906 | procUnitConfObjDict = None | |
911 |
|
907 | |||
912 | ELEMENTNAME = 'Project' |
|
908 | ELEMENTNAME = 'Project' | |
913 |
|
909 | |||
914 | plotterQueue = None |
|
910 | plotterQueue = None | |
915 |
|
911 | |||
916 | def __init__(self, plotter_queue=None): |
|
912 | def __init__(self, plotter_queue=None): | |
917 |
|
913 | |||
918 | self.id = None |
|
914 | self.id = None | |
919 | self.name = None |
|
915 | self.name = None | |
920 | self.description = None |
|
916 | self.description = None | |
921 |
|
917 | |||
922 | self.plotterQueue = plotter_queue |
|
918 | self.plotterQueue = plotter_queue | |
923 |
|
919 | |||
924 | self.procUnitConfObjDict = {} |
|
920 | self.procUnitConfObjDict = {} | |
925 |
|
921 | |||
926 | def __getNewId(self): |
|
922 | def __getNewId(self): | |
927 |
|
923 | |||
928 | idList = self.procUnitConfObjDict.keys() |
|
924 | idList = self.procUnitConfObjDict.keys() | |
929 |
|
925 | |||
930 | id = int(self.id)*10 |
|
926 | id = int(self.id)*10 | |
931 |
|
927 | |||
932 | while True: |
|
928 | while True: | |
933 | id += 1 |
|
929 | id += 1 | |
934 |
|
930 | |||
935 | if str(id) in idList: |
|
931 | if str(id) in idList: | |
936 | continue |
|
932 | continue | |
937 |
|
933 | |||
938 | break |
|
934 | break | |
939 |
|
935 | |||
940 | return str(id) |
|
936 | return str(id) | |
941 |
|
937 | |||
942 | def getElementName(self): |
|
938 | def getElementName(self): | |
943 |
|
939 | |||
944 | return self.ELEMENTNAME |
|
940 | return self.ELEMENTNAME | |
945 |
|
941 | |||
946 | def getId(self): |
|
942 | def getId(self): | |
947 |
|
943 | |||
948 | return self.id |
|
944 | return self.id | |
949 |
|
945 | |||
950 | def updateId(self, new_id): |
|
946 | def updateId(self, new_id): | |
951 |
|
947 | |||
952 | self.id = str(new_id) |
|
948 | self.id = str(new_id) | |
953 |
|
949 | |||
954 | keyList = self.procUnitConfObjDict.keys() |
|
950 | keyList = self.procUnitConfObjDict.keys() | |
955 | keyList.sort() |
|
951 | keyList.sort() | |
956 |
|
952 | |||
957 | n = 1 |
|
953 | n = 1 | |
958 | newProcUnitConfObjDict = {} |
|
954 | newProcUnitConfObjDict = {} | |
959 |
|
955 | |||
960 | for procKey in keyList: |
|
956 | for procKey in keyList: | |
961 |
|
957 | |||
962 | procUnitConfObj = self.procUnitConfObjDict[procKey] |
|
958 | procUnitConfObj = self.procUnitConfObjDict[procKey] | |
963 | idProcUnit = str(int(self.id)*10 + n) |
|
959 | idProcUnit = str(int(self.id)*10 + n) | |
964 | procUnitConfObj.updateId(idProcUnit, parentId = self.id) |
|
960 | procUnitConfObj.updateId(idProcUnit, parentId = self.id) | |
965 |
|
961 | |||
966 | newProcUnitConfObjDict[idProcUnit] = procUnitConfObj |
|
962 | newProcUnitConfObjDict[idProcUnit] = procUnitConfObj | |
967 | n += 1 |
|
963 | n += 1 | |
968 |
|
964 | |||
969 | self.procUnitConfObjDict = newProcUnitConfObjDict |
|
965 | self.procUnitConfObjDict = newProcUnitConfObjDict | |
970 |
|
966 | |||
971 | def setup(self, id, name, description): |
|
967 | def setup(self, id, name, description): | |
972 |
|
968 | |||
973 | self.id = str(id) |
|
969 | self.id = str(id) | |
974 | self.name = name |
|
970 | self.name = name | |
975 | self.description = description |
|
971 | self.description = description | |
976 |
|
972 | |||
977 | def update(self, name, description): |
|
973 | def update(self, name, description): | |
978 |
|
974 | |||
979 | self.name = name |
|
975 | self.name = name | |
980 | self.description = description |
|
976 | self.description = description | |
981 |
|
977 | |||
982 | def addReadUnit(self, id=None, datatype=None, name=None, **kwargs): |
|
978 | def addReadUnit(self, id=None, datatype=None, name=None, **kwargs): | |
983 |
|
979 | |||
984 | if id is None: |
|
980 | if id is None: | |
985 | idReadUnit = self.__getNewId() |
|
981 | idReadUnit = self.__getNewId() | |
986 | else: |
|
982 | else: | |
987 | idReadUnit = str(id) |
|
983 | idReadUnit = str(id) | |
988 |
|
984 | |||
989 | readUnitConfObj = ReadUnitConf() |
|
985 | readUnitConfObj = ReadUnitConf() | |
990 | readUnitConfObj.setup(idReadUnit, name, datatype, parentId=self.id, **kwargs) |
|
986 | readUnitConfObj.setup(idReadUnit, name, datatype, parentId=self.id, **kwargs) | |
991 |
|
987 | |||
992 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj |
|
988 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj | |
993 |
|
989 | |||
994 | return readUnitConfObj |
|
990 | return readUnitConfObj | |
995 |
|
991 | |||
996 | def addProcUnit(self, inputId='0', datatype=None, name=None): |
|
992 | def addProcUnit(self, inputId='0', datatype=None, name=None): | |
997 |
|
993 | |||
998 | idProcUnit = self.__getNewId() |
|
994 | idProcUnit = self.__getNewId() | |
999 |
|
995 | |||
1000 | procUnitConfObj = ProcUnitConf() |
|
996 | procUnitConfObj = ProcUnitConf() | |
1001 | procUnitConfObj.setup(idProcUnit, name, datatype, inputId, parentId=self.id) |
|
997 | procUnitConfObj.setup(idProcUnit, name, datatype, inputId, parentId=self.id) | |
1002 |
|
998 | |||
1003 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj |
|
999 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj | |
1004 |
|
1000 | |||
1005 | return procUnitConfObj |
|
1001 | return procUnitConfObj | |
1006 |
|
1002 | |||
1007 | def removeProcUnit(self, id): |
|
1003 | def removeProcUnit(self, id): | |
1008 |
|
1004 | |||
1009 | if id in self.procUnitConfObjDict.keys(): |
|
1005 | if id in self.procUnitConfObjDict.keys(): | |
1010 | self.procUnitConfObjDict.pop(id) |
|
1006 | self.procUnitConfObjDict.pop(id) | |
1011 |
|
1007 | |||
1012 | def getReadUnitId(self): |
|
1008 | def getReadUnitId(self): | |
1013 |
|
1009 | |||
1014 | readUnitConfObj = self.getReadUnitObj() |
|
1010 | readUnitConfObj = self.getReadUnitObj() | |
1015 |
|
1011 | |||
1016 | return readUnitConfObj.id |
|
1012 | return readUnitConfObj.id | |
1017 |
|
1013 | |||
1018 | def getReadUnitObj(self): |
|
1014 | def getReadUnitObj(self): | |
1019 |
|
1015 | |||
1020 | for obj in self.procUnitConfObjDict.values(): |
|
1016 | for obj in self.procUnitConfObjDict.values(): | |
1021 | if obj.getElementName() == "ReadUnit": |
|
1017 | if obj.getElementName() == "ReadUnit": | |
1022 | return obj |
|
1018 | return obj | |
1023 |
|
1019 | |||
1024 | return None |
|
1020 | return None | |
1025 |
|
1021 | |||
1026 | def getProcUnitObj(self, id=None, name=None): |
|
1022 | def getProcUnitObj(self, id=None, name=None): | |
1027 |
|
1023 | |||
1028 | if id != None: |
|
1024 | if id != None: | |
1029 | return self.procUnitConfObjDict[id] |
|
1025 | return self.procUnitConfObjDict[id] | |
1030 |
|
1026 | |||
1031 | if name != None: |
|
1027 | if name != None: | |
1032 | return self.getProcUnitObjByName(name) |
|
1028 | return self.getProcUnitObjByName(name) | |
1033 |
|
1029 | |||
1034 | return None |
|
1030 | return None | |
1035 |
|
1031 | |||
1036 | def getProcUnitObjByName(self, name): |
|
1032 | def getProcUnitObjByName(self, name): | |
1037 |
|
1033 | |||
1038 | for obj in self.procUnitConfObjDict.values(): |
|
1034 | for obj in self.procUnitConfObjDict.values(): | |
1039 | if obj.name == name: |
|
1035 | if obj.name == name: | |
1040 | return obj |
|
1036 | return obj | |
1041 |
|
1037 | |||
1042 | return None |
|
1038 | return None | |
1043 |
|
1039 | |||
1044 | def procUnitItems(self): |
|
1040 | def procUnitItems(self): | |
1045 |
|
1041 | |||
1046 | return self.procUnitConfObjDict.items() |
|
1042 | return self.procUnitConfObjDict.items() | |
1047 |
|
1043 | |||
1048 | def makeXml(self): |
|
1044 | def makeXml(self): | |
1049 |
|
1045 | |||
1050 | projectElement = Element('Project') |
|
1046 | projectElement = Element('Project') | |
1051 | projectElement.set('id', str(self.id)) |
|
1047 | projectElement.set('id', str(self.id)) | |
1052 | projectElement.set('name', self.name) |
|
1048 | projectElement.set('name', self.name) | |
1053 | projectElement.set('description', self.description) |
|
1049 | projectElement.set('description', self.description) | |
1054 |
|
1050 | |||
1055 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
1051 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |
1056 | procUnitConfObj.makeXml(projectElement) |
|
1052 | procUnitConfObj.makeXml(projectElement) | |
1057 |
|
1053 | |||
1058 | self.projectElement = projectElement |
|
1054 | self.projectElement = projectElement | |
1059 |
|
1055 | |||
1060 | def writeXml(self, filename=None): |
|
1056 | def writeXml(self, filename=None): | |
1061 |
|
1057 | |||
1062 | if filename == None: |
|
1058 | if filename == None: | |
1063 | if self.filename: |
|
1059 | if self.filename: | |
1064 | filename = self.filename |
|
1060 | filename = self.filename | |
1065 | else: |
|
1061 | else: | |
1066 | filename = "schain.xml" |
|
1062 | filename = "schain.xml" | |
1067 |
|
1063 | |||
1068 | if not filename: |
|
1064 | if not filename: | |
1069 | 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." | |
1070 | return 0 |
|
1066 | return 0 | |
1071 |
|
1067 | |||
1072 | abs_file = os.path.abspath(filename) |
|
1068 | abs_file = os.path.abspath(filename) | |
1073 |
|
1069 | |||
1074 | 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): | |
1075 | print "No write permission on %s" %os.path.dirname(abs_file) |
|
1071 | print "No write permission on %s" %os.path.dirname(abs_file) | |
1076 | return 0 |
|
1072 | return 0 | |
1077 |
|
1073 | |||
1078 | 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)): | |
1079 | 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 | |
1080 | return 0 |
|
1076 | return 0 | |
1081 |
|
1077 | |||
1082 | self.makeXml() |
|
1078 | self.makeXml() | |
1083 |
|
1079 | |||
1084 | ElementTree(self.projectElement).write(abs_file, method='xml') |
|
1080 | ElementTree(self.projectElement).write(abs_file, method='xml') | |
1085 |
|
1081 | |||
1086 | self.filename = abs_file |
|
1082 | self.filename = abs_file | |
1087 |
|
1083 | |||
1088 | return 1 |
|
1084 | return 1 | |
1089 |
|
1085 | |||
1090 | def readXml(self, filename = None): |
|
1086 | def readXml(self, filename = None): | |
1091 |
|
1087 | |||
1092 | if not filename: |
|
1088 | if not filename: | |
1093 | print "filename is not defined" |
|
1089 | print "filename is not defined" | |
1094 | return 0 |
|
1090 | return 0 | |
1095 |
|
1091 | |||
1096 | abs_file = os.path.abspath(filename) |
|
1092 | abs_file = os.path.abspath(filename) | |
1097 |
|
1093 | |||
1098 | if not os.path.isfile(abs_file): |
|
1094 | if not os.path.isfile(abs_file): | |
1099 | print "%s file does not exist" %abs_file |
|
1095 | print "%s file does not exist" %abs_file | |
1100 | return 0 |
|
1096 | return 0 | |
1101 |
|
1097 | |||
1102 | self.projectElement = None |
|
1098 | self.projectElement = None | |
1103 | self.procUnitConfObjDict = {} |
|
1099 | self.procUnitConfObjDict = {} | |
1104 |
|
1100 | |||
1105 | try: |
|
1101 | try: | |
1106 | self.projectElement = ElementTree().parse(abs_file) |
|
1102 | self.projectElement = ElementTree().parse(abs_file) | |
1107 | except: |
|
1103 | except: | |
1108 | print "Error reading %s, verify file format" %filename |
|
1104 | print "Error reading %s, verify file format" %filename | |
1109 | return 0 |
|
1105 | return 0 | |
1110 |
|
1106 | |||
1111 | self.project = self.projectElement.tag |
|
1107 | self.project = self.projectElement.tag | |
1112 |
|
1108 | |||
1113 | self.id = self.projectElement.get('id') |
|
1109 | self.id = self.projectElement.get('id') | |
1114 | self.name = self.projectElement.get('name') |
|
1110 | self.name = self.projectElement.get('name') | |
1115 | self.description = self.projectElement.get('description') |
|
1111 | self.description = self.projectElement.get('description') | |
1116 |
|
1112 | |||
1117 | readUnitElementList = self.projectElement.iter(ReadUnitConf().getElementName()) |
|
1113 | readUnitElementList = self.projectElement.iter(ReadUnitConf().getElementName()) | |
1118 |
|
1114 | |||
1119 | for readUnitElement in readUnitElementList: |
|
1115 | for readUnitElement in readUnitElementList: | |
1120 | readUnitConfObj = ReadUnitConf() |
|
1116 | readUnitConfObj = ReadUnitConf() | |
1121 | readUnitConfObj.readXml(readUnitElement) |
|
1117 | readUnitConfObj.readXml(readUnitElement) | |
1122 |
|
1118 | |||
1123 | if readUnitConfObj.parentId == None: |
|
1119 | if readUnitConfObj.parentId == None: | |
1124 | readUnitConfObj.parentId = self.id |
|
1120 | readUnitConfObj.parentId = self.id | |
1125 |
|
1121 | |||
1126 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj |
|
1122 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj | |
1127 |
|
1123 | |||
1128 | procUnitElementList = self.projectElement.iter(ProcUnitConf().getElementName()) |
|
1124 | procUnitElementList = self.projectElement.iter(ProcUnitConf().getElementName()) | |
1129 |
|
1125 | |||
1130 | for procUnitElement in procUnitElementList: |
|
1126 | for procUnitElement in procUnitElementList: | |
1131 | procUnitConfObj = ProcUnitConf() |
|
1127 | procUnitConfObj = ProcUnitConf() | |
1132 | procUnitConfObj.readXml(procUnitElement) |
|
1128 | procUnitConfObj.readXml(procUnitElement) | |
1133 |
|
1129 | |||
1134 | if procUnitConfObj.parentId == None: |
|
1130 | if procUnitConfObj.parentId == None: | |
1135 | procUnitConfObj.parentId = self.id |
|
1131 | procUnitConfObj.parentId = self.id | |
1136 |
|
1132 | |||
1137 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj |
|
1133 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj | |
1138 |
|
1134 | |||
1139 | self.filename = abs_file |
|
1135 | self.filename = abs_file | |
1140 |
|
1136 | |||
1141 | return 1 |
|
1137 | return 1 | |
1142 |
|
1138 | |||
1143 | def printattr(self): |
|
1139 | def printattr(self): | |
1144 |
|
1140 | |||
1145 | print "Project[%s]: name = %s, description = %s" %(self.id, |
|
1141 | print "Project[%s]: name = %s, description = %s" %(self.id, | |
1146 | self.name, |
|
1142 | self.name, | |
1147 | self.description) |
|
1143 | self.description) | |
1148 |
|
1144 | |||
1149 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
1145 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |
1150 | procUnitConfObj.printattr() |
|
1146 | procUnitConfObj.printattr() | |
1151 |
|
1147 | |||
1152 | def createObjects(self): |
|
1148 | def createObjects(self): | |
1153 |
|
1149 | |||
1154 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
1150 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |
1155 | procUnitConfObj.createObjects(self.plotterQueue) |
|
1151 | procUnitConfObj.createObjects(self.plotterQueue) | |
1156 |
|
1152 | |||
1157 | def __connect(self, objIN, thisObj): |
|
1153 | def __connect(self, objIN, thisObj): | |
1158 |
|
1154 | |||
1159 | thisObj.setInput(objIN.getOutputObj()) |
|
1155 | thisObj.setInput(objIN.getOutputObj()) | |
1160 |
|
1156 | |||
1161 | def connectObjects(self): |
|
1157 | def connectObjects(self): | |
1162 |
|
1158 | |||
1163 | for thisPUConfObj in self.procUnitConfObjDict.values(): |
|
1159 | for thisPUConfObj in self.procUnitConfObjDict.values(): | |
1164 |
|
1160 | |||
1165 | inputId = thisPUConfObj.getInputId() |
|
1161 | inputId = thisPUConfObj.getInputId() | |
1166 |
|
1162 | |||
1167 | if int(inputId) == 0: |
|
1163 | if int(inputId) == 0: | |
1168 | continue |
|
1164 | continue | |
1169 |
|
1165 | |||
1170 | #Get input object |
|
1166 | #Get input object | |
1171 | puConfINObj = self.procUnitConfObjDict[inputId] |
|
1167 | puConfINObj = self.procUnitConfObjDict[inputId] | |
1172 | puObjIN = puConfINObj.getProcUnitObj() |
|
1168 | puObjIN = puConfINObj.getProcUnitObj() | |
1173 |
|
1169 | |||
1174 | #Get current object |
|
1170 | #Get current object | |
1175 | thisPUObj = thisPUConfObj.getProcUnitObj() |
|
1171 | thisPUObj = thisPUConfObj.getProcUnitObj() | |
1176 |
|
1172 | |||
1177 | self.__connect(puObjIN, thisPUObj) |
|
1173 | self.__connect(puObjIN, thisPUObj) | |
1178 |
|
1174 | |||
1179 | def __handleError(self, procUnitConfObj, send_email=True): |
|
1175 | def __handleError(self, procUnitConfObj, send_email=True): | |
1180 |
|
1176 | |||
1181 | import socket |
|
1177 | import socket | |
1182 |
|
1178 | |||
1183 | err = traceback.format_exception(sys.exc_info()[0], |
|
1179 | err = traceback.format_exception(sys.exc_info()[0], | |
1184 | sys.exc_info()[1], |
|
1180 | sys.exc_info()[1], | |
1185 | sys.exc_info()[2]) |
|
1181 | sys.exc_info()[2]) | |
1186 |
|
1182 | |||
1187 | print "***** Error occurred in %s *****" %(procUnitConfObj.name) |
|
1183 | print "***** Error occurred in %s *****" %(procUnitConfObj.name) | |
1188 | print "***** %s" %err[-1] |
|
1184 | print "***** %s" %err[-1] | |
1189 |
|
1185 | |||
1190 | message = "".join(err) |
|
1186 | message = "".join(err) | |
1191 |
|
1187 | |||
1192 | sys.stderr.write(message) |
|
1188 | sys.stderr.write(message) | |
1193 |
|
1189 | |||
1194 | if not send_email: |
|
1190 | if not send_email: | |
1195 | return |
|
1191 | return | |
1196 |
|
1192 | |||
1197 | 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) | |
1198 |
|
1194 | |||
1199 | subtitle = "%s: %s\n" %(procUnitConfObj.getElementName() ,procUnitConfObj.name) |
|
1195 | subtitle = "%s: %s\n" %(procUnitConfObj.getElementName() ,procUnitConfObj.name) | |
1200 | subtitle += "Hostname: %s\n" %socket.gethostbyname(socket.gethostname()) |
|
1196 | subtitle += "Hostname: %s\n" %socket.gethostbyname(socket.gethostname()) | |
1201 | subtitle += "Working directory: %s\n" %os.path.abspath("./") |
|
1197 | subtitle += "Working directory: %s\n" %os.path.abspath("./") | |
1202 | subtitle += "Configuration file: %s\n" %self.filename |
|
1198 | subtitle += "Configuration file: %s\n" %self.filename | |
1203 | subtitle += "Time: %s\n" %str(datetime.datetime.now()) |
|
1199 | subtitle += "Time: %s\n" %str(datetime.datetime.now()) | |
1204 |
|
1200 | |||
1205 | readUnitConfObj = self.getReadUnitObj() |
|
1201 | readUnitConfObj = self.getReadUnitObj() | |
1206 | if readUnitConfObj: |
|
1202 | if readUnitConfObj: | |
1207 | subtitle += "\nInput parameters:\n" |
|
1203 | subtitle += "\nInput parameters:\n" | |
1208 | subtitle += "[Data path = %s]\n" %readUnitConfObj.path |
|
1204 | subtitle += "[Data path = %s]\n" %readUnitConfObj.path | |
1209 | subtitle += "[Data type = %s]\n" %readUnitConfObj.datatype |
|
1205 | subtitle += "[Data type = %s]\n" %readUnitConfObj.datatype | |
1210 | subtitle += "[Start date = %s]\n" %readUnitConfObj.startDate |
|
1206 | subtitle += "[Start date = %s]\n" %readUnitConfObj.startDate | |
1211 | subtitle += "[End date = %s]\n" %readUnitConfObj.endDate |
|
1207 | subtitle += "[End date = %s]\n" %readUnitConfObj.endDate | |
1212 | subtitle += "[Start time = %s]\n" %readUnitConfObj.startTime |
|
1208 | subtitle += "[Start time = %s]\n" %readUnitConfObj.startTime | |
1213 | subtitle += "[End time = %s]\n" %readUnitConfObj.endTime |
|
1209 | subtitle += "[End time = %s]\n" %readUnitConfObj.endTime | |
1214 |
|
1210 | |||
1215 | adminObj = schainpy.admin.SchainNotify() |
|
1211 | adminObj = schainpy.admin.SchainNotify() | |
1216 | adminObj.sendAlert(message=message, |
|
1212 | adminObj.sendAlert(message=message, | |
1217 | subject=subject, |
|
1213 | subject=subject, | |
1218 | subtitle=subtitle, |
|
1214 | subtitle=subtitle, | |
1219 | filename=self.filename) |
|
1215 | filename=self.filename) | |
1220 |
|
1216 | |||
1221 | def isPaused(self): |
|
1217 | def isPaused(self): | |
1222 | return 0 |
|
1218 | return 0 | |
1223 |
|
1219 | |||
1224 | def isStopped(self): |
|
1220 | def isStopped(self): | |
1225 | return 0 |
|
1221 | return 0 | |
1226 |
|
1222 | |||
1227 | def runController(self): |
|
1223 | def runController(self): | |
1228 | """ |
|
1224 | """ | |
1229 | returns 0 when this process has been stopped, 1 otherwise |
|
1225 | returns 0 when this process has been stopped, 1 otherwise | |
1230 | """ |
|
1226 | """ | |
1231 |
|
1227 | |||
1232 | if self.isPaused(): |
|
1228 | if self.isPaused(): | |
1233 | print "Process suspended" |
|
1229 | print "Process suspended" | |
1234 |
|
1230 | |||
1235 | while True: |
|
1231 | while True: | |
1236 | sleep(0.1) |
|
1232 | sleep(0.1) | |
1237 |
|
1233 | |||
1238 | if not self.isPaused(): |
|
1234 | if not self.isPaused(): | |
1239 | break |
|
1235 | break | |
1240 |
|
1236 | |||
1241 | if self.isStopped(): |
|
1237 | if self.isStopped(): | |
1242 | break |
|
1238 | break | |
1243 |
|
1239 | |||
1244 | print "Process reinitialized" |
|
1240 | print "Process reinitialized" | |
1245 |
|
1241 | |||
1246 | if self.isStopped(): |
|
1242 | if self.isStopped(): | |
1247 | print "Process stopped" |
|
1243 | print "Process stopped" | |
1248 | return 0 |
|
1244 | return 0 | |
1249 |
|
1245 | |||
1250 | return 1 |
|
1246 | return 1 | |
1251 |
|
1247 | |||
1252 | def setFilename(self, filename): |
|
1248 | def setFilename(self, filename): | |
1253 |
|
1249 | |||
1254 | self.filename = filename |
|
1250 | self.filename = filename | |
1255 |
|
1251 | |||
1256 | def setPlotterQueue(self, plotter_queue): |
|
1252 | def setPlotterQueue(self, plotter_queue): | |
1257 |
|
1253 | |||
1258 | raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class" |
|
1254 | raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class" | |
1259 |
|
1255 | |||
1260 | def getPlotterQueue(self): |
|
1256 | def getPlotterQueue(self): | |
1261 |
|
1257 | |||
1262 | raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class" |
|
1258 | raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class" | |
1263 |
|
1259 | |||
1264 | def useExternalPlotter(self): |
|
1260 | def useExternalPlotter(self): | |
1265 |
|
1261 | |||
1266 | raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class" |
|
1262 | raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class" | |
1267 |
|
1263 | |||
1268 | def run(self): |
|
1264 | def run(self): | |
1269 |
|
1265 | |||
1270 |
|
1266 | |||
1271 | print "*"*60 |
|
1267 | print "*"*60 | |
1272 | print " Starting SIGNAL CHAIN PROCESSING v%s " %schainpy.__version__ |
|
1268 | print " Starting SIGNAL CHAIN PROCESSING v%s " %schainpy.__version__ | |
1273 | print "*"*60 |
|
1269 | print "*"*60 | |
1274 |
|
1270 | |||
1275 |
|
1271 | |||
1276 | keyList = self.procUnitConfObjDict.keys() |
|
1272 | keyList = self.procUnitConfObjDict.keys() | |
1277 | keyList.sort() |
|
1273 | keyList.sort() | |
1278 |
|
1274 | |||
1279 | while(True): |
|
1275 | while(True): | |
1280 |
|
1276 | |||
1281 | is_ok = False |
|
1277 | is_ok = False | |
1282 |
|
1278 | |||
1283 | for procKey in keyList: |
|
1279 | for procKey in keyList: | |
1284 | # print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id) |
|
1280 | # print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id) | |
1285 |
|
1281 | |||
1286 | procUnitConfObj = self.procUnitConfObjDict[procKey] |
|
1282 | procUnitConfObj = self.procUnitConfObjDict[procKey] | |
1287 |
|
1283 | |||
1288 | try: |
|
1284 | try: | |
1289 | sts = procUnitConfObj.run() |
|
1285 | sts = procUnitConfObj.run() | |
1290 | is_ok = is_ok or sts |
|
1286 | is_ok = is_ok or sts | |
1291 | except KeyboardInterrupt: |
|
1287 | except KeyboardInterrupt: | |
1292 | is_ok = False |
|
1288 | is_ok = False | |
1293 | break |
|
1289 | break | |
1294 | except ValueError, e: |
|
1290 | except ValueError, e: | |
1295 | sleep(0.5) |
|
1291 | sleep(0.5) | |
1296 | self.__handleError(procUnitConfObj, send_email=True) |
|
1292 | self.__handleError(procUnitConfObj, send_email=True) | |
1297 | is_ok = False |
|
1293 | is_ok = False | |
1298 | break |
|
1294 | break | |
1299 | except: |
|
1295 | except: | |
1300 | sleep(0.5) |
|
1296 | sleep(0.5) | |
1301 | self.__handleError(procUnitConfObj) |
|
1297 | self.__handleError(procUnitConfObj) | |
1302 | is_ok = False |
|
1298 | is_ok = False | |
1303 | break |
|
1299 | break | |
1304 |
|
1300 | |||
1305 | #If every process unit finished so end process |
|
1301 | #If every process unit finished so end process | |
1306 | if not(is_ok): |
|
1302 | if not(is_ok): | |
1307 | # print "Every process unit have finished" |
|
1303 | # print "Every process unit have finished" | |
1308 | break |
|
1304 | break | |
1309 |
|
1305 | |||
1310 | if not self.runController(): |
|
1306 | if not self.runController(): | |
1311 | break |
|
1307 | break | |
1312 |
|
1308 | |||
1313 | #Closing every process |
|
1309 | #Closing every process | |
1314 | for procKey in keyList: |
|
1310 | for procKey in keyList: | |
1315 | procUnitConfObj = self.procUnitConfObjDict[procKey] |
|
1311 | procUnitConfObj = self.procUnitConfObjDict[procKey] | |
1316 | procUnitConfObj.close() |
|
1312 | procUnitConfObj.close() | |
1317 |
|
1313 | |||
1318 | print "Process finished" |
|
1314 | print "Process finished" | |
1319 |
|
1315 | |||
1320 | def start(self): |
|
1316 | def start(self): | |
1321 |
|
1317 | |||
1322 | self.writeXml() |
|
1318 | self.writeXml() | |
1323 | self.createObjects() |
|
1319 | self.createObjects() | |
1324 | self.connectObjects() |
|
1320 | self.connectObjects() | |
1325 | self.run() |
|
1321 | self.run() |
@@ -1,8 +1,7 | |||||
1 | from jroplot_voltage import * |
|
1 | from jroplot_voltage import * | |
2 | from jroplot_spectra import * |
|
2 | from jroplot_spectra import * | |
3 | from jroplot_heispectra import * |
|
3 | from jroplot_heispectra import * | |
4 | from jroplot_correlation import * |
|
4 | from jroplot_correlation import * | |
5 | from jroplot_parameters import * |
|
5 | from jroplot_parameters import * | |
6 | from jroplot_data import * |
|
6 | from jroplot_data import * | |
7 | from jroplotter import * |
|
7 | from jroplotter import * | |
8 | No newline at end of file |
|
@@ -1,690 +1,693 | |||||
1 |
|
1 | |||
2 | import os |
|
2 | import os | |
3 | import zmq |
|
3 | import zmq | |
4 | import time |
|
4 | import time | |
5 | import numpy |
|
5 | import numpy | |
6 | import datetime |
|
6 | import datetime | |
7 | import numpy as np |
|
7 | import numpy as np | |
|
8 | import matplotlib | |||
|
9 | matplotlib.use('TkAgg') | |||
8 | import matplotlib.pyplot as plt |
|
10 | import matplotlib.pyplot as plt | |
9 | from mpl_toolkits.axes_grid1 import make_axes_locatable |
|
11 | from mpl_toolkits.axes_grid1 import make_axes_locatable | |
10 | from matplotlib.ticker import FuncFormatter, LinearLocator |
|
12 | from matplotlib.ticker import FuncFormatter, LinearLocator | |
11 | from multiprocessing import Process |
|
13 | from multiprocessing import Process | |
12 |
|
14 | |||
13 | from schainpy.model.proc.jroproc_base import Operation |
|
15 | from schainpy.model.proc.jroproc_base import Operation | |
14 |
|
16 | |||
15 |
|
|
17 | plt.ioff() | |
16 |
|
18 | |||
17 | func = lambda x, pos: ('%s') %(datetime.datetime.fromtimestamp(x).strftime('%H:%M')) |
|
19 | func = lambda x, pos: ('%s') %(datetime.datetime.fromtimestamp(x).strftime('%H:%M')) | |
18 |
|
20 | |||
19 | d1970 = datetime.datetime(1970,1,1) |
|
21 | d1970 = datetime.datetime(1970,1,1) | |
20 |
|
22 | |||
21 | class PlotData(Operation, Process): |
|
23 | class PlotData(Operation, Process): | |
22 |
|
24 | |||
23 | CODE = 'Figure' |
|
25 | CODE = 'Figure' | |
24 | colormap = 'jro' |
|
26 | colormap = 'jro' | |
25 | CONFLATE = True |
|
27 | CONFLATE = True | |
26 | __MAXNUMX = 80 |
|
28 | __MAXNUMX = 80 | |
27 | __MAXNUMY = 80 |
|
29 | __MAXNUMY = 80 | |
28 | __missing = 1E30 |
|
30 | __missing = 1E30 | |
29 |
|
31 | |||
30 | def __init__(self, **kwargs): |
|
32 | def __init__(self, **kwargs): | |
31 |
|
33 | |||
32 | Operation.__init__(self, plot=True, **kwargs) |
|
34 | Operation.__init__(self, plot=True, **kwargs) | |
33 | Process.__init__(self) |
|
35 | Process.__init__(self) | |
34 | self.kwargs['code'] = self.CODE |
|
36 | self.kwargs['code'] = self.CODE | |
35 | self.mp = False |
|
37 | self.mp = False | |
36 | self.dataOut = None |
|
38 | self.dataOut = None | |
37 | self.isConfig = False |
|
39 | self.isConfig = False | |
38 | self.figure = None |
|
40 | self.figure = None | |
39 | self.axes = [] |
|
41 | self.axes = [] | |
40 | self.localtime = kwargs.pop('localtime', True) |
|
42 | self.localtime = kwargs.pop('localtime', True) | |
41 | self.show = kwargs.get('show', True) |
|
43 | self.show = kwargs.get('show', True) | |
42 | self.save = kwargs.get('save', False) |
|
44 | self.save = kwargs.get('save', False) | |
43 | self.colormap = kwargs.get('colormap', self.colormap) |
|
45 | self.colormap = kwargs.get('colormap', self.colormap) | |
44 | self.colormap_coh = kwargs.get('colormap_coh', 'jet') |
|
46 | self.colormap_coh = kwargs.get('colormap_coh', 'jet') | |
45 | self.colormap_phase = kwargs.get('colormap_phase', 'RdBu_r') |
|
47 | self.colormap_phase = kwargs.get('colormap_phase', 'RdBu_r') | |
46 | self.showprofile = kwargs.get('showprofile', True) |
|
48 | self.showprofile = kwargs.get('showprofile', True) | |
47 | self.title = kwargs.get('wintitle', '') |
|
49 | self.title = kwargs.get('wintitle', '') | |
48 | self.xaxis = kwargs.get('xaxis', 'frequency') |
|
50 | self.xaxis = kwargs.get('xaxis', 'frequency') | |
49 | self.zmin = kwargs.get('zmin', None) |
|
51 | self.zmin = kwargs.get('zmin', None) | |
50 | self.zmax = kwargs.get('zmax', None) |
|
52 | self.zmax = kwargs.get('zmax', None) | |
51 | self.xmin = kwargs.get('xmin', None) |
|
53 | self.xmin = kwargs.get('xmin', None) | |
52 | self.xmax = kwargs.get('xmax', None) |
|
54 | self.xmax = kwargs.get('xmax', None) | |
53 | self.xrange = kwargs.get('xrange', 24) |
|
55 | self.xrange = kwargs.get('xrange', 24) | |
54 | self.ymin = kwargs.get('ymin', None) |
|
56 | self.ymin = kwargs.get('ymin', None) | |
55 | self.ymax = kwargs.get('ymax', None) |
|
57 | self.ymax = kwargs.get('ymax', None) | |
56 | self.throttle_value = 5 |
|
58 | self.throttle_value = 5 | |
57 |
|
59 | |||
58 | def fill_gaps(self, x_buffer, y_buffer, z_buffer): |
|
60 | def fill_gaps(self, x_buffer, y_buffer, z_buffer): | |
59 |
|
61 | |||
60 | if x_buffer.shape[0] < 2: |
|
62 | if x_buffer.shape[0] < 2: | |
61 | return x_buffer, y_buffer, z_buffer |
|
63 | return x_buffer, y_buffer, z_buffer | |
62 |
|
64 | |||
63 | deltas = x_buffer[1:] - x_buffer[0:-1] |
|
65 | deltas = x_buffer[1:] - x_buffer[0:-1] | |
64 | x_median = np.median(deltas) |
|
66 | x_median = np.median(deltas) | |
65 |
|
67 | |||
66 | index = np.where(deltas > 5*x_median) |
|
68 | index = np.where(deltas > 5*x_median) | |
67 |
|
69 | |||
68 | if len(index[0]) != 0: |
|
70 | if len(index[0]) != 0: | |
69 | z_buffer[::, index[0], ::] = self.__missing |
|
71 | z_buffer[::, index[0], ::] = self.__missing | |
70 | z_buffer = np.ma.masked_inside(z_buffer, |
|
72 | z_buffer = np.ma.masked_inside(z_buffer, | |
71 | 0.99*self.__missing, |
|
73 | 0.99*self.__missing, | |
72 | 1.01*self.__missing) |
|
74 | 1.01*self.__missing) | |
73 |
|
75 | |||
74 | return x_buffer, y_buffer, z_buffer |
|
76 | return x_buffer, y_buffer, z_buffer | |
75 |
|
77 | |||
76 | def decimate(self): |
|
78 | def decimate(self): | |
77 |
|
79 | |||
78 | # dx = int(len(self.x)/self.__MAXNUMX) + 1 |
|
80 | # dx = int(len(self.x)/self.__MAXNUMX) + 1 | |
79 | dy = int(len(self.y)/self.__MAXNUMY) + 1 |
|
81 | dy = int(len(self.y)/self.__MAXNUMY) + 1 | |
80 |
|
82 | |||
81 | # x = self.x[::dx] |
|
83 | # x = self.x[::dx] | |
82 | x = self.x |
|
84 | x = self.x | |
83 | y = self.y[::dy] |
|
85 | y = self.y[::dy] | |
84 | z = self.z[::, ::, ::dy] |
|
86 | z = self.z[::, ::, ::dy] | |
85 |
|
87 | |||
86 | return x, y, z |
|
88 | return x, y, z | |
87 |
|
89 | |||
88 | def __plot(self): |
|
90 | def __plot(self): | |
89 |
|
91 | |||
90 | print 'plotting...{}'.format(self.CODE) |
|
92 | print 'plotting...{}'.format(self.CODE) | |
91 |
|
93 | |||
92 | if self.show: |
|
94 | if self.show: | |
|
95 | print 'showing' | |||
93 | self.figure.show() |
|
96 | self.figure.show() | |
94 |
|
97 | |||
95 | self.plot() |
|
98 | self.plot() | |
96 | plt.tight_layout() |
|
99 | plt.tight_layout() | |
97 | self.figure.canvas.manager.set_window_title('{} {} - Date:{}'.format(self.title, self.CODE.upper(), |
|
100 | self.figure.canvas.manager.set_window_title('{} {} - Date:{}'.format(self.title, self.CODE.upper(), | |
98 | datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S'))) |
|
101 | datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S'))) | |
99 |
|
102 | |||
100 | if self.save: |
|
103 | if self.save: | |
101 | figname = os.path.join(self.save, '{}_{}.png'.format(self.CODE, |
|
104 | figname = os.path.join(self.save, '{}_{}.png'.format(self.CODE, | |
102 | datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S'))) |
|
105 | datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S'))) | |
103 | print 'Saving figure: {}'.format(figname) |
|
106 | print 'Saving figure: {}'.format(figname) | |
104 | self.figure.savefig(figname) |
|
107 | self.figure.savefig(figname) | |
105 |
|
108 | |||
106 | self.figure.canvas.draw() |
|
109 | self.figure.canvas.draw() | |
107 |
|
110 | |||
108 | def plot(self): |
|
111 | def plot(self): | |
109 |
|
112 | |||
110 | print 'plotting...{}'.format(self.CODE.upper()) |
|
113 | print 'plotting...{}'.format(self.CODE.upper()) | |
111 | return |
|
114 | return | |
112 |
|
115 | |||
113 | def run(self): |
|
116 | def run(self): | |
114 |
|
117 | |||
115 | print '[Starting] {}'.format(self.name) |
|
118 | print '[Starting] {}'.format(self.name) | |
116 | context = zmq.Context() |
|
119 | context = zmq.Context() | |
117 | receiver = context.socket(zmq.SUB) |
|
120 | receiver = context.socket(zmq.SUB) | |
118 | receiver.setsockopt(zmq.SUBSCRIBE, '') |
|
121 | receiver.setsockopt(zmq.SUBSCRIBE, '') | |
119 | receiver.setsockopt(zmq.CONFLATE, self.CONFLATE) |
|
122 | receiver.setsockopt(zmq.CONFLATE, self.CONFLATE) | |
120 | receiver.connect("ipc:///tmp/zmq.plots") |
|
123 | receiver.connect("ipc:///tmp/zmq.plots") | |
121 |
|
124 | |||
122 | while True: |
|
125 | while True: | |
123 | try: |
|
126 | try: | |
124 | self.data = receiver.recv_pyobj(flags=zmq.NOBLOCK) |
|
127 | self.data = receiver.recv_pyobj(flags=zmq.NOBLOCK) | |
125 | self.dataOut = self.data['dataOut'] |
|
128 | self.dataOut = self.data['dataOut'] | |
126 | self.times = self.data['times'] |
|
129 | self.times = self.data['times'] | |
127 | self.times.sort() |
|
130 | self.times.sort() | |
128 | self.throttle_value = self.data['throttle'] |
|
131 | self.throttle_value = self.data['throttle'] | |
129 | self.min_time = self.times[0] |
|
132 | self.min_time = self.times[0] | |
130 | self.max_time = self.times[-1] |
|
133 | self.max_time = self.times[-1] | |
131 |
|
134 | |||
132 | if self.isConfig is False: |
|
135 | if self.isConfig is False: | |
133 | self.setup() |
|
136 | self.setup() | |
134 | self.isConfig = True |
|
137 | self.isConfig = True | |
135 | self.__plot() |
|
138 | self.__plot() | |
136 |
|
139 | |||
137 | if self.data['ENDED'] is True: |
|
140 | if self.data['ENDED'] is True: | |
138 | self.isConfig = False |
|
141 | self.isConfig = False | |
139 |
|
142 | |||
140 | except zmq.Again as e: |
|
143 | except zmq.Again as e: | |
141 | print 'Waiting for data...' |
|
144 | print 'Waiting for data...' | |
142 | plt.pause(self.throttle_value) |
|
145 | plt.pause(self.throttle_value) | |
143 |
|
146 | |||
144 | def close(self): |
|
147 | def close(self): | |
145 | if self.dataOut: |
|
148 | if self.dataOut: | |
146 | self.__plot() |
|
149 | self.__plot() | |
147 |
|
150 | |||
148 |
|
151 | |||
149 | class PlotSpectraData(PlotData): |
|
152 | class PlotSpectraData(PlotData): | |
150 |
|
153 | |||
151 | CODE = 'spc' |
|
154 | CODE = 'spc' | |
152 | colormap = 'jro' |
|
155 | colormap = 'jro' | |
153 | CONFLATE = False |
|
156 | CONFLATE = False | |
154 |
|
157 | |||
155 | def setup(self): |
|
158 | def setup(self): | |
156 |
|
159 | |||
157 | ncolspan = 1 |
|
160 | ncolspan = 1 | |
158 | colspan = 1 |
|
161 | colspan = 1 | |
159 | self.ncols = int(numpy.sqrt(self.dataOut.nChannels)+0.9) |
|
162 | self.ncols = int(numpy.sqrt(self.dataOut.nChannels)+0.9) | |
160 | self.nrows = int(self.dataOut.nChannels*1./self.ncols + 0.9) |
|
163 | self.nrows = int(self.dataOut.nChannels*1./self.ncols + 0.9) | |
161 | self.width = 3.6*self.ncols |
|
164 | self.width = 3.6*self.ncols | |
162 | self.height = 3.2*self.nrows |
|
165 | self.height = 3.2*self.nrows | |
163 | if self.showprofile: |
|
166 | if self.showprofile: | |
164 | ncolspan = 3 |
|
167 | ncolspan = 3 | |
165 | colspan = 2 |
|
168 | colspan = 2 | |
166 | self.width += 1.2*self.ncols |
|
169 | self.width += 1.2*self.ncols | |
167 |
|
170 | |||
168 | self.ylabel = 'Range [Km]' |
|
171 | self.ylabel = 'Range [Km]' | |
169 | self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList] |
|
172 | self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList] | |
170 |
|
173 | |||
171 | if self.figure is None: |
|
174 | if self.figure is None: | |
172 | self.figure = plt.figure(figsize=(self.width, self.height), |
|
175 | self.figure = plt.figure(figsize=(self.width, self.height), | |
173 | edgecolor='k', |
|
176 | edgecolor='k', | |
174 | facecolor='w') |
|
177 | facecolor='w') | |
175 | else: |
|
178 | else: | |
176 | self.figure.clf() |
|
179 | self.figure.clf() | |
177 |
|
180 | |||
178 | n = 0 |
|
181 | n = 0 | |
179 | for y in range(self.nrows): |
|
182 | for y in range(self.nrows): | |
180 | for x in range(self.ncols): |
|
183 | for x in range(self.ncols): | |
181 | if n >= self.dataOut.nChannels: |
|
184 | if n >= self.dataOut.nChannels: | |
182 | break |
|
185 | break | |
183 | ax = plt.subplot2grid((self.nrows, self.ncols*ncolspan), (y, x*ncolspan), 1, colspan) |
|
186 | ax = plt.subplot2grid((self.nrows, self.ncols*ncolspan), (y, x*ncolspan), 1, colspan) | |
184 | if self.showprofile: |
|
187 | if self.showprofile: | |
185 | ax.ax_profile = plt.subplot2grid((self.nrows, self.ncols*ncolspan), (y, x*ncolspan+colspan), 1, 1) |
|
188 | ax.ax_profile = plt.subplot2grid((self.nrows, self.ncols*ncolspan), (y, x*ncolspan+colspan), 1, 1) | |
186 |
|
189 | |||
187 | ax.firsttime = True |
|
190 | ax.firsttime = True | |
188 | self.axes.append(ax) |
|
191 | self.axes.append(ax) | |
189 | n += 1 |
|
192 | n += 1 | |
190 |
|
193 | |||
191 | def plot(self): |
|
194 | def plot(self): | |
192 |
|
195 | |||
193 | if self.xaxis == "frequency": |
|
196 | if self.xaxis == "frequency": | |
194 | x = self.dataOut.getFreqRange(1)/1000. |
|
197 | x = self.dataOut.getFreqRange(1)/1000. | |
195 | xlabel = "Frequency (kHz)" |
|
198 | xlabel = "Frequency (kHz)" | |
196 | elif self.xaxis == "time": |
|
199 | elif self.xaxis == "time": | |
197 | x = self.dataOut.getAcfRange(1) |
|
200 | x = self.dataOut.getAcfRange(1) | |
198 | xlabel = "Time (ms)" |
|
201 | xlabel = "Time (ms)" | |
199 | else: |
|
202 | else: | |
200 | x = self.dataOut.getVelRange(1) |
|
203 | x = self.dataOut.getVelRange(1) | |
201 | xlabel = "Velocity (m/s)" |
|
204 | xlabel = "Velocity (m/s)" | |
202 |
|
205 | |||
203 | y = self.dataOut.getHeiRange() |
|
206 | y = self.dataOut.getHeiRange() | |
204 | z = self.data[self.CODE] |
|
207 | z = self.data[self.CODE] | |
205 |
|
208 | |||
206 | for n, ax in enumerate(self.axes): |
|
209 | for n, ax in enumerate(self.axes): | |
207 |
|
210 | |||
208 | if ax.firsttime: |
|
211 | if ax.firsttime: | |
209 | self.xmax = self.xmax if self.xmax else np.nanmax(x) |
|
212 | self.xmax = self.xmax if self.xmax else np.nanmax(x) | |
210 | self.xmin = self.xmin if self.xmin else -self.xmax |
|
213 | self.xmin = self.xmin if self.xmin else -self.xmax | |
211 | self.ymin = self.ymin if self.ymin else np.nanmin(y) |
|
214 | self.ymin = self.ymin if self.ymin else np.nanmin(y) | |
212 | self.ymax = self.ymax if self.ymax else np.nanmax(y) |
|
215 | self.ymax = self.ymax if self.ymax else np.nanmax(y) | |
213 | self.zmin = self.zmin if self.zmin else np.nanmin(z) |
|
216 | self.zmin = self.zmin if self.zmin else np.nanmin(z) | |
214 | self.zmax = self.zmax if self.zmax else np.nanmax(z) |
|
217 | self.zmax = self.zmax if self.zmax else np.nanmax(z) | |
215 | ax.plot = ax.pcolormesh(x, y, z[n].T, |
|
218 | ax.plot = ax.pcolormesh(x, y, z[n].T, | |
216 | vmin=self.zmin, |
|
219 | vmin=self.zmin, | |
217 | vmax=self.zmax, |
|
220 | vmax=self.zmax, | |
218 | cmap=plt.get_cmap(self.colormap) |
|
221 | cmap=plt.get_cmap(self.colormap) | |
219 | ) |
|
222 | ) | |
220 | divider = make_axes_locatable(ax) |
|
223 | divider = make_axes_locatable(ax) | |
221 | cax = divider.new_horizontal(size='3%', pad=0.05) |
|
224 | cax = divider.new_horizontal(size='3%', pad=0.05) | |
222 | self.figure.add_axes(cax) |
|
225 | self.figure.add_axes(cax) | |
223 | plt.colorbar(ax.plot, cax) |
|
226 | plt.colorbar(ax.plot, cax) | |
224 |
|
227 | |||
225 | ax.set_xlim(self.xmin, self.xmax) |
|
228 | ax.set_xlim(self.xmin, self.xmax) | |
226 | ax.set_ylim(self.ymin, self.ymax) |
|
229 | ax.set_ylim(self.ymin, self.ymax) | |
227 |
|
230 | |||
228 | ax.set_ylabel(self.ylabel) |
|
231 | ax.set_ylabel(self.ylabel) | |
229 | ax.set_xlabel(xlabel) |
|
232 | ax.set_xlabel(xlabel) | |
230 |
|
233 | |||
231 | ax.firsttime = False |
|
234 | ax.firsttime = False | |
232 |
|
235 | |||
233 | if self.showprofile: |
|
236 | if self.showprofile: | |
234 | ax.plot_profile= ax.ax_profile.plot(self.data['rti'][self.max_time][n], y)[0] |
|
237 | ax.plot_profile= ax.ax_profile.plot(self.data['rti'][self.max_time][n], y)[0] | |
235 | ax.ax_profile.set_xlim(self.zmin, self.zmax) |
|
238 | ax.ax_profile.set_xlim(self.zmin, self.zmax) | |
236 | ax.ax_profile.set_ylim(self.ymin, self.ymax) |
|
239 | ax.ax_profile.set_ylim(self.ymin, self.ymax) | |
237 | ax.ax_profile.set_xlabel('dB') |
|
240 | ax.ax_profile.set_xlabel('dB') | |
238 | ax.ax_profile.grid(b=True, axis='x') |
|
241 | ax.ax_profile.grid(b=True, axis='x') | |
239 | ax.plot_noise = ax.ax_profile.plot(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y, |
|
242 | ax.plot_noise = ax.ax_profile.plot(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y, | |
240 | color="k", linestyle="dashed", lw=2)[0] |
|
243 | color="k", linestyle="dashed", lw=2)[0] | |
241 | [tick.set_visible(False) for tick in ax.ax_profile.get_yticklabels()] |
|
244 | [tick.set_visible(False) for tick in ax.ax_profile.get_yticklabels()] | |
242 | else: |
|
245 | else: | |
243 | ax.plot.set_array(z[n].T.ravel()) |
|
246 | ax.plot.set_array(z[n].T.ravel()) | |
244 | if self.showprofile: |
|
247 | if self.showprofile: | |
245 | ax.plot_profile.set_data(self.data['rti'][self.max_time][n], y) |
|
248 | ax.plot_profile.set_data(self.data['rti'][self.max_time][n], y) | |
246 | ax.plot_noise.set_data(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y) |
|
249 | ax.plot_noise.set_data(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y) | |
247 |
|
250 | |||
248 | ax.set_title('{} - Noise: {:.2f} dB'.format(self.titles[n], self.data['noise'][self.max_time][n]), |
|
251 | ax.set_title('{} - Noise: {:.2f} dB'.format(self.titles[n], self.data['noise'][self.max_time][n]), | |
249 | size=8) |
|
252 | size=8) | |
250 | self.saveTime = self.max_time |
|
253 | self.saveTime = self.max_time | |
251 |
|
254 | |||
252 |
|
255 | |||
253 | class PlotCrossSpectraData(PlotData): |
|
256 | class PlotCrossSpectraData(PlotData): | |
254 |
|
257 | |||
255 | CODE = 'cspc' |
|
258 | CODE = 'cspc' | |
256 | zmin_coh = None |
|
259 | zmin_coh = None | |
257 | zmax_coh = None |
|
260 | zmax_coh = None | |
258 | zmin_phase = None |
|
261 | zmin_phase = None | |
259 | zmax_phase = None |
|
262 | zmax_phase = None | |
260 | CONFLATE = False |
|
263 | CONFLATE = False | |
261 |
|
264 | |||
262 | def setup(self): |
|
265 | def setup(self): | |
263 |
|
266 | |||
264 | ncolspan = 1 |
|
267 | ncolspan = 1 | |
265 | colspan = 1 |
|
268 | colspan = 1 | |
266 | self.ncols = 2 |
|
269 | self.ncols = 2 | |
267 | self.nrows = self.dataOut.nPairs |
|
270 | self.nrows = self.dataOut.nPairs | |
268 | self.width = 3.6*self.ncols |
|
271 | self.width = 3.6*self.ncols | |
269 | self.height = 3.2*self.nrows |
|
272 | self.height = 3.2*self.nrows | |
270 |
|
273 | |||
271 | self.ylabel = 'Range [Km]' |
|
274 | self.ylabel = 'Range [Km]' | |
272 | self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList] |
|
275 | self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList] | |
273 |
|
276 | |||
274 | if self.figure is None: |
|
277 | if self.figure is None: | |
275 | self.figure = plt.figure(figsize=(self.width, self.height), |
|
278 | self.figure = plt.figure(figsize=(self.width, self.height), | |
276 | edgecolor='k', |
|
279 | edgecolor='k', | |
277 | facecolor='w') |
|
280 | facecolor='w') | |
278 | else: |
|
281 | else: | |
279 | self.figure.clf() |
|
282 | self.figure.clf() | |
280 |
|
283 | |||
281 | for y in range(self.nrows): |
|
284 | for y in range(self.nrows): | |
282 | for x in range(self.ncols): |
|
285 | for x in range(self.ncols): | |
283 | ax = plt.subplot2grid((self.nrows, self.ncols), (y, x), 1, 1) |
|
286 | ax = plt.subplot2grid((self.nrows, self.ncols), (y, x), 1, 1) | |
284 | ax.firsttime = True |
|
287 | ax.firsttime = True | |
285 | self.axes.append(ax) |
|
288 | self.axes.append(ax) | |
286 |
|
289 | |||
287 | def plot(self): |
|
290 | def plot(self): | |
288 |
|
291 | |||
289 | if self.xaxis == "frequency": |
|
292 | if self.xaxis == "frequency": | |
290 | x = self.dataOut.getFreqRange(1)/1000. |
|
293 | x = self.dataOut.getFreqRange(1)/1000. | |
291 | xlabel = "Frequency (kHz)" |
|
294 | xlabel = "Frequency (kHz)" | |
292 | elif self.xaxis == "time": |
|
295 | elif self.xaxis == "time": | |
293 | x = self.dataOut.getAcfRange(1) |
|
296 | x = self.dataOut.getAcfRange(1) | |
294 | xlabel = "Time (ms)" |
|
297 | xlabel = "Time (ms)" | |
295 | else: |
|
298 | else: | |
296 | x = self.dataOut.getVelRange(1) |
|
299 | x = self.dataOut.getVelRange(1) | |
297 | xlabel = "Velocity (m/s)" |
|
300 | xlabel = "Velocity (m/s)" | |
298 |
|
301 | |||
299 | y = self.dataOut.getHeiRange() |
|
302 | y = self.dataOut.getHeiRange() | |
300 | z_coh = self.data['cspc_coh'] |
|
303 | z_coh = self.data['cspc_coh'] | |
301 | z_phase = self.data['cspc_phase'] |
|
304 | z_phase = self.data['cspc_phase'] | |
302 |
|
305 | |||
303 | for n in range(self.nrows): |
|
306 | for n in range(self.nrows): | |
304 | ax = self.axes[2*n] |
|
307 | ax = self.axes[2*n] | |
305 | ax1 = self.axes[2*n+1] |
|
308 | ax1 = self.axes[2*n+1] | |
306 | if ax.firsttime: |
|
309 | if ax.firsttime: | |
307 | self.xmax = self.xmax if self.xmax else np.nanmax(x) |
|
310 | self.xmax = self.xmax if self.xmax else np.nanmax(x) | |
308 | self.xmin = self.xmin if self.xmin else -self.xmax |
|
311 | self.xmin = self.xmin if self.xmin else -self.xmax | |
309 | self.ymin = self.ymin if self.ymin else np.nanmin(y) |
|
312 | self.ymin = self.ymin if self.ymin else np.nanmin(y) | |
310 | self.ymax = self.ymax if self.ymax else np.nanmax(y) |
|
313 | self.ymax = self.ymax if self.ymax else np.nanmax(y) | |
311 | self.zmin_coh = self.zmin_coh if self.zmin_coh else 0.0 |
|
314 | self.zmin_coh = self.zmin_coh if self.zmin_coh else 0.0 | |
312 | self.zmax_coh = self.zmax_coh if self.zmax_coh else 1.0 |
|
315 | self.zmax_coh = self.zmax_coh if self.zmax_coh else 1.0 | |
313 | self.zmin_phase = self.zmin_phase if self.zmin_phase else -180 |
|
316 | self.zmin_phase = self.zmin_phase if self.zmin_phase else -180 | |
314 | self.zmax_phase = self.zmax_phase if self.zmax_phase else 180 |
|
317 | self.zmax_phase = self.zmax_phase if self.zmax_phase else 180 | |
315 |
|
318 | |||
316 | ax.plot = ax.pcolormesh(x, y, z_coh[n].T, |
|
319 | ax.plot = ax.pcolormesh(x, y, z_coh[n].T, | |
317 | vmin=self.zmin_coh, |
|
320 | vmin=self.zmin_coh, | |
318 | vmax=self.zmax_coh, |
|
321 | vmax=self.zmax_coh, | |
319 | cmap=plt.get_cmap(self.colormap_coh) |
|
322 | cmap=plt.get_cmap(self.colormap_coh) | |
320 | ) |
|
323 | ) | |
321 | divider = make_axes_locatable(ax) |
|
324 | divider = make_axes_locatable(ax) | |
322 | cax = divider.new_horizontal(size='3%', pad=0.05) |
|
325 | cax = divider.new_horizontal(size='3%', pad=0.05) | |
323 | self.figure.add_axes(cax) |
|
326 | self.figure.add_axes(cax) | |
324 | plt.colorbar(ax.plot, cax) |
|
327 | plt.colorbar(ax.plot, cax) | |
325 |
|
328 | |||
326 | ax.set_xlim(self.xmin, self.xmax) |
|
329 | ax.set_xlim(self.xmin, self.xmax) | |
327 | ax.set_ylim(self.ymin, self.ymax) |
|
330 | ax.set_ylim(self.ymin, self.ymax) | |
328 |
|
331 | |||
329 | ax.set_ylabel(self.ylabel) |
|
332 | ax.set_ylabel(self.ylabel) | |
330 | ax.set_xlabel(xlabel) |
|
333 | ax.set_xlabel(xlabel) | |
331 | ax.firsttime = False |
|
334 | ax.firsttime = False | |
332 |
|
335 | |||
333 | ax1.plot = ax1.pcolormesh(x, y, z_phase[n].T, |
|
336 | ax1.plot = ax1.pcolormesh(x, y, z_phase[n].T, | |
334 | vmin=self.zmin_phase, |
|
337 | vmin=self.zmin_phase, | |
335 | vmax=self.zmax_phase, |
|
338 | vmax=self.zmax_phase, | |
336 | cmap=plt.get_cmap(self.colormap_phase) |
|
339 | cmap=plt.get_cmap(self.colormap_phase) | |
337 | ) |
|
340 | ) | |
338 | divider = make_axes_locatable(ax1) |
|
341 | divider = make_axes_locatable(ax1) | |
339 | cax = divider.new_horizontal(size='3%', pad=0.05) |
|
342 | cax = divider.new_horizontal(size='3%', pad=0.05) | |
340 | self.figure.add_axes(cax) |
|
343 | self.figure.add_axes(cax) | |
341 | plt.colorbar(ax1.plot, cax) |
|
344 | plt.colorbar(ax1.plot, cax) | |
342 |
|
345 | |||
343 | ax1.set_xlim(self.xmin, self.xmax) |
|
346 | ax1.set_xlim(self.xmin, self.xmax) | |
344 | ax1.set_ylim(self.ymin, self.ymax) |
|
347 | ax1.set_ylim(self.ymin, self.ymax) | |
345 |
|
348 | |||
346 | ax1.set_ylabel(self.ylabel) |
|
349 | ax1.set_ylabel(self.ylabel) | |
347 | ax1.set_xlabel(xlabel) |
|
350 | ax1.set_xlabel(xlabel) | |
348 | ax1.firsttime = False |
|
351 | ax1.firsttime = False | |
349 | else: |
|
352 | else: | |
350 | ax.plot.set_array(z_coh[n].T.ravel()) |
|
353 | ax.plot.set_array(z_coh[n].T.ravel()) | |
351 | ax1.plot.set_array(z_phase[n].T.ravel()) |
|
354 | ax1.plot.set_array(z_phase[n].T.ravel()) | |
352 |
|
355 | |||
353 | ax.set_title('Coherence Ch{} * Ch{}'.format(self.dataOut.pairsList[n][0], self.dataOut.pairsList[n][1]), size=8) |
|
356 | ax.set_title('Coherence Ch{} * Ch{}'.format(self.dataOut.pairsList[n][0], self.dataOut.pairsList[n][1]), size=8) | |
354 | ax1.set_title('Phase Ch{} * Ch{}'.format(self.dataOut.pairsList[n][0], self.dataOut.pairsList[n][1]), size=8) |
|
357 | ax1.set_title('Phase Ch{} * Ch{}'.format(self.dataOut.pairsList[n][0], self.dataOut.pairsList[n][1]), size=8) | |
355 | self.saveTime = self.max_time |
|
358 | self.saveTime = self.max_time | |
356 |
|
359 | |||
357 |
|
360 | |||
358 | class PlotSpectraMeanData(PlotSpectraData): |
|
361 | class PlotSpectraMeanData(PlotSpectraData): | |
359 |
|
362 | |||
360 | CODE = 'spc_mean' |
|
363 | CODE = 'spc_mean' | |
361 | colormap = 'jet' |
|
364 | colormap = 'jet' | |
362 |
|
365 | |||
363 | def plot(self): |
|
366 | def plot(self): | |
364 |
|
367 | |||
365 | if self.xaxis == "frequency": |
|
368 | if self.xaxis == "frequency": | |
366 | x = self.dataOut.getFreqRange(1)/1000. |
|
369 | x = self.dataOut.getFreqRange(1)/1000. | |
367 | xlabel = "Frequency (kHz)" |
|
370 | xlabel = "Frequency (kHz)" | |
368 | elif self.xaxis == "time": |
|
371 | elif self.xaxis == "time": | |
369 | x = self.dataOut.getAcfRange(1) |
|
372 | x = self.dataOut.getAcfRange(1) | |
370 | xlabel = "Time (ms)" |
|
373 | xlabel = "Time (ms)" | |
371 | else: |
|
374 | else: | |
372 | x = self.dataOut.getVelRange(1) |
|
375 | x = self.dataOut.getVelRange(1) | |
373 | xlabel = "Velocity (m/s)" |
|
376 | xlabel = "Velocity (m/s)" | |
374 |
|
377 | |||
375 | y = self.dataOut.getHeiRange() |
|
378 | y = self.dataOut.getHeiRange() | |
376 | z = self.data['spc'] |
|
379 | z = self.data['spc'] | |
377 | mean = self.data['mean'][self.max_time] |
|
380 | mean = self.data['mean'][self.max_time] | |
378 |
|
381 | |||
379 | for n, ax in enumerate(self.axes): |
|
382 | for n, ax in enumerate(self.axes): | |
380 |
|
383 | |||
381 | if ax.firsttime: |
|
384 | if ax.firsttime: | |
382 | self.xmax = self.xmax if self.xmax else np.nanmax(x) |
|
385 | self.xmax = self.xmax if self.xmax else np.nanmax(x) | |
383 | self.xmin = self.xmin if self.xmin else -self.xmax |
|
386 | self.xmin = self.xmin if self.xmin else -self.xmax | |
384 | self.ymin = self.ymin if self.ymin else np.nanmin(y) |
|
387 | self.ymin = self.ymin if self.ymin else np.nanmin(y) | |
385 | self.ymax = self.ymax if self.ymax else np.nanmax(y) |
|
388 | self.ymax = self.ymax if self.ymax else np.nanmax(y) | |
386 | self.zmin = self.zmin if self.zmin else np.nanmin(z) |
|
389 | self.zmin = self.zmin if self.zmin else np.nanmin(z) | |
387 | self.zmax = self.zmax if self.zmax else np.nanmax(z) |
|
390 | self.zmax = self.zmax if self.zmax else np.nanmax(z) | |
388 | ax.plt = ax.pcolormesh(x, y, z[n].T, |
|
391 | ax.plt = ax.pcolormesh(x, y, z[n].T, | |
389 | vmin=self.zmin, |
|
392 | vmin=self.zmin, | |
390 | vmax=self.zmax, |
|
393 | vmax=self.zmax, | |
391 | cmap=plt.get_cmap(self.colormap) |
|
394 | cmap=plt.get_cmap(self.colormap) | |
392 | ) |
|
395 | ) | |
393 | ax.plt_dop = ax.plot(mean[n], y, |
|
396 | ax.plt_dop = ax.plot(mean[n], y, | |
394 | color='k')[0] |
|
397 | color='k')[0] | |
395 |
|
398 | |||
396 | divider = make_axes_locatable(ax) |
|
399 | divider = make_axes_locatable(ax) | |
397 | cax = divider.new_horizontal(size='3%', pad=0.05) |
|
400 | cax = divider.new_horizontal(size='3%', pad=0.05) | |
398 | self.figure.add_axes(cax) |
|
401 | self.figure.add_axes(cax) | |
399 | plt.colorbar(ax.plt, cax) |
|
402 | plt.colorbar(ax.plt, cax) | |
400 |
|
403 | |||
401 | ax.set_xlim(self.xmin, self.xmax) |
|
404 | ax.set_xlim(self.xmin, self.xmax) | |
402 | ax.set_ylim(self.ymin, self.ymax) |
|
405 | ax.set_ylim(self.ymin, self.ymax) | |
403 |
|
406 | |||
404 | ax.set_ylabel(self.ylabel) |
|
407 | ax.set_ylabel(self.ylabel) | |
405 | ax.set_xlabel(xlabel) |
|
408 | ax.set_xlabel(xlabel) | |
406 |
|
409 | |||
407 | ax.firsttime = False |
|
410 | ax.firsttime = False | |
408 |
|
411 | |||
409 | if self.showprofile: |
|
412 | if self.showprofile: | |
410 | ax.plt_profile= ax.ax_profile.plot(self.data['rti'][self.max_time][n], y)[0] |
|
413 | ax.plt_profile= ax.ax_profile.plot(self.data['rti'][self.max_time][n], y)[0] | |
411 | ax.ax_profile.set_xlim(self.zmin, self.zmax) |
|
414 | ax.ax_profile.set_xlim(self.zmin, self.zmax) | |
412 | ax.ax_profile.set_ylim(self.ymin, self.ymax) |
|
415 | ax.ax_profile.set_ylim(self.ymin, self.ymax) | |
413 | ax.ax_profile.set_xlabel('dB') |
|
416 | ax.ax_profile.set_xlabel('dB') | |
414 | ax.ax_profile.grid(b=True, axis='x') |
|
417 | ax.ax_profile.grid(b=True, axis='x') | |
415 | ax.plt_noise = ax.ax_profile.plot(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y, |
|
418 | ax.plt_noise = ax.ax_profile.plot(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y, | |
416 | color="k", linestyle="dashed", lw=2)[0] |
|
419 | color="k", linestyle="dashed", lw=2)[0] | |
417 | [tick.set_visible(False) for tick in ax.ax_profile.get_yticklabels()] |
|
420 | [tick.set_visible(False) for tick in ax.ax_profile.get_yticklabels()] | |
418 | else: |
|
421 | else: | |
419 | ax.plt.set_array(z[n].T.ravel()) |
|
422 | ax.plt.set_array(z[n].T.ravel()) | |
420 | ax.plt_dop.set_data(mean[n], y) |
|
423 | ax.plt_dop.set_data(mean[n], y) | |
421 | if self.showprofile: |
|
424 | if self.showprofile: | |
422 | ax.plt_profile.set_data(self.data['rti'][self.max_time][n], y) |
|
425 | ax.plt_profile.set_data(self.data['rti'][self.max_time][n], y) | |
423 | ax.plt_noise.set_data(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y) |
|
426 | ax.plt_noise.set_data(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y) | |
424 |
|
427 | |||
425 | ax.set_title('{} - Noise: {:.2f} dB'.format(self.titles[n], self.data['noise'][self.max_time][n]), |
|
428 | ax.set_title('{} - Noise: {:.2f} dB'.format(self.titles[n], self.data['noise'][self.max_time][n]), | |
426 | size=8) |
|
429 | size=8) | |
427 | self.saveTime = self.max_time |
|
430 | self.saveTime = self.max_time | |
428 |
|
431 | |||
429 |
|
432 | |||
430 | class PlotRTIData(PlotData): |
|
433 | class PlotRTIData(PlotData): | |
431 |
|
434 | |||
432 | CODE = 'rti' |
|
435 | CODE = 'rti' | |
433 | colormap = 'jro' |
|
436 | colormap = 'jro' | |
434 |
|
437 | |||
435 | def setup(self): |
|
438 | def setup(self): | |
436 | self.ncols = 1 |
|
439 | self.ncols = 1 | |
437 | self.nrows = self.dataOut.nChannels |
|
440 | self.nrows = self.dataOut.nChannels | |
438 | self.width = 10 |
|
441 | self.width = 10 | |
439 | self.height = 2.2*self.nrows if self.nrows<6 else 12 |
|
442 | self.height = 2.2*self.nrows if self.nrows<6 else 12 | |
440 | if self.nrows==1: |
|
443 | if self.nrows==1: | |
441 | self.height += 1 |
|
444 | self.height += 1 | |
442 | self.ylabel = 'Range [Km]' |
|
445 | self.ylabel = 'Range [Km]' | |
443 | self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList] |
|
446 | self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList] | |
444 |
|
447 | |||
445 | if self.figure is None: |
|
448 | if self.figure is None: | |
446 | self.figure = plt.figure(figsize=(self.width, self.height), |
|
449 | self.figure = plt.figure(figsize=(self.width, self.height), | |
447 | edgecolor='k', |
|
450 | edgecolor='k', | |
448 | facecolor='w') |
|
451 | facecolor='w') | |
449 | else: |
|
452 | else: | |
450 | self.figure.clf() |
|
453 | self.figure.clf() | |
451 | self.axes = [] |
|
454 | self.axes = [] | |
452 |
|
455 | |||
453 | for n in range(self.nrows): |
|
456 | for n in range(self.nrows): | |
454 | ax = self.figure.add_subplot(self.nrows, self.ncols, n+1) |
|
457 | ax = self.figure.add_subplot(self.nrows, self.ncols, n+1) | |
455 | ax.firsttime = True |
|
458 | ax.firsttime = True | |
456 | self.axes.append(ax) |
|
459 | self.axes.append(ax) | |
457 |
|
460 | |||
458 | def plot(self): |
|
461 | def plot(self): | |
459 |
|
462 | |||
460 | self.x = np.array(self.times) |
|
463 | self.x = np.array(self.times) | |
461 | self.y = self.dataOut.getHeiRange() |
|
464 | self.y = self.dataOut.getHeiRange() | |
462 | self.z = [] |
|
465 | self.z = [] | |
463 |
|
466 | |||
464 | for ch in range(self.nrows): |
|
467 | for ch in range(self.nrows): | |
465 | self.z.append([self.data[self.CODE][t][ch] for t in self.times]) |
|
468 | self.z.append([self.data[self.CODE][t][ch] for t in self.times]) | |
466 |
|
469 | |||
467 | self.z = np.array(self.z) |
|
470 | self.z = np.array(self.z) | |
468 | for n, ax in enumerate(self.axes): |
|
471 | for n, ax in enumerate(self.axes): | |
469 |
|
472 | |||
470 | x, y, z = self.fill_gaps(*self.decimate()) |
|
473 | x, y, z = self.fill_gaps(*self.decimate()) | |
471 | xmin = self.min_time |
|
474 | xmin = self.min_time | |
472 | xmax = xmin+self.xrange*60*60 |
|
475 | xmax = xmin+self.xrange*60*60 | |
473 | if ax.firsttime: |
|
476 | if ax.firsttime: | |
474 | self.ymin = self.ymin if self.ymin else np.nanmin(self.y) |
|
477 | self.ymin = self.ymin if self.ymin else np.nanmin(self.y) | |
475 | self.ymax = self.ymax if self.ymax else np.nanmax(self.y) |
|
478 | self.ymax = self.ymax if self.ymax else np.nanmax(self.y) | |
476 | self.zmin = self.zmin if self.zmin else np.nanmin(self.z) |
|
479 | self.zmin = self.zmin if self.zmin else np.nanmin(self.z) | |
477 | self.zmax = self.zmax if self.zmax else np.nanmax(self.z) |
|
480 | self.zmax = self.zmax if self.zmax else np.nanmax(self.z) | |
478 | plot = ax.pcolormesh(x, y, z[n].T, |
|
481 | plot = ax.pcolormesh(x, y, z[n].T, | |
479 | vmin=self.zmin, |
|
482 | vmin=self.zmin, | |
480 | vmax=self.zmax, |
|
483 | vmax=self.zmax, | |
481 | cmap=plt.get_cmap(self.colormap) |
|
484 | cmap=plt.get_cmap(self.colormap) | |
482 | ) |
|
485 | ) | |
483 | divider = make_axes_locatable(ax) |
|
486 | divider = make_axes_locatable(ax) | |
484 | cax = divider.new_horizontal(size='2%', pad=0.05) |
|
487 | cax = divider.new_horizontal(size='2%', pad=0.05) | |
485 | self.figure.add_axes(cax) |
|
488 | self.figure.add_axes(cax) | |
486 | plt.colorbar(plot, cax) |
|
489 | plt.colorbar(plot, cax) | |
487 | ax.set_ylim(self.ymin, self.ymax) |
|
490 | ax.set_ylim(self.ymin, self.ymax) | |
488 |
|
491 | |||
489 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
492 | ax.xaxis.set_major_formatter(FuncFormatter(func)) | |
490 | ax.xaxis.set_major_locator(LinearLocator(6)) |
|
493 | ax.xaxis.set_major_locator(LinearLocator(6)) | |
491 |
|
494 | |||
492 | ax.set_ylabel(self.ylabel) |
|
495 | ax.set_ylabel(self.ylabel) | |
493 |
|
496 | |||
494 | # if self.xmin is None: |
|
497 | # if self.xmin is None: | |
495 | # xmin = self.min_time |
|
498 | # xmin = self.min_time | |
496 | # else: |
|
499 | # else: | |
497 | # xmin = (datetime.datetime.combine(self.dataOut.datatime.date(), |
|
500 | # xmin = (datetime.datetime.combine(self.dataOut.datatime.date(), | |
498 | # datetime.time(self.xmin, 0, 0))-d1970).total_seconds() |
|
501 | # datetime.time(self.xmin, 0, 0))-d1970).total_seconds() | |
499 |
|
502 | |||
500 | ax.set_xlim(xmin, xmax) |
|
503 | ax.set_xlim(xmin, xmax) | |
501 | ax.firsttime = False |
|
504 | ax.firsttime = False | |
502 | else: |
|
505 | else: | |
503 | ax.collections.remove(ax.collections[0]) |
|
506 | ax.collections.remove(ax.collections[0]) | |
504 | ax.set_xlim(xmin, xmax) |
|
507 | ax.set_xlim(xmin, xmax) | |
505 | plot = ax.pcolormesh(x, y, z[n].T, |
|
508 | plot = ax.pcolormesh(x, y, z[n].T, | |
506 | vmin=self.zmin, |
|
509 | vmin=self.zmin, | |
507 | vmax=self.zmax, |
|
510 | vmax=self.zmax, | |
508 | cmap=plt.get_cmap(self.colormap) |
|
511 | cmap=plt.get_cmap(self.colormap) | |
509 | ) |
|
512 | ) | |
510 | ax.set_title('{} {}'.format(self.titles[n], |
|
513 | ax.set_title('{} {}'.format(self.titles[n], | |
511 | datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')), |
|
514 | datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')), | |
512 | size=8) |
|
515 | size=8) | |
513 |
|
516 | |||
514 | self.saveTime = self.min_time |
|
517 | self.saveTime = self.min_time | |
515 |
|
518 | |||
516 |
|
519 | |||
517 | class PlotCOHData(PlotRTIData): |
|
520 | class PlotCOHData(PlotRTIData): | |
518 |
|
521 | |||
519 | CODE = 'coh' |
|
522 | CODE = 'coh' | |
520 |
|
523 | |||
521 | def setup(self): |
|
524 | def setup(self): | |
522 |
|
525 | |||
523 | self.ncols = 1 |
|
526 | self.ncols = 1 | |
524 | self.nrows = self.dataOut.nPairs |
|
527 | self.nrows = self.dataOut.nPairs | |
525 | self.width = 10 |
|
528 | self.width = 10 | |
526 | self.height = 2.2*self.nrows if self.nrows<6 else 12 |
|
529 | self.height = 2.2*self.nrows if self.nrows<6 else 12 | |
527 | if self.nrows==1: |
|
530 | if self.nrows==1: | |
528 | self.height += 1 |
|
531 | self.height += 1 | |
529 | self.ylabel = 'Range [Km]' |
|
532 | self.ylabel = 'Range [Km]' | |
530 | self.titles = ['{} Ch{} * Ch{}'.format(self.CODE.upper(), x[0], x[1]) for x in self.dataOut.pairsList] |
|
533 | self.titles = ['{} Ch{} * Ch{}'.format(self.CODE.upper(), x[0], x[1]) for x in self.dataOut.pairsList] | |
531 |
|
534 | |||
532 | if self.figure is None: |
|
535 | if self.figure is None: | |
533 | self.figure = plt.figure(figsize=(self.width, self.height), |
|
536 | self.figure = plt.figure(figsize=(self.width, self.height), | |
534 | edgecolor='k', |
|
537 | edgecolor='k', | |
535 | facecolor='w') |
|
538 | facecolor='w') | |
536 | else: |
|
539 | else: | |
537 | self.figure.clf() |
|
540 | self.figure.clf() | |
538 | self.axes = [] |
|
541 | self.axes = [] | |
539 |
|
542 | |||
540 | for n in range(self.nrows): |
|
543 | for n in range(self.nrows): | |
541 | ax = self.figure.add_subplot(self.nrows, self.ncols, n+1) |
|
544 | ax = self.figure.add_subplot(self.nrows, self.ncols, n+1) | |
542 | ax.firsttime = True |
|
545 | ax.firsttime = True | |
543 | self.axes.append(ax) |
|
546 | self.axes.append(ax) | |
544 |
|
547 | |||
545 |
|
548 | |||
546 | class PlotNoiseData(PlotData): |
|
549 | class PlotNoiseData(PlotData): | |
547 | CODE = 'noise' |
|
550 | CODE = 'noise' | |
548 |
|
551 | |||
549 | def setup(self): |
|
552 | def setup(self): | |
550 |
|
553 | |||
551 | self.ncols = 1 |
|
554 | self.ncols = 1 | |
552 | self.nrows = 1 |
|
555 | self.nrows = 1 | |
553 | self.width = 10 |
|
556 | self.width = 10 | |
554 | self.height = 3.2 |
|
557 | self.height = 3.2 | |
555 | self.ylabel = 'Intensity [dB]' |
|
558 | self.ylabel = 'Intensity [dB]' | |
556 | self.titles = ['Noise'] |
|
559 | self.titles = ['Noise'] | |
557 |
|
560 | |||
558 | if self.figure is None: |
|
561 | if self.figure is None: | |
559 | self.figure = plt.figure(figsize=(self.width, self.height), |
|
562 | self.figure = plt.figure(figsize=(self.width, self.height), | |
560 | edgecolor='k', |
|
563 | edgecolor='k', | |
561 | facecolor='w') |
|
564 | facecolor='w') | |
562 | else: |
|
565 | else: | |
563 | self.figure.clf() |
|
566 | self.figure.clf() | |
564 | self.axes = [] |
|
567 | self.axes = [] | |
565 |
|
568 | |||
566 | self.ax = self.figure.add_subplot(self.nrows, self.ncols, 1) |
|
569 | self.ax = self.figure.add_subplot(self.nrows, self.ncols, 1) | |
567 | self.ax.firsttime = True |
|
570 | self.ax.firsttime = True | |
568 |
|
571 | |||
569 | def plot(self): |
|
572 | def plot(self): | |
570 |
|
573 | |||
571 | x = self.times |
|
574 | x = self.times | |
572 | xmin = self.min_time |
|
575 | xmin = self.min_time | |
573 | xmax = xmin+self.xrange*60*60 |
|
576 | xmax = xmin+self.xrange*60*60 | |
574 | if self.ax.firsttime: |
|
577 | if self.ax.firsttime: | |
575 | for ch in self.dataOut.channelList: |
|
578 | for ch in self.dataOut.channelList: | |
576 | y = [self.data[self.CODE][t][ch] for t in self.times] |
|
579 | y = [self.data[self.CODE][t][ch] for t in self.times] | |
577 | self.ax.plot(x, y, lw=1, label='Ch{}'.format(ch)) |
|
580 | self.ax.plot(x, y, lw=1, label='Ch{}'.format(ch)) | |
578 | self.ax.firsttime = False |
|
581 | self.ax.firsttime = False | |
579 | self.ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
582 | self.ax.xaxis.set_major_formatter(FuncFormatter(func)) | |
580 | self.ax.xaxis.set_major_locator(LinearLocator(6)) |
|
583 | self.ax.xaxis.set_major_locator(LinearLocator(6)) | |
581 | self.ax.set_ylabel(self.ylabel) |
|
584 | self.ax.set_ylabel(self.ylabel) | |
582 | plt.legend() |
|
585 | plt.legend() | |
583 | else: |
|
586 | else: | |
584 | for ch in self.dataOut.channelList: |
|
587 | for ch in self.dataOut.channelList: | |
585 | y = [self.data[self.CODE][t][ch] for t in self.times] |
|
588 | y = [self.data[self.CODE][t][ch] for t in self.times] | |
586 | self.ax.lines[ch].set_data(x, y) |
|
589 | self.ax.lines[ch].set_data(x, y) | |
587 |
|
590 | |||
588 | self.ax.set_xlim(xmin, xmax) |
|
591 | self.ax.set_xlim(xmin, xmax) | |
589 | self.ax.set_ylim(min(y)-5, max(y)+5) |
|
592 | self.ax.set_ylim(min(y)-5, max(y)+5) | |
590 | self.saveTime = self.min_time |
|
593 | self.saveTime = self.min_time | |
591 |
|
594 | |||
592 |
|
595 | |||
593 | class PlotWindProfilerData(PlotRTIData): |
|
596 | class PlotWindProfilerData(PlotRTIData): | |
594 | CODE = 'wind' |
|
597 | CODE = 'wind' | |
595 | colormap = 'seismic' |
|
598 | colormap = 'seismic' | |
596 |
|
599 | |||
597 | def setup(self): |
|
600 | def setup(self): | |
598 | self.ncols = 1 |
|
601 | self.ncols = 1 | |
599 | self.nrows = self.dataOut.data_output.shape[0] |
|
602 | self.nrows = self.dataOut.data_output.shape[0] | |
600 | self.width = 10 |
|
603 | self.width = 10 | |
601 | self.height = 2.2*self.nrows |
|
604 | self.height = 2.2*self.nrows | |
602 | self.ylabel = 'Height [Km]' |
|
605 | self.ylabel = 'Height [Km]' | |
603 | self.titles = ['Zonal' ,'Meridional', 'Vertical'] |
|
606 | self.titles = ['Zonal' ,'Meridional', 'Vertical'] | |
604 | self.clabels = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)'] |
|
607 | self.clabels = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)'] | |
605 | self.windFactor = [1, 1, 100] |
|
608 | self.windFactor = [1, 1, 100] | |
606 |
|
609 | |||
607 | if self.figure is None: |
|
610 | if self.figure is None: | |
608 | self.figure = plt.figure(figsize=(self.width, self.height), |
|
611 | self.figure = plt.figure(figsize=(self.width, self.height), | |
609 | edgecolor='k', |
|
612 | edgecolor='k', | |
610 | facecolor='w') |
|
613 | facecolor='w') | |
611 | else: |
|
614 | else: | |
612 | self.figure.clf() |
|
615 | self.figure.clf() | |
613 | self.axes = [] |
|
616 | self.axes = [] | |
614 |
|
617 | |||
615 | for n in range(self.nrows): |
|
618 | for n in range(self.nrows): | |
616 | ax = self.figure.add_subplot(self.nrows, self.ncols, n+1) |
|
619 | ax = self.figure.add_subplot(self.nrows, self.ncols, n+1) | |
617 | ax.firsttime = True |
|
620 | ax.firsttime = True | |
618 | self.axes.append(ax) |
|
621 | self.axes.append(ax) | |
619 |
|
622 | |||
620 | def plot(self): |
|
623 | def plot(self): | |
621 |
|
624 | |||
622 | self.x = np.array(self.times) |
|
625 | self.x = np.array(self.times) | |
623 | self.y = self.dataOut.heightList |
|
626 | self.y = self.dataOut.heightList | |
624 | self.z = [] |
|
627 | self.z = [] | |
625 |
|
628 | |||
626 | for ch in range(self.nrows): |
|
629 | for ch in range(self.nrows): | |
627 | self.z.append([self.data[self.CODE][t][ch] for t in self.times]) |
|
630 | self.z.append([self.data[self.CODE][t][ch] for t in self.times]) | |
628 |
|
631 | |||
629 | self.z = np.array(self.z) |
|
632 | self.z = np.array(self.z) | |
630 | self.z = numpy.ma.masked_invalid(self.z) |
|
633 | self.z = numpy.ma.masked_invalid(self.z) | |
631 |
|
634 | |||
632 | cmap=plt.get_cmap(self.colormap) |
|
635 | cmap=plt.get_cmap(self.colormap) | |
633 | cmap.set_bad('white', 1.) |
|
636 | cmap.set_bad('white', 1.) | |
634 |
|
637 | |||
635 | for n, ax in enumerate(self.axes): |
|
638 | for n, ax in enumerate(self.axes): | |
636 | x, y, z = self.fill_gaps(*self.decimate()) |
|
639 | x, y, z = self.fill_gaps(*self.decimate()) | |
637 | xmin = self.min_time |
|
640 | xmin = self.min_time | |
638 | xmax = xmin+self.xrange*60*60 |
|
641 | xmax = xmin+self.xrange*60*60 | |
639 | if ax.firsttime: |
|
642 | if ax.firsttime: | |
640 | self.ymin = self.ymin if self.ymin else np.nanmin(self.y) |
|
643 | self.ymin = self.ymin if self.ymin else np.nanmin(self.y) | |
641 | self.ymax = self.ymax if self.ymax else np.nanmax(self.y) |
|
644 | self.ymax = self.ymax if self.ymax else np.nanmax(self.y) | |
642 | self.zmax = self.zmax if self.zmax else numpy.nanmax(abs(self.z[:-1, :])) |
|
645 | self.zmax = self.zmax if self.zmax else numpy.nanmax(abs(self.z[:-1, :])) | |
643 | self.zmin = self.zmin if self.zmin else -self.zmax |
|
646 | self.zmin = self.zmin if self.zmin else -self.zmax | |
644 |
|
647 | |||
645 | plot = ax.pcolormesh(x, y, z[n].T*self.windFactor[n], |
|
648 | plot = ax.pcolormesh(x, y, z[n].T*self.windFactor[n], | |
646 | vmin=self.zmin, |
|
649 | vmin=self.zmin, | |
647 | vmax=self.zmax, |
|
650 | vmax=self.zmax, | |
648 | cmap=cmap |
|
651 | cmap=cmap | |
649 | ) |
|
652 | ) | |
650 | divider = make_axes_locatable(ax) |
|
653 | divider = make_axes_locatable(ax) | |
651 | cax = divider.new_horizontal(size='2%', pad=0.05) |
|
654 | cax = divider.new_horizontal(size='2%', pad=0.05) | |
652 | cax.set_ylabel(self.clabels[n]) |
|
655 | cax.set_ylabel(self.clabels[n]) | |
653 | self.figure.add_axes(cax) |
|
656 | self.figure.add_axes(cax) | |
654 | plt.colorbar(plot, cax) |
|
657 | plt.colorbar(plot, cax) | |
655 | ax.set_ylim(self.ymin, self.ymax) |
|
658 | ax.set_ylim(self.ymin, self.ymax) | |
656 |
|
659 | |||
657 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
660 | ax.xaxis.set_major_formatter(FuncFormatter(func)) | |
658 | ax.xaxis.set_major_locator(LinearLocator(6)) |
|
661 | ax.xaxis.set_major_locator(LinearLocator(6)) | |
659 |
|
662 | |||
660 | ax.set_ylabel(self.ylabel) |
|
663 | ax.set_ylabel(self.ylabel) | |
661 |
|
664 | |||
662 | ax.set_xlim(xmin, xmax) |
|
665 | ax.set_xlim(xmin, xmax) | |
663 | ax.firsttime = False |
|
666 | ax.firsttime = False | |
664 | else: |
|
667 | else: | |
665 | ax.collections.remove(ax.collections[0]) |
|
668 | ax.collections.remove(ax.collections[0]) | |
666 | ax.set_xlim(xmin, xmax) |
|
669 | ax.set_xlim(xmin, xmax) | |
667 | plot = ax.pcolormesh(x, y, z[n].T*self.windFactor[n], |
|
670 | plot = ax.pcolormesh(x, y, z[n].T*self.windFactor[n], | |
668 | vmin=self.zmin, |
|
671 | vmin=self.zmin, | |
669 | vmax=self.zmax, |
|
672 | vmax=self.zmax, | |
670 | cmap=plt.get_cmap(self.colormap) |
|
673 | cmap=plt.get_cmap(self.colormap) | |
671 | ) |
|
674 | ) | |
672 | ax.set_title('{} {}'.format(self.titles[n], |
|
675 | ax.set_title('{} {}'.format(self.titles[n], | |
673 | datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')), |
|
676 | datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')), | |
674 | size=8) |
|
677 | size=8) | |
675 |
|
678 | |||
676 | self.saveTime = self.min_time |
|
679 | self.saveTime = self.min_time | |
677 |
|
680 | |||
678 |
|
681 | |||
679 | class PlotSNRData(PlotRTIData): |
|
682 | class PlotSNRData(PlotRTIData): | |
680 | CODE = 'snr' |
|
683 | CODE = 'snr' | |
681 | colormap = 'jet' |
|
684 | colormap = 'jet' | |
682 |
|
685 | |||
683 | class PlotDOPData(PlotRTIData): |
|
686 | class PlotDOPData(PlotRTIData): | |
684 | CODE = 'dop' |
|
687 | CODE = 'dop' | |
685 | colormap = 'jet' |
|
688 | colormap = 'jet' | |
686 |
|
689 | |||
687 |
|
690 | |||
688 | class PlotPHASEData(PlotCOHData): |
|
691 | class PlotPHASEData(PlotCOHData): | |
689 | CODE = 'phase' |
|
692 | CODE = 'phase' | |
690 | colormap = 'seismic' |
|
693 | colormap = 'seismic' |
@@ -1,240 +1,240 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on Jul 9, 2014 |
|
2 | Created on Jul 9, 2014 | |
3 |
|
3 | |||
4 | @author: roj-idl71 |
|
4 | @author: roj-idl71 | |
5 | ''' |
|
5 | ''' | |
6 | import os, sys |
|
6 | import os, sys | |
7 | import datetime |
|
7 | import datetime | |
8 | import numpy |
|
8 | import numpy | |
9 | import traceback |
|
9 | import traceback | |
10 |
|
10 | |||
11 | from time import sleep |
|
11 | from time import sleep | |
12 | from threading import Lock |
|
12 | from threading import Lock | |
13 | # from threading import Thread |
|
13 | # from threading import Thread | |
14 |
|
14 | |||
15 | import schainpy |
|
15 | import schainpy | |
16 | import schainpy.admin |
|
16 | import schainpy.admin | |
17 |
|
17 | |||
18 | from schainpy.model.proc.jroproc_base import Operation |
|
18 | from schainpy.model.proc.jroproc_base import Operation | |
19 | from schainpy.model.serializer.data import obj2Dict, dict2Obj |
|
19 | from schainpy.model.serializer.data import obj2Dict, dict2Obj | |
20 | from jroplot_correlation import * |
|
20 | from jroplot_correlation import * | |
21 | from jroplot_heispectra import * |
|
21 | from jroplot_heispectra import * | |
22 | from jroplot_parameters import * |
|
22 | from jroplot_parameters import * | |
23 | from jroplot_spectra import * |
|
23 | from jroplot_spectra import * | |
24 | from jroplot_voltage import * |
|
24 | from jroplot_voltage import * | |
25 |
|
25 | |||
26 |
|
26 | |||
27 | class Plotter(Operation): |
|
27 | class Plotter(Operation): | |
28 |
|
28 | |||
29 | isConfig = None |
|
29 | isConfig = None | |
30 | name = None |
|
30 | name = None | |
31 | __queue = None |
|
31 | __queue = None | |
32 |
|
32 | |||
33 | def __init__(self, plotter_name, plotter_queue=None): |
|
33 | def __init__(self, plotter_name, plotter_queue=None, **kwargs): | |
|
34 | ||||
|
35 | Operation.__init__(self, **kwargs) | |||
34 |
|
36 | |||
35 | Operation.__init__(self) |
|
|||
36 |
|
||||
37 | self.isConfig = False |
|
37 | self.isConfig = False | |
38 | self.name = plotter_name |
|
38 | self.name = plotter_name | |
39 | self.__queue = plotter_queue |
|
39 | self.__queue = plotter_queue | |
40 |
|
40 | |||
41 | def getSubplots(self): |
|
41 | def getSubplots(self): | |
42 |
|
42 | |||
43 | nrow = self.nplots |
|
43 | nrow = self.nplots | |
44 | ncol = 1 |
|
44 | ncol = 1 | |
45 | return nrow, ncol |
|
45 | return nrow, ncol | |
46 |
|
46 | |||
47 | def setup(self, **kwargs): |
|
47 | def setup(self, **kwargs): | |
48 |
|
48 | |||
49 | print "Initializing ..." |
|
49 | print "Initializing ..." | |
50 |
|
50 | |||
51 |
|
51 | |||
52 | def run(self, dataOut, id=None, **kwargs): |
|
52 | def run(self, dataOut, id=None, **kwargs): | |
53 |
|
53 | |||
54 | """ |
|
54 | """ | |
55 |
|
55 | |||
56 | Input: |
|
56 | Input: | |
57 | dataOut : |
|
57 | dataOut : | |
58 | id : |
|
58 | id : | |
59 | """ |
|
59 | """ | |
60 |
|
60 | |||
61 | packDict = {} |
|
61 | packDict = {} | |
62 |
|
62 | |||
63 | packDict['id'] = id |
|
63 | packDict['id'] = id | |
64 | packDict['name'] = self.name |
|
64 | packDict['name'] = self.name | |
65 | packDict['kwargs'] = kwargs |
|
65 | packDict['kwargs'] = kwargs | |
66 |
|
66 | |||
67 | # packDict['data'] = obj2Dict(dataOut) |
|
67 | # packDict['data'] = obj2Dict(dataOut) | |
68 | packDict['data'] = dataOut |
|
68 | packDict['data'] = dataOut | |
69 |
|
69 | |||
70 | self.__queue.put(packDict) |
|
70 | self.__queue.put(packDict) | |
71 |
|
71 | |||
72 | # class PlotManager(Thread): |
|
72 | # class PlotManager(Thread): | |
73 | class PlotManager(): |
|
73 | class PlotManager(): | |
74 |
|
74 | |||
75 | __err = False |
|
75 | __err = False | |
76 | __stop = False |
|
76 | __stop = False | |
77 | __realtime = False |
|
77 | __realtime = False | |
78 |
|
78 | |||
79 | controllerThreadObj = None |
|
79 | controllerThreadObj = None | |
80 |
|
80 | |||
81 | plotterList = ['Scope', |
|
81 | plotterList = ['Scope', | |
82 | 'SpectraPlot', 'RTIPlot', |
|
82 | 'SpectraPlot', 'RTIPlot', | |
83 | 'SpectraCutPlot', |
|
83 | 'SpectraCutPlot', | |
84 | 'CrossSpectraPlot', 'CoherenceMap', |
|
84 | 'CrossSpectraPlot', 'CoherenceMap', | |
85 | 'PowerProfilePlot', 'Noise', 'BeaconPhase', |
|
85 | 'PowerProfilePlot', 'Noise', 'BeaconPhase', | |
86 | 'CorrelationPlot', |
|
86 | 'CorrelationPlot', | |
87 | 'SpectraHeisScope','RTIfromSpectraHeis'] |
|
87 | 'SpectraHeisScope', 'RTIfromSpectraHeis'] | |
88 |
|
88 | |||
89 | def __init__(self, plotter_queue): |
|
89 | def __init__(self, plotter_queue): | |
90 |
|
90 | |||
91 | # Thread.__init__(self) |
|
91 | # Thread.__init__(self) | |
92 | # self.setDaemon(True) |
|
92 | # self.setDaemon(True) | |
93 |
|
93 | |||
94 | self.__queue = plotter_queue |
|
94 | self.__queue = plotter_queue | |
95 | self.__lock = Lock() |
|
95 | self.__lock = Lock() | |
96 |
|
96 | |||
97 | self.plotInstanceDict = {} |
|
97 | self.plotInstanceDict = {} | |
98 |
|
98 | |||
99 | self.__err = False |
|
99 | self.__err = False | |
100 | self.__stop = False |
|
100 | self.__stop = False | |
101 | self.__realtime = False |
|
101 | self.__realtime = False | |
102 |
|
102 | |||
103 | def __handleError(self, name="", send_email=False): |
|
103 | def __handleError(self, name="", send_email=False): | |
104 |
|
104 | |||
105 | err = traceback.format_exception(sys.exc_info()[0], |
|
105 | err = traceback.format_exception(sys.exc_info()[0], | |
106 | sys.exc_info()[1], |
|
106 | sys.exc_info()[1], | |
107 | sys.exc_info()[2]) |
|
107 | sys.exc_info()[2]) | |
108 |
|
108 | |||
109 | print "***** Error occurred in PlotManager *****" |
|
109 | print "***** Error occurred in PlotManager *****" | |
110 | print "***** [%s]: %s" %(name, err[-1]) |
|
110 | print "***** [%s]: %s" %(name, err[-1]) | |
111 |
|
111 | |||
112 | message = "\nError ocurred in %s:\n" %name |
|
112 | message = "\nError ocurred in %s:\n" %name | |
113 | message += "".join(err) |
|
113 | message += "".join(err) | |
114 |
|
114 | |||
115 | sys.stderr.write(message) |
|
115 | sys.stderr.write(message) | |
116 |
|
116 | |||
117 | if not send_email: |
|
117 | if not send_email: | |
118 | return |
|
118 | return | |
119 |
|
119 | |||
120 | import socket |
|
120 | import socket | |
121 |
|
121 | |||
122 | subject = "SChain v%s: Error running %s\n" %(schainpy.__version__, name) |
|
122 | subject = "SChain v%s: Error running %s\n" %(schainpy.__version__, name) | |
123 |
|
123 | |||
124 | subtitle = "%s:\n" %(name) |
|
124 | subtitle = "%s:\n" %(name) | |
125 | subtitle += "Hostname: %s\n" %socket.gethostbyname(socket.gethostname()) |
|
125 | subtitle += "Hostname: %s\n" %socket.gethostbyname(socket.gethostname()) | |
126 | subtitle += "Working directory: %s\n" %os.path.abspath("./") |
|
126 | subtitle += "Working directory: %s\n" %os.path.abspath("./") | |
127 | # subtitle += "Configuration file: %s\n" %self.filename |
|
127 | # subtitle += "Configuration file: %s\n" %self.filename | |
128 | subtitle += "Time: %s\n" %str(datetime.datetime.now()) |
|
128 | subtitle += "Time: %s\n" %str(datetime.datetime.now()) | |
129 |
|
129 | |||
130 | adminObj = schainpy.admin.SchainNotify() |
|
130 | adminObj = schainpy.admin.SchainNotify() | |
131 | adminObj.sendAlert(message=message, |
|
131 | adminObj.sendAlert(message=message, | |
132 | subject=subject, |
|
132 | subject=subject, | |
133 | subtitle=subtitle) |
|
133 | subtitle=subtitle) | |
134 |
|
134 | |||
135 | def run(self): |
|
135 | def run(self): | |
136 |
|
136 | |||
137 | if self.__queue.empty(): |
|
137 | if self.__queue.empty(): | |
138 | return |
|
138 | return | |
139 |
|
139 | |||
140 | if self.__err: |
|
140 | if self.__err: | |
141 | serial_data = self.__queue.get() |
|
141 | serial_data = self.__queue.get() | |
142 | self.__queue.task_done() |
|
142 | self.__queue.task_done() | |
143 | return |
|
143 | return | |
144 |
|
144 | |||
145 | self.__lock.acquire() |
|
145 | self.__lock.acquire() | |
146 |
|
146 | |||
147 | # if self.__queue.full(): |
|
147 | # if self.__queue.full(): | |
148 | # for i in range(int(self.__queue.qsize()/2)): |
|
148 | # for i in range(int(self.__queue.qsize()/2)): | |
149 | # serial_data = self.__queue.get() |
|
149 | # serial_data = self.__queue.get() | |
150 | # self.__queue.task_done() |
|
150 | # self.__queue.task_done() | |
151 |
|
151 | |||
152 | n = int(self.__queue.qsize()/3 + 1) |
|
152 | n = int(self.__queue.qsize()/3 + 1) | |
153 |
|
153 | |||
154 | for i in range(n): |
|
154 | for i in range(n): | |
155 |
|
155 | |||
156 | if self.__queue.empty(): |
|
156 | if self.__queue.empty(): | |
157 | break |
|
157 | break | |
158 |
|
158 | |||
159 | serial_data = self.__queue.get() |
|
159 | serial_data = self.__queue.get() | |
160 | self.__queue.task_done() |
|
160 | self.__queue.task_done() | |
161 |
|
161 | |||
162 | plot_id = serial_data['id'] |
|
162 | plot_id = serial_data['id'] | |
163 | plot_name = serial_data['name'] |
|
163 | plot_name = serial_data['name'] | |
164 | kwargs = serial_data['kwargs'] |
|
164 | kwargs = serial_data['kwargs'] | |
165 | # dataDict = serial_data['data'] |
|
165 | # dataDict = serial_data['data'] | |
166 | # |
|
166 | # | |
167 | # dataPlot = dict2Obj(dataDict) |
|
167 | # dataPlot = dict2Obj(dataDict) | |
168 |
|
168 | |||
169 | dataPlot = serial_data['data'] |
|
169 | dataPlot = serial_data['data'] | |
170 |
|
170 | |||
171 | if plot_id not in self.plotInstanceDict.keys(): |
|
171 | if plot_id not in self.plotInstanceDict.keys(): | |
172 | className = eval(plot_name) |
|
172 | className = eval(plot_name) | |
173 | self.plotInstanceDict[plot_id] = className() |
|
173 | self.plotInstanceDict[plot_id] = className(**kwargs) | |
174 |
|
174 | |||
175 | plotter = self.plotInstanceDict[plot_id] |
|
175 | plotter = self.plotInstanceDict[plot_id] | |
176 | try: |
|
176 | try: | |
177 | plotter.run(dataPlot, plot_id, **kwargs) |
|
177 | plotter.run(dataPlot, plot_id, **kwargs) | |
178 | except: |
|
178 | except: | |
179 | self.__err = True |
|
179 | self.__err = True | |
180 | self.__handleError(plot_name, send_email=True) |
|
180 | self.__handleError(plot_name, send_email=True) | |
181 | break |
|
181 | break | |
182 |
|
182 | |||
183 | self.__lock.release() |
|
183 | self.__lock.release() | |
184 |
|
184 | |||
185 | def isEmpty(self): |
|
185 | def isEmpty(self): | |
186 |
|
186 | |||
187 | return self.__queue.empty() |
|
187 | return self.__queue.empty() | |
188 |
|
188 | |||
189 | def stop(self): |
|
189 | def stop(self): | |
190 |
|
190 | |||
191 | self.__lock.acquire() |
|
191 | self.__lock.acquire() | |
192 |
|
192 | |||
193 | self.__stop = True |
|
193 | self.__stop = True | |
194 |
|
194 | |||
195 | self.__lock.release() |
|
195 | self.__lock.release() | |
196 |
|
196 | |||
197 | def close(self): |
|
197 | def close(self): | |
198 |
|
198 | |||
199 | self.__lock.acquire() |
|
199 | self.__lock.acquire() | |
200 |
|
200 | |||
201 | for plot_id in self.plotInstanceDict.keys(): |
|
201 | for plot_id in self.plotInstanceDict.keys(): | |
202 | plotter = self.plotInstanceDict[plot_id] |
|
202 | plotter = self.plotInstanceDict[plot_id] | |
203 | plotter.close() |
|
203 | plotter.close() | |
204 |
|
204 | |||
205 | self.__lock.release() |
|
205 | self.__lock.release() | |
206 |
|
206 | |||
207 | def setController(self, controllerThreadObj): |
|
207 | def setController(self, controllerThreadObj): | |
208 |
|
208 | |||
209 | self.controllerThreadObj = controllerThreadObj |
|
209 | self.controllerThreadObj = controllerThreadObj | |
210 |
|
210 | |||
211 | def start(self): |
|
211 | def start(self): | |
212 |
|
212 | |||
213 | if not self.controllerThreadObj.isRunning(): |
|
213 | if not self.controllerThreadObj.isRunning(): | |
214 | raise RuntimeError, "controllerThreadObj has not been initialized. Use controllerThreadObj.start() before call this method" |
|
214 | raise RuntimeError, "controllerThreadObj has not been initialized. Use controllerThreadObj.start() before call this method" | |
215 |
|
215 | |||
216 | self.join() |
|
216 | self.join() | |
217 |
|
217 | |||
218 | def join(self): |
|
218 | def join(self): | |
219 |
|
219 | |||
220 | #Execute plotter while controller is running |
|
220 | #Execute plotter while controller is running | |
221 | while self.controllerThreadObj.isRunning(): |
|
221 | while self.controllerThreadObj.isRunning(): | |
222 | self.run() |
|
222 | self.run() | |
223 |
|
223 | |||
224 | self.controllerThreadObj.stop() |
|
224 | self.controllerThreadObj.stop() | |
225 |
|
225 | |||
226 | #Wait until plotter queue is empty |
|
226 | #Wait until plotter queue is empty | |
227 | while not self.isEmpty(): |
|
227 | while not self.isEmpty(): | |
228 | self.run() |
|
228 | self.run() | |
229 |
|
229 | |||
230 | self.close() |
|
230 | self.close() | |
231 |
|
231 | |||
232 | def isErrorDetected(self): |
|
232 | def isErrorDetected(self): | |
233 |
|
233 | |||
234 | self.__lock.acquire() |
|
234 | self.__lock.acquire() | |
235 |
|
235 | |||
236 | err = self.__err |
|
236 | err = self.__err | |
237 |
|
237 | |||
238 | self.__lock.release() |
|
238 | self.__lock.release() | |
239 |
|
239 | |||
240 | return err |
|
240 | return err |
@@ -1,468 +1,468 | |||||
1 | import numpy |
|
1 | import numpy | |
2 | import datetime |
|
2 | import datetime | |
3 | import sys |
|
3 | import sys | |
4 | import matplotlib |
|
4 | import matplotlib | |
5 |
|
5 | |||
6 | if 'linux' in sys.platform: |
|
6 | if 'linux' in sys.platform: | |
7 | matplotlib.use("TKAgg") |
|
7 | matplotlib.use("TKAgg") | |
8 |
|
8 | |||
9 | if 'darwin' in sys.platform: |
|
9 | if 'darwin' in sys.platform: | |
10 | matplotlib.use('TKAgg') |
|
10 | matplotlib.use('TKAgg') | |
11 | #Qt4Agg', 'GTK', 'GTKAgg', 'ps', 'agg', 'cairo', 'MacOSX', 'GTKCairo', 'WXAgg', 'template', 'TkAgg', 'GTK3Cairo', 'GTK3Agg', 'svg', 'WebAgg', 'CocoaAgg', 'emf', 'gdk', 'WX' |
|
11 | #Qt4Agg', 'GTK', 'GTKAgg', 'ps', 'agg', 'cairo', 'MacOSX', 'GTKCairo', 'WXAgg', 'template', 'TkAgg', 'GTK3Cairo', 'GTK3Agg', 'svg', 'WebAgg', 'CocoaAgg', 'emf', 'gdk', 'WX' | |
12 | import matplotlib.pyplot |
|
12 | import matplotlib.pyplot | |
13 |
|
13 | |||
14 | from mpl_toolkits.axes_grid1 import make_axes_locatable |
|
14 | from mpl_toolkits.axes_grid1 import make_axes_locatable | |
15 | from matplotlib.ticker import FuncFormatter, LinearLocator |
|
15 | from matplotlib.ticker import FuncFormatter, LinearLocator | |
16 |
|
16 | |||
17 | ########################################### |
|
17 | ########################################### | |
18 | #Actualizacion de las funciones del driver |
|
18 | #Actualizacion de las funciones del driver | |
19 | ########################################### |
|
19 | ########################################### | |
20 |
|
20 | |||
21 | # create jro colormap |
|
21 | # create jro colormap | |
22 |
|
22 | |||
23 | jet_values = matplotlib.pyplot.get_cmap("jet", 100)(numpy.arange(100))[10:90] |
|
23 | jet_values = matplotlib.pyplot.get_cmap("jet", 100)(numpy.arange(100))[10:90] | |
24 | blu_values = matplotlib.pyplot.get_cmap("seismic_r", 20)(numpy.arange(20))[10:15] |
|
24 | blu_values = matplotlib.pyplot.get_cmap("seismic_r", 20)(numpy.arange(20))[10:15] | |
25 | ncmap = matplotlib.colors.LinearSegmentedColormap.from_list("jro", numpy.vstack((blu_values, jet_values))) |
|
25 | ncmap = matplotlib.colors.LinearSegmentedColormap.from_list("jro", numpy.vstack((blu_values, jet_values))) | |
26 | matplotlib.pyplot.register_cmap(cmap=ncmap) |
|
26 | matplotlib.pyplot.register_cmap(cmap=ncmap) | |
27 |
|
27 | |||
28 | def createFigure(id, wintitle, width, height, facecolor="w", show=True, dpi = 80): |
|
28 | def createFigure(id, wintitle, width, height, facecolor="w", show=True, dpi = 80): | |
29 |
|
29 | |||
30 | matplotlib.pyplot.ioff() |
|
30 | matplotlib.pyplot.ioff() | |
31 |
|
31 | |||
32 | fig = matplotlib.pyplot.figure(num=id, facecolor=facecolor, figsize=(1.0*width/dpi, 1.0*height/dpi)) |
|
32 | fig = matplotlib.pyplot.figure(num=id, facecolor=facecolor, figsize=(1.0*width/dpi, 1.0*height/dpi)) | |
33 | fig.canvas.manager.set_window_title(wintitle) |
|
33 | fig.canvas.manager.set_window_title(wintitle) | |
34 | # fig.canvas.manager.resize(width, height) |
|
34 | # fig.canvas.manager.resize(width, height) | |
35 | matplotlib.pyplot.ion() |
|
35 | matplotlib.pyplot.ion() | |
36 |
|
36 | |||
37 | if show: |
|
37 | if show: | |
38 | matplotlib.pyplot.show() |
|
38 | matplotlib.pyplot.show() | |
39 |
|
39 | |||
40 | return fig |
|
40 | return fig | |
41 |
|
41 | |||
42 | def closeFigure(show=False, fig=None): |
|
42 | def closeFigure(show=False, fig=None): | |
43 |
|
43 | |||
44 | # matplotlib.pyplot.ioff() |
|
44 | # matplotlib.pyplot.ioff() | |
45 | # matplotlib.pyplot.pause(0) |
|
45 | # matplotlib.pyplot.pause(0) | |
46 |
|
46 | |||
47 | if show: |
|
47 | if show: | |
48 | matplotlib.pyplot.show() |
|
48 | matplotlib.pyplot.show() | |
49 |
|
49 | |||
50 | if fig != None: |
|
50 | if fig != None: | |
51 | matplotlib.pyplot.close(fig) |
|
51 | matplotlib.pyplot.close(fig) | |
52 | # matplotlib.pyplot.pause(0) |
|
52 | # matplotlib.pyplot.pause(0) | |
53 | # matplotlib.pyplot.ion() |
|
53 | # matplotlib.pyplot.ion() | |
54 |
|
54 | |||
55 | return |
|
55 | return | |
56 |
|
56 | |||
57 | matplotlib.pyplot.close("all") |
|
57 | matplotlib.pyplot.close("all") | |
58 | # matplotlib.pyplot.pause(0) |
|
58 | # matplotlib.pyplot.pause(0) | |
59 | # matplotlib.pyplot.ion() |
|
59 | # matplotlib.pyplot.ion() | |
60 |
|
60 | |||
61 | return |
|
61 | return | |
62 |
|
62 | |||
63 | def saveFigure(fig, filename): |
|
63 | def saveFigure(fig, filename): | |
64 |
|
64 | |||
65 | # matplotlib.pyplot.ioff() |
|
65 | # matplotlib.pyplot.ioff() | |
66 | fig.savefig(filename, dpi=matplotlib.pyplot.gcf().dpi) |
|
66 | fig.savefig(filename, dpi=matplotlib.pyplot.gcf().dpi) | |
67 | # matplotlib.pyplot.ion() |
|
67 | # matplotlib.pyplot.ion() | |
68 |
|
68 | |||
69 | def clearFigure(fig): |
|
69 | def clearFigure(fig): | |
70 |
|
70 | |||
71 | fig.clf() |
|
71 | fig.clf() | |
72 |
|
72 | |||
73 | def setWinTitle(fig, title): |
|
73 | def setWinTitle(fig, title): | |
74 |
|
74 | |||
75 | fig.canvas.manager.set_window_title(title) |
|
75 | fig.canvas.manager.set_window_title(title) | |
76 |
|
76 | |||
77 | def setTitle(fig, title): |
|
77 | def setTitle(fig, title): | |
78 |
|
78 | |||
79 | fig.suptitle(title) |
|
79 | fig.suptitle(title) | |
80 |
|
80 | |||
81 | def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan, polar=False): |
|
81 | def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan, polar=False): | |
82 |
|
82 | |||
83 | matplotlib.pyplot.ioff() |
|
83 | matplotlib.pyplot.ioff() | |
84 | matplotlib.pyplot.figure(fig.number) |
|
84 | matplotlib.pyplot.figure(fig.number) | |
85 | axes = matplotlib.pyplot.subplot2grid((nrow, ncol), |
|
85 | axes = matplotlib.pyplot.subplot2grid((nrow, ncol), | |
86 | (xpos, ypos), |
|
86 | (xpos, ypos), | |
87 | colspan=colspan, |
|
87 | colspan=colspan, | |
88 | rowspan=rowspan, |
|
88 | rowspan=rowspan, | |
89 | polar=polar) |
|
89 | polar=polar) | |
90 |
|
90 | |||
91 | matplotlib.pyplot.ion() |
|
91 | matplotlib.pyplot.ion() | |
92 | return axes |
|
92 | return axes | |
93 |
|
93 | |||
94 | def setAxesText(ax, text): |
|
94 | def setAxesText(ax, text): | |
95 |
|
95 | |||
96 | ax.annotate(text, |
|
96 | ax.annotate(text, | |
97 | xy = (.1, .99), |
|
97 | xy = (.1, .99), | |
98 | xycoords = 'figure fraction', |
|
98 | xycoords = 'figure fraction', | |
99 | horizontalalignment = 'left', |
|
99 | horizontalalignment = 'left', | |
100 | verticalalignment = 'top', |
|
100 | verticalalignment = 'top', | |
101 | fontsize = 10) |
|
101 | fontsize = 10) | |
102 |
|
102 | |||
103 | def printLabels(ax, xlabel, ylabel, title): |
|
103 | def printLabels(ax, xlabel, ylabel, title): | |
104 |
|
104 | |||
105 | ax.set_xlabel(xlabel, size=11) |
|
105 | ax.set_xlabel(xlabel, size=11) | |
106 | ax.set_ylabel(ylabel, size=11) |
|
106 | ax.set_ylabel(ylabel, size=11) | |
107 | ax.set_title(title, size=8) |
|
107 | ax.set_title(title, size=8) | |
108 |
|
108 | |||
109 | def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', |
|
109 | def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', | |
110 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
110 | ticksize=9, xtick_visible=True, ytick_visible=True, | |
111 | nxticks=4, nyticks=10, |
|
111 | nxticks=4, nyticks=10, | |
112 | grid=None,color='blue'): |
|
112 | grid=None,color='blue'): | |
113 |
|
113 | |||
114 | """ |
|
114 | """ | |
115 |
|
115 | |||
116 | Input: |
|
116 | Input: | |
117 | grid : None, 'both', 'x', 'y' |
|
117 | grid : None, 'both', 'x', 'y' | |
118 | """ |
|
118 | """ | |
119 |
|
119 | |||
120 | matplotlib.pyplot.ioff() |
|
120 | matplotlib.pyplot.ioff() | |
121 |
|
121 | |||
122 | ax.set_xlim([xmin,xmax]) |
|
122 | ax.set_xlim([xmin,xmax]) | |
123 | ax.set_ylim([ymin,ymax]) |
|
123 | ax.set_ylim([ymin,ymax]) | |
124 |
|
124 | |||
125 | printLabels(ax, xlabel, ylabel, title) |
|
125 | printLabels(ax, xlabel, ylabel, title) | |
126 |
|
126 | |||
127 | ###################################################### |
|
127 | ###################################################### | |
128 | if (xmax-xmin)<=1: |
|
128 | if (xmax-xmin)<=1: | |
129 | xtickspos = numpy.linspace(xmin,xmax,nxticks) |
|
129 | xtickspos = numpy.linspace(xmin,xmax,nxticks) | |
130 | xtickspos = numpy.array([float("%.1f"%i) for i in xtickspos]) |
|
130 | xtickspos = numpy.array([float("%.1f"%i) for i in xtickspos]) | |
131 | ax.set_xticks(xtickspos) |
|
131 | ax.set_xticks(xtickspos) | |
132 | else: |
|
132 | else: | |
133 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
|
133 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) | |
134 | # xtickspos = numpy.arange(nxticks)*float(xmax-xmin)/float(nxticks) + int(xmin) |
|
134 | # xtickspos = numpy.arange(nxticks)*float(xmax-xmin)/float(nxticks) + int(xmin) | |
135 | ax.set_xticks(xtickspos) |
|
135 | ax.set_xticks(xtickspos) | |
136 |
|
136 | |||
137 | for tick in ax.get_xticklabels(): |
|
137 | for tick in ax.get_xticklabels(): | |
138 | tick.set_visible(xtick_visible) |
|
138 | tick.set_visible(xtick_visible) | |
139 |
|
139 | |||
140 | for tick in ax.xaxis.get_major_ticks(): |
|
140 | for tick in ax.xaxis.get_major_ticks(): | |
141 | tick.label.set_fontsize(ticksize) |
|
141 | tick.label.set_fontsize(ticksize) | |
142 |
|
142 | |||
143 | ###################################################### |
|
143 | ###################################################### | |
144 | for tick in ax.get_yticklabels(): |
|
144 | for tick in ax.get_yticklabels(): | |
145 | tick.set_visible(ytick_visible) |
|
145 | tick.set_visible(ytick_visible) | |
146 |
|
146 | |||
147 | for tick in ax.yaxis.get_major_ticks(): |
|
147 | for tick in ax.yaxis.get_major_ticks(): | |
148 | tick.label.set_fontsize(ticksize) |
|
148 | tick.label.set_fontsize(ticksize) | |
149 |
|
149 | |||
150 | ax.plot(x, y, color=color) |
|
150 | ax.plot(x, y, color=color) | |
151 | iplot = ax.lines[-1] |
|
151 | iplot = ax.lines[-1] | |
152 |
|
152 | |||
153 | ###################################################### |
|
153 | ###################################################### | |
154 | if '0.' in matplotlib.__version__[0:2]: |
|
154 | if '0.' in matplotlib.__version__[0:2]: | |
155 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
155 | print "The matplotlib version has to be updated to 1.1 or newer" | |
156 | return iplot |
|
156 | return iplot | |
157 |
|
157 | |||
158 | if '1.0.' in matplotlib.__version__[0:4]: |
|
158 | if '1.0.' in matplotlib.__version__[0:4]: | |
159 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
159 | print "The matplotlib version has to be updated to 1.1 or newer" | |
160 | return iplot |
|
160 | return iplot | |
161 |
|
161 | |||
162 | if grid != None: |
|
162 | if grid != None: | |
163 | ax.grid(b=True, which='major', axis=grid) |
|
163 | ax.grid(b=True, which='major', axis=grid) | |
164 |
|
164 | |||
165 | matplotlib.pyplot.tight_layout() |
|
165 | matplotlib.pyplot.tight_layout() | |
166 |
|
166 | |||
167 | matplotlib.pyplot.ion() |
|
167 | matplotlib.pyplot.ion() | |
168 |
|
168 | |||
169 | return iplot |
|
169 | return iplot | |
170 |
|
170 | |||
171 | def set_linedata(ax, x, y, idline): |
|
171 | def set_linedata(ax, x, y, idline): | |
172 |
|
172 | |||
173 | ax.lines[idline].set_data(x,y) |
|
173 | ax.lines[idline].set_data(x,y) | |
174 |
|
174 | |||
175 | def pline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
175 | def pline(iplot, x, y, xlabel='', ylabel='', title=''): | |
176 |
|
176 | |||
177 | ax = iplot.axes |
|
177 | ax = iplot.axes | |
178 |
|
178 | |||
179 | printLabels(ax, xlabel, ylabel, title) |
|
179 | printLabels(ax, xlabel, ylabel, title) | |
180 |
|
180 | |||
181 | set_linedata(ax, x, y, idline=0) |
|
181 | set_linedata(ax, x, y, idline=0) | |
182 |
|
182 | |||
183 | def addpline(ax, x, y, color, linestyle, lw): |
|
183 | def addpline(ax, x, y, color, linestyle, lw): | |
184 |
|
184 | |||
185 | ax.plot(x,y,color=color,linestyle=linestyle,lw=lw) |
|
185 | ax.plot(x,y,color=color,linestyle=linestyle,lw=lw) | |
186 |
|
186 | |||
187 |
|
187 | |||
188 | def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, |
|
188 | def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, | |
189 | xlabel='', ylabel='', title='', ticksize = 9, |
|
189 | xlabel='', ylabel='', title='', ticksize = 9, | |
190 | colormap='jet',cblabel='', cbsize="5%", |
|
190 | colormap='jet',cblabel='', cbsize="5%", | |
191 | XAxisAsTime=False): |
|
191 | XAxisAsTime=False): | |
192 |
|
192 | |||
193 | matplotlib.pyplot.ioff() |
|
193 | matplotlib.pyplot.ioff() | |
194 |
|
194 | |||
195 | divider = make_axes_locatable(ax) |
|
195 | divider = make_axes_locatable(ax) | |
196 | ax_cb = divider.new_horizontal(size=cbsize, pad=0.05) |
|
196 | ax_cb = divider.new_horizontal(size=cbsize, pad=0.05) | |
197 | fig = ax.get_figure() |
|
197 | fig = ax.get_figure() | |
198 | fig.add_axes(ax_cb) |
|
198 | fig.add_axes(ax_cb) | |
199 |
|
199 | |||
200 | ax.set_xlim([xmin,xmax]) |
|
200 | ax.set_xlim([xmin,xmax]) | |
201 | ax.set_ylim([ymin,ymax]) |
|
201 | ax.set_ylim([ymin,ymax]) | |
202 |
|
202 | |||
203 | printLabels(ax, xlabel, ylabel, title) |
|
203 | printLabels(ax, xlabel, ylabel, title) | |
204 |
|
204 | |||
205 | z = numpy.ma.masked_invalid(z) |
|
205 | z = numpy.ma.masked_invalid(z) | |
206 | cmap=matplotlib.pyplot.get_cmap(colormap) |
|
206 | cmap=matplotlib.pyplot.get_cmap(colormap) | |
207 | cmap.set_bad('white', 1.) |
|
207 | cmap.set_bad('white', 1.) | |
208 | imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=cmap) |
|
208 | imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=cmap) | |
209 | cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb) |
|
209 | cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb) | |
210 | cb.set_label(cblabel) |
|
210 | cb.set_label(cblabel) | |
211 |
|
211 | |||
212 | # for tl in ax_cb.get_yticklabels(): |
|
212 | # for tl in ax_cb.get_yticklabels(): | |
213 | # tl.set_visible(True) |
|
213 | # tl.set_visible(True) | |
214 |
|
214 | |||
215 | for tick in ax.yaxis.get_major_ticks(): |
|
215 | for tick in ax.yaxis.get_major_ticks(): | |
216 | tick.label.set_fontsize(ticksize) |
|
216 | tick.label.set_fontsize(ticksize) | |
217 |
|
217 | |||
218 | for tick in ax.xaxis.get_major_ticks(): |
|
218 | for tick in ax.xaxis.get_major_ticks(): | |
219 | tick.label.set_fontsize(ticksize) |
|
219 | tick.label.set_fontsize(ticksize) | |
220 |
|
220 | |||
221 | for tick in cb.ax.get_yticklabels(): |
|
221 | for tick in cb.ax.get_yticklabels(): | |
222 | tick.set_fontsize(ticksize) |
|
222 | tick.set_fontsize(ticksize) | |
223 |
|
223 | |||
224 | ax_cb.yaxis.tick_right() |
|
224 | ax_cb.yaxis.tick_right() | |
225 |
|
225 | |||
226 | if '0.' in matplotlib.__version__[0:2]: |
|
226 | if '0.' in matplotlib.__version__[0:2]: | |
227 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
227 | print "The matplotlib version has to be updated to 1.1 or newer" | |
228 | return imesh |
|
228 | return imesh | |
229 |
|
229 | |||
230 | if '1.0.' in matplotlib.__version__[0:4]: |
|
230 | if '1.0.' in matplotlib.__version__[0:4]: | |
231 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
231 | print "The matplotlib version has to be updated to 1.1 or newer" | |
232 | return imesh |
|
232 | return imesh | |
233 |
|
233 | |||
234 | matplotlib.pyplot.tight_layout() |
|
234 | matplotlib.pyplot.tight_layout() | |
235 |
|
235 | |||
236 | if XAxisAsTime: |
|
236 | if XAxisAsTime: | |
237 |
|
237 | |||
238 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) |
|
238 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) | |
239 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
239 | ax.xaxis.set_major_formatter(FuncFormatter(func)) | |
240 | ax.xaxis.set_major_locator(LinearLocator(7)) |
|
240 | ax.xaxis.set_major_locator(LinearLocator(7)) | |
241 |
|
241 | |||
242 | matplotlib.pyplot.ion() |
|
242 | matplotlib.pyplot.ion() | |
243 | return imesh |
|
243 | return imesh | |
244 |
|
244 | |||
245 | def pcolor(imesh, z, xlabel='', ylabel='', title=''): |
|
245 | def pcolor(imesh, z, xlabel='', ylabel='', title=''): | |
246 |
|
246 | |||
247 | z = z.T |
|
247 | z = z.T | |
248 | ax = imesh.axes |
|
248 | ax = imesh.axes | |
249 | printLabels(ax, xlabel, ylabel, title) |
|
249 | printLabels(ax, xlabel, ylabel, title) | |
250 | imesh.set_array(z.ravel()) |
|
250 | imesh.set_array(z.ravel()) | |
251 |
|
251 | |||
252 | def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): |
|
252 | def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): | |
253 |
|
253 | |||
254 | printLabels(ax, xlabel, ylabel, title) |
|
254 | printLabels(ax, xlabel, ylabel, title) | |
255 |
|
255 | |||
256 | ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) |
|
256 | ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) | |
257 |
|
257 | |||
258 | def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): |
|
258 | def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): | |
259 |
|
259 | |||
260 | printLabels(ax, xlabel, ylabel, title) |
|
260 | printLabels(ax, xlabel, ylabel, title) | |
261 |
|
261 | |||
262 | ax.collections.remove(ax.collections[0]) |
|
262 | ax.collections.remove(ax.collections[0]) | |
263 |
|
263 | |||
264 | z = numpy.ma.masked_invalid(z) |
|
264 | z = numpy.ma.masked_invalid(z) | |
265 |
|
265 | |||
266 | cmap=matplotlib.pyplot.get_cmap(colormap) |
|
266 | cmap=matplotlib.pyplot.get_cmap(colormap) | |
267 | cmap.set_bad('white', 1.) |
|
267 | cmap.set_bad('white', 1.) | |
268 |
|
268 | |||
269 |
|
269 | |||
270 | ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=cmap) |
|
270 | ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=cmap) | |
271 |
|
271 | |||
272 | def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, |
|
272 | def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, | |
273 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
273 | ticksize=9, xtick_visible=True, ytick_visible=True, | |
274 | nxticks=4, nyticks=10, |
|
274 | nxticks=4, nyticks=10, | |
275 | grid=None): |
|
275 | grid=None): | |
276 |
|
276 | |||
277 | """ |
|
277 | """ | |
278 |
|
278 | |||
279 | Input: |
|
279 | Input: | |
280 | grid : None, 'both', 'x', 'y' |
|
280 | grid : None, 'both', 'x', 'y' | |
281 | """ |
|
281 | """ | |
282 |
|
282 | |||
283 | matplotlib.pyplot.ioff() |
|
283 | matplotlib.pyplot.ioff() | |
284 |
|
284 | |||
285 | lines = ax.plot(x.T, y) |
|
285 | lines = ax.plot(x.T, y) | |
286 | leg = ax.legend(lines, legendlabels, loc='upper right') |
|
286 | leg = ax.legend(lines, legendlabels, loc='upper right') | |
287 | leg.get_frame().set_alpha(0.5) |
|
287 | leg.get_frame().set_alpha(0.5) | |
288 | ax.set_xlim([xmin,xmax]) |
|
288 | ax.set_xlim([xmin,xmax]) | |
289 | ax.set_ylim([ymin,ymax]) |
|
289 | ax.set_ylim([ymin,ymax]) | |
290 | printLabels(ax, xlabel, ylabel, title) |
|
290 | printLabels(ax, xlabel, ylabel, title) | |
291 |
|
291 | |||
292 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
|
292 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) | |
293 | ax.set_xticks(xtickspos) |
|
293 | ax.set_xticks(xtickspos) | |
294 |
|
294 | |||
295 | for tick in ax.get_xticklabels(): |
|
295 | for tick in ax.get_xticklabels(): | |
296 | tick.set_visible(xtick_visible) |
|
296 | tick.set_visible(xtick_visible) | |
297 |
|
297 | |||
298 | for tick in ax.xaxis.get_major_ticks(): |
|
298 | for tick in ax.xaxis.get_major_ticks(): | |
299 | tick.label.set_fontsize(ticksize) |
|
299 | tick.label.set_fontsize(ticksize) | |
300 |
|
300 | |||
301 | for tick in ax.get_yticklabels(): |
|
301 | for tick in ax.get_yticklabels(): | |
302 | tick.set_visible(ytick_visible) |
|
302 | tick.set_visible(ytick_visible) | |
303 |
|
303 | |||
304 | for tick in ax.yaxis.get_major_ticks(): |
|
304 | for tick in ax.yaxis.get_major_ticks(): | |
305 | tick.label.set_fontsize(ticksize) |
|
305 | tick.label.set_fontsize(ticksize) | |
306 |
|
306 | |||
307 | iplot = ax.lines[-1] |
|
307 | iplot = ax.lines[-1] | |
308 |
|
308 | |||
309 | if '0.' in matplotlib.__version__[0:2]: |
|
309 | if '0.' in matplotlib.__version__[0:2]: | |
310 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
310 | print "The matplotlib version has to be updated to 1.1 or newer" | |
311 | return iplot |
|
311 | return iplot | |
312 |
|
312 | |||
313 | if '1.0.' in matplotlib.__version__[0:4]: |
|
313 | if '1.0.' in matplotlib.__version__[0:4]: | |
314 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
314 | print "The matplotlib version has to be updated to 1.1 or newer" | |
315 | return iplot |
|
315 | return iplot | |
316 |
|
316 | |||
317 | if grid != None: |
|
317 | if grid != None: | |
318 | ax.grid(b=True, which='major', axis=grid) |
|
318 | ax.grid(b=True, which='major', axis=grid) | |
319 |
|
319 | |||
320 | matplotlib.pyplot.tight_layout() |
|
320 | matplotlib.pyplot.tight_layout() | |
321 |
|
321 | |||
322 | matplotlib.pyplot.ion() |
|
322 | matplotlib.pyplot.ion() | |
323 |
|
323 | |||
324 | return iplot |
|
324 | return iplot | |
325 |
|
325 | |||
326 |
|
326 | |||
327 | def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
327 | def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''): | |
328 |
|
328 | |||
329 | ax = iplot.axes |
|
329 | ax = iplot.axes | |
330 |
|
330 | |||
331 | printLabels(ax, xlabel, ylabel, title) |
|
331 | printLabels(ax, xlabel, ylabel, title) | |
332 |
|
332 | |||
333 | for i in range(len(ax.lines)): |
|
333 | for i in range(len(ax.lines)): | |
334 | line = ax.lines[i] |
|
334 | line = ax.lines[i] | |
335 | line.set_data(x[i,:],y) |
|
335 | line.set_data(x[i,:],y) | |
336 |
|
336 | |||
337 | def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, |
|
337 | def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, | |
338 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
338 | ticksize=9, xtick_visible=True, ytick_visible=True, | |
339 | nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None", |
|
339 | nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None", | |
340 | grid=None, XAxisAsTime=False): |
|
340 | grid=None, XAxisAsTime=False): | |
341 |
|
341 | |||
342 | """ |
|
342 | """ | |
343 |
|
343 | |||
344 | Input: |
|
344 | Input: | |
345 | grid : None, 'both', 'x', 'y' |
|
345 | grid : None, 'both', 'x', 'y' | |
346 | """ |
|
346 | """ | |
347 |
|
347 | |||
348 | matplotlib.pyplot.ioff() |
|
348 | matplotlib.pyplot.ioff() | |
349 |
|
349 | |||
350 | # lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle) |
|
350 | # lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle) | |
351 | lines = ax.plot(x, y.T) |
|
351 | lines = ax.plot(x, y.T) | |
352 | # leg = ax.legend(lines, legendlabels, loc=2, bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \ |
|
352 | # leg = ax.legend(lines, legendlabels, loc=2, bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \ | |
353 | # handletextpad=0.5, borderpad=0.5, labelspacing=0.5, borderaxespad=0.) |
|
353 | # handletextpad=0.5, borderpad=0.5, labelspacing=0.5, borderaxespad=0.) | |
354 |
|
354 | |||
355 | leg = ax.legend(lines, legendlabels, |
|
355 | leg = ax.legend(lines, legendlabels, | |
356 | loc='upper right', bbox_to_anchor=(1.16, 1), borderaxespad=0) |
|
356 | loc='upper right', bbox_to_anchor=(1.16, 1), borderaxespad=0) | |
357 |
|
357 | |||
358 | for label in leg.get_texts(): label.set_fontsize(9) |
|
358 | for label in leg.get_texts(): label.set_fontsize(9) | |
359 |
|
359 | |||
360 | ax.set_xlim([xmin,xmax]) |
|
360 | ax.set_xlim([xmin,xmax]) | |
361 | ax.set_ylim([ymin,ymax]) |
|
361 | ax.set_ylim([ymin,ymax]) | |
362 | printLabels(ax, xlabel, ylabel, title) |
|
362 | printLabels(ax, xlabel, ylabel, title) | |
363 |
|
363 | |||
364 | # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
|
364 | # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) | |
365 | # ax.set_xticks(xtickspos) |
|
365 | # ax.set_xticks(xtickspos) | |
366 |
|
366 | |||
367 | for tick in ax.get_xticklabels(): |
|
367 | for tick in ax.get_xticklabels(): | |
368 | tick.set_visible(xtick_visible) |
|
368 | tick.set_visible(xtick_visible) | |
369 |
|
369 | |||
370 | for tick in ax.xaxis.get_major_ticks(): |
|
370 | for tick in ax.xaxis.get_major_ticks(): | |
371 | tick.label.set_fontsize(ticksize) |
|
371 | tick.label.set_fontsize(ticksize) | |
372 |
|
372 | |||
373 | for tick in ax.get_yticklabels(): |
|
373 | for tick in ax.get_yticklabels(): | |
374 | tick.set_visible(ytick_visible) |
|
374 | tick.set_visible(ytick_visible) | |
375 |
|
375 | |||
376 | for tick in ax.yaxis.get_major_ticks(): |
|
376 | for tick in ax.yaxis.get_major_ticks(): | |
377 | tick.label.set_fontsize(ticksize) |
|
377 | tick.label.set_fontsize(ticksize) | |
378 |
|
378 | |||
379 | iplot = ax.lines[-1] |
|
379 | iplot = ax.lines[-1] | |
380 |
|
380 | |||
381 | if '0.' in matplotlib.__version__[0:2]: |
|
381 | if '0.' in matplotlib.__version__[0:2]: | |
382 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
382 | print "The matplotlib version has to be updated to 1.1 or newer" | |
383 | return iplot |
|
383 | return iplot | |
384 |
|
384 | |||
385 | if '1.0.' in matplotlib.__version__[0:4]: |
|
385 | if '1.0.' in matplotlib.__version__[0:4]: | |
386 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
386 | print "The matplotlib version has to be updated to 1.1 or newer" | |
387 | return iplot |
|
387 | return iplot | |
388 |
|
388 | |||
389 | if grid != None: |
|
389 | if grid != None: | |
390 | ax.grid(b=True, which='major', axis=grid) |
|
390 | ax.grid(b=True, which='major', axis=grid) | |
391 |
|
391 | |||
392 | matplotlib.pyplot.tight_layout() |
|
392 | matplotlib.pyplot.tight_layout() | |
393 |
|
393 | |||
394 | if XAxisAsTime: |
|
394 | if XAxisAsTime: | |
395 |
|
395 | |||
396 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) |
|
396 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) | |
397 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
397 | ax.xaxis.set_major_formatter(FuncFormatter(func)) | |
398 | ax.xaxis.set_major_locator(LinearLocator(7)) |
|
398 | ax.xaxis.set_major_locator(LinearLocator(7)) | |
399 |
|
399 | |||
400 | matplotlib.pyplot.ion() |
|
400 | matplotlib.pyplot.ion() | |
401 |
|
401 | |||
402 | return iplot |
|
402 | return iplot | |
403 |
|
403 | |||
404 | def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''): |
|
404 | def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''): | |
405 |
|
405 | |||
406 | ax = iplot.axes |
|
406 | ax = iplot.axes | |
407 |
|
407 | |||
408 | printLabels(ax, xlabel, ylabel, title) |
|
408 | printLabels(ax, xlabel, ylabel, title) | |
409 |
|
409 | |||
410 | for i in range(len(ax.lines)): |
|
410 | for i in range(len(ax.lines)): | |
411 | line = ax.lines[i] |
|
411 | line = ax.lines[i] | |
412 | line.set_data(x,y[i,:]) |
|
412 | line.set_data(x,y[i,:]) | |
413 |
|
413 | |||
414 | def createPolar(ax, x, y, |
|
414 | def createPolar(ax, x, y, | |
415 | xlabel='', ylabel='', title='', ticksize = 9, |
|
415 | xlabel='', ylabel='', title='', ticksize = 9, | |
416 | colormap='jet',cblabel='', cbsize="5%", |
|
416 | colormap='jet',cblabel='', cbsize="5%", | |
417 | XAxisAsTime=False): |
|
417 | XAxisAsTime=False): | |
418 |
|
418 | |||
419 | matplotlib.pyplot.ioff() |
|
419 | matplotlib.pyplot.ioff() | |
420 |
|
420 | |||
421 | ax.plot(x,y,'bo', markersize=5) |
|
421 | ax.plot(x,y,'bo', markersize=5) | |
422 | # ax.set_rmax(90) |
|
422 | # ax.set_rmax(90) | |
423 | ax.set_ylim(0,90) |
|
423 | ax.set_ylim(0,90) | |
424 | ax.set_yticks(numpy.arange(0,90,20)) |
|
424 | ax.set_yticks(numpy.arange(0,90,20)) | |
425 | # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center' ,size='11') |
|
425 | # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center' ,size='11') | |
426 | # ax.text(0, 50, ylabel, rotation='vertical', va ='center', ha = 'left' ,size='11') |
|
426 | # ax.text(0, 50, ylabel, rotation='vertical', va ='center', ha = 'left' ,size='11') | |
427 | # ax.text(100, 100, 'example', ha='left', va='center', rotation='vertical') |
|
427 | # ax.text(100, 100, 'example', ha='left', va='center', rotation='vertical') | |
428 | ax.yaxis.labelpad = 40 |
|
428 | ax.yaxis.labelpad = 40 | |
429 | printLabels(ax, xlabel, ylabel, title) |
|
429 | printLabels(ax, xlabel, ylabel, title) | |
430 | iplot = ax.lines[-1] |
|
430 | iplot = ax.lines[-1] | |
431 |
|
431 | |||
432 | if '0.' in matplotlib.__version__[0:2]: |
|
432 | if '0.' in matplotlib.__version__[0:2]: | |
433 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
433 | print "The matplotlib version has to be updated to 1.1 or newer" | |
434 | return iplot |
|
434 | return iplot | |
435 |
|
435 | |||
436 | if '1.0.' in matplotlib.__version__[0:4]: |
|
436 | if '1.0.' in matplotlib.__version__[0:4]: | |
437 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
437 | print "The matplotlib version has to be updated to 1.1 or newer" | |
438 | return iplot |
|
438 | return iplot | |
439 |
|
439 | |||
440 | # if grid != None: |
|
440 | # if grid != None: | |
441 | # ax.grid(b=True, which='major', axis=grid) |
|
441 | # ax.grid(b=True, which='major', axis=grid) | |
442 |
|
442 | |||
443 | matplotlib.pyplot.tight_layout() |
|
443 | matplotlib.pyplot.tight_layout() | |
444 |
|
444 | |||
445 | matplotlib.pyplot.ion() |
|
445 | matplotlib.pyplot.ion() | |
446 |
|
446 | |||
447 |
|
447 | |||
448 | return iplot |
|
448 | return iplot | |
449 |
|
449 | |||
450 | def polar(iplot, x, y, xlabel='', ylabel='', title=''): |
|
450 | def polar(iplot, x, y, xlabel='', ylabel='', title=''): | |
451 |
|
451 | |||
452 | ax = iplot.axes |
|
452 | ax = iplot.axes | |
453 |
|
453 | |||
454 | # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center',size='11') |
|
454 | # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center',size='11') | |
455 | printLabels(ax, xlabel, ylabel, title) |
|
455 | printLabels(ax, xlabel, ylabel, title) | |
456 |
|
456 | |||
457 | set_linedata(ax, x, y, idline=0) |
|
457 | set_linedata(ax, x, y, idline=0) | |
458 |
|
458 | |||
459 | def draw(fig): |
|
459 | def draw(fig): | |
460 |
|
460 | |||
461 | if type(fig) == 'int': |
|
461 | if type(fig) == 'int': | |
462 | raise ValueError, "Error drawing: Fig parameter should be a matplotlib figure object figure" |
|
462 | raise ValueError, "Error drawing: Fig parameter should be a matplotlib figure object figure" | |
463 |
|
463 | |||
464 | fig.canvas.draw() |
|
464 | fig.canvas.draw() | |
465 |
|
465 | |||
466 | def pause(interval=0.000001): |
|
466 | def pause(interval=0.000001): | |
467 |
|
467 | |||
468 | matplotlib.pyplot.pause(interval) |
|
468 | matplotlib.pyplot.pause(interval) |
@@ -1,445 +1,445 | |||||
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 | import cPickle as pickle |
|
10 | import cPickle as pickle | |
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 |
|
18 | |||
19 | MAXNUMX = 100 |
|
19 | MAXNUMX = 100 | |
20 | MAXNUMY = 100 |
|
20 | MAXNUMY = 100 | |
21 |
|
21 | |||
22 | class PrettyFloat(float): |
|
22 | class PrettyFloat(float): | |
23 | def __repr__(self): |
|
23 | def __repr__(self): | |
24 | return '%.2f' % self |
|
24 | return '%.2f' % self | |
25 |
|
25 | |||
26 | def roundFloats(obj): |
|
26 | def roundFloats(obj): | |
27 | if isinstance(obj, list): |
|
27 | if isinstance(obj, list): | |
28 | return map(roundFloats, obj) |
|
28 | return map(roundFloats, obj) | |
29 | elif isinstance(obj, float): |
|
29 | elif isinstance(obj, float): | |
30 | return round(obj, 2) |
|
30 | return round(obj, 2) | |
31 |
|
31 | |||
32 | def decimate(z): |
|
32 | def decimate(z): | |
33 | # dx = int(len(self.x)/self.__MAXNUMX) + 1 |
|
33 | # dx = int(len(self.x)/self.__MAXNUMX) + 1 | |
34 |
|
34 | |||
35 | dy = int(len(z[0])/MAXNUMY) + 1 |
|
35 | dy = int(len(z[0])/MAXNUMY) + 1 | |
36 |
|
36 | |||
37 | return z[::, ::dy] |
|
37 | return z[::, ::dy] | |
38 |
|
38 | |||
39 | class throttle(object): |
|
39 | class throttle(object): | |
40 | """Decorator that prevents a function from being called more than once every |
|
40 | """Decorator that prevents a function from being called more than once every | |
41 | time period. |
|
41 | time period. | |
42 | To create a function that cannot be called more than once a minute, but |
|
42 | To create a function that cannot be called more than once a minute, but | |
43 | will sleep until it can be called: |
|
43 | will sleep until it can be called: | |
44 | @throttle(minutes=1) |
|
44 | @throttle(minutes=1) | |
45 | def foo(): |
|
45 | def foo(): | |
46 | pass |
|
46 | pass | |
47 |
|
47 | |||
48 | for i in range(10): |
|
48 | for i in range(10): | |
49 | foo() |
|
49 | foo() | |
50 | print "This function has run %s times." % i |
|
50 | print "This function has run %s times." % i | |
51 | """ |
|
51 | """ | |
52 |
|
52 | |||
53 | def __init__(self, seconds=0, minutes=0, hours=0): |
|
53 | def __init__(self, seconds=0, minutes=0, hours=0): | |
54 | self.throttle_period = datetime.timedelta( |
|
54 | self.throttle_period = datetime.timedelta( | |
55 | seconds=seconds, minutes=minutes, hours=hours |
|
55 | seconds=seconds, minutes=minutes, hours=hours | |
56 | ) |
|
56 | ) | |
57 |
|
57 | |||
58 | self.time_of_last_call = datetime.datetime.min |
|
58 | self.time_of_last_call = datetime.datetime.min | |
59 |
|
59 | |||
60 | def __call__(self, fn): |
|
60 | def __call__(self, fn): | |
61 | @wraps(fn) |
|
61 | @wraps(fn) | |
62 | def wrapper(*args, **kwargs): |
|
62 | def wrapper(*args, **kwargs): | |
63 | now = datetime.datetime.now() |
|
63 | now = datetime.datetime.now() | |
64 | time_since_last_call = now - self.time_of_last_call |
|
64 | time_since_last_call = now - self.time_of_last_call | |
65 | time_left = self.throttle_period - time_since_last_call |
|
65 | time_left = self.throttle_period - time_since_last_call | |
66 |
|
66 | |||
67 | if time_left > datetime.timedelta(seconds=0): |
|
67 | if time_left > datetime.timedelta(seconds=0): | |
68 | return |
|
68 | return | |
69 |
|
69 | |||
70 | self.time_of_last_call = datetime.datetime.now() |
|
70 | self.time_of_last_call = datetime.datetime.now() | |
71 | return fn(*args, **kwargs) |
|
71 | return fn(*args, **kwargs) | |
72 |
|
72 | |||
73 | return wrapper |
|
73 | return wrapper | |
74 |
|
74 | |||
75 |
|
75 | |||
76 | class PublishData(Operation): |
|
76 | class PublishData(Operation): | |
77 | """Clase publish.""" |
|
77 | """Clase publish.""" | |
78 |
|
78 | |||
79 | def __init__(self, **kwargs): |
|
79 | def __init__(self, **kwargs): | |
80 | """Inicio.""" |
|
80 | """Inicio.""" | |
81 | Operation.__init__(self, **kwargs) |
|
81 | Operation.__init__(self, **kwargs) | |
82 | self.isConfig = False |
|
82 | self.isConfig = False | |
83 | self.client = None |
|
83 | self.client = None | |
84 | self.zeromq = None |
|
84 | self.zeromq = None | |
85 | self.mqtt = None |
|
85 | self.mqtt = None | |
86 |
|
86 | |||
87 | def on_disconnect(self, client, userdata, rc): |
|
87 | def on_disconnect(self, client, userdata, rc): | |
88 | if rc != 0: |
|
88 | if rc != 0: | |
89 | print("Unexpected disconnection.") |
|
89 | print("Unexpected disconnection.") | |
90 | self.connect() |
|
90 | self.connect() | |
91 |
|
91 | |||
92 | def connect(self): |
|
92 | def connect(self): | |
93 | print 'trying to connect' |
|
93 | print 'trying to connect' | |
94 | try: |
|
94 | try: | |
95 | self.client.connect( |
|
95 | self.client.connect( | |
96 | host=self.host, |
|
96 | host=self.host, | |
97 | port=self.port, |
|
97 | port=self.port, | |
98 | keepalive=60*10, |
|
98 | keepalive=60*10, | |
99 | bind_address='') |
|
99 | bind_address='') | |
100 | self.client.loop_start() |
|
100 | self.client.loop_start() | |
101 | # self.client.publish( |
|
101 | # self.client.publish( | |
102 | # self.topic + 'SETUP', |
|
102 | # self.topic + 'SETUP', | |
103 | # json.dumps(setup), |
|
103 | # json.dumps(setup), | |
104 | # retain=True |
|
104 | # retain=True | |
105 | # ) |
|
105 | # ) | |
106 | except: |
|
106 | except: | |
107 | print "MQTT Conection error." |
|
107 | print "MQTT Conection error." | |
108 | self.client = False |
|
108 | self.client = False | |
109 |
|
109 | |||
110 | def setup(self, port=1883, username=None, password=None, clientId="user", zeromq=1, **kwargs): |
|
110 | def setup(self, port=1883, username=None, password=None, clientId="user", zeromq=1, **kwargs): | |
111 | self.counter = 0 |
|
111 | self.counter = 0 | |
112 | self.topic = kwargs.get('topic', 'schain') |
|
112 | self.topic = kwargs.get('topic', 'schain') | |
113 | self.delay = kwargs.get('delay', 0) |
|
113 | self.delay = kwargs.get('delay', 0) | |
114 | self.plottype = kwargs.get('plottype', 'spectra') |
|
114 | self.plottype = kwargs.get('plottype', 'spectra') | |
115 | self.host = kwargs.get('host', "10.10.10.82") |
|
115 | self.host = kwargs.get('host', "10.10.10.82") | |
116 | self.port = kwargs.get('port', 3000) |
|
116 | self.port = kwargs.get('port', 3000) | |
117 | self.clientId = clientId |
|
117 | self.clientId = clientId | |
118 | self.cnt = 0 |
|
118 | self.cnt = 0 | |
119 | self.zeromq = zeromq |
|
119 | self.zeromq = zeromq | |
120 | self.mqtt = kwargs.get('plottype', 0) |
|
120 | self.mqtt = kwargs.get('plottype', 0) | |
121 | self.client = None |
|
121 | self.client = None | |
122 | setup = [] |
|
122 | setup = [] | |
123 | if mqtt is 1: |
|
123 | if mqtt is 1: | |
124 | self.client = mqtt.Client( |
|
124 | self.client = mqtt.Client( | |
125 | client_id=self.clientId + self.topic + 'SCHAIN', |
|
125 | client_id=self.clientId + self.topic + 'SCHAIN', | |
126 | clean_session=True) |
|
126 | clean_session=True) | |
127 | self.client.on_disconnect = self.on_disconnect |
|
127 | self.client.on_disconnect = self.on_disconnect | |
128 | self.connect() |
|
128 | self.connect() | |
129 | for plot in self.plottype: |
|
129 | for plot in self.plottype: | |
130 | setup.append({ |
|
130 | setup.append({ | |
131 | 'plot': plot, |
|
131 | 'plot': plot, | |
132 | 'topic': self.topic + plot, |
|
132 | 'topic': self.topic + plot, | |
133 | 'title': getattr(self, plot + '_' + 'title', False), |
|
133 | 'title': getattr(self, plot + '_' + 'title', False), | |
134 | 'xlabel': getattr(self, plot + '_' + 'xlabel', False), |
|
134 | 'xlabel': getattr(self, plot + '_' + 'xlabel', False), | |
135 | 'ylabel': getattr(self, plot + '_' + 'ylabel', False), |
|
135 | 'ylabel': getattr(self, plot + '_' + 'ylabel', False), | |
136 | 'xrange': getattr(self, plot + '_' + 'xrange', False), |
|
136 | 'xrange': getattr(self, plot + '_' + 'xrange', False), | |
137 | 'yrange': getattr(self, plot + '_' + 'yrange', False), |
|
137 | 'yrange': getattr(self, plot + '_' + 'yrange', False), | |
138 | 'zrange': getattr(self, plot + '_' + 'zrange', False), |
|
138 | 'zrange': getattr(self, plot + '_' + 'zrange', False), | |
139 | }) |
|
139 | }) | |
140 | if zeromq is 1: |
|
140 | if zeromq is 1: | |
141 | context = zmq.Context() |
|
141 | context = zmq.Context() | |
142 | self.zmq_socket = context.socket(zmq.PUSH) |
|
142 | self.zmq_socket = context.socket(zmq.PUSH) | |
143 | server = kwargs.get('server', 'zmq.pipe') |
|
143 | server = kwargs.get('server', 'zmq.pipe') | |
144 |
|
144 | |||
145 | if 'tcp://' in server: |
|
145 | if 'tcp://' in server: | |
146 | address = server |
|
146 | address = server | |
147 | else: |
|
147 | else: | |
148 | address = 'ipc:///tmp/%s' % server |
|
148 | address = 'ipc:///tmp/%s' % server | |
149 |
|
149 | |||
150 | self.zmq_socket.connect(address) |
|
150 | self.zmq_socket.connect(address) | |
151 | time.sleep(1) |
|
151 | time.sleep(1) | |
152 |
|
152 | |||
153 | def publish_data(self): |
|
153 | def publish_data(self): | |
154 | self.dataOut.finished = False |
|
154 | self.dataOut.finished = False | |
155 | if self.mqtt is 1: |
|
155 | if self.mqtt is 1: | |
156 | yData = self.dataOut.heightList[:2].tolist() |
|
156 | yData = self.dataOut.heightList[:2].tolist() | |
157 | if self.plottype == 'spectra': |
|
157 | if self.plottype == 'spectra': | |
158 | data = getattr(self.dataOut, 'data_spc') |
|
158 | data = getattr(self.dataOut, 'data_spc') | |
159 | z = data/self.dataOut.normFactor |
|
159 | z = data/self.dataOut.normFactor | |
160 | zdB = 10*numpy.log10(z) |
|
160 | zdB = 10*numpy.log10(z) | |
161 | xlen, ylen = zdB[0].shape |
|
161 | xlen, ylen = zdB[0].shape | |
162 | dx = int(xlen/MAXNUMX) + 1 |
|
162 | dx = int(xlen/MAXNUMX) + 1 | |
163 | dy = int(ylen/MAXNUMY) + 1 |
|
163 | dy = int(ylen/MAXNUMY) + 1 | |
164 | Z = [0 for i in self.dataOut.channelList] |
|
164 | Z = [0 for i in self.dataOut.channelList] | |
165 | for i in self.dataOut.channelList: |
|
165 | for i in self.dataOut.channelList: | |
166 | Z[i] = zdB[i][::dx, ::dy].tolist() |
|
166 | Z[i] = zdB[i][::dx, ::dy].tolist() | |
167 | payload = { |
|
167 | payload = { | |
168 | 'timestamp': self.dataOut.utctime, |
|
168 | 'timestamp': self.dataOut.utctime, | |
169 | 'data': roundFloats(Z), |
|
169 | 'data': roundFloats(Z), | |
170 | 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList], |
|
170 | 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList], | |
171 | 'interval': self.dataOut.getTimeInterval(), |
|
171 | 'interval': self.dataOut.getTimeInterval(), | |
172 | 'type': self.plottype, |
|
172 | 'type': self.plottype, | |
173 | 'yData': yData |
|
173 | 'yData': yData | |
174 | } |
|
174 | } | |
175 | # print payload |
|
175 | # print payload | |
176 |
|
176 | |||
177 | elif self.plottype in ('rti', 'power'): |
|
177 | elif self.plottype in ('rti', 'power'): | |
178 | data = getattr(self.dataOut, 'data_spc') |
|
178 | data = getattr(self.dataOut, 'data_spc') | |
179 | z = data/self.dataOut.normFactor |
|
179 | z = data/self.dataOut.normFactor | |
180 | avg = numpy.average(z, axis=1) |
|
180 | avg = numpy.average(z, axis=1) | |
181 | avgdB = 10*numpy.log10(avg) |
|
181 | avgdB = 10*numpy.log10(avg) | |
182 | xlen, ylen = z[0].shape |
|
182 | xlen, ylen = z[0].shape | |
183 | dy = numpy.floor(ylen/self.__MAXNUMY) + 1 |
|
183 | dy = numpy.floor(ylen/self.__MAXNUMY) + 1 | |
184 | AVG = [0 for i in self.dataOut.channelList] |
|
184 | AVG = [0 for i in self.dataOut.channelList] | |
185 | for i in self.dataOut.channelList: |
|
185 | for i in self.dataOut.channelList: | |
186 | AVG[i] = avgdB[i][::dy].tolist() |
|
186 | AVG[i] = avgdB[i][::dy].tolist() | |
187 | payload = { |
|
187 | payload = { | |
188 | 'timestamp': self.dataOut.utctime, |
|
188 | 'timestamp': self.dataOut.utctime, | |
189 | 'data': roundFloats(AVG), |
|
189 | 'data': roundFloats(AVG), | |
190 | 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList], |
|
190 | 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList], | |
191 | 'interval': self.dataOut.getTimeInterval(), |
|
191 | 'interval': self.dataOut.getTimeInterval(), | |
192 | 'type': self.plottype, |
|
192 | 'type': self.plottype, | |
193 | 'yData': yData |
|
193 | 'yData': yData | |
194 | } |
|
194 | } | |
195 | elif self.plottype == 'noise': |
|
195 | elif self.plottype == 'noise': | |
196 | noise = self.dataOut.getNoise()/self.dataOut.normFactor |
|
196 | noise = self.dataOut.getNoise()/self.dataOut.normFactor | |
197 | noisedB = 10*numpy.log10(noise) |
|
197 | noisedB = 10*numpy.log10(noise) | |
198 | payload = { |
|
198 | payload = { | |
199 | 'timestamp': self.dataOut.utctime, |
|
199 | 'timestamp': self.dataOut.utctime, | |
200 | 'data': roundFloats(noisedB.reshape(-1, 1).tolist()), |
|
200 | 'data': roundFloats(noisedB.reshape(-1, 1).tolist()), | |
201 | 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList], |
|
201 | 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList], | |
202 | 'interval': self.dataOut.getTimeInterval(), |
|
202 | 'interval': self.dataOut.getTimeInterval(), | |
203 | 'type': self.plottype, |
|
203 | 'type': self.plottype, | |
204 | 'yData': yData |
|
204 | 'yData': yData | |
205 | } |
|
205 | } | |
206 | elif self.plottype == 'snr': |
|
206 | elif self.plottype == 'snr': | |
207 | data = getattr(self.dataOut, 'data_SNR') |
|
207 | data = getattr(self.dataOut, 'data_SNR') | |
208 | avgdB = 10*numpy.log10(data) |
|
208 | avgdB = 10*numpy.log10(data) | |
209 |
|
209 | |||
210 | ylen = data[0].size |
|
210 | ylen = data[0].size | |
211 | dy = numpy.floor(ylen/self.__MAXNUMY) + 1 |
|
211 | dy = numpy.floor(ylen/self.__MAXNUMY) + 1 | |
212 | AVG = [0 for i in self.dataOut.channelList] |
|
212 | AVG = [0 for i in self.dataOut.channelList] | |
213 | for i in self.dataOut.channelList: |
|
213 | for i in self.dataOut.channelList: | |
214 | AVG[i] = avgdB[i][::dy].tolist() |
|
214 | AVG[i] = avgdB[i][::dy].tolist() | |
215 | payload = { |
|
215 | payload = { | |
216 | 'timestamp': self.dataOut.utctime, |
|
216 | 'timestamp': self.dataOut.utctime, | |
217 | 'data': roundFloats(AVG), |
|
217 | 'data': roundFloats(AVG), | |
218 | 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList], |
|
218 | 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList], | |
219 | 'type': self.plottype, |
|
219 | 'type': self.plottype, | |
220 | 'yData': yData |
|
220 | 'yData': yData | |
221 | } |
|
221 | } | |
222 | else: |
|
222 | else: | |
223 | print "Tipo de grafico invalido" |
|
223 | print "Tipo de grafico invalido" | |
224 | payload = { |
|
224 | payload = { | |
225 | 'data': 'None', |
|
225 | 'data': 'None', | |
226 | 'timestamp': 'None', |
|
226 | 'timestamp': 'None', | |
227 | 'type': None |
|
227 | 'type': None | |
228 | } |
|
228 | } | |
229 | # print 'Publishing data to {}'.format(self.host) |
|
229 | # print 'Publishing data to {}'.format(self.host) | |
230 | self.client.publish(self.topic + self.plottype, json.dumps(payload), qos=0) |
|
230 | self.client.publish(self.topic + self.plottype, json.dumps(payload), qos=0) | |
231 |
|
231 | |||
232 | if self.zeromq is 1: |
|
232 | if self.zeromq is 1: | |
233 | print '[Sending] {} - {}'.format(self.dataOut.type, self.dataOut.datatime) |
|
233 | print '[Sending] {} - {}'.format(self.dataOut.type, self.dataOut.datatime) | |
234 | self.zmq_socket.send_pyobj(self.dataOut) |
|
234 | self.zmq_socket.send_pyobj(self.dataOut) | |
235 |
|
235 | |||
236 | def run(self, dataOut, **kwargs): |
|
236 | def run(self, dataOut, **kwargs): | |
237 | self.dataOut = dataOut |
|
237 | self.dataOut = dataOut | |
238 | if not self.isConfig: |
|
238 | if not self.isConfig: | |
239 | self.setup(**kwargs) |
|
239 | self.setup(**kwargs) | |
240 | self.isConfig = True |
|
240 | self.isConfig = True | |
241 |
|
241 | |||
242 | self.publish_data() |
|
242 | self.publish_data() | |
243 | time.sleep(self.delay) |
|
243 | time.sleep(self.delay) | |
244 |
|
244 | |||
245 | def close(self): |
|
245 | def close(self): | |
246 | if self.zeromq is 1: |
|
246 | if self.zeromq is 1: | |
247 | self.dataOut.finished = True |
|
247 | self.dataOut.finished = True | |
248 |
|
|
248 | self.zmq_socket.send_pyobj(self.dataOut) | |
249 |
|
249 | |||
250 | if self.client: |
|
250 | if self.client: | |
251 | self.client.loop_stop() |
|
251 | self.client.loop_stop() | |
252 | self.client.disconnect() |
|
252 | self.client.disconnect() | |
253 |
|
253 | |||
254 |
|
254 | |||
255 | class ReceiverData(ProcessingUnit, Process): |
|
255 | class ReceiverData(ProcessingUnit, Process): | |
256 |
|
256 | |||
257 | throttle_value = 5 |
|
257 | throttle_value = 5 | |
258 |
|
258 | |||
259 | def __init__(self, **kwargs): |
|
259 | def __init__(self, **kwargs): | |
260 |
|
260 | |||
261 | ProcessingUnit.__init__(self, **kwargs) |
|
261 | ProcessingUnit.__init__(self, **kwargs) | |
262 | Process.__init__(self) |
|
262 | Process.__init__(self) | |
263 | self.mp = False |
|
263 | self.mp = False | |
264 | self.isConfig = False |
|
264 | self.isConfig = False | |
265 | self.isWebConfig = False |
|
265 | self.isWebConfig = False | |
266 | self.plottypes =[] |
|
266 | self.plottypes =[] | |
267 | self.connections = 0 |
|
267 | self.connections = 0 | |
268 | server = kwargs.get('server', 'zmq.pipe') |
|
268 | server = kwargs.get('server', 'zmq.pipe') | |
269 | plot_server = kwargs.get('plot_server', 'zmq.web') |
|
269 | plot_server = kwargs.get('plot_server', 'zmq.web') | |
270 | if 'tcp://' in server: |
|
270 | if 'tcp://' in server: | |
271 | address = server |
|
271 | address = server | |
272 | else: |
|
272 | else: | |
273 | address = 'ipc:///tmp/%s' % server |
|
273 | address = 'ipc:///tmp/%s' % server | |
274 |
|
274 | |||
275 | if 'tcp://' in plot_server: |
|
275 | if 'tcp://' in plot_server: | |
276 | plot_address = plot_server |
|
276 | plot_address = plot_server | |
277 | else: |
|
277 | else: | |
278 | plot_address = 'ipc:///tmp/%s' % plot_server |
|
278 | plot_address = 'ipc:///tmp/%s' % plot_server | |
279 |
|
279 | |||
280 | self.address = address |
|
280 | self.address = address | |
281 | self.plot_address = plot_address |
|
281 | self.plot_address = plot_address | |
282 | self.plottypes = [s.strip() for s in kwargs.get('plottypes', 'rti').split(',')] |
|
282 | self.plottypes = [s.strip() for s in kwargs.get('plottypes', 'rti').split(',')] | |
283 | self.realtime = kwargs.get('realtime', False) |
|
283 | self.realtime = kwargs.get('realtime', False) | |
284 | self.throttle_value = kwargs.get('throttle', 5) |
|
284 | self.throttle_value = kwargs.get('throttle', 5) | |
285 | self.sendData = self.initThrottle(self.throttle_value) |
|
285 | self.sendData = self.initThrottle(self.throttle_value) | |
286 | self.setup() |
|
286 | self.setup() | |
287 |
|
287 | |||
288 | def setup(self): |
|
288 | def setup(self): | |
289 |
|
289 | |||
290 | self.data = {} |
|
290 | self.data = {} | |
291 | self.data['times'] = [] |
|
291 | self.data['times'] = [] | |
292 | for plottype in self.plottypes: |
|
292 | for plottype in self.plottypes: | |
293 | self.data[plottype] = {} |
|
293 | self.data[plottype] = {} | |
294 | self.data['noise'] = {} |
|
294 | self.data['noise'] = {} | |
295 | self.data['throttle'] = self.throttle_value |
|
295 | self.data['throttle'] = self.throttle_value | |
296 | self.data['ENDED'] = False |
|
296 | self.data['ENDED'] = False | |
297 | self.isConfig = True |
|
297 | self.isConfig = True | |
298 | self.data_web = {} |
|
298 | self.data_web = {} | |
299 |
|
299 | |||
300 | def event_monitor(self, monitor): |
|
300 | def event_monitor(self, monitor): | |
301 |
|
301 | |||
302 | events = {} |
|
302 | events = {} | |
303 |
|
303 | |||
304 | for name in dir(zmq): |
|
304 | for name in dir(zmq): | |
305 | if name.startswith('EVENT_'): |
|
305 | if name.startswith('EVENT_'): | |
306 | value = getattr(zmq, name) |
|
306 | value = getattr(zmq, name) | |
307 | events[value] = name |
|
307 | events[value] = name | |
308 |
|
308 | |||
309 | while monitor.poll(): |
|
309 | while monitor.poll(): | |
310 | evt = recv_monitor_message(monitor) |
|
310 | evt = recv_monitor_message(monitor) | |
311 | if evt['event'] == 32: |
|
311 | if evt['event'] == 32: | |
312 | self.connections += 1 |
|
312 | self.connections += 1 | |
313 | if evt['event'] == 512: |
|
313 | if evt['event'] == 512: | |
314 | pass |
|
314 | pass | |
315 | if self.connections == 0 and self.started is True: |
|
315 | if self.connections == 0 and self.started is True: | |
316 | self.ended = True |
|
316 | self.ended = True | |
317 |
|
317 | |||
318 | evt.update({'description': events[evt['event']]}) |
|
318 | evt.update({'description': events[evt['event']]}) | |
319 |
|
319 | |||
320 | if evt['event'] == zmq.EVENT_MONITOR_STOPPED: |
|
320 | if evt['event'] == zmq.EVENT_MONITOR_STOPPED: | |
321 | break |
|
321 | break | |
322 | monitor.close() |
|
322 | monitor.close() | |
323 | print("event monitor thread done!") |
|
323 | print("event monitor thread done!") | |
324 |
|
324 | |||
325 | def initThrottle(self, throttle_value): |
|
325 | def initThrottle(self, throttle_value): | |
326 |
|
326 | |||
327 | @throttle(seconds=throttle_value) |
|
327 | @throttle(seconds=throttle_value) | |
328 | def sendDataThrottled(fn_sender, data): |
|
328 | def sendDataThrottled(fn_sender, data): | |
329 | fn_sender(data) |
|
329 | fn_sender(data) | |
330 |
|
330 | |||
331 | return sendDataThrottled |
|
331 | return sendDataThrottled | |
332 |
|
332 | |||
333 | def send(self, data): |
|
333 | def send(self, data): | |
334 | # print '[sending] data=%s size=%s' % (data.keys(), len(data['times'])) |
|
334 | # print '[sending] data=%s size=%s' % (data.keys(), len(data['times'])) | |
335 | self.sender.send_pyobj(data) |
|
335 | self.sender.send_pyobj(data) | |
336 |
|
336 | |||
337 | def update(self): |
|
337 | def update(self): | |
338 |
|
338 | |||
339 | t = self.dataOut.utctime |
|
339 | t = self.dataOut.utctime | |
340 |
|
340 | |||
341 | if t in self.data['times']: |
|
341 | if t in self.data['times']: | |
342 | return |
|
342 | return | |
343 |
|
343 | |||
344 | self.data['times'].append(t) |
|
344 | self.data['times'].append(t) | |
345 | self.data['dataOut'] = self.dataOut |
|
345 | self.data['dataOut'] = self.dataOut | |
346 |
|
346 | |||
347 | for plottype in self.plottypes: |
|
347 | for plottype in self.plottypes: | |
348 | if plottype == 'spc': |
|
348 | if plottype == 'spc': | |
349 | z = self.dataOut.data_spc/self.dataOut.normFactor |
|
349 | z = self.dataOut.data_spc/self.dataOut.normFactor | |
350 | self.data[plottype] = 10*numpy.log10(z) |
|
350 | self.data[plottype] = 10*numpy.log10(z) | |
351 | self.data['noise'][t] = 10*numpy.log10(self.dataOut.getNoise()/self.dataOut.normFactor) |
|
351 | self.data['noise'][t] = 10*numpy.log10(self.dataOut.getNoise()/self.dataOut.normFactor) | |
352 | if plottype == 'cspc': |
|
352 | if plottype == 'cspc': | |
353 | jcoherence = self.dataOut.data_cspc/numpy.sqrt(self.dataOut.data_spc*self.dataOut.data_spc) |
|
353 | jcoherence = self.dataOut.data_cspc/numpy.sqrt(self.dataOut.data_spc*self.dataOut.data_spc) | |
354 | self.data['cspc_coh'] = numpy.abs(jcoherence) |
|
354 | self.data['cspc_coh'] = numpy.abs(jcoherence) | |
355 | self.data['cspc_phase'] = numpy.arctan2(jcoherence.imag, jcoherence.real)*180/numpy.pi |
|
355 | self.data['cspc_phase'] = numpy.arctan2(jcoherence.imag, jcoherence.real)*180/numpy.pi | |
356 | if plottype == 'rti': |
|
356 | if plottype == 'rti': | |
357 | self.data[plottype][t] = self.dataOut.getPower() |
|
357 | self.data[plottype][t] = self.dataOut.getPower() | |
358 | if plottype == 'snr': |
|
358 | if plottype == 'snr': | |
359 | self.data[plottype][t] = 10*numpy.log10(self.dataOut.data_SNR) |
|
359 | self.data[plottype][t] = 10*numpy.log10(self.dataOut.data_SNR) | |
360 | if plottype == 'dop': |
|
360 | if plottype == 'dop': | |
361 | self.data[plottype][t] = 10*numpy.log10(self.dataOut.data_DOP) |
|
361 | self.data[plottype][t] = 10*numpy.log10(self.dataOut.data_DOP) | |
362 | if plottype == 'mean': |
|
362 | if plottype == 'mean': | |
363 | self.data[plottype][t] = self.dataOut.data_MEAN |
|
363 | self.data[plottype][t] = self.dataOut.data_MEAN | |
364 | if plottype == 'std': |
|
364 | if plottype == 'std': | |
365 | self.data[plottype][t] = self.dataOut.data_STD |
|
365 | self.data[plottype][t] = self.dataOut.data_STD | |
366 | if plottype == 'coh': |
|
366 | if plottype == 'coh': | |
367 | self.data[plottype][t] = self.dataOut.getCoherence() |
|
367 | self.data[plottype][t] = self.dataOut.getCoherence() | |
368 | if plottype == 'phase': |
|
368 | if plottype == 'phase': | |
369 | self.data[plottype][t] = self.dataOut.getCoherence(phase=True) |
|
369 | self.data[plottype][t] = self.dataOut.getCoherence(phase=True) | |
370 | if plottype == 'wind': |
|
370 | if plottype == 'wind': | |
371 | self.data[plottype][t] = self.dataOut.data_output |
|
371 | self.data[plottype][t] = self.dataOut.data_output | |
372 | if self.realtime: |
|
372 | if self.realtime: | |
373 | self.data_web['timestamp'] = t |
|
373 | self.data_web['timestamp'] = t | |
374 | if plottype == 'spc': |
|
374 | if plottype == 'spc': | |
375 | self.data_web[plottype] = roundFloats(decimate(self.data[plottype]).tolist()) |
|
375 | self.data_web[plottype] = roundFloats(decimate(self.data[plottype]).tolist()) | |
376 | elif plottype == 'cspc': |
|
376 | elif plottype == 'cspc': | |
377 | self.data_web['cspc_coh'] = roundFloats(decimate(self.data['cspc_coh']).tolist()) |
|
377 | self.data_web['cspc_coh'] = roundFloats(decimate(self.data['cspc_coh']).tolist()) | |
378 | self.data_web['cspc_phase'] = roundFloats(decimate(self.data['cspc_phase']).tolist()) |
|
378 | self.data_web['cspc_phase'] = roundFloats(decimate(self.data['cspc_phase']).tolist()) | |
379 | elif plottype == 'noise': |
|
379 | elif plottype == 'noise': | |
380 | self.data_web['noise'] = roundFloats(self.data['noise'][t].tolist()) |
|
380 | self.data_web['noise'] = roundFloats(self.data['noise'][t].tolist()) | |
381 | else: |
|
381 | else: | |
382 | self.data_web[plottype] = roundFloats(decimate(self.data[plottype][t]).tolist()) |
|
382 | self.data_web[plottype] = roundFloats(decimate(self.data[plottype][t]).tolist()) | |
383 | self.data_web['interval'] = self.dataOut.getTimeInterval() |
|
383 | self.data_web['interval'] = self.dataOut.getTimeInterval() | |
384 | self.data_web['type'] = plottype |
|
384 | self.data_web['type'] = plottype | |
385 |
|
385 | |||
386 | def run(self): |
|
386 | def run(self): | |
387 |
|
387 | |||
388 | print '[Starting] {} from {}'.format(self.name, self.address) |
|
388 | print '[Starting] {} from {}'.format(self.name, self.address) | |
389 |
|
389 | |||
390 | self.context = zmq.Context() |
|
390 | self.context = zmq.Context() | |
391 | self.receiver = self.context.socket(zmq.PULL) |
|
391 | self.receiver = self.context.socket(zmq.PULL) | |
392 | self.receiver.bind(self.address) |
|
392 | self.receiver.bind(self.address) | |
393 | monitor = self.receiver.get_monitor_socket() |
|
393 | monitor = self.receiver.get_monitor_socket() | |
394 | self.sender = self.context.socket(zmq.PUB) |
|
394 | self.sender = self.context.socket(zmq.PUB) | |
395 | if self.realtime: |
|
395 | if self.realtime: | |
396 | self.sender_web = self.context.socket(zmq.PUB) |
|
396 | self.sender_web = self.context.socket(zmq.PUB) | |
397 | self.sender_web.connect(self.plot_address) |
|
397 | self.sender_web.connect(self.plot_address) | |
398 | time.sleep(1) |
|
398 | time.sleep(1) | |
399 | self.sender.bind("ipc:///tmp/zmq.plots") |
|
399 | self.sender.bind("ipc:///tmp/zmq.plots") | |
400 |
|
400 | |||
401 | t = Thread(target=self.event_monitor, args=(monitor,)) |
|
401 | t = Thread(target=self.event_monitor, args=(monitor,)) | |
402 | t.start() |
|
402 | t.start() | |
403 |
|
403 | |||
404 | while True: |
|
404 | while True: | |
405 | self.dataOut = self.receiver.recv_pyobj() |
|
405 | self.dataOut = self.receiver.recv_pyobj() | |
406 | # print '[Receiving] {} - {}'.format(self.dataOut.type, |
|
406 | # print '[Receiving] {} - {}'.format(self.dataOut.type, | |
407 | # self.dataOut.datatime.ctime()) |
|
407 | # self.dataOut.datatime.ctime()) | |
408 |
|
408 | |||
409 | self.update() |
|
409 | self.update() | |
410 |
|
410 | |||
411 | if self.dataOut.finished is True: |
|
411 | if self.dataOut.finished is True: | |
412 | self.send(self.data) |
|
412 | self.send(self.data) | |
413 | self.connections -= 1 |
|
413 | self.connections -= 1 | |
414 | if self.connections == 0 and self.started: |
|
414 | if self.connections == 0 and self.started: | |
415 | self.ended = True |
|
415 | self.ended = True | |
416 | self.data['ENDED'] = True |
|
416 | self.data['ENDED'] = True | |
417 | self.send(self.data) |
|
417 | self.send(self.data) | |
418 | self.setup() |
|
418 | self.setup() | |
419 | else: |
|
419 | else: | |
420 | if self.realtime: |
|
420 | if self.realtime: | |
421 | self.send(self.data) |
|
421 | self.send(self.data) | |
422 | self.sender_web.send_string(json.dumps(self.data_web)) |
|
422 | self.sender_web.send_string(json.dumps(self.data_web)) | |
423 | else: |
|
423 | else: | |
424 | self.sendData(self.send, self.data) |
|
424 | self.sendData(self.send, self.data) | |
425 | self.started = True |
|
425 | self.started = True | |
426 |
|
426 | |||
427 | return |
|
427 | return | |
428 |
|
428 | |||
429 | def sendToWeb(self): |
|
429 | def sendToWeb(self): | |
430 |
|
430 | |||
431 | if not self.isWebConfig: |
|
431 | if not self.isWebConfig: | |
432 | context = zmq.Context() |
|
432 | context = zmq.Context() | |
433 | sender_web_config = context.socket(zmq.PUB) |
|
433 | sender_web_config = context.socket(zmq.PUB) | |
434 | if 'tcp://' in self.plot_address: |
|
434 | if 'tcp://' in self.plot_address: | |
435 | dum, address, port = self.plot_address.split(':') |
|
435 | dum, address, port = self.plot_address.split(':') | |
436 | conf_address = '{}:{}:{}'.format(dum, address, int(port)+1) |
|
436 | conf_address = '{}:{}:{}'.format(dum, address, int(port)+1) | |
437 | else: |
|
437 | else: | |
438 | conf_address = self.plot_address + '.config' |
|
438 | conf_address = self.plot_address + '.config' | |
439 | sender_web_config.bind(conf_address) |
|
439 | sender_web_config.bind(conf_address) | |
440 | time.sleep(1) |
|
440 | time.sleep(1) | |
441 | for kwargs in self.operationKwargs.values(): |
|
441 | for kwargs in self.operationKwargs.values(): | |
442 | if 'plot' in kwargs: |
|
442 | if 'plot' in kwargs: | |
443 | print '[Sending] Config data to web for {}'.format(kwargs['code'].upper()) |
|
443 | print '[Sending] Config data to web for {}'.format(kwargs['code'].upper()) | |
444 | sender_web_config.send_string(json.dumps(kwargs)) |
|
444 | sender_web_config.send_string(json.dumps(kwargs)) | |
445 | self.isWebConfig = True |
|
445 | self.isWebConfig = True |
@@ -1,87 +1,87 | |||||
1 | import argparse |
|
1 | import argparse | |
2 |
|
2 | |||
3 | from schainpy.controller import Project, multiSchain |
|
3 | from schainpy.controller import Project, multiSchain | |
4 |
|
4 | |||
5 | desc = "HF_EXAMPLE" |
|
5 | desc = "HF_EXAMPLE" | |
6 |
|
6 | |||
7 | def fiber(cursor, skip, q, dt): |
|
7 | def fiber(cursor, skip, q, dt): | |
8 |
|
8 | |||
9 | controllerObj = Project() |
|
9 | controllerObj = Project() | |
10 |
|
10 | |||
11 | controllerObj.setup(id='191', name='test01', description=desc) |
|
11 | controllerObj.setup(id='191', name='test01', description=desc) | |
12 |
|
12 | |||
13 | readUnitConfObj = controllerObj.addReadUnit(datatype='SpectraReader', |
|
13 | readUnitConfObj = controllerObj.addReadUnit(datatype='SpectraReader', | |
14 | path='/home/nanosat/data/hysell_data20/pdata', |
|
14 | path='/home/nanosat/data/hysell_data20/pdata', | |
15 | startDate=dt, |
|
15 | startDate=dt, | |
16 | endDate=dt, |
|
16 | endDate=dt, | |
17 | startTime="00:00:00", |
|
17 | startTime="00:00:00", | |
18 | endTime="23:59:59", |
|
18 | endTime="23:59:59", | |
19 | online=0, |
|
19 | online=0, | |
20 | #set=1426485881, |
|
20 | #set=1426485881, | |
21 | delay=10, |
|
21 | delay=10, | |
22 | walk=1, |
|
22 | walk=1, | |
23 | queue=q, |
|
23 | queue=q, | |
24 | cursor=cursor, |
|
24 | cursor=cursor, | |
25 | skip=skip, |
|
25 | skip=skip, | |
26 | #timezone=-5*3600 |
|
26 | #timezone=-5*3600 | |
27 | ) |
|
27 | ) | |
28 |
|
28 | |||
29 | # #opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock') |
|
29 | # #opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock') | |
30 | # |
|
30 | # | |
31 | procUnitConfObj2 = controllerObj.addProcUnit(datatype='Spectra', inputId=readUnitConfObj.getId()) |
|
31 | procUnitConfObj2 = controllerObj.addProcUnit(datatype='Spectra', inputId=readUnitConfObj.getId()) | |
32 | # opObj11 = procUnitConfObj2.addParameter(name='pairsList', value='(0,1)', format='pairslist') |
|
32 | # opObj11 = procUnitConfObj2.addParameter(name='pairsList', value='(0,1)', format='pairslist') | |
33 | # |
|
33 | # | |
34 |
|
|
34 | procUnitConfObj3 = controllerObj.addProcUnit(datatype='ParametersProc', inputId=readUnitConfObj.getId()) | |
35 |
|
|
35 | opObj11 = procUnitConfObj3.addOperation(name='SpectralMoments', optype='other') | |
36 |
|
36 | |||
37 | # |
|
37 | # | |
38 | # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') |
|
38 | # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') | |
39 | # opObj11.addParameter(name='id', value='1000', format='int') |
|
39 | # opObj11.addParameter(name='id', value='1000', format='int') | |
40 | # opObj11.addParameter(name='wintitle', value='HF_Jicamarca_Spc', format='str') |
|
40 | # opObj11.addParameter(name='wintitle', value='HF_Jicamarca_Spc', format='str') | |
41 | # opObj11.addParameter(name='channelList', value='0', format='intlist') |
|
41 | # opObj11.addParameter(name='channelList', value='0', format='intlist') | |
42 | # opObj11.addParameter(name='zmin', value='-120', format='float') |
|
42 | # opObj11.addParameter(name='zmin', value='-120', format='float') | |
43 | # opObj11.addParameter(name='zmax', value='-70', format='float') |
|
43 | # opObj11.addParameter(name='zmax', value='-70', format='float') | |
44 | # opObj11.addParameter(name='save', value='1', format='int') |
|
44 | # opObj11.addParameter(name='save', value='1', format='int') | |
45 | # opObj11.addParameter(name='figpath', value=figpath, format='str') |
|
45 | # opObj11.addParameter(name='figpath', value=figpath, format='str') | |
46 |
|
46 | |||
47 | # opObj11 = procUnitConfObj2.addOperation(name='RTIPlot', optype='other') |
|
47 | # opObj11 = procUnitConfObj2.addOperation(name='RTIPlot', optype='other') | |
48 | # opObj11.addParameter(name='id', value='2000', format='int') |
|
48 | # opObj11.addParameter(name='id', value='2000', format='int') | |
49 | # opObj11.addParameter(name='wintitzmaxle', value='HF_Jicamarca', format='str') |
|
49 | # opObj11.addParameter(name='wintitzmaxle', value='HF_Jicamarca', format='str') | |
50 | # opObj11.addParameter(name='showprofile', value='0', format='int') |
|
50 | # opObj11.addParameter(name='showprofile', value='0', format='int') | |
51 | # # opObj11.addParameter(name='channelList', value='0', format='intlist') |
|
51 | # # opObj11.addParameter(name='channelList', value='0', format='intlist') | |
52 | # # opObj11.addParameter(name='xmin', value='0', format='float') |
|
52 | # # opObj11.addParameter(name='xmin', value='0', format='float') | |
53 | # opObj11.addParameter(name='xmin', value='0', format='float') |
|
53 | # opObj11.addParameter(name='xmin', value='0', format='float') | |
54 | # opObj11.addParameter(name='xmax', value='24', format='float') |
|
54 | # opObj11.addParameter(name='xmax', value='24', format='float') | |
55 |
|
55 | |||
56 | # opObj11.addParameter(name='zmin', value='-110', format='float') |
|
56 | # opObj11.addParameter(name='zmin', value='-110', format='float') | |
57 | # opObj11.addParameter(name='zmax', value='-70', format='float') |
|
57 | # opObj11.addParameter(name='zmax', value='-70', format='float') | |
58 | # opObj11.addParameter(name='save', value='0', format='int') |
|
58 | # opObj11.addParameter(name='save', value='0', format='int') | |
59 | # # opObj11.addParameter(name='figpath', value='/tmp/', format='str') |
|
59 | # # opObj11.addParameter(name='figpath', value='/tmp/', format='str') | |
60 | # |
|
60 | # | |
61 |
opObj12 = procUnitConfObj |
|
61 | opObj12 = procUnitConfObj3.addOperation(name='PublishData', optype='other') | |
62 | opObj12.addParameter(name='zeromq', value=1, format='int') |
|
62 | opObj12.addParameter(name='zeromq', value=1, format='int') | |
63 |
|
63 | |||
64 |
|
64 | |||
65 | # opObj13 = procUnitConfObj3.addOperation(name='PublishData', optype='other') |
|
65 | # opObj13 = procUnitConfObj3.addOperation(name='PublishData', optype='other') | |
66 | # opObj13.addParameter(name='zeromq', value=1, format='int') |
|
66 | # opObj13.addParameter(name='zeromq', value=1, format='int') | |
67 | # opObj13.addParameter(name='server', value="juanca", format='str') |
|
67 | # opObj13.addParameter(name='server', value="juanca", format='str') | |
68 |
|
68 | |||
69 | opObj12.addParameter(name='delay', value=1, format='int') |
|
69 | opObj12.addParameter(name='delay', value=1, format='int') | |
70 |
|
70 | |||
71 |
|
71 | |||
72 | # print "Escribiendo el archivo XML" |
|
72 | # print "Escribiendo el archivo XML" | |
73 | # controllerObj.writeXml(filename) |
|
73 | # controllerObj.writeXml(filename) | |
74 | # print "Leyendo el archivo XML" |
|
74 | # print "Leyendo el archivo XML" | |
75 | # controllerObj.readXml(filename) |
|
75 | # controllerObj.readXml(filename) | |
76 |
|
76 | |||
77 |
|
77 | |||
78 | # timeit.timeit('controllerObj.run()', number=2) |
|
78 | # timeit.timeit('controllerObj.run()', number=2) | |
79 |
|
79 | |||
80 | controllerObj.start() |
|
80 | controllerObj.start() | |
81 |
|
81 | |||
82 |
|
82 | |||
83 | if __name__ == '__main__': |
|
83 | if __name__ == '__main__': | |
84 | parser = argparse.ArgumentParser(description='Set number of parallel processes') |
|
84 | parser = argparse.ArgumentParser(description='Set number of parallel processes') | |
85 | parser.add_argument('--nProcess', default=1, type=int) |
|
85 | parser.add_argument('--nProcess', default=1, type=int) | |
86 | args = parser.parse_args() |
|
86 | args = parser.parse_args() | |
87 | multiSchain(fiber, nProcess=args.nProcess, startDate='2015/09/26', endDate='2015/09/26') |
|
87 | multiSchain(fiber, nProcess=args.nProcess, startDate='2015/09/26', endDate='2015/09/26') |
@@ -1,50 +1,58 | |||||
1 | #!/usr/bin/env python |
|
1 | #!/usr/bin/env python | |
2 | ''' |
|
2 | ''' | |
3 | Created on Jul 7, 2014 |
|
3 | Created on Jul 7, 2014 | |
4 |
|
4 | |||
5 | @author: roj-idl71 |
|
5 | @author: roj-idl71 | |
6 | ''' |
|
6 | ''' | |
7 | import os, sys |
|
7 | import os, sys | |
8 |
|
8 | |||
9 | from schainpy.controller import Project |
|
9 | from schainpy.controller import Project | |
10 |
|
10 | |||
11 | if __name__ == '__main__': |
|
11 | if __name__ == '__main__': | |
12 | desc = "Segundo Test" |
|
12 | desc = "Segundo Test" | |
13 |
|
13 | |||
14 | controllerObj = Project() |
|
14 | controllerObj = Project() | |
15 | controllerObj.setup(id='191', name='test01', description=desc) |
|
15 | controllerObj.setup(id='191', name='test01', description=desc) | |
16 |
|
16 | |||
17 | proc1 = controllerObj.addProcUnit(name='ReceiverData') |
|
17 | proc1 = controllerObj.addProcUnit(name='ReceiverData') | |
18 | proc1.addParameter(name='realtime', value='0', format='bool') |
|
18 | proc1.addParameter(name='realtime', value='0', format='bool') | |
19 | proc1.addParameter(name='plottypes', value='rti', format='str') |
|
19 | proc1.addParameter(name='plottypes', value='rti,coh,phase,snr,dop', format='str') | |
20 |
|
|
20 | proc1.addParameter(name='throttle', value='10', format='int') | |
21 | proc1.addParameter(name='plot_server', value='tcp://10.10.10.82:7000', format='str') |
|
21 | proc1.addParameter(name='plot_server', value='tcp://10.10.10.82:7000', format='str') | |
22 | ## TODO Agregar direccion de server de publicacion a graficos como variable |
|
22 | ## TODO Agregar direccion de server de publicacion a graficos como variable | |
23 |
|
23 | |||
24 | op1 = proc1.addOperation(name='PlotRTIData', optype='other') |
|
24 | op1 = proc1.addOperation(name='PlotRTIData', optype='other') | |
25 | op1.addParameter(name='wintitle', value='Julia 150Km', format='str') |
|
25 | op1.addParameter(name='wintitle', value='Julia 150Km', format='str') | |
26 | op1.addParameter(name='save', value='/home/nanosat/Pictures', format='str') |
|
26 | op1.addParameter(name='save', value='/home/nanosat/Pictures', format='str') | |
|
27 | op1.addParameter(name='show', value='0', format='bool') | |||
|
28 | op1.addParameter(name='colormap', value='jet', format='str') | |||
27 | # |
|
29 | # | |
28 |
|
|
30 | op2 = proc1.addOperation(name='PlotCOHData', optype='other') | |
29 |
|
|
31 | op2.addParameter(name='wintitle', value='Julia 150Km', format='str') | |
30 |
|
|
32 | op2.addParameter(name='save', value='/home/nanosat/Pictures', format='str') | |
|
33 | op2.addParameter(name='colormap', value='jet', format='str') | |||
|
34 | op2.addParameter(name='show', value='0', format='bool') | |||
31 | # # |
|
35 | # # | |
32 |
|
|
36 | op6 = proc1.addOperation(name='PlotPHASEData', optype='other') | |
33 |
|
|
37 | op6.addParameter(name='wintitle', value='Julia 150Km', format='str') | |
34 |
|
|
38 | op6.addParameter(name='save', value='/home/nanosat/Pictures', format='str') | |
|
39 | op6.addParameter(name='show', value='1', format='bool') | |||
35 | # |
|
40 | # | |
36 | # proc2 = controllerObj.addProcUnit(name='ReceiverData') |
|
41 | # proc2 = controllerObj.addProcUnit(name='ReceiverData') | |
37 | # proc2.addParameter(name='server', value='juanca', format='str') |
|
42 | # proc2.addParameter(name='server', value='juanca', format='str') | |
38 | # proc2.addParameter(name='plottypes', value='snr,dop', format='str') |
|
43 | # proc2.addParameter(name='plottypes', value='snr,dop', format='str') | |
39 | # |
|
44 | # | |
40 |
|
|
45 | op3 = proc1.addOperation(name='PlotSNRData', optype='other') | |
41 |
|
|
46 | op3.addParameter(name='wintitle', value='Julia 150Km', format='str') | |
42 |
|
|
47 | op3.addParameter(name='save', value='/home/nanosat/Pictures', format='str') | |
|
48 | op3.addParameter(name='show', value='0', format='bool') | |||
43 | # |
|
49 | # | |
44 |
|
|
50 | op4 = proc1.addOperation(name='PlotDOPData', optype='other') | |
45 |
|
|
51 | op4.addParameter(name='wintitle', value='Julia 150Km', format='str') | |
46 |
|
|
52 | op4.addParameter(name='save', value='/home/nanosat/Pictures', format='str') | |
|
53 | op4.addParameter(name='show', value='0', format='bool') | |||
|
54 | op4.addParameter(name='colormap', value='jet', format='str') | |||
47 |
|
55 | |||
48 |
|
56 | |||
49 |
|
57 | |||
50 | controllerObj.start() |
|
58 | controllerObj.start() |
@@ -1,1 +1,1 | |||||
1 | <Project description="Segundo Test" id="191" name="test01"><ProcUnit datatype="ReceiverData" id="1911" inputId="0" name="ReceiverData"><Operation id="19111" name="run" priority="1" type="self"><Parameter format="bool" id="191111" name="realtime" value="1" /><Parameter format="str" id="191112" name="plottypes" value="rti" /><Parameter format="str" id="191113" name="plot_server" value="tcp://10.10.10.82:7000" /></Operation><Operation id="19112" name="PlotRTIData" priority="2" type="other"><Parameter format="str" id="191121" name="wintitle" value="Julia 150Km" /><Parameter format="str" id="191122" name="save" value="/home/nanosat/Pictures" /></Operation></ProcUnit></Project> No newline at end of file |
|
1 | <Project description="HF_EXAMPLE" id="191" name="test01"><ReadUnit datatype="SpectraReader" id="1911" inputId="0" name="SpectraReader"><Operation id="19111" name="run" priority="1" type="self"><Parameter format="str" id="191111" name="datatype" value="SpectraReader" /><Parameter format="str" id="191112" name="path" value="/home/nanosat/data/hysell_data20/pdata" /><Parameter format="date" id="191113" name="startDate" value="2015/09/26" /><Parameter format="date" id="191114" name="endDate" value="2015/09/26" /><Parameter format="time" id="191115" name="startTime" value="00:00:00" /><Parameter format="time" id="191116" name="endTime" value="23:59:59" /><Parameter format="int" id="191118" name="cursor" value="2" /><Parameter format="int" id="191119" name="skip" value="720" /><Parameter format="int" id="191120" name="delay" value="10" /><Parameter format="int" id="191121" name="walk" value="1" /><Parameter format="int" id="191122" name="online" value="0" /></Operation></ReadUnit><ProcUnit datatype="ParametersProc" id="1913" inputId="1911" name="ParametersProc"><Operation id="19131" name="run" priority="1" type="self" /><Operation id="19132" name="SpectralMoments" priority="2" type="other" /><Operation id="19133" name="PublishData" priority="3" type="other"><Parameter format="int" id="191331" name="zeromq" value="1" /><Parameter format="int" id="191332" name="delay" value="1" /></Operation></ProcUnit><ProcUnit datatype="Spectra" id="1912" inputId="1911" name="SpectraProc"><Operation id="19121" name="run" priority="1" type="self" /></ProcUnit></Project> No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now