##// END OF EJS Templates
Envio de graficos por FTP:...
Daniel Valdez -
r283:7162b4ee74da
parent child
Show More
@@ -0,0 +1,293
1 import os.path
2 import ftplib
3
4
5 class Ftp():
6 """
7 Ftp is a public class used to define custom File Transfer Protocol from "ftplib" python module
8
9 Non-standard Python modules used: None
10
11 Written by "Daniel Suarez":mailto:daniel.suarez@jro.igp.gob.pe Oct. 26, 2010
12 """
13
14 def __init__(self,host = None, username=None, passw=None, remotefolder=None):
15 """
16 This method is used to setting parameters for FTP and establishing connection to remote host
17
18 Inputs:
19 host - remote host IP Address
20
21 username - remote host Username
22
23 passw - remote host Passw
24
25 remotefolder - remote host current working directory
26
27 Return: void
28
29 Affects:
30 self.status - in Error Case or Connection Failed this parameter is set to 1 else 0
31
32 self.folderList - sub-folder list of remote folder
33
34 self.fileList - file list of remote folder
35
36
37 """
38
39 if ((host == None) and (username==None) and (passw==None) and (remotefolder==None)):
40 host, username, passw, remotefolder = self.parmsByDefault()
41
42 self.host = host
43 self.username = username
44 self.passw = passw
45 self.remotefolder = remotefolder
46 self.file = None
47 self.ftp = None
48 self.status = 0
49
50 try:
51 self.ftp = ftplib.FTP(self.host)
52 self.ftp.login(self.username,self.passw)
53 self.ftp.cwd(self.remotefolder)
54 # print 'Connect to FTP Server: Successfully'
55
56 except ftplib.all_errors:
57 print 'Error FTP Service'
58 self.status = 1
59 return
60
61
62
63 self.dirList = []
64
65 try:
66 self.dirList = self.ftp.nlst()
67
68 except ftplib.error_perm, resp:
69 if str(resp) == "550 No files found":
70 print "no files in this directory"
71 self.status = 1
72 return
73
74 except ftplib.all_errors:
75 print 'Error Displaying Dir-Files'
76 self.status = 1
77 return
78
79 self.fileList = []
80 self.folderList = []
81 #only for test
82 for f in self.dirList:
83 name, ext = os.path.splitext(f)
84 if ext != '':
85 self.fileList.append(f)
86 # print 'filename: %s - size: %d'%(f,self.ftp.size(f))
87
88 def parmsByDefault(self):
89 host = 'jro.igp.gob.pe'
90 username = 'operaciones'
91 passw = 'mst98vhf'
92 remotefolder = '/users/database/on-line/'
93
94 return host, username, passw, remotefolder
95
96
97 def mkd(self,dirname):
98 """
99 mkd is used to make directory in remote host
100
101 Input:
102 dirname - directory name
103
104 Return:
105 1 in error case else 0
106 """
107 try:
108 self.ftp.mkd(dirname)
109 except:
110 print 'Error creating remote folder:%s'%dirname
111 return 1
112
113 return 0
114
115
116 def delete(self,filename):
117 """
118 delete is used to delete file in current working directory of remote host
119
120 Input:
121 filename - filename to delete in remote folder
122
123 Return:
124 1 in error case else 0
125 """
126
127 try:
128 self.ftp.delete(filename)
129 except:
130 print 'Error deleting remote file:%s'%filename
131 return 1
132
133 return 0
134
135 def download(self,filename,localfolder):
136 """
137 download is used to downloading file from remote folder into local folder
138
139 Inputs:
140 filename - filename to donwload
141
142 localfolder - directory local to store filename
143
144 Returns:
145 self.status - 1 in error case else 0
146 """
147
148 self.status = 0
149
150
151 if not(filename in self.fileList):
152 print 'filename:%s not exists'%filename
153 self.status = 1
154 return self.status
155
156 newfilename = os.path.join(localfolder,filename)
157
158 self.file = open(newfilename, 'wb')
159
160 try:
161 print 'Download: ' + filename
162 self.ftp.retrbinary('RETR ' + filename, self.__handleDownload)
163 print 'Download Complete'
164 except ftplib.all_errors:
165 print 'Error Downloading ' + filename
166 self.status = 1
167 return self.status
168
169 self.file.close()
170
171 return self.status
172
173
174 def __handleDownload(self,block):
175 """
176 __handleDownload is used to handle writing file
177 """
178 self.file.write(block)
179
180
181 def upload(self,filename,remotefolder=None):
182 """
183 upload is used to uploading local file to remote directory
184
185 Inputs:
186 filename - full path name of local file to store in remote directory
187
188 remotefolder - remote directory
189
190 Returns:
191 self.status - 1 in error case else 0
192 """
193
194 if remotefolder == None:
195 remotefolder = self.remotefolder
196
197 self.status = 0
198
199 try:
200 self.ftp.cwd(remotefolder)
201
202 self.file = open(filename, 'rb')
203
204 (head, tail) = os.path.split(filename)
205
206 command = "STOR " + tail
207
208 print 'Uploading: ' + tail
209 self.ftp.storbinary(command, self.file)
210 print 'Upload Completed'
211
212 except ftplib.all_errors:
213 print 'Error Uploading ' + tail
214 self.status = 1
215 return self.status
216
217 self.file.close()
218
219 #back to initial directory in __init__()
220 self.ftp.cwd(self.remotefolder)
221
222 return self.status
223
224
225 def dir(self,remotefolder):
226 """
227 dir is used to change working directory of remote host and get folder and file list
228
229 Input:
230 remotefolder - current working directory
231
232 Affects:
233 self.fileList - file list of working directory
234
235 Return:
236 infoList - list with filenames and size of file in bytes
237
238 self.folderList - folder list
239 """
240
241 self.remotefolder = remotefolder
242 print 'Change to ' + self.remotefolder
243 try:
244 self.ftp.cwd(remotefolder)
245 except ftplib.all_errors:
246 print 'Error Change to ' + self.remotefolder
247 infoList = None
248 self.folderList = None
249 return infoList,self.folderList
250
251 self.dirList = []
252
253 try:
254 self.dirList = self.ftp.nlst()
255
256 except ftplib.error_perm, resp:
257 if str(resp) == "550 No files found":
258 print "no files in this directory"
259 infoList = None
260 self.folderList = None
261 return infoList,self.folderList
262 except ftplib.all_errors:
263 print 'Error Displaying Dir-Files'
264 infoList = None
265 self.folderList = None
266 return infoList,self.folderList
267
268 infoList = []
269 self.fileList = []
270 self.folderList = []
271 for f in self.dirList:
272 name,ext = os.path.splitext(f)
273 if ext != '':
274 self.fileList.append(f)
275 value = (f,self.ftp.size(f))
276 infoList.append(value)
277
278 if ext == '':
279 self.folderList.append(f)
280
281 return infoList,self.folderList
282
283
284 def close(self):
285 """
286 close is used to close and end FTP connection
287
288 Inputs: None
289
290 Return: void
291
292 """
293 self.ftp.close() No newline at end of file
@@ -1,408 +1,414
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 idfigure = 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.idfigure)
36 36 filename = '%s_%s%s' %(self.PREFIX, name, ext)
37 37
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, idfigure, nplots, wintitle):
86 86
87 87 raise ValueError, "This method has been replaced with createFigure"
88 88
89 89 def createFigure(self, idfigure, wintitle, widthplot=None, heightplot=None):
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 idfigure : 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.idfigure = idfigure
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(self.idfigure,
115 115 self.wintitle,
116 116 self.widthscreen,
117 117 self.heightscreen)
118 118
119 119 self.axesObjList = []
120
120 121
121 122 def setDriver(self, driver=mpldriver):
122 123
123 124 self.__driver = driver
124 125
125 126 def setTitle(self, title):
126 127
127 128 self.__driver.setTitle(self.fig, title)
128 129
129 130 def setWinTitle(self, title):
130 131
131 132 self.__driver.setWinTitle(self.fig, title=title)
132 133
133 134 def setTextFromAxes(self, text):
134 135
135 136 raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes"
136 137
137 138 def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan):
138 139
139 140 raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes"
140 141
141 142 def addAxes(self, *args):
142 143 """
143 144
144 145 Input:
145 146 *args : Los parametros necesarios son
146 147 nrow, ncol, xpos, ypos, colspan, rowspan
147 148 """
148 149
149 150 axesObj = Axes(self.fig, *args)
150 151 self.axesObjList.append(axesObj)
151 152
152 153 def saveFigure(self, figpath, figfile, *args):
153 154
154 155 filename = os.path.join(figpath, figfile)
155 156
156 157 fullpath = os.path.split(filename)[0]
157 158
158 159 if not os.path.exists(fullpath):
159 160 os.mkdir(fullpath)
160 161
161 162 self.__driver.saveFigure(self.fig, filename, *args)
162 163
164 def sendByFTP(self, figfilename):
165 ftpObj = Ftp()
166 ftpObj.upload(figfilename)
167 ftpObj.close()
168
163 169 def draw(self):
164 170
165 171 self.__driver.draw(self.fig)
166 172
167 173 def run(self):
168 174
169 175 raise ValueError, "This method is not implemented"
170 176
171 177 axesList = property(getAxesObjList)
172 178
173 179
174 180 class Axes:
175 181
176 182 __driver = mpldriver
177 183 fig = None
178 184 ax = None
179 185 plot = None
180 186
181 187 __firsttime = None
182 188
183 189 __showprofile = False
184 190
185 191 xmin = None
186 192 xmax = None
187 193 ymin = None
188 194 ymax = None
189 195 zmin = None
190 196 zmax = None
191 197
192 198 def __init__(self, *args):
193 199
194 200 """
195 201
196 202 Input:
197 203 *args : Los parametros necesarios son
198 204 fig, nrow, ncol, xpos, ypos, colspan, rowspan
199 205 """
200 206
201 207 ax = self.__driver.createAxes(*args)
202 208 self.fig = args[0]
203 209 self.ax = ax
204 210 self.plot = None
205 211
206 212 self.__firsttime = True
207 213 self.idlineList = []
208 214
209 215 def setText(self, text):
210 216
211 217 self.__driver.setAxesText(self.ax, text)
212 218
213 219 def setXAxisAsTime(self):
214 220 pass
215 221
216 222 def pline(self, x, y,
217 223 xmin=None, xmax=None,
218 224 ymin=None, ymax=None,
219 225 xlabel='', ylabel='',
220 226 title='',
221 227 **kwargs):
222 228
223 229 """
224 230
225 231 Input:
226 232 x :
227 233 y :
228 234 xmin :
229 235 xmax :
230 236 ymin :
231 237 ymax :
232 238 xlabel :
233 239 ylabel :
234 240 title :
235 241 **kwargs : Los parametros aceptados son
236 242
237 243 ticksize
238 244 ytick_visible
239 245 """
240 246
241 247 if self.__firsttime:
242 248
243 249 if xmin == None: xmin = numpy.nanmin(x)
244 250 if xmax == None: xmax = numpy.nanmax(x)
245 251 if ymin == None: ymin = numpy.nanmin(y)
246 252 if ymax == None: ymax = numpy.nanmax(y)
247 253
248 254 self.plot = self.__driver.createPline(self.ax, x, y,
249 255 xmin, xmax,
250 256 ymin, ymax,
251 257 xlabel=xlabel,
252 258 ylabel=ylabel,
253 259 title=title,
254 260 **kwargs)
255 261
256 262 self.idlineList.append(0)
257 263 self.__firsttime = False
258 264 return
259 265
260 266 self.__driver.pline(self.plot, x, y, xlabel=xlabel,
261 267 ylabel=ylabel,
262 268 title=title)
263 269
264 270 def addpline(self, x, y, idline, **kwargs):
265 271 lines = self.ax.lines
266 272
267 273 if idline in self.idlineList:
268 274 self.__driver.set_linedata(self.ax, x, y, idline)
269 275
270 276 if idline not in(self.idlineList):
271 277 self.__driver.addpline(self.ax, x, y, **kwargs)
272 278 self.idlineList.append(idline)
273 279
274 280 return
275 281
276 282 def pmultiline(self, x, y,
277 283 xmin=None, xmax=None,
278 284 ymin=None, ymax=None,
279 285 xlabel='', ylabel='',
280 286 title='',
281 287 **kwargs):
282 288
283 289 if self.__firsttime:
284 290
285 291 if xmin == None: xmin = numpy.nanmin(x)
286 292 if xmax == None: xmax = numpy.nanmax(x)
287 293 if ymin == None: ymin = numpy.nanmin(y)
288 294 if ymax == None: ymax = numpy.nanmax(y)
289 295
290 296 self.plot = self.__driver.createPmultiline(self.ax, x, y,
291 297 xmin, xmax,
292 298 ymin, ymax,
293 299 xlabel=xlabel,
294 300 ylabel=ylabel,
295 301 title=title,
296 302 **kwargs)
297 303 self.__firsttime = False
298 304 return
299 305
300 306 self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel,
301 307 ylabel=ylabel,
302 308 title=title)
303 309
304 310 def pmultilineyaxis(self, x, y,
305 311 xmin=None, xmax=None,
306 312 ymin=None, ymax=None,
307 313 xlabel='', ylabel='',
308 314 title='',
309 315 **kwargs):
310 316
311 317 if self.__firsttime:
312 318
313 319 if xmin == None: xmin = numpy.nanmin(x)
314 320 if xmax == None: xmax = numpy.nanmax(x)
315 321 if ymin == None: ymin = numpy.nanmin(y)
316 322 if ymax == None: ymax = numpy.nanmax(y)
317 323
318 324 self.plot = self.__driver.createPmultilineYAxis(self.ax, x, y,
319 325 xmin, xmax,
320 326 ymin, ymax,
321 327 xlabel=xlabel,
322 328 ylabel=ylabel,
323 329 title=title,
324 330 **kwargs)
325 331 if self.xmin == None: self.xmin = xmin
326 332 if self.xmax == None: self.xmax = xmax
327 333 if self.ymin == None: self.ymin = ymin
328 334 if self.ymax == None: self.ymax = ymax
329 335
330 336 self.__firsttime = False
331 337 return
332 338
333 339 self.__driver.pmultilineyaxis(self.plot, x, y, xlabel=xlabel,
334 340 ylabel=ylabel,
335 341 title=title)
336 342
337 343 def pcolor(self, x, y, z,
338 344 xmin=None, xmax=None,
339 345 ymin=None, ymax=None,
340 346 zmin=None, zmax=None,
341 347 xlabel='', ylabel='',
342 348 title='', rti = False, colormap='jet',
343 349 **kwargs):
344 350
345 351 """
346 352 Input:
347 353 x :
348 354 y :
349 355 x :
350 356 xmin :
351 357 xmax :
352 358 ymin :
353 359 ymax :
354 360 zmin :
355 361 zmax :
356 362 xlabel :
357 363 ylabel :
358 364 title :
359 365 **kwargs : Los parametros aceptados son
360 366 ticksize=9,
361 367 cblabel=''
362 368 rti = True or False
363 369 """
364 370
365 371 if self.__firsttime:
366 372
367 373 if xmin == None: xmin = numpy.nanmin(x)
368 374 if xmax == None: xmax = numpy.nanmax(x)
369 375 if ymin == None: ymin = numpy.nanmin(y)
370 376 if ymax == None: ymax = numpy.nanmax(y)
371 377 if zmin == None: zmin = numpy.nanmin(z)
372 378 if zmax == None: zmax = numpy.nanmax(z)
373 379
374 380
375 381 self.plot = self.__driver.createPcolor(self.ax, x, y, z,
376 382 xmin, xmax,
377 383 ymin, ymax,
378 384 zmin, zmax,
379 385 xlabel=xlabel,
380 386 ylabel=ylabel,
381 387 title=title,
382 388 colormap=colormap,
383 389 **kwargs)
384 390
385 391 if self.xmin == None: self.xmin = xmin
386 392 if self.xmax == None: self.xmax = xmax
387 393 if self.ymin == None: self.ymin = ymin
388 394 if self.ymax == None: self.ymax = ymax
389 395 if self.zmin == None: self.zmin = zmin
390 396 if self.zmax == None: self.zmax = zmax
391 397
392 398 self.__firsttime = False
393 399 return
394 400
395 401 if rti:
396 402 self.__driver.addpcolor(self.ax, x, y, z, self.zmin, self.zmax,
397 403 xlabel=xlabel,
398 404 ylabel=ylabel,
399 405 title=title,
400 406 colormap=colormap)
401 407 return
402 408
403 409 self.__driver.pcolor(self.plot, z,
404 410 xlabel=xlabel,
405 411 ylabel=ylabel,
406 412 title=title)
407 413
408 414 No newline at end of file
@@ -1,990 +1,1004
1 1 import numpy
2 import time, datetime
2 import time, datetime, os
3 3 from graphics.figure import *
4 4
5 5 class CrossSpectraPlot(Figure):
6 6
7 7 __isConfig = None
8 8 __nsubplots = None
9 9
10 10 WIDTH = None
11 11 HEIGHT = None
12 12 WIDTHPROF = None
13 13 HEIGHTPROF = None
14 14 PREFIX = 'cspc'
15 15
16 16 def __init__(self):
17 17
18 18 self.__isConfig = False
19 19 self.__nsubplots = 4
20 20
21 21 self.WIDTH = 250
22 22 self.HEIGHT = 250
23 23 self.WIDTHPROF = 0
24 24 self.HEIGHTPROF = 0
25 25
26 26 def getSubplots(self):
27 27
28 28 ncol = 4
29 29 nrow = self.nplots
30 30
31 31 return nrow, ncol
32 32
33 33 def setup(self, idfigure, nplots, wintitle, showprofile=True):
34 34
35 35 self.__showprofile = showprofile
36 36 self.nplots = nplots
37 37
38 38 ncolspan = 1
39 39 colspan = 1
40 40
41 41 self.createFigure(idfigure = idfigure,
42 42 wintitle = wintitle,
43 43 widthplot = self.WIDTH + self.WIDTHPROF,
44 44 heightplot = self.HEIGHT + self.HEIGHTPROF)
45 45
46 46 nrow, ncol = self.getSubplots()
47 47
48 48 counter = 0
49 49 for y in range(nrow):
50 50 for x in range(ncol):
51 51 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
52 52
53 53 counter += 1
54 54
55 55 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
56 56 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
57 57 save=False, figpath='./', figfile=None,
58 58 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r'):
59 59
60 60 """
61 61
62 62 Input:
63 63 dataOut :
64 64 idfigure :
65 65 wintitle :
66 66 channelList :
67 67 showProfile :
68 68 xmin : None,
69 69 xmax : None,
70 70 ymin : None,
71 71 ymax : None,
72 72 zmin : None,
73 73 zmax : None
74 74 """
75 75
76 76 if pairsList == None:
77 77 pairsIndexList = dataOut.pairsIndexList
78 78 else:
79 79 pairsIndexList = []
80 80 for pair in pairsList:
81 81 if pair not in dataOut.pairsList:
82 82 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
83 83 pairsIndexList.append(dataOut.pairsList.index(pair))
84 84
85 85 if pairsIndexList == []:
86 86 return
87 87
88 88 if len(pairsIndexList) > 4:
89 89 pairsIndexList = pairsIndexList[0:4]
90 90 factor = dataOut.normFactor
91 91 x = dataOut.getVelRange(1)
92 92 y = dataOut.getHeiRange()
93 93 z = dataOut.data_spc[:,:,:]/factor
94 94 # z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
95 95 avg = numpy.abs(numpy.average(z, axis=1))
96 96 noise = dataOut.getNoise()/factor
97 97
98 98 zdB = 10*numpy.log10(z)
99 99 avgdB = 10*numpy.log10(avg)
100 100 noisedB = 10*numpy.log10(noise)
101 101
102 102
103 103 thisDatetime = dataOut.datatime
104 104 title = "Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
105 105 xlabel = "Velocity (m/s)"
106 106 ylabel = "Range (Km)"
107 107
108 108 if not self.__isConfig:
109 109
110 110 nplots = len(pairsIndexList)
111 111
112 112 self.setup(idfigure=idfigure,
113 113 nplots=nplots,
114 114 wintitle=wintitle,
115 115 showprofile=showprofile)
116 116
117 117 if xmin == None: xmin = numpy.nanmin(x)
118 118 if xmax == None: xmax = numpy.nanmax(x)
119 119 if ymin == None: ymin = numpy.nanmin(y)
120 120 if ymax == None: ymax = numpy.nanmax(y)
121 121 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
122 122 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
123 123
124 124 self.__isConfig = True
125 125
126 126 self.setWinTitle(title)
127 127
128 128 for i in range(self.nplots):
129 129 pair = dataOut.pairsList[pairsIndexList[i]]
130 130
131 131 title = "Channel %d: %4.2fdB" %(pair[0], noisedB[pair[0]])
132 132 zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]/factor)
133 133 axes0 = self.axesList[i*self.__nsubplots]
134 134 axes0.pcolor(x, y, zdB,
135 135 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
136 136 xlabel=xlabel, ylabel=ylabel, title=title,
137 137 ticksize=9, colormap=power_cmap, cblabel='')
138 138
139 139 title = "Channel %d: %4.2fdB" %(pair[1], noisedB[pair[1]])
140 140 zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]/factor)
141 141 axes0 = self.axesList[i*self.__nsubplots+1]
142 142 axes0.pcolor(x, y, zdB,
143 143 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
144 144 xlabel=xlabel, ylabel=ylabel, title=title,
145 145 ticksize=9, colormap=power_cmap, cblabel='')
146 146
147 147 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
148 148 coherence = numpy.abs(coherenceComplex)
149 149 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
150 150 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
151 151
152 152 title = "Coherence %d%d" %(pair[0], pair[1])
153 153 axes0 = self.axesList[i*self.__nsubplots+2]
154 154 axes0.pcolor(x, y, coherence,
155 155 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
156 156 xlabel=xlabel, ylabel=ylabel, title=title,
157 157 ticksize=9, colormap=coherence_cmap, cblabel='')
158 158
159 159 title = "Phase %d%d" %(pair[0], pair[1])
160 160 axes0 = self.axesList[i*self.__nsubplots+3]
161 161 axes0.pcolor(x, y, phase,
162 162 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
163 163 xlabel=xlabel, ylabel=ylabel, title=title,
164 164 ticksize=9, colormap=phase_cmap, cblabel='')
165 165
166 166
167 167
168 168 self.draw()
169 169
170 170 if save:
171 171 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
172 172 if figfile == None:
173 173 figfile = self.getFilename(name = date)
174 174
175 175 self.saveFigure(figpath, figfile)
176 176
177 177
178 178 class RTIPlot(Figure):
179 179
180 180 __isConfig = None
181 181 __nsubplots = None
182 182
183 183 WIDTHPROF = None
184 184 HEIGHTPROF = None
185 185 PREFIX = 'rti'
186 186
187 187 def __init__(self):
188 188
189 189 self.timerange = 2*60*60
190 190 self.__isConfig = False
191 191 self.__nsubplots = 1
192 192
193 193 self.WIDTH = 800
194 194 self.HEIGHT = 150
195 195 self.WIDTHPROF = 120
196 196 self.HEIGHTPROF = 0
197 self.counterftp = 0
197 198
198 199 def getSubplots(self):
199 200
200 201 ncol = 1
201 202 nrow = self.nplots
202 203
203 204 return nrow, ncol
204 205
205 206 def setup(self, idfigure, nplots, wintitle, showprofile=True):
206 207
207 208 self.__showprofile = showprofile
208 209 self.nplots = nplots
209 210
210 211 ncolspan = 1
211 212 colspan = 1
212 213 if showprofile:
213 214 ncolspan = 7
214 215 colspan = 6
215 216 self.__nsubplots = 2
216 217
217 218 self.createFigure(idfigure = idfigure,
218 219 wintitle = wintitle,
219 220 widthplot = self.WIDTH + self.WIDTHPROF,
220 221 heightplot = self.HEIGHT + self.HEIGHTPROF)
221 222
222 223 nrow, ncol = self.getSubplots()
223 224
224 225 counter = 0
225 226 for y in range(nrow):
226 227 for x in range(ncol):
227 228
228 229 if counter >= self.nplots:
229 230 break
230 231
231 232 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
232 233
233 234 if showprofile:
234 235 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
235 236
236 237 counter += 1
237 238
238 239 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
239 240 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
240 241 timerange=None,
241 save=False, figpath='./', figfile=None):
242 save=False, figpath='./', figfile=None, ftp=False, ftpratio=1):
242 243
243 244 """
244 245
245 246 Input:
246 247 dataOut :
247 248 idfigure :
248 249 wintitle :
249 250 channelList :
250 251 showProfile :
251 252 xmin : None,
252 253 xmax : None,
253 254 ymin : None,
254 255 ymax : None,
255 256 zmin : None,
256 257 zmax : None
257 258 """
258 259
259 260 if channelList == None:
260 261 channelIndexList = dataOut.channelIndexList
261 262 else:
262 263 channelIndexList = []
263 264 for channel in channelList:
264 265 if channel not in dataOut.channelList:
265 266 raise ValueError, "Channel %d is not in dataOut.channelList"
266 267 channelIndexList.append(dataOut.channelList.index(channel))
267 268
268 269 if timerange != None:
269 270 self.timerange = timerange
270 271
271 272 tmin = None
272 273 tmax = None
273 274 factor = dataOut.normFactor
274 275 x = dataOut.getTimeRange()
275 276 y = dataOut.getHeiRange()
276 277
277 278 z = dataOut.data_spc[channelIndexList,:,:]/factor
278 279 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
279 280 avg = numpy.average(z, axis=1)
280 281
281 282 avgdB = 10.*numpy.log10(avg)
282 283
283 284
284 285 thisDatetime = dataOut.datatime
285 286 title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
286 287 xlabel = ""
287 288 ylabel = "Range (Km)"
288 289
289 290 if not self.__isConfig:
290 291
291 292 nplots = len(channelIndexList)
292 293
293 294 self.setup(idfigure=idfigure,
294 295 nplots=nplots,
295 296 wintitle=wintitle,
296 297 showprofile=showprofile)
297 298
298 299 tmin, tmax = self.getTimeLim(x, xmin, xmax)
299 300 if ymin == None: ymin = numpy.nanmin(y)
300 301 if ymax == None: ymax = numpy.nanmax(y)
301 302 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
302 303 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
303 304
304 305 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
305 306 self.__isConfig = True
306 307
307 308
308 309 self.setWinTitle(title)
309 310
310 311 for i in range(self.nplots):
311 312 title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
312 313 axes = self.axesList[i*self.__nsubplots]
313 314 zdB = avgdB[i].reshape((1,-1))
314 315 axes.pcolor(x, y, zdB,
315 316 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
316 317 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
317 318 ticksize=9, cblabel='', cbsize="1%")
318 319
319 320 if self.__showprofile:
320 321 axes = self.axesList[i*self.__nsubplots +1]
321 322 axes.pline(avgdB[i], y,
322 323 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
323 324 xlabel='dB', ylabel='', title='',
324 325 ytick_visible=False,
325 326 grid='x')
326 327
327 328 self.draw()
328 329
329 330 if save:
330 331
331 332 if figfile == None:
332 333 figfile = self.getFilename(name = self.name)
333 334
334 335 self.saveFigure(figpath, figfile)
335 336
337 self.counterftp += 1
338 if (ftp and (self.counterftp==ftpratio)):
339 figfilename = os.path.join(figpath,figfile)
340 self.sendByFTP(figfilename)
341 self.counterftp = 0
342
336 343 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
337 344 self.__isConfig = False
338 345
339 346 class SpectraPlot(Figure):
340 347
341 348 __isConfig = None
342 349 __nsubplots = None
343 350
344 351 WIDTHPROF = None
345 352 HEIGHTPROF = None
346 353 PREFIX = 'spc'
347 354
348 355 def __init__(self):
349 356
350 357 self.__isConfig = False
351 358 self.__nsubplots = 1
352 359
353 360 self.WIDTH = 230
354 361 self.HEIGHT = 250
355 362 self.WIDTHPROF = 120
356 363 self.HEIGHTPROF = 0
357 364
358 365 def getSubplots(self):
359 366
360 367 ncol = int(numpy.sqrt(self.nplots)+0.9)
361 368 nrow = int(self.nplots*1./ncol + 0.9)
362 369
363 370 return nrow, ncol
364 371
365 372 def setup(self, idfigure, nplots, wintitle, showprofile=True):
366 373
367 374 self.__showprofile = showprofile
368 375 self.nplots = nplots
369 376
370 377 ncolspan = 1
371 378 colspan = 1
372 379 if showprofile:
373 380 ncolspan = 3
374 381 colspan = 2
375 382 self.__nsubplots = 2
376 383
377 384 self.createFigure(idfigure = idfigure,
378 385 wintitle = wintitle,
379 386 widthplot = self.WIDTH + self.WIDTHPROF,
380 387 heightplot = self.HEIGHT + self.HEIGHTPROF)
381 388
382 389 nrow, ncol = self.getSubplots()
383 390
384 391 counter = 0
385 392 for y in range(nrow):
386 393 for x in range(ncol):
387 394
388 395 if counter >= self.nplots:
389 396 break
390 397
391 398 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
392 399
393 400 if showprofile:
394 401 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
395 402
396 403 counter += 1
397 404
398 405 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
399 406 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
400 407 save=False, figpath='./', figfile=None):
401 408
402 409 """
403 410
404 411 Input:
405 412 dataOut :
406 413 idfigure :
407 414 wintitle :
408 415 channelList :
409 416 showProfile :
410 417 xmin : None,
411 418 xmax : None,
412 419 ymin : None,
413 420 ymax : None,
414 421 zmin : None,
415 422 zmax : None
416 423 """
417 424
418 425 if channelList == None:
419 426 channelIndexList = dataOut.channelIndexList
420 427 else:
421 428 channelIndexList = []
422 429 for channel in channelList:
423 430 if channel not in dataOut.channelList:
424 431 raise ValueError, "Channel %d is not in dataOut.channelList"
425 432 channelIndexList.append(dataOut.channelList.index(channel))
426 433 factor = dataOut.normFactor
427 434 x = dataOut.getVelRange(1)
428 435 y = dataOut.getHeiRange()
429 436
430 437 z = dataOut.data_spc[channelIndexList,:,:]/factor
431 438 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
432 439 avg = numpy.average(z, axis=1)
433 440 noise = dataOut.getNoise()/factor
434 441
435 442 zdB = 10*numpy.log10(z)
436 443 avgdB = 10*numpy.log10(avg)
437 444 noisedB = 10*numpy.log10(noise)
438 445
439 446 thisDatetime = dataOut.datatime
440 447 title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
441 448 xlabel = "Velocity (m/s)"
442 449 ylabel = "Range (Km)"
443 450
444 451 if not self.__isConfig:
445 452
446 453 nplots = len(channelIndexList)
447 454
448 455 self.setup(idfigure=idfigure,
449 456 nplots=nplots,
450 457 wintitle=wintitle,
451 458 showprofile=showprofile)
452 459
453 460 if xmin == None: xmin = numpy.nanmin(x)
454 461 if xmax == None: xmax = numpy.nanmax(x)
455 462 if ymin == None: ymin = numpy.nanmin(y)
456 463 if ymax == None: ymax = numpy.nanmax(y)
457 464 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
458 465 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
459 466
460 467 self.__isConfig = True
461 468
462 469 self.setWinTitle(title)
463 470
464 471 for i in range(self.nplots):
465 472 title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noisedB[i])
466 473 axes = self.axesList[i*self.__nsubplots]
467 474 axes.pcolor(x, y, zdB[i,:,:],
468 475 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
469 476 xlabel=xlabel, ylabel=ylabel, title=title,
470 477 ticksize=9, cblabel='')
471 478
472 479 if self.__showprofile:
473 480 axes = self.axesList[i*self.__nsubplots +1]
474 481 axes.pline(avgdB[i], y,
475 482 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
476 483 xlabel='dB', ylabel='', title='',
477 484 ytick_visible=False,
478 485 grid='x')
479 486
480 487 noiseline = numpy.repeat(noisedB[i], len(y))
481 488 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
482 489
483 490 self.draw()
484 491
485 492 if save:
486 493 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
487 494 if figfile == None:
488 495 figfile = self.getFilename(name = date)
489 496
490 497 self.saveFigure(figpath, figfile)
491 498
492 499 class Scope(Figure):
493 500
494 501 __isConfig = None
495 502
496 503 def __init__(self):
497 504
498 505 self.__isConfig = False
499 506 self.WIDTH = 600
500 507 self.HEIGHT = 200
501 508
502 509 def getSubplots(self):
503 510
504 511 nrow = self.nplots
505 512 ncol = 3
506 513 return nrow, ncol
507 514
508 515 def setup(self, idfigure, nplots, wintitle):
509 516
510 517 self.nplots = nplots
511 518
512 519 self.createFigure(idfigure, wintitle)
513 520
514 521 nrow,ncol = self.getSubplots()
515 522 colspan = 3
516 523 rowspan = 1
517 524
518 525 for i in range(nplots):
519 526 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
520 527
521 528
522 529
523 530 def run(self, dataOut, idfigure, wintitle="", channelList=None,
524 531 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
525 532 figpath='./', figfile=None):
526 533
527 534 """
528 535
529 536 Input:
530 537 dataOut :
531 538 idfigure :
532 539 wintitle :
533 540 channelList :
534 541 xmin : None,
535 542 xmax : None,
536 543 ymin : None,
537 544 ymax : None,
538 545 """
539 546
540 547 if channelList == None:
541 548 channelIndexList = dataOut.channelIndexList
542 549 else:
543 550 channelIndexList = []
544 551 for channel in channelList:
545 552 if channel not in dataOut.channelList:
546 553 raise ValueError, "Channel %d is not in dataOut.channelList"
547 554 channelIndexList.append(dataOut.channelList.index(channel))
548 555
549 556 x = dataOut.heightList
550 557 y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
551 558 y = y.real
552 559
553 560 thisDatetime = dataOut.datatime
554 561 title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
555 562 xlabel = "Range (Km)"
556 563 ylabel = "Intensity"
557 564
558 565 if not self.__isConfig:
559 566 nplots = len(channelIndexList)
560 567
561 568 self.setup(idfigure=idfigure,
562 569 nplots=nplots,
563 570 wintitle=wintitle)
564 571
565 572 if xmin == None: xmin = numpy.nanmin(x)
566 573 if xmax == None: xmax = numpy.nanmax(x)
567 574 if ymin == None: ymin = numpy.nanmin(y)
568 575 if ymax == None: ymax = numpy.nanmax(y)
569 576
570 577 self.__isConfig = True
571 578
572 579 self.setWinTitle(title)
573 580
574 581 for i in range(len(self.axesList)):
575 582 title = "Channel %d" %(i)
576 583 axes = self.axesList[i]
577 584 ychannel = y[i,:]
578 585 axes.pline(x, ychannel,
579 586 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
580 587 xlabel=xlabel, ylabel=ylabel, title=title)
581 588
582 589 self.draw()
583 590
584 591 if save:
585 592 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
586 593 if figfile == None:
587 594 figfile = self.getFilename(name = date)
588 595
589 596 self.saveFigure(figpath, figfile)
590 597
591 598 class ProfilePlot(Figure):
592 599 __isConfig = None
593 600 __nsubplots = None
594 601
595 602 WIDTHPROF = None
596 603 HEIGHTPROF = None
597 604 PREFIX = 'spcprofile'
598 605
599 606 def __init__(self):
600 607 self.__isConfig = False
601 608 self.__nsubplots = 1
602 609
603 610 self.WIDTH = 300
604 611 self.HEIGHT = 500
605 612
606 613 def getSubplots(self):
607 614 ncol = 1
608 615 nrow = 1
609 616
610 617 return nrow, ncol
611 618
612 619 def setup(self, idfigure, nplots, wintitle):
613 620
614 621 self.nplots = nplots
615 622
616 623 ncolspan = 1
617 624 colspan = 1
618 625
619 626 self.createFigure(idfigure = idfigure,
620 627 wintitle = wintitle,
621 628 widthplot = self.WIDTH,
622 629 heightplot = self.HEIGHT)
623 630
624 631 nrow, ncol = self.getSubplots()
625 632
626 633 counter = 0
627 634 for y in range(nrow):
628 635 for x in range(ncol):
629 636 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
630 637
631 638 def run(self, dataOut, idfigure, wintitle="", channelList=None,
632 639 xmin=None, xmax=None, ymin=None, ymax=None,
633 640 save=False, figpath='./', figfile=None):
634 641
635 642 if channelList == None:
636 643 channelIndexList = dataOut.channelIndexList
637 644 channelList = dataOut.channelList
638 645 else:
639 646 channelIndexList = []
640 647 for channel in channelList:
641 648 if channel not in dataOut.channelList:
642 649 raise ValueError, "Channel %d is not in dataOut.channelList"
643 650 channelIndexList.append(dataOut.channelList.index(channel))
644 651
645 652 factor = dataOut.normFactor
646 653 y = dataOut.getHeiRange()
647 654 x = dataOut.data_spc[channelIndexList,:,:]/factor
648 655 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
649 656 avg = numpy.average(x, axis=1)
650 657
651 658 avgdB = 10*numpy.log10(avg)
652 659
653 660 thisDatetime = dataOut.datatime
654 661 title = "Power Profile"
655 662 xlabel = "dB"
656 663 ylabel = "Range (Km)"
657 664
658 665 if not self.__isConfig:
659 666
660 667 nplots = 1
661 668
662 669 self.setup(idfigure=idfigure,
663 670 nplots=nplots,
664 671 wintitle=wintitle)
665 672
666 673 if ymin == None: ymin = numpy.nanmin(y)
667 674 if ymax == None: ymax = numpy.nanmax(y)
668 675 if xmin == None: xmin = numpy.nanmin(avgdB)*0.9
669 676 if xmax == None: xmax = numpy.nanmax(avgdB)*0.9
670 677
671 678 self.__isConfig = True
672 679
673 680 self.setWinTitle(title)
674 681
675 682
676 683 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
677 684 axes = self.axesList[0]
678 685
679 686 legendlabels = ["channel %d"%x for x in channelList]
680 687 axes.pmultiline(avgdB, y,
681 688 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
682 689 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
683 690 ytick_visible=True, nxticks=5,
684 691 grid='x')
685 692
686 693 self.draw()
687 694
688 695 if save:
689 696 date = thisDatetime.strftime("%Y%m%d")
690 697 if figfile == None:
691 698 figfile = self.getFilename(name = date)
692 699
693 700 self.saveFigure(figpath, figfile)
694 701
695 702 class CoherenceMap(Figure):
696 703 __isConfig = None
697 704 __nsubplots = None
698 705
699 706 WIDTHPROF = None
700 707 HEIGHTPROF = None
701 708 PREFIX = 'cmap'
702 709
703 710 def __init__(self):
704 711 self.timerange = 2*60*60
705 712 self.__isConfig = False
706 713 self.__nsubplots = 1
707 714
708 715 self.WIDTH = 800
709 716 self.HEIGHT = 150
710 717 self.WIDTHPROF = 120
711 718 self.HEIGHTPROF = 0
719 self.counterftp = 0
712 720
713 721 def getSubplots(self):
714 722 ncol = 1
715 723 nrow = self.nplots*2
716 724
717 725 return nrow, ncol
718 726
719 727 def setup(self, idfigure, nplots, wintitle, showprofile=True):
720 728 self.__showprofile = showprofile
721 729 self.nplots = nplots
722 730
723 731 ncolspan = 1
724 732 colspan = 1
725 733 if showprofile:
726 734 ncolspan = 7
727 735 colspan = 6
728 736 self.__nsubplots = 2
729 737
730 738 self.createFigure(idfigure = idfigure,
731 739 wintitle = wintitle,
732 740 widthplot = self.WIDTH + self.WIDTHPROF,
733 741 heightplot = self.HEIGHT + self.HEIGHTPROF)
734 742
735 743 nrow, ncol = self.getSubplots()
736 744
737 745 for y in range(nrow):
738 746 for x in range(ncol):
739 747
740 748 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
741 749
742 750 if showprofile:
743 751 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
744 752
745 753 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
746 754 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
747 755 timerange=None,
748 save=False, figpath='./', figfile=None,
756 save=False, figpath='./', figfile=None, ftp=False, ftpratio=1,
749 757 coherence_cmap='jet', phase_cmap='RdBu_r'):
750 758
751 759 if pairsList == None:
752 760 pairsIndexList = dataOut.pairsIndexList
753 761 else:
754 762 pairsIndexList = []
755 763 for pair in pairsList:
756 764 if pair not in dataOut.pairsList:
757 765 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
758 766 pairsIndexList.append(dataOut.pairsList.index(pair))
759 767
760 768 if timerange != None:
761 769 self.timerange = timerange
762 770
763 771 if pairsIndexList == []:
764 772 return
765 773
766 774 if len(pairsIndexList) > 4:
767 775 pairsIndexList = pairsIndexList[0:4]
768 776
769 777 tmin = None
770 778 tmax = None
771 779 x = dataOut.getTimeRange()
772 780 y = dataOut.getHeiRange()
773 781
774 782 thisDatetime = dataOut.datatime
775 783 title = "CoherenceMap: %s" %(thisDatetime.strftime("%d-%b-%Y"))
776 784 xlabel = ""
777 785 ylabel = "Range (Km)"
778 786
779 787 if not self.__isConfig:
780 788 nplots = len(pairsIndexList)
781 789 self.setup(idfigure=idfigure,
782 790 nplots=nplots,
783 791 wintitle=wintitle,
784 792 showprofile=showprofile)
785 793
786 794 tmin, tmax = self.getTimeLim(x, xmin, xmax)
787 795 if ymin == None: ymin = numpy.nanmin(y)
788 796 if ymax == None: ymax = numpy.nanmax(y)
789 797
790 798 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
791 799
792 800 self.__isConfig = True
793 801
794 802 self.setWinTitle(title)
795 803
796 804 for i in range(self.nplots):
797 805
798 806 pair = dataOut.pairsList[pairsIndexList[i]]
799 807 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
800 808 avgcoherenceComplex = numpy.average(coherenceComplex, axis=0)
801 809 coherence = numpy.abs(avgcoherenceComplex)
802 810 # coherence = numpy.abs(coherenceComplex)
803 811 # avg = numpy.average(coherence, axis=0)
804 812
805 813 z = coherence.reshape((1,-1))
806 814
807 815 counter = 0
808 816
809 817 title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
810 818 axes = self.axesList[i*self.__nsubplots*2]
811 819 axes.pcolor(x, y, z,
812 820 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
813 821 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
814 822 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
815 823
816 824 if self.__showprofile:
817 825 counter += 1
818 826 axes = self.axesList[i*self.__nsubplots*2 + counter]
819 827 axes.pline(coherence, y,
820 828 xmin=0, xmax=1, ymin=ymin, ymax=ymax,
821 829 xlabel='', ylabel='', title='', ticksize=7,
822 830 ytick_visible=False, nxticks=5,
823 831 grid='x')
824 832
825 833 counter += 1
826 834 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
827 835 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
828 836 # avg = numpy.average(phase, axis=0)
829 837 z = phase.reshape((1,-1))
830 838
831 839 title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
832 840 axes = self.axesList[i*self.__nsubplots*2 + counter]
833 841 axes.pcolor(x, y, z,
834 842 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
835 843 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
836 844 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
837 845
838 846 if self.__showprofile:
839 847 counter += 1
840 848 axes = self.axesList[i*self.__nsubplots*2 + counter]
841 849 axes.pline(phase, y,
842 850 xmin=-180, xmax=180, ymin=ymin, ymax=ymax,
843 851 xlabel='', ylabel='', title='', ticksize=7,
844 852 ytick_visible=False, nxticks=4,
845 853 grid='x')
846 854
847 855 self.draw()
848 856
849 857 if save:
850 858
851 859 if figfile == None:
852 860 figfile = self.getFilename(name = self.name)
853 861
854 862 self.saveFigure(figpath, figfile)
855 863
864 self.counterftp += 1
865 if (ftp and (self.counterftp==ftpratio)):
866 figfilename = os.path.join(figpath,figfile)
867 self.sendByFTP(figfilename)
868 self.counterftp = 0
869
856 870 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
857 871 self.__isConfig = False
858 872
859 873 class RTIfromNoise(Figure):
860 874
861 875 __isConfig = None
862 876 __nsubplots = None
863 877
864 878 PREFIX = 'rtinoise'
865 879
866 880 def __init__(self):
867 881
868 882 self.timerange = 24*60*60
869 883 self.__isConfig = False
870 884 self.__nsubplots = 1
871 885
872 886 self.WIDTH = 820
873 887 self.HEIGHT = 200
874 888 self.WIDTHPROF = 120
875 889 self.HEIGHTPROF = 0
876 890 self.xdata = None
877 891 self.ydata = None
878 892
879 893 def getSubplots(self):
880 894
881 895 ncol = 1
882 896 nrow = 1
883 897
884 898 return nrow, ncol
885 899
886 900 def setup(self, idfigure, nplots, wintitle, showprofile=True):
887 901
888 902 self.__showprofile = showprofile
889 903 self.nplots = nplots
890 904
891 905 ncolspan = 7
892 906 colspan = 6
893 907 self.__nsubplots = 2
894 908
895 909 self.createFigure(idfigure = idfigure,
896 910 wintitle = wintitle,
897 911 widthplot = self.WIDTH+self.WIDTHPROF,
898 912 heightplot = self.HEIGHT+self.HEIGHTPROF)
899 913
900 914 nrow, ncol = self.getSubplots()
901 915
902 916 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
903 917
904 918
905 919 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
906 920 xmin=None, xmax=None, ymin=None, ymax=None,
907 921 timerange=None,
908 922 save=False, figpath='./', figfile=None):
909 923
910 924 if channelList == None:
911 925 channelIndexList = dataOut.channelIndexList
912 926 channelList = dataOut.channelList
913 927 else:
914 928 channelIndexList = []
915 929 for channel in channelList:
916 930 if channel not in dataOut.channelList:
917 931 raise ValueError, "Channel %d is not in dataOut.channelList"
918 932 channelIndexList.append(dataOut.channelList.index(channel))
919 933
920 934 if timerange != None:
921 935 self.timerange = timerange
922 936
923 937 tmin = None
924 938 tmax = None
925 939 x = dataOut.getTimeRange()
926 940 y = dataOut.getHeiRange()
927 941 factor = dataOut.normFactor
928 942 noise = dataOut.getNoise()/factor
929 943 noisedB = 10*numpy.log10(noise)
930 944
931 945 thisDatetime = dataOut.datatime
932 946 title = "RTI Noise: %s" %(thisDatetime.strftime("%d-%b-%Y"))
933 947 xlabel = ""
934 948 ylabel = "Range (Km)"
935 949
936 950 if not self.__isConfig:
937 951
938 952 nplots = 1
939 953
940 954 self.setup(idfigure=idfigure,
941 955 nplots=nplots,
942 956 wintitle=wintitle,
943 957 showprofile=showprofile)
944 958
945 959 tmin, tmax = self.getTimeLim(x, xmin, xmax)
946 960 if ymin == None: ymin = numpy.nanmin(noisedB)
947 961 if ymax == None: ymax = numpy.nanmax(noisedB)
948 962
949 963 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
950 964 self.__isConfig = True
951 965
952 966 self.xdata = numpy.array([])
953 967 self.ydata = numpy.array([])
954 968
955 969 self.setWinTitle(title)
956 970
957 971
958 972 title = "RTI Noise %s" %(thisDatetime.strftime("%d-%b-%Y"))
959 973
960 974 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
961 975 axes = self.axesList[0]
962 976
963 977 self.xdata = numpy.hstack((self.xdata, x[0:1]))
964 978
965 979 if len(self.ydata)==0:
966 980 self.ydata = noisedB[channelIndexList].reshape(-1,1)
967 981 else:
968 982 self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1)))
969 983
970 984
971 985 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
972 986 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
973 987 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
974 988 XAxisAsTime=True
975 989 )
976 990
977 991 self.draw()
978 992
979 993 if save:
980 994
981 995 if figfile == None:
982 996 figfile = self.getFilename(name = self.name)
983 997
984 998 self.saveFigure(figpath, figfile)
985 999
986 1000 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
987 1001 self.__isConfig = False
988 1002 del self.xdata
989 1003 del self.ydata
990 1004 No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now