@@ -1,666 +1,673 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on September , 2012 |
|
2 | Created on September , 2012 | |
3 | @author: |
|
3 | @author: | |
4 | ''' |
|
4 | ''' | |
5 | from xml.etree.ElementTree import Element, SubElement, ElementTree |
|
5 | from xml.etree.ElementTree import Element, SubElement, ElementTree | |
6 | from xml.etree import ElementTree as ET |
|
6 | from xml.etree import ElementTree as ET | |
7 | from xml.dom import minidom |
|
7 | from xml.dom import minidom | |
8 |
|
8 | |||
9 | import sys |
|
9 | import sys | |
10 | import datetime |
|
10 | import datetime | |
11 | from model.jrodataIO import * |
|
11 | from model.jrodataIO import * | |
12 | from model.jroprocessing import * |
|
12 | from model.jroprocessing import * | |
13 | from model.jroplot import * |
|
13 | from model.jroplot import * | |
14 |
|
14 | |||
15 | def prettify(elem): |
|
15 | def prettify(elem): | |
16 | """Return a pretty-printed XML string for the Element. |
|
16 | """Return a pretty-printed XML string for the Element. | |
17 | """ |
|
17 | """ | |
18 | rough_string = ET.tostring(elem, 'utf-8') |
|
18 | rough_string = ET.tostring(elem, 'utf-8') | |
19 | reparsed = minidom.parseString(rough_string) |
|
19 | reparsed = minidom.parseString(rough_string) | |
20 | return reparsed.toprettyxml(indent=" ") |
|
20 | return reparsed.toprettyxml(indent=" ") | |
21 |
|
21 | |||
22 | class ParameterConf(): |
|
22 | class ParameterConf(): | |
23 |
|
23 | |||
24 | id = None |
|
24 | id = None | |
25 | name = None |
|
25 | name = None | |
26 | value = None |
|
26 | value = None | |
27 | format = None |
|
27 | format = None | |
28 |
|
28 | |||
29 | ELEMENTNAME = 'Parameter' |
|
29 | ELEMENTNAME = 'Parameter' | |
30 |
|
30 | |||
31 | def __init__(self): |
|
31 | def __init__(self): | |
32 |
|
32 | |||
33 | self.format = 'str' |
|
33 | self.format = 'str' | |
34 |
|
34 | |||
35 | def getElementName(self): |
|
35 | def getElementName(self): | |
36 |
|
36 | |||
37 | return self.ELEMENTNAME |
|
37 | return self.ELEMENTNAME | |
38 |
|
38 | |||
39 | def getValue(self): |
|
39 | def getValue(self): | |
40 |
|
40 | |||
41 | if self.format == 'list': |
|
41 | if self.format == 'list': | |
42 | strList = self.value.split(',') |
|
42 | strList = self.value.split(',') | |
43 | return strList |
|
43 | return strList | |
44 |
|
44 | |||
45 | if self.format == 'intlist': |
|
45 | if self.format == 'intlist': | |
46 | strList = self.value.split(',') |
|
46 | strList = self.value.split(',') | |
47 | intList = [int(x) for x in strList] |
|
47 | intList = [int(x) for x in strList] | |
48 | return intList |
|
48 | return intList | |
49 |
|
49 | |||
50 | if self.format == 'floatlist': |
|
50 | if self.format == 'floatlist': | |
51 | strList = self.value.split(',') |
|
51 | strList = self.value.split(',') | |
52 | floatList = [float(x) for x in strList] |
|
52 | floatList = [float(x) for x in strList] | |
53 | return floatList |
|
53 | return floatList | |
54 |
|
54 | |||
55 | if self.format == 'date': |
|
55 | if self.format == 'date': | |
56 | strList = self.value.split('/') |
|
56 | strList = self.value.split('/') | |
57 | intList = [int(x) for x in strList] |
|
57 | intList = [int(x) for x in strList] | |
58 | date = datetime.date(intList[0], intList[1], intList[2]) |
|
58 | date = datetime.date(intList[0], intList[1], intList[2]) | |
59 | return date |
|
59 | return date | |
60 |
|
60 | |||
61 | if self.format == 'time': |
|
61 | if self.format == 'time': | |
62 | strList = self.value.split(':') |
|
62 | strList = self.value.split(':') | |
63 | intList = [int(x) for x in strList] |
|
63 | intList = [int(x) for x in strList] | |
64 | time = datetime.time(intList[0], intList[1], intList[2]) |
|
64 | time = datetime.time(intList[0], intList[1], intList[2]) | |
65 | return time |
|
65 | return time | |
66 |
|
66 | |||
67 | func = eval(self.format) |
|
67 | func = eval(self.format) | |
68 |
|
68 | |||
69 | return func(self.value) |
|
69 | return func(self.value) | |
70 |
|
70 | |||
71 | def setup(self, id, name, value, format='str'): |
|
71 | def setup(self, id, name, value, format='str'): | |
72 |
|
72 | |||
73 | self.id = id |
|
73 | self.id = id | |
74 | self.name = name |
|
74 | self.name = name | |
75 | self.value = str(value) |
|
75 | self.value = str(value) | |
76 | self.format = format |
|
76 | self.format = format | |
77 |
|
77 | |||
78 | def makeXml(self, opElement): |
|
78 | def makeXml(self, opElement): | |
79 |
|
79 | |||
80 | parmElement = SubElement(opElement, self.ELEMENTNAME) |
|
80 | parmElement = SubElement(opElement, self.ELEMENTNAME) | |
81 | parmElement.set('id', str(self.id)) |
|
81 | parmElement.set('id', str(self.id)) | |
82 | parmElement.set('name', self.name) |
|
82 | parmElement.set('name', self.name) | |
83 | parmElement.set('value', self.value) |
|
83 | parmElement.set('value', self.value) | |
84 | parmElement.set('format', self.format) |
|
84 | parmElement.set('format', self.format) | |
85 |
|
85 | |||
86 | def readXml(self, parmElement): |
|
86 | def readXml(self, parmElement): | |
87 |
|
87 | |||
88 | self.id = parmElement.get('id') |
|
88 | self.id = parmElement.get('id') | |
89 | self.name = parmElement.get('name') |
|
89 | self.name = parmElement.get('name') | |
90 | self.value = parmElement.get('value') |
|
90 | self.value = parmElement.get('value') | |
91 | self.format = parmElement.get('format') |
|
91 | self.format = parmElement.get('format') | |
92 |
|
92 | |||
93 | def printattr(self): |
|
93 | def printattr(self): | |
94 |
|
94 | |||
95 | print "Parameter[%s]: name = %s, value = %s, format = %s" %(self.id, self.name, self.value, self.format) |
|
95 | print "Parameter[%s]: name = %s, value = %s, format = %s" %(self.id, self.name, self.value, self.format) | |
96 |
|
96 | |||
97 | class OperationConf(): |
|
97 | class OperationConf(): | |
98 |
|
98 | |||
99 | id = None |
|
99 | id = None | |
100 | name = None |
|
100 | name = None | |
101 | priority = None |
|
101 | priority = None | |
102 | type = None |
|
102 | type = None | |
103 |
|
103 | |||
104 | parmConfObjList = [] |
|
104 | parmConfObjList = [] | |
105 |
|
105 | |||
106 | ELEMENTNAME = 'Operation' |
|
106 | ELEMENTNAME = 'Operation' | |
107 |
|
107 | |||
108 | def __init__(self): |
|
108 | def __init__(self): | |
109 |
|
109 | |||
110 | id = 0 |
|
110 | id = 0 | |
111 | name = None |
|
111 | name = None | |
112 | priority = None |
|
112 | priority = None | |
113 | type = 'self' |
|
113 | type = 'self' | |
114 |
|
114 | |||
115 |
|
115 | |||
116 | def __getNewId(self): |
|
116 | def __getNewId(self): | |
117 |
|
117 | |||
118 | return int(self.id)*10 + len(self.parmConfObjList) + 1 |
|
118 | return int(self.id)*10 + len(self.parmConfObjList) + 1 | |
119 |
|
119 | |||
120 | def getElementName(self): |
|
120 | def getElementName(self): | |
121 |
|
121 | |||
122 | return self.ELEMENTNAME |
|
122 | return self.ELEMENTNAME | |
123 |
|
123 | |||
124 | def getParameterObjList(self): |
|
124 | def getParameterObjList(self): | |
125 |
|
125 | |||
126 | return self.parmConfObjList |
|
126 | return self.parmConfObjList | |
127 |
|
127 | |||
128 | def setup(self, id, name, priority, type): |
|
128 | def setup(self, id, name, priority, type): | |
129 |
|
129 | |||
130 | self.id = id |
|
130 | self.id = id | |
131 | self.name = name |
|
131 | self.name = name | |
132 | self.type = type |
|
132 | self.type = type | |
133 | self.priority = priority |
|
133 | self.priority = priority | |
134 |
|
134 | |||
135 | self.parmConfObjList = [] |
|
135 | self.parmConfObjList = [] | |
136 |
|
136 | |||
137 | def addParameter(self, name, value, format='str'): |
|
137 | def addParameter(self, name, value, format='str'): | |
138 |
|
138 | |||
139 | id = self.__getNewId() |
|
139 | id = self.__getNewId() | |
140 |
|
140 | |||
141 | parmConfObj = ParameterConf() |
|
141 | parmConfObj = ParameterConf() | |
142 | parmConfObj.setup(id, name, value, format) |
|
142 | parmConfObj.setup(id, name, value, format) | |
143 |
|
143 | |||
144 | self.parmConfObjList.append(parmConfObj) |
|
144 | self.parmConfObjList.append(parmConfObj) | |
145 |
|
145 | |||
146 | return parmConfObj |
|
146 | return parmConfObj | |
147 |
|
147 | |||
148 | def makeXml(self, upElement): |
|
148 | def makeXml(self, upElement): | |
149 |
|
149 | |||
150 | opElement = SubElement(upElement, self.ELEMENTNAME) |
|
150 | opElement = SubElement(upElement, self.ELEMENTNAME) | |
151 | opElement.set('id', str(self.id)) |
|
151 | opElement.set('id', str(self.id)) | |
152 | opElement.set('name', self.name) |
|
152 | opElement.set('name', self.name) | |
153 | opElement.set('type', self.type) |
|
153 | opElement.set('type', self.type) | |
154 | opElement.set('priority', str(self.priority)) |
|
154 | opElement.set('priority', str(self.priority)) | |
155 |
|
155 | |||
156 | for parmConfObj in self.parmConfObjList: |
|
156 | for parmConfObj in self.parmConfObjList: | |
157 | parmConfObj.makeXml(opElement) |
|
157 | parmConfObj.makeXml(opElement) | |
158 |
|
158 | |||
159 | def readXml(self, opElement): |
|
159 | def readXml(self, opElement): | |
160 |
|
160 | |||
161 | self.id = opElement.get('id') |
|
161 | self.id = opElement.get('id') | |
162 | self.name = opElement.get('name') |
|
162 | self.name = opElement.get('name') | |
163 | self.type = opElement.get('type') |
|
163 | self.type = opElement.get('type') | |
164 | self.priority = opElement.get('priority') |
|
164 | self.priority = opElement.get('priority') | |
165 |
|
165 | |||
166 | self.parmConfObjList = [] |
|
166 | self.parmConfObjList = [] | |
167 |
|
167 | |||
168 | parmElementList = opElement.getiterator(ParameterConf().getElementName()) |
|
168 | parmElementList = opElement.getiterator(ParameterConf().getElementName()) | |
169 |
|
169 | |||
170 | for parmElement in parmElementList: |
|
170 | for parmElement in parmElementList: | |
171 | parmConfObj = ParameterConf() |
|
171 | parmConfObj = ParameterConf() | |
172 | parmConfObj.readXml(parmElement) |
|
172 | parmConfObj.readXml(parmElement) | |
173 | self.parmConfObjList.append(parmConfObj) |
|
173 | self.parmConfObjList.append(parmConfObj) | |
174 |
|
174 | |||
175 | def printattr(self): |
|
175 | def printattr(self): | |
176 |
|
176 | |||
177 | print "%s[%s]: name = %s, type = %s, priority = %s" %(self.ELEMENTNAME, |
|
177 | print "%s[%s]: name = %s, type = %s, priority = %s" %(self.ELEMENTNAME, | |
178 | self.id, |
|
178 | self.id, | |
179 | self.name, |
|
179 | self.name, | |
180 | self.type, |
|
180 | self.type, | |
181 | self.priority) |
|
181 | self.priority) | |
182 |
|
182 | |||
183 | for parmConfObj in self.parmConfObjList: |
|
183 | for parmConfObj in self.parmConfObjList: | |
184 | parmConfObj.printattr() |
|
184 | parmConfObj.printattr() | |
185 |
|
185 | |||
186 | def createObject(self): |
|
186 | def createObject(self): | |
187 |
|
187 | |||
188 | if self.type == 'self': |
|
188 | if self.type == 'self': | |
189 | raise ValueError, "This operation type cannot be created" |
|
189 | raise ValueError, "This operation type cannot be created" | |
190 |
|
190 | |||
191 | if self.type == 'other': |
|
191 | if self.type == 'other': | |
192 | className = eval(self.name) |
|
192 | className = eval(self.name) | |
193 | opObj = className() |
|
193 | opObj = className() | |
194 |
|
194 | |||
195 | return opObj |
|
195 | return opObj | |
196 |
|
196 | |||
197 | class ProcUnitConf(): |
|
197 | class ProcUnitConf(): | |
198 |
|
198 | |||
199 | id = None |
|
199 | id = None | |
200 | name = None |
|
200 | name = None | |
201 | datatype = None |
|
201 | datatype = None | |
202 | inputId = None |
|
202 | inputId = None | |
203 |
|
203 | |||
204 | opConfObjList = [] |
|
204 | opConfObjList = [] | |
205 |
|
205 | |||
206 | procUnitObj = None |
|
206 | procUnitObj = None | |
207 | opObjList = [] |
|
207 | opObjList = [] | |
208 |
|
208 | |||
209 | ELEMENTNAME = 'ProcUnit' |
|
209 | ELEMENTNAME = 'ProcUnit' | |
210 |
|
210 | |||
211 | def __init__(self): |
|
211 | def __init__(self): | |
212 |
|
212 | |||
213 | self.id = None |
|
213 | self.id = None | |
214 | self.datatype = None |
|
214 | self.datatype = None | |
215 | self.name = None |
|
215 | self.name = None | |
216 | self.inputId = None |
|
216 | self.inputId = None | |
217 |
|
217 | |||
218 | self.opConfObjList = [] |
|
218 | self.opConfObjList = [] | |
219 |
|
219 | |||
220 | self.procUnitObj = None |
|
220 | self.procUnitObj = None | |
221 | self.opObjDict = {} |
|
221 | self.opObjDict = {} | |
222 |
|
222 | |||
223 | def __getPriority(self): |
|
223 | def __getPriority(self): | |
224 |
|
224 | |||
225 | return len(self.opConfObjList)+1 |
|
225 | return len(self.opConfObjList)+1 | |
226 |
|
226 | |||
227 | def __getNewId(self): |
|
227 | def __getNewId(self): | |
228 |
|
228 | |||
229 | return int(self.id)*10 + len(self.opConfObjList) + 1 |
|
229 | return int(self.id)*10 + len(self.opConfObjList) + 1 | |
230 |
|
230 | |||
231 | def getElementName(self): |
|
231 | def getElementName(self): | |
232 |
|
232 | |||
233 | return self.ELEMENTNAME |
|
233 | return self.ELEMENTNAME | |
234 |
|
234 | |||
235 | def getId(self): |
|
235 | def getId(self): | |
236 |
|
236 | |||
237 | return str(self.id) |
|
237 | return str(self.id) | |
238 |
|
238 | |||
239 | def getInputId(self): |
|
239 | def getInputId(self): | |
240 |
|
240 | |||
241 | return str(self.inputId) |
|
241 | return str(self.inputId) | |
242 |
|
242 | |||
243 | def getOperationObjList(self): |
|
243 | def getOperationObjList(self): | |
244 |
|
244 | |||
245 | return self.opConfObjList |
|
245 | return self.opConfObjList | |
246 |
|
246 | |||
247 | def getProcUnitObj(self): |
|
247 | def getProcUnitObj(self): | |
248 |
|
248 | |||
249 | return self.procUnitObj |
|
249 | return self.procUnitObj | |
250 |
|
250 | |||
251 | def setup(self, id, name, datatype, inputId): |
|
251 | def setup(self, id, name, datatype, inputId): | |
252 |
|
252 | |||
253 | self.id = id |
|
253 | self.id = id | |
254 | self.name = name |
|
254 | self.name = name | |
255 | self.datatype = datatype |
|
255 | self.datatype = datatype | |
256 | self.inputId = inputId |
|
256 | self.inputId = inputId | |
257 |
|
257 | |||
258 | self.opConfObjList = [] |
|
258 | self.opConfObjList = [] | |
259 |
|
259 | |||
260 | self.addOperation(name='init', optype='self') |
|
260 | self.addOperation(name='init', optype='self') | |
261 |
|
261 | |||
262 | def addOperation(self, name, optype='self'): |
|
262 | def addOperation(self, name, optype='self'): | |
263 |
|
263 | |||
264 | id = self.__getNewId() |
|
264 | id = self.__getNewId() | |
265 | priority = self.__getPriority() |
|
265 | priority = self.__getPriority() | |
266 |
|
266 | |||
267 | opConfObj = OperationConf() |
|
267 | opConfObj = OperationConf() | |
268 | opConfObj.setup(id, name=name, priority=priority, type=optype) |
|
268 | opConfObj.setup(id, name=name, priority=priority, type=optype) | |
269 |
|
269 | |||
270 | self.opConfObjList.append(opConfObj) |
|
270 | self.opConfObjList.append(opConfObj) | |
271 |
|
271 | |||
272 | return opConfObj |
|
272 | return opConfObj | |
273 |
|
273 | |||
274 | def makeXml(self, procUnitElement): |
|
274 | def makeXml(self, procUnitElement): | |
275 |
|
275 | |||
276 | upElement = SubElement(procUnitElement, self.ELEMENTNAME) |
|
276 | upElement = SubElement(procUnitElement, self.ELEMENTNAME) | |
277 | upElement.set('id', str(self.id)) |
|
277 | upElement.set('id', str(self.id)) | |
278 | upElement.set('name', self.name) |
|
278 | upElement.set('name', self.name) | |
279 | upElement.set('datatype', self.datatype) |
|
279 | upElement.set('datatype', self.datatype) | |
280 | upElement.set('inputId', str(self.inputId)) |
|
280 | upElement.set('inputId', str(self.inputId)) | |
281 |
|
281 | |||
282 | for opConfObj in self.opConfObjList: |
|
282 | for opConfObj in self.opConfObjList: | |
283 | opConfObj.makeXml(upElement) |
|
283 | opConfObj.makeXml(upElement) | |
284 |
|
284 | |||
285 | def readXml(self, upElement): |
|
285 | def readXml(self, upElement): | |
286 |
|
286 | |||
287 | self.id = upElement.get('id') |
|
287 | self.id = upElement.get('id') | |
288 | self.name = upElement.get('name') |
|
288 | self.name = upElement.get('name') | |
289 | self.datatype = upElement.get('datatype') |
|
289 | self.datatype = upElement.get('datatype') | |
290 | self.inputId = upElement.get('inputId') |
|
290 | self.inputId = upElement.get('inputId') | |
291 |
|
291 | |||
292 | self.opConfObjList = [] |
|
292 | self.opConfObjList = [] | |
293 |
|
293 | |||
294 | opElementList = upElement.getiterator(OperationConf().getElementName()) |
|
294 | opElementList = upElement.getiterator(OperationConf().getElementName()) | |
295 |
|
295 | |||
296 | for opElement in opElementList: |
|
296 | for opElement in opElementList: | |
297 | opConfObj = OperationConf() |
|
297 | opConfObj = OperationConf() | |
298 | opConfObj.readXml(opElement) |
|
298 | opConfObj.readXml(opElement) | |
299 | self.opConfObjList.append(opConfObj) |
|
299 | self.opConfObjList.append(opConfObj) | |
300 |
|
300 | |||
301 | def printattr(self): |
|
301 | def printattr(self): | |
302 |
|
302 | |||
303 | print "%s[%s]: name = %s, datatype = %s, inputId = %s" %(self.ELEMENTNAME, |
|
303 | print "%s[%s]: name = %s, datatype = %s, inputId = %s" %(self.ELEMENTNAME, | |
304 | self.id, |
|
304 | self.id, | |
305 | self.name, |
|
305 | self.name, | |
306 | self.datatype, |
|
306 | self.datatype, | |
307 | self.inputId) |
|
307 | self.inputId) | |
308 |
|
308 | |||
309 | for opConfObj in self.opConfObjList: |
|
309 | for opConfObj in self.opConfObjList: | |
310 | opConfObj.printattr() |
|
310 | opConfObj.printattr() | |
311 |
|
311 | |||
312 | def createObjects(self): |
|
312 | def createObjects(self): | |
313 |
|
313 | |||
314 | className = eval(self.name) |
|
314 | className = eval(self.name) | |
315 | procUnitObj = className() |
|
315 | procUnitObj = className() | |
316 |
|
316 | |||
317 | for opConfObj in self.opConfObjList: |
|
317 | for opConfObj in self.opConfObjList: | |
318 |
|
318 | |||
319 | if opConfObj.type == 'self': |
|
319 | if opConfObj.type == 'self': | |
320 | continue |
|
320 | continue | |
321 |
|
321 | |||
322 | opObj = opConfObj.createObject() |
|
322 | opObj = opConfObj.createObject() | |
323 |
|
323 | |||
324 | self.opObjDict[opConfObj.id] = opObj |
|
324 | self.opObjDict[opConfObj.id] = opObj | |
325 | procUnitObj.addOperation(opObj, opConfObj.id) |
|
325 | procUnitObj.addOperation(opObj, opConfObj.id) | |
326 |
|
326 | |||
327 | self.procUnitObj = procUnitObj |
|
327 | self.procUnitObj = procUnitObj | |
328 |
|
328 | |||
329 | return procUnitObj |
|
329 | return procUnitObj | |
330 |
|
330 | |||
331 | def run(self): |
|
331 | def run(self): | |
332 |
|
332 | |||
333 | finalSts = False |
|
333 | finalSts = False | |
334 |
|
334 | |||
335 | for opConfObj in self.opConfObjList: |
|
335 | for opConfObj in self.opConfObjList: | |
336 |
|
336 | |||
337 | kwargs = {} |
|
337 | kwargs = {} | |
338 | for parmConfObj in opConfObj.getParameterObjList(): |
|
338 | for parmConfObj in opConfObj.getParameterObjList(): | |
339 | kwargs[parmConfObj.name] = parmConfObj.getValue() |
|
339 | kwargs[parmConfObj.name] = parmConfObj.getValue() | |
340 |
|
340 | |||
341 | #print "\tRunning the '%s' operation with %s" %(opConfObj.name, opConfObj.id) |
|
341 | #print "\tRunning the '%s' operation with %s" %(opConfObj.name, opConfObj.id) | |
342 | sts = self.procUnitObj.call(opConfObj, **kwargs) |
|
342 | sts = self.procUnitObj.call(opConfObj, **kwargs) | |
343 | finalSts = finalSts or sts |
|
343 | finalSts = finalSts or sts | |
344 |
|
344 | |||
345 | return finalSts |
|
345 | return finalSts | |
346 |
|
346 | |||
347 | class ReadUnitConf(ProcUnitConf): |
|
347 | class ReadUnitConf(ProcUnitConf): | |
348 |
|
348 | |||
349 | path = None |
|
349 | path = None | |
350 | startDate = None |
|
350 | startDate = None | |
351 | endDate = None |
|
351 | endDate = None | |
352 | startTime = None |
|
352 | startTime = None | |
353 | endTime = None |
|
353 | endTime = None | |
354 | online = None |
|
354 | online = None | |
355 | expLabel = None |
|
355 | expLabel = None | |
356 | delay = None |
|
356 | delay = None | |
357 |
|
357 | |||
358 | ELEMENTNAME = 'ReadUnit' |
|
358 | ELEMENTNAME = 'ReadUnit' | |
359 |
|
359 | |||
360 | def __init__(self): |
|
360 | def __init__(self): | |
361 |
|
361 | |||
362 | self.id = None |
|
362 | self.id = None | |
363 | self.datatype = None |
|
363 | self.datatype = None | |
364 | self.name = None |
|
364 | self.name = None | |
365 | self.inputId = 0 |
|
365 | self.inputId = 0 | |
366 |
|
366 | |||
367 | self.opConfObjList = [] |
|
367 | self.opConfObjList = [] | |
368 | self.opObjList = [] |
|
368 | self.opObjList = [] | |
369 |
|
369 | |||
370 | def getElementName(self): |
|
370 | def getElementName(self): | |
371 |
|
371 | |||
372 | return self.ELEMENTNAME |
|
372 | return self.ELEMENTNAME | |
373 |
|
373 | |||
374 | def setup(self, id, name, datatype, path, startDate, endDate, startTime, endTime, online=0, expLabel='', delay=60): |
|
374 | def setup(self, id, name, datatype, path, startDate, endDate, startTime, endTime, online=0, expLabel='', delay=60): | |
375 |
|
375 | |||
376 | self.id = id |
|
376 | self.id = id | |
377 | self.name = name |
|
377 | self.name = name | |
378 | self.datatype = datatype |
|
378 | self.datatype = datatype | |
379 |
|
379 | |||
380 | self.path = path |
|
380 | self.path = path | |
381 | self.startDate = startDate |
|
381 | self.startDate = startDate | |
382 | self.endDate = endDate |
|
382 | self.endDate = endDate | |
383 | self.startTime = startTime |
|
383 | self.startTime = startTime | |
384 | self.endTime = endTime |
|
384 | self.endTime = endTime | |
385 | self.online = online |
|
385 | self.online = online | |
386 | self.expLabel = expLabel |
|
386 | self.expLabel = expLabel | |
387 | self.delay = delay |
|
387 | self.delay = delay | |
388 |
|
388 | |||
389 | self.addRunOperation() |
|
389 | self.addRunOperation() | |
390 |
|
390 | |||
391 | def addRunOperation(self): |
|
391 | def addRunOperation(self): | |
392 |
|
392 | |||
393 | opObj = self.addOperation(name = 'run', optype = 'self') |
|
393 | opObj = self.addOperation(name = 'run', optype = 'self') | |
394 |
|
394 | |||
395 | opObj.addParameter(name='path' , value=self.path, format='str') |
|
395 | opObj.addParameter(name='path' , value=self.path, format='str') | |
396 | opObj.addParameter(name='startDate' , value=self.startDate, format='date') |
|
396 | opObj.addParameter(name='startDate' , value=self.startDate, format='date') | |
397 | opObj.addParameter(name='endDate' , value=self.endDate, format='date') |
|
397 | opObj.addParameter(name='endDate' , value=self.endDate, format='date') | |
398 | opObj.addParameter(name='startTime' , value=self.startTime, format='time') |
|
398 | opObj.addParameter(name='startTime' , value=self.startTime, format='time') | |
399 | opObj.addParameter(name='endTime' , value=self.endTime, format='time') |
|
399 | opObj.addParameter(name='endTime' , value=self.endTime, format='time') | |
400 | opObj.addParameter(name='expLabel' , value=self.expLabel, format='str') |
|
400 | opObj.addParameter(name='expLabel' , value=self.expLabel, format='str') | |
401 | opObj.addParameter(name='online' , value=self.online, format='int') |
|
401 | opObj.addParameter(name='online' , value=self.online, format='int') | |
402 | opObj.addParameter(name='delay' , value=self.delay, format='float') |
|
402 | opObj.addParameter(name='delay' , value=self.delay, format='float') | |
403 |
|
403 | |||
404 | return opObj |
|
404 | return opObj | |
405 |
|
405 | |||
406 |
|
406 | |||
407 | class Controller(): |
|
407 | class Controller(): | |
408 |
|
408 | |||
409 | id = None |
|
409 | id = None | |
410 | name = None |
|
410 | name = None | |
411 | description = None |
|
411 | description = None | |
412 | # readUnitConfObjList = None |
|
412 | # readUnitConfObjList = None | |
413 | procUnitConfObjDict = None |
|
413 | procUnitConfObjDict = None | |
414 |
|
414 | |||
415 | ELEMENTNAME = 'Controller' |
|
415 | ELEMENTNAME = 'Controller' | |
416 |
|
416 | |||
417 | def __init__(self): |
|
417 | def __init__(self): | |
418 |
|
418 | |||
419 | self.id = None |
|
419 | self.id = None | |
420 | self.name = None |
|
420 | self.name = None | |
421 | self.description = None |
|
421 | self.description = None | |
422 |
|
422 | |||
423 | # self.readUnitConfObjList = [] |
|
423 | # self.readUnitConfObjList = [] | |
424 | self.procUnitConfObjDict = {} |
|
424 | self.procUnitConfObjDict = {} | |
425 |
|
425 | |||
426 | def __getNewId(self): |
|
426 | def __getNewId(self): | |
427 |
|
427 | |||
428 | id = int(self.id)*10 + len(self.procUnitConfObjDict) + 1 |
|
428 | id = int(self.id)*10 + len(self.procUnitConfObjDict) + 1 | |
429 |
|
429 | |||
430 | return str(id) |
|
430 | return str(id) | |
431 |
|
431 | |||
432 | def getElementName(self): |
|
432 | def getElementName(self): | |
433 |
|
433 | |||
434 | return self.ELEMENTNAME |
|
434 | return self.ELEMENTNAME | |
435 |
|
435 | |||
436 | def setup(self, id, name, description): |
|
436 | def setup(self, id, name, description): | |
437 |
|
437 | |||
438 | self.id = id |
|
438 | self.id = id | |
439 | self.name = name |
|
439 | self.name = name | |
440 | self.description = description |
|
440 | self.description = description | |
441 |
|
441 | |||
442 | def addReadUnit(self, datatype, path, startDate='', endDate='', startTime='', endTime='', online=0, expLabel='', delay=60): |
|
442 | def addReadUnit(self, datatype, path, startDate='', endDate='', startTime='', endTime='', online=0, expLabel='', delay=60): | |
443 |
|
443 | |||
444 | id = self.__getNewId() |
|
444 | id = self.__getNewId() | |
445 | name = '%sReader' %(datatype) |
|
445 | name = '%sReader' %(datatype) | |
446 |
|
446 | |||
447 | readUnitConfObj = ReadUnitConf() |
|
447 | readUnitConfObj = ReadUnitConf() | |
448 | readUnitConfObj.setup(id, name, datatype, path, startDate, endDate, startTime, endTime, online, expLabel, delay) |
|
448 | readUnitConfObj.setup(id, name, datatype, path, startDate, endDate, startTime, endTime, online, expLabel, delay) | |
449 |
|
449 | |||
450 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj |
|
450 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj | |
451 |
|
451 | |||
452 | return readUnitConfObj |
|
452 | return readUnitConfObj | |
453 |
|
453 | |||
454 | def addProcUnit(self, datatype, inputId): |
|
454 | def addProcUnit(self, datatype, inputId): | |
455 |
|
455 | |||
456 | id = self.__getNewId() |
|
456 | id = self.__getNewId() | |
457 | name = '%sProc' %(datatype) |
|
457 | name = '%sProc' %(datatype) | |
458 |
|
458 | |||
459 | procUnitConfObj = ProcUnitConf() |
|
459 | procUnitConfObj = ProcUnitConf() | |
460 | procUnitConfObj.setup(id, name, datatype, inputId) |
|
460 | procUnitConfObj.setup(id, name, datatype, inputId) | |
461 |
|
461 | |||
462 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj |
|
462 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj | |
463 |
|
463 | |||
464 | return procUnitConfObj |
|
464 | return procUnitConfObj | |
465 |
|
465 | |||
466 | def makeXml(self): |
|
466 | def makeXml(self): | |
467 |
|
467 | |||
468 | projectElement = Element('Controller') |
|
468 | projectElement = Element('Controller') | |
469 | projectElement.set('id', str(self.id)) |
|
469 | projectElement.set('id', str(self.id)) | |
470 | projectElement.set('name', self.name) |
|
470 | projectElement.set('name', self.name) | |
471 | projectElement.set('description', self.description) |
|
471 | projectElement.set('description', self.description) | |
472 |
|
472 | |||
473 | # for readUnitConfObj in self.readUnitConfObjList: |
|
473 | # for readUnitConfObj in self.readUnitConfObjList: | |
474 | # readUnitConfObj.makeXml(projectElement) |
|
474 | # readUnitConfObj.makeXml(projectElement) | |
475 |
|
475 | |||
476 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
476 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |
477 | procUnitConfObj.makeXml(projectElement) |
|
477 | procUnitConfObj.makeXml(projectElement) | |
478 |
|
478 | |||
479 | self.projectElement = projectElement |
|
479 | self.projectElement = projectElement | |
480 |
|
480 | |||
481 | def writeXml(self, filename): |
|
481 | def writeXml(self, filename): | |
482 |
|
482 | |||
483 | self.makeXml() |
|
483 | self.makeXml() | |
484 |
|
484 | |||
485 | print prettify(self.projectElement) |
|
485 | print prettify(self.projectElement) | |
486 |
|
486 | |||
487 | ElementTree(self.projectElement).write(filename, method='xml') |
|
487 | ElementTree(self.projectElement).write(filename, method='xml') | |
488 |
|
488 | |||
489 | def readXml(self, filename): |
|
489 | def readXml(self, filename): | |
490 |
|
490 | |||
491 | #tree = ET.parse(filename) |
|
491 | #tree = ET.parse(filename) | |
492 | self.projectElement = None |
|
492 | self.projectElement = None | |
493 | # self.readUnitConfObjList = [] |
|
493 | # self.readUnitConfObjList = [] | |
494 | self.procUnitConfObjDict = {} |
|
494 | self.procUnitConfObjDict = {} | |
495 |
|
495 | |||
496 | self.projectElement = ElementTree().parse(filename) |
|
496 | self.projectElement = ElementTree().parse(filename) | |
497 |
|
497 | |||
498 | self.project = self.projectElement.tag |
|
498 | self.project = self.projectElement.tag | |
499 |
|
499 | |||
500 | self.id = self.projectElement.get('id') |
|
500 | self.id = self.projectElement.get('id') | |
501 | self.name = self.projectElement.get('name') |
|
501 | self.name = self.projectElement.get('name') | |
502 | self.description = self.projectElement.get('description') |
|
502 | self.description = self.projectElement.get('description') | |
503 |
|
503 | |||
504 | readUnitElementList = self.projectElement.getiterator(ReadUnitConf().getElementName()) |
|
504 | readUnitElementList = self.projectElement.getiterator(ReadUnitConf().getElementName()) | |
505 |
|
505 | |||
506 | for readUnitElement in readUnitElementList: |
|
506 | for readUnitElement in readUnitElementList: | |
507 | readUnitConfObj = ReadUnitConf() |
|
507 | readUnitConfObj = ReadUnitConf() | |
508 | readUnitConfObj.readXml(readUnitElement) |
|
508 | readUnitConfObj.readXml(readUnitElement) | |
509 |
|
509 | |||
510 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj |
|
510 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj | |
511 |
|
511 | |||
512 | procUnitElementList = self.projectElement.getiterator(ProcUnitConf().getElementName()) |
|
512 | procUnitElementList = self.projectElement.getiterator(ProcUnitConf().getElementName()) | |
513 |
|
513 | |||
514 | for procUnitElement in procUnitElementList: |
|
514 | for procUnitElement in procUnitElementList: | |
515 | procUnitConfObj = ProcUnitConf() |
|
515 | procUnitConfObj = ProcUnitConf() | |
516 | procUnitConfObj.readXml(procUnitElement) |
|
516 | procUnitConfObj.readXml(procUnitElement) | |
517 |
|
517 | |||
518 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj |
|
518 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj | |
519 |
|
519 | |||
520 | def printattr(self): |
|
520 | def printattr(self): | |
521 |
|
521 | |||
522 | print "Controller[%s]: name = %s, description = %s" %(self.id, |
|
522 | print "Controller[%s]: name = %s, description = %s" %(self.id, | |
523 | self.name, |
|
523 | self.name, | |
524 | self.description) |
|
524 | self.description) | |
525 |
|
525 | |||
526 | # for readUnitConfObj in self.readUnitConfObjList: |
|
526 | # for readUnitConfObj in self.readUnitConfObjList: | |
527 | # readUnitConfObj.printattr() |
|
527 | # readUnitConfObj.printattr() | |
528 |
|
528 | |||
529 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
529 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |
530 | procUnitConfObj.printattr() |
|
530 | procUnitConfObj.printattr() | |
531 |
|
531 | |||
532 | def createObjects(self): |
|
532 | def createObjects(self): | |
533 |
|
533 | |||
534 | # for readUnitConfObj in self.readUnitConfObjList: |
|
534 | # for readUnitConfObj in self.readUnitConfObjList: | |
535 | # readUnitConfObj.createObjects() |
|
535 | # readUnitConfObj.createObjects() | |
536 |
|
536 | |||
537 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
537 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |
538 | procUnitConfObj.createObjects() |
|
538 | procUnitConfObj.createObjects() | |
539 |
|
539 | |||
540 | def __connect(self, objIN, obj): |
|
540 | def __connect(self, objIN, obj): | |
541 |
|
541 | |||
542 | obj.setInput(objIN.getOutput()) |
|
542 | obj.setInput(objIN.getOutput()) | |
543 |
|
543 | |||
544 | def connectObjects(self): |
|
544 | def connectObjects(self): | |
545 |
|
545 | |||
546 | for puConfObj in self.procUnitConfObjDict.values(): |
|
546 | for puConfObj in self.procUnitConfObjDict.values(): | |
547 |
|
547 | |||
548 | inputId = puConfObj.getInputId() |
|
548 | inputId = puConfObj.getInputId() | |
549 |
|
549 | |||
550 | if int(inputId) == 0: |
|
550 | if int(inputId) == 0: | |
551 | continue |
|
551 | continue | |
552 |
|
552 | |||
553 | puConfINObj = self.procUnitConfObjDict[inputId] |
|
553 | puConfINObj = self.procUnitConfObjDict[inputId] | |
554 |
|
554 | |||
555 | puObj = puConfObj.getProcUnitObj() |
|
555 | puObj = puConfObj.getProcUnitObj() | |
556 | puINObj = puConfINObj.getProcUnitObj() |
|
556 | puINObj = puConfINObj.getProcUnitObj() | |
557 |
|
557 | |||
558 | self.__connect(puINObj, puObj) |
|
558 | self.__connect(puINObj, puObj) | |
559 |
|
559 | |||
560 | def run(self): |
|
560 | def run(self): | |
561 |
|
561 | |||
562 | # for readUnitConfObj in self.readUnitConfObjList: |
|
562 | # for readUnitConfObj in self.readUnitConfObjList: | |
563 | # readUnitConfObj.run() |
|
563 | # readUnitConfObj.run() | |
564 |
|
564 | |||
565 | while(True): |
|
565 | while(True): | |
566 |
|
566 | |||
567 | finalSts = False |
|
567 | finalSts = False | |
568 |
|
568 | |||
569 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
569 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |
570 | #print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id) |
|
570 | #print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id) | |
571 | sts = procUnitConfObj.run() |
|
571 | sts = procUnitConfObj.run() | |
572 | finalSts = finalSts or sts |
|
572 | finalSts = finalSts or sts | |
573 |
|
573 | |||
574 | #If every process unit finished so end process |
|
574 | #If every process unit finished so end process | |
575 | if not(finalSts): |
|
575 | if not(finalSts): | |
576 | print "Every process units have finished" |
|
576 | print "Every process units have finished" | |
577 | break |
|
577 | break | |
578 |
|
578 | |||
579 | if __name__ == '__main__': |
|
579 | if __name__ == '__main__': | |
580 |
|
580 | |||
581 | desc = "Segundo Test" |
|
581 | desc = "Segundo Test" | |
582 | filename = "schain.xml" |
|
582 | filename = "schain.xml" | |
583 |
|
583 | |||
584 | controllerObj = Controller() |
|
584 | controllerObj = Controller() | |
585 |
|
585 | |||
586 | controllerObj.setup(id = '191', name='test01', description=desc) |
|
586 | controllerObj.setup(id = '191', name='test01', description=desc) | |
587 |
|
587 | |||
588 | readUnitConfObj = controllerObj.addReadUnit(datatype='Spectra', |
|
588 | readUnitConfObj = controllerObj.addReadUnit(datatype='Spectra', | |
589 |
path=' |
|
589 | path='/Users/dsuarez/Remote/IMAGING', | |
590 |
startDate='2011/0 |
|
590 | startDate='2011/03/20', | |
591 | endDate='2012/12/31', |
|
591 | endDate='2012/12/31', | |
592 |
startTime='0 |
|
592 | startTime='06:10:00', | |
593 | endTime='23:59:59', |
|
593 | endTime='23:59:59', | |
594 | online=0) |
|
594 | online=0) | |
595 |
|
595 | |||
596 | opObj00 = readUnitConfObj.addOperation(name='printTotalBlocks') |
|
596 | opObj00 = readUnitConfObj.addOperation(name='printTotalBlocks') | |
597 |
|
597 | |||
598 | procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=readUnitConfObj.getId()) |
|
598 | procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=readUnitConfObj.getId()) | |
599 |
|
599 | |||
600 | opObj10 = procUnitConfObj1.addOperation(name='selectChannels') |
|
600 | opObj10 = procUnitConfObj1.addOperation(name='selectChannels') | |
601 | opObj10.addParameter(name='channelList', value='0,1,2,4,6,7', format='intlist') |
|
601 | opObj10.addParameter(name='channelList', value='0,1,2,4,6,7', format='intlist') | |
602 |
|
602 | |||
603 | opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') |
|
603 | opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') | |
604 | opObj11.addParameter(name='idfigure', value='1', format='int') |
|
604 | opObj11.addParameter(name='idfigure', value='1', format='int') | |
605 | opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str') |
|
605 | opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str') | |
606 | # opObj11.addParameter(name='zmin', value='70', format='int') |
|
606 | # opObj11.addParameter(name='zmin', value='70', format='int') | |
607 | # opObj11.addParameter(name='zmax', value='90', format='int') |
|
607 | # opObj11.addParameter(name='zmax', value='90', format='int') | |
608 |
opObj11.addParameter(name='showprofile', value=' |
|
608 | opObj11.addParameter(name='showprofile', value='0', format='int') | |
609 |
|
609 | |||
610 |
opObj1 |
|
610 | opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other') | |
611 |
opObj1 |
|
611 | opObj11.addParameter(name='idfigure', value='10', format='int') | |
612 |
|
612 | opObj11.addParameter(name='wintitle', value='RTI', format='str') | ||
613 | opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') |
|
613 | # opObj11.addParameter(name='zmin', value='70', format='int') | |
614 |
opObj1 |
|
614 | # opObj11.addParameter(name='zmax', value='90', format='int') | |
615 |
|
615 | opObj11.addParameter(name='showprofile', value='0', format='int') | ||
616 | opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') |
|
616 | ||
617 | opObj11.addParameter(name='idfigure', value='2', format='int') |
|
617 | # opObj10 = procUnitConfObj1.addOperation(name='selectChannels') | |
618 |
opObj1 |
|
618 | # opObj10.addParameter(name='channelList', value='0,2,4,6', format='intlist') | |
619 | opObj11.addParameter(name='zmin', value='70', format='int') |
|
619 | # | |
620 | opObj11.addParameter(name='zmax', value='90', format='int') |
|
620 | # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') | |
621 |
|
621 | # opObj12.addParameter(name='n', value='2', format='int') | ||
622 | opObj10 = procUnitConfObj1.addOperation(name='selectChannels') |
|
622 | # | |
623 | opObj10.addParameter(name='channelList', value='2,6', format='intlist') |
|
623 | # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') | |
624 |
|
624 | # opObj11.addParameter(name='idfigure', value='2', format='int') | ||
625 | opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') |
|
625 | # opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str') | |
626 |
opObj1 |
|
626 | # opObj11.addParameter(name='zmin', value='70', format='int') | |
627 |
|
627 | # opObj11.addParameter(name='zmax', value='90', format='int') | ||
628 | opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') |
|
628 | # | |
629 | opObj11.addParameter(name='idfigure', value='3', format='int') |
|
629 | # opObj10 = procUnitConfObj1.addOperation(name='selectChannels') | |
630 |
opObj1 |
|
630 | # opObj10.addParameter(name='channelList', value='2,6', format='intlist') | |
631 | opObj11.addParameter(name='zmin', value='70', format='int') |
|
631 | # | |
632 | opObj11.addParameter(name='zmax', value='90', format='int') |
|
632 | # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') | |
|
633 | # opObj12.addParameter(name='n', value='2', format='int') | |||
|
634 | # | |||
|
635 | # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') | |||
|
636 | # opObj11.addParameter(name='idfigure', value='3', format='int') | |||
|
637 | # opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str') | |||
|
638 | # opObj11.addParameter(name='zmin', value='70', format='int') | |||
|
639 | # opObj11.addParameter(name='zmax', value='90', format='int') | |||
633 |
|
640 | |||
634 |
|
641 | |||
635 | # opObj12 = procUnitConfObj1.addOperation(name='decoder') |
|
642 | # opObj12 = procUnitConfObj1.addOperation(name='decoder') | |
636 | # opObj12.addParameter(name='ncode', value='2', format='int') |
|
643 | # opObj12.addParameter(name='ncode', value='2', format='int') | |
637 | # opObj12.addParameter(name='nbauds', value='8', format='int') |
|
644 | # opObj12.addParameter(name='nbauds', value='8', format='int') | |
638 | # opObj12.addParameter(name='code0', value='001110011', format='int') |
|
645 | # opObj12.addParameter(name='code0', value='001110011', format='int') | |
639 | # opObj12.addParameter(name='code1', value='001110011', format='int') |
|
646 | # opObj12.addParameter(name='code1', value='001110011', format='int') | |
640 |
|
647 | |||
641 |
|
648 | |||
642 |
|
649 | |||
643 | procUnitConfObj2 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj1.getId()) |
|
650 | # procUnitConfObj2 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj1.getId()) | |
644 |
|
651 | # | ||
645 | opObj21 = procUnitConfObj2.addOperation(name='IncohInt', optype='other') |
|
652 | # opObj21 = procUnitConfObj2.addOperation(name='IncohInt', optype='other') | |
646 | opObj21.addParameter(name='n', value='2', format='int') |
|
653 | # opObj21.addParameter(name='n', value='2', format='int') | |
647 |
|
654 | # | ||
648 | opObj11 = procUnitConfObj2.addOperation(name='SpectraPlot', optype='other') |
|
655 | # opObj11 = procUnitConfObj2.addOperation(name='SpectraPlot', optype='other') | |
649 | opObj11.addParameter(name='idfigure', value='4', format='int') |
|
656 | # opObj11.addParameter(name='idfigure', value='4', format='int') | |
650 | opObj11.addParameter(name='wintitle', value='SpectraPlot OBJ 2', format='str') |
|
657 | # opObj11.addParameter(name='wintitle', value='SpectraPlot OBJ 2', format='str') | |
651 | opObj11.addParameter(name='zmin', value='70', format='int') |
|
658 | # opObj11.addParameter(name='zmin', value='70', format='int') | |
652 | opObj11.addParameter(name='zmax', value='90', format='int') |
|
659 | # opObj11.addParameter(name='zmax', value='90', format='int') | |
653 |
|
660 | |||
654 | print "Escribiendo el archivo XML" |
|
661 | print "Escribiendo el archivo XML" | |
655 |
|
662 | |||
656 | controllerObj.writeXml(filename) |
|
663 | controllerObj.writeXml(filename) | |
657 |
|
664 | |||
658 | print "Leyendo el archivo XML" |
|
665 | print "Leyendo el archivo XML" | |
659 | controllerObj.readXml(filename) |
|
666 | controllerObj.readXml(filename) | |
660 | #controllerObj.printattr() |
|
667 | #controllerObj.printattr() | |
661 |
|
668 | |||
662 | controllerObj.createObjects() |
|
669 | controllerObj.createObjects() | |
663 | controllerObj.connectObjects() |
|
670 | controllerObj.connectObjects() | |
664 | controllerObj.run() |
|
671 | controllerObj.run() | |
665 |
|
672 | |||
666 | No newline at end of file |
|
673 |
@@ -1,245 +1,256 | |||||
1 | import numpy |
|
1 | import numpy | |
2 | import mpldriver |
|
2 | import mpldriver | |
3 |
|
3 | |||
4 |
|
4 | |||
5 | class Figure: |
|
5 | class Figure: | |
6 |
|
6 | |||
7 | __driver = mpldriver |
|
7 | __driver = mpldriver | |
8 | fig = None |
|
8 | fig = None | |
9 |
|
9 | |||
10 | idfigure = None |
|
10 | idfigure = None | |
11 | wintitle = None |
|
11 | wintitle = None | |
12 | width = None |
|
12 | width = None | |
13 | height = None |
|
13 | height = None | |
14 | nplots = None |
|
14 | nplots = None | |
15 |
|
15 | |||
16 | axesObjList = [] |
|
16 | axesObjList = [] | |
17 |
|
17 | |||
18 | WIDTH = None |
|
18 | WIDTH = None | |
19 | HEIGHT = None |
|
19 | HEIGHT = None | |
20 |
|
20 | |||
21 | def __init__(self): |
|
21 | def __init__(self): | |
22 |
|
22 | |||
23 | raise ValueError, "This method is not implemented" |
|
23 | raise ValueError, "This method is not implemented" | |
24 |
|
24 | |||
25 | def __del__(self): |
|
25 | def __del__(self): | |
26 |
|
26 | |||
27 | self.__driver.closeFigure() |
|
27 | self.__driver.closeFigure() | |
28 |
|
28 | |||
29 | def getAxesObjList(self): |
|
29 | def getAxesObjList(self): | |
30 |
|
30 | |||
31 | return self.axesObjList |
|
31 | return self.axesObjList | |
32 |
|
32 | |||
33 | def getSubplots(self): |
|
33 | def getSubplots(self): | |
34 |
|
34 | |||
35 | raise ValueError, "Abstract method: This method should be defined" |
|
35 | raise ValueError, "Abstract method: This method should be defined" | |
36 |
|
36 | |||
37 | def getScreenDim(self): |
|
37 | def getScreenDim(self): | |
38 |
|
38 | |||
39 | nrow, ncol = self.getSubplots() |
|
39 | nrow, ncol = self.getSubplots() | |
40 |
|
40 | |||
41 | width = self.WIDTH*ncol |
|
41 | width = self.WIDTH*ncol | |
42 | height = self.HEIGHT*nrow |
|
42 | height = self.HEIGHT*nrow | |
43 |
|
43 | |||
44 | return width, height |
|
44 | return width, height | |
45 |
|
45 | |||
46 | def init(self, idfigure, nplots, wintitle): |
|
46 | def init(self, idfigure, nplots, wintitle): | |
47 |
|
47 | |||
48 | raise ValueError, "This method has been replaced with createFigure" |
|
48 | raise ValueError, "This method has been replaced with createFigure" | |
49 |
|
49 | |||
50 | def createFigure(self, idfigure, wintitle): |
|
50 | def createFigure(self, idfigure, wintitle): | |
51 |
|
51 | |||
52 | """ |
|
52 | """ | |
53 | Crea la figura de acuerdo al driver y parametros seleccionados seleccionados. |
|
53 | Crea la figura de acuerdo al driver y parametros seleccionados seleccionados. | |
54 | Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH |
|
54 | Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH | |
55 | y self.HEIGHT y el numero de subplots (nrow, ncol) |
|
55 | y self.HEIGHT y el numero de subplots (nrow, ncol) | |
56 |
|
56 | |||
57 | Input: |
|
57 | Input: | |
58 | idfigure : Los parametros necesarios son |
|
58 | idfigure : Los parametros necesarios son | |
59 | wintitle : |
|
59 | wintitle : | |
60 |
|
60 | |||
61 | """ |
|
61 | """ | |
62 |
|
62 | |||
63 | self.idfigure = idfigure |
|
63 | self.idfigure = idfigure | |
64 |
|
64 | |||
65 | self.wintitle = wintitle |
|
65 | self.wintitle = wintitle | |
66 |
|
66 | |||
67 | self.width, self.height = self.getScreenDim() |
|
67 | self.width, self.height = self.getScreenDim() | |
68 |
|
68 | |||
69 | self.fig = self.__driver.createFigure(self.idfigure, |
|
69 | self.fig = self.__driver.createFigure(self.idfigure, | |
70 | self.wintitle, |
|
70 | self.wintitle, | |
71 | self.width, |
|
71 | self.width, | |
72 | self.height) |
|
72 | self.height) | |
73 |
|
73 | |||
74 | self.axesObjList = [] |
|
74 | self.axesObjList = [] | |
75 |
|
75 | |||
76 | def setDriver(self, driver=mpldriver): |
|
76 | def setDriver(self, driver=mpldriver): | |
77 |
|
77 | |||
78 | self.__driver = driver |
|
78 | self.__driver = driver | |
79 |
|
79 | |||
80 | def setTitle(self, title): |
|
80 | def setTitle(self, title): | |
81 |
|
81 | |||
82 | self.__driver.setTitle(self.fig, title) |
|
82 | self.__driver.setTitle(self.fig, title) | |
83 |
|
83 | |||
84 | def setWinTitle(self, title): |
|
84 | def setWinTitle(self, title): | |
85 |
|
85 | |||
86 | self.__driver.setWinTitle(self.fig, title=title) |
|
86 | self.__driver.setWinTitle(self.fig, title=title) | |
87 |
|
87 | |||
88 | def setTextFromAxes(self, text): |
|
88 | def setTextFromAxes(self, text): | |
89 |
|
89 | |||
90 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes" |
|
90 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes" | |
91 |
|
91 | |||
92 | def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan): |
|
92 | def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan): | |
93 |
|
93 | |||
94 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes" |
|
94 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes" | |
95 |
|
95 | |||
96 | def addAxes(self, *args): |
|
96 | def addAxes(self, *args): | |
97 | """ |
|
97 | """ | |
98 |
|
98 | |||
99 | Input: |
|
99 | Input: | |
100 | *args : Los parametros necesarios son |
|
100 | *args : Los parametros necesarios son | |
101 | nrow, ncol, xpos, ypos, colspan, rowspan |
|
101 | nrow, ncol, xpos, ypos, colspan, rowspan | |
102 | """ |
|
102 | """ | |
103 |
|
103 | |||
104 | axesObj = Axes(self.fig, *args) |
|
104 | axesObj = Axes(self.fig, *args) | |
105 | self.axesObjList.append(axesObj) |
|
105 | self.axesObjList.append(axesObj) | |
106 |
|
106 | |||
107 | def draw(self): |
|
107 | def draw(self): | |
108 |
|
108 | |||
109 | self.__driver.draw(self.fig) |
|
109 | self.__driver.draw(self.fig) | |
110 |
|
110 | |||
111 | def run(self): |
|
111 | def run(self): | |
112 |
|
112 | |||
113 | raise ValueError, "This method is not implemented" |
|
113 | raise ValueError, "This method is not implemented" | |
114 |
|
114 | |||
115 | axesList = property(getAxesObjList) |
|
115 | axesList = property(getAxesObjList) | |
116 |
|
116 | |||
117 |
|
117 | |||
118 | class Axes: |
|
118 | class Axes: | |
119 |
|
119 | |||
120 | __driver = mpldriver |
|
120 | __driver = mpldriver | |
121 | fig = None |
|
121 | fig = None | |
122 | ax = None |
|
122 | ax = None | |
123 | plot = None |
|
123 | plot = None | |
124 |
|
124 | |||
125 | firsttime = None |
|
125 | firsttime = None | |
126 |
|
126 | |||
127 | __showprofile = False |
|
127 | __showprofile = False | |
128 |
|
128 | |||
|
129 | __zmin = None | |||
|
130 | __zmax = None | |||
|
131 | ||||
129 | def __init__(self, *args): |
|
132 | def __init__(self, *args): | |
130 |
|
133 | |||
131 | """ |
|
134 | """ | |
132 |
|
135 | |||
133 | Input: |
|
136 | Input: | |
134 | *args : Los parametros necesarios son |
|
137 | *args : Los parametros necesarios son | |
135 | fig, nrow, ncol, xpos, ypos, colspan, rowspan |
|
138 | fig, nrow, ncol, xpos, ypos, colspan, rowspan | |
136 | """ |
|
139 | """ | |
137 |
|
140 | |||
138 | ax = self.__driver.createAxes(*args) |
|
141 | ax = self.__driver.createAxes(*args) | |
139 | self.fig = args[0] |
|
142 | self.fig = args[0] | |
140 | self.ax = ax |
|
143 | self.ax = ax | |
141 | self.plot = None |
|
144 | self.plot = None | |
142 |
|
145 | |||
143 | self.firsttime = True |
|
146 | self.firsttime = True | |
144 |
|
147 | |||
145 | def setText(self, text): |
|
148 | def setText(self, text): | |
146 |
|
149 | |||
147 | self.__driver.setAxesText(self.ax, text) |
|
150 | self.__driver.setAxesText(self.ax, text) | |
148 |
|
151 | |||
149 | def pline(self, x, y, |
|
152 | def pline(self, x, y, | |
150 | xmin=None, xmax=None, |
|
153 | xmin=None, xmax=None, | |
151 | ymin=None, ymax=None, |
|
154 | ymin=None, ymax=None, | |
152 | xlabel='', ylabel='', |
|
155 | xlabel='', ylabel='', | |
153 | title='', |
|
156 | title='', | |
154 | **kwargs): |
|
157 | **kwargs): | |
155 |
|
158 | |||
156 | """ |
|
159 | """ | |
157 |
|
160 | |||
158 | Input: |
|
161 | Input: | |
159 | x : |
|
162 | x : | |
160 | y : |
|
163 | y : | |
161 | xmin : |
|
164 | xmin : | |
162 | xmax : |
|
165 | xmax : | |
163 | ymin : |
|
166 | ymin : | |
164 | ymax : |
|
167 | ymax : | |
165 | xlabel : |
|
168 | xlabel : | |
166 | ylabel : |
|
169 | ylabel : | |
167 | title : |
|
170 | title : | |
168 | **kwargs : Los parametros aceptados son |
|
171 | **kwargs : Los parametros aceptados son | |
169 |
|
172 | |||
170 | ticksize |
|
173 | ticksize | |
171 | ytick_visible |
|
174 | ytick_visible | |
172 | """ |
|
175 | """ | |
173 |
|
176 | |||
174 | if self.firsttime: |
|
177 | if self.firsttime: | |
175 |
|
178 | |||
176 | if xmin == None: xmin = numpy.nanmin(x) |
|
179 | if xmin == None: xmin = numpy.nanmin(x) | |
177 | if xmax == None: xmax = numpy.nanmax(x) |
|
180 | if xmax == None: xmax = numpy.nanmax(x) | |
178 | if ymin == None: ymin = numpy.nanmin(y) |
|
181 | if ymin == None: ymin = numpy.nanmin(y) | |
179 | if ymax == None: ymax = numpy.nanmax(y) |
|
182 | if ymax == None: ymax = numpy.nanmax(y) | |
180 |
|
183 | |||
181 | self.plot = self.__driver.createPline(self.ax, x, y, |
|
184 | self.plot = self.__driver.createPline(self.ax, x, y, | |
182 | xmin, xmax, |
|
185 | xmin, xmax, | |
183 | ymin, ymax, |
|
186 | ymin, ymax, | |
184 | xlabel=xlabel, |
|
187 | xlabel=xlabel, | |
185 | ylabel=ylabel, |
|
188 | ylabel=ylabel, | |
186 | title=title, |
|
189 | title=title, | |
187 | **kwargs) |
|
190 | **kwargs) | |
188 | self.firsttime = False |
|
191 | self.firsttime = False | |
189 | return |
|
192 | return | |
190 |
|
193 | |||
191 | self.__driver.pline(self.plot, x, y, xlabel=xlabel, |
|
194 | self.__driver.pline(self.plot, x, y, xlabel=xlabel, | |
192 | ylabel=ylabel, |
|
195 | ylabel=ylabel, | |
193 | title=title) |
|
196 | title=title) | |
194 |
|
197 | |||
195 |
|
198 | |||
196 | def pcolor(self, x, y, z, |
|
199 | def pcolor(self, x, y, z, | |
197 | xmin=None, xmax=None, |
|
200 | xmin=None, xmax=None, | |
198 | ymin=None, ymax=None, |
|
201 | ymin=None, ymax=None, | |
199 | zmin=None, zmax=None, |
|
202 | zmin=None, zmax=None, | |
200 | xlabel='', ylabel='', |
|
203 | xlabel='', ylabel='', | |
201 | title='', |
|
204 | title='', rti = False, | |
202 | **kwargs): |
|
205 | **kwargs): | |
203 |
|
206 | |||
204 | """ |
|
207 | """ | |
205 | Input: |
|
208 | Input: | |
206 | x : |
|
209 | x : | |
207 | y : |
|
210 | y : | |
208 | x : |
|
211 | x : | |
209 | xmin : |
|
212 | xmin : | |
210 | xmax : |
|
213 | xmax : | |
211 | ymin : |
|
214 | ymin : | |
212 | ymax : |
|
215 | ymax : | |
213 | zmin : |
|
216 | zmin : | |
214 | zmax : |
|
217 | zmax : | |
215 | xlabel : |
|
218 | xlabel : | |
216 | ylabel : |
|
219 | ylabel : | |
217 | title : |
|
220 | title : | |
218 | **kwargs : Los parametros aceptados son |
|
221 | **kwargs : Los parametros aceptados son | |
219 | ticksize=9, |
|
222 | ticksize=9, | |
220 | cblabel='' |
|
223 | cblabel='' | |
|
224 | rti = True or False | |||
221 | """ |
|
225 | """ | |
222 |
|
226 | |||
223 | if self.firsttime: |
|
227 | if self.firsttime: | |
224 |
|
228 | |||
225 | if xmin == None: xmin = numpy.nanmin(x) |
|
229 | if xmin == None: xmin = numpy.nanmin(x) | |
226 | if xmax == None: xmax = numpy.nanmax(x) |
|
230 | if xmax == None: xmax = numpy.nanmax(x) | |
227 | if ymin == None: ymin = numpy.nanmin(y) |
|
231 | if ymin == None: ymin = numpy.nanmin(y) | |
228 | if ymax == None: ymax = numpy.nanmax(y) |
|
232 | if ymax == None: ymax = numpy.nanmax(y) | |
229 | if zmin == None: zmin = numpy.nanmin(z) |
|
233 | if zmin == None: zmin = numpy.nanmin(z) | |
230 | if zmax == None: zmax = numpy.nanmax(z) |
|
234 | if zmax == None: zmax = numpy.nanmax(z) | |
231 |
|
235 | |||
|
236 | ||||
232 | self.plot = self.__driver.createPcolor(self.ax, x, y, z, |
|
237 | self.plot = self.__driver.createPcolor(self.ax, x, y, z, | |
233 | xmin, xmax, |
|
238 | xmin, xmax, | |
234 | ymin, ymax, |
|
239 | ymin, ymax, | |
235 | zmin, zmax, |
|
240 | zmin, zmax, | |
236 | xlabel=xlabel, |
|
241 | xlabel=xlabel, | |
237 | ylabel=ylabel, |
|
242 | ylabel=ylabel, | |
238 | title=title, |
|
243 | title=title, | |
239 | **kwargs) |
|
244 | **kwargs) | |
240 | self.firsttime = False |
|
245 | self.firsttime = False | |
|
246 | if self.__zmin == None: self.__zmin = zmin | |||
|
247 | if self.__zmax == None: self.__zmax = zmax | |||
241 | return |
|
248 | return | |
242 |
|
|
249 | ||
243 | mesh = self.__driver.pcolor(self.plot, z, xlabel=xlabel, |
|
250 | if rti: | |
244 | ylabel=ylabel, |
|
251 | self.__driver.addpcolor(self.ax, x, y, z, self.__zmin, self.__zmax) | |
245 | title=title) |
|
252 | return | |
|
253 | ||||
|
254 | self.__driver.pcolor(self.plot, z, xlabel=xlabel, ylabel=ylabel, title=title) | |||
|
255 | ||||
|
256 | No newline at end of file |
@@ -1,246 +1,250 | |||||
1 | import numpy |
|
1 | import numpy | |
2 | import matplotlib |
|
2 | import matplotlib | |
3 | matplotlib.use("TKAgg") |
|
3 | matplotlib.use("TKAgg") | |
4 | import matplotlib.pyplot |
|
4 | import matplotlib.pyplot | |
5 | #import scitools.numpyutils |
|
5 | #import scitools.numpyutils | |
6 | from mpl_toolkits.axes_grid1 import make_axes_locatable |
|
6 | from mpl_toolkits.axes_grid1 import make_axes_locatable | |
7 |
|
7 | |||
8 | def init(idfigure, wintitle, width, height, facecolor="w"): |
|
8 | def init(idfigure, wintitle, width, height, facecolor="w"): | |
9 |
|
9 | |||
10 | matplotlib.pyplot.ioff() |
|
10 | matplotlib.pyplot.ioff() | |
11 | fig = matplotlib.pyplot.matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor) |
|
11 | fig = matplotlib.pyplot.matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor) | |
12 | fig.canvas.manager.set_window_title(wintitle) |
|
12 | fig.canvas.manager.set_window_title(wintitle) | |
13 | fig.canvas.manager.resize(width, height) |
|
13 | fig.canvas.manager.resize(width, height) | |
14 | matplotlib.pyplot.ion() |
|
14 | matplotlib.pyplot.ion() | |
15 |
|
15 | |||
16 | return fig |
|
16 | return fig | |
17 |
|
17 | |||
18 | def setWinTitle(fig, title): |
|
18 | def setWinTitle(fig, title): | |
19 |
|
19 | |||
20 | fig.canvas.manager.set_window_title(title) |
|
20 | fig.canvas.manager.set_window_title(title) | |
21 |
|
21 | |||
22 | def setTitle(idfigure, title): |
|
22 | def setTitle(idfigure, title): | |
23 | fig = matplotlib.pyplot.figure(idfigure) |
|
23 | fig = matplotlib.pyplot.figure(idfigure) | |
24 | fig.suptitle(title) |
|
24 | fig.suptitle(title) | |
25 |
|
25 | |||
26 | def makeAxes(idfigure, nrow, ncol, xpos, ypos, colspan, rowspan): |
|
26 | def makeAxes(idfigure, nrow, ncol, xpos, ypos, colspan, rowspan): | |
27 | fig = matplotlib.pyplot.figure(idfigure) |
|
27 | fig = matplotlib.pyplot.figure(idfigure) | |
28 | ax = matplotlib.pyplot.subplot2grid((nrow, ncol), (xpos, ypos), colspan=colspan, rowspan=rowspan) |
|
28 | ax = matplotlib.pyplot.subplot2grid((nrow, ncol), (xpos, ypos), colspan=colspan, rowspan=rowspan) | |
29 | return ax |
|
29 | return ax | |
30 |
|
30 | |||
31 | def setTextFromAxes(idfigure, ax, title): |
|
31 | def setTextFromAxes(idfigure, ax, title): | |
32 | fig = matplotlib.pyplot.figure(idfigure) |
|
32 | fig = matplotlib.pyplot.figure(idfigure) | |
33 | ax.annotate(title, xy=(.1, .99), |
|
33 | ax.annotate(title, xy=(.1, .99), | |
34 | xycoords='figure fraction', |
|
34 | xycoords='figure fraction', | |
35 | horizontalalignment='left', verticalalignment='top', |
|
35 | horizontalalignment='left', verticalalignment='top', | |
36 | fontsize=10) |
|
36 | fontsize=10) | |
37 |
|
37 | |||
38 | def pline(ax, x, y, xmin, xmax, ymin, ymax, xlabel, ylabel, title, firsttime): |
|
38 | def pline(ax, x, y, xmin, xmax, ymin, ymax, xlabel, ylabel, title, firsttime): | |
39 |
|
39 | |||
40 | if firsttime: |
|
40 | if firsttime: | |
41 | ax.plot(x, y) |
|
41 | ax.plot(x, y) | |
42 | ax.set_xlim([xmin,xmax]) |
|
42 | ax.set_xlim([xmin,xmax]) | |
43 | ax.set_ylim([ymin,ymax]) |
|
43 | ax.set_ylim([ymin,ymax]) | |
44 | ax.set_xlabel(xlabel, size=8) |
|
44 | ax.set_xlabel(xlabel, size=8) | |
45 | ax.set_ylabel(ylabel, size=8) |
|
45 | ax.set_ylabel(ylabel, size=8) | |
46 | ax.set_title(title, size=10) |
|
46 | ax.set_title(title, size=10) | |
47 | matplotlib.pyplot.tight_layout() |
|
47 | matplotlib.pyplot.tight_layout() | |
48 | else: |
|
48 | else: | |
49 | ax.lines[0].set_data(x,y) |
|
49 | ax.lines[0].set_data(x,y) | |
50 |
|
50 | |||
51 | def draw(idfigure): |
|
51 | def draw(idfigure): | |
52 |
|
52 | |||
53 | fig = matplotlib.pyplot.figure(idfigure) |
|
53 | fig = matplotlib.pyplot.figure(idfigure) | |
54 | fig.canvas.draw() |
|
54 | fig.canvas.draw() | |
55 |
|
55 | |||
56 | def pcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel, ylabel, title, firsttime, mesh): |
|
56 | def pcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel, ylabel, title, firsttime, mesh): | |
57 |
|
57 | |||
58 | if firsttime: |
|
58 | if firsttime: | |
59 | divider = make_axes_locatable(ax) |
|
59 | divider = make_axes_locatable(ax) | |
60 | ax_cb = divider.new_horizontal(size="4%", pad=0.05) |
|
60 | ax_cb = divider.new_horizontal(size="4%", pad=0.05) | |
61 | fig1 = ax.get_figure() |
|
61 | fig1 = ax.get_figure() | |
62 | fig1.add_axes(ax_cb) |
|
62 | fig1.add_axes(ax_cb) | |
63 |
|
63 | |||
64 | ax.set_xlim([xmin,xmax]) |
|
64 | ax.set_xlim([xmin,xmax]) | |
65 | ax.set_ylim([ymin,ymax]) |
|
65 | ax.set_ylim([ymin,ymax]) | |
66 | ax.set_xlabel(xlabel) |
|
66 | ax.set_xlabel(xlabel) | |
67 | ax.set_ylabel(ylabel) |
|
67 | ax.set_ylabel(ylabel) | |
68 | ax.set_title(title) |
|
68 | ax.set_title(title) | |
69 | print x |
|
69 | print x | |
70 | imesh=ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax) |
|
70 | imesh=ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax) | |
71 | matplotlib.pyplot.colorbar(imesh, cax=ax_cb) |
|
71 | matplotlib.pyplot.colorbar(imesh, cax=ax_cb) | |
72 | ax_cb.yaxis.tick_right() |
|
72 | ax_cb.yaxis.tick_right() | |
73 | for tl in ax_cb.get_yticklabels(): |
|
73 | for tl in ax_cb.get_yticklabels(): | |
74 | tl.set_visible(True) |
|
74 | tl.set_visible(True) | |
75 | ax_cb.yaxis.tick_right() |
|
75 | ax_cb.yaxis.tick_right() | |
76 | matplotlib.pyplot.tight_layout() |
|
76 | matplotlib.pyplot.tight_layout() | |
77 | return imesh |
|
77 | return imesh | |
78 | else: |
|
78 | else: | |
79 | # ax.set_xlim([xmin,xmax]) |
|
79 | # ax.set_xlim([xmin,xmax]) | |
80 | # ax.set_ylim([ymin,ymax]) |
|
80 | # ax.set_ylim([ymin,ymax]) | |
81 | ax.set_xlabel(xlabel) |
|
81 | ax.set_xlabel(xlabel) | |
82 | ax.set_ylabel(ylabel) |
|
82 | ax.set_ylabel(ylabel) | |
83 | ax.set_title(title) |
|
83 | ax.set_title(title) | |
84 |
|
84 | |||
85 | z = z.T |
|
85 | z = z.T | |
86 | # z = z[0:-1,0:-1] |
|
86 | # z = z[0:-1,0:-1] | |
87 | mesh.set_array(z.ravel()) |
|
87 | mesh.set_array(z.ravel()) | |
88 |
|
88 | |||
89 | return mesh |
|
89 | return mesh | |
90 |
|
90 | |||
91 | ########################################### |
|
91 | ########################################### | |
92 | #Actualizacion de las funciones del driver |
|
92 | #Actualizacion de las funciones del driver | |
93 | ########################################### |
|
93 | ########################################### | |
94 |
|
94 | |||
95 | def createFigure(idfigure, wintitle, width, height, facecolor="w"): |
|
95 | def createFigure(idfigure, wintitle, width, height, facecolor="w"): | |
96 |
|
96 | |||
97 | matplotlib.pyplot.ioff() |
|
97 | matplotlib.pyplot.ioff() | |
98 | fig = matplotlib.pyplot.matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor) |
|
98 | fig = matplotlib.pyplot.matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor) | |
99 | fig.canvas.manager.set_window_title(wintitle) |
|
99 | fig.canvas.manager.set_window_title(wintitle) | |
100 | fig.canvas.manager.resize(width, height) |
|
100 | fig.canvas.manager.resize(width, height) | |
101 | matplotlib.pyplot.ion() |
|
101 | matplotlib.pyplot.ion() | |
102 |
|
102 | |||
103 | return fig |
|
103 | return fig | |
104 |
|
104 | |||
105 | def closeFigure(): |
|
105 | def closeFigure(): | |
106 |
|
106 | |||
107 | matplotlib.pyplot.ioff() |
|
107 | matplotlib.pyplot.ioff() | |
108 | matplotlib.pyplot.show() |
|
108 | matplotlib.pyplot.show() | |
109 |
|
109 | |||
110 | retur |
|
110 | return | |
111 |
|
111 | |||
112 | def setWinTitle(fig, title): |
|
112 | def setWinTitle(fig, title): | |
113 |
|
113 | |||
114 | fig.canvas.manager.set_window_title(title) |
|
114 | fig.canvas.manager.set_window_title(title) | |
115 |
|
115 | |||
116 | def setTitle(fig, title): |
|
116 | def setTitle(fig, title): | |
117 |
|
117 | |||
118 | fig.suptitle(title) |
|
118 | fig.suptitle(title) | |
119 |
|
119 | |||
120 | def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan): |
|
120 | def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan): | |
121 |
|
121 | |||
122 | matplotlib.pyplot.figure(fig.number) |
|
122 | matplotlib.pyplot.figure(fig.number) | |
123 | axes = matplotlib.pyplot.subplot2grid((nrow, ncol), |
|
123 | axes = matplotlib.pyplot.subplot2grid((nrow, ncol), | |
124 | (xpos, ypos), |
|
124 | (xpos, ypos), | |
125 | colspan=colspan, |
|
125 | colspan=colspan, | |
126 | rowspan=rowspan) |
|
126 | rowspan=rowspan) | |
127 | return axes |
|
127 | return axes | |
128 |
|
128 | |||
129 | def setAxesText(ax, text): |
|
129 | def setAxesText(ax, text): | |
130 |
|
130 | |||
131 | ax.annotate(text, |
|
131 | ax.annotate(text, | |
132 | xy = (.1, .99), |
|
132 | xy = (.1, .99), | |
133 | xycoords = 'figure fraction', |
|
133 | xycoords = 'figure fraction', | |
134 | horizontalalignment = 'left', |
|
134 | horizontalalignment = 'left', | |
135 | verticalalignment = 'top', |
|
135 | verticalalignment = 'top', | |
136 | fontsize = 10) |
|
136 | fontsize = 10) | |
137 |
|
137 | |||
138 | def printLabels(ax, xlabel, ylabel, title): |
|
138 | def printLabels(ax, xlabel, ylabel, title): | |
139 |
|
139 | |||
140 | ax.set_xlabel(xlabel, size=11) |
|
140 | ax.set_xlabel(xlabel, size=11) | |
141 | ax.set_ylabel(ylabel, size=11) |
|
141 | ax.set_ylabel(ylabel, size=11) | |
142 | ax.set_title(title, size=12) |
|
142 | ax.set_title(title, size=12) | |
143 |
|
143 | |||
144 | def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', |
|
144 | def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', | |
145 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
145 | ticksize=9, xtick_visible=True, ytick_visible=True, | |
146 | nxticks=4, nyticks=10, |
|
146 | nxticks=4, nyticks=10, | |
147 | grid=None): |
|
147 | grid=None): | |
148 |
|
148 | |||
149 | """ |
|
149 | """ | |
150 |
|
150 | |||
151 | Input: |
|
151 | Input: | |
152 | grid : None, 'both', 'x', 'y' |
|
152 | grid : None, 'both', 'x', 'y' | |
153 | """ |
|
153 | """ | |
154 |
|
154 | |||
155 | ax.plot(x, y) |
|
155 | ax.plot(x, y) | |
156 | ax.set_xlim([xmin,xmax]) |
|
156 | ax.set_xlim([xmin,xmax]) | |
157 | ax.set_ylim([ymin,ymax]) |
|
157 | ax.set_ylim([ymin,ymax]) | |
158 |
|
158 | |||
159 | printLabels(ax, xlabel, ylabel, title) |
|
159 | printLabels(ax, xlabel, ylabel, title) | |
160 |
|
160 | |||
161 | ###################################################### |
|
161 | ###################################################### | |
162 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/nxticks) + int(xmin) |
|
162 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/nxticks) + int(xmin) | |
163 | ax.set_xticks(xtickspos) |
|
163 | ax.set_xticks(xtickspos) | |
164 |
|
164 | |||
165 | for tick in ax.get_xticklabels(): |
|
165 | for tick in ax.get_xticklabels(): | |
166 | tick.set_visible(xtick_visible) |
|
166 | tick.set_visible(xtick_visible) | |
167 |
|
167 | |||
168 | for tick in ax.xaxis.get_major_ticks(): |
|
168 | for tick in ax.xaxis.get_major_ticks(): | |
169 | tick.label.set_fontsize(ticksize) |
|
169 | tick.label.set_fontsize(ticksize) | |
170 |
|
170 | |||
171 | ###################################################### |
|
171 | ###################################################### | |
172 | for tick in ax.get_yticklabels(): |
|
172 | for tick in ax.get_yticklabels(): | |
173 | tick.set_visible(ytick_visible) |
|
173 | tick.set_visible(ytick_visible) | |
174 |
|
174 | |||
175 | for tick in ax.yaxis.get_major_ticks(): |
|
175 | for tick in ax.yaxis.get_major_ticks(): | |
176 | tick.label.set_fontsize(ticksize) |
|
176 | tick.label.set_fontsize(ticksize) | |
177 |
|
177 | |||
178 | ###################################################### |
|
178 | ###################################################### | |
179 | if grid != None: |
|
179 | if grid != None: | |
180 | ax.grid(b=True, which='major', axis=grid) |
|
180 | ax.grid(b=True, which='major', axis=grid) | |
181 |
|
181 | |||
182 | matplotlib.pyplot.tight_layout() |
|
182 | matplotlib.pyplot.tight_layout() | |
183 |
|
183 | |||
184 | iplot = ax.lines[-1] |
|
184 | iplot = ax.lines[-1] | |
185 |
|
185 | |||
186 | return iplot |
|
186 | return iplot | |
187 |
|
187 | |||
188 | def pline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
188 | def pline(iplot, x, y, xlabel='', ylabel='', title=''): | |
189 |
|
189 | |||
190 | ax = iplot.get_axes() |
|
190 | ax = iplot.get_axes() | |
191 |
|
191 | |||
192 | printLabels(ax, xlabel, ylabel, title) |
|
192 | printLabels(ax, xlabel, ylabel, title) | |
193 |
|
193 | |||
194 | iplot.set_data(x, y) |
|
194 | iplot.set_data(x, y) | |
195 |
|
195 | |||
196 | def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel='', ylabel='', title='', ticksize = 9, cblabel=''): |
|
196 | def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel='', ylabel='', title='', ticksize = 9, cblabel=''): | |
197 |
|
197 | |||
198 | divider = make_axes_locatable(ax) |
|
198 | divider = make_axes_locatable(ax) | |
199 | ax_cb = divider.new_horizontal(size="4%", pad=0.05) |
|
199 | ax_cb = divider.new_horizontal(size="4%", pad=0.05) | |
200 | fig = ax.get_figure() |
|
200 | fig = ax.get_figure() | |
201 | fig.add_axes(ax_cb) |
|
201 | fig.add_axes(ax_cb) | |
202 |
|
202 | |||
203 | ax.set_xlim([xmin,xmax]) |
|
203 | ax.set_xlim([xmin,xmax]) | |
204 | ax.set_ylim([ymin,ymax]) |
|
204 | ax.set_ylim([ymin,ymax]) | |
205 |
|
205 | |||
206 | printLabels(ax, xlabel, ylabel, title) |
|
206 | printLabels(ax, xlabel, ylabel, title) | |
207 |
|
207 | |||
208 | imesh = ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax) |
|
208 | imesh = ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax) | |
209 | cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb) |
|
209 | cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb) | |
210 | cb.set_label(cblabel) |
|
210 | cb.set_label(cblabel) | |
211 |
|
211 | |||
212 | ax_cb.yaxis.tick_right() |
|
212 | ax_cb.yaxis.tick_right() | |
213 |
|
213 | |||
214 | for tl in ax_cb.get_yticklabels(): |
|
214 | for tl in ax_cb.get_yticklabels(): | |
215 | tl.set_visible(True) |
|
215 | tl.set_visible(True) | |
216 |
|
216 | |||
217 | for tick in ax.yaxis.get_major_ticks(): |
|
217 | for tick in ax.yaxis.get_major_ticks(): | |
218 | tick.label.set_fontsize(ticksize) |
|
218 | tick.label.set_fontsize(ticksize) | |
219 |
|
219 | |||
220 | for tick in ax.xaxis.get_major_ticks(): |
|
220 | for tick in ax.xaxis.get_major_ticks(): | |
221 | tick.label.set_fontsize(ticksize) |
|
221 | tick.label.set_fontsize(ticksize) | |
222 |
|
222 | |||
223 | for tick in cb.ax.get_yticklabels(): |
|
223 | for tick in cb.ax.get_yticklabels(): | |
224 | tick.set_fontsize(ticksize) |
|
224 | tick.set_fontsize(ticksize) | |
225 |
|
225 | |||
226 | ax_cb.yaxis.tick_right() |
|
226 | ax_cb.yaxis.tick_right() | |
227 | matplotlib.pyplot.tight_layout() |
|
227 | matplotlib.pyplot.tight_layout() | |
228 |
|
228 | |||
229 | return imesh |
|
229 | return imesh | |
230 |
|
230 | |||
231 | def pcolor(imesh, z, xlabel='', ylabel='', title=''): |
|
231 | def pcolor(imesh, z, xlabel='', ylabel='', title=''): | |
232 |
|
232 | |||
233 | z = z.T |
|
233 | z = z.T | |
234 |
|
234 | |||
235 | ax = imesh.get_axes() |
|
235 | ax = imesh.get_axes() | |
236 |
|
236 | |||
237 | printLabels(ax, xlabel, ylabel, title) |
|
237 | printLabels(ax, xlabel, ylabel, title) | |
238 |
|
238 | |||
239 | imesh.set_array(z.ravel()) |
|
239 | imesh.set_array(z.ravel()) | |
240 |
|
240 | |||
|
241 | def addpcolor(ax, x, y, z, zmin, zmax): | |||
|
242 | ||||
|
243 | imesh = ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax) | |||
|
244 | ||||
241 | def draw(fig): |
|
245 | def draw(fig): | |
242 |
|
246 | |||
243 | if type(fig) == 'int': |
|
247 | if type(fig) == 'int': | |
244 | raise ValueError, "This parameter should be of tpye matplotlib figure" |
|
248 | raise ValueError, "This parameter should be of tpye matplotlib figure" | |
245 |
|
249 | |||
246 | fig.canvas.draw() No newline at end of file |
|
250 | fig.canvas.draw() |
@@ -1,462 +1,494 | |||||
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 os, sys |
|
7 | import os, sys | |
8 | import copy |
|
8 | import copy | |
9 | import numpy |
|
9 | import numpy | |
10 |
|
10 | |||
11 | from jroheaderIO import SystemHeader, RadarControllerHeader |
|
11 | from jroheaderIO import SystemHeader, RadarControllerHeader | |
12 |
|
12 | |||
13 | def hildebrand_sekhon(data, navg): |
|
13 | def hildebrand_sekhon(data, navg): | |
14 | """ |
|
14 | """ | |
15 | This method is for the objective determination of de noise level in Doppler spectra. This |
|
15 | This method is for the objective determination of de noise level in Doppler spectra. This | |
16 | implementation technique is based on the fact that the standard deviation of the spectral |
|
16 | implementation technique is based on the fact that the standard deviation of the spectral | |
17 | densities is equal to the mean spectral density for white Gaussian noise |
|
17 | densities is equal to the mean spectral density for white Gaussian noise | |
18 |
|
18 | |||
19 | Inputs: |
|
19 | Inputs: | |
20 | Data : heights |
|
20 | Data : heights | |
21 | navg : numbers of averages |
|
21 | navg : numbers of averages | |
22 |
|
22 | |||
23 | Return: |
|
23 | Return: | |
24 | -1 : any error |
|
24 | -1 : any error | |
25 | anoise : noise's level |
|
25 | anoise : noise's level | |
26 | """ |
|
26 | """ | |
27 |
|
27 | |||
28 | dataflat = data.copy().reshape(-1) |
|
28 | dataflat = data.copy().reshape(-1) | |
29 | dataflat.sort() |
|
29 | dataflat.sort() | |
30 | npts = dataflat.size #numbers of points of the data |
|
30 | npts = dataflat.size #numbers of points of the data | |
31 |
|
31 | |||
32 | if npts < 32: |
|
32 | if npts < 32: | |
33 | print "error in noise - requires at least 32 points" |
|
33 | print "error in noise - requires at least 32 points" | |
34 | return -1.0 |
|
34 | return -1.0 | |
35 |
|
35 | |||
36 | dataflat2 = numpy.power(dataflat,2) |
|
36 | dataflat2 = numpy.power(dataflat,2) | |
37 |
|
37 | |||
38 | cs = numpy.cumsum(dataflat) |
|
38 | cs = numpy.cumsum(dataflat) | |
39 | cs2 = numpy.cumsum(dataflat2) |
|
39 | cs2 = numpy.cumsum(dataflat2) | |
40 |
|
40 | |||
41 | # data sorted in ascending order |
|
41 | # data sorted in ascending order | |
42 | nmin = int((npts + 7.)/8) |
|
42 | nmin = int((npts + 7.)/8) | |
43 |
|
43 | |||
44 | for i in range(nmin, npts): |
|
44 | for i in range(nmin, npts): | |
45 | s = cs[i] |
|
45 | s = cs[i] | |
46 | s2 = cs2[i] |
|
46 | s2 = cs2[i] | |
47 | p = s / float(i); |
|
47 | p = s / float(i); | |
48 | p2 = p**2; |
|
48 | p2 = p**2; | |
49 | q = s2 / float(i) - p2; |
|
49 | q = s2 / float(i) - p2; | |
50 | leftc = p2; |
|
50 | leftc = p2; | |
51 | rightc = q * float(navg); |
|
51 | rightc = q * float(navg); | |
52 | R2 = leftc/rightc |
|
52 | R2 = leftc/rightc | |
53 |
|
53 | |||
54 | # Signal detect: R2 < 1 (R2 = leftc/rightc) |
|
54 | # Signal detect: R2 < 1 (R2 = leftc/rightc) | |
55 | if R2 < 1: |
|
55 | if R2 < 1: | |
56 | npts_noise = i |
|
56 | npts_noise = i | |
57 | break |
|
57 | break | |
58 |
|
58 | |||
59 |
|
59 | |||
60 | anoise = numpy.average(dataflat[0:npts_noise]) |
|
60 | anoise = numpy.average(dataflat[0:npts_noise]) | |
61 |
|
61 | |||
62 | return anoise; |
|
62 | return anoise; | |
63 |
|
63 | |||
64 | def sorting_bruce(data, navg): |
|
64 | def sorting_bruce(data, navg): | |
65 |
|
65 | |||
66 | data = data.copy() |
|
66 | data = data.copy() | |
67 |
|
67 | |||
68 | sortdata = numpy.sort(data) |
|
68 | sortdata = numpy.sort(data) | |
69 | lenOfData = len(data) |
|
69 | lenOfData = len(data) | |
70 | nums_min = lenOfData/10 |
|
70 | nums_min = lenOfData/10 | |
71 |
|
71 | |||
72 | if (lenOfData/10) > 0: |
|
72 | if (lenOfData/10) > 0: | |
73 | nums_min = lenOfData/10 |
|
73 | nums_min = lenOfData/10 | |
74 | else: |
|
74 | else: | |
75 | nums_min = 0 |
|
75 | nums_min = 0 | |
76 |
|
76 | |||
77 | rtest = 1.0 + 1.0/navg |
|
77 | rtest = 1.0 + 1.0/navg | |
78 |
|
78 | |||
79 | sum = 0. |
|
79 | sum = 0. | |
80 |
|
80 | |||
81 | sumq = 0. |
|
81 | sumq = 0. | |
82 |
|
82 | |||
83 | j = 0 |
|
83 | j = 0 | |
84 |
|
84 | |||
85 | cont = 1 |
|
85 | cont = 1 | |
86 |
|
86 | |||
87 | while((cont==1)and(j<lenOfData)): |
|
87 | while((cont==1)and(j<lenOfData)): | |
88 |
|
88 | |||
89 | sum += sortdata[j] |
|
89 | sum += sortdata[j] | |
90 |
|
90 | |||
91 | sumq += sortdata[j]**2 |
|
91 | sumq += sortdata[j]**2 | |
92 |
|
92 | |||
93 | j += 1 |
|
93 | j += 1 | |
94 |
|
94 | |||
95 | if j > nums_min: |
|
95 | if j > nums_min: | |
96 | if ((sumq*j) <= (rtest*sum**2)): |
|
96 | if ((sumq*j) <= (rtest*sum**2)): | |
97 | lnoise = sum / j |
|
97 | lnoise = sum / j | |
98 | else: |
|
98 | else: | |
99 | j = j - 1 |
|
99 | j = j - 1 | |
100 | sum = sum - sordata[j] |
|
100 | sum = sum - sordata[j] | |
101 | sumq = sumq - sordata[j]**2 |
|
101 | sumq = sumq - sordata[j]**2 | |
102 | cont = 0 |
|
102 | cont = 0 | |
103 |
|
103 | |||
104 | if j == nums_min: |
|
104 | if j == nums_min: | |
105 | lnoise = sum /j |
|
105 | lnoise = sum /j | |
106 |
|
106 | |||
107 | return lnoise |
|
107 | return lnoise | |
108 |
|
108 | |||
109 | class JROData: |
|
109 | class JROData: | |
110 |
|
110 | |||
111 | # m_BasicHeader = BasicHeader() |
|
111 | # m_BasicHeader = BasicHeader() | |
112 | # m_ProcessingHeader = ProcessingHeader() |
|
112 | # m_ProcessingHeader = ProcessingHeader() | |
113 |
|
113 | |||
114 | systemHeaderObj = SystemHeader() |
|
114 | systemHeaderObj = SystemHeader() | |
115 |
|
115 | |||
116 | radarControllerHeaderObj = RadarControllerHeader() |
|
116 | radarControllerHeaderObj = RadarControllerHeader() | |
117 |
|
117 | |||
118 | # data = None |
|
118 | # data = None | |
119 |
|
119 | |||
120 | type = None |
|
120 | type = None | |
121 |
|
121 | |||
122 | dtype = None |
|
122 | dtype = None | |
123 |
|
123 | |||
124 | # nChannels = None |
|
124 | # nChannels = None | |
125 |
|
125 | |||
126 | nHeights = None |
|
126 | # nHeights = None | |
127 |
|
127 | |||
128 | nProfiles = None |
|
128 | nProfiles = None | |
129 |
|
129 | |||
130 | heightList = None |
|
130 | heightList = None | |
131 |
|
131 | |||
132 | channelList = None |
|
132 | channelList = None | |
133 |
|
133 | |||
134 | flagNoData = True |
|
134 | flagNoData = True | |
135 |
|
135 | |||
136 | flagTimeBlock = False |
|
136 | flagTimeBlock = False | |
137 |
|
137 | |||
138 | utctime = None |
|
138 | utctime = None | |
139 |
|
139 | |||
140 | blocksize = None |
|
140 | blocksize = None | |
141 |
|
141 | |||
142 | nCode = None |
|
142 | nCode = None | |
143 |
|
143 | |||
144 | nBaud = None |
|
144 | nBaud = None | |
145 |
|
145 | |||
146 | code = None |
|
146 | code = None | |
147 |
|
147 | |||
148 | flagDecodeData = True #asumo q la data esta decodificada |
|
148 | flagDecodeData = True #asumo q la data esta decodificada | |
149 |
|
149 | |||
150 | flagDeflipData = True #asumo q la data esta sin flip |
|
150 | flagDeflipData = True #asumo q la data esta sin flip | |
151 |
|
151 | |||
152 | flagShiftFFT = False |
|
152 | flagShiftFFT = False | |
153 |
|
153 | |||
154 | ippSeconds = None |
|
154 | ippSeconds = None | |
155 |
|
155 | |||
156 | timeInterval = None |
|
156 | timeInterval = None | |
157 |
|
157 | |||
158 | nCohInt = None |
|
158 | nCohInt = None | |
159 |
|
159 | |||
160 | noise = None |
|
160 | noise = None | |
161 |
|
161 | |||
162 | #Speed of ligth |
|
162 | #Speed of ligth | |
163 | C = 3e8 |
|
163 | C = 3e8 | |
164 |
|
164 | |||
165 | frequency = 49.92e6 |
|
165 | frequency = 49.92e6 | |
166 |
|
166 | |||
167 | def __init__(self): |
|
167 | def __init__(self): | |
168 |
|
168 | |||
169 | raise ValueError, "This class has not been implemented" |
|
169 | raise ValueError, "This class has not been implemented" | |
170 |
|
170 | |||
171 | def copy(self, inputObj=None): |
|
171 | def copy(self, inputObj=None): | |
172 |
|
172 | |||
173 | if inputObj == None: |
|
173 | if inputObj == None: | |
174 | return copy.deepcopy(self) |
|
174 | return copy.deepcopy(self) | |
175 |
|
175 | |||
176 | for key in inputObj.__dict__.keys(): |
|
176 | for key in inputObj.__dict__.keys(): | |
177 | self.__dict__[key] = inputObj.__dict__[key] |
|
177 | self.__dict__[key] = inputObj.__dict__[key] | |
178 |
|
178 | |||
179 | def deepcopy(self): |
|
179 | def deepcopy(self): | |
180 |
|
180 | |||
181 | return copy.deepcopy(self) |
|
181 | return copy.deepcopy(self) | |
182 |
|
182 | |||
183 | def isEmpty(self): |
|
183 | def isEmpty(self): | |
184 |
|
184 | |||
185 | return self.flagNoData |
|
185 | return self.flagNoData | |
186 |
|
186 | |||
|
187 | def getNoise(self): | |||
|
188 | ||||
|
189 | raise ValueError, "Not implemented" | |||
|
190 | ||||
187 | def getNChannels(self): |
|
191 | def getNChannels(self): | |
188 |
|
192 | |||
189 | return len(self.channelList) |
|
193 | return len(self.channelList) | |
190 |
|
194 | |||
191 | def getChannelIndexList(self): |
|
195 | def getChannelIndexList(self): | |
192 |
|
196 | |||
193 | return range(self.nChannels) |
|
197 | return range(self.nChannels) | |
194 |
|
198 | |||
|
199 | def getNHeights(self): | |||
|
200 | ||||
|
201 | return len(self.heightList) | |||
|
202 | ||||
|
203 | def getHeiRange(self, extrapoints=0): | |||
|
204 | ||||
|
205 | heis = self.heightList | |||
|
206 | # deltah = self.heightList[1] - self.heightList[0] | |||
|
207 | # | |||
|
208 | # heis.append(self.heightList[-1]) | |||
|
209 | ||||
|
210 | return heis | |||
|
211 | ||||
|
212 | def getDatatime(self): | |||
|
213 | ||||
|
214 | datatime = [] | |||
|
215 | ||||
|
216 | datatime.append(self.utctime) | |||
|
217 | datatime.append(self.utctime + 2*self.timeInterval) | |||
|
218 | ||||
|
219 | datatime = numpy.array(datatime) | |||
|
220 | ||||
|
221 | return datatime | |||
|
222 | ||||
|
223 | def getFmax(self): | |||
|
224 | ||||
|
225 | PRF = 1./(self.ippSeconds * self.nCohInt) | |||
|
226 | ||||
|
227 | fmax = PRF/2. | |||
|
228 | ||||
|
229 | return fmax | |||
|
230 | ||||
|
231 | def getVmax(self): | |||
|
232 | ||||
|
233 | _lambda = self.C/self.frequency | |||
|
234 | ||||
|
235 | vmax = self.getFmax() * _lambda / 2. | |||
|
236 | ||||
|
237 | return vmax | |||
|
238 | ||||
195 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") |
|
239 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") | |
196 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") |
|
240 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") | |
197 |
|
241 | |||
|
242 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") | |||
|
243 | ||||
|
244 | noise = property(getNoise, "I'm the 'nHeights' property.") | |||
|
245 | ||||
198 | class Voltage(JROData): |
|
246 | class Voltage(JROData): | |
199 |
|
247 | |||
200 | #data es un numpy array de 2 dmensiones (canales, alturas) |
|
248 | #data es un numpy array de 2 dmensiones (canales, alturas) | |
201 | data = None |
|
249 | data = None | |
202 |
|
250 | |||
203 | def __init__(self): |
|
251 | def __init__(self): | |
204 | ''' |
|
252 | ''' | |
205 | Constructor |
|
253 | Constructor | |
206 | ''' |
|
254 | ''' | |
207 |
|
255 | |||
208 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
256 | self.radarControllerHeaderObj = RadarControllerHeader() | |
209 |
|
257 | |||
210 | self.systemHeaderObj = SystemHeader() |
|
258 | self.systemHeaderObj = SystemHeader() | |
211 |
|
259 | |||
212 | self.type = "Voltage" |
|
260 | self.type = "Voltage" | |
213 |
|
261 | |||
214 | self.data = None |
|
262 | self.data = None | |
215 |
|
263 | |||
216 | self.dtype = None |
|
264 | self.dtype = None | |
217 |
|
265 | |||
218 | # self.nChannels = 0 |
|
266 | # self.nChannels = 0 | |
219 |
|
267 | |||
220 | self.nHeights = 0 |
|
268 | # self.nHeights = 0 | |
221 |
|
269 | |||
222 | self.nProfiles = None |
|
270 | self.nProfiles = None | |
223 |
|
271 | |||
224 | self.heightList = None |
|
272 | self.heightList = None | |
225 |
|
273 | |||
226 | self.channelList = None |
|
274 | self.channelList = None | |
227 |
|
275 | |||
228 | # self.channelIndexList = None |
|
276 | # self.channelIndexList = None | |
229 |
|
277 | |||
230 | self.flagNoData = True |
|
278 | self.flagNoData = True | |
231 |
|
279 | |||
232 | self.flagTimeBlock = False |
|
280 | self.flagTimeBlock = False | |
233 |
|
281 | |||
234 | self.utctime = None |
|
282 | self.utctime = None | |
235 |
|
283 | |||
236 | self.nCohInt = None |
|
284 | self.nCohInt = None | |
237 |
|
285 | |||
238 | self.blocksize = None |
|
286 | self.blocksize = None | |
239 |
|
287 | |||
240 | def getNoisebyHildebrand(self): |
|
288 | def getNoisebyHildebrand(self): | |
241 | """ |
|
289 | """ | |
242 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
|
290 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon | |
243 |
|
291 | |||
244 | Return: |
|
292 | Return: | |
245 | noiselevel |
|
293 | noiselevel | |
246 | """ |
|
294 | """ | |
247 |
|
295 | |||
248 | for channel in range(self.nChannels): |
|
296 | for channel in range(self.nChannels): | |
249 | daux = self.data_spc[channel,:,:] |
|
297 | daux = self.data_spc[channel,:,:] | |
250 | self.noise[channel] = hildebrand_sekhon(daux, self.nCohInt) |
|
298 | self.noise[channel] = hildebrand_sekhon(daux, self.nCohInt) | |
251 |
|
299 | |||
252 | return self.noise |
|
300 | return self.noise | |
253 |
|
301 | |||
254 | def getNoise(self, type = 1): |
|
302 | def getNoise(self, type = 1): | |
255 |
|
303 | |||
256 | self.noise = numpy.zeros(self.nChannels) |
|
304 | self.noise = numpy.zeros(self.nChannels) | |
257 |
|
305 | |||
258 | if type == 1: |
|
306 | if type == 1: | |
259 | noise = self.getNoisebyHildebrand() |
|
307 | noise = self.getNoisebyHildebrand() | |
260 |
|
308 | |||
261 | return 10*numpy.log10(noise) |
|
309 | return 10*numpy.log10(noise) | |
262 |
|
310 | |||
263 | class Spectra(JROData): |
|
311 | class Spectra(JROData): | |
264 |
|
312 | |||
265 | #data es un numpy array de 2 dmensiones (canales, perfiles, alturas) |
|
313 | #data es un numpy array de 2 dmensiones (canales, perfiles, alturas) | |
266 | data_spc = None |
|
314 | data_spc = None | |
267 |
|
315 | |||
268 | #data es un numpy array de 2 dmensiones (canales, pares, alturas) |
|
316 | #data es un numpy array de 2 dmensiones (canales, pares, alturas) | |
269 | data_cspc = None |
|
317 | data_cspc = None | |
270 |
|
318 | |||
271 | #data es un numpy array de 2 dmensiones (canales, alturas) |
|
319 | #data es un numpy array de 2 dmensiones (canales, alturas) | |
272 | data_dc = None |
|
320 | data_dc = None | |
273 |
|
321 | |||
274 | nFFTPoints = None |
|
322 | nFFTPoints = None | |
275 |
|
323 | |||
276 | nPairs = None |
|
324 | nPairs = None | |
277 |
|
325 | |||
278 | pairsList = None |
|
326 | pairsList = None | |
279 |
|
327 | |||
280 | nIncohInt = None |
|
328 | nIncohInt = None | |
281 |
|
329 | |||
282 | wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia |
|
330 | wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia | |
283 |
|
331 | |||
284 | nCohInt = None #se requiere para determinar el valor de timeInterval |
|
332 | nCohInt = None #se requiere para determinar el valor de timeInterval | |
285 |
|
333 | |||
286 | def __init__(self): |
|
334 | def __init__(self): | |
287 | ''' |
|
335 | ''' | |
288 | Constructor |
|
336 | Constructor | |
289 | ''' |
|
337 | ''' | |
290 |
|
338 | |||
291 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
339 | self.radarControllerHeaderObj = RadarControllerHeader() | |
292 |
|
340 | |||
293 | self.systemHeaderObj = SystemHeader() |
|
341 | self.systemHeaderObj = SystemHeader() | |
294 |
|
342 | |||
295 | self.type = "Spectra" |
|
343 | self.type = "Spectra" | |
296 |
|
344 | |||
297 | # self.data = None |
|
345 | # self.data = None | |
298 |
|
346 | |||
299 | self.dtype = None |
|
347 | self.dtype = None | |
300 |
|
348 | |||
301 | # self.nChannels = 0 |
|
349 | # self.nChannels = 0 | |
302 |
|
350 | |||
303 | self.nHeights = 0 |
|
351 | # self.nHeights = 0 | |
304 |
|
352 | |||
305 | self.nProfiles = None |
|
353 | self.nProfiles = None | |
306 |
|
354 | |||
307 | self.heightList = None |
|
355 | self.heightList = None | |
308 |
|
356 | |||
309 | self.channelList = None |
|
357 | self.channelList = None | |
310 |
|
358 | |||
311 | # self.channelIndexList = None |
|
359 | # self.channelIndexList = None | |
312 |
|
360 | |||
313 | self.flagNoData = True |
|
361 | self.flagNoData = True | |
314 |
|
362 | |||
315 | self.flagTimeBlock = False |
|
363 | self.flagTimeBlock = False | |
316 |
|
364 | |||
317 | self.utctime = None |
|
365 | self.utctime = None | |
318 |
|
366 | |||
319 | self.nCohInt = None |
|
367 | self.nCohInt = None | |
320 |
|
368 | |||
321 | self.nIncohInt = None |
|
369 | self.nIncohInt = None | |
322 |
|
370 | |||
323 | self.blocksize = None |
|
371 | self.blocksize = None | |
324 |
|
372 | |||
325 | self.nFFTPoints = None |
|
373 | self.nFFTPoints = None | |
326 |
|
374 | |||
327 | self.wavelength = None |
|
375 | self.wavelength = None | |
328 |
|
||||
329 | def getFmax(self): |
|
|||
330 |
|
||||
331 | PRF = 1./(self.ippSeconds * self.nCohInt) |
|
|||
332 |
|
||||
333 | fmax = PRF/2. |
|
|||
334 |
|
||||
335 | return fmax |
|
|||
336 |
|
||||
337 | def getVmax(self): |
|
|||
338 |
|
||||
339 | _lambda = self.C/self.frequency |
|
|||
340 |
|
||||
341 | vmax = self.getFmax() * _lambda / 2. |
|
|||
342 |
|
||||
343 | return vmax |
|
|||
344 |
|
376 | |||
345 | def getFreqRange(self, extrapoints=0): |
|
377 | def getFreqRange(self, extrapoints=0): | |
346 |
|
378 | |||
347 | delfreq = 2 * self.getFmax() / self.nFFTPoints |
|
379 | delfreq = 2 * self.getFmax() / self.nFFTPoints | |
348 | freqrange = deltafreqs*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 |
|
380 | freqrange = deltafreqs*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 | |
349 |
|
381 | |||
350 | return freqrange |
|
382 | return freqrange | |
351 |
|
383 | |||
352 | def getVelRange(self, extrapoints=0): |
|
384 | def getVelRange(self, extrapoints=0): | |
353 |
|
385 | |||
354 | deltav = 2 * self.getVmax() / self.nFFTPoints |
|
386 | deltav = 2 * self.getVmax() / self.nFFTPoints | |
355 | velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltav/2 |
|
387 | velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltav/2 | |
356 |
|
388 | |||
357 | return velrange |
|
389 | return velrange | |
358 |
|
390 | |||
359 | def getNoisebyHildebrand(self): |
|
391 | def getNoisebyHildebrand(self): | |
360 | """ |
|
392 | """ | |
361 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
|
393 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon | |
362 |
|
394 | |||
363 | Return: |
|
395 | Return: | |
364 | noiselevel |
|
396 | noiselevel | |
365 | """ |
|
397 | """ | |
366 |
|
398 | |||
367 | for channel in range(self.nChannels): |
|
399 | for channel in range(self.nChannels): | |
368 | daux = self.data_spc[channel,:,:] |
|
400 | daux = self.data_spc[channel,:,:] | |
369 | self.noise[channel] = hildebrand_sekhon(daux, self.nIncohInt) |
|
401 | self.noise[channel] = hildebrand_sekhon(daux, self.nIncohInt) | |
370 |
|
402 | |||
371 | return self.noise |
|
403 | return self.noise | |
372 |
|
404 | |||
373 | def getNoisebyWindow(self, heiIndexMin=0, heiIndexMax=-1, freqIndexMin=0, freqIndexMax=-1): |
|
405 | def getNoisebyWindow(self, heiIndexMin=0, heiIndexMax=-1, freqIndexMin=0, freqIndexMax=-1): | |
374 | """ |
|
406 | """ | |
375 | Determina el ruido del canal utilizando la ventana indicada con las coordenadas: |
|
407 | Determina el ruido del canal utilizando la ventana indicada con las coordenadas: | |
376 | (heiIndexMIn, freqIndexMin) hasta (heiIndexMax, freqIndexMAx) |
|
408 | (heiIndexMIn, freqIndexMin) hasta (heiIndexMax, freqIndexMAx) | |
377 |
|
409 | |||
378 | Inputs: |
|
410 | Inputs: | |
379 | heiIndexMin: Limite inferior del eje de alturas |
|
411 | heiIndexMin: Limite inferior del eje de alturas | |
380 | heiIndexMax: Limite superior del eje de alturas |
|
412 | heiIndexMax: Limite superior del eje de alturas | |
381 | freqIndexMin: Limite inferior del eje de frecuencia |
|
413 | freqIndexMin: Limite inferior del eje de frecuencia | |
382 | freqIndexMax: Limite supoerior del eje de frecuencia |
|
414 | freqIndexMax: Limite supoerior del eje de frecuencia | |
383 | """ |
|
415 | """ | |
384 |
|
416 | |||
385 | data = self.data_spc[:, heiIndexMin:heiIndexMax, freqIndexMin:freqIndexMax] |
|
417 | data = self.data_spc[:, heiIndexMin:heiIndexMax, freqIndexMin:freqIndexMax] | |
386 |
|
418 | |||
387 | for channel in range(self.nChannels): |
|
419 | for channel in range(self.nChannels): | |
388 | daux = data[channel,:,:] |
|
420 | daux = data[channel,:,:] | |
389 | self.noise[channel] = numpy.average(daux) |
|
421 | self.noise[channel] = numpy.average(daux) | |
390 |
|
422 | |||
391 | return self.noise |
|
423 | return self.noise | |
392 |
|
424 | |||
393 | def getNoisebySort(self): |
|
425 | def getNoisebySort(self): | |
394 |
|
426 | |||
395 | for channel in range(self.nChannels): |
|
427 | for channel in range(self.nChannels): | |
396 | daux = self.data_spc[channel,:,:] |
|
428 | daux = self.data_spc[channel,:,:] | |
397 | self.noise[channel] = sorting_bruce(daux, self.nIncohInt) |
|
429 | self.noise[channel] = sorting_bruce(daux, self.nIncohInt) | |
398 |
|
430 | |||
399 | return self.noise |
|
431 | return self.noise | |
400 |
|
432 | |||
401 | def getNoise(self, type = 1): |
|
433 | def getNoise(self, type = 1): | |
402 |
|
434 | |||
403 | self.noise = numpy.zeros(self.nChannels) |
|
435 | self.noise = numpy.zeros(self.nChannels) | |
404 |
|
436 | |||
405 | if type == 1: |
|
437 | if type == 1: | |
406 | noise = self.getNoisebyHildebrand() |
|
438 | noise = self.getNoisebyHildebrand() | |
407 |
|
439 | |||
408 | if type == 2: |
|
440 | if type == 2: | |
409 | noise = self.getNoisebySort() |
|
441 | noise = self.getNoisebySort() | |
410 |
|
442 | |||
411 | if type == 3: |
|
443 | if type == 3: | |
412 | noise = self.getNoisebyWindow() |
|
444 | noise = self.getNoisebyWindow() | |
413 |
|
445 | |||
414 | return 10*numpy.log10(noise) |
|
446 | return 10*numpy.log10(noise) | |
415 |
|
447 | |||
416 | class SpectraHeis(JROData): |
|
448 | class SpectraHeis(JROData): | |
417 |
|
449 | |||
418 | data_spc = None |
|
450 | data_spc = None | |
419 |
|
451 | |||
420 | data_cspc = None |
|
452 | data_cspc = None | |
421 |
|
453 | |||
422 | data_dc = None |
|
454 | data_dc = None | |
423 |
|
455 | |||
424 | nFFTPoints = None |
|
456 | nFFTPoints = None | |
425 |
|
457 | |||
426 | nPairs = None |
|
458 | nPairs = None | |
427 |
|
459 | |||
428 | pairsList = None |
|
460 | pairsList = None | |
429 |
|
461 | |||
430 | nIncohInt = None |
|
462 | nIncohInt = None | |
431 |
|
463 | |||
432 | def __init__(self): |
|
464 | def __init__(self): | |
433 |
|
465 | |||
434 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
466 | self.radarControllerHeaderObj = RadarControllerHeader() | |
435 |
|
467 | |||
436 | self.systemHeaderObj = SystemHeader() |
|
468 | self.systemHeaderObj = SystemHeader() | |
437 |
|
469 | |||
438 | self.type = "SpectraHeis" |
|
470 | self.type = "SpectraHeis" | |
439 |
|
471 | |||
440 | self.dtype = None |
|
472 | self.dtype = None | |
441 |
|
473 | |||
442 | # self.nChannels = 0 |
|
474 | # self.nChannels = 0 | |
443 |
|
475 | |||
444 | self.nHeights = 0 |
|
476 | # self.nHeights = 0 | |
445 |
|
477 | |||
446 | self.nProfiles = None |
|
478 | self.nProfiles = None | |
447 |
|
479 | |||
448 | self.heightList = None |
|
480 | self.heightList = None | |
449 |
|
481 | |||
450 | self.channelList = None |
|
482 | self.channelList = None | |
451 |
|
483 | |||
452 | # self.channelIndexList = None |
|
484 | # self.channelIndexList = None | |
453 |
|
485 | |||
454 | self.flagNoData = True |
|
486 | self.flagNoData = True | |
455 |
|
487 | |||
456 | self.flagTimeBlock = False |
|
488 | self.flagTimeBlock = False | |
457 |
|
489 | |||
458 | self.nPairs = 0 |
|
490 | self.nPairs = 0 | |
459 |
|
491 | |||
460 | self.utctime = None |
|
492 | self.utctime = None | |
461 |
|
493 | |||
462 | self.blocksize = None |
|
494 | self.blocksize = None |
@@ -1,2479 +1,2479 | |||||
1 | ''' |
|
1 | ''' | |
2 |
|
2 | |||
3 | $Author: murco $ |
|
3 | $Author: murco $ | |
4 | $Id: JRODataIO.py 169 2012-11-19 21:57:03Z murco $ |
|
4 | $Id: JRODataIO.py 169 2012-11-19 21:57:03Z murco $ | |
5 | ''' |
|
5 | ''' | |
6 |
|
6 | |||
7 | import os, sys |
|
7 | import os, sys | |
8 | import glob |
|
8 | import glob | |
9 | import time |
|
9 | import time | |
10 | import numpy |
|
10 | import numpy | |
11 | import fnmatch |
|
11 | import fnmatch | |
12 | import time, datetime |
|
12 | import time, datetime | |
13 |
|
13 | |||
14 | from jrodata import * |
|
14 | from jrodata import * | |
15 | from jroheaderIO import * |
|
15 | from jroheaderIO import * | |
16 | from jroprocessing import * |
|
16 | from jroprocessing import * | |
17 |
|
17 | |||
18 | def isNumber(str): |
|
18 | def isNumber(str): | |
19 | """ |
|
19 | """ | |
20 | Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero. |
|
20 | Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero. | |
21 |
|
21 | |||
22 | Excepciones: |
|
22 | Excepciones: | |
23 | Si un determinado string no puede ser convertido a numero |
|
23 | Si un determinado string no puede ser convertido a numero | |
24 | Input: |
|
24 | Input: | |
25 | str, string al cual se le analiza para determinar si convertible a un numero o no |
|
25 | str, string al cual se le analiza para determinar si convertible a un numero o no | |
26 |
|
26 | |||
27 | Return: |
|
27 | Return: | |
28 | True : si el string es uno numerico |
|
28 | True : si el string es uno numerico | |
29 | False : no es un string numerico |
|
29 | False : no es un string numerico | |
30 | """ |
|
30 | """ | |
31 | try: |
|
31 | try: | |
32 | float( str ) |
|
32 | float( str ) | |
33 | return True |
|
33 | return True | |
34 | except: |
|
34 | except: | |
35 | return False |
|
35 | return False | |
36 |
|
36 | |||
37 | def isThisFileinRange(filename, startUTSeconds, endUTSeconds): |
|
37 | def isThisFileinRange(filename, startUTSeconds, endUTSeconds): | |
38 | """ |
|
38 | """ | |
39 | Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado. |
|
39 | Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado. | |
40 |
|
40 | |||
41 | Inputs: |
|
41 | Inputs: | |
42 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) |
|
42 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) | |
43 |
|
43 | |||
44 | startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en |
|
44 | startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en | |
45 | segundos contados desde 01/01/1970. |
|
45 | segundos contados desde 01/01/1970. | |
46 | endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en |
|
46 | endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en | |
47 | segundos contados desde 01/01/1970. |
|
47 | segundos contados desde 01/01/1970. | |
48 |
|
48 | |||
49 | Return: |
|
49 | Return: | |
50 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de |
|
50 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de | |
51 | fecha especificado, de lo contrario retorna False. |
|
51 | fecha especificado, de lo contrario retorna False. | |
52 |
|
52 | |||
53 | Excepciones: |
|
53 | Excepciones: | |
54 | Si el archivo no existe o no puede ser abierto |
|
54 | Si el archivo no existe o no puede ser abierto | |
55 | Si la cabecera no puede ser leida. |
|
55 | Si la cabecera no puede ser leida. | |
56 |
|
56 | |||
57 | """ |
|
57 | """ | |
58 | basicHeaderObj = BasicHeader() |
|
58 | basicHeaderObj = BasicHeader() | |
59 |
|
59 | |||
60 | try: |
|
60 | try: | |
61 | fp = open(filename,'rb') |
|
61 | fp = open(filename,'rb') | |
62 | except: |
|
62 | except: | |
63 | raise IOError, "The file %s can't be opened" %(filename) |
|
63 | raise IOError, "The file %s can't be opened" %(filename) | |
64 |
|
64 | |||
65 | sts = basicHeaderObj.read(fp) |
|
65 | sts = basicHeaderObj.read(fp) | |
66 | fp.close() |
|
66 | fp.close() | |
67 |
|
67 | |||
68 | if not(sts): |
|
68 | if not(sts): | |
69 | print "Skipping the file %s because it has not a valid header" %(filename) |
|
69 | print "Skipping the file %s because it has not a valid header" %(filename) | |
70 | return 0 |
|
70 | return 0 | |
71 |
|
71 | |||
72 | if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)): |
|
72 | if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)): | |
73 | return 0 |
|
73 | return 0 | |
74 |
|
74 | |||
75 | return 1 |
|
75 | return 1 | |
76 |
|
76 | |||
77 | def getlastFileFromPath(path, ext): |
|
77 | def getlastFileFromPath(path, ext): | |
78 | """ |
|
78 | """ | |
79 | Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext" |
|
79 | Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext" | |
80 | al final de la depuracion devuelve el ultimo file de la lista que quedo. |
|
80 | al final de la depuracion devuelve el ultimo file de la lista que quedo. | |
81 |
|
81 | |||
82 | Input: |
|
82 | Input: | |
83 | fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta |
|
83 | fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta | |
84 | ext : extension de los files contenidos en una carpeta |
|
84 | ext : extension de los files contenidos en una carpeta | |
85 |
|
85 | |||
86 | Return: |
|
86 | Return: | |
87 | El ultimo file de una determinada carpeta, no se considera el path. |
|
87 | El ultimo file de una determinada carpeta, no se considera el path. | |
88 | """ |
|
88 | """ | |
89 | validFilelist = [] |
|
89 | validFilelist = [] | |
90 | fileList = os.listdir(path) |
|
90 | fileList = os.listdir(path) | |
91 |
|
91 | |||
92 | # 0 1234 567 89A BCDE |
|
92 | # 0 1234 567 89A BCDE | |
93 | # H YYYY DDD SSS .ext |
|
93 | # H YYYY DDD SSS .ext | |
94 |
|
94 | |||
95 | for file in fileList: |
|
95 | for file in fileList: | |
96 | try: |
|
96 | try: | |
97 | year = int(file[1:5]) |
|
97 | year = int(file[1:5]) | |
98 | doy = int(file[5:8]) |
|
98 | doy = int(file[5:8]) | |
99 |
|
99 | |||
100 | if (os.path.splitext(file)[-1].upper() != ext.upper()) : continue |
|
100 | if (os.path.splitext(file)[-1].upper() != ext.upper()) : continue | |
101 | except: |
|
101 | except: | |
102 | continue |
|
102 | continue | |
103 |
|
103 | |||
104 | validFilelist.append(file) |
|
104 | validFilelist.append(file) | |
105 |
|
105 | |||
106 | if validFilelist: |
|
106 | if validFilelist: | |
107 | validFilelist = sorted( validFilelist, key=str.lower ) |
|
107 | validFilelist = sorted( validFilelist, key=str.lower ) | |
108 | return validFilelist[-1] |
|
108 | return validFilelist[-1] | |
109 |
|
109 | |||
110 | return None |
|
110 | return None | |
111 |
|
111 | |||
112 | def checkForRealPath(path, year, doy, set, ext): |
|
112 | def checkForRealPath(path, year, doy, set, ext): | |
113 | """ |
|
113 | """ | |
114 | Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path, |
|
114 | Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path, | |
115 | Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar |
|
115 | Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar | |
116 | el path exacto de un determinado file. |
|
116 | el path exacto de un determinado file. | |
117 |
|
117 | |||
118 | Example : |
|
118 | Example : | |
119 | nombre correcto del file es .../.../D2009307/P2009307367.ext |
|
119 | nombre correcto del file es .../.../D2009307/P2009307367.ext | |
120 |
|
120 | |||
121 | Entonces la funcion prueba con las siguientes combinaciones |
|
121 | Entonces la funcion prueba con las siguientes combinaciones | |
122 | .../.../x2009307/y2009307367.ext |
|
122 | .../.../x2009307/y2009307367.ext | |
123 | .../.../x2009307/Y2009307367.ext |
|
123 | .../.../x2009307/Y2009307367.ext | |
124 | .../.../X2009307/y2009307367.ext |
|
124 | .../.../X2009307/y2009307367.ext | |
125 | .../.../X2009307/Y2009307367.ext |
|
125 | .../.../X2009307/Y2009307367.ext | |
126 | siendo para este caso, la ultima combinacion de letras, identica al file buscado |
|
126 | siendo para este caso, la ultima combinacion de letras, identica al file buscado | |
127 |
|
127 | |||
128 | Return: |
|
128 | Return: | |
129 | Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file |
|
129 | Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file | |
130 | caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas |
|
130 | caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas | |
131 | para el filename |
|
131 | para el filename | |
132 | """ |
|
132 | """ | |
133 | filepath = None |
|
133 | filepath = None | |
134 | find_flag = False |
|
134 | find_flag = False | |
135 | filename = None |
|
135 | filename = None | |
136 |
|
136 | |||
137 | if ext.lower() == ".r": #voltage |
|
137 | if ext.lower() == ".r": #voltage | |
138 | header1 = "dD" |
|
138 | header1 = "dD" | |
139 | header2 = "dD" |
|
139 | header2 = "dD" | |
140 | elif ext.lower() == ".pdata": #spectra |
|
140 | elif ext.lower() == ".pdata": #spectra | |
141 | header1 = "dD" |
|
141 | header1 = "dD" | |
142 | header2 = "pP" |
|
142 | header2 = "pP" | |
143 | else: |
|
143 | else: | |
144 | return None, filename |
|
144 | return None, filename | |
145 |
|
145 | |||
146 | for dir in header1: #barrido por las dos combinaciones posibles de "D" |
|
146 | for dir in header1: #barrido por las dos combinaciones posibles de "D" | |
147 | for fil in header2: #barrido por las dos combinaciones posibles de "D" |
|
147 | for fil in header2: #barrido por las dos combinaciones posibles de "D" | |
148 | doypath = "%s%04d%03d" % ( dir, year, doy ) #formo el nombre del directorio xYYYYDDD (x=d o x=D) |
|
148 | doypath = "%s%04d%03d" % ( dir, year, doy ) #formo el nombre del directorio xYYYYDDD (x=d o x=D) | |
149 | filename = "%s%04d%03d%03d%s" % ( fil, year, doy, set, ext ) #formo el nombre del file xYYYYDDDSSS.ext |
|
149 | filename = "%s%04d%03d%03d%s" % ( fil, year, doy, set, ext ) #formo el nombre del file xYYYYDDDSSS.ext | |
150 | filepath = os.path.join( path, doypath, filename ) #formo el path completo |
|
150 | filepath = os.path.join( path, doypath, filename ) #formo el path completo | |
151 | if os.path.exists( filepath ): #verifico que exista |
|
151 | if os.path.exists( filepath ): #verifico que exista | |
152 | find_flag = True |
|
152 | find_flag = True | |
153 | break |
|
153 | break | |
154 | if find_flag: |
|
154 | if find_flag: | |
155 | break |
|
155 | break | |
156 |
|
156 | |||
157 | if not(find_flag): |
|
157 | if not(find_flag): | |
158 | return None, filename |
|
158 | return None, filename | |
159 |
|
159 | |||
160 | return filepath, filename |
|
160 | return filepath, filename | |
161 |
|
161 | |||
162 | class JRODataIO: |
|
162 | class JRODataIO: | |
163 |
|
163 | |||
164 | c = 3E8 |
|
164 | c = 3E8 | |
165 |
|
165 | |||
166 | isConfig = False |
|
166 | isConfig = False | |
167 |
|
167 | |||
168 | basicHeaderObj = BasicHeader() |
|
168 | basicHeaderObj = BasicHeader() | |
169 |
|
169 | |||
170 | systemHeaderObj = SystemHeader() |
|
170 | systemHeaderObj = SystemHeader() | |
171 |
|
171 | |||
172 | radarControllerHeaderObj = RadarControllerHeader() |
|
172 | radarControllerHeaderObj = RadarControllerHeader() | |
173 |
|
173 | |||
174 | processingHeaderObj = ProcessingHeader() |
|
174 | processingHeaderObj = ProcessingHeader() | |
175 |
|
175 | |||
176 | online = 0 |
|
176 | online = 0 | |
177 |
|
177 | |||
178 | dtype = None |
|
178 | dtype = None | |
179 |
|
179 | |||
180 | pathList = [] |
|
180 | pathList = [] | |
181 |
|
181 | |||
182 | filenameList = [] |
|
182 | filenameList = [] | |
183 |
|
183 | |||
184 | filename = None |
|
184 | filename = None | |
185 |
|
185 | |||
186 | ext = None |
|
186 | ext = None | |
187 |
|
187 | |||
188 | flagIsNewFile = 1 |
|
188 | flagIsNewFile = 1 | |
189 |
|
189 | |||
190 | flagTimeBlock = 0 |
|
190 | flagTimeBlock = 0 | |
191 |
|
191 | |||
192 | flagIsNewBlock = 0 |
|
192 | flagIsNewBlock = 0 | |
193 |
|
193 | |||
194 | fp = None |
|
194 | fp = None | |
195 |
|
195 | |||
196 | firstHeaderSize = 0 |
|
196 | firstHeaderSize = 0 | |
197 |
|
197 | |||
198 | basicHeaderSize = 24 |
|
198 | basicHeaderSize = 24 | |
199 |
|
199 | |||
200 | versionFile = 1103 |
|
200 | versionFile = 1103 | |
201 |
|
201 | |||
202 | fileSize = None |
|
202 | fileSize = None | |
203 |
|
203 | |||
204 | ippSeconds = None |
|
204 | ippSeconds = None | |
205 |
|
205 | |||
206 | fileSizeByHeader = None |
|
206 | fileSizeByHeader = None | |
207 |
|
207 | |||
208 | fileIndex = None |
|
208 | fileIndex = None | |
209 |
|
209 | |||
210 | profileIndex = None |
|
210 | profileIndex = None | |
211 |
|
211 | |||
212 | blockIndex = None |
|
212 | blockIndex = None | |
213 |
|
213 | |||
214 | nTotalBlocks = None |
|
214 | nTotalBlocks = None | |
215 |
|
215 | |||
216 | maxTimeStep = 30 |
|
216 | maxTimeStep = 30 | |
217 |
|
217 | |||
218 | lastUTTime = None |
|
218 | lastUTTime = None | |
219 |
|
219 | |||
220 | datablock = None |
|
220 | datablock = None | |
221 |
|
221 | |||
222 | dataOut = None |
|
222 | dataOut = None | |
223 |
|
223 | |||
224 | blocksize = None |
|
224 | blocksize = None | |
225 |
|
225 | |||
226 | def __init__(self): |
|
226 | def __init__(self): | |
227 |
|
227 | |||
228 | raise ValueError, "Not implemented" |
|
228 | raise ValueError, "Not implemented" | |
229 |
|
229 | |||
230 | def run(self): |
|
230 | def run(self): | |
231 |
|
231 | |||
232 | raise ValueError, "Not implemented" |
|
232 | raise ValueError, "Not implemented" | |
233 |
|
233 | |||
234 | def getOutput(self): |
|
234 | def getOutput(self): | |
235 |
|
235 | |||
236 | return self.dataOut |
|
236 | return self.dataOut | |
237 |
|
237 | |||
238 | class JRODataReader(JRODataIO, ProcessingUnit): |
|
238 | class JRODataReader(JRODataIO, ProcessingUnit): | |
239 |
|
239 | |||
240 | nReadBlocks = 0 |
|
240 | nReadBlocks = 0 | |
241 |
|
241 | |||
242 | delay = 60 #number of seconds waiting a new file |
|
242 | delay = 60 #number of seconds waiting a new file | |
243 |
|
243 | |||
244 | nTries = 3 #quantity tries |
|
244 | nTries = 3 #quantity tries | |
245 |
|
245 | |||
246 | nFiles = 3 #number of files for searching |
|
246 | nFiles = 3 #number of files for searching | |
247 |
|
247 | |||
248 | flagNoMoreFiles = 0 |
|
248 | flagNoMoreFiles = 0 | |
249 |
|
249 | |||
250 | def __init__(self): |
|
250 | def __init__(self): | |
251 |
|
251 | |||
252 | """ |
|
252 | """ | |
253 |
|
253 | |||
254 | """ |
|
254 | """ | |
255 |
|
255 | |||
256 | raise ValueError, "This method has not been implemented" |
|
256 | raise ValueError, "This method has not been implemented" | |
257 |
|
257 | |||
258 |
|
258 | |||
259 | def createObjByDefault(self): |
|
259 | def createObjByDefault(self): | |
260 | """ |
|
260 | """ | |
261 |
|
261 | |||
262 | """ |
|
262 | """ | |
263 | raise ValueError, "This method has not been implemented" |
|
263 | raise ValueError, "This method has not been implemented" | |
264 |
|
264 | |||
265 | def getBlockDimension(self): |
|
265 | def getBlockDimension(self): | |
266 |
|
266 | |||
267 | raise ValueError, "No implemented" |
|
267 | raise ValueError, "No implemented" | |
268 |
|
268 | |||
269 | def __searchFilesOffLine(self, |
|
269 | def __searchFilesOffLine(self, | |
270 | path, |
|
270 | path, | |
271 | startDate, |
|
271 | startDate, | |
272 | endDate, |
|
272 | endDate, | |
273 | startTime=datetime.time(0,0,0), |
|
273 | startTime=datetime.time(0,0,0), | |
274 | endTime=datetime.time(23,59,59), |
|
274 | endTime=datetime.time(23,59,59), | |
275 | set=None, |
|
275 | set=None, | |
276 | expLabel="", |
|
276 | expLabel="", | |
277 | ext=".r"): |
|
277 | ext=".r"): | |
278 | dirList = [] |
|
278 | dirList = [] | |
279 | for thisPath in os.listdir(path): |
|
279 | for thisPath in os.listdir(path): | |
280 | if os.path.isdir(os.path.join(path,thisPath)): |
|
280 | if os.path.isdir(os.path.join(path,thisPath)): | |
281 | dirList.append(thisPath) |
|
281 | dirList.append(thisPath) | |
282 |
|
282 | |||
283 | if not(dirList): |
|
283 | if not(dirList): | |
284 | return None, None |
|
284 | return None, None | |
285 |
|
285 | |||
286 | pathList = [] |
|
286 | pathList = [] | |
287 | dateList = [] |
|
287 | dateList = [] | |
288 |
|
288 | |||
289 | thisDate = startDate |
|
289 | thisDate = startDate | |
290 |
|
290 | |||
291 | while(thisDate <= endDate): |
|
291 | while(thisDate <= endDate): | |
292 | year = thisDate.timetuple().tm_year |
|
292 | year = thisDate.timetuple().tm_year | |
293 | doy = thisDate.timetuple().tm_yday |
|
293 | doy = thisDate.timetuple().tm_yday | |
294 |
|
294 | |||
295 | match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy)) |
|
295 | match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy)) | |
296 | if len(match) == 0: |
|
296 | if len(match) == 0: | |
297 | thisDate += datetime.timedelta(1) |
|
297 | thisDate += datetime.timedelta(1) | |
298 | continue |
|
298 | continue | |
299 |
|
299 | |||
300 | pathList.append(os.path.join(path,match[0],expLabel)) |
|
300 | pathList.append(os.path.join(path,match[0],expLabel)) | |
301 | dateList.append(thisDate) |
|
301 | dateList.append(thisDate) | |
302 | thisDate += datetime.timedelta(1) |
|
302 | thisDate += datetime.timedelta(1) | |
303 |
|
303 | |||
304 | filenameList = [] |
|
304 | filenameList = [] | |
305 | for index in range(len(pathList)): |
|
305 | for index in range(len(pathList)): | |
306 |
|
306 | |||
307 | thisPath = pathList[index] |
|
307 | thisPath = pathList[index] | |
308 | fileList = glob.glob1(thisPath, "*%s" %ext) |
|
308 | fileList = glob.glob1(thisPath, "*%s" %ext) | |
309 | fileList.sort() |
|
309 | fileList.sort() | |
310 |
|
310 | |||
311 | #Busqueda de datos en el rango de horas indicados |
|
311 | #Busqueda de datos en el rango de horas indicados | |
312 | thisDate = dateList[index] |
|
312 | thisDate = dateList[index] | |
313 | startDT = datetime.datetime.combine(thisDate, startTime) |
|
313 | startDT = datetime.datetime.combine(thisDate, startTime) | |
314 | endDT = datetime.datetime.combine(thisDate, endTime) |
|
314 | endDT = datetime.datetime.combine(thisDate, endTime) | |
315 |
|
315 | |||
316 | startUtSeconds = time.mktime(startDT.timetuple()) |
|
316 | startUtSeconds = time.mktime(startDT.timetuple()) | |
317 | endUtSeconds = time.mktime(endDT.timetuple()) |
|
317 | endUtSeconds = time.mktime(endDT.timetuple()) | |
318 |
|
318 | |||
319 | for file in fileList: |
|
319 | for file in fileList: | |
320 |
|
320 | |||
321 | filename = os.path.join(thisPath,file) |
|
321 | filename = os.path.join(thisPath,file) | |
322 |
|
322 | |||
323 | if isThisFileinRange(filename, startUtSeconds, endUtSeconds): |
|
323 | if isThisFileinRange(filename, startUtSeconds, endUtSeconds): | |
324 | filenameList.append(filename) |
|
324 | filenameList.append(filename) | |
325 |
|
325 | |||
326 | if not(filenameList): |
|
326 | if not(filenameList): | |
327 | return None, None |
|
327 | return None, None | |
328 |
|
328 | |||
329 | self.filenameList = filenameList |
|
329 | self.filenameList = filenameList | |
330 |
|
330 | |||
331 | return pathList, filenameList |
|
331 | return pathList, filenameList | |
332 |
|
332 | |||
333 | def __searchFilesOnLine(self, path, startDate=None, endDate=None, startTime=None, endTime=None, expLabel = "", ext = None): |
|
333 | def __searchFilesOnLine(self, path, startDate=None, endDate=None, startTime=None, endTime=None, expLabel = "", ext = None): | |
334 |
|
334 | |||
335 | """ |
|
335 | """ | |
336 | Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y |
|
336 | Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y | |
337 | devuelve el archivo encontrado ademas de otros datos. |
|
337 | devuelve el archivo encontrado ademas de otros datos. | |
338 |
|
338 | |||
339 | Input: |
|
339 | Input: | |
340 | path : carpeta donde estan contenidos los files que contiene data |
|
340 | path : carpeta donde estan contenidos los files que contiene data | |
341 |
|
341 | |||
342 | startDate : Fecha inicial. Rechaza todos los directorios donde |
|
342 | startDate : Fecha inicial. Rechaza todos los directorios donde | |
343 | file end time < startDate (obejto datetime.date) |
|
343 | file end time < startDate (obejto datetime.date) | |
344 |
|
344 | |||
345 | endDate : Fecha final. Rechaza todos los directorios donde |
|
345 | endDate : Fecha final. Rechaza todos los directorios donde | |
346 | file start time > endDate (obejto datetime.date) |
|
346 | file start time > endDate (obejto datetime.date) | |
347 |
|
347 | |||
348 | startTime : Tiempo inicial. Rechaza todos los archivos donde |
|
348 | startTime : Tiempo inicial. Rechaza todos los archivos donde | |
349 | file end time < startTime (obejto datetime.time) |
|
349 | file end time < startTime (obejto datetime.time) | |
350 |
|
350 | |||
351 | endTime : Tiempo final. Rechaza todos los archivos donde |
|
351 | endTime : Tiempo final. Rechaza todos los archivos donde | |
352 | file start time > endTime (obejto datetime.time) |
|
352 | file start time > endTime (obejto datetime.time) | |
353 |
|
353 | |||
354 | expLabel : Nombre del subexperimento (subfolder) |
|
354 | expLabel : Nombre del subexperimento (subfolder) | |
355 |
|
355 | |||
356 | ext : extension de los files |
|
356 | ext : extension de los files | |
357 |
|
357 | |||
358 | Return: |
|
358 | Return: | |
359 | directory : eL directorio donde esta el file encontrado |
|
359 | directory : eL directorio donde esta el file encontrado | |
360 | filename : el ultimo file de una determinada carpeta |
|
360 | filename : el ultimo file de una determinada carpeta | |
361 | year : el anho |
|
361 | year : el anho | |
362 | doy : el numero de dia del anho |
|
362 | doy : el numero de dia del anho | |
363 | set : el set del archivo |
|
363 | set : el set del archivo | |
364 |
|
364 | |||
365 |
|
365 | |||
366 | """ |
|
366 | """ | |
367 | dirList = [] |
|
367 | dirList = [] | |
368 | pathList = [] |
|
368 | pathList = [] | |
369 | directory = None |
|
369 | directory = None | |
370 |
|
370 | |||
371 | #Filtra solo los directorios |
|
371 | #Filtra solo los directorios | |
372 | for thisPath in os.listdir(path): |
|
372 | for thisPath in os.listdir(path): | |
373 | if os.path.isdir(os.path.join(path, thisPath)): |
|
373 | if os.path.isdir(os.path.join(path, thisPath)): | |
374 | dirList.append(thisPath) |
|
374 | dirList.append(thisPath) | |
375 |
|
375 | |||
376 | if not(dirList): |
|
376 | if not(dirList): | |
377 | return None, None, None, None, None |
|
377 | return None, None, None, None, None | |
378 |
|
378 | |||
379 | dirList = sorted( dirList, key=str.lower ) |
|
379 | dirList = sorted( dirList, key=str.lower ) | |
380 |
|
380 | |||
381 | if startDate: |
|
381 | if startDate: | |
382 | startDateTime = datetime.datetime.combine(startDate, startTime) |
|
382 | startDateTime = datetime.datetime.combine(startDate, startTime) | |
383 | thisDateTime = startDateTime |
|
383 | thisDateTime = startDateTime | |
384 | if endDate == None: endDateTime = startDateTime |
|
384 | if endDate == None: endDateTime = startDateTime | |
385 | else: endDateTime = datetime.datetime.combine(endDate, endTime) |
|
385 | else: endDateTime = datetime.datetime.combine(endDate, endTime) | |
386 |
|
386 | |||
387 | while(thisDateTime <= endDateTime): |
|
387 | while(thisDateTime <= endDateTime): | |
388 | year = thisDateTime.timetuple().tm_year |
|
388 | year = thisDateTime.timetuple().tm_year | |
389 | doy = thisDateTime.timetuple().tm_yday |
|
389 | doy = thisDateTime.timetuple().tm_yday | |
390 |
|
390 | |||
391 | match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy)) |
|
391 | match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy)) | |
392 | if len(match) == 0: |
|
392 | if len(match) == 0: | |
393 | thisDateTime += datetime.timedelta(1) |
|
393 | thisDateTime += datetime.timedelta(1) | |
394 | continue |
|
394 | continue | |
395 |
|
395 | |||
396 | pathList.append(os.path.join(path,match[0], expLabel)) |
|
396 | pathList.append(os.path.join(path,match[0], expLabel)) | |
397 | thisDateTime += datetime.timedelta(1) |
|
397 | thisDateTime += datetime.timedelta(1) | |
398 |
|
398 | |||
399 | if not(pathList): |
|
399 | if not(pathList): | |
400 | print "\tNo files in range: %s - %s" %(startDateTime.ctime(), endDateTime.ctime()) |
|
400 | print "\tNo files in range: %s - %s" %(startDateTime.ctime(), endDateTime.ctime()) | |
401 | return None, None, None, None, None |
|
401 | return None, None, None, None, None | |
402 |
|
402 | |||
403 | directory = pathList[0] |
|
403 | directory = pathList[0] | |
404 |
|
404 | |||
405 | else: |
|
405 | else: | |
406 | directory = dirList[-1] |
|
406 | directory = dirList[-1] | |
407 | directory = os.path.join(path,directory) |
|
407 | directory = os.path.join(path,directory) | |
408 |
|
408 | |||
409 | filename = getlastFileFromPath(directory, ext) |
|
409 | filename = getlastFileFromPath(directory, ext) | |
410 |
|
410 | |||
411 | if not(filename): |
|
411 | if not(filename): | |
412 | return None, None, None, None, None |
|
412 | return None, None, None, None, None | |
413 |
|
413 | |||
414 | if not(self.__verifyFile(os.path.join(directory, filename))): |
|
414 | if not(self.__verifyFile(os.path.join(directory, filename))): | |
415 | return None, None, None, None, None |
|
415 | return None, None, None, None, None | |
416 |
|
416 | |||
417 | year = int( filename[1:5] ) |
|
417 | year = int( filename[1:5] ) | |
418 | doy = int( filename[5:8] ) |
|
418 | doy = int( filename[5:8] ) | |
419 | set = int( filename[8:11] ) |
|
419 | set = int( filename[8:11] ) | |
420 |
|
420 | |||
421 | return directory, filename, year, doy, set |
|
421 | return directory, filename, year, doy, set | |
422 |
|
422 | |||
423 |
|
423 | |||
424 |
|
424 | |||
425 | def __setNextFileOffline(self): |
|
425 | def __setNextFileOffline(self): | |
426 |
|
426 | |||
427 | idFile = self.fileIndex |
|
427 | idFile = self.fileIndex | |
428 |
|
428 | |||
429 | while (True): |
|
429 | while (True): | |
430 | idFile += 1 |
|
430 | idFile += 1 | |
431 | if not(idFile < len(self.filenameList)): |
|
431 | if not(idFile < len(self.filenameList)): | |
432 | self.flagNoMoreFiles = 1 |
|
432 | self.flagNoMoreFiles = 1 | |
433 | print "No more Files" |
|
433 | print "No more Files" | |
434 | return 0 |
|
434 | return 0 | |
435 |
|
435 | |||
436 | filename = self.filenameList[idFile] |
|
436 | filename = self.filenameList[idFile] | |
437 |
|
437 | |||
438 | if not(self.__verifyFile(filename)): |
|
438 | if not(self.__verifyFile(filename)): | |
439 | continue |
|
439 | continue | |
440 |
|
440 | |||
441 | fileSize = os.path.getsize(filename) |
|
441 | fileSize = os.path.getsize(filename) | |
442 | fp = open(filename,'rb') |
|
442 | fp = open(filename,'rb') | |
443 | break |
|
443 | break | |
444 |
|
444 | |||
445 | self.flagIsNewFile = 1 |
|
445 | self.flagIsNewFile = 1 | |
446 | self.fileIndex = idFile |
|
446 | self.fileIndex = idFile | |
447 | self.filename = filename |
|
447 | self.filename = filename | |
448 | self.fileSize = fileSize |
|
448 | self.fileSize = fileSize | |
449 | self.fp = fp |
|
449 | self.fp = fp | |
450 |
|
450 | |||
451 | print "Setting the file: %s"%self.filename |
|
451 | print "Setting the file: %s"%self.filename | |
452 |
|
452 | |||
453 | return 1 |
|
453 | return 1 | |
454 |
|
454 | |||
455 | def __setNextFileOnline(self): |
|
455 | def __setNextFileOnline(self): | |
456 | """ |
|
456 | """ | |
457 | Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si |
|
457 | Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si | |
458 | no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files |
|
458 | no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files | |
459 | siguientes. |
|
459 | siguientes. | |
460 |
|
460 | |||
461 | Affected: |
|
461 | Affected: | |
462 | self.flagIsNewFile |
|
462 | self.flagIsNewFile | |
463 | self.filename |
|
463 | self.filename | |
464 | self.fileSize |
|
464 | self.fileSize | |
465 | self.fp |
|
465 | self.fp | |
466 | self.set |
|
466 | self.set | |
467 | self.flagNoMoreFiles |
|
467 | self.flagNoMoreFiles | |
468 |
|
468 | |||
469 | Return: |
|
469 | Return: | |
470 | 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado |
|
470 | 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado | |
471 | 1 : si el file fue abierto con exito y esta listo a ser leido |
|
471 | 1 : si el file fue abierto con exito y esta listo a ser leido | |
472 |
|
472 | |||
473 | Excepciones: |
|
473 | Excepciones: | |
474 | Si un determinado file no puede ser abierto |
|
474 | Si un determinado file no puede ser abierto | |
475 | """ |
|
475 | """ | |
476 | nFiles = 0 |
|
476 | nFiles = 0 | |
477 | fileOk_flag = False |
|
477 | fileOk_flag = False | |
478 | firstTime_flag = True |
|
478 | firstTime_flag = True | |
479 |
|
479 | |||
480 | self.set += 1 |
|
480 | self.set += 1 | |
481 |
|
481 | |||
482 | #busca el 1er file disponible |
|
482 | #busca el 1er file disponible | |
483 | file, filename = checkForRealPath( self.path, self.year, self.doy, self.set, self.ext ) |
|
483 | file, filename = checkForRealPath( self.path, self.year, self.doy, self.set, self.ext ) | |
484 | if file: |
|
484 | if file: | |
485 | if self.__verifyFile(file, False): |
|
485 | if self.__verifyFile(file, False): | |
486 | fileOk_flag = True |
|
486 | fileOk_flag = True | |
487 |
|
487 | |||
488 | #si no encuentra un file entonces espera y vuelve a buscar |
|
488 | #si no encuentra un file entonces espera y vuelve a buscar | |
489 | if not(fileOk_flag): |
|
489 | if not(fileOk_flag): | |
490 | for nFiles in range(self.nFiles+1): #busco en los siguientes self.nFiles+1 files posibles |
|
490 | for nFiles in range(self.nFiles+1): #busco en los siguientes self.nFiles+1 files posibles | |
491 |
|
491 | |||
492 | if firstTime_flag: #si es la 1era vez entonces hace el for self.nTries veces |
|
492 | if firstTime_flag: #si es la 1era vez entonces hace el for self.nTries veces | |
493 | tries = self.nTries |
|
493 | tries = self.nTries | |
494 | else: |
|
494 | else: | |
495 | tries = 1 #si no es la 1era vez entonces solo lo hace una vez |
|
495 | tries = 1 #si no es la 1era vez entonces solo lo hace una vez | |
496 |
|
496 | |||
497 | for nTries in range( tries ): |
|
497 | for nTries in range( tries ): | |
498 | if firstTime_flag: |
|
498 | if firstTime_flag: | |
499 | print "\tWaiting %0.2f sec for the file \"%s\" , try %03d ..." % ( self.delay, filename, nTries+1 ) |
|
499 | print "\tWaiting %0.2f sec for the file \"%s\" , try %03d ..." % ( self.delay, filename, nTries+1 ) | |
500 | time.sleep( self.delay ) |
|
500 | time.sleep( self.delay ) | |
501 | else: |
|
501 | else: | |
502 | print "\tSearching next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext) |
|
502 | print "\tSearching next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext) | |
503 |
|
503 | |||
504 | file, filename = checkForRealPath( self.path, self.year, self.doy, self.set, self.ext ) |
|
504 | file, filename = checkForRealPath( self.path, self.year, self.doy, self.set, self.ext ) | |
505 | if file: |
|
505 | if file: | |
506 | if self.__verifyFile(file): |
|
506 | if self.__verifyFile(file): | |
507 | fileOk_flag = True |
|
507 | fileOk_flag = True | |
508 | break |
|
508 | break | |
509 |
|
509 | |||
510 | if fileOk_flag: |
|
510 | if fileOk_flag: | |
511 | break |
|
511 | break | |
512 |
|
512 | |||
513 | firstTime_flag = False |
|
513 | firstTime_flag = False | |
514 |
|
514 | |||
515 | print "\tSkipping the file \"%s\" due to this file doesn't exist" % filename |
|
515 | print "\tSkipping the file \"%s\" due to this file doesn't exist" % filename | |
516 | self.set += 1 |
|
516 | self.set += 1 | |
517 |
|
517 | |||
518 | if nFiles == (self.nFiles-1): #si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta |
|
518 | if nFiles == (self.nFiles-1): #si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta | |
519 | self.set = 0 |
|
519 | self.set = 0 | |
520 | self.doy += 1 |
|
520 | self.doy += 1 | |
521 |
|
521 | |||
522 | if fileOk_flag: |
|
522 | if fileOk_flag: | |
523 | self.fileSize = os.path.getsize( file ) |
|
523 | self.fileSize = os.path.getsize( file ) | |
524 | self.filename = file |
|
524 | self.filename = file | |
525 | self.flagIsNewFile = 1 |
|
525 | self.flagIsNewFile = 1 | |
526 | if self.fp != None: self.fp.close() |
|
526 | if self.fp != None: self.fp.close() | |
527 | self.fp = open(file) |
|
527 | self.fp = open(file) | |
528 | self.flagNoMoreFiles = 0 |
|
528 | self.flagNoMoreFiles = 0 | |
529 | print 'Setting the file: %s' % file |
|
529 | print 'Setting the file: %s' % file | |
530 | else: |
|
530 | else: | |
531 | self.fileSize = 0 |
|
531 | self.fileSize = 0 | |
532 | self.filename = None |
|
532 | self.filename = None | |
533 | self.flagIsNewFile = 0 |
|
533 | self.flagIsNewFile = 0 | |
534 | self.fp = None |
|
534 | self.fp = None | |
535 | self.flagNoMoreFiles = 1 |
|
535 | self.flagNoMoreFiles = 1 | |
536 | print 'No more Files' |
|
536 | print 'No more Files' | |
537 |
|
537 | |||
538 | return fileOk_flag |
|
538 | return fileOk_flag | |
539 |
|
539 | |||
540 |
|
540 | |||
541 | def setNextFile(self): |
|
541 | def setNextFile(self): | |
542 | if self.fp != None: |
|
542 | if self.fp != None: | |
543 | self.fp.close() |
|
543 | self.fp.close() | |
544 |
|
544 | |||
545 | if self.online: |
|
545 | if self.online: | |
546 | newFile = self.__setNextFileOnline() |
|
546 | newFile = self.__setNextFileOnline() | |
547 | else: |
|
547 | else: | |
548 | newFile = self.__setNextFileOffline() |
|
548 | newFile = self.__setNextFileOffline() | |
549 |
|
549 | |||
550 | if not(newFile): |
|
550 | if not(newFile): | |
551 | return 0 |
|
551 | return 0 | |
552 |
|
552 | |||
553 | self.__readFirstHeader() |
|
553 | self.__readFirstHeader() | |
554 | self.nReadBlocks = 0 |
|
554 | self.nReadBlocks = 0 | |
555 | return 1 |
|
555 | return 1 | |
556 |
|
556 | |||
557 | def __setNewBlock(self): |
|
557 | def __setNewBlock(self): | |
558 | if self.fp == None: |
|
558 | if self.fp == None: | |
559 | return 0 |
|
559 | return 0 | |
560 |
|
560 | |||
561 | if self.flagIsNewFile: |
|
561 | if self.flagIsNewFile: | |
562 | return 1 |
|
562 | return 1 | |
563 |
|
563 | |||
564 | self.lastUTTime = self.basicHeaderObj.utc |
|
564 | self.lastUTTime = self.basicHeaderObj.utc | |
565 | currentSize = self.fileSize - self.fp.tell() |
|
565 | currentSize = self.fileSize - self.fp.tell() | |
566 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
566 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize | |
567 |
|
567 | |||
568 | if (currentSize >= neededSize): |
|
568 | if (currentSize >= neededSize): | |
569 | self.__rdBasicHeader() |
|
569 | self.__rdBasicHeader() | |
570 | return 1 |
|
570 | return 1 | |
571 |
|
571 | |||
572 | if not(self.setNextFile()): |
|
572 | if not(self.setNextFile()): | |
573 | return 0 |
|
573 | return 0 | |
574 |
|
574 | |||
575 | deltaTime = self.basicHeaderObj.utc - self.lastUTTime # |
|
575 | deltaTime = self.basicHeaderObj.utc - self.lastUTTime # | |
576 |
|
576 | |||
577 | self.flagTimeBlock = 0 |
|
577 | self.flagTimeBlock = 0 | |
578 |
|
578 | |||
579 | if deltaTime > self.maxTimeStep: |
|
579 | if deltaTime > self.maxTimeStep: | |
580 | self.flagTimeBlock = 1 |
|
580 | self.flagTimeBlock = 1 | |
581 |
|
581 | |||
582 | return 1 |
|
582 | return 1 | |
583 |
|
583 | |||
584 |
|
584 | |||
585 | def readNextBlock(self): |
|
585 | def readNextBlock(self): | |
586 | if not(self.__setNewBlock()): |
|
586 | if not(self.__setNewBlock()): | |
587 | return 0 |
|
587 | return 0 | |
588 |
|
588 | |||
589 | if not(self.readBlock()): |
|
589 | if not(self.readBlock()): | |
590 | return 0 |
|
590 | return 0 | |
591 |
|
591 | |||
592 | return 1 |
|
592 | return 1 | |
593 |
|
593 | |||
594 | def __rdProcessingHeader(self, fp=None): |
|
594 | def __rdProcessingHeader(self, fp=None): | |
595 | if fp == None: |
|
595 | if fp == None: | |
596 | fp = self.fp |
|
596 | fp = self.fp | |
597 |
|
597 | |||
598 | self.processingHeaderObj.read(fp) |
|
598 | self.processingHeaderObj.read(fp) | |
599 |
|
599 | |||
600 | def __rdRadarControllerHeader(self, fp=None): |
|
600 | def __rdRadarControllerHeader(self, fp=None): | |
601 | if fp == None: |
|
601 | if fp == None: | |
602 | fp = self.fp |
|
602 | fp = self.fp | |
603 |
|
603 | |||
604 | self.radarControllerHeaderObj.read(fp) |
|
604 | self.radarControllerHeaderObj.read(fp) | |
605 |
|
605 | |||
606 | def __rdSystemHeader(self, fp=None): |
|
606 | def __rdSystemHeader(self, fp=None): | |
607 | if fp == None: |
|
607 | if fp == None: | |
608 | fp = self.fp |
|
608 | fp = self.fp | |
609 |
|
609 | |||
610 | self.systemHeaderObj.read(fp) |
|
610 | self.systemHeaderObj.read(fp) | |
611 |
|
611 | |||
612 | def __rdBasicHeader(self, fp=None): |
|
612 | def __rdBasicHeader(self, fp=None): | |
613 | if fp == None: |
|
613 | if fp == None: | |
614 | fp = self.fp |
|
614 | fp = self.fp | |
615 |
|
615 | |||
616 | self.basicHeaderObj.read(fp) |
|
616 | self.basicHeaderObj.read(fp) | |
617 |
|
617 | |||
618 |
|
618 | |||
619 | def __readFirstHeader(self): |
|
619 | def __readFirstHeader(self): | |
620 | self.__rdBasicHeader() |
|
620 | self.__rdBasicHeader() | |
621 | self.__rdSystemHeader() |
|
621 | self.__rdSystemHeader() | |
622 | self.__rdRadarControllerHeader() |
|
622 | self.__rdRadarControllerHeader() | |
623 | self.__rdProcessingHeader() |
|
623 | self.__rdProcessingHeader() | |
624 |
|
624 | |||
625 | self.firstHeaderSize = self.basicHeaderObj.size |
|
625 | self.firstHeaderSize = self.basicHeaderObj.size | |
626 |
|
626 | |||
627 | datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) |
|
627 | datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) | |
628 | if datatype == 0: |
|
628 | if datatype == 0: | |
629 | datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
629 | datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
630 | elif datatype == 1: |
|
630 | elif datatype == 1: | |
631 | datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
631 | datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
632 | elif datatype == 2: |
|
632 | elif datatype == 2: | |
633 | datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
633 | datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
634 | elif datatype == 3: |
|
634 | elif datatype == 3: | |
635 | datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
635 | datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
636 | elif datatype == 4: |
|
636 | elif datatype == 4: | |
637 | datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
637 | datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
638 | elif datatype == 5: |
|
638 | elif datatype == 5: | |
639 | datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
639 | datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
640 | else: |
|
640 | else: | |
641 | raise ValueError, 'Data type was not defined' |
|
641 | raise ValueError, 'Data type was not defined' | |
642 |
|
642 | |||
643 | self.dtype = datatype_str |
|
643 | self.dtype = datatype_str | |
644 | self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c |
|
644 | self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c | |
645 | self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1) |
|
645 | self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1) | |
646 | # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels) |
|
646 | # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels) | |
647 | # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels) |
|
647 | # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels) | |
648 | self.getBlockDimension() |
|
648 | self.getBlockDimension() | |
649 |
|
649 | |||
650 |
|
650 | |||
651 | def __verifyFile(self, filename, msgFlag=True): |
|
651 | def __verifyFile(self, filename, msgFlag=True): | |
652 | msg = None |
|
652 | msg = None | |
653 | try: |
|
653 | try: | |
654 | fp = open(filename, 'rb') |
|
654 | fp = open(filename, 'rb') | |
655 | currentPosition = fp.tell() |
|
655 | currentPosition = fp.tell() | |
656 | except: |
|
656 | except: | |
657 | if msgFlag: |
|
657 | if msgFlag: | |
658 | print "The file %s can't be opened" % (filename) |
|
658 | print "The file %s can't be opened" % (filename) | |
659 | return False |
|
659 | return False | |
660 |
|
660 | |||
661 | neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize |
|
661 | neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize | |
662 |
|
662 | |||
663 | if neededSize == 0: |
|
663 | if neededSize == 0: | |
664 | basicHeaderObj = BasicHeader() |
|
664 | basicHeaderObj = BasicHeader() | |
665 | systemHeaderObj = SystemHeader() |
|
665 | systemHeaderObj = SystemHeader() | |
666 | radarControllerHeaderObj = RadarControllerHeader() |
|
666 | radarControllerHeaderObj = RadarControllerHeader() | |
667 | processingHeaderObj = ProcessingHeader() |
|
667 | processingHeaderObj = ProcessingHeader() | |
668 |
|
668 | |||
669 | try: |
|
669 | try: | |
670 | if not( basicHeaderObj.read(fp) ): raise ValueError |
|
670 | if not( basicHeaderObj.read(fp) ): raise ValueError | |
671 | if not( systemHeaderObj.read(fp) ): raise ValueError |
|
671 | if not( systemHeaderObj.read(fp) ): raise ValueError | |
672 | if not( radarControllerHeaderObj.read(fp) ): raise ValueError |
|
672 | if not( radarControllerHeaderObj.read(fp) ): raise ValueError | |
673 | if not( processingHeaderObj.read(fp) ): raise ValueError |
|
673 | if not( processingHeaderObj.read(fp) ): raise ValueError | |
674 | data_type = int(numpy.log2((processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) |
|
674 | data_type = int(numpy.log2((processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) | |
675 |
|
675 | |||
676 | neededSize = processingHeaderObj.blockSize + basicHeaderObj.size |
|
676 | neededSize = processingHeaderObj.blockSize + basicHeaderObj.size | |
677 |
|
677 | |||
678 | except: |
|
678 | except: | |
679 | if msgFlag: |
|
679 | if msgFlag: | |
680 | print "\tThe file %s is empty or it hasn't enough data" % filename |
|
680 | print "\tThe file %s is empty or it hasn't enough data" % filename | |
681 |
|
681 | |||
682 | fp.close() |
|
682 | fp.close() | |
683 | return False |
|
683 | return False | |
684 | else: |
|
684 | else: | |
685 | msg = "\tSkipping the file %s due to it hasn't enough data" %filename |
|
685 | msg = "\tSkipping the file %s due to it hasn't enough data" %filename | |
686 |
|
686 | |||
687 | fp.close() |
|
687 | fp.close() | |
688 | fileSize = os.path.getsize(filename) |
|
688 | fileSize = os.path.getsize(filename) | |
689 | currentSize = fileSize - currentPosition |
|
689 | currentSize = fileSize - currentPosition | |
690 | if currentSize < neededSize: |
|
690 | if currentSize < neededSize: | |
691 | if msgFlag and (msg != None): |
|
691 | if msgFlag and (msg != None): | |
692 | print msg #print"\tSkipping the file %s due to it hasn't enough data" %filename |
|
692 | print msg #print"\tSkipping the file %s due to it hasn't enough data" %filename | |
693 | return False |
|
693 | return False | |
694 |
|
694 | |||
695 | return True |
|
695 | return True | |
696 |
|
696 | |||
697 | def setup(self, |
|
697 | def setup(self, | |
698 | path=None, |
|
698 | path=None, | |
699 | startDate=None, |
|
699 | startDate=None, | |
700 | endDate=None, |
|
700 | endDate=None, | |
701 | startTime=datetime.time(0,0,0), |
|
701 | startTime=datetime.time(0,0,0), | |
702 | endTime=datetime.time(23,59,59), |
|
702 | endTime=datetime.time(23,59,59), | |
703 | set=0, |
|
703 | set=0, | |
704 | expLabel = "", |
|
704 | expLabel = "", | |
705 | ext = None, |
|
705 | ext = None, | |
706 | online = False, |
|
706 | online = False, | |
707 | delay = 60): |
|
707 | delay = 60): | |
708 |
|
708 | |||
709 | if path == None: |
|
709 | if path == None: | |
710 | raise ValueError, "The path is not valid" |
|
710 | raise ValueError, "The path is not valid" | |
711 |
|
711 | |||
712 | if ext == None: |
|
712 | if ext == None: | |
713 | ext = self.ext |
|
713 | ext = self.ext | |
714 |
|
714 | |||
715 | if online: |
|
715 | if online: | |
716 | print "Searching files in online mode..." |
|
716 | print "Searching files in online mode..." | |
717 | doypath, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext) |
|
717 | doypath, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext) | |
718 |
|
718 | |||
719 | if not(doypath): |
|
719 | if not(doypath): | |
720 | for nTries in range( self.nTries ): |
|
720 | for nTries in range( self.nTries ): | |
721 | print '\tWaiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1) |
|
721 | print '\tWaiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1) | |
722 | time.sleep( self.delay ) |
|
722 | time.sleep( self.delay ) | |
723 | doypath, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext) |
|
723 | doypath, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext) | |
724 | if doypath: |
|
724 | if doypath: | |
725 | break |
|
725 | break | |
726 |
|
726 | |||
727 | if not(doypath): |
|
727 | if not(doypath): | |
728 | print "There 'isn't valied files in %s" % path |
|
728 | print "There 'isn't valied files in %s" % path | |
729 | return None |
|
729 | return None | |
730 |
|
730 | |||
731 | self.year = year |
|
731 | self.year = year | |
732 | self.doy = doy |
|
732 | self.doy = doy | |
733 | self.set = set - 1 |
|
733 | self.set = set - 1 | |
734 | self.path = path |
|
734 | self.path = path | |
735 |
|
735 | |||
736 | else: |
|
736 | else: | |
737 | print "Searching files in offline mode ..." |
|
737 | print "Searching files in offline mode ..." | |
738 | pathList, filenameList = self.__searchFilesOffLine(path, startDate, endDate, startTime, endTime, set, expLabel, ext) |
|
738 | pathList, filenameList = self.__searchFilesOffLine(path, startDate, endDate, startTime, endTime, set, expLabel, ext) | |
739 |
|
739 | |||
740 | if not(pathList): |
|
740 | if not(pathList): | |
741 | print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path, |
|
741 | print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path, | |
742 | datetime.datetime.combine(startDate,startTime).ctime(), |
|
742 | datetime.datetime.combine(startDate,startTime).ctime(), | |
743 | datetime.datetime.combine(endDate,endTime).ctime()) |
|
743 | datetime.datetime.combine(endDate,endTime).ctime()) | |
744 |
|
744 | |||
745 | sys.exit(-1) |
|
745 | sys.exit(-1) | |
746 |
|
746 | |||
747 |
|
747 | |||
748 | self.fileIndex = -1 |
|
748 | self.fileIndex = -1 | |
749 | self.pathList = pathList |
|
749 | self.pathList = pathList | |
750 | self.filenameList = filenameList |
|
750 | self.filenameList = filenameList | |
751 |
|
751 | |||
752 | self.online = online |
|
752 | self.online = online | |
753 | self.delay = delay |
|
753 | self.delay = delay | |
754 | ext = ext.lower() |
|
754 | ext = ext.lower() | |
755 | self.ext = ext |
|
755 | self.ext = ext | |
756 |
|
756 | |||
757 | if not(self.setNextFile()): |
|
757 | if not(self.setNextFile()): | |
758 | if (startDate!=None) and (endDate!=None): |
|
758 | if (startDate!=None) and (endDate!=None): | |
759 | print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime()) |
|
759 | print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime()) | |
760 | elif startDate != None: |
|
760 | elif startDate != None: | |
761 | print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime()) |
|
761 | print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime()) | |
762 | else: |
|
762 | else: | |
763 | print "No files" |
|
763 | print "No files" | |
764 |
|
764 | |||
765 | sys.exit(-1) |
|
765 | sys.exit(-1) | |
766 |
|
766 | |||
767 | # self.updateDataHeader() |
|
767 | # self.updateDataHeader() | |
768 |
|
768 | |||
769 | return self.dataOut |
|
769 | return self.dataOut | |
770 |
|
770 | |||
771 | def getData(): |
|
771 | def getData(): | |
772 |
|
772 | |||
773 | raise ValueError, "This method has not been implemented" |
|
773 | raise ValueError, "This method has not been implemented" | |
774 |
|
774 | |||
775 | def hasNotDataInBuffer(): |
|
775 | def hasNotDataInBuffer(): | |
776 |
|
776 | |||
777 | raise ValueError, "This method has not been implemented" |
|
777 | raise ValueError, "This method has not been implemented" | |
778 |
|
778 | |||
779 | def readBlock(): |
|
779 | def readBlock(): | |
780 |
|
780 | |||
781 | raise ValueError, "This method has not been implemented" |
|
781 | raise ValueError, "This method has not been implemented" | |
782 |
|
782 | |||
783 | def isEndProcess(self): |
|
783 | def isEndProcess(self): | |
784 |
|
784 | |||
785 | return self.flagNoMoreFiles |
|
785 | return self.flagNoMoreFiles | |
786 |
|
786 | |||
787 | def printReadBlocks(self): |
|
787 | def printReadBlocks(self): | |
788 |
|
788 | |||
789 | print "Number of read blocks per file %04d" %self.nReadBlocks |
|
789 | print "Number of read blocks per file %04d" %self.nReadBlocks | |
790 |
|
790 | |||
791 | def printTotalBlocks(self): |
|
791 | def printTotalBlocks(self): | |
792 |
|
792 | |||
793 | print "Number of read blocks %04d" %self.nTotalBlocks |
|
793 | print "Number of read blocks %04d" %self.nTotalBlocks | |
794 |
|
794 | |||
795 | def run(self, **kwargs): |
|
795 | def run(self, **kwargs): | |
796 |
|
796 | |||
797 | if not(self.isConfig): |
|
797 | if not(self.isConfig): | |
798 |
|
798 | |||
799 | # self.dataOut = dataOut |
|
799 | # self.dataOut = dataOut | |
800 | self.setup(**kwargs) |
|
800 | self.setup(**kwargs) | |
801 | self.isConfig = True |
|
801 | self.isConfig = True | |
802 |
|
802 | |||
803 | self.getData() |
|
803 | self.getData() | |
804 |
|
804 | |||
805 | class JRODataWriter(JRODataIO, Operation): |
|
805 | class JRODataWriter(JRODataIO, Operation): | |
806 |
|
806 | |||
807 | """ |
|
807 | """ | |
808 | Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura |
|
808 | Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura | |
809 | de los datos siempre se realiza por bloques. |
|
809 | de los datos siempre se realiza por bloques. | |
810 | """ |
|
810 | """ | |
811 |
|
811 | |||
812 | blockIndex = 0 |
|
812 | blockIndex = 0 | |
813 |
|
813 | |||
814 | path = None |
|
814 | path = None | |
815 |
|
815 | |||
816 | setFile = None |
|
816 | setFile = None | |
817 |
|
817 | |||
818 | profilesPerBlock = None |
|
818 | profilesPerBlock = None | |
819 |
|
819 | |||
820 | blocksPerFile = None |
|
820 | blocksPerFile = None | |
821 |
|
821 | |||
822 | nWriteBlocks = 0 |
|
822 | nWriteBlocks = 0 | |
823 |
|
823 | |||
824 | def __init__(self, dataOut=None): |
|
824 | def __init__(self, dataOut=None): | |
825 | raise ValueError, "Not implemented" |
|
825 | raise ValueError, "Not implemented" | |
826 |
|
826 | |||
827 |
|
827 | |||
828 | def hasAllDataInBuffer(self): |
|
828 | def hasAllDataInBuffer(self): | |
829 | raise ValueError, "Not implemented" |
|
829 | raise ValueError, "Not implemented" | |
830 |
|
830 | |||
831 |
|
831 | |||
832 | def setBlockDimension(self): |
|
832 | def setBlockDimension(self): | |
833 | raise ValueError, "Not implemented" |
|
833 | raise ValueError, "Not implemented" | |
834 |
|
834 | |||
835 |
|
835 | |||
836 | def writeBlock(self): |
|
836 | def writeBlock(self): | |
837 | raise ValueError, "No implemented" |
|
837 | raise ValueError, "No implemented" | |
838 |
|
838 | |||
839 |
|
839 | |||
840 | def putData(self): |
|
840 | def putData(self): | |
841 | raise ValueError, "No implemented" |
|
841 | raise ValueError, "No implemented" | |
842 |
|
842 | |||
843 | def getDataHeader(self): |
|
843 | def getDataHeader(self): | |
844 | """ |
|
844 | """ | |
845 | Obtiene una copia del First Header |
|
845 | Obtiene una copia del First Header | |
846 |
|
846 | |||
847 | Affected: |
|
847 | Affected: | |
848 |
|
848 | |||
849 | self.basicHeaderObj |
|
849 | self.basicHeaderObj | |
850 | self.systemHeaderObj |
|
850 | self.systemHeaderObj | |
851 | self.radarControllerHeaderObj |
|
851 | self.radarControllerHeaderObj | |
852 | self.processingHeaderObj self. |
|
852 | self.processingHeaderObj self. | |
853 |
|
853 | |||
854 | Return: |
|
854 | Return: | |
855 | None |
|
855 | None | |
856 | """ |
|
856 | """ | |
857 |
|
857 | |||
858 | raise ValueError, "No implemented" |
|
858 | raise ValueError, "No implemented" | |
859 |
|
859 | |||
860 | def getBasicHeader(self): |
|
860 | def getBasicHeader(self): | |
861 |
|
861 | |||
862 | self.basicHeaderObj.size = self.basicHeaderSize #bytes |
|
862 | self.basicHeaderObj.size = self.basicHeaderSize #bytes | |
863 | self.basicHeaderObj.version = self.versionFile |
|
863 | self.basicHeaderObj.version = self.versionFile | |
864 | self.basicHeaderObj.dataBlock = self.nTotalBlocks |
|
864 | self.basicHeaderObj.dataBlock = self.nTotalBlocks | |
865 |
|
865 | |||
866 | utc = numpy.floor(self.dataOut.utctime) |
|
866 | utc = numpy.floor(self.dataOut.utctime) | |
867 | milisecond = (self.dataOut.utctime - utc)* 1000.0 |
|
867 | milisecond = (self.dataOut.utctime - utc)* 1000.0 | |
868 |
|
868 | |||
869 | self.basicHeaderObj.utc = utc |
|
869 | self.basicHeaderObj.utc = utc | |
870 | self.basicHeaderObj.miliSecond = milisecond |
|
870 | self.basicHeaderObj.miliSecond = milisecond | |
871 | self.basicHeaderObj.timeZone = 0 |
|
871 | self.basicHeaderObj.timeZone = 0 | |
872 | self.basicHeaderObj.dstFlag = 0 |
|
872 | self.basicHeaderObj.dstFlag = 0 | |
873 | self.basicHeaderObj.errorCount = 0 |
|
873 | self.basicHeaderObj.errorCount = 0 | |
874 |
|
874 | |||
875 | def __writeFirstHeader(self): |
|
875 | def __writeFirstHeader(self): | |
876 | """ |
|
876 | """ | |
877 | Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader) |
|
877 | Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader) | |
878 |
|
878 | |||
879 | Affected: |
|
879 | Affected: | |
880 | __dataType |
|
880 | __dataType | |
881 |
|
881 | |||
882 | Return: |
|
882 | Return: | |
883 | None |
|
883 | None | |
884 | """ |
|
884 | """ | |
885 |
|
885 | |||
886 | # CALCULAR PARAMETROS |
|
886 | # CALCULAR PARAMETROS | |
887 |
|
887 | |||
888 | sizeLongHeader = self.systemHeaderObj.size + self.radarControllerHeaderObj.size + self.processingHeaderObj.size |
|
888 | sizeLongHeader = self.systemHeaderObj.size + self.radarControllerHeaderObj.size + self.processingHeaderObj.size | |
889 | self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader |
|
889 | self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader | |
890 |
|
890 | |||
891 | self.basicHeaderObj.write(self.fp) |
|
891 | self.basicHeaderObj.write(self.fp) | |
892 | self.systemHeaderObj.write(self.fp) |
|
892 | self.systemHeaderObj.write(self.fp) | |
893 | self.radarControllerHeaderObj.write(self.fp) |
|
893 | self.radarControllerHeaderObj.write(self.fp) | |
894 | self.processingHeaderObj.write(self.fp) |
|
894 | self.processingHeaderObj.write(self.fp) | |
895 |
|
895 | |||
896 | self.dtype = self.dataOut.dtype |
|
896 | self.dtype = self.dataOut.dtype | |
897 |
|
897 | |||
898 | def __setNewBlock(self): |
|
898 | def __setNewBlock(self): | |
899 | """ |
|
899 | """ | |
900 | Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header |
|
900 | Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header | |
901 |
|
901 | |||
902 | Return: |
|
902 | Return: | |
903 | 0 : si no pudo escribir nada |
|
903 | 0 : si no pudo escribir nada | |
904 | 1 : Si escribio el Basic el First Header |
|
904 | 1 : Si escribio el Basic el First Header | |
905 | """ |
|
905 | """ | |
906 | if self.fp == None: |
|
906 | if self.fp == None: | |
907 | self.setNextFile() |
|
907 | self.setNextFile() | |
908 |
|
908 | |||
909 | if self.flagIsNewFile: |
|
909 | if self.flagIsNewFile: | |
910 | return 1 |
|
910 | return 1 | |
911 |
|
911 | |||
912 | if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile: |
|
912 | if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile: | |
913 | self.basicHeaderObj.write(self.fp) |
|
913 | self.basicHeaderObj.write(self.fp) | |
914 | return 1 |
|
914 | return 1 | |
915 |
|
915 | |||
916 | if not( self.setNextFile() ): |
|
916 | if not( self.setNextFile() ): | |
917 | return 0 |
|
917 | return 0 | |
918 |
|
918 | |||
919 | return 1 |
|
919 | return 1 | |
920 |
|
920 | |||
921 |
|
921 | |||
922 | def writeNextBlock(self): |
|
922 | def writeNextBlock(self): | |
923 | """ |
|
923 | """ | |
924 | Selecciona el bloque siguiente de datos y los escribe en un file |
|
924 | Selecciona el bloque siguiente de datos y los escribe en un file | |
925 |
|
925 | |||
926 | Return: |
|
926 | Return: | |
927 | 0 : Si no hizo pudo escribir el bloque de datos |
|
927 | 0 : Si no hizo pudo escribir el bloque de datos | |
928 | 1 : Si no pudo escribir el bloque de datos |
|
928 | 1 : Si no pudo escribir el bloque de datos | |
929 | """ |
|
929 | """ | |
930 | if not( self.__setNewBlock() ): |
|
930 | if not( self.__setNewBlock() ): | |
931 | return 0 |
|
931 | return 0 | |
932 |
|
932 | |||
933 | self.writeBlock() |
|
933 | self.writeBlock() | |
934 |
|
934 | |||
935 | return 1 |
|
935 | return 1 | |
936 |
|
936 | |||
937 | def setNextFile(self): |
|
937 | def setNextFile(self): | |
938 | """ |
|
938 | """ | |
939 | Determina el siguiente file que sera escrito |
|
939 | Determina el siguiente file que sera escrito | |
940 |
|
940 | |||
941 | Affected: |
|
941 | Affected: | |
942 | self.filename |
|
942 | self.filename | |
943 | self.subfolder |
|
943 | self.subfolder | |
944 | self.fp |
|
944 | self.fp | |
945 | self.setFile |
|
945 | self.setFile | |
946 | self.flagIsNewFile |
|
946 | self.flagIsNewFile | |
947 |
|
947 | |||
948 | Return: |
|
948 | Return: | |
949 | 0 : Si el archivo no puede ser escrito |
|
949 | 0 : Si el archivo no puede ser escrito | |
950 | 1 : Si el archivo esta listo para ser escrito |
|
950 | 1 : Si el archivo esta listo para ser escrito | |
951 | """ |
|
951 | """ | |
952 | ext = self.ext |
|
952 | ext = self.ext | |
953 | path = self.path |
|
953 | path = self.path | |
954 |
|
954 | |||
955 | if self.fp != None: |
|
955 | if self.fp != None: | |
956 | self.fp.close() |
|
956 | self.fp.close() | |
957 |
|
957 | |||
958 | timeTuple = time.localtime( self.dataOut.dataUtcTime) |
|
958 | timeTuple = time.localtime( self.dataOut.dataUtcTime) | |
959 | subfolder = 'D%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) |
|
959 | subfolder = 'D%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) | |
960 |
|
960 | |||
961 | doypath = os.path.join( path, subfolder ) |
|
961 | doypath = os.path.join( path, subfolder ) | |
962 | if not( os.path.exists(doypath) ): |
|
962 | if not( os.path.exists(doypath) ): | |
963 | os.mkdir(doypath) |
|
963 | os.mkdir(doypath) | |
964 | self.setFile = -1 #inicializo mi contador de seteo |
|
964 | self.setFile = -1 #inicializo mi contador de seteo | |
965 | else: |
|
965 | else: | |
966 | filesList = os.listdir( doypath ) |
|
966 | filesList = os.listdir( doypath ) | |
967 | if len( filesList ) > 0: |
|
967 | if len( filesList ) > 0: | |
968 | filesList = sorted( filesList, key=str.lower ) |
|
968 | filesList = sorted( filesList, key=str.lower ) | |
969 | filen = filesList[-1] |
|
969 | filen = filesList[-1] | |
970 | # el filename debera tener el siguiente formato |
|
970 | # el filename debera tener el siguiente formato | |
971 | # 0 1234 567 89A BCDE (hex) |
|
971 | # 0 1234 567 89A BCDE (hex) | |
972 | # x YYYY DDD SSS .ext |
|
972 | # x YYYY DDD SSS .ext | |
973 | if isNumber( filen[8:11] ): |
|
973 | if isNumber( filen[8:11] ): | |
974 | self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file |
|
974 | self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file | |
975 | else: |
|
975 | else: | |
976 | self.setFile = -1 |
|
976 | self.setFile = -1 | |
977 | else: |
|
977 | else: | |
978 | self.setFile = -1 #inicializo mi contador de seteo |
|
978 | self.setFile = -1 #inicializo mi contador de seteo | |
979 |
|
979 | |||
980 | setFile = self.setFile |
|
980 | setFile = self.setFile | |
981 | setFile += 1 |
|
981 | setFile += 1 | |
982 |
|
982 | |||
983 | file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar, |
|
983 | file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar, | |
984 | timeTuple.tm_year, |
|
984 | timeTuple.tm_year, | |
985 | timeTuple.tm_yday, |
|
985 | timeTuple.tm_yday, | |
986 | setFile, |
|
986 | setFile, | |
987 | ext ) |
|
987 | ext ) | |
988 |
|
988 | |||
989 | filename = os.path.join( path, subfolder, file ) |
|
989 | filename = os.path.join( path, subfolder, file ) | |
990 |
|
990 | |||
991 | fp = open( filename,'wb' ) |
|
991 | fp = open( filename,'wb' ) | |
992 |
|
992 | |||
993 | self.blockIndex = 0 |
|
993 | self.blockIndex = 0 | |
994 |
|
994 | |||
995 | #guardando atributos |
|
995 | #guardando atributos | |
996 | self.filename = filename |
|
996 | self.filename = filename | |
997 | self.subfolder = subfolder |
|
997 | self.subfolder = subfolder | |
998 | self.fp = fp |
|
998 | self.fp = fp | |
999 | self.setFile = setFile |
|
999 | self.setFile = setFile | |
1000 | self.flagIsNewFile = 1 |
|
1000 | self.flagIsNewFile = 1 | |
1001 |
|
1001 | |||
1002 | self.getDataHeader() |
|
1002 | self.getDataHeader() | |
1003 |
|
1003 | |||
1004 | print 'Writing the file: %s'%self.filename |
|
1004 | print 'Writing the file: %s'%self.filename | |
1005 |
|
1005 | |||
1006 | self.__writeFirstHeader() |
|
1006 | self.__writeFirstHeader() | |
1007 |
|
1007 | |||
1008 | return 1 |
|
1008 | return 1 | |
1009 |
|
1009 | |||
1010 | def setup(self, dataOut, path, blocksPerFile, profilesPerBlock=None, set=0, ext=None): |
|
1010 | def setup(self, dataOut, path, blocksPerFile, profilesPerBlock=None, set=0, ext=None): | |
1011 | """ |
|
1011 | """ | |
1012 | Setea el tipo de formato en la cual sera guardada la data y escribe el First Header |
|
1012 | Setea el tipo de formato en la cual sera guardada la data y escribe el First Header | |
1013 |
|
1013 | |||
1014 | Inputs: |
|
1014 | Inputs: | |
1015 | path : el path destino en el cual se escribiran los files a crear |
|
1015 | path : el path destino en el cual se escribiran los files a crear | |
1016 | format : formato en el cual sera salvado un file |
|
1016 | format : formato en el cual sera salvado un file | |
1017 | set : el setebo del file |
|
1017 | set : el setebo del file | |
1018 |
|
1018 | |||
1019 | Return: |
|
1019 | Return: | |
1020 | 0 : Si no realizo un buen seteo |
|
1020 | 0 : Si no realizo un buen seteo | |
1021 | 1 : Si realizo un buen seteo |
|
1021 | 1 : Si realizo un buen seteo | |
1022 | """ |
|
1022 | """ | |
1023 |
|
1023 | |||
1024 | if ext == None: |
|
1024 | if ext == None: | |
1025 | ext = self.ext |
|
1025 | ext = self.ext | |
1026 |
|
1026 | |||
1027 | ext = ext.lower() |
|
1027 | ext = ext.lower() | |
1028 |
|
1028 | |||
1029 | self.ext = ext |
|
1029 | self.ext = ext | |
1030 |
|
1030 | |||
1031 | self.path = path |
|
1031 | self.path = path | |
1032 |
|
1032 | |||
1033 | self.setFile = set - 1 |
|
1033 | self.setFile = set - 1 | |
1034 |
|
1034 | |||
1035 | self.blocksPerFile = blocksPerFile |
|
1035 | self.blocksPerFile = blocksPerFile | |
1036 |
|
1036 | |||
1037 | self.profilesPerBlock = profilesPerBlock |
|
1037 | self.profilesPerBlock = profilesPerBlock | |
1038 |
|
1038 | |||
1039 | self.dataOut = dataOut |
|
1039 | self.dataOut = dataOut | |
1040 |
|
1040 | |||
1041 | if not(self.setNextFile()): |
|
1041 | if not(self.setNextFile()): | |
1042 | print "There isn't a next file" |
|
1042 | print "There isn't a next file" | |
1043 | return 0 |
|
1043 | return 0 | |
1044 |
|
1044 | |||
1045 | self.setBlockDimension() |
|
1045 | self.setBlockDimension() | |
1046 |
|
1046 | |||
1047 | return 1 |
|
1047 | return 1 | |
1048 |
|
1048 | |||
1049 | def run(self, dataOut, **kwargs): |
|
1049 | def run(self, dataOut, **kwargs): | |
1050 |
|
1050 | |||
1051 | if not(self.isConfig): |
|
1051 | if not(self.isConfig): | |
1052 |
|
1052 | |||
1053 | self.setup(dataOut, **kwargs) |
|
1053 | self.setup(dataOut, **kwargs) | |
1054 | self.isConfig = True |
|
1054 | self.isConfig = True | |
1055 |
|
1055 | |||
1056 | self.putData() |
|
1056 | self.putData() | |
1057 |
|
1057 | |||
1058 | class VoltageReader(JRODataReader): |
|
1058 | class VoltageReader(JRODataReader): | |
1059 | """ |
|
1059 | """ | |
1060 | Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura |
|
1060 | Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura | |
1061 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones: |
|
1061 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones: | |
1062 | perfiles*alturas*canales) son almacenados en la variable "buffer". |
|
1062 | perfiles*alturas*canales) son almacenados en la variable "buffer". | |
1063 |
|
1063 | |||
1064 | perfiles * alturas * canales |
|
1064 | perfiles * alturas * canales | |
1065 |
|
1065 | |||
1066 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, |
|
1066 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, | |
1067 | RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la |
|
1067 | RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la | |
1068 | cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de |
|
1068 | cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de | |
1069 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". |
|
1069 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". | |
1070 |
|
1070 | |||
1071 | Example: |
|
1071 | Example: | |
1072 |
|
1072 | |||
1073 | dpath = "/home/myuser/data" |
|
1073 | dpath = "/home/myuser/data" | |
1074 |
|
1074 | |||
1075 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) |
|
1075 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) | |
1076 |
|
1076 | |||
1077 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) |
|
1077 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) | |
1078 |
|
1078 | |||
1079 | readerObj = VoltageReader() |
|
1079 | readerObj = VoltageReader() | |
1080 |
|
1080 | |||
1081 | readerObj.setup(dpath, startTime, endTime) |
|
1081 | readerObj.setup(dpath, startTime, endTime) | |
1082 |
|
1082 | |||
1083 | while(True): |
|
1083 | while(True): | |
1084 |
|
1084 | |||
1085 | #to get one profile |
|
1085 | #to get one profile | |
1086 | profile = readerObj.getData() |
|
1086 | profile = readerObj.getData() | |
1087 |
|
1087 | |||
1088 | #print the profile |
|
1088 | #print the profile | |
1089 | print profile |
|
1089 | print profile | |
1090 |
|
1090 | |||
1091 | #If you want to see all datablock |
|
1091 | #If you want to see all datablock | |
1092 | print readerObj.datablock |
|
1092 | print readerObj.datablock | |
1093 |
|
1093 | |||
1094 | if readerObj.flagNoMoreFiles: |
|
1094 | if readerObj.flagNoMoreFiles: | |
1095 | break |
|
1095 | break | |
1096 |
|
1096 | |||
1097 | """ |
|
1097 | """ | |
1098 |
|
1098 | |||
1099 | ext = ".r" |
|
1099 | ext = ".r" | |
1100 |
|
1100 | |||
1101 | optchar = "D" |
|
1101 | optchar = "D" | |
1102 | dataOut = None |
|
1102 | dataOut = None | |
1103 |
|
1103 | |||
1104 |
|
1104 | |||
1105 | def __init__(self): |
|
1105 | def __init__(self): | |
1106 | """ |
|
1106 | """ | |
1107 | Inicializador de la clase VoltageReader para la lectura de datos de voltage. |
|
1107 | Inicializador de la clase VoltageReader para la lectura de datos de voltage. | |
1108 |
|
1108 | |||
1109 | Input: |
|
1109 | Input: | |
1110 | dataOut : Objeto de la clase Voltage. Este objeto sera utilizado para |
|
1110 | dataOut : Objeto de la clase Voltage. Este objeto sera utilizado para | |
1111 | almacenar un perfil de datos cada vez que se haga un requerimiento |
|
1111 | almacenar un perfil de datos cada vez que se haga un requerimiento | |
1112 | (getData). El perfil sera obtenido a partir del buffer de datos, |
|
1112 | (getData). El perfil sera obtenido a partir del buffer de datos, | |
1113 | si el buffer esta vacio se hara un nuevo proceso de lectura de un |
|
1113 | si el buffer esta vacio se hara un nuevo proceso de lectura de un | |
1114 | bloque de datos. |
|
1114 | bloque de datos. | |
1115 | Si este parametro no es pasado se creara uno internamente. |
|
1115 | Si este parametro no es pasado se creara uno internamente. | |
1116 |
|
1116 | |||
1117 | Variables afectadas: |
|
1117 | Variables afectadas: | |
1118 | self.dataOut |
|
1118 | self.dataOut | |
1119 |
|
1119 | |||
1120 | Return: |
|
1120 | Return: | |
1121 | None |
|
1121 | None | |
1122 | """ |
|
1122 | """ | |
1123 |
|
1123 | |||
1124 | self.isConfig = False |
|
1124 | self.isConfig = False | |
1125 |
|
1125 | |||
1126 | self.datablock = None |
|
1126 | self.datablock = None | |
1127 |
|
1127 | |||
1128 | self.utc = 0 |
|
1128 | self.utc = 0 | |
1129 |
|
1129 | |||
1130 | self.ext = ".r" |
|
1130 | self.ext = ".r" | |
1131 |
|
1131 | |||
1132 | self.optchar = "D" |
|
1132 | self.optchar = "D" | |
1133 |
|
1133 | |||
1134 | self.basicHeaderObj = BasicHeader() |
|
1134 | self.basicHeaderObj = BasicHeader() | |
1135 |
|
1135 | |||
1136 | self.systemHeaderObj = SystemHeader() |
|
1136 | self.systemHeaderObj = SystemHeader() | |
1137 |
|
1137 | |||
1138 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
1138 | self.radarControllerHeaderObj = RadarControllerHeader() | |
1139 |
|
1139 | |||
1140 | self.processingHeaderObj = ProcessingHeader() |
|
1140 | self.processingHeaderObj = ProcessingHeader() | |
1141 |
|
1141 | |||
1142 | self.online = 0 |
|
1142 | self.online = 0 | |
1143 |
|
1143 | |||
1144 | self.fp = None |
|
1144 | self.fp = None | |
1145 |
|
1145 | |||
1146 | self.idFile = None |
|
1146 | self.idFile = None | |
1147 |
|
1147 | |||
1148 | self.dtype = None |
|
1148 | self.dtype = None | |
1149 |
|
1149 | |||
1150 | self.fileSizeByHeader = None |
|
1150 | self.fileSizeByHeader = None | |
1151 |
|
1151 | |||
1152 | self.filenameList = [] |
|
1152 | self.filenameList = [] | |
1153 |
|
1153 | |||
1154 | self.filename = None |
|
1154 | self.filename = None | |
1155 |
|
1155 | |||
1156 | self.fileSize = None |
|
1156 | self.fileSize = None | |
1157 |
|
1157 | |||
1158 | self.firstHeaderSize = 0 |
|
1158 | self.firstHeaderSize = 0 | |
1159 |
|
1159 | |||
1160 | self.basicHeaderSize = 24 |
|
1160 | self.basicHeaderSize = 24 | |
1161 |
|
1161 | |||
1162 | self.pathList = [] |
|
1162 | self.pathList = [] | |
1163 |
|
1163 | |||
1164 | self.filenameList = [] |
|
1164 | self.filenameList = [] | |
1165 |
|
1165 | |||
1166 | self.lastUTTime = 0 |
|
1166 | self.lastUTTime = 0 | |
1167 |
|
1167 | |||
1168 | self.maxTimeStep = 30 |
|
1168 | self.maxTimeStep = 30 | |
1169 |
|
1169 | |||
1170 | self.flagNoMoreFiles = 0 |
|
1170 | self.flagNoMoreFiles = 0 | |
1171 |
|
1171 | |||
1172 | self.set = 0 |
|
1172 | self.set = 0 | |
1173 |
|
1173 | |||
1174 | self.path = None |
|
1174 | self.path = None | |
1175 |
|
1175 | |||
1176 | self.profileIndex = 9999 |
|
1176 | self.profileIndex = 9999 | |
1177 |
|
1177 | |||
1178 | self.delay = 3 #seconds |
|
1178 | self.delay = 3 #seconds | |
1179 |
|
1179 | |||
1180 | self.nTries = 3 #quantity tries |
|
1180 | self.nTries = 3 #quantity tries | |
1181 |
|
1181 | |||
1182 | self.nFiles = 3 #number of files for searching |
|
1182 | self.nFiles = 3 #number of files for searching | |
1183 |
|
1183 | |||
1184 | self.nReadBlocks = 0 |
|
1184 | self.nReadBlocks = 0 | |
1185 |
|
1185 | |||
1186 | self.flagIsNewFile = 1 |
|
1186 | self.flagIsNewFile = 1 | |
1187 |
|
1187 | |||
1188 | self.ippSeconds = 0 |
|
1188 | self.ippSeconds = 0 | |
1189 |
|
1189 | |||
1190 | self.flagTimeBlock = 0 |
|
1190 | self.flagTimeBlock = 0 | |
1191 |
|
1191 | |||
1192 | self.flagIsNewBlock = 0 |
|
1192 | self.flagIsNewBlock = 0 | |
1193 |
|
1193 | |||
1194 | self.nTotalBlocks = 0 |
|
1194 | self.nTotalBlocks = 0 | |
1195 |
|
1195 | |||
1196 | self.blocksize = 0 |
|
1196 | self.blocksize = 0 | |
1197 |
|
1197 | |||
1198 | self.dataOut = self.createObjByDefault() |
|
1198 | self.dataOut = self.createObjByDefault() | |
1199 |
|
1199 | |||
1200 | def createObjByDefault(self): |
|
1200 | def createObjByDefault(self): | |
1201 |
|
1201 | |||
1202 | dataObj = Voltage() |
|
1202 | dataObj = Voltage() | |
1203 |
|
1203 | |||
1204 | return dataObj |
|
1204 | return dataObj | |
1205 |
|
1205 | |||
1206 | def __hasNotDataInBuffer(self): |
|
1206 | def __hasNotDataInBuffer(self): | |
1207 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: |
|
1207 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: | |
1208 | return 1 |
|
1208 | return 1 | |
1209 | return 0 |
|
1209 | return 0 | |
1210 |
|
1210 | |||
1211 |
|
1211 | |||
1212 | def getBlockDimension(self): |
|
1212 | def getBlockDimension(self): | |
1213 | """ |
|
1213 | """ | |
1214 | Obtiene la cantidad de puntos a leer por cada bloque de datos |
|
1214 | Obtiene la cantidad de puntos a leer por cada bloque de datos | |
1215 |
|
1215 | |||
1216 | Affected: |
|
1216 | Affected: | |
1217 | self.blocksize |
|
1217 | self.blocksize | |
1218 |
|
1218 | |||
1219 | Return: |
|
1219 | Return: | |
1220 | None |
|
1220 | None | |
1221 | """ |
|
1221 | """ | |
1222 | pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels |
|
1222 | pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels | |
1223 | self.blocksize = pts2read |
|
1223 | self.blocksize = pts2read | |
1224 |
|
1224 | |||
1225 |
|
1225 | |||
1226 | def readBlock(self): |
|
1226 | def readBlock(self): | |
1227 | """ |
|
1227 | """ | |
1228 | readBlock lee el bloque de datos desde la posicion actual del puntero del archivo |
|
1228 | readBlock lee el bloque de datos desde la posicion actual del puntero del archivo | |
1229 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos |
|
1229 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos | |
1230 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer |
|
1230 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer | |
1231 | es seteado a 0 |
|
1231 | es seteado a 0 | |
1232 |
|
1232 | |||
1233 | Inputs: |
|
1233 | Inputs: | |
1234 | None |
|
1234 | None | |
1235 |
|
1235 | |||
1236 | Return: |
|
1236 | Return: | |
1237 | None |
|
1237 | None | |
1238 |
|
1238 | |||
1239 | Affected: |
|
1239 | Affected: | |
1240 | self.profileIndex |
|
1240 | self.profileIndex | |
1241 | self.datablock |
|
1241 | self.datablock | |
1242 | self.flagIsNewFile |
|
1242 | self.flagIsNewFile | |
1243 | self.flagIsNewBlock |
|
1243 | self.flagIsNewBlock | |
1244 | self.nTotalBlocks |
|
1244 | self.nTotalBlocks | |
1245 |
|
1245 | |||
1246 | Exceptions: |
|
1246 | Exceptions: | |
1247 | Si un bloque leido no es un bloque valido |
|
1247 | Si un bloque leido no es un bloque valido | |
1248 | """ |
|
1248 | """ | |
1249 |
|
1249 | |||
1250 | junk = numpy.fromfile( self.fp, self.dtype, self.blocksize ) |
|
1250 | junk = numpy.fromfile( self.fp, self.dtype, self.blocksize ) | |
1251 |
|
1251 | |||
1252 | try: |
|
1252 | try: | |
1253 | junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) |
|
1253 | junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) | |
1254 | except: |
|
1254 | except: | |
1255 | print "The read block (%3d) has not enough data" %self.nReadBlocks |
|
1255 | print "The read block (%3d) has not enough data" %self.nReadBlocks | |
1256 | return 0 |
|
1256 | return 0 | |
1257 |
|
1257 | |||
1258 | junk = numpy.transpose(junk, (2,0,1)) |
|
1258 | junk = numpy.transpose(junk, (2,0,1)) | |
1259 | self.datablock = junk['real'] + junk['imag']*1j |
|
1259 | self.datablock = junk['real'] + junk['imag']*1j | |
1260 |
|
1260 | |||
1261 | self.profileIndex = 0 |
|
1261 | self.profileIndex = 0 | |
1262 |
|
1262 | |||
1263 | self.flagIsNewFile = 0 |
|
1263 | self.flagIsNewFile = 0 | |
1264 | self.flagIsNewBlock = 1 |
|
1264 | self.flagIsNewBlock = 1 | |
1265 |
|
1265 | |||
1266 | self.nTotalBlocks += 1 |
|
1266 | self.nTotalBlocks += 1 | |
1267 | self.nReadBlocks += 1 |
|
1267 | self.nReadBlocks += 1 | |
1268 |
|
1268 | |||
1269 | return 1 |
|
1269 | return 1 | |
1270 |
|
1270 | |||
1271 |
|
1271 | |||
1272 | def getData(self): |
|
1272 | def getData(self): | |
1273 | """ |
|
1273 | """ | |
1274 | getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage" |
|
1274 | getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage" | |
1275 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de |
|
1275 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de | |
1276 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" |
|
1276 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" | |
1277 |
|
1277 | |||
1278 | Ademas incrementa el contador del buffer en 1. |
|
1278 | Ademas incrementa el contador del buffer en 1. | |
1279 |
|
1279 | |||
1280 | Return: |
|
1280 | Return: | |
1281 | data : retorna un perfil de voltages (alturas * canales) copiados desde el |
|
1281 | data : retorna un perfil de voltages (alturas * canales) copiados desde el | |
1282 | buffer. Si no hay mas archivos a leer retorna None. |
|
1282 | buffer. Si no hay mas archivos a leer retorna None. | |
1283 |
|
1283 | |||
1284 | Variables afectadas: |
|
1284 | Variables afectadas: | |
1285 | self.dataOut |
|
1285 | self.dataOut | |
1286 | self.profileIndex |
|
1286 | self.profileIndex | |
1287 |
|
1287 | |||
1288 | Affected: |
|
1288 | Affected: | |
1289 | self.dataOut |
|
1289 | self.dataOut | |
1290 | self.profileIndex |
|
1290 | self.profileIndex | |
1291 | self.flagTimeBlock |
|
1291 | self.flagTimeBlock | |
1292 | self.flagIsNewBlock |
|
1292 | self.flagIsNewBlock | |
1293 | """ |
|
1293 | """ | |
1294 |
|
1294 | |||
1295 | if self.flagNoMoreFiles: |
|
1295 | if self.flagNoMoreFiles: | |
1296 | self.dataOut.flagNoData = True |
|
1296 | self.dataOut.flagNoData = True | |
1297 | print 'Process finished' |
|
1297 | print 'Process finished' | |
1298 | return 0 |
|
1298 | return 0 | |
1299 |
|
1299 | |||
1300 | self.flagTimeBlock = 0 |
|
1300 | self.flagTimeBlock = 0 | |
1301 | self.flagIsNewBlock = 0 |
|
1301 | self.flagIsNewBlock = 0 | |
1302 |
|
1302 | |||
1303 | if self.__hasNotDataInBuffer(): |
|
1303 | if self.__hasNotDataInBuffer(): | |
1304 |
|
1304 | |||
1305 | if not( self.readNextBlock() ): |
|
1305 | if not( self.readNextBlock() ): | |
1306 | return 0 |
|
1306 | return 0 | |
1307 |
|
1307 | |||
1308 | # self.updateDataHeader() |
|
1308 | # self.updateDataHeader() | |
1309 |
|
1309 | |||
1310 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) |
|
1310 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) | |
1311 |
|
1311 | |||
1312 | if self.datablock == None: |
|
1312 | if self.datablock == None: | |
1313 | self.dataOut.flagNoData = True |
|
1313 | self.dataOut.flagNoData = True | |
1314 | return 0 |
|
1314 | return 0 | |
1315 |
|
1315 | |||
1316 | self.dataOut.data = self.datablock[:,self.profileIndex,:] |
|
1316 | self.dataOut.data = self.datablock[:,self.profileIndex,:] | |
1317 |
|
1317 | |||
1318 | self.dataOut.dtype = self.dtype |
|
1318 | self.dataOut.dtype = self.dtype | |
1319 |
|
1319 | |||
1320 | # self.dataOut.nChannels = self.systemHeaderObj.nChannels |
|
1320 | # self.dataOut.nChannels = self.systemHeaderObj.nChannels | |
1321 |
|
1321 | |||
1322 | self.dataOut.nHeights = self.processingHeaderObj.nHeights |
|
1322 | # self.dataOut.nHeights = self.processingHeaderObj.nHeights | |
1323 |
|
1323 | |||
1324 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock |
|
1324 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock | |
1325 |
|
1325 | |||
1326 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight |
|
1326 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight | |
1327 |
|
1327 | |||
1328 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) |
|
1328 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) | |
1329 |
|
1329 | |||
1330 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) |
|
1330 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) | |
1331 |
|
1331 | |||
1332 | # self.dataOut.channelIndexList = range(self.systemHeaderObj.nChannels) |
|
1332 | # self.dataOut.channelIndexList = range(self.systemHeaderObj.nChannels) | |
1333 |
|
1333 | |||
1334 | self.dataOut.flagTimeBlock = self.flagTimeBlock |
|
1334 | self.dataOut.flagTimeBlock = self.flagTimeBlock | |
1335 |
|
1335 | |||
1336 | self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.ippSeconds |
|
1336 | self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.ippSeconds | |
1337 |
|
1337 | |||
1338 | self.dataOut.ippSeconds = self.ippSeconds |
|
1338 | self.dataOut.ippSeconds = self.ippSeconds | |
1339 |
|
1339 | |||
1340 | self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt |
|
1340 | self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt | |
1341 |
|
1341 | |||
1342 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt |
|
1342 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt | |
1343 |
|
1343 | |||
1344 | self.dataOut.flagShiftFFT = False |
|
1344 | self.dataOut.flagShiftFFT = False | |
1345 |
|
1345 | |||
1346 | if self.processingHeaderObj.code != None: |
|
1346 | if self.processingHeaderObj.code != None: | |
1347 | self.dataOut.nCode = self.processingHeaderObj.nCode |
|
1347 | self.dataOut.nCode = self.processingHeaderObj.nCode | |
1348 |
|
1348 | |||
1349 | self.dataOut.nBaud = self.processingHeaderObj.nBaud |
|
1349 | self.dataOut.nBaud = self.processingHeaderObj.nBaud | |
1350 |
|
1350 | |||
1351 | self.dataOut.code = self.processingHeaderObj.code |
|
1351 | self.dataOut.code = self.processingHeaderObj.code | |
1352 |
|
1352 | |||
1353 | self.profileIndex += 1 |
|
1353 | self.profileIndex += 1 | |
1354 |
|
1354 | |||
1355 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() |
|
1355 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() | |
1356 |
|
1356 | |||
1357 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() |
|
1357 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() | |
1358 |
|
1358 | |||
1359 | self.dataOut.flagNoData = False |
|
1359 | self.dataOut.flagNoData = False | |
1360 |
|
1360 | |||
1361 | # print self.profileIndex, self.dataOut.utctime |
|
1361 | # print self.profileIndex, self.dataOut.utctime | |
1362 | # if self.profileIndex == 800: |
|
1362 | # if self.profileIndex == 800: | |
1363 | # a=1 |
|
1363 | # a=1 | |
1364 |
|
1364 | |||
1365 | return self.dataOut.data |
|
1365 | return self.dataOut.data | |
1366 |
|
1366 | |||
1367 |
|
1367 | |||
1368 | class VoltageWriter(JRODataWriter): |
|
1368 | class VoltageWriter(JRODataWriter): | |
1369 | """ |
|
1369 | """ | |
1370 | Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura |
|
1370 | Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura | |
1371 | de los datos siempre se realiza por bloques. |
|
1371 | de los datos siempre se realiza por bloques. | |
1372 | """ |
|
1372 | """ | |
1373 |
|
1373 | |||
1374 | ext = ".r" |
|
1374 | ext = ".r" | |
1375 |
|
1375 | |||
1376 | optchar = "D" |
|
1376 | optchar = "D" | |
1377 |
|
1377 | |||
1378 | shapeBuffer = None |
|
1378 | shapeBuffer = None | |
1379 |
|
1379 | |||
1380 |
|
1380 | |||
1381 | def __init__(self): |
|
1381 | def __init__(self): | |
1382 | """ |
|
1382 | """ | |
1383 | Inicializador de la clase VoltageWriter para la escritura de datos de espectros. |
|
1383 | Inicializador de la clase VoltageWriter para la escritura de datos de espectros. | |
1384 |
|
1384 | |||
1385 | Affected: |
|
1385 | Affected: | |
1386 | self.dataOut |
|
1386 | self.dataOut | |
1387 |
|
1387 | |||
1388 | Return: None |
|
1388 | Return: None | |
1389 | """ |
|
1389 | """ | |
1390 |
|
1390 | |||
1391 | self.nTotalBlocks = 0 |
|
1391 | self.nTotalBlocks = 0 | |
1392 |
|
1392 | |||
1393 | self.profileIndex = 0 |
|
1393 | self.profileIndex = 0 | |
1394 |
|
1394 | |||
1395 | self.isConfig = False |
|
1395 | self.isConfig = False | |
1396 |
|
1396 | |||
1397 | self.fp = None |
|
1397 | self.fp = None | |
1398 |
|
1398 | |||
1399 | self.flagIsNewFile = 1 |
|
1399 | self.flagIsNewFile = 1 | |
1400 |
|
1400 | |||
1401 | self.nTotalBlocks = 0 |
|
1401 | self.nTotalBlocks = 0 | |
1402 |
|
1402 | |||
1403 | self.flagIsNewBlock = 0 |
|
1403 | self.flagIsNewBlock = 0 | |
1404 |
|
1404 | |||
1405 | self.setFile = None |
|
1405 | self.setFile = None | |
1406 |
|
1406 | |||
1407 | self.dtype = None |
|
1407 | self.dtype = None | |
1408 |
|
1408 | |||
1409 | self.path = None |
|
1409 | self.path = None | |
1410 |
|
1410 | |||
1411 | self.filename = None |
|
1411 | self.filename = None | |
1412 |
|
1412 | |||
1413 | self.basicHeaderObj = BasicHeader() |
|
1413 | self.basicHeaderObj = BasicHeader() | |
1414 |
|
1414 | |||
1415 | self.systemHeaderObj = SystemHeader() |
|
1415 | self.systemHeaderObj = SystemHeader() | |
1416 |
|
1416 | |||
1417 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
1417 | self.radarControllerHeaderObj = RadarControllerHeader() | |
1418 |
|
1418 | |||
1419 | self.processingHeaderObj = ProcessingHeader() |
|
1419 | self.processingHeaderObj = ProcessingHeader() | |
1420 |
|
1420 | |||
1421 | def hasAllDataInBuffer(self): |
|
1421 | def hasAllDataInBuffer(self): | |
1422 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: |
|
1422 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: | |
1423 | return 1 |
|
1423 | return 1 | |
1424 | return 0 |
|
1424 | return 0 | |
1425 |
|
1425 | |||
1426 |
|
1426 | |||
1427 | def setBlockDimension(self): |
|
1427 | def setBlockDimension(self): | |
1428 | """ |
|
1428 | """ | |
1429 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque |
|
1429 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque | |
1430 |
|
1430 | |||
1431 | Affected: |
|
1431 | Affected: | |
1432 | self.shape_spc_Buffer |
|
1432 | self.shape_spc_Buffer | |
1433 | self.shape_cspc_Buffer |
|
1433 | self.shape_cspc_Buffer | |
1434 | self.shape_dc_Buffer |
|
1434 | self.shape_dc_Buffer | |
1435 |
|
1435 | |||
1436 | Return: None |
|
1436 | Return: None | |
1437 | """ |
|
1437 | """ | |
1438 | self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock, |
|
1438 | self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock, | |
1439 | self.processingHeaderObj.nHeights, |
|
1439 | self.processingHeaderObj.nHeights, | |
1440 | self.systemHeaderObj.nChannels) |
|
1440 | self.systemHeaderObj.nChannels) | |
1441 |
|
1441 | |||
1442 | self.datablock = numpy.zeros((self.systemHeaderObj.nChannels, |
|
1442 | self.datablock = numpy.zeros((self.systemHeaderObj.nChannels, | |
1443 | self.processingHeaderObj.profilesPerBlock, |
|
1443 | self.processingHeaderObj.profilesPerBlock, | |
1444 | self.processingHeaderObj.nHeights), |
|
1444 | self.processingHeaderObj.nHeights), | |
1445 | dtype=numpy.dtype('complex')) |
|
1445 | dtype=numpy.dtype('complex')) | |
1446 |
|
1446 | |||
1447 |
|
1447 | |||
1448 | def writeBlock(self): |
|
1448 | def writeBlock(self): | |
1449 | """ |
|
1449 | """ | |
1450 | Escribe el buffer en el file designado |
|
1450 | Escribe el buffer en el file designado | |
1451 |
|
1451 | |||
1452 | Affected: |
|
1452 | Affected: | |
1453 | self.profileIndex |
|
1453 | self.profileIndex | |
1454 | self.flagIsNewFile |
|
1454 | self.flagIsNewFile | |
1455 | self.flagIsNewBlock |
|
1455 | self.flagIsNewBlock | |
1456 | self.nTotalBlocks |
|
1456 | self.nTotalBlocks | |
1457 | self.blockIndex |
|
1457 | self.blockIndex | |
1458 |
|
1458 | |||
1459 | Return: None |
|
1459 | Return: None | |
1460 | """ |
|
1460 | """ | |
1461 | data = numpy.zeros( self.shapeBuffer, self.dtype ) |
|
1461 | data = numpy.zeros( self.shapeBuffer, self.dtype ) | |
1462 |
|
1462 | |||
1463 | junk = numpy.transpose(self.datablock, (1,2,0)) |
|
1463 | junk = numpy.transpose(self.datablock, (1,2,0)) | |
1464 |
|
1464 | |||
1465 | data['real'] = junk.real |
|
1465 | data['real'] = junk.real | |
1466 | data['imag'] = junk.imag |
|
1466 | data['imag'] = junk.imag | |
1467 |
|
1467 | |||
1468 | data = data.reshape( (-1) ) |
|
1468 | data = data.reshape( (-1) ) | |
1469 |
|
1469 | |||
1470 | data.tofile( self.fp ) |
|
1470 | data.tofile( self.fp ) | |
1471 |
|
1471 | |||
1472 | self.datablock.fill(0) |
|
1472 | self.datablock.fill(0) | |
1473 |
|
1473 | |||
1474 | self.profileIndex = 0 |
|
1474 | self.profileIndex = 0 | |
1475 | self.flagIsNewFile = 0 |
|
1475 | self.flagIsNewFile = 0 | |
1476 | self.flagIsNewBlock = 1 |
|
1476 | self.flagIsNewBlock = 1 | |
1477 |
|
1477 | |||
1478 | self.blockIndex += 1 |
|
1478 | self.blockIndex += 1 | |
1479 | self.nTotalBlocks += 1 |
|
1479 | self.nTotalBlocks += 1 | |
1480 |
|
1480 | |||
1481 | def putData(self): |
|
1481 | def putData(self): | |
1482 | """ |
|
1482 | """ | |
1483 | Setea un bloque de datos y luego los escribe en un file |
|
1483 | Setea un bloque de datos y luego los escribe en un file | |
1484 |
|
1484 | |||
1485 | Affected: |
|
1485 | Affected: | |
1486 | self.flagIsNewBlock |
|
1486 | self.flagIsNewBlock | |
1487 | self.profileIndex |
|
1487 | self.profileIndex | |
1488 |
|
1488 | |||
1489 | Return: |
|
1489 | Return: | |
1490 | 0 : Si no hay data o no hay mas files que puedan escribirse |
|
1490 | 0 : Si no hay data o no hay mas files que puedan escribirse | |
1491 | 1 : Si se escribio la data de un bloque en un file |
|
1491 | 1 : Si se escribio la data de un bloque en un file | |
1492 | """ |
|
1492 | """ | |
1493 | if self.dataOut.flagNoData: |
|
1493 | if self.dataOut.flagNoData: | |
1494 | return 0 |
|
1494 | return 0 | |
1495 |
|
1495 | |||
1496 | self.flagIsNewBlock = 0 |
|
1496 | self.flagIsNewBlock = 0 | |
1497 |
|
1497 | |||
1498 | if self.dataOut.flagTimeBlock: |
|
1498 | if self.dataOut.flagTimeBlock: | |
1499 |
|
1499 | |||
1500 | self.datablock.fill(0) |
|
1500 | self.datablock.fill(0) | |
1501 | self.profileIndex = 0 |
|
1501 | self.profileIndex = 0 | |
1502 | self.setNextFile() |
|
1502 | self.setNextFile() | |
1503 |
|
1503 | |||
1504 | if self.profileIndex == 0: |
|
1504 | if self.profileIndex == 0: | |
1505 | self.getBasicHeader() |
|
1505 | self.getBasicHeader() | |
1506 |
|
1506 | |||
1507 | self.datablock[:,self.profileIndex,:] = self.dataOut.data |
|
1507 | self.datablock[:,self.profileIndex,:] = self.dataOut.data | |
1508 |
|
1508 | |||
1509 | self.profileIndex += 1 |
|
1509 | self.profileIndex += 1 | |
1510 |
|
1510 | |||
1511 | if self.hasAllDataInBuffer(): |
|
1511 | if self.hasAllDataInBuffer(): | |
1512 | #if self.flagIsNewFile: |
|
1512 | #if self.flagIsNewFile: | |
1513 | self.writeNextBlock() |
|
1513 | self.writeNextBlock() | |
1514 | # self.getDataHeader() |
|
1514 | # self.getDataHeader() | |
1515 |
|
1515 | |||
1516 | return 1 |
|
1516 | return 1 | |
1517 |
|
1517 | |||
1518 | def __getProcessFlags(self): |
|
1518 | def __getProcessFlags(self): | |
1519 |
|
1519 | |||
1520 | processFlags = 0 |
|
1520 | processFlags = 0 | |
1521 |
|
1521 | |||
1522 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
1522 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
1523 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
1523 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
1524 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
1524 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
1525 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
1525 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
1526 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
1526 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
1527 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
1527 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
1528 |
|
1528 | |||
1529 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
1529 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] | |
1530 |
|
1530 | |||
1531 |
|
1531 | |||
1532 |
|
1532 | |||
1533 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, |
|
1533 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, | |
1534 | PROCFLAG.DATATYPE_SHORT, |
|
1534 | PROCFLAG.DATATYPE_SHORT, | |
1535 | PROCFLAG.DATATYPE_LONG, |
|
1535 | PROCFLAG.DATATYPE_LONG, | |
1536 | PROCFLAG.DATATYPE_INT64, |
|
1536 | PROCFLAG.DATATYPE_INT64, | |
1537 | PROCFLAG.DATATYPE_FLOAT, |
|
1537 | PROCFLAG.DATATYPE_FLOAT, | |
1538 | PROCFLAG.DATATYPE_DOUBLE] |
|
1538 | PROCFLAG.DATATYPE_DOUBLE] | |
1539 |
|
1539 | |||
1540 |
|
1540 | |||
1541 | for index in range(len(dtypeList)): |
|
1541 | for index in range(len(dtypeList)): | |
1542 | if self.dataOut.dtype == dtypeList[index]: |
|
1542 | if self.dataOut.dtype == dtypeList[index]: | |
1543 | dtypeValue = datatypeValueList[index] |
|
1543 | dtypeValue = datatypeValueList[index] | |
1544 | break |
|
1544 | break | |
1545 |
|
1545 | |||
1546 | processFlags += dtypeValue |
|
1546 | processFlags += dtypeValue | |
1547 |
|
1547 | |||
1548 | if self.dataOut.flagDecodeData: |
|
1548 | if self.dataOut.flagDecodeData: | |
1549 | processFlags += PROCFLAG.DECODE_DATA |
|
1549 | processFlags += PROCFLAG.DECODE_DATA | |
1550 |
|
1550 | |||
1551 | if self.dataOut.flagDeflipData: |
|
1551 | if self.dataOut.flagDeflipData: | |
1552 | processFlags += PROCFLAG.DEFLIP_DATA |
|
1552 | processFlags += PROCFLAG.DEFLIP_DATA | |
1553 |
|
1553 | |||
1554 | if self.dataOut.code != None: |
|
1554 | if self.dataOut.code != None: | |
1555 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE |
|
1555 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE | |
1556 |
|
1556 | |||
1557 | if self.dataOut.nCohInt > 1: |
|
1557 | if self.dataOut.nCohInt > 1: | |
1558 | processFlags += PROCFLAG.COHERENT_INTEGRATION |
|
1558 | processFlags += PROCFLAG.COHERENT_INTEGRATION | |
1559 |
|
1559 | |||
1560 | return processFlags |
|
1560 | return processFlags | |
1561 |
|
1561 | |||
1562 |
|
1562 | |||
1563 | def __getBlockSize(self): |
|
1563 | def __getBlockSize(self): | |
1564 | ''' |
|
1564 | ''' | |
1565 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage |
|
1565 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage | |
1566 | ''' |
|
1566 | ''' | |
1567 |
|
1567 | |||
1568 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
1568 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
1569 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
1569 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
1570 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
1570 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
1571 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
1571 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
1572 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
1572 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
1573 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
1573 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
1574 |
|
1574 | |||
1575 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
1575 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] | |
1576 | datatypeValueList = [1,2,4,8,4,8] |
|
1576 | datatypeValueList = [1,2,4,8,4,8] | |
1577 | for index in range(len(dtypeList)): |
|
1577 | for index in range(len(dtypeList)): | |
1578 | if self.dataOut.dtype == dtypeList[index]: |
|
1578 | if self.dataOut.dtype == dtypeList[index]: | |
1579 | datatypeValue = datatypeValueList[index] |
|
1579 | datatypeValue = datatypeValueList[index] | |
1580 | break |
|
1580 | break | |
1581 |
|
1581 | |||
1582 | blocksize = int(self.dataOut.nHeights * self.dataOut.nChannels * self.dataOut.nProfiles * datatypeValue * 2) |
|
1582 | blocksize = int(self.dataOut.nHeights * self.dataOut.nChannels * self.dataOut.nProfiles * datatypeValue * 2) | |
1583 |
|
1583 | |||
1584 | return blocksize |
|
1584 | return blocksize | |
1585 |
|
1585 | |||
1586 | def getDataHeader(self): |
|
1586 | def getDataHeader(self): | |
1587 |
|
1587 | |||
1588 | """ |
|
1588 | """ | |
1589 | Obtiene una copia del First Header |
|
1589 | Obtiene una copia del First Header | |
1590 |
|
1590 | |||
1591 | Affected: |
|
1591 | Affected: | |
1592 | self.systemHeaderObj |
|
1592 | self.systemHeaderObj | |
1593 | self.radarControllerHeaderObj |
|
1593 | self.radarControllerHeaderObj | |
1594 | self.dtype |
|
1594 | self.dtype | |
1595 |
|
1595 | |||
1596 | Return: |
|
1596 | Return: | |
1597 | None |
|
1597 | None | |
1598 | """ |
|
1598 | """ | |
1599 |
|
1599 | |||
1600 | self.systemHeaderObj = self.dataOut.systemHeaderObj.copy() |
|
1600 | self.systemHeaderObj = self.dataOut.systemHeaderObj.copy() | |
1601 | self.systemHeaderObj.nChannels = self.dataOut.nChannels |
|
1601 | self.systemHeaderObj.nChannels = self.dataOut.nChannels | |
1602 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() |
|
1602 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() | |
1603 |
|
1603 | |||
1604 | self.getBasicHeader() |
|
1604 | self.getBasicHeader() | |
1605 |
|
1605 | |||
1606 | processingHeaderSize = 40 # bytes |
|
1606 | processingHeaderSize = 40 # bytes | |
1607 | self.processingHeaderObj.dtype = 0 # Voltage |
|
1607 | self.processingHeaderObj.dtype = 0 # Voltage | |
1608 | self.processingHeaderObj.blockSize = self.__getBlockSize() |
|
1608 | self.processingHeaderObj.blockSize = self.__getBlockSize() | |
1609 | self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock |
|
1609 | self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock | |
1610 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile |
|
1610 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile | |
1611 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows |
|
1611 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows | |
1612 | self.processingHeaderObj.processFlags = self.__getProcessFlags() |
|
1612 | self.processingHeaderObj.processFlags = self.__getProcessFlags() | |
1613 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt |
|
1613 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt | |
1614 | self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage |
|
1614 | self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage | |
1615 | self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage |
|
1615 | self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage | |
1616 |
|
1616 | |||
1617 | if self.dataOut.code != None: |
|
1617 | if self.dataOut.code != None: | |
1618 | self.processingHeaderObj.code = self.dataOut.code |
|
1618 | self.processingHeaderObj.code = self.dataOut.code | |
1619 | self.processingHeaderObj.nCode = self.dataOut.nCode |
|
1619 | self.processingHeaderObj.nCode = self.dataOut.nCode | |
1620 | self.processingHeaderObj.nBaud = self.dataOut.nBaud |
|
1620 | self.processingHeaderObj.nBaud = self.dataOut.nBaud | |
1621 | codesize = int(8 + 4 * self.dataOut.nCode * self.dataOut.nBaud) |
|
1621 | codesize = int(8 + 4 * self.dataOut.nCode * self.dataOut.nBaud) | |
1622 | processingHeaderSize += codesize |
|
1622 | processingHeaderSize += codesize | |
1623 |
|
1623 | |||
1624 | if self.processingHeaderObj.nWindows != 0: |
|
1624 | if self.processingHeaderObj.nWindows != 0: | |
1625 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] |
|
1625 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] | |
1626 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
1626 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] | |
1627 | self.processingHeaderObj.nHeights = self.dataOut.nHeights |
|
1627 | self.processingHeaderObj.nHeights = self.dataOut.nHeights | |
1628 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights |
|
1628 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights | |
1629 | processingHeaderSize += 12 |
|
1629 | processingHeaderSize += 12 | |
1630 |
|
1630 | |||
1631 | self.processingHeaderObj.size = processingHeaderSize |
|
1631 | self.processingHeaderObj.size = processingHeaderSize | |
1632 |
|
1632 | |||
1633 | class SpectraReader(JRODataReader): |
|
1633 | class SpectraReader(JRODataReader): | |
1634 | """ |
|
1634 | """ | |
1635 | Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura |
|
1635 | Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura | |
1636 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones) |
|
1636 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones) | |
1637 | son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel. |
|
1637 | son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel. | |
1638 |
|
1638 | |||
1639 | paresCanalesIguales * alturas * perfiles (Self Spectra) |
|
1639 | paresCanalesIguales * alturas * perfiles (Self Spectra) | |
1640 | paresCanalesDiferentes * alturas * perfiles (Cross Spectra) |
|
1640 | paresCanalesDiferentes * alturas * perfiles (Cross Spectra) | |
1641 | canales * alturas (DC Channels) |
|
1641 | canales * alturas (DC Channels) | |
1642 |
|
1642 | |||
1643 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, |
|
1643 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, | |
1644 | RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la |
|
1644 | RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la | |
1645 | cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de |
|
1645 | cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de | |
1646 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". |
|
1646 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". | |
1647 |
|
1647 | |||
1648 | Example: |
|
1648 | Example: | |
1649 | dpath = "/home/myuser/data" |
|
1649 | dpath = "/home/myuser/data" | |
1650 |
|
1650 | |||
1651 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) |
|
1651 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) | |
1652 |
|
1652 | |||
1653 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) |
|
1653 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) | |
1654 |
|
1654 | |||
1655 | readerObj = SpectraReader() |
|
1655 | readerObj = SpectraReader() | |
1656 |
|
1656 | |||
1657 | readerObj.setup(dpath, startTime, endTime) |
|
1657 | readerObj.setup(dpath, startTime, endTime) | |
1658 |
|
1658 | |||
1659 | while(True): |
|
1659 | while(True): | |
1660 |
|
1660 | |||
1661 | readerObj.getData() |
|
1661 | readerObj.getData() | |
1662 |
|
1662 | |||
1663 | print readerObj.data_spc |
|
1663 | print readerObj.data_spc | |
1664 |
|
1664 | |||
1665 | print readerObj.data_cspc |
|
1665 | print readerObj.data_cspc | |
1666 |
|
1666 | |||
1667 | print readerObj.data_dc |
|
1667 | print readerObj.data_dc | |
1668 |
|
1668 | |||
1669 | if readerObj.flagNoMoreFiles: |
|
1669 | if readerObj.flagNoMoreFiles: | |
1670 | break |
|
1670 | break | |
1671 |
|
1671 | |||
1672 | """ |
|
1672 | """ | |
1673 |
|
1673 | |||
1674 | pts2read_SelfSpectra = 0 |
|
1674 | pts2read_SelfSpectra = 0 | |
1675 |
|
1675 | |||
1676 | pts2read_CrossSpectra = 0 |
|
1676 | pts2read_CrossSpectra = 0 | |
1677 |
|
1677 | |||
1678 | pts2read_DCchannels = 0 |
|
1678 | pts2read_DCchannels = 0 | |
1679 |
|
1679 | |||
1680 | ext = ".pdata" |
|
1680 | ext = ".pdata" | |
1681 |
|
1681 | |||
1682 | optchar = "P" |
|
1682 | optchar = "P" | |
1683 |
|
1683 | |||
1684 | dataOut = None |
|
1684 | dataOut = None | |
1685 |
|
1685 | |||
1686 | nRdChannels = None |
|
1686 | nRdChannels = None | |
1687 |
|
1687 | |||
1688 | nRdPairs = None |
|
1688 | nRdPairs = None | |
1689 |
|
1689 | |||
1690 | rdPairList = [] |
|
1690 | rdPairList = [] | |
1691 |
|
1691 | |||
1692 |
|
1692 | |||
1693 | def __init__(self): |
|
1693 | def __init__(self): | |
1694 | """ |
|
1694 | """ | |
1695 | Inicializador de la clase SpectraReader para la lectura de datos de espectros. |
|
1695 | Inicializador de la clase SpectraReader para la lectura de datos de espectros. | |
1696 |
|
1696 | |||
1697 | Inputs: |
|
1697 | Inputs: | |
1698 | dataOut : Objeto de la clase Spectra. Este objeto sera utilizado para |
|
1698 | dataOut : Objeto de la clase Spectra. Este objeto sera utilizado para | |
1699 | almacenar un perfil de datos cada vez que se haga un requerimiento |
|
1699 | almacenar un perfil de datos cada vez que se haga un requerimiento | |
1700 | (getData). El perfil sera obtenido a partir del buffer de datos, |
|
1700 | (getData). El perfil sera obtenido a partir del buffer de datos, | |
1701 | si el buffer esta vacio se hara un nuevo proceso de lectura de un |
|
1701 | si el buffer esta vacio se hara un nuevo proceso de lectura de un | |
1702 | bloque de datos. |
|
1702 | bloque de datos. | |
1703 | Si este parametro no es pasado se creara uno internamente. |
|
1703 | Si este parametro no es pasado se creara uno internamente. | |
1704 |
|
1704 | |||
1705 | Affected: |
|
1705 | Affected: | |
1706 | self.dataOut |
|
1706 | self.dataOut | |
1707 |
|
1707 | |||
1708 | Return : None |
|
1708 | Return : None | |
1709 | """ |
|
1709 | """ | |
1710 |
|
1710 | |||
1711 | self.isConfig = False |
|
1711 | self.isConfig = False | |
1712 |
|
1712 | |||
1713 | self.pts2read_SelfSpectra = 0 |
|
1713 | self.pts2read_SelfSpectra = 0 | |
1714 |
|
1714 | |||
1715 | self.pts2read_CrossSpectra = 0 |
|
1715 | self.pts2read_CrossSpectra = 0 | |
1716 |
|
1716 | |||
1717 | self.pts2read_DCchannels = 0 |
|
1717 | self.pts2read_DCchannels = 0 | |
1718 |
|
1718 | |||
1719 | self.datablock = None |
|
1719 | self.datablock = None | |
1720 |
|
1720 | |||
1721 | self.utc = None |
|
1721 | self.utc = None | |
1722 |
|
1722 | |||
1723 | self.ext = ".pdata" |
|
1723 | self.ext = ".pdata" | |
1724 |
|
1724 | |||
1725 | self.optchar = "P" |
|
1725 | self.optchar = "P" | |
1726 |
|
1726 | |||
1727 | self.basicHeaderObj = BasicHeader() |
|
1727 | self.basicHeaderObj = BasicHeader() | |
1728 |
|
1728 | |||
1729 | self.systemHeaderObj = SystemHeader() |
|
1729 | self.systemHeaderObj = SystemHeader() | |
1730 |
|
1730 | |||
1731 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
1731 | self.radarControllerHeaderObj = RadarControllerHeader() | |
1732 |
|
1732 | |||
1733 | self.processingHeaderObj = ProcessingHeader() |
|
1733 | self.processingHeaderObj = ProcessingHeader() | |
1734 |
|
1734 | |||
1735 | self.online = 0 |
|
1735 | self.online = 0 | |
1736 |
|
1736 | |||
1737 | self.fp = None |
|
1737 | self.fp = None | |
1738 |
|
1738 | |||
1739 | self.idFile = None |
|
1739 | self.idFile = None | |
1740 |
|
1740 | |||
1741 | self.dtype = None |
|
1741 | self.dtype = None | |
1742 |
|
1742 | |||
1743 | self.fileSizeByHeader = None |
|
1743 | self.fileSizeByHeader = None | |
1744 |
|
1744 | |||
1745 | self.filenameList = [] |
|
1745 | self.filenameList = [] | |
1746 |
|
1746 | |||
1747 | self.filename = None |
|
1747 | self.filename = None | |
1748 |
|
1748 | |||
1749 | self.fileSize = None |
|
1749 | self.fileSize = None | |
1750 |
|
1750 | |||
1751 | self.firstHeaderSize = 0 |
|
1751 | self.firstHeaderSize = 0 | |
1752 |
|
1752 | |||
1753 | self.basicHeaderSize = 24 |
|
1753 | self.basicHeaderSize = 24 | |
1754 |
|
1754 | |||
1755 | self.pathList = [] |
|
1755 | self.pathList = [] | |
1756 |
|
1756 | |||
1757 | self.lastUTTime = 0 |
|
1757 | self.lastUTTime = 0 | |
1758 |
|
1758 | |||
1759 | self.maxTimeStep = 30 |
|
1759 | self.maxTimeStep = 30 | |
1760 |
|
1760 | |||
1761 | self.flagNoMoreFiles = 0 |
|
1761 | self.flagNoMoreFiles = 0 | |
1762 |
|
1762 | |||
1763 | self.set = 0 |
|
1763 | self.set = 0 | |
1764 |
|
1764 | |||
1765 | self.path = None |
|
1765 | self.path = None | |
1766 |
|
1766 | |||
1767 | self.delay = 3 #seconds |
|
1767 | self.delay = 3 #seconds | |
1768 |
|
1768 | |||
1769 | self.nTries = 3 #quantity tries |
|
1769 | self.nTries = 3 #quantity tries | |
1770 |
|
1770 | |||
1771 | self.nFiles = 3 #number of files for searching |
|
1771 | self.nFiles = 3 #number of files for searching | |
1772 |
|
1772 | |||
1773 | self.nReadBlocks = 0 |
|
1773 | self.nReadBlocks = 0 | |
1774 |
|
1774 | |||
1775 | self.flagIsNewFile = 1 |
|
1775 | self.flagIsNewFile = 1 | |
1776 |
|
1776 | |||
1777 | self.ippSeconds = 0 |
|
1777 | self.ippSeconds = 0 | |
1778 |
|
1778 | |||
1779 | self.flagTimeBlock = 0 |
|
1779 | self.flagTimeBlock = 0 | |
1780 |
|
1780 | |||
1781 | self.flagIsNewBlock = 0 |
|
1781 | self.flagIsNewBlock = 0 | |
1782 |
|
1782 | |||
1783 | self.nTotalBlocks = 0 |
|
1783 | self.nTotalBlocks = 0 | |
1784 |
|
1784 | |||
1785 | self.blocksize = 0 |
|
1785 | self.blocksize = 0 | |
1786 |
|
1786 | |||
1787 | self.dataOut = self.createObjByDefault() |
|
1787 | self.dataOut = self.createObjByDefault() | |
1788 |
|
1788 | |||
1789 |
|
1789 | |||
1790 | def createObjByDefault(self): |
|
1790 | def createObjByDefault(self): | |
1791 |
|
1791 | |||
1792 | dataObj = Spectra() |
|
1792 | dataObj = Spectra() | |
1793 |
|
1793 | |||
1794 | return dataObj |
|
1794 | return dataObj | |
1795 |
|
1795 | |||
1796 | def __hasNotDataInBuffer(self): |
|
1796 | def __hasNotDataInBuffer(self): | |
1797 | return 1 |
|
1797 | return 1 | |
1798 |
|
1798 | |||
1799 |
|
1799 | |||
1800 | def getBlockDimension(self): |
|
1800 | def getBlockDimension(self): | |
1801 | """ |
|
1801 | """ | |
1802 | Obtiene la cantidad de puntos a leer por cada bloque de datos |
|
1802 | Obtiene la cantidad de puntos a leer por cada bloque de datos | |
1803 |
|
1803 | |||
1804 | Affected: |
|
1804 | Affected: | |
1805 | self.nRdChannels |
|
1805 | self.nRdChannels | |
1806 | self.nRdPairs |
|
1806 | self.nRdPairs | |
1807 | self.pts2read_SelfSpectra |
|
1807 | self.pts2read_SelfSpectra | |
1808 | self.pts2read_CrossSpectra |
|
1808 | self.pts2read_CrossSpectra | |
1809 | self.pts2read_DCchannels |
|
1809 | self.pts2read_DCchannels | |
1810 | self.blocksize |
|
1810 | self.blocksize | |
1811 | self.dataOut.nChannels |
|
1811 | self.dataOut.nChannels | |
1812 | self.dataOut.nPairs |
|
1812 | self.dataOut.nPairs | |
1813 |
|
1813 | |||
1814 | Return: |
|
1814 | Return: | |
1815 | None |
|
1815 | None | |
1816 | """ |
|
1816 | """ | |
1817 | self.nRdChannels = 0 |
|
1817 | self.nRdChannels = 0 | |
1818 | self.nRdPairs = 0 |
|
1818 | self.nRdPairs = 0 | |
1819 | self.rdPairList = [] |
|
1819 | self.rdPairList = [] | |
1820 |
|
1820 | |||
1821 | for i in range(0, self.processingHeaderObj.totalSpectra*2, 2): |
|
1821 | for i in range(0, self.processingHeaderObj.totalSpectra*2, 2): | |
1822 | if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]: |
|
1822 | if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]: | |
1823 | self.nRdChannels = self.nRdChannels + 1 #par de canales iguales |
|
1823 | self.nRdChannels = self.nRdChannels + 1 #par de canales iguales | |
1824 | else: |
|
1824 | else: | |
1825 | self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes |
|
1825 | self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes | |
1826 | self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1])) |
|
1826 | self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1])) | |
1827 |
|
1827 | |||
1828 | pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock |
|
1828 | pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock | |
1829 |
|
1829 | |||
1830 | self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read) |
|
1830 | self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read) | |
1831 | self.blocksize = self.pts2read_SelfSpectra |
|
1831 | self.blocksize = self.pts2read_SelfSpectra | |
1832 |
|
1832 | |||
1833 | if self.processingHeaderObj.flag_cspc: |
|
1833 | if self.processingHeaderObj.flag_cspc: | |
1834 | self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read) |
|
1834 | self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read) | |
1835 | self.blocksize += self.pts2read_CrossSpectra |
|
1835 | self.blocksize += self.pts2read_CrossSpectra | |
1836 |
|
1836 | |||
1837 | if self.processingHeaderObj.flag_dc: |
|
1837 | if self.processingHeaderObj.flag_dc: | |
1838 | self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights) |
|
1838 | self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights) | |
1839 | self.blocksize += self.pts2read_DCchannels |
|
1839 | self.blocksize += self.pts2read_DCchannels | |
1840 |
|
1840 | |||
1841 | # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels |
|
1841 | # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels | |
1842 |
|
1842 | |||
1843 |
|
1843 | |||
1844 | def readBlock(self): |
|
1844 | def readBlock(self): | |
1845 | """ |
|
1845 | """ | |
1846 | Lee el bloque de datos desde la posicion actual del puntero del archivo |
|
1846 | Lee el bloque de datos desde la posicion actual del puntero del archivo | |
1847 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos |
|
1847 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos | |
1848 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer |
|
1848 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer | |
1849 | es seteado a 0 |
|
1849 | es seteado a 0 | |
1850 |
|
1850 | |||
1851 | Return: None |
|
1851 | Return: None | |
1852 |
|
1852 | |||
1853 | Variables afectadas: |
|
1853 | Variables afectadas: | |
1854 |
|
1854 | |||
1855 | self.flagIsNewFile |
|
1855 | self.flagIsNewFile | |
1856 | self.flagIsNewBlock |
|
1856 | self.flagIsNewBlock | |
1857 | self.nTotalBlocks |
|
1857 | self.nTotalBlocks | |
1858 | self.data_spc |
|
1858 | self.data_spc | |
1859 | self.data_cspc |
|
1859 | self.data_cspc | |
1860 | self.data_dc |
|
1860 | self.data_dc | |
1861 |
|
1861 | |||
1862 | Exceptions: |
|
1862 | Exceptions: | |
1863 | Si un bloque leido no es un bloque valido |
|
1863 | Si un bloque leido no es un bloque valido | |
1864 | """ |
|
1864 | """ | |
1865 | blockOk_flag = False |
|
1865 | blockOk_flag = False | |
1866 | fpointer = self.fp.tell() |
|
1866 | fpointer = self.fp.tell() | |
1867 |
|
1867 | |||
1868 | spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra ) |
|
1868 | spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra ) | |
1869 | spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D |
|
1869 | spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D | |
1870 |
|
1870 | |||
1871 | if self.processingHeaderObj.flag_cspc: |
|
1871 | if self.processingHeaderObj.flag_cspc: | |
1872 | cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra ) |
|
1872 | cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra ) | |
1873 | cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D |
|
1873 | cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D | |
1874 |
|
1874 | |||
1875 | if self.processingHeaderObj.flag_dc: |
|
1875 | if self.processingHeaderObj.flag_dc: | |
1876 | dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) ) |
|
1876 | dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) ) | |
1877 | dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D |
|
1877 | dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D | |
1878 |
|
1878 | |||
1879 |
|
1879 | |||
1880 | if not(self.processingHeaderObj.shif_fft): |
|
1880 | if not(self.processingHeaderObj.shif_fft): | |
1881 | #desplaza a la derecha en el eje 2 determinadas posiciones |
|
1881 | #desplaza a la derecha en el eje 2 determinadas posiciones | |
1882 | shift = int(self.processingHeaderObj.profilesPerBlock/2) |
|
1882 | shift = int(self.processingHeaderObj.profilesPerBlock/2) | |
1883 | spc = numpy.roll( spc, shift , axis=2 ) |
|
1883 | spc = numpy.roll( spc, shift , axis=2 ) | |
1884 |
|
1884 | |||
1885 | if self.processingHeaderObj.flag_cspc: |
|
1885 | if self.processingHeaderObj.flag_cspc: | |
1886 | #desplaza a la derecha en el eje 2 determinadas posiciones |
|
1886 | #desplaza a la derecha en el eje 2 determinadas posiciones | |
1887 | cspc = numpy.roll( cspc, shift, axis=2 ) |
|
1887 | cspc = numpy.roll( cspc, shift, axis=2 ) | |
1888 |
|
1888 | |||
1889 |
|
1889 | |||
1890 | spc = numpy.transpose( spc, (0,2,1) ) |
|
1890 | spc = numpy.transpose( spc, (0,2,1) ) | |
1891 | self.data_spc = spc |
|
1891 | self.data_spc = spc | |
1892 |
|
1892 | |||
1893 | if self.processingHeaderObj.flag_cspc: |
|
1893 | if self.processingHeaderObj.flag_cspc: | |
1894 | cspc = numpy.transpose( cspc, (0,2,1) ) |
|
1894 | cspc = numpy.transpose( cspc, (0,2,1) ) | |
1895 | self.data_cspc = cspc['real'] + cspc['imag']*1j |
|
1895 | self.data_cspc = cspc['real'] + cspc['imag']*1j | |
1896 | else: |
|
1896 | else: | |
1897 | self.data_cspc = None |
|
1897 | self.data_cspc = None | |
1898 |
|
1898 | |||
1899 | if self.processingHeaderObj.flag_dc: |
|
1899 | if self.processingHeaderObj.flag_dc: | |
1900 | self.data_dc = dc['real'] + dc['imag']*1j |
|
1900 | self.data_dc = dc['real'] + dc['imag']*1j | |
1901 | else: |
|
1901 | else: | |
1902 | self.data_dc = None |
|
1902 | self.data_dc = None | |
1903 |
|
1903 | |||
1904 | self.flagIsNewFile = 0 |
|
1904 | self.flagIsNewFile = 0 | |
1905 | self.flagIsNewBlock = 1 |
|
1905 | self.flagIsNewBlock = 1 | |
1906 |
|
1906 | |||
1907 | self.nTotalBlocks += 1 |
|
1907 | self.nTotalBlocks += 1 | |
1908 | self.nReadBlocks += 1 |
|
1908 | self.nReadBlocks += 1 | |
1909 |
|
1909 | |||
1910 | return 1 |
|
1910 | return 1 | |
1911 |
|
1911 | |||
1912 |
|
1912 | |||
1913 | def getData(self): |
|
1913 | def getData(self): | |
1914 | """ |
|
1914 | """ | |
1915 | Copia el buffer de lectura a la clase "Spectra", |
|
1915 | Copia el buffer de lectura a la clase "Spectra", | |
1916 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de |
|
1916 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de | |
1917 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" |
|
1917 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" | |
1918 |
|
1918 | |||
1919 | Return: |
|
1919 | Return: | |
1920 | 0 : Si no hay mas archivos disponibles |
|
1920 | 0 : Si no hay mas archivos disponibles | |
1921 | 1 : Si hizo una buena copia del buffer |
|
1921 | 1 : Si hizo una buena copia del buffer | |
1922 |
|
1922 | |||
1923 | Affected: |
|
1923 | Affected: | |
1924 | self.dataOut |
|
1924 | self.dataOut | |
1925 |
|
1925 | |||
1926 | self.flagTimeBlock |
|
1926 | self.flagTimeBlock | |
1927 | self.flagIsNewBlock |
|
1927 | self.flagIsNewBlock | |
1928 | """ |
|
1928 | """ | |
1929 |
|
1929 | |||
1930 | if self.flagNoMoreFiles: |
|
1930 | if self.flagNoMoreFiles: | |
1931 | self.dataOut.flagNoData = True |
|
1931 | self.dataOut.flagNoData = True | |
1932 | print 'Process finished' |
|
1932 | print 'Process finished' | |
1933 | return 0 |
|
1933 | return 0 | |
1934 |
|
1934 | |||
1935 | self.flagTimeBlock = 0 |
|
1935 | self.flagTimeBlock = 0 | |
1936 | self.flagIsNewBlock = 0 |
|
1936 | self.flagIsNewBlock = 0 | |
1937 |
|
1937 | |||
1938 | if self.__hasNotDataInBuffer(): |
|
1938 | if self.__hasNotDataInBuffer(): | |
1939 |
|
1939 | |||
1940 | if not( self.readNextBlock() ): |
|
1940 | if not( self.readNextBlock() ): | |
1941 | self.dataOut.flagNoData = True |
|
1941 | self.dataOut.flagNoData = True | |
1942 | return 0 |
|
1942 | return 0 | |
1943 |
|
1943 | |||
1944 | # self.updateDataHeader() |
|
1944 | # self.updateDataHeader() | |
1945 |
|
1945 | |||
1946 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) |
|
1946 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) | |
1947 |
|
1947 | |||
1948 | if self.data_dc == None: |
|
1948 | if self.data_dc == None: | |
1949 | self.dataOut.flagNoData = True |
|
1949 | self.dataOut.flagNoData = True | |
1950 | return 0 |
|
1950 | return 0 | |
1951 |
|
1951 | |||
1952 | self.dataOut.data_spc = self.data_spc |
|
1952 | self.dataOut.data_spc = self.data_spc | |
1953 |
|
1953 | |||
1954 | self.dataOut.data_cspc = self.data_cspc |
|
1954 | self.dataOut.data_cspc = self.data_cspc | |
1955 |
|
1955 | |||
1956 | self.dataOut.data_dc = self.data_dc |
|
1956 | self.dataOut.data_dc = self.data_dc | |
1957 |
|
1957 | |||
1958 | self.dataOut.flagTimeBlock = self.flagTimeBlock |
|
1958 | self.dataOut.flagTimeBlock = self.flagTimeBlock | |
1959 |
|
1959 | |||
1960 | self.dataOut.flagNoData = False |
|
1960 | self.dataOut.flagNoData = False | |
1961 |
|
1961 | |||
1962 | self.dataOut.dtype = self.dtype |
|
1962 | self.dataOut.dtype = self.dtype | |
1963 |
|
1963 | |||
1964 | # self.dataOut.nChannels = self.nRdChannels |
|
1964 | # self.dataOut.nChannels = self.nRdChannels | |
1965 |
|
1965 | |||
1966 | self.dataOut.nPairs = self.nRdPairs |
|
1966 | self.dataOut.nPairs = self.nRdPairs | |
1967 |
|
1967 | |||
1968 | self.dataOut.pairsList = self.rdPairList |
|
1968 | self.dataOut.pairsList = self.rdPairList | |
1969 |
|
1969 | |||
1970 | self.dataOut.nHeights = self.processingHeaderObj.nHeights |
|
1970 | # self.dataOut.nHeights = self.processingHeaderObj.nHeights | |
1971 |
|
1971 | |||
1972 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock |
|
1972 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock | |
1973 |
|
1973 | |||
1974 | self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock |
|
1974 | self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock | |
1975 |
|
1975 | |||
1976 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt |
|
1976 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt | |
1977 |
|
1977 | |||
1978 | self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt |
|
1978 | self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt | |
1979 |
|
1979 | |||
1980 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight |
|
1980 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight | |
1981 |
|
1981 | |||
1982 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) |
|
1982 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) | |
1983 |
|
1983 | |||
1984 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) |
|
1984 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) | |
1985 |
|
1985 | |||
1986 | # self.dataOut.channelIndexList = range(self.systemHeaderObj.nChannels) |
|
1986 | # self.dataOut.channelIndexList = range(self.systemHeaderObj.nChannels) | |
1987 |
|
1987 | |||
1988 | self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000.#+ self.profileIndex * self.ippSeconds |
|
1988 | self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000.#+ self.profileIndex * self.ippSeconds | |
1989 |
|
1989 | |||
1990 | self.dataOut.ippSeconds = self.ippSeconds |
|
1990 | self.dataOut.ippSeconds = self.ippSeconds | |
1991 |
|
1991 | |||
1992 | self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.dataOut.nFFTPoints |
|
1992 | self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.dataOut.nFFTPoints | |
1993 |
|
1993 | |||
1994 | self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft |
|
1994 | self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft | |
1995 |
|
1995 | |||
1996 | # self.profileIndex += 1 |
|
1996 | # self.profileIndex += 1 | |
1997 |
|
1997 | |||
1998 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() |
|
1998 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() | |
1999 |
|
1999 | |||
2000 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() |
|
2000 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() | |
2001 |
|
2001 | |||
2002 | return self.dataOut.data_spc |
|
2002 | return self.dataOut.data_spc | |
2003 |
|
2003 | |||
2004 |
|
2004 | |||
2005 | class SpectraWriter(JRODataWriter): |
|
2005 | class SpectraWriter(JRODataWriter): | |
2006 |
|
2006 | |||
2007 | """ |
|
2007 | """ | |
2008 | Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura |
|
2008 | Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura | |
2009 | de los datos siempre se realiza por bloques. |
|
2009 | de los datos siempre se realiza por bloques. | |
2010 | """ |
|
2010 | """ | |
2011 |
|
2011 | |||
2012 | ext = ".pdata" |
|
2012 | ext = ".pdata" | |
2013 |
|
2013 | |||
2014 | optchar = "P" |
|
2014 | optchar = "P" | |
2015 |
|
2015 | |||
2016 | shape_spc_Buffer = None |
|
2016 | shape_spc_Buffer = None | |
2017 |
|
2017 | |||
2018 | shape_cspc_Buffer = None |
|
2018 | shape_cspc_Buffer = None | |
2019 |
|
2019 | |||
2020 | shape_dc_Buffer = None |
|
2020 | shape_dc_Buffer = None | |
2021 |
|
2021 | |||
2022 | data_spc = None |
|
2022 | data_spc = None | |
2023 |
|
2023 | |||
2024 | data_cspc = None |
|
2024 | data_cspc = None | |
2025 |
|
2025 | |||
2026 | data_dc = None |
|
2026 | data_dc = None | |
2027 |
|
2027 | |||
2028 | # dataOut = None |
|
2028 | # dataOut = None | |
2029 |
|
2029 | |||
2030 | def __init__(self): |
|
2030 | def __init__(self): | |
2031 | """ |
|
2031 | """ | |
2032 | Inicializador de la clase SpectraWriter para la escritura de datos de espectros. |
|
2032 | Inicializador de la clase SpectraWriter para la escritura de datos de espectros. | |
2033 |
|
2033 | |||
2034 | Affected: |
|
2034 | Affected: | |
2035 | self.dataOut |
|
2035 | self.dataOut | |
2036 | self.basicHeaderObj |
|
2036 | self.basicHeaderObj | |
2037 | self.systemHeaderObj |
|
2037 | self.systemHeaderObj | |
2038 | self.radarControllerHeaderObj |
|
2038 | self.radarControllerHeaderObj | |
2039 | self.processingHeaderObj |
|
2039 | self.processingHeaderObj | |
2040 |
|
2040 | |||
2041 | Return: None |
|
2041 | Return: None | |
2042 | """ |
|
2042 | """ | |
2043 |
|
2043 | |||
2044 | self.isConfig = False |
|
2044 | self.isConfig = False | |
2045 |
|
2045 | |||
2046 | self.nTotalBlocks = 0 |
|
2046 | self.nTotalBlocks = 0 | |
2047 |
|
2047 | |||
2048 | self.data_spc = None |
|
2048 | self.data_spc = None | |
2049 |
|
2049 | |||
2050 | self.data_cspc = None |
|
2050 | self.data_cspc = None | |
2051 |
|
2051 | |||
2052 | self.data_dc = None |
|
2052 | self.data_dc = None | |
2053 |
|
2053 | |||
2054 | self.fp = None |
|
2054 | self.fp = None | |
2055 |
|
2055 | |||
2056 | self.flagIsNewFile = 1 |
|
2056 | self.flagIsNewFile = 1 | |
2057 |
|
2057 | |||
2058 | self.nTotalBlocks = 0 |
|
2058 | self.nTotalBlocks = 0 | |
2059 |
|
2059 | |||
2060 | self.flagIsNewBlock = 0 |
|
2060 | self.flagIsNewBlock = 0 | |
2061 |
|
2061 | |||
2062 | self.setFile = None |
|
2062 | self.setFile = None | |
2063 |
|
2063 | |||
2064 | self.dtype = None |
|
2064 | self.dtype = None | |
2065 |
|
2065 | |||
2066 | self.path = None |
|
2066 | self.path = None | |
2067 |
|
2067 | |||
2068 | self.noMoreFiles = 0 |
|
2068 | self.noMoreFiles = 0 | |
2069 |
|
2069 | |||
2070 | self.filename = None |
|
2070 | self.filename = None | |
2071 |
|
2071 | |||
2072 | self.basicHeaderObj = BasicHeader() |
|
2072 | self.basicHeaderObj = BasicHeader() | |
2073 |
|
2073 | |||
2074 | self.systemHeaderObj = SystemHeader() |
|
2074 | self.systemHeaderObj = SystemHeader() | |
2075 |
|
2075 | |||
2076 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
2076 | self.radarControllerHeaderObj = RadarControllerHeader() | |
2077 |
|
2077 | |||
2078 | self.processingHeaderObj = ProcessingHeader() |
|
2078 | self.processingHeaderObj = ProcessingHeader() | |
2079 |
|
2079 | |||
2080 |
|
2080 | |||
2081 | def hasAllDataInBuffer(self): |
|
2081 | def hasAllDataInBuffer(self): | |
2082 | return 1 |
|
2082 | return 1 | |
2083 |
|
2083 | |||
2084 |
|
2084 | |||
2085 | def setBlockDimension(self): |
|
2085 | def setBlockDimension(self): | |
2086 | """ |
|
2086 | """ | |
2087 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque |
|
2087 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque | |
2088 |
|
2088 | |||
2089 | Affected: |
|
2089 | Affected: | |
2090 | self.shape_spc_Buffer |
|
2090 | self.shape_spc_Buffer | |
2091 | self.shape_cspc_Buffer |
|
2091 | self.shape_cspc_Buffer | |
2092 | self.shape_dc_Buffer |
|
2092 | self.shape_dc_Buffer | |
2093 |
|
2093 | |||
2094 | Return: None |
|
2094 | Return: None | |
2095 | """ |
|
2095 | """ | |
2096 | self.shape_spc_Buffer = (self.dataOut.nChannels, |
|
2096 | self.shape_spc_Buffer = (self.dataOut.nChannels, | |
2097 | self.processingHeaderObj.nHeights, |
|
2097 | self.processingHeaderObj.nHeights, | |
2098 | self.processingHeaderObj.profilesPerBlock) |
|
2098 | self.processingHeaderObj.profilesPerBlock) | |
2099 |
|
2099 | |||
2100 | self.shape_cspc_Buffer = (self.dataOut.nPairs, |
|
2100 | self.shape_cspc_Buffer = (self.dataOut.nPairs, | |
2101 | self.processingHeaderObj.nHeights, |
|
2101 | self.processingHeaderObj.nHeights, | |
2102 | self.processingHeaderObj.profilesPerBlock) |
|
2102 | self.processingHeaderObj.profilesPerBlock) | |
2103 |
|
2103 | |||
2104 | self.shape_dc_Buffer = (self.dataOut.nChannels, |
|
2104 | self.shape_dc_Buffer = (self.dataOut.nChannels, | |
2105 | self.processingHeaderObj.nHeights) |
|
2105 | self.processingHeaderObj.nHeights) | |
2106 |
|
2106 | |||
2107 |
|
2107 | |||
2108 | def writeBlock(self): |
|
2108 | def writeBlock(self): | |
2109 | """ |
|
2109 | """ | |
2110 | Escribe el buffer en el file designado |
|
2110 | Escribe el buffer en el file designado | |
2111 |
|
2111 | |||
2112 | Affected: |
|
2112 | Affected: | |
2113 | self.data_spc |
|
2113 | self.data_spc | |
2114 | self.data_cspc |
|
2114 | self.data_cspc | |
2115 | self.data_dc |
|
2115 | self.data_dc | |
2116 | self.flagIsNewFile |
|
2116 | self.flagIsNewFile | |
2117 | self.flagIsNewBlock |
|
2117 | self.flagIsNewBlock | |
2118 | self.nTotalBlocks |
|
2118 | self.nTotalBlocks | |
2119 | self.nWriteBlocks |
|
2119 | self.nWriteBlocks | |
2120 |
|
2120 | |||
2121 | Return: None |
|
2121 | Return: None | |
2122 | """ |
|
2122 | """ | |
2123 |
|
2123 | |||
2124 | spc = numpy.transpose( self.data_spc, (0,2,1) ) |
|
2124 | spc = numpy.transpose( self.data_spc, (0,2,1) ) | |
2125 | if not( self.processingHeaderObj.shif_fft ): |
|
2125 | if not( self.processingHeaderObj.shif_fft ): | |
2126 | spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
2126 | spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones | |
2127 | data = spc.reshape((-1)) |
|
2127 | data = spc.reshape((-1)) | |
2128 | data.tofile(self.fp) |
|
2128 | data.tofile(self.fp) | |
2129 |
|
2129 | |||
2130 | if self.data_cspc != None: |
|
2130 | if self.data_cspc != None: | |
2131 | data = numpy.zeros( self.shape_cspc_Buffer, self.dtype ) |
|
2131 | data = numpy.zeros( self.shape_cspc_Buffer, self.dtype ) | |
2132 | cspc = numpy.transpose( self.data_cspc, (0,2,1) ) |
|
2132 | cspc = numpy.transpose( self.data_cspc, (0,2,1) ) | |
2133 | if not( self.processingHeaderObj.shif_fft ): |
|
2133 | if not( self.processingHeaderObj.shif_fft ): | |
2134 | cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
2134 | cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones | |
2135 | data['real'] = cspc.real |
|
2135 | data['real'] = cspc.real | |
2136 | data['imag'] = cspc.imag |
|
2136 | data['imag'] = cspc.imag | |
2137 | data = data.reshape((-1)) |
|
2137 | data = data.reshape((-1)) | |
2138 | data.tofile(self.fp) |
|
2138 | data.tofile(self.fp) | |
2139 |
|
2139 | |||
2140 | if self.data_dc != None: |
|
2140 | if self.data_dc != None: | |
2141 | data = numpy.zeros( self.shape_dc_Buffer, self.dtype ) |
|
2141 | data = numpy.zeros( self.shape_dc_Buffer, self.dtype ) | |
2142 | dc = self.data_dc |
|
2142 | dc = self.data_dc | |
2143 | data['real'] = dc.real |
|
2143 | data['real'] = dc.real | |
2144 | data['imag'] = dc.imag |
|
2144 | data['imag'] = dc.imag | |
2145 | data = data.reshape((-1)) |
|
2145 | data = data.reshape((-1)) | |
2146 | data.tofile(self.fp) |
|
2146 | data.tofile(self.fp) | |
2147 |
|
2147 | |||
2148 | self.data_spc.fill(0) |
|
2148 | self.data_spc.fill(0) | |
2149 | self.data_dc.fill(0) |
|
2149 | self.data_dc.fill(0) | |
2150 | if self.data_cspc != None: |
|
2150 | if self.data_cspc != None: | |
2151 | self.data_cspc.fill(0) |
|
2151 | self.data_cspc.fill(0) | |
2152 |
|
2152 | |||
2153 | self.flagIsNewFile = 0 |
|
2153 | self.flagIsNewFile = 0 | |
2154 | self.flagIsNewBlock = 1 |
|
2154 | self.flagIsNewBlock = 1 | |
2155 | self.nTotalBlocks += 1 |
|
2155 | self.nTotalBlocks += 1 | |
2156 | self.nWriteBlocks += 1 |
|
2156 | self.nWriteBlocks += 1 | |
2157 | self.blockIndex += 1 |
|
2157 | self.blockIndex += 1 | |
2158 |
|
2158 | |||
2159 |
|
2159 | |||
2160 | def putData(self): |
|
2160 | def putData(self): | |
2161 | """ |
|
2161 | """ | |
2162 | Setea un bloque de datos y luego los escribe en un file |
|
2162 | Setea un bloque de datos y luego los escribe en un file | |
2163 |
|
2163 | |||
2164 | Affected: |
|
2164 | Affected: | |
2165 | self.data_spc |
|
2165 | self.data_spc | |
2166 | self.data_cspc |
|
2166 | self.data_cspc | |
2167 | self.data_dc |
|
2167 | self.data_dc | |
2168 |
|
2168 | |||
2169 | Return: |
|
2169 | Return: | |
2170 | 0 : Si no hay data o no hay mas files que puedan escribirse |
|
2170 | 0 : Si no hay data o no hay mas files que puedan escribirse | |
2171 | 1 : Si se escribio la data de un bloque en un file |
|
2171 | 1 : Si se escribio la data de un bloque en un file | |
2172 | """ |
|
2172 | """ | |
2173 |
|
2173 | |||
2174 | if self.dataOut.flagNoData: |
|
2174 | if self.dataOut.flagNoData: | |
2175 | return 0 |
|
2175 | return 0 | |
2176 |
|
2176 | |||
2177 | self.flagIsNewBlock = 0 |
|
2177 | self.flagIsNewBlock = 0 | |
2178 |
|
2178 | |||
2179 | if self.dataOut.flagTimeBlock: |
|
2179 | if self.dataOut.flagTimeBlock: | |
2180 | self.data_spc.fill(0) |
|
2180 | self.data_spc.fill(0) | |
2181 | self.data_cspc.fill(0) |
|
2181 | self.data_cspc.fill(0) | |
2182 | self.data_dc.fill(0) |
|
2182 | self.data_dc.fill(0) | |
2183 | self.setNextFile() |
|
2183 | self.setNextFile() | |
2184 |
|
2184 | |||
2185 | if self.flagIsNewFile == 0: |
|
2185 | if self.flagIsNewFile == 0: | |
2186 | self.getBasicHeader() |
|
2186 | self.getBasicHeader() | |
2187 |
|
2187 | |||
2188 | self.data_spc = self.dataOut.data_spc |
|
2188 | self.data_spc = self.dataOut.data_spc | |
2189 | self.data_cspc = self.dataOut.data_cspc |
|
2189 | self.data_cspc = self.dataOut.data_cspc | |
2190 | self.data_dc = self.dataOut.data_dc |
|
2190 | self.data_dc = self.dataOut.data_dc | |
2191 |
|
2191 | |||
2192 | # #self.processingHeaderObj.dataBlocksPerFile) |
|
2192 | # #self.processingHeaderObj.dataBlocksPerFile) | |
2193 | if self.hasAllDataInBuffer(): |
|
2193 | if self.hasAllDataInBuffer(): | |
2194 | # self.getDataHeader() |
|
2194 | # self.getDataHeader() | |
2195 | self.writeNextBlock() |
|
2195 | self.writeNextBlock() | |
2196 |
|
2196 | |||
2197 | return 1 |
|
2197 | return 1 | |
2198 |
|
2198 | |||
2199 |
|
2199 | |||
2200 | def __getProcessFlags(self): |
|
2200 | def __getProcessFlags(self): | |
2201 |
|
2201 | |||
2202 | processFlags = 0 |
|
2202 | processFlags = 0 | |
2203 |
|
2203 | |||
2204 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
2204 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
2205 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
2205 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
2206 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
2206 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
2207 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
2207 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
2208 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
2208 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
2209 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
2209 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
2210 |
|
2210 | |||
2211 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
2211 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] | |
2212 |
|
2212 | |||
2213 |
|
2213 | |||
2214 |
|
2214 | |||
2215 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, |
|
2215 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, | |
2216 | PROCFLAG.DATATYPE_SHORT, |
|
2216 | PROCFLAG.DATATYPE_SHORT, | |
2217 | PROCFLAG.DATATYPE_LONG, |
|
2217 | PROCFLAG.DATATYPE_LONG, | |
2218 | PROCFLAG.DATATYPE_INT64, |
|
2218 | PROCFLAG.DATATYPE_INT64, | |
2219 | PROCFLAG.DATATYPE_FLOAT, |
|
2219 | PROCFLAG.DATATYPE_FLOAT, | |
2220 | PROCFLAG.DATATYPE_DOUBLE] |
|
2220 | PROCFLAG.DATATYPE_DOUBLE] | |
2221 |
|
2221 | |||
2222 |
|
2222 | |||
2223 | for index in range(len(dtypeList)): |
|
2223 | for index in range(len(dtypeList)): | |
2224 | if self.dataOut.dtype == dtypeList[index]: |
|
2224 | if self.dataOut.dtype == dtypeList[index]: | |
2225 | dtypeValue = datatypeValueList[index] |
|
2225 | dtypeValue = datatypeValueList[index] | |
2226 | break |
|
2226 | break | |
2227 |
|
2227 | |||
2228 | processFlags += dtypeValue |
|
2228 | processFlags += dtypeValue | |
2229 |
|
2229 | |||
2230 | if self.dataOut.flagDecodeData: |
|
2230 | if self.dataOut.flagDecodeData: | |
2231 | processFlags += PROCFLAG.DECODE_DATA |
|
2231 | processFlags += PROCFLAG.DECODE_DATA | |
2232 |
|
2232 | |||
2233 | if self.dataOut.flagDeflipData: |
|
2233 | if self.dataOut.flagDeflipData: | |
2234 | processFlags += PROCFLAG.DEFLIP_DATA |
|
2234 | processFlags += PROCFLAG.DEFLIP_DATA | |
2235 |
|
2235 | |||
2236 | if self.dataOut.code != None: |
|
2236 | if self.dataOut.code != None: | |
2237 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE |
|
2237 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE | |
2238 |
|
2238 | |||
2239 | if self.dataOut.nIncohInt > 1: |
|
2239 | if self.dataOut.nIncohInt > 1: | |
2240 | processFlags += PROCFLAG.INCOHERENT_INTEGRATION |
|
2240 | processFlags += PROCFLAG.INCOHERENT_INTEGRATION | |
2241 |
|
2241 | |||
2242 | if self.dataOut.data_dc != None: |
|
2242 | if self.dataOut.data_dc != None: | |
2243 | processFlags += PROCFLAG.SAVE_CHANNELS_DC |
|
2243 | processFlags += PROCFLAG.SAVE_CHANNELS_DC | |
2244 |
|
2244 | |||
2245 | return processFlags |
|
2245 | return processFlags | |
2246 |
|
2246 | |||
2247 |
|
2247 | |||
2248 | def __getBlockSize(self): |
|
2248 | def __getBlockSize(self): | |
2249 | ''' |
|
2249 | ''' | |
2250 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra |
|
2250 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra | |
2251 | ''' |
|
2251 | ''' | |
2252 |
|
2252 | |||
2253 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
2253 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
2254 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
2254 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
2255 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
2255 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
2256 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
2256 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
2257 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
2257 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
2258 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
2258 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
2259 |
|
2259 | |||
2260 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
2260 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] | |
2261 | datatypeValueList = [1,2,4,8,4,8] |
|
2261 | datatypeValueList = [1,2,4,8,4,8] | |
2262 | for index in range(len(dtypeList)): |
|
2262 | for index in range(len(dtypeList)): | |
2263 | if self.dataOut.dtype == dtypeList[index]: |
|
2263 | if self.dataOut.dtype == dtypeList[index]: | |
2264 | datatypeValue = datatypeValueList[index] |
|
2264 | datatypeValue = datatypeValueList[index] | |
2265 | break |
|
2265 | break | |
2266 |
|
2266 | |||
2267 |
|
2267 | |||
2268 | pts2write = self.dataOut.nHeights * self.dataOut.nFFTPoints |
|
2268 | pts2write = self.dataOut.nHeights * self.dataOut.nFFTPoints | |
2269 |
|
2269 | |||
2270 | pts2write_SelfSpectra = int(self.dataOut.nChannels * pts2write) |
|
2270 | pts2write_SelfSpectra = int(self.dataOut.nChannels * pts2write) | |
2271 | blocksize = (pts2write_SelfSpectra*datatypeValue) |
|
2271 | blocksize = (pts2write_SelfSpectra*datatypeValue) | |
2272 |
|
2272 | |||
2273 | if self.dataOut.data_cspc != None: |
|
2273 | if self.dataOut.data_cspc != None: | |
2274 | pts2write_CrossSpectra = int(self.dataOut.nPairs * pts2write) |
|
2274 | pts2write_CrossSpectra = int(self.dataOut.nPairs * pts2write) | |
2275 | blocksize += (pts2write_CrossSpectra*datatypeValue*2) |
|
2275 | blocksize += (pts2write_CrossSpectra*datatypeValue*2) | |
2276 |
|
2276 | |||
2277 | if self.dataOut.data_dc != None: |
|
2277 | if self.dataOut.data_dc != None: | |
2278 | pts2write_DCchannels = int(self.dataOut.nChannels * self.dataOut.nHeights) |
|
2278 | pts2write_DCchannels = int(self.dataOut.nChannels * self.dataOut.nHeights) | |
2279 | blocksize += (pts2write_DCchannels*datatypeValue*2) |
|
2279 | blocksize += (pts2write_DCchannels*datatypeValue*2) | |
2280 |
|
2280 | |||
2281 | blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO |
|
2281 | blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO | |
2282 |
|
2282 | |||
2283 | return blocksize |
|
2283 | return blocksize | |
2284 |
|
2284 | |||
2285 | def getDataHeader(self): |
|
2285 | def getDataHeader(self): | |
2286 |
|
2286 | |||
2287 | """ |
|
2287 | """ | |
2288 | Obtiene una copia del First Header |
|
2288 | Obtiene una copia del First Header | |
2289 |
|
2289 | |||
2290 | Affected: |
|
2290 | Affected: | |
2291 | self.systemHeaderObj |
|
2291 | self.systemHeaderObj | |
2292 | self.radarControllerHeaderObj |
|
2292 | self.radarControllerHeaderObj | |
2293 | self.dtype |
|
2293 | self.dtype | |
2294 |
|
2294 | |||
2295 | Return: |
|
2295 | Return: | |
2296 | None |
|
2296 | None | |
2297 | """ |
|
2297 | """ | |
2298 |
|
2298 | |||
2299 | self.systemHeaderObj = self.dataOut.systemHeaderObj.copy() |
|
2299 | self.systemHeaderObj = self.dataOut.systemHeaderObj.copy() | |
2300 | self.systemHeaderObj.nChannels = self.dataOut.nChannels |
|
2300 | self.systemHeaderObj.nChannels = self.dataOut.nChannels | |
2301 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() |
|
2301 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() | |
2302 |
|
2302 | |||
2303 | self.getBasicHeader() |
|
2303 | self.getBasicHeader() | |
2304 |
|
2304 | |||
2305 | processingHeaderSize = 40 # bytes |
|
2305 | processingHeaderSize = 40 # bytes | |
2306 | self.processingHeaderObj.dtype = 0 # Voltage |
|
2306 | self.processingHeaderObj.dtype = 0 # Voltage | |
2307 | self.processingHeaderObj.blockSize = self.__getBlockSize() |
|
2307 | self.processingHeaderObj.blockSize = self.__getBlockSize() | |
2308 | self.processingHeaderObj.profilesPerBlock = self.dataOut.nFFTPoints |
|
2308 | self.processingHeaderObj.profilesPerBlock = self.dataOut.nFFTPoints | |
2309 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile |
|
2309 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile | |
2310 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows |
|
2310 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows | |
2311 | self.processingHeaderObj.processFlags = self.__getProcessFlags() |
|
2311 | self.processingHeaderObj.processFlags = self.__getProcessFlags() | |
2312 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt# Se requiere para determinar el valor de timeInterval |
|
2312 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt# Se requiere para determinar el valor de timeInterval | |
2313 | self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt |
|
2313 | self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt | |
2314 | self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels |
|
2314 | self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels | |
2315 |
|
2315 | |||
2316 | if self.processingHeaderObj.totalSpectra > 0: |
|
2316 | if self.processingHeaderObj.totalSpectra > 0: | |
2317 | channelList = [] |
|
2317 | channelList = [] | |
2318 | for channel in range(self.dataOut.nChannels): |
|
2318 | for channel in range(self.dataOut.nChannels): | |
2319 | channelList.append(channel) |
|
2319 | channelList.append(channel) | |
2320 | channelList.append(channel) |
|
2320 | channelList.append(channel) | |
2321 |
|
2321 | |||
2322 | pairsList = [] |
|
2322 | pairsList = [] | |
2323 | for pair in self.dataOut.pairsList: |
|
2323 | for pair in self.dataOut.pairsList: | |
2324 | pairsList.append(pair[0]) |
|
2324 | pairsList.append(pair[0]) | |
2325 | pairsList.append(pair[1]) |
|
2325 | pairsList.append(pair[1]) | |
2326 | spectraComb = channelList + pairsList |
|
2326 | spectraComb = channelList + pairsList | |
2327 | spectraComb = numpy.array(spectraComb,dtype="u1") |
|
2327 | spectraComb = numpy.array(spectraComb,dtype="u1") | |
2328 | self.processingHeaderObj.spectraComb = spectraComb |
|
2328 | self.processingHeaderObj.spectraComb = spectraComb | |
2329 | sizeOfSpcComb = len(spectraComb) |
|
2329 | sizeOfSpcComb = len(spectraComb) | |
2330 | processingHeaderSize += sizeOfSpcComb |
|
2330 | processingHeaderSize += sizeOfSpcComb | |
2331 |
|
2331 | |||
2332 | if self.dataOut.code != None: |
|
2332 | if self.dataOut.code != None: | |
2333 | self.processingHeaderObj.code = self.dataOut.code |
|
2333 | self.processingHeaderObj.code = self.dataOut.code | |
2334 | self.processingHeaderObj.nCode = self.dataOut.nCode |
|
2334 | self.processingHeaderObj.nCode = self.dataOut.nCode | |
2335 | self.processingHeaderObj.nBaud = self.dataOut.nBaud |
|
2335 | self.processingHeaderObj.nBaud = self.dataOut.nBaud | |
2336 | nCodeSize = 4 # bytes |
|
2336 | nCodeSize = 4 # bytes | |
2337 | nBaudSize = 4 # bytes |
|
2337 | nBaudSize = 4 # bytes | |
2338 | codeSize = 4 # bytes |
|
2338 | codeSize = 4 # bytes | |
2339 | sizeOfCode = int(nCodeSize + nBaudSize + codeSize * self.dataOut.nCode * self.dataOut.nBaud) |
|
2339 | sizeOfCode = int(nCodeSize + nBaudSize + codeSize * self.dataOut.nCode * self.dataOut.nBaud) | |
2340 | processingHeaderSize += sizeOfCode |
|
2340 | processingHeaderSize += sizeOfCode | |
2341 |
|
2341 | |||
2342 | if self.processingHeaderObj.nWindows != 0: |
|
2342 | if self.processingHeaderObj.nWindows != 0: | |
2343 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] |
|
2343 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] | |
2344 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
2344 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] | |
2345 | self.processingHeaderObj.nHeights = self.dataOut.nHeights |
|
2345 | self.processingHeaderObj.nHeights = self.dataOut.nHeights | |
2346 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights |
|
2346 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights | |
2347 | sizeOfFirstHeight = 4 |
|
2347 | sizeOfFirstHeight = 4 | |
2348 | sizeOfdeltaHeight = 4 |
|
2348 | sizeOfdeltaHeight = 4 | |
2349 | sizeOfnHeights = 4 |
|
2349 | sizeOfnHeights = 4 | |
2350 | sizeOfWindows = (sizeOfFirstHeight + sizeOfdeltaHeight + sizeOfnHeights)*self.processingHeaderObj.nWindows |
|
2350 | sizeOfWindows = (sizeOfFirstHeight + sizeOfdeltaHeight + sizeOfnHeights)*self.processingHeaderObj.nWindows | |
2351 | processingHeaderSize += sizeOfWindows |
|
2351 | processingHeaderSize += sizeOfWindows | |
2352 |
|
2352 | |||
2353 | self.processingHeaderObj.size = processingHeaderSize |
|
2353 | self.processingHeaderObj.size = processingHeaderSize | |
2354 |
|
2354 | |||
2355 | class SpectraHeisWriter(): |
|
2355 | class SpectraHeisWriter(): | |
2356 |
|
2356 | |||
2357 | i=0 |
|
2357 | i=0 | |
2358 |
|
2358 | |||
2359 | def __init__(self, dataOut): |
|
2359 | def __init__(self, dataOut): | |
2360 |
|
2360 | |||
2361 | self.wrObj = FITS() |
|
2361 | self.wrObj = FITS() | |
2362 | self.dataOut = dataOut |
|
2362 | self.dataOut = dataOut | |
2363 |
|
2363 | |||
2364 | def isNumber(str): |
|
2364 | def isNumber(str): | |
2365 | """ |
|
2365 | """ | |
2366 | Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero. |
|
2366 | Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero. | |
2367 |
|
2367 | |||
2368 | Excepciones: |
|
2368 | Excepciones: | |
2369 | Si un determinado string no puede ser convertido a numero |
|
2369 | Si un determinado string no puede ser convertido a numero | |
2370 | Input: |
|
2370 | Input: | |
2371 | str, string al cual se le analiza para determinar si convertible a un numero o no |
|
2371 | str, string al cual se le analiza para determinar si convertible a un numero o no | |
2372 |
|
2372 | |||
2373 | Return: |
|
2373 | Return: | |
2374 | True : si el string es uno numerico |
|
2374 | True : si el string es uno numerico | |
2375 | False : no es un string numerico |
|
2375 | False : no es un string numerico | |
2376 | """ |
|
2376 | """ | |
2377 | try: |
|
2377 | try: | |
2378 | float( str ) |
|
2378 | float( str ) | |
2379 | return True |
|
2379 | return True | |
2380 | except: |
|
2380 | except: | |
2381 | return False |
|
2381 | return False | |
2382 |
|
2382 | |||
2383 | def setup(self, wrpath,): |
|
2383 | def setup(self, wrpath,): | |
2384 |
|
2384 | |||
2385 | if not(os.path.exists(wrpath)): |
|
2385 | if not(os.path.exists(wrpath)): | |
2386 | os.mkdir(wrpath) |
|
2386 | os.mkdir(wrpath) | |
2387 |
|
2387 | |||
2388 | self.wrpath = wrpath |
|
2388 | self.wrpath = wrpath | |
2389 | self.setFile = 0 |
|
2389 | self.setFile = 0 | |
2390 |
|
2390 | |||
2391 | def putData(self): |
|
2391 | def putData(self): | |
2392 | # self.wrObj.writeHeader(nChannels=self.dataOut.nChannels, nFFTPoints=self.dataOut.nFFTPoints) |
|
2392 | # self.wrObj.writeHeader(nChannels=self.dataOut.nChannels, nFFTPoints=self.dataOut.nFFTPoints) | |
2393 | #name = self.dataOut.utctime |
|
2393 | #name = self.dataOut.utctime | |
2394 | name= time.localtime( self.dataOut.utctime) |
|
2394 | name= time.localtime( self.dataOut.utctime) | |
2395 | ext=".fits" |
|
2395 | ext=".fits" | |
2396 | #folder='D%4.4d%3.3d'%(name.tm_year,name.tm_yday) |
|
2396 | #folder='D%4.4d%3.3d'%(name.tm_year,name.tm_yday) | |
2397 | subfolder = 'D%4.4d%3.3d' % (name.tm_year,name.tm_yday) |
|
2397 | subfolder = 'D%4.4d%3.3d' % (name.tm_year,name.tm_yday) | |
2398 |
|
2398 | |||
2399 | doypath = os.path.join( self.wrpath, subfolder ) |
|
2399 | doypath = os.path.join( self.wrpath, subfolder ) | |
2400 | if not( os.path.exists(doypath) ): |
|
2400 | if not( os.path.exists(doypath) ): | |
2401 | os.mkdir(doypath) |
|
2401 | os.mkdir(doypath) | |
2402 | self.setFile += 1 |
|
2402 | self.setFile += 1 | |
2403 | file = 'D%4.4d%3.3d%3.3d%s' % (name.tm_year,name.tm_yday,self.setFile,ext) |
|
2403 | file = 'D%4.4d%3.3d%3.3d%s' % (name.tm_year,name.tm_yday,self.setFile,ext) | |
2404 |
|
2404 | |||
2405 | filename = os.path.join(self.wrpath,subfolder, file) |
|
2405 | filename = os.path.join(self.wrpath,subfolder, file) | |
2406 |
|
2406 | |||
2407 | # print self.dataOut.ippSeconds |
|
2407 | # print self.dataOut.ippSeconds | |
2408 | freq=numpy.arange(-1*self.dataOut.nHeights/2.,self.dataOut.nHeights/2.)/(2*self.dataOut.ippSeconds) |
|
2408 | freq=numpy.arange(-1*self.dataOut.nHeights/2.,self.dataOut.nHeights/2.)/(2*self.dataOut.ippSeconds) | |
2409 |
|
2409 | |||
2410 | col1=self.wrObj.setColF(name="freq", format=str(self.dataOut.nFFTPoints)+'E', array=freq) |
|
2410 | col1=self.wrObj.setColF(name="freq", format=str(self.dataOut.nFFTPoints)+'E', array=freq) | |
2411 | col2=self.wrObj.writeData(name="P_Ch1",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[0,:])) |
|
2411 | col2=self.wrObj.writeData(name="P_Ch1",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[0,:])) | |
2412 | col3=self.wrObj.writeData(name="P_Ch2",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[1,:])) |
|
2412 | col3=self.wrObj.writeData(name="P_Ch2",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[1,:])) | |
2413 | col4=self.wrObj.writeData(name="P_Ch3",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[2,:])) |
|
2413 | col4=self.wrObj.writeData(name="P_Ch3",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[2,:])) | |
2414 | col5=self.wrObj.writeData(name="P_Ch4",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[3,:])) |
|
2414 | col5=self.wrObj.writeData(name="P_Ch4",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[3,:])) | |
2415 | col6=self.wrObj.writeData(name="P_Ch5",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[4,:])) |
|
2415 | col6=self.wrObj.writeData(name="P_Ch5",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[4,:])) | |
2416 | col7=self.wrObj.writeData(name="P_Ch6",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[5,:])) |
|
2416 | col7=self.wrObj.writeData(name="P_Ch6",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[5,:])) | |
2417 | col8=self.wrObj.writeData(name="P_Ch7",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[6,:])) |
|
2417 | col8=self.wrObj.writeData(name="P_Ch7",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[6,:])) | |
2418 | col9=self.wrObj.writeData(name="P_Ch8",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[7,:])) |
|
2418 | col9=self.wrObj.writeData(name="P_Ch8",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[7,:])) | |
2419 | #n=numpy.arange((100)) |
|
2419 | #n=numpy.arange((100)) | |
2420 | n=self.dataOut.data_spc[6,:] |
|
2420 | n=self.dataOut.data_spc[6,:] | |
2421 | a=self.wrObj.cFImage(n) |
|
2421 | a=self.wrObj.cFImage(n) | |
2422 | b=self.wrObj.Ctable(col1,col2,col3,col4,col5,col6,col7,col8,col9) |
|
2422 | b=self.wrObj.Ctable(col1,col2,col3,col4,col5,col6,col7,col8,col9) | |
2423 | self.wrObj.CFile(a,b) |
|
2423 | self.wrObj.CFile(a,b) | |
2424 | self.wrObj.wFile(filename) |
|
2424 | self.wrObj.wFile(filename) | |
2425 | return 1 |
|
2425 | return 1 | |
2426 |
|
2426 | |||
2427 | class FITS: |
|
2427 | class FITS: | |
2428 |
|
2428 | |||
2429 | name=None |
|
2429 | name=None | |
2430 | format=None |
|
2430 | format=None | |
2431 | array =None |
|
2431 | array =None | |
2432 | data =None |
|
2432 | data =None | |
2433 | thdulist=None |
|
2433 | thdulist=None | |
2434 |
|
2434 | |||
2435 | def __init__(self): |
|
2435 | def __init__(self): | |
2436 |
|
2436 | |||
2437 | pass |
|
2437 | pass | |
2438 |
|
2438 | |||
2439 | def setColF(self,name,format,array): |
|
2439 | def setColF(self,name,format,array): | |
2440 | self.name=name |
|
2440 | self.name=name | |
2441 | self.format=format |
|
2441 | self.format=format | |
2442 | self.array=array |
|
2442 | self.array=array | |
2443 | a1=numpy.array([self.array],dtype=numpy.float32) |
|
2443 | a1=numpy.array([self.array],dtype=numpy.float32) | |
2444 | self.col1 = pyfits.Column(name=self.name, format=self.format, array=a1) |
|
2444 | self.col1 = pyfits.Column(name=self.name, format=self.format, array=a1) | |
2445 | return self.col1 |
|
2445 | return self.col1 | |
2446 |
|
2446 | |||
2447 | # def setColP(self,name,format,data): |
|
2447 | # def setColP(self,name,format,data): | |
2448 | # self.name=name |
|
2448 | # self.name=name | |
2449 | # self.format=format |
|
2449 | # self.format=format | |
2450 | # self.data=data |
|
2450 | # self.data=data | |
2451 | # a2=numpy.array([self.data],dtype=numpy.float32) |
|
2451 | # a2=numpy.array([self.data],dtype=numpy.float32) | |
2452 | # self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2) |
|
2452 | # self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2) | |
2453 | # return self.col2 |
|
2453 | # return self.col2 | |
2454 |
|
2454 | |||
2455 | def writeHeader(self,): |
|
2455 | def writeHeader(self,): | |
2456 | pass |
|
2456 | pass | |
2457 |
|
2457 | |||
2458 | def writeData(self,name,format,data): |
|
2458 | def writeData(self,name,format,data): | |
2459 | self.name=name |
|
2459 | self.name=name | |
2460 | self.format=format |
|
2460 | self.format=format | |
2461 | self.data=data |
|
2461 | self.data=data | |
2462 | a2=numpy.array([self.data],dtype=numpy.float32) |
|
2462 | a2=numpy.array([self.data],dtype=numpy.float32) | |
2463 | self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2) |
|
2463 | self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2) | |
2464 | return self.col2 |
|
2464 | return self.col2 | |
2465 |
|
2465 | |||
2466 | def cFImage(self,n): |
|
2466 | def cFImage(self,n): | |
2467 | self.hdu= pyfits.PrimaryHDU(n) |
|
2467 | self.hdu= pyfits.PrimaryHDU(n) | |
2468 | return self.hdu |
|
2468 | return self.hdu | |
2469 |
|
2469 | |||
2470 | def Ctable(self,col1,col2,col3,col4,col5,col6,col7,col8,col9): |
|
2470 | def Ctable(self,col1,col2,col3,col4,col5,col6,col7,col8,col9): | |
2471 | self.cols=pyfits.ColDefs( [col1,col2,col3,col4,col5,col6,col7,col8,col9]) |
|
2471 | self.cols=pyfits.ColDefs( [col1,col2,col3,col4,col5,col6,col7,col8,col9]) | |
2472 | self.tbhdu = pyfits.new_table(self.cols) |
|
2472 | self.tbhdu = pyfits.new_table(self.cols) | |
2473 | return self.tbhdu |
|
2473 | return self.tbhdu | |
2474 |
|
2474 | |||
2475 | def CFile(self,hdu,tbhdu): |
|
2475 | def CFile(self,hdu,tbhdu): | |
2476 | self.thdulist=pyfits.HDUList([hdu,tbhdu]) |
|
2476 | self.thdulist=pyfits.HDUList([hdu,tbhdu]) | |
2477 |
|
2477 | |||
2478 | def wFile(self,filename): |
|
2478 | def wFile(self,filename): | |
2479 | self.thdulist.writeto(filename) No newline at end of file |
|
2479 | self.thdulist.writeto(filename) |
@@ -1,227 +1,364 | |||||
1 | import numpy |
|
1 | import numpy | |
2 | import datetime |
|
2 | import datetime | |
3 | from graphics.figure import * |
|
3 | from graphics.figure import * | |
4 |
|
4 | |||
|
5 | class RTIPlot(Figure): | |||
|
6 | ||||
|
7 | __isConfig = None | |||
|
8 | __nsubplots = None | |||
|
9 | ||||
|
10 | WIDTHPROF = None | |||
|
11 | HEIGHTPROF = None | |||
|
12 | ||||
|
13 | def __init__(self): | |||
|
14 | ||||
|
15 | self.__timerange = 30*60 | |||
|
16 | self.__isConfig = False | |||
|
17 | self.__nsubplots = 1 | |||
|
18 | ||||
|
19 | self.WIDTH = 800 | |||
|
20 | self.HEIGHT = 400 | |||
|
21 | self.WIDTHPROF = 120 | |||
|
22 | self.HEIGHTPROF = 0 | |||
|
23 | ||||
|
24 | def getSubplots(self): | |||
|
25 | ||||
|
26 | ncol = 1 | |||
|
27 | nrow = self.nplots | |||
|
28 | ||||
|
29 | return nrow, ncol | |||
|
30 | ||||
|
31 | def setup(self, idfigure, nplots, wintitle, showprofile=True): | |||
|
32 | ||||
|
33 | self.__showprofile = showprofile | |||
|
34 | self.nplots = nplots | |||
|
35 | ||||
|
36 | ncolspan = 1 | |||
|
37 | colspan = 1 | |||
|
38 | if showprofile: | |||
|
39 | ncolspan = 7 | |||
|
40 | colspan = 6 | |||
|
41 | self.__nsubplots = 2 | |||
|
42 | self.WIDTH += self.WIDTHPROF | |||
|
43 | self.HEIGHT += self.HEIGHTPROF | |||
|
44 | ||||
|
45 | self.createFigure(idfigure, wintitle) | |||
|
46 | ||||
|
47 | nrow, ncol = self.getSubplots() | |||
|
48 | ||||
|
49 | counter = 0 | |||
|
50 | for y in range(nrow): | |||
|
51 | for x in range(ncol): | |||
|
52 | ||||
|
53 | if counter >= self.nplots: | |||
|
54 | break | |||
|
55 | ||||
|
56 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |||
|
57 | ||||
|
58 | if showprofile: | |||
|
59 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |||
|
60 | ||||
|
61 | counter += 1 | |||
|
62 | ||||
|
63 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', | |||
|
64 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): | |||
|
65 | ||||
|
66 | """ | |||
|
67 | ||||
|
68 | Input: | |||
|
69 | dataOut : | |||
|
70 | idfigure : | |||
|
71 | wintitle : | |||
|
72 | channelList : | |||
|
73 | showProfile : | |||
|
74 | xmin : None, | |||
|
75 | xmax : None, | |||
|
76 | ymin : None, | |||
|
77 | ymax : None, | |||
|
78 | zmin : None, | |||
|
79 | zmax : None | |||
|
80 | """ | |||
|
81 | ||||
|
82 | if channelList == None: | |||
|
83 | channelIndexList = dataOut.channelIndexList | |||
|
84 | else: | |||
|
85 | channelIndexList = [] | |||
|
86 | for channel in channelList: | |||
|
87 | if channel not in dataOut.channelList: | |||
|
88 | raise ValueError, "Channel %d is not in dataOut.channelList" | |||
|
89 | channelIndexList.append(channel) | |||
|
90 | ||||
|
91 | x = dataOut.getDatatime() | |||
|
92 | y = dataOut.getHeiRange() | |||
|
93 | z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:]) | |||
|
94 | avg = numpy.average(z, axis=1) | |||
|
95 | ||||
|
96 | noise = dataOut.getNoise() | |||
|
97 | ||||
|
98 | if not self.__isConfig: | |||
|
99 | ||||
|
100 | nplots = len(channelIndexList) | |||
|
101 | ||||
|
102 | self.setup(idfigure=idfigure, | |||
|
103 | nplots=nplots, | |||
|
104 | wintitle=wintitle, | |||
|
105 | showprofile=showprofile) | |||
|
106 | ||||
|
107 | if xmin == None: xmin = numpy.min(x) | |||
|
108 | if xmax == None: xmax = xmin + self.__timerange | |||
|
109 | if ymin == None: ymin = numpy.nanmin(y) | |||
|
110 | if ymax == None: ymax = numpy.nanmax(y) | |||
|
111 | if zmin == None: zmin = numpy.nanmin(avg)*0.9 | |||
|
112 | if zmax == None: zmax = numpy.nanmax(avg)*0.9 | |||
|
113 | ||||
|
114 | self.__isConfig = True | |||
|
115 | ||||
|
116 | thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime) | |||
|
117 | title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |||
|
118 | xlabel = "Velocity (m/s)" | |||
|
119 | ylabel = "Range (Km)" | |||
|
120 | ||||
|
121 | self.setWinTitle(title) | |||
|
122 | ||||
|
123 | for i in range(self.nplots): | |||
|
124 | title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noise[i]) | |||
|
125 | axes = self.axesList[i*self.__nsubplots] | |||
|
126 | z = avg[i].reshape((1,-1)) | |||
|
127 | axes.pcolor(x, y, z, | |||
|
128 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |||
|
129 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, | |||
|
130 | ticksize=9, cblabel='') | |||
|
131 | ||||
|
132 | if self.__showprofile: | |||
|
133 | axes = self.axesList[i*self.__nsubplots +1] | |||
|
134 | axes.pline(avg[i], y, | |||
|
135 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |||
|
136 | xlabel='dB', ylabel='', title='', | |||
|
137 | ytick_visible=False, | |||
|
138 | grid='x') | |||
|
139 | ||||
|
140 | self.draw() | |||
|
141 | ||||
5 | class SpectraPlot(Figure): |
|
142 | class SpectraPlot(Figure): | |
6 |
|
143 | |||
7 | __isConfig = None |
|
144 | __isConfig = None | |
8 | __nsubplots = None |
|
145 | __nsubplots = None | |
9 |
|
146 | |||
10 | WIDTHPROF = None |
|
147 | WIDTHPROF = None | |
11 | HEIGHTPROF = None |
|
148 | HEIGHTPROF = None | |
12 |
|
149 | |||
13 | def __init__(self): |
|
150 | def __init__(self): | |
14 |
|
151 | |||
15 | self.__isConfig = False |
|
152 | self.__isConfig = False | |
16 | self.__nsubplots = 1 |
|
153 | self.__nsubplots = 1 | |
17 |
|
154 | |||
18 | self.WIDTH = 300 |
|
155 | self.WIDTH = 300 | |
19 | self.HEIGHT = 400 |
|
156 | self.HEIGHT = 400 | |
20 | self.WIDTHPROF = 120 |
|
157 | self.WIDTHPROF = 120 | |
21 | self.HEIGHTPROF = 0 |
|
158 | self.HEIGHTPROF = 0 | |
22 |
|
159 | |||
23 | def getSubplots(self): |
|
160 | def getSubplots(self): | |
24 |
|
161 | |||
25 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
162 | ncol = int(numpy.sqrt(self.nplots)+0.9) | |
26 | nrow = int(self.nplots*1./ncol + 0.9) |
|
163 | nrow = int(self.nplots*1./ncol + 0.9) | |
27 |
|
164 | |||
28 | return nrow, ncol |
|
165 | return nrow, ncol | |
29 |
|
166 | |||
30 | def setup(self, idfigure, nplots, wintitle, showprofile=True): |
|
167 | def setup(self, idfigure, nplots, wintitle, showprofile=True): | |
31 |
|
168 | |||
32 | self.__showprofile = showprofile |
|
169 | self.__showprofile = showprofile | |
33 | self.nplots = nplots |
|
170 | self.nplots = nplots | |
34 |
|
171 | |||
35 | ncolspan = 1 |
|
172 | ncolspan = 1 | |
36 | colspan = 1 |
|
173 | colspan = 1 | |
37 | if showprofile: |
|
174 | if showprofile: | |
38 | ncolspan = 3 |
|
175 | ncolspan = 3 | |
39 | colspan = 2 |
|
176 | colspan = 2 | |
40 | self.__nsubplots = 2 |
|
177 | self.__nsubplots = 2 | |
41 | self.WIDTH += self.WIDTHPROF |
|
178 | self.WIDTH += self.WIDTHPROF | |
42 | self.HEIGHT += self.HEIGHTPROF |
|
179 | self.HEIGHT += self.HEIGHTPROF | |
43 |
|
180 | |||
44 | self.createFigure(idfigure, wintitle) |
|
181 | self.createFigure(idfigure, wintitle) | |
45 |
|
182 | |||
46 | nrow, ncol = self.getSubplots() |
|
183 | nrow, ncol = self.getSubplots() | |
47 |
|
184 | |||
48 | counter = 0 |
|
185 | counter = 0 | |
49 | for y in range(nrow): |
|
186 | for y in range(nrow): | |
50 | for x in range(ncol): |
|
187 | for x in range(ncol): | |
51 |
|
188 | |||
52 | if counter >= self.nplots: |
|
189 | if counter >= self.nplots: | |
53 | break |
|
190 | break | |
54 |
|
191 | |||
55 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
192 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
56 |
|
193 | |||
57 | if showprofile: |
|
194 | if showprofile: | |
58 |
self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+ |
|
195 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
59 |
|
196 | |||
60 | counter += 1 |
|
197 | counter += 1 | |
61 |
|
198 | |||
62 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
199 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', | |
63 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): |
|
200 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): | |
64 |
|
201 | |||
65 | """ |
|
202 | """ | |
66 |
|
203 | |||
67 | Input: |
|
204 | Input: | |
68 | dataOut : |
|
205 | dataOut : | |
69 | idfigure : |
|
206 | idfigure : | |
70 | wintitle : |
|
207 | wintitle : | |
71 | channelList : |
|
208 | channelList : | |
72 | showProfile : |
|
209 | showProfile : | |
73 | xmin : None, |
|
210 | xmin : None, | |
74 | xmax : None, |
|
211 | xmax : None, | |
75 | ymin : None, |
|
212 | ymin : None, | |
76 | ymax : None, |
|
213 | ymax : None, | |
77 | zmin : None, |
|
214 | zmin : None, | |
78 | zmax : None |
|
215 | zmax : None | |
79 | """ |
|
216 | """ | |
80 |
|
217 | |||
81 | if channelList == None: |
|
218 | if channelList == None: | |
82 | channelIndexList = dataOut.channelIndexList |
|
219 | channelIndexList = dataOut.channelIndexList | |
83 | else: |
|
220 | else: | |
84 | channelIndexList = [] |
|
221 | channelIndexList = [] | |
85 | for channel in channelList: |
|
222 | for channel in channelList: | |
86 | if channel not in dataOut.channelList: |
|
223 | if channel not in dataOut.channelList: | |
87 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
224 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
88 | channelIndexList.append(channel) |
|
225 | channelIndexList.append(channel) | |
89 |
|
226 | |||
90 | x = dataOut.getVelRange(1) |
|
227 | x = dataOut.getVelRange(1) | |
91 |
y = dataOut. |
|
228 | y = dataOut.getHeiRange() | |
92 | z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:]) |
|
229 | z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:]) | |
93 | avg = numpy.average(z, axis=1) |
|
230 | avg = numpy.average(z, axis=1) | |
94 |
|
231 | |||
95 | noise = dataOut.getNoise() |
|
232 | noise = dataOut.getNoise() | |
96 |
|
233 | |||
97 | if not self.__isConfig: |
|
234 | if not self.__isConfig: | |
98 |
|
235 | |||
99 | nplots = len(channelIndexList) |
|
236 | nplots = len(channelIndexList) | |
100 |
|
237 | |||
101 | self.setup(idfigure=idfigure, |
|
238 | self.setup(idfigure=idfigure, | |
102 | nplots=nplots, |
|
239 | nplots=nplots, | |
103 | wintitle=wintitle, |
|
240 | wintitle=wintitle, | |
104 | showprofile=showprofile) |
|
241 | showprofile=showprofile) | |
105 |
|
242 | |||
106 | if xmin == None: xmin = numpy.nanmin(x) |
|
243 | if xmin == None: xmin = numpy.nanmin(x) | |
107 | if xmax == None: xmax = numpy.nanmax(x) |
|
244 | if xmax == None: xmax = numpy.nanmax(x) | |
108 | if ymin == None: ymin = numpy.nanmin(y) |
|
245 | if ymin == None: ymin = numpy.nanmin(y) | |
109 | if ymax == None: ymax = numpy.nanmax(y) |
|
246 | if ymax == None: ymax = numpy.nanmax(y) | |
110 | if zmin == None: zmin = numpy.nanmin(avg)*0.9 |
|
247 | if zmin == None: zmin = numpy.nanmin(avg)*0.9 | |
111 | if zmax == None: zmax = numpy.nanmax(avg)*0.9 |
|
248 | if zmax == None: zmax = numpy.nanmax(avg)*0.9 | |
112 |
|
249 | |||
113 | self.__isConfig = True |
|
250 | self.__isConfig = True | |
114 |
|
251 | |||
115 | thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime) |
|
252 | thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime) | |
116 | title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
253 | title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
117 | xlabel = "Velocity (m/s)" |
|
254 | xlabel = "Velocity (m/s)" | |
118 | ylabel = "Range (Km)" |
|
255 | ylabel = "Range (Km)" | |
119 |
|
256 | |||
120 | self.setWinTitle(title) |
|
257 | self.setWinTitle(title) | |
121 |
|
258 | |||
122 | for i in range(self.nplots): |
|
259 | for i in range(self.nplots): | |
123 | title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noise[i]) |
|
260 | title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noise[i]) | |
124 | axes = self.axesList[i*self.__nsubplots] |
|
261 | axes = self.axesList[i*self.__nsubplots] | |
125 | axes.pcolor(x, y, z[i,:,:], |
|
262 | axes.pcolor(x, y, z[i,:,:], | |
126 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
263 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
127 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
264 | xlabel=xlabel, ylabel=ylabel, title=title, | |
128 | ticksize=9, cblabel='') |
|
265 | ticksize=9, cblabel='') | |
129 |
|
266 | |||
130 | if self.__showprofile: |
|
267 | if self.__showprofile: | |
131 | axes = self.axesList[i*self.__nsubplots +1] |
|
268 | axes = self.axesList[i*self.__nsubplots +1] | |
132 | axes.pline(avg[i], y, |
|
269 | axes.pline(avg[i], y, | |
133 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
270 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |
134 | xlabel='dB', ylabel='', title='', |
|
271 | xlabel='dB', ylabel='', title='', | |
135 | ytick_visible=False, |
|
272 | ytick_visible=False, | |
136 | grid='x') |
|
273 | grid='x') | |
137 |
|
274 | |||
138 | self.draw() |
|
275 | self.draw() | |
139 |
|
276 | |||
140 | class Scope(Figure): |
|
277 | class Scope(Figure): | |
141 |
|
278 | |||
142 | __isConfig = None |
|
279 | __isConfig = None | |
143 |
|
280 | |||
144 | def __init__(self): |
|
281 | def __init__(self): | |
145 |
|
282 | |||
146 | self.__isConfig = False |
|
283 | self.__isConfig = False | |
147 | self.WIDTH = 600 |
|
284 | self.WIDTH = 600 | |
148 | self.HEIGHT = 200 |
|
285 | self.HEIGHT = 200 | |
149 |
|
286 | |||
150 | def getSubplots(self): |
|
287 | def getSubplots(self): | |
151 |
|
288 | |||
152 | nrow = self.nplots |
|
289 | nrow = self.nplots | |
153 | ncol = 3 |
|
290 | ncol = 3 | |
154 | return nrow, ncol |
|
291 | return nrow, ncol | |
155 |
|
292 | |||
156 | def setup(self, idfigure, nplots, wintitle): |
|
293 | def setup(self, idfigure, nplots, wintitle): | |
157 |
|
294 | |||
158 | self.createFigure(idfigure, wintitle) |
|
295 | self.createFigure(idfigure, wintitle) | |
159 |
|
296 | |||
160 | nrow,ncol = self.getSubplots() |
|
297 | nrow,ncol = self.getSubplots() | |
161 | colspan = 3 |
|
298 | colspan = 3 | |
162 | rowspan = 1 |
|
299 | rowspan = 1 | |
163 |
|
300 | |||
164 | for i in range(nplots): |
|
301 | for i in range(nplots): | |
165 | self.addAxes(nrow, ncol, i, 0, colspan, rowspan) |
|
302 | self.addAxes(nrow, ncol, i, 0, colspan, rowspan) | |
166 |
|
303 | |||
167 | self.nplots = nplots |
|
304 | self.nplots = nplots | |
168 |
|
305 | |||
169 | def run(self, dataOut, idfigure, wintitle="", channelList=None, |
|
306 | def run(self, dataOut, idfigure, wintitle="", channelList=None, | |
170 | xmin=None, xmax=None, ymin=None, ymax=None): |
|
307 | xmin=None, xmax=None, ymin=None, ymax=None): | |
171 |
|
308 | |||
172 | """ |
|
309 | """ | |
173 |
|
310 | |||
174 | Input: |
|
311 | Input: | |
175 | dataOut : |
|
312 | dataOut : | |
176 | idfigure : |
|
313 | idfigure : | |
177 | wintitle : |
|
314 | wintitle : | |
178 | channelList : |
|
315 | channelList : | |
179 | xmin : None, |
|
316 | xmin : None, | |
180 | xmax : None, |
|
317 | xmax : None, | |
181 | ymin : None, |
|
318 | ymin : None, | |
182 | ymax : None, |
|
319 | ymax : None, | |
183 | """ |
|
320 | """ | |
184 |
|
321 | |||
185 | if channelList == None: |
|
322 | if channelList == None: | |
186 | channelList = dataOut.channelList |
|
323 | channelList = dataOut.channelList | |
187 |
|
324 | |||
188 | x = dataOut.heightList |
|
325 | x = dataOut.heightList | |
189 | y = dataOut.data[channelList,:] * numpy.conjugate(dataOut.data[channelList,:]) |
|
326 | y = dataOut.data[channelList,:] * numpy.conjugate(dataOut.data[channelList,:]) | |
190 | y = y.real |
|
327 | y = y.real | |
191 |
|
328 | |||
192 | noise = dataOut.getNoise() |
|
329 | noise = dataOut.getNoise() | |
193 |
|
330 | |||
194 | if not self.__isConfig: |
|
331 | if not self.__isConfig: | |
195 | nplots = len(channelList) |
|
332 | nplots = len(channelList) | |
196 |
|
333 | |||
197 | self.setup(idfigure=idfigure, |
|
334 | self.setup(idfigure=idfigure, | |
198 | nplots=nplots, |
|
335 | nplots=nplots, | |
199 | wintitle=wintitle) |
|
336 | wintitle=wintitle) | |
200 |
|
337 | |||
201 | if xmin == None: xmin = numpy.nanmin(x) |
|
338 | if xmin == None: xmin = numpy.nanmin(x) | |
202 | if xmax == None: xmax = numpy.nanmax(x) |
|
339 | if xmax == None: xmax = numpy.nanmax(x) | |
203 | if ymin == None: ymin = numpy.nanmin(y) |
|
340 | if ymin == None: ymin = numpy.nanmin(y) | |
204 | if ymax == None: ymax = numpy.nanmax(y) |
|
341 | if ymax == None: ymax = numpy.nanmax(y) | |
205 |
|
342 | |||
206 | self.__isConfig = True |
|
343 | self.__isConfig = True | |
207 |
|
344 | |||
208 |
|
345 | |||
209 | thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime) |
|
346 | thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime) | |
210 | title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
347 | title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
211 | xlabel = "Range (Km)" |
|
348 | xlabel = "Range (Km)" | |
212 | ylabel = "Intensity" |
|
349 | ylabel = "Intensity" | |
213 |
|
350 | |||
214 | self.setWinTitle(title) |
|
351 | self.setWinTitle(title) | |
215 |
|
352 | |||
216 | for i in range(len(self.axesList)): |
|
353 | for i in range(len(self.axesList)): | |
217 | title = "Channel %d: %4.2fdB" %(i, noise[i]) |
|
354 | title = "Channel %d: %4.2fdB" %(i, noise[i]) | |
218 | axes = self.axesList[i] |
|
355 | axes = self.axesList[i] | |
219 | ychannel = y[i,:] |
|
356 | ychannel = y[i,:] | |
220 | axes.pline(x, ychannel, |
|
357 | axes.pline(x, ychannel, | |
221 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
358 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |
222 | xlabel=xlabel, ylabel=ylabel, title=title) |
|
359 | xlabel=xlabel, ylabel=ylabel, title=title) | |
223 |
|
360 | |||
224 | self.draw() |
|
361 | self.draw() | |
225 |
|
362 | |||
226 |
|
363 | |||
227 | No newline at end of file |
|
364 |
@@ -1,836 +1,836 | |||||
1 | ''' |
|
1 | ''' | |
2 |
|
2 | |||
3 | $Author: dsuarez $ |
|
3 | $Author: dsuarez $ | |
4 | $Id: Processor.py 1 2012-11-12 18:56:07Z dsuarez $ |
|
4 | $Id: Processor.py 1 2012-11-12 18:56:07Z dsuarez $ | |
5 | ''' |
|
5 | ''' | |
6 | import os |
|
6 | import os | |
7 | import numpy |
|
7 | import numpy | |
8 | import datetime |
|
8 | import datetime | |
9 | import time |
|
9 | import time | |
10 |
|
10 | |||
11 | from jrodata import * |
|
11 | from jrodata import * | |
12 | from jrodataIO import * |
|
12 | from jrodataIO import * | |
13 | from jroplot import * |
|
13 | from jroplot import * | |
14 |
|
14 | |||
15 | class ProcessingUnit: |
|
15 | class ProcessingUnit: | |
16 |
|
16 | |||
17 | """ |
|
17 | """ | |
18 | Esta es la clase base para el procesamiento de datos. |
|
18 | Esta es la clase base para el procesamiento de datos. | |
19 |
|
19 | |||
20 | Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser: |
|
20 | Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser: | |
21 | - Metodos internos (callMethod) |
|
21 | - Metodos internos (callMethod) | |
22 | - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos |
|
22 | - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos | |
23 | tienen que ser agreagados con el metodo "add". |
|
23 | tienen que ser agreagados con el metodo "add". | |
24 |
|
24 | |||
25 | """ |
|
25 | """ | |
26 | # objeto de datos de entrada (Voltage, Spectra o Correlation) |
|
26 | # objeto de datos de entrada (Voltage, Spectra o Correlation) | |
27 | dataIn = None |
|
27 | dataIn = None | |
28 |
|
28 | |||
29 | # objeto de datos de entrada (Voltage, Spectra o Correlation) |
|
29 | # objeto de datos de entrada (Voltage, Spectra o Correlation) | |
30 | dataOut = None |
|
30 | dataOut = None | |
31 |
|
31 | |||
32 |
|
32 | |||
33 | objectDict = None |
|
33 | objectDict = None | |
34 |
|
34 | |||
35 | def __init__(self): |
|
35 | def __init__(self): | |
36 |
|
36 | |||
37 | self.objectDict = {} |
|
37 | self.objectDict = {} | |
38 |
|
38 | |||
39 | def init(self): |
|
39 | def init(self): | |
40 |
|
40 | |||
41 | raise ValueError, "Not implemented" |
|
41 | raise ValueError, "Not implemented" | |
42 |
|
42 | |||
43 | def addOperation(self, object, objId): |
|
43 | def addOperation(self, object, objId): | |
44 |
|
44 | |||
45 | """ |
|
45 | """ | |
46 | Agrega el objeto "object" a la lista de objetos "self.objectList" y retorna el |
|
46 | Agrega el objeto "object" a la lista de objetos "self.objectList" y retorna el | |
47 | identificador asociado a este objeto. |
|
47 | identificador asociado a este objeto. | |
48 |
|
48 | |||
49 | Input: |
|
49 | Input: | |
50 |
|
50 | |||
51 | object : objeto de la clase "Operation" |
|
51 | object : objeto de la clase "Operation" | |
52 |
|
52 | |||
53 | Return: |
|
53 | Return: | |
54 |
|
54 | |||
55 | objId : identificador del objeto, necesario para ejecutar la operacion |
|
55 | objId : identificador del objeto, necesario para ejecutar la operacion | |
56 | """ |
|
56 | """ | |
57 |
|
57 | |||
58 | self.objectDict[objId] = object |
|
58 | self.objectDict[objId] = object | |
59 |
|
59 | |||
60 | return objId |
|
60 | return objId | |
61 |
|
61 | |||
62 | def operation(self, **kwargs): |
|
62 | def operation(self, **kwargs): | |
63 |
|
63 | |||
64 | """ |
|
64 | """ | |
65 | Operacion directa sobre la data (dataout.data). Es necesario actualizar los valores de los |
|
65 | Operacion directa sobre la data (dataout.data). Es necesario actualizar los valores de los | |
66 | atributos del objeto dataOut |
|
66 | atributos del objeto dataOut | |
67 |
|
67 | |||
68 | Input: |
|
68 | Input: | |
69 |
|
69 | |||
70 | **kwargs : Diccionario de argumentos de la funcion a ejecutar |
|
70 | **kwargs : Diccionario de argumentos de la funcion a ejecutar | |
71 | """ |
|
71 | """ | |
72 |
|
72 | |||
73 | raise ValueError, "ImplementedError" |
|
73 | raise ValueError, "ImplementedError" | |
74 |
|
74 | |||
75 | def callMethod(self, name, **kwargs): |
|
75 | def callMethod(self, name, **kwargs): | |
76 |
|
76 | |||
77 | """ |
|
77 | """ | |
78 | Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase. |
|
78 | Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase. | |
79 |
|
79 | |||
80 | Input: |
|
80 | Input: | |
81 | name : nombre del metodo a ejecutar |
|
81 | name : nombre del metodo a ejecutar | |
82 |
|
82 | |||
83 | **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. |
|
83 | **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. | |
84 |
|
84 | |||
85 | """ |
|
85 | """ | |
86 | if name != 'run': |
|
86 | if name != 'run': | |
87 |
|
87 | |||
88 | if name == 'init' and self.dataIn.isEmpty(): |
|
88 | if name == 'init' and self.dataIn.isEmpty(): | |
89 | self.dataOut.flagNoData = True |
|
89 | self.dataOut.flagNoData = True | |
90 | return False |
|
90 | return False | |
91 |
|
91 | |||
92 | if name != 'init' and self.dataOut.isEmpty(): |
|
92 | if name != 'init' and self.dataOut.isEmpty(): | |
93 | return False |
|
93 | return False | |
94 |
|
94 | |||
95 | methodToCall = getattr(self, name) |
|
95 | methodToCall = getattr(self, name) | |
96 |
|
96 | |||
97 | methodToCall(**kwargs) |
|
97 | methodToCall(**kwargs) | |
98 |
|
98 | |||
99 | if name != 'run': |
|
99 | if name != 'run': | |
100 | return True |
|
100 | return True | |
101 |
|
101 | |||
102 | if self.dataOut.isEmpty(): |
|
102 | if self.dataOut.isEmpty(): | |
103 | return False |
|
103 | return False | |
104 |
|
104 | |||
105 | return True |
|
105 | return True | |
106 |
|
106 | |||
107 | def callObject(self, objId, **kwargs): |
|
107 | def callObject(self, objId, **kwargs): | |
108 |
|
108 | |||
109 | """ |
|
109 | """ | |
110 | Ejecuta la operacion asociada al identificador del objeto "objId" |
|
110 | Ejecuta la operacion asociada al identificador del objeto "objId" | |
111 |
|
111 | |||
112 | Input: |
|
112 | Input: | |
113 |
|
113 | |||
114 | objId : identificador del objeto a ejecutar |
|
114 | objId : identificador del objeto a ejecutar | |
115 |
|
115 | |||
116 | **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. |
|
116 | **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. | |
117 |
|
117 | |||
118 | Return: |
|
118 | Return: | |
119 |
|
119 | |||
120 | None |
|
120 | None | |
121 | """ |
|
121 | """ | |
122 |
|
122 | |||
123 | if self.dataOut.isEmpty(): |
|
123 | if self.dataOut.isEmpty(): | |
124 | return False |
|
124 | return False | |
125 |
|
125 | |||
126 | object = self.objectDict[objId] |
|
126 | object = self.objectDict[objId] | |
127 |
|
127 | |||
128 | object.run(self.dataOut, **kwargs) |
|
128 | object.run(self.dataOut, **kwargs) | |
129 |
|
129 | |||
130 | return True |
|
130 | return True | |
131 |
|
131 | |||
132 | def call(self, operationConf, **kwargs): |
|
132 | def call(self, operationConf, **kwargs): | |
133 |
|
133 | |||
134 | """ |
|
134 | """ | |
135 | Return True si ejecuta la operacion "operationConf.name" con los |
|
135 | Return True si ejecuta la operacion "operationConf.name" con los | |
136 | argumentos "**kwargs". False si la operacion no se ha ejecutado. |
|
136 | argumentos "**kwargs". False si la operacion no se ha ejecutado. | |
137 | La operacion puede ser de dos tipos: |
|
137 | La operacion puede ser de dos tipos: | |
138 |
|
138 | |||
139 | 1. Un metodo propio de esta clase: |
|
139 | 1. Un metodo propio de esta clase: | |
140 |
|
140 | |||
141 | operation.type = "self" |
|
141 | operation.type = "self" | |
142 |
|
142 | |||
143 | 2. El metodo "run" de un objeto del tipo Operation o de un derivado de ella: |
|
143 | 2. El metodo "run" de un objeto del tipo Operation o de un derivado de ella: | |
144 | operation.type = "other". |
|
144 | operation.type = "other". | |
145 |
|
145 | |||
146 | Este objeto de tipo Operation debe de haber sido agregado antes con el metodo: |
|
146 | Este objeto de tipo Operation debe de haber sido agregado antes con el metodo: | |
147 | "addOperation" e identificado con el operation.id |
|
147 | "addOperation" e identificado con el operation.id | |
148 |
|
148 | |||
149 |
|
149 | |||
150 | con el id de la operacion. |
|
150 | con el id de la operacion. | |
151 |
|
151 | |||
152 | Input: |
|
152 | Input: | |
153 |
|
153 | |||
154 | Operation : Objeto del tipo operacion con los atributos: name, type y id. |
|
154 | Operation : Objeto del tipo operacion con los atributos: name, type y id. | |
155 |
|
155 | |||
156 | """ |
|
156 | """ | |
157 |
|
157 | |||
158 | if operationConf.type == 'self': |
|
158 | if operationConf.type == 'self': | |
159 | sts = self.callMethod(operationConf.name, **kwargs) |
|
159 | sts = self.callMethod(operationConf.name, **kwargs) | |
160 |
|
160 | |||
161 | if operationConf.type == 'other': |
|
161 | if operationConf.type == 'other': | |
162 | sts = self.callObject(operationConf.id, **kwargs) |
|
162 | sts = self.callObject(operationConf.id, **kwargs) | |
163 |
|
163 | |||
164 | return sts |
|
164 | return sts | |
165 |
|
165 | |||
166 | def setInput(self, dataIn): |
|
166 | def setInput(self, dataIn): | |
167 |
|
167 | |||
168 | self.dataIn = dataIn |
|
168 | self.dataIn = dataIn | |
169 |
|
169 | |||
170 | def getOutput(self): |
|
170 | def getOutput(self): | |
171 |
|
171 | |||
172 | return self.dataOut |
|
172 | return self.dataOut | |
173 |
|
173 | |||
174 | class Operation(): |
|
174 | class Operation(): | |
175 |
|
175 | |||
176 | """ |
|
176 | """ | |
177 | Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit |
|
177 | Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit | |
178 | y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de |
|
178 | y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de | |
179 | acumulacion dentro de esta clase |
|
179 | acumulacion dentro de esta clase | |
180 |
|
180 | |||
181 | Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer) |
|
181 | Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer) | |
182 |
|
182 | |||
183 | """ |
|
183 | """ | |
184 |
|
184 | |||
185 | __buffer = None |
|
185 | __buffer = None | |
186 | __isConfig = False |
|
186 | __isConfig = False | |
187 |
|
187 | |||
188 | def __init__(self): |
|
188 | def __init__(self): | |
189 |
|
189 | |||
190 | pass |
|
190 | pass | |
191 |
|
191 | |||
192 | def run(self, dataIn, **kwargs): |
|
192 | def run(self, dataIn, **kwargs): | |
193 |
|
193 | |||
194 | """ |
|
194 | """ | |
195 | Realiza las operaciones necesarias sobre la dataIn.data y actualiza los atributos del objeto dataIn. |
|
195 | Realiza las operaciones necesarias sobre la dataIn.data y actualiza los atributos del objeto dataIn. | |
196 |
|
196 | |||
197 | Input: |
|
197 | Input: | |
198 |
|
198 | |||
199 | dataIn : objeto del tipo JROData |
|
199 | dataIn : objeto del tipo JROData | |
200 |
|
200 | |||
201 | Return: |
|
201 | Return: | |
202 |
|
202 | |||
203 | None |
|
203 | None | |
204 |
|
204 | |||
205 | Affected: |
|
205 | Affected: | |
206 | __buffer : buffer de recepcion de datos. |
|
206 | __buffer : buffer de recepcion de datos. | |
207 |
|
207 | |||
208 | """ |
|
208 | """ | |
209 |
|
209 | |||
210 | raise ValueError, "ImplementedError" |
|
210 | raise ValueError, "ImplementedError" | |
211 |
|
211 | |||
212 | class VoltageProc(ProcessingUnit): |
|
212 | class VoltageProc(ProcessingUnit): | |
213 |
|
213 | |||
214 |
|
214 | |||
215 | def __init__(self): |
|
215 | def __init__(self): | |
216 |
|
216 | |||
217 | self.objectDict = {} |
|
217 | self.objectDict = {} | |
218 | self.dataOut = Voltage() |
|
218 | self.dataOut = Voltage() | |
219 |
|
219 | |||
220 | def init(self): |
|
220 | def init(self): | |
221 |
|
221 | |||
222 | self.dataOut.copy(self.dataIn) |
|
222 | self.dataOut.copy(self.dataIn) | |
223 | # No necesita copiar en cada init() los atributos de dataIn |
|
223 | # No necesita copiar en cada init() los atributos de dataIn | |
224 | # la copia deberia hacerse por cada nuevo bloque de datos |
|
224 | # la copia deberia hacerse por cada nuevo bloque de datos | |
225 |
|
225 | |||
226 | def selectChannels(self, channelList): |
|
226 | def selectChannels(self, channelList): | |
227 |
|
227 | |||
228 | channelIndexList = [] |
|
228 | channelIndexList = [] | |
229 |
|
229 | |||
230 | for channel in channelList: |
|
230 | for channel in channelList: | |
231 | index = self.dataOut.channelList.index(channel) |
|
231 | index = self.dataOut.channelList.index(channel) | |
232 | channelIndexList.append(index) |
|
232 | channelIndexList.append(index) | |
233 |
|
233 | |||
234 | self.selectChannelsByIndex(channelIndexList) |
|
234 | self.selectChannelsByIndex(channelIndexList) | |
235 |
|
235 | |||
236 | def selectChannelsByIndex(self, channelIndexList): |
|
236 | def selectChannelsByIndex(self, channelIndexList): | |
237 | """ |
|
237 | """ | |
238 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
238 | Selecciona un bloque de datos en base a canales segun el channelIndexList | |
239 |
|
239 | |||
240 | Input: |
|
240 | Input: | |
241 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
241 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] | |
242 |
|
242 | |||
243 | Affected: |
|
243 | Affected: | |
244 | self.dataOut.data |
|
244 | self.dataOut.data | |
245 | self.dataOut.channelIndexList |
|
245 | self.dataOut.channelIndexList | |
246 | self.dataOut.nChannels |
|
246 | self.dataOut.nChannels | |
247 | self.dataOut.m_ProcessingHeader.totalSpectra |
|
247 | self.dataOut.m_ProcessingHeader.totalSpectra | |
248 | self.dataOut.systemHeaderObj.numChannels |
|
248 | self.dataOut.systemHeaderObj.numChannels | |
249 | self.dataOut.m_ProcessingHeader.blockSize |
|
249 | self.dataOut.m_ProcessingHeader.blockSize | |
250 |
|
250 | |||
251 | Return: |
|
251 | Return: | |
252 | None |
|
252 | None | |
253 | """ |
|
253 | """ | |
254 |
|
254 | |||
255 | for channelIndex in channelIndexList: |
|
255 | for channelIndex in channelIndexList: | |
256 | if channelIndex not in self.dataOut.channelIndexList: |
|
256 | if channelIndex not in self.dataOut.channelIndexList: | |
257 | print channelIndexList |
|
257 | print channelIndexList | |
258 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex |
|
258 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex | |
259 |
|
259 | |||
260 | nChannels = len(channelIndexList) |
|
260 | nChannels = len(channelIndexList) | |
261 |
|
261 | |||
262 | data = self.dataOut.data[channelIndexList,:] |
|
262 | data = self.dataOut.data[channelIndexList,:] | |
263 |
|
263 | |||
264 | self.dataOut.data = data |
|
264 | self.dataOut.data = data | |
265 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
265 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] | |
266 | # self.dataOut.nChannels = nChannels |
|
266 | # self.dataOut.nChannels = nChannels | |
267 |
|
267 | |||
268 | return 1 |
|
268 | return 1 | |
269 |
|
269 | |||
270 | class CohInt(Operation): |
|
270 | class CohInt(Operation): | |
271 |
|
271 | |||
272 | __profIndex = 0 |
|
272 | __profIndex = 0 | |
273 | __withOverapping = False |
|
273 | __withOverapping = False | |
274 |
|
274 | |||
275 | __byTime = False |
|
275 | __byTime = False | |
276 | __initime = None |
|
276 | __initime = None | |
277 | __lastdatatime = None |
|
277 | __lastdatatime = None | |
278 | __integrationtime = None |
|
278 | __integrationtime = None | |
279 |
|
279 | |||
280 | __buffer = None |
|
280 | __buffer = None | |
281 |
|
281 | |||
282 | __dataReady = False |
|
282 | __dataReady = False | |
283 |
|
283 | |||
284 | n = None |
|
284 | n = None | |
285 |
|
285 | |||
286 |
|
286 | |||
287 | def __init__(self): |
|
287 | def __init__(self): | |
288 |
|
288 | |||
289 | self.__isConfig = False |
|
289 | self.__isConfig = False | |
290 |
|
290 | |||
291 | def setup(self, n=None, timeInterval=None, overlapping=False): |
|
291 | def setup(self, n=None, timeInterval=None, overlapping=False): | |
292 | """ |
|
292 | """ | |
293 | Set the parameters of the integration class. |
|
293 | Set the parameters of the integration class. | |
294 |
|
294 | |||
295 | Inputs: |
|
295 | Inputs: | |
296 |
|
296 | |||
297 | n : Number of coherent integrations |
|
297 | n : Number of coherent integrations | |
298 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
298 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work | |
299 | overlapping : |
|
299 | overlapping : | |
300 |
|
300 | |||
301 | """ |
|
301 | """ | |
302 |
|
302 | |||
303 | self.__initime = None |
|
303 | self.__initime = None | |
304 | self.__lastdatatime = 0 |
|
304 | self.__lastdatatime = 0 | |
305 | self.__buffer = None |
|
305 | self.__buffer = None | |
306 | self.__dataReady = False |
|
306 | self.__dataReady = False | |
307 |
|
307 | |||
308 |
|
308 | |||
309 | if n == None and timeInterval == None: |
|
309 | if n == None and timeInterval == None: | |
310 | raise ValueError, "n or timeInterval should be specified ..." |
|
310 | raise ValueError, "n or timeInterval should be specified ..." | |
311 |
|
311 | |||
312 | if n != None: |
|
312 | if n != None: | |
313 | self.n = n |
|
313 | self.n = n | |
314 | self.__byTime = False |
|
314 | self.__byTime = False | |
315 | else: |
|
315 | else: | |
316 | self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line |
|
316 | self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line | |
317 | self.n = 9999 |
|
317 | self.n = 9999 | |
318 | self.__byTime = True |
|
318 | self.__byTime = True | |
319 |
|
319 | |||
320 | if overlapping: |
|
320 | if overlapping: | |
321 | self.__withOverapping = True |
|
321 | self.__withOverapping = True | |
322 | self.__buffer = None |
|
322 | self.__buffer = None | |
323 | else: |
|
323 | else: | |
324 | self.__withOverapping = False |
|
324 | self.__withOverapping = False | |
325 | self.__buffer = 0 |
|
325 | self.__buffer = 0 | |
326 |
|
326 | |||
327 | self.__profIndex = 0 |
|
327 | self.__profIndex = 0 | |
328 |
|
328 | |||
329 | def putData(self, data): |
|
329 | def putData(self, data): | |
330 |
|
330 | |||
331 | """ |
|
331 | """ | |
332 | Add a profile to the __buffer and increase in one the __profileIndex |
|
332 | Add a profile to the __buffer and increase in one the __profileIndex | |
333 |
|
333 | |||
334 | """ |
|
334 | """ | |
335 |
|
335 | |||
336 | if not self.__withOverapping: |
|
336 | if not self.__withOverapping: | |
337 | self.__buffer += data.copy() |
|
337 | self.__buffer += data.copy() | |
338 | self.__profIndex += 1 |
|
338 | self.__profIndex += 1 | |
339 | return |
|
339 | return | |
340 |
|
340 | |||
341 | #Overlapping data |
|
341 | #Overlapping data | |
342 | nChannels, nHeis = data.shape |
|
342 | nChannels, nHeis = data.shape | |
343 | data = numpy.reshape(data, (1, nChannels, nHeis)) |
|
343 | data = numpy.reshape(data, (1, nChannels, nHeis)) | |
344 |
|
344 | |||
345 | #If the buffer is empty then it takes the data value |
|
345 | #If the buffer is empty then it takes the data value | |
346 | if self.__buffer == None: |
|
346 | if self.__buffer == None: | |
347 | self.__buffer = data |
|
347 | self.__buffer = data | |
348 | self.__profIndex += 1 |
|
348 | self.__profIndex += 1 | |
349 | return |
|
349 | return | |
350 |
|
350 | |||
351 | #If the buffer length is lower than n then stakcing the data value |
|
351 | #If the buffer length is lower than n then stakcing the data value | |
352 | if self.__profIndex < self.n: |
|
352 | if self.__profIndex < self.n: | |
353 | self.__buffer = numpy.vstack((self.__buffer, data)) |
|
353 | self.__buffer = numpy.vstack((self.__buffer, data)) | |
354 | self.__profIndex += 1 |
|
354 | self.__profIndex += 1 | |
355 | return |
|
355 | return | |
356 |
|
356 | |||
357 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
357 | #If the buffer length is equal to n then replacing the last buffer value with the data value | |
358 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) |
|
358 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) | |
359 | self.__buffer[self.n-1] = data |
|
359 | self.__buffer[self.n-1] = data | |
360 | self.__profIndex = self.n |
|
360 | self.__profIndex = self.n | |
361 | return |
|
361 | return | |
362 |
|
362 | |||
363 |
|
363 | |||
364 | def pushData(self): |
|
364 | def pushData(self): | |
365 | """ |
|
365 | """ | |
366 | Return the sum of the last profiles and the profiles used in the sum. |
|
366 | Return the sum of the last profiles and the profiles used in the sum. | |
367 |
|
367 | |||
368 | Affected: |
|
368 | Affected: | |
369 |
|
369 | |||
370 | self.__profileIndex |
|
370 | self.__profileIndex | |
371 |
|
371 | |||
372 | """ |
|
372 | """ | |
373 |
|
373 | |||
374 | if not self.__withOverapping: |
|
374 | if not self.__withOverapping: | |
375 | data = self.__buffer |
|
375 | data = self.__buffer | |
376 | n = self.__profIndex |
|
376 | n = self.__profIndex | |
377 |
|
377 | |||
378 | self.__buffer = 0 |
|
378 | self.__buffer = 0 | |
379 | self.__profIndex = 0 |
|
379 | self.__profIndex = 0 | |
380 |
|
380 | |||
381 | return data, n |
|
381 | return data, n | |
382 |
|
382 | |||
383 | #Integration with Overlapping |
|
383 | #Integration with Overlapping | |
384 | data = numpy.sum(self.__buffer, axis=0) |
|
384 | data = numpy.sum(self.__buffer, axis=0) | |
385 | n = self.__profIndex |
|
385 | n = self.__profIndex | |
386 |
|
386 | |||
387 | return data, n |
|
387 | return data, n | |
388 |
|
388 | |||
389 | def byProfiles(self, data): |
|
389 | def byProfiles(self, data): | |
390 |
|
390 | |||
391 | self.__dataReady = False |
|
391 | self.__dataReady = False | |
392 | avgdata = None |
|
392 | avgdata = None | |
393 | n = None |
|
393 | n = None | |
394 |
|
394 | |||
395 | self.putData(data) |
|
395 | self.putData(data) | |
396 |
|
396 | |||
397 | if self.__profIndex == self.n: |
|
397 | if self.__profIndex == self.n: | |
398 |
|
398 | |||
399 | avgdata, n = self.pushData() |
|
399 | avgdata, n = self.pushData() | |
400 | self.__dataReady = True |
|
400 | self.__dataReady = True | |
401 |
|
401 | |||
402 | return avgdata |
|
402 | return avgdata | |
403 |
|
403 | |||
404 | def byTime(self, data, datatime): |
|
404 | def byTime(self, data, datatime): | |
405 |
|
405 | |||
406 | self.__dataReady = False |
|
406 | self.__dataReady = False | |
407 | avgdata = None |
|
407 | avgdata = None | |
408 | n = None |
|
408 | n = None | |
409 |
|
409 | |||
410 | self.putData(data) |
|
410 | self.putData(data) | |
411 |
|
411 | |||
412 | if (datatime - self.__initime) >= self.__integrationtime: |
|
412 | if (datatime - self.__initime) >= self.__integrationtime: | |
413 | avgdata, n = self.pushData() |
|
413 | avgdata, n = self.pushData() | |
414 | self.n = n |
|
414 | self.n = n | |
415 | self.__dataReady = True |
|
415 | self.__dataReady = True | |
416 |
|
416 | |||
417 | return avgdata |
|
417 | return avgdata | |
418 |
|
418 | |||
419 | def integrate(self, data, datatime=None): |
|
419 | def integrate(self, data, datatime=None): | |
420 |
|
420 | |||
421 | if self.__initime == None: |
|
421 | if self.__initime == None: | |
422 | self.__initime = datatime |
|
422 | self.__initime = datatime | |
423 |
|
423 | |||
424 | if self.__byTime: |
|
424 | if self.__byTime: | |
425 | avgdata = self.byTime(data, datatime) |
|
425 | avgdata = self.byTime(data, datatime) | |
426 | else: |
|
426 | else: | |
427 | avgdata = self.byProfiles(data) |
|
427 | avgdata = self.byProfiles(data) | |
428 |
|
428 | |||
429 |
|
429 | |||
430 | self.__lastdatatime = datatime |
|
430 | self.__lastdatatime = datatime | |
431 |
|
431 | |||
432 | if avgdata == None: |
|
432 | if avgdata == None: | |
433 | return None, None |
|
433 | return None, None | |
434 |
|
434 | |||
435 | avgdatatime = self.__initime |
|
435 | avgdatatime = self.__initime | |
436 |
|
436 | |||
437 | deltatime = datatime -self.__lastdatatime |
|
437 | deltatime = datatime -self.__lastdatatime | |
438 |
|
438 | |||
439 | if not self.__withOverapping: |
|
439 | if not self.__withOverapping: | |
440 | self.__initime = datatime |
|
440 | self.__initime = datatime | |
441 | else: |
|
441 | else: | |
442 | self.__initime += deltatime |
|
442 | self.__initime += deltatime | |
443 |
|
443 | |||
444 | return avgdata, avgdatatime |
|
444 | return avgdata, avgdatatime | |
445 |
|
445 | |||
446 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False): |
|
446 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False): | |
447 |
|
447 | |||
448 | if not self.__isConfig: |
|
448 | if not self.__isConfig: | |
449 | self.setup(n, timeInterval, overlapping) |
|
449 | self.setup(n, timeInterval, overlapping) | |
450 | self.__isConfig = True |
|
450 | self.__isConfig = True | |
451 |
|
451 | |||
452 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) |
|
452 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) | |
453 |
|
453 | |||
454 | # dataOut.timeInterval *= n |
|
454 | # dataOut.timeInterval *= n | |
455 | dataOut.flagNoData = True |
|
455 | dataOut.flagNoData = True | |
456 |
|
456 | |||
457 | if self.__dataReady: |
|
457 | if self.__dataReady: | |
458 | dataOut.data = avgdata |
|
458 | dataOut.data = avgdata | |
459 | dataOut.nCohInt *= self.n |
|
459 | dataOut.nCohInt *= self.n | |
460 | dataOut.utctime = avgdatatime |
|
460 | dataOut.utctime = avgdatatime | |
461 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt |
|
461 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt | |
462 | dataOut.flagNoData = False |
|
462 | dataOut.flagNoData = False | |
463 |
|
463 | |||
464 |
|
464 | |||
465 | class SpectraProc(ProcessingUnit): |
|
465 | class SpectraProc(ProcessingUnit): | |
466 |
|
466 | |||
467 | def __init__(self): |
|
467 | def __init__(self): | |
468 |
|
468 | |||
469 | self.objectDict = {} |
|
469 | self.objectDict = {} | |
470 | self.buffer = None |
|
470 | self.buffer = None | |
471 | self.firstdatatime = None |
|
471 | self.firstdatatime = None | |
472 | self.profIndex = 0 |
|
472 | self.profIndex = 0 | |
473 | self.dataOut = Spectra() |
|
473 | self.dataOut = Spectra() | |
474 |
|
474 | |||
475 | def __updateObjFromInput(self): |
|
475 | def __updateObjFromInput(self): | |
476 |
|
476 | |||
477 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() |
|
477 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() | |
478 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() |
|
478 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() | |
479 | self.dataOut.channelList = self.dataIn.channelList |
|
479 | self.dataOut.channelList = self.dataIn.channelList | |
480 | self.dataOut.heightList = self.dataIn.heightList |
|
480 | self.dataOut.heightList = self.dataIn.heightList | |
481 | self.dataOut.dtype = self.dataIn.dtype |
|
481 | self.dataOut.dtype = self.dataIn.dtype | |
482 | self.dataOut.nHeights = self.dataIn.nHeights |
|
482 | # self.dataOut.nHeights = self.dataIn.nHeights | |
483 | # self.dataOut.nChannels = self.dataIn.nChannels |
|
483 | # self.dataOut.nChannels = self.dataIn.nChannels | |
484 | self.dataOut.nBaud = self.dataIn.nBaud |
|
484 | self.dataOut.nBaud = self.dataIn.nBaud | |
485 | self.dataOut.nCode = self.dataIn.nCode |
|
485 | self.dataOut.nCode = self.dataIn.nCode | |
486 | self.dataOut.code = self.dataIn.code |
|
486 | self.dataOut.code = self.dataIn.code | |
487 | self.dataOut.nProfiles = self.dataOut.nFFTPoints |
|
487 | self.dataOut.nProfiles = self.dataOut.nFFTPoints | |
488 | # self.dataOut.channelIndexList = self.dataIn.channelIndexList |
|
488 | # self.dataOut.channelIndexList = self.dataIn.channelIndexList | |
489 | self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock |
|
489 | self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock | |
490 | self.dataOut.utctime = self.firstdatatime |
|
490 | self.dataOut.utctime = self.firstdatatime | |
491 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada |
|
491 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada | |
492 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip |
|
492 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip | |
493 | self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT |
|
493 | self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT | |
494 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
494 | self.dataOut.nCohInt = self.dataIn.nCohInt | |
495 | self.dataOut.nIncohInt = 1 |
|
495 | self.dataOut.nIncohInt = 1 | |
496 | self.dataOut.ippSeconds = self.dataIn.ippSeconds |
|
496 | self.dataOut.ippSeconds = self.dataIn.ippSeconds | |
497 | self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints |
|
497 | self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints | |
498 |
|
498 | |||
499 | def __getFft(self): |
|
499 | def __getFft(self): | |
500 | """ |
|
500 | """ | |
501 | Convierte valores de Voltaje a Spectra |
|
501 | Convierte valores de Voltaje a Spectra | |
502 |
|
502 | |||
503 | Affected: |
|
503 | Affected: | |
504 | self.dataOut.data_spc |
|
504 | self.dataOut.data_spc | |
505 | self.dataOut.data_cspc |
|
505 | self.dataOut.data_cspc | |
506 | self.dataOut.data_dc |
|
506 | self.dataOut.data_dc | |
507 | self.dataOut.heightList |
|
507 | self.dataOut.heightList | |
508 | self.dataOut.m_BasicHeader |
|
508 | self.dataOut.m_BasicHeader | |
509 | self.dataOut.m_ProcessingHeader |
|
509 | self.dataOut.m_ProcessingHeader | |
510 | self.dataOut.radarControllerHeaderObj |
|
510 | self.dataOut.radarControllerHeaderObj | |
511 | self.dataOut.systemHeaderObj |
|
511 | self.dataOut.systemHeaderObj | |
512 | self.profIndex |
|
512 | self.profIndex | |
513 | self.buffer |
|
513 | self.buffer | |
514 | self.dataOut.flagNoData |
|
514 | self.dataOut.flagNoData | |
515 | self.dataOut.dtype |
|
515 | self.dataOut.dtype | |
516 | self.dataOut.nPairs |
|
516 | self.dataOut.nPairs | |
517 | self.dataOut.nChannels |
|
517 | self.dataOut.nChannels | |
518 | self.dataOut.nProfiles |
|
518 | self.dataOut.nProfiles | |
519 | self.dataOut.systemHeaderObj.numChannels |
|
519 | self.dataOut.systemHeaderObj.numChannels | |
520 | self.dataOut.m_ProcessingHeader.totalSpectra |
|
520 | self.dataOut.m_ProcessingHeader.totalSpectra | |
521 | self.dataOut.m_ProcessingHeader.profilesPerBlock |
|
521 | self.dataOut.m_ProcessingHeader.profilesPerBlock | |
522 | self.dataOut.m_ProcessingHeader.numHeights |
|
522 | self.dataOut.m_ProcessingHeader.numHeights | |
523 | self.dataOut.m_ProcessingHeader.spectraComb |
|
523 | self.dataOut.m_ProcessingHeader.spectraComb | |
524 | self.dataOut.m_ProcessingHeader.shif_fft |
|
524 | self.dataOut.m_ProcessingHeader.shif_fft | |
525 | """ |
|
525 | """ | |
526 | fft_volt = numpy.fft.fft(self.buffer,axis=1) |
|
526 | fft_volt = numpy.fft.fft(self.buffer,axis=1) | |
527 | dc = fft_volt[:,0,:] |
|
527 | dc = fft_volt[:,0,:] | |
528 |
|
528 | |||
529 | #calculo de self-spectra |
|
529 | #calculo de self-spectra | |
530 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) |
|
530 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) | |
531 | spc = fft_volt * numpy.conjugate(fft_volt) |
|
531 | spc = fft_volt * numpy.conjugate(fft_volt) | |
532 | spc = spc.real |
|
532 | spc = spc.real | |
533 |
|
533 | |||
534 | blocksize = 0 |
|
534 | blocksize = 0 | |
535 | blocksize += dc.size |
|
535 | blocksize += dc.size | |
536 | blocksize += spc.size |
|
536 | blocksize += spc.size | |
537 |
|
537 | |||
538 | cspc = None |
|
538 | cspc = None | |
539 | pairIndex = 0 |
|
539 | pairIndex = 0 | |
540 | if self.dataOut.pairsList != None: |
|
540 | if self.dataOut.pairsList != None: | |
541 | #calculo de cross-spectra |
|
541 | #calculo de cross-spectra | |
542 | cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex') |
|
542 | cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex') | |
543 | for pair in self.dataOut.pairsList: |
|
543 | for pair in self.dataOut.pairsList: | |
544 | cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])) |
|
544 | cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])) | |
545 | pairIndex += 1 |
|
545 | pairIndex += 1 | |
546 | blocksize += cspc.size |
|
546 | blocksize += cspc.size | |
547 |
|
547 | |||
548 | self.dataOut.data_spc = spc |
|
548 | self.dataOut.data_spc = spc | |
549 | self.dataOut.data_cspc = cspc |
|
549 | self.dataOut.data_cspc = cspc | |
550 | self.dataOut.data_dc = dc |
|
550 | self.dataOut.data_dc = dc | |
551 | self.dataOut.blockSize = blocksize |
|
551 | self.dataOut.blockSize = blocksize | |
552 |
|
552 | |||
553 | def init(self, nFFTPoints=None, pairsList=None): |
|
553 | def init(self, nFFTPoints=None, pairsList=None): | |
554 |
|
554 | |||
555 | if self.dataIn.type == "Spectra": |
|
555 | if self.dataIn.type == "Spectra": | |
556 | self.dataOut.copy(self.dataIn) |
|
556 | self.dataOut.copy(self.dataIn) | |
557 | return |
|
557 | return | |
558 |
|
558 | |||
559 | if self.dataIn.type == "Voltage": |
|
559 | if self.dataIn.type == "Voltage": | |
560 |
|
560 | |||
561 | if nFFTPoints == None: |
|
561 | if nFFTPoints == None: | |
562 | raise ValueError, "This SpectraProc.setup() need nFFTPoints input variable" |
|
562 | raise ValueError, "This SpectraProc.setup() need nFFTPoints input variable" | |
563 |
|
563 | |||
564 | if pairsList == None: |
|
564 | if pairsList == None: | |
565 | nPairs = 0 |
|
565 | nPairs = 0 | |
566 | else: |
|
566 | else: | |
567 | nPairs = len(pairsList) |
|
567 | nPairs = len(pairsList) | |
568 |
|
568 | |||
569 | self.dataOut.nFFTPoints = nFFTPoints |
|
569 | self.dataOut.nFFTPoints = nFFTPoints | |
570 | self.dataOut.pairsList = pairsList |
|
570 | self.dataOut.pairsList = pairsList | |
571 | self.dataOut.nPairs = nPairs |
|
571 | self.dataOut.nPairs = nPairs | |
572 |
|
572 | |||
573 | if self.buffer == None: |
|
573 | if self.buffer == None: | |
574 | self.buffer = numpy.zeros((self.dataIn.nChannels, |
|
574 | self.buffer = numpy.zeros((self.dataIn.nChannels, | |
575 | self.dataOut.nFFTPoints, |
|
575 | self.dataOut.nFFTPoints, | |
576 | self.dataIn.nHeights), |
|
576 | self.dataIn.nHeights), | |
577 | dtype='complex') |
|
577 | dtype='complex') | |
578 |
|
578 | |||
579 |
|
579 | |||
580 | self.buffer[:,self.profIndex,:] = self.dataIn.data |
|
580 | self.buffer[:,self.profIndex,:] = self.dataIn.data | |
581 | self.profIndex += 1 |
|
581 | self.profIndex += 1 | |
582 |
|
582 | |||
583 | if self.firstdatatime == None: |
|
583 | if self.firstdatatime == None: | |
584 | self.firstdatatime = self.dataIn.utctime |
|
584 | self.firstdatatime = self.dataIn.utctime | |
585 |
|
585 | |||
586 | if self.profIndex == self.dataOut.nFFTPoints: |
|
586 | if self.profIndex == self.dataOut.nFFTPoints: | |
587 | self.__updateObjFromInput() |
|
587 | self.__updateObjFromInput() | |
588 | self.__getFft() |
|
588 | self.__getFft() | |
589 |
|
589 | |||
590 | self.dataOut.flagNoData = False |
|
590 | self.dataOut.flagNoData = False | |
591 |
|
591 | |||
592 | self.buffer = None |
|
592 | self.buffer = None | |
593 | self.firstdatatime = None |
|
593 | self.firstdatatime = None | |
594 | self.profIndex = 0 |
|
594 | self.profIndex = 0 | |
595 |
|
595 | |||
596 | return |
|
596 | return | |
597 |
|
597 | |||
598 | raise ValuError, "The type object %s is not valid"%(self.dataIn.type) |
|
598 | raise ValuError, "The type object %s is not valid"%(self.dataIn.type) | |
599 |
|
599 | |||
600 | def selectChannels(self, channelList): |
|
600 | def selectChannels(self, channelList): | |
601 |
|
601 | |||
602 | channelIndexList = [] |
|
602 | channelIndexList = [] | |
603 |
|
603 | |||
604 | for channel in channelList: |
|
604 | for channel in channelList: | |
605 | index = self.dataOut.channelList.index(channel) |
|
605 | index = self.dataOut.channelList.index(channel) | |
606 | channelIndexList.append(index) |
|
606 | channelIndexList.append(index) | |
607 |
|
607 | |||
608 | self.selectChannelsByIndex(channelIndexList) |
|
608 | self.selectChannelsByIndex(channelIndexList) | |
609 |
|
609 | |||
610 | def selectChannelsByIndex(self, channelIndexList): |
|
610 | def selectChannelsByIndex(self, channelIndexList): | |
611 | """ |
|
611 | """ | |
612 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
612 | Selecciona un bloque de datos en base a canales segun el channelIndexList | |
613 |
|
613 | |||
614 | Input: |
|
614 | Input: | |
615 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
615 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] | |
616 |
|
616 | |||
617 | Affected: |
|
617 | Affected: | |
618 | self.dataOut.data_spc |
|
618 | self.dataOut.data_spc | |
619 | self.dataOut.channelIndexList |
|
619 | self.dataOut.channelIndexList | |
620 | self.dataOut.nChannels |
|
620 | self.dataOut.nChannels | |
621 |
|
621 | |||
622 | Return: |
|
622 | Return: | |
623 | None |
|
623 | None | |
624 | """ |
|
624 | """ | |
625 |
|
625 | |||
626 | for channelIndex in channelIndexList: |
|
626 | for channelIndex in channelIndexList: | |
627 | if channelIndex not in self.dataOut.channelIndexList: |
|
627 | if channelIndex not in self.dataOut.channelIndexList: | |
628 | print channelIndexList |
|
628 | print channelIndexList | |
629 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex |
|
629 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex | |
630 |
|
630 | |||
631 | nChannels = len(channelIndexList) |
|
631 | nChannels = len(channelIndexList) | |
632 |
|
632 | |||
633 | data_spc = self.dataOut.data_spc[channelIndexList,:] |
|
633 | data_spc = self.dataOut.data_spc[channelIndexList,:] | |
634 |
|
634 | |||
635 | self.dataOut.data_spc = data_spc |
|
635 | self.dataOut.data_spc = data_spc | |
636 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
636 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] | |
637 | # self.dataOut.nChannels = nChannels |
|
637 | # self.dataOut.nChannels = nChannels | |
638 |
|
638 | |||
639 | return 1 |
|
639 | return 1 | |
640 |
|
640 | |||
641 |
|
641 | |||
642 | class IncohInt(Operation): |
|
642 | class IncohInt(Operation): | |
643 |
|
643 | |||
644 |
|
644 | |||
645 | __profIndex = 0 |
|
645 | __profIndex = 0 | |
646 | __withOverapping = False |
|
646 | __withOverapping = False | |
647 |
|
647 | |||
648 | __byTime = False |
|
648 | __byTime = False | |
649 | __initime = None |
|
649 | __initime = None | |
650 | __lastdatatime = None |
|
650 | __lastdatatime = None | |
651 | __integrationtime = None |
|
651 | __integrationtime = None | |
652 |
|
652 | |||
653 | __buffer = None |
|
653 | __buffer = None | |
654 |
|
654 | |||
655 | __dataReady = False |
|
655 | __dataReady = False | |
656 |
|
656 | |||
657 | n = None |
|
657 | n = None | |
658 |
|
658 | |||
659 |
|
659 | |||
660 | def __init__(self): |
|
660 | def __init__(self): | |
661 |
|
661 | |||
662 | self.__isConfig = False |
|
662 | self.__isConfig = False | |
663 |
|
663 | |||
664 | def setup(self, n=None, timeInterval=None, overlapping=False): |
|
664 | def setup(self, n=None, timeInterval=None, overlapping=False): | |
665 | """ |
|
665 | """ | |
666 | Set the parameters of the integration class. |
|
666 | Set the parameters of the integration class. | |
667 |
|
667 | |||
668 | Inputs: |
|
668 | Inputs: | |
669 |
|
669 | |||
670 | n : Number of coherent integrations |
|
670 | n : Number of coherent integrations | |
671 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
671 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work | |
672 | overlapping : |
|
672 | overlapping : | |
673 |
|
673 | |||
674 | """ |
|
674 | """ | |
675 |
|
675 | |||
676 | self.__initime = None |
|
676 | self.__initime = None | |
677 | self.__lastdatatime = 0 |
|
677 | self.__lastdatatime = 0 | |
678 | self.__buffer = None |
|
678 | self.__buffer = None | |
679 | self.__dataReady = False |
|
679 | self.__dataReady = False | |
680 |
|
680 | |||
681 |
|
681 | |||
682 | if n == None and timeInterval == None: |
|
682 | if n == None and timeInterval == None: | |
683 | raise ValueError, "n or timeInterval should be specified ..." |
|
683 | raise ValueError, "n or timeInterval should be specified ..." | |
684 |
|
684 | |||
685 | if n != None: |
|
685 | if n != None: | |
686 | self.n = n |
|
686 | self.n = n | |
687 | self.__byTime = False |
|
687 | self.__byTime = False | |
688 | else: |
|
688 | else: | |
689 | self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line |
|
689 | self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line | |
690 | self.n = 9999 |
|
690 | self.n = 9999 | |
691 | self.__byTime = True |
|
691 | self.__byTime = True | |
692 |
|
692 | |||
693 | if overlapping: |
|
693 | if overlapping: | |
694 | self.__withOverapping = True |
|
694 | self.__withOverapping = True | |
695 | self.__buffer = None |
|
695 | self.__buffer = None | |
696 | else: |
|
696 | else: | |
697 | self.__withOverapping = False |
|
697 | self.__withOverapping = False | |
698 | self.__buffer = 0 |
|
698 | self.__buffer = 0 | |
699 |
|
699 | |||
700 | self.__profIndex = 0 |
|
700 | self.__profIndex = 0 | |
701 |
|
701 | |||
702 | def putData(self, data): |
|
702 | def putData(self, data): | |
703 |
|
703 | |||
704 | """ |
|
704 | """ | |
705 | Add a profile to the __buffer and increase in one the __profileIndex |
|
705 | Add a profile to the __buffer and increase in one the __profileIndex | |
706 |
|
706 | |||
707 | """ |
|
707 | """ | |
708 |
|
708 | |||
709 | if not self.__withOverapping: |
|
709 | if not self.__withOverapping: | |
710 | self.__buffer += data.copy() |
|
710 | self.__buffer += data.copy() | |
711 | self.__profIndex += 1 |
|
711 | self.__profIndex += 1 | |
712 | return |
|
712 | return | |
713 |
|
713 | |||
714 | #Overlapping data |
|
714 | #Overlapping data | |
715 | nChannels, nFFTPoints, nHeis = data.shape |
|
715 | nChannels, nFFTPoints, nHeis = data.shape | |
716 | data = numpy.reshape(data, (1, nChannels, nFFTPoints, nHeis)) |
|
716 | data = numpy.reshape(data, (1, nChannels, nFFTPoints, nHeis)) | |
717 |
|
717 | |||
718 | #If the buffer is empty then it takes the data value |
|
718 | #If the buffer is empty then it takes the data value | |
719 | if self.__buffer == None: |
|
719 | if self.__buffer == None: | |
720 | self.__buffer = data |
|
720 | self.__buffer = data | |
721 | self.__profIndex += 1 |
|
721 | self.__profIndex += 1 | |
722 | return |
|
722 | return | |
723 |
|
723 | |||
724 | #If the buffer length is lower than n then stakcing the data value |
|
724 | #If the buffer length is lower than n then stakcing the data value | |
725 | if self.__profIndex < self.n: |
|
725 | if self.__profIndex < self.n: | |
726 | self.__buffer = numpy.vstack((self.__buffer, data)) |
|
726 | self.__buffer = numpy.vstack((self.__buffer, data)) | |
727 | self.__profIndex += 1 |
|
727 | self.__profIndex += 1 | |
728 | return |
|
728 | return | |
729 |
|
729 | |||
730 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
730 | #If the buffer length is equal to n then replacing the last buffer value with the data value | |
731 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) |
|
731 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) | |
732 | self.__buffer[self.n-1] = data |
|
732 | self.__buffer[self.n-1] = data | |
733 | self.__profIndex = self.n |
|
733 | self.__profIndex = self.n | |
734 | return |
|
734 | return | |
735 |
|
735 | |||
736 |
|
736 | |||
737 | def pushData(self): |
|
737 | def pushData(self): | |
738 | """ |
|
738 | """ | |
739 | Return the sum of the last profiles and the profiles used in the sum. |
|
739 | Return the sum of the last profiles and the profiles used in the sum. | |
740 |
|
740 | |||
741 | Affected: |
|
741 | Affected: | |
742 |
|
742 | |||
743 | self.__profileIndex |
|
743 | self.__profileIndex | |
744 |
|
744 | |||
745 | """ |
|
745 | """ | |
746 |
|
746 | |||
747 | if not self.__withOverapping: |
|
747 | if not self.__withOverapping: | |
748 | data = self.__buffer |
|
748 | data = self.__buffer | |
749 | n = self.__profIndex |
|
749 | n = self.__profIndex | |
750 |
|
750 | |||
751 | self.__buffer = 0 |
|
751 | self.__buffer = 0 | |
752 | self.__profIndex = 0 |
|
752 | self.__profIndex = 0 | |
753 |
|
753 | |||
754 | return data, n |
|
754 | return data, n | |
755 |
|
755 | |||
756 | #Integration with Overlapping |
|
756 | #Integration with Overlapping | |
757 | data = numpy.sum(self.__buffer, axis=0) |
|
757 | data = numpy.sum(self.__buffer, axis=0) | |
758 | n = self.__profIndex |
|
758 | n = self.__profIndex | |
759 |
|
759 | |||
760 | return data, n |
|
760 | return data, n | |
761 |
|
761 | |||
762 | def byProfiles(self, data): |
|
762 | def byProfiles(self, data): | |
763 |
|
763 | |||
764 | self.__dataReady = False |
|
764 | self.__dataReady = False | |
765 | avgdata = None |
|
765 | avgdata = None | |
766 | n = None |
|
766 | n = None | |
767 |
|
767 | |||
768 | self.putData(data) |
|
768 | self.putData(data) | |
769 |
|
769 | |||
770 | if self.__profIndex == self.n: |
|
770 | if self.__profIndex == self.n: | |
771 |
|
771 | |||
772 | avgdata, n = self.pushData() |
|
772 | avgdata, n = self.pushData() | |
773 | self.__dataReady = True |
|
773 | self.__dataReady = True | |
774 |
|
774 | |||
775 | return avgdata |
|
775 | return avgdata | |
776 |
|
776 | |||
777 | def byTime(self, data, datatime): |
|
777 | def byTime(self, data, datatime): | |
778 |
|
778 | |||
779 | self.__dataReady = False |
|
779 | self.__dataReady = False | |
780 | avgdata = None |
|
780 | avgdata = None | |
781 | n = None |
|
781 | n = None | |
782 |
|
782 | |||
783 | self.putData(data) |
|
783 | self.putData(data) | |
784 |
|
784 | |||
785 | if (datatime - self.__initime) >= self.__integrationtime: |
|
785 | if (datatime - self.__initime) >= self.__integrationtime: | |
786 | avgdata, n = self.pushData() |
|
786 | avgdata, n = self.pushData() | |
787 | self.n = n |
|
787 | self.n = n | |
788 | self.__dataReady = True |
|
788 | self.__dataReady = True | |
789 |
|
789 | |||
790 | return avgdata |
|
790 | return avgdata | |
791 |
|
791 | |||
792 | def integrate(self, data, datatime=None): |
|
792 | def integrate(self, data, datatime=None): | |
793 |
|
793 | |||
794 | if self.__initime == None: |
|
794 | if self.__initime == None: | |
795 | self.__initime = datatime |
|
795 | self.__initime = datatime | |
796 |
|
796 | |||
797 | if self.__byTime: |
|
797 | if self.__byTime: | |
798 | avgdata = self.byTime(data, datatime) |
|
798 | avgdata = self.byTime(data, datatime) | |
799 | else: |
|
799 | else: | |
800 | avgdata = self.byProfiles(data) |
|
800 | avgdata = self.byProfiles(data) | |
801 |
|
801 | |||
802 |
|
802 | |||
803 | self.__lastdatatime = datatime |
|
803 | self.__lastdatatime = datatime | |
804 |
|
804 | |||
805 | if avgdata == None: |
|
805 | if avgdata == None: | |
806 | return None, None |
|
806 | return None, None | |
807 |
|
807 | |||
808 | avgdatatime = self.__initime |
|
808 | avgdatatime = self.__initime | |
809 |
|
809 | |||
810 | deltatime = datatime -self.__lastdatatime |
|
810 | deltatime = datatime -self.__lastdatatime | |
811 |
|
811 | |||
812 | if not self.__withOverapping: |
|
812 | if not self.__withOverapping: | |
813 | self.__initime = datatime |
|
813 | self.__initime = datatime | |
814 | else: |
|
814 | else: | |
815 | self.__initime += deltatime |
|
815 | self.__initime += deltatime | |
816 |
|
816 | |||
817 | return avgdata, avgdatatime |
|
817 | return avgdata, avgdatatime | |
818 |
|
818 | |||
819 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False): |
|
819 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False): | |
820 |
|
820 | |||
821 | if not self.__isConfig: |
|
821 | if not self.__isConfig: | |
822 | self.setup(n, timeInterval, overlapping) |
|
822 | self.setup(n, timeInterval, overlapping) | |
823 | self.__isConfig = True |
|
823 | self.__isConfig = True | |
824 |
|
824 | |||
825 | avgdata, avgdatatime = self.integrate(dataOut.data_spc, dataOut.utctime) |
|
825 | avgdata, avgdatatime = self.integrate(dataOut.data_spc, dataOut.utctime) | |
826 |
|
826 | |||
827 | # dataOut.timeInterval *= n |
|
827 | # dataOut.timeInterval *= n | |
828 | dataOut.flagNoData = True |
|
828 | dataOut.flagNoData = True | |
829 |
|
829 | |||
830 | if self.__dataReady: |
|
830 | if self.__dataReady: | |
831 | dataOut.data_spc = avgdata |
|
831 | dataOut.data_spc = avgdata | |
832 | dataOut.nIncohInt *= self.n |
|
832 | dataOut.nIncohInt *= self.n | |
833 | dataOut.utctime = avgdatatime |
|
833 | dataOut.utctime = avgdatatime | |
834 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints |
|
834 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints | |
835 | dataOut.flagNoData = False |
|
835 | dataOut.flagNoData = False | |
836 | No newline at end of file |
|
836 |
General Comments 0
You need to be logged in to leave comments.
Login now