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