@@ -0,0 +1,98 | |||||
|
1 | # Byte-compiled / optimized / DLL files | |||
|
2 | __pycache__/ | |||
|
3 | *.py[cod] | |||
|
4 | *$py.class | |||
|
5 | ||||
|
6 | # C extensions | |||
|
7 | *.so | |||
|
8 | ||||
|
9 | # Distribution / packaging | |||
|
10 | .Python | |||
|
11 | env/ | |||
|
12 | build/ | |||
|
13 | develop-eggs/ | |||
|
14 | dist/ | |||
|
15 | downloads/ | |||
|
16 | eggs/ | |||
|
17 | .eggs/ | |||
|
18 | lib/ | |||
|
19 | lib64/ | |||
|
20 | parts/ | |||
|
21 | sdist/ | |||
|
22 | var/ | |||
|
23 | wheels/ | |||
|
24 | *.egg-info/ | |||
|
25 | .installed.cfg | |||
|
26 | *.egg | |||
|
27 | ||||
|
28 | # PyInstaller | |||
|
29 | # Usually these files are written by a python script from a template | |||
|
30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. | |||
|
31 | *.manifest | |||
|
32 | *.spec | |||
|
33 | ||||
|
34 | # Installer logs | |||
|
35 | pip-log.txt | |||
|
36 | pip-delete-this-directory.txt | |||
|
37 | ||||
|
38 | # Unit test / coverage reports | |||
|
39 | htmlcov/ | |||
|
40 | .tox/ | |||
|
41 | .coverage | |||
|
42 | .coverage.* | |||
|
43 | .cache | |||
|
44 | nosetests.xml | |||
|
45 | coverage.xml | |||
|
46 | *,cover | |||
|
47 | .hypothesis/ | |||
|
48 | ||||
|
49 | # Translations | |||
|
50 | *.mo | |||
|
51 | *.pot | |||
|
52 | ||||
|
53 | # Django stuff: | |||
|
54 | *.log | |||
|
55 | local_settings.py | |||
|
56 | ||||
|
57 | # Flask stuff: | |||
|
58 | instance/ | |||
|
59 | .webassets-cache | |||
|
60 | ||||
|
61 | # Scrapy stuff: | |||
|
62 | .scrapy | |||
|
63 | ||||
|
64 | # Sphinx documentation | |||
|
65 | docs/_build/ | |||
|
66 | ||||
|
67 | # PyBuilder | |||
|
68 | target/ | |||
|
69 | ||||
|
70 | # Jupyter Notebook | |||
|
71 | .ipynb_checkpoints | |||
|
72 | ||||
|
73 | # pyenv | |||
|
74 | .python-version | |||
|
75 | ||||
|
76 | # celery beat schedule file | |||
|
77 | celerybeat-schedule | |||
|
78 | ||||
|
79 | # SageMath parsed files | |||
|
80 | *.sage.py | |||
|
81 | ||||
|
82 | # dotenv | |||
|
83 | .env | |||
|
84 | ||||
|
85 | # virtualenv | |||
|
86 | .venv | |||
|
87 | venv/ | |||
|
88 | ENV/ | |||
|
89 | ||||
|
90 | # Spyder project settings | |||
|
91 | .spyderproject | |||
|
92 | .spyproject | |||
|
93 | ||||
|
94 | # Rope project settings | |||
|
95 | .ropeproject | |||
|
96 | ||||
|
97 | # mkdocs documentation | |||
|
98 | /site |
@@ -0,0 +1,42 | |||||
|
1 | #!/usr/bin/env python | |||
|
2 | ''' | |||
|
3 | Created on Jul 7, 2014 | |||
|
4 | ||||
|
5 | @author: roj-idl71 | |||
|
6 | ''' | |||
|
7 | import os, sys | |||
|
8 | ||||
|
9 | from schainpy.controller import Project | |||
|
10 | ||||
|
11 | if __name__ == '__main__': | |||
|
12 | desc = "Segundo Test" | |||
|
13 | ||||
|
14 | controllerObj = Project() | |||
|
15 | controllerObj.setup(id = '191', name='test01', description=desc) | |||
|
16 | ||||
|
17 | proc1 = controllerObj.addProcUnit(name='ReceiverData') | |||
|
18 | # proc1.addParameter(name='server', value='tcp://10.10.10.87:3000', format='str') | |||
|
19 | proc1.addParameter(name='realtime', value='1', format='bool') | |||
|
20 | proc1.addParameter(name='plottypes', value='rti,spc', format='str') | |||
|
21 | ||||
|
22 | op1 = proc1.addOperation(name='PlotRTIData', optype='other') | |||
|
23 | op1.addParameter(name='wintitle', value='Julia 150Km', format='str') | |||
|
24 | ||||
|
25 | op2 = proc1.addOperation(name='PlotSpectraData', optype='other') | |||
|
26 | op2.addParameter(name='wintitle', value='Julia 150Km', format='str') | |||
|
27 | op2.addParameter(name='xaxis', value='velocity', format='str') | |||
|
28 | op2.addParameter(name='showprofile', value='1', format='bool') | |||
|
29 | #op2.addParameter(name='xmin', value='-0.1', format='float') | |||
|
30 | #op2.addParameter(name='xmax', value='0.1', format='float') | |||
|
31 | ||||
|
32 | # op1 = proc1.addOperation(name='PlotPHASEData', optype='other') | |||
|
33 | # op1.addParameter(name='wintitle', value='Julia 150Km', format='str') | |||
|
34 | ||||
|
35 | ||||
|
36 | # proc1 = controllerObj.addProcUnit(name='ReceiverData') | |||
|
37 | # proc1.addParameter(name='server', value='pipe2', format='str') | |||
|
38 | # proc1.addParameter(name='mode', value='buffer', format='str') | |||
|
39 | # proc1.addParameter(name='plottypes', value='snr', format='str') | |||
|
40 | ||||
|
41 | ||||
|
42 | controllerObj.start() |
This diff has been collapsed as it changes many lines, (903 lines changed) Show them Hide them | |||||
@@ -1,8 +1,8 | |||||
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 | |
@@ -24,95 +24,95 def prettify(elem): | |||||
24 | return reparsed.toprettyxml(indent=" ") |
|
24 | return reparsed.toprettyxml(indent=" ") | |
25 |
|
25 | |||
26 | class ParameterConf(): |
|
26 | class ParameterConf(): | |
27 |
|
27 | |||
28 | id = None |
|
28 | id = None | |
29 | name = None |
|
29 | name = None | |
30 | value = None |
|
30 | value = None | |
31 | format = None |
|
31 | format = None | |
32 |
|
32 | |||
33 | __formated_value = None |
|
33 | __formated_value = None | |
34 |
|
34 | |||
35 | ELEMENTNAME = 'Parameter' |
|
35 | ELEMENTNAME = 'Parameter' | |
36 |
|
36 | |||
37 | def __init__(self): |
|
37 | def __init__(self): | |
38 |
|
38 | |||
39 | self.format = 'str' |
|
39 | self.format = 'str' | |
40 |
|
40 | |||
41 | def getElementName(self): |
|
41 | def getElementName(self): | |
42 |
|
42 | |||
43 | return self.ELEMENTNAME |
|
43 | return self.ELEMENTNAME | |
44 |
|
44 | |||
45 | def getValue(self): |
|
45 | def getValue(self): | |
46 |
|
46 | |||
47 | value = self.value |
|
47 | value = self.value | |
48 | format = self.format |
|
48 | format = self.format | |
49 |
|
49 | |||
50 | if self.__formated_value != None: |
|
50 | if self.__formated_value != None: | |
51 |
|
51 | |||
52 | return self.__formated_value |
|
52 | return self.__formated_value | |
53 |
|
53 | |||
54 | if format == 'str': |
|
54 | if format == 'str': | |
55 | self.__formated_value = str(value) |
|
55 | self.__formated_value = str(value) | |
56 | return self.__formated_value |
|
56 | return self.__formated_value | |
57 |
|
57 | |||
58 | if value == '': |
|
58 | if value == '': | |
59 | raise ValueError, "%s: This parameter value is empty" %self.name |
|
59 | raise ValueError, "%s: This parameter value is empty" %self.name | |
60 |
|
60 | |||
61 | if format == 'list': |
|
61 | if format == 'list': | |
62 | strList = value.split(',') |
|
62 | strList = value.split(',') | |
63 |
|
63 | |||
64 | self.__formated_value = strList |
|
64 | self.__formated_value = strList | |
65 |
|
65 | |||
66 | return self.__formated_value |
|
66 | return self.__formated_value | |
67 |
|
67 | |||
68 | if format == 'intlist': |
|
68 | if format == 'intlist': | |
69 | """ |
|
69 | """ | |
70 | Example: |
|
70 | Example: | |
71 | value = (0,1,2) |
|
71 | value = (0,1,2) | |
72 | """ |
|
72 | """ | |
73 |
|
73 | |||
74 | new_value = ast.literal_eval(value) |
|
74 | new_value = ast.literal_eval(value) | |
75 |
|
75 | |||
76 | if type(new_value) not in (tuple, list): |
|
76 | if type(new_value) not in (tuple, list): | |
77 | new_value = [int(new_value)] |
|
77 | new_value = [int(new_value)] | |
78 |
|
78 | |||
79 | self.__formated_value = new_value |
|
79 | self.__formated_value = new_value | |
80 |
|
80 | |||
81 | return self.__formated_value |
|
81 | return self.__formated_value | |
82 |
|
82 | |||
83 | if format == 'floatlist': |
|
83 | if format == 'floatlist': | |
84 | """ |
|
84 | """ | |
85 | Example: |
|
85 | Example: | |
86 | value = (0.5, 1.4, 2.7) |
|
86 | value = (0.5, 1.4, 2.7) | |
87 | """ |
|
87 | """ | |
88 |
|
88 | |||
89 | new_value = ast.literal_eval(value) |
|
89 | new_value = ast.literal_eval(value) | |
90 |
|
90 | |||
91 | if type(new_value) not in (tuple, list): |
|
91 | if type(new_value) not in (tuple, list): | |
92 | new_value = [float(new_value)] |
|
92 | new_value = [float(new_value)] | |
93 |
|
93 | |||
94 | self.__formated_value = new_value |
|
94 | self.__formated_value = new_value | |
95 |
|
95 | |||
96 | return self.__formated_value |
|
96 | return self.__formated_value | |
97 |
|
97 | |||
98 | if format == 'date': |
|
98 | if format == 'date': | |
99 | strList = value.split('/') |
|
99 | strList = value.split('/') | |
100 | intList = [int(x) for x in strList] |
|
100 | intList = [int(x) for x in strList] | |
101 | date = datetime.date(intList[0], intList[1], intList[2]) |
|
101 | date = datetime.date(intList[0], intList[1], intList[2]) | |
102 |
|
102 | |||
103 | self.__formated_value = date |
|
103 | self.__formated_value = date | |
104 |
|
104 | |||
105 | return self.__formated_value |
|
105 | return self.__formated_value | |
106 |
|
106 | |||
107 | if format == 'time': |
|
107 | if format == 'time': | |
108 | strList = value.split(':') |
|
108 | strList = value.split(':') | |
109 | intList = [int(x) for x in strList] |
|
109 | intList = [int(x) for x in strList] | |
110 | time = datetime.time(intList[0], intList[1], intList[2]) |
|
110 | time = datetime.time(intList[0], intList[1], intList[2]) | |
111 |
|
111 | |||
112 | self.__formated_value = time |
|
112 | self.__formated_value = time | |
113 |
|
113 | |||
114 | return self.__formated_value |
|
114 | return self.__formated_value | |
115 |
|
115 | |||
116 | if format == 'pairslist': |
|
116 | if format == 'pairslist': | |
117 | """ |
|
117 | """ | |
118 | Example: |
|
118 | Example: | |
@@ -120,605 +120,629 class ParameterConf(): | |||||
120 | """ |
|
120 | """ | |
121 |
|
121 | |||
122 | new_value = ast.literal_eval(value) |
|
122 | new_value = ast.literal_eval(value) | |
123 |
|
123 | |||
124 | if type(new_value) not in (tuple, list): |
|
124 | if type(new_value) not in (tuple, list): | |
125 | raise ValueError, "%s has to be a tuple or list of pairs" %value |
|
125 | raise ValueError, "%s has to be a tuple or list of pairs" %value | |
126 |
|
126 | |||
127 | if type(new_value[0]) not in (tuple, list): |
|
127 | if type(new_value[0]) not in (tuple, list): | |
128 | if len(new_value) != 2: |
|
128 | if len(new_value) != 2: | |
129 | raise ValueError, "%s has to be a tuple or list of pairs" %value |
|
129 | raise ValueError, "%s has to be a tuple or list of pairs" %value | |
130 | new_value = [new_value] |
|
130 | new_value = [new_value] | |
131 |
|
131 | |||
132 | for thisPair in new_value: |
|
132 | for thisPair in new_value: | |
133 | if len(thisPair) != 2: |
|
133 | if len(thisPair) != 2: | |
134 | raise ValueError, "%s has to be a tuple or list of pairs" %value |
|
134 | raise ValueError, "%s has to be a tuple or list of pairs" %value | |
135 |
|
135 | |||
136 | self.__formated_value = new_value |
|
136 | self.__formated_value = new_value | |
137 |
|
137 | |||
138 | return self.__formated_value |
|
138 | return self.__formated_value | |
139 |
|
139 | |||
140 | if format == 'multilist': |
|
140 | if format == 'multilist': | |
141 | """ |
|
141 | """ | |
142 | Example: |
|
142 | Example: | |
143 | value = (0,1,2),(3,4,5) |
|
143 | value = (0,1,2),(3,4,5) | |
144 | """ |
|
144 | """ | |
145 | multiList = ast.literal_eval(value) |
|
145 | multiList = ast.literal_eval(value) | |
146 |
|
146 | |||
147 | if type(multiList[0]) == int: |
|
147 | if type(multiList[0]) == int: | |
148 | multiList = ast.literal_eval("(" + value + ")") |
|
148 | multiList = ast.literal_eval("(" + value + ")") | |
149 |
|
149 | |||
150 | self.__formated_value = multiList |
|
150 | self.__formated_value = multiList | |
151 |
|
151 | |||
152 | return self.__formated_value |
|
152 | return self.__formated_value | |
153 |
|
153 | |||
154 | if format == 'bool': |
|
154 | if format == 'bool': | |
155 | value = int(value) |
|
155 | value = int(value) | |
156 |
|
156 | |||
157 | if format == 'int': |
|
157 | if format == 'int': | |
158 | value = float(value) |
|
158 | value = float(value) | |
159 |
|
159 | |||
160 | format_func = eval(format) |
|
160 | format_func = eval(format) | |
161 |
|
161 | |||
162 | self.__formated_value = format_func(value) |
|
162 | self.__formated_value = format_func(value) | |
163 |
|
163 | |||
164 | return self.__formated_value |
|
164 | return self.__formated_value | |
165 |
|
165 | |||
166 | def updateId(self, new_id): |
|
166 | def updateId(self, new_id): | |
167 |
|
167 | |||
168 | self.id = str(new_id) |
|
168 | self.id = str(new_id) | |
169 |
|
169 | |||
170 | def setup(self, id, name, value, format='str'): |
|
170 | def setup(self, id, name, value, format='str'): | |
171 |
|
171 | |||
172 | self.id = str(id) |
|
172 | self.id = str(id) | |
173 | self.name = name |
|
173 | self.name = name | |
174 | self.value = str(value) |
|
174 | self.value = str(value) | |
175 | self.format = str.lower(format) |
|
175 | self.format = str.lower(format) | |
176 |
|
176 | |||
177 | self.getValue() |
|
177 | self.getValue() | |
178 |
|
178 | |||
179 | return 1 |
|
179 | return 1 | |
180 |
|
180 | |||
181 | def update(self, name, value, format='str'): |
|
181 | def update(self, name, value, format='str'): | |
182 |
|
182 | |||
183 | self.name = name |
|
183 | self.name = name | |
184 | self.value = str(value) |
|
184 | self.value = str(value) | |
185 | self.format = format |
|
185 | self.format = format | |
186 |
|
186 | |||
187 | def makeXml(self, opElement): |
|
187 | def makeXml(self, opElement): | |
188 |
|
188 | |||
189 | parmElement = SubElement(opElement, self.ELEMENTNAME) |
|
189 | parmElement = SubElement(opElement, self.ELEMENTNAME) | |
190 | parmElement.set('id', str(self.id)) |
|
190 | parmElement.set('id', str(self.id)) | |
191 | parmElement.set('name', self.name) |
|
191 | parmElement.set('name', self.name) | |
192 | parmElement.set('value', self.value) |
|
192 | parmElement.set('value', self.value) | |
193 | parmElement.set('format', self.format) |
|
193 | parmElement.set('format', self.format) | |
194 |
|
194 | |||
195 | def readXml(self, parmElement): |
|
195 | def readXml(self, parmElement): | |
196 |
|
196 | |||
197 | self.id = parmElement.get('id') |
|
197 | self.id = parmElement.get('id') | |
198 | self.name = parmElement.get('name') |
|
198 | self.name = parmElement.get('name') | |
199 | self.value = parmElement.get('value') |
|
199 | self.value = parmElement.get('value') | |
200 | self.format = str.lower(parmElement.get('format')) |
|
200 | self.format = str.lower(parmElement.get('format')) | |
201 |
|
201 | |||
202 | #Compatible with old signal chain version |
|
202 | #Compatible with old signal chain version | |
203 | if self.format == 'int' and self.name == 'idfigure': |
|
203 | if self.format == 'int' and self.name == 'idfigure': | |
204 | self.name = 'id' |
|
204 | self.name = 'id' | |
205 |
|
205 | |||
206 | def printattr(self): |
|
206 | def printattr(self): | |
207 |
|
207 | |||
208 | print "Parameter[%s]: name = %s, value = %s, format = %s" %(self.id, self.name, self.value, self.format) |
|
208 | print "Parameter[%s]: name = %s, value = %s, format = %s" %(self.id, self.name, self.value, self.format) | |
209 |
|
209 | |||
210 | class OperationConf(): |
|
210 | class OperationConf(): | |
211 |
|
211 | |||
212 | id = None |
|
212 | id = None | |
213 | name = None |
|
213 | name = None | |
214 | priority = None |
|
214 | priority = None | |
215 | type = None |
|
215 | type = None | |
216 |
|
216 | |||
217 | parmConfObjList = [] |
|
217 | parmConfObjList = [] | |
218 |
|
218 | |||
219 | ELEMENTNAME = 'Operation' |
|
219 | ELEMENTNAME = 'Operation' | |
220 |
|
220 | |||
221 | def __init__(self): |
|
221 | def __init__(self): | |
222 |
|
222 | |||
223 | self.id = '0' |
|
223 | self.id = '0' | |
224 | self.name = None |
|
224 | self.name = None | |
225 | self.priority = None |
|
225 | self.priority = None | |
226 | self.type = 'self' |
|
226 | self.type = 'self' | |
227 |
|
227 | |||
228 |
|
228 | |||
229 | def __getNewId(self): |
|
229 | def __getNewId(self): | |
230 |
|
230 | |||
231 | return int(self.id)*10 + len(self.parmConfObjList) + 1 |
|
231 | return int(self.id)*10 + len(self.parmConfObjList) + 1 | |
232 |
|
232 | |||
233 | def updateId(self, new_id): |
|
233 | def updateId(self, new_id): | |
234 |
|
234 | |||
235 | self.id = str(new_id) |
|
235 | self.id = str(new_id) | |
236 |
|
236 | |||
237 | n = 1 |
|
237 | n = 1 | |
238 | for parmObj in self.parmConfObjList: |
|
238 | for parmObj in self.parmConfObjList: | |
239 |
|
239 | |||
240 | idParm = str(int(new_id)*10 + n) |
|
240 | idParm = str(int(new_id)*10 + n) | |
241 | parmObj.updateId(idParm) |
|
241 | parmObj.updateId(idParm) | |
242 |
|
242 | |||
243 | n += 1 |
|
243 | n += 1 | |
244 |
|
244 | |||
245 | def getElementName(self): |
|
245 | def getElementName(self): | |
246 |
|
246 | |||
247 | return self.ELEMENTNAME |
|
247 | return self.ELEMENTNAME | |
248 |
|
248 | |||
249 | def getParameterObjList(self): |
|
249 | def getParameterObjList(self): | |
250 |
|
250 | |||
251 | return self.parmConfObjList |
|
251 | return self.parmConfObjList | |
252 |
|
252 | |||
253 | def getParameterObj(self, parameterName): |
|
253 | def getParameterObj(self, parameterName): | |
254 |
|
254 | |||
255 | for parmConfObj in self.parmConfObjList: |
|
255 | for parmConfObj in self.parmConfObjList: | |
256 |
|
256 | |||
257 | if parmConfObj.name != parameterName: |
|
257 | if parmConfObj.name != parameterName: | |
258 | continue |
|
258 | continue | |
259 |
|
259 | |||
260 | return parmConfObj |
|
260 | return parmConfObj | |
261 |
|
261 | |||
262 | return None |
|
262 | return None | |
263 |
|
263 | |||
264 | def getParameterObjfromValue(self, parameterValue): |
|
264 | def getParameterObjfromValue(self, parameterValue): | |
265 |
|
265 | |||
266 | for parmConfObj in self.parmConfObjList: |
|
266 | for parmConfObj in self.parmConfObjList: | |
267 |
|
267 | |||
268 | if parmConfObj.getValue() != parameterValue: |
|
268 | if parmConfObj.getValue() != parameterValue: | |
269 | continue |
|
269 | continue | |
270 |
|
270 | |||
271 | return parmConfObj.getValue() |
|
271 | return parmConfObj.getValue() | |
272 |
|
272 | |||
273 | return None |
|
273 | return None | |
274 |
|
274 | |||
275 | def getParameterValue(self, parameterName): |
|
275 | def getParameterValue(self, parameterName): | |
276 |
|
276 | |||
277 | parameterObj = self.getParameterObj(parameterName) |
|
277 | parameterObj = self.getParameterObj(parameterName) | |
278 |
|
278 | |||
279 | # if not parameterObj: |
|
279 | # if not parameterObj: | |
280 | # return None |
|
280 | # return None | |
281 |
|
281 | |||
282 | value = parameterObj.getValue() |
|
282 | value = parameterObj.getValue() | |
283 |
|
283 | |||
284 | return value |
|
284 | return value | |
285 |
|
285 | |||
|
286 | ||||
|
287 | def getKwargs(self): | |||
|
288 | ||||
|
289 | kwargs = {} | |||
|
290 | ||||
|
291 | for parmConfObj in self.parmConfObjList: | |||
|
292 | if self.name == 'run' and parmConfObj.name == 'datatype': | |||
|
293 | continue | |||
|
294 | ||||
|
295 | kwargs[parmConfObj.name] = parmConfObj.getValue() | |||
|
296 | ||||
|
297 | return kwargs | |||
|
298 | ||||
286 | def setup(self, id, name, priority, type): |
|
299 | def setup(self, id, name, priority, type): | |
287 |
|
300 | |||
288 | self.id = str(id) |
|
301 | self.id = str(id) | |
289 | self.name = name |
|
302 | self.name = name | |
290 | self.type = type |
|
303 | self.type = type | |
291 | self.priority = priority |
|
304 | self.priority = priority | |
292 |
|
305 | |||
293 | self.parmConfObjList = [] |
|
306 | self.parmConfObjList = [] | |
294 |
|
307 | |||
295 | def removeParameters(self): |
|
308 | def removeParameters(self): | |
296 |
|
309 | |||
297 | for obj in self.parmConfObjList: |
|
310 | for obj in self.parmConfObjList: | |
298 | del obj |
|
311 | del obj | |
299 |
|
312 | |||
300 | self.parmConfObjList = [] |
|
313 | self.parmConfObjList = [] | |
301 |
|
314 | |||
302 | def addParameter(self, name, value, format='str'): |
|
315 | def addParameter(self, name, value, format='str'): | |
303 |
|
316 | |||
304 | id = self.__getNewId() |
|
317 | id = self.__getNewId() | |
305 |
|
318 | |||
306 | parmConfObj = ParameterConf() |
|
319 | parmConfObj = ParameterConf() | |
307 | if not parmConfObj.setup(id, name, value, format): |
|
320 | if not parmConfObj.setup(id, name, value, format): | |
308 | return None |
|
321 | return None | |
309 |
|
322 | |||
310 | self.parmConfObjList.append(parmConfObj) |
|
323 | self.parmConfObjList.append(parmConfObj) | |
311 |
|
324 | |||
312 | return parmConfObj |
|
325 | return parmConfObj | |
313 |
|
326 | |||
314 | def changeParameter(self, name, value, format='str'): |
|
327 | def changeParameter(self, name, value, format='str'): | |
315 |
|
328 | |||
316 | parmConfObj = self.getParameterObj(name) |
|
329 | parmConfObj = self.getParameterObj(name) | |
317 | parmConfObj.update(name, value, format) |
|
330 | parmConfObj.update(name, value, format) | |
318 |
|
331 | |||
319 | return parmConfObj |
|
332 | return parmConfObj | |
320 |
|
333 | |||
321 | def makeXml(self, procUnitElement): |
|
334 | def makeXml(self, procUnitElement): | |
322 |
|
335 | |||
323 | opElement = SubElement(procUnitElement, self.ELEMENTNAME) |
|
336 | opElement = SubElement(procUnitElement, self.ELEMENTNAME) | |
324 | opElement.set('id', str(self.id)) |
|
337 | opElement.set('id', str(self.id)) | |
325 | opElement.set('name', self.name) |
|
338 | opElement.set('name', self.name) | |
326 | opElement.set('type', self.type) |
|
339 | opElement.set('type', self.type) | |
327 | opElement.set('priority', str(self.priority)) |
|
340 | opElement.set('priority', str(self.priority)) | |
328 |
|
341 | |||
329 | for parmConfObj in self.parmConfObjList: |
|
342 | for parmConfObj in self.parmConfObjList: | |
330 | parmConfObj.makeXml(opElement) |
|
343 | parmConfObj.makeXml(opElement) | |
331 |
|
344 | |||
332 | def readXml(self, opElement): |
|
345 | def readXml(self, opElement): | |
333 |
|
346 | |||
334 | self.id = opElement.get('id') |
|
347 | self.id = opElement.get('id') | |
335 | self.name = opElement.get('name') |
|
348 | self.name = opElement.get('name') | |
336 | self.type = opElement.get('type') |
|
349 | self.type = opElement.get('type') | |
337 | self.priority = opElement.get('priority') |
|
350 | self.priority = opElement.get('priority') | |
338 |
|
351 | |||
339 | #Compatible with old signal chain version |
|
352 | #Compatible with old signal chain version | |
340 | #Use of 'run' method instead 'init' |
|
353 | #Use of 'run' method instead 'init' | |
341 | if self.type == 'self' and self.name == 'init': |
|
354 | if self.type == 'self' and self.name == 'init': | |
342 | self.name = 'run' |
|
355 | self.name = 'run' | |
343 |
|
356 | |||
344 | self.parmConfObjList = [] |
|
357 | self.parmConfObjList = [] | |
345 |
|
358 | |||
346 | parmElementList = opElement.iter(ParameterConf().getElementName()) |
|
359 | parmElementList = opElement.iter(ParameterConf().getElementName()) | |
347 |
|
360 | |||
348 | for parmElement in parmElementList: |
|
361 | for parmElement in parmElementList: | |
349 | parmConfObj = ParameterConf() |
|
362 | parmConfObj = ParameterConf() | |
350 | parmConfObj.readXml(parmElement) |
|
363 | parmConfObj.readXml(parmElement) | |
351 |
|
364 | |||
352 | #Compatible with old signal chain version |
|
365 | #Compatible with old signal chain version | |
353 | #If an 'plot' OPERATION is found, changes name operation by the value of its type PARAMETER |
|
366 | #If an 'plot' OPERATION is found, changes name operation by the value of its type PARAMETER | |
354 | if self.type != 'self' and self.name == 'Plot': |
|
367 | if self.type != 'self' and self.name == 'Plot': | |
355 | if parmConfObj.format == 'str' and parmConfObj.name == 'type': |
|
368 | if parmConfObj.format == 'str' and parmConfObj.name == 'type': | |
356 | self.name = parmConfObj.value |
|
369 | self.name = parmConfObj.value | |
357 | continue |
|
370 | continue | |
358 |
|
371 | |||
359 | self.parmConfObjList.append(parmConfObj) |
|
372 | self.parmConfObjList.append(parmConfObj) | |
360 |
|
373 | |||
361 | def printattr(self): |
|
374 | def printattr(self): | |
362 |
|
375 | |||
363 | print "%s[%s]: name = %s, type = %s, priority = %s" %(self.ELEMENTNAME, |
|
376 | print "%s[%s]: name = %s, type = %s, priority = %s" %(self.ELEMENTNAME, | |
364 | self.id, |
|
377 | self.id, | |
365 | self.name, |
|
378 | self.name, | |
366 | self.type, |
|
379 | self.type, | |
367 | self.priority) |
|
380 | self.priority) | |
368 |
|
381 | |||
369 | for parmConfObj in self.parmConfObjList: |
|
382 | for parmConfObj in self.parmConfObjList: | |
370 | parmConfObj.printattr() |
|
383 | parmConfObj.printattr() | |
371 |
|
384 | |||
372 | def createObject(self, plotter_queue=None): |
|
385 | def createObject(self, plotter_queue=None): | |
373 |
|
386 | |||
374 | if self.type == 'self': |
|
387 | if self.type == 'self': | |
375 | raise ValueError, "This operation type cannot be created" |
|
388 | raise ValueError, "This operation type cannot be created" | |
376 |
|
389 | |||
377 | if self.type == 'plotter': |
|
390 | if self.type == 'plotter': | |
378 | #Plotter(plotter_name) |
|
391 | #Plotter(plotter_name) | |
379 | if not plotter_queue: |
|
392 | if not plotter_queue: | |
380 | raise ValueError, "plotter_queue is not defined. Use:\nmyProject = Project()\nmyProject.setPlotterQueue(plotter_queue)" |
|
393 | raise ValueError, "plotter_queue is not defined. Use:\nmyProject = Project()\nmyProject.setPlotterQueue(plotter_queue)" | |
381 |
|
394 | |||
382 | opObj = Plotter(self.name, plotter_queue) |
|
395 | opObj = Plotter(self.name, plotter_queue) | |
383 |
|
396 | |||
384 | if self.type == 'external' or self.type == 'other': |
|
397 | if self.type == 'external' or self.type == 'other': | |
385 | className = eval(self.name) |
|
398 | className = eval(self.name) | |
386 | opObj = className() |
|
399 | kwargs = self.getKwargs() | |
387 |
|
400 | opObj = className(**kwargs) | ||
|
401 | ||||
388 | return opObj |
|
402 | return opObj | |
389 |
|
403 | |||
|
404 | ||||
390 | class ProcUnitConf(): |
|
405 | class ProcUnitConf(): | |
391 |
|
406 | |||
392 | id = None |
|
407 | id = None | |
393 | name = None |
|
408 | name = None | |
394 | datatype = None |
|
409 | datatype = None | |
395 | inputId = None |
|
410 | inputId = None | |
396 | parentId = None |
|
411 | parentId = None | |
397 |
|
412 | |||
398 | opConfObjList = [] |
|
413 | opConfObjList = [] | |
399 |
|
414 | |||
400 | procUnitObj = None |
|
415 | procUnitObj = None | |
401 | opObjList = [] |
|
416 | opObjList = [] | |
402 |
|
417 | |||
403 | ELEMENTNAME = 'ProcUnit' |
|
418 | ELEMENTNAME = 'ProcUnit' | |
404 |
|
419 | |||
405 | def __init__(self): |
|
420 | def __init__(self): | |
406 |
|
421 | |||
407 | self.id = None |
|
422 | self.id = None | |
408 | self.datatype = None |
|
423 | self.datatype = None | |
409 | self.name = None |
|
424 | self.name = None | |
410 | self.inputId = None |
|
425 | self.inputId = None | |
411 |
|
426 | |||
412 | self.opConfObjList = [] |
|
427 | self.opConfObjList = [] | |
413 |
|
428 | |||
414 | self.procUnitObj = None |
|
429 | self.procUnitObj = None | |
415 | self.opObjDict = {} |
|
430 | self.opObjDict = {} | |
416 |
|
431 | |||
417 | def __getPriority(self): |
|
432 | def __getPriority(self): | |
418 |
|
433 | |||
419 | return len(self.opConfObjList)+1 |
|
434 | return len(self.opConfObjList)+1 | |
420 |
|
435 | |||
421 | def __getNewId(self): |
|
436 | def __getNewId(self): | |
422 |
|
437 | |||
423 | return int(self.id)*10 + len(self.opConfObjList) + 1 |
|
438 | return int(self.id)*10 + len(self.opConfObjList) + 1 | |
424 |
|
439 | |||
425 | def getElementName(self): |
|
440 | def getElementName(self): | |
426 |
|
441 | |||
427 | return self.ELEMENTNAME |
|
442 | return self.ELEMENTNAME | |
428 |
|
443 | |||
429 | def getId(self): |
|
444 | def getId(self): | |
430 |
|
445 | |||
431 | return self.id |
|
446 | return self.id | |
432 |
|
447 | |||
433 | def updateId(self, new_id, parentId=parentId): |
|
448 | def updateId(self, new_id, parentId=parentId): | |
434 |
|
449 | |||
435 |
|
450 | |||
436 | new_id = int(parentId)*10 + (int(self.id) % 10) |
|
451 | new_id = int(parentId)*10 + (int(self.id) % 10) | |
437 | new_inputId = int(parentId)*10 + (int(self.inputId) % 10) |
|
452 | new_inputId = int(parentId)*10 + (int(self.inputId) % 10) | |
438 |
|
453 | |||
439 | #If this proc unit has not inputs |
|
454 | #If this proc unit has not inputs | |
440 | if self.inputId == '0': |
|
455 | if self.inputId == '0': | |
441 | new_inputId = 0 |
|
456 | new_inputId = 0 | |
442 |
|
457 | |||
443 | n = 1 |
|
458 | n = 1 | |
444 | for opConfObj in self.opConfObjList: |
|
459 | for opConfObj in self.opConfObjList: | |
445 |
|
460 | |||
446 | idOp = str(int(new_id)*10 + n) |
|
461 | idOp = str(int(new_id)*10 + n) | |
447 | opConfObj.updateId(idOp) |
|
462 | opConfObj.updateId(idOp) | |
448 |
|
463 | |||
449 | n += 1 |
|
464 | n += 1 | |
450 |
|
465 | |||
451 | self.parentId = str(parentId) |
|
466 | self.parentId = str(parentId) | |
452 | self.id = str(new_id) |
|
467 | self.id = str(new_id) | |
453 | self.inputId = str(new_inputId) |
|
468 | self.inputId = str(new_inputId) | |
454 |
|
469 | |||
455 |
|
470 | |||
456 | def getInputId(self): |
|
471 | def getInputId(self): | |
457 |
|
472 | |||
458 | return self.inputId |
|
473 | return self.inputId | |
459 |
|
474 | |||
460 | def getOperationObjList(self): |
|
475 | def getOperationObjList(self): | |
461 |
|
476 | |||
462 | return self.opConfObjList |
|
477 | return self.opConfObjList | |
463 |
|
478 | |||
464 | def getOperationObj(self, name=None): |
|
479 | def getOperationObj(self, name=None): | |
465 |
|
480 | |||
466 | for opConfObj in self.opConfObjList: |
|
481 | for opConfObj in self.opConfObjList: | |
467 |
|
482 | |||
468 | if opConfObj.name != name: |
|
483 | if opConfObj.name != name: | |
469 | continue |
|
484 | continue | |
470 |
|
485 | |||
471 | return opConfObj |
|
486 | return opConfObj | |
472 |
|
487 | |||
473 | return None |
|
488 | return None | |
474 |
|
489 | |||
475 | def getOpObjfromParamValue(self, value=None): |
|
490 | def getOpObjfromParamValue(self, value=None): | |
476 |
|
491 | |||
477 | for opConfObj in self.opConfObjList: |
|
492 | for opConfObj in self.opConfObjList: | |
478 | if opConfObj.getParameterObjfromValue(parameterValue=value) != value: |
|
493 | if opConfObj.getParameterObjfromValue(parameterValue=value) != value: | |
479 | continue |
|
494 | continue | |
480 | return opConfObj |
|
495 | return opConfObj | |
481 | return None |
|
496 | return None | |
482 |
|
497 | |||
483 | def getProcUnitObj(self): |
|
498 | def getProcUnitObj(self): | |
484 |
|
499 | |||
485 | return self.procUnitObj |
|
500 | return self.procUnitObj | |
486 |
|
501 | |||
487 | def setup(self, id, name, datatype, inputId, parentId=None): |
|
502 | def setup(self, id, name, datatype, inputId, parentId=None): | |
488 |
|
503 | |||
489 | #Compatible with old signal chain version |
|
504 | #Compatible with old signal chain version | |
490 | if datatype==None and name==None: |
|
505 | if datatype==None and name==None: | |
491 | raise ValueError, "datatype or name should be defined" |
|
506 | raise ValueError, "datatype or name should be defined" | |
492 |
|
507 | |||
493 | if name==None: |
|
508 | if name==None: | |
494 | if 'Proc' in datatype: |
|
509 | if 'Proc' in datatype: | |
495 | name = datatype |
|
510 | name = datatype | |
496 | else: |
|
511 | else: | |
497 | name = '%sProc' %(datatype) |
|
512 | name = '%sProc' %(datatype) | |
498 |
|
513 | |||
499 | if datatype==None: |
|
514 | if datatype==None: | |
500 | datatype = name.replace('Proc','') |
|
515 | datatype = name.replace('Proc','') | |
501 |
|
516 | |||
502 | self.id = str(id) |
|
517 | self.id = str(id) | |
503 | self.name = name |
|
518 | self.name = name | |
504 | self.datatype = datatype |
|
519 | self.datatype = datatype | |
505 | self.inputId = inputId |
|
520 | self.inputId = inputId | |
506 | self.parentId = parentId |
|
521 | self.parentId = parentId | |
507 |
|
522 | |||
508 | self.opConfObjList = [] |
|
523 | self.opConfObjList = [] | |
509 |
|
524 | |||
510 | self.addOperation(name='run', optype='self') |
|
525 | self.addOperation(name='run', optype='self') | |
511 |
|
526 | |||
512 | def removeOperations(self): |
|
527 | def removeOperations(self): | |
513 |
|
528 | |||
514 | for obj in self.opConfObjList: |
|
529 | for obj in self.opConfObjList: | |
515 | del obj |
|
530 | del obj | |
516 |
|
531 | |||
517 | self.opConfObjList = [] |
|
532 | self.opConfObjList = [] | |
518 | self.addOperation(name='run') |
|
533 | self.addOperation(name='run') | |
519 |
|
534 | |||
520 | def addParameter(self, **kwargs): |
|
535 | def addParameter(self, **kwargs): | |
521 | ''' |
|
536 | ''' | |
522 | Add parameters to "run" operation |
|
537 | Add parameters to "run" operation | |
523 | ''' |
|
538 | ''' | |
524 | opObj = self.opConfObjList[0] |
|
539 | opObj = self.opConfObjList[0] | |
525 |
|
540 | |||
526 | opObj.addParameter(**kwargs) |
|
541 | opObj.addParameter(**kwargs) | |
527 |
|
542 | |||
528 | return opObj |
|
543 | return opObj | |
529 |
|
544 | |||
530 | def addOperation(self, name, optype='self'): |
|
545 | def addOperation(self, name, optype='self'): | |
531 |
|
546 | |||
532 | id = self.__getNewId() |
|
547 | id = self.__getNewId() | |
533 |
priority = self.__getPriority() |
|
548 | priority = self.__getPriority() | |
534 |
|
549 | |||
535 | opConfObj = OperationConf() |
|
550 | opConfObj = OperationConf() | |
536 | opConfObj.setup(id, name=name, priority=priority, type=optype) |
|
551 | opConfObj.setup(id, name=name, priority=priority, type=optype) | |
537 |
|
552 | |||
538 | self.opConfObjList.append(opConfObj) |
|
553 | self.opConfObjList.append(opConfObj) | |
539 |
|
554 | |||
540 | return opConfObj |
|
555 | return opConfObj | |
541 |
|
556 | |||
542 | def makeXml(self, projectElement): |
|
557 | def makeXml(self, projectElement): | |
543 |
|
558 | |||
544 | procUnitElement = SubElement(projectElement, self.ELEMENTNAME) |
|
559 | procUnitElement = SubElement(projectElement, self.ELEMENTNAME) | |
545 | procUnitElement.set('id', str(self.id)) |
|
560 | procUnitElement.set('id', str(self.id)) | |
546 | procUnitElement.set('name', self.name) |
|
561 | procUnitElement.set('name', self.name) | |
547 | procUnitElement.set('datatype', self.datatype) |
|
562 | procUnitElement.set('datatype', self.datatype) | |
548 | procUnitElement.set('inputId', str(self.inputId)) |
|
563 | procUnitElement.set('inputId', str(self.inputId)) | |
549 |
|
564 | |||
550 | for opConfObj in self.opConfObjList: |
|
565 | for opConfObj in self.opConfObjList: | |
551 | opConfObj.makeXml(procUnitElement) |
|
566 | opConfObj.makeXml(procUnitElement) | |
552 |
|
567 | |||
553 | def readXml(self, upElement): |
|
568 | def readXml(self, upElement): | |
554 |
|
569 | |||
555 | self.id = upElement.get('id') |
|
570 | self.id = upElement.get('id') | |
556 | self.name = upElement.get('name') |
|
571 | self.name = upElement.get('name') | |
557 | self.datatype = upElement.get('datatype') |
|
572 | self.datatype = upElement.get('datatype') | |
558 | self.inputId = upElement.get('inputId') |
|
573 | self.inputId = upElement.get('inputId') | |
559 |
|
574 | |||
560 | if self.ELEMENTNAME == "ReadUnit": |
|
575 | if self.ELEMENTNAME == "ReadUnit": | |
561 | self.datatype = self.datatype.replace("Reader", "") |
|
576 | self.datatype = self.datatype.replace("Reader", "") | |
562 |
|
577 | |||
563 | if self.ELEMENTNAME == "ProcUnit": |
|
578 | if self.ELEMENTNAME == "ProcUnit": | |
564 | self.datatype = self.datatype.replace("Proc", "") |
|
579 | self.datatype = self.datatype.replace("Proc", "") | |
565 |
|
580 | |||
566 | if self.inputId == 'None': |
|
581 | if self.inputId == 'None': | |
567 | self.inputId = '0' |
|
582 | self.inputId = '0' | |
568 |
|
583 | |||
569 | self.opConfObjList = [] |
|
584 | self.opConfObjList = [] | |
570 |
|
585 | |||
571 | opElementList = upElement.iter(OperationConf().getElementName()) |
|
586 | opElementList = upElement.iter(OperationConf().getElementName()) | |
572 |
|
587 | |||
573 | for opElement in opElementList: |
|
588 | for opElement in opElementList: | |
574 | opConfObj = OperationConf() |
|
589 | opConfObj = OperationConf() | |
575 | opConfObj.readXml(opElement) |
|
590 | opConfObj.readXml(opElement) | |
576 | self.opConfObjList.append(opConfObj) |
|
591 | self.opConfObjList.append(opConfObj) | |
577 |
|
592 | |||
578 | def printattr(self): |
|
593 | def printattr(self): | |
579 |
|
594 | |||
580 | print "%s[%s]: name = %s, datatype = %s, inputId = %s" %(self.ELEMENTNAME, |
|
595 | print "%s[%s]: name = %s, datatype = %s, inputId = %s" %(self.ELEMENTNAME, | |
581 | self.id, |
|
596 | self.id, | |
582 | self.name, |
|
597 | self.name, | |
583 | self.datatype, |
|
598 | self.datatype, | |
584 | self.inputId) |
|
599 | self.inputId) | |
585 |
|
600 | |||
586 | for opConfObj in self.opConfObjList: |
|
601 | for opConfObj in self.opConfObjList: | |
587 | opConfObj.printattr() |
|
602 | opConfObj.printattr() | |
588 |
|
603 | |||
|
604 | ||||
|
605 | def getKwargs(self): | |||
|
606 | ||||
|
607 | opObj = self.opConfObjList[0] | |||
|
608 | kwargs = opObj.getKwargs() | |||
|
609 | ||||
|
610 | return kwargs | |||
|
611 | ||||
589 | def createObjects(self, plotter_queue=None): |
|
612 | def createObjects(self, plotter_queue=None): | |
590 |
|
613 | |||
591 | className = eval(self.name) |
|
614 | className = eval(self.name) | |
592 | procUnitObj = className() |
|
615 | kwargs = self.getKwargs() | |
593 |
|
616 | procUnitObj = className(**kwargs) | ||
|
617 | ||||
594 | for opConfObj in self.opConfObjList: |
|
618 | for opConfObj in self.opConfObjList: | |
595 |
|
619 | |||
596 | if opConfObj.type == 'self': |
|
620 | if opConfObj.type == 'self': | |
597 | continue |
|
621 | continue | |
598 |
|
622 | |||
599 | opObj = opConfObj.createObject(plotter_queue) |
|
623 | opObj = opConfObj.createObject(plotter_queue) | |
600 |
|
624 | |||
601 | self.opObjDict[opConfObj.id] = opObj |
|
625 | self.opObjDict[opConfObj.id] = opObj | |
602 | procUnitObj.addOperation(opObj, opConfObj.id) |
|
626 | procUnitObj.addOperation(opObj, opConfObj.id) | |
603 |
|
627 | |||
604 | self.procUnitObj = procUnitObj |
|
628 | self.procUnitObj = procUnitObj | |
605 |
|
629 | |||
606 | return procUnitObj |
|
630 | return procUnitObj | |
607 |
|
631 | |||
608 | def run(self): |
|
632 | def run(self): | |
609 |
|
633 | |||
610 | is_ok = False |
|
634 | is_ok = False | |
611 |
|
635 | |||
612 | for opConfObj in self.opConfObjList: |
|
636 | for opConfObj in self.opConfObjList: | |
613 |
|
637 | |||
614 | kwargs = {} |
|
638 | kwargs = {} | |
615 | for parmConfObj in opConfObj.getParameterObjList(): |
|
639 | for parmConfObj in opConfObj.getParameterObjList(): | |
616 | if opConfObj.name == 'run' and parmConfObj.name == 'datatype': |
|
640 | if opConfObj.name == 'run' and parmConfObj.name == 'datatype': | |
617 | continue |
|
641 | continue | |
618 |
|
642 | |||
619 | kwargs[parmConfObj.name] = parmConfObj.getValue() |
|
643 | kwargs[parmConfObj.name] = parmConfObj.getValue() | |
620 |
|
644 | |||
621 | #ini = time.time() |
|
645 | #ini = time.time() | |
622 |
|
646 | |||
623 | #print "\tRunning the '%s' operation with %s" %(opConfObj.name, opConfObj.id) |
|
647 | #print "\tRunning the '%s' operation with %s" %(opConfObj.name, opConfObj.id) | |
624 | sts = self.procUnitObj.call(opType = opConfObj.type, |
|
648 | sts = self.procUnitObj.call(opType = opConfObj.type, | |
625 | opName = opConfObj.name, |
|
649 | opName = opConfObj.name, | |
626 | opId = opConfObj.id, |
|
650 | opId = opConfObj.id, | |
627 |
|
|
651 | ) | |
628 |
|
652 | |||
629 | # total_time = time.time() - ini |
|
653 | # total_time = time.time() - ini | |
630 | # |
|
654 | # | |
631 | # if total_time > 0.002: |
|
655 | # if total_time > 0.002: | |
632 | # print "%s::%s took %f seconds" %(self.name, opConfObj.name, total_time) |
|
656 | # print "%s::%s took %f seconds" %(self.name, opConfObj.name, total_time) | |
633 |
|
657 | |||
634 | is_ok = is_ok or sts |
|
658 | is_ok = is_ok or sts | |
635 |
|
659 | |||
636 | return is_ok |
|
660 | return is_ok | |
637 |
|
661 | |||
638 | def close(self): |
|
662 | def close(self): | |
639 |
|
663 | |||
640 | for opConfObj in self.opConfObjList: |
|
664 | for opConfObj in self.opConfObjList: | |
641 | if opConfObj.type == 'self': |
|
665 | if opConfObj.type == 'self': | |
642 | continue |
|
666 | continue | |
643 |
|
667 | |||
644 | opObj = self.procUnitObj.getOperationObj(opConfObj.id) |
|
668 | opObj = self.procUnitObj.getOperationObj(opConfObj.id) | |
645 | opObj.close() |
|
669 | opObj.close() | |
646 |
|
670 | |||
647 | self.procUnitObj.close() |
|
671 | self.procUnitObj.close() | |
648 |
|
672 | |||
649 | return |
|
673 | return | |
650 |
|
674 | |||
651 | class ReadUnitConf(ProcUnitConf): |
|
675 | class ReadUnitConf(ProcUnitConf): | |
652 |
|
676 | |||
653 | path = None |
|
677 | path = None | |
654 | startDate = None |
|
678 | startDate = None | |
655 | endDate = None |
|
679 | endDate = None | |
656 | startTime = None |
|
680 | startTime = None | |
657 | endTime = None |
|
681 | endTime = None | |
658 |
|
682 | |||
659 | ELEMENTNAME = 'ReadUnit' |
|
683 | ELEMENTNAME = 'ReadUnit' | |
660 |
|
684 | |||
661 | def __init__(self): |
|
685 | def __init__(self): | |
662 |
|
686 | |||
663 | self.id = None |
|
687 | self.id = None | |
664 | self.datatype = None |
|
688 | self.datatype = None | |
665 | self.name = None |
|
689 | self.name = None | |
666 | self.inputId = None |
|
690 | self.inputId = None | |
667 |
|
691 | |||
668 | self.parentId = None |
|
692 | self.parentId = None | |
669 |
|
693 | |||
670 | self.opConfObjList = [] |
|
694 | self.opConfObjList = [] | |
671 | self.opObjList = [] |
|
695 | self.opObjList = [] | |
672 |
|
696 | |||
673 | def getElementName(self): |
|
697 | def getElementName(self): | |
674 |
|
698 | |||
675 | return self.ELEMENTNAME |
|
699 | return self.ELEMENTNAME | |
676 |
|
700 | |||
677 | def setup(self, id, name, datatype, path, startDate="", endDate="", startTime="", endTime="", parentId=None, **kwargs): |
|
701 | def setup(self, id, name, datatype, path, startDate="", endDate="", startTime="", endTime="", parentId=None, **kwargs): | |
678 |
|
702 | |||
679 | #Compatible with old signal chain version |
|
703 | #Compatible with old signal chain version | |
680 | if datatype==None and name==None: |
|
704 | if datatype==None and name==None: | |
681 | raise ValueError, "datatype or name should be defined" |
|
705 | raise ValueError, "datatype or name should be defined" | |
682 |
|
706 | |||
683 | if name==None: |
|
707 | if name==None: | |
684 | if 'Reader' in datatype: |
|
708 | if 'Reader' in datatype: | |
685 | name = datatype |
|
709 | name = datatype | |
686 | else: |
|
710 | else: | |
687 | name = '%sReader' %(datatype) |
|
711 | name = '%sReader' %(datatype) | |
688 |
|
712 | |||
689 | if datatype==None: |
|
713 | if datatype==None: | |
690 | datatype = name.replace('Reader','') |
|
714 | datatype = name.replace('Reader','') | |
691 |
|
715 | |||
692 | self.id = id |
|
716 | self.id = id | |
693 | self.name = name |
|
717 | self.name = name | |
694 | self.datatype = datatype |
|
718 | self.datatype = datatype | |
695 |
|
719 | |||
696 | self.path = os.path.abspath(path) |
|
720 | self.path = os.path.abspath(path) | |
697 | self.startDate = startDate |
|
721 | self.startDate = startDate | |
698 | self.endDate = endDate |
|
722 | self.endDate = endDate | |
699 | self.startTime = startTime |
|
723 | self.startTime = startTime | |
700 | self.endTime = endTime |
|
724 | self.endTime = endTime | |
701 |
|
725 | |||
702 | self.inputId = '0' |
|
726 | self.inputId = '0' | |
703 | self.parentId = parentId |
|
727 | self.parentId = parentId | |
704 |
|
728 | |||
705 | self.addRunOperation(**kwargs) |
|
729 | self.addRunOperation(**kwargs) | |
706 |
|
730 | |||
707 | def update(self, datatype, path, startDate, endDate, startTime, endTime, parentId=None, name=None, **kwargs): |
|
731 | def update(self, datatype, path, startDate, endDate, startTime, endTime, parentId=None, name=None, **kwargs): | |
708 |
|
732 | |||
709 | #Compatible with old signal chain version |
|
733 | #Compatible with old signal chain version | |
710 | if datatype==None and name==None: |
|
734 | if datatype==None and name==None: | |
711 | raise ValueError, "datatype or name should be defined" |
|
735 | raise ValueError, "datatype or name should be defined" | |
712 |
|
736 | |||
713 | if name==None: |
|
737 | if name==None: | |
714 | if 'Reader' in datatype: |
|
738 | if 'Reader' in datatype: | |
715 | name = datatype |
|
739 | name = datatype | |
716 | else: |
|
740 | else: | |
717 | name = '%sReader' %(datatype) |
|
741 | name = '%sReader' %(datatype) | |
718 |
|
742 | |||
719 | if datatype==None: |
|
743 | if datatype==None: | |
720 | datatype = name.replace('Reader','') |
|
744 | datatype = name.replace('Reader','') | |
721 |
|
745 | |||
722 | self.datatype = datatype |
|
746 | self.datatype = datatype | |
723 | self.name = name |
|
747 | self.name = name | |
724 | self.path = path |
|
748 | self.path = path | |
@@ -726,394 +750,394 class ReadUnitConf(ProcUnitConf): | |||||
726 | self.endDate = endDate |
|
750 | self.endDate = endDate | |
727 | self.startTime = startTime |
|
751 | self.startTime = startTime | |
728 | self.endTime = endTime |
|
752 | self.endTime = endTime | |
729 |
|
753 | |||
730 | self.inputId = '0' |
|
754 | self.inputId = '0' | |
731 | self.parentId = parentId |
|
755 | self.parentId = parentId | |
732 |
|
756 | |||
733 | self.updateRunOperation(**kwargs) |
|
757 | self.updateRunOperation(**kwargs) | |
734 |
|
758 | |||
735 | def removeOperations(self): |
|
759 | def removeOperations(self): | |
736 |
|
760 | |||
737 | for obj in self.opConfObjList: |
|
761 | for obj in self.opConfObjList: | |
738 | del obj |
|
762 | del obj | |
739 |
|
763 | |||
740 | self.opConfObjList = [] |
|
764 | self.opConfObjList = [] | |
741 |
|
765 | |||
742 | def addRunOperation(self, **kwargs): |
|
766 | def addRunOperation(self, **kwargs): | |
743 |
|
767 | |||
744 | opObj = self.addOperation(name = 'run', optype = 'self') |
|
768 | opObj = self.addOperation(name = 'run', optype = 'self') | |
745 |
|
769 | |||
746 | opObj.addParameter(name='datatype' , value=self.datatype, format='str') |
|
770 | opObj.addParameter(name='datatype' , value=self.datatype, format='str') | |
747 | opObj.addParameter(name='path' , value=self.path, format='str') |
|
771 | opObj.addParameter(name='path' , value=self.path, format='str') | |
748 | opObj.addParameter(name='startDate' , value=self.startDate, format='date') |
|
772 | opObj.addParameter(name='startDate' , value=self.startDate, format='date') | |
749 | opObj.addParameter(name='endDate' , value=self.endDate, format='date') |
|
773 | opObj.addParameter(name='endDate' , value=self.endDate, format='date') | |
750 | opObj.addParameter(name='startTime' , value=self.startTime, format='time') |
|
774 | opObj.addParameter(name='startTime' , value=self.startTime, format='time') | |
751 | opObj.addParameter(name='endTime' , value=self.endTime, format='time') |
|
775 | opObj.addParameter(name='endTime' , value=self.endTime, format='time') | |
752 |
|
776 | |||
753 | for key, value in kwargs.items(): |
|
777 | for key, value in kwargs.items(): | |
754 | opObj.addParameter(name=key, value=value, format=type(value).__name__) |
|
778 | opObj.addParameter(name=key, value=value, format=type(value).__name__) | |
755 |
|
779 | |||
756 | return opObj |
|
780 | return opObj | |
757 |
|
781 | |||
758 | def updateRunOperation(self, **kwargs): |
|
782 | def updateRunOperation(self, **kwargs): | |
759 |
|
783 | |||
760 | opObj = self.getOperationObj(name = 'run') |
|
784 | opObj = self.getOperationObj(name = 'run') | |
761 | opObj.removeParameters() |
|
785 | opObj.removeParameters() | |
762 |
|
786 | |||
763 | opObj.addParameter(name='datatype' , value=self.datatype, format='str') |
|
787 | opObj.addParameter(name='datatype' , value=self.datatype, format='str') | |
764 | opObj.addParameter(name='path' , value=self.path, format='str') |
|
788 | opObj.addParameter(name='path' , value=self.path, format='str') | |
765 | opObj.addParameter(name='startDate' , value=self.startDate, format='date') |
|
789 | opObj.addParameter(name='startDate' , value=self.startDate, format='date') | |
766 | opObj.addParameter(name='endDate' , value=self.endDate, format='date') |
|
790 | opObj.addParameter(name='endDate' , value=self.endDate, format='date') | |
767 | opObj.addParameter(name='startTime' , value=self.startTime, format='time') |
|
791 | opObj.addParameter(name='startTime' , value=self.startTime, format='time') | |
768 | opObj.addParameter(name='endTime' , value=self.endTime, format='time') |
|
792 | opObj.addParameter(name='endTime' , value=self.endTime, format='time') | |
769 |
|
793 | |||
770 | for key, value in kwargs.items(): |
|
794 | for key, value in kwargs.items(): | |
771 | opObj.addParameter(name=key, value=value, format=type(value).__name__) |
|
795 | opObj.addParameter(name=key, value=value, format=type(value).__name__) | |
772 |
|
796 | |||
773 | return opObj |
|
797 | return opObj | |
774 |
|
798 | |||
775 | # def makeXml(self, projectElement): |
|
799 | # def makeXml(self, projectElement): | |
776 | # |
|
800 | # | |
777 | # procUnitElement = SubElement(projectElement, self.ELEMENTNAME) |
|
801 | # procUnitElement = SubElement(projectElement, self.ELEMENTNAME) | |
778 | # procUnitElement.set('id', str(self.id)) |
|
802 | # procUnitElement.set('id', str(self.id)) | |
779 | # procUnitElement.set('name', self.name) |
|
803 | # procUnitElement.set('name', self.name) | |
780 | # procUnitElement.set('datatype', self.datatype) |
|
804 | # procUnitElement.set('datatype', self.datatype) | |
781 | # procUnitElement.set('inputId', str(self.inputId)) |
|
805 | # procUnitElement.set('inputId', str(self.inputId)) | |
782 | # |
|
806 | # | |
783 | # for opConfObj in self.opConfObjList: |
|
807 | # for opConfObj in self.opConfObjList: | |
784 | # opConfObj.makeXml(procUnitElement) |
|
808 | # opConfObj.makeXml(procUnitElement) | |
785 |
|
809 | |||
786 | def readXml(self, upElement): |
|
810 | def readXml(self, upElement): | |
787 |
|
811 | |||
788 | self.id = upElement.get('id') |
|
812 | self.id = upElement.get('id') | |
789 | self.name = upElement.get('name') |
|
813 | self.name = upElement.get('name') | |
790 | self.datatype = upElement.get('datatype') |
|
814 | self.datatype = upElement.get('datatype') | |
791 | self.inputId = upElement.get('inputId') |
|
815 | self.inputId = upElement.get('inputId') | |
792 |
|
816 | |||
793 | if self.ELEMENTNAME == "ReadUnit": |
|
817 | if self.ELEMENTNAME == "ReadUnit": | |
794 | self.datatype = self.datatype.replace("Reader", "") |
|
818 | self.datatype = self.datatype.replace("Reader", "") | |
795 |
|
819 | |||
796 | if self.inputId == 'None': |
|
820 | if self.inputId == 'None': | |
797 | self.inputId = '0' |
|
821 | self.inputId = '0' | |
798 |
|
822 | |||
799 | self.opConfObjList = [] |
|
823 | self.opConfObjList = [] | |
800 |
|
824 | |||
801 | opElementList = upElement.iter(OperationConf().getElementName()) |
|
825 | opElementList = upElement.iter(OperationConf().getElementName()) | |
802 |
|
826 | |||
803 | for opElement in opElementList: |
|
827 | for opElement in opElementList: | |
804 | opConfObj = OperationConf() |
|
828 | opConfObj = OperationConf() | |
805 | opConfObj.readXml(opElement) |
|
829 | opConfObj.readXml(opElement) | |
806 | self.opConfObjList.append(opConfObj) |
|
830 | self.opConfObjList.append(opConfObj) | |
807 |
|
831 | |||
808 | if opConfObj.name == 'run': |
|
832 | if opConfObj.name == 'run': | |
809 | self.path = opConfObj.getParameterValue('path') |
|
833 | self.path = opConfObj.getParameterValue('path') | |
810 | self.startDate = opConfObj.getParameterValue('startDate') |
|
834 | self.startDate = opConfObj.getParameterValue('startDate') | |
811 | self.endDate = opConfObj.getParameterValue('endDate') |
|
835 | self.endDate = opConfObj.getParameterValue('endDate') | |
812 | self.startTime = opConfObj.getParameterValue('startTime') |
|
836 | self.startTime = opConfObj.getParameterValue('startTime') | |
813 | self.endTime = opConfObj.getParameterValue('endTime') |
|
837 | self.endTime = opConfObj.getParameterValue('endTime') | |
814 |
|
838 | |||
815 | class Project(): |
|
839 | class Project(): | |
816 |
|
840 | |||
817 | id = None |
|
841 | id = None | |
818 | name = None |
|
842 | name = None | |
819 | description = None |
|
843 | description = None | |
820 | filename = None |
|
844 | filename = None | |
821 |
|
845 | |||
822 | procUnitConfObjDict = None |
|
846 | procUnitConfObjDict = None | |
823 |
|
847 | |||
824 | ELEMENTNAME = 'Project' |
|
848 | ELEMENTNAME = 'Project' | |
825 |
|
849 | |||
826 | plotterQueue = None |
|
850 | plotterQueue = None | |
827 |
|
851 | |||
828 | def __init__(self, plotter_queue=None): |
|
852 | def __init__(self, plotter_queue=None): | |
829 |
|
853 | |||
830 | self.id = None |
|
854 | self.id = None | |
831 | self.name = None |
|
855 | self.name = None | |
832 | self.description = None |
|
856 | self.description = None | |
833 |
|
857 | |||
834 | self.plotterQueue = plotter_queue |
|
858 | self.plotterQueue = plotter_queue | |
835 |
|
859 | |||
836 | self.procUnitConfObjDict = {} |
|
860 | self.procUnitConfObjDict = {} | |
837 |
|
861 | |||
838 | def __getNewId(self): |
|
862 | def __getNewId(self): | |
839 |
|
863 | |||
840 | idList = self.procUnitConfObjDict.keys() |
|
864 | idList = self.procUnitConfObjDict.keys() | |
841 |
|
865 | |||
842 | id = int(self.id)*10 |
|
866 | id = int(self.id)*10 | |
843 |
|
867 | |||
844 | while True: |
|
868 | while True: | |
845 | id += 1 |
|
869 | id += 1 | |
846 |
|
870 | |||
847 | if str(id) in idList: |
|
871 | if str(id) in idList: | |
848 | continue |
|
872 | continue | |
849 |
|
873 | |||
850 | break |
|
874 | break | |
851 |
|
875 | |||
852 | return str(id) |
|
876 | return str(id) | |
853 |
|
877 | |||
854 | def getElementName(self): |
|
878 | def getElementName(self): | |
855 |
|
879 | |||
856 | return self.ELEMENTNAME |
|
880 | return self.ELEMENTNAME | |
857 |
|
881 | |||
858 | def getId(self): |
|
882 | def getId(self): | |
859 |
|
883 | |||
860 | return self.id |
|
884 | return self.id | |
861 |
|
885 | |||
862 | def updateId(self, new_id): |
|
886 | def updateId(self, new_id): | |
863 |
|
887 | |||
864 | self.id = str(new_id) |
|
888 | self.id = str(new_id) | |
865 |
|
889 | |||
866 | keyList = self.procUnitConfObjDict.keys() |
|
890 | keyList = self.procUnitConfObjDict.keys() | |
867 | keyList.sort() |
|
891 | keyList.sort() | |
868 |
|
892 | |||
869 | n = 1 |
|
893 | n = 1 | |
870 | newProcUnitConfObjDict = {} |
|
894 | newProcUnitConfObjDict = {} | |
871 |
|
895 | |||
872 | for procKey in keyList: |
|
896 | for procKey in keyList: | |
873 |
|
897 | |||
874 | procUnitConfObj = self.procUnitConfObjDict[procKey] |
|
898 | procUnitConfObj = self.procUnitConfObjDict[procKey] | |
875 | idProcUnit = str(int(self.id)*10 + n) |
|
899 | idProcUnit = str(int(self.id)*10 + n) | |
876 | procUnitConfObj.updateId(idProcUnit, parentId = self.id) |
|
900 | procUnitConfObj.updateId(idProcUnit, parentId = self.id) | |
877 |
|
901 | |||
878 | newProcUnitConfObjDict[idProcUnit] = procUnitConfObj |
|
902 | newProcUnitConfObjDict[idProcUnit] = procUnitConfObj | |
879 | n += 1 |
|
903 | n += 1 | |
880 |
|
904 | |||
881 | self.procUnitConfObjDict = newProcUnitConfObjDict |
|
905 | self.procUnitConfObjDict = newProcUnitConfObjDict | |
882 |
|
906 | |||
883 | def setup(self, id, name, description): |
|
907 | def setup(self, id, name, description): | |
884 |
|
908 | |||
885 | self.id = str(id) |
|
909 | self.id = str(id) | |
886 | self.name = name |
|
910 | self.name = name | |
887 | self.description = description |
|
911 | self.description = description | |
888 |
|
912 | |||
889 | def update(self, name, description): |
|
913 | def update(self, name, description): | |
890 |
|
914 | |||
891 | self.name = name |
|
915 | self.name = name | |
892 | self.description = description |
|
916 | self.description = description | |
893 |
|
917 | |||
894 | def addReadUnit(self, id=None, datatype=None, name=None, **kwargs): |
|
918 | def addReadUnit(self, id=None, datatype=None, name=None, **kwargs): | |
895 |
|
919 | |||
896 | if id is None: |
|
920 | if id is None: | |
897 | idReadUnit = self.__getNewId() |
|
921 | idReadUnit = self.__getNewId() | |
898 | else: |
|
922 | else: | |
899 | idReadUnit = str(id) |
|
923 | idReadUnit = str(id) | |
900 |
|
924 | |||
901 | readUnitConfObj = ReadUnitConf() |
|
925 | readUnitConfObj = ReadUnitConf() | |
902 | readUnitConfObj.setup(idReadUnit, name, datatype, parentId=self.id, **kwargs) |
|
926 | readUnitConfObj.setup(idReadUnit, name, datatype, parentId=self.id, **kwargs) | |
903 |
|
927 | |||
904 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj |
|
928 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj | |
905 |
|
929 | |||
906 | return readUnitConfObj |
|
930 | return readUnitConfObj | |
907 |
|
931 | |||
908 | def addProcUnit(self, inputId='0', datatype=None, name=None): |
|
932 | def addProcUnit(self, inputId='0', datatype=None, name=None): | |
909 |
|
933 | |||
910 | idProcUnit = self.__getNewId() |
|
934 | idProcUnit = self.__getNewId() | |
911 |
|
935 | |||
912 | procUnitConfObj = ProcUnitConf() |
|
936 | procUnitConfObj = ProcUnitConf() | |
913 | procUnitConfObj.setup(idProcUnit, name, datatype, inputId, parentId=self.id) |
|
937 | procUnitConfObj.setup(idProcUnit, name, datatype, inputId, parentId=self.id) | |
914 |
|
938 | |||
915 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj |
|
939 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj | |
916 |
|
940 | |||
917 | return procUnitConfObj |
|
941 | return procUnitConfObj | |
918 |
|
942 | |||
919 | def removeProcUnit(self, id): |
|
943 | def removeProcUnit(self, id): | |
920 |
|
944 | |||
921 | if id in self.procUnitConfObjDict.keys(): |
|
945 | if id in self.procUnitConfObjDict.keys(): | |
922 | self.procUnitConfObjDict.pop(id) |
|
946 | self.procUnitConfObjDict.pop(id) | |
923 |
|
947 | |||
924 | def getReadUnitId(self): |
|
948 | def getReadUnitId(self): | |
925 |
|
949 | |||
926 | readUnitConfObj = self.getReadUnitObj() |
|
950 | readUnitConfObj = self.getReadUnitObj() | |
927 |
|
951 | |||
928 | return readUnitConfObj.id |
|
952 | return readUnitConfObj.id | |
929 |
|
953 | |||
930 | def getReadUnitObj(self): |
|
954 | def getReadUnitObj(self): | |
931 |
|
955 | |||
932 | for obj in self.procUnitConfObjDict.values(): |
|
956 | for obj in self.procUnitConfObjDict.values(): | |
933 | if obj.getElementName() == "ReadUnit": |
|
957 | if obj.getElementName() == "ReadUnit": | |
934 | return obj |
|
958 | return obj | |
935 |
|
959 | |||
936 | return None |
|
960 | return None | |
937 |
|
961 | |||
938 | def getProcUnitObj(self, id=None, name=None): |
|
962 | def getProcUnitObj(self, id=None, name=None): | |
939 |
|
963 | |||
940 | if id != None: |
|
964 | if id != None: | |
941 | return self.procUnitConfObjDict[id] |
|
965 | return self.procUnitConfObjDict[id] | |
942 |
|
966 | |||
943 | if name != None: |
|
967 | if name != None: | |
944 | return self.getProcUnitObjByName(name) |
|
968 | return self.getProcUnitObjByName(name) | |
945 |
|
969 | |||
946 | return None |
|
970 | return None | |
947 |
|
971 | |||
948 | def getProcUnitObjByName(self, name): |
|
972 | def getProcUnitObjByName(self, name): | |
949 |
|
973 | |||
950 | for obj in self.procUnitConfObjDict.values(): |
|
974 | for obj in self.procUnitConfObjDict.values(): | |
951 | if obj.name == name: |
|
975 | if obj.name == name: | |
952 | return obj |
|
976 | return obj | |
953 |
|
977 | |||
954 | return None |
|
978 | return None | |
955 |
|
979 | |||
956 | def procUnitItems(self): |
|
980 | def procUnitItems(self): | |
957 |
|
981 | |||
958 | return self.procUnitConfObjDict.items() |
|
982 | return self.procUnitConfObjDict.items() | |
959 |
|
983 | |||
960 |
def makeXml(self): |
|
984 | def makeXml(self): | |
961 |
|
985 | |||
962 | projectElement = Element('Project') |
|
986 | projectElement = Element('Project') | |
963 | projectElement.set('id', str(self.id)) |
|
987 | projectElement.set('id', str(self.id)) | |
964 | projectElement.set('name', self.name) |
|
988 | projectElement.set('name', self.name) | |
965 | projectElement.set('description', self.description) |
|
989 | projectElement.set('description', self.description) | |
966 |
|
990 | |||
967 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
991 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |
968 | procUnitConfObj.makeXml(projectElement) |
|
992 | procUnitConfObj.makeXml(projectElement) | |
969 |
|
993 | |||
970 | self.projectElement = projectElement |
|
994 | self.projectElement = projectElement | |
971 |
|
995 | |||
972 | def writeXml(self, filename=None): |
|
996 | def writeXml(self, filename=None): | |
973 |
|
997 | |||
974 | if filename == None: |
|
998 | if filename == None: | |
975 | if self.filename: |
|
999 | if self.filename: | |
976 | filename = self.filename |
|
1000 | filename = self.filename | |
977 | else: |
|
1001 | else: | |
978 | filename = "schain.xml" |
|
1002 | filename = "schain.xml" | |
979 |
|
1003 | |||
980 | if not filename: |
|
1004 | if not filename: | |
981 | print "filename has not been defined. Use setFilename(filename) for do it." |
|
1005 | print "filename has not been defined. Use setFilename(filename) for do it." | |
982 | return 0 |
|
1006 | return 0 | |
983 |
|
1007 | |||
984 | abs_file = os.path.abspath(filename) |
|
1008 | abs_file = os.path.abspath(filename) | |
985 |
|
1009 | |||
986 | if not os.access(os.path.dirname(abs_file), os.W_OK): |
|
1010 | if not os.access(os.path.dirname(abs_file), os.W_OK): | |
987 | print "No write permission on %s" %os.path.dirname(abs_file) |
|
1011 | print "No write permission on %s" %os.path.dirname(abs_file) | |
988 | return 0 |
|
1012 | return 0 | |
989 |
|
1013 | |||
990 | if os.path.isfile(abs_file) and not(os.access(abs_file, os.W_OK)): |
|
1014 | if os.path.isfile(abs_file) and not(os.access(abs_file, os.W_OK)): | |
991 | print "File %s already exists and it could not be overwriten" %abs_file |
|
1015 | print "File %s already exists and it could not be overwriten" %abs_file | |
992 | return 0 |
|
1016 | return 0 | |
993 |
|
1017 | |||
994 | self.makeXml() |
|
1018 | self.makeXml() | |
995 |
|
1019 | |||
996 | ElementTree(self.projectElement).write(abs_file, method='xml') |
|
1020 | ElementTree(self.projectElement).write(abs_file, method='xml') | |
997 |
|
1021 | |||
998 | self.filename = abs_file |
|
1022 | self.filename = abs_file | |
999 |
|
1023 | |||
1000 | return 1 |
|
1024 | return 1 | |
1001 |
|
1025 | |||
1002 | def readXml(self, filename = None): |
|
1026 | def readXml(self, filename = None): | |
1003 |
|
1027 | |||
1004 | if not filename: |
|
1028 | if not filename: | |
1005 | print "filename is not defined" |
|
1029 | print "filename is not defined" | |
1006 | return 0 |
|
1030 | return 0 | |
1007 |
|
1031 | |||
1008 | abs_file = os.path.abspath(filename) |
|
1032 | abs_file = os.path.abspath(filename) | |
1009 |
|
1033 | |||
1010 | if not os.path.isfile(abs_file): |
|
1034 | if not os.path.isfile(abs_file): | |
1011 | print "%s file does not exist" %abs_file |
|
1035 | print "%s file does not exist" %abs_file | |
1012 | return 0 |
|
1036 | return 0 | |
1013 |
|
1037 | |||
1014 | self.projectElement = None |
|
1038 | self.projectElement = None | |
1015 | self.procUnitConfObjDict = {} |
|
1039 | self.procUnitConfObjDict = {} | |
1016 |
|
1040 | |||
1017 | try: |
|
1041 | try: | |
1018 | self.projectElement = ElementTree().parse(abs_file) |
|
1042 | self.projectElement = ElementTree().parse(abs_file) | |
1019 | except: |
|
1043 | except: | |
1020 | print "Error reading %s, verify file format" %filename |
|
1044 | print "Error reading %s, verify file format" %filename | |
1021 | return 0 |
|
1045 | return 0 | |
1022 |
|
1046 | |||
1023 | self.project = self.projectElement.tag |
|
1047 | self.project = self.projectElement.tag | |
1024 |
|
1048 | |||
1025 | self.id = self.projectElement.get('id') |
|
1049 | self.id = self.projectElement.get('id') | |
1026 | self.name = self.projectElement.get('name') |
|
1050 | self.name = self.projectElement.get('name') | |
1027 |
self.description = self.projectElement.get('description') |
|
1051 | self.description = self.projectElement.get('description') | |
1028 |
|
1052 | |||
1029 | readUnitElementList = self.projectElement.iter(ReadUnitConf().getElementName()) |
|
1053 | readUnitElementList = self.projectElement.iter(ReadUnitConf().getElementName()) | |
1030 |
|
1054 | |||
1031 | for readUnitElement in readUnitElementList: |
|
1055 | for readUnitElement in readUnitElementList: | |
1032 | readUnitConfObj = ReadUnitConf() |
|
1056 | readUnitConfObj = ReadUnitConf() | |
1033 | readUnitConfObj.readXml(readUnitElement) |
|
1057 | readUnitConfObj.readXml(readUnitElement) | |
1034 |
|
1058 | |||
1035 | if readUnitConfObj.parentId == None: |
|
1059 | if readUnitConfObj.parentId == None: | |
1036 | readUnitConfObj.parentId = self.id |
|
1060 | readUnitConfObj.parentId = self.id | |
1037 |
|
1061 | |||
1038 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj |
|
1062 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj | |
1039 |
|
1063 | |||
1040 | procUnitElementList = self.projectElement.iter(ProcUnitConf().getElementName()) |
|
1064 | procUnitElementList = self.projectElement.iter(ProcUnitConf().getElementName()) | |
1041 |
|
1065 | |||
1042 | for procUnitElement in procUnitElementList: |
|
1066 | for procUnitElement in procUnitElementList: | |
1043 | procUnitConfObj = ProcUnitConf() |
|
1067 | procUnitConfObj = ProcUnitConf() | |
1044 | procUnitConfObj.readXml(procUnitElement) |
|
1068 | procUnitConfObj.readXml(procUnitElement) | |
1045 |
|
1069 | |||
1046 | if procUnitConfObj.parentId == None: |
|
1070 | if procUnitConfObj.parentId == None: | |
1047 | procUnitConfObj.parentId = self.id |
|
1071 | procUnitConfObj.parentId = self.id | |
1048 |
|
1072 | |||
1049 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj |
|
1073 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj | |
1050 |
|
1074 | |||
1051 | self.filename = abs_file |
|
1075 | self.filename = abs_file | |
1052 |
|
1076 | |||
1053 | return 1 |
|
1077 | return 1 | |
1054 |
|
1078 | |||
1055 | def printattr(self): |
|
1079 | def printattr(self): | |
1056 |
|
1080 | |||
1057 | print "Project[%s]: name = %s, description = %s" %(self.id, |
|
1081 | print "Project[%s]: name = %s, description = %s" %(self.id, | |
1058 | self.name, |
|
1082 | self.name, | |
1059 | self.description) |
|
1083 | self.description) | |
1060 |
|
1084 | |||
1061 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
1085 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |
1062 | procUnitConfObj.printattr() |
|
1086 | procUnitConfObj.printattr() | |
1063 |
|
1087 | |||
1064 | def createObjects(self): |
|
1088 | def createObjects(self): | |
1065 |
|
1089 | |||
1066 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
1090 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |
1067 | procUnitConfObj.createObjects(self.plotterQueue) |
|
1091 | procUnitConfObj.createObjects(self.plotterQueue) | |
1068 |
|
1092 | |||
1069 | def __connect(self, objIN, thisObj): |
|
1093 | def __connect(self, objIN, thisObj): | |
1070 |
|
1094 | |||
1071 | thisObj.setInput(objIN.getOutputObj()) |
|
1095 | thisObj.setInput(objIN.getOutputObj()) | |
1072 |
|
1096 | |||
1073 | def connectObjects(self): |
|
1097 | def connectObjects(self): | |
1074 |
|
1098 | |||
1075 | for thisPUConfObj in self.procUnitConfObjDict.values(): |
|
1099 | for thisPUConfObj in self.procUnitConfObjDict.values(): | |
1076 |
|
1100 | |||
1077 | inputId = thisPUConfObj.getInputId() |
|
1101 | inputId = thisPUConfObj.getInputId() | |
1078 |
|
1102 | |||
1079 | if int(inputId) == 0: |
|
1103 | if int(inputId) == 0: | |
1080 | continue |
|
1104 | continue | |
1081 |
|
1105 | |||
1082 | #Get input object |
|
1106 | #Get input object | |
1083 | puConfINObj = self.procUnitConfObjDict[inputId] |
|
1107 | puConfINObj = self.procUnitConfObjDict[inputId] | |
1084 | puObjIN = puConfINObj.getProcUnitObj() |
|
1108 | puObjIN = puConfINObj.getProcUnitObj() | |
1085 |
|
1109 | |||
1086 | #Get current object |
|
1110 | #Get current object | |
1087 | thisPUObj = thisPUConfObj.getProcUnitObj() |
|
1111 | thisPUObj = thisPUConfObj.getProcUnitObj() | |
1088 |
|
1112 | |||
1089 | self.__connect(puObjIN, thisPUObj) |
|
1113 | self.__connect(puObjIN, thisPUObj) | |
1090 |
|
1114 | |||
1091 | def __handleError(self, procUnitConfObj, send_email=True): |
|
1115 | def __handleError(self, procUnitConfObj, send_email=True): | |
1092 |
|
1116 | |||
1093 | import socket |
|
1117 | import socket | |
1094 |
|
1118 | |||
1095 | err = traceback.format_exception(sys.exc_info()[0], |
|
1119 | err = traceback.format_exception(sys.exc_info()[0], | |
1096 | sys.exc_info()[1], |
|
1120 | sys.exc_info()[1], | |
1097 | sys.exc_info()[2]) |
|
1121 | sys.exc_info()[2]) | |
1098 |
|
1122 | |||
1099 | print "***** Error occurred in %s *****" %(procUnitConfObj.name) |
|
1123 | print "***** Error occurred in %s *****" %(procUnitConfObj.name) | |
1100 | print "***** %s" %err[-1] |
|
1124 | print "***** %s" %err[-1] | |
1101 |
|
1125 | |||
1102 | message = "".join(err) |
|
1126 | message = "".join(err) | |
1103 |
|
1127 | |||
1104 | sys.stderr.write(message) |
|
1128 | sys.stderr.write(message) | |
1105 |
|
1129 | |||
1106 | if not send_email: |
|
1130 | if not send_email: | |
1107 | return |
|
1131 | return | |
1108 |
|
1132 | |||
1109 | subject = "SChain v%s: Error running %s\n" %(schainpy.__version__, procUnitConfObj.name) |
|
1133 | subject = "SChain v%s: Error running %s\n" %(schainpy.__version__, procUnitConfObj.name) | |
1110 |
|
1134 | |||
1111 | subtitle = "%s: %s\n" %(procUnitConfObj.getElementName() ,procUnitConfObj.name) |
|
1135 | subtitle = "%s: %s\n" %(procUnitConfObj.getElementName() ,procUnitConfObj.name) | |
1112 | subtitle += "Hostname: %s\n" %socket.gethostbyname(socket.gethostname()) |
|
1136 | subtitle += "Hostname: %s\n" %socket.gethostbyname(socket.gethostname()) | |
1113 | subtitle += "Working directory: %s\n" %os.path.abspath("./") |
|
1137 | subtitle += "Working directory: %s\n" %os.path.abspath("./") | |
1114 | subtitle += "Configuration file: %s\n" %self.filename |
|
1138 | subtitle += "Configuration file: %s\n" %self.filename | |
1115 | subtitle += "Time: %s\n" %str(datetime.datetime.now()) |
|
1139 | subtitle += "Time: %s\n" %str(datetime.datetime.now()) | |
1116 |
|
1140 | |||
1117 | readUnitConfObj = self.getReadUnitObj() |
|
1141 | readUnitConfObj = self.getReadUnitObj() | |
1118 | if readUnitConfObj: |
|
1142 | if readUnitConfObj: | |
1119 | subtitle += "\nInput parameters:\n" |
|
1143 | subtitle += "\nInput parameters:\n" | |
@@ -1123,80 +1147,80 class Project(): | |||||
1123 | subtitle += "[End date = %s]\n" %readUnitConfObj.endDate |
|
1147 | subtitle += "[End date = %s]\n" %readUnitConfObj.endDate | |
1124 | subtitle += "[Start time = %s]\n" %readUnitConfObj.startTime |
|
1148 | subtitle += "[Start time = %s]\n" %readUnitConfObj.startTime | |
1125 | subtitle += "[End time = %s]\n" %readUnitConfObj.endTime |
|
1149 | subtitle += "[End time = %s]\n" %readUnitConfObj.endTime | |
1126 |
|
1150 | |||
1127 | adminObj = schainpy.admin.SchainNotify() |
|
1151 | adminObj = schainpy.admin.SchainNotify() | |
1128 | adminObj.sendAlert(message=message, |
|
1152 | adminObj.sendAlert(message=message, | |
1129 | subject=subject, |
|
1153 | subject=subject, | |
1130 | subtitle=subtitle, |
|
1154 | subtitle=subtitle, | |
1131 | filename=self.filename) |
|
1155 | filename=self.filename) | |
1132 |
|
1156 | |||
1133 | def isPaused(self): |
|
1157 | def isPaused(self): | |
1134 | return 0 |
|
1158 | return 0 | |
1135 |
|
1159 | |||
1136 | def isStopped(self): |
|
1160 | def isStopped(self): | |
1137 | return 0 |
|
1161 | return 0 | |
1138 |
|
1162 | |||
1139 | def runController(self): |
|
1163 | def runController(self): | |
1140 | """ |
|
1164 | """ | |
1141 | returns 0 when this process has been stopped, 1 otherwise |
|
1165 | returns 0 when this process has been stopped, 1 otherwise | |
1142 | """ |
|
1166 | """ | |
1143 |
|
1167 | |||
1144 | if self.isPaused(): |
|
1168 | if self.isPaused(): | |
1145 | print "Process suspended" |
|
1169 | print "Process suspended" | |
1146 |
|
1170 | |||
1147 | while True: |
|
1171 | while True: | |
1148 | sleep(0.1) |
|
1172 | sleep(0.1) | |
1149 |
|
1173 | |||
1150 | if not self.isPaused(): |
|
1174 | if not self.isPaused(): | |
1151 | break |
|
1175 | break | |
1152 |
|
1176 | |||
1153 | if self.isStopped(): |
|
1177 | if self.isStopped(): | |
1154 | break |
|
1178 | break | |
1155 |
|
1179 | |||
1156 | print "Process reinitialized" |
|
1180 | print "Process reinitialized" | |
1157 |
|
1181 | |||
1158 | if self.isStopped(): |
|
1182 | if self.isStopped(): | |
1159 | print "Process stopped" |
|
1183 | print "Process stopped" | |
1160 | return 0 |
|
1184 | return 0 | |
1161 |
|
1185 | |||
1162 | return 1 |
|
1186 | return 1 | |
1163 |
|
1187 | |||
1164 | def setFilename(self, filename): |
|
1188 | def setFilename(self, filename): | |
1165 |
|
1189 | |||
1166 | self.filename = filename |
|
1190 | self.filename = filename | |
1167 |
|
1191 | |||
1168 | def setPlotterQueue(self, plotter_queue): |
|
1192 | def setPlotterQueue(self, plotter_queue): | |
1169 |
|
1193 | |||
1170 | raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class" |
|
1194 | raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class" | |
1171 |
|
1195 | |||
1172 | def getPlotterQueue(self): |
|
1196 | def getPlotterQueue(self): | |
1173 |
|
1197 | |||
1174 | raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class" |
|
1198 | raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class" | |
1175 |
|
1199 | |||
1176 | def useExternalPlotter(self): |
|
1200 | def useExternalPlotter(self): | |
1177 |
|
1201 | |||
1178 | raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class" |
|
1202 | raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class" | |
1179 |
|
1203 | |||
1180 | def run(self): |
|
1204 | def run(self): | |
1181 |
|
1205 | |||
1182 |
|
1206 | |||
1183 | print "*"*60 |
|
1207 | print "*"*60 | |
1184 | print " Starting SIGNAL CHAIN PROCESSING v%s " %schainpy.__version__ |
|
1208 | print " Starting SIGNAL CHAIN PROCESSING v%s " %schainpy.__version__ | |
1185 | print "*"*60 |
|
1209 | print "*"*60 | |
1186 |
|
1210 | |||
1187 |
|
1211 | |||
1188 | keyList = self.procUnitConfObjDict.keys() |
|
1212 | keyList = self.procUnitConfObjDict.keys() | |
1189 | keyList.sort() |
|
1213 | keyList.sort() | |
1190 |
|
1214 | |||
1191 | while(True): |
|
1215 | while(True): | |
1192 |
|
1216 | |||
1193 | is_ok = False |
|
1217 | is_ok = False | |
1194 |
|
1218 | |||
1195 | for procKey in keyList: |
|
1219 | for procKey in keyList: | |
1196 | # print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id) |
|
1220 | # print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id) | |
1197 |
|
1221 | |||
1198 | procUnitConfObj = self.procUnitConfObjDict[procKey] |
|
1222 | procUnitConfObj = self.procUnitConfObjDict[procKey] | |
1199 |
|
1223 | |||
1200 | try: |
|
1224 | try: | |
1201 | sts = procUnitConfObj.run() |
|
1225 | sts = procUnitConfObj.run() | |
1202 | is_ok = is_ok or sts |
|
1226 | is_ok = is_ok or sts | |
@@ -1213,7 +1237,7 class Project(): | |||||
1213 | self.__handleError(procUnitConfObj) |
|
1237 | self.__handleError(procUnitConfObj) | |
1214 | is_ok = False |
|
1238 | is_ok = False | |
1215 | break |
|
1239 | break | |
1216 |
|
1240 | |||
1217 | #If every process unit finished so end process |
|
1241 | #If every process unit finished so end process | |
1218 | if not(is_ok): |
|
1242 | if not(is_ok): | |
1219 | # print "Every process unit have finished" |
|
1243 | # print "Every process unit have finished" | |
@@ -1221,74 +1245,17 class Project(): | |||||
1221 |
|
1245 | |||
1222 | if not self.runController(): |
|
1246 | if not self.runController(): | |
1223 | break |
|
1247 | break | |
1224 |
|
1248 | |||
1225 | #Closing every process |
|
1249 | #Closing every process | |
1226 | for procKey in keyList: |
|
1250 | for procKey in keyList: | |
1227 | procUnitConfObj = self.procUnitConfObjDict[procKey] |
|
1251 | procUnitConfObj = self.procUnitConfObjDict[procKey] | |
1228 | procUnitConfObj.close() |
|
1252 | procUnitConfObj.close() | |
1229 |
|
1253 | |||
1230 | print "Process finished" |
|
1254 | print "Process finished" | |
1231 |
|
1255 | |||
1232 | def start(self): |
|
1256 | def start(self): | |
1233 |
|
1257 | |||
1234 | self.writeXml() |
|
1258 | self.writeXml() | |
1235 |
|
||||
1236 | self.createObjects() |
|
1259 | self.createObjects() | |
1237 | self.connectObjects() |
|
1260 | self.connectObjects() | |
1238 | self.run() |
|
1261 | self.run() | |
1239 |
|
||||
1240 | if __name__ == '__main__': |
|
|||
1241 |
|
||||
1242 | desc = "Segundo Test" |
|
|||
1243 | filename = "schain.xml" |
|
|||
1244 |
|
||||
1245 | controllerObj = Project() |
|
|||
1246 |
|
||||
1247 | controllerObj.setup(id = '191', name='test01', description=desc) |
|
|||
1248 |
|
||||
1249 | readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage', |
|
|||
1250 | path='data/rawdata/', |
|
|||
1251 | startDate='2011/01/01', |
|
|||
1252 | endDate='2012/12/31', |
|
|||
1253 | startTime='00:00:00', |
|
|||
1254 | endTime='23:59:59', |
|
|||
1255 | online=1, |
|
|||
1256 | walk=1) |
|
|||
1257 |
|
||||
1258 | procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) |
|
|||
1259 |
|
||||
1260 | opObj10 = procUnitConfObj0.addOperation(name='selectChannels') |
|
|||
1261 | opObj10.addParameter(name='channelList', value='3,4,5', format='intlist') |
|
|||
1262 |
|
||||
1263 | opObj10 = procUnitConfObj0.addOperation(name='selectHeights') |
|
|||
1264 | opObj10.addParameter(name='minHei', value='90', format='float') |
|
|||
1265 | opObj10.addParameter(name='maxHei', value='180', format='float') |
|
|||
1266 |
|
||||
1267 | opObj12 = procUnitConfObj0.addOperation(name='CohInt', optype='external') |
|
|||
1268 | opObj12.addParameter(name='n', value='10', format='int') |
|
|||
1269 |
|
||||
1270 | procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId()) |
|
|||
1271 | procUnitConfObj1.addParameter(name='nFFTPoints', value='32', format='int') |
|
|||
1272 | # procUnitConfObj1.addParameter(name='pairList', value='(0,1),(0,2),(1,2)', format='') |
|
|||
1273 |
|
||||
1274 |
|
||||
1275 | opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='external') |
|
|||
1276 | opObj11.addParameter(name='idfigure', value='1', format='int') |
|
|||
1277 | opObj11.addParameter(name='wintitle', value='SpectraPlot0', format='str') |
|
|||
1278 | opObj11.addParameter(name='zmin', value='40', format='int') |
|
|||
1279 | opObj11.addParameter(name='zmax', value='90', format='int') |
|
|||
1280 | opObj11.addParameter(name='showprofile', value='1', format='int') |
|
|||
1281 |
|
||||
1282 | print "Escribiendo el archivo XML" |
|
|||
1283 |
|
||||
1284 | controllerObj.writeXml(filename) |
|
|||
1285 |
|
||||
1286 | print "Leyendo el archivo XML" |
|
|||
1287 | controllerObj.readXml(filename) |
|
|||
1288 | #controllerObj.printattr() |
|
|||
1289 |
|
||||
1290 | controllerObj.createObjects() |
|
|||
1291 | controllerObj.connectObjects() |
|
|||
1292 | controllerObj.run() |
|
|||
1293 |
|
||||
1294 | No newline at end of file |
|
This diff has been collapsed as it changes many lines, (937 lines changed) Show them Hide them | |||||
@@ -13,7 +13,7 from schainpy import cSchain | |||||
13 |
|
13 | |||
14 |
|
14 | |||
15 | def getNumpyDtype(dataTypeCode): |
|
15 | def getNumpyDtype(dataTypeCode): | |
16 |
|
16 | |||
17 | if dataTypeCode == 0: |
|
17 | if dataTypeCode == 0: | |
18 | numpyDtype = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
18 | numpyDtype = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
19 | elif dataTypeCode == 1: |
|
19 | elif dataTypeCode == 1: | |
@@ -28,11 +28,11 def getNumpyDtype(dataTypeCode): | |||||
28 | numpyDtype = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
28 | numpyDtype = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
29 | else: |
|
29 | else: | |
30 | raise ValueError, 'dataTypeCode was not defined' |
|
30 | raise ValueError, 'dataTypeCode was not defined' | |
31 |
|
31 | |||
32 | return numpyDtype |
|
32 | return numpyDtype | |
33 |
|
33 | |||
34 | def getDataTypeCode(numpyDtype): |
|
34 | def getDataTypeCode(numpyDtype): | |
35 |
|
35 | |||
36 | if numpyDtype == numpy.dtype([('real','<i1'),('imag','<i1')]): |
|
36 | if numpyDtype == numpy.dtype([('real','<i1'),('imag','<i1')]): | |
37 | datatype = 0 |
|
37 | datatype = 0 | |
38 | elif numpyDtype == numpy.dtype([('real','<i2'),('imag','<i2')]): |
|
38 | elif numpyDtype == numpy.dtype([('real','<i2'),('imag','<i2')]): | |
@@ -47,45 +47,45 def getDataTypeCode(numpyDtype): | |||||
47 | datatype = 5 |
|
47 | datatype = 5 | |
48 | else: |
|
48 | else: | |
49 | datatype = None |
|
49 | datatype = None | |
50 |
|
50 | |||
51 | return datatype |
|
51 | return datatype | |
52 |
|
52 | |||
53 | def hildebrand_sekhon(data, navg): |
|
53 | def hildebrand_sekhon(data, navg): | |
54 | """ |
|
54 | """ | |
55 |
This method is for the objective determination of the noise level in Doppler spectra. This |
|
55 | This method is for the objective determination of the noise level in Doppler spectra. This | |
56 |
implementation technique is based on the fact that the standard deviation of the spectral |
|
56 | implementation technique is based on the fact that the standard deviation of the spectral | |
57 | densities is equal to the mean spectral density for white Gaussian noise |
|
57 | densities is equal to the mean spectral density for white Gaussian noise | |
58 |
|
58 | |||
59 | Inputs: |
|
59 | Inputs: | |
60 | Data : heights |
|
60 | Data : heights | |
61 | navg : numbers of averages |
|
61 | navg : numbers of averages | |
62 |
|
62 | |||
63 | Return: |
|
63 | Return: | |
64 | -1 : any error |
|
64 | -1 : any error | |
65 | anoise : noise's level |
|
65 | anoise : noise's level | |
66 | """ |
|
66 | """ | |
67 |
|
67 | |||
68 | sortdata = numpy.sort(data,axis=None) |
|
68 | sortdata = numpy.sort(data,axis=None) | |
69 | # lenOfData = len(sortdata) |
|
69 | # lenOfData = len(sortdata) | |
70 | # nums_min = lenOfData*0.2 |
|
70 | # nums_min = lenOfData*0.2 | |
71 | # |
|
71 | # | |
72 | # if nums_min <= 5: |
|
72 | # if nums_min <= 5: | |
73 | # nums_min = 5 |
|
73 | # nums_min = 5 | |
74 |
# |
|
74 | # | |
75 | # sump = 0. |
|
75 | # sump = 0. | |
76 | # |
|
76 | # | |
77 | # sumq = 0. |
|
77 | # sumq = 0. | |
78 | # |
|
78 | # | |
79 | # j = 0 |
|
79 | # j = 0 | |
80 | # |
|
80 | # | |
81 | # cont = 1 |
|
81 | # cont = 1 | |
82 | # |
|
82 | # | |
83 | # while((cont==1)and(j<lenOfData)): |
|
83 | # while((cont==1)and(j<lenOfData)): | |
84 | # |
|
84 | # | |
85 | # sump += sortdata[j] |
|
85 | # sump += sortdata[j] | |
86 | # |
|
86 | # | |
87 | # sumq += sortdata[j]**2 |
|
87 | # sumq += sortdata[j]**2 | |
88 | # |
|
88 | # | |
89 | # if j > nums_min: |
|
89 | # if j > nums_min: | |
90 | # rtest = float(j)/(j-1) + 1.0/navg |
|
90 | # rtest = float(j)/(j-1) + 1.0/navg | |
91 | # if ((sumq*j) > (rtest*sump**2)): |
|
91 | # if ((sumq*j) > (rtest*sump**2)): | |
@@ -93,288 +93,288 def hildebrand_sekhon(data, navg): | |||||
93 | # sump = sump - sortdata[j] |
|
93 | # sump = sump - sortdata[j] | |
94 | # sumq = sumq - sortdata[j]**2 |
|
94 | # sumq = sumq - sortdata[j]**2 | |
95 | # cont = 0 |
|
95 | # cont = 0 | |
96 | # |
|
96 | # | |
97 | # j += 1 |
|
97 | # j += 1 | |
98 | # |
|
98 | # | |
99 | # lnoise = sump /j |
|
99 | # lnoise = sump /j | |
100 |
# |
|
100 | # | |
101 | # return lnoise |
|
101 | # return lnoise | |
102 |
|
102 | |||
103 | return cSchain.hildebrand_sekhon(sortdata, navg) |
|
103 | return cSchain.hildebrand_sekhon(sortdata, navg) | |
104 |
|
104 | |||
105 |
|
105 | |||
106 | class Beam: |
|
106 | class Beam: | |
107 |
|
107 | |||
108 | def __init__(self): |
|
108 | def __init__(self): | |
109 | self.codeList = [] |
|
109 | self.codeList = [] | |
110 | self.azimuthList = [] |
|
110 | self.azimuthList = [] | |
111 |
self.zenithList = [] |
|
111 | self.zenithList = [] | |
112 |
|
112 | |||
113 | class GenericData(object): |
|
113 | class GenericData(object): | |
114 |
|
114 | |||
115 | flagNoData = True |
|
115 | flagNoData = True | |
116 |
|
116 | |||
117 | def __init__(self): |
|
117 | def __init__(self): | |
118 |
|
118 | |||
119 | raise NotImplementedError |
|
119 | raise NotImplementedError | |
120 |
|
120 | |||
121 | def copy(self, inputObj=None): |
|
121 | def copy(self, inputObj=None): | |
122 |
|
122 | |||
123 | if inputObj == None: |
|
123 | if inputObj == None: | |
124 | return copy.deepcopy(self) |
|
124 | return copy.deepcopy(self) | |
125 |
|
125 | |||
126 | for key in inputObj.__dict__.keys(): |
|
126 | for key in inputObj.__dict__.keys(): | |
127 |
|
127 | |||
128 | attribute = inputObj.__dict__[key] |
|
128 | attribute = inputObj.__dict__[key] | |
129 |
|
129 | |||
130 | #If this attribute is a tuple or list |
|
130 | #If this attribute is a tuple or list | |
131 | if type(inputObj.__dict__[key]) in (tuple, list): |
|
131 | if type(inputObj.__dict__[key]) in (tuple, list): | |
132 | self.__dict__[key] = attribute[:] |
|
132 | self.__dict__[key] = attribute[:] | |
133 | continue |
|
133 | continue | |
134 |
|
134 | |||
135 | #If this attribute is another object or instance |
|
135 | #If this attribute is another object or instance | |
136 | if hasattr(attribute, '__dict__'): |
|
136 | if hasattr(attribute, '__dict__'): | |
137 | self.__dict__[key] = attribute.copy() |
|
137 | self.__dict__[key] = attribute.copy() | |
138 | continue |
|
138 | continue | |
139 |
|
139 | |||
140 | self.__dict__[key] = inputObj.__dict__[key] |
|
140 | self.__dict__[key] = inputObj.__dict__[key] | |
141 |
|
141 | |||
142 | def deepcopy(self): |
|
142 | def deepcopy(self): | |
143 |
|
143 | |||
144 | return copy.deepcopy(self) |
|
144 | return copy.deepcopy(self) | |
145 |
|
145 | |||
146 | def isEmpty(self): |
|
146 | def isEmpty(self): | |
147 |
|
147 | |||
148 | return self.flagNoData |
|
148 | return self.flagNoData | |
149 |
|
149 | |||
150 | class JROData(GenericData): |
|
150 | class JROData(GenericData): | |
151 |
|
151 | |||
152 | # m_BasicHeader = BasicHeader() |
|
152 | # m_BasicHeader = BasicHeader() | |
153 | # m_ProcessingHeader = ProcessingHeader() |
|
153 | # m_ProcessingHeader = ProcessingHeader() | |
154 |
|
154 | |||
155 | systemHeaderObj = SystemHeader() |
|
155 | systemHeaderObj = SystemHeader() | |
156 |
|
156 | |||
157 | radarControllerHeaderObj = RadarControllerHeader() |
|
157 | radarControllerHeaderObj = RadarControllerHeader() | |
158 |
|
158 | |||
159 | # data = None |
|
159 | # data = None | |
160 |
|
160 | |||
161 | type = None |
|
161 | type = None | |
162 |
|
162 | |||
163 | datatype = None #dtype but in string |
|
163 | datatype = None #dtype but in string | |
164 |
|
164 | |||
165 | # dtype = None |
|
165 | # dtype = None | |
166 |
|
166 | |||
167 | # nChannels = None |
|
167 | # nChannels = None | |
168 |
|
168 | |||
169 | # nHeights = None |
|
169 | # nHeights = None | |
170 |
|
170 | |||
171 | nProfiles = None |
|
171 | nProfiles = None | |
172 |
|
172 | |||
173 | heightList = None |
|
173 | heightList = None | |
174 |
|
174 | |||
175 | channelList = None |
|
175 | channelList = None | |
176 |
|
176 | |||
177 | flagDiscontinuousBlock = False |
|
177 | flagDiscontinuousBlock = False | |
178 |
|
178 | |||
179 | useLocalTime = False |
|
179 | useLocalTime = False | |
180 |
|
180 | |||
181 | utctime = None |
|
181 | utctime = None | |
182 |
|
182 | |||
183 | timeZone = None |
|
183 | timeZone = None | |
184 |
|
184 | |||
185 | dstFlag = None |
|
185 | dstFlag = None | |
186 |
|
186 | |||
187 | errorCount = None |
|
187 | errorCount = None | |
188 |
|
188 | |||
189 | blocksize = None |
|
189 | blocksize = None | |
190 |
|
190 | |||
191 | # nCode = None |
|
191 | # nCode = None | |
192 | # |
|
192 | # | |
193 | # nBaud = None |
|
193 | # nBaud = None | |
194 | # |
|
194 | # | |
195 | # code = None |
|
195 | # code = None | |
196 |
|
196 | |||
197 | flagDecodeData = False #asumo q la data no esta decodificada |
|
197 | flagDecodeData = False #asumo q la data no esta decodificada | |
198 |
|
198 | |||
199 | flagDeflipData = False #asumo q la data no esta sin flip |
|
199 | flagDeflipData = False #asumo q la data no esta sin flip | |
200 |
|
200 | |||
201 | flagShiftFFT = False |
|
201 | flagShiftFFT = False | |
202 |
|
202 | |||
203 | # ippSeconds = None |
|
203 | # ippSeconds = None | |
204 |
|
204 | |||
205 | # timeInterval = None |
|
205 | # timeInterval = None | |
206 |
|
206 | |||
207 | nCohInt = None |
|
207 | nCohInt = None | |
208 |
|
208 | |||
209 | # noise = None |
|
209 | # noise = None | |
210 |
|
210 | |||
211 | windowOfFilter = 1 |
|
211 | windowOfFilter = 1 | |
212 |
|
212 | |||
213 | #Speed of ligth |
|
213 | #Speed of ligth | |
214 | C = 3e8 |
|
214 | C = 3e8 | |
215 |
|
215 | |||
216 | frequency = 49.92e6 |
|
216 | frequency = 49.92e6 | |
217 |
|
217 | |||
218 | realtime = False |
|
218 | realtime = False | |
219 |
|
219 | |||
220 | beacon_heiIndexList = None |
|
220 | beacon_heiIndexList = None | |
221 |
|
221 | |||
222 | last_block = None |
|
222 | last_block = None | |
223 |
|
223 | |||
224 | blocknow = None |
|
224 | blocknow = None | |
225 |
|
225 | |||
226 | azimuth = None |
|
226 | azimuth = None | |
227 |
|
227 | |||
228 | zenith = None |
|
228 | zenith = None | |
229 |
|
229 | |||
230 | beam = Beam() |
|
230 | beam = Beam() | |
231 |
|
231 | |||
232 | profileIndex = None |
|
232 | profileIndex = None | |
233 |
|
233 | |||
234 | def __init__(self): |
|
234 | def __init__(self): | |
235 |
|
235 | |||
236 | raise NotImplementedError |
|
236 | raise NotImplementedError | |
237 |
|
237 | |||
238 | def getNoise(self): |
|
238 | def getNoise(self): | |
239 |
|
239 | |||
240 | raise NotImplementedError |
|
240 | raise NotImplementedError | |
241 |
|
241 | |||
242 | def getNChannels(self): |
|
242 | def getNChannels(self): | |
243 |
|
243 | |||
244 | return len(self.channelList) |
|
244 | return len(self.channelList) | |
245 |
|
245 | |||
246 | def getChannelIndexList(self): |
|
246 | def getChannelIndexList(self): | |
247 |
|
247 | |||
248 | return range(self.nChannels) |
|
248 | return range(self.nChannels) | |
249 |
|
249 | |||
250 | def getNHeights(self): |
|
250 | def getNHeights(self): | |
251 |
|
251 | |||
252 | return len(self.heightList) |
|
252 | return len(self.heightList) | |
253 |
|
253 | |||
254 | def getHeiRange(self, extrapoints=0): |
|
254 | def getHeiRange(self, extrapoints=0): | |
255 |
|
255 | |||
256 | heis = self.heightList |
|
256 | heis = self.heightList | |
257 | # deltah = self.heightList[1] - self.heightList[0] |
|
257 | # deltah = self.heightList[1] - self.heightList[0] | |
258 | # |
|
258 | # | |
259 | # heis.append(self.heightList[-1]) |
|
259 | # heis.append(self.heightList[-1]) | |
260 |
|
260 | |||
261 | return heis |
|
261 | return heis | |
262 |
|
262 | |||
263 | def getDeltaH(self): |
|
263 | def getDeltaH(self): | |
264 |
|
264 | |||
265 | delta = self.heightList[1] - self.heightList[0] |
|
265 | delta = self.heightList[1] - self.heightList[0] | |
266 |
|
266 | |||
267 | return delta |
|
267 | return delta | |
268 |
|
268 | |||
269 | def getltctime(self): |
|
269 | def getltctime(self): | |
270 |
|
270 | |||
271 | if self.useLocalTime: |
|
271 | if self.useLocalTime: | |
272 | return self.utctime - self.timeZone*60 |
|
272 | return self.utctime - self.timeZone*60 | |
273 |
|
273 | |||
274 | return self.utctime |
|
274 | return self.utctime | |
275 |
|
275 | |||
276 | def getDatatime(self): |
|
276 | def getDatatime(self): | |
277 |
|
277 | |||
278 | datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime) |
|
278 | datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime) | |
279 | return datatimeValue |
|
279 | return datatimeValue | |
280 |
|
280 | |||
281 | def getTimeRange(self): |
|
281 | def getTimeRange(self): | |
282 |
|
282 | |||
283 | datatime = [] |
|
283 | datatime = [] | |
284 |
|
284 | |||
285 | datatime.append(self.ltctime) |
|
285 | datatime.append(self.ltctime) | |
286 | datatime.append(self.ltctime + self.timeInterval+1) |
|
286 | datatime.append(self.ltctime + self.timeInterval+1) | |
287 |
|
287 | |||
288 | datatime = numpy.array(datatime) |
|
288 | datatime = numpy.array(datatime) | |
289 |
|
289 | |||
290 | return datatime |
|
290 | return datatime | |
291 |
|
291 | |||
292 | def getFmaxTimeResponse(self): |
|
292 | def getFmaxTimeResponse(self): | |
293 |
|
293 | |||
294 | period = (10**-6)*self.getDeltaH()/(0.15) |
|
294 | period = (10**-6)*self.getDeltaH()/(0.15) | |
295 |
|
295 | |||
296 | PRF = 1./(period * self.nCohInt) |
|
296 | PRF = 1./(period * self.nCohInt) | |
297 |
|
297 | |||
298 | fmax = PRF |
|
298 | fmax = PRF | |
299 |
|
299 | |||
300 | return fmax |
|
300 | return fmax | |
301 |
|
301 | |||
302 | def getFmax(self): |
|
302 | def getFmax(self): | |
303 |
|
303 | |||
304 | PRF = 1./(self.ippSeconds * self.nCohInt) |
|
304 | PRF = 1./(self.ippSeconds * self.nCohInt) | |
305 |
|
305 | |||
306 | fmax = PRF |
|
306 | fmax = PRF | |
307 |
|
307 | |||
308 | return fmax |
|
308 | return fmax | |
309 |
|
309 | |||
310 | def getVmax(self): |
|
310 | def getVmax(self): | |
311 |
|
311 | |||
312 | _lambda = self.C/self.frequency |
|
312 | _lambda = self.C/self.frequency | |
313 |
|
313 | |||
314 | vmax = self.getFmax() * _lambda/2 |
|
314 | vmax = self.getFmax() * _lambda/2 | |
315 |
|
315 | |||
316 | return vmax |
|
316 | return vmax | |
317 |
|
317 | |||
318 | def get_ippSeconds(self): |
|
318 | def get_ippSeconds(self): | |
319 | ''' |
|
319 | ''' | |
320 | ''' |
|
320 | ''' | |
321 | return self.radarControllerHeaderObj.ippSeconds |
|
321 | return self.radarControllerHeaderObj.ippSeconds | |
322 |
|
322 | |||
323 | def set_ippSeconds(self, ippSeconds): |
|
323 | def set_ippSeconds(self, ippSeconds): | |
324 | ''' |
|
324 | ''' | |
325 | ''' |
|
325 | ''' | |
326 |
|
326 | |||
327 | self.radarControllerHeaderObj.ippSeconds = ippSeconds |
|
327 | self.radarControllerHeaderObj.ippSeconds = ippSeconds | |
328 |
|
328 | |||
329 | return |
|
329 | return | |
330 |
|
330 | |||
331 | def get_dtype(self): |
|
331 | def get_dtype(self): | |
332 | ''' |
|
332 | ''' | |
333 | ''' |
|
333 | ''' | |
334 | return getNumpyDtype(self.datatype) |
|
334 | return getNumpyDtype(self.datatype) | |
335 |
|
335 | |||
336 | def set_dtype(self, numpyDtype): |
|
336 | def set_dtype(self, numpyDtype): | |
337 | ''' |
|
337 | ''' | |
338 | ''' |
|
338 | ''' | |
339 |
|
339 | |||
340 | self.datatype = getDataTypeCode(numpyDtype) |
|
340 | self.datatype = getDataTypeCode(numpyDtype) | |
341 |
|
341 | |||
342 | def get_code(self): |
|
342 | def get_code(self): | |
343 | ''' |
|
343 | ''' | |
344 | ''' |
|
344 | ''' | |
345 | return self.radarControllerHeaderObj.code |
|
345 | return self.radarControllerHeaderObj.code | |
346 |
|
346 | |||
347 | def set_code(self, code): |
|
347 | def set_code(self, code): | |
348 | ''' |
|
348 | ''' | |
349 | ''' |
|
349 | ''' | |
350 | self.radarControllerHeaderObj.code = code |
|
350 | self.radarControllerHeaderObj.code = code | |
351 |
|
351 | |||
352 | return |
|
352 | return | |
353 |
|
353 | |||
354 | def get_ncode(self): |
|
354 | def get_ncode(self): | |
355 | ''' |
|
355 | ''' | |
356 | ''' |
|
356 | ''' | |
357 | return self.radarControllerHeaderObj.nCode |
|
357 | return self.radarControllerHeaderObj.nCode | |
358 |
|
358 | |||
359 | def set_ncode(self, nCode): |
|
359 | def set_ncode(self, nCode): | |
360 | ''' |
|
360 | ''' | |
361 | ''' |
|
361 | ''' | |
362 | self.radarControllerHeaderObj.nCode = nCode |
|
362 | self.radarControllerHeaderObj.nCode = nCode | |
363 |
|
363 | |||
364 | return |
|
364 | return | |
365 |
|
365 | |||
366 | def get_nbaud(self): |
|
366 | def get_nbaud(self): | |
367 | ''' |
|
367 | ''' | |
368 | ''' |
|
368 | ''' | |
369 | return self.radarControllerHeaderObj.nBaud |
|
369 | return self.radarControllerHeaderObj.nBaud | |
370 |
|
370 | |||
371 | def set_nbaud(self, nBaud): |
|
371 | def set_nbaud(self, nBaud): | |
372 | ''' |
|
372 | ''' | |
373 | ''' |
|
373 | ''' | |
374 | self.radarControllerHeaderObj.nBaud = nBaud |
|
374 | self.radarControllerHeaderObj.nBaud = nBaud | |
375 |
|
375 | |||
376 | return |
|
376 | return | |
377 |
|
377 | |||
378 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") |
|
378 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") | |
379 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") |
|
379 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") | |
380 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") |
|
380 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") | |
@@ -387,71 +387,71 class JROData(GenericData): | |||||
387 | code = property(get_code, set_code) |
|
387 | code = property(get_code, set_code) | |
388 | nCode = property(get_ncode, set_ncode) |
|
388 | nCode = property(get_ncode, set_ncode) | |
389 | nBaud = property(get_nbaud, set_nbaud) |
|
389 | nBaud = property(get_nbaud, set_nbaud) | |
390 |
|
390 | |||
391 | class Voltage(JROData): |
|
391 | class Voltage(JROData): | |
392 |
|
392 | |||
393 | #data es un numpy array de 2 dmensiones (canales, alturas) |
|
393 | #data es un numpy array de 2 dmensiones (canales, alturas) | |
394 | data = None |
|
394 | data = None | |
395 |
|
395 | |||
396 | def __init__(self): |
|
396 | def __init__(self): | |
397 | ''' |
|
397 | ''' | |
398 | Constructor |
|
398 | Constructor | |
399 | ''' |
|
399 | ''' | |
400 |
|
400 | |||
401 | self.useLocalTime = True |
|
401 | self.useLocalTime = True | |
402 |
|
402 | |||
403 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
403 | self.radarControllerHeaderObj = RadarControllerHeader() | |
404 |
|
404 | |||
405 | self.systemHeaderObj = SystemHeader() |
|
405 | self.systemHeaderObj = SystemHeader() | |
406 |
|
406 | |||
407 | self.type = "Voltage" |
|
407 | self.type = "Voltage" | |
408 |
|
408 | |||
409 | self.data = None |
|
409 | self.data = None | |
410 |
|
410 | |||
411 | # self.dtype = None |
|
411 | # self.dtype = None | |
412 |
|
412 | |||
413 | # self.nChannels = 0 |
|
413 | # self.nChannels = 0 | |
414 |
|
414 | |||
415 | # self.nHeights = 0 |
|
415 | # self.nHeights = 0 | |
416 |
|
416 | |||
417 | self.nProfiles = None |
|
417 | self.nProfiles = None | |
418 |
|
418 | |||
419 | self.heightList = None |
|
419 | self.heightList = None | |
420 |
|
420 | |||
421 | self.channelList = None |
|
421 | self.channelList = None | |
422 |
|
422 | |||
423 | # self.channelIndexList = None |
|
423 | # self.channelIndexList = None | |
424 |
|
424 | |||
425 | self.flagNoData = True |
|
425 | self.flagNoData = True | |
426 |
|
426 | |||
427 | self.flagDiscontinuousBlock = False |
|
427 | self.flagDiscontinuousBlock = False | |
428 |
|
428 | |||
429 | self.utctime = None |
|
429 | self.utctime = None | |
430 |
|
430 | |||
431 | self.timeZone = None |
|
431 | self.timeZone = None | |
432 |
|
432 | |||
433 | self.dstFlag = None |
|
433 | self.dstFlag = None | |
434 |
|
434 | |||
435 | self.errorCount = None |
|
435 | self.errorCount = None | |
436 |
|
436 | |||
437 | self.nCohInt = None |
|
437 | self.nCohInt = None | |
438 |
|
438 | |||
439 | self.blocksize = None |
|
439 | self.blocksize = None | |
440 |
|
440 | |||
441 | self.flagDecodeData = False #asumo q la data no esta decodificada |
|
441 | self.flagDecodeData = False #asumo q la data no esta decodificada | |
442 |
|
442 | |||
443 | self.flagDeflipData = False #asumo q la data no esta sin flip |
|
443 | self.flagDeflipData = False #asumo q la data no esta sin flip | |
444 |
|
444 | |||
445 | self.flagShiftFFT = False |
|
445 | self.flagShiftFFT = False | |
446 |
|
446 | |||
447 | self.flagDataAsBlock = False #Asumo que la data es leida perfil a perfil |
|
447 | self.flagDataAsBlock = False #Asumo que la data es leida perfil a perfil | |
448 |
|
448 | |||
449 | self.profileIndex = 0 |
|
449 | self.profileIndex = 0 | |
450 |
|
450 | |||
451 | def getNoisebyHildebrand(self, channel = None): |
|
451 | def getNoisebyHildebrand(self, channel = None): | |
452 | """ |
|
452 | """ | |
453 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
|
453 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon | |
454 |
|
454 | |||
455 | Return: |
|
455 | Return: | |
456 | noiselevel |
|
456 | noiselevel | |
457 | """ |
|
457 | """ | |
@@ -462,248 +462,275 class Voltage(JROData): | |||||
462 | else: |
|
462 | else: | |
463 | data = self.data |
|
463 | data = self.data | |
464 | nChannels = self.nChannels |
|
464 | nChannels = self.nChannels | |
465 |
|
465 | |||
466 | noise = numpy.zeros(nChannels) |
|
466 | noise = numpy.zeros(nChannels) | |
467 | power = data * numpy.conjugate(data) |
|
467 | power = data * numpy.conjugate(data) | |
468 |
|
468 | |||
469 | for thisChannel in range(nChannels): |
|
469 | for thisChannel in range(nChannels): | |
470 | if nChannels == 1: |
|
470 | if nChannels == 1: | |
471 | daux = power[:].real |
|
471 | daux = power[:].real | |
472 | else: |
|
472 | else: | |
473 | daux = power[thisChannel,:].real |
|
473 | daux = power[thisChannel,:].real | |
474 | noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt) |
|
474 | noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt) | |
475 |
|
475 | |||
476 | return noise |
|
476 | return noise | |
477 |
|
477 | |||
478 | def getNoise(self, type = 1, channel = None): |
|
478 | def getNoise(self, type = 1, channel = None): | |
479 |
|
479 | |||
480 | if type == 1: |
|
480 | if type == 1: | |
481 | noise = self.getNoisebyHildebrand(channel) |
|
481 | noise = self.getNoisebyHildebrand(channel) | |
482 |
|
482 | |||
483 | return noise |
|
483 | return noise | |
484 |
|
484 | |||
485 | def getPower(self, channel = None): |
|
485 | def getPower(self, channel = None): | |
486 |
|
486 | |||
487 | if channel != None: |
|
487 | if channel != None: | |
488 | data = self.data[channel] |
|
488 | data = self.data[channel] | |
489 | else: |
|
489 | else: | |
490 | data = self.data |
|
490 | data = self.data | |
491 |
|
491 | |||
492 | power = data * numpy.conjugate(data) |
|
492 | power = data * numpy.conjugate(data) | |
493 | powerdB = 10*numpy.log10(power.real) |
|
493 | powerdB = 10*numpy.log10(power.real) | |
494 | powerdB = numpy.squeeze(powerdB) |
|
494 | powerdB = numpy.squeeze(powerdB) | |
495 |
|
495 | |||
496 | return powerdB |
|
496 | return powerdB | |
497 |
|
497 | |||
498 | def getTimeInterval(self): |
|
498 | def getTimeInterval(self): | |
499 |
|
499 | |||
500 | timeInterval = self.ippSeconds * self.nCohInt |
|
500 | timeInterval = self.ippSeconds * self.nCohInt | |
501 |
|
501 | |||
502 | return timeInterval |
|
502 | return timeInterval | |
503 |
|
503 | |||
504 | noise = property(getNoise, "I'm the 'nHeights' property.") |
|
504 | noise = property(getNoise, "I'm the 'nHeights' property.") | |
505 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
505 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") | |
506 |
|
506 | |||
507 | class Spectra(JROData): |
|
507 | class Spectra(JROData): | |
508 |
|
508 | |||
509 | #data spc es un numpy array de 2 dmensiones (canales, perfiles, alturas) |
|
509 | #data spc es un numpy array de 2 dmensiones (canales, perfiles, alturas) | |
510 | data_spc = None |
|
510 | data_spc = None | |
511 |
|
511 | |||
512 | #data cspc es un numpy array de 2 dmensiones (canales, pares, alturas) |
|
512 | #data cspc es un numpy array de 2 dmensiones (canales, pares, alturas) | |
513 | data_cspc = None |
|
513 | data_cspc = None | |
514 |
|
514 | |||
515 | #data dc es un numpy array de 2 dmensiones (canales, alturas) |
|
515 | #data dc es un numpy array de 2 dmensiones (canales, alturas) | |
516 | data_dc = None |
|
516 | data_dc = None | |
517 |
|
517 | |||
518 | #data power |
|
518 | #data power | |
519 | data_pwr = None |
|
519 | data_pwr = None | |
520 |
|
520 | |||
521 | nFFTPoints = None |
|
521 | nFFTPoints = None | |
522 |
|
522 | |||
523 | # nPairs = None |
|
523 | # nPairs = None | |
524 |
|
524 | |||
525 | pairsList = None |
|
525 | pairsList = None | |
526 |
|
526 | |||
527 | nIncohInt = None |
|
527 | nIncohInt = None | |
528 |
|
528 | |||
529 | wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia |
|
529 | wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia | |
530 |
|
530 | |||
531 | nCohInt = None #se requiere para determinar el valor de timeInterval |
|
531 | nCohInt = None #se requiere para determinar el valor de timeInterval | |
532 |
|
532 | |||
533 | ippFactor = None |
|
533 | ippFactor = None | |
534 |
|
534 | |||
535 | profileIndex = 0 |
|
535 | profileIndex = 0 | |
536 |
|
536 | |||
537 | plotting = "spectra" |
|
537 | plotting = "spectra" | |
538 |
|
538 | |||
539 | def __init__(self): |
|
539 | def __init__(self): | |
540 | ''' |
|
540 | ''' | |
541 | Constructor |
|
541 | Constructor | |
542 | ''' |
|
542 | ''' | |
543 |
|
543 | |||
544 | self.useLocalTime = True |
|
544 | self.useLocalTime = True | |
545 |
|
545 | |||
546 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
546 | self.radarControllerHeaderObj = RadarControllerHeader() | |
547 |
|
547 | |||
548 | self.systemHeaderObj = SystemHeader() |
|
548 | self.systemHeaderObj = SystemHeader() | |
549 |
|
549 | |||
550 | self.type = "Spectra" |
|
550 | self.type = "Spectra" | |
551 |
|
551 | |||
552 | # self.data = None |
|
552 | # self.data = None | |
553 |
|
553 | |||
554 | # self.dtype = None |
|
554 | # self.dtype = None | |
555 |
|
555 | |||
556 | # self.nChannels = 0 |
|
556 | # self.nChannels = 0 | |
557 |
|
557 | |||
558 | # self.nHeights = 0 |
|
558 | # self.nHeights = 0 | |
559 |
|
559 | |||
560 | self.nProfiles = None |
|
560 | self.nProfiles = None | |
561 |
|
561 | |||
562 | self.heightList = None |
|
562 | self.heightList = None | |
563 |
|
563 | |||
564 | self.channelList = None |
|
564 | self.channelList = None | |
565 |
|
565 | |||
566 | # self.channelIndexList = None |
|
566 | # self.channelIndexList = None | |
567 |
|
567 | |||
568 | self.pairsList = None |
|
568 | self.pairsList = None | |
569 |
|
569 | |||
570 | self.flagNoData = True |
|
570 | self.flagNoData = True | |
571 |
|
571 | |||
572 | self.flagDiscontinuousBlock = False |
|
572 | self.flagDiscontinuousBlock = False | |
573 |
|
573 | |||
574 | self.utctime = None |
|
574 | self.utctime = None | |
575 |
|
575 | |||
576 | self.nCohInt = None |
|
576 | self.nCohInt = None | |
577 |
|
577 | |||
578 | self.nIncohInt = None |
|
578 | self.nIncohInt = None | |
579 |
|
579 | |||
580 | self.blocksize = None |
|
580 | self.blocksize = None | |
581 |
|
581 | |||
582 | self.nFFTPoints = None |
|
582 | self.nFFTPoints = None | |
583 |
|
583 | |||
584 | self.wavelength = None |
|
584 | self.wavelength = None | |
585 |
|
585 | |||
586 | self.flagDecodeData = False #asumo q la data no esta decodificada |
|
586 | self.flagDecodeData = False #asumo q la data no esta decodificada | |
587 |
|
587 | |||
588 | self.flagDeflipData = False #asumo q la data no esta sin flip |
|
588 | self.flagDeflipData = False #asumo q la data no esta sin flip | |
589 |
|
589 | |||
590 | self.flagShiftFFT = False |
|
590 | self.flagShiftFFT = False | |
591 |
|
591 | |||
592 | self.ippFactor = 1 |
|
592 | self.ippFactor = 1 | |
593 |
|
593 | |||
594 | #self.noise = None |
|
594 | #self.noise = None | |
595 |
|
595 | |||
596 | self.beacon_heiIndexList = [] |
|
596 | self.beacon_heiIndexList = [] | |
597 |
|
597 | |||
598 | self.noise_estimation = None |
|
598 | self.noise_estimation = None | |
599 |
|
599 | |||
600 |
|
600 | |||
601 | def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None): |
|
601 | def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None): | |
602 | """ |
|
602 | """ | |
603 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
|
603 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon | |
604 |
|
604 | |||
605 | Return: |
|
605 | Return: | |
606 | noiselevel |
|
606 | noiselevel | |
607 | """ |
|
607 | """ | |
608 |
|
608 | |||
609 | noise = numpy.zeros(self.nChannels) |
|
609 | noise = numpy.zeros(self.nChannels) | |
610 |
|
610 | |||
611 | for channel in range(self.nChannels): |
|
611 | for channel in range(self.nChannels): | |
612 | daux = self.data_spc[channel,xmin_index:xmax_index,ymin_index:ymax_index] |
|
612 | daux = self.data_spc[channel,xmin_index:xmax_index,ymin_index:ymax_index] | |
613 | noise[channel] = hildebrand_sekhon(daux, self.nIncohInt) |
|
613 | noise[channel] = hildebrand_sekhon(daux, self.nIncohInt) | |
614 |
|
614 | |||
615 |
return noise |
|
615 | return noise | |
616 |
|
616 | |||
617 | def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None): |
|
617 | def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None): | |
618 |
|
618 | |||
619 | if self.noise_estimation is not None: |
|
619 | if self.noise_estimation is not None: | |
620 | return self.noise_estimation #this was estimated by getNoise Operation defined in jroproc_spectra.py |
|
620 | return self.noise_estimation #this was estimated by getNoise Operation defined in jroproc_spectra.py | |
621 | else: |
|
621 | else: | |
622 | noise = self.getNoisebyHildebrand(xmin_index, xmax_index, ymin_index, ymax_index) |
|
622 | noise = self.getNoisebyHildebrand(xmin_index, xmax_index, ymin_index, ymax_index) | |
623 | return noise |
|
623 | return noise | |
624 |
|
624 | |||
625 | def getFreqRangeTimeResponse(self, extrapoints=0): |
|
625 | def getFreqRangeTimeResponse(self, extrapoints=0): | |
626 |
|
626 | |||
627 | deltafreq = self.getFmaxTimeResponse() / (self.nFFTPoints*self.ippFactor) |
|
627 | deltafreq = self.getFmaxTimeResponse() / (self.nFFTPoints*self.ippFactor) | |
628 | freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 |
|
628 | freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 | |
629 |
|
629 | |||
630 | return freqrange |
|
630 | return freqrange | |
631 |
|
631 | |||
632 | def getAcfRange(self, extrapoints=0): |
|
632 | def getAcfRange(self, extrapoints=0): | |
633 |
|
633 | |||
634 | deltafreq = 10./(self.getFmax() / (self.nFFTPoints*self.ippFactor)) |
|
634 | deltafreq = 10./(self.getFmax() / (self.nFFTPoints*self.ippFactor)) | |
635 | freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 |
|
635 | freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 | |
636 |
|
636 | |||
637 | return freqrange |
|
637 | return freqrange | |
638 |
|
638 | |||
639 | def getFreqRange(self, extrapoints=0): |
|
639 | def getFreqRange(self, extrapoints=0): | |
640 |
|
640 | |||
641 | deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor) |
|
641 | deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor) | |
642 | freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 |
|
642 | freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 | |
643 |
|
643 | |||
644 | return freqrange |
|
644 | return freqrange | |
645 |
|
645 | |||
646 | def getVelRange(self, extrapoints=0): |
|
646 | def getVelRange(self, extrapoints=0): | |
647 |
|
647 | |||
648 | deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor) |
|
648 | deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor) | |
649 |
velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) #- deltav/2 |
|
649 | velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) #- deltav/2 | |
650 |
|
650 | |||
651 | return velrange |
|
651 | return velrange | |
652 |
|
652 | |||
653 | def getNPairs(self): |
|
653 | def getNPairs(self): | |
654 |
|
654 | |||
655 | return len(self.pairsList) |
|
655 | return len(self.pairsList) | |
656 |
|
656 | |||
657 | def getPairsIndexList(self): |
|
657 | def getPairsIndexList(self): | |
658 |
|
658 | |||
659 | return range(self.nPairs) |
|
659 | return range(self.nPairs) | |
660 |
|
660 | |||
661 | def getNormFactor(self): |
|
661 | def getNormFactor(self): | |
662 |
|
662 | |||
663 | pwcode = 1 |
|
663 | pwcode = 1 | |
664 |
|
664 | |||
665 | if self.flagDecodeData: |
|
665 | if self.flagDecodeData: | |
666 | pwcode = numpy.sum(self.code[0]**2) |
|
666 | pwcode = numpy.sum(self.code[0]**2) | |
667 | #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter |
|
667 | #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter | |
668 | normFactor = self.nProfiles*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter |
|
668 | normFactor = self.nProfiles*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter | |
669 |
|
669 | |||
670 | return normFactor |
|
670 | return normFactor | |
671 |
|
671 | |||
672 | def getFlagCspc(self): |
|
672 | def getFlagCspc(self): | |
673 |
|
673 | |||
674 | if self.data_cspc is None: |
|
674 | if self.data_cspc is None: | |
675 | return True |
|
675 | return True | |
676 |
|
676 | |||
677 | return False |
|
677 | return False | |
678 |
|
678 | |||
679 | def getFlagDc(self): |
|
679 | def getFlagDc(self): | |
680 |
|
680 | |||
681 | if self.data_dc is None: |
|
681 | if self.data_dc is None: | |
682 | return True |
|
682 | return True | |
683 |
|
683 | |||
684 | return False |
|
684 | return False | |
685 |
|
685 | |||
686 | def getTimeInterval(self): |
|
686 | def getTimeInterval(self): | |
687 |
|
687 | |||
688 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles |
|
688 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles | |
689 |
|
689 | |||
690 | return timeInterval |
|
690 | return timeInterval | |
691 |
|
691 | |||
692 | def getPower(self): |
|
692 | def getPower(self): | |
693 |
|
693 | |||
694 | factor = self.normFactor |
|
694 | factor = self.normFactor | |
695 | z = self.data_spc/factor |
|
695 | z = self.data_spc/factor | |
696 |
z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
696 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
697 | avg = numpy.average(z, axis=1) |
|
697 | avg = numpy.average(z, axis=1) | |
698 |
|
698 | |||
699 | return 10*numpy.log10(avg) |
|
699 | return 10*numpy.log10(avg) | |
700 |
|
700 | |||
|
701 | def getCoherence(self, pairsList=None, phase=False): | |||
|
702 | ||||
|
703 | z = [] | |||
|
704 | if pairsList is None: | |||
|
705 | pairsIndexList = self.pairsIndexList | |||
|
706 | else: | |||
|
707 | pairsIndexList = [] | |||
|
708 | for pair in pairsList: | |||
|
709 | if pair not in self.pairsList: | |||
|
710 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) | |||
|
711 | pairsIndexList.append(self.pairsList.index(pair)) | |||
|
712 | for i in range(len(pairsIndexList)): | |||
|
713 | pair = self.pairsList[pairsIndexList[i]] | |||
|
714 | ccf = numpy.average(self.data_cspc[pairsIndexList[i], :, :], axis=0) | |||
|
715 | powa = numpy.average(self.data_spc[pair[0], :, :], axis=0) | |||
|
716 | powb = numpy.average(self.data_spc[pair[1], :, :], axis=0) | |||
|
717 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) | |||
|
718 | if phase: | |||
|
719 | data = numpy.arctan2(avgcoherenceComplex.imag, | |||
|
720 | avgcoherenceComplex.real)*180/numpy.pi | |||
|
721 | else: | |||
|
722 | data = numpy.abs(avgcoherenceComplex) | |||
|
723 | ||||
|
724 | z.append(data) | |||
|
725 | ||||
|
726 | return numpy.array(z) | |||
|
727 | ||||
701 | def setValue(self, value): |
|
728 | def setValue(self, value): | |
702 |
|
729 | |||
703 | print "This property should not be initialized" |
|
730 | print "This property should not be initialized" | |
704 |
|
731 | |||
705 | return |
|
732 | return | |
706 |
|
733 | |||
707 | nPairs = property(getNPairs, setValue, "I'm the 'nPairs' property.") |
|
734 | nPairs = property(getNPairs, setValue, "I'm the 'nPairs' property.") | |
708 | pairsIndexList = property(getPairsIndexList, setValue, "I'm the 'pairsIndexList' property.") |
|
735 | pairsIndexList = property(getPairsIndexList, setValue, "I'm the 'pairsIndexList' property.") | |
709 | normFactor = property(getNormFactor, setValue, "I'm the 'getNormFactor' property.") |
|
736 | normFactor = property(getNormFactor, setValue, "I'm the 'getNormFactor' property.") | |
@@ -711,141 +738,141 class Spectra(JROData): | |||||
711 | flag_dc = property(getFlagDc, setValue) |
|
738 | flag_dc = property(getFlagDc, setValue) | |
712 | noise = property(getNoise, setValue, "I'm the 'nHeights' property.") |
|
739 | noise = property(getNoise, setValue, "I'm the 'nHeights' property.") | |
713 | timeInterval = property(getTimeInterval, setValue, "I'm the 'timeInterval' property") |
|
740 | timeInterval = property(getTimeInterval, setValue, "I'm the 'timeInterval' property") | |
714 |
|
741 | |||
715 | class SpectraHeis(Spectra): |
|
742 | class SpectraHeis(Spectra): | |
716 |
|
743 | |||
717 | data_spc = None |
|
744 | data_spc = None | |
718 |
|
745 | |||
719 | data_cspc = None |
|
746 | data_cspc = None | |
720 |
|
747 | |||
721 | data_dc = None |
|
748 | data_dc = None | |
722 |
|
749 | |||
723 | nFFTPoints = None |
|
750 | nFFTPoints = None | |
724 |
|
751 | |||
725 | # nPairs = None |
|
752 | # nPairs = None | |
726 |
|
753 | |||
727 | pairsList = None |
|
754 | pairsList = None | |
728 |
|
755 | |||
729 | nCohInt = None |
|
756 | nCohInt = None | |
730 |
|
757 | |||
731 | nIncohInt = None |
|
758 | nIncohInt = None | |
732 |
|
759 | |||
733 | def __init__(self): |
|
760 | def __init__(self): | |
734 |
|
761 | |||
735 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
762 | self.radarControllerHeaderObj = RadarControllerHeader() | |
736 |
|
763 | |||
737 | self.systemHeaderObj = SystemHeader() |
|
764 | self.systemHeaderObj = SystemHeader() | |
738 |
|
765 | |||
739 | self.type = "SpectraHeis" |
|
766 | self.type = "SpectraHeis" | |
740 |
|
767 | |||
741 | # self.dtype = None |
|
768 | # self.dtype = None | |
742 |
|
769 | |||
743 | # self.nChannels = 0 |
|
770 | # self.nChannels = 0 | |
744 |
|
771 | |||
745 | # self.nHeights = 0 |
|
772 | # self.nHeights = 0 | |
746 |
|
773 | |||
747 | self.nProfiles = None |
|
774 | self.nProfiles = None | |
748 |
|
775 | |||
749 | self.heightList = None |
|
776 | self.heightList = None | |
750 |
|
777 | |||
751 | self.channelList = None |
|
778 | self.channelList = None | |
752 |
|
779 | |||
753 | # self.channelIndexList = None |
|
780 | # self.channelIndexList = None | |
754 |
|
781 | |||
755 | self.flagNoData = True |
|
782 | self.flagNoData = True | |
756 |
|
783 | |||
757 | self.flagDiscontinuousBlock = False |
|
784 | self.flagDiscontinuousBlock = False | |
758 |
|
785 | |||
759 | # self.nPairs = 0 |
|
786 | # self.nPairs = 0 | |
760 |
|
787 | |||
761 | self.utctime = None |
|
788 | self.utctime = None | |
762 |
|
789 | |||
763 | self.blocksize = None |
|
790 | self.blocksize = None | |
764 |
|
791 | |||
765 | self.profileIndex = 0 |
|
792 | self.profileIndex = 0 | |
766 |
|
793 | |||
767 | self.nCohInt = 1 |
|
794 | self.nCohInt = 1 | |
768 |
|
795 | |||
769 | self.nIncohInt = 1 |
|
796 | self.nIncohInt = 1 | |
770 |
|
797 | |||
771 | def getNormFactor(self): |
|
798 | def getNormFactor(self): | |
772 | pwcode = 1 |
|
799 | pwcode = 1 | |
773 | if self.flagDecodeData: |
|
800 | if self.flagDecodeData: | |
774 | pwcode = numpy.sum(self.code[0]**2) |
|
801 | pwcode = numpy.sum(self.code[0]**2) | |
775 |
|
802 | |||
776 | normFactor = self.nIncohInt*self.nCohInt*pwcode |
|
803 | normFactor = self.nIncohInt*self.nCohInt*pwcode | |
777 |
|
804 | |||
778 | return normFactor |
|
805 | return normFactor | |
779 |
|
806 | |||
780 | def getTimeInterval(self): |
|
807 | def getTimeInterval(self): | |
781 |
|
808 | |||
782 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt |
|
809 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt | |
783 |
|
810 | |||
784 | return timeInterval |
|
811 | return timeInterval | |
785 |
|
812 | |||
786 | normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.") |
|
813 | normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.") | |
787 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
814 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") | |
788 |
|
815 | |||
789 | class Fits(JROData): |
|
816 | class Fits(JROData): | |
790 |
|
817 | |||
791 | heightList = None |
|
818 | heightList = None | |
792 |
|
819 | |||
793 | channelList = None |
|
820 | channelList = None | |
794 |
|
821 | |||
795 | flagNoData = True |
|
822 | flagNoData = True | |
796 |
|
823 | |||
797 | flagDiscontinuousBlock = False |
|
824 | flagDiscontinuousBlock = False | |
798 |
|
825 | |||
799 | useLocalTime = False |
|
826 | useLocalTime = False | |
800 |
|
827 | |||
801 | utctime = None |
|
828 | utctime = None | |
802 |
|
829 | |||
803 | timeZone = None |
|
830 | timeZone = None | |
804 |
|
831 | |||
805 | # ippSeconds = None |
|
832 | # ippSeconds = None | |
806 |
|
833 | |||
807 | # timeInterval = None |
|
834 | # timeInterval = None | |
808 |
|
835 | |||
809 | nCohInt = None |
|
836 | nCohInt = None | |
810 |
|
837 | |||
811 | nIncohInt = None |
|
838 | nIncohInt = None | |
812 |
|
839 | |||
813 | noise = None |
|
840 | noise = None | |
814 |
|
841 | |||
815 | windowOfFilter = 1 |
|
842 | windowOfFilter = 1 | |
816 |
|
843 | |||
817 | #Speed of ligth |
|
844 | #Speed of ligth | |
818 | C = 3e8 |
|
845 | C = 3e8 | |
819 |
|
846 | |||
820 | frequency = 49.92e6 |
|
847 | frequency = 49.92e6 | |
821 |
|
848 | |||
822 | realtime = False |
|
849 | realtime = False | |
823 |
|
850 | |||
824 |
|
851 | |||
825 | def __init__(self): |
|
852 | def __init__(self): | |
826 |
|
853 | |||
827 | self.type = "Fits" |
|
854 | self.type = "Fits" | |
828 |
|
855 | |||
829 | self.nProfiles = None |
|
856 | self.nProfiles = None | |
830 |
|
857 | |||
831 | self.heightList = None |
|
858 | self.heightList = None | |
832 |
|
859 | |||
833 | self.channelList = None |
|
860 | self.channelList = None | |
834 |
|
861 | |||
835 | # self.channelIndexList = None |
|
862 | # self.channelIndexList = None | |
836 |
|
863 | |||
837 | self.flagNoData = True |
|
864 | self.flagNoData = True | |
838 |
|
865 | |||
839 | self.utctime = None |
|
866 | self.utctime = None | |
840 |
|
867 | |||
841 | self.nCohInt = 1 |
|
868 | self.nCohInt = 1 | |
842 |
|
869 | |||
843 | self.nIncohInt = 1 |
|
870 | self.nIncohInt = 1 | |
844 |
|
871 | |||
845 | self.useLocalTime = True |
|
872 | self.useLocalTime = True | |
846 |
|
873 | |||
847 | self.profileIndex = 0 |
|
874 | self.profileIndex = 0 | |
848 |
|
875 | |||
849 | # self.utctime = None |
|
876 | # self.utctime = None | |
850 | # self.timeZone = None |
|
877 | # self.timeZone = None | |
851 | # self.ltctime = None |
|
878 | # self.ltctime = None | |
@@ -860,230 +887,230 class Fits(JROData): | |||||
860 | # self.nSamples = None |
|
887 | # self.nSamples = None | |
861 | # self.dataBlocksPerFile = None |
|
888 | # self.dataBlocksPerFile = None | |
862 | # self.comments = '' |
|
889 | # self.comments = '' | |
863 | # |
|
890 | # | |
|
891 | ||||
864 |
|
892 | |||
865 |
|
||||
866 | def getltctime(self): |
|
893 | def getltctime(self): | |
867 |
|
894 | |||
868 | if self.useLocalTime: |
|
895 | if self.useLocalTime: | |
869 | return self.utctime - self.timeZone*60 |
|
896 | return self.utctime - self.timeZone*60 | |
870 |
|
897 | |||
871 | return self.utctime |
|
898 | return self.utctime | |
872 |
|
899 | |||
873 | def getDatatime(self): |
|
900 | def getDatatime(self): | |
874 |
|
901 | |||
875 | datatime = datetime.datetime.utcfromtimestamp(self.ltctime) |
|
902 | datatime = datetime.datetime.utcfromtimestamp(self.ltctime) | |
876 | return datatime |
|
903 | return datatime | |
877 |
|
904 | |||
878 | def getTimeRange(self): |
|
905 | def getTimeRange(self): | |
879 |
|
906 | |||
880 | datatime = [] |
|
907 | datatime = [] | |
881 |
|
908 | |||
882 | datatime.append(self.ltctime) |
|
909 | datatime.append(self.ltctime) | |
883 | datatime.append(self.ltctime + self.timeInterval) |
|
910 | datatime.append(self.ltctime + self.timeInterval) | |
884 |
|
911 | |||
885 | datatime = numpy.array(datatime) |
|
912 | datatime = numpy.array(datatime) | |
886 |
|
913 | |||
887 | return datatime |
|
914 | return datatime | |
888 |
|
915 | |||
889 | def getHeiRange(self): |
|
916 | def getHeiRange(self): | |
890 |
|
917 | |||
891 | heis = self.heightList |
|
918 | heis = self.heightList | |
892 |
|
919 | |||
893 | return heis |
|
920 | return heis | |
894 |
|
921 | |||
895 | def getNHeights(self): |
|
922 | def getNHeights(self): | |
896 |
|
923 | |||
897 | return len(self.heightList) |
|
924 | return len(self.heightList) | |
898 |
|
925 | |||
899 | def getNChannels(self): |
|
926 | def getNChannels(self): | |
900 |
|
927 | |||
901 | return len(self.channelList) |
|
928 | return len(self.channelList) | |
902 |
|
929 | |||
903 | def getChannelIndexList(self): |
|
930 | def getChannelIndexList(self): | |
904 |
|
931 | |||
905 | return range(self.nChannels) |
|
932 | return range(self.nChannels) | |
906 |
|
933 | |||
907 | def getNoise(self, type = 1): |
|
934 | def getNoise(self, type = 1): | |
908 |
|
935 | |||
909 | #noise = numpy.zeros(self.nChannels) |
|
936 | #noise = numpy.zeros(self.nChannels) | |
910 |
|
937 | |||
911 | if type == 1: |
|
938 | if type == 1: | |
912 | noise = self.getNoisebyHildebrand() |
|
939 | noise = self.getNoisebyHildebrand() | |
913 |
|
940 | |||
914 | if type == 2: |
|
941 | if type == 2: | |
915 | noise = self.getNoisebySort() |
|
942 | noise = self.getNoisebySort() | |
916 |
|
943 | |||
917 | if type == 3: |
|
944 | if type == 3: | |
918 | noise = self.getNoisebyWindow() |
|
945 | noise = self.getNoisebyWindow() | |
919 |
|
946 | |||
920 | return noise |
|
947 | return noise | |
921 |
|
948 | |||
922 | def getTimeInterval(self): |
|
949 | def getTimeInterval(self): | |
923 |
|
950 | |||
924 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt |
|
951 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt | |
925 |
|
952 | |||
926 | return timeInterval |
|
953 | return timeInterval | |
927 |
|
954 | |||
928 | datatime = property(getDatatime, "I'm the 'datatime' property") |
|
955 | datatime = property(getDatatime, "I'm the 'datatime' property") | |
929 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") |
|
956 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") | |
930 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") |
|
957 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") | |
931 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") |
|
958 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") | |
932 | noise = property(getNoise, "I'm the 'nHeights' property.") |
|
959 | noise = property(getNoise, "I'm the 'nHeights' property.") | |
933 |
|
960 | |||
934 | ltctime = property(getltctime, "I'm the 'ltctime' property") |
|
961 | ltctime = property(getltctime, "I'm the 'ltctime' property") | |
935 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
962 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") | |
936 |
|
963 | |||
937 |
|
964 | |||
938 | class Correlation(JROData): |
|
965 | class Correlation(JROData): | |
939 |
|
966 | |||
940 | noise = None |
|
967 | noise = None | |
941 |
|
968 | |||
942 | SNR = None |
|
969 | SNR = None | |
943 |
|
970 | |||
944 | #-------------------------------------------------- |
|
971 | #-------------------------------------------------- | |
945 |
|
972 | |||
946 | mode = None |
|
973 | mode = None | |
947 |
|
974 | |||
948 | split = False |
|
975 | split = False | |
949 |
|
976 | |||
950 | data_cf = None |
|
977 | data_cf = None | |
951 |
|
978 | |||
952 | lags = None |
|
979 | lags = None | |
953 |
|
980 | |||
954 | lagRange = None |
|
981 | lagRange = None | |
955 |
|
982 | |||
956 | pairsList = None |
|
983 | pairsList = None | |
957 |
|
984 | |||
958 | normFactor = None |
|
985 | normFactor = None | |
959 |
|
986 | |||
960 | #-------------------------------------------------- |
|
987 | #-------------------------------------------------- | |
961 |
|
988 | |||
962 | # calculateVelocity = None |
|
989 | # calculateVelocity = None | |
963 |
|
990 | |||
964 | nLags = None |
|
991 | nLags = None | |
965 |
|
992 | |||
966 | nPairs = None |
|
993 | nPairs = None | |
967 |
|
994 | |||
968 | nAvg = None |
|
995 | nAvg = None | |
969 |
|
996 | |||
970 |
|
997 | |||
971 | def __init__(self): |
|
998 | def __init__(self): | |
972 | ''' |
|
999 | ''' | |
973 | Constructor |
|
1000 | Constructor | |
974 | ''' |
|
1001 | ''' | |
975 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
1002 | self.radarControllerHeaderObj = RadarControllerHeader() | |
976 |
|
1003 | |||
977 | self.systemHeaderObj = SystemHeader() |
|
1004 | self.systemHeaderObj = SystemHeader() | |
978 |
|
1005 | |||
979 | self.type = "Correlation" |
|
1006 | self.type = "Correlation" | |
980 |
|
1007 | |||
981 | self.data = None |
|
1008 | self.data = None | |
982 |
|
1009 | |||
983 | self.dtype = None |
|
1010 | self.dtype = None | |
984 |
|
1011 | |||
985 | self.nProfiles = None |
|
1012 | self.nProfiles = None | |
986 |
|
1013 | |||
987 | self.heightList = None |
|
1014 | self.heightList = None | |
988 |
|
1015 | |||
989 | self.channelList = None |
|
1016 | self.channelList = None | |
990 |
|
1017 | |||
991 | self.flagNoData = True |
|
1018 | self.flagNoData = True | |
992 |
|
1019 | |||
993 | self.flagDiscontinuousBlock = False |
|
1020 | self.flagDiscontinuousBlock = False | |
994 |
|
1021 | |||
995 | self.utctime = None |
|
1022 | self.utctime = None | |
996 |
|
1023 | |||
997 | self.timeZone = None |
|
1024 | self.timeZone = None | |
998 |
|
1025 | |||
999 | self.dstFlag = None |
|
1026 | self.dstFlag = None | |
1000 |
|
1027 | |||
1001 | self.errorCount = None |
|
1028 | self.errorCount = None | |
1002 |
|
1029 | |||
1003 | self.blocksize = None |
|
1030 | self.blocksize = None | |
1004 |
|
1031 | |||
1005 | self.flagDecodeData = False #asumo q la data no esta decodificada |
|
1032 | self.flagDecodeData = False #asumo q la data no esta decodificada | |
1006 |
|
1033 | |||
1007 | self.flagDeflipData = False #asumo q la data no esta sin flip |
|
1034 | self.flagDeflipData = False #asumo q la data no esta sin flip | |
1008 |
|
1035 | |||
1009 | self.pairsList = None |
|
1036 | self.pairsList = None | |
1010 |
|
1037 | |||
1011 | self.nPoints = None |
|
1038 | self.nPoints = None | |
1012 |
|
1039 | |||
1013 | def getPairsList(self): |
|
1040 | def getPairsList(self): | |
1014 |
|
1041 | |||
1015 | return self.pairsList |
|
1042 | return self.pairsList | |
1016 |
|
1043 | |||
1017 | def getNoise(self, mode = 2): |
|
1044 | def getNoise(self, mode = 2): | |
1018 |
|
1045 | |||
1019 | indR = numpy.where(self.lagR == 0)[0][0] |
|
1046 | indR = numpy.where(self.lagR == 0)[0][0] | |
1020 | indT = numpy.where(self.lagT == 0)[0][0] |
|
1047 | indT = numpy.where(self.lagT == 0)[0][0] | |
1021 |
|
1048 | |||
1022 | jspectra0 = self.data_corr[:,:,indR,:] |
|
1049 | jspectra0 = self.data_corr[:,:,indR,:] | |
1023 | jspectra = copy.copy(jspectra0) |
|
1050 | jspectra = copy.copy(jspectra0) | |
1024 |
|
1051 | |||
1025 | num_chan = jspectra.shape[0] |
|
1052 | num_chan = jspectra.shape[0] | |
1026 | num_hei = jspectra.shape[2] |
|
1053 | num_hei = jspectra.shape[2] | |
1027 |
|
1054 | |||
1028 | freq_dc = jspectra.shape[1]/2 |
|
1055 | freq_dc = jspectra.shape[1]/2 | |
1029 |
ind_vel = numpy.array([-2,-1,1,2]) + freq_dc |
|
1056 | ind_vel = numpy.array([-2,-1,1,2]) + freq_dc | |
1030 |
|
1057 | |||
1031 | if ind_vel[0]<0: |
|
1058 | if ind_vel[0]<0: | |
1032 | ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof |
|
1059 | ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof | |
1033 |
|
1060 | |||
1034 |
if mode == 1: |
|
1061 | if mode == 1: | |
1035 | jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION |
|
1062 | jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION | |
1036 |
|
1063 | |||
1037 | if mode == 2: |
|
1064 | if mode == 2: | |
1038 |
|
1065 | |||
1039 | vel = numpy.array([-2,-1,1,2]) |
|
1066 | vel = numpy.array([-2,-1,1,2]) | |
1040 | xx = numpy.zeros([4,4]) |
|
1067 | xx = numpy.zeros([4,4]) | |
1041 |
|
1068 | |||
1042 | for fil in range(4): |
|
1069 | for fil in range(4): | |
1043 | xx[fil,:] = vel[fil]**numpy.asarray(range(4)) |
|
1070 | xx[fil,:] = vel[fil]**numpy.asarray(range(4)) | |
1044 |
|
1071 | |||
1045 | xx_inv = numpy.linalg.inv(xx) |
|
1072 | xx_inv = numpy.linalg.inv(xx) | |
1046 | xx_aux = xx_inv[0,:] |
|
1073 | xx_aux = xx_inv[0,:] | |
1047 |
|
1074 | |||
1048 | for ich in range(num_chan): |
|
1075 | for ich in range(num_chan): | |
1049 | yy = jspectra[ich,ind_vel,:] |
|
1076 | yy = jspectra[ich,ind_vel,:] | |
1050 | jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy) |
|
1077 | jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy) | |
1051 |
|
1078 | |||
1052 | junkid = jspectra[ich,freq_dc,:]<=0 |
|
1079 | junkid = jspectra[ich,freq_dc,:]<=0 | |
1053 | cjunkid = sum(junkid) |
|
1080 | cjunkid = sum(junkid) | |
1054 |
|
1081 | |||
1055 | if cjunkid.any(): |
|
1082 | if cjunkid.any(): | |
1056 | jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2 |
|
1083 | jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2 | |
1057 |
|
1084 | |||
1058 | noise = jspectra0[:,freq_dc,:] - jspectra[:,freq_dc,:] |
|
1085 | noise = jspectra0[:,freq_dc,:] - jspectra[:,freq_dc,:] | |
1059 |
|
1086 | |||
1060 | return noise |
|
1087 | return noise | |
1061 |
|
1088 | |||
1062 | def getTimeInterval(self): |
|
1089 | def getTimeInterval(self): | |
1063 |
|
1090 | |||
1064 | timeInterval = self.ippSeconds * self.nCohInt * self.nProfiles |
|
1091 | timeInterval = self.ippSeconds * self.nCohInt * self.nProfiles | |
1065 |
|
1092 | |||
1066 | return timeInterval |
|
1093 | return timeInterval | |
1067 |
|
1094 | |||
1068 | def splitFunctions(self): |
|
1095 | def splitFunctions(self): | |
1069 |
|
1096 | |||
1070 | pairsList = self.pairsList |
|
1097 | pairsList = self.pairsList | |
1071 | ccf_pairs = [] |
|
1098 | ccf_pairs = [] | |
1072 | acf_pairs = [] |
|
1099 | acf_pairs = [] | |
1073 | ccf_ind = [] |
|
1100 | ccf_ind = [] | |
1074 | acf_ind = [] |
|
1101 | acf_ind = [] | |
1075 |
for l in range(len(pairsList)): |
|
1102 | for l in range(len(pairsList)): | |
1076 | chan0 = pairsList[l][0] |
|
1103 | chan0 = pairsList[l][0] | |
1077 | chan1 = pairsList[l][1] |
|
1104 | chan1 = pairsList[l][1] | |
1078 |
|
1105 | |||
1079 |
#Obteniendo pares de Autocorrelacion |
|
1106 | #Obteniendo pares de Autocorrelacion | |
1080 | if chan0 == chan1: |
|
1107 | if chan0 == chan1: | |
1081 | acf_pairs.append(chan0) |
|
1108 | acf_pairs.append(chan0) | |
1082 | acf_ind.append(l) |
|
1109 | acf_ind.append(l) | |
1083 | else: |
|
1110 | else: | |
1084 | ccf_pairs.append(pairsList[l]) |
|
1111 | ccf_pairs.append(pairsList[l]) | |
1085 | ccf_ind.append(l) |
|
1112 | ccf_ind.append(l) | |
1086 |
|
1113 | |||
1087 | data_acf = self.data_cf[acf_ind] |
|
1114 | data_acf = self.data_cf[acf_ind] | |
1088 | data_ccf = self.data_cf[ccf_ind] |
|
1115 | data_ccf = self.data_cf[ccf_ind] | |
1089 |
|
1116 | |||
@@ -1093,97 +1120,97 class Correlation(JROData): | |||||
1093 | acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.splitFunctions() |
|
1120 | acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.splitFunctions() | |
1094 | acf_pairs = numpy.array(acf_pairs) |
|
1121 | acf_pairs = numpy.array(acf_pairs) | |
1095 | normFactor = numpy.zeros((self.nPairs,self.nHeights)) |
|
1122 | normFactor = numpy.zeros((self.nPairs,self.nHeights)) | |
1096 |
|
1123 | |||
1097 | for p in range(self.nPairs): |
|
1124 | for p in range(self.nPairs): | |
1098 | pair = self.pairsList[p] |
|
1125 | pair = self.pairsList[p] | |
1099 |
|
1126 | |||
1100 | ch0 = pair[0] |
|
1127 | ch0 = pair[0] | |
1101 | ch1 = pair[1] |
|
1128 | ch1 = pair[1] | |
1102 |
|
1129 | |||
1103 | ch0_max = numpy.max(data_acf[acf_pairs==ch0,:,:], axis=1) |
|
1130 | ch0_max = numpy.max(data_acf[acf_pairs==ch0,:,:], axis=1) | |
1104 | ch1_max = numpy.max(data_acf[acf_pairs==ch1,:,:], axis=1) |
|
1131 | ch1_max = numpy.max(data_acf[acf_pairs==ch1,:,:], axis=1) | |
1105 | normFactor[p,:] = numpy.sqrt(ch0_max*ch1_max) |
|
1132 | normFactor[p,:] = numpy.sqrt(ch0_max*ch1_max) | |
1106 |
|
1133 | |||
1107 | return normFactor |
|
1134 | return normFactor | |
1108 |
|
1135 | |||
1109 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
1136 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") | |
1110 | normFactor = property(getNormFactor, "I'm the 'normFactor property'") |
|
1137 | normFactor = property(getNormFactor, "I'm the 'normFactor property'") | |
1111 |
|
1138 | |||
1112 | class Parameters(JROData): |
|
1139 | class Parameters(JROData): | |
1113 |
|
1140 | |||
1114 | experimentInfo = None #Information about the experiment |
|
1141 | experimentInfo = None #Information about the experiment | |
1115 |
|
1142 | |||
1116 | #Information from previous data |
|
1143 | #Information from previous data | |
1117 |
|
1144 | |||
1118 | inputUnit = None #Type of data to be processed |
|
1145 | inputUnit = None #Type of data to be processed | |
1119 |
|
1146 | |||
1120 | operation = None #Type of operation to parametrize |
|
1147 | operation = None #Type of operation to parametrize | |
1121 |
|
1148 | |||
1122 | normFactor = None #Normalization Factor |
|
1149 | normFactor = None #Normalization Factor | |
1123 |
|
1150 | |||
1124 | groupList = None #List of Pairs, Groups, etc |
|
1151 | groupList = None #List of Pairs, Groups, etc | |
1125 |
|
1152 | |||
1126 | #Parameters |
|
1153 | #Parameters | |
1127 |
|
1154 | |||
1128 | data_param = None #Parameters obtained |
|
1155 | data_param = None #Parameters obtained | |
1129 |
|
1156 | |||
1130 | data_pre = None #Data Pre Parametrization |
|
1157 | data_pre = None #Data Pre Parametrization | |
1131 |
|
1158 | |||
1132 | data_SNR = None #Signal to Noise Ratio |
|
1159 | data_SNR = None #Signal to Noise Ratio | |
1133 |
|
1160 | |||
1134 | # heightRange = None #Heights |
|
1161 | # heightRange = None #Heights | |
1135 |
|
1162 | |||
1136 | abscissaList = None #Abscissa, can be velocities, lags or time |
|
1163 | abscissaList = None #Abscissa, can be velocities, lags or time | |
1137 |
|
1164 | |||
1138 | noise = None #Noise Potency |
|
1165 | noise = None #Noise Potency | |
1139 |
|
1166 | |||
1140 | utctimeInit = None #Initial UTC time |
|
1167 | utctimeInit = None #Initial UTC time | |
1141 |
|
1168 | |||
1142 | paramInterval = None #Time interval to calculate Parameters in seconds |
|
1169 | paramInterval = None #Time interval to calculate Parameters in seconds | |
1143 |
|
1170 | |||
1144 | useLocalTime = True |
|
1171 | useLocalTime = True | |
1145 |
|
1172 | |||
1146 | #Fitting |
|
1173 | #Fitting | |
1147 |
|
1174 | |||
1148 | data_error = None #Error of the estimation |
|
1175 | data_error = None #Error of the estimation | |
1149 |
|
1176 | |||
1150 |
constants = None |
|
1177 | constants = None | |
1151 |
|
1178 | |||
1152 | library = None |
|
1179 | library = None | |
1153 |
|
1180 | |||
1154 | #Output signal |
|
1181 | #Output signal | |
1155 |
|
1182 | |||
1156 | outputInterval = None #Time interval to calculate output signal in seconds |
|
1183 | outputInterval = None #Time interval to calculate output signal in seconds | |
1157 |
|
1184 | |||
1158 | data_output = None #Out signal |
|
1185 | data_output = None #Out signal | |
1159 |
|
1186 | |||
1160 | nAvg = None |
|
1187 | nAvg = None | |
1161 |
|
1188 | |||
1162 |
|
1189 | |||
1163 | def __init__(self): |
|
1190 | def __init__(self): | |
1164 | ''' |
|
1191 | ''' | |
1165 | Constructor |
|
1192 | Constructor | |
1166 | ''' |
|
1193 | ''' | |
1167 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
1194 | self.radarControllerHeaderObj = RadarControllerHeader() | |
1168 |
|
1195 | |||
1169 | self.systemHeaderObj = SystemHeader() |
|
1196 | self.systemHeaderObj = SystemHeader() | |
1170 |
|
1197 | |||
1171 | self.type = "Parameters" |
|
1198 | self.type = "Parameters" | |
1172 |
|
1199 | |||
1173 | def getTimeRange1(self, interval): |
|
1200 | def getTimeRange1(self, interval): | |
1174 |
|
1201 | |||
1175 | datatime = [] |
|
1202 | datatime = [] | |
1176 |
|
1203 | |||
1177 | if self.useLocalTime: |
|
1204 | if self.useLocalTime: | |
1178 | time1 = self.utctimeInit - self.timeZone*60 |
|
1205 | time1 = self.utctimeInit - self.timeZone*60 | |
1179 | else: |
|
1206 | else: | |
1180 | time1 = self.utctimeInit |
|
1207 | time1 = self.utctimeInit | |
1181 |
|
1208 | |||
1182 | # datatime.append(self.utctimeInit) |
|
1209 | # datatime.append(self.utctimeInit) | |
1183 | # datatime.append(self.utctimeInit + self.outputInterval) |
|
1210 | # datatime.append(self.utctimeInit + self.outputInterval) | |
1184 | datatime.append(time1) |
|
1211 | datatime.append(time1) | |
1185 | datatime.append(time1 + interval) |
|
1212 | datatime.append(time1 + interval) | |
1186 |
|
1213 | |||
1187 | datatime = numpy.array(datatime) |
|
1214 | datatime = numpy.array(datatime) | |
1188 |
|
1215 | |||
1189 | return datatime |
|
1216 | return datatime |
@@ -1,5 +1,6 | |||||
1 |
|
1 | |||
2 | import os |
|
2 | import os | |
|
3 | import zmq | |||
3 | import time |
|
4 | import time | |
4 | import numpy |
|
5 | import numpy | |
5 | import datetime |
|
6 | import datetime | |
@@ -7,80 +8,48 import numpy as np | |||||
7 | import matplotlib.pyplot as plt |
|
8 | import matplotlib.pyplot as plt | |
8 | from mpl_toolkits.axes_grid1 import make_axes_locatable |
|
9 | from mpl_toolkits.axes_grid1 import make_axes_locatable | |
9 | from matplotlib.ticker import FuncFormatter, LinearLocator |
|
10 | from matplotlib.ticker import FuncFormatter, LinearLocator | |
|
11 | from multiprocessing import Process | |||
10 |
|
12 | |||
11 | from schainpy.model.proc.jroproc_base import Operation |
|
13 | from schainpy.model.proc.jroproc_base import Operation | |
12 |
|
14 | |||
|
15 | #plt.ion() | |||
|
16 | ||||
13 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime('%H:%M')) |
|
17 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime('%H:%M')) | |
14 |
|
18 | |||
15 | d1970 = datetime.datetime(1970,1,1) |
|
19 | d1970 = datetime.datetime(1970,1,1) | |
16 |
|
20 | |||
|
21 | class PlotData(Operation, Process): | |||
17 |
|
22 | |||
18 | class PlotData(Operation): |
|
23 | CODE = 'Figure' | |
19 |
|
24 | colormap = 'jet' | ||
20 | __code = 'Figure' |
|
|||
21 | __MAXNUMX = 80 |
|
25 | __MAXNUMX = 80 | |
22 | __MAXNUMY = 80 |
|
26 | __MAXNUMY = 80 | |
23 | __missing = 1E30 |
|
27 | __missing = 1E30 | |
24 |
|
28 | |||
25 | def __init__(self): |
|
29 | def __init__(self, **kwargs): | |
26 |
|
30 | |||
27 | Operation.__init__(self) |
|
31 | Operation.__init__(self) | |
28 | self.xmin = None |
|
32 | Process.__init__(self) | |
29 |
self. |
|
33 | self.mp = False | |
30 | self.newdataOut = None |
|
|||
31 | self.dataOut = None |
|
34 | self.dataOut = None | |
32 | self.isConfig = False |
|
35 | self.isConfig = False | |
33 | self.figure = None |
|
36 | self.figure = None | |
34 |
self. |
|
37 | self.axes = [] | |
35 | self.height = 4 |
|
|||
36 |
|
||||
37 | def setup(self, dataOut, **kwargs): |
|
|||
38 |
|
||||
39 | self.first = True |
|
|||
40 | self.localtime = kwargs.pop('localtime', True) |
|
38 | self.localtime = kwargs.pop('localtime', True) | |
41 |
self.show = kwargs. |
|
39 | self.show = kwargs.get('show', True) | |
42 |
self.save = kwargs. |
|
40 | self.save = kwargs.get('save', False) | |
43 |
self. |
|
41 | self.colormap = kwargs.get('colormap', self.colormap) | |
44 | self.time = [] |
|
42 | self.showprofile = kwargs.get('showprofile', False) | |
45 | self.nblock = 0 |
|
|||
46 | self.z = [] |
|
|||
47 | self.data = [{} for __ in dataOut.channelList] |
|
|||
48 | self.axes = [] |
|
|||
49 | self.colormap = kwargs.get('colormap', 'jet') |
|
|||
50 | self.title = kwargs.get('wintitle', '') |
|
43 | self.title = kwargs.get('wintitle', '') | |
51 |
self.xaxis = kwargs.get('xaxis', |
|
44 | self.xaxis = kwargs.get('xaxis', 'time') | |
52 | self.zmin = kwargs.get('zmin', None) |
|
45 | self.zmin = kwargs.get('zmin', None) | |
53 | self.zmax = kwargs.get('zmax', None) |
|
46 | self.zmax = kwargs.get('zmax', None) | |
54 |
|
47 | self.xmin = kwargs.get('xmin', None) | ||
55 |
|
|
48 | self.xmax = kwargs.get('xmax', None) | |
56 |
|
|
49 | self.xrange = kwargs.get('xrange', 24) | |
57 |
|
||||
58 | dt = dataOut.datatime.date() |
|
|||
59 | dtmin = datetime.datetime.combine(dt, datetime.time(xmin, 0, 0)) |
|
|||
60 | dtmax = datetime.datetime.combine(dt, datetime.time(xmax, 59, 59)) |
|
|||
61 |
|
||||
62 | self.xmin = (dtmin-d1970).total_seconds() |
|
|||
63 | self.xmax = (dtmax-d1970).total_seconds() |
|
|||
64 |
|
||||
65 | self.ymin = kwargs.get('ymin', None) |
|
50 | self.ymin = kwargs.get('ymin', None) | |
66 | self.ymax = kwargs.get('ymax', None) |
|
51 | self.ymax = kwargs.get('ymax', None) | |
67 |
|
52 | |||
68 | if self.figure is None: |
|
|||
69 | self.figure = plt.figure() |
|
|||
70 | else: |
|
|||
71 | self.figure.clf() |
|
|||
72 |
|
||||
73 | self.setup_fig() |
|
|||
74 |
|
||||
75 | for n in range(dataOut.nChannels): |
|
|||
76 | ax = self.figure.add_subplot(self.nrows, self.ncols, n+1) |
|
|||
77 | ax.firsttime = True |
|
|||
78 | self.axes.append(ax) |
|
|||
79 |
|
||||
80 | self.setup_fig() |
|
|||
81 |
|
||||
82 | self.figure.set_size_inches (self.width, self.height) |
|
|||
83 |
|
||||
84 | def fill_gaps(self, x_buffer, y_buffer, z_buffer): |
|
53 | def fill_gaps(self, x_buffer, y_buffer, z_buffer): | |
85 |
|
54 | |||
86 | if x_buffer.shape[0] < 2: |
|
55 | if x_buffer.shape[0] < 2: | |
@@ -100,160 +69,308 class PlotData(Operation): | |||||
100 | return x_buffer, y_buffer, z_buffer |
|
69 | return x_buffer, y_buffer, z_buffer | |
101 |
|
70 | |||
102 | def decimate(self): |
|
71 | def decimate(self): | |
103 |
|
72 | |||
104 | dx = int(len(self.x)/self.__MAXNUMX) + 1 |
|
73 | dx = int(len(self.x)/self.__MAXNUMX) + 1 | |
105 | dy = int(len(self.y)/self.__MAXNUMY) + 1 |
|
74 | dy = int(len(self.y)/self.__MAXNUMY) + 1 | |
106 |
|
75 | |||
107 | x = self.x[::dx] |
|
76 | x = self.x[::dx] | |
108 |
y = self.y[::dy] |
|
77 | y = self.y[::dy] | |
109 | z = self.z[::, ::dx, ::dy] |
|
78 | z = self.z[::, ::dx, ::dy] | |
110 |
|
79 | |||
111 | return x, y, z |
|
80 | return x, y, z | |
112 |
|
81 | |||
113 | def _plot(self): |
|
82 | def __plot(self): | |
|
83 | ||||
|
84 | print 'plotting...{}'.format(self.CODE) | |||
114 |
|
85 | |||
115 | self.plot() |
|
86 | self.plot() | |
116 |
|
87 | self.figure.suptitle('{} {}'.format(self.title, self.CODE.upper())) | ||
117 | self.figure.suptitle(self.title+self.__code) |
|
88 | ||
118 |
|
||||
119 | if self.save: |
|
89 | if self.save: | |
120 |
figname = os.path.join(self.save, '{}_{}.png'.format(self. |
|
90 | figname = os.path.join(self.save, '{}_{}.png'.format(self.CODE, | |
121 |
self. |
|
91 | datetime.datetime.utcfromtimestamp(self.times[-1]).strftime('%y%m%d_%H%M%S'))) | |
122 | print 'Saving figure: {}'.format(figname) |
|
92 | print 'Saving figure: {}'.format(figname) | |
123 | self.figure.savefig(figname) |
|
93 | self.figure.savefig(figname) | |
124 |
|
94 | |||
125 | self.figure.canvas.draw() |
|
95 | self.figure.canvas.draw() | |
126 | if self.show: |
|
|||
127 | self.figure.show() |
|
|||
128 | if self.pause: |
|
|||
129 | raw_input('Press <ENTER> to continue') |
|
|||
130 |
|
96 | |||
131 |
|
97 | def plot(self): | ||
132 | def update(self): |
|
98 | ||
|
99 | print 'plotting...{}'.format(self.CODE.upper()) | |||
|
100 | return | |||
133 |
|
101 | |||
134 | pass |
|
102 | def run(self): | |
135 |
|
103 | |||
136 | def run(self, dataOut, **kwargs): |
|
104 | print '[Starting] {}'.format(self.name) | |
|
105 | context = zmq.Context() | |||
|
106 | receiver = context.socket(zmq.SUB) | |||
|
107 | receiver.setsockopt(zmq.SUBSCRIBE, '') | |||
|
108 | receiver.setsockopt(zmq.CONFLATE, True) | |||
|
109 | receiver.connect("ipc:///tmp/zmq.plots") | |||
137 |
|
110 | |||
138 | self.dataOut = dataOut |
|
111 | while True: | |
|
112 | try: | |||
|
113 | #if True: | |||
|
114 | self.data = receiver.recv_pyobj(flags=zmq.NOBLOCK) | |||
|
115 | self.dataOut = self.data['dataOut'] | |||
|
116 | self.times = self.data['times'] | |||
|
117 | self.times.sort() | |||
|
118 | self.min_time = self.times[0] | |||
|
119 | self.max_time = self.times[-1] | |||
139 |
|
120 | |||
140 |
if |
|
121 | if self.isConfig is False: | |
141 |
self.setup( |
|
122 | self.setup() | |
142 | self.isConfig = True |
|
123 | self.isConfig = True | |
143 |
|
124 | |||
144 | self.nblock += 1 |
|
125 | self.__plot() | |
145 | self.update() |
|
126 | ||
146 |
|
127 | if 'ENDED' in self.data: | ||
147 | if dataOut.ltctime>=self.xmax: |
|
128 | #self.setup() | |
148 | self._plot() |
|
129 | #self.__plot() | |
149 | self.isConfig = False |
|
130 | pass | |
|
131 | ||||
|
132 | except zmq.Again as e: | |||
|
133 | print 'Waiting for data...' | |||
|
134 | plt.pause(5) | |||
|
135 | #time.sleep(3) | |||
150 |
|
136 | |||
151 | def close(self): |
|
137 | def close(self): | |
152 | if self.dataOut: |
|
138 | if self.dataOut: | |
153 | self._plot() |
|
139 | self._plot() | |
154 |
|
140 | |||
155 |
|
141 | |||
156 | class PlotSpectraData(PlotData): |
|
142 | class PlotSpectraData(PlotData): | |
157 |
|
||||
158 | __code = 'Spectra' |
|
|||
159 |
|
143 | |||
160 | def setup_fig(self): |
|
144 | CODE = 'spc' | |
161 | pass |
|
145 | colormap = 'jro' | |
|
146 | ||||
|
147 | def setup(self): | |||
|
148 | ||||
|
149 | ncolspan = 1 | |||
|
150 | colspan = 1 | |||
|
151 | self.ncols = int(numpy.sqrt(self.dataOut.nChannels)+0.9) | |||
|
152 | self.nrows = int(self.dataOut.nChannels*1./self.ncols + 0.9) | |||
|
153 | self.width = 3.6*self.ncols | |||
|
154 | self.height = 3.2*self.nrows | |||
|
155 | if self.showprofile: | |||
|
156 | ncolspan = 3 | |||
|
157 | colspan = 2 | |||
|
158 | self.width += 1.2*self.ncols | |||
|
159 | ||||
|
160 | self.ylabel = 'Range [Km]' | |||
|
161 | self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList] | |||
|
162 | ||||
|
163 | if self.figure is None: | |||
|
164 | self.figure = plt.figure(figsize=(self.width, self.height), | |||
|
165 | edgecolor='k', | |||
|
166 | facecolor='w') | |||
|
167 | else: | |||
|
168 | self.figure.clf() | |||
|
169 | ||||
|
170 | n = 0 | |||
|
171 | for y in range(self.nrows): | |||
|
172 | for x in range(self.ncols): | |||
|
173 | if n>=self.dataOut.nChannels: | |||
|
174 | break | |||
|
175 | ax = plt.subplot2grid((self.nrows, self.ncols*ncolspan), (y, x*ncolspan), 1, colspan) | |||
|
176 | if self.showprofile: | |||
|
177 | ax.ax_profile = plt.subplot2grid((self.nrows, self.ncols*ncolspan), (y, x*ncolspan+colspan), 1, 1) | |||
|
178 | ||||
|
179 | ax.firsttime = True | |||
|
180 | self.axes.append(ax) | |||
|
181 | n += 1 | |||
|
182 | ||||
|
183 | self.figure.subplots_adjust(wspace=0.9, hspace=0.5) | |||
|
184 | self.figure.show() | |||
162 |
|
185 | |||
163 | def update(self): |
|
|||
164 |
|
||||
165 | for ch in self.dataOut.channelList: |
|
|||
166 | self.data[ch] = self.dataOut.data_spc[ch] |
|
|||
167 |
|
||||
168 | def plot(self): |
|
186 | def plot(self): | |
169 | pass |
|
187 | ||
|
188 | if self.xaxis == "frequency": | |||
|
189 | x = self.dataOut.getFreqRange(1)/1000. | |||
|
190 | xlabel = "Frequency (kHz)" | |||
|
191 | elif self.xaxis == "time": | |||
|
192 | x = self.dataOut.getAcfRange(1) | |||
|
193 | xlabel = "Time (ms)" | |||
|
194 | else: | |||
|
195 | x = self.dataOut.getVelRange(1) | |||
|
196 | xlabel = "Velocity (m/s)" | |||
|
197 | ||||
|
198 | y = self.dataOut.getHeiRange() | |||
|
199 | z = self.data[self.CODE] | |||
|
200 | ||||
|
201 | for n, ax in enumerate(self.axes): | |||
|
202 | ||||
|
203 | if ax.firsttime: | |||
|
204 | self.xmax = self.xmax if self.xmax else np.nanmax(x) | |||
|
205 | self.xmin = self.xmin if self.xmin else -self.xmax | |||
|
206 | self.ymin = self.ymin if self.ymin else np.nanmin(y) | |||
|
207 | self.ymax = self.ymax if self.ymax else np.nanmax(y) | |||
|
208 | self.zmin = self.zmin if self.zmin else np.nanmin(z) | |||
|
209 | self.zmax = self.zmax if self.zmax else np.nanmax(z) | |||
|
210 | ax.plot = ax.pcolormesh(x, y, z[n].T, | |||
|
211 | vmin=self.zmin, | |||
|
212 | vmax=self.zmax, | |||
|
213 | cmap=plt.get_cmap(self.colormap) | |||
|
214 | ) | |||
|
215 | divider = make_axes_locatable(ax) | |||
|
216 | cax = divider.new_horizontal(size='3%', pad=0.05) | |||
|
217 | self.figure.add_axes(cax) | |||
|
218 | plt.colorbar(ax.plot, cax) | |||
|
219 | ||||
|
220 | ax.set_xlim(self.xmin, self.xmax) | |||
|
221 | ax.set_ylim(self.ymin, self.ymax) | |||
|
222 | ||||
|
223 | ax.xaxis.set_major_locator(LinearLocator(5)) | |||
|
224 | #ax.yaxis.set_major_locator(LinearLocator(4)) | |||
|
225 | ||||
|
226 | ax.set_ylabel(self.ylabel) | |||
|
227 | ax.set_xlabel(xlabel) | |||
|
228 | ||||
|
229 | ax.firsttime = False | |||
|
230 | ||||
|
231 | if self.showprofile: | |||
|
232 | ax.plot_profile= ax.ax_profile.plot(self.data['rti'][self.max_time][n], y)[0] | |||
|
233 | ax.ax_profile.set_xlim(self.zmin, self.zmax) | |||
|
234 | ax.ax_profile.set_ylim(self.ymin, self.ymax) | |||
|
235 | ax.ax_profile.set_xlabel('dB') | |||
|
236 | ax.ax_profile.grid(b=True, axis='x') | |||
|
237 | [tick.set_visible(False) for tick in ax.ax_profile.get_yticklabels()] | |||
|
238 | noise = 10*numpy.log10(self.data['rti'][self.max_time][n]/self.dataOut.normFactor) | |||
|
239 | ax.ax_profile.vlines(noise, self.ymin, self.ymax, colors="k", linestyle="dashed", lw=2) | |||
|
240 | else: | |||
|
241 | ax.plot.set_array(z[n].T.ravel()) | |||
|
242 | ax.set_title('{} {}'.format(self.titles[n], | |||
|
243 | datetime.datetime.utcfromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')), | |||
|
244 | size=8) | |||
|
245 | if self.showprofile: | |||
|
246 | ax.plot_profile.set_data(self.data['rti'][self.max_time][n], y) | |||
170 |
|
247 | |||
171 |
|
248 | |||
172 | class PlotRTIData(PlotData): |
|
249 | class PlotRTIData(PlotData): | |
173 |
|
250 | |||
174 | __code = 'RTI' |
|
251 | CODE = 'rti' | |
175 |
|
252 | colormap = 'jro' | ||
176 | def setup_fig(self): |
|
253 | ||
177 |
|
254 | def setup(self): | ||
|
255 | ||||
178 | self.ncols = 1 |
|
256 | self.ncols = 1 | |
179 | self.nrows = self.dataOut.nChannels |
|
257 | self.nrows = self.dataOut.nChannels | |
180 |
self.width = |
|
258 | self.width = 10 | |
181 | self.height = 2.2*self.nrows |
|
259 | self.height = 2.2*self.nrows | |
182 | self.ylabel = 'Range [Km]' |
|
260 | self.ylabel = 'Range [Km]' | |
183 |
|
261 | self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList] | ||
184 | def update(self): |
|
262 | ||
185 |
|
263 | if self.figure is None: | ||
186 | self.time.append(self.dataOut.ltctime) |
|
264 | self.figure = plt.figure(figsize=(self.width, self.height), | |
187 |
|
265 | edgecolor='k', | ||
188 | for ch in self.dataOut.channelList: |
|
266 | facecolor='w') | |
189 | self.data[ch][self.dataOut.ltctime] = self.dataOut.getPower()[ch] |
|
267 | else: | |
190 |
|
268 | self.figure.clf() | ||
|
269 | ||||
|
270 | for n in range(self.nrows): | |||
|
271 | ax = self.figure.add_subplot(self.nrows, self.ncols, n+1) | |||
|
272 | ax.firsttime = True | |||
|
273 | self.axes.append(ax) | |||
|
274 | ||||
|
275 | self.figure.subplots_adjust(hspace=0.5) | |||
|
276 | self.figure.show() | |||
|
277 | ||||
191 | def plot(self): |
|
278 | def plot(self): | |
192 |
|
||||
193 | self.plot_dt = datetime.datetime.utcfromtimestamp(self.time[-2]) |
|
|||
194 |
|
279 | |||
195 |
self. |
|
280 | self.x = np.array(self.times) | |
196 | self.x = self.time |
|
|||
197 | self.y = self.dataOut.getHeiRange() |
|
281 | self.y = self.dataOut.getHeiRange() | |
198 | self.z = [] |
|
282 | self.z = [] | |
199 |
|
283 | |||
200 |
for ch in self. |
|
284 | for ch in range(self.nrows): | |
201 |
self.z.append([self.data[ |
|
285 | self.z.append([self.data[self.CODE][t][ch] for t in self.times]) | |
202 |
|
286 | |||
203 |
self. |
|
287 | self.z = np.array(self.z) | |
204 | self.z = np.array(self.z) |
|
|||
205 |
|
||||
206 | for n, ax in enumerate(self.axes): |
|
|||
207 |
|
||||
208 | if self.xaxis=='time': |
|
|||
209 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
|||
210 | ax.xaxis.set_major_locator(LinearLocator(6)) |
|
|||
211 |
|
||||
212 | ax.yaxis.set_major_locator(LinearLocator(4)) |
|
|||
213 |
|
||||
214 | ax.set_ylabel(self.ylabel) |
|
|||
215 |
|
||||
216 | ax.set_xlim(self.xmin, self.xmax) |
|
|||
217 |
|
||||
218 | ax.set_title('Channel {} {}'.format(self.dataOut.channelList[n], |
|
|||
219 | self.plot_dt.strftime('%y/%m/%d %H:%M:%S')), |
|
|||
220 | size=8) |
|
|||
221 |
|
||||
222 | self.decimate() |
|
|||
223 |
|
288 | |||
224 | for n, ax in enumerate(self.axes): |
|
289 | for n, ax in enumerate(self.axes): | |
225 |
|
290 | |||
226 | x, y, z = self.fill_gaps(*self.decimate()) |
|
291 | x, y, z = self.fill_gaps(*self.decimate()) | |
227 |
|
292 | |||
228 | if ax.firsttime: |
|
293 | if ax.firsttime: | |
229 | ymin = self.ymin if self.ymin else np.nanmin(self.y) |
|
294 | self.ymin = self.ymin if self.ymin else np.nanmin(self.y) | |
230 | ymax = self.ymax if self.ymax else np.nanmax(self.y) |
|
295 | self.ymax = self.ymax if self.ymax else np.nanmax(self.y) | |
231 | zmin = self.zmin if self.zmin else np.nanmin(self.z) |
|
296 | self.zmin = self.zmin if self.zmin else np.nanmin(self.z) | |
232 | zmax = self.zmax if self.zmax else np.nanmax(self.z) |
|
297 | zmax = self.zmax if self.zmax else np.nanmax(self.z) | |
233 | plot = ax.pcolormesh(x, y, z[n].T, |
|
298 | plot = ax.pcolormesh(x, y, z[n].T, | |
234 | vmin=zmin, |
|
299 | vmin=self.zmin, | |
235 | vmax=zmax, |
|
300 | vmax=self.zmax, | |
236 | cmap=plt.get_cmap(self.colormap) |
|
301 | cmap=plt.get_cmap(self.colormap) | |
237 | ) |
|
302 | ) | |
238 | divider = make_axes_locatable(ax) |
|
303 | divider = make_axes_locatable(ax) | |
239 |
cax = divider.new_horizontal(size=' |
|
304 | cax = divider.new_horizontal(size='2%', pad=0.05) | |
240 | self.figure.add_axes(cax) |
|
305 | self.figure.add_axes(cax) | |
241 | plt.colorbar(plot, cax) |
|
306 | plt.colorbar(plot, cax) | |
242 | ax.set_ylim(self.ymin, self.ymax) |
|
307 | ax.set_ylim(self.ymin, self.ymax) | |
|
308 | if self.xaxis=='time': | |||
|
309 | ax.xaxis.set_major_formatter(FuncFormatter(func)) | |||
|
310 | ax.xaxis.set_major_locator(LinearLocator(6)) | |||
|
311 | ||||
|
312 | ax.yaxis.set_major_locator(LinearLocator(4)) | |||
|
313 | ||||
|
314 | ax.set_ylabel(self.ylabel) | |||
|
315 | ||||
|
316 | if self.xmin is None: | |||
|
317 | print 'is none' | |||
|
318 | xmin = self.min_time | |||
|
319 | else: | |||
|
320 | ||||
|
321 | xmin = (datetime.datetime.combine(self.dataOut.datatime.date(), | |||
|
322 | datetime.time(self.xmin, 0, 0))-d1970).total_seconds() | |||
|
323 | ||||
|
324 | xmax = xmin+self.xrange*60*60 | |||
|
325 | ||||
|
326 | ax.set_xlim(xmin, xmax) | |||
243 | ax.firsttime = False |
|
327 | ax.firsttime = False | |
244 |
else: |
|
328 | else: | |
245 | plot = ax.pcolormesh(x, y, z[n].T) |
|
329 | ax.collections.remove(ax.collections[0]) | |
|
330 | plot = ax.pcolormesh(x, y, z[n].T, | |||
|
331 | vmin=self.zmin, | |||
|
332 | vmax=self.zmax, | |||
|
333 | cmap=plt.get_cmap(self.colormap) | |||
|
334 | ) | |||
|
335 | ax.set_title('{} {}'.format(self.titles[n], | |||
|
336 | datetime.datetime.utcfromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')), | |||
|
337 | size=8) | |||
|
338 | ||||
|
339 | ||||
|
340 | class PlotCOHData(PlotRTIData): | |||
|
341 | ||||
|
342 | CODE = 'coh' | |||
|
343 | ||||
|
344 | def setup(self): | |||
|
345 | ||||
|
346 | self.ncols = 1 | |||
|
347 | self.nrows = self.dataOut.nPairs | |||
|
348 | self.width = 10 | |||
|
349 | self.height = 2.2*self.nrows | |||
|
350 | self.ylabel = 'Range [Km]' | |||
|
351 | self.titles = ['Channels {}'.format(x) for x in self.dataOut.pairsList] | |||
246 |
|
352 | |||
247 | self.figure.subplots_adjust(wspace=None, hspace=0.5) |
|
353 | if self.figure is None: | |
248 |
|
354 | self.figure = plt.figure(figsize=(self.width, self.height), | ||
|
355 | edgecolor='k', | |||
|
356 | facecolor='w') | |||
|
357 | else: | |||
|
358 | self.figure.clf() | |||
|
359 | ||||
|
360 | for n in range(self.nrows): | |||
|
361 | ax = self.figure.add_subplot(self.nrows, self.ncols, n+1) | |||
|
362 | ax.firsttime = True | |||
|
363 | self.axes.append(ax) | |||
|
364 | ||||
|
365 | self.figure.subplots_adjust(hspace=0.5) | |||
|
366 | self.figure.show() | |||
249 |
|
367 | |||
250 | class PlotSNRData(PlotRTIData): |
|
368 | class PlotSNRData(PlotRTIData): | |
251 |
|
369 | |||
252 | __code = 'SNR' |
|
370 | CODE = 'coh' | |
253 |
|
371 | |||
254 | def update(self): |
|
372 | ||
255 |
|
373 | class PlotPHASEData(PlotCOHData): | ||
256 | self.time.append(self.dataOut.ltctime) |
|
374 | ||
257 |
|
375 | CODE = 'phase' | ||
258 | for ch in self.dataOut.channelList: |
|
376 | colormap = 'seismic' | |
259 | self.data[ch][self.dataOut.ltctime] = 10*np.log10(self.dataOut.data_SNR[ch]) No newline at end of file |
|
@@ -11,174 +11,174 from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, | |||||
11 | from schainpy.model.data.jrodata import Spectra |
|
11 | from schainpy.model.data.jrodata import Spectra | |
12 |
|
12 | |||
13 | class SpectraReader(JRODataReader, ProcessingUnit): |
|
13 | class SpectraReader(JRODataReader, ProcessingUnit): | |
14 |
""" |
|
14 | """ | |
15 | Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura |
|
15 | Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura | |
16 |
de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones) |
|
16 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones) | |
17 | son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel. |
|
17 | son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel. | |
18 |
|
18 | |||
19 | paresCanalesIguales * alturas * perfiles (Self Spectra) |
|
19 | paresCanalesIguales * alturas * perfiles (Self Spectra) | |
20 | paresCanalesDiferentes * alturas * perfiles (Cross Spectra) |
|
20 | paresCanalesDiferentes * alturas * perfiles (Cross Spectra) | |
21 | canales * alturas (DC Channels) |
|
21 | canales * alturas (DC Channels) | |
22 |
|
22 | |||
23 |
Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, |
|
23 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, | |
24 | RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la |
|
24 | RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la | |
25 | cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de |
|
25 | cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de | |
26 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". |
|
26 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". | |
27 |
|
27 | |||
28 |
Example: |
|
28 | Example: | |
29 | dpath = "/home/myuser/data" |
|
29 | dpath = "/home/myuser/data" | |
30 |
|
30 | |||
31 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) |
|
31 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) | |
32 |
|
32 | |||
33 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) |
|
33 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) | |
34 |
|
34 | |||
35 | readerObj = SpectraReader() |
|
35 | readerObj = SpectraReader() | |
36 |
|
36 | |||
37 | readerObj.setup(dpath, startTime, endTime) |
|
37 | readerObj.setup(dpath, startTime, endTime) | |
38 |
|
38 | |||
39 | while(True): |
|
39 | while(True): | |
40 |
|
40 | |||
41 | readerObj.getData() |
|
41 | readerObj.getData() | |
42 |
|
42 | |||
43 | print readerObj.data_spc |
|
43 | print readerObj.data_spc | |
44 |
|
44 | |||
45 | print readerObj.data_cspc |
|
45 | print readerObj.data_cspc | |
46 |
|
46 | |||
47 | print readerObj.data_dc |
|
47 | print readerObj.data_dc | |
48 |
|
48 | |||
49 | if readerObj.flagNoMoreFiles: |
|
49 | if readerObj.flagNoMoreFiles: | |
50 | break |
|
50 | break | |
51 |
|
51 | |||
52 | """ |
|
52 | """ | |
53 |
|
53 | |||
54 | pts2read_SelfSpectra = 0 |
|
54 | pts2read_SelfSpectra = 0 | |
55 |
|
55 | |||
56 | pts2read_CrossSpectra = 0 |
|
56 | pts2read_CrossSpectra = 0 | |
57 |
|
57 | |||
58 | pts2read_DCchannels = 0 |
|
58 | pts2read_DCchannels = 0 | |
59 |
|
59 | |||
60 | ext = ".pdata" |
|
60 | ext = ".pdata" | |
61 |
|
61 | |||
62 | optchar = "P" |
|
62 | optchar = "P" | |
63 |
|
63 | |||
64 | dataOut = None |
|
64 | dataOut = None | |
65 |
|
65 | |||
66 | nRdChannels = None |
|
66 | nRdChannels = None | |
67 |
|
67 | |||
68 | nRdPairs = None |
|
68 | nRdPairs = None | |
69 |
|
69 | |||
70 | rdPairList = [] |
|
70 | rdPairList = [] | |
71 |
|
71 | |||
72 | def __init__(self): |
|
72 | def __init__(self, **kwargs): | |
73 |
""" |
|
73 | """ | |
74 | Inicializador de la clase SpectraReader para la lectura de datos de espectros. |
|
74 | Inicializador de la clase SpectraReader para la lectura de datos de espectros. | |
75 |
|
75 | |||
76 |
Inputs: |
|
76 | Inputs: | |
77 | dataOut : Objeto de la clase Spectra. Este objeto sera utilizado para |
|
77 | dataOut : Objeto de la clase Spectra. Este objeto sera utilizado para | |
78 | almacenar un perfil de datos cada vez que se haga un requerimiento |
|
78 | almacenar un perfil de datos cada vez que se haga un requerimiento | |
79 | (getData). El perfil sera obtenido a partir del buffer de datos, |
|
79 | (getData). El perfil sera obtenido a partir del buffer de datos, | |
80 | si el buffer esta vacio se hara un nuevo proceso de lectura de un |
|
80 | si el buffer esta vacio se hara un nuevo proceso de lectura de un | |
81 | bloque de datos. |
|
81 | bloque de datos. | |
82 | Si este parametro no es pasado se creara uno internamente. |
|
82 | Si este parametro no es pasado se creara uno internamente. | |
83 |
|
83 | |||
84 |
Affected: |
|
84 | Affected: | |
85 | self.dataOut |
|
85 | self.dataOut | |
86 |
|
86 | |||
87 | Return : None |
|
87 | Return : None | |
88 | """ |
|
88 | """ | |
89 |
|
89 | |||
90 | #Eliminar de la base la herencia |
|
90 | #Eliminar de la base la herencia | |
91 | ProcessingUnit.__init__(self) |
|
91 | ProcessingUnit.__init__(self, **kwargs) | |
92 |
|
92 | |||
93 | # self.isConfig = False |
|
93 | # self.isConfig = False | |
94 |
|
94 | |||
95 | self.pts2read_SelfSpectra = 0 |
|
95 | self.pts2read_SelfSpectra = 0 | |
96 |
|
96 | |||
97 | self.pts2read_CrossSpectra = 0 |
|
97 | self.pts2read_CrossSpectra = 0 | |
98 |
|
98 | |||
99 | self.pts2read_DCchannels = 0 |
|
99 | self.pts2read_DCchannels = 0 | |
100 |
|
100 | |||
101 | self.datablock = None |
|
101 | self.datablock = None | |
102 |
|
102 | |||
103 | self.utc = None |
|
103 | self.utc = None | |
104 |
|
104 | |||
105 | self.ext = ".pdata" |
|
105 | self.ext = ".pdata" | |
106 |
|
106 | |||
107 | self.optchar = "P" |
|
107 | self.optchar = "P" | |
108 |
|
108 | |||
109 | self.basicHeaderObj = BasicHeader(LOCALTIME) |
|
109 | self.basicHeaderObj = BasicHeader(LOCALTIME) | |
110 |
|
110 | |||
111 | self.systemHeaderObj = SystemHeader() |
|
111 | self.systemHeaderObj = SystemHeader() | |
112 |
|
112 | |||
113 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
113 | self.radarControllerHeaderObj = RadarControllerHeader() | |
114 |
|
114 | |||
115 | self.processingHeaderObj = ProcessingHeader() |
|
115 | self.processingHeaderObj = ProcessingHeader() | |
116 |
|
116 | |||
117 | self.online = 0 |
|
117 | self.online = 0 | |
118 |
|
118 | |||
119 | self.fp = None |
|
119 | self.fp = None | |
120 |
|
120 | |||
121 | self.idFile = None |
|
121 | self.idFile = None | |
122 |
|
122 | |||
123 | self.dtype = None |
|
123 | self.dtype = None | |
124 |
|
124 | |||
125 | self.fileSizeByHeader = None |
|
125 | self.fileSizeByHeader = None | |
126 |
|
126 | |||
127 | self.filenameList = [] |
|
127 | self.filenameList = [] | |
128 |
|
128 | |||
129 | self.filename = None |
|
129 | self.filename = None | |
130 |
|
130 | |||
131 | self.fileSize = None |
|
131 | self.fileSize = None | |
132 |
|
132 | |||
133 | self.firstHeaderSize = 0 |
|
133 | self.firstHeaderSize = 0 | |
134 |
|
134 | |||
135 | self.basicHeaderSize = 24 |
|
135 | self.basicHeaderSize = 24 | |
136 |
|
136 | |||
137 | self.pathList = [] |
|
137 | self.pathList = [] | |
138 |
|
138 | |||
139 | self.lastUTTime = 0 |
|
139 | self.lastUTTime = 0 | |
140 |
|
140 | |||
141 | self.maxTimeStep = 30 |
|
141 | self.maxTimeStep = 30 | |
142 |
|
142 | |||
143 | self.flagNoMoreFiles = 0 |
|
143 | self.flagNoMoreFiles = 0 | |
144 |
|
144 | |||
145 | self.set = 0 |
|
145 | self.set = 0 | |
146 |
|
146 | |||
147 | self.path = None |
|
147 | self.path = None | |
148 |
|
148 | |||
149 | self.delay = 60 #seconds |
|
149 | self.delay = 60 #seconds | |
150 |
|
150 | |||
151 | self.nTries = 3 #quantity tries |
|
151 | self.nTries = 3 #quantity tries | |
152 |
|
152 | |||
153 | self.nFiles = 3 #number of files for searching |
|
153 | self.nFiles = 3 #number of files for searching | |
154 |
|
154 | |||
155 | self.nReadBlocks = 0 |
|
155 | self.nReadBlocks = 0 | |
156 |
|
156 | |||
157 | self.flagIsNewFile = 1 |
|
157 | self.flagIsNewFile = 1 | |
158 |
|
158 | |||
159 | self.__isFirstTimeOnline = 1 |
|
159 | self.__isFirstTimeOnline = 1 | |
160 |
|
160 | |||
161 | # self.ippSeconds = 0 |
|
161 | # self.ippSeconds = 0 | |
162 |
|
162 | |||
163 |
self.flagDiscontinuousBlock = 0 |
|
163 | self.flagDiscontinuousBlock = 0 | |
164 |
|
164 | |||
165 | self.flagIsNewBlock = 0 |
|
165 | self.flagIsNewBlock = 0 | |
166 |
|
166 | |||
167 | self.nTotalBlocks = 0 |
|
167 | self.nTotalBlocks = 0 | |
168 |
|
168 | |||
169 | self.blocksize = 0 |
|
169 | self.blocksize = 0 | |
170 |
|
170 | |||
171 | self.dataOut = self.createObjByDefault() |
|
171 | self.dataOut = self.createObjByDefault() | |
172 |
|
172 | |||
173 | self.profileIndex = 1 #Always |
|
173 | self.profileIndex = 1 #Always | |
174 |
|
174 | |||
175 |
|
175 | |||
176 | def createObjByDefault(self): |
|
176 | def createObjByDefault(self): | |
177 |
|
177 | |||
178 | dataObj = Spectra() |
|
178 | dataObj = Spectra() | |
179 |
|
179 | |||
180 | return dataObj |
|
180 | return dataObj | |
181 |
|
181 | |||
182 | def __hasNotDataInBuffer(self): |
|
182 | def __hasNotDataInBuffer(self): | |
183 | return 1 |
|
183 | return 1 | |
184 |
|
184 | |||
@@ -186,7 +186,7 class SpectraReader(JRODataReader, ProcessingUnit): | |||||
186 | def getBlockDimension(self): |
|
186 | def getBlockDimension(self): | |
187 | """ |
|
187 | """ | |
188 | Obtiene la cantidad de puntos a leer por cada bloque de datos |
|
188 | Obtiene la cantidad de puntos a leer por cada bloque de datos | |
189 |
|
189 | |||
190 | Affected: |
|
190 | Affected: | |
191 | self.nRdChannels |
|
191 | self.nRdChannels | |
192 | self.nRdPairs |
|
192 | self.nRdPairs | |
@@ -203,10 +203,10 class SpectraReader(JRODataReader, ProcessingUnit): | |||||
203 | self.nRdChannels = 0 |
|
203 | self.nRdChannels = 0 | |
204 | self.nRdPairs = 0 |
|
204 | self.nRdPairs = 0 | |
205 | self.rdPairList = [] |
|
205 | self.rdPairList = [] | |
206 |
|
206 | |||
207 | for i in range(0, self.processingHeaderObj.totalSpectra*2, 2): |
|
207 | for i in range(0, self.processingHeaderObj.totalSpectra*2, 2): | |
208 | if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]: |
|
208 | if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]: | |
209 |
self.nRdChannels = self.nRdChannels + 1 #par de canales iguales |
|
209 | self.nRdChannels = self.nRdChannels + 1 #par de canales iguales | |
210 | else: |
|
210 | else: | |
211 | self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes |
|
211 | self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes | |
212 | self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1])) |
|
212 | self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1])) | |
@@ -215,29 +215,29 class SpectraReader(JRODataReader, ProcessingUnit): | |||||
215 |
|
215 | |||
216 | self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read) |
|
216 | self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read) | |
217 | self.blocksize = self.pts2read_SelfSpectra |
|
217 | self.blocksize = self.pts2read_SelfSpectra | |
218 |
|
218 | |||
219 | if self.processingHeaderObj.flag_cspc: |
|
219 | if self.processingHeaderObj.flag_cspc: | |
220 | self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read) |
|
220 | self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read) | |
221 | self.blocksize += self.pts2read_CrossSpectra |
|
221 | self.blocksize += self.pts2read_CrossSpectra | |
222 |
|
222 | |||
223 | if self.processingHeaderObj.flag_dc: |
|
223 | if self.processingHeaderObj.flag_dc: | |
224 | self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights) |
|
224 | self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights) | |
225 | self.blocksize += self.pts2read_DCchannels |
|
225 | self.blocksize += self.pts2read_DCchannels | |
226 |
|
226 | |||
227 | # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels |
|
227 | # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels | |
228 |
|
228 | |||
229 |
|
229 | |||
230 | def readBlock(self): |
|
230 | def readBlock(self): | |
231 | """ |
|
231 | """ | |
232 | Lee el bloque de datos desde la posicion actual del puntero del archivo |
|
232 | Lee el bloque de datos desde la posicion actual del puntero del archivo | |
233 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos |
|
233 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos | |
234 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer |
|
234 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer | |
235 | es seteado a 0 |
|
235 | es seteado a 0 | |
236 |
|
236 | |||
237 | Return: None |
|
237 | Return: None | |
238 |
|
238 | |||
239 | Variables afectadas: |
|
239 | Variables afectadas: | |
240 |
|
240 | |||
241 | self.flagIsNewFile |
|
241 | self.flagIsNewFile | |
242 | self.flagIsNewBlock |
|
242 | self.flagIsNewBlock | |
243 | self.nTotalBlocks |
|
243 | self.nTotalBlocks | |
@@ -245,7 +245,7 class SpectraReader(JRODataReader, ProcessingUnit): | |||||
245 | self.data_cspc |
|
245 | self.data_cspc | |
246 | self.data_dc |
|
246 | self.data_dc | |
247 |
|
247 | |||
248 |
Exceptions: |
|
248 | Exceptions: | |
249 | Si un bloque leido no es un bloque valido |
|
249 | Si un bloque leido no es un bloque valido | |
250 | """ |
|
250 | """ | |
251 | blockOk_flag = False |
|
251 | blockOk_flag = False | |
@@ -253,35 +253,35 class SpectraReader(JRODataReader, ProcessingUnit): | |||||
253 |
|
253 | |||
254 | spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra ) |
|
254 | spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra ) | |
255 | spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D |
|
255 | spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D | |
256 |
|
256 | |||
257 | if self.processingHeaderObj.flag_cspc: |
|
257 | if self.processingHeaderObj.flag_cspc: | |
258 | cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra ) |
|
258 | cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra ) | |
259 | cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D |
|
259 | cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D | |
260 |
|
260 | |||
261 | if self.processingHeaderObj.flag_dc: |
|
261 | if self.processingHeaderObj.flag_dc: | |
262 | dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) ) |
|
262 | dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) ) | |
263 | dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D |
|
263 | dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D | |
264 |
|
264 | |||
265 |
|
265 | |||
266 | if not(self.processingHeaderObj.shif_fft): |
|
266 | if not(self.processingHeaderObj.shif_fft): | |
267 | #desplaza a la derecha en el eje 2 determinadas posiciones |
|
267 | #desplaza a la derecha en el eje 2 determinadas posiciones | |
268 | shift = int(self.processingHeaderObj.profilesPerBlock/2) |
|
268 | shift = int(self.processingHeaderObj.profilesPerBlock/2) | |
269 | spc = numpy.roll( spc, shift , axis=2 ) |
|
269 | spc = numpy.roll( spc, shift , axis=2 ) | |
270 |
|
270 | |||
271 | if self.processingHeaderObj.flag_cspc: |
|
271 | if self.processingHeaderObj.flag_cspc: | |
272 | #desplaza a la derecha en el eje 2 determinadas posiciones |
|
272 | #desplaza a la derecha en el eje 2 determinadas posiciones | |
273 | cspc = numpy.roll( cspc, shift, axis=2 ) |
|
273 | cspc = numpy.roll( cspc, shift, axis=2 ) | |
274 |
|
274 | |||
275 | #Dimensions : nChannels, nProfiles, nSamples |
|
275 | #Dimensions : nChannels, nProfiles, nSamples | |
276 | spc = numpy.transpose( spc, (0,2,1) ) |
|
276 | spc = numpy.transpose( spc, (0,2,1) ) | |
277 | self.data_spc = spc |
|
277 | self.data_spc = spc | |
278 |
|
278 | |||
279 |
if self.processingHeaderObj.flag_cspc: |
|
279 | if self.processingHeaderObj.flag_cspc: | |
280 | cspc = numpy.transpose( cspc, (0,2,1) ) |
|
280 | cspc = numpy.transpose( cspc, (0,2,1) ) | |
281 | self.data_cspc = cspc['real'] + cspc['imag']*1j |
|
281 | self.data_cspc = cspc['real'] + cspc['imag']*1j | |
282 | else: |
|
282 | else: | |
283 | self.data_cspc = None |
|
283 | self.data_cspc = None | |
284 |
|
284 | |||
285 | if self.processingHeaderObj.flag_dc: |
|
285 | if self.processingHeaderObj.flag_dc: | |
286 | self.data_dc = dc['real'] + dc['imag']*1j |
|
286 | self.data_dc = dc['real'] + dc['imag']*1j | |
287 | else: |
|
287 | else: | |
@@ -294,60 +294,60 class SpectraReader(JRODataReader, ProcessingUnit): | |||||
294 | self.nReadBlocks += 1 |
|
294 | self.nReadBlocks += 1 | |
295 |
|
295 | |||
296 | return 1 |
|
296 | return 1 | |
297 |
|
297 | |||
298 | def getFirstHeader(self): |
|
298 | def getFirstHeader(self): | |
299 |
|
299 | |||
300 | self.getBasicHeader() |
|
300 | self.getBasicHeader() | |
301 |
|
301 | |||
302 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() |
|
302 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() | |
303 |
|
303 | |||
304 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() |
|
304 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() | |
305 |
|
305 | |||
306 | # self.dataOut.ippSeconds = self.ippSeconds |
|
306 | # self.dataOut.ippSeconds = self.ippSeconds | |
307 |
|
307 | |||
308 | # self.dataOut.timeInterval = self.radarControllerHeaderObj.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.processingHeaderObj.profilesPerBlock |
|
308 | # self.dataOut.timeInterval = self.radarControllerHeaderObj.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.processingHeaderObj.profilesPerBlock | |
309 |
|
309 | |||
310 | self.dataOut.dtype = self.dtype |
|
310 | self.dataOut.dtype = self.dtype | |
311 |
|
311 | |||
312 | # self.dataOut.nPairs = self.nPairs |
|
312 | # self.dataOut.nPairs = self.nPairs | |
313 |
|
313 | |||
314 | self.dataOut.pairsList = self.rdPairList |
|
314 | self.dataOut.pairsList = self.rdPairList | |
315 |
|
315 | |||
316 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock |
|
316 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock | |
317 |
|
317 | |||
318 | self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock |
|
318 | self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock | |
319 |
|
319 | |||
320 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt |
|
320 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt | |
321 |
|
321 | |||
322 | self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt |
|
322 | self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt | |
323 |
|
323 | |||
324 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight |
|
324 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight | |
325 |
|
325 | |||
326 |
self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) |
|
326 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) | |
327 |
|
327 | |||
328 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) |
|
328 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) | |
329 |
|
329 | |||
330 | self.dataOut.flagShiftFFT = True #Data is always shifted |
|
330 | self.dataOut.flagShiftFFT = True #Data is always shifted | |
331 |
|
331 | |||
332 | self.dataOut.flagDecodeData = self.processingHeaderObj.flag_decode #asumo q la data no esta decodificada |
|
332 | self.dataOut.flagDecodeData = self.processingHeaderObj.flag_decode #asumo q la data no esta decodificada | |
333 |
|
333 | |||
334 |
self.dataOut.flagDeflipData = self.processingHeaderObj.flag_deflip #asumo q la data esta sin flip |
|
334 | self.dataOut.flagDeflipData = self.processingHeaderObj.flag_deflip #asumo q la data esta sin flip | |
335 |
|
335 | |||
336 | def getData(self): |
|
336 | def getData(self): | |
337 | """ |
|
337 | """ | |
338 | First method to execute before "RUN" is called. |
|
338 | First method to execute before "RUN" is called. | |
339 |
|
339 | |||
340 | Copia el buffer de lectura a la clase "Spectra", |
|
340 | Copia el buffer de lectura a la clase "Spectra", | |
341 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de |
|
341 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de | |
342 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" |
|
342 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" | |
343 |
|
343 | |||
344 | Return: |
|
344 | Return: | |
345 | 0 : Si no hay mas archivos disponibles |
|
345 | 0 : Si no hay mas archivos disponibles | |
346 | 1 : Si hizo una buena copia del buffer |
|
346 | 1 : Si hizo una buena copia del buffer | |
347 |
|
347 | |||
348 | Affected: |
|
348 | Affected: | |
349 | self.dataOut |
|
349 | self.dataOut | |
350 |
|
350 | |||
351 | self.flagDiscontinuousBlock |
|
351 | self.flagDiscontinuousBlock | |
352 | self.flagIsNewBlock |
|
352 | self.flagIsNewBlock | |
353 | """ |
|
353 | """ | |
@@ -356,68 +356,68 class SpectraReader(JRODataReader, ProcessingUnit): | |||||
356 | self.dataOut.flagNoData = True |
|
356 | self.dataOut.flagNoData = True | |
357 | print 'Process finished' |
|
357 | print 'Process finished' | |
358 | return 0 |
|
358 | return 0 | |
359 |
|
359 | |||
360 | self.flagDiscontinuousBlock = 0 |
|
360 | self.flagDiscontinuousBlock = 0 | |
361 | self.flagIsNewBlock = 0 |
|
361 | self.flagIsNewBlock = 0 | |
362 |
|
362 | |||
363 |
if self.__hasNotDataInBuffer(): |
|
363 | if self.__hasNotDataInBuffer(): | |
364 |
|
364 | |||
365 | if not( self.readNextBlock() ): |
|
365 | if not( self.readNextBlock() ): | |
366 | self.dataOut.flagNoData = True |
|
366 | self.dataOut.flagNoData = True | |
367 | return 0 |
|
367 | return 0 | |
368 |
|
368 | |||
369 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) |
|
369 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) | |
370 |
|
370 | |||
371 | if self.data_spc is None: |
|
371 | if self.data_spc is None: | |
372 | self.dataOut.flagNoData = True |
|
372 | self.dataOut.flagNoData = True | |
373 | return 0 |
|
373 | return 0 | |
374 |
|
374 | |||
375 | self.getBasicHeader() |
|
375 | self.getBasicHeader() | |
376 |
|
376 | |||
377 | self.getFirstHeader() |
|
377 | self.getFirstHeader() | |
378 |
|
378 | |||
379 | self.dataOut.data_spc = self.data_spc |
|
379 | self.dataOut.data_spc = self.data_spc | |
380 |
|
380 | |||
381 | self.dataOut.data_cspc = self.data_cspc |
|
381 | self.dataOut.data_cspc = self.data_cspc | |
382 |
|
382 | |||
383 | self.dataOut.data_dc = self.data_dc |
|
383 | self.dataOut.data_dc = self.data_dc | |
384 |
|
384 | |||
385 | self.dataOut.flagNoData = False |
|
385 | self.dataOut.flagNoData = False | |
386 |
|
386 | |||
387 | self.dataOut.realtime = self.online |
|
387 | self.dataOut.realtime = self.online | |
388 |
|
388 | |||
389 | return self.dataOut.data_spc |
|
389 | return self.dataOut.data_spc | |
390 |
|
390 | |||
391 | class SpectraWriter(JRODataWriter, Operation): |
|
391 | class SpectraWriter(JRODataWriter, Operation): | |
392 |
|
392 | |||
393 |
""" |
|
393 | """ | |
394 | Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura |
|
394 | Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura | |
395 |
de los datos siempre se realiza por bloques. |
|
395 | de los datos siempre se realiza por bloques. | |
396 | """ |
|
396 | """ | |
397 |
|
397 | |||
398 | ext = ".pdata" |
|
398 | ext = ".pdata" | |
399 |
|
399 | |||
400 | optchar = "P" |
|
400 | optchar = "P" | |
401 |
|
401 | |||
402 | shape_spc_Buffer = None |
|
402 | shape_spc_Buffer = None | |
403 |
|
403 | |||
404 | shape_cspc_Buffer = None |
|
404 | shape_cspc_Buffer = None | |
405 |
|
405 | |||
406 | shape_dc_Buffer = None |
|
406 | shape_dc_Buffer = None | |
407 |
|
407 | |||
408 | data_spc = None |
|
408 | data_spc = None | |
409 |
|
409 | |||
410 | data_cspc = None |
|
410 | data_cspc = None | |
411 |
|
411 | |||
412 | data_dc = None |
|
412 | data_dc = None | |
413 |
|
413 | |||
414 | # dataOut = None |
|
414 | # dataOut = None | |
415 |
|
415 | |||
416 | def __init__(self): |
|
416 | def __init__(self): | |
417 |
""" |
|
417 | """ | |
418 | Inicializador de la clase SpectraWriter para la escritura de datos de espectros. |
|
418 | Inicializador de la clase SpectraWriter para la escritura de datos de espectros. | |
419 |
|
419 | |||
420 |
Affected: |
|
420 | Affected: | |
421 | self.dataOut |
|
421 | self.dataOut | |
422 | self.basicHeaderObj |
|
422 | self.basicHeaderObj | |
423 | self.systemHeaderObj |
|
423 | self.systemHeaderObj | |
@@ -426,50 +426,50 class SpectraWriter(JRODataWriter, Operation): | |||||
426 |
|
426 | |||
427 | Return: None |
|
427 | Return: None | |
428 | """ |
|
428 | """ | |
429 |
|
429 | |||
430 | Operation.__init__(self) |
|
430 | Operation.__init__(self) | |
431 |
|
431 | |||
432 | self.isConfig = False |
|
432 | self.isConfig = False | |
433 |
|
433 | |||
434 | self.nTotalBlocks = 0 |
|
434 | self.nTotalBlocks = 0 | |
435 |
|
435 | |||
436 | self.data_spc = None |
|
436 | self.data_spc = None | |
437 |
|
437 | |||
438 | self.data_cspc = None |
|
438 | self.data_cspc = None | |
439 |
|
439 | |||
440 | self.data_dc = None |
|
440 | self.data_dc = None | |
441 |
|
441 | |||
442 | self.fp = None |
|
442 | self.fp = None | |
443 |
|
443 | |||
444 | self.flagIsNewFile = 1 |
|
444 | self.flagIsNewFile = 1 | |
445 |
|
445 | |||
446 |
self.nTotalBlocks = 0 |
|
446 | self.nTotalBlocks = 0 | |
447 |
|
447 | |||
448 | self.flagIsNewBlock = 0 |
|
448 | self.flagIsNewBlock = 0 | |
449 |
|
449 | |||
450 | self.setFile = None |
|
450 | self.setFile = None | |
451 |
|
451 | |||
452 | self.dtype = None |
|
452 | self.dtype = None | |
453 |
|
453 | |||
454 | self.path = None |
|
454 | self.path = None | |
455 |
|
455 | |||
456 | self.noMoreFiles = 0 |
|
456 | self.noMoreFiles = 0 | |
457 |
|
457 | |||
458 | self.filename = None |
|
458 | self.filename = None | |
459 |
|
459 | |||
460 | self.basicHeaderObj = BasicHeader(LOCALTIME) |
|
460 | self.basicHeaderObj = BasicHeader(LOCALTIME) | |
461 |
|
461 | |||
462 | self.systemHeaderObj = SystemHeader() |
|
462 | self.systemHeaderObj = SystemHeader() | |
463 |
|
463 | |||
464 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
464 | self.radarControllerHeaderObj = RadarControllerHeader() | |
465 |
|
465 | |||
466 | self.processingHeaderObj = ProcessingHeader() |
|
466 | self.processingHeaderObj = ProcessingHeader() | |
467 |
|
467 | |||
468 |
|
468 | |||
469 | def hasAllDataInBuffer(self): |
|
469 | def hasAllDataInBuffer(self): | |
470 | return 1 |
|
470 | return 1 | |
471 |
|
471 | |||
472 |
|
472 | |||
473 | def setBlockDimension(self): |
|
473 | def setBlockDimension(self): | |
474 | """ |
|
474 | """ | |
475 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque |
|
475 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque | |
@@ -488,15 +488,15 class SpectraWriter(JRODataWriter, Operation): | |||||
488 | self.shape_cspc_Buffer = (self.dataOut.nPairs, |
|
488 | self.shape_cspc_Buffer = (self.dataOut.nPairs, | |
489 | self.processingHeaderObj.nHeights, |
|
489 | self.processingHeaderObj.nHeights, | |
490 | self.processingHeaderObj.profilesPerBlock) |
|
490 | self.processingHeaderObj.profilesPerBlock) | |
491 |
|
491 | |||
492 | self.shape_dc_Buffer = (self.dataOut.nChannels, |
|
492 | self.shape_dc_Buffer = (self.dataOut.nChannels, | |
493 | self.processingHeaderObj.nHeights) |
|
493 | self.processingHeaderObj.nHeights) | |
494 |
|
494 | |||
495 |
|
495 | |||
496 | def writeBlock(self): |
|
496 | def writeBlock(self): | |
497 | """ |
|
497 | """ | |
498 | Escribe el buffer en el file designado |
|
498 | Escribe el buffer en el file designado | |
499 |
|
499 | |||
500 | Affected: |
|
500 | Affected: | |
501 | self.data_spc |
|
501 | self.data_spc | |
502 | self.data_cspc |
|
502 | self.data_cspc | |
@@ -504,11 +504,11 class SpectraWriter(JRODataWriter, Operation): | |||||
504 | self.flagIsNewFile |
|
504 | self.flagIsNewFile | |
505 | self.flagIsNewBlock |
|
505 | self.flagIsNewBlock | |
506 | self.nTotalBlocks |
|
506 | self.nTotalBlocks | |
507 |
self.nWriteBlocks |
|
507 | self.nWriteBlocks | |
508 |
|
508 | |||
509 | Return: None |
|
509 | Return: None | |
510 | """ |
|
510 | """ | |
511 |
|
511 | |||
512 | spc = numpy.transpose( self.data_spc, (0,2,1) ) |
|
512 | spc = numpy.transpose( self.data_spc, (0,2,1) ) | |
513 | if not( self.processingHeaderObj.shif_fft ): |
|
513 | if not( self.processingHeaderObj.shif_fft ): | |
514 | spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
514 | spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones | |
@@ -525,7 +525,7 class SpectraWriter(JRODataWriter, Operation): | |||||
525 | data['imag'] = cspc.imag |
|
525 | data['imag'] = cspc.imag | |
526 | data = data.reshape((-1)) |
|
526 | data = data.reshape((-1)) | |
527 | data.tofile(self.fp) |
|
527 | data.tofile(self.fp) | |
528 |
|
528 | |||
529 | if self.data_dc is not None: |
|
529 | if self.data_dc is not None: | |
530 | data = numpy.zeros( self.shape_dc_Buffer, self.dtype ) |
|
530 | data = numpy.zeros( self.shape_dc_Buffer, self.dtype ) | |
531 | dc = self.data_dc |
|
531 | dc = self.data_dc | |
@@ -535,40 +535,40 class SpectraWriter(JRODataWriter, Operation): | |||||
535 | data.tofile(self.fp) |
|
535 | data.tofile(self.fp) | |
536 |
|
536 | |||
537 | # self.data_spc.fill(0) |
|
537 | # self.data_spc.fill(0) | |
538 | # |
|
538 | # | |
539 | # if self.data_dc is not None: |
|
539 | # if self.data_dc is not None: | |
540 | # self.data_dc.fill(0) |
|
540 | # self.data_dc.fill(0) | |
541 | # |
|
541 | # | |
542 | # if self.data_cspc is not None: |
|
542 | # if self.data_cspc is not None: | |
543 | # self.data_cspc.fill(0) |
|
543 | # self.data_cspc.fill(0) | |
544 |
|
544 | |||
545 | self.flagIsNewFile = 0 |
|
545 | self.flagIsNewFile = 0 | |
546 | self.flagIsNewBlock = 1 |
|
546 | self.flagIsNewBlock = 1 | |
547 | self.nTotalBlocks += 1 |
|
547 | self.nTotalBlocks += 1 | |
548 | self.nWriteBlocks += 1 |
|
548 | self.nWriteBlocks += 1 | |
549 | self.blockIndex += 1 |
|
549 | self.blockIndex += 1 | |
550 |
|
550 | |||
551 | # print "[Writing] Block = %d04" %self.blockIndex |
|
551 | # print "[Writing] Block = %d04" %self.blockIndex | |
552 |
|
552 | |||
553 | def putData(self): |
|
553 | def putData(self): | |
554 | """ |
|
554 | """ | |
555 |
Setea un bloque de datos y luego los escribe en un file |
|
555 | Setea un bloque de datos y luego los escribe en un file | |
556 |
|
556 | |||
557 | Affected: |
|
557 | Affected: | |
558 | self.data_spc |
|
558 | self.data_spc | |
559 | self.data_cspc |
|
559 | self.data_cspc | |
560 | self.data_dc |
|
560 | self.data_dc | |
561 |
|
561 | |||
562 |
Return: |
|
562 | Return: | |
563 |
0 : Si no hay data o no hay mas files que puedan escribirse |
|
563 | 0 : Si no hay data o no hay mas files que puedan escribirse | |
564 | 1 : Si se escribio la data de un bloque en un file |
|
564 | 1 : Si se escribio la data de un bloque en un file | |
565 | """ |
|
565 | """ | |
566 |
|
566 | |||
567 | if self.dataOut.flagNoData: |
|
567 | if self.dataOut.flagNoData: | |
568 | return 0 |
|
568 | return 0 | |
569 |
|
569 | |||
570 | self.flagIsNewBlock = 0 |
|
570 | self.flagIsNewBlock = 0 | |
571 |
|
571 | |||
572 | if self.dataOut.flagDiscontinuousBlock: |
|
572 | if self.dataOut.flagDiscontinuousBlock: | |
573 | self.data_spc.fill(0) |
|
573 | self.data_spc.fill(0) | |
574 | if self.dataOut.data_cspc is not None: |
|
574 | if self.dataOut.data_cspc is not None: | |
@@ -576,104 +576,104 class SpectraWriter(JRODataWriter, Operation): | |||||
576 | if self.dataOut.data_dc is not None: |
|
576 | if self.dataOut.data_dc is not None: | |
577 | self.data_dc.fill(0) |
|
577 | self.data_dc.fill(0) | |
578 | self.setNextFile() |
|
578 | self.setNextFile() | |
579 |
|
579 | |||
580 | if self.flagIsNewFile == 0: |
|
580 | if self.flagIsNewFile == 0: | |
581 | self.setBasicHeader() |
|
581 | self.setBasicHeader() | |
582 |
|
582 | |||
583 | self.data_spc = self.dataOut.data_spc.copy() |
|
583 | self.data_spc = self.dataOut.data_spc.copy() | |
584 |
|
584 | |||
585 | if self.dataOut.data_cspc is not None: |
|
585 | if self.dataOut.data_cspc is not None: | |
586 | self.data_cspc = self.dataOut.data_cspc.copy() |
|
586 | self.data_cspc = self.dataOut.data_cspc.copy() | |
587 |
|
587 | |||
588 | if self.dataOut.data_dc is not None: |
|
588 | if self.dataOut.data_dc is not None: | |
589 | self.data_dc = self.dataOut.data_dc.copy() |
|
589 | self.data_dc = self.dataOut.data_dc.copy() | |
590 |
|
590 | |||
591 | # #self.processingHeaderObj.dataBlocksPerFile) |
|
591 | # #self.processingHeaderObj.dataBlocksPerFile) | |
592 | if self.hasAllDataInBuffer(): |
|
592 | if self.hasAllDataInBuffer(): | |
593 | # self.setFirstHeader() |
|
593 | # self.setFirstHeader() | |
594 | self.writeNextBlock() |
|
594 | self.writeNextBlock() | |
595 |
|
595 | |||
596 | return 1 |
|
596 | return 1 | |
597 |
|
597 | |||
598 | def __getBlockSize(self): |
|
598 | def __getBlockSize(self): | |
599 | ''' |
|
599 | ''' | |
600 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra |
|
600 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra | |
601 | ''' |
|
601 | ''' | |
602 |
|
602 | |||
603 | dtype_width = self.getDtypeWidth() |
|
603 | dtype_width = self.getDtypeWidth() | |
604 |
|
604 | |||
605 | pts2write = self.dataOut.nHeights * self.dataOut.nFFTPoints |
|
605 | pts2write = self.dataOut.nHeights * self.dataOut.nFFTPoints | |
606 |
|
606 | |||
607 | pts2write_SelfSpectra = int(self.dataOut.nChannels * pts2write) |
|
607 | pts2write_SelfSpectra = int(self.dataOut.nChannels * pts2write) | |
608 | blocksize = (pts2write_SelfSpectra*dtype_width) |
|
608 | blocksize = (pts2write_SelfSpectra*dtype_width) | |
609 |
|
609 | |||
610 | if self.dataOut.data_cspc is not None: |
|
610 | if self.dataOut.data_cspc is not None: | |
611 | pts2write_CrossSpectra = int(self.dataOut.nPairs * pts2write) |
|
611 | pts2write_CrossSpectra = int(self.dataOut.nPairs * pts2write) | |
612 | blocksize += (pts2write_CrossSpectra*dtype_width*2) |
|
612 | blocksize += (pts2write_CrossSpectra*dtype_width*2) | |
613 |
|
613 | |||
614 | if self.dataOut.data_dc is not None: |
|
614 | if self.dataOut.data_dc is not None: | |
615 | pts2write_DCchannels = int(self.dataOut.nChannels * self.dataOut.nHeights) |
|
615 | pts2write_DCchannels = int(self.dataOut.nChannels * self.dataOut.nHeights) | |
616 | blocksize += (pts2write_DCchannels*dtype_width*2) |
|
616 | blocksize += (pts2write_DCchannels*dtype_width*2) | |
617 |
|
617 | |||
618 | # blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO |
|
618 | # blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO | |
619 |
|
619 | |||
620 | return blocksize |
|
620 | return blocksize | |
621 |
|
621 | |||
622 | def setFirstHeader(self): |
|
622 | def setFirstHeader(self): | |
623 |
|
623 | |||
624 | """ |
|
624 | """ | |
625 | Obtiene una copia del First Header |
|
625 | Obtiene una copia del First Header | |
626 |
|
626 | |||
627 | Affected: |
|
627 | Affected: | |
628 | self.systemHeaderObj |
|
628 | self.systemHeaderObj | |
629 | self.radarControllerHeaderObj |
|
629 | self.radarControllerHeaderObj | |
630 | self.dtype |
|
630 | self.dtype | |
631 |
|
631 | |||
632 |
Return: |
|
632 | Return: | |
633 | None |
|
633 | None | |
634 | """ |
|
634 | """ | |
635 |
|
635 | |||
636 | self.systemHeaderObj = self.dataOut.systemHeaderObj.copy() |
|
636 | self.systemHeaderObj = self.dataOut.systemHeaderObj.copy() | |
637 | self.systemHeaderObj.nChannels = self.dataOut.nChannels |
|
637 | self.systemHeaderObj.nChannels = self.dataOut.nChannels | |
638 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() |
|
638 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() | |
639 |
|
639 | |||
640 | self.processingHeaderObj.dtype = 1 # Spectra |
|
640 | self.processingHeaderObj.dtype = 1 # Spectra | |
641 | self.processingHeaderObj.blockSize = self.__getBlockSize() |
|
641 | self.processingHeaderObj.blockSize = self.__getBlockSize() | |
642 | self.processingHeaderObj.profilesPerBlock = self.dataOut.nFFTPoints |
|
642 | self.processingHeaderObj.profilesPerBlock = self.dataOut.nFFTPoints | |
643 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile |
|
643 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile | |
644 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows |
|
644 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows | |
645 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt# Se requiere para determinar el valor de timeInterval |
|
645 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt# Se requiere para determinar el valor de timeInterval | |
646 |
self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt |
|
646 | self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt | |
647 | self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels |
|
647 | self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels | |
648 | self.processingHeaderObj.shif_fft = self.dataOut.flagShiftFFT |
|
648 | self.processingHeaderObj.shif_fft = self.dataOut.flagShiftFFT | |
649 |
|
649 | |||
650 | if self.processingHeaderObj.totalSpectra > 0: |
|
650 | if self.processingHeaderObj.totalSpectra > 0: | |
651 | channelList = [] |
|
651 | channelList = [] | |
652 | for channel in range(self.dataOut.nChannels): |
|
652 | for channel in range(self.dataOut.nChannels): | |
653 | channelList.append(channel) |
|
653 | channelList.append(channel) | |
654 | channelList.append(channel) |
|
654 | channelList.append(channel) | |
655 |
|
655 | |||
656 | pairsList = [] |
|
656 | pairsList = [] | |
657 | if self.dataOut.nPairs > 0: |
|
657 | if self.dataOut.nPairs > 0: | |
658 | for pair in self.dataOut.pairsList: |
|
658 | for pair in self.dataOut.pairsList: | |
659 | pairsList.append(pair[0]) |
|
659 | pairsList.append(pair[0]) | |
660 | pairsList.append(pair[1]) |
|
660 | pairsList.append(pair[1]) | |
661 |
|
661 | |||
662 | spectraComb = channelList + pairsList |
|
662 | spectraComb = channelList + pairsList | |
663 | spectraComb = numpy.array(spectraComb, dtype="u1") |
|
663 | spectraComb = numpy.array(spectraComb, dtype="u1") | |
664 | self.processingHeaderObj.spectraComb = spectraComb |
|
664 | self.processingHeaderObj.spectraComb = spectraComb | |
665 |
|
665 | |||
666 | if self.dataOut.code is not None: |
|
666 | if self.dataOut.code is not None: | |
667 | self.processingHeaderObj.code = self.dataOut.code |
|
667 | self.processingHeaderObj.code = self.dataOut.code | |
668 | self.processingHeaderObj.nCode = self.dataOut.nCode |
|
668 | self.processingHeaderObj.nCode = self.dataOut.nCode | |
669 | self.processingHeaderObj.nBaud = self.dataOut.nBaud |
|
669 | self.processingHeaderObj.nBaud = self.dataOut.nBaud | |
670 |
|
670 | |||
671 | if self.processingHeaderObj.nWindows != 0: |
|
671 | if self.processingHeaderObj.nWindows != 0: | |
672 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] |
|
672 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] | |
673 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
673 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] | |
674 | self.processingHeaderObj.nHeights = self.dataOut.nHeights |
|
674 | self.processingHeaderObj.nHeights = self.dataOut.nHeights | |
675 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights |
|
675 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights | |
676 |
|
676 | |||
677 | self.processingHeaderObj.processFlags = self.getProcessFlags() |
|
677 | self.processingHeaderObj.processFlags = self.getProcessFlags() | |
678 |
|
678 | |||
679 | self.setBasicHeader() |
|
679 | self.setBasicHeader() |
@@ -27,7 +27,7 class ProcessingUnit(object): | |||||
27 | isConfig = False |
|
27 | isConfig = False | |
28 |
|
28 | |||
29 |
|
29 | |||
30 | def __init__(self): |
|
30 | def __init__(self, *args, **kwargs): | |
31 |
|
31 | |||
32 | self.dataIn = None |
|
32 | self.dataIn = None | |
33 | self.dataInList = [] |
|
33 | self.dataInList = [] | |
@@ -38,6 +38,9 class ProcessingUnit(object): | |||||
38 |
|
38 | |||
39 | self.isConfig = False |
|
39 | self.isConfig = False | |
40 |
|
40 | |||
|
41 | self.args = args | |||
|
42 | self.kwargs = kwargs | |||
|
43 | ||||
41 | def addOperation(self, opObj, objId): |
|
44 | def addOperation(self, opObj, objId): | |
42 |
|
45 | |||
43 | """ |
|
46 | """ | |
@@ -104,17 +107,13 class ProcessingUnit(object): | |||||
104 | methodToCall = getattr(self, name) |
|
107 | methodToCall = getattr(self, name) | |
105 |
|
108 | |||
106 | #Executing the self method |
|
109 | #Executing the self method | |
107 | methodToCall(**kwargs) |
|
|||
108 |
|
||||
109 | #Checkin the outputs |
|
|||
110 |
|
110 | |||
111 | # if name == 'run': |
|
111 | if hasattr(self, 'mp'): | |
112 |
|
|
112 | if self.mp is False: | |
113 | # else: |
|
113 | self.mp = True | |
114 |
|
|
114 | self.start() | |
115 | # |
|
115 | else: | |
116 | # if name != 'run': |
|
116 | methodToCall(**kwargs) | |
117 | # return True |
|
|||
118 |
|
117 | |||
119 | if self.dataOut is None: |
|
118 | if self.dataOut is None: | |
120 | return False |
|
119 | return False | |
@@ -124,7 +123,7 class ProcessingUnit(object): | |||||
124 |
|
123 | |||
125 | return True |
|
124 | return True | |
126 |
|
125 | |||
127 |
def callObject(self, objId |
|
126 | def callObject(self, objId): | |
128 |
|
127 | |||
129 | """ |
|
128 | """ | |
130 | Ejecuta la operacion asociada al identificador del objeto "objId" |
|
129 | Ejecuta la operacion asociada al identificador del objeto "objId" | |
@@ -140,16 +139,21 class ProcessingUnit(object): | |||||
140 | None |
|
139 | None | |
141 | """ |
|
140 | """ | |
142 |
|
141 | |||
143 | if self.dataOut.isEmpty(): |
|
142 | if self.dataOut is not None and self.dataOut.isEmpty(): | |
144 | return False |
|
143 | return False | |
145 |
|
144 | |||
146 | externalProcObj = self.operations2RunDict[objId] |
|
145 | externalProcObj = self.operations2RunDict[objId] | |
147 |
|
146 | |||
148 | externalProcObj.run(self.dataOut, **kwargs) |
|
147 | if hasattr(externalProcObj, 'mp'): | |
|
148 | if externalProcObj.mp is False: | |||
|
149 | externalProcObj.mp = True | |||
|
150 | externalProcObj.start() | |||
|
151 | else: | |||
|
152 | externalProcObj.run(self.dataOut, **externalProcObj.kwargs) | |||
149 |
|
153 | |||
150 | return True |
|
154 | return True | |
151 |
|
155 | |||
152 |
def call(self, opType, opName=None, opId=None |
|
156 | def call(self, opType, opName=None, opId=None): | |
153 |
|
157 | |||
154 | """ |
|
158 | """ | |
155 | Return True si ejecuta la operacion interna nombrada "opName" o la operacion externa |
|
159 | Return True si ejecuta la operacion interna nombrada "opName" o la operacion externa | |
@@ -194,7 +198,7 class ProcessingUnit(object): | |||||
194 | if not opName: |
|
198 | if not opName: | |
195 | raise ValueError, "opName parameter should be defined" |
|
199 | raise ValueError, "opName parameter should be defined" | |
196 |
|
200 | |||
197 | sts = self.callMethod(opName, **kwargs) |
|
201 | sts = self.callMethod(opName, **self.kwargs) | |
198 |
|
202 | |||
199 | elif opType == 'other' or opType == 'external' or opType == 'plotter': |
|
203 | elif opType == 'other' or opType == 'external' or opType == 'plotter': | |
200 |
|
204 | |||
@@ -204,7 +208,7 class ProcessingUnit(object): | |||||
204 | if opId not in self.operations2RunDict.keys(): |
|
208 | if opId not in self.operations2RunDict.keys(): | |
205 | raise ValueError, "Any operation with id=%s has been added" %str(opId) |
|
209 | raise ValueError, "Any operation with id=%s has been added" %str(opId) | |
206 |
|
210 | |||
207 |
sts = self.callObject(opId |
|
211 | sts = self.callObject(opId) | |
208 |
|
212 | |||
209 | else: |
|
213 | else: | |
210 | raise ValueError, "opType should be 'self', 'external' or 'plotter'; and not '%s'" %opType |
|
214 | raise ValueError, "opType should be 'self', 'external' or 'plotter'; and not '%s'" %opType | |
@@ -221,7 +225,7 class ProcessingUnit(object): | |||||
221 | return self.dataOut |
|
225 | return self.dataOut | |
222 |
|
226 | |||
223 | def checkInputs(self): |
|
227 | def checkInputs(self): | |
224 |
|
228 | |||
225 | for thisDataIn in self.dataInList: |
|
229 | for thisDataIn in self.dataInList: | |
226 |
|
230 | |||
227 | if thisDataIn.isEmpty(): |
|
231 | if thisDataIn.isEmpty(): | |
@@ -255,10 +259,11 class Operation(object): | |||||
255 | __buffer = None |
|
259 | __buffer = None | |
256 | isConfig = False |
|
260 | isConfig = False | |
257 |
|
261 | |||
258 | def __init__(self): |
|
262 | def __init__(self, **kwargs): | |
259 |
|
263 | |||
260 | self.__buffer = None |
|
264 | self.__buffer = None | |
261 | self.isConfig = False |
|
265 | self.isConfig = False | |
|
266 | self.kwargs = kwargs | |||
262 |
|
267 | |||
263 | def setup(self): |
|
268 | def setup(self): | |
264 |
|
269 |
@@ -16,6 +16,8 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 | |||
|
20 | MAXNUMY = 100 | |||
19 | throttle_value = 5 |
|
21 | throttle_value = 5 | |
20 |
|
22 | |||
21 | class PrettyFloat(float): |
|
23 | class PrettyFloat(float): | |
@@ -28,14 +30,6 def roundFloats(obj): | |||||
28 | elif isinstance(obj, float): |
|
30 | elif isinstance(obj, float): | |
29 | return round(obj, 2) |
|
31 | return round(obj, 2) | |
30 |
|
32 | |||
31 | def pretty_floats(obj): |
|
|||
32 | if isinstance(obj, float): |
|
|||
33 | return PrettyFloat(obj) |
|
|||
34 | elif isinstance(obj, dict): |
|
|||
35 | return dict((k, pretty_floats(v)) for k, v in obj.items()) |
|
|||
36 | elif isinstance(obj, (list, tuple)): |
|
|||
37 | return map(pretty_floats, obj) |
|
|||
38 | return obj |
|
|||
39 |
|
33 | |||
40 | class throttle(object): |
|
34 | class throttle(object): | |
41 | """Decorator that prevents a function from being called more than once every |
|
35 | """Decorator that prevents a function from being called more than once every | |
@@ -76,9 +70,6 class throttle(object): | |||||
76 | class PublishData(Operation): |
|
70 | class PublishData(Operation): | |
77 | """Clase publish.""" |
|
71 | """Clase publish.""" | |
78 |
|
72 | |||
79 | __MAXNUMX = 100 |
|
|||
80 | __MAXNUMY = 100 |
|
|||
81 |
|
||||
82 | def __init__(self, **kwargs): |
|
73 | def __init__(self, **kwargs): | |
83 | """Inicio.""" |
|
74 | """Inicio.""" | |
84 | Operation.__init__(self, **kwargs) |
|
75 | Operation.__init__(self, **kwargs) | |
@@ -146,12 +137,12 class PublishData(Operation): | |||||
146 | context = zmq.Context() |
|
137 | context = zmq.Context() | |
147 | self.zmq_socket = context.socket(zmq.PUSH) |
|
138 | self.zmq_socket = context.socket(zmq.PUSH) | |
148 | server = kwargs.get('server', 'zmq.pipe') |
|
139 | server = kwargs.get('server', 'zmq.pipe') | |
149 |
|
140 | |||
150 | if 'tcp://' in server: |
|
141 | if 'tcp://' in server: | |
151 | address = server |
|
142 | address = server | |
152 | else: |
|
143 | else: | |
153 | address = 'ipc:///tmp/%s' % server |
|
144 | address = 'ipc:///tmp/%s' % server | |
154 |
|
145 | |||
155 | self.zmq_socket.connect(address) |
|
146 | self.zmq_socket.connect(address) | |
156 | time.sleep(1) |
|
147 | time.sleep(1) | |
157 | print 'zeromq configured' |
|
148 | print 'zeromq configured' | |
@@ -166,8 +157,8 class PublishData(Operation): | |||||
166 | z = data/self.dataOut.normFactor |
|
157 | z = data/self.dataOut.normFactor | |
167 | zdB = 10*numpy.log10(z) |
|
158 | zdB = 10*numpy.log10(z) | |
168 | xlen, ylen = zdB[0].shape |
|
159 | xlen, ylen = zdB[0].shape | |
169 |
dx = |
|
160 | dx = int(xlen/MAXNUMX) + 1 | |
170 |
dy = |
|
161 | dy = int(ylen/MAXNUMY) + 1 | |
171 | Z = [0 for i in self.dataOut.channelList] |
|
162 | Z = [0 for i in self.dataOut.channelList] | |
172 | for i in self.dataOut.channelList: |
|
163 | for i in self.dataOut.channelList: | |
173 | Z[i] = zdB[i][::dx, ::dy].tolist() |
|
164 | Z[i] = zdB[i][::dx, ::dy].tolist() | |
@@ -237,7 +228,7 class PublishData(Operation): | |||||
237 | self.client.publish(self.topic + self.plottype, json.dumps(payload), qos=0) |
|
228 | self.client.publish(self.topic + self.plottype, json.dumps(payload), qos=0) | |
238 |
|
229 | |||
239 | if self.zeromq is 1: |
|
230 | if self.zeromq is 1: | |
240 |
print '[Sending] {} - {}'.format(self.dataOut.type, self.dataOut.datatime) |
|
231 | print '[Sending] {} - {}'.format(self.dataOut.type, self.dataOut.datatime) | |
241 | self.zmq_socket.send_pyobj(self.dataOut) |
|
232 | self.zmq_socket.send_pyobj(self.dataOut) | |
242 |
|
233 | |||
243 | def run(self, dataOut, **kwargs): |
|
234 | def run(self, dataOut, **kwargs): | |
@@ -257,3 +248,131 class PublishData(Operation): | |||||
257 | if self.client: |
|
248 | if self.client: | |
258 | self.client.loop_stop() |
|
249 | self.client.loop_stop() | |
259 | self.client.disconnect() |
|
250 | self.client.disconnect() | |
|
251 | ||||
|
252 | ||||
|
253 | class ReceiverData(ProcessingUnit, Process): | |||
|
254 | ||||
|
255 | def __init__(self, **kwargs): | |||
|
256 | ||||
|
257 | ProcessingUnit.__init__(self, **kwargs) | |||
|
258 | Process.__init__(self) | |||
|
259 | self.mp = False | |||
|
260 | self.isConfig = False | |||
|
261 | self.plottypes =[] | |||
|
262 | self.connections = 0 | |||
|
263 | server = kwargs.get('server', 'zmq.pipe') | |||
|
264 | if 'tcp://' in server: | |||
|
265 | address = server | |||
|
266 | else: | |||
|
267 | address = 'ipc:///tmp/%s' % server | |||
|
268 | ||||
|
269 | self.address = address | |||
|
270 | self.plottypes = [s.strip() for s in kwargs.get('plottypes', 'rti').split(',')] | |||
|
271 | self.realtime = kwargs.get('realtime', False) | |||
|
272 | global throttle_value | |||
|
273 | throttle_value = kwargs.get('throttle', 10) | |||
|
274 | self.setup() | |||
|
275 | ||||
|
276 | def setup(self): | |||
|
277 | ||||
|
278 | self.data = {} | |||
|
279 | self.data['times'] = [] | |||
|
280 | for plottype in self.plottypes: | |||
|
281 | self.data[plottype] = {} | |||
|
282 | ||||
|
283 | self.isConfig = True | |||
|
284 | ||||
|
285 | def event_monitor(self, monitor): | |||
|
286 | ||||
|
287 | events = {} | |||
|
288 | ||||
|
289 | for name in dir(zmq): | |||
|
290 | if name.startswith('EVENT_'): | |||
|
291 | value = getattr(zmq, name) | |||
|
292 | events[value] = name | |||
|
293 | ||||
|
294 | while monitor.poll(): | |||
|
295 | evt = recv_monitor_message(monitor) | |||
|
296 | if evt['event'] == 32: | |||
|
297 | self.connections += 1 | |||
|
298 | if evt['event'] == 512: | |||
|
299 | pass | |||
|
300 | if self.connections == 0 and self.started is True: | |||
|
301 | self.ended = True | |||
|
302 | # send('ENDED') | |||
|
303 | evt.update({'description': events[evt['event']]}) | |||
|
304 | ||||
|
305 | if evt['event'] == zmq.EVENT_MONITOR_STOPPED: | |||
|
306 | break | |||
|
307 | monitor.close() | |||
|
308 | print("event monitor thread done!") | |||
|
309 | ||||
|
310 | @throttle(seconds=throttle_value) | |||
|
311 | def sendData(self, data): | |||
|
312 | self.send(data) | |||
|
313 | ||||
|
314 | def send(self, data): | |||
|
315 | print '[sending] data=%s size=%s' % (data.keys(), len(data['times'])) | |||
|
316 | self.sender.send_pyobj(data) | |||
|
317 | ||||
|
318 | def update(self): | |||
|
319 | ||||
|
320 | t = self.dataOut.ltctime | |||
|
321 | self.data['times'].append(t) | |||
|
322 | self.data['dataOut'] = self.dataOut | |||
|
323 | ||||
|
324 | for plottype in self.plottypes: | |||
|
325 | ||||
|
326 | if plottype == 'spc': | |||
|
327 | z = self.dataOut.data_spc/self.dataOut.normFactor | |||
|
328 | zdB = 10*numpy.log10(z) | |||
|
329 | self.data[plottype] = zdB | |||
|
330 | if plottype == 'rti': | |||
|
331 | self.data[plottype][t] = self.dataOut.getPower() | |||
|
332 | if plottype == 'snr': | |||
|
333 | self.data[plottype][t] = 10*numpy.log10(self.dataOut.data_SNR) | |||
|
334 | if plottype == 'dop': | |||
|
335 | self.data[plottype][t] = 10*numpy.log10(self.dataOut.data_DOP) | |||
|
336 | if plottype == 'coh': | |||
|
337 | self.data[plottype][t] = self.dataOut.getCoherence() | |||
|
338 | if plottype == 'phase': | |||
|
339 | self.data[plottype][t] = self.dataOut.getCoherence(phase=True) | |||
|
340 | ||||
|
341 | def run(self): | |||
|
342 | ||||
|
343 | print '[Starting] {} from {}'.format(self.name, self.address) | |||
|
344 | ||||
|
345 | self.context = zmq.Context() | |||
|
346 | self.receiver = self.context.socket(zmq.PULL) | |||
|
347 | self.receiver.bind(self.address) | |||
|
348 | monitor = self.receiver.get_monitor_socket() | |||
|
349 | self.sender = self.context.socket(zmq.PUB) | |||
|
350 | ||||
|
351 | self.sender.bind("ipc:///tmp/zmq.plots") | |||
|
352 | ||||
|
353 | t = Thread(target=self.event_monitor, args=(monitor,)) | |||
|
354 | t.start() | |||
|
355 | ||||
|
356 | while True: | |||
|
357 | self.dataOut = self.receiver.recv_pyobj() | |||
|
358 | print '[Receiving] {} - {}'.format(self.dataOut.type, | |||
|
359 | self.dataOut.datatime.ctime()) | |||
|
360 | ||||
|
361 | self.update() | |||
|
362 | ||||
|
363 | if self.dataOut.finished is True: | |||
|
364 | self.send(self.data) | |||
|
365 | self.connections -= 1 | |||
|
366 | if self.connections==0 and self.started: | |||
|
367 | self.ended = True | |||
|
368 | self.data['ENDED'] = True | |||
|
369 | self.send(self.data) | |||
|
370 | self.setup() | |||
|
371 | else: | |||
|
372 | if self.realtime: | |||
|
373 | self.send(self.data) | |||
|
374 | else: | |||
|
375 | self.sendData(self.data) | |||
|
376 | self.started = True | |||
|
377 | ||||
|
378 | return |
General Comments 0
You need to be logged in to leave comments.
Login now