##// END OF EJS Templates
checking misspelled kwargs in operations/processing units
José Chávez -
r929:136584fbb1e2
parent child
Show More
@@ -1,1946 +1,1945
1 import os
1 import os
2 import datetime
2 import datetime
3 import numpy
3 import numpy
4
4 import inspect
5 from figure import Figure, isRealtime, isTimeInHourRange
5 from figure import Figure, isRealtime, isTimeInHourRange
6 from plotting_codes import *
6 from plotting_codes import *
7
7
8
8
9 class MomentsPlot(Figure):
9 class MomentsPlot(Figure):
10
10
11 isConfig = None
11 isConfig = None
12 __nsubplots = None
12 __nsubplots = None
13
13
14 WIDTHPROF = None
14 WIDTHPROF = None
15 HEIGHTPROF = None
15 HEIGHTPROF = None
16 PREFIX = 'prm'
16 PREFIX = 'prm'
17
17
18 def __init__(self, **kwargs):
18 def __init__(self, **kwargs):
19 Figure.__init__(self, **kwargs)
19 Figure.__init__(self, **kwargs)
20 self.isConfig = False
20 self.isConfig = False
21 self.__nsubplots = 1
21 self.__nsubplots = 1
22
22
23 self.WIDTH = 280
23 self.WIDTH = 280
24 self.HEIGHT = 250
24 self.HEIGHT = 250
25 self.WIDTHPROF = 120
25 self.WIDTHPROF = 120
26 self.HEIGHTPROF = 0
26 self.HEIGHTPROF = 0
27 self.counter_imagwr = 0
27 self.counter_imagwr = 0
28
28
29 self.PLOT_CODE = MOMENTS_CODE
29 self.PLOT_CODE = MOMENTS_CODE
30
30
31 self.FTP_WEI = None
31 self.FTP_WEI = None
32 self.EXP_CODE = None
32 self.EXP_CODE = None
33 self.SUB_EXP_CODE = None
33 self.SUB_EXP_CODE = None
34 self.PLOT_POS = None
34 self.PLOT_POS = None
35
35
36 def getSubplots(self):
36 def getSubplots(self):
37
37
38 ncol = int(numpy.sqrt(self.nplots)+0.9)
38 ncol = int(numpy.sqrt(self.nplots)+0.9)
39 nrow = int(self.nplots*1./ncol + 0.9)
39 nrow = int(self.nplots*1./ncol + 0.9)
40
40
41 return nrow, ncol
41 return nrow, ncol
42
42
43 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
43 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
44
44
45 self.__showprofile = showprofile
45 self.__showprofile = showprofile
46 self.nplots = nplots
46 self.nplots = nplots
47
47
48 ncolspan = 1
48 ncolspan = 1
49 colspan = 1
49 colspan = 1
50 if showprofile:
50 if showprofile:
51 ncolspan = 3
51 ncolspan = 3
52 colspan = 2
52 colspan = 2
53 self.__nsubplots = 2
53 self.__nsubplots = 2
54
54
55 self.createFigure(id = id,
55 self.createFigure(id = id,
56 wintitle = wintitle,
56 wintitle = wintitle,
57 widthplot = self.WIDTH + self.WIDTHPROF,
57 widthplot = self.WIDTH + self.WIDTHPROF,
58 heightplot = self.HEIGHT + self.HEIGHTPROF,
58 heightplot = self.HEIGHT + self.HEIGHTPROF,
59 show=show)
59 show=show)
60
60
61 nrow, ncol = self.getSubplots()
61 nrow, ncol = self.getSubplots()
62
62
63 counter = 0
63 counter = 0
64 for y in range(nrow):
64 for y in range(nrow):
65 for x in range(ncol):
65 for x in range(ncol):
66
66
67 if counter >= self.nplots:
67 if counter >= self.nplots:
68 break
68 break
69
69
70 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
70 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
71
71
72 if showprofile:
72 if showprofile:
73 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
73 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
74
74
75 counter += 1
75 counter += 1
76
76
77 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
77 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
78 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
78 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
79 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
79 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
80 server=None, folder=None, username=None, password=None,
80 server=None, folder=None, username=None, password=None,
81 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
81 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
82
82
83 """
83 """
84
84
85 Input:
85 Input:
86 dataOut :
86 dataOut :
87 id :
87 id :
88 wintitle :
88 wintitle :
89 channelList :
89 channelList :
90 showProfile :
90 showProfile :
91 xmin : None,
91 xmin : None,
92 xmax : None,
92 xmax : None,
93 ymin : None,
93 ymin : None,
94 ymax : None,
94 ymax : None,
95 zmin : None,
95 zmin : None,
96 zmax : None
96 zmax : None
97 """
97 """
98
98
99 if dataOut.flagNoData:
99 if dataOut.flagNoData:
100 return None
100 return None
101
101
102 if realtime:
102 if realtime:
103 if not(isRealtime(utcdatatime = dataOut.utctime)):
103 if not(isRealtime(utcdatatime = dataOut.utctime)):
104 print 'Skipping this plot function'
104 print 'Skipping this plot function'
105 return
105 return
106
106
107 if channelList == None:
107 if channelList == None:
108 channelIndexList = dataOut.channelIndexList
108 channelIndexList = dataOut.channelIndexList
109 else:
109 else:
110 channelIndexList = []
110 channelIndexList = []
111 for channel in channelList:
111 for channel in channelList:
112 if channel not in dataOut.channelList:
112 if channel not in dataOut.channelList:
113 raise ValueError, "Channel %d is not in dataOut.channelList"
113 raise ValueError, "Channel %d is not in dataOut.channelList"
114 channelIndexList.append(dataOut.channelList.index(channel))
114 channelIndexList.append(dataOut.channelList.index(channel))
115
115
116 factor = dataOut.normFactor
116 factor = dataOut.normFactor
117 x = dataOut.abscissaList
117 x = dataOut.abscissaList
118 y = dataOut.heightList
118 y = dataOut.heightList
119
119
120 z = dataOut.data_pre[channelIndexList,:,:]/factor
120 z = dataOut.data_pre[channelIndexList,:,:]/factor
121 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
121 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
122 avg = numpy.average(z, axis=1)
122 avg = numpy.average(z, axis=1)
123 noise = dataOut.noise/factor
123 noise = dataOut.noise/factor
124
124
125 zdB = 10*numpy.log10(z)
125 zdB = 10*numpy.log10(z)
126 avgdB = 10*numpy.log10(avg)
126 avgdB = 10*numpy.log10(avg)
127 noisedB = 10*numpy.log10(noise)
127 noisedB = 10*numpy.log10(noise)
128
128
129 #thisDatetime = dataOut.datatime
129 #thisDatetime = dataOut.datatime
130 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
130 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
131 title = wintitle + " Parameters"
131 title = wintitle + " Parameters"
132 xlabel = "Velocity (m/s)"
132 xlabel = "Velocity (m/s)"
133 ylabel = "Range (Km)"
133 ylabel = "Range (Km)"
134
134
135 update_figfile = False
135 update_figfile = False
136
136
137 if not self.isConfig:
137 if not self.isConfig:
138
138
139 nplots = len(channelIndexList)
139 nplots = len(channelIndexList)
140
140
141 self.setup(id=id,
141 self.setup(id=id,
142 nplots=nplots,
142 nplots=nplots,
143 wintitle=wintitle,
143 wintitle=wintitle,
144 showprofile=showprofile,
144 showprofile=showprofile,
145 show=show)
145 show=show)
146
146
147 if xmin == None: xmin = numpy.nanmin(x)
147 if xmin == None: xmin = numpy.nanmin(x)
148 if xmax == None: xmax = numpy.nanmax(x)
148 if xmax == None: xmax = numpy.nanmax(x)
149 if ymin == None: ymin = numpy.nanmin(y)
149 if ymin == None: ymin = numpy.nanmin(y)
150 if ymax == None: ymax = numpy.nanmax(y)
150 if ymax == None: ymax = numpy.nanmax(y)
151 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
151 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
152 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
152 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
153
153
154 self.FTP_WEI = ftp_wei
154 self.FTP_WEI = ftp_wei
155 self.EXP_CODE = exp_code
155 self.EXP_CODE = exp_code
156 self.SUB_EXP_CODE = sub_exp_code
156 self.SUB_EXP_CODE = sub_exp_code
157 self.PLOT_POS = plot_pos
157 self.PLOT_POS = plot_pos
158
158
159 self.isConfig = True
159 self.isConfig = True
160 update_figfile = True
160 update_figfile = True
161
161
162 self.setWinTitle(title)
162 self.setWinTitle(title)
163
163
164 for i in range(self.nplots):
164 for i in range(self.nplots):
165 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
165 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
166 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i], noisedB[i], str_datetime)
166 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i], noisedB[i], str_datetime)
167 axes = self.axesList[i*self.__nsubplots]
167 axes = self.axesList[i*self.__nsubplots]
168 axes.pcolor(x, y, zdB[i,:,:],
168 axes.pcolor(x, y, zdB[i,:,:],
169 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
169 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
170 xlabel=xlabel, ylabel=ylabel, title=title,
170 xlabel=xlabel, ylabel=ylabel, title=title,
171 ticksize=9, cblabel='')
171 ticksize=9, cblabel='')
172 #Mean Line
172 #Mean Line
173 mean = dataOut.data_param[i, 1, :]
173 mean = dataOut.data_param[i, 1, :]
174 axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1)
174 axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1)
175
175
176 if self.__showprofile:
176 if self.__showprofile:
177 axes = self.axesList[i*self.__nsubplots +1]
177 axes = self.axesList[i*self.__nsubplots +1]
178 axes.pline(avgdB[i], y,
178 axes.pline(avgdB[i], y,
179 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
179 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
180 xlabel='dB', ylabel='', title='',
180 xlabel='dB', ylabel='', title='',
181 ytick_visible=False,
181 ytick_visible=False,
182 grid='x')
182 grid='x')
183
183
184 noiseline = numpy.repeat(noisedB[i], len(y))
184 noiseline = numpy.repeat(noisedB[i], len(y))
185 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
185 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
186
186
187 self.draw()
187 self.draw()
188
188
189 self.save(figpath=figpath,
189 self.save(figpath=figpath,
190 figfile=figfile,
190 figfile=figfile,
191 save=save,
191 save=save,
192 ftp=ftp,
192 ftp=ftp,
193 wr_period=wr_period,
193 wr_period=wr_period,
194 thisDatetime=thisDatetime)
194 thisDatetime=thisDatetime)
195
195
196
196
197
197
198 class SkyMapPlot(Figure):
198 class SkyMapPlot(Figure):
199
199
200 __isConfig = None
200 __isConfig = None
201 __nsubplots = None
201 __nsubplots = None
202
202
203 WIDTHPROF = None
203 WIDTHPROF = None
204 HEIGHTPROF = None
204 HEIGHTPROF = None
205 PREFIX = 'mmap'
205 PREFIX = 'mmap'
206
206
207 def __init__(self, **kwargs):
207 def __init__(self, **kwargs):
208 Figure.__init__(self, **kwargs)
208 Figure.__init__(self, **kwargs)
209 self.isConfig = False
209 self.isConfig = False
210 self.__nsubplots = 1
210 self.__nsubplots = 1
211
211
212 # self.WIDTH = 280
212 # self.WIDTH = 280
213 # self.HEIGHT = 250
213 # self.HEIGHT = 250
214 self.WIDTH = 600
214 self.WIDTH = 600
215 self.HEIGHT = 600
215 self.HEIGHT = 600
216 self.WIDTHPROF = 120
216 self.WIDTHPROF = 120
217 self.HEIGHTPROF = 0
217 self.HEIGHTPROF = 0
218 self.counter_imagwr = 0
218 self.counter_imagwr = 0
219
219
220 self.PLOT_CODE = MSKYMAP_CODE
220 self.PLOT_CODE = MSKYMAP_CODE
221
221
222 self.FTP_WEI = None
222 self.FTP_WEI = None
223 self.EXP_CODE = None
223 self.EXP_CODE = None
224 self.SUB_EXP_CODE = None
224 self.SUB_EXP_CODE = None
225 self.PLOT_POS = None
225 self.PLOT_POS = None
226
226
227 def getSubplots(self):
227 def getSubplots(self):
228
228
229 ncol = int(numpy.sqrt(self.nplots)+0.9)
229 ncol = int(numpy.sqrt(self.nplots)+0.9)
230 nrow = int(self.nplots*1./ncol + 0.9)
230 nrow = int(self.nplots*1./ncol + 0.9)
231
231
232 return nrow, ncol
232 return nrow, ncol
233
233
234 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
234 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
235
235
236 self.__showprofile = showprofile
236 self.__showprofile = showprofile
237 self.nplots = nplots
237 self.nplots = nplots
238
238
239 ncolspan = 1
239 ncolspan = 1
240 colspan = 1
240 colspan = 1
241
241
242 self.createFigure(id = id,
242 self.createFigure(id = id,
243 wintitle = wintitle,
243 wintitle = wintitle,
244 widthplot = self.WIDTH, #+ self.WIDTHPROF,
244 widthplot = self.WIDTH, #+ self.WIDTHPROF,
245 heightplot = self.HEIGHT,# + self.HEIGHTPROF,
245 heightplot = self.HEIGHT,# + self.HEIGHTPROF,
246 show=show)
246 show=show)
247
247
248 nrow, ncol = 1,1
248 nrow, ncol = 1,1
249 counter = 0
249 counter = 0
250 x = 0
250 x = 0
251 y = 0
251 y = 0
252 self.addAxes(1, 1, 0, 0, 1, 1, True)
252 self.addAxes(1, 1, 0, 0, 1, 1, True)
253
253
254 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
254 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
255 tmin=0, tmax=24, timerange=None,
255 tmin=0, tmax=24, timerange=None,
256 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
256 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
257 server=None, folder=None, username=None, password=None,
257 server=None, folder=None, username=None, password=None,
258 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
258 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
259
259
260 """
260 """
261
261
262 Input:
262 Input:
263 dataOut :
263 dataOut :
264 id :
264 id :
265 wintitle :
265 wintitle :
266 channelList :
266 channelList :
267 showProfile :
267 showProfile :
268 xmin : None,
268 xmin : None,
269 xmax : None,
269 xmax : None,
270 ymin : None,
270 ymin : None,
271 ymax : None,
271 ymax : None,
272 zmin : None,
272 zmin : None,
273 zmax : None
273 zmax : None
274 """
274 """
275
275
276 arrayParameters = dataOut.data_param
276 arrayParameters = dataOut.data_param
277 error = arrayParameters[:,-1]
277 error = arrayParameters[:,-1]
278 indValid = numpy.where(error == 0)[0]
278 indValid = numpy.where(error == 0)[0]
279 finalMeteor = arrayParameters[indValid,:]
279 finalMeteor = arrayParameters[indValid,:]
280 finalAzimuth = finalMeteor[:,3]
280 finalAzimuth = finalMeteor[:,3]
281 finalZenith = finalMeteor[:,4]
281 finalZenith = finalMeteor[:,4]
282
282
283 x = finalAzimuth*numpy.pi/180
283 x = finalAzimuth*numpy.pi/180
284 y = finalZenith
284 y = finalZenith
285 x1 = [dataOut.ltctime, dataOut.ltctime]
285 x1 = [dataOut.ltctime, dataOut.ltctime]
286
286
287 #thisDatetime = dataOut.datatime
287 #thisDatetime = dataOut.datatime
288 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
288 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
289 title = wintitle + " Parameters"
289 title = wintitle + " Parameters"
290 xlabel = "Zonal Zenith Angle (deg) "
290 xlabel = "Zonal Zenith Angle (deg) "
291 ylabel = "Meridional Zenith Angle (deg)"
291 ylabel = "Meridional Zenith Angle (deg)"
292 update_figfile = False
292 update_figfile = False
293
293
294 if not self.isConfig:
294 if not self.isConfig:
295
295
296 nplots = 1
296 nplots = 1
297
297
298 self.setup(id=id,
298 self.setup(id=id,
299 nplots=nplots,
299 nplots=nplots,
300 wintitle=wintitle,
300 wintitle=wintitle,
301 showprofile=showprofile,
301 showprofile=showprofile,
302 show=show)
302 show=show)
303
303
304 if self.xmin is None and self.xmax is None:
304 if self.xmin is None and self.xmax is None:
305 self.xmin, self.xmax = self.getTimeLim(x1, tmin, tmax, timerange)
305 self.xmin, self.xmax = self.getTimeLim(x1, tmin, tmax, timerange)
306
306
307 if timerange != None:
307 if timerange != None:
308 self.timerange = timerange
308 self.timerange = timerange
309 else:
309 else:
310 self.timerange = self.xmax - self.xmin
310 self.timerange = self.xmax - self.xmin
311
311
312 self.FTP_WEI = ftp_wei
312 self.FTP_WEI = ftp_wei
313 self.EXP_CODE = exp_code
313 self.EXP_CODE = exp_code
314 self.SUB_EXP_CODE = sub_exp_code
314 self.SUB_EXP_CODE = sub_exp_code
315 self.PLOT_POS = plot_pos
315 self.PLOT_POS = plot_pos
316 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
316 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
317 self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
317 self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
318 self.isConfig = True
318 self.isConfig = True
319 update_figfile = True
319 update_figfile = True
320
320
321 self.setWinTitle(title)
321 self.setWinTitle(title)
322
322
323 i = 0
323 i = 0
324 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
324 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
325
325
326 axes = self.axesList[i*self.__nsubplots]
326 axes = self.axesList[i*self.__nsubplots]
327 nevents = axes.x_buffer.shape[0] + x.shape[0]
327 nevents = axes.x_buffer.shape[0] + x.shape[0]
328 title = "Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n" %(self.firstdate,str_datetime,nevents)
328 title = "Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n" %(self.firstdate,str_datetime,nevents)
329 axes.polar(x, y,
329 axes.polar(x, y,
330 title=title, xlabel=xlabel, ylabel=ylabel,
330 title=title, xlabel=xlabel, ylabel=ylabel,
331 ticksize=9, cblabel='')
331 ticksize=9, cblabel='')
332
332
333 self.draw()
333 self.draw()
334
334
335 self.save(figpath=figpath,
335 self.save(figpath=figpath,
336 figfile=figfile,
336 figfile=figfile,
337 save=save,
337 save=save,
338 ftp=ftp,
338 ftp=ftp,
339 wr_period=wr_period,
339 wr_period=wr_period,
340 thisDatetime=thisDatetime,
340 thisDatetime=thisDatetime,
341 update_figfile=update_figfile)
341 update_figfile=update_figfile)
342
342
343 if dataOut.ltctime >= self.xmax:
343 if dataOut.ltctime >= self.xmax:
344 self.isConfigmagwr = wr_period
344 self.isConfigmagwr = wr_period
345 self.isConfig = False
345 self.isConfig = False
346 update_figfile = True
346 update_figfile = True
347 axes.__firsttime = True
347 axes.__firsttime = True
348 self.xmin += self.timerange
348 self.xmin += self.timerange
349 self.xmax += self.timerange
349 self.xmax += self.timerange
350
350
351
351
352
352
353
353
354 class WindProfilerPlot(Figure):
354 class WindProfilerPlot(Figure):
355
355
356 __isConfig = None
356 __isConfig = None
357 __nsubplots = None
357 __nsubplots = None
358
358
359 WIDTHPROF = None
359 WIDTHPROF = None
360 HEIGHTPROF = None
360 HEIGHTPROF = None
361 PREFIX = 'wind'
361 PREFIX = 'wind'
362
362
363 def __init__(self, **kwargs):
363 def __init__(self, **kwargs):
364 Figure.__init__(self, **kwargs)
364 Figure.__init__(self, **kwargs)
365 self.timerange = None
365 self.timerange = None
366 self.isConfig = False
366 self.isConfig = False
367 self.__nsubplots = 1
367 self.__nsubplots = 1
368
368
369 self.WIDTH = 800
369 self.WIDTH = 800
370 self.HEIGHT = 300
370 self.HEIGHT = 300
371 self.WIDTHPROF = 120
371 self.WIDTHPROF = 120
372 self.HEIGHTPROF = 0
372 self.HEIGHTPROF = 0
373 self.counter_imagwr = 0
373 self.counter_imagwr = 0
374
374
375 self.PLOT_CODE = WIND_CODE
375 self.PLOT_CODE = WIND_CODE
376
376
377 self.FTP_WEI = None
377 self.FTP_WEI = None
378 self.EXP_CODE = None
378 self.EXP_CODE = None
379 self.SUB_EXP_CODE = None
379 self.SUB_EXP_CODE = None
380 self.PLOT_POS = None
380 self.PLOT_POS = None
381 self.tmin = None
381 self.tmin = None
382 self.tmax = None
382 self.tmax = None
383
383
384 self.xmin = None
384 self.xmin = None
385 self.xmax = None
385 self.xmax = None
386
386
387 self.figfile = None
387 self.figfile = None
388
388
389 def getSubplots(self):
389 def getSubplots(self):
390
390
391 ncol = 1
391 ncol = 1
392 nrow = self.nplots
392 nrow = self.nplots
393
393
394 return nrow, ncol
394 return nrow, ncol
395
395
396 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
396 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
397
397
398 self.__showprofile = showprofile
398 self.__showprofile = showprofile
399 self.nplots = nplots
399 self.nplots = nplots
400
400
401 ncolspan = 1
401 ncolspan = 1
402 colspan = 1
402 colspan = 1
403
403
404 self.createFigure(id = id,
404 self.createFigure(id = id,
405 wintitle = wintitle,
405 wintitle = wintitle,
406 widthplot = self.WIDTH + self.WIDTHPROF,
406 widthplot = self.WIDTH + self.WIDTHPROF,
407 heightplot = self.HEIGHT + self.HEIGHTPROF,
407 heightplot = self.HEIGHT + self.HEIGHTPROF,
408 show=show)
408 show=show)
409
409
410 nrow, ncol = self.getSubplots()
410 nrow, ncol = self.getSubplots()
411
411
412 counter = 0
412 counter = 0
413 for y in range(nrow):
413 for y in range(nrow):
414 if counter >= self.nplots:
414 if counter >= self.nplots:
415 break
415 break
416
416
417 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
417 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
418 counter += 1
418 counter += 1
419
419
420 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='False',
420 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='False',
421 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
421 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
422 zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None,
422 zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None,
423 timerange=None, SNRthresh = None,
423 timerange=None, SNRthresh = None,
424 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
424 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
425 server=None, folder=None, username=None, password=None,
425 server=None, folder=None, username=None, password=None,
426 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
426 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
427 """
427 """
428
428
429 Input:
429 Input:
430 dataOut :
430 dataOut :
431 id :
431 id :
432 wintitle :
432 wintitle :
433 channelList :
433 channelList :
434 showProfile :
434 showProfile :
435 xmin : None,
435 xmin : None,
436 xmax : None,
436 xmax : None,
437 ymin : None,
437 ymin : None,
438 ymax : None,
438 ymax : None,
439 zmin : None,
439 zmin : None,
440 zmax : None
440 zmax : None
441 """
441 """
442
442
443 # if timerange is not None:
443 # if timerange is not None:
444 # self.timerange = timerange
444 # self.timerange = timerange
445 #
445 #
446 # tmin = None
446 # tmin = None
447 # tmax = None
447 # tmax = None
448
448
449
449
450 x = dataOut.getTimeRange1(dataOut.outputInterval)
450 x = dataOut.getTimeRange1(dataOut.outputInterval)
451 y = dataOut.heightList
451 y = dataOut.heightList
452 z = dataOut.data_output.copy()
452 z = dataOut.data_output.copy()
453 nplots = z.shape[0] #Number of wind dimensions estimated
453 nplots = z.shape[0] #Number of wind dimensions estimated
454 nplotsw = nplots
454 nplotsw = nplots
455
455
456
456
457 #If there is a SNR function defined
457 #If there is a SNR function defined
458 if dataOut.data_SNR is not None:
458 if dataOut.data_SNR is not None:
459 nplots += 1
459 nplots += 1
460 SNR = dataOut.data_SNR
460 SNR = dataOut.data_SNR
461 SNRavg = numpy.average(SNR, axis=0)
461 SNRavg = numpy.average(SNR, axis=0)
462
462
463 SNRdB = 10*numpy.log10(SNR)
463 SNRdB = 10*numpy.log10(SNR)
464 SNRavgdB = 10*numpy.log10(SNRavg)
464 SNRavgdB = 10*numpy.log10(SNRavg)
465
465
466 if SNRthresh == None: SNRthresh = -5.0
466 if SNRthresh == None: SNRthresh = -5.0
467 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
467 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
468
468
469 for i in range(nplotsw):
469 for i in range(nplotsw):
470 z[i,ind] = numpy.nan
470 z[i,ind] = numpy.nan
471
471
472 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
472 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
473 #thisDatetime = datetime.datetime.now()
473 #thisDatetime = datetime.datetime.now()
474 title = wintitle + "Wind"
474 title = wintitle + "Wind"
475 xlabel = ""
475 xlabel = ""
476 ylabel = "Height (km)"
476 ylabel = "Height (km)"
477 update_figfile = False
477 update_figfile = False
478
478
479 if not self.isConfig:
479 if not self.isConfig:
480
480
481 self.setup(id=id,
481 self.setup(id=id,
482 nplots=nplots,
482 nplots=nplots,
483 wintitle=wintitle,
483 wintitle=wintitle,
484 showprofile=showprofile,
484 showprofile=showprofile,
485 show=show)
485 show=show)
486
486
487 if timerange is not None:
487 if timerange is not None:
488 self.timerange = timerange
488 self.timerange = timerange
489
489
490 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
490 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
491
491
492 if ymin == None: ymin = numpy.nanmin(y)
492 if ymin == None: ymin = numpy.nanmin(y)
493 if ymax == None: ymax = numpy.nanmax(y)
493 if ymax == None: ymax = numpy.nanmax(y)
494
494
495 if zmax == None: zmax = numpy.nanmax(abs(z[range(2),:]))
495 if zmax == None: zmax = numpy.nanmax(abs(z[range(2),:]))
496 #if numpy.isnan(zmax): zmax = 50
496 #if numpy.isnan(zmax): zmax = 50
497 if zmin == None: zmin = -zmax
497 if zmin == None: zmin = -zmax
498
498
499 if nplotsw == 3:
499 if nplotsw == 3:
500 if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:]))
500 if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:]))
501 if zmin_ver == None: zmin_ver = -zmax_ver
501 if zmin_ver == None: zmin_ver = -zmax_ver
502
502
503 if dataOut.data_SNR is not None:
503 if dataOut.data_SNR is not None:
504 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
504 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
505 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
505 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
506
506
507
507
508 self.FTP_WEI = ftp_wei
508 self.FTP_WEI = ftp_wei
509 self.EXP_CODE = exp_code
509 self.EXP_CODE = exp_code
510 self.SUB_EXP_CODE = sub_exp_code
510 self.SUB_EXP_CODE = sub_exp_code
511 self.PLOT_POS = plot_pos
511 self.PLOT_POS = plot_pos
512
512
513 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
513 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
514 self.isConfig = True
514 self.isConfig = True
515 self.figfile = figfile
515 self.figfile = figfile
516 update_figfile = True
516 update_figfile = True
517
517
518 self.setWinTitle(title)
518 self.setWinTitle(title)
519
519
520 if ((self.xmax - x[1]) < (x[1]-x[0])):
520 if ((self.xmax - x[1]) < (x[1]-x[0])):
521 x[1] = self.xmax
521 x[1] = self.xmax
522
522
523 strWind = ['Zonal', 'Meridional', 'Vertical']
523 strWind = ['Zonal', 'Meridional', 'Vertical']
524 strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)']
524 strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)']
525 zmaxVector = [zmax, zmax, zmax_ver]
525 zmaxVector = [zmax, zmax, zmax_ver]
526 zminVector = [zmin, zmin, zmin_ver]
526 zminVector = [zmin, zmin, zmin_ver]
527 windFactor = [1,1,100]
527 windFactor = [1,1,100]
528
528
529 for i in range(nplotsw):
529 for i in range(nplotsw):
530
530
531 title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
531 title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
532 axes = self.axesList[i*self.__nsubplots]
532 axes = self.axesList[i*self.__nsubplots]
533
533
534 z1 = z[i,:].reshape((1,-1))*windFactor[i]
534 z1 = z[i,:].reshape((1,-1))*windFactor[i]
535 #z1=numpy.ma.masked_where(z1==0.,z1)
535 #z1=numpy.ma.masked_where(z1==0.,z1)
536
536
537 axes.pcolorbuffer(x, y, z1,
537 axes.pcolorbuffer(x, y, z1,
538 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
538 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
539 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
539 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
540 ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="seismic" )
540 ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="seismic" )
541
541
542 if dataOut.data_SNR is not None:
542 if dataOut.data_SNR is not None:
543 i += 1
543 i += 1
544 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
544 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
545 axes = self.axesList[i*self.__nsubplots]
545 axes = self.axesList[i*self.__nsubplots]
546 SNRavgdB = SNRavgdB.reshape((1,-1))
546 SNRavgdB = SNRavgdB.reshape((1,-1))
547 axes.pcolorbuffer(x, y, SNRavgdB,
547 axes.pcolorbuffer(x, y, SNRavgdB,
548 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
548 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
549 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
549 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
550 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
550 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
551
551
552 self.draw()
552 self.draw()
553
553
554 self.save(figpath=figpath,
554 self.save(figpath=figpath,
555 figfile=figfile,
555 figfile=figfile,
556 save=save,
556 save=save,
557 ftp=ftp,
557 ftp=ftp,
558 wr_period=wr_period,
558 wr_period=wr_period,
559 thisDatetime=thisDatetime,
559 thisDatetime=thisDatetime,
560 update_figfile=update_figfile)
560 update_figfile=update_figfile)
561
561
562 if dataOut.ltctime + dataOut.outputInterval >= self.xmax:
562 if dataOut.ltctime + dataOut.outputInterval >= self.xmax:
563 self.counter_imagwr = wr_period
563 self.counter_imagwr = wr_period
564 self.isConfig = False
564 self.isConfig = False
565 update_figfile = True
565 update_figfile = True
566
566
567
567
568 class ParametersPlot(Figure):
568 class ParametersPlot(Figure):
569
569
570 __isConfig = None
570 __isConfig = None
571 __nsubplots = None
571 __nsubplots = None
572
572
573 WIDTHPROF = None
573 WIDTHPROF = None
574 HEIGHTPROF = None
574 HEIGHTPROF = None
575 PREFIX = 'param'
575 PREFIX = 'param'
576
576
577 nplots = None
577 nplots = None
578 nchan = None
578 nchan = None
579
579
580 def __init__(self, **kwargs):
580 def __init__(self, **kwargs):
581 Figure.__init__(self, **kwargs)
581 Figure.__init__(self, **kwargs)
582 self.timerange = None
582 self.timerange = None
583 self.isConfig = False
583 self.isConfig = False
584 self.__nsubplots = 1
584 self.__nsubplots = 1
585
585
586 self.WIDTH = 800
586 self.WIDTH = 800
587 self.HEIGHT = 180
587 self.HEIGHT = 180
588 self.WIDTHPROF = 120
588 self.WIDTHPROF = 120
589 self.HEIGHTPROF = 0
589 self.HEIGHTPROF = 0
590 self.counter_imagwr = 0
590 self.counter_imagwr = 0
591
591
592 self.PLOT_CODE = RTI_CODE
592 self.PLOT_CODE = RTI_CODE
593
593
594 self.FTP_WEI = None
594 self.FTP_WEI = None
595 self.EXP_CODE = None
595 self.EXP_CODE = None
596 self.SUB_EXP_CODE = None
596 self.SUB_EXP_CODE = None
597 self.PLOT_POS = None
597 self.PLOT_POS = None
598 self.tmin = None
598 self.tmin = None
599 self.tmax = None
599 self.tmax = None
600
600
601 self.xmin = None
601 self.xmin = None
602 self.xmax = None
602 self.xmax = None
603
603
604 self.figfile = None
604 self.figfile = None
605
605
606 def getSubplots(self):
606 def getSubplots(self):
607
607
608 ncol = 1
608 ncol = 1
609 nrow = self.nplots
609 nrow = self.nplots
610
610
611 return nrow, ncol
611 return nrow, ncol
612
612
613 def setup(self, id, nplots, wintitle, show=True):
613 def setup(self, id, nplots, wintitle, show=True):
614
614
615 self.nplots = nplots
615 self.nplots = nplots
616
616
617 ncolspan = 1
617 ncolspan = 1
618 colspan = 1
618 colspan = 1
619
619
620 self.createFigure(id = id,
620 self.createFigure(id = id,
621 wintitle = wintitle,
621 wintitle = wintitle,
622 widthplot = self.WIDTH + self.WIDTHPROF,
622 widthplot = self.WIDTH + self.WIDTHPROF,
623 heightplot = self.HEIGHT + self.HEIGHTPROF,
623 heightplot = self.HEIGHT + self.HEIGHTPROF,
624 show=show)
624 show=show)
625
625
626 nrow, ncol = self.getSubplots()
626 nrow, ncol = self.getSubplots()
627
627
628 counter = 0
628 counter = 0
629 for y in range(nrow):
629 for y in range(nrow):
630 for x in range(ncol):
630 for x in range(ncol):
631
631
632 if counter >= self.nplots:
632 if counter >= self.nplots:
633 break
633 break
634
634
635 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
635 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
636
636
637 counter += 1
637 counter += 1
638
638
639 def run(self, dataOut, id, wintitle="", channelList=None, paramIndex = 0, colormap=True,
639 def run(self, dataOut, id, wintitle="", channelList=None, paramIndex = 0, colormap=True,
640 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, timerange=None,
640 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, timerange=None,
641 showSNR=False, SNRthresh = -numpy.inf, SNRmin=None, SNRmax=None,
641 showSNR=False, SNRthresh = -numpy.inf, SNRmin=None, SNRmax=None,
642 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
642 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
643 server=None, folder=None, username=None, password=None,
643 server=None, folder=None, username=None, password=None,
644 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
644 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
645
646 """
645 """
647
646
648 Input:
647 Input:
649 dataOut :
648 dataOut :
650 id :
649 id :
651 wintitle :
650 wintitle :
652 channelList :
651 channelList :
653 showProfile :
652 showProfile :
654 xmin : None,
653 xmin : None,
655 xmax : None,
654 xmax : None,
656 ymin : None,
655 ymin : None,
657 ymax : None,
656 ymax : None,
658 zmin : None,
657 zmin : None,
659 zmax : None
658 zmax : None
660 """
659 """
661
660
662 if colormap:
661 if colormap:
663 colormap="jet"
662 colormap="jet"
664 else:
663 else:
665 colormap="RdBu_r"
664 colormap="RdBu_r"
666
665
667 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
666 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
668 return
667 return
669
668
670 if channelList == None:
669 if channelList == None:
671 channelIndexList = range(dataOut.data_param.shape[0])
670 channelIndexList = range(dataOut.data_param.shape[0])
672 else:
671 else:
673 channelIndexList = []
672 channelIndexList = []
674 for channel in channelList:
673 for channel in channelList:
675 if channel not in dataOut.channelList:
674 if channel not in dataOut.channelList:
676 raise ValueError, "Channel %d is not in dataOut.channelList"
675 raise ValueError, "Channel %d is not in dataOut.channelList"
677 channelIndexList.append(dataOut.channelList.index(channel))
676 channelIndexList.append(dataOut.channelList.index(channel))
678
677
679 x = dataOut.getTimeRange1(dataOut.paramInterval)
678 x = dataOut.getTimeRange1(dataOut.paramInterval)
680 y = dataOut.getHeiRange()
679 y = dataOut.getHeiRange()
681
680
682 if dataOut.data_param.ndim == 3:
681 if dataOut.data_param.ndim == 3:
683 z = dataOut.data_param[channelIndexList,paramIndex,:]
682 z = dataOut.data_param[channelIndexList,paramIndex,:]
684 else:
683 else:
685 z = dataOut.data_param[channelIndexList,:]
684 z = dataOut.data_param[channelIndexList,:]
686
685
687 if showSNR:
686 if showSNR:
688 #SNR data
687 #SNR data
689 SNRarray = dataOut.data_SNR[channelIndexList,:]
688 SNRarray = dataOut.data_SNR[channelIndexList,:]
690 SNRdB = 10*numpy.log10(SNRarray)
689 SNRdB = 10*numpy.log10(SNRarray)
691 ind = numpy.where(SNRdB < SNRthresh)
690 ind = numpy.where(SNRdB < SNRthresh)
692 z[ind] = numpy.nan
691 z[ind] = numpy.nan
693
692
694 thisDatetime = dataOut.datatime
693 thisDatetime = dataOut.datatime
695 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
694 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
696 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
695 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
697 xlabel = ""
696 xlabel = ""
698 ylabel = "Range (Km)"
697 ylabel = "Range (Km)"
699
698
700 update_figfile = False
699 update_figfile = False
701
700
702 if not self.isConfig:
701 if not self.isConfig:
703
702
704 nchan = len(channelIndexList)
703 nchan = len(channelIndexList)
705 self.nchan = nchan
704 self.nchan = nchan
706 self.plotFact = 1
705 self.plotFact = 1
707 nplots = nchan
706 nplots = nchan
708
707
709 if showSNR:
708 if showSNR:
710 nplots = nchan*2
709 nplots = nchan*2
711 self.plotFact = 2
710 self.plotFact = 2
712 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
711 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
713 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
712 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
714
713
715 self.setup(id=id,
714 self.setup(id=id,
716 nplots=nplots,
715 nplots=nplots,
717 wintitle=wintitle,
716 wintitle=wintitle,
718 show=show)
717 show=show)
719
718
720 if timerange != None:
719 if timerange != None:
721 self.timerange = timerange
720 self.timerange = timerange
722
721
723 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
722 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
724
723
725 if ymin == None: ymin = numpy.nanmin(y)
724 if ymin == None: ymin = numpy.nanmin(y)
726 if ymax == None: ymax = numpy.nanmax(y)
725 if ymax == None: ymax = numpy.nanmax(y)
727 if zmin == None: zmin = numpy.nanmin(z)
726 if zmin == None: zmin = numpy.nanmin(z)
728 if zmax == None: zmax = numpy.nanmax(z)
727 if zmax == None: zmax = numpy.nanmax(z)
729
728
730 self.FTP_WEI = ftp_wei
729 self.FTP_WEI = ftp_wei
731 self.EXP_CODE = exp_code
730 self.EXP_CODE = exp_code
732 self.SUB_EXP_CODE = sub_exp_code
731 self.SUB_EXP_CODE = sub_exp_code
733 self.PLOT_POS = plot_pos
732 self.PLOT_POS = plot_pos
734
733
735 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
734 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
736 self.isConfig = True
735 self.isConfig = True
737 self.figfile = figfile
736 self.figfile = figfile
738 update_figfile = True
737 update_figfile = True
739
738
740 self.setWinTitle(title)
739 self.setWinTitle(title)
741
740
742 for i in range(self.nchan):
741 for i in range(self.nchan):
743 index = channelIndexList[i]
742 index = channelIndexList[i]
744 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
743 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
745 axes = self.axesList[i*self.plotFact]
744 axes = self.axesList[i*self.plotFact]
746 z1 = z[i,:].reshape((1,-1))
745 z1 = z[i,:].reshape((1,-1))
747 axes.pcolorbuffer(x, y, z1,
746 axes.pcolorbuffer(x, y, z1,
748 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
747 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
749 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
748 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
750 ticksize=9, cblabel='', cbsize="1%",colormap=colormap)
749 ticksize=9, cblabel='', cbsize="1%",colormap=colormap)
751
750
752 if showSNR:
751 if showSNR:
753 title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
752 title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
754 axes = self.axesList[i*self.plotFact + 1]
753 axes = self.axesList[i*self.plotFact + 1]
755 SNRdB1 = SNRdB[i,:].reshape((1,-1))
754 SNRdB1 = SNRdB[i,:].reshape((1,-1))
756 axes.pcolorbuffer(x, y, SNRdB1,
755 axes.pcolorbuffer(x, y, SNRdB1,
757 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
756 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
758 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
757 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
759 ticksize=9, cblabel='', cbsize="1%",colormap='jet')
758 ticksize=9, cblabel='', cbsize="1%",colormap='jet')
760
759
761
760
762 self.draw()
761 self.draw()
763
762
764 if dataOut.ltctime >= self.xmax:
763 if dataOut.ltctime >= self.xmax:
765 self.counter_imagwr = wr_period
764 self.counter_imagwr = wr_period
766 self.isConfig = False
765 self.isConfig = False
767 update_figfile = True
766 update_figfile = True
768
767
769 self.save(figpath=figpath,
768 self.save(figpath=figpath,
770 figfile=figfile,
769 figfile=figfile,
771 save=save,
770 save=save,
772 ftp=ftp,
771 ftp=ftp,
773 wr_period=wr_period,
772 wr_period=wr_period,
774 thisDatetime=thisDatetime,
773 thisDatetime=thisDatetime,
775 update_figfile=update_figfile)
774 update_figfile=update_figfile)
776
775
777
776
778
777
779 class Parameters1Plot(Figure):
778 class Parameters1Plot(Figure):
780
779
781 __isConfig = None
780 __isConfig = None
782 __nsubplots = None
781 __nsubplots = None
783
782
784 WIDTHPROF = None
783 WIDTHPROF = None
785 HEIGHTPROF = None
784 HEIGHTPROF = None
786 PREFIX = 'prm'
785 PREFIX = 'prm'
787
786
788 def __init__(self, **kwargs):
787 def __init__(self, **kwargs):
789 Figure.__init__(self, **kwargs)
788 Figure.__init__(self, **kwargs)
790 self.timerange = 2*60*60
789 self.timerange = 2*60*60
791 self.isConfig = False
790 self.isConfig = False
792 self.__nsubplots = 1
791 self.__nsubplots = 1
793
792
794 self.WIDTH = 800
793 self.WIDTH = 800
795 self.HEIGHT = 150
794 self.HEIGHT = 180
796 self.WIDTHPROF = 120
795 self.WIDTHPROF = 120
797 self.HEIGHTPROF = 0
796 self.HEIGHTPROF = 0
798 self.counter_imagwr = 0
797 self.counter_imagwr = 0
799
798
800 self.PLOT_CODE = PARMS_CODE
799 self.PLOT_CODE = PARMS_CODE
801
800
802 self.FTP_WEI = None
801 self.FTP_WEI = None
803 self.EXP_CODE = None
802 self.EXP_CODE = None
804 self.SUB_EXP_CODE = None
803 self.SUB_EXP_CODE = None
805 self.PLOT_POS = None
804 self.PLOT_POS = None
806 self.tmin = None
805 self.tmin = None
807 self.tmax = None
806 self.tmax = None
808
807
809 self.xmin = None
808 self.xmin = None
810 self.xmax = None
809 self.xmax = None
811
810
812 self.figfile = None
811 self.figfile = None
813
812
814 def getSubplots(self):
813 def getSubplots(self):
815
814
816 ncol = 1
815 ncol = 1
817 nrow = self.nplots
816 nrow = self.nplots
818
817
819 return nrow, ncol
818 return nrow, ncol
820
819
821 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
820 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
822
821
823 self.__showprofile = showprofile
822 self.__showprofile = showprofile
824 self.nplots = nplots
823 self.nplots = nplots
825
824
826 ncolspan = 1
825 ncolspan = 1
827 colspan = 1
826 colspan = 1
828
827
829 self.createFigure(id = id,
828 self.createFigure(id = id,
830 wintitle = wintitle,
829 wintitle = wintitle,
831 widthplot = self.WIDTH + self.WIDTHPROF,
830 widthplot = self.WIDTH + self.WIDTHPROF,
832 heightplot = self.HEIGHT + self.HEIGHTPROF,
831 heightplot = self.HEIGHT + self.HEIGHTPROF,
833 show=show)
832 show=show)
834
833
835 nrow, ncol = self.getSubplots()
834 nrow, ncol = self.getSubplots()
836
835
837 counter = 0
836 counter = 0
838 for y in range(nrow):
837 for y in range(nrow):
839 for x in range(ncol):
838 for x in range(ncol):
840
839
841 if counter >= self.nplots:
840 if counter >= self.nplots:
842 break
841 break
843
842
844 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
843 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
845
844
846 if showprofile:
845 if showprofile:
847 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
846 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
848
847
849 counter += 1
848 counter += 1
850
849
851 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
850 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
852 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None,
851 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None,
853 parameterIndex = None, onlyPositive = False,
852 parameterIndex = None, onlyPositive = False,
854 SNRthresh = -numpy.inf, SNR = True, SNRmin = None, SNRmax = None, onlySNR = False,
853 SNRthresh = -numpy.inf, SNR = True, SNRmin = None, SNRmax = None, onlySNR = False,
855 DOP = True,
854 DOP = True,
856 zlabel = "", parameterName = "", parameterObject = "data_param",
855 zlabel = "", parameterName = "", parameterObject = "data_param",
857 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
856 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
858 server=None, folder=None, username=None, password=None,
857 server=None, folder=None, username=None, password=None,
859 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
858 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
860
859 #print inspect.getargspec(self.run).args
861 """
860 """
862
861
863 Input:
862 Input:
864 dataOut :
863 dataOut :
865 id :
864 id :
866 wintitle :
865 wintitle :
867 channelList :
866 channelList :
868 showProfile :
867 showProfile :
869 xmin : None,
868 xmin : None,
870 xmax : None,
869 xmax : None,
871 ymin : None,
870 ymin : None,
872 ymax : None,
871 ymax : None,
873 zmin : None,
872 zmin : None,
874 zmax : None
873 zmax : None
875 """
874 """
876
875
877 data_param = getattr(dataOut, parameterObject)
876 data_param = getattr(dataOut, parameterObject)
878
877
879 if channelList == None:
878 if channelList == None:
880 channelIndexList = numpy.arange(data_param.shape[0])
879 channelIndexList = numpy.arange(data_param.shape[0])
881 else:
880 else:
882 channelIndexList = numpy.array(channelList)
881 channelIndexList = numpy.array(channelList)
883
882
884 nchan = len(channelIndexList) #Number of channels being plotted
883 nchan = len(channelIndexList) #Number of channels being plotted
885
884
886 if nchan < 1:
885 if nchan < 1:
887 return
886 return
888
887
889 nGraphsByChannel = 0
888 nGraphsByChannel = 0
890
889
891 if SNR:
890 if SNR:
892 nGraphsByChannel += 1
891 nGraphsByChannel += 1
893 if DOP:
892 if DOP:
894 nGraphsByChannel += 1
893 nGraphsByChannel += 1
895
894
896 if nGraphsByChannel < 1:
895 if nGraphsByChannel < 1:
897 return
896 return
898
897
899 nplots = nGraphsByChannel*nchan
898 nplots = nGraphsByChannel*nchan
900
899
901 if timerange is not None:
900 if timerange is not None:
902 self.timerange = timerange
901 self.timerange = timerange
903
902
904 #tmin = None
903 #tmin = None
905 #tmax = None
904 #tmax = None
906 if parameterIndex == None:
905 if parameterIndex == None:
907 parameterIndex = 1
906 parameterIndex = 1
908
907
909 x = dataOut.getTimeRange1(dataOut.paramInterval)
908 x = dataOut.getTimeRange1(dataOut.paramInterval)
910 y = dataOut.heightList
909 y = dataOut.heightList
911 z = data_param[channelIndexList,parameterIndex,:].copy()
910 z = data_param[channelIndexList,parameterIndex,:].copy()
912
911
913 zRange = dataOut.abscissaList
912 zRange = dataOut.abscissaList
914 # nChannels = z.shape[0] #Number of wind dimensions estimated
913 # nChannels = z.shape[0] #Number of wind dimensions estimated
915 # thisDatetime = dataOut.datatime
914 # thisDatetime = dataOut.datatime
916
915
917 if dataOut.data_SNR is not None:
916 if dataOut.data_SNR is not None:
918 SNRarray = dataOut.data_SNR[channelIndexList,:]
917 SNRarray = dataOut.data_SNR[channelIndexList,:]
919 SNRdB = 10*numpy.log10(SNRarray)
918 SNRdB = 10*numpy.log10(SNRarray)
920 # SNRavgdB = 10*numpy.log10(SNRavg)
919 # SNRavgdB = 10*numpy.log10(SNRavg)
921 ind = numpy.where(SNRdB < 10**(SNRthresh/10))
920 ind = numpy.where(SNRdB < 10**(SNRthresh/10))
922 z[ind] = numpy.nan
921 z[ind] = numpy.nan
923
922
924 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
923 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
925 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
924 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
926 xlabel = ""
925 xlabel = ""
927 ylabel = "Range (Km)"
926 ylabel = "Range (Km)"
928
927
929 if (SNR and not onlySNR): nplots = 2*nplots
928 if (SNR and not onlySNR): nplots = 2*nplots
930
929
931 if onlyPositive:
930 if onlyPositive:
932 colormap = "jet"
931 colormap = "jet"
933 zmin = 0
932 zmin = 0
934 else: colormap = "RdBu_r"
933 else: colormap = "RdBu_r"
935
934
936 if not self.isConfig:
935 if not self.isConfig:
937
936
938 self.setup(id=id,
937 self.setup(id=id,
939 nplots=nplots,
938 nplots=nplots,
940 wintitle=wintitle,
939 wintitle=wintitle,
941 showprofile=showprofile,
940 showprofile=showprofile,
942 show=show)
941 show=show)
943
942
944 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
943 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
945
944
946 if ymin == None: ymin = numpy.nanmin(y)
945 if ymin == None: ymin = numpy.nanmin(y)
947 if ymax == None: ymax = numpy.nanmax(y)
946 if ymax == None: ymax = numpy.nanmax(y)
948 if zmin == None: zmin = numpy.nanmin(zRange)
947 if zmin == None: zmin = numpy.nanmin(zRange)
949 if zmax == None: zmax = numpy.nanmax(zRange)
948 if zmax == None: zmax = numpy.nanmax(zRange)
950
949
951 if SNR:
950 if SNR:
952 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
951 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
953 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
952 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
954
953
955 self.FTP_WEI = ftp_wei
954 self.FTP_WEI = ftp_wei
956 self.EXP_CODE = exp_code
955 self.EXP_CODE = exp_code
957 self.SUB_EXP_CODE = sub_exp_code
956 self.SUB_EXP_CODE = sub_exp_code
958 self.PLOT_POS = plot_pos
957 self.PLOT_POS = plot_pos
959
958
960 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
959 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
961 self.isConfig = True
960 self.isConfig = True
962 self.figfile = figfile
961 self.figfile = figfile
963
962
964 self.setWinTitle(title)
963 self.setWinTitle(title)
965
964
966 if ((self.xmax - x[1]) < (x[1]-x[0])):
965 if ((self.xmax - x[1]) < (x[1]-x[0])):
967 x[1] = self.xmax
966 x[1] = self.xmax
968
967
969 for i in range(nchan):
968 for i in range(nchan):
970
969
971 if (SNR and not onlySNR): j = 2*i
970 if (SNR and not onlySNR): j = 2*i
972 else: j = i
971 else: j = i
973
972
974 j = nGraphsByChannel*i
973 j = nGraphsByChannel*i
975
974
976 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
975 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
977 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
976 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
978
977
979 if not onlySNR:
978 if not onlySNR:
980 axes = self.axesList[j*self.__nsubplots]
979 axes = self.axesList[j*self.__nsubplots]
981 z1 = z[i,:].reshape((1,-1))
980 z1 = z[i,:].reshape((1,-1))
982 axes.pcolorbuffer(x, y, z1,
981 axes.pcolorbuffer(x, y, z1,
983 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
982 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
984 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
983 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
985 ticksize=9, cblabel=zlabel, cbsize="1%")
984 ticksize=9, cblabel=zlabel, cbsize="1%")
986
985
987 if DOP:
986 if DOP:
988 title = "%s Channel %d: %s" %(parameterName, channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
987 title = "%s Channel %d: %s" %(parameterName, channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
989
988
990 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
989 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
991 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
990 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
992 axes = self.axesList[j]
991 axes = self.axesList[j]
993 z1 = z[i,:].reshape((1,-1))
992 z1 = z[i,:].reshape((1,-1))
994 axes.pcolorbuffer(x, y, z1,
993 axes.pcolorbuffer(x, y, z1,
995 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
994 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
996 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
995 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
997 ticksize=9, cblabel=zlabel, cbsize="1%")
996 ticksize=9, cblabel=zlabel, cbsize="1%")
998
997
999 if SNR:
998 if SNR:
1000 title = "Channel %d Signal Noise Ratio (SNR): %s" %(channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
999 title = "Channel %d Signal Noise Ratio (SNR): %s" %(channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1001 axes = self.axesList[(j)*self.__nsubplots]
1000 axes = self.axesList[(j)*self.__nsubplots]
1002 if not onlySNR:
1001 if not onlySNR:
1003 axes = self.axesList[(j + 1)*self.__nsubplots]
1002 axes = self.axesList[(j + 1)*self.__nsubplots]
1004
1003
1005 axes = self.axesList[(j + nGraphsByChannel-1)]
1004 axes = self.axesList[(j + nGraphsByChannel-1)]
1006
1005
1007 z1 = SNRdB[i,:].reshape((1,-1))
1006 z1 = SNRdB[i,:].reshape((1,-1))
1008 axes.pcolorbuffer(x, y, z1,
1007 axes.pcolorbuffer(x, y, z1,
1009 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1008 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1010 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap="jet",
1009 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap="jet",
1011 ticksize=9, cblabel=zlabel, cbsize="1%")
1010 ticksize=9, cblabel=zlabel, cbsize="1%")
1012
1011
1013
1012
1014
1013
1015 self.draw()
1014 self.draw()
1016
1015
1017 if x[1] >= self.axesList[0].xmax:
1016 if x[1] >= self.axesList[0].xmax:
1018 self.counter_imagwr = wr_period
1017 self.counter_imagwr = wr_period
1019 self.isConfig = False
1018 self.isConfig = False
1020 self.figfile = None
1019 self.figfile = None
1021
1020
1022 self.save(figpath=figpath,
1021 self.save(figpath=figpath,
1023 figfile=figfile,
1022 figfile=figfile,
1024 save=save,
1023 save=save,
1025 ftp=ftp,
1024 ftp=ftp,
1026 wr_period=wr_period,
1025 wr_period=wr_period,
1027 thisDatetime=thisDatetime,
1026 thisDatetime=thisDatetime,
1028 update_figfile=False)
1027 update_figfile=False)
1029
1028
1030 class SpectralFittingPlot(Figure):
1029 class SpectralFittingPlot(Figure):
1031
1030
1032 __isConfig = None
1031 __isConfig = None
1033 __nsubplots = None
1032 __nsubplots = None
1034
1033
1035 WIDTHPROF = None
1034 WIDTHPROF = None
1036 HEIGHTPROF = None
1035 HEIGHTPROF = None
1037 PREFIX = 'prm'
1036 PREFIX = 'prm'
1038
1037
1039
1038
1040 N = None
1039 N = None
1041 ippSeconds = None
1040 ippSeconds = None
1042
1041
1043 def __init__(self, **kwargs):
1042 def __init__(self, **kwargs):
1044 Figure.__init__(self, **kwargs)
1043 Figure.__init__(self, **kwargs)
1045 self.isConfig = False
1044 self.isConfig = False
1046 self.__nsubplots = 1
1045 self.__nsubplots = 1
1047
1046
1048 self.PLOT_CODE = SPECFIT_CODE
1047 self.PLOT_CODE = SPECFIT_CODE
1049
1048
1050 self.WIDTH = 450
1049 self.WIDTH = 450
1051 self.HEIGHT = 250
1050 self.HEIGHT = 250
1052 self.WIDTHPROF = 0
1051 self.WIDTHPROF = 0
1053 self.HEIGHTPROF = 0
1052 self.HEIGHTPROF = 0
1054
1053
1055 def getSubplots(self):
1054 def getSubplots(self):
1056
1055
1057 ncol = int(numpy.sqrt(self.nplots)+0.9)
1056 ncol = int(numpy.sqrt(self.nplots)+0.9)
1058 nrow = int(self.nplots*1./ncol + 0.9)
1057 nrow = int(self.nplots*1./ncol + 0.9)
1059
1058
1060 return nrow, ncol
1059 return nrow, ncol
1061
1060
1062 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
1061 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
1063
1062
1064 showprofile = False
1063 showprofile = False
1065 self.__showprofile = showprofile
1064 self.__showprofile = showprofile
1066 self.nplots = nplots
1065 self.nplots = nplots
1067
1066
1068 ncolspan = 5
1067 ncolspan = 5
1069 colspan = 4
1068 colspan = 4
1070 if showprofile:
1069 if showprofile:
1071 ncolspan = 5
1070 ncolspan = 5
1072 colspan = 4
1071 colspan = 4
1073 self.__nsubplots = 2
1072 self.__nsubplots = 2
1074
1073
1075 self.createFigure(id = id,
1074 self.createFigure(id = id,
1076 wintitle = wintitle,
1075 wintitle = wintitle,
1077 widthplot = self.WIDTH + self.WIDTHPROF,
1076 widthplot = self.WIDTH + self.WIDTHPROF,
1078 heightplot = self.HEIGHT + self.HEIGHTPROF,
1077 heightplot = self.HEIGHT + self.HEIGHTPROF,
1079 show=show)
1078 show=show)
1080
1079
1081 nrow, ncol = self.getSubplots()
1080 nrow, ncol = self.getSubplots()
1082
1081
1083 counter = 0
1082 counter = 0
1084 for y in range(nrow):
1083 for y in range(nrow):
1085 for x in range(ncol):
1084 for x in range(ncol):
1086
1085
1087 if counter >= self.nplots:
1086 if counter >= self.nplots:
1088 break
1087 break
1089
1088
1090 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1089 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1091
1090
1092 if showprofile:
1091 if showprofile:
1093 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1092 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1094
1093
1095 counter += 1
1094 counter += 1
1096
1095
1097 def run(self, dataOut, id, cutHeight=None, fit=False, wintitle="", channelList=None, showprofile=True,
1096 def run(self, dataOut, id, cutHeight=None, fit=False, wintitle="", channelList=None, showprofile=True,
1098 xmin=None, xmax=None, ymin=None, ymax=None,
1097 xmin=None, xmax=None, ymin=None, ymax=None,
1099 save=False, figpath='./', figfile=None, show=True):
1098 save=False, figpath='./', figfile=None, show=True):
1100
1099
1101 """
1100 """
1102
1101
1103 Input:
1102 Input:
1104 dataOut :
1103 dataOut :
1105 id :
1104 id :
1106 wintitle :
1105 wintitle :
1107 channelList :
1106 channelList :
1108 showProfile :
1107 showProfile :
1109 xmin : None,
1108 xmin : None,
1110 xmax : None,
1109 xmax : None,
1111 zmin : None,
1110 zmin : None,
1112 zmax : None
1111 zmax : None
1113 """
1112 """
1114
1113
1115 if cutHeight==None:
1114 if cutHeight==None:
1116 h=270
1115 h=270
1117 heightindex = numpy.abs(cutHeight - dataOut.heightList).argmin()
1116 heightindex = numpy.abs(cutHeight - dataOut.heightList).argmin()
1118 cutHeight = dataOut.heightList[heightindex]
1117 cutHeight = dataOut.heightList[heightindex]
1119
1118
1120 factor = dataOut.normFactor
1119 factor = dataOut.normFactor
1121 x = dataOut.abscissaList[:-1]
1120 x = dataOut.abscissaList[:-1]
1122 #y = dataOut.getHeiRange()
1121 #y = dataOut.getHeiRange()
1123
1122
1124 z = dataOut.data_pre[:,:,heightindex]/factor
1123 z = dataOut.data_pre[:,:,heightindex]/factor
1125 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1124 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1126 avg = numpy.average(z, axis=1)
1125 avg = numpy.average(z, axis=1)
1127 listChannels = z.shape[0]
1126 listChannels = z.shape[0]
1128
1127
1129 #Reconstruct Function
1128 #Reconstruct Function
1130 if fit==True:
1129 if fit==True:
1131 groupArray = dataOut.groupList
1130 groupArray = dataOut.groupList
1132 listChannels = groupArray.reshape((groupArray.size))
1131 listChannels = groupArray.reshape((groupArray.size))
1133 listChannels.sort()
1132 listChannels.sort()
1134 spcFitLine = numpy.zeros(z.shape)
1133 spcFitLine = numpy.zeros(z.shape)
1135 constants = dataOut.constants
1134 constants = dataOut.constants
1136
1135
1137 nGroups = groupArray.shape[0]
1136 nGroups = groupArray.shape[0]
1138 nChannels = groupArray.shape[1]
1137 nChannels = groupArray.shape[1]
1139 nProfiles = z.shape[1]
1138 nProfiles = z.shape[1]
1140
1139
1141 for f in range(nGroups):
1140 for f in range(nGroups):
1142 groupChann = groupArray[f,:]
1141 groupChann = groupArray[f,:]
1143 p = dataOut.data_param[f,:,heightindex]
1142 p = dataOut.data_param[f,:,heightindex]
1144 # p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167])
1143 # p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167])
1145 fitLineAux = dataOut.library.modelFunction(p, constants)*nProfiles
1144 fitLineAux = dataOut.library.modelFunction(p, constants)*nProfiles
1146 fitLineAux = fitLineAux.reshape((nChannels,nProfiles))
1145 fitLineAux = fitLineAux.reshape((nChannels,nProfiles))
1147 spcFitLine[groupChann,:] = fitLineAux
1146 spcFitLine[groupChann,:] = fitLineAux
1148 # spcFitLine = spcFitLine/factor
1147 # spcFitLine = spcFitLine/factor
1149
1148
1150 z = z[listChannels,:]
1149 z = z[listChannels,:]
1151 spcFitLine = spcFitLine[listChannels,:]
1150 spcFitLine = spcFitLine[listChannels,:]
1152 spcFitLinedB = 10*numpy.log10(spcFitLine)
1151 spcFitLinedB = 10*numpy.log10(spcFitLine)
1153
1152
1154 zdB = 10*numpy.log10(z)
1153 zdB = 10*numpy.log10(z)
1155 #thisDatetime = dataOut.datatime
1154 #thisDatetime = dataOut.datatime
1156 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1155 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1157 title = wintitle + " Doppler Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1156 title = wintitle + " Doppler Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1158 xlabel = "Velocity (m/s)"
1157 xlabel = "Velocity (m/s)"
1159 ylabel = "Spectrum"
1158 ylabel = "Spectrum"
1160
1159
1161 if not self.isConfig:
1160 if not self.isConfig:
1162
1161
1163 nplots = listChannels.size
1162 nplots = listChannels.size
1164
1163
1165 self.setup(id=id,
1164 self.setup(id=id,
1166 nplots=nplots,
1165 nplots=nplots,
1167 wintitle=wintitle,
1166 wintitle=wintitle,
1168 showprofile=showprofile,
1167 showprofile=showprofile,
1169 show=show)
1168 show=show)
1170
1169
1171 if xmin == None: xmin = numpy.nanmin(x)
1170 if xmin == None: xmin = numpy.nanmin(x)
1172 if xmax == None: xmax = numpy.nanmax(x)
1171 if xmax == None: xmax = numpy.nanmax(x)
1173 if ymin == None: ymin = numpy.nanmin(zdB)
1172 if ymin == None: ymin = numpy.nanmin(zdB)
1174 if ymax == None: ymax = numpy.nanmax(zdB)+2
1173 if ymax == None: ymax = numpy.nanmax(zdB)+2
1175
1174
1176 self.isConfig = True
1175 self.isConfig = True
1177
1176
1178 self.setWinTitle(title)
1177 self.setWinTitle(title)
1179 for i in range(self.nplots):
1178 for i in range(self.nplots):
1180 # title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i])
1179 # title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i])
1181 title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i])
1180 title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i])
1182 axes = self.axesList[i*self.__nsubplots]
1181 axes = self.axesList[i*self.__nsubplots]
1183 if fit == False:
1182 if fit == False:
1184 axes.pline(x, zdB[i,:],
1183 axes.pline(x, zdB[i,:],
1185 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1184 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1186 xlabel=xlabel, ylabel=ylabel, title=title
1185 xlabel=xlabel, ylabel=ylabel, title=title
1187 )
1186 )
1188 if fit == True:
1187 if fit == True:
1189 fitline=spcFitLinedB[i,:]
1188 fitline=spcFitLinedB[i,:]
1190 y=numpy.vstack([zdB[i,:],fitline] )
1189 y=numpy.vstack([zdB[i,:],fitline] )
1191 legendlabels=['Data','Fitting']
1190 legendlabels=['Data','Fitting']
1192 axes.pmultilineyaxis(x, y,
1191 axes.pmultilineyaxis(x, y,
1193 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1192 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1194 xlabel=xlabel, ylabel=ylabel, title=title,
1193 xlabel=xlabel, ylabel=ylabel, title=title,
1195 legendlabels=legendlabels, marker=None,
1194 legendlabels=legendlabels, marker=None,
1196 linestyle='solid', grid='both')
1195 linestyle='solid', grid='both')
1197
1196
1198 self.draw()
1197 self.draw()
1199
1198
1200 self.save(figpath=figpath,
1199 self.save(figpath=figpath,
1201 figfile=figfile,
1200 figfile=figfile,
1202 save=save,
1201 save=save,
1203 ftp=ftp,
1202 ftp=ftp,
1204 wr_period=wr_period,
1203 wr_period=wr_period,
1205 thisDatetime=thisDatetime)
1204 thisDatetime=thisDatetime)
1206
1205
1207
1206
1208 class EWDriftsPlot(Figure):
1207 class EWDriftsPlot(Figure):
1209
1208
1210 __isConfig = None
1209 __isConfig = None
1211 __nsubplots = None
1210 __nsubplots = None
1212
1211
1213 WIDTHPROF = None
1212 WIDTHPROF = None
1214 HEIGHTPROF = None
1213 HEIGHTPROF = None
1215 PREFIX = 'drift'
1214 PREFIX = 'drift'
1216
1215
1217 def __init__(self, **kwargs):
1216 def __init__(self, **kwargs):
1218 Figure.__init__(self, **kwargs)
1217 Figure.__init__(self, **kwargs)
1219 self.timerange = 2*60*60
1218 self.timerange = 2*60*60
1220 self.isConfig = False
1219 self.isConfig = False
1221 self.__nsubplots = 1
1220 self.__nsubplots = 1
1222
1221
1223 self.WIDTH = 800
1222 self.WIDTH = 800
1224 self.HEIGHT = 150
1223 self.HEIGHT = 150
1225 self.WIDTHPROF = 120
1224 self.WIDTHPROF = 120
1226 self.HEIGHTPROF = 0
1225 self.HEIGHTPROF = 0
1227 self.counter_imagwr = 0
1226 self.counter_imagwr = 0
1228
1227
1229 self.PLOT_CODE = EWDRIFT_CODE
1228 self.PLOT_CODE = EWDRIFT_CODE
1230
1229
1231 self.FTP_WEI = None
1230 self.FTP_WEI = None
1232 self.EXP_CODE = None
1231 self.EXP_CODE = None
1233 self.SUB_EXP_CODE = None
1232 self.SUB_EXP_CODE = None
1234 self.PLOT_POS = None
1233 self.PLOT_POS = None
1235 self.tmin = None
1234 self.tmin = None
1236 self.tmax = None
1235 self.tmax = None
1237
1236
1238 self.xmin = None
1237 self.xmin = None
1239 self.xmax = None
1238 self.xmax = None
1240
1239
1241 self.figfile = None
1240 self.figfile = None
1242
1241
1243 def getSubplots(self):
1242 def getSubplots(self):
1244
1243
1245 ncol = 1
1244 ncol = 1
1246 nrow = self.nplots
1245 nrow = self.nplots
1247
1246
1248 return nrow, ncol
1247 return nrow, ncol
1249
1248
1250 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1249 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1251
1250
1252 self.__showprofile = showprofile
1251 self.__showprofile = showprofile
1253 self.nplots = nplots
1252 self.nplots = nplots
1254
1253
1255 ncolspan = 1
1254 ncolspan = 1
1256 colspan = 1
1255 colspan = 1
1257
1256
1258 self.createFigure(id = id,
1257 self.createFigure(id = id,
1259 wintitle = wintitle,
1258 wintitle = wintitle,
1260 widthplot = self.WIDTH + self.WIDTHPROF,
1259 widthplot = self.WIDTH + self.WIDTHPROF,
1261 heightplot = self.HEIGHT + self.HEIGHTPROF,
1260 heightplot = self.HEIGHT + self.HEIGHTPROF,
1262 show=show)
1261 show=show)
1263
1262
1264 nrow, ncol = self.getSubplots()
1263 nrow, ncol = self.getSubplots()
1265
1264
1266 counter = 0
1265 counter = 0
1267 for y in range(nrow):
1266 for y in range(nrow):
1268 if counter >= self.nplots:
1267 if counter >= self.nplots:
1269 break
1268 break
1270
1269
1271 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
1270 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
1272 counter += 1
1271 counter += 1
1273
1272
1274 def run(self, dataOut, id, wintitle="", channelList=None,
1273 def run(self, dataOut, id, wintitle="", channelList=None,
1275 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
1274 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
1276 zmaxVertical = None, zminVertical = None, zmaxZonal = None, zminZonal = None,
1275 zmaxVertical = None, zminVertical = None, zmaxZonal = None, zminZonal = None,
1277 timerange=None, SNRthresh = -numpy.inf, SNRmin = None, SNRmax = None, SNR_1 = False,
1276 timerange=None, SNRthresh = -numpy.inf, SNRmin = None, SNRmax = None, SNR_1 = False,
1278 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1277 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1279 server=None, folder=None, username=None, password=None,
1278 server=None, folder=None, username=None, password=None,
1280 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1279 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1281 """
1280 """
1282
1281
1283 Input:
1282 Input:
1284 dataOut :
1283 dataOut :
1285 id :
1284 id :
1286 wintitle :
1285 wintitle :
1287 channelList :
1286 channelList :
1288 showProfile :
1287 showProfile :
1289 xmin : None,
1288 xmin : None,
1290 xmax : None,
1289 xmax : None,
1291 ymin : None,
1290 ymin : None,
1292 ymax : None,
1291 ymax : None,
1293 zmin : None,
1292 zmin : None,
1294 zmax : None
1293 zmax : None
1295 """
1294 """
1296
1295
1297 if timerange is not None:
1296 if timerange is not None:
1298 self.timerange = timerange
1297 self.timerange = timerange
1299
1298
1300 tmin = None
1299 tmin = None
1301 tmax = None
1300 tmax = None
1302
1301
1303 x = dataOut.getTimeRange1(dataOut.outputInterval)
1302 x = dataOut.getTimeRange1(dataOut.outputInterval)
1304 # y = dataOut.heightList
1303 # y = dataOut.heightList
1305 y = dataOut.heightList
1304 y = dataOut.heightList
1306
1305
1307 z = dataOut.data_output
1306 z = dataOut.data_output
1308 nplots = z.shape[0] #Number of wind dimensions estimated
1307 nplots = z.shape[0] #Number of wind dimensions estimated
1309 nplotsw = nplots
1308 nplotsw = nplots
1310
1309
1311 #If there is a SNR function defined
1310 #If there is a SNR function defined
1312 if dataOut.data_SNR is not None:
1311 if dataOut.data_SNR is not None:
1313 nplots += 1
1312 nplots += 1
1314 SNR = dataOut.data_SNR
1313 SNR = dataOut.data_SNR
1315
1314
1316 if SNR_1:
1315 if SNR_1:
1317 SNR += 1
1316 SNR += 1
1318
1317
1319 SNRavg = numpy.average(SNR, axis=0)
1318 SNRavg = numpy.average(SNR, axis=0)
1320
1319
1321 SNRdB = 10*numpy.log10(SNR)
1320 SNRdB = 10*numpy.log10(SNR)
1322 SNRavgdB = 10*numpy.log10(SNRavg)
1321 SNRavgdB = 10*numpy.log10(SNRavg)
1323
1322
1324 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
1323 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
1325
1324
1326 for i in range(nplotsw):
1325 for i in range(nplotsw):
1327 z[i,ind] = numpy.nan
1326 z[i,ind] = numpy.nan
1328
1327
1329
1328
1330 showprofile = False
1329 showprofile = False
1331 # thisDatetime = dataOut.datatime
1330 # thisDatetime = dataOut.datatime
1332 thisDatetime = datetime.datetime.utcfromtimestamp(x[1])
1331 thisDatetime = datetime.datetime.utcfromtimestamp(x[1])
1333 title = wintitle + " EW Drifts"
1332 title = wintitle + " EW Drifts"
1334 xlabel = ""
1333 xlabel = ""
1335 ylabel = "Height (Km)"
1334 ylabel = "Height (Km)"
1336
1335
1337 if not self.isConfig:
1336 if not self.isConfig:
1338
1337
1339 self.setup(id=id,
1338 self.setup(id=id,
1340 nplots=nplots,
1339 nplots=nplots,
1341 wintitle=wintitle,
1340 wintitle=wintitle,
1342 showprofile=showprofile,
1341 showprofile=showprofile,
1343 show=show)
1342 show=show)
1344
1343
1345 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1344 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1346
1345
1347 if ymin == None: ymin = numpy.nanmin(y)
1346 if ymin == None: ymin = numpy.nanmin(y)
1348 if ymax == None: ymax = numpy.nanmax(y)
1347 if ymax == None: ymax = numpy.nanmax(y)
1349
1348
1350 if zmaxZonal == None: zmaxZonal = numpy.nanmax(abs(z[0,:]))
1349 if zmaxZonal == None: zmaxZonal = numpy.nanmax(abs(z[0,:]))
1351 if zminZonal == None: zminZonal = -zmaxZonal
1350 if zminZonal == None: zminZonal = -zmaxZonal
1352 if zmaxVertical == None: zmaxVertical = numpy.nanmax(abs(z[1,:]))
1351 if zmaxVertical == None: zmaxVertical = numpy.nanmax(abs(z[1,:]))
1353 if zminVertical == None: zminVertical = -zmaxVertical
1352 if zminVertical == None: zminVertical = -zmaxVertical
1354
1353
1355 if dataOut.data_SNR is not None:
1354 if dataOut.data_SNR is not None:
1356 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
1355 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
1357 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
1356 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
1358
1357
1359 self.FTP_WEI = ftp_wei
1358 self.FTP_WEI = ftp_wei
1360 self.EXP_CODE = exp_code
1359 self.EXP_CODE = exp_code
1361 self.SUB_EXP_CODE = sub_exp_code
1360 self.SUB_EXP_CODE = sub_exp_code
1362 self.PLOT_POS = plot_pos
1361 self.PLOT_POS = plot_pos
1363
1362
1364 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1363 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1365 self.isConfig = True
1364 self.isConfig = True
1366
1365
1367
1366
1368 self.setWinTitle(title)
1367 self.setWinTitle(title)
1369
1368
1370 if ((self.xmax - x[1]) < (x[1]-x[0])):
1369 if ((self.xmax - x[1]) < (x[1]-x[0])):
1371 x[1] = self.xmax
1370 x[1] = self.xmax
1372
1371
1373 strWind = ['Zonal','Vertical']
1372 strWind = ['Zonal','Vertical']
1374 strCb = 'Velocity (m/s)'
1373 strCb = 'Velocity (m/s)'
1375 zmaxVector = [zmaxZonal, zmaxVertical]
1374 zmaxVector = [zmaxZonal, zmaxVertical]
1376 zminVector = [zminZonal, zminVertical]
1375 zminVector = [zminZonal, zminVertical]
1377
1376
1378 for i in range(nplotsw):
1377 for i in range(nplotsw):
1379
1378
1380 title = "%s Drifts: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1379 title = "%s Drifts: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1381 axes = self.axesList[i*self.__nsubplots]
1380 axes = self.axesList[i*self.__nsubplots]
1382
1381
1383 z1 = z[i,:].reshape((1,-1))
1382 z1 = z[i,:].reshape((1,-1))
1384
1383
1385 axes.pcolorbuffer(x, y, z1,
1384 axes.pcolorbuffer(x, y, z1,
1386 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
1385 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
1387 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1386 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1388 ticksize=9, cblabel=strCb, cbsize="1%", colormap="RdBu_r")
1387 ticksize=9, cblabel=strCb, cbsize="1%", colormap="RdBu_r")
1389
1388
1390 if dataOut.data_SNR is not None:
1389 if dataOut.data_SNR is not None:
1391 i += 1
1390 i += 1
1392 if SNR_1:
1391 if SNR_1:
1393 title = "Signal Noise Ratio + 1 (SNR+1): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1392 title = "Signal Noise Ratio + 1 (SNR+1): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1394 else:
1393 else:
1395 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1394 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1396 axes = self.axesList[i*self.__nsubplots]
1395 axes = self.axesList[i*self.__nsubplots]
1397 SNRavgdB = SNRavgdB.reshape((1,-1))
1396 SNRavgdB = SNRavgdB.reshape((1,-1))
1398
1397
1399 axes.pcolorbuffer(x, y, SNRavgdB,
1398 axes.pcolorbuffer(x, y, SNRavgdB,
1400 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1399 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1401 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1400 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1402 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
1401 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
1403
1402
1404 self.draw()
1403 self.draw()
1405
1404
1406 if x[1] >= self.axesList[0].xmax:
1405 if x[1] >= self.axesList[0].xmax:
1407 self.counter_imagwr = wr_period
1406 self.counter_imagwr = wr_period
1408 self.isConfig = False
1407 self.isConfig = False
1409 self.figfile = None
1408 self.figfile = None
1410
1409
1411
1410
1412
1411
1413
1412
1414 class PhasePlot(Figure):
1413 class PhasePlot(Figure):
1415
1414
1416 __isConfig = None
1415 __isConfig = None
1417 __nsubplots = None
1416 __nsubplots = None
1418
1417
1419 PREFIX = 'mphase'
1418 PREFIX = 'mphase'
1420
1419
1421 def __init__(self, **kwargs):
1420 def __init__(self, **kwargs):
1422 Figure.__init__(self, **kwargs)
1421 Figure.__init__(self, **kwargs)
1423 self.timerange = 24*60*60
1422 self.timerange = 24*60*60
1424 self.isConfig = False
1423 self.isConfig = False
1425 self.__nsubplots = 1
1424 self.__nsubplots = 1
1426 self.counter_imagwr = 0
1425 self.counter_imagwr = 0
1427 self.WIDTH = 600
1426 self.WIDTH = 600
1428 self.HEIGHT = 300
1427 self.HEIGHT = 300
1429 self.WIDTHPROF = 120
1428 self.WIDTHPROF = 120
1430 self.HEIGHTPROF = 0
1429 self.HEIGHTPROF = 0
1431 self.xdata = None
1430 self.xdata = None
1432 self.ydata = None
1431 self.ydata = None
1433
1432
1434 self.PLOT_CODE = MPHASE_CODE
1433 self.PLOT_CODE = MPHASE_CODE
1435
1434
1436 self.FTP_WEI = None
1435 self.FTP_WEI = None
1437 self.EXP_CODE = None
1436 self.EXP_CODE = None
1438 self.SUB_EXP_CODE = None
1437 self.SUB_EXP_CODE = None
1439 self.PLOT_POS = None
1438 self.PLOT_POS = None
1440
1439
1441
1440
1442 self.filename_phase = None
1441 self.filename_phase = None
1443
1442
1444 self.figfile = None
1443 self.figfile = None
1445
1444
1446 def getSubplots(self):
1445 def getSubplots(self):
1447
1446
1448 ncol = 1
1447 ncol = 1
1449 nrow = 1
1448 nrow = 1
1450
1449
1451 return nrow, ncol
1450 return nrow, ncol
1452
1451
1453 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1452 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1454
1453
1455 self.__showprofile = showprofile
1454 self.__showprofile = showprofile
1456 self.nplots = nplots
1455 self.nplots = nplots
1457
1456
1458 ncolspan = 7
1457 ncolspan = 7
1459 colspan = 6
1458 colspan = 6
1460 self.__nsubplots = 2
1459 self.__nsubplots = 2
1461
1460
1462 self.createFigure(id = id,
1461 self.createFigure(id = id,
1463 wintitle = wintitle,
1462 wintitle = wintitle,
1464 widthplot = self.WIDTH+self.WIDTHPROF,
1463 widthplot = self.WIDTH+self.WIDTHPROF,
1465 heightplot = self.HEIGHT+self.HEIGHTPROF,
1464 heightplot = self.HEIGHT+self.HEIGHTPROF,
1466 show=show)
1465 show=show)
1467
1466
1468 nrow, ncol = self.getSubplots()
1467 nrow, ncol = self.getSubplots()
1469
1468
1470 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1469 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1471
1470
1472
1471
1473 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1472 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1474 xmin=None, xmax=None, ymin=None, ymax=None,
1473 xmin=None, xmax=None, ymin=None, ymax=None,
1475 timerange=None,
1474 timerange=None,
1476 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1475 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1477 server=None, folder=None, username=None, password=None,
1476 server=None, folder=None, username=None, password=None,
1478 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1477 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1479
1478
1480
1479
1481 tmin = None
1480 tmin = None
1482 tmax = None
1481 tmax = None
1483 x = dataOut.getTimeRange1(dataOut.outputInterval)
1482 x = dataOut.getTimeRange1(dataOut.outputInterval)
1484 y = dataOut.getHeiRange()
1483 y = dataOut.getHeiRange()
1485
1484
1486
1485
1487 #thisDatetime = dataOut.datatime
1486 #thisDatetime = dataOut.datatime
1488 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1487 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1489 title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1488 title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1490 xlabel = "Local Time"
1489 xlabel = "Local Time"
1491 ylabel = "Phase"
1490 ylabel = "Phase"
1492
1491
1493
1492
1494 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1493 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1495 phase_beacon = dataOut.data_output
1494 phase_beacon = dataOut.data_output
1496 update_figfile = False
1495 update_figfile = False
1497
1496
1498 if not self.isConfig:
1497 if not self.isConfig:
1499
1498
1500 self.nplots = phase_beacon.size
1499 self.nplots = phase_beacon.size
1501
1500
1502 self.setup(id=id,
1501 self.setup(id=id,
1503 nplots=self.nplots,
1502 nplots=self.nplots,
1504 wintitle=wintitle,
1503 wintitle=wintitle,
1505 showprofile=showprofile,
1504 showprofile=showprofile,
1506 show=show)
1505 show=show)
1507
1506
1508 if timerange is not None:
1507 if timerange is not None:
1509 self.timerange = timerange
1508 self.timerange = timerange
1510
1509
1511 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1510 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1512
1511
1513 if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0
1512 if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0
1514 if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0
1513 if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0
1515
1514
1516 self.FTP_WEI = ftp_wei
1515 self.FTP_WEI = ftp_wei
1517 self.EXP_CODE = exp_code
1516 self.EXP_CODE = exp_code
1518 self.SUB_EXP_CODE = sub_exp_code
1517 self.SUB_EXP_CODE = sub_exp_code
1519 self.PLOT_POS = plot_pos
1518 self.PLOT_POS = plot_pos
1520
1519
1521 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1520 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1522 self.isConfig = True
1521 self.isConfig = True
1523 self.figfile = figfile
1522 self.figfile = figfile
1524 self.xdata = numpy.array([])
1523 self.xdata = numpy.array([])
1525 self.ydata = numpy.array([])
1524 self.ydata = numpy.array([])
1526
1525
1527 #open file beacon phase
1526 #open file beacon phase
1528 path = '%s%03d' %(self.PREFIX, self.id)
1527 path = '%s%03d' %(self.PREFIX, self.id)
1529 beacon_file = os.path.join(path,'%s.txt'%self.name)
1528 beacon_file = os.path.join(path,'%s.txt'%self.name)
1530 self.filename_phase = os.path.join(figpath,beacon_file)
1529 self.filename_phase = os.path.join(figpath,beacon_file)
1531 update_figfile = True
1530 update_figfile = True
1532
1531
1533
1532
1534 #store data beacon phase
1533 #store data beacon phase
1535 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1534 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1536
1535
1537 self.setWinTitle(title)
1536 self.setWinTitle(title)
1538
1537
1539
1538
1540 title = "Phase Offset %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1539 title = "Phase Offset %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1541
1540
1542 legendlabels = ["phase %d"%(chan) for chan in numpy.arange(self.nplots)]
1541 legendlabels = ["phase %d"%(chan) for chan in numpy.arange(self.nplots)]
1543
1542
1544 axes = self.axesList[0]
1543 axes = self.axesList[0]
1545
1544
1546 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1545 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1547
1546
1548 if len(self.ydata)==0:
1547 if len(self.ydata)==0:
1549 self.ydata = phase_beacon.reshape(-1,1)
1548 self.ydata = phase_beacon.reshape(-1,1)
1550 else:
1549 else:
1551 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1550 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1552
1551
1553
1552
1554 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1553 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1555 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1554 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1556 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1555 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1557 XAxisAsTime=True, grid='both'
1556 XAxisAsTime=True, grid='both'
1558 )
1557 )
1559
1558
1560 self.draw()
1559 self.draw()
1561
1560
1562 self.save(figpath=figpath,
1561 self.save(figpath=figpath,
1563 figfile=figfile,
1562 figfile=figfile,
1564 save=save,
1563 save=save,
1565 ftp=ftp,
1564 ftp=ftp,
1566 wr_period=wr_period,
1565 wr_period=wr_period,
1567 thisDatetime=thisDatetime,
1566 thisDatetime=thisDatetime,
1568 update_figfile=update_figfile)
1567 update_figfile=update_figfile)
1569
1568
1570 if dataOut.ltctime + dataOut.outputInterval >= self.xmax:
1569 if dataOut.ltctime + dataOut.outputInterval >= self.xmax:
1571 self.counter_imagwr = wr_period
1570 self.counter_imagwr = wr_period
1572 self.isConfig = False
1571 self.isConfig = False
1573 update_figfile = True
1572 update_figfile = True
1574
1573
1575
1574
1576
1575
1577 class NSMeteorDetection1Plot(Figure):
1576 class NSMeteorDetection1Plot(Figure):
1578
1577
1579 isConfig = None
1578 isConfig = None
1580 __nsubplots = None
1579 __nsubplots = None
1581
1580
1582 WIDTHPROF = None
1581 WIDTHPROF = None
1583 HEIGHTPROF = None
1582 HEIGHTPROF = None
1584 PREFIX = 'nsm'
1583 PREFIX = 'nsm'
1585
1584
1586 zminList = None
1585 zminList = None
1587 zmaxList = None
1586 zmaxList = None
1588 cmapList = None
1587 cmapList = None
1589 titleList = None
1588 titleList = None
1590 nPairs = None
1589 nPairs = None
1591 nChannels = None
1590 nChannels = None
1592 nParam = None
1591 nParam = None
1593
1592
1594 def __init__(self, **kwargs):
1593 def __init__(self, **kwargs):
1595 Figure.__init__(self, **kwargs)
1594 Figure.__init__(self, **kwargs)
1596 self.isConfig = False
1595 self.isConfig = False
1597 self.__nsubplots = 1
1596 self.__nsubplots = 1
1598
1597
1599 self.WIDTH = 750
1598 self.WIDTH = 750
1600 self.HEIGHT = 250
1599 self.HEIGHT = 250
1601 self.WIDTHPROF = 120
1600 self.WIDTHPROF = 120
1602 self.HEIGHTPROF = 0
1601 self.HEIGHTPROF = 0
1603 self.counter_imagwr = 0
1602 self.counter_imagwr = 0
1604
1603
1605 self.PLOT_CODE = SPEC_CODE
1604 self.PLOT_CODE = SPEC_CODE
1606
1605
1607 self.FTP_WEI = None
1606 self.FTP_WEI = None
1608 self.EXP_CODE = None
1607 self.EXP_CODE = None
1609 self.SUB_EXP_CODE = None
1608 self.SUB_EXP_CODE = None
1610 self.PLOT_POS = None
1609 self.PLOT_POS = None
1611
1610
1612 self.__xfilter_ena = False
1611 self.__xfilter_ena = False
1613 self.__yfilter_ena = False
1612 self.__yfilter_ena = False
1614
1613
1615 def getSubplots(self):
1614 def getSubplots(self):
1616
1615
1617 ncol = 3
1616 ncol = 3
1618 nrow = int(numpy.ceil(self.nplots/3.0))
1617 nrow = int(numpy.ceil(self.nplots/3.0))
1619
1618
1620 return nrow, ncol
1619 return nrow, ncol
1621
1620
1622 def setup(self, id, nplots, wintitle, show=True):
1621 def setup(self, id, nplots, wintitle, show=True):
1623
1622
1624 self.nplots = nplots
1623 self.nplots = nplots
1625
1624
1626 ncolspan = 1
1625 ncolspan = 1
1627 colspan = 1
1626 colspan = 1
1628
1627
1629 self.createFigure(id = id,
1628 self.createFigure(id = id,
1630 wintitle = wintitle,
1629 wintitle = wintitle,
1631 widthplot = self.WIDTH + self.WIDTHPROF,
1630 widthplot = self.WIDTH + self.WIDTHPROF,
1632 heightplot = self.HEIGHT + self.HEIGHTPROF,
1631 heightplot = self.HEIGHT + self.HEIGHTPROF,
1633 show=show)
1632 show=show)
1634
1633
1635 nrow, ncol = self.getSubplots()
1634 nrow, ncol = self.getSubplots()
1636
1635
1637 counter = 0
1636 counter = 0
1638 for y in range(nrow):
1637 for y in range(nrow):
1639 for x in range(ncol):
1638 for x in range(ncol):
1640
1639
1641 if counter >= self.nplots:
1640 if counter >= self.nplots:
1642 break
1641 break
1643
1642
1644 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1643 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1645
1644
1646 counter += 1
1645 counter += 1
1647
1646
1648 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
1647 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
1649 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
1648 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
1650 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
1649 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
1651 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1650 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1652 server=None, folder=None, username=None, password=None,
1651 server=None, folder=None, username=None, password=None,
1653 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
1652 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
1654 xaxis="frequency"):
1653 xaxis="frequency"):
1655
1654
1656 """
1655 """
1657
1656
1658 Input:
1657 Input:
1659 dataOut :
1658 dataOut :
1660 id :
1659 id :
1661 wintitle :
1660 wintitle :
1662 channelList :
1661 channelList :
1663 showProfile :
1662 showProfile :
1664 xmin : None,
1663 xmin : None,
1665 xmax : None,
1664 xmax : None,
1666 ymin : None,
1665 ymin : None,
1667 ymax : None,
1666 ymax : None,
1668 zmin : None,
1667 zmin : None,
1669 zmax : None
1668 zmax : None
1670 """
1669 """
1671 #SEPARAR EN DOS PLOTS
1670 #SEPARAR EN DOS PLOTS
1672 nParam = dataOut.data_param.shape[1] - 3
1671 nParam = dataOut.data_param.shape[1] - 3
1673
1672
1674 utctime = dataOut.data_param[0,0]
1673 utctime = dataOut.data_param[0,0]
1675 tmet = dataOut.data_param[:,1].astype(int)
1674 tmet = dataOut.data_param[:,1].astype(int)
1676 hmet = dataOut.data_param[:,2].astype(int)
1675 hmet = dataOut.data_param[:,2].astype(int)
1677
1676
1678 x = dataOut.abscissaList
1677 x = dataOut.abscissaList
1679 y = dataOut.heightList
1678 y = dataOut.heightList
1680
1679
1681 z = numpy.zeros((nParam, y.size, x.size - 1))
1680 z = numpy.zeros((nParam, y.size, x.size - 1))
1682 z[:,:] = numpy.nan
1681 z[:,:] = numpy.nan
1683 z[:,hmet,tmet] = dataOut.data_param[:,3:].T
1682 z[:,hmet,tmet] = dataOut.data_param[:,3:].T
1684 z[0,:,:] = 10*numpy.log10(z[0,:,:])
1683 z[0,:,:] = 10*numpy.log10(z[0,:,:])
1685
1684
1686 xlabel = "Time (s)"
1685 xlabel = "Time (s)"
1687 ylabel = "Range (km)"
1686 ylabel = "Range (km)"
1688
1687
1689 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1688 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1690
1689
1691 if not self.isConfig:
1690 if not self.isConfig:
1692
1691
1693 nplots = nParam
1692 nplots = nParam
1694
1693
1695 self.setup(id=id,
1694 self.setup(id=id,
1696 nplots=nplots,
1695 nplots=nplots,
1697 wintitle=wintitle,
1696 wintitle=wintitle,
1698 show=show)
1697 show=show)
1699
1698
1700 if xmin is None: xmin = numpy.nanmin(x)
1699 if xmin is None: xmin = numpy.nanmin(x)
1701 if xmax is None: xmax = numpy.nanmax(x)
1700 if xmax is None: xmax = numpy.nanmax(x)
1702 if ymin is None: ymin = numpy.nanmin(y)
1701 if ymin is None: ymin = numpy.nanmin(y)
1703 if ymax is None: ymax = numpy.nanmax(y)
1702 if ymax is None: ymax = numpy.nanmax(y)
1704 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
1703 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
1705 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
1704 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
1706 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
1705 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
1707 if vmin is None: vmin = -vmax
1706 if vmin is None: vmin = -vmax
1708 if wmin is None: wmin = 0
1707 if wmin is None: wmin = 0
1709 if wmax is None: wmax = 50
1708 if wmax is None: wmax = 50
1710
1709
1711 pairsList = dataOut.groupList
1710 pairsList = dataOut.groupList
1712 self.nPairs = len(dataOut.groupList)
1711 self.nPairs = len(dataOut.groupList)
1713
1712
1714 zminList = [SNRmin, vmin, cmin] + [pmin]*self.nPairs
1713 zminList = [SNRmin, vmin, cmin] + [pmin]*self.nPairs
1715 zmaxList = [SNRmax, vmax, cmax] + [pmax]*self.nPairs
1714 zmaxList = [SNRmax, vmax, cmax] + [pmax]*self.nPairs
1716 titleList = ["SNR","Radial Velocity","Coherence"]
1715 titleList = ["SNR","Radial Velocity","Coherence"]
1717 cmapList = ["jet","RdBu_r","jet"]
1716 cmapList = ["jet","RdBu_r","jet"]
1718
1717
1719 for i in range(self.nPairs):
1718 for i in range(self.nPairs):
1720 strAux1 = "Phase Difference "+ str(pairsList[i][0]) + str(pairsList[i][1])
1719 strAux1 = "Phase Difference "+ str(pairsList[i][0]) + str(pairsList[i][1])
1721 titleList = titleList + [strAux1]
1720 titleList = titleList + [strAux1]
1722 cmapList = cmapList + ["RdBu_r"]
1721 cmapList = cmapList + ["RdBu_r"]
1723
1722
1724 self.zminList = zminList
1723 self.zminList = zminList
1725 self.zmaxList = zmaxList
1724 self.zmaxList = zmaxList
1726 self.cmapList = cmapList
1725 self.cmapList = cmapList
1727 self.titleList = titleList
1726 self.titleList = titleList
1728
1727
1729 self.FTP_WEI = ftp_wei
1728 self.FTP_WEI = ftp_wei
1730 self.EXP_CODE = exp_code
1729 self.EXP_CODE = exp_code
1731 self.SUB_EXP_CODE = sub_exp_code
1730 self.SUB_EXP_CODE = sub_exp_code
1732 self.PLOT_POS = plot_pos
1731 self.PLOT_POS = plot_pos
1733
1732
1734 self.isConfig = True
1733 self.isConfig = True
1735
1734
1736 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
1735 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
1737
1736
1738 for i in range(nParam):
1737 for i in range(nParam):
1739 title = self.titleList[i] + ": " +str_datetime
1738 title = self.titleList[i] + ": " +str_datetime
1740 axes = self.axesList[i]
1739 axes = self.axesList[i]
1741 axes.pcolor(x, y, z[i,:].T,
1740 axes.pcolor(x, y, z[i,:].T,
1742 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
1741 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
1743 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
1742 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
1744 self.draw()
1743 self.draw()
1745
1744
1746 if figfile == None:
1745 if figfile == None:
1747 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
1746 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
1748 name = str_datetime
1747 name = str_datetime
1749 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1748 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1750 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
1749 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
1751 figfile = self.getFilename(name)
1750 figfile = self.getFilename(name)
1752
1751
1753 self.save(figpath=figpath,
1752 self.save(figpath=figpath,
1754 figfile=figfile,
1753 figfile=figfile,
1755 save=save,
1754 save=save,
1756 ftp=ftp,
1755 ftp=ftp,
1757 wr_period=wr_period,
1756 wr_period=wr_period,
1758 thisDatetime=thisDatetime)
1757 thisDatetime=thisDatetime)
1759
1758
1760
1759
1761 class NSMeteorDetection2Plot(Figure):
1760 class NSMeteorDetection2Plot(Figure):
1762
1761
1763 isConfig = None
1762 isConfig = None
1764 __nsubplots = None
1763 __nsubplots = None
1765
1764
1766 WIDTHPROF = None
1765 WIDTHPROF = None
1767 HEIGHTPROF = None
1766 HEIGHTPROF = None
1768 PREFIX = 'nsm'
1767 PREFIX = 'nsm'
1769
1768
1770 zminList = None
1769 zminList = None
1771 zmaxList = None
1770 zmaxList = None
1772 cmapList = None
1771 cmapList = None
1773 titleList = None
1772 titleList = None
1774 nPairs = None
1773 nPairs = None
1775 nChannels = None
1774 nChannels = None
1776 nParam = None
1775 nParam = None
1777
1776
1778 def __init__(self, **kwargs):
1777 def __init__(self, **kwargs):
1779 Figure.__init__(self, **kwargs)
1778 Figure.__init__(self, **kwargs)
1780 self.isConfig = False
1779 self.isConfig = False
1781 self.__nsubplots = 1
1780 self.__nsubplots = 1
1782
1781
1783 self.WIDTH = 750
1782 self.WIDTH = 750
1784 self.HEIGHT = 250
1783 self.HEIGHT = 250
1785 self.WIDTHPROF = 120
1784 self.WIDTHPROF = 120
1786 self.HEIGHTPROF = 0
1785 self.HEIGHTPROF = 0
1787 self.counter_imagwr = 0
1786 self.counter_imagwr = 0
1788
1787
1789 self.PLOT_CODE = SPEC_CODE
1788 self.PLOT_CODE = SPEC_CODE
1790
1789
1791 self.FTP_WEI = None
1790 self.FTP_WEI = None
1792 self.EXP_CODE = None
1791 self.EXP_CODE = None
1793 self.SUB_EXP_CODE = None
1792 self.SUB_EXP_CODE = None
1794 self.PLOT_POS = None
1793 self.PLOT_POS = None
1795
1794
1796 self.__xfilter_ena = False
1795 self.__xfilter_ena = False
1797 self.__yfilter_ena = False
1796 self.__yfilter_ena = False
1798
1797
1799 def getSubplots(self):
1798 def getSubplots(self):
1800
1799
1801 ncol = 3
1800 ncol = 3
1802 nrow = int(numpy.ceil(self.nplots/3.0))
1801 nrow = int(numpy.ceil(self.nplots/3.0))
1803
1802
1804 return nrow, ncol
1803 return nrow, ncol
1805
1804
1806 def setup(self, id, nplots, wintitle, show=True):
1805 def setup(self, id, nplots, wintitle, show=True):
1807
1806
1808 self.nplots = nplots
1807 self.nplots = nplots
1809
1808
1810 ncolspan = 1
1809 ncolspan = 1
1811 colspan = 1
1810 colspan = 1
1812
1811
1813 self.createFigure(id = id,
1812 self.createFigure(id = id,
1814 wintitle = wintitle,
1813 wintitle = wintitle,
1815 widthplot = self.WIDTH + self.WIDTHPROF,
1814 widthplot = self.WIDTH + self.WIDTHPROF,
1816 heightplot = self.HEIGHT + self.HEIGHTPROF,
1815 heightplot = self.HEIGHT + self.HEIGHTPROF,
1817 show=show)
1816 show=show)
1818
1817
1819 nrow, ncol = self.getSubplots()
1818 nrow, ncol = self.getSubplots()
1820
1819
1821 counter = 0
1820 counter = 0
1822 for y in range(nrow):
1821 for y in range(nrow):
1823 for x in range(ncol):
1822 for x in range(ncol):
1824
1823
1825 if counter >= self.nplots:
1824 if counter >= self.nplots:
1826 break
1825 break
1827
1826
1828 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1827 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1829
1828
1830 counter += 1
1829 counter += 1
1831
1830
1832 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
1831 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
1833 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
1832 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
1834 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
1833 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
1835 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1834 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1836 server=None, folder=None, username=None, password=None,
1835 server=None, folder=None, username=None, password=None,
1837 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
1836 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
1838 xaxis="frequency"):
1837 xaxis="frequency"):
1839
1838
1840 """
1839 """
1841
1840
1842 Input:
1841 Input:
1843 dataOut :
1842 dataOut :
1844 id :
1843 id :
1845 wintitle :
1844 wintitle :
1846 channelList :
1845 channelList :
1847 showProfile :
1846 showProfile :
1848 xmin : None,
1847 xmin : None,
1849 xmax : None,
1848 xmax : None,
1850 ymin : None,
1849 ymin : None,
1851 ymax : None,
1850 ymax : None,
1852 zmin : None,
1851 zmin : None,
1853 zmax : None
1852 zmax : None
1854 """
1853 """
1855 #Rebuild matrix
1854 #Rebuild matrix
1856 utctime = dataOut.data_param[0,0]
1855 utctime = dataOut.data_param[0,0]
1857 cmet = dataOut.data_param[:,1].astype(int)
1856 cmet = dataOut.data_param[:,1].astype(int)
1858 tmet = dataOut.data_param[:,2].astype(int)
1857 tmet = dataOut.data_param[:,2].astype(int)
1859 hmet = dataOut.data_param[:,3].astype(int)
1858 hmet = dataOut.data_param[:,3].astype(int)
1860
1859
1861 nParam = 3
1860 nParam = 3
1862 nChan = len(dataOut.groupList)
1861 nChan = len(dataOut.groupList)
1863 x = dataOut.abscissaList
1862 x = dataOut.abscissaList
1864 y = dataOut.heightList
1863 y = dataOut.heightList
1865
1864
1866 z = numpy.full((nChan, nParam, y.size, x.size - 1),numpy.nan)
1865 z = numpy.full((nChan, nParam, y.size, x.size - 1),numpy.nan)
1867 z[cmet,:,hmet,tmet] = dataOut.data_param[:,4:]
1866 z[cmet,:,hmet,tmet] = dataOut.data_param[:,4:]
1868 z[:,0,:,:] = 10*numpy.log10(z[:,0,:,:]) #logarithmic scale
1867 z[:,0,:,:] = 10*numpy.log10(z[:,0,:,:]) #logarithmic scale
1869 z = numpy.reshape(z, (nChan*nParam, y.size, x.size-1))
1868 z = numpy.reshape(z, (nChan*nParam, y.size, x.size-1))
1870
1869
1871 xlabel = "Time (s)"
1870 xlabel = "Time (s)"
1872 ylabel = "Range (km)"
1871 ylabel = "Range (km)"
1873
1872
1874 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1873 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1875
1874
1876 if not self.isConfig:
1875 if not self.isConfig:
1877
1876
1878 nplots = nParam*nChan
1877 nplots = nParam*nChan
1879
1878
1880 self.setup(id=id,
1879 self.setup(id=id,
1881 nplots=nplots,
1880 nplots=nplots,
1882 wintitle=wintitle,
1881 wintitle=wintitle,
1883 show=show)
1882 show=show)
1884
1883
1885 if xmin is None: xmin = numpy.nanmin(x)
1884 if xmin is None: xmin = numpy.nanmin(x)
1886 if xmax is None: xmax = numpy.nanmax(x)
1885 if xmax is None: xmax = numpy.nanmax(x)
1887 if ymin is None: ymin = numpy.nanmin(y)
1886 if ymin is None: ymin = numpy.nanmin(y)
1888 if ymax is None: ymax = numpy.nanmax(y)
1887 if ymax is None: ymax = numpy.nanmax(y)
1889 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
1888 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
1890 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
1889 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
1891 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
1890 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
1892 if vmin is None: vmin = -vmax
1891 if vmin is None: vmin = -vmax
1893 if wmin is None: wmin = 0
1892 if wmin is None: wmin = 0
1894 if wmax is None: wmax = 50
1893 if wmax is None: wmax = 50
1895
1894
1896 self.nChannels = nChan
1895 self.nChannels = nChan
1897
1896
1898 zminList = []
1897 zminList = []
1899 zmaxList = []
1898 zmaxList = []
1900 titleList = []
1899 titleList = []
1901 cmapList = []
1900 cmapList = []
1902 for i in range(self.nChannels):
1901 for i in range(self.nChannels):
1903 strAux1 = "SNR Channel "+ str(i)
1902 strAux1 = "SNR Channel "+ str(i)
1904 strAux2 = "Radial Velocity Channel "+ str(i)
1903 strAux2 = "Radial Velocity Channel "+ str(i)
1905 strAux3 = "Spectral Width Channel "+ str(i)
1904 strAux3 = "Spectral Width Channel "+ str(i)
1906
1905
1907 titleList = titleList + [strAux1,strAux2,strAux3]
1906 titleList = titleList + [strAux1,strAux2,strAux3]
1908 cmapList = cmapList + ["jet","RdBu_r","jet"]
1907 cmapList = cmapList + ["jet","RdBu_r","jet"]
1909 zminList = zminList + [SNRmin,vmin,wmin]
1908 zminList = zminList + [SNRmin,vmin,wmin]
1910 zmaxList = zmaxList + [SNRmax,vmax,wmax]
1909 zmaxList = zmaxList + [SNRmax,vmax,wmax]
1911
1910
1912 self.zminList = zminList
1911 self.zminList = zminList
1913 self.zmaxList = zmaxList
1912 self.zmaxList = zmaxList
1914 self.cmapList = cmapList
1913 self.cmapList = cmapList
1915 self.titleList = titleList
1914 self.titleList = titleList
1916
1915
1917 self.FTP_WEI = ftp_wei
1916 self.FTP_WEI = ftp_wei
1918 self.EXP_CODE = exp_code
1917 self.EXP_CODE = exp_code
1919 self.SUB_EXP_CODE = sub_exp_code
1918 self.SUB_EXP_CODE = sub_exp_code
1920 self.PLOT_POS = plot_pos
1919 self.PLOT_POS = plot_pos
1921
1920
1922 self.isConfig = True
1921 self.isConfig = True
1923
1922
1924 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
1923 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
1925
1924
1926 for i in range(self.nplots):
1925 for i in range(self.nplots):
1927 title = self.titleList[i] + ": " +str_datetime
1926 title = self.titleList[i] + ": " +str_datetime
1928 axes = self.axesList[i]
1927 axes = self.axesList[i]
1929 axes.pcolor(x, y, z[i,:].T,
1928 axes.pcolor(x, y, z[i,:].T,
1930 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
1929 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
1931 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
1930 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
1932 self.draw()
1931 self.draw()
1933
1932
1934 if figfile == None:
1933 if figfile == None:
1935 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
1934 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
1936 name = str_datetime
1935 name = str_datetime
1937 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1936 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1938 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
1937 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
1939 figfile = self.getFilename(name)
1938 figfile = self.getFilename(name)
1940
1939
1941 self.save(figpath=figpath,
1940 self.save(figpath=figpath,
1942 figfile=figfile,
1941 figfile=figfile,
1943 save=save,
1942 save=save,
1944 ftp=ftp,
1943 ftp=ftp,
1945 wr_period=wr_period,
1944 wr_period=wr_period,
1946 thisDatetime=thisDatetime)
1945 thisDatetime=thisDatetime)
@@ -1,315 +1,347
1 '''
1 '''
2
2
3 $Author: murco $
3 $Author: murco $
4 $Id: jroproc_base.py 1 2012-11-12 18:56:07Z murco $
4 $Id: jroproc_base.py 1 2012-11-12 18:56:07Z murco $
5 '''
5 '''
6 import inspect
7 from fuzzywuzzy import process
8
9 def checkKwargs(method, kwargs):
10 currentKwargs = kwargs
11 choices = inspect.getargspec(method).args
12 try:
13 choices.remove('self')
14 except Exception as e:
15 pass
16
17 try:
18 choices.remove('dataOut')
19 except Exception as e:
20 pass
21
22 for kwarg in kwargs:
23 fuzz = process.extractOne(kwarg, choices)
24 print fuzz
25 if fuzz is None:
26 continue
27 if fuzz[1] < 100:
28 raise Exception('\x1b[2;30;43mDid you mean {} instead of {} in {}? \x1b[0m'.
29 format(fuzz[0], kwarg, method.__self__.__class__.__name__))
6
30
7 class ProcessingUnit(object):
31 class ProcessingUnit(object):
8
32
9 """
33 """
10 Esta es la clase base para el procesamiento de datos.
34 Esta es la clase base para el procesamiento de datos.
11
35
12 Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser:
36 Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser:
13 - Metodos internos (callMethod)
37 - Metodos internos (callMethod)
14 - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos
38 - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos
15 tienen que ser agreagados con el metodo "add".
39 tienen que ser agreagados con el metodo "add".
16
40
17 """
41 """
18 # objeto de datos de entrada (Voltage, Spectra o Correlation)
42 # objeto de datos de entrada (Voltage, Spectra o Correlation)
19 dataIn = None
43 dataIn = None
20 dataInList = []
44 dataInList = []
21
45
22 # objeto de datos de entrada (Voltage, Spectra o Correlation)
46 # objeto de datos de entrada (Voltage, Spectra o Correlation)
23 dataOut = None
47 dataOut = None
24
48
25 operations2RunDict = None
49 operations2RunDict = None
26
50
27 isConfig = False
51 isConfig = False
28
52
29
53
30 def __init__(self, *args, **kwargs):
54 def __init__(self, *args, **kwargs):
31
55
32 self.dataIn = None
56 self.dataIn = None
33 self.dataInList = []
57 self.dataInList = []
34
58
35 self.dataOut = None
59 self.dataOut = None
36
60
37 self.operations2RunDict = {}
61 self.operations2RunDict = {}
38 self.operationKwargs = {}
62 self.operationKwargs = {}
39
63
40 self.isConfig = False
64 self.isConfig = False
41
65
42 self.args = args
66 self.args = args
43 self.kwargs = kwargs
67 self.kwargs = kwargs
68 checkKwargs(self.run, kwargs)
69
70 def getAllowedArgs(self):
71 return inspect.getargspec(self.run).args
44
72
45 def addOperationKwargs(self, objId, **kwargs):
73 def addOperationKwargs(self, objId, **kwargs):
46 '''
74 '''
47 '''
75 '''
48
76
49 self.operationKwargs[objId] = kwargs
77 self.operationKwargs[objId] = kwargs
50
78
51
79
52 def addOperation(self, opObj, objId):
80 def addOperation(self, opObj, objId):
53
81
54 """
82 """
55 Agrega un objeto del tipo "Operation" (opObj) a la lista de objetos "self.objectList" y retorna el
83 Agrega un objeto del tipo "Operation" (opObj) a la lista de objetos "self.objectList" y retorna el
56 identificador asociado a este objeto.
84 identificador asociado a este objeto.
57
85
58 Input:
86 Input:
59
87
60 object : objeto de la clase "Operation"
88 object : objeto de la clase "Operation"
61
89
62 Return:
90 Return:
63
91
64 objId : identificador del objeto, necesario para ejecutar la operacion
92 objId : identificador del objeto, necesario para ejecutar la operacion
65 """
93 """
66
94
67 self.operations2RunDict[objId] = opObj
95 self.operations2RunDict[objId] = opObj
68
96
69 return objId
97 return objId
70
98
71 def getOperationObj(self, objId):
99 def getOperationObj(self, objId):
72
100
73 if objId not in self.operations2RunDict.keys():
101 if objId not in self.operations2RunDict.keys():
74 return None
102 return None
75
103
76 return self.operations2RunDict[objId]
104 return self.operations2RunDict[objId]
77
105
78 def operation(self, **kwargs):
106 def operation(self, **kwargs):
79
107
80 """
108 """
81 Operacion directa sobre la data (dataOut.data). Es necesario actualizar los valores de los
109 Operacion directa sobre la data (dataOut.data). Es necesario actualizar los valores de los
82 atributos del objeto dataOut
110 atributos del objeto dataOut
83
111
84 Input:
112 Input:
85
113
86 **kwargs : Diccionario de argumentos de la funcion a ejecutar
114 **kwargs : Diccionario de argumentos de la funcion a ejecutar
87 """
115 """
88
116
89 raise NotImplementedError
117 raise NotImplementedError
90
118
91 def callMethod(self, name, opId):
119 def callMethod(self, name, opId):
92
120
93 """
121 """
94 Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase.
122 Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase.
95
123
96 Input:
124 Input:
97 name : nombre del metodo a ejecutar
125 name : nombre del metodo a ejecutar
98
126
99 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
127 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
100
128
101 """
129 """
102
130
103 #Checking the inputs
131 #Checking the inputs
104 if name == 'run':
132 if name == 'run':
105
133
106 if not self.checkInputs():
134 if not self.checkInputs():
107 self.dataOut.flagNoData = True
135 self.dataOut.flagNoData = True
108 return False
136 return False
109 else:
137 else:
110 #Si no es un metodo RUN la entrada es la misma dataOut (interna)
138 #Si no es un metodo RUN la entrada es la misma dataOut (interna)
111 if self.dataOut is not None and self.dataOut.isEmpty():
139 if self.dataOut is not None and self.dataOut.isEmpty():
112 return False
140 return False
113
141
114 #Getting the pointer to method
142 #Getting the pointer to method
115 methodToCall = getattr(self, name)
143 methodToCall = getattr(self, name)
116
144
117 #Executing the self method
145 #Executing the self method
118
146
119 if hasattr(self, 'mp'):
147 if hasattr(self, 'mp'):
120 if name=='run':
148 if name=='run':
121 if self.mp is False:
149 if self.mp is False:
122 self.mp = True
150 self.mp = True
123 self.start()
151 self.start()
124 else:
152 else:
125 methodToCall(**self.operationKwargs[opId])
153 methodToCall(**self.operationKwargs[opId])
126 else:
154 else:
127 if name=='run':
155 if name=='run':
128 methodToCall(**self.kwargs)
156 methodToCall(**self.kwargs)
129 else:
157 else:
130 methodToCall(**self.operationKwargs[opId])
158 methodToCall(**self.operationKwargs[opId])
131
159
132 if self.dataOut is None:
160 if self.dataOut is None:
133 return False
161 return False
134
162
135 if self.dataOut.isEmpty():
163 if self.dataOut.isEmpty():
136 return False
164 return False
137
165
138 return True
166 return True
139
167
140 def callObject(self, objId):
168 def callObject(self, objId):
141
169
142 """
170 """
143 Ejecuta la operacion asociada al identificador del objeto "objId"
171 Ejecuta la operacion asociada al identificador del objeto "objId"
144
172
145 Input:
173 Input:
146
174
147 objId : identificador del objeto a ejecutar
175 objId : identificador del objeto a ejecutar
148
176
149 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
177 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
150
178
151 Return:
179 Return:
152
180
153 None
181 None
154 """
182 """
155
183
156 if self.dataOut is not None and self.dataOut.isEmpty():
184 if self.dataOut is not None and self.dataOut.isEmpty():
157 return False
185 return False
158
186
159 externalProcObj = self.operations2RunDict[objId]
187 externalProcObj = self.operations2RunDict[objId]
160
188
161 if hasattr(externalProcObj, 'mp'):
189 if hasattr(externalProcObj, 'mp'):
162 if externalProcObj.mp is False:
190 if externalProcObj.mp is False:
163 self.operationKwargs[objId] = externalProcObj.kwargs
191 self.operationKwargs[objId] = externalProcObj.kwargs
164 externalProcObj.mp = True
192 externalProcObj.mp = True
165 externalProcObj.start()
193 externalProcObj.start()
166 else:
194 else:
167 externalProcObj.run(self.dataOut, **externalProcObj.kwargs)
195 externalProcObj.run(self.dataOut, **externalProcObj.kwargs)
168 self.operationKwargs[objId] = externalProcObj.kwargs
196 self.operationKwargs[objId] = externalProcObj.kwargs
169
197
170 return True
198 return True
171
199
172 def call(self, opType, opName=None, opId=None):
200 def call(self, opType, opName=None, opId=None):
173
201
174 """
202 """
175 Return True si ejecuta la operacion interna nombrada "opName" o la operacion externa
203 Return True si ejecuta la operacion interna nombrada "opName" o la operacion externa
176 identificada con el id "opId"; con los argumentos "**kwargs".
204 identificada con el id "opId"; con los argumentos "**kwargs".
177
205
178 False si la operacion no se ha ejecutado.
206 False si la operacion no se ha ejecutado.
179
207
180 Input:
208 Input:
181
209
182 opType : Puede ser "self" o "external"
210 opType : Puede ser "self" o "external"
183
211
184 Depende del tipo de operacion para llamar a:callMethod or callObject:
212 Depende del tipo de operacion para llamar a:callMethod or callObject:
185
213
186 1. If opType = "self": Llama a un metodo propio de esta clase:
214 1. If opType = "self": Llama a un metodo propio de esta clase:
187
215
188 name_method = getattr(self, name)
216 name_method = getattr(self, name)
189 name_method(**kwargs)
217 name_method(**kwargs)
190
218
191
219
192 2. If opType = "other" o"external": Llama al metodo "run()" de una instancia de la
220 2. If opType = "other" o"external": Llama al metodo "run()" de una instancia de la
193 clase "Operation" o de un derivado de ella:
221 clase "Operation" o de un derivado de ella:
194
222
195 instanceName = self.operationList[opId]
223 instanceName = self.operationList[opId]
196 instanceName.run(**kwargs)
224 instanceName.run(**kwargs)
197
225
198 opName : Si la operacion es interna (opType = 'self'), entonces el "opName" sera
226 opName : Si la operacion es interna (opType = 'self'), entonces el "opName" sera
199 usada para llamar a un metodo interno de la clase Processing
227 usada para llamar a un metodo interno de la clase Processing
200
228
201 opId : Si la operacion es externa (opType = 'other' o 'external), entonces el
229 opId : Si la operacion es externa (opType = 'other' o 'external), entonces el
202 "opId" sera usada para llamar al metodo "run" de la clase Operation
230 "opId" sera usada para llamar al metodo "run" de la clase Operation
203 registrada anteriormente con ese Id
231 registrada anteriormente con ese Id
204
232
205 Exception:
233 Exception:
206 Este objeto de tipo Operation debe de haber sido agregado antes con el metodo:
234 Este objeto de tipo Operation debe de haber sido agregado antes con el metodo:
207 "addOperation" e identificado con el valor "opId" = el id de la operacion.
235 "addOperation" e identificado con el valor "opId" = el id de la operacion.
208 De lo contrario retornara un error del tipo ValueError
236 De lo contrario retornara un error del tipo ValueError
209
237
210 """
238 """
211
239
212 if opType == 'self':
240 if opType == 'self':
213
241
214 if not opName:
242 if not opName:
215 raise ValueError, "opName parameter should be defined"
243 raise ValueError, "opName parameter should be defined"
216
244
217 sts = self.callMethod(opName, opId)
245 sts = self.callMethod(opName, opId)
218
246
219 elif opType == 'other' or opType == 'external' or opType == 'plotter':
247 elif opType == 'other' or opType == 'external' or opType == 'plotter':
220
248
221 if not opId:
249 if not opId:
222 raise ValueError, "opId parameter should be defined"
250 raise ValueError, "opId parameter should be defined"
223
251
224 if opId not in self.operations2RunDict.keys():
252 if opId not in self.operations2RunDict.keys():
225 raise ValueError, "Any operation with id=%s has been added" %str(opId)
253 raise ValueError, "Any operation with id=%s has been added" %str(opId)
226
254
227 sts = self.callObject(opId)
255 sts = self.callObject(opId)
228
256
229 else:
257 else:
230 raise ValueError, "opType should be 'self', 'external' or 'plotter'; and not '%s'" %opType
258 raise ValueError, "opType should be 'self', 'external' or 'plotter'; and not '%s'" %opType
231
259
232 return sts
260 return sts
233
261
234 def setInput(self, dataIn):
262 def setInput(self, dataIn):
235
263
236 self.dataIn = dataIn
264 self.dataIn = dataIn
237 self.dataInList.append(dataIn)
265 self.dataInList.append(dataIn)
238
266
239 def getOutputObj(self):
267 def getOutputObj(self):
240
268
241 return self.dataOut
269 return self.dataOut
242
270
243 def checkInputs(self):
271 def checkInputs(self):
244
272
245 for thisDataIn in self.dataInList:
273 for thisDataIn in self.dataInList:
246
274
247 if thisDataIn.isEmpty():
275 if thisDataIn.isEmpty():
248 return False
276 return False
249
277
250 return True
278 return True
251
279
252 def setup(self):
280 def setup(self):
253
281
254 raise NotImplementedError
282 raise NotImplementedError
255
283
256 def run(self):
284 def run(self):
257
285
258 raise NotImplementedError
286 raise NotImplementedError
259
287
260 def close(self):
288 def close(self):
261 #Close every thread, queue or any other object here is it is neccesary.
289 #Close every thread, queue or any other object here is it is neccesary.
262 return
290 return
263
291
264 class Operation(object):
292 class Operation(object):
265
293
266 """
294 """
267 Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit
295 Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit
268 y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de
296 y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de
269 acumulacion dentro de esta clase
297 acumulacion dentro de esta clase
270
298
271 Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer)
299 Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer)
272
300
273 """
301 """
274
302
275 __buffer = None
303 __buffer = None
276 isConfig = False
304 isConfig = False
277
305
278 def __init__(self, **kwargs):
306 def __init__(self, **kwargs):
279
307
280 self.__buffer = None
308 self.__buffer = None
281 self.isConfig = False
309 self.isConfig = False
282 self.kwargs = kwargs
310 self.kwargs = kwargs
311 checkKwargs(self.run, kwargs)
312
313 def getAllowedArgs(self):
314 return inspect.getargspec(self.run).args
283
315
284 def setup(self):
316 def setup(self):
285
317
286 self.isConfig = True
318 self.isConfig = True
287
319
288 raise NotImplementedError
320 raise NotImplementedError
289
321
290 def run(self, dataIn, **kwargs):
322 def run(self, dataIn, **kwargs):
291
323
292 """
324 """
293 Realiza las operaciones necesarias sobre la dataIn.data y actualiza los
325 Realiza las operaciones necesarias sobre la dataIn.data y actualiza los
294 atributos del objeto dataIn.
326 atributos del objeto dataIn.
295
327
296 Input:
328 Input:
297
329
298 dataIn : objeto del tipo JROData
330 dataIn : objeto del tipo JROData
299
331
300 Return:
332 Return:
301
333
302 None
334 None
303
335
304 Affected:
336 Affected:
305 __buffer : buffer de recepcion de datos.
337 __buffer : buffer de recepcion de datos.
306
338
307 """
339 """
308 if not self.isConfig:
340 if not self.isConfig:
309 self.setup(**kwargs)
341 self.setup(**kwargs)
310
342
311 raise NotImplementedError
343 raise NotImplementedError
312
344
313 def close(self):
345 def close(self):
314
346
315 pass
347 pass
@@ -1,87 +1,96
1 import argparse
1 import argparse
2
2
3 from schainpy.controller import Project, multiSchain
3 from schainpy.controller import Project, multiSchain
4
4
5 desc = "HF_EXAMPLE"
5 desc = "HF_EXAMPLE"
6
6
7 def fiber(cursor, skip, q, dt):
7 def fiber(cursor, skip, q, dt):
8
8
9 controllerObj = Project()
9 controllerObj = Project()
10
10
11 controllerObj.setup(id='191', name='test01', description=desc)
11 controllerObj.setup(id='191', name='test01', description=desc)
12
12
13 readUnitConfObj = controllerObj.addReadUnit(datatype='SpectraReader',
13 readUnitConfObj = controllerObj.addReadUnit(datatype='SpectraReader',
14 path='/home/nanosat/data/hysell_data20/pdata',
14 path='/home/nanosat/data/julia',
15 startDate=dt,
15 startDate=dt,
16 endDate=dt,
16 endDate=dt,
17 startTime="00:00:00",
17 startTime="00:00:00",
18 endTime="23:59:59",
18 endTie="23:59:59",
19 online=0,
19 online=0,
20 #set=1426485881,
20 #set=1426485881,
21 delay=10,
21 delay=10,
22 walk=1,
22 walk=1,
23 queue=q,
23 queue=q,
24 cursor=cursor,
24 cursor=cursor,
25 skip=skip,
25 skip=skip,
26 #timezone=-5*3600
26 #timezone=-5*3600
27 )
27 )
28
28
29 # #opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock')
29 # #opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock')
30 #
30 #
31 procUnitConfObj2 = controllerObj.addProcUnit(datatype='Spectra', inputId=readUnitConfObj.getId())
31 procUnitConfObj2 = controllerObj.addProcUnit(datatype='Spectra', inputId=readUnitConfObj.getId())
32 # opObj11 = procUnitConfObj2.addParameter(name='pairsList', value='(0,1)', format='pairslist')
32 # procUnitConfObj2.addParameter(name='nipp', value='5', format='int')
33 #
33
34 procUnitConfObj3 = controllerObj.addProcUnit(datatype='ParametersProc', inputId=readUnitConfObj.getId())
34 procUnitConfObj3 = controllerObj.addProcUnit(datatype='ParametersProc', inputId=readUnitConfObj.getId())
35 opObj11 = procUnitConfObj3.addOperation(name='SpectralMoments', optype='other')
35 opObj11 = procUnitConfObj3.addOperation(name='SpectralMoments', optype='other')
36
36
37 #
37 #
38 # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other')
38 # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other')
39 # opObj11.addParameter(name='id', value='1000', format='int')
39 # opObj11.addParameter(name='id', value='1000', format='int')
40 # opObj11.addParameter(name='wintitle', value='HF_Jicamarca_Spc', format='str')
40 # opObj11.addParameter(name='wintitle', value='HF_Jicamarca_Spc', format='str')
41 # opObj11.addParameter(name='channelList', value='0', format='intlist')
41 # opObj11.addParameter(name='channelList', value='0', format='intlist')
42 # opObj11.addParameter(name='zmin', value='-120', format='float')
42 # opObj11.addParameter(name='zmin', value='-120', format='float')
43 # opObj11.addParameter(name='zmax', value='-70', format='float')
43 # opObj11.addParameter(name='zmax', value='-70', format='float')
44 # opObj11.addParameter(name='save', value='1', format='int')
44 # opObj11.addParameter(name='save', value='1', format='int')
45 # opObj11.addParameter(name='figpath', value=figpath, format='str')
45 # opObj11.addParameter(name='figpath', value=figpath, format='str')
46
46
47 # opObj11 = procUnitConfObj2.addOperation(name='RTIPlot', optype='other')
47 opObj11 = procUnitConfObj3.addOperation(name='Parameters1Plot', optype='other')
48 # opObj11.addParameter(name='id', value='2000', format='int')
48 opObj11.addParameter(name='channelList', value='0', format='intList')
49 # opObj11.addParameter(name='wintitzmaxle', value='HF_Jicamarca', format='str')
49
50 # opObj11.addParameter(name='showprofile', value='0', format='int')
50 opObj11.addParameter(name='id', value='2000', format='int')
51 # opObj11.addParameter(name='colormap', value='0', format='bool')
52 opObj11.addParameter(name='onlySNR', value='1', format='bool')
53 opObj11.addParameter(name='DOP', value='0', format='bool')
54 # opObj11.addParameter(name='showSNR', value='1', format='bool')
55 # opObj11.addParameter(name='SNRthresh', value='0', format='int')
56 # opObj11.addParameter(name='SNRmin', value='-10', format='int')
57 # opObj11.addParameter(name='SNRmax', value='30', format='int')
58
59 # opObj11.addParameter(name='showSNR', value='1', format='int')
51 # # opObj11.addParameter(name='channelList', value='0', format='intlist')
60 # # opObj11.addParameter(name='channelList', value='0', format='intlist')
52 # # opObj11.addParameter(name='xmin', value='0', format='float')
61 # # opObj11.addParameter(name='xmin', value='0', format='float')
53 # opObj11.addParameter(name='xmin', value='0', format='float')
62 # opObj11.addParameter(name='xmin', value='0', format='float')
54 # opObj11.addParameter(name='xmax', value='24', format='float')
63 # opObj11.addParameter(name='xmax', value='24', format='float')
55
64
56 # opObj11.addParameter(name='zmin', value='-110', format='float')
65 # opObj11.addParameter(name='zmin', value='-110', format='float')
57 # opObj11.addParameter(name='zmax', value='-70', format='float')
66 # opObj11.addParameter(name='zmax', value='-70', format='float')
58 # opObj11.addParameter(name='save', value='0', format='int')
67 # opObj11.addParameter(name='save', value='0', format='int')
59 # # opObj11.addParameter(name='figpath', value='/tmp/', format='str')
68 # # opObj11.addParameter(name='figpath', value='/tmp/', format='str')
60 #
69 #
61 opObj12 = procUnitConfObj3.addOperation(name='PublishData', optype='other')
70 opObj12 = procUnitConfObj3.addOperation(name='PublishData', optype='other')
62 opObj12.addParameter(name='zeromq', value=1, format='int')
71 opObj12.addParameter(name='zeromq', value=1, format='int')
63
72
64
73
65 # opObj13 = procUnitConfObj3.addOperation(name='PublishData', optype='other')
74 # opObj13 = procUnitConfObj3.addOperation(name='PublishData', optype='other')
66 # opObj13.addParameter(name='zeromq', value=1, format='int')
75 # opObj13.addParameter(name='zeromq', value=1, format='int')
67 # opObj13.addParameter(name='server', value="juanca", format='str')
76 # opObj13.addParameter(name='server', value="juanca", format='str')
68
77
69 opObj12.addParameter(name='delay', value=1, format='int')
78 opObj12.addParameter(name='delay', value=1, format='int')
70
79
71
80
72 # print "Escribiendo el archivo XML"
81 # print "Escribiendo el archivo XML"
73 # controllerObj.writeXml(filename)
82 # controllerObj.writeXml(filename)
74 # print "Leyendo el archivo XML"
83 # print "Leyendo el archivo XML"
75 # controllerObj.readXml(filename)
84 # controllerObj.readXml(filename)
76
85
77
86
78 # timeit.timeit('controllerObj.run()', number=2)
87 # timeit.timeit('controllerObj.run()', number=2)
79
88
80 controllerObj.start()
89 controllerObj.start()
81
90
82
91
83 if __name__ == '__main__':
92 if __name__ == '__main__':
84 parser = argparse.ArgumentParser(description='Set number of parallel processes')
93 parser = argparse.ArgumentParser(description='Set number of parallel processes')
85 parser.add_argument('--nProcess', default=1, type=int)
94 parser.add_argument('--nProcess', default=1, type=int)
86 args = parser.parse_args()
95 args = parser.parse_args()
87 multiSchain(fiber, nProcess=args.nProcess, startDate='2015/09/26', endDate='2015/09/26')
96 multiSchain(fiber, nProcess=args.nProcess, startDate='2015/09/26', endDate='2015/09/26')
@@ -1,1 +1,1
1 <Project description="HF_EXAMPLE" id="191" name="test01"><ReadUnit datatype="SpectraReader" id="1911" inputId="0" name="SpectraReader"><Operation id="19111" name="run" priority="1" type="self"><Parameter format="str" id="191111" name="datatype" value="SpectraReader" /><Parameter format="str" id="191112" name="path" value="/home/nanosat/data/hysell_data20/pdata" /><Parameter format="date" id="191113" name="startDate" value="2015/09/26" /><Parameter format="date" id="191114" name="endDate" value="2015/09/26" /><Parameter format="time" id="191115" name="startTime" value="00:00:00" /><Parameter format="time" id="191116" name="endTime" value="23:59:59" /><Parameter format="int" id="191118" name="cursor" value="2" /><Parameter format="int" id="191119" name="skip" value="720" /><Parameter format="int" id="191120" name="delay" value="10" /><Parameter format="int" id="191121" name="walk" value="1" /><Parameter format="int" id="191122" name="online" value="0" /></Operation></ReadUnit><ProcUnit datatype="ParametersProc" id="1913" inputId="1911" name="ParametersProc"><Operation id="19131" name="run" priority="1" type="self" /><Operation id="19132" name="SpectralMoments" priority="2" type="other" /><Operation id="19133" name="PublishData" priority="3" type="other"><Parameter format="int" id="191331" name="zeromq" value="1" /><Parameter format="int" id="191332" name="delay" value="1" /></Operation></ProcUnit><ProcUnit datatype="Spectra" id="1912" inputId="1911" name="SpectraProc"><Operation id="19121" name="run" priority="1" type="self" /></ProcUnit></Project> No newline at end of file
1 <Project description="HF_EXAMPLE" id="191" name="test01"><ReadUnit datatype="SpectraReader" id="1911" inputId="0" name="SpectraReader"><Operation id="19111" name="run" priority="1" type="self"><Parameter format="str" id="191111" name="datatype" value="SpectraReader" /><Parameter format="str" id="191112" name="path" value="/home/nanosat/data/julia" /><Parameter format="date" id="191113" name="startDate" value="2015/09/26" /><Parameter format="date" id="191114" name="endDate" value="2015/09/26" /><Parameter format="time" id="191115" name="startTime" value="00:00:00" /><Parameter format="time" id="191116" name="endTime" value="23:59:59" /><Parameter format="int" id="191118" name="cursor" value="0" /><Parameter format="int" id="191119" name="skip" value="0" /><Parameter format="int" id="191120" name="delay" value="10" /><Parameter format="int" id="191121" name="walk" value="1" /><Parameter format="int" id="191122" name="online" value="0" /></Operation></ReadUnit><ProcUnit datatype="ParametersProc" id="1913" inputId="1911" name="ParametersProc"><Operation id="19131" name="run" priority="1" type="self" /><Operation id="19132" name="SpectralMoments" priority="2" type="other" /><Operation id="19133" name="Parameters1Plot" priority="3" type="other"><Parameter format="intlist" id="191331" name="channelList" value="0" /><Parameter format="int" id="191332" name="id" value="2000" /><Parameter format="bool" id="191333" name="olySNR" value="1" /><Parameter format="bool" id="191334" name="DOP" value="0" /></Operation><Operation id="19134" name="PublishData" priority="4" type="other"><Parameter format="int" id="191341" name="zeromq" value="1" /><Parameter format="int" id="191342" name="delay" value="1" /></Operation></ProcUnit><ProcUnit datatype="Spectra" id="1912" inputId="1911" name="SpectraProc"><Operation id="19121" name="run" priority="1" type="self" /></ProcUnit></Project> No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now