##// END OF EJS Templates
Miguel Valdez -
r825:09aa53a6d71c
parent child
Show More
@@ -1,661 +1,661
1 import os
1 import os
2 import numpy
2 import numpy
3 import time, datetime
3 import time, datetime
4 import mpldriver
4 import mpldriver
5
5
6 from schainpy.model.proc.jroproc_base import Operation
6 from schainpy.model.proc.jroproc_base import Operation
7
7
8 def isTimeInHourRange(datatime, xmin, xmax):
8 def isTimeInHourRange(datatime, xmin, xmax):
9
9
10 if xmin == None or xmax == None:
10 if xmin == None or xmax == None:
11 return 1
11 return 1
12 hour = datatime.hour + datatime.minute/60.0
12 hour = datatime.hour + datatime.minute/60.0
13
13
14 if xmin < (xmax % 24):
14 if xmin < (xmax % 24):
15
15
16 if hour >= xmin and hour <= xmax:
16 if hour >= xmin and hour <= xmax:
17 return 1
17 return 1
18 else:
18 else:
19 return 0
19 return 0
20
20
21 else:
21 else:
22
22
23 if hour >= xmin or hour <= (xmax % 24):
23 if hour >= xmin or hour <= (xmax % 24):
24 return 1
24 return 1
25 else:
25 else:
26 return 0
26 return 0
27
27
28 return 0
28 return 0
29
29
30 def isRealtime(utcdatatime):
30 def isRealtime(utcdatatime):
31
31
32 utcnow = time.mktime(time.localtime())
32 utcnow = time.mktime(time.localtime())
33 delta = abs(utcnow - utcdatatime) # abs
33 delta = abs(utcnow - utcdatatime) # abs
34 if delta >= 30.:
34 if delta >= 30.:
35 return False
35 return False
36 return True
36 return True
37
37
38 class Figure(Operation):
38 class Figure(Operation):
39
39
40 __driver = mpldriver
40 __driver = mpldriver
41 fig = None
41 fig = None
42
42
43 id = None
43 id = None
44 wintitle = None
44 wintitle = None
45 width = None
45 width = None
46 height = None
46 height = None
47 nplots = None
47 nplots = None
48 timerange = None
48 timerange = None
49
49
50 axesObjList = []
50 axesObjList = []
51
51
52 WIDTH = 300
52 WIDTH = 300
53 HEIGHT = 200
53 HEIGHT = 200
54 PREFIX = 'fig'
54 PREFIX = 'fig'
55
55
56 xmin = None
56 xmin = None
57 xmax = None
57 xmax = None
58
58
59 counter_imagwr = 0
59 counter_imagwr = 0
60
60
61 figfile = None
61 figfile = None
62
62
63 created = False
63 created = False
64
64
65 def __init__(self):
65 def __init__(self):
66
66
67 raise NotImplementedError
67 raise NotImplementedError
68
68
69 def __del__(self):
69 def __del__(self):
70
70
71 self.__driver.closeFigure()
71 self.__driver.closeFigure()
72
72
73 def getFilename(self, name, ext='.png'):
73 def getFilename(self, name, ext='.png'):
74
74
75 path = '%s%03d' %(self.PREFIX, self.id)
75 path = '%s%03d' %(self.PREFIX, self.id)
76 filename = '%s_%s%s' %(self.PREFIX, name, ext)
76 filename = '%s_%s%s' %(self.PREFIX, name, ext)
77 return os.path.join(path, filename)
77 return os.path.join(path, filename)
78
78
79 def getAxesObjList(self):
79 def getAxesObjList(self):
80
80
81 return self.axesObjList
81 return self.axesObjList
82
82
83 def getSubplots(self):
83 def getSubplots(self):
84
84
85 raise NotImplementedError
85 raise NotImplementedError
86
86
87 def getScreenDim(self, widthplot, heightplot):
87 def getScreenDim(self, widthplot, heightplot):
88
88
89 nrow, ncol = self.getSubplots()
89 nrow, ncol = self.getSubplots()
90
90
91 widthscreen = widthplot*ncol
91 widthscreen = widthplot*ncol
92 heightscreen = heightplot*nrow
92 heightscreen = heightplot*nrow
93
93
94 return widthscreen, heightscreen
94 return widthscreen, heightscreen
95
95
96 def getTimeLim(self, x, xmin=None, xmax=None, timerange=None):
96 def getTimeLim(self, x, xmin=None, xmax=None, timerange=None):
97
97
98 # if self.xmin != None and self.xmax != None:
98 # if self.xmin != None and self.xmax != None:
99 # if timerange == None:
99 # if timerange == None:
100 # timerange = self.xmax - self.xmin
100 # timerange = self.xmax - self.xmin
101 # xmin = self.xmin + timerange
101 # xmin = self.xmin + timerange
102 # xmax = self.xmax + timerange
102 # xmax = self.xmax + timerange
103 #
103 #
104 # return xmin, xmax
104 # return xmin, xmax
105
105
106 if timerange == None and (xmin==None or xmax==None):
106 if timerange == None and (xmin==None or xmax==None):
107 timerange = 14400 #seconds
107 timerange = 14400 #seconds
108
108
109 if timerange != None:
109 if timerange != None:
110 txmin = x[0] #- x[0] % min(timerange/10, 10*60)
110 txmin = x[0] #- x[0] % min(timerange/10, 10*60)
111 else:
111 else:
112 txmin = x[0] #- x[0] % 10*60
112 txmin = x[0] #- x[0] % 10*60
113
113
114 thisdatetime = datetime.datetime.utcfromtimestamp(txmin)
114 thisdatetime = datetime.datetime.utcfromtimestamp(txmin)
115 thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
115 thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
116
116
117 if timerange != None:
117 if timerange != None:
118 xmin = (thisdatetime - thisdate).seconds/(60*60.)
118 xmin = (thisdatetime - thisdate).seconds/(60*60.)
119 xmax = xmin + timerange/(60*60.)
119 xmax = xmin + timerange/(60*60.)
120
120
121 d1970 = datetime.datetime(1970,1,1)
121 d1970 = datetime.datetime(1970,1,1)
122
122
123 mindt = thisdate + datetime.timedelta(hours=xmin) #- datetime.timedelta(seconds=time.timezone)
123 mindt = thisdate + datetime.timedelta(hours=xmin) #- datetime.timedelta(seconds=time.timezone)
124 xmin_sec = (mindt - d1970).total_seconds() #time.mktime(mindt.timetuple()) - time.timezone
124 xmin_sec = (mindt - d1970).total_seconds() #time.mktime(mindt.timetuple()) - time.timezone
125
125
126 maxdt = thisdate + datetime.timedelta(hours=xmax) #- datetime.timedelta(seconds=time.timezone)
126 maxdt = thisdate + datetime.timedelta(hours=xmax) #- datetime.timedelta(seconds=time.timezone)
127 xmax_sec = (maxdt - d1970).total_seconds() #time.mktime(maxdt.timetuple()) - time.timezone
127 xmax_sec = (maxdt - d1970).total_seconds() #time.mktime(maxdt.timetuple()) - time.timezone
128
128
129 return xmin_sec, xmax_sec
129 return xmin_sec, xmax_sec
130
130
131 def init(self, id, nplots, wintitle):
131 def init(self, id, nplots, wintitle):
132
132
133 raise NotImplementedError, "This method has been replaced with createFigure"
133 raise NotImplementedError, "This method has been replaced by createFigure"
134
134
135 def createFigure(self, id, wintitle, widthplot=None, heightplot=None, show=True):
135 def createFigure(self, id, wintitle, widthplot=None, heightplot=None, show=True):
136
136
137 """
137 """
138 Crea la figura de acuerdo al driver y parametros seleccionados seleccionados.
138 Crea la figura de acuerdo al driver y parametros seleccionados seleccionados.
139 Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH
139 Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH
140 y self.HEIGHT y el numero de subplots (nrow, ncol)
140 y self.HEIGHT y el numero de subplots (nrow, ncol)
141
141
142 Input:
142 Input:
143 id : Los parametros necesarios son
143 id : Los parametros necesarios son
144 wintitle :
144 wintitle :
145
145
146 """
146 """
147
147
148 if widthplot == None:
148 if widthplot == None:
149 widthplot = self.WIDTH
149 widthplot = self.WIDTH
150
150
151 if heightplot == None:
151 if heightplot == None:
152 heightplot = self.HEIGHT
152 heightplot = self.HEIGHT
153
153
154 self.id = id
154 self.id = id
155
155
156 self.wintitle = wintitle
156 self.wintitle = wintitle
157
157
158 self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot)
158 self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot)
159
159
160 # if self.created:
160 # if self.created:
161 # self.__driver.closeFigure(self.fig)
161 # self.__driver.closeFigure(self.fig)
162
162
163 if not self.created:
163 if not self.created:
164 self.fig = self.__driver.createFigure(id=self.id,
164 self.fig = self.__driver.createFigure(id=self.id,
165 wintitle=self.wintitle,
165 wintitle=self.wintitle,
166 width=self.widthscreen,
166 width=self.widthscreen,
167 height=self.heightscreen,
167 height=self.heightscreen,
168 show=show)
168 show=show)
169 else:
169 else:
170 self.__driver.clearFigure(self.fig)
170 self.__driver.clearFigure(self.fig)
171
171
172 self.axesObjList = []
172 self.axesObjList = []
173 self.counter_imagwr = 0
173 self.counter_imagwr = 0
174
174
175 self.created = True
175 self.created = True
176
176
177 def setDriver(self, driver=mpldriver):
177 def setDriver(self, driver=mpldriver):
178
178
179 self.__driver = driver
179 self.__driver = driver
180
180
181 def setTitle(self, title):
181 def setTitle(self, title):
182
182
183 self.__driver.setTitle(self.fig, title)
183 self.__driver.setTitle(self.fig, title)
184
184
185 def setWinTitle(self, title):
185 def setWinTitle(self, title):
186
186
187 self.__driver.setWinTitle(self.fig, title=title)
187 self.__driver.setWinTitle(self.fig, title=title)
188
188
189 def setTextFromAxes(self, text):
189 def setTextFromAxes(self, text):
190
190
191 raise NotImplementedError, "This method has been replaced with Axes.setText"
191 raise NotImplementedError, "This method has been replaced with Axes.setText"
192
192
193 def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan):
193 def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan):
194
194
195 raise NotImplementedError, "This method has been replaced with Axes.addAxes"
195 raise NotImplementedError, "This method has been replaced with Axes.addAxes"
196
196
197 def addAxes(self, *args):
197 def addAxes(self, *args):
198 """
198 """
199
199
200 Input:
200 Input:
201 *args : Los parametros necesarios son
201 *args : Los parametros necesarios son
202 nrow, ncol, xpos, ypos, colspan, rowspan
202 nrow, ncol, xpos, ypos, colspan, rowspan
203 """
203 """
204
204
205 axesObj = Axes(self.fig, *args)
205 axesObj = Axes(self.fig, *args)
206 self.axesObjList.append(axesObj)
206 self.axesObjList.append(axesObj)
207
207
208 def saveFigure(self, figpath, figfile, *args):
208 def saveFigure(self, figpath, figfile, *args):
209
209
210 filename = os.path.join(figpath, figfile)
210 filename = os.path.join(figpath, figfile)
211
211
212 fullpath = os.path.split(filename)[0]
212 fullpath = os.path.split(filename)[0]
213
213
214 if not os.path.exists(fullpath):
214 if not os.path.exists(fullpath):
215 subpath = os.path.split(fullpath)[0]
215 subpath = os.path.split(fullpath)[0]
216
216
217 if not os.path.exists(subpath):
217 if not os.path.exists(subpath):
218 os.mkdir(subpath)
218 os.mkdir(subpath)
219
219
220 os.mkdir(fullpath)
220 os.mkdir(fullpath)
221
221
222 self.__driver.saveFigure(self.fig, filename, *args)
222 self.__driver.saveFigure(self.fig, filename, *args)
223
223
224 def save(self, figpath, figfile=None, save=True, ftp=False, wr_period=1, thisDatetime=None, update_figfile=True):
224 def save(self, figpath, figfile=None, save=True, ftp=False, wr_period=1, thisDatetime=None, update_figfile=True):
225
225
226 self.counter_imagwr += 1
226 self.counter_imagwr += 1
227 if self.counter_imagwr < wr_period:
227 if self.counter_imagwr < wr_period:
228 return
228 return
229
229
230 self.counter_imagwr = 0
230 self.counter_imagwr = 0
231
231
232 if save:
232 if save:
233
233
234 if not figfile:
234 if not figfile:
235
235
236 if not thisDatetime:
236 if not thisDatetime:
237 raise ValueError, "Saving figure: figfile or thisDatetime should be defined"
237 raise ValueError, "Saving figure: figfile or thisDatetime should be defined"
238 return
238 return
239
239
240 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
240 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
241 figfile = self.getFilename(name = str_datetime)
241 figfile = self.getFilename(name = str_datetime)
242
242
243 if self.figfile == None:
243 if self.figfile == None:
244 self.figfile = figfile
244 self.figfile = figfile
245
245
246 if update_figfile:
246 if update_figfile:
247 self.figfile = figfile
247 self.figfile = figfile
248
248
249 # store png plot to local folder
249 # store png plot to local folder
250 self.saveFigure(figpath, self.figfile)
250 self.saveFigure(figpath, self.figfile)
251
251
252
252
253 if not ftp:
253 if not ftp:
254 return
254 return
255
255
256 if not thisDatetime:
256 if not thisDatetime:
257 return
257 return
258
258
259 # store png plot to FTP server according to RT-Web format
259 # store png plot to FTP server according to RT-Web format
260 ftp_filename = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
260 ftp_filename = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
261 # ftp_filename = os.path.join(figpath, name)
261 # ftp_filename = os.path.join(figpath, name)
262 self.saveFigure(figpath, ftp_filename)
262 self.saveFigure(figpath, ftp_filename)
263
263
264 def getNameToFtp(self, thisDatetime, FTP_WEI, EXP_CODE, SUB_EXP_CODE, PLOT_CODE, PLOT_POS):
264 def getNameToFtp(self, thisDatetime, FTP_WEI, EXP_CODE, SUB_EXP_CODE, PLOT_CODE, PLOT_POS):
265 YEAR_STR = '%4.4d'%thisDatetime.timetuple().tm_year
265 YEAR_STR = '%4.4d'%thisDatetime.timetuple().tm_year
266 DOY_STR = '%3.3d'%thisDatetime.timetuple().tm_yday
266 DOY_STR = '%3.3d'%thisDatetime.timetuple().tm_yday
267 FTP_WEI = '%2.2d'%FTP_WEI
267 FTP_WEI = '%2.2d'%FTP_WEI
268 EXP_CODE = '%3.3d'%EXP_CODE
268 EXP_CODE = '%3.3d'%EXP_CODE
269 SUB_EXP_CODE = '%2.2d'%SUB_EXP_CODE
269 SUB_EXP_CODE = '%2.2d'%SUB_EXP_CODE
270 PLOT_CODE = '%2.2d'%PLOT_CODE
270 PLOT_CODE = '%2.2d'%PLOT_CODE
271 PLOT_POS = '%2.2d'%PLOT_POS
271 PLOT_POS = '%2.2d'%PLOT_POS
272 name = YEAR_STR + DOY_STR + FTP_WEI + EXP_CODE + SUB_EXP_CODE + PLOT_CODE + PLOT_POS
272 name = YEAR_STR + DOY_STR + FTP_WEI + EXP_CODE + SUB_EXP_CODE + PLOT_CODE + PLOT_POS
273 return name
273 return name
274
274
275 def draw(self):
275 def draw(self):
276
276
277 self.__driver.draw(self.fig)
277 self.__driver.draw(self.fig)
278
278
279 def run(self):
279 def run(self):
280
280
281 raise NotImplementedError
281 raise NotImplementedError
282
282
283 def close(self, show=False):
283 def close(self, show=False):
284
284
285 self.__driver.closeFigure(show=show, fig=self.fig)
285 self.__driver.closeFigure(show=show, fig=self.fig)
286
286
287 axesList = property(getAxesObjList)
287 axesList = property(getAxesObjList)
288
288
289
289
290 class Axes:
290 class Axes:
291
291
292 __driver = mpldriver
292 __driver = mpldriver
293 fig = None
293 fig = None
294 ax = None
294 ax = None
295 plot = None
295 plot = None
296 __missing = 1E30
296 __missing = 1E30
297 __firsttime = None
297 __firsttime = None
298
298
299 __showprofile = False
299 __showprofile = False
300
300
301 xmin = None
301 xmin = None
302 xmax = None
302 xmax = None
303 ymin = None
303 ymin = None
304 ymax = None
304 ymax = None
305 zmin = None
305 zmin = None
306 zmax = None
306 zmax = None
307
307
308 x_buffer = None
308 x_buffer = None
309 z_buffer = None
309 z_buffer = None
310
310
311 decimationx = None
311 decimationx = None
312 decimationy = None
312 decimationy = None
313
313
314 __MAXNUMX = 200
314 __MAXNUMX = 200
315 __MAXNUMY = 400
315 __MAXNUMY = 400
316
316
317 __MAXNUMTIME = 500
317 __MAXNUMTIME = 500
318
318
319 def __init__(self, *args):
319 def __init__(self, *args):
320
320
321 """
321 """
322
322
323 Input:
323 Input:
324 *args : Los parametros necesarios son
324 *args : Los parametros necesarios son
325 fig, nrow, ncol, xpos, ypos, colspan, rowspan
325 fig, nrow, ncol, xpos, ypos, colspan, rowspan
326 """
326 """
327
327
328 ax = self.__driver.createAxes(*args)
328 ax = self.__driver.createAxes(*args)
329 self.fig = args[0]
329 self.fig = args[0]
330 self.ax = ax
330 self.ax = ax
331 self.plot = None
331 self.plot = None
332
332
333 self.__firsttime = True
333 self.__firsttime = True
334 self.idlineList = []
334 self.idlineList = []
335
335
336 self.x_buffer = numpy.array([])
336 self.x_buffer = numpy.array([])
337 self.z_buffer = numpy.array([])
337 self.z_buffer = numpy.array([])
338
338
339 def setText(self, text):
339 def setText(self, text):
340
340
341 self.__driver.setAxesText(self.ax, text)
341 self.__driver.setAxesText(self.ax, text)
342
342
343 def setXAxisAsTime(self):
343 def setXAxisAsTime(self):
344 pass
344 pass
345
345
346 def pline(self, x, y,
346 def pline(self, x, y,
347 xmin=None, xmax=None,
347 xmin=None, xmax=None,
348 ymin=None, ymax=None,
348 ymin=None, ymax=None,
349 xlabel='', ylabel='',
349 xlabel='', ylabel='',
350 title='',
350 title='',
351 **kwargs):
351 **kwargs):
352
352
353 """
353 """
354
354
355 Input:
355 Input:
356 x :
356 x :
357 y :
357 y :
358 xmin :
358 xmin :
359 xmax :
359 xmax :
360 ymin :
360 ymin :
361 ymax :
361 ymax :
362 xlabel :
362 xlabel :
363 ylabel :
363 ylabel :
364 title :
364 title :
365 **kwargs : Los parametros aceptados son
365 **kwargs : Los parametros aceptados son
366
366
367 ticksize
367 ticksize
368 ytick_visible
368 ytick_visible
369 """
369 """
370
370
371 if self.__firsttime:
371 if self.__firsttime:
372
372
373 if xmin == None: xmin = numpy.nanmin(x)
373 if xmin == None: xmin = numpy.nanmin(x)
374 if xmax == None: xmax = numpy.nanmax(x)
374 if xmax == None: xmax = numpy.nanmax(x)
375 if ymin == None: ymin = numpy.nanmin(y)
375 if ymin == None: ymin = numpy.nanmin(y)
376 if ymax == None: ymax = numpy.nanmax(y)
376 if ymax == None: ymax = numpy.nanmax(y)
377
377
378 self.plot = self.__driver.createPline(self.ax, x, y,
378 self.plot = self.__driver.createPline(self.ax, x, y,
379 xmin, xmax,
379 xmin, xmax,
380 ymin, ymax,
380 ymin, ymax,
381 xlabel=xlabel,
381 xlabel=xlabel,
382 ylabel=ylabel,
382 ylabel=ylabel,
383 title=title,
383 title=title,
384 **kwargs)
384 **kwargs)
385
385
386 self.idlineList.append(0)
386 self.idlineList.append(0)
387 self.__firsttime = False
387 self.__firsttime = False
388 return
388 return
389
389
390 self.__driver.pline(self.plot, x, y, xlabel=xlabel,
390 self.__driver.pline(self.plot, x, y, xlabel=xlabel,
391 ylabel=ylabel,
391 ylabel=ylabel,
392 title=title)
392 title=title)
393
393
394 # self.__driver.pause()
394 # self.__driver.pause()
395
395
396 def addpline(self, x, y, idline, **kwargs):
396 def addpline(self, x, y, idline, **kwargs):
397 lines = self.ax.lines
397 lines = self.ax.lines
398
398
399 if idline in self.idlineList:
399 if idline in self.idlineList:
400 self.__driver.set_linedata(self.ax, x, y, idline)
400 self.__driver.set_linedata(self.ax, x, y, idline)
401
401
402 if idline not in(self.idlineList):
402 if idline not in(self.idlineList):
403 self.__driver.addpline(self.ax, x, y, **kwargs)
403 self.__driver.addpline(self.ax, x, y, **kwargs)
404 self.idlineList.append(idline)
404 self.idlineList.append(idline)
405
405
406 return
406 return
407
407
408 def pmultiline(self, x, y,
408 def pmultiline(self, x, y,
409 xmin=None, xmax=None,
409 xmin=None, xmax=None,
410 ymin=None, ymax=None,
410 ymin=None, ymax=None,
411 xlabel='', ylabel='',
411 xlabel='', ylabel='',
412 title='',
412 title='',
413 **kwargs):
413 **kwargs):
414
414
415 if self.__firsttime:
415 if self.__firsttime:
416
416
417 if xmin == None: xmin = numpy.nanmin(x)
417 if xmin == None: xmin = numpy.nanmin(x)
418 if xmax == None: xmax = numpy.nanmax(x)
418 if xmax == None: xmax = numpy.nanmax(x)
419 if ymin == None: ymin = numpy.nanmin(y)
419 if ymin == None: ymin = numpy.nanmin(y)
420 if ymax == None: ymax = numpy.nanmax(y)
420 if ymax == None: ymax = numpy.nanmax(y)
421
421
422 self.plot = self.__driver.createPmultiline(self.ax, x, y,
422 self.plot = self.__driver.createPmultiline(self.ax, x, y,
423 xmin, xmax,
423 xmin, xmax,
424 ymin, ymax,
424 ymin, ymax,
425 xlabel=xlabel,
425 xlabel=xlabel,
426 ylabel=ylabel,
426 ylabel=ylabel,
427 title=title,
427 title=title,
428 **kwargs)
428 **kwargs)
429 self.__firsttime = False
429 self.__firsttime = False
430 return
430 return
431
431
432 self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel,
432 self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel,
433 ylabel=ylabel,
433 ylabel=ylabel,
434 title=title)
434 title=title)
435
435
436 # self.__driver.pause()
436 # self.__driver.pause()
437
437
438 def pmultilineyaxis(self, x, y,
438 def pmultilineyaxis(self, x, y,
439 xmin=None, xmax=None,
439 xmin=None, xmax=None,
440 ymin=None, ymax=None,
440 ymin=None, ymax=None,
441 xlabel='', ylabel='',
441 xlabel='', ylabel='',
442 title='',
442 title='',
443 **kwargs):
443 **kwargs):
444
444
445 if self.__firsttime:
445 if self.__firsttime:
446
446
447 if xmin == None: xmin = numpy.nanmin(x)
447 if xmin == None: xmin = numpy.nanmin(x)
448 if xmax == None: xmax = numpy.nanmax(x)
448 if xmax == None: xmax = numpy.nanmax(x)
449 if ymin == None: ymin = numpy.nanmin(y)
449 if ymin == None: ymin = numpy.nanmin(y)
450 if ymax == None: ymax = numpy.nanmax(y)
450 if ymax == None: ymax = numpy.nanmax(y)
451
451
452 self.plot = self.__driver.createPmultilineYAxis(self.ax, x, y,
452 self.plot = self.__driver.createPmultilineYAxis(self.ax, x, y,
453 xmin, xmax,
453 xmin, xmax,
454 ymin, ymax,
454 ymin, ymax,
455 xlabel=xlabel,
455 xlabel=xlabel,
456 ylabel=ylabel,
456 ylabel=ylabel,
457 title=title,
457 title=title,
458 **kwargs)
458 **kwargs)
459 if self.xmin == None: self.xmin = xmin
459 if self.xmin == None: self.xmin = xmin
460 if self.xmax == None: self.xmax = xmax
460 if self.xmax == None: self.xmax = xmax
461 if self.ymin == None: self.ymin = ymin
461 if self.ymin == None: self.ymin = ymin
462 if self.ymax == None: self.ymax = ymax
462 if self.ymax == None: self.ymax = ymax
463
463
464 self.__firsttime = False
464 self.__firsttime = False
465 return
465 return
466
466
467 self.__driver.pmultilineyaxis(self.plot, x, y, xlabel=xlabel,
467 self.__driver.pmultilineyaxis(self.plot, x, y, xlabel=xlabel,
468 ylabel=ylabel,
468 ylabel=ylabel,
469 title=title)
469 title=title)
470
470
471 # self.__driver.pause()
471 # self.__driver.pause()
472
472
473 def pcolor(self, x, y, z,
473 def pcolor(self, x, y, z,
474 xmin=None, xmax=None,
474 xmin=None, xmax=None,
475 ymin=None, ymax=None,
475 ymin=None, ymax=None,
476 zmin=None, zmax=None,
476 zmin=None, zmax=None,
477 xlabel='', ylabel='',
477 xlabel='', ylabel='',
478 title='', colormap='jet',
478 title='', colormap='jet',
479 **kwargs):
479 **kwargs):
480
480
481 """
481 """
482 Input:
482 Input:
483 x :
483 x :
484 y :
484 y :
485 x :
485 x :
486 xmin :
486 xmin :
487 xmax :
487 xmax :
488 ymin :
488 ymin :
489 ymax :
489 ymax :
490 zmin :
490 zmin :
491 zmax :
491 zmax :
492 xlabel :
492 xlabel :
493 ylabel :
493 ylabel :
494 title :
494 title :
495 **kwargs : Los parametros aceptados son
495 **kwargs : Los parametros aceptados son
496 ticksize=9,
496 ticksize=9,
497 cblabel=''
497 cblabel=''
498 """
498 """
499
499
500 #Decimating data
500 #Decimating data
501 xlen = len(x)
501 xlen = len(x)
502 ylen = len(y)
502 ylen = len(y)
503
503
504 decimationx = numpy.floor(xlen/self.__MAXNUMX) + 1
504 decimationx = numpy.floor(xlen/self.__MAXNUMX) + 1
505 decimationy = numpy.floor(ylen/self.__MAXNUMY) + 1
505 decimationy = numpy.floor(ylen/self.__MAXNUMY) + 1
506
506
507 x_buffer = x[::decimationx]
507 x_buffer = x[::decimationx]
508 y_buffer = y[::decimationy]
508 y_buffer = y[::decimationy]
509 z_buffer = z[::decimationx, ::decimationy]
509 z_buffer = z[::decimationx, ::decimationy]
510 #===================================================
510 #===================================================
511
511
512 if self.__firsttime:
512 if self.__firsttime:
513
513
514 if xmin == None: xmin = numpy.nanmin(x)
514 if xmin == None: xmin = numpy.nanmin(x)
515 if xmax == None: xmax = numpy.nanmax(x)
515 if xmax == None: xmax = numpy.nanmax(x)
516 if ymin == None: ymin = numpy.nanmin(y)
516 if ymin == None: ymin = numpy.nanmin(y)
517 if ymax == None: ymax = numpy.nanmax(y)
517 if ymax == None: ymax = numpy.nanmax(y)
518 if zmin == None: zmin = numpy.nanmin(z)
518 if zmin == None: zmin = numpy.nanmin(z)
519 if zmax == None: zmax = numpy.nanmax(z)
519 if zmax == None: zmax = numpy.nanmax(z)
520
520
521
521
522 self.plot = self.__driver.createPcolor(self.ax, x_buffer,
522 self.plot = self.__driver.createPcolor(self.ax, x_buffer,
523 y_buffer,
523 y_buffer,
524 z_buffer,
524 z_buffer,
525 xmin, xmax,
525 xmin, xmax,
526 ymin, ymax,
526 ymin, ymax,
527 zmin, zmax,
527 zmin, zmax,
528 xlabel=xlabel,
528 xlabel=xlabel,
529 ylabel=ylabel,
529 ylabel=ylabel,
530 title=title,
530 title=title,
531 colormap=colormap,
531 colormap=colormap,
532 **kwargs)
532 **kwargs)
533
533
534 if self.xmin == None: self.xmin = xmin
534 if self.xmin == None: self.xmin = xmin
535 if self.xmax == None: self.xmax = xmax
535 if self.xmax == None: self.xmax = xmax
536 if self.ymin == None: self.ymin = ymin
536 if self.ymin == None: self.ymin = ymin
537 if self.ymax == None: self.ymax = ymax
537 if self.ymax == None: self.ymax = ymax
538 if self.zmin == None: self.zmin = zmin
538 if self.zmin == None: self.zmin = zmin
539 if self.zmax == None: self.zmax = zmax
539 if self.zmax == None: self.zmax = zmax
540
540
541 self.__firsttime = False
541 self.__firsttime = False
542 return
542 return
543
543
544 self.__driver.pcolor(self.plot,
544 self.__driver.pcolor(self.plot,
545 z_buffer,
545 z_buffer,
546 xlabel=xlabel,
546 xlabel=xlabel,
547 ylabel=ylabel,
547 ylabel=ylabel,
548 title=title)
548 title=title)
549
549
550 # self.__driver.pause()
550 # self.__driver.pause()
551
551
552 def pcolorbuffer(self, x, y, z,
552 def pcolorbuffer(self, x, y, z,
553 xmin=None, xmax=None,
553 xmin=None, xmax=None,
554 ymin=None, ymax=None,
554 ymin=None, ymax=None,
555 zmin=None, zmax=None,
555 zmin=None, zmax=None,
556 xlabel='', ylabel='',
556 xlabel='', ylabel='',
557 title='', rti = True, colormap='jet',
557 title='', rti = True, colormap='jet',
558 maxNumX = None, maxNumY = None,
558 maxNumX = None, maxNumY = None,
559 **kwargs):
559 **kwargs):
560
560
561 if maxNumX == None:
561 if maxNumX == None:
562 maxNumX = self.__MAXNUMTIME
562 maxNumX = self.__MAXNUMTIME
563
563
564 if maxNumY == None:
564 if maxNumY == None:
565 maxNumY = self.__MAXNUMY
565 maxNumY = self.__MAXNUMY
566
566
567 if self.__firsttime:
567 if self.__firsttime:
568 self.z_buffer = z
568 self.z_buffer = z
569 self.x_buffer = numpy.hstack((self.x_buffer, x))
569 self.x_buffer = numpy.hstack((self.x_buffer, x))
570
570
571 if xmin == None: xmin = numpy.nanmin(x)
571 if xmin == None: xmin = numpy.nanmin(x)
572 if xmax == None: xmax = numpy.nanmax(x)
572 if xmax == None: xmax = numpy.nanmax(x)
573 if ymin == None: ymin = numpy.nanmin(y)
573 if ymin == None: ymin = numpy.nanmin(y)
574 if ymax == None: ymax = numpy.nanmax(y)
574 if ymax == None: ymax = numpy.nanmax(y)
575 if zmin == None: zmin = numpy.nanmin(z)
575 if zmin == None: zmin = numpy.nanmin(z)
576 if zmax == None: zmax = numpy.nanmax(z)
576 if zmax == None: zmax = numpy.nanmax(z)
577
577
578
578
579 self.plot = self.__driver.createPcolor(self.ax, self.x_buffer, y, z,
579 self.plot = self.__driver.createPcolor(self.ax, self.x_buffer, y, z,
580 xmin, xmax,
580 xmin, xmax,
581 ymin, ymax,
581 ymin, ymax,
582 zmin, zmax,
582 zmin, zmax,
583 xlabel=xlabel,
583 xlabel=xlabel,
584 ylabel=ylabel,
584 ylabel=ylabel,
585 title=title,
585 title=title,
586 colormap=colormap,
586 colormap=colormap,
587 **kwargs)
587 **kwargs)
588
588
589 if self.xmin == None: self.xmin = xmin
589 if self.xmin == None: self.xmin = xmin
590 if self.xmax == None: self.xmax = xmax
590 if self.xmax == None: self.xmax = xmax
591 if self.ymin == None: self.ymin = ymin
591 if self.ymin == None: self.ymin = ymin
592 if self.ymax == None: self.ymax = ymax
592 if self.ymax == None: self.ymax = ymax
593 if self.zmin == None: self.zmin = zmin
593 if self.zmin == None: self.zmin = zmin
594 if self.zmax == None: self.zmax = zmax
594 if self.zmax == None: self.zmax = zmax
595
595
596 self.__firsttime = False
596 self.__firsttime = False
597 return
597 return
598
598
599 self.x_buffer = numpy.hstack((self.x_buffer[:-1], x[0], x[-1]))
599 self.x_buffer = numpy.hstack((self.x_buffer[:-1], x[0], x[-1]))
600 self.z_buffer = numpy.hstack((self.z_buffer, z))
600 self.z_buffer = numpy.hstack((self.z_buffer, z))
601 z_buffer = self.z_buffer.reshape(-1,len(y))
601 z_buffer = self.z_buffer.reshape(-1,len(y))
602
602
603 #Decimating data
603 #Decimating data
604 xlen = len(self.x_buffer)
604 xlen = len(self.x_buffer)
605 ylen = len(y)
605 ylen = len(y)
606
606
607 decimationx = numpy.floor(xlen/maxNumX) + 1
607 decimationx = numpy.floor(xlen/maxNumX) + 1
608 decimationy = numpy.floor(ylen/maxNumY) + 1
608 decimationy = numpy.floor(ylen/maxNumY) + 1
609
609
610 x_buffer = self.x_buffer[::decimationx]
610 x_buffer = self.x_buffer[::decimationx]
611 y_buffer = y[::decimationy]
611 y_buffer = y[::decimationy]
612 z_buffer = z_buffer[::decimationx, ::decimationy]
612 z_buffer = z_buffer[::decimationx, ::decimationy]
613 #===================================================
613 #===================================================
614
614
615 x_buffer, y_buffer, z_buffer = self.__fillGaps(x_buffer, y_buffer, z_buffer)
615 x_buffer, y_buffer, z_buffer = self.__fillGaps(x_buffer, y_buffer, z_buffer)
616
616
617 self.__driver.addpcolorbuffer(self.ax, x_buffer, y_buffer, z_buffer, self.zmin, self.zmax,
617 self.__driver.addpcolorbuffer(self.ax, x_buffer, y_buffer, z_buffer, self.zmin, self.zmax,
618 xlabel=xlabel,
618 xlabel=xlabel,
619 ylabel=ylabel,
619 ylabel=ylabel,
620 title=title,
620 title=title,
621 colormap=colormap)
621 colormap=colormap)
622
622
623 # self.__driver.pause()
623 # self.__driver.pause()
624
624
625 def polar(self, x, y,
625 def polar(self, x, y,
626 title='', xlabel='',ylabel='',**kwargs):
626 title='', xlabel='',ylabel='',**kwargs):
627
627
628 if self.__firsttime:
628 if self.__firsttime:
629 self.plot = self.__driver.createPolar(self.ax, x, y, title = title, xlabel = xlabel, ylabel = ylabel)
629 self.plot = self.__driver.createPolar(self.ax, x, y, title = title, xlabel = xlabel, ylabel = ylabel)
630 self.__firsttime = False
630 self.__firsttime = False
631 self.x_buffer = x
631 self.x_buffer = x
632 self.y_buffer = y
632 self.y_buffer = y
633 return
633 return
634
634
635 self.x_buffer = numpy.hstack((self.x_buffer,x))
635 self.x_buffer = numpy.hstack((self.x_buffer,x))
636 self.y_buffer = numpy.hstack((self.y_buffer,y))
636 self.y_buffer = numpy.hstack((self.y_buffer,y))
637 self.__driver.polar(self.plot, self.x_buffer, self.y_buffer, xlabel=xlabel,
637 self.__driver.polar(self.plot, self.x_buffer, self.y_buffer, xlabel=xlabel,
638 ylabel=ylabel,
638 ylabel=ylabel,
639 title=title)
639 title=title)
640
640
641 # self.__driver.pause()
641 # self.__driver.pause()
642
642
643 def __fillGaps(self, x_buffer, y_buffer, z_buffer):
643 def __fillGaps(self, x_buffer, y_buffer, z_buffer):
644
644
645 if x_buffer.shape[0] < 2:
645 if x_buffer.shape[0] < 2:
646 return x_buffer, y_buffer, z_buffer
646 return x_buffer, y_buffer, z_buffer
647
647
648 deltas = x_buffer[1:] - x_buffer[0:-1]
648 deltas = x_buffer[1:] - x_buffer[0:-1]
649 x_median = numpy.median(deltas)
649 x_median = numpy.median(deltas)
650
650
651 index = numpy.where(deltas > 5*x_median)
651 index = numpy.where(deltas > 5*x_median)
652
652
653 if len(index[0]) != 0:
653 if len(index[0]) != 0:
654 z_buffer[index[0],::] = self.__missing
654 z_buffer[index[0],::] = self.__missing
655 z_buffer = numpy.ma.masked_inside(z_buffer,0.99*self.__missing,1.01*self.__missing)
655 z_buffer = numpy.ma.masked_inside(z_buffer,0.99*self.__missing,1.01*self.__missing)
656
656
657 return x_buffer, y_buffer, z_buffer
657 return x_buffer, y_buffer, z_buffer
658
658
659
659
660
660
661 No newline at end of file
661
@@ -1,1509 +1,1522
1 '''
1 '''
2 Created on Jul 9, 2014
2 Created on Jul 9, 2014
3
3
4 @author: roj-idl71
4 @author: roj-idl71
5 '''
5 '''
6 import os
6 import os
7 import datetime
7 import datetime
8 import numpy
8 import numpy
9
9
10 from figure import Figure, isRealtime, isTimeInHourRange
10 from figure import Figure, isRealtime, isTimeInHourRange
11 from plotting_codes import *
11 from plotting_codes import *
12
12
13 class SpectraPlot(Figure):
13 class SpectraPlot(Figure):
14
14
15 isConfig = None
15 isConfig = None
16 __nsubplots = None
16 __nsubplots = None
17
17
18 WIDTHPROF = None
18 WIDTHPROF = None
19 HEIGHTPROF = None
19 HEIGHTPROF = None
20 PREFIX = 'spc'
20 PREFIX = 'spc'
21
21
22 def __init__(self):
22 def __init__(self):
23
23
24 self.isConfig = False
24 self.isConfig = False
25 self.__nsubplots = 1
25 self.__nsubplots = 1
26
26
27 self.WIDTH = 250
27 self.WIDTH = 250
28 self.HEIGHT = 250
28 self.HEIGHT = 250
29 self.WIDTHPROF = 120
29 self.WIDTHPROF = 120
30 self.HEIGHTPROF = 0
30 self.HEIGHTPROF = 0
31 self.counter_imagwr = 0
31 self.counter_imagwr = 0
32
32
33 self.PLOT_CODE = SPEC_CODE
33 self.PLOT_CODE = SPEC_CODE
34
34
35 self.FTP_WEI = None
35 self.FTP_WEI = None
36 self.EXP_CODE = None
36 self.EXP_CODE = None
37 self.SUB_EXP_CODE = None
37 self.SUB_EXP_CODE = None
38 self.PLOT_POS = None
38 self.PLOT_POS = None
39
39
40 self.__xfilter_ena = False
40 self.__xfilter_ena = False
41 self.__yfilter_ena = False
41 self.__yfilter_ena = False
42
42
43 def getSubplots(self):
43 def getSubplots(self):
44
44
45 ncol = int(numpy.sqrt(self.nplots)+0.9)
45 ncol = int(numpy.sqrt(self.nplots)+0.9)
46 nrow = int(self.nplots*1./ncol + 0.9)
46 nrow = int(self.nplots*1./ncol + 0.9)
47
47
48 return nrow, ncol
48 return nrow, ncol
49
49
50 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
50 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
51
51
52 self.__showprofile = showprofile
52 self.__showprofile = showprofile
53 self.nplots = nplots
53 self.nplots = nplots
54
54
55 ncolspan = 1
55 ncolspan = 1
56 colspan = 1
56 colspan = 1
57 if showprofile:
57 if showprofile:
58 ncolspan = 3
58 ncolspan = 3
59 colspan = 2
59 colspan = 2
60 self.__nsubplots = 2
60 self.__nsubplots = 2
61
61
62 self.createFigure(id = id,
62 self.createFigure(id = id,
63 wintitle = wintitle,
63 wintitle = wintitle,
64 widthplot = self.WIDTH + self.WIDTHPROF,
64 widthplot = self.WIDTH + self.WIDTHPROF,
65 heightplot = self.HEIGHT + self.HEIGHTPROF,
65 heightplot = self.HEIGHT + self.HEIGHTPROF,
66 show=show)
66 show=show)
67
67
68 nrow, ncol = self.getSubplots()
68 nrow, ncol = self.getSubplots()
69
69
70 counter = 0
70 counter = 0
71 for y in range(nrow):
71 for y in range(nrow):
72 for x in range(ncol):
72 for x in range(ncol):
73
73
74 if counter >= self.nplots:
74 if counter >= self.nplots:
75 break
75 break
76
76
77 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
77 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
78
78
79 if showprofile:
79 if showprofile:
80 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
80 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
81
81
82 counter += 1
82 counter += 1
83
83
84 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
84 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
85 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
85 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
86 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
86 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
87 server=None, folder=None, username=None, password=None,
87 server=None, folder=None, username=None, password=None,
88 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
88 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
89 xaxis="velocity"):
89 xaxis="frequency"):
90
90
91 """
91 """
92
92
93 Input:
93 Input:
94 dataOut :
94 dataOut :
95 id :
95 id :
96 wintitle :
96 wintitle :
97 channelList :
97 channelList :
98 showProfile :
98 showProfile :
99 xmin : None,
99 xmin : None,
100 xmax : None,
100 xmax : None,
101 ymin : None,
101 ymin : None,
102 ymax : None,
102 ymax : None,
103 zmin : None,
103 zmin : None,
104 zmax : None
104 zmax : None
105 """
105 """
106
106
107 if realtime:
107 if realtime:
108 if not(isRealtime(utcdatatime = dataOut.utctime)):
108 if not(isRealtime(utcdatatime = dataOut.utctime)):
109 print 'Skipping this plot function'
109 print 'Skipping this plot function'
110 return
110 return
111
111
112 if channelList == None:
112 if channelList == None:
113 channelIndexList = dataOut.channelIndexList
113 channelIndexList = dataOut.channelIndexList
114 else:
114 else:
115 channelIndexList = []
115 channelIndexList = []
116 for channel in channelList:
116 for channel in channelList:
117 if channel not in dataOut.channelList:
117 if channel not in dataOut.channelList:
118 raise ValueError, "Channel %d is not in dataOut.channelList" %channel
118 raise ValueError, "Channel %d is not in dataOut.channelList" %channel
119 channelIndexList.append(dataOut.channelList.index(channel))
119 channelIndexList.append(dataOut.channelList.index(channel))
120
120
121 factor = dataOut.normFactor
121 factor = dataOut.normFactor
122
122
123 if xaxis == "frequency":
123 if xaxis == "frequency":
124 x = dataOut.getFreqRange(1)/1000.
124 x = dataOut.getFreqRange(1)/1000.
125 xlabel = "Frquency (kHz)"
125 xlabel = "Frequency (kHz)"
126
126
127 elif xaxis == "time":
127 elif xaxis == "time":
128 x = dataOut.getAcfRange(1)
128 x = dataOut.getAcfRange(1)
129 xlabel = "Time (ms)"
129 xlabel = "Time (ms)"
130
130
131 else:
131 else:
132 x = dataOut.getVelRange(1)
132 x = dataOut.getVelRange(1)
133 xlabel = "Velocity (m/s)"
133 xlabel = "Velocity (m/s)"
134
134
135 ylabel = "Range (Km)"
135 ylabel = "Range (Km)"
136
136
137 y = dataOut.getHeiRange()
137 y = dataOut.getHeiRange()
138
138
139 z = dataOut.data_spc/factor
139 z = dataOut.data_spc/factor
140 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
140 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
141 zdB = 10*numpy.log10(z)
141 zdB = 10*numpy.log10(z)
142
142
143 avg = numpy.average(z, axis=1)
143 avg = numpy.average(z, axis=1)
144 avgdB = 10*numpy.log10(avg)
144 avgdB = 10*numpy.log10(avg)
145
145
146 noise = dataOut.getNoise()/factor
146 noise = dataOut.getNoise()/factor
147 noisedB = 10*numpy.log10(noise)
147 noisedB = 10*numpy.log10(noise)
148
148
149 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
149 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
150 title = wintitle + " Spectra"
150 title = wintitle + " Spectra"
151 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
151 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
152 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
152 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
153
153
154 if not self.isConfig:
154 if not self.isConfig:
155
155
156 nplots = len(channelIndexList)
156 nplots = len(channelIndexList)
157
157
158 self.setup(id=id,
158 self.setup(id=id,
159 nplots=nplots,
159 nplots=nplots,
160 wintitle=wintitle,
160 wintitle=wintitle,
161 showprofile=showprofile,
161 showprofile=showprofile,
162 show=show)
162 show=show)
163
163
164 if xmin == None: xmin = numpy.nanmin(x)
164 if xmin == None: xmin = numpy.nanmin(x)
165 if xmax == None: xmax = numpy.nanmax(x)
165 if xmax == None: xmax = numpy.nanmax(x)
166 if ymin == None: ymin = numpy.nanmin(y)
166 if ymin == None: ymin = numpy.nanmin(y)
167 if ymax == None: ymax = numpy.nanmax(y)
167 if ymax == None: ymax = numpy.nanmax(y)
168 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
168 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
169 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
169 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
170
170
171 self.FTP_WEI = ftp_wei
171 self.FTP_WEI = ftp_wei
172 self.EXP_CODE = exp_code
172 self.EXP_CODE = exp_code
173 self.SUB_EXP_CODE = sub_exp_code
173 self.SUB_EXP_CODE = sub_exp_code
174 self.PLOT_POS = plot_pos
174 self.PLOT_POS = plot_pos
175
175
176 self.isConfig = True
176 self.isConfig = True
177
177
178 self.setWinTitle(title)
178 self.setWinTitle(title)
179
179
180 for i in range(self.nplots):
180 for i in range(self.nplots):
181 index = channelIndexList[i]
181 index = channelIndexList[i]
182 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
182 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
183 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime)
183 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime)
184 if len(dataOut.beam.codeList) != 0:
184 if len(dataOut.beam.codeList) != 0:
185 title = "Ch%d:%4.2fdB,%2.2f,%2.2f:%s" %(dataOut.channelList[index], noisedB[index], dataOut.beam.azimuthList[index], dataOut.beam.zenithList[index], str_datetime)
185 title = "Ch%d:%4.2fdB,%2.2f,%2.2f:%s" %(dataOut.channelList[index], noisedB[index], dataOut.beam.azimuthList[index], dataOut.beam.zenithList[index], str_datetime)
186
186
187 axes = self.axesList[i*self.__nsubplots]
187 axes = self.axesList[i*self.__nsubplots]
188 axes.pcolor(x, y, zdB[index,:,:],
188 axes.pcolor(x, y, zdB[index,:,:],
189 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
189 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
190 xlabel=xlabel, ylabel=ylabel, title=title,
190 xlabel=xlabel, ylabel=ylabel, title=title,
191 ticksize=9, cblabel='')
191 ticksize=9, cblabel='')
192
192
193 if self.__showprofile:
193 if self.__showprofile:
194 axes = self.axesList[i*self.__nsubplots +1]
194 axes = self.axesList[i*self.__nsubplots +1]
195 axes.pline(avgdB[index,:], y,
195 axes.pline(avgdB[index,:], y,
196 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
196 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
197 xlabel='dB', ylabel='', title='',
197 xlabel='dB', ylabel='', title='',
198 ytick_visible=False,
198 ytick_visible=False,
199 grid='x')
199 grid='x')
200
200
201 noiseline = numpy.repeat(noisedB[index], len(y))
201 noiseline = numpy.repeat(noisedB[index], len(y))
202 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
202 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
203
203
204 self.draw()
204 self.draw()
205
205
206 if figfile == None:
206 if figfile == None:
207 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
207 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
208 name = str_datetime
208 name = str_datetime
209 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
209 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
210 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
210 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
211 figfile = self.getFilename(name)
211 figfile = self.getFilename(name)
212
212
213 self.save(figpath=figpath,
213 self.save(figpath=figpath,
214 figfile=figfile,
214 figfile=figfile,
215 save=save,
215 save=save,
216 ftp=ftp,
216 ftp=ftp,
217 wr_period=wr_period,
217 wr_period=wr_period,
218 thisDatetime=thisDatetime)
218 thisDatetime=thisDatetime)
219
219
220 class CrossSpectraPlot(Figure):
220 class CrossSpectraPlot(Figure):
221
221
222 isConfig = None
222 isConfig = None
223 __nsubplots = None
223 __nsubplots = None
224
224
225 WIDTH = None
225 WIDTH = None
226 HEIGHT = None
226 HEIGHT = None
227 WIDTHPROF = None
227 WIDTHPROF = None
228 HEIGHTPROF = None
228 HEIGHTPROF = None
229 PREFIX = 'cspc'
229 PREFIX = 'cspc'
230
230
231 def __init__(self):
231 def __init__(self):
232
232
233 self.isConfig = False
233 self.isConfig = False
234 self.__nsubplots = 4
234 self.__nsubplots = 4
235 self.counter_imagwr = 0
235 self.counter_imagwr = 0
236 self.WIDTH = 250
236 self.WIDTH = 250
237 self.HEIGHT = 250
237 self.HEIGHT = 250
238 self.WIDTHPROF = 0
238 self.WIDTHPROF = 0
239 self.HEIGHTPROF = 0
239 self.HEIGHTPROF = 0
240
240
241 self.PLOT_CODE = CROSS_CODE
241 self.PLOT_CODE = CROSS_CODE
242 self.FTP_WEI = None
242 self.FTP_WEI = None
243 self.EXP_CODE = None
243 self.EXP_CODE = None
244 self.SUB_EXP_CODE = None
244 self.SUB_EXP_CODE = None
245 self.PLOT_POS = None
245 self.PLOT_POS = None
246
246
247 def getSubplots(self):
247 def getSubplots(self):
248
248
249 ncol = 4
249 ncol = 4
250 nrow = self.nplots
250 nrow = self.nplots
251
251
252 return nrow, ncol
252 return nrow, ncol
253
253
254 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
254 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
255
255
256 self.__showprofile = showprofile
256 self.__showprofile = showprofile
257 self.nplots = nplots
257 self.nplots = nplots
258
258
259 ncolspan = 1
259 ncolspan = 1
260 colspan = 1
260 colspan = 1
261
261
262 self.createFigure(id = id,
262 self.createFigure(id = id,
263 wintitle = wintitle,
263 wintitle = wintitle,
264 widthplot = self.WIDTH + self.WIDTHPROF,
264 widthplot = self.WIDTH + self.WIDTHPROF,
265 heightplot = self.HEIGHT + self.HEIGHTPROF,
265 heightplot = self.HEIGHT + self.HEIGHTPROF,
266 show=True)
266 show=True)
267
267
268 nrow, ncol = self.getSubplots()
268 nrow, ncol = self.getSubplots()
269
269
270 counter = 0
270 counter = 0
271 for y in range(nrow):
271 for y in range(nrow):
272 for x in range(ncol):
272 for x in range(ncol):
273 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
273 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
274
274
275 counter += 1
275 counter += 1
276
276
277 def run(self, dataOut, id, wintitle="", pairsList=None,
277 def run(self, dataOut, id, wintitle="", pairsList=None,
278 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
278 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
279 coh_min=None, coh_max=None, phase_min=None, phase_max=None,
279 coh_min=None, coh_max=None, phase_min=None, phase_max=None,
280 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
280 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
281 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
281 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
282 server=None, folder=None, username=None, password=None,
282 server=None, folder=None, username=None, password=None,
283 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
283 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0,
284 xaxis='frequency'):
284
285
285 """
286 """
286
287
287 Input:
288 Input:
288 dataOut :
289 dataOut :
289 id :
290 id :
290 wintitle :
291 wintitle :
291 channelList :
292 channelList :
292 showProfile :
293 showProfile :
293 xmin : None,
294 xmin : None,
294 xmax : None,
295 xmax : None,
295 ymin : None,
296 ymin : None,
296 ymax : None,
297 ymax : None,
297 zmin : None,
298 zmin : None,
298 zmax : None
299 zmax : None
299 """
300 """
300
301
301 if pairsList == None:
302 if pairsList == None:
302 pairsIndexList = dataOut.pairsIndexList
303 pairsIndexList = dataOut.pairsIndexList
303 else:
304 else:
304 pairsIndexList = []
305 pairsIndexList = []
305 for pair in pairsList:
306 for pair in pairsList:
306 if pair not in dataOut.pairsList:
307 if pair not in dataOut.pairsList:
307 raise ValueError, "Pair %s is not in dataOut.pairsList" %str(pair)
308 raise ValueError, "Pair %s is not in dataOut.pairsList" %str(pair)
308 pairsIndexList.append(dataOut.pairsList.index(pair))
309 pairsIndexList.append(dataOut.pairsList.index(pair))
309
310
310 if not pairsIndexList:
311 if not pairsIndexList:
311 return
312 return
312
313
313 if len(pairsIndexList) > 4:
314 if len(pairsIndexList) > 4:
314 pairsIndexList = pairsIndexList[0:4]
315 pairsIndexList = pairsIndexList[0:4]
315
316
316 factor = dataOut.normFactor
317 factor = dataOut.normFactor
317 x = dataOut.getVelRange(1)
318 x = dataOut.getVelRange(1)
318 y = dataOut.getHeiRange()
319 y = dataOut.getHeiRange()
319 z = dataOut.data_spc[:,:,:]/factor
320 z = dataOut.data_spc[:,:,:]/factor
320 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
321 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
321
322
322 noise = dataOut.noise/factor
323 noise = dataOut.noise/factor
323
324
324 zdB = 10*numpy.log10(z)
325 zdB = 10*numpy.log10(z)
325 noisedB = 10*numpy.log10(noise)
326 noisedB = 10*numpy.log10(noise)
326
327
327 if coh_min == None:
328 if coh_min == None:
328 coh_min = 0.0
329 coh_min = 0.0
329 if coh_max == None:
330 if coh_max == None:
330 coh_max = 1.0
331 coh_max = 1.0
331
332
332 if phase_min == None:
333 if phase_min == None:
333 phase_min = -180
334 phase_min = -180
334 if phase_max == None:
335 if phase_max == None:
335 phase_max = 180
336 phase_max = 180
336
337
337 #thisDatetime = dataOut.datatime
338 #thisDatetime = dataOut.datatime
338 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
339 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
339 title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
340 title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
340 xlabel = "Velocity (m/s)"
341 # xlabel = "Velocity (m/s)"
341 ylabel = "Range (Km)"
342 ylabel = "Range (Km)"
342
343
344 if xaxis == "frequency":
345 x = dataOut.getFreqRange(1)/1000.
346 xlabel = "Frequency (kHz)"
347
348 elif xaxis == "time":
349 x = dataOut.getAcfRange(1)
350 xlabel = "Time (ms)"
351
352 else:
353 x = dataOut.getVelRange(1)
354 xlabel = "Velocity (m/s)"
355
343 if not self.isConfig:
356 if not self.isConfig:
344
357
345 nplots = len(pairsIndexList)
358 nplots = len(pairsIndexList)
346
359
347 self.setup(id=id,
360 self.setup(id=id,
348 nplots=nplots,
361 nplots=nplots,
349 wintitle=wintitle,
362 wintitle=wintitle,
350 showprofile=False,
363 showprofile=False,
351 show=show)
364 show=show)
352
365
353 avg = numpy.abs(numpy.average(z, axis=1))
366 avg = numpy.abs(numpy.average(z, axis=1))
354 avgdB = 10*numpy.log10(avg)
367 avgdB = 10*numpy.log10(avg)
355
368
356 if xmin == None: xmin = numpy.nanmin(x)
369 if xmin == None: xmin = numpy.nanmin(x)
357 if xmax == None: xmax = numpy.nanmax(x)
370 if xmax == None: xmax = numpy.nanmax(x)
358 if ymin == None: ymin = numpy.nanmin(y)
371 if ymin == None: ymin = numpy.nanmin(y)
359 if ymax == None: ymax = numpy.nanmax(y)
372 if ymax == None: ymax = numpy.nanmax(y)
360 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
373 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
361 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
374 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
362
375
363 self.FTP_WEI = ftp_wei
376 self.FTP_WEI = ftp_wei
364 self.EXP_CODE = exp_code
377 self.EXP_CODE = exp_code
365 self.SUB_EXP_CODE = sub_exp_code
378 self.SUB_EXP_CODE = sub_exp_code
366 self.PLOT_POS = plot_pos
379 self.PLOT_POS = plot_pos
367
380
368 self.isConfig = True
381 self.isConfig = True
369
382
370 self.setWinTitle(title)
383 self.setWinTitle(title)
371
384
372 for i in range(self.nplots):
385 for i in range(self.nplots):
373 pair = dataOut.pairsList[pairsIndexList[i]]
386 pair = dataOut.pairsList[pairsIndexList[i]]
374
387
375 chan_index0 = dataOut.channelList.index(pair[0])
388 chan_index0 = dataOut.channelList.index(pair[0])
376 chan_index1 = dataOut.channelList.index(pair[1])
389 chan_index1 = dataOut.channelList.index(pair[1])
377
390
378 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
391 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
379 title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[chan_index0], str_datetime)
392 title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[chan_index0], str_datetime)
380 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index0,:,:]/factor)
393 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index0,:,:]/factor)
381 axes0 = self.axesList[i*self.__nsubplots]
394 axes0 = self.axesList[i*self.__nsubplots]
382 axes0.pcolor(x, y, zdB,
395 axes0.pcolor(x, y, zdB,
383 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
396 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
384 xlabel=xlabel, ylabel=ylabel, title=title,
397 xlabel=xlabel, ylabel=ylabel, title=title,
385 ticksize=9, colormap=power_cmap, cblabel='')
398 ticksize=9, colormap=power_cmap, cblabel='')
386
399
387 title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[chan_index1], str_datetime)
400 title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[chan_index1], str_datetime)
388 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index1,:,:]/factor)
401 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index1,:,:]/factor)
389 axes0 = self.axesList[i*self.__nsubplots+1]
402 axes0 = self.axesList[i*self.__nsubplots+1]
390 axes0.pcolor(x, y, zdB,
403 axes0.pcolor(x, y, zdB,
391 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
404 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
392 xlabel=xlabel, ylabel=ylabel, title=title,
405 xlabel=xlabel, ylabel=ylabel, title=title,
393 ticksize=9, colormap=power_cmap, cblabel='')
406 ticksize=9, colormap=power_cmap, cblabel='')
394
407
395 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[chan_index0,:,:]*dataOut.data_spc[chan_index1,:,:])
408 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[chan_index0,:,:]*dataOut.data_spc[chan_index1,:,:])
396 coherence = numpy.abs(coherenceComplex)
409 coherence = numpy.abs(coherenceComplex)
397 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
410 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
398 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
411 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
399
412
400 title = "Coherence Ch%d * Ch%d" %(pair[0], pair[1])
413 title = "Coherence Ch%d * Ch%d" %(pair[0], pair[1])
401 axes0 = self.axesList[i*self.__nsubplots+2]
414 axes0 = self.axesList[i*self.__nsubplots+2]
402 axes0.pcolor(x, y, coherence,
415 axes0.pcolor(x, y, coherence,
403 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=coh_min, zmax=coh_max,
416 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=coh_min, zmax=coh_max,
404 xlabel=xlabel, ylabel=ylabel, title=title,
417 xlabel=xlabel, ylabel=ylabel, title=title,
405 ticksize=9, colormap=coherence_cmap, cblabel='')
418 ticksize=9, colormap=coherence_cmap, cblabel='')
406
419
407 title = "Phase Ch%d * Ch%d" %(pair[0], pair[1])
420 title = "Phase Ch%d * Ch%d" %(pair[0], pair[1])
408 axes0 = self.axesList[i*self.__nsubplots+3]
421 axes0 = self.axesList[i*self.__nsubplots+3]
409 axes0.pcolor(x, y, phase,
422 axes0.pcolor(x, y, phase,
410 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
423 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
411 xlabel=xlabel, ylabel=ylabel, title=title,
424 xlabel=xlabel, ylabel=ylabel, title=title,
412 ticksize=9, colormap=phase_cmap, cblabel='')
425 ticksize=9, colormap=phase_cmap, cblabel='')
413
426
414
427
415
428
416 self.draw()
429 self.draw()
417
430
418 self.save(figpath=figpath,
431 self.save(figpath=figpath,
419 figfile=figfile,
432 figfile=figfile,
420 save=save,
433 save=save,
421 ftp=ftp,
434 ftp=ftp,
422 wr_period=wr_period,
435 wr_period=wr_period,
423 thisDatetime=thisDatetime)
436 thisDatetime=thisDatetime)
424
437
425
438
426 class RTIPlot(Figure):
439 class RTIPlot(Figure):
427
440
428 __isConfig = None
441 __isConfig = None
429 __nsubplots = None
442 __nsubplots = None
430
443
431 WIDTHPROF = None
444 WIDTHPROF = None
432 HEIGHTPROF = None
445 HEIGHTPROF = None
433 PREFIX = 'rti'
446 PREFIX = 'rti'
434
447
435 def __init__(self):
448 def __init__(self):
436
449
437 self.timerange = None
450 self.timerange = None
438 self.isConfig = False
451 self.isConfig = False
439 self.__nsubplots = 1
452 self.__nsubplots = 1
440
453
441 self.WIDTH = 800
454 self.WIDTH = 800
442 self.HEIGHT = 180
455 self.HEIGHT = 180
443 self.WIDTHPROF = 120
456 self.WIDTHPROF = 120
444 self.HEIGHTPROF = 0
457 self.HEIGHTPROF = 0
445 self.counter_imagwr = 0
458 self.counter_imagwr = 0
446
459
447 self.PLOT_CODE = RTI_CODE
460 self.PLOT_CODE = RTI_CODE
448
461
449 self.FTP_WEI = None
462 self.FTP_WEI = None
450 self.EXP_CODE = None
463 self.EXP_CODE = None
451 self.SUB_EXP_CODE = None
464 self.SUB_EXP_CODE = None
452 self.PLOT_POS = None
465 self.PLOT_POS = None
453 self.tmin = None
466 self.tmin = None
454 self.tmax = None
467 self.tmax = None
455
468
456 self.xmin = None
469 self.xmin = None
457 self.xmax = None
470 self.xmax = None
458
471
459 self.figfile = None
472 self.figfile = None
460
473
461 def getSubplots(self):
474 def getSubplots(self):
462
475
463 ncol = 1
476 ncol = 1
464 nrow = self.nplots
477 nrow = self.nplots
465
478
466 return nrow, ncol
479 return nrow, ncol
467
480
468 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
481 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
469
482
470 self.__showprofile = showprofile
483 self.__showprofile = showprofile
471 self.nplots = nplots
484 self.nplots = nplots
472
485
473 ncolspan = 1
486 ncolspan = 1
474 colspan = 1
487 colspan = 1
475 if showprofile:
488 if showprofile:
476 ncolspan = 7
489 ncolspan = 7
477 colspan = 6
490 colspan = 6
478 self.__nsubplots = 2
491 self.__nsubplots = 2
479
492
480 self.createFigure(id = id,
493 self.createFigure(id = id,
481 wintitle = wintitle,
494 wintitle = wintitle,
482 widthplot = self.WIDTH + self.WIDTHPROF,
495 widthplot = self.WIDTH + self.WIDTHPROF,
483 heightplot = self.HEIGHT + self.HEIGHTPROF,
496 heightplot = self.HEIGHT + self.HEIGHTPROF,
484 show=show)
497 show=show)
485
498
486 nrow, ncol = self.getSubplots()
499 nrow, ncol = self.getSubplots()
487
500
488 counter = 0
501 counter = 0
489 for y in range(nrow):
502 for y in range(nrow):
490 for x in range(ncol):
503 for x in range(ncol):
491
504
492 if counter >= self.nplots:
505 if counter >= self.nplots:
493 break
506 break
494
507
495 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
508 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
496
509
497 if showprofile:
510 if showprofile:
498 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
511 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
499
512
500 counter += 1
513 counter += 1
501
514
502 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
515 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
503 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
516 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
504 timerange=None,
517 timerange=None,
505 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
518 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
506 server=None, folder=None, username=None, password=None,
519 server=None, folder=None, username=None, password=None,
507 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
520 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
508
521
509 """
522 """
510
523
511 Input:
524 Input:
512 dataOut :
525 dataOut :
513 id :
526 id :
514 wintitle :
527 wintitle :
515 channelList :
528 channelList :
516 showProfile :
529 showProfile :
517 xmin : None,
530 xmin : None,
518 xmax : None,
531 xmax : None,
519 ymin : None,
532 ymin : None,
520 ymax : None,
533 ymax : None,
521 zmin : None,
534 zmin : None,
522 zmax : None
535 zmax : None
523 """
536 """
524
537
525 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
538 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
526 return
539 return
527
540
528 if channelList == None:
541 if channelList == None:
529 channelIndexList = dataOut.channelIndexList
542 channelIndexList = dataOut.channelIndexList
530 else:
543 else:
531 channelIndexList = []
544 channelIndexList = []
532 for channel in channelList:
545 for channel in channelList:
533 if channel not in dataOut.channelList:
546 if channel not in dataOut.channelList:
534 raise ValueError, "Channel %d is not in dataOut.channelList"
547 raise ValueError, "Channel %d is not in dataOut.channelList"
535 channelIndexList.append(dataOut.channelList.index(channel))
548 channelIndexList.append(dataOut.channelList.index(channel))
536
549
537 factor = dataOut.normFactor
550 factor = dataOut.normFactor
538 x = dataOut.getTimeRange()
551 x = dataOut.getTimeRange()
539 y = dataOut.getHeiRange()
552 y = dataOut.getHeiRange()
540
553
541 z = dataOut.data_spc/factor
554 z = dataOut.data_spc/factor
542 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
555 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
543 avg = numpy.average(z, axis=1)
556 avg = numpy.average(z, axis=1)
544
557
545 avgdB = 10.*numpy.log10(avg)
558 avgdB = 10.*numpy.log10(avg)
546
559
547 thisDatetime = dataOut.datatime
560 thisDatetime = dataOut.datatime
548 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
561 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
549 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
562 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
550 xlabel = ""
563 xlabel = ""
551 ylabel = "Range (Km)"
564 ylabel = "Range (Km)"
552
565
553 update_figfile = False
566 update_figfile = False
554
567
555 if dataOut.ltctime >= self.xmax:
568 if dataOut.ltctime >= self.xmax:
556 self.counter_imagwr = wr_period
569 self.counter_imagwr = wr_period
557 self.isConfig = False
570 self.isConfig = False
558 update_figfile = True
571 update_figfile = True
559
572
560 if not self.isConfig:
573 if not self.isConfig:
561
574
562 nplots = len(channelIndexList)
575 nplots = len(channelIndexList)
563
576
564 self.setup(id=id,
577 self.setup(id=id,
565 nplots=nplots,
578 nplots=nplots,
566 wintitle=wintitle,
579 wintitle=wintitle,
567 showprofile=showprofile,
580 showprofile=showprofile,
568 show=show)
581 show=show)
569
582
570 if timerange != None:
583 if timerange != None:
571 self.timerange = timerange
584 self.timerange = timerange
572
585
573 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
586 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
574
587
575 noise = dataOut.noise/factor
588 noise = dataOut.noise/factor
576 noisedB = 10*numpy.log10(noise)
589 noisedB = 10*numpy.log10(noise)
577
590
578 if ymin == None: ymin = numpy.nanmin(y)
591 if ymin == None: ymin = numpy.nanmin(y)
579 if ymax == None: ymax = numpy.nanmax(y)
592 if ymax == None: ymax = numpy.nanmax(y)
580 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
593 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
581 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
594 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
582
595
583 self.FTP_WEI = ftp_wei
596 self.FTP_WEI = ftp_wei
584 self.EXP_CODE = exp_code
597 self.EXP_CODE = exp_code
585 self.SUB_EXP_CODE = sub_exp_code
598 self.SUB_EXP_CODE = sub_exp_code
586 self.PLOT_POS = plot_pos
599 self.PLOT_POS = plot_pos
587
600
588 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
601 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
589 self.isConfig = True
602 self.isConfig = True
590 self.figfile = figfile
603 self.figfile = figfile
591 update_figfile = True
604 update_figfile = True
592
605
593 self.setWinTitle(title)
606 self.setWinTitle(title)
594
607
595 for i in range(self.nplots):
608 for i in range(self.nplots):
596 index = channelIndexList[i]
609 index = channelIndexList[i]
597 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
610 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
598 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
611 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
599 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
612 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
600 axes = self.axesList[i*self.__nsubplots]
613 axes = self.axesList[i*self.__nsubplots]
601 zdB = avgdB[index].reshape((1,-1))
614 zdB = avgdB[index].reshape((1,-1))
602 axes.pcolorbuffer(x, y, zdB,
615 axes.pcolorbuffer(x, y, zdB,
603 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
616 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
604 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
617 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
605 ticksize=9, cblabel='', cbsize="1%")
618 ticksize=9, cblabel='', cbsize="1%")
606
619
607 if self.__showprofile:
620 if self.__showprofile:
608 axes = self.axesList[i*self.__nsubplots +1]
621 axes = self.axesList[i*self.__nsubplots +1]
609 axes.pline(avgdB[index], y,
622 axes.pline(avgdB[index], y,
610 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
623 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
611 xlabel='dB', ylabel='', title='',
624 xlabel='dB', ylabel='', title='',
612 ytick_visible=False,
625 ytick_visible=False,
613 grid='x')
626 grid='x')
614
627
615 self.draw()
628 self.draw()
616
629
617 self.save(figpath=figpath,
630 self.save(figpath=figpath,
618 figfile=figfile,
631 figfile=figfile,
619 save=save,
632 save=save,
620 ftp=ftp,
633 ftp=ftp,
621 wr_period=wr_period,
634 wr_period=wr_period,
622 thisDatetime=thisDatetime,
635 thisDatetime=thisDatetime,
623 update_figfile=update_figfile)
636 update_figfile=update_figfile)
624
637
625 class CoherenceMap(Figure):
638 class CoherenceMap(Figure):
626 isConfig = None
639 isConfig = None
627 __nsubplots = None
640 __nsubplots = None
628
641
629 WIDTHPROF = None
642 WIDTHPROF = None
630 HEIGHTPROF = None
643 HEIGHTPROF = None
631 PREFIX = 'cmap'
644 PREFIX = 'cmap'
632
645
633 def __init__(self):
646 def __init__(self):
634 self.timerange = 2*60*60
647 self.timerange = 2*60*60
635 self.isConfig = False
648 self.isConfig = False
636 self.__nsubplots = 1
649 self.__nsubplots = 1
637
650
638 self.WIDTH = 800
651 self.WIDTH = 800
639 self.HEIGHT = 180
652 self.HEIGHT = 180
640 self.WIDTHPROF = 120
653 self.WIDTHPROF = 120
641 self.HEIGHTPROF = 0
654 self.HEIGHTPROF = 0
642 self.counter_imagwr = 0
655 self.counter_imagwr = 0
643
656
644 self.PLOT_CODE = COH_CODE
657 self.PLOT_CODE = COH_CODE
645
658
646 self.FTP_WEI = None
659 self.FTP_WEI = None
647 self.EXP_CODE = None
660 self.EXP_CODE = None
648 self.SUB_EXP_CODE = None
661 self.SUB_EXP_CODE = None
649 self.PLOT_POS = None
662 self.PLOT_POS = None
650 self.counter_imagwr = 0
663 self.counter_imagwr = 0
651
664
652 self.xmin = None
665 self.xmin = None
653 self.xmax = None
666 self.xmax = None
654
667
655 def getSubplots(self):
668 def getSubplots(self):
656 ncol = 1
669 ncol = 1
657 nrow = self.nplots*2
670 nrow = self.nplots*2
658
671
659 return nrow, ncol
672 return nrow, ncol
660
673
661 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
674 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
662 self.__showprofile = showprofile
675 self.__showprofile = showprofile
663 self.nplots = nplots
676 self.nplots = nplots
664
677
665 ncolspan = 1
678 ncolspan = 1
666 colspan = 1
679 colspan = 1
667 if showprofile:
680 if showprofile:
668 ncolspan = 7
681 ncolspan = 7
669 colspan = 6
682 colspan = 6
670 self.__nsubplots = 2
683 self.__nsubplots = 2
671
684
672 self.createFigure(id = id,
685 self.createFigure(id = id,
673 wintitle = wintitle,
686 wintitle = wintitle,
674 widthplot = self.WIDTH + self.WIDTHPROF,
687 widthplot = self.WIDTH + self.WIDTHPROF,
675 heightplot = self.HEIGHT + self.HEIGHTPROF,
688 heightplot = self.HEIGHT + self.HEIGHTPROF,
676 show=True)
689 show=True)
677
690
678 nrow, ncol = self.getSubplots()
691 nrow, ncol = self.getSubplots()
679
692
680 for y in range(nrow):
693 for y in range(nrow):
681 for x in range(ncol):
694 for x in range(ncol):
682
695
683 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
696 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
684
697
685 if showprofile:
698 if showprofile:
686 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
699 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
687
700
688 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
701 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
689 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
702 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
690 timerange=None, phase_min=None, phase_max=None,
703 timerange=None, phase_min=None, phase_max=None,
691 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
704 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
692 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
705 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
693 server=None, folder=None, username=None, password=None,
706 server=None, folder=None, username=None, password=None,
694 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
707 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
695
708
696 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
709 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
697 return
710 return
698
711
699 if pairsList == None:
712 if pairsList == None:
700 pairsIndexList = dataOut.pairsIndexList
713 pairsIndexList = dataOut.pairsIndexList
701 else:
714 else:
702 pairsIndexList = []
715 pairsIndexList = []
703 for pair in pairsList:
716 for pair in pairsList:
704 if pair not in dataOut.pairsList:
717 if pair not in dataOut.pairsList:
705 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
718 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
706 pairsIndexList.append(dataOut.pairsList.index(pair))
719 pairsIndexList.append(dataOut.pairsList.index(pair))
707
720
708 if pairsIndexList == []:
721 if pairsIndexList == []:
709 return
722 return
710
723
711 if len(pairsIndexList) > 4:
724 if len(pairsIndexList) > 4:
712 pairsIndexList = pairsIndexList[0:4]
725 pairsIndexList = pairsIndexList[0:4]
713
726
714 if phase_min == None:
727 if phase_min == None:
715 phase_min = -180
728 phase_min = -180
716 if phase_max == None:
729 if phase_max == None:
717 phase_max = 180
730 phase_max = 180
718
731
719 x = dataOut.getTimeRange()
732 x = dataOut.getTimeRange()
720 y = dataOut.getHeiRange()
733 y = dataOut.getHeiRange()
721
734
722 thisDatetime = dataOut.datatime
735 thisDatetime = dataOut.datatime
723
736
724 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
737 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
725 xlabel = ""
738 xlabel = ""
726 ylabel = "Range (Km)"
739 ylabel = "Range (Km)"
727 update_figfile = False
740 update_figfile = False
728
741
729 if not self.isConfig:
742 if not self.isConfig:
730 nplots = len(pairsIndexList)
743 nplots = len(pairsIndexList)
731 self.setup(id=id,
744 self.setup(id=id,
732 nplots=nplots,
745 nplots=nplots,
733 wintitle=wintitle,
746 wintitle=wintitle,
734 showprofile=showprofile,
747 showprofile=showprofile,
735 show=show)
748 show=show)
736
749
737 if timerange != None:
750 if timerange != None:
738 self.timerange = timerange
751 self.timerange = timerange
739
752
740 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
753 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
741
754
742 if ymin == None: ymin = numpy.nanmin(y)
755 if ymin == None: ymin = numpy.nanmin(y)
743 if ymax == None: ymax = numpy.nanmax(y)
756 if ymax == None: ymax = numpy.nanmax(y)
744 if zmin == None: zmin = 0.
757 if zmin == None: zmin = 0.
745 if zmax == None: zmax = 1.
758 if zmax == None: zmax = 1.
746
759
747 self.FTP_WEI = ftp_wei
760 self.FTP_WEI = ftp_wei
748 self.EXP_CODE = exp_code
761 self.EXP_CODE = exp_code
749 self.SUB_EXP_CODE = sub_exp_code
762 self.SUB_EXP_CODE = sub_exp_code
750 self.PLOT_POS = plot_pos
763 self.PLOT_POS = plot_pos
751
764
752 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
765 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
753
766
754 self.isConfig = True
767 self.isConfig = True
755 update_figfile = True
768 update_figfile = True
756
769
757 self.setWinTitle(title)
770 self.setWinTitle(title)
758
771
759 for i in range(self.nplots):
772 for i in range(self.nplots):
760
773
761 pair = dataOut.pairsList[pairsIndexList[i]]
774 pair = dataOut.pairsList[pairsIndexList[i]]
762
775
763 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
776 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
764 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
777 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
765 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
778 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
766
779
767
780
768 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
781 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
769 coherence = numpy.abs(avgcoherenceComplex)
782 coherence = numpy.abs(avgcoherenceComplex)
770
783
771 z = coherence.reshape((1,-1))
784 z = coherence.reshape((1,-1))
772
785
773 counter = 0
786 counter = 0
774
787
775 title = "Coherence Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
788 title = "Coherence Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
776 axes = self.axesList[i*self.__nsubplots*2]
789 axes = self.axesList[i*self.__nsubplots*2]
777 axes.pcolorbuffer(x, y, z,
790 axes.pcolorbuffer(x, y, z,
778 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
791 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
779 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
792 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
780 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
793 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
781
794
782 if self.__showprofile:
795 if self.__showprofile:
783 counter += 1
796 counter += 1
784 axes = self.axesList[i*self.__nsubplots*2 + counter]
797 axes = self.axesList[i*self.__nsubplots*2 + counter]
785 axes.pline(coherence, y,
798 axes.pline(coherence, y,
786 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
799 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
787 xlabel='', ylabel='', title='', ticksize=7,
800 xlabel='', ylabel='', title='', ticksize=7,
788 ytick_visible=False, nxticks=5,
801 ytick_visible=False, nxticks=5,
789 grid='x')
802 grid='x')
790
803
791 counter += 1
804 counter += 1
792
805
793 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
806 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
794
807
795 z = phase.reshape((1,-1))
808 z = phase.reshape((1,-1))
796
809
797 title = "Phase Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
810 title = "Phase Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
798 axes = self.axesList[i*self.__nsubplots*2 + counter]
811 axes = self.axesList[i*self.__nsubplots*2 + counter]
799 axes.pcolorbuffer(x, y, z,
812 axes.pcolorbuffer(x, y, z,
800 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
813 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
801 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
814 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
802 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
815 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
803
816
804 if self.__showprofile:
817 if self.__showprofile:
805 counter += 1
818 counter += 1
806 axes = self.axesList[i*self.__nsubplots*2 + counter]
819 axes = self.axesList[i*self.__nsubplots*2 + counter]
807 axes.pline(phase, y,
820 axes.pline(phase, y,
808 xmin=phase_min, xmax=phase_max, ymin=ymin, ymax=ymax,
821 xmin=phase_min, xmax=phase_max, ymin=ymin, ymax=ymax,
809 xlabel='', ylabel='', title='', ticksize=7,
822 xlabel='', ylabel='', title='', ticksize=7,
810 ytick_visible=False, nxticks=4,
823 ytick_visible=False, nxticks=4,
811 grid='x')
824 grid='x')
812
825
813 self.draw()
826 self.draw()
814
827
815 if dataOut.ltctime >= self.xmax:
828 if dataOut.ltctime >= self.xmax:
816 self.counter_imagwr = wr_period
829 self.counter_imagwr = wr_period
817 self.isConfig = False
830 self.isConfig = False
818 update_figfile = True
831 update_figfile = True
819
832
820 self.save(figpath=figpath,
833 self.save(figpath=figpath,
821 figfile=figfile,
834 figfile=figfile,
822 save=save,
835 save=save,
823 ftp=ftp,
836 ftp=ftp,
824 wr_period=wr_period,
837 wr_period=wr_period,
825 thisDatetime=thisDatetime,
838 thisDatetime=thisDatetime,
826 update_figfile=update_figfile)
839 update_figfile=update_figfile)
827
840
828 class PowerProfilePlot(Figure):
841 class PowerProfilePlot(Figure):
829
842
830 isConfig = None
843 isConfig = None
831 __nsubplots = None
844 __nsubplots = None
832
845
833 WIDTHPROF = None
846 WIDTHPROF = None
834 HEIGHTPROF = None
847 HEIGHTPROF = None
835 PREFIX = 'spcprofile'
848 PREFIX = 'spcprofile'
836
849
837 def __init__(self):
850 def __init__(self):
838 self.isConfig = False
851 self.isConfig = False
839 self.__nsubplots = 1
852 self.__nsubplots = 1
840
853
841 self.PLOT_CODE = POWER_CODE
854 self.PLOT_CODE = POWER_CODE
842
855
843 self.WIDTH = 300
856 self.WIDTH = 300
844 self.HEIGHT = 500
857 self.HEIGHT = 500
845 self.counter_imagwr = 0
858 self.counter_imagwr = 0
846
859
847 def getSubplots(self):
860 def getSubplots(self):
848 ncol = 1
861 ncol = 1
849 nrow = 1
862 nrow = 1
850
863
851 return nrow, ncol
864 return nrow, ncol
852
865
853 def setup(self, id, nplots, wintitle, show):
866 def setup(self, id, nplots, wintitle, show):
854
867
855 self.nplots = nplots
868 self.nplots = nplots
856
869
857 ncolspan = 1
870 ncolspan = 1
858 colspan = 1
871 colspan = 1
859
872
860 self.createFigure(id = id,
873 self.createFigure(id = id,
861 wintitle = wintitle,
874 wintitle = wintitle,
862 widthplot = self.WIDTH,
875 widthplot = self.WIDTH,
863 heightplot = self.HEIGHT,
876 heightplot = self.HEIGHT,
864 show=show)
877 show=show)
865
878
866 nrow, ncol = self.getSubplots()
879 nrow, ncol = self.getSubplots()
867
880
868 counter = 0
881 counter = 0
869 for y in range(nrow):
882 for y in range(nrow):
870 for x in range(ncol):
883 for x in range(ncol):
871 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
884 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
872
885
873 def run(self, dataOut, id, wintitle="", channelList=None,
886 def run(self, dataOut, id, wintitle="", channelList=None,
874 xmin=None, xmax=None, ymin=None, ymax=None,
887 xmin=None, xmax=None, ymin=None, ymax=None,
875 save=False, figpath='./', figfile=None, show=True,
888 save=False, figpath='./', figfile=None, show=True,
876 ftp=False, wr_period=1, server=None,
889 ftp=False, wr_period=1, server=None,
877 folder=None, username=None, password=None):
890 folder=None, username=None, password=None):
878
891
879
892
880 if channelList == None:
893 if channelList == None:
881 channelIndexList = dataOut.channelIndexList
894 channelIndexList = dataOut.channelIndexList
882 channelList = dataOut.channelList
895 channelList = dataOut.channelList
883 else:
896 else:
884 channelIndexList = []
897 channelIndexList = []
885 for channel in channelList:
898 for channel in channelList:
886 if channel not in dataOut.channelList:
899 if channel not in dataOut.channelList:
887 raise ValueError, "Channel %d is not in dataOut.channelList"
900 raise ValueError, "Channel %d is not in dataOut.channelList"
888 channelIndexList.append(dataOut.channelList.index(channel))
901 channelIndexList.append(dataOut.channelList.index(channel))
889
902
890 factor = dataOut.normFactor
903 factor = dataOut.normFactor
891
904
892 y = dataOut.getHeiRange()
905 y = dataOut.getHeiRange()
893
906
894 #for voltage
907 #for voltage
895 if dataOut.type == 'Voltage':
908 if dataOut.type == 'Voltage':
896 x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
909 x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
897 x = x.real
910 x = x.real
898 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
911 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
899
912
900 #for spectra
913 #for spectra
901 if dataOut.type == 'Spectra':
914 if dataOut.type == 'Spectra':
902 x = dataOut.data_spc[channelIndexList,:,:]/factor
915 x = dataOut.data_spc[channelIndexList,:,:]/factor
903 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
916 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
904 x = numpy.average(x, axis=1)
917 x = numpy.average(x, axis=1)
905
918
906
919
907 xdB = 10*numpy.log10(x)
920 xdB = 10*numpy.log10(x)
908
921
909 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
922 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
910 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
923 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
911 xlabel = "dB"
924 xlabel = "dB"
912 ylabel = "Range (Km)"
925 ylabel = "Range (Km)"
913
926
914 if not self.isConfig:
927 if not self.isConfig:
915
928
916 nplots = 1
929 nplots = 1
917
930
918 self.setup(id=id,
931 self.setup(id=id,
919 nplots=nplots,
932 nplots=nplots,
920 wintitle=wintitle,
933 wintitle=wintitle,
921 show=show)
934 show=show)
922
935
923 if ymin == None: ymin = numpy.nanmin(y)
936 if ymin == None: ymin = numpy.nanmin(y)
924 if ymax == None: ymax = numpy.nanmax(y)
937 if ymax == None: ymax = numpy.nanmax(y)
925 if xmin == None: xmin = numpy.nanmin(xdB)*0.9
938 if xmin == None: xmin = numpy.nanmin(xdB)*0.9
926 if xmax == None: xmax = numpy.nanmax(xdB)*1.1
939 if xmax == None: xmax = numpy.nanmax(xdB)*1.1
927
940
928 self.isConfig = True
941 self.isConfig = True
929
942
930 self.setWinTitle(title)
943 self.setWinTitle(title)
931
944
932 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
945 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
933 axes = self.axesList[0]
946 axes = self.axesList[0]
934
947
935 legendlabels = ["channel %d"%x for x in channelList]
948 legendlabels = ["channel %d"%x for x in channelList]
936 axes.pmultiline(xdB, y,
949 axes.pmultiline(xdB, y,
937 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
950 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
938 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
951 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
939 ytick_visible=True, nxticks=5,
952 ytick_visible=True, nxticks=5,
940 grid='x')
953 grid='x')
941
954
942 self.draw()
955 self.draw()
943
956
944 self.save(figpath=figpath,
957 self.save(figpath=figpath,
945 figfile=figfile,
958 figfile=figfile,
946 save=save,
959 save=save,
947 ftp=ftp,
960 ftp=ftp,
948 wr_period=wr_period,
961 wr_period=wr_period,
949 thisDatetime=thisDatetime)
962 thisDatetime=thisDatetime)
950
963
951 class SpectraCutPlot(Figure):
964 class SpectraCutPlot(Figure):
952
965
953 isConfig = None
966 isConfig = None
954 __nsubplots = None
967 __nsubplots = None
955
968
956 WIDTHPROF = None
969 WIDTHPROF = None
957 HEIGHTPROF = None
970 HEIGHTPROF = None
958 PREFIX = 'spc_cut'
971 PREFIX = 'spc_cut'
959
972
960 def __init__(self):
973 def __init__(self):
961 self.isConfig = False
974 self.isConfig = False
962 self.__nsubplots = 1
975 self.__nsubplots = 1
963
976
964 self.PLOT_CODE = POWER_CODE
977 self.PLOT_CODE = POWER_CODE
965
978
966 self.WIDTH = 700
979 self.WIDTH = 700
967 self.HEIGHT = 500
980 self.HEIGHT = 500
968 self.counter_imagwr = 0
981 self.counter_imagwr = 0
969
982
970 def getSubplots(self):
983 def getSubplots(self):
971 ncol = 1
984 ncol = 1
972 nrow = 1
985 nrow = 1
973
986
974 return nrow, ncol
987 return nrow, ncol
975
988
976 def setup(self, id, nplots, wintitle, show):
989 def setup(self, id, nplots, wintitle, show):
977
990
978 self.nplots = nplots
991 self.nplots = nplots
979
992
980 ncolspan = 1
993 ncolspan = 1
981 colspan = 1
994 colspan = 1
982
995
983 self.createFigure(id = id,
996 self.createFigure(id = id,
984 wintitle = wintitle,
997 wintitle = wintitle,
985 widthplot = self.WIDTH,
998 widthplot = self.WIDTH,
986 heightplot = self.HEIGHT,
999 heightplot = self.HEIGHT,
987 show=show)
1000 show=show)
988
1001
989 nrow, ncol = self.getSubplots()
1002 nrow, ncol = self.getSubplots()
990
1003
991 counter = 0
1004 counter = 0
992 for y in range(nrow):
1005 for y in range(nrow):
993 for x in range(ncol):
1006 for x in range(ncol):
994 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1007 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
995
1008
996 def run(self, dataOut, id, wintitle="", channelList=None,
1009 def run(self, dataOut, id, wintitle="", channelList=None,
997 xmin=None, xmax=None, ymin=None, ymax=None,
1010 xmin=None, xmax=None, ymin=None, ymax=None,
998 save=False, figpath='./', figfile=None, show=True,
1011 save=False, figpath='./', figfile=None, show=True,
999 ftp=False, wr_period=1, server=None,
1012 ftp=False, wr_period=1, server=None,
1000 folder=None, username=None, password=None,
1013 folder=None, username=None, password=None,
1001 xaxis="velocity"):
1014 xaxis="frequency"):
1002
1015
1003
1016
1004 if channelList == None:
1017 if channelList == None:
1005 channelIndexList = dataOut.channelIndexList
1018 channelIndexList = dataOut.channelIndexList
1006 channelList = dataOut.channelList
1019 channelList = dataOut.channelList
1007 else:
1020 else:
1008 channelIndexList = []
1021 channelIndexList = []
1009 for channel in channelList:
1022 for channel in channelList:
1010 if channel not in dataOut.channelList:
1023 if channel not in dataOut.channelList:
1011 raise ValueError, "Channel %d is not in dataOut.channelList"
1024 raise ValueError, "Channel %d is not in dataOut.channelList"
1012 channelIndexList.append(dataOut.channelList.index(channel))
1025 channelIndexList.append(dataOut.channelList.index(channel))
1013
1026
1014 factor = dataOut.normFactor
1027 factor = dataOut.normFactor
1015
1028
1016 y = dataOut.getHeiRange()
1029 y = dataOut.getHeiRange()
1017
1030
1018 z = dataOut.data_spc/factor
1031 z = dataOut.data_spc/factor
1019 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1032 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1020
1033
1021 hei_index = numpy.arange(25)*3 + 20
1034 hei_index = numpy.arange(25)*3 + 20
1022
1035
1023 if xaxis == "frequency":
1036 if xaxis == "frequency":
1024 x = dataOut.getFreqRange()/1000.
1037 x = dataOut.getFreqRange()/1000.
1025 zdB = 10*numpy.log10(z[0,:,hei_index])
1038 zdB = 10*numpy.log10(z[0,:,hei_index])
1026 xlabel = "Frequency (kHz)"
1039 xlabel = "Frequency (kHz)"
1027 ylabel = "Power (dB)"
1040 ylabel = "Power (dB)"
1028
1041
1029 elif xaxis == "time":
1042 elif xaxis == "time":
1030 x = dataOut.getAcfRange()
1043 x = dataOut.getAcfRange()
1031 zdB = z[0,:,hei_index]
1044 zdB = z[0,:,hei_index]
1032 xlabel = "Time (ms)"
1045 xlabel = "Time (ms)"
1033 ylabel = "ACF"
1046 ylabel = "ACF"
1034
1047
1035 else:
1048 else:
1036 x = dataOut.getVelRange()
1049 x = dataOut.getVelRange()
1037 zdB = 10*numpy.log10(z[0,:,hei_index])
1050 zdB = 10*numpy.log10(z[0,:,hei_index])
1038 xlabel = "Velocity (m/s)"
1051 xlabel = "Velocity (m/s)"
1039 ylabel = "Power (dB)"
1052 ylabel = "Power (dB)"
1040
1053
1041 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1054 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1042 title = wintitle + " Range Cuts %s" %(thisDatetime.strftime("%d-%b-%Y"))
1055 title = wintitle + " Range Cuts %s" %(thisDatetime.strftime("%d-%b-%Y"))
1043
1056
1044 if not self.isConfig:
1057 if not self.isConfig:
1045
1058
1046 nplots = 1
1059 nplots = 1
1047
1060
1048 self.setup(id=id,
1061 self.setup(id=id,
1049 nplots=nplots,
1062 nplots=nplots,
1050 wintitle=wintitle,
1063 wintitle=wintitle,
1051 show=show)
1064 show=show)
1052
1065
1053 if xmin == None: xmin = numpy.nanmin(x)*0.9
1066 if xmin == None: xmin = numpy.nanmin(x)*0.9
1054 if xmax == None: xmax = numpy.nanmax(x)*1.1
1067 if xmax == None: xmax = numpy.nanmax(x)*1.1
1055 if ymin == None: ymin = numpy.nanmin(zdB)
1068 if ymin == None: ymin = numpy.nanmin(zdB)
1056 if ymax == None: ymax = numpy.nanmax(zdB)
1069 if ymax == None: ymax = numpy.nanmax(zdB)
1057
1070
1058 self.isConfig = True
1071 self.isConfig = True
1059
1072
1060 self.setWinTitle(title)
1073 self.setWinTitle(title)
1061
1074
1062 title = "Spectra Cuts: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1075 title = "Spectra Cuts: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1063 axes = self.axesList[0]
1076 axes = self.axesList[0]
1064
1077
1065 legendlabels = ["Range = %dKm" %y[i] for i in hei_index]
1078 legendlabels = ["Range = %dKm" %y[i] for i in hei_index]
1066
1079
1067 axes.pmultilineyaxis( x, zdB,
1080 axes.pmultilineyaxis( x, zdB,
1068 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1081 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1069 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
1082 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
1070 ytick_visible=True, nxticks=5,
1083 ytick_visible=True, nxticks=5,
1071 grid='x')
1084 grid='x')
1072
1085
1073 self.draw()
1086 self.draw()
1074
1087
1075 self.save(figpath=figpath,
1088 self.save(figpath=figpath,
1076 figfile=figfile,
1089 figfile=figfile,
1077 save=save,
1090 save=save,
1078 ftp=ftp,
1091 ftp=ftp,
1079 wr_period=wr_period,
1092 wr_period=wr_period,
1080 thisDatetime=thisDatetime)
1093 thisDatetime=thisDatetime)
1081
1094
1082 class Noise(Figure):
1095 class Noise(Figure):
1083
1096
1084 isConfig = None
1097 isConfig = None
1085 __nsubplots = None
1098 __nsubplots = None
1086
1099
1087 PREFIX = 'noise'
1100 PREFIX = 'noise'
1088
1101
1089 def __init__(self):
1102 def __init__(self):
1090
1103
1091 self.timerange = 24*60*60
1104 self.timerange = 24*60*60
1092 self.isConfig = False
1105 self.isConfig = False
1093 self.__nsubplots = 1
1106 self.__nsubplots = 1
1094 self.counter_imagwr = 0
1107 self.counter_imagwr = 0
1095 self.WIDTH = 800
1108 self.WIDTH = 800
1096 self.HEIGHT = 400
1109 self.HEIGHT = 400
1097 self.WIDTHPROF = 120
1110 self.WIDTHPROF = 120
1098 self.HEIGHTPROF = 0
1111 self.HEIGHTPROF = 0
1099 self.xdata = None
1112 self.xdata = None
1100 self.ydata = None
1113 self.ydata = None
1101
1114
1102 self.PLOT_CODE = NOISE_CODE
1115 self.PLOT_CODE = NOISE_CODE
1103
1116
1104 self.FTP_WEI = None
1117 self.FTP_WEI = None
1105 self.EXP_CODE = None
1118 self.EXP_CODE = None
1106 self.SUB_EXP_CODE = None
1119 self.SUB_EXP_CODE = None
1107 self.PLOT_POS = None
1120 self.PLOT_POS = None
1108 self.figfile = None
1121 self.figfile = None
1109
1122
1110 self.xmin = None
1123 self.xmin = None
1111 self.xmax = None
1124 self.xmax = None
1112
1125
1113 def getSubplots(self):
1126 def getSubplots(self):
1114
1127
1115 ncol = 1
1128 ncol = 1
1116 nrow = 1
1129 nrow = 1
1117
1130
1118 return nrow, ncol
1131 return nrow, ncol
1119
1132
1120 def openfile(self, filename):
1133 def openfile(self, filename):
1121 dirname = os.path.dirname(filename)
1134 dirname = os.path.dirname(filename)
1122
1135
1123 if not os.path.exists(dirname):
1136 if not os.path.exists(dirname):
1124 os.mkdir(dirname)
1137 os.mkdir(dirname)
1125
1138
1126 f = open(filename,'w+')
1139 f = open(filename,'w+')
1127 f.write('\n\n')
1140 f.write('\n\n')
1128 f.write('JICAMARCA RADIO OBSERVATORY - Noise \n')
1141 f.write('JICAMARCA RADIO OBSERVATORY - Noise \n')
1129 f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' )
1142 f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' )
1130 f.close()
1143 f.close()
1131
1144
1132 def save_data(self, filename_phase, data, data_datetime):
1145 def save_data(self, filename_phase, data, data_datetime):
1133
1146
1134 f=open(filename_phase,'a')
1147 f=open(filename_phase,'a')
1135
1148
1136 timetuple_data = data_datetime.timetuple()
1149 timetuple_data = data_datetime.timetuple()
1137 day = str(timetuple_data.tm_mday)
1150 day = str(timetuple_data.tm_mday)
1138 month = str(timetuple_data.tm_mon)
1151 month = str(timetuple_data.tm_mon)
1139 year = str(timetuple_data.tm_year)
1152 year = str(timetuple_data.tm_year)
1140 hour = str(timetuple_data.tm_hour)
1153 hour = str(timetuple_data.tm_hour)
1141 minute = str(timetuple_data.tm_min)
1154 minute = str(timetuple_data.tm_min)
1142 second = str(timetuple_data.tm_sec)
1155 second = str(timetuple_data.tm_sec)
1143
1156
1144 data_msg = ''
1157 data_msg = ''
1145 for i in range(len(data)):
1158 for i in range(len(data)):
1146 data_msg += str(data[i]) + ' '
1159 data_msg += str(data[i]) + ' '
1147
1160
1148 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' ' + data_msg + '\n')
1161 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' ' + data_msg + '\n')
1149 f.close()
1162 f.close()
1150
1163
1151
1164
1152 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1165 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1153
1166
1154 self.__showprofile = showprofile
1167 self.__showprofile = showprofile
1155 self.nplots = nplots
1168 self.nplots = nplots
1156
1169
1157 ncolspan = 7
1170 ncolspan = 7
1158 colspan = 6
1171 colspan = 6
1159 self.__nsubplots = 2
1172 self.__nsubplots = 2
1160
1173
1161 self.createFigure(id = id,
1174 self.createFigure(id = id,
1162 wintitle = wintitle,
1175 wintitle = wintitle,
1163 widthplot = self.WIDTH+self.WIDTHPROF,
1176 widthplot = self.WIDTH+self.WIDTHPROF,
1164 heightplot = self.HEIGHT+self.HEIGHTPROF,
1177 heightplot = self.HEIGHT+self.HEIGHTPROF,
1165 show=show)
1178 show=show)
1166
1179
1167 nrow, ncol = self.getSubplots()
1180 nrow, ncol = self.getSubplots()
1168
1181
1169 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1182 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1170
1183
1171
1184
1172 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1185 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1173 xmin=None, xmax=None, ymin=None, ymax=None,
1186 xmin=None, xmax=None, ymin=None, ymax=None,
1174 timerange=None,
1187 timerange=None,
1175 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1188 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1176 server=None, folder=None, username=None, password=None,
1189 server=None, folder=None, username=None, password=None,
1177 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1190 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1178
1191
1179 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1192 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1180 return
1193 return
1181
1194
1182 if channelList == None:
1195 if channelList == None:
1183 channelIndexList = dataOut.channelIndexList
1196 channelIndexList = dataOut.channelIndexList
1184 channelList = dataOut.channelList
1197 channelList = dataOut.channelList
1185 else:
1198 else:
1186 channelIndexList = []
1199 channelIndexList = []
1187 for channel in channelList:
1200 for channel in channelList:
1188 if channel not in dataOut.channelList:
1201 if channel not in dataOut.channelList:
1189 raise ValueError, "Channel %d is not in dataOut.channelList"
1202 raise ValueError, "Channel %d is not in dataOut.channelList"
1190 channelIndexList.append(dataOut.channelList.index(channel))
1203 channelIndexList.append(dataOut.channelList.index(channel))
1191
1204
1192 x = dataOut.getTimeRange()
1205 x = dataOut.getTimeRange()
1193 #y = dataOut.getHeiRange()
1206 #y = dataOut.getHeiRange()
1194 factor = dataOut.normFactor
1207 factor = dataOut.normFactor
1195 noise = dataOut.noise[channelIndexList]/factor
1208 noise = dataOut.noise[channelIndexList]/factor
1196 noisedB = 10*numpy.log10(noise)
1209 noisedB = 10*numpy.log10(noise)
1197
1210
1198 thisDatetime = dataOut.datatime
1211 thisDatetime = dataOut.datatime
1199
1212
1200 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1213 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1201 xlabel = ""
1214 xlabel = ""
1202 ylabel = "Intensity (dB)"
1215 ylabel = "Intensity (dB)"
1203 update_figfile = False
1216 update_figfile = False
1204
1217
1205 if not self.isConfig:
1218 if not self.isConfig:
1206
1219
1207 nplots = 1
1220 nplots = 1
1208
1221
1209 self.setup(id=id,
1222 self.setup(id=id,
1210 nplots=nplots,
1223 nplots=nplots,
1211 wintitle=wintitle,
1224 wintitle=wintitle,
1212 showprofile=showprofile,
1225 showprofile=showprofile,
1213 show=show)
1226 show=show)
1214
1227
1215 if timerange != None:
1228 if timerange != None:
1216 self.timerange = timerange
1229 self.timerange = timerange
1217
1230
1218 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1231 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1219
1232
1220 if ymin == None: ymin = numpy.floor(numpy.nanmin(noisedB)) - 10.0
1233 if ymin == None: ymin = numpy.floor(numpy.nanmin(noisedB)) - 10.0
1221 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1234 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1222
1235
1223 self.FTP_WEI = ftp_wei
1236 self.FTP_WEI = ftp_wei
1224 self.EXP_CODE = exp_code
1237 self.EXP_CODE = exp_code
1225 self.SUB_EXP_CODE = sub_exp_code
1238 self.SUB_EXP_CODE = sub_exp_code
1226 self.PLOT_POS = plot_pos
1239 self.PLOT_POS = plot_pos
1227
1240
1228
1241
1229 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1242 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1230 self.isConfig = True
1243 self.isConfig = True
1231 self.figfile = figfile
1244 self.figfile = figfile
1232 self.xdata = numpy.array([])
1245 self.xdata = numpy.array([])
1233 self.ydata = numpy.array([])
1246 self.ydata = numpy.array([])
1234
1247
1235 update_figfile = True
1248 update_figfile = True
1236
1249
1237 #open file beacon phase
1250 #open file beacon phase
1238 path = '%s%03d' %(self.PREFIX, self.id)
1251 path = '%s%03d' %(self.PREFIX, self.id)
1239 noise_file = os.path.join(path,'%s.txt'%self.name)
1252 noise_file = os.path.join(path,'%s.txt'%self.name)
1240 self.filename_noise = os.path.join(figpath,noise_file)
1253 self.filename_noise = os.path.join(figpath,noise_file)
1241
1254
1242 self.setWinTitle(title)
1255 self.setWinTitle(title)
1243
1256
1244 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1257 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1245
1258
1246 legendlabels = ["channel %d"%(idchannel) for idchannel in channelList]
1259 legendlabels = ["channel %d"%(idchannel) for idchannel in channelList]
1247 axes = self.axesList[0]
1260 axes = self.axesList[0]
1248
1261
1249 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1262 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1250
1263
1251 if len(self.ydata)==0:
1264 if len(self.ydata)==0:
1252 self.ydata = noisedB.reshape(-1,1)
1265 self.ydata = noisedB.reshape(-1,1)
1253 else:
1266 else:
1254 self.ydata = numpy.hstack((self.ydata, noisedB.reshape(-1,1)))
1267 self.ydata = numpy.hstack((self.ydata, noisedB.reshape(-1,1)))
1255
1268
1256
1269
1257 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1270 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1258 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1271 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1259 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1272 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1260 XAxisAsTime=True, grid='both'
1273 XAxisAsTime=True, grid='both'
1261 )
1274 )
1262
1275
1263 self.draw()
1276 self.draw()
1264
1277
1265 if dataOut.ltctime >= self.xmax:
1278 if dataOut.ltctime >= self.xmax:
1266 self.counter_imagwr = wr_period
1279 self.counter_imagwr = wr_period
1267 self.isConfig = False
1280 self.isConfig = False
1268 update_figfile = True
1281 update_figfile = True
1269
1282
1270 self.save(figpath=figpath,
1283 self.save(figpath=figpath,
1271 figfile=figfile,
1284 figfile=figfile,
1272 save=save,
1285 save=save,
1273 ftp=ftp,
1286 ftp=ftp,
1274 wr_period=wr_period,
1287 wr_period=wr_period,
1275 thisDatetime=thisDatetime,
1288 thisDatetime=thisDatetime,
1276 update_figfile=update_figfile)
1289 update_figfile=update_figfile)
1277
1290
1278 #store data beacon phase
1291 #store data beacon phase
1279 if save:
1292 if save:
1280 self.save_data(self.filename_noise, noisedB, thisDatetime)
1293 self.save_data(self.filename_noise, noisedB, thisDatetime)
1281
1294
1282 class BeaconPhase(Figure):
1295 class BeaconPhase(Figure):
1283
1296
1284 __isConfig = None
1297 __isConfig = None
1285 __nsubplots = None
1298 __nsubplots = None
1286
1299
1287 PREFIX = 'beacon_phase'
1300 PREFIX = 'beacon_phase'
1288
1301
1289 def __init__(self):
1302 def __init__(self):
1290
1303
1291 self.timerange = 24*60*60
1304 self.timerange = 24*60*60
1292 self.isConfig = False
1305 self.isConfig = False
1293 self.__nsubplots = 1
1306 self.__nsubplots = 1
1294 self.counter_imagwr = 0
1307 self.counter_imagwr = 0
1295 self.WIDTH = 800
1308 self.WIDTH = 800
1296 self.HEIGHT = 400
1309 self.HEIGHT = 400
1297 self.WIDTHPROF = 120
1310 self.WIDTHPROF = 120
1298 self.HEIGHTPROF = 0
1311 self.HEIGHTPROF = 0
1299 self.xdata = None
1312 self.xdata = None
1300 self.ydata = None
1313 self.ydata = None
1301
1314
1302 self.PLOT_CODE = BEACON_CODE
1315 self.PLOT_CODE = BEACON_CODE
1303
1316
1304 self.FTP_WEI = None
1317 self.FTP_WEI = None
1305 self.EXP_CODE = None
1318 self.EXP_CODE = None
1306 self.SUB_EXP_CODE = None
1319 self.SUB_EXP_CODE = None
1307 self.PLOT_POS = None
1320 self.PLOT_POS = None
1308
1321
1309 self.filename_phase = None
1322 self.filename_phase = None
1310
1323
1311 self.figfile = None
1324 self.figfile = None
1312
1325
1313 self.xmin = None
1326 self.xmin = None
1314 self.xmax = None
1327 self.xmax = None
1315
1328
1316 def getSubplots(self):
1329 def getSubplots(self):
1317
1330
1318 ncol = 1
1331 ncol = 1
1319 nrow = 1
1332 nrow = 1
1320
1333
1321 return nrow, ncol
1334 return nrow, ncol
1322
1335
1323 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1336 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1324
1337
1325 self.__showprofile = showprofile
1338 self.__showprofile = showprofile
1326 self.nplots = nplots
1339 self.nplots = nplots
1327
1340
1328 ncolspan = 7
1341 ncolspan = 7
1329 colspan = 6
1342 colspan = 6
1330 self.__nsubplots = 2
1343 self.__nsubplots = 2
1331
1344
1332 self.createFigure(id = id,
1345 self.createFigure(id = id,
1333 wintitle = wintitle,
1346 wintitle = wintitle,
1334 widthplot = self.WIDTH+self.WIDTHPROF,
1347 widthplot = self.WIDTH+self.WIDTHPROF,
1335 heightplot = self.HEIGHT+self.HEIGHTPROF,
1348 heightplot = self.HEIGHT+self.HEIGHTPROF,
1336 show=show)
1349 show=show)
1337
1350
1338 nrow, ncol = self.getSubplots()
1351 nrow, ncol = self.getSubplots()
1339
1352
1340 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1353 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1341
1354
1342 def save_phase(self, filename_phase):
1355 def save_phase(self, filename_phase):
1343 f = open(filename_phase,'w+')
1356 f = open(filename_phase,'w+')
1344 f.write('\n\n')
1357 f.write('\n\n')
1345 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
1358 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
1346 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
1359 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
1347 f.close()
1360 f.close()
1348
1361
1349 def save_data(self, filename_phase, data, data_datetime):
1362 def save_data(self, filename_phase, data, data_datetime):
1350 f=open(filename_phase,'a')
1363 f=open(filename_phase,'a')
1351 timetuple_data = data_datetime.timetuple()
1364 timetuple_data = data_datetime.timetuple()
1352 day = str(timetuple_data.tm_mday)
1365 day = str(timetuple_data.tm_mday)
1353 month = str(timetuple_data.tm_mon)
1366 month = str(timetuple_data.tm_mon)
1354 year = str(timetuple_data.tm_year)
1367 year = str(timetuple_data.tm_year)
1355 hour = str(timetuple_data.tm_hour)
1368 hour = str(timetuple_data.tm_hour)
1356 minute = str(timetuple_data.tm_min)
1369 minute = str(timetuple_data.tm_min)
1357 second = str(timetuple_data.tm_sec)
1370 second = str(timetuple_data.tm_sec)
1358 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1371 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1359 f.close()
1372 f.close()
1360
1373
1361
1374
1362 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1375 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1363 xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None,
1376 xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None,
1364 timerange=None,
1377 timerange=None,
1365 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1378 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1366 server=None, folder=None, username=None, password=None,
1379 server=None, folder=None, username=None, password=None,
1367 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1380 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1368
1381
1369 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1382 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1370 return
1383 return
1371
1384
1372 if pairsList == None:
1385 if pairsList == None:
1373 pairsIndexList = dataOut.pairsIndexList[:10]
1386 pairsIndexList = dataOut.pairsIndexList[:10]
1374 else:
1387 else:
1375 pairsIndexList = []
1388 pairsIndexList = []
1376 for pair in pairsList:
1389 for pair in pairsList:
1377 if pair not in dataOut.pairsList:
1390 if pair not in dataOut.pairsList:
1378 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
1391 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
1379 pairsIndexList.append(dataOut.pairsList.index(pair))
1392 pairsIndexList.append(dataOut.pairsList.index(pair))
1380
1393
1381 if pairsIndexList == []:
1394 if pairsIndexList == []:
1382 return
1395 return
1383
1396
1384 # if len(pairsIndexList) > 4:
1397 # if len(pairsIndexList) > 4:
1385 # pairsIndexList = pairsIndexList[0:4]
1398 # pairsIndexList = pairsIndexList[0:4]
1386
1399
1387 hmin_index = None
1400 hmin_index = None
1388 hmax_index = None
1401 hmax_index = None
1389
1402
1390 if hmin != None and hmax != None:
1403 if hmin != None and hmax != None:
1391 indexes = numpy.arange(dataOut.nHeights)
1404 indexes = numpy.arange(dataOut.nHeights)
1392 hmin_list = indexes[dataOut.heightList >= hmin]
1405 hmin_list = indexes[dataOut.heightList >= hmin]
1393 hmax_list = indexes[dataOut.heightList <= hmax]
1406 hmax_list = indexes[dataOut.heightList <= hmax]
1394
1407
1395 if hmin_list.any():
1408 if hmin_list.any():
1396 hmin_index = hmin_list[0]
1409 hmin_index = hmin_list[0]
1397
1410
1398 if hmax_list.any():
1411 if hmax_list.any():
1399 hmax_index = hmax_list[-1]+1
1412 hmax_index = hmax_list[-1]+1
1400
1413
1401 x = dataOut.getTimeRange()
1414 x = dataOut.getTimeRange()
1402 #y = dataOut.getHeiRange()
1415 #y = dataOut.getHeiRange()
1403
1416
1404
1417
1405 thisDatetime = dataOut.datatime
1418 thisDatetime = dataOut.datatime
1406
1419
1407 title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1420 title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1408 xlabel = "Local Time"
1421 xlabel = "Local Time"
1409 ylabel = "Phase (degrees)"
1422 ylabel = "Phase (degrees)"
1410
1423
1411 update_figfile = False
1424 update_figfile = False
1412
1425
1413 nplots = len(pairsIndexList)
1426 nplots = len(pairsIndexList)
1414 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1427 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1415 phase_beacon = numpy.zeros(len(pairsIndexList))
1428 phase_beacon = numpy.zeros(len(pairsIndexList))
1416 for i in range(nplots):
1429 for i in range(nplots):
1417 pair = dataOut.pairsList[pairsIndexList[i]]
1430 pair = dataOut.pairsList[pairsIndexList[i]]
1418 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0)
1431 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0)
1419 powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0)
1432 powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0)
1420 powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0)
1433 powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0)
1421 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
1434 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
1422 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1435 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1423
1436
1424 #print "Phase %d%d" %(pair[0], pair[1])
1437 #print "Phase %d%d" %(pair[0], pair[1])
1425 #print phase[dataOut.beacon_heiIndexList]
1438 #print phase[dataOut.beacon_heiIndexList]
1426
1439
1427 if dataOut.beacon_heiIndexList:
1440 if dataOut.beacon_heiIndexList:
1428 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
1441 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
1429 else:
1442 else:
1430 phase_beacon[i] = numpy.average(phase)
1443 phase_beacon[i] = numpy.average(phase)
1431
1444
1432 if not self.isConfig:
1445 if not self.isConfig:
1433
1446
1434 nplots = len(pairsIndexList)
1447 nplots = len(pairsIndexList)
1435
1448
1436 self.setup(id=id,
1449 self.setup(id=id,
1437 nplots=nplots,
1450 nplots=nplots,
1438 wintitle=wintitle,
1451 wintitle=wintitle,
1439 showprofile=showprofile,
1452 showprofile=showprofile,
1440 show=show)
1453 show=show)
1441
1454
1442 if timerange != None:
1455 if timerange != None:
1443 self.timerange = timerange
1456 self.timerange = timerange
1444
1457
1445 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1458 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1446
1459
1447 if ymin == None: ymin = 0
1460 if ymin == None: ymin = 0
1448 if ymax == None: ymax = 360
1461 if ymax == None: ymax = 360
1449
1462
1450 self.FTP_WEI = ftp_wei
1463 self.FTP_WEI = ftp_wei
1451 self.EXP_CODE = exp_code
1464 self.EXP_CODE = exp_code
1452 self.SUB_EXP_CODE = sub_exp_code
1465 self.SUB_EXP_CODE = sub_exp_code
1453 self.PLOT_POS = plot_pos
1466 self.PLOT_POS = plot_pos
1454
1467
1455 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1468 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1456 self.isConfig = True
1469 self.isConfig = True
1457 self.figfile = figfile
1470 self.figfile = figfile
1458 self.xdata = numpy.array([])
1471 self.xdata = numpy.array([])
1459 self.ydata = numpy.array([])
1472 self.ydata = numpy.array([])
1460
1473
1461 update_figfile = True
1474 update_figfile = True
1462
1475
1463 #open file beacon phase
1476 #open file beacon phase
1464 path = '%s%03d' %(self.PREFIX, self.id)
1477 path = '%s%03d' %(self.PREFIX, self.id)
1465 beacon_file = os.path.join(path,'%s.txt'%self.name)
1478 beacon_file = os.path.join(path,'%s.txt'%self.name)
1466 self.filename_phase = os.path.join(figpath,beacon_file)
1479 self.filename_phase = os.path.join(figpath,beacon_file)
1467 #self.save_phase(self.filename_phase)
1480 #self.save_phase(self.filename_phase)
1468
1481
1469
1482
1470 #store data beacon phase
1483 #store data beacon phase
1471 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1484 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1472
1485
1473 self.setWinTitle(title)
1486 self.setWinTitle(title)
1474
1487
1475
1488
1476 title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1489 title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1477
1490
1478 legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList]
1491 legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList]
1479
1492
1480 axes = self.axesList[0]
1493 axes = self.axesList[0]
1481
1494
1482 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1495 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1483
1496
1484 if len(self.ydata)==0:
1497 if len(self.ydata)==0:
1485 self.ydata = phase_beacon.reshape(-1,1)
1498 self.ydata = phase_beacon.reshape(-1,1)
1486 else:
1499 else:
1487 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1500 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1488
1501
1489
1502
1490 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1503 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1491 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1504 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1492 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1505 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1493 XAxisAsTime=True, grid='both'
1506 XAxisAsTime=True, grid='both'
1494 )
1507 )
1495
1508
1496 self.draw()
1509 self.draw()
1497
1510
1498 if dataOut.ltctime >= self.xmax:
1511 if dataOut.ltctime >= self.xmax:
1499 self.counter_imagwr = wr_period
1512 self.counter_imagwr = wr_period
1500 self.isConfig = False
1513 self.isConfig = False
1501 update_figfile = True
1514 update_figfile = True
1502
1515
1503 self.save(figpath=figpath,
1516 self.save(figpath=figpath,
1504 figfile=figfile,
1517 figfile=figfile,
1505 save=save,
1518 save=save,
1506 ftp=ftp,
1519 ftp=ftp,
1507 wr_period=wr_period,
1520 wr_period=wr_period,
1508 thisDatetime=thisDatetime,
1521 thisDatetime=thisDatetime,
1509 update_figfile=update_figfile)
1522 update_figfile=update_figfile)
General Comments 0
You need to be logged in to leave comments. Login now