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