@@ -0,0 +1,196 | |||
|
1 | import os | |
|
2 | import datetime | |
|
3 | import numpy | |
|
4 | import copy | |
|
5 | ||
|
6 | from figure import Figure, isRealtime | |
|
7 | ||
|
8 | class CorrelationPlot(Figure): | |
|
9 | ||
|
10 | isConfig = None | |
|
11 | __nsubplots = None | |
|
12 | ||
|
13 | WIDTHPROF = None | |
|
14 | HEIGHTPROF = None | |
|
15 | PREFIX = 'corr' | |
|
16 | ||
|
17 | def __init__(self): | |
|
18 | ||
|
19 | self.isConfig = False | |
|
20 | self.__nsubplots = 1 | |
|
21 | ||
|
22 | self.WIDTH = 280 | |
|
23 | self.HEIGHT = 250 | |
|
24 | self.WIDTHPROF = 120 | |
|
25 | self.HEIGHTPROF = 0 | |
|
26 | self.counter_imagwr = 0 | |
|
27 | ||
|
28 | self.PLOT_CODE = 1 | |
|
29 | self.FTP_WEI = None | |
|
30 | self.EXP_CODE = None | |
|
31 | self.SUB_EXP_CODE = None | |
|
32 | self.PLOT_POS = None | |
|
33 | ||
|
34 | def getSubplots(self): | |
|
35 | ||
|
36 | ncol = int(numpy.sqrt(self.nplots)+0.9) | |
|
37 | nrow = int(self.nplots*1./ncol + 0.9) | |
|
38 | ||
|
39 | return nrow, ncol | |
|
40 | ||
|
41 | def setup(self, id, nplots, wintitle, showprofile=False, show=True): | |
|
42 | ||
|
43 | showprofile = False | |
|
44 | self.__showprofile = showprofile | |
|
45 | self.nplots = nplots | |
|
46 | ||
|
47 | ncolspan = 1 | |
|
48 | colspan = 1 | |
|
49 | if showprofile: | |
|
50 | ncolspan = 3 | |
|
51 | colspan = 2 | |
|
52 | self.__nsubplots = 2 | |
|
53 | ||
|
54 | self.createFigure(id = id, | |
|
55 | wintitle = wintitle, | |
|
56 | widthplot = self.WIDTH + self.WIDTHPROF, | |
|
57 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
|
58 | show=show) | |
|
59 | ||
|
60 | nrow, ncol = self.getSubplots() | |
|
61 | ||
|
62 | counter = 0 | |
|
63 | for y in range(nrow): | |
|
64 | for x in range(ncol): | |
|
65 | ||
|
66 | if counter >= self.nplots: | |
|
67 | break | |
|
68 | ||
|
69 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
|
70 | ||
|
71 | if showprofile: | |
|
72 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
|
73 | ||
|
74 | counter += 1 | |
|
75 | ||
|
76 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False, | |
|
77 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
|
78 | save=False, figpath='', figfile=None, show=True, ftp=False, wr_period=1, | |
|
79 | server=None, folder=None, username=None, password=None, | |
|
80 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): | |
|
81 | ||
|
82 | """ | |
|
83 | ||
|
84 | Input: | |
|
85 | dataOut : | |
|
86 | id : | |
|
87 | wintitle : | |
|
88 | channelList : | |
|
89 | showProfile : | |
|
90 | xmin : None, | |
|
91 | xmax : None, | |
|
92 | ymin : None, | |
|
93 | ymax : None, | |
|
94 | zmin : None, | |
|
95 | zmax : None | |
|
96 | """ | |
|
97 | ||
|
98 | if dataOut.flagNoData: | |
|
99 | return None | |
|
100 | ||
|
101 | if realtime: | |
|
102 | if not(isRealtime(utcdatatime = dataOut.utctime)): | |
|
103 | print 'Skipping this plot function' | |
|
104 | return | |
|
105 | ||
|
106 | if channelList == None: | |
|
107 | channelIndexList = dataOut.channelIndexList | |
|
108 | else: | |
|
109 | channelIndexList = [] | |
|
110 | for channel in channelList: | |
|
111 | if channel not in dataOut.channelList: | |
|
112 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
|
113 | channelIndexList.append(dataOut.channelList.index(channel)) | |
|
114 | ||
|
115 | factor = dataOut.normFactor | |
|
116 | lenfactor = factor.shape[1] | |
|
117 | x = dataOut.getLagTRange(1) | |
|
118 | y = dataOut.getHeiRange() | |
|
119 | ||
|
120 | z = copy.copy(dataOut.data_corr[:,:,0,:]) | |
|
121 | for i in range(dataOut.data_corr.shape[0]): | |
|
122 | z[i,:,:] = z[i,:,:]/factor[i,:] | |
|
123 | zdB = numpy.abs(z) | |
|
124 | ||
|
125 | avg = numpy.average(z, axis=1) | |
|
126 | # avg = numpy.nanmean(z, axis=1) | |
|
127 | # noise = dataOut.noise/factor | |
|
128 | ||
|
129 | #thisDatetime = dataOut.datatime | |
|
130 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
|
131 | title = wintitle + " Correlation" | |
|
132 | xlabel = "Lag T (s)" | |
|
133 | ylabel = "Range (Km)" | |
|
134 | ||
|
135 | if not self.isConfig: | |
|
136 | ||
|
137 | nplots = dataOut.data_corr.shape[0] | |
|
138 | ||
|
139 | self.setup(id=id, | |
|
140 | nplots=nplots, | |
|
141 | wintitle=wintitle, | |
|
142 | showprofile=showprofile, | |
|
143 | show=show) | |
|
144 | ||
|
145 | if xmin == None: xmin = numpy.nanmin(x) | |
|
146 | if xmax == None: xmax = numpy.nanmax(x) | |
|
147 | if ymin == None: ymin = numpy.nanmin(y) | |
|
148 | if ymax == None: ymax = numpy.nanmax(y) | |
|
149 | if zmin == None: zmin = 0 | |
|
150 | if zmax == None: zmax = 1 | |
|
151 | ||
|
152 | self.FTP_WEI = ftp_wei | |
|
153 | self.EXP_CODE = exp_code | |
|
154 | self.SUB_EXP_CODE = sub_exp_code | |
|
155 | self.PLOT_POS = plot_pos | |
|
156 | ||
|
157 | self.isConfig = True | |
|
158 | ||
|
159 | self.setWinTitle(title) | |
|
160 | ||
|
161 | for i in range(self.nplots): | |
|
162 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) | |
|
163 | title = "Channel %d and %d: : %s" %(dataOut.pairsList[i][0]+1,dataOut.pairsList[i][1]+1 , str_datetime) | |
|
164 | axes = self.axesList[i*self.__nsubplots] | |
|
165 | axes.pcolor(x, y, zdB[i,:,:], | |
|
166 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
|
167 | xlabel=xlabel, ylabel=ylabel, title=title, | |
|
168 | ticksize=9, cblabel='') | |
|
169 | ||
|
170 | # if self.__showprofile: | |
|
171 | # axes = self.axesList[i*self.__nsubplots +1] | |
|
172 | # axes.pline(avgdB[i], y, | |
|
173 | # xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |
|
174 | # xlabel='dB', ylabel='', title='', | |
|
175 | # ytick_visible=False, | |
|
176 | # grid='x') | |
|
177 | # | |
|
178 | # noiseline = numpy.repeat(noisedB[i], len(y)) | |
|
179 | # axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) | |
|
180 | ||
|
181 | self.draw() | |
|
182 | ||
|
183 | if figfile == None: | |
|
184 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
|
185 | figfile = self.getFilename(name = str_datetime) | |
|
186 | ||
|
187 | if figpath != '': | |
|
188 | self.counter_imagwr += 1 | |
|
189 | if (self.counter_imagwr>=wr_period): | |
|
190 | # store png plot to local folder | |
|
191 | self.saveFigure(figpath, figfile) | |
|
192 | # store png plot to FTP server according to RT-Web format | |
|
193 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
|
194 | ftp_filename = os.path.join(figpath, name) | |
|
195 | self.saveFigure(figpath, ftp_filename) | |
|
196 | self.counter_imagwr = 0 |
This diff has been collapsed as it changes many lines, (579 lines changed) Show them Hide them | |||
@@ -0,0 +1,579 | |||
|
1 | import os | |
|
2 | import datetime | |
|
3 | import numpy | |
|
4 | ||
|
5 | from figure import Figure, isRealtime | |
|
6 | ||
|
7 | class MomentsPlot(Figure): | |
|
8 | ||
|
9 | isConfig = None | |
|
10 | __nsubplots = None | |
|
11 | ||
|
12 | WIDTHPROF = None | |
|
13 | HEIGHTPROF = None | |
|
14 | PREFIX = 'prm' | |
|
15 | ||
|
16 | def __init__(self): | |
|
17 | ||
|
18 | self.isConfig = False | |
|
19 | self.__nsubplots = 1 | |
|
20 | ||
|
21 | self.WIDTH = 280 | |
|
22 | self.HEIGHT = 250 | |
|
23 | self.WIDTHPROF = 120 | |
|
24 | self.HEIGHTPROF = 0 | |
|
25 | self.counter_imagwr = 0 | |
|
26 | ||
|
27 | self.PLOT_CODE = 1 | |
|
28 | self.FTP_WEI = None | |
|
29 | self.EXP_CODE = None | |
|
30 | self.SUB_EXP_CODE = None | |
|
31 | self.PLOT_POS = None | |
|
32 | ||
|
33 | def getSubplots(self): | |
|
34 | ||
|
35 | ncol = int(numpy.sqrt(self.nplots)+0.9) | |
|
36 | nrow = int(self.nplots*1./ncol + 0.9) | |
|
37 | ||
|
38 | return nrow, ncol | |
|
39 | ||
|
40 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
|
41 | ||
|
42 | self.__showprofile = showprofile | |
|
43 | self.nplots = nplots | |
|
44 | ||
|
45 | ncolspan = 1 | |
|
46 | colspan = 1 | |
|
47 | if showprofile: | |
|
48 | ncolspan = 3 | |
|
49 | colspan = 2 | |
|
50 | self.__nsubplots = 2 | |
|
51 | ||
|
52 | self.createFigure(id = id, | |
|
53 | wintitle = wintitle, | |
|
54 | widthplot = self.WIDTH + self.WIDTHPROF, | |
|
55 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
|
56 | show=show) | |
|
57 | ||
|
58 | nrow, ncol = self.getSubplots() | |
|
59 | ||
|
60 | counter = 0 | |
|
61 | for y in range(nrow): | |
|
62 | for x in range(ncol): | |
|
63 | ||
|
64 | if counter >= self.nplots: | |
|
65 | break | |
|
66 | ||
|
67 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
|
68 | ||
|
69 | if showprofile: | |
|
70 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
|
71 | ||
|
72 | counter += 1 | |
|
73 | ||
|
74 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, | |
|
75 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
|
76 | save=False, figpath='', figfile=None, show=True, ftp=False, wr_period=1, | |
|
77 | server=None, folder=None, username=None, password=None, | |
|
78 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): | |
|
79 | ||
|
80 | """ | |
|
81 | ||
|
82 | Input: | |
|
83 | dataOut : | |
|
84 | id : | |
|
85 | wintitle : | |
|
86 | channelList : | |
|
87 | showProfile : | |
|
88 | xmin : None, | |
|
89 | xmax : None, | |
|
90 | ymin : None, | |
|
91 | ymax : None, | |
|
92 | zmin : None, | |
|
93 | zmax : None | |
|
94 | """ | |
|
95 | ||
|
96 | if dataOut.flagNoData: | |
|
97 | return None | |
|
98 | ||
|
99 | if realtime: | |
|
100 | if not(isRealtime(utcdatatime = dataOut.utctime)): | |
|
101 | print 'Skipping this plot function' | |
|
102 | return | |
|
103 | ||
|
104 | if channelList == None: | |
|
105 | channelIndexList = dataOut.channelIndexList | |
|
106 | else: | |
|
107 | channelIndexList = [] | |
|
108 | for channel in channelList: | |
|
109 | if channel not in dataOut.channelList: | |
|
110 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
|
111 | channelIndexList.append(dataOut.channelList.index(channel)) | |
|
112 | ||
|
113 | factor = dataOut.normFactor | |
|
114 | x = dataOut.abscissaRange | |
|
115 | y = dataOut.heightRange | |
|
116 | ||
|
117 | z = dataOut.data_pre[channelIndexList,:,:]/factor | |
|
118 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
|
119 | avg = numpy.average(z, axis=1) | |
|
120 | noise = dataOut.noise/factor | |
|
121 | ||
|
122 | zdB = 10*numpy.log10(z) | |
|
123 | avgdB = 10*numpy.log10(avg) | |
|
124 | noisedB = 10*numpy.log10(noise) | |
|
125 | ||
|
126 | #thisDatetime = dataOut.datatime | |
|
127 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
|
128 | title = wintitle + " Parameters" | |
|
129 | xlabel = "Velocity (m/s)" | |
|
130 | ylabel = "Range (Km)" | |
|
131 | ||
|
132 | if not self.isConfig: | |
|
133 | ||
|
134 | nplots = len(channelIndexList) | |
|
135 | ||
|
136 | self.setup(id=id, | |
|
137 | nplots=nplots, | |
|
138 | wintitle=wintitle, | |
|
139 | showprofile=showprofile, | |
|
140 | show=show) | |
|
141 | ||
|
142 | if xmin == None: xmin = numpy.nanmin(x) | |
|
143 | if xmax == None: xmax = numpy.nanmax(x) | |
|
144 | if ymin == None: ymin = numpy.nanmin(y) | |
|
145 | if ymax == None: ymax = numpy.nanmax(y) | |
|
146 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 | |
|
147 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 | |
|
148 | ||
|
149 | self.FTP_WEI = ftp_wei | |
|
150 | self.EXP_CODE = exp_code | |
|
151 | self.SUB_EXP_CODE = sub_exp_code | |
|
152 | self.PLOT_POS = plot_pos | |
|
153 | ||
|
154 | self.isConfig = True | |
|
155 | ||
|
156 | self.setWinTitle(title) | |
|
157 | ||
|
158 | for i in range(self.nplots): | |
|
159 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) | |
|
160 | title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i]+1, noisedB[i], str_datetime) | |
|
161 | axes = self.axesList[i*self.__nsubplots] | |
|
162 | axes.pcolor(x, y, zdB[i,:,:], | |
|
163 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
|
164 | xlabel=xlabel, ylabel=ylabel, title=title, | |
|
165 | ticksize=9, cblabel='') | |
|
166 | #Mean Line | |
|
167 | mean = dataOut.data_param[i, 1, :] | |
|
168 | axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1) | |
|
169 | ||
|
170 | if self.__showprofile: | |
|
171 | axes = self.axesList[i*self.__nsubplots +1] | |
|
172 | axes.pline(avgdB[i], y, | |
|
173 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |
|
174 | xlabel='dB', ylabel='', title='', | |
|
175 | ytick_visible=False, | |
|
176 | grid='x') | |
|
177 | ||
|
178 | noiseline = numpy.repeat(noisedB[i], len(y)) | |
|
179 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) | |
|
180 | ||
|
181 | self.draw() | |
|
182 | ||
|
183 | if figfile == None: | |
|
184 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
|
185 | figfile = self.getFilename(name = str_datetime) | |
|
186 | ||
|
187 | if figpath != '': | |
|
188 | self.counter_imagwr += 1 | |
|
189 | if (self.counter_imagwr>=wr_period): | |
|
190 | # store png plot to local folder | |
|
191 | self.saveFigure(figpath, figfile) | |
|
192 | # store png plot to FTP server according to RT-Web format | |
|
193 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
|
194 | ftp_filename = os.path.join(figpath, name) | |
|
195 | self.saveFigure(figpath, ftp_filename) | |
|
196 | self.counter_imagwr = 0 | |
|
197 | ||
|
198 | class SkyMapPlot(Figure): | |
|
199 | ||
|
200 | __isConfig = None | |
|
201 | __nsubplots = None | |
|
202 | ||
|
203 | WIDTHPROF = None | |
|
204 | HEIGHTPROF = None | |
|
205 | PREFIX = 'prm' | |
|
206 | ||
|
207 | def __init__(self): | |
|
208 | ||
|
209 | self.__isConfig = False | |
|
210 | self.__nsubplots = 1 | |
|
211 | ||
|
212 | # self.WIDTH = 280 | |
|
213 | # self.HEIGHT = 250 | |
|
214 | self.WIDTH = 600 | |
|
215 | self.HEIGHT = 600 | |
|
216 | self.WIDTHPROF = 120 | |
|
217 | self.HEIGHTPROF = 0 | |
|
218 | self.counter_imagwr = 0 | |
|
219 | ||
|
220 | self.PLOT_CODE = 1 | |
|
221 | self.FTP_WEI = None | |
|
222 | self.EXP_CODE = None | |
|
223 | self.SUB_EXP_CODE = None | |
|
224 | self.PLOT_POS = None | |
|
225 | ||
|
226 | def getSubplots(self): | |
|
227 | ||
|
228 | ncol = int(numpy.sqrt(self.nplots)+0.9) | |
|
229 | nrow = int(self.nplots*1./ncol + 0.9) | |
|
230 | ||
|
231 | return nrow, ncol | |
|
232 | ||
|
233 | def setup(self, id, nplots, wintitle, showprofile=False, show=True): | |
|
234 | ||
|
235 | self.__showprofile = showprofile | |
|
236 | self.nplots = nplots | |
|
237 | ||
|
238 | ncolspan = 1 | |
|
239 | colspan = 1 | |
|
240 | ||
|
241 | self.createFigure(id = id, | |
|
242 | wintitle = wintitle, | |
|
243 | widthplot = self.WIDTH, #+ self.WIDTHPROF, | |
|
244 | heightplot = self.HEIGHT,# + self.HEIGHTPROF, | |
|
245 | show=show) | |
|
246 | ||
|
247 | nrow, ncol = 1,1 | |
|
248 | counter = 0 | |
|
249 | x = 0 | |
|
250 | y = 0 | |
|
251 | self.addAxes(1, 1, 0, 0, 1, 1, True) | |
|
252 | ||
|
253 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False, | |
|
254 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
|
255 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, | |
|
256 | server=None, folder=None, username=None, password=None, | |
|
257 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): | |
|
258 | ||
|
259 | """ | |
|
260 | ||
|
261 | Input: | |
|
262 | dataOut : | |
|
263 | id : | |
|
264 | wintitle : | |
|
265 | channelList : | |
|
266 | showProfile : | |
|
267 | xmin : None, | |
|
268 | xmax : None, | |
|
269 | ymin : None, | |
|
270 | ymax : None, | |
|
271 | zmin : None, | |
|
272 | zmax : None | |
|
273 | """ | |
|
274 | ||
|
275 | arrayParameters = dataOut.data_param | |
|
276 | error = arrayParameters[:,-1] | |
|
277 | indValid = numpy.where(error == 0)[0] | |
|
278 | finalMeteor = arrayParameters[indValid,:] | |
|
279 | finalAzimuth = finalMeteor[:,4] | |
|
280 | finalZenith = finalMeteor[:,5] | |
|
281 | ||
|
282 | x = finalAzimuth*numpy.pi/180 | |
|
283 | y = finalZenith | |
|
284 | ||
|
285 | ||
|
286 | #thisDatetime = dataOut.datatime | |
|
287 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
|
288 | title = wintitle + " Parameters" | |
|
289 | xlabel = "Zonal Zenith Angle (deg) " | |
|
290 | ylabel = "Meridional Zenith Angle (deg)" | |
|
291 | ||
|
292 | if not self.__isConfig: | |
|
293 | ||
|
294 | nplots = 1 | |
|
295 | ||
|
296 | self.setup(id=id, | |
|
297 | nplots=nplots, | |
|
298 | wintitle=wintitle, | |
|
299 | showprofile=showprofile, | |
|
300 | show=show) | |
|
301 | ||
|
302 | self.FTP_WEI = ftp_wei | |
|
303 | self.EXP_CODE = exp_code | |
|
304 | self.SUB_EXP_CODE = sub_exp_code | |
|
305 | self.PLOT_POS = plot_pos | |
|
306 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
|
307 | self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) | |
|
308 | self.__isConfig = True | |
|
309 | ||
|
310 | self.setWinTitle(title) | |
|
311 | ||
|
312 | i = 0 | |
|
313 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) | |
|
314 | ||
|
315 | axes = self.axesList[i*self.__nsubplots] | |
|
316 | nevents = axes.x_buffer.shape[0] + x.shape[0] | |
|
317 | title = "Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n" %(self.firstdate,str_datetime,nevents) | |
|
318 | axes.polar(x, y, | |
|
319 | title=title, xlabel=xlabel, ylabel=ylabel, | |
|
320 | ticksize=9, cblabel='') | |
|
321 | ||
|
322 | self.draw() | |
|
323 | ||
|
324 | if save: | |
|
325 | ||
|
326 | self.counter_imagwr += 1 | |
|
327 | if (self.counter_imagwr==wr_period): | |
|
328 | ||
|
329 | if figfile == None: | |
|
330 | figfile = self.getFilename(name = self.name) | |
|
331 | self.saveFigure(figpath, figfile) | |
|
332 | ||
|
333 | if ftp: | |
|
334 | #provisionalmente envia archivos en el formato de la web en tiempo real | |
|
335 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
|
336 | path = '%s%03d' %(self.PREFIX, self.id) | |
|
337 | ftp_file = os.path.join(path,'ftp','%s.png'%name) | |
|
338 | self.saveFigure(figpath, ftp_file) | |
|
339 | ftp_filename = os.path.join(figpath,ftp_file) | |
|
340 | ||
|
341 | ||
|
342 | try: | |
|
343 | self.sendByFTP(ftp_filename, server, folder, username, password) | |
|
344 | except: | |
|
345 | self.counter_imagwr = 0 | |
|
346 | raise ValueError, 'Error FTP' | |
|
347 | ||
|
348 | self.counter_imagwr = 0 | |
|
349 | ||
|
350 | ||
|
351 | class WindProfilerPlot(Figure): | |
|
352 | ||
|
353 | __isConfig = None | |
|
354 | __nsubplots = None | |
|
355 | ||
|
356 | WIDTHPROF = None | |
|
357 | HEIGHTPROF = None | |
|
358 | PREFIX = 'wind' | |
|
359 | ||
|
360 | def __init__(self): | |
|
361 | ||
|
362 | self.timerange = 2*60*60 | |
|
363 | self.isConfig = False | |
|
364 | self.__nsubplots = 1 | |
|
365 | ||
|
366 | self.WIDTH = 800 | |
|
367 | self.HEIGHT = 150 | |
|
368 | self.WIDTHPROF = 120 | |
|
369 | self.HEIGHTPROF = 0 | |
|
370 | self.counter_imagwr = 0 | |
|
371 | ||
|
372 | self.PLOT_CODE = 0 | |
|
373 | self.FTP_WEI = None | |
|
374 | self.EXP_CODE = None | |
|
375 | self.SUB_EXP_CODE = None | |
|
376 | self.PLOT_POS = None | |
|
377 | self.tmin = None | |
|
378 | self.tmax = None | |
|
379 | ||
|
380 | self.xmin = None | |
|
381 | self.xmax = None | |
|
382 | ||
|
383 | self.figfile = None | |
|
384 | ||
|
385 | def getSubplots(self): | |
|
386 | ||
|
387 | ncol = 1 | |
|
388 | nrow = self.nplots | |
|
389 | ||
|
390 | return nrow, ncol | |
|
391 | ||
|
392 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
|
393 | ||
|
394 | self.__showprofile = showprofile | |
|
395 | self.nplots = nplots | |
|
396 | ||
|
397 | ncolspan = 1 | |
|
398 | colspan = 1 | |
|
399 | ||
|
400 | self.createFigure(id = id, | |
|
401 | wintitle = wintitle, | |
|
402 | widthplot = self.WIDTH + self.WIDTHPROF, | |
|
403 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
|
404 | show=show) | |
|
405 | ||
|
406 | nrow, ncol = self.getSubplots() | |
|
407 | ||
|
408 | counter = 0 | |
|
409 | for y in range(nrow): | |
|
410 | if counter >= self.nplots: | |
|
411 | break | |
|
412 | ||
|
413 | self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1) | |
|
414 | counter += 1 | |
|
415 | ||
|
416 | def run(self, dataOut, id, wintitle="", channelList=None, | |
|
417 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
|
418 | zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None, | |
|
419 | timerange=None, SNRthresh = None, | |
|
420 | save=False, figpath='', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, | |
|
421 | server=None, folder=None, username=None, password=None, | |
|
422 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): | |
|
423 | """ | |
|
424 | ||
|
425 | Input: | |
|
426 | dataOut : | |
|
427 | id : | |
|
428 | wintitle : | |
|
429 | channelList : | |
|
430 | showProfile : | |
|
431 | xmin : None, | |
|
432 | xmax : None, | |
|
433 | ymin : None, | |
|
434 | ymax : None, | |
|
435 | zmin : None, | |
|
436 | zmax : None | |
|
437 | """ | |
|
438 | ||
|
439 | if channelList == None: | |
|
440 | channelIndexList = dataOut.channelIndexList | |
|
441 | else: | |
|
442 | channelIndexList = [] | |
|
443 | for channel in channelList: | |
|
444 | if channel not in dataOut.channelList: | |
|
445 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
|
446 | channelIndexList.append(dataOut.channelList.index(channel)) | |
|
447 | ||
|
448 | if timerange != None: | |
|
449 | self.timerange = timerange | |
|
450 | ||
|
451 | tmin = None | |
|
452 | tmax = None | |
|
453 | ||
|
454 | x = dataOut.getTimeRange1() | |
|
455 | y = dataOut.heightRange | |
|
456 | ||
|
457 | z = dataOut.winds | |
|
458 | nplots = z.shape[0] #Number of wind dimensions estimated | |
|
459 | nplotsw = nplots | |
|
460 | ||
|
461 | #If there is a SNR function defined | |
|
462 | if dataOut.SNR != None: | |
|
463 | nplots += 1 | |
|
464 | SNR = dataOut.SNR | |
|
465 | SNRavg = numpy.average(SNR, axis=0) | |
|
466 | ||
|
467 | SNRdB = 10*numpy.log10(SNR) | |
|
468 | SNRavgdB = 10*numpy.log10(SNRavg) | |
|
469 | ||
|
470 | if SNRthresh == None: SNRthresh = -5.0 | |
|
471 | ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0] | |
|
472 | ||
|
473 | for i in range(nplotsw): | |
|
474 | z[i,ind] = numpy.nan | |
|
475 | ||
|
476 | ||
|
477 | showprofile = False | |
|
478 | # thisDatetime = dataOut.datatime | |
|
479 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
|
480 | title = wintitle + "Wind" | |
|
481 | xlabel = "" | |
|
482 | ylabel = "Range (Km)" | |
|
483 | ||
|
484 | if not self.__isConfig: | |
|
485 | ||
|
486 | ||
|
487 | ||
|
488 | self.setup(id=id, | |
|
489 | nplots=nplots, | |
|
490 | wintitle=wintitle, | |
|
491 | showprofile=showprofile, | |
|
492 | show=show) | |
|
493 | ||
|
494 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) | |
|
495 | ||
|
496 | if ymin == None: ymin = numpy.nanmin(y) | |
|
497 | if ymax == None: ymax = numpy.nanmax(y) | |
|
498 | ||
|
499 | if zmax == None: zmax = numpy.nanmax(abs(z[range(2),:])) | |
|
500 | #if numpy.isnan(zmax): zmax = 50 | |
|
501 | if zmin == None: zmin = -zmax | |
|
502 | ||
|
503 | if nplotsw == 3: | |
|
504 | if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:])) | |
|
505 | if zmin_ver == None: zmin_ver = -zmax_ver | |
|
506 | ||
|
507 | if dataOut.SNR != None: | |
|
508 | if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB) | |
|
509 | if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB) | |
|
510 | ||
|
511 | self.FTP_WEI = ftp_wei | |
|
512 | self.EXP_CODE = exp_code | |
|
513 | self.SUB_EXP_CODE = sub_exp_code | |
|
514 | self.PLOT_POS = plot_pos | |
|
515 | ||
|
516 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
|
517 | self.__isConfig = True | |
|
518 | ||
|
519 | ||
|
520 | self.setWinTitle(title) | |
|
521 | ||
|
522 | if ((self.xmax - x[1]) < (x[1]-x[0])): | |
|
523 | x[1] = self.xmax | |
|
524 | ||
|
525 | strWind = ['Zonal', 'Meridional', 'Vertical'] | |
|
526 | strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)'] | |
|
527 | zmaxVector = [zmax, zmax, zmax_ver] | |
|
528 | zminVector = [zmin, zmin, zmin_ver] | |
|
529 | windFactor = [1,1,100] | |
|
530 | ||
|
531 | for i in range(nplotsw): | |
|
532 | ||
|
533 | title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
|
534 | axes = self.axesList[i*self.__nsubplots] | |
|
535 | ||
|
536 | z1 = z[i,:].reshape((1,-1))*windFactor[i] | |
|
537 | ||
|
538 | axes.pcolorbuffer(x, y, z1, | |
|
539 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i], | |
|
540 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
|
541 | ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="RdBu_r" ) | |
|
542 | ||
|
543 | if dataOut.SNR != None: | |
|
544 | i += 1 | |
|
545 | title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
|
546 | axes = self.axesList[i*self.__nsubplots] | |
|
547 | ||
|
548 | SNRavgdB = SNRavgdB.reshape((1,-1)) | |
|
549 | ||
|
550 | axes.pcolorbuffer(x, y, SNRavgdB, | |
|
551 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax, | |
|
552 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
|
553 | ticksize=9, cblabel='', cbsize="1%", colormap="jet") | |
|
554 | ||
|
555 | self.draw() | |
|
556 | ||
|
557 | if x[1] >= self.axesList[0].xmax: | |
|
558 | self.counter_imagwr = wr_period | |
|
559 | self.__isConfig = False | |
|
560 | ||
|
561 | ||
|
562 | if self.figfile == None: | |
|
563 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
|
564 | self.figfile = self.getFilename(name = str_datetime) | |
|
565 | ||
|
566 | if figpath != '': | |
|
567 | ||
|
568 | self.counter_imagwr += 1 | |
|
569 | if (self.counter_imagwr>=wr_period): | |
|
570 | # store png plot to local folder | |
|
571 | self.saveFigure(figpath, self.figfile) | |
|
572 | # store png plot to FTP server according to RT-Web format | |
|
573 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
|
574 | ftp_filename = os.path.join(figpath, name) | |
|
575 | self.saveFigure(figpath, ftp_filename) | |
|
576 | ||
|
577 | self.counter_imagwr = 0 | |
|
578 | ||
|
579 | No newline at end of file |
@@ -0,0 +1,246 | |||
|
1 | import numpy | |
|
2 | ||
|
3 | from jroproc_base import ProcessingUnit, Operation | |
|
4 | from model.data.jrodata import Correlation | |
|
5 | ||
|
6 | class CorrelationProc(ProcessingUnit): | |
|
7 | ||
|
8 | def __init__(self): | |
|
9 | ||
|
10 | ProcessingUnit.__init__(self) | |
|
11 | ||
|
12 | self.objectDict = {} | |
|
13 | self.buffer = None | |
|
14 | self.firstdatatime = None | |
|
15 | self.profIndex = 0 | |
|
16 | self.dataOut = Correlation() | |
|
17 | ||
|
18 | def __updateObjFromInput(self): | |
|
19 | ||
|
20 | self.dataOut.timeZone = self.dataIn.timeZone | |
|
21 | self.dataOut.dstFlag = self.dataIn.dstFlag | |
|
22 | self.dataOut.errorCount = self.dataIn.errorCount | |
|
23 | self.dataOut.useLocalTime = self.dataIn.useLocalTime | |
|
24 | ||
|
25 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() | |
|
26 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() | |
|
27 | self.dataOut.channelList = self.dataIn.channelList | |
|
28 | self.dataOut.heightList = self.dataIn.heightList | |
|
29 | self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
|
30 | # self.dataOut.nHeights = self.dataIn.nHeights | |
|
31 | # self.dataOut.nChannels = self.dataIn.nChannels | |
|
32 | self.dataOut.nBaud = self.dataIn.nBaud | |
|
33 | self.dataOut.nCode = self.dataIn.nCode | |
|
34 | self.dataOut.code = self.dataIn.code | |
|
35 | # self.dataOut.nProfiles = self.dataOut.nFFTPoints | |
|
36 | self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock | |
|
37 | self.dataOut.utctime = self.firstdatatime | |
|
38 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada | |
|
39 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip | |
|
40 | # self.dataOut.nCohInt = self.dataIn.nCohInt | |
|
41 | # self.dataOut.nIncohInt = 1 | |
|
42 | self.dataOut.ippSeconds = self.dataIn.ippSeconds | |
|
43 | # self.dataOut.windowOfFilter = self.dataIn.windowOfFilter | |
|
44 | ||
|
45 | self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nPoints | |
|
46 | ||
|
47 | ||
|
48 | def removeDC(self, jspectra): | |
|
49 | ||
|
50 | nChannel = jspectra.shape[0] | |
|
51 | ||
|
52 | for i in range(nChannel): | |
|
53 | jspectra_tmp = jspectra[i,:,:] | |
|
54 | jspectra_DC = numpy.mean(jspectra_tmp,axis = 0) | |
|
55 | ||
|
56 | jspectra_tmp = jspectra_tmp - jspectra_DC | |
|
57 | jspectra[i,:,:] = jspectra_tmp | |
|
58 | ||
|
59 | return jspectra | |
|
60 | ||
|
61 | ||
|
62 | def removeNoise(self, mode = 2): | |
|
63 | indR = numpy.where(self.dataOut.lagR == 0)[0][0] | |
|
64 | indT = numpy.where(self.dataOut.lagT == 0)[0][0] | |
|
65 | ||
|
66 | jspectra = self.dataOut.data_corr[:,:,indR,:] | |
|
67 | ||
|
68 | num_chan = jspectra.shape[0] | |
|
69 | num_hei = jspectra.shape[2] | |
|
70 | ||
|
71 | freq_dc = indT | |
|
72 | ind_vel = numpy.array([-2,-1,1,2]) + freq_dc | |
|
73 | ||
|
74 | NPot = self.dataOut.getNoise(mode) | |
|
75 | jspectra[:,freq_dc,:] = jspectra[:,freq_dc,:] - NPot | |
|
76 | SPot = jspectra[:,freq_dc,:] | |
|
77 | pairsAutoCorr = self.dataOut.getPairsAutoCorr() | |
|
78 | # self.dataOut.signalPotency = SPot | |
|
79 | self.dataOut.noise = NPot | |
|
80 | self.dataOut.SNR = (SPot/NPot)[pairsAutoCorr] | |
|
81 | self.dataOut.data_corr[:,:,indR,:] = jspectra | |
|
82 | ||
|
83 | return 1 | |
|
84 | ||
|
85 | ||
|
86 | def calculateNormFactor(self): | |
|
87 | ||
|
88 | pairsList = self.dataOut.pairsList | |
|
89 | pairsAutoCorr = self.dataOut.pairsAutoCorr | |
|
90 | nHeights = self.dataOut.nHeights | |
|
91 | nPairs = len(pairsList) | |
|
92 | normFactor = numpy.zeros((nPairs,nHeights)) | |
|
93 | ||
|
94 | indR = numpy.where(self.dataOut.lagR == 0)[0][0] | |
|
95 | indT = numpy.where(self.dataOut.lagT == 0)[0][0] | |
|
96 | ||
|
97 | for l in range(len(pairsList)): | |
|
98 | firstChannel = pairsList[l][0] | |
|
99 | secondChannel = pairsList[l][1] | |
|
100 | ||
|
101 | AC1 = pairsAutoCorr[firstChannel] | |
|
102 | AC2 = pairsAutoCorr[secondChannel] | |
|
103 | ||
|
104 | if (AC1 >= 0 and AC2 >= 0): | |
|
105 | ||
|
106 | data1 = numpy.abs(self.dataOut.data_corr[AC1,:,indR,:]) | |
|
107 | data2 = numpy.abs(self.dataOut.data_corr[AC2,:,indR,:]) | |
|
108 | maxim1 = data1.max(axis = 0) | |
|
109 | maxim2 = data1.max(axis = 0) | |
|
110 | maxim = numpy.sqrt(maxim1*maxim2) | |
|
111 | else: | |
|
112 | #In case there is no autocorrelation for the pair | |
|
113 | data = numpy.abs(self.dataOut.data_corr[l,:,indR,:]) | |
|
114 | maxim = numpy.max(data, axis = 0) | |
|
115 | ||
|
116 | normFactor[l,:] = maxim | |
|
117 | ||
|
118 | self.dataOut.normFactor = normFactor | |
|
119 | ||
|
120 | return 1 | |
|
121 | ||
|
122 | def run(self, lagT=None, lagR=None, pairsList=None, | |
|
123 | nPoints=None, nAvg=None, bufferSize=None, | |
|
124 | fullT = False, fullR = False, removeDC = False): | |
|
125 | ||
|
126 | self.dataOut.flagNoData = True | |
|
127 | ||
|
128 | if self.dataIn.type == "Correlation": | |
|
129 | ||
|
130 | self.dataOut.copy(self.dataIn) | |
|
131 | ||
|
132 | return | |
|
133 | ||
|
134 | if self.dataIn.type == "Voltage": | |
|
135 | ||
|
136 | if pairsList == None: | |
|
137 | pairsList = [numpy.array([0,0])] | |
|
138 | ||
|
139 | if nPoints == None: | |
|
140 | nPoints = 128 | |
|
141 | #------------------------------------------------------------ | |
|
142 | #Condicionales para calcular Correlaciones en Tiempo y Rango | |
|
143 | if fullT: | |
|
144 | lagT = numpy.arange(nPoints*2 - 1) - nPoints + 1 | |
|
145 | elif lagT == None: | |
|
146 | lagT = numpy.array([0]) | |
|
147 | else: | |
|
148 | lagT = numpy.array(lagT) | |
|
149 | ||
|
150 | if fullR: | |
|
151 | lagR = numpy.arange(self.dataOut.nHeights) | |
|
152 | elif lagR == None: | |
|
153 | lagR = numpy.array([0]) | |
|
154 | #------------------------------------------------------------- | |
|
155 | ||
|
156 | if nAvg == None: | |
|
157 | nAvg = 1 | |
|
158 | ||
|
159 | if bufferSize == None: | |
|
160 | bufferSize = 0 | |
|
161 | ||
|
162 | deltaH = self.dataIn.heightList[1] - self.dataIn.heightList[0] | |
|
163 | self.dataOut.lagR = numpy.round(numpy.array(lagR)/deltaH) | |
|
164 | self.dataOut.pairsList = pairsList | |
|
165 | self.dataOut.nPoints = nPoints | |
|
166 | # channels = numpy.sort(list(set(list(itertools.chain.from_iterable(pairsList))))) | |
|
167 | ||
|
168 | if self.buffer == None: | |
|
169 | ||
|
170 | self.buffer = numpy.zeros((self.dataIn.nChannels,self.dataIn.nProfiles,self.dataIn.nHeights),dtype='complex') | |
|
171 | ||
|
172 | ||
|
173 | self.buffer[:,self.profIndex,:] = self.dataIn.data.copy()[:,:] | |
|
174 | ||
|
175 | self.profIndex += 1 | |
|
176 | ||
|
177 | if self.firstdatatime == None: | |
|
178 | ||
|
179 | self.firstdatatime = self.dataIn.utctime | |
|
180 | ||
|
181 | if self.profIndex == nPoints: | |
|
182 | ||
|
183 | tmp = self.buffer[:,0:nPoints,:] | |
|
184 | self.buffer = None | |
|
185 | self.buffer = tmp | |
|
186 | ||
|
187 | #--------------- Remover DC ------------ | |
|
188 | if removeDC: | |
|
189 | self.buffer = self.removeDC(self.buffer) | |
|
190 | #--------------------------------------------- | |
|
191 | self.dataOut.data_volts = self.buffer | |
|
192 | self.__updateObjFromInput() | |
|
193 | self.dataOut.data_corr = numpy.zeros((len(pairsList), | |
|
194 | len(lagT),len(lagR), | |
|
195 | self.dataIn.nHeights), | |
|
196 | dtype='complex') | |
|
197 | ||
|
198 | for l in range(len(pairsList)): | |
|
199 | ||
|
200 | firstChannel = pairsList[l][0] | |
|
201 | secondChannel = pairsList[l][1] | |
|
202 | ||
|
203 | tmp = None | |
|
204 | tmp = numpy.zeros((len(lagT),len(lagR),self.dataIn.nHeights),dtype='complex') | |
|
205 | ||
|
206 | for t in range(len(lagT)): | |
|
207 | ||
|
208 | for r in range(len(lagR)): | |
|
209 | ||
|
210 | idxT = lagT[t] | |
|
211 | idxR = lagR[r] | |
|
212 | ||
|
213 | if idxT >= 0: | |
|
214 | vStacked = numpy.vstack((self.buffer[secondChannel,idxT:,:], | |
|
215 | numpy.zeros((idxT,self.dataIn.nHeights),dtype='complex'))) | |
|
216 | else: | |
|
217 | vStacked = numpy.vstack((numpy.zeros((-idxT,self.dataIn.nHeights),dtype='complex'), | |
|
218 | self.buffer[secondChannel,:(nPoints + idxT),:])) | |
|
219 | ||
|
220 | if idxR >= 0: | |
|
221 | hStacked = numpy.hstack((vStacked[:,idxR:],numpy.zeros((nPoints,idxR),dtype='complex'))) | |
|
222 | else: | |
|
223 | hStacked = numpy.hstack((numpy.zeros((nPoints,-idxR),dtype='complex'),vStacked[:,(self.dataOut.nHeights + idxR)])) | |
|
224 | ||
|
225 | ||
|
226 | tmp[t,r,:] = numpy.sum((numpy.conjugate(self.buffer[firstChannel,:,:])*hStacked),axis=0) | |
|
227 | ||
|
228 | ||
|
229 | hStacked = None | |
|
230 | vStacked = None | |
|
231 | ||
|
232 | self.dataOut.data_corr[l,:,:,:] = tmp[:,:,:] | |
|
233 | ||
|
234 | #Se Calcula los factores de Normalizacion | |
|
235 | self.dataOut.pairsAutoCorr = self.dataOut.getPairsAutoCorr() | |
|
236 | self.dataOut.lagT = lagT*self.dataIn.ippSeconds*self.dataIn.nCohInt | |
|
237 | self.dataOut.lagR = lagR | |
|
238 | ||
|
239 | self.calculateNormFactor() | |
|
240 | ||
|
241 | self.dataOut.flagNoData = False | |
|
242 | self.buffer = None | |
|
243 | self.firstdatatime = None | |
|
244 | self.profIndex = 0 | |
|
245 | ||
|
246 | return No newline at end of file |
This diff has been collapsed as it changes many lines, (1521 lines changed) Show them Hide them | |||
@@ -0,0 +1,1521 | |||
|
1 | import numpy | |
|
2 | import math | |
|
3 | from scipy import optimize | |
|
4 | from scipy import interpolate | |
|
5 | from scipy import signal | |
|
6 | from scipy import stats | |
|
7 | import re | |
|
8 | import datetime | |
|
9 | import copy | |
|
10 | ||
|
11 | ||
|
12 | from jroproc_base import ProcessingUnit, Operation | |
|
13 | from model.data.jrodata import Parameters | |
|
14 | ||
|
15 | ||
|
16 | class ParametersProc(ProcessingUnit): | |
|
17 | ||
|
18 | nSeconds = None | |
|
19 | ||
|
20 | def __init__(self): | |
|
21 | ProcessingUnit.__init__(self) | |
|
22 | ||
|
23 | self.objectDict = {} | |
|
24 | self.buffer = None | |
|
25 | self.firstdatatime = None | |
|
26 | self.profIndex = 0 | |
|
27 | self.dataOut = Parameters() | |
|
28 | ||
|
29 | def __updateObjFromInput(self): | |
|
30 | ||
|
31 | self.dataOut.inputUnit = self.dataIn.type | |
|
32 | ||
|
33 | self.dataOut.timeZone = self.dataIn.timeZone | |
|
34 | self.dataOut.dstFlag = self.dataIn.dstFlag | |
|
35 | self.dataOut.errorCount = self.dataIn.errorCount | |
|
36 | self.dataOut.useLocalTime = self.dataIn.useLocalTime | |
|
37 | ||
|
38 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() | |
|
39 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() | |
|
40 | self.dataOut.channelList = self.dataIn.channelList | |
|
41 | self.dataOut.heightList = self.dataIn.heightList | |
|
42 | self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
|
43 | # self.dataOut.nHeights = self.dataIn.nHeights | |
|
44 | # self.dataOut.nChannels = self.dataIn.nChannels | |
|
45 | self.dataOut.nBaud = self.dataIn.nBaud | |
|
46 | self.dataOut.nCode = self.dataIn.nCode | |
|
47 | self.dataOut.code = self.dataIn.code | |
|
48 | # self.dataOut.nProfiles = self.dataOut.nFFTPoints | |
|
49 | self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock | |
|
50 | self.dataOut.utctime = self.firstdatatime | |
|
51 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada | |
|
52 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip | |
|
53 | # self.dataOut.nCohInt = self.dataIn.nCohInt | |
|
54 | # self.dataOut.nIncohInt = 1 | |
|
55 | self.dataOut.ippSeconds = self.dataIn.ippSeconds | |
|
56 | # self.dataOut.windowOfFilter = self.dataIn.windowOfFilter | |
|
57 | self.dataOut.timeInterval = self.dataIn.timeInterval | |
|
58 | self.dataOut.heightRange = self.dataIn.getHeiRange() | |
|
59 | self.dataOut.frequency = self.dataIn.frequency | |
|
60 | ||
|
61 | def run(self, nSeconds = None, nProfiles = None): | |
|
62 | ||
|
63 | self.dataOut.flagNoData = True | |
|
64 | ||
|
65 | if self.firstdatatime == None: | |
|
66 | self.firstdatatime = self.dataIn.utctime | |
|
67 | ||
|
68 | #---------------------- Voltage Data --------------------------- | |
|
69 | ||
|
70 | if self.dataIn.type == "Voltage": | |
|
71 | if nSeconds != None: | |
|
72 | self.nSeconds = nSeconds | |
|
73 | self.nProfiles= int(numpy.floor(nSeconds/(self.dataIn.ippSeconds*self.dataIn.nCohInt))) | |
|
74 | ||
|
75 | if self.buffer == None: | |
|
76 | self.buffer = numpy.zeros((self.dataIn.nChannels, | |
|
77 | self.nProfiles, | |
|
78 | self.dataIn.nHeights), | |
|
79 | dtype='complex') | |
|
80 | ||
|
81 | self.buffer[:,self.profIndex,:] = self.dataIn.data.copy() | |
|
82 | self.profIndex += 1 | |
|
83 | ||
|
84 | if self.profIndex == self.nProfiles: | |
|
85 | ||
|
86 | self.__updateObjFromInput() | |
|
87 | self.dataOut.data_pre = self.buffer.copy() | |
|
88 | self.dataOut.paramInterval = nSeconds | |
|
89 | self.dataOut.flagNoData = False | |
|
90 | ||
|
91 | self.buffer = None | |
|
92 | self.firstdatatime = None | |
|
93 | self.profIndex = 0 | |
|
94 | ||
|
95 | #---------------------- Spectra Data --------------------------- | |
|
96 | ||
|
97 | if self.dataIn.type == "Spectra": | |
|
98 | self.dataOut.data_pre = self.dataIn.data_spc.copy() | |
|
99 | self.dataOut.abscissaRange = self.dataIn.getVelRange(1) | |
|
100 | self.dataOut.noise = self.dataIn.getNoise() | |
|
101 | self.dataOut.normFactor = self.dataIn.normFactor | |
|
102 | ||
|
103 | self.__updateObjFromInput() | |
|
104 | self.dataOut.flagNoData = False | |
|
105 | self.firstdatatime = None | |
|
106 | ||
|
107 | #---------------------- Correlation Data --------------------------- | |
|
108 | ||
|
109 | if self.dataIn.type == "Correlation": | |
|
110 | lagRRange = self.dataIn.lagR | |
|
111 | indR = numpy.where(lagRRange == 0)[0][0] | |
|
112 | ||
|
113 | self.dataOut.data_pre = self.dataIn.data_corr.copy()[:,:,indR,:] | |
|
114 | self.dataOut.abscissaRange = self.dataIn.getLagTRange(1) | |
|
115 | self.dataOut.noise = self.dataIn.noise | |
|
116 | self.dataOut.normFactor = self.dataIn.normFactor | |
|
117 | self.dataOut.SNR = self.dataIn.SNR | |
|
118 | self.dataOut.pairsList = self.dataIn.pairsList | |
|
119 | ||
|
120 | self.__updateObjFromInput() | |
|
121 | self.dataOut.flagNoData = False | |
|
122 | self.firstdatatime = None | |
|
123 | ||
|
124 | #------------------- Get Moments ---------------------------------- | |
|
125 | def GetMoments(self, channelList = None): | |
|
126 | ''' | |
|
127 | Function GetMoments() | |
|
128 | ||
|
129 | Input: | |
|
130 | channelList : simple channel list to select e.g. [2,3,7] | |
|
131 | self.dataOut.data_pre | |
|
132 | self.dataOut.abscissaRange | |
|
133 | self.dataOut.noise | |
|
134 | ||
|
135 | Affected: | |
|
136 | self.dataOut.data_param | |
|
137 | self.dataOut.SNR | |
|
138 | ||
|
139 | ''' | |
|
140 | data = self.dataOut.data_pre | |
|
141 | absc = self.dataOut.abscissaRange[:-1] | |
|
142 | noise = self.dataOut.noise | |
|
143 | ||
|
144 | data_param = numpy.zeros((data.shape[0], 4, data.shape[2])) | |
|
145 | ||
|
146 | if channelList== None: channelList = self.dataOut.channelList | |
|
147 | ||
|
148 | for ind in channelList: | |
|
149 | data_param[ind,:,:] = self.__calculateMoments(data[ind,:,:], absc, noise[ind]) | |
|
150 | ||
|
151 | self.dataOut.data_param = data_param[:,1:] | |
|
152 | self.dataOut.SNR = data_param[:,0] | |
|
153 | return | |
|
154 | ||
|
155 | def __calculateMoments(self, oldspec, oldfreq, n0, nicoh = None, graph = None, smooth = None, type1 = None, fwindow = None, snrth = None, dc = None, aliasing = None, oldfd = None, wwauto = None): | |
|
156 | ||
|
157 | if (nicoh == None): nicoh = 1 | |
|
158 | if (graph == None): graph = 0 | |
|
159 | if (smooth == None): smooth = 0 | |
|
160 | elif (self.smooth < 3): smooth = 0 | |
|
161 | ||
|
162 | if (type1 == None): type1 = 0 | |
|
163 | if (fwindow == None): fwindow = numpy.zeros(oldfreq.size) + 1 | |
|
164 | if (snrth == None): snrth = -3 | |
|
165 | if (dc == None): dc = 0 | |
|
166 | if (aliasing == None): aliasing = 0 | |
|
167 | if (oldfd == None): oldfd = 0 | |
|
168 | if (wwauto == None): wwauto = 0 | |
|
169 | ||
|
170 | if (n0 < 1.e-20): n0 = 1.e-20 | |
|
171 | ||
|
172 | freq = oldfreq | |
|
173 | vec_power = numpy.zeros(oldspec.shape[1]) | |
|
174 | vec_fd = numpy.zeros(oldspec.shape[1]) | |
|
175 | vec_w = numpy.zeros(oldspec.shape[1]) | |
|
176 | vec_snr = numpy.zeros(oldspec.shape[1]) | |
|
177 | ||
|
178 | for ind in range(oldspec.shape[1]): | |
|
179 | ||
|
180 | spec = oldspec[:,ind] | |
|
181 | aux = spec*fwindow | |
|
182 | max_spec = aux.max() | |
|
183 | m = list(aux).index(max_spec) | |
|
184 | ||
|
185 | #Smooth | |
|
186 | if (smooth == 0): spec2 = spec | |
|
187 | else: spec2 = scipy.ndimage.filters.uniform_filter1d(spec,size=smooth) | |
|
188 | ||
|
189 | # Calculo de Momentos | |
|
190 | bb = spec2[range(m,spec2.size)] | |
|
191 | bb = (bb<n0).nonzero() | |
|
192 | bb = bb[0] | |
|
193 | ||
|
194 | ss = spec2[range(0,m + 1)] | |
|
195 | ss = (ss<n0).nonzero() | |
|
196 | ss = ss[0] | |
|
197 | ||
|
198 | if (bb.size == 0): | |
|
199 | bb0 = spec.size - 1 - m | |
|
200 | else: | |
|
201 | bb0 = bb[0] - 1 | |
|
202 | if (bb0 < 0): | |
|
203 | bb0 = 0 | |
|
204 | ||
|
205 | if (ss.size == 0): ss1 = 1 | |
|
206 | else: ss1 = max(ss) + 1 | |
|
207 | ||
|
208 | if (ss1 > m): ss1 = m | |
|
209 | ||
|
210 | valid = numpy.asarray(range(int(m + bb0 - ss1 + 1))) + ss1 | |
|
211 | power = ((spec2[valid] - n0)*fwindow[valid]).sum() | |
|
212 | fd = ((spec2[valid]- n0)*freq[valid]*fwindow[valid]).sum()/power | |
|
213 | w = math.sqrt(((spec2[valid] - n0)*fwindow[valid]*(freq[valid]- fd)**2).sum()/power) | |
|
214 | snr = (spec2.mean()-n0)/n0 | |
|
215 | ||
|
216 | if (snr < 1.e-20) : | |
|
217 | snr = 1.e-20 | |
|
218 | ||
|
219 | vec_power[ind] = power | |
|
220 | vec_fd[ind] = fd | |
|
221 | vec_w[ind] = w | |
|
222 | vec_snr[ind] = snr | |
|
223 | ||
|
224 | moments = numpy.vstack((vec_snr, vec_power, vec_fd, vec_w)) | |
|
225 | return moments | |
|
226 | ||
|
227 | #------------------- Get Lags ---------------------------------- | |
|
228 | ||
|
229 | def GetLags(self): | |
|
230 | ''' | |
|
231 | Function GetMoments() | |
|
232 | ||
|
233 | Input: | |
|
234 | self.dataOut.data_pre | |
|
235 | self.dataOut.abscissaRange | |
|
236 | self.dataOut.noise | |
|
237 | self.dataOut.normFactor | |
|
238 | self.dataOut.SNR | |
|
239 | self.dataOut.pairsList | |
|
240 | self.dataOut.nChannels | |
|
241 | ||
|
242 | Affected: | |
|
243 | self.dataOut.data_param | |
|
244 | ||
|
245 | ''' | |
|
246 | data = self.dataOut.data_pre | |
|
247 | normFactor = self.dataOut.normFactor | |
|
248 | nHeights = self.dataOut.nHeights | |
|
249 | absc = self.dataOut.abscissaRange[:-1] | |
|
250 | noise = self.dataOut.noise | |
|
251 | SNR = self.dataOut.SNR | |
|
252 | pairsList = self.dataOut.pairsList | |
|
253 | nChannels = self.dataOut.nChannels | |
|
254 | pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairsList, nChannels) | |
|
255 | self.dataOut.data_param = numpy.zeros((len(pairsCrossCorr)*2 + 1, nHeights)) | |
|
256 | ||
|
257 | dataNorm = numpy.abs(data) | |
|
258 | for l in range(len(pairsList)): | |
|
259 | dataNorm[l,:,:] = dataNorm[l,:,:]/normFactor[l,:] | |
|
260 | ||
|
261 | self.dataOut.data_param[:-1,:] = self.__calculateTaus(dataNorm, pairsCrossCorr, pairsAutoCorr, absc) | |
|
262 | self.dataOut.data_param[-1,:] = self.__calculateLag1Phase(data, pairsAutoCorr, absc) | |
|
263 | return | |
|
264 | ||
|
265 | def __getPairsAutoCorr(self, pairsList, nChannels): | |
|
266 | ||
|
267 | pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan | |
|
268 | ||
|
269 | for l in range(len(pairsList)): | |
|
270 | firstChannel = pairsList[l][0] | |
|
271 | secondChannel = pairsList[l][1] | |
|
272 | ||
|
273 | #Obteniendo pares de Autocorrelacion | |
|
274 | if firstChannel == secondChannel: | |
|
275 | pairsAutoCorr[firstChannel] = int(l) | |
|
276 | ||
|
277 | pairsAutoCorr = pairsAutoCorr.astype(int) | |
|
278 | ||
|
279 | pairsCrossCorr = range(len(pairsList)) | |
|
280 | pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr) | |
|
281 | ||
|
282 | return pairsAutoCorr, pairsCrossCorr | |
|
283 | ||
|
284 | def __calculateTaus(self, data, pairsCrossCorr, pairsAutoCorr, lagTRange): | |
|
285 | ||
|
286 | Pt0 = data.shape[1]/2 | |
|
287 | #Funcion de Autocorrelacion | |
|
288 | dataAutoCorr = stats.nanmean(data[pairsAutoCorr,:,:], axis = 0) | |
|
289 | ||
|
290 | #Obtencion Indice de TauCross | |
|
291 | indCross = data[pairsCrossCorr,:,:].argmax(axis = 1) | |
|
292 | #Obtencion Indice de TauAuto | |
|
293 | indAuto = numpy.zeros(indCross.shape,dtype = 'int') | |
|
294 | CCValue = data[pairsCrossCorr,Pt0,:] | |
|
295 | for i in range(pairsCrossCorr.size): | |
|
296 | indAuto[i,:] = numpy.abs(dataAutoCorr - CCValue[i,:]).argmin(axis = 0) | |
|
297 | ||
|
298 | #Obtencion de TauCross y TauAuto | |
|
299 | tauCross = lagTRange[indCross] | |
|
300 | tauAuto = lagTRange[indAuto] | |
|
301 | ||
|
302 | Nan1, Nan2 = numpy.where(tauCross == lagTRange[0]) | |
|
303 | ||
|
304 | tauCross[Nan1,Nan2] = numpy.nan | |
|
305 | tauAuto[Nan1,Nan2] = numpy.nan | |
|
306 | tau = numpy.vstack((tauCross,tauAuto)) | |
|
307 | ||
|
308 | return tau | |
|
309 | ||
|
310 | def __calculateLag1Phase(self, data, pairs, lagTRange): | |
|
311 | data1 = stats.nanmean(data[pairs,:,:], axis = 0) | |
|
312 | lag1 = numpy.where(lagTRange == 0)[0][0] + 1 | |
|
313 | ||
|
314 | phase = numpy.angle(data1[lag1,:]) | |
|
315 | ||
|
316 | return phase | |
|
317 | #------------------- Detect Meteors ------------------------------ | |
|
318 | ||
|
319 | def DetectMeteors(self, hei_ref = None, tauindex = 0, | |
|
320 | predefinedPhaseShifts = None, centerReceiverIndex = 2, | |
|
321 | cohDetection = False, cohDet_timeStep = 1, cohDet_thresh = 25, | |
|
322 | noise_timeStep = 4, noise_multiple = 4, | |
|
323 | multDet_timeLimit = 1, multDet_rangeLimit = 3, | |
|
324 | phaseThresh = 20, SNRThresh = 8, | |
|
325 | hmin = 70, hmax=110, azimuth = 0) : | |
|
326 | ||
|
327 | ''' | |
|
328 | Function DetectMeteors() | |
|
329 | Project developed with paper: | |
|
330 | HOLDSWORTH ET AL. 2004 | |
|
331 | ||
|
332 | Input: | |
|
333 | self.dataOut.data_pre | |
|
334 | ||
|
335 | centerReceiverIndex: From the channels, which is the center receiver | |
|
336 | ||
|
337 | hei_ref: Height reference for the Beacon signal extraction | |
|
338 | tauindex: | |
|
339 | predefinedPhaseShifts: Predefined phase offset for the voltge signals | |
|
340 | ||
|
341 | cohDetection: Whether to user Coherent detection or not | |
|
342 | cohDet_timeStep: Coherent Detection calculation time step | |
|
343 | cohDet_thresh: Coherent Detection phase threshold to correct phases | |
|
344 | ||
|
345 | noise_timeStep: Noise calculation time step | |
|
346 | noise_multiple: Noise multiple to define signal threshold | |
|
347 | ||
|
348 | multDet_timeLimit: Multiple Detection Removal time limit in seconds | |
|
349 | multDet_rangeLimit: Multiple Detection Removal range limit in km | |
|
350 | ||
|
351 | phaseThresh: Maximum phase difference between receiver to be consider a meteor | |
|
352 | SNRThresh: Minimum SNR threshold of the meteor signal to be consider a meteor | |
|
353 | ||
|
354 | hmin: Minimum Height of the meteor to use it in the further wind estimations | |
|
355 | hmax: Maximum Height of the meteor to use it in the further wind estimations | |
|
356 | azimuth: Azimuth angle correction | |
|
357 | ||
|
358 | Affected: | |
|
359 | self.dataOut.data_param | |
|
360 | ||
|
361 | Rejection Criteria (Errors): | |
|
362 | 0: No error; analysis OK | |
|
363 | 1: SNR < SNR threshold | |
|
364 | 2: angle of arrival (AOA) ambiguously determined | |
|
365 | 3: AOA estimate not feasible | |
|
366 | 4: Large difference in AOAs obtained from different antenna baselines | |
|
367 | 5: echo at start or end of time series | |
|
368 | 6: echo less than 5 examples long; too short for analysis | |
|
369 | 7: echo rise exceeds 0.3s | |
|
370 | 8: echo decay time less than twice rise time | |
|
371 | 9: large power level before echo | |
|
372 | 10: large power level after echo | |
|
373 | 11: poor fit to amplitude for estimation of decay time | |
|
374 | 12: poor fit to CCF phase variation for estimation of radial drift velocity | |
|
375 | 13: height unresolvable echo: not valid height within 70 to 110 km | |
|
376 | 14: height ambiguous echo: more then one possible height within 70 to 110 km | |
|
377 | 15: radial drift velocity or projected horizontal velocity exceeds 200 m/s | |
|
378 | 16: oscilatory echo, indicating event most likely not an underdense echo | |
|
379 | ||
|
380 | 17: phase difference in meteor Reestimation | |
|
381 | ||
|
382 | Data Storage: | |
|
383 | Meteors for Wind Estimation (8): | |
|
384 | Day Hour | Range Height | |
|
385 | Azimuth Zenith errorCosDir | |
|
386 | VelRad errorVelRad | |
|
387 | TypeError | |
|
388 | ||
|
389 | ''' | |
|
390 | #Get Beacon signal | |
|
391 | newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex]) | |
|
392 | ||
|
393 | if hei_ref != None: | |
|
394 | newheis = numpy.where(self.dataOut.heightList>hei_ref) | |
|
395 | ||
|
396 | heiRang = self.dataOut.getHeiRange() | |
|
397 | #Pairs List | |
|
398 | pairslist = [] | |
|
399 | nChannel = self.dataOut.nChannels | |
|
400 | for i in range(nChannel): | |
|
401 | if i != centerReceiverIndex: | |
|
402 | pairslist.append((centerReceiverIndex,i)) | |
|
403 | ||
|
404 | #****************REMOVING HARDWARE PHASE DIFFERENCES*************** | |
|
405 | # see if the user put in pre defined phase shifts | |
|
406 | voltsPShift = self.dataOut.data_pre.copy() | |
|
407 | ||
|
408 | if predefinedPhaseShifts != None: | |
|
409 | hardwarePhaseShifts = numpy.array(predefinedPhaseShifts)*numpy.pi/180 | |
|
410 | else: | |
|
411 | #get hardware phase shifts using beacon signal | |
|
412 | hardwarePhaseShifts = self.__getHardwarePhaseDiff(self.dataOut.data_pre, pairslist, newheis, 10) | |
|
413 | hardwarePhaseShifts = numpy.insert(hardwarePhaseShifts,centerReceiverIndex,0) | |
|
414 | ||
|
415 | voltsPShift = numpy.zeros((self.dataOut.data_pre.shape[0],self.dataOut.data_pre.shape[1],self.dataOut.data_pre.shape[2]), dtype = 'complex') | |
|
416 | for i in range(self.dataOut.data_pre.shape[0]): | |
|
417 | voltsPShift[i,:,:] = self.__shiftPhase(self.dataOut.data_pre[i,:,:], hardwarePhaseShifts[i]) | |
|
418 | #******************END OF REMOVING HARDWARE PHASE DIFFERENCES********* | |
|
419 | ||
|
420 | #Remove DC | |
|
421 | voltsDC = numpy.mean(voltsPShift,1) | |
|
422 | voltsDC = numpy.mean(voltsDC,1) | |
|
423 | for i in range(voltsDC.shape[0]): | |
|
424 | voltsPShift[i] = voltsPShift[i] - voltsDC[i] | |
|
425 | ||
|
426 | #Don't considerate last heights, theyre used to calculate Hardware Phase Shift | |
|
427 | voltsPShift = voltsPShift[:,:,:newheis[0][0]] | |
|
428 | ||
|
429 | #************ FIND POWER OF DATA W/COH OR NON COH DETECTION (3.4) ********** | |
|
430 | #Coherent Detection | |
|
431 | if cohDetection: | |
|
432 | #use coherent detection to get the net power | |
|
433 | cohDet_thresh = cohDet_thresh*numpy.pi/180 | |
|
434 | voltsPShift = self.__coherentDetection(voltsPShift, cohDet_timeStep, self.dataOut.timeInterval, pairslist, cohDet_thresh) | |
|
435 | ||
|
436 | #Non-coherent detection! | |
|
437 | powerNet = numpy.nansum(numpy.abs(voltsPShift[:,:,:])**2,0) | |
|
438 | #********** END OF COH/NON-COH POWER CALCULATION********************** | |
|
439 | ||
|
440 | #********** FIND THE NOISE LEVEL AND POSSIBLE METEORS **************** | |
|
441 | #Get noise | |
|
442 | noise, noise1 = self.__getNoise(powerNet, noise_timeStep, self.dataOut.timeInterval) | |
|
443 | # noise = self.getNoise1(powerNet, noise_timeStep, self.dataOut.timeInterval) | |
|
444 | #Get signal threshold | |
|
445 | signalThresh = noise_multiple*noise | |
|
446 | #Meteor echoes detection | |
|
447 | listMeteors = self.__findMeteors(powerNet, signalThresh) | |
|
448 | #******* END OF NOISE LEVEL AND POSSIBLE METEORS CACULATION ********** | |
|
449 | ||
|
450 | #************** REMOVE MULTIPLE DETECTIONS (3.5) *************************** | |
|
451 | #Parameters | |
|
452 | heiRange = self.dataOut.getHeiRange() | |
|
453 | rangeInterval = heiRange[1] - heiRange[0] | |
|
454 | rangeLimit = multDet_rangeLimit/rangeInterval | |
|
455 | timeLimit = multDet_timeLimit/self.dataOut.timeInterval | |
|
456 | #Multiple detection removals | |
|
457 | listMeteors1 = self.__removeMultipleDetections(listMeteors, rangeLimit, timeLimit) | |
|
458 | #************ END OF REMOVE MULTIPLE DETECTIONS ********************** | |
|
459 | ||
|
460 | #********************* METEOR REESTIMATION (3.7, 3.8, 3.9, 3.10) ******************** | |
|
461 | #Parameters | |
|
462 | phaseThresh = phaseThresh*numpy.pi/180 | |
|
463 | thresh = [phaseThresh, noise_multiple, SNRThresh] | |
|
464 | #Meteor reestimation (Errors N 1, 6, 12, 17) | |
|
465 | listMeteors2, listMeteorsPower, listMeteorsVolts = self.__meteorReestimation(listMeteors1, voltsPShift, pairslist, thresh, noise, self.dataOut.timeInterval, self.dataOut.frequency) | |
|
466 | # listMeteors2, listMeteorsPower, listMeteorsVolts = self.meteorReestimation3(listMeteors2, listMeteorsPower, listMeteorsVolts, voltsPShift, pairslist, thresh, noise) | |
|
467 | #Estimation of decay times (Errors N 7, 8, 11) | |
|
468 | listMeteors3 = self.__estimateDecayTime(listMeteors2, listMeteorsPower, self.dataOut.timeInterval, self.dataOut.frequency) | |
|
469 | #******************* END OF METEOR REESTIMATION ******************* | |
|
470 | ||
|
471 | #********************* METEOR PARAMETERS CALCULATION (3.11, 3.12, 3.13) ************************** | |
|
472 | #Calculating Radial Velocity (Error N 15) | |
|
473 | radialStdThresh = 10 | |
|
474 | listMeteors4 = self.__getRadialVelocity(listMeteors3, listMeteorsVolts, radialStdThresh, pairslist, self.dataOut.timeInterval) | |
|
475 | ||
|
476 | if len(listMeteors4) > 0: | |
|
477 | #Setting New Array | |
|
478 | date = repr(self.dataOut.datatime) | |
|
479 | arrayMeteors4, arrayParameters = self.__setNewArrays(listMeteors4, date, heiRang) | |
|
480 | ||
|
481 | #Calculate AOA (Error N 3, 4) | |
|
482 | #JONES ET AL. 1998 | |
|
483 | AOAthresh = numpy.pi/8 | |
|
484 | error = arrayParameters[:,-1] | |
|
485 | phases = -arrayMeteors4[:,9:13] | |
|
486 | pairsList = [] | |
|
487 | pairsList.append((0,3)) | |
|
488 | pairsList.append((1,2)) | |
|
489 | arrayParameters[:,4:7], arrayParameters[:,-1] = self.__getAOA(phases, pairsList, error, AOAthresh, azimuth) | |
|
490 | ||
|
491 | #Calculate Heights (Error N 13 and 14) | |
|
492 | error = arrayParameters[:,-1] | |
|
493 | Ranges = arrayParameters[:,2] | |
|
494 | zenith = arrayParameters[:,5] | |
|
495 | arrayParameters[:,3], arrayParameters[:,-1] = self.__getHeights(Ranges, zenith, error, hmin, hmax) | |
|
496 | #********************* END OF PARAMETERS CALCULATION ************************** | |
|
497 | ||
|
498 | #***************************+ SAVE DATA IN HDF5 FORMAT ********************** | |
|
499 | self.dataOut.data_param = arrayParameters | |
|
500 | ||
|
501 | return | |
|
502 | ||
|
503 | def __getHardwarePhaseDiff(self, voltage0, pairslist, newheis, n): | |
|
504 | ||
|
505 | minIndex = min(newheis[0]) | |
|
506 | maxIndex = max(newheis[0]) | |
|
507 | ||
|
508 | voltage = voltage0[:,:,minIndex:maxIndex+1] | |
|
509 | nLength = voltage.shape[1]/n | |
|
510 | nMin = 0 | |
|
511 | nMax = 0 | |
|
512 | phaseOffset = numpy.zeros((len(pairslist),n)) | |
|
513 | ||
|
514 | for i in range(n): | |
|
515 | nMax += nLength | |
|
516 | phaseCCF = -numpy.angle(self.__calculateCCF(voltage[:,nMin:nMax,:], pairslist, [0])) | |
|
517 | phaseCCF = numpy.mean(phaseCCF, axis = 2) | |
|
518 | phaseOffset[:,i] = phaseCCF.transpose() | |
|
519 | nMin = nMax | |
|
520 | # phaseDiff, phaseArrival = self.estimatePhaseDifference(voltage, pairslist) | |
|
521 | ||
|
522 | #Remove Outliers | |
|
523 | factor = 2 | |
|
524 | wt = phaseOffset - signal.medfilt(phaseOffset,(1,5)) | |
|
525 | dw = numpy.std(wt,axis = 1) | |
|
526 | dw = dw.reshape((dw.size,1)) | |
|
527 | ind = numpy.where(numpy.logical_or(wt>dw*factor,wt<-dw*factor)) | |
|
528 | phaseOffset[ind] = numpy.nan | |
|
529 | phaseOffset = stats.nanmean(phaseOffset, axis=1) | |
|
530 | ||
|
531 | return phaseOffset | |
|
532 | ||
|
533 | def __shiftPhase(self, data, phaseShift): | |
|
534 | #this will shift the phase of a complex number | |
|
535 | dataShifted = numpy.abs(data) * numpy.exp((numpy.angle(data)+phaseShift)*1j) | |
|
536 | return dataShifted | |
|
537 | ||
|
538 | def __estimatePhaseDifference(self, array, pairslist): | |
|
539 | nChannel = array.shape[0] | |
|
540 | nHeights = array.shape[2] | |
|
541 | numPairs = len(pairslist) | |
|
542 | # phaseCCF = numpy.zeros((nChannel, 5, nHeights)) | |
|
543 | phaseCCF = numpy.angle(self.__calculateCCF(array, pairslist, [-2,-1,0,1,2])) | |
|
544 | ||
|
545 | #Correct phases | |
|
546 | derPhaseCCF = phaseCCF[:,1:,:] - phaseCCF[:,0:-1,:] | |
|
547 | indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi) | |
|
548 | ||
|
549 | if indDer[0].shape[0] > 0: | |
|
550 | for i in range(indDer[0].shape[0]): | |
|
551 | signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i],indDer[2][i]]) | |
|
552 | phaseCCF[indDer[0][i],indDer[1][i]+1:,:] += signo*2*numpy.pi | |
|
553 | ||
|
554 | # for j in range(numSides): | |
|
555 | # phaseCCFAux = self.calculateCCF(arrayCenter, arraySides[j,:,:], [-2,1,0,1,2]) | |
|
556 | # phaseCCF[j,:,:] = numpy.angle(phaseCCFAux) | |
|
557 | # | |
|
558 | #Linear | |
|
559 | phaseInt = numpy.zeros((numPairs,1)) | |
|
560 | angAllCCF = phaseCCF[:,[0,1,3,4],0] | |
|
561 | for j in range(numPairs): | |
|
562 | fit = stats.linregress([-2,-1,1,2],angAllCCF[j,:]) | |
|
563 | phaseInt[j] = fit[1] | |
|
564 | #Phase Differences | |
|
565 | phaseDiff = phaseInt - phaseCCF[:,2,:] | |
|
566 | phaseArrival = phaseInt.reshape(phaseInt.size) | |
|
567 | ||
|
568 | #Dealias | |
|
569 | indAlias = numpy.where(phaseArrival > numpy.pi) | |
|
570 | phaseArrival[indAlias] -= 2*numpy.pi | |
|
571 | indAlias = numpy.where(phaseArrival < -numpy.pi) | |
|
572 | phaseArrival[indAlias] += 2*numpy.pi | |
|
573 | ||
|
574 | return phaseDiff, phaseArrival | |
|
575 | ||
|
576 | def __coherentDetection(self, volts, timeSegment, timeInterval, pairslist, thresh): | |
|
577 | #this function will run the coherent detection used in Holdworth et al. 2004 and return the net power | |
|
578 | #find the phase shifts of each channel over 1 second intervals | |
|
579 | #only look at ranges below the beacon signal | |
|
580 | numProfPerBlock = numpy.ceil(timeSegment/timeInterval) | |
|
581 | numBlocks = int(volts.shape[1]/numProfPerBlock) | |
|
582 | numHeights = volts.shape[2] | |
|
583 | nChannel = volts.shape[0] | |
|
584 | voltsCohDet = volts.copy() | |
|
585 | ||
|
586 | pairsarray = numpy.array(pairslist) | |
|
587 | indSides = pairsarray[:,1] | |
|
588 | # indSides = numpy.array(range(nChannel)) | |
|
589 | # indSides = numpy.delete(indSides, indCenter) | |
|
590 | # | |
|
591 | # listCenter = numpy.array_split(volts[indCenter,:,:], numBlocks, 0) | |
|
592 | listBlocks = numpy.array_split(volts, numBlocks, 1) | |
|
593 | ||
|
594 | startInd = 0 | |
|
595 | endInd = 0 | |
|
596 | ||
|
597 | for i in range(numBlocks): | |
|
598 | startInd = endInd | |
|
599 | endInd = endInd + listBlocks[i].shape[1] | |
|
600 | ||
|
601 | arrayBlock = listBlocks[i] | |
|
602 | # arrayBlockCenter = listCenter[i] | |
|
603 | ||
|
604 | #Estimate the Phase Difference | |
|
605 | phaseDiff, aux = self.__estimatePhaseDifference(arrayBlock, pairslist) | |
|
606 | #Phase Difference RMS | |
|
607 | arrayPhaseRMS = numpy.abs(phaseDiff) | |
|
608 | phaseRMSaux = numpy.sum(arrayPhaseRMS < thresh,0) | |
|
609 | indPhase = numpy.where(phaseRMSaux==4) | |
|
610 | #Shifting | |
|
611 | if indPhase[0].shape[0] > 0: | |
|
612 | for j in range(indSides.size): | |
|
613 | arrayBlock[indSides[j],:,indPhase] = self.__shiftPhase(arrayBlock[indSides[j],:,indPhase], phaseDiff[j,indPhase].transpose()) | |
|
614 | voltsCohDet[:,startInd:endInd,:] = arrayBlock | |
|
615 | ||
|
616 | return voltsCohDet | |
|
617 | ||
|
618 | def __calculateCCF(self, volts, pairslist ,laglist): | |
|
619 | ||
|
620 | nHeights = volts.shape[2] | |
|
621 | nPoints = volts.shape[1] | |
|
622 | voltsCCF = numpy.zeros((len(pairslist), len(laglist), nHeights),dtype = 'complex') | |
|
623 | ||
|
624 | for i in range(len(pairslist)): | |
|
625 | volts1 = volts[pairslist[i][0]] | |
|
626 | volts2 = volts[pairslist[i][1]] | |
|
627 | ||
|
628 | for t in range(len(laglist)): | |
|
629 | idxT = laglist[t] | |
|
630 | if idxT >= 0: | |
|
631 | vStacked = numpy.vstack((volts2[idxT:,:], | |
|
632 | numpy.zeros((idxT, nHeights),dtype='complex'))) | |
|
633 | else: | |
|
634 | vStacked = numpy.vstack((numpy.zeros((-idxT, nHeights),dtype='complex'), | |
|
635 | volts2[:(nPoints + idxT),:])) | |
|
636 | voltsCCF[i,t,:] = numpy.sum((numpy.conjugate(volts1)*vStacked),axis=0) | |
|
637 | ||
|
638 | vStacked = None | |
|
639 | return voltsCCF | |
|
640 | ||
|
641 | def __getNoise(self, power, timeSegment, timeInterval): | |
|
642 | numProfPerBlock = numpy.ceil(timeSegment/timeInterval) | |
|
643 | numBlocks = int(power.shape[0]/numProfPerBlock) | |
|
644 | numHeights = power.shape[1] | |
|
645 | ||
|
646 | listPower = numpy.array_split(power, numBlocks, 0) | |
|
647 | noise = numpy.zeros((power.shape[0], power.shape[1])) | |
|
648 | noise1 = numpy.zeros((power.shape[0], power.shape[1])) | |
|
649 | ||
|
650 | startInd = 0 | |
|
651 | endInd = 0 | |
|
652 | ||
|
653 | for i in range(numBlocks): #split por canal | |
|
654 | startInd = endInd | |
|
655 | endInd = endInd + listPower[i].shape[0] | |
|
656 | ||
|
657 | arrayBlock = listPower[i] | |
|
658 | noiseAux = numpy.mean(arrayBlock, 0) | |
|
659 | # noiseAux = numpy.median(noiseAux) | |
|
660 | # noiseAux = numpy.mean(arrayBlock) | |
|
661 | noise[startInd:endInd,:] = noise[startInd:endInd,:] + noiseAux | |
|
662 | ||
|
663 | noiseAux1 = numpy.mean(arrayBlock) | |
|
664 | noise1[startInd:endInd,:] = noise1[startInd:endInd,:] + noiseAux1 | |
|
665 | ||
|
666 | return noise, noise1 | |
|
667 | ||
|
668 | def __findMeteors(self, power, thresh): | |
|
669 | nProf = power.shape[0] | |
|
670 | nHeights = power.shape[1] | |
|
671 | listMeteors = [] | |
|
672 | ||
|
673 | for i in range(nHeights): | |
|
674 | powerAux = power[:,i] | |
|
675 | threshAux = thresh[:,i] | |
|
676 | ||
|
677 | indUPthresh = numpy.where(powerAux > threshAux)[0] | |
|
678 | indDNthresh = numpy.where(powerAux <= threshAux)[0] | |
|
679 | ||
|
680 | j = 0 | |
|
681 | ||
|
682 | while (j < indUPthresh.size - 2): | |
|
683 | if (indUPthresh[j + 2] == indUPthresh[j] + 2): | |
|
684 | indDNAux = numpy.where(indDNthresh > indUPthresh[j]) | |
|
685 | indDNthresh = indDNthresh[indDNAux] | |
|
686 | ||
|
687 | if (indDNthresh.size > 0): | |
|
688 | indEnd = indDNthresh[0] - 1 | |
|
689 | indInit = indUPthresh[j] | |
|
690 | ||
|
691 | meteor = powerAux[indInit:indEnd + 1] | |
|
692 | indPeak = meteor.argmax() + indInit | |
|
693 | FLA = sum(numpy.conj(meteor)*numpy.hstack((meteor[1:],0))) | |
|
694 | ||
|
695 | listMeteors.append(numpy.array([i,indInit,indPeak,indEnd,FLA])) #CHEQUEAR!!!!! | |
|
696 | j = numpy.where(indUPthresh == indEnd)[0] + 1 | |
|
697 | else: j+=1 | |
|
698 | else: j+=1 | |
|
699 | ||
|
700 | return listMeteors | |
|
701 | ||
|
702 | def __removeMultipleDetections(self,listMeteors, rangeLimit, timeLimit): | |
|
703 | ||
|
704 | arrayMeteors = numpy.asarray(listMeteors) | |
|
705 | listMeteors1 = [] | |
|
706 | ||
|
707 | while arrayMeteors.shape[0] > 0: | |
|
708 | FLAs = arrayMeteors[:,4] | |
|
709 | maxFLA = FLAs.argmax() | |
|
710 | listMeteors1.append(arrayMeteors[maxFLA,:]) | |
|
711 | ||
|
712 | MeteorInitTime = arrayMeteors[maxFLA,1] | |
|
713 | MeteorEndTime = arrayMeteors[maxFLA,3] | |
|
714 | MeteorHeight = arrayMeteors[maxFLA,0] | |
|
715 | ||
|
716 | #Check neighborhood | |
|
717 | maxHeightIndex = MeteorHeight + rangeLimit | |
|
718 | minHeightIndex = MeteorHeight - rangeLimit | |
|
719 | minTimeIndex = MeteorInitTime - timeLimit | |
|
720 | maxTimeIndex = MeteorEndTime + timeLimit | |
|
721 | ||
|
722 | #Check Heights | |
|
723 | indHeight = numpy.logical_and(arrayMeteors[:,0] >= minHeightIndex, arrayMeteors[:,0] <= maxHeightIndex) | |
|
724 | indTime = numpy.logical_and(arrayMeteors[:,3] >= minTimeIndex, arrayMeteors[:,1] <= maxTimeIndex) | |
|
725 | indBoth = numpy.where(numpy.logical_and(indTime,indHeight)) | |
|
726 | ||
|
727 | arrayMeteors = numpy.delete(arrayMeteors, indBoth, axis = 0) | |
|
728 | ||
|
729 | return listMeteors1 | |
|
730 | ||
|
731 | def __meteorReestimation(self, listMeteors, volts, pairslist, thresh, noise, timeInterval,frequency): | |
|
732 | numHeights = volts.shape[2] | |
|
733 | nChannel = volts.shape[0] | |
|
734 | ||
|
735 | thresholdPhase = thresh[0] | |
|
736 | thresholdNoise = thresh[1] | |
|
737 | thresholdDB = float(thresh[2]) | |
|
738 | ||
|
739 | thresholdDB1 = 10**(thresholdDB/10) | |
|
740 | pairsarray = numpy.array(pairslist) | |
|
741 | indSides = pairsarray[:,1] | |
|
742 | ||
|
743 | pairslist1 = list(pairslist) | |
|
744 | pairslist1.append((0,1)) | |
|
745 | pairslist1.append((3,4)) | |
|
746 | ||
|
747 | listMeteors1 = [] | |
|
748 | listPowerSeries = [] | |
|
749 | listVoltageSeries = [] | |
|
750 | #volts has the war data | |
|
751 | ||
|
752 | if frequency == 30e6: | |
|
753 | timeLag = 45*10**-3 | |
|
754 | else: | |
|
755 | timeLag = 15*10**-3 | |
|
756 | lag = numpy.ceil(timeLag/timeInterval) | |
|
757 | ||
|
758 | for i in range(len(listMeteors)): | |
|
759 | ||
|
760 | ###################### 3.6 - 3.7 PARAMETERS REESTIMATION ######################### | |
|
761 | meteorAux = numpy.zeros(16) | |
|
762 | ||
|
763 | #Loading meteor Data (mHeight, mStart, mPeak, mEnd) | |
|
764 | mHeight = listMeteors[i][0] | |
|
765 | mStart = listMeteors[i][1] | |
|
766 | mPeak = listMeteors[i][2] | |
|
767 | mEnd = listMeteors[i][3] | |
|
768 | ||
|
769 | #get the volt data between the start and end times of the meteor | |
|
770 | meteorVolts = volts[:,mStart:mEnd+1,mHeight] | |
|
771 | meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1) | |
|
772 | ||
|
773 | #3.6. Phase Difference estimation | |
|
774 | phaseDiff, aux = self.__estimatePhaseDifference(meteorVolts, pairslist) | |
|
775 | ||
|
776 | #3.7. Phase difference removal & meteor start, peak and end times reestimated | |
|
777 | #meteorVolts0.- all Channels, all Profiles | |
|
778 | meteorVolts0 = volts[:,:,mHeight] | |
|
779 | meteorThresh = noise[:,mHeight]*thresholdNoise | |
|
780 | meteorNoise = noise[:,mHeight] | |
|
781 | meteorVolts0[indSides,:] = self.__shiftPhase(meteorVolts0[indSides,:], phaseDiff) #Phase Shifting | |
|
782 | powerNet0 = numpy.nansum(numpy.abs(meteorVolts0)**2, axis = 0) #Power | |
|
783 | ||
|
784 | #Times reestimation | |
|
785 | mStart1 = numpy.where(powerNet0[:mPeak] < meteorThresh[:mPeak])[0] | |
|
786 | if mStart1.size > 0: | |
|
787 | mStart1 = mStart1[-1] + 1 | |
|
788 | ||
|
789 | else: | |
|
790 | mStart1 = mPeak | |
|
791 | ||
|
792 | mEnd1 = numpy.where(powerNet0[mPeak:] < meteorThresh[mPeak:])[0][0] + mPeak - 1 | |
|
793 | mEndDecayTime1 = numpy.where(powerNet0[mPeak:] < meteorNoise[mPeak:])[0] | |
|
794 | if mEndDecayTime1.size == 0: | |
|
795 | mEndDecayTime1 = powerNet0.size | |
|
796 | else: | |
|
797 | mEndDecayTime1 = mEndDecayTime1[0] + mPeak - 1 | |
|
798 | # mPeak1 = meteorVolts0[mStart1:mEnd1 + 1].argmax() | |
|
799 | ||
|
800 | #meteorVolts1.- all Channels, from start to end | |
|
801 | meteorVolts1 = meteorVolts0[:,mStart1:mEnd1 + 1] | |
|
802 | meteorVolts2 = meteorVolts0[:,mPeak + lag:mEnd1 + 1] | |
|
803 | if meteorVolts2.shape[1] == 0: | |
|
804 | meteorVolts2 = meteorVolts0[:,mPeak:mEnd1 + 1] | |
|
805 | meteorVolts1 = meteorVolts1.reshape(meteorVolts1.shape[0], meteorVolts1.shape[1], 1) | |
|
806 | meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1], 1) | |
|
807 | ##################### END PARAMETERS REESTIMATION ######################### | |
|
808 | ||
|
809 | ##################### 3.8 PHASE DIFFERENCE REESTIMATION ######################## | |
|
810 | # if mEnd1 - mStart1 > 4: #Error Number 6: echo less than 5 samples long; too short for analysis | |
|
811 | if meteorVolts2.shape[1] > 0: | |
|
812 | #Phase Difference re-estimation | |
|
813 | phaseDiff1, phaseDiffint = self.__estimatePhaseDifference(meteorVolts2, pairslist1) #Phase Difference Estimation | |
|
814 | # phaseDiff1, phaseDiffint = self.estimatePhaseDifference(meteorVolts2, pairslist) | |
|
815 | meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1]) | |
|
816 | phaseDiff11 = numpy.reshape(phaseDiff1, (phaseDiff1.shape[0],1)) | |
|
817 | meteorVolts2[indSides,:] = self.__shiftPhase(meteorVolts2[indSides,:], phaseDiff11[0:4]) #Phase Shifting | |
|
818 | ||
|
819 | #Phase Difference RMS | |
|
820 | phaseRMS1 = numpy.sqrt(numpy.mean(numpy.square(phaseDiff1))) | |
|
821 | powerNet1 = numpy.nansum(numpy.abs(meteorVolts1[:,:])**2,0) | |
|
822 | #Data from Meteor | |
|
823 | mPeak1 = powerNet1.argmax() + mStart1 | |
|
824 | mPeakPower1 = powerNet1.max() | |
|
825 | noiseAux = sum(noise[mStart1:mEnd1 + 1,mHeight]) | |
|
826 | mSNR1 = (sum(powerNet1)-noiseAux)/noiseAux | |
|
827 | Meteor1 = numpy.array([mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1]) | |
|
828 | Meteor1 = numpy.hstack((Meteor1,phaseDiffint)) | |
|
829 | PowerSeries = powerNet0[mStart1:mEndDecayTime1 + 1] | |
|
830 | #Vectorize | |
|
831 | meteorAux[0:7] = [mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1] | |
|
832 | meteorAux[7:11] = phaseDiffint[0:4] | |
|
833 | ||
|
834 | #Rejection Criterions | |
|
835 | if phaseRMS1 > thresholdPhase: #Error Number 17: Phase variation | |
|
836 | meteorAux[-1] = 17 | |
|
837 | elif mSNR1 < thresholdDB1: #Error Number 1: SNR < threshold dB | |
|
838 | meteorAux[-1] = 1 | |
|
839 | ||
|
840 | ||
|
841 | else: | |
|
842 | meteorAux[0:4] = [mHeight, mStart, mPeak, mEnd] | |
|
843 | meteorAux[-1] = 6 #Error Number 6: echo less than 5 samples long; too short for analysis | |
|
844 | PowerSeries = 0 | |
|
845 | ||
|
846 | listMeteors1.append(meteorAux) | |
|
847 | listPowerSeries.append(PowerSeries) | |
|
848 | listVoltageSeries.append(meteorVolts1) | |
|
849 | ||
|
850 | return listMeteors1, listPowerSeries, listVoltageSeries | |
|
851 | ||
|
852 | def __estimateDecayTime(self, listMeteors, listPower, timeInterval, frequency): | |
|
853 | ||
|
854 | threshError = 10 | |
|
855 | #Depending if it is 30 or 50 MHz | |
|
856 | if frequency == 30e6: | |
|
857 | timeLag = 45*10**-3 | |
|
858 | else: | |
|
859 | timeLag = 15*10**-3 | |
|
860 | lag = numpy.ceil(timeLag/timeInterval) | |
|
861 | ||
|
862 | listMeteors1 = [] | |
|
863 | ||
|
864 | for i in range(len(listMeteors)): | |
|
865 | meteorPower = listPower[i] | |
|
866 | meteorAux = listMeteors[i] | |
|
867 | ||
|
868 | if meteorAux[-1] == 0: | |
|
869 | ||
|
870 | try: | |
|
871 | indmax = meteorPower.argmax() | |
|
872 | indlag = indmax + lag | |
|
873 | ||
|
874 | y = meteorPower[indlag:] | |
|
875 | x = numpy.arange(0, y.size)*timeLag | |
|
876 | ||
|
877 | #first guess | |
|
878 | a = y[0] | |
|
879 | tau = timeLag | |
|
880 | #exponential fit | |
|
881 | popt, pcov = optimize.curve_fit(self.__exponential_function, x, y, p0 = [a, tau]) | |
|
882 | y1 = self.__exponential_function(x, *popt) | |
|
883 | #error estimation | |
|
884 | error = sum((y - y1)**2)/(numpy.var(y)*(y.size - popt.size)) | |
|
885 | ||
|
886 | decayTime = popt[1] | |
|
887 | riseTime = indmax*timeInterval | |
|
888 | meteorAux[11:13] = [decayTime, error] | |
|
889 | ||
|
890 | #Table items 7, 8 and 11 | |
|
891 | if (riseTime > 0.3): #Number 7: Echo rise exceeds 0.3s | |
|
892 | meteorAux[-1] = 7 | |
|
893 | elif (decayTime < 2*riseTime) : #Number 8: Echo decay time less than than twice rise time | |
|
894 | meteorAux[-1] = 8 | |
|
895 | if (error > threshError): #Number 11: Poor fit to amplitude for estimation of decay time | |
|
896 | meteorAux[-1] = 11 | |
|
897 | ||
|
898 | ||
|
899 | except: | |
|
900 | meteorAux[-1] = 11 | |
|
901 | ||
|
902 | ||
|
903 | listMeteors1.append(meteorAux) | |
|
904 | ||
|
905 | return listMeteors1 | |
|
906 | ||
|
907 | #Exponential Function | |
|
908 | ||
|
909 | def __exponential_function(self, x, a, tau): | |
|
910 | y = a*numpy.exp(-x/tau) | |
|
911 | return y | |
|
912 | ||
|
913 | def __getRadialVelocity(self, listMeteors, listVolts, radialStdThresh, pairslist, timeInterval): | |
|
914 | ||
|
915 | pairslist1 = list(pairslist) | |
|
916 | pairslist1.append((0,1)) | |
|
917 | pairslist1.append((3,4)) | |
|
918 | numPairs = len(pairslist1) | |
|
919 | #Time Lag | |
|
920 | timeLag = 45*10**-3 | |
|
921 | c = 3e8 | |
|
922 | lag = numpy.ceil(timeLag/timeInterval) | |
|
923 | freq = 30e6 | |
|
924 | ||
|
925 | listMeteors1 = [] | |
|
926 | ||
|
927 | for i in range(len(listMeteors)): | |
|
928 | meteor = listMeteors[i] | |
|
929 | meteorAux = numpy.hstack((meteor[:-1], 0, 0, meteor[-1])) | |
|
930 | if meteor[-1] == 0: | |
|
931 | mStart = listMeteors[i][1] | |
|
932 | mPeak = listMeteors[i][2] | |
|
933 | mLag = mPeak - mStart + lag | |
|
934 | ||
|
935 | #get the volt data between the start and end times of the meteor | |
|
936 | meteorVolts = listVolts[i] | |
|
937 | meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1) | |
|
938 | ||
|
939 | #Get CCF | |
|
940 | allCCFs = self.__calculateCCF(meteorVolts, pairslist1, [-2,-1,0,1,2]) | |
|
941 | ||
|
942 | #Method 2 | |
|
943 | slopes = numpy.zeros(numPairs) | |
|
944 | time = numpy.array([-2,-1,1,2])*timeInterval | |
|
945 | angAllCCF = numpy.angle(allCCFs[:,[0,1,3,4],0]) | |
|
946 | ||
|
947 | #Correct phases | |
|
948 | derPhaseCCF = angAllCCF[:,1:] - angAllCCF[:,0:-1] | |
|
949 | indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi) | |
|
950 | ||
|
951 | if indDer[0].shape[0] > 0: | |
|
952 | for i in range(indDer[0].shape[0]): | |
|
953 | signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i]]) | |
|
954 | angAllCCF[indDer[0][i],indDer[1][i]+1:] += signo*2*numpy.pi | |
|
955 | ||
|
956 | # fit = scipy.stats.linregress(numpy.array([-2,-1,1,2])*timeInterval, numpy.array([phaseLagN2s[i],phaseLagN1s[i],phaseLag1s[i],phaseLag2s[i]])) | |
|
957 | for j in range(numPairs): | |
|
958 | fit = stats.linregress(time, angAllCCF[j,:]) | |
|
959 | slopes[j] = fit[0] | |
|
960 | ||
|
961 | #Remove Outlier | |
|
962 | # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes))) | |
|
963 | # slopes = numpy.delete(slopes,indOut) | |
|
964 | # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes))) | |
|
965 | # slopes = numpy.delete(slopes,indOut) | |
|
966 | ||
|
967 | radialVelocity = -numpy.mean(slopes)*(0.25/numpy.pi)*(c/freq) | |
|
968 | radialError = numpy.std(slopes)*(0.25/numpy.pi)*(c/freq) | |
|
969 | meteorAux[-2] = radialError | |
|
970 | meteorAux[-3] = radialVelocity | |
|
971 | ||
|
972 | #Setting Error | |
|
973 | #Number 15: Radial Drift velocity or projected horizontal velocity exceeds 200 m/s | |
|
974 | if numpy.abs(radialVelocity) > 200: | |
|
975 | meteorAux[-1] = 15 | |
|
976 | #Number 12: Poor fit to CCF variation for estimation of radial drift velocity | |
|
977 | elif radialError > radialStdThresh: | |
|
978 | meteorAux[-1] = 12 | |
|
979 | ||
|
980 | listMeteors1.append(meteorAux) | |
|
981 | return listMeteors1 | |
|
982 | ||
|
983 | def __setNewArrays(self, listMeteors, date, heiRang): | |
|
984 | ||
|
985 | #New arrays | |
|
986 | arrayMeteors = numpy.array(listMeteors) | |
|
987 | arrayParameters = numpy.zeros((len(listMeteors),10)) | |
|
988 | ||
|
989 | #Date inclusion | |
|
990 | date = re.findall(r'\((.*?)\)', date) | |
|
991 | date = date[0].split(',') | |
|
992 | date = map(int, date) | |
|
993 | date = [date[0]*10000 + date[1]*100 + date[2], date[3]*10000 + date[4]*100 + date[5]] | |
|
994 | arrayDate = numpy.tile(date, (len(listMeteors), 1)) | |
|
995 | ||
|
996 | #Meteor array | |
|
997 | arrayMeteors[:,0] = heiRang[arrayMeteors[:,0].astype(int)] | |
|
998 | arrayMeteors = numpy.hstack((arrayDate, arrayMeteors)) | |
|
999 | ||
|
1000 | #Parameters Array | |
|
1001 | arrayParameters[:,0:3] = arrayMeteors[:,0:3] | |
|
1002 | arrayParameters[:,-3:] = arrayMeteors[:,-3:] | |
|
1003 | ||
|
1004 | return arrayMeteors, arrayParameters | |
|
1005 | ||
|
1006 | def __getAOA(self, phases, pairsList, error, AOAthresh, azimuth): | |
|
1007 | ||
|
1008 | arrayAOA = numpy.zeros((phases.shape[0],3)) | |
|
1009 | cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList) | |
|
1010 | ||
|
1011 | arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth) | |
|
1012 | cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1) | |
|
1013 | arrayAOA[:,2] = cosDirError | |
|
1014 | ||
|
1015 | azimuthAngle = arrayAOA[:,0] | |
|
1016 | zenithAngle = arrayAOA[:,1] | |
|
1017 | ||
|
1018 | #Setting Error | |
|
1019 | #Number 3: AOA not fesible | |
|
1020 | indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0] | |
|
1021 | error[indInvalid] = 3 | |
|
1022 | #Number 4: Large difference in AOAs obtained from different antenna baselines | |
|
1023 | indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0] | |
|
1024 | error[indInvalid] = 4 | |
|
1025 | return arrayAOA, error | |
|
1026 | ||
|
1027 | def __getDirectionCosines(self, arrayPhase, pairsList): | |
|
1028 | ||
|
1029 | #Initializing some variables | |
|
1030 | ang_aux = numpy.array([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])*2*numpy.pi | |
|
1031 | ang_aux = ang_aux.reshape(1,ang_aux.size) | |
|
1032 | ||
|
1033 | cosdir = numpy.zeros((arrayPhase.shape[0],2)) | |
|
1034 | cosdir0 = numpy.zeros((arrayPhase.shape[0],2)) | |
|
1035 | ||
|
1036 | ||
|
1037 | for i in range(2): | |
|
1038 | #First Estimation | |
|
1039 | phi0_aux = arrayPhase[:,pairsList[i][0]] + arrayPhase[:,pairsList[i][1]] | |
|
1040 | #Dealias | |
|
1041 | indcsi = numpy.where(phi0_aux > numpy.pi) | |
|
1042 | phi0_aux[indcsi] -= 2*numpy.pi | |
|
1043 | indcsi = numpy.where(phi0_aux < -numpy.pi) | |
|
1044 | phi0_aux[indcsi] += 2*numpy.pi | |
|
1045 | #Direction Cosine 0 | |
|
1046 | cosdir0[:,i] = -(phi0_aux)/(2*numpy.pi*0.5) | |
|
1047 | ||
|
1048 | #Most-Accurate Second Estimation | |
|
1049 | phi1_aux = arrayPhase[:,pairsList[i][0]] - arrayPhase[:,pairsList[i][1]] | |
|
1050 | phi1_aux = phi1_aux.reshape(phi1_aux.size,1) | |
|
1051 | #Direction Cosine 1 | |
|
1052 | cosdir1 = -(phi1_aux + ang_aux)/(2*numpy.pi*4.5) | |
|
1053 | ||
|
1054 | #Searching the correct Direction Cosine | |
|
1055 | cosdir0_aux = cosdir0[:,i] | |
|
1056 | cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1) | |
|
1057 | #Minimum Distance | |
|
1058 | cosDiff = (cosdir1 - cosdir0_aux)**2 | |
|
1059 | indcos = cosDiff.argmin(axis = 1) | |
|
1060 | #Saving Value obtained | |
|
1061 | cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos] | |
|
1062 | ||
|
1063 | return cosdir0, cosdir | |
|
1064 | ||
|
1065 | def __calculateAOA(self, cosdir, azimuth): | |
|
1066 | cosdirX = cosdir[:,0] | |
|
1067 | cosdirY = cosdir[:,1] | |
|
1068 | ||
|
1069 | zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi | |
|
1070 | azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth #0 deg north, 90 deg east | |
|
1071 | angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose() | |
|
1072 | ||
|
1073 | return angles | |
|
1074 | ||
|
1075 | def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight): | |
|
1076 | ||
|
1077 | Ramb = 375 #Ramb = c/(2*PRF) | |
|
1078 | Re = 6371 #Earth Radius | |
|
1079 | heights = numpy.zeros(Ranges.shape) | |
|
1080 | ||
|
1081 | R_aux = numpy.array([0,1,2])*Ramb | |
|
1082 | R_aux = R_aux.reshape(1,R_aux.size) | |
|
1083 | ||
|
1084 | Ranges = Ranges.reshape(Ranges.size,1) | |
|
1085 | ||
|
1086 | Ri = Ranges + R_aux | |
|
1087 | hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re | |
|
1088 | ||
|
1089 | #Check if there is a height between 70 and 110 km | |
|
1090 | h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1) | |
|
1091 | ind_h = numpy.where(h_bool == 1)[0] | |
|
1092 | ||
|
1093 | hCorr = hi[ind_h, :] | |
|
1094 | ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight)) | |
|
1095 | ||
|
1096 | hCorr = hi[ind_hCorr] | |
|
1097 | heights[ind_h] = hCorr | |
|
1098 | ||
|
1099 | #Setting Error | |
|
1100 | #Number 13: Height unresolvable echo: not valid height within 70 to 110 km | |
|
1101 | #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km | |
|
1102 | ||
|
1103 | indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0] | |
|
1104 | error[indInvalid2] = 14 | |
|
1105 | indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0] | |
|
1106 | error[indInvalid1] = 13 | |
|
1107 | ||
|
1108 | return heights, error | |
|
1109 | ||
|
1110 | ||
|
1111 | class WindProfiler(Operation): | |
|
1112 | ||
|
1113 | __isConfig = False | |
|
1114 | ||
|
1115 | __initime = None | |
|
1116 | __lastdatatime = None | |
|
1117 | __integrationtime = None | |
|
1118 | ||
|
1119 | __buffer = None | |
|
1120 | ||
|
1121 | __dataReady = False | |
|
1122 | ||
|
1123 | __firstdata = None | |
|
1124 | ||
|
1125 | n = None | |
|
1126 | ||
|
1127 | def __init__(self): | |
|
1128 | Operation.__init__(self) | |
|
1129 | ||
|
1130 | def __calculateAngles(self, theta_x, theta_y, azimuth): | |
|
1131 | ||
|
1132 | dir_cosw = numpy.sqrt(1-theta_x**2-theta_y**2) | |
|
1133 | zenith_arr = numpy.arccos(dir_cosw) | |
|
1134 | azimuth_arr = numpy.arctan2(theta_x,theta_y) + azimuth*math.pi/180 | |
|
1135 | ||
|
1136 | dir_cosu = numpy.sin(azimuth_arr)*numpy.sin(zenith_arr) | |
|
1137 | dir_cosv = numpy.cos(azimuth_arr)*numpy.sin(zenith_arr) | |
|
1138 | ||
|
1139 | return azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw | |
|
1140 | ||
|
1141 | def __calculateMatA(self, dir_cosu, dir_cosv, dir_cosw, horOnly): | |
|
1142 | ||
|
1143 | # | |
|
1144 | if horOnly: | |
|
1145 | A = numpy.c_[dir_cosu,dir_cosv] | |
|
1146 | else: | |
|
1147 | A = numpy.c_[dir_cosu,dir_cosv,dir_cosw] | |
|
1148 | A = numpy.asmatrix(A) | |
|
1149 | A1 = numpy.linalg.inv(A.transpose()*A)*A.transpose() | |
|
1150 | ||
|
1151 | return A1 | |
|
1152 | ||
|
1153 | def __correctValues(self, heiRang, phi, velRadial, SNR): | |
|
1154 | listPhi = phi.tolist() | |
|
1155 | maxid = listPhi.index(max(listPhi)) | |
|
1156 | minid = listPhi.index(min(listPhi)) | |
|
1157 | ||
|
1158 | rango = range(len(phi)) | |
|
1159 | # rango = numpy.delete(rango,maxid) | |
|
1160 | ||
|
1161 | heiRang1 = heiRang*math.cos(phi[maxid]) | |
|
1162 | heiRangAux = heiRang*math.cos(phi[minid]) | |
|
1163 | indOut = (heiRang1 < heiRangAux[0]).nonzero() | |
|
1164 | heiRang1 = numpy.delete(heiRang1,indOut) | |
|
1165 | ||
|
1166 | velRadial1 = numpy.zeros([len(phi),len(heiRang1)]) | |
|
1167 | SNR1 = numpy.zeros([len(phi),len(heiRang1)]) | |
|
1168 | ||
|
1169 | for i in rango: | |
|
1170 | x = heiRang*math.cos(phi[i]) | |
|
1171 | y1 = velRadial[i,:] | |
|
1172 | f1 = interpolate.interp1d(x,y1,kind = 'cubic') | |
|
1173 | ||
|
1174 | x1 = heiRang1 | |
|
1175 | y11 = f1(x1) | |
|
1176 | ||
|
1177 | y2 = SNR[i,:] | |
|
1178 | f2 = interpolate.interp1d(x,y2,kind = 'cubic') | |
|
1179 | y21 = f2(x1) | |
|
1180 | ||
|
1181 | velRadial1[i,:] = y11 | |
|
1182 | SNR1[i,:] = y21 | |
|
1183 | ||
|
1184 | return heiRang1, velRadial1, SNR1 | |
|
1185 | ||
|
1186 | def __calculateVelUVW(self, A, velRadial): | |
|
1187 | ||
|
1188 | #Operacion Matricial | |
|
1189 | # velUVW = numpy.zeros((velRadial.shape[1],3)) | |
|
1190 | # for ind in range(velRadial.shape[1]): | |
|
1191 | # velUVW[ind,:] = numpy.dot(A,velRadial[:,ind]) | |
|
1192 | # velUVW = velUVW.transpose() | |
|
1193 | velUVW = numpy.zeros((A.shape[0],velRadial.shape[1])) | |
|
1194 | velUVW[:,:] = numpy.dot(A,velRadial) | |
|
1195 | ||
|
1196 | ||
|
1197 | return velUVW | |
|
1198 | ||
|
1199 | def techniqueDBS(self, velRadial0, dirCosx, disrCosy, azimuth, correct, horizontalOnly, heiRang, SNR0): | |
|
1200 | """ | |
|
1201 | Function that implements Doppler Beam Swinging (DBS) technique. | |
|
1202 | ||
|
1203 | Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth, | |
|
1204 | Direction correction (if necessary), Ranges and SNR | |
|
1205 | ||
|
1206 | Output: Winds estimation (Zonal, Meridional and Vertical) | |
|
1207 | ||
|
1208 | Parameters affected: Winds, height range, SNR | |
|
1209 | """ | |
|
1210 | azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw = self.__calculateAngles(dirCosx, disrCosy, azimuth) | |
|
1211 | heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, zenith_arr, correct*velRadial0, SNR0) | |
|
1212 | A = self.__calculateMatA(dir_cosu, dir_cosv, dir_cosw, horizontalOnly) | |
|
1213 | ||
|
1214 | #Calculo de Componentes de la velocidad con DBS | |
|
1215 | winds = self.__calculateVelUVW(A,velRadial1) | |
|
1216 | ||
|
1217 | return winds, heiRang1, SNR1 | |
|
1218 | ||
|
1219 | def __calculateDistance(self, posx, posy, pairsCrossCorr, pairsList, pairs, azimuth = None): | |
|
1220 | ||
|
1221 | posx = numpy.asarray(posx) | |
|
1222 | posy = numpy.asarray(posy) | |
|
1223 | ||
|
1224 | #Rotacion Inversa para alinear con el azimuth | |
|
1225 | if azimuth!= None: | |
|
1226 | azimuth = azimuth*math.pi/180 | |
|
1227 | posx1 = posx*math.cos(azimuth) + posy*math.sin(azimuth) | |
|
1228 | posy1 = -posx*math.sin(azimuth) + posy*math.cos(azimuth) | |
|
1229 | else: | |
|
1230 | posx1 = posx | |
|
1231 | posy1 = posy | |
|
1232 | ||
|
1233 | #Calculo de Distancias | |
|
1234 | distx = numpy.zeros(pairsCrossCorr.size) | |
|
1235 | disty = numpy.zeros(pairsCrossCorr.size) | |
|
1236 | dist = numpy.zeros(pairsCrossCorr.size) | |
|
1237 | ang = numpy.zeros(pairsCrossCorr.size) | |
|
1238 | ||
|
1239 | for i in range(pairsCrossCorr.size): | |
|
1240 | distx[i] = posx1[pairsList[pairsCrossCorr[i]][1]] - posx1[pairsList[pairsCrossCorr[i]][0]] | |
|
1241 | disty[i] = posy1[pairsList[pairsCrossCorr[i]][1]] - posy1[pairsList[pairsCrossCorr[i]][0]] | |
|
1242 | dist[i] = numpy.sqrt(distx[i]**2 + disty[i]**2) | |
|
1243 | ang[i] = numpy.arctan2(disty[i],distx[i]) | |
|
1244 | #Calculo de Matrices | |
|
1245 | nPairs = len(pairs) | |
|
1246 | ang1 = numpy.zeros((nPairs, 2, 1)) | |
|
1247 | dist1 = numpy.zeros((nPairs, 2, 1)) | |
|
1248 | ||
|
1249 | for j in range(nPairs): | |
|
1250 | dist1[j,0,0] = dist[pairs[j][0]] | |
|
1251 | dist1[j,1,0] = dist[pairs[j][1]] | |
|
1252 | ang1[j,0,0] = ang[pairs[j][0]] | |
|
1253 | ang1[j,1,0] = ang[pairs[j][1]] | |
|
1254 | ||
|
1255 | return distx,disty, dist1,ang1 | |
|
1256 | ||
|
1257 | def __calculateVelVer(self, phase, lagTRange, _lambda): | |
|
1258 | ||
|
1259 | Ts = lagTRange[1] - lagTRange[0] | |
|
1260 | velW = -_lambda*phase/(4*math.pi*Ts) | |
|
1261 | ||
|
1262 | return velW | |
|
1263 | ||
|
1264 | def __calculateVelHorDir(self, dist, tau1, tau2, ang): | |
|
1265 | nPairs = tau1.shape[0] | |
|
1266 | vel = numpy.zeros((nPairs,3,tau1.shape[2])) | |
|
1267 | ||
|
1268 | angCos = numpy.cos(ang) | |
|
1269 | angSin = numpy.sin(ang) | |
|
1270 | ||
|
1271 | vel0 = dist*tau1/(2*tau2**2) | |
|
1272 | vel[:,0,:] = (vel0*angCos).sum(axis = 1) | |
|
1273 | vel[:,1,:] = (vel0*angSin).sum(axis = 1) | |
|
1274 | ||
|
1275 | ind = numpy.where(numpy.isinf(vel)) | |
|
1276 | vel[ind] = numpy.nan | |
|
1277 | ||
|
1278 | return vel | |
|
1279 | ||
|
1280 | def __getPairsAutoCorr(self, pairsList, nChannels): | |
|
1281 | ||
|
1282 | pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan | |
|
1283 | ||
|
1284 | for l in range(len(pairsList)): | |
|
1285 | firstChannel = pairsList[l][0] | |
|
1286 | secondChannel = pairsList[l][1] | |
|
1287 | ||
|
1288 | #Obteniendo pares de Autocorrelacion | |
|
1289 | if firstChannel == secondChannel: | |
|
1290 | pairsAutoCorr[firstChannel] = int(l) | |
|
1291 | ||
|
1292 | pairsAutoCorr = pairsAutoCorr.astype(int) | |
|
1293 | ||
|
1294 | pairsCrossCorr = range(len(pairsList)) | |
|
1295 | pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr) | |
|
1296 | ||
|
1297 | return pairsAutoCorr, pairsCrossCorr | |
|
1298 | ||
|
1299 | def techniqueSA(self, pairsSelected, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, lagTRange, correctFactor): | |
|
1300 | """ | |
|
1301 | Function that implements Spaced Antenna (SA) technique. | |
|
1302 | ||
|
1303 | Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth, | |
|
1304 | Direction correction (if necessary), Ranges and SNR | |
|
1305 | ||
|
1306 | Output: Winds estimation (Zonal, Meridional and Vertical) | |
|
1307 | ||
|
1308 | Parameters affected: Winds | |
|
1309 | """ | |
|
1310 | #Cross Correlation pairs obtained | |
|
1311 | pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairsList, nChannels) | |
|
1312 | pairsArray = numpy.array(pairsList)[pairsCrossCorr] | |
|
1313 | pairsSelArray = numpy.array(pairsSelected) | |
|
1314 | pairs = [] | |
|
1315 | ||
|
1316 | #Wind estimation pairs obtained | |
|
1317 | for i in range(pairsSelArray.shape[0]/2): | |
|
1318 | ind1 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i], axis = 1))[0][0] | |
|
1319 | ind2 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i + 1], axis = 1))[0][0] | |
|
1320 | pairs.append((ind1,ind2)) | |
|
1321 | ||
|
1322 | indtau = tau.shape[0]/2 | |
|
1323 | tau1 = tau[:indtau,:] | |
|
1324 | tau2 = tau[indtau:-1,:] | |
|
1325 | tau1 = tau1[pairs,:] | |
|
1326 | tau2 = tau2[pairs,:] | |
|
1327 | phase1 = tau[-1,:] | |
|
1328 | ||
|
1329 | #--------------------------------------------------------------------- | |
|
1330 | #Metodo Directo | |
|
1331 | distx, disty, dist, ang = self.__calculateDistance(position_x, position_y, pairsCrossCorr, pairsList, pairs,azimuth) | |
|
1332 | winds = self.__calculateVelHorDir(dist, tau1, tau2, ang) | |
|
1333 | winds = stats.nanmean(winds, axis=0) | |
|
1334 | #--------------------------------------------------------------------- | |
|
1335 | #Metodo General | |
|
1336 | # distx, disty, dist = self.calculateDistance(position_x,position_y,pairsCrossCorr, pairsList, azimuth) | |
|
1337 | # #Calculo Coeficientes de Funcion de Correlacion | |
|
1338 | # F,G,A,B,H = self.calculateCoef(tau1,tau2,distx,disty,n) | |
|
1339 | # #Calculo de Velocidades | |
|
1340 | # winds = self.calculateVelUV(F,G,A,B,H) | |
|
1341 | ||
|
1342 | #--------------------------------------------------------------------- | |
|
1343 | winds[2,:] = self.__calculateVelVer(phase1, lagTRange, _lambda) | |
|
1344 | winds = correctFactor*winds | |
|
1345 | return winds | |
|
1346 | ||
|
1347 | def __checkTime(self, currentTime, paramInterval, windsInterval): | |
|
1348 | ||
|
1349 | dataTime = currentTime + paramInterval | |
|
1350 | deltaTime = dataTime - self.__initime | |
|
1351 | ||
|
1352 | if deltaTime >= windsInterval or deltaTime < 0: | |
|
1353 | self.__dataReady = True | |
|
1354 | return | |
|
1355 | ||
|
1356 | def techniqueMeteors(self, arrayMeteor, meteorThresh, heightMin, heightMax): | |
|
1357 | ''' | |
|
1358 | Function that implements winds estimation technique with detected meteors. | |
|
1359 | ||
|
1360 | Input: Detected meteors, Minimum meteor quantity to wind estimation | |
|
1361 | ||
|
1362 | Output: Winds estimation (Zonal and Meridional) | |
|
1363 | ||
|
1364 | Parameters affected: Winds | |
|
1365 | ''' | |
|
1366 | #Settings | |
|
1367 | nInt = (heightMax - heightMin)/2 | |
|
1368 | winds = numpy.zeros((2,nInt))*numpy.nan | |
|
1369 | ||
|
1370 | #Filter errors | |
|
1371 | error = numpy.where(arrayMeteor[:,-1] == 0)[0] | |
|
1372 | finalMeteor = arrayMeteor[error,:] | |
|
1373 | ||
|
1374 | #Meteor Histogram | |
|
1375 | finalHeights = finalMeteor[:,3] | |
|
1376 | hist = numpy.histogram(finalHeights, bins = nInt, range = (heightMin,heightMax)) | |
|
1377 | nMeteorsPerI = hist[0] | |
|
1378 | heightPerI = hist[1] | |
|
1379 | ||
|
1380 | #Sort of meteors | |
|
1381 | indSort = finalHeights.argsort() | |
|
1382 | finalMeteor2 = finalMeteor[indSort,:] | |
|
1383 | ||
|
1384 | # Calculating winds | |
|
1385 | ind1 = 0 | |
|
1386 | ind2 = 0 | |
|
1387 | ||
|
1388 | for i in range(nInt): | |
|
1389 | nMet = nMeteorsPerI[i] | |
|
1390 | ind1 = ind2 | |
|
1391 | ind2 = ind1 + nMet | |
|
1392 | ||
|
1393 | meteorAux = finalMeteor2[ind1:ind2,:] | |
|
1394 | ||
|
1395 | if meteorAux.shape[0] >= meteorThresh: | |
|
1396 | vel = meteorAux[:, 7] | |
|
1397 | zen = meteorAux[:, 5]*numpy.pi/180 | |
|
1398 | azim = meteorAux[:, 4]*numpy.pi/180 | |
|
1399 | ||
|
1400 | n = numpy.cos(zen) | |
|
1401 | # m = (1 - n**2)/(1 - numpy.tan(azim)**2) | |
|
1402 | # l = m*numpy.tan(azim) | |
|
1403 | l = numpy.sin(zen)*numpy.sin(azim) | |
|
1404 | m = numpy.sin(zen)*numpy.cos(azim) | |
|
1405 | ||
|
1406 | A = numpy.vstack((l, m)).transpose() | |
|
1407 | A1 = numpy.dot(numpy.linalg.inv( numpy.dot(A.transpose(),A) ),A.transpose()) | |
|
1408 | windsAux = numpy.dot(A1, vel) | |
|
1409 | ||
|
1410 | winds[0,i] = windsAux[0] | |
|
1411 | winds[1,i] = windsAux[1] | |
|
1412 | ||
|
1413 | return winds, heightPerI[:-1] | |
|
1414 | ||
|
1415 | def run(self, dataOut, technique, **kwargs): | |
|
1416 | ||
|
1417 | param = dataOut.data_param | |
|
1418 | if dataOut.abscissaRange != None: | |
|
1419 | absc = dataOut.abscissaRange[:-1] | |
|
1420 | noise = dataOut.noise | |
|
1421 | heightRange = dataOut.getHeiRange() | |
|
1422 | SNR = dataOut.SNR | |
|
1423 | ||
|
1424 | if technique == 'DBS': | |
|
1425 | ||
|
1426 | theta_x = numpy.array(kwargs['dirCosx']) | |
|
1427 | theta_y = numpy.array(kwargs['dirCosy']) | |
|
1428 | azimuth = kwargs['azimuth'] | |
|
1429 | if kwargs.has_key('horizontalOnly'): | |
|
1430 | horizontalOnly = kwargs['horizontalOnly'] | |
|
1431 | else: horizontalOnly = False | |
|
1432 | if kwargs.has_key('correctFactor'): | |
|
1433 | correctFactor = kwargs['correctFactor'] | |
|
1434 | else: correctFactor = 1 | |
|
1435 | if kwargs.has_key('channelList'): | |
|
1436 | channelList = kwargs['channelList'] | |
|
1437 | if len(channelList) == 2: | |
|
1438 | horizontalOnly = True | |
|
1439 | arrayChannel = numpy.array(channelList) | |
|
1440 | param = param[arrayChannel,:,:] | |
|
1441 | theta_x = theta_x[arrayChannel] | |
|
1442 | theta_y = theta_y[arrayChannel] | |
|
1443 | ||
|
1444 | velRadial0 = param[:,1,:] #Radial velocity | |
|
1445 | dataOut.winds, dataOut.heightRange, dataOut.SNR = self.techniqueDBS(velRadial0, theta_x, theta_y, azimuth, correctFactor, horizontalOnly, heightRange, SNR) #DBS Function | |
|
1446 | dataOut.initUtcTime = dataOut.ltctime | |
|
1447 | dataOut.windsInterval = dataOut.timeInterval | |
|
1448 | ||
|
1449 | elif technique == 'SA': | |
|
1450 | ||
|
1451 | #Parameters | |
|
1452 | position_x = kwargs['positionX'] | |
|
1453 | position_y = kwargs['positionY'] | |
|
1454 | azimuth = kwargs['azimuth'] | |
|
1455 | ||
|
1456 | if kwargs.has_key('crosspairsList'): | |
|
1457 | pairs = kwargs['crosspairsList'] | |
|
1458 | else: | |
|
1459 | pairs = None | |
|
1460 | ||
|
1461 | if kwargs.has_key('correctFactor'): | |
|
1462 | correctFactor = kwargs['correctFactor'] | |
|
1463 | else: | |
|
1464 | correctFactor = 1 | |
|
1465 | ||
|
1466 | tau = dataOut.data_param | |
|
1467 | _lambda = dataOut.C/dataOut.frequency | |
|
1468 | pairsList = dataOut.pairsList | |
|
1469 | nChannels = dataOut.nChannels | |
|
1470 | ||
|
1471 | dataOut.winds = self.techniqueSA(pairs, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, absc, correctFactor) | |
|
1472 | dataOut.initUtcTime = dataOut.ltctime | |
|
1473 | dataOut.windsInterval = dataOut.timeInterval | |
|
1474 | ||
|
1475 | elif technique == 'Meteors': | |
|
1476 | dataOut.flagNoData = True | |
|
1477 | self.__dataReady = False | |
|
1478 | ||
|
1479 | if kwargs.has_key('nHours'): | |
|
1480 | nHours = kwargs['nHours'] | |
|
1481 | else: | |
|
1482 | nHours = 1 | |
|
1483 | ||
|
1484 | if kwargs.has_key('meteorsPerBin'): | |
|
1485 | meteorThresh = kwargs['meteorsPerBin'] | |
|
1486 | else: | |
|
1487 | meteorThresh = 6 | |
|
1488 | ||
|
1489 | if kwargs.has_key('hmin'): | |
|
1490 | hmin = kwargs['hmin'] | |
|
1491 | else: hmin = 70 | |
|
1492 | if kwargs.has_key('hmax'): | |
|
1493 | hmax = kwargs['hmax'] | |
|
1494 | else: hmax = 110 | |
|
1495 | ||
|
1496 | dataOut.windsInterval = nHours*3600 | |
|
1497 | ||
|
1498 | if self.__isConfig == False: | |
|
1499 | # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03) | |
|
1500 | #Get Initial LTC time | |
|
1501 | self.__initime = (dataOut.datatime.replace(minute = 0, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds() | |
|
1502 | self.__isConfig = True | |
|
1503 | ||
|
1504 | if self.__buffer == None: | |
|
1505 | self.__buffer = dataOut.data_param | |
|
1506 | self.__firstdata = copy.copy(dataOut) | |
|
1507 | ||
|
1508 | else: | |
|
1509 | self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param)) | |
|
1510 | ||
|
1511 | self.__checkTime(dataOut.ltctime, dataOut.paramInterval, dataOut.windsInterval) #Check if the buffer is ready | |
|
1512 | ||
|
1513 | if self.__dataReady: | |
|
1514 | dataOut.initUtcTime = self.__initime | |
|
1515 | self.__initime = self.__initime + dataOut.windsInterval #to erase time offset | |
|
1516 | ||
|
1517 | dataOut.winds, dataOut.heightRange = self.techniqueMeteors(self.__buffer, meteorThresh, hmin, hmax) | |
|
1518 | dataOut.flagNoData = False | |
|
1519 | self.__buffer = None | |
|
1520 | ||
|
1521 | return No newline at end of file |
@@ -0,0 +1,103 | |||
|
1 | # DIAS 19 Y 20 FEB 2014 | |
|
2 | # Comprobacion de Resultados DBS con SA | |
|
3 | ||
|
4 | import os, sys | |
|
5 | ||
|
6 | path = os.path.split(os.getcwd())[0] | |
|
7 | sys.path.append(path) | |
|
8 | ||
|
9 | from controller import * | |
|
10 | ||
|
11 | desc = "JASMET Experiment Test" | |
|
12 | filename = "JASMETtest.xml" | |
|
13 | ||
|
14 | controllerObj = Project() | |
|
15 | ||
|
16 | controllerObj.setup(id = '191', name='test01', description=desc) | |
|
17 | ||
|
18 | #Experimentos | |
|
19 | ||
|
20 | #2014051 20 Feb 2014 | |
|
21 | path = '/home/soporte/Data/JASMET/JASMET_30/2014106' | |
|
22 | pathFigure = '/home/soporte/workspace/Graficos/JASMET/prueba1' | |
|
23 | ||
|
24 | startTime = '00:00:00' | |
|
25 | endTime = '23:59:59' | |
|
26 | xmin ='19.0' | |
|
27 | xmax = '34.0' | |
|
28 | ||
|
29 | #------------------------------------------------------------------------------------------------ | |
|
30 | readUnitConfObj = controllerObj.addReadUnit(datatype='VoltageReader', | |
|
31 | path=path, | |
|
32 | startDate='2014/04/15', | |
|
33 | endDate='2014/04/16', | |
|
34 | startTime=startTime, | |
|
35 | endTime=endTime, | |
|
36 | online=0, | |
|
37 | delay=5, | |
|
38 | walk=0) | |
|
39 | ||
|
40 | opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock') | |
|
41 | ||
|
42 | ||
|
43 | #-------------------------------------------------------------------------------------------------- | |
|
44 | ||
|
45 | procUnitConfObj0 = controllerObj.addProcUnit(datatype='VoltageProc', inputId=readUnitConfObj.getId()) | |
|
46 | ||
|
47 | opObj00 = procUnitConfObj0.addOperation(name='selectChannels') | |
|
48 | opObj00.addParameter(name='channelList', value='0, 1, 2, 3, 4', format='intlist') | |
|
49 | ||
|
50 | opObj01 = procUnitConfObj0.addOperation(name='setRadarFrequency') | |
|
51 | opObj01.addParameter(name='frequency', value='30.e6', format='float') | |
|
52 | ||
|
53 | #opObj11 = procUnitConfObj0.addOperation(name='Decoder', optype='other') | |
|
54 | #-------------------------------------------------------------------------------------------------- | |
|
55 | ||
|
56 | procUnitConfObj1 = controllerObj.addProcUnit(datatype='ParametersProc', inputId=procUnitConfObj0.getId()) | |
|
57 | procUnitConfObj1.addParameter(name='nSeconds', value='100', format='int') | |
|
58 | ||
|
59 | opObj10 = procUnitConfObj1.addOperation(name='DetectMeteors') | |
|
60 | opObj10.addParameter(name='predefinedPhaseShifts', value='-89.5, 41.5, 0.0, -138.0, -85.5', format='floatlist') | |
|
61 | opObj10.addParameter(name='cohDetection', value='0', format='bool') | |
|
62 | opObj10.addParameter(name='noise_multiple', value='4', format='int') | |
|
63 | opObj10.addParameter(name='SNRThresh', value='5', format='float') | |
|
64 | opObj10.addParameter(name='phaseThresh', value='20', format='float') | |
|
65 | opObj10.addParameter(name='azimuth', value='45', format='float') | |
|
66 | opObj10.addParameter(name='hmin', value='68', format='float') | |
|
67 | opObj10.addParameter(name='hmax', value='112', format='float') | |
|
68 | ||
|
69 | opObj13 = procUnitConfObj1.addOperation(name='SkyMapPlot', optype='other') | |
|
70 | opObj13.addParameter(name='id', value='1', format='int') | |
|
71 | opObj13.addParameter(name='wintitle', value='Sky Map', format='str') | |
|
72 | opObj13.addParameter(name='save', value='1', format='bool') | |
|
73 | opObj13.addParameter(name='figpath', value=pathFigure, format='str') | |
|
74 | ||
|
75 | opObj11 = procUnitConfObj1.addOperation(name='WindProfiler', optype='other') | |
|
76 | opObj11.addParameter(name='technique', value='Meteors', format='str') | |
|
77 | opObj11.addParameter(name='nHours', value='1.0', format='float') | |
|
78 | opObj11.addParameter(name='SNRThresh', value='12.0', format='float') | |
|
79 | ||
|
80 | opObj12 = procUnitConfObj1.addOperation(name='WindProfilerPlot', optype='other') | |
|
81 | opObj12.addParameter(name='id', value='2', format='int') | |
|
82 | opObj12.addParameter(name='wintitle', value='Wind Profiler', format='str') | |
|
83 | opObj12.addParameter(name='save', value='1', format='bool') | |
|
84 | opObj12.addParameter(name='figpath', value = pathFigure, format='str') | |
|
85 | opObj12.addParameter(name='zmin', value='-120', format='int') | |
|
86 | opObj12.addParameter(name='zmax', value='120', format='int') | |
|
87 | # opObj12.addParameter(name='zmin_ver', value='-0.8', format='float') | |
|
88 | # opObj12.addParameter(name='zmax_ver', value='0.8', format='float') | |
|
89 | # opObj23.addParameter(name='SNRmin', value='-10', format='int') | |
|
90 | # opObj23.addParameter(name='SNRmax', value='60', format='int') | |
|
91 | # opObj23.addParameter(name='SNRthresh', value='0', format='float') | |
|
92 | opObj12.addParameter(name='xmin', value=xmin, format='float') | |
|
93 | opObj12.addParameter(name='xmax', value=xmax, format='float') | |
|
94 | ||
|
95 | #-------------------------------------------------------------------------------------------------- | |
|
96 | print "Escribiendo el archivo XML" | |
|
97 | controllerObj.writeXml(filename) | |
|
98 | print "Leyendo el archivo XML" | |
|
99 | controllerObj.readXml(filename) | |
|
100 | ||
|
101 | controllerObj.createObjects() | |
|
102 | controllerObj.connectObjects() | |
|
103 | controllerObj.run() No newline at end of file |
@@ -0,0 +1,105 | |||
|
1 | # DIAS 19 Y 20 FEB 2014 | |
|
2 | # Comprobacion de Resultados DBS con SA | |
|
3 | ||
|
4 | import os, sys | |
|
5 | ||
|
6 | path = os.path.split(os.getcwd())[0] | |
|
7 | sys.path.append(path) | |
|
8 | ||
|
9 | from controller import * | |
|
10 | ||
|
11 | desc = "JASMET Experiment Test" | |
|
12 | filename = "JASMETtest.xml" | |
|
13 | ||
|
14 | controllerObj = Project() | |
|
15 | ||
|
16 | controllerObj.setup(id = '191', name='test01', description=desc) | |
|
17 | ||
|
18 | #Experimentos | |
|
19 | ||
|
20 | #2014051 20 Feb 2014 | |
|
21 | path = '/home/soporte/Data/JASMET/JASMET_50/2014106' | |
|
22 | pathFigure = '/home/soporte/workspace/Graficos/JASMET' | |
|
23 | ||
|
24 | startTime = '00:00:00' | |
|
25 | endTime = '23:59:59' | |
|
26 | xmin ='19.0' | |
|
27 | xmax = '33.0' | |
|
28 | ||
|
29 | ||
|
30 | #------------------------------------------------------------------------------------------------ | |
|
31 | readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage', | |
|
32 | path=path, | |
|
33 | startDate='2014/04/15', | |
|
34 | endDate='2014/04/16', | |
|
35 | startTime=startTime, | |
|
36 | endTime=endTime, | |
|
37 | online=0, | |
|
38 | delay=5, | |
|
39 | walk=0) | |
|
40 | ||
|
41 | opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock') | |
|
42 | ||
|
43 | ||
|
44 | #-------------------------------------------------------------------------------------------------- | |
|
45 | ||
|
46 | procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) | |
|
47 | ||
|
48 | opObj00 = procUnitConfObj0.addOperation(name='selectChannels') | |
|
49 | opObj00.addParameter(name='channelList', value='0, 1, 2, 3, 4', format='intlist') | |
|
50 | ||
|
51 | opObj01 = procUnitConfObj0.addOperation(name='setRadarFrequency') | |
|
52 | opObj01.addParameter(name='frequency', value='50.e6', format='float') | |
|
53 | ||
|
54 | #opObj11 = procUnitConfObj0.addOperation(name='Decoder', optype='other') | |
|
55 | #-------------------------------------------------------------------------------------------------- | |
|
56 | ||
|
57 | procUnitConfObj1 = controllerObj.addProcUnit(datatype='Parameters', inputId=procUnitConfObj0.getId()) | |
|
58 | procUnitConfObj1.addParameter(name='nSeconds', value='100', format='int') | |
|
59 | ||
|
60 | opObj10 = procUnitConfObj1.addOperation(name='DetectMeteors') | |
|
61 | opObj10.addParameter(name='predefinedPhaseShifts', value='-17.0, -139.0, 0.0, 48.0, -130.0', format='floatlist') | |
|
62 | opObj10.addParameter(name='cohDetection', value='0', format='bool') | |
|
63 | opObj10.addParameter(name='noise_multiple', value='4', format='int') | |
|
64 | opObj10.addParameter(name='SNRThresh', value='5', format='float') | |
|
65 | opObj10.addParameter(name='phaseThresh', value='20', format='float') | |
|
66 | opObj10.addParameter(name='azimuth', value='45', format='float') | |
|
67 | opObj10.addParameter(name='hmin', value='68', format='float') | |
|
68 | opObj10.addParameter(name='hmax', value='112', format='float') | |
|
69 | opObj10.addParameter(name='savefile', value='1', format='bool') | |
|
70 | opObj10.addParameter(name='filename', value=filehdf5, format='str') | |
|
71 | ||
|
72 | opObj13 = procUnitConfObj1.addOperation(name='SkyMapPlot', optype='other') | |
|
73 | opObj13.addParameter(name='id', value='1', format='int') | |
|
74 | opObj13.addParameter(name='wintitle', value='Sky Map', format='str') | |
|
75 | opObj13.addParameter(name='save', value='1', format='bool') | |
|
76 | opObj13.addParameter(name='figpath', value=pathFigure, format='str') | |
|
77 | ||
|
78 | opObj11 = procUnitConfObj1.addOperation(name='WindProfiler', optype='other') | |
|
79 | opObj11.addParameter(name='technique', value='Meteors', format='str') | |
|
80 | opObj11.addParameter(name='nHours', value='1.0', format='float') | |
|
81 | ||
|
82 | opObj12 = procUnitConfObj1.addOperation(name='WindProfilerPlot', optype='other') | |
|
83 | opObj12.addParameter(name='id', value='2', format='int') | |
|
84 | opObj12.addParameter(name='wintitle', value='Wind Profiler', format='str') | |
|
85 | opObj12.addParameter(name='save', value='1', format='bool') | |
|
86 | opObj12.addParameter(name='figpath', value = pathFigure, format='str') | |
|
87 | opObj12.addParameter(name='zmin', value='-120', format='int') | |
|
88 | opObj12.addParameter(name='zmax', value='120', format='int') | |
|
89 | # opObj12.addParameter(name='zmin_ver', value='-0.8', format='float') | |
|
90 | # opObj12.addParameter(name='zmax_ver', value='0.8', format='float') | |
|
91 | # opObj23.addParameter(name='SNRmin', value='-10', format='int') | |
|
92 | # opObj23.addParameter(name='SNRmax', value='60', format='int') | |
|
93 | # opObj23.addParameter(name='SNRthresh', value='0', format='float') | |
|
94 | opObj12.addParameter(name='xmin', value=xmin, format='float') | |
|
95 | opObj12.addParameter(name='xmax', value=xmax, format='float') | |
|
96 | ||
|
97 | #-------------------------------------------------------------------------------------------------- | |
|
98 | print "Escribiendo el archivo XML" | |
|
99 | controllerObj.writeXml(filename) | |
|
100 | print "Leyendo el archivo XML" | |
|
101 | controllerObj.readXml(filename) | |
|
102 | ||
|
103 | controllerObj.createObjects() | |
|
104 | controllerObj.connectObjects() | |
|
105 | controllerObj.run() No newline at end of file |
@@ -0,0 +1,144 | |||
|
1 | # DIAS 19 Y 20 FEB 2014 | |
|
2 | # Comprobacion de Resultados DBS con SA | |
|
3 | ||
|
4 | import os, sys | |
|
5 | ||
|
6 | path = os.path.split(os.getcwd())[0] | |
|
7 | sys.path.append(path) | |
|
8 | ||
|
9 | from controller import * | |
|
10 | ||
|
11 | desc = "DBS Experiment Test" | |
|
12 | filename = "DBStest.xml" | |
|
13 | ||
|
14 | controllerObj = Project() | |
|
15 | ||
|
16 | controllerObj.setup(id = '191', name='test01', description=desc) | |
|
17 | ||
|
18 | #Experimentos | |
|
19 | ||
|
20 | #2014050 19 Feb 2014 | |
|
21 | # path = '/home/soporte/Documents/MST_Data/DBS/d2014050' | |
|
22 | # pathFigure = '/home/soporte/workspace/Graficos/DBS/d2014050p/' | |
|
23 | # xmin = '15.5' | |
|
24 | # xmax = '23.99999999' | |
|
25 | # startTime = '17:25:00' | |
|
26 | # filehdf5 = "DBS_2014050.hdf5" | |
|
27 | ||
|
28 | #2014051 20 Feb 2014 | |
|
29 | path = '/home/soporte/Data/MST/DBS/d2014051' | |
|
30 | pathFigure = '/home/soporte/workspace/Graficos/DBS/prueba1/' | |
|
31 | xmin = '0.0' | |
|
32 | xmax = '8.0' | |
|
33 | startTime = '00:00:00' | |
|
34 | filehdf5 = "DBS_2014051.hdf5" | |
|
35 | ||
|
36 | ||
|
37 | ||
|
38 | #------------------------------------------------------------------------------------------------ | |
|
39 | readUnitConfObj = controllerObj.addReadUnit(datatype='VoltageReader', | |
|
40 | path=path, | |
|
41 | startDate='2014/01/31', | |
|
42 | endDate='2014/03/31', | |
|
43 | startTime=startTime, | |
|
44 | endTime='23:59:59', | |
|
45 | online=0, | |
|
46 | delay=5, | |
|
47 | walk=0) | |
|
48 | ||
|
49 | opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock') | |
|
50 | ||
|
51 | ||
|
52 | #-------------------------------------------------------------------------------------------------- | |
|
53 | ||
|
54 | procUnitConfObj0 = controllerObj.addProcUnit(datatype='VoltageProc', inputId=readUnitConfObj.getId()) | |
|
55 | ||
|
56 | opObj11 = procUnitConfObj0.addOperation(name='Decoder', optype='other') | |
|
57 | ||
|
58 | opObj11 = procUnitConfObj0.addOperation(name='CohInt', optype='other') | |
|
59 | opObj11.addParameter(name='n', value='256', format='int') | |
|
60 | # opObj11.addParameter(name='n', value='16', format='int') | |
|
61 | ||
|
62 | opObj11 = procUnitConfObj0.addOperation(name='selectHeightsByIndex') | |
|
63 | opObj11.addParameter(name='minIndex', value='10', format='float') | |
|
64 | opObj11.addParameter(name='maxIndex', value='60', format='float') | |
|
65 | ||
|
66 | #--------------------------------------------------------------------------------------------------- | |
|
67 | ||
|
68 | procUnitConfObj1 = controllerObj.addProcUnit(datatype='SpectraProc', inputId=procUnitConfObj0.getId()) | |
|
69 | procUnitConfObj1.addParameter(name='nFFTPoints', value='64', format='int') | |
|
70 | procUnitConfObj1.addParameter(name='nProfiles', value='64', format='int') | |
|
71 | # procUnitConfObj1.addParameter(name='ippFactor', value='2', format='int') | |
|
72 | procUnitConfObj1.addParameter(name='pairsList', value='(0,0),(0,1),(2,1)', format='pairsList') | |
|
73 | ||
|
74 | opObj11 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') | |
|
75 | opObj11.addParameter(name='n', value='5', format='int') | |
|
76 | ||
|
77 | opObj14 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') | |
|
78 | opObj14.addParameter(name='id', value='1', format='int') | |
|
79 | opObj14.addParameter(name='wintitle', value='Con interf', format='str') | |
|
80 | opObj14.addParameter(name='save', value='1', format='bool') | |
|
81 | opObj14.addParameter(name='figpath', value=pathFigure, format='str') | |
|
82 | opObj14.addParameter(name='zmin', value='5', format='int') | |
|
83 | opObj14.addParameter(name='zmax', value='90', format='int') | |
|
84 | ||
|
85 | opObj12 = procUnitConfObj1.addOperation(name='removeInterference') | |
|
86 | opObj13 = procUnitConfObj1.addOperation(name='removeDC') | |
|
87 | opObj13.addParameter(name='mode', value='1', format='int') | |
|
88 | ||
|
89 | opObj12 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other') | |
|
90 | opObj12.addParameter(name='id', value='2', format='int') | |
|
91 | opObj12.addParameter(name='wintitle', value='RTI Plot', format='str') | |
|
92 | opObj12.addParameter(name='save', value='1', format='bool') | |
|
93 | opObj12.addParameter(name='figpath', value = pathFigure, format='str') | |
|
94 | opObj12.addParameter(name='xmin', value=xmin, format='float') | |
|
95 | opObj12.addParameter(name='xmax', value=xmax, format='float') | |
|
96 | opObj12.addParameter(name='zmin', value='5', format='int') | |
|
97 | opObj12.addParameter(name='zmax', value='90', format='int') | |
|
98 | ||
|
99 | #-------------------------------------------------------------------------------------------------- | |
|
100 | ||
|
101 | procUnitConfObj2 = controllerObj.addProcUnit(datatype='ParametersProc', inputId=procUnitConfObj1.getId()) | |
|
102 | opObj20 = procUnitConfObj2.addOperation(name='GetMoments') | |
|
103 | ||
|
104 | opObj21 = procUnitConfObj2.addOperation(name='MomentsPlot', optype='other') | |
|
105 | opObj21.addParameter(name='id', value='3', format='int') | |
|
106 | opObj21.addParameter(name='wintitle', value='Moments Plot', format='str') | |
|
107 | opObj21.addParameter(name='save', value='1', format='bool') | |
|
108 | opObj21.addParameter(name='figpath', value=pathFigure, format='str') | |
|
109 | opObj21.addParameter(name='zmin', value='5', format='int') | |
|
110 | opObj21.addParameter(name='zmax', value='90', format='int') | |
|
111 | ||
|
112 | opObj22 = procUnitConfObj2.addOperation(name='WindProfiler', optype='other') | |
|
113 | opObj22.addParameter(name='technique', value='DBS', format='str') | |
|
114 | opObj22.addParameter(name='azimuth', value='51.06', format='float') | |
|
115 | opObj22.addParameter(name='correctFactor', value='-1', format='float') | |
|
116 | opObj22.addParameter(name='dirCosx', value='0.041016, 0, -0.054688', format='floatlist') | |
|
117 | opObj22.addParameter(name='dirCosy', value='-0.041016, 0.025391, -0.023438', format='floatlist') | |
|
118 | # opObj22.addParameter(name='horizontalOnly', value='1', format='bool') | |
|
119 | # opObj22.addParameter(name='channelList', value='1,2', format='intlist') | |
|
120 | ||
|
121 | opObj23 = procUnitConfObj2.addOperation(name='WindProfilerPlot', optype='other') | |
|
122 | opObj23.addParameter(name='id', value='4', format='int') | |
|
123 | opObj23.addParameter(name='wintitle', value='Wind Profiler', format='str') | |
|
124 | opObj23.addParameter(name='save', value='1', format='bool') | |
|
125 | opObj23.addParameter(name='figpath', value = pathFigure, format='str') | |
|
126 | opObj23.addParameter(name='zmin', value='-10', format='int') | |
|
127 | opObj23.addParameter(name='zmax', value='10', format='int') | |
|
128 | opObj23.addParameter(name='zmin_ver', value='-80', format='float') | |
|
129 | opObj23.addParameter(name='zmax_ver', value='80', format='float') | |
|
130 | opObj23.addParameter(name='SNRmin', value='-10', format='int') | |
|
131 | opObj23.addParameter(name='SNRmax', value='60', format='int') | |
|
132 | opObj23.addParameter(name='SNRthresh', value='0', format='float') | |
|
133 | opObj23.addParameter(name='xmin', value=xmin, format='float') | |
|
134 | opObj23.addParameter(name='xmax', value=xmax, format='float') | |
|
135 | ||
|
136 | #-------------------------------------------------------------------------------------------------- | |
|
137 | print "Escribiendo el archivo XML" | |
|
138 | controllerObj.writeXml(filename) | |
|
139 | print "Leyendo el archivo XML" | |
|
140 | controllerObj.readXml(filename) | |
|
141 | ||
|
142 | controllerObj.createObjects() | |
|
143 | controllerObj.connectObjects() | |
|
144 | controllerObj.run() No newline at end of file |
@@ -0,0 +1,139 | |||
|
1 | # DIAS 19 Y 20 FEB 2014 | |
|
2 | # Comprobacion de Resultados DBS con SA | |
|
3 | ||
|
4 | import os, sys | |
|
5 | ||
|
6 | path = os.path.split(os.getcwd())[0] | |
|
7 | sys.path.append(path) | |
|
8 | ||
|
9 | from controller import * | |
|
10 | ||
|
11 | desc = "SA Experiment Test" | |
|
12 | filename = "SA2014050.xml" | |
|
13 | ||
|
14 | controllerObj = Project() | |
|
15 | ||
|
16 | controllerObj.setup(id = '191', name='test01', description=desc) | |
|
17 | ||
|
18 | ||
|
19 | #Experimentos | |
|
20 | ||
|
21 | #2014050 19 Feb 2014 | |
|
22 | # path = '/home/soporte/Documents/MST_Data/SA/d2014050' | |
|
23 | # pathFigure = '/home/soporte/workspace/Graficos/SA/d2014050_prueba/' | |
|
24 | # xmin = '15.5' | |
|
25 | # xmax = '23.99999999' | |
|
26 | # startTime = '15:30:00' | |
|
27 | # filehdf5 = "SA_2014050.hdf5" | |
|
28 | ||
|
29 | #2014051 20 Feb 2014 | |
|
30 | path = '/home/soporte/Data/MST/SA/d2014051' | |
|
31 | pathFigure = '/home/soporte/workspace/Graficos/SA/prueba1/' | |
|
32 | xmin = '0.0' | |
|
33 | xmax = '8.0' | |
|
34 | startTime = '06:00:00' | |
|
35 | filehdf5 = "SA_2014051.hdf5" | |
|
36 | ||
|
37 | readUnitConfObj = controllerObj.addReadUnit(datatype='VoltageReader', | |
|
38 | path=path, | |
|
39 | startDate='2014/01/01', | |
|
40 | endDate='2014/03/31', | |
|
41 | startTime=startTime, | |
|
42 | endTime='23:59:59', | |
|
43 | online=0, | |
|
44 | delay=5, | |
|
45 | walk=0) | |
|
46 | ||
|
47 | opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock') | |
|
48 | ||
|
49 | ||
|
50 | #-------------------------------------------------------------------------------------------------- | |
|
51 | ||
|
52 | procUnitConfObj0 = controllerObj.addProcUnit(datatype='VoltageProc', inputId=readUnitConfObj.getId()) | |
|
53 | ||
|
54 | opObj11 = procUnitConfObj0.addOperation(name='Decoder', optype='other') | |
|
55 | ||
|
56 | opObj11 = procUnitConfObj0.addOperation(name='CohInt', optype='other') | |
|
57 | opObj11.addParameter(name='n', value='600', format='int') | |
|
58 | # opObj11.addParameter(name='n', value='10', format='int') | |
|
59 | ||
|
60 | opObj11 = procUnitConfObj0.addOperation(name='selectHeightsByIndex') | |
|
61 | opObj11.addParameter(name='minIndex', value='10', format='float') | |
|
62 | opObj11.addParameter(name='maxIndex', value='60', format='float') | |
|
63 | #--------------------------------------------------------------------------------------------------- | |
|
64 | procUnitConfObj1 = controllerObj.addProcUnit(datatype='CorrelationProc', inputId=procUnitConfObj0.getId()) | |
|
65 | # procUnitConfObj1.addParameter(name='pairsList', value='(0,0),(1,1),(2,2),(3,3),(1,0),(2,3)', format='pairsList') | |
|
66 | procUnitConfObj1.addParameter(name='pairsList', value='(0,0),(1,1),(2,2),(3,3),(0,3),(0,2),(1,3),(1,2)', format='pairsList') | |
|
67 | procUnitConfObj1.addParameter(name='fullT', value='1', format='bool') | |
|
68 | procUnitConfObj1.addParameter(name='removeDC', value='1', format='bool') | |
|
69 | #procUnitConfObj1.addParameter(name='lagT', value='0,1,2,3', format='intlist') | |
|
70 | ||
|
71 | opObj12 = procUnitConfObj1.addOperation(name='CorrelationPlot', optype='other') | |
|
72 | opObj12.addParameter(name='id', value='1', format='int') | |
|
73 | opObj12.addParameter(name='wintitle', value='CrossCorrelation Plot', format='str') | |
|
74 | opObj12.addParameter(name='save', value='1', format='bool') | |
|
75 | opObj12.addParameter(name='zmin', value='0', format='int') | |
|
76 | opObj12.addParameter(name='zmax', value='1', format='int') | |
|
77 | opObj12.addParameter(name='figpath', value = pathFigure, format='str') | |
|
78 | ||
|
79 | opObj12 = procUnitConfObj1.addOperation(name='removeNoise') | |
|
80 | opObj12.addParameter(name='mode', value='2', format='int') | |
|
81 | opObj12 = procUnitConfObj1.addOperation(name='calculateNormFactor') | |
|
82 | ||
|
83 | opObj12 = procUnitConfObj1.addOperation(name='CorrelationPlot', optype='other') | |
|
84 | opObj12.addParameter(name='id', value='2', format='int') | |
|
85 | opObj12.addParameter(name='wintitle', value='CrossCorrelation Plot', format='str') | |
|
86 | opObj12.addParameter(name='save', value='1', format='bool') | |
|
87 | opObj12.addParameter(name='zmin', value='0', format='int') | |
|
88 | opObj12.addParameter(name='zmax', value='1', format='int') | |
|
89 | opObj12.addParameter(name='figpath', value = pathFigure, format='str') | |
|
90 | ||
|
91 | #--------------------------------------------------------------------------------------------------- | |
|
92 | procUnitConfObj2 = controllerObj.addProcUnit(datatype='ParametersProc', inputId=procUnitConfObj1.getId()) | |
|
93 | opObj20 = procUnitConfObj2.addOperation(name='GetLags') | |
|
94 | ||
|
95 | opObj21 = procUnitConfObj2.addOperation(name='WindProfiler', optype='other') | |
|
96 | opObj21.addParameter(name='technique', value='SA', format='str') | |
|
97 | # opObj21.addParameter(name='correctFactor', value='-1', format='float') | |
|
98 | opObj21.addParameter(name='positionX', value='36,0,36,0', format='floatlist') | |
|
99 | opObj21.addParameter(name='positionY', value='36,0,0,36', format='floatlist') | |
|
100 | opObj21.addParameter(name='azimuth', value='51.06', format='float') | |
|
101 | opObj21.addParameter(name='crosspairsList', value='(0,3),(0,2),(1,3),(1,2)', format='pairsList')#COrregir | |
|
102 | # | |
|
103 | opObj22 = procUnitConfObj2.addOperation(name='WindProfilerPlot', optype='other') | |
|
104 | opObj22.addParameter(name='id', value='4', format='int') | |
|
105 | opObj22.addParameter(name='wintitle', value='Wind Profiler', format='str') | |
|
106 | opObj22.addParameter(name='save', value='1', format='bool') | |
|
107 | opObj22.addParameter(name='figpath', value = pathFigure, format='str') | |
|
108 | opObj22.addParameter(name='zmin', value='-15', format='int') | |
|
109 | opObj22.addParameter(name='zmax', value='15', format='int') | |
|
110 | opObj22.addParameter(name='zmin_ver', value='-80', format='float') | |
|
111 | opObj22.addParameter(name='zmax_ver', value='80', format='float') | |
|
112 | opObj22.addParameter(name='SNRmin', value='-20', format='int') | |
|
113 | opObj22.addParameter(name='SNRmax', value='40', format='int') | |
|
114 | opObj22.addParameter(name='SNRthresh', value='-3.5', format='float') | |
|
115 | opObj22.addParameter(name='xmin', value=xmin, format='float') | |
|
116 | opObj22.addParameter(name='xmax', value=xmax, format='float') | |
|
117 | # #----------------------------------------------------------------------------------- | |
|
118 | # | |
|
119 | # procUnitConfObj2 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId()) | |
|
120 | # procUnitConfObj2.addParameter(name='nFFTPoints', value='128', format='int') | |
|
121 | # procUnitConfObj2.addParameter(name='nProfiles', value='128', format='int') | |
|
122 | # procUnitConfObj2.addParameter(name='pairsList', value='(0,0),(0,1),(2,1)', format='pairsList') | |
|
123 | # | |
|
124 | # opObj22 = procUnitConfObj2.addOperation(name='SpectraPlot', optype='other') | |
|
125 | # opObj22.addParameter(name='id', value='5', format='int') | |
|
126 | # opObj22.addParameter(name='wintitle', value='Spectra Plot', format='str') | |
|
127 | # opObj22.addParameter(name='save', value='1', format='bool') | |
|
128 | # opObj22.addParameter(name='figpath', value = pathFigure, format='str') | |
|
129 | ||
|
130 | #----------------------------------------------------------------------------------- | |
|
131 | ||
|
132 | print "Escribiendo el archivo XML" | |
|
133 | controllerObj.writeXml(filename) | |
|
134 | print "Leyendo el archivo XML" | |
|
135 | controllerObj.readXml(filename) | |
|
136 | ||
|
137 | controllerObj.createObjects() | |
|
138 | controllerObj.connectObjects() | |
|
139 | controllerObj.run() No newline at end of file |
@@ -0,0 +1,131 | |||
|
1 | import os, sys | |
|
2 | ||
|
3 | path = os.path.split(os.getcwd())[0] | |
|
4 | sys.path.append(path) | |
|
5 | ||
|
6 | from controller import * | |
|
7 | ||
|
8 | desc = "AMISR Experiment" | |
|
9 | ||
|
10 | filename = "amisr_reader.xml" | |
|
11 | ||
|
12 | controllerObj = Project() | |
|
13 | ||
|
14 | controllerObj.setup(id = '191', name='test01', description=desc) | |
|
15 | ||
|
16 | ||
|
17 | path = os.path.join(os.environ['HOME'],'Development/amisr/data') | |
|
18 | path = '/home/soporte/Data/AMISR' | |
|
19 | figpath = os.path.join(os.environ['HOME'],'Pictures/amisr') | |
|
20 | ||
|
21 | pathFigure = '/home/soporte/workspace/Graficos/DBS/amisr/' | |
|
22 | xmin = '12.0' | |
|
23 | xmax = '14.0' | |
|
24 | ||
|
25 | readUnitConfObj = controllerObj.addReadUnit(datatype='AMISRReader', | |
|
26 | path=path, | |
|
27 | startDate='2014/10/21', | |
|
28 | endDate='2014/10/21', | |
|
29 | startTime='00:00:00', | |
|
30 | endTime='23:59:59', | |
|
31 | walk=1, | |
|
32 | timezone='lt') | |
|
33 | ||
|
34 | #AMISR Processing Unit | |
|
35 | procUnitAMISRBeam0 = controllerObj.addProcUnit(datatype='AMISRProc', inputId=readUnitConfObj.getId()) | |
|
36 | ||
|
37 | opObj11 = procUnitAMISRBeam0.addOperation(name='PrintInfo', optype='other') | |
|
38 | ||
|
39 | #Reshaper | |
|
40 | opObj11 = procUnitAMISRBeam0.addOperation(name='ProfileToChannels', optype='other') | |
|
41 | ||
|
42 | ||
|
43 | #Beam Selector | |
|
44 | #opObj11 = procUnitAMISRBeam0.addOperation(name='BeamSelector', optype='other') | |
|
45 | #opObj11.addParameter(name='beam', value='0', format='int') | |
|
46 | ||
|
47 | #Voltage Processing Unit | |
|
48 | procUnitConfObjBeam0 = controllerObj.addProcUnit(datatype='VoltageProc', inputId=procUnitAMISRBeam0.getId()) | |
|
49 | #Coherent Integration | |
|
50 | opObj11 = procUnitConfObjBeam0.addOperation(name='CohInt', optype='other') | |
|
51 | opObj11.addParameter(name='n', value='8', format='int') | |
|
52 | #Spectra Unit Processing, getting spectras with nProfiles and nFFTPoints | |
|
53 | procUnitConfObjSpectraBeam0 = controllerObj.addProcUnit(datatype='SpectraProc', inputId=procUnitConfObjBeam0.getId()) | |
|
54 | procUnitConfObjSpectraBeam0.addParameter(name='nFFTPoints', value=32, format='int') | |
|
55 | procUnitConfObjSpectraBeam0.addParameter(name='nProfiles', value=32, format='int') | |
|
56 | #RemoveDc | |
|
57 | opObj11 = procUnitConfObjSpectraBeam0.addOperation(name='removeDC') | |
|
58 | ||
|
59 | #Noise Estimation | |
|
60 | opObj11 = procUnitConfObjSpectraBeam0.addOperation(name='getNoise') | |
|
61 | opObj11.addParameter(name='minHei', value='5', format='float') | |
|
62 | opObj11.addParameter(name='maxHei', value='20', format='float') | |
|
63 | ||
|
64 | #SpectraPlot | |
|
65 | opObj11 = procUnitConfObjSpectraBeam0.addOperation(name='SpectraPlot', optype='other') | |
|
66 | opObj11.addParameter(name='id', value='100', format='int') | |
|
67 | opObj11.addParameter(name='wintitle', value='AMISR Beam 0', format='str') | |
|
68 | opObj11.addParameter(name='zmin', value='30', format='int') | |
|
69 | opObj11.addParameter(name='zmax', value='80', format='int') | |
|
70 | ||
|
71 | #RTIPlot | |
|
72 | #title0 = 'RTI AMISR Beam 0' | |
|
73 | #opObj11 = procUnitConfObjSpectraBeam0.addOperation(name='RTIPlot', optype='other') | |
|
74 | #opObj11.addParameter(name='id', value='200', format='int') | |
|
75 | #opObj11.addParameter(name='wintitle', value=title0, format='str') | |
|
76 | #opObj11.addParameter(name='showprofile', value='0', format='int') | |
|
77 | ##Setting RTI time using xmin,xmax | |
|
78 | #opObj11.addParameter(name='xmin', value='15', format='int') | |
|
79 | #opObj11.addParameter(name='xmax', value='23', format='int') | |
|
80 | #Setting dB range with zmin, zmax | |
|
81 | #opObj11.addParameter(name='zmin', value='45', format='int') | |
|
82 | #opObj11.addParameter(name='zmax', value='70', format='int') | |
|
83 | #Save RTI | |
|
84 | #figfile0 = 'amisr_rti_beam0.png' | |
|
85 | #opObj11.addParameter(name='figpath', value=figpath, format='str') | |
|
86 | #opObj11.addParameter(name='figfile', value=figfile0, format='str') | |
|
87 | ||
|
88 | #----------------------------------------------------------------------------------------------- | |
|
89 | procUnitConfObj2 = controllerObj.addProcUnit(datatype='ParametersProc', inputId=procUnitConfObjSpectraBeam0 .getId()) | |
|
90 | opObj20 = procUnitConfObj2.addOperation(name='GetMoments') | |
|
91 | ||
|
92 | # opObj21 = procUnitConfObj2.addOperation(name='MomentsPlot', optype='other') | |
|
93 | # opObj21.addParameter(name='id', value='3', format='int') | |
|
94 | # opObj21.addParameter(name='wintitle', value='Moments Plot', format='str') | |
|
95 | # opObj21.addParameter(name='save', value='1', format='bool') | |
|
96 | # opObj21.addParameter(name='figpath', value=pathFigure, format='str') | |
|
97 | # opObj21.addParameter(name='zmin', value='5', format='int') | |
|
98 | # opObj21.addParameter(name='zmax', value='90', format='int') | |
|
99 | ||
|
100 | opObj22 = procUnitConfObj2.addOperation(name='WindProfiler', optype='other') | |
|
101 | opObj22.addParameter(name='technique', value='DBS', format='str') | |
|
102 | opObj22.addParameter(name='azimuth', value='51.06', format='float') | |
|
103 | opObj22.addParameter(name='correctFactor', value='-1', format='float') | |
|
104 | opObj22.addParameter(name='dirCosx', value='9.63770247e-01, 5.93066547e-17, 1, 5.93066547e-17,-9.68583161e-01', format='floatlist') | |
|
105 | opObj22.addParameter(name='dirCosy', value=' 0,-0.96858316,0,0.96858316,0', format='floatlist') | |
|
106 | # opObj22.addParameter(name='horizontalOnly', value='1', format='bool') | |
|
107 | # opObj22.addParameter(name='channelList', value='1,2', format='intlist') | |
|
108 | ||
|
109 | opObj23 = procUnitConfObj2.addOperation(name='WindProfilerPlot', optype='other') | |
|
110 | opObj23.addParameter(name='id', value='4', format='int') | |
|
111 | opObj23.addParameter(name='wintitle', value='Wind Profiler', format='str') | |
|
112 | opObj23.addParameter(name='save', value='1', format='bool') | |
|
113 | opObj23.addParameter(name='figpath', value = pathFigure, format='str') | |
|
114 | opObj23.addParameter(name='zmin', value='-10', format='int') | |
|
115 | opObj23.addParameter(name='zmax', value='10', format='int') | |
|
116 | opObj23.addParameter(name='zmin_ver', value='-80', format='float') | |
|
117 | opObj23.addParameter(name='zmax_ver', value='80', format='float') | |
|
118 | opObj23.addParameter(name='SNRmin', value='-10', format='int') | |
|
119 | opObj23.addParameter(name='SNRmax', value='60', format='int') | |
|
120 | opObj23.addParameter(name='SNRthresh', value='0', format='float') | |
|
121 | opObj23.addParameter(name='xmin', value=xmin, format='float') | |
|
122 | opObj23.addParameter(name='xmax', value=xmax, format='float') | |
|
123 | ||
|
124 | print "Escribiendo el archivo XML" | |
|
125 | controllerObj.writeXml(filename) | |
|
126 | print "Leyendo el archivo XML" | |
|
127 | controllerObj.readXml(filename) | |
|
128 | ||
|
129 | controllerObj.createObjects() | |
|
130 | controllerObj.connectObjects() | |
|
131 | controllerObj.run() |
@@ -1,746 +1,967 | |||
|
1 | 1 | ''' |
|
2 | 2 | |
|
3 | 3 | $Author: murco $ |
|
4 | 4 | $Id: JROData.py 173 2012-11-20 15:06:21Z murco $ |
|
5 | 5 | ''' |
|
6 | 6 | |
|
7 | 7 | import copy |
|
8 | 8 | import numpy |
|
9 | 9 | import datetime |
|
10 | 10 | |
|
11 | 11 | from jroheaderIO import SystemHeader, RadarControllerHeader |
|
12 | 12 | |
|
13 | 13 | def getNumpyDtype(dataTypeCode): |
|
14 | 14 | |
|
15 | 15 | if dataTypeCode == 0: |
|
16 | 16 | numpyDtype = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
17 | 17 | elif dataTypeCode == 1: |
|
18 | 18 | numpyDtype = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
19 | 19 | elif dataTypeCode == 2: |
|
20 | 20 | numpyDtype = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
21 | 21 | elif dataTypeCode == 3: |
|
22 | 22 | numpyDtype = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
23 | 23 | elif dataTypeCode == 4: |
|
24 | 24 | numpyDtype = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
25 | 25 | elif dataTypeCode == 5: |
|
26 | 26 | numpyDtype = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
27 | 27 | else: |
|
28 | 28 | raise ValueError, 'dataTypeCode was not defined' |
|
29 | 29 | |
|
30 | 30 | return numpyDtype |
|
31 | 31 | |
|
32 | 32 | def getDataTypeCode(numpyDtype): |
|
33 | 33 | |
|
34 | 34 | if numpyDtype == numpy.dtype([('real','<i1'),('imag','<i1')]): |
|
35 | 35 | datatype = 0 |
|
36 | 36 | elif numpyDtype == numpy.dtype([('real','<i2'),('imag','<i2')]): |
|
37 | 37 | datatype = 1 |
|
38 | 38 | elif numpyDtype == numpy.dtype([('real','<i4'),('imag','<i4')]): |
|
39 | 39 | datatype = 2 |
|
40 | 40 | elif numpyDtype == numpy.dtype([('real','<i8'),('imag','<i8')]): |
|
41 | 41 | datatype = 3 |
|
42 | 42 | elif numpyDtype == numpy.dtype([('real','<f4'),('imag','<f4')]): |
|
43 | 43 | datatype = 4 |
|
44 | 44 | elif numpyDtype == numpy.dtype([('real','<f8'),('imag','<f8')]): |
|
45 | 45 | datatype = 5 |
|
46 | 46 | else: |
|
47 | 47 | datatype = None |
|
48 | 48 | |
|
49 | 49 | return datatype |
|
50 | 50 | |
|
51 | 51 | def hildebrand_sekhon(data, navg): |
|
52 | 52 | |
|
53 | 53 | data = data.copy() |
|
54 | 54 | |
|
55 | 55 | sortdata = numpy.sort(data,axis=None) |
|
56 | 56 | lenOfData = len(sortdata) |
|
57 | 57 | nums_min = lenOfData/10 |
|
58 | 58 | |
|
59 | 59 | if (lenOfData/10) > 2: |
|
60 | 60 | nums_min = lenOfData/10 |
|
61 | 61 | else: |
|
62 | 62 | nums_min = 2 |
|
63 | 63 | |
|
64 | 64 | sump = 0. |
|
65 | 65 | |
|
66 | 66 | sumq = 0. |
|
67 | 67 | |
|
68 | 68 | j = 0 |
|
69 | 69 | |
|
70 | 70 | cont = 1 |
|
71 | 71 | |
|
72 | 72 | while((cont==1)and(j<lenOfData)): |
|
73 | 73 | |
|
74 | 74 | sump += sortdata[j] |
|
75 | 75 | |
|
76 | 76 | sumq += sortdata[j]**2 |
|
77 | 77 | |
|
78 | 78 | j += 1 |
|
79 | 79 | |
|
80 | 80 | if j > nums_min: |
|
81 | 81 | rtest = float(j)/(j-1) + 1.0/navg |
|
82 | 82 | if ((sumq*j) > (rtest*sump**2)): |
|
83 | 83 | j = j - 1 |
|
84 | 84 | sump = sump - sortdata[j] |
|
85 | 85 | sumq = sumq - sortdata[j]**2 |
|
86 | 86 | cont = 0 |
|
87 | 87 | |
|
88 | 88 | lnoise = sump /j |
|
89 | 89 | stdv = numpy.sqrt((sumq - lnoise**2)/(j - 1)) |
|
90 | 90 | return lnoise |
|
91 | 91 | |
|
92 | 92 | class Beam: |
|
93 | 93 | def __init__(self): |
|
94 | 94 | self.codeList = [] |
|
95 | 95 | self.azimuthList = [] |
|
96 | 96 | self.zenithList = [] |
|
97 | 97 | |
|
98 | 98 | class GenericData(object): |
|
99 | 99 | |
|
100 | 100 | flagNoData = True |
|
101 | 101 | |
|
102 | 102 | def __init__(self): |
|
103 | 103 | |
|
104 | 104 | raise ValueError, "This class has not been implemented" |
|
105 | 105 | |
|
106 | 106 | def copy(self, inputObj=None): |
|
107 | 107 | |
|
108 | 108 | if inputObj == None: |
|
109 | 109 | return copy.deepcopy(self) |
|
110 | 110 | |
|
111 | 111 | for key in inputObj.__dict__.keys(): |
|
112 | 112 | self.__dict__[key] = inputObj.__dict__[key] |
|
113 | 113 | |
|
114 | 114 | def deepcopy(self): |
|
115 | 115 | |
|
116 | 116 | return copy.deepcopy(self) |
|
117 | 117 | |
|
118 | 118 | def isEmpty(self): |
|
119 | 119 | |
|
120 | 120 | return self.flagNoData |
|
121 | 121 | |
|
122 | 122 | class JROData(GenericData): |
|
123 | 123 | |
|
124 | 124 | # m_BasicHeader = BasicHeader() |
|
125 | 125 | # m_ProcessingHeader = ProcessingHeader() |
|
126 | 126 | |
|
127 | 127 | systemHeaderObj = SystemHeader() |
|
128 | 128 | |
|
129 | 129 | radarControllerHeaderObj = RadarControllerHeader() |
|
130 | 130 | |
|
131 | 131 | # data = None |
|
132 | 132 | |
|
133 | 133 | type = None |
|
134 | 134 | |
|
135 | 135 | datatype = None #dtype but in string |
|
136 | 136 | |
|
137 | 137 | # dtype = None |
|
138 | 138 | |
|
139 | 139 | # nChannels = None |
|
140 | 140 | |
|
141 | 141 | # nHeights = None |
|
142 | 142 | |
|
143 | 143 | nProfiles = None |
|
144 | 144 | |
|
145 | 145 | heightList = None |
|
146 | 146 | |
|
147 | 147 | channelList = None |
|
148 | 148 | |
|
149 | 149 | flagTimeBlock = False |
|
150 | 150 | |
|
151 | 151 | useLocalTime = False |
|
152 | 152 | |
|
153 | 153 | utctime = None |
|
154 | 154 | |
|
155 | 155 | timeZone = None |
|
156 | 156 | |
|
157 | 157 | dstFlag = None |
|
158 | 158 | |
|
159 | 159 | errorCount = None |
|
160 | 160 | |
|
161 | 161 | blocksize = None |
|
162 | 162 | |
|
163 | 163 | nCode = None |
|
164 | 164 | |
|
165 | 165 | nBaud = None |
|
166 | 166 | |
|
167 | 167 | code = None |
|
168 | 168 | |
|
169 | 169 | flagDecodeData = False #asumo q la data no esta decodificada |
|
170 | 170 | |
|
171 | 171 | flagDeflipData = False #asumo q la data no esta sin flip |
|
172 | 172 | |
|
173 | 173 | flagShiftFFT = False |
|
174 | 174 | |
|
175 | 175 | # ippSeconds = None |
|
176 | 176 | |
|
177 | 177 | timeInterval = None |
|
178 | 178 | |
|
179 | 179 | nCohInt = None |
|
180 | 180 | |
|
181 | 181 | noise = None |
|
182 | 182 | |
|
183 | 183 | windowOfFilter = 1 |
|
184 | 184 | |
|
185 | 185 | #Speed of ligth |
|
186 | 186 | C = 3e8 |
|
187 | 187 | |
|
188 | 188 | frequency = 49.92e6 |
|
189 | 189 | |
|
190 | 190 | realtime = False |
|
191 | 191 | |
|
192 | 192 | beacon_heiIndexList = None |
|
193 | 193 | |
|
194 | 194 | last_block = None |
|
195 | 195 | |
|
196 | 196 | blocknow = None |
|
197 | 197 | |
|
198 | 198 | azimuth = None |
|
199 | 199 | |
|
200 | 200 | zenith = None |
|
201 | 201 | |
|
202 | 202 | beam = Beam() |
|
203 | 203 | |
|
204 | 204 | def __init__(self): |
|
205 | 205 | |
|
206 | 206 | raise ValueError, "This class has not been implemented" |
|
207 | 207 | |
|
208 | 208 | def getNoise(self): |
|
209 | 209 | |
|
210 | 210 | raise ValueError, "Not implemented" |
|
211 | 211 | |
|
212 | 212 | def getNChannels(self): |
|
213 | 213 | |
|
214 | 214 | return len(self.channelList) |
|
215 | 215 | |
|
216 | 216 | def getChannelIndexList(self): |
|
217 | 217 | |
|
218 | 218 | return range(self.nChannels) |
|
219 | 219 | |
|
220 | 220 | def getNHeights(self): |
|
221 | 221 | |
|
222 | 222 | return len(self.heightList) |
|
223 | 223 | |
|
224 | 224 | def getHeiRange(self, extrapoints=0): |
|
225 | 225 | |
|
226 | 226 | heis = self.heightList |
|
227 | 227 | # deltah = self.heightList[1] - self.heightList[0] |
|
228 | 228 | # |
|
229 | 229 | # heis.append(self.heightList[-1]) |
|
230 | 230 | |
|
231 | 231 | return heis |
|
232 | 232 | |
|
233 | 233 | def getltctime(self): |
|
234 | 234 | |
|
235 | 235 | if self.useLocalTime: |
|
236 | 236 | return self.utctime - self.timeZone*60 |
|
237 | 237 | |
|
238 | 238 | return self.utctime |
|
239 | 239 | |
|
240 | 240 | def getDatatime(self): |
|
241 | 241 | |
|
242 | 242 | datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime) |
|
243 | 243 | return datatimeValue |
|
244 | 244 | |
|
245 | 245 | def getTimeRange(self): |
|
246 | 246 | |
|
247 | 247 | datatime = [] |
|
248 | 248 | |
|
249 | 249 | datatime.append(self.ltctime) |
|
250 | 250 | datatime.append(self.ltctime + self.timeInterval) |
|
251 | 251 | |
|
252 | 252 | datatime = numpy.array(datatime) |
|
253 | 253 | |
|
254 | 254 | return datatime |
|
255 | 255 | |
|
256 | 256 | def getFmax(self): |
|
257 | 257 | |
|
258 | 258 | PRF = 1./(self.ippSeconds * self.nCohInt) |
|
259 | 259 | |
|
260 | 260 | fmax = PRF/2. |
|
261 | 261 | |
|
262 | 262 | return fmax |
|
263 | 263 | |
|
264 | 264 | def getVmax(self): |
|
265 | 265 | |
|
266 | 266 | _lambda = self.C/self.frequency |
|
267 | 267 | |
|
268 | 268 | vmax = self.getFmax() * _lambda |
|
269 | 269 | |
|
270 | 270 | return vmax |
|
271 | 271 | |
|
272 | 272 | def get_ippSeconds(self): |
|
273 | 273 | ''' |
|
274 | 274 | ''' |
|
275 | 275 | return self.radarControllerHeaderObj.ippSeconds |
|
276 | 276 | |
|
277 | 277 | def set_ippSeconds(self, ippSeconds): |
|
278 | 278 | ''' |
|
279 | 279 | ''' |
|
280 | 280 | |
|
281 | 281 | self.radarControllerHeaderObj.ippSeconds = ippSeconds |
|
282 | 282 | |
|
283 | 283 | return |
|
284 | 284 | |
|
285 | 285 | def get_dtype(self): |
|
286 | 286 | ''' |
|
287 | 287 | ''' |
|
288 | 288 | return getNumpyDtype(self.datatype) |
|
289 | 289 | |
|
290 | 290 | def set_dtype(self, numpyDtype): |
|
291 | 291 | ''' |
|
292 | 292 | ''' |
|
293 | 293 | |
|
294 | 294 | self.datatype = getDataTypeCode(numpyDtype) |
|
295 | 295 | |
|
296 | 296 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") |
|
297 | 297 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") |
|
298 | 298 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") |
|
299 | 299 | #noise = property(getNoise, "I'm the 'nHeights' property.") |
|
300 | 300 | datatime = property(getDatatime, "I'm the 'datatime' property") |
|
301 | 301 | ltctime = property(getltctime, "I'm the 'ltctime' property") |
|
302 | 302 | ippSeconds = property(get_ippSeconds, set_ippSeconds) |
|
303 | 303 | dtype = property(get_dtype, set_dtype) |
|
304 | 304 | |
|
305 | 305 | class Voltage(JROData): |
|
306 | 306 | |
|
307 | 307 | #data es un numpy array de 2 dmensiones (canales, alturas) |
|
308 | 308 | data = None |
|
309 | 309 | |
|
310 | 310 | def __init__(self): |
|
311 | 311 | ''' |
|
312 | 312 | Constructor |
|
313 | 313 | ''' |
|
314 | 314 | |
|
315 | 315 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
316 | 316 | |
|
317 | 317 | self.systemHeaderObj = SystemHeader() |
|
318 | 318 | |
|
319 | 319 | self.type = "Voltage" |
|
320 | 320 | |
|
321 | 321 | self.data = None |
|
322 | 322 | |
|
323 | 323 | # self.dtype = None |
|
324 | 324 | |
|
325 | 325 | # self.nChannels = 0 |
|
326 | 326 | |
|
327 | 327 | # self.nHeights = 0 |
|
328 | 328 | |
|
329 | 329 | self.nProfiles = None |
|
330 | 330 | |
|
331 | 331 | self.heightList = None |
|
332 | 332 | |
|
333 | 333 | self.channelList = None |
|
334 | 334 | |
|
335 | 335 | # self.channelIndexList = None |
|
336 | 336 | |
|
337 | 337 | self.flagNoData = True |
|
338 | 338 | |
|
339 | 339 | self.flagTimeBlock = False |
|
340 | 340 | |
|
341 | 341 | self.utctime = None |
|
342 | 342 | |
|
343 | 343 | self.timeZone = None |
|
344 | 344 | |
|
345 | 345 | self.dstFlag = None |
|
346 | 346 | |
|
347 | 347 | self.errorCount = None |
|
348 | 348 | |
|
349 | 349 | self.nCohInt = None |
|
350 | 350 | |
|
351 | 351 | self.blocksize = None |
|
352 | 352 | |
|
353 | 353 | self.flagDecodeData = False #asumo q la data no esta decodificada |
|
354 | 354 | |
|
355 | 355 | self.flagDeflipData = False #asumo q la data no esta sin flip |
|
356 | 356 | |
|
357 | 357 | self.flagShiftFFT = False |
|
358 | 358 | |
|
359 | 359 | |
|
360 | 360 | def getNoisebyHildebrand(self): |
|
361 | 361 | """ |
|
362 | 362 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
|
363 | 363 | |
|
364 | 364 | Return: |
|
365 | 365 | noiselevel |
|
366 | 366 | """ |
|
367 | 367 | |
|
368 | 368 | for channel in range(self.nChannels): |
|
369 | 369 | daux = self.data_spc[channel,:,:] |
|
370 | 370 | self.noise[channel] = hildebrand_sekhon(daux, self.nCohInt) |
|
371 | 371 | |
|
372 | 372 | return self.noise |
|
373 | 373 | |
|
374 | 374 | def getNoise(self, type = 1): |
|
375 | 375 | |
|
376 | 376 | self.noise = numpy.zeros(self.nChannels) |
|
377 | 377 | |
|
378 | 378 | if type == 1: |
|
379 | 379 | noise = self.getNoisebyHildebrand() |
|
380 | 380 | |
|
381 | 381 | return 10*numpy.log10(noise) |
|
382 | 382 | |
|
383 | 383 | noise = property(getNoise, "I'm the 'nHeights' property.") |
|
384 | 384 | |
|
385 | 385 | class Spectra(JROData): |
|
386 | 386 | |
|
387 | 387 | #data es un numpy array de 2 dmensiones (canales, perfiles, alturas) |
|
388 | 388 | data_spc = None |
|
389 | 389 | |
|
390 | 390 | #data es un numpy array de 2 dmensiones (canales, pares, alturas) |
|
391 | 391 | data_cspc = None |
|
392 | 392 | |
|
393 | 393 | #data es un numpy array de 2 dmensiones (canales, alturas) |
|
394 | 394 | data_dc = None |
|
395 | 395 | |
|
396 | 396 | nFFTPoints = None |
|
397 | 397 | |
|
398 | 398 | # nPairs = None |
|
399 | 399 | |
|
400 | 400 | pairsList = None |
|
401 | 401 | |
|
402 | 402 | nIncohInt = None |
|
403 | 403 | |
|
404 | 404 | wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia |
|
405 | 405 | |
|
406 | 406 | nCohInt = None #se requiere para determinar el valor de timeInterval |
|
407 | 407 | |
|
408 | 408 | ippFactor = None |
|
409 | 409 | |
|
410 | 410 | def __init__(self): |
|
411 | 411 | ''' |
|
412 | 412 | Constructor |
|
413 | 413 | ''' |
|
414 | 414 | |
|
415 | 415 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
416 | 416 | |
|
417 | 417 | self.systemHeaderObj = SystemHeader() |
|
418 | 418 | |
|
419 | 419 | self.type = "Spectra" |
|
420 | 420 | |
|
421 | 421 | # self.data = None |
|
422 | 422 | |
|
423 | 423 | # self.dtype = None |
|
424 | 424 | |
|
425 | 425 | # self.nChannels = 0 |
|
426 | 426 | |
|
427 | 427 | # self.nHeights = 0 |
|
428 | 428 | |
|
429 | 429 | self.nProfiles = None |
|
430 | 430 | |
|
431 | 431 | self.heightList = None |
|
432 | 432 | |
|
433 | 433 | self.channelList = None |
|
434 | 434 | |
|
435 | 435 | # self.channelIndexList = None |
|
436 | 436 | |
|
437 | 437 | self.pairsList = None |
|
438 | 438 | |
|
439 | 439 | self.flagNoData = True |
|
440 | 440 | |
|
441 | 441 | self.flagTimeBlock = False |
|
442 | 442 | |
|
443 | 443 | self.utctime = None |
|
444 | 444 | |
|
445 | 445 | self.nCohInt = None |
|
446 | 446 | |
|
447 | 447 | self.nIncohInt = None |
|
448 | 448 | |
|
449 | 449 | self.blocksize = None |
|
450 | 450 | |
|
451 | 451 | self.nFFTPoints = None |
|
452 | 452 | |
|
453 | 453 | self.wavelength = None |
|
454 | 454 | |
|
455 | 455 | self.flagDecodeData = False #asumo q la data no esta decodificada |
|
456 | 456 | |
|
457 | 457 | self.flagDeflipData = False #asumo q la data no esta sin flip |
|
458 | 458 | |
|
459 | 459 | self.flagShiftFFT = False |
|
460 | 460 | |
|
461 | 461 | self.ippFactor = 1 |
|
462 | 462 | |
|
463 | 463 | #self.noise = None |
|
464 | 464 | |
|
465 | 465 | self.beacon_heiIndexList = [] |
|
466 | 466 | |
|
467 | 467 | self.noise_estimation = None |
|
468 | 468 | |
|
469 | 469 | |
|
470 | 470 | def getNoisebyHildebrand(self): |
|
471 | 471 | """ |
|
472 | 472 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
|
473 | 473 | |
|
474 | 474 | Return: |
|
475 | 475 | noiselevel |
|
476 | 476 | """ |
|
477 | 477 | |
|
478 | 478 | noise = numpy.zeros(self.nChannels) |
|
479 | 479 | for channel in range(self.nChannels): |
|
480 | 480 | daux = self.data_spc[channel,:,:] |
|
481 | 481 | noise[channel] = hildebrand_sekhon(daux, self.nIncohInt) |
|
482 | 482 | |
|
483 | 483 | return noise |
|
484 | 484 | |
|
485 | 485 | def getNoise(self): |
|
486 | 486 | if self.noise_estimation != None: |
|
487 | 487 | return self.noise_estimation #this was estimated by getNoise Operation defined in jroproc_spectra.py |
|
488 | 488 | else: |
|
489 | 489 | noise = self.getNoisebyHildebrand() |
|
490 | 490 | return noise |
|
491 | 491 | |
|
492 | 492 | |
|
493 | 493 | def getFreqRange(self, extrapoints=0): |
|
494 | 494 | |
|
495 | 495 | deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor) |
|
496 | 496 | freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 |
|
497 | 497 | |
|
498 | 498 | return freqrange |
|
499 | 499 | |
|
500 | 500 | def getVelRange(self, extrapoints=0): |
|
501 | 501 | |
|
502 | 502 | deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor) |
|
503 | 503 | velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltav/2 |
|
504 | 504 | |
|
505 | 505 | return velrange |
|
506 | 506 | |
|
507 | 507 | def getNPairs(self): |
|
508 | 508 | |
|
509 | 509 | return len(self.pairsList) |
|
510 | 510 | |
|
511 | 511 | def getPairsIndexList(self): |
|
512 | 512 | |
|
513 | 513 | return range(self.nPairs) |
|
514 | 514 | |
|
515 | 515 | def getNormFactor(self): |
|
516 | 516 | pwcode = 1 |
|
517 | 517 | if self.flagDecodeData: |
|
518 | 518 | pwcode = numpy.sum(self.code[0]**2) |
|
519 | 519 | #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter |
|
520 | 520 | normFactor = self.nProfiles*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter |
|
521 | 521 | |
|
522 | 522 | return normFactor |
|
523 | 523 | |
|
524 | 524 | def getFlagCspc(self): |
|
525 | 525 | |
|
526 | 526 | if self.data_cspc == None: |
|
527 | 527 | return True |
|
528 | 528 | |
|
529 | 529 | return False |
|
530 | 530 | |
|
531 | 531 | def getFlagDc(self): |
|
532 | 532 | |
|
533 | 533 | if self.data_dc == None: |
|
534 | 534 | return True |
|
535 | 535 | |
|
536 | 536 | return False |
|
537 | 537 | |
|
538 | 538 | nPairs = property(getNPairs, "I'm the 'nPairs' property.") |
|
539 | 539 | pairsIndexList = property(getPairsIndexList, "I'm the 'pairsIndexList' property.") |
|
540 | 540 | normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.") |
|
541 | 541 | flag_cspc = property(getFlagCspc) |
|
542 | 542 | flag_dc = property(getFlagDc) |
|
543 | 543 | noise = property(getNoise, "I'm the 'nHeights' property.") |
|
544 | 544 | |
|
545 | 545 | class SpectraHeis(Spectra): |
|
546 | 546 | |
|
547 | 547 | data_spc = None |
|
548 | 548 | |
|
549 | 549 | data_cspc = None |
|
550 | 550 | |
|
551 | 551 | data_dc = None |
|
552 | 552 | |
|
553 | 553 | nFFTPoints = None |
|
554 | 554 | |
|
555 | 555 | # nPairs = None |
|
556 | 556 | |
|
557 | 557 | pairsList = None |
|
558 | 558 | |
|
559 | 559 | nIncohInt = None |
|
560 | 560 | |
|
561 | 561 | def __init__(self): |
|
562 | 562 | |
|
563 | 563 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
564 | 564 | |
|
565 | 565 | self.systemHeaderObj = SystemHeader() |
|
566 | 566 | |
|
567 | 567 | self.type = "SpectraHeis" |
|
568 | 568 | |
|
569 | 569 | # self.dtype = None |
|
570 | 570 | |
|
571 | 571 | # self.nChannels = 0 |
|
572 | 572 | |
|
573 | 573 | # self.nHeights = 0 |
|
574 | 574 | |
|
575 | 575 | self.nProfiles = None |
|
576 | 576 | |
|
577 | 577 | self.heightList = None |
|
578 | 578 | |
|
579 | 579 | self.channelList = None |
|
580 | 580 | |
|
581 | 581 | # self.channelIndexList = None |
|
582 | 582 | |
|
583 | 583 | self.flagNoData = True |
|
584 | 584 | |
|
585 | 585 | self.flagTimeBlock = False |
|
586 | 586 | |
|
587 | 587 | # self.nPairs = 0 |
|
588 | 588 | |
|
589 | 589 | self.utctime = None |
|
590 | 590 | |
|
591 | 591 | self.blocksize = None |
|
592 | 592 | |
|
593 | 593 | def getNormFactor(self): |
|
594 | 594 | pwcode = 1 |
|
595 | 595 | if self.flagDecodeData: |
|
596 | 596 | pwcode = numpy.sum(self.code[0]**2) |
|
597 | 597 | |
|
598 | 598 | normFactor = self.nIncohInt*self.nCohInt*pwcode |
|
599 | 599 | |
|
600 | 600 | return normFactor |
|
601 | 601 | |
|
602 | 602 | normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.") |
|
603 | 603 | |
|
604 | 604 | class Fits: |
|
605 | 605 | |
|
606 | 606 | heightList = None |
|
607 | 607 | |
|
608 | 608 | channelList = None |
|
609 | 609 | |
|
610 | 610 | flagNoData = True |
|
611 | 611 | |
|
612 | 612 | flagTimeBlock = False |
|
613 | 613 | |
|
614 | 614 | useLocalTime = False |
|
615 | 615 | |
|
616 | 616 | utctime = None |
|
617 | 617 | |
|
618 | 618 | timeZone = None |
|
619 | 619 | |
|
620 | 620 | # ippSeconds = None |
|
621 | 621 | |
|
622 | 622 | timeInterval = None |
|
623 | 623 | |
|
624 | 624 | nCohInt = None |
|
625 | 625 | |
|
626 | 626 | nIncohInt = None |
|
627 | 627 | |
|
628 | 628 | noise = None |
|
629 | 629 | |
|
630 | 630 | windowOfFilter = 1 |
|
631 | 631 | |
|
632 | 632 | #Speed of ligth |
|
633 | 633 | C = 3e8 |
|
634 | 634 | |
|
635 | 635 | frequency = 49.92e6 |
|
636 | 636 | |
|
637 | 637 | realtime = False |
|
638 | 638 | |
|
639 | 639 | |
|
640 | 640 | def __init__(self): |
|
641 | 641 | |
|
642 | 642 | self.type = "Fits" |
|
643 | 643 | |
|
644 | 644 | self.nProfiles = None |
|
645 | 645 | |
|
646 | 646 | self.heightList = None |
|
647 | 647 | |
|
648 | 648 | self.channelList = None |
|
649 | 649 | |
|
650 | 650 | # self.channelIndexList = None |
|
651 | 651 | |
|
652 | 652 | self.flagNoData = True |
|
653 | 653 | |
|
654 | 654 | self.utctime = None |
|
655 | 655 | |
|
656 | 656 | self.nCohInt = None |
|
657 | 657 | |
|
658 | 658 | self.nIncohInt = None |
|
659 | 659 | |
|
660 | 660 | self.useLocalTime = True |
|
661 | 661 | |
|
662 | 662 | # self.utctime = None |
|
663 | 663 | # self.timeZone = None |
|
664 | 664 | # self.ltctime = None |
|
665 | 665 | # self.timeInterval = None |
|
666 | 666 | # self.header = None |
|
667 | 667 | # self.data_header = None |
|
668 | 668 | # self.data = None |
|
669 | 669 | # self.datatime = None |
|
670 | 670 | # self.flagNoData = False |
|
671 | 671 | # self.expName = '' |
|
672 | 672 | # self.nChannels = None |
|
673 | 673 | # self.nSamples = None |
|
674 | 674 | # self.dataBlocksPerFile = None |
|
675 | 675 | # self.comments = '' |
|
676 | 676 | # |
|
677 | 677 | |
|
678 | 678 | |
|
679 | 679 | def getltctime(self): |
|
680 | 680 | |
|
681 | 681 | if self.useLocalTime: |
|
682 | 682 | return self.utctime - self.timeZone*60 |
|
683 | 683 | |
|
684 | 684 | return self.utctime |
|
685 | 685 | |
|
686 | 686 | def getDatatime(self): |
|
687 | 687 | |
|
688 | 688 | datatime = datetime.datetime.utcfromtimestamp(self.ltctime) |
|
689 | 689 | return datatime |
|
690 | 690 | |
|
691 | 691 | def getTimeRange(self): |
|
692 | 692 | |
|
693 | 693 | datatime = [] |
|
694 | 694 | |
|
695 | 695 | datatime.append(self.ltctime) |
|
696 | 696 | datatime.append(self.ltctime + self.timeInterval) |
|
697 | 697 | |
|
698 | 698 | datatime = numpy.array(datatime) |
|
699 | 699 | |
|
700 | 700 | return datatime |
|
701 | 701 | |
|
702 | 702 | def getHeiRange(self): |
|
703 | 703 | |
|
704 | 704 | heis = self.heightList |
|
705 | 705 | |
|
706 | 706 | return heis |
|
707 | 707 | |
|
708 | 708 | def isEmpty(self): |
|
709 | 709 | |
|
710 | 710 | return self.flagNoData |
|
711 | 711 | |
|
712 | 712 | def getNHeights(self): |
|
713 | 713 | |
|
714 | 714 | return len(self.heightList) |
|
715 | 715 | |
|
716 | 716 | def getNChannels(self): |
|
717 | 717 | |
|
718 | 718 | return len(self.channelList) |
|
719 | 719 | |
|
720 | 720 | def getChannelIndexList(self): |
|
721 | 721 | |
|
722 | 722 | return range(self.nChannels) |
|
723 | 723 | |
|
724 | 724 | def getNoise(self, type = 1): |
|
725 | 725 | |
|
726 | 726 | self.noise = numpy.zeros(self.nChannels) |
|
727 | 727 | |
|
728 | 728 | if type == 1: |
|
729 | 729 | noise = self.getNoisebyHildebrand() |
|
730 | 730 | |
|
731 | 731 | if type == 2: |
|
732 | 732 | noise = self.getNoisebySort() |
|
733 | 733 | |
|
734 | 734 | if type == 3: |
|
735 | 735 | noise = self.getNoisebyWindow() |
|
736 | 736 | |
|
737 | 737 | return noise |
|
738 | 738 | |
|
739 | 739 | datatime = property(getDatatime, "I'm the 'datatime' property") |
|
740 | 740 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") |
|
741 | 741 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") |
|
742 | 742 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") |
|
743 | 743 | noise = property(getNoise, "I'm the 'nHeights' property.") |
|
744 | 744 | datatime = property(getDatatime, "I'm the 'datatime' property") |
|
745 | 745 | ltctime = property(getltctime, "I'm the 'ltctime' property") |
|
746 | ||
|
747 | class Correlation(JROData): | |
|
748 | ||
|
749 | noise = None | |
|
750 | ||
|
751 | SNR = None | |
|
752 | ||
|
753 | pairsAutoCorr = None #Pairs of Autocorrelation | |
|
754 | ||
|
755 | #-------------------------------------------------- | |
|
756 | ||
|
757 | data_corr = None | |
|
758 | ||
|
759 | data_volt = None | |
|
760 | ||
|
761 | lagT = None # each element value is a profileIndex | |
|
762 | ||
|
763 | lagR = None # each element value is in km | |
|
764 | ||
|
765 | pairsList = None | |
|
766 | ||
|
767 | calculateVelocity = None | |
|
768 | ||
|
769 | nPoints = None | |
|
770 | ||
|
771 | nAvg = None | |
|
772 | ||
|
773 | bufferSize = None | |
|
774 | ||
|
775 | def __init__(self): | |
|
776 | ''' | |
|
777 | Constructor | |
|
778 | ''' | |
|
779 | self.radarControllerHeaderObj = RadarControllerHeader() | |
|
780 | ||
|
781 | self.systemHeaderObj = SystemHeader() | |
|
782 | ||
|
783 | self.type = "Correlation" | |
|
784 | ||
|
785 | self.data = None | |
|
786 | ||
|
787 | self.dtype = None | |
|
788 | ||
|
789 | self.nProfiles = None | |
|
790 | ||
|
791 | self.heightList = None | |
|
792 | ||
|
793 | self.channelList = None | |
|
794 | ||
|
795 | self.flagNoData = True | |
|
796 | ||
|
797 | self.flagTimeBlock = False | |
|
798 | ||
|
799 | self.utctime = None | |
|
800 | ||
|
801 | self.timeZone = None | |
|
802 | ||
|
803 | self.dstFlag = None | |
|
804 | ||
|
805 | self.errorCount = None | |
|
806 | ||
|
807 | self.blocksize = None | |
|
808 | ||
|
809 | self.flagDecodeData = False #asumo q la data no esta decodificada | |
|
810 | ||
|
811 | self.flagDeflipData = False #asumo q la data no esta sin flip | |
|
812 | ||
|
813 | self.pairsList = None | |
|
814 | ||
|
815 | self.nPoints = None | |
|
816 | ||
|
817 | def getLagTRange(self, extrapoints=0): | |
|
818 | ||
|
819 | lagTRange = self.lagT | |
|
820 | diff = lagTRange[1] - lagTRange[0] | |
|
821 | extra = numpy.arange(1,extrapoints + 1)*diff + lagTRange[-1] | |
|
822 | lagTRange = numpy.hstack((lagTRange, extra)) | |
|
823 | ||
|
824 | return lagTRange | |
|
825 | ||
|
826 | def getLagRRange(self, extrapoints=0): | |
|
827 | ||
|
828 | return self.lagR | |
|
829 | ||
|
830 | def getPairsList(self): | |
|
831 | ||
|
832 | return self.pairsList | |
|
833 | ||
|
834 | def getCalculateVelocity(self): | |
|
835 | ||
|
836 | return self.calculateVelocity | |
|
837 | ||
|
838 | def getNPoints(self): | |
|
839 | ||
|
840 | return self.nPoints | |
|
841 | ||
|
842 | def getNAvg(self): | |
|
843 | ||
|
844 | return self.nAvg | |
|
845 | ||
|
846 | def getBufferSize(self): | |
|
847 | ||
|
848 | return self.bufferSize | |
|
849 | ||
|
850 | def getPairsAutoCorr(self): | |
|
851 | pairsList = self.pairsList | |
|
852 | pairsAutoCorr = numpy.zeros(self.nChannels, dtype = 'int')*numpy.nan | |
|
853 | ||
|
854 | for l in range(len(pairsList)): | |
|
855 | firstChannel = pairsList[l][0] | |
|
856 | secondChannel = pairsList[l][1] | |
|
857 | ||
|
858 | #Obteniendo pares de Autocorrelacion | |
|
859 | if firstChannel == secondChannel: | |
|
860 | pairsAutoCorr[firstChannel] = int(l) | |
|
861 | ||
|
862 | pairsAutoCorr = pairsAutoCorr.astype(int) | |
|
863 | ||
|
864 | return pairsAutoCorr | |
|
865 | ||
|
866 | def getNoise(self, mode = 2): | |
|
867 | ||
|
868 | indR = numpy.where(self.lagR == 0)[0][0] | |
|
869 | indT = numpy.where(self.lagT == 0)[0][0] | |
|
870 | ||
|
871 | jspectra0 = self.data_corr[:,:,indR,:] | |
|
872 | jspectra = copy.copy(jspectra0) | |
|
873 | ||
|
874 | num_chan = jspectra.shape[0] | |
|
875 | num_hei = jspectra.shape[2] | |
|
876 | ||
|
877 | freq_dc = jspectra.shape[1]/2 | |
|
878 | ind_vel = numpy.array([-2,-1,1,2]) + freq_dc | |
|
879 | ||
|
880 | if ind_vel[0]<0: | |
|
881 | ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof | |
|
882 | ||
|
883 | if mode == 1: | |
|
884 | jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION | |
|
885 | ||
|
886 | if mode == 2: | |
|
887 | ||
|
888 | vel = numpy.array([-2,-1,1,2]) | |
|
889 | xx = numpy.zeros([4,4]) | |
|
890 | ||
|
891 | for fil in range(4): | |
|
892 | xx[fil,:] = vel[fil]**numpy.asarray(range(4)) | |
|
893 | ||
|
894 | xx_inv = numpy.linalg.inv(xx) | |
|
895 | xx_aux = xx_inv[0,:] | |
|
896 | ||
|
897 | for ich in range(num_chan): | |
|
898 | yy = jspectra[ich,ind_vel,:] | |
|
899 | jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy) | |
|
900 | ||
|
901 | junkid = jspectra[ich,freq_dc,:]<=0 | |
|
902 | cjunkid = sum(junkid) | |
|
903 | ||
|
904 | if cjunkid.any(): | |
|
905 | jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2 | |
|
906 | ||
|
907 | noise = jspectra0[:,freq_dc,:] - jspectra[:,freq_dc,:] | |
|
908 | ||
|
909 | return noise | |
|
910 | ||
|
911 | # pairsList = property(getPairsList, "I'm the 'pairsList' property.") | |
|
912 | # nPoints = property(getNPoints, "I'm the 'nPoints' property.") | |
|
913 | calculateVelocity = property(getCalculateVelocity, "I'm the 'calculateVelocity' property.") | |
|
914 | nAvg = property(getNAvg, "I'm the 'nAvg' property.") | |
|
915 | bufferSize = property(getBufferSize, "I'm the 'bufferSize' property.") | |
|
916 | ||
|
917 | ||
|
918 | class Parameters(JROData): | |
|
919 | ||
|
920 | inputUnit = None #Type of data to be processed | |
|
921 | ||
|
922 | operation = None #Type of operation to parametrize | |
|
923 | ||
|
924 | data_param = None #Parameters obtained | |
|
925 | ||
|
926 | data_pre = None #Data Pre Parametrization | |
|
746 | 927 | |
|
928 | heightRange = None #Heights | |
|
929 | ||
|
930 | abscissaRange = None #Abscissa, can be velocities, lags or time | |
|
931 | ||
|
932 | noise = None #Noise Potency | |
|
933 | ||
|
934 | SNR = None #Signal to Noise Ratio | |
|
935 | ||
|
936 | pairsList = None #List of Pairs for Cross correlations or Cross spectrum | |
|
937 | ||
|
938 | initUtcTime = None #Initial UTC time | |
|
939 | ||
|
940 | paramInterval = None #Time interval to calculate Parameters in seconds | |
|
941 | ||
|
942 | windsInterval = None #Time interval to calculate Winds in seconds | |
|
943 | ||
|
944 | normFactor = None #Normalization Factor | |
|
945 | ||
|
946 | winds = None #Wind estimations | |
|
947 | ||
|
948 | def __init__(self): | |
|
949 | ''' | |
|
950 | Constructor | |
|
951 | ''' | |
|
952 | self.radarControllerHeaderObj = RadarControllerHeader() | |
|
953 | ||
|
954 | self.systemHeaderObj = SystemHeader() | |
|
955 | ||
|
956 | self.type = "Parameters" | |
|
957 | ||
|
958 | def getTimeRange1(self): | |
|
959 | ||
|
960 | datatime = [] | |
|
961 | ||
|
962 | datatime.append(self.initUtcTime) | |
|
963 | datatime.append(self.initUtcTime + self.windsInterval - 1) | |
|
964 | ||
|
965 | datatime = numpy.array(datatime) | |
|
966 | ||
|
967 | return datatime |
@@ -1,590 +1,607 | |||
|
1 | 1 | import os |
|
2 | 2 | import numpy |
|
3 | 3 | import time, datetime |
|
4 | 4 | import mpldriver |
|
5 | 5 | |
|
6 | 6 | |
|
7 | 7 | import Queue |
|
8 | 8 | import threading |
|
9 | 9 | |
|
10 | 10 | def isRealtime(utcdatatime): |
|
11 | 11 | utcnow = time.mktime(time.localtime()) |
|
12 | 12 | delta = abs(utcnow - utcdatatime) # abs |
|
13 | 13 | if delta >= 30.: |
|
14 | 14 | return False |
|
15 | 15 | return True |
|
16 | 16 | |
|
17 | 17 | |
|
18 | 18 | |
|
19 | 19 | |
|
20 | 20 | class Figure: |
|
21 | 21 | |
|
22 | 22 | __driver = mpldriver |
|
23 | 23 | __isConfigThread = False |
|
24 | 24 | fig = None |
|
25 | 25 | |
|
26 | 26 | id = None |
|
27 | 27 | wintitle = None |
|
28 | 28 | width = None |
|
29 | 29 | height = None |
|
30 | 30 | nplots = None |
|
31 | 31 | timerange = None |
|
32 | 32 | |
|
33 | 33 | axesObjList = [] |
|
34 | 34 | |
|
35 | 35 | WIDTH = None |
|
36 | 36 | HEIGHT = None |
|
37 | 37 | PREFIX = 'fig' |
|
38 | 38 | |
|
39 | 39 | xmin = None |
|
40 | 40 | xmax = None |
|
41 | 41 | |
|
42 | 42 | def __init__(self): |
|
43 | 43 | |
|
44 | 44 | raise ValueError, "This method is not implemented" |
|
45 | 45 | |
|
46 | 46 | def __del__(self): |
|
47 | 47 | |
|
48 | 48 | self.__driver.closeFigure() |
|
49 | 49 | |
|
50 | 50 | def getFilename(self, name, ext='.png'): |
|
51 | 51 | |
|
52 | 52 | path = '%s%03d' %(self.PREFIX, self.id) |
|
53 | 53 | filename = '%s_%s%s' %(self.PREFIX, name, ext) |
|
54 | 54 | return os.path.join(path, filename) |
|
55 | 55 | |
|
56 | 56 | def getAxesObjList(self): |
|
57 | 57 | |
|
58 | 58 | return self.axesObjList |
|
59 | 59 | |
|
60 | 60 | def getSubplots(self): |
|
61 | 61 | |
|
62 | 62 | raise ValueError, "Abstract method: This method should be defined" |
|
63 | 63 | |
|
64 | 64 | def getScreenDim(self, widthplot, heightplot): |
|
65 | 65 | |
|
66 | 66 | nrow, ncol = self.getSubplots() |
|
67 | 67 | |
|
68 | 68 | widthscreen = widthplot*ncol |
|
69 | 69 | heightscreen = heightplot*nrow |
|
70 | 70 | |
|
71 | 71 | return widthscreen, heightscreen |
|
72 | 72 | |
|
73 | 73 | def getTimeLim(self, x, xmin=None, xmax=None, timerange=None): |
|
74 | 74 | |
|
75 | 75 | if self.xmin != None and self.xmax != None: |
|
76 | 76 | if timerange == None: |
|
77 | 77 | timerange = self.xmax - self.xmin |
|
78 | 78 | xmin = self.xmin + timerange |
|
79 | 79 | xmax = self.xmax + timerange |
|
80 | 80 | |
|
81 | 81 | return xmin, xmax |
|
82 | 82 | |
|
83 | 83 | |
|
84 | 84 | if timerange != None and self.xmin == None and self.xmax == None: |
|
85 | 85 | txmin = x[0] - x[0]%timerange |
|
86 | 86 | thisdatetime = datetime.datetime.utcfromtimestamp(txmin) |
|
87 | 87 | thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0)) |
|
88 | 88 | xmin = (thisdatetime - thisdate).seconds/(60*60.) |
|
89 | 89 | xmax = xmin + timerange/(60*60.) |
|
90 | 90 | |
|
91 | 91 | |
|
92 | 92 | if timerange == None: |
|
93 | 93 | txmin = numpy.min(x) |
|
94 | 94 | thisdatetime = datetime.datetime.utcfromtimestamp(txmin) |
|
95 | 95 | thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0)) |
|
96 | 96 | |
|
97 | 97 | mindt = thisdate + datetime.timedelta(hours=xmin) - datetime.timedelta(seconds=time.timezone) |
|
98 | 98 | xmin_sec = time.mktime(mindt.timetuple()) |
|
99 | 99 | |
|
100 | 100 | maxdt = thisdate + datetime.timedelta(hours=xmax) - datetime.timedelta(seconds=time.timezone) |
|
101 | 101 | xmax_sec = time.mktime(maxdt.timetuple()) |
|
102 | 102 | |
|
103 | 103 | return xmin_sec, xmax_sec |
|
104 | 104 | |
|
105 | 105 | |
|
106 | 106 | |
|
107 | 107 | |
|
108 | 108 | |
|
109 | 109 | # if timerange != None: |
|
110 | 110 | # txmin = x[0] - x[0]%timerange |
|
111 | 111 | # else: |
|
112 | 112 | # txmin = numpy.min(x) |
|
113 | 113 | # |
|
114 | 114 | # thisdatetime = datetime.datetime.utcfromtimestamp(txmin) |
|
115 | 115 | # thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0)) |
|
116 | 116 | # |
|
117 | 117 | # #################################################### |
|
118 | 118 | # #If the x is out of xrange |
|
119 | 119 | # if xmax != None: |
|
120 | 120 | # if xmax < (thisdatetime - thisdate).seconds/(60*60.): |
|
121 | 121 | # xmin = None |
|
122 | 122 | # xmax = None |
|
123 | 123 | # |
|
124 | 124 | # if xmin == None: |
|
125 | 125 | # td = thisdatetime - thisdate |
|
126 | 126 | # xmin = td.seconds/(60*60.) |
|
127 | 127 | # |
|
128 | 128 | # if xmax == None: |
|
129 | 129 | # xmax = xmin + self.timerange/(60*60.) |
|
130 | 130 | # |
|
131 | 131 | # mindt = thisdate + datetime.timedelta(hours=xmin) - datetime.timedelta(seconds=time.timezone) |
|
132 | 132 | # tmin = time.mktime(mindt.timetuple()) |
|
133 | 133 | # |
|
134 | 134 | # maxdt = thisdate + datetime.timedelta(hours=xmax) - datetime.timedelta(seconds=time.timezone) |
|
135 | 135 | # tmax = time.mktime(maxdt.timetuple()) |
|
136 | 136 | # |
|
137 | 137 | # #self.timerange = tmax - tmin |
|
138 | 138 | # |
|
139 | 139 | # return tmin, tmax |
|
140 | 140 | |
|
141 | 141 | def init(self, id, nplots, wintitle): |
|
142 | 142 | |
|
143 | 143 | raise ValueError, "This method has been replaced with createFigure" |
|
144 | 144 | |
|
145 | 145 | def createFigure(self, id, wintitle, widthplot=None, heightplot=None, show=True): |
|
146 | 146 | |
|
147 | 147 | """ |
|
148 | 148 | Crea la figura de acuerdo al driver y parametros seleccionados seleccionados. |
|
149 | 149 | Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH |
|
150 | 150 | y self.HEIGHT y el numero de subplots (nrow, ncol) |
|
151 | 151 | |
|
152 | 152 | Input: |
|
153 | 153 | id : Los parametros necesarios son |
|
154 | 154 | wintitle : |
|
155 | 155 | |
|
156 | 156 | """ |
|
157 | 157 | |
|
158 | 158 | if widthplot == None: |
|
159 | 159 | widthplot = self.WIDTH |
|
160 | 160 | |
|
161 | 161 | if heightplot == None: |
|
162 | 162 | heightplot = self.HEIGHT |
|
163 | 163 | |
|
164 | 164 | self.id = id |
|
165 | 165 | |
|
166 | 166 | self.wintitle = wintitle |
|
167 | 167 | |
|
168 | 168 | self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot) |
|
169 | 169 | |
|
170 | 170 | self.fig = self.__driver.createFigure(id=self.id, |
|
171 | 171 | wintitle=self.wintitle, |
|
172 | 172 | width=self.widthscreen, |
|
173 | 173 | height=self.heightscreen, |
|
174 | 174 | show=show) |
|
175 | 175 | |
|
176 | 176 | self.axesObjList = [] |
|
177 | 177 | |
|
178 | 178 | |
|
179 | 179 | def setDriver(self, driver=mpldriver): |
|
180 | 180 | |
|
181 | 181 | self.__driver = driver |
|
182 | 182 | |
|
183 | 183 | def setTitle(self, title): |
|
184 | 184 | |
|
185 | 185 | self.__driver.setTitle(self.fig, title) |
|
186 | 186 | |
|
187 | 187 | def setWinTitle(self, title): |
|
188 | 188 | |
|
189 | 189 | self.__driver.setWinTitle(self.fig, title=title) |
|
190 | 190 | |
|
191 | 191 | def setTextFromAxes(self, text): |
|
192 | 192 | |
|
193 | 193 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes" |
|
194 | 194 | |
|
195 | 195 | def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan): |
|
196 | 196 | |
|
197 | 197 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes" |
|
198 | 198 | |
|
199 | 199 | def addAxes(self, *args): |
|
200 | 200 | """ |
|
201 | 201 | |
|
202 | 202 | Input: |
|
203 | 203 | *args : Los parametros necesarios son |
|
204 | 204 | nrow, ncol, xpos, ypos, colspan, rowspan |
|
205 | 205 | """ |
|
206 | 206 | |
|
207 | 207 | axesObj = Axes(self.fig, *args) |
|
208 | 208 | self.axesObjList.append(axesObj) |
|
209 | 209 | |
|
210 | 210 | def saveFigure(self, figpath, figfile, *args): |
|
211 | 211 | |
|
212 | 212 | filename = os.path.join(figpath, figfile) |
|
213 | 213 | |
|
214 | 214 | fullpath = os.path.split(filename)[0] |
|
215 | 215 | |
|
216 | 216 | if not os.path.exists(fullpath): |
|
217 | 217 | subpath = os.path.split(fullpath)[0] |
|
218 | 218 | |
|
219 | 219 | if not os.path.exists(subpath): |
|
220 | 220 | os.mkdir(subpath) |
|
221 | 221 | |
|
222 | 222 | os.mkdir(fullpath) |
|
223 | 223 | |
|
224 | 224 | self.__driver.saveFigure(self.fig, filename, *args) |
|
225 | 225 | |
|
226 | 226 | |
|
227 | 227 | |
|
228 | 228 | |
|
229 | 229 | def getNameToFtp(self, thisDatetime, FTP_WEI, EXP_CODE, SUB_EXP_CODE, PLOT_CODE, PLOT_POS): |
|
230 | 230 | YEAR_STR = '%4.4d'%thisDatetime.timetuple().tm_year |
|
231 | 231 | DOY_STR = '%3.3d'%thisDatetime.timetuple().tm_yday |
|
232 | 232 | FTP_WEI = '%2.2d'%FTP_WEI |
|
233 | 233 | EXP_CODE = '%3.3d'%EXP_CODE |
|
234 | 234 | SUB_EXP_CODE = '%2.2d'%SUB_EXP_CODE |
|
235 | 235 | PLOT_CODE = '%2.2d'%PLOT_CODE |
|
236 | 236 | PLOT_POS = '%2.2d'%PLOT_POS |
|
237 | 237 | name = YEAR_STR + DOY_STR + FTP_WEI + EXP_CODE + SUB_EXP_CODE + PLOT_CODE + PLOT_POS |
|
238 | 238 | return name |
|
239 | 239 | |
|
240 | 240 | def draw(self): |
|
241 | 241 | |
|
242 | 242 | self.__driver.draw(self.fig) |
|
243 | 243 | |
|
244 | 244 | def run(self): |
|
245 | 245 | |
|
246 | 246 | raise ValueError, "This method is not implemented" |
|
247 | 247 | |
|
248 | 248 | def close(self): |
|
249 | 249 | |
|
250 | 250 | self.__driver.show(True) |
|
251 | 251 | |
|
252 | 252 | axesList = property(getAxesObjList) |
|
253 | 253 | |
|
254 | 254 | |
|
255 | 255 | class Axes: |
|
256 | 256 | |
|
257 | 257 | __driver = mpldriver |
|
258 | 258 | fig = None |
|
259 | 259 | ax = None |
|
260 | 260 | plot = None |
|
261 | 261 | __missing = 1E30 |
|
262 | 262 | __firsttime = None |
|
263 | 263 | |
|
264 | 264 | __showprofile = False |
|
265 | 265 | |
|
266 | 266 | xmin = None |
|
267 | 267 | xmax = None |
|
268 | 268 | ymin = None |
|
269 | 269 | ymax = None |
|
270 | 270 | zmin = None |
|
271 | 271 | zmax = None |
|
272 | 272 | |
|
273 | 273 | x_buffer = None |
|
274 | 274 | z_buffer = None |
|
275 | 275 | |
|
276 | 276 | decimationx = None |
|
277 | 277 | decimationy = None |
|
278 | 278 | |
|
279 | 279 | __MAXNUMX = 300 |
|
280 | 280 | __MAXNUMY = 150 |
|
281 | 281 | |
|
282 | 282 | def __init__(self, *args): |
|
283 | 283 | |
|
284 | 284 | """ |
|
285 | 285 | |
|
286 | 286 | Input: |
|
287 | 287 | *args : Los parametros necesarios son |
|
288 | 288 | fig, nrow, ncol, xpos, ypos, colspan, rowspan |
|
289 | 289 | """ |
|
290 | 290 | |
|
291 | 291 | ax = self.__driver.createAxes(*args) |
|
292 | 292 | self.fig = args[0] |
|
293 | 293 | self.ax = ax |
|
294 | 294 | self.plot = None |
|
295 | 295 | |
|
296 | 296 | self.__firsttime = True |
|
297 | 297 | self.idlineList = [] |
|
298 | 298 | |
|
299 | 299 | self.x_buffer = numpy.array([]) |
|
300 | 300 | self.z_buffer = numpy.array([]) |
|
301 | 301 | |
|
302 | 302 | def setText(self, text): |
|
303 | 303 | |
|
304 | 304 | self.__driver.setAxesText(self.ax, text) |
|
305 | 305 | |
|
306 | 306 | def setXAxisAsTime(self): |
|
307 | 307 | pass |
|
308 | 308 | |
|
309 | 309 | def pline(self, x, y, |
|
310 | 310 | xmin=None, xmax=None, |
|
311 | 311 | ymin=None, ymax=None, |
|
312 | 312 | xlabel='', ylabel='', |
|
313 | 313 | title='', |
|
314 | 314 | **kwargs): |
|
315 | 315 | |
|
316 | 316 | """ |
|
317 | 317 | |
|
318 | 318 | Input: |
|
319 | 319 | x : |
|
320 | 320 | y : |
|
321 | 321 | xmin : |
|
322 | 322 | xmax : |
|
323 | 323 | ymin : |
|
324 | 324 | ymax : |
|
325 | 325 | xlabel : |
|
326 | 326 | ylabel : |
|
327 | 327 | title : |
|
328 | 328 | **kwargs : Los parametros aceptados son |
|
329 | 329 | |
|
330 | 330 | ticksize |
|
331 | 331 | ytick_visible |
|
332 | 332 | """ |
|
333 | 333 | |
|
334 | 334 | if self.__firsttime: |
|
335 | 335 | |
|
336 | 336 | if xmin == None: xmin = numpy.nanmin(x) |
|
337 | 337 | if xmax == None: xmax = numpy.nanmax(x) |
|
338 | 338 | if ymin == None: ymin = numpy.nanmin(y) |
|
339 | 339 | if ymax == None: ymax = numpy.nanmax(y) |
|
340 | 340 | |
|
341 | 341 | self.plot = self.__driver.createPline(self.ax, x, y, |
|
342 | 342 | xmin, xmax, |
|
343 | 343 | ymin, ymax, |
|
344 | 344 | xlabel=xlabel, |
|
345 | 345 | ylabel=ylabel, |
|
346 | 346 | title=title, |
|
347 | 347 | **kwargs) |
|
348 | 348 | |
|
349 | 349 | self.idlineList.append(0) |
|
350 | 350 | self.__firsttime = False |
|
351 | 351 | return |
|
352 | 352 | |
|
353 | 353 | self.__driver.pline(self.plot, x, y, xlabel=xlabel, |
|
354 | 354 | ylabel=ylabel, |
|
355 | 355 | title=title) |
|
356 | 356 | |
|
357 | 357 | def addpline(self, x, y, idline, **kwargs): |
|
358 | 358 | lines = self.ax.lines |
|
359 | 359 | |
|
360 | 360 | if idline in self.idlineList: |
|
361 | 361 | self.__driver.set_linedata(self.ax, x, y, idline) |
|
362 | 362 | |
|
363 | 363 | if idline not in(self.idlineList): |
|
364 | 364 | self.__driver.addpline(self.ax, x, y, **kwargs) |
|
365 | 365 | self.idlineList.append(idline) |
|
366 | 366 | |
|
367 | 367 | return |
|
368 | 368 | |
|
369 | 369 | def pmultiline(self, x, y, |
|
370 | 370 | xmin=None, xmax=None, |
|
371 | 371 | ymin=None, ymax=None, |
|
372 | 372 | xlabel='', ylabel='', |
|
373 | 373 | title='', |
|
374 | 374 | **kwargs): |
|
375 | 375 | |
|
376 | 376 | if self.__firsttime: |
|
377 | 377 | |
|
378 | 378 | if xmin == None: xmin = numpy.nanmin(x) |
|
379 | 379 | if xmax == None: xmax = numpy.nanmax(x) |
|
380 | 380 | if ymin == None: ymin = numpy.nanmin(y) |
|
381 | 381 | if ymax == None: ymax = numpy.nanmax(y) |
|
382 | 382 | |
|
383 | 383 | self.plot = self.__driver.createPmultiline(self.ax, x, y, |
|
384 | 384 | xmin, xmax, |
|
385 | 385 | ymin, ymax, |
|
386 | 386 | xlabel=xlabel, |
|
387 | 387 | ylabel=ylabel, |
|
388 | 388 | title=title, |
|
389 | 389 | **kwargs) |
|
390 | 390 | self.__firsttime = False |
|
391 | 391 | return |
|
392 | 392 | |
|
393 | 393 | self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel, |
|
394 | 394 | ylabel=ylabel, |
|
395 | 395 | title=title) |
|
396 | 396 | |
|
397 | 397 | def pmultilineyaxis(self, x, y, |
|
398 | 398 | xmin=None, xmax=None, |
|
399 | 399 | ymin=None, ymax=None, |
|
400 | 400 | xlabel='', ylabel='', |
|
401 | 401 | title='', |
|
402 | 402 | **kwargs): |
|
403 | 403 | |
|
404 | 404 | if self.__firsttime: |
|
405 | 405 | |
|
406 | 406 | if xmin == None: xmin = numpy.nanmin(x) |
|
407 | 407 | if xmax == None: xmax = numpy.nanmax(x) |
|
408 | 408 | if ymin == None: ymin = numpy.nanmin(y) |
|
409 | 409 | if ymax == None: ymax = numpy.nanmax(y) |
|
410 | 410 | |
|
411 | 411 | self.plot = self.__driver.createPmultilineYAxis(self.ax, x, y, |
|
412 | 412 | xmin, xmax, |
|
413 | 413 | ymin, ymax, |
|
414 | 414 | xlabel=xlabel, |
|
415 | 415 | ylabel=ylabel, |
|
416 | 416 | title=title, |
|
417 | 417 | **kwargs) |
|
418 | 418 | if self.xmin == None: self.xmin = xmin |
|
419 | 419 | if self.xmax == None: self.xmax = xmax |
|
420 | 420 | if self.ymin == None: self.ymin = ymin |
|
421 | 421 | if self.ymax == None: self.ymax = ymax |
|
422 | 422 | |
|
423 | 423 | self.__firsttime = False |
|
424 | 424 | return |
|
425 | 425 | |
|
426 | 426 | self.__driver.pmultilineyaxis(self.plot, x, y, xlabel=xlabel, |
|
427 | 427 | ylabel=ylabel, |
|
428 | 428 | title=title) |
|
429 | 429 | |
|
430 | 430 | def pcolor(self, x, y, z, |
|
431 | 431 | xmin=None, xmax=None, |
|
432 | 432 | ymin=None, ymax=None, |
|
433 | 433 | zmin=None, zmax=None, |
|
434 | 434 | xlabel='', ylabel='', |
|
435 | 435 | title='', rti = False, colormap='jet', |
|
436 | 436 | **kwargs): |
|
437 | 437 | |
|
438 | 438 | """ |
|
439 | 439 | Input: |
|
440 | 440 | x : |
|
441 | 441 | y : |
|
442 | 442 | x : |
|
443 | 443 | xmin : |
|
444 | 444 | xmax : |
|
445 | 445 | ymin : |
|
446 | 446 | ymax : |
|
447 | 447 | zmin : |
|
448 | 448 | zmax : |
|
449 | 449 | xlabel : |
|
450 | 450 | ylabel : |
|
451 | 451 | title : |
|
452 | 452 | **kwargs : Los parametros aceptados son |
|
453 | 453 | ticksize=9, |
|
454 | 454 | cblabel='' |
|
455 | 455 | rti = True or False |
|
456 | 456 | """ |
|
457 | 457 | |
|
458 | 458 | if self.__firsttime: |
|
459 | 459 | |
|
460 | 460 | if xmin == None: xmin = numpy.nanmin(x) |
|
461 | 461 | if xmax == None: xmax = numpy.nanmax(x) |
|
462 | 462 | if ymin == None: ymin = numpy.nanmin(y) |
|
463 | 463 | if ymax == None: ymax = numpy.nanmax(y) |
|
464 | 464 | if zmin == None: zmin = numpy.nanmin(z) |
|
465 | 465 | if zmax == None: zmax = numpy.nanmax(z) |
|
466 | 466 | |
|
467 | 467 | |
|
468 | 468 | self.plot = self.__driver.createPcolor(self.ax, x, y, z, |
|
469 | 469 | xmin, xmax, |
|
470 | 470 | ymin, ymax, |
|
471 | 471 | zmin, zmax, |
|
472 | 472 | xlabel=xlabel, |
|
473 | 473 | ylabel=ylabel, |
|
474 | 474 | title=title, |
|
475 | 475 | colormap=colormap, |
|
476 | 476 | **kwargs) |
|
477 | 477 | |
|
478 | 478 | if self.xmin == None: self.xmin = xmin |
|
479 | 479 | if self.xmax == None: self.xmax = xmax |
|
480 | 480 | if self.ymin == None: self.ymin = ymin |
|
481 | 481 | if self.ymax == None: self.ymax = ymax |
|
482 | 482 | if self.zmin == None: self.zmin = zmin |
|
483 | 483 | if self.zmax == None: self.zmax = zmax |
|
484 | 484 | |
|
485 | 485 | self.__firsttime = False |
|
486 | 486 | return |
|
487 | 487 | |
|
488 | 488 | if rti: |
|
489 | 489 | self.__driver.addpcolor(self.ax, x, y, z, self.zmin, self.zmax, |
|
490 | 490 | xlabel=xlabel, |
|
491 | 491 | ylabel=ylabel, |
|
492 | 492 | title=title, |
|
493 | 493 | colormap=colormap) |
|
494 | 494 | return |
|
495 | 495 | |
|
496 | 496 | self.__driver.pcolor(self.plot, z, |
|
497 | 497 | xlabel=xlabel, |
|
498 | 498 | ylabel=ylabel, |
|
499 | 499 | title=title) |
|
500 | 500 | |
|
501 | 501 | def pcolorbuffer(self, x, y, z, |
|
502 | 502 | xmin=None, xmax=None, |
|
503 | 503 | ymin=None, ymax=None, |
|
504 | 504 | zmin=None, zmax=None, |
|
505 | 505 | xlabel='', ylabel='', |
|
506 | 506 | title='', rti = True, colormap='jet', |
|
507 | 507 | maxNumX = None, maxNumY = None, |
|
508 | 508 | **kwargs): |
|
509 | 509 | |
|
510 | 510 | if maxNumX == None: |
|
511 | 511 | maxNumX = self.__MAXNUMX |
|
512 | 512 | |
|
513 | 513 | if maxNumY == None: |
|
514 | 514 | maxNumY = self.__MAXNUMY |
|
515 | 515 | |
|
516 | 516 | if self.__firsttime: |
|
517 | 517 | self.z_buffer = z |
|
518 | 518 | self.x_buffer = numpy.hstack((self.x_buffer, x)) |
|
519 | 519 | |
|
520 | 520 | if xmin == None: xmin = numpy.nanmin(x) |
|
521 | 521 | if xmax == None: xmax = numpy.nanmax(x) |
|
522 | 522 | if ymin == None: ymin = numpy.nanmin(y) |
|
523 | 523 | if ymax == None: ymax = numpy.nanmax(y) |
|
524 | 524 | if zmin == None: zmin = numpy.nanmin(z) |
|
525 | 525 | if zmax == None: zmax = numpy.nanmax(z) |
|
526 | 526 | |
|
527 | 527 | |
|
528 | 528 | self.plot = self.__driver.createPcolor(self.ax, self.x_buffer, y, z, |
|
529 | 529 | xmin, xmax, |
|
530 | 530 | ymin, ymax, |
|
531 | 531 | zmin, zmax, |
|
532 | 532 | xlabel=xlabel, |
|
533 | 533 | ylabel=ylabel, |
|
534 | 534 | title=title, |
|
535 | 535 | colormap=colormap, |
|
536 | 536 | **kwargs) |
|
537 | 537 | |
|
538 | 538 | if self.xmin == None: self.xmin = xmin |
|
539 | 539 | if self.xmax == None: self.xmax = xmax |
|
540 | 540 | if self.ymin == None: self.ymin = ymin |
|
541 | 541 | if self.ymax == None: self.ymax = ymax |
|
542 | 542 | if self.zmin == None: self.zmin = zmin |
|
543 | 543 | if self.zmax == None: self.zmax = zmax |
|
544 | 544 | |
|
545 | 545 | self.__firsttime = False |
|
546 | 546 | return |
|
547 | 547 | |
|
548 | 548 | self.x_buffer = numpy.hstack((self.x_buffer, x[-1])) |
|
549 | 549 | self.z_buffer = numpy.hstack((self.z_buffer, z)) |
|
550 | 550 | |
|
551 | 551 | if self.decimationx == None: |
|
552 | 552 | deltax = float(self.xmax - self.xmin)/maxNumX |
|
553 | 553 | deltay = float(self.ymax - self.ymin)/maxNumY |
|
554 | 554 | |
|
555 | 555 | resolutionx = self.x_buffer[2]-self.x_buffer[0] |
|
556 | 556 | resolutiony = y[1]-y[0] |
|
557 | 557 | |
|
558 | 558 | self.decimationx = numpy.ceil(deltax / resolutionx) |
|
559 | 559 | self.decimationy = numpy.ceil(deltay / resolutiony) |
|
560 | 560 | |
|
561 | 561 | z_buffer = self.z_buffer.reshape(-1,len(y)) |
|
562 | 562 | |
|
563 | 563 | x_buffer = self.x_buffer[::self.decimationx] |
|
564 | 564 | y_buffer = y[::self.decimationy] |
|
565 | 565 | z_buffer = z_buffer[::self.decimationx, ::self.decimationy] |
|
566 | 566 | #=================================================== |
|
567 | 567 | |
|
568 | 568 | x_buffer, y_buffer, z_buffer = self.__fillGaps(x_buffer, y_buffer, z_buffer) |
|
569 | 569 | |
|
570 | 570 | self.__driver.addpcolorbuffer(self.ax, x_buffer, y_buffer, z_buffer, self.zmin, self.zmax, |
|
571 | 571 | xlabel=xlabel, |
|
572 | 572 | ylabel=ylabel, |
|
573 | 573 | title=title, |
|
574 | 574 | colormap=colormap) |
|
575 | ||
|
576 | def polar(self, x, y, | |
|
577 | title='', xlabel='',ylabel='',**kwargs): | |
|
578 | ||
|
579 | if self.__firsttime: | |
|
580 | self.plot = self.__driver.createPolar(self.ax, x, y, title = title, xlabel = xlabel, ylabel = ylabel) | |
|
581 | self.__firsttime = False | |
|
582 | self.x_buffer = x | |
|
583 | self.y_buffer = y | |
|
584 | return | |
|
585 | ||
|
586 | self.x_buffer = numpy.hstack((self.x_buffer,x)) | |
|
587 | self.y_buffer = numpy.hstack((self.y_buffer,y)) | |
|
588 | self.__driver.polar(self.plot, self.x_buffer, self.y_buffer, xlabel=xlabel, | |
|
589 | ylabel=ylabel, | |
|
590 | title=title) | |
|
591 | ||
|
575 | 592 | def __fillGaps(self, x_buffer, y_buffer, z_buffer): |
|
576 | 593 | |
|
577 | 594 | deltas = x_buffer[1:] - x_buffer[0:-1] |
|
578 | 595 | x_median = numpy.median(deltas) |
|
579 | 596 | |
|
580 | 597 | index = numpy.where(deltas >= 2*x_median) |
|
581 | 598 | |
|
582 | 599 | if len(index[0]) != 0: |
|
583 | 600 | z_buffer[index[0],::] = self.__missing |
|
584 | 601 | z_buffer = numpy.ma.masked_inside(z_buffer,0.99*self.__missing,1.01*self.__missing) |
|
585 | 602 | |
|
586 | 603 | return x_buffer, y_buffer, z_buffer |
|
587 | 604 | |
|
588 | 605 | |
|
589 | 606 | |
|
590 | 607 | No newline at end of file |
@@ -1,3 +1,5 | |||
|
1 | 1 | from jroplot_voltage import * |
|
2 | 2 | from jroplot_spectra import * |
|
3 | 3 | from jroplot_heispectra import * |
|
4 | from jroplot_correlation import * | |
|
5 | from jroplot_parameters import * No newline at end of file |
@@ -1,1357 +1,1357 | |||
|
1 | 1 | ''' |
|
2 | 2 | @author: Daniel Suarez |
|
3 | 3 | ''' |
|
4 | 4 | import os |
|
5 | 5 | import datetime |
|
6 | 6 | import numpy |
|
7 | 7 | |
|
8 | 8 | from figure import Figure, isRealtime |
|
9 | 9 | |
|
10 | 10 | class SpectraPlot(Figure): |
|
11 | 11 | |
|
12 | 12 | isConfig = None |
|
13 | 13 | __nsubplots = None |
|
14 | 14 | |
|
15 | 15 | WIDTHPROF = None |
|
16 | 16 | HEIGHTPROF = None |
|
17 | 17 | PREFIX = 'spc' |
|
18 | 18 | |
|
19 | 19 | def __init__(self): |
|
20 | 20 | |
|
21 | 21 | self.isConfig = False |
|
22 | 22 | self.__nsubplots = 1 |
|
23 | 23 | |
|
24 | 24 | self.WIDTH = 280 |
|
25 | 25 | self.HEIGHT = 250 |
|
26 | 26 | self.WIDTHPROF = 120 |
|
27 | 27 | self.HEIGHTPROF = 0 |
|
28 | 28 | self.counter_imagwr = 0 |
|
29 | 29 | |
|
30 | 30 | self.PLOT_CODE = 1 |
|
31 | 31 | self.FTP_WEI = None |
|
32 | 32 | self.EXP_CODE = None |
|
33 | 33 | self.SUB_EXP_CODE = None |
|
34 | 34 | self.PLOT_POS = None |
|
35 | 35 | |
|
36 | 36 | def getSubplots(self): |
|
37 | 37 | |
|
38 | 38 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
39 | 39 | nrow = int(self.nplots*1./ncol + 0.9) |
|
40 | 40 | |
|
41 | 41 | return nrow, ncol |
|
42 | 42 | |
|
43 | 43 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
44 | 44 | |
|
45 | 45 | self.__showprofile = showprofile |
|
46 | 46 | self.nplots = nplots |
|
47 | 47 | |
|
48 | 48 | ncolspan = 1 |
|
49 | 49 | colspan = 1 |
|
50 | 50 | if showprofile: |
|
51 | 51 | ncolspan = 3 |
|
52 | 52 | colspan = 2 |
|
53 | 53 | self.__nsubplots = 2 |
|
54 | 54 | |
|
55 | 55 | self.createFigure(id = id, |
|
56 | 56 | wintitle = wintitle, |
|
57 | 57 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
58 | 58 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
59 | 59 | show=show) |
|
60 | 60 | |
|
61 | 61 | nrow, ncol = self.getSubplots() |
|
62 | 62 | |
|
63 | 63 | counter = 0 |
|
64 | 64 | for y in range(nrow): |
|
65 | 65 | for x in range(ncol): |
|
66 | 66 | |
|
67 | 67 | if counter >= self.nplots: |
|
68 | 68 | break |
|
69 | 69 | |
|
70 | 70 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
71 | 71 | |
|
72 | 72 | if showprofile: |
|
73 | 73 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
74 | 74 | |
|
75 | 75 | counter += 1 |
|
76 | 76 | |
|
77 | 77 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, |
|
78 | 78 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
79 | 79 | save=False, figpath='', figfile=None, show=True, ftp=False, wr_period=1, |
|
80 | 80 | server=None, folder=None, username=None, password=None, |
|
81 | 81 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): |
|
82 | 82 | |
|
83 | 83 | """ |
|
84 | 84 | |
|
85 | 85 | Input: |
|
86 | 86 | dataOut : |
|
87 | 87 | id : |
|
88 | 88 | wintitle : |
|
89 | 89 | channelList : |
|
90 | 90 | showProfile : |
|
91 | 91 | xmin : None, |
|
92 | 92 | xmax : None, |
|
93 | 93 | ymin : None, |
|
94 | 94 | ymax : None, |
|
95 | 95 | zmin : None, |
|
96 | 96 | zmax : None |
|
97 | 97 | """ |
|
98 | 98 | |
|
99 | 99 | if dataOut.flagNoData: |
|
100 | 100 | return None |
|
101 | 101 | |
|
102 | 102 | if realtime: |
|
103 | 103 | if not(isRealtime(utcdatatime = dataOut.utctime)): |
|
104 | 104 | print 'Skipping this plot function' |
|
105 | 105 | return |
|
106 | 106 | |
|
107 | 107 | if channelList == None: |
|
108 | 108 | channelIndexList = dataOut.channelIndexList |
|
109 | 109 | else: |
|
110 | 110 | channelIndexList = [] |
|
111 | 111 | for channel in channelList: |
|
112 | 112 | if channel not in dataOut.channelList: |
|
113 | 113 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
114 | 114 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
115 | 115 | |
|
116 | 116 | factor = dataOut.normFactor |
|
117 | 117 | |
|
118 | 118 | x = dataOut.getVelRange(1) |
|
119 | 119 | y = dataOut.getHeiRange() |
|
120 | 120 | |
|
121 | 121 | z = dataOut.data_spc[channelIndexList,:,:]/factor |
|
122 | 122 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
123 | 123 | avg = numpy.average(z, axis=1) |
|
124 | avg = numpy.nanmean(z, axis=1) | |
|
124 | #avg = numpy.nanmean(z, axis=1) | |
|
125 | 125 | noise = dataOut.noise/factor |
|
126 | 126 | |
|
127 | 127 | zdB = 10*numpy.log10(z) |
|
128 | 128 | avgdB = 10*numpy.log10(avg) |
|
129 | 129 | noisedB = 10*numpy.log10(noise) |
|
130 | 130 | |
|
131 | 131 | #thisDatetime = dataOut.datatime |
|
132 | 132 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
133 | 133 | title = wintitle + " Spectra" |
|
134 | 134 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
135 | 135 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) |
|
136 | 136 | |
|
137 | 137 | xlabel = "Velocity (m/s)" |
|
138 | 138 | ylabel = "Range (Km)" |
|
139 | 139 | |
|
140 | 140 | if not self.isConfig: |
|
141 | 141 | |
|
142 | 142 | nplots = len(channelIndexList) |
|
143 | 143 | |
|
144 | 144 | self.setup(id=id, |
|
145 | 145 | nplots=nplots, |
|
146 | 146 | wintitle=wintitle, |
|
147 | 147 | showprofile=showprofile, |
|
148 | 148 | show=show) |
|
149 | 149 | |
|
150 | 150 | if xmin == None: xmin = numpy.nanmin(x) |
|
151 | 151 | if xmax == None: xmax = numpy.nanmax(x) |
|
152 | 152 | if ymin == None: ymin = numpy.nanmin(y) |
|
153 | 153 | if ymax == None: ymax = numpy.nanmax(y) |
|
154 | 154 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
155 | 155 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
156 | 156 | |
|
157 | 157 | self.FTP_WEI = ftp_wei |
|
158 | 158 | self.EXP_CODE = exp_code |
|
159 | 159 | self.SUB_EXP_CODE = sub_exp_code |
|
160 | 160 | self.PLOT_POS = plot_pos |
|
161 | 161 | |
|
162 | 162 | self.isConfig = True |
|
163 | 163 | |
|
164 | 164 | self.setWinTitle(title) |
|
165 | 165 | |
|
166 | 166 | for i in range(self.nplots): |
|
167 | 167 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
168 | 168 | title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i]+1, noisedB[i], str_datetime) |
|
169 | 169 | if len(dataOut.beam.codeList) != 0: |
|
170 | 170 | title = "Ch%d:%4.2fdB,%2.2f,%2.2f:%s" %(dataOut.channelList[i]+1, noisedB[i], dataOut.beam.azimuthList[i], dataOut.beam.zenithList[i], str_datetime) |
|
171 | 171 | |
|
172 | 172 | axes = self.axesList[i*self.__nsubplots] |
|
173 | 173 | axes.pcolor(x, y, zdB[i,:,:], |
|
174 | 174 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
175 | 175 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
176 | 176 | ticksize=9, cblabel='') |
|
177 | 177 | |
|
178 | 178 | if self.__showprofile: |
|
179 | 179 | axes = self.axesList[i*self.__nsubplots +1] |
|
180 | 180 | axes.pline(avgdB[i], y, |
|
181 | 181 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
182 | 182 | xlabel='dB', ylabel='', title='', |
|
183 | 183 | ytick_visible=False, |
|
184 | 184 | grid='x') |
|
185 | 185 | |
|
186 | 186 | noiseline = numpy.repeat(noisedB[i], len(y)) |
|
187 | 187 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) |
|
188 | 188 | |
|
189 | 189 | self.draw() |
|
190 | 190 | |
|
191 | 191 | if figfile == None: |
|
192 | 192 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
193 | 193 | figfile = self.getFilename(name = str_datetime) |
|
194 | 194 | name = str_datetime |
|
195 | 195 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
196 | 196 | name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith) |
|
197 | 197 | figfile = self.getFilename(name) |
|
198 | 198 | if figpath != '': |
|
199 | 199 | self.counter_imagwr += 1 |
|
200 | 200 | if (self.counter_imagwr>=wr_period): |
|
201 | 201 | # store png plot to local folder |
|
202 | 202 | self.saveFigure(figpath, figfile) |
|
203 | 203 | # store png plot to FTP server according to RT-Web format |
|
204 | 204 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
205 | 205 | ftp_filename = os.path.join(figpath, name) |
|
206 | 206 | self.saveFigure(figpath, ftp_filename) |
|
207 | 207 | self.counter_imagwr = 0 |
|
208 | 208 | |
|
209 | 209 | |
|
210 | 210 | class CrossSpectraPlot(Figure): |
|
211 | 211 | |
|
212 | 212 | isConfig = None |
|
213 | 213 | __nsubplots = None |
|
214 | 214 | |
|
215 | 215 | WIDTH = None |
|
216 | 216 | HEIGHT = None |
|
217 | 217 | WIDTHPROF = None |
|
218 | 218 | HEIGHTPROF = None |
|
219 | 219 | PREFIX = 'cspc' |
|
220 | 220 | |
|
221 | 221 | def __init__(self): |
|
222 | 222 | |
|
223 | 223 | self.isConfig = False |
|
224 | 224 | self.__nsubplots = 4 |
|
225 | 225 | self.counter_imagwr = 0 |
|
226 | 226 | self.WIDTH = 250 |
|
227 | 227 | self.HEIGHT = 250 |
|
228 | 228 | self.WIDTHPROF = 0 |
|
229 | 229 | self.HEIGHTPROF = 0 |
|
230 | 230 | |
|
231 | 231 | self.PLOT_CODE = 1 |
|
232 | 232 | self.FTP_WEI = None |
|
233 | 233 | self.EXP_CODE = None |
|
234 | 234 | self.SUB_EXP_CODE = None |
|
235 | 235 | self.PLOT_POS = None |
|
236 | 236 | |
|
237 | 237 | def getSubplots(self): |
|
238 | 238 | |
|
239 | 239 | ncol = 4 |
|
240 | 240 | nrow = self.nplots |
|
241 | 241 | |
|
242 | 242 | return nrow, ncol |
|
243 | 243 | |
|
244 | 244 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
245 | 245 | |
|
246 | 246 | self.__showprofile = showprofile |
|
247 | 247 | self.nplots = nplots |
|
248 | 248 | |
|
249 | 249 | ncolspan = 1 |
|
250 | 250 | colspan = 1 |
|
251 | 251 | |
|
252 | 252 | self.createFigure(id = id, |
|
253 | 253 | wintitle = wintitle, |
|
254 | 254 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
255 | 255 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
256 | 256 | show=True) |
|
257 | 257 | |
|
258 | 258 | nrow, ncol = self.getSubplots() |
|
259 | 259 | |
|
260 | 260 | counter = 0 |
|
261 | 261 | for y in range(nrow): |
|
262 | 262 | for x in range(ncol): |
|
263 | 263 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
264 | 264 | |
|
265 | 265 | counter += 1 |
|
266 | 266 | |
|
267 | 267 | def run(self, dataOut, id, wintitle="", pairsList=None, |
|
268 | 268 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
269 | 269 | save=False, figpath='', figfile=None, ftp=False, wr_period=1, |
|
270 | 270 | power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True, |
|
271 | 271 | server=None, folder=None, username=None, password=None, |
|
272 | 272 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
273 | 273 | |
|
274 | 274 | """ |
|
275 | 275 | |
|
276 | 276 | Input: |
|
277 | 277 | dataOut : |
|
278 | 278 | id : |
|
279 | 279 | wintitle : |
|
280 | 280 | channelList : |
|
281 | 281 | showProfile : |
|
282 | 282 | xmin : None, |
|
283 | 283 | xmax : None, |
|
284 | 284 | ymin : None, |
|
285 | 285 | ymax : None, |
|
286 | 286 | zmin : None, |
|
287 | 287 | zmax : None |
|
288 | 288 | """ |
|
289 | 289 | |
|
290 | 290 | if pairsList == None: |
|
291 | 291 | pairsIndexList = dataOut.pairsIndexList |
|
292 | 292 | else: |
|
293 | 293 | pairsIndexList = [] |
|
294 | 294 | for pair in pairsList: |
|
295 | 295 | if pair not in dataOut.pairsList: |
|
296 | 296 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
297 | 297 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
298 | 298 | |
|
299 | 299 | if pairsIndexList == []: |
|
300 | 300 | return |
|
301 | 301 | |
|
302 | 302 | if len(pairsIndexList) > 4: |
|
303 | 303 | pairsIndexList = pairsIndexList[0:4] |
|
304 | 304 | factor = dataOut.normFactor |
|
305 | 305 | x = dataOut.getVelRange(1) |
|
306 | 306 | y = dataOut.getHeiRange() |
|
307 | 307 | z = dataOut.data_spc[:,:,:]/factor |
|
308 | 308 | # z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
309 | 309 | avg = numpy.abs(numpy.average(z, axis=1)) |
|
310 | 310 | noise = dataOut.noise()/factor |
|
311 | 311 | |
|
312 | 312 | zdB = 10*numpy.log10(z) |
|
313 | 313 | avgdB = 10*numpy.log10(avg) |
|
314 | 314 | noisedB = 10*numpy.log10(noise) |
|
315 | 315 | |
|
316 | 316 | |
|
317 | 317 | #thisDatetime = dataOut.datatime |
|
318 | 318 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
319 | 319 | title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
320 | 320 | xlabel = "Velocity (m/s)" |
|
321 | 321 | ylabel = "Range (Km)" |
|
322 | 322 | |
|
323 | 323 | if not self.isConfig: |
|
324 | 324 | |
|
325 | 325 | nplots = len(pairsIndexList) |
|
326 | 326 | |
|
327 | 327 | self.setup(id=id, |
|
328 | 328 | nplots=nplots, |
|
329 | 329 | wintitle=wintitle, |
|
330 | 330 | showprofile=False, |
|
331 | 331 | show=show) |
|
332 | 332 | |
|
333 | 333 | if xmin == None: xmin = numpy.nanmin(x) |
|
334 | 334 | if xmax == None: xmax = numpy.nanmax(x) |
|
335 | 335 | if ymin == None: ymin = numpy.nanmin(y) |
|
336 | 336 | if ymax == None: ymax = numpy.nanmax(y) |
|
337 | 337 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
338 | 338 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
339 | 339 | |
|
340 | 340 | self.FTP_WEI = ftp_wei |
|
341 | 341 | self.EXP_CODE = exp_code |
|
342 | 342 | self.SUB_EXP_CODE = sub_exp_code |
|
343 | 343 | self.PLOT_POS = plot_pos |
|
344 | 344 | |
|
345 | 345 | self.isConfig = True |
|
346 | 346 | |
|
347 | 347 | self.setWinTitle(title) |
|
348 | 348 | |
|
349 | 349 | for i in range(self.nplots): |
|
350 | 350 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
351 | 351 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
352 | 352 | title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[pair[0]], str_datetime) |
|
353 | 353 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]/factor) |
|
354 | 354 | axes0 = self.axesList[i*self.__nsubplots] |
|
355 | 355 | axes0.pcolor(x, y, zdB, |
|
356 | 356 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
357 | 357 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
358 | 358 | ticksize=9, colormap=power_cmap, cblabel='') |
|
359 | 359 | |
|
360 | 360 | title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[pair[1]], str_datetime) |
|
361 | 361 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]/factor) |
|
362 | 362 | axes0 = self.axesList[i*self.__nsubplots+1] |
|
363 | 363 | axes0.pcolor(x, y, zdB, |
|
364 | 364 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
365 | 365 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
366 | 366 | ticksize=9, colormap=power_cmap, cblabel='') |
|
367 | 367 | |
|
368 | 368 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) |
|
369 | 369 | coherence = numpy.abs(coherenceComplex) |
|
370 | 370 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi |
|
371 | 371 | phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi |
|
372 | 372 | |
|
373 | 373 | title = "Coherence %d%d" %(pair[0], pair[1]) |
|
374 | 374 | axes0 = self.axesList[i*self.__nsubplots+2] |
|
375 | 375 | axes0.pcolor(x, y, coherence, |
|
376 | 376 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1, |
|
377 | 377 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
378 | 378 | ticksize=9, colormap=coherence_cmap, cblabel='') |
|
379 | 379 | |
|
380 | 380 | title = "Phase %d%d" %(pair[0], pair[1]) |
|
381 | 381 | axes0 = self.axesList[i*self.__nsubplots+3] |
|
382 | 382 | axes0.pcolor(x, y, phase, |
|
383 | 383 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, |
|
384 | 384 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
385 | 385 | ticksize=9, colormap=phase_cmap, cblabel='') |
|
386 | 386 | |
|
387 | 387 | |
|
388 | 388 | |
|
389 | 389 | self.draw() |
|
390 | 390 | |
|
391 | 391 | if figfile == None: |
|
392 | 392 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
393 | 393 | figfile = self.getFilename(name = str_datetime) |
|
394 | 394 | |
|
395 | 395 | if figpath != '': |
|
396 | 396 | self.counter_imagwr += 1 |
|
397 | 397 | if (self.counter_imagwr>=wr_period): |
|
398 | 398 | # store png plot to local folder |
|
399 | 399 | self.saveFigure(figpath, figfile) |
|
400 | 400 | # store png plot to FTP server according to RT-Web format |
|
401 | 401 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
402 | 402 | ftp_filename = os.path.join(figpath, name) |
|
403 | 403 | self.saveFigure(figpath, ftp_filename) |
|
404 | 404 | self.counter_imagwr = 0 |
|
405 | 405 | |
|
406 | 406 | |
|
407 | 407 | class RTIPlot(Figure): |
|
408 | 408 | |
|
409 | 409 | isConfig = None |
|
410 | 410 | __nsubplots = None |
|
411 | 411 | |
|
412 | 412 | WIDTHPROF = None |
|
413 | 413 | HEIGHTPROF = None |
|
414 | 414 | PREFIX = 'rti' |
|
415 | 415 | |
|
416 | 416 | def __init__(self): |
|
417 | 417 | |
|
418 | 418 | self.timerange = 2*60*60 |
|
419 | 419 | self.isConfig = False |
|
420 | 420 | self.__nsubplots = 1 |
|
421 | 421 | |
|
422 | 422 | self.WIDTH = 800 |
|
423 | 423 | self.HEIGHT = 150 |
|
424 | 424 | self.WIDTHPROF = 120 |
|
425 | 425 | self.HEIGHTPROF = 0 |
|
426 | 426 | self.counter_imagwr = 0 |
|
427 | 427 | |
|
428 | 428 | self.PLOT_CODE = 0 |
|
429 | 429 | self.FTP_WEI = None |
|
430 | 430 | self.EXP_CODE = None |
|
431 | 431 | self.SUB_EXP_CODE = None |
|
432 | 432 | self.PLOT_POS = None |
|
433 | 433 | self.tmin = None |
|
434 | 434 | self.tmax = None |
|
435 | 435 | |
|
436 | 436 | self.xmin = None |
|
437 | 437 | self.xmax = None |
|
438 | 438 | |
|
439 | 439 | self.figfile = None |
|
440 | 440 | |
|
441 | 441 | def getSubplots(self): |
|
442 | 442 | |
|
443 | 443 | ncol = 1 |
|
444 | 444 | nrow = self.nplots |
|
445 | 445 | |
|
446 | 446 | return nrow, ncol |
|
447 | 447 | |
|
448 | 448 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
449 | 449 | |
|
450 | 450 | self.__showprofile = showprofile |
|
451 | 451 | self.nplots = nplots |
|
452 | 452 | |
|
453 | 453 | ncolspan = 1 |
|
454 | 454 | colspan = 1 |
|
455 | 455 | if showprofile: |
|
456 | 456 | ncolspan = 7 |
|
457 | 457 | colspan = 6 |
|
458 | 458 | self.__nsubplots = 2 |
|
459 | 459 | |
|
460 | 460 | self.createFigure(id = id, |
|
461 | 461 | wintitle = wintitle, |
|
462 | 462 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
463 | 463 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
464 | 464 | show=show) |
|
465 | 465 | |
|
466 | 466 | nrow, ncol = self.getSubplots() |
|
467 | 467 | |
|
468 | 468 | counter = 0 |
|
469 | 469 | for y in range(nrow): |
|
470 | 470 | for x in range(ncol): |
|
471 | 471 | |
|
472 | 472 | if counter >= self.nplots: |
|
473 | 473 | break |
|
474 | 474 | |
|
475 | 475 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
476 | 476 | |
|
477 | 477 | if showprofile: |
|
478 | 478 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
479 | 479 | |
|
480 | 480 | counter += 1 |
|
481 | 481 | |
|
482 | 482 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
483 | 483 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
484 | 484 | timerange=None, |
|
485 | 485 | save=False, figpath='', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
486 | 486 | server=None, folder=None, username=None, password=None, |
|
487 | 487 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
488 | 488 | |
|
489 | 489 | """ |
|
490 | 490 | |
|
491 | 491 | Input: |
|
492 | 492 | dataOut : |
|
493 | 493 | id : |
|
494 | 494 | wintitle : |
|
495 | 495 | channelList : |
|
496 | 496 | showProfile : |
|
497 | 497 | xmin : None, |
|
498 | 498 | xmax : None, |
|
499 | 499 | ymin : None, |
|
500 | 500 | ymax : None, |
|
501 | 501 | zmin : None, |
|
502 | 502 | zmax : None |
|
503 | 503 | """ |
|
504 | 504 | |
|
505 | 505 | if channelList == None: |
|
506 | 506 | channelIndexList = dataOut.channelIndexList |
|
507 | 507 | else: |
|
508 | 508 | channelIndexList = [] |
|
509 | 509 | for channel in channelList: |
|
510 | 510 | if channel not in dataOut.channelList: |
|
511 | 511 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
512 | 512 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
513 | 513 | |
|
514 | 514 | if timerange != None: |
|
515 | 515 | self.timerange = timerange |
|
516 | 516 | |
|
517 | 517 | #tmin = None |
|
518 | 518 | #tmax = None |
|
519 | 519 | factor = dataOut.normFactor |
|
520 | 520 | x = dataOut.getTimeRange() |
|
521 | 521 | y = dataOut.getHeiRange() |
|
522 | 522 | |
|
523 | 523 | z = dataOut.data_spc[channelIndexList,:,:]/factor |
|
524 | 524 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
525 | 525 | avg = numpy.average(z, axis=1) |
|
526 | 526 | |
|
527 | 527 | avgdB = 10.*numpy.log10(avg) |
|
528 | 528 | |
|
529 | 529 | |
|
530 | 530 | # thisDatetime = dataOut.datatime |
|
531 | 531 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
532 | 532 | title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
533 | 533 | xlabel = "" |
|
534 | 534 | ylabel = "Range (Km)" |
|
535 | 535 | |
|
536 | 536 | if not self.isConfig: |
|
537 | 537 | |
|
538 | 538 | nplots = len(channelIndexList) |
|
539 | 539 | |
|
540 | 540 | self.setup(id=id, |
|
541 | 541 | nplots=nplots, |
|
542 | 542 | wintitle=wintitle, |
|
543 | 543 | showprofile=showprofile, |
|
544 | 544 | show=show) |
|
545 | 545 | |
|
546 | 546 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
547 | 547 | |
|
548 | 548 | # if timerange != None: |
|
549 | 549 | # self.timerange = timerange |
|
550 | 550 | # self.xmin, self.tmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
551 | 551 | |
|
552 | 552 | |
|
553 | 553 | |
|
554 | 554 | if ymin == None: ymin = numpy.nanmin(y) |
|
555 | 555 | if ymax == None: ymax = numpy.nanmax(y) |
|
556 | 556 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
557 | 557 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
558 | 558 | |
|
559 | 559 | self.FTP_WEI = ftp_wei |
|
560 | 560 | self.EXP_CODE = exp_code |
|
561 | 561 | self.SUB_EXP_CODE = sub_exp_code |
|
562 | 562 | self.PLOT_POS = plot_pos |
|
563 | 563 | |
|
564 | 564 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
565 | 565 | self.isConfig = True |
|
566 | 566 | self.figfile = figfile |
|
567 | 567 | |
|
568 | 568 | self.setWinTitle(title) |
|
569 | 569 | |
|
570 | 570 | if ((self.xmax - x[1]) < (x[1]-x[0])): |
|
571 | 571 | x[1] = self.xmax |
|
572 | 572 | |
|
573 | 573 | for i in range(self.nplots): |
|
574 | 574 | title = "Channel %d: %s" %(dataOut.channelList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
575 | 575 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
576 | 576 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) |
|
577 | 577 | axes = self.axesList[i*self.__nsubplots] |
|
578 | 578 | zdB = avgdB[i].reshape((1,-1)) |
|
579 | 579 | axes.pcolorbuffer(x, y, zdB, |
|
580 | 580 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
581 | 581 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
582 | 582 | ticksize=9, cblabel='', cbsize="1%") |
|
583 | 583 | |
|
584 | 584 | if self.__showprofile: |
|
585 | 585 | axes = self.axesList[i*self.__nsubplots +1] |
|
586 | 586 | axes.pline(avgdB[i], y, |
|
587 | 587 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
588 | 588 | xlabel='dB', ylabel='', title='', |
|
589 | 589 | ytick_visible=False, |
|
590 | 590 | grid='x') |
|
591 | 591 | |
|
592 | 592 | self.draw() |
|
593 | 593 | |
|
594 | 594 | if x[1] >= self.axesList[0].xmax: |
|
595 | 595 | self.counter_imagwr = wr_period |
|
596 | 596 | self.__isConfig = False |
|
597 | 597 | |
|
598 | 598 | |
|
599 | 599 | if self.figfile == None: |
|
600 | 600 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
601 | 601 | self.figfile = self.getFilename(name = str_datetime) |
|
602 | 602 | |
|
603 | 603 | if figpath != '': |
|
604 | 604 | |
|
605 | 605 | self.counter_imagwr += 1 |
|
606 | 606 | if (self.counter_imagwr>=wr_period): |
|
607 | 607 | # store png plot to local folder |
|
608 | 608 | self.saveFigure(figpath, self.figfile) |
|
609 | 609 | # store png plot to FTP server according to RT-Web format |
|
610 | 610 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
611 | 611 | ftp_filename = os.path.join(figpath, name) |
|
612 | 612 | self.saveFigure(figpath, ftp_filename) |
|
613 | 613 | |
|
614 | 614 | self.counter_imagwr = 0 |
|
615 | 615 | |
|
616 | 616 | |
|
617 | 617 | class CoherenceMap(Figure): |
|
618 | 618 | isConfig = None |
|
619 | 619 | __nsubplots = None |
|
620 | 620 | |
|
621 | 621 | WIDTHPROF = None |
|
622 | 622 | HEIGHTPROF = None |
|
623 | 623 | PREFIX = 'cmap' |
|
624 | 624 | |
|
625 | 625 | def __init__(self): |
|
626 | 626 | self.timerange = 2*60*60 |
|
627 | 627 | self.isConfig = False |
|
628 | 628 | self.__nsubplots = 1 |
|
629 | 629 | |
|
630 | 630 | self.WIDTH = 800 |
|
631 | 631 | self.HEIGHT = 150 |
|
632 | 632 | self.WIDTHPROF = 120 |
|
633 | 633 | self.HEIGHTPROF = 0 |
|
634 | 634 | self.counter_imagwr = 0 |
|
635 | 635 | |
|
636 | 636 | self.PLOT_CODE = 3 |
|
637 | 637 | self.FTP_WEI = None |
|
638 | 638 | self.EXP_CODE = None |
|
639 | 639 | self.SUB_EXP_CODE = None |
|
640 | 640 | self.PLOT_POS = None |
|
641 | 641 | self.counter_imagwr = 0 |
|
642 | 642 | |
|
643 | 643 | self.xmin = None |
|
644 | 644 | self.xmax = None |
|
645 | 645 | |
|
646 | 646 | def getSubplots(self): |
|
647 | 647 | ncol = 1 |
|
648 | 648 | nrow = self.nplots*2 |
|
649 | 649 | |
|
650 | 650 | return nrow, ncol |
|
651 | 651 | |
|
652 | 652 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
653 | 653 | self.__showprofile = showprofile |
|
654 | 654 | self.nplots = nplots |
|
655 | 655 | |
|
656 | 656 | ncolspan = 1 |
|
657 | 657 | colspan = 1 |
|
658 | 658 | if showprofile: |
|
659 | 659 | ncolspan = 7 |
|
660 | 660 | colspan = 6 |
|
661 | 661 | self.__nsubplots = 2 |
|
662 | 662 | |
|
663 | 663 | self.createFigure(id = id, |
|
664 | 664 | wintitle = wintitle, |
|
665 | 665 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
666 | 666 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
667 | 667 | show=True) |
|
668 | 668 | |
|
669 | 669 | nrow, ncol = self.getSubplots() |
|
670 | 670 | |
|
671 | 671 | for y in range(nrow): |
|
672 | 672 | for x in range(ncol): |
|
673 | 673 | |
|
674 | 674 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
675 | 675 | |
|
676 | 676 | if showprofile: |
|
677 | 677 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
678 | 678 | |
|
679 | 679 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', |
|
680 | 680 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
681 | 681 | timerange=None, |
|
682 | 682 | save=False, figpath='', figfile=None, ftp=False, wr_period=1, |
|
683 | 683 | coherence_cmap='jet', phase_cmap='RdBu_r', show=True, |
|
684 | 684 | server=None, folder=None, username=None, password=None, |
|
685 | 685 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
686 | 686 | |
|
687 | 687 | if pairsList == None: |
|
688 | 688 | pairsIndexList = dataOut.pairsIndexList |
|
689 | 689 | else: |
|
690 | 690 | pairsIndexList = [] |
|
691 | 691 | for pair in pairsList: |
|
692 | 692 | if pair not in dataOut.pairsList: |
|
693 | 693 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
694 | 694 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
695 | 695 | |
|
696 | 696 | if timerange != None: |
|
697 | 697 | self.timerange = timerange |
|
698 | 698 | |
|
699 | 699 | if pairsIndexList == []: |
|
700 | 700 | return |
|
701 | 701 | |
|
702 | 702 | if len(pairsIndexList) > 4: |
|
703 | 703 | pairsIndexList = pairsIndexList[0:4] |
|
704 | 704 | |
|
705 | 705 | # tmin = None |
|
706 | 706 | # tmax = None |
|
707 | 707 | x = dataOut.getTimeRange() |
|
708 | 708 | y = dataOut.getHeiRange() |
|
709 | 709 | |
|
710 | 710 | #thisDatetime = dataOut.datatime |
|
711 | 711 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
712 | 712 | title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
713 | 713 | xlabel = "" |
|
714 | 714 | ylabel = "Range (Km)" |
|
715 | 715 | |
|
716 | 716 | if not self.isConfig: |
|
717 | 717 | nplots = len(pairsIndexList) |
|
718 | 718 | self.setup(id=id, |
|
719 | 719 | nplots=nplots, |
|
720 | 720 | wintitle=wintitle, |
|
721 | 721 | showprofile=showprofile, |
|
722 | 722 | show=show) |
|
723 | 723 | |
|
724 | 724 | #tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
725 | 725 | |
|
726 | 726 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
727 | 727 | |
|
728 | 728 | if ymin == None: ymin = numpy.nanmin(y) |
|
729 | 729 | if ymax == None: ymax = numpy.nanmax(y) |
|
730 | 730 | if zmin == None: zmin = 0. |
|
731 | 731 | if zmax == None: zmax = 1. |
|
732 | 732 | |
|
733 | 733 | self.FTP_WEI = ftp_wei |
|
734 | 734 | self.EXP_CODE = exp_code |
|
735 | 735 | self.SUB_EXP_CODE = sub_exp_code |
|
736 | 736 | self.PLOT_POS = plot_pos |
|
737 | 737 | |
|
738 | 738 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
739 | 739 | |
|
740 | 740 | self.isConfig = True |
|
741 | 741 | |
|
742 | 742 | self.setWinTitle(title) |
|
743 | 743 | |
|
744 | 744 | if ((self.xmax - x[1]) < (x[1]-x[0])): |
|
745 | 745 | x[1] = self.xmax |
|
746 | 746 | |
|
747 | 747 | for i in range(self.nplots): |
|
748 | 748 | |
|
749 | 749 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
750 | 750 | |
|
751 | 751 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0) |
|
752 | 752 | powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0) |
|
753 | 753 | powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0) |
|
754 | 754 | |
|
755 | 755 | |
|
756 | 756 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) |
|
757 | 757 | coherence = numpy.abs(avgcoherenceComplex) |
|
758 | 758 | |
|
759 | 759 | z = coherence.reshape((1,-1)) |
|
760 | 760 | |
|
761 | 761 | counter = 0 |
|
762 | 762 | |
|
763 | 763 | title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
764 | 764 | axes = self.axesList[i*self.__nsubplots*2] |
|
765 | 765 | axes.pcolorbuffer(x, y, z, |
|
766 | 766 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
767 | 767 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
768 | 768 | ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%") |
|
769 | 769 | |
|
770 | 770 | if self.__showprofile: |
|
771 | 771 | counter += 1 |
|
772 | 772 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
773 | 773 | axes.pline(coherence, y, |
|
774 | 774 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
775 | 775 | xlabel='', ylabel='', title='', ticksize=7, |
|
776 | 776 | ytick_visible=False, nxticks=5, |
|
777 | 777 | grid='x') |
|
778 | 778 | |
|
779 | 779 | counter += 1 |
|
780 | 780 | |
|
781 | 781 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi |
|
782 | 782 | |
|
783 | 783 | z = phase.reshape((1,-1)) |
|
784 | 784 | |
|
785 | 785 | title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
786 | 786 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
787 | 787 | axes.pcolorbuffer(x, y, z, |
|
788 | 788 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, |
|
789 | 789 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
790 | 790 | ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%") |
|
791 | 791 | |
|
792 | 792 | if self.__showprofile: |
|
793 | 793 | counter += 1 |
|
794 | 794 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
795 | 795 | axes.pline(phase, y, |
|
796 | 796 | xmin=-180, xmax=180, ymin=ymin, ymax=ymax, |
|
797 | 797 | xlabel='', ylabel='', title='', ticksize=7, |
|
798 | 798 | ytick_visible=False, nxticks=4, |
|
799 | 799 | grid='x') |
|
800 | 800 | |
|
801 | 801 | self.draw() |
|
802 | 802 | |
|
803 | 803 | if x[1] >= self.axesList[0].xmax: |
|
804 | 804 | self.counter_imagwr = wr_period |
|
805 | 805 | self.__isConfig = False |
|
806 | 806 | |
|
807 | 807 | if figfile == None: |
|
808 | 808 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
809 | 809 | figfile = self.getFilename(name = str_datetime) |
|
810 | 810 | |
|
811 | 811 | if figpath != '': |
|
812 | 812 | |
|
813 | 813 | self.counter_imagwr += 1 |
|
814 | 814 | if (self.counter_imagwr>=wr_period): |
|
815 | 815 | # store png plot to local folder |
|
816 | 816 | self.saveFigure(figpath, figfile) |
|
817 | 817 | # store png plot to FTP server according to RT-Web format |
|
818 | 818 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
819 | 819 | ftp_filename = os.path.join(figpath, name) |
|
820 | 820 | self.saveFigure(figpath, ftp_filename) |
|
821 | 821 | |
|
822 | 822 | self.counter_imagwr = 0 |
|
823 | 823 | |
|
824 | 824 | class PowerProfile(Figure): |
|
825 | 825 | isConfig = None |
|
826 | 826 | __nsubplots = None |
|
827 | 827 | |
|
828 | 828 | WIDTHPROF = None |
|
829 | 829 | HEIGHTPROF = None |
|
830 | 830 | PREFIX = 'spcprofile' |
|
831 | 831 | |
|
832 | 832 | def __init__(self): |
|
833 | 833 | self.isConfig = False |
|
834 | 834 | self.__nsubplots = 1 |
|
835 | 835 | |
|
836 | 836 | self.WIDTH = 300 |
|
837 | 837 | self.HEIGHT = 500 |
|
838 | 838 | self.counter_imagwr = 0 |
|
839 | 839 | |
|
840 | 840 | def getSubplots(self): |
|
841 | 841 | ncol = 1 |
|
842 | 842 | nrow = 1 |
|
843 | 843 | |
|
844 | 844 | return nrow, ncol |
|
845 | 845 | |
|
846 | 846 | def setup(self, id, nplots, wintitle, show): |
|
847 | 847 | |
|
848 | 848 | self.nplots = nplots |
|
849 | 849 | |
|
850 | 850 | ncolspan = 1 |
|
851 | 851 | colspan = 1 |
|
852 | 852 | |
|
853 | 853 | self.createFigure(id = id, |
|
854 | 854 | wintitle = wintitle, |
|
855 | 855 | widthplot = self.WIDTH, |
|
856 | 856 | heightplot = self.HEIGHT, |
|
857 | 857 | show=show) |
|
858 | 858 | |
|
859 | 859 | nrow, ncol = self.getSubplots() |
|
860 | 860 | |
|
861 | 861 | counter = 0 |
|
862 | 862 | for y in range(nrow): |
|
863 | 863 | for x in range(ncol): |
|
864 | 864 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
865 | 865 | |
|
866 | 866 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
867 | 867 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
868 | 868 | save=False, figpath='', figfile=None, show=True, wr_period=1, |
|
869 | 869 | server=None, folder=None, username=None, password=None,): |
|
870 | 870 | |
|
871 | 871 | if dataOut.flagNoData: |
|
872 | 872 | return None |
|
873 | 873 | |
|
874 | 874 | if channelList == None: |
|
875 | 875 | channelIndexList = dataOut.channelIndexList |
|
876 | 876 | channelList = dataOut.channelList |
|
877 | 877 | else: |
|
878 | 878 | channelIndexList = [] |
|
879 | 879 | for channel in channelList: |
|
880 | 880 | if channel not in dataOut.channelList: |
|
881 | 881 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
882 | 882 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
883 | 883 | |
|
884 | 884 | try: |
|
885 | 885 | factor = dataOut.normFactor |
|
886 | 886 | except: |
|
887 | 887 | factor = 1 |
|
888 | 888 | |
|
889 | 889 | y = dataOut.getHeiRange() |
|
890 | 890 | |
|
891 | 891 | #for voltage |
|
892 | 892 | if dataOut.type == 'Voltage': |
|
893 | 893 | x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) |
|
894 | 894 | x = x.real |
|
895 | 895 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) |
|
896 | 896 | |
|
897 | 897 | #for spectra |
|
898 | 898 | if dataOut.type == 'Spectra': |
|
899 | 899 | x = dataOut.data_spc[channelIndexList,:,:]/factor |
|
900 | 900 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) |
|
901 | 901 | x = numpy.average(x, axis=1) |
|
902 | 902 | |
|
903 | 903 | |
|
904 | 904 | xdB = 10*numpy.log10(x) |
|
905 | 905 | |
|
906 | 906 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
907 | 907 | title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
908 | 908 | xlabel = "dB" |
|
909 | 909 | ylabel = "Range (Km)" |
|
910 | 910 | |
|
911 | 911 | if not self.isConfig: |
|
912 | 912 | |
|
913 | 913 | nplots = 1 |
|
914 | 914 | |
|
915 | 915 | self.setup(id=id, |
|
916 | 916 | nplots=nplots, |
|
917 | 917 | wintitle=wintitle, |
|
918 | 918 | show=show) |
|
919 | 919 | |
|
920 | 920 | if ymin == None: ymin = numpy.nanmin(y) |
|
921 | 921 | if ymax == None: ymax = numpy.nanmax(y) |
|
922 | 922 | if xmin == None: xmin = numpy.nanmin(xdB)*0.9 |
|
923 | 923 | if xmax == None: xmax = numpy.nanmax(xdB)*0.9 |
|
924 | 924 | |
|
925 | 925 | self.__isConfig = True |
|
926 | 926 | |
|
927 | 927 | self.setWinTitle(title) |
|
928 | 928 | |
|
929 | 929 | title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
930 | 930 | axes = self.axesList[0] |
|
931 | 931 | |
|
932 | 932 | legendlabels = ["channel %d"%x for x in channelList] |
|
933 | 933 | axes.pmultiline(xdB, y, |
|
934 | 934 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
935 | 935 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, |
|
936 | 936 | ytick_visible=True, nxticks=5, |
|
937 | 937 | grid='x') |
|
938 | 938 | |
|
939 | 939 | self.draw() |
|
940 | 940 | |
|
941 | 941 | if figfile == None: |
|
942 | 942 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
943 | 943 | figfile = self.getFilename(name = str_datetime) |
|
944 | 944 | |
|
945 | 945 | if figpath != '': |
|
946 | 946 | self.counter_imagwr += 1 |
|
947 | 947 | if (self.counter_imagwr>=wr_period): |
|
948 | 948 | # store png plot to local folder |
|
949 | 949 | self.saveFigure(figpath, figfile) |
|
950 | 950 | # store png plot to FTP server according to RT-Web format |
|
951 | 951 | #name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
952 | 952 | #ftp_filename = os.path.join(figpath, name) |
|
953 | 953 | #self.saveFigure(figpath, ftp_filename) |
|
954 | 954 | self.counter_imagwr = 0 |
|
955 | 955 | |
|
956 | 956 | |
|
957 | 957 | |
|
958 | 958 | class Noise(Figure): |
|
959 | 959 | |
|
960 | 960 | isConfig = None |
|
961 | 961 | __nsubplots = None |
|
962 | 962 | |
|
963 | 963 | PREFIX = 'noise' |
|
964 | 964 | |
|
965 | 965 | def __init__(self): |
|
966 | 966 | |
|
967 | 967 | self.timerange = 24*60*60 |
|
968 | 968 | self.isConfig = False |
|
969 | 969 | self.__nsubplots = 1 |
|
970 | 970 | self.counter_imagwr = 0 |
|
971 | 971 | self.WIDTH = 600 |
|
972 | 972 | self.HEIGHT = 300 |
|
973 | 973 | self.WIDTHPROF = 120 |
|
974 | 974 | self.HEIGHTPROF = 0 |
|
975 | 975 | self.xdata = None |
|
976 | 976 | self.ydata = None |
|
977 | 977 | |
|
978 | 978 | self.PLOT_CODE = 17 |
|
979 | 979 | self.FTP_WEI = None |
|
980 | 980 | self.EXP_CODE = None |
|
981 | 981 | self.SUB_EXP_CODE = None |
|
982 | 982 | self.PLOT_POS = None |
|
983 | 983 | self.figfile = None |
|
984 | 984 | |
|
985 | 985 | def getSubplots(self): |
|
986 | 986 | |
|
987 | 987 | ncol = 1 |
|
988 | 988 | nrow = 1 |
|
989 | 989 | |
|
990 | 990 | return nrow, ncol |
|
991 | 991 | |
|
992 | 992 | def openfile(self, filename): |
|
993 | 993 | f = open(filename,'w+') |
|
994 | 994 | f.write('\n\n') |
|
995 | 995 | f.write('JICAMARCA RADIO OBSERVATORY - Noise \n') |
|
996 | 996 | f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' ) |
|
997 | 997 | f.close() |
|
998 | 998 | |
|
999 | 999 | def save_data(self, filename_phase, data, data_datetime): |
|
1000 | 1000 | f=open(filename_phase,'a') |
|
1001 | 1001 | timetuple_data = data_datetime.timetuple() |
|
1002 | 1002 | day = str(timetuple_data.tm_mday) |
|
1003 | 1003 | month = str(timetuple_data.tm_mon) |
|
1004 | 1004 | year = str(timetuple_data.tm_year) |
|
1005 | 1005 | hour = str(timetuple_data.tm_hour) |
|
1006 | 1006 | minute = str(timetuple_data.tm_min) |
|
1007 | 1007 | second = str(timetuple_data.tm_sec) |
|
1008 | 1008 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n') |
|
1009 | 1009 | f.close() |
|
1010 | 1010 | |
|
1011 | 1011 | |
|
1012 | 1012 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1013 | 1013 | |
|
1014 | 1014 | self.__showprofile = showprofile |
|
1015 | 1015 | self.nplots = nplots |
|
1016 | 1016 | |
|
1017 | 1017 | ncolspan = 7 |
|
1018 | 1018 | colspan = 6 |
|
1019 | 1019 | self.__nsubplots = 2 |
|
1020 | 1020 | |
|
1021 | 1021 | self.createFigure(id = id, |
|
1022 | 1022 | wintitle = wintitle, |
|
1023 | 1023 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1024 | 1024 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1025 | 1025 | show=show) |
|
1026 | 1026 | |
|
1027 | 1027 | nrow, ncol = self.getSubplots() |
|
1028 | 1028 | |
|
1029 | 1029 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1030 | 1030 | |
|
1031 | 1031 | |
|
1032 | 1032 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
1033 | 1033 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1034 | 1034 | timerange=None, |
|
1035 | 1035 | save=False, figpath='', figfile=None, show=True, ftp=False, wr_period=1, |
|
1036 | 1036 | server=None, folder=None, username=None, password=None, |
|
1037 | 1037 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1038 | 1038 | |
|
1039 | 1039 | if channelList == None: |
|
1040 | 1040 | channelIndexList = dataOut.channelIndexList |
|
1041 | 1041 | channelList = dataOut.channelList |
|
1042 | 1042 | else: |
|
1043 | 1043 | channelIndexList = [] |
|
1044 | 1044 | for channel in channelList: |
|
1045 | 1045 | if channel not in dataOut.channelList: |
|
1046 | 1046 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
1047 | 1047 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1048 | 1048 | |
|
1049 | 1049 | if timerange != None: |
|
1050 | 1050 | self.timerange = timerange |
|
1051 | 1051 | |
|
1052 | 1052 | tmin = None |
|
1053 | 1053 | tmax = None |
|
1054 | 1054 | x = dataOut.getTimeRange() |
|
1055 | 1055 | y = dataOut.getHeiRange() |
|
1056 | 1056 | factor = dataOut.normFactor |
|
1057 | 1057 | noise = dataOut.noise()/factor |
|
1058 | 1058 | noisedB = 10*numpy.log10(noise) |
|
1059 | 1059 | |
|
1060 | 1060 | #thisDatetime = dataOut.datatime |
|
1061 | 1061 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
1062 | 1062 | title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1063 | 1063 | xlabel = "" |
|
1064 | 1064 | ylabel = "Intensity (dB)" |
|
1065 | 1065 | |
|
1066 | 1066 | if not self.isConfig: |
|
1067 | 1067 | |
|
1068 | 1068 | nplots = 1 |
|
1069 | 1069 | |
|
1070 | 1070 | self.setup(id=id, |
|
1071 | 1071 | nplots=nplots, |
|
1072 | 1072 | wintitle=wintitle, |
|
1073 | 1073 | showprofile=showprofile, |
|
1074 | 1074 | show=show) |
|
1075 | 1075 | |
|
1076 | 1076 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
1077 | 1077 | if ymin == None: ymin = numpy.nanmin(noisedB) - 10.0 |
|
1078 | 1078 | if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0 |
|
1079 | 1079 | |
|
1080 | 1080 | self.FTP_WEI = ftp_wei |
|
1081 | 1081 | self.EXP_CODE = exp_code |
|
1082 | 1082 | self.SUB_EXP_CODE = sub_exp_code |
|
1083 | 1083 | self.PLOT_POS = plot_pos |
|
1084 | 1084 | |
|
1085 | 1085 | |
|
1086 | 1086 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1087 | 1087 | self.isConfig = True |
|
1088 | 1088 | self.figfile = figfile |
|
1089 | 1089 | self.xdata = numpy.array([]) |
|
1090 | 1090 | self.ydata = numpy.array([]) |
|
1091 | 1091 | |
|
1092 | 1092 | #open file beacon phase |
|
1093 | 1093 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1094 | 1094 | noise_file = os.path.join(path,'%s.txt'%self.name) |
|
1095 | 1095 | self.filename_noise = os.path.join(figpath,noise_file) |
|
1096 | 1096 | self.openfile(self.filename_noise) |
|
1097 | 1097 | |
|
1098 | 1098 | |
|
1099 | 1099 | #store data beacon phase |
|
1100 | 1100 | self.save_data(self.filename_noise, noisedB, thisDatetime) |
|
1101 | 1101 | |
|
1102 | 1102 | |
|
1103 | 1103 | self.setWinTitle(title) |
|
1104 | 1104 | |
|
1105 | 1105 | |
|
1106 | 1106 | title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1107 | 1107 | |
|
1108 | 1108 | legendlabels = ["channel %d"%(idchannel+1) for idchannel in channelList] |
|
1109 | 1109 | axes = self.axesList[0] |
|
1110 | 1110 | |
|
1111 | 1111 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1112 | 1112 | |
|
1113 | 1113 | if len(self.ydata)==0: |
|
1114 | 1114 | self.ydata = noisedB[channelIndexList].reshape(-1,1) |
|
1115 | 1115 | else: |
|
1116 | 1116 | self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1))) |
|
1117 | 1117 | |
|
1118 | 1118 | |
|
1119 | 1119 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1120 | 1120 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, |
|
1121 | 1121 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
1122 | 1122 | XAxisAsTime=True, grid='both' |
|
1123 | 1123 | ) |
|
1124 | 1124 | |
|
1125 | 1125 | self.draw() |
|
1126 | 1126 | |
|
1127 | 1127 | if x[1] >= self.axesList[0].xmax: |
|
1128 | 1128 | self.counter_imagwr = wr_period |
|
1129 | 1129 | del self.xdata |
|
1130 | 1130 | del self.ydata |
|
1131 | 1131 | self.__isConfig = False |
|
1132 | 1132 | |
|
1133 | 1133 | if self.figfile == None: |
|
1134 | 1134 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1135 | 1135 | self.figfile = self.getFilename(name = str_datetime) |
|
1136 | 1136 | |
|
1137 | 1137 | if figpath != '': |
|
1138 | 1138 | self.counter_imagwr += 1 |
|
1139 | 1139 | if (self.counter_imagwr>=wr_period): |
|
1140 | 1140 | # store png plot to local folder |
|
1141 | 1141 | self.saveFigure(figpath, self.figfile) |
|
1142 | 1142 | # store png plot to FTP server according to RT-Web format |
|
1143 | 1143 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
1144 | 1144 | ftp_filename = os.path.join(figpath, name) |
|
1145 | 1145 | self.saveFigure(figpath, ftp_filename) |
|
1146 | 1146 | self.counter_imagwr = 0 |
|
1147 | 1147 | |
|
1148 | 1148 | |
|
1149 | 1149 | class BeaconPhase(Figure): |
|
1150 | 1150 | |
|
1151 | 1151 | __isConfig = None |
|
1152 | 1152 | __nsubplots = None |
|
1153 | 1153 | |
|
1154 | 1154 | PREFIX = 'beacon_phase' |
|
1155 | 1155 | |
|
1156 | 1156 | def __init__(self): |
|
1157 | 1157 | |
|
1158 | 1158 | self.timerange = 24*60*60 |
|
1159 | 1159 | self.__isConfig = False |
|
1160 | 1160 | self.__nsubplots = 1 |
|
1161 | 1161 | self.counter_imagwr = 0 |
|
1162 | 1162 | self.WIDTH = 600 |
|
1163 | 1163 | self.HEIGHT = 300 |
|
1164 | 1164 | self.WIDTHPROF = 120 |
|
1165 | 1165 | self.HEIGHTPROF = 0 |
|
1166 | 1166 | self.xdata = None |
|
1167 | 1167 | self.ydata = None |
|
1168 | 1168 | |
|
1169 | 1169 | self.PLOT_CODE = 18 |
|
1170 | 1170 | self.FTP_WEI = None |
|
1171 | 1171 | self.EXP_CODE = None |
|
1172 | 1172 | self.SUB_EXP_CODE = None |
|
1173 | 1173 | self.PLOT_POS = None |
|
1174 | 1174 | |
|
1175 | 1175 | self.filename_phase = None |
|
1176 | 1176 | |
|
1177 | 1177 | self.figfile = None |
|
1178 | 1178 | |
|
1179 | 1179 | def getSubplots(self): |
|
1180 | 1180 | |
|
1181 | 1181 | ncol = 1 |
|
1182 | 1182 | nrow = 1 |
|
1183 | 1183 | |
|
1184 | 1184 | return nrow, ncol |
|
1185 | 1185 | |
|
1186 | 1186 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1187 | 1187 | |
|
1188 | 1188 | self.__showprofile = showprofile |
|
1189 | 1189 | self.nplots = nplots |
|
1190 | 1190 | |
|
1191 | 1191 | ncolspan = 7 |
|
1192 | 1192 | colspan = 6 |
|
1193 | 1193 | self.__nsubplots = 2 |
|
1194 | 1194 | |
|
1195 | 1195 | self.createFigure(id = id, |
|
1196 | 1196 | wintitle = wintitle, |
|
1197 | 1197 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1198 | 1198 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1199 | 1199 | show=show) |
|
1200 | 1200 | |
|
1201 | 1201 | nrow, ncol = self.getSubplots() |
|
1202 | 1202 | |
|
1203 | 1203 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1204 | 1204 | |
|
1205 | 1205 | def save_phase(self, filename_phase): |
|
1206 | 1206 | f = open(filename_phase,'w+') |
|
1207 | 1207 | f.write('\n\n') |
|
1208 | 1208 | f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n') |
|
1209 | 1209 | f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' ) |
|
1210 | 1210 | f.close() |
|
1211 | 1211 | |
|
1212 | 1212 | def save_data(self, filename_phase, data, data_datetime): |
|
1213 | 1213 | f=open(filename_phase,'a') |
|
1214 | 1214 | timetuple_data = data_datetime.timetuple() |
|
1215 | 1215 | day = str(timetuple_data.tm_mday) |
|
1216 | 1216 | month = str(timetuple_data.tm_mon) |
|
1217 | 1217 | year = str(timetuple_data.tm_year) |
|
1218 | 1218 | hour = str(timetuple_data.tm_hour) |
|
1219 | 1219 | minute = str(timetuple_data.tm_min) |
|
1220 | 1220 | second = str(timetuple_data.tm_sec) |
|
1221 | 1221 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n') |
|
1222 | 1222 | f.close() |
|
1223 | 1223 | |
|
1224 | 1224 | |
|
1225 | 1225 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', |
|
1226 | 1226 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1227 | 1227 | timerange=None, |
|
1228 | 1228 | save=False, figpath='', figfile=None, show=True, ftp=False, wr_period=1, |
|
1229 | 1229 | server=None, folder=None, username=None, password=None, |
|
1230 | 1230 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1231 | 1231 | |
|
1232 | 1232 | if pairsList == None: |
|
1233 | 1233 | pairsIndexList = dataOut.pairsIndexList |
|
1234 | 1234 | else: |
|
1235 | 1235 | pairsIndexList = [] |
|
1236 | 1236 | for pair in pairsList: |
|
1237 | 1237 | if pair not in dataOut.pairsList: |
|
1238 | 1238 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
1239 | 1239 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
1240 | 1240 | |
|
1241 | 1241 | if pairsIndexList == []: |
|
1242 | 1242 | return |
|
1243 | 1243 | |
|
1244 | 1244 | # if len(pairsIndexList) > 4: |
|
1245 | 1245 | # pairsIndexList = pairsIndexList[0:4] |
|
1246 | 1246 | |
|
1247 | 1247 | if timerange != None: |
|
1248 | 1248 | self.timerange = timerange |
|
1249 | 1249 | |
|
1250 | 1250 | tmin = None |
|
1251 | 1251 | tmax = None |
|
1252 | 1252 | x = dataOut.getTimeRange() |
|
1253 | 1253 | y = dataOut.getHeiRange() |
|
1254 | 1254 | |
|
1255 | 1255 | |
|
1256 | 1256 | #thisDatetime = dataOut.datatime |
|
1257 | 1257 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
1258 | 1258 | title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1259 | 1259 | xlabel = "Local Time" |
|
1260 | 1260 | ylabel = "Phase" |
|
1261 | 1261 | |
|
1262 | 1262 | nplots = len(pairsIndexList) |
|
1263 | 1263 | #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList))) |
|
1264 | 1264 | phase_beacon = numpy.zeros(len(pairsIndexList)) |
|
1265 | 1265 | for i in range(nplots): |
|
1266 | 1266 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
1267 | 1267 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0) |
|
1268 | 1268 | powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0) |
|
1269 | 1269 | powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0) |
|
1270 | 1270 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) |
|
1271 | 1271 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi |
|
1272 | 1272 | |
|
1273 | 1273 | #print "Phase %d%d" %(pair[0], pair[1]) |
|
1274 | 1274 | #print phase[dataOut.beacon_heiIndexList] |
|
1275 | 1275 | |
|
1276 | 1276 | phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList]) |
|
1277 | 1277 | |
|
1278 | 1278 | if not self.__isConfig: |
|
1279 | 1279 | |
|
1280 | 1280 | nplots = len(pairsIndexList) |
|
1281 | 1281 | |
|
1282 | 1282 | self.setup(id=id, |
|
1283 | 1283 | nplots=nplots, |
|
1284 | 1284 | wintitle=wintitle, |
|
1285 | 1285 | showprofile=showprofile, |
|
1286 | 1286 | show=show) |
|
1287 | 1287 | |
|
1288 | 1288 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
1289 | 1289 | if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0 |
|
1290 | 1290 | if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0 |
|
1291 | 1291 | |
|
1292 | 1292 | self.FTP_WEI = ftp_wei |
|
1293 | 1293 | self.EXP_CODE = exp_code |
|
1294 | 1294 | self.SUB_EXP_CODE = sub_exp_code |
|
1295 | 1295 | self.PLOT_POS = plot_pos |
|
1296 | 1296 | |
|
1297 | 1297 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1298 | 1298 | self.__isConfig = True |
|
1299 | 1299 | self.figfile = figfile |
|
1300 | 1300 | self.xdata = numpy.array([]) |
|
1301 | 1301 | self.ydata = numpy.array([]) |
|
1302 | 1302 | |
|
1303 | 1303 | #open file beacon phase |
|
1304 | 1304 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1305 | 1305 | beacon_file = os.path.join(path,'%s.txt'%self.name) |
|
1306 | 1306 | self.filename_phase = os.path.join(figpath,beacon_file) |
|
1307 | 1307 | #self.save_phase(self.filename_phase) |
|
1308 | 1308 | |
|
1309 | 1309 | |
|
1310 | 1310 | #store data beacon phase |
|
1311 | 1311 | #self.save_data(self.filename_phase, phase_beacon, thisDatetime) |
|
1312 | 1312 | |
|
1313 | 1313 | self.setWinTitle(title) |
|
1314 | 1314 | |
|
1315 | 1315 | |
|
1316 | 1316 | title = "Beacon Signal %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1317 | 1317 | |
|
1318 | 1318 | legendlabels = ["pairs %d%d"%(pair[0], pair[1]) for pair in dataOut.pairsList] |
|
1319 | 1319 | |
|
1320 | 1320 | axes = self.axesList[0] |
|
1321 | 1321 | |
|
1322 | 1322 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1323 | 1323 | |
|
1324 | 1324 | if len(self.ydata)==0: |
|
1325 | 1325 | self.ydata = phase_beacon.reshape(-1,1) |
|
1326 | 1326 | else: |
|
1327 | 1327 | self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1))) |
|
1328 | 1328 | |
|
1329 | 1329 | |
|
1330 | 1330 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1331 | 1331 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, |
|
1332 | 1332 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
1333 | 1333 | XAxisAsTime=True, grid='both' |
|
1334 | 1334 | ) |
|
1335 | 1335 | |
|
1336 | 1336 | self.draw() |
|
1337 | 1337 | |
|
1338 | 1338 | if x[1] >= self.axesList[0].xmax: |
|
1339 | 1339 | self.counter_imagwr = wr_period |
|
1340 | 1340 | del self.xdata |
|
1341 | 1341 | del self.ydata |
|
1342 | 1342 | self.__isConfig = False |
|
1343 | 1343 | |
|
1344 | 1344 | if self.figfile == None: |
|
1345 | 1345 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1346 | 1346 | self.figfile = self.getFilename(name = str_datetime) |
|
1347 | 1347 | |
|
1348 | 1348 | if figpath != '': |
|
1349 | 1349 | self.counter_imagwr += 1 |
|
1350 | 1350 | if (self.counter_imagwr>=wr_period): |
|
1351 | 1351 | # store png plot to local folder |
|
1352 | 1352 | self.saveFigure(figpath, self.figfile) |
|
1353 | 1353 | # store png plot to FTP server according to RT-Web format |
|
1354 | 1354 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
1355 | 1355 | ftp_filename = os.path.join(figpath, name) |
|
1356 | 1356 | self.saveFigure(figpath, ftp_filename) |
|
1357 | 1357 | self.counter_imagwr = 0 |
@@ -1,383 +1,427 | |||
|
1 | 1 | import numpy |
|
2 | 2 | import datetime |
|
3 | 3 | import sys |
|
4 | 4 | import matplotlib |
|
5 | 5 | |
|
6 | 6 | if 'linux' in sys.platform: |
|
7 | 7 | matplotlib.use("TKAgg") |
|
8 | 8 | |
|
9 | 9 | if 'darwin' in sys.platform: |
|
10 | 10 | matplotlib.use("TKAgg") |
|
11 | 11 | |
|
12 | 12 | import matplotlib.pyplot |
|
13 | 13 | |
|
14 | 14 | from mpl_toolkits.axes_grid1 import make_axes_locatable |
|
15 | 15 | from matplotlib.ticker import * |
|
16 | 16 | |
|
17 | 17 | ########################################### |
|
18 | 18 | #Actualizacion de las funciones del driver |
|
19 | 19 | ########################################### |
|
20 | 20 | |
|
21 | 21 | def createFigure(id, wintitle, width, height, facecolor="w", show=True): |
|
22 | 22 | |
|
23 | 23 | matplotlib.pyplot.ioff() |
|
24 | 24 | fig = matplotlib.pyplot.figure(num=id, facecolor=facecolor) |
|
25 | 25 | fig.canvas.manager.set_window_title(wintitle) |
|
26 | 26 | fig.canvas.manager.resize(width, height) |
|
27 | 27 | matplotlib.pyplot.ion() |
|
28 | 28 | if show: |
|
29 | 29 | matplotlib.pyplot.show() |
|
30 | 30 | |
|
31 | 31 | return fig |
|
32 | 32 | |
|
33 | 33 | def closeFigure(show=True): |
|
34 | 34 | |
|
35 | 35 | matplotlib.pyplot.ioff() |
|
36 | 36 | if show: |
|
37 | 37 | matplotlib.pyplot.show() |
|
38 | 38 | |
|
39 | 39 | return |
|
40 | 40 | |
|
41 | 41 | def saveFigure(fig, filename): |
|
42 | 42 | |
|
43 | 43 | matplotlib.pyplot.ioff() |
|
44 | 44 | fig.savefig(filename) |
|
45 | 45 | matplotlib.pyplot.ion() |
|
46 | 46 | |
|
47 | 47 | def setWinTitle(fig, title): |
|
48 | 48 | |
|
49 | 49 | fig.canvas.manager.set_window_title(title) |
|
50 | 50 | |
|
51 | 51 | def setTitle(fig, title): |
|
52 | 52 | |
|
53 | 53 | fig.suptitle(title) |
|
54 | 54 | |
|
55 | def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan): | |
|
55 | def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan, polar=False): | |
|
56 | 56 | |
|
57 | 57 | matplotlib.pyplot.ioff() |
|
58 | 58 | matplotlib.pyplot.figure(fig.number) |
|
59 | 59 | axes = matplotlib.pyplot.subplot2grid((nrow, ncol), |
|
60 | 60 | (xpos, ypos), |
|
61 | 61 | colspan=colspan, |
|
62 |
rowspan=rowspan |
|
|
62 | rowspan=rowspan, | |
|
63 | polar=polar) | |
|
63 | 64 | |
|
64 | 65 | matplotlib.pyplot.ion() |
|
65 | 66 | return axes |
|
66 | 67 | |
|
67 | 68 | def setAxesText(ax, text): |
|
68 | 69 | |
|
69 | 70 | ax.annotate(text, |
|
70 | 71 | xy = (.1, .99), |
|
71 | 72 | xycoords = 'figure fraction', |
|
72 | 73 | horizontalalignment = 'left', |
|
73 | 74 | verticalalignment = 'top', |
|
74 | 75 | fontsize = 10) |
|
75 | 76 | |
|
76 | 77 | def printLabels(ax, xlabel, ylabel, title): |
|
77 | 78 | |
|
78 | 79 | ax.set_xlabel(xlabel, size=11) |
|
79 | 80 | ax.set_ylabel(ylabel, size=11) |
|
80 | 81 | ax.set_title(title, size=8) |
|
81 | 82 | |
|
82 | 83 | def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', |
|
83 | 84 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
84 | 85 | nxticks=4, nyticks=10, |
|
85 | 86 | grid=None,color='blue'): |
|
86 | 87 | |
|
87 | 88 | """ |
|
88 | 89 | |
|
89 | 90 | Input: |
|
90 | 91 | grid : None, 'both', 'x', 'y' |
|
91 | 92 | """ |
|
92 | 93 | |
|
93 | 94 | matplotlib.pyplot.ioff() |
|
94 | 95 | |
|
95 | 96 | ax.set_xlim([xmin,xmax]) |
|
96 | 97 | ax.set_ylim([ymin,ymax]) |
|
97 | 98 | |
|
98 | 99 | printLabels(ax, xlabel, ylabel, title) |
|
99 | 100 | |
|
100 | 101 | ###################################################### |
|
101 | 102 | if (xmax-xmin)<=1: |
|
102 | 103 | xtickspos = numpy.linspace(xmin,xmax,nxticks) |
|
103 | 104 | xtickspos = numpy.array([float("%.1f"%i) for i in xtickspos]) |
|
104 | 105 | ax.set_xticks(xtickspos) |
|
105 | 106 | else: |
|
106 | 107 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
|
107 | 108 | # xtickspos = numpy.arange(nxticks)*float(xmax-xmin)/float(nxticks) + int(xmin) |
|
108 | 109 | ax.set_xticks(xtickspos) |
|
109 | 110 | |
|
110 | 111 | for tick in ax.get_xticklabels(): |
|
111 | 112 | tick.set_visible(xtick_visible) |
|
112 | 113 | |
|
113 | 114 | for tick in ax.xaxis.get_major_ticks(): |
|
114 | 115 | tick.label.set_fontsize(ticksize) |
|
115 | 116 | |
|
116 | 117 | ###################################################### |
|
117 | 118 | for tick in ax.get_yticklabels(): |
|
118 | 119 | tick.set_visible(ytick_visible) |
|
119 | 120 | |
|
120 | 121 | for tick in ax.yaxis.get_major_ticks(): |
|
121 | 122 | tick.label.set_fontsize(ticksize) |
|
122 | 123 | |
|
123 | 124 | ax.plot(x, y, color=color) |
|
124 | 125 | iplot = ax.lines[-1] |
|
125 | 126 | |
|
126 | 127 | ###################################################### |
|
127 | 128 | if '0.' in matplotlib.__version__[0:2]: |
|
128 | 129 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
129 | 130 | return iplot |
|
130 | 131 | |
|
131 | 132 | if '1.0.' in matplotlib.__version__[0:4]: |
|
132 | 133 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
133 | 134 | return iplot |
|
134 | 135 | |
|
135 | 136 | if grid != None: |
|
136 | 137 | ax.grid(b=True, which='major', axis=grid) |
|
137 | 138 | |
|
138 | 139 | matplotlib.pyplot.tight_layout() |
|
139 | 140 | |
|
140 | 141 | matplotlib.pyplot.ion() |
|
141 | 142 | |
|
142 | 143 | return iplot |
|
143 | 144 | |
|
144 | 145 | def set_linedata(ax, x, y, idline): |
|
145 | 146 | |
|
146 | 147 | ax.lines[idline].set_data(x,y) |
|
147 | 148 | |
|
148 | 149 | def pline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
149 | 150 | |
|
150 | 151 | ax = iplot.get_axes() |
|
151 | 152 | |
|
152 | 153 | printLabels(ax, xlabel, ylabel, title) |
|
153 | 154 | |
|
154 | 155 | set_linedata(ax, x, y, idline=0) |
|
155 | 156 | |
|
156 | 157 | def addpline(ax, x, y, color, linestyle, lw): |
|
157 | 158 | |
|
158 | 159 | ax.plot(x,y,color=color,linestyle=linestyle,lw=lw) |
|
159 | 160 | |
|
160 | 161 | |
|
161 | 162 | def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, |
|
162 | 163 | xlabel='', ylabel='', title='', ticksize = 9, |
|
163 | 164 | colormap='jet',cblabel='', cbsize="5%", |
|
164 | 165 | XAxisAsTime=False): |
|
165 | 166 | |
|
166 | 167 | matplotlib.pyplot.ioff() |
|
167 | 168 | |
|
168 | 169 | divider = make_axes_locatable(ax) |
|
169 | 170 | ax_cb = divider.new_horizontal(size=cbsize, pad=0.05) |
|
170 | 171 | fig = ax.get_figure() |
|
171 | 172 | fig.add_axes(ax_cb) |
|
172 | 173 | |
|
173 | 174 | ax.set_xlim([xmin,xmax]) |
|
174 | 175 | ax.set_ylim([ymin,ymax]) |
|
175 | 176 | |
|
176 | 177 | printLabels(ax, xlabel, ylabel, title) |
|
177 | 178 | |
|
178 | 179 | imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) |
|
179 | 180 | cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb) |
|
180 | 181 | cb.set_label(cblabel) |
|
181 | 182 | |
|
182 | 183 | # for tl in ax_cb.get_yticklabels(): |
|
183 | 184 | # tl.set_visible(True) |
|
184 | 185 | |
|
185 | 186 | for tick in ax.yaxis.get_major_ticks(): |
|
186 | 187 | tick.label.set_fontsize(ticksize) |
|
187 | 188 | |
|
188 | 189 | for tick in ax.xaxis.get_major_ticks(): |
|
189 | 190 | tick.label.set_fontsize(ticksize) |
|
190 | 191 | |
|
191 | 192 | for tick in cb.ax.get_yticklabels(): |
|
192 | 193 | tick.set_fontsize(ticksize) |
|
193 | 194 | |
|
194 | 195 | ax_cb.yaxis.tick_right() |
|
195 | 196 | |
|
196 | 197 | if '0.' in matplotlib.__version__[0:2]: |
|
197 | 198 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
198 | 199 | return imesh |
|
199 | 200 | |
|
200 | 201 | if '1.0.' in matplotlib.__version__[0:4]: |
|
201 | 202 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
202 | 203 | return imesh |
|
203 | 204 | |
|
204 | 205 | matplotlib.pyplot.tight_layout() |
|
205 | 206 | |
|
206 | 207 | if XAxisAsTime: |
|
207 | 208 | |
|
208 | 209 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) |
|
209 | 210 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
210 | 211 | ax.xaxis.set_major_locator(LinearLocator(7)) |
|
211 | 212 | |
|
212 | 213 | matplotlib.pyplot.ion() |
|
213 | 214 | return imesh |
|
214 | 215 | |
|
215 | 216 | def pcolor(imesh, z, xlabel='', ylabel='', title=''): |
|
216 | 217 | |
|
217 | 218 | z = z.T |
|
218 | 219 | |
|
219 | 220 | ax = imesh.get_axes() |
|
220 | 221 | |
|
221 | 222 | printLabels(ax, xlabel, ylabel, title) |
|
222 | 223 | |
|
223 | 224 | imesh.set_array(z.ravel()) |
|
224 | 225 | |
|
225 | 226 | def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): |
|
226 | 227 | |
|
227 | 228 | printLabels(ax, xlabel, ylabel, title) |
|
228 | 229 | |
|
229 | 230 | ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) |
|
230 | 231 | |
|
231 | 232 | def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): |
|
232 | 233 | |
|
233 | 234 | printLabels(ax, xlabel, ylabel, title) |
|
234 | 235 | |
|
235 | 236 | ax.collections.remove(ax.collections[0]) |
|
236 | 237 | |
|
237 | 238 | ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) |
|
238 | 239 | |
|
239 | 240 | def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, |
|
240 | 241 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
241 | 242 | nxticks=4, nyticks=10, |
|
242 | 243 | grid=None): |
|
243 | 244 | |
|
244 | 245 | """ |
|
245 | 246 | |
|
246 | 247 | Input: |
|
247 | 248 | grid : None, 'both', 'x', 'y' |
|
248 | 249 | """ |
|
249 | 250 | |
|
250 | 251 | matplotlib.pyplot.ioff() |
|
251 | 252 | |
|
252 | 253 | lines = ax.plot(x.T, y) |
|
253 | 254 | leg = ax.legend(lines, legendlabels, loc='upper right') |
|
254 | 255 | leg.get_frame().set_alpha(0.5) |
|
255 | 256 | ax.set_xlim([xmin,xmax]) |
|
256 | 257 | ax.set_ylim([ymin,ymax]) |
|
257 | 258 | printLabels(ax, xlabel, ylabel, title) |
|
258 | 259 | |
|
259 | 260 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
|
260 | 261 | ax.set_xticks(xtickspos) |
|
261 | 262 | |
|
262 | 263 | for tick in ax.get_xticklabels(): |
|
263 | 264 | tick.set_visible(xtick_visible) |
|
264 | 265 | |
|
265 | 266 | for tick in ax.xaxis.get_major_ticks(): |
|
266 | 267 | tick.label.set_fontsize(ticksize) |
|
267 | 268 | |
|
268 | 269 | for tick in ax.get_yticklabels(): |
|
269 | 270 | tick.set_visible(ytick_visible) |
|
270 | 271 | |
|
271 | 272 | for tick in ax.yaxis.get_major_ticks(): |
|
272 | 273 | tick.label.set_fontsize(ticksize) |
|
273 | 274 | |
|
274 | 275 | iplot = ax.lines[-1] |
|
275 | 276 | |
|
276 | 277 | if '0.' in matplotlib.__version__[0:2]: |
|
277 | 278 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
278 | 279 | return iplot |
|
279 | 280 | |
|
280 | 281 | if '1.0.' in matplotlib.__version__[0:4]: |
|
281 | 282 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
282 | 283 | return iplot |
|
283 | 284 | |
|
284 | 285 | if grid != None: |
|
285 | 286 | ax.grid(b=True, which='major', axis=grid) |
|
286 | 287 | |
|
287 | 288 | matplotlib.pyplot.tight_layout() |
|
288 | 289 | |
|
289 | 290 | matplotlib.pyplot.ion() |
|
290 | 291 | |
|
291 | 292 | return iplot |
|
292 | 293 | |
|
293 | 294 | |
|
294 | 295 | def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
295 | 296 | |
|
296 | 297 | ax = iplot.get_axes() |
|
297 | 298 | |
|
298 | 299 | printLabels(ax, xlabel, ylabel, title) |
|
299 | 300 | |
|
300 | 301 | for i in range(len(ax.lines)): |
|
301 | 302 | line = ax.lines[i] |
|
302 | 303 | line.set_data(x[i,:],y) |
|
303 | 304 | |
|
304 | 305 | def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, |
|
305 | 306 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
306 | 307 | nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None", |
|
307 | 308 | grid=None, XAxisAsTime=False): |
|
308 | 309 | |
|
309 | 310 | """ |
|
310 | 311 | |
|
311 | 312 | Input: |
|
312 | 313 | grid : None, 'both', 'x', 'y' |
|
313 | 314 | """ |
|
314 | 315 | |
|
315 | 316 | matplotlib.pyplot.ioff() |
|
316 | 317 | |
|
317 | 318 | # lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle) |
|
318 | 319 | lines = ax.plot(x, y.T, linestyle='None', marker='.', markersize=markersize) |
|
319 | 320 | leg = ax.legend(lines, legendlabels, loc='upper left', bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \ |
|
320 | 321 | handletextpad=0.5, borderpad=0.5, labelspacing=0.5, borderaxespad=0.) |
|
321 | 322 | |
|
322 | 323 | for label in leg.get_texts(): label.set_fontsize(9) |
|
323 | 324 | |
|
324 | 325 | ax.set_xlim([xmin,xmax]) |
|
325 | 326 | ax.set_ylim([ymin,ymax]) |
|
326 | 327 | printLabels(ax, xlabel, ylabel, title) |
|
327 | 328 | |
|
328 | 329 | # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
|
329 | 330 | # ax.set_xticks(xtickspos) |
|
330 | 331 | |
|
331 | 332 | for tick in ax.get_xticklabels(): |
|
332 | 333 | tick.set_visible(xtick_visible) |
|
333 | 334 | |
|
334 | 335 | for tick in ax.xaxis.get_major_ticks(): |
|
335 | 336 | tick.label.set_fontsize(ticksize) |
|
336 | 337 | |
|
337 | 338 | for tick in ax.get_yticklabels(): |
|
338 | 339 | tick.set_visible(ytick_visible) |
|
339 | 340 | |
|
340 | 341 | for tick in ax.yaxis.get_major_ticks(): |
|
341 | 342 | tick.label.set_fontsize(ticksize) |
|
342 | 343 | |
|
343 | 344 | iplot = ax.lines[-1] |
|
344 | 345 | |
|
345 | 346 | if '0.' in matplotlib.__version__[0:2]: |
|
346 | 347 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
347 | 348 | return iplot |
|
348 | 349 | |
|
349 | 350 | if '1.0.' in matplotlib.__version__[0:4]: |
|
350 | 351 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
351 | 352 | return iplot |
|
352 | 353 | |
|
353 | 354 | if grid != None: |
|
354 | 355 | ax.grid(b=True, which='major', axis=grid) |
|
355 | 356 | |
|
356 | 357 | matplotlib.pyplot.tight_layout() |
|
357 | 358 | |
|
358 | 359 | if XAxisAsTime: |
|
359 | 360 | |
|
360 | 361 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) |
|
361 | 362 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
362 | 363 | ax.xaxis.set_major_locator(LinearLocator(7)) |
|
363 | 364 | |
|
364 | 365 | matplotlib.pyplot.ion() |
|
365 | 366 | |
|
366 | 367 | return iplot |
|
367 | 368 | |
|
368 | 369 | def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''): |
|
369 | 370 | |
|
370 | 371 | ax = iplot.get_axes() |
|
371 | 372 | |
|
372 | 373 | printLabels(ax, xlabel, ylabel, title) |
|
373 | 374 | |
|
374 | 375 | for i in range(len(ax.lines)): |
|
375 | 376 | line = ax.lines[i] |
|
376 | 377 | line.set_data(x,y[i,:]) |
|
378 | ||
|
379 | def createPolar(ax, x, y, | |
|
380 | xlabel='', ylabel='', title='', ticksize = 9, | |
|
381 | colormap='jet',cblabel='', cbsize="5%", | |
|
382 | XAxisAsTime=False): | |
|
383 | ||
|
384 | matplotlib.pyplot.ioff() | |
|
385 | ||
|
386 | ax.plot(x,y,'bo', markersize=5) | |
|
387 | # ax.set_rmax(90) | |
|
388 | ax.set_ylim(0,90) | |
|
389 | ax.set_yticks(numpy.arange(0,90,20)) | |
|
390 | ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center' ,size='11') | |
|
391 | # ax.text(100, 100, 'example', ha='left', va='center', rotation='vertical') | |
|
392 | printLabels(ax, xlabel, '', title) | |
|
393 | iplot = ax.lines[-1] | |
|
394 | ||
|
395 | if '0.' in matplotlib.__version__[0:2]: | |
|
396 | print "The matplotlib version has to be updated to 1.1 or newer" | |
|
397 | return iplot | |
|
398 | ||
|
399 | if '1.0.' in matplotlib.__version__[0:4]: | |
|
400 | print "The matplotlib version has to be updated to 1.1 or newer" | |
|
401 | return iplot | |
|
402 | ||
|
403 | # if grid != None: | |
|
404 | # ax.grid(b=True, which='major', axis=grid) | |
|
405 | ||
|
406 | matplotlib.pyplot.tight_layout() | |
|
407 | ||
|
408 | matplotlib.pyplot.ion() | |
|
409 | ||
|
410 | ||
|
411 | return iplot | |
|
412 | ||
|
413 | def polar(iplot, x, y, xlabel='', ylabel='', title=''): | |
|
414 | ||
|
415 | ax = iplot.get_axes() | |
|
416 | ||
|
417 | # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center',size='11') | |
|
418 | printLabels(ax, xlabel, '', title) | |
|
419 | ||
|
420 | set_linedata(ax, x, y, idline=0) | |
|
377 | 421 | |
|
378 | 422 | def draw(fig): |
|
379 | 423 | |
|
380 | 424 | if type(fig) == 'int': |
|
381 | 425 | raise ValueError, "This parameter should be of tpye matplotlib figure" |
|
382 | 426 | |
|
383 | 427 | fig.canvas.draw() |
@@ -1,934 +1,935 | |||
|
1 | 1 | import numpy |
|
2 | import math | |
|
2 | 3 | |
|
3 | 4 | from jroproc_base import ProcessingUnit, Operation |
|
4 | 5 | from model.data.jrodata import Spectra |
|
5 | 6 | from model.data.jrodata import hildebrand_sekhon |
|
6 | 7 | |
|
7 | 8 | class SpectraProc(ProcessingUnit): |
|
8 | 9 | |
|
9 | 10 | def __init__(self): |
|
10 | 11 | |
|
11 | 12 | ProcessingUnit.__init__(self) |
|
12 | 13 | |
|
13 | 14 | self.buffer = None |
|
14 | 15 | self.firstdatatime = None |
|
15 | 16 | self.profIndex = 0 |
|
16 | 17 | self.dataOut = Spectra() |
|
17 | 18 | self.id_min = None |
|
18 | 19 | self.id_max = None |
|
19 | 20 | |
|
20 | 21 | def __updateObjFromInput(self): |
|
21 | 22 | |
|
22 | 23 | self.dataOut.timeZone = self.dataIn.timeZone |
|
23 | 24 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
24 | 25 | self.dataOut.errorCount = self.dataIn.errorCount |
|
25 | 26 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
26 | 27 | |
|
27 | 28 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() |
|
28 | 29 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() |
|
29 | 30 | self.dataOut.channelList = self.dataIn.channelList |
|
30 | 31 | self.dataOut.heightList = self.dataIn.heightList |
|
31 | 32 | self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
32 | 33 | # self.dataOut.nHeights = self.dataIn.nHeights |
|
33 | 34 | # self.dataOut.nChannels = self.dataIn.nChannels |
|
34 | 35 | self.dataOut.nBaud = self.dataIn.nBaud |
|
35 | 36 | self.dataOut.nCode = self.dataIn.nCode |
|
36 | 37 | self.dataOut.code = self.dataIn.code |
|
37 | 38 | self.dataOut.nProfiles = self.dataOut.nFFTPoints |
|
38 | 39 | # self.dataOut.channelIndexList = self.dataIn.channelIndexList |
|
39 | 40 | self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock |
|
40 | 41 | self.dataOut.utctime = self.firstdatatime |
|
41 | 42 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada |
|
42 | 43 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip |
|
43 | 44 | # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT |
|
44 | 45 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
45 | 46 | self.dataOut.nIncohInt = 1 |
|
46 | 47 | # self.dataOut.ippSeconds = self.dataIn.ippSeconds |
|
47 | 48 | self.dataOut.windowOfFilter = self.dataIn.windowOfFilter |
|
48 | 49 | |
|
49 | 50 | self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt |
|
50 | 51 | self.dataOut.frequency = self.dataIn.frequency |
|
51 | 52 | self.dataOut.realtime = self.dataIn.realtime |
|
52 | 53 | |
|
53 | 54 | self.dataOut.azimuth = self.dataIn.azimuth |
|
54 | 55 | self.dataOut.zenith = self.dataIn.zenith |
|
55 | 56 | |
|
56 | 57 | self.dataOut.beam.codeList = self.dataIn.beam.codeList |
|
57 | 58 | self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList |
|
58 | 59 | self.dataOut.beam.zenithList = self.dataIn.beam.zenithList |
|
59 | 60 | |
|
60 | 61 | def __getFft(self): |
|
61 | 62 | """ |
|
62 | 63 | Convierte valores de Voltaje a Spectra |
|
63 | 64 | |
|
64 | 65 | Affected: |
|
65 | 66 | self.dataOut.data_spc |
|
66 | 67 | self.dataOut.data_cspc |
|
67 | 68 | self.dataOut.data_dc |
|
68 | 69 | self.dataOut.heightList |
|
69 | 70 | self.profIndex |
|
70 | 71 | self.buffer |
|
71 | 72 | self.dataOut.flagNoData |
|
72 | 73 | """ |
|
73 | 74 | fft_volt = numpy.fft.fft(self.buffer,n=self.dataOut.nFFTPoints,axis=1) |
|
74 | 75 | fft_volt = fft_volt.astype(numpy.dtype('complex')) |
|
75 | 76 | dc = fft_volt[:,0,:] |
|
76 | 77 | |
|
77 | 78 | #calculo de self-spectra |
|
78 | 79 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) |
|
79 | 80 | spc = fft_volt * numpy.conjugate(fft_volt) |
|
80 | 81 | spc = spc.real |
|
81 | 82 | |
|
82 | 83 | blocksize = 0 |
|
83 | 84 | blocksize += dc.size |
|
84 | 85 | blocksize += spc.size |
|
85 | 86 | |
|
86 | 87 | cspc = None |
|
87 | 88 | pairIndex = 0 |
|
88 | 89 | if self.dataOut.pairsList != None: |
|
89 | 90 | #calculo de cross-spectra |
|
90 | 91 | cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex') |
|
91 | 92 | for pair in self.dataOut.pairsList: |
|
92 | 93 | cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]) |
|
93 | 94 | pairIndex += 1 |
|
94 | 95 | blocksize += cspc.size |
|
95 | 96 | |
|
96 | 97 | self.dataOut.data_spc = spc |
|
97 | 98 | self.dataOut.data_cspc = cspc |
|
98 | 99 | self.dataOut.data_dc = dc |
|
99 | 100 | self.dataOut.blockSize = blocksize |
|
100 | 101 | self.dataOut.flagShiftFFT = False |
|
101 | 102 | |
|
102 | 103 | def run(self, nProfiles=None, nFFTPoints=None, pairsList=[], ippFactor=None): |
|
103 | 104 | |
|
104 | 105 | self.dataOut.flagNoData = True |
|
105 | 106 | |
|
106 | 107 | if self.dataIn.type == "Spectra": |
|
107 | 108 | self.dataOut.copy(self.dataIn) |
|
108 | 109 | return True |
|
109 | 110 | |
|
110 | 111 | if self.dataIn.type == "Voltage": |
|
111 | 112 | |
|
112 | 113 | if nFFTPoints == None: |
|
113 | 114 | raise ValueError, "This SpectraProc.run() need nFFTPoints input variable" |
|
114 | 115 | |
|
115 | 116 | if nProfiles == None: |
|
116 | 117 | raise ValueError, "This SpectraProc.run() need nProfiles input variable" |
|
117 | 118 | |
|
118 | 119 | |
|
119 | 120 | if ippFactor == None: |
|
120 | 121 | ippFactor = 1 |
|
121 | 122 | self.dataOut.ippFactor = ippFactor |
|
122 | 123 | |
|
123 | 124 | self.dataOut.nFFTPoints = nFFTPoints |
|
124 | 125 | self.dataOut.pairsList = pairsList |
|
125 | 126 | |
|
126 | 127 | if self.buffer == None: |
|
127 | 128 | self.buffer = numpy.zeros((self.dataIn.nChannels, |
|
128 | 129 | nProfiles, |
|
129 | 130 | self.dataIn.nHeights), |
|
130 | 131 | dtype='complex') |
|
131 | 132 | self.id_min = 0 |
|
132 | 133 | self.id_max = self.dataIn.data.shape[1] |
|
133 | 134 | |
|
134 | 135 | if len(self.dataIn.data.shape) == 2: |
|
135 | 136 | self.buffer[:,self.profIndex,:] = self.dataIn.data.copy() |
|
136 | 137 | self.profIndex += 1 |
|
137 | 138 | else: |
|
138 | 139 | if self.dataIn.data.shape[1] == nProfiles: |
|
139 | 140 | self.buffer = self.dataIn.data.copy() |
|
140 | 141 | self.profIndex = nProfiles |
|
141 | 142 | elif self.dataIn.data.shape[1] < nProfiles: |
|
142 | 143 | self.buffer[:,self.id_min:self.id_max,:] = self.dataIn.data |
|
143 | 144 | self.profIndex += self.dataIn.data.shape[1] |
|
144 | 145 | self.id_min += self.dataIn.data.shape[1] |
|
145 | 146 | self.id_max += self.dataIn.data.shape[1] |
|
146 | 147 | else: |
|
147 | 148 | raise ValueError, "The type object %s has %d profiles, it should be equal to %d profiles"%(self.dataIn.type,self.dataIn.data.shape[1],nProfiles) |
|
148 | 149 | self.dataOut.flagNoData = True |
|
149 | 150 | return 0 |
|
150 | 151 | |
|
151 | 152 | |
|
152 | 153 | if self.firstdatatime == None: |
|
153 | 154 | self.firstdatatime = self.dataIn.utctime |
|
154 | 155 | |
|
155 | 156 | if self.profIndex == nProfiles: |
|
156 | 157 | self.__updateObjFromInput() |
|
157 | 158 | self.__getFft() |
|
158 | 159 | |
|
159 | 160 | self.dataOut.flagNoData = False |
|
160 | 161 | |
|
161 | 162 | self.buffer = None |
|
162 | 163 | self.firstdatatime = None |
|
163 | 164 | self.profIndex = 0 |
|
164 | 165 | |
|
165 | 166 | return True |
|
166 | 167 | |
|
167 | 168 | raise ValueError, "The type object %s is not valid"%(self.dataIn.type) |
|
168 | 169 | |
|
169 | 170 | def selectChannels(self, channelList): |
|
170 | 171 | |
|
171 | 172 | channelIndexList = [] |
|
172 | 173 | |
|
173 | 174 | for channel in channelList: |
|
174 | 175 | index = self.dataOut.channelList.index(channel) |
|
175 | 176 | channelIndexList.append(index) |
|
176 | 177 | |
|
177 | 178 | self.selectChannelsByIndex(channelIndexList) |
|
178 | 179 | |
|
179 | 180 | def selectChannelsByIndex(self, channelIndexList): |
|
180 | 181 | """ |
|
181 | 182 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
182 | 183 | |
|
183 | 184 | Input: |
|
184 | 185 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
185 | 186 | |
|
186 | 187 | Affected: |
|
187 | 188 | self.dataOut.data_spc |
|
188 | 189 | self.dataOut.channelIndexList |
|
189 | 190 | self.dataOut.nChannels |
|
190 | 191 | |
|
191 | 192 | Return: |
|
192 | 193 | None |
|
193 | 194 | """ |
|
194 | 195 | |
|
195 | 196 | for channelIndex in channelIndexList: |
|
196 | 197 | if channelIndex not in self.dataOut.channelIndexList: |
|
197 | 198 | print channelIndexList |
|
198 | 199 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex |
|
199 | 200 | |
|
200 | 201 | # nChannels = len(channelIndexList) |
|
201 | 202 | |
|
202 | 203 | data_spc = self.dataOut.data_spc[channelIndexList,:] |
|
203 | 204 | |
|
204 | 205 | self.dataOut.data_spc = data_spc |
|
205 | 206 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
206 | 207 | # self.dataOut.nChannels = nChannels |
|
207 | 208 | |
|
208 | 209 | return 1 |
|
209 | 210 | |
|
210 | 211 | def selectHeights(self, minHei, maxHei): |
|
211 | 212 | """ |
|
212 | 213 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
213 | 214 | minHei <= height <= maxHei |
|
214 | 215 | |
|
215 | 216 | Input: |
|
216 | 217 | minHei : valor minimo de altura a considerar |
|
217 | 218 | maxHei : valor maximo de altura a considerar |
|
218 | 219 | |
|
219 | 220 | Affected: |
|
220 | 221 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
221 | 222 | |
|
222 | 223 | Return: |
|
223 | 224 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
224 | 225 | """ |
|
225 | 226 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): |
|
226 | 227 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
227 | 228 | |
|
228 | 229 | if (maxHei > self.dataOut.heightList[-1]): |
|
229 | 230 | maxHei = self.dataOut.heightList[-1] |
|
230 | 231 | # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
231 | 232 | |
|
232 | 233 | minIndex = 0 |
|
233 | 234 | maxIndex = 0 |
|
234 | 235 | heights = self.dataOut.heightList |
|
235 | 236 | |
|
236 | 237 | inda = numpy.where(heights >= minHei) |
|
237 | 238 | indb = numpy.where(heights <= maxHei) |
|
238 | 239 | |
|
239 | 240 | try: |
|
240 | 241 | minIndex = inda[0][0] |
|
241 | 242 | except: |
|
242 | 243 | minIndex = 0 |
|
243 | 244 | |
|
244 | 245 | try: |
|
245 | 246 | maxIndex = indb[0][-1] |
|
246 | 247 | except: |
|
247 | 248 | maxIndex = len(heights) |
|
248 | 249 | |
|
249 | 250 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
250 | 251 | |
|
251 | 252 | return 1 |
|
252 | 253 | |
|
253 | 254 | def getBeaconSignal(self, tauindex = 0, channelindex = 0, hei_ref=None): |
|
254 | 255 | newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex]) |
|
255 | 256 | |
|
256 | 257 | if hei_ref != None: |
|
257 | 258 | newheis = numpy.where(self.dataOut.heightList>hei_ref) |
|
258 | 259 | |
|
259 | 260 | minIndex = min(newheis[0]) |
|
260 | 261 | maxIndex = max(newheis[0]) |
|
261 | 262 | data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1] |
|
262 | 263 | heightList = self.dataOut.heightList[minIndex:maxIndex+1] |
|
263 | 264 | |
|
264 | 265 | # determina indices |
|
265 | 266 | nheis = int(self.dataOut.radarControllerHeaderObj.txB/(self.dataOut.heightList[1]-self.dataOut.heightList[0])) |
|
266 | 267 | avg_dB = 10*numpy.log10(numpy.sum(data_spc[channelindex,:,:],axis=0)) |
|
267 | 268 | beacon_dB = numpy.sort(avg_dB)[-nheis:] |
|
268 | 269 | beacon_heiIndexList = [] |
|
269 | 270 | for val in avg_dB.tolist(): |
|
270 | 271 | if val >= beacon_dB[0]: |
|
271 | 272 | beacon_heiIndexList.append(avg_dB.tolist().index(val)) |
|
272 | 273 | |
|
273 | 274 | #data_spc = data_spc[:,:,beacon_heiIndexList] |
|
274 | 275 | data_cspc = None |
|
275 | 276 | if self.dataOut.data_cspc != None: |
|
276 | 277 | data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1] |
|
277 | 278 | #data_cspc = data_cspc[:,:,beacon_heiIndexList] |
|
278 | 279 | |
|
279 | 280 | data_dc = None |
|
280 | 281 | if self.dataOut.data_dc != None: |
|
281 | 282 | data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1] |
|
282 | 283 | #data_dc = data_dc[:,beacon_heiIndexList] |
|
283 | 284 | |
|
284 | 285 | self.dataOut.data_spc = data_spc |
|
285 | 286 | self.dataOut.data_cspc = data_cspc |
|
286 | 287 | self.dataOut.data_dc = data_dc |
|
287 | 288 | self.dataOut.heightList = heightList |
|
288 | 289 | self.dataOut.beacon_heiIndexList = beacon_heiIndexList |
|
289 | 290 | |
|
290 | 291 | return 1 |
|
291 | 292 | |
|
292 | 293 | |
|
293 | 294 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
294 | 295 | """ |
|
295 | 296 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
296 | 297 | minIndex <= index <= maxIndex |
|
297 | 298 | |
|
298 | 299 | Input: |
|
299 | 300 | minIndex : valor de indice minimo de altura a considerar |
|
300 | 301 | maxIndex : valor de indice maximo de altura a considerar |
|
301 | 302 | |
|
302 | 303 | Affected: |
|
303 | 304 | self.dataOut.data_spc |
|
304 | 305 | self.dataOut.data_cspc |
|
305 | 306 | self.dataOut.data_dc |
|
306 | 307 | self.dataOut.heightList |
|
307 | 308 | |
|
308 | 309 | Return: |
|
309 | 310 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
310 | 311 | """ |
|
311 | 312 | |
|
312 | 313 | if (minIndex < 0) or (minIndex > maxIndex): |
|
313 | 314 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
314 | 315 | |
|
315 | 316 | if (maxIndex >= self.dataOut.nHeights): |
|
316 | 317 | maxIndex = self.dataOut.nHeights-1 |
|
317 | 318 | # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
318 | 319 | |
|
319 | 320 | # nHeights = maxIndex - minIndex + 1 |
|
320 | 321 | |
|
321 | 322 | #Spectra |
|
322 | 323 | data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1] |
|
323 | 324 | |
|
324 | 325 | data_cspc = None |
|
325 | 326 | if self.dataOut.data_cspc != None: |
|
326 | 327 | data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1] |
|
327 | 328 | |
|
328 | 329 | data_dc = None |
|
329 | 330 | if self.dataOut.data_dc != None: |
|
330 | 331 | data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1] |
|
331 | 332 | |
|
332 | 333 | self.dataOut.data_spc = data_spc |
|
333 | 334 | self.dataOut.data_cspc = data_cspc |
|
334 | 335 | self.dataOut.data_dc = data_dc |
|
335 | 336 | |
|
336 | 337 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1] |
|
337 | 338 | |
|
338 | 339 | return 1 |
|
339 | 340 | |
|
340 | 341 | def removeDC(self, mode = 2): |
|
341 | 342 | jspectra = self.dataOut.data_spc |
|
342 | 343 | jcspectra = self.dataOut.data_cspc |
|
343 | 344 | |
|
344 | 345 | |
|
345 | 346 | num_chan = jspectra.shape[0] |
|
346 | 347 | num_hei = jspectra.shape[2] |
|
347 | 348 | |
|
348 | 349 | if jcspectra != None: |
|
349 | 350 | jcspectraExist = True |
|
350 | 351 | num_pairs = jcspectra.shape[0] |
|
351 | 352 | else: jcspectraExist = False |
|
352 | 353 | |
|
353 | 354 | freq_dc = jspectra.shape[1]/2 |
|
354 | 355 | ind_vel = numpy.array([-2,-1,1,2]) + freq_dc |
|
355 | 356 | |
|
356 | 357 | if ind_vel[0]<0: |
|
357 | 358 | ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof |
|
358 | 359 | |
|
359 | 360 | if mode == 1: |
|
360 | 361 | jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION |
|
361 | 362 | |
|
362 | 363 | if jcspectraExist: |
|
363 | 364 | jcspectra[:,freq_dc,:] = (jcspectra[:,ind_vel[1],:] + jcspectra[:,ind_vel[2],:])/2 |
|
364 | 365 | |
|
365 | 366 | if mode == 2: |
|
366 | 367 | |
|
367 | 368 | vel = numpy.array([-2,-1,1,2]) |
|
368 | 369 | xx = numpy.zeros([4,4]) |
|
369 | 370 | |
|
370 | 371 | for fil in range(4): |
|
371 | 372 | xx[fil,:] = vel[fil]**numpy.asarray(range(4)) |
|
372 | 373 | |
|
373 | 374 | xx_inv = numpy.linalg.inv(xx) |
|
374 | 375 | xx_aux = xx_inv[0,:] |
|
375 | 376 | |
|
376 | 377 | for ich in range(num_chan): |
|
377 | 378 | yy = jspectra[ich,ind_vel,:] |
|
378 | 379 | jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy) |
|
379 | 380 | |
|
380 | 381 | junkid = jspectra[ich,freq_dc,:]<=0 |
|
381 | 382 | cjunkid = sum(junkid) |
|
382 | 383 | |
|
383 | 384 | if cjunkid.any(): |
|
384 | 385 | jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2 |
|
385 | 386 | |
|
386 | 387 | if jcspectraExist: |
|
387 | 388 | for ip in range(num_pairs): |
|
388 | 389 | yy = jcspectra[ip,ind_vel,:] |
|
389 | 390 | jcspectra[ip,freq_dc,:] = numpy.dot(xx_aux,yy) |
|
390 | 391 | |
|
391 | 392 | |
|
392 | 393 | self.dataOut.data_spc = jspectra |
|
393 | 394 | self.dataOut.data_cspc = jcspectra |
|
394 | 395 | |
|
395 | 396 | return 1 |
|
396 | 397 | |
|
397 | 398 | def removeInterference(self, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None): |
|
398 | 399 | |
|
399 | 400 | jspectra = self.dataOut.data_spc |
|
400 | 401 | jcspectra = self.dataOut.data_cspc |
|
401 | 402 | jnoise = self.dataOut.getNoise() |
|
402 | 403 | num_incoh = self.dataOut.nIncohInt |
|
403 | 404 | |
|
404 | 405 | num_channel = jspectra.shape[0] |
|
405 | 406 | num_prof = jspectra.shape[1] |
|
406 | 407 | num_hei = jspectra.shape[2] |
|
407 | 408 | |
|
408 | 409 | #hei_interf |
|
409 | 410 | if hei_interf == None: |
|
410 | 411 | count_hei = num_hei/2 #Como es entero no importa |
|
411 | 412 | hei_interf = numpy.asmatrix(range(count_hei)) + num_hei - count_hei |
|
412 | 413 | hei_interf = numpy.asarray(hei_interf)[0] |
|
413 | 414 | #nhei_interf |
|
414 | 415 | if (nhei_interf == None): |
|
415 | 416 | nhei_interf = 5 |
|
416 | 417 | if (nhei_interf < 1): |
|
417 | 418 | nhei_interf = 1 |
|
418 | 419 | if (nhei_interf > count_hei): |
|
419 | 420 | nhei_interf = count_hei |
|
420 | 421 | if (offhei_interf == None): |
|
421 | 422 | offhei_interf = 0 |
|
422 | 423 | |
|
423 | 424 | ind_hei = range(num_hei) |
|
424 | 425 | # mask_prof = numpy.asarray(range(num_prof - 2)) + 1 |
|
425 | 426 | # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1 |
|
426 | 427 | mask_prof = numpy.asarray(range(num_prof)) |
|
427 | 428 | num_mask_prof = mask_prof.size |
|
428 | 429 | comp_mask_prof = [0, num_prof/2] |
|
429 | 430 | |
|
430 | 431 | |
|
431 | 432 | #noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal |
|
432 | 433 | if (jnoise.size < num_channel or numpy.isnan(jnoise).any()): |
|
433 | 434 | jnoise = numpy.nan |
|
434 | 435 | noise_exist = jnoise[0] < numpy.Inf |
|
435 | 436 | |
|
436 | 437 | #Subrutina de Remocion de la Interferencia |
|
437 | 438 | for ich in range(num_channel): |
|
438 | 439 | #Se ordena los espectros segun su potencia (menor a mayor) |
|
439 | 440 | power = jspectra[ich,mask_prof,:] |
|
440 | 441 | power = power[:,hei_interf] |
|
441 | 442 | power = power.sum(axis = 0) |
|
442 | 443 | psort = power.ravel().argsort() |
|
443 | 444 | |
|
444 | 445 | #Se estima la interferencia promedio en los Espectros de Potencia empleando |
|
445 | 446 | junkspc_interf = jspectra[ich,:,hei_interf[psort[range(offhei_interf, nhei_interf + offhei_interf)]]] |
|
446 | 447 | |
|
447 | 448 | if noise_exist: |
|
448 | 449 | # tmp_noise = jnoise[ich] / num_prof |
|
449 | 450 | tmp_noise = jnoise[ich] |
|
450 | 451 | junkspc_interf = junkspc_interf - tmp_noise |
|
451 | 452 | #junkspc_interf[:,comp_mask_prof] = 0 |
|
452 | 453 | |
|
453 | 454 | jspc_interf = junkspc_interf.sum(axis = 0) / nhei_interf |
|
454 | 455 | jspc_interf = jspc_interf.transpose() |
|
455 | 456 | #Calculando el espectro de interferencia promedio |
|
456 | 457 | noiseid = numpy.where(jspc_interf <= tmp_noise/ math.sqrt(num_incoh)) |
|
457 | 458 | noiseid = noiseid[0] |
|
458 | 459 | cnoiseid = noiseid.size |
|
459 | 460 | interfid = numpy.where(jspc_interf > tmp_noise/ math.sqrt(num_incoh)) |
|
460 | 461 | interfid = interfid[0] |
|
461 | 462 | cinterfid = interfid.size |
|
462 | 463 | |
|
463 | 464 | if (cnoiseid > 0): jspc_interf[noiseid] = 0 |
|
464 | 465 | |
|
465 | 466 | #Expandiendo los perfiles a limpiar |
|
466 | 467 | if (cinterfid > 0): |
|
467 | 468 | new_interfid = (numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof)%num_prof |
|
468 | 469 | new_interfid = numpy.asarray(new_interfid) |
|
469 | 470 | new_interfid = {x for x in new_interfid} |
|
470 | 471 | new_interfid = numpy.array(list(new_interfid)) |
|
471 | 472 | new_cinterfid = new_interfid.size |
|
472 | 473 | else: new_cinterfid = 0 |
|
473 | 474 | |
|
474 | 475 | for ip in range(new_cinterfid): |
|
475 | 476 | ind = junkspc_interf[:,new_interfid[ip]].ravel().argsort() |
|
476 | 477 | jspc_interf[new_interfid[ip]] = junkspc_interf[ind[nhei_interf/2],new_interfid[ip]] |
|
477 | 478 | |
|
478 | 479 | |
|
479 | 480 | jspectra[ich,:,ind_hei] = jspectra[ich,:,ind_hei] - jspc_interf #Corregir indices |
|
480 | 481 | |
|
481 | 482 | #Removiendo la interferencia del punto de mayor interferencia |
|
482 | 483 | ListAux = jspc_interf[mask_prof].tolist() |
|
483 | 484 | maxid = ListAux.index(max(ListAux)) |
|
484 | 485 | |
|
485 | 486 | |
|
486 | 487 | if cinterfid > 0: |
|
487 | 488 | for ip in range(cinterfid*(interf == 2) - 1): |
|
488 | 489 | ind = (jspectra[ich,interfid[ip],:] < tmp_noise*(1 + 1/math.sqrt(num_incoh))).nonzero() |
|
489 | 490 | cind = len(ind) |
|
490 | 491 | |
|
491 | 492 | if (cind > 0): |
|
492 | 493 | jspectra[ich,interfid[ip],ind] = tmp_noise*(1 + (numpy.random.uniform(cind) - 0.5)/math.sqrt(num_incoh)) |
|
493 | 494 | |
|
494 | 495 | ind = numpy.array([-2,-1,1,2]) |
|
495 | 496 | xx = numpy.zeros([4,4]) |
|
496 | 497 | |
|
497 | 498 | for id1 in range(4): |
|
498 | 499 | xx[:,id1] = ind[id1]**numpy.asarray(range(4)) |
|
499 | 500 | |
|
500 | 501 | xx_inv = numpy.linalg.inv(xx) |
|
501 | 502 | xx = xx_inv[:,0] |
|
502 | 503 | ind = (ind + maxid + num_mask_prof)%num_mask_prof |
|
503 | 504 | yy = jspectra[ich,mask_prof[ind],:] |
|
504 | 505 | jspectra[ich,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx) |
|
505 | 506 | |
|
506 | 507 | |
|
507 | 508 | indAux = (jspectra[ich,:,:] < tmp_noise*(1-1/math.sqrt(num_incoh))).nonzero() |
|
508 | 509 | jspectra[ich,indAux[0],indAux[1]] = tmp_noise * (1 - 1/math.sqrt(num_incoh)) |
|
509 | 510 | |
|
510 | 511 | #Remocion de Interferencia en el Cross Spectra |
|
511 | 512 | if jcspectra == None: return jspectra, jcspectra |
|
512 | 513 | num_pairs = jcspectra.size/(num_prof*num_hei) |
|
513 | 514 | jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei) |
|
514 | 515 | |
|
515 | 516 | for ip in range(num_pairs): |
|
516 | 517 | |
|
517 | 518 | #------------------------------------------- |
|
518 | 519 | |
|
519 | 520 | cspower = numpy.abs(jcspectra[ip,mask_prof,:]) |
|
520 | 521 | cspower = cspower[:,hei_interf] |
|
521 | 522 | cspower = cspower.sum(axis = 0) |
|
522 | 523 | |
|
523 | 524 | cspsort = cspower.ravel().argsort() |
|
524 | 525 | junkcspc_interf = jcspectra[ip,:,hei_interf[cspsort[range(offhei_interf, nhei_interf + offhei_interf)]]] |
|
525 | 526 | junkcspc_interf = junkcspc_interf.transpose() |
|
526 | 527 | jcspc_interf = junkcspc_interf.sum(axis = 1)/nhei_interf |
|
527 | 528 | |
|
528 | 529 | ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort() |
|
529 | 530 | |
|
530 | 531 | median_real = numpy.median(numpy.real(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:])) |
|
531 | 532 | median_imag = numpy.median(numpy.imag(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:])) |
|
532 | 533 | junkcspc_interf[comp_mask_prof,:] = numpy.complex(median_real, median_imag) |
|
533 | 534 | |
|
534 | 535 | for iprof in range(num_prof): |
|
535 | 536 | ind = numpy.abs(junkcspc_interf[iprof,:]).ravel().argsort() |
|
536 | 537 | jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf/2]] |
|
537 | 538 | |
|
538 | 539 | #Removiendo la Interferencia |
|
539 | 540 | jcspectra[ip,:,ind_hei] = jcspectra[ip,:,ind_hei] - jcspc_interf |
|
540 | 541 | |
|
541 | 542 | ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist() |
|
542 | 543 | maxid = ListAux.index(max(ListAux)) |
|
543 | 544 | |
|
544 | 545 | ind = numpy.array([-2,-1,1,2]) |
|
545 | 546 | xx = numpy.zeros([4,4]) |
|
546 | 547 | |
|
547 | 548 | for id1 in range(4): |
|
548 | 549 | xx[:,id1] = ind[id1]**numpy.asarray(range(4)) |
|
549 | 550 | |
|
550 | 551 | xx_inv = numpy.linalg.inv(xx) |
|
551 | 552 | xx = xx_inv[:,0] |
|
552 | 553 | |
|
553 | 554 | ind = (ind + maxid + num_mask_prof)%num_mask_prof |
|
554 | 555 | yy = jcspectra[ip,mask_prof[ind],:] |
|
555 | 556 | jcspectra[ip,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx) |
|
556 | 557 | |
|
557 | 558 | #Guardar Resultados |
|
558 | 559 | self.dataOut.data_spc = jspectra |
|
559 | 560 | self.dataOut.data_cspc = jcspectra |
|
560 | 561 | |
|
561 | 562 | return 1 |
|
562 | 563 | |
|
563 | 564 | def setRadarFrequency(self, frequency=None): |
|
564 | 565 | if frequency != None: |
|
565 | 566 | self.dataOut.frequency = frequency |
|
566 | 567 | |
|
567 | 568 | return 1 |
|
568 | 569 | |
|
569 | 570 | def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None): |
|
570 | 571 | #validacion de rango |
|
571 | 572 | if minHei == None: |
|
572 | 573 | minHei = self.dataOut.heightList[0] |
|
573 | 574 | |
|
574 | 575 | if maxHei == None: |
|
575 | 576 | maxHei = self.dataOut.heightList[-1] |
|
576 | 577 | |
|
577 | 578 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): |
|
578 | 579 | print 'minHei: %.2f is out of the heights range'%(minHei) |
|
579 | 580 | print 'minHei is setting to %.2f'%(self.dataOut.heightList[0]) |
|
580 | 581 | minHei = self.dataOut.heightList[0] |
|
581 | 582 | |
|
582 | 583 | if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei): |
|
583 | 584 | print 'maxHei: %.2f is out of the heights range'%(maxHei) |
|
584 | 585 | print 'maxHei is setting to %.2f'%(self.dataOut.heightList[-1]) |
|
585 | 586 | maxHei = self.dataOut.heightList[-1] |
|
586 | 587 | |
|
587 | 588 | # validacion de velocidades |
|
588 | 589 | velrange = self.dataOut.getVelRange(1) |
|
589 | 590 | |
|
590 | 591 | if minVel == None: |
|
591 | 592 | minVel = velrange[0] |
|
592 | 593 | |
|
593 | 594 | if maxVel == None: |
|
594 | 595 | maxVel = velrange[-1] |
|
595 | 596 | |
|
596 | 597 | if (minVel < velrange[0]) or (minVel > maxVel): |
|
597 | 598 | print 'minVel: %.2f is out of the velocity range'%(minVel) |
|
598 | 599 | print 'minVel is setting to %.2f'%(velrange[0]) |
|
599 | 600 | minVel = velrange[0] |
|
600 | 601 | |
|
601 | 602 | if (maxVel > velrange[-1]) or (maxVel < minVel): |
|
602 | 603 | print 'maxVel: %.2f is out of the velocity range'%(maxVel) |
|
603 | 604 | print 'maxVel is setting to %.2f'%(velrange[-1]) |
|
604 | 605 | maxVel = velrange[-1] |
|
605 | 606 | |
|
606 | 607 | # seleccion de indices para rango |
|
607 | 608 | minIndex = 0 |
|
608 | 609 | maxIndex = 0 |
|
609 | 610 | heights = self.dataOut.heightList |
|
610 | 611 | |
|
611 | 612 | inda = numpy.where(heights >= minHei) |
|
612 | 613 | indb = numpy.where(heights <= maxHei) |
|
613 | 614 | |
|
614 | 615 | try: |
|
615 | 616 | minIndex = inda[0][0] |
|
616 | 617 | except: |
|
617 | 618 | minIndex = 0 |
|
618 | 619 | |
|
619 | 620 | try: |
|
620 | 621 | maxIndex = indb[0][-1] |
|
621 | 622 | except: |
|
622 | 623 | maxIndex = len(heights) |
|
623 | 624 | |
|
624 | 625 | if (minIndex < 0) or (minIndex > maxIndex): |
|
625 | 626 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
626 | 627 | |
|
627 | 628 | if (maxIndex >= self.dataOut.nHeights): |
|
628 | 629 | maxIndex = self.dataOut.nHeights-1 |
|
629 | 630 | |
|
630 | 631 | # seleccion de indices para velocidades |
|
631 | 632 | indminvel = numpy.where(velrange >= minVel) |
|
632 | 633 | indmaxvel = numpy.where(velrange <= maxVel) |
|
633 | 634 | try: |
|
634 | 635 | minIndexVel = indminvel[0][0] |
|
635 | 636 | except: |
|
636 | 637 | minIndexVel = 0 |
|
637 | 638 | |
|
638 | 639 | try: |
|
639 | 640 | maxIndexVel = indmaxvel[0][-1] |
|
640 | 641 | except: |
|
641 | 642 | maxIndexVel = len(velrange) |
|
642 | 643 | |
|
643 | 644 | #seleccion del espectro |
|
644 | 645 | data_spc = self.dataOut.data_spc[:,minIndexVel:maxIndexVel+1,minIndex:maxIndex+1] |
|
645 | 646 | #estimacion de ruido |
|
646 | 647 | noise = numpy.zeros(self.dataOut.nChannels) |
|
647 | 648 | |
|
648 | 649 | for channel in range(self.dataOut.nChannels): |
|
649 | 650 | daux = data_spc[channel,:,:] |
|
650 | 651 | noise[channel] = hildebrand_sekhon(daux, self.dataOut.nIncohInt) |
|
651 | 652 | |
|
652 | 653 | self.dataOut.noise_estimation = noise.copy() |
|
653 | 654 | |
|
654 | 655 | return 1 |
|
655 | 656 | |
|
656 | 657 | class IncohInt(Operation): |
|
657 | 658 | |
|
658 | 659 | |
|
659 | 660 | __profIndex = 0 |
|
660 | 661 | __withOverapping = False |
|
661 | 662 | |
|
662 | 663 | __byTime = False |
|
663 | 664 | __initime = None |
|
664 | 665 | __lastdatatime = None |
|
665 | 666 | __integrationtime = None |
|
666 | 667 | |
|
667 | 668 | __buffer_spc = None |
|
668 | 669 | __buffer_cspc = None |
|
669 | 670 | __buffer_dc = None |
|
670 | 671 | |
|
671 | 672 | __dataReady = False |
|
672 | 673 | |
|
673 | 674 | __timeInterval = None |
|
674 | 675 | |
|
675 | 676 | n = None |
|
676 | 677 | |
|
677 | 678 | |
|
678 | 679 | |
|
679 | 680 | def __init__(self): |
|
680 | 681 | |
|
681 | 682 | Operation.__init__(self) |
|
682 | 683 | # self.isConfig = False |
|
683 | 684 | |
|
684 | 685 | def setup(self, n=None, timeInterval=None, overlapping=False): |
|
685 | 686 | """ |
|
686 | 687 | Set the parameters of the integration class. |
|
687 | 688 | |
|
688 | 689 | Inputs: |
|
689 | 690 | |
|
690 | 691 | n : Number of coherent integrations |
|
691 | 692 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
692 | 693 | overlapping : |
|
693 | 694 | |
|
694 | 695 | """ |
|
695 | 696 | |
|
696 | 697 | self.__initime = None |
|
697 | 698 | self.__lastdatatime = 0 |
|
698 | 699 | self.__buffer_spc = None |
|
699 | 700 | self.__buffer_cspc = None |
|
700 | 701 | self.__buffer_dc = None |
|
701 | 702 | self.__dataReady = False |
|
702 | 703 | |
|
703 | 704 | |
|
704 | 705 | if n == None and timeInterval == None: |
|
705 | 706 | raise ValueError, "n or timeInterval should be specified ..." |
|
706 | 707 | |
|
707 | 708 | if n != None: |
|
708 | 709 | self.n = n |
|
709 | 710 | self.__byTime = False |
|
710 | 711 | else: |
|
711 | 712 | self.__integrationtime = timeInterval #if (type(timeInterval)!=integer) -> change this line |
|
712 | 713 | self.n = 9999 |
|
713 | 714 | self.__byTime = True |
|
714 | 715 | |
|
715 | 716 | if overlapping: |
|
716 | 717 | self.__withOverapping = True |
|
717 | 718 | else: |
|
718 | 719 | self.__withOverapping = False |
|
719 | 720 | self.__buffer_spc = 0 |
|
720 | 721 | self.__buffer_cspc = 0 |
|
721 | 722 | self.__buffer_dc = 0 |
|
722 | 723 | |
|
723 | 724 | self.__profIndex = 0 |
|
724 | 725 | |
|
725 | 726 | def putData(self, data_spc, data_cspc, data_dc): |
|
726 | 727 | |
|
727 | 728 | """ |
|
728 | 729 | Add a profile to the __buffer_spc and increase in one the __profileIndex |
|
729 | 730 | |
|
730 | 731 | """ |
|
731 | 732 | |
|
732 | 733 | if not self.__withOverapping: |
|
733 | 734 | self.__buffer_spc += data_spc |
|
734 | 735 | |
|
735 | 736 | if data_cspc == None: |
|
736 | 737 | self.__buffer_cspc = None |
|
737 | 738 | else: |
|
738 | 739 | self.__buffer_cspc += data_cspc |
|
739 | 740 | |
|
740 | 741 | if data_dc == None: |
|
741 | 742 | self.__buffer_dc = None |
|
742 | 743 | else: |
|
743 | 744 | self.__buffer_dc += data_dc |
|
744 | 745 | |
|
745 | 746 | self.__profIndex += 1 |
|
746 | 747 | return |
|
747 | 748 | |
|
748 | 749 | #Overlapping data |
|
749 | 750 | nChannels, nFFTPoints, nHeis = data_spc.shape |
|
750 | 751 | data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis)) |
|
751 | 752 | if data_cspc != None: |
|
752 | 753 | data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis)) |
|
753 | 754 | if data_dc != None: |
|
754 | 755 | data_dc = numpy.reshape(data_dc, (1, -1, nHeis)) |
|
755 | 756 | |
|
756 | 757 | #If the buffer is empty then it takes the data value |
|
757 | 758 | if self.__buffer_spc == None: |
|
758 | 759 | self.__buffer_spc = data_spc |
|
759 | 760 | |
|
760 | 761 | if data_cspc == None: |
|
761 | 762 | self.__buffer_cspc = None |
|
762 | 763 | else: |
|
763 | 764 | self.__buffer_cspc += data_cspc |
|
764 | 765 | |
|
765 | 766 | if data_dc == None: |
|
766 | 767 | self.__buffer_dc = None |
|
767 | 768 | else: |
|
768 | 769 | self.__buffer_dc += data_dc |
|
769 | 770 | |
|
770 | 771 | self.__profIndex += 1 |
|
771 | 772 | return |
|
772 | 773 | |
|
773 | 774 | #If the buffer length is lower than n then stakcing the data value |
|
774 | 775 | if self.__profIndex < self.n: |
|
775 | 776 | self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc)) |
|
776 | 777 | |
|
777 | 778 | if data_cspc != None: |
|
778 | 779 | self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc)) |
|
779 | 780 | |
|
780 | 781 | if data_dc != None: |
|
781 | 782 | self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc)) |
|
782 | 783 | |
|
783 | 784 | self.__profIndex += 1 |
|
784 | 785 | return |
|
785 | 786 | |
|
786 | 787 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
787 | 788 | self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0) |
|
788 | 789 | self.__buffer_spc[self.n-1] = data_spc |
|
789 | 790 | |
|
790 | 791 | if data_cspc != None: |
|
791 | 792 | self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0) |
|
792 | 793 | self.__buffer_cspc[self.n-1] = data_cspc |
|
793 | 794 | |
|
794 | 795 | if data_dc != None: |
|
795 | 796 | self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0) |
|
796 | 797 | self.__buffer_dc[self.n-1] = data_dc |
|
797 | 798 | |
|
798 | 799 | self.__profIndex = self.n |
|
799 | 800 | return |
|
800 | 801 | |
|
801 | 802 | |
|
802 | 803 | def pushData(self): |
|
803 | 804 | """ |
|
804 | 805 | Return the sum of the last profiles and the profiles used in the sum. |
|
805 | 806 | |
|
806 | 807 | Affected: |
|
807 | 808 | |
|
808 | 809 | self.__profileIndex |
|
809 | 810 | |
|
810 | 811 | """ |
|
811 | 812 | data_spc = None |
|
812 | 813 | data_cspc = None |
|
813 | 814 | data_dc = None |
|
814 | 815 | |
|
815 | 816 | if not self.__withOverapping: |
|
816 | 817 | data_spc = self.__buffer_spc |
|
817 | 818 | data_cspc = self.__buffer_cspc |
|
818 | 819 | data_dc = self.__buffer_dc |
|
819 | 820 | |
|
820 | 821 | n = self.__profIndex |
|
821 | 822 | |
|
822 | 823 | self.__buffer_spc = 0 |
|
823 | 824 | self.__buffer_cspc = 0 |
|
824 | 825 | self.__buffer_dc = 0 |
|
825 | 826 | self.__profIndex = 0 |
|
826 | 827 | |
|
827 | 828 | return data_spc, data_cspc, data_dc, n |
|
828 | 829 | |
|
829 | 830 | #Integration with Overlapping |
|
830 | 831 | data_spc = numpy.sum(self.__buffer_spc, axis=0) |
|
831 | 832 | |
|
832 | 833 | if self.__buffer_cspc != None: |
|
833 | 834 | data_cspc = numpy.sum(self.__buffer_cspc, axis=0) |
|
834 | 835 | |
|
835 | 836 | if self.__buffer_dc != None: |
|
836 | 837 | data_dc = numpy.sum(self.__buffer_dc, axis=0) |
|
837 | 838 | |
|
838 | 839 | n = self.__profIndex |
|
839 | 840 | |
|
840 | 841 | return data_spc, data_cspc, data_dc, n |
|
841 | 842 | |
|
842 | 843 | def byProfiles(self, *args): |
|
843 | 844 | |
|
844 | 845 | self.__dataReady = False |
|
845 | 846 | avgdata_spc = None |
|
846 | 847 | avgdata_cspc = None |
|
847 | 848 | avgdata_dc = None |
|
848 | 849 | # n = None |
|
849 | 850 | |
|
850 | 851 | self.putData(*args) |
|
851 | 852 | |
|
852 | 853 | if self.__profIndex == self.n: |
|
853 | 854 | |
|
854 | 855 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() |
|
855 | 856 | self.__dataReady = True |
|
856 | 857 | |
|
857 | 858 | return avgdata_spc, avgdata_cspc, avgdata_dc |
|
858 | 859 | |
|
859 | 860 | def byTime(self, datatime, *args): |
|
860 | 861 | |
|
861 | 862 | self.__dataReady = False |
|
862 | 863 | avgdata_spc = None |
|
863 | 864 | avgdata_cspc = None |
|
864 | 865 | avgdata_dc = None |
|
865 | 866 | n = None |
|
866 | 867 | |
|
867 | 868 | self.putData(*args) |
|
868 | 869 | |
|
869 | 870 | if (datatime - self.__initime) >= self.__integrationtime: |
|
870 | 871 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() |
|
871 | 872 | self.n = n |
|
872 | 873 | self.__dataReady = True |
|
873 | 874 | |
|
874 | 875 | return avgdata_spc, avgdata_cspc, avgdata_dc |
|
875 | 876 | |
|
876 | 877 | def integrate(self, datatime, *args): |
|
877 | 878 | |
|
878 | 879 | if self.__initime == None: |
|
879 | 880 | self.__initime = datatime |
|
880 | 881 | |
|
881 | 882 | if self.__byTime: |
|
882 | 883 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args) |
|
883 | 884 | else: |
|
884 | 885 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args) |
|
885 | 886 | |
|
886 | 887 | self.__lastdatatime = datatime |
|
887 | 888 | |
|
888 | 889 | if avgdata_spc == None: |
|
889 | 890 | return None, None, None, None |
|
890 | 891 | |
|
891 | 892 | avgdatatime = self.__initime |
|
892 | 893 | try: |
|
893 | 894 | self.__timeInterval = (self.__lastdatatime - self.__initime)/(self.n - 1) |
|
894 | 895 | except: |
|
895 | 896 | self.__timeInterval = self.__lastdatatime - self.__initime |
|
896 | 897 | |
|
897 | 898 | deltatime = datatime -self.__lastdatatime |
|
898 | 899 | |
|
899 | 900 | if not self.__withOverapping: |
|
900 | 901 | self.__initime = datatime |
|
901 | 902 | else: |
|
902 | 903 | self.__initime += deltatime |
|
903 | 904 | |
|
904 | 905 | return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc |
|
905 | 906 | |
|
906 | 907 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False): |
|
907 | 908 | |
|
908 | 909 | if n==1: |
|
909 | 910 | dataOut.flagNoData = False |
|
910 | 911 | return |
|
911 | 912 | |
|
912 | 913 | if not self.isConfig: |
|
913 | 914 | self.setup(n, timeInterval, overlapping) |
|
914 | 915 | self.isConfig = True |
|
915 | 916 | |
|
916 | 917 | avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime, |
|
917 | 918 | dataOut.data_spc, |
|
918 | 919 | dataOut.data_cspc, |
|
919 | 920 | dataOut.data_dc) |
|
920 | 921 | |
|
921 | 922 | # dataOut.timeInterval *= n |
|
922 | 923 | dataOut.flagNoData = True |
|
923 | 924 | |
|
924 | 925 | if self.__dataReady: |
|
925 | 926 | |
|
926 | 927 | dataOut.data_spc = avgdata_spc |
|
927 | 928 | dataOut.data_cspc = avgdata_cspc |
|
928 | 929 | dataOut.data_dc = avgdata_dc |
|
929 | 930 | |
|
930 | 931 | dataOut.nIncohInt *= self.n |
|
931 | 932 | dataOut.utctime = avgdatatime |
|
932 | 933 | #dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints |
|
933 | 934 | dataOut.timeInterval = self.__timeInterval*self.n |
|
934 | 935 | dataOut.flagNoData = False |
@@ -1,4 +1,6 | |||
|
1 | 1 | from jroproc_voltage import * |
|
2 | 2 | from jroproc_spectra import * |
|
3 | 3 | from jroproc_heispectra import * |
|
4 | from jroproc_amisr import * No newline at end of file | |
|
4 | from jroproc_amisr import * | |
|
5 | from jroproc_correlation import * | |
|
6 | from jroproc_parameters import * No newline at end of file |
@@ -1,78 +1,81 | |||
|
1 | 1 | """ |
|
2 | 2 | Se debe verficar que el disco de datos se encuentra montado en el sistema |
|
3 | 3 | """ |
|
4 | 4 | import os, sys |
|
5 | 5 | |
|
6 | 6 | path = os.path.split(os.getcwd())[0] |
|
7 | 7 | sys.path.append(path) |
|
8 | 8 | |
|
9 | 9 | from controller import * |
|
10 | 10 | |
|
11 | 11 | desc = "Meteor Experiment Test" |
|
12 | 12 | filename = "meteor20130812.xml" |
|
13 | 13 | |
|
14 | 14 | controllerObj = Project() |
|
15 | 15 | controllerObj.setup(id = '191', name='meteor_test01', description=desc) |
|
16 | 16 | |
|
17 | 17 | path = '/home/dsuarez/.gvfs/data on 10.10.20.13/Jasmet50' |
|
18 | pathFigure = '/home/jasmet/jasmet30_phase' | |
|
19 | path = '/home/soporte/Data/JASMET/JASMET_30/2014106' | |
|
20 | pathFigure = '/home/soporte/workspace/Graficos/JASMET/prueba1' | |
|
18 | 21 | |
|
19 | 22 | |
|
20 | readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage', | |
|
23 | readUnitConfObj = controllerObj.addReadUnit(datatype='VoltageReader', | |
|
21 | 24 | path=path, |
|
22 | 25 | startDate='2014/04/15', |
|
23 | 26 | endDate='2014/04/15', |
|
24 |
startTime=' |
|
|
27 | startTime='20:00:00', | |
|
25 | 28 | endTime='23:59:59', |
|
26 | 29 | online=0, |
|
27 |
walk= |
|
|
30 | walk=0) | |
|
28 | 31 | |
|
29 | 32 | opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock') |
|
30 | 33 | |
|
31 | procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) | |
|
34 | procUnitConfObj0 = controllerObj.addProcUnit(datatype='VoltageProc', inputId=readUnitConfObj.getId()) | |
|
32 | 35 | |
|
33 | 36 | |
|
34 | opObj11 = procUnitConfObj0.addOperation(name='Decoder', optype='other') | |
|
37 | # opObj11 = procUnitConfObj0.addOperation(name='Decoder', optype='other') | |
|
38 | # | |
|
39 | # | |
|
40 | # opObj11 = procUnitConfObj0.addOperation(name='CohInt', optype='other') | |
|
41 | # opObj11.addParameter(name='n', value='2', format='int') | |
|
35 | 42 | |
|
36 | ||
|
37 | opObj11 = procUnitConfObj0.addOperation(name='CohInt', optype='other') | |
|
38 |
opObj11.addParameter(name=' |
|
|
39 | ||
|
40 | opObj11 = procUnitConfObj0.addOperation(name='VoltageWriter', optype='other') | |
|
41 | opObj11.addParameter(name='path', value='/home/jasmet/jasmet30_abril') | |
|
42 | opObj11.addParameter(name='blocksPerFile', value='100', format='int') | |
|
43 | opObj11.addParameter(name='profilesPerBlock', value='200', format='int') | |
|
43 | # opObj11 = procUnitConfObj0.addOperation(name='VoltageWriter', optype='other') | |
|
44 | # opObj11.addParameter(name='path', value='/home/jasmet/jasmet30_abril') | |
|
45 | # opObj11.addParameter(name='blocksPerFile', value='100', format='int') | |
|
46 | # opObj11.addParameter(name='profilesPerBlock', value='200', format='int') | |
|
44 | 47 | |
|
45 | 48 | |
|
46 | 49 | """ |
|
47 | 50 | ########################################### BEACON ########################################## |
|
48 | 51 | """ |
|
49 | 52 | |
|
50 | procUnitConfObjBeacon = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId()) | |
|
53 | procUnitConfObjBeacon = controllerObj.addProcUnit(datatype='SpectraProc', inputId=procUnitConfObj0.getId()) | |
|
51 | 54 | procUnitConfObjBeacon.addParameter(name='nProfiles', value='200', format='int') |
|
52 | 55 | procUnitConfObjBeacon.addParameter(name='nFFTPoints', value='200', format='int') |
|
53 | 56 | procUnitConfObjBeacon.addParameter(name='pairsList', value='(2,0),(2,1),(2,3),(2,4)', format='pairsList') |
|
54 | 57 | |
|
55 | 58 | opObj11 = procUnitConfObjBeacon.addOperation(name='IncohInt', optype='other') |
|
56 | 59 | opObj11.addParameter(name='n', value='4', format='int') |
|
57 | 60 | |
|
58 | 61 | opObj11 = procUnitConfObjBeacon.addOperation(name='getBeaconSignal') |
|
59 | 62 | |
|
60 | 63 | opObj11 = procUnitConfObjBeacon.addOperation(name='BeaconPhase', optype='other') |
|
61 | 64 | opObj11.addParameter(name='id', value='201', format='int') |
|
62 | 65 | opObj11.addParameter(name='wintitle', value='Beacon Phase', format='str') |
|
63 | 66 | opObj11.addParameter(name='timerange', value='300', format='int') |
|
64 | opObj11.addParameter(name='xmin', value='0', format='float') | |
|
65 |
opObj11.addParameter(name='xmax', value='2 |
|
|
67 | opObj11.addParameter(name='xmin', value='20', format='float') | |
|
68 | opObj11.addParameter(name='xmax', value='22', format='float') | |
|
66 | 69 | opObj11.addParameter(name='ymin', value='-180', format='float') |
|
67 | 70 | opObj11.addParameter(name='ymax', value='180', format='float') |
|
68 |
opObj11.addParameter(name='figpath', value= |
|
|
71 | opObj11.addParameter(name='figpath', value=pathFigure, format='str') | |
|
69 | 72 | |
|
70 | 73 | |
|
71 | 74 | print "Escribiendo el archivo XML" |
|
72 | 75 | controllerObj.writeXml(filename) |
|
73 | 76 | print "Leyendo el archivo XML" |
|
74 | 77 | controllerObj.readXml(filename) |
|
75 | 78 | |
|
76 | 79 | controllerObj.createObjects() |
|
77 | 80 | controllerObj.connectObjects() |
|
78 | 81 | controllerObj.run() |
|
1 | NO CONTENT: file renamed from schainpy/test/Meteor_JASMET_50mhz.py to schainpy/test/Meteor_JASMET50Mhz_Beacon.py |
General Comments 0
You need to be logged in to leave comments.
Login now