The requested changes are too big and content was truncated. Show full diff
@@ -1,1051 +1,1061 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on September , 2012 |
|
2 | Created on September , 2012 | |
3 | @author: |
|
3 | @author: | |
4 | ''' |
|
4 | ''' | |
5 | from xml.etree.ElementTree import Element, SubElement |
|
5 | from xml.etree.ElementTree import Element, SubElement | |
6 | from xml.etree import ElementTree as ET |
|
6 | from xml.etree import ElementTree as ET | |
7 | from xml.dom import minidom |
|
7 | from xml.dom import minidom | |
8 |
|
8 | |||
9 | #import datetime |
|
9 | #import datetime | |
10 | from model import * |
|
10 | from model import * | |
11 |
|
11 | |||
|
12 | try: | |||
|
13 | from gevent import sleep | |||
|
14 | except: | |||
|
15 | from time import sleep | |||
|
16 | ||||
12 | import ast |
|
17 | import ast | |
13 |
|
18 | |||
14 | def prettify(elem): |
|
19 | def prettify(elem): | |
15 | """Return a pretty-printed XML string for the Element. |
|
20 | """Return a pretty-printed XML string for the Element. | |
16 | """ |
|
21 | """ | |
17 | rough_string = ET.tostring(elem, 'utf-8') |
|
22 | rough_string = ET.tostring(elem, 'utf-8') | |
18 | reparsed = minidom.parseString(rough_string) |
|
23 | reparsed = minidom.parseString(rough_string) | |
19 | return reparsed.toprettyxml(indent=" ") |
|
24 | return reparsed.toprettyxml(indent=" ") | |
20 |
|
25 | |||
21 | class ParameterConf(): |
|
26 | class ParameterConf(): | |
22 |
|
27 | |||
23 | id = None |
|
28 | id = None | |
24 | name = None |
|
29 | name = None | |
25 | value = None |
|
30 | value = None | |
26 | format = None |
|
31 | format = None | |
27 |
|
32 | |||
28 | __formated_value = None |
|
33 | __formated_value = None | |
29 |
|
34 | |||
30 | ELEMENTNAME = 'Parameter' |
|
35 | ELEMENTNAME = 'Parameter' | |
31 |
|
36 | |||
32 | def __init__(self): |
|
37 | def __init__(self): | |
33 |
|
38 | |||
34 | self.format = 'str' |
|
39 | self.format = 'str' | |
35 |
|
40 | |||
36 | def getElementName(self): |
|
41 | def getElementName(self): | |
37 |
|
42 | |||
38 | return self.ELEMENTNAME |
|
43 | return self.ELEMENTNAME | |
39 |
|
44 | |||
40 | def getValue(self): |
|
45 | def getValue(self): | |
41 |
|
46 | |||
42 | if self.__formated_value != None: |
|
47 | if self.__formated_value != None: | |
43 |
|
48 | |||
44 | return self.__formated_value |
|
49 | return self.__formated_value | |
45 |
|
|
50 | ||
46 | value = self.value |
|
51 | value = self.value | |
47 |
|
52 | |||
48 | if self.format == 'bool': |
|
53 | if self.format == 'bool': | |
49 | value = int(value) |
|
54 | value = int(value) | |
50 |
|
55 | |||
51 | if self.format == 'list': |
|
56 | if self.format == 'list': | |
52 | strList = value.split(',') |
|
57 | strList = value.split(',') | |
53 |
|
58 | |||
54 | self.__formated_value = strList |
|
59 | self.__formated_value = strList | |
55 |
|
60 | |||
56 | return self.__formated_value |
|
61 | return self.__formated_value | |
57 |
|
62 | |||
58 | if self.format == 'intlist': |
|
63 | if self.format == 'intlist': | |
59 | """ |
|
64 | """ | |
60 | Example: |
|
65 | Example: | |
61 | value = (0,1,2) |
|
66 | value = (0,1,2) | |
62 | """ |
|
67 | """ | |
63 | value = value.replace('(', '') |
|
68 | value = value.replace('(', '') | |
64 | value = value.replace(')', '') |
|
69 | value = value.replace(')', '') | |
65 |
|
70 | |||
66 | value = value.replace('[', '') |
|
71 | value = value.replace('[', '') | |
67 | value = value.replace(']', '') |
|
72 | value = value.replace(']', '') | |
68 |
|
73 | |||
69 | strList = value.split(',') |
|
74 | strList = value.split(',') | |
70 | intList = [int(x) for x in strList] |
|
75 | intList = [int(x) for x in strList] | |
71 |
|
76 | |||
72 | self.__formated_value = intList |
|
77 | self.__formated_value = intList | |
73 |
|
78 | |||
74 | return self.__formated_value |
|
79 | return self.__formated_value | |
75 |
|
80 | |||
76 | if self.format == 'floatlist': |
|
81 | if self.format == 'floatlist': | |
77 | """ |
|
82 | """ | |
78 | Example: |
|
83 | Example: | |
79 | value = (0.5, 1.4, 2.7) |
|
84 | value = (0.5, 1.4, 2.7) | |
80 | """ |
|
85 | """ | |
81 |
|
86 | |||
82 | value = value.replace('(', '') |
|
87 | value = value.replace('(', '') | |
83 | value = value.replace(')', '') |
|
88 | value = value.replace(')', '') | |
84 |
|
89 | |||
85 | value = value.replace('[', '') |
|
90 | value = value.replace('[', '') | |
86 | value = value.replace(']', '') |
|
91 | value = value.replace(']', '') | |
87 |
|
92 | |||
88 | strList = value.split(',') |
|
93 | strList = value.split(',') | |
89 | floatList = [float(x) for x in strList] |
|
94 | floatList = [float(x) for x in strList] | |
90 |
|
95 | |||
91 | self.__formated_value = floatList |
|
96 | self.__formated_value = floatList | |
92 |
|
97 | |||
93 | return self.__formated_value |
|
98 | return self.__formated_value | |
94 |
|
99 | |||
95 | if self.format == 'date': |
|
100 | if self.format == 'date': | |
96 | strList = value.split('/') |
|
101 | strList = value.split('/') | |
97 | intList = [int(x) for x in strList] |
|
102 | intList = [int(x) for x in strList] | |
98 | date = datetime.date(intList[0], intList[1], intList[2]) |
|
103 | date = datetime.date(intList[0], intList[1], intList[2]) | |
99 |
|
104 | |||
100 | self.__formated_value = date |
|
105 | self.__formated_value = date | |
101 |
|
106 | |||
102 | return self.__formated_value |
|
107 | return self.__formated_value | |
103 |
|
108 | |||
104 | if self.format == 'time': |
|
109 | if self.format == 'time': | |
105 | strList = value.split(':') |
|
110 | strList = value.split(':') | |
106 | intList = [int(x) for x in strList] |
|
111 | intList = [int(x) for x in strList] | |
107 | time = datetime.time(intList[0], intList[1], intList[2]) |
|
112 | time = datetime.time(intList[0], intList[1], intList[2]) | |
108 |
|
113 | |||
109 | self.__formated_value = time |
|
114 | self.__formated_value = time | |
110 |
|
115 | |||
111 | return self.__formated_value |
|
116 | return self.__formated_value | |
112 |
|
117 | |||
113 | if self.format == 'pairslist': |
|
118 | if self.format == 'pairslist': | |
114 | """ |
|
119 | """ | |
115 | Example: |
|
120 | Example: | |
116 | value = (0,1),(1,2) |
|
121 | value = (0,1),(1,2) | |
117 | """ |
|
122 | """ | |
118 |
|
123 | |||
119 | value = value.replace('(', '') |
|
124 | value = value.replace('(', '') | |
120 | value = value.replace(')', '') |
|
125 | value = value.replace(')', '') | |
121 |
|
126 | |||
122 | value = value.replace('[', '') |
|
127 | value = value.replace('[', '') | |
123 | value = value.replace(']', '') |
|
128 | value = value.replace(']', '') | |
124 |
|
129 | |||
125 | strList = value.split(',') |
|
130 | strList = value.split(',') | |
126 | intList = [int(item) for item in strList] |
|
131 | intList = [int(item) for item in strList] | |
127 | pairList = [] |
|
132 | pairList = [] | |
128 | for i in range(len(intList)/2): |
|
133 | for i in range(len(intList)/2): | |
129 | pairList.append((intList[i*2], intList[i*2 + 1])) |
|
134 | pairList.append((intList[i*2], intList[i*2 + 1])) | |
130 |
|
135 | |||
131 | self.__formated_value = pairList |
|
136 | self.__formated_value = pairList | |
132 |
|
137 | |||
133 | return self.__formated_value |
|
138 | return self.__formated_value | |
134 |
|
139 | |||
135 | if self.format == 'multilist': |
|
140 | if self.format == 'multilist': | |
136 | """ |
|
141 | """ | |
137 | Example: |
|
142 | Example: | |
138 | value = (0,1,2),(3,4,5) |
|
143 | value = (0,1,2),(3,4,5) | |
139 | """ |
|
144 | """ | |
140 | multiList = ast.literal_eval(value) |
|
145 | multiList = ast.literal_eval(value) | |
141 |
|
146 | |||
142 | self.__formated_value = multiList |
|
147 | self.__formated_value = multiList | |
143 |
|
148 | |||
144 | return self.__formated_value |
|
149 | return self.__formated_value | |
145 |
|
150 | |||
146 | format_func = eval(self.format) |
|
151 | format_func = eval(self.format) | |
147 |
|
152 | |||
148 | self.__formated_value = format_func(value) |
|
153 | self.__formated_value = format_func(value) | |
149 |
|
154 | |||
150 | return self.__formated_value |
|
155 | return self.__formated_value | |
151 |
|
156 | |||
152 | def setup(self, id, name, value, format='str'): |
|
157 | def setup(self, id, name, value, format='str'): | |
153 |
|
158 | |||
154 | self.id = id |
|
159 | self.id = id | |
155 | self.name = name |
|
160 | self.name = name | |
156 | self.value = str(value) |
|
161 | self.value = str(value) | |
157 | self.format = str.lower(format) |
|
162 | self.format = str.lower(format) | |
158 |
|
163 | |||
159 | def update(self, name, value, format='str'): |
|
164 | def update(self, name, value, format='str'): | |
160 |
|
165 | |||
161 | self.name = name |
|
166 | self.name = name | |
162 | self.value = str(value) |
|
167 | self.value = str(value) | |
163 | self.format = format |
|
168 | self.format = format | |
164 |
|
169 | |||
165 | def makeXml(self, opElement): |
|
170 | def makeXml(self, opElement): | |
166 |
|
171 | |||
167 | parmElement = SubElement(opElement, self.ELEMENTNAME) |
|
172 | parmElement = SubElement(opElement, self.ELEMENTNAME) | |
168 | parmElement.set('id', str(self.id)) |
|
173 | parmElement.set('id', str(self.id)) | |
169 | parmElement.set('name', self.name) |
|
174 | parmElement.set('name', self.name) | |
170 | parmElement.set('value', self.value) |
|
175 | parmElement.set('value', self.value) | |
171 | parmElement.set('format', self.format) |
|
176 | parmElement.set('format', self.format) | |
172 |
|
177 | |||
173 | def readXml(self, parmElement): |
|
178 | def readXml(self, parmElement): | |
174 |
|
179 | |||
175 | self.id = parmElement.get('id') |
|
180 | self.id = parmElement.get('id') | |
176 | self.name = parmElement.get('name') |
|
181 | self.name = parmElement.get('name') | |
177 | self.value = parmElement.get('value') |
|
182 | self.value = parmElement.get('value') | |
178 | self.format = str.lower(parmElement.get('format')) |
|
183 | self.format = str.lower(parmElement.get('format')) | |
179 |
|
184 | |||
180 | #Compatible with old signal chain version |
|
185 | #Compatible with old signal chain version | |
181 | if self.format == 'int' and self.name == 'idfigure': |
|
186 | if self.format == 'int' and self.name == 'idfigure': | |
182 | self.name = 'id' |
|
187 | self.name = 'id' | |
183 |
|
188 | |||
184 | def printattr(self): |
|
189 | def printattr(self): | |
185 |
|
190 | |||
186 | print "Parameter[%s]: name = %s, value = %s, format = %s" %(self.id, self.name, self.value, self.format) |
|
191 | print "Parameter[%s]: name = %s, value = %s, format = %s" %(self.id, self.name, self.value, self.format) | |
187 |
|
192 | |||
188 | class OperationConf(): |
|
193 | class OperationConf(): | |
189 |
|
194 | |||
190 | id = None |
|
195 | id = None | |
191 | name = None |
|
196 | name = None | |
192 | priority = None |
|
197 | priority = None | |
193 | type = None |
|
198 | type = None | |
194 |
|
199 | |||
195 | parmConfObjList = [] |
|
200 | parmConfObjList = [] | |
196 |
|
201 | |||
197 | ELEMENTNAME = 'Operation' |
|
202 | ELEMENTNAME = 'Operation' | |
198 |
|
203 | |||
199 | def __init__(self): |
|
204 | def __init__(self): | |
200 |
|
205 | |||
201 | self.id = 0 |
|
206 | self.id = 0 | |
202 | self.name = None |
|
207 | self.name = None | |
203 | self.priority = None |
|
208 | self.priority = None | |
204 | self.type = 'self' |
|
209 | self.type = 'self' | |
205 |
|
210 | |||
206 |
|
211 | |||
207 | def __getNewId(self): |
|
212 | def __getNewId(self): | |
208 |
|
213 | |||
209 | return int(self.id)*10 + len(self.parmConfObjList) + 1 |
|
214 | return int(self.id)*10 + len(self.parmConfObjList) + 1 | |
210 |
|
215 | |||
211 | def getElementName(self): |
|
216 | def getElementName(self): | |
212 |
|
217 | |||
213 | return self.ELEMENTNAME |
|
218 | return self.ELEMENTNAME | |
214 |
|
219 | |||
215 | def getParameterObjList(self): |
|
220 | def getParameterObjList(self): | |
216 |
|
221 | |||
217 | return self.parmConfObjList |
|
222 | return self.parmConfObjList | |
218 |
|
223 | |||
219 | def getParameterObj(self, parameterName): |
|
224 | def getParameterObj(self, parameterName): | |
220 |
|
225 | |||
221 | for parmConfObj in self.parmConfObjList: |
|
226 | for parmConfObj in self.parmConfObjList: | |
222 |
|
227 | |||
223 | if parmConfObj.name != parameterName: |
|
228 | if parmConfObj.name != parameterName: | |
224 | continue |
|
229 | continue | |
225 |
|
230 | |||
226 | return parmConfObj |
|
231 | return parmConfObj | |
227 |
|
232 | |||
228 | return None |
|
233 | return None | |
229 |
|
234 | |||
230 | def getParameterObjfromValue(self,parameterValue): |
|
235 | def getParameterObjfromValue(self,parameterValue): | |
231 | for parmConfObj in self.parmConfObjList: |
|
236 | for parmConfObj in self.parmConfObjList: | |
232 |
|
237 | |||
233 | if parmConfObj.getValue() != parameterValue: |
|
238 | if parmConfObj.getValue() != parameterValue: | |
234 | continue |
|
239 | continue | |
235 |
|
240 | |||
236 | return parmConfObj.getValue() |
|
241 | return parmConfObj.getValue() | |
237 |
|
242 | |||
238 | return None |
|
243 | return None | |
239 |
|
244 | |||
240 | def getParameterValue(self, parameterName): |
|
245 | def getParameterValue(self, parameterName): | |
241 |
|
246 | |||
242 | parameterObj = self.getParameterObj(parameterName) |
|
247 | parameterObj = self.getParameterObj(parameterName) | |
243 | value = parameterObj.getValue() |
|
248 | value = parameterObj.getValue() | |
244 |
|
249 | |||
245 | return value |
|
250 | return value | |
246 |
|
251 | |||
247 | def setup(self, id, name, priority, type): |
|
252 | def setup(self, id, name, priority, type): | |
248 |
|
253 | |||
249 | self.id = id |
|
254 | self.id = id | |
250 | self.name = name |
|
255 | self.name = name | |
251 | self.type = type |
|
256 | self.type = type | |
252 | self.priority = priority |
|
257 | self.priority = priority | |
253 |
|
258 | |||
254 | self.parmConfObjList = [] |
|
259 | self.parmConfObjList = [] | |
255 |
|
260 | |||
256 | def removeParameters(self): |
|
261 | def removeParameters(self): | |
257 |
|
262 | |||
258 | for obj in self.parmConfObjList: |
|
263 | for obj in self.parmConfObjList: | |
259 | del obj |
|
264 | del obj | |
260 |
|
265 | |||
261 | self.parmConfObjList = [] |
|
266 | self.parmConfObjList = [] | |
262 |
|
267 | |||
263 | def addParameter(self, name, value, format='str'): |
|
268 | def addParameter(self, name, value, format='str'): | |
264 |
|
269 | |||
265 | id = self.__getNewId() |
|
270 | id = self.__getNewId() | |
266 |
|
271 | |||
267 | parmConfObj = ParameterConf() |
|
272 | parmConfObj = ParameterConf() | |
268 | parmConfObj.setup(id, name, value, format) |
|
273 | parmConfObj.setup(id, name, value, format) | |
269 |
|
274 | |||
270 | self.parmConfObjList.append(parmConfObj) |
|
275 | self.parmConfObjList.append(parmConfObj) | |
271 |
|
276 | |||
272 | return parmConfObj |
|
277 | return parmConfObj | |
273 |
|
278 | |||
274 | def changeParameter(self, name, value, format='str'): |
|
279 | def changeParameter(self, name, value, format='str'): | |
275 |
|
280 | |||
276 | parmConfObj = self.getParameterObj(name) |
|
281 | parmConfObj = self.getParameterObj(name) | |
277 | parmConfObj.update(name, value, format) |
|
282 | parmConfObj.update(name, value, format) | |
278 |
|
283 | |||
279 | return parmConfObj |
|
284 | return parmConfObj | |
280 |
|
285 | |||
281 | def makeXml(self, upElement): |
|
286 | def makeXml(self, upElement): | |
282 |
|
287 | |||
283 | opElement = SubElement(upElement, self.ELEMENTNAME) |
|
288 | opElement = SubElement(upElement, self.ELEMENTNAME) | |
284 | opElement.set('id', str(self.id)) |
|
289 | opElement.set('id', str(self.id)) | |
285 | opElement.set('name', self.name) |
|
290 | opElement.set('name', self.name) | |
286 | opElement.set('type', self.type) |
|
291 | opElement.set('type', self.type) | |
287 | opElement.set('priority', str(self.priority)) |
|
292 | opElement.set('priority', str(self.priority)) | |
288 |
|
293 | |||
289 | for parmConfObj in self.parmConfObjList: |
|
294 | for parmConfObj in self.parmConfObjList: | |
290 | parmConfObj.makeXml(opElement) |
|
295 | parmConfObj.makeXml(opElement) | |
291 |
|
296 | |||
292 | def readXml(self, opElement): |
|
297 | def readXml(self, opElement): | |
293 |
|
298 | |||
294 | self.id = opElement.get('id') |
|
299 | self.id = opElement.get('id') | |
295 | self.name = opElement.get('name') |
|
300 | self.name = opElement.get('name') | |
296 | self.type = opElement.get('type') |
|
301 | self.type = opElement.get('type') | |
297 | self.priority = opElement.get('priority') |
|
302 | self.priority = opElement.get('priority') | |
298 |
|
303 | |||
299 | #Compatible with old signal chain version |
|
304 | #Compatible with old signal chain version | |
300 | #Use of 'run' method instead 'init' |
|
305 | #Use of 'run' method instead 'init' | |
301 | if self.type == 'self' and self.name == 'init': |
|
306 | if self.type == 'self' and self.name == 'init': | |
302 | self.name = 'run' |
|
307 | self.name = 'run' | |
303 |
|
308 | |||
304 | self.parmConfObjList = [] |
|
309 | self.parmConfObjList = [] | |
305 |
|
310 | |||
306 | parmElementList = opElement.getiterator(ParameterConf().getElementName()) |
|
311 | parmElementList = opElement.getiterator(ParameterConf().getElementName()) | |
307 |
|
312 | |||
308 | for parmElement in parmElementList: |
|
313 | for parmElement in parmElementList: | |
309 | parmConfObj = ParameterConf() |
|
314 | parmConfObj = ParameterConf() | |
310 | parmConfObj.readXml(parmElement) |
|
315 | parmConfObj.readXml(parmElement) | |
311 |
|
316 | |||
312 | #Compatible with old signal chain version |
|
317 | #Compatible with old signal chain version | |
313 | #If an 'plot' OPERATION is found, changes name operation by the value of its type PARAMETER |
|
318 | #If an 'plot' OPERATION is found, changes name operation by the value of its type PARAMETER | |
314 | if self.type != 'self' and self.name == 'Plot': |
|
319 | if self.type != 'self' and self.name == 'Plot': | |
315 | if parmConfObj.format == 'str' and parmConfObj.name == 'type': |
|
320 | if parmConfObj.format == 'str' and parmConfObj.name == 'type': | |
316 | self.name = parmConfObj.value |
|
321 | self.name = parmConfObj.value | |
317 | continue |
|
322 | continue | |
318 |
|
323 | |||
319 | self.parmConfObjList.append(parmConfObj) |
|
324 | self.parmConfObjList.append(parmConfObj) | |
320 |
|
325 | |||
321 | def printattr(self): |
|
326 | def printattr(self): | |
322 |
|
327 | |||
323 | print "%s[%s]: name = %s, type = %s, priority = %s" %(self.ELEMENTNAME, |
|
328 | print "%s[%s]: name = %s, type = %s, priority = %s" %(self.ELEMENTNAME, | |
324 | self.id, |
|
329 | self.id, | |
325 | self.name, |
|
330 | self.name, | |
326 | self.type, |
|
331 | self.type, | |
327 | self.priority) |
|
332 | self.priority) | |
328 |
|
333 | |||
329 | for parmConfObj in self.parmConfObjList: |
|
334 | for parmConfObj in self.parmConfObjList: | |
330 | parmConfObj.printattr() |
|
335 | parmConfObj.printattr() | |
331 |
|
336 | |||
332 | def createObject(self): |
|
337 | def createObject(self): | |
333 |
|
338 | |||
334 | if self.type == 'self': |
|
339 | if self.type == 'self': | |
335 | raise ValueError, "This operation type cannot be created" |
|
340 | raise ValueError, "This operation type cannot be created" | |
336 |
|
341 | |||
337 | if self.type == 'external' or self.type == 'other': |
|
342 | if self.type == 'external' or self.type == 'other': | |
338 | className = eval(self.name) |
|
343 | className = eval(self.name) | |
339 | opObj = className() |
|
344 | opObj = className() | |
340 |
|
345 | |||
341 | return opObj |
|
346 | return opObj | |
342 |
|
347 | |||
343 | class ProcUnitConf(): |
|
348 | class ProcUnitConf(): | |
344 |
|
349 | |||
345 | id = None |
|
350 | id = None | |
346 | name = None |
|
351 | name = None | |
347 | datatype = None |
|
352 | datatype = None | |
348 | inputId = None |
|
353 | inputId = None | |
349 | parentId = None |
|
354 | parentId = None | |
350 |
|
355 | |||
351 | opConfObjList = [] |
|
356 | opConfObjList = [] | |
352 |
|
357 | |||
353 | procUnitObj = None |
|
358 | procUnitObj = None | |
354 | opObjList = [] |
|
359 | opObjList = [] | |
355 |
|
360 | |||
356 | ELEMENTNAME = 'ProcUnit' |
|
361 | ELEMENTNAME = 'ProcUnit' | |
357 |
|
362 | |||
358 | def __init__(self): |
|
363 | def __init__(self): | |
359 |
|
364 | |||
360 | self.id = None |
|
365 | self.id = None | |
361 | self.datatype = None |
|
366 | self.datatype = None | |
362 | self.name = None |
|
367 | self.name = None | |
363 | self.inputId = None |
|
368 | self.inputId = None | |
364 |
|
369 | |||
365 | self.opConfObjList = [] |
|
370 | self.opConfObjList = [] | |
366 |
|
371 | |||
367 | self.procUnitObj = None |
|
372 | self.procUnitObj = None | |
368 | self.opObjDict = {} |
|
373 | self.opObjDict = {} | |
369 |
|
374 | |||
370 | def __getPriority(self): |
|
375 | def __getPriority(self): | |
371 |
|
376 | |||
372 | return len(self.opConfObjList)+1 |
|
377 | return len(self.opConfObjList)+1 | |
373 |
|
378 | |||
374 | def __getNewId(self): |
|
379 | def __getNewId(self): | |
375 |
|
380 | |||
376 | return int(self.id)*10 + len(self.opConfObjList) + 1 |
|
381 | return int(self.id)*10 + len(self.opConfObjList) + 1 | |
377 |
|
382 | |||
378 | def getElementName(self): |
|
383 | def getElementName(self): | |
379 |
|
384 | |||
380 | return self.ELEMENTNAME |
|
385 | return self.ELEMENTNAME | |
381 |
|
386 | |||
382 | def getId(self): |
|
387 | def getId(self): | |
383 |
|
388 | |||
384 | return str(self.id) |
|
389 | return str(self.id) | |
385 |
|
390 | |||
386 | def getInputId(self): |
|
391 | def getInputId(self): | |
387 |
|
392 | |||
388 | return str(self.inputId) |
|
393 | return str(self.inputId) | |
389 |
|
394 | |||
390 | def getOperationObjList(self): |
|
395 | def getOperationObjList(self): | |
391 |
|
396 | |||
392 | return self.opConfObjList |
|
397 | return self.opConfObjList | |
393 |
|
398 | |||
394 | def getOperationObj(self, name=None): |
|
399 | def getOperationObj(self, name=None): | |
395 |
|
400 | |||
396 | for opConfObj in self.opConfObjList: |
|
401 | for opConfObj in self.opConfObjList: | |
397 |
|
402 | |||
398 | if opConfObj.name != name: |
|
403 | if opConfObj.name != name: | |
399 | continue |
|
404 | continue | |
400 |
|
405 | |||
401 | return opConfObj |
|
406 | return opConfObj | |
402 |
|
407 | |||
403 | return None |
|
408 | return None | |
404 |
|
409 | |||
405 | def getOpObjfromParamValue(self,value=None): |
|
410 | def getOpObjfromParamValue(self,value=None): | |
406 |
|
411 | |||
407 | for opConfObj in self.opConfObjList: |
|
412 | for opConfObj in self.opConfObjList: | |
408 | if opConfObj.getParameterObjfromValue(parameterValue=value) != value: |
|
413 | if opConfObj.getParameterObjfromValue(parameterValue=value) != value: | |
409 | continue |
|
414 | continue | |
410 | return opConfObj |
|
415 | return opConfObj | |
411 | return None |
|
416 | return None | |
412 |
|
417 | |||
413 | def getProcUnitObj(self): |
|
418 | def getProcUnitObj(self): | |
414 |
|
419 | |||
415 | return self.procUnitObj |
|
420 | return self.procUnitObj | |
416 |
|
421 | |||
417 | def setup(self, id, name, datatype, inputId, parentId=None): |
|
422 | def setup(self, id, name, datatype, inputId, parentId=None): | |
418 |
|
423 | |||
419 | self.id = id |
|
424 | self.id = id | |
420 | self.name = name |
|
425 | self.name = name | |
421 | self.datatype = datatype |
|
426 | self.datatype = datatype | |
422 | self.inputId = inputId |
|
427 | self.inputId = inputId | |
423 | self.parentId = parentId |
|
428 | self.parentId = parentId | |
424 |
|
429 | |||
425 | self.opConfObjList = [] |
|
430 | self.opConfObjList = [] | |
426 |
|
431 | |||
427 | self.addOperation(name='run', optype='self') |
|
432 | self.addOperation(name='run', optype='self') | |
428 |
|
433 | |||
429 | def removeOperations(self): |
|
434 | def removeOperations(self): | |
430 |
|
435 | |||
431 | for obj in self.opConfObjList: |
|
436 | for obj in self.opConfObjList: | |
432 | del obj |
|
437 | del obj | |
433 |
|
438 | |||
434 | self.opConfObjList = [] |
|
439 | self.opConfObjList = [] | |
435 | self.addOperation(name='run') |
|
440 | self.addOperation(name='run') | |
436 |
|
441 | |||
437 | def addParameter(self, **kwargs): |
|
442 | def addParameter(self, **kwargs): | |
438 | ''' |
|
443 | ''' | |
439 | Add parameters to "run" operation |
|
444 | Add parameters to "run" operation | |
440 | ''' |
|
445 | ''' | |
441 | opObj = self.opConfObjList[0] |
|
446 | opObj = self.opConfObjList[0] | |
442 |
|
447 | |||
443 | opObj.addParameter(**kwargs) |
|
448 | opObj.addParameter(**kwargs) | |
444 |
|
449 | |||
445 | return opObj |
|
450 | return opObj | |
446 |
|
451 | |||
447 | def addOperation(self, name, optype='self'): |
|
452 | def addOperation(self, name, optype='self'): | |
448 |
|
453 | |||
449 | id = self.__getNewId() |
|
454 | id = self.__getNewId() | |
450 | priority = self.__getPriority() |
|
455 | priority = self.__getPriority() | |
451 |
|
456 | |||
452 | opConfObj = OperationConf() |
|
457 | opConfObj = OperationConf() | |
453 | opConfObj.setup(id, name=name, priority=priority, type=optype) |
|
458 | opConfObj.setup(id, name=name, priority=priority, type=optype) | |
454 |
|
459 | |||
455 | self.opConfObjList.append(opConfObj) |
|
460 | self.opConfObjList.append(opConfObj) | |
456 |
|
461 | |||
457 | return opConfObj |
|
462 | return opConfObj | |
458 |
|
463 | |||
459 | def makeXml(self, procUnitElement): |
|
464 | def makeXml(self, procUnitElement): | |
460 |
|
465 | |||
461 | upElement = SubElement(procUnitElement, self.ELEMENTNAME) |
|
466 | upElement = SubElement(procUnitElement, self.ELEMENTNAME) | |
462 | upElement.set('id', str(self.id)) |
|
467 | upElement.set('id', str(self.id)) | |
463 | upElement.set('name', self.name) |
|
468 | upElement.set('name', self.name) | |
464 | upElement.set('datatype', self.datatype) |
|
469 | upElement.set('datatype', self.datatype) | |
465 | upElement.set('inputId', str(self.inputId)) |
|
470 | upElement.set('inputId', str(self.inputId)) | |
466 |
|
471 | |||
467 | for opConfObj in self.opConfObjList: |
|
472 | for opConfObj in self.opConfObjList: | |
468 | opConfObj.makeXml(upElement) |
|
473 | opConfObj.makeXml(upElement) | |
469 |
|
474 | |||
470 | def readXml(self, upElement): |
|
475 | def readXml(self, upElement): | |
471 |
|
476 | |||
472 | self.id = upElement.get('id') |
|
477 | self.id = upElement.get('id') | |
473 | self.name = upElement.get('name') |
|
478 | self.name = upElement.get('name') | |
474 | self.datatype = upElement.get('datatype') |
|
479 | self.datatype = upElement.get('datatype') | |
475 | self.inputId = upElement.get('inputId') |
|
480 | self.inputId = upElement.get('inputId') | |
476 |
|
481 | |||
477 | self.opConfObjList = [] |
|
482 | self.opConfObjList = [] | |
478 |
|
483 | |||
479 | opElementList = upElement.getiterator(OperationConf().getElementName()) |
|
484 | opElementList = upElement.getiterator(OperationConf().getElementName()) | |
480 |
|
485 | |||
481 | for opElement in opElementList: |
|
486 | for opElement in opElementList: | |
482 | opConfObj = OperationConf() |
|
487 | opConfObj = OperationConf() | |
483 | opConfObj.readXml(opElement) |
|
488 | opConfObj.readXml(opElement) | |
484 | self.opConfObjList.append(opConfObj) |
|
489 | self.opConfObjList.append(opConfObj) | |
485 |
|
490 | |||
486 | def printattr(self): |
|
491 | def printattr(self): | |
487 |
|
492 | |||
488 | print "%s[%s]: name = %s, datatype = %s, inputId = %s" %(self.ELEMENTNAME, |
|
493 | print "%s[%s]: name = %s, datatype = %s, inputId = %s" %(self.ELEMENTNAME, | |
489 | self.id, |
|
494 | self.id, | |
490 | self.name, |
|
495 | self.name, | |
491 | self.datatype, |
|
496 | self.datatype, | |
492 | self.inputId) |
|
497 | self.inputId) | |
493 |
|
498 | |||
494 | for opConfObj in self.opConfObjList: |
|
499 | for opConfObj in self.opConfObjList: | |
495 | opConfObj.printattr() |
|
500 | opConfObj.printattr() | |
496 |
|
501 | |||
497 | def createObjects(self): |
|
502 | def createObjects(self): | |
498 |
|
503 | |||
499 | className = eval(self.name) |
|
504 | className = eval(self.name) | |
500 | procUnitObj = className() |
|
505 | procUnitObj = className() | |
501 |
|
506 | |||
502 | for opConfObj in self.opConfObjList: |
|
507 | for opConfObj in self.opConfObjList: | |
503 |
|
508 | |||
504 | if opConfObj.type == 'self': |
|
509 | if opConfObj.type == 'self': | |
505 | continue |
|
510 | continue | |
506 |
|
511 | |||
507 | opObj = opConfObj.createObject() |
|
512 | opObj = opConfObj.createObject() | |
508 |
|
513 | |||
509 | self.opObjDict[opConfObj.id] = opObj |
|
514 | self.opObjDict[opConfObj.id] = opObj | |
510 | procUnitObj.addOperation(opObj, opConfObj.id) |
|
515 | procUnitObj.addOperation(opObj, opConfObj.id) | |
511 |
|
516 | |||
512 | self.procUnitObj = procUnitObj |
|
517 | self.procUnitObj = procUnitObj | |
513 |
|
518 | |||
514 | return procUnitObj |
|
519 | return procUnitObj | |
515 |
|
520 | |||
516 | def run(self): |
|
521 | def run(self): | |
517 |
|
522 | |||
518 | finalSts = False |
|
523 | finalSts = False | |
519 |
|
524 | |||
520 | for opConfObj in self.opConfObjList: |
|
525 | for opConfObj in self.opConfObjList: | |
521 |
|
526 | |||
522 | kwargs = {} |
|
527 | kwargs = {} | |
523 | for parmConfObj in opConfObj.getParameterObjList(): |
|
528 | for parmConfObj in opConfObj.getParameterObjList(): | |
524 | if opConfObj.name == 'run' and parmConfObj.name == 'datatype': |
|
529 | if opConfObj.name == 'run' and parmConfObj.name == 'datatype': | |
525 | continue |
|
530 | continue | |
526 |
|
531 | |||
527 | kwargs[parmConfObj.name] = parmConfObj.getValue() |
|
532 | kwargs[parmConfObj.name] = parmConfObj.getValue() | |
528 |
|
533 | |||
529 | #print "\tRunning the '%s' operation with %s" %(opConfObj.name, opConfObj.id) |
|
534 | #print "\tRunning the '%s' operation with %s" %(opConfObj.name, opConfObj.id) | |
530 | sts = self.procUnitObj.call(opType = opConfObj.type, |
|
535 | sts = self.procUnitObj.call(opType = opConfObj.type, | |
531 | opName = opConfObj.name, |
|
536 | opName = opConfObj.name, | |
532 | opId = opConfObj.id, |
|
537 | opId = opConfObj.id, | |
533 | **kwargs) |
|
538 | **kwargs) | |
534 | finalSts = finalSts or sts |
|
539 | finalSts = finalSts or sts | |
535 |
|
540 | |||
536 | return finalSts |
|
541 | return finalSts | |
537 |
|
542 | |||
538 | def close(self): |
|
543 | def close(self): | |
539 |
|
544 | |||
540 | for opConfObj in self.opConfObjList: |
|
545 | for opConfObj in self.opConfObjList: | |
541 | if opConfObj.type == 'self': |
|
546 | if opConfObj.type == 'self': | |
542 | continue |
|
547 | continue | |
543 |
|
548 | |||
544 | opObj = self.procUnitObj.getOperationObj(opConfObj.id) |
|
549 | opObj = self.procUnitObj.getOperationObj(opConfObj.id) | |
545 | opObj.close() |
|
550 | opObj.close() | |
546 |
|
551 | |||
547 | self.procUnitObj.close() |
|
552 | self.procUnitObj.close() | |
548 |
|
553 | |||
549 | return |
|
554 | return | |
550 |
|
555 | |||
551 | class ReadUnitConf(ProcUnitConf): |
|
556 | class ReadUnitConf(ProcUnitConf): | |
552 |
|
557 | |||
553 | path = None |
|
558 | path = None | |
554 | startDate = None |
|
559 | startDate = None | |
555 | endDate = None |
|
560 | endDate = None | |
556 | startTime = None |
|
561 | startTime = None | |
557 | endTime = None |
|
562 | endTime = None | |
558 |
|
563 | |||
559 | ELEMENTNAME = 'ReadUnit' |
|
564 | ELEMENTNAME = 'ReadUnit' | |
560 |
|
565 | |||
561 | def __init__(self): |
|
566 | def __init__(self): | |
562 |
|
567 | |||
563 | self.id = None |
|
568 | self.id = None | |
564 | self.datatype = None |
|
569 | self.datatype = None | |
565 | self.name = None |
|
570 | self.name = None | |
566 | self.inputId = 0 |
|
571 | self.inputId = 0 | |
567 |
|
572 | |||
568 | self.opConfObjList = [] |
|
573 | self.opConfObjList = [] | |
569 | self.opObjList = [] |
|
574 | self.opObjList = [] | |
570 |
|
575 | |||
571 | def getElementName(self): |
|
576 | def getElementName(self): | |
572 |
|
577 | |||
573 | return self.ELEMENTNAME |
|
578 | return self.ELEMENTNAME | |
574 |
|
579 | |||
575 | def setup(self, id, name, datatype, path, startDate="", endDate="", startTime="", endTime="", parentId=None, **kwargs): |
|
580 | def setup(self, id, name, datatype, path, startDate="", endDate="", startTime="", endTime="", parentId=None, **kwargs): | |
576 |
|
581 | |||
577 | self.id = id |
|
582 | self.id = id | |
578 | self.name = name |
|
583 | self.name = name | |
579 | self.datatype = datatype |
|
584 | self.datatype = datatype | |
580 |
|
585 | |||
581 | self.path = path |
|
586 | self.path = path | |
582 | self.startDate = startDate |
|
587 | self.startDate = startDate | |
583 | self.endDate = endDate |
|
588 | self.endDate = endDate | |
584 | self.startTime = startTime |
|
589 | self.startTime = startTime | |
585 | self.endTime = endTime |
|
590 | self.endTime = endTime | |
586 |
|
591 | |||
587 | self.addRunOperation(**kwargs) |
|
592 | self.addRunOperation(**kwargs) | |
588 |
|
593 | |||
589 | def update(self, datatype, path, startDate, endDate, startTime, endTime, parentId=None, **kwargs): |
|
594 | def update(self, datatype, path, startDate, endDate, startTime, endTime, parentId=None, **kwargs): | |
590 |
|
595 | |||
591 | self.datatype = datatype |
|
596 | self.datatype = datatype | |
592 | self.path = path |
|
597 | self.path = path | |
593 | self.startDate = startDate |
|
598 | self.startDate = startDate | |
594 | self.endDate = endDate |
|
599 | self.endDate = endDate | |
595 | self.startTime = startTime |
|
600 | self.startTime = startTime | |
596 | self.endTime = endTime |
|
601 | self.endTime = endTime | |
597 |
|
602 | |||
598 | self.updateRunOperation(**kwargs) |
|
603 | self.updateRunOperation(**kwargs) | |
599 |
|
604 | |||
600 | def addRunOperation(self, **kwargs): |
|
605 | def addRunOperation(self, **kwargs): | |
601 |
|
606 | |||
602 | opObj = self.addOperation(name = 'run', optype = 'self') |
|
607 | opObj = self.addOperation(name = 'run', optype = 'self') | |
603 |
|
608 | |||
604 | opObj.addParameter(name='datatype' , value=self.datatype, format='str') |
|
609 | opObj.addParameter(name='datatype' , value=self.datatype, format='str') | |
605 | opObj.addParameter(name='path' , value=self.path, format='str') |
|
610 | opObj.addParameter(name='path' , value=self.path, format='str') | |
606 | opObj.addParameter(name='startDate' , value=self.startDate, format='date') |
|
611 | opObj.addParameter(name='startDate' , value=self.startDate, format='date') | |
607 | opObj.addParameter(name='endDate' , value=self.endDate, format='date') |
|
612 | opObj.addParameter(name='endDate' , value=self.endDate, format='date') | |
608 | opObj.addParameter(name='startTime' , value=self.startTime, format='time') |
|
613 | opObj.addParameter(name='startTime' , value=self.startTime, format='time') | |
609 | opObj.addParameter(name='endTime' , value=self.endTime, format='time') |
|
614 | opObj.addParameter(name='endTime' , value=self.endTime, format='time') | |
610 |
|
615 | |||
611 | for key, value in kwargs.items(): |
|
616 | for key, value in kwargs.items(): | |
612 | opObj.addParameter(name=key, value=value, format=type(value).__name__) |
|
617 | opObj.addParameter(name=key, value=value, format=type(value).__name__) | |
613 |
|
618 | |||
614 | return opObj |
|
619 | return opObj | |
615 |
|
620 | |||
616 | def updateRunOperation(self, **kwargs): |
|
621 | def updateRunOperation(self, **kwargs): | |
617 |
|
622 | |||
618 | opObj = self.getOperationObj(name = 'run') |
|
623 | opObj = self.getOperationObj(name = 'run') | |
619 | opObj.removeParameters() |
|
624 | opObj.removeParameters() | |
620 |
|
625 | |||
621 | opObj.addParameter(name='datatype' , value=self.datatype, format='str') |
|
626 | opObj.addParameter(name='datatype' , value=self.datatype, format='str') | |
622 | opObj.addParameter(name='path' , value=self.path, format='str') |
|
627 | opObj.addParameter(name='path' , value=self.path, format='str') | |
623 | opObj.addParameter(name='startDate' , value=self.startDate, format='date') |
|
628 | opObj.addParameter(name='startDate' , value=self.startDate, format='date') | |
624 | opObj.addParameter(name='endDate' , value=self.endDate, format='date') |
|
629 | opObj.addParameter(name='endDate' , value=self.endDate, format='date') | |
625 | opObj.addParameter(name='startTime' , value=self.startTime, format='time') |
|
630 | opObj.addParameter(name='startTime' , value=self.startTime, format='time') | |
626 | opObj.addParameter(name='endTime' , value=self.endTime, format='time') |
|
631 | opObj.addParameter(name='endTime' , value=self.endTime, format='time') | |
627 |
|
632 | |||
628 | for key, value in kwargs.items(): |
|
633 | for key, value in kwargs.items(): | |
629 | opObj.addParameter(name=key, value=value, format=type(value).__name__) |
|
634 | opObj.addParameter(name=key, value=value, format=type(value).__name__) | |
630 |
|
635 | |||
631 | return opObj |
|
636 | return opObj | |
632 |
|
637 | |||
633 | class Project(): |
|
638 | class Project(): | |
634 |
|
639 | |||
635 | id = None |
|
640 | id = None | |
636 | name = None |
|
641 | name = None | |
637 | description = None |
|
642 | description = None | |
638 | # readUnitConfObjList = None |
|
643 | # readUnitConfObjList = None | |
639 | procUnitConfObjDict = None |
|
644 | procUnitConfObjDict = None | |
640 |
|
645 | |||
641 | ELEMENTNAME = 'Project' |
|
646 | ELEMENTNAME = 'Project' | |
642 |
|
647 | |||
643 | def __init__(self, control=None, dataq=None): |
|
648 | def __init__(self, control=None, dataq=None): | |
644 |
|
649 | |||
645 | self.id = None |
|
650 | self.id = None | |
646 | self.name = None |
|
651 | self.name = None | |
647 | self.description = None |
|
652 | self.description = None | |
648 |
|
653 | |||
649 | self.procUnitConfObjDict = {} |
|
654 | self.procUnitConfObjDict = {} | |
650 |
|
655 | |||
651 | #global data_q |
|
656 | #global data_q | |
652 | #data_q = dataq |
|
657 | #data_q = dataq | |
653 |
|
658 | |||
654 | if control==None: |
|
659 | if control==None: | |
655 | control = {} |
|
660 | control = {} | |
656 | control['stop'] = False |
|
661 | control['stop'] = False | |
657 | control['pause'] = False |
|
662 | control['pause'] = False | |
658 |
|
663 | |||
659 | self.control = control |
|
664 | self.control = control | |
660 |
|
665 | |||
661 | def __getNewId(self): |
|
666 | def __getNewId(self): | |
662 |
|
667 | |||
663 | id = int(self.id)*10 + len(self.procUnitConfObjDict) + 1 |
|
668 | id = int(self.id)*10 + len(self.procUnitConfObjDict) + 1 | |
664 |
|
669 | |||
665 | return str(id) |
|
670 | return str(id) | |
666 |
|
671 | |||
667 | def getElementName(self): |
|
672 | def getElementName(self): | |
668 |
|
673 | |||
669 | return self.ELEMENTNAME |
|
674 | return self.ELEMENTNAME | |
670 |
|
675 | |||
671 | def getId(self): |
|
676 | def getId(self): | |
672 |
|
677 | |||
673 | return self.id |
|
678 | return self.id | |
674 |
|
679 | |||
675 | def setup(self, id, name, description): |
|
680 | def setup(self, id, name, description): | |
676 |
|
681 | |||
677 | self.id = id |
|
682 | self.id = id | |
678 | self.name = name |
|
683 | self.name = name | |
679 | self.description = description |
|
684 | self.description = description | |
680 |
|
685 | |||
681 | def update(self, name, description): |
|
686 | def update(self, name, description): | |
682 |
|
687 | |||
683 | self.name = name |
|
688 | self.name = name | |
684 | self.description = description |
|
689 | self.description = description | |
685 |
|
690 | |||
686 | def addReadUnit(self, datatype=None, name=None, **kwargs): |
|
691 | def addReadUnit(self, datatype=None, name=None, **kwargs): | |
687 |
|
692 | |||
688 | #Compatible with old signal chain version |
|
693 | #Compatible with old signal chain version | |
689 | if datatype==None and name==None: |
|
694 | if datatype==None and name==None: | |
690 | raise ValueError, "datatype or name should be defined" |
|
695 | raise ValueError, "datatype or name should be defined" | |
691 |
|
696 | |||
692 | if name==None: |
|
697 | if name==None: | |
693 | if 'Reader' in datatype: |
|
698 | if 'Reader' in datatype: | |
694 | name = datatype |
|
699 | name = datatype | |
695 | else: |
|
700 | else: | |
696 | name = '%sReader' %(datatype) |
|
701 | name = '%sReader' %(datatype) | |
697 |
|
702 | |||
698 | if datatype==None: |
|
703 | if datatype==None: | |
699 | datatype = name.replace('Reader','') |
|
704 | datatype = name.replace('Reader','') | |
700 |
|
705 | |||
701 | id = self.__getNewId() |
|
706 | id = self.__getNewId() | |
702 |
|
707 | |||
703 | readUnitConfObj = ReadUnitConf() |
|
708 | readUnitConfObj = ReadUnitConf() | |
704 | readUnitConfObj.setup(id, name, datatype, parentId=self.id, **kwargs) |
|
709 | readUnitConfObj.setup(id, name, datatype, parentId=self.id, **kwargs) | |
705 |
|
710 | |||
706 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj |
|
711 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj | |
707 |
|
712 | |||
708 | return readUnitConfObj |
|
713 | return readUnitConfObj | |
709 |
|
714 | |||
710 | def addProcUnit(self, inputId=0, datatype=None, name=None): |
|
715 | def addProcUnit(self, inputId=0, datatype=None, name=None): | |
711 |
|
716 | |||
712 | #Compatible with old signal chain version |
|
717 | #Compatible with old signal chain version | |
713 | if datatype==None and name==None: |
|
718 | if datatype==None and name==None: | |
714 | raise ValueError, "datatype or name should be defined" |
|
719 | raise ValueError, "datatype or name should be defined" | |
715 |
|
720 | |||
716 | if name==None: |
|
721 | if name==None: | |
717 | if 'Proc' in datatype: |
|
722 | if 'Proc' in datatype: | |
718 | name = datatype |
|
723 | name = datatype | |
719 | else: |
|
724 | else: | |
720 | name = '%sProc' %(datatype) |
|
725 | name = '%sProc' %(datatype) | |
721 |
|
726 | |||
722 | if datatype==None: |
|
727 | if datatype==None: | |
723 | datatype = name.replace('Proc','') |
|
728 | datatype = name.replace('Proc','') | |
724 |
|
729 | |||
725 | id = self.__getNewId() |
|
730 | id = self.__getNewId() | |
726 |
|
731 | |||
727 | procUnitConfObj = ProcUnitConf() |
|
732 | procUnitConfObj = ProcUnitConf() | |
728 | procUnitConfObj.setup(id, name, datatype, inputId, parentId=self.id) |
|
733 | procUnitConfObj.setup(id, name, datatype, inputId, parentId=self.id) | |
729 |
|
734 | |||
730 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj |
|
735 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj | |
731 |
|
736 | |||
732 | return procUnitConfObj |
|
737 | return procUnitConfObj | |
733 |
|
738 | |||
|
739 | def removeProcUnit(self, id): | |||
|
740 | ||||
|
741 | if id in self.procUnitConfObjDict.keys(): | |||
|
742 | self.procUnitConfObjDict.pop(id) | |||
|
743 | ||||
734 | def getReadUnitId(self): |
|
744 | def getReadUnitId(self): | |
735 |
|
745 | |||
736 | readUnitConfObj = self.getReadUnitObj() |
|
746 | readUnitConfObj = self.getReadUnitObj() | |
737 |
|
747 | |||
738 | return readUnitConfObj.id |
|
748 | return readUnitConfObj.id | |
739 |
|
749 | |||
740 | def getReadUnitObj(self): |
|
750 | def getReadUnitObj(self): | |
741 |
|
751 | |||
742 | for obj in self.procUnitConfObjDict.values(): |
|
752 | for obj in self.procUnitConfObjDict.values(): | |
743 | if obj.getElementName() == "ReadUnit": |
|
753 | if obj.getElementName() == "ReadUnit": | |
744 | return obj |
|
754 | return obj | |
745 |
|
755 | |||
746 | return None |
|
756 | return None | |
747 |
|
757 | |||
748 | def getProcUnitObj(self, id): |
|
758 | def getProcUnitObj(self, id): | |
749 |
|
759 | |||
750 | return self.procUnitConfObjDict[id] |
|
760 | return self.procUnitConfObjDict[id] | |
751 |
|
761 | |||
752 | def getProcUnitObjByName(self, name): |
|
762 | def getProcUnitObjByName(self, name): | |
753 |
|
763 | |||
754 | for obj in self.procUnitConfObjDict.values(): |
|
764 | for obj in self.procUnitConfObjDict.values(): | |
755 | if obj.name == name: |
|
765 | if obj.name == name: | |
756 | return obj |
|
766 | return obj | |
757 |
|
767 | |||
758 | return None |
|
768 | return None | |
759 |
|
769 | |||
760 | def makeXml(self): |
|
770 | def makeXml(self): | |
761 |
|
771 | |||
762 | projectElement = Element('Project') |
|
772 | projectElement = Element('Project') | |
763 | projectElement.set('id', str(self.id)) |
|
773 | projectElement.set('id', str(self.id)) | |
764 | projectElement.set('name', self.name) |
|
774 | projectElement.set('name', self.name) | |
765 | projectElement.set('description', self.description) |
|
775 | projectElement.set('description', self.description) | |
766 |
|
776 | |||
767 | # for readUnitConfObj in self.readUnitConfObjList: |
|
777 | # for readUnitConfObj in self.readUnitConfObjList: | |
768 | # readUnitConfObj.makeXml(projectElement) |
|
778 | # readUnitConfObj.makeXml(projectElement) | |
769 |
|
779 | |||
770 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
780 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |
771 | procUnitConfObj.makeXml(projectElement) |
|
781 | procUnitConfObj.makeXml(projectElement) | |
772 |
|
782 | |||
773 | self.projectElement = projectElement |
|
783 | self.projectElement = projectElement | |
774 |
|
784 | |||
775 | def writeXml(self, filename): |
|
785 | def writeXml(self, filename): | |
776 |
|
786 | |||
777 | self.makeXml() |
|
787 | self.makeXml() | |
778 |
|
788 | |||
779 | #print prettify(self.projectElement) |
|
789 | #print prettify(self.projectElement) | |
780 |
|
790 | |||
781 | ElementTree(self.projectElement).write(filename, method='xml') |
|
791 | ElementTree(self.projectElement).write(filename, method='xml') | |
782 |
|
792 | |||
783 | def readXml(self, filename): |
|
793 | def readXml(self, filename): | |
784 |
|
794 | |||
785 | #tree = ET.parse(filename) |
|
795 | #tree = ET.parse(filename) | |
786 | self.projectElement = None |
|
796 | self.projectElement = None | |
787 | # self.readUnitConfObjList = [] |
|
797 | # self.readUnitConfObjList = [] | |
788 | self.procUnitConfObjDict = {} |
|
798 | self.procUnitConfObjDict = {} | |
789 |
|
799 | |||
790 | self.projectElement = ElementTree().parse(filename) |
|
800 | self.projectElement = ElementTree().parse(filename) | |
791 |
|
801 | |||
792 | self.project = self.projectElement.tag |
|
802 | self.project = self.projectElement.tag | |
793 |
|
803 | |||
794 | self.id = self.projectElement.get('id') |
|
804 | self.id = self.projectElement.get('id') | |
795 | self.name = self.projectElement.get('name') |
|
805 | self.name = self.projectElement.get('name') | |
796 | self.description = self.projectElement.get('description') |
|
806 | self.description = self.projectElement.get('description') | |
797 |
|
807 | |||
798 | readUnitElementList = self.projectElement.getiterator(ReadUnitConf().getElementName()) |
|
808 | readUnitElementList = self.projectElement.getiterator(ReadUnitConf().getElementName()) | |
799 |
|
809 | |||
800 | for readUnitElement in readUnitElementList: |
|
810 | for readUnitElement in readUnitElementList: | |
801 | readUnitConfObj = ReadUnitConf() |
|
811 | readUnitConfObj = ReadUnitConf() | |
802 | readUnitConfObj.readXml(readUnitElement) |
|
812 | readUnitConfObj.readXml(readUnitElement) | |
803 |
|
813 | |||
804 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj |
|
814 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj | |
805 |
|
815 | |||
806 | procUnitElementList = self.projectElement.getiterator(ProcUnitConf().getElementName()) |
|
816 | procUnitElementList = self.projectElement.getiterator(ProcUnitConf().getElementName()) | |
807 |
|
817 | |||
808 | for procUnitElement in procUnitElementList: |
|
818 | for procUnitElement in procUnitElementList: | |
809 | procUnitConfObj = ProcUnitConf() |
|
819 | procUnitConfObj = ProcUnitConf() | |
810 | procUnitConfObj.readXml(procUnitElement) |
|
820 | procUnitConfObj.readXml(procUnitElement) | |
811 |
|
821 | |||
812 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj |
|
822 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj | |
813 |
|
823 | |||
814 | def printattr(self): |
|
824 | def printattr(self): | |
815 |
|
825 | |||
816 | print "Project[%s]: name = %s, description = %s" %(self.id, |
|
826 | print "Project[%s]: name = %s, description = %s" %(self.id, | |
817 | self.name, |
|
827 | self.name, | |
818 | self.description) |
|
828 | self.description) | |
819 |
|
829 | |||
820 | # for readUnitConfObj in self.readUnitConfObjList: |
|
830 | # for readUnitConfObj in self.readUnitConfObjList: | |
821 | # readUnitConfObj.printattr() |
|
831 | # readUnitConfObj.printattr() | |
822 |
|
832 | |||
823 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
833 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |
824 | procUnitConfObj.printattr() |
|
834 | procUnitConfObj.printattr() | |
825 |
|
835 | |||
826 | def createObjects(self): |
|
836 | def createObjects(self): | |
827 |
|
837 | |||
828 | # for readUnitConfObj in self.readUnitConfObjList: |
|
838 | # for readUnitConfObj in self.readUnitConfObjList: | |
829 | # readUnitConfObj.createObjects() |
|
839 | # readUnitConfObj.createObjects() | |
830 |
|
840 | |||
831 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
841 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |
832 | procUnitConfObj.createObjects() |
|
842 | procUnitConfObj.createObjects() | |
833 |
|
843 | |||
834 | def __connect(self, objIN, thisObj): |
|
844 | def __connect(self, objIN, thisObj): | |
835 |
|
845 | |||
836 | thisObj.setInput(objIN.getOutputObj()) |
|
846 | thisObj.setInput(objIN.getOutputObj()) | |
837 |
|
847 | |||
838 | def connectObjects(self): |
|
848 | def connectObjects(self): | |
839 |
|
849 | |||
840 | for thisPUConfObj in self.procUnitConfObjDict.values(): |
|
850 | for thisPUConfObj in self.procUnitConfObjDict.values(): | |
841 |
|
851 | |||
842 | inputId = thisPUConfObj.getInputId() |
|
852 | inputId = thisPUConfObj.getInputId() | |
843 |
|
853 | |||
844 | if int(inputId) == 0: |
|
854 | if int(inputId) == 0: | |
845 | continue |
|
855 | continue | |
846 |
|
856 | |||
847 | #Get input object |
|
857 | #Get input object | |
848 | puConfINObj = self.procUnitConfObjDict[inputId] |
|
858 | puConfINObj = self.procUnitConfObjDict[inputId] | |
849 | puObjIN = puConfINObj.getProcUnitObj() |
|
859 | puObjIN = puConfINObj.getProcUnitObj() | |
850 |
|
860 | |||
851 | #Get current object |
|
861 | #Get current object | |
852 | thisPUObj = thisPUConfObj.getProcUnitObj() |
|
862 | thisPUObj = thisPUConfObj.getProcUnitObj() | |
853 |
|
863 | |||
854 | self.__connect(puObjIN, thisPUObj) |
|
864 | self.__connect(puObjIN, thisPUObj) | |
855 |
|
865 | |||
856 | def run(self): |
|
866 | def run(self): | |
857 |
|
867 | |||
858 | # for readUnitConfObj in self.readUnitConfObjList: |
|
868 | # for readUnitConfObj in self.readUnitConfObjList: | |
859 | # readUnitConfObj.run() |
|
869 | # readUnitConfObj.run() | |
860 |
|
870 | |||
861 | print "*"*40 |
|
871 | print "*"*40 | |
862 | print " Starting SIGNAL CHAIN PROCESSING " |
|
872 | print " Starting SIGNAL CHAIN PROCESSING " | |
863 | print "*"*40 |
|
873 | print "*"*40 | |
864 |
|
874 | |||
865 |
|
875 | |||
866 | keyList = self.procUnitConfObjDict.keys() |
|
876 | keyList = self.procUnitConfObjDict.keys() | |
867 | keyList.sort() |
|
877 | keyList.sort() | |
868 |
|
878 | |||
869 | while(True): |
|
879 | while(True): | |
870 |
|
880 | |||
871 | finalSts = False |
|
881 | finalSts = False | |
872 |
|
882 | |||
873 | for procKey in keyList: |
|
883 | for procKey in keyList: | |
874 | # print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id) |
|
884 | # print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id) | |
875 |
|
885 | |||
876 | procUnitConfObj = self.procUnitConfObjDict[procKey] |
|
886 | procUnitConfObj = self.procUnitConfObjDict[procKey] | |
877 | sts = procUnitConfObj.run() |
|
887 | sts = procUnitConfObj.run() | |
878 | finalSts = finalSts or sts |
|
888 | finalSts = finalSts or sts | |
879 |
|
889 | |||
880 | #If every process unit finished so end process |
|
890 | #If every process unit finished so end process | |
881 | if not(finalSts): |
|
891 | if not(finalSts): | |
882 | print "Every process unit have finished" |
|
892 | print "Every process unit have finished" | |
883 | break |
|
893 | break | |
884 |
|
894 | |||
885 | if self.control['pause']: |
|
895 | if self.control['pause']: | |
886 | print "Process suspended" |
|
896 | print "Process suspended" | |
887 |
|
897 | |||
888 | while True: |
|
898 | while True: | |
889 |
|
|
899 | sleep(0.1) | |
890 |
|
900 | |||
891 | if not self.control['pause']: |
|
901 | if not self.control['pause']: | |
892 | break |
|
902 | break | |
893 |
|
903 | |||
894 | if self.control['stop']: |
|
904 | if self.control['stop']: | |
895 | break |
|
905 | break | |
896 | print "Process reinitialized" |
|
906 | print "Process reinitialized" | |
897 |
|
907 | |||
898 | if self.control['stop']: |
|
908 | if self.control['stop']: | |
899 |
print " |
|
909 | print "Process stopped" | |
900 | break |
|
910 | break | |
901 |
|
911 | |||
902 | #Closing every process |
|
912 | #Closing every process | |
903 | for procKey in keyList: |
|
913 | for procKey in keyList: | |
904 | procUnitConfObj = self.procUnitConfObjDict[procKey] |
|
914 | procUnitConfObj = self.procUnitConfObjDict[procKey] | |
905 | procUnitConfObj.close() |
|
915 | procUnitConfObj.close() | |
906 |
|
916 | |||
907 |
print "Process |
|
917 | print "Process finished" | |
908 |
|
918 | |||
909 | def start(self, filename): |
|
919 | def start(self, filename): | |
910 |
|
920 | |||
911 | self.writeXml(filename) |
|
921 | self.writeXml(filename) | |
912 | self.readXml(filename) |
|
922 | self.readXml(filename) | |
913 |
|
923 | |||
914 | self.createObjects() |
|
924 | self.createObjects() | |
915 | self.connectObjects() |
|
925 | self.connectObjects() | |
916 | self.run() |
|
926 | self.run() | |
917 |
|
927 | |||
918 | if __name__ == '__main__': |
|
928 | if __name__ == '__main__': | |
919 |
|
929 | |||
920 | desc = "Segundo Test" |
|
930 | desc = "Segundo Test" | |
921 | filename = "schain.xml" |
|
931 | filename = "schain.xml" | |
922 |
|
932 | |||
923 | controllerObj = Project() |
|
933 | controllerObj = Project() | |
924 |
|
934 | |||
925 | controllerObj.setup(id = '191', name='test01', description=desc) |
|
935 | controllerObj.setup(id = '191', name='test01', description=desc) | |
926 |
|
936 | |||
927 | readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage', |
|
937 | readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage', | |
928 | path='data/rawdata/', |
|
938 | path='data/rawdata/', | |
929 | startDate='2011/01/01', |
|
939 | startDate='2011/01/01', | |
930 | endDate='2012/12/31', |
|
940 | endDate='2012/12/31', | |
931 | startTime='00:00:00', |
|
941 | startTime='00:00:00', | |
932 | endTime='23:59:59', |
|
942 | endTime='23:59:59', | |
933 | online=1, |
|
943 | online=1, | |
934 | walk=1) |
|
944 | walk=1) | |
935 |
|
945 | |||
936 | # opObj00 = readUnitConfObj.addOperation(name='printInfo') |
|
946 | # opObj00 = readUnitConfObj.addOperation(name='printInfo') | |
937 |
|
947 | |||
938 | procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) |
|
948 | procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) | |
939 |
|
949 | |||
940 | opObj10 = procUnitConfObj0.addOperation(name='selectChannels') |
|
950 | opObj10 = procUnitConfObj0.addOperation(name='selectChannels') | |
941 | opObj10.addParameter(name='channelList', value='3,4,5', format='intlist') |
|
951 | opObj10.addParameter(name='channelList', value='3,4,5', format='intlist') | |
942 |
|
952 | |||
943 | opObj10 = procUnitConfObj0.addOperation(name='selectHeights') |
|
953 | opObj10 = procUnitConfObj0.addOperation(name='selectHeights') | |
944 | opObj10.addParameter(name='minHei', value='90', format='float') |
|
954 | opObj10.addParameter(name='minHei', value='90', format='float') | |
945 | opObj10.addParameter(name='maxHei', value='180', format='float') |
|
955 | opObj10.addParameter(name='maxHei', value='180', format='float') | |
946 |
|
956 | |||
947 | opObj12 = procUnitConfObj0.addOperation(name='CohInt', optype='external') |
|
957 | opObj12 = procUnitConfObj0.addOperation(name='CohInt', optype='external') | |
948 | opObj12.addParameter(name='n', value='10', format='int') |
|
958 | opObj12.addParameter(name='n', value='10', format='int') | |
949 |
|
959 | |||
950 | procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId()) |
|
960 | procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId()) | |
951 | procUnitConfObj1.addParameter(name='nFFTPoints', value='32', format='int') |
|
961 | procUnitConfObj1.addParameter(name='nFFTPoints', value='32', format='int') | |
952 | # procUnitConfObj1.addParameter(name='pairList', value='(0,1),(0,2),(1,2)', format='') |
|
962 | # procUnitConfObj1.addParameter(name='pairList', value='(0,1),(0,2),(1,2)', format='') | |
953 |
|
963 | |||
954 |
|
964 | |||
955 | opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='external') |
|
965 | opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='external') | |
956 | opObj11.addParameter(name='idfigure', value='1', format='int') |
|
966 | opObj11.addParameter(name='idfigure', value='1', format='int') | |
957 | opObj11.addParameter(name='wintitle', value='SpectraPlot0', format='str') |
|
967 | opObj11.addParameter(name='wintitle', value='SpectraPlot0', format='str') | |
958 | opObj11.addParameter(name='zmin', value='40', format='int') |
|
968 | opObj11.addParameter(name='zmin', value='40', format='int') | |
959 | opObj11.addParameter(name='zmax', value='90', format='int') |
|
969 | opObj11.addParameter(name='zmax', value='90', format='int') | |
960 | opObj11.addParameter(name='showprofile', value='1', format='int') |
|
970 | opObj11.addParameter(name='showprofile', value='1', format='int') | |
961 |
|
971 | |||
962 | # opObj11 = procUnitConfObj1.addOperation(name='CrossSpectraPlot', optype='external') |
|
972 | # opObj11 = procUnitConfObj1.addOperation(name='CrossSpectraPlot', optype='external') | |
963 | # opObj11.addParameter(name='idfigure', value='2', format='int') |
|
973 | # opObj11.addParameter(name='idfigure', value='2', format='int') | |
964 | # opObj11.addParameter(name='wintitle', value='CrossSpectraPlot', format='str') |
|
974 | # opObj11.addParameter(name='wintitle', value='CrossSpectraPlot', format='str') | |
965 | # opObj11.addParameter(name='zmin', value='40', format='int') |
|
975 | # opObj11.addParameter(name='zmin', value='40', format='int') | |
966 | # opObj11.addParameter(name='zmax', value='90', format='int') |
|
976 | # opObj11.addParameter(name='zmax', value='90', format='int') | |
967 |
|
977 | |||
968 |
|
978 | |||
969 | # procUnitConfObj2 = controllerObj.addProcUnit(datatype='Voltage', inputId=procUnitConfObj0.getId()) |
|
979 | # procUnitConfObj2 = controllerObj.addProcUnit(datatype='Voltage', inputId=procUnitConfObj0.getId()) | |
970 | # |
|
980 | # | |
971 | # opObj12 = procUnitConfObj2.addOperation(name='CohInt', optype='external') |
|
981 | # opObj12 = procUnitConfObj2.addOperation(name='CohInt', optype='external') | |
972 | # opObj12.addParameter(name='n', value='2', format='int') |
|
982 | # opObj12.addParameter(name='n', value='2', format='int') | |
973 | # opObj12.addParameter(name='overlapping', value='1', format='int') |
|
983 | # opObj12.addParameter(name='overlapping', value='1', format='int') | |
974 | # |
|
984 | # | |
975 | # procUnitConfObj3 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj2.getId()) |
|
985 | # procUnitConfObj3 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj2.getId()) | |
976 | # procUnitConfObj3.addParameter(name='nFFTPoints', value='32', format='int') |
|
986 | # procUnitConfObj3.addParameter(name='nFFTPoints', value='32', format='int') | |
977 | # |
|
987 | # | |
978 | # opObj11 = procUnitConfObj3.addOperation(name='SpectraPlot', optype='external') |
|
988 | # opObj11 = procUnitConfObj3.addOperation(name='SpectraPlot', optype='external') | |
979 | # opObj11.addParameter(name='idfigure', value='2', format='int') |
|
989 | # opObj11.addParameter(name='idfigure', value='2', format='int') | |
980 | # opObj11.addParameter(name='wintitle', value='SpectraPlot1', format='str') |
|
990 | # opObj11.addParameter(name='wintitle', value='SpectraPlot1', format='str') | |
981 | # opObj11.addParameter(name='zmin', value='40', format='int') |
|
991 | # opObj11.addParameter(name='zmin', value='40', format='int') | |
982 | # opObj11.addParameter(name='zmax', value='90', format='int') |
|
992 | # opObj11.addParameter(name='zmax', value='90', format='int') | |
983 | # opObj11.addParameter(name='showprofile', value='1', format='int') |
|
993 | # opObj11.addParameter(name='showprofile', value='1', format='int') | |
984 |
|
994 | |||
985 | # opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='external') |
|
995 | # opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='external') | |
986 | # opObj11.addParameter(name='idfigure', value='10', format='int') |
|
996 | # opObj11.addParameter(name='idfigure', value='10', format='int') | |
987 | # opObj11.addParameter(name='wintitle', value='RTI', format='str') |
|
997 | # opObj11.addParameter(name='wintitle', value='RTI', format='str') | |
988 | ## opObj11.addParameter(name='xmin', value='21', format='float') |
|
998 | ## opObj11.addParameter(name='xmin', value='21', format='float') | |
989 | ## opObj11.addParameter(name='xmax', value='22', format='float') |
|
999 | ## opObj11.addParameter(name='xmax', value='22', format='float') | |
990 | # opObj11.addParameter(name='zmin', value='40', format='int') |
|
1000 | # opObj11.addParameter(name='zmin', value='40', format='int') | |
991 | # opObj11.addParameter(name='zmax', value='90', format='int') |
|
1001 | # opObj11.addParameter(name='zmax', value='90', format='int') | |
992 | # opObj11.addParameter(name='showprofile', value='1', format='int') |
|
1002 | # opObj11.addParameter(name='showprofile', value='1', format='int') | |
993 | # opObj11.addParameter(name='timerange', value=str(60), format='int') |
|
1003 | # opObj11.addParameter(name='timerange', value=str(60), format='int') | |
994 |
|
1004 | |||
995 | # opObj10 = procUnitConfObj1.addOperation(name='selectChannels') |
|
1005 | # opObj10 = procUnitConfObj1.addOperation(name='selectChannels') | |
996 | # opObj10.addParameter(name='channelList', value='0,2,4,6', format='intlist') |
|
1006 | # opObj10.addParameter(name='channelList', value='0,2,4,6', format='intlist') | |
997 | # |
|
1007 | # | |
998 | # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='external') |
|
1008 | # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='external') | |
999 | # opObj12.addParameter(name='n', value='2', format='int') |
|
1009 | # opObj12.addParameter(name='n', value='2', format='int') | |
1000 | # |
|
1010 | # | |
1001 | # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='external') |
|
1011 | # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='external') | |
1002 | # opObj11.addParameter(name='idfigure', value='2', format='int') |
|
1012 | # opObj11.addParameter(name='idfigure', value='2', format='int') | |
1003 | # opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str') |
|
1013 | # opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str') | |
1004 | # opObj11.addParameter(name='zmin', value='70', format='int') |
|
1014 | # opObj11.addParameter(name='zmin', value='70', format='int') | |
1005 | # opObj11.addParameter(name='zmax', value='90', format='int') |
|
1015 | # opObj11.addParameter(name='zmax', value='90', format='int') | |
1006 | # |
|
1016 | # | |
1007 | # opObj10 = procUnitConfObj1.addOperation(name='selectChannels') |
|
1017 | # opObj10 = procUnitConfObj1.addOperation(name='selectChannels') | |
1008 | # opObj10.addParameter(name='channelList', value='2,6', format='intlist') |
|
1018 | # opObj10.addParameter(name='channelList', value='2,6', format='intlist') | |
1009 | # |
|
1019 | # | |
1010 | # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='external') |
|
1020 | # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='external') | |
1011 | # opObj12.addParameter(name='n', value='2', format='int') |
|
1021 | # opObj12.addParameter(name='n', value='2', format='int') | |
1012 | # |
|
1022 | # | |
1013 | # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='external') |
|
1023 | # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='external') | |
1014 | # opObj11.addParameter(name='idfigure', value='3', format='int') |
|
1024 | # opObj11.addParameter(name='idfigure', value='3', format='int') | |
1015 | # opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str') |
|
1025 | # opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str') | |
1016 | # opObj11.addParameter(name='zmin', value='70', format='int') |
|
1026 | # opObj11.addParameter(name='zmin', value='70', format='int') | |
1017 | # opObj11.addParameter(name='zmax', value='90', format='int') |
|
1027 | # opObj11.addParameter(name='zmax', value='90', format='int') | |
1018 |
|
1028 | |||
1019 |
|
1029 | |||
1020 | # opObj12 = procUnitConfObj1.addOperation(name='decoder') |
|
1030 | # opObj12 = procUnitConfObj1.addOperation(name='decoder') | |
1021 | # opObj12.addParameter(name='ncode', value='2', format='int') |
|
1031 | # opObj12.addParameter(name='ncode', value='2', format='int') | |
1022 | # opObj12.addParameter(name='nbauds', value='8', format='int') |
|
1032 | # opObj12.addParameter(name='nbauds', value='8', format='int') | |
1023 | # opObj12.addParameter(name='code0', value='001110011', format='int') |
|
1033 | # opObj12.addParameter(name='code0', value='001110011', format='int') | |
1024 | # opObj12.addParameter(name='code1', value='001110011', format='int') |
|
1034 | # opObj12.addParameter(name='code1', value='001110011', format='int') | |
1025 |
|
1035 | |||
1026 |
|
1036 | |||
1027 |
|
1037 | |||
1028 | # procUnitConfObj2 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj1.getId()) |
|
1038 | # procUnitConfObj2 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj1.getId()) | |
1029 | # |
|
1039 | # | |
1030 | # opObj21 = procUnitConfObj2.addOperation(name='IncohInt', optype='external') |
|
1040 | # opObj21 = procUnitConfObj2.addOperation(name='IncohInt', optype='external') | |
1031 | # opObj21.addParameter(name='n', value='2', format='int') |
|
1041 | # opObj21.addParameter(name='n', value='2', format='int') | |
1032 | # |
|
1042 | # | |
1033 | # opObj11 = procUnitConfObj2.addOperation(name='SpectraPlot', optype='external') |
|
1043 | # opObj11 = procUnitConfObj2.addOperation(name='SpectraPlot', optype='external') | |
1034 | # opObj11.addParameter(name='idfigure', value='4', format='int') |
|
1044 | # opObj11.addParameter(name='idfigure', value='4', format='int') | |
1035 | # opObj11.addParameter(name='wintitle', value='SpectraPlot OBJ 2', format='str') |
|
1045 | # opObj11.addParameter(name='wintitle', value='SpectraPlot OBJ 2', format='str') | |
1036 | # opObj11.addParameter(name='zmin', value='70', format='int') |
|
1046 | # opObj11.addParameter(name='zmin', value='70', format='int') | |
1037 | # opObj11.addParameter(name='zmax', value='90', format='int') |
|
1047 | # opObj11.addParameter(name='zmax', value='90', format='int') | |
1038 |
|
1048 | |||
1039 | print "Escribiendo el archivo XML" |
|
1049 | print "Escribiendo el archivo XML" | |
1040 |
|
1050 | |||
1041 | controllerObj.writeXml(filename) |
|
1051 | controllerObj.writeXml(filename) | |
1042 |
|
1052 | |||
1043 | print "Leyendo el archivo XML" |
|
1053 | print "Leyendo el archivo XML" | |
1044 | controllerObj.readXml(filename) |
|
1054 | controllerObj.readXml(filename) | |
1045 | #controllerObj.printattr() |
|
1055 | #controllerObj.printattr() | |
1046 |
|
1056 | |||
1047 | controllerObj.createObjects() |
|
1057 | controllerObj.createObjects() | |
1048 | controllerObj.connectObjects() |
|
1058 | controllerObj.connectObjects() | |
1049 | controllerObj.run() |
|
1059 | controllerObj.run() | |
1050 |
|
1060 | |||
1051 | No newline at end of file |
|
1061 |
1 | NO CONTENT: modified file |
|
NO CONTENT: modified file | ||
The requested commit or file is too big and content was truncated. Show full diff |
@@ -1,100 +1,115 | |||||
1 | import threading |
|
1 | import threading | |
2 | import Queue |
|
2 | import Queue | |
3 | from time import sleep |
|
3 | try: | |
|
4 | from gevent import sleep | |||
|
5 | except: | |||
|
6 | from time import sleep | |||
4 |
|
7 | |||
5 | from schainpy.controller import Project |
|
8 | from schainpy.controller import Project | |
6 | from command import * |
|
9 | from command import * | |
7 |
|
10 | |||
8 | class ControllerThread(threading.Thread): |
|
11 | class ControllerThread(threading.Thread): | |
9 | def __init__(self, filename, data_q=None): |
|
12 | def __init__(self, filename, data_q=None): | |
10 | super(ControllerThread, self).__init__() |
|
13 | super(ControllerThread, self).__init__() | |
11 | self.filename = filename |
|
14 | self.filename = filename | |
12 | self.data_q = data_q |
|
15 | self.data_q = data_q | |
13 | self.control = {'stop':False,'pause':False} |
|
16 | self.control = {'stop':False,'pause':False} | |
14 |
|
17 | |||
15 | def stop(self): |
|
18 | def stop(self): | |
16 | self.control['stop'] = True |
|
19 | self.control['stop'] = True | |
17 |
|
20 | |||
18 | def pause(self): |
|
21 | def pause(self): | |
19 | self.control['pause'] = not(self.control['pause']) |
|
22 | self.control['pause'] = not(self.control['pause']) | |
20 |
|
23 | |||
21 | def run(self): |
|
24 | def run(self): | |
22 | self.control['stop'] = False |
|
25 | self.control['stop'] = False | |
23 | self.control['pause'] = False |
|
26 | self.control['pause'] = False | |
24 | self.controllerObj = Project(self.control, self.data_q) |
|
27 | self.controllerObj = Project(self.control, self.data_q) | |
25 | self.controllerObj.readXml(self.filename) |
|
28 | self.controllerObj.readXml(self.filename) | |
26 | self.controllerObj.createObjects() |
|
29 | self.controllerObj.createObjects() | |
27 | self.controllerObj.connectObjects() |
|
30 | self.controllerObj.connectObjects() | |
28 | self.controllerObj.run() |
|
31 | self.controllerObj.run() | |
29 |
|
32 | |||
30 | class CommCtrlProcessThread(threading.Thread): |
|
33 | class CommCtrlProcessThread(threading.Thread): | |
31 | """ Implements the threading.Thread interface (start, join, etc.) and |
|
34 | """ Implements the threading.Thread interface (start, join, etc.) and | |
32 | can be controlled via the cmd_q Queue attribute. Replies are placed in |
|
35 | can be controlled via the cmd_q Queue attribute. Replies are placed in | |
33 | the reply_q Queue attribute. |
|
36 | the reply_q Queue attribute. | |
34 | """ |
|
37 | """ | |
35 | def __init__(self, cmd_q=Queue.Queue(), reply_q=Queue.Queue()): |
|
38 | def __init__(self, cmd_q=Queue.Queue(), reply_q=Queue.Queue()): | |
36 | super(CommCtrlProcessThread, self).__init__() |
|
39 | super(CommCtrlProcessThread, self).__init__() | |
37 | self.cmd_q = cmd_q |
|
40 | self.cmd_q = cmd_q | |
38 | # self.reply_q = reply_q |
|
41 | # self.reply_q = reply_q | |
39 |
|
42 | |||
40 | # self.print_q = Queue.Queue() |
|
43 | # self.print_q = Queue.Queue() | |
41 | # self.data_q = Queue.Queue() |
|
44 | # self.data_q = Queue.Queue() | |
42 |
|
45 | |||
43 |
|
46 | |||
44 | self.alive = threading.Event() |
|
47 | self.alive = threading.Event() | |
45 | self.setDaemon(True) |
|
48 | self.setDaemon(True) | |
46 | self.alive.set() |
|
49 | self.alive.set() | |
47 | self.socket = None |
|
50 | self.socket = None | |
48 |
|
51 | |||
49 | self.socketIO = None |
|
52 | self.socketIO = None | |
50 | self.mySocket = None |
|
53 | self.mySocket = None | |
51 |
|
54 | |||
|
55 | self.controllerObj = None | |||
52 |
|
56 | |||
53 | self.handlers = { |
|
57 | self.handlers = { | |
54 | ProcessCommand.PROCESS: self._handle_ioPROCESSTHREAD, |
|
58 | ProcessCommand.PROCESS: self._handle_ioPROCESSTHREAD, | |
55 | ProcessCommand.MESSAGE: self._handle_ioMESSAGE, |
|
59 | ProcessCommand.MESSAGE: self._handle_ioMESSAGE, | |
56 | ProcessCommand.DATA: self._handle_ioDATA, |
|
60 | ProcessCommand.DATA: self._handle_ioDATA, | |
57 | ProcessCommand.STOP: self._handle_ioSTOP, |
|
61 | ProcessCommand.STOP: self._handle_ioSTOP, | |
58 | ProcessCommand.PAUSE: self._handle_ioPAUSE |
|
62 | ProcessCommand.PAUSE: self._handle_ioPAUSE | |
59 | } |
|
63 | } | |
60 |
|
64 | |||
61 | def run(self): |
|
65 | def run(self): | |
62 |
|
66 | |||
63 | while self.alive.isSet(): |
|
67 | while self.alive.isSet(): | |
64 | try: |
|
68 | try: | |
65 | cmd = self.cmd_q.get(True, 0.1) |
|
69 | cmd = self.cmd_q.get(True, 0.1) | |
66 | self.handlers[cmd.type](cmd) |
|
70 | self.handlers[cmd.type](cmd) | |
67 | except Queue.Empty as e: |
|
71 | except Queue.Empty as e: | |
68 | sleep(0.1) |
|
72 | sleep(0.1) | |
69 | continue |
|
73 | continue | |
70 |
|
74 | |||
71 |
|
75 | def isRunning(self): | ||
|
76 | ||||
|
77 | if self.controllerObj == None: | |||
|
78 | return False | |||
|
79 | ||||
|
80 | if self.controllerObj.isAlive(): | |||
|
81 | return True | |||
|
82 | ||||
|
83 | return False | |||
|
84 | ||||
72 | def _handle_ioPROCESSTHREAD(self, cmd): |
|
85 | def _handle_ioPROCESSTHREAD(self, cmd): | |
73 | filename = cmd.data |
|
86 | filename = cmd.data | |
74 | self.controllerObj = ControllerThread(filename=filename) |
|
87 | self.controllerObj = ControllerThread(filename=filename) | |
75 | self.controllerObj.start() |
|
88 | self.controllerObj.start() | |
76 |
|
89 | |||
77 | def _handle_ioPAUSE(self, cmd): |
|
90 | def _handle_ioPAUSE(self, cmd): | |
78 | self.controllerObj.pause() |
|
91 | self.controllerObj.pause() | |
79 |
|
92 | |||
80 | def _handle_ioSTOP(self, cmd): |
|
93 | def _handle_ioSTOP(self, cmd): | |
81 | self.controllerObj.stop() |
|
94 | self.controllerObj.stop() | |
|
95 | self.controllerObj.join() | |||
|
96 | # print "Process thread finished" | |||
82 |
|
97 | |||
83 | def _handle_ioDATA(self, cmd): |
|
98 | def _handle_ioDATA(self, cmd): | |
84 | self.reply_q.put(self._success_reply_data(data=cmd.data)) |
|
99 | self.reply_q.put(self._success_reply_data(data=cmd.data)) | |
85 |
|
100 | |||
86 | def _handle_ioMESSAGE(self, cmd): |
|
101 | def _handle_ioMESSAGE(self, cmd): | |
87 | self.reply_q.put(self._success_reply_message(data=cmd.data)) |
|
102 | self.reply_q.put(self._success_reply_message(data=cmd.data)) | |
88 |
|
103 | |||
89 | def _success_reply_data(self, data=None): |
|
104 | def _success_reply_data(self, data=None): | |
90 | return ClientReply(ClientReply.DATA, data) |
|
105 | return ClientReply(ClientReply.DATA, data) | |
91 |
|
106 | |||
92 | def _success_reply_message(self, data=None): |
|
107 | def _success_reply_message(self, data=None): | |
93 | return ClientReply(ClientReply.MESSAGE, data) |
|
108 | return ClientReply(ClientReply.MESSAGE, data) | |
94 |
|
109 | |||
95 | def join(self, timeout=None): |
|
110 | def join(self, timeout=None): | |
96 | self.alive.clear() |
|
111 | self.alive.clear() | |
97 | threading.Thread.join(self, timeout) |
|
112 | threading.Thread.join(self, timeout) | |
98 |
|
113 | |||
99 |
|
114 | |||
100 | No newline at end of file |
|
115 |
@@ -1,83 +1,90 | |||||
1 | import numpy |
|
1 | import numpy | |
2 | import copy |
|
2 | import copy | |
3 |
|
3 | |||
4 | class Beam: |
|
4 | class Beam: | |
5 | def __init__(self): |
|
5 | def __init__(self): | |
6 | self.codeList = [] |
|
6 | self.codeList = [] | |
7 | self.azimuthList = [] |
|
7 | self.azimuthList = [] | |
8 | self.zenithList = [] |
|
8 | self.zenithList = [] | |
9 |
|
9 | |||
10 |
|
10 | |||
11 | class AMISR: |
|
11 | class AMISR: | |
12 | def __init__(self): |
|
12 | def __init__(self): | |
13 | self.flagNoData = True |
|
13 | self.flagNoData = True | |
14 | self.data = None |
|
14 | self.data = None | |
15 | self.utctime = None |
|
15 | self.utctime = None | |
16 | self.type = "AMISR" |
|
16 | self.type = "AMISR" | |
17 |
|
17 | |||
18 | #propiedades para compatibilidad con Voltages |
|
18 | #propiedades para compatibilidad con Voltages | |
19 | self.timeZone = 0#timezone like jroheader, difference in minutes between UTC and localtime |
|
19 | self.timeZone = 0#timezone like jroheader, difference in minutes between UTC and localtime | |
20 | self.dstFlag = 0#self.dataIn.dstFlag |
|
20 | self.dstFlag = 0#self.dataIn.dstFlag | |
21 | self.errorCount = 0#self.dataIn.errorCount |
|
21 | self.errorCount = 0#self.dataIn.errorCount | |
22 | self.useLocalTime = True#self.dataIn.useLocalTime |
|
22 | self.useLocalTime = True#self.dataIn.useLocalTime | |
23 |
|
23 | |||
24 | self.radarControllerHeaderObj = None#self.dataIn.radarControllerHeaderObj.copy() |
|
24 | self.radarControllerHeaderObj = None#self.dataIn.radarControllerHeaderObj.copy() | |
25 | self.systemHeaderObj = None#self.dataIn.systemHeaderObj.copy() |
|
25 | self.systemHeaderObj = None#self.dataIn.systemHeaderObj.copy() | |
26 | self.channelList = [0]#self.dataIn.channelList esto solo aplica para el caso de AMISR |
|
26 | self.channelList = [0]#self.dataIn.channelList esto solo aplica para el caso de AMISR | |
27 | self.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
27 | self.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
28 |
|
28 | |||
29 | self.flagDiscontinuousBlock = None#self.dataIn.flagDiscontinuousBlock |
|
29 | self.flagDiscontinuousBlock = None#self.dataIn.flagDiscontinuousBlock | |
30 | #self.utctime = #self.firstdatatime |
|
30 | #self.utctime = #self.firstdatatime | |
31 | self.flagDecodeData = None#self.dataIn.flagDecodeData #asumo q la data esta decodificada |
|
31 | self.flagDecodeData = None#self.dataIn.flagDecodeData #asumo q la data esta decodificada | |
32 | self.flagDeflipData = None#self.dataIn.flagDeflipData #asumo q la data esta sin flip |
|
32 | self.flagDeflipData = None#self.dataIn.flagDeflipData #asumo q la data esta sin flip | |
33 |
|
33 | |||
34 | self.nCohInt = 1#self.dataIn.nCohInt |
|
34 | self.nCohInt = 1#self.dataIn.nCohInt | |
35 | self.nIncohInt = 1 |
|
35 | self.nIncohInt = 1 | |
36 | self.ippSeconds = None#self.dataIn.ippSeconds, segun el filename/Setup/Tufile |
|
36 | self.ippSeconds = None#self.dataIn.ippSeconds, segun el filename/Setup/Tufile | |
37 | self.windowOfFilter = None#self.dataIn.windowOfFilter |
|
37 | self.windowOfFilter = None#self.dataIn.windowOfFilter | |
38 |
|
38 | |||
39 | self.timeInterval = None#self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt |
|
39 | self.timeInterval = None#self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt | |
40 | self.frequency = None#self.dataIn.frequency |
|
40 | self.frequency = None#self.dataIn.frequency | |
41 | self.realtime = 0#self.dataIn.realtime |
|
41 | self.realtime = 0#self.dataIn.realtime | |
42 |
|
42 | |||
43 | #actualizar en la lectura de datos |
|
43 | #actualizar en la lectura de datos | |
44 | self.heightList = None#self.dataIn.heightList |
|
44 | self.heightList = None#self.dataIn.heightList | |
45 | self.nProfiles = None#Number of samples or nFFTPoints |
|
45 | self.nProfiles = None#Number of samples or nFFTPoints | |
46 | self.nRecords = None |
|
46 | self.nRecords = None | |
47 | self.nBeams = None |
|
47 | self.nBeams = None | |
48 | self.nBaud = None#self.dataIn.nBaud |
|
48 | self.nBaud = None#self.dataIn.nBaud | |
49 | self.nCode = None#self.dataIn.nCode |
|
49 | self.nCode = None#self.dataIn.nCode | |
50 | self.code = None#self.dataIn.code |
|
50 | self.code = None#self.dataIn.code | |
51 |
|
51 | |||
52 | #consideracion para los Beams |
|
52 | #consideracion para los Beams | |
53 | self.beamCodeDict = None |
|
53 | self.beamCodeDict = None | |
54 | self.beamRangeDict = None |
|
54 | self.beamRangeDict = None | |
55 | self.beamcode = None |
|
55 | self.beamcode = None | |
56 | self.azimuth = None |
|
56 | self.azimuth = None | |
57 | self.zenith = None |
|
57 | self.zenith = None | |
58 | self.gain = None |
|
58 | self.gain = None | |
59 |
|
59 | |||
60 | self.npulseByFrame = None |
|
60 | self.npulseByFrame = None | |
61 |
|
61 | |||
62 | self.profileIndex = None |
|
62 | self.profileIndex = None | |
63 |
|
63 | |||
64 | self.beam = Beam() |
|
64 | self.beam = Beam() | |
65 |
|
65 | |||
66 | def copy(self, inputObj=None): |
|
66 | def copy(self, inputObj=None): | |
67 |
|
67 | |||
68 | if inputObj == None: |
|
68 | if inputObj == None: | |
69 | return copy.deepcopy(self) |
|
69 | return copy.deepcopy(self) | |
70 |
|
70 | |||
71 | for key in inputObj.__dict__.keys(): |
|
71 | for key in inputObj.__dict__.keys(): | |
72 | self.__dict__[key] = inputObj.__dict__[key] |
|
72 | self.__dict__[key] = inputObj.__dict__[key] | |
73 |
|
73 | |||
74 | def getNHeights(self): |
|
74 | def getNHeights(self): | |
75 |
|
75 | |||
76 | return len(self.heightList) |
|
76 | return len(self.heightList) | |
77 |
|
77 | |||
78 |
|
78 | |||
79 | def isEmpty(self): |
|
79 | def isEmpty(self): | |
80 |
|
80 | |||
81 | return self.flagNoData |
|
81 | return self.flagNoData | |
|
82 | ||||
|
83 | def getTimeInterval(self): | |||
|
84 | ||||
|
85 | timeInterval = self.ippSeconds * self.nCohInt | |||
|
86 | ||||
|
87 | return timeInterval | |||
82 |
|
88 | |||
|
89 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") | |||
83 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") No newline at end of file |
|
90 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") |
@@ -1,1102 +1,1115 | |||||
1 | ''' |
|
1 | ''' | |
2 |
|
2 | |||
3 | $Author: murco $ |
|
3 | $Author: murco $ | |
4 | $Id: JROData.py 173 2012-11-20 15:06:21Z murco $ |
|
4 | $Id: JROData.py 173 2012-11-20 15:06:21Z murco $ | |
5 | ''' |
|
5 | ''' | |
6 |
|
6 | |||
7 | import copy |
|
7 | import copy | |
8 | import numpy |
|
8 | import numpy | |
9 | import datetime |
|
9 | import datetime | |
10 |
|
10 | |||
11 | from jroheaderIO import SystemHeader, RadarControllerHeader |
|
11 | from jroheaderIO import SystemHeader, RadarControllerHeader | |
12 |
|
12 | |||
13 | def getNumpyDtype(dataTypeCode): |
|
13 | def getNumpyDtype(dataTypeCode): | |
14 |
|
14 | |||
15 | if dataTypeCode == 0: |
|
15 | if dataTypeCode == 0: | |
16 | numpyDtype = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
16 | numpyDtype = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
17 | elif dataTypeCode == 1: |
|
17 | elif dataTypeCode == 1: | |
18 | numpyDtype = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
18 | numpyDtype = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
19 | elif dataTypeCode == 2: |
|
19 | elif dataTypeCode == 2: | |
20 | numpyDtype = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
20 | numpyDtype = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
21 | elif dataTypeCode == 3: |
|
21 | elif dataTypeCode == 3: | |
22 | numpyDtype = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
22 | numpyDtype = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
23 | elif dataTypeCode == 4: |
|
23 | elif dataTypeCode == 4: | |
24 | numpyDtype = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
24 | numpyDtype = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
25 | elif dataTypeCode == 5: |
|
25 | elif dataTypeCode == 5: | |
26 | numpyDtype = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
26 | numpyDtype = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
27 | else: |
|
27 | else: | |
28 | raise ValueError, 'dataTypeCode was not defined' |
|
28 | raise ValueError, 'dataTypeCode was not defined' | |
29 |
|
29 | |||
30 | return numpyDtype |
|
30 | return numpyDtype | |
31 |
|
31 | |||
32 | def getDataTypeCode(numpyDtype): |
|
32 | def getDataTypeCode(numpyDtype): | |
33 |
|
33 | |||
34 | if numpyDtype == numpy.dtype([('real','<i1'),('imag','<i1')]): |
|
34 | if numpyDtype == numpy.dtype([('real','<i1'),('imag','<i1')]): | |
35 | datatype = 0 |
|
35 | datatype = 0 | |
36 | elif numpyDtype == numpy.dtype([('real','<i2'),('imag','<i2')]): |
|
36 | elif numpyDtype == numpy.dtype([('real','<i2'),('imag','<i2')]): | |
37 | datatype = 1 |
|
37 | datatype = 1 | |
38 | elif numpyDtype == numpy.dtype([('real','<i4'),('imag','<i4')]): |
|
38 | elif numpyDtype == numpy.dtype([('real','<i4'),('imag','<i4')]): | |
39 | datatype = 2 |
|
39 | datatype = 2 | |
40 | elif numpyDtype == numpy.dtype([('real','<i8'),('imag','<i8')]): |
|
40 | elif numpyDtype == numpy.dtype([('real','<i8'),('imag','<i8')]): | |
41 | datatype = 3 |
|
41 | datatype = 3 | |
42 | elif numpyDtype == numpy.dtype([('real','<f4'),('imag','<f4')]): |
|
42 | elif numpyDtype == numpy.dtype([('real','<f4'),('imag','<f4')]): | |
43 | datatype = 4 |
|
43 | datatype = 4 | |
44 | elif numpyDtype == numpy.dtype([('real','<f8'),('imag','<f8')]): |
|
44 | elif numpyDtype == numpy.dtype([('real','<f8'),('imag','<f8')]): | |
45 | datatype = 5 |
|
45 | datatype = 5 | |
46 | else: |
|
46 | else: | |
47 | datatype = None |
|
47 | datatype = None | |
48 |
|
48 | |||
49 | return datatype |
|
49 | return datatype | |
50 |
|
50 | |||
51 | def hildebrand_sekhon(data, navg): |
|
51 | def hildebrand_sekhon(data, navg): | |
52 | """ |
|
52 | """ | |
53 | This method is for the objective determination of the noise level in Doppler spectra. This |
|
53 | This method is for the objective determination of the noise level in Doppler spectra. This | |
54 | implementation technique is based on the fact that the standard deviation of the spectral |
|
54 | implementation technique is based on the fact that the standard deviation of the spectral | |
55 | densities is equal to the mean spectral density for white Gaussian noise |
|
55 | densities is equal to the mean spectral density for white Gaussian noise | |
56 |
|
56 | |||
57 | Inputs: |
|
57 | Inputs: | |
58 | Data : heights |
|
58 | Data : heights | |
59 | navg : numbers of averages |
|
59 | navg : numbers of averages | |
60 |
|
60 | |||
61 | Return: |
|
61 | Return: | |
62 | -1 : any error |
|
62 | -1 : any error | |
63 | anoise : noise's level |
|
63 | anoise : noise's level | |
64 | """ |
|
64 | """ | |
65 |
|
65 | |||
66 | sortdata = numpy.sort(data,axis=None) |
|
66 | sortdata = numpy.sort(data,axis=None) | |
67 | lenOfData = len(sortdata) |
|
67 | lenOfData = len(sortdata) | |
68 | nums_min = lenOfData/10 |
|
68 | nums_min = lenOfData/10 | |
69 |
|
69 | |||
70 | if (lenOfData/10) > 2: |
|
70 | if (lenOfData/10) > 2: | |
71 | nums_min = lenOfData/10 |
|
71 | nums_min = lenOfData/10 | |
72 | else: |
|
72 | else: | |
73 | nums_min = 2 |
|
73 | nums_min = 2 | |
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 | j += 1 |
|
89 | j += 1 | |
90 |
|
90 | |||
91 | if j > nums_min: |
|
91 | if j > nums_min: | |
92 | rtest = float(j)/(j-1) + 1.0/navg |
|
92 | rtest = float(j)/(j-1) + 1.0/navg | |
93 | if ((sumq*j) > (rtest*sump**2)): |
|
93 | if ((sumq*j) > (rtest*sump**2)): | |
94 | j = j - 1 |
|
94 | j = j - 1 | |
95 | sump = sump - sortdata[j] |
|
95 | sump = sump - sortdata[j] | |
96 | sumq = sumq - sortdata[j]**2 |
|
96 | sumq = sumq - sortdata[j]**2 | |
97 | cont = 0 |
|
97 | cont = 0 | |
98 |
|
98 | |||
99 | lnoise = sump /j |
|
99 | lnoise = sump /j | |
100 | stdv = numpy.sqrt((sumq - lnoise**2)/(j - 1)) |
|
100 | stdv = numpy.sqrt((sumq - lnoise**2)/(j - 1)) | |
101 | return lnoise |
|
101 | return lnoise | |
102 |
|
102 | |||
103 | class Beam: |
|
103 | class Beam: | |
104 | def __init__(self): |
|
104 | def __init__(self): | |
105 | self.codeList = [] |
|
105 | self.codeList = [] | |
106 | self.azimuthList = [] |
|
106 | self.azimuthList = [] | |
107 | self.zenithList = [] |
|
107 | self.zenithList = [] | |
108 |
|
108 | |||
109 | class GenericData(object): |
|
109 | class GenericData(object): | |
110 |
|
110 | |||
111 | flagNoData = True |
|
111 | flagNoData = True | |
112 |
|
112 | |||
113 | def __init__(self): |
|
113 | def __init__(self): | |
114 |
|
114 | |||
115 | raise ValueError, "This class has not been implemented" |
|
115 | raise ValueError, "This class has not been implemented" | |
116 |
|
116 | |||
117 | def copy(self, inputObj=None): |
|
117 | def copy(self, inputObj=None): | |
118 |
|
118 | |||
119 | if inputObj == None: |
|
119 | if inputObj == None: | |
120 | return copy.deepcopy(self) |
|
120 | return copy.deepcopy(self) | |
121 |
|
121 | |||
122 | for key in inputObj.__dict__.keys(): |
|
122 | for key in inputObj.__dict__.keys(): | |
123 | self.__dict__[key] = inputObj.__dict__[key] |
|
123 | self.__dict__[key] = inputObj.__dict__[key] | |
124 |
|
124 | |||
125 | def deepcopy(self): |
|
125 | def deepcopy(self): | |
126 |
|
126 | |||
127 | return copy.deepcopy(self) |
|
127 | return copy.deepcopy(self) | |
128 |
|
128 | |||
129 | def isEmpty(self): |
|
129 | def isEmpty(self): | |
130 |
|
130 | |||
131 | return self.flagNoData |
|
131 | return self.flagNoData | |
132 |
|
132 | |||
133 | class JROData(GenericData): |
|
133 | class JROData(GenericData): | |
134 |
|
134 | |||
135 | # m_BasicHeader = BasicHeader() |
|
135 | # m_BasicHeader = BasicHeader() | |
136 | # m_ProcessingHeader = ProcessingHeader() |
|
136 | # m_ProcessingHeader = ProcessingHeader() | |
137 |
|
137 | |||
138 | systemHeaderObj = SystemHeader() |
|
138 | systemHeaderObj = SystemHeader() | |
139 |
|
139 | |||
140 | radarControllerHeaderObj = RadarControllerHeader() |
|
140 | radarControllerHeaderObj = RadarControllerHeader() | |
141 |
|
141 | |||
142 | # data = None |
|
142 | # data = None | |
143 |
|
143 | |||
144 | type = None |
|
144 | type = None | |
145 |
|
145 | |||
146 | datatype = None #dtype but in string |
|
146 | datatype = None #dtype but in string | |
147 |
|
147 | |||
148 | # dtype = None |
|
148 | # dtype = None | |
149 |
|
149 | |||
150 | # nChannels = None |
|
150 | # nChannels = None | |
151 |
|
151 | |||
152 | # nHeights = None |
|
152 | # nHeights = None | |
153 |
|
153 | |||
154 | nProfiles = None |
|
154 | nProfiles = None | |
155 |
|
155 | |||
156 | heightList = None |
|
156 | heightList = None | |
157 |
|
157 | |||
158 | channelList = None |
|
158 | channelList = None | |
159 |
|
159 | |||
160 | flagDiscontinuousBlock = False |
|
160 | flagDiscontinuousBlock = False | |
161 |
|
161 | |||
162 | useLocalTime = False |
|
162 | useLocalTime = False | |
163 |
|
163 | |||
164 | utctime = None |
|
164 | utctime = None | |
165 |
|
165 | |||
166 | timeZone = None |
|
166 | timeZone = None | |
167 |
|
167 | |||
168 | dstFlag = None |
|
168 | dstFlag = None | |
169 |
|
169 | |||
170 | errorCount = None |
|
170 | errorCount = None | |
171 |
|
171 | |||
172 | blocksize = None |
|
172 | blocksize = None | |
173 |
|
173 | |||
174 | # nCode = None |
|
174 | # nCode = None | |
175 | # |
|
175 | # | |
176 | # nBaud = None |
|
176 | # nBaud = None | |
177 | # |
|
177 | # | |
178 | # code = None |
|
178 | # code = None | |
179 |
|
179 | |||
180 | flagDecodeData = False #asumo q la data no esta decodificada |
|
180 | flagDecodeData = False #asumo q la data no esta decodificada | |
181 |
|
181 | |||
182 | flagDeflipData = False #asumo q la data no esta sin flip |
|
182 | flagDeflipData = False #asumo q la data no esta sin flip | |
183 |
|
183 | |||
184 | flagShiftFFT = False |
|
184 | flagShiftFFT = False | |
185 |
|
185 | |||
186 | # ippSeconds = None |
|
186 | # ippSeconds = None | |
187 |
|
187 | |||
188 | # timeInterval = None |
|
188 | # timeInterval = None | |
189 |
|
189 | |||
190 | nCohInt = None |
|
190 | nCohInt = None | |
191 |
|
191 | |||
192 | # noise = None |
|
192 | # noise = None | |
193 |
|
193 | |||
194 | windowOfFilter = 1 |
|
194 | windowOfFilter = 1 | |
195 |
|
195 | |||
196 | #Speed of ligth |
|
196 | #Speed of ligth | |
197 | C = 3e8 |
|
197 | C = 3e8 | |
198 |
|
198 | |||
199 | frequency = 49.92e6 |
|
199 | frequency = 49.92e6 | |
200 |
|
200 | |||
201 | realtime = False |
|
201 | realtime = False | |
202 |
|
202 | |||
203 | beacon_heiIndexList = None |
|
203 | beacon_heiIndexList = None | |
204 |
|
204 | |||
205 | last_block = None |
|
205 | last_block = None | |
206 |
|
206 | |||
207 | blocknow = None |
|
207 | blocknow = None | |
208 |
|
208 | |||
209 | azimuth = None |
|
209 | azimuth = None | |
210 |
|
210 | |||
211 | zenith = None |
|
211 | zenith = None | |
212 |
|
212 | |||
213 | beam = Beam() |
|
213 | beam = Beam() | |
214 |
|
214 | |||
215 | profileIndex = None |
|
215 | profileIndex = None | |
216 |
|
216 | |||
217 | def __init__(self): |
|
217 | def __init__(self): | |
218 |
|
218 | |||
219 | raise ValueError, "This class has not been implemented" |
|
219 | raise ValueError, "This class has not been implemented" | |
220 |
|
220 | |||
221 | def getNoise(self): |
|
221 | def getNoise(self): | |
222 |
|
222 | |||
223 | raise ValueError, "Not implemented" |
|
223 | raise ValueError, "Not implemented" | |
224 |
|
224 | |||
225 | def getNChannels(self): |
|
225 | def getNChannels(self): | |
226 |
|
226 | |||
227 | return len(self.channelList) |
|
227 | return len(self.channelList) | |
228 |
|
228 | |||
229 | def getChannelIndexList(self): |
|
229 | def getChannelIndexList(self): | |
230 |
|
230 | |||
231 | return range(self.nChannels) |
|
231 | return range(self.nChannels) | |
232 |
|
232 | |||
233 | def getNHeights(self): |
|
233 | def getNHeights(self): | |
234 |
|
234 | |||
235 | return len(self.heightList) |
|
235 | return len(self.heightList) | |
236 |
|
236 | |||
237 | def getHeiRange(self, extrapoints=0): |
|
237 | def getHeiRange(self, extrapoints=0): | |
238 |
|
238 | |||
239 | heis = self.heightList |
|
239 | heis = self.heightList | |
240 | # deltah = self.heightList[1] - self.heightList[0] |
|
240 | # deltah = self.heightList[1] - self.heightList[0] | |
241 | # |
|
241 | # | |
242 | # heis.append(self.heightList[-1]) |
|
242 | # heis.append(self.heightList[-1]) | |
243 |
|
243 | |||
244 | return heis |
|
244 | return heis | |
245 |
|
245 | |||
246 | def getltctime(self): |
|
246 | def getltctime(self): | |
247 |
|
247 | |||
248 | if self.useLocalTime: |
|
248 | if self.useLocalTime: | |
249 | return self.utctime - self.timeZone*60 |
|
249 | return self.utctime - self.timeZone*60 | |
250 |
|
250 | |||
251 | return self.utctime |
|
251 | return self.utctime | |
252 |
|
252 | |||
253 | def getDatatime(self): |
|
253 | def getDatatime(self): | |
254 |
|
254 | |||
255 | datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime) |
|
255 | datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime) | |
256 | return datatimeValue |
|
256 | return datatimeValue | |
257 |
|
257 | |||
258 | def getTimeRange(self): |
|
258 | def getTimeRange(self): | |
259 |
|
259 | |||
260 | datatime = [] |
|
260 | datatime = [] | |
261 |
|
261 | |||
262 | datatime.append(self.ltctime) |
|
262 | datatime.append(self.ltctime) | |
263 | datatime.append(self.ltctime + self.timeInterval+60) |
|
263 | datatime.append(self.ltctime + self.timeInterval+60) | |
264 |
|
264 | |||
265 | datatime = numpy.array(datatime) |
|
265 | datatime = numpy.array(datatime) | |
266 |
|
266 | |||
267 | return datatime |
|
267 | return datatime | |
268 |
|
268 | |||
269 | def getFmax(self): |
|
269 | def getFmax(self): | |
270 |
|
270 | |||
271 | PRF = 1./(self.ippSeconds * self.nCohInt) |
|
271 | PRF = 1./(self.ippSeconds * self.nCohInt) | |
272 |
|
272 | |||
273 | fmax = PRF/2. |
|
273 | fmax = PRF/2. | |
274 |
|
274 | |||
275 | return fmax |
|
275 | return fmax | |
276 |
|
276 | |||
277 | def getVmax(self): |
|
277 | def getVmax(self): | |
278 |
|
278 | |||
279 | _lambda = self.C/self.frequency |
|
279 | _lambda = self.C/self.frequency | |
280 |
|
280 | |||
281 | vmax = self.getFmax() * _lambda |
|
281 | vmax = self.getFmax() * _lambda | |
282 |
|
282 | |||
283 | return vmax |
|
283 | return vmax | |
284 |
|
284 | |||
285 | def get_ippSeconds(self): |
|
285 | def get_ippSeconds(self): | |
286 | ''' |
|
286 | ''' | |
287 | ''' |
|
287 | ''' | |
288 | return self.radarControllerHeaderObj.ippSeconds |
|
288 | return self.radarControllerHeaderObj.ippSeconds | |
289 |
|
289 | |||
290 | def set_ippSeconds(self, ippSeconds): |
|
290 | def set_ippSeconds(self, ippSeconds): | |
291 | ''' |
|
291 | ''' | |
292 | ''' |
|
292 | ''' | |
293 |
|
293 | |||
294 | self.radarControllerHeaderObj.ippSeconds = ippSeconds |
|
294 | self.radarControllerHeaderObj.ippSeconds = ippSeconds | |
295 |
|
295 | |||
296 | return |
|
296 | return | |
297 |
|
297 | |||
298 | def get_dtype(self): |
|
298 | def get_dtype(self): | |
299 | ''' |
|
299 | ''' | |
300 | ''' |
|
300 | ''' | |
301 | return getNumpyDtype(self.datatype) |
|
301 | return getNumpyDtype(self.datatype) | |
302 |
|
302 | |||
303 | def set_dtype(self, numpyDtype): |
|
303 | def set_dtype(self, numpyDtype): | |
304 | ''' |
|
304 | ''' | |
305 | ''' |
|
305 | ''' | |
306 |
|
306 | |||
307 | self.datatype = getDataTypeCode(numpyDtype) |
|
307 | self.datatype = getDataTypeCode(numpyDtype) | |
308 |
|
308 | |||
309 | def get_code(self): |
|
309 | def get_code(self): | |
310 | ''' |
|
310 | ''' | |
311 | ''' |
|
311 | ''' | |
312 | return self.radarControllerHeaderObj.code |
|
312 | return self.radarControllerHeaderObj.code | |
313 |
|
313 | |||
314 | def set_code(self, code): |
|
314 | def set_code(self, code): | |
315 | ''' |
|
315 | ''' | |
316 | ''' |
|
316 | ''' | |
317 | self.radarControllerHeaderObj.code = code |
|
317 | self.radarControllerHeaderObj.code = code | |
318 |
|
318 | |||
319 | return |
|
319 | return | |
320 |
|
320 | |||
321 | def get_ncode(self): |
|
321 | def get_ncode(self): | |
322 | ''' |
|
322 | ''' | |
323 | ''' |
|
323 | ''' | |
324 | return self.radarControllerHeaderObj.nCode |
|
324 | return self.radarControllerHeaderObj.nCode | |
325 |
|
325 | |||
326 | def set_ncode(self, nCode): |
|
326 | def set_ncode(self, nCode): | |
327 | ''' |
|
327 | ''' | |
328 | ''' |
|
328 | ''' | |
329 | self.radarControllerHeaderObj.nCode = nCode |
|
329 | self.radarControllerHeaderObj.nCode = nCode | |
330 |
|
330 | |||
331 | return |
|
331 | return | |
332 |
|
332 | |||
333 | def get_nbaud(self): |
|
333 | def get_nbaud(self): | |
334 | ''' |
|
334 | ''' | |
335 | ''' |
|
335 | ''' | |
336 | return self.radarControllerHeaderObj.nBaud |
|
336 | return self.radarControllerHeaderObj.nBaud | |
337 |
|
337 | |||
338 | def set_nbaud(self, nBaud): |
|
338 | def set_nbaud(self, nBaud): | |
339 | ''' |
|
339 | ''' | |
340 | ''' |
|
340 | ''' | |
341 | self.radarControllerHeaderObj.nBaud = nBaud |
|
341 | self.radarControllerHeaderObj.nBaud = nBaud | |
342 |
|
342 | |||
343 | return |
|
343 | return | |
344 | # def getTimeInterval(self): |
|
344 | # def getTimeInterval(self): | |
345 | # |
|
345 | # | |
346 | # raise IOError, "This method should be implemented inside each Class" |
|
346 | # raise IOError, "This method should be implemented inside each Class" | |
347 |
|
347 | |||
348 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") |
|
348 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") | |
349 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") |
|
349 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") | |
350 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") |
|
350 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") | |
351 | #noise = property(getNoise, "I'm the 'nHeights' property.") |
|
351 | #noise = property(getNoise, "I'm the 'nHeights' property.") | |
352 | datatime = property(getDatatime, "I'm the 'datatime' property") |
|
352 | datatime = property(getDatatime, "I'm the 'datatime' property") | |
353 | ltctime = property(getltctime, "I'm the 'ltctime' property") |
|
353 | ltctime = property(getltctime, "I'm the 'ltctime' property") | |
354 | ippSeconds = property(get_ippSeconds, set_ippSeconds) |
|
354 | ippSeconds = property(get_ippSeconds, set_ippSeconds) | |
355 | dtype = property(get_dtype, set_dtype) |
|
355 | dtype = property(get_dtype, set_dtype) | |
356 | # timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
356 | # timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") | |
357 | code = property(get_code, set_code) |
|
357 | code = property(get_code, set_code) | |
358 | nCode = property(get_ncode, set_ncode) |
|
358 | nCode = property(get_ncode, set_ncode) | |
359 | nBaud = property(get_nbaud, set_nbaud) |
|
359 | nBaud = property(get_nbaud, set_nbaud) | |
360 |
|
360 | |||
361 | class Voltage(JROData): |
|
361 | class Voltage(JROData): | |
362 |
|
362 | |||
363 | #data es un numpy array de 2 dmensiones (canales, alturas) |
|
363 | #data es un numpy array de 2 dmensiones (canales, alturas) | |
364 | data = None |
|
364 | data = None | |
365 |
|
365 | |||
366 | def __init__(self): |
|
366 | def __init__(self): | |
367 | ''' |
|
367 | ''' | |
368 | Constructor |
|
368 | Constructor | |
369 | ''' |
|
369 | ''' | |
370 |
|
370 | |||
371 | self.useLocalTime = True |
|
371 | self.useLocalTime = True | |
372 |
|
372 | |||
373 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
373 | self.radarControllerHeaderObj = RadarControllerHeader() | |
374 |
|
374 | |||
375 | self.systemHeaderObj = SystemHeader() |
|
375 | self.systemHeaderObj = SystemHeader() | |
376 |
|
376 | |||
377 | self.type = "Voltage" |
|
377 | self.type = "Voltage" | |
378 |
|
378 | |||
379 | self.data = None |
|
379 | self.data = None | |
380 |
|
380 | |||
381 | # self.dtype = None |
|
381 | # self.dtype = None | |
382 |
|
382 | |||
383 | # self.nChannels = 0 |
|
383 | # self.nChannels = 0 | |
384 |
|
384 | |||
385 | # self.nHeights = 0 |
|
385 | # self.nHeights = 0 | |
386 |
|
386 | |||
387 | self.nProfiles = None |
|
387 | self.nProfiles = None | |
388 |
|
388 | |||
389 | self.heightList = None |
|
389 | self.heightList = None | |
390 |
|
390 | |||
391 | self.channelList = None |
|
391 | self.channelList = None | |
392 |
|
392 | |||
393 | # self.channelIndexList = None |
|
393 | # self.channelIndexList = None | |
394 |
|
394 | |||
395 | self.flagNoData = True |
|
395 | self.flagNoData = True | |
396 |
|
396 | |||
397 | self.flagDiscontinuousBlock = False |
|
397 | self.flagDiscontinuousBlock = False | |
398 |
|
398 | |||
399 | self.utctime = None |
|
399 | self.utctime = None | |
400 |
|
400 | |||
401 | self.timeZone = None |
|
401 | self.timeZone = None | |
402 |
|
402 | |||
403 | self.dstFlag = None |
|
403 | self.dstFlag = None | |
404 |
|
404 | |||
405 | self.errorCount = None |
|
405 | self.errorCount = None | |
406 |
|
406 | |||
407 | self.nCohInt = None |
|
407 | self.nCohInt = None | |
408 |
|
408 | |||
409 | self.blocksize = None |
|
409 | self.blocksize = None | |
410 |
|
410 | |||
411 | self.flagDecodeData = False #asumo q la data no esta decodificada |
|
411 | self.flagDecodeData = False #asumo q la data no esta decodificada | |
412 |
|
412 | |||
413 | self.flagDeflipData = False #asumo q la data no esta sin flip |
|
413 | self.flagDeflipData = False #asumo q la data no esta sin flip | |
414 |
|
414 | |||
415 | self.flagShiftFFT = False |
|
415 | self.flagShiftFFT = False | |
416 |
|
416 | |||
417 | self.flagDataAsBlock = False #Asumo que la data es leida perfil a perfil |
|
417 | self.flagDataAsBlock = False #Asumo que la data es leida perfil a perfil | |
418 |
|
418 | |||
419 | self.profileIndex = 0 |
|
419 | self.profileIndex = 0 | |
420 |
|
420 | |||
421 | def getNoisebyHildebrand(self, channel = None): |
|
421 | def getNoisebyHildebrand(self, channel = None): | |
422 | """ |
|
422 | """ | |
423 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
|
423 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon | |
424 |
|
424 | |||
425 | Return: |
|
425 | Return: | |
426 | noiselevel |
|
426 | noiselevel | |
427 | """ |
|
427 | """ | |
428 |
|
428 | |||
429 | if channel != None: |
|
429 | if channel != None: | |
430 | data = self.data[channel] |
|
430 | data = self.data[channel] | |
431 | nChannels = 1 |
|
431 | nChannels = 1 | |
432 | else: |
|
432 | else: | |
433 | data = self.data |
|
433 | data = self.data | |
434 | nChannels = self.nChannels |
|
434 | nChannels = self.nChannels | |
435 |
|
435 | |||
436 | noise = numpy.zeros(nChannels) |
|
436 | noise = numpy.zeros(nChannels) | |
437 | power = data * numpy.conjugate(data) |
|
437 | power = data * numpy.conjugate(data) | |
438 |
|
438 | |||
439 | for thisChannel in range(nChannels): |
|
439 | for thisChannel in range(nChannels): | |
440 | if nChannels == 1: |
|
440 | if nChannels == 1: | |
441 | daux = power[:].real |
|
441 | daux = power[:].real | |
442 | else: |
|
442 | else: | |
443 | daux = power[thisChannel,:].real |
|
443 | daux = power[thisChannel,:].real | |
444 | noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt) |
|
444 | noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt) | |
445 |
|
445 | |||
446 | return noise |
|
446 | return noise | |
447 |
|
447 | |||
448 | def getNoise(self, type = 1, channel = None): |
|
448 | def getNoise(self, type = 1, channel = None): | |
449 |
|
449 | |||
450 | if type == 1: |
|
450 | if type == 1: | |
451 | noise = self.getNoisebyHildebrand(channel) |
|
451 | noise = self.getNoisebyHildebrand(channel) | |
452 |
|
452 | |||
453 | return 10*numpy.log10(noise) |
|
453 | return 10*numpy.log10(noise) | |
454 |
|
454 | |||
455 | def getPower(self, channel = None): |
|
455 | def getPower(self, channel = None): | |
456 |
|
456 | |||
457 | if channel != None: |
|
457 | if channel != None: | |
458 | data = self.data[channel] |
|
458 | data = self.data[channel] | |
459 | else: |
|
459 | else: | |
460 | data = self.data |
|
460 | data = self.data | |
461 |
|
461 | |||
462 | power = data * numpy.conjugate(data) |
|
462 | power = data * numpy.conjugate(data) | |
463 |
|
463 | |||
464 | return 10*numpy.log10(power.real) |
|
464 | return 10*numpy.log10(power.real) | |
465 |
|
465 | |||
466 | def getTimeInterval(self): |
|
466 | def getTimeInterval(self): | |
467 |
|
467 | |||
468 | timeInterval = self.ippSeconds * self.nCohInt |
|
468 | timeInterval = self.ippSeconds * self.nCohInt | |
469 |
|
469 | |||
470 | return timeInterval |
|
470 | return timeInterval | |
471 |
|
471 | |||
472 | noise = property(getNoise, "I'm the 'nHeights' property.") |
|
472 | noise = property(getNoise, "I'm the 'nHeights' property.") | |
473 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
473 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") | |
474 |
|
474 | |||
475 | class Spectra(JROData): |
|
475 | class Spectra(JROData): | |
476 |
|
476 | |||
477 | #data es un numpy array de 2 dmensiones (canales, perfiles, alturas) |
|
477 | #data es un numpy array de 2 dmensiones (canales, perfiles, alturas) | |
478 | data_spc = None |
|
478 | data_spc = None | |
479 |
|
479 | |||
480 | #data es un numpy array de 2 dmensiones (canales, pares, alturas) |
|
480 | #data es un numpy array de 2 dmensiones (canales, pares, alturas) | |
481 | data_cspc = None |
|
481 | data_cspc = None | |
482 |
|
482 | |||
483 | #data es un numpy array de 2 dmensiones (canales, alturas) |
|
483 | #data es un numpy array de 2 dmensiones (canales, alturas) | |
484 | data_dc = None |
|
484 | data_dc = None | |
485 |
|
485 | |||
486 | nFFTPoints = None |
|
486 | nFFTPoints = None | |
487 |
|
487 | |||
488 | # nPairs = None |
|
488 | # nPairs = None | |
489 |
|
489 | |||
490 | pairsList = None |
|
490 | pairsList = None | |
491 |
|
491 | |||
492 | nIncohInt = None |
|
492 | nIncohInt = None | |
493 |
|
493 | |||
494 | wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia |
|
494 | wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia | |
495 |
|
495 | |||
496 | nCohInt = None #se requiere para determinar el valor de timeInterval |
|
496 | nCohInt = None #se requiere para determinar el valor de timeInterval | |
497 |
|
497 | |||
498 | ippFactor = None |
|
498 | ippFactor = None | |
499 |
|
499 | |||
500 | profileIndex = 0 |
|
500 | profileIndex = 0 | |
501 |
|
501 | |||
502 | def __init__(self): |
|
502 | def __init__(self): | |
503 | ''' |
|
503 | ''' | |
504 | Constructor |
|
504 | Constructor | |
505 | ''' |
|
505 | ''' | |
506 |
|
506 | |||
507 | self.useLocalTime = True |
|
507 | self.useLocalTime = True | |
508 |
|
508 | |||
509 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
509 | self.radarControllerHeaderObj = RadarControllerHeader() | |
510 |
|
510 | |||
511 | self.systemHeaderObj = SystemHeader() |
|
511 | self.systemHeaderObj = SystemHeader() | |
512 |
|
512 | |||
513 | self.type = "Spectra" |
|
513 | self.type = "Spectra" | |
514 |
|
514 | |||
515 | # self.data = None |
|
515 | # self.data = None | |
516 |
|
516 | |||
517 | # self.dtype = None |
|
517 | # self.dtype = None | |
518 |
|
518 | |||
519 | # self.nChannels = 0 |
|
519 | # self.nChannels = 0 | |
520 |
|
520 | |||
521 | # self.nHeights = 0 |
|
521 | # self.nHeights = 0 | |
522 |
|
522 | |||
523 | self.nProfiles = None |
|
523 | self.nProfiles = None | |
524 |
|
524 | |||
525 | self.heightList = None |
|
525 | self.heightList = None | |
526 |
|
526 | |||
527 | self.channelList = None |
|
527 | self.channelList = None | |
528 |
|
528 | |||
529 | # self.channelIndexList = None |
|
529 | # self.channelIndexList = None | |
530 |
|
530 | |||
531 | self.pairsList = None |
|
531 | self.pairsList = None | |
532 |
|
532 | |||
533 | self.flagNoData = True |
|
533 | self.flagNoData = True | |
534 |
|
534 | |||
535 | self.flagDiscontinuousBlock = False |
|
535 | self.flagDiscontinuousBlock = False | |
536 |
|
536 | |||
537 | self.utctime = None |
|
537 | self.utctime = None | |
538 |
|
538 | |||
539 | self.nCohInt = None |
|
539 | self.nCohInt = None | |
540 |
|
540 | |||
541 | self.nIncohInt = None |
|
541 | self.nIncohInt = None | |
542 |
|
542 | |||
543 | self.blocksize = None |
|
543 | self.blocksize = None | |
544 |
|
544 | |||
545 | self.nFFTPoints = None |
|
545 | self.nFFTPoints = None | |
546 |
|
546 | |||
547 | self.wavelength = None |
|
547 | self.wavelength = None | |
548 |
|
548 | |||
549 | self.flagDecodeData = False #asumo q la data no esta decodificada |
|
549 | self.flagDecodeData = False #asumo q la data no esta decodificada | |
550 |
|
550 | |||
551 | self.flagDeflipData = False #asumo q la data no esta sin flip |
|
551 | self.flagDeflipData = False #asumo q la data no esta sin flip | |
552 |
|
552 | |||
553 | self.flagShiftFFT = False |
|
553 | self.flagShiftFFT = False | |
554 |
|
554 | |||
555 | self.ippFactor = 1 |
|
555 | self.ippFactor = 1 | |
556 |
|
556 | |||
557 | #self.noise = None |
|
557 | #self.noise = None | |
558 |
|
558 | |||
559 | self.beacon_heiIndexList = [] |
|
559 | self.beacon_heiIndexList = [] | |
560 |
|
560 | |||
561 | self.noise_estimation = None |
|
561 | self.noise_estimation = None | |
562 |
|
562 | |||
563 |
|
563 | |||
564 | def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None): |
|
564 | def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None): | |
565 | """ |
|
565 | """ | |
566 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
|
566 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon | |
567 |
|
567 | |||
568 | Return: |
|
568 | Return: | |
569 | noiselevel |
|
569 | noiselevel | |
570 | """ |
|
570 | """ | |
571 |
|
571 | |||
572 | noise = numpy.zeros(self.nChannels) |
|
572 | noise = numpy.zeros(self.nChannels) | |
573 |
|
573 | |||
574 | for channel in range(self.nChannels): |
|
574 | for channel in range(self.nChannels): | |
575 | daux = self.data_spc[channel,xmin_index:xmax_index,ymin_index:ymax_index] |
|
575 | daux = self.data_spc[channel,xmin_index:xmax_index,ymin_index:ymax_index] | |
576 | noise[channel] = hildebrand_sekhon(daux, self.nIncohInt) |
|
576 | noise[channel] = hildebrand_sekhon(daux, self.nIncohInt) | |
577 |
|
577 | |||
578 | return noise |
|
578 | return noise | |
579 |
|
579 | |||
580 | def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None): |
|
580 | def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None): | |
581 |
|
581 | |||
582 | if self.noise_estimation != None: |
|
582 | if self.noise_estimation != None: | |
583 | return self.noise_estimation #this was estimated by getNoise Operation defined in jroproc_spectra.py |
|
583 | return self.noise_estimation #this was estimated by getNoise Operation defined in jroproc_spectra.py | |
584 | else: |
|
584 | else: | |
585 | noise = self.getNoisebyHildebrand(xmin_index, xmax_index, ymin_index, ymax_index) |
|
585 | noise = self.getNoisebyHildebrand(xmin_index, xmax_index, ymin_index, ymax_index) | |
586 | return noise |
|
586 | return noise | |
587 |
|
587 | |||
588 |
|
588 | |||
589 | def getFreqRange(self, extrapoints=0): |
|
589 | def getFreqRange(self, extrapoints=0): | |
590 |
|
590 | |||
591 | deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor) |
|
591 | deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor) | |
592 | freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 |
|
592 | freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 | |
593 |
|
593 | |||
594 | return freqrange |
|
594 | return freqrange | |
595 |
|
595 | |||
596 | def getVelRange(self, extrapoints=0): |
|
596 | def getVelRange(self, extrapoints=0): | |
597 |
|
597 | |||
598 | deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor) |
|
598 | deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor) | |
599 | velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltav/2 |
|
599 | velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltav/2 | |
600 |
|
600 | |||
601 | return velrange |
|
601 | return velrange | |
602 |
|
602 | |||
603 | def getNPairs(self): |
|
603 | def getNPairs(self): | |
604 |
|
604 | |||
605 | return len(self.pairsList) |
|
605 | return len(self.pairsList) | |
606 |
|
606 | |||
607 | def getPairsIndexList(self): |
|
607 | def getPairsIndexList(self): | |
608 |
|
608 | |||
609 | return range(self.nPairs) |
|
609 | return range(self.nPairs) | |
610 |
|
610 | |||
611 | def getNormFactor(self): |
|
611 | def getNormFactor(self): | |
612 | pwcode = 1 |
|
612 | pwcode = 1 | |
613 | if self.flagDecodeData: |
|
613 | if self.flagDecodeData: | |
614 | pwcode = numpy.sum(self.code[0]**2) |
|
614 | pwcode = numpy.sum(self.code[0]**2) | |
615 | #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter |
|
615 | #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter | |
616 | normFactor = self.nProfiles*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter |
|
616 | normFactor = self.nProfiles*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter | |
617 |
|
617 | |||
618 | return normFactor |
|
618 | return normFactor | |
619 |
|
619 | |||
620 | def getFlagCspc(self): |
|
620 | def getFlagCspc(self): | |
621 |
|
621 | |||
622 | if self.data_cspc == None: |
|
622 | if self.data_cspc == None: | |
623 | return True |
|
623 | return True | |
624 |
|
624 | |||
625 | return False |
|
625 | return False | |
626 |
|
626 | |||
627 | def getFlagDc(self): |
|
627 | def getFlagDc(self): | |
628 |
|
628 | |||
629 | if self.data_dc == None: |
|
629 | if self.data_dc == None: | |
630 | return True |
|
630 | return True | |
631 |
|
631 | |||
632 | return False |
|
632 | return False | |
633 |
|
633 | |||
634 | def getTimeInterval(self): |
|
634 | def getTimeInterval(self): | |
635 |
|
635 | |||
636 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles |
|
636 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles | |
637 |
|
637 | |||
638 | return timeInterval |
|
638 | return timeInterval | |
639 |
|
639 | |||
640 | nPairs = property(getNPairs, "I'm the 'nPairs' property.") |
|
640 | nPairs = property(getNPairs, "I'm the 'nPairs' property.") | |
641 | pairsIndexList = property(getPairsIndexList, "I'm the 'pairsIndexList' property.") |
|
641 | pairsIndexList = property(getPairsIndexList, "I'm the 'pairsIndexList' property.") | |
642 | normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.") |
|
642 | normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.") | |
643 | flag_cspc = property(getFlagCspc) |
|
643 | flag_cspc = property(getFlagCspc) | |
644 | flag_dc = property(getFlagDc) |
|
644 | flag_dc = property(getFlagDc) | |
645 | noise = property(getNoise, "I'm the 'nHeights' property.") |
|
645 | noise = property(getNoise, "I'm the 'nHeights' property.") | |
646 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
646 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") | |
647 |
|
647 | |||
648 | class SpectraHeis(Spectra): |
|
648 | class SpectraHeis(Spectra): | |
649 |
|
649 | |||
650 | data_spc = None |
|
650 | data_spc = None | |
651 |
|
651 | |||
652 | data_cspc = None |
|
652 | data_cspc = None | |
653 |
|
653 | |||
654 | data_dc = None |
|
654 | data_dc = None | |
655 |
|
655 | |||
656 | nFFTPoints = None |
|
656 | nFFTPoints = None | |
657 |
|
657 | |||
658 | # nPairs = None |
|
658 | # nPairs = None | |
659 |
|
659 | |||
660 | pairsList = None |
|
660 | pairsList = None | |
661 |
|
661 | |||
|
662 | nCohInt = None | |||
|
663 | ||||
662 | nIncohInt = None |
|
664 | nIncohInt = None | |
663 |
|
665 | |||
664 | def __init__(self): |
|
666 | def __init__(self): | |
665 |
|
667 | |||
666 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
668 | self.radarControllerHeaderObj = RadarControllerHeader() | |
667 |
|
669 | |||
668 | self.systemHeaderObj = SystemHeader() |
|
670 | self.systemHeaderObj = SystemHeader() | |
669 |
|
671 | |||
670 | self.type = "SpectraHeis" |
|
672 | self.type = "SpectraHeis" | |
671 |
|
673 | |||
672 | # self.dtype = None |
|
674 | # self.dtype = None | |
673 |
|
675 | |||
674 | # self.nChannels = 0 |
|
676 | # self.nChannels = 0 | |
675 |
|
677 | |||
676 | # self.nHeights = 0 |
|
678 | # self.nHeights = 0 | |
677 |
|
679 | |||
678 | self.nProfiles = None |
|
680 | self.nProfiles = None | |
679 |
|
681 | |||
680 | self.heightList = None |
|
682 | self.heightList = None | |
681 |
|
683 | |||
682 | self.channelList = None |
|
684 | self.channelList = None | |
683 |
|
685 | |||
684 | # self.channelIndexList = None |
|
686 | # self.channelIndexList = None | |
685 |
|
687 | |||
686 | self.flagNoData = True |
|
688 | self.flagNoData = True | |
687 |
|
689 | |||
688 | self.flagDiscontinuousBlock = False |
|
690 | self.flagDiscontinuousBlock = False | |
689 |
|
691 | |||
690 | # self.nPairs = 0 |
|
692 | # self.nPairs = 0 | |
691 |
|
693 | |||
692 | self.utctime = None |
|
694 | self.utctime = None | |
693 |
|
695 | |||
694 | self.blocksize = None |
|
696 | self.blocksize = None | |
695 |
|
697 | |||
696 | self.profileIndex = 0 |
|
698 | self.profileIndex = 0 | |
|
699 | ||||
|
700 | self.nCohInt = 1 | |||
|
701 | ||||
|
702 | self.nIncohInt = 1 | |||
697 |
|
703 | |||
698 | def getNormFactor(self): |
|
704 | def getNormFactor(self): | |
699 | pwcode = 1 |
|
705 | pwcode = 1 | |
700 | if self.flagDecodeData: |
|
706 | if self.flagDecodeData: | |
701 | pwcode = numpy.sum(self.code[0]**2) |
|
707 | pwcode = numpy.sum(self.code[0]**2) | |
702 |
|
708 | |||
703 | normFactor = self.nIncohInt*self.nCohInt*pwcode |
|
709 | normFactor = self.nIncohInt*self.nCohInt*pwcode | |
704 |
|
710 | |||
705 | return normFactor |
|
711 | return normFactor | |
706 |
|
712 | |||
707 | def getTimeInterval(self): |
|
713 | def getTimeInterval(self): | |
708 |
|
714 | |||
709 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt |
|
715 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt | |
710 |
|
716 | |||
711 | return timeInterval |
|
717 | return timeInterval | |
712 |
|
718 | |||
713 | normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.") |
|
719 | normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.") | |
714 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
720 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") | |
715 |
|
721 | |||
716 | class Fits: |
|
722 | class Fits(JROData): | |
717 |
|
723 | |||
718 | heightList = None |
|
724 | heightList = None | |
719 |
|
725 | |||
720 | channelList = None |
|
726 | channelList = None | |
721 |
|
727 | |||
722 | flagNoData = True |
|
728 | flagNoData = True | |
723 |
|
729 | |||
724 | flagDiscontinuousBlock = False |
|
730 | flagDiscontinuousBlock = False | |
725 |
|
731 | |||
726 | useLocalTime = False |
|
732 | useLocalTime = False | |
727 |
|
733 | |||
728 | utctime = None |
|
734 | utctime = None | |
729 |
|
735 | |||
730 | timeZone = None |
|
736 | timeZone = None | |
731 |
|
737 | |||
732 | # ippSeconds = None |
|
738 | # ippSeconds = None | |
733 |
|
739 | |||
734 | # timeInterval = None |
|
740 | # timeInterval = None | |
735 |
|
741 | |||
736 | nCohInt = None |
|
742 | nCohInt = None | |
737 |
|
743 | |||
738 | nIncohInt = None |
|
744 | nIncohInt = None | |
739 |
|
745 | |||
740 | noise = None |
|
746 | noise = None | |
741 |
|
747 | |||
742 | windowOfFilter = 1 |
|
748 | windowOfFilter = 1 | |
743 |
|
749 | |||
744 | #Speed of ligth |
|
750 | #Speed of ligth | |
745 | C = 3e8 |
|
751 | C = 3e8 | |
746 |
|
752 | |||
747 | frequency = 49.92e6 |
|
753 | frequency = 49.92e6 | |
748 |
|
754 | |||
749 | realtime = False |
|
755 | realtime = False | |
750 |
|
756 | |||
751 |
|
757 | |||
752 | def __init__(self): |
|
758 | def __init__(self): | |
753 |
|
759 | |||
754 | self.type = "Fits" |
|
760 | self.type = "Fits" | |
755 |
|
761 | |||
756 | self.nProfiles = None |
|
762 | self.nProfiles = None | |
757 |
|
763 | |||
758 | self.heightList = None |
|
764 | self.heightList = None | |
759 |
|
765 | |||
760 | self.channelList = None |
|
766 | self.channelList = None | |
761 |
|
767 | |||
762 | # self.channelIndexList = None |
|
768 | # self.channelIndexList = None | |
763 |
|
769 | |||
764 | self.flagNoData = True |
|
770 | self.flagNoData = True | |
765 |
|
771 | |||
766 | self.utctime = None |
|
772 | self.utctime = None | |
767 |
|
773 | |||
768 |
self.nCohInt = |
|
774 | self.nCohInt = 1 | |
769 |
|
775 | |||
770 |
self.nIncohInt = |
|
776 | self.nIncohInt = 1 | |
771 |
|
777 | |||
772 | self.useLocalTime = True |
|
778 | self.useLocalTime = True | |
773 |
|
779 | |||
774 | self.profileIndex = 0 |
|
780 | self.profileIndex = 0 | |
775 |
|
781 | |||
776 | # self.utctime = None |
|
782 | # self.utctime = None | |
777 | # self.timeZone = None |
|
783 | # self.timeZone = None | |
778 | # self.ltctime = None |
|
784 | # self.ltctime = None | |
779 | # self.timeInterval = None |
|
785 | # self.timeInterval = None | |
780 | # self.header = None |
|
786 | # self.header = None | |
781 | # self.data_header = None |
|
787 | # self.data_header = None | |
782 | # self.data = None |
|
788 | # self.data = None | |
783 | # self.datatime = None |
|
789 | # self.datatime = None | |
784 | # self.flagNoData = False |
|
790 | # self.flagNoData = False | |
785 | # self.expName = '' |
|
791 | # self.expName = '' | |
786 | # self.nChannels = None |
|
792 | # self.nChannels = None | |
787 | # self.nSamples = None |
|
793 | # self.nSamples = None | |
788 | # self.dataBlocksPerFile = None |
|
794 | # self.dataBlocksPerFile = None | |
789 | # self.comments = '' |
|
795 | # self.comments = '' | |
790 | # |
|
796 | # | |
791 |
|
797 | |||
792 |
|
798 | |||
793 | def getltctime(self): |
|
799 | def getltctime(self): | |
794 |
|
800 | |||
795 | if self.useLocalTime: |
|
801 | if self.useLocalTime: | |
796 | return self.utctime - self.timeZone*60 |
|
802 | return self.utctime - self.timeZone*60 | |
797 |
|
803 | |||
798 | return self.utctime |
|
804 | return self.utctime | |
799 |
|
805 | |||
800 | def getDatatime(self): |
|
806 | def getDatatime(self): | |
801 |
|
807 | |||
802 | datatime = datetime.datetime.utcfromtimestamp(self.ltctime) |
|
808 | datatime = datetime.datetime.utcfromtimestamp(self.ltctime) | |
803 | return datatime |
|
809 | return datatime | |
804 |
|
810 | |||
805 | def getTimeRange(self): |
|
811 | def getTimeRange(self): | |
806 |
|
812 | |||
807 | datatime = [] |
|
813 | datatime = [] | |
808 |
|
814 | |||
809 | datatime.append(self.ltctime) |
|
815 | datatime.append(self.ltctime) | |
810 | datatime.append(self.ltctime + self.timeInterval) |
|
816 | datatime.append(self.ltctime + self.timeInterval) | |
811 |
|
817 | |||
812 | datatime = numpy.array(datatime) |
|
818 | datatime = numpy.array(datatime) | |
813 |
|
819 | |||
814 | return datatime |
|
820 | return datatime | |
815 |
|
821 | |||
816 | def getHeiRange(self): |
|
822 | def getHeiRange(self): | |
817 |
|
823 | |||
818 | heis = self.heightList |
|
824 | heis = self.heightList | |
819 |
|
825 | |||
820 | return heis |
|
826 | return heis | |
821 |
|
827 | |||
822 | def isEmpty(self): |
|
828 | def isEmpty(self): | |
823 |
|
829 | |||
824 | return self.flagNoData |
|
830 | return self.flagNoData | |
825 |
|
831 | |||
826 | def getNHeights(self): |
|
832 | def getNHeights(self): | |
827 |
|
833 | |||
828 | return len(self.heightList) |
|
834 | return len(self.heightList) | |
829 |
|
835 | |||
830 | def getNChannels(self): |
|
836 | def getNChannels(self): | |
831 |
|
837 | |||
832 | return len(self.channelList) |
|
838 | return len(self.channelList) | |
833 |
|
839 | |||
834 | def getChannelIndexList(self): |
|
840 | def getChannelIndexList(self): | |
835 |
|
841 | |||
836 | return range(self.nChannels) |
|
842 | return range(self.nChannels) | |
837 |
|
843 | |||
838 | def getNoise(self, type = 1): |
|
844 | def getNoise(self, type = 1): | |
839 |
|
845 | |||
840 | #noise = numpy.zeros(self.nChannels) |
|
846 | #noise = numpy.zeros(self.nChannels) | |
841 |
|
847 | |||
842 | if type == 1: |
|
848 | if type == 1: | |
843 | noise = self.getNoisebyHildebrand() |
|
849 | noise = self.getNoisebyHildebrand() | |
844 |
|
850 | |||
845 | if type == 2: |
|
851 | if type == 2: | |
846 | noise = self.getNoisebySort() |
|
852 | noise = self.getNoisebySort() | |
847 |
|
853 | |||
848 | if type == 3: |
|
854 | if type == 3: | |
849 | noise = self.getNoisebyWindow() |
|
855 | noise = self.getNoisebyWindow() | |
850 |
|
856 | |||
851 | return noise |
|
857 | return noise | |
852 |
|
858 | |||
853 | def getTimeInterval(self): |
|
859 | def getTimeInterval(self): | |
854 |
|
860 | |||
855 | raise ValueError, "This method is not implemented yet" |
|
861 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt | |
|
862 | ||||
|
863 | return timeInterval | |||
856 |
|
864 | |||
857 | datatime = property(getDatatime, "I'm the 'datatime' property") |
|
865 | datatime = property(getDatatime, "I'm the 'datatime' property") | |
858 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") |
|
866 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") | |
859 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") |
|
867 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") | |
860 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") |
|
868 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") | |
861 | noise = property(getNoise, "I'm the 'nHeights' property.") |
|
869 | noise = property(getNoise, "I'm the 'nHeights' property.") | |
862 | datatime = property(getDatatime, "I'm the 'datatime' property") |
|
870 | datatime = property(getDatatime, "I'm the 'datatime' property") | |
863 | ltctime = property(getltctime, "I'm the 'ltctime' property") |
|
871 | ltctime = property(getltctime, "I'm the 'ltctime' property") | |
864 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
872 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") | |
865 |
|
873 | |||
866 | class Correlation(JROData): |
|
874 | class Correlation(JROData): | |
867 |
|
875 | |||
868 | noise = None |
|
876 | noise = None | |
869 |
|
877 | |||
870 | SNR = None |
|
878 | SNR = None | |
871 |
|
879 | |||
872 | pairsAutoCorr = None #Pairs of Autocorrelation |
|
880 | pairsAutoCorr = None #Pairs of Autocorrelation | |
873 |
|
881 | |||
874 | #-------------------------------------------------- |
|
882 | #-------------------------------------------------- | |
875 |
|
883 | |||
876 | data_corr = None |
|
884 | data_corr = None | |
877 |
|
885 | |||
878 | data_volt = None |
|
886 | data_volt = None | |
879 |
|
887 | |||
880 | lagT = None # each element value is a profileIndex |
|
888 | lagT = None # each element value is a profileIndex | |
881 |
|
889 | |||
882 | lagR = None # each element value is in km |
|
890 | lagR = None # each element value is in km | |
883 |
|
891 | |||
884 | pairsList = None |
|
892 | pairsList = None | |
885 |
|
893 | |||
886 | calculateVelocity = None |
|
894 | calculateVelocity = None | |
887 |
|
895 | |||
888 | nPoints = None |
|
896 | nPoints = None | |
889 |
|
897 | |||
890 | nAvg = None |
|
898 | nAvg = None | |
891 |
|
899 | |||
892 | bufferSize = None |
|
900 | bufferSize = None | |
893 |
|
901 | |||
894 | def __init__(self): |
|
902 | def __init__(self): | |
895 | ''' |
|
903 | ''' | |
896 | Constructor |
|
904 | Constructor | |
897 | ''' |
|
905 | ''' | |
898 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
906 | self.radarControllerHeaderObj = RadarControllerHeader() | |
899 |
|
907 | |||
900 | self.systemHeaderObj = SystemHeader() |
|
908 | self.systemHeaderObj = SystemHeader() | |
901 |
|
909 | |||
902 | self.type = "Correlation" |
|
910 | self.type = "Correlation" | |
903 |
|
911 | |||
904 | self.data = None |
|
912 | self.data = None | |
905 |
|
913 | |||
906 | self.dtype = None |
|
914 | self.dtype = None | |
907 |
|
915 | |||
908 | self.nProfiles = None |
|
916 | self.nProfiles = None | |
909 |
|
917 | |||
910 | self.heightList = None |
|
918 | self.heightList = None | |
911 |
|
919 | |||
912 | self.channelList = None |
|
920 | self.channelList = None | |
913 |
|
921 | |||
914 | self.flagNoData = True |
|
922 | self.flagNoData = True | |
915 |
|
923 | |||
916 | self.flagDiscontinuousBlock = False |
|
924 | self.flagDiscontinuousBlock = False | |
917 |
|
925 | |||
918 | self.utctime = None |
|
926 | self.utctime = None | |
919 |
|
927 | |||
920 | self.timeZone = None |
|
928 | self.timeZone = None | |
921 |
|
929 | |||
922 | self.dstFlag = None |
|
930 | self.dstFlag = None | |
923 |
|
931 | |||
924 | self.errorCount = None |
|
932 | self.errorCount = None | |
925 |
|
933 | |||
926 | self.blocksize = None |
|
934 | self.blocksize = None | |
927 |
|
935 | |||
928 | self.flagDecodeData = False #asumo q la data no esta decodificada |
|
936 | self.flagDecodeData = False #asumo q la data no esta decodificada | |
929 |
|
937 | |||
930 | self.flagDeflipData = False #asumo q la data no esta sin flip |
|
938 | self.flagDeflipData = False #asumo q la data no esta sin flip | |
931 |
|
939 | |||
932 | self.pairsList = None |
|
940 | self.pairsList = None | |
933 |
|
941 | |||
934 | self.nPoints = None |
|
942 | self.nPoints = None | |
935 |
|
943 | |||
936 | def getLagTRange(self, extrapoints=0): |
|
944 | def getLagTRange(self, extrapoints=0): | |
937 |
|
945 | |||
938 | lagTRange = self.lagT |
|
946 | lagTRange = self.lagT | |
939 | diff = lagTRange[1] - lagTRange[0] |
|
947 | diff = lagTRange[1] - lagTRange[0] | |
940 | extra = numpy.arange(1,extrapoints + 1)*diff + lagTRange[-1] |
|
948 | extra = numpy.arange(1,extrapoints + 1)*diff + lagTRange[-1] | |
941 | lagTRange = numpy.hstack((lagTRange, extra)) |
|
949 | lagTRange = numpy.hstack((lagTRange, extra)) | |
942 |
|
950 | |||
943 | return lagTRange |
|
951 | return lagTRange | |
944 |
|
952 | |||
945 | def getLagRRange(self, extrapoints=0): |
|
953 | def getLagRRange(self, extrapoints=0): | |
946 |
|
954 | |||
947 | return self.lagR |
|
955 | return self.lagR | |
948 |
|
956 | |||
949 | def getPairsList(self): |
|
957 | def getPairsList(self): | |
950 |
|
958 | |||
951 | return self.pairsList |
|
959 | return self.pairsList | |
952 |
|
960 | |||
953 | def getCalculateVelocity(self): |
|
961 | def getCalculateVelocity(self): | |
954 |
|
962 | |||
955 | return self.calculateVelocity |
|
963 | return self.calculateVelocity | |
956 |
|
964 | |||
957 | def getNPoints(self): |
|
965 | def getNPoints(self): | |
958 |
|
966 | |||
959 | return self.nPoints |
|
967 | return self.nPoints | |
960 |
|
968 | |||
961 | def getNAvg(self): |
|
969 | def getNAvg(self): | |
962 |
|
970 | |||
963 | return self.nAvg |
|
971 | return self.nAvg | |
964 |
|
972 | |||
965 | def getBufferSize(self): |
|
973 | def getBufferSize(self): | |
966 |
|
974 | |||
967 | return self.bufferSize |
|
975 | return self.bufferSize | |
968 |
|
976 | |||
969 | def getPairsAutoCorr(self): |
|
977 | def getPairsAutoCorr(self): | |
970 | pairsList = self.pairsList |
|
978 | pairsList = self.pairsList | |
971 | pairsAutoCorr = numpy.zeros(self.nChannels, dtype = 'int')*numpy.nan |
|
979 | pairsAutoCorr = numpy.zeros(self.nChannels, dtype = 'int')*numpy.nan | |
972 |
|
980 | |||
973 | for l in range(len(pairsList)): |
|
981 | for l in range(len(pairsList)): | |
974 | firstChannel = pairsList[l][0] |
|
982 | firstChannel = pairsList[l][0] | |
975 | secondChannel = pairsList[l][1] |
|
983 | secondChannel = pairsList[l][1] | |
976 |
|
984 | |||
977 | #Obteniendo pares de Autocorrelacion |
|
985 | #Obteniendo pares de Autocorrelacion | |
978 | if firstChannel == secondChannel: |
|
986 | if firstChannel == secondChannel: | |
979 | pairsAutoCorr[firstChannel] = int(l) |
|
987 | pairsAutoCorr[firstChannel] = int(l) | |
980 |
|
988 | |||
981 | pairsAutoCorr = pairsAutoCorr.astype(int) |
|
989 | pairsAutoCorr = pairsAutoCorr.astype(int) | |
982 |
|
990 | |||
983 | return pairsAutoCorr |
|
991 | return pairsAutoCorr | |
984 |
|
992 | |||
985 | def getNoise(self, mode = 2): |
|
993 | def getNoise(self, mode = 2): | |
986 |
|
994 | |||
987 | indR = numpy.where(self.lagR == 0)[0][0] |
|
995 | indR = numpy.where(self.lagR == 0)[0][0] | |
988 | indT = numpy.where(self.lagT == 0)[0][0] |
|
996 | indT = numpy.where(self.lagT == 0)[0][0] | |
989 |
|
997 | |||
990 | jspectra0 = self.data_corr[:,:,indR,:] |
|
998 | jspectra0 = self.data_corr[:,:,indR,:] | |
991 | jspectra = copy.copy(jspectra0) |
|
999 | jspectra = copy.copy(jspectra0) | |
992 |
|
1000 | |||
993 | num_chan = jspectra.shape[0] |
|
1001 | num_chan = jspectra.shape[0] | |
994 | num_hei = jspectra.shape[2] |
|
1002 | num_hei = jspectra.shape[2] | |
995 |
|
1003 | |||
996 | freq_dc = jspectra.shape[1]/2 |
|
1004 | freq_dc = jspectra.shape[1]/2 | |
997 | ind_vel = numpy.array([-2,-1,1,2]) + freq_dc |
|
1005 | ind_vel = numpy.array([-2,-1,1,2]) + freq_dc | |
998 |
|
1006 | |||
999 | if ind_vel[0]<0: |
|
1007 | if ind_vel[0]<0: | |
1000 | ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof |
|
1008 | ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof | |
1001 |
|
1009 | |||
1002 | if mode == 1: |
|
1010 | if mode == 1: | |
1003 | jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION |
|
1011 | jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION | |
1004 |
|
1012 | |||
1005 | if mode == 2: |
|
1013 | if mode == 2: | |
1006 |
|
1014 | |||
1007 | vel = numpy.array([-2,-1,1,2]) |
|
1015 | vel = numpy.array([-2,-1,1,2]) | |
1008 | xx = numpy.zeros([4,4]) |
|
1016 | xx = numpy.zeros([4,4]) | |
1009 |
|
1017 | |||
1010 | for fil in range(4): |
|
1018 | for fil in range(4): | |
1011 | xx[fil,:] = vel[fil]**numpy.asarray(range(4)) |
|
1019 | xx[fil,:] = vel[fil]**numpy.asarray(range(4)) | |
1012 |
|
1020 | |||
1013 | xx_inv = numpy.linalg.inv(xx) |
|
1021 | xx_inv = numpy.linalg.inv(xx) | |
1014 | xx_aux = xx_inv[0,:] |
|
1022 | xx_aux = xx_inv[0,:] | |
1015 |
|
1023 | |||
1016 | for ich in range(num_chan): |
|
1024 | for ich in range(num_chan): | |
1017 | yy = jspectra[ich,ind_vel,:] |
|
1025 | yy = jspectra[ich,ind_vel,:] | |
1018 | jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy) |
|
1026 | jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy) | |
1019 |
|
1027 | |||
1020 | junkid = jspectra[ich,freq_dc,:]<=0 |
|
1028 | junkid = jspectra[ich,freq_dc,:]<=0 | |
1021 | cjunkid = sum(junkid) |
|
1029 | cjunkid = sum(junkid) | |
1022 |
|
1030 | |||
1023 | if cjunkid.any(): |
|
1031 | if cjunkid.any(): | |
1024 | jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2 |
|
1032 | jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2 | |
1025 |
|
1033 | |||
1026 | noise = jspectra0[:,freq_dc,:] - jspectra[:,freq_dc,:] |
|
1034 | noise = jspectra0[:,freq_dc,:] - jspectra[:,freq_dc,:] | |
1027 |
|
1035 | |||
1028 | return noise |
|
1036 | return noise | |
|
1037 | ||||
|
1038 | def getTimeInterval(self): | |||
|
1039 | ||||
|
1040 | timeInterval = self.ippSeconds * self.nCohInt * self.nPoints | |||
|
1041 | ||||
|
1042 | return timeInterval | |||
1029 |
|
1043 | |||
|
1044 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") | |||
1030 | # pairsList = property(getPairsList, "I'm the 'pairsList' property.") |
|
1045 | # pairsList = property(getPairsList, "I'm the 'pairsList' property.") | |
1031 | # nPoints = property(getNPoints, "I'm the 'nPoints' property.") |
|
1046 | # nPoints = property(getNPoints, "I'm the 'nPoints' property.") | |
1032 | calculateVelocity = property(getCalculateVelocity, "I'm the 'calculateVelocity' property.") |
|
1047 | calculateVelocity = property(getCalculateVelocity, "I'm the 'calculateVelocity' property.") | |
1033 | nAvg = property(getNAvg, "I'm the 'nAvg' property.") |
|
1048 | nAvg = property(getNAvg, "I'm the 'nAvg' property.") | |
1034 | bufferSize = property(getBufferSize, "I'm the 'bufferSize' property.") |
|
1049 | bufferSize = property(getBufferSize, "I'm the 'bufferSize' property.") | |
1035 |
|
1050 | |||
1036 |
|
1051 | |||
1037 | class Parameters(JROData): |
|
1052 | class Parameters(JROData): | |
1038 |
|
1053 | |||
1039 | #Information from previous data |
|
1054 | #Information from previous data | |
1040 |
|
1055 | |||
1041 | inputUnit = None #Type of data to be processed |
|
1056 | inputUnit = None #Type of data to be processed | |
1042 |
|
1057 | |||
1043 | operation = None #Type of operation to parametrize |
|
1058 | operation = None #Type of operation to parametrize | |
1044 |
|
1059 | |||
1045 | normFactor = None #Normalization Factor |
|
1060 | normFactor = None #Normalization Factor | |
1046 |
|
1061 | |||
1047 | groupList = None #List of Pairs, Groups, etc |
|
1062 | groupList = None #List of Pairs, Groups, etc | |
1048 |
|
1063 | |||
1049 | #Parameters |
|
1064 | #Parameters | |
1050 |
|
1065 | |||
1051 | data_param = None #Parameters obtained |
|
1066 | data_param = None #Parameters obtained | |
1052 |
|
1067 | |||
1053 | data_pre = None #Data Pre Parametrization |
|
1068 | data_pre = None #Data Pre Parametrization | |
1054 |
|
1069 | |||
1055 | data_SNR = None #Signal to Noise Ratio |
|
1070 | data_SNR = None #Signal to Noise Ratio | |
1056 |
|
1071 | |||
1057 | heightRange = None #Heights |
|
1072 | heightRange = None #Heights | |
1058 |
|
1073 | |||
1059 | abscissaRange = None #Abscissa, can be velocities, lags or time |
|
1074 | abscissaRange = None #Abscissa, can be velocities, lags or time | |
1060 |
|
1075 | |||
1061 | noise = None #Noise Potency |
|
1076 | noise = None #Noise Potency | |
1062 |
|
1077 | |||
1063 | initUtcTime = None #Initial UTC time |
|
1078 | # initUtcTime = None #Initial UTC time | |
1064 |
|
1079 | |||
1065 | paramInterval = None #Time interval to calculate Parameters in seconds |
|
1080 | paramInterval = None #Time interval to calculate Parameters in seconds | |
1066 |
|
1081 | |||
1067 | #Fitting |
|
1082 | #Fitting | |
1068 |
|
1083 | |||
1069 | data_error = None #Error of the estimation |
|
1084 | data_error = None #Error of the estimation | |
1070 |
|
1085 | |||
1071 | constants = None |
|
1086 | constants = None | |
1072 |
|
1087 | |||
1073 | library = None |
|
1088 | library = None | |
1074 |
|
1089 | |||
1075 | #Output signal |
|
1090 | #Output signal | |
1076 |
|
1091 | |||
1077 | outputInterval = None #Time interval to calculate output signal in seconds |
|
1092 | outputInterval = None #Time interval to calculate output signal in seconds | |
1078 |
|
1093 | |||
1079 | data_output = None #Out signal |
|
1094 | data_output = None #Out signal | |
1080 |
|
1095 | |||
1081 |
|
||||
1082 |
|
||||
1083 | def __init__(self): |
|
1096 | def __init__(self): | |
1084 | ''' |
|
1097 | ''' | |
1085 | Constructor |
|
1098 | Constructor | |
1086 | ''' |
|
1099 | ''' | |
1087 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
1100 | self.radarControllerHeaderObj = RadarControllerHeader() | |
1088 |
|
1101 | |||
1089 | self.systemHeaderObj = SystemHeader() |
|
1102 | self.systemHeaderObj = SystemHeader() | |
1090 |
|
1103 | |||
1091 | self.type = "Parameters" |
|
1104 | self.type = "Parameters" | |
1092 |
|
|
1105 | ||
1093 | def getTimeRange1(self): |
|
1106 | def getTimeRange1(self): | |
1094 |
|
1107 | |||
1095 | datatime = [] |
|
1108 | datatime = [] | |
1096 |
|
1109 | |||
1097 |
datatime.append(self. |
|
1110 | datatime.append(self.ltctime) | |
1098 |
datatime.append(self. |
|
1111 | datatime.append(self.ltctime + self.outputInterval - 1) | |
1099 |
|
1112 | |||
1100 | datatime = numpy.array(datatime) |
|
1113 | datatime = numpy.array(datatime) | |
1101 |
|
1114 | |||
1102 | return datatime |
|
1115 | return datatime |
@@ -1,646 +1,610 | |||||
1 | import os |
|
1 | import os | |
2 | import numpy |
|
2 | import numpy | |
3 | import time, datetime |
|
3 | import time, datetime | |
4 | import mpldriver |
|
4 | import mpldriver | |
5 |
|
5 | |||
6 | from schainpy.model.proc.jroproc_base import Operation |
|
6 | from schainpy.model.proc.jroproc_base import Operation | |
7 |
|
7 | |||
8 | def isRealtime(utcdatatime): |
|
8 | def isRealtime(utcdatatime): | |
9 | utcnow = time.mktime(time.localtime()) |
|
9 | utcnow = time.mktime(time.localtime()) | |
10 | delta = abs(utcnow - utcdatatime) # abs |
|
10 | delta = abs(utcnow - utcdatatime) # abs | |
11 | if delta >= 30.: |
|
11 | if delta >= 30.: | |
12 | return False |
|
12 | return False | |
13 | return True |
|
13 | return True | |
14 |
|
14 | |||
15 | class Figure(Operation): |
|
15 | class Figure(Operation): | |
16 |
|
16 | |||
17 | __driver = mpldriver |
|
17 | __driver = mpldriver | |
18 | __isConfigThread = False |
|
18 | __isConfigThread = False | |
19 | fig = None |
|
19 | fig = None | |
20 |
|
20 | |||
21 | id = None |
|
21 | id = None | |
22 | wintitle = None |
|
22 | wintitle = None | |
23 | width = None |
|
23 | width = None | |
24 | height = None |
|
24 | height = None | |
25 | nplots = None |
|
25 | nplots = None | |
26 | timerange = None |
|
26 | timerange = None | |
27 |
|
27 | |||
28 | axesObjList = [] |
|
28 | axesObjList = [] | |
29 |
|
29 | |||
30 | WIDTH = None |
|
30 | WIDTH = None | |
31 | HEIGHT = None |
|
31 | HEIGHT = None | |
32 | PREFIX = 'fig' |
|
32 | PREFIX = 'fig' | |
33 |
|
33 | |||
34 | xmin = None |
|
34 | xmin = None | |
35 | xmax = None |
|
35 | xmax = None | |
36 |
|
36 | |||
37 | counter_imagwr = 0 |
|
37 | counter_imagwr = 0 | |
38 |
|
38 | |||
39 | figfile = None |
|
39 | figfile = None | |
40 |
|
40 | |||
41 | def __init__(self): |
|
41 | def __init__(self): | |
42 |
|
42 | |||
43 | raise ValueError, "This method is not implemented" |
|
43 | raise ValueError, "This method is not implemented" | |
44 |
|
44 | |||
45 | def __del__(self): |
|
45 | def __del__(self): | |
46 |
|
46 | |||
47 | self.__driver.closeFigure() |
|
47 | self.__driver.closeFigure() | |
48 |
|
48 | |||
49 | def getFilename(self, name, ext='.png'): |
|
49 | def getFilename(self, name, ext='.png'): | |
50 |
|
50 | |||
51 | path = '%s%03d' %(self.PREFIX, self.id) |
|
51 | path = '%s%03d' %(self.PREFIX, self.id) | |
52 | filename = '%s_%s%s' %(self.PREFIX, name, ext) |
|
52 | filename = '%s_%s%s' %(self.PREFIX, name, ext) | |
53 | return os.path.join(path, filename) |
|
53 | return os.path.join(path, filename) | |
54 |
|
54 | |||
55 | def getAxesObjList(self): |
|
55 | def getAxesObjList(self): | |
56 |
|
56 | |||
57 | return self.axesObjList |
|
57 | return self.axesObjList | |
58 |
|
58 | |||
59 | def getSubplots(self): |
|
59 | def getSubplots(self): | |
60 |
|
60 | |||
61 | raise ValueError, "Abstract method: This method should be defined" |
|
61 | raise ValueError, "Abstract method: This method should be defined" | |
62 |
|
62 | |||
63 | def getScreenDim(self, widthplot, heightplot): |
|
63 | def getScreenDim(self, widthplot, heightplot): | |
64 |
|
64 | |||
65 | nrow, ncol = self.getSubplots() |
|
65 | nrow, ncol = self.getSubplots() | |
66 |
|
66 | |||
67 | widthscreen = widthplot*ncol |
|
67 | widthscreen = widthplot*ncol | |
68 | heightscreen = heightplot*nrow |
|
68 | heightscreen = heightplot*nrow | |
69 |
|
69 | |||
70 | return widthscreen, heightscreen |
|
70 | return widthscreen, heightscreen | |
71 |
|
71 | |||
72 | def getTimeLim(self, x, xmin=None, xmax=None, timerange=None): |
|
72 | def getTimeLim(self, x, xmin=None, xmax=None, timerange=None): | |
73 |
|
73 | |||
74 | if self.xmin != None and self.xmax != None: |
|
74 | if self.xmin != None and self.xmax != None: | |
75 | if timerange == None: |
|
75 | if timerange == None: | |
76 | timerange = self.xmax - self.xmin |
|
76 | timerange = self.xmax - self.xmin | |
77 | xmin = self.xmin + timerange |
|
77 | xmin = self.xmin + timerange | |
78 | xmax = self.xmax + timerange |
|
78 | xmax = self.xmax + timerange | |
79 |
|
79 | |||
80 | return xmin, xmax |
|
80 | return xmin, xmax | |
81 |
|
81 | |||
82 | if timerange == None and (xmin==None or xmax==None): |
|
82 | if timerange == None and (xmin==None or xmax==None): | |
83 | timerange = 14400 #seconds |
|
83 | timerange = 14400 #seconds | |
84 | #raise ValueError, "(timerange) or (xmin & xmax) should be defined" |
|
84 | #raise ValueError, "(timerange) or (xmin & xmax) should be defined" | |
85 |
|
85 | |||
86 | if timerange != None: |
|
86 | if timerange != None: | |
87 | txmin = x[0] - x[0] % min(timerange/10, 10*60) |
|
87 | txmin = x[0] - x[0] % min(timerange/10, 10*60) | |
88 | else: |
|
88 | else: | |
89 | txmin = x[0] - x[0] % 10*60 |
|
89 | txmin = x[0] - x[0] % 10*60 | |
90 |
|
90 | |||
91 | thisdatetime = datetime.datetime.utcfromtimestamp(txmin) |
|
91 | thisdatetime = datetime.datetime.utcfromtimestamp(txmin) | |
92 | thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0)) |
|
92 | thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0)) | |
93 |
|
93 | |||
94 | if timerange != None: |
|
94 | if timerange != None: | |
95 | xmin = (thisdatetime - thisdate).seconds/(60*60.) |
|
95 | xmin = (thisdatetime - thisdate).seconds/(60*60.) | |
96 | xmax = xmin + timerange/(60*60.) |
|
96 | xmax = xmin + timerange/(60*60.) | |
97 |
|
97 | |||
98 | mindt = thisdate + datetime.timedelta(hours=xmin) - datetime.timedelta(seconds=time.timezone) |
|
98 | mindt = thisdate + datetime.timedelta(hours=xmin) - datetime.timedelta(seconds=time.timezone) | |
99 | xmin_sec = time.mktime(mindt.timetuple()) |
|
99 | xmin_sec = time.mktime(mindt.timetuple()) | |
100 |
|
100 | |||
101 | maxdt = thisdate + datetime.timedelta(hours=xmax) - datetime.timedelta(seconds=time.timezone) |
|
101 | maxdt = thisdate + datetime.timedelta(hours=xmax) - datetime.timedelta(seconds=time.timezone) | |
102 | xmax_sec = time.mktime(maxdt.timetuple()) |
|
102 | xmax_sec = time.mktime(maxdt.timetuple()) | |
103 |
|
103 | |||
104 | return xmin_sec, xmax_sec |
|
104 | return xmin_sec, xmax_sec | |
105 |
|
||||
106 |
|
||||
107 |
|
||||
108 |
|
||||
109 |
|
||||
110 | # if timerange != None: |
|
|||
111 | # txmin = x[0] - x[0]%timerange |
|
|||
112 | # else: |
|
|||
113 | # txmin = numpy.min(x) |
|
|||
114 | # |
|
|||
115 | # thisdatetime = datetime.datetime.utcfromtimestamp(txmin) |
|
|||
116 | # thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0)) |
|
|||
117 | # |
|
|||
118 | # #################################################### |
|
|||
119 | # #If the x is out of xrange |
|
|||
120 | # if xmax != None: |
|
|||
121 | # if xmax < (thisdatetime - thisdate).seconds/(60*60.): |
|
|||
122 | # xmin = None |
|
|||
123 | # xmax = None |
|
|||
124 | # |
|
|||
125 | # if xmin == None: |
|
|||
126 | # td = thisdatetime - thisdate |
|
|||
127 | # xmin = td.seconds/(60*60.) |
|
|||
128 | # |
|
|||
129 | # if xmax == None: |
|
|||
130 | # xmax = xmin + self.timerange/(60*60.) |
|
|||
131 | # |
|
|||
132 | # mindt = thisdate + datetime.timedelta(hours=xmin) - datetime.timedelta(seconds=time.timezone) |
|
|||
133 | # tmin = time.mktime(mindt.timetuple()) |
|
|||
134 | # |
|
|||
135 | # maxdt = thisdate + datetime.timedelta(hours=xmax) - datetime.timedelta(seconds=time.timezone) |
|
|||
136 | # tmax = time.mktime(maxdt.timetuple()) |
|
|||
137 | # |
|
|||
138 | # #self.timerange = tmax - tmin |
|
|||
139 | # |
|
|||
140 | # return tmin, tmax |
|
|||
141 |
|
105 | |||
142 | def init(self, id, nplots, wintitle): |
|
106 | def init(self, id, nplots, wintitle): | |
143 |
|
107 | |||
144 | raise ValueError, "This method has been replaced with createFigure" |
|
108 | raise ValueError, "This method has been replaced with createFigure" | |
145 |
|
109 | |||
146 | def createFigure(self, id, wintitle, widthplot=None, heightplot=None, show=True): |
|
110 | def createFigure(self, id, wintitle, widthplot=None, heightplot=None, show=True): | |
147 |
|
111 | |||
148 | """ |
|
112 | """ | |
149 | Crea la figura de acuerdo al driver y parametros seleccionados seleccionados. |
|
113 | Crea la figura de acuerdo al driver y parametros seleccionados seleccionados. | |
150 | Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH |
|
114 | Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH | |
151 | y self.HEIGHT y el numero de subplots (nrow, ncol) |
|
115 | y self.HEIGHT y el numero de subplots (nrow, ncol) | |
152 |
|
116 | |||
153 | Input: |
|
117 | Input: | |
154 | id : Los parametros necesarios son |
|
118 | id : Los parametros necesarios son | |
155 | wintitle : |
|
119 | wintitle : | |
156 |
|
120 | |||
157 | """ |
|
121 | """ | |
158 |
|
122 | |||
159 | if widthplot == None: |
|
123 | if widthplot == None: | |
160 | widthplot = self.WIDTH |
|
124 | widthplot = self.WIDTH | |
161 |
|
125 | |||
162 | if heightplot == None: |
|
126 | if heightplot == None: | |
163 | heightplot = self.HEIGHT |
|
127 | heightplot = self.HEIGHT | |
164 |
|
128 | |||
165 | self.id = id |
|
129 | self.id = id | |
166 |
|
130 | |||
167 | self.wintitle = wintitle |
|
131 | self.wintitle = wintitle | |
168 |
|
132 | |||
169 | self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot) |
|
133 | self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot) | |
170 |
|
134 | |||
171 | self.fig = self.__driver.createFigure(id=self.id, |
|
135 | self.fig = self.__driver.createFigure(id=self.id, | |
172 | wintitle=self.wintitle, |
|
136 | wintitle=self.wintitle, | |
173 | width=self.widthscreen, |
|
137 | width=self.widthscreen, | |
174 | height=self.heightscreen, |
|
138 | height=self.heightscreen, | |
175 | show=show) |
|
139 | show=show) | |
176 |
|
140 | |||
177 | self.axesObjList = [] |
|
141 | self.axesObjList = [] | |
178 | self.counter_imagwr = 0 |
|
142 | self.counter_imagwr = 0 | |
179 |
|
143 | |||
180 |
|
144 | |||
181 | def setDriver(self, driver=mpldriver): |
|
145 | def setDriver(self, driver=mpldriver): | |
182 |
|
146 | |||
183 | self.__driver = driver |
|
147 | self.__driver = driver | |
184 |
|
148 | |||
185 | def setTitle(self, title): |
|
149 | def setTitle(self, title): | |
186 |
|
150 | |||
187 | self.__driver.setTitle(self.fig, title) |
|
151 | self.__driver.setTitle(self.fig, title) | |
188 |
|
152 | |||
189 | def setWinTitle(self, title): |
|
153 | def setWinTitle(self, title): | |
190 |
|
154 | |||
191 | self.__driver.setWinTitle(self.fig, title=title) |
|
155 | self.__driver.setWinTitle(self.fig, title=title) | |
192 |
|
156 | |||
193 | def setTextFromAxes(self, text): |
|
157 | def setTextFromAxes(self, text): | |
194 |
|
158 | |||
195 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes" |
|
159 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes" | |
196 |
|
160 | |||
197 | def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan): |
|
161 | def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan): | |
198 |
|
162 | |||
199 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes" |
|
163 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes" | |
200 |
|
164 | |||
201 | def addAxes(self, *args): |
|
165 | def addAxes(self, *args): | |
202 | """ |
|
166 | """ | |
203 |
|
167 | |||
204 | Input: |
|
168 | Input: | |
205 | *args : Los parametros necesarios son |
|
169 | *args : Los parametros necesarios son | |
206 | nrow, ncol, xpos, ypos, colspan, rowspan |
|
170 | nrow, ncol, xpos, ypos, colspan, rowspan | |
207 | """ |
|
171 | """ | |
208 |
|
172 | |||
209 | axesObj = Axes(self.fig, *args) |
|
173 | axesObj = Axes(self.fig, *args) | |
210 | self.axesObjList.append(axesObj) |
|
174 | self.axesObjList.append(axesObj) | |
211 |
|
175 | |||
212 | def saveFigure(self, figpath, figfile, *args): |
|
176 | def saveFigure(self, figpath, figfile, *args): | |
213 |
|
177 | |||
214 | filename = os.path.join(figpath, figfile) |
|
178 | filename = os.path.join(figpath, figfile) | |
215 |
|
179 | |||
216 | fullpath = os.path.split(filename)[0] |
|
180 | fullpath = os.path.split(filename)[0] | |
217 |
|
181 | |||
218 | if not os.path.exists(fullpath): |
|
182 | if not os.path.exists(fullpath): | |
219 | subpath = os.path.split(fullpath)[0] |
|
183 | subpath = os.path.split(fullpath)[0] | |
220 |
|
184 | |||
221 | if not os.path.exists(subpath): |
|
185 | if not os.path.exists(subpath): | |
222 | os.mkdir(subpath) |
|
186 | os.mkdir(subpath) | |
223 |
|
187 | |||
224 | os.mkdir(fullpath) |
|
188 | os.mkdir(fullpath) | |
225 |
|
189 | |||
226 | self.__driver.saveFigure(self.fig, filename, *args) |
|
190 | self.__driver.saveFigure(self.fig, filename, *args) | |
227 |
|
191 | |||
228 | def save(self, figpath, figfile=None, save=True, ftp=False, wr_period=1, thisDatetime=None, update_figfile=True): |
|
192 | def save(self, figpath, figfile=None, save=True, ftp=False, wr_period=1, thisDatetime=None, update_figfile=True): | |
229 |
|
193 | |||
230 | self.counter_imagwr += 1 |
|
194 | self.counter_imagwr += 1 | |
231 | if self.counter_imagwr < wr_period: |
|
195 | if self.counter_imagwr < wr_period: | |
232 | return |
|
196 | return | |
233 |
|
197 | |||
234 | self.counter_imagwr = 0 |
|
198 | self.counter_imagwr = 0 | |
235 |
|
199 | |||
236 | if save: |
|
200 | if save: | |
237 |
|
201 | |||
238 | if figfile == None: |
|
202 | if figfile == None: | |
239 |
|
203 | |||
240 | if not thisDatetime: |
|
204 | if not thisDatetime: | |
241 | raise ValueError, "Saving figure: figfile or thisDatetime should be defined" |
|
205 | raise ValueError, "Saving figure: figfile or thisDatetime should be defined" | |
242 | return |
|
206 | return | |
243 |
|
207 | |||
244 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
208 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
245 | figfile = self.getFilename(name = str_datetime) |
|
209 | figfile = self.getFilename(name = str_datetime) | |
246 |
|
210 | |||
247 | if self.figfile == None: |
|
211 | if self.figfile == None: | |
248 | self.figfile = figfile |
|
212 | self.figfile = figfile | |
249 |
|
213 | |||
250 | if update_figfile: |
|
214 | if update_figfile: | |
251 | self.figfile = figfile |
|
215 | self.figfile = figfile | |
252 |
|
216 | |||
253 | # store png plot to local folder |
|
217 | # store png plot to local folder | |
254 | self.saveFigure(figpath, self.figfile) |
|
218 | self.saveFigure(figpath, self.figfile) | |
255 |
|
219 | |||
256 |
|
220 | |||
257 | if not ftp: |
|
221 | if not ftp: | |
258 | return |
|
222 | return | |
259 |
|
223 | |||
260 | if not thisDatetime: |
|
224 | if not thisDatetime: | |
261 | return |
|
225 | return | |
262 |
|
226 | |||
263 | # store png plot to FTP server according to RT-Web format |
|
227 | # store png plot to FTP server according to RT-Web format | |
264 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
228 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
265 | ftp_filename = os.path.join(figpath, name) |
|
229 | ftp_filename = os.path.join(figpath, name) | |
266 | self.saveFigure(figpath, ftp_filename) |
|
230 | self.saveFigure(figpath, ftp_filename) | |
267 |
|
231 | |||
268 | def getNameToFtp(self, thisDatetime, FTP_WEI, EXP_CODE, SUB_EXP_CODE, PLOT_CODE, PLOT_POS): |
|
232 | def getNameToFtp(self, thisDatetime, FTP_WEI, EXP_CODE, SUB_EXP_CODE, PLOT_CODE, PLOT_POS): | |
269 | YEAR_STR = '%4.4d'%thisDatetime.timetuple().tm_year |
|
233 | YEAR_STR = '%4.4d'%thisDatetime.timetuple().tm_year | |
270 | DOY_STR = '%3.3d'%thisDatetime.timetuple().tm_yday |
|
234 | DOY_STR = '%3.3d'%thisDatetime.timetuple().tm_yday | |
271 | FTP_WEI = '%2.2d'%FTP_WEI |
|
235 | FTP_WEI = '%2.2d'%FTP_WEI | |
272 | EXP_CODE = '%3.3d'%EXP_CODE |
|
236 | EXP_CODE = '%3.3d'%EXP_CODE | |
273 | SUB_EXP_CODE = '%2.2d'%SUB_EXP_CODE |
|
237 | SUB_EXP_CODE = '%2.2d'%SUB_EXP_CODE | |
274 | PLOT_CODE = '%2.2d'%PLOT_CODE |
|
238 | PLOT_CODE = '%2.2d'%PLOT_CODE | |
275 | PLOT_POS = '%2.2d'%PLOT_POS |
|
239 | PLOT_POS = '%2.2d'%PLOT_POS | |
276 | name = YEAR_STR + DOY_STR + FTP_WEI + EXP_CODE + SUB_EXP_CODE + PLOT_CODE + PLOT_POS |
|
240 | name = YEAR_STR + DOY_STR + FTP_WEI + EXP_CODE + SUB_EXP_CODE + PLOT_CODE + PLOT_POS | |
277 | return name |
|
241 | return name | |
278 |
|
242 | |||
279 | def draw(self): |
|
243 | def draw(self): | |
280 |
|
244 | |||
281 | self.__driver.draw(self.fig) |
|
245 | self.__driver.draw(self.fig) | |
282 |
|
246 | |||
283 | def run(self): |
|
247 | def run(self): | |
284 |
|
248 | |||
285 | raise ValueError, "This method is not implemented" |
|
249 | raise ValueError, "This method is not implemented" | |
286 |
|
250 | |||
287 | def close(self): |
|
251 | def close(self, show=False): | |
288 |
|
252 | |||
289 | self.__driver.closeFigure() |
|
253 | self.__driver.closeFigure(show=show, fig=self.fig) | |
290 |
|
254 | |||
291 | axesList = property(getAxesObjList) |
|
255 | axesList = property(getAxesObjList) | |
292 |
|
256 | |||
293 |
|
257 | |||
294 | class Axes: |
|
258 | class Axes: | |
295 |
|
259 | |||
296 | __driver = mpldriver |
|
260 | __driver = mpldriver | |
297 | fig = None |
|
261 | fig = None | |
298 | ax = None |
|
262 | ax = None | |
299 | plot = None |
|
263 | plot = None | |
300 | __missing = 1E30 |
|
264 | __missing = 1E30 | |
301 | __firsttime = None |
|
265 | __firsttime = None | |
302 |
|
266 | |||
303 | __showprofile = False |
|
267 | __showprofile = False | |
304 |
|
268 | |||
305 | xmin = None |
|
269 | xmin = None | |
306 | xmax = None |
|
270 | xmax = None | |
307 | ymin = None |
|
271 | ymin = None | |
308 | ymax = None |
|
272 | ymax = None | |
309 | zmin = None |
|
273 | zmin = None | |
310 | zmax = None |
|
274 | zmax = None | |
311 |
|
275 | |||
312 | x_buffer = None |
|
276 | x_buffer = None | |
313 | z_buffer = None |
|
277 | z_buffer = None | |
314 |
|
278 | |||
315 | decimationx = None |
|
279 | decimationx = None | |
316 | decimationy = None |
|
280 | decimationy = None | |
317 |
|
281 | |||
318 | __MAXNUMX = 300 |
|
282 | __MAXNUMX = 300 | |
319 | __MAXNUMY = 150 |
|
283 | __MAXNUMY = 150 | |
320 |
|
284 | |||
321 | def __init__(self, *args): |
|
285 | def __init__(self, *args): | |
322 |
|
286 | |||
323 | """ |
|
287 | """ | |
324 |
|
288 | |||
325 | Input: |
|
289 | Input: | |
326 | *args : Los parametros necesarios son |
|
290 | *args : Los parametros necesarios son | |
327 | fig, nrow, ncol, xpos, ypos, colspan, rowspan |
|
291 | fig, nrow, ncol, xpos, ypos, colspan, rowspan | |
328 | """ |
|
292 | """ | |
329 |
|
293 | |||
330 | ax = self.__driver.createAxes(*args) |
|
294 | ax = self.__driver.createAxes(*args) | |
331 | self.fig = args[0] |
|
295 | self.fig = args[0] | |
332 | self.ax = ax |
|
296 | self.ax = ax | |
333 | self.plot = None |
|
297 | self.plot = None | |
334 |
|
298 | |||
335 | self.__firsttime = True |
|
299 | self.__firsttime = True | |
336 | self.idlineList = [] |
|
300 | self.idlineList = [] | |
337 |
|
301 | |||
338 | self.x_buffer = numpy.array([]) |
|
302 | self.x_buffer = numpy.array([]) | |
339 | self.z_buffer = numpy.array([]) |
|
303 | self.z_buffer = numpy.array([]) | |
340 |
|
304 | |||
341 | def setText(self, text): |
|
305 | def setText(self, text): | |
342 |
|
306 | |||
343 | self.__driver.setAxesText(self.ax, text) |
|
307 | self.__driver.setAxesText(self.ax, text) | |
344 |
|
308 | |||
345 | def setXAxisAsTime(self): |
|
309 | def setXAxisAsTime(self): | |
346 | pass |
|
310 | pass | |
347 |
|
311 | |||
348 | def pline(self, x, y, |
|
312 | def pline(self, x, y, | |
349 | xmin=None, xmax=None, |
|
313 | xmin=None, xmax=None, | |
350 | ymin=None, ymax=None, |
|
314 | ymin=None, ymax=None, | |
351 | xlabel='', ylabel='', |
|
315 | xlabel='', ylabel='', | |
352 | title='', |
|
316 | title='', | |
353 | **kwargs): |
|
317 | **kwargs): | |
354 |
|
318 | |||
355 | """ |
|
319 | """ | |
356 |
|
320 | |||
357 | Input: |
|
321 | Input: | |
358 | x : |
|
322 | x : | |
359 | y : |
|
323 | y : | |
360 | xmin : |
|
324 | xmin : | |
361 | xmax : |
|
325 | xmax : | |
362 | ymin : |
|
326 | ymin : | |
363 | ymax : |
|
327 | ymax : | |
364 | xlabel : |
|
328 | xlabel : | |
365 | ylabel : |
|
329 | ylabel : | |
366 | title : |
|
330 | title : | |
367 | **kwargs : Los parametros aceptados son |
|
331 | **kwargs : Los parametros aceptados son | |
368 |
|
332 | |||
369 | ticksize |
|
333 | ticksize | |
370 | ytick_visible |
|
334 | ytick_visible | |
371 | """ |
|
335 | """ | |
372 |
|
336 | |||
373 | if self.__firsttime: |
|
337 | if self.__firsttime: | |
374 |
|
338 | |||
375 | if xmin == None: xmin = numpy.nanmin(x) |
|
339 | if xmin == None: xmin = numpy.nanmin(x) | |
376 | if xmax == None: xmax = numpy.nanmax(x) |
|
340 | if xmax == None: xmax = numpy.nanmax(x) | |
377 | if ymin == None: ymin = numpy.nanmin(y) |
|
341 | if ymin == None: ymin = numpy.nanmin(y) | |
378 | if ymax == None: ymax = numpy.nanmax(y) |
|
342 | if ymax == None: ymax = numpy.nanmax(y) | |
379 |
|
343 | |||
380 | self.plot = self.__driver.createPline(self.ax, x, y, |
|
344 | self.plot = self.__driver.createPline(self.ax, x, y, | |
381 | xmin, xmax, |
|
345 | xmin, xmax, | |
382 | ymin, ymax, |
|
346 | ymin, ymax, | |
383 | xlabel=xlabel, |
|
347 | xlabel=xlabel, | |
384 | ylabel=ylabel, |
|
348 | ylabel=ylabel, | |
385 | title=title, |
|
349 | title=title, | |
386 | **kwargs) |
|
350 | **kwargs) | |
387 |
|
351 | |||
388 | self.idlineList.append(0) |
|
352 | self.idlineList.append(0) | |
389 | self.__firsttime = False |
|
353 | self.__firsttime = False | |
390 | return |
|
354 | return | |
391 |
|
355 | |||
392 | self.__driver.pline(self.plot, x, y, xlabel=xlabel, |
|
356 | self.__driver.pline(self.plot, x, y, xlabel=xlabel, | |
393 | ylabel=ylabel, |
|
357 | ylabel=ylabel, | |
394 | title=title) |
|
358 | title=title) | |
395 |
|
359 | |||
396 | def addpline(self, x, y, idline, **kwargs): |
|
360 | def addpline(self, x, y, idline, **kwargs): | |
397 | lines = self.ax.lines |
|
361 | lines = self.ax.lines | |
398 |
|
362 | |||
399 | if idline in self.idlineList: |
|
363 | if idline in self.idlineList: | |
400 | self.__driver.set_linedata(self.ax, x, y, idline) |
|
364 | self.__driver.set_linedata(self.ax, x, y, idline) | |
401 |
|
365 | |||
402 | if idline not in(self.idlineList): |
|
366 | if idline not in(self.idlineList): | |
403 | self.__driver.addpline(self.ax, x, y, **kwargs) |
|
367 | self.__driver.addpline(self.ax, x, y, **kwargs) | |
404 | self.idlineList.append(idline) |
|
368 | self.idlineList.append(idline) | |
405 |
|
369 | |||
406 | return |
|
370 | return | |
407 |
|
371 | |||
408 | def pmultiline(self, x, y, |
|
372 | def pmultiline(self, x, y, | |
409 | xmin=None, xmax=None, |
|
373 | xmin=None, xmax=None, | |
410 | ymin=None, ymax=None, |
|
374 | ymin=None, ymax=None, | |
411 | xlabel='', ylabel='', |
|
375 | xlabel='', ylabel='', | |
412 | title='', |
|
376 | title='', | |
413 | **kwargs): |
|
377 | **kwargs): | |
414 |
|
378 | |||
415 | if self.__firsttime: |
|
379 | if self.__firsttime: | |
416 |
|
380 | |||
417 | if xmin == None: xmin = numpy.nanmin(x) |
|
381 | if xmin == None: xmin = numpy.nanmin(x) | |
418 | if xmax == None: xmax = numpy.nanmax(x) |
|
382 | if xmax == None: xmax = numpy.nanmax(x) | |
419 | if ymin == None: ymin = numpy.nanmin(y) |
|
383 | if ymin == None: ymin = numpy.nanmin(y) | |
420 | if ymax == None: ymax = numpy.nanmax(y) |
|
384 | if ymax == None: ymax = numpy.nanmax(y) | |
421 |
|
385 | |||
422 | self.plot = self.__driver.createPmultiline(self.ax, x, y, |
|
386 | self.plot = self.__driver.createPmultiline(self.ax, x, y, | |
423 | xmin, xmax, |
|
387 | xmin, xmax, | |
424 | ymin, ymax, |
|
388 | ymin, ymax, | |
425 | xlabel=xlabel, |
|
389 | xlabel=xlabel, | |
426 | ylabel=ylabel, |
|
390 | ylabel=ylabel, | |
427 | title=title, |
|
391 | title=title, | |
428 | **kwargs) |
|
392 | **kwargs) | |
429 | self.__firsttime = False |
|
393 | self.__firsttime = False | |
430 | return |
|
394 | return | |
431 |
|
395 | |||
432 | self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel, |
|
396 | self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel, | |
433 | ylabel=ylabel, |
|
397 | ylabel=ylabel, | |
434 | title=title) |
|
398 | title=title) | |
435 |
|
399 | |||
436 | def pmultilineyaxis(self, x, y, |
|
400 | def pmultilineyaxis(self, x, y, | |
437 | xmin=None, xmax=None, |
|
401 | xmin=None, xmax=None, | |
438 | ymin=None, ymax=None, |
|
402 | ymin=None, ymax=None, | |
439 | xlabel='', ylabel='', |
|
403 | xlabel='', ylabel='', | |
440 | title='', |
|
404 | title='', | |
441 | **kwargs): |
|
405 | **kwargs): | |
442 |
|
406 | |||
443 | if self.__firsttime: |
|
407 | if self.__firsttime: | |
444 |
|
408 | |||
445 | if xmin == None: xmin = numpy.nanmin(x) |
|
409 | if xmin == None: xmin = numpy.nanmin(x) | |
446 | if xmax == None: xmax = numpy.nanmax(x) |
|
410 | if xmax == None: xmax = numpy.nanmax(x) | |
447 | if ymin == None: ymin = numpy.nanmin(y) |
|
411 | if ymin == None: ymin = numpy.nanmin(y) | |
448 | if ymax == None: ymax = numpy.nanmax(y) |
|
412 | if ymax == None: ymax = numpy.nanmax(y) | |
449 |
|
413 | |||
450 | self.plot = self.__driver.createPmultilineYAxis(self.ax, x, y, |
|
414 | self.plot = self.__driver.createPmultilineYAxis(self.ax, x, y, | |
451 | xmin, xmax, |
|
415 | xmin, xmax, | |
452 | ymin, ymax, |
|
416 | ymin, ymax, | |
453 | xlabel=xlabel, |
|
417 | xlabel=xlabel, | |
454 | ylabel=ylabel, |
|
418 | ylabel=ylabel, | |
455 | title=title, |
|
419 | title=title, | |
456 | **kwargs) |
|
420 | **kwargs) | |
457 | if self.xmin == None: self.xmin = xmin |
|
421 | if self.xmin == None: self.xmin = xmin | |
458 | if self.xmax == None: self.xmax = xmax |
|
422 | if self.xmax == None: self.xmax = xmax | |
459 | if self.ymin == None: self.ymin = ymin |
|
423 | if self.ymin == None: self.ymin = ymin | |
460 | if self.ymax == None: self.ymax = ymax |
|
424 | if self.ymax == None: self.ymax = ymax | |
461 |
|
425 | |||
462 | self.__firsttime = False |
|
426 | self.__firsttime = False | |
463 | return |
|
427 | return | |
464 |
|
428 | |||
465 | self.__driver.pmultilineyaxis(self.plot, x, y, xlabel=xlabel, |
|
429 | self.__driver.pmultilineyaxis(self.plot, x, y, xlabel=xlabel, | |
466 | ylabel=ylabel, |
|
430 | ylabel=ylabel, | |
467 | title=title) |
|
431 | title=title) | |
468 |
|
432 | |||
469 | def pcolor(self, x, y, z, |
|
433 | def pcolor(self, x, y, z, | |
470 | xmin=None, xmax=None, |
|
434 | xmin=None, xmax=None, | |
471 | ymin=None, ymax=None, |
|
435 | ymin=None, ymax=None, | |
472 | zmin=None, zmax=None, |
|
436 | zmin=None, zmax=None, | |
473 | xlabel='', ylabel='', |
|
437 | xlabel='', ylabel='', | |
474 | title='', rti = False, colormap='jet', |
|
438 | title='', rti = False, colormap='jet', | |
475 | **kwargs): |
|
439 | **kwargs): | |
476 |
|
440 | |||
477 | """ |
|
441 | """ | |
478 | Input: |
|
442 | Input: | |
479 | x : |
|
443 | x : | |
480 | y : |
|
444 | y : | |
481 | x : |
|
445 | x : | |
482 | xmin : |
|
446 | xmin : | |
483 | xmax : |
|
447 | xmax : | |
484 | ymin : |
|
448 | ymin : | |
485 | ymax : |
|
449 | ymax : | |
486 | zmin : |
|
450 | zmin : | |
487 | zmax : |
|
451 | zmax : | |
488 | xlabel : |
|
452 | xlabel : | |
489 | ylabel : |
|
453 | ylabel : | |
490 | title : |
|
454 | title : | |
491 | **kwargs : Los parametros aceptados son |
|
455 | **kwargs : Los parametros aceptados son | |
492 | ticksize=9, |
|
456 | ticksize=9, | |
493 | cblabel='' |
|
457 | cblabel='' | |
494 | rti = True or False |
|
458 | rti = True or False | |
495 | """ |
|
459 | """ | |
496 |
|
460 | |||
497 | if self.__firsttime: |
|
461 | if self.__firsttime: | |
498 |
|
462 | |||
499 | if xmin == None: xmin = numpy.nanmin(x) |
|
463 | if xmin == None: xmin = numpy.nanmin(x) | |
500 | if xmax == None: xmax = numpy.nanmax(x) |
|
464 | if xmax == None: xmax = numpy.nanmax(x) | |
501 | if ymin == None: ymin = numpy.nanmin(y) |
|
465 | if ymin == None: ymin = numpy.nanmin(y) | |
502 | if ymax == None: ymax = numpy.nanmax(y) |
|
466 | if ymax == None: ymax = numpy.nanmax(y) | |
503 | if zmin == None: zmin = numpy.nanmin(z) |
|
467 | if zmin == None: zmin = numpy.nanmin(z) | |
504 | if zmax == None: zmax = numpy.nanmax(z) |
|
468 | if zmax == None: zmax = numpy.nanmax(z) | |
505 |
|
469 | |||
506 |
|
470 | |||
507 | self.plot = self.__driver.createPcolor(self.ax, x, y, z, |
|
471 | self.plot = self.__driver.createPcolor(self.ax, x, y, z, | |
508 | xmin, xmax, |
|
472 | xmin, xmax, | |
509 | ymin, ymax, |
|
473 | ymin, ymax, | |
510 | zmin, zmax, |
|
474 | zmin, zmax, | |
511 | xlabel=xlabel, |
|
475 | xlabel=xlabel, | |
512 | ylabel=ylabel, |
|
476 | ylabel=ylabel, | |
513 | title=title, |
|
477 | title=title, | |
514 | colormap=colormap, |
|
478 | colormap=colormap, | |
515 | **kwargs) |
|
479 | **kwargs) | |
516 |
|
480 | |||
517 | if self.xmin == None: self.xmin = xmin |
|
481 | if self.xmin == None: self.xmin = xmin | |
518 | if self.xmax == None: self.xmax = xmax |
|
482 | if self.xmax == None: self.xmax = xmax | |
519 | if self.ymin == None: self.ymin = ymin |
|
483 | if self.ymin == None: self.ymin = ymin | |
520 | if self.ymax == None: self.ymax = ymax |
|
484 | if self.ymax == None: self.ymax = ymax | |
521 | if self.zmin == None: self.zmin = zmin |
|
485 | if self.zmin == None: self.zmin = zmin | |
522 | if self.zmax == None: self.zmax = zmax |
|
486 | if self.zmax == None: self.zmax = zmax | |
523 |
|
487 | |||
524 | self.__firsttime = False |
|
488 | self.__firsttime = False | |
525 | return |
|
489 | return | |
526 |
|
490 | |||
527 | if rti: |
|
491 | if rti: | |
528 | self.__driver.addpcolor(self.ax, x, y, z, self.zmin, self.zmax, |
|
492 | self.__driver.addpcolor(self.ax, x, y, z, self.zmin, self.zmax, | |
529 | xlabel=xlabel, |
|
493 | xlabel=xlabel, | |
530 | ylabel=ylabel, |
|
494 | ylabel=ylabel, | |
531 | title=title, |
|
495 | title=title, | |
532 | colormap=colormap) |
|
496 | colormap=colormap) | |
533 | return |
|
497 | return | |
534 |
|
498 | |||
535 | self.__driver.pcolor(self.plot, z, |
|
499 | self.__driver.pcolor(self.plot, z, | |
536 | xlabel=xlabel, |
|
500 | xlabel=xlabel, | |
537 | ylabel=ylabel, |
|
501 | ylabel=ylabel, | |
538 | title=title) |
|
502 | title=title) | |
539 |
|
503 | |||
540 | def pcolorbuffer(self, x, y, z, |
|
504 | def pcolorbuffer(self, x, y, z, | |
541 | xmin=None, xmax=None, |
|
505 | xmin=None, xmax=None, | |
542 | ymin=None, ymax=None, |
|
506 | ymin=None, ymax=None, | |
543 | zmin=None, zmax=None, |
|
507 | zmin=None, zmax=None, | |
544 | xlabel='', ylabel='', |
|
508 | xlabel='', ylabel='', | |
545 | title='', rti = True, colormap='jet', |
|
509 | title='', rti = True, colormap='jet', | |
546 | maxNumX = None, maxNumY = None, |
|
510 | maxNumX = None, maxNumY = None, | |
547 | **kwargs): |
|
511 | **kwargs): | |
548 |
|
512 | |||
549 | if maxNumX == None: |
|
513 | if maxNumX == None: | |
550 | maxNumX = self.__MAXNUMX |
|
514 | maxNumX = self.__MAXNUMX | |
551 |
|
515 | |||
552 | if maxNumY == None: |
|
516 | if maxNumY == None: | |
553 | maxNumY = self.__MAXNUMY |
|
517 | maxNumY = self.__MAXNUMY | |
554 |
|
518 | |||
555 | if self.__firsttime: |
|
519 | if self.__firsttime: | |
556 | self.z_buffer = z |
|
520 | self.z_buffer = z | |
557 | self.x_buffer = numpy.hstack((self.x_buffer, x)) |
|
521 | self.x_buffer = numpy.hstack((self.x_buffer, x)) | |
558 |
|
522 | |||
559 | if xmin == None: xmin = numpy.nanmin(x) |
|
523 | if xmin == None: xmin = numpy.nanmin(x) | |
560 | if xmax == None: xmax = numpy.nanmax(x) |
|
524 | if xmax == None: xmax = numpy.nanmax(x) | |
561 | if ymin == None: ymin = numpy.nanmin(y) |
|
525 | if ymin == None: ymin = numpy.nanmin(y) | |
562 | if ymax == None: ymax = numpy.nanmax(y) |
|
526 | if ymax == None: ymax = numpy.nanmax(y) | |
563 | if zmin == None: zmin = numpy.nanmin(z) |
|
527 | if zmin == None: zmin = numpy.nanmin(z) | |
564 | if zmax == None: zmax = numpy.nanmax(z) |
|
528 | if zmax == None: zmax = numpy.nanmax(z) | |
565 |
|
529 | |||
566 |
|
530 | |||
567 | self.plot = self.__driver.createPcolor(self.ax, self.x_buffer, y, z, |
|
531 | self.plot = self.__driver.createPcolor(self.ax, self.x_buffer, y, z, | |
568 | xmin, xmax, |
|
532 | xmin, xmax, | |
569 | ymin, ymax, |
|
533 | ymin, ymax, | |
570 | zmin, zmax, |
|
534 | zmin, zmax, | |
571 | xlabel=xlabel, |
|
535 | xlabel=xlabel, | |
572 | ylabel=ylabel, |
|
536 | ylabel=ylabel, | |
573 | title=title, |
|
537 | title=title, | |
574 | colormap=colormap, |
|
538 | colormap=colormap, | |
575 | **kwargs) |
|
539 | **kwargs) | |
576 |
|
540 | |||
577 | if self.xmin == None: self.xmin = xmin |
|
541 | if self.xmin == None: self.xmin = xmin | |
578 | if self.xmax == None: self.xmax = xmax |
|
542 | if self.xmax == None: self.xmax = xmax | |
579 | if self.ymin == None: self.ymin = ymin |
|
543 | if self.ymin == None: self.ymin = ymin | |
580 | if self.ymax == None: self.ymax = ymax |
|
544 | if self.ymax == None: self.ymax = ymax | |
581 | if self.zmin == None: self.zmin = zmin |
|
545 | if self.zmin == None: self.zmin = zmin | |
582 | if self.zmax == None: self.zmax = zmax |
|
546 | if self.zmax == None: self.zmax = zmax | |
583 |
|
547 | |||
584 | self.__firsttime = False |
|
548 | self.__firsttime = False | |
585 | return |
|
549 | return | |
586 |
|
550 | |||
587 | self.x_buffer = numpy.hstack((self.x_buffer, x[-1])) |
|
551 | self.x_buffer = numpy.hstack((self.x_buffer, x[-1])) | |
588 | self.z_buffer = numpy.hstack((self.z_buffer, z)) |
|
552 | self.z_buffer = numpy.hstack((self.z_buffer, z)) | |
589 |
|
553 | |||
590 | if self.decimationx == None: |
|
554 | if self.decimationx == None: | |
591 | deltax = float(self.xmax - self.xmin)/maxNumX |
|
555 | deltax = float(self.xmax - self.xmin)/maxNumX | |
592 | deltay = float(self.ymax - self.ymin)/maxNumY |
|
556 | deltay = float(self.ymax - self.ymin)/maxNumY | |
593 |
|
557 | |||
594 | resolutionx = self.x_buffer[2]-self.x_buffer[0] |
|
558 | resolutionx = self.x_buffer[2]-self.x_buffer[0] | |
595 | resolutiony = y[1]-y[0] |
|
559 | resolutiony = y[1]-y[0] | |
596 |
|
560 | |||
597 | self.decimationx = numpy.ceil(deltax / resolutionx) |
|
561 | self.decimationx = numpy.ceil(deltax / resolutionx) | |
598 | self.decimationy = numpy.ceil(deltay / resolutiony) |
|
562 | self.decimationy = numpy.ceil(deltay / resolutiony) | |
599 |
|
563 | |||
600 | z_buffer = self.z_buffer.reshape(-1,len(y)) |
|
564 | z_buffer = self.z_buffer.reshape(-1,len(y)) | |
601 |
|
565 | |||
602 | x_buffer = self.x_buffer[::self.decimationx] |
|
566 | x_buffer = self.x_buffer[::self.decimationx] | |
603 | y_buffer = y[::self.decimationy] |
|
567 | y_buffer = y[::self.decimationy] | |
604 | z_buffer = z_buffer[::self.decimationx, ::self.decimationy] |
|
568 | z_buffer = z_buffer[::self.decimationx, ::self.decimationy] | |
605 | #=================================================== |
|
569 | #=================================================== | |
606 |
|
570 | |||
607 | x_buffer, y_buffer, z_buffer = self.__fillGaps(x_buffer, y_buffer, z_buffer) |
|
571 | x_buffer, y_buffer, z_buffer = self.__fillGaps(x_buffer, y_buffer, z_buffer) | |
608 |
|
572 | |||
609 | self.__driver.addpcolorbuffer(self.ax, x_buffer, y_buffer, z_buffer, self.zmin, self.zmax, |
|
573 | self.__driver.addpcolorbuffer(self.ax, x_buffer, y_buffer, z_buffer, self.zmin, self.zmax, | |
610 | xlabel=xlabel, |
|
574 | xlabel=xlabel, | |
611 | ylabel=ylabel, |
|
575 | ylabel=ylabel, | |
612 | title=title, |
|
576 | title=title, | |
613 | colormap=colormap) |
|
577 | colormap=colormap) | |
614 |
|
578 | |||
615 | def polar(self, x, y, |
|
579 | def polar(self, x, y, | |
616 | title='', xlabel='',ylabel='',**kwargs): |
|
580 | title='', xlabel='',ylabel='',**kwargs): | |
617 |
|
581 | |||
618 | if self.__firsttime: |
|
582 | if self.__firsttime: | |
619 | self.plot = self.__driver.createPolar(self.ax, x, y, title = title, xlabel = xlabel, ylabel = ylabel) |
|
583 | self.plot = self.__driver.createPolar(self.ax, x, y, title = title, xlabel = xlabel, ylabel = ylabel) | |
620 | self.__firsttime = False |
|
584 | self.__firsttime = False | |
621 | self.x_buffer = x |
|
585 | self.x_buffer = x | |
622 | self.y_buffer = y |
|
586 | self.y_buffer = y | |
623 | return |
|
587 | return | |
624 |
|
588 | |||
625 | self.x_buffer = numpy.hstack((self.x_buffer,x)) |
|
589 | self.x_buffer = numpy.hstack((self.x_buffer,x)) | |
626 | self.y_buffer = numpy.hstack((self.y_buffer,y)) |
|
590 | self.y_buffer = numpy.hstack((self.y_buffer,y)) | |
627 | self.__driver.polar(self.plot, self.x_buffer, self.y_buffer, xlabel=xlabel, |
|
591 | self.__driver.polar(self.plot, self.x_buffer, self.y_buffer, xlabel=xlabel, | |
628 | ylabel=ylabel, |
|
592 | ylabel=ylabel, | |
629 | title=title) |
|
593 | title=title) | |
630 |
|
594 | |||
631 | def __fillGaps(self, x_buffer, y_buffer, z_buffer): |
|
595 | def __fillGaps(self, x_buffer, y_buffer, z_buffer): | |
632 |
|
596 | |||
633 | deltas = x_buffer[1:] - x_buffer[0:-1] |
|
597 | deltas = x_buffer[1:] - x_buffer[0:-1] | |
634 | x_median = numpy.median(deltas) |
|
598 | x_median = numpy.median(deltas) | |
635 |
|
599 | |||
636 | index = numpy.where(deltas >= 2*x_median) |
|
600 | index = numpy.where(deltas >= 2*x_median) | |
637 |
|
601 | |||
638 | if len(index[0]) != 0: |
|
602 | if len(index[0]) != 0: | |
639 | z_buffer[index[0],::] = self.__missing |
|
603 | z_buffer[index[0],::] = self.__missing | |
640 | z_buffer = numpy.ma.masked_inside(z_buffer,0.99*self.__missing,1.01*self.__missing) |
|
604 | z_buffer = numpy.ma.masked_inside(z_buffer,0.99*self.__missing,1.01*self.__missing) | |
641 |
|
605 | |||
642 | return x_buffer, y_buffer, z_buffer |
|
606 | return x_buffer, y_buffer, z_buffer | |
643 |
|
607 | |||
644 |
|
608 | |||
645 |
|
609 | |||
646 | No newline at end of file |
|
610 |
@@ -1,1326 +1,1327 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on Jul 9, 2014 |
|
2 | Created on Jul 9, 2014 | |
3 |
|
3 | |||
4 | @author: roj-idl71 |
|
4 | @author: roj-idl71 | |
5 | ''' |
|
5 | ''' | |
6 | import os |
|
6 | import os | |
7 | import datetime |
|
7 | import datetime | |
8 | import numpy |
|
8 | import numpy | |
9 |
|
9 | |||
10 | from figure import Figure, isRealtime |
|
10 | from figure import Figure, isRealtime | |
11 | from plotting_codes import * |
|
11 | from plotting_codes import * | |
12 |
|
12 | |||
13 | class SpectraPlot(Figure): |
|
13 | class SpectraPlot(Figure): | |
14 |
|
14 | |||
15 | isConfig = None |
|
15 | isConfig = None | |
16 | __nsubplots = None |
|
16 | __nsubplots = None | |
17 |
|
17 | |||
18 | WIDTHPROF = None |
|
18 | WIDTHPROF = None | |
19 | HEIGHTPROF = None |
|
19 | HEIGHTPROF = None | |
20 | PREFIX = 'spc' |
|
20 | PREFIX = 'spc' | |
21 |
|
21 | |||
22 | def __init__(self): |
|
22 | def __init__(self): | |
23 |
|
23 | |||
24 | self.isConfig = False |
|
24 | self.isConfig = False | |
25 | self.__nsubplots = 1 |
|
25 | self.__nsubplots = 1 | |
26 |
|
26 | |||
27 | self.WIDTH = 280 |
|
27 | self.WIDTH = 280 | |
28 | self.HEIGHT = 250 |
|
28 | self.HEIGHT = 250 | |
29 | self.WIDTHPROF = 120 |
|
29 | self.WIDTHPROF = 120 | |
30 | self.HEIGHTPROF = 0 |
|
30 | self.HEIGHTPROF = 0 | |
31 | self.counter_imagwr = 0 |
|
31 | self.counter_imagwr = 0 | |
32 |
|
32 | |||
33 | self.PLOT_CODE = SPEC_CODE |
|
33 | self.PLOT_CODE = SPEC_CODE | |
34 |
|
34 | |||
35 | self.FTP_WEI = None |
|
35 | self.FTP_WEI = None | |
36 | self.EXP_CODE = None |
|
36 | self.EXP_CODE = None | |
37 | self.SUB_EXP_CODE = None |
|
37 | self.SUB_EXP_CODE = None | |
38 | self.PLOT_POS = None |
|
38 | self.PLOT_POS = None | |
39 |
|
39 | |||
40 | self.__xfilter_ena = False |
|
40 | self.__xfilter_ena = False | |
41 | self.__yfilter_ena = False |
|
41 | self.__yfilter_ena = False | |
42 |
|
42 | |||
43 | def getSubplots(self): |
|
43 | def getSubplots(self): | |
44 |
|
44 | |||
45 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
45 | ncol = int(numpy.sqrt(self.nplots)+0.9) | |
46 | nrow = int(self.nplots*1./ncol + 0.9) |
|
46 | nrow = int(self.nplots*1./ncol + 0.9) | |
47 |
|
47 | |||
48 | return nrow, ncol |
|
48 | return nrow, ncol | |
49 |
|
49 | |||
50 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
50 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
51 |
|
51 | |||
52 | self.__showprofile = showprofile |
|
52 | self.__showprofile = showprofile | |
53 | self.nplots = nplots |
|
53 | self.nplots = nplots | |
54 |
|
54 | |||
55 | ncolspan = 1 |
|
55 | ncolspan = 1 | |
56 | colspan = 1 |
|
56 | colspan = 1 | |
57 | if showprofile: |
|
57 | if showprofile: | |
58 | ncolspan = 3 |
|
58 | ncolspan = 3 | |
59 | colspan = 2 |
|
59 | colspan = 2 | |
60 | self.__nsubplots = 2 |
|
60 | self.__nsubplots = 2 | |
61 |
|
61 | |||
62 | self.createFigure(id = id, |
|
62 | self.createFigure(id = id, | |
63 | wintitle = wintitle, |
|
63 | wintitle = wintitle, | |
64 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
64 | widthplot = self.WIDTH + self.WIDTHPROF, | |
65 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
65 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
66 | show=show) |
|
66 | show=show) | |
67 |
|
67 | |||
68 | nrow, ncol = self.getSubplots() |
|
68 | nrow, ncol = self.getSubplots() | |
69 |
|
69 | |||
70 | counter = 0 |
|
70 | counter = 0 | |
71 | for y in range(nrow): |
|
71 | for y in range(nrow): | |
72 | for x in range(ncol): |
|
72 | for x in range(ncol): | |
73 |
|
73 | |||
74 | if counter >= self.nplots: |
|
74 | if counter >= self.nplots: | |
75 | break |
|
75 | break | |
76 |
|
76 | |||
77 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
77 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
78 |
|
78 | |||
79 | if showprofile: |
|
79 | if showprofile: | |
80 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
80 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
81 |
|
81 | |||
82 | counter += 1 |
|
82 | counter += 1 | |
83 |
|
83 | |||
84 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, |
|
84 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, | |
85 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
85 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
86 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
86 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, | |
87 | server=None, folder=None, username=None, password=None, |
|
87 | server=None, folder=None, username=None, password=None, | |
88 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): |
|
88 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): | |
89 |
|
89 | |||
90 | """ |
|
90 | """ | |
91 |
|
91 | |||
92 | Input: |
|
92 | Input: | |
93 | dataOut : |
|
93 | dataOut : | |
94 | id : |
|
94 | id : | |
95 | wintitle : |
|
95 | wintitle : | |
96 | channelList : |
|
96 | channelList : | |
97 | showProfile : |
|
97 | showProfile : | |
98 | xmin : None, |
|
98 | xmin : None, | |
99 | xmax : None, |
|
99 | xmax : None, | |
100 | ymin : None, |
|
100 | ymin : None, | |
101 | ymax : None, |
|
101 | ymax : None, | |
102 | zmin : None, |
|
102 | zmin : None, | |
103 | zmax : None |
|
103 | zmax : None | |
104 | """ |
|
104 | """ | |
105 |
|
105 | |||
106 | if realtime: |
|
106 | if realtime: | |
107 | if not(isRealtime(utcdatatime = dataOut.utctime)): |
|
107 | if not(isRealtime(utcdatatime = dataOut.utctime)): | |
108 | print 'Skipping this plot function' |
|
108 | print 'Skipping this plot function' | |
109 | return |
|
109 | return | |
110 |
|
110 | |||
111 | if channelList == None: |
|
111 | if channelList == None: | |
112 | channelIndexList = dataOut.channelIndexList |
|
112 | channelIndexList = dataOut.channelIndexList | |
113 | else: |
|
113 | else: | |
114 | channelIndexList = [] |
|
114 | channelIndexList = [] | |
115 | for channel in channelList: |
|
115 | for channel in channelList: | |
116 | if channel not in dataOut.channelList: |
|
116 | if channel not in dataOut.channelList: | |
117 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
117 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
118 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
118 | channelIndexList.append(dataOut.channelList.index(channel)) | |
119 |
|
119 | |||
120 | factor = dataOut.normFactor |
|
120 | factor = dataOut.normFactor | |
121 |
|
121 | |||
122 | x = dataOut.getVelRange(1) |
|
122 | x = dataOut.getVelRange(1) | |
123 | y = dataOut.getHeiRange() |
|
123 | y = dataOut.getHeiRange() | |
124 |
|
124 | |||
125 | z = dataOut.data_spc[channelIndexList,:,:]/factor |
|
125 | z = dataOut.data_spc[channelIndexList,:,:]/factor | |
126 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
126 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
127 | zdB = 10*numpy.log10(z) |
|
127 | zdB = 10*numpy.log10(z) | |
128 |
|
128 | |||
129 | avg = numpy.average(z, axis=1) |
|
129 | avg = numpy.average(z, axis=1) | |
130 | avgdB = 10*numpy.log10(avg) |
|
130 | avgdB = 10*numpy.log10(avg) | |
131 |
|
131 | |||
132 | noise = dataOut.getNoise()/factor |
|
132 | noise = dataOut.getNoise()/factor | |
133 | noisedB = 10*numpy.log10(noise) |
|
133 | noisedB = 10*numpy.log10(noise) | |
134 |
|
134 | |||
135 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
135 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | |
136 | title = wintitle + " Spectra" |
|
136 | title = wintitle + " Spectra" | |
137 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
137 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): | |
138 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) |
|
138 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) | |
139 |
|
139 | |||
140 | xlabel = "Velocity (m/s)" |
|
140 | xlabel = "Velocity (m/s)" | |
141 | ylabel = "Range (Km)" |
|
141 | ylabel = "Range (Km)" | |
142 |
|
142 | |||
143 | if not self.isConfig: |
|
143 | if not self.isConfig: | |
144 |
|
144 | |||
145 | nplots = len(channelIndexList) |
|
145 | nplots = len(channelIndexList) | |
146 |
|
146 | |||
147 | self.setup(id=id, |
|
147 | self.setup(id=id, | |
148 | nplots=nplots, |
|
148 | nplots=nplots, | |
149 | wintitle=wintitle, |
|
149 | wintitle=wintitle, | |
150 | showprofile=showprofile, |
|
150 | showprofile=showprofile, | |
151 | show=show) |
|
151 | show=show) | |
152 |
|
152 | |||
153 | if xmin == None: xmin = numpy.nanmin(x) |
|
153 | if xmin == None: xmin = numpy.nanmin(x) | |
154 | if xmax == None: xmax = numpy.nanmax(x) |
|
154 | if xmax == None: xmax = numpy.nanmax(x) | |
155 | if ymin == None: ymin = numpy.nanmin(y) |
|
155 | if ymin == None: ymin = numpy.nanmin(y) | |
156 | if ymax == None: ymax = numpy.nanmax(y) |
|
156 | if ymax == None: ymax = numpy.nanmax(y) | |
157 | if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 |
|
157 | if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 | |
158 | if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 |
|
158 | if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 | |
159 |
|
159 | |||
160 | self.FTP_WEI = ftp_wei |
|
160 | self.FTP_WEI = ftp_wei | |
161 | self.EXP_CODE = exp_code |
|
161 | self.EXP_CODE = exp_code | |
162 | self.SUB_EXP_CODE = sub_exp_code |
|
162 | self.SUB_EXP_CODE = sub_exp_code | |
163 | self.PLOT_POS = plot_pos |
|
163 | self.PLOT_POS = plot_pos | |
164 |
|
164 | |||
165 | self.isConfig = True |
|
165 | self.isConfig = True | |
166 |
|
166 | |||
167 | self.setWinTitle(title) |
|
167 | self.setWinTitle(title) | |
168 |
|
168 | |||
169 | for i in range(self.nplots): |
|
169 | for i in range(self.nplots): | |
170 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
170 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) | |
171 | title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i]+1, noisedB[i], str_datetime) |
|
171 | title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i]+1, noisedB[i], str_datetime) | |
172 | if len(dataOut.beam.codeList) != 0: |
|
172 | if len(dataOut.beam.codeList) != 0: | |
173 | title = "Ch%d:%4.2fdB,%2.2f,%2.2f:%s" %(dataOut.channelList[i]+1, noisedB[i], dataOut.beam.azimuthList[i], dataOut.beam.zenithList[i], str_datetime) |
|
173 | title = "Ch%d:%4.2fdB,%2.2f,%2.2f:%s" %(dataOut.channelList[i]+1, noisedB[i], dataOut.beam.azimuthList[i], dataOut.beam.zenithList[i], str_datetime) | |
174 |
|
174 | |||
175 | axes = self.axesList[i*self.__nsubplots] |
|
175 | axes = self.axesList[i*self.__nsubplots] | |
176 | axes.pcolor(x, y, zdB[i,:,:], |
|
176 | axes.pcolor(x, y, zdB[i,:,:], | |
177 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
177 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
178 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
178 | xlabel=xlabel, ylabel=ylabel, title=title, | |
179 | ticksize=9, cblabel='') |
|
179 | ticksize=9, cblabel='') | |
180 |
|
180 | |||
181 | if self.__showprofile: |
|
181 | if self.__showprofile: | |
182 | axes = self.axesList[i*self.__nsubplots +1] |
|
182 | axes = self.axesList[i*self.__nsubplots +1] | |
183 | axes.pline(avgdB[i,:], y, |
|
183 | axes.pline(avgdB[i,:], y, | |
184 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
184 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |
185 | xlabel='dB', ylabel='', title='', |
|
185 | xlabel='dB', ylabel='', title='', | |
186 | ytick_visible=False, |
|
186 | ytick_visible=False, | |
187 | grid='x') |
|
187 | grid='x') | |
188 |
|
188 | |||
189 | noiseline = numpy.repeat(noisedB[i], len(y)) |
|
189 | noiseline = numpy.repeat(noisedB[i], len(y)) | |
190 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) |
|
190 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) | |
191 |
|
191 | |||
192 | self.draw() |
|
192 | self.draw() | |
193 |
|
193 | |||
194 | if figfile == None: |
|
194 | if figfile == None: | |
195 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
195 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
196 | name = str_datetime |
|
196 | name = str_datetime | |
197 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
197 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): | |
198 | name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith) |
|
198 | name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith) | |
199 | figfile = self.getFilename(name) |
|
199 | figfile = self.getFilename(name) | |
200 |
|
200 | |||
201 | self.save(figpath=figpath, |
|
201 | self.save(figpath=figpath, | |
202 | figfile=figfile, |
|
202 | figfile=figfile, | |
203 | save=save, |
|
203 | save=save, | |
204 | ftp=ftp, |
|
204 | ftp=ftp, | |
205 | wr_period=wr_period, |
|
205 | wr_period=wr_period, | |
206 | thisDatetime=thisDatetime) |
|
206 | thisDatetime=thisDatetime) | |
207 |
|
207 | |||
208 | class CrossSpectraPlot(Figure): |
|
208 | class CrossSpectraPlot(Figure): | |
209 |
|
209 | |||
210 | isConfig = None |
|
210 | isConfig = None | |
211 | __nsubplots = None |
|
211 | __nsubplots = None | |
212 |
|
212 | |||
213 | WIDTH = None |
|
213 | WIDTH = None | |
214 | HEIGHT = None |
|
214 | HEIGHT = None | |
215 | WIDTHPROF = None |
|
215 | WIDTHPROF = None | |
216 | HEIGHTPROF = None |
|
216 | HEIGHTPROF = None | |
217 | PREFIX = 'cspc' |
|
217 | PREFIX = 'cspc' | |
218 |
|
218 | |||
219 | def __init__(self): |
|
219 | def __init__(self): | |
220 |
|
220 | |||
221 | self.isConfig = False |
|
221 | self.isConfig = False | |
222 | self.__nsubplots = 4 |
|
222 | self.__nsubplots = 4 | |
223 | self.counter_imagwr = 0 |
|
223 | self.counter_imagwr = 0 | |
224 | self.WIDTH = 250 |
|
224 | self.WIDTH = 250 | |
225 | self.HEIGHT = 250 |
|
225 | self.HEIGHT = 250 | |
226 | self.WIDTHPROF = 0 |
|
226 | self.WIDTHPROF = 0 | |
227 | self.HEIGHTPROF = 0 |
|
227 | self.HEIGHTPROF = 0 | |
228 |
|
228 | |||
229 | self.PLOT_CODE = CROSS_CODE |
|
229 | self.PLOT_CODE = CROSS_CODE | |
230 | self.FTP_WEI = None |
|
230 | self.FTP_WEI = None | |
231 | self.EXP_CODE = None |
|
231 | self.EXP_CODE = None | |
232 | self.SUB_EXP_CODE = None |
|
232 | self.SUB_EXP_CODE = None | |
233 | self.PLOT_POS = None |
|
233 | self.PLOT_POS = None | |
234 |
|
234 | |||
235 | def getSubplots(self): |
|
235 | def getSubplots(self): | |
236 |
|
236 | |||
237 | ncol = 4 |
|
237 | ncol = 4 | |
238 | nrow = self.nplots |
|
238 | nrow = self.nplots | |
239 |
|
239 | |||
240 | return nrow, ncol |
|
240 | return nrow, ncol | |
241 |
|
241 | |||
242 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
242 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
243 |
|
243 | |||
244 | self.__showprofile = showprofile |
|
244 | self.__showprofile = showprofile | |
245 | self.nplots = nplots |
|
245 | self.nplots = nplots | |
246 |
|
246 | |||
247 | ncolspan = 1 |
|
247 | ncolspan = 1 | |
248 | colspan = 1 |
|
248 | colspan = 1 | |
249 |
|
249 | |||
250 | self.createFigure(id = id, |
|
250 | self.createFigure(id = id, | |
251 | wintitle = wintitle, |
|
251 | wintitle = wintitle, | |
252 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
252 | widthplot = self.WIDTH + self.WIDTHPROF, | |
253 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
253 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
254 | show=True) |
|
254 | show=True) | |
255 |
|
255 | |||
256 | nrow, ncol = self.getSubplots() |
|
256 | nrow, ncol = self.getSubplots() | |
257 |
|
257 | |||
258 | counter = 0 |
|
258 | counter = 0 | |
259 | for y in range(nrow): |
|
259 | for y in range(nrow): | |
260 | for x in range(ncol): |
|
260 | for x in range(ncol): | |
261 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
261 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
262 |
|
262 | |||
263 | counter += 1 |
|
263 | counter += 1 | |
264 |
|
264 | |||
265 | def run(self, dataOut, id, wintitle="", pairsList=None, |
|
265 | def run(self, dataOut, id, wintitle="", pairsList=None, | |
266 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
266 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
267 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, |
|
267 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, | |
268 | power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True, |
|
268 | power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True, | |
269 | server=None, folder=None, username=None, password=None, |
|
269 | server=None, folder=None, username=None, password=None, | |
270 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
270 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): | |
271 |
|
271 | |||
272 | """ |
|
272 | """ | |
273 |
|
273 | |||
274 | Input: |
|
274 | Input: | |
275 | dataOut : |
|
275 | dataOut : | |
276 | id : |
|
276 | id : | |
277 | wintitle : |
|
277 | wintitle : | |
278 | channelList : |
|
278 | channelList : | |
279 | showProfile : |
|
279 | showProfile : | |
280 | xmin : None, |
|
280 | xmin : None, | |
281 | xmax : None, |
|
281 | xmax : None, | |
282 | ymin : None, |
|
282 | ymin : None, | |
283 | ymax : None, |
|
283 | ymax : None, | |
284 | zmin : None, |
|
284 | zmin : None, | |
285 | zmax : None |
|
285 | zmax : None | |
286 | """ |
|
286 | """ | |
287 |
|
287 | |||
288 | if pairsList == None: |
|
288 | if pairsList == None: | |
289 | pairsIndexList = dataOut.pairsIndexList |
|
289 | pairsIndexList = dataOut.pairsIndexList | |
290 | else: |
|
290 | else: | |
291 | pairsIndexList = [] |
|
291 | pairsIndexList = [] | |
292 | for pair in pairsList: |
|
292 | for pair in pairsList: | |
293 | if pair not in dataOut.pairsList: |
|
293 | if pair not in dataOut.pairsList: | |
294 | raise ValueError, "Pair %s is not in dataOut.pairsList" %str(pair) |
|
294 | raise ValueError, "Pair %s is not in dataOut.pairsList" %str(pair) | |
295 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
295 | pairsIndexList.append(dataOut.pairsList.index(pair)) | |
296 |
|
296 | |||
297 |
if pairsIndexList |
|
297 | if not pairsIndexList: | |
298 | return |
|
298 | return | |
299 |
|
299 | |||
300 | if len(pairsIndexList) > 4: |
|
300 | if len(pairsIndexList) > 4: | |
301 | pairsIndexList = pairsIndexList[0:4] |
|
301 | pairsIndexList = pairsIndexList[0:4] | |
|
302 | ||||
302 | factor = dataOut.normFactor |
|
303 | factor = dataOut.normFactor | |
303 | x = dataOut.getVelRange(1) |
|
304 | x = dataOut.getVelRange(1) | |
304 | y = dataOut.getHeiRange() |
|
305 | y = dataOut.getHeiRange() | |
305 | z = dataOut.data_spc[:,:,:]/factor |
|
306 | z = dataOut.data_spc[:,:,:]/factor | |
306 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
307 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
307 |
|
308 | |||
308 | noise = dataOut.noise/factor |
|
309 | noise = dataOut.noise/factor | |
309 |
|
310 | |||
310 | zdB = 10*numpy.log10(z) |
|
311 | zdB = 10*numpy.log10(z) | |
311 | noisedB = 10*numpy.log10(noise) |
|
312 | noisedB = 10*numpy.log10(noise) | |
312 |
|
313 | |||
313 |
|
314 | |||
314 | #thisDatetime = dataOut.datatime |
|
315 | #thisDatetime = dataOut.datatime | |
315 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
316 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | |
316 | title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
317 | title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
317 | xlabel = "Velocity (m/s)" |
|
318 | xlabel = "Velocity (m/s)" | |
318 | ylabel = "Range (Km)" |
|
319 | ylabel = "Range (Km)" | |
319 |
|
320 | |||
320 | if not self.isConfig: |
|
321 | if not self.isConfig: | |
321 |
|
322 | |||
322 | nplots = len(pairsIndexList) |
|
323 | nplots = len(pairsIndexList) | |
323 |
|
324 | |||
324 | self.setup(id=id, |
|
325 | self.setup(id=id, | |
325 | nplots=nplots, |
|
326 | nplots=nplots, | |
326 | wintitle=wintitle, |
|
327 | wintitle=wintitle, | |
327 | showprofile=False, |
|
328 | showprofile=False, | |
328 | show=show) |
|
329 | show=show) | |
329 |
|
330 | |||
330 | avg = numpy.abs(numpy.average(z, axis=1)) |
|
331 | avg = numpy.abs(numpy.average(z, axis=1)) | |
331 | avgdB = 10*numpy.log10(avg) |
|
332 | avgdB = 10*numpy.log10(avg) | |
332 |
|
333 | |||
333 | if xmin == None: xmin = numpy.nanmin(x) |
|
334 | if xmin == None: xmin = numpy.nanmin(x) | |
334 | if xmax == None: xmax = numpy.nanmax(x) |
|
335 | if xmax == None: xmax = numpy.nanmax(x) | |
335 | if ymin == None: ymin = numpy.nanmin(y) |
|
336 | if ymin == None: ymin = numpy.nanmin(y) | |
336 | if ymax == None: ymax = numpy.nanmax(y) |
|
337 | if ymax == None: ymax = numpy.nanmax(y) | |
337 | if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 |
|
338 | if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 | |
338 | if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 |
|
339 | if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 | |
339 |
|
340 | |||
340 | self.FTP_WEI = ftp_wei |
|
341 | self.FTP_WEI = ftp_wei | |
341 | self.EXP_CODE = exp_code |
|
342 | self.EXP_CODE = exp_code | |
342 | self.SUB_EXP_CODE = sub_exp_code |
|
343 | self.SUB_EXP_CODE = sub_exp_code | |
343 | self.PLOT_POS = plot_pos |
|
344 | self.PLOT_POS = plot_pos | |
344 |
|
345 | |||
345 | self.isConfig = True |
|
346 | self.isConfig = True | |
346 |
|
347 | |||
347 | self.setWinTitle(title) |
|
348 | self.setWinTitle(title) | |
348 |
|
349 | |||
349 | for i in range(self.nplots): |
|
350 | for i in range(self.nplots): | |
350 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
351 | pair = dataOut.pairsList[pairsIndexList[i]] | |
351 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
352 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) | |
352 | title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[pair[0]], str_datetime) |
|
353 | title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[pair[0]], str_datetime) | |
353 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]/factor) |
|
354 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]/factor) | |
354 | axes0 = self.axesList[i*self.__nsubplots] |
|
355 | axes0 = self.axesList[i*self.__nsubplots] | |
355 | axes0.pcolor(x, y, zdB, |
|
356 | axes0.pcolor(x, y, zdB, | |
356 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
357 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
357 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
358 | xlabel=xlabel, ylabel=ylabel, title=title, | |
358 | ticksize=9, colormap=power_cmap, cblabel='') |
|
359 | ticksize=9, colormap=power_cmap, cblabel='') | |
359 |
|
360 | |||
360 | title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[pair[1]], str_datetime) |
|
361 | title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[pair[1]], str_datetime) | |
361 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]/factor) |
|
362 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]/factor) | |
362 | axes0 = self.axesList[i*self.__nsubplots+1] |
|
363 | axes0 = self.axesList[i*self.__nsubplots+1] | |
363 | axes0.pcolor(x, y, zdB, |
|
364 | axes0.pcolor(x, y, zdB, | |
364 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
365 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
365 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
366 | xlabel=xlabel, ylabel=ylabel, title=title, | |
366 | ticksize=9, colormap=power_cmap, cblabel='') |
|
367 | ticksize=9, colormap=power_cmap, cblabel='') | |
367 |
|
368 | |||
368 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) |
|
369 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) | |
369 | coherence = numpy.abs(coherenceComplex) |
|
370 | coherence = numpy.abs(coherenceComplex) | |
370 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi |
|
371 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi | |
371 | phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi |
|
372 | phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi | |
372 |
|
373 | |||
373 | title = "Coherence %d%d" %(pair[0], pair[1]) |
|
374 | title = "Coherence %d%d" %(pair[0], pair[1]) | |
374 | axes0 = self.axesList[i*self.__nsubplots+2] |
|
375 | axes0 = self.axesList[i*self.__nsubplots+2] | |
375 | axes0.pcolor(x, y, coherence, |
|
376 | axes0.pcolor(x, y, coherence, | |
376 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1, |
|
377 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1, | |
377 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
378 | xlabel=xlabel, ylabel=ylabel, title=title, | |
378 | ticksize=9, colormap=coherence_cmap, cblabel='') |
|
379 | ticksize=9, colormap=coherence_cmap, cblabel='') | |
379 |
|
380 | |||
380 | title = "Phase %d%d" %(pair[0], pair[1]) |
|
381 | title = "Phase %d%d" %(pair[0], pair[1]) | |
381 | axes0 = self.axesList[i*self.__nsubplots+3] |
|
382 | axes0 = self.axesList[i*self.__nsubplots+3] | |
382 | axes0.pcolor(x, y, phase, |
|
383 | axes0.pcolor(x, y, phase, | |
383 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, |
|
384 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, | |
384 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
385 | xlabel=xlabel, ylabel=ylabel, title=title, | |
385 | ticksize=9, colormap=phase_cmap, cblabel='') |
|
386 | ticksize=9, colormap=phase_cmap, cblabel='') | |
386 |
|
387 | |||
387 |
|
388 | |||
388 |
|
389 | |||
389 | self.draw() |
|
390 | self.draw() | |
390 |
|
391 | |||
391 | self.save(figpath=figpath, |
|
392 | self.save(figpath=figpath, | |
392 | figfile=figfile, |
|
393 | figfile=figfile, | |
393 | save=save, |
|
394 | save=save, | |
394 | ftp=ftp, |
|
395 | ftp=ftp, | |
395 | wr_period=wr_period, |
|
396 | wr_period=wr_period, | |
396 | thisDatetime=thisDatetime) |
|
397 | thisDatetime=thisDatetime) | |
397 |
|
398 | |||
398 |
|
399 | |||
399 | class RTIPlot(Figure): |
|
400 | class RTIPlot(Figure): | |
400 |
|
401 | |||
401 | __isConfig = None |
|
402 | __isConfig = None | |
402 | __nsubplots = None |
|
403 | __nsubplots = None | |
403 |
|
404 | |||
404 | WIDTHPROF = None |
|
405 | WIDTHPROF = None | |
405 | HEIGHTPROF = None |
|
406 | HEIGHTPROF = None | |
406 | PREFIX = 'rti' |
|
407 | PREFIX = 'rti' | |
407 |
|
408 | |||
408 | def __init__(self): |
|
409 | def __init__(self): | |
409 |
|
410 | |||
410 | self.timerange = None |
|
411 | self.timerange = None | |
411 | self.__isConfig = False |
|
412 | self.__isConfig = False | |
412 | self.__nsubplots = 1 |
|
413 | self.__nsubplots = 1 | |
413 |
|
414 | |||
414 | self.WIDTH = 800 |
|
415 | self.WIDTH = 800 | |
415 | self.HEIGHT = 150 |
|
416 | self.HEIGHT = 150 | |
416 | self.WIDTHPROF = 120 |
|
417 | self.WIDTHPROF = 120 | |
417 | self.HEIGHTPROF = 0 |
|
418 | self.HEIGHTPROF = 0 | |
418 | self.counter_imagwr = 0 |
|
419 | self.counter_imagwr = 0 | |
419 |
|
420 | |||
420 | self.PLOT_CODE = RTI_CODE |
|
421 | self.PLOT_CODE = RTI_CODE | |
421 |
|
422 | |||
422 | self.FTP_WEI = None |
|
423 | self.FTP_WEI = None | |
423 | self.EXP_CODE = None |
|
424 | self.EXP_CODE = None | |
424 | self.SUB_EXP_CODE = None |
|
425 | self.SUB_EXP_CODE = None | |
425 | self.PLOT_POS = None |
|
426 | self.PLOT_POS = None | |
426 | self.tmin = None |
|
427 | self.tmin = None | |
427 | self.tmax = None |
|
428 | self.tmax = None | |
428 |
|
429 | |||
429 | self.xmin = None |
|
430 | self.xmin = None | |
430 | self.xmax = None |
|
431 | self.xmax = None | |
431 |
|
432 | |||
432 | self.figfile = None |
|
433 | self.figfile = None | |
433 |
|
434 | |||
434 | def getSubplots(self): |
|
435 | def getSubplots(self): | |
435 |
|
436 | |||
436 | ncol = 1 |
|
437 | ncol = 1 | |
437 | nrow = self.nplots |
|
438 | nrow = self.nplots | |
438 |
|
439 | |||
439 | return nrow, ncol |
|
440 | return nrow, ncol | |
440 |
|
441 | |||
441 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
442 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
442 |
|
443 | |||
443 | self.__showprofile = showprofile |
|
444 | self.__showprofile = showprofile | |
444 | self.nplots = nplots |
|
445 | self.nplots = nplots | |
445 |
|
446 | |||
446 | ncolspan = 1 |
|
447 | ncolspan = 1 | |
447 | colspan = 1 |
|
448 | colspan = 1 | |
448 | if showprofile: |
|
449 | if showprofile: | |
449 | ncolspan = 7 |
|
450 | ncolspan = 7 | |
450 | colspan = 6 |
|
451 | colspan = 6 | |
451 | self.__nsubplots = 2 |
|
452 | self.__nsubplots = 2 | |
452 |
|
453 | |||
453 | self.createFigure(id = id, |
|
454 | self.createFigure(id = id, | |
454 | wintitle = wintitle, |
|
455 | wintitle = wintitle, | |
455 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
456 | widthplot = self.WIDTH + self.WIDTHPROF, | |
456 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
457 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
457 | show=show) |
|
458 | show=show) | |
458 |
|
459 | |||
459 | nrow, ncol = self.getSubplots() |
|
460 | nrow, ncol = self.getSubplots() | |
460 |
|
461 | |||
461 | counter = 0 |
|
462 | counter = 0 | |
462 | for y in range(nrow): |
|
463 | for y in range(nrow): | |
463 | for x in range(ncol): |
|
464 | for x in range(ncol): | |
464 |
|
465 | |||
465 | if counter >= self.nplots: |
|
466 | if counter >= self.nplots: | |
466 | break |
|
467 | break | |
467 |
|
468 | |||
468 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
469 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
469 |
|
470 | |||
470 | if showprofile: |
|
471 | if showprofile: | |
471 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
472 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
472 |
|
473 | |||
473 | counter += 1 |
|
474 | counter += 1 | |
474 |
|
475 | |||
475 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
476 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', | |
476 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
477 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
477 | timerange=None, |
|
478 | timerange=None, | |
478 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
479 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, | |
479 | server=None, folder=None, username=None, password=None, |
|
480 | server=None, folder=None, username=None, password=None, | |
480 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
481 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): | |
481 |
|
482 | |||
482 | """ |
|
483 | """ | |
483 |
|
484 | |||
484 | Input: |
|
485 | Input: | |
485 | dataOut : |
|
486 | dataOut : | |
486 | id : |
|
487 | id : | |
487 | wintitle : |
|
488 | wintitle : | |
488 | channelList : |
|
489 | channelList : | |
489 | showProfile : |
|
490 | showProfile : | |
490 | xmin : None, |
|
491 | xmin : None, | |
491 | xmax : None, |
|
492 | xmax : None, | |
492 | ymin : None, |
|
493 | ymin : None, | |
493 | ymax : None, |
|
494 | ymax : None, | |
494 | zmin : None, |
|
495 | zmin : None, | |
495 | zmax : None |
|
496 | zmax : None | |
496 | """ |
|
497 | """ | |
497 |
|
498 | |||
498 | if channelList == None: |
|
499 | if channelList == None: | |
499 | channelIndexList = dataOut.channelIndexList |
|
500 | channelIndexList = dataOut.channelIndexList | |
500 | else: |
|
501 | else: | |
501 | channelIndexList = [] |
|
502 | channelIndexList = [] | |
502 | for channel in channelList: |
|
503 | for channel in channelList: | |
503 | if channel not in dataOut.channelList: |
|
504 | if channel not in dataOut.channelList: | |
504 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
505 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
505 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
506 | channelIndexList.append(dataOut.channelList.index(channel)) | |
506 |
|
507 | |||
507 | # if timerange != None: |
|
508 | # if timerange != None: | |
508 | # self.timerange = timerange |
|
509 | # self.timerange = timerange | |
509 |
|
510 | |||
510 | #tmin = None |
|
511 | #tmin = None | |
511 | #tmax = None |
|
512 | #tmax = None | |
512 | factor = dataOut.normFactor |
|
513 | factor = dataOut.normFactor | |
513 | x = dataOut.getTimeRange() |
|
514 | x = dataOut.getTimeRange() | |
514 | y = dataOut.getHeiRange() |
|
515 | y = dataOut.getHeiRange() | |
515 |
|
516 | |||
516 | z = dataOut.data_spc[channelIndexList,:,:]/factor |
|
517 | z = dataOut.data_spc[channelIndexList,:,:]/factor | |
517 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
518 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
518 | avg = numpy.average(z, axis=1) |
|
519 | avg = numpy.average(z, axis=1) | |
519 |
|
520 | |||
520 | avgdB = 10.*numpy.log10(avg) |
|
521 | avgdB = 10.*numpy.log10(avg) | |
521 |
|
522 | |||
522 |
|
523 | |||
523 | # thisDatetime = dataOut.datatime |
|
524 | # thisDatetime = dataOut.datatime | |
524 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
525 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | |
525 | title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
526 | title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
526 | xlabel = "" |
|
527 | xlabel = "" | |
527 | ylabel = "Range (Km)" |
|
528 | ylabel = "Range (Km)" | |
528 |
|
529 | |||
529 | if not self.__isConfig: |
|
530 | if not self.__isConfig: | |
530 |
|
531 | |||
531 | nplots = len(channelIndexList) |
|
532 | nplots = len(channelIndexList) | |
532 |
|
533 | |||
533 | self.setup(id=id, |
|
534 | self.setup(id=id, | |
534 | nplots=nplots, |
|
535 | nplots=nplots, | |
535 | wintitle=wintitle, |
|
536 | wintitle=wintitle, | |
536 | showprofile=showprofile, |
|
537 | showprofile=showprofile, | |
537 | show=show) |
|
538 | show=show) | |
538 |
|
539 | |||
539 | if timerange != None: |
|
540 | if timerange != None: | |
540 | self.timerange = timerange |
|
541 | self.timerange = timerange | |
541 |
|
542 | |||
542 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
543 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) | |
543 |
|
544 | |||
544 | noise = dataOut.noise/factor |
|
545 | noise = dataOut.noise/factor | |
545 | noisedB = 10*numpy.log10(noise) |
|
546 | noisedB = 10*numpy.log10(noise) | |
546 |
|
547 | |||
547 | if ymin == None: ymin = numpy.nanmin(y) |
|
548 | if ymin == None: ymin = numpy.nanmin(y) | |
548 | if ymax == None: ymax = numpy.nanmax(y) |
|
549 | if ymax == None: ymax = numpy.nanmax(y) | |
549 | if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 |
|
550 | if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 | |
550 | if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 |
|
551 | if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 | |
551 |
|
552 | |||
552 | self.FTP_WEI = ftp_wei |
|
553 | self.FTP_WEI = ftp_wei | |
553 | self.EXP_CODE = exp_code |
|
554 | self.EXP_CODE = exp_code | |
554 | self.SUB_EXP_CODE = sub_exp_code |
|
555 | self.SUB_EXP_CODE = sub_exp_code | |
555 | self.PLOT_POS = plot_pos |
|
556 | self.PLOT_POS = plot_pos | |
556 |
|
557 | |||
557 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
558 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
558 | self.__isConfig = True |
|
559 | self.__isConfig = True | |
559 | self.figfile = figfile |
|
560 | self.figfile = figfile | |
560 |
|
561 | |||
561 | self.setWinTitle(title) |
|
562 | self.setWinTitle(title) | |
562 |
|
563 | |||
563 | if ((self.xmax - x[1]) < (x[1]-x[0])): |
|
564 | if ((self.xmax - x[1]) < (x[1]-x[0])): | |
564 | x[1] = self.xmax |
|
565 | x[1] = self.xmax | |
565 |
|
566 | |||
566 | for i in range(self.nplots): |
|
567 | for i in range(self.nplots): | |
567 | title = "Channel %d: %s" %(dataOut.channelList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
568 | title = "Channel %d: %s" %(dataOut.channelList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
568 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
569 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): | |
569 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) |
|
570 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) | |
570 | axes = self.axesList[i*self.__nsubplots] |
|
571 | axes = self.axesList[i*self.__nsubplots] | |
571 | zdB = avgdB[i].reshape((1,-1)) |
|
572 | zdB = avgdB[i].reshape((1,-1)) | |
572 | axes.pcolorbuffer(x, y, zdB, |
|
573 | axes.pcolorbuffer(x, y, zdB, | |
573 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
574 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
574 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
575 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
575 | ticksize=9, cblabel='', cbsize="1%") |
|
576 | ticksize=9, cblabel='', cbsize="1%") | |
576 |
|
577 | |||
577 | if self.__showprofile: |
|
578 | if self.__showprofile: | |
578 | axes = self.axesList[i*self.__nsubplots +1] |
|
579 | axes = self.axesList[i*self.__nsubplots +1] | |
579 | axes.pline(avgdB[i], y, |
|
580 | axes.pline(avgdB[i], y, | |
580 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
581 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |
581 | xlabel='dB', ylabel='', title='', |
|
582 | xlabel='dB', ylabel='', title='', | |
582 | ytick_visible=False, |
|
583 | ytick_visible=False, | |
583 | grid='x') |
|
584 | grid='x') | |
584 |
|
585 | |||
585 | self.draw() |
|
586 | self.draw() | |
586 |
|
587 | |||
587 | if x[1] >= self.axesList[0].xmax: |
|
588 | if x[1] >= self.axesList[0].xmax: | |
588 | self.counter_imagwr = wr_period |
|
589 | self.counter_imagwr = wr_period | |
589 | self.__isConfig = False |
|
590 | self.__isConfig = False | |
590 | self.figfile = None |
|
591 | self.figfile = None | |
591 |
|
592 | |||
592 | self.save(figpath=figpath, |
|
593 | self.save(figpath=figpath, | |
593 | figfile=figfile, |
|
594 | figfile=figfile, | |
594 | save=save, |
|
595 | save=save, | |
595 | ftp=ftp, |
|
596 | ftp=ftp, | |
596 | wr_period=wr_period, |
|
597 | wr_period=wr_period, | |
597 | thisDatetime=thisDatetime, |
|
598 | thisDatetime=thisDatetime, | |
598 | update_figfile=False) |
|
599 | update_figfile=False) | |
599 |
|
600 | |||
600 | class CoherenceMap(Figure): |
|
601 | class CoherenceMap(Figure): | |
601 | isConfig = None |
|
602 | isConfig = None | |
602 | __nsubplots = None |
|
603 | __nsubplots = None | |
603 |
|
604 | |||
604 | WIDTHPROF = None |
|
605 | WIDTHPROF = None | |
605 | HEIGHTPROF = None |
|
606 | HEIGHTPROF = None | |
606 | PREFIX = 'cmap' |
|
607 | PREFIX = 'cmap' | |
607 |
|
608 | |||
608 | def __init__(self): |
|
609 | def __init__(self): | |
609 | self.timerange = 2*60*60 |
|
610 | self.timerange = 2*60*60 | |
610 | self.isConfig = False |
|
611 | self.isConfig = False | |
611 | self.__nsubplots = 1 |
|
612 | self.__nsubplots = 1 | |
612 |
|
613 | |||
613 | self.WIDTH = 800 |
|
614 | self.WIDTH = 800 | |
614 | self.HEIGHT = 150 |
|
615 | self.HEIGHT = 150 | |
615 | self.WIDTHPROF = 120 |
|
616 | self.WIDTHPROF = 120 | |
616 | self.HEIGHTPROF = 0 |
|
617 | self.HEIGHTPROF = 0 | |
617 | self.counter_imagwr = 0 |
|
618 | self.counter_imagwr = 0 | |
618 |
|
619 | |||
619 | self.PLOT_CODE = COH_CODE |
|
620 | self.PLOT_CODE = COH_CODE | |
620 |
|
621 | |||
621 | self.FTP_WEI = None |
|
622 | self.FTP_WEI = None | |
622 | self.EXP_CODE = None |
|
623 | self.EXP_CODE = None | |
623 | self.SUB_EXP_CODE = None |
|
624 | self.SUB_EXP_CODE = None | |
624 | self.PLOT_POS = None |
|
625 | self.PLOT_POS = None | |
625 | self.counter_imagwr = 0 |
|
626 | self.counter_imagwr = 0 | |
626 |
|
627 | |||
627 | self.xmin = None |
|
628 | self.xmin = None | |
628 | self.xmax = None |
|
629 | self.xmax = None | |
629 |
|
630 | |||
630 | def getSubplots(self): |
|
631 | def getSubplots(self): | |
631 | ncol = 1 |
|
632 | ncol = 1 | |
632 | nrow = self.nplots*2 |
|
633 | nrow = self.nplots*2 | |
633 |
|
634 | |||
634 | return nrow, ncol |
|
635 | return nrow, ncol | |
635 |
|
636 | |||
636 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
637 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
637 | self.__showprofile = showprofile |
|
638 | self.__showprofile = showprofile | |
638 | self.nplots = nplots |
|
639 | self.nplots = nplots | |
639 |
|
640 | |||
640 | ncolspan = 1 |
|
641 | ncolspan = 1 | |
641 | colspan = 1 |
|
642 | colspan = 1 | |
642 | if showprofile: |
|
643 | if showprofile: | |
643 | ncolspan = 7 |
|
644 | ncolspan = 7 | |
644 | colspan = 6 |
|
645 | colspan = 6 | |
645 | self.__nsubplots = 2 |
|
646 | self.__nsubplots = 2 | |
646 |
|
647 | |||
647 | self.createFigure(id = id, |
|
648 | self.createFigure(id = id, | |
648 | wintitle = wintitle, |
|
649 | wintitle = wintitle, | |
649 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
650 | widthplot = self.WIDTH + self.WIDTHPROF, | |
650 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
651 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
651 | show=True) |
|
652 | show=True) | |
652 |
|
653 | |||
653 | nrow, ncol = self.getSubplots() |
|
654 | nrow, ncol = self.getSubplots() | |
654 |
|
655 | |||
655 | for y in range(nrow): |
|
656 | for y in range(nrow): | |
656 | for x in range(ncol): |
|
657 | for x in range(ncol): | |
657 |
|
658 | |||
658 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
659 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
659 |
|
660 | |||
660 | if showprofile: |
|
661 | if showprofile: | |
661 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
662 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
662 |
|
663 | |||
663 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', |
|
664 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', | |
664 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
665 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
665 | timerange=None, |
|
666 | timerange=None, | |
666 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, |
|
667 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, | |
667 | coherence_cmap='jet', phase_cmap='RdBu_r', show=True, |
|
668 | coherence_cmap='jet', phase_cmap='RdBu_r', show=True, | |
668 | server=None, folder=None, username=None, password=None, |
|
669 | server=None, folder=None, username=None, password=None, | |
669 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
670 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): | |
670 |
|
671 | |||
671 | if pairsList == None: |
|
672 | if pairsList == None: | |
672 | pairsIndexList = dataOut.pairsIndexList |
|
673 | pairsIndexList = dataOut.pairsIndexList | |
673 | else: |
|
674 | else: | |
674 | pairsIndexList = [] |
|
675 | pairsIndexList = [] | |
675 | for pair in pairsList: |
|
676 | for pair in pairsList: | |
676 | if pair not in dataOut.pairsList: |
|
677 | if pair not in dataOut.pairsList: | |
677 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
678 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) | |
678 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
679 | pairsIndexList.append(dataOut.pairsList.index(pair)) | |
679 |
|
680 | |||
680 | if pairsIndexList == []: |
|
681 | if pairsIndexList == []: | |
681 | return |
|
682 | return | |
682 |
|
683 | |||
683 | if len(pairsIndexList) > 4: |
|
684 | if len(pairsIndexList) > 4: | |
684 | pairsIndexList = pairsIndexList[0:4] |
|
685 | pairsIndexList = pairsIndexList[0:4] | |
685 |
|
686 | |||
686 | # tmin = None |
|
687 | # tmin = None | |
687 | # tmax = None |
|
688 | # tmax = None | |
688 | x = dataOut.getTimeRange() |
|
689 | x = dataOut.getTimeRange() | |
689 | y = dataOut.getHeiRange() |
|
690 | y = dataOut.getHeiRange() | |
690 |
|
691 | |||
691 | #thisDatetime = dataOut.datatime |
|
692 | #thisDatetime = dataOut.datatime | |
692 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
693 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | |
693 | title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
694 | title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
694 | xlabel = "" |
|
695 | xlabel = "" | |
695 | ylabel = "Range (Km)" |
|
696 | ylabel = "Range (Km)" | |
696 |
|
697 | |||
697 | if not self.isConfig: |
|
698 | if not self.isConfig: | |
698 | nplots = len(pairsIndexList) |
|
699 | nplots = len(pairsIndexList) | |
699 | self.setup(id=id, |
|
700 | self.setup(id=id, | |
700 | nplots=nplots, |
|
701 | nplots=nplots, | |
701 | wintitle=wintitle, |
|
702 | wintitle=wintitle, | |
702 | showprofile=showprofile, |
|
703 | showprofile=showprofile, | |
703 | show=show) |
|
704 | show=show) | |
704 |
|
705 | |||
705 | if timerange != None: |
|
706 | if timerange != None: | |
706 | self.timerange = timerange |
|
707 | self.timerange = timerange | |
707 |
|
708 | |||
708 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
709 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) | |
709 |
|
710 | |||
710 | if ymin == None: ymin = numpy.nanmin(y) |
|
711 | if ymin == None: ymin = numpy.nanmin(y) | |
711 | if ymax == None: ymax = numpy.nanmax(y) |
|
712 | if ymax == None: ymax = numpy.nanmax(y) | |
712 | if zmin == None: zmin = 0. |
|
713 | if zmin == None: zmin = 0. | |
713 | if zmax == None: zmax = 1. |
|
714 | if zmax == None: zmax = 1. | |
714 |
|
715 | |||
715 | self.FTP_WEI = ftp_wei |
|
716 | self.FTP_WEI = ftp_wei | |
716 | self.EXP_CODE = exp_code |
|
717 | self.EXP_CODE = exp_code | |
717 | self.SUB_EXP_CODE = sub_exp_code |
|
718 | self.SUB_EXP_CODE = sub_exp_code | |
718 | self.PLOT_POS = plot_pos |
|
719 | self.PLOT_POS = plot_pos | |
719 |
|
720 | |||
720 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
721 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
721 |
|
722 | |||
722 | self.isConfig = True |
|
723 | self.isConfig = True | |
723 |
|
724 | |||
724 | self.setWinTitle(title) |
|
725 | self.setWinTitle(title) | |
725 |
|
726 | |||
726 | if ((self.xmax - x[1]) < (x[1]-x[0])): |
|
727 | if ((self.xmax - x[1]) < (x[1]-x[0])): | |
727 | x[1] = self.xmax |
|
728 | x[1] = self.xmax | |
728 |
|
729 | |||
729 | for i in range(self.nplots): |
|
730 | for i in range(self.nplots): | |
730 |
|
731 | |||
731 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
732 | pair = dataOut.pairsList[pairsIndexList[i]] | |
732 |
|
733 | |||
733 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0) |
|
734 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0) | |
734 | powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0) |
|
735 | powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0) | |
735 | powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0) |
|
736 | powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0) | |
736 |
|
737 | |||
737 |
|
738 | |||
738 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) |
|
739 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) | |
739 | coherence = numpy.abs(avgcoherenceComplex) |
|
740 | coherence = numpy.abs(avgcoherenceComplex) | |
740 |
|
741 | |||
741 | z = coherence.reshape((1,-1)) |
|
742 | z = coherence.reshape((1,-1)) | |
742 |
|
743 | |||
743 | counter = 0 |
|
744 | counter = 0 | |
744 |
|
745 | |||
745 | title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
746 | title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
746 | axes = self.axesList[i*self.__nsubplots*2] |
|
747 | axes = self.axesList[i*self.__nsubplots*2] | |
747 | axes.pcolorbuffer(x, y, z, |
|
748 | axes.pcolorbuffer(x, y, z, | |
748 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
749 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
749 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
750 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
750 | ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%") |
|
751 | ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%") | |
751 |
|
752 | |||
752 | if self.__showprofile: |
|
753 | if self.__showprofile: | |
753 | counter += 1 |
|
754 | counter += 1 | |
754 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
755 | axes = self.axesList[i*self.__nsubplots*2 + counter] | |
755 | axes.pline(coherence, y, |
|
756 | axes.pline(coherence, y, | |
756 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
757 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |
757 | xlabel='', ylabel='', title='', ticksize=7, |
|
758 | xlabel='', ylabel='', title='', ticksize=7, | |
758 | ytick_visible=False, nxticks=5, |
|
759 | ytick_visible=False, nxticks=5, | |
759 | grid='x') |
|
760 | grid='x') | |
760 |
|
761 | |||
761 | counter += 1 |
|
762 | counter += 1 | |
762 |
|
763 | |||
763 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi |
|
764 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi | |
764 |
|
765 | |||
765 | z = phase.reshape((1,-1)) |
|
766 | z = phase.reshape((1,-1)) | |
766 |
|
767 | |||
767 | title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
768 | title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
768 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
769 | axes = self.axesList[i*self.__nsubplots*2 + counter] | |
769 | axes.pcolorbuffer(x, y, z, |
|
770 | axes.pcolorbuffer(x, y, z, | |
770 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, |
|
771 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, | |
771 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
772 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
772 | ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%") |
|
773 | ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%") | |
773 |
|
774 | |||
774 | if self.__showprofile: |
|
775 | if self.__showprofile: | |
775 | counter += 1 |
|
776 | counter += 1 | |
776 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
777 | axes = self.axesList[i*self.__nsubplots*2 + counter] | |
777 | axes.pline(phase, y, |
|
778 | axes.pline(phase, y, | |
778 | xmin=-180, xmax=180, ymin=ymin, ymax=ymax, |
|
779 | xmin=-180, xmax=180, ymin=ymin, ymax=ymax, | |
779 | xlabel='', ylabel='', title='', ticksize=7, |
|
780 | xlabel='', ylabel='', title='', ticksize=7, | |
780 | ytick_visible=False, nxticks=4, |
|
781 | ytick_visible=False, nxticks=4, | |
781 | grid='x') |
|
782 | grid='x') | |
782 |
|
783 | |||
783 | self.draw() |
|
784 | self.draw() | |
784 |
|
785 | |||
785 | if x[1] >= self.axesList[0].xmax: |
|
786 | if x[1] >= self.axesList[0].xmax: | |
786 | self.counter_imagwr = wr_period |
|
787 | self.counter_imagwr = wr_period | |
787 | self.__isConfig = False |
|
788 | self.__isConfig = False | |
788 | self.figfile = None |
|
789 | self.figfile = None | |
789 |
|
790 | |||
790 | self.save(figpath=figpath, |
|
791 | self.save(figpath=figpath, | |
791 | figfile=figfile, |
|
792 | figfile=figfile, | |
792 | save=save, |
|
793 | save=save, | |
793 | ftp=ftp, |
|
794 | ftp=ftp, | |
794 | wr_period=wr_period, |
|
795 | wr_period=wr_period, | |
795 | thisDatetime=thisDatetime, |
|
796 | thisDatetime=thisDatetime, | |
796 | update_figfile=False) |
|
797 | update_figfile=False) | |
797 |
|
798 | |||
798 | class PowerProfilePlot(Figure): |
|
799 | class PowerProfilePlot(Figure): | |
799 |
|
800 | |||
800 | isConfig = None |
|
801 | isConfig = None | |
801 | __nsubplots = None |
|
802 | __nsubplots = None | |
802 |
|
803 | |||
803 | WIDTHPROF = None |
|
804 | WIDTHPROF = None | |
804 | HEIGHTPROF = None |
|
805 | HEIGHTPROF = None | |
805 | PREFIX = 'spcprofile' |
|
806 | PREFIX = 'spcprofile' | |
806 |
|
807 | |||
807 | def __init__(self): |
|
808 | def __init__(self): | |
808 | self.isConfig = False |
|
809 | self.isConfig = False | |
809 | self.__nsubplots = 1 |
|
810 | self.__nsubplots = 1 | |
810 |
|
811 | |||
811 | self.PLOT_CODE = POWER_CODE |
|
812 | self.PLOT_CODE = POWER_CODE | |
812 |
|
813 | |||
813 | self.WIDTH = 300 |
|
814 | self.WIDTH = 300 | |
814 | self.HEIGHT = 500 |
|
815 | self.HEIGHT = 500 | |
815 | self.counter_imagwr = 0 |
|
816 | self.counter_imagwr = 0 | |
816 |
|
817 | |||
817 | def getSubplots(self): |
|
818 | def getSubplots(self): | |
818 | ncol = 1 |
|
819 | ncol = 1 | |
819 | nrow = 1 |
|
820 | nrow = 1 | |
820 |
|
821 | |||
821 | return nrow, ncol |
|
822 | return nrow, ncol | |
822 |
|
823 | |||
823 | def setup(self, id, nplots, wintitle, show): |
|
824 | def setup(self, id, nplots, wintitle, show): | |
824 |
|
825 | |||
825 | self.nplots = nplots |
|
826 | self.nplots = nplots | |
826 |
|
827 | |||
827 | ncolspan = 1 |
|
828 | ncolspan = 1 | |
828 | colspan = 1 |
|
829 | colspan = 1 | |
829 |
|
830 | |||
830 | self.createFigure(id = id, |
|
831 | self.createFigure(id = id, | |
831 | wintitle = wintitle, |
|
832 | wintitle = wintitle, | |
832 | widthplot = self.WIDTH, |
|
833 | widthplot = self.WIDTH, | |
833 | heightplot = self.HEIGHT, |
|
834 | heightplot = self.HEIGHT, | |
834 | show=show) |
|
835 | show=show) | |
835 |
|
836 | |||
836 | nrow, ncol = self.getSubplots() |
|
837 | nrow, ncol = self.getSubplots() | |
837 |
|
838 | |||
838 | counter = 0 |
|
839 | counter = 0 | |
839 | for y in range(nrow): |
|
840 | for y in range(nrow): | |
840 | for x in range(ncol): |
|
841 | for x in range(ncol): | |
841 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
842 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
842 |
|
843 | |||
843 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
844 | def run(self, dataOut, id, wintitle="", channelList=None, | |
844 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
845 | xmin=None, xmax=None, ymin=None, ymax=None, | |
845 | save=False, figpath='./', figfile=None, show=True, |
|
846 | save=False, figpath='./', figfile=None, show=True, | |
846 | ftp=False, wr_period=1, server=None, |
|
847 | ftp=False, wr_period=1, server=None, | |
847 | folder=None, username=None, password=None): |
|
848 | folder=None, username=None, password=None): | |
848 |
|
849 | |||
849 |
|
850 | |||
850 | if channelList == None: |
|
851 | if channelList == None: | |
851 | channelIndexList = dataOut.channelIndexList |
|
852 | channelIndexList = dataOut.channelIndexList | |
852 | channelList = dataOut.channelList |
|
853 | channelList = dataOut.channelList | |
853 | else: |
|
854 | else: | |
854 | channelIndexList = [] |
|
855 | channelIndexList = [] | |
855 | for channel in channelList: |
|
856 | for channel in channelList: | |
856 | if channel not in dataOut.channelList: |
|
857 | if channel not in dataOut.channelList: | |
857 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
858 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
858 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
859 | channelIndexList.append(dataOut.channelList.index(channel)) | |
859 |
|
860 | |||
860 | factor = dataOut.normFactor |
|
861 | factor = dataOut.normFactor | |
861 |
|
862 | |||
862 | y = dataOut.getHeiRange() |
|
863 | y = dataOut.getHeiRange() | |
863 |
|
864 | |||
864 | #for voltage |
|
865 | #for voltage | |
865 | if dataOut.type == 'Voltage': |
|
866 | if dataOut.type == 'Voltage': | |
866 | x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) |
|
867 | x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) | |
867 | x = x.real |
|
868 | x = x.real | |
868 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) |
|
869 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) | |
869 |
|
870 | |||
870 | #for spectra |
|
871 | #for spectra | |
871 | if dataOut.type == 'Spectra': |
|
872 | if dataOut.type == 'Spectra': | |
872 | x = dataOut.data_spc[channelIndexList,:,:]/factor |
|
873 | x = dataOut.data_spc[channelIndexList,:,:]/factor | |
873 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) |
|
874 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) | |
874 | x = numpy.average(x, axis=1) |
|
875 | x = numpy.average(x, axis=1) | |
875 |
|
876 | |||
876 |
|
877 | |||
877 | xdB = 10*numpy.log10(x) |
|
878 | xdB = 10*numpy.log10(x) | |
878 |
|
879 | |||
879 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
880 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | |
880 | title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
881 | title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
881 | xlabel = "dB" |
|
882 | xlabel = "dB" | |
882 | ylabel = "Range (Km)" |
|
883 | ylabel = "Range (Km)" | |
883 |
|
884 | |||
884 | if not self.isConfig: |
|
885 | if not self.isConfig: | |
885 |
|
886 | |||
886 | nplots = 1 |
|
887 | nplots = 1 | |
887 |
|
888 | |||
888 | self.setup(id=id, |
|
889 | self.setup(id=id, | |
889 | nplots=nplots, |
|
890 | nplots=nplots, | |
890 | wintitle=wintitle, |
|
891 | wintitle=wintitle, | |
891 | show=show) |
|
892 | show=show) | |
892 |
|
893 | |||
893 | if ymin == None: ymin = numpy.nanmin(y) |
|
894 | if ymin == None: ymin = numpy.nanmin(y) | |
894 | if ymax == None: ymax = numpy.nanmax(y) |
|
895 | if ymax == None: ymax = numpy.nanmax(y) | |
895 | if xmin == None: xmin = numpy.nanmin(xdB)*0.9 |
|
896 | if xmin == None: xmin = numpy.nanmin(xdB)*0.9 | |
896 | if xmax == None: xmax = numpy.nanmax(xdB)*1.1 |
|
897 | if xmax == None: xmax = numpy.nanmax(xdB)*1.1 | |
897 |
|
898 | |||
898 | self.__isConfig = True |
|
899 | self.__isConfig = True | |
899 |
|
900 | |||
900 | self.setWinTitle(title) |
|
901 | self.setWinTitle(title) | |
901 |
|
902 | |||
902 | title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
903 | title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
903 | axes = self.axesList[0] |
|
904 | axes = self.axesList[0] | |
904 |
|
905 | |||
905 | legendlabels = ["channel %d"%x for x in channelList] |
|
906 | legendlabels = ["channel %d"%x for x in channelList] | |
906 | axes.pmultiline(xdB, y, |
|
907 | axes.pmultiline(xdB, y, | |
907 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
908 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |
908 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, |
|
909 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, | |
909 | ytick_visible=True, nxticks=5, |
|
910 | ytick_visible=True, nxticks=5, | |
910 | grid='x') |
|
911 | grid='x') | |
911 |
|
912 | |||
912 | self.draw() |
|
913 | self.draw() | |
913 |
|
914 | |||
914 | self.save(figpath=figpath, |
|
915 | self.save(figpath=figpath, | |
915 | figfile=figfile, |
|
916 | figfile=figfile, | |
916 | save=save, |
|
917 | save=save, | |
917 | ftp=ftp, |
|
918 | ftp=ftp, | |
918 | wr_period=wr_period, |
|
919 | wr_period=wr_period, | |
919 | thisDatetime=thisDatetime) |
|
920 | thisDatetime=thisDatetime) | |
920 |
|
921 | |||
921 | class Noise(Figure): |
|
922 | class Noise(Figure): | |
922 |
|
923 | |||
923 | isConfig = None |
|
924 | isConfig = None | |
924 | __nsubplots = None |
|
925 | __nsubplots = None | |
925 |
|
926 | |||
926 | PREFIX = 'noise' |
|
927 | PREFIX = 'noise' | |
927 |
|
928 | |||
928 | def __init__(self): |
|
929 | def __init__(self): | |
929 |
|
930 | |||
930 | self.timerange = 24*60*60 |
|
931 | self.timerange = 24*60*60 | |
931 | self.isConfig = False |
|
932 | self.isConfig = False | |
932 | self.__nsubplots = 1 |
|
933 | self.__nsubplots = 1 | |
933 | self.counter_imagwr = 0 |
|
934 | self.counter_imagwr = 0 | |
934 | self.WIDTH = 600 |
|
935 | self.WIDTH = 600 | |
935 | self.HEIGHT = 300 |
|
936 | self.HEIGHT = 300 | |
936 | self.WIDTHPROF = 120 |
|
937 | self.WIDTHPROF = 120 | |
937 | self.HEIGHTPROF = 0 |
|
938 | self.HEIGHTPROF = 0 | |
938 | self.xdata = None |
|
939 | self.xdata = None | |
939 | self.ydata = None |
|
940 | self.ydata = None | |
940 |
|
941 | |||
941 | self.PLOT_CODE = NOISE_CODE |
|
942 | self.PLOT_CODE = NOISE_CODE | |
942 |
|
943 | |||
943 | self.FTP_WEI = None |
|
944 | self.FTP_WEI = None | |
944 | self.EXP_CODE = None |
|
945 | self.EXP_CODE = None | |
945 | self.SUB_EXP_CODE = None |
|
946 | self.SUB_EXP_CODE = None | |
946 | self.PLOT_POS = None |
|
947 | self.PLOT_POS = None | |
947 | self.figfile = None |
|
948 | self.figfile = None | |
948 |
|
949 | |||
949 | self.xmin = None |
|
950 | self.xmin = None | |
950 | self.xmax = None |
|
951 | self.xmax = None | |
951 |
|
952 | |||
952 | def getSubplots(self): |
|
953 | def getSubplots(self): | |
953 |
|
954 | |||
954 | ncol = 1 |
|
955 | ncol = 1 | |
955 | nrow = 1 |
|
956 | nrow = 1 | |
956 |
|
957 | |||
957 | return nrow, ncol |
|
958 | return nrow, ncol | |
958 |
|
959 | |||
959 | def openfile(self, filename): |
|
960 | def openfile(self, filename): | |
960 | dirname = os.path.dirname(filename) |
|
961 | dirname = os.path.dirname(filename) | |
961 |
|
962 | |||
962 | if not os.path.exists(dirname): |
|
963 | if not os.path.exists(dirname): | |
963 | os.mkdir(dirname) |
|
964 | os.mkdir(dirname) | |
964 |
|
965 | |||
965 | f = open(filename,'w+') |
|
966 | f = open(filename,'w+') | |
966 | f.write('\n\n') |
|
967 | f.write('\n\n') | |
967 | f.write('JICAMARCA RADIO OBSERVATORY - Noise \n') |
|
968 | f.write('JICAMARCA RADIO OBSERVATORY - Noise \n') | |
968 | f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' ) |
|
969 | f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' ) | |
969 | f.close() |
|
970 | f.close() | |
970 |
|
971 | |||
971 | def save_data(self, filename_phase, data, data_datetime): |
|
972 | def save_data(self, filename_phase, data, data_datetime): | |
972 | f=open(filename_phase,'a') |
|
973 | f=open(filename_phase,'a') | |
973 | timetuple_data = data_datetime.timetuple() |
|
974 | timetuple_data = data_datetime.timetuple() | |
974 | day = str(timetuple_data.tm_mday) |
|
975 | day = str(timetuple_data.tm_mday) | |
975 | month = str(timetuple_data.tm_mon) |
|
976 | month = str(timetuple_data.tm_mon) | |
976 | year = str(timetuple_data.tm_year) |
|
977 | year = str(timetuple_data.tm_year) | |
977 | hour = str(timetuple_data.tm_hour) |
|
978 | hour = str(timetuple_data.tm_hour) | |
978 | minute = str(timetuple_data.tm_min) |
|
979 | minute = str(timetuple_data.tm_min) | |
979 | second = str(timetuple_data.tm_sec) |
|
980 | second = str(timetuple_data.tm_sec) | |
980 |
|
981 | |||
981 | data_msg = '' |
|
982 | data_msg = '' | |
982 | for i in range(len(data)): |
|
983 | for i in range(len(data)): | |
983 | data_msg += str(data[i]) + ' ' |
|
984 | data_msg += str(data[i]) + ' ' | |
984 |
|
985 | |||
985 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' ' + data_msg + '\n') |
|
986 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' ' + data_msg + '\n') | |
986 | f.close() |
|
987 | f.close() | |
987 |
|
988 | |||
988 |
|
989 | |||
989 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
990 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
990 |
|
991 | |||
991 | self.__showprofile = showprofile |
|
992 | self.__showprofile = showprofile | |
992 | self.nplots = nplots |
|
993 | self.nplots = nplots | |
993 |
|
994 | |||
994 | ncolspan = 7 |
|
995 | ncolspan = 7 | |
995 | colspan = 6 |
|
996 | colspan = 6 | |
996 | self.__nsubplots = 2 |
|
997 | self.__nsubplots = 2 | |
997 |
|
998 | |||
998 | self.createFigure(id = id, |
|
999 | self.createFigure(id = id, | |
999 | wintitle = wintitle, |
|
1000 | wintitle = wintitle, | |
1000 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1001 | widthplot = self.WIDTH+self.WIDTHPROF, | |
1001 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1002 | heightplot = self.HEIGHT+self.HEIGHTPROF, | |
1002 | show=show) |
|
1003 | show=show) | |
1003 |
|
1004 | |||
1004 | nrow, ncol = self.getSubplots() |
|
1005 | nrow, ncol = self.getSubplots() | |
1005 |
|
1006 | |||
1006 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1007 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) | |
1007 |
|
1008 | |||
1008 |
|
1009 | |||
1009 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
1010 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', | |
1010 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1011 | xmin=None, xmax=None, ymin=None, ymax=None, | |
1011 | timerange=None, |
|
1012 | timerange=None, | |
1012 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
1013 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, | |
1013 | server=None, folder=None, username=None, password=None, |
|
1014 | server=None, folder=None, username=None, password=None, | |
1014 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1015 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): | |
1015 |
|
1016 | |||
1016 | if channelList == None: |
|
1017 | if channelList == None: | |
1017 | channelIndexList = dataOut.channelIndexList |
|
1018 | channelIndexList = dataOut.channelIndexList | |
1018 | channelList = dataOut.channelList |
|
1019 | channelList = dataOut.channelList | |
1019 | else: |
|
1020 | else: | |
1020 | channelIndexList = [] |
|
1021 | channelIndexList = [] | |
1021 | for channel in channelList: |
|
1022 | for channel in channelList: | |
1022 | if channel not in dataOut.channelList: |
|
1023 | if channel not in dataOut.channelList: | |
1023 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
1024 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
1024 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1025 | channelIndexList.append(dataOut.channelList.index(channel)) | |
1025 |
|
1026 | |||
1026 | x = dataOut.getTimeRange() |
|
1027 | x = dataOut.getTimeRange() | |
1027 | #y = dataOut.getHeiRange() |
|
1028 | #y = dataOut.getHeiRange() | |
1028 | factor = dataOut.normFactor |
|
1029 | factor = dataOut.normFactor | |
1029 | noise = dataOut.noise/factor |
|
1030 | noise = dataOut.noise/factor | |
1030 | noisedB = 10*numpy.log10(noise) |
|
1031 | noisedB = 10*numpy.log10(noise) | |
1031 |
|
1032 | |||
1032 | #thisDatetime = dataOut.datatime |
|
1033 | #thisDatetime = dataOut.datatime | |
1033 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
1034 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | |
1034 | title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1035 | title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
1035 | xlabel = "" |
|
1036 | xlabel = "" | |
1036 | ylabel = "Intensity (dB)" |
|
1037 | ylabel = "Intensity (dB)" | |
1037 |
|
1038 | |||
1038 | if not self.isConfig: |
|
1039 | if not self.isConfig: | |
1039 |
|
1040 | |||
1040 | nplots = 1 |
|
1041 | nplots = 1 | |
1041 |
|
1042 | |||
1042 | self.setup(id=id, |
|
1043 | self.setup(id=id, | |
1043 | nplots=nplots, |
|
1044 | nplots=nplots, | |
1044 | wintitle=wintitle, |
|
1045 | wintitle=wintitle, | |
1045 | showprofile=showprofile, |
|
1046 | showprofile=showprofile, | |
1046 | show=show) |
|
1047 | show=show) | |
1047 |
|
1048 | |||
1048 | if timerange != None: |
|
1049 | if timerange != None: | |
1049 | self.timerange = timerange |
|
1050 | self.timerange = timerange | |
1050 |
|
1051 | |||
1051 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
1052 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) | |
1052 |
|
1053 | |||
1053 | if ymin == None: ymin = numpy.floor(numpy.nanmin(noisedB)) - 10.0 |
|
1054 | if ymin == None: ymin = numpy.floor(numpy.nanmin(noisedB)) - 10.0 | |
1054 | if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0 |
|
1055 | if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0 | |
1055 |
|
1056 | |||
1056 | self.FTP_WEI = ftp_wei |
|
1057 | self.FTP_WEI = ftp_wei | |
1057 | self.EXP_CODE = exp_code |
|
1058 | self.EXP_CODE = exp_code | |
1058 | self.SUB_EXP_CODE = sub_exp_code |
|
1059 | self.SUB_EXP_CODE = sub_exp_code | |
1059 | self.PLOT_POS = plot_pos |
|
1060 | self.PLOT_POS = plot_pos | |
1060 |
|
1061 | |||
1061 |
|
1062 | |||
1062 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1063 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
1063 | self.isConfig = True |
|
1064 | self.isConfig = True | |
1064 | self.figfile = figfile |
|
1065 | self.figfile = figfile | |
1065 | self.xdata = numpy.array([]) |
|
1066 | self.xdata = numpy.array([]) | |
1066 | self.ydata = numpy.array([]) |
|
1067 | self.ydata = numpy.array([]) | |
1067 |
|
1068 | |||
1068 | #open file beacon phase |
|
1069 | #open file beacon phase | |
1069 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1070 | path = '%s%03d' %(self.PREFIX, self.id) | |
1070 | noise_file = os.path.join(path,'%s.txt'%self.name) |
|
1071 | noise_file = os.path.join(path,'%s.txt'%self.name) | |
1071 | self.filename_noise = os.path.join(figpath,noise_file) |
|
1072 | self.filename_noise = os.path.join(figpath,noise_file) | |
1072 | if save: |
|
1073 | if save: | |
1073 | self.openfile(self.filename_noise) |
|
1074 | self.openfile(self.filename_noise) | |
1074 |
|
1075 | |||
1075 |
|
1076 | |||
1076 | #store data beacon phase |
|
1077 | #store data beacon phase | |
1077 | if save: |
|
1078 | if save: | |
1078 | self.save_data(self.filename_noise, noisedB, thisDatetime) |
|
1079 | self.save_data(self.filename_noise, noisedB, thisDatetime) | |
1079 |
|
1080 | |||
1080 |
|
1081 | |||
1081 | self.setWinTitle(title) |
|
1082 | self.setWinTitle(title) | |
1082 |
|
1083 | |||
1083 |
|
1084 | |||
1084 | title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1085 | title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
1085 |
|
1086 | |||
1086 | legendlabels = ["channel %d"%(idchannel+1) for idchannel in channelList] |
|
1087 | legendlabels = ["channel %d"%(idchannel+1) for idchannel in channelList] | |
1087 | axes = self.axesList[0] |
|
1088 | axes = self.axesList[0] | |
1088 |
|
1089 | |||
1089 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1090 | self.xdata = numpy.hstack((self.xdata, x[0:1])) | |
1090 |
|
1091 | |||
1091 | if len(self.ydata)==0: |
|
1092 | if len(self.ydata)==0: | |
1092 | self.ydata = noisedB[channelIndexList].reshape(-1,1) |
|
1093 | self.ydata = noisedB[channelIndexList].reshape(-1,1) | |
1093 | else: |
|
1094 | else: | |
1094 | self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1))) |
|
1095 | self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1))) | |
1095 |
|
1096 | |||
1096 |
|
1097 | |||
1097 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1098 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, | |
1098 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, |
|
1099 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, | |
1099 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
1100 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", | |
1100 | XAxisAsTime=True, grid='both' |
|
1101 | XAxisAsTime=True, grid='both' | |
1101 | ) |
|
1102 | ) | |
1102 |
|
1103 | |||
1103 | self.draw() |
|
1104 | self.draw() | |
1104 |
|
1105 | |||
1105 | if x[1] >= self.axesList[0].xmax: |
|
1106 | if x[1] >= self.axesList[0].xmax: | |
1106 | self.counter_imagwr = wr_period |
|
1107 | self.counter_imagwr = wr_period | |
1107 | del self.xdata |
|
1108 | del self.xdata | |
1108 | del self.ydata |
|
1109 | del self.ydata | |
1109 | self.__isConfig = False |
|
1110 | self.__isConfig = False | |
1110 | self.figfile = None |
|
1111 | self.figfile = None | |
1111 |
|
1112 | |||
1112 | self.save(figpath=figpath, |
|
1113 | self.save(figpath=figpath, | |
1113 | figfile=figfile, |
|
1114 | figfile=figfile, | |
1114 | save=save, |
|
1115 | save=save, | |
1115 | ftp=ftp, |
|
1116 | ftp=ftp, | |
1116 | wr_period=wr_period, |
|
1117 | wr_period=wr_period, | |
1117 | thisDatetime=thisDatetime, |
|
1118 | thisDatetime=thisDatetime, | |
1118 | update_figfile=False) |
|
1119 | update_figfile=False) | |
1119 |
|
1120 | |||
1120 |
|
1121 | |||
1121 | class BeaconPhase(Figure): |
|
1122 | class BeaconPhase(Figure): | |
1122 |
|
1123 | |||
1123 | __isConfig = None |
|
1124 | __isConfig = None | |
1124 | __nsubplots = None |
|
1125 | __nsubplots = None | |
1125 |
|
1126 | |||
1126 | PREFIX = 'beacon_phase' |
|
1127 | PREFIX = 'beacon_phase' | |
1127 |
|
1128 | |||
1128 | def __init__(self): |
|
1129 | def __init__(self): | |
1129 |
|
1130 | |||
1130 | self.timerange = 24*60*60 |
|
1131 | self.timerange = 24*60*60 | |
1131 | self.__isConfig = False |
|
1132 | self.__isConfig = False | |
1132 | self.__nsubplots = 1 |
|
1133 | self.__nsubplots = 1 | |
1133 | self.counter_imagwr = 0 |
|
1134 | self.counter_imagwr = 0 | |
1134 | self.WIDTH = 600 |
|
1135 | self.WIDTH = 600 | |
1135 | self.HEIGHT = 300 |
|
1136 | self.HEIGHT = 300 | |
1136 | self.WIDTHPROF = 120 |
|
1137 | self.WIDTHPROF = 120 | |
1137 | self.HEIGHTPROF = 0 |
|
1138 | self.HEIGHTPROF = 0 | |
1138 | self.xdata = None |
|
1139 | self.xdata = None | |
1139 | self.ydata = None |
|
1140 | self.ydata = None | |
1140 |
|
1141 | |||
1141 | self.PLOT_CODE = BEACON_CODE |
|
1142 | self.PLOT_CODE = BEACON_CODE | |
1142 |
|
1143 | |||
1143 | self.FTP_WEI = None |
|
1144 | self.FTP_WEI = None | |
1144 | self.EXP_CODE = None |
|
1145 | self.EXP_CODE = None | |
1145 | self.SUB_EXP_CODE = None |
|
1146 | self.SUB_EXP_CODE = None | |
1146 | self.PLOT_POS = None |
|
1147 | self.PLOT_POS = None | |
1147 |
|
1148 | |||
1148 | self.filename_phase = None |
|
1149 | self.filename_phase = None | |
1149 |
|
1150 | |||
1150 | self.figfile = None |
|
1151 | self.figfile = None | |
1151 |
|
1152 | |||
1152 | self.xmin = None |
|
1153 | self.xmin = None | |
1153 | self.xmax = None |
|
1154 | self.xmax = None | |
1154 |
|
1155 | |||
1155 | def getSubplots(self): |
|
1156 | def getSubplots(self): | |
1156 |
|
1157 | |||
1157 | ncol = 1 |
|
1158 | ncol = 1 | |
1158 | nrow = 1 |
|
1159 | nrow = 1 | |
1159 |
|
1160 | |||
1160 | return nrow, ncol |
|
1161 | return nrow, ncol | |
1161 |
|
1162 | |||
1162 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1163 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
1163 |
|
1164 | |||
1164 | self.__showprofile = showprofile |
|
1165 | self.__showprofile = showprofile | |
1165 | self.nplots = nplots |
|
1166 | self.nplots = nplots | |
1166 |
|
1167 | |||
1167 | ncolspan = 7 |
|
1168 | ncolspan = 7 | |
1168 | colspan = 6 |
|
1169 | colspan = 6 | |
1169 | self.__nsubplots = 2 |
|
1170 | self.__nsubplots = 2 | |
1170 |
|
1171 | |||
1171 | self.createFigure(id = id, |
|
1172 | self.createFigure(id = id, | |
1172 | wintitle = wintitle, |
|
1173 | wintitle = wintitle, | |
1173 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1174 | widthplot = self.WIDTH+self.WIDTHPROF, | |
1174 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1175 | heightplot = self.HEIGHT+self.HEIGHTPROF, | |
1175 | show=show) |
|
1176 | show=show) | |
1176 |
|
1177 | |||
1177 | nrow, ncol = self.getSubplots() |
|
1178 | nrow, ncol = self.getSubplots() | |
1178 |
|
1179 | |||
1179 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1180 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) | |
1180 |
|
1181 | |||
1181 | def save_phase(self, filename_phase): |
|
1182 | def save_phase(self, filename_phase): | |
1182 | f = open(filename_phase,'w+') |
|
1183 | f = open(filename_phase,'w+') | |
1183 | f.write('\n\n') |
|
1184 | f.write('\n\n') | |
1184 | f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n') |
|
1185 | f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n') | |
1185 | f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' ) |
|
1186 | f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' ) | |
1186 | f.close() |
|
1187 | f.close() | |
1187 |
|
1188 | |||
1188 | def save_data(self, filename_phase, data, data_datetime): |
|
1189 | def save_data(self, filename_phase, data, data_datetime): | |
1189 | f=open(filename_phase,'a') |
|
1190 | f=open(filename_phase,'a') | |
1190 | timetuple_data = data_datetime.timetuple() |
|
1191 | timetuple_data = data_datetime.timetuple() | |
1191 | day = str(timetuple_data.tm_mday) |
|
1192 | day = str(timetuple_data.tm_mday) | |
1192 | month = str(timetuple_data.tm_mon) |
|
1193 | month = str(timetuple_data.tm_mon) | |
1193 | year = str(timetuple_data.tm_year) |
|
1194 | year = str(timetuple_data.tm_year) | |
1194 | hour = str(timetuple_data.tm_hour) |
|
1195 | hour = str(timetuple_data.tm_hour) | |
1195 | minute = str(timetuple_data.tm_min) |
|
1196 | minute = str(timetuple_data.tm_min) | |
1196 | second = str(timetuple_data.tm_sec) |
|
1197 | second = str(timetuple_data.tm_sec) | |
1197 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n') |
|
1198 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n') | |
1198 | f.close() |
|
1199 | f.close() | |
1199 |
|
1200 | |||
1200 |
|
1201 | |||
1201 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', |
|
1202 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', | |
1202 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1203 | xmin=None, xmax=None, ymin=None, ymax=None, | |
1203 | timerange=None, |
|
1204 | timerange=None, | |
1204 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
1205 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, | |
1205 | server=None, folder=None, username=None, password=None, |
|
1206 | server=None, folder=None, username=None, password=None, | |
1206 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1207 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): | |
1207 |
|
1208 | |||
1208 | if pairsList == None: |
|
1209 | if pairsList == None: | |
1209 | pairsIndexList = dataOut.pairsIndexList |
|
1210 | pairsIndexList = dataOut.pairsIndexList | |
1210 | else: |
|
1211 | else: | |
1211 | pairsIndexList = [] |
|
1212 | pairsIndexList = [] | |
1212 | for pair in pairsList: |
|
1213 | for pair in pairsList: | |
1213 | if pair not in dataOut.pairsList: |
|
1214 | if pair not in dataOut.pairsList: | |
1214 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
1215 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) | |
1215 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
1216 | pairsIndexList.append(dataOut.pairsList.index(pair)) | |
1216 |
|
1217 | |||
1217 | if pairsIndexList == []: |
|
1218 | if pairsIndexList == []: | |
1218 | return |
|
1219 | return | |
1219 |
|
1220 | |||
1220 | # if len(pairsIndexList) > 4: |
|
1221 | # if len(pairsIndexList) > 4: | |
1221 | # pairsIndexList = pairsIndexList[0:4] |
|
1222 | # pairsIndexList = pairsIndexList[0:4] | |
1222 |
|
1223 | |||
1223 | x = dataOut.getTimeRange() |
|
1224 | x = dataOut.getTimeRange() | |
1224 | #y = dataOut.getHeiRange() |
|
1225 | #y = dataOut.getHeiRange() | |
1225 |
|
1226 | |||
1226 |
|
1227 | |||
1227 | #thisDatetime = dataOut.datatime |
|
1228 | #thisDatetime = dataOut.datatime | |
1228 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
1229 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | |
1229 | title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1230 | title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
1230 | xlabel = "Local Time" |
|
1231 | xlabel = "Local Time" | |
1231 | ylabel = "Phase" |
|
1232 | ylabel = "Phase" | |
1232 |
|
1233 | |||
1233 | nplots = len(pairsIndexList) |
|
1234 | nplots = len(pairsIndexList) | |
1234 | #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList))) |
|
1235 | #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList))) | |
1235 | phase_beacon = numpy.zeros(len(pairsIndexList)) |
|
1236 | phase_beacon = numpy.zeros(len(pairsIndexList)) | |
1236 | for i in range(nplots): |
|
1237 | for i in range(nplots): | |
1237 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
1238 | pair = dataOut.pairsList[pairsIndexList[i]] | |
1238 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0) |
|
1239 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0) | |
1239 | powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0) |
|
1240 | powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0) | |
1240 | powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0) |
|
1241 | powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0) | |
1241 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) |
|
1242 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) | |
1242 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi |
|
1243 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi | |
1243 |
|
1244 | |||
1244 | #print "Phase %d%d" %(pair[0], pair[1]) |
|
1245 | #print "Phase %d%d" %(pair[0], pair[1]) | |
1245 | #print phase[dataOut.beacon_heiIndexList] |
|
1246 | #print phase[dataOut.beacon_heiIndexList] | |
1246 |
|
1247 | |||
1247 | phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList]) |
|
1248 | phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList]) | |
1248 |
|
1249 | |||
1249 | if not self.__isConfig: |
|
1250 | if not self.__isConfig: | |
1250 |
|
1251 | |||
1251 | nplots = len(pairsIndexList) |
|
1252 | nplots = len(pairsIndexList) | |
1252 |
|
1253 | |||
1253 | self.setup(id=id, |
|
1254 | self.setup(id=id, | |
1254 | nplots=nplots, |
|
1255 | nplots=nplots, | |
1255 | wintitle=wintitle, |
|
1256 | wintitle=wintitle, | |
1256 | showprofile=showprofile, |
|
1257 | showprofile=showprofile, | |
1257 | show=show) |
|
1258 | show=show) | |
1258 |
|
1259 | |||
1259 | if timerange != None: |
|
1260 | if timerange != None: | |
1260 | self.timerange = timerange |
|
1261 | self.timerange = timerange | |
1261 |
|
1262 | |||
1262 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
1263 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) | |
1263 |
|
1264 | |||
1264 | if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0 |
|
1265 | if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0 | |
1265 | if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0 |
|
1266 | if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0 | |
1266 |
|
1267 | |||
1267 | self.FTP_WEI = ftp_wei |
|
1268 | self.FTP_WEI = ftp_wei | |
1268 | self.EXP_CODE = exp_code |
|
1269 | self.EXP_CODE = exp_code | |
1269 | self.SUB_EXP_CODE = sub_exp_code |
|
1270 | self.SUB_EXP_CODE = sub_exp_code | |
1270 | self.PLOT_POS = plot_pos |
|
1271 | self.PLOT_POS = plot_pos | |
1271 |
|
1272 | |||
1272 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1273 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
1273 | self.__isConfig = True |
|
1274 | self.__isConfig = True | |
1274 | self.figfile = figfile |
|
1275 | self.figfile = figfile | |
1275 | self.xdata = numpy.array([]) |
|
1276 | self.xdata = numpy.array([]) | |
1276 | self.ydata = numpy.array([]) |
|
1277 | self.ydata = numpy.array([]) | |
1277 |
|
1278 | |||
1278 | #open file beacon phase |
|
1279 | #open file beacon phase | |
1279 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1280 | path = '%s%03d' %(self.PREFIX, self.id) | |
1280 | beacon_file = os.path.join(path,'%s.txt'%self.name) |
|
1281 | beacon_file = os.path.join(path,'%s.txt'%self.name) | |
1281 | self.filename_phase = os.path.join(figpath,beacon_file) |
|
1282 | self.filename_phase = os.path.join(figpath,beacon_file) | |
1282 | #self.save_phase(self.filename_phase) |
|
1283 | #self.save_phase(self.filename_phase) | |
1283 |
|
1284 | |||
1284 |
|
1285 | |||
1285 | #store data beacon phase |
|
1286 | #store data beacon phase | |
1286 | #self.save_data(self.filename_phase, phase_beacon, thisDatetime) |
|
1287 | #self.save_data(self.filename_phase, phase_beacon, thisDatetime) | |
1287 |
|
1288 | |||
1288 | self.setWinTitle(title) |
|
1289 | self.setWinTitle(title) | |
1289 |
|
1290 | |||
1290 |
|
1291 | |||
1291 | title = "Beacon Signal %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1292 | title = "Beacon Signal %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
1292 |
|
1293 | |||
1293 | legendlabels = ["pairs %d%d"%(pair[0], pair[1]) for pair in dataOut.pairsList] |
|
1294 | legendlabels = ["pairs %d%d"%(pair[0], pair[1]) for pair in dataOut.pairsList] | |
1294 |
|
1295 | |||
1295 | axes = self.axesList[0] |
|
1296 | axes = self.axesList[0] | |
1296 |
|
1297 | |||
1297 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1298 | self.xdata = numpy.hstack((self.xdata, x[0:1])) | |
1298 |
|
1299 | |||
1299 | if len(self.ydata)==0: |
|
1300 | if len(self.ydata)==0: | |
1300 | self.ydata = phase_beacon.reshape(-1,1) |
|
1301 | self.ydata = phase_beacon.reshape(-1,1) | |
1301 | else: |
|
1302 | else: | |
1302 | self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1))) |
|
1303 | self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1))) | |
1303 |
|
1304 | |||
1304 |
|
1305 | |||
1305 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1306 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, | |
1306 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, |
|
1307 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, | |
1307 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
1308 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", | |
1308 | XAxisAsTime=True, grid='both' |
|
1309 | XAxisAsTime=True, grid='both' | |
1309 | ) |
|
1310 | ) | |
1310 |
|
1311 | |||
1311 | self.draw() |
|
1312 | self.draw() | |
1312 |
|
1313 | |||
1313 | if x[1] >= self.axesList[0].xmax: |
|
1314 | if x[1] >= self.axesList[0].xmax: | |
1314 | self.counter_imagwr = wr_period |
|
1315 | self.counter_imagwr = wr_period | |
1315 | del self.xdata |
|
1316 | del self.xdata | |
1316 | del self.ydata |
|
1317 | del self.ydata | |
1317 | self.__isConfig = False |
|
1318 | self.__isConfig = False | |
1318 | self.figfile = None |
|
1319 | self.figfile = None | |
1319 |
|
1320 | |||
1320 | self.save(figpath=figpath, |
|
1321 | self.save(figpath=figpath, | |
1321 | figfile=figfile, |
|
1322 | figfile=figfile, | |
1322 | save=save, |
|
1323 | save=save, | |
1323 | ftp=ftp, |
|
1324 | ftp=ftp, | |
1324 | wr_period=wr_period, |
|
1325 | wr_period=wr_period, | |
1325 | thisDatetime=thisDatetime, |
|
1326 | thisDatetime=thisDatetime, | |
1326 | update_figfile=False) |
|
1327 | update_figfile=False) |
@@ -1,425 +1,435 | |||||
1 | import numpy |
|
1 | import numpy | |
2 | import datetime |
|
2 | import datetime | |
3 | import sys |
|
3 | import sys | |
4 | import matplotlib |
|
4 | import matplotlib | |
5 |
|
5 | |||
6 | if 'linux' in sys.platform: |
|
6 | if 'linux' in sys.platform: | |
7 | matplotlib.use("TKAgg") |
|
7 | matplotlib.use("TKAgg") | |
8 |
|
8 | |||
9 | if 'darwin' in sys.platform: |
|
9 | if 'darwin' in sys.platform: | |
10 | matplotlib.use("WXAgg") |
|
10 | matplotlib.use("WXAgg") | |
11 | #Qt4Agg', 'GTK', 'GTKAgg', 'ps', 'agg', 'cairo', 'MacOSX', 'GTKCairo', 'WXAgg', 'template', 'TkAgg', 'GTK3Cairo', 'GTK3Agg', 'svg', 'WebAgg', 'CocoaAgg', 'emf', 'gdk', 'WX' |
|
11 | #Qt4Agg', 'GTK', 'GTKAgg', 'ps', 'agg', 'cairo', 'MacOSX', 'GTKCairo', 'WXAgg', 'template', 'TkAgg', 'GTK3Cairo', 'GTK3Agg', 'svg', 'WebAgg', 'CocoaAgg', 'emf', 'gdk', 'WX' | |
12 | import matplotlib.pyplot |
|
12 | import matplotlib.pyplot | |
13 |
|
13 | |||
14 | from mpl_toolkits.axes_grid1 import make_axes_locatable |
|
14 | from mpl_toolkits.axes_grid1 import make_axes_locatable | |
15 | from matplotlib.ticker import * |
|
15 | from matplotlib.ticker import * | |
16 |
|
16 | |||
17 | ########################################### |
|
17 | ########################################### | |
18 | #Actualizacion de las funciones del driver |
|
18 | #Actualizacion de las funciones del driver | |
19 | ########################################### |
|
19 | ########################################### | |
20 |
|
20 | |||
21 | def createFigure(id, wintitle, width, height, facecolor="w", show=True): |
|
21 | def createFigure(id, wintitle, width, height, facecolor="w", show=True): | |
22 |
|
22 | |||
23 | matplotlib.pyplot.ioff() |
|
23 | matplotlib.pyplot.ioff() | |
24 | fig = matplotlib.pyplot.figure(num=id, facecolor=facecolor) |
|
24 | fig = matplotlib.pyplot.figure(num=id, facecolor=facecolor) | |
25 | fig.canvas.manager.set_window_title(wintitle) |
|
25 | fig.canvas.manager.set_window_title(wintitle) | |
26 | fig.canvas.manager.resize(width, height) |
|
26 | fig.canvas.manager.resize(width, height) | |
27 | matplotlib.pyplot.ion() |
|
27 | matplotlib.pyplot.ion() | |
28 | if show: |
|
28 | if show: | |
29 | matplotlib.pyplot.show() |
|
29 | matplotlib.pyplot.show() | |
30 |
|
30 | |||
31 | return fig |
|
31 | return fig | |
32 |
|
32 | |||
33 | def closeFigure(show=False): |
|
33 | def closeFigure(show=False, fig=None): | |
34 |
|
34 | |||
35 | matplotlib.pyplot.ioff() |
|
35 | matplotlib.pyplot.ioff() | |
|
36 | matplotlib.pyplot.pause(0.1) | |||
|
37 | ||||
36 | if show: |
|
38 | if show: | |
37 | matplotlib.pyplot.show() |
|
39 | matplotlib.pyplot.show() | |
38 |
|
|
40 | ||
39 | matplotlib.pyplot.close() |
|
41 | if fig != None: | |
|
42 | matplotlib.pyplot.close(fig) | |||
|
43 | matplotlib.pyplot.pause(0.1) | |||
|
44 | matplotlib.pyplot.ion() | |||
|
45 | return | |||
|
46 | ||||
|
47 | matplotlib.pyplot.close("all") | |||
|
48 | matplotlib.pyplot.pause(0.1) | |||
|
49 | matplotlib.pyplot.ion() | |||
40 | return |
|
50 | return | |
41 |
|
51 | |||
42 | def saveFigure(fig, filename): |
|
52 | def saveFigure(fig, filename): | |
43 |
|
53 | |||
44 | matplotlib.pyplot.ioff() |
|
54 | matplotlib.pyplot.ioff() | |
45 | fig.savefig(filename) |
|
55 | fig.savefig(filename) | |
46 | matplotlib.pyplot.ion() |
|
56 | matplotlib.pyplot.ion() | |
47 |
|
57 | |||
48 | def setWinTitle(fig, title): |
|
58 | def setWinTitle(fig, title): | |
49 |
|
59 | |||
50 | fig.canvas.manager.set_window_title(title) |
|
60 | fig.canvas.manager.set_window_title(title) | |
51 |
|
61 | |||
52 | def setTitle(fig, title): |
|
62 | def setTitle(fig, title): | |
53 |
|
63 | |||
54 | fig.suptitle(title) |
|
64 | fig.suptitle(title) | |
55 |
|
65 | |||
56 | def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan, polar=False): |
|
66 | def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan, polar=False): | |
57 |
|
67 | |||
58 | matplotlib.pyplot.ioff() |
|
68 | matplotlib.pyplot.ioff() | |
59 | matplotlib.pyplot.figure(fig.number) |
|
69 | matplotlib.pyplot.figure(fig.number) | |
60 | axes = matplotlib.pyplot.subplot2grid((nrow, ncol), |
|
70 | axes = matplotlib.pyplot.subplot2grid((nrow, ncol), | |
61 | (xpos, ypos), |
|
71 | (xpos, ypos), | |
62 | colspan=colspan, |
|
72 | colspan=colspan, | |
63 | rowspan=rowspan, |
|
73 | rowspan=rowspan, | |
64 | polar=polar) |
|
74 | polar=polar) | |
65 |
|
75 | |||
66 | matplotlib.pyplot.ion() |
|
76 | matplotlib.pyplot.ion() | |
67 | return axes |
|
77 | return axes | |
68 |
|
78 | |||
69 | def setAxesText(ax, text): |
|
79 | def setAxesText(ax, text): | |
70 |
|
80 | |||
71 | ax.annotate(text, |
|
81 | ax.annotate(text, | |
72 | xy = (.1, .99), |
|
82 | xy = (.1, .99), | |
73 | xycoords = 'figure fraction', |
|
83 | xycoords = 'figure fraction', | |
74 | horizontalalignment = 'left', |
|
84 | horizontalalignment = 'left', | |
75 | verticalalignment = 'top', |
|
85 | verticalalignment = 'top', | |
76 | fontsize = 10) |
|
86 | fontsize = 10) | |
77 |
|
87 | |||
78 | def printLabels(ax, xlabel, ylabel, title): |
|
88 | def printLabels(ax, xlabel, ylabel, title): | |
79 |
|
89 | |||
80 | ax.set_xlabel(xlabel, size=11) |
|
90 | ax.set_xlabel(xlabel, size=11) | |
81 | ax.set_ylabel(ylabel, size=11) |
|
91 | ax.set_ylabel(ylabel, size=11) | |
82 | ax.set_title(title, size=8) |
|
92 | ax.set_title(title, size=8) | |
83 |
|
93 | |||
84 | def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', |
|
94 | def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', | |
85 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
95 | ticksize=9, xtick_visible=True, ytick_visible=True, | |
86 | nxticks=4, nyticks=10, |
|
96 | nxticks=4, nyticks=10, | |
87 | grid=None,color='blue'): |
|
97 | grid=None,color='blue'): | |
88 |
|
98 | |||
89 | """ |
|
99 | """ | |
90 |
|
100 | |||
91 | Input: |
|
101 | Input: | |
92 | grid : None, 'both', 'x', 'y' |
|
102 | grid : None, 'both', 'x', 'y' | |
93 | """ |
|
103 | """ | |
94 |
|
104 | |||
95 | matplotlib.pyplot.ioff() |
|
105 | matplotlib.pyplot.ioff() | |
96 |
|
106 | |||
97 | ax.set_xlim([xmin,xmax]) |
|
107 | ax.set_xlim([xmin,xmax]) | |
98 | ax.set_ylim([ymin,ymax]) |
|
108 | ax.set_ylim([ymin,ymax]) | |
99 |
|
109 | |||
100 | printLabels(ax, xlabel, ylabel, title) |
|
110 | printLabels(ax, xlabel, ylabel, title) | |
101 |
|
111 | |||
102 | ###################################################### |
|
112 | ###################################################### | |
103 | if (xmax-xmin)<=1: |
|
113 | if (xmax-xmin)<=1: | |
104 | xtickspos = numpy.linspace(xmin,xmax,nxticks) |
|
114 | xtickspos = numpy.linspace(xmin,xmax,nxticks) | |
105 | xtickspos = numpy.array([float("%.1f"%i) for i in xtickspos]) |
|
115 | xtickspos = numpy.array([float("%.1f"%i) for i in xtickspos]) | |
106 | ax.set_xticks(xtickspos) |
|
116 | ax.set_xticks(xtickspos) | |
107 | else: |
|
117 | else: | |
108 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
|
118 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) | |
109 | # xtickspos = numpy.arange(nxticks)*float(xmax-xmin)/float(nxticks) + int(xmin) |
|
119 | # xtickspos = numpy.arange(nxticks)*float(xmax-xmin)/float(nxticks) + int(xmin) | |
110 | ax.set_xticks(xtickspos) |
|
120 | ax.set_xticks(xtickspos) | |
111 |
|
121 | |||
112 | for tick in ax.get_xticklabels(): |
|
122 | for tick in ax.get_xticklabels(): | |
113 | tick.set_visible(xtick_visible) |
|
123 | tick.set_visible(xtick_visible) | |
114 |
|
124 | |||
115 | for tick in ax.xaxis.get_major_ticks(): |
|
125 | for tick in ax.xaxis.get_major_ticks(): | |
116 | tick.label.set_fontsize(ticksize) |
|
126 | tick.label.set_fontsize(ticksize) | |
117 |
|
127 | |||
118 | ###################################################### |
|
128 | ###################################################### | |
119 | for tick in ax.get_yticklabels(): |
|
129 | for tick in ax.get_yticklabels(): | |
120 | tick.set_visible(ytick_visible) |
|
130 | tick.set_visible(ytick_visible) | |
121 |
|
131 | |||
122 | for tick in ax.yaxis.get_major_ticks(): |
|
132 | for tick in ax.yaxis.get_major_ticks(): | |
123 | tick.label.set_fontsize(ticksize) |
|
133 | tick.label.set_fontsize(ticksize) | |
124 |
|
134 | |||
125 | ax.plot(x, y, color=color) |
|
135 | ax.plot(x, y, color=color) | |
126 | iplot = ax.lines[-1] |
|
136 | iplot = ax.lines[-1] | |
127 |
|
137 | |||
128 | ###################################################### |
|
138 | ###################################################### | |
129 | if '0.' in matplotlib.__version__[0:2]: |
|
139 | if '0.' in matplotlib.__version__[0:2]: | |
130 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
140 | print "The matplotlib version has to be updated to 1.1 or newer" | |
131 | return iplot |
|
141 | return iplot | |
132 |
|
142 | |||
133 | if '1.0.' in matplotlib.__version__[0:4]: |
|
143 | if '1.0.' in matplotlib.__version__[0:4]: | |
134 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
144 | print "The matplotlib version has to be updated to 1.1 or newer" | |
135 | return iplot |
|
145 | return iplot | |
136 |
|
146 | |||
137 | if grid != None: |
|
147 | if grid != None: | |
138 | ax.grid(b=True, which='major', axis=grid) |
|
148 | ax.grid(b=True, which='major', axis=grid) | |
139 |
|
149 | |||
140 | matplotlib.pyplot.tight_layout() |
|
150 | matplotlib.pyplot.tight_layout() | |
141 |
|
151 | |||
142 | matplotlib.pyplot.ion() |
|
152 | matplotlib.pyplot.ion() | |
143 |
|
153 | |||
144 | return iplot |
|
154 | return iplot | |
145 |
|
155 | |||
146 | def set_linedata(ax, x, y, idline): |
|
156 | def set_linedata(ax, x, y, idline): | |
147 |
|
157 | |||
148 | ax.lines[idline].set_data(x,y) |
|
158 | ax.lines[idline].set_data(x,y) | |
149 |
|
159 | |||
150 | def pline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
160 | def pline(iplot, x, y, xlabel='', ylabel='', title=''): | |
151 |
|
161 | |||
152 | ax = iplot.get_axes() |
|
162 | ax = iplot.get_axes() | |
153 |
|
163 | |||
154 | printLabels(ax, xlabel, ylabel, title) |
|
164 | printLabels(ax, xlabel, ylabel, title) | |
155 |
|
165 | |||
156 | set_linedata(ax, x, y, idline=0) |
|
166 | set_linedata(ax, x, y, idline=0) | |
157 |
|
167 | |||
158 | def addpline(ax, x, y, color, linestyle, lw): |
|
168 | def addpline(ax, x, y, color, linestyle, lw): | |
159 |
|
169 | |||
160 | ax.plot(x,y,color=color,linestyle=linestyle,lw=lw) |
|
170 | ax.plot(x,y,color=color,linestyle=linestyle,lw=lw) | |
161 |
|
171 | |||
162 |
|
172 | |||
163 | def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, |
|
173 | def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, | |
164 | xlabel='', ylabel='', title='', ticksize = 9, |
|
174 | xlabel='', ylabel='', title='', ticksize = 9, | |
165 | colormap='jet',cblabel='', cbsize="5%", |
|
175 | colormap='jet',cblabel='', cbsize="5%", | |
166 | XAxisAsTime=False): |
|
176 | XAxisAsTime=False): | |
167 |
|
177 | |||
168 | matplotlib.pyplot.ioff() |
|
178 | matplotlib.pyplot.ioff() | |
169 |
|
179 | |||
170 | divider = make_axes_locatable(ax) |
|
180 | divider = make_axes_locatable(ax) | |
171 | ax_cb = divider.new_horizontal(size=cbsize, pad=0.05) |
|
181 | ax_cb = divider.new_horizontal(size=cbsize, pad=0.05) | |
172 | fig = ax.get_figure() |
|
182 | fig = ax.get_figure() | |
173 | fig.add_axes(ax_cb) |
|
183 | fig.add_axes(ax_cb) | |
174 |
|
184 | |||
175 | ax.set_xlim([xmin,xmax]) |
|
185 | ax.set_xlim([xmin,xmax]) | |
176 | ax.set_ylim([ymin,ymax]) |
|
186 | ax.set_ylim([ymin,ymax]) | |
177 |
|
187 | |||
178 | printLabels(ax, xlabel, ylabel, title) |
|
188 | printLabels(ax, xlabel, ylabel, title) | |
179 |
|
189 | |||
180 | imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) |
|
190 | imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) | |
181 | cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb) |
|
191 | cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb) | |
182 | cb.set_label(cblabel) |
|
192 | cb.set_label(cblabel) | |
183 |
|
193 | |||
184 | # for tl in ax_cb.get_yticklabels(): |
|
194 | # for tl in ax_cb.get_yticklabels(): | |
185 | # tl.set_visible(True) |
|
195 | # tl.set_visible(True) | |
186 |
|
196 | |||
187 | for tick in ax.yaxis.get_major_ticks(): |
|
197 | for tick in ax.yaxis.get_major_ticks(): | |
188 | tick.label.set_fontsize(ticksize) |
|
198 | tick.label.set_fontsize(ticksize) | |
189 |
|
199 | |||
190 | for tick in ax.xaxis.get_major_ticks(): |
|
200 | for tick in ax.xaxis.get_major_ticks(): | |
191 | tick.label.set_fontsize(ticksize) |
|
201 | tick.label.set_fontsize(ticksize) | |
192 |
|
202 | |||
193 | for tick in cb.ax.get_yticklabels(): |
|
203 | for tick in cb.ax.get_yticklabels(): | |
194 | tick.set_fontsize(ticksize) |
|
204 | tick.set_fontsize(ticksize) | |
195 |
|
205 | |||
196 | ax_cb.yaxis.tick_right() |
|
206 | ax_cb.yaxis.tick_right() | |
197 |
|
207 | |||
198 | if '0.' in matplotlib.__version__[0:2]: |
|
208 | if '0.' in matplotlib.__version__[0:2]: | |
199 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
209 | print "The matplotlib version has to be updated to 1.1 or newer" | |
200 | return imesh |
|
210 | return imesh | |
201 |
|
211 | |||
202 | if '1.0.' in matplotlib.__version__[0:4]: |
|
212 | if '1.0.' in matplotlib.__version__[0:4]: | |
203 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
213 | print "The matplotlib version has to be updated to 1.1 or newer" | |
204 | return imesh |
|
214 | return imesh | |
205 |
|
215 | |||
206 | matplotlib.pyplot.tight_layout() |
|
216 | matplotlib.pyplot.tight_layout() | |
207 |
|
217 | |||
208 | if XAxisAsTime: |
|
218 | if XAxisAsTime: | |
209 |
|
219 | |||
210 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) |
|
220 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) | |
211 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
221 | ax.xaxis.set_major_formatter(FuncFormatter(func)) | |
212 | ax.xaxis.set_major_locator(LinearLocator(7)) |
|
222 | ax.xaxis.set_major_locator(LinearLocator(7)) | |
213 |
|
223 | |||
214 | matplotlib.pyplot.ion() |
|
224 | matplotlib.pyplot.ion() | |
215 | return imesh |
|
225 | return imesh | |
216 |
|
226 | |||
217 | def pcolor(imesh, z, xlabel='', ylabel='', title=''): |
|
227 | def pcolor(imesh, z, xlabel='', ylabel='', title=''): | |
218 |
|
228 | |||
219 | z = z.T |
|
229 | z = z.T | |
220 | ax = imesh.get_axes() |
|
230 | ax = imesh.get_axes() | |
221 | printLabels(ax, xlabel, ylabel, title) |
|
231 | printLabels(ax, xlabel, ylabel, title) | |
222 | imesh.set_array(z.ravel()) |
|
232 | imesh.set_array(z.ravel()) | |
223 |
|
233 | |||
224 | def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): |
|
234 | def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): | |
225 |
|
235 | |||
226 | printLabels(ax, xlabel, ylabel, title) |
|
236 | printLabels(ax, xlabel, ylabel, title) | |
227 |
|
237 | |||
228 | ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) |
|
238 | ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) | |
229 |
|
239 | |||
230 | def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): |
|
240 | def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): | |
231 |
|
241 | |||
232 | printLabels(ax, xlabel, ylabel, title) |
|
242 | printLabels(ax, xlabel, ylabel, title) | |
233 |
|
243 | |||
234 | ax.collections.remove(ax.collections[0]) |
|
244 | ax.collections.remove(ax.collections[0]) | |
235 |
|
245 | |||
236 | ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) |
|
246 | ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) | |
237 |
|
247 | |||
238 | def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, |
|
248 | def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, | |
239 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
249 | ticksize=9, xtick_visible=True, ytick_visible=True, | |
240 | nxticks=4, nyticks=10, |
|
250 | nxticks=4, nyticks=10, | |
241 | grid=None): |
|
251 | grid=None): | |
242 |
|
252 | |||
243 | """ |
|
253 | """ | |
244 |
|
254 | |||
245 | Input: |
|
255 | Input: | |
246 | grid : None, 'both', 'x', 'y' |
|
256 | grid : None, 'both', 'x', 'y' | |
247 | """ |
|
257 | """ | |
248 |
|
258 | |||
249 | matplotlib.pyplot.ioff() |
|
259 | matplotlib.pyplot.ioff() | |
250 |
|
260 | |||
251 | lines = ax.plot(x.T, y) |
|
261 | lines = ax.plot(x.T, y) | |
252 | leg = ax.legend(lines, legendlabels, loc='upper right') |
|
262 | leg = ax.legend(lines, legendlabels, loc='upper right') | |
253 | leg.get_frame().set_alpha(0.5) |
|
263 | leg.get_frame().set_alpha(0.5) | |
254 | ax.set_xlim([xmin,xmax]) |
|
264 | ax.set_xlim([xmin,xmax]) | |
255 | ax.set_ylim([ymin,ymax]) |
|
265 | ax.set_ylim([ymin,ymax]) | |
256 | printLabels(ax, xlabel, ylabel, title) |
|
266 | printLabels(ax, xlabel, ylabel, title) | |
257 |
|
267 | |||
258 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
|
268 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) | |
259 | ax.set_xticks(xtickspos) |
|
269 | ax.set_xticks(xtickspos) | |
260 |
|
270 | |||
261 | for tick in ax.get_xticklabels(): |
|
271 | for tick in ax.get_xticklabels(): | |
262 | tick.set_visible(xtick_visible) |
|
272 | tick.set_visible(xtick_visible) | |
263 |
|
273 | |||
264 | for tick in ax.xaxis.get_major_ticks(): |
|
274 | for tick in ax.xaxis.get_major_ticks(): | |
265 | tick.label.set_fontsize(ticksize) |
|
275 | tick.label.set_fontsize(ticksize) | |
266 |
|
276 | |||
267 | for tick in ax.get_yticklabels(): |
|
277 | for tick in ax.get_yticklabels(): | |
268 | tick.set_visible(ytick_visible) |
|
278 | tick.set_visible(ytick_visible) | |
269 |
|
279 | |||
270 | for tick in ax.yaxis.get_major_ticks(): |
|
280 | for tick in ax.yaxis.get_major_ticks(): | |
271 | tick.label.set_fontsize(ticksize) |
|
281 | tick.label.set_fontsize(ticksize) | |
272 |
|
282 | |||
273 | iplot = ax.lines[-1] |
|
283 | iplot = ax.lines[-1] | |
274 |
|
284 | |||
275 | if '0.' in matplotlib.__version__[0:2]: |
|
285 | if '0.' in matplotlib.__version__[0:2]: | |
276 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
286 | print "The matplotlib version has to be updated to 1.1 or newer" | |
277 | return iplot |
|
287 | return iplot | |
278 |
|
288 | |||
279 | if '1.0.' in matplotlib.__version__[0:4]: |
|
289 | if '1.0.' in matplotlib.__version__[0:4]: | |
280 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
290 | print "The matplotlib version has to be updated to 1.1 or newer" | |
281 | return iplot |
|
291 | return iplot | |
282 |
|
292 | |||
283 | if grid != None: |
|
293 | if grid != None: | |
284 | ax.grid(b=True, which='major', axis=grid) |
|
294 | ax.grid(b=True, which='major', axis=grid) | |
285 |
|
295 | |||
286 | matplotlib.pyplot.tight_layout() |
|
296 | matplotlib.pyplot.tight_layout() | |
287 |
|
297 | |||
288 | matplotlib.pyplot.ion() |
|
298 | matplotlib.pyplot.ion() | |
289 |
|
299 | |||
290 | return iplot |
|
300 | return iplot | |
291 |
|
301 | |||
292 |
|
302 | |||
293 | def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
303 | def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''): | |
294 |
|
304 | |||
295 | ax = iplot.get_axes() |
|
305 | ax = iplot.get_axes() | |
296 |
|
306 | |||
297 | printLabels(ax, xlabel, ylabel, title) |
|
307 | printLabels(ax, xlabel, ylabel, title) | |
298 |
|
308 | |||
299 | for i in range(len(ax.lines)): |
|
309 | for i in range(len(ax.lines)): | |
300 | line = ax.lines[i] |
|
310 | line = ax.lines[i] | |
301 | line.set_data(x[i,:],y) |
|
311 | line.set_data(x[i,:],y) | |
302 |
|
312 | |||
303 | def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, |
|
313 | def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, | |
304 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
314 | ticksize=9, xtick_visible=True, ytick_visible=True, | |
305 | nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None", |
|
315 | nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None", | |
306 | grid=None, XAxisAsTime=False): |
|
316 | grid=None, XAxisAsTime=False): | |
307 |
|
317 | |||
308 | """ |
|
318 | """ | |
309 |
|
319 | |||
310 | Input: |
|
320 | Input: | |
311 | grid : None, 'both', 'x', 'y' |
|
321 | grid : None, 'both', 'x', 'y' | |
312 | """ |
|
322 | """ | |
313 |
|
323 | |||
314 | matplotlib.pyplot.ioff() |
|
324 | matplotlib.pyplot.ioff() | |
315 |
|
325 | |||
316 | # lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle) |
|
326 | # lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle) | |
317 | lines = ax.plot(x, y.T, linestyle=linestyle, marker=marker, markersize=markersize) |
|
327 | lines = ax.plot(x, y.T, linestyle=linestyle, marker=marker, markersize=markersize) | |
318 | leg = ax.legend(lines, legendlabels, loc='upper left', bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \ |
|
328 | leg = ax.legend(lines, legendlabels, loc='upper left', bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \ | |
319 | handletextpad=0.5, borderpad=0.5, labelspacing=0.5, borderaxespad=0.) |
|
329 | handletextpad=0.5, borderpad=0.5, labelspacing=0.5, borderaxespad=0.) | |
320 |
|
330 | |||
321 | for label in leg.get_texts(): label.set_fontsize(9) |
|
331 | for label in leg.get_texts(): label.set_fontsize(9) | |
322 |
|
332 | |||
323 | ax.set_xlim([xmin,xmax]) |
|
333 | ax.set_xlim([xmin,xmax]) | |
324 | ax.set_ylim([ymin,ymax]) |
|
334 | ax.set_ylim([ymin,ymax]) | |
325 | printLabels(ax, xlabel, ylabel, title) |
|
335 | printLabels(ax, xlabel, ylabel, title) | |
326 |
|
336 | |||
327 | # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
|
337 | # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) | |
328 | # ax.set_xticks(xtickspos) |
|
338 | # ax.set_xticks(xtickspos) | |
329 |
|
339 | |||
330 | for tick in ax.get_xticklabels(): |
|
340 | for tick in ax.get_xticklabels(): | |
331 | tick.set_visible(xtick_visible) |
|
341 | tick.set_visible(xtick_visible) | |
332 |
|
342 | |||
333 | for tick in ax.xaxis.get_major_ticks(): |
|
343 | for tick in ax.xaxis.get_major_ticks(): | |
334 | tick.label.set_fontsize(ticksize) |
|
344 | tick.label.set_fontsize(ticksize) | |
335 |
|
345 | |||
336 | for tick in ax.get_yticklabels(): |
|
346 | for tick in ax.get_yticklabels(): | |
337 | tick.set_visible(ytick_visible) |
|
347 | tick.set_visible(ytick_visible) | |
338 |
|
348 | |||
339 | for tick in ax.yaxis.get_major_ticks(): |
|
349 | for tick in ax.yaxis.get_major_ticks(): | |
340 | tick.label.set_fontsize(ticksize) |
|
350 | tick.label.set_fontsize(ticksize) | |
341 |
|
351 | |||
342 | iplot = ax.lines[-1] |
|
352 | iplot = ax.lines[-1] | |
343 |
|
353 | |||
344 | if '0.' in matplotlib.__version__[0:2]: |
|
354 | if '0.' in matplotlib.__version__[0:2]: | |
345 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
355 | print "The matplotlib version has to be updated to 1.1 or newer" | |
346 | return iplot |
|
356 | return iplot | |
347 |
|
357 | |||
348 | if '1.0.' in matplotlib.__version__[0:4]: |
|
358 | if '1.0.' in matplotlib.__version__[0:4]: | |
349 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
359 | print "The matplotlib version has to be updated to 1.1 or newer" | |
350 | return iplot |
|
360 | return iplot | |
351 |
|
361 | |||
352 | if grid != None: |
|
362 | if grid != None: | |
353 | ax.grid(b=True, which='major', axis=grid) |
|
363 | ax.grid(b=True, which='major', axis=grid) | |
354 |
|
364 | |||
355 | matplotlib.pyplot.tight_layout() |
|
365 | matplotlib.pyplot.tight_layout() | |
356 |
|
366 | |||
357 | if XAxisAsTime: |
|
367 | if XAxisAsTime: | |
358 |
|
368 | |||
359 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) |
|
369 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) | |
360 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
370 | ax.xaxis.set_major_formatter(FuncFormatter(func)) | |
361 | ax.xaxis.set_major_locator(LinearLocator(7)) |
|
371 | ax.xaxis.set_major_locator(LinearLocator(7)) | |
362 |
|
372 | |||
363 | matplotlib.pyplot.ion() |
|
373 | matplotlib.pyplot.ion() | |
364 |
|
374 | |||
365 | return iplot |
|
375 | return iplot | |
366 |
|
376 | |||
367 | def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''): |
|
377 | def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''): | |
368 |
|
378 | |||
369 | ax = iplot.get_axes() |
|
379 | ax = iplot.get_axes() | |
370 |
|
380 | |||
371 | printLabels(ax, xlabel, ylabel, title) |
|
381 | printLabels(ax, xlabel, ylabel, title) | |
372 |
|
382 | |||
373 | for i in range(len(ax.lines)): |
|
383 | for i in range(len(ax.lines)): | |
374 | line = ax.lines[i] |
|
384 | line = ax.lines[i] | |
375 | line.set_data(x,y[i,:]) |
|
385 | line.set_data(x,y[i,:]) | |
376 |
|
386 | |||
377 | def createPolar(ax, x, y, |
|
387 | def createPolar(ax, x, y, | |
378 | xlabel='', ylabel='', title='', ticksize = 9, |
|
388 | xlabel='', ylabel='', title='', ticksize = 9, | |
379 | colormap='jet',cblabel='', cbsize="5%", |
|
389 | colormap='jet',cblabel='', cbsize="5%", | |
380 | XAxisAsTime=False): |
|
390 | XAxisAsTime=False): | |
381 |
|
391 | |||
382 | matplotlib.pyplot.ioff() |
|
392 | matplotlib.pyplot.ioff() | |
383 |
|
393 | |||
384 | ax.plot(x,y,'bo', markersize=5) |
|
394 | ax.plot(x,y,'bo', markersize=5) | |
385 | # ax.set_rmax(90) |
|
395 | # ax.set_rmax(90) | |
386 | ax.set_ylim(0,90) |
|
396 | ax.set_ylim(0,90) | |
387 | ax.set_yticks(numpy.arange(0,90,20)) |
|
397 | ax.set_yticks(numpy.arange(0,90,20)) | |
388 | ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center' ,size='11') |
|
398 | ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center' ,size='11') | |
389 | # ax.text(100, 100, 'example', ha='left', va='center', rotation='vertical') |
|
399 | # ax.text(100, 100, 'example', ha='left', va='center', rotation='vertical') | |
390 | printLabels(ax, xlabel, '', title) |
|
400 | printLabels(ax, xlabel, '', title) | |
391 | iplot = ax.lines[-1] |
|
401 | iplot = ax.lines[-1] | |
392 |
|
402 | |||
393 | if '0.' in matplotlib.__version__[0:2]: |
|
403 | if '0.' in matplotlib.__version__[0:2]: | |
394 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
404 | print "The matplotlib version has to be updated to 1.1 or newer" | |
395 | return iplot |
|
405 | return iplot | |
396 |
|
406 | |||
397 | if '1.0.' in matplotlib.__version__[0:4]: |
|
407 | if '1.0.' in matplotlib.__version__[0:4]: | |
398 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
408 | print "The matplotlib version has to be updated to 1.1 or newer" | |
399 | return iplot |
|
409 | return iplot | |
400 |
|
410 | |||
401 | # if grid != None: |
|
411 | # if grid != None: | |
402 | # ax.grid(b=True, which='major', axis=grid) |
|
412 | # ax.grid(b=True, which='major', axis=grid) | |
403 |
|
413 | |||
404 | matplotlib.pyplot.tight_layout() |
|
414 | matplotlib.pyplot.tight_layout() | |
405 |
|
415 | |||
406 | matplotlib.pyplot.ion() |
|
416 | matplotlib.pyplot.ion() | |
407 |
|
417 | |||
408 |
|
418 | |||
409 | return iplot |
|
419 | return iplot | |
410 |
|
420 | |||
411 | def polar(iplot, x, y, xlabel='', ylabel='', title=''): |
|
421 | def polar(iplot, x, y, xlabel='', ylabel='', title=''): | |
412 |
|
422 | |||
413 | ax = iplot.get_axes() |
|
423 | ax = iplot.get_axes() | |
414 |
|
424 | |||
415 | # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center',size='11') |
|
425 | # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center',size='11') | |
416 | printLabels(ax, xlabel, '', title) |
|
426 | printLabels(ax, xlabel, '', title) | |
417 |
|
427 | |||
418 | set_linedata(ax, x, y, idline=0) |
|
428 | set_linedata(ax, x, y, idline=0) | |
419 |
|
429 | |||
420 | def draw(fig): |
|
430 | def draw(fig): | |
421 |
|
431 | |||
422 | if type(fig) == 'int': |
|
432 | if type(fig) == 'int': | |
423 |
raise ValueError, " |
|
433 | raise ValueError, "Error drawing: Fig parameter should be a matplotlib figure object figure" | |
424 |
|
434 | |||
425 | fig.canvas.draw() |
|
435 | fig.canvas.draw() |
@@ -1,687 +1,692 | |||||
1 | ''' |
|
1 | ''' | |
2 | @author: Daniel Suarez |
|
2 | @author: Daniel Suarez | |
3 | ''' |
|
3 | ''' | |
4 |
|
4 | |||
5 | import os |
|
5 | import os | |
6 | import sys |
|
6 | import sys | |
7 | import glob |
|
7 | import glob | |
8 | import fnmatch |
|
8 | import fnmatch | |
9 | import datetime |
|
9 | import datetime | |
10 | import time |
|
10 | import time | |
11 | import re |
|
11 | import re | |
12 | import h5py |
|
12 | import h5py | |
13 | import numpy |
|
13 | import numpy | |
14 |
|
14 | |||
15 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation |
|
15 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation | |
16 | from schainpy.model.data.jroamisr import AMISR |
|
16 | from schainpy.model.data.jroamisr import AMISR | |
17 |
|
17 | |||
|
18 | try: | |||
|
19 | from gevent import sleep | |||
|
20 | except: | |||
|
21 | from time import sleep | |||
|
22 | ||||
18 | class RadacHeader(): |
|
23 | class RadacHeader(): | |
19 | def __init__(self, fp): |
|
24 | def __init__(self, fp): | |
20 | header = 'Raw11/Data/RadacHeader' |
|
25 | header = 'Raw11/Data/RadacHeader' | |
21 | self.beamCodeByPulse = fp.get(header+'/BeamCode') |
|
26 | self.beamCodeByPulse = fp.get(header+'/BeamCode') | |
22 | self.beamCode = fp.get('Raw11/Data/Beamcodes') |
|
27 | self.beamCode = fp.get('Raw11/Data/Beamcodes') | |
23 | self.code = fp.get(header+'/Code') |
|
28 | self.code = fp.get(header+'/Code') | |
24 | self.frameCount = fp.get(header+'/FrameCount') |
|
29 | self.frameCount = fp.get(header+'/FrameCount') | |
25 | self.modeGroup = fp.get(header+'/ModeGroup') |
|
30 | self.modeGroup = fp.get(header+'/ModeGroup') | |
26 | self.nsamplesPulse = fp.get(header+'/NSamplesPulse') |
|
31 | self.nsamplesPulse = fp.get(header+'/NSamplesPulse') | |
27 | self.pulseCount = fp.get(header+'/PulseCount') |
|
32 | self.pulseCount = fp.get(header+'/PulseCount') | |
28 | self.radacTime = fp.get(header+'/RadacTime') |
|
33 | self.radacTime = fp.get(header+'/RadacTime') | |
29 | self.timeCount = fp.get(header+'/TimeCount') |
|
34 | self.timeCount = fp.get(header+'/TimeCount') | |
30 | self.timeStatus = fp.get(header+'/TimeStatus') |
|
35 | self.timeStatus = fp.get(header+'/TimeStatus') | |
31 |
|
36 | |||
32 | self.nrecords = self.pulseCount.shape[0] #nblocks |
|
37 | self.nrecords = self.pulseCount.shape[0] #nblocks | |
33 | self.npulses = self.pulseCount.shape[1] #nprofile |
|
38 | self.npulses = self.pulseCount.shape[1] #nprofile | |
34 | self.nsamples = self.nsamplesPulse[0,0] #ngates |
|
39 | self.nsamples = self.nsamplesPulse[0,0] #ngates | |
35 | self.nbeams = self.beamCode.shape[1] |
|
40 | self.nbeams = self.beamCode.shape[1] | |
36 |
|
41 | |||
37 |
|
42 | |||
38 | def getIndexRangeToPulse(self, idrecord=0): |
|
43 | def getIndexRangeToPulse(self, idrecord=0): | |
39 | #indexToZero = numpy.where(self.pulseCount.value[idrecord,:]==0) |
|
44 | #indexToZero = numpy.where(self.pulseCount.value[idrecord,:]==0) | |
40 | #startPulseCountId = indexToZero[0][0] |
|
45 | #startPulseCountId = indexToZero[0][0] | |
41 | #endPulseCountId = startPulseCountId - 1 |
|
46 | #endPulseCountId = startPulseCountId - 1 | |
42 | #range1 = numpy.arange(startPulseCountId,self.npulses,1) |
|
47 | #range1 = numpy.arange(startPulseCountId,self.npulses,1) | |
43 | #range2 = numpy.arange(0,startPulseCountId,1) |
|
48 | #range2 = numpy.arange(0,startPulseCountId,1) | |
44 | #return range1, range2 |
|
49 | #return range1, range2 | |
45 | zero = 0 |
|
50 | zero = 0 | |
46 | npulse = max(self.pulseCount[0,:]+1)-1 |
|
51 | npulse = max(self.pulseCount[0,:]+1)-1 | |
47 | looking_index = numpy.where(self.pulseCount.value[idrecord,:]==npulse)[0] |
|
52 | looking_index = numpy.where(self.pulseCount.value[idrecord,:]==npulse)[0] | |
48 | getLastIndex = looking_index[-1] |
|
53 | getLastIndex = looking_index[-1] | |
49 | index_data = numpy.arange(0,getLastIndex+1,1) |
|
54 | index_data = numpy.arange(0,getLastIndex+1,1) | |
50 | index_buffer = numpy.arange(getLastIndex+1,self.npulses,1) |
|
55 | index_buffer = numpy.arange(getLastIndex+1,self.npulses,1) | |
51 | return index_data, index_buffer |
|
56 | return index_data, index_buffer | |
52 |
|
57 | |||
53 | class AMISRReader(ProcessingUnit): |
|
58 | class AMISRReader(ProcessingUnit): | |
54 |
|
59 | |||
55 | path = None |
|
60 | path = None | |
56 | startDate = None |
|
61 | startDate = None | |
57 | endDate = None |
|
62 | endDate = None | |
58 | startTime = None |
|
63 | startTime = None | |
59 | endTime = None |
|
64 | endTime = None | |
60 | walk = None |
|
65 | walk = None | |
61 | isConfig = False |
|
66 | isConfig = False | |
62 |
|
67 | |||
63 | def __init__(self): |
|
68 | def __init__(self): | |
64 | self.set = None |
|
69 | self.set = None | |
65 | self.subset = None |
|
70 | self.subset = None | |
66 | self.extension_file = '.h5' |
|
71 | self.extension_file = '.h5' | |
67 | self.dtc_str = 'dtc' |
|
72 | self.dtc_str = 'dtc' | |
68 | self.dtc_id = 0 |
|
73 | self.dtc_id = 0 | |
69 | self.status = True |
|
74 | self.status = True | |
70 | self.isConfig = False |
|
75 | self.isConfig = False | |
71 | self.dirnameList = [] |
|
76 | self.dirnameList = [] | |
72 | self.filenameList = [] |
|
77 | self.filenameList = [] | |
73 | self.fileIndex = None |
|
78 | self.fileIndex = None | |
74 | self.flagNoMoreFiles = False |
|
79 | self.flagNoMoreFiles = False | |
75 | self.flagIsNewFile = 0 |
|
80 | self.flagIsNewFile = 0 | |
76 | self.filename = '' |
|
81 | self.filename = '' | |
77 | self.amisrFilePointer = None |
|
82 | self.amisrFilePointer = None | |
78 | self.radacHeaderObj = None |
|
83 | self.radacHeaderObj = None | |
79 | self.dataOut = self.__createObjByDefault() |
|
84 | self.dataOut = self.__createObjByDefault() | |
80 | self.datablock = None |
|
85 | self.datablock = None | |
81 | self.rest_datablock = None |
|
86 | self.rest_datablock = None | |
82 | self.range = None |
|
87 | self.range = None | |
83 | self.idrecord_count = 0 |
|
88 | self.idrecord_count = 0 | |
84 | self.profileIndex = 0 |
|
89 | self.profileIndex = 0 | |
85 | self.index_amisr_sample = None |
|
90 | self.index_amisr_sample = None | |
86 | self.index_amisr_buffer = None |
|
91 | self.index_amisr_buffer = None | |
87 | self.beamCodeByFrame = None |
|
92 | self.beamCodeByFrame = None | |
88 | self.radacTimeByFrame = None |
|
93 | self.radacTimeByFrame = None | |
89 | #atributos originales tal y como esta en el archivo de datos |
|
94 | #atributos originales tal y como esta en el archivo de datos | |
90 | self.beamCodesFromFile = None |
|
95 | self.beamCodesFromFile = None | |
91 | self.radacTimeFromFile = None |
|
96 | self.radacTimeFromFile = None | |
92 | self.rangeFromFile = None |
|
97 | self.rangeFromFile = None | |
93 | self.dataByFrame = None |
|
98 | self.dataByFrame = None | |
94 | self.dataset = None |
|
99 | self.dataset = None | |
95 |
|
100 | |||
96 | self.beamCodeDict = {} |
|
101 | self.beamCodeDict = {} | |
97 | self.beamRangeDict = {} |
|
102 | self.beamRangeDict = {} | |
98 |
|
103 | |||
99 | #experiment cgf file |
|
104 | #experiment cgf file | |
100 | self.npulsesint_fromfile = None |
|
105 | self.npulsesint_fromfile = None | |
101 | self.recordsperfile_fromfile = None |
|
106 | self.recordsperfile_fromfile = None | |
102 | self.nbeamcodes_fromfile = None |
|
107 | self.nbeamcodes_fromfile = None | |
103 | self.ngates_fromfile = None |
|
108 | self.ngates_fromfile = None | |
104 | self.ippSeconds_fromfile = None |
|
109 | self.ippSeconds_fromfile = None | |
105 | self.frequency_h5file = None |
|
110 | self.frequency_h5file = None | |
106 |
|
111 | |||
107 |
|
112 | |||
108 | self.__firstFile = True |
|
113 | self.__firstFile = True | |
109 | self.buffer_radactime = None |
|
114 | self.buffer_radactime = None | |
110 |
|
115 | |||
111 | self.index4_schain_datablock = None |
|
116 | self.index4_schain_datablock = None | |
112 | self.index4_buffer = None |
|
117 | self.index4_buffer = None | |
113 | self.schain_datablock = None |
|
118 | self.schain_datablock = None | |
114 | self.buffer = None |
|
119 | self.buffer = None | |
115 | self.linear_pulseCount = None |
|
120 | self.linear_pulseCount = None | |
116 | self.npulseByFrame = None |
|
121 | self.npulseByFrame = None | |
117 | self.profileIndex_offset = None |
|
122 | self.profileIndex_offset = None | |
118 | self.timezone = 'ut' |
|
123 | self.timezone = 'ut' | |
119 |
|
124 | |||
120 | self.__waitForNewFile = 20 |
|
125 | self.__waitForNewFile = 20 | |
121 | self.__filename_online = None |
|
126 | self.__filename_online = None | |
122 |
|
127 | |||
123 | def __createObjByDefault(self): |
|
128 | def __createObjByDefault(self): | |
124 |
|
129 | |||
125 | dataObj = AMISR() |
|
130 | dataObj = AMISR() | |
126 |
|
131 | |||
127 | return dataObj |
|
132 | return dataObj | |
128 |
|
133 | |||
129 | def __setParameters(self,path='', startDate='',endDate='',startTime='', endTime='', walk=''): |
|
134 | def __setParameters(self,path='', startDate='',endDate='',startTime='', endTime='', walk=''): | |
130 | self.path = path |
|
135 | self.path = path | |
131 | self.startDate = startDate |
|
136 | self.startDate = startDate | |
132 | self.endDate = endDate |
|
137 | self.endDate = endDate | |
133 | self.startTime = startTime |
|
138 | self.startTime = startTime | |
134 | self.endTime = endTime |
|
139 | self.endTime = endTime | |
135 | self.walk = walk |
|
140 | self.walk = walk | |
136 |
|
141 | |||
137 | def __checkPath(self): |
|
142 | def __checkPath(self): | |
138 | if os.path.exists(self.path): |
|
143 | if os.path.exists(self.path): | |
139 | self.status = 1 |
|
144 | self.status = 1 | |
140 | else: |
|
145 | else: | |
141 | self.status = 0 |
|
146 | self.status = 0 | |
142 | print 'Path:%s does not exists'%self.path |
|
147 | print 'Path:%s does not exists'%self.path | |
143 |
|
148 | |||
144 | return |
|
149 | return | |
145 |
|
150 | |||
146 | def __selDates(self, amisr_dirname_format): |
|
151 | def __selDates(self, amisr_dirname_format): | |
147 | try: |
|
152 | try: | |
148 | year = int(amisr_dirname_format[0:4]) |
|
153 | year = int(amisr_dirname_format[0:4]) | |
149 | month = int(amisr_dirname_format[4:6]) |
|
154 | month = int(amisr_dirname_format[4:6]) | |
150 | dom = int(amisr_dirname_format[6:8]) |
|
155 | dom = int(amisr_dirname_format[6:8]) | |
151 | thisDate = datetime.date(year,month,dom) |
|
156 | thisDate = datetime.date(year,month,dom) | |
152 |
|
157 | |||
153 | if (thisDate>=self.startDate and thisDate <= self.endDate): |
|
158 | if (thisDate>=self.startDate and thisDate <= self.endDate): | |
154 | return amisr_dirname_format |
|
159 | return amisr_dirname_format | |
155 | except: |
|
160 | except: | |
156 | return None |
|
161 | return None | |
157 |
|
162 | |||
158 | def __findDataForDates(self,online=False): |
|
163 | def __findDataForDates(self,online=False): | |
159 |
|
164 | |||
160 |
|
165 | |||
161 |
|
166 | |||
162 | if not(self.status): |
|
167 | if not(self.status): | |
163 | return None |
|
168 | return None | |
164 |
|
169 | |||
165 | pat = '\d+.\d+' |
|
170 | pat = '\d+.\d+' | |
166 | dirnameList = [re.search(pat,x) for x in os.listdir(self.path)] |
|
171 | dirnameList = [re.search(pat,x) for x in os.listdir(self.path)] | |
167 | dirnameList = filter(lambda x:x!=None,dirnameList) |
|
172 | dirnameList = filter(lambda x:x!=None,dirnameList) | |
168 | dirnameList = [x.string for x in dirnameList] |
|
173 | dirnameList = [x.string for x in dirnameList] | |
169 | if not(online): |
|
174 | if not(online): | |
170 | dirnameList = [self.__selDates(x) for x in dirnameList] |
|
175 | dirnameList = [self.__selDates(x) for x in dirnameList] | |
171 | dirnameList = filter(lambda x:x!=None,dirnameList) |
|
176 | dirnameList = filter(lambda x:x!=None,dirnameList) | |
172 | if len(dirnameList)>0: |
|
177 | if len(dirnameList)>0: | |
173 | self.status = 1 |
|
178 | self.status = 1 | |
174 | self.dirnameList = dirnameList |
|
179 | self.dirnameList = dirnameList | |
175 | self.dirnameList.sort() |
|
180 | self.dirnameList.sort() | |
176 | else: |
|
181 | else: | |
177 | self.status = 0 |
|
182 | self.status = 0 | |
178 | return None |
|
183 | return None | |
179 |
|
184 | |||
180 | def __getTimeFromData(self): |
|
185 | def __getTimeFromData(self): | |
181 | startDateTime_Reader = datetime.datetime.combine(self.startDate,self.startTime) |
|
186 | startDateTime_Reader = datetime.datetime.combine(self.startDate,self.startTime) | |
182 | endDateTime_Reader = datetime.datetime.combine(self.endDate,self.endTime) |
|
187 | endDateTime_Reader = datetime.datetime.combine(self.endDate,self.endTime) | |
183 |
|
188 | |||
184 | print 'Filtering Files from %s to %s'%(startDateTime_Reader, endDateTime_Reader) |
|
189 | print 'Filtering Files from %s to %s'%(startDateTime_Reader, endDateTime_Reader) | |
185 | print '........................................' |
|
190 | print '........................................' | |
186 | filter_filenameList = [] |
|
191 | filter_filenameList = [] | |
187 | self.filenameList.sort() |
|
192 | self.filenameList.sort() | |
188 | for i in range(len(self.filenameList)-1): |
|
193 | for i in range(len(self.filenameList)-1): | |
189 | filename = self.filenameList[i] |
|
194 | filename = self.filenameList[i] | |
190 | fp = h5py.File(filename,'r') |
|
195 | fp = h5py.File(filename,'r') | |
191 | time_str = fp.get('Time/RadacTimeString') |
|
196 | time_str = fp.get('Time/RadacTimeString') | |
192 |
|
197 | |||
193 | startDateTimeStr_File = time_str[0][0].split('.')[0] |
|
198 | startDateTimeStr_File = time_str[0][0].split('.')[0] | |
194 | junk = time.strptime(startDateTimeStr_File, '%Y-%m-%d %H:%M:%S') |
|
199 | junk = time.strptime(startDateTimeStr_File, '%Y-%m-%d %H:%M:%S') | |
195 | startDateTime_File = datetime.datetime(junk.tm_year,junk.tm_mon,junk.tm_mday,junk.tm_hour, junk.tm_min, junk.tm_sec) |
|
200 | startDateTime_File = datetime.datetime(junk.tm_year,junk.tm_mon,junk.tm_mday,junk.tm_hour, junk.tm_min, junk.tm_sec) | |
196 |
|
201 | |||
197 | endDateTimeStr_File = time_str[-1][-1].split('.')[0] |
|
202 | endDateTimeStr_File = time_str[-1][-1].split('.')[0] | |
198 | junk = time.strptime(endDateTimeStr_File, '%Y-%m-%d %H:%M:%S') |
|
203 | junk = time.strptime(endDateTimeStr_File, '%Y-%m-%d %H:%M:%S') | |
199 | endDateTime_File = datetime.datetime(junk.tm_year,junk.tm_mon,junk.tm_mday,junk.tm_hour, junk.tm_min, junk.tm_sec) |
|
204 | endDateTime_File = datetime.datetime(junk.tm_year,junk.tm_mon,junk.tm_mday,junk.tm_hour, junk.tm_min, junk.tm_sec) | |
200 |
|
205 | |||
201 | fp.close() |
|
206 | fp.close() | |
202 |
|
207 | |||
203 | if self.timezone == 'lt': |
|
208 | if self.timezone == 'lt': | |
204 | startDateTime_File = startDateTime_File - datetime.timedelta(minutes = 300) |
|
209 | startDateTime_File = startDateTime_File - datetime.timedelta(minutes = 300) | |
205 | endDateTime_File = endDateTime_File - datetime.timedelta(minutes = 300) |
|
210 | endDateTime_File = endDateTime_File - datetime.timedelta(minutes = 300) | |
206 |
|
211 | |||
207 | if (endDateTime_File>=startDateTime_Reader and endDateTime_File<endDateTime_Reader): |
|
212 | if (endDateTime_File>=startDateTime_Reader and endDateTime_File<endDateTime_Reader): | |
208 | #self.filenameList.remove(filename) |
|
213 | #self.filenameList.remove(filename) | |
209 | filter_filenameList.append(filename) |
|
214 | filter_filenameList.append(filename) | |
210 |
|
215 | |||
211 | filter_filenameList.sort() |
|
216 | filter_filenameList.sort() | |
212 | self.filenameList = filter_filenameList |
|
217 | self.filenameList = filter_filenameList | |
213 | return 1 |
|
218 | return 1 | |
214 |
|
219 | |||
215 | def __filterByGlob1(self, dirName): |
|
220 | def __filterByGlob1(self, dirName): | |
216 | filter_files = glob.glob1(dirName, '*.*%s'%self.extension_file) |
|
221 | filter_files = glob.glob1(dirName, '*.*%s'%self.extension_file) | |
217 | filterDict = {} |
|
222 | filterDict = {} | |
218 | filterDict.setdefault(dirName) |
|
223 | filterDict.setdefault(dirName) | |
219 | filterDict[dirName] = filter_files |
|
224 | filterDict[dirName] = filter_files | |
220 | return filterDict |
|
225 | return filterDict | |
221 |
|
226 | |||
222 | def __getFilenameList(self, fileListInKeys, dirList): |
|
227 | def __getFilenameList(self, fileListInKeys, dirList): | |
223 | for value in fileListInKeys: |
|
228 | for value in fileListInKeys: | |
224 | dirName = value.keys()[0] |
|
229 | dirName = value.keys()[0] | |
225 | for file in value[dirName]: |
|
230 | for file in value[dirName]: | |
226 | filename = os.path.join(dirName, file) |
|
231 | filename = os.path.join(dirName, file) | |
227 | self.filenameList.append(filename) |
|
232 | self.filenameList.append(filename) | |
228 |
|
233 | |||
229 |
|
234 | |||
230 | def __selectDataForTimes(self, online=False): |
|
235 | def __selectDataForTimes(self, online=False): | |
231 | #aun no esta implementado el filtro for tiempo |
|
236 | #aun no esta implementado el filtro for tiempo | |
232 | if not(self.status): |
|
237 | if not(self.status): | |
233 | return None |
|
238 | return None | |
234 |
|
239 | |||
235 | dirList = [os.path.join(self.path,x) for x in self.dirnameList] |
|
240 | dirList = [os.path.join(self.path,x) for x in self.dirnameList] | |
236 |
|
241 | |||
237 | fileListInKeys = [self.__filterByGlob1(x) for x in dirList] |
|
242 | fileListInKeys = [self.__filterByGlob1(x) for x in dirList] | |
238 |
|
243 | |||
239 | self.__getFilenameList(fileListInKeys, dirList) |
|
244 | self.__getFilenameList(fileListInKeys, dirList) | |
240 | if not(online): |
|
245 | if not(online): | |
241 | #filtro por tiempo |
|
246 | #filtro por tiempo | |
242 | if not(self.all): |
|
247 | if not(self.all): | |
243 | self.__getTimeFromData() |
|
248 | self.__getTimeFromData() | |
244 |
|
249 | |||
245 | if len(self.filenameList)>0: |
|
250 | if len(self.filenameList)>0: | |
246 | self.status = 1 |
|
251 | self.status = 1 | |
247 | self.filenameList.sort() |
|
252 | self.filenameList.sort() | |
248 | else: |
|
253 | else: | |
249 | self.status = 0 |
|
254 | self.status = 0 | |
250 | return None |
|
255 | return None | |
251 |
|
256 | |||
252 | else: |
|
257 | else: | |
253 | #get the last file - 1 |
|
258 | #get the last file - 1 | |
254 | self.filenameList = [self.filenameList[-2]] |
|
259 | self.filenameList = [self.filenameList[-2]] | |
255 |
|
260 | |||
256 | new_dirnameList = [] |
|
261 | new_dirnameList = [] | |
257 | for dirname in self.dirnameList: |
|
262 | for dirname in self.dirnameList: | |
258 | junk = numpy.array([dirname in x for x in self.filenameList]) |
|
263 | junk = numpy.array([dirname in x for x in self.filenameList]) | |
259 | junk_sum = junk.sum() |
|
264 | junk_sum = junk.sum() | |
260 | if junk_sum > 0: |
|
265 | if junk_sum > 0: | |
261 | new_dirnameList.append(dirname) |
|
266 | new_dirnameList.append(dirname) | |
262 | self.dirnameList = new_dirnameList |
|
267 | self.dirnameList = new_dirnameList | |
263 | return 1 |
|
268 | return 1 | |
264 |
|
269 | |||
265 | def __searchFilesOnline(self, |
|
270 | def __searchFilesOnline(self, | |
266 | path, |
|
271 | path, | |
267 | walk=True): |
|
272 | walk=True): | |
268 |
|
273 | |||
269 | startDate = datetime.datetime.utcnow().date() |
|
274 | startDate = datetime.datetime.utcnow().date() | |
270 | endDate = datetime.datetime.utcnow().date() |
|
275 | endDate = datetime.datetime.utcnow().date() | |
271 |
|
276 | |||
272 | self.__setParameters(path=path, startDate=startDate, endDate=endDate, walk=walk) |
|
277 | self.__setParameters(path=path, startDate=startDate, endDate=endDate, walk=walk) | |
273 |
|
278 | |||
274 | self.__checkPath() |
|
279 | self.__checkPath() | |
275 |
|
280 | |||
276 | self.__findDataForDates(online=True) |
|
281 | self.__findDataForDates(online=True) | |
277 |
|
282 | |||
278 | self.dirnameList = [self.dirnameList[-1]] |
|
283 | self.dirnameList = [self.dirnameList[-1]] | |
279 |
|
284 | |||
280 | self.__selectDataForTimes(online=True) |
|
285 | self.__selectDataForTimes(online=True) | |
281 |
|
286 | |||
282 | return |
|
287 | return | |
283 |
|
288 | |||
284 |
|
289 | |||
285 | def __searchFilesOffline(self, |
|
290 | def __searchFilesOffline(self, | |
286 | path, |
|
291 | path, | |
287 | startDate, |
|
292 | startDate, | |
288 | endDate, |
|
293 | endDate, | |
289 | startTime=datetime.time(0,0,0), |
|
294 | startTime=datetime.time(0,0,0), | |
290 | endTime=datetime.time(23,59,59), |
|
295 | endTime=datetime.time(23,59,59), | |
291 | walk=True): |
|
296 | walk=True): | |
292 |
|
297 | |||
293 | self.__setParameters(path, startDate, endDate, startTime, endTime, walk) |
|
298 | self.__setParameters(path, startDate, endDate, startTime, endTime, walk) | |
294 |
|
299 | |||
295 | self.__checkPath() |
|
300 | self.__checkPath() | |
296 |
|
301 | |||
297 | self.__findDataForDates() |
|
302 | self.__findDataForDates() | |
298 |
|
303 | |||
299 | self.__selectDataForTimes() |
|
304 | self.__selectDataForTimes() | |
300 |
|
305 | |||
301 | for i in range(len(self.filenameList)): |
|
306 | for i in range(len(self.filenameList)): | |
302 | print "%s" %(self.filenameList[i]) |
|
307 | print "%s" %(self.filenameList[i]) | |
303 |
|
308 | |||
304 | return |
|
309 | return | |
305 |
|
310 | |||
306 | def __setNextFileOffline(self): |
|
311 | def __setNextFileOffline(self): | |
307 | idFile = self.fileIndex |
|
312 | idFile = self.fileIndex | |
308 |
|
313 | |||
309 | while (True): |
|
314 | while (True): | |
310 | idFile += 1 |
|
315 | idFile += 1 | |
311 | if not(idFile < len(self.filenameList)): |
|
316 | if not(idFile < len(self.filenameList)): | |
312 | self.flagNoMoreFiles = 1 |
|
317 | self.flagNoMoreFiles = 1 | |
313 | print "No more Files" |
|
318 | print "No more Files" | |
314 | return 0 |
|
319 | return 0 | |
315 |
|
320 | |||
316 | filename = self.filenameList[idFile] |
|
321 | filename = self.filenameList[idFile] | |
317 |
|
322 | |||
318 | amisrFilePointer = h5py.File(filename,'r') |
|
323 | amisrFilePointer = h5py.File(filename,'r') | |
319 |
|
324 | |||
320 | break |
|
325 | break | |
321 |
|
326 | |||
322 | self.flagIsNewFile = 1 |
|
327 | self.flagIsNewFile = 1 | |
323 | self.fileIndex = idFile |
|
328 | self.fileIndex = idFile | |
324 | self.filename = filename |
|
329 | self.filename = filename | |
325 |
|
330 | |||
326 | self.amisrFilePointer = amisrFilePointer |
|
331 | self.amisrFilePointer = amisrFilePointer | |
327 |
|
332 | |||
328 | print "Setting the file: %s"%self.filename |
|
333 | print "Setting the file: %s"%self.filename | |
329 |
|
334 | |||
330 | return 1 |
|
335 | return 1 | |
331 |
|
336 | |||
332 |
|
337 | |||
333 | def __setNextFileOnline(self): |
|
338 | def __setNextFileOnline(self): | |
334 | filename = self.filenameList[0] |
|
339 | filename = self.filenameList[0] | |
335 | if self.__filename_online != None: |
|
340 | if self.__filename_online != None: | |
336 | self.__selectDataForTimes(online=True) |
|
341 | self.__selectDataForTimes(online=True) | |
337 | filename = self.filenameList[0] |
|
342 | filename = self.filenameList[0] | |
338 | while self.__filename_online == filename: |
|
343 | while self.__filename_online == filename: | |
339 | print 'waiting %d seconds to get a new file...'%(self.__waitForNewFile) |
|
344 | print 'waiting %d seconds to get a new file...'%(self.__waitForNewFile) | |
340 |
|
|
345 | sleep(self.__waitForNewFile) | |
341 | self.__selectDataForTimes(online=True) |
|
346 | self.__selectDataForTimes(online=True) | |
342 | filename = self.filenameList[0] |
|
347 | filename = self.filenameList[0] | |
343 |
|
348 | |||
344 | self.__filename_online = filename |
|
349 | self.__filename_online = filename | |
345 |
|
350 | |||
346 | self.amisrFilePointer = h5py.File(filename,'r') |
|
351 | self.amisrFilePointer = h5py.File(filename,'r') | |
347 | self.flagIsNewFile = 1 |
|
352 | self.flagIsNewFile = 1 | |
348 | self.filename = filename |
|
353 | self.filename = filename | |
349 | print "Setting the file: %s"%self.filename |
|
354 | print "Setting the file: %s"%self.filename | |
350 | return 1 |
|
355 | return 1 | |
351 |
|
356 | |||
352 |
|
357 | |||
353 | def __readHeader(self): |
|
358 | def __readHeader(self): | |
354 | self.radacHeaderObj = RadacHeader(self.amisrFilePointer) |
|
359 | self.radacHeaderObj = RadacHeader(self.amisrFilePointer) | |
355 |
|
360 | |||
356 | #update values from experiment cfg file |
|
361 | #update values from experiment cfg file | |
357 | if self.radacHeaderObj.nrecords == self.recordsperfile_fromfile: |
|
362 | if self.radacHeaderObj.nrecords == self.recordsperfile_fromfile: | |
358 | self.radacHeaderObj.nrecords = self.recordsperfile_fromfile |
|
363 | self.radacHeaderObj.nrecords = self.recordsperfile_fromfile | |
359 | self.radacHeaderObj.nbeams = self.nbeamcodes_fromfile |
|
364 | self.radacHeaderObj.nbeams = self.nbeamcodes_fromfile | |
360 | self.radacHeaderObj.npulses = self.npulsesint_fromfile |
|
365 | self.radacHeaderObj.npulses = self.npulsesint_fromfile | |
361 | self.radacHeaderObj.nsamples = self.ngates_fromfile |
|
366 | self.radacHeaderObj.nsamples = self.ngates_fromfile | |
362 |
|
367 | |||
363 | #looking index list for data |
|
368 | #looking index list for data | |
364 | start_index = self.radacHeaderObj.pulseCount[0,:][0] |
|
369 | start_index = self.radacHeaderObj.pulseCount[0,:][0] | |
365 | end_index = self.radacHeaderObj.npulses |
|
370 | end_index = self.radacHeaderObj.npulses | |
366 | range4data = range(start_index, end_index) |
|
371 | range4data = range(start_index, end_index) | |
367 | self.index4_schain_datablock = numpy.array(range4data) |
|
372 | self.index4_schain_datablock = numpy.array(range4data) | |
368 |
|
373 | |||
369 | buffer_start_index = 0 |
|
374 | buffer_start_index = 0 | |
370 | buffer_end_index = self.radacHeaderObj.pulseCount[0,:][0] |
|
375 | buffer_end_index = self.radacHeaderObj.pulseCount[0,:][0] | |
371 | range4buffer = range(buffer_start_index, buffer_end_index) |
|
376 | range4buffer = range(buffer_start_index, buffer_end_index) | |
372 | self.index4_buffer = numpy.array(range4buffer) |
|
377 | self.index4_buffer = numpy.array(range4buffer) | |
373 |
|
378 | |||
374 | self.linear_pulseCount = numpy.array(range4data + range4buffer) |
|
379 | self.linear_pulseCount = numpy.array(range4data + range4buffer) | |
375 | self.npulseByFrame = max(self.radacHeaderObj.pulseCount[0,:]+1) |
|
380 | self.npulseByFrame = max(self.radacHeaderObj.pulseCount[0,:]+1) | |
376 |
|
381 | |||
377 | #get tuning frequency |
|
382 | #get tuning frequency | |
378 | frequency_h5file_dataset = self.amisrFilePointer.get('Rx'+'/TuningFrequency') |
|
383 | frequency_h5file_dataset = self.amisrFilePointer.get('Rx'+'/TuningFrequency') | |
379 | self.frequency_h5file = frequency_h5file_dataset[0,0] |
|
384 | self.frequency_h5file = frequency_h5file_dataset[0,0] | |
380 |
|
385 | |||
381 | self.flagIsNewFile = 1 |
|
386 | self.flagIsNewFile = 1 | |
382 |
|
387 | |||
383 | def __getBeamCode(self): |
|
388 | def __getBeamCode(self): | |
384 | self.beamCodeDict = {} |
|
389 | self.beamCodeDict = {} | |
385 | self.beamRangeDict = {} |
|
390 | self.beamRangeDict = {} | |
386 |
|
391 | |||
387 | beamCodeMap = self.amisrFilePointer.get('Setup/BeamcodeMap') |
|
392 | beamCodeMap = self.amisrFilePointer.get('Setup/BeamcodeMap') | |
388 |
|
393 | |||
389 | for i in range(len(self.radacHeaderObj.beamCode[0,:])): |
|
394 | for i in range(len(self.radacHeaderObj.beamCode[0,:])): | |
390 | self.beamCodeDict.setdefault(i) |
|
395 | self.beamCodeDict.setdefault(i) | |
391 | self.beamRangeDict.setdefault(i) |
|
396 | self.beamRangeDict.setdefault(i) | |
392 | beamcodeValue = self.radacHeaderObj.beamCode[0,i] |
|
397 | beamcodeValue = self.radacHeaderObj.beamCode[0,i] | |
393 | beamcodeIndex = numpy.where(beamCodeMap[:,0] == beamcodeValue)[0][0] |
|
398 | beamcodeIndex = numpy.where(beamCodeMap[:,0] == beamcodeValue)[0][0] | |
394 | x = beamCodeMap[beamcodeIndex][1] |
|
399 | x = beamCodeMap[beamcodeIndex][1] | |
395 | y = beamCodeMap[beamcodeIndex][2] |
|
400 | y = beamCodeMap[beamcodeIndex][2] | |
396 | z = beamCodeMap[beamcodeIndex][3] |
|
401 | z = beamCodeMap[beamcodeIndex][3] | |
397 | self.beamCodeDict[i] = [beamcodeValue, x, y, z] |
|
402 | self.beamCodeDict[i] = [beamcodeValue, x, y, z] | |
398 |
|
403 | |||
399 | just4record0 = self.radacHeaderObj.beamCodeByPulse[0,:] |
|
404 | just4record0 = self.radacHeaderObj.beamCodeByPulse[0,:] | |
400 |
|
405 | |||
401 | for i in range(len(self.beamCodeDict.values())): |
|
406 | for i in range(len(self.beamCodeDict.values())): | |
402 | xx = numpy.where(just4record0==self.beamCodeDict.values()[i][0]) |
|
407 | xx = numpy.where(just4record0==self.beamCodeDict.values()[i][0]) | |
403 | indexPulseByBeam = self.linear_pulseCount[xx[0]] |
|
408 | indexPulseByBeam = self.linear_pulseCount[xx[0]] | |
404 | self.beamRangeDict[i] = indexPulseByBeam |
|
409 | self.beamRangeDict[i] = indexPulseByBeam | |
405 |
|
410 | |||
406 | def __getExpParameters(self): |
|
411 | def __getExpParameters(self): | |
407 | if not(self.status): |
|
412 | if not(self.status): | |
408 | return None |
|
413 | return None | |
409 |
|
414 | |||
410 | experimentCfgPath = os.path.join(self.path, self.dirnameList[0], 'Setup') |
|
415 | experimentCfgPath = os.path.join(self.path, self.dirnameList[0], 'Setup') | |
411 |
|
416 | |||
412 | expFinder = glob.glob1(experimentCfgPath,'*.exp') |
|
417 | expFinder = glob.glob1(experimentCfgPath,'*.exp') | |
413 | if len(expFinder)== 0: |
|
418 | if len(expFinder)== 0: | |
414 | self.status = 0 |
|
419 | self.status = 0 | |
415 | return None |
|
420 | return None | |
416 |
|
421 | |||
417 | experimentFilename = os.path.join(experimentCfgPath,expFinder[0]) |
|
422 | experimentFilename = os.path.join(experimentCfgPath,expFinder[0]) | |
418 |
|
423 | |||
419 | f = open(experimentFilename) |
|
424 | f = open(experimentFilename) | |
420 | lines = f.readlines() |
|
425 | lines = f.readlines() | |
421 | f.close() |
|
426 | f.close() | |
422 |
|
427 | |||
423 | parmsList = ['npulsesint*','recordsperfile*','nbeamcodes*','ngates*'] |
|
428 | parmsList = ['npulsesint*','recordsperfile*','nbeamcodes*','ngates*'] | |
424 | filterList = [fnmatch.filter(lines, x) for x in parmsList] |
|
429 | filterList = [fnmatch.filter(lines, x) for x in parmsList] | |
425 |
|
430 | |||
426 |
|
431 | |||
427 | values = [re.sub(r'\D',"",x[0]) for x in filterList] |
|
432 | values = [re.sub(r'\D',"",x[0]) for x in filterList] | |
428 |
|
433 | |||
429 | self.npulsesint_fromfile = int(values[0]) |
|
434 | self.npulsesint_fromfile = int(values[0]) | |
430 | self.recordsperfile_fromfile = int(values[1]) |
|
435 | self.recordsperfile_fromfile = int(values[1]) | |
431 | self.nbeamcodes_fromfile = int(values[2]) |
|
436 | self.nbeamcodes_fromfile = int(values[2]) | |
432 | self.ngates_fromfile = int(values[3]) |
|
437 | self.ngates_fromfile = int(values[3]) | |
433 |
|
438 | |||
434 | tufileFinder = fnmatch.filter(lines, 'tufile=*') |
|
439 | tufileFinder = fnmatch.filter(lines, 'tufile=*') | |
435 | tufile = tufileFinder[0].split('=')[1].split('\n')[0] |
|
440 | tufile = tufileFinder[0].split('=')[1].split('\n')[0] | |
436 | tufile = tufile.split('\r')[0] |
|
441 | tufile = tufile.split('\r')[0] | |
437 | tufilename = os.path.join(experimentCfgPath,tufile) |
|
442 | tufilename = os.path.join(experimentCfgPath,tufile) | |
438 |
|
443 | |||
439 | f = open(tufilename) |
|
444 | f = open(tufilename) | |
440 | lines = f.readlines() |
|
445 | lines = f.readlines() | |
441 | f.close() |
|
446 | f.close() | |
442 | self.ippSeconds_fromfile = float(lines[1].split()[2])/1E6 |
|
447 | self.ippSeconds_fromfile = float(lines[1].split()[2])/1E6 | |
443 |
|
448 | |||
444 |
|
449 | |||
445 | self.status = 1 |
|
450 | self.status = 1 | |
446 |
|
451 | |||
447 | def __setIdsAndArrays(self): |
|
452 | def __setIdsAndArrays(self): | |
448 | self.dataByFrame = self.__setDataByFrame() |
|
453 | self.dataByFrame = self.__setDataByFrame() | |
449 | self.beamCodeByFrame = self.amisrFilePointer.get('Raw11/Data/RadacHeader/BeamCode').value[0, :] |
|
454 | self.beamCodeByFrame = self.amisrFilePointer.get('Raw11/Data/RadacHeader/BeamCode').value[0, :] | |
450 | self.readRanges() |
|
455 | self.readRanges() | |
451 | self.index_amisr_sample, self.index_amisr_buffer = self.radacHeaderObj.getIndexRangeToPulse(0) |
|
456 | self.index_amisr_sample, self.index_amisr_buffer = self.radacHeaderObj.getIndexRangeToPulse(0) | |
452 | self.radacTimeByFrame = numpy.zeros(self.radacHeaderObj.npulses) |
|
457 | self.radacTimeByFrame = numpy.zeros(self.radacHeaderObj.npulses) | |
453 | if len(self.index_amisr_buffer) > 0: |
|
458 | if len(self.index_amisr_buffer) > 0: | |
454 | self.buffer_radactime = numpy.zeros_like(self.radacTimeByFrame) |
|
459 | self.buffer_radactime = numpy.zeros_like(self.radacTimeByFrame) | |
455 |
|
460 | |||
456 |
|
461 | |||
457 | def __setNextFile(self,online=False): |
|
462 | def __setNextFile(self,online=False): | |
458 |
|
463 | |||
459 | if not(online): |
|
464 | if not(online): | |
460 | newFile = self.__setNextFileOffline() |
|
465 | newFile = self.__setNextFileOffline() | |
461 | else: |
|
466 | else: | |
462 | newFile = self.__setNextFileOnline() |
|
467 | newFile = self.__setNextFileOnline() | |
463 |
|
468 | |||
464 | if not(newFile): |
|
469 | if not(newFile): | |
465 | return 0 |
|
470 | return 0 | |
466 |
|
471 | |||
467 | self.__readHeader() |
|
472 | self.__readHeader() | |
468 |
|
473 | |||
469 | if self.__firstFile: |
|
474 | if self.__firstFile: | |
470 | self.__setIdsAndArrays() |
|
475 | self.__setIdsAndArrays() | |
471 | self.__firstFile = False |
|
476 | self.__firstFile = False | |
472 |
|
477 | |||
473 | self.__getBeamCode() |
|
478 | self.__getBeamCode() | |
474 | self.readDataBlock() |
|
479 | self.readDataBlock() | |
475 |
|
480 | |||
476 |
|
481 | |||
477 | def setup(self,path=None, |
|
482 | def setup(self,path=None, | |
478 | startDate=None, |
|
483 | startDate=None, | |
479 | endDate=None, |
|
484 | endDate=None, | |
480 | startTime=datetime.time(0,0,0), |
|
485 | startTime=datetime.time(0,0,0), | |
481 | endTime=datetime.time(23,59,59), |
|
486 | endTime=datetime.time(23,59,59), | |
482 | walk=True, |
|
487 | walk=True, | |
483 | timezone='ut', |
|
488 | timezone='ut', | |
484 | all=0, |
|
489 | all=0, | |
485 | online=False): |
|
490 | online=False): | |
486 |
|
491 | |||
487 | self.timezone = timezone |
|
492 | self.timezone = timezone | |
488 | self.all = all |
|
493 | self.all = all | |
489 | self.online = online |
|
494 | self.online = online | |
490 | if not(online): |
|
495 | if not(online): | |
491 | #Busqueda de archivos offline |
|
496 | #Busqueda de archivos offline | |
492 | self.__searchFilesOffline(path, startDate, endDate, startTime, endTime, walk) |
|
497 | self.__searchFilesOffline(path, startDate, endDate, startTime, endTime, walk) | |
493 | else: |
|
498 | else: | |
494 | self.__searchFilesOnline(path, walk) |
|
499 | self.__searchFilesOnline(path, walk) | |
495 |
|
500 | |||
496 | if not(self.filenameList): |
|
501 | if not(self.filenameList): | |
497 | print "There is no files into the folder: %s"%(path) |
|
502 | print "There is no files into the folder: %s"%(path) | |
498 |
|
503 | |||
499 | sys.exit(-1) |
|
504 | sys.exit(-1) | |
500 |
|
505 | |||
501 | self.__getExpParameters() |
|
506 | self.__getExpParameters() | |
502 |
|
507 | |||
503 | self.fileIndex = -1 |
|
508 | self.fileIndex = -1 | |
504 |
|
509 | |||
505 | self.__setNextFile(online) |
|
510 | self.__setNextFile(online) | |
506 |
|
511 | |||
507 | # first_beamcode = self.radacHeaderObj.beamCodeByPulse[0,0] |
|
512 | # first_beamcode = self.radacHeaderObj.beamCodeByPulse[0,0] | |
508 | # index = numpy.where(self.radacHeaderObj.beamCodeByPulse[0,:]!=first_beamcode)[0][0] |
|
513 | # index = numpy.where(self.radacHeaderObj.beamCodeByPulse[0,:]!=first_beamcode)[0][0] | |
509 | self.profileIndex_offset = self.radacHeaderObj.pulseCount[0,:][0] |
|
514 | self.profileIndex_offset = self.radacHeaderObj.pulseCount[0,:][0] | |
510 | self.profileIndex = self.profileIndex_offset |
|
515 | self.profileIndex = self.profileIndex_offset | |
511 |
|
516 | |||
512 | def readRanges(self): |
|
517 | def readRanges(self): | |
513 | dataset = self.amisrFilePointer.get('Raw11/Data/Samples/Range') |
|
518 | dataset = self.amisrFilePointer.get('Raw11/Data/Samples/Range') | |
514 |
|
519 | |||
515 | self.rangeFromFile = numpy.reshape(dataset.value,(-1)) |
|
520 | self.rangeFromFile = numpy.reshape(dataset.value,(-1)) | |
516 | return self.rangeFromFile |
|
521 | return self.rangeFromFile | |
517 |
|
522 | |||
518 |
|
523 | |||
519 | def readRadacTime(self,idrecord, range1, range2): |
|
524 | def readRadacTime(self,idrecord, range1, range2): | |
520 | self.radacTimeFromFile = self.radacHeaderObj.radacTime.value |
|
525 | self.radacTimeFromFile = self.radacHeaderObj.radacTime.value | |
521 |
|
526 | |||
522 | radacTimeByFrame = numpy.zeros((self.radacHeaderObj.npulses)) |
|
527 | radacTimeByFrame = numpy.zeros((self.radacHeaderObj.npulses)) | |
523 | #radacTimeByFrame = dataset[idrecord - 1,range1] |
|
528 | #radacTimeByFrame = dataset[idrecord - 1,range1] | |
524 | #radacTimeByFrame = dataset[idrecord,range2] |
|
529 | #radacTimeByFrame = dataset[idrecord,range2] | |
525 |
|
530 | |||
526 | return radacTimeByFrame |
|
531 | return radacTimeByFrame | |
527 |
|
532 | |||
528 | def readBeamCode(self, idrecord, range1, range2): |
|
533 | def readBeamCode(self, idrecord, range1, range2): | |
529 | dataset = self.amisrFilePointer.get('Raw11/Data/RadacHeader/BeamCode') |
|
534 | dataset = self.amisrFilePointer.get('Raw11/Data/RadacHeader/BeamCode') | |
530 | beamcodeByFrame = numpy.zeros((self.radacHeaderObj.npulses)) |
|
535 | beamcodeByFrame = numpy.zeros((self.radacHeaderObj.npulses)) | |
531 | self.beamCodesFromFile = dataset.value |
|
536 | self.beamCodesFromFile = dataset.value | |
532 |
|
537 | |||
533 | #beamcodeByFrame[range1] = dataset[idrecord - 1, range1] |
|
538 | #beamcodeByFrame[range1] = dataset[idrecord - 1, range1] | |
534 | #beamcodeByFrame[range2] = dataset[idrecord, range2] |
|
539 | #beamcodeByFrame[range2] = dataset[idrecord, range2] | |
535 | beamcodeByFrame[range1] = dataset[idrecord, range1] |
|
540 | beamcodeByFrame[range1] = dataset[idrecord, range1] | |
536 | beamcodeByFrame[range2] = dataset[idrecord, range2] |
|
541 | beamcodeByFrame[range2] = dataset[idrecord, range2] | |
537 |
|
542 | |||
538 | return beamcodeByFrame |
|
543 | return beamcodeByFrame | |
539 |
|
544 | |||
540 |
|
545 | |||
541 | def __setDataByFrame(self): |
|
546 | def __setDataByFrame(self): | |
542 | ndata = 2 # porque es complejo |
|
547 | ndata = 2 # porque es complejo | |
543 | dataByFrame = numpy.zeros((self.radacHeaderObj.npulses, self.radacHeaderObj.nsamples, ndata)) |
|
548 | dataByFrame = numpy.zeros((self.radacHeaderObj.npulses, self.radacHeaderObj.nsamples, ndata)) | |
544 | return dataByFrame |
|
549 | return dataByFrame | |
545 |
|
550 | |||
546 | def __readDataSet(self): |
|
551 | def __readDataSet(self): | |
547 | dataset = self.amisrFilePointer.get('Raw11/Data/Samples/Data') |
|
552 | dataset = self.amisrFilePointer.get('Raw11/Data/Samples/Data') | |
548 | return dataset |
|
553 | return dataset | |
549 |
|
554 | |||
550 | def __setDataBlock(self,): |
|
555 | def __setDataBlock(self,): | |
551 | real = self.dataByFrame[:,:,0] #asumo que 0 es real |
|
556 | real = self.dataByFrame[:,:,0] #asumo que 0 es real | |
552 | imag = self.dataByFrame[:,:,1] #asumo que 1 es imaginario |
|
557 | imag = self.dataByFrame[:,:,1] #asumo que 1 es imaginario | |
553 | datablock = real + imag*1j #armo el complejo |
|
558 | datablock = real + imag*1j #armo el complejo | |
554 | return datablock |
|
559 | return datablock | |
555 |
|
560 | |||
556 | def readSamples_version1(self,idrecord): |
|
561 | def readSamples_version1(self,idrecord): | |
557 | #estas tres primeras lineas solo se deben ejecutar una vez |
|
562 | #estas tres primeras lineas solo se deben ejecutar una vez | |
558 | if self.flagIsNewFile: |
|
563 | if self.flagIsNewFile: | |
559 | #reading dataset |
|
564 | #reading dataset | |
560 | self.dataset = self.__readDataSet() |
|
565 | self.dataset = self.__readDataSet() | |
561 | self.flagIsNewFile = 0 |
|
566 | self.flagIsNewFile = 0 | |
562 |
|
567 | |||
563 | if idrecord == 0: |
|
568 | if idrecord == 0: | |
564 | self.dataByFrame[self.index4_schain_datablock, : ,:] = self.dataset[0, self.index_amisr_sample,:,:] |
|
569 | self.dataByFrame[self.index4_schain_datablock, : ,:] = self.dataset[0, self.index_amisr_sample,:,:] | |
565 | self.radacTimeByFrame[self.index4_schain_datablock] = self.radacHeaderObj.radacTime[0, self.index_amisr_sample] |
|
570 | self.radacTimeByFrame[self.index4_schain_datablock] = self.radacHeaderObj.radacTime[0, self.index_amisr_sample] | |
566 | datablock = self.__setDataBlock() |
|
571 | datablock = self.__setDataBlock() | |
567 | if len(self.index_amisr_buffer) > 0: |
|
572 | if len(self.index_amisr_buffer) > 0: | |
568 | self.buffer = self.dataset[0, self.index_amisr_buffer,:,:] |
|
573 | self.buffer = self.dataset[0, self.index_amisr_buffer,:,:] | |
569 | self.buffer_radactime = self.radacHeaderObj.radacTime[0, self.index_amisr_buffer] |
|
574 | self.buffer_radactime = self.radacHeaderObj.radacTime[0, self.index_amisr_buffer] | |
570 |
|
575 | |||
571 | return datablock |
|
576 | return datablock | |
572 | if len(self.index_amisr_buffer) > 0: |
|
577 | if len(self.index_amisr_buffer) > 0: | |
573 | self.dataByFrame[self.index4_buffer,:,:] = self.buffer.copy() |
|
578 | self.dataByFrame[self.index4_buffer,:,:] = self.buffer.copy() | |
574 | self.radacTimeByFrame[self.index4_buffer] = self.buffer_radactime.copy() |
|
579 | self.radacTimeByFrame[self.index4_buffer] = self.buffer_radactime.copy() | |
575 | self.dataByFrame[self.index4_schain_datablock,:,:] = self.dataset[idrecord, self.index_amisr_sample,:,:] |
|
580 | self.dataByFrame[self.index4_schain_datablock,:,:] = self.dataset[idrecord, self.index_amisr_sample,:,:] | |
576 | self.radacTimeByFrame[self.index4_schain_datablock] = self.radacHeaderObj.radacTime[idrecord, self.index_amisr_sample] |
|
581 | self.radacTimeByFrame[self.index4_schain_datablock] = self.radacHeaderObj.radacTime[idrecord, self.index_amisr_sample] | |
577 | datablock = self.__setDataBlock() |
|
582 | datablock = self.__setDataBlock() | |
578 | if len(self.index_amisr_buffer) > 0: |
|
583 | if len(self.index_amisr_buffer) > 0: | |
579 | self.buffer = self.dataset[idrecord, self.index_amisr_buffer, :, :] |
|
584 | self.buffer = self.dataset[idrecord, self.index_amisr_buffer, :, :] | |
580 | self.buffer_radactime = self.radacHeaderObj.radacTime[idrecord, self.index_amisr_buffer] |
|
585 | self.buffer_radactime = self.radacHeaderObj.radacTime[idrecord, self.index_amisr_buffer] | |
581 |
|
586 | |||
582 | return datablock |
|
587 | return datablock | |
583 |
|
588 | |||
584 |
|
589 | |||
585 | def readSamples(self,idrecord): |
|
590 | def readSamples(self,idrecord): | |
586 | if self.flagIsNewFile: |
|
591 | if self.flagIsNewFile: | |
587 | self.dataByFrame = self.__setDataByFrame() |
|
592 | self.dataByFrame = self.__setDataByFrame() | |
588 | self.beamCodeByFrame = self.amisrFilePointer.get('Raw11/Data/RadacHeader/BeamCode').value[idrecord, :] |
|
593 | self.beamCodeByFrame = self.amisrFilePointer.get('Raw11/Data/RadacHeader/BeamCode').value[idrecord, :] | |
589 |
|
594 | |||
590 | #reading ranges |
|
595 | #reading ranges | |
591 | self.readRanges() |
|
596 | self.readRanges() | |
592 | #reading dataset |
|
597 | #reading dataset | |
593 | self.dataset = self.__readDataSet() |
|
598 | self.dataset = self.__readDataSet() | |
594 |
|
599 | |||
595 | self.flagIsNewFile = 0 |
|
600 | self.flagIsNewFile = 0 | |
596 | self.radacTimeByFrame = self.radacHeaderObj.radacTime.value[idrecord, :] |
|
601 | self.radacTimeByFrame = self.radacHeaderObj.radacTime.value[idrecord, :] | |
597 | self.dataByFrame = self.dataset[idrecord, :, :, :] |
|
602 | self.dataByFrame = self.dataset[idrecord, :, :, :] | |
598 | datablock = self.__setDataBlock() |
|
603 | datablock = self.__setDataBlock() | |
599 | return datablock |
|
604 | return datablock | |
600 |
|
605 | |||
601 |
|
606 | |||
602 | def readDataBlock(self): |
|
607 | def readDataBlock(self): | |
603 |
|
608 | |||
604 | self.datablock = self.readSamples_version1(self.idrecord_count) |
|
609 | self.datablock = self.readSamples_version1(self.idrecord_count) | |
605 | #self.datablock = self.readSamples(self.idrecord_count) |
|
610 | #self.datablock = self.readSamples(self.idrecord_count) | |
606 | #print 'record:', self.idrecord_count |
|
611 | #print 'record:', self.idrecord_count | |
607 |
|
612 | |||
608 | self.idrecord_count += 1 |
|
613 | self.idrecord_count += 1 | |
609 | self.profileIndex = 0 |
|
614 | self.profileIndex = 0 | |
610 |
|
615 | |||
611 | if self.idrecord_count >= self.radacHeaderObj.nrecords: |
|
616 | if self.idrecord_count >= self.radacHeaderObj.nrecords: | |
612 | self.idrecord_count = 0 |
|
617 | self.idrecord_count = 0 | |
613 | self.flagIsNewFile = 1 |
|
618 | self.flagIsNewFile = 1 | |
614 |
|
619 | |||
615 | def readNextBlock(self): |
|
620 | def readNextBlock(self): | |
616 |
|
621 | |||
617 | self.readDataBlock() |
|
622 | self.readDataBlock() | |
618 |
|
623 | |||
619 | if self.flagIsNewFile: |
|
624 | if self.flagIsNewFile: | |
620 | self.__setNextFile(self.online) |
|
625 | self.__setNextFile(self.online) | |
621 | pass |
|
626 | pass | |
622 |
|
627 | |||
623 | def __hasNotDataInBuffer(self): |
|
628 | def __hasNotDataInBuffer(self): | |
624 | #self.radacHeaderObj.npulses debe ser otra variable para considerar el numero de pulsos a tomar en el primer y ultimo record |
|
629 | #self.radacHeaderObj.npulses debe ser otra variable para considerar el numero de pulsos a tomar en el primer y ultimo record | |
625 | if self.profileIndex >= self.radacHeaderObj.npulses: |
|
630 | if self.profileIndex >= self.radacHeaderObj.npulses: | |
626 | return 1 |
|
631 | return 1 | |
627 | return 0 |
|
632 | return 0 | |
628 |
|
633 | |||
629 | def printUTC(self): |
|
634 | def printUTC(self): | |
630 | print self.dataOut.utctime |
|
635 | print self.dataOut.utctime | |
631 | print '' |
|
636 | print '' | |
632 |
|
637 | |||
633 | def setObjProperties(self): |
|
638 | def setObjProperties(self): | |
634 |
|
639 | |||
635 | self.dataOut.heightList = self.rangeFromFile/1000.0 #km |
|
640 | self.dataOut.heightList = self.rangeFromFile/1000.0 #km | |
636 | self.dataOut.nProfiles = self.radacHeaderObj.npulses |
|
641 | self.dataOut.nProfiles = self.radacHeaderObj.npulses | |
637 | self.dataOut.nRecords = self.radacHeaderObj.nrecords |
|
642 | self.dataOut.nRecords = self.radacHeaderObj.nrecords | |
638 | self.dataOut.nBeams = self.radacHeaderObj.nbeams |
|
643 | self.dataOut.nBeams = self.radacHeaderObj.nbeams | |
639 | self.dataOut.ippSeconds = self.ippSeconds_fromfile |
|
644 | self.dataOut.ippSeconds = self.ippSeconds_fromfile | |
640 | # self.dataOut.timeInterval = self.dataOut.ippSeconds * self.dataOut.nCohInt |
|
645 | # self.dataOut.timeInterval = self.dataOut.ippSeconds * self.dataOut.nCohInt | |
641 | self.dataOut.frequency = self.frequency_h5file |
|
646 | self.dataOut.frequency = self.frequency_h5file | |
642 | self.dataOut.npulseByFrame = self.npulseByFrame |
|
647 | self.dataOut.npulseByFrame = self.npulseByFrame | |
643 | self.dataOut.nBaud = None |
|
648 | self.dataOut.nBaud = None | |
644 | self.dataOut.nCode = None |
|
649 | self.dataOut.nCode = None | |
645 | self.dataOut.code = None |
|
650 | self.dataOut.code = None | |
646 |
|
651 | |||
647 | self.dataOut.beamCodeDict = self.beamCodeDict |
|
652 | self.dataOut.beamCodeDict = self.beamCodeDict | |
648 | self.dataOut.beamRangeDict = self.beamRangeDict |
|
653 | self.dataOut.beamRangeDict = self.beamRangeDict | |
649 |
|
654 | |||
650 | if self.timezone == 'lt': |
|
655 | if self.timezone == 'lt': | |
651 | self.dataOut.timeZone = time.timezone / 60. #get the timezone in minutes |
|
656 | self.dataOut.timeZone = time.timezone / 60. #get the timezone in minutes | |
652 | else: |
|
657 | else: | |
653 | self.dataOut.timeZone = 0 #by default time is UTC |
|
658 | self.dataOut.timeZone = 0 #by default time is UTC | |
654 |
|
659 | |||
655 | def getData(self): |
|
660 | def getData(self): | |
656 |
|
661 | |||
657 | if self.flagNoMoreFiles: |
|
662 | if self.flagNoMoreFiles: | |
658 | self.dataOut.flagNoData = True |
|
663 | self.dataOut.flagNoData = True | |
659 | print 'Process finished' |
|
664 | print 'Process finished' | |
660 | return 0 |
|
665 | return 0 | |
661 |
|
666 | |||
662 | if self.__hasNotDataInBuffer(): |
|
667 | if self.__hasNotDataInBuffer(): | |
663 | self.readNextBlock() |
|
668 | self.readNextBlock() | |
664 |
|
669 | |||
665 |
|
670 | |||
666 | if self.datablock == None: # setear esta condicion cuando no hayan datos por leers |
|
671 | if self.datablock == None: # setear esta condicion cuando no hayan datos por leers | |
667 | self.dataOut.flagNoData = True |
|
672 | self.dataOut.flagNoData = True | |
668 | return 0 |
|
673 | return 0 | |
669 |
|
674 | |||
670 | self.dataOut.data = numpy.reshape(self.datablock[self.profileIndex,:],(1,-1)) |
|
675 | self.dataOut.data = numpy.reshape(self.datablock[self.profileIndex,:],(1,-1)) | |
671 |
|
676 | |||
672 | self.dataOut.utctime = self.radacTimeByFrame[self.profileIndex] |
|
677 | self.dataOut.utctime = self.radacTimeByFrame[self.profileIndex] | |
673 | self.dataOut.profileIndex = self.profileIndex |
|
678 | self.dataOut.profileIndex = self.profileIndex | |
674 | self.dataOut.flagNoData = False |
|
679 | self.dataOut.flagNoData = False | |
675 |
|
680 | |||
676 | self.profileIndex += 1 |
|
681 | self.profileIndex += 1 | |
677 |
|
682 | |||
678 | return self.dataOut.data |
|
683 | return self.dataOut.data | |
679 |
|
684 | |||
680 |
|
685 | |||
681 | def run(self, **kwargs): |
|
686 | def run(self, **kwargs): | |
682 | if not(self.isConfig): |
|
687 | if not(self.isConfig): | |
683 | self.setup(**kwargs) |
|
688 | self.setup(**kwargs) | |
684 | self.setObjProperties() |
|
689 | self.setObjProperties() | |
685 | self.isConfig = True |
|
690 | self.isConfig = True | |
686 |
|
691 | |||
687 | self.getData() |
|
692 | self.getData() |
@@ -1,834 +1,849 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on Jul 3, 2014 |
|
2 | Created on Jul 3, 2014 | |
3 |
|
3 | |||
4 | @author: roj-idl71 |
|
4 | @author: roj-idl71 | |
5 | ''' |
|
5 | ''' | |
6 |
|
6 | |||
7 | import os, sys |
|
7 | import os, sys | |
8 | import time, datetime |
|
8 | import time, datetime | |
9 | import numpy |
|
9 | import numpy | |
10 | import fnmatch |
|
10 | import fnmatch | |
11 | import glob |
|
11 | import glob | |
12 |
|
12 | |||
13 | try: |
|
13 | try: | |
14 | from gevent import sleep |
|
14 | from gevent import sleep | |
15 | except: |
|
15 | except: | |
16 | from time import sleep |
|
16 | from time import sleep | |
17 |
|
17 | |||
18 | try: |
|
18 | try: | |
19 | import pyfits |
|
19 | import pyfits | |
20 | except: |
|
20 | except: | |
21 | """ |
|
21 | """ | |
22 | """ |
|
22 | """ | |
23 |
|
23 | |||
24 | from xml.etree.ElementTree import ElementTree |
|
24 | from xml.etree.ElementTree import ElementTree | |
25 |
|
25 | |||
26 | from jroIO_base import isDoyFolder, isNumber |
|
26 | from jroIO_base import isDoyFolder, isNumber | |
27 | from schainpy.model.proc.jroproc_base import Operation, ProcessingUnit |
|
27 | from schainpy.model.proc.jroproc_base import Operation, ProcessingUnit | |
28 |
|
28 | |||
29 | class Fits: |
|
29 | class Fits: | |
30 | name=None |
|
30 | name=None | |
31 | format=None |
|
31 | format=None | |
32 | array =None |
|
32 | array =None | |
33 | data =None |
|
33 | data =None | |
34 | thdulist=None |
|
34 | thdulist=None | |
35 | prihdr=None |
|
35 | prihdr=None | |
36 | hdu=None |
|
36 | hdu=None | |
37 |
|
37 | |||
38 | def __init__(self): |
|
38 | def __init__(self): | |
39 |
|
39 | |||
40 | pass |
|
40 | pass | |
41 |
|
41 | |||
42 | def setColF(self,name,format,array): |
|
42 | def setColF(self,name,format,array): | |
43 | self.name=name |
|
43 | self.name=name | |
44 | self.format=format |
|
44 | self.format=format | |
45 | self.array=array |
|
45 | self.array=array | |
46 | a1=numpy.array([self.array],dtype=numpy.float32) |
|
46 | a1=numpy.array([self.array],dtype=numpy.float32) | |
47 | self.col1 = pyfits.Column(name=self.name, format=self.format, array=a1) |
|
47 | self.col1 = pyfits.Column(name=self.name, format=self.format, array=a1) | |
48 | return self.col1 |
|
48 | return self.col1 | |
49 |
|
49 | |||
50 | # def setColP(self,name,format,data): |
|
50 | # def setColP(self,name,format,data): | |
51 | # self.name=name |
|
51 | # self.name=name | |
52 | # self.format=format |
|
52 | # self.format=format | |
53 | # self.data=data |
|
53 | # self.data=data | |
54 | # a2=numpy.array([self.data],dtype=numpy.float32) |
|
54 | # a2=numpy.array([self.data],dtype=numpy.float32) | |
55 | # self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2) |
|
55 | # self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2) | |
56 | # return self.col2 |
|
56 | # return self.col2 | |
57 |
|
57 | |||
58 |
|
58 | |||
59 | def writeData(self,name,format,data): |
|
59 | def writeData(self,name,format,data): | |
60 | self.name=name |
|
60 | self.name=name | |
61 | self.format=format |
|
61 | self.format=format | |
62 | self.data=data |
|
62 | self.data=data | |
63 | a2=numpy.array([self.data],dtype=numpy.float32) |
|
63 | a2=numpy.array([self.data],dtype=numpy.float32) | |
64 | self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2) |
|
64 | self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2) | |
65 | return self.col2 |
|
65 | return self.col2 | |
66 |
|
66 | |||
67 | def cFImage(self,idblock,year,month,day,hour,minute,second): |
|
67 | def cFImage(self,idblock,year,month,day,hour,minute,second): | |
68 | self.hdu= pyfits.PrimaryHDU(idblock) |
|
68 | self.hdu= pyfits.PrimaryHDU(idblock) | |
69 | self.hdu.header.set("Year",year) |
|
69 | self.hdu.header.set("Year",year) | |
70 | self.hdu.header.set("Month",month) |
|
70 | self.hdu.header.set("Month",month) | |
71 | self.hdu.header.set("Day",day) |
|
71 | self.hdu.header.set("Day",day) | |
72 | self.hdu.header.set("Hour",hour) |
|
72 | self.hdu.header.set("Hour",hour) | |
73 | self.hdu.header.set("Minute",minute) |
|
73 | self.hdu.header.set("Minute",minute) | |
74 | self.hdu.header.set("Second",second) |
|
74 | self.hdu.header.set("Second",second) | |
75 | return self.hdu |
|
75 | return self.hdu | |
76 |
|
76 | |||
77 |
|
77 | |||
78 | def Ctable(self,colList): |
|
78 | def Ctable(self,colList): | |
79 | self.cols=pyfits.ColDefs(colList) |
|
79 | self.cols=pyfits.ColDefs(colList) | |
80 | self.tbhdu = pyfits.new_table(self.cols) |
|
80 | self.tbhdu = pyfits.new_table(self.cols) | |
81 | return self.tbhdu |
|
81 | return self.tbhdu | |
82 |
|
82 | |||
83 |
|
83 | |||
84 | def CFile(self,hdu,tbhdu): |
|
84 | def CFile(self,hdu,tbhdu): | |
85 | self.thdulist=pyfits.HDUList([hdu,tbhdu]) |
|
85 | self.thdulist=pyfits.HDUList([hdu,tbhdu]) | |
86 |
|
86 | |||
87 | def wFile(self,filename): |
|
87 | def wFile(self,filename): | |
88 | if os.path.isfile(filename): |
|
88 | if os.path.isfile(filename): | |
89 | os.remove(filename) |
|
89 | os.remove(filename) | |
90 | self.thdulist.writeto(filename) |
|
90 | self.thdulist.writeto(filename) | |
91 |
|
91 | |||
92 |
|
92 | |||
93 | class ParameterConf: |
|
93 | class ParameterConf: | |
94 | ELEMENTNAME = 'Parameter' |
|
94 | ELEMENTNAME = 'Parameter' | |
95 | def __init__(self): |
|
95 | def __init__(self): | |
96 | self.name = '' |
|
96 | self.name = '' | |
97 | self.value = '' |
|
97 | self.value = '' | |
98 |
|
98 | |||
99 | def readXml(self, parmElement): |
|
99 | def readXml(self, parmElement): | |
100 | self.name = parmElement.get('name') |
|
100 | self.name = parmElement.get('name') | |
101 | self.value = parmElement.get('value') |
|
101 | self.value = parmElement.get('value') | |
102 |
|
102 | |||
103 | def getElementName(self): |
|
103 | def getElementName(self): | |
104 | return self.ELEMENTNAME |
|
104 | return self.ELEMENTNAME | |
105 |
|
105 | |||
106 | class Metadata: |
|
106 | class Metadata: | |
107 |
|
107 | |||
108 | def __init__(self, filename): |
|
108 | def __init__(self, filename): | |
109 | self.parmConfObjList = [] |
|
109 | self.parmConfObjList = [] | |
110 | self.readXml(filename) |
|
110 | self.readXml(filename) | |
111 |
|
111 | |||
112 | def readXml(self, filename): |
|
112 | def readXml(self, filename): | |
113 | self.projectElement = None |
|
113 | self.projectElement = None | |
114 | self.procUnitConfObjDict = {} |
|
114 | self.procUnitConfObjDict = {} | |
115 | self.projectElement = ElementTree().parse(filename) |
|
115 | self.projectElement = ElementTree().parse(filename) | |
116 | self.project = self.projectElement.tag |
|
116 | self.project = self.projectElement.tag | |
117 |
|
117 | |||
118 | parmElementList = self.projectElement.getiterator(ParameterConf().getElementName()) |
|
118 | parmElementList = self.projectElement.getiterator(ParameterConf().getElementName()) | |
119 |
|
119 | |||
120 | for parmElement in parmElementList: |
|
120 | for parmElement in parmElementList: | |
121 | parmConfObj = ParameterConf() |
|
121 | parmConfObj = ParameterConf() | |
122 | parmConfObj.readXml(parmElement) |
|
122 | parmConfObj.readXml(parmElement) | |
123 | self.parmConfObjList.append(parmConfObj) |
|
123 | self.parmConfObjList.append(parmConfObj) | |
124 |
|
124 | |||
125 | class FitsWriter(Operation): |
|
125 | class FitsWriter(Operation): | |
126 |
|
126 | |||
127 | def __init__(self): |
|
127 | def __init__(self): | |
128 | self.isConfig = False |
|
128 | self.isConfig = False | |
129 | self.dataBlocksPerFile = None |
|
129 | self.dataBlocksPerFile = None | |
130 | self.blockIndex = 0 |
|
130 | self.blockIndex = 0 | |
131 | self.flagIsNewFile = 1 |
|
131 | self.flagIsNewFile = 1 | |
132 | self.fitsObj = None |
|
132 | self.fitsObj = None | |
133 | self.optchar = 'P' |
|
133 | self.optchar = 'P' | |
134 | self.ext = '.fits' |
|
134 | self.ext = '.fits' | |
135 | self.setFile = 0 |
|
135 | self.setFile = 0 | |
136 |
|
136 | |||
137 | def setFitsHeader(self, dataOut, metadatafile): |
|
137 | def setFitsHeader(self, dataOut, metadatafile): | |
138 |
|
138 | |||
139 | header_data = pyfits.PrimaryHDU() |
|
139 | header_data = pyfits.PrimaryHDU() | |
140 |
|
140 | |||
141 | metadata4fits = Metadata(metadatafile) |
|
141 | metadata4fits = Metadata(metadatafile) | |
142 | for parameter in metadata4fits.parmConfObjList: |
|
142 | for parameter in metadata4fits.parmConfObjList: | |
143 | parm_name = parameter.name |
|
143 | parm_name = parameter.name | |
144 | parm_value = parameter.value |
|
144 | parm_value = parameter.value | |
145 |
|
145 | |||
146 | # if parm_value == 'fromdatadatetime': |
|
146 | # if parm_value == 'fromdatadatetime': | |
147 | # value = time.strftime("%b %d %Y %H:%M:%S", dataOut.datatime.timetuple()) |
|
147 | # value = time.strftime("%b %d %Y %H:%M:%S", dataOut.datatime.timetuple()) | |
148 | # elif parm_value == 'fromdataheights': |
|
148 | # elif parm_value == 'fromdataheights': | |
149 | # value = dataOut.nHeights |
|
149 | # value = dataOut.nHeights | |
150 | # elif parm_value == 'fromdatachannel': |
|
150 | # elif parm_value == 'fromdatachannel': | |
151 | # value = dataOut.nChannels |
|
151 | # value = dataOut.nChannels | |
152 | # elif parm_value == 'fromdatasamples': |
|
152 | # elif parm_value == 'fromdatasamples': | |
153 | # value = dataOut.nFFTPoints |
|
153 | # value = dataOut.nFFTPoints | |
154 | # else: |
|
154 | # else: | |
155 | # value = parm_value |
|
155 | # value = parm_value | |
156 |
|
156 | |||
157 | header_data.header[parm_name] = parm_value |
|
157 | header_data.header[parm_name] = parm_value | |
158 |
|
158 | |||
159 |
|
159 | |||
160 | header_data.header['DATETIME'] = time.strftime("%b %d %Y %H:%M:%S", dataOut.datatime.timetuple()) |
|
160 | header_data.header['DATETIME'] = time.strftime("%b %d %Y %H:%M:%S", dataOut.datatime.timetuple()) | |
161 | header_data.header['CHANNELLIST'] = str(dataOut.channelList) |
|
161 | header_data.header['CHANNELLIST'] = str(dataOut.channelList) | |
162 | header_data.header['NCHANNELS'] = dataOut.nChannels |
|
162 | header_data.header['NCHANNELS'] = dataOut.nChannels | |
163 | #header_data.header['HEIGHTS'] = dataOut.heightList |
|
163 | #header_data.header['HEIGHTS'] = dataOut.heightList | |
164 | header_data.header['NHEIGHTS'] = dataOut.nHeights |
|
164 | header_data.header['NHEIGHTS'] = dataOut.nHeights | |
165 |
|
165 | |||
166 | header_data.header['IPPSECONDS'] = dataOut.ippSeconds |
|
166 | header_data.header['IPPSECONDS'] = dataOut.ippSeconds | |
167 | header_data.header['NCOHINT'] = dataOut.nCohInt |
|
167 | header_data.header['NCOHINT'] = dataOut.nCohInt | |
168 | header_data.header['NINCOHINT'] = dataOut.nIncohInt |
|
168 | header_data.header['NINCOHINT'] = dataOut.nIncohInt | |
169 | header_data.header['TIMEZONE'] = dataOut.timeZone |
|
169 | header_data.header['TIMEZONE'] = dataOut.timeZone | |
170 | header_data.header['NBLOCK'] = self.blockIndex |
|
170 | header_data.header['NBLOCK'] = self.blockIndex | |
171 |
|
171 | |||
172 | header_data.writeto(self.filename) |
|
172 | header_data.writeto(self.filename) | |
173 |
|
173 | |||
174 | self.addExtension(dataOut.heightList,'HEIGHTLIST') |
|
174 | self.addExtension(dataOut.heightList,'HEIGHTLIST') | |
175 |
|
175 | |||
176 |
|
176 | |||
177 | def setup(self, dataOut, path, dataBlocksPerFile, metadatafile): |
|
177 | def setup(self, dataOut, path, dataBlocksPerFile, metadatafile): | |
178 |
|
178 | |||
179 | self.path = path |
|
179 | self.path = path | |
180 | self.dataOut = dataOut |
|
180 | self.dataOut = dataOut | |
181 | self.metadatafile = metadatafile |
|
181 | self.metadatafile = metadatafile | |
182 | self.dataBlocksPerFile = dataBlocksPerFile |
|
182 | self.dataBlocksPerFile = dataBlocksPerFile | |
183 |
|
183 | |||
184 | def open(self): |
|
184 | def open(self): | |
185 | self.fitsObj = pyfits.open(self.filename, mode='update') |
|
185 | self.fitsObj = pyfits.open(self.filename, mode='update') | |
186 |
|
186 | |||
187 |
|
187 | |||
188 | def addExtension(self, data, tagname): |
|
188 | def addExtension(self, data, tagname): | |
189 | self.open() |
|
189 | self.open() | |
190 | extension = pyfits.ImageHDU(data=data, name=tagname) |
|
190 | extension = pyfits.ImageHDU(data=data, name=tagname) | |
191 | #extension.header['TAG'] = tagname |
|
191 | #extension.header['TAG'] = tagname | |
192 | self.fitsObj.append(extension) |
|
192 | self.fitsObj.append(extension) | |
193 | self.write() |
|
193 | self.write() | |
194 |
|
194 | |||
195 | def addData(self, data): |
|
195 | def addData(self, data): | |
196 | self.open() |
|
196 | self.open() | |
197 | extension = pyfits.ImageHDU(data=data, name=self.fitsObj[0].header['DATATYPE']) |
|
197 | extension = pyfits.ImageHDU(data=data, name=self.fitsObj[0].header['DATATYPE']) | |
198 | extension.header['UTCTIME'] = self.dataOut.utctime |
|
198 | extension.header['UTCTIME'] = self.dataOut.utctime | |
199 | self.fitsObj.append(extension) |
|
199 | self.fitsObj.append(extension) | |
200 | self.blockIndex += 1 |
|
200 | self.blockIndex += 1 | |
201 | self.fitsObj[0].header['NBLOCK'] = self.blockIndex |
|
201 | self.fitsObj[0].header['NBLOCK'] = self.blockIndex | |
202 |
|
202 | |||
203 | self.write() |
|
203 | self.write() | |
204 |
|
204 | |||
205 | def write(self): |
|
205 | def write(self): | |
206 |
|
206 | |||
207 | self.fitsObj.flush(verbose=True) |
|
207 | self.fitsObj.flush(verbose=True) | |
208 | self.fitsObj.close() |
|
208 | self.fitsObj.close() | |
209 |
|
209 | |||
210 |
|
210 | |||
211 | def setNextFile(self): |
|
211 | def setNextFile(self): | |
212 |
|
212 | |||
213 | ext = self.ext |
|
213 | ext = self.ext | |
214 | path = self.path |
|
214 | path = self.path | |
215 |
|
215 | |||
216 | timeTuple = time.localtime( self.dataOut.utctime) |
|
216 | timeTuple = time.localtime( self.dataOut.utctime) | |
217 | subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) |
|
217 | subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) | |
218 |
|
218 | |||
219 | fullpath = os.path.join( path, subfolder ) |
|
219 | fullpath = os.path.join( path, subfolder ) | |
220 | if not( os.path.exists(fullpath) ): |
|
220 | if not( os.path.exists(fullpath) ): | |
221 | os.mkdir(fullpath) |
|
221 | os.mkdir(fullpath) | |
222 | self.setFile = -1 #inicializo mi contador de seteo |
|
222 | self.setFile = -1 #inicializo mi contador de seteo | |
223 | else: |
|
223 | else: | |
224 | filesList = os.listdir( fullpath ) |
|
224 | filesList = os.listdir( fullpath ) | |
225 | if len( filesList ) > 0: |
|
225 | if len( filesList ) > 0: | |
226 | filesList = sorted( filesList, key=str.lower ) |
|
226 | filesList = sorted( filesList, key=str.lower ) | |
227 | filen = filesList[-1] |
|
227 | filen = filesList[-1] | |
228 |
|
228 | |||
229 | if isNumber( filen[8:11] ): |
|
229 | if isNumber( filen[8:11] ): | |
230 | self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file |
|
230 | self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file | |
231 | else: |
|
231 | else: | |
232 | self.setFile = -1 |
|
232 | self.setFile = -1 | |
233 | else: |
|
233 | else: | |
234 | self.setFile = -1 #inicializo mi contador de seteo |
|
234 | self.setFile = -1 #inicializo mi contador de seteo | |
235 |
|
235 | |||
236 | setFile = self.setFile |
|
236 | setFile = self.setFile | |
237 | setFile += 1 |
|
237 | setFile += 1 | |
238 |
|
238 | |||
239 | thisFile = '%s%4.4d%3.3d%3.3d%s' % (self.optchar, |
|
239 | thisFile = '%s%4.4d%3.3d%3.3d%s' % (self.optchar, | |
240 | timeTuple.tm_year, |
|
240 | timeTuple.tm_year, | |
241 | timeTuple.tm_yday, |
|
241 | timeTuple.tm_yday, | |
242 | setFile, |
|
242 | setFile, | |
243 | ext ) |
|
243 | ext ) | |
244 |
|
244 | |||
245 | filename = os.path.join( path, subfolder, thisFile ) |
|
245 | filename = os.path.join( path, subfolder, thisFile ) | |
246 |
|
246 | |||
247 | self.blockIndex = 0 |
|
247 | self.blockIndex = 0 | |
248 | self.filename = filename |
|
248 | self.filename = filename | |
249 | self.setFile = setFile |
|
249 | self.setFile = setFile | |
250 | self.flagIsNewFile = 1 |
|
250 | self.flagIsNewFile = 1 | |
251 |
|
251 | |||
252 | print 'Writing the file: %s'%self.filename |
|
252 | print 'Writing the file: %s'%self.filename | |
253 |
|
253 | |||
254 | self.setFitsHeader(self.dataOut, self.metadatafile) |
|
254 | self.setFitsHeader(self.dataOut, self.metadatafile) | |
255 |
|
255 | |||
256 | return 1 |
|
256 | return 1 | |
257 |
|
257 | |||
258 | def writeBlock(self): |
|
258 | def writeBlock(self): | |
259 | self.addData(self.dataOut.data_spc) |
|
259 | self.addData(self.dataOut.data_spc) | |
260 | self.flagIsNewFile = 0 |
|
260 | self.flagIsNewFile = 0 | |
261 |
|
261 | |||
262 |
|
262 | |||
263 | def __setNewBlock(self): |
|
263 | def __setNewBlock(self): | |
264 |
|
264 | |||
265 | if self.flagIsNewFile: |
|
265 | if self.flagIsNewFile: | |
266 | return 1 |
|
266 | return 1 | |
267 |
|
267 | |||
268 | if self.blockIndex < self.dataBlocksPerFile: |
|
268 | if self.blockIndex < self.dataBlocksPerFile: | |
269 | return 1 |
|
269 | return 1 | |
270 |
|
270 | |||
271 | if not( self.setNextFile() ): |
|
271 | if not( self.setNextFile() ): | |
272 | return 0 |
|
272 | return 0 | |
273 |
|
273 | |||
274 | return 1 |
|
274 | return 1 | |
275 |
|
275 | |||
276 | def writeNextBlock(self): |
|
276 | def writeNextBlock(self): | |
277 | if not( self.__setNewBlock() ): |
|
277 | if not( self.__setNewBlock() ): | |
278 | return 0 |
|
278 | return 0 | |
279 | self.writeBlock() |
|
279 | self.writeBlock() | |
280 | return 1 |
|
280 | return 1 | |
281 |
|
281 | |||
282 | def putData(self): |
|
282 | def putData(self): | |
283 | if self.flagIsNewFile: |
|
283 | if self.flagIsNewFile: | |
284 | self.setNextFile() |
|
284 | self.setNextFile() | |
285 | self.writeNextBlock() |
|
285 | self.writeNextBlock() | |
286 |
|
286 | |||
287 | def run(self, dataOut, **kwargs): |
|
287 | def run(self, dataOut, **kwargs): | |
288 | if not(self.isConfig): |
|
288 | if not(self.isConfig): | |
289 | self.setup(dataOut, **kwargs) |
|
289 | self.setup(dataOut, **kwargs) | |
290 | self.isConfig = True |
|
290 | self.isConfig = True | |
291 | self.putData() |
|
291 | self.putData() | |
292 |
|
292 | |||
293 |
|
293 | |||
294 | class FitsReader(ProcessingUnit): |
|
294 | class FitsReader(ProcessingUnit): | |
295 |
|
295 | |||
296 | # __TIMEZONE = time.timezone |
|
296 | # __TIMEZONE = time.timezone | |
297 |
|
297 | |||
298 | expName = None |
|
298 | expName = None | |
299 | datetimestr = None |
|
299 | datetimestr = None | |
300 | utc = None |
|
300 | utc = None | |
301 | nChannels = None |
|
301 | nChannels = None | |
302 | nSamples = None |
|
302 | nSamples = None | |
303 | dataBlocksPerFile = None |
|
303 | dataBlocksPerFile = None | |
304 | comments = None |
|
304 | comments = None | |
305 | lastUTTime = None |
|
305 | lastUTTime = None | |
306 | header_dict = None |
|
306 | header_dict = None | |
307 | data = None |
|
307 | data = None | |
308 | data_header_dict = None |
|
308 | data_header_dict = None | |
309 |
|
309 | |||
310 | def __init__(self): |
|
310 | def __init__(self): | |
311 | self.isConfig = False |
|
311 | self.isConfig = False | |
312 | self.ext = '.fits' |
|
312 | self.ext = '.fits' | |
313 | self.setFile = 0 |
|
313 | self.setFile = 0 | |
314 | self.flagNoMoreFiles = 0 |
|
314 | self.flagNoMoreFiles = 0 | |
315 | self.flagIsNewFile = 1 |
|
315 | self.flagIsNewFile = 1 | |
316 | self.flagDiscontinuousBlock = None |
|
316 | self.flagDiscontinuousBlock = None | |
317 | self.fileIndex = None |
|
317 | self.fileIndex = None | |
318 | self.filename = None |
|
318 | self.filename = None | |
319 | self.fileSize = None |
|
319 | self.fileSize = None | |
320 | self.fitsObj = None |
|
320 | self.fitsObj = None | |
321 | self.timeZone = None |
|
321 | self.timeZone = None | |
322 | self.nReadBlocks = 0 |
|
322 | self.nReadBlocks = 0 | |
323 | self.nTotalBlocks = 0 |
|
323 | self.nTotalBlocks = 0 | |
324 | self.dataOut = self.createObjByDefault() |
|
324 | self.dataOut = self.createObjByDefault() | |
325 | self.maxTimeStep = 10# deberia ser definido por el usuario usando el metodo setup() |
|
325 | self.maxTimeStep = 10# deberia ser definido por el usuario usando el metodo setup() | |
326 | self.blockIndex = 1 |
|
326 | self.blockIndex = 1 | |
327 |
|
327 | |||
328 | def createObjByDefault(self): |
|
328 | def createObjByDefault(self): | |
329 |
|
329 | |||
330 | dataObj = Fits() |
|
330 | dataObj = Fits() | |
331 |
|
331 | |||
332 | return dataObj |
|
332 | return dataObj | |
333 |
|
333 | |||
334 | def isFileinThisTime(self, filename, startTime, endTime, useLocalTime=False): |
|
334 | def isFileinThisTime(self, filename, startTime, endTime, useLocalTime=False): | |
335 | try: |
|
335 | try: | |
336 | fitsObj = pyfits.open(filename,'readonly') |
|
336 | fitsObj = pyfits.open(filename,'readonly') | |
337 | except: |
|
337 | except: | |
338 | raise IOError, "The file %s can't be opened" %(filename) |
|
338 | raise IOError, "The file %s can't be opened" %(filename) | |
339 |
|
339 | |||
340 | header = fitsObj[0].header |
|
340 | header = fitsObj[0].header | |
341 | struct_time = time.strptime(header['DATETIME'], "%b %d %Y %H:%M:%S") |
|
341 | struct_time = time.strptime(header['DATETIME'], "%b %d %Y %H:%M:%S") | |
342 | utc = time.mktime(struct_time) - time.timezone #TIMEZONE debe ser un parametro del header FITS |
|
342 | utc = time.mktime(struct_time) - time.timezone #TIMEZONE debe ser un parametro del header FITS | |
343 |
|
343 | |||
344 | ltc = utc |
|
344 | ltc = utc | |
345 | if useLocalTime: |
|
345 | if useLocalTime: | |
346 | ltc -= time.timezone |
|
346 | ltc -= time.timezone | |
347 | thisDatetime = datetime.datetime.utcfromtimestamp(ltc) |
|
347 | thisDatetime = datetime.datetime.utcfromtimestamp(ltc) | |
348 | thisTime = thisDatetime.time() |
|
348 | thisTime = thisDatetime.time() | |
349 |
|
349 | |||
350 | if not ((startTime <= thisTime) and (endTime > thisTime)): |
|
350 | if not ((startTime <= thisTime) and (endTime > thisTime)): | |
351 | return None |
|
351 | return None | |
352 |
|
352 | |||
353 | return thisDatetime |
|
353 | return thisDatetime | |
354 |
|
354 | |||
355 | def __setNextFileOnline(self): |
|
355 | def __setNextFileOnline(self): | |
356 | raise ValueError, "No implemented" |
|
356 | raise ValueError, "No implemented" | |
357 |
|
357 | |||
358 | def __setNextFileOffline(self): |
|
358 | def __setNextFileOffline(self): | |
359 | idFile = self.fileIndex |
|
359 | idFile = self.fileIndex | |
360 |
|
360 | |||
361 | while (True): |
|
361 | while (True): | |
362 | idFile += 1 |
|
362 | idFile += 1 | |
363 | if not(idFile < len(self.filenameList)): |
|
363 | if not(idFile < len(self.filenameList)): | |
364 | self.flagNoMoreFiles = 1 |
|
364 | self.flagNoMoreFiles = 1 | |
365 | print "No more Files" |
|
365 | print "No more Files" | |
366 | return 0 |
|
366 | return 0 | |
367 |
|
367 | |||
368 | filename = self.filenameList[idFile] |
|
368 | filename = self.filenameList[idFile] | |
369 |
|
369 | |||
370 | # if not(self.__verifyFile(filename)): |
|
370 | # if not(self.__verifyFile(filename)): | |
371 | # continue |
|
371 | # continue | |
372 |
|
372 | |||
373 | fileSize = os.path.getsize(filename) |
|
373 | fileSize = os.path.getsize(filename) | |
374 | fitsObj = pyfits.open(filename,'readonly') |
|
374 | fitsObj = pyfits.open(filename,'readonly') | |
375 | break |
|
375 | break | |
376 |
|
376 | |||
377 | self.flagIsNewFile = 1 |
|
377 | self.flagIsNewFile = 1 | |
378 | self.fileIndex = idFile |
|
378 | self.fileIndex = idFile | |
379 | self.filename = filename |
|
379 | self.filename = filename | |
380 | self.fileSize = fileSize |
|
380 | self.fileSize = fileSize | |
381 | self.fitsObj = fitsObj |
|
381 | self.fitsObj = fitsObj | |
382 | self.blockIndex = 0 |
|
382 | self.blockIndex = 0 | |
383 | print "Setting the file: %s"%self.filename |
|
383 | print "Setting the file: %s"%self.filename | |
384 |
|
384 | |||
385 | return 1 |
|
385 | return 1 | |
386 |
|
386 | |||
|
387 | def __setValuesFromHeader(self): | |||
|
388 | ||||
|
389 | self.dataOut.header = self.header_dict | |||
|
390 | self.dataOut.expName = self.expName | |||
|
391 | self.dataOut.nChannels = self.nChannels | |||
|
392 | self.dataOut.timeZone = self.timeZone | |||
|
393 | self.dataOut.dataBlocksPerFile = self.dataBlocksPerFile | |||
|
394 | self.dataOut.comments = self.comments | |||
|
395 | # self.dataOut.timeInterval = self.timeInterval | |||
|
396 | self.dataOut.channelList = self.channelList | |||
|
397 | self.dataOut.heightList = self.heightList | |||
|
398 | ||||
|
399 | self.dataOut.nCohInt = self.nCohInt | |||
|
400 | self.dataOut.nIncohInt = self.nIncohInt | |||
|
401 | ||||
387 | def readHeader(self): |
|
402 | def readHeader(self): | |
388 | headerObj = self.fitsObj[0] |
|
403 | headerObj = self.fitsObj[0] | |
389 |
|
404 | |||
390 | self.header_dict = headerObj.header |
|
405 | self.header_dict = headerObj.header | |
391 | if 'EXPNAME' in headerObj.header.keys(): |
|
406 | if 'EXPNAME' in headerObj.header.keys(): | |
392 | self.expName = headerObj.header['EXPNAME'] |
|
407 | self.expName = headerObj.header['EXPNAME'] | |
393 |
|
408 | |||
394 | if 'DATATYPE' in headerObj.header.keys(): |
|
409 | if 'DATATYPE' in headerObj.header.keys(): | |
395 | self.dataType = headerObj.header['DATATYPE'] |
|
410 | self.dataType = headerObj.header['DATATYPE'] | |
396 |
|
411 | |||
397 | self.datetimestr = headerObj.header['DATETIME'] |
|
412 | self.datetimestr = headerObj.header['DATETIME'] | |
398 | channelList = headerObj.header['CHANNELLIST'] |
|
413 | channelList = headerObj.header['CHANNELLIST'] | |
399 | channelList = channelList.split('[') |
|
414 | channelList = channelList.split('[') | |
400 | channelList = channelList[1].split(']') |
|
415 | channelList = channelList[1].split(']') | |
401 | channelList = channelList[0].split(',') |
|
416 | channelList = channelList[0].split(',') | |
402 | channelList = [int(ch) for ch in channelList] |
|
417 | channelList = [int(ch) for ch in channelList] | |
403 | self.channelList = channelList |
|
418 | self.channelList = channelList | |
404 | self.nChannels = headerObj.header['NCHANNELS'] |
|
419 | self.nChannels = headerObj.header['NCHANNELS'] | |
405 | self.nHeights = headerObj.header['NHEIGHTS'] |
|
420 | self.nHeights = headerObj.header['NHEIGHTS'] | |
406 | self.ippSeconds = headerObj.header['IPPSECONDS'] |
|
421 | self.ippSeconds = headerObj.header['IPPSECONDS'] | |
407 | self.nCohInt = headerObj.header['NCOHINT'] |
|
422 | self.nCohInt = headerObj.header['NCOHINT'] | |
408 | self.nIncohInt = headerObj.header['NINCOHINT'] |
|
423 | self.nIncohInt = headerObj.header['NINCOHINT'] | |
409 | self.dataBlocksPerFile = headerObj.header['NBLOCK'] |
|
424 | self.dataBlocksPerFile = headerObj.header['NBLOCK'] | |
410 | self.timeZone = headerObj.header['TIMEZONE'] |
|
425 | self.timeZone = headerObj.header['TIMEZONE'] | |
411 |
|
426 | |||
412 | # self.timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt |
|
427 | # self.timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt | |
413 |
|
428 | |||
414 | if 'COMMENT' in headerObj.header.keys(): |
|
429 | if 'COMMENT' in headerObj.header.keys(): | |
415 | self.comments = headerObj.header['COMMENT'] |
|
430 | self.comments = headerObj.header['COMMENT'] | |
416 |
|
431 | |||
417 | self.readHeightList() |
|
432 | self.readHeightList() | |
418 |
|
433 | |||
419 | def readHeightList(self): |
|
434 | def readHeightList(self): | |
420 | self.blockIndex = self.blockIndex + 1 |
|
435 | self.blockIndex = self.blockIndex + 1 | |
421 | obj = self.fitsObj[self.blockIndex] |
|
436 | obj = self.fitsObj[self.blockIndex] | |
422 | self.heightList = obj.data |
|
437 | self.heightList = obj.data | |
423 | self.blockIndex = self.blockIndex + 1 |
|
438 | self.blockIndex = self.blockIndex + 1 | |
424 |
|
439 | |||
425 | def readExtension(self): |
|
440 | def readExtension(self): | |
426 | obj = self.fitsObj[self.blockIndex] |
|
441 | obj = self.fitsObj[self.blockIndex] | |
427 | self.heightList = obj.data |
|
442 | self.heightList = obj.data | |
428 | self.blockIndex = self.blockIndex + 1 |
|
443 | self.blockIndex = self.blockIndex + 1 | |
429 |
|
444 | |||
430 | def setNextFile(self): |
|
445 | def setNextFile(self): | |
431 |
|
446 | |||
432 | if self.online: |
|
447 | if self.online: | |
433 | newFile = self.__setNextFileOnline() |
|
448 | newFile = self.__setNextFileOnline() | |
434 | else: |
|
449 | else: | |
435 | newFile = self.__setNextFileOffline() |
|
450 | newFile = self.__setNextFileOffline() | |
436 |
|
451 | |||
437 | if not(newFile): |
|
452 | if not(newFile): | |
438 | return 0 |
|
453 | return 0 | |
439 |
|
454 | |||
440 | self.readHeader() |
|
455 | self.readHeader() | |
441 |
|
456 | self.__setValuesFromHeader() | ||
442 | self.nReadBlocks = 0 |
|
457 | self.nReadBlocks = 0 | |
443 | # self.blockIndex = 1 |
|
458 | # self.blockIndex = 1 | |
444 | return 1 |
|
459 | return 1 | |
445 |
|
460 | |||
446 | def __searchFilesOffLine(self, |
|
461 | def __searchFilesOffLine(self, | |
447 | path, |
|
462 | path, | |
448 | startDate, |
|
463 | startDate, | |
449 | endDate, |
|
464 | endDate, | |
450 | startTime=datetime.time(0,0,0), |
|
465 | startTime=datetime.time(0,0,0), | |
451 | endTime=datetime.time(23,59,59), |
|
466 | endTime=datetime.time(23,59,59), | |
452 | set=None, |
|
467 | set=None, | |
453 | expLabel='', |
|
468 | expLabel='', | |
454 | ext='.fits', |
|
469 | ext='.fits', | |
455 | walk=True): |
|
470 | walk=True): | |
456 |
|
471 | |||
457 | pathList = [] |
|
472 | pathList = [] | |
458 |
|
473 | |||
459 | if not walk: |
|
474 | if not walk: | |
460 | pathList.append(path) |
|
475 | pathList.append(path) | |
461 |
|
476 | |||
462 | else: |
|
477 | else: | |
463 | dirList = [] |
|
478 | dirList = [] | |
464 | for thisPath in os.listdir(path): |
|
479 | for thisPath in os.listdir(path): | |
465 | if not os.path.isdir(os.path.join(path,thisPath)): |
|
480 | if not os.path.isdir(os.path.join(path,thisPath)): | |
466 | continue |
|
481 | continue | |
467 | if not isDoyFolder(thisPath): |
|
482 | if not isDoyFolder(thisPath): | |
468 | continue |
|
483 | continue | |
469 |
|
484 | |||
470 | dirList.append(thisPath) |
|
485 | dirList.append(thisPath) | |
471 |
|
486 | |||
472 | if not(dirList): |
|
487 | if not(dirList): | |
473 | return None, None |
|
488 | return None, None | |
474 |
|
489 | |||
475 | thisDate = startDate |
|
490 | thisDate = startDate | |
476 |
|
491 | |||
477 | while(thisDate <= endDate): |
|
492 | while(thisDate <= endDate): | |
478 | year = thisDate.timetuple().tm_year |
|
493 | year = thisDate.timetuple().tm_year | |
479 | doy = thisDate.timetuple().tm_yday |
|
494 | doy = thisDate.timetuple().tm_yday | |
480 |
|
495 | |||
481 | matchlist = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy) + '*') |
|
496 | matchlist = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy) + '*') | |
482 | if len(matchlist) == 0: |
|
497 | if len(matchlist) == 0: | |
483 | thisDate += datetime.timedelta(1) |
|
498 | thisDate += datetime.timedelta(1) | |
484 | continue |
|
499 | continue | |
485 | for match in matchlist: |
|
500 | for match in matchlist: | |
486 | pathList.append(os.path.join(path,match,expLabel)) |
|
501 | pathList.append(os.path.join(path,match,expLabel)) | |
487 |
|
502 | |||
488 | thisDate += datetime.timedelta(1) |
|
503 | thisDate += datetime.timedelta(1) | |
489 |
|
504 | |||
490 | if pathList == []: |
|
505 | if pathList == []: | |
491 | print "Any folder was found for the date range: %s-%s" %(startDate, endDate) |
|
506 | print "Any folder was found for the date range: %s-%s" %(startDate, endDate) | |
492 | return None, None |
|
507 | return None, None | |
493 |
|
508 | |||
494 | print "%d folder(s) was(were) found for the date range: %s - %s" %(len(pathList), startDate, endDate) |
|
509 | print "%d folder(s) was(were) found for the date range: %s - %s" %(len(pathList), startDate, endDate) | |
495 |
|
510 | |||
496 | filenameList = [] |
|
511 | filenameList = [] | |
497 | datetimeList = [] |
|
512 | datetimeList = [] | |
498 |
|
513 | |||
499 | for i in range(len(pathList)): |
|
514 | for i in range(len(pathList)): | |
500 |
|
515 | |||
501 | thisPath = pathList[i] |
|
516 | thisPath = pathList[i] | |
502 |
|
517 | |||
503 | fileList = glob.glob1(thisPath, "*%s" %ext) |
|
518 | fileList = glob.glob1(thisPath, "*%s" %ext) | |
504 | fileList.sort() |
|
519 | fileList.sort() | |
505 |
|
520 | |||
506 | for thisFile in fileList: |
|
521 | for thisFile in fileList: | |
507 |
|
522 | |||
508 | filename = os.path.join(thisPath,thisFile) |
|
523 | filename = os.path.join(thisPath,thisFile) | |
509 | thisDatetime = self.isFileinThisTime(filename, startTime, endTime) |
|
524 | thisDatetime = self.isFileinThisTime(filename, startTime, endTime) | |
510 |
|
525 | |||
511 | if not(thisDatetime): |
|
526 | if not(thisDatetime): | |
512 | continue |
|
527 | continue | |
513 |
|
528 | |||
514 | filenameList.append(filename) |
|
529 | filenameList.append(filename) | |
515 | datetimeList.append(thisDatetime) |
|
530 | datetimeList.append(thisDatetime) | |
516 |
|
531 | |||
517 | if not(filenameList): |
|
532 | if not(filenameList): | |
518 | print "Any file was found for the time range %s - %s" %(startTime, endTime) |
|
533 | print "Any file was found for the time range %s - %s" %(startTime, endTime) | |
519 | return None, None |
|
534 | return None, None | |
520 |
|
535 | |||
521 | print "%d file(s) was(were) found for the time range: %s - %s" %(len(filenameList), startTime, endTime) |
|
536 | print "%d file(s) was(were) found for the time range: %s - %s" %(len(filenameList), startTime, endTime) | |
522 |
|
537 | |||
523 |
|
538 | |||
524 | for i in range(len(filenameList)): |
|
539 | for i in range(len(filenameList)): | |
525 | print "%s -> [%s]" %(filenameList[i], datetimeList[i].ctime()) |
|
540 | print "%s -> [%s]" %(filenameList[i], datetimeList[i].ctime()) | |
526 |
|
541 | |||
527 | self.filenameList = filenameList |
|
542 | self.filenameList = filenameList | |
528 | self.datetimeList = datetimeList |
|
543 | self.datetimeList = datetimeList | |
529 |
|
544 | |||
530 | return pathList, filenameList |
|
545 | return pathList, filenameList | |
531 |
|
546 | |||
532 | def setup(self, path=None, |
|
547 | def setup(self, path=None, | |
533 | startDate=None, |
|
548 | startDate=None, | |
534 | endDate=None, |
|
549 | endDate=None, | |
535 | startTime=datetime.time(0,0,0), |
|
550 | startTime=datetime.time(0,0,0), | |
536 | endTime=datetime.time(23,59,59), |
|
551 | endTime=datetime.time(23,59,59), | |
537 | set=0, |
|
552 | set=0, | |
538 | expLabel = "", |
|
553 | expLabel = "", | |
539 | ext = None, |
|
554 | ext = None, | |
540 | online = False, |
|
555 | online = False, | |
541 | delay = 60, |
|
556 | delay = 60, | |
542 | walk = True): |
|
557 | walk = True): | |
543 |
|
558 | |||
544 | if path == None: |
|
559 | if path == None: | |
545 | raise ValueError, "The path is not valid" |
|
560 | raise ValueError, "The path is not valid" | |
546 |
|
561 | |||
547 | if ext == None: |
|
562 | if ext == None: | |
548 | ext = self.ext |
|
563 | ext = self.ext | |
549 |
|
564 | |||
550 | if not(online): |
|
565 | if not(online): | |
551 | print "Searching files in offline mode ..." |
|
566 | print "Searching files in offline mode ..." | |
552 | pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate, |
|
567 | pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate, | |
553 | startTime=startTime, endTime=endTime, |
|
568 | startTime=startTime, endTime=endTime, | |
554 | set=set, expLabel=expLabel, ext=ext, |
|
569 | set=set, expLabel=expLabel, ext=ext, | |
555 | walk=walk) |
|
570 | walk=walk) | |
556 |
|
571 | |||
557 | if not(pathList): |
|
572 | if not(pathList): | |
558 | print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path, |
|
573 | print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path, | |
559 | datetime.datetime.combine(startDate,startTime).ctime(), |
|
574 | datetime.datetime.combine(startDate,startTime).ctime(), | |
560 | datetime.datetime.combine(endDate,endTime).ctime()) |
|
575 | datetime.datetime.combine(endDate,endTime).ctime()) | |
561 |
|
576 | |||
562 | sys.exit(-1) |
|
577 | sys.exit(-1) | |
563 |
|
578 | |||
564 | self.fileIndex = -1 |
|
579 | self.fileIndex = -1 | |
565 | self.pathList = pathList |
|
580 | self.pathList = pathList | |
566 | self.filenameList = filenameList |
|
581 | self.filenameList = filenameList | |
567 |
|
582 | |||
568 | self.online = online |
|
583 | self.online = online | |
569 | self.delay = delay |
|
584 | self.delay = delay | |
570 | ext = ext.lower() |
|
585 | ext = ext.lower() | |
571 | self.ext = ext |
|
586 | self.ext = ext | |
572 |
|
587 | |||
573 | if not(self.setNextFile()): |
|
588 | if not(self.setNextFile()): | |
574 | if (startDate!=None) and (endDate!=None): |
|
589 | if (startDate!=None) and (endDate!=None): | |
575 | print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime()) |
|
590 | print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime()) | |
576 | elif startDate != None: |
|
591 | elif startDate != None: | |
577 | print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime()) |
|
592 | print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime()) | |
578 | else: |
|
593 | else: | |
579 | print "No files" |
|
594 | print "No files" | |
580 |
|
595 | |||
581 | sys.exit(-1) |
|
596 | sys.exit(-1) | |
582 |
|
597 | |||
583 |
|
598 | |||
584 |
|
599 | |||
585 | def readBlock(self): |
|
600 | def readBlock(self): | |
586 | dataObj = self.fitsObj[self.blockIndex] |
|
601 | dataObj = self.fitsObj[self.blockIndex] | |
587 |
|
602 | |||
588 | self.data = dataObj.data |
|
603 | self.data = dataObj.data | |
589 | self.data_header_dict = dataObj.header |
|
604 | self.data_header_dict = dataObj.header | |
590 | self.utc = self.data_header_dict['UTCTIME'] |
|
605 | self.utc = self.data_header_dict['UTCTIME'] | |
591 |
|
606 | |||
592 | self.flagIsNewFile = 0 |
|
607 | self.flagIsNewFile = 0 | |
593 | self.blockIndex += 1 |
|
608 | self.blockIndex += 1 | |
594 | self.nTotalBlocks += 1 |
|
609 | self.nTotalBlocks += 1 | |
595 | self.nReadBlocks += 1 |
|
610 | self.nReadBlocks += 1 | |
596 |
|
611 | |||
597 | return 1 |
|
612 | return 1 | |
598 |
|
613 | |||
599 | def __jumpToLastBlock(self): |
|
614 | def __jumpToLastBlock(self): | |
600 | raise ValueError, "No implemented" |
|
615 | raise ValueError, "No implemented" | |
601 |
|
616 | |||
602 | def __waitNewBlock(self): |
|
617 | def __waitNewBlock(self): | |
603 | """ |
|
618 | """ | |
604 | Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma. |
|
619 | Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma. | |
605 |
|
620 | |||
606 | Si el modo de lectura es OffLine siempre retorn 0 |
|
621 | Si el modo de lectura es OffLine siempre retorn 0 | |
607 | """ |
|
622 | """ | |
608 | if not self.online: |
|
623 | if not self.online: | |
609 | return 0 |
|
624 | return 0 | |
610 |
|
625 | |||
611 | if (self.nReadBlocks >= self.dataBlocksPerFile): |
|
626 | if (self.nReadBlocks >= self.dataBlocksPerFile): | |
612 | return 0 |
|
627 | return 0 | |
613 |
|
628 | |||
614 | currentPointer = self.fp.tell() |
|
629 | currentPointer = self.fp.tell() | |
615 |
|
630 | |||
616 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
631 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize | |
617 |
|
632 | |||
618 | for nTries in range( self.nTries ): |
|
633 | for nTries in range( self.nTries ): | |
619 |
|
634 | |||
620 | self.fp.close() |
|
635 | self.fp.close() | |
621 | self.fp = open( self.filename, 'rb' ) |
|
636 | self.fp = open( self.filename, 'rb' ) | |
622 | self.fp.seek( currentPointer ) |
|
637 | self.fp.seek( currentPointer ) | |
623 |
|
638 | |||
624 | self.fileSize = os.path.getsize( self.filename ) |
|
639 | self.fileSize = os.path.getsize( self.filename ) | |
625 | currentSize = self.fileSize - currentPointer |
|
640 | currentSize = self.fileSize - currentPointer | |
626 |
|
641 | |||
627 | if ( currentSize >= neededSize ): |
|
642 | if ( currentSize >= neededSize ): | |
628 | self.__rdBasicHeader() |
|
643 | self.__rdBasicHeader() | |
629 | return 1 |
|
644 | return 1 | |
630 |
|
645 | |||
631 | print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1) |
|
646 | print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1) | |
632 | sleep( self.delay ) |
|
647 | sleep( self.delay ) | |
633 |
|
648 | |||
634 |
|
649 | |||
635 | return 0 |
|
650 | return 0 | |
636 |
|
651 | |||
637 | def __setNewBlock(self): |
|
652 | def __setNewBlock(self): | |
638 |
|
653 | |||
639 | if self.online: |
|
654 | if self.online: | |
640 | self.__jumpToLastBlock() |
|
655 | self.__jumpToLastBlock() | |
641 |
|
656 | |||
642 | if self.flagIsNewFile: |
|
657 | if self.flagIsNewFile: | |
643 | return 1 |
|
658 | return 1 | |
644 |
|
659 | |||
645 | self.lastUTTime = self.utc |
|
660 | self.lastUTTime = self.utc | |
646 |
|
661 | |||
647 | if self.online: |
|
662 | if self.online: | |
648 | if self.__waitNewBlock(): |
|
663 | if self.__waitNewBlock(): | |
649 | return 1 |
|
664 | return 1 | |
650 |
|
665 | |||
651 | if self.nReadBlocks < self.dataBlocksPerFile: |
|
666 | if self.nReadBlocks < self.dataBlocksPerFile: | |
652 | return 1 |
|
667 | return 1 | |
653 |
|
668 | |||
654 | if not(self.setNextFile()): |
|
669 | if not(self.setNextFile()): | |
655 | return 0 |
|
670 | return 0 | |
656 |
|
671 | |||
657 | deltaTime = self.utc - self.lastUTTime |
|
672 | deltaTime = self.utc - self.lastUTTime | |
658 |
|
673 | |||
659 | self.flagDiscontinuousBlock = 0 |
|
674 | self.flagDiscontinuousBlock = 0 | |
660 |
|
675 | |||
661 | if deltaTime > self.maxTimeStep: |
|
676 | if deltaTime > self.maxTimeStep: | |
662 | self.flagDiscontinuousBlock = 1 |
|
677 | self.flagDiscontinuousBlock = 1 | |
663 |
|
678 | |||
664 | return 1 |
|
679 | return 1 | |
665 |
|
680 | |||
666 |
|
681 | |||
667 | def readNextBlock(self): |
|
682 | def readNextBlock(self): | |
668 | if not(self.__setNewBlock()): |
|
683 | if not(self.__setNewBlock()): | |
669 | return 0 |
|
684 | return 0 | |
670 |
|
685 | |||
671 | if not(self.readBlock()): |
|
686 | if not(self.readBlock()): | |
672 | return 0 |
|
687 | return 0 | |
673 |
|
688 | |||
674 | return 1 |
|
689 | return 1 | |
675 |
|
690 | |||
676 |
|
691 | |||
677 | def getData(self): |
|
692 | def getData(self): | |
678 |
|
693 | |||
679 | if self.flagNoMoreFiles: |
|
694 | if self.flagNoMoreFiles: | |
680 | self.dataOut.flagNoData = True |
|
695 | self.dataOut.flagNoData = True | |
681 | print 'Process finished' |
|
696 | print 'Process finished' | |
682 | return 0 |
|
697 | return 0 | |
683 |
|
698 | |||
684 | self.flagDiscontinuousBlock = 0 |
|
699 | self.flagDiscontinuousBlock = 0 | |
685 | self.flagIsNewBlock = 0 |
|
700 | self.flagIsNewBlock = 0 | |
686 |
|
701 | |||
687 | if not(self.readNextBlock()): |
|
702 | if not(self.readNextBlock()): | |
688 | return 0 |
|
703 | return 0 | |
689 |
|
704 | |||
690 | if self.data == None: |
|
705 | if self.data == None: | |
691 | self.dataOut.flagNoData = True |
|
706 | self.dataOut.flagNoData = True | |
692 | return 0 |
|
707 | return 0 | |
693 |
|
708 | |||
694 | self.dataOut.data = self.data |
|
709 | self.dataOut.data = self.data | |
695 | self.dataOut.data_header = self.data_header_dict |
|
710 | self.dataOut.data_header = self.data_header_dict | |
696 | self.dataOut.utctime = self.utc |
|
711 | self.dataOut.utctime = self.utc | |
697 |
|
712 | |||
698 | self.dataOut.header = self.header_dict |
|
713 | # self.dataOut.header = self.header_dict | |
699 | self.dataOut.expName = self.expName |
|
714 | # self.dataOut.expName = self.expName | |
700 | self.dataOut.nChannels = self.nChannels |
|
715 | # self.dataOut.nChannels = self.nChannels | |
701 | self.dataOut.timeZone = self.timeZone |
|
716 | # self.dataOut.timeZone = self.timeZone | |
702 | self.dataOut.dataBlocksPerFile = self.dataBlocksPerFile |
|
717 | # self.dataOut.dataBlocksPerFile = self.dataBlocksPerFile | |
703 | self.dataOut.comments = self.comments |
|
718 | # self.dataOut.comments = self.comments | |
704 | self.dataOut.timeInterval = self.timeInterval |
|
719 | # # self.dataOut.timeInterval = self.timeInterval | |
705 | self.dataOut.channelList = self.channelList |
|
720 | # self.dataOut.channelList = self.channelList | |
706 | self.dataOut.heightList = self.heightList |
|
721 | # self.dataOut.heightList = self.heightList | |
707 | self.dataOut.flagNoData = False |
|
722 | self.dataOut.flagNoData = False | |
708 |
|
723 | |||
709 | return self.dataOut.data |
|
724 | return self.dataOut.data | |
710 |
|
725 | |||
711 | def run(self, **kwargs): |
|
726 | def run(self, **kwargs): | |
712 |
|
727 | |||
713 | if not(self.isConfig): |
|
728 | if not(self.isConfig): | |
714 | self.setup(**kwargs) |
|
729 | self.setup(**kwargs) | |
715 | self.isConfig = True |
|
730 | self.isConfig = True | |
716 |
|
731 | |||
717 | self.getData() |
|
732 | self.getData() | |
718 |
|
733 | |||
719 | class SpectraHeisWriter(Operation): |
|
734 | class SpectraHeisWriter(Operation): | |
720 | # set = None |
|
735 | # set = None | |
721 | setFile = None |
|
736 | setFile = None | |
722 | idblock = None |
|
737 | idblock = None | |
723 | doypath = None |
|
738 | doypath = None | |
724 | subfolder = None |
|
739 | subfolder = None | |
725 |
|
740 | |||
726 | def __init__(self): |
|
741 | def __init__(self): | |
727 | self.wrObj = Fits() |
|
742 | self.wrObj = Fits() | |
728 | # self.dataOut = dataOut |
|
743 | # self.dataOut = dataOut | |
729 | self.nTotalBlocks=0 |
|
744 | self.nTotalBlocks=0 | |
730 | # self.set = None |
|
745 | # self.set = None | |
731 | self.setFile = None |
|
746 | self.setFile = None | |
732 | self.idblock = 0 |
|
747 | self.idblock = 0 | |
733 | self.wrpath = None |
|
748 | self.wrpath = None | |
734 | self.doypath = None |
|
749 | self.doypath = None | |
735 | self.subfolder = None |
|
750 | self.subfolder = None | |
736 | self.isConfig = False |
|
751 | self.isConfig = False | |
737 |
|
752 | |||
738 | def isNumber(str): |
|
753 | def isNumber(str): | |
739 | """ |
|
754 | """ | |
740 | Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero. |
|
755 | Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero. | |
741 |
|
756 | |||
742 | Excepciones: |
|
757 | Excepciones: | |
743 | Si un determinado string no puede ser convertido a numero |
|
758 | Si un determinado string no puede ser convertido a numero | |
744 | Input: |
|
759 | Input: | |
745 | str, string al cual se le analiza para determinar si convertible a un numero o no |
|
760 | str, string al cual se le analiza para determinar si convertible a un numero o no | |
746 |
|
761 | |||
747 | Return: |
|
762 | Return: | |
748 | True : si el string es uno numerico |
|
763 | True : si el string es uno numerico | |
749 | False : no es un string numerico |
|
764 | False : no es un string numerico | |
750 | """ |
|
765 | """ | |
751 | try: |
|
766 | try: | |
752 | float( str ) |
|
767 | float( str ) | |
753 | return True |
|
768 | return True | |
754 | except: |
|
769 | except: | |
755 | return False |
|
770 | return False | |
756 |
|
771 | |||
757 | def setup(self, dataOut, wrpath): |
|
772 | def setup(self, dataOut, wrpath): | |
758 |
|
773 | |||
759 | if not(os.path.exists(wrpath)): |
|
774 | if not(os.path.exists(wrpath)): | |
760 | os.mkdir(wrpath) |
|
775 | os.mkdir(wrpath) | |
761 |
|
776 | |||
762 | self.wrpath = wrpath |
|
777 | self.wrpath = wrpath | |
763 | # self.setFile = 0 |
|
778 | # self.setFile = 0 | |
764 | self.dataOut = dataOut |
|
779 | self.dataOut = dataOut | |
765 |
|
780 | |||
766 | def putData(self): |
|
781 | def putData(self): | |
767 | name= time.localtime( self.dataOut.utctime) |
|
782 | name= time.localtime( self.dataOut.utctime) | |
768 | ext=".fits" |
|
783 | ext=".fits" | |
769 |
|
784 | |||
770 | if self.doypath == None: |
|
785 | if self.doypath == None: | |
771 | self.subfolder = 'F%4.4d%3.3d_%d' % (name.tm_year,name.tm_yday,time.mktime(datetime.datetime.now().timetuple())) |
|
786 | self.subfolder = 'F%4.4d%3.3d_%d' % (name.tm_year,name.tm_yday,time.mktime(datetime.datetime.now().timetuple())) | |
772 | self.doypath = os.path.join( self.wrpath, self.subfolder ) |
|
787 | self.doypath = os.path.join( self.wrpath, self.subfolder ) | |
773 | os.mkdir(self.doypath) |
|
788 | os.mkdir(self.doypath) | |
774 |
|
789 | |||
775 | if self.setFile == None: |
|
790 | if self.setFile == None: | |
776 | # self.set = self.dataOut.set |
|
791 | # self.set = self.dataOut.set | |
777 | self.setFile = 0 |
|
792 | self.setFile = 0 | |
778 | # if self.set != self.dataOut.set: |
|
793 | # if self.set != self.dataOut.set: | |
779 | ## self.set = self.dataOut.set |
|
794 | ## self.set = self.dataOut.set | |
780 | # self.setFile = 0 |
|
795 | # self.setFile = 0 | |
781 |
|
796 | |||
782 | #make the filename |
|
797 | #make the filename | |
783 | thisFile = 'D%4.4d%3.3d_%3.3d%s' % (name.tm_year,name.tm_yday,self.setFile,ext) |
|
798 | thisFile = 'D%4.4d%3.3d_%3.3d%s' % (name.tm_year,name.tm_yday,self.setFile,ext) | |
784 |
|
799 | |||
785 | filename = os.path.join(self.wrpath,self.subfolder, thisFile) |
|
800 | filename = os.path.join(self.wrpath,self.subfolder, thisFile) | |
786 |
|
801 | |||
787 | idblock = numpy.array([self.idblock],dtype="int64") |
|
802 | idblock = numpy.array([self.idblock],dtype="int64") | |
788 | header=self.wrObj.cFImage(idblock=idblock, |
|
803 | header=self.wrObj.cFImage(idblock=idblock, | |
789 | year=time.gmtime(self.dataOut.utctime).tm_year, |
|
804 | year=time.gmtime(self.dataOut.utctime).tm_year, | |
790 | month=time.gmtime(self.dataOut.utctime).tm_mon, |
|
805 | month=time.gmtime(self.dataOut.utctime).tm_mon, | |
791 | day=time.gmtime(self.dataOut.utctime).tm_mday, |
|
806 | day=time.gmtime(self.dataOut.utctime).tm_mday, | |
792 | hour=time.gmtime(self.dataOut.utctime).tm_hour, |
|
807 | hour=time.gmtime(self.dataOut.utctime).tm_hour, | |
793 | minute=time.gmtime(self.dataOut.utctime).tm_min, |
|
808 | minute=time.gmtime(self.dataOut.utctime).tm_min, | |
794 | second=time.gmtime(self.dataOut.utctime).tm_sec) |
|
809 | second=time.gmtime(self.dataOut.utctime).tm_sec) | |
795 |
|
810 | |||
796 | c=3E8 |
|
811 | c=3E8 | |
797 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
812 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] | |
798 | freq=numpy.arange(-1*self.dataOut.nHeights/2.,self.dataOut.nHeights/2.)*(c/(2*deltaHeight*1000)) |
|
813 | freq=numpy.arange(-1*self.dataOut.nHeights/2.,self.dataOut.nHeights/2.)*(c/(2*deltaHeight*1000)) | |
799 |
|
814 | |||
800 | colList = [] |
|
815 | colList = [] | |
801 |
|
816 | |||
802 | colFreq=self.wrObj.setColF(name="freq", format=str(self.dataOut.nFFTPoints)+'E', array=freq) |
|
817 | colFreq=self.wrObj.setColF(name="freq", format=str(self.dataOut.nFFTPoints)+'E', array=freq) | |
803 |
|
818 | |||
804 | colList.append(colFreq) |
|
819 | colList.append(colFreq) | |
805 |
|
820 | |||
806 | nchannel=self.dataOut.nChannels |
|
821 | nchannel=self.dataOut.nChannels | |
807 |
|
822 | |||
808 | for i in range(nchannel): |
|
823 | for i in range(nchannel): | |
809 | col = self.wrObj.writeData(name="PCh"+str(i+1), |
|
824 | col = self.wrObj.writeData(name="PCh"+str(i+1), | |
810 | format=str(self.dataOut.nFFTPoints)+'E', |
|
825 | format=str(self.dataOut.nFFTPoints)+'E', | |
811 | data=10*numpy.log10(self.dataOut.data_spc[i,:])) |
|
826 | data=10*numpy.log10(self.dataOut.data_spc[i,:])) | |
812 |
|
827 | |||
813 | colList.append(col) |
|
828 | colList.append(col) | |
814 |
|
829 | |||
815 | data=self.wrObj.Ctable(colList=colList) |
|
830 | data=self.wrObj.Ctable(colList=colList) | |
816 |
|
831 | |||
817 | self.wrObj.CFile(header,data) |
|
832 | self.wrObj.CFile(header,data) | |
818 |
|
833 | |||
819 | self.wrObj.wFile(filename) |
|
834 | self.wrObj.wFile(filename) | |
820 |
|
835 | |||
821 | #update the setFile |
|
836 | #update the setFile | |
822 | self.setFile += 1 |
|
837 | self.setFile += 1 | |
823 | self.idblock += 1 |
|
838 | self.idblock += 1 | |
824 |
|
839 | |||
825 | return 1 |
|
840 | return 1 | |
826 |
|
841 | |||
827 | def run(self, dataOut, **kwargs): |
|
842 | def run(self, dataOut, **kwargs): | |
828 |
|
843 | |||
829 | if not(self.isConfig): |
|
844 | if not(self.isConfig): | |
830 |
|
845 | |||
831 | self.setup(dataOut, **kwargs) |
|
846 | self.setup(dataOut, **kwargs) | |
832 | self.isConfig = True |
|
847 | self.isConfig = True | |
833 |
|
848 | |||
834 | self.putData() No newline at end of file |
|
849 | self.putData() |
1 | NO CONTENT: modified file |
|
NO CONTENT: modified file | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: modified file |
|
NO CONTENT: modified file | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: modified file |
|
NO CONTENT: modified file | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: modified file |
|
NO CONTENT: modified file | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: modified file |
|
NO CONTENT: modified file | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: modified file |
|
NO CONTENT: modified file | ||
The requested commit or file is too big and content was truncated. Show full diff |
General Comments 0
You need to be logged in to leave comments.
Login now