@@ -1,673 +1,675 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on September , 2012 |
|
2 | Created on September , 2012 | |
3 | @author: |
|
3 | @author: | |
4 | ''' |
|
4 | ''' | |
5 | from xml.etree.ElementTree import Element, SubElement, ElementTree |
|
5 | from xml.etree.ElementTree import Element, SubElement, ElementTree | |
6 | from xml.etree import ElementTree as ET |
|
6 | from xml.etree import ElementTree as ET | |
7 | from xml.dom import minidom |
|
7 | from xml.dom import minidom | |
8 |
|
8 | |||
9 | import sys |
|
9 | import sys | |
10 | import datetime |
|
10 | import datetime | |
11 | from model.jrodataIO import * |
|
11 | from model.jrodataIO import * | |
12 | from model.jroprocessing import * |
|
12 | from model.jroprocessing import * | |
13 | from model.jroplot import * |
|
13 | from model.jroplot import * | |
14 |
|
14 | |||
15 | def prettify(elem): |
|
15 | def prettify(elem): | |
16 | """Return a pretty-printed XML string for the Element. |
|
16 | """Return a pretty-printed XML string for the Element. | |
17 | """ |
|
17 | """ | |
18 | rough_string = ET.tostring(elem, 'utf-8') |
|
18 | rough_string = ET.tostring(elem, 'utf-8') | |
19 | reparsed = minidom.parseString(rough_string) |
|
19 | reparsed = minidom.parseString(rough_string) | |
20 | return reparsed.toprettyxml(indent=" ") |
|
20 | return reparsed.toprettyxml(indent=" ") | |
21 |
|
21 | |||
22 | class ParameterConf(): |
|
22 | class ParameterConf(): | |
23 |
|
23 | |||
24 | id = None |
|
24 | id = None | |
25 | name = None |
|
25 | name = None | |
26 | value = None |
|
26 | value = None | |
27 | format = None |
|
27 | format = None | |
28 |
|
28 | |||
29 | ELEMENTNAME = 'Parameter' |
|
29 | ELEMENTNAME = 'Parameter' | |
30 |
|
30 | |||
31 | def __init__(self): |
|
31 | def __init__(self): | |
32 |
|
32 | |||
33 | self.format = 'str' |
|
33 | self.format = 'str' | |
34 |
|
34 | |||
35 | def getElementName(self): |
|
35 | def getElementName(self): | |
36 |
|
36 | |||
37 | return self.ELEMENTNAME |
|
37 | return self.ELEMENTNAME | |
38 |
|
38 | |||
39 | def getValue(self): |
|
39 | def getValue(self): | |
40 |
|
40 | |||
41 | if self.format == 'list': |
|
41 | if self.format == 'list': | |
42 | strList = self.value.split(',') |
|
42 | strList = self.value.split(',') | |
43 | return strList |
|
43 | return strList | |
44 |
|
44 | |||
45 | if self.format == 'intlist': |
|
45 | if self.format == 'intlist': | |
46 | strList = self.value.split(',') |
|
46 | strList = self.value.split(',') | |
47 | intList = [int(x) for x in strList] |
|
47 | intList = [int(x) for x in strList] | |
48 | return intList |
|
48 | return intList | |
49 |
|
49 | |||
50 | if self.format == 'floatlist': |
|
50 | if self.format == 'floatlist': | |
51 | strList = self.value.split(',') |
|
51 | strList = self.value.split(',') | |
52 | floatList = [float(x) for x in strList] |
|
52 | floatList = [float(x) for x in strList] | |
53 | return floatList |
|
53 | return floatList | |
54 |
|
54 | |||
55 | if self.format == 'date': |
|
55 | if self.format == 'date': | |
56 | strList = self.value.split('/') |
|
56 | strList = self.value.split('/') | |
57 | intList = [int(x) for x in strList] |
|
57 | intList = [int(x) for x in strList] | |
58 | date = datetime.date(intList[0], intList[1], intList[2]) |
|
58 | date = datetime.date(intList[0], intList[1], intList[2]) | |
59 | return date |
|
59 | return date | |
60 |
|
60 | |||
61 | if self.format == 'time': |
|
61 | if self.format == 'time': | |
62 | strList = self.value.split(':') |
|
62 | strList = self.value.split(':') | |
63 | intList = [int(x) for x in strList] |
|
63 | intList = [int(x) for x in strList] | |
64 | time = datetime.time(intList[0], intList[1], intList[2]) |
|
64 | time = datetime.time(intList[0], intList[1], intList[2]) | |
65 | return time |
|
65 | return time | |
66 |
|
66 | |||
67 | func = eval(self.format) |
|
67 | func = eval(self.format) | |
68 |
|
68 | |||
69 | return func(self.value) |
|
69 | return func(self.value) | |
70 |
|
70 | |||
71 | def setup(self, id, name, value, format='str'): |
|
71 | def setup(self, id, name, value, format='str'): | |
72 |
|
72 | |||
73 | self.id = id |
|
73 | self.id = id | |
74 | self.name = name |
|
74 | self.name = name | |
75 | self.value = str(value) |
|
75 | self.value = str(value) | |
76 | self.format = format |
|
76 | self.format = format | |
77 |
|
77 | |||
78 | def makeXml(self, opElement): |
|
78 | def makeXml(self, opElement): | |
79 |
|
79 | |||
80 | parmElement = SubElement(opElement, self.ELEMENTNAME) |
|
80 | parmElement = SubElement(opElement, self.ELEMENTNAME) | |
81 | parmElement.set('id', str(self.id)) |
|
81 | parmElement.set('id', str(self.id)) | |
82 | parmElement.set('name', self.name) |
|
82 | parmElement.set('name', self.name) | |
83 | parmElement.set('value', self.value) |
|
83 | parmElement.set('value', self.value) | |
84 | parmElement.set('format', self.format) |
|
84 | parmElement.set('format', self.format) | |
85 |
|
85 | |||
86 | def readXml(self, parmElement): |
|
86 | def readXml(self, parmElement): | |
87 |
|
87 | |||
88 | self.id = parmElement.get('id') |
|
88 | self.id = parmElement.get('id') | |
89 | self.name = parmElement.get('name') |
|
89 | self.name = parmElement.get('name') | |
90 | self.value = parmElement.get('value') |
|
90 | self.value = parmElement.get('value') | |
91 | self.format = parmElement.get('format') |
|
91 | self.format = parmElement.get('format') | |
92 |
|
92 | |||
93 | def printattr(self): |
|
93 | def printattr(self): | |
94 |
|
94 | |||
95 | print "Parameter[%s]: name = %s, value = %s, format = %s" %(self.id, self.name, self.value, self.format) |
|
95 | print "Parameter[%s]: name = %s, value = %s, format = %s" %(self.id, self.name, self.value, self.format) | |
96 |
|
96 | |||
97 | class OperationConf(): |
|
97 | class OperationConf(): | |
98 |
|
98 | |||
99 | id = None |
|
99 | id = None | |
100 | name = None |
|
100 | name = None | |
101 | priority = None |
|
101 | priority = None | |
102 | type = None |
|
102 | type = None | |
103 |
|
103 | |||
104 | parmConfObjList = [] |
|
104 | parmConfObjList = [] | |
105 |
|
105 | |||
106 | ELEMENTNAME = 'Operation' |
|
106 | ELEMENTNAME = 'Operation' | |
107 |
|
107 | |||
108 | def __init__(self): |
|
108 | def __init__(self): | |
109 |
|
109 | |||
110 | id = 0 |
|
110 | id = 0 | |
111 | name = None |
|
111 | name = None | |
112 | priority = None |
|
112 | priority = None | |
113 | type = 'self' |
|
113 | type = 'self' | |
114 |
|
114 | |||
115 |
|
115 | |||
116 | def __getNewId(self): |
|
116 | def __getNewId(self): | |
117 |
|
117 | |||
118 | return int(self.id)*10 + len(self.parmConfObjList) + 1 |
|
118 | return int(self.id)*10 + len(self.parmConfObjList) + 1 | |
119 |
|
119 | |||
120 | def getElementName(self): |
|
120 | def getElementName(self): | |
121 |
|
121 | |||
122 | return self.ELEMENTNAME |
|
122 | return self.ELEMENTNAME | |
123 |
|
123 | |||
124 | def getParameterObjList(self): |
|
124 | def getParameterObjList(self): | |
125 |
|
125 | |||
126 | return self.parmConfObjList |
|
126 | return self.parmConfObjList | |
127 |
|
127 | |||
128 | def setup(self, id, name, priority, type): |
|
128 | def setup(self, id, name, priority, type): | |
129 |
|
129 | |||
130 | self.id = id |
|
130 | self.id = id | |
131 | self.name = name |
|
131 | self.name = name | |
132 | self.type = type |
|
132 | self.type = type | |
133 | self.priority = priority |
|
133 | self.priority = priority | |
134 |
|
134 | |||
135 | self.parmConfObjList = [] |
|
135 | self.parmConfObjList = [] | |
136 |
|
136 | |||
137 | def addParameter(self, name, value, format='str'): |
|
137 | def addParameter(self, name, value, format='str'): | |
138 |
|
138 | |||
139 | id = self.__getNewId() |
|
139 | id = self.__getNewId() | |
140 |
|
140 | |||
141 | parmConfObj = ParameterConf() |
|
141 | parmConfObj = ParameterConf() | |
142 | parmConfObj.setup(id, name, value, format) |
|
142 | parmConfObj.setup(id, name, value, format) | |
143 |
|
143 | |||
144 | self.parmConfObjList.append(parmConfObj) |
|
144 | self.parmConfObjList.append(parmConfObj) | |
145 |
|
145 | |||
146 | return parmConfObj |
|
146 | return parmConfObj | |
147 |
|
147 | |||
148 | def makeXml(self, upElement): |
|
148 | def makeXml(self, upElement): | |
149 |
|
149 | |||
150 | opElement = SubElement(upElement, self.ELEMENTNAME) |
|
150 | opElement = SubElement(upElement, self.ELEMENTNAME) | |
151 | opElement.set('id', str(self.id)) |
|
151 | opElement.set('id', str(self.id)) | |
152 | opElement.set('name', self.name) |
|
152 | opElement.set('name', self.name) | |
153 | opElement.set('type', self.type) |
|
153 | opElement.set('type', self.type) | |
154 | opElement.set('priority', str(self.priority)) |
|
154 | opElement.set('priority', str(self.priority)) | |
155 |
|
155 | |||
156 | for parmConfObj in self.parmConfObjList: |
|
156 | for parmConfObj in self.parmConfObjList: | |
157 | parmConfObj.makeXml(opElement) |
|
157 | parmConfObj.makeXml(opElement) | |
158 |
|
158 | |||
159 | def readXml(self, opElement): |
|
159 | def readXml(self, opElement): | |
160 |
|
160 | |||
161 | self.id = opElement.get('id') |
|
161 | self.id = opElement.get('id') | |
162 | self.name = opElement.get('name') |
|
162 | self.name = opElement.get('name') | |
163 | self.type = opElement.get('type') |
|
163 | self.type = opElement.get('type') | |
164 | self.priority = opElement.get('priority') |
|
164 | self.priority = opElement.get('priority') | |
165 |
|
165 | |||
166 | self.parmConfObjList = [] |
|
166 | self.parmConfObjList = [] | |
167 |
|
167 | |||
168 | parmElementList = opElement.getiterator(ParameterConf().getElementName()) |
|
168 | parmElementList = opElement.getiterator(ParameterConf().getElementName()) | |
169 |
|
169 | |||
170 | for parmElement in parmElementList: |
|
170 | for parmElement in parmElementList: | |
171 | parmConfObj = ParameterConf() |
|
171 | parmConfObj = ParameterConf() | |
172 | parmConfObj.readXml(parmElement) |
|
172 | parmConfObj.readXml(parmElement) | |
173 | self.parmConfObjList.append(parmConfObj) |
|
173 | self.parmConfObjList.append(parmConfObj) | |
174 |
|
174 | |||
175 | def printattr(self): |
|
175 | def printattr(self): | |
176 |
|
176 | |||
177 | print "%s[%s]: name = %s, type = %s, priority = %s" %(self.ELEMENTNAME, |
|
177 | print "%s[%s]: name = %s, type = %s, priority = %s" %(self.ELEMENTNAME, | |
178 | self.id, |
|
178 | self.id, | |
179 | self.name, |
|
179 | self.name, | |
180 | self.type, |
|
180 | self.type, | |
181 | self.priority) |
|
181 | self.priority) | |
182 |
|
182 | |||
183 | for parmConfObj in self.parmConfObjList: |
|
183 | for parmConfObj in self.parmConfObjList: | |
184 | parmConfObj.printattr() |
|
184 | parmConfObj.printattr() | |
185 |
|
185 | |||
186 | def createObject(self): |
|
186 | def createObject(self): | |
187 |
|
187 | |||
188 | if self.type == 'self': |
|
188 | if self.type == 'self': | |
189 | raise ValueError, "This operation type cannot be created" |
|
189 | raise ValueError, "This operation type cannot be created" | |
190 |
|
190 | |||
191 | if self.type == 'other': |
|
191 | if self.type == 'other': | |
192 | className = eval(self.name) |
|
192 | className = eval(self.name) | |
193 | opObj = className() |
|
193 | opObj = className() | |
194 |
|
194 | |||
195 | return opObj |
|
195 | return opObj | |
196 |
|
196 | |||
197 | class ProcUnitConf(): |
|
197 | class ProcUnitConf(): | |
198 |
|
198 | |||
199 | id = None |
|
199 | id = None | |
200 | name = None |
|
200 | name = None | |
201 | datatype = None |
|
201 | datatype = None | |
202 | inputId = None |
|
202 | inputId = None | |
203 |
|
203 | |||
204 | opConfObjList = [] |
|
204 | opConfObjList = [] | |
205 |
|
205 | |||
206 | procUnitObj = None |
|
206 | procUnitObj = None | |
207 | opObjList = [] |
|
207 | opObjList = [] | |
208 |
|
208 | |||
209 | ELEMENTNAME = 'ProcUnit' |
|
209 | ELEMENTNAME = 'ProcUnit' | |
210 |
|
210 | |||
211 | def __init__(self): |
|
211 | def __init__(self): | |
212 |
|
212 | |||
213 | self.id = None |
|
213 | self.id = None | |
214 | self.datatype = None |
|
214 | self.datatype = None | |
215 | self.name = None |
|
215 | self.name = None | |
216 | self.inputId = None |
|
216 | self.inputId = None | |
217 |
|
217 | |||
218 | self.opConfObjList = [] |
|
218 | self.opConfObjList = [] | |
219 |
|
219 | |||
220 | self.procUnitObj = None |
|
220 | self.procUnitObj = None | |
221 | self.opObjDict = {} |
|
221 | self.opObjDict = {} | |
222 |
|
222 | |||
223 | def __getPriority(self): |
|
223 | def __getPriority(self): | |
224 |
|
224 | |||
225 | return len(self.opConfObjList)+1 |
|
225 | return len(self.opConfObjList)+1 | |
226 |
|
226 | |||
227 | def __getNewId(self): |
|
227 | def __getNewId(self): | |
228 |
|
228 | |||
229 | return int(self.id)*10 + len(self.opConfObjList) + 1 |
|
229 | return int(self.id)*10 + len(self.opConfObjList) + 1 | |
230 |
|
230 | |||
231 | def getElementName(self): |
|
231 | def getElementName(self): | |
232 |
|
232 | |||
233 | return self.ELEMENTNAME |
|
233 | return self.ELEMENTNAME | |
234 |
|
234 | |||
235 | def getId(self): |
|
235 | def getId(self): | |
236 |
|
236 | |||
237 | return str(self.id) |
|
237 | return str(self.id) | |
238 |
|
238 | |||
239 | def getInputId(self): |
|
239 | def getInputId(self): | |
240 |
|
240 | |||
241 | return str(self.inputId) |
|
241 | return str(self.inputId) | |
242 |
|
242 | |||
243 | def getOperationObjList(self): |
|
243 | def getOperationObjList(self): | |
244 |
|
244 | |||
245 | return self.opConfObjList |
|
245 | return self.opConfObjList | |
246 |
|
246 | |||
247 | def getProcUnitObj(self): |
|
247 | def getProcUnitObj(self): | |
248 |
|
248 | |||
249 | return self.procUnitObj |
|
249 | return self.procUnitObj | |
250 |
|
250 | |||
251 | def setup(self, id, name, datatype, inputId): |
|
251 | def setup(self, id, name, datatype, inputId): | |
252 |
|
252 | |||
253 | self.id = id |
|
253 | self.id = id | |
254 | self.name = name |
|
254 | self.name = name | |
255 | self.datatype = datatype |
|
255 | self.datatype = datatype | |
256 | self.inputId = inputId |
|
256 | self.inputId = inputId | |
257 |
|
257 | |||
258 | self.opConfObjList = [] |
|
258 | self.opConfObjList = [] | |
259 |
|
259 | |||
260 | self.addOperation(name='init', optype='self') |
|
260 | self.addOperation(name='init', optype='self') | |
261 |
|
261 | |||
262 | def addOperation(self, name, optype='self'): |
|
262 | def addOperation(self, name, optype='self'): | |
263 |
|
263 | |||
264 | id = self.__getNewId() |
|
264 | id = self.__getNewId() | |
265 | priority = self.__getPriority() |
|
265 | priority = self.__getPriority() | |
266 |
|
266 | |||
267 | opConfObj = OperationConf() |
|
267 | opConfObj = OperationConf() | |
268 | opConfObj.setup(id, name=name, priority=priority, type=optype) |
|
268 | opConfObj.setup(id, name=name, priority=priority, type=optype) | |
269 |
|
269 | |||
270 | self.opConfObjList.append(opConfObj) |
|
270 | self.opConfObjList.append(opConfObj) | |
271 |
|
271 | |||
272 | return opConfObj |
|
272 | return opConfObj | |
273 |
|
273 | |||
274 | def makeXml(self, procUnitElement): |
|
274 | def makeXml(self, procUnitElement): | |
275 |
|
275 | |||
276 | upElement = SubElement(procUnitElement, self.ELEMENTNAME) |
|
276 | upElement = SubElement(procUnitElement, self.ELEMENTNAME) | |
277 | upElement.set('id', str(self.id)) |
|
277 | upElement.set('id', str(self.id)) | |
278 | upElement.set('name', self.name) |
|
278 | upElement.set('name', self.name) | |
279 | upElement.set('datatype', self.datatype) |
|
279 | upElement.set('datatype', self.datatype) | |
280 | upElement.set('inputId', str(self.inputId)) |
|
280 | upElement.set('inputId', str(self.inputId)) | |
281 |
|
281 | |||
282 | for opConfObj in self.opConfObjList: |
|
282 | for opConfObj in self.opConfObjList: | |
283 | opConfObj.makeXml(upElement) |
|
283 | opConfObj.makeXml(upElement) | |
284 |
|
284 | |||
285 | def readXml(self, upElement): |
|
285 | def readXml(self, upElement): | |
286 |
|
286 | |||
287 | self.id = upElement.get('id') |
|
287 | self.id = upElement.get('id') | |
288 | self.name = upElement.get('name') |
|
288 | self.name = upElement.get('name') | |
289 | self.datatype = upElement.get('datatype') |
|
289 | self.datatype = upElement.get('datatype') | |
290 | self.inputId = upElement.get('inputId') |
|
290 | self.inputId = upElement.get('inputId') | |
291 |
|
291 | |||
292 | self.opConfObjList = [] |
|
292 | self.opConfObjList = [] | |
293 |
|
293 | |||
294 | opElementList = upElement.getiterator(OperationConf().getElementName()) |
|
294 | opElementList = upElement.getiterator(OperationConf().getElementName()) | |
295 |
|
295 | |||
296 | for opElement in opElementList: |
|
296 | for opElement in opElementList: | |
297 | opConfObj = OperationConf() |
|
297 | opConfObj = OperationConf() | |
298 | opConfObj.readXml(opElement) |
|
298 | opConfObj.readXml(opElement) | |
299 | self.opConfObjList.append(opConfObj) |
|
299 | self.opConfObjList.append(opConfObj) | |
300 |
|
300 | |||
301 | def printattr(self): |
|
301 | def printattr(self): | |
302 |
|
302 | |||
303 | print "%s[%s]: name = %s, datatype = %s, inputId = %s" %(self.ELEMENTNAME, |
|
303 | print "%s[%s]: name = %s, datatype = %s, inputId = %s" %(self.ELEMENTNAME, | |
304 | self.id, |
|
304 | self.id, | |
305 | self.name, |
|
305 | self.name, | |
306 | self.datatype, |
|
306 | self.datatype, | |
307 | self.inputId) |
|
307 | self.inputId) | |
308 |
|
308 | |||
309 | for opConfObj in self.opConfObjList: |
|
309 | for opConfObj in self.opConfObjList: | |
310 | opConfObj.printattr() |
|
310 | opConfObj.printattr() | |
311 |
|
311 | |||
312 | def createObjects(self): |
|
312 | def createObjects(self): | |
313 |
|
313 | |||
314 | className = eval(self.name) |
|
314 | className = eval(self.name) | |
315 | procUnitObj = className() |
|
315 | procUnitObj = className() | |
316 |
|
316 | |||
317 | for opConfObj in self.opConfObjList: |
|
317 | for opConfObj in self.opConfObjList: | |
318 |
|
318 | |||
319 | if opConfObj.type == 'self': |
|
319 | if opConfObj.type == 'self': | |
320 | continue |
|
320 | continue | |
321 |
|
321 | |||
322 | opObj = opConfObj.createObject() |
|
322 | opObj = opConfObj.createObject() | |
323 |
|
323 | |||
324 | self.opObjDict[opConfObj.id] = opObj |
|
324 | self.opObjDict[opConfObj.id] = opObj | |
325 | procUnitObj.addOperation(opObj, opConfObj.id) |
|
325 | procUnitObj.addOperation(opObj, opConfObj.id) | |
326 |
|
326 | |||
327 | self.procUnitObj = procUnitObj |
|
327 | self.procUnitObj = procUnitObj | |
328 |
|
328 | |||
329 | return procUnitObj |
|
329 | return procUnitObj | |
330 |
|
330 | |||
331 | def run(self): |
|
331 | def run(self): | |
332 |
|
332 | |||
333 | finalSts = False |
|
333 | finalSts = False | |
334 |
|
334 | |||
335 | for opConfObj in self.opConfObjList: |
|
335 | for opConfObj in self.opConfObjList: | |
336 |
|
336 | |||
337 | kwargs = {} |
|
337 | kwargs = {} | |
338 | for parmConfObj in opConfObj.getParameterObjList(): |
|
338 | for parmConfObj in opConfObj.getParameterObjList(): | |
339 | kwargs[parmConfObj.name] = parmConfObj.getValue() |
|
339 | kwargs[parmConfObj.name] = parmConfObj.getValue() | |
340 |
|
340 | |||
341 | #print "\tRunning the '%s' operation with %s" %(opConfObj.name, opConfObj.id) |
|
341 | #print "\tRunning the '%s' operation with %s" %(opConfObj.name, opConfObj.id) | |
342 | sts = self.procUnitObj.call(opConfObj, **kwargs) |
|
342 | sts = self.procUnitObj.call(opConfObj, **kwargs) | |
343 | finalSts = finalSts or sts |
|
343 | finalSts = finalSts or sts | |
344 |
|
344 | |||
345 | return finalSts |
|
345 | return finalSts | |
346 |
|
346 | |||
347 | class ReadUnitConf(ProcUnitConf): |
|
347 | class ReadUnitConf(ProcUnitConf): | |
348 |
|
348 | |||
349 | path = None |
|
349 | path = None | |
350 | startDate = None |
|
350 | startDate = None | |
351 | endDate = None |
|
351 | endDate = None | |
352 | startTime = None |
|
352 | startTime = None | |
353 | endTime = None |
|
353 | endTime = None | |
354 | online = None |
|
354 | online = None | |
355 | expLabel = None |
|
355 | expLabel = None | |
356 | delay = None |
|
356 | delay = None | |
357 |
|
357 | |||
358 | ELEMENTNAME = 'ReadUnit' |
|
358 | ELEMENTNAME = 'ReadUnit' | |
359 |
|
359 | |||
360 | def __init__(self): |
|
360 | def __init__(self): | |
361 |
|
361 | |||
362 | self.id = None |
|
362 | self.id = None | |
363 | self.datatype = None |
|
363 | self.datatype = None | |
364 | self.name = None |
|
364 | self.name = None | |
365 | self.inputId = 0 |
|
365 | self.inputId = 0 | |
366 |
|
366 | |||
367 | self.opConfObjList = [] |
|
367 | self.opConfObjList = [] | |
368 | self.opObjList = [] |
|
368 | self.opObjList = [] | |
369 |
|
369 | |||
370 | def getElementName(self): |
|
370 | def getElementName(self): | |
371 |
|
371 | |||
372 | return self.ELEMENTNAME |
|
372 | return self.ELEMENTNAME | |
373 |
|
373 | |||
374 | def setup(self, id, name, datatype, path, startDate, endDate, startTime, endTime, online=0, expLabel='', delay=60): |
|
374 | def setup(self, id, name, datatype, path, startDate, endDate, startTime, endTime, online=0, expLabel='', delay=60): | |
375 |
|
375 | |||
376 | self.id = id |
|
376 | self.id = id | |
377 | self.name = name |
|
377 | self.name = name | |
378 | self.datatype = datatype |
|
378 | self.datatype = datatype | |
379 |
|
379 | |||
380 | self.path = path |
|
380 | self.path = path | |
381 | self.startDate = startDate |
|
381 | self.startDate = startDate | |
382 | self.endDate = endDate |
|
382 | self.endDate = endDate | |
383 | self.startTime = startTime |
|
383 | self.startTime = startTime | |
384 | self.endTime = endTime |
|
384 | self.endTime = endTime | |
385 | self.online = online |
|
385 | self.online = online | |
386 | self.expLabel = expLabel |
|
386 | self.expLabel = expLabel | |
387 | self.delay = delay |
|
387 | self.delay = delay | |
388 |
|
388 | |||
389 | self.addRunOperation() |
|
389 | self.addRunOperation() | |
390 |
|
390 | |||
391 | def addRunOperation(self): |
|
391 | def addRunOperation(self): | |
392 |
|
392 | |||
393 | opObj = self.addOperation(name = 'run', optype = 'self') |
|
393 | opObj = self.addOperation(name = 'run', optype = 'self') | |
394 |
|
394 | |||
395 | opObj.addParameter(name='path' , value=self.path, format='str') |
|
395 | opObj.addParameter(name='path' , value=self.path, format='str') | |
396 | opObj.addParameter(name='startDate' , value=self.startDate, format='date') |
|
396 | opObj.addParameter(name='startDate' , value=self.startDate, format='date') | |
397 | opObj.addParameter(name='endDate' , value=self.endDate, format='date') |
|
397 | opObj.addParameter(name='endDate' , value=self.endDate, format='date') | |
398 | opObj.addParameter(name='startTime' , value=self.startTime, format='time') |
|
398 | opObj.addParameter(name='startTime' , value=self.startTime, format='time') | |
399 | opObj.addParameter(name='endTime' , value=self.endTime, format='time') |
|
399 | opObj.addParameter(name='endTime' , value=self.endTime, format='time') | |
400 | opObj.addParameter(name='expLabel' , value=self.expLabel, format='str') |
|
400 | opObj.addParameter(name='expLabel' , value=self.expLabel, format='str') | |
401 | opObj.addParameter(name='online' , value=self.online, format='int') |
|
401 | opObj.addParameter(name='online' , value=self.online, format='int') | |
402 | opObj.addParameter(name='delay' , value=self.delay, format='float') |
|
402 | opObj.addParameter(name='delay' , value=self.delay, format='float') | |
403 |
|
403 | |||
404 | return opObj |
|
404 | return opObj | |
405 |
|
405 | |||
406 |
|
406 | |||
407 | class Controller(): |
|
407 | class Controller(): | |
408 |
|
408 | |||
409 | id = None |
|
409 | id = None | |
410 | name = None |
|
410 | name = None | |
411 | description = None |
|
411 | description = None | |
412 | # readUnitConfObjList = None |
|
412 | # readUnitConfObjList = None | |
413 | procUnitConfObjDict = None |
|
413 | procUnitConfObjDict = None | |
414 |
|
414 | |||
415 | ELEMENTNAME = 'Controller' |
|
415 | ELEMENTNAME = 'Controller' | |
416 |
|
416 | |||
417 | def __init__(self): |
|
417 | def __init__(self): | |
418 |
|
418 | |||
419 | self.id = None |
|
419 | self.id = None | |
420 | self.name = None |
|
420 | self.name = None | |
421 | self.description = None |
|
421 | self.description = None | |
422 |
|
422 | |||
423 | # self.readUnitConfObjList = [] |
|
423 | # self.readUnitConfObjList = [] | |
424 | self.procUnitConfObjDict = {} |
|
424 | self.procUnitConfObjDict = {} | |
425 |
|
425 | |||
426 | def __getNewId(self): |
|
426 | def __getNewId(self): | |
427 |
|
427 | |||
428 | id = int(self.id)*10 + len(self.procUnitConfObjDict) + 1 |
|
428 | id = int(self.id)*10 + len(self.procUnitConfObjDict) + 1 | |
429 |
|
429 | |||
430 | return str(id) |
|
430 | return str(id) | |
431 |
|
431 | |||
432 | def getElementName(self): |
|
432 | def getElementName(self): | |
433 |
|
433 | |||
434 | return self.ELEMENTNAME |
|
434 | return self.ELEMENTNAME | |
435 |
|
435 | |||
436 | def setup(self, id, name, description): |
|
436 | def setup(self, id, name, description): | |
437 |
|
437 | |||
438 | self.id = id |
|
438 | self.id = id | |
439 | self.name = name |
|
439 | self.name = name | |
440 | self.description = description |
|
440 | self.description = description | |
441 |
|
441 | |||
442 | def addReadUnit(self, datatype, path, startDate='', endDate='', startTime='', endTime='', online=0, expLabel='', delay=60): |
|
442 | def addReadUnit(self, datatype, path, startDate='', endDate='', startTime='', endTime='', online=0, expLabel='', delay=60): | |
443 |
|
443 | |||
444 | id = self.__getNewId() |
|
444 | id = self.__getNewId() | |
445 | name = '%sReader' %(datatype) |
|
445 | name = '%sReader' %(datatype) | |
446 |
|
446 | |||
447 | readUnitConfObj = ReadUnitConf() |
|
447 | readUnitConfObj = ReadUnitConf() | |
448 | readUnitConfObj.setup(id, name, datatype, path, startDate, endDate, startTime, endTime, online, expLabel, delay) |
|
448 | readUnitConfObj.setup(id, name, datatype, path, startDate, endDate, startTime, endTime, online, expLabel, delay) | |
449 |
|
449 | |||
450 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj |
|
450 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj | |
451 |
|
451 | |||
452 | return readUnitConfObj |
|
452 | return readUnitConfObj | |
453 |
|
453 | |||
454 | def addProcUnit(self, datatype, inputId): |
|
454 | def addProcUnit(self, datatype, inputId): | |
455 |
|
455 | |||
456 | id = self.__getNewId() |
|
456 | id = self.__getNewId() | |
457 | name = '%sProc' %(datatype) |
|
457 | name = '%sProc' %(datatype) | |
458 |
|
458 | |||
459 | procUnitConfObj = ProcUnitConf() |
|
459 | procUnitConfObj = ProcUnitConf() | |
460 | procUnitConfObj.setup(id, name, datatype, inputId) |
|
460 | procUnitConfObj.setup(id, name, datatype, inputId) | |
461 |
|
461 | |||
462 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj |
|
462 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj | |
463 |
|
463 | |||
464 | return procUnitConfObj |
|
464 | return procUnitConfObj | |
465 |
|
465 | |||
466 | def makeXml(self): |
|
466 | def makeXml(self): | |
467 |
|
467 | |||
468 | projectElement = Element('Controller') |
|
468 | projectElement = Element('Controller') | |
469 | projectElement.set('id', str(self.id)) |
|
469 | projectElement.set('id', str(self.id)) | |
470 | projectElement.set('name', self.name) |
|
470 | projectElement.set('name', self.name) | |
471 | projectElement.set('description', self.description) |
|
471 | projectElement.set('description', self.description) | |
472 |
|
472 | |||
473 | # for readUnitConfObj in self.readUnitConfObjList: |
|
473 | # for readUnitConfObj in self.readUnitConfObjList: | |
474 | # readUnitConfObj.makeXml(projectElement) |
|
474 | # readUnitConfObj.makeXml(projectElement) | |
475 |
|
475 | |||
476 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
476 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |
477 | procUnitConfObj.makeXml(projectElement) |
|
477 | procUnitConfObj.makeXml(projectElement) | |
478 |
|
478 | |||
479 | self.projectElement = projectElement |
|
479 | self.projectElement = projectElement | |
480 |
|
480 | |||
481 | def writeXml(self, filename): |
|
481 | def writeXml(self, filename): | |
482 |
|
482 | |||
483 | self.makeXml() |
|
483 | self.makeXml() | |
484 |
|
484 | |||
485 | print prettify(self.projectElement) |
|
485 | print prettify(self.projectElement) | |
486 |
|
486 | |||
487 | ElementTree(self.projectElement).write(filename, method='xml') |
|
487 | ElementTree(self.projectElement).write(filename, method='xml') | |
488 |
|
488 | |||
489 | def readXml(self, filename): |
|
489 | def readXml(self, filename): | |
490 |
|
490 | |||
491 | #tree = ET.parse(filename) |
|
491 | #tree = ET.parse(filename) | |
492 | self.projectElement = None |
|
492 | self.projectElement = None | |
493 | # self.readUnitConfObjList = [] |
|
493 | # self.readUnitConfObjList = [] | |
494 | self.procUnitConfObjDict = {} |
|
494 | self.procUnitConfObjDict = {} | |
495 |
|
495 | |||
496 | self.projectElement = ElementTree().parse(filename) |
|
496 | self.projectElement = ElementTree().parse(filename) | |
497 |
|
497 | |||
498 | self.project = self.projectElement.tag |
|
498 | self.project = self.projectElement.tag | |
499 |
|
499 | |||
500 | self.id = self.projectElement.get('id') |
|
500 | self.id = self.projectElement.get('id') | |
501 | self.name = self.projectElement.get('name') |
|
501 | self.name = self.projectElement.get('name') | |
502 | self.description = self.projectElement.get('description') |
|
502 | self.description = self.projectElement.get('description') | |
503 |
|
503 | |||
504 | readUnitElementList = self.projectElement.getiterator(ReadUnitConf().getElementName()) |
|
504 | readUnitElementList = self.projectElement.getiterator(ReadUnitConf().getElementName()) | |
505 |
|
505 | |||
506 | for readUnitElement in readUnitElementList: |
|
506 | for readUnitElement in readUnitElementList: | |
507 | readUnitConfObj = ReadUnitConf() |
|
507 | readUnitConfObj = ReadUnitConf() | |
508 | readUnitConfObj.readXml(readUnitElement) |
|
508 | readUnitConfObj.readXml(readUnitElement) | |
509 |
|
509 | |||
510 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj |
|
510 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj | |
511 |
|
511 | |||
512 | procUnitElementList = self.projectElement.getiterator(ProcUnitConf().getElementName()) |
|
512 | procUnitElementList = self.projectElement.getiterator(ProcUnitConf().getElementName()) | |
513 |
|
513 | |||
514 | for procUnitElement in procUnitElementList: |
|
514 | for procUnitElement in procUnitElementList: | |
515 | procUnitConfObj = ProcUnitConf() |
|
515 | procUnitConfObj = ProcUnitConf() | |
516 | procUnitConfObj.readXml(procUnitElement) |
|
516 | procUnitConfObj.readXml(procUnitElement) | |
517 |
|
517 | |||
518 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj |
|
518 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj | |
519 |
|
519 | |||
520 | def printattr(self): |
|
520 | def printattr(self): | |
521 |
|
521 | |||
522 | print "Controller[%s]: name = %s, description = %s" %(self.id, |
|
522 | print "Controller[%s]: name = %s, description = %s" %(self.id, | |
523 | self.name, |
|
523 | self.name, | |
524 | self.description) |
|
524 | self.description) | |
525 |
|
525 | |||
526 | # for readUnitConfObj in self.readUnitConfObjList: |
|
526 | # for readUnitConfObj in self.readUnitConfObjList: | |
527 | # readUnitConfObj.printattr() |
|
527 | # readUnitConfObj.printattr() | |
528 |
|
528 | |||
529 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
529 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |
530 | procUnitConfObj.printattr() |
|
530 | procUnitConfObj.printattr() | |
531 |
|
531 | |||
532 | def createObjects(self): |
|
532 | def createObjects(self): | |
533 |
|
533 | |||
534 | # for readUnitConfObj in self.readUnitConfObjList: |
|
534 | # for readUnitConfObj in self.readUnitConfObjList: | |
535 | # readUnitConfObj.createObjects() |
|
535 | # readUnitConfObj.createObjects() | |
536 |
|
536 | |||
537 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
537 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |
538 | procUnitConfObj.createObjects() |
|
538 | procUnitConfObj.createObjects() | |
539 |
|
539 | |||
540 | def __connect(self, objIN, obj): |
|
540 | def __connect(self, objIN, obj): | |
541 |
|
541 | |||
542 | obj.setInput(objIN.getOutput()) |
|
542 | obj.setInput(objIN.getOutput()) | |
543 |
|
543 | |||
544 | def connectObjects(self): |
|
544 | def connectObjects(self): | |
545 |
|
545 | |||
546 | for puConfObj in self.procUnitConfObjDict.values(): |
|
546 | for puConfObj in self.procUnitConfObjDict.values(): | |
547 |
|
547 | |||
548 | inputId = puConfObj.getInputId() |
|
548 | inputId = puConfObj.getInputId() | |
549 |
|
549 | |||
550 | if int(inputId) == 0: |
|
550 | if int(inputId) == 0: | |
551 | continue |
|
551 | continue | |
552 |
|
552 | |||
553 | puConfINObj = self.procUnitConfObjDict[inputId] |
|
553 | puConfINObj = self.procUnitConfObjDict[inputId] | |
554 |
|
554 | |||
555 | puObj = puConfObj.getProcUnitObj() |
|
555 | puObj = puConfObj.getProcUnitObj() | |
556 | puINObj = puConfINObj.getProcUnitObj() |
|
556 | puINObj = puConfINObj.getProcUnitObj() | |
557 |
|
557 | |||
558 | self.__connect(puINObj, puObj) |
|
558 | self.__connect(puINObj, puObj) | |
559 |
|
559 | |||
560 | def run(self): |
|
560 | def run(self): | |
561 |
|
561 | |||
562 | # for readUnitConfObj in self.readUnitConfObjList: |
|
562 | # for readUnitConfObj in self.readUnitConfObjList: | |
563 | # readUnitConfObj.run() |
|
563 | # readUnitConfObj.run() | |
564 |
|
564 | |||
565 | while(True): |
|
565 | while(True): | |
566 |
|
566 | |||
567 | finalSts = False |
|
567 | finalSts = False | |
568 |
|
568 | |||
569 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
569 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |
570 | #print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id) |
|
570 | #print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id) | |
571 | sts = procUnitConfObj.run() |
|
571 | sts = procUnitConfObj.run() | |
572 | finalSts = finalSts or sts |
|
572 | finalSts = finalSts or sts | |
573 |
|
573 | |||
574 | #If every process unit finished so end process |
|
574 | #If every process unit finished so end process | |
575 | if not(finalSts): |
|
575 | if not(finalSts): | |
576 | print "Every process units have finished" |
|
576 | print "Every process units have finished" | |
577 | break |
|
577 | break | |
578 |
|
578 | |||
579 | if __name__ == '__main__': |
|
579 | if __name__ == '__main__': | |
580 |
|
580 | |||
581 | desc = "Segundo Test" |
|
581 | desc = "Segundo Test" | |
582 | filename = "schain.xml" |
|
582 | filename = "schain.xml" | |
583 |
|
583 | |||
584 | controllerObj = Controller() |
|
584 | controllerObj = Controller() | |
585 |
|
585 | |||
586 | controllerObj.setup(id = '191', name='test01', description=desc) |
|
586 | controllerObj.setup(id = '191', name='test01', description=desc) | |
587 |
|
587 | |||
588 | readUnitConfObj = controllerObj.addReadUnit(datatype='Spectra', |
|
588 | readUnitConfObj = controllerObj.addReadUnit(datatype='Spectra', | |
589 | path='/Users/dsuarez/Remote/IMAGING', |
|
589 | path='/Users/dsuarez/Remote/IMAGING', | |
590 | startDate='2011/03/20', |
|
590 | startDate='2011/03/20', | |
591 | endDate='2012/12/31', |
|
591 | endDate='2012/12/31', | |
592 | startTime='06:10:00', |
|
592 | startTime='06:10:00', | |
593 | endTime='23:59:59', |
|
593 | endTime='23:59:59', | |
594 | online=0) |
|
594 | online=0) | |
595 |
|
595 | |||
596 | opObj00 = readUnitConfObj.addOperation(name='printTotalBlocks') |
|
596 | opObj00 = readUnitConfObj.addOperation(name='printTotalBlocks') | |
597 |
|
597 | |||
598 | procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=readUnitConfObj.getId()) |
|
598 | procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=readUnitConfObj.getId()) | |
599 |
|
599 | |||
600 | opObj10 = procUnitConfObj1.addOperation(name='selectChannels') |
|
600 | opObj10 = procUnitConfObj1.addOperation(name='selectChannels') | |
601 | opObj10.addParameter(name='channelList', value='0,1,2,4,6,7', format='intlist') |
|
601 | opObj10.addParameter(name='channelList', value='0,1,2,4,6,7', format='intlist') | |
602 |
|
602 | |||
603 | opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') |
|
603 | opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') | |
604 | opObj11.addParameter(name='idfigure', value='1', format='int') |
|
604 | opObj11.addParameter(name='idfigure', value='1', format='int') | |
605 | opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str') |
|
605 | opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str') | |
606 | # opObj11.addParameter(name='zmin', value='70', format='int') |
|
606 | # opObj11.addParameter(name='zmin', value='70', format='int') | |
607 | # opObj11.addParameter(name='zmax', value='90', format='int') |
|
607 | # opObj11.addParameter(name='zmax', value='90', format='int') | |
608 | opObj11.addParameter(name='showprofile', value='0', format='int') |
|
608 | opObj11.addParameter(name='showprofile', value='0', format='int') | |
|
609 | opObj11.addParameter(name='save', value='1', format='int') | |||
|
610 | opObj11.addParameter(name='filename', value='/Users/dsuarez/Pictures/SpectraPlot.png', format='str') | |||
609 |
|
611 | |||
610 | opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other') |
|
612 | opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other') | |
611 | opObj11.addParameter(name='idfigure', value='10', format='int') |
|
613 | opObj11.addParameter(name='idfigure', value='10', format='int') | |
612 | opObj11.addParameter(name='wintitle', value='RTI', format='str') |
|
614 | opObj11.addParameter(name='wintitle', value='RTI', format='str') | |
613 | # opObj11.addParameter(name='zmin', value='70', format='int') |
|
615 | # opObj11.addParameter(name='zmin', value='70', format='int') | |
614 | # opObj11.addParameter(name='zmax', value='90', format='int') |
|
616 | # opObj11.addParameter(name='zmax', value='90', format='int') | |
615 | opObj11.addParameter(name='showprofile', value='0', format='int') |
|
617 | opObj11.addParameter(name='showprofile', value='0', format='int') | |
616 |
|
618 | |||
617 | # opObj10 = procUnitConfObj1.addOperation(name='selectChannels') |
|
619 | # opObj10 = procUnitConfObj1.addOperation(name='selectChannels') | |
618 | # opObj10.addParameter(name='channelList', value='0,2,4,6', format='intlist') |
|
620 | # opObj10.addParameter(name='channelList', value='0,2,4,6', format='intlist') | |
619 | # |
|
621 | # | |
620 | # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') |
|
622 | # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') | |
621 | # opObj12.addParameter(name='n', value='2', format='int') |
|
623 | # opObj12.addParameter(name='n', value='2', format='int') | |
622 | # |
|
624 | # | |
623 | # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') |
|
625 | # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') | |
624 | # opObj11.addParameter(name='idfigure', value='2', format='int') |
|
626 | # opObj11.addParameter(name='idfigure', value='2', format='int') | |
625 | # opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str') |
|
627 | # opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str') | |
626 | # opObj11.addParameter(name='zmin', value='70', format='int') |
|
628 | # opObj11.addParameter(name='zmin', value='70', format='int') | |
627 | # opObj11.addParameter(name='zmax', value='90', format='int') |
|
629 | # opObj11.addParameter(name='zmax', value='90', format='int') | |
628 | # |
|
630 | # | |
629 | # opObj10 = procUnitConfObj1.addOperation(name='selectChannels') |
|
631 | # opObj10 = procUnitConfObj1.addOperation(name='selectChannels') | |
630 | # opObj10.addParameter(name='channelList', value='2,6', format='intlist') |
|
632 | # opObj10.addParameter(name='channelList', value='2,6', format='intlist') | |
631 | # |
|
633 | # | |
632 | # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') |
|
634 | # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') | |
633 | # opObj12.addParameter(name='n', value='2', format='int') |
|
635 | # opObj12.addParameter(name='n', value='2', format='int') | |
634 | # |
|
636 | # | |
635 | # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') |
|
637 | # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') | |
636 | # opObj11.addParameter(name='idfigure', value='3', format='int') |
|
638 | # opObj11.addParameter(name='idfigure', value='3', format='int') | |
637 | # opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str') |
|
639 | # opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str') | |
638 | # opObj11.addParameter(name='zmin', value='70', format='int') |
|
640 | # opObj11.addParameter(name='zmin', value='70', format='int') | |
639 | # opObj11.addParameter(name='zmax', value='90', format='int') |
|
641 | # opObj11.addParameter(name='zmax', value='90', format='int') | |
640 |
|
642 | |||
641 |
|
643 | |||
642 | # opObj12 = procUnitConfObj1.addOperation(name='decoder') |
|
644 | # opObj12 = procUnitConfObj1.addOperation(name='decoder') | |
643 | # opObj12.addParameter(name='ncode', value='2', format='int') |
|
645 | # opObj12.addParameter(name='ncode', value='2', format='int') | |
644 | # opObj12.addParameter(name='nbauds', value='8', format='int') |
|
646 | # opObj12.addParameter(name='nbauds', value='8', format='int') | |
645 | # opObj12.addParameter(name='code0', value='001110011', format='int') |
|
647 | # opObj12.addParameter(name='code0', value='001110011', format='int') | |
646 | # opObj12.addParameter(name='code1', value='001110011', format='int') |
|
648 | # opObj12.addParameter(name='code1', value='001110011', format='int') | |
647 |
|
649 | |||
648 |
|
650 | |||
649 |
|
651 | |||
650 | # procUnitConfObj2 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj1.getId()) |
|
652 | # procUnitConfObj2 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj1.getId()) | |
651 | # |
|
653 | # | |
652 | # opObj21 = procUnitConfObj2.addOperation(name='IncohInt', optype='other') |
|
654 | # opObj21 = procUnitConfObj2.addOperation(name='IncohInt', optype='other') | |
653 | # opObj21.addParameter(name='n', value='2', format='int') |
|
655 | # opObj21.addParameter(name='n', value='2', format='int') | |
654 | # |
|
656 | # | |
655 | # opObj11 = procUnitConfObj2.addOperation(name='SpectraPlot', optype='other') |
|
657 | # opObj11 = procUnitConfObj2.addOperation(name='SpectraPlot', optype='other') | |
656 | # opObj11.addParameter(name='idfigure', value='4', format='int') |
|
658 | # opObj11.addParameter(name='idfigure', value='4', format='int') | |
657 | # opObj11.addParameter(name='wintitle', value='SpectraPlot OBJ 2', format='str') |
|
659 | # opObj11.addParameter(name='wintitle', value='SpectraPlot OBJ 2', format='str') | |
658 | # opObj11.addParameter(name='zmin', value='70', format='int') |
|
660 | # opObj11.addParameter(name='zmin', value='70', format='int') | |
659 | # opObj11.addParameter(name='zmax', value='90', format='int') |
|
661 | # opObj11.addParameter(name='zmax', value='90', format='int') | |
660 |
|
662 | |||
661 | print "Escribiendo el archivo XML" |
|
663 | print "Escribiendo el archivo XML" | |
662 |
|
664 | |||
663 | controllerObj.writeXml(filename) |
|
665 | controllerObj.writeXml(filename) | |
664 |
|
666 | |||
665 | print "Leyendo el archivo XML" |
|
667 | print "Leyendo el archivo XML" | |
666 | controllerObj.readXml(filename) |
|
668 | controllerObj.readXml(filename) | |
667 | #controllerObj.printattr() |
|
669 | #controllerObj.printattr() | |
668 |
|
670 | |||
669 | controllerObj.createObjects() |
|
671 | controllerObj.createObjects() | |
670 | controllerObj.connectObjects() |
|
672 | controllerObj.connectObjects() | |
671 | controllerObj.run() |
|
673 | controllerObj.run() | |
672 |
|
674 | |||
673 | No newline at end of file |
|
675 |
@@ -1,256 +1,262 | |||||
1 | import numpy |
|
1 | import numpy | |
2 | import mpldriver |
|
2 | import mpldriver | |
3 |
|
3 | |||
4 |
|
4 | |||
5 | class Figure: |
|
5 | class Figure: | |
6 |
|
6 | |||
7 | __driver = mpldriver |
|
7 | __driver = mpldriver | |
8 | fig = None |
|
8 | fig = None | |
9 |
|
9 | |||
10 | idfigure = None |
|
10 | idfigure = None | |
11 | wintitle = None |
|
11 | wintitle = None | |
12 | width = None |
|
12 | width = None | |
13 | height = None |
|
13 | height = None | |
14 | nplots = None |
|
14 | nplots = None | |
15 |
|
15 | |||
16 | axesObjList = [] |
|
16 | axesObjList = [] | |
17 |
|
17 | |||
18 | WIDTH = None |
|
18 | WIDTH = None | |
19 | HEIGHT = None |
|
19 | HEIGHT = None | |
20 |
|
20 | |||
21 | def __init__(self): |
|
21 | def __init__(self): | |
22 |
|
22 | |||
23 | raise ValueError, "This method is not implemented" |
|
23 | raise ValueError, "This method is not implemented" | |
24 |
|
24 | |||
25 | def __del__(self): |
|
25 | def __del__(self): | |
26 |
|
26 | |||
27 | self.__driver.closeFigure() |
|
27 | self.__driver.closeFigure() | |
28 |
|
28 | |||
29 | def getAxesObjList(self): |
|
29 | def getAxesObjList(self): | |
30 |
|
30 | |||
31 | return self.axesObjList |
|
31 | return self.axesObjList | |
32 |
|
32 | |||
33 | def getSubplots(self): |
|
33 | def getSubplots(self): | |
34 |
|
34 | |||
35 | raise ValueError, "Abstract method: This method should be defined" |
|
35 | raise ValueError, "Abstract method: This method should be defined" | |
36 |
|
36 | |||
37 | def getScreenDim(self): |
|
37 | def getScreenDim(self): | |
38 |
|
38 | |||
39 | nrow, ncol = self.getSubplots() |
|
39 | nrow, ncol = self.getSubplots() | |
40 |
|
40 | |||
41 | width = self.WIDTH*ncol |
|
41 | width = self.WIDTH*ncol | |
42 | height = self.HEIGHT*nrow |
|
42 | height = self.HEIGHT*nrow | |
43 |
|
43 | |||
44 | return width, height |
|
44 | return width, height | |
45 |
|
45 | |||
46 | def init(self, idfigure, nplots, wintitle): |
|
46 | def init(self, idfigure, nplots, wintitle): | |
47 |
|
47 | |||
48 | raise ValueError, "This method has been replaced with createFigure" |
|
48 | raise ValueError, "This method has been replaced with createFigure" | |
49 |
|
49 | |||
50 | def createFigure(self, idfigure, wintitle): |
|
50 | def createFigure(self, idfigure, wintitle): | |
51 |
|
51 | |||
52 | """ |
|
52 | """ | |
53 | Crea la figura de acuerdo al driver y parametros seleccionados seleccionados. |
|
53 | Crea la figura de acuerdo al driver y parametros seleccionados seleccionados. | |
54 | Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH |
|
54 | Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH | |
55 | y self.HEIGHT y el numero de subplots (nrow, ncol) |
|
55 | y self.HEIGHT y el numero de subplots (nrow, ncol) | |
56 |
|
56 | |||
57 | Input: |
|
57 | Input: | |
58 | idfigure : Los parametros necesarios son |
|
58 | idfigure : Los parametros necesarios son | |
59 | wintitle : |
|
59 | wintitle : | |
60 |
|
60 | |||
61 | """ |
|
61 | """ | |
62 |
|
62 | |||
63 | self.idfigure = idfigure |
|
63 | self.idfigure = idfigure | |
64 |
|
64 | |||
65 | self.wintitle = wintitle |
|
65 | self.wintitle = wintitle | |
66 |
|
66 | |||
67 | self.width, self.height = self.getScreenDim() |
|
67 | self.width, self.height = self.getScreenDim() | |
68 |
|
68 | |||
69 | self.fig = self.__driver.createFigure(self.idfigure, |
|
69 | self.fig = self.__driver.createFigure(self.idfigure, | |
70 | self.wintitle, |
|
70 | self.wintitle, | |
71 | self.width, |
|
71 | self.width, | |
72 | self.height) |
|
72 | self.height) | |
73 |
|
73 | |||
74 | self.axesObjList = [] |
|
74 | self.axesObjList = [] | |
75 |
|
75 | |||
76 | def setDriver(self, driver=mpldriver): |
|
76 | def setDriver(self, driver=mpldriver): | |
77 |
|
77 | |||
78 | self.__driver = driver |
|
78 | self.__driver = driver | |
79 |
|
79 | |||
80 | def setTitle(self, title): |
|
80 | def setTitle(self, title): | |
81 |
|
81 | |||
82 | self.__driver.setTitle(self.fig, title) |
|
82 | self.__driver.setTitle(self.fig, title) | |
83 |
|
83 | |||
84 | def setWinTitle(self, title): |
|
84 | def setWinTitle(self, title): | |
85 |
|
85 | |||
86 | self.__driver.setWinTitle(self.fig, title=title) |
|
86 | self.__driver.setWinTitle(self.fig, title=title) | |
87 |
|
87 | |||
88 | def setTextFromAxes(self, text): |
|
88 | def setTextFromAxes(self, text): | |
89 |
|
89 | |||
90 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes" |
|
90 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes" | |
91 |
|
91 | |||
92 | def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan): |
|
92 | def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan): | |
93 |
|
93 | |||
94 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes" |
|
94 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes" | |
95 |
|
95 | |||
96 | def addAxes(self, *args): |
|
96 | def addAxes(self, *args): | |
97 | """ |
|
97 | """ | |
98 |
|
98 | |||
99 | Input: |
|
99 | Input: | |
100 | *args : Los parametros necesarios son |
|
100 | *args : Los parametros necesarios son | |
101 | nrow, ncol, xpos, ypos, colspan, rowspan |
|
101 | nrow, ncol, xpos, ypos, colspan, rowspan | |
102 | """ |
|
102 | """ | |
103 |
|
103 | |||
104 | axesObj = Axes(self.fig, *args) |
|
104 | axesObj = Axes(self.fig, *args) | |
105 | self.axesObjList.append(axesObj) |
|
105 | self.axesObjList.append(axesObj) | |
106 |
|
106 | |||
|
107 | def saveFigure(self, *args): | |||
|
108 | self.__driver.saveFigure(self.fig, *args) | |||
|
109 | ||||
107 | def draw(self): |
|
110 | def draw(self): | |
108 |
|
111 | |||
109 | self.__driver.draw(self.fig) |
|
112 | self.__driver.draw(self.fig) | |
110 |
|
113 | |||
111 | def run(self): |
|
114 | def run(self): | |
112 |
|
115 | |||
113 | raise ValueError, "This method is not implemented" |
|
116 | raise ValueError, "This method is not implemented" | |
114 |
|
117 | |||
115 | axesList = property(getAxesObjList) |
|
118 | axesList = property(getAxesObjList) | |
116 |
|
119 | |||
117 |
|
120 | |||
118 | class Axes: |
|
121 | class Axes: | |
119 |
|
122 | |||
120 | __driver = mpldriver |
|
123 | __driver = mpldriver | |
121 | fig = None |
|
124 | fig = None | |
122 | ax = None |
|
125 | ax = None | |
123 | plot = None |
|
126 | plot = None | |
124 |
|
127 | |||
125 | firsttime = None |
|
128 | firsttime = None | |
126 |
|
129 | |||
127 | __showprofile = False |
|
130 | __showprofile = False | |
128 |
|
131 | |||
129 | __zmin = None |
|
132 | __zmin = None | |
130 | __zmax = None |
|
133 | __zmax = None | |
131 |
|
134 | |||
132 | def __init__(self, *args): |
|
135 | def __init__(self, *args): | |
133 |
|
136 | |||
134 | """ |
|
137 | """ | |
135 |
|
138 | |||
136 | Input: |
|
139 | Input: | |
137 | *args : Los parametros necesarios son |
|
140 | *args : Los parametros necesarios son | |
138 | fig, nrow, ncol, xpos, ypos, colspan, rowspan |
|
141 | fig, nrow, ncol, xpos, ypos, colspan, rowspan | |
139 | """ |
|
142 | """ | |
140 |
|
143 | |||
141 | ax = self.__driver.createAxes(*args) |
|
144 | ax = self.__driver.createAxes(*args) | |
142 | self.fig = args[0] |
|
145 | self.fig = args[0] | |
143 | self.ax = ax |
|
146 | self.ax = ax | |
144 | self.plot = None |
|
147 | self.plot = None | |
145 |
|
148 | |||
146 | self.firsttime = True |
|
149 | self.firsttime = True | |
147 |
|
150 | |||
148 | def setText(self, text): |
|
151 | def setText(self, text): | |
149 |
|
152 | |||
150 | self.__driver.setAxesText(self.ax, text) |
|
153 | self.__driver.setAxesText(self.ax, text) | |
151 |
|
154 | |||
|
155 | def setXAxisAsTime(self): | |||
|
156 | pass | |||
|
157 | ||||
152 | def pline(self, x, y, |
|
158 | def pline(self, x, y, | |
153 | xmin=None, xmax=None, |
|
159 | xmin=None, xmax=None, | |
154 | ymin=None, ymax=None, |
|
160 | ymin=None, ymax=None, | |
155 | xlabel='', ylabel='', |
|
161 | xlabel='', ylabel='', | |
156 | title='', |
|
162 | title='', | |
157 | **kwargs): |
|
163 | **kwargs): | |
158 |
|
164 | |||
159 | """ |
|
165 | """ | |
160 |
|
166 | |||
161 | Input: |
|
167 | Input: | |
162 | x : |
|
168 | x : | |
163 | y : |
|
169 | y : | |
164 | xmin : |
|
170 | xmin : | |
165 | xmax : |
|
171 | xmax : | |
166 | ymin : |
|
172 | ymin : | |
167 | ymax : |
|
173 | ymax : | |
168 | xlabel : |
|
174 | xlabel : | |
169 | ylabel : |
|
175 | ylabel : | |
170 | title : |
|
176 | title : | |
171 | **kwargs : Los parametros aceptados son |
|
177 | **kwargs : Los parametros aceptados son | |
172 |
|
178 | |||
173 | ticksize |
|
179 | ticksize | |
174 | ytick_visible |
|
180 | ytick_visible | |
175 | """ |
|
181 | """ | |
176 |
|
182 | |||
177 | if self.firsttime: |
|
183 | if self.firsttime: | |
178 |
|
184 | |||
179 | if xmin == None: xmin = numpy.nanmin(x) |
|
185 | if xmin == None: xmin = numpy.nanmin(x) | |
180 | if xmax == None: xmax = numpy.nanmax(x) |
|
186 | if xmax == None: xmax = numpy.nanmax(x) | |
181 | if ymin == None: ymin = numpy.nanmin(y) |
|
187 | if ymin == None: ymin = numpy.nanmin(y) | |
182 | if ymax == None: ymax = numpy.nanmax(y) |
|
188 | if ymax == None: ymax = numpy.nanmax(y) | |
183 |
|
189 | |||
184 | self.plot = self.__driver.createPline(self.ax, x, y, |
|
190 | self.plot = self.__driver.createPline(self.ax, x, y, | |
185 | xmin, xmax, |
|
191 | xmin, xmax, | |
186 | ymin, ymax, |
|
192 | ymin, ymax, | |
187 | xlabel=xlabel, |
|
193 | xlabel=xlabel, | |
188 | ylabel=ylabel, |
|
194 | ylabel=ylabel, | |
189 | title=title, |
|
195 | title=title, | |
190 | **kwargs) |
|
196 | **kwargs) | |
191 | self.firsttime = False |
|
197 | self.firsttime = False | |
192 | return |
|
198 | return | |
193 |
|
199 | |||
194 | self.__driver.pline(self.plot, x, y, xlabel=xlabel, |
|
200 | self.__driver.pline(self.plot, x, y, xlabel=xlabel, | |
195 | ylabel=ylabel, |
|
201 | ylabel=ylabel, | |
196 | title=title) |
|
202 | title=title) | |
197 |
|
203 | |||
198 |
|
204 | |||
199 | def pcolor(self, x, y, z, |
|
205 | def pcolor(self, x, y, z, | |
200 | xmin=None, xmax=None, |
|
206 | xmin=None, xmax=None, | |
201 | ymin=None, ymax=None, |
|
207 | ymin=None, ymax=None, | |
202 | zmin=None, zmax=None, |
|
208 | zmin=None, zmax=None, | |
203 | xlabel='', ylabel='', |
|
209 | xlabel='', ylabel='', | |
204 | title='', rti = False, |
|
210 | title='', rti = False, | |
205 | **kwargs): |
|
211 | **kwargs): | |
206 |
|
212 | |||
207 | """ |
|
213 | """ | |
208 | Input: |
|
214 | Input: | |
209 | x : |
|
215 | x : | |
210 | y : |
|
216 | y : | |
211 | x : |
|
217 | x : | |
212 | xmin : |
|
218 | xmin : | |
213 | xmax : |
|
219 | xmax : | |
214 | ymin : |
|
220 | ymin : | |
215 | ymax : |
|
221 | ymax : | |
216 | zmin : |
|
222 | zmin : | |
217 | zmax : |
|
223 | zmax : | |
218 | xlabel : |
|
224 | xlabel : | |
219 | ylabel : |
|
225 | ylabel : | |
220 | title : |
|
226 | title : | |
221 | **kwargs : Los parametros aceptados son |
|
227 | **kwargs : Los parametros aceptados son | |
222 | ticksize=9, |
|
228 | ticksize=9, | |
223 | cblabel='' |
|
229 | cblabel='' | |
224 | rti = True or False |
|
230 | rti = True or False | |
225 | """ |
|
231 | """ | |
226 |
|
232 | |||
227 | if self.firsttime: |
|
233 | if self.firsttime: | |
228 |
|
234 | |||
229 | if xmin == None: xmin = numpy.nanmin(x) |
|
235 | if xmin == None: xmin = numpy.nanmin(x) | |
230 | if xmax == None: xmax = numpy.nanmax(x) |
|
236 | if xmax == None: xmax = numpy.nanmax(x) | |
231 | if ymin == None: ymin = numpy.nanmin(y) |
|
237 | if ymin == None: ymin = numpy.nanmin(y) | |
232 | if ymax == None: ymax = numpy.nanmax(y) |
|
238 | if ymax == None: ymax = numpy.nanmax(y) | |
233 | if zmin == None: zmin = numpy.nanmin(z) |
|
239 | if zmin == None: zmin = numpy.nanmin(z) | |
234 | if zmax == None: zmax = numpy.nanmax(z) |
|
240 | if zmax == None: zmax = numpy.nanmax(z) | |
235 |
|
241 | |||
236 |
|
242 | |||
237 | self.plot = self.__driver.createPcolor(self.ax, x, y, z, |
|
243 | self.plot = self.__driver.createPcolor(self.ax, x, y, z, | |
238 | xmin, xmax, |
|
244 | xmin, xmax, | |
239 | ymin, ymax, |
|
245 | ymin, ymax, | |
240 | zmin, zmax, |
|
246 | zmin, zmax, | |
241 | xlabel=xlabel, |
|
247 | xlabel=xlabel, | |
242 | ylabel=ylabel, |
|
248 | ylabel=ylabel, | |
243 | title=title, |
|
249 | title=title, | |
244 | **kwargs) |
|
250 | **kwargs) | |
245 | self.firsttime = False |
|
251 | self.firsttime = False | |
246 | if self.__zmin == None: self.__zmin = zmin |
|
252 | if self.__zmin == None: self.__zmin = zmin | |
247 | if self.__zmax == None: self.__zmax = zmax |
|
253 | if self.__zmax == None: self.__zmax = zmax | |
248 | return |
|
254 | return | |
249 |
|
255 | |||
250 | if rti: |
|
256 | if rti: | |
251 | self.__driver.addpcolor(self.ax, x, y, z, self.__zmin, self.__zmax) |
|
257 | self.__driver.addpcolor(self.ax, x, y, z, self.__zmin, self.__zmax) | |
252 | return |
|
258 | return | |
253 |
|
259 | |||
254 | self.__driver.pcolor(self.plot, z, xlabel=xlabel, ylabel=ylabel, title=title) |
|
260 | self.__driver.pcolor(self.plot, z, xlabel=xlabel, ylabel=ylabel, title=title) | |
255 |
|
261 | |||
256 | No newline at end of file |
|
262 |
@@ -1,250 +1,272 | |||||
1 | import numpy |
|
1 | import numpy | |
|
2 | import datetime | |||
2 | import matplotlib |
|
3 | import matplotlib | |
3 | matplotlib.use("TKAgg") |
|
4 | matplotlib.use("TKAgg") | |
4 | import matplotlib.pyplot |
|
5 | import matplotlib.pyplot | |
|
6 | import matplotlib.dates | |||
5 | #import scitools.numpyutils |
|
7 | #import scitools.numpyutils | |
6 | from mpl_toolkits.axes_grid1 import make_axes_locatable |
|
8 | from mpl_toolkits.axes_grid1 import make_axes_locatable | |
7 |
|
9 | |||
|
10 | from matplotlib.dates import DayLocator, HourLocator, MinuteLocator, SecondLocator, DateFormatter | |||
|
11 | ||||
8 | def init(idfigure, wintitle, width, height, facecolor="w"): |
|
12 | def init(idfigure, wintitle, width, height, facecolor="w"): | |
9 |
|
13 | |||
10 | matplotlib.pyplot.ioff() |
|
14 | matplotlib.pyplot.ioff() | |
11 | fig = matplotlib.pyplot.matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor) |
|
15 | fig = matplotlib.pyplot.matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor) | |
12 | fig.canvas.manager.set_window_title(wintitle) |
|
16 | fig.canvas.manager.set_window_title(wintitle) | |
13 | fig.canvas.manager.resize(width, height) |
|
17 | fig.canvas.manager.resize(width, height) | |
14 | matplotlib.pyplot.ion() |
|
18 | matplotlib.pyplot.ion() | |
15 |
|
19 | |||
16 | return fig |
|
20 | return fig | |
17 |
|
21 | |||
18 | def setWinTitle(fig, title): |
|
22 | def setWinTitle(fig, title): | |
19 |
|
23 | |||
20 | fig.canvas.manager.set_window_title(title) |
|
24 | fig.canvas.manager.set_window_title(title) | |
21 |
|
25 | |||
22 | def setTitle(idfigure, title): |
|
26 | def setTitle(idfigure, title): | |
23 | fig = matplotlib.pyplot.figure(idfigure) |
|
27 | fig = matplotlib.pyplot.figure(idfigure) | |
24 | fig.suptitle(title) |
|
28 | fig.suptitle(title) | |
25 |
|
29 | |||
26 | def makeAxes(idfigure, nrow, ncol, xpos, ypos, colspan, rowspan): |
|
30 | def makeAxes(idfigure, nrow, ncol, xpos, ypos, colspan, rowspan): | |
27 | fig = matplotlib.pyplot.figure(idfigure) |
|
31 | fig = matplotlib.pyplot.figure(idfigure) | |
28 | ax = matplotlib.pyplot.subplot2grid((nrow, ncol), (xpos, ypos), colspan=colspan, rowspan=rowspan) |
|
32 | ax = matplotlib.pyplot.subplot2grid((nrow, ncol), (xpos, ypos), colspan=colspan, rowspan=rowspan) | |
29 | return ax |
|
33 | return ax | |
30 |
|
34 | |||
31 | def setTextFromAxes(idfigure, ax, title): |
|
35 | def setTextFromAxes(idfigure, ax, title): | |
32 | fig = matplotlib.pyplot.figure(idfigure) |
|
36 | fig = matplotlib.pyplot.figure(idfigure) | |
33 | ax.annotate(title, xy=(.1, .99), |
|
37 | ax.annotate(title, xy=(.1, .99), | |
34 | xycoords='figure fraction', |
|
38 | xycoords='figure fraction', | |
35 | horizontalalignment='left', verticalalignment='top', |
|
39 | horizontalalignment='left', verticalalignment='top', | |
36 | fontsize=10) |
|
40 | fontsize=10) | |
37 |
|
41 | |||
38 | def pline(ax, x, y, xmin, xmax, ymin, ymax, xlabel, ylabel, title, firsttime): |
|
42 | def pline(ax, x, y, xmin, xmax, ymin, ymax, xlabel, ylabel, title, firsttime): | |
39 |
|
43 | |||
40 | if firsttime: |
|
44 | if firsttime: | |
41 | ax.plot(x, y) |
|
45 | ax.plot(x, y) | |
42 | ax.set_xlim([xmin,xmax]) |
|
46 | ax.set_xlim([xmin,xmax]) | |
43 | ax.set_ylim([ymin,ymax]) |
|
47 | ax.set_ylim([ymin,ymax]) | |
44 | ax.set_xlabel(xlabel, size=8) |
|
48 | ax.set_xlabel(xlabel, size=8) | |
45 | ax.set_ylabel(ylabel, size=8) |
|
49 | ax.set_ylabel(ylabel, size=8) | |
46 | ax.set_title(title, size=10) |
|
50 | ax.set_title(title, size=10) | |
47 | matplotlib.pyplot.tight_layout() |
|
51 | matplotlib.pyplot.tight_layout() | |
48 | else: |
|
52 | else: | |
49 | ax.lines[0].set_data(x,y) |
|
53 | ax.lines[0].set_data(x,y) | |
50 |
|
54 | |||
51 | def draw(idfigure): |
|
55 | def draw(idfigure): | |
52 |
|
56 | |||
53 | fig = matplotlib.pyplot.figure(idfigure) |
|
57 | fig = matplotlib.pyplot.figure(idfigure) | |
54 | fig.canvas.draw() |
|
58 | fig.canvas.draw() | |
55 |
|
59 | |||
56 | def pcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel, ylabel, title, firsttime, mesh): |
|
60 | def pcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel, ylabel, title, firsttime, mesh): | |
57 |
|
61 | |||
58 | if firsttime: |
|
62 | if firsttime: | |
59 | divider = make_axes_locatable(ax) |
|
63 | divider = make_axes_locatable(ax) | |
60 | ax_cb = divider.new_horizontal(size="4%", pad=0.05) |
|
64 | ax_cb = divider.new_horizontal(size="4%", pad=0.05) | |
61 | fig1 = ax.get_figure() |
|
65 | fig1 = ax.get_figure() | |
62 | fig1.add_axes(ax_cb) |
|
66 | fig1.add_axes(ax_cb) | |
63 |
|
67 | |||
64 | ax.set_xlim([xmin,xmax]) |
|
68 | ax.set_xlim([xmin,xmax]) | |
65 | ax.set_ylim([ymin,ymax]) |
|
69 | ax.set_ylim([ymin,ymax]) | |
66 | ax.set_xlabel(xlabel) |
|
70 | ax.set_xlabel(xlabel) | |
67 | ax.set_ylabel(ylabel) |
|
71 | ax.set_ylabel(ylabel) | |
68 | ax.set_title(title) |
|
72 | ax.set_title(title) | |
69 | print x |
|
73 | print x | |
70 | imesh=ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax) |
|
74 | imesh=ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax) | |
71 | matplotlib.pyplot.colorbar(imesh, cax=ax_cb) |
|
75 | matplotlib.pyplot.colorbar(imesh, cax=ax_cb) | |
72 | ax_cb.yaxis.tick_right() |
|
76 | ax_cb.yaxis.tick_right() | |
73 | for tl in ax_cb.get_yticklabels(): |
|
77 | for tl in ax_cb.get_yticklabels(): | |
74 | tl.set_visible(True) |
|
78 | tl.set_visible(True) | |
75 | ax_cb.yaxis.tick_right() |
|
79 | ax_cb.yaxis.tick_right() | |
76 | matplotlib.pyplot.tight_layout() |
|
80 | matplotlib.pyplot.tight_layout() | |
77 | return imesh |
|
81 | return imesh | |
78 | else: |
|
82 | else: | |
79 | # ax.set_xlim([xmin,xmax]) |
|
83 | # ax.set_xlim([xmin,xmax]) | |
80 | # ax.set_ylim([ymin,ymax]) |
|
84 | # ax.set_ylim([ymin,ymax]) | |
81 | ax.set_xlabel(xlabel) |
|
85 | ax.set_xlabel(xlabel) | |
82 | ax.set_ylabel(ylabel) |
|
86 | ax.set_ylabel(ylabel) | |
83 | ax.set_title(title) |
|
87 | ax.set_title(title) | |
84 |
|
88 | |||
85 | z = z.T |
|
89 | z = z.T | |
86 | # z = z[0:-1,0:-1] |
|
90 | # z = z[0:-1,0:-1] | |
87 | mesh.set_array(z.ravel()) |
|
91 | mesh.set_array(z.ravel()) | |
88 |
|
92 | |||
89 | return mesh |
|
93 | return mesh | |
90 |
|
94 | |||
91 | ########################################### |
|
95 | ########################################### | |
92 | #Actualizacion de las funciones del driver |
|
96 | #Actualizacion de las funciones del driver | |
93 | ########################################### |
|
97 | ########################################### | |
94 |
|
98 | |||
95 | def createFigure(idfigure, wintitle, width, height, facecolor="w"): |
|
99 | def createFigure(idfigure, wintitle, width, height, facecolor="w"): | |
96 |
|
100 | |||
97 | matplotlib.pyplot.ioff() |
|
101 | matplotlib.pyplot.ioff() | |
98 | fig = matplotlib.pyplot.matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor) |
|
102 | fig = matplotlib.pyplot.matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor) | |
99 | fig.canvas.manager.set_window_title(wintitle) |
|
103 | fig.canvas.manager.set_window_title(wintitle) | |
100 | fig.canvas.manager.resize(width, height) |
|
104 | fig.canvas.manager.resize(width, height) | |
101 | matplotlib.pyplot.ion() |
|
105 | matplotlib.pyplot.ion() | |
102 |
|
106 | |||
103 | return fig |
|
107 | return fig | |
104 |
|
108 | |||
105 | def closeFigure(): |
|
109 | def closeFigure(): | |
106 |
|
110 | |||
107 | matplotlib.pyplot.ioff() |
|
111 | matplotlib.pyplot.ioff() | |
108 | matplotlib.pyplot.show() |
|
112 | matplotlib.pyplot.show() | |
109 |
|
113 | |||
110 | return |
|
114 | return | |
111 |
|
115 | |||
|
116 | def saveFigure(fig, filename): | |||
|
117 | fig.savefig(filename) | |||
|
118 | ||||
112 | def setWinTitle(fig, title): |
|
119 | def setWinTitle(fig, title): | |
113 |
|
120 | |||
114 | fig.canvas.manager.set_window_title(title) |
|
121 | fig.canvas.manager.set_window_title(title) | |
115 |
|
122 | |||
116 | def setTitle(fig, title): |
|
123 | def setTitle(fig, title): | |
117 |
|
124 | |||
118 | fig.suptitle(title) |
|
125 | fig.suptitle(title) | |
119 |
|
126 | |||
120 | def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan): |
|
127 | def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan): | |
121 |
|
128 | |||
122 | matplotlib.pyplot.figure(fig.number) |
|
129 | matplotlib.pyplot.figure(fig.number) | |
123 | axes = matplotlib.pyplot.subplot2grid((nrow, ncol), |
|
130 | axes = matplotlib.pyplot.subplot2grid((nrow, ncol), | |
124 | (xpos, ypos), |
|
131 | (xpos, ypos), | |
125 | colspan=colspan, |
|
132 | colspan=colspan, | |
126 | rowspan=rowspan) |
|
133 | rowspan=rowspan) | |
127 | return axes |
|
134 | return axes | |
128 |
|
135 | |||
129 | def setAxesText(ax, text): |
|
136 | def setAxesText(ax, text): | |
130 |
|
137 | |||
131 | ax.annotate(text, |
|
138 | ax.annotate(text, | |
132 | xy = (.1, .99), |
|
139 | xy = (.1, .99), | |
133 | xycoords = 'figure fraction', |
|
140 | xycoords = 'figure fraction', | |
134 | horizontalalignment = 'left', |
|
141 | horizontalalignment = 'left', | |
135 | verticalalignment = 'top', |
|
142 | verticalalignment = 'top', | |
136 | fontsize = 10) |
|
143 | fontsize = 10) | |
137 |
|
144 | |||
138 | def printLabels(ax, xlabel, ylabel, title): |
|
145 | def printLabels(ax, xlabel, ylabel, title): | |
139 |
|
146 | |||
140 | ax.set_xlabel(xlabel, size=11) |
|
147 | ax.set_xlabel(xlabel, size=11) | |
141 | ax.set_ylabel(ylabel, size=11) |
|
148 | ax.set_ylabel(ylabel, size=11) | |
142 | ax.set_title(title, size=12) |
|
149 | ax.set_title(title, size=12) | |
143 |
|
150 | |||
144 | def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', |
|
151 | def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', | |
145 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
152 | ticksize=9, xtick_visible=True, ytick_visible=True, | |
146 | nxticks=4, nyticks=10, |
|
153 | nxticks=4, nyticks=10, | |
147 | grid=None): |
|
154 | grid=None): | |
148 |
|
155 | |||
149 | """ |
|
156 | """ | |
150 |
|
157 | |||
151 | Input: |
|
158 | Input: | |
152 | grid : None, 'both', 'x', 'y' |
|
159 | grid : None, 'both', 'x', 'y' | |
153 | """ |
|
160 | """ | |
154 |
|
161 | |||
155 | ax.plot(x, y) |
|
162 | ax.plot(x, y) | |
156 | ax.set_xlim([xmin,xmax]) |
|
163 | ax.set_xlim([xmin,xmax]) | |
157 | ax.set_ylim([ymin,ymax]) |
|
164 | ax.set_ylim([ymin,ymax]) | |
158 |
|
165 | |||
159 | printLabels(ax, xlabel, ylabel, title) |
|
166 | printLabels(ax, xlabel, ylabel, title) | |
160 |
|
167 | |||
161 | ###################################################### |
|
168 | ###################################################### | |
162 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/nxticks) + int(xmin) |
|
169 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/nxticks) + int(xmin) | |
163 | ax.set_xticks(xtickspos) |
|
170 | ax.set_xticks(xtickspos) | |
164 |
|
171 | |||
165 | for tick in ax.get_xticklabels(): |
|
172 | for tick in ax.get_xticklabels(): | |
166 | tick.set_visible(xtick_visible) |
|
173 | tick.set_visible(xtick_visible) | |
167 |
|
174 | |||
168 | for tick in ax.xaxis.get_major_ticks(): |
|
175 | for tick in ax.xaxis.get_major_ticks(): | |
169 | tick.label.set_fontsize(ticksize) |
|
176 | tick.label.set_fontsize(ticksize) | |
170 |
|
177 | |||
171 | ###################################################### |
|
178 | ###################################################### | |
172 | for tick in ax.get_yticklabels(): |
|
179 | for tick in ax.get_yticklabels(): | |
173 | tick.set_visible(ytick_visible) |
|
180 | tick.set_visible(ytick_visible) | |
174 |
|
181 | |||
175 | for tick in ax.yaxis.get_major_ticks(): |
|
182 | for tick in ax.yaxis.get_major_ticks(): | |
176 | tick.label.set_fontsize(ticksize) |
|
183 | tick.label.set_fontsize(ticksize) | |
177 |
|
184 | |||
178 | ###################################################### |
|
185 | ###################################################### | |
179 | if grid != None: |
|
186 | if grid != None: | |
180 | ax.grid(b=True, which='major', axis=grid) |
|
187 | ax.grid(b=True, which='major', axis=grid) | |
181 |
|
188 | |||
182 | matplotlib.pyplot.tight_layout() |
|
189 | matplotlib.pyplot.tight_layout() | |
183 |
|
190 | |||
184 | iplot = ax.lines[-1] |
|
191 | iplot = ax.lines[-1] | |
185 |
|
192 | |||
186 | return iplot |
|
193 | return iplot | |
187 |
|
194 | |||
188 | def pline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
195 | def pline(iplot, x, y, xlabel='', ylabel='', title=''): | |
189 |
|
196 | |||
190 | ax = iplot.get_axes() |
|
197 | ax = iplot.get_axes() | |
191 |
|
198 | |||
192 | printLabels(ax, xlabel, ylabel, title) |
|
199 | printLabels(ax, xlabel, ylabel, title) | |
193 |
|
200 | |||
194 | iplot.set_data(x, y) |
|
201 | iplot.set_data(x, y) | |
195 |
|
202 | |||
196 | def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel='', ylabel='', title='', ticksize = 9, cblabel=''): |
|
203 | def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel='', ylabel='', title='', ticksize = 9, cblabel='',XAxisAsTime=False): | |
197 |
|
204 | |||
198 | divider = make_axes_locatable(ax) |
|
205 | divider = make_axes_locatable(ax) | |
199 | ax_cb = divider.new_horizontal(size="4%", pad=0.05) |
|
206 | ax_cb = divider.new_horizontal(size="4%", pad=0.05) | |
200 | fig = ax.get_figure() |
|
207 | fig = ax.get_figure() | |
201 | fig.add_axes(ax_cb) |
|
208 | fig.add_axes(ax_cb) | |
202 |
|
209 | |||
203 | ax.set_xlim([xmin,xmax]) |
|
210 | ax.set_xlim([xmin,xmax]) | |
|
211 | ||||
|
212 | if XAxisAsTime: | |||
|
213 | seconds = numpy.array([xmin, xmax]) | |||
|
214 | datesList = map(datetime.datetime.fromtimestamp, seconds) | |||
|
215 | ax.set_xlim([datesList[0],datesList[-1]]) | |||
|
216 | ax.xaxis.set_major_locator(MinuteLocator(numpy.arange(0,61,10))) | |||
|
217 | ax.xaxis.set_minor_locator(SecondLocator(numpy.arange(0,61,60))) | |||
|
218 | ax.xaxis.set_major_formatter(DateFormatter("%H:%M:%S")) | |||
|
219 | xdateList = map(datetime.datetime.fromtimestamp, x) | |||
|
220 | xdate = matplotlib.dates.date2num(xdateList) | |||
|
221 | x = xdate | |||
|
222 | ||||
|
223 | ||||
204 | ax.set_ylim([ymin,ymax]) |
|
224 | ax.set_ylim([ymin,ymax]) | |
205 |
|
225 | |||
206 | printLabels(ax, xlabel, ylabel, title) |
|
226 | printLabels(ax, xlabel, ylabel, title) | |
207 |
|
227 | |||
208 | imesh = ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax) |
|
228 | imesh = ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax) | |
209 | cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb) |
|
229 | cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb) | |
210 | cb.set_label(cblabel) |
|
230 | cb.set_label(cblabel) | |
211 |
|
231 | |||
212 | ax_cb.yaxis.tick_right() |
|
232 | ax_cb.yaxis.tick_right() | |
213 |
|
233 | |||
214 | for tl in ax_cb.get_yticklabels(): |
|
234 | for tl in ax_cb.get_yticklabels(): | |
215 | tl.set_visible(True) |
|
235 | tl.set_visible(True) | |
216 |
|
236 | |||
217 | for tick in ax.yaxis.get_major_ticks(): |
|
237 | for tick in ax.yaxis.get_major_ticks(): | |
218 | tick.label.set_fontsize(ticksize) |
|
238 | tick.label.set_fontsize(ticksize) | |
219 |
|
239 | |||
220 | for tick in ax.xaxis.get_major_ticks(): |
|
240 | for tick in ax.xaxis.get_major_ticks(): | |
221 | tick.label.set_fontsize(ticksize) |
|
241 | tick.label.set_fontsize(ticksize) | |
222 |
|
242 | |||
223 | for tick in cb.ax.get_yticklabels(): |
|
243 | for tick in cb.ax.get_yticklabels(): | |
224 | tick.set_fontsize(ticksize) |
|
244 | tick.set_fontsize(ticksize) | |
225 |
|
245 | |||
226 | ax_cb.yaxis.tick_right() |
|
246 | ax_cb.yaxis.tick_right() | |
227 | matplotlib.pyplot.tight_layout() |
|
247 | matplotlib.pyplot.tight_layout() | |
228 |
|
248 | |||
229 | return imesh |
|
249 | return imesh | |
230 |
|
250 | |||
231 | def pcolor(imesh, z, xlabel='', ylabel='', title=''): |
|
251 | def pcolor(imesh, z, xlabel='', ylabel='', title=''): | |
232 |
|
252 | |||
233 | z = z.T |
|
253 | z = z.T | |
234 |
|
254 | |||
235 | ax = imesh.get_axes() |
|
255 | ax = imesh.get_axes() | |
236 |
|
256 | |||
237 | printLabels(ax, xlabel, ylabel, title) |
|
257 | printLabels(ax, xlabel, ylabel, title) | |
238 |
|
258 | |||
239 | imesh.set_array(z.ravel()) |
|
259 | imesh.set_array(z.ravel()) | |
240 |
|
260 | |||
241 | def addpcolor(ax, x, y, z, zmin, zmax): |
|
261 | def addpcolor(ax, x, y, z, zmin, zmax): | |
|
262 | xdateList = map(datetime.datetime.fromtimestamp, x) | |||
|
263 | xdate = matplotlib.dates.date2num(xdateList) | |||
242 |
|
264 | |||
243 | imesh = ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax) |
|
265 | imesh = ax.pcolormesh(xdate,y,z.T,vmin=zmin,vmax=zmax) | |
244 |
|
266 | |||
245 | def draw(fig): |
|
267 | def draw(fig): | |
246 |
|
268 | |||
247 | if type(fig) == 'int': |
|
269 | if type(fig) == 'int': | |
248 | raise ValueError, "This parameter should be of tpye matplotlib figure" |
|
270 | raise ValueError, "This parameter should be of tpye matplotlib figure" | |
249 |
|
271 | |||
250 | fig.canvas.draw() No newline at end of file |
|
272 | fig.canvas.draw() |
@@ -1,364 +1,371 | |||||
1 | import numpy |
|
1 | import numpy | |
2 | import datetime |
|
2 | import datetime | |
3 | from graphics.figure import * |
|
3 | from graphics.figure import * | |
4 |
|
4 | |||
5 | class RTIPlot(Figure): |
|
5 | class RTIPlot(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 |
|
12 | |||
13 | def __init__(self): |
|
13 | def __init__(self): | |
14 |
|
14 | |||
15 | self.__timerange = 30*60 |
|
15 | self.__timerange = 30*60 | |
16 | self.__isConfig = False |
|
16 | self.__isConfig = False | |
17 | self.__nsubplots = 1 |
|
17 | self.__nsubplots = 1 | |
18 |
|
18 | |||
19 | self.WIDTH = 800 |
|
19 | self.WIDTH = 800 | |
20 | self.HEIGHT = 400 |
|
20 | self.HEIGHT = 400 | |
21 | self.WIDTHPROF = 120 |
|
21 | self.WIDTHPROF = 120 | |
22 | self.HEIGHTPROF = 0 |
|
22 | self.HEIGHTPROF = 0 | |
23 |
|
23 | |||
24 | def getSubplots(self): |
|
24 | def getSubplots(self): | |
25 |
|
25 | |||
26 | ncol = 1 |
|
26 | ncol = 1 | |
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 | if showprofile: |
|
38 | if showprofile: | |
39 | ncolspan = 7 |
|
39 | ncolspan = 7 | |
40 | colspan = 6 |
|
40 | colspan = 6 | |
41 | self.__nsubplots = 2 |
|
41 | self.__nsubplots = 2 | |
42 | self.WIDTH += self.WIDTHPROF |
|
42 | self.WIDTH += self.WIDTHPROF | |
43 | self.HEIGHT += self.HEIGHTPROF |
|
43 | self.HEIGHT += self.HEIGHTPROF | |
44 |
|
44 | |||
45 | self.createFigure(idfigure, wintitle) |
|
45 | self.createFigure(idfigure, wintitle) | |
46 |
|
46 | |||
47 | nrow, ncol = self.getSubplots() |
|
47 | nrow, ncol = self.getSubplots() | |
48 |
|
48 | |||
49 | counter = 0 |
|
49 | counter = 0 | |
50 | for y in range(nrow): |
|
50 | for y in range(nrow): | |
51 | for x in range(ncol): |
|
51 | for x in range(ncol): | |
52 |
|
52 | |||
53 | if counter >= self.nplots: |
|
53 | if counter >= self.nplots: | |
54 | break |
|
54 | break | |
55 |
|
55 | |||
56 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
56 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
57 |
|
57 | |||
58 | if showprofile: |
|
58 | if showprofile: | |
59 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
59 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
60 |
|
60 | |||
61 | counter += 1 |
|
61 | counter += 1 | |
62 |
|
62 | |||
63 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
63 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', | |
64 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): |
|
64 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, save=False, filename=None): | |
65 |
|
65 | |||
66 | """ |
|
66 | """ | |
67 |
|
67 | |||
68 | Input: |
|
68 | Input: | |
69 | dataOut : |
|
69 | dataOut : | |
70 | idfigure : |
|
70 | idfigure : | |
71 | wintitle : |
|
71 | wintitle : | |
72 | channelList : |
|
72 | channelList : | |
73 | showProfile : |
|
73 | showProfile : | |
74 | xmin : None, |
|
74 | xmin : None, | |
75 | xmax : None, |
|
75 | xmax : None, | |
76 | ymin : None, |
|
76 | ymin : None, | |
77 | ymax : None, |
|
77 | ymax : None, | |
78 | zmin : None, |
|
78 | zmin : None, | |
79 | zmax : None |
|
79 | zmax : None | |
80 | """ |
|
80 | """ | |
81 |
|
81 | |||
82 | if channelList == None: |
|
82 | if channelList == None: | |
83 | channelIndexList = dataOut.channelIndexList |
|
83 | channelIndexList = dataOut.channelIndexList | |
84 | else: |
|
84 | else: | |
85 | channelIndexList = [] |
|
85 | channelIndexList = [] | |
86 | for channel in channelList: |
|
86 | for channel in channelList: | |
87 | if channel not in dataOut.channelList: |
|
87 | if channel not in dataOut.channelList: | |
88 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
88 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
89 | channelIndexList.append(channel) |
|
89 | channelIndexList.append(channel) | |
90 |
|
90 | |||
91 | x = dataOut.getDatatime() |
|
91 | x = dataOut.getDatatime() | |
92 | y = dataOut.getHeiRange() |
|
92 | y = dataOut.getHeiRange() | |
93 | z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:]) |
|
93 | z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:]) | |
94 | avg = numpy.average(z, axis=1) |
|
94 | avg = numpy.average(z, axis=1) | |
95 |
|
95 | |||
96 | noise = dataOut.getNoise() |
|
96 | noise = dataOut.getNoise() | |
97 |
|
97 | |||
98 | if not self.__isConfig: |
|
98 | if not self.__isConfig: | |
99 |
|
99 | |||
100 | nplots = len(channelIndexList) |
|
100 | nplots = len(channelIndexList) | |
101 |
|
101 | |||
102 | self.setup(idfigure=idfigure, |
|
102 | self.setup(idfigure=idfigure, | |
103 | nplots=nplots, |
|
103 | nplots=nplots, | |
104 | wintitle=wintitle, |
|
104 | wintitle=wintitle, | |
105 | showprofile=showprofile) |
|
105 | showprofile=showprofile) | |
106 |
|
106 | |||
107 | if xmin == None: xmin = numpy.min(x) |
|
107 | if xmin == None: xmin = numpy.min(x) | |
108 | if xmax == None: xmax = xmin + self.__timerange |
|
108 | if xmax == None: xmax = xmin + self.__timerange | |
109 | if ymin == None: ymin = numpy.nanmin(y) |
|
109 | if ymin == None: ymin = numpy.nanmin(y) | |
110 | if ymax == None: ymax = numpy.nanmax(y) |
|
110 | if ymax == None: ymax = numpy.nanmax(y) | |
111 | if zmin == None: zmin = numpy.nanmin(avg)*0.9 |
|
111 | if zmin == None: zmin = numpy.nanmin(avg)*0.9 | |
112 | if zmax == None: zmax = numpy.nanmax(avg)*0.9 |
|
112 | if zmax == None: zmax = numpy.nanmax(avg)*0.9 | |
113 |
|
113 | |||
114 | self.__isConfig = True |
|
114 | self.__isConfig = True | |
115 |
|
115 | |||
116 | thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime) |
|
116 | thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime) | |
117 | title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
117 | title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
118 | xlabel = "Velocity (m/s)" |
|
118 | xlabel = "Velocity (m/s)" | |
119 | ylabel = "Range (Km)" |
|
119 | ylabel = "Range (Km)" | |
120 |
|
120 | |||
121 | self.setWinTitle(title) |
|
121 | self.setWinTitle(title) | |
122 |
|
122 | |||
123 | for i in range(self.nplots): |
|
123 | for i in range(self.nplots): | |
124 | title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noise[i]) |
|
124 | title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noise[i]) | |
125 | axes = self.axesList[i*self.__nsubplots] |
|
125 | axes = self.axesList[i*self.__nsubplots] | |
126 | z = avg[i].reshape((1,-1)) |
|
126 | z = avg[i].reshape((1,-1)) | |
127 | axes.pcolor(x, y, z, |
|
127 | axes.pcolor(x, y, z, | |
128 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
128 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
129 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, |
|
129 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
130 | ticksize=9, cblabel='') |
|
130 | ticksize=9, cblabel='') | |
131 |
|
131 | |||
132 | if self.__showprofile: |
|
132 | if self.__showprofile: | |
133 | axes = self.axesList[i*self.__nsubplots +1] |
|
133 | axes = self.axesList[i*self.__nsubplots +1] | |
134 | axes.pline(avg[i], y, |
|
134 | axes.pline(avg[i], y, | |
135 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
135 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |
136 | xlabel='dB', ylabel='', title='', |
|
136 | xlabel='dB', ylabel='', title='', | |
137 | ytick_visible=False, |
|
137 | ytick_visible=False, | |
138 | grid='x') |
|
138 | grid='x') | |
139 |
|
139 | |||
140 | self.draw() |
|
140 | self.draw() | |
141 |
|
141 | |||
|
142 | if save: | |||
|
143 | self.saveFigure(filename) | |||
|
144 | ||||
142 | class SpectraPlot(Figure): |
|
145 | class SpectraPlot(Figure): | |
143 |
|
146 | |||
144 | __isConfig = None |
|
147 | __isConfig = None | |
145 | __nsubplots = None |
|
148 | __nsubplots = None | |
146 |
|
149 | |||
147 | WIDTHPROF = None |
|
150 | WIDTHPROF = None | |
148 | HEIGHTPROF = None |
|
151 | HEIGHTPROF = None | |
149 |
|
152 | |||
150 | def __init__(self): |
|
153 | def __init__(self): | |
151 |
|
154 | |||
152 | self.__isConfig = False |
|
155 | self.__isConfig = False | |
153 | self.__nsubplots = 1 |
|
156 | self.__nsubplots = 1 | |
154 |
|
157 | |||
155 | self.WIDTH = 300 |
|
158 | self.WIDTH = 300 | |
156 | self.HEIGHT = 400 |
|
159 | self.HEIGHT = 400 | |
157 | self.WIDTHPROF = 120 |
|
160 | self.WIDTHPROF = 120 | |
158 | self.HEIGHTPROF = 0 |
|
161 | self.HEIGHTPROF = 0 | |
159 |
|
162 | |||
160 | def getSubplots(self): |
|
163 | def getSubplots(self): | |
161 |
|
164 | |||
162 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
165 | ncol = int(numpy.sqrt(self.nplots)+0.9) | |
163 | nrow = int(self.nplots*1./ncol + 0.9) |
|
166 | nrow = int(self.nplots*1./ncol + 0.9) | |
164 |
|
167 | |||
165 | return nrow, ncol |
|
168 | return nrow, ncol | |
166 |
|
169 | |||
167 | def setup(self, idfigure, nplots, wintitle, showprofile=True): |
|
170 | def setup(self, idfigure, nplots, wintitle, showprofile=True): | |
168 |
|
171 | |||
169 | self.__showprofile = showprofile |
|
172 | self.__showprofile = showprofile | |
170 | self.nplots = nplots |
|
173 | self.nplots = nplots | |
171 |
|
174 | |||
172 | ncolspan = 1 |
|
175 | ncolspan = 1 | |
173 | colspan = 1 |
|
176 | colspan = 1 | |
174 | if showprofile: |
|
177 | if showprofile: | |
175 | ncolspan = 3 |
|
178 | ncolspan = 3 | |
176 | colspan = 2 |
|
179 | colspan = 2 | |
177 | self.__nsubplots = 2 |
|
180 | self.__nsubplots = 2 | |
178 | self.WIDTH += self.WIDTHPROF |
|
181 | self.WIDTH += self.WIDTHPROF | |
179 | self.HEIGHT += self.HEIGHTPROF |
|
182 | self.HEIGHT += self.HEIGHTPROF | |
180 |
|
183 | |||
181 | self.createFigure(idfigure, wintitle) |
|
184 | self.createFigure(idfigure, wintitle) | |
182 |
|
185 | |||
183 | nrow, ncol = self.getSubplots() |
|
186 | nrow, ncol = self.getSubplots() | |
184 |
|
187 | |||
185 | counter = 0 |
|
188 | counter = 0 | |
186 | for y in range(nrow): |
|
189 | for y in range(nrow): | |
187 | for x in range(ncol): |
|
190 | for x in range(ncol): | |
188 |
|
191 | |||
189 | if counter >= self.nplots: |
|
192 | if counter >= self.nplots: | |
190 | break |
|
193 | break | |
191 |
|
194 | |||
192 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
195 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
193 |
|
196 | |||
194 | if showprofile: |
|
197 | if showprofile: | |
195 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
198 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
196 |
|
199 | |||
197 | counter += 1 |
|
200 | counter += 1 | |
198 |
|
201 | |||
199 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
202 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', | |
200 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): |
|
203 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, save=False, filename=None): | |
201 |
|
204 | |||
202 | """ |
|
205 | """ | |
203 |
|
206 | |||
204 | Input: |
|
207 | Input: | |
205 | dataOut : |
|
208 | dataOut : | |
206 | idfigure : |
|
209 | idfigure : | |
207 | wintitle : |
|
210 | wintitle : | |
208 | channelList : |
|
211 | channelList : | |
209 | showProfile : |
|
212 | showProfile : | |
210 | xmin : None, |
|
213 | xmin : None, | |
211 | xmax : None, |
|
214 | xmax : None, | |
212 | ymin : None, |
|
215 | ymin : None, | |
213 | ymax : None, |
|
216 | ymax : None, | |
214 | zmin : None, |
|
217 | zmin : None, | |
215 | zmax : None |
|
218 | zmax : None | |
216 | """ |
|
219 | """ | |
217 |
|
220 | |||
218 | if channelList == None: |
|
221 | if channelList == None: | |
219 | channelIndexList = dataOut.channelIndexList |
|
222 | channelIndexList = dataOut.channelIndexList | |
220 | else: |
|
223 | else: | |
221 | channelIndexList = [] |
|
224 | channelIndexList = [] | |
222 | for channel in channelList: |
|
225 | for channel in channelList: | |
223 | if channel not in dataOut.channelList: |
|
226 | if channel not in dataOut.channelList: | |
224 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
227 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
225 | channelIndexList.append(channel) |
|
228 | channelIndexList.append(channel) | |
226 |
|
229 | |||
227 | x = dataOut.getVelRange(1) |
|
230 | x = dataOut.getVelRange(1) | |
228 | y = dataOut.getHeiRange() |
|
231 | y = dataOut.getHeiRange() | |
229 | z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:]) |
|
232 | z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:]) | |
230 | avg = numpy.average(z, axis=1) |
|
233 | avg = numpy.average(z, axis=1) | |
231 |
|
234 | |||
232 | noise = dataOut.getNoise() |
|
235 | noise = dataOut.getNoise() | |
233 |
|
236 | |||
234 | if not self.__isConfig: |
|
237 | if not self.__isConfig: | |
235 |
|
238 | |||
236 | nplots = len(channelIndexList) |
|
239 | nplots = len(channelIndexList) | |
237 |
|
240 | |||
238 | self.setup(idfigure=idfigure, |
|
241 | self.setup(idfigure=idfigure, | |
239 | nplots=nplots, |
|
242 | nplots=nplots, | |
240 | wintitle=wintitle, |
|
243 | wintitle=wintitle, | |
241 | showprofile=showprofile) |
|
244 | showprofile=showprofile) | |
242 |
|
245 | |||
243 | if xmin == None: xmin = numpy.nanmin(x) |
|
246 | if xmin == None: xmin = numpy.nanmin(x) | |
244 | if xmax == None: xmax = numpy.nanmax(x) |
|
247 | if xmax == None: xmax = numpy.nanmax(x) | |
245 | if ymin == None: ymin = numpy.nanmin(y) |
|
248 | if ymin == None: ymin = numpy.nanmin(y) | |
246 | if ymax == None: ymax = numpy.nanmax(y) |
|
249 | if ymax == None: ymax = numpy.nanmax(y) | |
247 | if zmin == None: zmin = numpy.nanmin(avg)*0.9 |
|
250 | if zmin == None: zmin = numpy.nanmin(avg)*0.9 | |
248 | if zmax == None: zmax = numpy.nanmax(avg)*0.9 |
|
251 | if zmax == None: zmax = numpy.nanmax(avg)*0.9 | |
249 |
|
252 | |||
250 | self.__isConfig = True |
|
253 | self.__isConfig = True | |
251 |
|
254 | |||
252 | thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime) |
|
255 | thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime) | |
253 | title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
256 | title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
254 | xlabel = "Velocity (m/s)" |
|
257 | xlabel = "Velocity (m/s)" | |
255 | ylabel = "Range (Km)" |
|
258 | ylabel = "Range (Km)" | |
256 |
|
259 | |||
257 | self.setWinTitle(title) |
|
260 | self.setWinTitle(title) | |
258 |
|
261 | |||
259 | for i in range(self.nplots): |
|
262 | for i in range(self.nplots): | |
260 | title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noise[i]) |
|
263 | title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noise[i]) | |
261 | axes = self.axesList[i*self.__nsubplots] |
|
264 | axes = self.axesList[i*self.__nsubplots] | |
262 | axes.pcolor(x, y, z[i,:,:], |
|
265 | axes.pcolor(x, y, z[i,:,:], | |
263 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
266 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
264 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
267 | xlabel=xlabel, ylabel=ylabel, title=title, | |
265 | ticksize=9, cblabel='') |
|
268 | ticksize=9, cblabel='') | |
266 |
|
269 | |||
267 | if self.__showprofile: |
|
270 | if self.__showprofile: | |
268 | axes = self.axesList[i*self.__nsubplots +1] |
|
271 | axes = self.axesList[i*self.__nsubplots +1] | |
269 | axes.pline(avg[i], y, |
|
272 | axes.pline(avg[i], y, | |
270 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
273 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |
271 | xlabel='dB', ylabel='', title='', |
|
274 | xlabel='dB', ylabel='', title='', | |
272 | ytick_visible=False, |
|
275 | ytick_visible=False, | |
273 | grid='x') |
|
276 | grid='x') | |
274 |
|
277 | |||
275 | self.draw() |
|
278 | self.draw() | |
|
279 | ||||
|
280 | if save: | |||
|
281 | self.saveFigure(filename) | |||
276 |
|
282 | |||
277 | class Scope(Figure): |
|
283 | class Scope(Figure): | |
278 |
|
284 | |||
279 | __isConfig = None |
|
285 | __isConfig = None | |
280 |
|
286 | |||
281 | def __init__(self): |
|
287 | def __init__(self): | |
282 |
|
288 | |||
283 | self.__isConfig = False |
|
289 | self.__isConfig = False | |
284 | self.WIDTH = 600 |
|
290 | self.WIDTH = 600 | |
285 | self.HEIGHT = 200 |
|
291 | self.HEIGHT = 200 | |
286 |
|
292 | |||
287 | def getSubplots(self): |
|
293 | def getSubplots(self): | |
288 |
|
294 | |||
289 | nrow = self.nplots |
|
295 | nrow = self.nplots | |
290 | ncol = 3 |
|
296 | ncol = 3 | |
291 | return nrow, ncol |
|
297 | return nrow, ncol | |
292 |
|
298 | |||
293 | def setup(self, idfigure, nplots, wintitle): |
|
299 | def setup(self, idfigure, nplots, wintitle): | |
294 |
|
300 | |||
295 | self.createFigure(idfigure, wintitle) |
|
301 | self.createFigure(idfigure, wintitle) | |
296 |
|
302 | |||
297 | nrow,ncol = self.getSubplots() |
|
303 | nrow,ncol = self.getSubplots() | |
298 | colspan = 3 |
|
304 | colspan = 3 | |
299 | rowspan = 1 |
|
305 | rowspan = 1 | |
300 |
|
306 | |||
301 | for i in range(nplots): |
|
307 | for i in range(nplots): | |
302 | self.addAxes(nrow, ncol, i, 0, colspan, rowspan) |
|
308 | self.addAxes(nrow, ncol, i, 0, colspan, rowspan) | |
303 |
|
309 | |||
304 | self.nplots = nplots |
|
310 | self.nplots = nplots | |
305 |
|
311 | |||
306 | def run(self, dataOut, idfigure, wintitle="", channelList=None, |
|
312 | def run(self, dataOut, idfigure, wintitle="", channelList=None, | |
307 | xmin=None, xmax=None, ymin=None, ymax=None): |
|
313 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, filename=None): | |
308 |
|
314 | |||
309 | """ |
|
315 | """ | |
310 |
|
316 | |||
311 | Input: |
|
317 | Input: | |
312 | dataOut : |
|
318 | dataOut : | |
313 | idfigure : |
|
319 | idfigure : | |
314 | wintitle : |
|
320 | wintitle : | |
315 | channelList : |
|
321 | channelList : | |
316 | xmin : None, |
|
322 | xmin : None, | |
317 | xmax : None, |
|
323 | xmax : None, | |
318 | ymin : None, |
|
324 | ymin : None, | |
319 | ymax : None, |
|
325 | ymax : None, | |
320 | """ |
|
326 | """ | |
321 |
|
327 | |||
322 | if channelList == None: |
|
328 | if channelList == None: | |
323 | channelList = dataOut.channelList |
|
329 | channelList = dataOut.channelList | |
324 |
|
330 | |||
325 | x = dataOut.heightList |
|
331 | x = dataOut.heightList | |
326 | y = dataOut.data[channelList,:] * numpy.conjugate(dataOut.data[channelList,:]) |
|
332 | y = dataOut.data[channelList,:] * numpy.conjugate(dataOut.data[channelList,:]) | |
327 | y = y.real |
|
333 | y = y.real | |
328 |
|
334 | |||
329 | noise = dataOut.getNoise() |
|
335 | noise = dataOut.getNoise() | |
330 |
|
336 | |||
331 | if not self.__isConfig: |
|
337 | if not self.__isConfig: | |
332 | nplots = len(channelList) |
|
338 | nplots = len(channelList) | |
333 |
|
339 | |||
334 | self.setup(idfigure=idfigure, |
|
340 | self.setup(idfigure=idfigure, | |
335 | nplots=nplots, |
|
341 | nplots=nplots, | |
336 | wintitle=wintitle) |
|
342 | wintitle=wintitle) | |
337 |
|
343 | |||
338 | if xmin == None: xmin = numpy.nanmin(x) |
|
344 | if xmin == None: xmin = numpy.nanmin(x) | |
339 | if xmax == None: xmax = numpy.nanmax(x) |
|
345 | if xmax == None: xmax = numpy.nanmax(x) | |
340 | if ymin == None: ymin = numpy.nanmin(y) |
|
346 | if ymin == None: ymin = numpy.nanmin(y) | |
341 | if ymax == None: ymax = numpy.nanmax(y) |
|
347 | if ymax == None: ymax = numpy.nanmax(y) | |
342 |
|
348 | |||
343 | self.__isConfig = True |
|
349 | self.__isConfig = True | |
344 |
|
350 | |||
345 |
|
351 | |||
346 | thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime) |
|
352 | thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime) | |
347 | title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
353 | title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
348 | xlabel = "Range (Km)" |
|
354 | xlabel = "Range (Km)" | |
349 | ylabel = "Intensity" |
|
355 | ylabel = "Intensity" | |
350 |
|
356 | |||
351 | self.setWinTitle(title) |
|
357 | self.setWinTitle(title) | |
352 |
|
358 | |||
353 | for i in range(len(self.axesList)): |
|
359 | for i in range(len(self.axesList)): | |
354 | title = "Channel %d: %4.2fdB" %(i, noise[i]) |
|
360 | title = "Channel %d: %4.2fdB" %(i, noise[i]) | |
355 | axes = self.axesList[i] |
|
361 | axes = self.axesList[i] | |
356 | ychannel = y[i,:] |
|
362 | ychannel = y[i,:] | |
357 | axes.pline(x, ychannel, |
|
363 | axes.pline(x, ychannel, | |
358 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
364 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |
359 | xlabel=xlabel, ylabel=ylabel, title=title) |
|
365 | xlabel=xlabel, ylabel=ylabel, title=title) | |
360 |
|
366 | |||
361 | self.draw() |
|
367 | self.draw() | |
362 |
|
368 | |||
363 |
|
369 | if save: | ||
|
370 | self.saveFigure(filename) | |||
364 | No newline at end of file |
|
371 |
General Comments 0
You need to be logged in to leave comments.
Login now