@@ -0,0 +1,113 | |||||
|
1 | import os, sys | |||
|
2 | ||||
|
3 | path = os.path.split(os.getcwd())[0] | |||
|
4 | sys.path.append(path) | |||
|
5 | ||||
|
6 | from controller import * | |||
|
7 | ||||
|
8 | desc = "Meteor Experiment Test" | |||
|
9 | filename = "meteor20130812.xml" | |||
|
10 | ||||
|
11 | controllerObj = Project() | |||
|
12 | controllerObj.setup(id = '191', name='meteor_test01', description=desc) | |||
|
13 | ||||
|
14 | path = '/home/dsuarez/.gvfs/datos on 10.10.20.2/High_Power_Meteor' | |||
|
15 | ||||
|
16 | path = '/Volumes/FREE_DISK/meteor_data' | |||
|
17 | ||||
|
18 | path = '/Users/dsuarez/Movies/meteor' | |||
|
19 | ||||
|
20 | readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage', | |||
|
21 | path=path, | |||
|
22 | startDate='2013/08/01', | |||
|
23 | endDate='2013/08/30', | |||
|
24 | startTime='00:00:00', | |||
|
25 | endTime='23:59:59', | |||
|
26 | online=0, | |||
|
27 | delay=5, | |||
|
28 | walk=0) | |||
|
29 | ||||
|
30 | opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock') | |||
|
31 | ||||
|
32 | procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) | |||
|
33 | ||||
|
34 | opObj11 = procUnitConfObj0.addOperation(name='ProfileSelector', optype='other') | |||
|
35 | opObj11.addParameter(name='profileList', | |||
|
36 | value='1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, \ | |||
|
37 | 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, \ | |||
|
38 | 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, \ | |||
|
39 | 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99, 101, \ | |||
|
40 | 103, 105, 107, 109, 111, 113, 115, 117, 119, 121, 123, \ | |||
|
41 | 125, 127, 129, 131, 133, 135, 137, 139, 141, 143, 145, \ | |||
|
42 | 147, 149, 151, 153, 155, 157, 159, 161, 163, 165, 167, \ | |||
|
43 | 169, 171, 173, 175, 177, 179, 181, 183, 185, 187, 189, \ | |||
|
44 | 191, 193, 195, 197, 199, 201, 203, 205, 207, 209, 211, \ | |||
|
45 | 213, 215, 217, 219, 221, 223, 225, 227, 229, 231, 233, \ | |||
|
46 | 235, 237, 239, 241, 243, 245, 247, 249, 251, 253, 255, \ | |||
|
47 | 257, 259, 261, 263, 265, 267, 269, 271, 273, 275, 277, \ | |||
|
48 | 279, 281, 283, 285, 287, 289, 291, 293, 295, 297, 299, \ | |||
|
49 | 301, 303, 305, 307, 309, 311, 313, 315, 317, 319, 321, \ | |||
|
50 | 323, 325, 327, 329, 331, 333, 335, 337, 339, 341, 343, \ | |||
|
51 | 345, 347, 349, 351, 353, 355, 357, 359, 361, 363, 365, \ | |||
|
52 | 367, 369, 371, 373, 375, 377, 379, 381, 383, 385, 387, \ | |||
|
53 | 389, 391, 393, 395, 397, 399, 401, 403, 405, 407, 409, \ | |||
|
54 | 411, 413, 415, 417, 419, 421, 423, 425, 427, 429, 431, \ | |||
|
55 | 433, 435, 437, 439, 441, 443, 445, 447, 449, 451, 453, \ | |||
|
56 | 455, 457, 459, 461, 463, 465, 467, 469, 471, 473, 475, \ | |||
|
57 | 477, 479, 481, 483, 485, 487, 489, 491, 493, 495, 497, \ | |||
|
58 | 499, 501, 503, 505, 507, 509, 511, 513, 515, 517, 519, \ | |||
|
59 | 521, 523, 525, 527, 529, 531, 533, 535, 537, 539, 541, \ | |||
|
60 | 543, 545, 547, 549, 551, 553, 555, 557, 559, 561, 563, \ | |||
|
61 | 565, 567, 569, 571, 573, 575, 577, 579, 581, 583, 585, \ | |||
|
62 | 587, 589, 591, 593, 595, 597, 599, 601, 603, 605, 607, \ | |||
|
63 | 609, 611, 613, 615, 617, 619, 621, 623, 625, 627, 629, \ | |||
|
64 | 631, 633, 635, 637, 639, 641, 643, 645, 647, 649, 651, \ | |||
|
65 | 653, 655, 657, 659, 661, 663, 665, 667, 669, 671, 673, \ | |||
|
66 | 675, 677, 679, 681, 683, 685, 687, 689, 691, 693, 695, \ | |||
|
67 | 697, 699, 701, 703, 705, 707, 709, 711, 713, 715, 717, \ | |||
|
68 | 719, 721, 723, 725, 727, 729, 731, 733, 735, 737, 739, \ | |||
|
69 | 741, 743, 745, 747, 749, 751, 753, 755, 757, 759, 761, \ | |||
|
70 | 763, 765, 767, 769, 771, 773, 775, 777, 779, 781, 783, \ | |||
|
71 | 785, 787, 789, 791, 793, 795, 797, 799', format='intlist') | |||
|
72 | ||||
|
73 | # opObj11 = procUnitConfObj0.addOperation(name='filterByHeights') | |||
|
74 | # opObj11.addParameter(name='window', value='3', format='int') | |||
|
75 | ||||
|
76 | opObj11 = procUnitConfObj0.addOperation(name='Decoder', optype='other') | |||
|
77 | opObj11.addParameter(name='code', value='1,1,1,1,1,-1,-1,1,1,-1,1,-1,1', format='floatlist') | |||
|
78 | opObj11.addParameter(name='nCode', value='1', format='int') | |||
|
79 | opObj11.addParameter(name='nBaud', value='13', format='int') | |||
|
80 | ||||
|
81 | procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId()) | |||
|
82 | procUnitConfObj1.addParameter(name='nFFTPoints', value='64', format='int') | |||
|
83 | ||||
|
84 | opObj11 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') | |||
|
85 | opObj11.addParameter(name='n', value='5', format='int') | |||
|
86 | ||||
|
87 | opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') | |||
|
88 | opObj11.addParameter(name='id', value='100', format='int') | |||
|
89 | opObj11.addParameter(name='wintitle', value='MeteorSpectra', format='str') | |||
|
90 | # opObj11.addParameter(name='save', value='1', format='int') | |||
|
91 | # opObj11.addParameter(name='figpath', value='/Users/dsuarez/Pictures', format='str') | |||
|
92 | # opObj11.addParameter(name='ftp', value='1', format='int') | |||
|
93 | # opObj11.addParameter(name='res_imagwr', value='1', format='int') | |||
|
94 | ||||
|
95 | # opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other') | |||
|
96 | # opObj11.addParameter(name='id', value='101', format='int') | |||
|
97 | # opObj11.addParameter(name='wintitle', value='MeteorRTI', format='str') | |||
|
98 | # opObj11.addParameter(name='xmin', value='0', format='float') | |||
|
99 | # opObj11.addParameter(name='xmax', value='24', format='float') | |||
|
100 | # opObj11.addParameter(name='save', value='1', format='int') | |||
|
101 | # opObj11.addParameter(name='figpath', value='/Users/dsuarez/Pictures', format='str') | |||
|
102 | # opObj11.addParameter(name='ftp', value='1', format='int') | |||
|
103 | # opObj11.addParameter(name='res_imagwr', value='1', format='int') | |||
|
104 | ||||
|
105 | ||||
|
106 | print "Escribiendo el archivo XML" | |||
|
107 | controllerObj.writeXml(filename) | |||
|
108 | print "Leyendo el archivo XML" | |||
|
109 | controllerObj.readXml(filename) | |||
|
110 | ||||
|
111 | controllerObj.createObjects() | |||
|
112 | controllerObj.connectObjects() | |||
|
113 | controllerObj.run() |
@@ -1,293 +1,293 | |||||
1 | import os.path |
|
1 | import os.path | |
2 | import ftplib |
|
2 | import ftplib | |
3 |
|
3 | |||
4 |
|
4 | |||
5 | class Ftp(): |
|
5 | class Ftp(): | |
6 | """ |
|
6 | """ | |
7 | Ftp is a public class used to define custom File Transfer Protocol from "ftplib" python module |
|
7 | Ftp is a public class used to define custom File Transfer Protocol from "ftplib" python module | |
8 |
|
8 | |||
9 | Non-standard Python modules used: None |
|
9 | Non-standard Python modules used: None | |
10 |
|
10 | |||
11 | Written by "Daniel Suarez":mailto:daniel.suarez@jro.igp.gob.pe Oct. 26, 2010 |
|
11 | Written by "Daniel Suarez":mailto:daniel.suarez@jro.igp.gob.pe Oct. 26, 2010 | |
12 | """ |
|
12 | """ | |
13 |
|
13 | |||
14 | def __init__(self,host = None, username=None, passw=None, remotefolder=None): |
|
14 | def __init__(self,host = None, username=None, passw=None, remotefolder=None): | |
15 | """ |
|
15 | """ | |
16 | This method is used to setting parameters for FTP and establishing connection to remote host |
|
16 | This method is used to setting parameters for FTP and establishing connection to remote host | |
17 |
|
17 | |||
18 | Inputs: |
|
18 | Inputs: | |
19 | host - remote host IP Address |
|
19 | host - remote host IP Address | |
20 |
|
20 | |||
21 | username - remote host Username |
|
21 | username - remote host Username | |
22 |
|
22 | |||
23 | passw - remote host Passw |
|
23 | passw - remote host Passw | |
24 |
|
24 | |||
25 | remotefolder - remote host current working directory |
|
25 | remotefolder - remote host current working directory | |
26 |
|
26 | |||
27 | Return: void |
|
27 | Return: void | |
28 |
|
28 | |||
29 | Affects: |
|
29 | Affects: | |
30 | self.status - in Error Case or Connection Failed this parameter is set to 1 else 0 |
|
30 | self.status - in Error Case or Connection Failed this parameter is set to 1 else 0 | |
31 |
|
31 | |||
32 | self.folderList - sub-folder list of remote folder |
|
32 | self.folderList - sub-folder list of remote folder | |
33 |
|
33 | |||
34 | self.fileList - file list of remote folder |
|
34 | self.fileList - file list of remote folder | |
35 |
|
35 | |||
36 |
|
36 | |||
37 | """ |
|
37 | """ | |
38 |
|
38 | |||
39 | if ((host == None) and (username==None) and (passw==None) and (remotefolder==None)): |
|
39 | if ((host == None) and (username==None) and (passw==None) and (remotefolder==None)): | |
40 | host, username, passw, remotefolder = self.parmsByDefault() |
|
40 | host, username, passw, remotefolder = self.parmsByDefault() | |
41 |
|
41 | |||
42 | self.host = host |
|
42 | self.host = host | |
43 | self.username = username |
|
43 | self.username = username | |
44 | self.passw = passw |
|
44 | self.passw = passw | |
45 | self.remotefolder = remotefolder |
|
45 | self.remotefolder = remotefolder | |
46 | self.file = None |
|
46 | self.file = None | |
47 | self.ftp = None |
|
47 | self.ftp = None | |
48 | self.status = 0 |
|
48 | self.status = 0 | |
49 |
|
49 | |||
50 | try: |
|
50 | try: | |
51 | self.ftp = ftplib.FTP(self.host) |
|
51 | self.ftp = ftplib.FTP(self.host) | |
52 | self.ftp.login(self.username,self.passw) |
|
52 | self.ftp.login(self.username,self.passw) | |
53 | self.ftp.cwd(self.remotefolder) |
|
53 | self.ftp.cwd(self.remotefolder) | |
54 | # print 'Connect to FTP Server: Successfully' |
|
54 | # print 'Connect to FTP Server: Successfully' | |
55 |
|
55 | |||
56 | except ftplib.all_errors: |
|
56 | except ftplib.all_errors: | |
57 | print 'Error FTP Service' |
|
57 | print 'Error FTP Service' | |
58 | self.status = 1 |
|
58 | self.status = 1 | |
59 | return |
|
59 | return | |
60 |
|
60 | |||
61 |
|
61 | |||
62 |
|
62 | |||
63 | self.dirList = [] |
|
63 | self.dirList = [] | |
64 |
|
64 | |||
65 | try: |
|
65 | try: | |
66 | self.dirList = self.ftp.nlst() |
|
66 | self.dirList = self.ftp.nlst() | |
67 |
|
67 | |||
68 | except ftplib.error_perm, resp: |
|
68 | except ftplib.error_perm, resp: | |
69 | if str(resp) == "550 No files found": |
|
69 | if str(resp) == "550 No files found": | |
70 | print "no files in this directory" |
|
70 | print "no files in this directory" | |
71 | self.status = 1 |
|
71 | self.status = 1 | |
72 | return |
|
72 | return | |
73 |
|
73 | |||
74 | except ftplib.all_errors: |
|
74 | except ftplib.all_errors: | |
75 | print 'Error Displaying Dir-Files' |
|
75 | print 'Error Displaying Dir-Files' | |
76 | self.status = 1 |
|
76 | self.status = 1 | |
77 | return |
|
77 | return | |
78 |
|
78 | |||
79 | self.fileList = [] |
|
79 | self.fileList = [] | |
80 | self.folderList = [] |
|
80 | self.folderList = [] | |
81 | #only for test |
|
81 | #only for test | |
82 | for f in self.dirList: |
|
82 | for f in self.dirList: | |
83 | name, ext = os.path.splitext(f) |
|
83 | name, ext = os.path.splitext(f) | |
84 | if ext != '': |
|
84 | if ext != '': | |
85 | self.fileList.append(f) |
|
85 | self.fileList.append(f) | |
86 | # print 'filename: %s - size: %d'%(f,self.ftp.size(f)) |
|
86 | # print 'filename: %s - size: %d'%(f,self.ftp.size(f)) | |
87 |
|
87 | |||
88 | def parmsByDefault(self): |
|
88 | def parmsByDefault(self): | |
89 | host = 'jro.igp.gob.pe' |
|
89 | host = 'jro-app.igp.gob.pe' | |
90 |
username = ' |
|
90 | username = 'wmaster' | |
91 |
passw = 'mst |
|
91 | passw = 'mst2010vhf' | |
92 |
remotefolder = '/ |
|
92 | remotefolder = '/home/wmaster/graficos' | |
93 |
|
93 | |||
94 | return host, username, passw, remotefolder |
|
94 | return host, username, passw, remotefolder | |
95 |
|
95 | |||
96 |
|
96 | |||
97 | def mkd(self,dirname): |
|
97 | def mkd(self,dirname): | |
98 | """ |
|
98 | """ | |
99 | mkd is used to make directory in remote host |
|
99 | mkd is used to make directory in remote host | |
100 |
|
100 | |||
101 | Input: |
|
101 | Input: | |
102 | dirname - directory name |
|
102 | dirname - directory name | |
103 |
|
103 | |||
104 | Return: |
|
104 | Return: | |
105 | 1 in error case else 0 |
|
105 | 1 in error case else 0 | |
106 | """ |
|
106 | """ | |
107 | try: |
|
107 | try: | |
108 | self.ftp.mkd(dirname) |
|
108 | self.ftp.mkd(dirname) | |
109 | except: |
|
109 | except: | |
110 | print 'Error creating remote folder:%s'%dirname |
|
110 | print 'Error creating remote folder:%s'%dirname | |
111 | return 1 |
|
111 | return 1 | |
112 |
|
112 | |||
113 | return 0 |
|
113 | return 0 | |
114 |
|
114 | |||
115 |
|
115 | |||
116 | def delete(self,filename): |
|
116 | def delete(self,filename): | |
117 | """ |
|
117 | """ | |
118 | delete is used to delete file in current working directory of remote host |
|
118 | delete is used to delete file in current working directory of remote host | |
119 |
|
119 | |||
120 | Input: |
|
120 | Input: | |
121 | filename - filename to delete in remote folder |
|
121 | filename - filename to delete in remote folder | |
122 |
|
122 | |||
123 | Return: |
|
123 | Return: | |
124 | 1 in error case else 0 |
|
124 | 1 in error case else 0 | |
125 | """ |
|
125 | """ | |
126 |
|
126 | |||
127 | try: |
|
127 | try: | |
128 | self.ftp.delete(filename) |
|
128 | self.ftp.delete(filename) | |
129 | except: |
|
129 | except: | |
130 | print 'Error deleting remote file:%s'%filename |
|
130 | print 'Error deleting remote file:%s'%filename | |
131 | return 1 |
|
131 | return 1 | |
132 |
|
132 | |||
133 | return 0 |
|
133 | return 0 | |
134 |
|
134 | |||
135 | def download(self,filename,localfolder): |
|
135 | def download(self,filename,localfolder): | |
136 | """ |
|
136 | """ | |
137 | download is used to downloading file from remote folder into local folder |
|
137 | download is used to downloading file from remote folder into local folder | |
138 |
|
138 | |||
139 | Inputs: |
|
139 | Inputs: | |
140 | filename - filename to donwload |
|
140 | filename - filename to donwload | |
141 |
|
141 | |||
142 | localfolder - directory local to store filename |
|
142 | localfolder - directory local to store filename | |
143 |
|
143 | |||
144 | Returns: |
|
144 | Returns: | |
145 | self.status - 1 in error case else 0 |
|
145 | self.status - 1 in error case else 0 | |
146 | """ |
|
146 | """ | |
147 |
|
147 | |||
148 | self.status = 0 |
|
148 | self.status = 0 | |
149 |
|
149 | |||
150 |
|
150 | |||
151 | if not(filename in self.fileList): |
|
151 | if not(filename in self.fileList): | |
152 | print 'filename:%s not exists'%filename |
|
152 | print 'filename:%s not exists'%filename | |
153 | self.status = 1 |
|
153 | self.status = 1 | |
154 | return self.status |
|
154 | return self.status | |
155 |
|
155 | |||
156 | newfilename = os.path.join(localfolder,filename) |
|
156 | newfilename = os.path.join(localfolder,filename) | |
157 |
|
157 | |||
158 | self.file = open(newfilename, 'wb') |
|
158 | self.file = open(newfilename, 'wb') | |
159 |
|
159 | |||
160 | try: |
|
160 | try: | |
161 | print 'Download: ' + filename |
|
161 | print 'Download: ' + filename | |
162 | self.ftp.retrbinary('RETR ' + filename, self.__handleDownload) |
|
162 | self.ftp.retrbinary('RETR ' + filename, self.__handleDownload) | |
163 | print 'Download Complete' |
|
163 | print 'Download Complete' | |
164 | except ftplib.all_errors: |
|
164 | except ftplib.all_errors: | |
165 | print 'Error Downloading ' + filename |
|
165 | print 'Error Downloading ' + filename | |
166 | self.status = 1 |
|
166 | self.status = 1 | |
167 | return self.status |
|
167 | return self.status | |
168 |
|
168 | |||
169 | self.file.close() |
|
169 | self.file.close() | |
170 |
|
170 | |||
171 | return self.status |
|
171 | return self.status | |
172 |
|
172 | |||
173 |
|
173 | |||
174 | def __handleDownload(self,block): |
|
174 | def __handleDownload(self,block): | |
175 | """ |
|
175 | """ | |
176 | __handleDownload is used to handle writing file |
|
176 | __handleDownload is used to handle writing file | |
177 | """ |
|
177 | """ | |
178 | self.file.write(block) |
|
178 | self.file.write(block) | |
179 |
|
179 | |||
180 |
|
180 | |||
181 | def upload(self,filename,remotefolder=None): |
|
181 | def upload(self,filename,remotefolder=None): | |
182 | """ |
|
182 | """ | |
183 | upload is used to uploading local file to remote directory |
|
183 | upload is used to uploading local file to remote directory | |
184 |
|
184 | |||
185 | Inputs: |
|
185 | Inputs: | |
186 | filename - full path name of local file to store in remote directory |
|
186 | filename - full path name of local file to store in remote directory | |
187 |
|
187 | |||
188 | remotefolder - remote directory |
|
188 | remotefolder - remote directory | |
189 |
|
189 | |||
190 | Returns: |
|
190 | Returns: | |
191 | self.status - 1 in error case else 0 |
|
191 | self.status - 1 in error case else 0 | |
192 | """ |
|
192 | """ | |
193 |
|
193 | |||
194 | if remotefolder == None: |
|
194 | if remotefolder == None: | |
195 | remotefolder = self.remotefolder |
|
195 | remotefolder = self.remotefolder | |
196 |
|
196 | |||
197 | self.status = 0 |
|
197 | self.status = 0 | |
198 |
|
198 | |||
199 | try: |
|
199 | try: | |
200 | self.ftp.cwd(remotefolder) |
|
200 | self.ftp.cwd(remotefolder) | |
201 |
|
201 | |||
202 | self.file = open(filename, 'rb') |
|
202 | self.file = open(filename, 'rb') | |
203 |
|
203 | |||
204 | (head, tail) = os.path.split(filename) |
|
204 | (head, tail) = os.path.split(filename) | |
205 |
|
205 | |||
206 | command = "STOR " + tail |
|
206 | command = "STOR " + tail | |
207 |
|
207 | |||
208 | print 'Uploading: ' + tail |
|
208 | print 'Uploading: ' + tail | |
209 | self.ftp.storbinary(command, self.file) |
|
209 | self.ftp.storbinary(command, self.file) | |
210 | print 'Upload Completed' |
|
210 | print 'Upload Completed' | |
211 |
|
211 | |||
212 | except ftplib.all_errors: |
|
212 | except ftplib.all_errors: | |
213 | print 'Error Uploading ' + tail |
|
213 | print 'Error Uploading ' + tail | |
214 | self.status = 1 |
|
214 | self.status = 1 | |
215 | return self.status |
|
215 | return self.status | |
216 |
|
216 | |||
217 | self.file.close() |
|
217 | self.file.close() | |
218 |
|
218 | |||
219 | #back to initial directory in __init__() |
|
219 | #back to initial directory in __init__() | |
220 | self.ftp.cwd(self.remotefolder) |
|
220 | self.ftp.cwd(self.remotefolder) | |
221 |
|
221 | |||
222 | return self.status |
|
222 | return self.status | |
223 |
|
223 | |||
224 |
|
224 | |||
225 | def dir(self,remotefolder): |
|
225 | def dir(self,remotefolder): | |
226 | """ |
|
226 | """ | |
227 | dir is used to change working directory of remote host and get folder and file list |
|
227 | dir is used to change working directory of remote host and get folder and file list | |
228 |
|
228 | |||
229 | Input: |
|
229 | Input: | |
230 | remotefolder - current working directory |
|
230 | remotefolder - current working directory | |
231 |
|
231 | |||
232 | Affects: |
|
232 | Affects: | |
233 | self.fileList - file list of working directory |
|
233 | self.fileList - file list of working directory | |
234 |
|
234 | |||
235 | Return: |
|
235 | Return: | |
236 | infoList - list with filenames and size of file in bytes |
|
236 | infoList - list with filenames and size of file in bytes | |
237 |
|
237 | |||
238 | self.folderList - folder list |
|
238 | self.folderList - folder list | |
239 | """ |
|
239 | """ | |
240 |
|
240 | |||
241 | self.remotefolder = remotefolder |
|
241 | self.remotefolder = remotefolder | |
242 | print 'Change to ' + self.remotefolder |
|
242 | print 'Change to ' + self.remotefolder | |
243 | try: |
|
243 | try: | |
244 | self.ftp.cwd(remotefolder) |
|
244 | self.ftp.cwd(remotefolder) | |
245 | except ftplib.all_errors: |
|
245 | except ftplib.all_errors: | |
246 | print 'Error Change to ' + self.remotefolder |
|
246 | print 'Error Change to ' + self.remotefolder | |
247 | infoList = None |
|
247 | infoList = None | |
248 | self.folderList = None |
|
248 | self.folderList = None | |
249 | return infoList,self.folderList |
|
249 | return infoList,self.folderList | |
250 |
|
250 | |||
251 | self.dirList = [] |
|
251 | self.dirList = [] | |
252 |
|
252 | |||
253 | try: |
|
253 | try: | |
254 | self.dirList = self.ftp.nlst() |
|
254 | self.dirList = self.ftp.nlst() | |
255 |
|
255 | |||
256 | except ftplib.error_perm, resp: |
|
256 | except ftplib.error_perm, resp: | |
257 | if str(resp) == "550 No files found": |
|
257 | if str(resp) == "550 No files found": | |
258 | print "no files in this directory" |
|
258 | print "no files in this directory" | |
259 | infoList = None |
|
259 | infoList = None | |
260 | self.folderList = None |
|
260 | self.folderList = None | |
261 | return infoList,self.folderList |
|
261 | return infoList,self.folderList | |
262 | except ftplib.all_errors: |
|
262 | except ftplib.all_errors: | |
263 | print 'Error Displaying Dir-Files' |
|
263 | print 'Error Displaying Dir-Files' | |
264 | infoList = None |
|
264 | infoList = None | |
265 | self.folderList = None |
|
265 | self.folderList = None | |
266 | return infoList,self.folderList |
|
266 | return infoList,self.folderList | |
267 |
|
267 | |||
268 | infoList = [] |
|
268 | infoList = [] | |
269 | self.fileList = [] |
|
269 | self.fileList = [] | |
270 | self.folderList = [] |
|
270 | self.folderList = [] | |
271 | for f in self.dirList: |
|
271 | for f in self.dirList: | |
272 | name,ext = os.path.splitext(f) |
|
272 | name,ext = os.path.splitext(f) | |
273 | if ext != '': |
|
273 | if ext != '': | |
274 | self.fileList.append(f) |
|
274 | self.fileList.append(f) | |
275 | value = (f,self.ftp.size(f)) |
|
275 | value = (f,self.ftp.size(f)) | |
276 | infoList.append(value) |
|
276 | infoList.append(value) | |
277 |
|
277 | |||
278 | if ext == '': |
|
278 | if ext == '': | |
279 | self.folderList.append(f) |
|
279 | self.folderList.append(f) | |
280 |
|
280 | |||
281 | return infoList,self.folderList |
|
281 | return infoList,self.folderList | |
282 |
|
282 | |||
283 |
|
283 | |||
284 | def close(self): |
|
284 | def close(self): | |
285 | """ |
|
285 | """ | |
286 | close is used to close and end FTP connection |
|
286 | close is used to close and end FTP connection | |
287 |
|
287 | |||
288 | Inputs: None |
|
288 | Inputs: None | |
289 |
|
289 | |||
290 | Return: void |
|
290 | Return: void | |
291 |
|
291 | |||
292 | """ |
|
292 | """ | |
293 | self.ftp.close() No newline at end of file |
|
293 | self.ftp.close() |
@@ -1,521 +1,521 | |||||
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 | from customftp import * |
|
5 | from customftp import * | |
6 |
|
6 | |||
7 | class Figure: |
|
7 | class Figure: | |
8 |
|
8 | |||
9 | __driver = mpldriver |
|
9 | __driver = mpldriver | |
10 | fig = None |
|
10 | fig = None | |
11 |
|
11 | |||
12 | id = None |
|
12 | id = None | |
13 | wintitle = None |
|
13 | wintitle = None | |
14 | width = None |
|
14 | width = None | |
15 | height = None |
|
15 | height = None | |
16 | nplots = None |
|
16 | nplots = None | |
17 | timerange = None |
|
17 | timerange = None | |
18 |
|
18 | |||
19 | axesObjList = [] |
|
19 | axesObjList = [] | |
20 |
|
20 | |||
21 | WIDTH = None |
|
21 | WIDTH = None | |
22 | HEIGHT = None |
|
22 | HEIGHT = None | |
23 | PREFIX = 'fig' |
|
23 | PREFIX = 'fig' | |
24 |
|
24 | |||
25 | def __init__(self): |
|
25 | def __init__(self): | |
26 |
|
26 | |||
27 | raise ValueError, "This method is not implemented" |
|
27 | raise ValueError, "This method is not implemented" | |
28 |
|
28 | |||
29 | def __del__(self): |
|
29 | def __del__(self): | |
30 |
|
30 | |||
31 | self.__driver.closeFigure() |
|
31 | self.__driver.closeFigure() | |
32 |
|
32 | |||
33 | def getFilename(self, name, ext='.png'): |
|
33 | def getFilename(self, name, ext='.png'): | |
34 |
|
34 | |||
35 | path = '%s%03d' %(self.PREFIX, self.id) |
|
35 | path = '%s%03d' %(self.PREFIX, self.id) | |
36 | filename = '%s_%s%s' %(self.PREFIX, name, ext) |
|
36 | filename = '%s_%s%s' %(self.PREFIX, name, ext) | |
37 |
|
37 | filename = '%s%s' %(name, ext) | ||
38 | return os.path.join(path, filename) |
|
38 | return os.path.join(path, filename) | |
39 |
|
39 | |||
40 | def getAxesObjList(self): |
|
40 | def getAxesObjList(self): | |
41 |
|
41 | |||
42 | return self.axesObjList |
|
42 | return self.axesObjList | |
43 |
|
43 | |||
44 | def getSubplots(self): |
|
44 | def getSubplots(self): | |
45 |
|
45 | |||
46 | raise ValueError, "Abstract method: This method should be defined" |
|
46 | raise ValueError, "Abstract method: This method should be defined" | |
47 |
|
47 | |||
48 | def getScreenDim(self, widthplot, heightplot): |
|
48 | def getScreenDim(self, widthplot, heightplot): | |
49 |
|
49 | |||
50 | nrow, ncol = self.getSubplots() |
|
50 | nrow, ncol = self.getSubplots() | |
51 |
|
51 | |||
52 | widthscreen = widthplot*ncol |
|
52 | widthscreen = widthplot*ncol | |
53 | heightscreen = heightplot*nrow |
|
53 | heightscreen = heightplot*nrow | |
54 |
|
54 | |||
55 | return widthscreen, heightscreen |
|
55 | return widthscreen, heightscreen | |
56 |
|
56 | |||
57 | def getTimeLim(self, x, xmin, xmax): |
|
57 | def getTimeLim(self, x, xmin, xmax): | |
58 |
|
58 | |||
59 | thisdatetime = datetime.datetime.utcfromtimestamp(numpy.min(x)) |
|
59 | thisdatetime = datetime.datetime.utcfromtimestamp(numpy.min(x)) | |
60 | thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0)) |
|
60 | thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0)) | |
61 |
|
61 | |||
62 | #################################################### |
|
62 | #################################################### | |
63 | #If the x is out of xrange |
|
63 | #If the x is out of xrange | |
64 | if xmax < (thisdatetime - thisdate).seconds/(60*60.): |
|
64 | if xmax < (thisdatetime - thisdate).seconds/(60*60.): | |
65 | xmin = None |
|
65 | xmin = None | |
66 | xmax = None |
|
66 | xmax = None | |
67 |
|
67 | |||
68 | if xmin == None: |
|
68 | if xmin == None: | |
69 | td = thisdatetime - thisdate |
|
69 | td = thisdatetime - thisdate | |
70 | xmin = td.seconds/(60*60.) |
|
70 | xmin = td.seconds/(60*60.) | |
71 |
|
71 | |||
72 | if xmax == None: |
|
72 | if xmax == None: | |
73 | xmax = xmin + self.timerange/(60*60.) |
|
73 | xmax = xmin + self.timerange/(60*60.) | |
74 |
|
74 | |||
75 | mindt = thisdate + datetime.timedelta(hours=xmin) - datetime.timedelta(seconds=time.timezone) |
|
75 | mindt = thisdate + datetime.timedelta(hours=xmin) - datetime.timedelta(seconds=time.timezone) | |
76 | tmin = time.mktime(mindt.timetuple()) |
|
76 | tmin = time.mktime(mindt.timetuple()) | |
77 |
|
77 | |||
78 | maxdt = thisdate + datetime.timedelta(hours=xmax) - datetime.timedelta(seconds=time.timezone) |
|
78 | maxdt = thisdate + datetime.timedelta(hours=xmax) - datetime.timedelta(seconds=time.timezone) | |
79 | tmax = time.mktime(maxdt.timetuple()) |
|
79 | tmax = time.mktime(maxdt.timetuple()) | |
80 |
|
80 | |||
81 | self.timerange = tmax - tmin |
|
81 | self.timerange = tmax - tmin | |
82 |
|
82 | |||
83 | return tmin, tmax |
|
83 | return tmin, tmax | |
84 |
|
84 | |||
85 | def init(self, id, nplots, wintitle): |
|
85 | def init(self, id, nplots, wintitle): | |
86 |
|
86 | |||
87 | raise ValueError, "This method has been replaced with createFigure" |
|
87 | raise ValueError, "This method has been replaced with createFigure" | |
88 |
|
88 | |||
89 | def createFigure(self, id, wintitle, widthplot=None, heightplot=None, show=True): |
|
89 | def createFigure(self, id, wintitle, widthplot=None, heightplot=None, show=True): | |
90 |
|
90 | |||
91 | """ |
|
91 | """ | |
92 | Crea la figura de acuerdo al driver y parametros seleccionados seleccionados. |
|
92 | Crea la figura de acuerdo al driver y parametros seleccionados seleccionados. | |
93 | Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH |
|
93 | Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH | |
94 | y self.HEIGHT y el numero de subplots (nrow, ncol) |
|
94 | y self.HEIGHT y el numero de subplots (nrow, ncol) | |
95 |
|
95 | |||
96 | Input: |
|
96 | Input: | |
97 | id : Los parametros necesarios son |
|
97 | id : Los parametros necesarios son | |
98 | wintitle : |
|
98 | wintitle : | |
99 |
|
99 | |||
100 | """ |
|
100 | """ | |
101 |
|
101 | |||
102 | if widthplot == None: |
|
102 | if widthplot == None: | |
103 | widthplot = self.WIDTH |
|
103 | widthplot = self.WIDTH | |
104 |
|
104 | |||
105 | if heightplot == None: |
|
105 | if heightplot == None: | |
106 | heightplot = self.HEIGHT |
|
106 | heightplot = self.HEIGHT | |
107 |
|
107 | |||
108 | self.id = id |
|
108 | self.id = id | |
109 |
|
109 | |||
110 | self.wintitle = wintitle |
|
110 | self.wintitle = wintitle | |
111 |
|
111 | |||
112 | self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot) |
|
112 | self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot) | |
113 |
|
113 | |||
114 | self.fig = self.__driver.createFigure(id=self.id, |
|
114 | self.fig = self.__driver.createFigure(id=self.id, | |
115 | wintitle=self.wintitle, |
|
115 | wintitle=self.wintitle, | |
116 | width=self.widthscreen, |
|
116 | width=self.widthscreen, | |
117 | height=self.heightscreen, |
|
117 | height=self.heightscreen, | |
118 | show=show) |
|
118 | show=show) | |
119 |
|
119 | |||
120 | self.axesObjList = [] |
|
120 | self.axesObjList = [] | |
121 |
|
121 | |||
122 |
|
122 | |||
123 | def setDriver(self, driver=mpldriver): |
|
123 | def setDriver(self, driver=mpldriver): | |
124 |
|
124 | |||
125 | self.__driver = driver |
|
125 | self.__driver = driver | |
126 |
|
126 | |||
127 | def setTitle(self, title): |
|
127 | def setTitle(self, title): | |
128 |
|
128 | |||
129 | self.__driver.setTitle(self.fig, title) |
|
129 | self.__driver.setTitle(self.fig, title) | |
130 |
|
130 | |||
131 | def setWinTitle(self, title): |
|
131 | def setWinTitle(self, title): | |
132 |
|
132 | |||
133 | self.__driver.setWinTitle(self.fig, title=title) |
|
133 | self.__driver.setWinTitle(self.fig, title=title) | |
134 |
|
134 | |||
135 | def setTextFromAxes(self, text): |
|
135 | def setTextFromAxes(self, text): | |
136 |
|
136 | |||
137 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes" |
|
137 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes" | |
138 |
|
138 | |||
139 | def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan): |
|
139 | def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan): | |
140 |
|
140 | |||
141 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes" |
|
141 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes" | |
142 |
|
142 | |||
143 | def addAxes(self, *args): |
|
143 | def addAxes(self, *args): | |
144 | """ |
|
144 | """ | |
145 |
|
145 | |||
146 | Input: |
|
146 | Input: | |
147 | *args : Los parametros necesarios son |
|
147 | *args : Los parametros necesarios son | |
148 | nrow, ncol, xpos, ypos, colspan, rowspan |
|
148 | nrow, ncol, xpos, ypos, colspan, rowspan | |
149 | """ |
|
149 | """ | |
150 |
|
150 | |||
151 | axesObj = Axes(self.fig, *args) |
|
151 | axesObj = Axes(self.fig, *args) | |
152 | self.axesObjList.append(axesObj) |
|
152 | self.axesObjList.append(axesObj) | |
153 |
|
153 | |||
154 | def saveFigure(self, figpath, figfile, *args): |
|
154 | def saveFigure(self, figpath, figfile, *args): | |
155 |
|
155 | |||
156 | filename = os.path.join(figpath, figfile) |
|
156 | filename = os.path.join(figpath, figfile) | |
157 |
|
157 | |||
158 | fullpath = os.path.split(filename)[0] |
|
158 | fullpath = os.path.split(filename)[0] | |
159 |
|
159 | |||
160 | if not os.path.exists(fullpath): |
|
160 | if not os.path.exists(fullpath): | |
161 | subpath = os.path.split(fullpath)[0] |
|
161 | subpath = os.path.split(fullpath)[0] | |
162 |
|
162 | |||
163 | if not os.path.exists(subpath): |
|
163 | if not os.path.exists(subpath): | |
164 | os.mkdir(subpath) |
|
164 | os.mkdir(subpath) | |
165 |
|
165 | |||
166 | os.mkdir(fullpath) |
|
166 | os.mkdir(fullpath) | |
167 |
|
167 | |||
168 | self.__driver.saveFigure(self.fig, filename, *args) |
|
168 | self.__driver.saveFigure(self.fig, filename, *args) | |
169 |
|
169 | |||
170 | def sendByFTP(self, figfilename): |
|
170 | def sendByFTP(self, figfilename): | |
171 | ftpObj = Ftp() |
|
171 | ftpObj = Ftp() | |
172 | ftpObj.upload(figfilename) |
|
172 | ftpObj.upload(figfilename) | |
173 | ftpObj.close() |
|
173 | ftpObj.close() | |
174 |
|
174 | |||
175 | def draw(self): |
|
175 | def draw(self): | |
176 |
|
176 | |||
177 | self.__driver.draw(self.fig) |
|
177 | self.__driver.draw(self.fig) | |
178 |
|
178 | |||
179 | def run(self): |
|
179 | def run(self): | |
180 |
|
180 | |||
181 | raise ValueError, "This method is not implemented" |
|
181 | raise ValueError, "This method is not implemented" | |
182 |
|
182 | |||
183 | axesList = property(getAxesObjList) |
|
183 | axesList = property(getAxesObjList) | |
184 |
|
184 | |||
185 |
|
185 | |||
186 | class Axes: |
|
186 | class Axes: | |
187 |
|
187 | |||
188 | __driver = mpldriver |
|
188 | __driver = mpldriver | |
189 | fig = None |
|
189 | fig = None | |
190 | ax = None |
|
190 | ax = None | |
191 | plot = None |
|
191 | plot = None | |
192 | __missing = 1E30 |
|
192 | __missing = 1E30 | |
193 | __firsttime = None |
|
193 | __firsttime = None | |
194 |
|
194 | |||
195 | __showprofile = False |
|
195 | __showprofile = False | |
196 |
|
196 | |||
197 | xmin = None |
|
197 | xmin = None | |
198 | xmax = None |
|
198 | xmax = None | |
199 | ymin = None |
|
199 | ymin = None | |
200 | ymax = None |
|
200 | ymax = None | |
201 | zmin = None |
|
201 | zmin = None | |
202 | zmax = None |
|
202 | zmax = None | |
203 |
|
203 | |||
204 | x_buffer = None |
|
204 | x_buffer = None | |
205 | z_buffer = None |
|
205 | z_buffer = None | |
206 |
|
206 | |||
207 | decimationx = None |
|
207 | decimationx = None | |
208 | decimationy = None |
|
208 | decimationy = None | |
209 |
|
209 | |||
210 | __MAXNUMX = 1000 |
|
210 | __MAXNUMX = 1000 | |
211 | __MAXNUMY = 500 |
|
211 | __MAXNUMY = 500 | |
212 |
|
212 | |||
213 | def __init__(self, *args): |
|
213 | def __init__(self, *args): | |
214 |
|
214 | |||
215 | """ |
|
215 | """ | |
216 |
|
216 | |||
217 | Input: |
|
217 | Input: | |
218 | *args : Los parametros necesarios son |
|
218 | *args : Los parametros necesarios son | |
219 | fig, nrow, ncol, xpos, ypos, colspan, rowspan |
|
219 | fig, nrow, ncol, xpos, ypos, colspan, rowspan | |
220 | """ |
|
220 | """ | |
221 |
|
221 | |||
222 | ax = self.__driver.createAxes(*args) |
|
222 | ax = self.__driver.createAxes(*args) | |
223 | self.fig = args[0] |
|
223 | self.fig = args[0] | |
224 | self.ax = ax |
|
224 | self.ax = ax | |
225 | self.plot = None |
|
225 | self.plot = None | |
226 |
|
226 | |||
227 | self.__firsttime = True |
|
227 | self.__firsttime = True | |
228 | self.idlineList = [] |
|
228 | self.idlineList = [] | |
229 |
|
229 | |||
230 | self.x_buffer = numpy.array([]) |
|
230 | self.x_buffer = numpy.array([]) | |
231 | self.z_buffer = numpy.array([]) |
|
231 | self.z_buffer = numpy.array([]) | |
232 |
|
232 | |||
233 | def setText(self, text): |
|
233 | def setText(self, text): | |
234 |
|
234 | |||
235 | self.__driver.setAxesText(self.ax, text) |
|
235 | self.__driver.setAxesText(self.ax, text) | |
236 |
|
236 | |||
237 | def setXAxisAsTime(self): |
|
237 | def setXAxisAsTime(self): | |
238 | pass |
|
238 | pass | |
239 |
|
239 | |||
240 | def pline(self, x, y, |
|
240 | def pline(self, x, y, | |
241 | xmin=None, xmax=None, |
|
241 | xmin=None, xmax=None, | |
242 | ymin=None, ymax=None, |
|
242 | ymin=None, ymax=None, | |
243 | xlabel='', ylabel='', |
|
243 | xlabel='', ylabel='', | |
244 | title='', |
|
244 | title='', | |
245 | **kwargs): |
|
245 | **kwargs): | |
246 |
|
246 | |||
247 | """ |
|
247 | """ | |
248 |
|
248 | |||
249 | Input: |
|
249 | Input: | |
250 | x : |
|
250 | x : | |
251 | y : |
|
251 | y : | |
252 | xmin : |
|
252 | xmin : | |
253 | xmax : |
|
253 | xmax : | |
254 | ymin : |
|
254 | ymin : | |
255 | ymax : |
|
255 | ymax : | |
256 | xlabel : |
|
256 | xlabel : | |
257 | ylabel : |
|
257 | ylabel : | |
258 | title : |
|
258 | title : | |
259 | **kwargs : Los parametros aceptados son |
|
259 | **kwargs : Los parametros aceptados son | |
260 |
|
260 | |||
261 | ticksize |
|
261 | ticksize | |
262 | ytick_visible |
|
262 | ytick_visible | |
263 | """ |
|
263 | """ | |
264 |
|
264 | |||
265 | if self.__firsttime: |
|
265 | if self.__firsttime: | |
266 |
|
266 | |||
267 | if xmin == None: xmin = numpy.nanmin(x) |
|
267 | if xmin == None: xmin = numpy.nanmin(x) | |
268 | if xmax == None: xmax = numpy.nanmax(x) |
|
268 | if xmax == None: xmax = numpy.nanmax(x) | |
269 | if ymin == None: ymin = numpy.nanmin(y) |
|
269 | if ymin == None: ymin = numpy.nanmin(y) | |
270 | if ymax == None: ymax = numpy.nanmax(y) |
|
270 | if ymax == None: ymax = numpy.nanmax(y) | |
271 |
|
271 | |||
272 | self.plot = self.__driver.createPline(self.ax, x, y, |
|
272 | self.plot = self.__driver.createPline(self.ax, x, y, | |
273 | xmin, xmax, |
|
273 | xmin, xmax, | |
274 | ymin, ymax, |
|
274 | ymin, ymax, | |
275 | xlabel=xlabel, |
|
275 | xlabel=xlabel, | |
276 | ylabel=ylabel, |
|
276 | ylabel=ylabel, | |
277 | title=title, |
|
277 | title=title, | |
278 | **kwargs) |
|
278 | **kwargs) | |
279 |
|
279 | |||
280 | self.idlineList.append(0) |
|
280 | self.idlineList.append(0) | |
281 | self.__firsttime = False |
|
281 | self.__firsttime = False | |
282 | return |
|
282 | return | |
283 |
|
283 | |||
284 | self.__driver.pline(self.plot, x, y, xlabel=xlabel, |
|
284 | self.__driver.pline(self.plot, x, y, xlabel=xlabel, | |
285 | ylabel=ylabel, |
|
285 | ylabel=ylabel, | |
286 | title=title) |
|
286 | title=title) | |
287 |
|
287 | |||
288 | def addpline(self, x, y, idline, **kwargs): |
|
288 | def addpline(self, x, y, idline, **kwargs): | |
289 | lines = self.ax.lines |
|
289 | lines = self.ax.lines | |
290 |
|
290 | |||
291 | if idline in self.idlineList: |
|
291 | if idline in self.idlineList: | |
292 | self.__driver.set_linedata(self.ax, x, y, idline) |
|
292 | self.__driver.set_linedata(self.ax, x, y, idline) | |
293 |
|
293 | |||
294 | if idline not in(self.idlineList): |
|
294 | if idline not in(self.idlineList): | |
295 | self.__driver.addpline(self.ax, x, y, **kwargs) |
|
295 | self.__driver.addpline(self.ax, x, y, **kwargs) | |
296 | self.idlineList.append(idline) |
|
296 | self.idlineList.append(idline) | |
297 |
|
297 | |||
298 | return |
|
298 | return | |
299 |
|
299 | |||
300 | def pmultiline(self, x, y, |
|
300 | def pmultiline(self, x, y, | |
301 | xmin=None, xmax=None, |
|
301 | xmin=None, xmax=None, | |
302 | ymin=None, ymax=None, |
|
302 | ymin=None, ymax=None, | |
303 | xlabel='', ylabel='', |
|
303 | xlabel='', ylabel='', | |
304 | title='', |
|
304 | title='', | |
305 | **kwargs): |
|
305 | **kwargs): | |
306 |
|
306 | |||
307 | if self.__firsttime: |
|
307 | if self.__firsttime: | |
308 |
|
308 | |||
309 | if xmin == None: xmin = numpy.nanmin(x) |
|
309 | if xmin == None: xmin = numpy.nanmin(x) | |
310 | if xmax == None: xmax = numpy.nanmax(x) |
|
310 | if xmax == None: xmax = numpy.nanmax(x) | |
311 | if ymin == None: ymin = numpy.nanmin(y) |
|
311 | if ymin == None: ymin = numpy.nanmin(y) | |
312 | if ymax == None: ymax = numpy.nanmax(y) |
|
312 | if ymax == None: ymax = numpy.nanmax(y) | |
313 |
|
313 | |||
314 | self.plot = self.__driver.createPmultiline(self.ax, x, y, |
|
314 | self.plot = self.__driver.createPmultiline(self.ax, x, y, | |
315 | xmin, xmax, |
|
315 | xmin, xmax, | |
316 | ymin, ymax, |
|
316 | ymin, ymax, | |
317 | xlabel=xlabel, |
|
317 | xlabel=xlabel, | |
318 | ylabel=ylabel, |
|
318 | ylabel=ylabel, | |
319 | title=title, |
|
319 | title=title, | |
320 | **kwargs) |
|
320 | **kwargs) | |
321 | self.__firsttime = False |
|
321 | self.__firsttime = False | |
322 | return |
|
322 | return | |
323 |
|
323 | |||
324 | self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel, |
|
324 | self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel, | |
325 | ylabel=ylabel, |
|
325 | ylabel=ylabel, | |
326 | title=title) |
|
326 | title=title) | |
327 |
|
327 | |||
328 | def pmultilineyaxis(self, x, y, |
|
328 | def pmultilineyaxis(self, x, y, | |
329 | xmin=None, xmax=None, |
|
329 | xmin=None, xmax=None, | |
330 | ymin=None, ymax=None, |
|
330 | ymin=None, ymax=None, | |
331 | xlabel='', ylabel='', |
|
331 | xlabel='', ylabel='', | |
332 | title='', |
|
332 | title='', | |
333 | **kwargs): |
|
333 | **kwargs): | |
334 |
|
334 | |||
335 | if self.__firsttime: |
|
335 | if self.__firsttime: | |
336 |
|
336 | |||
337 | if xmin == None: xmin = numpy.nanmin(x) |
|
337 | if xmin == None: xmin = numpy.nanmin(x) | |
338 | if xmax == None: xmax = numpy.nanmax(x) |
|
338 | if xmax == None: xmax = numpy.nanmax(x) | |
339 | if ymin == None: ymin = numpy.nanmin(y) |
|
339 | if ymin == None: ymin = numpy.nanmin(y) | |
340 | if ymax == None: ymax = numpy.nanmax(y) |
|
340 | if ymax == None: ymax = numpy.nanmax(y) | |
341 |
|
341 | |||
342 | self.plot = self.__driver.createPmultilineYAxis(self.ax, x, y, |
|
342 | self.plot = self.__driver.createPmultilineYAxis(self.ax, x, y, | |
343 | xmin, xmax, |
|
343 | xmin, xmax, | |
344 | ymin, ymax, |
|
344 | ymin, ymax, | |
345 | xlabel=xlabel, |
|
345 | xlabel=xlabel, | |
346 | ylabel=ylabel, |
|
346 | ylabel=ylabel, | |
347 | title=title, |
|
347 | title=title, | |
348 | **kwargs) |
|
348 | **kwargs) | |
349 | if self.xmin == None: self.xmin = xmin |
|
349 | if self.xmin == None: self.xmin = xmin | |
350 | if self.xmax == None: self.xmax = xmax |
|
350 | if self.xmax == None: self.xmax = xmax | |
351 | if self.ymin == None: self.ymin = ymin |
|
351 | if self.ymin == None: self.ymin = ymin | |
352 | if self.ymax == None: self.ymax = ymax |
|
352 | if self.ymax == None: self.ymax = ymax | |
353 |
|
353 | |||
354 | self.__firsttime = False |
|
354 | self.__firsttime = False | |
355 | return |
|
355 | return | |
356 |
|
356 | |||
357 | self.__driver.pmultilineyaxis(self.plot, x, y, xlabel=xlabel, |
|
357 | self.__driver.pmultilineyaxis(self.plot, x, y, xlabel=xlabel, | |
358 | ylabel=ylabel, |
|
358 | ylabel=ylabel, | |
359 | title=title) |
|
359 | title=title) | |
360 |
|
360 | |||
361 | def pcolor(self, x, y, z, |
|
361 | def pcolor(self, x, y, z, | |
362 | xmin=None, xmax=None, |
|
362 | xmin=None, xmax=None, | |
363 | ymin=None, ymax=None, |
|
363 | ymin=None, ymax=None, | |
364 | zmin=None, zmax=None, |
|
364 | zmin=None, zmax=None, | |
365 | xlabel='', ylabel='', |
|
365 | xlabel='', ylabel='', | |
366 | title='', rti = False, colormap='jet', |
|
366 | title='', rti = False, colormap='jet', | |
367 | **kwargs): |
|
367 | **kwargs): | |
368 |
|
368 | |||
369 | """ |
|
369 | """ | |
370 | Input: |
|
370 | Input: | |
371 | x : |
|
371 | x : | |
372 | y : |
|
372 | y : | |
373 | x : |
|
373 | x : | |
374 | xmin : |
|
374 | xmin : | |
375 | xmax : |
|
375 | xmax : | |
376 | ymin : |
|
376 | ymin : | |
377 | ymax : |
|
377 | ymax : | |
378 | zmin : |
|
378 | zmin : | |
379 | zmax : |
|
379 | zmax : | |
380 | xlabel : |
|
380 | xlabel : | |
381 | ylabel : |
|
381 | ylabel : | |
382 | title : |
|
382 | title : | |
383 | **kwargs : Los parametros aceptados son |
|
383 | **kwargs : Los parametros aceptados son | |
384 | ticksize=9, |
|
384 | ticksize=9, | |
385 | cblabel='' |
|
385 | cblabel='' | |
386 | rti = True or False |
|
386 | rti = True or False | |
387 | """ |
|
387 | """ | |
388 |
|
388 | |||
389 | if self.__firsttime: |
|
389 | if self.__firsttime: | |
390 |
|
390 | |||
391 | if xmin == None: xmin = numpy.nanmin(x) |
|
391 | if xmin == None: xmin = numpy.nanmin(x) | |
392 | if xmax == None: xmax = numpy.nanmax(x) |
|
392 | if xmax == None: xmax = numpy.nanmax(x) | |
393 | if ymin == None: ymin = numpy.nanmin(y) |
|
393 | if ymin == None: ymin = numpy.nanmin(y) | |
394 | if ymax == None: ymax = numpy.nanmax(y) |
|
394 | if ymax == None: ymax = numpy.nanmax(y) | |
395 | if zmin == None: zmin = numpy.nanmin(z) |
|
395 | if zmin == None: zmin = numpy.nanmin(z) | |
396 | if zmax == None: zmax = numpy.nanmax(z) |
|
396 | if zmax == None: zmax = numpy.nanmax(z) | |
397 |
|
397 | |||
398 |
|
398 | |||
399 | self.plot = self.__driver.createPcolor(self.ax, x, y, z, |
|
399 | self.plot = self.__driver.createPcolor(self.ax, x, y, z, | |
400 | xmin, xmax, |
|
400 | xmin, xmax, | |
401 | ymin, ymax, |
|
401 | ymin, ymax, | |
402 | zmin, zmax, |
|
402 | zmin, zmax, | |
403 | xlabel=xlabel, |
|
403 | xlabel=xlabel, | |
404 | ylabel=ylabel, |
|
404 | ylabel=ylabel, | |
405 | title=title, |
|
405 | title=title, | |
406 | colormap=colormap, |
|
406 | colormap=colormap, | |
407 | **kwargs) |
|
407 | **kwargs) | |
408 |
|
408 | |||
409 | if self.xmin == None: self.xmin = xmin |
|
409 | if self.xmin == None: self.xmin = xmin | |
410 | if self.xmax == None: self.xmax = xmax |
|
410 | if self.xmax == None: self.xmax = xmax | |
411 | if self.ymin == None: self.ymin = ymin |
|
411 | if self.ymin == None: self.ymin = ymin | |
412 | if self.ymax == None: self.ymax = ymax |
|
412 | if self.ymax == None: self.ymax = ymax | |
413 | if self.zmin == None: self.zmin = zmin |
|
413 | if self.zmin == None: self.zmin = zmin | |
414 | if self.zmax == None: self.zmax = zmax |
|
414 | if self.zmax == None: self.zmax = zmax | |
415 |
|
415 | |||
416 | self.__firsttime = False |
|
416 | self.__firsttime = False | |
417 | return |
|
417 | return | |
418 |
|
418 | |||
419 | if rti: |
|
419 | if rti: | |
420 | self.__driver.addpcolor(self.ax, x, y, z, self.zmin, self.zmax, |
|
420 | self.__driver.addpcolor(self.ax, x, y, z, self.zmin, self.zmax, | |
421 | xlabel=xlabel, |
|
421 | xlabel=xlabel, | |
422 | ylabel=ylabel, |
|
422 | ylabel=ylabel, | |
423 | title=title, |
|
423 | title=title, | |
424 | colormap=colormap) |
|
424 | colormap=colormap) | |
425 | return |
|
425 | return | |
426 |
|
426 | |||
427 | self.__driver.pcolor(self.plot, z, |
|
427 | self.__driver.pcolor(self.plot, z, | |
428 | xlabel=xlabel, |
|
428 | xlabel=xlabel, | |
429 | ylabel=ylabel, |
|
429 | ylabel=ylabel, | |
430 | title=title) |
|
430 | title=title) | |
431 |
|
431 | |||
432 | def pcolorbuffer(self, x, y, z, |
|
432 | def pcolorbuffer(self, x, y, z, | |
433 | xmin=None, xmax=None, |
|
433 | xmin=None, xmax=None, | |
434 | ymin=None, ymax=None, |
|
434 | ymin=None, ymax=None, | |
435 | zmin=None, zmax=None, |
|
435 | zmin=None, zmax=None, | |
436 | xlabel='', ylabel='', |
|
436 | xlabel='', ylabel='', | |
437 | title='', rti = True, colormap='jet', |
|
437 | title='', rti = True, colormap='jet', | |
438 | maxNumX = None, maxNumY = None, |
|
438 | maxNumX = None, maxNumY = None, | |
439 | **kwargs): |
|
439 | **kwargs): | |
440 |
|
440 | |||
441 | if maxNumX == None: |
|
441 | if maxNumX == None: | |
442 | maxNumX = self.__MAXNUMX |
|
442 | maxNumX = self.__MAXNUMX | |
443 |
|
443 | |||
444 | if maxNumY == None: |
|
444 | if maxNumY == None: | |
445 | maxNumY = self.__MAXNUMY |
|
445 | maxNumY = self.__MAXNUMY | |
446 |
|
446 | |||
447 | if self.__firsttime: |
|
447 | if self.__firsttime: | |
448 | self.z_buffer = z |
|
448 | self.z_buffer = z | |
449 | self.x_buffer = numpy.hstack((self.x_buffer, x)) |
|
449 | self.x_buffer = numpy.hstack((self.x_buffer, x)) | |
450 |
|
450 | |||
451 | if xmin == None: xmin = numpy.nanmin(x) |
|
451 | if xmin == None: xmin = numpy.nanmin(x) | |
452 | if xmax == None: xmax = numpy.nanmax(x) |
|
452 | if xmax == None: xmax = numpy.nanmax(x) | |
453 | if ymin == None: ymin = numpy.nanmin(y) |
|
453 | if ymin == None: ymin = numpy.nanmin(y) | |
454 | if ymax == None: ymax = numpy.nanmax(y) |
|
454 | if ymax == None: ymax = numpy.nanmax(y) | |
455 | if zmin == None: zmin = numpy.nanmin(z) |
|
455 | if zmin == None: zmin = numpy.nanmin(z) | |
456 | if zmax == None: zmax = numpy.nanmax(z) |
|
456 | if zmax == None: zmax = numpy.nanmax(z) | |
457 |
|
457 | |||
458 |
|
458 | |||
459 | self.plot = self.__driver.createPcolor(self.ax, self.x_buffer, y, z, |
|
459 | self.plot = self.__driver.createPcolor(self.ax, self.x_buffer, y, z, | |
460 | xmin, xmax, |
|
460 | xmin, xmax, | |
461 | ymin, ymax, |
|
461 | ymin, ymax, | |
462 | zmin, zmax, |
|
462 | zmin, zmax, | |
463 | xlabel=xlabel, |
|
463 | xlabel=xlabel, | |
464 | ylabel=ylabel, |
|
464 | ylabel=ylabel, | |
465 | title=title, |
|
465 | title=title, | |
466 | colormap=colormap, |
|
466 | colormap=colormap, | |
467 | **kwargs) |
|
467 | **kwargs) | |
468 |
|
468 | |||
469 | if self.xmin == None: self.xmin = xmin |
|
469 | if self.xmin == None: self.xmin = xmin | |
470 | if self.xmax == None: self.xmax = xmax |
|
470 | if self.xmax == None: self.xmax = xmax | |
471 | if self.ymin == None: self.ymin = ymin |
|
471 | if self.ymin == None: self.ymin = ymin | |
472 | if self.ymax == None: self.ymax = ymax |
|
472 | if self.ymax == None: self.ymax = ymax | |
473 | if self.zmin == None: self.zmin = zmin |
|
473 | if self.zmin == None: self.zmin = zmin | |
474 | if self.zmax == None: self.zmax = zmax |
|
474 | if self.zmax == None: self.zmax = zmax | |
475 |
|
475 | |||
476 | self.__firsttime = False |
|
476 | self.__firsttime = False | |
477 | return |
|
477 | return | |
478 |
|
478 | |||
479 | self.x_buffer = numpy.hstack((self.x_buffer, x[-1])) |
|
479 | self.x_buffer = numpy.hstack((self.x_buffer, x[-1])) | |
480 | self.z_buffer = numpy.hstack((self.z_buffer, z)) |
|
480 | self.z_buffer = numpy.hstack((self.z_buffer, z)) | |
481 |
|
481 | |||
482 | if self.decimationx == None: |
|
482 | if self.decimationx == None: | |
483 | deltax = (self.xmax - self.xmin)/maxNumX |
|
483 | deltax = (self.xmax - self.xmin)/maxNumX | |
484 | deltay = (self.ymax - self.ymin)/maxNumY |
|
484 | deltay = (self.ymax - self.ymin)/maxNumY | |
485 |
|
485 | |||
486 | resolutionx = self.x_buffer[2]-self.x_buffer[0] |
|
486 | resolutionx = self.x_buffer[2]-self.x_buffer[0] | |
487 | resolutiony = y[1]-y[0] |
|
487 | resolutiony = y[1]-y[0] | |
488 |
|
488 | |||
489 | self.decimationx = numpy.ceil(deltax / resolutionx) |
|
489 | self.decimationx = numpy.ceil(deltax / resolutionx) | |
490 | self.decimationy = numpy.ceil(deltay / resolutiony) |
|
490 | self.decimationy = numpy.ceil(deltay / resolutiony) | |
491 |
|
491 | |||
492 | z_buffer = self.z_buffer.reshape(-1,len(y)) |
|
492 | z_buffer = self.z_buffer.reshape(-1,len(y)) | |
493 |
|
493 | |||
494 | x_buffer = self.x_buffer[::self.decimationx] |
|
494 | x_buffer = self.x_buffer[::self.decimationx] | |
495 | y_buffer = y[::self.decimationy] |
|
495 | y_buffer = y[::self.decimationy] | |
496 | z_buffer = z_buffer[::self.decimationx, ::self.decimationy] |
|
496 | z_buffer = z_buffer[::self.decimationx, ::self.decimationy] | |
497 | #=================================================== |
|
497 | #=================================================== | |
498 |
|
498 | |||
499 | x_buffer, y_buffer, z_buffer = self.__fillGaps(x_buffer, y_buffer, z_buffer) |
|
499 | x_buffer, y_buffer, z_buffer = self.__fillGaps(x_buffer, y_buffer, z_buffer) | |
500 |
|
500 | |||
501 | self.__driver.addpcolorbuffer(self.ax, x_buffer, y_buffer, z_buffer, self.zmin, self.zmax, |
|
501 | self.__driver.addpcolorbuffer(self.ax, x_buffer, y_buffer, z_buffer, self.zmin, self.zmax, | |
502 | xlabel=xlabel, |
|
502 | xlabel=xlabel, | |
503 | ylabel=ylabel, |
|
503 | ylabel=ylabel, | |
504 | title=title, |
|
504 | title=title, | |
505 | colormap=colormap) |
|
505 | colormap=colormap) | |
506 | def __fillGaps(self, x_buffer, y_buffer, z_buffer): |
|
506 | def __fillGaps(self, x_buffer, y_buffer, z_buffer): | |
507 |
|
507 | |||
508 | deltas = x_buffer[1:] - x_buffer[0:-1] |
|
508 | deltas = x_buffer[1:] - x_buffer[0:-1] | |
509 | x_median = numpy.median(deltas) |
|
509 | x_median = numpy.median(deltas) | |
510 |
|
510 | |||
511 | index = numpy.where(deltas >= 2*x_median) |
|
511 | index = numpy.where(deltas >= 2*x_median) | |
512 |
|
512 | |||
513 | if len(index[0]) != 0: |
|
513 | if len(index[0]) != 0: | |
514 | z_buffer[index[0],::] = self.__missing |
|
514 | z_buffer[index[0],::] = self.__missing | |
515 | z_buffer = numpy.ma.masked_inside(z_buffer,0.99*self.__missing,1.01*self.__missing) |
|
515 | z_buffer = numpy.ma.masked_inside(z_buffer,0.99*self.__missing,1.01*self.__missing) | |
516 |
|
516 | |||
517 | return x_buffer, y_buffer, z_buffer |
|
517 | return x_buffer, y_buffer, z_buffer | |
518 |
|
518 | |||
519 |
|
519 | |||
520 |
|
520 | |||
521 | No newline at end of file |
|
521 |
@@ -1,383 +1,383 | |||||
1 | import numpy |
|
1 | import numpy | |
2 | import datetime |
|
2 | import datetime | |
3 | import sys |
|
3 | import sys | |
4 | import matplotlib |
|
4 | import matplotlib | |
5 |
|
5 | |||
6 | if 'linux' in sys.platform: |
|
6 | if 'linux' in sys.platform: | |
7 | matplotlib.use("TKAgg") |
|
7 | matplotlib.use("TKAgg") | |
8 |
|
8 | |||
9 | if 'darwin' in sys.platform: |
|
9 | if 'darwin' in sys.platform: | |
10 | matplotlib.use("GTKAgg") |
|
10 | matplotlib.use("GTKAgg") | |
11 |
|
11 | |||
12 | import matplotlib.pyplot |
|
12 | import matplotlib.pyplot | |
13 |
|
13 | |||
14 | from mpl_toolkits.axes_grid1 import make_axes_locatable |
|
14 | from mpl_toolkits.axes_grid1 import make_axes_locatable | |
15 | from matplotlib.ticker import * |
|
15 | from matplotlib.ticker import * | |
16 |
|
16 | |||
17 | ########################################### |
|
17 | ########################################### | |
18 | #Actualizacion de las funciones del driver |
|
18 | #Actualizacion de las funciones del driver | |
19 | ########################################### |
|
19 | ########################################### | |
20 |
|
20 | |||
21 | def createFigure(id, wintitle, width, height, facecolor="w", show=True): |
|
21 | def createFigure(id, wintitle, width, height, facecolor="w", show=True): | |
22 |
|
22 | |||
23 | matplotlib.pyplot.ioff() |
|
23 | matplotlib.pyplot.ioff() | |
24 | fig = matplotlib.pyplot.figure(num=id, facecolor=facecolor) |
|
24 | fig = matplotlib.pyplot.figure(num=id, facecolor=facecolor) | |
25 | fig.canvas.manager.set_window_title(wintitle) |
|
25 | fig.canvas.manager.set_window_title(wintitle) | |
26 | fig.canvas.manager.resize(width, height) |
|
26 | fig.canvas.manager.resize(width, height) | |
27 | matplotlib.pyplot.ion() |
|
27 | matplotlib.pyplot.ion() | |
28 | if show: |
|
28 | if show: | |
29 | matplotlib.pyplot.show() |
|
29 | matplotlib.pyplot.show() | |
30 |
|
30 | |||
31 | return fig |
|
31 | return fig | |
32 |
|
32 | |||
33 | def closeFigure(show=True): |
|
33 | def closeFigure(show=True): | |
34 |
|
34 | |||
35 | matplotlib.pyplot.ioff() |
|
35 | matplotlib.pyplot.ioff() | |
36 | if show: |
|
36 | if show: | |
37 | matplotlib.pyplot.show() |
|
37 | matplotlib.pyplot.show() | |
38 |
|
38 | |||
39 | return |
|
39 | return | |
40 |
|
40 | |||
41 | def saveFigure(fig, filename): |
|
41 | def saveFigure(fig, filename): | |
42 |
|
42 | |||
43 | matplotlib.pyplot.ioff() |
|
43 | matplotlib.pyplot.ioff() | |
44 | fig.savefig(filename) |
|
44 | fig.savefig(filename) | |
45 | matplotlib.pyplot.ion() |
|
45 | matplotlib.pyplot.ion() | |
46 |
|
46 | |||
47 | def setWinTitle(fig, title): |
|
47 | def setWinTitle(fig, title): | |
48 |
|
48 | |||
49 | fig.canvas.manager.set_window_title(title) |
|
49 | fig.canvas.manager.set_window_title(title) | |
50 |
|
50 | |||
51 | def setTitle(fig, title): |
|
51 | def setTitle(fig, title): | |
52 |
|
52 | |||
53 | fig.suptitle(title) |
|
53 | fig.suptitle(title) | |
54 |
|
54 | |||
55 | def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan): |
|
55 | def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan): | |
56 |
|
56 | |||
57 | matplotlib.pyplot.ioff() |
|
57 | matplotlib.pyplot.ioff() | |
58 | matplotlib.pyplot.figure(fig.number) |
|
58 | matplotlib.pyplot.figure(fig.number) | |
59 | axes = matplotlib.pyplot.subplot2grid((nrow, ncol), |
|
59 | axes = matplotlib.pyplot.subplot2grid((nrow, ncol), | |
60 | (xpos, ypos), |
|
60 | (xpos, ypos), | |
61 | colspan=colspan, |
|
61 | colspan=colspan, | |
62 | rowspan=rowspan) |
|
62 | rowspan=rowspan) | |
63 |
|
63 | |||
64 | matplotlib.pyplot.ion() |
|
64 | matplotlib.pyplot.ion() | |
65 | return axes |
|
65 | return axes | |
66 |
|
66 | |||
67 | def setAxesText(ax, text): |
|
67 | def setAxesText(ax, text): | |
68 |
|
68 | |||
69 | ax.annotate(text, |
|
69 | ax.annotate(text, | |
70 | xy = (.1, .99), |
|
70 | xy = (.1, .99), | |
71 | xycoords = 'figure fraction', |
|
71 | xycoords = 'figure fraction', | |
72 | horizontalalignment = 'left', |
|
72 | horizontalalignment = 'left', | |
73 | verticalalignment = 'top', |
|
73 | verticalalignment = 'top', | |
74 | fontsize = 10) |
|
74 | fontsize = 10) | |
75 |
|
75 | |||
76 | def printLabels(ax, xlabel, ylabel, title): |
|
76 | def printLabels(ax, xlabel, ylabel, title): | |
77 |
|
77 | |||
78 | ax.set_xlabel(xlabel, size=11) |
|
78 | ax.set_xlabel(xlabel, size=11) | |
79 | ax.set_ylabel(ylabel, size=11) |
|
79 | ax.set_ylabel(ylabel, size=11) | |
80 | ax.set_title(title, size=12) |
|
80 | ax.set_title(title, size=12) | |
81 |
|
81 | |||
82 | def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', |
|
82 | def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', | |
83 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
83 | ticksize=9, xtick_visible=True, ytick_visible=True, | |
84 | nxticks=4, nyticks=10, |
|
84 | nxticks=4, nyticks=10, | |
85 | grid=None): |
|
85 | grid=None): | |
86 |
|
86 | |||
87 | """ |
|
87 | """ | |
88 |
|
88 | |||
89 | Input: |
|
89 | Input: | |
90 | grid : None, 'both', 'x', 'y' |
|
90 | grid : None, 'both', 'x', 'y' | |
91 | """ |
|
91 | """ | |
92 |
|
92 | |||
93 | matplotlib.pyplot.ioff() |
|
93 | matplotlib.pyplot.ioff() | |
94 |
|
94 | |||
95 | ax.set_xlim([xmin,xmax]) |
|
95 | ax.set_xlim([xmin,xmax]) | |
96 | ax.set_ylim([ymin,ymax]) |
|
96 | ax.set_ylim([ymin,ymax]) | |
97 |
|
97 | |||
98 | printLabels(ax, xlabel, ylabel, title) |
|
98 | printLabels(ax, xlabel, ylabel, title) | |
99 |
|
99 | |||
100 | ###################################################### |
|
100 | ###################################################### | |
101 | if (xmax-xmin)<=1: |
|
101 | if (xmax-xmin)<=1: | |
102 | xtickspos = numpy.linspace(xmin,xmax,nxticks) |
|
102 | xtickspos = numpy.linspace(xmin,xmax,nxticks) | |
103 | xtickspos = numpy.array([float("%.1f"%i) for i in xtickspos]) |
|
103 | xtickspos = numpy.array([float("%.1f"%i) for i in xtickspos]) | |
104 | ax.set_xticks(xtickspos) |
|
104 | ax.set_xticks(xtickspos) | |
105 | else: |
|
105 | else: | |
106 |
|
|
106 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) | |
107 | xtickspos = numpy.arange(nxticks)*float(xmax-xmin)/float(nxticks) + int(xmin) |
|
107 | # xtickspos = numpy.arange(nxticks)*float(xmax-xmin)/float(nxticks) + int(xmin) | |
108 | ax.set_xticks(xtickspos) |
|
108 | ax.set_xticks(xtickspos) | |
109 |
|
109 | |||
110 | for tick in ax.get_xticklabels(): |
|
110 | for tick in ax.get_xticklabels(): | |
111 | tick.set_visible(xtick_visible) |
|
111 | tick.set_visible(xtick_visible) | |
112 |
|
112 | |||
113 | for tick in ax.xaxis.get_major_ticks(): |
|
113 | for tick in ax.xaxis.get_major_ticks(): | |
114 | tick.label.set_fontsize(ticksize) |
|
114 | tick.label.set_fontsize(ticksize) | |
115 |
|
115 | |||
116 | ###################################################### |
|
116 | ###################################################### | |
117 | for tick in ax.get_yticklabels(): |
|
117 | for tick in ax.get_yticklabels(): | |
118 | tick.set_visible(ytick_visible) |
|
118 | tick.set_visible(ytick_visible) | |
119 |
|
119 | |||
120 | for tick in ax.yaxis.get_major_ticks(): |
|
120 | for tick in ax.yaxis.get_major_ticks(): | |
121 | tick.label.set_fontsize(ticksize) |
|
121 | tick.label.set_fontsize(ticksize) | |
122 |
|
122 | |||
123 | ax.plot(x, y) |
|
123 | ax.plot(x, y) | |
124 | iplot = ax.lines[-1] |
|
124 | iplot = ax.lines[-1] | |
125 |
|
125 | |||
126 | ###################################################### |
|
126 | ###################################################### | |
127 | if '0.' in matplotlib.__version__[0:2]: |
|
127 | if '0.' in matplotlib.__version__[0:2]: | |
128 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
128 | print "The matplotlib version has to be updated to 1.1 or newer" | |
129 | return iplot |
|
129 | return iplot | |
130 |
|
130 | |||
131 | if '1.0.' in matplotlib.__version__[0:4]: |
|
131 | if '1.0.' in matplotlib.__version__[0:4]: | |
132 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
132 | print "The matplotlib version has to be updated to 1.1 or newer" | |
133 | return iplot |
|
133 | return iplot | |
134 |
|
134 | |||
135 | if grid != None: |
|
135 | if grid != None: | |
136 | ax.grid(b=True, which='major', axis=grid) |
|
136 | ax.grid(b=True, which='major', axis=grid) | |
137 |
|
137 | |||
138 | matplotlib.pyplot.tight_layout() |
|
138 | matplotlib.pyplot.tight_layout() | |
139 |
|
139 | |||
140 | matplotlib.pyplot.ion() |
|
140 | matplotlib.pyplot.ion() | |
141 |
|
141 | |||
142 | return iplot |
|
142 | return iplot | |
143 |
|
143 | |||
144 | def set_linedata(ax, x, y, idline): |
|
144 | def set_linedata(ax, x, y, idline): | |
145 |
|
145 | |||
146 | ax.lines[idline].set_data(x,y) |
|
146 | ax.lines[idline].set_data(x,y) | |
147 |
|
147 | |||
148 | def pline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
148 | def pline(iplot, x, y, xlabel='', ylabel='', title=''): | |
149 |
|
149 | |||
150 | ax = iplot.get_axes() |
|
150 | ax = iplot.get_axes() | |
151 |
|
151 | |||
152 | printLabels(ax, xlabel, ylabel, title) |
|
152 | printLabels(ax, xlabel, ylabel, title) | |
153 |
|
153 | |||
154 | set_linedata(ax, x, y, idline=0) |
|
154 | set_linedata(ax, x, y, idline=0) | |
155 |
|
155 | |||
156 | def addpline(ax, x, y, color, linestyle, lw): |
|
156 | def addpline(ax, x, y, color, linestyle, lw): | |
157 |
|
157 | |||
158 | ax.plot(x,y,color=color,linestyle=linestyle,lw=lw) |
|
158 | ax.plot(x,y,color=color,linestyle=linestyle,lw=lw) | |
159 |
|
159 | |||
160 |
|
160 | |||
161 | def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, |
|
161 | def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, | |
162 | xlabel='', ylabel='', title='', ticksize = 9, |
|
162 | xlabel='', ylabel='', title='', ticksize = 9, | |
163 | colormap='jet',cblabel='', cbsize="5%", |
|
163 | colormap='jet',cblabel='', cbsize="5%", | |
164 | XAxisAsTime=False): |
|
164 | XAxisAsTime=False): | |
165 |
|
165 | |||
166 | matplotlib.pyplot.ioff() |
|
166 | matplotlib.pyplot.ioff() | |
167 |
|
167 | |||
168 | divider = make_axes_locatable(ax) |
|
168 | divider = make_axes_locatable(ax) | |
169 | ax_cb = divider.new_horizontal(size=cbsize, pad=0.05) |
|
169 | ax_cb = divider.new_horizontal(size=cbsize, pad=0.05) | |
170 | fig = ax.get_figure() |
|
170 | fig = ax.get_figure() | |
171 | fig.add_axes(ax_cb) |
|
171 | fig.add_axes(ax_cb) | |
172 |
|
172 | |||
173 | ax.set_xlim([xmin,xmax]) |
|
173 | ax.set_xlim([xmin,xmax]) | |
174 | ax.set_ylim([ymin,ymax]) |
|
174 | ax.set_ylim([ymin,ymax]) | |
175 |
|
175 | |||
176 | printLabels(ax, xlabel, ylabel, title) |
|
176 | printLabels(ax, xlabel, ylabel, title) | |
177 |
|
177 | |||
178 | imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) |
|
178 | imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) | |
179 | cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb) |
|
179 | cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb) | |
180 | cb.set_label(cblabel) |
|
180 | cb.set_label(cblabel) | |
181 |
|
181 | |||
182 | # for tl in ax_cb.get_yticklabels(): |
|
182 | # for tl in ax_cb.get_yticklabels(): | |
183 | # tl.set_visible(True) |
|
183 | # tl.set_visible(True) | |
184 |
|
184 | |||
185 | for tick in ax.yaxis.get_major_ticks(): |
|
185 | for tick in ax.yaxis.get_major_ticks(): | |
186 | tick.label.set_fontsize(ticksize) |
|
186 | tick.label.set_fontsize(ticksize) | |
187 |
|
187 | |||
188 | for tick in ax.xaxis.get_major_ticks(): |
|
188 | for tick in ax.xaxis.get_major_ticks(): | |
189 | tick.label.set_fontsize(ticksize) |
|
189 | tick.label.set_fontsize(ticksize) | |
190 |
|
190 | |||
191 | for tick in cb.ax.get_yticklabels(): |
|
191 | for tick in cb.ax.get_yticklabels(): | |
192 | tick.set_fontsize(ticksize) |
|
192 | tick.set_fontsize(ticksize) | |
193 |
|
193 | |||
194 | ax_cb.yaxis.tick_right() |
|
194 | ax_cb.yaxis.tick_right() | |
195 |
|
195 | |||
196 | if '0.' in matplotlib.__version__[0:2]: |
|
196 | if '0.' in matplotlib.__version__[0:2]: | |
197 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
197 | print "The matplotlib version has to be updated to 1.1 or newer" | |
198 | return imesh |
|
198 | return imesh | |
199 |
|
199 | |||
200 | if '1.0.' in matplotlib.__version__[0:4]: |
|
200 | if '1.0.' in matplotlib.__version__[0:4]: | |
201 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
201 | print "The matplotlib version has to be updated to 1.1 or newer" | |
202 | return imesh |
|
202 | return imesh | |
203 |
|
203 | |||
204 | matplotlib.pyplot.tight_layout() |
|
204 | matplotlib.pyplot.tight_layout() | |
205 |
|
205 | |||
206 | if XAxisAsTime: |
|
206 | if XAxisAsTime: | |
207 |
|
207 | |||
208 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) |
|
208 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) | |
209 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
209 | ax.xaxis.set_major_formatter(FuncFormatter(func)) | |
210 | ax.xaxis.set_major_locator(LinearLocator(7)) |
|
210 | ax.xaxis.set_major_locator(LinearLocator(7)) | |
211 |
|
211 | |||
212 | matplotlib.pyplot.ion() |
|
212 | matplotlib.pyplot.ion() | |
213 | return imesh |
|
213 | return imesh | |
214 |
|
214 | |||
215 | def pcolor(imesh, z, xlabel='', ylabel='', title=''): |
|
215 | def pcolor(imesh, z, xlabel='', ylabel='', title=''): | |
216 |
|
216 | |||
217 | z = z.T |
|
217 | z = z.T | |
218 |
|
218 | |||
219 | ax = imesh.get_axes() |
|
219 | ax = imesh.get_axes() | |
220 |
|
220 | |||
221 | printLabels(ax, xlabel, ylabel, title) |
|
221 | printLabels(ax, xlabel, ylabel, title) | |
222 |
|
222 | |||
223 | imesh.set_array(z.ravel()) |
|
223 | imesh.set_array(z.ravel()) | |
224 |
|
224 | |||
225 | def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): |
|
225 | def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): | |
226 |
|
226 | |||
227 | printLabels(ax, xlabel, ylabel, title) |
|
227 | printLabels(ax, xlabel, ylabel, title) | |
228 |
|
228 | |||
229 | ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) |
|
229 | ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) | |
230 |
|
230 | |||
231 | def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): |
|
231 | def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): | |
232 |
|
232 | |||
233 | printLabels(ax, xlabel, ylabel, title) |
|
233 | printLabels(ax, xlabel, ylabel, title) | |
234 |
|
234 | |||
235 | ax.collections.remove(ax.collections[0]) |
|
235 | ax.collections.remove(ax.collections[0]) | |
236 |
|
236 | |||
237 | ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) |
|
237 | ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) | |
238 |
|
238 | |||
239 | def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, |
|
239 | def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, | |
240 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
240 | ticksize=9, xtick_visible=True, ytick_visible=True, | |
241 | nxticks=4, nyticks=10, |
|
241 | nxticks=4, nyticks=10, | |
242 | grid=None): |
|
242 | grid=None): | |
243 |
|
243 | |||
244 | """ |
|
244 | """ | |
245 |
|
245 | |||
246 | Input: |
|
246 | Input: | |
247 | grid : None, 'both', 'x', 'y' |
|
247 | grid : None, 'both', 'x', 'y' | |
248 | """ |
|
248 | """ | |
249 |
|
249 | |||
250 | matplotlib.pyplot.ioff() |
|
250 | matplotlib.pyplot.ioff() | |
251 |
|
251 | |||
252 | lines = ax.plot(x.T, y) |
|
252 | lines = ax.plot(x.T, y) | |
253 | leg = ax.legend(lines, legendlabels, loc='upper right') |
|
253 | leg = ax.legend(lines, legendlabels, loc='upper right') | |
254 | leg.get_frame().set_alpha(0.5) |
|
254 | leg.get_frame().set_alpha(0.5) | |
255 | ax.set_xlim([xmin,xmax]) |
|
255 | ax.set_xlim([xmin,xmax]) | |
256 | ax.set_ylim([ymin,ymax]) |
|
256 | ax.set_ylim([ymin,ymax]) | |
257 | printLabels(ax, xlabel, ylabel, title) |
|
257 | printLabels(ax, xlabel, ylabel, title) | |
258 |
|
258 | |||
259 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
|
259 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) | |
260 | ax.set_xticks(xtickspos) |
|
260 | ax.set_xticks(xtickspos) | |
261 |
|
261 | |||
262 | for tick in ax.get_xticklabels(): |
|
262 | for tick in ax.get_xticklabels(): | |
263 | tick.set_visible(xtick_visible) |
|
263 | tick.set_visible(xtick_visible) | |
264 |
|
264 | |||
265 | for tick in ax.xaxis.get_major_ticks(): |
|
265 | for tick in ax.xaxis.get_major_ticks(): | |
266 | tick.label.set_fontsize(ticksize) |
|
266 | tick.label.set_fontsize(ticksize) | |
267 |
|
267 | |||
268 | for tick in ax.get_yticklabels(): |
|
268 | for tick in ax.get_yticklabels(): | |
269 | tick.set_visible(ytick_visible) |
|
269 | tick.set_visible(ytick_visible) | |
270 |
|
270 | |||
271 | for tick in ax.yaxis.get_major_ticks(): |
|
271 | for tick in ax.yaxis.get_major_ticks(): | |
272 | tick.label.set_fontsize(ticksize) |
|
272 | tick.label.set_fontsize(ticksize) | |
273 |
|
273 | |||
274 | iplot = ax.lines[-1] |
|
274 | iplot = ax.lines[-1] | |
275 |
|
275 | |||
276 | if '0.' in matplotlib.__version__[0:2]: |
|
276 | if '0.' in matplotlib.__version__[0:2]: | |
277 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
277 | print "The matplotlib version has to be updated to 1.1 or newer" | |
278 | return iplot |
|
278 | return iplot | |
279 |
|
279 | |||
280 | if '1.0.' in matplotlib.__version__[0:4]: |
|
280 | if '1.0.' in matplotlib.__version__[0:4]: | |
281 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
281 | print "The matplotlib version has to be updated to 1.1 or newer" | |
282 | return iplot |
|
282 | return iplot | |
283 |
|
283 | |||
284 | if grid != None: |
|
284 | if grid != None: | |
285 | ax.grid(b=True, which='major', axis=grid) |
|
285 | ax.grid(b=True, which='major', axis=grid) | |
286 |
|
286 | |||
287 | matplotlib.pyplot.tight_layout() |
|
287 | matplotlib.pyplot.tight_layout() | |
288 |
|
288 | |||
289 | matplotlib.pyplot.ion() |
|
289 | matplotlib.pyplot.ion() | |
290 |
|
290 | |||
291 | return iplot |
|
291 | return iplot | |
292 |
|
292 | |||
293 |
|
293 | |||
294 | def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
294 | def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''): | |
295 |
|
295 | |||
296 | ax = iplot.get_axes() |
|
296 | ax = iplot.get_axes() | |
297 |
|
297 | |||
298 | printLabels(ax, xlabel, ylabel, title) |
|
298 | printLabels(ax, xlabel, ylabel, title) | |
299 |
|
299 | |||
300 | for i in range(len(ax.lines)): |
|
300 | for i in range(len(ax.lines)): | |
301 | line = ax.lines[i] |
|
301 | line = ax.lines[i] | |
302 | line.set_data(x[i,:],y) |
|
302 | line.set_data(x[i,:],y) | |
303 |
|
303 | |||
304 | def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, |
|
304 | def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, | |
305 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
305 | ticksize=9, xtick_visible=True, ytick_visible=True, | |
306 | nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None", |
|
306 | nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None", | |
307 | grid=None, XAxisAsTime=False): |
|
307 | grid=None, XAxisAsTime=False): | |
308 |
|
308 | |||
309 | """ |
|
309 | """ | |
310 |
|
310 | |||
311 | Input: |
|
311 | Input: | |
312 | grid : None, 'both', 'x', 'y' |
|
312 | grid : None, 'both', 'x', 'y' | |
313 | """ |
|
313 | """ | |
314 |
|
314 | |||
315 | matplotlib.pyplot.ioff() |
|
315 | matplotlib.pyplot.ioff() | |
316 |
|
316 | |||
317 | # lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle) |
|
317 | # lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle) | |
318 | lines = ax.plot(x, y.T, linestyle='None', marker='.', markersize=markersize) |
|
318 | lines = ax.plot(x, y.T, linestyle='None', marker='.', markersize=markersize) | |
319 | leg = ax.legend(lines, legendlabels, loc='upper left', bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \ |
|
319 | leg = ax.legend(lines, legendlabels, loc='upper left', bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \ | |
320 | handletextpad=0.5, borderpad=0.5, labelspacing=0.5, borderaxespad=0.) |
|
320 | handletextpad=0.5, borderpad=0.5, labelspacing=0.5, borderaxespad=0.) | |
321 |
|
321 | |||
322 | for label in leg.get_texts(): label.set_fontsize(9) |
|
322 | for label in leg.get_texts(): label.set_fontsize(9) | |
323 |
|
323 | |||
324 | ax.set_xlim([xmin,xmax]) |
|
324 | ax.set_xlim([xmin,xmax]) | |
325 | ax.set_ylim([ymin,ymax]) |
|
325 | ax.set_ylim([ymin,ymax]) | |
326 | printLabels(ax, xlabel, ylabel, title) |
|
326 | printLabels(ax, xlabel, ylabel, title) | |
327 |
|
327 | |||
328 | # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
|
328 | # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) | |
329 | # ax.set_xticks(xtickspos) |
|
329 | # ax.set_xticks(xtickspos) | |
330 |
|
330 | |||
331 | for tick in ax.get_xticklabels(): |
|
331 | for tick in ax.get_xticklabels(): | |
332 | tick.set_visible(xtick_visible) |
|
332 | tick.set_visible(xtick_visible) | |
333 |
|
333 | |||
334 | for tick in ax.xaxis.get_major_ticks(): |
|
334 | for tick in ax.xaxis.get_major_ticks(): | |
335 | tick.label.set_fontsize(ticksize) |
|
335 | tick.label.set_fontsize(ticksize) | |
336 |
|
336 | |||
337 | for tick in ax.get_yticklabels(): |
|
337 | for tick in ax.get_yticklabels(): | |
338 | tick.set_visible(ytick_visible) |
|
338 | tick.set_visible(ytick_visible) | |
339 |
|
339 | |||
340 | for tick in ax.yaxis.get_major_ticks(): |
|
340 | for tick in ax.yaxis.get_major_ticks(): | |
341 | tick.label.set_fontsize(ticksize) |
|
341 | tick.label.set_fontsize(ticksize) | |
342 |
|
342 | |||
343 | iplot = ax.lines[-1] |
|
343 | iplot = ax.lines[-1] | |
344 |
|
344 | |||
345 | if '0.' in matplotlib.__version__[0:2]: |
|
345 | if '0.' in matplotlib.__version__[0:2]: | |
346 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
346 | print "The matplotlib version has to be updated to 1.1 or newer" | |
347 | return iplot |
|
347 | return iplot | |
348 |
|
348 | |||
349 | if '1.0.' in matplotlib.__version__[0:4]: |
|
349 | if '1.0.' in matplotlib.__version__[0:4]: | |
350 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
350 | print "The matplotlib version has to be updated to 1.1 or newer" | |
351 | return iplot |
|
351 | return iplot | |
352 |
|
352 | |||
353 | if grid != None: |
|
353 | if grid != None: | |
354 | ax.grid(b=True, which='major', axis=grid) |
|
354 | ax.grid(b=True, which='major', axis=grid) | |
355 |
|
355 | |||
356 | matplotlib.pyplot.tight_layout() |
|
356 | matplotlib.pyplot.tight_layout() | |
357 |
|
357 | |||
358 | if XAxisAsTime: |
|
358 | if XAxisAsTime: | |
359 |
|
359 | |||
360 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) |
|
360 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) | |
361 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
361 | ax.xaxis.set_major_formatter(FuncFormatter(func)) | |
362 | ax.xaxis.set_major_locator(LinearLocator(7)) |
|
362 | ax.xaxis.set_major_locator(LinearLocator(7)) | |
363 |
|
363 | |||
364 | matplotlib.pyplot.ion() |
|
364 | matplotlib.pyplot.ion() | |
365 |
|
365 | |||
366 | return iplot |
|
366 | return iplot | |
367 |
|
367 | |||
368 | def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''): |
|
368 | def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''): | |
369 |
|
369 | |||
370 | ax = iplot.get_axes() |
|
370 | ax = iplot.get_axes() | |
371 |
|
371 | |||
372 | printLabels(ax, xlabel, ylabel, title) |
|
372 | printLabels(ax, xlabel, ylabel, title) | |
373 |
|
373 | |||
374 | for i in range(len(ax.lines)): |
|
374 | for i in range(len(ax.lines)): | |
375 | line = ax.lines[i] |
|
375 | line = ax.lines[i] | |
376 | line.set_data(x,y[i,:]) |
|
376 | line.set_data(x,y[i,:]) | |
377 |
|
377 | |||
378 | def draw(fig): |
|
378 | def draw(fig): | |
379 |
|
379 | |||
380 | if type(fig) == 'int': |
|
380 | if type(fig) == 'int': | |
381 | raise ValueError, "This parameter should be of tpye matplotlib figure" |
|
381 | raise ValueError, "This parameter should be of tpye matplotlib figure" | |
382 |
|
382 | |||
383 | fig.canvas.draw() No newline at end of file |
|
383 | fig.canvas.draw() |
@@ -1,1367 +1,1387 | |||||
1 | import numpy |
|
1 | import numpy | |
2 | import time, datetime, os |
|
2 | import time, datetime, os | |
3 | from graphics.figure import * |
|
3 | from graphics.figure import * | |
4 | def isRealtime(utcdatatime): |
|
4 | def isRealtime(utcdatatime): | |
5 | utcnow = time.mktime(datetime.datetime.utcnow().timetuple()) |
|
5 | utcnow = time.mktime(datetime.datetime.utcnow().timetuple()) | |
6 | delta = utcnow - utcdatatime # abs |
|
6 | delta = utcnow - utcdatatime # abs | |
7 | if delta >= 5*60.: |
|
7 | if delta >= 5*60.: | |
8 | return False |
|
8 | return False | |
9 | return True |
|
9 | return True | |
10 |
|
10 | |||
11 | class CrossSpectraPlot(Figure): |
|
11 | class CrossSpectraPlot(Figure): | |
12 |
|
12 | |||
13 | __isConfig = None |
|
13 | __isConfig = None | |
14 | __nsubplots = None |
|
14 | __nsubplots = None | |
15 |
|
15 | |||
16 | WIDTH = None |
|
16 | WIDTH = None | |
17 | HEIGHT = None |
|
17 | HEIGHT = None | |
18 | WIDTHPROF = None |
|
18 | WIDTHPROF = None | |
19 | HEIGHTPROF = None |
|
19 | HEIGHTPROF = None | |
20 | PREFIX = 'cspc' |
|
20 | PREFIX = 'cspc' | |
21 |
|
21 | |||
22 | def __init__(self): |
|
22 | def __init__(self): | |
23 |
|
23 | |||
24 | self.__isConfig = False |
|
24 | self.__isConfig = False | |
25 | self.__nsubplots = 4 |
|
25 | self.__nsubplots = 4 | |
26 |
|
26 | |||
27 | self.WIDTH = 250 |
|
27 | self.WIDTH = 250 | |
28 | self.HEIGHT = 250 |
|
28 | self.HEIGHT = 250 | |
29 | self.WIDTHPROF = 0 |
|
29 | self.WIDTHPROF = 0 | |
30 | self.HEIGHTPROF = 0 |
|
30 | self.HEIGHTPROF = 0 | |
31 |
|
31 | |||
32 | def getSubplots(self): |
|
32 | def getSubplots(self): | |
33 |
|
33 | |||
34 | ncol = 4 |
|
34 | ncol = 4 | |
35 | nrow = self.nplots |
|
35 | nrow = self.nplots | |
36 |
|
36 | |||
37 | return nrow, ncol |
|
37 | return nrow, ncol | |
38 |
|
38 | |||
39 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
39 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
40 |
|
40 | |||
41 | self.__showprofile = showprofile |
|
41 | self.__showprofile = showprofile | |
42 | self.nplots = nplots |
|
42 | self.nplots = nplots | |
43 |
|
43 | |||
44 | ncolspan = 1 |
|
44 | ncolspan = 1 | |
45 | colspan = 1 |
|
45 | colspan = 1 | |
46 |
|
46 | |||
47 | self.createFigure(id = id, |
|
47 | self.createFigure(id = id, | |
48 | wintitle = wintitle, |
|
48 | wintitle = wintitle, | |
49 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
49 | widthplot = self.WIDTH + self.WIDTHPROF, | |
50 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
50 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
51 | show=True) |
|
51 | show=True) | |
52 |
|
52 | |||
53 | nrow, ncol = self.getSubplots() |
|
53 | nrow, ncol = self.getSubplots() | |
54 |
|
54 | |||
55 | counter = 0 |
|
55 | counter = 0 | |
56 | for y in range(nrow): |
|
56 | for y in range(nrow): | |
57 | for x in range(ncol): |
|
57 | for x in range(ncol): | |
58 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
58 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
59 |
|
59 | |||
60 | counter += 1 |
|
60 | counter += 1 | |
61 |
|
61 | |||
62 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', |
|
62 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', | |
63 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
63 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
64 | save=False, figpath='./', figfile=None, |
|
64 | save=False, figpath='./', figfile=None, | |
65 | power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True): |
|
65 | power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True): | |
66 |
|
66 | |||
67 | """ |
|
67 | """ | |
68 |
|
68 | |||
69 | Input: |
|
69 | Input: | |
70 | dataOut : |
|
70 | dataOut : | |
71 | id : |
|
71 | id : | |
72 | wintitle : |
|
72 | wintitle : | |
73 | channelList : |
|
73 | channelList : | |
74 | showProfile : |
|
74 | showProfile : | |
75 | xmin : None, |
|
75 | xmin : None, | |
76 | xmax : None, |
|
76 | xmax : None, | |
77 | ymin : None, |
|
77 | ymin : None, | |
78 | ymax : None, |
|
78 | ymax : None, | |
79 | zmin : None, |
|
79 | zmin : None, | |
80 | zmax : None |
|
80 | zmax : None | |
81 | """ |
|
81 | """ | |
82 |
|
82 | |||
83 | if pairsList == None: |
|
83 | if pairsList == None: | |
84 | pairsIndexList = dataOut.pairsIndexList |
|
84 | pairsIndexList = dataOut.pairsIndexList | |
85 | else: |
|
85 | else: | |
86 | pairsIndexList = [] |
|
86 | pairsIndexList = [] | |
87 | for pair in pairsList: |
|
87 | for pair in pairsList: | |
88 | if pair not in dataOut.pairsList: |
|
88 | if pair not in dataOut.pairsList: | |
89 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
89 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) | |
90 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
90 | pairsIndexList.append(dataOut.pairsList.index(pair)) | |
91 |
|
91 | |||
92 | if pairsIndexList == []: |
|
92 | if pairsIndexList == []: | |
93 | return |
|
93 | return | |
94 |
|
94 | |||
95 | if len(pairsIndexList) > 4: |
|
95 | if len(pairsIndexList) > 4: | |
96 | pairsIndexList = pairsIndexList[0:4] |
|
96 | pairsIndexList = pairsIndexList[0:4] | |
97 | factor = dataOut.normFactor |
|
97 | factor = dataOut.normFactor | |
98 | x = dataOut.getVelRange(1) |
|
98 | x = dataOut.getVelRange(1) | |
99 | y = dataOut.getHeiRange() |
|
99 | y = dataOut.getHeiRange() | |
100 | z = dataOut.data_spc[:,:,:]/factor |
|
100 | z = dataOut.data_spc[:,:,:]/factor | |
101 | # z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
101 | # z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
102 | avg = numpy.abs(numpy.average(z, axis=1)) |
|
102 | avg = numpy.abs(numpy.average(z, axis=1)) | |
103 | noise = dataOut.getNoise()/factor |
|
103 | noise = dataOut.getNoise()/factor | |
104 |
|
104 | |||
105 | zdB = 10*numpy.log10(z) |
|
105 | zdB = 10*numpy.log10(z) | |
106 | avgdB = 10*numpy.log10(avg) |
|
106 | avgdB = 10*numpy.log10(avg) | |
107 | noisedB = 10*numpy.log10(noise) |
|
107 | noisedB = 10*numpy.log10(noise) | |
108 |
|
108 | |||
109 |
|
109 | |||
110 | #thisDatetime = dataOut.datatime |
|
110 | #thisDatetime = dataOut.datatime | |
111 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
111 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
112 | title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
112 | title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
113 | xlabel = "Velocity (m/s)" |
|
113 | xlabel = "Velocity (m/s)" | |
114 | ylabel = "Range (Km)" |
|
114 | ylabel = "Range (Km)" | |
115 |
|
115 | |||
116 | if not self.__isConfig: |
|
116 | if not self.__isConfig: | |
117 |
|
117 | |||
118 | nplots = len(pairsIndexList) |
|
118 | nplots = len(pairsIndexList) | |
119 |
|
119 | |||
120 | self.setup(id=id, |
|
120 | self.setup(id=id, | |
121 | nplots=nplots, |
|
121 | nplots=nplots, | |
122 | wintitle=wintitle, |
|
122 | wintitle=wintitle, | |
123 | showprofile=showprofile, |
|
123 | showprofile=showprofile, | |
124 | show=show) |
|
124 | show=show) | |
125 |
|
125 | |||
126 | if xmin == None: xmin = numpy.nanmin(x) |
|
126 | if xmin == None: xmin = numpy.nanmin(x) | |
127 | if xmax == None: xmax = numpy.nanmax(x) |
|
127 | if xmax == None: xmax = numpy.nanmax(x) | |
128 | if ymin == None: ymin = numpy.nanmin(y) |
|
128 | if ymin == None: ymin = numpy.nanmin(y) | |
129 | if ymax == None: ymax = numpy.nanmax(y) |
|
129 | if ymax == None: ymax = numpy.nanmax(y) | |
130 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
130 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 | |
131 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
131 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 | |
132 |
|
132 | |||
133 | self.__isConfig = True |
|
133 | self.__isConfig = True | |
134 |
|
134 | |||
135 | self.setWinTitle(title) |
|
135 | self.setWinTitle(title) | |
136 |
|
136 | |||
137 | for i in range(self.nplots): |
|
137 | for i in range(self.nplots): | |
138 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
138 | pair = dataOut.pairsList[pairsIndexList[i]] | |
139 |
|
139 | |||
140 | title = "Channel %d: %4.2fdB" %(pair[0], noisedB[pair[0]]) |
|
140 | title = "Channel %d: %4.2fdB" %(pair[0], noisedB[pair[0]]) | |
141 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]/factor) |
|
141 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]/factor) | |
142 | axes0 = self.axesList[i*self.__nsubplots] |
|
142 | axes0 = self.axesList[i*self.__nsubplots] | |
143 | axes0.pcolor(x, y, zdB, |
|
143 | axes0.pcolor(x, y, zdB, | |
144 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
144 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
145 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
145 | xlabel=xlabel, ylabel=ylabel, title=title, | |
146 | ticksize=9, colormap=power_cmap, cblabel='') |
|
146 | ticksize=9, colormap=power_cmap, cblabel='') | |
147 |
|
147 | |||
148 | title = "Channel %d: %4.2fdB" %(pair[1], noisedB[pair[1]]) |
|
148 | title = "Channel %d: %4.2fdB" %(pair[1], noisedB[pair[1]]) | |
149 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]/factor) |
|
149 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]/factor) | |
150 | axes0 = self.axesList[i*self.__nsubplots+1] |
|
150 | axes0 = self.axesList[i*self.__nsubplots+1] | |
151 | axes0.pcolor(x, y, zdB, |
|
151 | axes0.pcolor(x, y, zdB, | |
152 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
152 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
153 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
153 | xlabel=xlabel, ylabel=ylabel, title=title, | |
154 | ticksize=9, colormap=power_cmap, cblabel='') |
|
154 | ticksize=9, colormap=power_cmap, cblabel='') | |
155 |
|
155 | |||
156 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) |
|
156 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) | |
157 | coherence = numpy.abs(coherenceComplex) |
|
157 | coherence = numpy.abs(coherenceComplex) | |
158 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi |
|
158 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi | |
159 | phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi |
|
159 | phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi | |
160 |
|
160 | |||
161 | title = "Coherence %d%d" %(pair[0], pair[1]) |
|
161 | title = "Coherence %d%d" %(pair[0], pair[1]) | |
162 | axes0 = self.axesList[i*self.__nsubplots+2] |
|
162 | axes0 = self.axesList[i*self.__nsubplots+2] | |
163 | axes0.pcolor(x, y, coherence, |
|
163 | axes0.pcolor(x, y, coherence, | |
164 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1, |
|
164 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1, | |
165 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
165 | xlabel=xlabel, ylabel=ylabel, title=title, | |
166 | ticksize=9, colormap=coherence_cmap, cblabel='') |
|
166 | ticksize=9, colormap=coherence_cmap, cblabel='') | |
167 |
|
167 | |||
168 | title = "Phase %d%d" %(pair[0], pair[1]) |
|
168 | title = "Phase %d%d" %(pair[0], pair[1]) | |
169 | axes0 = self.axesList[i*self.__nsubplots+3] |
|
169 | axes0 = self.axesList[i*self.__nsubplots+3] | |
170 | axes0.pcolor(x, y, phase, |
|
170 | axes0.pcolor(x, y, phase, | |
171 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, |
|
171 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, | |
172 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
172 | xlabel=xlabel, ylabel=ylabel, title=title, | |
173 | ticksize=9, colormap=phase_cmap, cblabel='') |
|
173 | ticksize=9, colormap=phase_cmap, cblabel='') | |
174 |
|
174 | |||
175 |
|
175 | |||
176 |
|
176 | |||
177 | self.draw() |
|
177 | self.draw() | |
178 |
|
178 | |||
179 | if save: |
|
179 | if save: | |
180 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
180 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
181 | if figfile == None: |
|
181 | if figfile == None: | |
182 | figfile = self.getFilename(name = date) |
|
182 | figfile = self.getFilename(name = date) | |
183 |
|
183 | |||
184 | self.saveFigure(figpath, figfile) |
|
184 | self.saveFigure(figpath, figfile) | |
185 |
|
185 | |||
186 |
|
186 | |||
187 | class RTIPlot(Figure): |
|
187 | class RTIPlot(Figure): | |
188 |
|
188 | |||
189 | __isConfig = None |
|
189 | __isConfig = None | |
190 | __nsubplots = None |
|
190 | __nsubplots = None | |
191 |
|
191 | |||
192 | WIDTHPROF = None |
|
192 | WIDTHPROF = None | |
193 | HEIGHTPROF = None |
|
193 | HEIGHTPROF = None | |
194 | PREFIX = 'rti' |
|
194 | PREFIX = 'rti' | |
195 |
|
195 | |||
196 | def __init__(self): |
|
196 | def __init__(self): | |
197 |
|
197 | |||
198 | self.timerange = 2*60*60 |
|
198 | self.timerange = 2*60*60 | |
199 | self.__isConfig = False |
|
199 | self.__isConfig = False | |
200 | self.__nsubplots = 1 |
|
200 | self.__nsubplots = 1 | |
201 |
|
201 | |||
202 | self.WIDTH = 800 |
|
202 | self.WIDTH = 800 | |
203 | self.HEIGHT = 150 |
|
203 | self.HEIGHT = 150 | |
204 | self.WIDTHPROF = 120 |
|
204 | self.WIDTHPROF = 120 | |
205 | self.HEIGHTPROF = 0 |
|
205 | self.HEIGHTPROF = 0 | |
206 | self.counter_imagwr = 0 |
|
206 | self.counter_imagwr = 0 | |
207 |
|
207 | |||
208 | def getSubplots(self): |
|
208 | def getSubplots(self): | |
209 |
|
209 | |||
210 | ncol = 1 |
|
210 | ncol = 1 | |
211 | nrow = self.nplots |
|
211 | nrow = self.nplots | |
212 |
|
212 | |||
213 | return nrow, ncol |
|
213 | return nrow, ncol | |
214 |
|
214 | |||
215 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
215 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
216 |
|
216 | |||
217 | self.__showprofile = showprofile |
|
217 | self.__showprofile = showprofile | |
218 | self.nplots = nplots |
|
218 | self.nplots = nplots | |
219 |
|
219 | |||
220 | ncolspan = 1 |
|
220 | ncolspan = 1 | |
221 | colspan = 1 |
|
221 | colspan = 1 | |
222 | if showprofile: |
|
222 | if showprofile: | |
223 | ncolspan = 7 |
|
223 | ncolspan = 7 | |
224 | colspan = 6 |
|
224 | colspan = 6 | |
225 | self.__nsubplots = 2 |
|
225 | self.__nsubplots = 2 | |
226 |
|
226 | |||
227 | self.createFigure(id = id, |
|
227 | self.createFigure(id = id, | |
228 | wintitle = wintitle, |
|
228 | wintitle = wintitle, | |
229 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
229 | widthplot = self.WIDTH + self.WIDTHPROF, | |
230 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
230 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
231 | show=show) |
|
231 | show=show) | |
232 |
|
232 | |||
233 | nrow, ncol = self.getSubplots() |
|
233 | nrow, ncol = self.getSubplots() | |
234 |
|
234 | |||
235 | counter = 0 |
|
235 | counter = 0 | |
236 | for y in range(nrow): |
|
236 | for y in range(nrow): | |
237 | for x in range(ncol): |
|
237 | for x in range(ncol): | |
238 |
|
238 | |||
239 | if counter >= self.nplots: |
|
239 | if counter >= self.nplots: | |
240 | break |
|
240 | break | |
241 |
|
241 | |||
242 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
242 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
243 |
|
243 | |||
244 | if showprofile: |
|
244 | if showprofile: | |
245 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
245 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
246 |
|
246 | |||
247 | counter += 1 |
|
247 | counter += 1 | |
248 |
|
248 | |||
249 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
249 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', | |
250 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
250 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
251 | timerange=None, |
|
251 | timerange=None, | |
252 | save=False, figpath='./', figfile=None, ftp=False, res_imagwr=1, show=True): |
|
252 | save=False, figpath='./', figfile=None, ftp=False, res_imagwr=1, show=True): | |
253 |
|
253 | |||
254 | """ |
|
254 | """ | |
255 |
|
255 | |||
256 | Input: |
|
256 | Input: | |
257 | dataOut : |
|
257 | dataOut : | |
258 | id : |
|
258 | id : | |
259 | wintitle : |
|
259 | wintitle : | |
260 | channelList : |
|
260 | channelList : | |
261 | showProfile : |
|
261 | showProfile : | |
262 | xmin : None, |
|
262 | xmin : None, | |
263 | xmax : None, |
|
263 | xmax : None, | |
264 | ymin : None, |
|
264 | ymin : None, | |
265 | ymax : None, |
|
265 | ymax : None, | |
266 | zmin : None, |
|
266 | zmin : None, | |
267 | zmax : None |
|
267 | zmax : None | |
268 | """ |
|
268 | """ | |
269 |
|
269 | |||
270 | if channelList == None: |
|
270 | if channelList == None: | |
271 | channelIndexList = dataOut.channelIndexList |
|
271 | channelIndexList = dataOut.channelIndexList | |
272 | else: |
|
272 | else: | |
273 | channelIndexList = [] |
|
273 | channelIndexList = [] | |
274 | for channel in channelList: |
|
274 | for channel in channelList: | |
275 | if channel not in dataOut.channelList: |
|
275 | if channel not in dataOut.channelList: | |
276 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
276 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
277 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
277 | channelIndexList.append(dataOut.channelList.index(channel)) | |
278 |
|
278 | |||
279 | if timerange != None: |
|
279 | if timerange != None: | |
280 | self.timerange = timerange |
|
280 | self.timerange = timerange | |
281 |
|
281 | |||
282 | tmin = None |
|
282 | tmin = None | |
283 | tmax = None |
|
283 | tmax = None | |
284 | factor = dataOut.normFactor |
|
284 | factor = dataOut.normFactor | |
285 | x = dataOut.getTimeRange() |
|
285 | x = dataOut.getTimeRange() | |
286 | y = dataOut.getHeiRange() |
|
286 | y = dataOut.getHeiRange() | |
287 |
|
287 | |||
288 | z = dataOut.data_spc[channelIndexList,:,:]/factor |
|
288 | z = dataOut.data_spc[channelIndexList,:,:]/factor | |
289 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
289 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
290 | avg = numpy.average(z, axis=1) |
|
290 | avg = numpy.average(z, axis=1) | |
291 |
|
291 | |||
292 | avgdB = 10.*numpy.log10(avg) |
|
292 | avgdB = 10.*numpy.log10(avg) | |
293 |
|
293 | |||
294 |
|
294 | |||
295 | # thisDatetime = dataOut.datatime |
|
295 | # thisDatetime = dataOut.datatime | |
296 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
296 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
297 | title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
297 | title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
298 | xlabel = "" |
|
298 | xlabel = "" | |
299 | ylabel = "Range (Km)" |
|
299 | ylabel = "Range (Km)" | |
300 |
|
300 | |||
301 | if not self.__isConfig: |
|
301 | if not self.__isConfig: | |
302 |
|
302 | |||
303 | nplots = len(channelIndexList) |
|
303 | nplots = len(channelIndexList) | |
304 |
|
304 | |||
305 | self.setup(id=id, |
|
305 | self.setup(id=id, | |
306 | nplots=nplots, |
|
306 | nplots=nplots, | |
307 | wintitle=wintitle, |
|
307 | wintitle=wintitle, | |
308 | showprofile=showprofile, |
|
308 | showprofile=showprofile, | |
309 | show=show) |
|
309 | show=show) | |
310 |
|
310 | |||
311 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
311 | tmin, tmax = self.getTimeLim(x, xmin, xmax) | |
312 | if ymin == None: ymin = numpy.nanmin(y) |
|
312 | if ymin == None: ymin = numpy.nanmin(y) | |
313 | if ymax == None: ymax = numpy.nanmax(y) |
|
313 | if ymax == None: ymax = numpy.nanmax(y) | |
314 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
314 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 | |
315 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
315 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 | |
316 |
|
316 | |||
317 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
317 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
|
318 | self.name = '%4d%3d00010000000'%(thisDatetime.timetuple().tm_year,thisDatetime.timetuple().tm_yday) | |||
318 | self.__isConfig = True |
|
319 | self.__isConfig = True | |
319 |
|
320 | |||
320 |
|
321 | |||
321 | self.setWinTitle(title) |
|
322 | self.setWinTitle(title) | |
322 |
|
323 | |||
323 | for i in range(self.nplots): |
|
324 | for i in range(self.nplots): | |
324 | title = "Channel %d: %s" %(dataOut.channelList[i]+1, thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
325 | title = "Channel %d: %s" %(dataOut.channelList[i]+1, thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
325 | axes = self.axesList[i*self.__nsubplots] |
|
326 | axes = self.axesList[i*self.__nsubplots] | |
326 | zdB = avgdB[i].reshape((1,-1)) |
|
327 | zdB = avgdB[i].reshape((1,-1)) | |
327 | axes.pcolorbuffer(x, y, zdB, |
|
328 | axes.pcolorbuffer(x, y, zdB, | |
328 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
329 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
329 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
330 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
330 | ticksize=9, cblabel='', cbsize="1%") |
|
331 | ticksize=9, cblabel='', cbsize="1%") | |
331 |
|
332 | |||
332 | if self.__showprofile: |
|
333 | if self.__showprofile: | |
333 | axes = self.axesList[i*self.__nsubplots +1] |
|
334 | axes = self.axesList[i*self.__nsubplots +1] | |
334 | axes.pline(avgdB[i], y, |
|
335 | axes.pline(avgdB[i], y, | |
335 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
336 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |
336 | xlabel='dB', ylabel='', title='', |
|
337 | xlabel='dB', ylabel='', title='', | |
337 | ytick_visible=False, |
|
338 | ytick_visible=False, | |
338 | grid='x') |
|
339 | grid='x') | |
339 |
|
340 | |||
340 | self.draw() |
|
341 | self.draw() | |
341 |
|
342 | |||
342 | if save: |
|
343 | if save: | |
343 |
|
344 | |||
344 | self.counter_imagwr += 1 |
|
345 | self.counter_imagwr += 1 | |
345 | if (self.counter_imagwr==res_imagwr): |
|
346 | if (self.counter_imagwr==res_imagwr): | |
346 |
|
347 | |||
347 |
|
348 | |||
348 | fig_file = self.getFilename(name = self.name) |
|
349 | fig_file = self.getFilename(name = self.name) | |
349 | self.saveFigure(figpath, fig_file) |
|
350 | self.saveFigure(figpath, fig_file) | |
350 | if ftp: |
|
351 | if ftp: | |
351 | self.saveFigure(figpath, figfile) |
|
352 | # self.saveFigure(figpath, figfile) | |
352 | figfilename = os.path.join(figpath,figfile) |
|
353 | figfilename = os.path.join(figpath,fig_file) | |
353 | self.sendByFTP(figfilename) |
|
354 | self.sendByFTP(figfilename) | |
354 |
|
355 | |||
355 | self.counter_imagwr = 0 |
|
356 | self.counter_imagwr = 0 | |
356 |
|
357 | |||
357 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
358 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: | |
358 | self.__isConfig = False |
|
359 | self.__isConfig = False | |
359 |
|
360 | |||
360 | class SpectraPlot(Figure): |
|
361 | class SpectraPlot(Figure): | |
361 |
|
362 | |||
362 | __isConfig = None |
|
363 | __isConfig = None | |
363 | __nsubplots = None |
|
364 | __nsubplots = None | |
364 |
|
365 | |||
365 | WIDTHPROF = None |
|
366 | WIDTHPROF = None | |
366 | HEIGHTPROF = None |
|
367 | HEIGHTPROF = None | |
367 | PREFIX = 'spc' |
|
368 | PREFIX = 'spc' | |
368 |
|
369 | |||
369 | def __init__(self): |
|
370 | def __init__(self): | |
370 |
|
371 | |||
371 | self.__isConfig = False |
|
372 | self.__isConfig = False | |
372 | self.__nsubplots = 1 |
|
373 | self.__nsubplots = 1 | |
373 |
|
374 | |||
374 | self.WIDTH = 230 |
|
375 | self.WIDTH = 230 | |
375 | self.HEIGHT = 250 |
|
376 | self.HEIGHT = 250 | |
376 | self.WIDTHPROF = 120 |
|
377 | self.WIDTHPROF = 120 | |
377 | self.HEIGHTPROF = 0 |
|
378 | self.HEIGHTPROF = 0 | |
|
379 | self.counter_imagwr = 0 | |||
378 |
|
380 | |||
379 | def getSubplots(self): |
|
381 | def getSubplots(self): | |
380 |
|
382 | |||
381 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
383 | ncol = int(numpy.sqrt(self.nplots)+0.9) | |
382 | nrow = int(self.nplots*1./ncol + 0.9) |
|
384 | nrow = int(self.nplots*1./ncol + 0.9) | |
383 |
|
385 | |||
384 | return nrow, ncol |
|
386 | return nrow, ncol | |
385 |
|
387 | |||
386 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
388 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
387 |
|
389 | |||
388 | self.__showprofile = showprofile |
|
390 | self.__showprofile = showprofile | |
389 | self.nplots = nplots |
|
391 | self.nplots = nplots | |
390 |
|
392 | |||
391 | ncolspan = 1 |
|
393 | ncolspan = 1 | |
392 | colspan = 1 |
|
394 | colspan = 1 | |
393 | if showprofile: |
|
395 | if showprofile: | |
394 | ncolspan = 3 |
|
396 | ncolspan = 3 | |
395 | colspan = 2 |
|
397 | colspan = 2 | |
396 | self.__nsubplots = 2 |
|
398 | self.__nsubplots = 2 | |
397 |
|
399 | |||
398 | self.createFigure(id = id, |
|
400 | self.createFigure(id = id, | |
399 | wintitle = wintitle, |
|
401 | wintitle = wintitle, | |
400 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
402 | widthplot = self.WIDTH + self.WIDTHPROF, | |
401 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
403 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
402 | show=show) |
|
404 | show=show) | |
403 |
|
405 | |||
404 | nrow, ncol = self.getSubplots() |
|
406 | nrow, ncol = self.getSubplots() | |
405 |
|
407 | |||
406 | counter = 0 |
|
408 | counter = 0 | |
407 | for y in range(nrow): |
|
409 | for y in range(nrow): | |
408 | for x in range(ncol): |
|
410 | for x in range(ncol): | |
409 |
|
411 | |||
410 | if counter >= self.nplots: |
|
412 | if counter >= self.nplots: | |
411 | break |
|
413 | break | |
412 |
|
414 | |||
413 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
415 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
414 |
|
416 | |||
415 | if showprofile: |
|
417 | if showprofile: | |
416 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
418 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
417 |
|
419 | |||
418 | counter += 1 |
|
420 | counter += 1 | |
419 |
|
421 | |||
420 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
422 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', | |
421 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
423 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
422 | save=False, figpath='./', figfile=None, show=True): |
|
424 | save=False, figpath='./', figfile=None, show=True, ftp=False, res_imagwr=1): | |
423 |
|
425 | |||
424 | """ |
|
426 | """ | |
425 |
|
427 | |||
426 | Input: |
|
428 | Input: | |
427 | dataOut : |
|
429 | dataOut : | |
428 | id : |
|
430 | id : | |
429 | wintitle : |
|
431 | wintitle : | |
430 | channelList : |
|
432 | channelList : | |
431 | showProfile : |
|
433 | showProfile : | |
432 | xmin : None, |
|
434 | xmin : None, | |
433 | xmax : None, |
|
435 | xmax : None, | |
434 | ymin : None, |
|
436 | ymin : None, | |
435 | ymax : None, |
|
437 | ymax : None, | |
436 | zmin : None, |
|
438 | zmin : None, | |
437 | zmax : None |
|
439 | zmax : None | |
438 | """ |
|
440 | """ | |
439 |
|
441 | |||
440 | if channelList == None: |
|
442 | if channelList == None: | |
441 | channelIndexList = dataOut.channelIndexList |
|
443 | channelIndexList = dataOut.channelIndexList | |
442 | else: |
|
444 | else: | |
443 | channelIndexList = [] |
|
445 | channelIndexList = [] | |
444 | for channel in channelList: |
|
446 | for channel in channelList: | |
445 | if channel not in dataOut.channelList: |
|
447 | if channel not in dataOut.channelList: | |
446 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
448 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
447 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
449 | channelIndexList.append(dataOut.channelList.index(channel)) | |
448 | factor = dataOut.normFactor |
|
450 | factor = dataOut.normFactor | |
449 | x = dataOut.getVelRange(1) |
|
451 | x = dataOut.getVelRange(1) | |
450 | y = dataOut.getHeiRange() |
|
452 | y = dataOut.getHeiRange() | |
451 |
|
453 | |||
452 | z = dataOut.data_spc[channelIndexList,:,:]/factor |
|
454 | z = dataOut.data_spc[channelIndexList,:,:]/factor | |
453 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
455 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
454 | avg = numpy.average(z, axis=1) |
|
456 | avg = numpy.average(z, axis=1) | |
455 | noise = dataOut.getNoise()/factor |
|
457 | noise = dataOut.getNoise()/factor | |
456 |
|
458 | |||
457 | zdB = 10*numpy.log10(z) |
|
459 | zdB = 10*numpy.log10(z) | |
458 | avgdB = 10*numpy.log10(avg) |
|
460 | avgdB = 10*numpy.log10(avg) | |
459 | noisedB = 10*numpy.log10(noise) |
|
461 | noisedB = 10*numpy.log10(noise) | |
460 |
|
462 | |||
461 | #thisDatetime = dataOut.datatime |
|
463 | #thisDatetime = dataOut.datatime | |
462 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
464 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
463 | title = wintitle + " Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
465 | title = wintitle + " Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
464 | xlabel = "Velocity (m/s)" |
|
466 | xlabel = "Velocity (m/s)" | |
465 | ylabel = "Range (Km)" |
|
467 | ylabel = "Range (Km)" | |
466 |
|
468 | |||
467 | if not self.__isConfig: |
|
469 | if not self.__isConfig: | |
468 |
|
470 | |||
469 | nplots = len(channelIndexList) |
|
471 | nplots = len(channelIndexList) | |
470 |
|
472 | |||
471 | self.setup(id=id, |
|
473 | self.setup(id=id, | |
472 | nplots=nplots, |
|
474 | nplots=nplots, | |
473 | wintitle=wintitle, |
|
475 | wintitle=wintitle, | |
474 | showprofile=showprofile, |
|
476 | showprofile=showprofile, | |
475 | show=show) |
|
477 | show=show) | |
476 |
|
478 | |||
477 | if xmin == None: xmin = numpy.nanmin(x) |
|
479 | if xmin == None: xmin = numpy.nanmin(x) | |
478 | if xmax == None: xmax = numpy.nanmax(x) |
|
480 | if xmax == None: xmax = numpy.nanmax(x) | |
479 | if ymin == None: ymin = numpy.nanmin(y) |
|
481 | if ymin == None: ymin = numpy.nanmin(y) | |
480 | if ymax == None: ymax = numpy.nanmax(y) |
|
482 | if ymax == None: ymax = numpy.nanmax(y) | |
481 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
483 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 | |
482 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
484 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 | |
483 |
|
485 | |||
484 | self.__isConfig = True |
|
486 | self.__isConfig = True | |
485 |
|
487 | |||
486 | self.setWinTitle(title) |
|
488 | self.setWinTitle(title) | |
487 |
|
489 | |||
488 | for i in range(self.nplots): |
|
490 | for i in range(self.nplots): | |
489 | title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i]) |
|
491 | title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i]) | |
490 | axes = self.axesList[i*self.__nsubplots] |
|
492 | axes = self.axesList[i*self.__nsubplots] | |
491 | axes.pcolor(x, y, zdB[i,:,:], |
|
493 | axes.pcolor(x, y, zdB[i,:,:], | |
492 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
494 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
493 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
495 | xlabel=xlabel, ylabel=ylabel, title=title, | |
494 | ticksize=9, cblabel='') |
|
496 | ticksize=9, cblabel='') | |
495 |
|
497 | |||
496 | if self.__showprofile: |
|
498 | if self.__showprofile: | |
497 | axes = self.axesList[i*self.__nsubplots +1] |
|
499 | axes = self.axesList[i*self.__nsubplots +1] | |
498 | axes.pline(avgdB[i], y, |
|
500 | axes.pline(avgdB[i], y, | |
499 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
501 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |
500 | xlabel='dB', ylabel='', title='', |
|
502 | xlabel='dB', ylabel='', title='', | |
501 | ytick_visible=False, |
|
503 | ytick_visible=False, | |
502 | grid='x') |
|
504 | grid='x') | |
503 |
|
505 | |||
504 | noiseline = numpy.repeat(noisedB[i], len(y)) |
|
506 | noiseline = numpy.repeat(noisedB[i], len(y)) | |
505 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) |
|
507 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) | |
506 |
|
508 | |||
507 | self.draw() |
|
509 | self.draw() | |
508 |
|
510 | |||
509 | if save: |
|
511 | if save: | |
510 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
512 | ||
511 | if figfile == None: |
|
513 | self.counter_imagwr += 1 | |
512 | figfile = self.getFilename(name = date) |
|
514 | if (self.counter_imagwr==res_imagwr): | |
513 |
|
515 | date = '%4d%3d00010000100'%(thisDatetime.timetuple().tm_year,thisDatetime.timetuple().tm_yday) | ||
514 | self.saveFigure(figpath, figfile) |
|
516 | ||
|
517 | fig_file = self.getFilename(name = date) | |||
|
518 | self.saveFigure(figpath, fig_file) | |||
|
519 | ||||
|
520 | if ftp: | |||
|
521 | # self.saveFigure(figpath, figfile) | |||
|
522 | figfilename = os.path.join(figpath,fig_file) | |||
|
523 | self.sendByFTP(figfilename) | |||
|
524 | ||||
|
525 | self.counter_imagwr = 0 | |||
|
526 | ||||
|
527 | ||||
|
528 | # if save: | |||
|
529 | # date = thisDatetime.strftime("%Y%m%d_%H%M%S") | |||
|
530 | # date = '%4d%3d00010000100'%(thisDatetime.timetuple().tm_year,thisDatetime.timetuple().tm_yday) | |||
|
531 | # if figfile == None: | |||
|
532 | # figfile = self.getFilename(name = date) | |||
|
533 | # | |||
|
534 | # self.saveFigure(figpath, figfile) | |||
515 |
|
535 | |||
516 | class Scope(Figure): |
|
536 | class Scope(Figure): | |
517 |
|
537 | |||
518 | __isConfig = None |
|
538 | __isConfig = None | |
519 |
|
539 | |||
520 | def __init__(self): |
|
540 | def __init__(self): | |
521 |
|
541 | |||
522 | self.__isConfig = False |
|
542 | self.__isConfig = False | |
523 | self.WIDTH = 600 |
|
543 | self.WIDTH = 600 | |
524 | self.HEIGHT = 200 |
|
544 | self.HEIGHT = 200 | |
525 |
|
545 | |||
526 | def getSubplots(self): |
|
546 | def getSubplots(self): | |
527 |
|
547 | |||
528 | nrow = self.nplots |
|
548 | nrow = self.nplots | |
529 | ncol = 3 |
|
549 | ncol = 3 | |
530 | return nrow, ncol |
|
550 | return nrow, ncol | |
531 |
|
551 | |||
532 | def setup(self, id, nplots, wintitle, show): |
|
552 | def setup(self, id, nplots, wintitle, show): | |
533 |
|
553 | |||
534 | self.nplots = nplots |
|
554 | self.nplots = nplots | |
535 |
|
555 | |||
536 | self.createFigure(id=id, |
|
556 | self.createFigure(id=id, | |
537 | wintitle=wintitle, |
|
557 | wintitle=wintitle, | |
538 | show=show) |
|
558 | show=show) | |
539 |
|
559 | |||
540 | nrow,ncol = self.getSubplots() |
|
560 | nrow,ncol = self.getSubplots() | |
541 | colspan = 3 |
|
561 | colspan = 3 | |
542 | rowspan = 1 |
|
562 | rowspan = 1 | |
543 |
|
563 | |||
544 | for i in range(nplots): |
|
564 | for i in range(nplots): | |
545 | self.addAxes(nrow, ncol, i, 0, colspan, rowspan) |
|
565 | self.addAxes(nrow, ncol, i, 0, colspan, rowspan) | |
546 |
|
566 | |||
547 |
|
567 | |||
548 |
|
568 | |||
549 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
569 | def run(self, dataOut, id, wintitle="", channelList=None, | |
550 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, |
|
570 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, | |
551 | figpath='./', figfile=None, show=True): |
|
571 | figpath='./', figfile=None, show=True): | |
552 |
|
572 | |||
553 | """ |
|
573 | """ | |
554 |
|
574 | |||
555 | Input: |
|
575 | Input: | |
556 | dataOut : |
|
576 | dataOut : | |
557 | id : |
|
577 | id : | |
558 | wintitle : |
|
578 | wintitle : | |
559 | channelList : |
|
579 | channelList : | |
560 | xmin : None, |
|
580 | xmin : None, | |
561 | xmax : None, |
|
581 | xmax : None, | |
562 | ymin : None, |
|
582 | ymin : None, | |
563 | ymax : None, |
|
583 | ymax : None, | |
564 | """ |
|
584 | """ | |
565 |
|
585 | |||
566 | if channelList == None: |
|
586 | if channelList == None: | |
567 | channelIndexList = dataOut.channelIndexList |
|
587 | channelIndexList = dataOut.channelIndexList | |
568 | else: |
|
588 | else: | |
569 | channelIndexList = [] |
|
589 | channelIndexList = [] | |
570 | for channel in channelList: |
|
590 | for channel in channelList: | |
571 | if channel not in dataOut.channelList: |
|
591 | if channel not in dataOut.channelList: | |
572 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
592 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
573 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
593 | channelIndexList.append(dataOut.channelList.index(channel)) | |
574 |
|
594 | |||
575 | x = dataOut.heightList |
|
595 | x = dataOut.heightList | |
576 | y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) |
|
596 | y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) | |
577 | y = y.real |
|
597 | y = y.real | |
578 |
|
598 | |||
579 | #thisDatetime = dataOut.datatime |
|
599 | #thisDatetime = dataOut.datatime | |
580 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
600 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
581 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
601 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
582 | xlabel = "Range (Km)" |
|
602 | xlabel = "Range (Km)" | |
583 | ylabel = "Intensity" |
|
603 | ylabel = "Intensity" | |
584 |
|
604 | |||
585 | if not self.__isConfig: |
|
605 | if not self.__isConfig: | |
586 | nplots = len(channelIndexList) |
|
606 | nplots = len(channelIndexList) | |
587 |
|
607 | |||
588 | self.setup(id=id, |
|
608 | self.setup(id=id, | |
589 | nplots=nplots, |
|
609 | nplots=nplots, | |
590 | wintitle=wintitle, |
|
610 | wintitle=wintitle, | |
591 | show=show) |
|
611 | show=show) | |
592 |
|
612 | |||
593 | if xmin == None: xmin = numpy.nanmin(x) |
|
613 | if xmin == None: xmin = numpy.nanmin(x) | |
594 | if xmax == None: xmax = numpy.nanmax(x) |
|
614 | if xmax == None: xmax = numpy.nanmax(x) | |
595 | if ymin == None: ymin = numpy.nanmin(y) |
|
615 | if ymin == None: ymin = numpy.nanmin(y) | |
596 | if ymax == None: ymax = numpy.nanmax(y) |
|
616 | if ymax == None: ymax = numpy.nanmax(y) | |
597 |
|
617 | |||
598 | self.__isConfig = True |
|
618 | self.__isConfig = True | |
599 |
|
619 | |||
600 | self.setWinTitle(title) |
|
620 | self.setWinTitle(title) | |
601 |
|
621 | |||
602 | for i in range(len(self.axesList)): |
|
622 | for i in range(len(self.axesList)): | |
603 | title = "Channel %d" %(i) |
|
623 | title = "Channel %d" %(i) | |
604 | axes = self.axesList[i] |
|
624 | axes = self.axesList[i] | |
605 | ychannel = y[i,:] |
|
625 | ychannel = y[i,:] | |
606 | axes.pline(x, ychannel, |
|
626 | axes.pline(x, ychannel, | |
607 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
627 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |
608 | xlabel=xlabel, ylabel=ylabel, title=title) |
|
628 | xlabel=xlabel, ylabel=ylabel, title=title) | |
609 |
|
629 | |||
610 | self.draw() |
|
630 | self.draw() | |
611 |
|
631 | |||
612 | if save: |
|
632 | if save: | |
613 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
633 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
614 | if figfile == None: |
|
634 | if figfile == None: | |
615 | figfile = self.getFilename(name = date) |
|
635 | figfile = self.getFilename(name = date) | |
616 |
|
636 | |||
617 | self.saveFigure(figpath, figfile) |
|
637 | self.saveFigure(figpath, figfile) | |
618 |
|
638 | |||
619 | class PowerProfilePlot(Figure): |
|
639 | class PowerProfilePlot(Figure): | |
620 | __isConfig = None |
|
640 | __isConfig = None | |
621 | __nsubplots = None |
|
641 | __nsubplots = None | |
622 |
|
642 | |||
623 | WIDTHPROF = None |
|
643 | WIDTHPROF = None | |
624 | HEIGHTPROF = None |
|
644 | HEIGHTPROF = None | |
625 | PREFIX = 'spcprofile' |
|
645 | PREFIX = 'spcprofile' | |
626 |
|
646 | |||
627 | def __init__(self): |
|
647 | def __init__(self): | |
628 | self.__isConfig = False |
|
648 | self.__isConfig = False | |
629 | self.__nsubplots = 1 |
|
649 | self.__nsubplots = 1 | |
630 |
|
650 | |||
631 | self.WIDTH = 300 |
|
651 | self.WIDTH = 300 | |
632 | self.HEIGHT = 500 |
|
652 | self.HEIGHT = 500 | |
633 |
|
653 | |||
634 | def getSubplots(self): |
|
654 | def getSubplots(self): | |
635 | ncol = 1 |
|
655 | ncol = 1 | |
636 | nrow = 1 |
|
656 | nrow = 1 | |
637 |
|
657 | |||
638 | return nrow, ncol |
|
658 | return nrow, ncol | |
639 |
|
659 | |||
640 | def setup(self, id, nplots, wintitle, show): |
|
660 | def setup(self, id, nplots, wintitle, show): | |
641 |
|
661 | |||
642 | self.nplots = nplots |
|
662 | self.nplots = nplots | |
643 |
|
663 | |||
644 | ncolspan = 1 |
|
664 | ncolspan = 1 | |
645 | colspan = 1 |
|
665 | colspan = 1 | |
646 |
|
666 | |||
647 | self.createFigure(id = id, |
|
667 | self.createFigure(id = id, | |
648 | wintitle = wintitle, |
|
668 | wintitle = wintitle, | |
649 | widthplot = self.WIDTH, |
|
669 | widthplot = self.WIDTH, | |
650 | heightplot = self.HEIGHT, |
|
670 | heightplot = self.HEIGHT, | |
651 | show=show) |
|
671 | show=show) | |
652 |
|
672 | |||
653 | nrow, ncol = self.getSubplots() |
|
673 | nrow, ncol = self.getSubplots() | |
654 |
|
674 | |||
655 | counter = 0 |
|
675 | counter = 0 | |
656 | for y in range(nrow): |
|
676 | for y in range(nrow): | |
657 | for x in range(ncol): |
|
677 | for x in range(ncol): | |
658 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
678 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
659 |
|
679 | |||
660 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
680 | def run(self, dataOut, id, wintitle="", channelList=None, | |
661 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
681 | xmin=None, xmax=None, ymin=None, ymax=None, | |
662 | save=False, figpath='./', figfile=None, show=True): |
|
682 | save=False, figpath='./', figfile=None, show=True): | |
663 |
|
683 | |||
664 | if channelList == None: |
|
684 | if channelList == None: | |
665 | channelIndexList = dataOut.channelIndexList |
|
685 | channelIndexList = dataOut.channelIndexList | |
666 | channelList = dataOut.channelList |
|
686 | channelList = dataOut.channelList | |
667 | else: |
|
687 | else: | |
668 | channelIndexList = [] |
|
688 | channelIndexList = [] | |
669 | for channel in channelList: |
|
689 | for channel in channelList: | |
670 | if channel not in dataOut.channelList: |
|
690 | if channel not in dataOut.channelList: | |
671 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
691 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
672 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
692 | channelIndexList.append(dataOut.channelList.index(channel)) | |
673 |
|
693 | |||
674 | factor = dataOut.normFactor |
|
694 | factor = dataOut.normFactor | |
675 | y = dataOut.getHeiRange() |
|
695 | y = dataOut.getHeiRange() | |
676 | x = dataOut.data_spc[channelIndexList,:,:]/factor |
|
696 | x = dataOut.data_spc[channelIndexList,:,:]/factor | |
677 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) |
|
697 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) | |
678 | avg = numpy.average(x, axis=1) |
|
698 | avg = numpy.average(x, axis=1) | |
679 |
|
699 | |||
680 | avgdB = 10*numpy.log10(avg) |
|
700 | avgdB = 10*numpy.log10(avg) | |
681 |
|
701 | |||
682 | #thisDatetime = dataOut.datatime |
|
702 | #thisDatetime = dataOut.datatime | |
683 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
703 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
684 | title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
704 | title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
685 | xlabel = "dB" |
|
705 | xlabel = "dB" | |
686 | ylabel = "Range (Km)" |
|
706 | ylabel = "Range (Km)" | |
687 |
|
707 | |||
688 | if not self.__isConfig: |
|
708 | if not self.__isConfig: | |
689 |
|
709 | |||
690 | nplots = 1 |
|
710 | nplots = 1 | |
691 |
|
711 | |||
692 | self.setup(id=id, |
|
712 | self.setup(id=id, | |
693 | nplots=nplots, |
|
713 | nplots=nplots, | |
694 | wintitle=wintitle, |
|
714 | wintitle=wintitle, | |
695 | show=show) |
|
715 | show=show) | |
696 |
|
716 | |||
697 | if ymin == None: ymin = numpy.nanmin(y) |
|
717 | if ymin == None: ymin = numpy.nanmin(y) | |
698 | if ymax == None: ymax = numpy.nanmax(y) |
|
718 | if ymax == None: ymax = numpy.nanmax(y) | |
699 | if xmin == None: xmin = numpy.nanmin(avgdB)*0.9 |
|
719 | if xmin == None: xmin = numpy.nanmin(avgdB)*0.9 | |
700 | if xmax == None: xmax = numpy.nanmax(avgdB)*0.9 |
|
720 | if xmax == None: xmax = numpy.nanmax(avgdB)*0.9 | |
701 |
|
721 | |||
702 | self.__isConfig = True |
|
722 | self.__isConfig = True | |
703 |
|
723 | |||
704 | self.setWinTitle(title) |
|
724 | self.setWinTitle(title) | |
705 |
|
725 | |||
706 |
|
726 | |||
707 | title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
727 | title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
708 | axes = self.axesList[0] |
|
728 | axes = self.axesList[0] | |
709 |
|
729 | |||
710 | legendlabels = ["channel %d"%x for x in channelList] |
|
730 | legendlabels = ["channel %d"%x for x in channelList] | |
711 | axes.pmultiline(avgdB, y, |
|
731 | axes.pmultiline(avgdB, y, | |
712 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
732 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |
713 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, |
|
733 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, | |
714 | ytick_visible=True, nxticks=5, |
|
734 | ytick_visible=True, nxticks=5, | |
715 | grid='x') |
|
735 | grid='x') | |
716 |
|
736 | |||
717 | self.draw() |
|
737 | self.draw() | |
718 |
|
738 | |||
719 | if save: |
|
739 | if save: | |
720 | date = thisDatetime.strftime("%Y%m%d") |
|
740 | date = thisDatetime.strftime("%Y%m%d") | |
721 | if figfile == None: |
|
741 | if figfile == None: | |
722 | figfile = self.getFilename(name = date) |
|
742 | figfile = self.getFilename(name = date) | |
723 |
|
743 | |||
724 | self.saveFigure(figpath, figfile) |
|
744 | self.saveFigure(figpath, figfile) | |
725 |
|
745 | |||
726 | class CoherenceMap(Figure): |
|
746 | class CoherenceMap(Figure): | |
727 | __isConfig = None |
|
747 | __isConfig = None | |
728 | __nsubplots = None |
|
748 | __nsubplots = None | |
729 |
|
749 | |||
730 | WIDTHPROF = None |
|
750 | WIDTHPROF = None | |
731 | HEIGHTPROF = None |
|
751 | HEIGHTPROF = None | |
732 | PREFIX = 'cmap' |
|
752 | PREFIX = 'cmap' | |
733 |
|
753 | |||
734 | def __init__(self): |
|
754 | def __init__(self): | |
735 | self.timerange = 2*60*60 |
|
755 | self.timerange = 2*60*60 | |
736 | self.__isConfig = False |
|
756 | self.__isConfig = False | |
737 | self.__nsubplots = 1 |
|
757 | self.__nsubplots = 1 | |
738 |
|
758 | |||
739 | self.WIDTH = 800 |
|
759 | self.WIDTH = 800 | |
740 | self.HEIGHT = 150 |
|
760 | self.HEIGHT = 150 | |
741 | self.WIDTHPROF = 120 |
|
761 | self.WIDTHPROF = 120 | |
742 | self.HEIGHTPROF = 0 |
|
762 | self.HEIGHTPROF = 0 | |
743 | self.counter_imagwr = 0 |
|
763 | self.counter_imagwr = 0 | |
744 |
|
764 | |||
745 | def getSubplots(self): |
|
765 | def getSubplots(self): | |
746 | ncol = 1 |
|
766 | ncol = 1 | |
747 | nrow = self.nplots*2 |
|
767 | nrow = self.nplots*2 | |
748 |
|
768 | |||
749 | return nrow, ncol |
|
769 | return nrow, ncol | |
750 |
|
770 | |||
751 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
771 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
752 | self.__showprofile = showprofile |
|
772 | self.__showprofile = showprofile | |
753 | self.nplots = nplots |
|
773 | self.nplots = nplots | |
754 |
|
774 | |||
755 | ncolspan = 1 |
|
775 | ncolspan = 1 | |
756 | colspan = 1 |
|
776 | colspan = 1 | |
757 | if showprofile: |
|
777 | if showprofile: | |
758 | ncolspan = 7 |
|
778 | ncolspan = 7 | |
759 | colspan = 6 |
|
779 | colspan = 6 | |
760 | self.__nsubplots = 2 |
|
780 | self.__nsubplots = 2 | |
761 |
|
781 | |||
762 | self.createFigure(id = id, |
|
782 | self.createFigure(id = id, | |
763 | wintitle = wintitle, |
|
783 | wintitle = wintitle, | |
764 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
784 | widthplot = self.WIDTH + self.WIDTHPROF, | |
765 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
785 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
766 | show=True) |
|
786 | show=True) | |
767 |
|
787 | |||
768 | nrow, ncol = self.getSubplots() |
|
788 | nrow, ncol = self.getSubplots() | |
769 |
|
789 | |||
770 | for y in range(nrow): |
|
790 | for y in range(nrow): | |
771 | for x in range(ncol): |
|
791 | for x in range(ncol): | |
772 |
|
792 | |||
773 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
793 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
774 |
|
794 | |||
775 | if showprofile: |
|
795 | if showprofile: | |
776 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
796 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
777 |
|
797 | |||
778 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', |
|
798 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', | |
779 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
799 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
780 | timerange=None, |
|
800 | timerange=None, | |
781 | save=False, figpath='./', figfile=None, ftp=False, res_imagwr=1, |
|
801 | save=False, figpath='./', figfile=None, ftp=False, res_imagwr=1, | |
782 | coherence_cmap='jet', phase_cmap='RdBu_r', show=True): |
|
802 | coherence_cmap='jet', phase_cmap='RdBu_r', show=True): | |
783 |
|
803 | |||
784 | if pairsList == None: |
|
804 | if pairsList == None: | |
785 | pairsIndexList = dataOut.pairsIndexList |
|
805 | pairsIndexList = dataOut.pairsIndexList | |
786 | else: |
|
806 | else: | |
787 | pairsIndexList = [] |
|
807 | pairsIndexList = [] | |
788 | for pair in pairsList: |
|
808 | for pair in pairsList: | |
789 | if pair not in dataOut.pairsList: |
|
809 | if pair not in dataOut.pairsList: | |
790 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
810 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) | |
791 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
811 | pairsIndexList.append(dataOut.pairsList.index(pair)) | |
792 |
|
812 | |||
793 | if timerange != None: |
|
813 | if timerange != None: | |
794 | self.timerange = timerange |
|
814 | self.timerange = timerange | |
795 |
|
815 | |||
796 | if pairsIndexList == []: |
|
816 | if pairsIndexList == []: | |
797 | return |
|
817 | return | |
798 |
|
818 | |||
799 | if len(pairsIndexList) > 4: |
|
819 | if len(pairsIndexList) > 4: | |
800 | pairsIndexList = pairsIndexList[0:4] |
|
820 | pairsIndexList = pairsIndexList[0:4] | |
801 |
|
821 | |||
802 | tmin = None |
|
822 | tmin = None | |
803 | tmax = None |
|
823 | tmax = None | |
804 | x = dataOut.getTimeRange() |
|
824 | x = dataOut.getTimeRange() | |
805 | y = dataOut.getHeiRange() |
|
825 | y = dataOut.getHeiRange() | |
806 |
|
826 | |||
807 | #thisDatetime = dataOut.datatime |
|
827 | #thisDatetime = dataOut.datatime | |
808 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
828 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
809 | title = wintitle + " CoherenceMap: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
829 | title = wintitle + " CoherenceMap: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
810 | xlabel = "" |
|
830 | xlabel = "" | |
811 | ylabel = "Range (Km)" |
|
831 | ylabel = "Range (Km)" | |
812 |
|
832 | |||
813 | if not self.__isConfig: |
|
833 | if not self.__isConfig: | |
814 | nplots = len(pairsIndexList) |
|
834 | nplots = len(pairsIndexList) | |
815 | self.setup(id=id, |
|
835 | self.setup(id=id, | |
816 | nplots=nplots, |
|
836 | nplots=nplots, | |
817 | wintitle=wintitle, |
|
837 | wintitle=wintitle, | |
818 | showprofile=showprofile, |
|
838 | showprofile=showprofile, | |
819 | show=show) |
|
839 | show=show) | |
820 |
|
840 | |||
821 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
841 | tmin, tmax = self.getTimeLim(x, xmin, xmax) | |
822 | if ymin == None: ymin = numpy.nanmin(y) |
|
842 | if ymin == None: ymin = numpy.nanmin(y) | |
823 | if ymax == None: ymax = numpy.nanmax(y) |
|
843 | if ymax == None: ymax = numpy.nanmax(y) | |
824 | if zmin == None: zmin = 0. |
|
844 | if zmin == None: zmin = 0. | |
825 | if zmax == None: zmax = 1. |
|
845 | if zmax == None: zmax = 1. | |
826 |
|
846 | |||
827 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
847 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
828 |
|
848 | |||
829 | self.__isConfig = True |
|
849 | self.__isConfig = True | |
830 |
|
850 | |||
831 | self.setWinTitle(title) |
|
851 | self.setWinTitle(title) | |
832 |
|
852 | |||
833 | for i in range(self.nplots): |
|
853 | for i in range(self.nplots): | |
834 |
|
854 | |||
835 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
855 | pair = dataOut.pairsList[pairsIndexList[i]] | |
836 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) |
|
856 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) | |
837 | avgcoherenceComplex = numpy.average(coherenceComplex, axis=0) |
|
857 | avgcoherenceComplex = numpy.average(coherenceComplex, axis=0) | |
838 | coherence = numpy.abs(avgcoherenceComplex) |
|
858 | coherence = numpy.abs(avgcoherenceComplex) | |
839 | # coherence = numpy.abs(coherenceComplex) |
|
859 | # coherence = numpy.abs(coherenceComplex) | |
840 | # avg = numpy.average(coherence, axis=0) |
|
860 | # avg = numpy.average(coherence, axis=0) | |
841 |
|
861 | |||
842 | z = coherence.reshape((1,-1)) |
|
862 | z = coherence.reshape((1,-1)) | |
843 |
|
863 | |||
844 | counter = 0 |
|
864 | counter = 0 | |
845 |
|
865 | |||
846 | title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
866 | title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
847 | axes = self.axesList[i*self.__nsubplots*2] |
|
867 | axes = self.axesList[i*self.__nsubplots*2] | |
848 | axes.pcolorbuffer(x, y, z, |
|
868 | axes.pcolorbuffer(x, y, z, | |
849 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
869 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
850 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
870 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
851 | ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%") |
|
871 | ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%") | |
852 |
|
872 | |||
853 | if self.__showprofile: |
|
873 | if self.__showprofile: | |
854 | counter += 1 |
|
874 | counter += 1 | |
855 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
875 | axes = self.axesList[i*self.__nsubplots*2 + counter] | |
856 | axes.pline(coherence, y, |
|
876 | axes.pline(coherence, y, | |
857 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
877 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |
858 | xlabel='', ylabel='', title='', ticksize=7, |
|
878 | xlabel='', ylabel='', title='', ticksize=7, | |
859 | ytick_visible=False, nxticks=5, |
|
879 | ytick_visible=False, nxticks=5, | |
860 | grid='x') |
|
880 | grid='x') | |
861 |
|
881 | |||
862 | counter += 1 |
|
882 | counter += 1 | |
863 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi |
|
883 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi | |
864 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi |
|
884 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi | |
865 | # avg = numpy.average(phase, axis=0) |
|
885 | # avg = numpy.average(phase, axis=0) | |
866 | z = phase.reshape((1,-1)) |
|
886 | z = phase.reshape((1,-1)) | |
867 |
|
887 | |||
868 | title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
888 | title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
869 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
889 | axes = self.axesList[i*self.__nsubplots*2 + counter] | |
870 | axes.pcolorbuffer(x, y, z, |
|
890 | axes.pcolorbuffer(x, y, z, | |
871 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, |
|
891 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, | |
872 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
892 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
873 | ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%") |
|
893 | ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%") | |
874 |
|
894 | |||
875 | if self.__showprofile: |
|
895 | if self.__showprofile: | |
876 | counter += 1 |
|
896 | counter += 1 | |
877 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
897 | axes = self.axesList[i*self.__nsubplots*2 + counter] | |
878 | axes.pline(phase, y, |
|
898 | axes.pline(phase, y, | |
879 | xmin=-180, xmax=180, ymin=ymin, ymax=ymax, |
|
899 | xmin=-180, xmax=180, ymin=ymin, ymax=ymax, | |
880 | xlabel='', ylabel='', title='', ticksize=7, |
|
900 | xlabel='', ylabel='', title='', ticksize=7, | |
881 | ytick_visible=False, nxticks=4, |
|
901 | ytick_visible=False, nxticks=4, | |
882 | grid='x') |
|
902 | grid='x') | |
883 |
|
903 | |||
884 | self.draw() |
|
904 | self.draw() | |
885 |
|
905 | |||
886 | if save: |
|
906 | if save: | |
887 |
|
907 | |||
888 | self.counter_imagwr += 1 |
|
908 | self.counter_imagwr += 1 | |
889 | if (self.counter_imagwr==res_imagwr): |
|
909 | if (self.counter_imagwr==res_imagwr): | |
890 | fig_file = self.getFilename(name = self.name) |
|
910 | fig_file = self.getFilename(name = self.name) | |
891 | self.saveFigure(figpath, fig_file) |
|
911 | self.saveFigure(figpath, fig_file) | |
892 | if ftp: |
|
912 | if ftp: | |
893 | self.saveFigure(figpath, figfile) |
|
913 | self.saveFigure(figpath, figfile) | |
894 | figfilename = os.path.join(figpath,figfile) |
|
914 | figfilename = os.path.join(figpath,figfile) | |
895 | self.sendByFTP(figfilename) |
|
915 | self.sendByFTP(figfilename) | |
896 |
|
916 | |||
897 | self.counter_imagwr = 0 |
|
917 | self.counter_imagwr = 0 | |
898 |
|
918 | |||
899 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
919 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: | |
900 | self.__isConfig = False |
|
920 | self.__isConfig = False | |
901 |
|
921 | |||
902 | class RTIfromNoise(Figure): |
|
922 | class RTIfromNoise(Figure): | |
903 |
|
923 | |||
904 | __isConfig = None |
|
924 | __isConfig = None | |
905 | __nsubplots = None |
|
925 | __nsubplots = None | |
906 |
|
926 | |||
907 | PREFIX = 'rtinoise' |
|
927 | PREFIX = 'rtinoise' | |
908 |
|
928 | |||
909 | def __init__(self): |
|
929 | def __init__(self): | |
910 |
|
930 | |||
911 | self.timerange = 24*60*60 |
|
931 | self.timerange = 24*60*60 | |
912 | self.__isConfig = False |
|
932 | self.__isConfig = False | |
913 | self.__nsubplots = 1 |
|
933 | self.__nsubplots = 1 | |
914 |
|
934 | |||
915 | self.WIDTH = 820 |
|
935 | self.WIDTH = 820 | |
916 | self.HEIGHT = 200 |
|
936 | self.HEIGHT = 200 | |
917 | self.WIDTHPROF = 120 |
|
937 | self.WIDTHPROF = 120 | |
918 | self.HEIGHTPROF = 0 |
|
938 | self.HEIGHTPROF = 0 | |
919 | self.xdata = None |
|
939 | self.xdata = None | |
920 | self.ydata = None |
|
940 | self.ydata = None | |
921 |
|
941 | |||
922 | def getSubplots(self): |
|
942 | def getSubplots(self): | |
923 |
|
943 | |||
924 | ncol = 1 |
|
944 | ncol = 1 | |
925 | nrow = 1 |
|
945 | nrow = 1 | |
926 |
|
946 | |||
927 | return nrow, ncol |
|
947 | return nrow, ncol | |
928 |
|
948 | |||
929 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
949 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
930 |
|
950 | |||
931 | self.__showprofile = showprofile |
|
951 | self.__showprofile = showprofile | |
932 | self.nplots = nplots |
|
952 | self.nplots = nplots | |
933 |
|
953 | |||
934 | ncolspan = 7 |
|
954 | ncolspan = 7 | |
935 | colspan = 6 |
|
955 | colspan = 6 | |
936 | self.__nsubplots = 2 |
|
956 | self.__nsubplots = 2 | |
937 |
|
957 | |||
938 | self.createFigure(id = id, |
|
958 | self.createFigure(id = id, | |
939 | wintitle = wintitle, |
|
959 | wintitle = wintitle, | |
940 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
960 | widthplot = self.WIDTH+self.WIDTHPROF, | |
941 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
961 | heightplot = self.HEIGHT+self.HEIGHTPROF, | |
942 | show=show) |
|
962 | show=show) | |
943 |
|
963 | |||
944 | nrow, ncol = self.getSubplots() |
|
964 | nrow, ncol = self.getSubplots() | |
945 |
|
965 | |||
946 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
966 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) | |
947 |
|
967 | |||
948 |
|
968 | |||
949 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
969 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', | |
950 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
970 | xmin=None, xmax=None, ymin=None, ymax=None, | |
951 | timerange=None, |
|
971 | timerange=None, | |
952 | save=False, figpath='./', figfile=None, show=True): |
|
972 | save=False, figpath='./', figfile=None, show=True): | |
953 |
|
973 | |||
954 | if channelList == None: |
|
974 | if channelList == None: | |
955 | channelIndexList = dataOut.channelIndexList |
|
975 | channelIndexList = dataOut.channelIndexList | |
956 | channelList = dataOut.channelList |
|
976 | channelList = dataOut.channelList | |
957 | else: |
|
977 | else: | |
958 | channelIndexList = [] |
|
978 | channelIndexList = [] | |
959 | for channel in channelList: |
|
979 | for channel in channelList: | |
960 | if channel not in dataOut.channelList: |
|
980 | if channel not in dataOut.channelList: | |
961 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
981 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
962 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
982 | channelIndexList.append(dataOut.channelList.index(channel)) | |
963 |
|
983 | |||
964 | if timerange != None: |
|
984 | if timerange != None: | |
965 | self.timerange = timerange |
|
985 | self.timerange = timerange | |
966 |
|
986 | |||
967 | tmin = None |
|
987 | tmin = None | |
968 | tmax = None |
|
988 | tmax = None | |
969 | x = dataOut.getTimeRange() |
|
989 | x = dataOut.getTimeRange() | |
970 | y = dataOut.getHeiRange() |
|
990 | y = dataOut.getHeiRange() | |
971 | factor = dataOut.normFactor |
|
991 | factor = dataOut.normFactor | |
972 | noise = dataOut.getNoise()/factor |
|
992 | noise = dataOut.getNoise()/factor | |
973 | noisedB = 10*numpy.log10(noise) |
|
993 | noisedB = 10*numpy.log10(noise) | |
974 |
|
994 | |||
975 | #thisDatetime = dataOut.datatime |
|
995 | #thisDatetime = dataOut.datatime | |
976 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
996 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
977 | title = wintitle + " RTI Noise: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
997 | title = wintitle + " RTI Noise: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
978 | xlabel = "" |
|
998 | xlabel = "" | |
979 | ylabel = "Range (Km)" |
|
999 | ylabel = "Range (Km)" | |
980 |
|
1000 | |||
981 | if not self.__isConfig: |
|
1001 | if not self.__isConfig: | |
982 |
|
1002 | |||
983 | nplots = 1 |
|
1003 | nplots = 1 | |
984 |
|
1004 | |||
985 | self.setup(id=id, |
|
1005 | self.setup(id=id, | |
986 | nplots=nplots, |
|
1006 | nplots=nplots, | |
987 | wintitle=wintitle, |
|
1007 | wintitle=wintitle, | |
988 | showprofile=showprofile, |
|
1008 | showprofile=showprofile, | |
989 | show=show) |
|
1009 | show=show) | |
990 |
|
1010 | |||
991 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
1011 | tmin, tmax = self.getTimeLim(x, xmin, xmax) | |
992 | if ymin == None: ymin = numpy.nanmin(noisedB) |
|
1012 | if ymin == None: ymin = numpy.nanmin(noisedB) | |
993 | if ymax == None: ymax = numpy.nanmax(noisedB) |
|
1013 | if ymax == None: ymax = numpy.nanmax(noisedB) | |
994 |
|
1014 | |||
995 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1015 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
996 | self.__isConfig = True |
|
1016 | self.__isConfig = True | |
997 |
|
1017 | |||
998 | self.xdata = numpy.array([]) |
|
1018 | self.xdata = numpy.array([]) | |
999 | self.ydata = numpy.array([]) |
|
1019 | self.ydata = numpy.array([]) | |
1000 |
|
1020 | |||
1001 | self.setWinTitle(title) |
|
1021 | self.setWinTitle(title) | |
1002 |
|
1022 | |||
1003 |
|
1023 | |||
1004 | title = "RTI Noise %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1024 | title = "RTI Noise %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
1005 |
|
1025 | |||
1006 | legendlabels = ["channel %d"%idchannel for idchannel in channelList] |
|
1026 | legendlabels = ["channel %d"%idchannel for idchannel in channelList] | |
1007 | axes = self.axesList[0] |
|
1027 | axes = self.axesList[0] | |
1008 |
|
1028 | |||
1009 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1029 | self.xdata = numpy.hstack((self.xdata, x[0:1])) | |
1010 |
|
1030 | |||
1011 | if len(self.ydata)==0: |
|
1031 | if len(self.ydata)==0: | |
1012 | self.ydata = noisedB[channelIndexList].reshape(-1,1) |
|
1032 | self.ydata = noisedB[channelIndexList].reshape(-1,1) | |
1013 | else: |
|
1033 | else: | |
1014 | self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1))) |
|
1034 | self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1))) | |
1015 |
|
1035 | |||
1016 |
|
1036 | |||
1017 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1037 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, | |
1018 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, |
|
1038 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, | |
1019 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
1039 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", | |
1020 | XAxisAsTime=True |
|
1040 | XAxisAsTime=True | |
1021 | ) |
|
1041 | ) | |
1022 |
|
1042 | |||
1023 | self.draw() |
|
1043 | self.draw() | |
1024 |
|
1044 | |||
1025 | if save: |
|
1045 | if save: | |
1026 |
|
1046 | |||
1027 | if figfile == None: |
|
1047 | if figfile == None: | |
1028 | figfile = self.getFilename(name = self.name) |
|
1048 | figfile = self.getFilename(name = self.name) | |
1029 |
|
1049 | |||
1030 | self.saveFigure(figpath, figfile) |
|
1050 | self.saveFigure(figpath, figfile) | |
1031 |
|
1051 | |||
1032 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
1052 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: | |
1033 | self.__isConfig = False |
|
1053 | self.__isConfig = False | |
1034 | del self.xdata |
|
1054 | del self.xdata | |
1035 | del self.ydata |
|
1055 | del self.ydata | |
1036 |
|
1056 | |||
1037 |
|
1057 | |||
1038 | class SpectraHeisScope(Figure): |
|
1058 | class SpectraHeisScope(Figure): | |
1039 |
|
1059 | |||
1040 |
|
1060 | |||
1041 | __isConfig = None |
|
1061 | __isConfig = None | |
1042 | __nsubplots = None |
|
1062 | __nsubplots = None | |
1043 |
|
1063 | |||
1044 | WIDTHPROF = None |
|
1064 | WIDTHPROF = None | |
1045 | HEIGHTPROF = None |
|
1065 | HEIGHTPROF = None | |
1046 | PREFIX = 'spc' |
|
1066 | PREFIX = 'spc' | |
1047 |
|
1067 | |||
1048 | def __init__(self): |
|
1068 | def __init__(self): | |
1049 |
|
1069 | |||
1050 | self.__isConfig = False |
|
1070 | self.__isConfig = False | |
1051 | self.__nsubplots = 1 |
|
1071 | self.__nsubplots = 1 | |
1052 |
|
1072 | |||
1053 | self.WIDTH = 230 |
|
1073 | self.WIDTH = 230 | |
1054 | self.HEIGHT = 250 |
|
1074 | self.HEIGHT = 250 | |
1055 | self.WIDTHPROF = 120 |
|
1075 | self.WIDTHPROF = 120 | |
1056 | self.HEIGHTPROF = 0 |
|
1076 | self.HEIGHTPROF = 0 | |
1057 | self.counter_imagwr = 0 |
|
1077 | self.counter_imagwr = 0 | |
1058 |
|
1078 | |||
1059 | def getSubplots(self): |
|
1079 | def getSubplots(self): | |
1060 |
|
1080 | |||
1061 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
1081 | ncol = int(numpy.sqrt(self.nplots)+0.9) | |
1062 | nrow = int(self.nplots*1./ncol + 0.9) |
|
1082 | nrow = int(self.nplots*1./ncol + 0.9) | |
1063 |
|
1083 | |||
1064 | return nrow, ncol |
|
1084 | return nrow, ncol | |
1065 |
|
1085 | |||
1066 | def setup(self, id, nplots, wintitle, show): |
|
1086 | def setup(self, id, nplots, wintitle, show): | |
1067 |
|
1087 | |||
1068 | showprofile = False |
|
1088 | showprofile = False | |
1069 | self.__showprofile = showprofile |
|
1089 | self.__showprofile = showprofile | |
1070 | self.nplots = nplots |
|
1090 | self.nplots = nplots | |
1071 |
|
1091 | |||
1072 | ncolspan = 1 |
|
1092 | ncolspan = 1 | |
1073 | colspan = 1 |
|
1093 | colspan = 1 | |
1074 | if showprofile: |
|
1094 | if showprofile: | |
1075 | ncolspan = 3 |
|
1095 | ncolspan = 3 | |
1076 | colspan = 2 |
|
1096 | colspan = 2 | |
1077 | self.__nsubplots = 2 |
|
1097 | self.__nsubplots = 2 | |
1078 |
|
1098 | |||
1079 | self.createFigure(id = id, |
|
1099 | self.createFigure(id = id, | |
1080 | wintitle = wintitle, |
|
1100 | wintitle = wintitle, | |
1081 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
1101 | widthplot = self.WIDTH + self.WIDTHPROF, | |
1082 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
1102 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
1083 | show = show) |
|
1103 | show = show) | |
1084 |
|
1104 | |||
1085 | nrow, ncol = self.getSubplots() |
|
1105 | nrow, ncol = self.getSubplots() | |
1086 |
|
1106 | |||
1087 | counter = 0 |
|
1107 | counter = 0 | |
1088 | for y in range(nrow): |
|
1108 | for y in range(nrow): | |
1089 | for x in range(ncol): |
|
1109 | for x in range(ncol): | |
1090 |
|
1110 | |||
1091 | if counter >= self.nplots: |
|
1111 | if counter >= self.nplots: | |
1092 | break |
|
1112 | break | |
1093 |
|
1113 | |||
1094 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
1114 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
1095 |
|
1115 | |||
1096 | if showprofile: |
|
1116 | if showprofile: | |
1097 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
1117 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
1098 |
|
1118 | |||
1099 | counter += 1 |
|
1119 | counter += 1 | |
1100 |
|
1120 | |||
1101 | # __isConfig = None |
|
1121 | # __isConfig = None | |
1102 | # def __init__(self): |
|
1122 | # def __init__(self): | |
1103 | # |
|
1123 | # | |
1104 | # self.__isConfig = False |
|
1124 | # self.__isConfig = False | |
1105 | # self.WIDTH = 600 |
|
1125 | # self.WIDTH = 600 | |
1106 | # self.HEIGHT = 200 |
|
1126 | # self.HEIGHT = 200 | |
1107 | # |
|
1127 | # | |
1108 | # def getSubplots(self): |
|
1128 | # def getSubplots(self): | |
1109 | # |
|
1129 | # | |
1110 | # nrow = self.nplots |
|
1130 | # nrow = self.nplots | |
1111 | # ncol = 3 |
|
1131 | # ncol = 3 | |
1112 | # return nrow, ncol |
|
1132 | # return nrow, ncol | |
1113 | # |
|
1133 | # | |
1114 | # def setup(self, id, nplots, wintitle): |
|
1134 | # def setup(self, id, nplots, wintitle): | |
1115 | # |
|
1135 | # | |
1116 | # self.nplots = nplots |
|
1136 | # self.nplots = nplots | |
1117 | # |
|
1137 | # | |
1118 | # self.createFigure(id, wintitle) |
|
1138 | # self.createFigure(id, wintitle) | |
1119 | # |
|
1139 | # | |
1120 | # nrow,ncol = self.getSubplots() |
|
1140 | # nrow,ncol = self.getSubplots() | |
1121 | # colspan = 3 |
|
1141 | # colspan = 3 | |
1122 | # rowspan = 1 |
|
1142 | # rowspan = 1 | |
1123 | # |
|
1143 | # | |
1124 | # for i in range(nplots): |
|
1144 | # for i in range(nplots): | |
1125 | # self.addAxes(nrow, ncol, i, 0, colspan, rowspan) |
|
1145 | # self.addAxes(nrow, ncol, i, 0, colspan, rowspan) | |
1126 |
|
1146 | |||
1127 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
1147 | def run(self, dataOut, id, wintitle="", channelList=None, | |
1128 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, |
|
1148 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, | |
1129 | figpath='./', figfile=None, ftp=False, res_imagwr=1, show=True): |
|
1149 | figpath='./', figfile=None, ftp=False, res_imagwr=1, show=True): | |
1130 |
|
1150 | |||
1131 | """ |
|
1151 | """ | |
1132 |
|
1152 | |||
1133 | Input: |
|
1153 | Input: | |
1134 | dataOut : |
|
1154 | dataOut : | |
1135 | id : |
|
1155 | id : | |
1136 | wintitle : |
|
1156 | wintitle : | |
1137 | channelList : |
|
1157 | channelList : | |
1138 | xmin : None, |
|
1158 | xmin : None, | |
1139 | xmax : None, |
|
1159 | xmax : None, | |
1140 | ymin : None, |
|
1160 | ymin : None, | |
1141 | ymax : None, |
|
1161 | ymax : None, | |
1142 | """ |
|
1162 | """ | |
1143 |
|
1163 | |||
1144 | if dataOut.realtime: |
|
1164 | if dataOut.realtime: | |
1145 | if not(isRealtime(utcdatatime = dataOut.utctime)): |
|
1165 | if not(isRealtime(utcdatatime = dataOut.utctime)): | |
1146 | print 'Skipping this plot function' |
|
1166 | print 'Skipping this plot function' | |
1147 | return |
|
1167 | return | |
1148 |
|
1168 | |||
1149 | if channelList == None: |
|
1169 | if channelList == None: | |
1150 | channelIndexList = dataOut.channelIndexList |
|
1170 | channelIndexList = dataOut.channelIndexList | |
1151 | else: |
|
1171 | else: | |
1152 | channelIndexList = [] |
|
1172 | channelIndexList = [] | |
1153 | for channel in channelList: |
|
1173 | for channel in channelList: | |
1154 | if channel not in dataOut.channelList: |
|
1174 | if channel not in dataOut.channelList: | |
1155 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
1175 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
1156 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1176 | channelIndexList.append(dataOut.channelList.index(channel)) | |
1157 |
|
1177 | |||
1158 | # x = dataOut.heightList |
|
1178 | # x = dataOut.heightList | |
1159 | c = 3E8 |
|
1179 | c = 3E8 | |
1160 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1180 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1161 | #deberia cambiar para el caso de 1Mhz y 100KHz |
|
1181 | #deberia cambiar para el caso de 1Mhz y 100KHz | |
1162 | x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000)) |
|
1182 | x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000)) | |
1163 | x= x/(10000.0) |
|
1183 | x= x/(10000.0) | |
1164 | # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) |
|
1184 | # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) | |
1165 | # y = y.real |
|
1185 | # y = y.real | |
1166 | datadB = 10.*numpy.log10(dataOut.data_spc) |
|
1186 | datadB = 10.*numpy.log10(dataOut.data_spc) | |
1167 | y = datadB |
|
1187 | y = datadB | |
1168 |
|
1188 | |||
1169 | #thisDatetime = dataOut.datatime |
|
1189 | #thisDatetime = dataOut.datatime | |
1170 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
1190 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
1171 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
1191 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
1172 | xlabel = "Frequency x 10000" |
|
1192 | xlabel = "Frequency x 10000" | |
1173 | ylabel = "Intensity (dB)" |
|
1193 | ylabel = "Intensity (dB)" | |
1174 |
|
1194 | |||
1175 | if not self.__isConfig: |
|
1195 | if not self.__isConfig: | |
1176 | nplots = len(channelIndexList) |
|
1196 | nplots = len(channelIndexList) | |
1177 |
|
1197 | |||
1178 | self.setup(id=id, |
|
1198 | self.setup(id=id, | |
1179 | nplots=nplots, |
|
1199 | nplots=nplots, | |
1180 | wintitle=wintitle, |
|
1200 | wintitle=wintitle, | |
1181 | show=show) |
|
1201 | show=show) | |
1182 |
|
1202 | |||
1183 | if xmin == None: xmin = numpy.nanmin(x) |
|
1203 | if xmin == None: xmin = numpy.nanmin(x) | |
1184 | if xmax == None: xmax = numpy.nanmax(x) |
|
1204 | if xmax == None: xmax = numpy.nanmax(x) | |
1185 | if ymin == None: ymin = numpy.nanmin(y) |
|
1205 | if ymin == None: ymin = numpy.nanmin(y) | |
1186 | if ymax == None: ymax = numpy.nanmax(y) |
|
1206 | if ymax == None: ymax = numpy.nanmax(y) | |
1187 |
|
1207 | |||
1188 | self.__isConfig = True |
|
1208 | self.__isConfig = True | |
1189 |
|
1209 | |||
1190 | self.setWinTitle(title) |
|
1210 | self.setWinTitle(title) | |
1191 |
|
1211 | |||
1192 | for i in range(len(self.axesList)): |
|
1212 | for i in range(len(self.axesList)): | |
1193 | ychannel = y[i,:] |
|
1213 | ychannel = y[i,:] | |
1194 | title = "Channel %d - peak:%.2f" %(i,numpy.max(ychannel)) |
|
1214 | title = "Channel %d - peak:%.2f" %(i,numpy.max(ychannel)) | |
1195 | axes = self.axesList[i] |
|
1215 | axes = self.axesList[i] | |
1196 | axes.pline(x, ychannel, |
|
1216 | axes.pline(x, ychannel, | |
1197 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
1217 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |
1198 | xlabel=xlabel, ylabel=ylabel, title=title, grid='both') |
|
1218 | xlabel=xlabel, ylabel=ylabel, title=title, grid='both') | |
1199 |
|
1219 | |||
1200 |
|
1220 | |||
1201 | self.draw() |
|
1221 | self.draw() | |
1202 |
|
1222 | |||
1203 | if save: |
|
1223 | if save: | |
1204 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1224 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
1205 | if figfile == None: |
|
1225 | if figfile == None: | |
1206 | figfile = self.getFilename(name = date) |
|
1226 | figfile = self.getFilename(name = date) | |
1207 |
|
1227 | |||
1208 | self.saveFigure(figpath, figfile) |
|
1228 | self.saveFigure(figpath, figfile) | |
1209 |
|
1229 | |||
1210 | self.counter_imagwr += 1 |
|
1230 | self.counter_imagwr += 1 | |
1211 | if (ftp and (self.counter_imagwr==res_imagwr)): |
|
1231 | if (ftp and (self.counter_imagwr==res_imagwr)): | |
1212 | figfilename = os.path.join(figpath,figfile) |
|
1232 | figfilename = os.path.join(figpath,figfile) | |
1213 | self.sendByFTP(figfilename) |
|
1233 | self.sendByFTP(figfilename) | |
1214 | self.counter_imagwr = 0 |
|
1234 | self.counter_imagwr = 0 | |
1215 |
|
1235 | |||
1216 |
|
1236 | |||
1217 | class RTIfromSpectraHeis(Figure): |
|
1237 | class RTIfromSpectraHeis(Figure): | |
1218 |
|
1238 | |||
1219 | __isConfig = None |
|
1239 | __isConfig = None | |
1220 | __nsubplots = None |
|
1240 | __nsubplots = None | |
1221 |
|
1241 | |||
1222 | PREFIX = 'rtinoise' |
|
1242 | PREFIX = 'rtinoise' | |
1223 |
|
1243 | |||
1224 | def __init__(self): |
|
1244 | def __init__(self): | |
1225 |
|
1245 | |||
1226 | self.timerange = 24*60*60 |
|
1246 | self.timerange = 24*60*60 | |
1227 | self.__isConfig = False |
|
1247 | self.__isConfig = False | |
1228 | self.__nsubplots = 1 |
|
1248 | self.__nsubplots = 1 | |
1229 |
|
1249 | |||
1230 | self.WIDTH = 820 |
|
1250 | self.WIDTH = 820 | |
1231 | self.HEIGHT = 200 |
|
1251 | self.HEIGHT = 200 | |
1232 | self.WIDTHPROF = 120 |
|
1252 | self.WIDTHPROF = 120 | |
1233 | self.HEIGHTPROF = 0 |
|
1253 | self.HEIGHTPROF = 0 | |
1234 | self.counter_imagwr = 0 |
|
1254 | self.counter_imagwr = 0 | |
1235 | self.xdata = None |
|
1255 | self.xdata = None | |
1236 | self.ydata = None |
|
1256 | self.ydata = None | |
1237 |
|
1257 | |||
1238 | def getSubplots(self): |
|
1258 | def getSubplots(self): | |
1239 |
|
1259 | |||
1240 | ncol = 1 |
|
1260 | ncol = 1 | |
1241 | nrow = 1 |
|
1261 | nrow = 1 | |
1242 |
|
1262 | |||
1243 | return nrow, ncol |
|
1263 | return nrow, ncol | |
1244 |
|
1264 | |||
1245 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1265 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
1246 |
|
1266 | |||
1247 | self.__showprofile = showprofile |
|
1267 | self.__showprofile = showprofile | |
1248 | self.nplots = nplots |
|
1268 | self.nplots = nplots | |
1249 |
|
1269 | |||
1250 | ncolspan = 7 |
|
1270 | ncolspan = 7 | |
1251 | colspan = 6 |
|
1271 | colspan = 6 | |
1252 | self.__nsubplots = 2 |
|
1272 | self.__nsubplots = 2 | |
1253 |
|
1273 | |||
1254 | self.createFigure(id = id, |
|
1274 | self.createFigure(id = id, | |
1255 | wintitle = wintitle, |
|
1275 | wintitle = wintitle, | |
1256 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1276 | widthplot = self.WIDTH+self.WIDTHPROF, | |
1257 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1277 | heightplot = self.HEIGHT+self.HEIGHTPROF, | |
1258 | show = show) |
|
1278 | show = show) | |
1259 |
|
1279 | |||
1260 | nrow, ncol = self.getSubplots() |
|
1280 | nrow, ncol = self.getSubplots() | |
1261 |
|
1281 | |||
1262 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1282 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) | |
1263 |
|
1283 | |||
1264 |
|
1284 | |||
1265 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
1285 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', | |
1266 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1286 | xmin=None, xmax=None, ymin=None, ymax=None, | |
1267 | timerange=None, |
|
1287 | timerange=None, | |
1268 | save=False, figpath='./', figfile=None, ftp=False, res_imagwr=1, show=True): |
|
1288 | save=False, figpath='./', figfile=None, ftp=False, res_imagwr=1, show=True): | |
1269 |
|
1289 | |||
1270 | if channelList == None: |
|
1290 | if channelList == None: | |
1271 | channelIndexList = dataOut.channelIndexList |
|
1291 | channelIndexList = dataOut.channelIndexList | |
1272 | channelList = dataOut.channelList |
|
1292 | channelList = dataOut.channelList | |
1273 | else: |
|
1293 | else: | |
1274 | channelIndexList = [] |
|
1294 | channelIndexList = [] | |
1275 | for channel in channelList: |
|
1295 | for channel in channelList: | |
1276 | if channel not in dataOut.channelList: |
|
1296 | if channel not in dataOut.channelList: | |
1277 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
1297 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
1278 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1298 | channelIndexList.append(dataOut.channelList.index(channel)) | |
1279 |
|
1299 | |||
1280 | if timerange != None: |
|
1300 | if timerange != None: | |
1281 | self.timerange = timerange |
|
1301 | self.timerange = timerange | |
1282 |
|
1302 | |||
1283 | tmin = None |
|
1303 | tmin = None | |
1284 | tmax = None |
|
1304 | tmax = None | |
1285 | x = dataOut.getTimeRange() |
|
1305 | x = dataOut.getTimeRange() | |
1286 | y = dataOut.getHeiRange() |
|
1306 | y = dataOut.getHeiRange() | |
1287 |
|
1307 | |||
1288 | factor = 1 |
|
1308 | factor = 1 | |
1289 | data = dataOut.data_spc/factor |
|
1309 | data = dataOut.data_spc/factor | |
1290 | data = numpy.average(data,axis=1) |
|
1310 | data = numpy.average(data,axis=1) | |
1291 | datadB = 10*numpy.log10(data) |
|
1311 | datadB = 10*numpy.log10(data) | |
1292 |
|
1312 | |||
1293 | # factor = dataOut.normFactor |
|
1313 | # factor = dataOut.normFactor | |
1294 | # noise = dataOut.getNoise()/factor |
|
1314 | # noise = dataOut.getNoise()/factor | |
1295 | # noisedB = 10*numpy.log10(noise) |
|
1315 | # noisedB = 10*numpy.log10(noise) | |
1296 |
|
1316 | |||
1297 | #thisDatetime = dataOut.datatime |
|
1317 | #thisDatetime = dataOut.datatime | |
1298 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
1318 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
1299 | title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1319 | title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
1300 | xlabel = "Local Time" |
|
1320 | xlabel = "Local Time" | |
1301 | ylabel = "Intensity (dB)" |
|
1321 | ylabel = "Intensity (dB)" | |
1302 |
|
1322 | |||
1303 | if not self.__isConfig: |
|
1323 | if not self.__isConfig: | |
1304 |
|
1324 | |||
1305 | nplots = 1 |
|
1325 | nplots = 1 | |
1306 |
|
1326 | |||
1307 | self.setup(id=id, |
|
1327 | self.setup(id=id, | |
1308 | nplots=nplots, |
|
1328 | nplots=nplots, | |
1309 | wintitle=wintitle, |
|
1329 | wintitle=wintitle, | |
1310 | showprofile=showprofile, |
|
1330 | showprofile=showprofile, | |
1311 | show=show) |
|
1331 | show=show) | |
1312 |
|
1332 | |||
1313 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
1333 | tmin, tmax = self.getTimeLim(x, xmin, xmax) | |
1314 | if ymin == None: ymin = numpy.nanmin(datadB) |
|
1334 | if ymin == None: ymin = numpy.nanmin(datadB) | |
1315 | if ymax == None: ymax = numpy.nanmax(datadB) |
|
1335 | if ymax == None: ymax = numpy.nanmax(datadB) | |
1316 |
|
1336 | |||
1317 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1337 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
1318 | self.__isConfig = True |
|
1338 | self.__isConfig = True | |
1319 |
|
1339 | |||
1320 | self.xdata = numpy.array([]) |
|
1340 | self.xdata = numpy.array([]) | |
1321 | self.ydata = numpy.array([]) |
|
1341 | self.ydata = numpy.array([]) | |
1322 |
|
1342 | |||
1323 | self.setWinTitle(title) |
|
1343 | self.setWinTitle(title) | |
1324 |
|
1344 | |||
1325 |
|
1345 | |||
1326 | # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1346 | # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
1327 | title = "RTI-Noise - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
1347 | title = "RTI-Noise - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
1328 |
|
1348 | |||
1329 | legendlabels = ["channel %d"%idchannel for idchannel in channelList] |
|
1349 | legendlabels = ["channel %d"%idchannel for idchannel in channelList] | |
1330 | axes = self.axesList[0] |
|
1350 | axes = self.axesList[0] | |
1331 |
|
1351 | |||
1332 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1352 | self.xdata = numpy.hstack((self.xdata, x[0:1])) | |
1333 |
|
1353 | |||
1334 | if len(self.ydata)==0: |
|
1354 | if len(self.ydata)==0: | |
1335 | self.ydata = datadB[channelIndexList].reshape(-1,1) |
|
1355 | self.ydata = datadB[channelIndexList].reshape(-1,1) | |
1336 | else: |
|
1356 | else: | |
1337 | self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1))) |
|
1357 | self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1))) | |
1338 |
|
1358 | |||
1339 |
|
1359 | |||
1340 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1360 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, | |
1341 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, |
|
1361 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, | |
1342 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both', |
|
1362 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both', | |
1343 | XAxisAsTime=True |
|
1363 | XAxisAsTime=True | |
1344 | ) |
|
1364 | ) | |
1345 |
|
1365 | |||
1346 | self.draw() |
|
1366 | self.draw() | |
1347 |
|
1367 | |||
1348 | if save: |
|
1368 | if save: | |
1349 |
|
1369 | |||
1350 | if figfile == None: |
|
1370 | if figfile == None: | |
1351 | figfile = self.getFilename(name = self.name) |
|
1371 | figfile = self.getFilename(name = self.name) | |
1352 |
|
1372 | |||
1353 | self.saveFigure(figpath, figfile) |
|
1373 | self.saveFigure(figpath, figfile) | |
1354 |
|
1374 | |||
1355 | self.counter_imagwr += 1 |
|
1375 | self.counter_imagwr += 1 | |
1356 | if (ftp and (self.counter_imagwr==res_imagwr)): |
|
1376 | if (ftp and (self.counter_imagwr==res_imagwr)): | |
1357 | figfilename = os.path.join(figpath,figfile) |
|
1377 | figfilename = os.path.join(figpath,figfile) | |
1358 | self.sendByFTP(figfilename) |
|
1378 | self.sendByFTP(figfilename) | |
1359 | self.counter_imagwr = 0 |
|
1379 | self.counter_imagwr = 0 | |
1360 |
|
1380 | |||
1361 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
1381 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: | |
1362 | self.__isConfig = False |
|
1382 | self.__isConfig = False | |
1363 | del self.xdata |
|
1383 | del self.xdata | |
1364 | del self.ydata |
|
1384 | del self.ydata | |
1365 |
|
1385 | |||
1366 |
|
1386 | |||
1367 | No newline at end of file |
|
1387 |
General Comments 0
You need to be logged in to leave comments.
Login now