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