##// END OF EJS Templates
-Added Radial Velocity graphic ...
Julio Valdez -
r511:4883db3dd5a0
parent child
Show More
@@ -1,576 +1,793
1 import os
1 import os
2 import datetime
2 import datetime
3 import numpy
3 import numpy
4
4
5 from figure import Figure, isRealtime
5 from figure import Figure, isRealtime
6
6
7 class MomentsPlot(Figure):
7 class MomentsPlot(Figure):
8
8
9 isConfig = None
9 isConfig = None
10 __nsubplots = None
10 __nsubplots = None
11
11
12 WIDTHPROF = None
12 WIDTHPROF = None
13 HEIGHTPROF = None
13 HEIGHTPROF = None
14 PREFIX = 'prm'
14 PREFIX = 'prm'
15
15
16 def __init__(self):
16 def __init__(self):
17
17
18 self.isConfig = False
18 self.isConfig = False
19 self.__nsubplots = 1
19 self.__nsubplots = 1
20
20
21 self.WIDTH = 280
21 self.WIDTH = 280
22 self.HEIGHT = 250
22 self.HEIGHT = 250
23 self.WIDTHPROF = 120
23 self.WIDTHPROF = 120
24 self.HEIGHTPROF = 0
24 self.HEIGHTPROF = 0
25 self.counter_imagwr = 0
25 self.counter_imagwr = 0
26
26
27 self.PLOT_CODE = 1
27 self.PLOT_CODE = 1
28 self.FTP_WEI = None
28 self.FTP_WEI = None
29 self.EXP_CODE = None
29 self.EXP_CODE = None
30 self.SUB_EXP_CODE = None
30 self.SUB_EXP_CODE = None
31 self.PLOT_POS = None
31 self.PLOT_POS = None
32
32
33 def getSubplots(self):
33 def getSubplots(self):
34
34
35 ncol = int(numpy.sqrt(self.nplots)+0.9)
35 ncol = int(numpy.sqrt(self.nplots)+0.9)
36 nrow = int(self.nplots*1./ncol + 0.9)
36 nrow = int(self.nplots*1./ncol + 0.9)
37
37
38 return nrow, ncol
38 return nrow, ncol
39
39
40 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
40 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
41
41
42 self.__showprofile = showprofile
42 self.__showprofile = showprofile
43 self.nplots = nplots
43 self.nplots = nplots
44
44
45 ncolspan = 1
45 ncolspan = 1
46 colspan = 1
46 colspan = 1
47 if showprofile:
47 if showprofile:
48 ncolspan = 3
48 ncolspan = 3
49 colspan = 2
49 colspan = 2
50 self.__nsubplots = 2
50 self.__nsubplots = 2
51
51
52 self.createFigure(id = id,
52 self.createFigure(id = id,
53 wintitle = wintitle,
53 wintitle = wintitle,
54 widthplot = self.WIDTH + self.WIDTHPROF,
54 widthplot = self.WIDTH + self.WIDTHPROF,
55 heightplot = self.HEIGHT + self.HEIGHTPROF,
55 heightplot = self.HEIGHT + self.HEIGHTPROF,
56 show=show)
56 show=show)
57
57
58 nrow, ncol = self.getSubplots()
58 nrow, ncol = self.getSubplots()
59
59
60 counter = 0
60 counter = 0
61 for y in range(nrow):
61 for y in range(nrow):
62 for x in range(ncol):
62 for x in range(ncol):
63
63
64 if counter >= self.nplots:
64 if counter >= self.nplots:
65 break
65 break
66
66
67 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
67 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
68
68
69 if showprofile:
69 if showprofile:
70 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
70 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
71
71
72 counter += 1
72 counter += 1
73
73
74 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
74 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
75 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
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,
76 save=False, figpath='', figfile=None, show=True, ftp=False, wr_period=1,
77 server=None, folder=None, username=None, password=None,
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):
78 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
79
79
80 """
80 """
81
81
82 Input:
82 Input:
83 dataOut :
83 dataOut :
84 id :
84 id :
85 wintitle :
85 wintitle :
86 channelList :
86 channelList :
87 showProfile :
87 showProfile :
88 xmin : None,
88 xmin : None,
89 xmax : None,
89 xmax : None,
90 ymin : None,
90 ymin : None,
91 ymax : None,
91 ymax : None,
92 zmin : None,
92 zmin : None,
93 zmax : None
93 zmax : None
94 """
94 """
95
95
96 if dataOut.flagNoData:
96 if dataOut.flagNoData:
97 return None
97 return None
98
98
99 if realtime:
99 if realtime:
100 if not(isRealtime(utcdatatime = dataOut.utctime)):
100 if not(isRealtime(utcdatatime = dataOut.utctime)):
101 print 'Skipping this plot function'
101 print 'Skipping this plot function'
102 return
102 return
103
103
104 if channelList == None:
104 if channelList == None:
105 channelIndexList = dataOut.channelIndexList
105 channelIndexList = dataOut.channelIndexList
106 else:
106 else:
107 channelIndexList = []
107 channelIndexList = []
108 for channel in channelList:
108 for channel in channelList:
109 if channel not in dataOut.channelList:
109 if channel not in dataOut.channelList:
110 raise ValueError, "Channel %d is not in dataOut.channelList"
110 raise ValueError, "Channel %d is not in dataOut.channelList"
111 channelIndexList.append(dataOut.channelList.index(channel))
111 channelIndexList.append(dataOut.channelList.index(channel))
112
112
113 factor = dataOut.normFactor
113 factor = dataOut.normFactor
114 x = dataOut.abscissaRange
114 x = dataOut.abscissaRange
115 y = dataOut.heightRange
115 y = dataOut.heightRange
116
116
117 z = dataOut.data_pre[channelIndexList,:,:]/factor
117 z = dataOut.data_pre[channelIndexList,:,:]/factor
118 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
118 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
119 avg = numpy.average(z, axis=1)
119 avg = numpy.average(z, axis=1)
120 noise = dataOut.noise/factor
120 noise = dataOut.noise/factor
121
121
122 zdB = 10*numpy.log10(z)
122 zdB = 10*numpy.log10(z)
123 avgdB = 10*numpy.log10(avg)
123 avgdB = 10*numpy.log10(avg)
124 noisedB = 10*numpy.log10(noise)
124 noisedB = 10*numpy.log10(noise)
125
125
126 #thisDatetime = dataOut.datatime
126 #thisDatetime = dataOut.datatime
127 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
127 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
128 title = wintitle + " Parameters"
128 title = wintitle + " Parameters"
129 xlabel = "Velocity (m/s)"
129 xlabel = "Velocity (m/s)"
130 ylabel = "Range (Km)"
130 ylabel = "Range (Km)"
131
131
132 if not self.isConfig:
132 if not self.isConfig:
133
133
134 nplots = len(channelIndexList)
134 nplots = len(channelIndexList)
135
135
136 self.setup(id=id,
136 self.setup(id=id,
137 nplots=nplots,
137 nplots=nplots,
138 wintitle=wintitle,
138 wintitle=wintitle,
139 showprofile=showprofile,
139 showprofile=showprofile,
140 show=show)
140 show=show)
141
141
142 if xmin == None: xmin = numpy.nanmin(x)
142 if xmin == None: xmin = numpy.nanmin(x)
143 if xmax == None: xmax = numpy.nanmax(x)
143 if xmax == None: xmax = numpy.nanmax(x)
144 if ymin == None: ymin = numpy.nanmin(y)
144 if ymin == None: ymin = numpy.nanmin(y)
145 if ymax == None: ymax = numpy.nanmax(y)
145 if ymax == None: ymax = numpy.nanmax(y)
146 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
146 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
147 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
147 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
148
148
149 self.FTP_WEI = ftp_wei
149 self.FTP_WEI = ftp_wei
150 self.EXP_CODE = exp_code
150 self.EXP_CODE = exp_code
151 self.SUB_EXP_CODE = sub_exp_code
151 self.SUB_EXP_CODE = sub_exp_code
152 self.PLOT_POS = plot_pos
152 self.PLOT_POS = plot_pos
153
153
154 self.isConfig = True
154 self.isConfig = True
155
155
156 self.setWinTitle(title)
156 self.setWinTitle(title)
157
157
158 for i in range(self.nplots):
158 for i in range(self.nplots):
159 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
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)
160 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i]+1, noisedB[i], str_datetime)
161 axes = self.axesList[i*self.__nsubplots]
161 axes = self.axesList[i*self.__nsubplots]
162 axes.pcolor(x, y, zdB[i,:,:],
162 axes.pcolor(x, y, zdB[i,:,:],
163 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
163 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
164 xlabel=xlabel, ylabel=ylabel, title=title,
164 xlabel=xlabel, ylabel=ylabel, title=title,
165 ticksize=9, cblabel='')
165 ticksize=9, cblabel='')
166 #Mean Line
166 #Mean Line
167 mean = dataOut.data_param[i, 1, :]
167 mean = dataOut.data_param[i, 1, :]
168 axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1)
168 axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1)
169
169
170 if self.__showprofile:
170 if self.__showprofile:
171 axes = self.axesList[i*self.__nsubplots +1]
171 axes = self.axesList[i*self.__nsubplots +1]
172 axes.pline(avgdB[i], y,
172 axes.pline(avgdB[i], y,
173 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
173 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
174 xlabel='dB', ylabel='', title='',
174 xlabel='dB', ylabel='', title='',
175 ytick_visible=False,
175 ytick_visible=False,
176 grid='x')
176 grid='x')
177
177
178 noiseline = numpy.repeat(noisedB[i], len(y))
178 noiseline = numpy.repeat(noisedB[i], len(y))
179 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
179 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
180
180
181 self.draw()
181 self.draw()
182
182
183 if figfile == None:
183 if figfile == None:
184 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
184 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
185 figfile = self.getFilename(name = str_datetime)
185 figfile = self.getFilename(name = str_datetime)
186
186
187 if figpath != '':
187 if figpath != '':
188 self.counter_imagwr += 1
188 self.counter_imagwr += 1
189 if (self.counter_imagwr>=wr_period):
189 if (self.counter_imagwr>=wr_period):
190 # store png plot to local folder
190 # store png plot to local folder
191 self.saveFigure(figpath, figfile)
191 self.saveFigure(figpath, figfile)
192 # store png plot to FTP server according to RT-Web format
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)
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)
194 ftp_filename = os.path.join(figpath, name)
195 self.saveFigure(figpath, ftp_filename)
195 self.saveFigure(figpath, ftp_filename)
196 self.counter_imagwr = 0
196 self.counter_imagwr = 0
197
197
198 class SkyMapPlot(Figure):
198 class SkyMapPlot(Figure):
199
199
200 __isConfig = None
200 __isConfig = None
201 __nsubplots = None
201 __nsubplots = None
202
202
203 WIDTHPROF = None
203 WIDTHPROF = None
204 HEIGHTPROF = None
204 HEIGHTPROF = None
205 PREFIX = 'prm'
205 PREFIX = 'prm'
206
206
207 def __init__(self):
207 def __init__(self):
208
208
209 self.__isConfig = False
209 self.__isConfig = False
210 self.__nsubplots = 1
210 self.__nsubplots = 1
211
211
212 # self.WIDTH = 280
212 # self.WIDTH = 280
213 # self.HEIGHT = 250
213 # self.HEIGHT = 250
214 self.WIDTH = 600
214 self.WIDTH = 600
215 self.HEIGHT = 600
215 self.HEIGHT = 600
216 self.WIDTHPROF = 120
216 self.WIDTHPROF = 120
217 self.HEIGHTPROF = 0
217 self.HEIGHTPROF = 0
218 self.counter_imagwr = 0
218 self.counter_imagwr = 0
219
219
220 self.PLOT_CODE = 1
220 self.PLOT_CODE = 1
221 self.FTP_WEI = None
221 self.FTP_WEI = None
222 self.EXP_CODE = None
222 self.EXP_CODE = None
223 self.SUB_EXP_CODE = None
223 self.SUB_EXP_CODE = None
224 self.PLOT_POS = None
224 self.PLOT_POS = None
225
225
226 def getSubplots(self):
226 def getSubplots(self):
227
227
228 ncol = int(numpy.sqrt(self.nplots)+0.9)
228 ncol = int(numpy.sqrt(self.nplots)+0.9)
229 nrow = int(self.nplots*1./ncol + 0.9)
229 nrow = int(self.nplots*1./ncol + 0.9)
230
230
231 return nrow, ncol
231 return nrow, ncol
232
232
233 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
233 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
234
234
235 self.__showprofile = showprofile
235 self.__showprofile = showprofile
236 self.nplots = nplots
236 self.nplots = nplots
237
237
238 ncolspan = 1
238 ncolspan = 1
239 colspan = 1
239 colspan = 1
240
240
241 self.createFigure(id = id,
241 self.createFigure(id = id,
242 wintitle = wintitle,
242 wintitle = wintitle,
243 widthplot = self.WIDTH, #+ self.WIDTHPROF,
243 widthplot = self.WIDTH, #+ self.WIDTHPROF,
244 heightplot = self.HEIGHT,# + self.HEIGHTPROF,
244 heightplot = self.HEIGHT,# + self.HEIGHTPROF,
245 show=show)
245 show=show)
246
246
247 nrow, ncol = 1,1
247 nrow, ncol = 1,1
248 counter = 0
248 counter = 0
249 x = 0
249 x = 0
250 y = 0
250 y = 0
251 self.addAxes(1, 1, 0, 0, 1, 1, True)
251 self.addAxes(1, 1, 0, 0, 1, 1, True)
252
252
253 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
253 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
254 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
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,
255 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
256 server=None, folder=None, username=None, password=None,
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):
257 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
258
258
259 """
259 """
260
260
261 Input:
261 Input:
262 dataOut :
262 dataOut :
263 id :
263 id :
264 wintitle :
264 wintitle :
265 channelList :
265 channelList :
266 showProfile :
266 showProfile :
267 xmin : None,
267 xmin : None,
268 xmax : None,
268 xmax : None,
269 ymin : None,
269 ymin : None,
270 ymax : None,
270 ymax : None,
271 zmin : None,
271 zmin : None,
272 zmax : None
272 zmax : None
273 """
273 """
274
274
275 arrayParameters = dataOut.data_param
275 arrayParameters = dataOut.data_param
276 error = arrayParameters[:,-1]
276 error = arrayParameters[:,-1]
277 indValid = numpy.where(error == 0)[0]
277 indValid = numpy.where(error == 0)[0]
278 finalMeteor = arrayParameters[indValid,:]
278 finalMeteor = arrayParameters[indValid,:]
279 finalAzimuth = finalMeteor[:,4]
279 finalAzimuth = finalMeteor[:,4]
280 finalZenith = finalMeteor[:,5]
280 finalZenith = finalMeteor[:,5]
281
281
282 x = finalAzimuth*numpy.pi/180
282 x = finalAzimuth*numpy.pi/180
283 y = finalZenith
283 y = finalZenith
284
284
285
285
286 #thisDatetime = dataOut.datatime
286 #thisDatetime = dataOut.datatime
287 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
287 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
288 title = wintitle + " Parameters"
288 title = wintitle + " Parameters"
289 xlabel = "Zonal Zenith Angle (deg) "
289 xlabel = "Zonal Zenith Angle (deg) "
290 ylabel = "Meridional Zenith Angle (deg)"
290 ylabel = "Meridional Zenith Angle (deg)"
291
291
292 if not self.__isConfig:
292 if not self.__isConfig:
293
293
294 nplots = 1
294 nplots = 1
295
295
296 self.setup(id=id,
296 self.setup(id=id,
297 nplots=nplots,
297 nplots=nplots,
298 wintitle=wintitle,
298 wintitle=wintitle,
299 showprofile=showprofile,
299 showprofile=showprofile,
300 show=show)
300 show=show)
301
301
302 self.FTP_WEI = ftp_wei
302 self.FTP_WEI = ftp_wei
303 self.EXP_CODE = exp_code
303 self.EXP_CODE = exp_code
304 self.SUB_EXP_CODE = sub_exp_code
304 self.SUB_EXP_CODE = sub_exp_code
305 self.PLOT_POS = plot_pos
305 self.PLOT_POS = plot_pos
306 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
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"))
307 self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
308 self.__isConfig = True
308 self.__isConfig = True
309
309
310 self.setWinTitle(title)
310 self.setWinTitle(title)
311
311
312 i = 0
312 i = 0
313 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
313 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
314
314
315 axes = self.axesList[i*self.__nsubplots]
315 axes = self.axesList[i*self.__nsubplots]
316 nevents = axes.x_buffer.shape[0] + x.shape[0]
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)
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,
318 axes.polar(x, y,
319 title=title, xlabel=xlabel, ylabel=ylabel,
319 title=title, xlabel=xlabel, ylabel=ylabel,
320 ticksize=9, cblabel='')
320 ticksize=9, cblabel='')
321
321
322 self.draw()
322 self.draw()
323
323
324 if save:
324 if save:
325
325
326 self.counter_imagwr += 1
326 self.counter_imagwr += 1
327 if (self.counter_imagwr==wr_period):
327 if (self.counter_imagwr==wr_period):
328
328
329 if figfile == None:
329 if figfile == None:
330 figfile = self.getFilename(name = self.name)
330 figfile = self.getFilename(name = self.name)
331 self.saveFigure(figpath, figfile)
331 self.saveFigure(figpath, figfile)
332
332
333 if ftp:
333 if ftp:
334 #provisionalmente envia archivos en el formato de la web en tiempo real
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)
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)
336 path = '%s%03d' %(self.PREFIX, self.id)
337 ftp_file = os.path.join(path,'ftp','%s.png'%name)
337 ftp_file = os.path.join(path,'ftp','%s.png'%name)
338 self.saveFigure(figpath, ftp_file)
338 self.saveFigure(figpath, ftp_file)
339 ftp_filename = os.path.join(figpath,ftp_file)
339 ftp_filename = os.path.join(figpath,ftp_file)
340
340
341
341
342 try:
342 try:
343 self.sendByFTP(ftp_filename, server, folder, username, password)
343 self.sendByFTP(ftp_filename, server, folder, username, password)
344 except:
344 except:
345 self.counter_imagwr = 0
345 self.counter_imagwr = 0
346 raise ValueError, 'Error FTP'
346 raise ValueError, 'Error FTP'
347
347
348 self.counter_imagwr = 0
348 self.counter_imagwr = 0
349
349
350
350
351 class WindProfilerPlot(Figure):
351 class WindProfilerPlot(Figure):
352
352
353 __isConfig = None
353 __isConfig = None
354 __nsubplots = None
354 __nsubplots = None
355
355
356 WIDTHPROF = None
356 WIDTHPROF = None
357 HEIGHTPROF = None
357 HEIGHTPROF = None
358 PREFIX = 'wind'
358 PREFIX = 'wind'
359
359
360 def __init__(self):
360 def __init__(self):
361
361
362 self.timerange = 2*60*60
362 self.timerange = 2*60*60
363 self.__isConfig = False
363 self.__isConfig = False
364 self.__nsubplots = 1
364 self.__nsubplots = 1
365
365
366 self.WIDTH = 800
366 self.WIDTH = 800
367 self.HEIGHT = 150
367 self.HEIGHT = 150
368 self.WIDTHPROF = 120
368 self.WIDTHPROF = 120
369 self.HEIGHTPROF = 0
369 self.HEIGHTPROF = 0
370 self.counter_imagwr = 0
370 self.counter_imagwr = 0
371
371
372 self.PLOT_CODE = 0
372 self.PLOT_CODE = 0
373 self.FTP_WEI = None
373 self.FTP_WEI = None
374 self.EXP_CODE = None
374 self.EXP_CODE = None
375 self.SUB_EXP_CODE = None
375 self.SUB_EXP_CODE = None
376 self.PLOT_POS = None
376 self.PLOT_POS = None
377 self.tmin = None
377 self.tmin = None
378 self.tmax = None
378 self.tmax = None
379
379
380 self.xmin = None
380 self.xmin = None
381 self.xmax = None
381 self.xmax = None
382
382
383 self.figfile = None
383 self.figfile = None
384
384
385 def getSubplots(self):
385 def getSubplots(self):
386
386
387 ncol = 1
387 ncol = 1
388 nrow = self.nplots
388 nrow = self.nplots
389
389
390 return nrow, ncol
390 return nrow, ncol
391
391
392 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
392 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
393
393
394 self.__showprofile = showprofile
394 self.__showprofile = showprofile
395 self.nplots = nplots
395 self.nplots = nplots
396
396
397 ncolspan = 1
397 ncolspan = 1
398 colspan = 1
398 colspan = 1
399
399
400 self.createFigure(id = id,
400 self.createFigure(id = id,
401 wintitle = wintitle,
401 wintitle = wintitle,
402 widthplot = self.WIDTH + self.WIDTHPROF,
402 widthplot = self.WIDTH + self.WIDTHPROF,
403 heightplot = self.HEIGHT + self.HEIGHTPROF,
403 heightplot = self.HEIGHT + self.HEIGHTPROF,
404 show=show)
404 show=show)
405
405
406 nrow, ncol = self.getSubplots()
406 nrow, ncol = self.getSubplots()
407
407
408 counter = 0
408 counter = 0
409 for y in range(nrow):
409 for y in range(nrow):
410 if counter >= self.nplots:
410 if counter >= self.nplots:
411 break
411 break
412
412
413 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
413 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
414 counter += 1
414 counter += 1
415
415
416 def run(self, dataOut, id, wintitle="", channelList=None,
416 def run(self, dataOut, id, wintitle="", channelList=None,
417 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=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,
418 zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None,
419 timerange=None, SNRthresh = None,
419 timerange=None, SNRthresh = None,
420 save=False, figpath='', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
420 save=False, figpath='', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
421 server=None, folder=None, username=None, password=None,
421 server=None, folder=None, username=None, password=None,
422 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
422 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
423 """
423 """
424
424
425 Input:
425 Input:
426 dataOut :
426 dataOut :
427 id :
427 id :
428 wintitle :
428 wintitle :
429 channelList :
429 channelList :
430 showProfile :
430 showProfile :
431 xmin : None,
431 xmin : None,
432 xmax : None,
432 xmax : None,
433 ymin : None,
433 ymin : None,
434 ymax : None,
434 ymax : None,
435 zmin : None,
435 zmin : None,
436 zmax : None
436 zmax : None
437 """
437 """
438
438
439 if channelList == None:
439 if channelList == None:
440 channelIndexList = dataOut.channelIndexList
440 channelIndexList = dataOut.channelIndexList
441 else:
441 else:
442 channelIndexList = []
442 channelIndexList = []
443 for channel in channelList:
443 for channel in channelList:
444 if channel not in dataOut.channelList:
444 if channel not in dataOut.channelList:
445 raise ValueError, "Channel %d is not in dataOut.channelList"
445 raise ValueError, "Channel %d is not in dataOut.channelList"
446 channelIndexList.append(dataOut.channelList.index(channel))
446 channelIndexList.append(dataOut.channelList.index(channel))
447
447
448 if timerange != None:
448 if timerange != None:
449 self.timerange = timerange
449 self.timerange = timerange
450
450
451 tmin = None
451 tmin = None
452 tmax = None
452 tmax = None
453
453
454 x = dataOut.getTimeRange1()
454 x = dataOut.getTimeRange1()
455 # y = dataOut.heightRange
455 # y = dataOut.heightRange
456 y = dataOut.heightRange
456 y = dataOut.heightRange
457
457
458 z = dataOut.winds
458 z = dataOut.winds.copy()
459 nplots = z.shape[0] #Number of wind dimensions estimated
459 nplots = z.shape[0] #Number of wind dimensions estimated
460 nplotsw = nplots
460 nplotsw = nplots
461
461
462 #If there is a SNR function defined
462 #If there is a SNR function defined
463 if dataOut.SNR != None:
463 if dataOut.SNR != None:
464 nplots += 1
464 nplots += 1
465 SNR = dataOut.SNR
465 SNR = dataOut.SNR
466 SNRavg = numpy.average(SNR, axis=0)
466 SNRavg = numpy.average(SNR, axis=0)
467
467
468 SNRdB = 10*numpy.log10(SNR)
468 SNRdB = 10*numpy.log10(SNR)
469 SNRavgdB = 10*numpy.log10(SNRavg)
469 SNRavgdB = 10*numpy.log10(SNRavg)
470
470
471 if SNRthresh == None: SNRthresh = -5.0
471 if SNRthresh == None: SNRthresh = -5.0
472 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
472 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
473
473
474 for i in range(nplotsw):
474 for i in range(nplotsw):
475 z[i,ind] = numpy.nan
475 z[i,ind] = numpy.nan
476
476
477
477
478 showprofile = False
478 showprofile = False
479 # thisDatetime = dataOut.datatime
479 # thisDatetime = dataOut.datatime
480 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
480 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
481 title = wintitle + "Wind"
481 title = wintitle + "Wind"
482 xlabel = ""
482 xlabel = ""
483 ylabel = "Range (Km)"
483 ylabel = "Range (Km)"
484
484
485 if not self.__isConfig:
485 if not self.__isConfig:
486
486
487 self.setup(id=id,
487 self.setup(id=id,
488 nplots=nplots,
488 nplots=nplots,
489 wintitle=wintitle,
489 wintitle=wintitle,
490 showprofile=showprofile,
490 showprofile=showprofile,
491 show=show)
491 show=show)
492
492
493 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
493 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
494
494
495 if ymin == None: ymin = numpy.nanmin(y)
495 if ymin == None: ymin = numpy.nanmin(y)
496 if ymax == None: ymax = numpy.nanmax(y)
496 if ymax == None: ymax = numpy.nanmax(y)
497
497
498 if zmax == None: zmax = numpy.nanmax(abs(z[range(2),:]))
498 if zmax == None: zmax = numpy.nanmax(abs(z[range(2),:]))
499 #if numpy.isnan(zmax): zmax = 50
499 #if numpy.isnan(zmax): zmax = 50
500 if zmin == None: zmin = -zmax
500 if zmin == None: zmin = -zmax
501
501
502 if nplotsw == 3:
502 if nplotsw == 3:
503 if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:]))
503 if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:]))
504 if zmin_ver == None: zmin_ver = -zmax_ver
504 if zmin_ver == None: zmin_ver = -zmax_ver
505
505
506 if dataOut.SNR != None:
506 if dataOut.SNR != None:
507 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
507 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
508 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
508 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
509
509
510 self.FTP_WEI = ftp_wei
510 self.FTP_WEI = ftp_wei
511 self.EXP_CODE = exp_code
511 self.EXP_CODE = exp_code
512 self.SUB_EXP_CODE = sub_exp_code
512 self.SUB_EXP_CODE = sub_exp_code
513 self.PLOT_POS = plot_pos
513 self.PLOT_POS = plot_pos
514
514
515 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
515 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
516 self.__isConfig = True
516 self.__isConfig = True
517
517
518
518
519 self.setWinTitle(title)
519 self.setWinTitle(title)
520
520
521 if ((self.xmax - x[1]) < (x[1]-x[0])):
521 if ((self.xmax - x[1]) < (x[1]-x[0])):
522 x[1] = self.xmax
522 x[1] = self.xmax
523
523
524 strWind = ['Zonal', 'Meridional', 'Vertical']
524 strWind = ['Zonal', 'Meridional', 'Vertical']
525 strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)']
525 strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)']
526 zmaxVector = [zmax, zmax, zmax_ver]
526 zmaxVector = [zmax, zmax, zmax_ver]
527 zminVector = [zmin, zmin, zmin_ver]
527 zminVector = [zmin, zmin, zmin_ver]
528 windFactor = [1,1,100]
528 windFactor = [1,1,100]
529
529
530 for i in range(nplotsw):
530 for i in range(nplotsw):
531
531
532 title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
532 title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
533 axes = self.axesList[i*self.__nsubplots]
533 axes = self.axesList[i*self.__nsubplots]
534
534
535 z1 = z[i,:].reshape((1,-1))*windFactor[i]
535 z1 = z[i,:].reshape((1,-1))*windFactor[i]
536
536
537 axes.pcolorbuffer(x, y, z1,
537 axes.pcolorbuffer(x, y, z1,
538 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
538 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
539 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
539 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
540 ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="RdBu_r" )
540 ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="RdBu_r" )
541
541
542 if dataOut.SNR != None:
542 if dataOut.SNR != None:
543 i += 1
543 i += 1
544 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
544 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
545 axes = self.axesList[i*self.__nsubplots]
545 axes = self.axesList[i*self.__nsubplots]
546
546
547 SNRavgdB = SNRavgdB.reshape((1,-1))
547 SNRavgdB = SNRavgdB.reshape((1,-1))
548
548
549 axes.pcolorbuffer(x, y, SNRavgdB,
549 axes.pcolorbuffer(x, y, SNRavgdB,
550 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
550 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
551 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
551 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
552 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
552 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
553
553
554 self.draw()
554 self.draw()
555
555
556 if self.figfile == None:
556 if self.figfile == None:
557 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
557 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
558 self.figfile = self.getFilename(name = str_datetime)
558 self.figfile = self.getFilename(name = str_datetime)
559
559
560 if figpath != '':
560 if figpath != '':
561
561
562 self.counter_imagwr += 1
562 self.counter_imagwr += 1
563 if (self.counter_imagwr>=wr_period):
563 if (self.counter_imagwr>=wr_period):
564 # store png plot to local folder
564 # store png plot to local folder
565 self.saveFigure(figpath, self.figfile)
565 self.saveFigure(figpath, self.figfile)
566 # store png plot to FTP server according to RT-Web format
566 # store png plot to FTP server according to RT-Web format
567 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
567 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
568 ftp_filename = os.path.join(figpath, name)
568 ftp_filename = os.path.join(figpath, name)
569 self.saveFigure(figpath, ftp_filename)
569 self.saveFigure(figpath, ftp_filename)
570
570
571 self.counter_imagwr = 0
571 self.counter_imagwr = 0
572
572
573 if x[1] >= self.axesList[0].xmax:
573 if x[1] >= self.axesList[0].xmax:
574 self.counter_imagwr = wr_period
574 self.counter_imagwr = wr_period
575 self.__isConfig = False
575 self.__isConfig = False
576 self.figfile = None
577
578
579 class RadialVelocityPlot(Figure):
580
581 __isConfig = None
582 __nsubplots = None
583
584 WIDTHPROF = None
585 HEIGHTPROF = None
586 PREFIX = 'rti'
587
588 def __init__(self):
589
590 self.timerange = 2*60*60
591 self.__isConfig = False
592 self.__nsubplots = 1
593
594 self.WIDTH = 800
595 self.HEIGHT = 150
596 self.WIDTHPROF = 120
597 self.HEIGHTPROF = 0
598 self.counter_imagwr = 0
599
600 self.PLOT_CODE = 0
601 self.FTP_WEI = None
602 self.EXP_CODE = None
603 self.SUB_EXP_CODE = None
604 self.PLOT_POS = None
605 self.tmin = None
606 self.tmax = None
607
608 self.xmin = None
609 self.xmax = None
610
611 self.figfile = None
612
613 def getSubplots(self):
614
615 ncol = 1
616 nrow = self.nplots
617
618 return nrow, ncol
619
620 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
621
622 self.__showprofile = showprofile
623 self.nplots = nplots
624
625 ncolspan = 1
626 colspan = 1
627
628 self.createFigure(id = id,
629 wintitle = wintitle,
630 widthplot = self.WIDTH + self.WIDTHPROF,
631 heightplot = self.HEIGHT + self.HEIGHTPROF,
632 show=show)
633
634 nrow, ncol = self.getSubplots()
635
636 counter = 0
637 for y in range(nrow):
638 for x in range(ncol):
639
640 if counter >= self.nplots:
641 break
642
643 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
644
645 if showprofile:
646 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
647
648 counter += 1
649
650 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
651 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None,
652 SNRmin = None, SNRmax = None, SNRthresh = None, paramIndex = None,
653 save=False, figpath='', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
654 server=None, folder=None, username=None, password=None,
655 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
656
657 """
658
659 Input:
660 dataOut :
661 id :
662 wintitle :
663 channelList :
664 showProfile :
665 xmin : None,
666 xmax : None,
667 ymin : None,
668 ymax : None,
669 zmin : None,
670 zmax : None
671 """
672
673 if channelList == None:
674 channelIndexList = dataOut.channelIndexList
675 else:
676 channelIndexList = []
677 for channel in channelList:
678 if channel not in dataOut.channelList:
679 raise ValueError, "Channel %d is not in dataOut.channelList"
680 channelIndexList.append(dataOut.channelList.index(channel))
681
682 if timerange != None:
683 self.timerange = timerange
684
685 #tmin = None
686 #tmax = None
687 if paramIndex == None:
688 paramIndex = 1
689 x = dataOut.getTimeRange1()
690 y = dataOut.heightRange
691 z = dataOut.data_param[channelIndexList,paramIndex,:].copy()
692
693 zRange = dataOut.abscissaRange
694 nplots = z.shape[0] #Number of wind dimensions estimated
695 nplotsw = nplots
696
697 if dataOut.SNR != None:
698 nplots += 1
699 SNR = dataOut.SNR
700 SNRavg = numpy.average(SNR, axis=0)
701
702 SNRdB = 10*numpy.log10(SNR)
703 SNRavgdB = 10*numpy.log10(SNRavg)
704
705 if SNRthresh == None: SNRthresh = -5.0
706 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
707
708 for i in range(nplotsw):
709 z[i,ind] = numpy.nan
710 # thisDatetime = dataOut.datatime
711 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
712 title = wintitle + " Radial Velocity" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
713 xlabel = ""
714 ylabel = "Height (Km)"
715
716 if not self.__isConfig:
717
718 self.setup(id=id,
719 nplots=nplots,
720 wintitle=wintitle,
721 showprofile=showprofile,
722 show=show)
723
724 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
725
726 if ymin == None: ymin = numpy.nanmin(y)
727 if ymax == None: ymax = numpy.nanmax(y)
728 if zmin == None: zmin = numpy.nanmin(zRange)
729 if zmax == None: zmax = numpy.nanmax(zRange)
730 if dataOut.SNR != None:
731 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
732 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
733
734 self.FTP_WEI = ftp_wei
735 self.EXP_CODE = exp_code
736 self.SUB_EXP_CODE = sub_exp_code
737 self.PLOT_POS = plot_pos
738
739 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
740 self.__isConfig = True
741 self.figfile = figfile
742
743 self.setWinTitle(title)
744
745 if ((self.xmax - x[1]) < (x[1]-x[0])):
746 x[1] = self.xmax
747
748 for i in range(nplotsw):
749 title = "Channel %d: %s" %(dataOut.channelList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
750 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
751 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
752 axes = self.axesList[i*self.__nsubplots]
753 z1 = z[i,:].reshape((1,-1))
754 axes.pcolorbuffer(x, y, z1,
755 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
756 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap="RdBu_r",
757 ticksize=9, cblabel='', cbsize="1%")
758
759 if dataOut.SNR != None:
760 i += 1
761 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
762 axes = self.axesList[i*self.__nsubplots]
763
764 SNRavgdB = SNRavgdB.reshape((1,-1))
765
766 axes.pcolorbuffer(x, y, SNRavgdB,
767 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
768 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
769 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
770
771 self.draw()
772
773 if self.figfile == None:
774 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
775 self.figfile = self.getFilename(name = str_datetime)
776
777 if figpath != '':
778
779 self.counter_imagwr += 1
780 if (self.counter_imagwr>=wr_period):
781 # store png plot to local folder
782 self.saveFigure(figpath, self.figfile)
783 # store png plot to FTP server according to RT-Web format
784 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
785 ftp_filename = os.path.join(figpath, name)
786 self.saveFigure(figpath, ftp_filename)
787
788 self.counter_imagwr = 0
789
790 if x[1] >= self.axesList[0].xmax:
791 self.counter_imagwr = wr_period
792 self.__isConfig = False
576 self.figfile = None No newline at end of file
793 self.figfile = None
@@ -1,1539 +1,1539
1 import numpy
1 import numpy
2 import math
2 import math
3 from scipy import optimize
3 from scipy import optimize
4 from scipy import interpolate
4 from scipy import interpolate
5 from scipy import signal
5 from scipy import signal
6 from scipy import stats
6 from scipy import stats
7 import re
7 import re
8 import datetime
8 import datetime
9 import copy
9 import copy
10
10
11
11
12 from jroproc_base import ProcessingUnit, Operation
12 from jroproc_base import ProcessingUnit, Operation
13 from model.data.jrodata import Parameters
13 from model.data.jrodata import Parameters
14
14
15
15
16 class ParametersProc(ProcessingUnit):
16 class ParametersProc(ProcessingUnit):
17
17
18 nSeconds = None
18 nSeconds = None
19
19
20 def __init__(self):
20 def __init__(self):
21 ProcessingUnit.__init__(self)
21 ProcessingUnit.__init__(self)
22
22
23 self.objectDict = {}
23 self.objectDict = {}
24 self.buffer = None
24 self.buffer = None
25 self.firstdatatime = None
25 self.firstdatatime = None
26 self.profIndex = 0
26 self.profIndex = 0
27 self.dataOut = Parameters()
27 self.dataOut = Parameters()
28
28
29 def __updateObjFromInput(self):
29 def __updateObjFromInput(self):
30
30
31 self.dataOut.inputUnit = self.dataIn.type
31 self.dataOut.inputUnit = self.dataIn.type
32
32
33 self.dataOut.timeZone = self.dataIn.timeZone
33 self.dataOut.timeZone = self.dataIn.timeZone
34 self.dataOut.dstFlag = self.dataIn.dstFlag
34 self.dataOut.dstFlag = self.dataIn.dstFlag
35 self.dataOut.errorCount = self.dataIn.errorCount
35 self.dataOut.errorCount = self.dataIn.errorCount
36 self.dataOut.useLocalTime = self.dataIn.useLocalTime
36 self.dataOut.useLocalTime = self.dataIn.useLocalTime
37
37
38 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
38 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
39 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
39 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
40 self.dataOut.channelList = self.dataIn.channelList
40 self.dataOut.channelList = self.dataIn.channelList
41 self.dataOut.heightList = self.dataIn.heightList
41 self.dataOut.heightList = self.dataIn.heightList
42 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
42 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
43 # self.dataOut.nHeights = self.dataIn.nHeights
43 # self.dataOut.nHeights = self.dataIn.nHeights
44 # self.dataOut.nChannels = self.dataIn.nChannels
44 # self.dataOut.nChannels = self.dataIn.nChannels
45 self.dataOut.nBaud = self.dataIn.nBaud
45 self.dataOut.nBaud = self.dataIn.nBaud
46 self.dataOut.nCode = self.dataIn.nCode
46 self.dataOut.nCode = self.dataIn.nCode
47 self.dataOut.code = self.dataIn.code
47 self.dataOut.code = self.dataIn.code
48 # self.dataOut.nProfiles = self.dataOut.nFFTPoints
48 # self.dataOut.nProfiles = self.dataOut.nFFTPoints
49 self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock
49 self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock
50 self.dataOut.utctime = self.firstdatatime
50 self.dataOut.utctime = self.firstdatatime
51 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
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
52 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
53 # self.dataOut.nCohInt = self.dataIn.nCohInt
53 # self.dataOut.nCohInt = self.dataIn.nCohInt
54 # self.dataOut.nIncohInt = 1
54 # self.dataOut.nIncohInt = 1
55 self.dataOut.ippSeconds = self.dataIn.ippSeconds
55 self.dataOut.ippSeconds = self.dataIn.ippSeconds
56 # self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
56 # self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
57 self.dataOut.timeInterval = self.dataIn.timeInterval
57 self.dataOut.timeInterval = self.dataIn.timeInterval
58 self.dataOut.heightRange = self.dataIn.getHeiRange()
58 self.dataOut.heightRange = self.dataIn.getHeiRange()
59 self.dataOut.frequency = self.dataIn.frequency
59 self.dataOut.frequency = self.dataIn.frequency
60
60
61 def run(self, nSeconds = None, nProfiles = None):
61 def run(self, nSeconds = None, nProfiles = None):
62
62
63 self.dataOut.flagNoData = True
63 self.dataOut.flagNoData = True
64
64
65 if self.firstdatatime == None:
65 if self.firstdatatime == None:
66 self.firstdatatime = self.dataIn.utctime
66 self.firstdatatime = self.dataIn.utctime
67
67
68 #---------------------- Voltage Data ---------------------------
68 #---------------------- Voltage Data ---------------------------
69
69
70 if self.dataIn.type == "Voltage":
70 if self.dataIn.type == "Voltage":
71 if nSeconds != None:
71 if nSeconds != None:
72 self.nSeconds = nSeconds
72 self.nSeconds = nSeconds
73 self.nProfiles= int(numpy.floor(nSeconds/(self.dataIn.ippSeconds*self.dataIn.nCohInt)))
73 self.nProfiles= int(numpy.floor(nSeconds/(self.dataIn.ippSeconds*self.dataIn.nCohInt)))
74
74
75 if self.buffer == None:
75 if self.buffer == None:
76 self.buffer = numpy.zeros((self.dataIn.nChannels,
76 self.buffer = numpy.zeros((self.dataIn.nChannels,
77 self.nProfiles,
77 self.nProfiles,
78 self.dataIn.nHeights),
78 self.dataIn.nHeights),
79 dtype='complex')
79 dtype='complex')
80
80
81 self.buffer[:,self.profIndex,:] = self.dataIn.data.copy()
81 self.buffer[:,self.profIndex,:] = self.dataIn.data.copy()
82 self.profIndex += 1
82 self.profIndex += 1
83
83
84 if self.profIndex == self.nProfiles:
84 if self.profIndex == self.nProfiles:
85
85
86 self.__updateObjFromInput()
86 self.__updateObjFromInput()
87 self.dataOut.data_pre = self.buffer.copy()
87 self.dataOut.data_pre = self.buffer.copy()
88 self.dataOut.paramInterval = nSeconds
88 self.dataOut.paramInterval = nSeconds
89 self.dataOut.flagNoData = False
89 self.dataOut.flagNoData = False
90
90
91 self.buffer = None
91 self.buffer = None
92 self.firstdatatime = None
92 self.firstdatatime = None
93 self.profIndex = 0
93 self.profIndex = 0
94 return
94
95
95 #---------------------- Spectra Data ---------------------------
96 #---------------------- Spectra Data ---------------------------
96
97
97 if self.dataIn.type == "Spectra":
98 if self.dataIn.type == "Spectra":
98 self.dataOut.data_pre = self.dataIn.data_spc.copy()
99 self.dataOut.data_pre = self.dataIn.data_spc.copy()
99 self.dataOut.abscissaRange = self.dataIn.getVelRange(1)
100 self.dataOut.abscissaRange = self.dataIn.getVelRange(1)
100 self.dataOut.noise = self.dataIn.getNoise()
101 self.dataOut.noise = self.dataIn.getNoise()
101 self.dataOut.normFactor = self.dataIn.normFactor
102 self.dataOut.normFactor = self.dataIn.normFactor
102
103
103 self.__updateObjFromInput()
104 self.dataOut.flagNoData = False
105 self.firstdatatime = None
106
107 #---------------------- Correlation Data ---------------------------
104 #---------------------- Correlation Data ---------------------------
108
105
109 if self.dataIn.type == "Correlation":
106 if self.dataIn.type == "Correlation":
110 lagRRange = self.dataIn.lagR
107 lagRRange = self.dataIn.lagR
111 indR = numpy.where(lagRRange == 0)[0][0]
108 indR = numpy.where(lagRRange == 0)[0][0]
112
109
113 self.dataOut.data_pre = self.dataIn.data_corr.copy()[:,:,indR,:]
110 self.dataOut.data_pre = self.dataIn.data_corr.copy()[:,:,indR,:]
114 self.dataOut.abscissaRange = self.dataIn.getLagTRange(1)
111 self.dataOut.abscissaRange = self.dataIn.getLagTRange(1)
115 self.dataOut.noise = self.dataIn.noise
112 self.dataOut.noise = self.dataIn.noise
116 self.dataOut.normFactor = self.dataIn.normFactor
113 self.dataOut.normFactor = self.dataIn.normFactor
117 self.dataOut.SNR = self.dataIn.SNR
114 self.dataOut.SNR = self.dataIn.SNR
118 self.dataOut.pairsList = self.dataIn.pairsList
115 self.dataOut.pairsList = self.dataIn.pairsList
119
116
120 self.__updateObjFromInput()
117
121 self.dataOut.flagNoData = False
118 self.__updateObjFromInput()
122 self.firstdatatime = None
119 self.dataOut.flagNoData = False
120 self.firstdatatime = None
121 self.dataOut.initUtcTime = self.dataIn.ltctime
122 self.dataOut.windsInterval = self.dataIn.timeInterval
123
123
124 #------------------- Get Moments ----------------------------------
124 #------------------- Get Moments ----------------------------------
125 def GetMoments(self, channelList = None):
125 def GetMoments(self, channelList = None):
126 '''
126 '''
127 Function GetMoments()
127 Function GetMoments()
128
128
129 Input:
129 Input:
130 channelList : simple channel list to select e.g. [2,3,7]
130 channelList : simple channel list to select e.g. [2,3,7]
131 self.dataOut.data_pre
131 self.dataOut.data_pre
132 self.dataOut.abscissaRange
132 self.dataOut.abscissaRange
133 self.dataOut.noise
133 self.dataOut.noise
134
134
135 Affected:
135 Affected:
136 self.dataOut.data_param
136 self.dataOut.data_param
137 self.dataOut.SNR
137 self.dataOut.SNR
138
138
139 '''
139 '''
140 data = self.dataOut.data_pre
140 data = self.dataOut.data_pre
141 absc = self.dataOut.abscissaRange[:-1]
141 absc = self.dataOut.abscissaRange[:-1]
142 noise = self.dataOut.noise
142 noise = self.dataOut.noise
143
143
144 data_param = numpy.zeros((data.shape[0], 4, data.shape[2]))
144 data_param = numpy.zeros((data.shape[0], 4, data.shape[2]))
145
145
146 if channelList== None: channelList = self.dataOut.channelList
146 if channelList== None:
147 channelList = self.dataIn.channelList
148 self.dataOut.channelList = channelList
147
149
148 for ind in channelList:
150 for ind in channelList:
149 data_param[ind,:,:] = self.__calculateMoments(data[ind,:,:], absc, noise[ind])
151 data_param[ind,:,:] = self.__calculateMoments(data[ind,:,:], absc, noise[ind])
150
152
151 self.dataOut.data_param = data_param[:,1:]
153 self.dataOut.data_param = data_param[:,1:,:]
152 self.dataOut.SNR = data_param[:,0]
154 self.dataOut.SNR = data_param[:,0]
153 return
155 return
154
156
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):
157 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
158
157 if (nicoh == None): nicoh = 1
159 if (nicoh == None): nicoh = 1
158 if (graph == None): graph = 0
160 if (graph == None): graph = 0
159 if (smooth == None): smooth = 0
161 if (smooth == None): smooth = 0
160 elif (self.smooth < 3): smooth = 0
162 elif (self.smooth < 3): smooth = 0
161
163
162 if (type1 == None): type1 = 0
164 if (type1 == None): type1 = 0
163 if (fwindow == None): fwindow = numpy.zeros(oldfreq.size) + 1
165 if (fwindow == None): fwindow = numpy.zeros(oldfreq.size) + 1
164 if (snrth == None): snrth = -3
166 if (snrth == None): snrth = -3
165 if (dc == None): dc = 0
167 if (dc == None): dc = 0
166 if (aliasing == None): aliasing = 0
168 if (aliasing == None): aliasing = 0
167 if (oldfd == None): oldfd = 0
169 if (oldfd == None): oldfd = 0
168 if (wwauto == None): wwauto = 0
170 if (wwauto == None): wwauto = 0
169
171
170 if (n0 < 1.e-20): n0 = 1.e-20
172 if (n0 < 1.e-20): n0 = 1.e-20
171
173
172 freq = oldfreq
174 freq = oldfreq
173 vec_power = numpy.zeros(oldspec.shape[1])
175 vec_power = numpy.zeros(oldspec.shape[1])
174 vec_fd = numpy.zeros(oldspec.shape[1])
176 vec_fd = numpy.zeros(oldspec.shape[1])
175 vec_w = numpy.zeros(oldspec.shape[1])
177 vec_w = numpy.zeros(oldspec.shape[1])
176 vec_snr = numpy.zeros(oldspec.shape[1])
178 vec_snr = numpy.zeros(oldspec.shape[1])
177
179
178 for ind in range(oldspec.shape[1]):
180 for ind in range(oldspec.shape[1]):
179
181
180 spec = oldspec[:,ind]
182 spec = oldspec[:,ind]
181 aux = spec*fwindow
183 aux = spec*fwindow
182 max_spec = aux.max()
184 max_spec = aux.max()
183 m = list(aux).index(max_spec)
185 m = list(aux).index(max_spec)
184
186
185 #Smooth
187 #Smooth
186 if (smooth == 0): spec2 = spec
188 if (smooth == 0): spec2 = spec
187 else: spec2 = scipy.ndimage.filters.uniform_filter1d(spec,size=smooth)
189 else: spec2 = scipy.ndimage.filters.uniform_filter1d(spec,size=smooth)
188
190
189 # Calculo de Momentos
191 # Calculo de Momentos
190 bb = spec2[range(m,spec2.size)]
192 bb = spec2[range(m,spec2.size)]
191 bb = (bb<n0).nonzero()
193 bb = (bb<n0).nonzero()
192 bb = bb[0]
194 bb = bb[0]
193
195
194 ss = spec2[range(0,m + 1)]
196 ss = spec2[range(0,m + 1)]
195 ss = (ss<n0).nonzero()
197 ss = (ss<n0).nonzero()
196 ss = ss[0]
198 ss = ss[0]
197
199
198 if (bb.size == 0):
200 if (bb.size == 0):
199 bb0 = spec.size - 1 - m
201 bb0 = spec.size - 1 - m
200 else:
202 else:
201 bb0 = bb[0] - 1
203 bb0 = bb[0] - 1
202 if (bb0 < 0):
204 if (bb0 < 0):
203 bb0 = 0
205 bb0 = 0
204
206
205 if (ss.size == 0): ss1 = 1
207 if (ss.size == 0): ss1 = 1
206 else: ss1 = max(ss) + 1
208 else: ss1 = max(ss) + 1
207
209
208 if (ss1 > m): ss1 = m
210 if (ss1 > m): ss1 = m
209
211
210 valid = numpy.asarray(range(int(m + bb0 - ss1 + 1))) + ss1
212 valid = numpy.asarray(range(int(m + bb0 - ss1 + 1))) + ss1
211 power = ((spec2[valid] - n0)*fwindow[valid]).sum()
213 power = ((spec2[valid] - n0)*fwindow[valid]).sum()
212 fd = ((spec2[valid]- n0)*freq[valid]*fwindow[valid]).sum()/power
214 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)
215 w = math.sqrt(((spec2[valid] - n0)*fwindow[valid]*(freq[valid]- fd)**2).sum()/power)
214 snr = (spec2.mean()-n0)/n0
216 snr = (spec2.mean()-n0)/n0
215
217
216 if (snr < 1.e-20) :
218 if (snr < 1.e-20) :
217 snr = 1.e-20
219 snr = 1.e-20
218
220
219 vec_power[ind] = power
221 vec_power[ind] = power
220 vec_fd[ind] = fd
222 vec_fd[ind] = fd
221 vec_w[ind] = w
223 vec_w[ind] = w
222 vec_snr[ind] = snr
224 vec_snr[ind] = snr
223
225
224 moments = numpy.vstack((vec_snr, vec_power, vec_fd, vec_w))
226 moments = numpy.vstack((vec_snr, vec_power, vec_fd, vec_w))
225 return moments
227 return moments
226
228
227 #------------------- Get Lags ----------------------------------
229 #------------------- Get Lags ----------------------------------
228
230
229 def GetLags(self):
231 def GetLags(self):
230 '''
232 '''
231 Function GetMoments()
233 Function GetMoments()
232
234
233 Input:
235 Input:
234 self.dataOut.data_pre
236 self.dataOut.data_pre
235 self.dataOut.abscissaRange
237 self.dataOut.abscissaRange
236 self.dataOut.noise
238 self.dataOut.noise
237 self.dataOut.normFactor
239 self.dataOut.normFactor
238 self.dataOut.SNR
240 self.dataOut.SNR
239 self.dataOut.pairsList
241 self.dataOut.pairsList
240 self.dataOut.nChannels
242 self.dataOut.nChannels
241
243
242 Affected:
244 Affected:
243 self.dataOut.data_param
245 self.dataOut.data_param
244
246
245 '''
247 '''
246 data = self.dataOut.data_pre
248 data = self.dataOut.data_pre
247 normFactor = self.dataOut.normFactor
249 normFactor = self.dataOut.normFactor
248 nHeights = self.dataOut.nHeights
250 nHeights = self.dataOut.nHeights
249 absc = self.dataOut.abscissaRange[:-1]
251 absc = self.dataOut.abscissaRange[:-1]
250 noise = self.dataOut.noise
252 noise = self.dataOut.noise
251 SNR = self.dataOut.SNR
253 SNR = self.dataOut.SNR
252 pairsList = self.dataOut.pairsList
254 pairsList = self.dataOut.pairsList
253 nChannels = self.dataOut.nChannels
255 nChannels = self.dataOut.nChannels
254 pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairsList, nChannels)
256 pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairsList, nChannels)
255 self.dataOut.data_param = numpy.zeros((len(pairsCrossCorr)*2 + 1, nHeights))
257 self.dataOut.data_param = numpy.zeros((len(pairsCrossCorr)*2 + 1, nHeights))
256
258
257 dataNorm = numpy.abs(data)
259 dataNorm = numpy.abs(data)
258 for l in range(len(pairsList)):
260 for l in range(len(pairsList)):
259 dataNorm[l,:,:] = dataNorm[l,:,:]/normFactor[l,:]
261 dataNorm[l,:,:] = dataNorm[l,:,:]/normFactor[l,:]
260
262
261 self.dataOut.data_param[:-1,:] = self.__calculateTaus(dataNorm, pairsCrossCorr, pairsAutoCorr, absc)
263 self.dataOut.data_param[:-1,:] = self.__calculateTaus(dataNorm, pairsCrossCorr, pairsAutoCorr, absc)
262 self.dataOut.data_param[-1,:] = self.__calculateLag1Phase(data, pairsAutoCorr, absc)
264 self.dataOut.data_param[-1,:] = self.__calculateLag1Phase(data, pairsAutoCorr, absc)
263 return
265 return
264
266
265 def __getPairsAutoCorr(self, pairsList, nChannels):
267 def __getPairsAutoCorr(self, pairsList, nChannels):
266
268
267 pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan
269 pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan
268
270
269 for l in range(len(pairsList)):
271 for l in range(len(pairsList)):
270 firstChannel = pairsList[l][0]
272 firstChannel = pairsList[l][0]
271 secondChannel = pairsList[l][1]
273 secondChannel = pairsList[l][1]
272
274
273 #Obteniendo pares de Autocorrelacion
275 #Obteniendo pares de Autocorrelacion
274 if firstChannel == secondChannel:
276 if firstChannel == secondChannel:
275 pairsAutoCorr[firstChannel] = int(l)
277 pairsAutoCorr[firstChannel] = int(l)
276
278
277 pairsAutoCorr = pairsAutoCorr.astype(int)
279 pairsAutoCorr = pairsAutoCorr.astype(int)
278
280
279 pairsCrossCorr = range(len(pairsList))
281 pairsCrossCorr = range(len(pairsList))
280 pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr)
282 pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr)
281
283
282 return pairsAutoCorr, pairsCrossCorr
284 return pairsAutoCorr, pairsCrossCorr
283
285
284 def __calculateTaus(self, data, pairsCrossCorr, pairsAutoCorr, lagTRange):
286 def __calculateTaus(self, data, pairsCrossCorr, pairsAutoCorr, lagTRange):
285
287
286 Pt0 = data.shape[1]/2
288 Pt0 = data.shape[1]/2
287 #Funcion de Autocorrelacion
289 #Funcion de Autocorrelacion
288 dataAutoCorr = stats.nanmean(data[pairsAutoCorr,:,:], axis = 0)
290 dataAutoCorr = stats.nanmean(data[pairsAutoCorr,:,:], axis = 0)
289
291
290 #Obtencion Indice de TauCross
292 #Obtencion Indice de TauCross
291 indCross = data[pairsCrossCorr,:,:].argmax(axis = 1)
293 indCross = data[pairsCrossCorr,:,:].argmax(axis = 1)
292 #Obtencion Indice de TauAuto
294 #Obtencion Indice de TauAuto
293 indAuto = numpy.zeros(indCross.shape,dtype = 'int')
295 indAuto = numpy.zeros(indCross.shape,dtype = 'int')
294 CCValue = data[pairsCrossCorr,Pt0,:]
296 CCValue = data[pairsCrossCorr,Pt0,:]
295 for i in range(pairsCrossCorr.size):
297 for i in range(pairsCrossCorr.size):
296 indAuto[i,:] = numpy.abs(dataAutoCorr - CCValue[i,:]).argmin(axis = 0)
298 indAuto[i,:] = numpy.abs(dataAutoCorr - CCValue[i,:]).argmin(axis = 0)
297
299
298 #Obtencion de TauCross y TauAuto
300 #Obtencion de TauCross y TauAuto
299 tauCross = lagTRange[indCross]
301 tauCross = lagTRange[indCross]
300 tauAuto = lagTRange[indAuto]
302 tauAuto = lagTRange[indAuto]
301
303
302 Nan1, Nan2 = numpy.where(tauCross == lagTRange[0])
304 Nan1, Nan2 = numpy.where(tauCross == lagTRange[0])
303
305
304 tauCross[Nan1,Nan2] = numpy.nan
306 tauCross[Nan1,Nan2] = numpy.nan
305 tauAuto[Nan1,Nan2] = numpy.nan
307 tauAuto[Nan1,Nan2] = numpy.nan
306 tau = numpy.vstack((tauCross,tauAuto))
308 tau = numpy.vstack((tauCross,tauAuto))
307
309
308 return tau
310 return tau
309
311
310 def __calculateLag1Phase(self, data, pairs, lagTRange):
312 def __calculateLag1Phase(self, data, pairs, lagTRange):
311 data1 = stats.nanmean(data[pairs,:,:], axis = 0)
313 data1 = stats.nanmean(data[pairs,:,:], axis = 0)
312 lag1 = numpy.where(lagTRange == 0)[0][0] + 1
314 lag1 = numpy.where(lagTRange == 0)[0][0] + 1
313
315
314 phase = numpy.angle(data1[lag1,:])
316 phase = numpy.angle(data1[lag1,:])
315
317
316 return phase
318 return phase
317 #------------------- Detect Meteors ------------------------------
319 #------------------- Detect Meteors ------------------------------
318
320
319 def DetectMeteors(self, hei_ref = None, tauindex = 0,
321 def DetectMeteors(self, hei_ref = None, tauindex = 0,
320 predefinedPhaseShifts = None, centerReceiverIndex = 2,
322 predefinedPhaseShifts = None, centerReceiverIndex = 2,
321 cohDetection = False, cohDet_timeStep = 1, cohDet_thresh = 25,
323 cohDetection = False, cohDet_timeStep = 1, cohDet_thresh = 25,
322 noise_timeStep = 4, noise_multiple = 4,
324 noise_timeStep = 4, noise_multiple = 4,
323 multDet_timeLimit = 1, multDet_rangeLimit = 3,
325 multDet_timeLimit = 1, multDet_rangeLimit = 3,
324 phaseThresh = 20, SNRThresh = 8,
326 phaseThresh = 20, SNRThresh = 8,
325 hmin = 70, hmax=110, azimuth = 0) :
327 hmin = 70, hmax=110, azimuth = 0) :
326
328
327 '''
329 '''
328 Function DetectMeteors()
330 Function DetectMeteors()
329 Project developed with paper:
331 Project developed with paper:
330 HOLDSWORTH ET AL. 2004
332 HOLDSWORTH ET AL. 2004
331
333
332 Input:
334 Input:
333 self.dataOut.data_pre
335 self.dataOut.data_pre
334
336
335 centerReceiverIndex: From the channels, which is the center receiver
337 centerReceiverIndex: From the channels, which is the center receiver
336
338
337 hei_ref: Height reference for the Beacon signal extraction
339 hei_ref: Height reference for the Beacon signal extraction
338 tauindex:
340 tauindex:
339 predefinedPhaseShifts: Predefined phase offset for the voltge signals
341 predefinedPhaseShifts: Predefined phase offset for the voltge signals
340
342
341 cohDetection: Whether to user Coherent detection or not
343 cohDetection: Whether to user Coherent detection or not
342 cohDet_timeStep: Coherent Detection calculation time step
344 cohDet_timeStep: Coherent Detection calculation time step
343 cohDet_thresh: Coherent Detection phase threshold to correct phases
345 cohDet_thresh: Coherent Detection phase threshold to correct phases
344
346
345 noise_timeStep: Noise calculation time step
347 noise_timeStep: Noise calculation time step
346 noise_multiple: Noise multiple to define signal threshold
348 noise_multiple: Noise multiple to define signal threshold
347
349
348 multDet_timeLimit: Multiple Detection Removal time limit in seconds
350 multDet_timeLimit: Multiple Detection Removal time limit in seconds
349 multDet_rangeLimit: Multiple Detection Removal range limit in km
351 multDet_rangeLimit: Multiple Detection Removal range limit in km
350
352
351 phaseThresh: Maximum phase difference between receiver to be consider a meteor
353 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
354 SNRThresh: Minimum SNR threshold of the meteor signal to be consider a meteor
353
355
354 hmin: Minimum Height of the meteor to use it in the further wind estimations
356 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
357 hmax: Maximum Height of the meteor to use it in the further wind estimations
356 azimuth: Azimuth angle correction
358 azimuth: Azimuth angle correction
357
359
358 Affected:
360 Affected:
359 self.dataOut.data_param
361 self.dataOut.data_param
360
362
361 Rejection Criteria (Errors):
363 Rejection Criteria (Errors):
362 0: No error; analysis OK
364 0: No error; analysis OK
363 1: SNR < SNR threshold
365 1: SNR < SNR threshold
364 2: angle of arrival (AOA) ambiguously determined
366 2: angle of arrival (AOA) ambiguously determined
365 3: AOA estimate not feasible
367 3: AOA estimate not feasible
366 4: Large difference in AOAs obtained from different antenna baselines
368 4: Large difference in AOAs obtained from different antenna baselines
367 5: echo at start or end of time series
369 5: echo at start or end of time series
368 6: echo less than 5 examples long; too short for analysis
370 6: echo less than 5 examples long; too short for analysis
369 7: echo rise exceeds 0.3s
371 7: echo rise exceeds 0.3s
370 8: echo decay time less than twice rise time
372 8: echo decay time less than twice rise time
371 9: large power level before echo
373 9: large power level before echo
372 10: large power level after echo
374 10: large power level after echo
373 11: poor fit to amplitude for estimation of decay time
375 11: poor fit to amplitude for estimation of decay time
374 12: poor fit to CCF phase variation for estimation of radial drift velocity
376 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
377 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
378 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
379 15: radial drift velocity or projected horizontal velocity exceeds 200 m/s
378 16: oscilatory echo, indicating event most likely not an underdense echo
380 16: oscilatory echo, indicating event most likely not an underdense echo
379
381
380 17: phase difference in meteor Reestimation
382 17: phase difference in meteor Reestimation
381
383
382 Data Storage:
384 Data Storage:
383 Meteors for Wind Estimation (8):
385 Meteors for Wind Estimation (8):
384 Day Hour | Range Height
386 Day Hour | Range Height
385 Azimuth Zenith errorCosDir
387 Azimuth Zenith errorCosDir
386 VelRad errorVelRad
388 VelRad errorVelRad
387 TypeError
389 TypeError
388
390
389 '''
391 '''
390 #Get Beacon signal
392 #Get Beacon signal
391 newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex])
393 newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex])
392
394
393 if hei_ref != None:
395 if hei_ref != None:
394 newheis = numpy.where(self.dataOut.heightList>hei_ref)
396 newheis = numpy.where(self.dataOut.heightList>hei_ref)
395
397
396 heiRang = self.dataOut.getHeiRange()
398 heiRang = self.dataOut.getHeiRange()
397 #Pairs List
399 #Pairs List
398 pairslist = []
400 pairslist = []
399 nChannel = self.dataOut.nChannels
401 nChannel = self.dataOut.nChannels
400 for i in range(nChannel):
402 for i in range(nChannel):
401 if i != centerReceiverIndex:
403 if i != centerReceiverIndex:
402 pairslist.append((centerReceiverIndex,i))
404 pairslist.append((centerReceiverIndex,i))
403
405
404 #****************REMOVING HARDWARE PHASE DIFFERENCES***************
406 #****************REMOVING HARDWARE PHASE DIFFERENCES***************
405 # see if the user put in pre defined phase shifts
407 # see if the user put in pre defined phase shifts
406 voltsPShift = self.dataOut.data_pre.copy()
408 voltsPShift = self.dataOut.data_pre.copy()
407
409
408 if predefinedPhaseShifts != None:
410 if predefinedPhaseShifts != None:
409 hardwarePhaseShifts = numpy.array(predefinedPhaseShifts)*numpy.pi/180
411 hardwarePhaseShifts = numpy.array(predefinedPhaseShifts)*numpy.pi/180
410 else:
412 else:
411 #get hardware phase shifts using beacon signal
413 #get hardware phase shifts using beacon signal
412 hardwarePhaseShifts = self.__getHardwarePhaseDiff(self.dataOut.data_pre, pairslist, newheis, 10)
414 hardwarePhaseShifts = self.__getHardwarePhaseDiff(self.dataOut.data_pre, pairslist, newheis, 10)
413 hardwarePhaseShifts = numpy.insert(hardwarePhaseShifts,centerReceiverIndex,0)
415 hardwarePhaseShifts = numpy.insert(hardwarePhaseShifts,centerReceiverIndex,0)
414
416
415 voltsPShift = numpy.zeros((self.dataOut.data_pre.shape[0],self.dataOut.data_pre.shape[1],self.dataOut.data_pre.shape[2]), dtype = 'complex')
417 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]):
418 for i in range(self.dataOut.data_pre.shape[0]):
417 voltsPShift[i,:,:] = self.__shiftPhase(self.dataOut.data_pre[i,:,:], hardwarePhaseShifts[i])
419 voltsPShift[i,:,:] = self.__shiftPhase(self.dataOut.data_pre[i,:,:], hardwarePhaseShifts[i])
418 #******************END OF REMOVING HARDWARE PHASE DIFFERENCES*********
420 #******************END OF REMOVING HARDWARE PHASE DIFFERENCES*********
419
421
420 #Remove DC
422 #Remove DC
421 voltsDC = numpy.mean(voltsPShift,1)
423 voltsDC = numpy.mean(voltsPShift,1)
422 voltsDC = numpy.mean(voltsDC,1)
424 voltsDC = numpy.mean(voltsDC,1)
423 for i in range(voltsDC.shape[0]):
425 for i in range(voltsDC.shape[0]):
424 voltsPShift[i] = voltsPShift[i] - voltsDC[i]
426 voltsPShift[i] = voltsPShift[i] - voltsDC[i]
425
427
426 #Don't considerate last heights, theyre used to calculate Hardware Phase Shift
428 #Don't considerate last heights, theyre used to calculate Hardware Phase Shift
427 voltsPShift = voltsPShift[:,:,:newheis[0][0]]
429 voltsPShift = voltsPShift[:,:,:newheis[0][0]]
428
430
429 #************ FIND POWER OF DATA W/COH OR NON COH DETECTION (3.4) **********
431 #************ FIND POWER OF DATA W/COH OR NON COH DETECTION (3.4) **********
430 #Coherent Detection
432 #Coherent Detection
431 if cohDetection:
433 if cohDetection:
432 #use coherent detection to get the net power
434 #use coherent detection to get the net power
433 cohDet_thresh = cohDet_thresh*numpy.pi/180
435 cohDet_thresh = cohDet_thresh*numpy.pi/180
434 voltsPShift = self.__coherentDetection(voltsPShift, cohDet_timeStep, self.dataOut.timeInterval, pairslist, cohDet_thresh)
436 voltsPShift = self.__coherentDetection(voltsPShift, cohDet_timeStep, self.dataOut.timeInterval, pairslist, cohDet_thresh)
435
437
436 #Non-coherent detection!
438 #Non-coherent detection!
437 powerNet = numpy.nansum(numpy.abs(voltsPShift[:,:,:])**2,0)
439 powerNet = numpy.nansum(numpy.abs(voltsPShift[:,:,:])**2,0)
438 #********** END OF COH/NON-COH POWER CALCULATION**********************
440 #********** END OF COH/NON-COH POWER CALCULATION**********************
439
441
440 #********** FIND THE NOISE LEVEL AND POSSIBLE METEORS ****************
442 #********** FIND THE NOISE LEVEL AND POSSIBLE METEORS ****************
441 #Get noise
443 #Get noise
442 noise, noise1 = self.__getNoise(powerNet, noise_timeStep, self.dataOut.timeInterval)
444 noise, noise1 = self.__getNoise(powerNet, noise_timeStep, self.dataOut.timeInterval)
443 # noise = self.getNoise1(powerNet, noise_timeStep, self.dataOut.timeInterval)
445 # noise = self.getNoise1(powerNet, noise_timeStep, self.dataOut.timeInterval)
444 #Get signal threshold
446 #Get signal threshold
445 signalThresh = noise_multiple*noise
447 signalThresh = noise_multiple*noise
446 #Meteor echoes detection
448 #Meteor echoes detection
447 listMeteors = self.__findMeteors(powerNet, signalThresh)
449 listMeteors = self.__findMeteors(powerNet, signalThresh)
448 #******* END OF NOISE LEVEL AND POSSIBLE METEORS CACULATION **********
450 #******* END OF NOISE LEVEL AND POSSIBLE METEORS CACULATION **********
449
451
450 #************** REMOVE MULTIPLE DETECTIONS (3.5) ***************************
452 #************** REMOVE MULTIPLE DETECTIONS (3.5) ***************************
451 #Parameters
453 #Parameters
452 heiRange = self.dataOut.getHeiRange()
454 heiRange = self.dataOut.getHeiRange()
453 rangeInterval = heiRange[1] - heiRange[0]
455 rangeInterval = heiRange[1] - heiRange[0]
454 rangeLimit = multDet_rangeLimit/rangeInterval
456 rangeLimit = multDet_rangeLimit/rangeInterval
455 timeLimit = multDet_timeLimit/self.dataOut.timeInterval
457 timeLimit = multDet_timeLimit/self.dataOut.timeInterval
456 #Multiple detection removals
458 #Multiple detection removals
457 listMeteors1 = self.__removeMultipleDetections(listMeteors, rangeLimit, timeLimit)
459 listMeteors1 = self.__removeMultipleDetections(listMeteors, rangeLimit, timeLimit)
458 #************ END OF REMOVE MULTIPLE DETECTIONS **********************
460 #************ END OF REMOVE MULTIPLE DETECTIONS **********************
459
461
460 #********************* METEOR REESTIMATION (3.7, 3.8, 3.9, 3.10) ********************
462 #********************* METEOR REESTIMATION (3.7, 3.8, 3.9, 3.10) ********************
461 #Parameters
463 #Parameters
462 phaseThresh = phaseThresh*numpy.pi/180
464 phaseThresh = phaseThresh*numpy.pi/180
463 thresh = [phaseThresh, noise_multiple, SNRThresh]
465 thresh = [phaseThresh, noise_multiple, SNRThresh]
464 #Meteor reestimation (Errors N 1, 6, 12, 17)
466 #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)
467 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)
468 # listMeteors2, listMeteorsPower, listMeteorsVolts = self.meteorReestimation3(listMeteors2, listMeteorsPower, listMeteorsVolts, voltsPShift, pairslist, thresh, noise)
467 #Estimation of decay times (Errors N 7, 8, 11)
469 #Estimation of decay times (Errors N 7, 8, 11)
468 listMeteors3 = self.__estimateDecayTime(listMeteors2, listMeteorsPower, self.dataOut.timeInterval, self.dataOut.frequency)
470 listMeteors3 = self.__estimateDecayTime(listMeteors2, listMeteorsPower, self.dataOut.timeInterval, self.dataOut.frequency)
469 #******************* END OF METEOR REESTIMATION *******************
471 #******************* END OF METEOR REESTIMATION *******************
470
472
471 #********************* METEOR PARAMETERS CALCULATION (3.11, 3.12, 3.13) **************************
473 #********************* METEOR PARAMETERS CALCULATION (3.11, 3.12, 3.13) **************************
472 #Calculating Radial Velocity (Error N 15)
474 #Calculating Radial Velocity (Error N 15)
473 radialStdThresh = 10
475 radialStdThresh = 10
474 listMeteors4 = self.__getRadialVelocity(listMeteors3, listMeteorsVolts, radialStdThresh, pairslist, self.dataOut.timeInterval)
476 listMeteors4 = self.__getRadialVelocity(listMeteors3, listMeteorsVolts, radialStdThresh, pairslist, self.dataOut.timeInterval)
475
477
476 if len(listMeteors4) > 0:
478 if len(listMeteors4) > 0:
477 #Setting New Array
479 #Setting New Array
478 date = repr(self.dataOut.datatime)
480 date = repr(self.dataOut.datatime)
479 arrayMeteors4, arrayParameters = self.__setNewArrays(listMeteors4, date, heiRang)
481 arrayMeteors4, arrayParameters = self.__setNewArrays(listMeteors4, date, heiRang)
480
482
481 #Calculate AOA (Error N 3, 4)
483 #Calculate AOA (Error N 3, 4)
482 #JONES ET AL. 1998
484 #JONES ET AL. 1998
483 AOAthresh = numpy.pi/8
485 AOAthresh = numpy.pi/8
484 error = arrayParameters[:,-1]
486 error = arrayParameters[:,-1]
485 phases = -arrayMeteors4[:,9:13]
487 phases = -arrayMeteors4[:,9:13]
486 pairsList = []
488 pairsList = []
487 pairsList.append((0,3))
489 pairsList.append((0,3))
488 pairsList.append((1,2))
490 pairsList.append((1,2))
489 arrayParameters[:,4:7], arrayParameters[:,-1] = self.__getAOA(phases, pairsList, error, AOAthresh, azimuth)
491 arrayParameters[:,4:7], arrayParameters[:,-1] = self.__getAOA(phases, pairsList, error, AOAthresh, azimuth)
490
492
491 #Calculate Heights (Error N 13 and 14)
493 #Calculate Heights (Error N 13 and 14)
492 error = arrayParameters[:,-1]
494 error = arrayParameters[:,-1]
493 Ranges = arrayParameters[:,2]
495 Ranges = arrayParameters[:,2]
494 zenith = arrayParameters[:,5]
496 zenith = arrayParameters[:,5]
495 arrayParameters[:,3], arrayParameters[:,-1] = self.__getHeights(Ranges, zenith, error, hmin, hmax)
497 arrayParameters[:,3], arrayParameters[:,-1] = self.__getHeights(Ranges, zenith, error, hmin, hmax)
496 #********************* END OF PARAMETERS CALCULATION **************************
498 #********************* END OF PARAMETERS CALCULATION **************************
497
499
498 #***************************+ SAVE DATA IN HDF5 FORMAT **********************
500 #***************************+ SAVE DATA IN HDF5 FORMAT **********************
499 self.dataOut.data_param = arrayParameters
501 self.dataOut.data_param = arrayParameters
500
502
501 return
503 return
502
504
503 def __getHardwarePhaseDiff(self, voltage0, pairslist, newheis, n):
505 def __getHardwarePhaseDiff(self, voltage0, pairslist, newheis, n):
504
506
505 minIndex = min(newheis[0])
507 minIndex = min(newheis[0])
506 maxIndex = max(newheis[0])
508 maxIndex = max(newheis[0])
507
509
508 voltage = voltage0[:,:,minIndex:maxIndex+1]
510 voltage = voltage0[:,:,minIndex:maxIndex+1]
509 nLength = voltage.shape[1]/n
511 nLength = voltage.shape[1]/n
510 nMin = 0
512 nMin = 0
511 nMax = 0
513 nMax = 0
512 phaseOffset = numpy.zeros((len(pairslist),n))
514 phaseOffset = numpy.zeros((len(pairslist),n))
513
515
514 for i in range(n):
516 for i in range(n):
515 nMax += nLength
517 nMax += nLength
516 phaseCCF = -numpy.angle(self.__calculateCCF(voltage[:,nMin:nMax,:], pairslist, [0]))
518 phaseCCF = -numpy.angle(self.__calculateCCF(voltage[:,nMin:nMax,:], pairslist, [0]))
517 phaseCCF = numpy.mean(phaseCCF, axis = 2)
519 phaseCCF = numpy.mean(phaseCCF, axis = 2)
518 phaseOffset[:,i] = phaseCCF.transpose()
520 phaseOffset[:,i] = phaseCCF.transpose()
519 nMin = nMax
521 nMin = nMax
520 # phaseDiff, phaseArrival = self.estimatePhaseDifference(voltage, pairslist)
522 # phaseDiff, phaseArrival = self.estimatePhaseDifference(voltage, pairslist)
521
523
522 #Remove Outliers
524 #Remove Outliers
523 factor = 2
525 factor = 2
524 wt = phaseOffset - signal.medfilt(phaseOffset,(1,5))
526 wt = phaseOffset - signal.medfilt(phaseOffset,(1,5))
525 dw = numpy.std(wt,axis = 1)
527 dw = numpy.std(wt,axis = 1)
526 dw = dw.reshape((dw.size,1))
528 dw = dw.reshape((dw.size,1))
527 ind = numpy.where(numpy.logical_or(wt>dw*factor,wt<-dw*factor))
529 ind = numpy.where(numpy.logical_or(wt>dw*factor,wt<-dw*factor))
528 phaseOffset[ind] = numpy.nan
530 phaseOffset[ind] = numpy.nan
529 phaseOffset = stats.nanmean(phaseOffset, axis=1)
531 phaseOffset = stats.nanmean(phaseOffset, axis=1)
530
532
531 return phaseOffset
533 return phaseOffset
532
534
533 def __shiftPhase(self, data, phaseShift):
535 def __shiftPhase(self, data, phaseShift):
534 #this will shift the phase of a complex number
536 #this will shift the phase of a complex number
535 dataShifted = numpy.abs(data) * numpy.exp((numpy.angle(data)+phaseShift)*1j)
537 dataShifted = numpy.abs(data) * numpy.exp((numpy.angle(data)+phaseShift)*1j)
536 return dataShifted
538 return dataShifted
537
539
538 def __estimatePhaseDifference(self, array, pairslist):
540 def __estimatePhaseDifference(self, array, pairslist):
539 nChannel = array.shape[0]
541 nChannel = array.shape[0]
540 nHeights = array.shape[2]
542 nHeights = array.shape[2]
541 numPairs = len(pairslist)
543 numPairs = len(pairslist)
542 # phaseCCF = numpy.zeros((nChannel, 5, nHeights))
544 # phaseCCF = numpy.zeros((nChannel, 5, nHeights))
543 phaseCCF = numpy.angle(self.__calculateCCF(array, pairslist, [-2,-1,0,1,2]))
545 phaseCCF = numpy.angle(self.__calculateCCF(array, pairslist, [-2,-1,0,1,2]))
544
546
545 #Correct phases
547 #Correct phases
546 derPhaseCCF = phaseCCF[:,1:,:] - phaseCCF[:,0:-1,:]
548 derPhaseCCF = phaseCCF[:,1:,:] - phaseCCF[:,0:-1,:]
547 indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi)
549 indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi)
548
550
549 if indDer[0].shape[0] > 0:
551 if indDer[0].shape[0] > 0:
550 for i in range(indDer[0].shape[0]):
552 for i in range(indDer[0].shape[0]):
551 signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i],indDer[2][i]])
553 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
554 phaseCCF[indDer[0][i],indDer[1][i]+1:,:] += signo*2*numpy.pi
553
555
554 # for j in range(numSides):
556 # for j in range(numSides):
555 # phaseCCFAux = self.calculateCCF(arrayCenter, arraySides[j,:,:], [-2,1,0,1,2])
557 # phaseCCFAux = self.calculateCCF(arrayCenter, arraySides[j,:,:], [-2,1,0,1,2])
556 # phaseCCF[j,:,:] = numpy.angle(phaseCCFAux)
558 # phaseCCF[j,:,:] = numpy.angle(phaseCCFAux)
557 #
559 #
558 #Linear
560 #Linear
559 phaseInt = numpy.zeros((numPairs,1))
561 phaseInt = numpy.zeros((numPairs,1))
560 angAllCCF = phaseCCF[:,[0,1,3,4],0]
562 angAllCCF = phaseCCF[:,[0,1,3,4],0]
561 for j in range(numPairs):
563 for j in range(numPairs):
562 fit = stats.linregress([-2,-1,1,2],angAllCCF[j,:])
564 fit = stats.linregress([-2,-1,1,2],angAllCCF[j,:])
563 phaseInt[j] = fit[1]
565 phaseInt[j] = fit[1]
564 #Phase Differences
566 #Phase Differences
565 phaseDiff = phaseInt - phaseCCF[:,2,:]
567 phaseDiff = phaseInt - phaseCCF[:,2,:]
566 phaseArrival = phaseInt.reshape(phaseInt.size)
568 phaseArrival = phaseInt.reshape(phaseInt.size)
567
569
568 #Dealias
570 #Dealias
569 indAlias = numpy.where(phaseArrival > numpy.pi)
571 indAlias = numpy.where(phaseArrival > numpy.pi)
570 phaseArrival[indAlias] -= 2*numpy.pi
572 phaseArrival[indAlias] -= 2*numpy.pi
571 indAlias = numpy.where(phaseArrival < -numpy.pi)
573 indAlias = numpy.where(phaseArrival < -numpy.pi)
572 phaseArrival[indAlias] += 2*numpy.pi
574 phaseArrival[indAlias] += 2*numpy.pi
573
575
574 return phaseDiff, phaseArrival
576 return phaseDiff, phaseArrival
575
577
576 def __coherentDetection(self, volts, timeSegment, timeInterval, pairslist, thresh):
578 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
579 #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
580 #find the phase shifts of each channel over 1 second intervals
579 #only look at ranges below the beacon signal
581 #only look at ranges below the beacon signal
580 numProfPerBlock = numpy.ceil(timeSegment/timeInterval)
582 numProfPerBlock = numpy.ceil(timeSegment/timeInterval)
581 numBlocks = int(volts.shape[1]/numProfPerBlock)
583 numBlocks = int(volts.shape[1]/numProfPerBlock)
582 numHeights = volts.shape[2]
584 numHeights = volts.shape[2]
583 nChannel = volts.shape[0]
585 nChannel = volts.shape[0]
584 voltsCohDet = volts.copy()
586 voltsCohDet = volts.copy()
585
587
586 pairsarray = numpy.array(pairslist)
588 pairsarray = numpy.array(pairslist)
587 indSides = pairsarray[:,1]
589 indSides = pairsarray[:,1]
588 # indSides = numpy.array(range(nChannel))
590 # indSides = numpy.array(range(nChannel))
589 # indSides = numpy.delete(indSides, indCenter)
591 # indSides = numpy.delete(indSides, indCenter)
590 #
592 #
591 # listCenter = numpy.array_split(volts[indCenter,:,:], numBlocks, 0)
593 # listCenter = numpy.array_split(volts[indCenter,:,:], numBlocks, 0)
592 listBlocks = numpy.array_split(volts, numBlocks, 1)
594 listBlocks = numpy.array_split(volts, numBlocks, 1)
593
595
594 startInd = 0
596 startInd = 0
595 endInd = 0
597 endInd = 0
596
598
597 for i in range(numBlocks):
599 for i in range(numBlocks):
598 startInd = endInd
600 startInd = endInd
599 endInd = endInd + listBlocks[i].shape[1]
601 endInd = endInd + listBlocks[i].shape[1]
600
602
601 arrayBlock = listBlocks[i]
603 arrayBlock = listBlocks[i]
602 # arrayBlockCenter = listCenter[i]
604 # arrayBlockCenter = listCenter[i]
603
605
604 #Estimate the Phase Difference
606 #Estimate the Phase Difference
605 phaseDiff, aux = self.__estimatePhaseDifference(arrayBlock, pairslist)
607 phaseDiff, aux = self.__estimatePhaseDifference(arrayBlock, pairslist)
606 #Phase Difference RMS
608 #Phase Difference RMS
607 arrayPhaseRMS = numpy.abs(phaseDiff)
609 arrayPhaseRMS = numpy.abs(phaseDiff)
608 phaseRMSaux = numpy.sum(arrayPhaseRMS < thresh,0)
610 phaseRMSaux = numpy.sum(arrayPhaseRMS < thresh,0)
609 indPhase = numpy.where(phaseRMSaux==4)
611 indPhase = numpy.where(phaseRMSaux==4)
610 #Shifting
612 #Shifting
611 if indPhase[0].shape[0] > 0:
613 if indPhase[0].shape[0] > 0:
612 for j in range(indSides.size):
614 for j in range(indSides.size):
613 arrayBlock[indSides[j],:,indPhase] = self.__shiftPhase(arrayBlock[indSides[j],:,indPhase], phaseDiff[j,indPhase].transpose())
615 arrayBlock[indSides[j],:,indPhase] = self.__shiftPhase(arrayBlock[indSides[j],:,indPhase], phaseDiff[j,indPhase].transpose())
614 voltsCohDet[:,startInd:endInd,:] = arrayBlock
616 voltsCohDet[:,startInd:endInd,:] = arrayBlock
615
617
616 return voltsCohDet
618 return voltsCohDet
617
619
618 def __calculateCCF(self, volts, pairslist ,laglist):
620 def __calculateCCF(self, volts, pairslist ,laglist):
619
621
620 nHeights = volts.shape[2]
622 nHeights = volts.shape[2]
621 nPoints = volts.shape[1]
623 nPoints = volts.shape[1]
622 voltsCCF = numpy.zeros((len(pairslist), len(laglist), nHeights),dtype = 'complex')
624 voltsCCF = numpy.zeros((len(pairslist), len(laglist), nHeights),dtype = 'complex')
623
625
624 for i in range(len(pairslist)):
626 for i in range(len(pairslist)):
625 volts1 = volts[pairslist[i][0]]
627 volts1 = volts[pairslist[i][0]]
626 volts2 = volts[pairslist[i][1]]
628 volts2 = volts[pairslist[i][1]]
627
629
628 for t in range(len(laglist)):
630 for t in range(len(laglist)):
629 idxT = laglist[t]
631 idxT = laglist[t]
630 if idxT >= 0:
632 if idxT >= 0:
631 vStacked = numpy.vstack((volts2[idxT:,:],
633 vStacked = numpy.vstack((volts2[idxT:,:],
632 numpy.zeros((idxT, nHeights),dtype='complex')))
634 numpy.zeros((idxT, nHeights),dtype='complex')))
633 else:
635 else:
634 vStacked = numpy.vstack((numpy.zeros((-idxT, nHeights),dtype='complex'),
636 vStacked = numpy.vstack((numpy.zeros((-idxT, nHeights),dtype='complex'),
635 volts2[:(nPoints + idxT),:]))
637 volts2[:(nPoints + idxT),:]))
636 voltsCCF[i,t,:] = numpy.sum((numpy.conjugate(volts1)*vStacked),axis=0)
638 voltsCCF[i,t,:] = numpy.sum((numpy.conjugate(volts1)*vStacked),axis=0)
637
639
638 vStacked = None
640 vStacked = None
639 return voltsCCF
641 return voltsCCF
640
642
641 def __getNoise(self, power, timeSegment, timeInterval):
643 def __getNoise(self, power, timeSegment, timeInterval):
642 numProfPerBlock = numpy.ceil(timeSegment/timeInterval)
644 numProfPerBlock = numpy.ceil(timeSegment/timeInterval)
643 numBlocks = int(power.shape[0]/numProfPerBlock)
645 numBlocks = int(power.shape[0]/numProfPerBlock)
644 numHeights = power.shape[1]
646 numHeights = power.shape[1]
645
647
646 listPower = numpy.array_split(power, numBlocks, 0)
648 listPower = numpy.array_split(power, numBlocks, 0)
647 noise = numpy.zeros((power.shape[0], power.shape[1]))
649 noise = numpy.zeros((power.shape[0], power.shape[1]))
648 noise1 = numpy.zeros((power.shape[0], power.shape[1]))
650 noise1 = numpy.zeros((power.shape[0], power.shape[1]))
649
651
650 startInd = 0
652 startInd = 0
651 endInd = 0
653 endInd = 0
652
654
653 for i in range(numBlocks): #split por canal
655 for i in range(numBlocks): #split por canal
654 startInd = endInd
656 startInd = endInd
655 endInd = endInd + listPower[i].shape[0]
657 endInd = endInd + listPower[i].shape[0]
656
658
657 arrayBlock = listPower[i]
659 arrayBlock = listPower[i]
658 noiseAux = numpy.mean(arrayBlock, 0)
660 noiseAux = numpy.mean(arrayBlock, 0)
659 # noiseAux = numpy.median(noiseAux)
661 # noiseAux = numpy.median(noiseAux)
660 # noiseAux = numpy.mean(arrayBlock)
662 # noiseAux = numpy.mean(arrayBlock)
661 noise[startInd:endInd,:] = noise[startInd:endInd,:] + noiseAux
663 noise[startInd:endInd,:] = noise[startInd:endInd,:] + noiseAux
662
664
663 noiseAux1 = numpy.mean(arrayBlock)
665 noiseAux1 = numpy.mean(arrayBlock)
664 noise1[startInd:endInd,:] = noise1[startInd:endInd,:] + noiseAux1
666 noise1[startInd:endInd,:] = noise1[startInd:endInd,:] + noiseAux1
665
667
666 return noise, noise1
668 return noise, noise1
667
669
668 def __findMeteors(self, power, thresh):
670 def __findMeteors(self, power, thresh):
669 nProf = power.shape[0]
671 nProf = power.shape[0]
670 nHeights = power.shape[1]
672 nHeights = power.shape[1]
671 listMeteors = []
673 listMeteors = []
672
674
673 for i in range(nHeights):
675 for i in range(nHeights):
674 powerAux = power[:,i]
676 powerAux = power[:,i]
675 threshAux = thresh[:,i]
677 threshAux = thresh[:,i]
676
678
677 indUPthresh = numpy.where(powerAux > threshAux)[0]
679 indUPthresh = numpy.where(powerAux > threshAux)[0]
678 indDNthresh = numpy.where(powerAux <= threshAux)[0]
680 indDNthresh = numpy.where(powerAux <= threshAux)[0]
679
681
680 j = 0
682 j = 0
681
683
682 while (j < indUPthresh.size - 2):
684 while (j < indUPthresh.size - 2):
683 if (indUPthresh[j + 2] == indUPthresh[j] + 2):
685 if (indUPthresh[j + 2] == indUPthresh[j] + 2):
684 indDNAux = numpy.where(indDNthresh > indUPthresh[j])
686 indDNAux = numpy.where(indDNthresh > indUPthresh[j])
685 indDNthresh = indDNthresh[indDNAux]
687 indDNthresh = indDNthresh[indDNAux]
686
688
687 if (indDNthresh.size > 0):
689 if (indDNthresh.size > 0):
688 indEnd = indDNthresh[0] - 1
690 indEnd = indDNthresh[0] - 1
689 indInit = indUPthresh[j]
691 indInit = indUPthresh[j]
690
692
691 meteor = powerAux[indInit:indEnd + 1]
693 meteor = powerAux[indInit:indEnd + 1]
692 indPeak = meteor.argmax() + indInit
694 indPeak = meteor.argmax() + indInit
693 FLA = sum(numpy.conj(meteor)*numpy.hstack((meteor[1:],0)))
695 FLA = sum(numpy.conj(meteor)*numpy.hstack((meteor[1:],0)))
694
696
695 listMeteors.append(numpy.array([i,indInit,indPeak,indEnd,FLA])) #CHEQUEAR!!!!!
697 listMeteors.append(numpy.array([i,indInit,indPeak,indEnd,FLA])) #CHEQUEAR!!!!!
696 j = numpy.where(indUPthresh == indEnd)[0] + 1
698 j = numpy.where(indUPthresh == indEnd)[0] + 1
697 else: j+=1
699 else: j+=1
698 else: j+=1
700 else: j+=1
699
701
700 return listMeteors
702 return listMeteors
701
703
702 def __removeMultipleDetections(self,listMeteors, rangeLimit, timeLimit):
704 def __removeMultipleDetections(self,listMeteors, rangeLimit, timeLimit):
703
705
704 arrayMeteors = numpy.asarray(listMeteors)
706 arrayMeteors = numpy.asarray(listMeteors)
705 listMeteors1 = []
707 listMeteors1 = []
706
708
707 while arrayMeteors.shape[0] > 0:
709 while arrayMeteors.shape[0] > 0:
708 FLAs = arrayMeteors[:,4]
710 FLAs = arrayMeteors[:,4]
709 maxFLA = FLAs.argmax()
711 maxFLA = FLAs.argmax()
710 listMeteors1.append(arrayMeteors[maxFLA,:])
712 listMeteors1.append(arrayMeteors[maxFLA,:])
711
713
712 MeteorInitTime = arrayMeteors[maxFLA,1]
714 MeteorInitTime = arrayMeteors[maxFLA,1]
713 MeteorEndTime = arrayMeteors[maxFLA,3]
715 MeteorEndTime = arrayMeteors[maxFLA,3]
714 MeteorHeight = arrayMeteors[maxFLA,0]
716 MeteorHeight = arrayMeteors[maxFLA,0]
715
717
716 #Check neighborhood
718 #Check neighborhood
717 maxHeightIndex = MeteorHeight + rangeLimit
719 maxHeightIndex = MeteorHeight + rangeLimit
718 minHeightIndex = MeteorHeight - rangeLimit
720 minHeightIndex = MeteorHeight - rangeLimit
719 minTimeIndex = MeteorInitTime - timeLimit
721 minTimeIndex = MeteorInitTime - timeLimit
720 maxTimeIndex = MeteorEndTime + timeLimit
722 maxTimeIndex = MeteorEndTime + timeLimit
721
723
722 #Check Heights
724 #Check Heights
723 indHeight = numpy.logical_and(arrayMeteors[:,0] >= minHeightIndex, arrayMeteors[:,0] <= maxHeightIndex)
725 indHeight = numpy.logical_and(arrayMeteors[:,0] >= minHeightIndex, arrayMeteors[:,0] <= maxHeightIndex)
724 indTime = numpy.logical_and(arrayMeteors[:,3] >= minTimeIndex, arrayMeteors[:,1] <= maxTimeIndex)
726 indTime = numpy.logical_and(arrayMeteors[:,3] >= minTimeIndex, arrayMeteors[:,1] <= maxTimeIndex)
725 indBoth = numpy.where(numpy.logical_and(indTime,indHeight))
727 indBoth = numpy.where(numpy.logical_and(indTime,indHeight))
726
728
727 arrayMeteors = numpy.delete(arrayMeteors, indBoth, axis = 0)
729 arrayMeteors = numpy.delete(arrayMeteors, indBoth, axis = 0)
728
730
729 return listMeteors1
731 return listMeteors1
730
732
731 def __meteorReestimation(self, listMeteors, volts, pairslist, thresh, noise, timeInterval,frequency):
733 def __meteorReestimation(self, listMeteors, volts, pairslist, thresh, noise, timeInterval,frequency):
732 numHeights = volts.shape[2]
734 numHeights = volts.shape[2]
733 nChannel = volts.shape[0]
735 nChannel = volts.shape[0]
734
736
735 thresholdPhase = thresh[0]
737 thresholdPhase = thresh[0]
736 thresholdNoise = thresh[1]
738 thresholdNoise = thresh[1]
737 thresholdDB = float(thresh[2])
739 thresholdDB = float(thresh[2])
738
740
739 thresholdDB1 = 10**(thresholdDB/10)
741 thresholdDB1 = 10**(thresholdDB/10)
740 pairsarray = numpy.array(pairslist)
742 pairsarray = numpy.array(pairslist)
741 indSides = pairsarray[:,1]
743 indSides = pairsarray[:,1]
742
744
743 pairslist1 = list(pairslist)
745 pairslist1 = list(pairslist)
744 pairslist1.append((0,1))
746 pairslist1.append((0,1))
745 pairslist1.append((3,4))
747 pairslist1.append((3,4))
746
748
747 listMeteors1 = []
749 listMeteors1 = []
748 listPowerSeries = []
750 listPowerSeries = []
749 listVoltageSeries = []
751 listVoltageSeries = []
750 #volts has the war data
752 #volts has the war data
751
753
752 if frequency == 30e6:
754 if frequency == 30e6:
753 timeLag = 45*10**-3
755 timeLag = 45*10**-3
754 else:
756 else:
755 timeLag = 15*10**-3
757 timeLag = 15*10**-3
756 lag = numpy.ceil(timeLag/timeInterval)
758 lag = numpy.ceil(timeLag/timeInterval)
757
759
758 for i in range(len(listMeteors)):
760 for i in range(len(listMeteors)):
759
761
760 ###################### 3.6 - 3.7 PARAMETERS REESTIMATION #########################
762 ###################### 3.6 - 3.7 PARAMETERS REESTIMATION #########################
761 meteorAux = numpy.zeros(16)
763 meteorAux = numpy.zeros(16)
762
764
763 #Loading meteor Data (mHeight, mStart, mPeak, mEnd)
765 #Loading meteor Data (mHeight, mStart, mPeak, mEnd)
764 mHeight = listMeteors[i][0]
766 mHeight = listMeteors[i][0]
765 mStart = listMeteors[i][1]
767 mStart = listMeteors[i][1]
766 mPeak = listMeteors[i][2]
768 mPeak = listMeteors[i][2]
767 mEnd = listMeteors[i][3]
769 mEnd = listMeteors[i][3]
768
770
769 #get the volt data between the start and end times of the meteor
771 #get the volt data between the start and end times of the meteor
770 meteorVolts = volts[:,mStart:mEnd+1,mHeight]
772 meteorVolts = volts[:,mStart:mEnd+1,mHeight]
771 meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1)
773 meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1)
772
774
773 #3.6. Phase Difference estimation
775 #3.6. Phase Difference estimation
774 phaseDiff, aux = self.__estimatePhaseDifference(meteorVolts, pairslist)
776 phaseDiff, aux = self.__estimatePhaseDifference(meteorVolts, pairslist)
775
777
776 #3.7. Phase difference removal & meteor start, peak and end times reestimated
778 #3.7. Phase difference removal & meteor start, peak and end times reestimated
777 #meteorVolts0.- all Channels, all Profiles
779 #meteorVolts0.- all Channels, all Profiles
778 meteorVolts0 = volts[:,:,mHeight]
780 meteorVolts0 = volts[:,:,mHeight]
779 meteorThresh = noise[:,mHeight]*thresholdNoise
781 meteorThresh = noise[:,mHeight]*thresholdNoise
780 meteorNoise = noise[:,mHeight]
782 meteorNoise = noise[:,mHeight]
781 meteorVolts0[indSides,:] = self.__shiftPhase(meteorVolts0[indSides,:], phaseDiff) #Phase Shifting
783 meteorVolts0[indSides,:] = self.__shiftPhase(meteorVolts0[indSides,:], phaseDiff) #Phase Shifting
782 powerNet0 = numpy.nansum(numpy.abs(meteorVolts0)**2, axis = 0) #Power
784 powerNet0 = numpy.nansum(numpy.abs(meteorVolts0)**2, axis = 0) #Power
783
785
784 #Times reestimation
786 #Times reestimation
785 mStart1 = numpy.where(powerNet0[:mPeak] < meteorThresh[:mPeak])[0]
787 mStart1 = numpy.where(powerNet0[:mPeak] < meteorThresh[:mPeak])[0]
786 if mStart1.size > 0:
788 if mStart1.size > 0:
787 mStart1 = mStart1[-1] + 1
789 mStart1 = mStart1[-1] + 1
788
790
789 else:
791 else:
790 mStart1 = mPeak
792 mStart1 = mPeak
791
793
792 mEnd1 = numpy.where(powerNet0[mPeak:] < meteorThresh[mPeak:])[0][0] + mPeak - 1
794 mEnd1 = numpy.where(powerNet0[mPeak:] < meteorThresh[mPeak:])[0][0] + mPeak - 1
793 mEndDecayTime1 = numpy.where(powerNet0[mPeak:] < meteorNoise[mPeak:])[0]
795 mEndDecayTime1 = numpy.where(powerNet0[mPeak:] < meteorNoise[mPeak:])[0]
794 if mEndDecayTime1.size == 0:
796 if mEndDecayTime1.size == 0:
795 mEndDecayTime1 = powerNet0.size
797 mEndDecayTime1 = powerNet0.size
796 else:
798 else:
797 mEndDecayTime1 = mEndDecayTime1[0] + mPeak - 1
799 mEndDecayTime1 = mEndDecayTime1[0] + mPeak - 1
798 # mPeak1 = meteorVolts0[mStart1:mEnd1 + 1].argmax()
800 # mPeak1 = meteorVolts0[mStart1:mEnd1 + 1].argmax()
799
801
800 #meteorVolts1.- all Channels, from start to end
802 #meteorVolts1.- all Channels, from start to end
801 meteorVolts1 = meteorVolts0[:,mStart1:mEnd1 + 1]
803 meteorVolts1 = meteorVolts0[:,mStart1:mEnd1 + 1]
802 meteorVolts2 = meteorVolts0[:,mPeak + lag:mEnd1 + 1]
804 meteorVolts2 = meteorVolts0[:,mPeak + lag:mEnd1 + 1]
803 if meteorVolts2.shape[1] == 0:
805 if meteorVolts2.shape[1] == 0:
804 meteorVolts2 = meteorVolts0[:,mPeak:mEnd1 + 1]
806 meteorVolts2 = meteorVolts0[:,mPeak:mEnd1 + 1]
805 meteorVolts1 = meteorVolts1.reshape(meteorVolts1.shape[0], meteorVolts1.shape[1], 1)
807 meteorVolts1 = meteorVolts1.reshape(meteorVolts1.shape[0], meteorVolts1.shape[1], 1)
806 meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1], 1)
808 meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1], 1)
807 ##################### END PARAMETERS REESTIMATION #########################
809 ##################### END PARAMETERS REESTIMATION #########################
808
810
809 ##################### 3.8 PHASE DIFFERENCE REESTIMATION ########################
811 ##################### 3.8 PHASE DIFFERENCE REESTIMATION ########################
810 # if mEnd1 - mStart1 > 4: #Error Number 6: echo less than 5 samples long; too short for analysis
812 # if mEnd1 - mStart1 > 4: #Error Number 6: echo less than 5 samples long; too short for analysis
811 if meteorVolts2.shape[1] > 0:
813 if meteorVolts2.shape[1] > 0:
812 #Phase Difference re-estimation
814 #Phase Difference re-estimation
813 phaseDiff1, phaseDiffint = self.__estimatePhaseDifference(meteorVolts2, pairslist1) #Phase Difference Estimation
815 phaseDiff1, phaseDiffint = self.__estimatePhaseDifference(meteorVolts2, pairslist1) #Phase Difference Estimation
814 # phaseDiff1, phaseDiffint = self.estimatePhaseDifference(meteorVolts2, pairslist)
816 # phaseDiff1, phaseDiffint = self.estimatePhaseDifference(meteorVolts2, pairslist)
815 meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1])
817 meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1])
816 phaseDiff11 = numpy.reshape(phaseDiff1, (phaseDiff1.shape[0],1))
818 phaseDiff11 = numpy.reshape(phaseDiff1, (phaseDiff1.shape[0],1))
817 meteorVolts2[indSides,:] = self.__shiftPhase(meteorVolts2[indSides,:], phaseDiff11[0:4]) #Phase Shifting
819 meteorVolts2[indSides,:] = self.__shiftPhase(meteorVolts2[indSides,:], phaseDiff11[0:4]) #Phase Shifting
818
820
819 #Phase Difference RMS
821 #Phase Difference RMS
820 phaseRMS1 = numpy.sqrt(numpy.mean(numpy.square(phaseDiff1)))
822 phaseRMS1 = numpy.sqrt(numpy.mean(numpy.square(phaseDiff1)))
821 powerNet1 = numpy.nansum(numpy.abs(meteorVolts1[:,:])**2,0)
823 powerNet1 = numpy.nansum(numpy.abs(meteorVolts1[:,:])**2,0)
822 #Data from Meteor
824 #Data from Meteor
823 mPeak1 = powerNet1.argmax() + mStart1
825 mPeak1 = powerNet1.argmax() + mStart1
824 mPeakPower1 = powerNet1.max()
826 mPeakPower1 = powerNet1.max()
825 noiseAux = sum(noise[mStart1:mEnd1 + 1,mHeight])
827 noiseAux = sum(noise[mStart1:mEnd1 + 1,mHeight])
826 mSNR1 = (sum(powerNet1)-noiseAux)/noiseAux
828 mSNR1 = (sum(powerNet1)-noiseAux)/noiseAux
827 Meteor1 = numpy.array([mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1])
829 Meteor1 = numpy.array([mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1])
828 Meteor1 = numpy.hstack((Meteor1,phaseDiffint))
830 Meteor1 = numpy.hstack((Meteor1,phaseDiffint))
829 PowerSeries = powerNet0[mStart1:mEndDecayTime1 + 1]
831 PowerSeries = powerNet0[mStart1:mEndDecayTime1 + 1]
830 #Vectorize
832 #Vectorize
831 meteorAux[0:7] = [mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1]
833 meteorAux[0:7] = [mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1]
832 meteorAux[7:11] = phaseDiffint[0:4]
834 meteorAux[7:11] = phaseDiffint[0:4]
833
835
834 #Rejection Criterions
836 #Rejection Criterions
835 if phaseRMS1 > thresholdPhase: #Error Number 17: Phase variation
837 if phaseRMS1 > thresholdPhase: #Error Number 17: Phase variation
836 meteorAux[-1] = 17
838 meteorAux[-1] = 17
837 elif mSNR1 < thresholdDB1: #Error Number 1: SNR < threshold dB
839 elif mSNR1 < thresholdDB1: #Error Number 1: SNR < threshold dB
838 meteorAux[-1] = 1
840 meteorAux[-1] = 1
839
841
840
842
841 else:
843 else:
842 meteorAux[0:4] = [mHeight, mStart, mPeak, mEnd]
844 meteorAux[0:4] = [mHeight, mStart, mPeak, mEnd]
843 meteorAux[-1] = 6 #Error Number 6: echo less than 5 samples long; too short for analysis
845 meteorAux[-1] = 6 #Error Number 6: echo less than 5 samples long; too short for analysis
844 PowerSeries = 0
846 PowerSeries = 0
845
847
846 listMeteors1.append(meteorAux)
848 listMeteors1.append(meteorAux)
847 listPowerSeries.append(PowerSeries)
849 listPowerSeries.append(PowerSeries)
848 listVoltageSeries.append(meteorVolts1)
850 listVoltageSeries.append(meteorVolts1)
849
851
850 return listMeteors1, listPowerSeries, listVoltageSeries
852 return listMeteors1, listPowerSeries, listVoltageSeries
851
853
852 def __estimateDecayTime(self, listMeteors, listPower, timeInterval, frequency):
854 def __estimateDecayTime(self, listMeteors, listPower, timeInterval, frequency):
853
855
854 threshError = 10
856 threshError = 10
855 #Depending if it is 30 or 50 MHz
857 #Depending if it is 30 or 50 MHz
856 if frequency == 30e6:
858 if frequency == 30e6:
857 timeLag = 45*10**-3
859 timeLag = 45*10**-3
858 else:
860 else:
859 timeLag = 15*10**-3
861 timeLag = 15*10**-3
860 lag = numpy.ceil(timeLag/timeInterval)
862 lag = numpy.ceil(timeLag/timeInterval)
861
863
862 listMeteors1 = []
864 listMeteors1 = []
863
865
864 for i in range(len(listMeteors)):
866 for i in range(len(listMeteors)):
865 meteorPower = listPower[i]
867 meteorPower = listPower[i]
866 meteorAux = listMeteors[i]
868 meteorAux = listMeteors[i]
867
869
868 if meteorAux[-1] == 0:
870 if meteorAux[-1] == 0:
869
871
870 try:
872 try:
871 indmax = meteorPower.argmax()
873 indmax = meteorPower.argmax()
872 indlag = indmax + lag
874 indlag = indmax + lag
873
875
874 y = meteorPower[indlag:]
876 y = meteorPower[indlag:]
875 x = numpy.arange(0, y.size)*timeLag
877 x = numpy.arange(0, y.size)*timeLag
876
878
877 #first guess
879 #first guess
878 a = y[0]
880 a = y[0]
879 tau = timeLag
881 tau = timeLag
880 #exponential fit
882 #exponential fit
881 popt, pcov = optimize.curve_fit(self.__exponential_function, x, y, p0 = [a, tau])
883 popt, pcov = optimize.curve_fit(self.__exponential_function, x, y, p0 = [a, tau])
882 y1 = self.__exponential_function(x, *popt)
884 y1 = self.__exponential_function(x, *popt)
883 #error estimation
885 #error estimation
884 error = sum((y - y1)**2)/(numpy.var(y)*(y.size - popt.size))
886 error = sum((y - y1)**2)/(numpy.var(y)*(y.size - popt.size))
885
887
886 decayTime = popt[1]
888 decayTime = popt[1]
887 riseTime = indmax*timeInterval
889 riseTime = indmax*timeInterval
888 meteorAux[11:13] = [decayTime, error]
890 meteorAux[11:13] = [decayTime, error]
889
891
890 #Table items 7, 8 and 11
892 #Table items 7, 8 and 11
891 if (riseTime > 0.3): #Number 7: Echo rise exceeds 0.3s
893 if (riseTime > 0.3): #Number 7: Echo rise exceeds 0.3s
892 meteorAux[-1] = 7
894 meteorAux[-1] = 7
893 elif (decayTime < 2*riseTime) : #Number 8: Echo decay time less than than twice rise time
895 elif (decayTime < 2*riseTime) : #Number 8: Echo decay time less than than twice rise time
894 meteorAux[-1] = 8
896 meteorAux[-1] = 8
895 if (error > threshError): #Number 11: Poor fit to amplitude for estimation of decay time
897 if (error > threshError): #Number 11: Poor fit to amplitude for estimation of decay time
896 meteorAux[-1] = 11
898 meteorAux[-1] = 11
897
899
898
900
899 except:
901 except:
900 meteorAux[-1] = 11
902 meteorAux[-1] = 11
901
903
902
904
903 listMeteors1.append(meteorAux)
905 listMeteors1.append(meteorAux)
904
906
905 return listMeteors1
907 return listMeteors1
906
908
907 #Exponential Function
909 #Exponential Function
908
910
909 def __exponential_function(self, x, a, tau):
911 def __exponential_function(self, x, a, tau):
910 y = a*numpy.exp(-x/tau)
912 y = a*numpy.exp(-x/tau)
911 return y
913 return y
912
914
913 def __getRadialVelocity(self, listMeteors, listVolts, radialStdThresh, pairslist, timeInterval):
915 def __getRadialVelocity(self, listMeteors, listVolts, radialStdThresh, pairslist, timeInterval):
914
916
915 pairslist1 = list(pairslist)
917 pairslist1 = list(pairslist)
916 pairslist1.append((0,1))
918 pairslist1.append((0,1))
917 pairslist1.append((3,4))
919 pairslist1.append((3,4))
918 numPairs = len(pairslist1)
920 numPairs = len(pairslist1)
919 #Time Lag
921 #Time Lag
920 timeLag = 45*10**-3
922 timeLag = 45*10**-3
921 c = 3e8
923 c = 3e8
922 lag = numpy.ceil(timeLag/timeInterval)
924 lag = numpy.ceil(timeLag/timeInterval)
923 freq = 30e6
925 freq = 30e6
924
926
925 listMeteors1 = []
927 listMeteors1 = []
926
928
927 for i in range(len(listMeteors)):
929 for i in range(len(listMeteors)):
928 meteor = listMeteors[i]
930 meteor = listMeteors[i]
929 meteorAux = numpy.hstack((meteor[:-1], 0, 0, meteor[-1]))
931 meteorAux = numpy.hstack((meteor[:-1], 0, 0, meteor[-1]))
930 if meteor[-1] == 0:
932 if meteor[-1] == 0:
931 mStart = listMeteors[i][1]
933 mStart = listMeteors[i][1]
932 mPeak = listMeteors[i][2]
934 mPeak = listMeteors[i][2]
933 mLag = mPeak - mStart + lag
935 mLag = mPeak - mStart + lag
934
936
935 #get the volt data between the start and end times of the meteor
937 #get the volt data between the start and end times of the meteor
936 meteorVolts = listVolts[i]
938 meteorVolts = listVolts[i]
937 meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1)
939 meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1)
938
940
939 #Get CCF
941 #Get CCF
940 allCCFs = self.__calculateCCF(meteorVolts, pairslist1, [-2,-1,0,1,2])
942 allCCFs = self.__calculateCCF(meteorVolts, pairslist1, [-2,-1,0,1,2])
941
943
942 #Method 2
944 #Method 2
943 slopes = numpy.zeros(numPairs)
945 slopes = numpy.zeros(numPairs)
944 time = numpy.array([-2,-1,1,2])*timeInterval
946 time = numpy.array([-2,-1,1,2])*timeInterval
945 angAllCCF = numpy.angle(allCCFs[:,[0,1,3,4],0])
947 angAllCCF = numpy.angle(allCCFs[:,[0,1,3,4],0])
946
948
947 #Correct phases
949 #Correct phases
948 derPhaseCCF = angAllCCF[:,1:] - angAllCCF[:,0:-1]
950 derPhaseCCF = angAllCCF[:,1:] - angAllCCF[:,0:-1]
949 indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi)
951 indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi)
950
952
951 if indDer[0].shape[0] > 0:
953 if indDer[0].shape[0] > 0:
952 for i in range(indDer[0].shape[0]):
954 for i in range(indDer[0].shape[0]):
953 signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i]])
955 signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i]])
954 angAllCCF[indDer[0][i],indDer[1][i]+1:] += signo*2*numpy.pi
956 angAllCCF[indDer[0][i],indDer[1][i]+1:] += signo*2*numpy.pi
955
957
956 # fit = scipy.stats.linregress(numpy.array([-2,-1,1,2])*timeInterval, numpy.array([phaseLagN2s[i],phaseLagN1s[i],phaseLag1s[i],phaseLag2s[i]]))
958 # 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):
959 for j in range(numPairs):
958 fit = stats.linregress(time, angAllCCF[j,:])
960 fit = stats.linregress(time, angAllCCF[j,:])
959 slopes[j] = fit[0]
961 slopes[j] = fit[0]
960
962
961 #Remove Outlier
963 #Remove Outlier
962 # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes)))
964 # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes)))
963 # slopes = numpy.delete(slopes,indOut)
965 # slopes = numpy.delete(slopes,indOut)
964 # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes)))
966 # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes)))
965 # slopes = numpy.delete(slopes,indOut)
967 # slopes = numpy.delete(slopes,indOut)
966
968
967 radialVelocity = -numpy.mean(slopes)*(0.25/numpy.pi)*(c/freq)
969 radialVelocity = -numpy.mean(slopes)*(0.25/numpy.pi)*(c/freq)
968 radialError = numpy.std(slopes)*(0.25/numpy.pi)*(c/freq)
970 radialError = numpy.std(slopes)*(0.25/numpy.pi)*(c/freq)
969 meteorAux[-2] = radialError
971 meteorAux[-2] = radialError
970 meteorAux[-3] = radialVelocity
972 meteorAux[-3] = radialVelocity
971
973
972 #Setting Error
974 #Setting Error
973 #Number 15: Radial Drift velocity or projected horizontal velocity exceeds 200 m/s
975 #Number 15: Radial Drift velocity or projected horizontal velocity exceeds 200 m/s
974 if numpy.abs(radialVelocity) > 200:
976 if numpy.abs(radialVelocity) > 200:
975 meteorAux[-1] = 15
977 meteorAux[-1] = 15
976 #Number 12: Poor fit to CCF variation for estimation of radial drift velocity
978 #Number 12: Poor fit to CCF variation for estimation of radial drift velocity
977 elif radialError > radialStdThresh:
979 elif radialError > radialStdThresh:
978 meteorAux[-1] = 12
980 meteorAux[-1] = 12
979
981
980 listMeteors1.append(meteorAux)
982 listMeteors1.append(meteorAux)
981 return listMeteors1
983 return listMeteors1
982
984
983 def __setNewArrays(self, listMeteors, date, heiRang):
985 def __setNewArrays(self, listMeteors, date, heiRang):
984
986
985 #New arrays
987 #New arrays
986 arrayMeteors = numpy.array(listMeteors)
988 arrayMeteors = numpy.array(listMeteors)
987 arrayParameters = numpy.zeros((len(listMeteors),10))
989 arrayParameters = numpy.zeros((len(listMeteors),10))
988
990
989 #Date inclusion
991 #Date inclusion
990 date = re.findall(r'\((.*?)\)', date)
992 date = re.findall(r'\((.*?)\)', date)
991 date = date[0].split(',')
993 date = date[0].split(',')
992 date = map(int, date)
994 date = map(int, date)
993 date = [date[0]*10000 + date[1]*100 + date[2], date[3]*10000 + date[4]*100 + date[5]]
995 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))
996 arrayDate = numpy.tile(date, (len(listMeteors), 1))
995
997
996 #Meteor array
998 #Meteor array
997 arrayMeteors[:,0] = heiRang[arrayMeteors[:,0].astype(int)]
999 arrayMeteors[:,0] = heiRang[arrayMeteors[:,0].astype(int)]
998 arrayMeteors = numpy.hstack((arrayDate, arrayMeteors))
1000 arrayMeteors = numpy.hstack((arrayDate, arrayMeteors))
999
1001
1000 #Parameters Array
1002 #Parameters Array
1001 arrayParameters[:,0:3] = arrayMeteors[:,0:3]
1003 arrayParameters[:,0:3] = arrayMeteors[:,0:3]
1002 arrayParameters[:,-3:] = arrayMeteors[:,-3:]
1004 arrayParameters[:,-3:] = arrayMeteors[:,-3:]
1003
1005
1004 return arrayMeteors, arrayParameters
1006 return arrayMeteors, arrayParameters
1005
1007
1006 def __getAOA(self, phases, pairsList, error, AOAthresh, azimuth):
1008 def __getAOA(self, phases, pairsList, error, AOAthresh, azimuth):
1007
1009
1008 arrayAOA = numpy.zeros((phases.shape[0],3))
1010 arrayAOA = numpy.zeros((phases.shape[0],3))
1009 cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList)
1011 cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList)
1010
1012
1011 arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth)
1013 arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth)
1012 cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1)
1014 cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1)
1013 arrayAOA[:,2] = cosDirError
1015 arrayAOA[:,2] = cosDirError
1014
1016
1015 azimuthAngle = arrayAOA[:,0]
1017 azimuthAngle = arrayAOA[:,0]
1016 zenithAngle = arrayAOA[:,1]
1018 zenithAngle = arrayAOA[:,1]
1017
1019
1018 #Setting Error
1020 #Setting Error
1019 #Number 3: AOA not fesible
1021 #Number 3: AOA not fesible
1020 indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0]
1022 indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0]
1021 error[indInvalid] = 3
1023 error[indInvalid] = 3
1022 #Number 4: Large difference in AOAs obtained from different antenna baselines
1024 #Number 4: Large difference in AOAs obtained from different antenna baselines
1023 indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0]
1025 indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0]
1024 error[indInvalid] = 4
1026 error[indInvalid] = 4
1025 return arrayAOA, error
1027 return arrayAOA, error
1026
1028
1027 def __getDirectionCosines(self, arrayPhase, pairsList):
1029 def __getDirectionCosines(self, arrayPhase, pairsList):
1028
1030
1029 #Initializing some variables
1031 #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
1032 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)
1033 ang_aux = ang_aux.reshape(1,ang_aux.size)
1032
1034
1033 cosdir = numpy.zeros((arrayPhase.shape[0],2))
1035 cosdir = numpy.zeros((arrayPhase.shape[0],2))
1034 cosdir0 = numpy.zeros((arrayPhase.shape[0],2))
1036 cosdir0 = numpy.zeros((arrayPhase.shape[0],2))
1035
1037
1036
1038
1037 for i in range(2):
1039 for i in range(2):
1038 #First Estimation
1040 #First Estimation
1039 phi0_aux = arrayPhase[:,pairsList[i][0]] + arrayPhase[:,pairsList[i][1]]
1041 phi0_aux = arrayPhase[:,pairsList[i][0]] + arrayPhase[:,pairsList[i][1]]
1040 #Dealias
1042 #Dealias
1041 indcsi = numpy.where(phi0_aux > numpy.pi)
1043 indcsi = numpy.where(phi0_aux > numpy.pi)
1042 phi0_aux[indcsi] -= 2*numpy.pi
1044 phi0_aux[indcsi] -= 2*numpy.pi
1043 indcsi = numpy.where(phi0_aux < -numpy.pi)
1045 indcsi = numpy.where(phi0_aux < -numpy.pi)
1044 phi0_aux[indcsi] += 2*numpy.pi
1046 phi0_aux[indcsi] += 2*numpy.pi
1045 #Direction Cosine 0
1047 #Direction Cosine 0
1046 cosdir0[:,i] = -(phi0_aux)/(2*numpy.pi*0.5)
1048 cosdir0[:,i] = -(phi0_aux)/(2*numpy.pi*0.5)
1047
1049
1048 #Most-Accurate Second Estimation
1050 #Most-Accurate Second Estimation
1049 phi1_aux = arrayPhase[:,pairsList[i][0]] - arrayPhase[:,pairsList[i][1]]
1051 phi1_aux = arrayPhase[:,pairsList[i][0]] - arrayPhase[:,pairsList[i][1]]
1050 phi1_aux = phi1_aux.reshape(phi1_aux.size,1)
1052 phi1_aux = phi1_aux.reshape(phi1_aux.size,1)
1051 #Direction Cosine 1
1053 #Direction Cosine 1
1052 cosdir1 = -(phi1_aux + ang_aux)/(2*numpy.pi*4.5)
1054 cosdir1 = -(phi1_aux + ang_aux)/(2*numpy.pi*4.5)
1053
1055
1054 #Searching the correct Direction Cosine
1056 #Searching the correct Direction Cosine
1055 cosdir0_aux = cosdir0[:,i]
1057 cosdir0_aux = cosdir0[:,i]
1056 cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1)
1058 cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1)
1057 #Minimum Distance
1059 #Minimum Distance
1058 cosDiff = (cosdir1 - cosdir0_aux)**2
1060 cosDiff = (cosdir1 - cosdir0_aux)**2
1059 indcos = cosDiff.argmin(axis = 1)
1061 indcos = cosDiff.argmin(axis = 1)
1060 #Saving Value obtained
1062 #Saving Value obtained
1061 cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos]
1063 cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos]
1062
1064
1063 return cosdir0, cosdir
1065 return cosdir0, cosdir
1064
1066
1065 def __calculateAOA(self, cosdir, azimuth):
1067 def __calculateAOA(self, cosdir, azimuth):
1066 cosdirX = cosdir[:,0]
1068 cosdirX = cosdir[:,0]
1067 cosdirY = cosdir[:,1]
1069 cosdirY = cosdir[:,1]
1068
1070
1069 zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi
1071 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
1072 azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth #0 deg north, 90 deg east
1071 angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose()
1073 angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose()
1072
1074
1073 return angles
1075 return angles
1074
1076
1075 def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight):
1077 def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight):
1076
1078
1077 Ramb = 375 #Ramb = c/(2*PRF)
1079 Ramb = 375 #Ramb = c/(2*PRF)
1078 Re = 6371 #Earth Radius
1080 Re = 6371 #Earth Radius
1079 heights = numpy.zeros(Ranges.shape)
1081 heights = numpy.zeros(Ranges.shape)
1080
1082
1081 R_aux = numpy.array([0,1,2])*Ramb
1083 R_aux = numpy.array([0,1,2])*Ramb
1082 R_aux = R_aux.reshape(1,R_aux.size)
1084 R_aux = R_aux.reshape(1,R_aux.size)
1083
1085
1084 Ranges = Ranges.reshape(Ranges.size,1)
1086 Ranges = Ranges.reshape(Ranges.size,1)
1085
1087
1086 Ri = Ranges + R_aux
1088 Ri = Ranges + R_aux
1087 hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re
1089 hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re
1088
1090
1089 #Check if there is a height between 70 and 110 km
1091 #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)
1092 h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1)
1091 ind_h = numpy.where(h_bool == 1)[0]
1093 ind_h = numpy.where(h_bool == 1)[0]
1092
1094
1093 hCorr = hi[ind_h, :]
1095 hCorr = hi[ind_h, :]
1094 ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight))
1096 ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight))
1095
1097
1096 hCorr = hi[ind_hCorr]
1098 hCorr = hi[ind_hCorr]
1097 heights[ind_h] = hCorr
1099 heights[ind_h] = hCorr
1098
1100
1099 #Setting Error
1101 #Setting Error
1100 #Number 13: Height unresolvable echo: not valid height within 70 to 110 km
1102 #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
1103 #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km
1102
1104
1103 indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0]
1105 indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0]
1104 error[indInvalid2] = 14
1106 error[indInvalid2] = 14
1105 indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0]
1107 indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0]
1106 error[indInvalid1] = 13
1108 error[indInvalid1] = 13
1107
1109
1108 return heights, error
1110 return heights, error
1109
1111
1110
1112
1111 class WindProfiler(Operation):
1113 class WindProfiler(Operation):
1112
1114
1113 __isConfig = False
1115 __isConfig = False
1114
1116
1115 __initime = None
1117 __initime = None
1116 __lastdatatime = None
1118 __lastdatatime = None
1117 __integrationtime = None
1119 __integrationtime = None
1118
1120
1119 __buffer = None
1121 __buffer = None
1120
1122
1121 __dataReady = False
1123 __dataReady = False
1122
1124
1123 __firstdata = None
1125 __firstdata = None
1124
1126
1125 n = None
1127 n = None
1126
1128
1127 def __init__(self):
1129 def __init__(self):
1128 Operation.__init__(self)
1130 Operation.__init__(self)
1129
1131
1130 def __calculateCosDir(self, elev, azim):
1132 def __calculateCosDir(self, elev, azim):
1131 zen = (90 - elev)*numpy.pi/180
1133 zen = (90 - elev)*numpy.pi/180
1132 azim = azim*numpy.pi/180
1134 azim = azim*numpy.pi/180
1133 cosDirX = numpy.sqrt((1-numpy.cos(zen)**2)/((1+numpy.tan(azim)**2)))
1135 cosDirX = numpy.sqrt((1-numpy.cos(zen)**2)/((1+numpy.tan(azim)**2)))
1134 cosDirY = numpy.sqrt(1-numpy.cos(zen)**2-cosDirX**2)
1136 cosDirY = numpy.sqrt(1-numpy.cos(zen)**2-cosDirX**2)
1135
1137
1136 signX = numpy.sign(numpy.cos(azim))
1138 signX = numpy.sign(numpy.cos(azim))
1137 signY = numpy.sign(numpy.sin(azim))
1139 signY = numpy.sign(numpy.sin(azim))
1138
1140
1139 cosDirX = numpy.copysign(cosDirX, signX)
1141 cosDirX = numpy.copysign(cosDirX, signX)
1140 cosDirY = numpy.copysign(cosDirY, signY)
1142 cosDirY = numpy.copysign(cosDirY, signY)
1141 return cosDirX, cosDirY
1143 return cosDirX, cosDirY
1142
1144
1143 def __calculateAngles(self, theta_x, theta_y, azimuth):
1145 def __calculateAngles(self, theta_x, theta_y, azimuth):
1144
1146
1145 dir_cosw = numpy.sqrt(1-theta_x**2-theta_y**2)
1147 dir_cosw = numpy.sqrt(1-theta_x**2-theta_y**2)
1146 zenith_arr = numpy.arccos(dir_cosw)
1148 zenith_arr = numpy.arccos(dir_cosw)
1147 azimuth_arr = numpy.arctan2(theta_x,theta_y) + azimuth*math.pi/180
1149 azimuth_arr = numpy.arctan2(theta_x,theta_y) + azimuth*math.pi/180
1148
1150
1149 dir_cosu = numpy.sin(azimuth_arr)*numpy.sin(zenith_arr)
1151 dir_cosu = numpy.sin(azimuth_arr)*numpy.sin(zenith_arr)
1150 dir_cosv = numpy.cos(azimuth_arr)*numpy.sin(zenith_arr)
1152 dir_cosv = numpy.cos(azimuth_arr)*numpy.sin(zenith_arr)
1151
1153
1152 return azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw
1154 return azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw
1153
1155
1154 def __calculateMatA(self, dir_cosu, dir_cosv, dir_cosw, horOnly):
1156 def __calculateMatA(self, dir_cosu, dir_cosv, dir_cosw, horOnly):
1155
1157
1156 #
1158 #
1157 if horOnly:
1159 if horOnly:
1158 A = numpy.c_[dir_cosu,dir_cosv]
1160 A = numpy.c_[dir_cosu,dir_cosv]
1159 else:
1161 else:
1160 A = numpy.c_[dir_cosu,dir_cosv,dir_cosw]
1162 A = numpy.c_[dir_cosu,dir_cosv,dir_cosw]
1161 A = numpy.asmatrix(A)
1163 A = numpy.asmatrix(A)
1162 A1 = numpy.linalg.inv(A.transpose()*A)*A.transpose()
1164 A1 = numpy.linalg.inv(A.transpose()*A)*A.transpose()
1163
1165
1164 return A1
1166 return A1
1165
1167
1166 def __correctValues(self, heiRang, phi, velRadial, SNR):
1168 def __correctValues(self, heiRang, phi, velRadial, SNR):
1167 listPhi = phi.tolist()
1169 listPhi = phi.tolist()
1168 maxid = listPhi.index(max(listPhi))
1170 maxid = listPhi.index(max(listPhi))
1169 minid = listPhi.index(min(listPhi))
1171 minid = listPhi.index(min(listPhi))
1170
1172
1171 rango = range(len(phi))
1173 rango = range(len(phi))
1172 # rango = numpy.delete(rango,maxid)
1174 # rango = numpy.delete(rango,maxid)
1173
1175
1174 heiRang1 = heiRang*math.cos(phi[maxid])
1176 heiRang1 = heiRang*math.cos(phi[maxid])
1175 heiRangAux = heiRang*math.cos(phi[minid])
1177 heiRangAux = heiRang*math.cos(phi[minid])
1176 indOut = (heiRang1 < heiRangAux[0]).nonzero()
1178 indOut = (heiRang1 < heiRangAux[0]).nonzero()
1177 heiRang1 = numpy.delete(heiRang1,indOut)
1179 heiRang1 = numpy.delete(heiRang1,indOut)
1178
1180
1179 velRadial1 = numpy.zeros([len(phi),len(heiRang1)])
1181 velRadial1 = numpy.zeros([len(phi),len(heiRang1)])
1180 SNR1 = numpy.zeros([len(phi),len(heiRang1)])
1182 SNR1 = numpy.zeros([len(phi),len(heiRang1)])
1181
1183
1182 for i in rango:
1184 for i in rango:
1183 x = heiRang*math.cos(phi[i])
1185 x = heiRang*math.cos(phi[i])
1184 y1 = velRadial[i,:]
1186 y1 = velRadial[i,:]
1185 f1 = interpolate.interp1d(x,y1,kind = 'cubic')
1187 f1 = interpolate.interp1d(x,y1,kind = 'cubic')
1186
1188
1187 x1 = heiRang1
1189 x1 = heiRang1
1188 y11 = f1(x1)
1190 y11 = f1(x1)
1189
1191
1190 y2 = SNR[i,:]
1192 y2 = SNR[i,:]
1191 f2 = interpolate.interp1d(x,y2,kind = 'cubic')
1193 f2 = interpolate.interp1d(x,y2,kind = 'cubic')
1192 y21 = f2(x1)
1194 y21 = f2(x1)
1193
1195
1194 velRadial1[i,:] = y11
1196 velRadial1[i,:] = y11
1195 SNR1[i,:] = y21
1197 SNR1[i,:] = y21
1196
1198
1197 return heiRang1, velRadial1, SNR1
1199 return heiRang1, velRadial1, SNR1
1198
1200
1199 def __calculateVelUVW(self, A, velRadial):
1201 def __calculateVelUVW(self, A, velRadial):
1200
1202
1201 #Operacion Matricial
1203 #Operacion Matricial
1202 # velUVW = numpy.zeros((velRadial.shape[1],3))
1204 # velUVW = numpy.zeros((velRadial.shape[1],3))
1203 # for ind in range(velRadial.shape[1]):
1205 # for ind in range(velRadial.shape[1]):
1204 # velUVW[ind,:] = numpy.dot(A,velRadial[:,ind])
1206 # velUVW[ind,:] = numpy.dot(A,velRadial[:,ind])
1205 # velUVW = velUVW.transpose()
1207 # velUVW = velUVW.transpose()
1206 velUVW = numpy.zeros((A.shape[0],velRadial.shape[1]))
1208 velUVW = numpy.zeros((A.shape[0],velRadial.shape[1]))
1207 velUVW[:,:] = numpy.dot(A,velRadial)
1209 velUVW[:,:] = numpy.dot(A,velRadial)
1208
1210
1209
1211
1210 return velUVW
1212 return velUVW
1211
1213
1212 def techniqueDBS(self, velRadial0, dirCosx, disrCosy, azimuth, correct, horizontalOnly, heiRang, SNR0):
1214 def techniqueDBS(self, velRadial0, dirCosx, disrCosy, azimuth, correct, horizontalOnly, heiRang, SNR0):
1213 """
1215 """
1214 Function that implements Doppler Beam Swinging (DBS) technique.
1216 Function that implements Doppler Beam Swinging (DBS) technique.
1215
1217
1216 Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth,
1218 Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth,
1217 Direction correction (if necessary), Ranges and SNR
1219 Direction correction (if necessary), Ranges and SNR
1218
1220
1219 Output: Winds estimation (Zonal, Meridional and Vertical)
1221 Output: Winds estimation (Zonal, Meridional and Vertical)
1220
1222
1221 Parameters affected: Winds, height range, SNR
1223 Parameters affected: Winds, height range, SNR
1222 """
1224 """
1223 azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw = self.__calculateAngles(dirCosx, disrCosy, azimuth)
1225 azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw = self.__calculateAngles(dirCosx, disrCosy, azimuth)
1224 heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, zenith_arr, correct*velRadial0, SNR0)
1226 heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, zenith_arr, correct*velRadial0, SNR0)
1225 A = self.__calculateMatA(dir_cosu, dir_cosv, dir_cosw, horizontalOnly)
1227 A = self.__calculateMatA(dir_cosu, dir_cosv, dir_cosw, horizontalOnly)
1226
1228
1227 #Calculo de Componentes de la velocidad con DBS
1229 #Calculo de Componentes de la velocidad con DBS
1228 winds = self.__calculateVelUVW(A,velRadial1)
1230 winds = self.__calculateVelUVW(A,velRadial1)
1229
1231
1230 return winds, heiRang1, SNR1
1232 return winds, heiRang1, SNR1
1231
1233
1232 def __calculateDistance(self, posx, posy, pairsCrossCorr, pairsList, pairs, azimuth = None):
1234 def __calculateDistance(self, posx, posy, pairsCrossCorr, pairsList, pairs, azimuth = None):
1233
1235
1234 posx = numpy.asarray(posx)
1236 posx = numpy.asarray(posx)
1235 posy = numpy.asarray(posy)
1237 posy = numpy.asarray(posy)
1236
1238
1237 #Rotacion Inversa para alinear con el azimuth
1239 #Rotacion Inversa para alinear con el azimuth
1238 if azimuth!= None:
1240 if azimuth!= None:
1239 azimuth = azimuth*math.pi/180
1241 azimuth = azimuth*math.pi/180
1240 posx1 = posx*math.cos(azimuth) + posy*math.sin(azimuth)
1242 posx1 = posx*math.cos(azimuth) + posy*math.sin(azimuth)
1241 posy1 = -posx*math.sin(azimuth) + posy*math.cos(azimuth)
1243 posy1 = -posx*math.sin(azimuth) + posy*math.cos(azimuth)
1242 else:
1244 else:
1243 posx1 = posx
1245 posx1 = posx
1244 posy1 = posy
1246 posy1 = posy
1245
1247
1246 #Calculo de Distancias
1248 #Calculo de Distancias
1247 distx = numpy.zeros(pairsCrossCorr.size)
1249 distx = numpy.zeros(pairsCrossCorr.size)
1248 disty = numpy.zeros(pairsCrossCorr.size)
1250 disty = numpy.zeros(pairsCrossCorr.size)
1249 dist = numpy.zeros(pairsCrossCorr.size)
1251 dist = numpy.zeros(pairsCrossCorr.size)
1250 ang = numpy.zeros(pairsCrossCorr.size)
1252 ang = numpy.zeros(pairsCrossCorr.size)
1251
1253
1252 for i in range(pairsCrossCorr.size):
1254 for i in range(pairsCrossCorr.size):
1253 distx[i] = posx1[pairsList[pairsCrossCorr[i]][1]] - posx1[pairsList[pairsCrossCorr[i]][0]]
1255 distx[i] = posx1[pairsList[pairsCrossCorr[i]][1]] - posx1[pairsList[pairsCrossCorr[i]][0]]
1254 disty[i] = posy1[pairsList[pairsCrossCorr[i]][1]] - posy1[pairsList[pairsCrossCorr[i]][0]]
1256 disty[i] = posy1[pairsList[pairsCrossCorr[i]][1]] - posy1[pairsList[pairsCrossCorr[i]][0]]
1255 dist[i] = numpy.sqrt(distx[i]**2 + disty[i]**2)
1257 dist[i] = numpy.sqrt(distx[i]**2 + disty[i]**2)
1256 ang[i] = numpy.arctan2(disty[i],distx[i])
1258 ang[i] = numpy.arctan2(disty[i],distx[i])
1257 #Calculo de Matrices
1259 #Calculo de Matrices
1258 nPairs = len(pairs)
1260 nPairs = len(pairs)
1259 ang1 = numpy.zeros((nPairs, 2, 1))
1261 ang1 = numpy.zeros((nPairs, 2, 1))
1260 dist1 = numpy.zeros((nPairs, 2, 1))
1262 dist1 = numpy.zeros((nPairs, 2, 1))
1261
1263
1262 for j in range(nPairs):
1264 for j in range(nPairs):
1263 dist1[j,0,0] = dist[pairs[j][0]]
1265 dist1[j,0,0] = dist[pairs[j][0]]
1264 dist1[j,1,0] = dist[pairs[j][1]]
1266 dist1[j,1,0] = dist[pairs[j][1]]
1265 ang1[j,0,0] = ang[pairs[j][0]]
1267 ang1[j,0,0] = ang[pairs[j][0]]
1266 ang1[j,1,0] = ang[pairs[j][1]]
1268 ang1[j,1,0] = ang[pairs[j][1]]
1267
1269
1268 return distx,disty, dist1,ang1
1270 return distx,disty, dist1,ang1
1269
1271
1270 def __calculateVelVer(self, phase, lagTRange, _lambda):
1272 def __calculateVelVer(self, phase, lagTRange, _lambda):
1271
1273
1272 Ts = lagTRange[1] - lagTRange[0]
1274 Ts = lagTRange[1] - lagTRange[0]
1273 velW = -_lambda*phase/(4*math.pi*Ts)
1275 velW = -_lambda*phase/(4*math.pi*Ts)
1274
1276
1275 return velW
1277 return velW
1276
1278
1277 def __calculateVelHorDir(self, dist, tau1, tau2, ang):
1279 def __calculateVelHorDir(self, dist, tau1, tau2, ang):
1278 nPairs = tau1.shape[0]
1280 nPairs = tau1.shape[0]
1279 vel = numpy.zeros((nPairs,3,tau1.shape[2]))
1281 vel = numpy.zeros((nPairs,3,tau1.shape[2]))
1280
1282
1281 angCos = numpy.cos(ang)
1283 angCos = numpy.cos(ang)
1282 angSin = numpy.sin(ang)
1284 angSin = numpy.sin(ang)
1283
1285
1284 vel0 = dist*tau1/(2*tau2**2)
1286 vel0 = dist*tau1/(2*tau2**2)
1285 vel[:,0,:] = (vel0*angCos).sum(axis = 1)
1287 vel[:,0,:] = (vel0*angCos).sum(axis = 1)
1286 vel[:,1,:] = (vel0*angSin).sum(axis = 1)
1288 vel[:,1,:] = (vel0*angSin).sum(axis = 1)
1287
1289
1288 ind = numpy.where(numpy.isinf(vel))
1290 ind = numpy.where(numpy.isinf(vel))
1289 vel[ind] = numpy.nan
1291 vel[ind] = numpy.nan
1290
1292
1291 return vel
1293 return vel
1292
1294
1293 def __getPairsAutoCorr(self, pairsList, nChannels):
1295 def __getPairsAutoCorr(self, pairsList, nChannels):
1294
1296
1295 pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan
1297 pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan
1296
1298
1297 for l in range(len(pairsList)):
1299 for l in range(len(pairsList)):
1298 firstChannel = pairsList[l][0]
1300 firstChannel = pairsList[l][0]
1299 secondChannel = pairsList[l][1]
1301 secondChannel = pairsList[l][1]
1300
1302
1301 #Obteniendo pares de Autocorrelacion
1303 #Obteniendo pares de Autocorrelacion
1302 if firstChannel == secondChannel:
1304 if firstChannel == secondChannel:
1303 pairsAutoCorr[firstChannel] = int(l)
1305 pairsAutoCorr[firstChannel] = int(l)
1304
1306
1305 pairsAutoCorr = pairsAutoCorr.astype(int)
1307 pairsAutoCorr = pairsAutoCorr.astype(int)
1306
1308
1307 pairsCrossCorr = range(len(pairsList))
1309 pairsCrossCorr = range(len(pairsList))
1308 pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr)
1310 pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr)
1309
1311
1310 return pairsAutoCorr, pairsCrossCorr
1312 return pairsAutoCorr, pairsCrossCorr
1311
1313
1312 def techniqueSA(self, pairsSelected, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, lagTRange, correctFactor):
1314 def techniqueSA(self, pairsSelected, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, lagTRange, correctFactor):
1313 """
1315 """
1314 Function that implements Spaced Antenna (SA) technique.
1316 Function that implements Spaced Antenna (SA) technique.
1315
1317
1316 Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth,
1318 Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth,
1317 Direction correction (if necessary), Ranges and SNR
1319 Direction correction (if necessary), Ranges and SNR
1318
1320
1319 Output: Winds estimation (Zonal, Meridional and Vertical)
1321 Output: Winds estimation (Zonal, Meridional and Vertical)
1320
1322
1321 Parameters affected: Winds
1323 Parameters affected: Winds
1322 """
1324 """
1323 #Cross Correlation pairs obtained
1325 #Cross Correlation pairs obtained
1324 pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairsList, nChannels)
1326 pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairsList, nChannels)
1325 pairsArray = numpy.array(pairsList)[pairsCrossCorr]
1327 pairsArray = numpy.array(pairsList)[pairsCrossCorr]
1326 pairsSelArray = numpy.array(pairsSelected)
1328 pairsSelArray = numpy.array(pairsSelected)
1327 pairs = []
1329 pairs = []
1328
1330
1329 #Wind estimation pairs obtained
1331 #Wind estimation pairs obtained
1330 for i in range(pairsSelArray.shape[0]/2):
1332 for i in range(pairsSelArray.shape[0]/2):
1331 ind1 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i], axis = 1))[0][0]
1333 ind1 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i], axis = 1))[0][0]
1332 ind2 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i + 1], axis = 1))[0][0]
1334 ind2 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i + 1], axis = 1))[0][0]
1333 pairs.append((ind1,ind2))
1335 pairs.append((ind1,ind2))
1334
1336
1335 indtau = tau.shape[0]/2
1337 indtau = tau.shape[0]/2
1336 tau1 = tau[:indtau,:]
1338 tau1 = tau[:indtau,:]
1337 tau2 = tau[indtau:-1,:]
1339 tau2 = tau[indtau:-1,:]
1338 tau1 = tau1[pairs,:]
1340 tau1 = tau1[pairs,:]
1339 tau2 = tau2[pairs,:]
1341 tau2 = tau2[pairs,:]
1340 phase1 = tau[-1,:]
1342 phase1 = tau[-1,:]
1341
1343
1342 #---------------------------------------------------------------------
1344 #---------------------------------------------------------------------
1343 #Metodo Directo
1345 #Metodo Directo
1344 distx, disty, dist, ang = self.__calculateDistance(position_x, position_y, pairsCrossCorr, pairsList, pairs,azimuth)
1346 distx, disty, dist, ang = self.__calculateDistance(position_x, position_y, pairsCrossCorr, pairsList, pairs,azimuth)
1345 winds = self.__calculateVelHorDir(dist, tau1, tau2, ang)
1347 winds = self.__calculateVelHorDir(dist, tau1, tau2, ang)
1346 winds = stats.nanmean(winds, axis=0)
1348 winds = stats.nanmean(winds, axis=0)
1347 #---------------------------------------------------------------------
1349 #---------------------------------------------------------------------
1348 #Metodo General
1350 #Metodo General
1349 # distx, disty, dist = self.calculateDistance(position_x,position_y,pairsCrossCorr, pairsList, azimuth)
1351 # distx, disty, dist = self.calculateDistance(position_x,position_y,pairsCrossCorr, pairsList, azimuth)
1350 # #Calculo Coeficientes de Funcion de Correlacion
1352 # #Calculo Coeficientes de Funcion de Correlacion
1351 # F,G,A,B,H = self.calculateCoef(tau1,tau2,distx,disty,n)
1353 # F,G,A,B,H = self.calculateCoef(tau1,tau2,distx,disty,n)
1352 # #Calculo de Velocidades
1354 # #Calculo de Velocidades
1353 # winds = self.calculateVelUV(F,G,A,B,H)
1355 # winds = self.calculateVelUV(F,G,A,B,H)
1354
1356
1355 #---------------------------------------------------------------------
1357 #---------------------------------------------------------------------
1356 winds[2,:] = self.__calculateVelVer(phase1, lagTRange, _lambda)
1358 winds[2,:] = self.__calculateVelVer(phase1, lagTRange, _lambda)
1357 winds = correctFactor*winds
1359 winds = correctFactor*winds
1358 return winds
1360 return winds
1359
1361
1360 def __checkTime(self, currentTime, paramInterval, windsInterval):
1362 def __checkTime(self, currentTime, paramInterval, windsInterval):
1361
1363
1362 dataTime = currentTime + paramInterval
1364 dataTime = currentTime + paramInterval
1363 deltaTime = dataTime - self.__initime
1365 deltaTime = dataTime - self.__initime
1364
1366
1365 if deltaTime >= windsInterval or deltaTime < 0:
1367 if deltaTime >= windsInterval or deltaTime < 0:
1366 self.__dataReady = True
1368 self.__dataReady = True
1367 return
1369 return
1368
1370
1369 def techniqueMeteors(self, arrayMeteor, meteorThresh, heightMin, heightMax):
1371 def techniqueMeteors(self, arrayMeteor, meteorThresh, heightMin, heightMax):
1370 '''
1372 '''
1371 Function that implements winds estimation technique with detected meteors.
1373 Function that implements winds estimation technique with detected meteors.
1372
1374
1373 Input: Detected meteors, Minimum meteor quantity to wind estimation
1375 Input: Detected meteors, Minimum meteor quantity to wind estimation
1374
1376
1375 Output: Winds estimation (Zonal and Meridional)
1377 Output: Winds estimation (Zonal and Meridional)
1376
1378
1377 Parameters affected: Winds
1379 Parameters affected: Winds
1378 '''
1380 '''
1379 #Settings
1381 #Settings
1380 nInt = (heightMax - heightMin)/2
1382 nInt = (heightMax - heightMin)/2
1381 winds = numpy.zeros((2,nInt))*numpy.nan
1383 winds = numpy.zeros((2,nInt))*numpy.nan
1382
1384
1383 #Filter errors
1385 #Filter errors
1384 error = numpy.where(arrayMeteor[:,-1] == 0)[0]
1386 error = numpy.where(arrayMeteor[:,-1] == 0)[0]
1385 finalMeteor = arrayMeteor[error,:]
1387 finalMeteor = arrayMeteor[error,:]
1386
1388
1387 #Meteor Histogram
1389 #Meteor Histogram
1388 finalHeights = finalMeteor[:,3]
1390 finalHeights = finalMeteor[:,3]
1389 hist = numpy.histogram(finalHeights, bins = nInt, range = (heightMin,heightMax))
1391 hist = numpy.histogram(finalHeights, bins = nInt, range = (heightMin,heightMax))
1390 nMeteorsPerI = hist[0]
1392 nMeteorsPerI = hist[0]
1391 heightPerI = hist[1]
1393 heightPerI = hist[1]
1392
1394
1393 #Sort of meteors
1395 #Sort of meteors
1394 indSort = finalHeights.argsort()
1396 indSort = finalHeights.argsort()
1395 finalMeteor2 = finalMeteor[indSort,:]
1397 finalMeteor2 = finalMeteor[indSort,:]
1396
1398
1397 # Calculating winds
1399 # Calculating winds
1398 ind1 = 0
1400 ind1 = 0
1399 ind2 = 0
1401 ind2 = 0
1400
1402
1401 for i in range(nInt):
1403 for i in range(nInt):
1402 nMet = nMeteorsPerI[i]
1404 nMet = nMeteorsPerI[i]
1403 ind1 = ind2
1405 ind1 = ind2
1404 ind2 = ind1 + nMet
1406 ind2 = ind1 + nMet
1405
1407
1406 meteorAux = finalMeteor2[ind1:ind2,:]
1408 meteorAux = finalMeteor2[ind1:ind2,:]
1407
1409
1408 if meteorAux.shape[0] >= meteorThresh:
1410 if meteorAux.shape[0] >= meteorThresh:
1409 vel = meteorAux[:, 7]
1411 vel = meteorAux[:, 7]
1410 zen = meteorAux[:, 5]*numpy.pi/180
1412 zen = meteorAux[:, 5]*numpy.pi/180
1411 azim = meteorAux[:, 4]*numpy.pi/180
1413 azim = meteorAux[:, 4]*numpy.pi/180
1412
1414
1413 n = numpy.cos(zen)
1415 n = numpy.cos(zen)
1414 # m = (1 - n**2)/(1 - numpy.tan(azim)**2)
1416 # m = (1 - n**2)/(1 - numpy.tan(azim)**2)
1415 # l = m*numpy.tan(azim)
1417 # l = m*numpy.tan(azim)
1416 l = numpy.sin(zen)*numpy.sin(azim)
1418 l = numpy.sin(zen)*numpy.sin(azim)
1417 m = numpy.sin(zen)*numpy.cos(azim)
1419 m = numpy.sin(zen)*numpy.cos(azim)
1418
1420
1419 A = numpy.vstack((l, m)).transpose()
1421 A = numpy.vstack((l, m)).transpose()
1420 A1 = numpy.dot(numpy.linalg.inv( numpy.dot(A.transpose(),A) ),A.transpose())
1422 A1 = numpy.dot(numpy.linalg.inv( numpy.dot(A.transpose(),A) ),A.transpose())
1421 windsAux = numpy.dot(A1, vel)
1423 windsAux = numpy.dot(A1, vel)
1422
1424
1423 winds[0,i] = windsAux[0]
1425 winds[0,i] = windsAux[0]
1424 winds[1,i] = windsAux[1]
1426 winds[1,i] = windsAux[1]
1425
1427
1426 return winds, heightPerI[:-1]
1428 return winds, heightPerI[:-1]
1427
1429
1428 def run(self, dataOut, technique, **kwargs):
1430 def run(self, dataOut, technique, **kwargs):
1429
1431
1430 param = dataOut.data_param
1432 param = dataOut.data_param
1431 if dataOut.abscissaRange != None:
1433 if dataOut.abscissaRange != None:
1432 absc = dataOut.abscissaRange[:-1]
1434 absc = dataOut.abscissaRange[:-1]
1433 noise = dataOut.noise
1435 noise = dataOut.noise
1434 heightRange = dataOut.getHeiRange()
1436 heightRange = dataOut.getHeiRange()
1435 SNR = dataOut.SNR
1437 SNR = dataOut.SNR
1436
1438
1437 if technique == 'DBS':
1439 if technique == 'DBS':
1438
1440
1439 if kwargs.has_key('dirCosx') and kwargs.has_key('dirCosy'):
1441 if kwargs.has_key('dirCosx') and kwargs.has_key('dirCosy'):
1440 theta_x = numpy.array(kwargs['dirCosx'])
1442 theta_x = numpy.array(kwargs['dirCosx'])
1441 theta_y = numpy.array(kwargs['dirCosy'])
1443 theta_y = numpy.array(kwargs['dirCosy'])
1442 else:
1444 else:
1443 elev = numpy.array(kwargs['elevation'])
1445 elev = numpy.array(kwargs['elevation'])
1444 azim = numpy.array(kwargs['azimuth'])
1446 azim = numpy.array(kwargs['azimuth'])
1445 theta_x, theta_y = self.__calculateCosDir(elev, azim)
1447 theta_x, theta_y = self.__calculateCosDir(elev, azim)
1446 azimuth = kwargs['correctAzimuth']
1448 azimuth = kwargs['correctAzimuth']
1447 if kwargs.has_key('horizontalOnly'):
1449 if kwargs.has_key('horizontalOnly'):
1448 horizontalOnly = kwargs['horizontalOnly']
1450 horizontalOnly = kwargs['horizontalOnly']
1449 else: horizontalOnly = False
1451 else: horizontalOnly = False
1450 if kwargs.has_key('correctFactor'):
1452 if kwargs.has_key('correctFactor'):
1451 correctFactor = kwargs['correctFactor']
1453 correctFactor = kwargs['correctFactor']
1452 else: correctFactor = 1
1454 else: correctFactor = 1
1453 if kwargs.has_key('channelList'):
1455 if kwargs.has_key('channelList'):
1454 channelList = kwargs['channelList']
1456 channelList = kwargs['channelList']
1455 if len(channelList) == 2:
1457 if len(channelList) == 2:
1456 horizontalOnly = True
1458 horizontalOnly = True
1457 arrayChannel = numpy.array(channelList)
1459 arrayChannel = numpy.array(channelList)
1458 param = param[arrayChannel,:,:]
1460 param = param[arrayChannel,:,:]
1459 theta_x = theta_x[arrayChannel]
1461 theta_x = theta_x[arrayChannel]
1460 theta_y = theta_y[arrayChannel]
1462 theta_y = theta_y[arrayChannel]
1461
1463
1462 velRadial0 = param[:,1,:] #Radial velocity
1464 velRadial0 = param[:,1,:] #Radial velocity
1463 dataOut.winds, dataOut.heightRange, dataOut.SNR = self.techniqueDBS(velRadial0, theta_x, theta_y, azimuth, correctFactor, horizontalOnly, heightRange, SNR) #DBS Function
1465 dataOut.winds, dataOut.heightRange, dataOut.SNR = self.techniqueDBS(velRadial0, theta_x, theta_y, azimuth, correctFactor, horizontalOnly, heightRange, SNR) #DBS Function
1464 dataOut.initUtcTime = dataOut.ltctime
1465 dataOut.windsInterval = dataOut.timeInterval
1466
1466
1467 elif technique == 'SA':
1467 elif technique == 'SA':
1468
1468
1469 #Parameters
1469 #Parameters
1470 position_x = kwargs['positionX']
1470 position_x = kwargs['positionX']
1471 position_y = kwargs['positionY']
1471 position_y = kwargs['positionY']
1472 azimuth = kwargs['azimuth']
1472 azimuth = kwargs['azimuth']
1473
1473
1474 if kwargs.has_key('crosspairsList'):
1474 if kwargs.has_key('crosspairsList'):
1475 pairs = kwargs['crosspairsList']
1475 pairs = kwargs['crosspairsList']
1476 else:
1476 else:
1477 pairs = None
1477 pairs = None
1478
1478
1479 if kwargs.has_key('correctFactor'):
1479 if kwargs.has_key('correctFactor'):
1480 correctFactor = kwargs['correctFactor']
1480 correctFactor = kwargs['correctFactor']
1481 else:
1481 else:
1482 correctFactor = 1
1482 correctFactor = 1
1483
1483
1484 tau = dataOut.data_param
1484 tau = dataOut.data_param
1485 _lambda = dataOut.C/dataOut.frequency
1485 _lambda = dataOut.C/dataOut.frequency
1486 pairsList = dataOut.pairsList
1486 pairsList = dataOut.pairsList
1487 nChannels = dataOut.nChannels
1487 nChannels = dataOut.nChannels
1488
1488
1489 dataOut.winds = self.techniqueSA(pairs, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, absc, correctFactor)
1489 dataOut.winds = self.techniqueSA(pairs, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, absc, correctFactor)
1490 dataOut.initUtcTime = dataOut.ltctime
1490 dataOut.initUtcTime = dataOut.ltctime
1491 dataOut.windsInterval = dataOut.timeInterval
1491 dataOut.windsInterval = dataOut.timeInterval
1492
1492
1493 elif technique == 'Meteors':
1493 elif technique == 'Meteors':
1494 dataOut.flagNoData = True
1494 dataOut.flagNoData = True
1495 self.__dataReady = False
1495 self.__dataReady = False
1496
1496
1497 if kwargs.has_key('nHours'):
1497 if kwargs.has_key('nHours'):
1498 nHours = kwargs['nHours']
1498 nHours = kwargs['nHours']
1499 else:
1499 else:
1500 nHours = 1
1500 nHours = 1
1501
1501
1502 if kwargs.has_key('meteorsPerBin'):
1502 if kwargs.has_key('meteorsPerBin'):
1503 meteorThresh = kwargs['meteorsPerBin']
1503 meteorThresh = kwargs['meteorsPerBin']
1504 else:
1504 else:
1505 meteorThresh = 6
1505 meteorThresh = 6
1506
1506
1507 if kwargs.has_key('hmin'):
1507 if kwargs.has_key('hmin'):
1508 hmin = kwargs['hmin']
1508 hmin = kwargs['hmin']
1509 else: hmin = 70
1509 else: hmin = 70
1510 if kwargs.has_key('hmax'):
1510 if kwargs.has_key('hmax'):
1511 hmax = kwargs['hmax']
1511 hmax = kwargs['hmax']
1512 else: hmax = 110
1512 else: hmax = 110
1513
1513
1514 dataOut.windsInterval = nHours*3600
1514 dataOut.windsInterval = nHours*3600
1515
1515
1516 if self.__isConfig == False:
1516 if self.__isConfig == False:
1517 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
1517 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
1518 #Get Initial LTC time
1518 #Get Initial LTC time
1519 self.__initime = (dataOut.datatime.replace(minute = 0, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
1519 self.__initime = (dataOut.datatime.replace(minute = 0, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
1520 self.__isConfig = True
1520 self.__isConfig = True
1521
1521
1522 if self.__buffer == None:
1522 if self.__buffer == None:
1523 self.__buffer = dataOut.data_param
1523 self.__buffer = dataOut.data_param
1524 self.__firstdata = copy.copy(dataOut)
1524 self.__firstdata = copy.copy(dataOut)
1525
1525
1526 else:
1526 else:
1527 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
1527 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
1528
1528
1529 self.__checkTime(dataOut.ltctime, dataOut.paramInterval, dataOut.windsInterval) #Check if the buffer is ready
1529 self.__checkTime(dataOut.ltctime, dataOut.paramInterval, dataOut.windsInterval) #Check if the buffer is ready
1530
1530
1531 if self.__dataReady:
1531 if self.__dataReady:
1532 dataOut.initUtcTime = self.__initime
1532 dataOut.initUtcTime = self.__initime
1533 self.__initime = self.__initime + dataOut.windsInterval #to erase time offset
1533 self.__initime = self.__initime + dataOut.windsInterval #to erase time offset
1534
1534
1535 dataOut.winds, dataOut.heightRange = self.techniqueMeteors(self.__buffer, meteorThresh, hmin, hmax)
1535 dataOut.winds, dataOut.heightRange = self.techniqueMeteors(self.__buffer, meteorThresh, hmin, hmax)
1536 dataOut.flagNoData = False
1536 dataOut.flagNoData = False
1537 self.__buffer = None
1537 self.__buffer = None
1538
1538
1539 return No newline at end of file
1539 return
@@ -1,144 +1,155
1 # DIAS 19 Y 20 FEB 2014
1 # DIAS 19 Y 20 FEB 2014
2 # Comprobacion de Resultados DBS con SA
2 # Comprobacion de Resultados DBS con SA
3
3
4 import os, sys
4 import os, sys
5
5
6 path = os.path.split(os.getcwd())[0]
6 path = os.path.split(os.getcwd())[0]
7 sys.path.append(path)
7 sys.path.append(path)
8
8
9 from controller import *
9 from controller import *
10
10
11 desc = "DBS Experiment Test"
11 desc = "DBS Experiment Test"
12 filename = "DBStest.xml"
12 filename = "DBStest.xml"
13
13
14 controllerObj = Project()
14 controllerObj = Project()
15
15
16 controllerObj.setup(id = '191', name='test01', description=desc)
16 controllerObj.setup(id = '191', name='test01', description=desc)
17
17
18 #Experimentos
18 #Experimentos
19
19
20 #2014050 19 Feb 2014
20 #2014050 19 Feb 2014
21 # path = '/home/soporte/Documents/MST_Data/DBS/d2014050'
21 # path = '/home/soporte/Documents/MST_Data/DBS/d2014050'
22 # pathFigure = '/home/soporte/workspace/Graficos/DBS/d2014050p/'
22 # pathFigure = '/home/soporte/workspace/Graficos/DBS/d2014050p/'
23 # xmin = '15.5'
23 # xmin = '15.5'
24 # xmax = '23.99999999'
24 # xmax = '23.99999999'
25 # startTime = '17:25:00'
25 # startTime = '17:25:00'
26 # filehdf5 = "DBS_2014050.hdf5"
26 # filehdf5 = "DBS_2014050.hdf5"
27
27
28 #2014051 20 Feb 2014
28 #2014051 20 Feb 2014
29 path = '/home/soporte/Data/MST/DBS/d2014051'
29 path = '/home/soporte/Data/MST/DBS/d2014051'
30 pathFigure = '/home/soporte/workspace/Graficos/DBS/prueba1/'
30 pathFigure = '/home/soporte/workspace/Graficos/DBS/prueba1/'
31 xmin = '0.0'
31 xmin = '0'
32 xmax = '8.0'
32 xmax = '7.5'
33 startTime = '00:00:00'
33 startTime = '00:00:00'
34 filehdf5 = "DBS_2014051.hdf5"
34 filehdf5 = "DBS_2014051.hdf5"
35
35
36
36
37
37
38 #------------------------------------------------------------------------------------------------
38 #------------------------------------------------------------------------------------------------
39 readUnitConfObj = controllerObj.addReadUnit(datatype='VoltageReader',
39 readUnitConfObj = controllerObj.addReadUnit(datatype='VoltageReader',
40 path=path,
40 path=path,
41 startDate='2014/01/31',
41 startDate='2014/01/31',
42 endDate='2014/03/31',
42 endDate='2014/03/31',
43 startTime=startTime,
43 startTime=startTime,
44 endTime='23:59:59',
44 endTime='23:59:59',
45 online=0,
45 online=0,
46 delay=5,
46 delay=5,
47 walk=0)
47 walk=0)
48
48
49 opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock')
49 opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock')
50
50
51
51
52 #--------------------------------------------------------------------------------------------------
52 #--------------------------------------------------------------------------------------------------
53
53
54 procUnitConfObj0 = controllerObj.addProcUnit(datatype='VoltageProc', inputId=readUnitConfObj.getId())
54 procUnitConfObj0 = controllerObj.addProcUnit(datatype='VoltageProc', inputId=readUnitConfObj.getId())
55
55
56 opObj11 = procUnitConfObj0.addOperation(name='Decoder', optype='other')
56 opObj11 = procUnitConfObj0.addOperation(name='Decoder', optype='other')
57
57
58 opObj11 = procUnitConfObj0.addOperation(name='CohInt', optype='other')
58 opObj11 = procUnitConfObj0.addOperation(name='CohInt', optype='other')
59 opObj11.addParameter(name='n', value='256', format='int')
59 opObj11.addParameter(name='n', value='256', format='int')
60 # opObj11.addParameter(name='n', value='16', format='int')
60 # opObj11.addParameter(name='n', value='16', format='int')
61
61
62 opObj11 = procUnitConfObj0.addOperation(name='selectHeightsByIndex')
62 opObj11 = procUnitConfObj0.addOperation(name='selectHeightsByIndex')
63 opObj11.addParameter(name='minIndex', value='10', format='float')
63 opObj11.addParameter(name='minIndex', value='10', format='float')
64 opObj11.addParameter(name='maxIndex', value='60', format='float')
64 opObj11.addParameter(name='maxIndex', value='60', format='float')
65
65
66 #---------------------------------------------------------------------------------------------------
66 #---------------------------------------------------------------------------------------------------
67
67
68 procUnitConfObj1 = controllerObj.addProcUnit(datatype='SpectraProc', inputId=procUnitConfObj0.getId())
68 procUnitConfObj1 = controllerObj.addProcUnit(datatype='SpectraProc', inputId=procUnitConfObj0.getId())
69 procUnitConfObj1.addParameter(name='nFFTPoints', value='64', format='int')
69 procUnitConfObj1.addParameter(name='nFFTPoints', value='64', format='int')
70 procUnitConfObj1.addParameter(name='nProfiles', value='64', format='int')
70 procUnitConfObj1.addParameter(name='nProfiles', value='64', format='int')
71 # procUnitConfObj1.addParameter(name='ippFactor', value='2', 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')
72 procUnitConfObj1.addParameter(name='pairsList', value='(0,0),(0,1),(2,1)', format='pairsList')
73
73
74 opObj11 = procUnitConfObj1.addOperation(name='IncohInt', optype='other')
74 opObj11 = procUnitConfObj1.addOperation(name='IncohInt', optype='other')
75 opObj11.addParameter(name='n', value='5', format='int')
75 opObj11.addParameter(name='n', value='5', format='int')
76
76
77 opObj14 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other')
77 opObj14 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other')
78 opObj14.addParameter(name='id', value='1', format='int')
78 opObj14.addParameter(name='id', value='1', format='int')
79 opObj14.addParameter(name='wintitle', value='Con interf', format='str')
79 opObj14.addParameter(name='wintitle', value='Con interf', format='str')
80 opObj14.addParameter(name='save', value='1', format='bool')
80 opObj14.addParameter(name='save', value='1', format='bool')
81 opObj14.addParameter(name='figpath', value=pathFigure, format='str')
81 opObj14.addParameter(name='figpath', value=pathFigure, format='str')
82 opObj14.addParameter(name='zmin', value='5', format='int')
82 opObj14.addParameter(name='zmin', value='5', format='int')
83 opObj14.addParameter(name='zmax', value='90', format='int')
83 opObj14.addParameter(name='zmax', value='90', format='int')
84
84
85 opObj12 = procUnitConfObj1.addOperation(name='removeInterference')
85 opObj12 = procUnitConfObj1.addOperation(name='removeInterference')
86 opObj13 = procUnitConfObj1.addOperation(name='removeDC')
86 opObj13 = procUnitConfObj1.addOperation(name='removeDC')
87 opObj13.addParameter(name='mode', value='1', format='int')
87 opObj13.addParameter(name='mode', value='1', format='int')
88
88
89 opObj12 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other')
89 opObj12 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other')
90 opObj12.addParameter(name='id', value='2', format='int')
90 opObj12.addParameter(name='id', value='2', format='int')
91 opObj12.addParameter(name='wintitle', value='RTI Plot', format='str')
91 opObj12.addParameter(name='wintitle', value='RTI Plot', format='str')
92 opObj12.addParameter(name='save', value='1', format='bool')
92 opObj12.addParameter(name='save', value='1', format='bool')
93 opObj12.addParameter(name='figpath', value = pathFigure, format='str')
93 opObj12.addParameter(name='figpath', value = pathFigure, format='str')
94 opObj12.addParameter(name='xmin', value=xmin, format='float')
94 opObj12.addParameter(name='xmin', value=xmin, format='float')
95 opObj12.addParameter(name='xmax', value=xmax, format='float')
95 opObj12.addParameter(name='xmax', value=xmax, format='float')
96 opObj12.addParameter(name='zmin', value='5', format='int')
96 opObj12.addParameter(name='zmin', value='5', format='int')
97 opObj12.addParameter(name='zmax', value='90', format='int')
97 opObj12.addParameter(name='zmax', value='90', format='int')
98
98
99 #--------------------------------------------------------------------------------------------------
99 #--------------------------------------------------------------------------------------------------
100
100
101 procUnitConfObj2 = controllerObj.addProcUnit(datatype='ParametersProc', inputId=procUnitConfObj1.getId())
101 procUnitConfObj2 = controllerObj.addProcUnit(datatype='ParametersProc', inputId=procUnitConfObj1.getId())
102 opObj20 = procUnitConfObj2.addOperation(name='GetMoments')
102 opObj20 = procUnitConfObj2.addOperation(name='GetMoments')
103
103
104 opObj21 = procUnitConfObj2.addOperation(name='MomentsPlot', optype='other')
104 opObj21 = procUnitConfObj2.addOperation(name='MomentsPlot', optype='other')
105 opObj21.addParameter(name='id', value='3', format='int')
105 opObj21.addParameter(name='id', value='3', format='int')
106 opObj21.addParameter(name='wintitle', value='Moments Plot', format='str')
106 opObj21.addParameter(name='wintitle', value='Moments Plot', format='str')
107 opObj21.addParameter(name='save', value='1', format='bool')
107 opObj21.addParameter(name='save', value='1', format='bool')
108 opObj21.addParameter(name='figpath', value=pathFigure, format='str')
108 opObj21.addParameter(name='figpath', value=pathFigure, format='str')
109 opObj21.addParameter(name='zmin', value='5', format='int')
109 opObj21.addParameter(name='zmin', value='5', format='int')
110 opObj21.addParameter(name='zmax', value='90', format='int')
110 opObj21.addParameter(name='zmax', value='90', format='int')
111
112 opObj21 = procUnitConfObj2.addOperation(name='RadialVelocityPlot', optype='other')
113 opObj21.addParameter(name='id', value='5', format='int')
114 opObj21.addParameter(name='wintitle', value='Radial Velocity Plot', format='str')
115 opObj21.addParameter(name='save', value='1', format='bool')
116 opObj21.addParameter(name='figpath', value=pathFigure, format='str')
117 opObj21.addParameter(name='SNRmin', value='-10', format='int')
118 opObj21.addParameter(name='SNRmax', value='60', format='int')
119 opObj21.addParameter(name='SNRthresh', value='0', format='float')
120 opObj21.addParameter(name='xmin', value=xmin, format='float')
121 opObj21.addParameter(name='xmax', value=xmax, format='float')
111
122
112 opObj22 = procUnitConfObj2.addOperation(name='WindProfiler', optype='other')
123 opObj22 = procUnitConfObj2.addOperation(name='WindProfiler', optype='other')
113 opObj22.addParameter(name='technique', value='DBS', format='str')
124 opObj22.addParameter(name='technique', value='DBS', format='str')
114 opObj22.addParameter(name='correctAzimuth', value='51.06', format='float')
125 opObj22.addParameter(name='correctAzimuth', value='51.06', format='float')
115 opObj22.addParameter(name='correctFactor', value='-1', format='float')
126 opObj22.addParameter(name='correctFactor', value='-1', format='float')
116 opObj22.addParameter(name='dirCosx', value='0.041016, 0, -0.054688', format='floatlist')
127 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')
128 opObj22.addParameter(name='dirCosy', value='-0.041016, 0.025391, -0.023438', format='floatlist')
118 # opObj22.addParameter(name='horizontalOnly', value='1', format='bool')
129 # opObj22.addParameter(name='horizontalOnly', value='1', format='bool')
119 # opObj22.addParameter(name='channelList', value='1,2', format='intlist')
130 # opObj22.addParameter(name='channelList', value='1,2', format='intlist')
120
131
121 opObj23 = procUnitConfObj2.addOperation(name='WindProfilerPlot', optype='other')
132 opObj23 = procUnitConfObj2.addOperation(name='WindProfilerPlot', optype='other')
122 opObj23.addParameter(name='id', value='4', format='int')
133 opObj23.addParameter(name='id', value='4', format='int')
123 opObj23.addParameter(name='wintitle', value='Wind Profiler', format='str')
134 opObj23.addParameter(name='wintitle', value='Wind Profiler', format='str')
124 opObj23.addParameter(name='save', value='1', format='bool')
135 opObj23.addParameter(name='save', value='1', format='bool')
125 opObj23.addParameter(name='figpath', value = pathFigure, format='str')
136 opObj23.addParameter(name='figpath', value = pathFigure, format='str')
126 opObj23.addParameter(name='zmin', value='-10', format='int')
137 opObj23.addParameter(name='zmin', value='-10', format='int')
127 opObj23.addParameter(name='zmax', value='10', format='int')
138 opObj23.addParameter(name='zmax', value='10', format='int')
128 opObj23.addParameter(name='zmin_ver', value='-80', format='float')
139 opObj23.addParameter(name='zmin_ver', value='-80', format='float')
129 opObj23.addParameter(name='zmax_ver', value='80', format='float')
140 opObj23.addParameter(name='zmax_ver', value='80', format='float')
130 opObj23.addParameter(name='SNRmin', value='-10', format='int')
141 opObj23.addParameter(name='SNRmin', value='-10', format='int')
131 opObj23.addParameter(name='SNRmax', value='60', format='int')
142 opObj23.addParameter(name='SNRmax', value='60', format='int')
132 opObj23.addParameter(name='SNRthresh', value='0', format='float')
143 opObj23.addParameter(name='SNRthresh', value='0', format='float')
133 opObj23.addParameter(name='xmin', value=xmin, format='float')
144 opObj23.addParameter(name='xmin', value=xmin, format='float')
134 opObj23.addParameter(name='xmax', value=xmax, format='float')
145 opObj23.addParameter(name='xmax', value=xmax, format='float')
135
146
136 #--------------------------------------------------------------------------------------------------
147 #--------------------------------------------------------------------------------------------------
137 print "Escribiendo el archivo XML"
148 print "Escribiendo el archivo XML"
138 controllerObj.writeXml(filename)
149 controllerObj.writeXml(filename)
139 print "Leyendo el archivo XML"
150 print "Leyendo el archivo XML"
140 controllerObj.readXml(filename)
151 controllerObj.readXml(filename)
141
152
142 controllerObj.createObjects()
153 controllerObj.createObjects()
143 controllerObj.connectObjects()
154 controllerObj.connectObjects()
144 controllerObj.run() No newline at end of file
155 controllerObj.run()
@@ -1,139 +1,139
1 # DIAS 19 Y 20 FEB 2014
1 # DIAS 19 Y 20 FEB 2014
2 # Comprobacion de Resultados DBS con SA
2 # Comprobacion de Resultados DBS con SA
3
3
4 import os, sys
4 import os, sys
5
5
6 path = os.path.split(os.getcwd())[0]
6 path = os.path.split(os.getcwd())[0]
7 sys.path.append(path)
7 sys.path.append(path)
8
8
9 from controller import *
9 from controller import *
10
10
11 desc = "SA Experiment Test"
11 desc = "SA Experiment Test"
12 filename = "SA2014050.xml"
12 filename = "SA2014050.xml"
13
13
14 controllerObj = Project()
14 controllerObj = Project()
15
15
16 controllerObj.setup(id = '191', name='test01', description=desc)
16 controllerObj.setup(id = '191', name='test01', description=desc)
17
17
18
18
19 #Experimentos
19 #Experimentos
20
20
21 #2014050 19 Feb 2014
21 #2014050 19 Feb 2014
22 # path = '/home/soporte/Documents/MST_Data/SA/d2014050'
22 path = '/home/soporte/Data/MST/SA/d2014050'
23 # pathFigure = '/home/soporte/workspace/Graficos/SA/d2014050_prueba/'
23 pathFigure = '/home/soporte/workspace/Graficos/SA/new1/'
24 # xmin = '15.5'
24 xmin = '15.5'
25 # xmax = '23.99999999'
25 xmax = '24'
26 # startTime = '15:30:00'
26 startTime = '15:30:00'
27 # filehdf5 = "SA_2014050.hdf5"
27 filehdf5 = "SA_2014050.hdf5"
28
28
29 #2014051 20 Feb 2014
29 #2014051 20 Feb 2014
30 path = '/home/soporte/Data/MST/SA/d2014051'
30 # path = '/home/soporte/Data/MST/SA/d2014051'
31 pathFigure = '/home/soporte/workspace/Graficos/SA/prueba1/'
31 # pathFigure = '/home/soporte/workspace/Graficos/SA/new/'
32 xmin = '0.0'
32 # xmin = '0.0'
33 xmax = '8.0'
33 # xmax = '8.0'
34 startTime = '06:00:00'
34 # startTime = '00:00:00'
35 filehdf5 = "SA_2014051.hdf5"
35 # filehdf5 = "SA_2014051.hdf5"
36
36
37 readUnitConfObj = controllerObj.addReadUnit(datatype='VoltageReader',
37 readUnitConfObj = controllerObj.addReadUnit(datatype='VoltageReader',
38 path=path,
38 path=path,
39 startDate='2014/01/01',
39 startDate='2014/01/01',
40 endDate='2014/03/31',
40 endDate='2014/03/31',
41 startTime=startTime,
41 startTime=startTime,
42 endTime='23:59:59',
42 endTime='23:59:59',
43 online=0,
43 online=0,
44 delay=5,
44 delay=5,
45 walk=0)
45 walk=0)
46
46
47 opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock')
47 opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock')
48
48
49
49
50 #--------------------------------------------------------------------------------------------------
50 #--------------------------------------------------------------------------------------------------
51
51
52 procUnitConfObj0 = controllerObj.addProcUnit(datatype='VoltageProc', inputId=readUnitConfObj.getId())
52 procUnitConfObj0 = controllerObj.addProcUnit(datatype='VoltageProc', inputId=readUnitConfObj.getId())
53
53
54 opObj11 = procUnitConfObj0.addOperation(name='Decoder', optype='other')
54 opObj11 = procUnitConfObj0.addOperation(name='Decoder', optype='other')
55
55
56 opObj11 = procUnitConfObj0.addOperation(name='CohInt', optype='other')
56 opObj11 = procUnitConfObj0.addOperation(name='CohInt', optype='other')
57 opObj11.addParameter(name='n', value='600', format='int')
57 opObj11.addParameter(name='n', value='600', format='int')
58 # opObj11.addParameter(name='n', value='10', format='int')
58 # opObj11.addParameter(name='n', value='10', format='int')
59
59
60 opObj11 = procUnitConfObj0.addOperation(name='selectHeightsByIndex')
60 opObj11 = procUnitConfObj0.addOperation(name='selectHeightsByIndex')
61 opObj11.addParameter(name='minIndex', value='10', format='float')
61 opObj11.addParameter(name='minIndex', value='10', format='float')
62 opObj11.addParameter(name='maxIndex', value='60', format='float')
62 opObj11.addParameter(name='maxIndex', value='60', format='float')
63 #---------------------------------------------------------------------------------------------------
63 #---------------------------------------------------------------------------------------------------
64 procUnitConfObj1 = controllerObj.addProcUnit(datatype='CorrelationProc', inputId=procUnitConfObj0.getId())
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')
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')
66 procUnitConfObj1.addParameter(name='pairsList', value='(0,0),(1,1),(2,2),(3,3),(0,3),(0,2),(1,3),(1,2),(0,1),(2,3)', format='pairsList')
67 procUnitConfObj1.addParameter(name='fullT', value='1', format='bool')
67 procUnitConfObj1.addParameter(name='fullT', value='1', format='bool')
68 procUnitConfObj1.addParameter(name='removeDC', 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')
69 #procUnitConfObj1.addParameter(name='lagT', value='0,1,2,3', format='intlist')
70
70
71 opObj12 = procUnitConfObj1.addOperation(name='CorrelationPlot', optype='other')
71 opObj12 = procUnitConfObj1.addOperation(name='CorrelationPlot', optype='other')
72 opObj12.addParameter(name='id', value='1', format='int')
72 opObj12.addParameter(name='id', value='1', format='int')
73 opObj12.addParameter(name='wintitle', value='CrossCorrelation Plot', format='str')
73 opObj12.addParameter(name='wintitle', value='CrossCorrelation Plot', format='str')
74 opObj12.addParameter(name='save', value='1', format='bool')
74 opObj12.addParameter(name='save', value='1', format='bool')
75 opObj12.addParameter(name='zmin', value='0', format='int')
75 opObj12.addParameter(name='zmin', value='0', format='int')
76 opObj12.addParameter(name='zmax', value='1', format='int')
76 opObj12.addParameter(name='zmax', value='1', format='int')
77 opObj12.addParameter(name='figpath', value = pathFigure, format='str')
77 opObj12.addParameter(name='figpath', value = pathFigure, format='str')
78
78
79 opObj12 = procUnitConfObj1.addOperation(name='removeNoise')
79 opObj12 = procUnitConfObj1.addOperation(name='removeNoise')
80 opObj12.addParameter(name='mode', value='2', format='int')
80 opObj12.addParameter(name='mode', value='2', format='int')
81 opObj12 = procUnitConfObj1.addOperation(name='calculateNormFactor')
81 opObj12 = procUnitConfObj1.addOperation(name='calculateNormFactor')
82
82
83 opObj12 = procUnitConfObj1.addOperation(name='CorrelationPlot', optype='other')
83 opObj12 = procUnitConfObj1.addOperation(name='CorrelationPlot', optype='other')
84 opObj12.addParameter(name='id', value='2', format='int')
84 opObj12.addParameter(name='id', value='2', format='int')
85 opObj12.addParameter(name='wintitle', value='CrossCorrelation Plot', format='str')
85 opObj12.addParameter(name='wintitle', value='CrossCorrelation Plot', format='str')
86 opObj12.addParameter(name='save', value='1', format='bool')
86 opObj12.addParameter(name='save', value='1', format='bool')
87 opObj12.addParameter(name='zmin', value='0', format='int')
87 opObj12.addParameter(name='zmin', value='0', format='int')
88 opObj12.addParameter(name='zmax', value='1', format='int')
88 opObj12.addParameter(name='zmax', value='1', format='int')
89 opObj12.addParameter(name='figpath', value = pathFigure, format='str')
89 opObj12.addParameter(name='figpath', value = pathFigure, format='str')
90
90
91 #---------------------------------------------------------------------------------------------------
91 #---------------------------------------------------------------------------------------------------
92 procUnitConfObj2 = controllerObj.addProcUnit(datatype='ParametersProc', inputId=procUnitConfObj1.getId())
92 procUnitConfObj2 = controllerObj.addProcUnit(datatype='ParametersProc', inputId=procUnitConfObj1.getId())
93 opObj20 = procUnitConfObj2.addOperation(name='GetLags')
93 opObj20 = procUnitConfObj2.addOperation(name='GetLags')
94
94
95 opObj21 = procUnitConfObj2.addOperation(name='WindProfiler', optype='other')
95 opObj21 = procUnitConfObj2.addOperation(name='WindProfiler', optype='other')
96 opObj21.addParameter(name='technique', value='SA', format='str')
96 opObj21.addParameter(name='technique', value='SA', format='str')
97 # opObj21.addParameter(name='correctFactor', value='-1', format='float')
97 # opObj21.addParameter(name='correctFactor', value='-1', format='float')
98 opObj21.addParameter(name='positionX', value='36,0,36,0', format='floatlist')
98 opObj21.addParameter(name='positionX', value='36,0,36,0', format='floatlist')
99 opObj21.addParameter(name='positionY', value='36,0,0,36', format='floatlist')
99 opObj21.addParameter(name='positionY', value='36,0,0,36', format='floatlist')
100 opObj21.addParameter(name='azimuth', value='51.06', format='float')
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
101 opObj21.addParameter(name='crosspairsList', value='(0,3),(0,2),(1,3),(1,2),(0,1),(2,3)', format='pairsList')#COrregir
102 #
102 #
103 opObj22 = procUnitConfObj2.addOperation(name='WindProfilerPlot', optype='other')
103 opObj22 = procUnitConfObj2.addOperation(name='WindProfilerPlot', optype='other')
104 opObj22.addParameter(name='id', value='4', format='int')
104 opObj22.addParameter(name='id', value='4', format='int')
105 opObj22.addParameter(name='wintitle', value='Wind Profiler', format='str')
105 opObj22.addParameter(name='wintitle', value='Wind Profiler', format='str')
106 opObj22.addParameter(name='save', value='1', format='bool')
106 opObj22.addParameter(name='save', value='1', format='bool')
107 opObj22.addParameter(name='figpath', value = pathFigure, format='str')
107 opObj22.addParameter(name='figpath', value = pathFigure, format='str')
108 opObj22.addParameter(name='zmin', value='-15', format='int')
108 opObj22.addParameter(name='zmin', value='-15', format='int')
109 opObj22.addParameter(name='zmax', value='15', format='int')
109 opObj22.addParameter(name='zmax', value='15', format='int')
110 opObj22.addParameter(name='zmin_ver', value='-80', format='float')
110 opObj22.addParameter(name='zmin_ver', value='-80', format='float')
111 opObj22.addParameter(name='zmax_ver', value='80', format='float')
111 opObj22.addParameter(name='zmax_ver', value='80', format='float')
112 opObj22.addParameter(name='SNRmin', value='-20', format='int')
112 opObj22.addParameter(name='SNRmin', value='-20', format='int')
113 opObj22.addParameter(name='SNRmax', value='40', format='int')
113 opObj22.addParameter(name='SNRmax', value='40', format='int')
114 opObj22.addParameter(name='SNRthresh', value='-3.5', format='float')
114 opObj22.addParameter(name='SNRthresh', value='-3.5', format='float')
115 opObj22.addParameter(name='xmin', value=xmin, format='float')
115 opObj22.addParameter(name='xmin', value=xmin, format='float')
116 opObj22.addParameter(name='xmax', value=xmax, format='float')
116 opObj22.addParameter(name='xmax', value=xmax, format='float')
117 # #-----------------------------------------------------------------------------------
117 # #-----------------------------------------------------------------------------------
118 #
118 #
119 # procUnitConfObj2 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId())
119 # procUnitConfObj2 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId())
120 # procUnitConfObj2.addParameter(name='nFFTPoints', value='128', format='int')
120 # procUnitConfObj2.addParameter(name='nFFTPoints', value='128', format='int')
121 # procUnitConfObj2.addParameter(name='nProfiles', 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')
122 # procUnitConfObj2.addParameter(name='pairsList', value='(0,0),(0,1),(2,1)', format='pairsList')
123 #
123 #
124 # opObj22 = procUnitConfObj2.addOperation(name='SpectraPlot', optype='other')
124 # opObj22 = procUnitConfObj2.addOperation(name='SpectraPlot', optype='other')
125 # opObj22.addParameter(name='id', value='5', format='int')
125 # opObj22.addParameter(name='id', value='5', format='int')
126 # opObj22.addParameter(name='wintitle', value='Spectra Plot', format='str')
126 # opObj22.addParameter(name='wintitle', value='Spectra Plot', format='str')
127 # opObj22.addParameter(name='save', value='1', format='bool')
127 # opObj22.addParameter(name='save', value='1', format='bool')
128 # opObj22.addParameter(name='figpath', value = pathFigure, format='str')
128 # opObj22.addParameter(name='figpath', value = pathFigure, format='str')
129
129
130 #-----------------------------------------------------------------------------------
130 #-----------------------------------------------------------------------------------
131
131
132 print "Escribiendo el archivo XML"
132 print "Escribiendo el archivo XML"
133 controllerObj.writeXml(filename)
133 controllerObj.writeXml(filename)
134 print "Leyendo el archivo XML"
134 print "Leyendo el archivo XML"
135 controllerObj.readXml(filename)
135 controllerObj.readXml(filename)
136
136
137 controllerObj.createObjects()
137 controllerObj.createObjects()
138 controllerObj.connectObjects()
138 controllerObj.connectObjects()
139 controllerObj.run() No newline at end of file
139 controllerObj.run()
General Comments 0
You need to be logged in to leave comments. Login now