@@ -1,74 +1,78 | |||
|
1 | 1 | VERSIONS: |
|
2 | 2 | |
|
3 | 3 | 2.1.2: |
|
4 | 4 | -jroutils_ftp.py: Bug fixed, Any error sending file stopped the Server Thread |
|
5 | 5 | Server thread opens and closes remote server each time file list is sent |
|
6 | 6 | -jroplot_spectra.py: Noise path was not being created when noise data is saved. |
|
7 | 7 | -jroIO_base.py: startTime can be greater than endTime. Example: SpreadF [18:00 - 07:00] |
|
8 | 8 | |
|
9 | 9 | 2.1.3: |
|
10 | 10 | -jroplot_heispectra.py: SpectraHeisScope was not showing the right channels |
|
11 | 11 | -jroproc_voltage.py: Bug fixed selecting profiles (self.nProfiles took a wrong value), |
|
12 | 12 | Bug fixed selecting heights by block (selecting profiles instead heights) |
|
13 | 13 | -jroproc_voltage.py: New feature added: decoding data by block using FFT. |
|
14 | 14 | -jroIO_heispectra.py: Bug fixed in FitsReader. Using local Fits instance instead schainpy.mode.data.jrodata.Fits. |
|
15 | 15 | -jroIO_heispectra.py: Channel index list does not exist. |
|
16 | 16 | |
|
17 | 17 | 2.1.3.1: |
|
18 | 18 | -GUI: every icon were resized |
|
19 | 19 | -jroproc_voltage.py: Print a message when "Read from code" option is selected and the code is not defined inside data file |
|
20 | 20 | |
|
21 | 21 | 2.1.3.2: |
|
22 | 22 | -GUI: user interaction enhanced |
|
23 | 23 | -controller_api.py: Safe access to ControllerThead |
|
24 | 24 | |
|
25 | 25 | 2.1.3.3: |
|
26 | 26 | -Colored Button Icons were added to GUI |
|
27 | 27 | |
|
28 | 28 | 2.1.4: |
|
29 | 29 | -Sending error notifications to signal chain administrator |
|
30 | 30 | -Login to email server added |
|
31 | 31 | |
|
32 | 32 | 2.1.4.1: |
|
33 | 33 | -Send notifications when an error different to ValueError is detected |
|
34 | 34 | |
|
35 | 35 | 2.1.4.2: |
|
36 | 36 | -A new Plotter Class was added |
|
37 | 37 | -Project.start() does not accept filename as a parameter anymore |
|
38 | 38 | |
|
39 | 39 | 2.1.5: |
|
40 | 40 | -serializer module added to Signal Chain |
|
41 | 41 | -jroplotter.py added to Signal Chain |
|
42 | 42 | |
|
43 | 43 | 2.2.0: |
|
44 | 44 | -GUI: use of external plotter |
|
45 | 45 | -Compatible with matplotlib 1.5.0 |
|
46 | 46 | |
|
47 | 47 | 2.2.1: |
|
48 | 48 | -Bugs fixed in GUI |
|
49 | 49 | -Views were improved in GUI |
|
50 | 50 | -Support to MST-ISR experiments |
|
51 | 51 | -Bug fixed getting noise using hyldebrant. (minimum number of points > 20%) |
|
52 | 52 | -handleError added to jroplotter.py |
|
53 | 53 | |
|
54 | 54 | 2.2.2: |
|
55 | 55 | -VoltageProc: ProfileSelector, Reshape, Decoder with nTxs!=1 and getblock=True was tested |
|
56 | 56 | -Rawdata and testRawdata.py added to Signal Chain project |
|
57 | 57 | |
|
58 | 58 | 2.2.3: |
|
59 | 59 | -Bug fixed in GUI: Error getting(reading) Code value |
|
60 | 60 | -Bug fixed in GUI: Flip option always needs channelList field |
|
61 | 61 | -Bug fixed in jrodata: when one branch modified a value in "dataOut" (example: dataOut.code) this value |
|
62 | 62 | was modified for every branch (because this was a reference). It was modified in data.copy() |
|
63 | 63 | -Bug fixed in jroproc_voltage.profileSelector(): rangeList replaces to profileRangeList. |
|
64 | 64 | |
|
65 | 65 | |
|
66 | 66 | 2.2.3.1: |
|
67 | 67 | -Filtering block by time has been added. |
|
68 | 68 | -Bug fixed plotting RTI, CoherenceMap and others using xmin and xmax parameters. The first day worked |
|
69 | 69 | properly but the next days did not. |
|
70 | 70 | |
|
71 | 71 | 2.2.4: |
|
72 | 72 | -jroproc_spectra_lags.py added to schainpy |
|
73 | 73 | -Bug fixed in schainGUI: ProcUnit was created with the same id in some cases. |
|
74 | 74 | -Bug fixed in jroHeaderIO: Header size validation. |
|
75 | ||
|
76 | 2.2.4.1: | |
|
77 | -jroIO_usrp.py is update to read Sandra's data | |
|
78 | -decimation in Spectra and RTI plots is always enabled. No newline at end of file |
@@ -1,1282 +1,1290 | |||
|
1 | 1 | ''' |
|
2 | 2 | Created on September , 2012 |
|
3 | 3 | @author: |
|
4 | 4 | ''' |
|
5 | 5 | |
|
6 | 6 | import sys |
|
7 | 7 | import ast |
|
8 | 8 | import datetime |
|
9 | 9 | import traceback |
|
10 | 10 | import schainpy |
|
11 | 11 | import schainpy.admin |
|
12 | 12 | |
|
13 | 13 | from xml.etree.ElementTree import ElementTree, Element, SubElement, tostring |
|
14 | 14 | from xml.dom import minidom |
|
15 | 15 | |
|
16 | 16 | from schainpy.model import * |
|
17 | 17 | from time import sleep |
|
18 | 18 | |
|
19 | 19 | def prettify(elem): |
|
20 | 20 | """Return a pretty-printed XML string for the Element. |
|
21 | 21 | """ |
|
22 | 22 | rough_string = tostring(elem, 'utf-8') |
|
23 | 23 | reparsed = minidom.parseString(rough_string) |
|
24 | 24 | return reparsed.toprettyxml(indent=" ") |
|
25 | 25 | |
|
26 | 26 | class ParameterConf(): |
|
27 | 27 | |
|
28 | 28 | id = None |
|
29 | 29 | name = None |
|
30 | 30 | value = None |
|
31 | 31 | format = None |
|
32 | 32 | |
|
33 | 33 | __formated_value = None |
|
34 | 34 | |
|
35 | 35 | ELEMENTNAME = 'Parameter' |
|
36 | 36 | |
|
37 | 37 | def __init__(self): |
|
38 | 38 | |
|
39 | 39 | self.format = 'str' |
|
40 | 40 | |
|
41 | 41 | def getElementName(self): |
|
42 | 42 | |
|
43 | 43 | return self.ELEMENTNAME |
|
44 | 44 | |
|
45 | 45 | def getValue(self): |
|
46 | 46 | |
|
47 | 47 | value = self.value |
|
48 | 48 | format = self.format |
|
49 | 49 | |
|
50 | 50 | if self.__formated_value != None: |
|
51 | 51 | |
|
52 | 52 | return self.__formated_value |
|
53 | 53 | |
|
54 | 54 | if format == 'str': |
|
55 | 55 | self.__formated_value = str(value) |
|
56 | 56 | return self.__formated_value |
|
57 | 57 | |
|
58 | 58 | if value == '': |
|
59 | 59 | raise ValueError, "%s: This parameter value is empty" %self.name |
|
60 | 60 | |
|
61 | 61 | if format == 'list': |
|
62 | 62 | strList = value.split(',') |
|
63 | 63 | |
|
64 | 64 | self.__formated_value = strList |
|
65 | 65 | |
|
66 | 66 | return self.__formated_value |
|
67 | 67 | |
|
68 | 68 | if format == 'intlist': |
|
69 | 69 | """ |
|
70 | 70 | Example: |
|
71 | 71 | value = (0,1,2) |
|
72 | 72 | """ |
|
73 | 73 | |
|
74 | 74 | new_value = ast.literal_eval(value) |
|
75 | 75 | |
|
76 | 76 | if type(new_value) not in (tuple, list): |
|
77 | 77 | new_value = [int(new_value)] |
|
78 | 78 | |
|
79 | 79 | self.__formated_value = new_value |
|
80 | 80 | |
|
81 | 81 | return self.__formated_value |
|
82 | 82 | |
|
83 | 83 | if format == 'floatlist': |
|
84 | 84 | """ |
|
85 | 85 | Example: |
|
86 | 86 | value = (0.5, 1.4, 2.7) |
|
87 | 87 | """ |
|
88 | 88 | |
|
89 | 89 | new_value = ast.literal_eval(value) |
|
90 | 90 | |
|
91 | 91 | if type(new_value) not in (tuple, list): |
|
92 | 92 | new_value = [float(new_value)] |
|
93 | 93 | |
|
94 | 94 | self.__formated_value = new_value |
|
95 | 95 | |
|
96 | 96 | return self.__formated_value |
|
97 | 97 | |
|
98 | 98 | if format == 'date': |
|
99 | 99 | strList = value.split('/') |
|
100 | 100 | intList = [int(x) for x in strList] |
|
101 | 101 | date = datetime.date(intList[0], intList[1], intList[2]) |
|
102 | 102 | |
|
103 | 103 | self.__formated_value = date |
|
104 | 104 | |
|
105 | 105 | return self.__formated_value |
|
106 | 106 | |
|
107 | 107 | if format == 'time': |
|
108 | 108 | strList = value.split(':') |
|
109 | 109 | intList = [int(x) for x in strList] |
|
110 | 110 | time = datetime.time(intList[0], intList[1], intList[2]) |
|
111 | 111 | |
|
112 | 112 | self.__formated_value = time |
|
113 | 113 | |
|
114 | 114 | return self.__formated_value |
|
115 | 115 | |
|
116 | 116 | if format == 'pairslist': |
|
117 | 117 | """ |
|
118 | 118 | Example: |
|
119 | 119 | value = (0,1),(1,2) |
|
120 | 120 | """ |
|
121 | 121 | |
|
122 | 122 | new_value = ast.literal_eval(value) |
|
123 | 123 | |
|
124 | 124 | if type(new_value) not in (tuple, list): |
|
125 | 125 | raise ValueError, "%s has to be a tuple or list of pairs" %value |
|
126 | 126 | |
|
127 | 127 | if type(new_value[0]) not in (tuple, list): |
|
128 | 128 | if len(new_value) != 2: |
|
129 | 129 | raise ValueError, "%s has to be a tuple or list of pairs" %value |
|
130 | 130 | new_value = [new_value] |
|
131 | 131 | |
|
132 | 132 | for thisPair in new_value: |
|
133 | 133 | if len(thisPair) != 2: |
|
134 | 134 | raise ValueError, "%s has to be a tuple or list of pairs" %value |
|
135 | 135 | |
|
136 | 136 | self.__formated_value = new_value |
|
137 | 137 | |
|
138 | 138 | return self.__formated_value |
|
139 | 139 | |
|
140 | 140 | if format == 'multilist': |
|
141 | 141 | """ |
|
142 | 142 | Example: |
|
143 | 143 | value = (0,1,2),(3,4,5) |
|
144 | 144 | """ |
|
145 | 145 | multiList = ast.literal_eval(value) |
|
146 | 146 | |
|
147 | 147 | if type(multiList[0]) == int: |
|
148 | 148 | multiList = ast.literal_eval("(" + value + ")") |
|
149 | 149 | |
|
150 | 150 | self.__formated_value = multiList |
|
151 | 151 | |
|
152 | 152 | return self.__formated_value |
|
153 | 153 | |
|
154 | 154 | if format == 'bool': |
|
155 | 155 | value = int(value) |
|
156 | 156 | |
|
157 | 157 | if format == 'int': |
|
158 | 158 | value = float(value) |
|
159 | 159 | |
|
160 | 160 | format_func = eval(format) |
|
161 | 161 | |
|
162 | 162 | self.__formated_value = format_func(value) |
|
163 | 163 | |
|
164 | 164 | return self.__formated_value |
|
165 | 165 | |
|
166 | 166 | def updateId(self, new_id): |
|
167 | 167 | |
|
168 | 168 | self.id = str(new_id) |
|
169 | 169 | |
|
170 | 170 | def setup(self, id, name, value, format='str'): |
|
171 | 171 | |
|
172 | 172 | self.id = str(id) |
|
173 | 173 | self.name = name |
|
174 | 174 | self.value = str(value) |
|
175 | 175 | self.format = str.lower(format) |
|
176 | 176 | |
|
177 | 177 | self.getValue() |
|
178 | 178 | |
|
179 | 179 | return 1 |
|
180 | 180 | |
|
181 | 181 | def update(self, name, value, format='str'): |
|
182 | 182 | |
|
183 | 183 | self.name = name |
|
184 | 184 | self.value = str(value) |
|
185 | 185 | self.format = format |
|
186 | 186 | |
|
187 | 187 | def makeXml(self, opElement): |
|
188 | 188 | |
|
189 | 189 | parmElement = SubElement(opElement, self.ELEMENTNAME) |
|
190 | 190 | parmElement.set('id', str(self.id)) |
|
191 | 191 | parmElement.set('name', self.name) |
|
192 | 192 | parmElement.set('value', self.value) |
|
193 | 193 | parmElement.set('format', self.format) |
|
194 | 194 | |
|
195 | 195 | def readXml(self, parmElement): |
|
196 | 196 | |
|
197 | 197 | self.id = parmElement.get('id') |
|
198 | 198 | self.name = parmElement.get('name') |
|
199 | 199 | self.value = parmElement.get('value') |
|
200 | 200 | self.format = str.lower(parmElement.get('format')) |
|
201 | 201 | |
|
202 | 202 | #Compatible with old signal chain version |
|
203 | 203 | if self.format == 'int' and self.name == 'idfigure': |
|
204 | 204 | self.name = 'id' |
|
205 | 205 | |
|
206 | 206 | def printattr(self): |
|
207 | 207 | |
|
208 | 208 | print "Parameter[%s]: name = %s, value = %s, format = %s" %(self.id, self.name, self.value, self.format) |
|
209 | 209 | |
|
210 | 210 | class OperationConf(): |
|
211 | 211 | |
|
212 | 212 | id = None |
|
213 | 213 | name = None |
|
214 | 214 | priority = None |
|
215 | 215 | type = None |
|
216 | 216 | |
|
217 | 217 | parmConfObjList = [] |
|
218 | 218 | |
|
219 | 219 | ELEMENTNAME = 'Operation' |
|
220 | 220 | |
|
221 | 221 | def __init__(self): |
|
222 | 222 | |
|
223 | 223 | self.id = '0' |
|
224 | 224 | self.name = None |
|
225 | 225 | self.priority = None |
|
226 | 226 | self.type = 'self' |
|
227 | 227 | |
|
228 | 228 | |
|
229 | 229 | def __getNewId(self): |
|
230 | 230 | |
|
231 | 231 | return int(self.id)*10 + len(self.parmConfObjList) + 1 |
|
232 | 232 | |
|
233 | 233 | def updateId(self, new_id): |
|
234 | 234 | |
|
235 | 235 | self.id = str(new_id) |
|
236 | 236 | |
|
237 | 237 | n = 1 |
|
238 | 238 | for parmObj in self.parmConfObjList: |
|
239 | 239 | |
|
240 | 240 | idParm = str(int(new_id)*10 + n) |
|
241 | 241 | parmObj.updateId(idParm) |
|
242 | 242 | |
|
243 | 243 | n += 1 |
|
244 | 244 | |
|
245 | 245 | def getElementName(self): |
|
246 | 246 | |
|
247 | 247 | return self.ELEMENTNAME |
|
248 | 248 | |
|
249 | 249 | def getParameterObjList(self): |
|
250 | 250 | |
|
251 | 251 | return self.parmConfObjList |
|
252 | 252 | |
|
253 | 253 | def getParameterObj(self, parameterName): |
|
254 | 254 | |
|
255 | 255 | for parmConfObj in self.parmConfObjList: |
|
256 | 256 | |
|
257 | 257 | if parmConfObj.name != parameterName: |
|
258 | 258 | continue |
|
259 | 259 | |
|
260 | 260 | return parmConfObj |
|
261 | 261 | |
|
262 | 262 | return None |
|
263 | 263 | |
|
264 | 264 | def getParameterObjfromValue(self, parameterValue): |
|
265 | 265 | |
|
266 | 266 | for parmConfObj in self.parmConfObjList: |
|
267 | 267 | |
|
268 | 268 | if parmConfObj.getValue() != parameterValue: |
|
269 | 269 | continue |
|
270 | 270 | |
|
271 | 271 | return parmConfObj.getValue() |
|
272 | 272 | |
|
273 | 273 | return None |
|
274 | 274 | |
|
275 | 275 | def getParameterValue(self, parameterName): |
|
276 | 276 | |
|
277 | 277 | parameterObj = self.getParameterObj(parameterName) |
|
278 | 278 | |
|
279 | 279 | # if not parameterObj: |
|
280 | 280 | # return None |
|
281 | 281 | |
|
282 | 282 | value = parameterObj.getValue() |
|
283 | 283 | |
|
284 | 284 | return value |
|
285 | 285 | |
|
286 | 286 | def setup(self, id, name, priority, type): |
|
287 | 287 | |
|
288 | 288 | self.id = str(id) |
|
289 | 289 | self.name = name |
|
290 | 290 | self.type = type |
|
291 | 291 | self.priority = priority |
|
292 | 292 | |
|
293 | 293 | self.parmConfObjList = [] |
|
294 | 294 | |
|
295 | 295 | def removeParameters(self): |
|
296 | 296 | |
|
297 | 297 | for obj in self.parmConfObjList: |
|
298 | 298 | del obj |
|
299 | 299 | |
|
300 | 300 | self.parmConfObjList = [] |
|
301 | 301 | |
|
302 | 302 | def addParameter(self, name, value, format='str'): |
|
303 | 303 | |
|
304 | 304 | id = self.__getNewId() |
|
305 | 305 | |
|
306 | 306 | parmConfObj = ParameterConf() |
|
307 | 307 | if not parmConfObj.setup(id, name, value, format): |
|
308 | 308 | return None |
|
309 | 309 | |
|
310 | 310 | self.parmConfObjList.append(parmConfObj) |
|
311 | 311 | |
|
312 | 312 | return parmConfObj |
|
313 | 313 | |
|
314 | 314 | def changeParameter(self, name, value, format='str'): |
|
315 | 315 | |
|
316 | 316 | parmConfObj = self.getParameterObj(name) |
|
317 | 317 | parmConfObj.update(name, value, format) |
|
318 | 318 | |
|
319 | 319 | return parmConfObj |
|
320 | 320 | |
|
321 | 321 | def makeXml(self, procUnitElement): |
|
322 | 322 | |
|
323 | 323 | opElement = SubElement(procUnitElement, self.ELEMENTNAME) |
|
324 | 324 | opElement.set('id', str(self.id)) |
|
325 | 325 | opElement.set('name', self.name) |
|
326 | 326 | opElement.set('type', self.type) |
|
327 | 327 | opElement.set('priority', str(self.priority)) |
|
328 | 328 | |
|
329 | 329 | for parmConfObj in self.parmConfObjList: |
|
330 | 330 | parmConfObj.makeXml(opElement) |
|
331 | 331 | |
|
332 | 332 | def readXml(self, opElement): |
|
333 | 333 | |
|
334 | 334 | self.id = opElement.get('id') |
|
335 | 335 | self.name = opElement.get('name') |
|
336 | 336 | self.type = opElement.get('type') |
|
337 | 337 | self.priority = opElement.get('priority') |
|
338 | 338 | |
|
339 | 339 | #Compatible with old signal chain version |
|
340 | 340 | #Use of 'run' method instead 'init' |
|
341 | 341 | if self.type == 'self' and self.name == 'init': |
|
342 | 342 | self.name = 'run' |
|
343 | 343 | |
|
344 | 344 | self.parmConfObjList = [] |
|
345 | 345 | |
|
346 | 346 | parmElementList = opElement.getiterator(ParameterConf().getElementName()) |
|
347 | 347 | |
|
348 | 348 | for parmElement in parmElementList: |
|
349 | 349 | parmConfObj = ParameterConf() |
|
350 | 350 | parmConfObj.readXml(parmElement) |
|
351 | 351 | |
|
352 | 352 | #Compatible with old signal chain version |
|
353 | 353 | #If an 'plot' OPERATION is found, changes name operation by the value of its type PARAMETER |
|
354 | 354 | if self.type != 'self' and self.name == 'Plot': |
|
355 | 355 | if parmConfObj.format == 'str' and parmConfObj.name == 'type': |
|
356 | 356 | self.name = parmConfObj.value |
|
357 | 357 | continue |
|
358 | 358 | |
|
359 | 359 | self.parmConfObjList.append(parmConfObj) |
|
360 | 360 | |
|
361 | 361 | def printattr(self): |
|
362 | 362 | |
|
363 | 363 | print "%s[%s]: name = %s, type = %s, priority = %s" %(self.ELEMENTNAME, |
|
364 | 364 | self.id, |
|
365 | 365 | self.name, |
|
366 | 366 | self.type, |
|
367 | 367 | self.priority) |
|
368 | 368 | |
|
369 | 369 | for parmConfObj in self.parmConfObjList: |
|
370 | 370 | parmConfObj.printattr() |
|
371 | 371 | |
|
372 | 372 | def createObject(self, plotter_queue=None): |
|
373 | 373 | |
|
374 | 374 | if self.type == 'self': |
|
375 | 375 | raise ValueError, "This operation type cannot be created" |
|
376 | 376 | |
|
377 | 377 | if self.type == 'plotter': |
|
378 | 378 | #Plotter(plotter_name) |
|
379 | 379 | if not plotter_queue: |
|
380 | 380 | raise ValueError, "plotter_queue is not defined. Use:\nmyProject = Project()\nmyProject.setPlotterQueue(plotter_queue)" |
|
381 | 381 | |
|
382 | 382 | opObj = Plotter(self.name, plotter_queue) |
|
383 | 383 | |
|
384 | 384 | if self.type == 'external' or self.type == 'other': |
|
385 | 385 | className = eval(self.name) |
|
386 | 386 | opObj = className() |
|
387 | 387 | |
|
388 | 388 | return opObj |
|
389 | 389 | |
|
390 | 390 | class ProcUnitConf(): |
|
391 | 391 | |
|
392 | 392 | id = None |
|
393 | 393 | name = None |
|
394 | 394 | datatype = None |
|
395 | 395 | inputId = None |
|
396 | 396 | parentId = None |
|
397 | 397 | |
|
398 | 398 | opConfObjList = [] |
|
399 | 399 | |
|
400 | 400 | procUnitObj = None |
|
401 | 401 | opObjList = [] |
|
402 | 402 | |
|
403 | 403 | ELEMENTNAME = 'ProcUnit' |
|
404 | 404 | |
|
405 | 405 | def __init__(self): |
|
406 | 406 | |
|
407 | 407 | self.id = None |
|
408 | 408 | self.datatype = None |
|
409 | 409 | self.name = None |
|
410 | 410 | self.inputId = None |
|
411 | 411 | |
|
412 | 412 | self.opConfObjList = [] |
|
413 | 413 | |
|
414 | 414 | self.procUnitObj = None |
|
415 | 415 | self.opObjDict = {} |
|
416 | 416 | |
|
417 | 417 | def __getPriority(self): |
|
418 | 418 | |
|
419 | 419 | return len(self.opConfObjList)+1 |
|
420 | 420 | |
|
421 | 421 | def __getNewId(self): |
|
422 | 422 | |
|
423 | 423 | return int(self.id)*10 + len(self.opConfObjList) + 1 |
|
424 | 424 | |
|
425 | 425 | def getElementName(self): |
|
426 | 426 | |
|
427 | 427 | return self.ELEMENTNAME |
|
428 | 428 | |
|
429 | 429 | def getId(self): |
|
430 | 430 | |
|
431 | 431 | return self.id |
|
432 | 432 | |
|
433 | 433 | def updateId(self, new_id, parentId=parentId): |
|
434 | 434 | |
|
435 | 435 | |
|
436 | 436 | new_id = int(parentId)*10 + (int(self.id) % 10) |
|
437 | 437 | new_inputId = int(parentId)*10 + (int(self.inputId) % 10) |
|
438 | 438 | |
|
439 | 439 | #If this proc unit has not inputs |
|
440 | 440 | if self.inputId == '0': |
|
441 | 441 | new_inputId = 0 |
|
442 | 442 | |
|
443 | 443 | n = 1 |
|
444 | 444 | for opConfObj in self.opConfObjList: |
|
445 | 445 | |
|
446 | 446 | idOp = str(int(new_id)*10 + n) |
|
447 | 447 | opConfObj.updateId(idOp) |
|
448 | 448 | |
|
449 | 449 | n += 1 |
|
450 | 450 | |
|
451 | 451 | self.parentId = str(parentId) |
|
452 | 452 | self.id = str(new_id) |
|
453 | 453 | self.inputId = str(new_inputId) |
|
454 | 454 | |
|
455 | 455 | |
|
456 | 456 | def getInputId(self): |
|
457 | 457 | |
|
458 | 458 | return self.inputId |
|
459 | 459 | |
|
460 | 460 | def getOperationObjList(self): |
|
461 | 461 | |
|
462 | 462 | return self.opConfObjList |
|
463 | 463 | |
|
464 | 464 | def getOperationObj(self, name=None): |
|
465 | 465 | |
|
466 | 466 | for opConfObj in self.opConfObjList: |
|
467 | 467 | |
|
468 | 468 | if opConfObj.name != name: |
|
469 | 469 | continue |
|
470 | 470 | |
|
471 | 471 | return opConfObj |
|
472 | 472 | |
|
473 | 473 | return None |
|
474 | 474 | |
|
475 | 475 | def getOpObjfromParamValue(self, value=None): |
|
476 | 476 | |
|
477 | 477 | for opConfObj in self.opConfObjList: |
|
478 | 478 | if opConfObj.getParameterObjfromValue(parameterValue=value) != value: |
|
479 | 479 | continue |
|
480 | 480 | return opConfObj |
|
481 | 481 | return None |
|
482 | 482 | |
|
483 | 483 | def getProcUnitObj(self): |
|
484 | 484 | |
|
485 | 485 | return self.procUnitObj |
|
486 | 486 | |
|
487 | 487 | def setup(self, id, name, datatype, inputId, parentId=None): |
|
488 | 488 | |
|
489 | 489 | #Compatible with old signal chain version |
|
490 | 490 | if datatype==None and name==None: |
|
491 | 491 | raise ValueError, "datatype or name should be defined" |
|
492 | 492 | |
|
493 | 493 | if name==None: |
|
494 | 494 | if 'Proc' in datatype: |
|
495 | 495 | name = datatype |
|
496 | 496 | else: |
|
497 | 497 | name = '%sProc' %(datatype) |
|
498 | 498 | |
|
499 | 499 | if datatype==None: |
|
500 | 500 | datatype = name.replace('Proc','') |
|
501 | 501 | |
|
502 | 502 | self.id = str(id) |
|
503 | 503 | self.name = name |
|
504 | 504 | self.datatype = datatype |
|
505 | 505 | self.inputId = inputId |
|
506 | 506 | self.parentId = parentId |
|
507 | 507 | |
|
508 | 508 | self.opConfObjList = [] |
|
509 | 509 | |
|
510 | 510 | self.addOperation(name='run', optype='self') |
|
511 | 511 | |
|
512 | 512 | def removeOperations(self): |
|
513 | 513 | |
|
514 | 514 | for obj in self.opConfObjList: |
|
515 | 515 | del obj |
|
516 | 516 | |
|
517 | 517 | self.opConfObjList = [] |
|
518 | 518 | self.addOperation(name='run') |
|
519 | 519 | |
|
520 | 520 | def addParameter(self, **kwargs): |
|
521 | 521 | ''' |
|
522 | 522 | Add parameters to "run" operation |
|
523 | 523 | ''' |
|
524 | 524 | opObj = self.opConfObjList[0] |
|
525 | 525 | |
|
526 | 526 | opObj.addParameter(**kwargs) |
|
527 | 527 | |
|
528 | 528 | return opObj |
|
529 | 529 | |
|
530 | 530 | def addOperation(self, name, optype='self'): |
|
531 | 531 | |
|
532 | 532 | id = self.__getNewId() |
|
533 | 533 | priority = self.__getPriority() |
|
534 | 534 | |
|
535 | 535 | opConfObj = OperationConf() |
|
536 | 536 | opConfObj.setup(id, name=name, priority=priority, type=optype) |
|
537 | 537 | |
|
538 | 538 | self.opConfObjList.append(opConfObj) |
|
539 | 539 | |
|
540 | 540 | return opConfObj |
|
541 | 541 | |
|
542 | 542 | def makeXml(self, projectElement): |
|
543 | 543 | |
|
544 | 544 | procUnitElement = SubElement(projectElement, self.ELEMENTNAME) |
|
545 | 545 | procUnitElement.set('id', str(self.id)) |
|
546 | 546 | procUnitElement.set('name', self.name) |
|
547 | 547 | procUnitElement.set('datatype', self.datatype) |
|
548 | 548 | procUnitElement.set('inputId', str(self.inputId)) |
|
549 | 549 | |
|
550 | 550 | for opConfObj in self.opConfObjList: |
|
551 | 551 | opConfObj.makeXml(procUnitElement) |
|
552 | 552 | |
|
553 | 553 | def readXml(self, upElement): |
|
554 | 554 | |
|
555 | 555 | self.id = upElement.get('id') |
|
556 | 556 | self.name = upElement.get('name') |
|
557 | 557 | self.datatype = upElement.get('datatype') |
|
558 | 558 | self.inputId = upElement.get('inputId') |
|
559 | 559 | |
|
560 | 560 | if self.ELEMENTNAME == "ReadUnit": |
|
561 | 561 | self.datatype = self.datatype.replace("Reader", "") |
|
562 | 562 | |
|
563 | 563 | if self.ELEMENTNAME == "ProcUnit": |
|
564 | 564 | self.datatype = self.datatype.replace("Proc", "") |
|
565 | 565 | |
|
566 | 566 | if self.inputId == 'None': |
|
567 | 567 | self.inputId = '0' |
|
568 | 568 | |
|
569 | 569 | self.opConfObjList = [] |
|
570 | 570 | |
|
571 | 571 | opElementList = upElement.getiterator(OperationConf().getElementName()) |
|
572 | 572 | |
|
573 | 573 | for opElement in opElementList: |
|
574 | 574 | opConfObj = OperationConf() |
|
575 | 575 | opConfObj.readXml(opElement) |
|
576 | 576 | self.opConfObjList.append(opConfObj) |
|
577 | 577 | |
|
578 | 578 | def printattr(self): |
|
579 | 579 | |
|
580 | 580 | print "%s[%s]: name = %s, datatype = %s, inputId = %s" %(self.ELEMENTNAME, |
|
581 | 581 | self.id, |
|
582 | 582 | self.name, |
|
583 | 583 | self.datatype, |
|
584 | 584 | self.inputId) |
|
585 | 585 | |
|
586 | 586 | for opConfObj in self.opConfObjList: |
|
587 | 587 | opConfObj.printattr() |
|
588 | 588 | |
|
589 | 589 | def createObjects(self, plotter_queue=None): |
|
590 | 590 | |
|
591 | 591 | className = eval(self.name) |
|
592 | 592 | procUnitObj = className() |
|
593 | 593 | |
|
594 | 594 | for opConfObj in self.opConfObjList: |
|
595 | 595 | |
|
596 | 596 | if opConfObj.type == 'self': |
|
597 | 597 | continue |
|
598 | 598 | |
|
599 | 599 | opObj = opConfObj.createObject(plotter_queue) |
|
600 | 600 | |
|
601 | 601 | self.opObjDict[opConfObj.id] = opObj |
|
602 | 602 | procUnitObj.addOperation(opObj, opConfObj.id) |
|
603 | 603 | |
|
604 | 604 | self.procUnitObj = procUnitObj |
|
605 | 605 | |
|
606 | 606 | return procUnitObj |
|
607 | 607 | |
|
608 | 608 | def run(self): |
|
609 | 609 | |
|
610 | 610 | is_ok = False |
|
611 | 611 | |
|
612 | 612 | for opConfObj in self.opConfObjList: |
|
613 | 613 | |
|
614 | 614 | kwargs = {} |
|
615 | 615 | for parmConfObj in opConfObj.getParameterObjList(): |
|
616 | 616 | if opConfObj.name == 'run' and parmConfObj.name == 'datatype': |
|
617 | 617 | continue |
|
618 | 618 | |
|
619 | 619 | kwargs[parmConfObj.name] = parmConfObj.getValue() |
|
620 | 620 | |
|
621 | ini = time.time() | |
|
622 | ||
|
621 | 623 | #print "\tRunning the '%s' operation with %s" %(opConfObj.name, opConfObj.id) |
|
622 | 624 | sts = self.procUnitObj.call(opType = opConfObj.type, |
|
623 | 625 | opName = opConfObj.name, |
|
624 | 626 | opId = opConfObj.id, |
|
625 | 627 | **kwargs) |
|
628 | ||
|
629 | # total_time = time.time() - ini | |
|
630 | # | |
|
631 | # if total_time > 0.002: | |
|
632 | # print "%s::%s took %f seconds" %(self.name, opConfObj.name, total_time) | |
|
633 | ||
|
626 | 634 | is_ok = is_ok or sts |
|
627 | 635 | |
|
628 | 636 | return is_ok |
|
629 | 637 | |
|
630 | 638 | def close(self): |
|
631 | 639 | |
|
632 | 640 | for opConfObj in self.opConfObjList: |
|
633 | 641 | if opConfObj.type == 'self': |
|
634 | 642 | continue |
|
635 | 643 | |
|
636 | 644 | opObj = self.procUnitObj.getOperationObj(opConfObj.id) |
|
637 | 645 | opObj.close() |
|
638 | 646 | |
|
639 | 647 | self.procUnitObj.close() |
|
640 | 648 | |
|
641 | 649 | return |
|
642 | 650 | |
|
643 | 651 | class ReadUnitConf(ProcUnitConf): |
|
644 | 652 | |
|
645 | 653 | path = None |
|
646 | 654 | startDate = None |
|
647 | 655 | endDate = None |
|
648 | 656 | startTime = None |
|
649 | 657 | endTime = None |
|
650 | 658 | |
|
651 | 659 | ELEMENTNAME = 'ReadUnit' |
|
652 | 660 | |
|
653 | 661 | def __init__(self): |
|
654 | 662 | |
|
655 | 663 | self.id = None |
|
656 | 664 | self.datatype = None |
|
657 | 665 | self.name = None |
|
658 | 666 | self.inputId = None |
|
659 | 667 | |
|
660 | 668 | self.parentId = None |
|
661 | 669 | |
|
662 | 670 | self.opConfObjList = [] |
|
663 | 671 | self.opObjList = [] |
|
664 | 672 | |
|
665 | 673 | def getElementName(self): |
|
666 | 674 | |
|
667 | 675 | return self.ELEMENTNAME |
|
668 | 676 | |
|
669 | 677 | def setup(self, id, name, datatype, path, startDate="", endDate="", startTime="", endTime="", parentId=None, **kwargs): |
|
670 | 678 | |
|
671 | 679 | #Compatible with old signal chain version |
|
672 | 680 | if datatype==None and name==None: |
|
673 | 681 | raise ValueError, "datatype or name should be defined" |
|
674 | 682 | |
|
675 | 683 | if name==None: |
|
676 | 684 | if 'Reader' in datatype: |
|
677 | 685 | name = datatype |
|
678 | 686 | else: |
|
679 | 687 | name = '%sReader' %(datatype) |
|
680 | 688 | |
|
681 | 689 | if datatype==None: |
|
682 | 690 | datatype = name.replace('Reader','') |
|
683 | 691 | |
|
684 | 692 | self.id = id |
|
685 | 693 | self.name = name |
|
686 | 694 | self.datatype = datatype |
|
687 | 695 | |
|
688 | 696 | self.path = os.path.abspath(path) |
|
689 | 697 | self.startDate = startDate |
|
690 | 698 | self.endDate = endDate |
|
691 | 699 | self.startTime = startTime |
|
692 | 700 | self.endTime = endTime |
|
693 | 701 | |
|
694 | 702 | self.inputId = '0' |
|
695 | 703 | self.parentId = parentId |
|
696 | 704 | |
|
697 | 705 | self.addRunOperation(**kwargs) |
|
698 | 706 | |
|
699 | 707 | def update(self, datatype, path, startDate, endDate, startTime, endTime, parentId=None, name=None, **kwargs): |
|
700 | 708 | |
|
701 | 709 | #Compatible with old signal chain version |
|
702 | 710 | if datatype==None and name==None: |
|
703 | 711 | raise ValueError, "datatype or name should be defined" |
|
704 | 712 | |
|
705 | 713 | if name==None: |
|
706 | 714 | if 'Reader' in datatype: |
|
707 | 715 | name = datatype |
|
708 | 716 | else: |
|
709 | 717 | name = '%sReader' %(datatype) |
|
710 | 718 | |
|
711 | 719 | if datatype==None: |
|
712 | 720 | datatype = name.replace('Reader','') |
|
713 | 721 | |
|
714 | 722 | self.datatype = datatype |
|
715 | 723 | self.name = name |
|
716 | 724 | self.path = path |
|
717 | 725 | self.startDate = startDate |
|
718 | 726 | self.endDate = endDate |
|
719 | 727 | self.startTime = startTime |
|
720 | 728 | self.endTime = endTime |
|
721 | 729 | |
|
722 | 730 | self.inputId = '0' |
|
723 | 731 | self.parentId = parentId |
|
724 | 732 | |
|
725 | 733 | self.updateRunOperation(**kwargs) |
|
726 | 734 | |
|
727 | 735 | def removeOperations(self): |
|
728 | 736 | |
|
729 | 737 | for obj in self.opConfObjList: |
|
730 | 738 | del obj |
|
731 | 739 | |
|
732 | 740 | self.opConfObjList = [] |
|
733 | 741 | |
|
734 | 742 | def addRunOperation(self, **kwargs): |
|
735 | 743 | |
|
736 | 744 | opObj = self.addOperation(name = 'run', optype = 'self') |
|
737 | 745 | |
|
738 | 746 | opObj.addParameter(name='datatype' , value=self.datatype, format='str') |
|
739 | 747 | opObj.addParameter(name='path' , value=self.path, format='str') |
|
740 | 748 | opObj.addParameter(name='startDate' , value=self.startDate, format='date') |
|
741 | 749 | opObj.addParameter(name='endDate' , value=self.endDate, format='date') |
|
742 | 750 | opObj.addParameter(name='startTime' , value=self.startTime, format='time') |
|
743 | 751 | opObj.addParameter(name='endTime' , value=self.endTime, format='time') |
|
744 | 752 | |
|
745 | 753 | for key, value in kwargs.items(): |
|
746 | 754 | opObj.addParameter(name=key, value=value, format=type(value).__name__) |
|
747 | 755 | |
|
748 | 756 | return opObj |
|
749 | 757 | |
|
750 | 758 | def updateRunOperation(self, **kwargs): |
|
751 | 759 | |
|
752 | 760 | opObj = self.getOperationObj(name = 'run') |
|
753 | 761 | opObj.removeParameters() |
|
754 | 762 | |
|
755 | 763 | opObj.addParameter(name='datatype' , value=self.datatype, format='str') |
|
756 | 764 | opObj.addParameter(name='path' , value=self.path, format='str') |
|
757 | 765 | opObj.addParameter(name='startDate' , value=self.startDate, format='date') |
|
758 | 766 | opObj.addParameter(name='endDate' , value=self.endDate, format='date') |
|
759 | 767 | opObj.addParameter(name='startTime' , value=self.startTime, format='time') |
|
760 | 768 | opObj.addParameter(name='endTime' , value=self.endTime, format='time') |
|
761 | 769 | |
|
762 | 770 | for key, value in kwargs.items(): |
|
763 | 771 | opObj.addParameter(name=key, value=value, format=type(value).__name__) |
|
764 | 772 | |
|
765 | 773 | return opObj |
|
766 | 774 | |
|
767 | 775 | # def makeXml(self, projectElement): |
|
768 | 776 | # |
|
769 | 777 | # procUnitElement = SubElement(projectElement, self.ELEMENTNAME) |
|
770 | 778 | # procUnitElement.set('id', str(self.id)) |
|
771 | 779 | # procUnitElement.set('name', self.name) |
|
772 | 780 | # procUnitElement.set('datatype', self.datatype) |
|
773 | 781 | # procUnitElement.set('inputId', str(self.inputId)) |
|
774 | 782 | # |
|
775 | 783 | # for opConfObj in self.opConfObjList: |
|
776 | 784 | # opConfObj.makeXml(procUnitElement) |
|
777 | 785 | |
|
778 | 786 | def readXml(self, upElement): |
|
779 | 787 | |
|
780 | 788 | self.id = upElement.get('id') |
|
781 | 789 | self.name = upElement.get('name') |
|
782 | 790 | self.datatype = upElement.get('datatype') |
|
783 | 791 | self.inputId = upElement.get('inputId') |
|
784 | 792 | |
|
785 | 793 | if self.ELEMENTNAME == "ReadUnit": |
|
786 | 794 | self.datatype = self.datatype.replace("Reader", "") |
|
787 | 795 | |
|
788 | 796 | if self.inputId == 'None': |
|
789 | 797 | self.inputId = '0' |
|
790 | 798 | |
|
791 | 799 | self.opConfObjList = [] |
|
792 | 800 | |
|
793 | 801 | opElementList = upElement.getiterator(OperationConf().getElementName()) |
|
794 | 802 | |
|
795 | 803 | for opElement in opElementList: |
|
796 | 804 | opConfObj = OperationConf() |
|
797 | 805 | opConfObj.readXml(opElement) |
|
798 | 806 | self.opConfObjList.append(opConfObj) |
|
799 | 807 | |
|
800 | 808 | if opConfObj.name == 'run': |
|
801 | 809 | self.path = opConfObj.getParameterValue('path') |
|
802 | 810 | self.startDate = opConfObj.getParameterValue('startDate') |
|
803 | 811 | self.endDate = opConfObj.getParameterValue('endDate') |
|
804 | 812 | self.startTime = opConfObj.getParameterValue('startTime') |
|
805 | 813 | self.endTime = opConfObj.getParameterValue('endTime') |
|
806 | 814 | |
|
807 | 815 | class Project(): |
|
808 | 816 | |
|
809 | 817 | id = None |
|
810 | 818 | name = None |
|
811 | 819 | description = None |
|
812 | 820 | filename = None |
|
813 | 821 | |
|
814 | 822 | procUnitConfObjDict = None |
|
815 | 823 | |
|
816 | 824 | ELEMENTNAME = 'Project' |
|
817 | 825 | |
|
818 | 826 | plotterQueue = None |
|
819 | 827 | |
|
820 | 828 | def __init__(self, plotter_queue=None): |
|
821 | 829 | |
|
822 | 830 | self.id = None |
|
823 | 831 | self.name = None |
|
824 | 832 | self.description = None |
|
825 | 833 | |
|
826 | 834 | self.plotterQueue = plotter_queue |
|
827 | 835 | |
|
828 | 836 | self.procUnitConfObjDict = {} |
|
829 | 837 | |
|
830 | 838 | def __getNewId(self): |
|
831 | 839 | |
|
832 | 840 | idList = self.procUnitConfObjDict.keys() |
|
833 | 841 | |
|
834 | 842 | id = int(self.id)*10 |
|
835 | 843 | |
|
836 | 844 | while True: |
|
837 | 845 | id += 1 |
|
838 | 846 | |
|
839 | 847 | if str(id) in idList: |
|
840 | 848 | continue |
|
841 | 849 | |
|
842 | 850 | break |
|
843 | 851 | |
|
844 | 852 | return str(id) |
|
845 | 853 | |
|
846 | 854 | def getElementName(self): |
|
847 | 855 | |
|
848 | 856 | return self.ELEMENTNAME |
|
849 | 857 | |
|
850 | 858 | def getId(self): |
|
851 | 859 | |
|
852 | 860 | return self.id |
|
853 | 861 | |
|
854 | 862 | def updateId(self, new_id): |
|
855 | 863 | |
|
856 | 864 | self.id = str(new_id) |
|
857 | 865 | |
|
858 | 866 | keyList = self.procUnitConfObjDict.keys() |
|
859 | 867 | keyList.sort() |
|
860 | 868 | |
|
861 | 869 | n = 1 |
|
862 | 870 | newProcUnitConfObjDict = {} |
|
863 | 871 | |
|
864 | 872 | for procKey in keyList: |
|
865 | 873 | |
|
866 | 874 | procUnitConfObj = self.procUnitConfObjDict[procKey] |
|
867 | 875 | idProcUnit = str(int(self.id)*10 + n) |
|
868 | 876 | procUnitConfObj.updateId(idProcUnit, parentId = self.id) |
|
869 | 877 | |
|
870 | 878 | newProcUnitConfObjDict[idProcUnit] = procUnitConfObj |
|
871 | 879 | n += 1 |
|
872 | 880 | |
|
873 | 881 | self.procUnitConfObjDict = newProcUnitConfObjDict |
|
874 | 882 | |
|
875 | 883 | def setup(self, id, name, description): |
|
876 | 884 | |
|
877 | 885 | self.id = str(id) |
|
878 | 886 | self.name = name |
|
879 | 887 | self.description = description |
|
880 | 888 | |
|
881 | 889 | def update(self, name, description): |
|
882 | 890 | |
|
883 | 891 | self.name = name |
|
884 | 892 | self.description = description |
|
885 | 893 | |
|
886 | 894 | def addReadUnit(self, id=None, datatype=None, name=None, **kwargs): |
|
887 | 895 | |
|
888 | 896 | if id is None: |
|
889 | 897 | idReadUnit = self.__getNewId() |
|
890 | 898 | else: |
|
891 | 899 | idReadUnit = str(id) |
|
892 | 900 | |
|
893 | 901 | readUnitConfObj = ReadUnitConf() |
|
894 | 902 | readUnitConfObj.setup(idReadUnit, name, datatype, parentId=self.id, **kwargs) |
|
895 | 903 | |
|
896 | 904 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj |
|
897 | 905 | |
|
898 | 906 | return readUnitConfObj |
|
899 | 907 | |
|
900 | 908 | def addProcUnit(self, inputId='0', datatype=None, name=None): |
|
901 | 909 | |
|
902 | 910 | idProcUnit = self.__getNewId() |
|
903 | 911 | |
|
904 | 912 | procUnitConfObj = ProcUnitConf() |
|
905 | 913 | procUnitConfObj.setup(idProcUnit, name, datatype, inputId, parentId=self.id) |
|
906 | 914 | |
|
907 | 915 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj |
|
908 | 916 | |
|
909 | 917 | return procUnitConfObj |
|
910 | 918 | |
|
911 | 919 | def removeProcUnit(self, id): |
|
912 | 920 | |
|
913 | 921 | if id in self.procUnitConfObjDict.keys(): |
|
914 | 922 | self.procUnitConfObjDict.pop(id) |
|
915 | 923 | |
|
916 | 924 | def getReadUnitId(self): |
|
917 | 925 | |
|
918 | 926 | readUnitConfObj = self.getReadUnitObj() |
|
919 | 927 | |
|
920 | 928 | return readUnitConfObj.id |
|
921 | 929 | |
|
922 | 930 | def getReadUnitObj(self): |
|
923 | 931 | |
|
924 | 932 | for obj in self.procUnitConfObjDict.values(): |
|
925 | 933 | if obj.getElementName() == "ReadUnit": |
|
926 | 934 | return obj |
|
927 | 935 | |
|
928 | 936 | return None |
|
929 | 937 | |
|
930 | 938 | def getProcUnitObj(self, id=None, name=None): |
|
931 | 939 | |
|
932 | 940 | if id != None: |
|
933 | 941 | return self.procUnitConfObjDict[id] |
|
934 | 942 | |
|
935 | 943 | if name != None: |
|
936 | 944 | return self.getProcUnitObjByName(name) |
|
937 | 945 | |
|
938 | 946 | return None |
|
939 | 947 | |
|
940 | 948 | def getProcUnitObjByName(self, name): |
|
941 | 949 | |
|
942 | 950 | for obj in self.procUnitConfObjDict.values(): |
|
943 | 951 | if obj.name == name: |
|
944 | 952 | return obj |
|
945 | 953 | |
|
946 | 954 | return None |
|
947 | 955 | |
|
948 | 956 | def procUnitItems(self): |
|
949 | 957 | |
|
950 | 958 | return self.procUnitConfObjDict.items() |
|
951 | 959 | |
|
952 | 960 | def makeXml(self): |
|
953 | 961 | |
|
954 | 962 | projectElement = Element('Project') |
|
955 | 963 | projectElement.set('id', str(self.id)) |
|
956 | 964 | projectElement.set('name', self.name) |
|
957 | 965 | projectElement.set('description', self.description) |
|
958 | 966 | |
|
959 | 967 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
960 | 968 | procUnitConfObj.makeXml(projectElement) |
|
961 | 969 | |
|
962 | 970 | self.projectElement = projectElement |
|
963 | 971 | |
|
964 | 972 | def writeXml(self, filename=None): |
|
965 | 973 | |
|
966 | 974 | if filename == None: |
|
967 | 975 | if self.filename: |
|
968 | 976 | filename = self.filename |
|
969 | 977 | else: |
|
970 | 978 | filename = "schain.xml" |
|
971 | 979 | |
|
972 | 980 | if not filename: |
|
973 | 981 | print "filename has not been defined. Use setFilename(filename) for do it." |
|
974 | 982 | return 0 |
|
975 | 983 | |
|
976 | 984 | abs_file = os.path.abspath(filename) |
|
977 | 985 | |
|
978 | 986 | if not os.access(os.path.dirname(abs_file), os.W_OK): |
|
979 | 987 | print "No write permission on %s" %os.path.dirname(abs_file) |
|
980 | 988 | return 0 |
|
981 | 989 | |
|
982 | 990 | if os.path.isfile(abs_file) and not(os.access(abs_file, os.W_OK)): |
|
983 | 991 | print "File %s already exists and it could not be overwriten" %abs_file |
|
984 | 992 | return 0 |
|
985 | 993 | |
|
986 | 994 | self.makeXml() |
|
987 | 995 | |
|
988 | 996 | ElementTree(self.projectElement).write(abs_file, method='xml') |
|
989 | 997 | |
|
990 | 998 | self.filename = abs_file |
|
991 | 999 | |
|
992 | 1000 | return 1 |
|
993 | 1001 | |
|
994 | 1002 | def readXml(self, filename = None): |
|
995 | 1003 | |
|
996 | 1004 | abs_file = os.path.abspath(filename) |
|
997 | 1005 | |
|
998 | 1006 | if not os.path.isfile(abs_file): |
|
999 | 1007 | print "%s does not exist" %abs_file |
|
1000 | 1008 | return 0 |
|
1001 | 1009 | |
|
1002 | 1010 | self.projectElement = None |
|
1003 | 1011 | self.procUnitConfObjDict = {} |
|
1004 | 1012 | |
|
1005 | 1013 | try: |
|
1006 | 1014 | self.projectElement = ElementTree().parse(abs_file) |
|
1007 | 1015 | except: |
|
1008 | 1016 | print "Error reading %s, verify file format" %filename |
|
1009 | 1017 | return 0 |
|
1010 | 1018 | |
|
1011 | 1019 | self.project = self.projectElement.tag |
|
1012 | 1020 | |
|
1013 | 1021 | self.id = self.projectElement.get('id') |
|
1014 | 1022 | self.name = self.projectElement.get('name') |
|
1015 | 1023 | self.description = self.projectElement.get('description') |
|
1016 | 1024 | |
|
1017 | 1025 | readUnitElementList = self.projectElement.getiterator(ReadUnitConf().getElementName()) |
|
1018 | 1026 | |
|
1019 | 1027 | for readUnitElement in readUnitElementList: |
|
1020 | 1028 | readUnitConfObj = ReadUnitConf() |
|
1021 | 1029 | readUnitConfObj.readXml(readUnitElement) |
|
1022 | 1030 | |
|
1023 | 1031 | if readUnitConfObj.parentId == None: |
|
1024 | 1032 | readUnitConfObj.parentId = self.id |
|
1025 | 1033 | |
|
1026 | 1034 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj |
|
1027 | 1035 | |
|
1028 | 1036 | procUnitElementList = self.projectElement.getiterator(ProcUnitConf().getElementName()) |
|
1029 | 1037 | |
|
1030 | 1038 | for procUnitElement in procUnitElementList: |
|
1031 | 1039 | procUnitConfObj = ProcUnitConf() |
|
1032 | 1040 | procUnitConfObj.readXml(procUnitElement) |
|
1033 | 1041 | |
|
1034 | 1042 | if procUnitConfObj.parentId == None: |
|
1035 | 1043 | procUnitConfObj.parentId = self.id |
|
1036 | 1044 | |
|
1037 | 1045 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj |
|
1038 | 1046 | |
|
1039 | 1047 | self.filename = abs_file |
|
1040 | 1048 | |
|
1041 | 1049 | return 1 |
|
1042 | 1050 | |
|
1043 | 1051 | def printattr(self): |
|
1044 | 1052 | |
|
1045 | 1053 | print "Project[%s]: name = %s, description = %s" %(self.id, |
|
1046 | 1054 | self.name, |
|
1047 | 1055 | self.description) |
|
1048 | 1056 | |
|
1049 | 1057 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
1050 | 1058 | procUnitConfObj.printattr() |
|
1051 | 1059 | |
|
1052 | 1060 | def createObjects(self): |
|
1053 | 1061 | |
|
1054 | 1062 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
1055 | 1063 | procUnitConfObj.createObjects(self.plotterQueue) |
|
1056 | 1064 | |
|
1057 | 1065 | def __connect(self, objIN, thisObj): |
|
1058 | 1066 | |
|
1059 | 1067 | thisObj.setInput(objIN.getOutputObj()) |
|
1060 | 1068 | |
|
1061 | 1069 | def connectObjects(self): |
|
1062 | 1070 | |
|
1063 | 1071 | for thisPUConfObj in self.procUnitConfObjDict.values(): |
|
1064 | 1072 | |
|
1065 | 1073 | inputId = thisPUConfObj.getInputId() |
|
1066 | 1074 | |
|
1067 | 1075 | if int(inputId) == 0: |
|
1068 | 1076 | continue |
|
1069 | 1077 | |
|
1070 | 1078 | #Get input object |
|
1071 | 1079 | puConfINObj = self.procUnitConfObjDict[inputId] |
|
1072 | 1080 | puObjIN = puConfINObj.getProcUnitObj() |
|
1073 | 1081 | |
|
1074 | 1082 | #Get current object |
|
1075 | 1083 | thisPUObj = thisPUConfObj.getProcUnitObj() |
|
1076 | 1084 | |
|
1077 | 1085 | self.__connect(puObjIN, thisPUObj) |
|
1078 | 1086 | |
|
1079 | 1087 | def __handleError(self, procUnitConfObj, send_email=True): |
|
1080 | 1088 | |
|
1081 | 1089 | import socket |
|
1082 | 1090 | |
|
1083 | 1091 | err = traceback.format_exception(sys.exc_info()[0], |
|
1084 | 1092 | sys.exc_info()[1], |
|
1085 | 1093 | sys.exc_info()[2]) |
|
1086 | 1094 | |
|
1087 | 1095 | print "***** Error occurred in %s *****" %(procUnitConfObj.name) |
|
1088 | 1096 | print "***** %s" %err[-1] |
|
1089 | 1097 | |
|
1090 | 1098 | message = "".join(err) |
|
1091 | 1099 | |
|
1092 | 1100 | sys.stderr.write(message) |
|
1093 | 1101 | |
|
1094 | 1102 | if not send_email: |
|
1095 | 1103 | return |
|
1096 | 1104 | |
|
1097 | 1105 | subject = "SChain v%s: Error running %s\n" %(schainpy.__version__, procUnitConfObj.name) |
|
1098 | 1106 | |
|
1099 | 1107 | subtitle = "%s: %s\n" %(procUnitConfObj.getElementName() ,procUnitConfObj.name) |
|
1100 | 1108 | subtitle += "Hostname: %s\n" %socket.gethostbyname(socket.gethostname()) |
|
1101 | 1109 | subtitle += "Working directory: %s\n" %os.path.abspath("./") |
|
1102 | 1110 | subtitle += "Configuration file: %s\n" %self.filename |
|
1103 | 1111 | subtitle += "Time: %s\n" %str(datetime.datetime.now()) |
|
1104 | 1112 | |
|
1105 | 1113 | readUnitConfObj = self.getReadUnitObj() |
|
1106 | 1114 | if readUnitConfObj: |
|
1107 | 1115 | subtitle += "\nInput parameters:\n" |
|
1108 | 1116 | subtitle += "[Data path = %s]\n" %readUnitConfObj.path |
|
1109 | 1117 | subtitle += "[Data type = %s]\n" %readUnitConfObj.datatype |
|
1110 | 1118 | subtitle += "[Start date = %s]\n" %readUnitConfObj.startDate |
|
1111 | 1119 | subtitle += "[End date = %s]\n" %readUnitConfObj.endDate |
|
1112 | 1120 | subtitle += "[Start time = %s]\n" %readUnitConfObj.startTime |
|
1113 | 1121 | subtitle += "[End time = %s]\n" %readUnitConfObj.endTime |
|
1114 | 1122 | |
|
1115 | 1123 | adminObj = schainpy.admin.SchainNotify() |
|
1116 | 1124 | adminObj.sendAlert(message=message, |
|
1117 | 1125 | subject=subject, |
|
1118 | 1126 | subtitle=subtitle, |
|
1119 | 1127 | filename=self.filename) |
|
1120 | 1128 | |
|
1121 | 1129 | def isPaused(self): |
|
1122 | 1130 | return 0 |
|
1123 | 1131 | |
|
1124 | 1132 | def isStopped(self): |
|
1125 | 1133 | return 0 |
|
1126 | 1134 | |
|
1127 | 1135 | def runController(self): |
|
1128 | 1136 | """ |
|
1129 | 1137 | returns 0 when this process has been stopped, 1 otherwise |
|
1130 | 1138 | """ |
|
1131 | 1139 | |
|
1132 | 1140 | if self.isPaused(): |
|
1133 | 1141 | print "Process suspended" |
|
1134 | 1142 | |
|
1135 | 1143 | while True: |
|
1136 | 1144 | sleep(0.1) |
|
1137 | 1145 | |
|
1138 | 1146 | if not self.isPaused(): |
|
1139 | 1147 | break |
|
1140 | 1148 | |
|
1141 | 1149 | if self.isStopped(): |
|
1142 | 1150 | break |
|
1143 | 1151 | |
|
1144 | 1152 | print "Process reinitialized" |
|
1145 | 1153 | |
|
1146 | 1154 | if self.isStopped(): |
|
1147 | 1155 | print "Process stopped" |
|
1148 | 1156 | return 0 |
|
1149 | 1157 | |
|
1150 | 1158 | return 1 |
|
1151 | 1159 | |
|
1152 | 1160 | def setFilename(self, filename): |
|
1153 | 1161 | |
|
1154 | 1162 | self.filename = filename |
|
1155 | 1163 | |
|
1156 | 1164 | def setPlotterQueue(self, plotter_queue): |
|
1157 | 1165 | |
|
1158 | 1166 | raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class" |
|
1159 | 1167 | |
|
1160 | 1168 | def getPlotterQueue(self): |
|
1161 | 1169 | |
|
1162 | 1170 | raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class" |
|
1163 | 1171 | |
|
1164 | 1172 | def useExternalPlotter(self): |
|
1165 | 1173 | |
|
1166 | 1174 | raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class" |
|
1167 | 1175 | |
|
1168 | 1176 | def run(self): |
|
1169 | 1177 | |
|
1170 | 1178 | |
|
1171 | 1179 | print "*"*60 |
|
1172 | 1180 | print " Starting SIGNAL CHAIN PROCESSING v%s " %schainpy.__version__ |
|
1173 | 1181 | print "*"*60 |
|
1174 | 1182 | |
|
1175 | 1183 | |
|
1176 | 1184 | keyList = self.procUnitConfObjDict.keys() |
|
1177 | 1185 | keyList.sort() |
|
1178 | 1186 | |
|
1179 | 1187 | while(True): |
|
1180 | 1188 | |
|
1181 | 1189 | is_ok = False |
|
1182 | 1190 | |
|
1183 | 1191 | for procKey in keyList: |
|
1184 | 1192 | # print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id) |
|
1185 | 1193 | |
|
1186 | 1194 | procUnitConfObj = self.procUnitConfObjDict[procKey] |
|
1187 | 1195 | |
|
1188 | 1196 | try: |
|
1189 | 1197 | sts = procUnitConfObj.run() |
|
1190 | 1198 | is_ok = is_ok or sts |
|
1191 | 1199 | except KeyboardInterrupt: |
|
1192 | 1200 | is_ok = False |
|
1193 | 1201 | break |
|
1194 | 1202 | except ValueError, e: |
|
1195 | 1203 | sleep(0.5) |
|
1196 | 1204 | self.__handleError(procUnitConfObj, send_email=True) |
|
1197 | 1205 | is_ok = False |
|
1198 | 1206 | break |
|
1199 | 1207 | except: |
|
1200 | 1208 | sleep(0.5) |
|
1201 | 1209 | self.__handleError(procUnitConfObj) |
|
1202 | 1210 | is_ok = False |
|
1203 | 1211 | break |
|
1204 | 1212 | |
|
1205 | 1213 | #If every process unit finished so end process |
|
1206 | 1214 | if not(is_ok): |
|
1207 | 1215 | # print "Every process unit have finished" |
|
1208 | 1216 | break |
|
1209 | 1217 | |
|
1210 | 1218 | if not self.runController(): |
|
1211 | 1219 | break |
|
1212 | 1220 | |
|
1213 | 1221 | #Closing every process |
|
1214 | 1222 | for procKey in keyList: |
|
1215 | 1223 | procUnitConfObj = self.procUnitConfObjDict[procKey] |
|
1216 | 1224 | procUnitConfObj.close() |
|
1217 | 1225 | |
|
1218 | 1226 | print "Process finished" |
|
1219 | 1227 | |
|
1220 | 1228 | def start(self): |
|
1221 | 1229 | |
|
1222 | 1230 | self.writeXml() |
|
1223 | 1231 | |
|
1224 | 1232 | self.createObjects() |
|
1225 | 1233 | self.connectObjects() |
|
1226 | 1234 | self.run() |
|
1227 | 1235 | |
|
1228 | 1236 | if __name__ == '__main__': |
|
1229 | 1237 | |
|
1230 | 1238 | desc = "Segundo Test" |
|
1231 | 1239 | filename = "schain.xml" |
|
1232 | 1240 | |
|
1233 | 1241 | controllerObj = Project() |
|
1234 | 1242 | |
|
1235 | 1243 | controllerObj.setup(id = '191', name='test01', description=desc) |
|
1236 | 1244 | |
|
1237 | 1245 | readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage', |
|
1238 | 1246 | path='data/rawdata/', |
|
1239 | 1247 | startDate='2011/01/01', |
|
1240 | 1248 | endDate='2012/12/31', |
|
1241 | 1249 | startTime='00:00:00', |
|
1242 | 1250 | endTime='23:59:59', |
|
1243 | 1251 | online=1, |
|
1244 | 1252 | walk=1) |
|
1245 | 1253 | |
|
1246 | 1254 | procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) |
|
1247 | 1255 | |
|
1248 | 1256 | opObj10 = procUnitConfObj0.addOperation(name='selectChannels') |
|
1249 | 1257 | opObj10.addParameter(name='channelList', value='3,4,5', format='intlist') |
|
1250 | 1258 | |
|
1251 | 1259 | opObj10 = procUnitConfObj0.addOperation(name='selectHeights') |
|
1252 | 1260 | opObj10.addParameter(name='minHei', value='90', format='float') |
|
1253 | 1261 | opObj10.addParameter(name='maxHei', value='180', format='float') |
|
1254 | 1262 | |
|
1255 | 1263 | opObj12 = procUnitConfObj0.addOperation(name='CohInt', optype='external') |
|
1256 | 1264 | opObj12.addParameter(name='n', value='10', format='int') |
|
1257 | 1265 | |
|
1258 | 1266 | procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId()) |
|
1259 | 1267 | procUnitConfObj1.addParameter(name='nFFTPoints', value='32', format='int') |
|
1260 | 1268 | # procUnitConfObj1.addParameter(name='pairList', value='(0,1),(0,2),(1,2)', format='') |
|
1261 | 1269 | |
|
1262 | 1270 | |
|
1263 | 1271 | opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='external') |
|
1264 | 1272 | opObj11.addParameter(name='idfigure', value='1', format='int') |
|
1265 | 1273 | opObj11.addParameter(name='wintitle', value='SpectraPlot0', format='str') |
|
1266 | 1274 | opObj11.addParameter(name='zmin', value='40', format='int') |
|
1267 | 1275 | opObj11.addParameter(name='zmax', value='90', format='int') |
|
1268 | 1276 | opObj11.addParameter(name='showprofile', value='1', format='int') |
|
1269 | 1277 | |
|
1270 | 1278 | print "Escribiendo el archivo XML" |
|
1271 | 1279 | |
|
1272 | 1280 | controllerObj.writeXml(filename) |
|
1273 | 1281 | |
|
1274 | 1282 | print "Leyendo el archivo XML" |
|
1275 | 1283 | controllerObj.readXml(filename) |
|
1276 | 1284 | #controllerObj.printattr() |
|
1277 | 1285 | |
|
1278 | 1286 | controllerObj.createObjects() |
|
1279 | 1287 | controllerObj.connectObjects() |
|
1280 | 1288 | controllerObj.run() |
|
1281 | 1289 | |
|
1282 | 1290 | No newline at end of file |
@@ -1,655 +1,659 | |||
|
1 | 1 | import os |
|
2 | 2 | import numpy |
|
3 | 3 | import time, datetime |
|
4 | 4 | import mpldriver |
|
5 | 5 | |
|
6 | 6 | from schainpy.model.proc.jroproc_base import Operation |
|
7 | 7 | |
|
8 | 8 | def isTimeInHourRange(datatime, xmin, xmax): |
|
9 | 9 | |
|
10 | 10 | if xmin == None or xmax == None: |
|
11 | 11 | return 1 |
|
12 | 12 | hour = datatime.hour + datatime.minute/60.0 |
|
13 | 13 | |
|
14 | 14 | if xmin < (xmax % 24): |
|
15 | 15 | |
|
16 | 16 | if hour >= xmin and hour <= xmax: |
|
17 | 17 | return 1 |
|
18 | 18 | else: |
|
19 | 19 | return 0 |
|
20 | 20 | |
|
21 | 21 | else: |
|
22 | 22 | |
|
23 | 23 | if hour >= xmin or hour <= (xmax % 24): |
|
24 | 24 | return 1 |
|
25 | 25 | else: |
|
26 | 26 | return 0 |
|
27 | 27 | |
|
28 | 28 | return 0 |
|
29 | 29 | |
|
30 | 30 | def isRealtime(utcdatatime): |
|
31 | 31 | |
|
32 | 32 | utcnow = time.mktime(time.localtime()) |
|
33 | 33 | delta = abs(utcnow - utcdatatime) # abs |
|
34 | 34 | if delta >= 30.: |
|
35 | 35 | return False |
|
36 | 36 | return True |
|
37 | 37 | |
|
38 | 38 | class Figure(Operation): |
|
39 | 39 | |
|
40 | 40 | __driver = mpldriver |
|
41 | 41 | fig = None |
|
42 | 42 | |
|
43 | 43 | id = None |
|
44 | 44 | wintitle = None |
|
45 | 45 | width = None |
|
46 | 46 | height = None |
|
47 | 47 | nplots = None |
|
48 | 48 | timerange = None |
|
49 | 49 | |
|
50 | 50 | axesObjList = [] |
|
51 | 51 | |
|
52 | 52 | WIDTH = 300 |
|
53 | 53 | HEIGHT = 200 |
|
54 | 54 | PREFIX = 'fig' |
|
55 | 55 | |
|
56 | 56 | xmin = None |
|
57 | 57 | xmax = None |
|
58 | 58 | |
|
59 | 59 | counter_imagwr = 0 |
|
60 | 60 | |
|
61 | 61 | figfile = None |
|
62 | 62 | |
|
63 | 63 | created = False |
|
64 | 64 | |
|
65 | 65 | def __init__(self): |
|
66 | 66 | |
|
67 | 67 | raise NotImplementedError |
|
68 | 68 | |
|
69 | 69 | def __del__(self): |
|
70 | 70 | |
|
71 | 71 | self.__driver.closeFigure() |
|
72 | 72 | |
|
73 | 73 | def getFilename(self, name, ext='.png'): |
|
74 | 74 | |
|
75 | 75 | path = '%s%03d' %(self.PREFIX, self.id) |
|
76 | 76 | filename = '%s_%s%s' %(self.PREFIX, name, ext) |
|
77 | 77 | return os.path.join(path, filename) |
|
78 | 78 | |
|
79 | 79 | def getAxesObjList(self): |
|
80 | 80 | |
|
81 | 81 | return self.axesObjList |
|
82 | 82 | |
|
83 | 83 | def getSubplots(self): |
|
84 | 84 | |
|
85 | 85 | raise NotImplementedError |
|
86 | 86 | |
|
87 | 87 | def getScreenDim(self, widthplot, heightplot): |
|
88 | 88 | |
|
89 | 89 | nrow, ncol = self.getSubplots() |
|
90 | 90 | |
|
91 | 91 | widthscreen = widthplot*ncol |
|
92 | 92 | heightscreen = heightplot*nrow |
|
93 | 93 | |
|
94 | 94 | return widthscreen, heightscreen |
|
95 | 95 | |
|
96 | 96 | def getTimeLim(self, x, xmin=None, xmax=None, timerange=None): |
|
97 | 97 | |
|
98 | 98 | # if self.xmin != None and self.xmax != None: |
|
99 | 99 | # if timerange == None: |
|
100 | 100 | # timerange = self.xmax - self.xmin |
|
101 | 101 | # xmin = self.xmin + timerange |
|
102 | 102 | # xmax = self.xmax + timerange |
|
103 | 103 | # |
|
104 | 104 | # return xmin, xmax |
|
105 | 105 | |
|
106 | 106 | if timerange == None and (xmin==None or xmax==None): |
|
107 | 107 | timerange = 14400 #seconds |
|
108 | 108 | |
|
109 | 109 | if timerange != None: |
|
110 | 110 | txmin = x[0] #- x[0] % min(timerange/10, 10*60) |
|
111 | 111 | else: |
|
112 | 112 | txmin = x[0] #- x[0] % 10*60 |
|
113 | 113 | |
|
114 | 114 | thisdatetime = datetime.datetime.utcfromtimestamp(txmin) |
|
115 | 115 | thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0)) |
|
116 | 116 | |
|
117 | 117 | if timerange != None: |
|
118 | 118 | xmin = (thisdatetime - thisdate).seconds/(60*60.) |
|
119 | 119 | xmax = xmin + timerange/(60*60.) |
|
120 | 120 | |
|
121 | 121 | mindt = thisdate + datetime.timedelta(hours=xmin) - datetime.timedelta(seconds=time.timezone) |
|
122 | 122 | xmin_sec = time.mktime(mindt.timetuple()) |
|
123 | 123 | |
|
124 | 124 | maxdt = thisdate + datetime.timedelta(hours=xmax) - datetime.timedelta(seconds=time.timezone) |
|
125 | 125 | xmax_sec = time.mktime(maxdt.timetuple()) |
|
126 | 126 | |
|
127 | 127 | return xmin_sec, xmax_sec |
|
128 | 128 | |
|
129 | 129 | def init(self, id, nplots, wintitle): |
|
130 | 130 | |
|
131 | 131 | raise NotImplementedError, "This method has been replaced with createFigure" |
|
132 | 132 | |
|
133 | 133 | def createFigure(self, id, wintitle, widthplot=None, heightplot=None, show=True): |
|
134 | 134 | |
|
135 | 135 | """ |
|
136 | 136 | Crea la figura de acuerdo al driver y parametros seleccionados seleccionados. |
|
137 | 137 | Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH |
|
138 | 138 | y self.HEIGHT y el numero de subplots (nrow, ncol) |
|
139 | 139 | |
|
140 | 140 | Input: |
|
141 | 141 | id : Los parametros necesarios son |
|
142 | 142 | wintitle : |
|
143 | 143 | |
|
144 | 144 | """ |
|
145 | 145 | |
|
146 | 146 | if widthplot == None: |
|
147 | 147 | widthplot = self.WIDTH |
|
148 | 148 | |
|
149 | 149 | if heightplot == None: |
|
150 | 150 | heightplot = self.HEIGHT |
|
151 | 151 | |
|
152 | 152 | self.id = id |
|
153 | 153 | |
|
154 | 154 | self.wintitle = wintitle |
|
155 | 155 | |
|
156 | 156 | self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot) |
|
157 | 157 | |
|
158 | 158 | # if self.created: |
|
159 | 159 | # self.__driver.closeFigure(self.fig) |
|
160 | 160 | |
|
161 | 161 | if not self.created: |
|
162 | 162 | self.fig = self.__driver.createFigure(id=self.id, |
|
163 | 163 | wintitle=self.wintitle, |
|
164 | 164 | width=self.widthscreen, |
|
165 | 165 | height=self.heightscreen, |
|
166 | 166 | show=show) |
|
167 | 167 | else: |
|
168 | 168 | self.__driver.clearFigure(self.fig) |
|
169 | 169 | |
|
170 | 170 | self.axesObjList = [] |
|
171 | 171 | self.counter_imagwr = 0 |
|
172 | 172 | |
|
173 | 173 | self.created = True |
|
174 | 174 | |
|
175 | 175 | def setDriver(self, driver=mpldriver): |
|
176 | 176 | |
|
177 | 177 | self.__driver = driver |
|
178 | 178 | |
|
179 | 179 | def setTitle(self, title): |
|
180 | 180 | |
|
181 | 181 | self.__driver.setTitle(self.fig, title) |
|
182 | 182 | |
|
183 | 183 | def setWinTitle(self, title): |
|
184 | 184 | |
|
185 | 185 | self.__driver.setWinTitle(self.fig, title=title) |
|
186 | 186 | |
|
187 | 187 | def setTextFromAxes(self, text): |
|
188 | 188 | |
|
189 | 189 | raise NotImplementedError, "This method has been replaced with Axes.setText" |
|
190 | 190 | |
|
191 | 191 | def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan): |
|
192 | 192 | |
|
193 | 193 | raise NotImplementedError, "This method has been replaced with Axes.addAxes" |
|
194 | 194 | |
|
195 | 195 | def addAxes(self, *args): |
|
196 | 196 | """ |
|
197 | 197 | |
|
198 | 198 | Input: |
|
199 | 199 | *args : Los parametros necesarios son |
|
200 | 200 | nrow, ncol, xpos, ypos, colspan, rowspan |
|
201 | 201 | """ |
|
202 | 202 | |
|
203 | 203 | axesObj = Axes(self.fig, *args) |
|
204 | 204 | self.axesObjList.append(axesObj) |
|
205 | 205 | |
|
206 | 206 | def saveFigure(self, figpath, figfile, *args): |
|
207 | 207 | |
|
208 | 208 | filename = os.path.join(figpath, figfile) |
|
209 | 209 | |
|
210 | 210 | fullpath = os.path.split(filename)[0] |
|
211 | 211 | |
|
212 | 212 | if not os.path.exists(fullpath): |
|
213 | 213 | subpath = os.path.split(fullpath)[0] |
|
214 | 214 | |
|
215 | 215 | if not os.path.exists(subpath): |
|
216 | 216 | os.mkdir(subpath) |
|
217 | 217 | |
|
218 | 218 | os.mkdir(fullpath) |
|
219 | 219 | |
|
220 | 220 | self.__driver.saveFigure(self.fig, filename, *args) |
|
221 | 221 | |
|
222 | 222 | def save(self, figpath, figfile=None, save=True, ftp=False, wr_period=1, thisDatetime=None, update_figfile=True): |
|
223 | 223 | |
|
224 | 224 | self.counter_imagwr += 1 |
|
225 | 225 | if self.counter_imagwr < wr_period: |
|
226 | 226 | return |
|
227 | 227 | |
|
228 | 228 | self.counter_imagwr = 0 |
|
229 | 229 | |
|
230 | 230 | if save: |
|
231 | 231 | |
|
232 | 232 | if not figfile: |
|
233 | 233 | |
|
234 | 234 | if not thisDatetime: |
|
235 | 235 | raise ValueError, "Saving figure: figfile or thisDatetime should be defined" |
|
236 | 236 | return |
|
237 | 237 | |
|
238 | 238 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
239 | 239 | figfile = self.getFilename(name = str_datetime) |
|
240 | 240 | |
|
241 | 241 | if self.figfile == None: |
|
242 | 242 | self.figfile = figfile |
|
243 | 243 | |
|
244 | 244 | if update_figfile: |
|
245 | 245 | self.figfile = figfile |
|
246 | 246 | |
|
247 | 247 | # store png plot to local folder |
|
248 | 248 | self.saveFigure(figpath, self.figfile) |
|
249 | 249 | |
|
250 | 250 | |
|
251 | 251 | if not ftp: |
|
252 | 252 | return |
|
253 | 253 | |
|
254 | 254 | if not thisDatetime: |
|
255 | 255 | return |
|
256 | 256 | |
|
257 | 257 | # store png plot to FTP server according to RT-Web format |
|
258 | 258 | ftp_filename = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
259 | 259 | # ftp_filename = os.path.join(figpath, name) |
|
260 | 260 | self.saveFigure(figpath, ftp_filename) |
|
261 | 261 | |
|
262 | 262 | def getNameToFtp(self, thisDatetime, FTP_WEI, EXP_CODE, SUB_EXP_CODE, PLOT_CODE, PLOT_POS): |
|
263 | 263 | YEAR_STR = '%4.4d'%thisDatetime.timetuple().tm_year |
|
264 | 264 | DOY_STR = '%3.3d'%thisDatetime.timetuple().tm_yday |
|
265 | 265 | FTP_WEI = '%2.2d'%FTP_WEI |
|
266 | 266 | EXP_CODE = '%3.3d'%EXP_CODE |
|
267 | 267 | SUB_EXP_CODE = '%2.2d'%SUB_EXP_CODE |
|
268 | 268 | PLOT_CODE = '%2.2d'%PLOT_CODE |
|
269 | 269 | PLOT_POS = '%2.2d'%PLOT_POS |
|
270 | 270 | name = YEAR_STR + DOY_STR + FTP_WEI + EXP_CODE + SUB_EXP_CODE + PLOT_CODE + PLOT_POS |
|
271 | 271 | return name |
|
272 | 272 | |
|
273 | 273 | def draw(self): |
|
274 | 274 | |
|
275 | 275 | self.__driver.draw(self.fig) |
|
276 | 276 | |
|
277 | 277 | def run(self): |
|
278 | 278 | |
|
279 | 279 | raise NotImplementedError |
|
280 | 280 | |
|
281 | 281 | def close(self, show=False): |
|
282 | 282 | |
|
283 | 283 | self.__driver.closeFigure(show=show, fig=self.fig) |
|
284 | 284 | |
|
285 | 285 | axesList = property(getAxesObjList) |
|
286 | 286 | |
|
287 | 287 | |
|
288 | 288 | class Axes: |
|
289 | 289 | |
|
290 | 290 | __driver = mpldriver |
|
291 | 291 | fig = None |
|
292 | 292 | ax = None |
|
293 | 293 | plot = None |
|
294 | 294 | __missing = 1E30 |
|
295 | 295 | __firsttime = None |
|
296 | 296 | |
|
297 | 297 | __showprofile = False |
|
298 | 298 | |
|
299 | 299 | xmin = None |
|
300 | 300 | xmax = None |
|
301 | 301 | ymin = None |
|
302 | 302 | ymax = None |
|
303 | 303 | zmin = None |
|
304 | 304 | zmax = None |
|
305 | 305 | |
|
306 | 306 | x_buffer = None |
|
307 | 307 | z_buffer = None |
|
308 | 308 | |
|
309 | 309 | decimationx = None |
|
310 | 310 | decimationy = None |
|
311 | 311 | |
|
312 |
__MAXNUMX = |
|
|
313 |
__MAXNUMY = |
|
|
312 | __MAXNUMX = 200 | |
|
313 | __MAXNUMY = 400 | |
|
314 | ||
|
315 | __MAXNUMTIME = 500 | |
|
314 | 316 | |
|
315 | 317 | def __init__(self, *args): |
|
316 | 318 | |
|
317 | 319 | """ |
|
318 | 320 | |
|
319 | 321 | Input: |
|
320 | 322 | *args : Los parametros necesarios son |
|
321 | 323 | fig, nrow, ncol, xpos, ypos, colspan, rowspan |
|
322 | 324 | """ |
|
323 | 325 | |
|
324 | 326 | ax = self.__driver.createAxes(*args) |
|
325 | 327 | self.fig = args[0] |
|
326 | 328 | self.ax = ax |
|
327 | 329 | self.plot = None |
|
328 | 330 | |
|
329 | 331 | self.__firsttime = True |
|
330 | 332 | self.idlineList = [] |
|
331 | 333 | |
|
332 | 334 | self.x_buffer = numpy.array([]) |
|
333 | 335 | self.z_buffer = numpy.array([]) |
|
334 | 336 | |
|
335 | 337 | def setText(self, text): |
|
336 | 338 | |
|
337 | 339 | self.__driver.setAxesText(self.ax, text) |
|
338 | 340 | |
|
339 | 341 | def setXAxisAsTime(self): |
|
340 | 342 | pass |
|
341 | 343 | |
|
342 | 344 | def pline(self, x, y, |
|
343 | 345 | xmin=None, xmax=None, |
|
344 | 346 | ymin=None, ymax=None, |
|
345 | 347 | xlabel='', ylabel='', |
|
346 | 348 | title='', |
|
347 | 349 | **kwargs): |
|
348 | 350 | |
|
349 | 351 | """ |
|
350 | 352 | |
|
351 | 353 | Input: |
|
352 | 354 | x : |
|
353 | 355 | y : |
|
354 | 356 | xmin : |
|
355 | 357 | xmax : |
|
356 | 358 | ymin : |
|
357 | 359 | ymax : |
|
358 | 360 | xlabel : |
|
359 | 361 | ylabel : |
|
360 | 362 | title : |
|
361 | 363 | **kwargs : Los parametros aceptados son |
|
362 | 364 | |
|
363 | 365 | ticksize |
|
364 | 366 | ytick_visible |
|
365 | 367 | """ |
|
366 | 368 | |
|
367 | 369 | if self.__firsttime: |
|
368 | 370 | |
|
369 | 371 | if xmin == None: xmin = numpy.nanmin(x) |
|
370 | 372 | if xmax == None: xmax = numpy.nanmax(x) |
|
371 | 373 | if ymin == None: ymin = numpy.nanmin(y) |
|
372 | 374 | if ymax == None: ymax = numpy.nanmax(y) |
|
373 | 375 | |
|
374 | 376 | self.plot = self.__driver.createPline(self.ax, x, y, |
|
375 | 377 | xmin, xmax, |
|
376 | 378 | ymin, ymax, |
|
377 | 379 | xlabel=xlabel, |
|
378 | 380 | ylabel=ylabel, |
|
379 | 381 | title=title, |
|
380 | 382 | **kwargs) |
|
381 | 383 | |
|
382 | 384 | self.idlineList.append(0) |
|
383 | 385 | self.__firsttime = False |
|
384 | 386 | return |
|
385 | 387 | |
|
386 | 388 | self.__driver.pline(self.plot, x, y, xlabel=xlabel, |
|
387 | 389 | ylabel=ylabel, |
|
388 | 390 | title=title) |
|
389 | 391 | |
|
390 | 392 | # self.__driver.pause() |
|
391 | 393 | |
|
392 | 394 | def addpline(self, x, y, idline, **kwargs): |
|
393 | 395 | lines = self.ax.lines |
|
394 | 396 | |
|
395 | 397 | if idline in self.idlineList: |
|
396 | 398 | self.__driver.set_linedata(self.ax, x, y, idline) |
|
397 | 399 | |
|
398 | 400 | if idline not in(self.idlineList): |
|
399 | 401 | self.__driver.addpline(self.ax, x, y, **kwargs) |
|
400 | 402 | self.idlineList.append(idline) |
|
401 | 403 | |
|
402 | 404 | return |
|
403 | 405 | |
|
404 | 406 | def pmultiline(self, x, y, |
|
405 | 407 | xmin=None, xmax=None, |
|
406 | 408 | ymin=None, ymax=None, |
|
407 | 409 | xlabel='', ylabel='', |
|
408 | 410 | title='', |
|
409 | 411 | **kwargs): |
|
410 | 412 | |
|
411 | 413 | if self.__firsttime: |
|
412 | 414 | |
|
413 | 415 | if xmin == None: xmin = numpy.nanmin(x) |
|
414 | 416 | if xmax == None: xmax = numpy.nanmax(x) |
|
415 | 417 | if ymin == None: ymin = numpy.nanmin(y) |
|
416 | 418 | if ymax == None: ymax = numpy.nanmax(y) |
|
417 | 419 | |
|
418 | 420 | self.plot = self.__driver.createPmultiline(self.ax, x, y, |
|
419 | 421 | xmin, xmax, |
|
420 | 422 | ymin, ymax, |
|
421 | 423 | xlabel=xlabel, |
|
422 | 424 | ylabel=ylabel, |
|
423 | 425 | title=title, |
|
424 | 426 | **kwargs) |
|
425 | 427 | self.__firsttime = False |
|
426 | 428 | return |
|
427 | 429 | |
|
428 | 430 | self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel, |
|
429 | 431 | ylabel=ylabel, |
|
430 | 432 | title=title) |
|
431 | 433 | |
|
432 | 434 | # self.__driver.pause() |
|
433 | 435 | |
|
434 | 436 | def pmultilineyaxis(self, x, y, |
|
435 | 437 | xmin=None, xmax=None, |
|
436 | 438 | ymin=None, ymax=None, |
|
437 | 439 | xlabel='', ylabel='', |
|
438 | 440 | title='', |
|
439 | 441 | **kwargs): |
|
440 | 442 | |
|
441 | 443 | if self.__firsttime: |
|
442 | 444 | |
|
443 | 445 | if xmin == None: xmin = numpy.nanmin(x) |
|
444 | 446 | if xmax == None: xmax = numpy.nanmax(x) |
|
445 | 447 | if ymin == None: ymin = numpy.nanmin(y) |
|
446 | 448 | if ymax == None: ymax = numpy.nanmax(y) |
|
447 | 449 | |
|
448 | 450 | self.plot = self.__driver.createPmultilineYAxis(self.ax, x, y, |
|
449 | 451 | xmin, xmax, |
|
450 | 452 | ymin, ymax, |
|
451 | 453 | xlabel=xlabel, |
|
452 | 454 | ylabel=ylabel, |
|
453 | 455 | title=title, |
|
454 | 456 | **kwargs) |
|
455 | 457 | if self.xmin == None: self.xmin = xmin |
|
456 | 458 | if self.xmax == None: self.xmax = xmax |
|
457 | 459 | if self.ymin == None: self.ymin = ymin |
|
458 | 460 | if self.ymax == None: self.ymax = ymax |
|
459 | 461 | |
|
460 | 462 | self.__firsttime = False |
|
461 | 463 | return |
|
462 | 464 | |
|
463 | 465 | self.__driver.pmultilineyaxis(self.plot, x, y, xlabel=xlabel, |
|
464 | 466 | ylabel=ylabel, |
|
465 | 467 | title=title) |
|
466 | 468 | |
|
467 | 469 | # self.__driver.pause() |
|
468 | 470 | |
|
469 | 471 | def pcolor(self, x, y, z, |
|
470 | 472 | xmin=None, xmax=None, |
|
471 | 473 | ymin=None, ymax=None, |
|
472 | 474 | zmin=None, zmax=None, |
|
473 | 475 | xlabel='', ylabel='', |
|
474 |
title='' |
|
|
476 | title='', colormap='jet', | |
|
475 | 477 | **kwargs): |
|
476 | 478 | |
|
477 | 479 | """ |
|
478 | 480 | Input: |
|
479 | 481 | x : |
|
480 | 482 | y : |
|
481 | 483 | x : |
|
482 | 484 | xmin : |
|
483 | 485 | xmax : |
|
484 | 486 | ymin : |
|
485 | 487 | ymax : |
|
486 | 488 | zmin : |
|
487 | 489 | zmax : |
|
488 | 490 | xlabel : |
|
489 | 491 | ylabel : |
|
490 | 492 | title : |
|
491 | 493 | **kwargs : Los parametros aceptados son |
|
492 | 494 | ticksize=9, |
|
493 | 495 | cblabel='' |
|
494 | rti = True or False | |
|
495 | 496 | """ |
|
497 | ||
|
498 | #Decimating data | |
|
499 | xlen = len(x) | |
|
500 | ylen = len(y) | |
|
501 | ||
|
502 | decimationx = numpy.floor(xlen/self.__MAXNUMX) + 1 | |
|
503 | decimationy = numpy.floor(ylen/self.__MAXNUMY) + 1 | |
|
504 | ||
|
505 | x_buffer = x[::decimationx] | |
|
506 | y_buffer = y[::decimationy] | |
|
507 | z_buffer = z[::decimationx, ::decimationy] | |
|
508 | #=================================================== | |
|
496 | 509 | |
|
497 | 510 | if self.__firsttime: |
|
498 | 511 | |
|
499 | 512 | if xmin == None: xmin = numpy.nanmin(x) |
|
500 | 513 | if xmax == None: xmax = numpy.nanmax(x) |
|
501 | 514 | if ymin == None: ymin = numpy.nanmin(y) |
|
502 | 515 | if ymax == None: ymax = numpy.nanmax(y) |
|
503 | 516 | if zmin == None: zmin = numpy.nanmin(z) |
|
504 | 517 | if zmax == None: zmax = numpy.nanmax(z) |
|
505 | 518 | |
|
506 | 519 | |
|
507 |
self.plot = self.__driver.createPcolor(self.ax, x |
|
|
520 | self.plot = self.__driver.createPcolor(self.ax, x_buffer, | |
|
521 | y_buffer, | |
|
522 | z_buffer, | |
|
508 | 523 | xmin, xmax, |
|
509 | 524 | ymin, ymax, |
|
510 | 525 | zmin, zmax, |
|
511 | 526 | xlabel=xlabel, |
|
512 | 527 | ylabel=ylabel, |
|
513 | 528 | title=title, |
|
514 | 529 | colormap=colormap, |
|
515 | 530 | **kwargs) |
|
516 | 531 | |
|
517 | 532 | if self.xmin == None: self.xmin = xmin |
|
518 | 533 | if self.xmax == None: self.xmax = xmax |
|
519 | 534 | if self.ymin == None: self.ymin = ymin |
|
520 | 535 | if self.ymax == None: self.ymax = ymax |
|
521 | 536 | if self.zmin == None: self.zmin = zmin |
|
522 | 537 | if self.zmax == None: self.zmax = zmax |
|
523 | 538 | |
|
524 | 539 | self.__firsttime = False |
|
525 | 540 | return |
|
526 | 541 | |
|
527 | if rti: | |
|
528 | self.__driver.addpcolor(self.ax, x, y, z, self.zmin, self.zmax, | |
|
529 | xlabel=xlabel, | |
|
530 | ylabel=ylabel, | |
|
531 | title=title, | |
|
532 | colormap=colormap) | |
|
533 | return | |
|
534 | ||
|
535 | self.__driver.pcolor(self.plot, z, | |
|
542 | self.__driver.pcolor(self.plot, | |
|
543 | z_buffer, | |
|
536 | 544 | xlabel=xlabel, |
|
537 | 545 | ylabel=ylabel, |
|
538 | 546 | title=title) |
|
539 | 547 | |
|
540 | 548 | # self.__driver.pause() |
|
541 | 549 | |
|
542 | 550 | def pcolorbuffer(self, x, y, z, |
|
543 | 551 | xmin=None, xmax=None, |
|
544 | 552 | ymin=None, ymax=None, |
|
545 | 553 | zmin=None, zmax=None, |
|
546 | 554 | xlabel='', ylabel='', |
|
547 | 555 | title='', rti = True, colormap='jet', |
|
548 | 556 | maxNumX = None, maxNumY = None, |
|
549 | 557 | **kwargs): |
|
550 | 558 | |
|
551 | 559 | if maxNumX == None: |
|
552 |
maxNumX = self.__MAXNUM |
|
|
560 | maxNumX = self.__MAXNUMTIME | |
|
553 | 561 | |
|
554 | 562 | if maxNumY == None: |
|
555 | 563 | maxNumY = self.__MAXNUMY |
|
556 | 564 | |
|
557 | 565 | if self.__firsttime: |
|
558 | 566 | self.z_buffer = z |
|
559 | 567 | self.x_buffer = numpy.hstack((self.x_buffer, x)) |
|
560 | 568 | |
|
561 | 569 | if xmin == None: xmin = numpy.nanmin(x) |
|
562 | 570 | if xmax == None: xmax = numpy.nanmax(x) |
|
563 | 571 | if ymin == None: ymin = numpy.nanmin(y) |
|
564 | 572 | if ymax == None: ymax = numpy.nanmax(y) |
|
565 | 573 | if zmin == None: zmin = numpy.nanmin(z) |
|
566 | 574 | if zmax == None: zmax = numpy.nanmax(z) |
|
567 | 575 | |
|
568 | 576 | |
|
569 | 577 | self.plot = self.__driver.createPcolor(self.ax, self.x_buffer, y, z, |
|
570 | 578 | xmin, xmax, |
|
571 | 579 | ymin, ymax, |
|
572 | 580 | zmin, zmax, |
|
573 | 581 | xlabel=xlabel, |
|
574 | 582 | ylabel=ylabel, |
|
575 | 583 | title=title, |
|
576 | 584 | colormap=colormap, |
|
577 | 585 | **kwargs) |
|
578 | 586 | |
|
579 | 587 | if self.xmin == None: self.xmin = xmin |
|
580 | 588 | if self.xmax == None: self.xmax = xmax |
|
581 | 589 | if self.ymin == None: self.ymin = ymin |
|
582 | 590 | if self.ymax == None: self.ymax = ymax |
|
583 | 591 | if self.zmin == None: self.zmin = zmin |
|
584 | 592 | if self.zmax == None: self.zmax = zmax |
|
585 | 593 | |
|
586 | 594 | self.__firsttime = False |
|
587 | 595 | return |
|
588 | 596 | |
|
589 | 597 | self.x_buffer = numpy.hstack((self.x_buffer[:-1], x[0], x[-1])) |
|
590 | 598 | self.z_buffer = numpy.hstack((self.z_buffer, z)) |
|
599 | z_buffer = self.z_buffer.reshape(-1,len(y)) | |
|
591 | 600 | |
|
592 | if self.decimationx == None: | |
|
593 | deltax = float(self.xmax - self.xmin)/maxNumX | |
|
594 | deltay = float(self.ymax - self.ymin)/maxNumY | |
|
595 | ||
|
596 | resolutionx = self.x_buffer[2]-self.x_buffer[0] | |
|
597 | resolutiony = y[1]-y[0] | |
|
598 | ||
|
599 | self.decimationx = numpy.ceil(deltax / resolutionx) | |
|
600 | self.decimationy = numpy.ceil(deltay / resolutiony) | |
|
601 | #Decimating data | |
|
602 | xlen = len(self.x_buffer) | |
|
603 | ylen = len(y) | |
|
601 | 604 | |
|
602 | z_buffer = self.z_buffer.reshape(-1,len(y)) | |
|
605 | decimationx = numpy.floor(xlen/maxNumX) + 1 | |
|
606 | decimationy = numpy.floor(ylen/maxNumY) + 1 | |
|
603 | 607 | |
|
604 |
x_buffer = self.x_buffer[:: |
|
|
605 |
y_buffer = y[:: |
|
|
606 |
z_buffer = z_buffer[:: |
|
|
608 | x_buffer = self.x_buffer[::decimationx] | |
|
609 | y_buffer = y[::decimationy] | |
|
610 | z_buffer = z_buffer[::decimationx, ::decimationy] | |
|
607 | 611 | #=================================================== |
|
608 | 612 | |
|
609 | 613 | x_buffer, y_buffer, z_buffer = self.__fillGaps(x_buffer, y_buffer, z_buffer) |
|
610 | 614 | |
|
611 | 615 | self.__driver.addpcolorbuffer(self.ax, x_buffer, y_buffer, z_buffer, self.zmin, self.zmax, |
|
612 | 616 | xlabel=xlabel, |
|
613 | 617 | ylabel=ylabel, |
|
614 | 618 | title=title, |
|
615 | 619 | colormap=colormap) |
|
616 | 620 | |
|
617 | 621 | # self.__driver.pause() |
|
618 | 622 | |
|
619 | 623 | def polar(self, x, y, |
|
620 | 624 | title='', xlabel='',ylabel='',**kwargs): |
|
621 | 625 | |
|
622 | 626 | if self.__firsttime: |
|
623 | 627 | self.plot = self.__driver.createPolar(self.ax, x, y, title = title, xlabel = xlabel, ylabel = ylabel) |
|
624 | 628 | self.__firsttime = False |
|
625 | 629 | self.x_buffer = x |
|
626 | 630 | self.y_buffer = y |
|
627 | 631 | return |
|
628 | 632 | |
|
629 | 633 | self.x_buffer = numpy.hstack((self.x_buffer,x)) |
|
630 | 634 | self.y_buffer = numpy.hstack((self.y_buffer,y)) |
|
631 | 635 | self.__driver.polar(self.plot, self.x_buffer, self.y_buffer, xlabel=xlabel, |
|
632 | 636 | ylabel=ylabel, |
|
633 | 637 | title=title) |
|
634 | 638 | |
|
635 | 639 | # self.__driver.pause() |
|
636 | 640 | |
|
637 | 641 | def __fillGaps(self, x_buffer, y_buffer, z_buffer): |
|
638 | 642 | |
|
639 | 643 | if x_buffer.shape[0] < 2: |
|
640 | 644 | return x_buffer, y_buffer, z_buffer |
|
641 | 645 | |
|
642 | 646 | deltas = x_buffer[1:] - x_buffer[0:-1] |
|
643 | 647 | x_median = numpy.median(deltas) |
|
644 | 648 | |
|
645 | 649 | index = numpy.where(deltas > 5*x_median) |
|
646 | 650 | |
|
647 | 651 | if len(index[0]) != 0: |
|
648 | 652 | z_buffer[index[0],::] = self.__missing |
|
649 | 653 | z_buffer = numpy.ma.masked_inside(z_buffer,0.99*self.__missing,1.01*self.__missing) |
|
650 | 654 | |
|
651 | 655 | return x_buffer, y_buffer, z_buffer |
|
652 | 656 | |
|
653 | 657 | |
|
654 | 658 | |
|
655 | 659 | No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now