@@ -1,710 +1,719 | |||||
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 | value = self.value | |||
|
42 | ||||
41 | if self.format == 'list': |
|
43 | if self.format == 'list': | |
42 |
strList = |
|
44 | strList = value.split(',') | |
43 | return strList |
|
45 | return strList | |
44 |
|
46 | |||
45 | if self.format == 'intlist': |
|
47 | if self.format == 'intlist': | |
46 |
strList = |
|
48 | strList = value.split(',') | |
47 | intList = [int(x) for x in strList] |
|
49 | intList = [int(x) for x in strList] | |
48 | return intList |
|
50 | return intList | |
49 |
|
51 | |||
50 | if self.format == 'floatlist': |
|
52 | if self.format == 'floatlist': | |
51 |
strList = |
|
53 | strList = value.split(',') | |
52 | floatList = [float(x) for x in strList] |
|
54 | floatList = [float(x) for x in strList] | |
53 | return floatList |
|
55 | return floatList | |
54 |
|
56 | |||
55 | if self.format == 'date': |
|
57 | if self.format == 'date': | |
56 |
strList = |
|
58 | strList = value.split('/') | |
57 | intList = [int(x) for x in strList] |
|
59 | intList = [int(x) for x in strList] | |
58 | date = datetime.date(intList[0], intList[1], intList[2]) |
|
60 | date = datetime.date(intList[0], intList[1], intList[2]) | |
59 | return date |
|
61 | return date | |
60 |
|
62 | |||
61 | if self.format == 'time': |
|
63 | if self.format == 'time': | |
62 |
strList = |
|
64 | strList = value.split(':') | |
63 | intList = [int(x) for x in strList] |
|
65 | intList = [int(x) for x in strList] | |
64 | time = datetime.time(intList[0], intList[1], intList[2]) |
|
66 | time = datetime.time(intList[0], intList[1], intList[2]) | |
65 | return time |
|
67 | return time | |
66 |
|
|
68 | ||
|
69 | if self.format == 'bool': | |||
|
70 | value = int(value) | |||
|
71 | ||||
67 | func = eval(self.format) |
|
72 | func = eval(self.format) | |
68 |
|
|
73 | ||
69 |
return func( |
|
74 | return func(value) | |
70 |
|
75 | |||
71 | def setup(self, id, name, value, format='str'): |
|
76 | def setup(self, id, name, value, format='str'): | |
72 |
|
77 | |||
73 | self.id = id |
|
78 | self.id = id | |
74 | self.name = name |
|
79 | self.name = name | |
75 | self.value = str(value) |
|
80 | self.value = str(value) | |
76 | self.format = format |
|
81 | self.format = format | |
77 |
|
82 | |||
78 | def makeXml(self, opElement): |
|
83 | def makeXml(self, opElement): | |
79 |
|
84 | |||
80 | parmElement = SubElement(opElement, self.ELEMENTNAME) |
|
85 | parmElement = SubElement(opElement, self.ELEMENTNAME) | |
81 | parmElement.set('id', str(self.id)) |
|
86 | parmElement.set('id', str(self.id)) | |
82 | parmElement.set('name', self.name) |
|
87 | parmElement.set('name', self.name) | |
83 | parmElement.set('value', self.value) |
|
88 | parmElement.set('value', self.value) | |
84 | parmElement.set('format', self.format) |
|
89 | parmElement.set('format', self.format) | |
85 |
|
90 | |||
86 | def readXml(self, parmElement): |
|
91 | def readXml(self, parmElement): | |
87 |
|
92 | |||
88 | self.id = parmElement.get('id') |
|
93 | self.id = parmElement.get('id') | |
89 | self.name = parmElement.get('name') |
|
94 | self.name = parmElement.get('name') | |
90 | self.value = parmElement.get('value') |
|
95 | self.value = parmElement.get('value') | |
91 | self.format = parmElement.get('format') |
|
96 | self.format = parmElement.get('format') | |
92 |
|
97 | |||
93 | def printattr(self): |
|
98 | def printattr(self): | |
94 |
|
99 | |||
95 | print "Parameter[%s]: name = %s, value = %s, format = %s" %(self.id, self.name, self.value, self.format) |
|
100 | print "Parameter[%s]: name = %s, value = %s, format = %s" %(self.id, self.name, self.value, self.format) | |
96 |
|
101 | |||
97 | class OperationConf(): |
|
102 | class OperationConf(): | |
98 |
|
103 | |||
99 | id = None |
|
104 | id = None | |
100 | name = None |
|
105 | name = None | |
101 | priority = None |
|
106 | priority = None | |
102 | type = None |
|
107 | type = None | |
103 |
|
108 | |||
104 | parmConfObjList = [] |
|
109 | parmConfObjList = [] | |
105 |
|
110 | |||
106 | ELEMENTNAME = 'Operation' |
|
111 | ELEMENTNAME = 'Operation' | |
107 |
|
112 | |||
108 | def __init__(self): |
|
113 | def __init__(self): | |
109 |
|
114 | |||
110 | id = 0 |
|
115 | id = 0 | |
111 | name = None |
|
116 | name = None | |
112 | priority = None |
|
117 | priority = None | |
113 | type = 'self' |
|
118 | type = 'self' | |
114 |
|
119 | |||
115 |
|
120 | |||
116 | def __getNewId(self): |
|
121 | def __getNewId(self): | |
117 |
|
122 | |||
118 | return int(self.id)*10 + len(self.parmConfObjList) + 1 |
|
123 | return int(self.id)*10 + len(self.parmConfObjList) + 1 | |
119 |
|
124 | |||
120 | def getElementName(self): |
|
125 | def getElementName(self): | |
121 |
|
126 | |||
122 | return self.ELEMENTNAME |
|
127 | return self.ELEMENTNAME | |
123 |
|
128 | |||
124 | def getParameterObjList(self): |
|
129 | def getParameterObjList(self): | |
125 |
|
130 | |||
126 | return self.parmConfObjList |
|
131 | return self.parmConfObjList | |
127 |
|
132 | |||
128 | def setup(self, id, name, priority, type): |
|
133 | def setup(self, id, name, priority, type): | |
129 |
|
134 | |||
130 | self.id = id |
|
135 | self.id = id | |
131 | self.name = name |
|
136 | self.name = name | |
132 | self.type = type |
|
137 | self.type = type | |
133 | self.priority = priority |
|
138 | self.priority = priority | |
134 |
|
139 | |||
135 | self.parmConfObjList = [] |
|
140 | self.parmConfObjList = [] | |
136 |
|
141 | |||
137 | def addParameter(self, name, value, format='str'): |
|
142 | def addParameter(self, name, value, format='str'): | |
138 |
|
143 | |||
139 | id = self.__getNewId() |
|
144 | id = self.__getNewId() | |
140 |
|
145 | |||
141 | parmConfObj = ParameterConf() |
|
146 | parmConfObj = ParameterConf() | |
142 | parmConfObj.setup(id, name, value, format) |
|
147 | parmConfObj.setup(id, name, value, format) | |
143 |
|
148 | |||
144 | self.parmConfObjList.append(parmConfObj) |
|
149 | self.parmConfObjList.append(parmConfObj) | |
145 |
|
150 | |||
146 | return parmConfObj |
|
151 | return parmConfObj | |
147 |
|
152 | |||
148 | def makeXml(self, upElement): |
|
153 | def makeXml(self, upElement): | |
149 |
|
154 | |||
150 | opElement = SubElement(upElement, self.ELEMENTNAME) |
|
155 | opElement = SubElement(upElement, self.ELEMENTNAME) | |
151 | opElement.set('id', str(self.id)) |
|
156 | opElement.set('id', str(self.id)) | |
152 | opElement.set('name', self.name) |
|
157 | opElement.set('name', self.name) | |
153 | opElement.set('type', self.type) |
|
158 | opElement.set('type', self.type) | |
154 | opElement.set('priority', str(self.priority)) |
|
159 | opElement.set('priority', str(self.priority)) | |
155 |
|
160 | |||
156 | for parmConfObj in self.parmConfObjList: |
|
161 | for parmConfObj in self.parmConfObjList: | |
157 | parmConfObj.makeXml(opElement) |
|
162 | parmConfObj.makeXml(opElement) | |
158 |
|
163 | |||
159 | def readXml(self, opElement): |
|
164 | def readXml(self, opElement): | |
160 |
|
165 | |||
161 | self.id = opElement.get('id') |
|
166 | self.id = opElement.get('id') | |
162 | self.name = opElement.get('name') |
|
167 | self.name = opElement.get('name') | |
163 | self.type = opElement.get('type') |
|
168 | self.type = opElement.get('type') | |
164 | self.priority = opElement.get('priority') |
|
169 | self.priority = opElement.get('priority') | |
165 |
|
170 | |||
166 | self.parmConfObjList = [] |
|
171 | self.parmConfObjList = [] | |
167 |
|
172 | |||
168 | parmElementList = opElement.getiterator(ParameterConf().getElementName()) |
|
173 | parmElementList = opElement.getiterator(ParameterConf().getElementName()) | |
169 |
|
174 | |||
170 | for parmElement in parmElementList: |
|
175 | for parmElement in parmElementList: | |
171 | parmConfObj = ParameterConf() |
|
176 | parmConfObj = ParameterConf() | |
172 | parmConfObj.readXml(parmElement) |
|
177 | parmConfObj.readXml(parmElement) | |
173 | self.parmConfObjList.append(parmConfObj) |
|
178 | self.parmConfObjList.append(parmConfObj) | |
174 |
|
179 | |||
175 | def printattr(self): |
|
180 | def printattr(self): | |
176 |
|
181 | |||
177 | print "%s[%s]: name = %s, type = %s, priority = %s" %(self.ELEMENTNAME, |
|
182 | print "%s[%s]: name = %s, type = %s, priority = %s" %(self.ELEMENTNAME, | |
178 | self.id, |
|
183 | self.id, | |
179 | self.name, |
|
184 | self.name, | |
180 | self.type, |
|
185 | self.type, | |
181 | self.priority) |
|
186 | self.priority) | |
182 |
|
187 | |||
183 | for parmConfObj in self.parmConfObjList: |
|
188 | for parmConfObj in self.parmConfObjList: | |
184 | parmConfObj.printattr() |
|
189 | parmConfObj.printattr() | |
185 |
|
190 | |||
186 | def createObject(self): |
|
191 | def createObject(self): | |
187 |
|
192 | |||
188 | if self.type == 'self': |
|
193 | if self.type == 'self': | |
189 | raise ValueError, "This operation type cannot be created" |
|
194 | raise ValueError, "This operation type cannot be created" | |
190 |
|
195 | |||
191 | if self.type == 'other': |
|
196 | if self.type == 'other': | |
192 | className = eval(self.name) |
|
197 | className = eval(self.name) | |
193 | opObj = className() |
|
198 | opObj = className() | |
194 |
|
199 | |||
195 | return opObj |
|
200 | return opObj | |
196 |
|
201 | |||
197 | class ProcUnitConf(): |
|
202 | class ProcUnitConf(): | |
198 |
|
203 | |||
199 | id = None |
|
204 | id = None | |
200 | name = None |
|
205 | name = None | |
201 | datatype = None |
|
206 | datatype = None | |
202 | inputId = None |
|
207 | inputId = None | |
203 |
|
208 | |||
204 | opConfObjList = [] |
|
209 | opConfObjList = [] | |
205 |
|
210 | |||
206 | procUnitObj = None |
|
211 | procUnitObj = None | |
207 | opObjList = [] |
|
212 | opObjList = [] | |
208 |
|
213 | |||
209 | ELEMENTNAME = 'ProcUnit' |
|
214 | ELEMENTNAME = 'ProcUnit' | |
210 |
|
215 | |||
211 | def __init__(self): |
|
216 | def __init__(self): | |
212 |
|
217 | |||
213 | self.id = None |
|
218 | self.id = None | |
214 | self.datatype = None |
|
219 | self.datatype = None | |
215 | self.name = None |
|
220 | self.name = None | |
216 | self.inputId = None |
|
221 | self.inputId = None | |
217 |
|
222 | |||
218 | self.opConfObjList = [] |
|
223 | self.opConfObjList = [] | |
219 |
|
224 | |||
220 | self.procUnitObj = None |
|
225 | self.procUnitObj = None | |
221 | self.opObjDict = {} |
|
226 | self.opObjDict = {} | |
222 |
|
227 | |||
223 | def __getPriority(self): |
|
228 | def __getPriority(self): | |
224 |
|
229 | |||
225 | return len(self.opConfObjList)+1 |
|
230 | return len(self.opConfObjList)+1 | |
226 |
|
231 | |||
227 | def __getNewId(self): |
|
232 | def __getNewId(self): | |
228 |
|
233 | |||
229 | return int(self.id)*10 + len(self.opConfObjList) + 1 |
|
234 | return int(self.id)*10 + len(self.opConfObjList) + 1 | |
230 |
|
235 | |||
231 | def getElementName(self): |
|
236 | def getElementName(self): | |
232 |
|
237 | |||
233 | return self.ELEMENTNAME |
|
238 | return self.ELEMENTNAME | |
234 |
|
239 | |||
235 | def getId(self): |
|
240 | def getId(self): | |
236 |
|
241 | |||
237 | return str(self.id) |
|
242 | return str(self.id) | |
238 |
|
243 | |||
239 | def getInputId(self): |
|
244 | def getInputId(self): | |
240 |
|
245 | |||
241 | return str(self.inputId) |
|
246 | return str(self.inputId) | |
242 |
|
247 | |||
243 | def getOperationObjList(self): |
|
248 | def getOperationObjList(self): | |
244 |
|
249 | |||
245 | return self.opConfObjList |
|
250 | return self.opConfObjList | |
246 |
|
251 | |||
247 | def getProcUnitObj(self): |
|
252 | def getProcUnitObj(self): | |
248 |
|
253 | |||
249 | return self.procUnitObj |
|
254 | return self.procUnitObj | |
250 |
|
255 | |||
251 | def setup(self, id, name, datatype, inputId): |
|
256 | def setup(self, id, name, datatype, inputId): | |
252 |
|
257 | |||
253 | self.id = id |
|
258 | self.id = id | |
254 | self.name = name |
|
259 | self.name = name | |
255 | self.datatype = datatype |
|
260 | self.datatype = datatype | |
256 | self.inputId = inputId |
|
261 | self.inputId = inputId | |
257 |
|
262 | |||
258 | self.opConfObjList = [] |
|
263 | self.opConfObjList = [] | |
259 |
|
264 | |||
260 | self.addOperation(name='init', optype='self') |
|
265 | self.addOperation(name='init', optype='self') | |
261 |
|
266 | |||
262 | def addParameter(self, **kwargs): |
|
267 | def addParameter(self, **kwargs): | |
263 |
|
268 | |||
264 | opObj = self.opConfObjList[0] |
|
269 | opObj = self.opConfObjList[0] | |
265 |
|
270 | |||
266 | opObj.addParameter(**kwargs) |
|
271 | opObj.addParameter(**kwargs) | |
267 |
|
272 | |||
268 | return opObj |
|
273 | return opObj | |
269 |
|
274 | |||
270 | def addOperation(self, name, optype='self'): |
|
275 | def addOperation(self, name, optype='self'): | |
271 |
|
276 | |||
272 | id = self.__getNewId() |
|
277 | id = self.__getNewId() | |
273 | priority = self.__getPriority() |
|
278 | priority = self.__getPriority() | |
274 |
|
279 | |||
275 | opConfObj = OperationConf() |
|
280 | opConfObj = OperationConf() | |
276 | opConfObj.setup(id, name=name, priority=priority, type=optype) |
|
281 | opConfObj.setup(id, name=name, priority=priority, type=optype) | |
277 |
|
282 | |||
278 | self.opConfObjList.append(opConfObj) |
|
283 | self.opConfObjList.append(opConfObj) | |
279 |
|
284 | |||
280 | return opConfObj |
|
285 | return opConfObj | |
281 |
|
286 | |||
282 | def makeXml(self, procUnitElement): |
|
287 | def makeXml(self, procUnitElement): | |
283 |
|
288 | |||
284 | upElement = SubElement(procUnitElement, self.ELEMENTNAME) |
|
289 | upElement = SubElement(procUnitElement, self.ELEMENTNAME) | |
285 | upElement.set('id', str(self.id)) |
|
290 | upElement.set('id', str(self.id)) | |
286 | upElement.set('name', self.name) |
|
291 | upElement.set('name', self.name) | |
287 | upElement.set('datatype', self.datatype) |
|
292 | upElement.set('datatype', self.datatype) | |
288 | upElement.set('inputId', str(self.inputId)) |
|
293 | upElement.set('inputId', str(self.inputId)) | |
289 |
|
294 | |||
290 | for opConfObj in self.opConfObjList: |
|
295 | for opConfObj in self.opConfObjList: | |
291 | opConfObj.makeXml(upElement) |
|
296 | opConfObj.makeXml(upElement) | |
292 |
|
297 | |||
293 | def readXml(self, upElement): |
|
298 | def readXml(self, upElement): | |
294 |
|
299 | |||
295 | self.id = upElement.get('id') |
|
300 | self.id = upElement.get('id') | |
296 | self.name = upElement.get('name') |
|
301 | self.name = upElement.get('name') | |
297 | self.datatype = upElement.get('datatype') |
|
302 | self.datatype = upElement.get('datatype') | |
298 | self.inputId = upElement.get('inputId') |
|
303 | self.inputId = upElement.get('inputId') | |
299 |
|
304 | |||
300 | self.opConfObjList = [] |
|
305 | self.opConfObjList = [] | |
301 |
|
306 | |||
302 | opElementList = upElement.getiterator(OperationConf().getElementName()) |
|
307 | opElementList = upElement.getiterator(OperationConf().getElementName()) | |
303 |
|
308 | |||
304 | for opElement in opElementList: |
|
309 | for opElement in opElementList: | |
305 | opConfObj = OperationConf() |
|
310 | opConfObj = OperationConf() | |
306 | opConfObj.readXml(opElement) |
|
311 | opConfObj.readXml(opElement) | |
307 | self.opConfObjList.append(opConfObj) |
|
312 | self.opConfObjList.append(opConfObj) | |
308 |
|
313 | |||
309 | def printattr(self): |
|
314 | def printattr(self): | |
310 |
|
315 | |||
311 | print "%s[%s]: name = %s, datatype = %s, inputId = %s" %(self.ELEMENTNAME, |
|
316 | print "%s[%s]: name = %s, datatype = %s, inputId = %s" %(self.ELEMENTNAME, | |
312 | self.id, |
|
317 | self.id, | |
313 | self.name, |
|
318 | self.name, | |
314 | self.datatype, |
|
319 | self.datatype, | |
315 | self.inputId) |
|
320 | self.inputId) | |
316 |
|
321 | |||
317 | for opConfObj in self.opConfObjList: |
|
322 | for opConfObj in self.opConfObjList: | |
318 | opConfObj.printattr() |
|
323 | opConfObj.printattr() | |
319 |
|
324 | |||
320 | def createObjects(self): |
|
325 | def createObjects(self): | |
321 |
|
326 | |||
322 | className = eval(self.name) |
|
327 | className = eval(self.name) | |
323 | procUnitObj = className() |
|
328 | procUnitObj = className() | |
324 |
|
329 | |||
325 | for opConfObj in self.opConfObjList: |
|
330 | for opConfObj in self.opConfObjList: | |
326 |
|
331 | |||
327 | if opConfObj.type == 'self': |
|
332 | if opConfObj.type == 'self': | |
328 | continue |
|
333 | continue | |
329 |
|
334 | |||
330 | opObj = opConfObj.createObject() |
|
335 | opObj = opConfObj.createObject() | |
331 |
|
336 | |||
332 | self.opObjDict[opConfObj.id] = opObj |
|
337 | self.opObjDict[opConfObj.id] = opObj | |
333 | procUnitObj.addOperation(opObj, opConfObj.id) |
|
338 | procUnitObj.addOperation(opObj, opConfObj.id) | |
334 |
|
339 | |||
335 | self.procUnitObj = procUnitObj |
|
340 | self.procUnitObj = procUnitObj | |
336 |
|
341 | |||
337 | return procUnitObj |
|
342 | return procUnitObj | |
338 |
|
343 | |||
339 | def run(self): |
|
344 | def run(self): | |
340 |
|
345 | |||
341 | finalSts = False |
|
346 | finalSts = False | |
342 |
|
347 | |||
343 | for opConfObj in self.opConfObjList: |
|
348 | for opConfObj in self.opConfObjList: | |
344 |
|
349 | |||
345 | kwargs = {} |
|
350 | kwargs = {} | |
346 | for parmConfObj in opConfObj.getParameterObjList(): |
|
351 | for parmConfObj in opConfObj.getParameterObjList(): | |
347 | kwargs[parmConfObj.name] = parmConfObj.getValue() |
|
352 | kwargs[parmConfObj.name] = parmConfObj.getValue() | |
348 |
|
353 | |||
349 | #print "\tRunning the '%s' operation with %s" %(opConfObj.name, opConfObj.id) |
|
354 | #print "\tRunning the '%s' operation with %s" %(opConfObj.name, opConfObj.id) | |
350 | sts = self.procUnitObj.call(opConfObj, **kwargs) |
|
355 | sts = self.procUnitObj.call(opConfObj, **kwargs) | |
351 | finalSts = finalSts or sts |
|
356 | finalSts = finalSts or sts | |
352 |
|
357 | |||
353 | return finalSts |
|
358 | return finalSts | |
354 |
|
359 | |||
355 | class ReadUnitConf(ProcUnitConf): |
|
360 | class ReadUnitConf(ProcUnitConf): | |
356 |
|
361 | |||
357 | path = None |
|
362 | path = None | |
358 | startDate = None |
|
363 | startDate = None | |
359 | endDate = None |
|
364 | endDate = None | |
360 | startTime = None |
|
365 | startTime = None | |
361 | endTime = None |
|
366 | endTime = None | |
362 | online = None |
|
|||
363 | expLabel = None |
|
|||
364 | delay = None |
|
|||
365 |
|
367 | |||
366 | ELEMENTNAME = 'ReadUnit' |
|
368 | ELEMENTNAME = 'ReadUnit' | |
367 |
|
369 | |||
368 | def __init__(self): |
|
370 | def __init__(self): | |
369 |
|
371 | |||
370 | self.id = None |
|
372 | self.id = None | |
371 | self.datatype = None |
|
373 | self.datatype = None | |
372 | self.name = None |
|
374 | self.name = None | |
373 | self.inputId = 0 |
|
375 | self.inputId = 0 | |
374 |
|
376 | |||
375 | self.opConfObjList = [] |
|
377 | self.opConfObjList = [] | |
376 | self.opObjList = [] |
|
378 | self.opObjList = [] | |
377 |
|
379 | |||
378 | def getElementName(self): |
|
380 | def getElementName(self): | |
379 |
|
381 | |||
380 | return self.ELEMENTNAME |
|
382 | return self.ELEMENTNAME | |
381 |
|
383 | |||
382 |
def setup(self, id, name, datatype, path, startDate, endDate, startTime, endTime, |
|
384 | def setup(self, id, name, datatype, path, startDate, endDate, startTime, endTime, **kwargs): | |
383 |
|
385 | |||
384 | self.id = id |
|
386 | self.id = id | |
385 | self.name = name |
|
387 | self.name = name | |
386 | self.datatype = datatype |
|
388 | self.datatype = datatype | |
387 |
|
389 | |||
388 | self.path = path |
|
390 | self.path = path | |
389 | self.startDate = startDate |
|
391 | self.startDate = startDate | |
390 | self.endDate = endDate |
|
392 | self.endDate = endDate | |
391 | self.startTime = startTime |
|
393 | self.startTime = startTime | |
392 | self.endTime = endTime |
|
394 | self.endTime = endTime | |
393 | self.online = online |
|
|||
394 | self.expLabel = expLabel |
|
|||
395 | self.delay = delay |
|
|||
396 |
|
395 | |||
397 | self.addRunOperation() |
|
396 | self.addRunOperation(**kwargs) | |
398 |
|
397 | |||
399 | def addRunOperation(self): |
|
398 | def addRunOperation(self, **kwargs): | |
400 |
|
399 | |||
401 | opObj = self.addOperation(name = 'run', optype = 'self') |
|
400 | opObj = self.addOperation(name = 'run', optype = 'self') | |
402 |
|
401 | |||
403 | opObj.addParameter(name='path' , value=self.path, format='str') |
|
402 | opObj.addParameter(name='path' , value=self.path, format='str') | |
404 | opObj.addParameter(name='startDate' , value=self.startDate, format='date') |
|
403 | opObj.addParameter(name='startDate' , value=self.startDate, format='date') | |
405 | opObj.addParameter(name='endDate' , value=self.endDate, format='date') |
|
404 | opObj.addParameter(name='endDate' , value=self.endDate, format='date') | |
406 | opObj.addParameter(name='startTime' , value=self.startTime, format='time') |
|
405 | opObj.addParameter(name='startTime' , value=self.startTime, format='time') | |
407 | opObj.addParameter(name='endTime' , value=self.endTime, format='time') |
|
406 | opObj.addParameter(name='endTime' , value=self.endTime, format='time') | |
408 | opObj.addParameter(name='expLabel' , value=self.expLabel, format='str') |
|
407 | ||
409 | opObj.addParameter(name='online' , value=self.online, format='int') |
|
408 | for key, value in kwargs.items(): | |
410 |
opObj.addParameter(name= |
|
409 | opObj.addParameter(name=key, value=value, format=type(value).__name__) | |
411 |
|
|
410 | ||
412 | return opObj |
|
411 | return opObj | |
413 |
|
412 | |||
414 |
|
413 | |||
415 |
class |
|
414 | class Project(): | |
416 |
|
415 | |||
417 | id = None |
|
416 | id = None | |
418 | name = None |
|
417 | name = None | |
419 | description = None |
|
418 | description = None | |
420 | # readUnitConfObjList = None |
|
419 | # readUnitConfObjList = None | |
421 | procUnitConfObjDict = None |
|
420 | procUnitConfObjDict = None | |
422 |
|
421 | |||
423 |
ELEMENTNAME = ' |
|
422 | ELEMENTNAME = 'Project' | |
424 |
|
423 | |||
425 | def __init__(self): |
|
424 | def __init__(self): | |
426 |
|
425 | |||
427 | self.id = None |
|
426 | self.id = None | |
428 | self.name = None |
|
427 | self.name = None | |
429 | self.description = None |
|
428 | self.description = None | |
430 |
|
429 | |||
431 | # self.readUnitConfObjList = [] |
|
430 | # self.readUnitConfObjList = [] | |
432 | self.procUnitConfObjDict = {} |
|
431 | self.procUnitConfObjDict = {} | |
433 |
|
432 | |||
434 | def __getNewId(self): |
|
433 | def __getNewId(self): | |
435 |
|
434 | |||
436 | id = int(self.id)*10 + len(self.procUnitConfObjDict) + 1 |
|
435 | id = int(self.id)*10 + len(self.procUnitConfObjDict) + 1 | |
437 |
|
436 | |||
438 | return str(id) |
|
437 | return str(id) | |
439 |
|
438 | |||
440 | def getElementName(self): |
|
439 | def getElementName(self): | |
441 |
|
440 | |||
442 | return self.ELEMENTNAME |
|
441 | return self.ELEMENTNAME | |
443 |
|
442 | |||
444 | def setup(self, id, name, description): |
|
443 | def setup(self, id, name, description): | |
445 |
|
444 | |||
446 | self.id = id |
|
445 | self.id = id | |
447 | self.name = name |
|
446 | self.name = name | |
448 | self.description = description |
|
447 | self.description = description | |
449 |
|
448 | |||
450 |
def addReadUnit(self, datatype, path, startDate='', endDate='', startTime='', endTime='', |
|
449 | def addReadUnit(self, datatype, path, startDate='', endDate='', startTime='', endTime='', **kwargs): | |
451 |
|
450 | |||
452 | id = self.__getNewId() |
|
451 | id = self.__getNewId() | |
453 | name = '%sReader' %(datatype) |
|
452 | name = '%sReader' %(datatype) | |
454 |
|
453 | |||
455 | readUnitConfObj = ReadUnitConf() |
|
454 | readUnitConfObj = ReadUnitConf() | |
456 |
readUnitConfObj.setup(id, name, datatype, path, startDate, endDate, startTime, endTime, |
|
455 | readUnitConfObj.setup(id, name, datatype, path, startDate, endDate, startTime, endTime, **kwargs) | |
457 |
|
456 | |||
458 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj |
|
457 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj | |
459 |
|
458 | |||
460 | return readUnitConfObj |
|
459 | return readUnitConfObj | |
461 |
|
460 | |||
462 | def addProcUnit(self, datatype, inputId): |
|
461 | def addProcUnit(self, datatype, inputId): | |
463 |
|
462 | |||
464 | id = self.__getNewId() |
|
463 | id = self.__getNewId() | |
465 | name = '%sProc' %(datatype) |
|
464 | name = '%sProc' %(datatype) | |
466 |
|
465 | |||
467 | procUnitConfObj = ProcUnitConf() |
|
466 | procUnitConfObj = ProcUnitConf() | |
468 | procUnitConfObj.setup(id, name, datatype, inputId) |
|
467 | procUnitConfObj.setup(id, name, datatype, inputId) | |
469 |
|
468 | |||
470 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj |
|
469 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj | |
471 |
|
470 | |||
472 | return procUnitConfObj |
|
471 | return procUnitConfObj | |
473 |
|
472 | |||
474 | def makeXml(self): |
|
473 | def makeXml(self): | |
475 |
|
474 | |||
476 |
projectElement = Element(' |
|
475 | projectElement = Element('Project') | |
477 | projectElement.set('id', str(self.id)) |
|
476 | projectElement.set('id', str(self.id)) | |
478 | projectElement.set('name', self.name) |
|
477 | projectElement.set('name', self.name) | |
479 | projectElement.set('description', self.description) |
|
478 | projectElement.set('description', self.description) | |
480 |
|
479 | |||
481 | # for readUnitConfObj in self.readUnitConfObjList: |
|
480 | # for readUnitConfObj in self.readUnitConfObjList: | |
482 | # readUnitConfObj.makeXml(projectElement) |
|
481 | # readUnitConfObj.makeXml(projectElement) | |
483 |
|
482 | |||
484 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
483 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |
485 | procUnitConfObj.makeXml(projectElement) |
|
484 | procUnitConfObj.makeXml(projectElement) | |
486 |
|
485 | |||
487 | self.projectElement = projectElement |
|
486 | self.projectElement = projectElement | |
488 |
|
487 | |||
489 | def writeXml(self, filename): |
|
488 | def writeXml(self, filename): | |
490 |
|
489 | |||
491 | self.makeXml() |
|
490 | self.makeXml() | |
492 |
|
491 | |||
493 | print prettify(self.projectElement) |
|
492 | print prettify(self.projectElement) | |
494 |
|
493 | |||
495 | ElementTree(self.projectElement).write(filename, method='xml') |
|
494 | ElementTree(self.projectElement).write(filename, method='xml') | |
496 |
|
495 | |||
497 | def readXml(self, filename): |
|
496 | def readXml(self, filename): | |
498 |
|
497 | |||
499 | #tree = ET.parse(filename) |
|
498 | #tree = ET.parse(filename) | |
500 | self.projectElement = None |
|
499 | self.projectElement = None | |
501 | # self.readUnitConfObjList = [] |
|
500 | # self.readUnitConfObjList = [] | |
502 | self.procUnitConfObjDict = {} |
|
501 | self.procUnitConfObjDict = {} | |
503 |
|
502 | |||
504 | self.projectElement = ElementTree().parse(filename) |
|
503 | self.projectElement = ElementTree().parse(filename) | |
505 |
|
504 | |||
506 | self.project = self.projectElement.tag |
|
505 | self.project = self.projectElement.tag | |
507 |
|
506 | |||
508 | self.id = self.projectElement.get('id') |
|
507 | self.id = self.projectElement.get('id') | |
509 | self.name = self.projectElement.get('name') |
|
508 | self.name = self.projectElement.get('name') | |
510 | self.description = self.projectElement.get('description') |
|
509 | self.description = self.projectElement.get('description') | |
511 |
|
510 | |||
512 | readUnitElementList = self.projectElement.getiterator(ReadUnitConf().getElementName()) |
|
511 | readUnitElementList = self.projectElement.getiterator(ReadUnitConf().getElementName()) | |
513 |
|
512 | |||
514 | for readUnitElement in readUnitElementList: |
|
513 | for readUnitElement in readUnitElementList: | |
515 | readUnitConfObj = ReadUnitConf() |
|
514 | readUnitConfObj = ReadUnitConf() | |
516 | readUnitConfObj.readXml(readUnitElement) |
|
515 | readUnitConfObj.readXml(readUnitElement) | |
517 |
|
516 | |||
518 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj |
|
517 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj | |
519 |
|
518 | |||
520 | procUnitElementList = self.projectElement.getiterator(ProcUnitConf().getElementName()) |
|
519 | procUnitElementList = self.projectElement.getiterator(ProcUnitConf().getElementName()) | |
521 |
|
520 | |||
522 | for procUnitElement in procUnitElementList: |
|
521 | for procUnitElement in procUnitElementList: | |
523 | procUnitConfObj = ProcUnitConf() |
|
522 | procUnitConfObj = ProcUnitConf() | |
524 | procUnitConfObj.readXml(procUnitElement) |
|
523 | procUnitConfObj.readXml(procUnitElement) | |
525 |
|
524 | |||
526 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj |
|
525 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj | |
527 |
|
526 | |||
528 | def printattr(self): |
|
527 | def printattr(self): | |
529 |
|
528 | |||
530 |
print " |
|
529 | print "Project[%s]: name = %s, description = %s" %(self.id, | |
531 | self.name, |
|
530 | self.name, | |
532 | self.description) |
|
531 | self.description) | |
533 |
|
532 | |||
534 | # for readUnitConfObj in self.readUnitConfObjList: |
|
533 | # for readUnitConfObj in self.readUnitConfObjList: | |
535 | # readUnitConfObj.printattr() |
|
534 | # readUnitConfObj.printattr() | |
536 |
|
535 | |||
537 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
536 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |
538 | procUnitConfObj.printattr() |
|
537 | procUnitConfObj.printattr() | |
539 |
|
538 | |||
540 | def createObjects(self): |
|
539 | def createObjects(self): | |
541 |
|
540 | |||
542 | # for readUnitConfObj in self.readUnitConfObjList: |
|
541 | # for readUnitConfObj in self.readUnitConfObjList: | |
543 | # readUnitConfObj.createObjects() |
|
542 | # readUnitConfObj.createObjects() | |
544 |
|
543 | |||
545 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
544 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |
546 | procUnitConfObj.createObjects() |
|
545 | procUnitConfObj.createObjects() | |
547 |
|
546 | |||
548 | def __connect(self, objIN, obj): |
|
547 | def __connect(self, objIN, obj): | |
549 |
|
548 | |||
550 | obj.setInput(objIN.getOutput()) |
|
549 | obj.setInput(objIN.getOutput()) | |
551 |
|
550 | |||
552 | def connectObjects(self): |
|
551 | def connectObjects(self): | |
553 |
|
552 | |||
554 | for puConfObj in self.procUnitConfObjDict.values(): |
|
553 | for puConfObj in self.procUnitConfObjDict.values(): | |
555 |
|
554 | |||
556 | inputId = puConfObj.getInputId() |
|
555 | inputId = puConfObj.getInputId() | |
557 |
|
556 | |||
558 | if int(inputId) == 0: |
|
557 | if int(inputId) == 0: | |
559 | continue |
|
558 | continue | |
560 |
|
559 | |||
561 | puConfINObj = self.procUnitConfObjDict[inputId] |
|
560 | puConfINObj = self.procUnitConfObjDict[inputId] | |
562 |
|
561 | |||
563 | puObj = puConfObj.getProcUnitObj() |
|
562 | puObj = puConfObj.getProcUnitObj() | |
564 | puINObj = puConfINObj.getProcUnitObj() |
|
563 | puINObj = puConfINObj.getProcUnitObj() | |
565 |
|
564 | |||
566 | self.__connect(puINObj, puObj) |
|
565 | self.__connect(puINObj, puObj) | |
567 |
|
566 | |||
568 | def run(self): |
|
567 | def run(self): | |
569 |
|
568 | |||
570 | # for readUnitConfObj in self.readUnitConfObjList: |
|
569 | # for readUnitConfObj in self.readUnitConfObjList: | |
571 | # readUnitConfObj.run() |
|
570 | # readUnitConfObj.run() | |
572 |
|
571 | |||
573 | while(True): |
|
572 | while(True): | |
574 |
|
573 | |||
575 | finalSts = False |
|
574 | finalSts = False | |
576 |
|
575 | |||
577 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
576 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |
578 | #print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id) |
|
577 | #print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id) | |
579 | sts = procUnitConfObj.run() |
|
578 | sts = procUnitConfObj.run() | |
580 | finalSts = finalSts or sts |
|
579 | finalSts = finalSts or sts | |
581 |
|
580 | |||
582 | #If every process unit finished so end process |
|
581 | #If every process unit finished so end process | |
583 | if not(finalSts): |
|
582 | if not(finalSts): | |
584 | print "Every process units have finished" |
|
583 | print "Every process units have finished" | |
585 | break |
|
584 | break | |
586 |
|
585 | |||
587 | if __name__ == '__main__': |
|
586 | if __name__ == '__main__': | |
588 |
|
587 | |||
589 | desc = "Segundo Test" |
|
588 | desc = "Segundo Test" | |
590 | filename = "schain.xml" |
|
589 | filename = "schain.xml" | |
591 |
|
590 | |||
592 |
controllerObj = |
|
591 | controllerObj = Project() | |
593 |
|
592 | |||
594 | controllerObj.setup(id = '191', name='test01', description=desc) |
|
593 | controllerObj.setup(id = '191', name='test01', description=desc) | |
595 |
|
594 | |||
596 | readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage', |
|
595 | readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage', | |
597 | path='data/rawdata/', |
|
596 | path='data/rawdata/', | |
598 | startDate='2011/01/01', |
|
597 | startDate='2011/01/01', | |
599 | endDate='2012/12/31', |
|
598 | endDate='2012/12/31', | |
600 | startTime='00:00:00', |
|
599 | startTime='00:00:00', | |
601 | endTime='23:59:59', |
|
600 | endTime='23:59:59', | |
602 |
online= |
|
601 | online=1, | |
|
602 | walk=1) | |||
603 |
|
603 | |||
604 | # opObj00 = readUnitConfObj.addOperation(name='printInfo') |
|
604 | # opObj00 = readUnitConfObj.addOperation(name='printInfo') | |
605 |
|
605 | |||
606 | procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) |
|
606 | procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) | |
607 |
|
607 | |||
608 | opObj10 = procUnitConfObj0.addOperation(name='selectChannels') |
|
608 | opObj10 = procUnitConfObj0.addOperation(name='selectChannels') | |
609 | opObj10.addParameter(name='channelList', value='3,4,5', format='intlist') |
|
609 | opObj10.addParameter(name='channelList', value='3,4,5', format='intlist') | |
610 |
|
610 | |||
611 | opObj10 = procUnitConfObj0.addOperation(name='selectHeights') |
|
611 | opObj10 = procUnitConfObj0.addOperation(name='selectHeights') | |
612 | opObj10.addParameter(name='minHei', value='90', format='float') |
|
612 | opObj10.addParameter(name='minHei', value='90', format='float') | |
613 | opObj10.addParameter(name='maxHei', value='180', format='float') |
|
613 | opObj10.addParameter(name='maxHei', value='180', format='float') | |
614 |
|
614 | |||
615 | opObj12 = procUnitConfObj0.addOperation(name='CohInt', optype='other') |
|
615 | opObj12 = procUnitConfObj0.addOperation(name='CohInt', optype='other') | |
616 | opObj12.addParameter(name='n', value='10', format='int') |
|
616 | opObj12.addParameter(name='n', value='10', format='int') | |
617 |
|
617 | |||
618 | procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId()) |
|
618 | procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId()) | |
619 | procUnitConfObj1.addParameter(name='nFFTPoints', value='32', format='int') |
|
619 | procUnitConfObj1.addParameter(name='nFFTPoints', value='32', format='int') | |
|
620 | # procUnitConfObj1.addParameter(name='pairList', value='(0,1),(0,2),(1,2)', format='') | |||
|
621 | ||||
620 |
|
622 | |||
621 | opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') |
|
623 | opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') | |
622 | opObj11.addParameter(name='idfigure', value='1', format='int') |
|
624 | opObj11.addParameter(name='idfigure', value='1', format='int') | |
623 | opObj11.addParameter(name='wintitle', value='SpectraPlot0', format='str') |
|
625 | opObj11.addParameter(name='wintitle', value='SpectraPlot0', format='str') | |
624 | opObj11.addParameter(name='zmin', value='40', format='int') |
|
626 | opObj11.addParameter(name='zmin', value='40', format='int') | |
625 | opObj11.addParameter(name='zmax', value='90', format='int') |
|
627 | opObj11.addParameter(name='zmax', value='90', format='int') | |
626 | opObj11.addParameter(name='showprofile', value='1', format='int') |
|
628 | opObj11.addParameter(name='showprofile', value='1', format='int') | |
627 |
|
||||
628 | procUnitConfObj2 = controllerObj.addProcUnit(datatype='Voltage', inputId=procUnitConfObj0.getId()) |
|
|||
629 |
|
||||
630 | opObj12 = procUnitConfObj2.addOperation(name='CohInt', optype='other') |
|
|||
631 | opObj12.addParameter(name='n', value='2', format='int') |
|
|||
632 | opObj12.addParameter(name='overlapping', value='1', format='int') |
|
|||
633 |
|
629 | |||
634 | procUnitConfObj3 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj2.getId()) |
|
630 | # opObj11 = procUnitConfObj1.addOperation(name='CrossSpectraPlot', optype='other') | |
635 |
|
|
631 | # opObj11.addParameter(name='idfigure', value='2', format='int') | |
636 |
|
632 | # opObj11.addParameter(name='wintitle', value='CrossSpectraPlot', format='str') | ||
637 | opObj11 = procUnitConfObj3.addOperation(name='SpectraPlot', optype='other') |
|
633 | # opObj11.addParameter(name='zmin', value='40', format='int') | |
638 |
opObj11.addParameter(name=' |
|
634 | # opObj11.addParameter(name='zmax', value='90', format='int') | |
639 | opObj11.addParameter(name='wintitle', value='SpectraPlot1', format='str') |
|
635 | ||
640 | opObj11.addParameter(name='zmin', value='40', format='int') |
|
636 | ||
641 | opObj11.addParameter(name='zmax', value='90', format='int') |
|
637 | # procUnitConfObj2 = controllerObj.addProcUnit(datatype='Voltage', inputId=procUnitConfObj0.getId()) | |
|
638 | # | |||
|
639 | # opObj12 = procUnitConfObj2.addOperation(name='CohInt', optype='other') | |||
|
640 | # opObj12.addParameter(name='n', value='2', format='int') | |||
|
641 | # opObj12.addParameter(name='overlapping', value='1', format='int') | |||
|
642 | # | |||
|
643 | # procUnitConfObj3 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj2.getId()) | |||
|
644 | # procUnitConfObj3.addParameter(name='nFFTPoints', value='32', format='int') | |||
|
645 | # | |||
|
646 | # opObj11 = procUnitConfObj3.addOperation(name='SpectraPlot', optype='other') | |||
|
647 | # opObj11.addParameter(name='idfigure', value='2', format='int') | |||
|
648 | # opObj11.addParameter(name='wintitle', value='SpectraPlot1', format='str') | |||
|
649 | # opObj11.addParameter(name='zmin', value='40', format='int') | |||
|
650 | # opObj11.addParameter(name='zmax', value='90', format='int') | |||
642 | # opObj11.addParameter(name='showprofile', value='1', format='int') |
|
651 | # opObj11.addParameter(name='showprofile', value='1', format='int') | |
643 |
|
652 | |||
644 | # opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other') |
|
653 | # opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other') | |
645 | # opObj11.addParameter(name='idfigure', value='10', format='int') |
|
654 | # opObj11.addParameter(name='idfigure', value='10', format='int') | |
646 | # opObj11.addParameter(name='wintitle', value='RTI', format='str') |
|
655 | # opObj11.addParameter(name='wintitle', value='RTI', format='str') | |
647 | ## opObj11.addParameter(name='xmin', value='21', format='float') |
|
656 | ## opObj11.addParameter(name='xmin', value='21', format='float') | |
648 | ## opObj11.addParameter(name='xmax', value='22', format='float') |
|
657 | ## opObj11.addParameter(name='xmax', value='22', format='float') | |
649 | # opObj11.addParameter(name='zmin', value='40', format='int') |
|
658 | # opObj11.addParameter(name='zmin', value='40', format='int') | |
650 | # opObj11.addParameter(name='zmax', value='90', format='int') |
|
659 | # opObj11.addParameter(name='zmax', value='90', format='int') | |
651 | # opObj11.addParameter(name='showprofile', value='1', format='int') |
|
660 | # opObj11.addParameter(name='showprofile', value='1', format='int') | |
652 | # opObj11.addParameter(name='timerange', value=str(60), format='int') |
|
661 | # opObj11.addParameter(name='timerange', value=str(60), format='int') | |
653 |
|
662 | |||
654 | # opObj10 = procUnitConfObj1.addOperation(name='selectChannels') |
|
663 | # opObj10 = procUnitConfObj1.addOperation(name='selectChannels') | |
655 | # opObj10.addParameter(name='channelList', value='0,2,4,6', format='intlist') |
|
664 | # opObj10.addParameter(name='channelList', value='0,2,4,6', format='intlist') | |
656 | # |
|
665 | # | |
657 | # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') |
|
666 | # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') | |
658 | # opObj12.addParameter(name='n', value='2', format='int') |
|
667 | # opObj12.addParameter(name='n', value='2', format='int') | |
659 | # |
|
668 | # | |
660 | # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') |
|
669 | # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') | |
661 | # opObj11.addParameter(name='idfigure', value='2', format='int') |
|
670 | # opObj11.addParameter(name='idfigure', value='2', format='int') | |
662 | # opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str') |
|
671 | # opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str') | |
663 | # opObj11.addParameter(name='zmin', value='70', format='int') |
|
672 | # opObj11.addParameter(name='zmin', value='70', format='int') | |
664 | # opObj11.addParameter(name='zmax', value='90', format='int') |
|
673 | # opObj11.addParameter(name='zmax', value='90', format='int') | |
665 | # |
|
674 | # | |
666 | # opObj10 = procUnitConfObj1.addOperation(name='selectChannels') |
|
675 | # opObj10 = procUnitConfObj1.addOperation(name='selectChannels') | |
667 | # opObj10.addParameter(name='channelList', value='2,6', format='intlist') |
|
676 | # opObj10.addParameter(name='channelList', value='2,6', format='intlist') | |
668 | # |
|
677 | # | |
669 | # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') |
|
678 | # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') | |
670 | # opObj12.addParameter(name='n', value='2', format='int') |
|
679 | # opObj12.addParameter(name='n', value='2', format='int') | |
671 | # |
|
680 | # | |
672 | # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') |
|
681 | # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') | |
673 | # opObj11.addParameter(name='idfigure', value='3', format='int') |
|
682 | # opObj11.addParameter(name='idfigure', value='3', format='int') | |
674 | # opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str') |
|
683 | # opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str') | |
675 | # opObj11.addParameter(name='zmin', value='70', format='int') |
|
684 | # opObj11.addParameter(name='zmin', value='70', format='int') | |
676 | # opObj11.addParameter(name='zmax', value='90', format='int') |
|
685 | # opObj11.addParameter(name='zmax', value='90', format='int') | |
677 |
|
686 | |||
678 |
|
687 | |||
679 | # opObj12 = procUnitConfObj1.addOperation(name='decoder') |
|
688 | # opObj12 = procUnitConfObj1.addOperation(name='decoder') | |
680 | # opObj12.addParameter(name='ncode', value='2', format='int') |
|
689 | # opObj12.addParameter(name='ncode', value='2', format='int') | |
681 | # opObj12.addParameter(name='nbauds', value='8', format='int') |
|
690 | # opObj12.addParameter(name='nbauds', value='8', format='int') | |
682 | # opObj12.addParameter(name='code0', value='001110011', format='int') |
|
691 | # opObj12.addParameter(name='code0', value='001110011', format='int') | |
683 | # opObj12.addParameter(name='code1', value='001110011', format='int') |
|
692 | # opObj12.addParameter(name='code1', value='001110011', format='int') | |
684 |
|
693 | |||
685 |
|
694 | |||
686 |
|
695 | |||
687 | # procUnitConfObj2 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj1.getId()) |
|
696 | # procUnitConfObj2 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj1.getId()) | |
688 | # |
|
697 | # | |
689 | # opObj21 = procUnitConfObj2.addOperation(name='IncohInt', optype='other') |
|
698 | # opObj21 = procUnitConfObj2.addOperation(name='IncohInt', optype='other') | |
690 | # opObj21.addParameter(name='n', value='2', format='int') |
|
699 | # opObj21.addParameter(name='n', value='2', format='int') | |
691 | # |
|
700 | # | |
692 | # opObj11 = procUnitConfObj2.addOperation(name='SpectraPlot', optype='other') |
|
701 | # opObj11 = procUnitConfObj2.addOperation(name='SpectraPlot', optype='other') | |
693 | # opObj11.addParameter(name='idfigure', value='4', format='int') |
|
702 | # opObj11.addParameter(name='idfigure', value='4', format='int') | |
694 | # opObj11.addParameter(name='wintitle', value='SpectraPlot OBJ 2', format='str') |
|
703 | # opObj11.addParameter(name='wintitle', value='SpectraPlot OBJ 2', format='str') | |
695 | # opObj11.addParameter(name='zmin', value='70', format='int') |
|
704 | # opObj11.addParameter(name='zmin', value='70', format='int') | |
696 | # opObj11.addParameter(name='zmax', value='90', format='int') |
|
705 | # opObj11.addParameter(name='zmax', value='90', format='int') | |
697 |
|
706 | |||
698 | print "Escribiendo el archivo XML" |
|
707 | print "Escribiendo el archivo XML" | |
699 |
|
708 | |||
700 | controllerObj.writeXml(filename) |
|
709 | controllerObj.writeXml(filename) | |
701 |
|
710 | |||
702 | print "Leyendo el archivo XML" |
|
711 | print "Leyendo el archivo XML" | |
703 | controllerObj.readXml(filename) |
|
712 | controllerObj.readXml(filename) | |
704 | #controllerObj.printattr() |
|
713 | #controllerObj.printattr() | |
705 |
|
714 | |||
706 | controllerObj.createObjects() |
|
715 | controllerObj.createObjects() | |
707 | controllerObj.connectObjects() |
|
716 | controllerObj.connectObjects() | |
708 | controllerObj.run() |
|
717 | controllerObj.run() | |
709 |
|
718 | |||
710 | No newline at end of file |
|
719 |
@@ -1,305 +1,285 | |||||
1 | import numpy |
|
1 | import numpy | |
2 | import datetime |
|
2 | import datetime | |
3 | import matplotlib |
|
3 | import matplotlib | |
4 | matplotlib.use("TKAgg") |
|
4 | matplotlib.use("TKAgg") | |
5 | import matplotlib.pyplot |
|
5 | import matplotlib.pyplot | |
6 | import matplotlib.dates |
|
6 | import matplotlib.dates | |
7 | #import scitools.numpyutils |
|
7 | #import scitools.numpyutils | |
8 | from mpl_toolkits.axes_grid1 import make_axes_locatable |
|
8 | from mpl_toolkits.axes_grid1 import make_axes_locatable | |
9 |
|
9 | |||
10 | from matplotlib.dates import DayLocator, HourLocator, MinuteLocator, SecondLocator, DateFormatter |
|
10 | from matplotlib.dates import DayLocator, HourLocator, MinuteLocator, SecondLocator, DateFormatter | |
11 | from matplotlib.ticker import FuncFormatter |
|
11 | from matplotlib.ticker import FuncFormatter | |
12 | from matplotlib.ticker import * |
|
12 | from matplotlib.ticker import * | |
13 |
|
13 | |||
14 | #def init(idfigure, wintitle, width, height, facecolor="w"): |
|
14 | #def init(idfigure, wintitle, width, height, facecolor="w"): | |
15 | # |
|
15 | # | |
16 | # matplotlib.pyplot.ioff() |
|
16 | # matplotlib.pyplot.ioff() | |
17 | # fig = matplotlib.pyplot.matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor) |
|
17 | # fig = matplotlib.pyplot.matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor) | |
18 | # fig.canvas.manager.set_window_title(wintitle) |
|
18 | # fig.canvas.manager.set_window_title(wintitle) | |
19 | # fig.canvas.manager.resize(width, height) |
|
19 | # fig.canvas.manager.resize(width, height) | |
20 | # matplotlib.pyplot.ion() |
|
20 | # matplotlib.pyplot.ion() | |
21 | # |
|
21 | # | |
22 | # return fig |
|
22 | # return fig | |
23 | # |
|
23 | # | |
24 | #def setWinTitle(fig, title): |
|
24 | #def setWinTitle(fig, title): | |
25 | # |
|
25 | # | |
26 | # fig.canvas.manager.set_window_title(title) |
|
26 | # fig.canvas.manager.set_window_title(title) | |
27 | # |
|
27 | # | |
28 | #def setTitle(idfigure, title): |
|
28 | #def setTitle(idfigure, title): | |
29 | # fig = matplotlib.pyplot.figure(idfigure) |
|
29 | # fig = matplotlib.pyplot.figure(idfigure) | |
30 | # fig.suptitle(title) |
|
30 | # fig.suptitle(title) | |
31 | # |
|
31 | # | |
32 | #def makeAxes(idfigure, nrow, ncol, xpos, ypos, colspan, rowspan): |
|
32 | #def makeAxes(idfigure, nrow, ncol, xpos, ypos, colspan, rowspan): | |
33 | # fig = matplotlib.pyplot.figure(idfigure) |
|
33 | # fig = matplotlib.pyplot.figure(idfigure) | |
34 | # ax = matplotlib.pyplot.subplot2grid((nrow, ncol), (xpos, ypos), colspan=colspan, rowspan=rowspan) |
|
34 | # ax = matplotlib.pyplot.subplot2grid((nrow, ncol), (xpos, ypos), colspan=colspan, rowspan=rowspan) | |
35 | # return ax |
|
35 | # return ax | |
36 | # |
|
36 | # | |
37 | #def setTextFromAxes(idfigure, ax, title): |
|
37 | #def setTextFromAxes(idfigure, ax, title): | |
38 | # fig = matplotlib.pyplot.figure(idfigure) |
|
38 | # fig = matplotlib.pyplot.figure(idfigure) | |
39 | # ax.annotate(title, xy=(.1, .99), |
|
39 | # ax.annotate(title, xy=(.1, .99), | |
40 | # xycoords='figure fraction', |
|
40 | # xycoords='figure fraction', | |
41 | # horizontalalignment='left', verticalalignment='top', |
|
41 | # horizontalalignment='left', verticalalignment='top', | |
42 | # fontsize=10) |
|
42 | # fontsize=10) | |
43 | # |
|
43 | # | |
44 | #def pline(ax, x, y, xmin, xmax, ymin, ymax, xlabel, ylabel, title, firsttime): |
|
44 | #def pline(ax, x, y, xmin, xmax, ymin, ymax, xlabel, ylabel, title, firsttime): | |
45 | # |
|
45 | # | |
46 | # if firsttime: |
|
46 | # if firsttime: | |
47 | # ax.plot(x, y) |
|
47 | # ax.plot(x, y) | |
48 | # ax.set_xlim([xmin,xmax]) |
|
48 | # ax.set_xlim([xmin,xmax]) | |
49 | # ax.set_ylim([ymin,ymax]) |
|
49 | # ax.set_ylim([ymin,ymax]) | |
50 | # ax.set_xlabel(xlabel, size=8) |
|
50 | # ax.set_xlabel(xlabel, size=8) | |
51 | # ax.set_ylabel(ylabel, size=8) |
|
51 | # ax.set_ylabel(ylabel, size=8) | |
52 | # ax.set_title(title, size=10) |
|
52 | # ax.set_title(title, size=10) | |
53 | # matplotlib.pyplot.tight_layout() |
|
53 | # matplotlib.pyplot.tight_layout() | |
54 | # else: |
|
54 | # else: | |
55 | # ax.lines[0].set_data(x,y) |
|
55 | # ax.lines[0].set_data(x,y) | |
56 | # |
|
56 | # | |
57 | #def draw(idfigure): |
|
57 | #def draw(idfigure): | |
58 | # |
|
58 | # | |
59 | # fig = matplotlib.pyplot.figure(idfigure) |
|
59 | # fig = matplotlib.pyplot.figure(idfigure) | |
60 | # fig.canvas.draw() |
|
60 | # fig.canvas.draw() | |
61 | # |
|
61 | # | |
62 | #def pcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel, ylabel, title, firsttime, mesh): |
|
62 | #def pcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel, ylabel, title, firsttime, mesh): | |
63 | # |
|
63 | # | |
64 | # if firsttime: |
|
64 | # if firsttime: | |
65 | # divider = make_axes_locatable(ax) |
|
65 | # divider = make_axes_locatable(ax) | |
66 | # ax_cb = divider.new_horizontal(size="4%", pad=0.05) |
|
66 | # ax_cb = divider.new_horizontal(size="4%", pad=0.05) | |
67 | # fig1 = ax.get_figure() |
|
67 | # fig1 = ax.get_figure() | |
68 | # fig1.add_axes(ax_cb) |
|
68 | # fig1.add_axes(ax_cb) | |
69 | # |
|
69 | # | |
70 | # ax.set_xlim([xmin,xmax]) |
|
70 | # ax.set_xlim([xmin,xmax]) | |
71 | # ax.set_ylim([ymin,ymax]) |
|
71 | # ax.set_ylim([ymin,ymax]) | |
72 | # ax.set_xlabel(xlabel) |
|
72 | # ax.set_xlabel(xlabel) | |
73 | # ax.set_ylabel(ylabel) |
|
73 | # ax.set_ylabel(ylabel) | |
74 | # ax.set_title(title) |
|
74 | # ax.set_title(title) | |
75 | # print x |
|
75 | # print x | |
76 | # imesh=ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax) |
|
76 | # imesh=ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax) | |
77 | # matplotlib.pyplot.colorbar(imesh, cax=ax_cb) |
|
77 | # matplotlib.pyplot.colorbar(imesh, cax=ax_cb) | |
78 | # ax_cb.yaxis.tick_right() |
|
78 | # ax_cb.yaxis.tick_right() | |
79 | # for tl in ax_cb.get_yticklabels(): |
|
79 | # for tl in ax_cb.get_yticklabels(): | |
80 | # tl.set_visible(True) |
|
80 | # tl.set_visible(True) | |
81 | # ax_cb.yaxis.tick_right() |
|
81 | # ax_cb.yaxis.tick_right() | |
82 | # matplotlib.pyplot.tight_layout() |
|
82 | # matplotlib.pyplot.tight_layout() | |
83 | # return imesh |
|
83 | # return imesh | |
84 | # else: |
|
84 | # else: | |
85 | ## ax.set_xlim([xmin,xmax]) |
|
85 | ## ax.set_xlim([xmin,xmax]) | |
86 | ## ax.set_ylim([ymin,ymax]) |
|
86 | ## ax.set_ylim([ymin,ymax]) | |
87 | # ax.set_xlabel(xlabel) |
|
87 | # ax.set_xlabel(xlabel) | |
88 | # ax.set_ylabel(ylabel) |
|
88 | # ax.set_ylabel(ylabel) | |
89 | # ax.set_title(title) |
|
89 | # ax.set_title(title) | |
90 | # |
|
90 | # | |
91 | # z = z.T |
|
91 | # z = z.T | |
92 | ## z = z[0:-1,0:-1] |
|
92 | ## z = z[0:-1,0:-1] | |
93 | # mesh.set_array(z.ravel()) |
|
93 | # mesh.set_array(z.ravel()) | |
94 | # |
|
94 | # | |
95 | # return mesh |
|
95 | # return mesh | |
96 |
|
96 | |||
97 | ########################################### |
|
97 | ########################################### | |
98 | #Actualizacion de las funciones del driver |
|
98 | #Actualizacion de las funciones del driver | |
99 | ########################################### |
|
99 | ########################################### | |
100 |
|
100 | |||
101 | def createFigure(idfigure, wintitle, width, height, facecolor="w"): |
|
101 | def createFigure(idfigure, wintitle, width, height, facecolor="w"): | |
102 |
|
102 | |||
103 | matplotlib.pyplot.ioff() |
|
103 | matplotlib.pyplot.ioff() | |
104 | fig = matplotlib.pyplot.matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor) |
|
104 | fig = matplotlib.pyplot.matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor) | |
105 | fig.canvas.manager.set_window_title(wintitle) |
|
105 | fig.canvas.manager.set_window_title(wintitle) | |
106 | fig.canvas.manager.resize(width, height) |
|
106 | fig.canvas.manager.resize(width, height) | |
107 | matplotlib.pyplot.ion() |
|
107 | matplotlib.pyplot.ion() | |
108 |
|
108 | |||
109 | return fig |
|
109 | return fig | |
110 |
|
110 | |||
111 | def closeFigure(): |
|
111 | def closeFigure(): | |
112 |
|
112 | |||
113 | matplotlib.pyplot.ioff() |
|
113 | matplotlib.pyplot.ioff() | |
114 | matplotlib.pyplot.show() |
|
114 | matplotlib.pyplot.show() | |
115 |
|
115 | |||
116 | return |
|
116 | return | |
117 |
|
117 | |||
118 | def saveFigure(fig, filename): |
|
118 | def saveFigure(fig, filename): | |
119 | fig.savefig(filename) |
|
119 | fig.savefig(filename) | |
120 |
|
120 | |||
121 | def setWinTitle(fig, title): |
|
121 | def setWinTitle(fig, title): | |
122 |
|
122 | |||
123 | fig.canvas.manager.set_window_title(title) |
|
123 | fig.canvas.manager.set_window_title(title) | |
124 |
|
124 | |||
125 | def setTitle(fig, title): |
|
125 | def setTitle(fig, title): | |
126 |
|
126 | |||
127 | fig.suptitle(title) |
|
127 | fig.suptitle(title) | |
128 |
|
128 | |||
129 | def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan): |
|
129 | def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan): | |
130 |
|
130 | |||
131 | matplotlib.pyplot.figure(fig.number) |
|
131 | matplotlib.pyplot.figure(fig.number) | |
132 | axes = matplotlib.pyplot.subplot2grid((nrow, ncol), |
|
132 | axes = matplotlib.pyplot.subplot2grid((nrow, ncol), | |
133 | (xpos, ypos), |
|
133 | (xpos, ypos), | |
134 | colspan=colspan, |
|
134 | colspan=colspan, | |
135 | rowspan=rowspan) |
|
135 | rowspan=rowspan) | |
136 | return axes |
|
136 | return axes | |
137 |
|
137 | |||
138 | def setAxesText(ax, text): |
|
138 | def setAxesText(ax, text): | |
139 |
|
139 | |||
140 | ax.annotate(text, |
|
140 | ax.annotate(text, | |
141 | xy = (.1, .99), |
|
141 | xy = (.1, .99), | |
142 | xycoords = 'figure fraction', |
|
142 | xycoords = 'figure fraction', | |
143 | horizontalalignment = 'left', |
|
143 | horizontalalignment = 'left', | |
144 | verticalalignment = 'top', |
|
144 | verticalalignment = 'top', | |
145 | fontsize = 10) |
|
145 | fontsize = 10) | |
146 |
|
146 | |||
147 | def printLabels(ax, xlabel, ylabel, title): |
|
147 | def printLabels(ax, xlabel, ylabel, title): | |
148 |
|
148 | |||
149 | ax.set_xlabel(xlabel, size=11) |
|
149 | ax.set_xlabel(xlabel, size=11) | |
150 | ax.set_ylabel(ylabel, size=11) |
|
150 | ax.set_ylabel(ylabel, size=11) | |
151 | ax.set_title(title, size=12) |
|
151 | ax.set_title(title, size=12) | |
152 |
|
152 | |||
153 | def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', |
|
153 | def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', | |
154 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
154 | ticksize=9, xtick_visible=True, ytick_visible=True, | |
155 | nxticks=4, nyticks=10, |
|
155 | nxticks=4, nyticks=10, | |
156 | grid=None): |
|
156 | grid=None): | |
157 |
|
157 | |||
158 | """ |
|
158 | """ | |
159 |
|
159 | |||
160 | Input: |
|
160 | Input: | |
161 | grid : None, 'both', 'x', 'y' |
|
161 | grid : None, 'both', 'x', 'y' | |
162 | """ |
|
162 | """ | |
163 |
|
163 | |||
164 | ax.plot(x, y) |
|
164 | ax.plot(x, y) | |
165 | ax.set_xlim([xmin,xmax]) |
|
165 | ax.set_xlim([xmin,xmax]) | |
166 | ax.set_ylim([ymin,ymax]) |
|
166 | ax.set_ylim([ymin,ymax]) | |
167 |
|
167 | |||
168 | printLabels(ax, xlabel, ylabel, title) |
|
168 | printLabels(ax, xlabel, ylabel, title) | |
169 |
|
169 | |||
170 | ###################################################### |
|
170 | ###################################################### | |
171 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/nxticks) + int(xmin) |
|
171 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/nxticks) + int(xmin) | |
172 | ax.set_xticks(xtickspos) |
|
172 | ax.set_xticks(xtickspos) | |
173 |
|
173 | |||
174 | for tick in ax.get_xticklabels(): |
|
174 | for tick in ax.get_xticklabels(): | |
175 | tick.set_visible(xtick_visible) |
|
175 | tick.set_visible(xtick_visible) | |
176 |
|
176 | |||
177 | for tick in ax.xaxis.get_major_ticks(): |
|
177 | for tick in ax.xaxis.get_major_ticks(): | |
178 | tick.label.set_fontsize(ticksize) |
|
178 | tick.label.set_fontsize(ticksize) | |
179 |
|
179 | |||
180 | ###################################################### |
|
180 | ###################################################### | |
181 | for tick in ax.get_yticklabels(): |
|
181 | for tick in ax.get_yticklabels(): | |
182 | tick.set_visible(ytick_visible) |
|
182 | tick.set_visible(ytick_visible) | |
183 |
|
183 | |||
184 | for tick in ax.yaxis.get_major_ticks(): |
|
184 | for tick in ax.yaxis.get_major_ticks(): | |
185 | tick.label.set_fontsize(ticksize) |
|
185 | tick.label.set_fontsize(ticksize) | |
186 |
|
186 | |||
187 | iplot = ax.lines[-1] |
|
187 | iplot = ax.lines[-1] | |
188 |
|
188 | |||
189 | ###################################################### |
|
189 | ###################################################### | |
190 | if '0.' in matplotlib.__version__[0:2]: |
|
190 | if '0.' in matplotlib.__version__[0:2]: | |
191 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
191 | print "The matplotlib version has to be updated to 1.1 or newer" | |
192 | return iplot |
|
192 | return iplot | |
193 |
|
193 | |||
194 | if '1.0.' in matplotlib.__version__[0:4]: |
|
194 | if '1.0.' in matplotlib.__version__[0:4]: | |
195 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
195 | print "The matplotlib version has to be updated to 1.1 or newer" | |
196 | return iplot |
|
196 | return iplot | |
197 |
|
197 | |||
198 | if grid != None: |
|
198 | if grid != None: | |
199 | ax.grid(b=True, which='major', axis=grid) |
|
199 | ax.grid(b=True, which='major', axis=grid) | |
200 |
|
200 | |||
201 | matplotlib.pyplot.tight_layout() |
|
201 | matplotlib.pyplot.tight_layout() | |
202 |
|
202 | |||
203 | return iplot |
|
203 | return iplot | |
204 |
|
204 | |||
205 | def pline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
205 | def pline(iplot, x, y, xlabel='', ylabel='', title=''): | |
206 |
|
206 | |||
207 | ax = iplot.get_axes() |
|
207 | ax = iplot.get_axes() | |
208 |
|
208 | |||
209 | printLabels(ax, xlabel, ylabel, title) |
|
209 | printLabels(ax, xlabel, ylabel, title) | |
210 |
|
210 | |||
211 | iplot.set_data(x, y) |
|
211 | iplot.set_data(x, y) | |
212 |
|
212 | |||
213 | def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, |
|
213 | def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, | |
214 | xlabel='', ylabel='', title='', ticksize = 9, |
|
214 | xlabel='', ylabel='', title='', ticksize = 9, | |
215 | cblabel='', cbsize="5%", |
|
215 | cblabel='', cbsize="5%", | |
216 | XAxisAsTime=False): |
|
216 | XAxisAsTime=False): | |
217 |
|
217 | |||
218 | divider = make_axes_locatable(ax) |
|
218 | divider = make_axes_locatable(ax) | |
219 | ax_cb = divider.new_horizontal(size=cbsize, pad=0.05) |
|
219 | ax_cb = divider.new_horizontal(size=cbsize, pad=0.05) | |
220 | fig = ax.get_figure() |
|
220 | fig = ax.get_figure() | |
221 | fig.add_axes(ax_cb) |
|
221 | fig.add_axes(ax_cb) | |
222 |
|
222 | |||
223 | ax.set_xlim([xmin,xmax]) |
|
223 | ax.set_xlim([xmin,xmax]) | |
224 | ax.set_ylim([ymin,ymax]) |
|
224 | ax.set_ylim([ymin,ymax]) | |
225 |
|
225 | |||
226 | printLabels(ax, xlabel, ylabel, title) |
|
226 | printLabels(ax, xlabel, ylabel, title) | |
227 |
|
227 | |||
228 | imesh = ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax) |
|
228 | imesh = ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax) | |
229 | cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb) |
|
229 | cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb) | |
230 | cb.set_label(cblabel) |
|
230 | cb.set_label(cblabel) | |
231 |
|
231 | |||
232 | # for tl in ax_cb.get_yticklabels(): |
|
232 | # for tl in ax_cb.get_yticklabels(): | |
233 | # tl.set_visible(True) |
|
233 | # tl.set_visible(True) | |
234 |
|
234 | |||
235 | for tick in ax.yaxis.get_major_ticks(): |
|
235 | for tick in ax.yaxis.get_major_ticks(): | |
236 | tick.label.set_fontsize(ticksize) |
|
236 | tick.label.set_fontsize(ticksize) | |
237 |
|
237 | |||
238 | for tick in ax.xaxis.get_major_ticks(): |
|
238 | for tick in ax.xaxis.get_major_ticks(): | |
239 | tick.label.set_fontsize(ticksize) |
|
239 | tick.label.set_fontsize(ticksize) | |
240 |
|
240 | |||
241 | for tick in cb.ax.get_yticklabels(): |
|
241 | for tick in cb.ax.get_yticklabels(): | |
242 | tick.set_fontsize(ticksize) |
|
242 | tick.set_fontsize(ticksize) | |
243 |
|
243 | |||
244 | ax_cb.yaxis.tick_right() |
|
244 | ax_cb.yaxis.tick_right() | |
245 |
|
245 | |||
246 | if '0.' in matplotlib.__version__[0:2]: |
|
246 | if '0.' in matplotlib.__version__[0:2]: | |
247 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
247 | print "The matplotlib version has to be updated to 1.1 or newer" | |
248 | return imesh |
|
248 | return imesh | |
249 |
|
249 | |||
250 | if '1.0.' in matplotlib.__version__[0:4]: |
|
250 | if '1.0.' in matplotlib.__version__[0:4]: | |
251 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
251 | print "The matplotlib version has to be updated to 1.1 or newer" | |
252 | return imesh |
|
252 | return imesh | |
253 |
|
253 | |||
254 | matplotlib.pyplot.tight_layout() |
|
254 | matplotlib.pyplot.tight_layout() | |
255 |
|
255 | |||
256 | if XAxisAsTime: |
|
256 | if XAxisAsTime: | |
257 |
|
257 | |||
258 | func = lambda x, pos: ('%s') %(datetime.datetime.fromtimestamp(x).strftime("%H:%M:%S")) |
|
258 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) | |
259 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
259 | ax.xaxis.set_major_formatter(FuncFormatter(func)) | |
260 | ax.xaxis.set_major_locator(LinearLocator(7)) |
|
260 | ax.xaxis.set_major_locator(LinearLocator(7)) | |
261 |
|
261 | |||
262 | # seconds = numpy.array([xmin, xmax]) |
|
|||
263 | # datesList = map(datetime.datetime.fromtimestamp, seconds) |
|
|||
264 | # ax.set_xlim([datesList[0],datesList[-1]]) |
|
|||
265 | # ax.xaxis.set_major_locator(MinuteLocator(numpy.arange(0,61,10))) |
|
|||
266 | # ax.xaxis.set_minor_locator(SecondLocator(numpy.arange(0,61,60))) |
|
|||
267 | # ax.xaxis.set_major_formatter(DateFormatter("%H:%M:%S")) |
|
|||
268 | # xdateList = map(datetime.datetime.fromtimestamp, x) |
|
|||
269 | # xdate = matplotlib.dates.date2num(xdateList) |
|
|||
270 | # x = xdate |
|
|||
271 |
|
||||
272 | # labels = [] |
|
|||
273 | # for item in ax.xaxis.get_ticklabels(): |
|
|||
274 | # stri = item.get_text() |
|
|||
275 | # text = datetime.datetime.fromtimestamp(float(stri)) |
|
|||
276 | # labels.append(text) |
|
|||
277 | # |
|
|||
278 | # ax.xaxis.set_ticklabels(labels) |
|
|||
279 | return imesh |
|
262 | return imesh | |
280 |
|
263 | |||
281 | def pcolor(imesh, z, xlabel='', ylabel='', title=''): |
|
264 | def pcolor(imesh, z, xlabel='', ylabel='', title=''): | |
282 |
|
265 | |||
283 | z = z.T |
|
266 | z = z.T | |
284 |
|
267 | |||
285 | ax = imesh.get_axes() |
|
268 | ax = imesh.get_axes() | |
286 |
|
269 | |||
287 | printLabels(ax, xlabel, ylabel, title) |
|
270 | printLabels(ax, xlabel, ylabel, title) | |
288 |
|
271 | |||
289 | imesh.set_array(z.ravel()) |
|
272 | imesh.set_array(z.ravel()) | |
290 |
|
273 | |||
291 | def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title=''): |
|
274 | def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title=''): | |
292 |
|
275 | |||
293 | # xdateList = map(datetime.datetime.fromtimestamp, x) |
|
|||
294 | # xdate = matplotlib.dates.date2num(xdateList) |
|
|||
295 |
|
||||
296 | printLabels(ax, xlabel, ylabel, title) |
|
276 | printLabels(ax, xlabel, ylabel, title) | |
297 |
|
277 | |||
298 | imesh = ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax) |
|
278 | imesh = ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax) | |
299 |
|
279 | |||
300 | def draw(fig): |
|
280 | def draw(fig): | |
301 |
|
281 | |||
302 | if type(fig) == 'int': |
|
282 | if type(fig) == 'int': | |
303 | raise ValueError, "This parameter should be of tpye matplotlib figure" |
|
283 | raise ValueError, "This parameter should be of tpye matplotlib figure" | |
304 |
|
284 | |||
305 | fig.canvas.draw() No newline at end of file |
|
285 | fig.canvas.draw() |
@@ -1,506 +1,511 | |||||
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 | import datetime | |||
10 |
|
11 | |||
11 | from jroheaderIO import SystemHeader, RadarControllerHeader |
|
12 | from jroheaderIO import SystemHeader, RadarControllerHeader | |
12 |
|
13 | |||
13 | def hildebrand_sekhon(data, navg): |
|
14 | def hildebrand_sekhon(data, navg): | |
14 | """ |
|
15 | """ | |
15 | This method is for the objective determination of de noise level in Doppler spectra. This |
|
16 | 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 |
|
17 | 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 |
|
18 | densities is equal to the mean spectral density for white Gaussian noise | |
18 |
|
19 | |||
19 | Inputs: |
|
20 | Inputs: | |
20 | Data : heights |
|
21 | Data : heights | |
21 | navg : numbers of averages |
|
22 | navg : numbers of averages | |
22 |
|
23 | |||
23 | Return: |
|
24 | Return: | |
24 | -1 : any error |
|
25 | -1 : any error | |
25 | anoise : noise's level |
|
26 | anoise : noise's level | |
26 | """ |
|
27 | """ | |
27 |
|
28 | |||
28 | dataflat = data.copy().reshape(-1) |
|
29 | dataflat = data.copy().reshape(-1) | |
29 | dataflat.sort() |
|
30 | dataflat.sort() | |
30 | npts = dataflat.size #numbers of points of the data |
|
31 | npts = dataflat.size #numbers of points of the data | |
31 |
|
32 | |||
32 | if npts < 32: |
|
33 | if npts < 32: | |
33 | print "error in noise - requires at least 32 points" |
|
34 | print "error in noise - requires at least 32 points" | |
34 | return -1.0 |
|
35 | return -1.0 | |
35 |
|
36 | |||
36 | dataflat2 = numpy.power(dataflat,2) |
|
37 | dataflat2 = numpy.power(dataflat,2) | |
37 |
|
38 | |||
38 | cs = numpy.cumsum(dataflat) |
|
39 | cs = numpy.cumsum(dataflat) | |
39 | cs2 = numpy.cumsum(dataflat2) |
|
40 | cs2 = numpy.cumsum(dataflat2) | |
40 |
|
41 | |||
41 | # data sorted in ascending order |
|
42 | # data sorted in ascending order | |
42 | nmin = int((npts + 7.)/8) |
|
43 | nmin = int((npts + 7.)/8) | |
43 |
|
44 | |||
44 | for i in range(nmin, npts): |
|
45 | for i in range(nmin, npts): | |
45 | s = cs[i] |
|
46 | s = cs[i] | |
46 | s2 = cs2[i] |
|
47 | s2 = cs2[i] | |
47 | p = s / float(i); |
|
48 | p = s / float(i); | |
48 | p2 = p**2; |
|
49 | p2 = p**2; | |
49 | q = s2 / float(i) - p2; |
|
50 | q = s2 / float(i) - p2; | |
50 | leftc = p2; |
|
51 | leftc = p2; | |
51 | rightc = q * float(navg); |
|
52 | rightc = q * float(navg); | |
52 | R2 = leftc/rightc |
|
53 | R2 = leftc/rightc | |
53 |
|
54 | |||
54 | # Signal detect: R2 < 1 (R2 = leftc/rightc) |
|
55 | # Signal detect: R2 < 1 (R2 = leftc/rightc) | |
55 | if R2 < 1: |
|
56 | if R2 < 1: | |
56 | npts_noise = i |
|
57 | npts_noise = i | |
57 | break |
|
58 | break | |
58 |
|
59 | |||
59 |
|
60 | |||
60 | anoise = numpy.average(dataflat[0:npts_noise]) |
|
61 | anoise = numpy.average(dataflat[0:npts_noise]) | |
61 |
|
62 | |||
62 | return anoise; |
|
63 | return anoise; | |
63 |
|
64 | |||
64 | def sorting_bruce(data, navg): |
|
65 | def sorting_bruce(data, navg): | |
65 |
|
66 | |||
66 | data = data.copy() |
|
67 | data = data.copy() | |
67 |
|
68 | |||
68 | sortdata = numpy.sort(data) |
|
69 | sortdata = numpy.sort(data) | |
69 | lenOfData = len(data) |
|
70 | lenOfData = len(data) | |
70 | nums_min = lenOfData/10 |
|
71 | nums_min = lenOfData/10 | |
71 |
|
72 | |||
72 | if (lenOfData/10) > 0: |
|
73 | if (lenOfData/10) > 0: | |
73 | nums_min = lenOfData/10 |
|
74 | nums_min = lenOfData/10 | |
74 | else: |
|
75 | else: | |
75 | nums_min = 0 |
|
76 | nums_min = 0 | |
76 |
|
77 | |||
77 | rtest = 1.0 + 1.0/navg |
|
78 | rtest = 1.0 + 1.0/navg | |
78 |
|
79 | |||
79 | sum = 0. |
|
80 | sum = 0. | |
80 |
|
81 | |||
81 | sumq = 0. |
|
82 | sumq = 0. | |
82 |
|
83 | |||
83 | j = 0 |
|
84 | j = 0 | |
84 |
|
85 | |||
85 | cont = 1 |
|
86 | cont = 1 | |
86 |
|
87 | |||
87 | while((cont==1)and(j<lenOfData)): |
|
88 | while((cont==1)and(j<lenOfData)): | |
88 |
|
89 | |||
89 | sum += sortdata[j] |
|
90 | sum += sortdata[j] | |
90 |
|
91 | |||
91 | sumq += sortdata[j]**2 |
|
92 | sumq += sortdata[j]**2 | |
92 |
|
93 | |||
93 | j += 1 |
|
94 | j += 1 | |
94 |
|
95 | |||
95 | if j > nums_min: |
|
96 | if j > nums_min: | |
96 | if ((sumq*j) <= (rtest*sum**2)): |
|
97 | if ((sumq*j) <= (rtest*sum**2)): | |
97 | lnoise = sum / j |
|
98 | lnoise = sum / j | |
98 | else: |
|
99 | else: | |
99 | j = j - 1 |
|
100 | j = j - 1 | |
100 | sum = sum - sordata[j] |
|
101 | sum = sum - sordata[j] | |
101 | sumq = sumq - sordata[j]**2 |
|
102 | sumq = sumq - sordata[j]**2 | |
102 | cont = 0 |
|
103 | cont = 0 | |
103 |
|
104 | |||
104 | if j == nums_min: |
|
105 | if j == nums_min: | |
105 | lnoise = sum /j |
|
106 | lnoise = sum /j | |
106 |
|
107 | |||
107 | return lnoise |
|
108 | return lnoise | |
108 |
|
109 | |||
109 | class JROData: |
|
110 | class JROData: | |
110 |
|
111 | |||
111 | # m_BasicHeader = BasicHeader() |
|
112 | # m_BasicHeader = BasicHeader() | |
112 | # m_ProcessingHeader = ProcessingHeader() |
|
113 | # m_ProcessingHeader = ProcessingHeader() | |
113 |
|
114 | |||
114 | systemHeaderObj = SystemHeader() |
|
115 | systemHeaderObj = SystemHeader() | |
115 |
|
116 | |||
116 | radarControllerHeaderObj = RadarControllerHeader() |
|
117 | radarControllerHeaderObj = RadarControllerHeader() | |
117 |
|
118 | |||
118 | # data = None |
|
119 | # data = None | |
119 |
|
120 | |||
120 | type = None |
|
121 | type = None | |
121 |
|
122 | |||
122 | dtype = None |
|
123 | dtype = None | |
123 |
|
124 | |||
124 | # nChannels = None |
|
125 | # nChannels = None | |
125 |
|
126 | |||
126 | # nHeights = None |
|
127 | # nHeights = None | |
127 |
|
128 | |||
128 | nProfiles = None |
|
129 | nProfiles = None | |
129 |
|
130 | |||
130 | heightList = None |
|
131 | heightList = None | |
131 |
|
132 | |||
132 | channelList = None |
|
133 | channelList = None | |
133 |
|
134 | |||
134 | flagNoData = True |
|
135 | flagNoData = True | |
135 |
|
136 | |||
136 | flagTimeBlock = False |
|
137 | flagTimeBlock = False | |
137 |
|
138 | |||
138 | utctime = None |
|
139 | utctime = None | |
139 |
|
140 | |||
140 | blocksize = None |
|
141 | blocksize = None | |
141 |
|
142 | |||
142 | nCode = None |
|
143 | nCode = None | |
143 |
|
144 | |||
144 | nBaud = None |
|
145 | nBaud = None | |
145 |
|
146 | |||
146 | code = None |
|
147 | code = None | |
147 |
|
148 | |||
148 | flagDecodeData = True #asumo q la data esta decodificada |
|
149 | flagDecodeData = True #asumo q la data esta decodificada | |
149 |
|
150 | |||
150 | flagDeflipData = True #asumo q la data esta sin flip |
|
151 | flagDeflipData = True #asumo q la data esta sin flip | |
151 |
|
152 | |||
152 | flagShiftFFT = False |
|
153 | flagShiftFFT = False | |
153 |
|
154 | |||
154 | ippSeconds = None |
|
155 | ippSeconds = None | |
155 |
|
156 | |||
156 | timeInterval = None |
|
157 | timeInterval = None | |
157 |
|
158 | |||
158 | nCohInt = None |
|
159 | nCohInt = None | |
159 |
|
160 | |||
160 | noise = None |
|
161 | noise = None | |
161 |
|
162 | |||
162 | #Speed of ligth |
|
163 | #Speed of ligth | |
163 | C = 3e8 |
|
164 | C = 3e8 | |
164 |
|
165 | |||
165 | frequency = 49.92e6 |
|
166 | frequency = 49.92e6 | |
166 |
|
167 | |||
167 | def __init__(self): |
|
168 | def __init__(self): | |
168 |
|
169 | |||
169 | raise ValueError, "This class has not been implemented" |
|
170 | raise ValueError, "This class has not been implemented" | |
170 |
|
171 | |||
171 | def copy(self, inputObj=None): |
|
172 | def copy(self, inputObj=None): | |
172 |
|
173 | |||
173 | if inputObj == None: |
|
174 | if inputObj == None: | |
174 | return copy.deepcopy(self) |
|
175 | return copy.deepcopy(self) | |
175 |
|
176 | |||
176 | for key in inputObj.__dict__.keys(): |
|
177 | for key in inputObj.__dict__.keys(): | |
177 | self.__dict__[key] = inputObj.__dict__[key] |
|
178 | self.__dict__[key] = inputObj.__dict__[key] | |
178 |
|
179 | |||
179 | def deepcopy(self): |
|
180 | def deepcopy(self): | |
180 |
|
181 | |||
181 | return copy.deepcopy(self) |
|
182 | return copy.deepcopy(self) | |
182 |
|
183 | |||
183 | def isEmpty(self): |
|
184 | def isEmpty(self): | |
184 |
|
185 | |||
185 | return self.flagNoData |
|
186 | return self.flagNoData | |
186 |
|
187 | |||
187 | def getNoise(self): |
|
188 | def getNoise(self): | |
188 |
|
189 | |||
189 | raise ValueError, "Not implemented" |
|
190 | raise ValueError, "Not implemented" | |
190 |
|
191 | |||
191 | def getNChannels(self): |
|
192 | def getNChannels(self): | |
192 |
|
193 | |||
193 | return len(self.channelList) |
|
194 | return len(self.channelList) | |
194 |
|
195 | |||
195 | def getChannelIndexList(self): |
|
196 | def getChannelIndexList(self): | |
196 |
|
197 | |||
197 | return range(self.nChannels) |
|
198 | return range(self.nChannels) | |
198 |
|
199 | |||
199 | def getNHeights(self): |
|
200 | def getNHeights(self): | |
200 |
|
201 | |||
201 | return len(self.heightList) |
|
202 | return len(self.heightList) | |
202 |
|
203 | |||
203 | def getHeiRange(self, extrapoints=0): |
|
204 | def getHeiRange(self, extrapoints=0): | |
204 |
|
205 | |||
205 | heis = self.heightList |
|
206 | heis = self.heightList | |
206 | # deltah = self.heightList[1] - self.heightList[0] |
|
207 | # deltah = self.heightList[1] - self.heightList[0] | |
207 | # |
|
208 | # | |
208 | # heis.append(self.heightList[-1]) |
|
209 | # heis.append(self.heightList[-1]) | |
209 |
|
210 | |||
210 | return heis |
|
211 | return heis | |
211 |
|
212 | |||
212 | def getDatatime(self): |
|
213 | def getDatatime(self): | |
213 |
|
214 | |||
|
215 | datatime = datetime.datetime.utcfromtimestamp(self.utctime) | |||
|
216 | return datatime | |||
|
217 | ||||
|
218 | def getTimeRange(self): | |||
|
219 | ||||
214 | datatime = [] |
|
220 | datatime = [] | |
215 |
|
221 | |||
216 | datatime.append(self.utctime) |
|
222 | datatime.append(self.utctime) | |
217 | datatime.append(self.utctime + self.timeInterval) |
|
223 | datatime.append(self.utctime + self.timeInterval) | |
218 |
|
224 | |||
219 | datatime = numpy.array(datatime) |
|
225 | datatime = numpy.array(datatime) | |
220 |
|
226 | |||
221 | return datatime |
|
227 | return datatime | |
222 |
|
228 | |||
223 | def getFmax(self): |
|
229 | def getFmax(self): | |
224 |
|
230 | |||
225 | PRF = 1./(self.ippSeconds * self.nCohInt) |
|
231 | PRF = 1./(self.ippSeconds * self.nCohInt) | |
226 |
|
232 | |||
227 | fmax = PRF/2. |
|
233 | fmax = PRF/2. | |
228 |
|
234 | |||
229 | return fmax |
|
235 | return fmax | |
230 |
|
236 | |||
231 | def getVmax(self): |
|
237 | def getVmax(self): | |
232 |
|
238 | |||
233 | _lambda = self.C/self.frequency |
|
239 | _lambda = self.C/self.frequency | |
234 |
|
240 | |||
235 | vmax = self.getFmax() * _lambda / 2. |
|
241 | vmax = self.getFmax() * _lambda / 2. | |
236 |
|
242 | |||
237 | return vmax |
|
243 | return vmax | |
238 |
|
244 | |||
239 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") |
|
245 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") | |
240 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") |
|
246 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") | |
241 |
|
||||
242 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") |
|
247 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") | |
243 |
|
||||
244 | noise = property(getNoise, "I'm the 'nHeights' property.") |
|
248 | noise = property(getNoise, "I'm the 'nHeights' property.") | |
|
249 | datatime = property(getDatatime, "I'm the 'datatime' property") | |||
245 |
|
250 | |||
246 | class Voltage(JROData): |
|
251 | class Voltage(JROData): | |
247 |
|
252 | |||
248 | #data es un numpy array de 2 dmensiones (canales, alturas) |
|
253 | #data es un numpy array de 2 dmensiones (canales, alturas) | |
249 | data = None |
|
254 | data = None | |
250 |
|
255 | |||
251 | def __init__(self): |
|
256 | def __init__(self): | |
252 | ''' |
|
257 | ''' | |
253 | Constructor |
|
258 | Constructor | |
254 | ''' |
|
259 | ''' | |
255 |
|
260 | |||
256 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
261 | self.radarControllerHeaderObj = RadarControllerHeader() | |
257 |
|
262 | |||
258 | self.systemHeaderObj = SystemHeader() |
|
263 | self.systemHeaderObj = SystemHeader() | |
259 |
|
264 | |||
260 | self.type = "Voltage" |
|
265 | self.type = "Voltage" | |
261 |
|
266 | |||
262 | self.data = None |
|
267 | self.data = None | |
263 |
|
268 | |||
264 | self.dtype = None |
|
269 | self.dtype = None | |
265 |
|
270 | |||
266 | # self.nChannels = 0 |
|
271 | # self.nChannels = 0 | |
267 |
|
272 | |||
268 | # self.nHeights = 0 |
|
273 | # self.nHeights = 0 | |
269 |
|
274 | |||
270 | self.nProfiles = None |
|
275 | self.nProfiles = None | |
271 |
|
276 | |||
272 | self.heightList = None |
|
277 | self.heightList = None | |
273 |
|
278 | |||
274 | self.channelList = None |
|
279 | self.channelList = None | |
275 |
|
280 | |||
276 | # self.channelIndexList = None |
|
281 | # self.channelIndexList = None | |
277 |
|
282 | |||
278 | self.flagNoData = True |
|
283 | self.flagNoData = True | |
279 |
|
284 | |||
280 | self.flagTimeBlock = False |
|
285 | self.flagTimeBlock = False | |
281 |
|
286 | |||
282 | self.utctime = None |
|
287 | self.utctime = None | |
283 |
|
288 | |||
284 | self.nCohInt = None |
|
289 | self.nCohInt = None | |
285 |
|
290 | |||
286 | self.blocksize = None |
|
291 | self.blocksize = None | |
287 |
|
292 | |||
288 | def getNoisebyHildebrand(self): |
|
293 | def getNoisebyHildebrand(self): | |
289 | """ |
|
294 | """ | |
290 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
|
295 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon | |
291 |
|
296 | |||
292 | Return: |
|
297 | Return: | |
293 | noiselevel |
|
298 | noiselevel | |
294 | """ |
|
299 | """ | |
295 |
|
300 | |||
296 | for channel in range(self.nChannels): |
|
301 | for channel in range(self.nChannels): | |
297 | daux = self.data_spc[channel,:,:] |
|
302 | daux = self.data_spc[channel,:,:] | |
298 | self.noise[channel] = hildebrand_sekhon(daux, self.nCohInt) |
|
303 | self.noise[channel] = hildebrand_sekhon(daux, self.nCohInt) | |
299 |
|
304 | |||
300 | return self.noise |
|
305 | return self.noise | |
301 |
|
306 | |||
302 | def getNoise(self, type = 1): |
|
307 | def getNoise(self, type = 1): | |
303 |
|
308 | |||
304 | self.noise = numpy.zeros(self.nChannels) |
|
309 | self.noise = numpy.zeros(self.nChannels) | |
305 |
|
310 | |||
306 | if type == 1: |
|
311 | if type == 1: | |
307 | noise = self.getNoisebyHildebrand() |
|
312 | noise = self.getNoisebyHildebrand() | |
308 |
|
313 | |||
309 | return 10*numpy.log10(noise) |
|
314 | return 10*numpy.log10(noise) | |
310 |
|
315 | |||
311 | class Spectra(JROData): |
|
316 | class Spectra(JROData): | |
312 |
|
317 | |||
313 | #data es un numpy array de 2 dmensiones (canales, perfiles, alturas) |
|
318 | #data es un numpy array de 2 dmensiones (canales, perfiles, alturas) | |
314 | data_spc = None |
|
319 | data_spc = None | |
315 |
|
320 | |||
316 | #data es un numpy array de 2 dmensiones (canales, pares, alturas) |
|
321 | #data es un numpy array de 2 dmensiones (canales, pares, alturas) | |
317 | data_cspc = None |
|
322 | data_cspc = None | |
318 |
|
323 | |||
319 | #data es un numpy array de 2 dmensiones (canales, alturas) |
|
324 | #data es un numpy array de 2 dmensiones (canales, alturas) | |
320 | data_dc = None |
|
325 | data_dc = None | |
321 |
|
326 | |||
322 | nFFTPoints = None |
|
327 | nFFTPoints = None | |
323 |
|
328 | |||
324 | nPairs = None |
|
329 | nPairs = None | |
325 |
|
330 | |||
326 | pairsList = None |
|
331 | pairsList = None | |
327 |
|
332 | |||
328 | nIncohInt = None |
|
333 | nIncohInt = None | |
329 |
|
334 | |||
330 | wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia |
|
335 | wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia | |
331 |
|
336 | |||
332 | nCohInt = None #se requiere para determinar el valor de timeInterval |
|
337 | nCohInt = None #se requiere para determinar el valor de timeInterval | |
333 |
|
338 | |||
334 | def __init__(self): |
|
339 | def __init__(self): | |
335 | ''' |
|
340 | ''' | |
336 | Constructor |
|
341 | Constructor | |
337 | ''' |
|
342 | ''' | |
338 |
|
343 | |||
339 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
344 | self.radarControllerHeaderObj = RadarControllerHeader() | |
340 |
|
345 | |||
341 | self.systemHeaderObj = SystemHeader() |
|
346 | self.systemHeaderObj = SystemHeader() | |
342 |
|
347 | |||
343 | self.type = "Spectra" |
|
348 | self.type = "Spectra" | |
344 |
|
349 | |||
345 | # self.data = None |
|
350 | # self.data = None | |
346 |
|
351 | |||
347 | self.dtype = None |
|
352 | self.dtype = None | |
348 |
|
353 | |||
349 | # self.nChannels = 0 |
|
354 | # self.nChannels = 0 | |
350 |
|
355 | |||
351 | # self.nHeights = 0 |
|
356 | # self.nHeights = 0 | |
352 |
|
357 | |||
353 | self.nProfiles = None |
|
358 | self.nProfiles = None | |
354 |
|
359 | |||
355 | self.heightList = None |
|
360 | self.heightList = None | |
356 |
|
361 | |||
357 | self.channelList = None |
|
362 | self.channelList = None | |
358 |
|
363 | |||
359 | # self.channelIndexList = None |
|
364 | # self.channelIndexList = None | |
360 |
|
365 | |||
361 | self.flagNoData = True |
|
366 | self.flagNoData = True | |
362 |
|
367 | |||
363 | self.flagTimeBlock = False |
|
368 | self.flagTimeBlock = False | |
364 |
|
369 | |||
365 | self.utctime = None |
|
370 | self.utctime = None | |
366 |
|
371 | |||
367 | self.nCohInt = None |
|
372 | self.nCohInt = None | |
368 |
|
373 | |||
369 | self.nIncohInt = None |
|
374 | self.nIncohInt = None | |
370 |
|
375 | |||
371 | self.blocksize = None |
|
376 | self.blocksize = None | |
372 |
|
377 | |||
373 | self.nFFTPoints = None |
|
378 | self.nFFTPoints = None | |
374 |
|
379 | |||
375 | self.wavelength = None |
|
380 | self.wavelength = None | |
376 |
|
381 | |||
377 | def getNoisebyHildebrand(self): |
|
382 | def getNoisebyHildebrand(self): | |
378 | """ |
|
383 | """ | |
379 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
|
384 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon | |
380 |
|
385 | |||
381 | Return: |
|
386 | Return: | |
382 | noiselevel |
|
387 | noiselevel | |
383 | """ |
|
388 | """ | |
384 |
|
389 | |||
385 | for channel in range(self.nChannels): |
|
390 | for channel in range(self.nChannels): | |
386 | daux = self.data_spc[channel,:,:] |
|
391 | daux = self.data_spc[channel,:,:] | |
387 | self.noise[channel] = hildebrand_sekhon(daux, self.nIncohInt) |
|
392 | self.noise[channel] = hildebrand_sekhon(daux, self.nIncohInt) | |
388 |
|
393 | |||
389 | return self.noise |
|
394 | return self.noise | |
390 |
|
395 | |||
391 | def getNoisebyWindow(self, heiIndexMin=0, heiIndexMax=-1, freqIndexMin=0, freqIndexMax=-1): |
|
396 | def getNoisebyWindow(self, heiIndexMin=0, heiIndexMax=-1, freqIndexMin=0, freqIndexMax=-1): | |
392 | """ |
|
397 | """ | |
393 | Determina el ruido del canal utilizando la ventana indicada con las coordenadas: |
|
398 | Determina el ruido del canal utilizando la ventana indicada con las coordenadas: | |
394 | (heiIndexMIn, freqIndexMin) hasta (heiIndexMax, freqIndexMAx) |
|
399 | (heiIndexMIn, freqIndexMin) hasta (heiIndexMax, freqIndexMAx) | |
395 |
|
400 | |||
396 | Inputs: |
|
401 | Inputs: | |
397 | heiIndexMin: Limite inferior del eje de alturas |
|
402 | heiIndexMin: Limite inferior del eje de alturas | |
398 | heiIndexMax: Limite superior del eje de alturas |
|
403 | heiIndexMax: Limite superior del eje de alturas | |
399 | freqIndexMin: Limite inferior del eje de frecuencia |
|
404 | freqIndexMin: Limite inferior del eje de frecuencia | |
400 | freqIndexMax: Limite supoerior del eje de frecuencia |
|
405 | freqIndexMax: Limite supoerior del eje de frecuencia | |
401 | """ |
|
406 | """ | |
402 |
|
407 | |||
403 | data = self.data_spc[:, heiIndexMin:heiIndexMax, freqIndexMin:freqIndexMax] |
|
408 | data = self.data_spc[:, heiIndexMin:heiIndexMax, freqIndexMin:freqIndexMax] | |
404 |
|
409 | |||
405 | for channel in range(self.nChannels): |
|
410 | for channel in range(self.nChannels): | |
406 | daux = data[channel,:,:] |
|
411 | daux = data[channel,:,:] | |
407 | self.noise[channel] = numpy.average(daux) |
|
412 | self.noise[channel] = numpy.average(daux) | |
408 |
|
413 | |||
409 | return self.noise |
|
414 | return self.noise | |
410 |
|
415 | |||
411 | def getNoisebySort(self): |
|
416 | def getNoisebySort(self): | |
412 |
|
417 | |||
413 | for channel in range(self.nChannels): |
|
418 | for channel in range(self.nChannels): | |
414 | daux = self.data_spc[channel,:,:] |
|
419 | daux = self.data_spc[channel,:,:] | |
415 | self.noise[channel] = sorting_bruce(daux, self.nIncohInt) |
|
420 | self.noise[channel] = sorting_bruce(daux, self.nIncohInt) | |
416 |
|
421 | |||
417 | return self.noise |
|
422 | return self.noise | |
418 |
|
423 | |||
419 | def getNoise(self, type = 1): |
|
424 | def getNoise(self, type = 1): | |
420 |
|
425 | |||
421 | self.noise = numpy.zeros(self.nChannels) |
|
426 | self.noise = numpy.zeros(self.nChannels) | |
422 |
|
427 | |||
423 | if type == 1: |
|
428 | if type == 1: | |
424 | noise = self.getNoisebyHildebrand() |
|
429 | noise = self.getNoisebyHildebrand() | |
425 |
|
430 | |||
426 | if type == 2: |
|
431 | if type == 2: | |
427 | noise = self.getNoisebySort() |
|
432 | noise = self.getNoisebySort() | |
428 |
|
433 | |||
429 | if type == 3: |
|
434 | if type == 3: | |
430 | noise = self.getNoisebyWindow() |
|
435 | noise = self.getNoisebyWindow() | |
431 |
|
436 | |||
432 | return 10*numpy.log10(noise) |
|
437 | return 10*numpy.log10(noise) | |
433 |
|
438 | |||
434 |
|
439 | |||
435 | def getFreqRange(self, extrapoints=0): |
|
440 | def getFreqRange(self, extrapoints=0): | |
436 |
|
441 | |||
437 | delfreq = 2 * self.getFmax() / self.nFFTPoints |
|
442 | delfreq = 2 * self.getFmax() / self.nFFTPoints | |
438 | freqrange = deltafreqs*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 |
|
443 | freqrange = deltafreqs*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 | |
439 |
|
444 | |||
440 | return freqrange |
|
445 | return freqrange | |
441 |
|
446 | |||
442 | def getVelRange(self, extrapoints=0): |
|
447 | def getVelRange(self, extrapoints=0): | |
443 |
|
448 | |||
444 | deltav = 2 * self.getVmax() / self.nFFTPoints |
|
449 | deltav = 2 * self.getVmax() / self.nFFTPoints | |
445 | velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltav/2 |
|
450 | velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltav/2 | |
446 |
|
451 | |||
447 | return velrange |
|
452 | return velrange | |
448 |
|
453 | |||
449 | def getNPairs(self): |
|
454 | def getNPairs(self): | |
450 |
|
455 | |||
451 | return len(self.pairsList) |
|
456 | return len(self.pairsList) | |
452 |
|
457 | |||
453 | def getPairsIndexList(self): |
|
458 | def getPairsIndexList(self): | |
454 |
|
459 | |||
455 | return range(self.nPairs) |
|
460 | return range(self.nPairs) | |
456 |
|
461 | |||
457 | nPairs = property(getNPairs, "I'm the 'nPairs' property.") |
|
462 | nPairs = property(getNPairs, "I'm the 'nPairs' property.") | |
458 | pairsIndexList = property(getPairsIndexList, "I'm the 'pairsIndexList' property.") |
|
463 | pairsIndexList = property(getPairsIndexList, "I'm the 'pairsIndexList' property.") | |
459 |
|
464 | |||
460 | class SpectraHeis(JROData): |
|
465 | class SpectraHeis(JROData): | |
461 |
|
466 | |||
462 | data_spc = None |
|
467 | data_spc = None | |
463 |
|
468 | |||
464 | data_cspc = None |
|
469 | data_cspc = None | |
465 |
|
470 | |||
466 | data_dc = None |
|
471 | data_dc = None | |
467 |
|
472 | |||
468 | nFFTPoints = None |
|
473 | nFFTPoints = None | |
469 |
|
474 | |||
470 | nPairs = None |
|
475 | nPairs = None | |
471 |
|
476 | |||
472 | pairsList = None |
|
477 | pairsList = None | |
473 |
|
478 | |||
474 | nIncohInt = None |
|
479 | nIncohInt = None | |
475 |
|
480 | |||
476 | def __init__(self): |
|
481 | def __init__(self): | |
477 |
|
482 | |||
478 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
483 | self.radarControllerHeaderObj = RadarControllerHeader() | |
479 |
|
484 | |||
480 | self.systemHeaderObj = SystemHeader() |
|
485 | self.systemHeaderObj = SystemHeader() | |
481 |
|
486 | |||
482 | self.type = "SpectraHeis" |
|
487 | self.type = "SpectraHeis" | |
483 |
|
488 | |||
484 | self.dtype = None |
|
489 | self.dtype = None | |
485 |
|
490 | |||
486 | # self.nChannels = 0 |
|
491 | # self.nChannels = 0 | |
487 |
|
492 | |||
488 | # self.nHeights = 0 |
|
493 | # self.nHeights = 0 | |
489 |
|
494 | |||
490 | self.nProfiles = None |
|
495 | self.nProfiles = None | |
491 |
|
496 | |||
492 | self.heightList = None |
|
497 | self.heightList = None | |
493 |
|
498 | |||
494 | self.channelList = None |
|
499 | self.channelList = None | |
495 |
|
500 | |||
496 | # self.channelIndexList = None |
|
501 | # self.channelIndexList = None | |
497 |
|
502 | |||
498 | self.flagNoData = True |
|
503 | self.flagNoData = True | |
499 |
|
504 | |||
500 | self.flagTimeBlock = False |
|
505 | self.flagTimeBlock = False | |
501 |
|
506 | |||
502 | self.nPairs = 0 |
|
507 | self.nPairs = 0 | |
503 |
|
508 | |||
504 | self.utctime = None |
|
509 | self.utctime = None | |
505 |
|
510 | |||
506 | self.blocksize = None |
|
511 | self.blocksize = None |
@@ -1,2516 +1,2541 | |||||
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 isFileinThisTime(filename, startTime, endTime): | |||
|
78 | """ | |||
|
79 | Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado. | |||
|
80 | ||||
|
81 | Inputs: | |||
|
82 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) | |||
|
83 | ||||
|
84 | startTime : tiempo inicial del rango seleccionado en formato datetime.time | |||
|
85 | ||||
|
86 | endTime : tiempo final del rango seleccionado en formato datetime.time | |||
|
87 | ||||
|
88 | Return: | |||
|
89 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de | |||
|
90 | fecha especificado, de lo contrario retorna False. | |||
|
91 | ||||
|
92 | Excepciones: | |||
|
93 | Si el archivo no existe o no puede ser abierto | |||
|
94 | Si la cabecera no puede ser leida. | |||
|
95 | ||||
|
96 | """ | |||
|
97 | ||||
|
98 | ||||
|
99 | try: | |||
|
100 | fp = open(filename,'rb') | |||
|
101 | except: | |||
|
102 | raise IOError, "The file %s can't be opened" %(filename) | |||
|
103 | ||||
|
104 | basicHeaderObj = BasicHeader() | |||
|
105 | sts = basicHeaderObj.read(fp) | |||
|
106 | fp.close() | |||
|
107 | ||||
|
108 | thisTime = basicHeaderObj.datatime.time() | |||
|
109 | ||||
|
110 | if not(sts): | |||
|
111 | print "Skipping the file %s because it has not a valid header" %(filename) | |||
|
112 | return 0 | |||
|
113 | ||||
|
114 | if not ((startTime <= thisTime) and (endTime > thisTime)): | |||
|
115 | return 0 | |||
|
116 | ||||
|
117 | return 1 | |||
|
118 | ||||
77 | def getlastFileFromPath(path, ext): |
|
119 | def getlastFileFromPath(path, ext): | |
78 | """ |
|
120 | """ | |
79 | Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext" |
|
121 | 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. |
|
122 | al final de la depuracion devuelve el ultimo file de la lista que quedo. | |
81 |
|
123 | |||
82 | Input: |
|
124 | Input: | |
83 | fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta |
|
125 | fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta | |
84 | ext : extension de los files contenidos en una carpeta |
|
126 | ext : extension de los files contenidos en una carpeta | |
85 |
|
127 | |||
86 | Return: |
|
128 | Return: | |
87 | El ultimo file de una determinada carpeta, no se considera el path. |
|
129 | El ultimo file de una determinada carpeta, no se considera el path. | |
88 | """ |
|
130 | """ | |
89 | validFilelist = [] |
|
131 | validFilelist = [] | |
90 | fileList = os.listdir(path) |
|
132 | fileList = os.listdir(path) | |
91 |
|
133 | |||
92 | # 0 1234 567 89A BCDE |
|
134 | # 0 1234 567 89A BCDE | |
93 | # H YYYY DDD SSS .ext |
|
135 | # H YYYY DDD SSS .ext | |
94 |
|
136 | |||
95 | for file in fileList: |
|
137 | for file in fileList: | |
96 | try: |
|
138 | try: | |
97 | year = int(file[1:5]) |
|
139 | year = int(file[1:5]) | |
98 | doy = int(file[5:8]) |
|
140 | doy = int(file[5:8]) | |
99 |
|
141 | |||
100 | if (os.path.splitext(file)[-1].upper() != ext.upper()) : continue |
|
142 | ||
101 | except: |
|
143 | except: | |
102 | continue |
|
144 | continue | |
103 |
|
145 | |||
|
146 | if (os.path.splitext(file)[-1].lower() != ext.lower()): | |||
|
147 | continue | |||
|
148 | ||||
104 | validFilelist.append(file) |
|
149 | validFilelist.append(file) | |
105 |
|
150 | |||
106 | if validFilelist: |
|
151 | if validFilelist: | |
107 | validFilelist = sorted( validFilelist, key=str.lower ) |
|
152 | validFilelist = sorted( validFilelist, key=str.lower ) | |
108 | return validFilelist[-1] |
|
153 | return validFilelist[-1] | |
109 |
|
154 | |||
110 | return None |
|
155 | return None | |
111 |
|
156 | |||
112 | def checkForRealPath(path, year, doy, set, ext): |
|
157 | def checkForRealPath(path, year, doy, set, ext): | |
113 | """ |
|
158 | """ | |
114 | Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path, |
|
159 | 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 |
|
160 | Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar | |
116 | el path exacto de un determinado file. |
|
161 | el path exacto de un determinado file. | |
117 |
|
162 | |||
118 | Example : |
|
163 | Example : | |
119 | nombre correcto del file es .../.../D2009307/P2009307367.ext |
|
164 | nombre correcto del file es .../.../D2009307/P2009307367.ext | |
120 |
|
165 | |||
121 | Entonces la funcion prueba con las siguientes combinaciones |
|
166 | Entonces la funcion prueba con las siguientes combinaciones | |
|
167 | .../.../y2009307367.ext | |||
|
168 | .../.../Y2009307367.ext | |||
122 | .../.../x2009307/y2009307367.ext |
|
169 | .../.../x2009307/y2009307367.ext | |
123 | .../.../x2009307/Y2009307367.ext |
|
170 | .../.../x2009307/Y2009307367.ext | |
124 | .../.../X2009307/y2009307367.ext |
|
171 | .../.../X2009307/y2009307367.ext | |
125 | .../.../X2009307/Y2009307367.ext |
|
172 | .../.../X2009307/Y2009307367.ext | |
126 | siendo para este caso, la ultima combinacion de letras, identica al file buscado |
|
173 | siendo para este caso, la ultima combinacion de letras, identica al file buscado | |
127 |
|
174 | |||
128 | Return: |
|
175 | Return: | |
129 | Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file |
|
176 | 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 |
|
177 | caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas | |
131 | para el filename |
|
178 | para el filename | |
132 | """ |
|
179 | """ | |
133 |
f |
|
180 | fullfilename = None | |
134 | find_flag = False |
|
181 | find_flag = False | |
135 | filename = None |
|
182 | filename = None | |
136 |
|
183 | |||
|
184 | prefixDirList = [None,'d','D'] | |||
137 | if ext.lower() == ".r": #voltage |
|
185 | if ext.lower() == ".r": #voltage | |
138 | header1 = "dD" |
|
186 | prefixFileList = ['d','D'] | |
139 | header2 = "dD" |
|
|||
140 | elif ext.lower() == ".pdata": #spectra |
|
187 | elif ext.lower() == ".pdata": #spectra | |
141 | header1 = "dD" |
|
188 | prefixFileList = ['p','P'] | |
142 | header2 = "pP" |
|
|||
143 | else: |
|
189 | else: | |
144 | return None, filename |
|
190 | return None, filename | |
|
191 | ||||
|
192 | #barrido por las combinaciones posibles | |||
|
193 | for prefixDir in prefixDirList: | |||
|
194 | thispath = path | |||
|
195 | if prefixDir != None: | |||
|
196 | #formo el nombre del directorio xYYYYDDD (x=d o x=D) | |||
|
197 | thispath = os.path.join(path, "%s%04d%03d" % ( prefixDir, year, doy )) | |||
|
198 | ||||
|
199 | for prefixFile in prefixFileList: #barrido por las dos combinaciones posibles de "D" | |||
|
200 | filename = "%s%04d%03d%03d%s" % ( prefixFile, year, doy, set, ext ) #formo el nombre del file xYYYYDDDSSS.ext | |||
|
201 | fullfilename = os.path.join( thispath, filename ) #formo el path completo | |||
145 |
|
202 | |||
146 | for dir in header1: #barrido por las dos combinaciones posibles de "D" |
|
203 | if os.path.exists( fullfilename ): #verifico que exista | |
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) |
|
|||
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 |
|
|||
151 | if os.path.exists( filepath ): #verifico que exista |
|
|||
152 | find_flag = True |
|
204 | find_flag = True | |
153 | break |
|
205 | break | |
154 | if find_flag: |
|
206 | if find_flag: | |
155 | break |
|
207 | break | |
156 |
|
208 | |||
157 | if not(find_flag): |
|
209 | if not(find_flag): | |
158 | return None, filename |
|
210 | return None, filename | |
159 |
|
211 | |||
160 |
return f |
|
212 | return fullfilename, filename | |
161 |
|
213 | |||
162 | class JRODataIO: |
|
214 | class JRODataIO: | |
163 |
|
215 | |||
164 | c = 3E8 |
|
216 | c = 3E8 | |
165 |
|
217 | |||
166 | isConfig = False |
|
218 | isConfig = False | |
167 |
|
219 | |||
168 | basicHeaderObj = BasicHeader() |
|
220 | basicHeaderObj = BasicHeader() | |
169 |
|
221 | |||
170 | systemHeaderObj = SystemHeader() |
|
222 | systemHeaderObj = SystemHeader() | |
171 |
|
223 | |||
172 | radarControllerHeaderObj = RadarControllerHeader() |
|
224 | radarControllerHeaderObj = RadarControllerHeader() | |
173 |
|
225 | |||
174 | processingHeaderObj = ProcessingHeader() |
|
226 | processingHeaderObj = ProcessingHeader() | |
175 |
|
227 | |||
176 | online = 0 |
|
228 | online = 0 | |
177 |
|
229 | |||
178 | dtype = None |
|
230 | dtype = None | |
179 |
|
231 | |||
180 | pathList = [] |
|
232 | pathList = [] | |
181 |
|
233 | |||
182 | filenameList = [] |
|
234 | filenameList = [] | |
183 |
|
235 | |||
184 | filename = None |
|
236 | filename = None | |
185 |
|
237 | |||
186 | ext = None |
|
238 | ext = None | |
187 |
|
239 | |||
188 | flagIsNewFile = 1 |
|
240 | flagIsNewFile = 1 | |
189 |
|
241 | |||
190 | flagTimeBlock = 0 |
|
242 | flagTimeBlock = 0 | |
191 |
|
243 | |||
192 | flagIsNewBlock = 0 |
|
244 | flagIsNewBlock = 0 | |
193 |
|
245 | |||
194 | fp = None |
|
246 | fp = None | |
195 |
|
247 | |||
196 | firstHeaderSize = 0 |
|
248 | firstHeaderSize = 0 | |
197 |
|
249 | |||
198 | basicHeaderSize = 24 |
|
250 | basicHeaderSize = 24 | |
199 |
|
251 | |||
200 | versionFile = 1103 |
|
252 | versionFile = 1103 | |
201 |
|
253 | |||
202 | fileSize = None |
|
254 | fileSize = None | |
203 |
|
255 | |||
204 | ippSeconds = None |
|
256 | ippSeconds = None | |
205 |
|
257 | |||
206 | fileSizeByHeader = None |
|
258 | fileSizeByHeader = None | |
207 |
|
259 | |||
208 | fileIndex = None |
|
260 | fileIndex = None | |
209 |
|
261 | |||
210 | profileIndex = None |
|
262 | profileIndex = None | |
211 |
|
263 | |||
212 | blockIndex = None |
|
264 | blockIndex = None | |
213 |
|
265 | |||
214 | nTotalBlocks = None |
|
266 | nTotalBlocks = None | |
215 |
|
267 | |||
216 | maxTimeStep = 30 |
|
268 | maxTimeStep = 30 | |
217 |
|
269 | |||
218 | lastUTTime = None |
|
270 | lastUTTime = None | |
219 |
|
271 | |||
220 | datablock = None |
|
272 | datablock = None | |
221 |
|
273 | |||
222 | dataOut = None |
|
274 | dataOut = None | |
223 |
|
275 | |||
224 | blocksize = None |
|
276 | blocksize = None | |
225 |
|
277 | |||
226 | def __init__(self): |
|
278 | def __init__(self): | |
227 |
|
279 | |||
228 | raise ValueError, "Not implemented" |
|
280 | raise ValueError, "Not implemented" | |
229 |
|
281 | |||
230 | def run(self): |
|
282 | def run(self): | |
231 |
|
283 | |||
232 | raise ValueError, "Not implemented" |
|
284 | raise ValueError, "Not implemented" | |
233 |
|
285 | |||
234 | def getOutput(self): |
|
286 | def getOutput(self): | |
235 |
|
287 | |||
236 | return self.dataOut |
|
288 | return self.dataOut | |
237 |
|
289 | |||
238 | class JRODataReader(JRODataIO, ProcessingUnit): |
|
290 | class JRODataReader(JRODataIO, ProcessingUnit): | |
239 |
|
291 | |||
240 | nReadBlocks = 0 |
|
292 | nReadBlocks = 0 | |
241 |
|
293 | |||
242 | delay = 10 #number of seconds waiting a new file |
|
294 | delay = 10 #number of seconds waiting a new file | |
243 |
|
295 | |||
244 | nTries = 3 #quantity tries |
|
296 | nTries = 3 #quantity tries | |
245 |
|
297 | |||
246 | nFiles = 3 #number of files for searching |
|
298 | nFiles = 3 #number of files for searching | |
247 |
|
299 | |||
248 | flagNoMoreFiles = 0 |
|
300 | flagNoMoreFiles = 0 | |
249 |
|
301 | |||
250 | def __init__(self): |
|
302 | def __init__(self): | |
251 |
|
303 | |||
252 | """ |
|
304 | """ | |
253 |
|
305 | |||
254 | """ |
|
306 | """ | |
255 |
|
307 | |||
256 | raise ValueError, "This method has not been implemented" |
|
308 | raise ValueError, "This method has not been implemented" | |
257 |
|
309 | |||
258 |
|
310 | |||
259 | def createObjByDefault(self): |
|
311 | def createObjByDefault(self): | |
260 | """ |
|
312 | """ | |
261 |
|
313 | |||
262 | """ |
|
314 | """ | |
263 | raise ValueError, "This method has not been implemented" |
|
315 | raise ValueError, "This method has not been implemented" | |
264 |
|
316 | |||
265 | def getBlockDimension(self): |
|
317 | def getBlockDimension(self): | |
266 |
|
318 | |||
267 | raise ValueError, "No implemented" |
|
319 | raise ValueError, "No implemented" | |
268 |
|
320 | |||
269 | def __searchFilesOffLine(self, |
|
321 | def __searchFilesOffLine(self, | |
270 | path, |
|
322 | path, | |
271 | startDate, |
|
323 | startDate, | |
272 | endDate, |
|
324 | endDate, | |
273 | startTime=datetime.time(0,0,0), |
|
325 | startTime=datetime.time(0,0,0), | |
274 | endTime=datetime.time(23,59,59), |
|
326 | endTime=datetime.time(23,59,59), | |
275 | set=None, |
|
327 | set=None, | |
276 |
expLabel= |
|
328 | expLabel='', | |
277 |
ext= |
|
329 | ext='.r', | |
278 | dirList = [] |
|
330 | walk=True): | |
279 | for thisPath in os.listdir(path): |
|
|||
280 | if os.path.isdir(os.path.join(path,thisPath)): |
|
|||
281 | dirList.append(thisPath) |
|
|||
282 |
|
||||
283 | if not(dirList): |
|
|||
284 | return None, None |
|
|||
285 |
|
||||
286 | pathList = [] |
|
|||
287 | dateList = [] |
|
|||
288 |
|
331 | |||
289 |
this |
|
332 | pathList = [] | |
290 |
|
333 | |||
291 | while(thisDate <= endDate): |
|
334 | if not walk: | |
292 | year = thisDate.timetuple().tm_year |
|
335 | pathList.append(path) | |
293 | doy = thisDate.timetuple().tm_yday |
|
|||
294 |
|
336 | |||
295 | match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy)) |
|
337 | else: | |
296 |
|
|
338 | dirList = [] | |
297 | thisDate += datetime.timedelta(1) |
|
339 | for thisPath in os.listdir(path): | |
298 | continue |
|
340 | if os.path.isdir(os.path.join(path,thisPath)): | |
|
341 | dirList.append(thisPath) | |||
|
342 | ||||
|
343 | if not(dirList): | |||
|
344 | return None, None | |||
|
345 | ||||
|
346 | thisDate = startDate | |||
299 |
|
347 | |||
300 | pathList.append(os.path.join(path,match[0],expLabel)) |
|
348 | while(thisDate <= endDate): | |
301 | dateList.append(thisDate) |
|
349 | year = thisDate.timetuple().tm_year | |
302 | thisDate += datetime.timedelta(1) |
|
350 | doy = thisDate.timetuple().tm_yday | |
|
351 | ||||
|
352 | match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy)) | |||
|
353 | if len(match) == 0: | |||
|
354 | thisDate += datetime.timedelta(1) | |||
|
355 | continue | |||
|
356 | ||||
|
357 | pathList.append(os.path.join(path,match[0],expLabel)) | |||
|
358 | thisDate += datetime.timedelta(1) | |||
|
359 | ||||
303 |
|
360 | |||
304 | filenameList = [] |
|
361 | filenameList = [] | |
305 |
for |
|
362 | for thisPath in pathList: | |
306 |
|
363 | |||
307 | thisPath = pathList[index] |
|
|||
308 | fileList = glob.glob1(thisPath, "*%s" %ext) |
|
364 | fileList = glob.glob1(thisPath, "*%s" %ext) | |
309 | fileList.sort() |
|
365 | fileList.sort() | |
310 |
|
366 | |||
311 | #Busqueda de datos en el rango de horas indicados |
|
|||
312 | thisDate = dateList[index] |
|
|||
313 | startDT = datetime.datetime.combine(thisDate, startTime) |
|
|||
314 | endDT = datetime.datetime.combine(thisDate, endTime) |
|
|||
315 |
|
||||
316 | startUtSeconds = time.mktime(startDT.timetuple()) |
|
|||
317 | endUtSeconds = time.mktime(endDT.timetuple()) |
|
|||
318 |
|
||||
319 | for file in fileList: |
|
367 | for file in fileList: | |
320 |
|
368 | |||
321 | filename = os.path.join(thisPath,file) |
|
369 | filename = os.path.join(thisPath,file) | |
322 |
|
370 | |||
323 |
if |
|
371 | if isFileinThisTime(filename, startTime, endTime): | |
324 | filenameList.append(filename) |
|
372 | filenameList.append(filename) | |
325 |
|
373 | |||
326 | if not(filenameList): |
|
374 | if not(filenameList): | |
327 | return None, None |
|
375 | return None, None | |
328 |
|
376 | |||
329 | self.filenameList = filenameList |
|
377 | self.filenameList = filenameList | |
330 |
|
378 | |||
331 | return pathList, filenameList |
|
379 | return pathList, filenameList | |
332 |
|
380 | |||
333 |
def __searchFilesOnLine(self, path |
|
381 | def __searchFilesOnLine(self, path, expLabel = "", ext = None, walk=True): | |
334 |
|
382 | |||
335 | """ |
|
383 | """ | |
336 | Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y |
|
384 | Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y | |
337 | devuelve el archivo encontrado ademas de otros datos. |
|
385 | devuelve el archivo encontrado ademas de otros datos. | |
338 |
|
386 | |||
339 | Input: |
|
387 | Input: | |
340 | path : carpeta donde estan contenidos los files que contiene data |
|
388 | path : carpeta donde estan contenidos los files que contiene data | |
341 |
|
389 | |||
342 | startDate : Fecha inicial. Rechaza todos los directorios donde |
|
|||
343 | file end time < startDate (obejto datetime.date) |
|
|||
344 |
|
||||
345 | endDate : Fecha final. Rechaza todos los directorios donde |
|
|||
346 | file start time > endDate (obejto datetime.date) |
|
|||
347 |
|
||||
348 | startTime : Tiempo inicial. Rechaza todos los archivos donde |
|
|||
349 | file end time < startTime (obejto datetime.time) |
|
|||
350 |
|
||||
351 | endTime : Tiempo final. Rechaza todos los archivos donde |
|
|||
352 | file start time > endTime (obejto datetime.time) |
|
|||
353 |
|
||||
354 | expLabel : Nombre del subexperimento (subfolder) |
|
390 | expLabel : Nombre del subexperimento (subfolder) | |
355 |
|
391 | |||
356 |
ext : extension de los files |
|
392 | ext : extension de los files | |
|
393 | ||||
|
394 | walk : Si es habilitado no realiza busquedas dentro de los ubdirectorios (doypath) | |||
357 |
|
395 | |||
358 | Return: |
|
396 | Return: | |
359 | directory : eL directorio donde esta el file encontrado |
|
397 | directory : eL directorio donde esta el file encontrado | |
360 | filename : el ultimo file de una determinada carpeta |
|
398 | filename : el ultimo file de una determinada carpeta | |
361 | year : el anho |
|
399 | year : el anho | |
362 | doy : el numero de dia del anho |
|
400 | doy : el numero de dia del anho | |
363 | set : el set del archivo |
|
401 | set : el set del archivo | |
364 |
|
402 | |||
365 |
|
403 | |||
366 | """ |
|
404 | """ | |
367 | dirList = [] |
|
405 | dirList = [] | |
368 | pathList = [] |
|
|||
369 | directory = None |
|
|||
370 |
|
406 | |||
371 | #Filtra solo los directorios |
|
407 | if walk: | |
372 | for thisPath in os.listdir(path): |
|
|||
373 | if os.path.isdir(os.path.join(path, thisPath)): |
|
|||
374 | dirList.append(thisPath) |
|
|||
375 |
|
||||
376 | if not(dirList): |
|
|||
377 | return None, None, None, None, None |
|
|||
378 |
|
||||
379 | dirList = sorted( dirList, key=str.lower ) |
|
|||
380 |
|
||||
381 | if startDate: |
|
|||
382 | startDateTime = datetime.datetime.combine(startDate, startTime) |
|
|||
383 | thisDateTime = startDateTime |
|
|||
384 | if endDate == None: endDateTime = startDateTime |
|
|||
385 | else: endDateTime = datetime.datetime.combine(endDate, endTime) |
|
|||
386 |
|
408 | |||
387 | while(thisDateTime <= endDateTime): |
|
409 | #Filtra solo los directorios | |
388 | year = thisDateTime.timetuple().tm_year |
|
410 | for thisPath in os.listdir(path): | |
389 | doy = thisDateTime.timetuple().tm_yday |
|
411 | if os.path.isdir(os.path.join(path, thisPath)): | |
390 |
|
412 | dirList.append(thisPath) | ||
391 | match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy)) |
|
413 | ||
392 |
|
|
414 | if not(dirList): | |
393 | thisDateTime += datetime.timedelta(1) |
|
|||
394 | continue |
|
|||
395 |
|
||||
396 | pathList.append(os.path.join(path,match[0], expLabel)) |
|
|||
397 | thisDateTime += datetime.timedelta(1) |
|
|||
398 |
|
||||
399 | if not(pathList): |
|
|||
400 | print "\tNo files in range: %s - %s" %(startDateTime.ctime(), endDateTime.ctime()) |
|
|||
401 | return None, None, None, None, None |
|
415 | return None, None, None, None, None | |
402 |
|
416 | |||
403 | directory = pathList[0] |
|
417 | dirList = sorted( dirList, key=str.lower ) | |
404 |
|
418 | |||
|
419 | doypath = dirList[-1] | |||
|
420 | fullpath = os.path.join(path, doypath, expLabel) | |||
|
421 | ||||
405 | else: |
|
422 | else: | |
406 | directory = dirList[-1] |
|
423 | fullpath = path | |
407 | directory = os.path.join(path,directory) |
|
|||
408 |
|
424 | |||
409 |
filename = getlastFileFromPath( |
|
425 | filename = getlastFileFromPath(fullpath, ext) | |
410 |
|
426 | |||
411 | if not(filename): |
|
427 | if not(filename): | |
412 | return None, None, None, None, None |
|
428 | return None, None, None, None, None | |
413 |
|
429 | |||
414 |
if not(self.__verifyFile(os.path.join( |
|
430 | if not(self.__verifyFile(os.path.join(fullpath, filename))): | |
415 | return None, None, None, None, None |
|
431 | return None, None, None, None, None | |
416 |
|
432 | |||
417 | year = int( filename[1:5] ) |
|
433 | year = int( filename[1:5] ) | |
418 | doy = int( filename[5:8] ) |
|
434 | doy = int( filename[5:8] ) | |
419 | set = int( filename[8:11] ) |
|
435 | set = int( filename[8:11] ) | |
420 |
|
436 | |||
421 |
return |
|
437 | return fullpath, filename, year, doy, set | |
422 |
|
438 | |||
423 |
|
439 | |||
424 |
|
440 | |||
425 | def __setNextFileOffline(self): |
|
441 | def __setNextFileOffline(self): | |
426 |
|
442 | |||
427 | idFile = self.fileIndex |
|
443 | idFile = self.fileIndex | |
428 |
|
444 | |||
429 | while (True): |
|
445 | while (True): | |
430 | idFile += 1 |
|
446 | idFile += 1 | |
431 | if not(idFile < len(self.filenameList)): |
|
447 | if not(idFile < len(self.filenameList)): | |
432 | self.flagNoMoreFiles = 1 |
|
448 | self.flagNoMoreFiles = 1 | |
433 | print "No more Files" |
|
449 | print "No more Files" | |
434 | return 0 |
|
450 | return 0 | |
435 |
|
451 | |||
436 | filename = self.filenameList[idFile] |
|
452 | filename = self.filenameList[idFile] | |
437 |
|
453 | |||
438 | if not(self.__verifyFile(filename)): |
|
454 | if not(self.__verifyFile(filename)): | |
439 | continue |
|
455 | continue | |
440 |
|
456 | |||
441 | fileSize = os.path.getsize(filename) |
|
457 | fileSize = os.path.getsize(filename) | |
442 | fp = open(filename,'rb') |
|
458 | fp = open(filename,'rb') | |
443 | break |
|
459 | break | |
444 |
|
460 | |||
445 | self.flagIsNewFile = 1 |
|
461 | self.flagIsNewFile = 1 | |
446 | self.fileIndex = idFile |
|
462 | self.fileIndex = idFile | |
447 | self.filename = filename |
|
463 | self.filename = filename | |
448 | self.fileSize = fileSize |
|
464 | self.fileSize = fileSize | |
449 | self.fp = fp |
|
465 | self.fp = fp | |
450 |
|
466 | |||
451 | print "Setting the file: %s"%self.filename |
|
467 | print "Setting the file: %s"%self.filename | |
452 |
|
468 | |||
453 | return 1 |
|
469 | return 1 | |
454 |
|
470 | |||
455 | def __setNextFileOnline(self): |
|
471 | def __setNextFileOnline(self): | |
456 | """ |
|
472 | """ | |
457 | Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si |
|
473 | 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 |
|
474 | no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files | |
459 | siguientes. |
|
475 | siguientes. | |
460 |
|
476 | |||
461 | Affected: |
|
477 | Affected: | |
462 | self.flagIsNewFile |
|
478 | self.flagIsNewFile | |
463 | self.filename |
|
479 | self.filename | |
464 | self.fileSize |
|
480 | self.fileSize | |
465 | self.fp |
|
481 | self.fp | |
466 | self.set |
|
482 | self.set | |
467 | self.flagNoMoreFiles |
|
483 | self.flagNoMoreFiles | |
468 |
|
484 | |||
469 | Return: |
|
485 | Return: | |
470 | 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado |
|
486 | 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 |
|
487 | 1 : si el file fue abierto con exito y esta listo a ser leido | |
472 |
|
488 | |||
473 | Excepciones: |
|
489 | Excepciones: | |
474 | Si un determinado file no puede ser abierto |
|
490 | Si un determinado file no puede ser abierto | |
475 | """ |
|
491 | """ | |
476 | nFiles = 0 |
|
492 | nFiles = 0 | |
477 | fileOk_flag = False |
|
493 | fileOk_flag = False | |
478 | firstTime_flag = True |
|
494 | firstTime_flag = True | |
479 |
|
495 | |||
480 | self.set += 1 |
|
496 | self.set += 1 | |
481 |
|
497 | |||
482 | #busca el 1er file disponible |
|
498 | #busca el 1er file disponible | |
483 | file, filename = checkForRealPath( self.path, self.year, self.doy, self.set, self.ext ) |
|
499 | fullfilename, filename = checkForRealPath( self.path, self.year, self.doy, self.set, self.ext ) | |
484 | if file: |
|
500 | if fullfilename: | |
485 | if self.__verifyFile(file, False): |
|
501 | if self.__verifyFile(fullfilename, False): | |
486 | fileOk_flag = True |
|
502 | fileOk_flag = True | |
487 |
|
503 | |||
488 | #si no encuentra un file entonces espera y vuelve a buscar |
|
504 | #si no encuentra un file entonces espera y vuelve a buscar | |
489 | if not(fileOk_flag): |
|
505 | if not(fileOk_flag): | |
490 | for nFiles in range(self.nFiles+1): #busco en los siguientes self.nFiles+1 files posibles |
|
506 | for nFiles in range(self.nFiles+1): #busco en los siguientes self.nFiles+1 files posibles | |
491 |
|
507 | |||
492 | if firstTime_flag: #si es la 1era vez entonces hace el for self.nTries veces |
|
508 | if firstTime_flag: #si es la 1era vez entonces hace el for self.nTries veces | |
493 | tries = self.nTries |
|
509 | tries = self.nTries | |
494 | else: |
|
510 | else: | |
495 | tries = 1 #si no es la 1era vez entonces solo lo hace una vez |
|
511 | tries = 1 #si no es la 1era vez entonces solo lo hace una vez | |
496 |
|
512 | |||
497 | for nTries in range( tries ): |
|
513 | for nTries in range( tries ): | |
498 | if firstTime_flag: |
|
514 | if firstTime_flag: | |
499 | print "\tWaiting %0.2f sec for the file \"%s\" , try %03d ..." % ( self.delay, filename, nTries+1 ) |
|
515 | print "\tWaiting %0.2f sec for the file \"%s\" , try %03d ..." % ( self.delay, filename, nTries+1 ) | |
500 | time.sleep( self.delay ) |
|
516 | time.sleep( self.delay ) | |
501 | else: |
|
517 | else: | |
502 | print "\tSearching next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext) |
|
518 | print "\tSearching next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext) | |
503 |
|
519 | |||
504 | file, filename = checkForRealPath( self.path, self.year, self.doy, self.set, self.ext ) |
|
520 | fullfilename, filename = checkForRealPath( self.path, self.year, self.doy, self.set, self.ext ) | |
505 | if file: |
|
521 | if fullfilename: | |
506 | if self.__verifyFile(file): |
|
522 | if self.__verifyFile(fullfilename): | |
507 | fileOk_flag = True |
|
523 | fileOk_flag = True | |
508 | break |
|
524 | break | |
509 |
|
525 | |||
510 | if fileOk_flag: |
|
526 | if fileOk_flag: | |
511 | break |
|
527 | break | |
512 |
|
528 | |||
513 | firstTime_flag = False |
|
529 | firstTime_flag = False | |
514 |
|
530 | |||
515 | print "\tSkipping the file \"%s\" due to this file doesn't exist" % filename |
|
531 | print "\tSkipping the file \"%s\" due to this file doesn't exist" % filename | |
516 | self.set += 1 |
|
532 | self.set += 1 | |
517 |
|
533 | |||
518 | if nFiles == (self.nFiles-1): #si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta |
|
534 | if nFiles == (self.nFiles-1): #si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta | |
519 | self.set = 0 |
|
535 | self.set = 0 | |
520 | self.doy += 1 |
|
536 | self.doy += 1 | |
521 |
|
537 | |||
522 | if fileOk_flag: |
|
538 | if fileOk_flag: | |
523 | self.fileSize = os.path.getsize( file ) |
|
539 | self.fileSize = os.path.getsize( fullfilename ) | |
524 | self.filename = file |
|
540 | self.filename = fullfilename | |
525 | self.flagIsNewFile = 1 |
|
541 | self.flagIsNewFile = 1 | |
526 | if self.fp != None: self.fp.close() |
|
542 | if self.fp != None: self.fp.close() | |
527 | self.fp = open(file, 'rb') |
|
543 | self.fp = open(fullfilename, 'rb') | |
528 | self.flagNoMoreFiles = 0 |
|
544 | self.flagNoMoreFiles = 0 | |
529 | print 'Setting the file: %s' % file |
|
545 | print 'Setting the file: %s' % fullfilename | |
530 | else: |
|
546 | else: | |
531 | self.fileSize = 0 |
|
547 | self.fileSize = 0 | |
532 | self.filename = None |
|
548 | self.filename = None | |
533 | self.flagIsNewFile = 0 |
|
549 | self.flagIsNewFile = 0 | |
534 | self.fp = None |
|
550 | self.fp = None | |
535 | self.flagNoMoreFiles = 1 |
|
551 | self.flagNoMoreFiles = 1 | |
536 | print 'No more Files' |
|
552 | print 'No more Files' | |
537 |
|
553 | |||
538 | return fileOk_flag |
|
554 | return fileOk_flag | |
539 |
|
555 | |||
540 |
|
556 | |||
541 | def setNextFile(self): |
|
557 | def setNextFile(self): | |
542 | if self.fp != None: |
|
558 | if self.fp != None: | |
543 | self.fp.close() |
|
559 | self.fp.close() | |
544 |
|
560 | |||
545 | if self.online: |
|
561 | if self.online: | |
546 | newFile = self.__setNextFileOnline() |
|
562 | newFile = self.__setNextFileOnline() | |
547 | else: |
|
563 | else: | |
548 | newFile = self.__setNextFileOffline() |
|
564 | newFile = self.__setNextFileOffline() | |
549 |
|
565 | |||
550 | if not(newFile): |
|
566 | if not(newFile): | |
551 | return 0 |
|
567 | return 0 | |
552 |
|
568 | |||
553 | self.__readFirstHeader() |
|
569 | self.__readFirstHeader() | |
554 | self.nReadBlocks = 0 |
|
570 | self.nReadBlocks = 0 | |
555 | return 1 |
|
571 | return 1 | |
556 |
|
572 | |||
557 | def __waitNewBlock(self): |
|
573 | def __waitNewBlock(self): | |
558 | #si es OnLine y ademas aun no se han leido un bloque completo entonces se espera por uno valido |
|
574 | """ | |
|
575 | Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma. | |||
|
576 | ||||
|
577 | Si el modo de lectura es OffLine siempre retorn 0 | |||
|
578 | """ | |||
559 | if not self.online: |
|
579 | if not self.online: | |
560 | return 0 |
|
580 | return 0 | |
561 |
|
581 | |||
562 | if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile): |
|
582 | if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile): | |
563 | return 0 |
|
583 | return 0 | |
564 |
|
584 | |||
565 | currentPointer = self.fp.tell() |
|
585 | currentPointer = self.fp.tell() | |
566 |
|
586 | |||
567 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
587 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize | |
568 |
|
588 | |||
569 | for nTries in range( self.nTries ): |
|
589 | for nTries in range( self.nTries ): | |
570 |
|
590 | |||
571 | self.fp.close() |
|
591 | self.fp.close() | |
572 | self.fp = open( self.filename, 'rb' ) |
|
592 | self.fp = open( self.filename, 'rb' ) | |
573 | self.fp.seek( currentPointer ) |
|
593 | self.fp.seek( currentPointer ) | |
574 |
|
594 | |||
575 | self.fileSize = os.path.getsize( self.filename ) |
|
595 | self.fileSize = os.path.getsize( self.filename ) | |
576 | currentSize = self.fileSize - currentPointer |
|
596 | currentSize = self.fileSize - currentPointer | |
577 |
|
597 | |||
578 | if ( currentSize >= neededSize ): |
|
598 | if ( currentSize >= neededSize ): | |
579 | self.__rdBasicHeader() |
|
599 | self.__rdBasicHeader() | |
580 | return 1 |
|
600 | return 1 | |
581 |
|
601 | |||
582 | print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1) |
|
602 | print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1) | |
583 | time.sleep( self.delay ) |
|
603 | time.sleep( self.delay ) | |
584 |
|
604 | |||
585 |
|
605 | |||
586 | return 0 |
|
606 | return 0 | |
587 |
|
607 | |||
588 | def __setNewBlock(self): |
|
608 | def __setNewBlock(self): | |
|
609 | ||||
589 | if self.fp == None: |
|
610 | if self.fp == None: | |
590 | return 0 |
|
611 | return 0 | |
591 |
|
612 | |||
592 | if self.flagIsNewFile: |
|
613 | if self.flagIsNewFile: | |
593 | return 1 |
|
614 | return 1 | |
594 |
|
615 | |||
595 | self.lastUTTime = self.basicHeaderObj.utc |
|
616 | self.lastUTTime = self.basicHeaderObj.utc | |
596 | currentSize = self.fileSize - self.fp.tell() |
|
617 | currentSize = self.fileSize - self.fp.tell() | |
597 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
618 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize | |
598 |
|
619 | |||
599 | if (currentSize >= neededSize): |
|
620 | if (currentSize >= neededSize): | |
600 | self.__rdBasicHeader() |
|
621 | self.__rdBasicHeader() | |
601 | return 1 |
|
622 | return 1 | |
602 |
|
623 | |||
603 | if self.__waitNewBlock(): |
|
624 | if self.__waitNewBlock(): | |
604 | return 1 |
|
625 | return 1 | |
605 |
|
626 | |||
606 | if not(self.setNextFile()): |
|
627 | if not(self.setNextFile()): | |
607 | return 0 |
|
628 | return 0 | |
608 |
|
629 | |||
609 | deltaTime = self.basicHeaderObj.utc - self.lastUTTime # |
|
630 | deltaTime = self.basicHeaderObj.utc - self.lastUTTime # | |
610 |
|
631 | |||
611 | self.flagTimeBlock = 0 |
|
632 | self.flagTimeBlock = 0 | |
612 |
|
633 | |||
613 | if deltaTime > self.maxTimeStep: |
|
634 | if deltaTime > self.maxTimeStep: | |
614 | self.flagTimeBlock = 1 |
|
635 | self.flagTimeBlock = 1 | |
615 |
|
636 | |||
616 | return 1 |
|
637 | return 1 | |
617 |
|
638 | |||
618 |
|
639 | |||
619 | def readNextBlock(self): |
|
640 | def readNextBlock(self): | |
620 | if not(self.__setNewBlock()): |
|
641 | if not(self.__setNewBlock()): | |
621 | return 0 |
|
642 | return 0 | |
622 |
|
643 | |||
623 | if not(self.readBlock()): |
|
644 | if not(self.readBlock()): | |
624 | return 0 |
|
645 | return 0 | |
625 |
|
646 | |||
626 | return 1 |
|
647 | return 1 | |
627 |
|
648 | |||
628 | def __rdProcessingHeader(self, fp=None): |
|
649 | def __rdProcessingHeader(self, fp=None): | |
629 | if fp == None: |
|
650 | if fp == None: | |
630 | fp = self.fp |
|
651 | fp = self.fp | |
631 |
|
652 | |||
632 | self.processingHeaderObj.read(fp) |
|
653 | self.processingHeaderObj.read(fp) | |
633 |
|
654 | |||
634 | def __rdRadarControllerHeader(self, fp=None): |
|
655 | def __rdRadarControllerHeader(self, fp=None): | |
635 | if fp == None: |
|
656 | if fp == None: | |
636 | fp = self.fp |
|
657 | fp = self.fp | |
637 |
|
658 | |||
638 | self.radarControllerHeaderObj.read(fp) |
|
659 | self.radarControllerHeaderObj.read(fp) | |
639 |
|
660 | |||
640 | def __rdSystemHeader(self, fp=None): |
|
661 | def __rdSystemHeader(self, fp=None): | |
641 | if fp == None: |
|
662 | if fp == None: | |
642 | fp = self.fp |
|
663 | fp = self.fp | |
643 |
|
664 | |||
644 | self.systemHeaderObj.read(fp) |
|
665 | self.systemHeaderObj.read(fp) | |
645 |
|
666 | |||
646 | def __rdBasicHeader(self, fp=None): |
|
667 | def __rdBasicHeader(self, fp=None): | |
647 | if fp == None: |
|
668 | if fp == None: | |
648 | fp = self.fp |
|
669 | fp = self.fp | |
649 |
|
670 | |||
650 | self.basicHeaderObj.read(fp) |
|
671 | self.basicHeaderObj.read(fp) | |
651 |
|
672 | |||
652 |
|
673 | |||
653 | def __readFirstHeader(self): |
|
674 | def __readFirstHeader(self): | |
654 | self.__rdBasicHeader() |
|
675 | self.__rdBasicHeader() | |
655 | self.__rdSystemHeader() |
|
676 | self.__rdSystemHeader() | |
656 | self.__rdRadarControllerHeader() |
|
677 | self.__rdRadarControllerHeader() | |
657 | self.__rdProcessingHeader() |
|
678 | self.__rdProcessingHeader() | |
658 |
|
679 | |||
659 | self.firstHeaderSize = self.basicHeaderObj.size |
|
680 | self.firstHeaderSize = self.basicHeaderObj.size | |
660 |
|
681 | |||
661 | datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) |
|
682 | datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) | |
662 | if datatype == 0: |
|
683 | if datatype == 0: | |
663 | datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
684 | datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
664 | elif datatype == 1: |
|
685 | elif datatype == 1: | |
665 | datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
686 | datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
666 | elif datatype == 2: |
|
687 | elif datatype == 2: | |
667 | datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
688 | datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
668 | elif datatype == 3: |
|
689 | elif datatype == 3: | |
669 | datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
690 | datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
670 | elif datatype == 4: |
|
691 | elif datatype == 4: | |
671 | datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
692 | datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
672 | elif datatype == 5: |
|
693 | elif datatype == 5: | |
673 | datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
694 | datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
674 | else: |
|
695 | else: | |
675 | raise ValueError, 'Data type was not defined' |
|
696 | raise ValueError, 'Data type was not defined' | |
676 |
|
697 | |||
677 | self.dtype = datatype_str |
|
698 | self.dtype = datatype_str | |
678 | self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c |
|
699 | self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c | |
679 | self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1) |
|
700 | self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1) | |
680 | # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels) |
|
701 | # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels) | |
681 | # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels) |
|
702 | # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels) | |
682 | self.getBlockDimension() |
|
703 | self.getBlockDimension() | |
683 |
|
704 | |||
684 |
|
705 | |||
685 | def __verifyFile(self, filename, msgFlag=True): |
|
706 | def __verifyFile(self, filename, msgFlag=True): | |
686 | msg = None |
|
707 | msg = None | |
687 | try: |
|
708 | try: | |
688 | fp = open(filename, 'rb') |
|
709 | fp = open(filename, 'rb') | |
689 | currentPosition = fp.tell() |
|
710 | currentPosition = fp.tell() | |
690 | except: |
|
711 | except: | |
691 | if msgFlag: |
|
712 | if msgFlag: | |
692 | print "The file %s can't be opened" % (filename) |
|
713 | print "The file %s can't be opened" % (filename) | |
693 | return False |
|
714 | return False | |
694 |
|
715 | |||
695 | neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize |
|
716 | neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize | |
696 |
|
717 | |||
697 | if neededSize == 0: |
|
718 | if neededSize == 0: | |
698 | basicHeaderObj = BasicHeader() |
|
719 | basicHeaderObj = BasicHeader() | |
699 | systemHeaderObj = SystemHeader() |
|
720 | systemHeaderObj = SystemHeader() | |
700 | radarControllerHeaderObj = RadarControllerHeader() |
|
721 | radarControllerHeaderObj = RadarControllerHeader() | |
701 | processingHeaderObj = ProcessingHeader() |
|
722 | processingHeaderObj = ProcessingHeader() | |
702 |
|
723 | |||
703 | try: |
|
724 | try: | |
704 | if not( basicHeaderObj.read(fp) ): raise IOError |
|
725 | if not( basicHeaderObj.read(fp) ): raise IOError | |
705 | if not( systemHeaderObj.read(fp) ): raise IOError |
|
726 | if not( systemHeaderObj.read(fp) ): raise IOError | |
706 | if not( radarControllerHeaderObj.read(fp) ): raise IOError |
|
727 | if not( radarControllerHeaderObj.read(fp) ): raise IOError | |
707 | if not( processingHeaderObj.read(fp) ): raise IOError |
|
728 | if not( processingHeaderObj.read(fp) ): raise IOError | |
708 | data_type = int(numpy.log2((processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) |
|
729 | data_type = int(numpy.log2((processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) | |
709 |
|
730 | |||
710 | neededSize = processingHeaderObj.blockSize + basicHeaderObj.size |
|
731 | neededSize = processingHeaderObj.blockSize + basicHeaderObj.size | |
711 |
|
732 | |||
712 | except: |
|
733 | except: | |
713 | if msgFlag: |
|
734 | if msgFlag: | |
714 | print "\tThe file %s is empty or it hasn't enough data" % filename |
|
735 | print "\tThe file %s is empty or it hasn't enough data" % filename | |
715 |
|
736 | |||
716 | fp.close() |
|
737 | fp.close() | |
717 | return False |
|
738 | return False | |
718 | else: |
|
739 | else: | |
719 | msg = "\tSkipping the file %s due to it hasn't enough data" %filename |
|
740 | msg = "\tSkipping the file %s due to it hasn't enough data" %filename | |
720 |
|
741 | |||
721 | fp.close() |
|
742 | fp.close() | |
722 | fileSize = os.path.getsize(filename) |
|
743 | fileSize = os.path.getsize(filename) | |
723 | currentSize = fileSize - currentPosition |
|
744 | currentSize = fileSize - currentPosition | |
724 | if currentSize < neededSize: |
|
745 | if currentSize < neededSize: | |
725 | if msgFlag and (msg != None): |
|
746 | if msgFlag and (msg != None): | |
726 | print msg #print"\tSkipping the file %s due to it hasn't enough data" %filename |
|
747 | print msg #print"\tSkipping the file %s due to it hasn't enough data" %filename | |
727 | return False |
|
748 | return False | |
728 |
|
749 | |||
729 | return True |
|
750 | return True | |
730 |
|
751 | |||
731 | def setup(self, |
|
752 | def setup(self, | |
732 | path=None, |
|
753 | path=None, | |
733 | startDate=None, |
|
754 | startDate=None, | |
734 | endDate=None, |
|
755 | endDate=None, | |
735 | startTime=datetime.time(0,0,0), |
|
756 | startTime=datetime.time(0,0,0), | |
736 | endTime=datetime.time(23,59,59), |
|
757 | endTime=datetime.time(23,59,59), | |
737 | set=0, |
|
758 | set=0, | |
738 | expLabel = "", |
|
759 | expLabel = "", | |
739 | ext = None, |
|
760 | ext = None, | |
740 | online = False, |
|
761 | online = False, | |
741 |
delay = 60 |
|
762 | delay = 60, | |
|
763 | walk = True): | |||
742 |
|
764 | |||
743 | if path == None: |
|
765 | if path == None: | |
744 | raise ValueError, "The path is not valid" |
|
766 | raise ValueError, "The path is not valid" | |
745 |
|
767 | |||
746 | if ext == None: |
|
768 | if ext == None: | |
747 | ext = self.ext |
|
769 | ext = self.ext | |
748 |
|
770 | |||
749 | if online: |
|
771 | if online: | |
750 | print "Searching files in online mode..." |
|
772 | print "Searching files in online mode..." | |
751 | doypath, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext) |
|
773 | ||
752 |
|
774 | for nTries in range( self.nTries ): | ||
753 | if not(doypath): |
|
775 | fullpath, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext, walk=walk) | |
754 | for nTries in range( self.nTries ): |
|
776 | ||
755 | print '\tWaiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1) |
|
777 | if fullpath: | |
756 |
|
|
778 | break | |
757 | doypath, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext) |
|
779 | ||
758 | if doypath: |
|
780 | print '\tWaiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1) | |
759 | break |
|
781 | time.sleep( self.delay ) | |
760 |
|
782 | |||
761 |
if not( |
|
783 | if not(fullpath): | |
762 | print "There 'isn't valied files in %s" % path |
|
784 | print "There 'isn't valied files in %s" % path | |
763 | return None |
|
785 | return None | |
764 |
|
786 | |||
765 | self.year = year |
|
787 | self.year = year | |
766 | self.doy = doy |
|
788 | self.doy = doy | |
767 | self.set = set - 1 |
|
789 | self.set = set - 1 | |
768 | self.path = path |
|
790 | self.path = path | |
769 |
|
791 | |||
770 | else: |
|
792 | else: | |
771 | print "Searching files in offline mode ..." |
|
793 | print "Searching files in offline mode ..." | |
772 |
pathList, filenameList = self.__searchFilesOffLine(path, startDate, endDate, |
|
794 | pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate, | |
|
795 | startTime=startTime, endTime=endTime, | |||
|
796 | set=set, expLabel=expLabel, ext=ext, | |||
|
797 | walk=walk) | |||
773 |
|
798 | |||
774 | if not(pathList): |
|
799 | if not(pathList): | |
775 | print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path, |
|
800 | print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path, | |
776 | datetime.datetime.combine(startDate,startTime).ctime(), |
|
801 | datetime.datetime.combine(startDate,startTime).ctime(), | |
777 | datetime.datetime.combine(endDate,endTime).ctime()) |
|
802 | datetime.datetime.combine(endDate,endTime).ctime()) | |
778 |
|
803 | |||
779 | sys.exit(-1) |
|
804 | sys.exit(-1) | |
780 |
|
805 | |||
781 |
|
806 | |||
782 | self.fileIndex = -1 |
|
807 | self.fileIndex = -1 | |
783 | self.pathList = pathList |
|
808 | self.pathList = pathList | |
784 | self.filenameList = filenameList |
|
809 | self.filenameList = filenameList | |
785 |
|
810 | |||
786 | self.online = online |
|
811 | self.online = online | |
787 | self.delay = delay |
|
812 | self.delay = delay | |
788 | ext = ext.lower() |
|
813 | ext = ext.lower() | |
789 | self.ext = ext |
|
814 | self.ext = ext | |
790 |
|
815 | |||
791 | if not(self.setNextFile()): |
|
816 | if not(self.setNextFile()): | |
792 | if (startDate!=None) and (endDate!=None): |
|
817 | if (startDate!=None) and (endDate!=None): | |
793 | print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime()) |
|
818 | print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime()) | |
794 | elif startDate != None: |
|
819 | elif startDate != None: | |
795 | print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime()) |
|
820 | print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime()) | |
796 | else: |
|
821 | else: | |
797 | print "No files" |
|
822 | print "No files" | |
798 |
|
823 | |||
799 | sys.exit(-1) |
|
824 | sys.exit(-1) | |
800 |
|
825 | |||
801 | # self.updateDataHeader() |
|
826 | # self.updateDataHeader() | |
802 |
|
827 | |||
803 | return self.dataOut |
|
828 | return self.dataOut | |
804 |
|
829 | |||
805 | def getData(): |
|
830 | def getData(): | |
806 |
|
831 | |||
807 | raise ValueError, "This method has not been implemented" |
|
832 | raise ValueError, "This method has not been implemented" | |
808 |
|
833 | |||
809 | def hasNotDataInBuffer(): |
|
834 | def hasNotDataInBuffer(): | |
810 |
|
835 | |||
811 | raise ValueError, "This method has not been implemented" |
|
836 | raise ValueError, "This method has not been implemented" | |
812 |
|
837 | |||
813 | def readBlock(): |
|
838 | def readBlock(): | |
814 |
|
839 | |||
815 | raise ValueError, "This method has not been implemented" |
|
840 | raise ValueError, "This method has not been implemented" | |
816 |
|
841 | |||
817 | def isEndProcess(self): |
|
842 | def isEndProcess(self): | |
818 |
|
843 | |||
819 | return self.flagNoMoreFiles |
|
844 | return self.flagNoMoreFiles | |
820 |
|
845 | |||
821 | def printReadBlocks(self): |
|
846 | def printReadBlocks(self): | |
822 |
|
847 | |||
823 | print "Number of read blocks per file %04d" %self.nReadBlocks |
|
848 | print "Number of read blocks per file %04d" %self.nReadBlocks | |
824 |
|
849 | |||
825 | def printTotalBlocks(self): |
|
850 | def printTotalBlocks(self): | |
826 |
|
851 | |||
827 | print "Number of read blocks %04d" %self.nTotalBlocks |
|
852 | print "Number of read blocks %04d" %self.nTotalBlocks | |
828 |
|
853 | |||
829 | def printInfo(self): |
|
854 | def printInfo(self): | |
830 |
|
855 | |||
831 | print self.basicHeaderObj.printInfo() |
|
856 | print self.basicHeaderObj.printInfo() | |
832 | print self.systemHeaderObj.printInfo() |
|
857 | print self.systemHeaderObj.printInfo() | |
833 | print self.radarControllerHeaderObj.printInfo() |
|
858 | print self.radarControllerHeaderObj.printInfo() | |
834 | print self.processingHeaderObj.printInfo() |
|
859 | print self.processingHeaderObj.printInfo() | |
835 |
|
860 | |||
836 |
|
861 | |||
837 | def run(self, **kwargs): |
|
862 | def run(self, **kwargs): | |
838 |
|
863 | |||
839 | if not(self.isConfig): |
|
864 | if not(self.isConfig): | |
840 |
|
865 | |||
841 | # self.dataOut = dataOut |
|
866 | # self.dataOut = dataOut | |
842 | self.setup(**kwargs) |
|
867 | self.setup(**kwargs) | |
843 | self.isConfig = True |
|
868 | self.isConfig = True | |
844 |
|
869 | |||
845 | self.getData() |
|
870 | self.getData() | |
846 |
|
871 | |||
847 | class JRODataWriter(JRODataIO, Operation): |
|
872 | class JRODataWriter(JRODataIO, Operation): | |
848 |
|
873 | |||
849 | """ |
|
874 | """ | |
850 | Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura |
|
875 | Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura | |
851 | de los datos siempre se realiza por bloques. |
|
876 | de los datos siempre se realiza por bloques. | |
852 | """ |
|
877 | """ | |
853 |
|
878 | |||
854 | blockIndex = 0 |
|
879 | blockIndex = 0 | |
855 |
|
880 | |||
856 | path = None |
|
881 | path = None | |
857 |
|
882 | |||
858 | setFile = None |
|
883 | setFile = None | |
859 |
|
884 | |||
860 | profilesPerBlock = None |
|
885 | profilesPerBlock = None | |
861 |
|
886 | |||
862 | blocksPerFile = None |
|
887 | blocksPerFile = None | |
863 |
|
888 | |||
864 | nWriteBlocks = 0 |
|
889 | nWriteBlocks = 0 | |
865 |
|
890 | |||
866 | def __init__(self, dataOut=None): |
|
891 | def __init__(self, dataOut=None): | |
867 | raise ValueError, "Not implemented" |
|
892 | raise ValueError, "Not implemented" | |
868 |
|
893 | |||
869 |
|
894 | |||
870 | def hasAllDataInBuffer(self): |
|
895 | def hasAllDataInBuffer(self): | |
871 | raise ValueError, "Not implemented" |
|
896 | raise ValueError, "Not implemented" | |
872 |
|
897 | |||
873 |
|
898 | |||
874 | def setBlockDimension(self): |
|
899 | def setBlockDimension(self): | |
875 | raise ValueError, "Not implemented" |
|
900 | raise ValueError, "Not implemented" | |
876 |
|
901 | |||
877 |
|
902 | |||
878 | def writeBlock(self): |
|
903 | def writeBlock(self): | |
879 | raise ValueError, "No implemented" |
|
904 | raise ValueError, "No implemented" | |
880 |
|
905 | |||
881 |
|
906 | |||
882 | def putData(self): |
|
907 | def putData(self): | |
883 | raise ValueError, "No implemented" |
|
908 | raise ValueError, "No implemented" | |
884 |
|
909 | |||
885 | def getDataHeader(self): |
|
910 | def getDataHeader(self): | |
886 | """ |
|
911 | """ | |
887 | Obtiene una copia del First Header |
|
912 | Obtiene una copia del First Header | |
888 |
|
913 | |||
889 | Affected: |
|
914 | Affected: | |
890 |
|
915 | |||
891 | self.basicHeaderObj |
|
916 | self.basicHeaderObj | |
892 | self.systemHeaderObj |
|
917 | self.systemHeaderObj | |
893 | self.radarControllerHeaderObj |
|
918 | self.radarControllerHeaderObj | |
894 | self.processingHeaderObj self. |
|
919 | self.processingHeaderObj self. | |
895 |
|
920 | |||
896 | Return: |
|
921 | Return: | |
897 | None |
|
922 | None | |
898 | """ |
|
923 | """ | |
899 |
|
924 | |||
900 | raise ValueError, "No implemented" |
|
925 | raise ValueError, "No implemented" | |
901 |
|
926 | |||
902 | def getBasicHeader(self): |
|
927 | def getBasicHeader(self): | |
903 |
|
928 | |||
904 | self.basicHeaderObj.size = self.basicHeaderSize #bytes |
|
929 | self.basicHeaderObj.size = self.basicHeaderSize #bytes | |
905 | self.basicHeaderObj.version = self.versionFile |
|
930 | self.basicHeaderObj.version = self.versionFile | |
906 | self.basicHeaderObj.dataBlock = self.nTotalBlocks |
|
931 | self.basicHeaderObj.dataBlock = self.nTotalBlocks | |
907 |
|
932 | |||
908 | utc = numpy.floor(self.dataOut.utctime) |
|
933 | utc = numpy.floor(self.dataOut.utctime) | |
909 | milisecond = (self.dataOut.utctime - utc)* 1000.0 |
|
934 | milisecond = (self.dataOut.utctime - utc)* 1000.0 | |
910 |
|
935 | |||
911 | self.basicHeaderObj.utc = utc |
|
936 | self.basicHeaderObj.utc = utc | |
912 | self.basicHeaderObj.miliSecond = milisecond |
|
937 | self.basicHeaderObj.miliSecond = milisecond | |
913 | self.basicHeaderObj.timeZone = 0 |
|
938 | self.basicHeaderObj.timeZone = 0 | |
914 | self.basicHeaderObj.dstFlag = 0 |
|
939 | self.basicHeaderObj.dstFlag = 0 | |
915 | self.basicHeaderObj.errorCount = 0 |
|
940 | self.basicHeaderObj.errorCount = 0 | |
916 |
|
941 | |||
917 | def __writeFirstHeader(self): |
|
942 | def __writeFirstHeader(self): | |
918 | """ |
|
943 | """ | |
919 | Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader) |
|
944 | Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader) | |
920 |
|
945 | |||
921 | Affected: |
|
946 | Affected: | |
922 | __dataType |
|
947 | __dataType | |
923 |
|
948 | |||
924 | Return: |
|
949 | Return: | |
925 | None |
|
950 | None | |
926 | """ |
|
951 | """ | |
927 |
|
952 | |||
928 | # CALCULAR PARAMETROS |
|
953 | # CALCULAR PARAMETROS | |
929 |
|
954 | |||
930 | sizeLongHeader = self.systemHeaderObj.size + self.radarControllerHeaderObj.size + self.processingHeaderObj.size |
|
955 | sizeLongHeader = self.systemHeaderObj.size + self.radarControllerHeaderObj.size + self.processingHeaderObj.size | |
931 | self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader |
|
956 | self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader | |
932 |
|
957 | |||
933 | self.basicHeaderObj.write(self.fp) |
|
958 | self.basicHeaderObj.write(self.fp) | |
934 | self.systemHeaderObj.write(self.fp) |
|
959 | self.systemHeaderObj.write(self.fp) | |
935 | self.radarControllerHeaderObj.write(self.fp) |
|
960 | self.radarControllerHeaderObj.write(self.fp) | |
936 | self.processingHeaderObj.write(self.fp) |
|
961 | self.processingHeaderObj.write(self.fp) | |
937 |
|
962 | |||
938 | self.dtype = self.dataOut.dtype |
|
963 | self.dtype = self.dataOut.dtype | |
939 |
|
964 | |||
940 | def __setNewBlock(self): |
|
965 | def __setNewBlock(self): | |
941 | """ |
|
966 | """ | |
942 | Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header |
|
967 | Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header | |
943 |
|
968 | |||
944 | Return: |
|
969 | Return: | |
945 | 0 : si no pudo escribir nada |
|
970 | 0 : si no pudo escribir nada | |
946 | 1 : Si escribio el Basic el First Header |
|
971 | 1 : Si escribio el Basic el First Header | |
947 | """ |
|
972 | """ | |
948 | if self.fp == None: |
|
973 | if self.fp == None: | |
949 | self.setNextFile() |
|
974 | self.setNextFile() | |
950 |
|
975 | |||
951 | if self.flagIsNewFile: |
|
976 | if self.flagIsNewFile: | |
952 | return 1 |
|
977 | return 1 | |
953 |
|
978 | |||
954 | if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile: |
|
979 | if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile: | |
955 | self.basicHeaderObj.write(self.fp) |
|
980 | self.basicHeaderObj.write(self.fp) | |
956 | return 1 |
|
981 | return 1 | |
957 |
|
982 | |||
958 | if not( self.setNextFile() ): |
|
983 | if not( self.setNextFile() ): | |
959 | return 0 |
|
984 | return 0 | |
960 |
|
985 | |||
961 | return 1 |
|
986 | return 1 | |
962 |
|
987 | |||
963 |
|
988 | |||
964 | def writeNextBlock(self): |
|
989 | def writeNextBlock(self): | |
965 | """ |
|
990 | """ | |
966 | Selecciona el bloque siguiente de datos y los escribe en un file |
|
991 | Selecciona el bloque siguiente de datos y los escribe en un file | |
967 |
|
992 | |||
968 | Return: |
|
993 | Return: | |
969 | 0 : Si no hizo pudo escribir el bloque de datos |
|
994 | 0 : Si no hizo pudo escribir el bloque de datos | |
970 | 1 : Si no pudo escribir el bloque de datos |
|
995 | 1 : Si no pudo escribir el bloque de datos | |
971 | """ |
|
996 | """ | |
972 | if not( self.__setNewBlock() ): |
|
997 | if not( self.__setNewBlock() ): | |
973 | return 0 |
|
998 | return 0 | |
974 |
|
999 | |||
975 | self.writeBlock() |
|
1000 | self.writeBlock() | |
976 |
|
1001 | |||
977 | return 1 |
|
1002 | return 1 | |
978 |
|
1003 | |||
979 | def setNextFile(self): |
|
1004 | def setNextFile(self): | |
980 | """ |
|
1005 | """ | |
981 | Determina el siguiente file que sera escrito |
|
1006 | Determina el siguiente file que sera escrito | |
982 |
|
1007 | |||
983 | Affected: |
|
1008 | Affected: | |
984 | self.filename |
|
1009 | self.filename | |
985 | self.subfolder |
|
1010 | self.subfolder | |
986 | self.fp |
|
1011 | self.fp | |
987 | self.setFile |
|
1012 | self.setFile | |
988 | self.flagIsNewFile |
|
1013 | self.flagIsNewFile | |
989 |
|
1014 | |||
990 | Return: |
|
1015 | Return: | |
991 | 0 : Si el archivo no puede ser escrito |
|
1016 | 0 : Si el archivo no puede ser escrito | |
992 | 1 : Si el archivo esta listo para ser escrito |
|
1017 | 1 : Si el archivo esta listo para ser escrito | |
993 | """ |
|
1018 | """ | |
994 | ext = self.ext |
|
1019 | ext = self.ext | |
995 | path = self.path |
|
1020 | path = self.path | |
996 |
|
1021 | |||
997 | if self.fp != None: |
|
1022 | if self.fp != None: | |
998 | self.fp.close() |
|
1023 | self.fp.close() | |
999 |
|
1024 | |||
1000 | timeTuple = time.localtime( self.dataOut.dataUtcTime) |
|
1025 | timeTuple = time.localtime( self.dataOut.dataUtcTime) | |
1001 | subfolder = 'D%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) |
|
1026 | subfolder = 'D%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) | |
1002 |
|
1027 | |||
1003 |
|
|
1028 | fullpath = os.path.join( path, subfolder ) | |
1004 |
if not( os.path.exists( |
|
1029 | if not( os.path.exists(fullpath) ): | |
1005 |
os.mkdir( |
|
1030 | os.mkdir(fullpath) | |
1006 | self.setFile = -1 #inicializo mi contador de seteo |
|
1031 | self.setFile = -1 #inicializo mi contador de seteo | |
1007 | else: |
|
1032 | else: | |
1008 |
filesList = os.listdir( |
|
1033 | filesList = os.listdir( fullpath ) | |
1009 | if len( filesList ) > 0: |
|
1034 | if len( filesList ) > 0: | |
1010 | filesList = sorted( filesList, key=str.lower ) |
|
1035 | filesList = sorted( filesList, key=str.lower ) | |
1011 | filen = filesList[-1] |
|
1036 | filen = filesList[-1] | |
1012 | # el filename debera tener el siguiente formato |
|
1037 | # el filename debera tener el siguiente formato | |
1013 | # 0 1234 567 89A BCDE (hex) |
|
1038 | # 0 1234 567 89A BCDE (hex) | |
1014 | # x YYYY DDD SSS .ext |
|
1039 | # x YYYY DDD SSS .ext | |
1015 | if isNumber( filen[8:11] ): |
|
1040 | if isNumber( filen[8:11] ): | |
1016 | self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file |
|
1041 | self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file | |
1017 | else: |
|
1042 | else: | |
1018 | self.setFile = -1 |
|
1043 | self.setFile = -1 | |
1019 | else: |
|
1044 | else: | |
1020 | self.setFile = -1 #inicializo mi contador de seteo |
|
1045 | self.setFile = -1 #inicializo mi contador de seteo | |
1021 |
|
1046 | |||
1022 | setFile = self.setFile |
|
1047 | setFile = self.setFile | |
1023 | setFile += 1 |
|
1048 | setFile += 1 | |
1024 |
|
1049 | |||
1025 | file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar, |
|
1050 | file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar, | |
1026 | timeTuple.tm_year, |
|
1051 | timeTuple.tm_year, | |
1027 | timeTuple.tm_yday, |
|
1052 | timeTuple.tm_yday, | |
1028 | setFile, |
|
1053 | setFile, | |
1029 | ext ) |
|
1054 | ext ) | |
1030 |
|
1055 | |||
1031 | filename = os.path.join( path, subfolder, file ) |
|
1056 | filename = os.path.join( path, subfolder, file ) | |
1032 |
|
1057 | |||
1033 | fp = open( filename,'wb' ) |
|
1058 | fp = open( filename,'wb' ) | |
1034 |
|
1059 | |||
1035 | self.blockIndex = 0 |
|
1060 | self.blockIndex = 0 | |
1036 |
|
1061 | |||
1037 | #guardando atributos |
|
1062 | #guardando atributos | |
1038 | self.filename = filename |
|
1063 | self.filename = filename | |
1039 | self.subfolder = subfolder |
|
1064 | self.subfolder = subfolder | |
1040 | self.fp = fp |
|
1065 | self.fp = fp | |
1041 | self.setFile = setFile |
|
1066 | self.setFile = setFile | |
1042 | self.flagIsNewFile = 1 |
|
1067 | self.flagIsNewFile = 1 | |
1043 |
|
1068 | |||
1044 | self.getDataHeader() |
|
1069 | self.getDataHeader() | |
1045 |
|
1070 | |||
1046 | print 'Writing the file: %s'%self.filename |
|
1071 | print 'Writing the file: %s'%self.filename | |
1047 |
|
1072 | |||
1048 | self.__writeFirstHeader() |
|
1073 | self.__writeFirstHeader() | |
1049 |
|
1074 | |||
1050 | return 1 |
|
1075 | return 1 | |
1051 |
|
1076 | |||
1052 | def setup(self, dataOut, path, blocksPerFile, profilesPerBlock=None, set=0, ext=None): |
|
1077 | def setup(self, dataOut, path, blocksPerFile, profilesPerBlock=None, set=0, ext=None): | |
1053 | """ |
|
1078 | """ | |
1054 | Setea el tipo de formato en la cual sera guardada la data y escribe el First Header |
|
1079 | Setea el tipo de formato en la cual sera guardada la data y escribe el First Header | |
1055 |
|
1080 | |||
1056 | Inputs: |
|
1081 | Inputs: | |
1057 | path : el path destino en el cual se escribiran los files a crear |
|
1082 | path : el path destino en el cual se escribiran los files a crear | |
1058 | format : formato en el cual sera salvado un file |
|
1083 | format : formato en el cual sera salvado un file | |
1059 | set : el setebo del file |
|
1084 | set : el setebo del file | |
1060 |
|
1085 | |||
1061 | Return: |
|
1086 | Return: | |
1062 | 0 : Si no realizo un buen seteo |
|
1087 | 0 : Si no realizo un buen seteo | |
1063 | 1 : Si realizo un buen seteo |
|
1088 | 1 : Si realizo un buen seteo | |
1064 | """ |
|
1089 | """ | |
1065 |
|
1090 | |||
1066 | if ext == None: |
|
1091 | if ext == None: | |
1067 | ext = self.ext |
|
1092 | ext = self.ext | |
1068 |
|
1093 | |||
1069 | ext = ext.lower() |
|
1094 | ext = ext.lower() | |
1070 |
|
1095 | |||
1071 | self.ext = ext |
|
1096 | self.ext = ext | |
1072 |
|
1097 | |||
1073 | self.path = path |
|
1098 | self.path = path | |
1074 |
|
1099 | |||
1075 | self.setFile = set - 1 |
|
1100 | self.setFile = set - 1 | |
1076 |
|
1101 | |||
1077 | self.blocksPerFile = blocksPerFile |
|
1102 | self.blocksPerFile = blocksPerFile | |
1078 |
|
1103 | |||
1079 | self.profilesPerBlock = profilesPerBlock |
|
1104 | self.profilesPerBlock = profilesPerBlock | |
1080 |
|
1105 | |||
1081 | self.dataOut = dataOut |
|
1106 | self.dataOut = dataOut | |
1082 |
|
1107 | |||
1083 | if not(self.setNextFile()): |
|
1108 | if not(self.setNextFile()): | |
1084 | print "There isn't a next file" |
|
1109 | print "There isn't a next file" | |
1085 | return 0 |
|
1110 | return 0 | |
1086 |
|
1111 | |||
1087 | self.setBlockDimension() |
|
1112 | self.setBlockDimension() | |
1088 |
|
1113 | |||
1089 | return 1 |
|
1114 | return 1 | |
1090 |
|
1115 | |||
1091 | def run(self, dataOut, **kwargs): |
|
1116 | def run(self, dataOut, **kwargs): | |
1092 |
|
1117 | |||
1093 | if not(self.isConfig): |
|
1118 | if not(self.isConfig): | |
1094 |
|
1119 | |||
1095 | self.setup(dataOut, **kwargs) |
|
1120 | self.setup(dataOut, **kwargs) | |
1096 | self.isConfig = True |
|
1121 | self.isConfig = True | |
1097 |
|
1122 | |||
1098 | self.putData() |
|
1123 | self.putData() | |
1099 |
|
1124 | |||
1100 | class VoltageReader(JRODataReader): |
|
1125 | class VoltageReader(JRODataReader): | |
1101 | """ |
|
1126 | """ | |
1102 | Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura |
|
1127 | Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura | |
1103 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones: |
|
1128 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones: | |
1104 | perfiles*alturas*canales) son almacenados en la variable "buffer". |
|
1129 | perfiles*alturas*canales) son almacenados en la variable "buffer". | |
1105 |
|
1130 | |||
1106 | perfiles * alturas * canales |
|
1131 | perfiles * alturas * canales | |
1107 |
|
1132 | |||
1108 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, |
|
1133 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, | |
1109 | RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la |
|
1134 | RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la | |
1110 | cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de |
|
1135 | cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de | |
1111 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". |
|
1136 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". | |
1112 |
|
1137 | |||
1113 | Example: |
|
1138 | Example: | |
1114 |
|
1139 | |||
1115 | dpath = "/home/myuser/data" |
|
1140 | dpath = "/home/myuser/data" | |
1116 |
|
1141 | |||
1117 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) |
|
1142 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) | |
1118 |
|
1143 | |||
1119 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) |
|
1144 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) | |
1120 |
|
1145 | |||
1121 | readerObj = VoltageReader() |
|
1146 | readerObj = VoltageReader() | |
1122 |
|
1147 | |||
1123 | readerObj.setup(dpath, startTime, endTime) |
|
1148 | readerObj.setup(dpath, startTime, endTime) | |
1124 |
|
1149 | |||
1125 | while(True): |
|
1150 | while(True): | |
1126 |
|
1151 | |||
1127 | #to get one profile |
|
1152 | #to get one profile | |
1128 | profile = readerObj.getData() |
|
1153 | profile = readerObj.getData() | |
1129 |
|
1154 | |||
1130 | #print the profile |
|
1155 | #print the profile | |
1131 | print profile |
|
1156 | print profile | |
1132 |
|
1157 | |||
1133 | #If you want to see all datablock |
|
1158 | #If you want to see all datablock | |
1134 | print readerObj.datablock |
|
1159 | print readerObj.datablock | |
1135 |
|
1160 | |||
1136 | if readerObj.flagNoMoreFiles: |
|
1161 | if readerObj.flagNoMoreFiles: | |
1137 | break |
|
1162 | break | |
1138 |
|
1163 | |||
1139 | """ |
|
1164 | """ | |
1140 |
|
1165 | |||
1141 | ext = ".r" |
|
1166 | ext = ".r" | |
1142 |
|
1167 | |||
1143 | optchar = "D" |
|
1168 | optchar = "D" | |
1144 | dataOut = None |
|
1169 | dataOut = None | |
1145 |
|
1170 | |||
1146 |
|
1171 | |||
1147 | def __init__(self): |
|
1172 | def __init__(self): | |
1148 | """ |
|
1173 | """ | |
1149 | Inicializador de la clase VoltageReader para la lectura de datos de voltage. |
|
1174 | Inicializador de la clase VoltageReader para la lectura de datos de voltage. | |
1150 |
|
1175 | |||
1151 | Input: |
|
1176 | Input: | |
1152 | dataOut : Objeto de la clase Voltage. Este objeto sera utilizado para |
|
1177 | dataOut : Objeto de la clase Voltage. Este objeto sera utilizado para | |
1153 | almacenar un perfil de datos cada vez que se haga un requerimiento |
|
1178 | almacenar un perfil de datos cada vez que se haga un requerimiento | |
1154 | (getData). El perfil sera obtenido a partir del buffer de datos, |
|
1179 | (getData). El perfil sera obtenido a partir del buffer de datos, | |
1155 | si el buffer esta vacio se hara un nuevo proceso de lectura de un |
|
1180 | si el buffer esta vacio se hara un nuevo proceso de lectura de un | |
1156 | bloque de datos. |
|
1181 | bloque de datos. | |
1157 | Si este parametro no es pasado se creara uno internamente. |
|
1182 | Si este parametro no es pasado se creara uno internamente. | |
1158 |
|
1183 | |||
1159 | Variables afectadas: |
|
1184 | Variables afectadas: | |
1160 | self.dataOut |
|
1185 | self.dataOut | |
1161 |
|
1186 | |||
1162 | Return: |
|
1187 | Return: | |
1163 | None |
|
1188 | None | |
1164 | """ |
|
1189 | """ | |
1165 |
|
1190 | |||
1166 | self.isConfig = False |
|
1191 | self.isConfig = False | |
1167 |
|
1192 | |||
1168 | self.datablock = None |
|
1193 | self.datablock = None | |
1169 |
|
1194 | |||
1170 | self.utc = 0 |
|
1195 | self.utc = 0 | |
1171 |
|
1196 | |||
1172 | self.ext = ".r" |
|
1197 | self.ext = ".r" | |
1173 |
|
1198 | |||
1174 | self.optchar = "D" |
|
1199 | self.optchar = "D" | |
1175 |
|
1200 | |||
1176 | self.basicHeaderObj = BasicHeader() |
|
1201 | self.basicHeaderObj = BasicHeader() | |
1177 |
|
1202 | |||
1178 | self.systemHeaderObj = SystemHeader() |
|
1203 | self.systemHeaderObj = SystemHeader() | |
1179 |
|
1204 | |||
1180 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
1205 | self.radarControllerHeaderObj = RadarControllerHeader() | |
1181 |
|
1206 | |||
1182 | self.processingHeaderObj = ProcessingHeader() |
|
1207 | self.processingHeaderObj = ProcessingHeader() | |
1183 |
|
1208 | |||
1184 | self.online = 0 |
|
1209 | self.online = 0 | |
1185 |
|
1210 | |||
1186 | self.fp = None |
|
1211 | self.fp = None | |
1187 |
|
1212 | |||
1188 | self.idFile = None |
|
1213 | self.idFile = None | |
1189 |
|
1214 | |||
1190 | self.dtype = None |
|
1215 | self.dtype = None | |
1191 |
|
1216 | |||
1192 | self.fileSizeByHeader = None |
|
1217 | self.fileSizeByHeader = None | |
1193 |
|
1218 | |||
1194 | self.filenameList = [] |
|
1219 | self.filenameList = [] | |
1195 |
|
1220 | |||
1196 | self.filename = None |
|
1221 | self.filename = None | |
1197 |
|
1222 | |||
1198 | self.fileSize = None |
|
1223 | self.fileSize = None | |
1199 |
|
1224 | |||
1200 | self.firstHeaderSize = 0 |
|
1225 | self.firstHeaderSize = 0 | |
1201 |
|
1226 | |||
1202 | self.basicHeaderSize = 24 |
|
1227 | self.basicHeaderSize = 24 | |
1203 |
|
1228 | |||
1204 | self.pathList = [] |
|
1229 | self.pathList = [] | |
1205 |
|
1230 | |||
1206 | self.filenameList = [] |
|
1231 | self.filenameList = [] | |
1207 |
|
1232 | |||
1208 | self.lastUTTime = 0 |
|
1233 | self.lastUTTime = 0 | |
1209 |
|
1234 | |||
1210 | self.maxTimeStep = 30 |
|
1235 | self.maxTimeStep = 30 | |
1211 |
|
1236 | |||
1212 | self.flagNoMoreFiles = 0 |
|
1237 | self.flagNoMoreFiles = 0 | |
1213 |
|
1238 | |||
1214 | self.set = 0 |
|
1239 | self.set = 0 | |
1215 |
|
1240 | |||
1216 | self.path = None |
|
1241 | self.path = None | |
1217 |
|
1242 | |||
1218 | self.profileIndex = 9999 |
|
1243 | self.profileIndex = 9999 | |
1219 |
|
1244 | |||
1220 | self.delay = 3 #seconds |
|
1245 | self.delay = 3 #seconds | |
1221 |
|
1246 | |||
1222 | self.nTries = 3 #quantity tries |
|
1247 | self.nTries = 3 #quantity tries | |
1223 |
|
1248 | |||
1224 | self.nFiles = 3 #number of files for searching |
|
1249 | self.nFiles = 3 #number of files for searching | |
1225 |
|
1250 | |||
1226 | self.nReadBlocks = 0 |
|
1251 | self.nReadBlocks = 0 | |
1227 |
|
1252 | |||
1228 | self.flagIsNewFile = 1 |
|
1253 | self.flagIsNewFile = 1 | |
1229 |
|
1254 | |||
1230 | self.ippSeconds = 0 |
|
1255 | self.ippSeconds = 0 | |
1231 |
|
1256 | |||
1232 | self.flagTimeBlock = 0 |
|
1257 | self.flagTimeBlock = 0 | |
1233 |
|
1258 | |||
1234 | self.flagIsNewBlock = 0 |
|
1259 | self.flagIsNewBlock = 0 | |
1235 |
|
1260 | |||
1236 | self.nTotalBlocks = 0 |
|
1261 | self.nTotalBlocks = 0 | |
1237 |
|
1262 | |||
1238 | self.blocksize = 0 |
|
1263 | self.blocksize = 0 | |
1239 |
|
1264 | |||
1240 | self.dataOut = self.createObjByDefault() |
|
1265 | self.dataOut = self.createObjByDefault() | |
1241 |
|
1266 | |||
1242 | def createObjByDefault(self): |
|
1267 | def createObjByDefault(self): | |
1243 |
|
1268 | |||
1244 | dataObj = Voltage() |
|
1269 | dataObj = Voltage() | |
1245 |
|
1270 | |||
1246 | return dataObj |
|
1271 | return dataObj | |
1247 |
|
1272 | |||
1248 | def __hasNotDataInBuffer(self): |
|
1273 | def __hasNotDataInBuffer(self): | |
1249 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: |
|
1274 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: | |
1250 | return 1 |
|
1275 | return 1 | |
1251 | return 0 |
|
1276 | return 0 | |
1252 |
|
1277 | |||
1253 |
|
1278 | |||
1254 | def getBlockDimension(self): |
|
1279 | def getBlockDimension(self): | |
1255 | """ |
|
1280 | """ | |
1256 | Obtiene la cantidad de puntos a leer por cada bloque de datos |
|
1281 | Obtiene la cantidad de puntos a leer por cada bloque de datos | |
1257 |
|
1282 | |||
1258 | Affected: |
|
1283 | Affected: | |
1259 | self.blocksize |
|
1284 | self.blocksize | |
1260 |
|
1285 | |||
1261 | Return: |
|
1286 | Return: | |
1262 | None |
|
1287 | None | |
1263 | """ |
|
1288 | """ | |
1264 | pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels |
|
1289 | pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels | |
1265 | self.blocksize = pts2read |
|
1290 | self.blocksize = pts2read | |
1266 |
|
1291 | |||
1267 |
|
1292 | |||
1268 | def readBlock(self): |
|
1293 | def readBlock(self): | |
1269 | """ |
|
1294 | """ | |
1270 | readBlock lee el bloque de datos desde la posicion actual del puntero del archivo |
|
1295 | readBlock lee el bloque de datos desde la posicion actual del puntero del archivo | |
1271 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos |
|
1296 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos | |
1272 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer |
|
1297 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer | |
1273 | es seteado a 0 |
|
1298 | es seteado a 0 | |
1274 |
|
1299 | |||
1275 | Inputs: |
|
1300 | Inputs: | |
1276 | None |
|
1301 | None | |
1277 |
|
1302 | |||
1278 | Return: |
|
1303 | Return: | |
1279 | None |
|
1304 | None | |
1280 |
|
1305 | |||
1281 | Affected: |
|
1306 | Affected: | |
1282 | self.profileIndex |
|
1307 | self.profileIndex | |
1283 | self.datablock |
|
1308 | self.datablock | |
1284 | self.flagIsNewFile |
|
1309 | self.flagIsNewFile | |
1285 | self.flagIsNewBlock |
|
1310 | self.flagIsNewBlock | |
1286 | self.nTotalBlocks |
|
1311 | self.nTotalBlocks | |
1287 |
|
1312 | |||
1288 | Exceptions: |
|
1313 | Exceptions: | |
1289 | Si un bloque leido no es un bloque valido |
|
1314 | Si un bloque leido no es un bloque valido | |
1290 | """ |
|
1315 | """ | |
1291 |
|
1316 | |||
1292 | junk = numpy.fromfile( self.fp, self.dtype, self.blocksize ) |
|
1317 | junk = numpy.fromfile( self.fp, self.dtype, self.blocksize ) | |
1293 |
|
1318 | |||
1294 | try: |
|
1319 | try: | |
1295 | junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) |
|
1320 | junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) | |
1296 | except: |
|
1321 | except: | |
1297 | print "The read block (%3d) has not enough data" %self.nReadBlocks |
|
1322 | print "The read block (%3d) has not enough data" %self.nReadBlocks | |
1298 | return 0 |
|
1323 | return 0 | |
1299 |
|
1324 | |||
1300 | junk = numpy.transpose(junk, (2,0,1)) |
|
1325 | junk = numpy.transpose(junk, (2,0,1)) | |
1301 | self.datablock = junk['real'] + junk['imag']*1j |
|
1326 | self.datablock = junk['real'] + junk['imag']*1j | |
1302 |
|
1327 | |||
1303 | self.profileIndex = 0 |
|
1328 | self.profileIndex = 0 | |
1304 |
|
1329 | |||
1305 | self.flagIsNewFile = 0 |
|
1330 | self.flagIsNewFile = 0 | |
1306 | self.flagIsNewBlock = 1 |
|
1331 | self.flagIsNewBlock = 1 | |
1307 |
|
1332 | |||
1308 | self.nTotalBlocks += 1 |
|
1333 | self.nTotalBlocks += 1 | |
1309 | self.nReadBlocks += 1 |
|
1334 | self.nReadBlocks += 1 | |
1310 |
|
1335 | |||
1311 | return 1 |
|
1336 | return 1 | |
1312 |
|
1337 | |||
1313 |
|
1338 | |||
1314 | def getData(self): |
|
1339 | def getData(self): | |
1315 | """ |
|
1340 | """ | |
1316 | getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage" |
|
1341 | getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage" | |
1317 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de |
|
1342 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de | |
1318 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" |
|
1343 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" | |
1319 |
|
1344 | |||
1320 | Ademas incrementa el contador del buffer en 1. |
|
1345 | Ademas incrementa el contador del buffer en 1. | |
1321 |
|
1346 | |||
1322 | Return: |
|
1347 | Return: | |
1323 | data : retorna un perfil de voltages (alturas * canales) copiados desde el |
|
1348 | data : retorna un perfil de voltages (alturas * canales) copiados desde el | |
1324 | buffer. Si no hay mas archivos a leer retorna None. |
|
1349 | buffer. Si no hay mas archivos a leer retorna None. | |
1325 |
|
1350 | |||
1326 | Variables afectadas: |
|
1351 | Variables afectadas: | |
1327 | self.dataOut |
|
1352 | self.dataOut | |
1328 | self.profileIndex |
|
1353 | self.profileIndex | |
1329 |
|
1354 | |||
1330 | Affected: |
|
1355 | Affected: | |
1331 | self.dataOut |
|
1356 | self.dataOut | |
1332 | self.profileIndex |
|
1357 | self.profileIndex | |
1333 | self.flagTimeBlock |
|
1358 | self.flagTimeBlock | |
1334 | self.flagIsNewBlock |
|
1359 | self.flagIsNewBlock | |
1335 | """ |
|
1360 | """ | |
1336 |
|
1361 | |||
1337 | if self.flagNoMoreFiles: |
|
1362 | if self.flagNoMoreFiles: | |
1338 | self.dataOut.flagNoData = True |
|
1363 | self.dataOut.flagNoData = True | |
1339 | print 'Process finished' |
|
1364 | print 'Process finished' | |
1340 | return 0 |
|
1365 | return 0 | |
1341 |
|
1366 | |||
1342 | self.flagTimeBlock = 0 |
|
1367 | self.flagTimeBlock = 0 | |
1343 | self.flagIsNewBlock = 0 |
|
1368 | self.flagIsNewBlock = 0 | |
1344 |
|
1369 | |||
1345 | if self.__hasNotDataInBuffer(): |
|
1370 | if self.__hasNotDataInBuffer(): | |
1346 |
|
1371 | |||
1347 | if not( self.readNextBlock() ): |
|
1372 | if not( self.readNextBlock() ): | |
1348 | return 0 |
|
1373 | return 0 | |
1349 |
|
1374 | |||
1350 | self.dataOut.dtype = self.dtype |
|
1375 | self.dataOut.dtype = self.dtype | |
1351 |
|
1376 | |||
1352 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock |
|
1377 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock | |
1353 |
|
1378 | |||
1354 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight |
|
1379 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight | |
1355 |
|
1380 | |||
1356 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) |
|
1381 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) | |
1357 |
|
1382 | |||
1358 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) |
|
1383 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) | |
1359 |
|
1384 | |||
1360 | self.dataOut.flagTimeBlock = self.flagTimeBlock |
|
1385 | self.dataOut.flagTimeBlock = self.flagTimeBlock | |
1361 |
|
1386 | |||
1362 | self.dataOut.ippSeconds = self.ippSeconds |
|
1387 | self.dataOut.ippSeconds = self.ippSeconds | |
1363 |
|
1388 | |||
1364 | self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt |
|
1389 | self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt | |
1365 |
|
1390 | |||
1366 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt |
|
1391 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt | |
1367 |
|
1392 | |||
1368 | self.dataOut.flagShiftFFT = False |
|
1393 | self.dataOut.flagShiftFFT = False | |
1369 |
|
1394 | |||
1370 | if self.processingHeaderObj.code != None: |
|
1395 | if self.processingHeaderObj.code != None: | |
1371 | self.dataOut.nCode = self.processingHeaderObj.nCode |
|
1396 | self.dataOut.nCode = self.processingHeaderObj.nCode | |
1372 |
|
1397 | |||
1373 | self.dataOut.nBaud = self.processingHeaderObj.nBaud |
|
1398 | self.dataOut.nBaud = self.processingHeaderObj.nBaud | |
1374 |
|
1399 | |||
1375 | self.dataOut.code = self.processingHeaderObj.code |
|
1400 | self.dataOut.code = self.processingHeaderObj.code | |
1376 |
|
1401 | |||
1377 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() |
|
1402 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() | |
1378 |
|
1403 | |||
1379 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() |
|
1404 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() | |
1380 |
|
1405 | |||
1381 | # self.updateDataHeader() |
|
1406 | # self.updateDataHeader() | |
1382 |
|
1407 | |||
1383 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) |
|
1408 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) | |
1384 |
|
1409 | |||
1385 | if self.datablock == None: |
|
1410 | if self.datablock == None: | |
1386 | self.dataOut.flagNoData = True |
|
1411 | self.dataOut.flagNoData = True | |
1387 | return 0 |
|
1412 | return 0 | |
1388 |
|
1413 | |||
1389 | self.dataOut.data = self.datablock[:,self.profileIndex,:] |
|
1414 | self.dataOut.data = self.datablock[:,self.profileIndex,:] | |
1390 |
|
1415 | |||
1391 | self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.ippSeconds |
|
1416 | self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.ippSeconds | |
1392 |
|
1417 | |||
1393 | self.profileIndex += 1 |
|
1418 | self.profileIndex += 1 | |
1394 |
|
1419 | |||
1395 | self.dataOut.flagNoData = False |
|
1420 | self.dataOut.flagNoData = False | |
1396 |
|
1421 | |||
1397 | # print self.profileIndex, self.dataOut.utctime |
|
1422 | # print self.profileIndex, self.dataOut.utctime | |
1398 | # if self.profileIndex == 800: |
|
1423 | # if self.profileIndex == 800: | |
1399 | # a=1 |
|
1424 | # a=1 | |
1400 |
|
1425 | |||
1401 |
|
1426 | |||
1402 | return self.dataOut.data |
|
1427 | return self.dataOut.data | |
1403 |
|
1428 | |||
1404 |
|
1429 | |||
1405 | class VoltageWriter(JRODataWriter): |
|
1430 | class VoltageWriter(JRODataWriter): | |
1406 | """ |
|
1431 | """ | |
1407 | Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura |
|
1432 | Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura | |
1408 | de los datos siempre se realiza por bloques. |
|
1433 | de los datos siempre se realiza por bloques. | |
1409 | """ |
|
1434 | """ | |
1410 |
|
1435 | |||
1411 | ext = ".r" |
|
1436 | ext = ".r" | |
1412 |
|
1437 | |||
1413 | optchar = "D" |
|
1438 | optchar = "D" | |
1414 |
|
1439 | |||
1415 | shapeBuffer = None |
|
1440 | shapeBuffer = None | |
1416 |
|
1441 | |||
1417 |
|
1442 | |||
1418 | def __init__(self): |
|
1443 | def __init__(self): | |
1419 | """ |
|
1444 | """ | |
1420 | Inicializador de la clase VoltageWriter para la escritura de datos de espectros. |
|
1445 | Inicializador de la clase VoltageWriter para la escritura de datos de espectros. | |
1421 |
|
1446 | |||
1422 | Affected: |
|
1447 | Affected: | |
1423 | self.dataOut |
|
1448 | self.dataOut | |
1424 |
|
1449 | |||
1425 | Return: None |
|
1450 | Return: None | |
1426 | """ |
|
1451 | """ | |
1427 |
|
1452 | |||
1428 | self.nTotalBlocks = 0 |
|
1453 | self.nTotalBlocks = 0 | |
1429 |
|
1454 | |||
1430 | self.profileIndex = 0 |
|
1455 | self.profileIndex = 0 | |
1431 |
|
1456 | |||
1432 | self.isConfig = False |
|
1457 | self.isConfig = False | |
1433 |
|
1458 | |||
1434 | self.fp = None |
|
1459 | self.fp = None | |
1435 |
|
1460 | |||
1436 | self.flagIsNewFile = 1 |
|
1461 | self.flagIsNewFile = 1 | |
1437 |
|
1462 | |||
1438 | self.nTotalBlocks = 0 |
|
1463 | self.nTotalBlocks = 0 | |
1439 |
|
1464 | |||
1440 | self.flagIsNewBlock = 0 |
|
1465 | self.flagIsNewBlock = 0 | |
1441 |
|
1466 | |||
1442 | self.setFile = None |
|
1467 | self.setFile = None | |
1443 |
|
1468 | |||
1444 | self.dtype = None |
|
1469 | self.dtype = None | |
1445 |
|
1470 | |||
1446 | self.path = None |
|
1471 | self.path = None | |
1447 |
|
1472 | |||
1448 | self.filename = None |
|
1473 | self.filename = None | |
1449 |
|
1474 | |||
1450 | self.basicHeaderObj = BasicHeader() |
|
1475 | self.basicHeaderObj = BasicHeader() | |
1451 |
|
1476 | |||
1452 | self.systemHeaderObj = SystemHeader() |
|
1477 | self.systemHeaderObj = SystemHeader() | |
1453 |
|
1478 | |||
1454 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
1479 | self.radarControllerHeaderObj = RadarControllerHeader() | |
1455 |
|
1480 | |||
1456 | self.processingHeaderObj = ProcessingHeader() |
|
1481 | self.processingHeaderObj = ProcessingHeader() | |
1457 |
|
1482 | |||
1458 | def hasAllDataInBuffer(self): |
|
1483 | def hasAllDataInBuffer(self): | |
1459 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: |
|
1484 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: | |
1460 | return 1 |
|
1485 | return 1 | |
1461 | return 0 |
|
1486 | return 0 | |
1462 |
|
1487 | |||
1463 |
|
1488 | |||
1464 | def setBlockDimension(self): |
|
1489 | def setBlockDimension(self): | |
1465 | """ |
|
1490 | """ | |
1466 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque |
|
1491 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque | |
1467 |
|
1492 | |||
1468 | Affected: |
|
1493 | Affected: | |
1469 | self.shape_spc_Buffer |
|
1494 | self.shape_spc_Buffer | |
1470 | self.shape_cspc_Buffer |
|
1495 | self.shape_cspc_Buffer | |
1471 | self.shape_dc_Buffer |
|
1496 | self.shape_dc_Buffer | |
1472 |
|
1497 | |||
1473 | Return: None |
|
1498 | Return: None | |
1474 | """ |
|
1499 | """ | |
1475 | self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock, |
|
1500 | self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock, | |
1476 | self.processingHeaderObj.nHeights, |
|
1501 | self.processingHeaderObj.nHeights, | |
1477 | self.systemHeaderObj.nChannels) |
|
1502 | self.systemHeaderObj.nChannels) | |
1478 |
|
1503 | |||
1479 | self.datablock = numpy.zeros((self.systemHeaderObj.nChannels, |
|
1504 | self.datablock = numpy.zeros((self.systemHeaderObj.nChannels, | |
1480 | self.processingHeaderObj.profilesPerBlock, |
|
1505 | self.processingHeaderObj.profilesPerBlock, | |
1481 | self.processingHeaderObj.nHeights), |
|
1506 | self.processingHeaderObj.nHeights), | |
1482 | dtype=numpy.dtype('complex')) |
|
1507 | dtype=numpy.dtype('complex')) | |
1483 |
|
1508 | |||
1484 |
|
1509 | |||
1485 | def writeBlock(self): |
|
1510 | def writeBlock(self): | |
1486 | """ |
|
1511 | """ | |
1487 | Escribe el buffer en el file designado |
|
1512 | Escribe el buffer en el file designado | |
1488 |
|
1513 | |||
1489 | Affected: |
|
1514 | Affected: | |
1490 | self.profileIndex |
|
1515 | self.profileIndex | |
1491 | self.flagIsNewFile |
|
1516 | self.flagIsNewFile | |
1492 | self.flagIsNewBlock |
|
1517 | self.flagIsNewBlock | |
1493 | self.nTotalBlocks |
|
1518 | self.nTotalBlocks | |
1494 | self.blockIndex |
|
1519 | self.blockIndex | |
1495 |
|
1520 | |||
1496 | Return: None |
|
1521 | Return: None | |
1497 | """ |
|
1522 | """ | |
1498 | data = numpy.zeros( self.shapeBuffer, self.dtype ) |
|
1523 | data = numpy.zeros( self.shapeBuffer, self.dtype ) | |
1499 |
|
1524 | |||
1500 | junk = numpy.transpose(self.datablock, (1,2,0)) |
|
1525 | junk = numpy.transpose(self.datablock, (1,2,0)) | |
1501 |
|
1526 | |||
1502 | data['real'] = junk.real |
|
1527 | data['real'] = junk.real | |
1503 | data['imag'] = junk.imag |
|
1528 | data['imag'] = junk.imag | |
1504 |
|
1529 | |||
1505 | data = data.reshape( (-1) ) |
|
1530 | data = data.reshape( (-1) ) | |
1506 |
|
1531 | |||
1507 | data.tofile( self.fp ) |
|
1532 | data.tofile( self.fp ) | |
1508 |
|
1533 | |||
1509 | self.datablock.fill(0) |
|
1534 | self.datablock.fill(0) | |
1510 |
|
1535 | |||
1511 | self.profileIndex = 0 |
|
1536 | self.profileIndex = 0 | |
1512 | self.flagIsNewFile = 0 |
|
1537 | self.flagIsNewFile = 0 | |
1513 | self.flagIsNewBlock = 1 |
|
1538 | self.flagIsNewBlock = 1 | |
1514 |
|
1539 | |||
1515 | self.blockIndex += 1 |
|
1540 | self.blockIndex += 1 | |
1516 | self.nTotalBlocks += 1 |
|
1541 | self.nTotalBlocks += 1 | |
1517 |
|
1542 | |||
1518 | def putData(self): |
|
1543 | def putData(self): | |
1519 | """ |
|
1544 | """ | |
1520 | Setea un bloque de datos y luego los escribe en un file |
|
1545 | Setea un bloque de datos y luego los escribe en un file | |
1521 |
|
1546 | |||
1522 | Affected: |
|
1547 | Affected: | |
1523 | self.flagIsNewBlock |
|
1548 | self.flagIsNewBlock | |
1524 | self.profileIndex |
|
1549 | self.profileIndex | |
1525 |
|
1550 | |||
1526 | Return: |
|
1551 | Return: | |
1527 | 0 : Si no hay data o no hay mas files que puedan escribirse |
|
1552 | 0 : Si no hay data o no hay mas files que puedan escribirse | |
1528 | 1 : Si se escribio la data de un bloque en un file |
|
1553 | 1 : Si se escribio la data de un bloque en un file | |
1529 | """ |
|
1554 | """ | |
1530 | if self.dataOut.flagNoData: |
|
1555 | if self.dataOut.flagNoData: | |
1531 | return 0 |
|
1556 | return 0 | |
1532 |
|
1557 | |||
1533 | self.flagIsNewBlock = 0 |
|
1558 | self.flagIsNewBlock = 0 | |
1534 |
|
1559 | |||
1535 | if self.dataOut.flagTimeBlock: |
|
1560 | if self.dataOut.flagTimeBlock: | |
1536 |
|
1561 | |||
1537 | self.datablock.fill(0) |
|
1562 | self.datablock.fill(0) | |
1538 | self.profileIndex = 0 |
|
1563 | self.profileIndex = 0 | |
1539 | self.setNextFile() |
|
1564 | self.setNextFile() | |
1540 |
|
1565 | |||
1541 | if self.profileIndex == 0: |
|
1566 | if self.profileIndex == 0: | |
1542 | self.getBasicHeader() |
|
1567 | self.getBasicHeader() | |
1543 |
|
1568 | |||
1544 | self.datablock[:,self.profileIndex,:] = self.dataOut.data |
|
1569 | self.datablock[:,self.profileIndex,:] = self.dataOut.data | |
1545 |
|
1570 | |||
1546 | self.profileIndex += 1 |
|
1571 | self.profileIndex += 1 | |
1547 |
|
1572 | |||
1548 | if self.hasAllDataInBuffer(): |
|
1573 | if self.hasAllDataInBuffer(): | |
1549 | #if self.flagIsNewFile: |
|
1574 | #if self.flagIsNewFile: | |
1550 | self.writeNextBlock() |
|
1575 | self.writeNextBlock() | |
1551 | # self.getDataHeader() |
|
1576 | # self.getDataHeader() | |
1552 |
|
1577 | |||
1553 | return 1 |
|
1578 | return 1 | |
1554 |
|
1579 | |||
1555 | def __getProcessFlags(self): |
|
1580 | def __getProcessFlags(self): | |
1556 |
|
1581 | |||
1557 | processFlags = 0 |
|
1582 | processFlags = 0 | |
1558 |
|
1583 | |||
1559 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
1584 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
1560 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
1585 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
1561 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
1586 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
1562 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
1587 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
1563 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
1588 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
1564 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
1589 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
1565 |
|
1590 | |||
1566 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
1591 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] | |
1567 |
|
1592 | |||
1568 |
|
1593 | |||
1569 |
|
1594 | |||
1570 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, |
|
1595 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, | |
1571 | PROCFLAG.DATATYPE_SHORT, |
|
1596 | PROCFLAG.DATATYPE_SHORT, | |
1572 | PROCFLAG.DATATYPE_LONG, |
|
1597 | PROCFLAG.DATATYPE_LONG, | |
1573 | PROCFLAG.DATATYPE_INT64, |
|
1598 | PROCFLAG.DATATYPE_INT64, | |
1574 | PROCFLAG.DATATYPE_FLOAT, |
|
1599 | PROCFLAG.DATATYPE_FLOAT, | |
1575 | PROCFLAG.DATATYPE_DOUBLE] |
|
1600 | PROCFLAG.DATATYPE_DOUBLE] | |
1576 |
|
1601 | |||
1577 |
|
1602 | |||
1578 | for index in range(len(dtypeList)): |
|
1603 | for index in range(len(dtypeList)): | |
1579 | if self.dataOut.dtype == dtypeList[index]: |
|
1604 | if self.dataOut.dtype == dtypeList[index]: | |
1580 | dtypeValue = datatypeValueList[index] |
|
1605 | dtypeValue = datatypeValueList[index] | |
1581 | break |
|
1606 | break | |
1582 |
|
1607 | |||
1583 | processFlags += dtypeValue |
|
1608 | processFlags += dtypeValue | |
1584 |
|
1609 | |||
1585 | if self.dataOut.flagDecodeData: |
|
1610 | if self.dataOut.flagDecodeData: | |
1586 | processFlags += PROCFLAG.DECODE_DATA |
|
1611 | processFlags += PROCFLAG.DECODE_DATA | |
1587 |
|
1612 | |||
1588 | if self.dataOut.flagDeflipData: |
|
1613 | if self.dataOut.flagDeflipData: | |
1589 | processFlags += PROCFLAG.DEFLIP_DATA |
|
1614 | processFlags += PROCFLAG.DEFLIP_DATA | |
1590 |
|
1615 | |||
1591 | if self.dataOut.code != None: |
|
1616 | if self.dataOut.code != None: | |
1592 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE |
|
1617 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE | |
1593 |
|
1618 | |||
1594 | if self.dataOut.nCohInt > 1: |
|
1619 | if self.dataOut.nCohInt > 1: | |
1595 | processFlags += PROCFLAG.COHERENT_INTEGRATION |
|
1620 | processFlags += PROCFLAG.COHERENT_INTEGRATION | |
1596 |
|
1621 | |||
1597 | return processFlags |
|
1622 | return processFlags | |
1598 |
|
1623 | |||
1599 |
|
1624 | |||
1600 | def __getBlockSize(self): |
|
1625 | def __getBlockSize(self): | |
1601 | ''' |
|
1626 | ''' | |
1602 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage |
|
1627 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage | |
1603 | ''' |
|
1628 | ''' | |
1604 |
|
1629 | |||
1605 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
1630 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
1606 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
1631 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
1607 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
1632 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
1608 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
1633 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
1609 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
1634 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
1610 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
1635 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
1611 |
|
1636 | |||
1612 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
1637 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] | |
1613 | datatypeValueList = [1,2,4,8,4,8] |
|
1638 | datatypeValueList = [1,2,4,8,4,8] | |
1614 | for index in range(len(dtypeList)): |
|
1639 | for index in range(len(dtypeList)): | |
1615 | if self.dataOut.dtype == dtypeList[index]: |
|
1640 | if self.dataOut.dtype == dtypeList[index]: | |
1616 | datatypeValue = datatypeValueList[index] |
|
1641 | datatypeValue = datatypeValueList[index] | |
1617 | break |
|
1642 | break | |
1618 |
|
1643 | |||
1619 | blocksize = int(self.dataOut.nHeights * self.dataOut.nChannels * self.dataOut.nProfiles * datatypeValue * 2) |
|
1644 | blocksize = int(self.dataOut.nHeights * self.dataOut.nChannels * self.dataOut.nProfiles * datatypeValue * 2) | |
1620 |
|
1645 | |||
1621 | return blocksize |
|
1646 | return blocksize | |
1622 |
|
1647 | |||
1623 | def getDataHeader(self): |
|
1648 | def getDataHeader(self): | |
1624 |
|
1649 | |||
1625 | """ |
|
1650 | """ | |
1626 | Obtiene una copia del First Header |
|
1651 | Obtiene una copia del First Header | |
1627 |
|
1652 | |||
1628 | Affected: |
|
1653 | Affected: | |
1629 | self.systemHeaderObj |
|
1654 | self.systemHeaderObj | |
1630 | self.radarControllerHeaderObj |
|
1655 | self.radarControllerHeaderObj | |
1631 | self.dtype |
|
1656 | self.dtype | |
1632 |
|
1657 | |||
1633 | Return: |
|
1658 | Return: | |
1634 | None |
|
1659 | None | |
1635 | """ |
|
1660 | """ | |
1636 |
|
1661 | |||
1637 | self.systemHeaderObj = self.dataOut.systemHeaderObj.copy() |
|
1662 | self.systemHeaderObj = self.dataOut.systemHeaderObj.copy() | |
1638 | self.systemHeaderObj.nChannels = self.dataOut.nChannels |
|
1663 | self.systemHeaderObj.nChannels = self.dataOut.nChannels | |
1639 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() |
|
1664 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() | |
1640 |
|
1665 | |||
1641 | self.getBasicHeader() |
|
1666 | self.getBasicHeader() | |
1642 |
|
1667 | |||
1643 | processingHeaderSize = 40 # bytes |
|
1668 | processingHeaderSize = 40 # bytes | |
1644 | self.processingHeaderObj.dtype = 0 # Voltage |
|
1669 | self.processingHeaderObj.dtype = 0 # Voltage | |
1645 | self.processingHeaderObj.blockSize = self.__getBlockSize() |
|
1670 | self.processingHeaderObj.blockSize = self.__getBlockSize() | |
1646 | self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock |
|
1671 | self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock | |
1647 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile |
|
1672 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile | |
1648 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows |
|
1673 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows | |
1649 | self.processingHeaderObj.processFlags = self.__getProcessFlags() |
|
1674 | self.processingHeaderObj.processFlags = self.__getProcessFlags() | |
1650 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt |
|
1675 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt | |
1651 | self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage |
|
1676 | self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage | |
1652 | self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage |
|
1677 | self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage | |
1653 |
|
1678 | |||
1654 | if self.dataOut.code != None: |
|
1679 | if self.dataOut.code != None: | |
1655 | self.processingHeaderObj.code = self.dataOut.code |
|
1680 | self.processingHeaderObj.code = self.dataOut.code | |
1656 | self.processingHeaderObj.nCode = self.dataOut.nCode |
|
1681 | self.processingHeaderObj.nCode = self.dataOut.nCode | |
1657 | self.processingHeaderObj.nBaud = self.dataOut.nBaud |
|
1682 | self.processingHeaderObj.nBaud = self.dataOut.nBaud | |
1658 | codesize = int(8 + 4 * self.dataOut.nCode * self.dataOut.nBaud) |
|
1683 | codesize = int(8 + 4 * self.dataOut.nCode * self.dataOut.nBaud) | |
1659 | processingHeaderSize += codesize |
|
1684 | processingHeaderSize += codesize | |
1660 |
|
1685 | |||
1661 | if self.processingHeaderObj.nWindows != 0: |
|
1686 | if self.processingHeaderObj.nWindows != 0: | |
1662 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] |
|
1687 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] | |
1663 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
1688 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] | |
1664 | self.processingHeaderObj.nHeights = self.dataOut.nHeights |
|
1689 | self.processingHeaderObj.nHeights = self.dataOut.nHeights | |
1665 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights |
|
1690 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights | |
1666 | processingHeaderSize += 12 |
|
1691 | processingHeaderSize += 12 | |
1667 |
|
1692 | |||
1668 | self.processingHeaderObj.size = processingHeaderSize |
|
1693 | self.processingHeaderObj.size = processingHeaderSize | |
1669 |
|
1694 | |||
1670 | class SpectraReader(JRODataReader): |
|
1695 | class SpectraReader(JRODataReader): | |
1671 | """ |
|
1696 | """ | |
1672 | Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura |
|
1697 | Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura | |
1673 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones) |
|
1698 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones) | |
1674 | son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel. |
|
1699 | son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel. | |
1675 |
|
1700 | |||
1676 | paresCanalesIguales * alturas * perfiles (Self Spectra) |
|
1701 | paresCanalesIguales * alturas * perfiles (Self Spectra) | |
1677 | paresCanalesDiferentes * alturas * perfiles (Cross Spectra) |
|
1702 | paresCanalesDiferentes * alturas * perfiles (Cross Spectra) | |
1678 | canales * alturas (DC Channels) |
|
1703 | canales * alturas (DC Channels) | |
1679 |
|
1704 | |||
1680 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, |
|
1705 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, | |
1681 | RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la |
|
1706 | RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la | |
1682 | cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de |
|
1707 | cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de | |
1683 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". |
|
1708 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". | |
1684 |
|
1709 | |||
1685 | Example: |
|
1710 | Example: | |
1686 | dpath = "/home/myuser/data" |
|
1711 | dpath = "/home/myuser/data" | |
1687 |
|
1712 | |||
1688 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) |
|
1713 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) | |
1689 |
|
1714 | |||
1690 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) |
|
1715 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) | |
1691 |
|
1716 | |||
1692 | readerObj = SpectraReader() |
|
1717 | readerObj = SpectraReader() | |
1693 |
|
1718 | |||
1694 | readerObj.setup(dpath, startTime, endTime) |
|
1719 | readerObj.setup(dpath, startTime, endTime) | |
1695 |
|
1720 | |||
1696 | while(True): |
|
1721 | while(True): | |
1697 |
|
1722 | |||
1698 | readerObj.getData() |
|
1723 | readerObj.getData() | |
1699 |
|
1724 | |||
1700 | print readerObj.data_spc |
|
1725 | print readerObj.data_spc | |
1701 |
|
1726 | |||
1702 | print readerObj.data_cspc |
|
1727 | print readerObj.data_cspc | |
1703 |
|
1728 | |||
1704 | print readerObj.data_dc |
|
1729 | print readerObj.data_dc | |
1705 |
|
1730 | |||
1706 | if readerObj.flagNoMoreFiles: |
|
1731 | if readerObj.flagNoMoreFiles: | |
1707 | break |
|
1732 | break | |
1708 |
|
1733 | |||
1709 | """ |
|
1734 | """ | |
1710 |
|
1735 | |||
1711 | pts2read_SelfSpectra = 0 |
|
1736 | pts2read_SelfSpectra = 0 | |
1712 |
|
1737 | |||
1713 | pts2read_CrossSpectra = 0 |
|
1738 | pts2read_CrossSpectra = 0 | |
1714 |
|
1739 | |||
1715 | pts2read_DCchannels = 0 |
|
1740 | pts2read_DCchannels = 0 | |
1716 |
|
1741 | |||
1717 | ext = ".pdata" |
|
1742 | ext = ".pdata" | |
1718 |
|
1743 | |||
1719 | optchar = "P" |
|
1744 | optchar = "P" | |
1720 |
|
1745 | |||
1721 | dataOut = None |
|
1746 | dataOut = None | |
1722 |
|
1747 | |||
1723 | nRdChannels = None |
|
1748 | nRdChannels = None | |
1724 |
|
1749 | |||
1725 | nRdPairs = None |
|
1750 | nRdPairs = None | |
1726 |
|
1751 | |||
1727 | rdPairList = [] |
|
1752 | rdPairList = [] | |
1728 |
|
1753 | |||
1729 |
|
1754 | |||
1730 | def __init__(self): |
|
1755 | def __init__(self): | |
1731 | """ |
|
1756 | """ | |
1732 | Inicializador de la clase SpectraReader para la lectura de datos de espectros. |
|
1757 | Inicializador de la clase SpectraReader para la lectura de datos de espectros. | |
1733 |
|
1758 | |||
1734 | Inputs: |
|
1759 | Inputs: | |
1735 | dataOut : Objeto de la clase Spectra. Este objeto sera utilizado para |
|
1760 | dataOut : Objeto de la clase Spectra. Este objeto sera utilizado para | |
1736 | almacenar un perfil de datos cada vez que se haga un requerimiento |
|
1761 | almacenar un perfil de datos cada vez que se haga un requerimiento | |
1737 | (getData). El perfil sera obtenido a partir del buffer de datos, |
|
1762 | (getData). El perfil sera obtenido a partir del buffer de datos, | |
1738 | si el buffer esta vacio se hara un nuevo proceso de lectura de un |
|
1763 | si el buffer esta vacio se hara un nuevo proceso de lectura de un | |
1739 | bloque de datos. |
|
1764 | bloque de datos. | |
1740 | Si este parametro no es pasado se creara uno internamente. |
|
1765 | Si este parametro no es pasado se creara uno internamente. | |
1741 |
|
1766 | |||
1742 | Affected: |
|
1767 | Affected: | |
1743 | self.dataOut |
|
1768 | self.dataOut | |
1744 |
|
1769 | |||
1745 | Return : None |
|
1770 | Return : None | |
1746 | """ |
|
1771 | """ | |
1747 |
|
1772 | |||
1748 | self.isConfig = False |
|
1773 | self.isConfig = False | |
1749 |
|
1774 | |||
1750 | self.pts2read_SelfSpectra = 0 |
|
1775 | self.pts2read_SelfSpectra = 0 | |
1751 |
|
1776 | |||
1752 | self.pts2read_CrossSpectra = 0 |
|
1777 | self.pts2read_CrossSpectra = 0 | |
1753 |
|
1778 | |||
1754 | self.pts2read_DCchannels = 0 |
|
1779 | self.pts2read_DCchannels = 0 | |
1755 |
|
1780 | |||
1756 | self.datablock = None |
|
1781 | self.datablock = None | |
1757 |
|
1782 | |||
1758 | self.utc = None |
|
1783 | self.utc = None | |
1759 |
|
1784 | |||
1760 | self.ext = ".pdata" |
|
1785 | self.ext = ".pdata" | |
1761 |
|
1786 | |||
1762 | self.optchar = "P" |
|
1787 | self.optchar = "P" | |
1763 |
|
1788 | |||
1764 | self.basicHeaderObj = BasicHeader() |
|
1789 | self.basicHeaderObj = BasicHeader() | |
1765 |
|
1790 | |||
1766 | self.systemHeaderObj = SystemHeader() |
|
1791 | self.systemHeaderObj = SystemHeader() | |
1767 |
|
1792 | |||
1768 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
1793 | self.radarControllerHeaderObj = RadarControllerHeader() | |
1769 |
|
1794 | |||
1770 | self.processingHeaderObj = ProcessingHeader() |
|
1795 | self.processingHeaderObj = ProcessingHeader() | |
1771 |
|
1796 | |||
1772 | self.online = 0 |
|
1797 | self.online = 0 | |
1773 |
|
1798 | |||
1774 | self.fp = None |
|
1799 | self.fp = None | |
1775 |
|
1800 | |||
1776 | self.idFile = None |
|
1801 | self.idFile = None | |
1777 |
|
1802 | |||
1778 | self.dtype = None |
|
1803 | self.dtype = None | |
1779 |
|
1804 | |||
1780 | self.fileSizeByHeader = None |
|
1805 | self.fileSizeByHeader = None | |
1781 |
|
1806 | |||
1782 | self.filenameList = [] |
|
1807 | self.filenameList = [] | |
1783 |
|
1808 | |||
1784 | self.filename = None |
|
1809 | self.filename = None | |
1785 |
|
1810 | |||
1786 | self.fileSize = None |
|
1811 | self.fileSize = None | |
1787 |
|
1812 | |||
1788 | self.firstHeaderSize = 0 |
|
1813 | self.firstHeaderSize = 0 | |
1789 |
|
1814 | |||
1790 | self.basicHeaderSize = 24 |
|
1815 | self.basicHeaderSize = 24 | |
1791 |
|
1816 | |||
1792 | self.pathList = [] |
|
1817 | self.pathList = [] | |
1793 |
|
1818 | |||
1794 | self.lastUTTime = 0 |
|
1819 | self.lastUTTime = 0 | |
1795 |
|
1820 | |||
1796 | self.maxTimeStep = 30 |
|
1821 | self.maxTimeStep = 30 | |
1797 |
|
1822 | |||
1798 | self.flagNoMoreFiles = 0 |
|
1823 | self.flagNoMoreFiles = 0 | |
1799 |
|
1824 | |||
1800 | self.set = 0 |
|
1825 | self.set = 0 | |
1801 |
|
1826 | |||
1802 | self.path = None |
|
1827 | self.path = None | |
1803 |
|
1828 | |||
1804 | self.delay = 3 #seconds |
|
1829 | self.delay = 3 #seconds | |
1805 |
|
1830 | |||
1806 | self.nTries = 3 #quantity tries |
|
1831 | self.nTries = 3 #quantity tries | |
1807 |
|
1832 | |||
1808 | self.nFiles = 3 #number of files for searching |
|
1833 | self.nFiles = 3 #number of files for searching | |
1809 |
|
1834 | |||
1810 | self.nReadBlocks = 0 |
|
1835 | self.nReadBlocks = 0 | |
1811 |
|
1836 | |||
1812 | self.flagIsNewFile = 1 |
|
1837 | self.flagIsNewFile = 1 | |
1813 |
|
1838 | |||
1814 | self.ippSeconds = 0 |
|
1839 | self.ippSeconds = 0 | |
1815 |
|
1840 | |||
1816 | self.flagTimeBlock = 0 |
|
1841 | self.flagTimeBlock = 0 | |
1817 |
|
1842 | |||
1818 | self.flagIsNewBlock = 0 |
|
1843 | self.flagIsNewBlock = 0 | |
1819 |
|
1844 | |||
1820 | self.nTotalBlocks = 0 |
|
1845 | self.nTotalBlocks = 0 | |
1821 |
|
1846 | |||
1822 | self.blocksize = 0 |
|
1847 | self.blocksize = 0 | |
1823 |
|
1848 | |||
1824 | self.dataOut = self.createObjByDefault() |
|
1849 | self.dataOut = self.createObjByDefault() | |
1825 |
|
1850 | |||
1826 |
|
1851 | |||
1827 | def createObjByDefault(self): |
|
1852 | def createObjByDefault(self): | |
1828 |
|
1853 | |||
1829 | dataObj = Spectra() |
|
1854 | dataObj = Spectra() | |
1830 |
|
1855 | |||
1831 | return dataObj |
|
1856 | return dataObj | |
1832 |
|
1857 | |||
1833 | def __hasNotDataInBuffer(self): |
|
1858 | def __hasNotDataInBuffer(self): | |
1834 | return 1 |
|
1859 | return 1 | |
1835 |
|
1860 | |||
1836 |
|
1861 | |||
1837 | def getBlockDimension(self): |
|
1862 | def getBlockDimension(self): | |
1838 | """ |
|
1863 | """ | |
1839 | Obtiene la cantidad de puntos a leer por cada bloque de datos |
|
1864 | Obtiene la cantidad de puntos a leer por cada bloque de datos | |
1840 |
|
1865 | |||
1841 | Affected: |
|
1866 | Affected: | |
1842 | self.nRdChannels |
|
1867 | self.nRdChannels | |
1843 | self.nRdPairs |
|
1868 | self.nRdPairs | |
1844 | self.pts2read_SelfSpectra |
|
1869 | self.pts2read_SelfSpectra | |
1845 | self.pts2read_CrossSpectra |
|
1870 | self.pts2read_CrossSpectra | |
1846 | self.pts2read_DCchannels |
|
1871 | self.pts2read_DCchannels | |
1847 | self.blocksize |
|
1872 | self.blocksize | |
1848 | self.dataOut.nChannels |
|
1873 | self.dataOut.nChannels | |
1849 | self.dataOut.nPairs |
|
1874 | self.dataOut.nPairs | |
1850 |
|
1875 | |||
1851 | Return: |
|
1876 | Return: | |
1852 | None |
|
1877 | None | |
1853 | """ |
|
1878 | """ | |
1854 | self.nRdChannels = 0 |
|
1879 | self.nRdChannels = 0 | |
1855 | self.nRdPairs = 0 |
|
1880 | self.nRdPairs = 0 | |
1856 | self.rdPairList = [] |
|
1881 | self.rdPairList = [] | |
1857 |
|
1882 | |||
1858 | for i in range(0, self.processingHeaderObj.totalSpectra*2, 2): |
|
1883 | for i in range(0, self.processingHeaderObj.totalSpectra*2, 2): | |
1859 | if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]: |
|
1884 | if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]: | |
1860 | self.nRdChannels = self.nRdChannels + 1 #par de canales iguales |
|
1885 | self.nRdChannels = self.nRdChannels + 1 #par de canales iguales | |
1861 | else: |
|
1886 | else: | |
1862 | self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes |
|
1887 | self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes | |
1863 | self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1])) |
|
1888 | self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1])) | |
1864 |
|
1889 | |||
1865 | pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock |
|
1890 | pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock | |
1866 |
|
1891 | |||
1867 | self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read) |
|
1892 | self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read) | |
1868 | self.blocksize = self.pts2read_SelfSpectra |
|
1893 | self.blocksize = self.pts2read_SelfSpectra | |
1869 |
|
1894 | |||
1870 | if self.processingHeaderObj.flag_cspc: |
|
1895 | if self.processingHeaderObj.flag_cspc: | |
1871 | self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read) |
|
1896 | self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read) | |
1872 | self.blocksize += self.pts2read_CrossSpectra |
|
1897 | self.blocksize += self.pts2read_CrossSpectra | |
1873 |
|
1898 | |||
1874 | if self.processingHeaderObj.flag_dc: |
|
1899 | if self.processingHeaderObj.flag_dc: | |
1875 | self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights) |
|
1900 | self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights) | |
1876 | self.blocksize += self.pts2read_DCchannels |
|
1901 | self.blocksize += self.pts2read_DCchannels | |
1877 |
|
1902 | |||
1878 | # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels |
|
1903 | # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels | |
1879 |
|
1904 | |||
1880 |
|
1905 | |||
1881 | def readBlock(self): |
|
1906 | def readBlock(self): | |
1882 | """ |
|
1907 | """ | |
1883 | Lee el bloque de datos desde la posicion actual del puntero del archivo |
|
1908 | Lee el bloque de datos desde la posicion actual del puntero del archivo | |
1884 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos |
|
1909 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos | |
1885 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer |
|
1910 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer | |
1886 | es seteado a 0 |
|
1911 | es seteado a 0 | |
1887 |
|
1912 | |||
1888 | Return: None |
|
1913 | Return: None | |
1889 |
|
1914 | |||
1890 | Variables afectadas: |
|
1915 | Variables afectadas: | |
1891 |
|
1916 | |||
1892 | self.flagIsNewFile |
|
1917 | self.flagIsNewFile | |
1893 | self.flagIsNewBlock |
|
1918 | self.flagIsNewBlock | |
1894 | self.nTotalBlocks |
|
1919 | self.nTotalBlocks | |
1895 | self.data_spc |
|
1920 | self.data_spc | |
1896 | self.data_cspc |
|
1921 | self.data_cspc | |
1897 | self.data_dc |
|
1922 | self.data_dc | |
1898 |
|
1923 | |||
1899 | Exceptions: |
|
1924 | Exceptions: | |
1900 | Si un bloque leido no es un bloque valido |
|
1925 | Si un bloque leido no es un bloque valido | |
1901 | """ |
|
1926 | """ | |
1902 | blockOk_flag = False |
|
1927 | blockOk_flag = False | |
1903 | fpointer = self.fp.tell() |
|
1928 | fpointer = self.fp.tell() | |
1904 |
|
1929 | |||
1905 | spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra ) |
|
1930 | spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra ) | |
1906 | spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D |
|
1931 | spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D | |
1907 |
|
1932 | |||
1908 | if self.processingHeaderObj.flag_cspc: |
|
1933 | if self.processingHeaderObj.flag_cspc: | |
1909 | cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra ) |
|
1934 | cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra ) | |
1910 | cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D |
|
1935 | cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D | |
1911 |
|
1936 | |||
1912 | if self.processingHeaderObj.flag_dc: |
|
1937 | if self.processingHeaderObj.flag_dc: | |
1913 | dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) ) |
|
1938 | dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) ) | |
1914 | dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D |
|
1939 | dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D | |
1915 |
|
1940 | |||
1916 |
|
1941 | |||
1917 | if not(self.processingHeaderObj.shif_fft): |
|
1942 | if not(self.processingHeaderObj.shif_fft): | |
1918 | #desplaza a la derecha en el eje 2 determinadas posiciones |
|
1943 | #desplaza a la derecha en el eje 2 determinadas posiciones | |
1919 | shift = int(self.processingHeaderObj.profilesPerBlock/2) |
|
1944 | shift = int(self.processingHeaderObj.profilesPerBlock/2) | |
1920 | spc = numpy.roll( spc, shift , axis=2 ) |
|
1945 | spc = numpy.roll( spc, shift , axis=2 ) | |
1921 |
|
1946 | |||
1922 | if self.processingHeaderObj.flag_cspc: |
|
1947 | if self.processingHeaderObj.flag_cspc: | |
1923 | #desplaza a la derecha en el eje 2 determinadas posiciones |
|
1948 | #desplaza a la derecha en el eje 2 determinadas posiciones | |
1924 | cspc = numpy.roll( cspc, shift, axis=2 ) |
|
1949 | cspc = numpy.roll( cspc, shift, axis=2 ) | |
1925 |
|
1950 | |||
1926 |
|
1951 | |||
1927 | spc = numpy.transpose( spc, (0,2,1) ) |
|
1952 | spc = numpy.transpose( spc, (0,2,1) ) | |
1928 | self.data_spc = spc |
|
1953 | self.data_spc = spc | |
1929 |
|
1954 | |||
1930 | if self.processingHeaderObj.flag_cspc: |
|
1955 | if self.processingHeaderObj.flag_cspc: | |
1931 | cspc = numpy.transpose( cspc, (0,2,1) ) |
|
1956 | cspc = numpy.transpose( cspc, (0,2,1) ) | |
1932 | self.data_cspc = cspc['real'] + cspc['imag']*1j |
|
1957 | self.data_cspc = cspc['real'] + cspc['imag']*1j | |
1933 | else: |
|
1958 | else: | |
1934 | self.data_cspc = None |
|
1959 | self.data_cspc = None | |
1935 |
|
1960 | |||
1936 | if self.processingHeaderObj.flag_dc: |
|
1961 | if self.processingHeaderObj.flag_dc: | |
1937 | self.data_dc = dc['real'] + dc['imag']*1j |
|
1962 | self.data_dc = dc['real'] + dc['imag']*1j | |
1938 | else: |
|
1963 | else: | |
1939 | self.data_dc = None |
|
1964 | self.data_dc = None | |
1940 |
|
1965 | |||
1941 | self.flagIsNewFile = 0 |
|
1966 | self.flagIsNewFile = 0 | |
1942 | self.flagIsNewBlock = 1 |
|
1967 | self.flagIsNewBlock = 1 | |
1943 |
|
1968 | |||
1944 | self.nTotalBlocks += 1 |
|
1969 | self.nTotalBlocks += 1 | |
1945 | self.nReadBlocks += 1 |
|
1970 | self.nReadBlocks += 1 | |
1946 |
|
1971 | |||
1947 | return 1 |
|
1972 | return 1 | |
1948 |
|
1973 | |||
1949 |
|
1974 | |||
1950 | def getData(self): |
|
1975 | def getData(self): | |
1951 | """ |
|
1976 | """ | |
1952 | Copia el buffer de lectura a la clase "Spectra", |
|
1977 | Copia el buffer de lectura a la clase "Spectra", | |
1953 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de |
|
1978 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de | |
1954 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" |
|
1979 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" | |
1955 |
|
1980 | |||
1956 | Return: |
|
1981 | Return: | |
1957 | 0 : Si no hay mas archivos disponibles |
|
1982 | 0 : Si no hay mas archivos disponibles | |
1958 | 1 : Si hizo una buena copia del buffer |
|
1983 | 1 : Si hizo una buena copia del buffer | |
1959 |
|
1984 | |||
1960 | Affected: |
|
1985 | Affected: | |
1961 | self.dataOut |
|
1986 | self.dataOut | |
1962 |
|
1987 | |||
1963 | self.flagTimeBlock |
|
1988 | self.flagTimeBlock | |
1964 | self.flagIsNewBlock |
|
1989 | self.flagIsNewBlock | |
1965 | """ |
|
1990 | """ | |
1966 |
|
1991 | |||
1967 | if self.flagNoMoreFiles: |
|
1992 | if self.flagNoMoreFiles: | |
1968 | self.dataOut.flagNoData = True |
|
1993 | self.dataOut.flagNoData = True | |
1969 | print 'Process finished' |
|
1994 | print 'Process finished' | |
1970 | return 0 |
|
1995 | return 0 | |
1971 |
|
1996 | |||
1972 | self.flagTimeBlock = 0 |
|
1997 | self.flagTimeBlock = 0 | |
1973 | self.flagIsNewBlock = 0 |
|
1998 | self.flagIsNewBlock = 0 | |
1974 |
|
1999 | |||
1975 | if self.__hasNotDataInBuffer(): |
|
2000 | if self.__hasNotDataInBuffer(): | |
1976 |
|
2001 | |||
1977 | if not( self.readNextBlock() ): |
|
2002 | if not( self.readNextBlock() ): | |
1978 | self.dataOut.flagNoData = True |
|
2003 | self.dataOut.flagNoData = True | |
1979 | return 0 |
|
2004 | return 0 | |
1980 |
|
2005 | |||
1981 | # self.updateDataHeader() |
|
2006 | # self.updateDataHeader() | |
1982 |
|
2007 | |||
1983 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) |
|
2008 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) | |
1984 |
|
2009 | |||
1985 | if self.data_dc == None: |
|
2010 | if self.data_dc == None: | |
1986 | self.dataOut.flagNoData = True |
|
2011 | self.dataOut.flagNoData = True | |
1987 | return 0 |
|
2012 | return 0 | |
1988 |
|
2013 | |||
1989 | self.dataOut.data_spc = self.data_spc |
|
2014 | self.dataOut.data_spc = self.data_spc | |
1990 |
|
2015 | |||
1991 | self.dataOut.data_cspc = self.data_cspc |
|
2016 | self.dataOut.data_cspc = self.data_cspc | |
1992 |
|
2017 | |||
1993 | self.dataOut.data_dc = self.data_dc |
|
2018 | self.dataOut.data_dc = self.data_dc | |
1994 |
|
2019 | |||
1995 | self.dataOut.flagTimeBlock = self.flagTimeBlock |
|
2020 | self.dataOut.flagTimeBlock = self.flagTimeBlock | |
1996 |
|
2021 | |||
1997 | self.dataOut.flagNoData = False |
|
2022 | self.dataOut.flagNoData = False | |
1998 |
|
2023 | |||
1999 | self.dataOut.dtype = self.dtype |
|
2024 | self.dataOut.dtype = self.dtype | |
2000 |
|
2025 | |||
2001 | # self.dataOut.nChannels = self.nRdChannels |
|
2026 | # self.dataOut.nChannels = self.nRdChannels | |
2002 |
|
2027 | |||
2003 | self.dataOut.nPairs = self.nRdPairs |
|
2028 | self.dataOut.nPairs = self.nRdPairs | |
2004 |
|
2029 | |||
2005 | self.dataOut.pairsList = self.rdPairList |
|
2030 | self.dataOut.pairsList = self.rdPairList | |
2006 |
|
2031 | |||
2007 | # self.dataOut.nHeights = self.processingHeaderObj.nHeights |
|
2032 | # self.dataOut.nHeights = self.processingHeaderObj.nHeights | |
2008 |
|
2033 | |||
2009 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock |
|
2034 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock | |
2010 |
|
2035 | |||
2011 | self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock |
|
2036 | self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock | |
2012 |
|
2037 | |||
2013 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt |
|
2038 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt | |
2014 |
|
2039 | |||
2015 | self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt |
|
2040 | self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt | |
2016 |
|
2041 | |||
2017 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight |
|
2042 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight | |
2018 |
|
2043 | |||
2019 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) |
|
2044 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) | |
2020 |
|
2045 | |||
2021 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) |
|
2046 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) | |
2022 |
|
2047 | |||
2023 | # self.dataOut.channelIndexList = range(self.systemHeaderObj.nChannels) |
|
2048 | # self.dataOut.channelIndexList = range(self.systemHeaderObj.nChannels) | |
2024 |
|
2049 | |||
2025 | self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000.#+ self.profileIndex * self.ippSeconds |
|
2050 | self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000.#+ self.profileIndex * self.ippSeconds | |
2026 |
|
2051 | |||
2027 | self.dataOut.ippSeconds = self.ippSeconds |
|
2052 | self.dataOut.ippSeconds = self.ippSeconds | |
2028 |
|
2053 | |||
2029 | self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.dataOut.nFFTPoints |
|
2054 | self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.dataOut.nFFTPoints | |
2030 |
|
2055 | |||
2031 | self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft |
|
2056 | self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft | |
2032 |
|
2057 | |||
2033 | # self.profileIndex += 1 |
|
2058 | # self.profileIndex += 1 | |
2034 |
|
2059 | |||
2035 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() |
|
2060 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() | |
2036 |
|
2061 | |||
2037 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() |
|
2062 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() | |
2038 |
|
2063 | |||
2039 | return self.dataOut.data_spc |
|
2064 | return self.dataOut.data_spc | |
2040 |
|
2065 | |||
2041 |
|
2066 | |||
2042 | class SpectraWriter(JRODataWriter): |
|
2067 | class SpectraWriter(JRODataWriter): | |
2043 |
|
2068 | |||
2044 | """ |
|
2069 | """ | |
2045 | Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura |
|
2070 | Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura | |
2046 | de los datos siempre se realiza por bloques. |
|
2071 | de los datos siempre se realiza por bloques. | |
2047 | """ |
|
2072 | """ | |
2048 |
|
2073 | |||
2049 | ext = ".pdata" |
|
2074 | ext = ".pdata" | |
2050 |
|
2075 | |||
2051 | optchar = "P" |
|
2076 | optchar = "P" | |
2052 |
|
2077 | |||
2053 | shape_spc_Buffer = None |
|
2078 | shape_spc_Buffer = None | |
2054 |
|
2079 | |||
2055 | shape_cspc_Buffer = None |
|
2080 | shape_cspc_Buffer = None | |
2056 |
|
2081 | |||
2057 | shape_dc_Buffer = None |
|
2082 | shape_dc_Buffer = None | |
2058 |
|
2083 | |||
2059 | data_spc = None |
|
2084 | data_spc = None | |
2060 |
|
2085 | |||
2061 | data_cspc = None |
|
2086 | data_cspc = None | |
2062 |
|
2087 | |||
2063 | data_dc = None |
|
2088 | data_dc = None | |
2064 |
|
2089 | |||
2065 | # dataOut = None |
|
2090 | # dataOut = None | |
2066 |
|
2091 | |||
2067 | def __init__(self): |
|
2092 | def __init__(self): | |
2068 | """ |
|
2093 | """ | |
2069 | Inicializador de la clase SpectraWriter para la escritura de datos de espectros. |
|
2094 | Inicializador de la clase SpectraWriter para la escritura de datos de espectros. | |
2070 |
|
2095 | |||
2071 | Affected: |
|
2096 | Affected: | |
2072 | self.dataOut |
|
2097 | self.dataOut | |
2073 | self.basicHeaderObj |
|
2098 | self.basicHeaderObj | |
2074 | self.systemHeaderObj |
|
2099 | self.systemHeaderObj | |
2075 | self.radarControllerHeaderObj |
|
2100 | self.radarControllerHeaderObj | |
2076 | self.processingHeaderObj |
|
2101 | self.processingHeaderObj | |
2077 |
|
2102 | |||
2078 | Return: None |
|
2103 | Return: None | |
2079 | """ |
|
2104 | """ | |
2080 |
|
2105 | |||
2081 | self.isConfig = False |
|
2106 | self.isConfig = False | |
2082 |
|
2107 | |||
2083 | self.nTotalBlocks = 0 |
|
2108 | self.nTotalBlocks = 0 | |
2084 |
|
2109 | |||
2085 | self.data_spc = None |
|
2110 | self.data_spc = None | |
2086 |
|
2111 | |||
2087 | self.data_cspc = None |
|
2112 | self.data_cspc = None | |
2088 |
|
2113 | |||
2089 | self.data_dc = None |
|
2114 | self.data_dc = None | |
2090 |
|
2115 | |||
2091 | self.fp = None |
|
2116 | self.fp = None | |
2092 |
|
2117 | |||
2093 | self.flagIsNewFile = 1 |
|
2118 | self.flagIsNewFile = 1 | |
2094 |
|
2119 | |||
2095 | self.nTotalBlocks = 0 |
|
2120 | self.nTotalBlocks = 0 | |
2096 |
|
2121 | |||
2097 | self.flagIsNewBlock = 0 |
|
2122 | self.flagIsNewBlock = 0 | |
2098 |
|
2123 | |||
2099 | self.setFile = None |
|
2124 | self.setFile = None | |
2100 |
|
2125 | |||
2101 | self.dtype = None |
|
2126 | self.dtype = None | |
2102 |
|
2127 | |||
2103 | self.path = None |
|
2128 | self.path = None | |
2104 |
|
2129 | |||
2105 | self.noMoreFiles = 0 |
|
2130 | self.noMoreFiles = 0 | |
2106 |
|
2131 | |||
2107 | self.filename = None |
|
2132 | self.filename = None | |
2108 |
|
2133 | |||
2109 | self.basicHeaderObj = BasicHeader() |
|
2134 | self.basicHeaderObj = BasicHeader() | |
2110 |
|
2135 | |||
2111 | self.systemHeaderObj = SystemHeader() |
|
2136 | self.systemHeaderObj = SystemHeader() | |
2112 |
|
2137 | |||
2113 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
2138 | self.radarControllerHeaderObj = RadarControllerHeader() | |
2114 |
|
2139 | |||
2115 | self.processingHeaderObj = ProcessingHeader() |
|
2140 | self.processingHeaderObj = ProcessingHeader() | |
2116 |
|
2141 | |||
2117 |
|
2142 | |||
2118 | def hasAllDataInBuffer(self): |
|
2143 | def hasAllDataInBuffer(self): | |
2119 | return 1 |
|
2144 | return 1 | |
2120 |
|
2145 | |||
2121 |
|
2146 | |||
2122 | def setBlockDimension(self): |
|
2147 | def setBlockDimension(self): | |
2123 | """ |
|
2148 | """ | |
2124 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque |
|
2149 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque | |
2125 |
|
2150 | |||
2126 | Affected: |
|
2151 | Affected: | |
2127 | self.shape_spc_Buffer |
|
2152 | self.shape_spc_Buffer | |
2128 | self.shape_cspc_Buffer |
|
2153 | self.shape_cspc_Buffer | |
2129 | self.shape_dc_Buffer |
|
2154 | self.shape_dc_Buffer | |
2130 |
|
2155 | |||
2131 | Return: None |
|
2156 | Return: None | |
2132 | """ |
|
2157 | """ | |
2133 | self.shape_spc_Buffer = (self.dataOut.nChannels, |
|
2158 | self.shape_spc_Buffer = (self.dataOut.nChannels, | |
2134 | self.processingHeaderObj.nHeights, |
|
2159 | self.processingHeaderObj.nHeights, | |
2135 | self.processingHeaderObj.profilesPerBlock) |
|
2160 | self.processingHeaderObj.profilesPerBlock) | |
2136 |
|
2161 | |||
2137 | self.shape_cspc_Buffer = (self.dataOut.nPairs, |
|
2162 | self.shape_cspc_Buffer = (self.dataOut.nPairs, | |
2138 | self.processingHeaderObj.nHeights, |
|
2163 | self.processingHeaderObj.nHeights, | |
2139 | self.processingHeaderObj.profilesPerBlock) |
|
2164 | self.processingHeaderObj.profilesPerBlock) | |
2140 |
|
2165 | |||
2141 | self.shape_dc_Buffer = (self.dataOut.nChannels, |
|
2166 | self.shape_dc_Buffer = (self.dataOut.nChannels, | |
2142 | self.processingHeaderObj.nHeights) |
|
2167 | self.processingHeaderObj.nHeights) | |
2143 |
|
2168 | |||
2144 |
|
2169 | |||
2145 | def writeBlock(self): |
|
2170 | def writeBlock(self): | |
2146 | """ |
|
2171 | """ | |
2147 | Escribe el buffer en el file designado |
|
2172 | Escribe el buffer en el file designado | |
2148 |
|
2173 | |||
2149 | Affected: |
|
2174 | Affected: | |
2150 | self.data_spc |
|
2175 | self.data_spc | |
2151 | self.data_cspc |
|
2176 | self.data_cspc | |
2152 | self.data_dc |
|
2177 | self.data_dc | |
2153 | self.flagIsNewFile |
|
2178 | self.flagIsNewFile | |
2154 | self.flagIsNewBlock |
|
2179 | self.flagIsNewBlock | |
2155 | self.nTotalBlocks |
|
2180 | self.nTotalBlocks | |
2156 | self.nWriteBlocks |
|
2181 | self.nWriteBlocks | |
2157 |
|
2182 | |||
2158 | Return: None |
|
2183 | Return: None | |
2159 | """ |
|
2184 | """ | |
2160 |
|
2185 | |||
2161 | spc = numpy.transpose( self.data_spc, (0,2,1) ) |
|
2186 | spc = numpy.transpose( self.data_spc, (0,2,1) ) | |
2162 | if not( self.processingHeaderObj.shif_fft ): |
|
2187 | if not( self.processingHeaderObj.shif_fft ): | |
2163 | spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
2188 | spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones | |
2164 | data = spc.reshape((-1)) |
|
2189 | data = spc.reshape((-1)) | |
2165 | data.tofile(self.fp) |
|
2190 | data.tofile(self.fp) | |
2166 |
|
2191 | |||
2167 | if self.data_cspc != None: |
|
2192 | if self.data_cspc != None: | |
2168 | data = numpy.zeros( self.shape_cspc_Buffer, self.dtype ) |
|
2193 | data = numpy.zeros( self.shape_cspc_Buffer, self.dtype ) | |
2169 | cspc = numpy.transpose( self.data_cspc, (0,2,1) ) |
|
2194 | cspc = numpy.transpose( self.data_cspc, (0,2,1) ) | |
2170 | if not( self.processingHeaderObj.shif_fft ): |
|
2195 | if not( self.processingHeaderObj.shif_fft ): | |
2171 | cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
2196 | cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones | |
2172 | data['real'] = cspc.real |
|
2197 | data['real'] = cspc.real | |
2173 | data['imag'] = cspc.imag |
|
2198 | data['imag'] = cspc.imag | |
2174 | data = data.reshape((-1)) |
|
2199 | data = data.reshape((-1)) | |
2175 | data.tofile(self.fp) |
|
2200 | data.tofile(self.fp) | |
2176 |
|
2201 | |||
2177 | if self.data_dc != None: |
|
2202 | if self.data_dc != None: | |
2178 | data = numpy.zeros( self.shape_dc_Buffer, self.dtype ) |
|
2203 | data = numpy.zeros( self.shape_dc_Buffer, self.dtype ) | |
2179 | dc = self.data_dc |
|
2204 | dc = self.data_dc | |
2180 | data['real'] = dc.real |
|
2205 | data['real'] = dc.real | |
2181 | data['imag'] = dc.imag |
|
2206 | data['imag'] = dc.imag | |
2182 | data = data.reshape((-1)) |
|
2207 | data = data.reshape((-1)) | |
2183 | data.tofile(self.fp) |
|
2208 | data.tofile(self.fp) | |
2184 |
|
2209 | |||
2185 | self.data_spc.fill(0) |
|
2210 | self.data_spc.fill(0) | |
2186 | self.data_dc.fill(0) |
|
2211 | self.data_dc.fill(0) | |
2187 | if self.data_cspc != None: |
|
2212 | if self.data_cspc != None: | |
2188 | self.data_cspc.fill(0) |
|
2213 | self.data_cspc.fill(0) | |
2189 |
|
2214 | |||
2190 | self.flagIsNewFile = 0 |
|
2215 | self.flagIsNewFile = 0 | |
2191 | self.flagIsNewBlock = 1 |
|
2216 | self.flagIsNewBlock = 1 | |
2192 | self.nTotalBlocks += 1 |
|
2217 | self.nTotalBlocks += 1 | |
2193 | self.nWriteBlocks += 1 |
|
2218 | self.nWriteBlocks += 1 | |
2194 | self.blockIndex += 1 |
|
2219 | self.blockIndex += 1 | |
2195 |
|
2220 | |||
2196 |
|
2221 | |||
2197 | def putData(self): |
|
2222 | def putData(self): | |
2198 | """ |
|
2223 | """ | |
2199 | Setea un bloque de datos y luego los escribe en un file |
|
2224 | Setea un bloque de datos y luego los escribe en un file | |
2200 |
|
2225 | |||
2201 | Affected: |
|
2226 | Affected: | |
2202 | self.data_spc |
|
2227 | self.data_spc | |
2203 | self.data_cspc |
|
2228 | self.data_cspc | |
2204 | self.data_dc |
|
2229 | self.data_dc | |
2205 |
|
2230 | |||
2206 | Return: |
|
2231 | Return: | |
2207 | 0 : Si no hay data o no hay mas files que puedan escribirse |
|
2232 | 0 : Si no hay data o no hay mas files que puedan escribirse | |
2208 | 1 : Si se escribio la data de un bloque en un file |
|
2233 | 1 : Si se escribio la data de un bloque en un file | |
2209 | """ |
|
2234 | """ | |
2210 |
|
2235 | |||
2211 | if self.dataOut.flagNoData: |
|
2236 | if self.dataOut.flagNoData: | |
2212 | return 0 |
|
2237 | return 0 | |
2213 |
|
2238 | |||
2214 | self.flagIsNewBlock = 0 |
|
2239 | self.flagIsNewBlock = 0 | |
2215 |
|
2240 | |||
2216 | if self.dataOut.flagTimeBlock: |
|
2241 | if self.dataOut.flagTimeBlock: | |
2217 | self.data_spc.fill(0) |
|
2242 | self.data_spc.fill(0) | |
2218 | self.data_cspc.fill(0) |
|
2243 | self.data_cspc.fill(0) | |
2219 | self.data_dc.fill(0) |
|
2244 | self.data_dc.fill(0) | |
2220 | self.setNextFile() |
|
2245 | self.setNextFile() | |
2221 |
|
2246 | |||
2222 | if self.flagIsNewFile == 0: |
|
2247 | if self.flagIsNewFile == 0: | |
2223 | self.getBasicHeader() |
|
2248 | self.getBasicHeader() | |
2224 |
|
2249 | |||
2225 | self.data_spc = self.dataOut.data_spc |
|
2250 | self.data_spc = self.dataOut.data_spc | |
2226 | self.data_cspc = self.dataOut.data_cspc |
|
2251 | self.data_cspc = self.dataOut.data_cspc | |
2227 | self.data_dc = self.dataOut.data_dc |
|
2252 | self.data_dc = self.dataOut.data_dc | |
2228 |
|
2253 | |||
2229 | # #self.processingHeaderObj.dataBlocksPerFile) |
|
2254 | # #self.processingHeaderObj.dataBlocksPerFile) | |
2230 | if self.hasAllDataInBuffer(): |
|
2255 | if self.hasAllDataInBuffer(): | |
2231 | # self.getDataHeader() |
|
2256 | # self.getDataHeader() | |
2232 | self.writeNextBlock() |
|
2257 | self.writeNextBlock() | |
2233 |
|
2258 | |||
2234 | return 1 |
|
2259 | return 1 | |
2235 |
|
2260 | |||
2236 |
|
2261 | |||
2237 | def __getProcessFlags(self): |
|
2262 | def __getProcessFlags(self): | |
2238 |
|
2263 | |||
2239 | processFlags = 0 |
|
2264 | processFlags = 0 | |
2240 |
|
2265 | |||
2241 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
2266 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
2242 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
2267 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
2243 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
2268 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
2244 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
2269 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
2245 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
2270 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
2246 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
2271 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
2247 |
|
2272 | |||
2248 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
2273 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] | |
2249 |
|
2274 | |||
2250 |
|
2275 | |||
2251 |
|
2276 | |||
2252 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, |
|
2277 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, | |
2253 | PROCFLAG.DATATYPE_SHORT, |
|
2278 | PROCFLAG.DATATYPE_SHORT, | |
2254 | PROCFLAG.DATATYPE_LONG, |
|
2279 | PROCFLAG.DATATYPE_LONG, | |
2255 | PROCFLAG.DATATYPE_INT64, |
|
2280 | PROCFLAG.DATATYPE_INT64, | |
2256 | PROCFLAG.DATATYPE_FLOAT, |
|
2281 | PROCFLAG.DATATYPE_FLOAT, | |
2257 | PROCFLAG.DATATYPE_DOUBLE] |
|
2282 | PROCFLAG.DATATYPE_DOUBLE] | |
2258 |
|
2283 | |||
2259 |
|
2284 | |||
2260 | for index in range(len(dtypeList)): |
|
2285 | for index in range(len(dtypeList)): | |
2261 | if self.dataOut.dtype == dtypeList[index]: |
|
2286 | if self.dataOut.dtype == dtypeList[index]: | |
2262 | dtypeValue = datatypeValueList[index] |
|
2287 | dtypeValue = datatypeValueList[index] | |
2263 | break |
|
2288 | break | |
2264 |
|
2289 | |||
2265 | processFlags += dtypeValue |
|
2290 | processFlags += dtypeValue | |
2266 |
|
2291 | |||
2267 | if self.dataOut.flagDecodeData: |
|
2292 | if self.dataOut.flagDecodeData: | |
2268 | processFlags += PROCFLAG.DECODE_DATA |
|
2293 | processFlags += PROCFLAG.DECODE_DATA | |
2269 |
|
2294 | |||
2270 | if self.dataOut.flagDeflipData: |
|
2295 | if self.dataOut.flagDeflipData: | |
2271 | processFlags += PROCFLAG.DEFLIP_DATA |
|
2296 | processFlags += PROCFLAG.DEFLIP_DATA | |
2272 |
|
2297 | |||
2273 | if self.dataOut.code != None: |
|
2298 | if self.dataOut.code != None: | |
2274 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE |
|
2299 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE | |
2275 |
|
2300 | |||
2276 | if self.dataOut.nIncohInt > 1: |
|
2301 | if self.dataOut.nIncohInt > 1: | |
2277 | processFlags += PROCFLAG.INCOHERENT_INTEGRATION |
|
2302 | processFlags += PROCFLAG.INCOHERENT_INTEGRATION | |
2278 |
|
2303 | |||
2279 | if self.dataOut.data_dc != None: |
|
2304 | if self.dataOut.data_dc != None: | |
2280 | processFlags += PROCFLAG.SAVE_CHANNELS_DC |
|
2305 | processFlags += PROCFLAG.SAVE_CHANNELS_DC | |
2281 |
|
2306 | |||
2282 | return processFlags |
|
2307 | return processFlags | |
2283 |
|
2308 | |||
2284 |
|
2309 | |||
2285 | def __getBlockSize(self): |
|
2310 | def __getBlockSize(self): | |
2286 | ''' |
|
2311 | ''' | |
2287 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra |
|
2312 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra | |
2288 | ''' |
|
2313 | ''' | |
2289 |
|
2314 | |||
2290 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
2315 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
2291 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
2316 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
2292 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
2317 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
2293 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
2318 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
2294 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
2319 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
2295 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
2320 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
2296 |
|
2321 | |||
2297 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
2322 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] | |
2298 | datatypeValueList = [1,2,4,8,4,8] |
|
2323 | datatypeValueList = [1,2,4,8,4,8] | |
2299 | for index in range(len(dtypeList)): |
|
2324 | for index in range(len(dtypeList)): | |
2300 | if self.dataOut.dtype == dtypeList[index]: |
|
2325 | if self.dataOut.dtype == dtypeList[index]: | |
2301 | datatypeValue = datatypeValueList[index] |
|
2326 | datatypeValue = datatypeValueList[index] | |
2302 | break |
|
2327 | break | |
2303 |
|
2328 | |||
2304 |
|
2329 | |||
2305 | pts2write = self.dataOut.nHeights * self.dataOut.nFFTPoints |
|
2330 | pts2write = self.dataOut.nHeights * self.dataOut.nFFTPoints | |
2306 |
|
2331 | |||
2307 | pts2write_SelfSpectra = int(self.dataOut.nChannels * pts2write) |
|
2332 | pts2write_SelfSpectra = int(self.dataOut.nChannels * pts2write) | |
2308 | blocksize = (pts2write_SelfSpectra*datatypeValue) |
|
2333 | blocksize = (pts2write_SelfSpectra*datatypeValue) | |
2309 |
|
2334 | |||
2310 | if self.dataOut.data_cspc != None: |
|
2335 | if self.dataOut.data_cspc != None: | |
2311 | pts2write_CrossSpectra = int(self.dataOut.nPairs * pts2write) |
|
2336 | pts2write_CrossSpectra = int(self.dataOut.nPairs * pts2write) | |
2312 | blocksize += (pts2write_CrossSpectra*datatypeValue*2) |
|
2337 | blocksize += (pts2write_CrossSpectra*datatypeValue*2) | |
2313 |
|
2338 | |||
2314 | if self.dataOut.data_dc != None: |
|
2339 | if self.dataOut.data_dc != None: | |
2315 | pts2write_DCchannels = int(self.dataOut.nChannels * self.dataOut.nHeights) |
|
2340 | pts2write_DCchannels = int(self.dataOut.nChannels * self.dataOut.nHeights) | |
2316 | blocksize += (pts2write_DCchannels*datatypeValue*2) |
|
2341 | blocksize += (pts2write_DCchannels*datatypeValue*2) | |
2317 |
|
2342 | |||
2318 | blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO |
|
2343 | blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO | |
2319 |
|
2344 | |||
2320 | return blocksize |
|
2345 | return blocksize | |
2321 |
|
2346 | |||
2322 | def getDataHeader(self): |
|
2347 | def getDataHeader(self): | |
2323 |
|
2348 | |||
2324 | """ |
|
2349 | """ | |
2325 | Obtiene una copia del First Header |
|
2350 | Obtiene una copia del First Header | |
2326 |
|
2351 | |||
2327 | Affected: |
|
2352 | Affected: | |
2328 | self.systemHeaderObj |
|
2353 | self.systemHeaderObj | |
2329 | self.radarControllerHeaderObj |
|
2354 | self.radarControllerHeaderObj | |
2330 | self.dtype |
|
2355 | self.dtype | |
2331 |
|
2356 | |||
2332 | Return: |
|
2357 | Return: | |
2333 | None |
|
2358 | None | |
2334 | """ |
|
2359 | """ | |
2335 |
|
2360 | |||
2336 | self.systemHeaderObj = self.dataOut.systemHeaderObj.copy() |
|
2361 | self.systemHeaderObj = self.dataOut.systemHeaderObj.copy() | |
2337 | self.systemHeaderObj.nChannels = self.dataOut.nChannels |
|
2362 | self.systemHeaderObj.nChannels = self.dataOut.nChannels | |
2338 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() |
|
2363 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() | |
2339 |
|
2364 | |||
2340 | self.getBasicHeader() |
|
2365 | self.getBasicHeader() | |
2341 |
|
2366 | |||
2342 | processingHeaderSize = 40 # bytes |
|
2367 | processingHeaderSize = 40 # bytes | |
2343 | self.processingHeaderObj.dtype = 0 # Voltage |
|
2368 | self.processingHeaderObj.dtype = 0 # Voltage | |
2344 | self.processingHeaderObj.blockSize = self.__getBlockSize() |
|
2369 | self.processingHeaderObj.blockSize = self.__getBlockSize() | |
2345 | self.processingHeaderObj.profilesPerBlock = self.dataOut.nFFTPoints |
|
2370 | self.processingHeaderObj.profilesPerBlock = self.dataOut.nFFTPoints | |
2346 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile |
|
2371 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile | |
2347 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows |
|
2372 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows | |
2348 | self.processingHeaderObj.processFlags = self.__getProcessFlags() |
|
2373 | self.processingHeaderObj.processFlags = self.__getProcessFlags() | |
2349 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt# Se requiere para determinar el valor de timeInterval |
|
2374 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt# Se requiere para determinar el valor de timeInterval | |
2350 | self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt |
|
2375 | self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt | |
2351 | self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels |
|
2376 | self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels | |
2352 |
|
2377 | |||
2353 | if self.processingHeaderObj.totalSpectra > 0: |
|
2378 | if self.processingHeaderObj.totalSpectra > 0: | |
2354 | channelList = [] |
|
2379 | channelList = [] | |
2355 | for channel in range(self.dataOut.nChannels): |
|
2380 | for channel in range(self.dataOut.nChannels): | |
2356 | channelList.append(channel) |
|
2381 | channelList.append(channel) | |
2357 | channelList.append(channel) |
|
2382 | channelList.append(channel) | |
2358 |
|
2383 | |||
2359 | pairsList = [] |
|
2384 | pairsList = [] | |
2360 | for pair in self.dataOut.pairsList: |
|
2385 | for pair in self.dataOut.pairsList: | |
2361 | pairsList.append(pair[0]) |
|
2386 | pairsList.append(pair[0]) | |
2362 | pairsList.append(pair[1]) |
|
2387 | pairsList.append(pair[1]) | |
2363 | spectraComb = channelList + pairsList |
|
2388 | spectraComb = channelList + pairsList | |
2364 | spectraComb = numpy.array(spectraComb,dtype="u1") |
|
2389 | spectraComb = numpy.array(spectraComb,dtype="u1") | |
2365 | self.processingHeaderObj.spectraComb = spectraComb |
|
2390 | self.processingHeaderObj.spectraComb = spectraComb | |
2366 | sizeOfSpcComb = len(spectraComb) |
|
2391 | sizeOfSpcComb = len(spectraComb) | |
2367 | processingHeaderSize += sizeOfSpcComb |
|
2392 | processingHeaderSize += sizeOfSpcComb | |
2368 |
|
2393 | |||
2369 | if self.dataOut.code != None: |
|
2394 | if self.dataOut.code != None: | |
2370 | self.processingHeaderObj.code = self.dataOut.code |
|
2395 | self.processingHeaderObj.code = self.dataOut.code | |
2371 | self.processingHeaderObj.nCode = self.dataOut.nCode |
|
2396 | self.processingHeaderObj.nCode = self.dataOut.nCode | |
2372 | self.processingHeaderObj.nBaud = self.dataOut.nBaud |
|
2397 | self.processingHeaderObj.nBaud = self.dataOut.nBaud | |
2373 | nCodeSize = 4 # bytes |
|
2398 | nCodeSize = 4 # bytes | |
2374 | nBaudSize = 4 # bytes |
|
2399 | nBaudSize = 4 # bytes | |
2375 | codeSize = 4 # bytes |
|
2400 | codeSize = 4 # bytes | |
2376 | sizeOfCode = int(nCodeSize + nBaudSize + codeSize * self.dataOut.nCode * self.dataOut.nBaud) |
|
2401 | sizeOfCode = int(nCodeSize + nBaudSize + codeSize * self.dataOut.nCode * self.dataOut.nBaud) | |
2377 | processingHeaderSize += sizeOfCode |
|
2402 | processingHeaderSize += sizeOfCode | |
2378 |
|
2403 | |||
2379 | if self.processingHeaderObj.nWindows != 0: |
|
2404 | if self.processingHeaderObj.nWindows != 0: | |
2380 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] |
|
2405 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] | |
2381 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
2406 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] | |
2382 | self.processingHeaderObj.nHeights = self.dataOut.nHeights |
|
2407 | self.processingHeaderObj.nHeights = self.dataOut.nHeights | |
2383 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights |
|
2408 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights | |
2384 | sizeOfFirstHeight = 4 |
|
2409 | sizeOfFirstHeight = 4 | |
2385 | sizeOfdeltaHeight = 4 |
|
2410 | sizeOfdeltaHeight = 4 | |
2386 | sizeOfnHeights = 4 |
|
2411 | sizeOfnHeights = 4 | |
2387 | sizeOfWindows = (sizeOfFirstHeight + sizeOfdeltaHeight + sizeOfnHeights)*self.processingHeaderObj.nWindows |
|
2412 | sizeOfWindows = (sizeOfFirstHeight + sizeOfdeltaHeight + sizeOfnHeights)*self.processingHeaderObj.nWindows | |
2388 | processingHeaderSize += sizeOfWindows |
|
2413 | processingHeaderSize += sizeOfWindows | |
2389 |
|
2414 | |||
2390 | self.processingHeaderObj.size = processingHeaderSize |
|
2415 | self.processingHeaderObj.size = processingHeaderSize | |
2391 |
|
2416 | |||
2392 | class SpectraHeisWriter(): |
|
2417 | class SpectraHeisWriter(): | |
2393 |
|
2418 | |||
2394 | i=0 |
|
2419 | i=0 | |
2395 |
|
2420 | |||
2396 | def __init__(self, dataOut): |
|
2421 | def __init__(self, dataOut): | |
2397 |
|
2422 | |||
2398 | self.wrObj = FITS() |
|
2423 | self.wrObj = FITS() | |
2399 | self.dataOut = dataOut |
|
2424 | self.dataOut = dataOut | |
2400 |
|
2425 | |||
2401 | def isNumber(str): |
|
2426 | def isNumber(str): | |
2402 | """ |
|
2427 | """ | |
2403 | Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero. |
|
2428 | Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero. | |
2404 |
|
2429 | |||
2405 | Excepciones: |
|
2430 | Excepciones: | |
2406 | Si un determinado string no puede ser convertido a numero |
|
2431 | Si un determinado string no puede ser convertido a numero | |
2407 | Input: |
|
2432 | Input: | |
2408 | str, string al cual se le analiza para determinar si convertible a un numero o no |
|
2433 | str, string al cual se le analiza para determinar si convertible a un numero o no | |
2409 |
|
2434 | |||
2410 | Return: |
|
2435 | Return: | |
2411 | True : si el string es uno numerico |
|
2436 | True : si el string es uno numerico | |
2412 | False : no es un string numerico |
|
2437 | False : no es un string numerico | |
2413 | """ |
|
2438 | """ | |
2414 | try: |
|
2439 | try: | |
2415 | float( str ) |
|
2440 | float( str ) | |
2416 | return True |
|
2441 | return True | |
2417 | except: |
|
2442 | except: | |
2418 | return False |
|
2443 | return False | |
2419 |
|
2444 | |||
2420 | def setup(self, wrpath,): |
|
2445 | def setup(self, wrpath,): | |
2421 |
|
2446 | |||
2422 | if not(os.path.exists(wrpath)): |
|
2447 | if not(os.path.exists(wrpath)): | |
2423 | os.mkdir(wrpath) |
|
2448 | os.mkdir(wrpath) | |
2424 |
|
2449 | |||
2425 | self.wrpath = wrpath |
|
2450 | self.wrpath = wrpath | |
2426 | self.setFile = 0 |
|
2451 | self.setFile = 0 | |
2427 |
|
2452 | |||
2428 | def putData(self): |
|
2453 | def putData(self): | |
2429 | # self.wrObj.writeHeader(nChannels=self.dataOut.nChannels, nFFTPoints=self.dataOut.nFFTPoints) |
|
2454 | # self.wrObj.writeHeader(nChannels=self.dataOut.nChannels, nFFTPoints=self.dataOut.nFFTPoints) | |
2430 | #name = self.dataOut.utctime |
|
2455 | #name = self.dataOut.utctime | |
2431 | name= time.localtime( self.dataOut.utctime) |
|
2456 | name= time.localtime( self.dataOut.utctime) | |
2432 | ext=".fits" |
|
2457 | ext=".fits" | |
2433 | #folder='D%4.4d%3.3d'%(name.tm_year,name.tm_yday) |
|
2458 | #folder='D%4.4d%3.3d'%(name.tm_year,name.tm_yday) | |
2434 | subfolder = 'D%4.4d%3.3d' % (name.tm_year,name.tm_yday) |
|
2459 | subfolder = 'D%4.4d%3.3d' % (name.tm_year,name.tm_yday) | |
2435 |
|
2460 | |||
2436 |
|
|
2461 | fullpath = os.path.join( self.wrpath, subfolder ) | |
2437 |
if not( os.path.exists( |
|
2462 | if not( os.path.exists(fullpath) ): | |
2438 |
os.mkdir( |
|
2463 | os.mkdir(fullpath) | |
2439 | self.setFile += 1 |
|
2464 | self.setFile += 1 | |
2440 | file = 'D%4.4d%3.3d%3.3d%s' % (name.tm_year,name.tm_yday,self.setFile,ext) |
|
2465 | file = 'D%4.4d%3.3d%3.3d%s' % (name.tm_year,name.tm_yday,self.setFile,ext) | |
2441 |
|
2466 | |||
2442 | filename = os.path.join(self.wrpath,subfolder, file) |
|
2467 | filename = os.path.join(self.wrpath,subfolder, file) | |
2443 |
|
2468 | |||
2444 | # print self.dataOut.ippSeconds |
|
2469 | # print self.dataOut.ippSeconds | |
2445 | freq=numpy.arange(-1*self.dataOut.nHeights/2.,self.dataOut.nHeights/2.)/(2*self.dataOut.ippSeconds) |
|
2470 | freq=numpy.arange(-1*self.dataOut.nHeights/2.,self.dataOut.nHeights/2.)/(2*self.dataOut.ippSeconds) | |
2446 |
|
2471 | |||
2447 | col1=self.wrObj.setColF(name="freq", format=str(self.dataOut.nFFTPoints)+'E', array=freq) |
|
2472 | col1=self.wrObj.setColF(name="freq", format=str(self.dataOut.nFFTPoints)+'E', array=freq) | |
2448 | col2=self.wrObj.writeData(name="P_Ch1",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[0,:])) |
|
2473 | col2=self.wrObj.writeData(name="P_Ch1",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[0,:])) | |
2449 | col3=self.wrObj.writeData(name="P_Ch2",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[1,:])) |
|
2474 | col3=self.wrObj.writeData(name="P_Ch2",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[1,:])) | |
2450 | col4=self.wrObj.writeData(name="P_Ch3",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[2,:])) |
|
2475 | col4=self.wrObj.writeData(name="P_Ch3",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[2,:])) | |
2451 | col5=self.wrObj.writeData(name="P_Ch4",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[3,:])) |
|
2476 | col5=self.wrObj.writeData(name="P_Ch4",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[3,:])) | |
2452 | col6=self.wrObj.writeData(name="P_Ch5",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[4,:])) |
|
2477 | col6=self.wrObj.writeData(name="P_Ch5",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[4,:])) | |
2453 | col7=self.wrObj.writeData(name="P_Ch6",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[5,:])) |
|
2478 | col7=self.wrObj.writeData(name="P_Ch6",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[5,:])) | |
2454 | col8=self.wrObj.writeData(name="P_Ch7",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[6,:])) |
|
2479 | col8=self.wrObj.writeData(name="P_Ch7",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[6,:])) | |
2455 | col9=self.wrObj.writeData(name="P_Ch8",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[7,:])) |
|
2480 | col9=self.wrObj.writeData(name="P_Ch8",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[7,:])) | |
2456 | #n=numpy.arange((100)) |
|
2481 | #n=numpy.arange((100)) | |
2457 | n=self.dataOut.data_spc[6,:] |
|
2482 | n=self.dataOut.data_spc[6,:] | |
2458 | a=self.wrObj.cFImage(n) |
|
2483 | a=self.wrObj.cFImage(n) | |
2459 | b=self.wrObj.Ctable(col1,col2,col3,col4,col5,col6,col7,col8,col9) |
|
2484 | b=self.wrObj.Ctable(col1,col2,col3,col4,col5,col6,col7,col8,col9) | |
2460 | self.wrObj.CFile(a,b) |
|
2485 | self.wrObj.CFile(a,b) | |
2461 | self.wrObj.wFile(filename) |
|
2486 | self.wrObj.wFile(filename) | |
2462 | return 1 |
|
2487 | return 1 | |
2463 |
|
2488 | |||
2464 | class FITS: |
|
2489 | class FITS: | |
2465 |
|
2490 | |||
2466 | name=None |
|
2491 | name=None | |
2467 | format=None |
|
2492 | format=None | |
2468 | array =None |
|
2493 | array =None | |
2469 | data =None |
|
2494 | data =None | |
2470 | thdulist=None |
|
2495 | thdulist=None | |
2471 |
|
2496 | |||
2472 | def __init__(self): |
|
2497 | def __init__(self): | |
2473 |
|
2498 | |||
2474 | pass |
|
2499 | pass | |
2475 |
|
2500 | |||
2476 | def setColF(self,name,format,array): |
|
2501 | def setColF(self,name,format,array): | |
2477 | self.name=name |
|
2502 | self.name=name | |
2478 | self.format=format |
|
2503 | self.format=format | |
2479 | self.array=array |
|
2504 | self.array=array | |
2480 | a1=numpy.array([self.array],dtype=numpy.float32) |
|
2505 | a1=numpy.array([self.array],dtype=numpy.float32) | |
2481 | self.col1 = pyfits.Column(name=self.name, format=self.format, array=a1) |
|
2506 | self.col1 = pyfits.Column(name=self.name, format=self.format, array=a1) | |
2482 | return self.col1 |
|
2507 | return self.col1 | |
2483 |
|
2508 | |||
2484 | # def setColP(self,name,format,data): |
|
2509 | # def setColP(self,name,format,data): | |
2485 | # self.name=name |
|
2510 | # self.name=name | |
2486 | # self.format=format |
|
2511 | # self.format=format | |
2487 | # self.data=data |
|
2512 | # self.data=data | |
2488 | # a2=numpy.array([self.data],dtype=numpy.float32) |
|
2513 | # a2=numpy.array([self.data],dtype=numpy.float32) | |
2489 | # self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2) |
|
2514 | # self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2) | |
2490 | # return self.col2 |
|
2515 | # return self.col2 | |
2491 |
|
2516 | |||
2492 | def writeHeader(self,): |
|
2517 | def writeHeader(self,): | |
2493 | pass |
|
2518 | pass | |
2494 |
|
2519 | |||
2495 | def writeData(self,name,format,data): |
|
2520 | def writeData(self,name,format,data): | |
2496 | self.name=name |
|
2521 | self.name=name | |
2497 | self.format=format |
|
2522 | self.format=format | |
2498 | self.data=data |
|
2523 | self.data=data | |
2499 | a2=numpy.array([self.data],dtype=numpy.float32) |
|
2524 | a2=numpy.array([self.data],dtype=numpy.float32) | |
2500 | self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2) |
|
2525 | self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2) | |
2501 | return self.col2 |
|
2526 | return self.col2 | |
2502 |
|
2527 | |||
2503 | def cFImage(self,n): |
|
2528 | def cFImage(self,n): | |
2504 | self.hdu= pyfits.PrimaryHDU(n) |
|
2529 | self.hdu= pyfits.PrimaryHDU(n) | |
2505 | return self.hdu |
|
2530 | return self.hdu | |
2506 |
|
2531 | |||
2507 | def Ctable(self,col1,col2,col3,col4,col5,col6,col7,col8,col9): |
|
2532 | def Ctable(self,col1,col2,col3,col4,col5,col6,col7,col8,col9): | |
2508 | self.cols=pyfits.ColDefs( [col1,col2,col3,col4,col5,col6,col7,col8,col9]) |
|
2533 | self.cols=pyfits.ColDefs( [col1,col2,col3,col4,col5,col6,col7,col8,col9]) | |
2509 | self.tbhdu = pyfits.new_table(self.cols) |
|
2534 | self.tbhdu = pyfits.new_table(self.cols) | |
2510 | return self.tbhdu |
|
2535 | return self.tbhdu | |
2511 |
|
2536 | |||
2512 | def CFile(self,hdu,tbhdu): |
|
2537 | def CFile(self,hdu,tbhdu): | |
2513 | self.thdulist=pyfits.HDUList([hdu,tbhdu]) |
|
2538 | self.thdulist=pyfits.HDUList([hdu,tbhdu]) | |
2514 |
|
2539 | |||
2515 | def wFile(self,filename): |
|
2540 | def wFile(self,filename): | |
2516 | self.thdulist.writeto(filename) No newline at end of file |
|
2541 | self.thdulist.writeto(filename) |
@@ -1,516 +1,519 | |||||
1 | ''' |
|
1 | ''' | |
2 |
|
2 | |||
3 | $Author: murco $ |
|
3 | $Author: murco $ | |
4 | $Id: JROHeaderIO.py 151 2012-10-31 19:00:51Z murco $ |
|
4 | $Id: JROHeaderIO.py 151 2012-10-31 19:00:51Z murco $ | |
5 | ''' |
|
5 | ''' | |
6 | import sys |
|
6 | import sys | |
7 | import numpy |
|
7 | import numpy | |
8 | import copy |
|
8 | import copy | |
|
9 | import datetime | |||
9 |
|
10 | |||
10 | class Header: |
|
11 | class Header: | |
11 |
|
12 | |||
12 | def __init__(self): |
|
13 | def __init__(self): | |
13 | raise |
|
14 | raise | |
14 |
|
15 | |||
15 | def copy(self): |
|
16 | def copy(self): | |
16 | return copy.deepcopy(self) |
|
17 | return copy.deepcopy(self) | |
17 |
|
18 | |||
18 | def read(): |
|
19 | def read(): | |
19 | pass |
|
20 | pass | |
20 |
|
21 | |||
21 | def write(): |
|
22 | def write(): | |
22 | pass |
|
23 | pass | |
23 |
|
24 | |||
24 | def printInfo(self): |
|
25 | def printInfo(self): | |
25 |
|
26 | |||
26 | for key in self.__dict__.keys(): |
|
27 | for key in self.__dict__.keys(): | |
27 | print "%s = %s" %(key, self.__dict__[key]) |
|
28 | print "%s = %s" %(key, self.__dict__[key]) | |
28 |
|
29 | |||
29 | class BasicHeader(Header): |
|
30 | class BasicHeader(Header): | |
30 |
|
31 | |||
31 | size = None |
|
32 | size = None | |
32 | version = None |
|
33 | version = None | |
33 | dataBlock = None |
|
34 | dataBlock = None | |
34 | utc = None |
|
35 | utc = None | |
35 | miliSecond = None |
|
36 | miliSecond = None | |
36 | timeZone = None |
|
37 | timeZone = None | |
37 | dstFlag = None |
|
38 | dstFlag = None | |
38 | errorCount = None |
|
39 | errorCount = None | |
39 | struct = None |
|
40 | struct = None | |
|
41 | datatime = None | |||
40 |
|
42 | |||
41 | def __init__(self): |
|
43 | def __init__(self): | |
42 |
|
44 | |||
43 | self.size = 0 |
|
45 | self.size = 0 | |
44 | self.version = 0 |
|
46 | self.version = 0 | |
45 | self.dataBlock = 0 |
|
47 | self.dataBlock = 0 | |
46 | self.utc = 0 |
|
48 | self.utc = 0 | |
47 | self.miliSecond = 0 |
|
49 | self.miliSecond = 0 | |
48 | self.timeZone = 0 |
|
50 | self.timeZone = 0 | |
49 | self.dstFlag = 0 |
|
51 | self.dstFlag = 0 | |
50 | self.errorCount = 0 |
|
52 | self.errorCount = 0 | |
51 | self.struct = numpy.dtype([ |
|
53 | self.struct = numpy.dtype([ | |
52 | ('nSize','<u4'), |
|
54 | ('nSize','<u4'), | |
53 | ('nVersion','<u2'), |
|
55 | ('nVersion','<u2'), | |
54 | ('nDataBlockId','<u4'), |
|
56 | ('nDataBlockId','<u4'), | |
55 | ('nUtime','<u4'), |
|
57 | ('nUtime','<u4'), | |
56 | ('nMilsec','<u2'), |
|
58 | ('nMilsec','<u2'), | |
57 | ('nTimezone','<i2'), |
|
59 | ('nTimezone','<i2'), | |
58 | ('nDstflag','<i2'), |
|
60 | ('nDstflag','<i2'), | |
59 | ('nErrorCount','<u4') |
|
61 | ('nErrorCount','<u4') | |
60 | ]) |
|
62 | ]) | |
61 |
|
63 | |||
62 |
|
64 | |||
63 | def read(self, fp): |
|
65 | def read(self, fp): | |
64 | try: |
|
66 | try: | |
65 | header = numpy.fromfile(fp, self.struct,1) |
|
67 | header = numpy.fromfile(fp, self.struct,1) | |
66 | self.size = int(header['nSize'][0]) |
|
68 | self.size = int(header['nSize'][0]) | |
67 | self.version = int(header['nVersion'][0]) |
|
69 | self.version = int(header['nVersion'][0]) | |
68 | self.dataBlock = int(header['nDataBlockId'][0]) |
|
70 | self.dataBlock = int(header['nDataBlockId'][0]) | |
69 | self.utc = int(header['nUtime'][0]) |
|
71 | self.utc = int(header['nUtime'][0]) | |
70 | self.miliSecond = int(header['nMilsec'][0]) |
|
72 | self.miliSecond = int(header['nMilsec'][0]) | |
71 | self.timeZone = int(header['nTimezone'][0]) |
|
73 | self.timeZone = int(header['nTimezone'][0]) | |
72 | self.dstFlag = int(header['nDstflag'][0]) |
|
74 | self.dstFlag = int(header['nDstflag'][0]) | |
73 | self.errorCount = int(header['nErrorCount'][0]) |
|
75 | self.errorCount = int(header['nErrorCount'][0]) | |
74 |
|
76 | |||
|
77 | self.datatime = datetime.datetime.utcfromtimestamp(self.utc) | |||
75 | except Exception, e: |
|
78 | except Exception, e: | |
76 | print "BasicHeader: " + e |
|
79 | print "BasicHeader: " + e | |
77 | return 0 |
|
80 | return 0 | |
78 |
|
81 | |||
79 | return 1 |
|
82 | return 1 | |
80 |
|
83 | |||
81 | def write(self, fp): |
|
84 | def write(self, fp): | |
82 | headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount) |
|
85 | headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount) | |
83 | header = numpy.array(headerTuple,self.struct) |
|
86 | header = numpy.array(headerTuple,self.struct) | |
84 | header.tofile(fp) |
|
87 | header.tofile(fp) | |
85 |
|
88 | |||
86 | return 1 |
|
89 | return 1 | |
87 |
|
90 | |||
88 | class SystemHeader(Header): |
|
91 | class SystemHeader(Header): | |
89 |
|
92 | |||
90 | size = None |
|
93 | size = None | |
91 | nSamples = None |
|
94 | nSamples = None | |
92 | nProfiles = None |
|
95 | nProfiles = None | |
93 | nChannels = None |
|
96 | nChannels = None | |
94 | adcResolution = None |
|
97 | adcResolution = None | |
95 | pciDioBusWidth = None |
|
98 | pciDioBusWidth = None | |
96 | struct = None |
|
99 | struct = None | |
97 |
|
100 | |||
98 | def __init__(self): |
|
101 | def __init__(self): | |
99 | self.size = 0 |
|
102 | self.size = 0 | |
100 | self.nSamples = 0 |
|
103 | self.nSamples = 0 | |
101 | self.nProfiles = 0 |
|
104 | self.nProfiles = 0 | |
102 | self.nChannels = 0 |
|
105 | self.nChannels = 0 | |
103 | self.adcResolution = 0 |
|
106 | self.adcResolution = 0 | |
104 | self.pciDioBusWidth = 0 |
|
107 | self.pciDioBusWidth = 0 | |
105 | self.struct = numpy.dtype([ |
|
108 | self.struct = numpy.dtype([ | |
106 | ('nSize','<u4'), |
|
109 | ('nSize','<u4'), | |
107 | ('nNumSamples','<u4'), |
|
110 | ('nNumSamples','<u4'), | |
108 | ('nNumProfiles','<u4'), |
|
111 | ('nNumProfiles','<u4'), | |
109 | ('nNumChannels','<u4'), |
|
112 | ('nNumChannels','<u4'), | |
110 | ('nADCResolution','<u4'), |
|
113 | ('nADCResolution','<u4'), | |
111 | ('nPCDIOBusWidth','<u4'), |
|
114 | ('nPCDIOBusWidth','<u4'), | |
112 | ]) |
|
115 | ]) | |
113 |
|
116 | |||
114 |
|
117 | |||
115 | def read(self, fp): |
|
118 | def read(self, fp): | |
116 | try: |
|
119 | try: | |
117 | header = numpy.fromfile(fp,self.struct,1) |
|
120 | header = numpy.fromfile(fp,self.struct,1) | |
118 | self.size = header['nSize'][0] |
|
121 | self.size = header['nSize'][0] | |
119 | self.nSamples = header['nNumSamples'][0] |
|
122 | self.nSamples = header['nNumSamples'][0] | |
120 | self.nProfiles = header['nNumProfiles'][0] |
|
123 | self.nProfiles = header['nNumProfiles'][0] | |
121 | self.nChannels = header['nNumChannels'][0] |
|
124 | self.nChannels = header['nNumChannels'][0] | |
122 | self.adcResolution = header['nADCResolution'][0] |
|
125 | self.adcResolution = header['nADCResolution'][0] | |
123 | self.pciDioBusWidth = header['nPCDIOBusWidth'][0] |
|
126 | self.pciDioBusWidth = header['nPCDIOBusWidth'][0] | |
124 |
|
127 | |||
125 | except Exception, e: |
|
128 | except Exception, e: | |
126 | print "SystemHeader: " + e |
|
129 | print "SystemHeader: " + e | |
127 | return 0 |
|
130 | return 0 | |
128 |
|
131 | |||
129 | return 1 |
|
132 | return 1 | |
130 |
|
133 | |||
131 | def write(self, fp): |
|
134 | def write(self, fp): | |
132 | headerTuple = (self.size,self.nSamples,self.nProfiles,self.nChannels,self.adcResolution,self.pciDioBusWidth) |
|
135 | headerTuple = (self.size,self.nSamples,self.nProfiles,self.nChannels,self.adcResolution,self.pciDioBusWidth) | |
133 | header = numpy.array(headerTuple,self.struct) |
|
136 | header = numpy.array(headerTuple,self.struct) | |
134 | header.tofile(fp) |
|
137 | header.tofile(fp) | |
135 |
|
138 | |||
136 | return 1 |
|
139 | return 1 | |
137 |
|
140 | |||
138 | class RadarControllerHeader(Header): |
|
141 | class RadarControllerHeader(Header): | |
139 |
|
142 | |||
140 | size = None |
|
143 | size = None | |
141 | expType = None |
|
144 | expType = None | |
142 | nTx = None |
|
145 | nTx = None | |
143 | ipp = None |
|
146 | ipp = None | |
144 | txA = None |
|
147 | txA = None | |
145 | txB = None |
|
148 | txB = None | |
146 | nWindows = None |
|
149 | nWindows = None | |
147 | numTaus = None |
|
150 | numTaus = None | |
148 | codeType = None |
|
151 | codeType = None | |
149 | line6Function = None |
|
152 | line6Function = None | |
150 | line5Function = None |
|
153 | line5Function = None | |
151 | fClock = None |
|
154 | fClock = None | |
152 | prePulseBefore = None |
|
155 | prePulseBefore = None | |
153 | prePulserAfter = None |
|
156 | prePulserAfter = None | |
154 | rangeIpp = None |
|
157 | rangeIpp = None | |
155 | rangeTxA = None |
|
158 | rangeTxA = None | |
156 | rangeTxB = None |
|
159 | rangeTxB = None | |
157 | struct = None |
|
160 | struct = None | |
158 |
|
161 | |||
159 | def __init__(self): |
|
162 | def __init__(self): | |
160 | self.size = 0 |
|
163 | self.size = 0 | |
161 | self.expType = 0 |
|
164 | self.expType = 0 | |
162 | self.nTx = 0 |
|
165 | self.nTx = 0 | |
163 | self.ipp = 0 |
|
166 | self.ipp = 0 | |
164 | self.txA = 0 |
|
167 | self.txA = 0 | |
165 | self.txB = 0 |
|
168 | self.txB = 0 | |
166 | self.nWindows = 0 |
|
169 | self.nWindows = 0 | |
167 | self.numTaus = 0 |
|
170 | self.numTaus = 0 | |
168 | self.codeType = 0 |
|
171 | self.codeType = 0 | |
169 | self.line6Function = 0 |
|
172 | self.line6Function = 0 | |
170 | self.line5Function = 0 |
|
173 | self.line5Function = 0 | |
171 | self.fClock = 0 |
|
174 | self.fClock = 0 | |
172 | self.prePulseBefore = 0 |
|
175 | self.prePulseBefore = 0 | |
173 | self.prePulserAfter = 0 |
|
176 | self.prePulserAfter = 0 | |
174 | self.rangeIpp = 0 |
|
177 | self.rangeIpp = 0 | |
175 | self.rangeTxA = 0 |
|
178 | self.rangeTxA = 0 | |
176 | self.rangeTxB = 0 |
|
179 | self.rangeTxB = 0 | |
177 | self.struct = numpy.dtype([ |
|
180 | self.struct = numpy.dtype([ | |
178 | ('nSize','<u4'), |
|
181 | ('nSize','<u4'), | |
179 | ('nExpType','<u4'), |
|
182 | ('nExpType','<u4'), | |
180 | ('nNTx','<u4'), |
|
183 | ('nNTx','<u4'), | |
181 | ('fIpp','<f4'), |
|
184 | ('fIpp','<f4'), | |
182 | ('fTxA','<f4'), |
|
185 | ('fTxA','<f4'), | |
183 | ('fTxB','<f4'), |
|
186 | ('fTxB','<f4'), | |
184 | ('nNumWindows','<u4'), |
|
187 | ('nNumWindows','<u4'), | |
185 | ('nNumTaus','<u4'), |
|
188 | ('nNumTaus','<u4'), | |
186 | ('nCodeType','<u4'), |
|
189 | ('nCodeType','<u4'), | |
187 | ('nLine6Function','<u4'), |
|
190 | ('nLine6Function','<u4'), | |
188 | ('nLine5Function','<u4'), |
|
191 | ('nLine5Function','<u4'), | |
189 | ('fClock','<f4'), |
|
192 | ('fClock','<f4'), | |
190 | ('nPrePulseBefore','<u4'), |
|
193 | ('nPrePulseBefore','<u4'), | |
191 | ('nPrePulseAfter','<u4'), |
|
194 | ('nPrePulseAfter','<u4'), | |
192 | ('sRangeIPP','<a20'), |
|
195 | ('sRangeIPP','<a20'), | |
193 | ('sRangeTxA','<a20'), |
|
196 | ('sRangeTxA','<a20'), | |
194 | ('sRangeTxB','<a20'), |
|
197 | ('sRangeTxB','<a20'), | |
195 | ]) |
|
198 | ]) | |
196 |
|
199 | |||
197 | self.samplingWindowStruct = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')]) |
|
200 | self.samplingWindowStruct = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')]) | |
198 |
|
201 | |||
199 | self.samplingWindow = None |
|
202 | self.samplingWindow = None | |
200 | self.nHeights = None |
|
203 | self.nHeights = None | |
201 | self.firstHeight = None |
|
204 | self.firstHeight = None | |
202 | self.deltaHeight = None |
|
205 | self.deltaHeight = None | |
203 | self.samplesWin = None |
|
206 | self.samplesWin = None | |
204 |
|
207 | |||
205 | self.nCode = None |
|
208 | self.nCode = None | |
206 | self.nBaud = None |
|
209 | self.nBaud = None | |
207 | self.code = None |
|
210 | self.code = None | |
208 | self.flip1 = None |
|
211 | self.flip1 = None | |
209 | self.flip2 = None |
|
212 | self.flip2 = None | |
210 |
|
213 | |||
211 | self.dynamic = numpy.array([],numpy.dtype('byte')) |
|
214 | self.dynamic = numpy.array([],numpy.dtype('byte')) | |
212 |
|
215 | |||
213 |
|
216 | |||
214 | def read(self, fp): |
|
217 | def read(self, fp): | |
215 | try: |
|
218 | try: | |
216 | startFp = fp.tell() |
|
219 | startFp = fp.tell() | |
217 | header = numpy.fromfile(fp,self.struct,1) |
|
220 | header = numpy.fromfile(fp,self.struct,1) | |
218 | self.size = int(header['nSize'][0]) |
|
221 | self.size = int(header['nSize'][0]) | |
219 | self.expType = int(header['nExpType'][0]) |
|
222 | self.expType = int(header['nExpType'][0]) | |
220 | self.nTx = int(header['nNTx'][0]) |
|
223 | self.nTx = int(header['nNTx'][0]) | |
221 | self.ipp = float(header['fIpp'][0]) |
|
224 | self.ipp = float(header['fIpp'][0]) | |
222 | self.txA = float(header['fTxA'][0]) |
|
225 | self.txA = float(header['fTxA'][0]) | |
223 | self.txB = float(header['fTxB'][0]) |
|
226 | self.txB = float(header['fTxB'][0]) | |
224 | self.nWindows = int(header['nNumWindows'][0]) |
|
227 | self.nWindows = int(header['nNumWindows'][0]) | |
225 | self.numTaus = int(header['nNumTaus'][0]) |
|
228 | self.numTaus = int(header['nNumTaus'][0]) | |
226 | self.codeType = int(header['nCodeType'][0]) |
|
229 | self.codeType = int(header['nCodeType'][0]) | |
227 | self.line6Function = int(header['nLine6Function'][0]) |
|
230 | self.line6Function = int(header['nLine6Function'][0]) | |
228 | self.line5Function = int(header['nLine5Function'][0]) |
|
231 | self.line5Function = int(header['nLine5Function'][0]) | |
229 | self.fClock = float(header['fClock'][0]) |
|
232 | self.fClock = float(header['fClock'][0]) | |
230 | self.prePulseBefore = int(header['nPrePulseBefore'][0]) |
|
233 | self.prePulseBefore = int(header['nPrePulseBefore'][0]) | |
231 | self.prePulserAfter = int(header['nPrePulseAfter'][0]) |
|
234 | self.prePulserAfter = int(header['nPrePulseAfter'][0]) | |
232 | self.rangeIpp = header['sRangeIPP'][0] |
|
235 | self.rangeIpp = header['sRangeIPP'][0] | |
233 | self.rangeTxA = header['sRangeTxA'][0] |
|
236 | self.rangeTxA = header['sRangeTxA'][0] | |
234 | self.rangeTxB = header['sRangeTxB'][0] |
|
237 | self.rangeTxB = header['sRangeTxB'][0] | |
235 | # jump Dynamic Radar Controller Header |
|
238 | # jump Dynamic Radar Controller Header | |
236 | jumpFp = self.size - 116 |
|
239 | jumpFp = self.size - 116 | |
237 | self.dynamic = numpy.fromfile(fp,numpy.dtype('byte'),jumpFp) |
|
240 | self.dynamic = numpy.fromfile(fp,numpy.dtype('byte'),jumpFp) | |
238 | #pointer backward to dynamic header and read |
|
241 | #pointer backward to dynamic header and read | |
239 | backFp = fp.tell() - jumpFp |
|
242 | backFp = fp.tell() - jumpFp | |
240 | fp.seek(backFp) |
|
243 | fp.seek(backFp) | |
241 |
|
244 | |||
242 | self.samplingWindow = numpy.fromfile(fp,self.samplingWindowStruct,self.nWindows) |
|
245 | self.samplingWindow = numpy.fromfile(fp,self.samplingWindowStruct,self.nWindows) | |
243 | self.nHeights = int(numpy.sum(self.samplingWindow['nsa'])) |
|
246 | self.nHeights = int(numpy.sum(self.samplingWindow['nsa'])) | |
244 | self.firstHeight = self.samplingWindow['h0'] |
|
247 | self.firstHeight = self.samplingWindow['h0'] | |
245 | self.deltaHeight = self.samplingWindow['dh'] |
|
248 | self.deltaHeight = self.samplingWindow['dh'] | |
246 | self.samplesWin = self.samplingWindow['nsa'] |
|
249 | self.samplesWin = self.samplingWindow['nsa'] | |
247 |
|
250 | |||
248 | self.Taus = numpy.fromfile(fp,'<f4',self.numTaus) |
|
251 | self.Taus = numpy.fromfile(fp,'<f4',self.numTaus) | |
249 |
|
252 | |||
250 | if self.codeType != 0: |
|
253 | if self.codeType != 0: | |
251 | self.nCode = int(numpy.fromfile(fp,'<u4',1)) |
|
254 | self.nCode = int(numpy.fromfile(fp,'<u4',1)) | |
252 | self.nBaud = int(numpy.fromfile(fp,'<u4',1)) |
|
255 | self.nBaud = int(numpy.fromfile(fp,'<u4',1)) | |
253 | self.code = numpy.empty([self.nCode,self.nBaud],dtype='u1') |
|
256 | self.code = numpy.empty([self.nCode,self.nBaud],dtype='u1') | |
254 | tempList = [] |
|
257 | tempList = [] | |
255 | for ic in range(self.nCode): |
|
258 | for ic in range(self.nCode): | |
256 | temp = numpy.fromfile(fp,'u1',4*int(numpy.ceil(self.nBaud/32.))) |
|
259 | temp = numpy.fromfile(fp,'u1',4*int(numpy.ceil(self.nBaud/32.))) | |
257 | tempList.append(temp) |
|
260 | tempList.append(temp) | |
258 | self.code[ic] = numpy.unpackbits(temp[::-1])[-1*self.nBaud:] |
|
261 | self.code[ic] = numpy.unpackbits(temp[::-1])[-1*self.nBaud:] | |
259 | self.code = 2.0*self.code - 1.0 |
|
262 | self.code = 2.0*self.code - 1.0 | |
260 |
|
263 | |||
261 | if self.line5Function == RCfunction.FLIP: |
|
264 | if self.line5Function == RCfunction.FLIP: | |
262 | self.flip1 = numpy.fromfile(fp,'<u4',1) |
|
265 | self.flip1 = numpy.fromfile(fp,'<u4',1) | |
263 |
|
266 | |||
264 | if self.line6Function == RCfunction.FLIP: |
|
267 | if self.line6Function == RCfunction.FLIP: | |
265 | self.flip2 = numpy.fromfile(fp,'<u4',1) |
|
268 | self.flip2 = numpy.fromfile(fp,'<u4',1) | |
266 |
|
269 | |||
267 | endFp = self.size + startFp |
|
270 | endFp = self.size + startFp | |
268 | jumpFp = endFp - fp.tell() |
|
271 | jumpFp = endFp - fp.tell() | |
269 | if jumpFp > 0: |
|
272 | if jumpFp > 0: | |
270 | fp.seek(jumpFp) |
|
273 | fp.seek(jumpFp) | |
271 |
|
274 | |||
272 | except Exception, e: |
|
275 | except Exception, e: | |
273 | print "RadarControllerHeader: " + e |
|
276 | print "RadarControllerHeader: " + e | |
274 | return 0 |
|
277 | return 0 | |
275 |
|
278 | |||
276 | return 1 |
|
279 | return 1 | |
277 |
|
280 | |||
278 | def write(self, fp): |
|
281 | def write(self, fp): | |
279 | headerTuple = (self.size, |
|
282 | headerTuple = (self.size, | |
280 | self.expType, |
|
283 | self.expType, | |
281 | self.nTx, |
|
284 | self.nTx, | |
282 | self.ipp, |
|
285 | self.ipp, | |
283 | self.txA, |
|
286 | self.txA, | |
284 | self.txB, |
|
287 | self.txB, | |
285 | self.nWindows, |
|
288 | self.nWindows, | |
286 | self.numTaus, |
|
289 | self.numTaus, | |
287 | self.codeType, |
|
290 | self.codeType, | |
288 | self.line6Function, |
|
291 | self.line6Function, | |
289 | self.line5Function, |
|
292 | self.line5Function, | |
290 | self.fClock, |
|
293 | self.fClock, | |
291 | self.prePulseBefore, |
|
294 | self.prePulseBefore, | |
292 | self.prePulserAfter, |
|
295 | self.prePulserAfter, | |
293 | self.rangeIpp, |
|
296 | self.rangeIpp, | |
294 | self.rangeTxA, |
|
297 | self.rangeTxA, | |
295 | self.rangeTxB) |
|
298 | self.rangeTxB) | |
296 |
|
299 | |||
297 | header = numpy.array(headerTuple,self.struct) |
|
300 | header = numpy.array(headerTuple,self.struct) | |
298 | header.tofile(fp) |
|
301 | header.tofile(fp) | |
299 |
|
302 | |||
300 | dynamic = self.dynamic |
|
303 | dynamic = self.dynamic | |
301 | dynamic.tofile(fp) |
|
304 | dynamic.tofile(fp) | |
302 |
|
305 | |||
303 | return 1 |
|
306 | return 1 | |
304 |
|
307 | |||
305 |
|
308 | |||
306 |
|
309 | |||
307 | class ProcessingHeader(Header): |
|
310 | class ProcessingHeader(Header): | |
308 |
|
311 | |||
309 | size = None |
|
312 | size = None | |
310 | dtype = None |
|
313 | dtype = None | |
311 | blockSize = None |
|
314 | blockSize = None | |
312 | profilesPerBlock = None |
|
315 | profilesPerBlock = None | |
313 | dataBlocksPerFile = None |
|
316 | dataBlocksPerFile = None | |
314 | nWindows = None |
|
317 | nWindows = None | |
315 | processFlags = None |
|
318 | processFlags = None | |
316 | nCohInt = None |
|
319 | nCohInt = None | |
317 | nIncohInt = None |
|
320 | nIncohInt = None | |
318 | totalSpectra = None |
|
321 | totalSpectra = None | |
319 | struct = None |
|
322 | struct = None | |
320 | flag_dc = None |
|
323 | flag_dc = None | |
321 | flag_cspc = None |
|
324 | flag_cspc = None | |
322 |
|
325 | |||
323 | def __init__(self): |
|
326 | def __init__(self): | |
324 | self.size = 0 |
|
327 | self.size = 0 | |
325 | self.dtype = 0 |
|
328 | self.dtype = 0 | |
326 | self.blockSize = 0 |
|
329 | self.blockSize = 0 | |
327 | self.profilesPerBlock = 0 |
|
330 | self.profilesPerBlock = 0 | |
328 | self.dataBlocksPerFile = 0 |
|
331 | self.dataBlocksPerFile = 0 | |
329 | self.nWindows = 0 |
|
332 | self.nWindows = 0 | |
330 | self.processFlags = 0 |
|
333 | self.processFlags = 0 | |
331 | self.nCohInt = 0 |
|
334 | self.nCohInt = 0 | |
332 | self.nIncohInt = 0 |
|
335 | self.nIncohInt = 0 | |
333 | self.totalSpectra = 0 |
|
336 | self.totalSpectra = 0 | |
334 | self.struct = numpy.dtype([ |
|
337 | self.struct = numpy.dtype([ | |
335 | ('nSize','<u4'), |
|
338 | ('nSize','<u4'), | |
336 | ('nDataType','<u4'), |
|
339 | ('nDataType','<u4'), | |
337 | ('nSizeOfDataBlock','<u4'), |
|
340 | ('nSizeOfDataBlock','<u4'), | |
338 | ('nProfilesperBlock','<u4'), |
|
341 | ('nProfilesperBlock','<u4'), | |
339 | ('nDataBlocksperFile','<u4'), |
|
342 | ('nDataBlocksperFile','<u4'), | |
340 | ('nNumWindows','<u4'), |
|
343 | ('nNumWindows','<u4'), | |
341 | ('nProcessFlags','<u4'), |
|
344 | ('nProcessFlags','<u4'), | |
342 | ('nCoherentIntegrations','<u4'), |
|
345 | ('nCoherentIntegrations','<u4'), | |
343 | ('nIncoherentIntegrations','<u4'), |
|
346 | ('nIncoherentIntegrations','<u4'), | |
344 | ('nTotalSpectra','<u4') |
|
347 | ('nTotalSpectra','<u4') | |
345 | ]) |
|
348 | ]) | |
346 | self.samplingWindow = 0 |
|
349 | self.samplingWindow = 0 | |
347 | self.structSamplingWindow = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')]) |
|
350 | self.structSamplingWindow = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')]) | |
348 | self.nHeights = 0 |
|
351 | self.nHeights = 0 | |
349 | self.firstHeight = 0 |
|
352 | self.firstHeight = 0 | |
350 | self.deltaHeight = 0 |
|
353 | self.deltaHeight = 0 | |
351 | self.samplesWin = 0 |
|
354 | self.samplesWin = 0 | |
352 | self.spectraComb = 0 |
|
355 | self.spectraComb = 0 | |
353 | self.nCode = None |
|
356 | self.nCode = None | |
354 | self.code = None |
|
357 | self.code = None | |
355 | self.nBaud = None |
|
358 | self.nBaud = None | |
356 | self.shif_fft = False |
|
359 | self.shif_fft = False | |
357 | self.flag_dc = False |
|
360 | self.flag_dc = False | |
358 | self.flag_cspc = False |
|
361 | self.flag_cspc = False | |
359 |
|
362 | |||
360 | def read(self, fp): |
|
363 | def read(self, fp): | |
361 | try: |
|
364 | try: | |
362 | header = numpy.fromfile(fp,self.struct,1) |
|
365 | header = numpy.fromfile(fp,self.struct,1) | |
363 | self.size = int(header['nSize'][0]) |
|
366 | self.size = int(header['nSize'][0]) | |
364 | self.dtype = int(header['nDataType'][0]) |
|
367 | self.dtype = int(header['nDataType'][0]) | |
365 | self.blockSize = int(header['nSizeOfDataBlock'][0]) |
|
368 | self.blockSize = int(header['nSizeOfDataBlock'][0]) | |
366 | self.profilesPerBlock = int(header['nProfilesperBlock'][0]) |
|
369 | self.profilesPerBlock = int(header['nProfilesperBlock'][0]) | |
367 | self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0]) |
|
370 | self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0]) | |
368 | self.nWindows = int(header['nNumWindows'][0]) |
|
371 | self.nWindows = int(header['nNumWindows'][0]) | |
369 | self.processFlags = int(header['nProcessFlags']) |
|
372 | self.processFlags = int(header['nProcessFlags']) | |
370 | self.nCohInt = int(header['nCoherentIntegrations'][0]) |
|
373 | self.nCohInt = int(header['nCoherentIntegrations'][0]) | |
371 | self.nIncohInt = int(header['nIncoherentIntegrations'][0]) |
|
374 | self.nIncohInt = int(header['nIncoherentIntegrations'][0]) | |
372 | self.totalSpectra = int(header['nTotalSpectra'][0]) |
|
375 | self.totalSpectra = int(header['nTotalSpectra'][0]) | |
373 | self.samplingWindow = numpy.fromfile(fp,self.structSamplingWindow,self.nWindows) |
|
376 | self.samplingWindow = numpy.fromfile(fp,self.structSamplingWindow,self.nWindows) | |
374 | self.nHeights = int(numpy.sum(self.samplingWindow['nsa'])) |
|
377 | self.nHeights = int(numpy.sum(self.samplingWindow['nsa'])) | |
375 | self.firstHeight = float(self.samplingWindow['h0'][0]) |
|
378 | self.firstHeight = float(self.samplingWindow['h0'][0]) | |
376 | self.deltaHeight = float(self.samplingWindow['dh'][0]) |
|
379 | self.deltaHeight = float(self.samplingWindow['dh'][0]) | |
377 | self.samplesWin = self.samplingWindow['nsa'] |
|
380 | self.samplesWin = self.samplingWindow['nsa'] | |
378 | self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra) |
|
381 | self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra) | |
379 |
|
382 | |||
380 | if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE): |
|
383 | if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE): | |
381 | self.nCode = int(numpy.fromfile(fp,'<u4',1)) |
|
384 | self.nCode = int(numpy.fromfile(fp,'<u4',1)) | |
382 | self.nBaud = int(numpy.fromfile(fp,'<u4',1)) |
|
385 | self.nBaud = int(numpy.fromfile(fp,'<u4',1)) | |
383 | self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nBaud,self.nCode) |
|
386 | self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nBaud,self.nCode) | |
384 |
|
387 | |||
385 | if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA): |
|
388 | if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA): | |
386 | self.shif_fft = True |
|
389 | self.shif_fft = True | |
387 | else: |
|
390 | else: | |
388 | self.shif_fft = False |
|
391 | self.shif_fft = False | |
389 |
|
392 | |||
390 | if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC): |
|
393 | if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC): | |
391 | self.flag_dc = True |
|
394 | self.flag_dc = True | |
392 |
|
395 | |||
393 | nChannels = 0 |
|
396 | nChannels = 0 | |
394 | nPairs = 0 |
|
397 | nPairs = 0 | |
395 | pairList = [] |
|
398 | pairList = [] | |
396 |
|
399 | |||
397 | for i in range( 0, self.totalSpectra*2, 2 ): |
|
400 | for i in range( 0, self.totalSpectra*2, 2 ): | |
398 | if self.spectraComb[i] == self.spectraComb[i+1]: |
|
401 | if self.spectraComb[i] == self.spectraComb[i+1]: | |
399 | nChannels = nChannels + 1 #par de canales iguales |
|
402 | nChannels = nChannels + 1 #par de canales iguales | |
400 | else: |
|
403 | else: | |
401 | nPairs = nPairs + 1 #par de canales diferentes |
|
404 | nPairs = nPairs + 1 #par de canales diferentes | |
402 | pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) ) |
|
405 | pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) ) | |
403 |
|
406 | |||
404 | self.flag_cspc = False |
|
407 | self.flag_cspc = False | |
405 | if nPairs > 0: |
|
408 | if nPairs > 0: | |
406 | self.flag_cspc = True |
|
409 | self.flag_cspc = True | |
407 |
|
410 | |||
408 | except Exception, e: |
|
411 | except Exception, e: | |
409 | print "ProcessingHeader: " + e |
|
412 | print "ProcessingHeader: " + e | |
410 | return 0 |
|
413 | return 0 | |
411 |
|
414 | |||
412 | return 1 |
|
415 | return 1 | |
413 |
|
416 | |||
414 | def write(self, fp): |
|
417 | def write(self, fp): | |
415 | headerTuple = (self.size, |
|
418 | headerTuple = (self.size, | |
416 | self.dtype, |
|
419 | self.dtype, | |
417 | self.blockSize, |
|
420 | self.blockSize, | |
418 | self.profilesPerBlock, |
|
421 | self.profilesPerBlock, | |
419 | self.dataBlocksPerFile, |
|
422 | self.dataBlocksPerFile, | |
420 | self.nWindows, |
|
423 | self.nWindows, | |
421 | self.processFlags, |
|
424 | self.processFlags, | |
422 | self.nCohInt, |
|
425 | self.nCohInt, | |
423 | self.nIncohInt, |
|
426 | self.nIncohInt, | |
424 | self.totalSpectra) |
|
427 | self.totalSpectra) | |
425 |
|
428 | |||
426 | header = numpy.array(headerTuple,self.struct) |
|
429 | header = numpy.array(headerTuple,self.struct) | |
427 | header.tofile(fp) |
|
430 | header.tofile(fp) | |
428 |
|
431 | |||
429 | if self.nWindows != 0: |
|
432 | if self.nWindows != 0: | |
430 | sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin) |
|
433 | sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin) | |
431 | samplingWindow = numpy.array(sampleWindowTuple,self.structSamplingWindow) |
|
434 | samplingWindow = numpy.array(sampleWindowTuple,self.structSamplingWindow) | |
432 | samplingWindow.tofile(fp) |
|
435 | samplingWindow.tofile(fp) | |
433 |
|
436 | |||
434 |
|
437 | |||
435 | if self.totalSpectra != 0: |
|
438 | if self.totalSpectra != 0: | |
436 | spectraComb = numpy.array([],numpy.dtype('u1')) |
|
439 | spectraComb = numpy.array([],numpy.dtype('u1')) | |
437 | spectraComb = self.spectraComb |
|
440 | spectraComb = self.spectraComb | |
438 | spectraComb.tofile(fp) |
|
441 | spectraComb.tofile(fp) | |
439 |
|
442 | |||
440 |
|
443 | |||
441 | if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE: |
|
444 | if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE: | |
442 | nCode = self.nCode #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba |
|
445 | nCode = self.nCode #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba | |
443 | nCode.tofile(fp) |
|
446 | nCode.tofile(fp) | |
444 |
|
447 | |||
445 | nBaud = self.nBaud |
|
448 | nBaud = self.nBaud | |
446 | nBaud.tofile(fp) |
|
449 | nBaud.tofile(fp) | |
447 |
|
450 | |||
448 | code = self.code.reshape(nCode*nBaud) |
|
451 | code = self.code.reshape(nCode*nBaud) | |
449 | code.tofile(fp) |
|
452 | code.tofile(fp) | |
450 |
|
453 | |||
451 | return 1 |
|
454 | return 1 | |
452 |
|
455 | |||
453 | class RCfunction: |
|
456 | class RCfunction: | |
454 | NONE=0 |
|
457 | NONE=0 | |
455 | FLIP=1 |
|
458 | FLIP=1 | |
456 | CODE=2 |
|
459 | CODE=2 | |
457 | SAMPLING=3 |
|
460 | SAMPLING=3 | |
458 | LIN6DIV256=4 |
|
461 | LIN6DIV256=4 | |
459 | SYNCHRO=5 |
|
462 | SYNCHRO=5 | |
460 |
|
463 | |||
461 | class nCodeType: |
|
464 | class nCodeType: | |
462 | NONE=0 |
|
465 | NONE=0 | |
463 | USERDEFINE=1 |
|
466 | USERDEFINE=1 | |
464 | BARKER2=2 |
|
467 | BARKER2=2 | |
465 | BARKER3=3 |
|
468 | BARKER3=3 | |
466 | BARKER4=4 |
|
469 | BARKER4=4 | |
467 | BARKER5=5 |
|
470 | BARKER5=5 | |
468 | BARKER7=6 |
|
471 | BARKER7=6 | |
469 | BARKER11=7 |
|
472 | BARKER11=7 | |
470 | BARKER13=8 |
|
473 | BARKER13=8 | |
471 | AC128=9 |
|
474 | AC128=9 | |
472 | COMPLEMENTARYCODE2=10 |
|
475 | COMPLEMENTARYCODE2=10 | |
473 | COMPLEMENTARYCODE4=11 |
|
476 | COMPLEMENTARYCODE4=11 | |
474 | COMPLEMENTARYCODE8=12 |
|
477 | COMPLEMENTARYCODE8=12 | |
475 | COMPLEMENTARYCODE16=13 |
|
478 | COMPLEMENTARYCODE16=13 | |
476 | COMPLEMENTARYCODE32=14 |
|
479 | COMPLEMENTARYCODE32=14 | |
477 | COMPLEMENTARYCODE64=15 |
|
480 | COMPLEMENTARYCODE64=15 | |
478 | COMPLEMENTARYCODE128=16 |
|
481 | COMPLEMENTARYCODE128=16 | |
479 | CODE_BINARY28=17 |
|
482 | CODE_BINARY28=17 | |
480 |
|
483 | |||
481 | class PROCFLAG: |
|
484 | class PROCFLAG: | |
482 | COHERENT_INTEGRATION = numpy.uint32(0x00000001) |
|
485 | COHERENT_INTEGRATION = numpy.uint32(0x00000001) | |
483 | DECODE_DATA = numpy.uint32(0x00000002) |
|
486 | DECODE_DATA = numpy.uint32(0x00000002) | |
484 | SPECTRA_CALC = numpy.uint32(0x00000004) |
|
487 | SPECTRA_CALC = numpy.uint32(0x00000004) | |
485 | INCOHERENT_INTEGRATION = numpy.uint32(0x00000008) |
|
488 | INCOHERENT_INTEGRATION = numpy.uint32(0x00000008) | |
486 | POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010) |
|
489 | POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010) | |
487 | SHIFT_FFT_DATA = numpy.uint32(0x00000020) |
|
490 | SHIFT_FFT_DATA = numpy.uint32(0x00000020) | |
488 |
|
491 | |||
489 | DATATYPE_CHAR = numpy.uint32(0x00000040) |
|
492 | DATATYPE_CHAR = numpy.uint32(0x00000040) | |
490 | DATATYPE_SHORT = numpy.uint32(0x00000080) |
|
493 | DATATYPE_SHORT = numpy.uint32(0x00000080) | |
491 | DATATYPE_LONG = numpy.uint32(0x00000100) |
|
494 | DATATYPE_LONG = numpy.uint32(0x00000100) | |
492 | DATATYPE_INT64 = numpy.uint32(0x00000200) |
|
495 | DATATYPE_INT64 = numpy.uint32(0x00000200) | |
493 | DATATYPE_FLOAT = numpy.uint32(0x00000400) |
|
496 | DATATYPE_FLOAT = numpy.uint32(0x00000400) | |
494 | DATATYPE_DOUBLE = numpy.uint32(0x00000800) |
|
497 | DATATYPE_DOUBLE = numpy.uint32(0x00000800) | |
495 |
|
498 | |||
496 | DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000) |
|
499 | DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000) | |
497 | DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000) |
|
500 | DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000) | |
498 | DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000) |
|
501 | DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000) | |
499 |
|
502 | |||
500 | SAVE_CHANNELS_DC = numpy.uint32(0x00008000) |
|
503 | SAVE_CHANNELS_DC = numpy.uint32(0x00008000) | |
501 | DEFLIP_DATA = numpy.uint32(0x00010000) |
|
504 | DEFLIP_DATA = numpy.uint32(0x00010000) | |
502 | DEFINE_PROCESS_CODE = numpy.uint32(0x00020000) |
|
505 | DEFINE_PROCESS_CODE = numpy.uint32(0x00020000) | |
503 |
|
506 | |||
504 | ACQ_SYS_NATALIA = numpy.uint32(0x00040000) |
|
507 | ACQ_SYS_NATALIA = numpy.uint32(0x00040000) | |
505 | ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000) |
|
508 | ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000) | |
506 | ACQ_SYS_ADRXD = numpy.uint32(0x000C0000) |
|
509 | ACQ_SYS_ADRXD = numpy.uint32(0x000C0000) | |
507 | ACQ_SYS_JULIA = numpy.uint32(0x00100000) |
|
510 | ACQ_SYS_JULIA = numpy.uint32(0x00100000) | |
508 | ACQ_SYS_XXXXXX = numpy.uint32(0x00140000) |
|
511 | ACQ_SYS_XXXXXX = numpy.uint32(0x00140000) | |
509 |
|
512 | |||
510 | EXP_NAME_ESP = numpy.uint32(0x00200000) |
|
513 | EXP_NAME_ESP = numpy.uint32(0x00200000) | |
511 | CHANNEL_NAMES_ESP = numpy.uint32(0x00400000) |
|
514 | CHANNEL_NAMES_ESP = numpy.uint32(0x00400000) | |
512 |
|
515 | |||
513 | OPERATION_MASK = numpy.uint32(0x0000003F) |
|
516 | OPERATION_MASK = numpy.uint32(0x0000003F) | |
514 | DATATYPE_MASK = numpy.uint32(0x00000FC0) |
|
517 | DATATYPE_MASK = numpy.uint32(0x00000FC0) | |
515 | DATAARRANGE_MASK = numpy.uint32(0x00007000) |
|
518 | DATAARRANGE_MASK = numpy.uint32(0x00007000) | |
516 | ACQ_SYS_MASK = numpy.uint32(0x001C0000) No newline at end of file |
|
519 | ACQ_SYS_MASK = numpy.uint32(0x001C0000) |
@@ -1,586 +1,589 | |||||
1 | import numpy |
|
1 | import numpy | |
2 | import time, datetime |
|
2 | import time, datetime | |
3 | from graphics.figure import * |
|
3 | from graphics.figure import * | |
4 |
|
4 | |||
5 | class CrossSpectraPlot(Figure): |
|
5 | class CrossSpectraPlot(Figure): | |
6 |
|
6 | |||
7 | __isConfig = None |
|
7 | __isConfig = None | |
8 | __nsubplots = None |
|
8 | __nsubplots = None | |
9 |
|
9 | |||
10 | WIDTHPROF = None |
|
10 | WIDTHPROF = None | |
11 | HEIGHTPROF = None |
|
11 | HEIGHTPROF = None | |
12 | PREFIX = 'spc' |
|
12 | PREFIX = 'spc' | |
13 |
|
13 | |||
14 | def __init__(self): |
|
14 | def __init__(self): | |
15 |
|
15 | |||
16 | self.__isConfig = False |
|
16 | self.__isConfig = False | |
17 | self.__nsubplots = 4 |
|
17 | self.__nsubplots = 4 | |
18 |
|
18 | |||
19 | self.WIDTH = 300 |
|
19 | self.WIDTH = 300 | |
20 | self.HEIGHT = 400 |
|
20 | self.HEIGHT = 400 | |
21 | self.WIDTHPROF = 0 |
|
21 | self.WIDTHPROF = 0 | |
22 | self.HEIGHTPROF = 0 |
|
22 | self.HEIGHTPROF = 0 | |
23 |
|
23 | |||
24 | def getSubplots(self): |
|
24 | def getSubplots(self): | |
25 |
|
25 | |||
26 | ncol = 4 |
|
26 | ncol = 4 | |
27 | nrow = self.nplots |
|
27 | nrow = self.nplots | |
28 |
|
28 | |||
29 | return nrow, ncol |
|
29 | return nrow, ncol | |
30 |
|
30 | |||
31 | def setup(self, idfigure, nplots, wintitle, showprofile=True): |
|
31 | def setup(self, idfigure, nplots, wintitle, showprofile=True): | |
32 |
|
32 | |||
33 | self.__showprofile = showprofile |
|
33 | self.__showprofile = showprofile | |
34 | self.nplots = nplots |
|
34 | self.nplots = nplots | |
35 |
|
35 | |||
36 | ncolspan = 1 |
|
36 | ncolspan = 1 | |
37 | colspan = 1 |
|
37 | colspan = 1 | |
38 |
|
38 | |||
39 | self.createFigure(idfigure = idfigure, |
|
39 | self.createFigure(idfigure = idfigure, | |
40 | wintitle = wintitle, |
|
40 | wintitle = wintitle, | |
41 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
41 | widthplot = self.WIDTH + self.WIDTHPROF, | |
42 | heightplot = self.HEIGHT + self.HEIGHTPROF) |
|
42 | heightplot = self.HEIGHT + self.HEIGHTPROF) | |
43 |
|
43 | |||
44 | nrow, ncol = self.getSubplots() |
|
44 | nrow, ncol = self.getSubplots() | |
45 |
|
45 | |||
46 | counter = 0 |
|
46 | counter = 0 | |
47 | for y in range(nrow): |
|
47 | for y in range(nrow): | |
48 | for x in range(ncol): |
|
48 | for x in range(ncol): | |
49 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
49 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
50 |
|
50 | |||
51 | counter += 1 |
|
51 | counter += 1 | |
52 |
|
52 | |||
53 | def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True', |
|
53 | def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True', | |
54 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
54 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
55 | save=False, figpath='./', figfile=None): |
|
55 | save=False, figpath='./', figfile=None): | |
56 |
|
56 | |||
57 | """ |
|
57 | """ | |
58 |
|
58 | |||
59 | Input: |
|
59 | Input: | |
60 | dataOut : |
|
60 | dataOut : | |
61 | idfigure : |
|
61 | idfigure : | |
62 | wintitle : |
|
62 | wintitle : | |
63 | channelList : |
|
63 | channelList : | |
64 | showProfile : |
|
64 | showProfile : | |
65 | xmin : None, |
|
65 | xmin : None, | |
66 | xmax : None, |
|
66 | xmax : None, | |
67 | ymin : None, |
|
67 | ymin : None, | |
68 | ymax : None, |
|
68 | ymax : None, | |
69 | zmin : None, |
|
69 | zmin : None, | |
70 | zmax : None |
|
70 | zmax : None | |
71 | """ |
|
71 | """ | |
72 |
|
72 | |||
73 | if pairsList == None: |
|
73 | if pairsList == None: | |
74 | pairsIndexList = dataOut.pairsIndexList |
|
74 | pairsIndexList = dataOut.pairsIndexList | |
75 | else: |
|
75 | else: | |
76 | pairsIndexList = [] |
|
76 | pairsIndexList = [] | |
77 | for pair in pairsList: |
|
77 | for pair in pairsList: | |
78 | if pair not in dataOut.pairsList: |
|
78 | if pair not in dataOut.pairsList: | |
79 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
79 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) | |
80 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
80 | pairsIndexList.append(dataOut.pairsList.index(pair)) | |
81 |
|
81 | |||
|
82 | if pairIndexList == []: | |||
|
83 | return | |||
|
84 | ||||
82 | x = dataOut.getVelRange(1) |
|
85 | x = dataOut.getVelRange(1) | |
83 | y = dataOut.getHeiRange() |
|
86 | y = dataOut.getHeiRange() | |
84 | z = 10.*numpy.log10(dataOut.data_spc[:,:,:]) |
|
87 | z = 10.*numpy.log10(dataOut.data_spc[:,:,:]) | |
85 | avg = numpy.average(numpy.abs(z), axis=1) |
|
88 | avg = numpy.average(numpy.abs(z), axis=1) | |
86 |
|
89 | |||
87 | noise = dataOut.getNoise() |
|
90 | noise = dataOut.getNoise() | |
88 |
|
91 | |||
89 | if not self.__isConfig: |
|
92 | if not self.__isConfig: | |
90 |
|
93 | |||
91 | nplots = len(pairsIndexList) |
|
94 | nplots = len(pairsIndexList) | |
92 |
|
95 | |||
93 | self.setup(idfigure=idfigure, |
|
96 | self.setup(idfigure=idfigure, | |
94 | nplots=nplots, |
|
97 | nplots=nplots, | |
95 | wintitle=wintitle, |
|
98 | wintitle=wintitle, | |
96 | showprofile=showprofile) |
|
99 | showprofile=showprofile) | |
97 |
|
100 | |||
98 | if xmin == None: xmin = numpy.nanmin(x) |
|
101 | if xmin == None: xmin = numpy.nanmin(x) | |
99 | if xmax == None: xmax = numpy.nanmax(x) |
|
102 | if xmax == None: xmax = numpy.nanmax(x) | |
100 | if ymin == None: ymin = numpy.nanmin(y) |
|
103 | if ymin == None: ymin = numpy.nanmin(y) | |
101 | if ymax == None: ymax = numpy.nanmax(y) |
|
104 | if ymax == None: ymax = numpy.nanmax(y) | |
102 | if zmin == None: zmin = numpy.nanmin(avg)*0.9 |
|
105 | if zmin == None: zmin = numpy.nanmin(avg)*0.9 | |
103 | if zmax == None: zmax = numpy.nanmax(avg)*0.9 |
|
106 | if zmax == None: zmax = numpy.nanmax(avg)*0.9 | |
104 |
|
107 | |||
105 | self.__isConfig = True |
|
108 | self.__isConfig = True | |
106 |
|
109 | |||
107 |
thisDatetime = |
|
110 | thisDatetime = dataOut.datatime | |
108 | title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
111 | title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
109 | xlabel = "Velocity (m/s)" |
|
112 | xlabel = "Velocity (m/s)" | |
110 | ylabel = "Range (Km)" |
|
113 | ylabel = "Range (Km)" | |
111 |
|
114 | |||
112 | self.setWinTitle(title) |
|
115 | self.setWinTitle(title) | |
113 |
|
116 | |||
114 | for i in range(self.nplots): |
|
117 | for i in range(self.nplots): | |
115 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
118 | pair = dataOut.pairsList[pairsIndexList[i]] | |
116 |
|
119 | |||
117 | title = "Channel %d: %4.2fdB" %(pair[0], noise[pair[0]]) |
|
120 | title = "Channel %d: %4.2fdB" %(pair[0], noise[pair[0]]) | |
118 | z = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]) |
|
121 | z = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]) | |
119 | axes0 = self.axesList[i*self.__nsubplots] |
|
122 | axes0 = self.axesList[i*self.__nsubplots] | |
120 | axes0.pcolor(x, y, z, |
|
123 | axes0.pcolor(x, y, z, | |
121 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
124 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
122 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
125 | xlabel=xlabel, ylabel=ylabel, title=title, | |
123 | ticksize=9, cblabel='') |
|
126 | ticksize=9, cblabel='') | |
124 |
|
127 | |||
125 | title = "Channel %d: %4.2fdB" %(pair[1], noise[pair[1]]) |
|
128 | title = "Channel %d: %4.2fdB" %(pair[1], noise[pair[1]]) | |
126 | z = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]) |
|
129 | z = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]) | |
127 | axes0 = self.axesList[i*self.__nsubplots+1] |
|
130 | axes0 = self.axesList[i*self.__nsubplots+1] | |
128 | axes0.pcolor(x, y, z, |
|
131 | axes0.pcolor(x, y, z, | |
129 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
132 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
130 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
133 | xlabel=xlabel, ylabel=ylabel, title=title, | |
131 | ticksize=9, cblabel='') |
|
134 | ticksize=9, cblabel='') | |
132 |
|
135 | |||
133 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) |
|
136 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) | |
134 | coherence = numpy.abs(coherenceComplex) |
|
137 | coherence = numpy.abs(coherenceComplex) | |
135 | phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi |
|
138 | phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi | |
136 |
|
139 | |||
137 |
|
140 | |||
138 | title = "Coherence %d%d" %(pair[0], pair[1]) |
|
141 | title = "Coherence %d%d" %(pair[0], pair[1]) | |
139 | axes0 = self.axesList[i*self.__nsubplots+2] |
|
142 | axes0 = self.axesList[i*self.__nsubplots+2] | |
140 | axes0.pcolor(x, y, coherence, |
|
143 | axes0.pcolor(x, y, coherence, | |
141 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-1, zmax=1, |
|
144 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-1, zmax=1, | |
142 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
145 | xlabel=xlabel, ylabel=ylabel, title=title, | |
143 | ticksize=9, cblabel='') |
|
146 | ticksize=9, cblabel='') | |
144 |
|
147 | |||
145 | title = "Phase %d%d" %(pair[0], pair[1]) |
|
148 | title = "Phase %d%d" %(pair[0], pair[1]) | |
146 | axes0 = self.axesList[i*self.__nsubplots+3] |
|
149 | axes0 = self.axesList[i*self.__nsubplots+3] | |
147 | axes0.pcolor(x, y, phase, |
|
150 | axes0.pcolor(x, y, phase, | |
148 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, |
|
151 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, | |
149 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
152 | xlabel=xlabel, ylabel=ylabel, title=title, | |
150 | ticksize=9, cblabel='') |
|
153 | ticksize=9, cblabel='') | |
151 |
|
154 | |||
152 |
|
155 | |||
153 |
|
156 | |||
154 | self.draw() |
|
157 | self.draw() | |
155 |
|
158 | |||
156 | if save: |
|
159 | if save: | |
157 | date = thisDatetime.strftime("%Y%m%d") |
|
160 | date = thisDatetime.strftime("%Y%m%d") | |
158 | if figfile == None: |
|
161 | if figfile == None: | |
159 | figfile = self.getFilename(name = date) |
|
162 | figfile = self.getFilename(name = date) | |
160 |
|
163 | |||
161 | self.saveFigure(figpath, figfile) |
|
164 | self.saveFigure(figpath, figfile) | |
162 |
|
165 | |||
163 |
|
166 | |||
164 | class RTIPlot(Figure): |
|
167 | class RTIPlot(Figure): | |
165 |
|
168 | |||
166 | __isConfig = None |
|
169 | __isConfig = None | |
167 | __nsubplots = None |
|
170 | __nsubplots = None | |
168 |
|
171 | |||
169 | WIDTHPROF = None |
|
172 | WIDTHPROF = None | |
170 | HEIGHTPROF = None |
|
173 | HEIGHTPROF = None | |
171 | PREFIX = 'rti' |
|
174 | PREFIX = 'rti' | |
172 |
|
175 | |||
173 | def __init__(self): |
|
176 | def __init__(self): | |
174 |
|
177 | |||
175 | self.__timerange = 24*60*60 |
|
178 | self.__timerange = 24*60*60 | |
176 | self.__isConfig = False |
|
179 | self.__isConfig = False | |
177 | self.__nsubplots = 1 |
|
180 | self.__nsubplots = 1 | |
178 |
|
181 | |||
179 | self.WIDTH = 800 |
|
182 | self.WIDTH = 800 | |
180 | self.HEIGHT = 200 |
|
183 | self.HEIGHT = 200 | |
181 | self.WIDTHPROF = 120 |
|
184 | self.WIDTHPROF = 120 | |
182 | self.HEIGHTPROF = 0 |
|
185 | self.HEIGHTPROF = 0 | |
183 |
|
186 | |||
184 | def getSubplots(self): |
|
187 | def getSubplots(self): | |
185 |
|
188 | |||
186 | ncol = 1 |
|
189 | ncol = 1 | |
187 | nrow = self.nplots |
|
190 | nrow = self.nplots | |
188 |
|
191 | |||
189 | return nrow, ncol |
|
192 | return nrow, ncol | |
190 |
|
193 | |||
191 | def setup(self, idfigure, nplots, wintitle, showprofile=True): |
|
194 | def setup(self, idfigure, nplots, wintitle, showprofile=True): | |
192 |
|
195 | |||
193 | self.__showprofile = showprofile |
|
196 | self.__showprofile = showprofile | |
194 | self.nplots = nplots |
|
197 | self.nplots = nplots | |
195 |
|
198 | |||
196 | ncolspan = 1 |
|
199 | ncolspan = 1 | |
197 | colspan = 1 |
|
200 | colspan = 1 | |
198 | if showprofile: |
|
201 | if showprofile: | |
199 | ncolspan = 7 |
|
202 | ncolspan = 7 | |
200 | colspan = 6 |
|
203 | colspan = 6 | |
201 | self.__nsubplots = 2 |
|
204 | self.__nsubplots = 2 | |
202 |
|
205 | |||
203 | self.createFigure(idfigure = idfigure, |
|
206 | self.createFigure(idfigure = idfigure, | |
204 | wintitle = wintitle, |
|
207 | wintitle = wintitle, | |
205 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
208 | widthplot = self.WIDTH + self.WIDTHPROF, | |
206 | heightplot = self.HEIGHT + self.HEIGHTPROF) |
|
209 | heightplot = self.HEIGHT + self.HEIGHTPROF) | |
207 |
|
210 | |||
208 | nrow, ncol = self.getSubplots() |
|
211 | nrow, ncol = self.getSubplots() | |
209 |
|
212 | |||
210 | counter = 0 |
|
213 | counter = 0 | |
211 | for y in range(nrow): |
|
214 | for y in range(nrow): | |
212 | for x in range(ncol): |
|
215 | for x in range(ncol): | |
213 |
|
216 | |||
214 | if counter >= self.nplots: |
|
217 | if counter >= self.nplots: | |
215 | break |
|
218 | break | |
216 |
|
219 | |||
217 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
220 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
218 |
|
221 | |||
219 | if showprofile: |
|
222 | if showprofile: | |
220 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
223 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
221 |
|
224 | |||
222 | counter += 1 |
|
225 | counter += 1 | |
223 |
|
226 | |||
224 | def __getTimeLim(self, x, xmin, xmax): |
|
227 | def __getTimeLim(self, x, xmin, xmax): | |
225 |
|
228 | |||
226 | thisdatetime = datetime.datetime.fromtimestamp(numpy.min(x)) |
|
229 | thisdatetime = datetime.datetime.utcfromtimestamp(numpy.min(x)) | |
227 | thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0)) |
|
230 | thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0)) | |
228 |
|
231 | |||
229 | #################################################### |
|
232 | #################################################### | |
230 | #If the x is out of xrange |
|
233 | #If the x is out of xrange | |
231 | if xmax < (thisdatetime - thisdate).seconds/(60*60.): |
|
234 | if xmax < (thisdatetime - thisdate).seconds/(60*60.): | |
232 | xmin = None |
|
235 | xmin = None | |
233 | xmax = None |
|
236 | xmax = None | |
234 |
|
237 | |||
235 | if xmin == None: |
|
238 | if xmin == None: | |
236 | td = thisdatetime - thisdate |
|
239 | td = thisdatetime - thisdate | |
237 | xmin = td.seconds/(60*60.) |
|
240 | xmin = td.seconds/(60*60.) | |
238 |
|
241 | |||
239 | if xmax == None: |
|
242 | if xmax == None: | |
240 | xmax = xmin + self.__timerange/(60*60.) |
|
243 | xmax = xmin + self.__timerange/(60*60.) | |
241 |
|
244 | |||
242 | mindt = thisdate + datetime.timedelta(0,0,0,0,0, xmin) |
|
245 | mindt = thisdate + datetime.timedelta(0,0,0,0,0, xmin) | |
243 | tmin = time.mktime(mindt.timetuple()) |
|
246 | tmin = time.mktime(mindt.timetuple()) | |
244 |
|
247 | |||
245 | maxdt = thisdate + datetime.timedelta(0,0,0,0,0, xmax) |
|
248 | maxdt = thisdate + datetime.timedelta(0,0,0,0,0, xmax) | |
246 | tmax = time.mktime(maxdt.timetuple()) |
|
249 | tmax = time.mktime(maxdt.timetuple()) | |
247 |
|
250 | |||
248 | self.__timerange = tmax - tmin |
|
251 | self.__timerange = tmax - tmin | |
249 |
|
252 | |||
250 | return tmin, tmax |
|
253 | return tmin, tmax | |
251 |
|
254 | |||
252 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
255 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', | |
253 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
256 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
254 | timerange=None, |
|
257 | timerange=None, | |
255 | save=False, figpath='./', figfile=None): |
|
258 | save=False, figpath='./', figfile=None): | |
256 |
|
259 | |||
257 | """ |
|
260 | """ | |
258 |
|
261 | |||
259 | Input: |
|
262 | Input: | |
260 | dataOut : |
|
263 | dataOut : | |
261 | idfigure : |
|
264 | idfigure : | |
262 | wintitle : |
|
265 | wintitle : | |
263 | channelList : |
|
266 | channelList : | |
264 | showProfile : |
|
267 | showProfile : | |
265 | xmin : None, |
|
268 | xmin : None, | |
266 | xmax : None, |
|
269 | xmax : None, | |
267 | ymin : None, |
|
270 | ymin : None, | |
268 | ymax : None, |
|
271 | ymax : None, | |
269 | zmin : None, |
|
272 | zmin : None, | |
270 | zmax : None |
|
273 | zmax : None | |
271 | """ |
|
274 | """ | |
272 |
|
275 | |||
273 | if channelList == None: |
|
276 | if channelList == None: | |
274 | channelIndexList = dataOut.channelIndexList |
|
277 | channelIndexList = dataOut.channelIndexList | |
275 | else: |
|
278 | else: | |
276 | channelIndexList = [] |
|
279 | channelIndexList = [] | |
277 | for channel in channelList: |
|
280 | for channel in channelList: | |
278 | if channel not in dataOut.channelList: |
|
281 | if channel not in dataOut.channelList: | |
279 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
282 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
280 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
283 | channelIndexList.append(dataOut.channelList.index(channel)) | |
281 |
|
284 | |||
282 | if timerange != None: |
|
285 | if timerange != None: | |
283 | self.__timerange = timerange |
|
286 | self.__timerange = timerange | |
284 |
|
287 | |||
285 | tmin = None |
|
288 | tmin = None | |
286 | tmax = None |
|
289 | tmax = None | |
287 |
x = dataOut.get |
|
290 | x = dataOut.getTimeRange() | |
288 | y = dataOut.getHeiRange() |
|
291 | y = dataOut.getHeiRange() | |
289 | z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:]) |
|
292 | z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:]) | |
290 | avg = numpy.average(z, axis=1) |
|
293 | avg = numpy.average(z, axis=1) | |
291 |
|
294 | |||
292 | noise = dataOut.getNoise() |
|
295 | noise = dataOut.getNoise() | |
293 |
|
296 | |||
294 | if not self.__isConfig: |
|
297 | if not self.__isConfig: | |
295 |
|
298 | |||
296 | nplots = len(channelIndexList) |
|
299 | nplots = len(channelIndexList) | |
297 |
|
300 | |||
298 | self.setup(idfigure=idfigure, |
|
301 | self.setup(idfigure=idfigure, | |
299 | nplots=nplots, |
|
302 | nplots=nplots, | |
300 | wintitle=wintitle, |
|
303 | wintitle=wintitle, | |
301 | showprofile=showprofile) |
|
304 | showprofile=showprofile) | |
302 |
|
305 | |||
303 | tmin, tmax = self.__getTimeLim(x, xmin, xmax) |
|
306 | tmin, tmax = self.__getTimeLim(x, xmin, xmax) | |
304 | if ymin == None: ymin = numpy.nanmin(y) |
|
307 | if ymin == None: ymin = numpy.nanmin(y) | |
305 | if ymax == None: ymax = numpy.nanmax(y) |
|
308 | if ymax == None: ymax = numpy.nanmax(y) | |
306 | if zmin == None: zmin = numpy.nanmin(avg)*0.9 |
|
309 | if zmin == None: zmin = numpy.nanmin(avg)*0.9 | |
307 | if zmax == None: zmax = numpy.nanmax(avg)*0.9 |
|
310 | if zmax == None: zmax = numpy.nanmax(avg)*0.9 | |
308 |
|
311 | |||
309 | self.__isConfig = True |
|
312 | self.__isConfig = True | |
310 |
|
313 | |||
311 |
thisDatetime = |
|
314 | thisDatetime = dataOut.datatime | |
312 | title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
315 | title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
313 | xlabel = "Velocity (m/s)" |
|
316 | xlabel = "Velocity (m/s)" | |
314 | ylabel = "Range (Km)" |
|
317 | ylabel = "Range (Km)" | |
315 |
|
318 | |||
316 | self.setWinTitle(title) |
|
319 | self.setWinTitle(title) | |
317 |
|
320 | |||
318 | for i in range(self.nplots): |
|
321 | for i in range(self.nplots): | |
319 | title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
322 | title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
320 | axes = self.axesList[i*self.__nsubplots] |
|
323 | axes = self.axesList[i*self.__nsubplots] | |
321 | z = avg[i].reshape((1,-1)) |
|
324 | z = avg[i].reshape((1,-1)) | |
322 | axes.pcolor(x, y, z, |
|
325 | axes.pcolor(x, y, z, | |
323 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
326 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
324 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
327 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
325 | ticksize=9, cblabel='', cbsize="1%") |
|
328 | ticksize=9, cblabel='', cbsize="1%") | |
326 |
|
329 | |||
327 | if self.__showprofile: |
|
330 | if self.__showprofile: | |
328 | axes = self.axesList[i*self.__nsubplots +1] |
|
331 | axes = self.axesList[i*self.__nsubplots +1] | |
329 | axes.pline(avg[i], y, |
|
332 | axes.pline(avg[i], y, | |
330 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
333 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |
331 | xlabel='dB', ylabel='', title='', |
|
334 | xlabel='dB', ylabel='', title='', | |
332 | ytick_visible=False, |
|
335 | ytick_visible=False, | |
333 | grid='x') |
|
336 | grid='x') | |
334 |
|
337 | |||
335 | self.draw() |
|
338 | self.draw() | |
336 |
|
339 | |||
337 | if save: |
|
340 | if save: | |
338 | date = thisDatetime.strftime("%Y%m%d") |
|
341 | date = thisDatetime.strftime("%Y%m%d") | |
339 | if figfile == None: |
|
342 | if figfile == None: | |
340 | figfile = self.getFilename(name = date) |
|
343 | figfile = self.getFilename(name = date) | |
341 |
|
344 | |||
342 | self.saveFigure(figpath, figfile) |
|
345 | self.saveFigure(figpath, figfile) | |
343 |
|
346 | |||
344 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
347 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: | |
345 | self.__isConfig = False |
|
348 | self.__isConfig = False | |
346 |
|
349 | |||
347 | class SpectraPlot(Figure): |
|
350 | class SpectraPlot(Figure): | |
348 |
|
351 | |||
349 | __isConfig = None |
|
352 | __isConfig = None | |
350 | __nsubplots = None |
|
353 | __nsubplots = None | |
351 |
|
354 | |||
352 | WIDTHPROF = None |
|
355 | WIDTHPROF = None | |
353 | HEIGHTPROF = None |
|
356 | HEIGHTPROF = None | |
354 | PREFIX = 'spc' |
|
357 | PREFIX = 'spc' | |
355 |
|
358 | |||
356 | def __init__(self): |
|
359 | def __init__(self): | |
357 |
|
360 | |||
358 | self.__isConfig = False |
|
361 | self.__isConfig = False | |
359 | self.__nsubplots = 1 |
|
362 | self.__nsubplots = 1 | |
360 |
|
363 | |||
361 | self.WIDTH = 300 |
|
364 | self.WIDTH = 300 | |
362 | self.HEIGHT = 400 |
|
365 | self.HEIGHT = 400 | |
363 | self.WIDTHPROF = 120 |
|
366 | self.WIDTHPROF = 120 | |
364 | self.HEIGHTPROF = 0 |
|
367 | self.HEIGHTPROF = 0 | |
365 |
|
368 | |||
366 | def getSubplots(self): |
|
369 | def getSubplots(self): | |
367 |
|
370 | |||
368 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
371 | ncol = int(numpy.sqrt(self.nplots)+0.9) | |
369 | nrow = int(self.nplots*1./ncol + 0.9) |
|
372 | nrow = int(self.nplots*1./ncol + 0.9) | |
370 |
|
373 | |||
371 | return nrow, ncol |
|
374 | return nrow, ncol | |
372 |
|
375 | |||
373 | def setup(self, idfigure, nplots, wintitle, showprofile=True): |
|
376 | def setup(self, idfigure, nplots, wintitle, showprofile=True): | |
374 |
|
377 | |||
375 | self.__showprofile = showprofile |
|
378 | self.__showprofile = showprofile | |
376 | self.nplots = nplots |
|
379 | self.nplots = nplots | |
377 |
|
380 | |||
378 | ncolspan = 1 |
|
381 | ncolspan = 1 | |
379 | colspan = 1 |
|
382 | colspan = 1 | |
380 | if showprofile: |
|
383 | if showprofile: | |
381 | ncolspan = 3 |
|
384 | ncolspan = 3 | |
382 | colspan = 2 |
|
385 | colspan = 2 | |
383 | self.__nsubplots = 2 |
|
386 | self.__nsubplots = 2 | |
384 |
|
387 | |||
385 | self.createFigure(idfigure = idfigure, |
|
388 | self.createFigure(idfigure = idfigure, | |
386 | wintitle = wintitle, |
|
389 | wintitle = wintitle, | |
387 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
390 | widthplot = self.WIDTH + self.WIDTHPROF, | |
388 | heightplot = self.HEIGHT + self.HEIGHTPROF) |
|
391 | heightplot = self.HEIGHT + self.HEIGHTPROF) | |
389 |
|
392 | |||
390 | nrow, ncol = self.getSubplots() |
|
393 | nrow, ncol = self.getSubplots() | |
391 |
|
394 | |||
392 | counter = 0 |
|
395 | counter = 0 | |
393 | for y in range(nrow): |
|
396 | for y in range(nrow): | |
394 | for x in range(ncol): |
|
397 | for x in range(ncol): | |
395 |
|
398 | |||
396 | if counter >= self.nplots: |
|
399 | if counter >= self.nplots: | |
397 | break |
|
400 | break | |
398 |
|
401 | |||
399 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
402 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
400 |
|
403 | |||
401 | if showprofile: |
|
404 | if showprofile: | |
402 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
405 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
403 |
|
406 | |||
404 | counter += 1 |
|
407 | counter += 1 | |
405 |
|
408 | |||
406 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
409 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', | |
407 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
410 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
408 | save=False, figpath='./', figfile=None): |
|
411 | save=False, figpath='./', figfile=None): | |
409 |
|
412 | |||
410 | """ |
|
413 | """ | |
411 |
|
414 | |||
412 | Input: |
|
415 | Input: | |
413 | dataOut : |
|
416 | dataOut : | |
414 | idfigure : |
|
417 | idfigure : | |
415 | wintitle : |
|
418 | wintitle : | |
416 | channelList : |
|
419 | channelList : | |
417 | showProfile : |
|
420 | showProfile : | |
418 | xmin : None, |
|
421 | xmin : None, | |
419 | xmax : None, |
|
422 | xmax : None, | |
420 | ymin : None, |
|
423 | ymin : None, | |
421 | ymax : None, |
|
424 | ymax : None, | |
422 | zmin : None, |
|
425 | zmin : None, | |
423 | zmax : None |
|
426 | zmax : None | |
424 | """ |
|
427 | """ | |
425 |
|
428 | |||
426 | if channelList == None: |
|
429 | if channelList == None: | |
427 | channelIndexList = dataOut.channelIndexList |
|
430 | channelIndexList = dataOut.channelIndexList | |
428 | else: |
|
431 | else: | |
429 | channelIndexList = [] |
|
432 | channelIndexList = [] | |
430 | for channel in channelList: |
|
433 | for channel in channelList: | |
431 | if channel not in dataOut.channelList: |
|
434 | if channel not in dataOut.channelList: | |
432 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
435 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
433 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
436 | channelIndexList.append(dataOut.channelList.index(channel)) | |
434 |
|
437 | |||
435 | x = dataOut.getVelRange(1) |
|
438 | x = dataOut.getVelRange(1) | |
436 | y = dataOut.getHeiRange() |
|
439 | y = dataOut.getHeiRange() | |
437 | z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:]) |
|
440 | z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:]) | |
438 | avg = numpy.average(z, axis=1) |
|
441 | avg = numpy.average(z, axis=1) | |
439 |
|
442 | |||
440 | noise = dataOut.getNoise() |
|
443 | noise = dataOut.getNoise() | |
441 |
|
444 | |||
442 | if not self.__isConfig: |
|
445 | if not self.__isConfig: | |
443 |
|
446 | |||
444 | nplots = len(channelIndexList) |
|
447 | nplots = len(channelIndexList) | |
445 |
|
448 | |||
446 | self.setup(idfigure=idfigure, |
|
449 | self.setup(idfigure=idfigure, | |
447 | nplots=nplots, |
|
450 | nplots=nplots, | |
448 | wintitle=wintitle, |
|
451 | wintitle=wintitle, | |
449 | showprofile=showprofile) |
|
452 | showprofile=showprofile) | |
450 |
|
453 | |||
451 | if xmin == None: xmin = numpy.nanmin(x) |
|
454 | if xmin == None: xmin = numpy.nanmin(x) | |
452 | if xmax == None: xmax = numpy.nanmax(x) |
|
455 | if xmax == None: xmax = numpy.nanmax(x) | |
453 | if ymin == None: ymin = numpy.nanmin(y) |
|
456 | if ymin == None: ymin = numpy.nanmin(y) | |
454 | if ymax == None: ymax = numpy.nanmax(y) |
|
457 | if ymax == None: ymax = numpy.nanmax(y) | |
455 | if zmin == None: zmin = numpy.nanmin(avg)*0.9 |
|
458 | if zmin == None: zmin = numpy.nanmin(avg)*0.9 | |
456 | if zmax == None: zmax = numpy.nanmax(avg)*0.9 |
|
459 | if zmax == None: zmax = numpy.nanmax(avg)*0.9 | |
457 |
|
460 | |||
458 | self.__isConfig = True |
|
461 | self.__isConfig = True | |
459 |
|
462 | |||
460 |
thisDatetime = |
|
463 | thisDatetime = dataOut.datatime | |
461 | title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
464 | title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
462 | xlabel = "Velocity (m/s)" |
|
465 | xlabel = "Velocity (m/s)" | |
463 | ylabel = "Range (Km)" |
|
466 | ylabel = "Range (Km)" | |
464 |
|
467 | |||
465 | self.setWinTitle(title) |
|
468 | self.setWinTitle(title) | |
466 |
|
469 | |||
467 | for i in range(self.nplots): |
|
470 | for i in range(self.nplots): | |
468 | title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noise[i]) |
|
471 | title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noise[i]) | |
469 | axes = self.axesList[i*self.__nsubplots] |
|
472 | axes = self.axesList[i*self.__nsubplots] | |
470 | axes.pcolor(x, y, z[i,:,:], |
|
473 | axes.pcolor(x, y, z[i,:,:], | |
471 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
474 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
472 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
475 | xlabel=xlabel, ylabel=ylabel, title=title, | |
473 | ticksize=9, cblabel='') |
|
476 | ticksize=9, cblabel='') | |
474 |
|
477 | |||
475 | if self.__showprofile: |
|
478 | if self.__showprofile: | |
476 | axes = self.axesList[i*self.__nsubplots +1] |
|
479 | axes = self.axesList[i*self.__nsubplots +1] | |
477 | axes.pline(avg[i], y, |
|
480 | axes.pline(avg[i], y, | |
478 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
481 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |
479 | xlabel='dB', ylabel='', title='', |
|
482 | xlabel='dB', ylabel='', title='', | |
480 | ytick_visible=False, |
|
483 | ytick_visible=False, | |
481 | grid='x') |
|
484 | grid='x') | |
482 |
|
485 | |||
483 | self.draw() |
|
486 | self.draw() | |
484 |
|
487 | |||
485 | if save: |
|
488 | if save: | |
486 | date = thisDatetime.strftime("%Y%m%d") |
|
489 | date = thisDatetime.strftime("%Y%m%d") | |
487 | if figfile == None: |
|
490 | if figfile == None: | |
488 | figfile = self.getFilename(name = date) |
|
491 | figfile = self.getFilename(name = date) | |
489 |
|
492 | |||
490 | self.saveFigure(figpath, figfile) |
|
493 | self.saveFigure(figpath, figfile) | |
491 |
|
494 | |||
492 | class Scope(Figure): |
|
495 | class Scope(Figure): | |
493 |
|
496 | |||
494 | __isConfig = None |
|
497 | __isConfig = None | |
495 |
|
498 | |||
496 | def __init__(self): |
|
499 | def __init__(self): | |
497 |
|
500 | |||
498 | self.__isConfig = False |
|
501 | self.__isConfig = False | |
499 | self.WIDTH = 600 |
|
502 | self.WIDTH = 600 | |
500 | self.HEIGHT = 200 |
|
503 | self.HEIGHT = 200 | |
501 |
|
504 | |||
502 | def getSubplots(self): |
|
505 | def getSubplots(self): | |
503 |
|
506 | |||
504 | nrow = self.nplots |
|
507 | nrow = self.nplots | |
505 | ncol = 3 |
|
508 | ncol = 3 | |
506 | return nrow, ncol |
|
509 | return nrow, ncol | |
507 |
|
510 | |||
508 | def setup(self, idfigure, nplots, wintitle): |
|
511 | def setup(self, idfigure, nplots, wintitle): | |
509 |
|
512 | |||
510 | self.createFigure(idfigure, wintitle) |
|
513 | self.createFigure(idfigure, wintitle) | |
511 |
|
514 | |||
512 | nrow,ncol = self.getSubplots() |
|
515 | nrow,ncol = self.getSubplots() | |
513 | colspan = 3 |
|
516 | colspan = 3 | |
514 | rowspan = 1 |
|
517 | rowspan = 1 | |
515 |
|
518 | |||
516 | for i in range(nplots): |
|
519 | for i in range(nplots): | |
517 | self.addAxes(nrow, ncol, i, 0, colspan, rowspan) |
|
520 | self.addAxes(nrow, ncol, i, 0, colspan, rowspan) | |
518 |
|
521 | |||
519 | self.nplots = nplots |
|
522 | self.nplots = nplots | |
520 |
|
523 | |||
521 | def run(self, dataOut, idfigure, wintitle="", channelList=None, |
|
524 | def run(self, dataOut, idfigure, wintitle="", channelList=None, | |
522 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, filename=None): |
|
525 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, filename=None): | |
523 |
|
526 | |||
524 | """ |
|
527 | """ | |
525 |
|
528 | |||
526 | Input: |
|
529 | Input: | |
527 | dataOut : |
|
530 | dataOut : | |
528 | idfigure : |
|
531 | idfigure : | |
529 | wintitle : |
|
532 | wintitle : | |
530 | channelList : |
|
533 | channelList : | |
531 | xmin : None, |
|
534 | xmin : None, | |
532 | xmax : None, |
|
535 | xmax : None, | |
533 | ymin : None, |
|
536 | ymin : None, | |
534 | ymax : None, |
|
537 | ymax : None, | |
535 | """ |
|
538 | """ | |
536 |
|
539 | |||
537 | if channelList == None: |
|
540 | if channelList == None: | |
538 | channelIndexList = dataOut.channelIndexList |
|
541 | channelIndexList = dataOut.channelIndexList | |
539 | else: |
|
542 | else: | |
540 | channelIndexList = [] |
|
543 | channelIndexList = [] | |
541 | for channel in channelList: |
|
544 | for channel in channelList: | |
542 | if channel not in dataOut.channelList: |
|
545 | if channel not in dataOut.channelList: | |
543 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
546 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
544 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
547 | channelIndexList.append(dataOut.channelList.index(channel)) | |
545 |
|
548 | |||
546 | x = dataOut.heightList |
|
549 | x = dataOut.heightList | |
547 | y = dataOut.data[channelList,:] * numpy.conjugate(dataOut.data[channelList,:]) |
|
550 | y = dataOut.data[channelList,:] * numpy.conjugate(dataOut.data[channelList,:]) | |
548 | y = y.real |
|
551 | y = y.real | |
549 |
|
552 | |||
550 | noise = dataOut.getNoise() |
|
553 | noise = dataOut.getNoise() | |
551 |
|
554 | |||
552 | if not self.__isConfig: |
|
555 | if not self.__isConfig: | |
553 | nplots = len(channelList) |
|
556 | nplots = len(channelList) | |
554 |
|
557 | |||
555 | self.setup(idfigure=idfigure, |
|
558 | self.setup(idfigure=idfigure, | |
556 | nplots=nplots, |
|
559 | nplots=nplots, | |
557 | wintitle=wintitle) |
|
560 | wintitle=wintitle) | |
558 |
|
561 | |||
559 | if xmin == None: xmin = numpy.nanmin(x) |
|
562 | if xmin == None: xmin = numpy.nanmin(x) | |
560 | if xmax == None: xmax = numpy.nanmax(x) |
|
563 | if xmax == None: xmax = numpy.nanmax(x) | |
561 | if ymin == None: ymin = numpy.nanmin(y) |
|
564 | if ymin == None: ymin = numpy.nanmin(y) | |
562 | if ymax == None: ymax = numpy.nanmax(y) |
|
565 | if ymax == None: ymax = numpy.nanmax(y) | |
563 |
|
566 | |||
564 | self.__isConfig = True |
|
567 | self.__isConfig = True | |
565 |
|
568 | |||
566 |
|
569 | |||
567 |
thisDatetime = |
|
570 | thisDatetime = dataOut.datatime | |
568 | title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
571 | title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
569 | xlabel = "Range (Km)" |
|
572 | xlabel = "Range (Km)" | |
570 | ylabel = "Intensity" |
|
573 | ylabel = "Intensity" | |
571 |
|
574 | |||
572 | self.setWinTitle(title) |
|
575 | self.setWinTitle(title) | |
573 |
|
576 | |||
574 | for i in range(len(self.axesList)): |
|
577 | for i in range(len(self.axesList)): | |
575 | title = "Channel %d: %4.2fdB" %(i, noise[i]) |
|
578 | title = "Channel %d: %4.2fdB" %(i, noise[i]) | |
576 | axes = self.axesList[i] |
|
579 | axes = self.axesList[i] | |
577 | ychannel = y[i,:] |
|
580 | ychannel = y[i,:] | |
578 | axes.pline(x, ychannel, |
|
581 | axes.pline(x, ychannel, | |
579 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
582 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |
580 | xlabel=xlabel, ylabel=ylabel, title=title) |
|
583 | xlabel=xlabel, ylabel=ylabel, title=title) | |
581 |
|
584 | |||
582 | self.draw() |
|
585 | self.draw() | |
583 |
|
586 | |||
584 | if save: |
|
587 | if save: | |
585 | self.saveFigure(filename) |
|
588 | self.saveFigure(filename) | |
586 | No newline at end of file |
|
589 |
General Comments 0
You need to be logged in to leave comments.
Login now