@@ -1,643 +1,666 | |||||
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='D:\Data\IMAGING', |
|
589 | path='D:\Data\IMAGING', | |
590 | startDate='2011/01/01', |
|
590 | startDate='2011/01/01', | |
591 | endDate='2012/12/31', |
|
591 | endDate='2012/12/31', | |
592 | startTime='00:00:00', |
|
592 | startTime='00:00: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', 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=' |
|
606 | # opObj11.addParameter(name='zmin', value='70', format='int') | |
607 |
# opObj11.addParameter(name='zmax', value=' |
|
607 | # opObj11.addParameter(name='zmax', value='90', format='int') | |
|
608 | opObj11.addParameter(name='showprofile', value='1', format='int') | |||
|
609 | ||||
|
610 | opObj10 = procUnitConfObj1.addOperation(name='selectChannels') | |||
|
611 | opObj10.addParameter(name='channelList', value='0,2,4,6', format='intlist') | |||
608 |
|
612 | |||
609 | opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') |
|
613 | opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') | |
610 |
opObj12.addParameter(name='n', value=' |
|
614 | opObj12.addParameter(name='n', value='2', format='int') | |
611 |
|
615 | |||
612 | opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') |
|
616 | opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') | |
613 | opObj11.addParameter(name='idfigure', value='2', format='int') |
|
617 | opObj11.addParameter(name='idfigure', value='2', format='int') | |
614 | opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str') |
|
618 | opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str') | |
615 |
|
|
619 | opObj11.addParameter(name='zmin', value='70', format='int') | |
616 |
|
|
620 | opObj11.addParameter(name='zmax', value='90', format='int') | |
617 |
|
621 | |||
|
622 | opObj10 = procUnitConfObj1.addOperation(name='selectChannels') | |||
|
623 | opObj10.addParameter(name='channelList', value='2,6', format='intlist') | |||
|
624 | ||||
|
625 | opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') | |||
|
626 | opObj12.addParameter(name='n', value='2', format='int') | |||
|
627 | ||||
|
628 | opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') | |||
|
629 | opObj11.addParameter(name='idfigure', value='3', format='int') | |||
|
630 | opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str') | |||
|
631 | opObj11.addParameter(name='zmin', value='70', format='int') | |||
|
632 | opObj11.addParameter(name='zmax', value='90', format='int') | |||
|
633 | ||||
|
634 | ||||
618 | # opObj12 = procUnitConfObj1.addOperation(name='decoder') |
|
635 | # opObj12 = procUnitConfObj1.addOperation(name='decoder') | |
619 | # opObj12.addParameter(name='ncode', value='2', format='int') |
|
636 | # opObj12.addParameter(name='ncode', value='2', format='int') | |
620 | # opObj12.addParameter(name='nbauds', value='8', format='int') |
|
637 | # opObj12.addParameter(name='nbauds', value='8', format='int') | |
621 | # opObj12.addParameter(name='code0', value='001110011', format='int') |
|
638 | # opObj12.addParameter(name='code0', value='001110011', format='int') | |
622 | # opObj12.addParameter(name='code1', value='001110011', format='int') |
|
639 | # opObj12.addParameter(name='code1', value='001110011', format='int') | |
623 |
|
640 | |||
624 | # procUnitConfObj2 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj1.getId()) |
|
|||
625 |
|
641 | |||
|
642 | ||||
|
643 | procUnitConfObj2 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj1.getId()) | |||
626 |
|
644 | |||
627 |
|
|
645 | opObj21 = procUnitConfObj2.addOperation(name='IncohInt', optype='other') | |
628 |
|
|
646 | opObj21.addParameter(name='n', value='2', format='int') | |
629 |
|
||||
630 |
|
647 | |||
|
648 | opObj11 = procUnitConfObj2.addOperation(name='SpectraPlot', optype='other') | |||
|
649 | opObj11.addParameter(name='idfigure', value='4', format='int') | |||
|
650 | opObj11.addParameter(name='wintitle', value='SpectraPlot OBJ 2', format='str') | |||
|
651 | opObj11.addParameter(name='zmin', value='70', format='int') | |||
|
652 | opObj11.addParameter(name='zmax', value='90', format='int') | |||
|
653 | ||||
631 | print "Escribiendo el archivo XML" |
|
654 | print "Escribiendo el archivo XML" | |
632 |
|
655 | |||
633 | controllerObj.writeXml(filename) |
|
656 | controllerObj.writeXml(filename) | |
634 |
|
657 | |||
635 | print "Leyendo el archivo XML" |
|
658 | print "Leyendo el archivo XML" | |
636 | controllerObj.readXml(filename) |
|
659 | controllerObj.readXml(filename) | |
637 | #controllerObj.printattr() |
|
660 | #controllerObj.printattr() | |
638 |
|
661 | |||
639 | controllerObj.createObjects() |
|
662 | controllerObj.createObjects() | |
640 | controllerObj.connectObjects() |
|
663 | controllerObj.connectObjects() | |
641 | controllerObj.run() |
|
664 | controllerObj.run() | |
642 |
|
665 | |||
643 | No newline at end of file |
|
666 |
@@ -1,231 +1,240 | |||||
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 |
|
8 | |||
9 | idfigure = None |
|
9 | idfigure = None | |
10 | wintitle = None |
|
10 | wintitle = None | |
11 | width = None |
|
11 | width = None | |
12 | height = None |
|
12 | height = None | |
13 | nplots = None |
|
13 | nplots = None | |
14 |
|
14 | |||
15 | axesObjList = [] |
|
15 | axesObjList = [] | |
16 |
|
16 | |||
17 | WIDTH = None |
|
17 | WIDTH = None | |
18 | HEIGHT = None |
|
18 | HEIGHT = None | |
19 |
|
19 | |||
20 | def __init__(self): |
|
20 | def __init__(self): | |
21 |
|
21 | |||
22 | raise ValueError, "This method is not implemented" |
|
22 | raise ValueError, "This method is not implemented" | |
23 |
|
23 | |||
24 | def getAxesObjList(self): |
|
24 | def getAxesObjList(self): | |
25 |
|
25 | |||
26 | return self.axesObjList |
|
26 | return self.axesObjList | |
27 |
|
27 | |||
28 | def getSubplots(self): |
|
28 | def getSubplots(self): | |
29 |
|
29 | |||
30 | raise ValueError, "Abstract method: This method should be defined" |
|
30 | raise ValueError, "Abstract method: This method should be defined" | |
31 |
|
31 | |||
32 | def getScreenDim(self): |
|
32 | def getScreenDim(self): | |
33 |
|
33 | |||
34 | nrow, ncol = self.getSubplots() |
|
34 | nrow, ncol = self.getSubplots() | |
35 |
|
35 | |||
36 | width = self.WIDTH*ncol |
|
36 | width = self.WIDTH*ncol | |
37 | height = self.HEIGHT*nrow |
|
37 | height = self.HEIGHT*nrow | |
38 |
|
38 | |||
39 | return width, height |
|
39 | return width, height | |
40 |
|
40 | |||
41 | def init(self, idfigure, nplots, wintitle): |
|
41 | def init(self, idfigure, nplots, wintitle): | |
|
42 | ||||
|
43 | raise ValueError, "This method has been replaced with createFigure" | |||
|
44 | ||||
|
45 | def createFigure(self, idfigure, wintitle): | |||
42 |
|
46 | |||
43 | """ |
|
47 | """ | |
44 |
|
|
48 | Crea la figura de acuerdo al driver y parametros seleccionados seleccionados. | |
|
49 | Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH | |||
|
50 | y self.HEIGHT y el numero de subplots (nrow, ncol) | |||
|
51 | ||||
45 | Input: |
|
52 | Input: | |
46 |
|
|
53 | idfigure : Los parametros necesarios son | |
47 | idfigure, wintitle, width, height |
|
54 | wintitle : | |
|
55 | ||||
48 | """ |
|
56 | """ | |
49 |
|
57 | |||
50 | self.idfigure = idfigure |
|
58 | self.idfigure = idfigure | |
51 |
|
59 | |||
52 | self.nplots = nplots |
|
|||
53 |
|
||||
54 | self.wintitle = wintitle |
|
60 | self.wintitle = wintitle | |
55 |
|
61 | |||
56 | self.width, self.height = self.getScreenDim() |
|
62 | self.width, self.height = self.getScreenDim() | |
57 |
|
63 | |||
58 | self.fig = self.__driver.createFigure(self.idfigure, |
|
64 | self.fig = self.__driver.createFigure(self.idfigure, | |
59 | self.wintitle, |
|
65 | self.wintitle, | |
60 | self.width, |
|
66 | self.width, | |
61 | self.height) |
|
67 | self.height) | |
62 |
|
68 | |||
63 | self.axesObjList = [] |
|
69 | self.axesObjList = [] | |
64 |
|
70 | |||
65 | def setDriver(self, driver=mpldriver): |
|
71 | def setDriver(self, driver=mpldriver): | |
66 |
|
72 | |||
67 | self.__driver = driver |
|
73 | self.__driver = driver | |
68 |
|
74 | |||
69 | def setTitle(self, title): |
|
75 | def setTitle(self, title): | |
70 |
|
76 | |||
71 | self.__driver.setTitle(self.fig, title) |
|
77 | self.__driver.setTitle(self.fig, title) | |
72 |
|
78 | |||
73 | def setWinTitle(self, title): |
|
79 | def setWinTitle(self, title): | |
74 |
|
80 | |||
75 | self.__driver.setWinTitle(self.fig, title=title) |
|
81 | self.__driver.setWinTitle(self.fig, title=title) | |
76 |
|
82 | |||
77 | def setTextFromAxes(self, text): |
|
83 | def setTextFromAxes(self, text): | |
78 |
|
84 | |||
79 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes" |
|
85 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes" | |
80 |
|
86 | |||
81 | def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan): |
|
87 | def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan): | |
82 |
|
88 | |||
83 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes" |
|
89 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes" | |
84 |
|
90 | |||
85 | def addAxes(self, *args): |
|
91 | def addAxes(self, *args): | |
86 | """ |
|
92 | """ | |
87 |
|
93 | |||
88 | Input: |
|
94 | Input: | |
89 | *args : Los parametros necesarios son |
|
95 | *args : Los parametros necesarios son | |
90 | nrow, ncol, xpos, ypos, colspan, rowspan |
|
96 | nrow, ncol, xpos, ypos, colspan, rowspan | |
91 | """ |
|
97 | """ | |
92 |
|
98 | |||
93 | axesObj = Axes(self.fig, *args) |
|
99 | axesObj = Axes(self.fig, *args) | |
94 | self.axesObjList.append(axesObj) |
|
100 | self.axesObjList.append(axesObj) | |
95 |
|
101 | |||
96 | def draw(self): |
|
102 | def draw(self): | |
97 |
|
103 | |||
98 | self.__driver.draw(self.fig) |
|
104 | self.__driver.draw(self.fig) | |
99 |
|
105 | |||
100 | def run(self): |
|
106 | def run(self): | |
101 |
|
107 | |||
102 | raise ValueError, "This method is not implemented" |
|
108 | raise ValueError, "This method is not implemented" | |
103 |
|
109 | |||
104 | axesList = property(getAxesObjList) |
|
110 | axesList = property(getAxesObjList) | |
105 |
|
111 | |||
106 |
|
112 | |||
107 | class Axes: |
|
113 | class Axes: | |
108 |
|
114 | |||
109 | __driver = mpldriver |
|
115 | __driver = mpldriver | |
110 | fig = None |
|
116 | fig = None | |
111 | ax = None |
|
117 | ax = None | |
112 | plot = None |
|
118 | plot = None | |
113 |
|
119 | |||
114 | firsttime = None |
|
120 | firsttime = None | |
115 |
|
121 | |||
|
122 | __showprofile = False | |||
|
123 | ||||
116 | def __init__(self, *args): |
|
124 | def __init__(self, *args): | |
117 |
|
125 | |||
118 | """ |
|
126 | """ | |
119 |
|
127 | |||
120 | Input: |
|
128 | Input: | |
121 | *args : Los parametros necesarios son |
|
129 | *args : Los parametros necesarios son | |
122 | fig, nrow, ncol, xpos, ypos, colspan, rowspan |
|
130 | fig, nrow, ncol, xpos, ypos, colspan, rowspan | |
123 | """ |
|
131 | """ | |
124 |
|
132 | |||
125 | ax = self.__driver.createAxes(*args) |
|
133 | ax = self.__driver.createAxes(*args) | |
126 | self.fig = args[0] |
|
134 | self.fig = args[0] | |
127 | self.ax = ax |
|
135 | self.ax = ax | |
128 | self.plot = None |
|
136 | self.plot = None | |
129 |
|
137 | |||
130 | self.firsttime = True |
|
138 | self.firsttime = True | |
131 |
|
139 | |||
132 | def setText(self, text): |
|
140 | def setText(self, text): | |
133 |
|
141 | |||
134 | self.__driver.setAxesText(self.ax, text) |
|
142 | self.__driver.setAxesText(self.ax, text) | |
135 |
|
143 | |||
136 | def pline(self, x, y, |
|
144 | def pline(self, x, y, | |
137 | xmin=None, xmax=None, |
|
145 | xmin=None, xmax=None, | |
138 | ymin=None, ymax=None, |
|
146 | ymin=None, ymax=None, | |
139 | xlabel='', ylabel='', |
|
147 | xlabel='', ylabel='', | |
140 | title='', |
|
148 | title='', | |
141 | **kwargs): |
|
149 | **kwargs): | |
142 |
|
150 | |||
143 | """ |
|
151 | """ | |
144 |
|
152 | |||
145 | Input: |
|
153 | Input: | |
146 | x : |
|
154 | x : | |
147 | y : |
|
155 | y : | |
148 | xmin : |
|
156 | xmin : | |
149 | xmax : |
|
157 | xmax : | |
150 | ymin : |
|
158 | ymin : | |
151 | ymax : |
|
159 | ymax : | |
152 | xlabel : |
|
160 | xlabel : | |
153 | ylabel : |
|
161 | ylabel : | |
154 | title : |
|
162 | title : | |
155 | **kwargs : Los parametros aceptados son |
|
163 | **kwargs : Los parametros aceptados son | |
156 |
|
164 | |||
157 | ticksize |
|
165 | ticksize | |
|
166 | ytick_visible | |||
158 | """ |
|
167 | """ | |
159 |
|
168 | |||
160 | if self.firsttime: |
|
169 | if self.firsttime: | |
161 |
|
170 | |||
162 | if xmin == None: xmin = numpy.nanmin(x) |
|
171 | if xmin == None: xmin = numpy.nanmin(x) | |
163 | if xmax == None: xmax = numpy.nanmax(x) |
|
172 | if xmax == None: xmax = numpy.nanmax(x) | |
164 | if ymin == None: ymin = numpy.nanmin(y) |
|
173 | if ymin == None: ymin = numpy.nanmin(y) | |
165 | if ymax == None: ymax = numpy.nanmax(y) |
|
174 | if ymax == None: ymax = numpy.nanmax(y) | |
166 |
|
175 | |||
167 | self.plot = self.__driver.createPline(self.ax, x, y, |
|
176 | self.plot = self.__driver.createPline(self.ax, x, y, | |
168 | xmin, xmax, |
|
177 | xmin, xmax, | |
169 | ymin, ymax, |
|
178 | ymin, ymax, | |
170 | xlabel=xlabel, |
|
179 | xlabel=xlabel, | |
171 | ylabel=ylabel, |
|
180 | ylabel=ylabel, | |
172 | title=title, |
|
181 | title=title, | |
173 | **kwargs) |
|
182 | **kwargs) | |
174 | self.firsttime = False |
|
183 | self.firsttime = False | |
175 | return |
|
184 | return | |
176 |
|
185 | |||
177 | self.__driver.pline(self.plot, x, y, xlabel=xlabel, |
|
186 | self.__driver.pline(self.plot, x, y, xlabel=xlabel, | |
178 | ylabel=ylabel, |
|
187 | ylabel=ylabel, | |
179 | title=title) |
|
188 | title=title) | |
180 |
|
189 | |||
181 |
|
190 | |||
182 | def pcolor(self, x, y, z, |
|
191 | def pcolor(self, x, y, z, | |
183 | xmin=None, xmax=None, |
|
192 | xmin=None, xmax=None, | |
184 | ymin=None, ymax=None, |
|
193 | ymin=None, ymax=None, | |
185 | zmin=None, zmax=None, |
|
194 | zmin=None, zmax=None, | |
186 | xlabel='', ylabel='', |
|
195 | xlabel='', ylabel='', | |
187 | title='', |
|
196 | title='', | |
188 | **kwargs): |
|
197 | **kwargs): | |
189 |
|
198 | |||
190 | """ |
|
199 | """ | |
191 | Input: |
|
200 | Input: | |
192 | x : |
|
201 | x : | |
193 | y : |
|
202 | y : | |
194 | x : |
|
203 | x : | |
195 | xmin : |
|
204 | xmin : | |
196 | xmax : |
|
205 | xmax : | |
197 | ymin : |
|
206 | ymin : | |
198 | ymax : |
|
207 | ymax : | |
199 | zmin : |
|
208 | zmin : | |
200 | zmax : |
|
209 | zmax : | |
201 | xlabel : |
|
210 | xlabel : | |
202 | ylabel : |
|
211 | ylabel : | |
203 | title : |
|
212 | title : | |
204 | **kwargs : Los parametros aceptados son |
|
213 | **kwargs : Los parametros aceptados son | |
205 | ticksize=9, |
|
214 | ticksize=9, | |
206 | cblabel='' |
|
215 | cblabel='' | |
207 | """ |
|
216 | """ | |
208 |
|
217 | |||
209 | if self.firsttime: |
|
218 | if self.firsttime: | |
210 |
|
219 | |||
211 | if xmin == None: xmin = numpy.nanmin(x) |
|
220 | if xmin == None: xmin = numpy.nanmin(x) | |
212 | if xmax == None: xmax = numpy.nanmax(x) |
|
221 | if xmax == None: xmax = numpy.nanmax(x) | |
213 | if ymin == None: ymin = numpy.nanmin(y) |
|
222 | if ymin == None: ymin = numpy.nanmin(y) | |
214 | if ymax == None: ymax = numpy.nanmax(y) |
|
223 | if ymax == None: ymax = numpy.nanmax(y) | |
215 | if zmin == None: zmin = numpy.nanmin(z) |
|
224 | if zmin == None: zmin = numpy.nanmin(z) | |
216 | if zmax == None: zmax = numpy.nanmax(z) |
|
225 | if zmax == None: zmax = numpy.nanmax(z) | |
217 |
|
226 | |||
218 | self.plot = self.__driver.createPcolor(self.ax, x, y, z, |
|
227 | self.plot = self.__driver.createPcolor(self.ax, x, y, z, | |
219 | xmin, xmax, |
|
228 | xmin, xmax, | |
220 | ymin, ymax, |
|
229 | ymin, ymax, | |
221 | zmin, zmax, |
|
230 | zmin, zmax, | |
222 | xlabel=xlabel, |
|
231 | xlabel=xlabel, | |
223 | ylabel=ylabel, |
|
232 | ylabel=ylabel, | |
224 | title=title, |
|
233 | title=title, | |
225 | **kwargs) |
|
234 | **kwargs) | |
226 | self.firsttime = False |
|
235 | self.firsttime = False | |
227 | return |
|
236 | return | |
228 |
|
237 | |||
229 | mesh = self.__driver.pcolor(self.plot, z, xlabel=xlabel, |
|
238 | mesh = self.__driver.pcolor(self.plot, z, xlabel=xlabel, | |
230 | ylabel=ylabel, |
|
239 | ylabel=ylabel, | |
231 | title=title) |
|
240 | title=title) |
@@ -1,215 +1,239 | |||||
1 | import numpy |
|
1 | import numpy | |
2 | import matplotlib |
|
2 | import matplotlib | |
3 | matplotlib.use("TKAgg") |
|
3 | matplotlib.use("TKAgg") | |
4 | import matplotlib.pyplot |
|
4 | import matplotlib.pyplot | |
5 | #import scitools.numpyutils |
|
5 | #import scitools.numpyutils | |
6 | from mpl_toolkits.axes_grid1 import make_axes_locatable |
|
6 | from mpl_toolkits.axes_grid1 import make_axes_locatable | |
7 |
|
7 | |||
8 | def init(idfigure, wintitle, width, height, facecolor="w"): |
|
8 | def init(idfigure, wintitle, width, height, facecolor="w"): | |
9 |
|
9 | |||
10 | matplotlib.pyplot.ioff() |
|
10 | matplotlib.pyplot.ioff() | |
11 | fig = matplotlib.pyplot.matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor) |
|
11 | fig = matplotlib.pyplot.matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor) | |
12 | fig.canvas.manager.set_window_title(wintitle) |
|
12 | fig.canvas.manager.set_window_title(wintitle) | |
13 | fig.canvas.manager.resize(width, height) |
|
13 | fig.canvas.manager.resize(width, height) | |
14 | matplotlib.pyplot.ion() |
|
14 | matplotlib.pyplot.ion() | |
15 |
|
15 | |||
16 | return fig |
|
16 | return fig | |
17 |
|
17 | |||
18 | def setWinTitle(fig, title): |
|
18 | def setWinTitle(fig, title): | |
19 |
|
19 | |||
20 | fig.canvas.manager.set_window_title(title) |
|
20 | fig.canvas.manager.set_window_title(title) | |
21 |
|
21 | |||
22 | def setTitle(idfigure, title): |
|
22 | def setTitle(idfigure, title): | |
23 | fig = matplotlib.pyplot.figure(idfigure) |
|
23 | fig = matplotlib.pyplot.figure(idfigure) | |
24 | fig.suptitle(title) |
|
24 | fig.suptitle(title) | |
25 |
|
25 | |||
26 | def makeAxes(idfigure, nrow, ncol, xpos, ypos, colspan, rowspan): |
|
26 | def makeAxes(idfigure, nrow, ncol, xpos, ypos, colspan, rowspan): | |
27 | fig = matplotlib.pyplot.figure(idfigure) |
|
27 | fig = matplotlib.pyplot.figure(idfigure) | |
28 | ax = matplotlib.pyplot.subplot2grid((nrow, ncol), (xpos, ypos), colspan=colspan, rowspan=rowspan) |
|
28 | ax = matplotlib.pyplot.subplot2grid((nrow, ncol), (xpos, ypos), colspan=colspan, rowspan=rowspan) | |
29 | return ax |
|
29 | return ax | |
30 |
|
30 | |||
31 | def setTextFromAxes(idfigure, ax, title): |
|
31 | def setTextFromAxes(idfigure, ax, title): | |
32 | fig = matplotlib.pyplot.figure(idfigure) |
|
32 | fig = matplotlib.pyplot.figure(idfigure) | |
33 | ax.annotate(title, xy=(.1, .99), |
|
33 | ax.annotate(title, xy=(.1, .99), | |
34 | xycoords='figure fraction', |
|
34 | xycoords='figure fraction', | |
35 | horizontalalignment='left', verticalalignment='top', |
|
35 | horizontalalignment='left', verticalalignment='top', | |
36 | fontsize=10) |
|
36 | fontsize=10) | |
37 |
|
37 | |||
38 | def pline(ax, x, y, xmin, xmax, ymin, ymax, xlabel, ylabel, title, firsttime): |
|
38 | def pline(ax, x, y, xmin, xmax, ymin, ymax, xlabel, ylabel, title, firsttime): | |
39 |
|
39 | |||
40 | if firsttime: |
|
40 | if firsttime: | |
41 | ax.plot(x, y) |
|
41 | ax.plot(x, y) | |
42 | ax.set_xlim([xmin,xmax]) |
|
42 | ax.set_xlim([xmin,xmax]) | |
43 | ax.set_ylim([ymin,ymax]) |
|
43 | ax.set_ylim([ymin,ymax]) | |
44 | ax.set_xlabel(xlabel, size=8) |
|
44 | ax.set_xlabel(xlabel, size=8) | |
45 | ax.set_ylabel(ylabel, size=8) |
|
45 | ax.set_ylabel(ylabel, size=8) | |
46 | ax.set_title(title, size=10) |
|
46 | ax.set_title(title, size=10) | |
47 | matplotlib.pyplot.tight_layout() |
|
47 | matplotlib.pyplot.tight_layout() | |
48 | else: |
|
48 | else: | |
49 | ax.lines[0].set_data(x,y) |
|
49 | ax.lines[0].set_data(x,y) | |
50 |
|
50 | |||
51 | def draw(idfigure): |
|
51 | def draw(idfigure): | |
52 |
|
52 | |||
53 | fig = matplotlib.pyplot.figure(idfigure) |
|
53 | fig = matplotlib.pyplot.figure(idfigure) | |
54 | fig.canvas.draw() |
|
54 | fig.canvas.draw() | |
55 |
|
55 | |||
56 | def pcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel, ylabel, title, firsttime, mesh): |
|
56 | def pcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel, ylabel, title, firsttime, mesh): | |
57 |
|
57 | |||
58 | if firsttime: |
|
58 | if firsttime: | |
59 | divider = make_axes_locatable(ax) |
|
59 | divider = make_axes_locatable(ax) | |
60 | ax_cb = divider.new_horizontal(size="4%", pad=0.05) |
|
60 | ax_cb = divider.new_horizontal(size="4%", pad=0.05) | |
61 | fig1 = ax.get_figure() |
|
61 | fig1 = ax.get_figure() | |
62 | fig1.add_axes(ax_cb) |
|
62 | fig1.add_axes(ax_cb) | |
63 |
|
63 | |||
64 | ax.set_xlim([xmin,xmax]) |
|
64 | ax.set_xlim([xmin,xmax]) | |
65 | ax.set_ylim([ymin,ymax]) |
|
65 | ax.set_ylim([ymin,ymax]) | |
66 | ax.set_xlabel(xlabel) |
|
66 | ax.set_xlabel(xlabel) | |
67 | ax.set_ylabel(ylabel) |
|
67 | ax.set_ylabel(ylabel) | |
68 | ax.set_title(title) |
|
68 | ax.set_title(title) | |
69 | print x |
|
69 | print x | |
70 | imesh=ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax) |
|
70 | imesh=ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax) | |
71 | matplotlib.pyplot.colorbar(imesh, cax=ax_cb) |
|
71 | matplotlib.pyplot.colorbar(imesh, cax=ax_cb) | |
72 | ax_cb.yaxis.tick_right() |
|
72 | ax_cb.yaxis.tick_right() | |
73 | for tl in ax_cb.get_yticklabels(): |
|
73 | for tl in ax_cb.get_yticklabels(): | |
74 | tl.set_visible(True) |
|
74 | tl.set_visible(True) | |
75 | ax_cb.yaxis.tick_right() |
|
75 | ax_cb.yaxis.tick_right() | |
76 | matplotlib.pyplot.tight_layout() |
|
76 | matplotlib.pyplot.tight_layout() | |
77 | return imesh |
|
77 | return imesh | |
78 | else: |
|
78 | else: | |
79 | # ax.set_xlim([xmin,xmax]) |
|
79 | # ax.set_xlim([xmin,xmax]) | |
80 | # ax.set_ylim([ymin,ymax]) |
|
80 | # ax.set_ylim([ymin,ymax]) | |
81 | ax.set_xlabel(xlabel) |
|
81 | ax.set_xlabel(xlabel) | |
82 | ax.set_ylabel(ylabel) |
|
82 | ax.set_ylabel(ylabel) | |
83 | ax.set_title(title) |
|
83 | ax.set_title(title) | |
84 |
|
84 | |||
85 | z = z.T |
|
85 | z = z.T | |
86 | # z = z[0:-1,0:-1] |
|
86 | # z = z[0:-1,0:-1] | |
87 | mesh.set_array(z.ravel()) |
|
87 | mesh.set_array(z.ravel()) | |
88 |
|
88 | |||
89 | return mesh |
|
89 | return mesh | |
90 |
|
90 | |||
91 | ########################################### |
|
91 | ########################################### | |
92 | #Actualizacion de las funciones del driver |
|
92 | #Actualizacion de las funciones del driver | |
93 | ########################################### |
|
93 | ########################################### | |
94 |
|
94 | |||
95 | def createFigure(idfigure, wintitle, width, height, facecolor="w"): |
|
95 | def createFigure(idfigure, wintitle, width, height, facecolor="w"): | |
96 |
|
96 | |||
97 | matplotlib.pyplot.ioff() |
|
97 | matplotlib.pyplot.ioff() | |
98 | fig = matplotlib.pyplot.matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor) |
|
98 | fig = matplotlib.pyplot.matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor) | |
99 | fig.canvas.manager.set_window_title(wintitle) |
|
99 | fig.canvas.manager.set_window_title(wintitle) | |
100 | fig.canvas.manager.resize(width, height) |
|
100 | fig.canvas.manager.resize(width, height) | |
101 | matplotlib.pyplot.ion() |
|
101 | matplotlib.pyplot.ion() | |
102 |
|
102 | |||
103 | return fig |
|
103 | return fig | |
104 |
|
104 | |||
105 | def setWinTitle(fig, title): |
|
105 | def setWinTitle(fig, title): | |
106 |
|
106 | |||
107 | fig.canvas.manager.set_window_title(title) |
|
107 | fig.canvas.manager.set_window_title(title) | |
108 |
|
108 | |||
109 | def setTitle(fig, title): |
|
109 | def setTitle(fig, title): | |
110 |
|
110 | |||
111 | fig.suptitle(title) |
|
111 | fig.suptitle(title) | |
112 |
|
112 | |||
113 | def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan): |
|
113 | def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan): | |
114 |
|
114 | |||
115 | matplotlib.pyplot.figure(fig.number) |
|
115 | matplotlib.pyplot.figure(fig.number) | |
116 | axes = matplotlib.pyplot.subplot2grid((nrow, ncol), |
|
116 | axes = matplotlib.pyplot.subplot2grid((nrow, ncol), | |
117 | (xpos, ypos), |
|
117 | (xpos, ypos), | |
118 | colspan=colspan, |
|
118 | colspan=colspan, | |
119 | rowspan=rowspan) |
|
119 | rowspan=rowspan) | |
120 | return axes |
|
120 | return axes | |
121 |
|
121 | |||
122 | def setAxesText(ax, text): |
|
122 | def setAxesText(ax, text): | |
123 |
|
123 | |||
124 | ax.annotate(text, |
|
124 | ax.annotate(text, | |
125 | xy = (.1, .99), |
|
125 | xy = (.1, .99), | |
126 | xycoords = 'figure fraction', |
|
126 | xycoords = 'figure fraction', | |
127 | horizontalalignment = 'left', |
|
127 | horizontalalignment = 'left', | |
128 | verticalalignment = 'top', |
|
128 | verticalalignment = 'top', | |
129 | fontsize = 10) |
|
129 | fontsize = 10) | |
130 |
|
130 | |||
131 | def printLabels(ax, xlabel, ylabel, title): |
|
131 | def printLabels(ax, xlabel, ylabel, title): | |
132 |
|
132 | |||
133 | ax.set_xlabel(xlabel, size=11) |
|
133 | ax.set_xlabel(xlabel, size=11) | |
134 | ax.set_ylabel(ylabel, size=11) |
|
134 | ax.set_ylabel(ylabel, size=11) | |
135 | ax.set_title(title, size=12) |
|
135 | ax.set_title(title, size=12) | |
136 |
|
136 | |||
137 |
def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', |
|
137 | def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', | |
|
138 | ticksize=9, xtick_visible=True, ytick_visible=True, | |||
|
139 | nxticks=4, nyticks=10, | |||
|
140 | grid=None): | |||
138 |
|
|
141 | ||
|
142 | """ | |||
|
143 | ||||
|
144 | Input: | |||
|
145 | grid : None, 'both', 'x', 'y' | |||
|
146 | """ | |||
|
147 | ||||
139 | ax.plot(x, y) |
|
148 | ax.plot(x, y) | |
140 | ax.set_xlim([xmin,xmax]) |
|
149 | ax.set_xlim([xmin,xmax]) | |
141 | ax.set_ylim([ymin,ymax]) |
|
150 | ax.set_ylim([ymin,ymax]) | |
142 |
|
151 | |||
143 | printLabels(ax, xlabel, ylabel, title) |
|
152 | printLabels(ax, xlabel, ylabel, title) | |
144 |
|
153 | |||
145 | for tick in ax.yaxis.get_major_ticks(): |
|
154 | ###################################################### | |
146 | tick.label.set_fontsize(ticksize) |
|
155 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/nxticks) + int(xmin) | |
|
156 | ax.set_xticks(xtickspos) | |||
|
157 | ||||
|
158 | for tick in ax.get_xticklabels(): | |||
|
159 | tick.set_visible(xtick_visible) | |||
147 |
|
160 | |||
148 | for tick in ax.xaxis.get_major_ticks(): |
|
161 | for tick in ax.xaxis.get_major_ticks(): | |
149 | tick.label.set_fontsize(ticksize) |
|
162 | tick.label.set_fontsize(ticksize) | |
150 |
|
|
163 | ||
|
164 | ###################################################### | |||
|
165 | for tick in ax.get_yticklabels(): | |||
|
166 | tick.set_visible(ytick_visible) | |||
|
167 | ||||
|
168 | for tick in ax.yaxis.get_major_ticks(): | |||
|
169 | tick.label.set_fontsize(ticksize) | |||
|
170 | ||||
|
171 | ###################################################### | |||
|
172 | if grid != None: | |||
|
173 | ax.grid(b=True, which='major', axis=grid) | |||
|
174 | ||||
151 | matplotlib.pyplot.tight_layout() |
|
175 | matplotlib.pyplot.tight_layout() | |
152 |
|
176 | |||
153 | iplot = ax.lines[-1] |
|
177 | iplot = ax.lines[-1] | |
154 |
|
178 | |||
155 | return iplot |
|
179 | return iplot | |
156 |
|
180 | |||
157 | def pline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
181 | def pline(iplot, x, y, xlabel='', ylabel='', title=''): | |
158 |
|
182 | |||
159 | ax = iplot.get_axes() |
|
183 | ax = iplot.get_axes() | |
160 |
|
184 | |||
161 | printLabels(ax, xlabel, ylabel, title) |
|
185 | printLabels(ax, xlabel, ylabel, title) | |
162 |
|
186 | |||
163 | iplot.set_data(x, y) |
|
187 | iplot.set_data(x, y) | |
164 |
|
188 | |||
165 | def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel='', ylabel='', title='', ticksize = 9, cblabel=''): |
|
189 | def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel='', ylabel='', title='', ticksize = 9, cblabel=''): | |
166 |
|
190 | |||
167 | divider = make_axes_locatable(ax) |
|
191 | divider = make_axes_locatable(ax) | |
168 | ax_cb = divider.new_horizontal(size="4%", pad=0.05) |
|
192 | ax_cb = divider.new_horizontal(size="4%", pad=0.05) | |
169 | fig = ax.get_figure() |
|
193 | fig = ax.get_figure() | |
170 | fig.add_axes(ax_cb) |
|
194 | fig.add_axes(ax_cb) | |
171 |
|
195 | |||
172 | ax.set_xlim([xmin,xmax]) |
|
196 | ax.set_xlim([xmin,xmax]) | |
173 | ax.set_ylim([ymin,ymax]) |
|
197 | ax.set_ylim([ymin,ymax]) | |
174 |
|
198 | |||
175 | printLabels(ax, xlabel, ylabel, title) |
|
199 | printLabels(ax, xlabel, ylabel, title) | |
176 |
|
200 | |||
177 | imesh = ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax) |
|
201 | imesh = ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax) | |
178 | cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb) |
|
202 | cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb) | |
179 | cb.set_label(cblabel) |
|
203 | cb.set_label(cblabel) | |
180 |
|
204 | |||
181 | ax_cb.yaxis.tick_right() |
|
205 | ax_cb.yaxis.tick_right() | |
182 |
|
206 | |||
183 | for tl in ax_cb.get_yticklabels(): |
|
207 | for tl in ax_cb.get_yticklabels(): | |
184 | tl.set_visible(True) |
|
208 | tl.set_visible(True) | |
185 |
|
209 | |||
186 | for tick in ax.yaxis.get_major_ticks(): |
|
210 | for tick in ax.yaxis.get_major_ticks(): | |
187 | tick.label.set_fontsize(ticksize) |
|
211 | tick.label.set_fontsize(ticksize) | |
188 |
|
212 | |||
189 | for tick in ax.xaxis.get_major_ticks(): |
|
213 | for tick in ax.xaxis.get_major_ticks(): | |
190 | tick.label.set_fontsize(ticksize) |
|
214 | tick.label.set_fontsize(ticksize) | |
191 |
|
215 | |||
192 | for tick in cb.ax.get_yticklabels(): |
|
216 | for tick in cb.ax.get_yticklabels(): | |
193 | tick.set_fontsize(ticksize) |
|
217 | tick.set_fontsize(ticksize) | |
194 |
|
218 | |||
195 | ax_cb.yaxis.tick_right() |
|
219 | ax_cb.yaxis.tick_right() | |
196 | matplotlib.pyplot.tight_layout() |
|
220 | matplotlib.pyplot.tight_layout() | |
197 |
|
221 | |||
198 | return imesh |
|
222 | return imesh | |
199 |
|
223 | |||
200 | def pcolor(imesh, z, xlabel='', ylabel='', title=''): |
|
224 | def pcolor(imesh, z, xlabel='', ylabel='', title=''): | |
201 |
|
225 | |||
202 | z = z.T |
|
226 | z = z.T | |
203 |
|
227 | |||
204 | ax = imesh.get_axes() |
|
228 | ax = imesh.get_axes() | |
205 |
|
229 | |||
206 | printLabels(ax, xlabel, ylabel, title) |
|
230 | printLabels(ax, xlabel, ylabel, title) | |
207 |
|
231 | |||
208 | imesh.set_array(z.ravel()) |
|
232 | imesh.set_array(z.ravel()) | |
209 |
|
233 | |||
210 | def draw(fig): |
|
234 | def draw(fig): | |
211 |
|
235 | |||
212 | if type(fig) == 'int': |
|
236 | if type(fig) == 'int': | |
213 | raise ValueError, "This parameter should be of tpye matplotlib figure" |
|
237 | raise ValueError, "This parameter should be of tpye matplotlib figure" | |
214 |
|
238 | |||
215 | fig.canvas.draw() No newline at end of file |
|
239 | fig.canvas.draw() |
@@ -1,215 +1,229 | |||||
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 SpectraPlot(Figure): |
|
5 | class SpectraPlot(Figure): | |
6 |
|
6 | |||
7 | __isConfig = None |
|
7 | __isConfig = None | |
|
8 | __nsubplots = None | |||
|
9 | ||||
|
10 | WIDTHPROF = None | |||
|
11 | HEIGHTPROF = None | |||
8 |
|
12 | |||
9 | def __init__(self): |
|
13 | def __init__(self): | |
10 |
|
14 | |||
11 | self.__isConfig = False |
|
15 | self.__isConfig = False | |
|
16 | self.__nsubplots = 1 | |||
|
17 | ||||
12 | self.WIDTH = 300 |
|
18 | self.WIDTH = 300 | |
13 | self.HEIGHT = 400 |
|
19 | self.HEIGHT = 400 | |
|
20 | self.WIDTHPROF = 120 | |||
|
21 | self.HEIGHTPROF = 0 | |||
14 |
|
22 | |||
15 | def getSubplots(self): |
|
23 | def getSubplots(self): | |
16 |
|
24 | |||
17 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
25 | ncol = int(numpy.sqrt(self.nplots)+0.9) | |
18 | nrow = int(self.nplots*1./ncol + 0.9) |
|
26 | nrow = int(self.nplots*1./ncol + 0.9) | |
19 | return nrow, ncol |
|
|||
20 |
|
27 | |||
21 | def setAxesWithOutProfiles(self, nrow, ncol): |
|
28 | return nrow, ncol | |
|
29 | ||||
|
30 | def setup(self, idfigure, nplots, wintitle, showprofile=True): | |||
|
31 | ||||
|
32 | self.__showprofile = showprofile | |||
|
33 | self.nplots = nplots | |||
22 |
|
34 | |||
|
35 | ncolspan = 1 | |||
23 | colspan = 1 |
|
36 | colspan = 1 | |
24 | rowspan = 1 |
|
37 | if showprofile: | |
25 |
|
|
38 | ncolspan = 3 | |
|
39 | colspan = 2 | |||
|
40 | self.__nsubplots = 2 | |||
|
41 | self.WIDTH += self.WIDTHPROF | |||
|
42 | self.HEIGHT += self.HEIGHTPROF | |||
|
43 | ||||
|
44 | self.createFigure(idfigure, wintitle) | |||
26 |
|
45 | |||
27 | for y in range(nrow): |
|
46 | nrow, ncol = self.getSubplots() | |
28 | for x in range(ncol): |
|
|||
29 | if counter < self.nplots: |
|
|||
30 | self.addAxes(nrow, ncol, y, x, colspan, rowspan) |
|
|||
31 | counter += 1 |
|
|||
32 |
|
||||
33 | def setAxesWithProfiles(self, nrow, ncol): |
|
|||
34 |
|
47 | |||
35 | colspan = 1 |
|
|||
36 | rowspan = 1 |
|
|||
37 | factor = 2 |
|
|||
38 | ncol = ncol*factor |
|
|||
39 | counter = 0 |
|
48 | counter = 0 | |
40 |
|
||||
41 | for y in range(nrow): |
|
49 | for y in range(nrow): | |
42 | for x in range(ncol): |
|
50 | for x in range(ncol): | |
43 | if counter < self.nplots*factor: |
|
51 | ||
44 | # plt.subplot2grid((nrow, ncol), (y, x), colspan=colspan, rowspan=rowspan) |
|
52 | if counter >= self.nplots: | |
45 | self.addAxes(nrow, ncol, y, x, colspan, rowspan) |
|
53 | break | |
|
54 | ||||
|
55 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |||
|
56 | ||||
|
57 | if showprofile: | |||
|
58 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+2, 1, 1) | |||
|
59 | ||||
46 | counter += 1 |
|
60 | counter += 1 | |
47 |
|
61 | |||
48 |
def |
|
62 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', | |
49 |
|
||||
50 | self.init(idfigure, nplots, wintitle) |
|
|||
51 |
|
||||
52 | nrow, ncol = self.getSubplots() |
|
|||
53 |
|
||||
54 | if showprofile: |
|
|||
55 | self.setAxesWithProfiles(nrow, ncol) |
|
|||
56 | else: |
|
|||
57 | self.setAxesWithOutProfiles(nrow, ncol) |
|
|||
58 |
|
||||
59 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile=False, |
|
|||
60 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): |
|
63 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): | |
61 |
|
64 | |||
62 | """ |
|
65 | """ | |
63 |
|
66 | |||
64 | Input: |
|
67 | Input: | |
65 | dataOut : |
|
68 | dataOut : | |
66 | idfigure : |
|
69 | idfigure : | |
67 | wintitle : |
|
70 | wintitle : | |
68 | channelList : |
|
71 | channelList : | |
69 | showProfile : |
|
72 | showProfile : | |
70 | xmin : None, |
|
73 | xmin : None, | |
71 | xmax : None, |
|
74 | xmax : None, | |
72 | ymin : None, |
|
75 | ymin : None, | |
73 | ymax : None, |
|
76 | ymax : None, | |
74 | zmin : None, |
|
77 | zmin : None, | |
75 | zmax : None |
|
78 | zmax : None | |
76 | """ |
|
79 | """ | |
77 |
|
80 | |||
78 | if channelList == None: |
|
81 | if channelList == None: | |
79 | channelIndexList = dataOut.channelIndexList |
|
82 | channelIndexList = dataOut.channelIndexList | |
80 | else: |
|
83 | else: | |
81 | channelIndexList = [] |
|
84 | channelIndexList = [] | |
82 | for channel in channelList: |
|
85 | for channel in channelList: | |
83 | if channel not in dataOut.channelList: |
|
86 | if channel not in dataOut.channelList: | |
84 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
87 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
85 | channelIndexList.append(channel) |
|
88 | channelIndexList.append(channel) | |
86 |
|
89 | |||
87 | x = dataOut.getVelRange(1) |
|
90 | x = dataOut.getVelRange(1) | |
88 | y = dataOut.heightList |
|
91 | y = dataOut.heightList | |
89 | z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:]) |
|
92 | z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:]) | |
90 |
|
93 | |||
91 | noise = dataOut.getNoise() |
|
94 | noise = dataOut.getNoise() | |
92 |
|
95 | |||
93 | if not self.__isConfig: |
|
96 | if not self.__isConfig: | |
94 |
|
97 | |||
95 | nplots = len(channelIndexList) |
|
98 | nplots = len(channelIndexList) | |
96 |
|
99 | |||
97 | self.setup(idfigure=idfigure, |
|
100 | self.setup(idfigure=idfigure, | |
98 | nplots=nplots, |
|
101 | nplots=nplots, | |
99 | wintitle=wintitle, |
|
102 | wintitle=wintitle, | |
100 | showprofile=showprofile) |
|
103 | showprofile=showprofile) | |
101 |
|
104 | |||
102 | if xmin == None: xmin = numpy.nanmin(x) |
|
105 | if xmin == None: xmin = numpy.nanmin(x) | |
103 | if xmax == None: xmax = numpy.nanmax(x) |
|
106 | if xmax == None: xmax = numpy.nanmax(x) | |
104 | if ymin == None: ymin = numpy.nanmin(y) |
|
107 | if ymin == None: ymin = numpy.nanmin(y) | |
105 | if ymax == None: ymax = numpy.nanmax(y) |
|
108 | if ymax == None: ymax = numpy.nanmax(y) | |
106 | if zmin == None: zmin = numpy.nanmin(z)*0.9 |
|
109 | if zmin == None: zmin = numpy.nanmin(z)*0.9 | |
107 | if zmax == None: zmax = numpy.nanmax(z)*0.9 |
|
110 | if zmax == None: zmax = numpy.nanmax(z)*0.9 | |
108 |
|
111 | |||
109 | self.__isConfig = True |
|
112 | self.__isConfig = True | |
110 |
|
113 | |||
111 | thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime) |
|
114 | thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime) | |
112 | title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
115 | title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
113 | xlabel = "Velocity (m/s)" |
|
116 | xlabel = "Velocity (m/s)" | |
114 | ylabel = "Range (Km)" |
|
117 | ylabel = "Range (Km)" | |
115 |
|
118 | |||
116 | self.setWinTitle(title) |
|
119 | self.setWinTitle(title) | |
117 |
|
120 | |||
|
121 | if self.__showprofile: | |||
|
122 | avg = numpy.average(z, axis=1) | |||
|
123 | ||||
118 | for i in range(self.nplots): |
|
124 | for i in range(self.nplots): | |
119 | title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noise[i]) |
|
125 | title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noise[i]) | |
120 | zchannel = z[i,:,:] |
|
126 | axes = self.axesList[i*self.__nsubplots] | |
121 |
|
127 | axes.pcolor(x, y, z[i,:,:], | ||
122 | axes = self.axesList[i] |
|
|||
123 | axes.pcolor(x, y, zchannel, |
|
|||
124 | 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, | |
125 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
129 | xlabel=xlabel, ylabel=ylabel, title=title, | |
126 |
ticksize=9, cblabel=' |
|
130 | ticksize=9, cblabel='') | |
|
131 | ||||
|
132 | if self.__showprofile: | |||
|
133 | axes = self.axesList[i*self.__nsubplots +1] | |||
|
134 | axes.pline(avg[i], y, | |||
|
135 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |||
|
136 | xlabel='dB', ylabel='', title='', | |||
|
137 | ytick_visible=False, | |||
|
138 | grid='x') | |||
127 |
|
139 | |||
128 | self.draw() |
|
140 | self.draw() | |
129 |
|
141 | |||
130 | class Scope(Figure): |
|
142 | class Scope(Figure): | |
131 |
|
143 | |||
132 | __isConfig = None |
|
144 | __isConfig = None | |
133 |
|
145 | |||
134 | def __init__(self): |
|
146 | def __init__(self): | |
135 |
|
147 | |||
136 | self.__isConfig = False |
|
148 | self.__isConfig = False | |
137 | self.WIDTH = 600 |
|
149 | self.WIDTH = 600 | |
138 | self.HEIGHT = 200 |
|
150 | self.HEIGHT = 200 | |
139 |
|
151 | |||
140 | def getSubplots(self): |
|
152 | def getSubplots(self): | |
141 |
|
153 | |||
142 | nrow = self.nplots |
|
154 | nrow = self.nplots | |
143 | ncol = 3 |
|
155 | ncol = 3 | |
144 | return nrow, ncol |
|
156 | return nrow, ncol | |
145 |
|
157 | |||
146 | def setup(self, idfigure, nplots, wintitle): |
|
158 | def setup(self, idfigure, nplots, wintitle): | |
147 |
|
159 | |||
148 |
self. |
|
160 | self.createFigure(idfigure, wintitle) | |
149 |
|
161 | |||
150 | nrow,ncol = self.getSubplots() |
|
162 | nrow,ncol = self.getSubplots() | |
151 | colspan = 3 |
|
163 | colspan = 3 | |
152 | rowspan = 1 |
|
164 | rowspan = 1 | |
153 |
|
165 | |||
154 | for i in range(nplots): |
|
166 | for i in range(nplots): | |
155 | self.addAxes(nrow, ncol, i, 0, colspan, rowspan) |
|
167 | self.addAxes(nrow, ncol, i, 0, colspan, rowspan) | |
|
168 | ||||
|
169 | self.nplots = nplots | |||
156 |
|
170 | |||
157 | def run(self, dataOut, idfigure, wintitle="", channelList=None, |
|
171 | def run(self, dataOut, idfigure, wintitle="", channelList=None, | |
158 | xmin=None, xmax=None, ymin=None, ymax=None): |
|
172 | xmin=None, xmax=None, ymin=None, ymax=None): | |
159 |
|
173 | |||
160 | """ |
|
174 | """ | |
161 |
|
175 | |||
162 | Input: |
|
176 | Input: | |
163 | dataOut : |
|
177 | dataOut : | |
164 | idfigure : |
|
178 | idfigure : | |
165 | wintitle : |
|
179 | wintitle : | |
166 | channelList : |
|
180 | channelList : | |
167 | xmin : None, |
|
181 | xmin : None, | |
168 | xmax : None, |
|
182 | xmax : None, | |
169 | ymin : None, |
|
183 | ymin : None, | |
170 | ymax : None, |
|
184 | ymax : None, | |
171 | """ |
|
185 | """ | |
172 |
|
186 | |||
173 | if channelList == None: |
|
187 | if channelList == None: | |
174 | channelList = dataOut.channelList |
|
188 | channelList = dataOut.channelList | |
175 |
|
189 | |||
176 | x = dataOut.heightList |
|
190 | x = dataOut.heightList | |
177 | y = dataOut.data[channelList,:] * numpy.conjugate(dataOut.data[channelList,:]) |
|
191 | y = dataOut.data[channelList,:] * numpy.conjugate(dataOut.data[channelList,:]) | |
178 | y = y.real |
|
192 | y = y.real | |
179 |
|
193 | |||
180 | noise = dataOut.getNoise() |
|
194 | noise = dataOut.getNoise() | |
181 |
|
195 | |||
182 | if not self.__isConfig: |
|
196 | if not self.__isConfig: | |
183 | nplots = len(channelList) |
|
197 | nplots = len(channelList) | |
184 |
|
198 | |||
185 | self.setup(idfigure=idfigure, |
|
199 | self.setup(idfigure=idfigure, | |
186 | nplots=nplots, |
|
200 | nplots=nplots, | |
187 | wintitle=wintitle) |
|
201 | wintitle=wintitle) | |
188 |
|
202 | |||
189 | if xmin == None: xmin = numpy.nanmin(x) |
|
203 | if xmin == None: xmin = numpy.nanmin(x) | |
190 | if xmax == None: xmax = numpy.nanmax(x) |
|
204 | if xmax == None: xmax = numpy.nanmax(x) | |
191 | if ymin == None: ymin = numpy.nanmin(y) |
|
205 | if ymin == None: ymin = numpy.nanmin(y) | |
192 | if ymax == None: ymax = numpy.nanmax(y) |
|
206 | if ymax == None: ymax = numpy.nanmax(y) | |
193 |
|
207 | |||
194 | self.__isConfig = True |
|
208 | self.__isConfig = True | |
195 |
|
209 | |||
196 |
|
210 | |||
197 | thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime) |
|
211 | thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime) | |
198 | title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
212 | title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
199 | xlabel = "Range (Km)" |
|
213 | xlabel = "Range (Km)" | |
200 | ylabel = "Intensity" |
|
214 | ylabel = "Intensity" | |
201 |
|
215 | |||
202 | self.setWinTitle(title) |
|
216 | self.setWinTitle(title) | |
203 |
|
217 | |||
204 | for i in range(len(self.axesList)): |
|
218 | for i in range(len(self.axesList)): | |
205 | title = "Channel %d: %4.2fdB" %(i, noise[i]) |
|
219 | title = "Channel %d: %4.2fdB" %(i, noise[i]) | |
206 | axes = self.axesList[i] |
|
220 | axes = self.axesList[i] | |
207 | ychannel = y[i,:] |
|
221 | ychannel = y[i,:] | |
208 | axes.pline(x, ychannel, |
|
222 | axes.pline(x, ychannel, | |
209 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
223 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |
210 | xlabel=xlabel, ylabel=ylabel, title=title) |
|
224 | xlabel=xlabel, ylabel=ylabel, title=title) | |
211 |
|
225 | |||
212 | self.draw() |
|
226 | self.draw() | |
213 |
|
227 | |||
214 |
|
228 | |||
215 | No newline at end of file |
|
229 |
General Comments 0
You need to be logged in to leave comments.
Login now