##// END OF EJS Templates
15/3/18
ebocanegra -
r1149:c513dba92d21
parent child
Show More
@@ -1,2160 +1,2161
1 import os
1 import os
2 import datetime
2 import datetime
3 import numpy
3 import numpy
4 import inspect
4 import inspect
5 from figure import Figure, isRealtime, isTimeInHourRange
5 from figure import Figure, isRealtime, isTimeInHourRange
6 from plotting_codes import *
6 from plotting_codes import *
7
7
8
8
9 class SpcParamPlot(Figure):
9 class SpcParamPlot(Figure):
10
10
11 isConfig = None
11 isConfig = None
12 __nsubplots = None
12 __nsubplots = None
13
13
14 WIDTHPROF = None
14 WIDTHPROF = None
15 HEIGHTPROF = None
15 HEIGHTPROF = None
16 PREFIX = 'SpcParam'
16 PREFIX = 'SpcParam'
17
17
18 def __init__(self, **kwargs):
18 def __init__(self, **kwargs):
19 Figure.__init__(self, **kwargs)
19 Figure.__init__(self, **kwargs)
20 self.isConfig = False
20 self.isConfig = False
21 self.__nsubplots = 1
21 self.__nsubplots = 1
22
22
23 self.WIDTH = 250
23 self.WIDTH = 250
24 self.HEIGHT = 250
24 self.HEIGHT = 250
25 self.WIDTHPROF = 120
25 self.WIDTHPROF = 120
26 self.HEIGHTPROF = 0
26 self.HEIGHTPROF = 0
27 self.counter_imagwr = 0
27 self.counter_imagwr = 0
28
28
29 self.PLOT_CODE = SPEC_CODE
29 self.PLOT_CODE = SPEC_CODE
30
30
31 self.FTP_WEI = None
31 self.FTP_WEI = None
32 self.EXP_CODE = None
32 self.EXP_CODE = None
33 self.SUB_EXP_CODE = None
33 self.SUB_EXP_CODE = None
34 self.PLOT_POS = None
34 self.PLOT_POS = None
35
35
36 self.__xfilter_ena = False
36 self.__xfilter_ena = False
37 self.__yfilter_ena = False
37 self.__yfilter_ena = False
38
38
39 def getSubplots(self):
39 def getSubplots(self):
40
40
41 ncol = int(numpy.sqrt(self.nplots)+0.9)
41 ncol = int(numpy.sqrt(self.nplots)+0.9)
42 nrow = int(self.nplots*1./ncol + 0.9)
42 nrow = int(self.nplots*1./ncol + 0.9)
43
43
44 return nrow, ncol
44 return nrow, ncol
45
45
46 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
46 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
47
47
48 self.__showprofile = showprofile
48 self.__showprofile = showprofile
49 self.nplots = nplots
49 self.nplots = nplots
50
50
51 ncolspan = 1
51 ncolspan = 1
52 colspan = 1
52 colspan = 1
53 if showprofile:
53 if showprofile:
54 ncolspan = 3
54 ncolspan = 3
55 colspan = 2
55 colspan = 2
56 self.__nsubplots = 2
56 self.__nsubplots = 2
57
57
58 self.createFigure(id = id,
58 self.createFigure(id = id,
59 wintitle = wintitle,
59 wintitle = wintitle,
60 widthplot = self.WIDTH + self.WIDTHPROF,
60 widthplot = self.WIDTH + self.WIDTHPROF,
61 heightplot = self.HEIGHT + self.HEIGHTPROF,
61 heightplot = self.HEIGHT + self.HEIGHTPROF,
62 show=show)
62 show=show)
63
63
64 nrow, ncol = self.getSubplots()
64 nrow, ncol = self.getSubplots()
65
65
66 counter = 0
66 counter = 0
67 for y in range(nrow):
67 for y in range(nrow):
68 for x in range(ncol):
68 for x in range(ncol):
69
69
70 if counter >= self.nplots:
70 if counter >= self.nplots:
71 break
71 break
72
72
73 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
73 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
74
74
75 if showprofile:
75 if showprofile:
76 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
76 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
77
77
78 counter += 1
78 counter += 1
79
79
80 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
80 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
81 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
81 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
82 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
82 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
83 server=None, folder=None, username=None, password=None,
83 server=None, folder=None, username=None, password=None,
84 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
84 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
85 xaxis="frequency", colormap='jet', normFactor=None , Selector = 0):
85 xaxis="frequency", colormap='jet', normFactor=None , Selector = 0):
86
86
87 """
87 """
88
88
89 Input:
89 Input:
90 dataOut :
90 dataOut :
91 id :
91 id :
92 wintitle :
92 wintitle :
93 channelList :
93 channelList :
94 showProfile :
94 showProfile :
95 xmin : None,
95 xmin : None,
96 xmax : None,
96 xmax : None,
97 ymin : None,
97 ymin : None,
98 ymax : None,
98 ymax : None,
99 zmin : None,
99 zmin : None,
100 zmax : None
100 zmax : None
101 """
101 """
102 if realtime:
102 if realtime:
103 if not(isRealtime(utcdatatime = dataOut.utctime)):
103 if not(isRealtime(utcdatatime = dataOut.utctime)):
104 print 'Skipping this plot function'
104 print 'Skipping this plot function'
105 return
105 return
106
106
107 if channelList == None:
107 if channelList == None:
108 channelIndexList = dataOut.channelIndexList
108 channelIndexList = dataOut.channelIndexList
109 else:
109 else:
110 channelIndexList = []
110 channelIndexList = []
111 for channel in channelList:
111 for channel in channelList:
112 if channel not in dataOut.channelList:
112 if channel not in dataOut.channelList:
113 raise ValueError, "Channel %d is not in dataOut.channelList" %channel
113 raise ValueError, "Channel %d is not in dataOut.channelList" %channel
114 channelIndexList.append(dataOut.channelList.index(channel))
114 channelIndexList.append(dataOut.channelList.index(channel))
115
115
116 # if normFactor is None:
116 # if normFactor is None:
117 # factor = dataOut.normFactor
117 # factor = dataOut.normFactor
118 # else:
118 # else:
119 # factor = normFactor
119 # factor = normFactor
120 if xaxis == "frequency":
120 if xaxis == "frequency":
121 x = dataOut.spcparam_range[0]
121 x = dataOut.spcparam_range[0]
122 xlabel = "Frequency (kHz)"
122 xlabel = "Frequency (kHz)"
123
123
124 elif xaxis == "time":
124 elif xaxis == "time":
125 x = dataOut.spcparam_range[1]
125 x = dataOut.spcparam_range[1]
126 xlabel = "Time (ms)"
126 xlabel = "Time (ms)"
127
127
128 else:
128 else:
129 x = dataOut.spcparam_range[2]
129 x = dataOut.spcparam_range[2]
130 xlabel = "Velocity (m/s)"
130 xlabel = "Velocity (m/s)"
131 print "Vmax=",x[-1]
131
132
132 ylabel = "Range (Km)"
133 ylabel = "Range (Km)"
133
134
134 y = dataOut.getHeiRange()
135 y = dataOut.getHeiRange()
135
136
136 z = dataOut.SPCparam[Selector] #GauSelector] #dataOut.data_spc/factor
137 z = dataOut.SPCparam[Selector] /1966080.0#/ dataOut.normFactor#GauSelector] #dataOut.data_spc/factor
137 #print 'GausSPC', z[0,32,10:40]
138 #print 'GausSPC', z[0,32,10:40]
138 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
139 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
139 zdB = 10*numpy.log10(z)
140 zdB = 10*numpy.log10(z)
140
141
141 avg = numpy.average(z, axis=1)
142 avg = numpy.average(z, axis=1)
142 avgdB = 10*numpy.log10(avg)
143 avgdB = 10*numpy.log10(avg)
143
144
144 noise = dataOut.spc_noise
145 noise = dataOut.spc_noise
145 noisedB = 10*numpy.log10(noise)
146 noisedB = 10*numpy.log10(noise)
146
147
147 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
148 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
148 title = wintitle + " Spectra"
149 title = wintitle + " Spectra"
149 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
150 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
150 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
151 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
151
152
152 if not self.isConfig:
153 if not self.isConfig:
153
154
154 nplots = len(channelIndexList)
155 nplots = len(channelIndexList)
155
156
156 self.setup(id=id,
157 self.setup(id=id,
157 nplots=nplots,
158 nplots=nplots,
158 wintitle=wintitle,
159 wintitle=wintitle,
159 showprofile=showprofile,
160 showprofile=showprofile,
160 show=show)
161 show=show)
161
162
162 if xmin == None: xmin = numpy.nanmin(x)
163 if xmin == None: xmin = numpy.nanmin(x)
163 if xmax == None: xmax = numpy.nanmax(x)
164 if xmax == None: xmax = numpy.nanmax(x)
164 if ymin == None: ymin = numpy.nanmin(y)
165 if ymin == None: ymin = numpy.nanmin(y)
165 if ymax == None: ymax = numpy.nanmax(y)
166 if ymax == None: ymax = numpy.nanmax(y)
166 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
167 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
167 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
168 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
168
169
169 self.FTP_WEI = ftp_wei
170 self.FTP_WEI = ftp_wei
170 self.EXP_CODE = exp_code
171 self.EXP_CODE = exp_code
171 self.SUB_EXP_CODE = sub_exp_code
172 self.SUB_EXP_CODE = sub_exp_code
172 self.PLOT_POS = plot_pos
173 self.PLOT_POS = plot_pos
173
174
174 self.isConfig = True
175 self.isConfig = True
175
176
176 self.setWinTitle(title)
177 self.setWinTitle(title)
177
178
178 for i in range(self.nplots):
179 for i in range(self.nplots):
179 index = channelIndexList[i]
180 index = channelIndexList[i]
180 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
181 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
181 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime)
182 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime)
182 if len(dataOut.beam.codeList) != 0:
183 if len(dataOut.beam.codeList) != 0:
183 title = "Ch%d:%4.2fdB,%2.2f,%2.2f:%s" %(dataOut.channelList[index], noisedB[index], dataOut.beam.azimuthList[index], dataOut.beam.zenithList[index], str_datetime)
184 title = "Ch%d:%4.2fdB,%2.2f,%2.2f:%s" %(dataOut.channelList[index], noisedB[index], dataOut.beam.azimuthList[index], dataOut.beam.zenithList[index], str_datetime)
184
185
185 axes = self.axesList[i*self.__nsubplots]
186 axes = self.axesList[i*self.__nsubplots]
186 axes.pcolor(x, y, zdB[index,:,:],
187 axes.pcolor(x, y, zdB[index,:,:],
187 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
188 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
188 xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap,
189 xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap,
189 ticksize=9, cblabel='')
190 ticksize=9, cblabel='')
190
191
191 if self.__showprofile:
192 if self.__showprofile:
192 axes = self.axesList[i*self.__nsubplots +1]
193 axes = self.axesList[i*self.__nsubplots +1]
193 axes.pline(avgdB[index,:], y,
194 axes.pline(avgdB[index,:], y,
194 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
195 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
195 xlabel='dB', ylabel='', title='',
196 xlabel='dB', ylabel='', title='',
196 ytick_visible=False,
197 ytick_visible=False,
197 grid='x')
198 grid='x')
198
199
199 noiseline = numpy.repeat(noisedB[index], len(y))
200 noiseline = numpy.repeat(noisedB[index], len(y))
200 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
201 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
201
202
202 self.draw()
203 self.draw()
203
204
204 if figfile == None:
205 if figfile == None:
205 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
206 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
206 name = str_datetime
207 name = str_datetime
207 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
208 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
208 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
209 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
209 figfile = self.getFilename(name)
210 figfile = self.getFilename(name)
210
211
211 self.save(figpath=figpath,
212 self.save(figpath=figpath,
212 figfile=figfile,
213 figfile=figfile,
213 save=save,
214 save=save,
214 ftp=ftp,
215 ftp=ftp,
215 wr_period=wr_period,
216 wr_period=wr_period,
216 thisDatetime=thisDatetime)
217 thisDatetime=thisDatetime)
217
218
218
219
219
220
220 class MomentsPlot(Figure):
221 class MomentsPlot(Figure):
221
222
222 isConfig = None
223 isConfig = None
223 __nsubplots = None
224 __nsubplots = None
224
225
225 WIDTHPROF = None
226 WIDTHPROF = None
226 HEIGHTPROF = None
227 HEIGHTPROF = None
227 PREFIX = 'prm'
228 PREFIX = 'prm'
228
229
229 def __init__(self, **kwargs):
230 def __init__(self, **kwargs):
230 Figure.__init__(self, **kwargs)
231 Figure.__init__(self, **kwargs)
231 self.isConfig = False
232 self.isConfig = False
232 self.__nsubplots = 1
233 self.__nsubplots = 1
233
234
234 self.WIDTH = 280
235 self.WIDTH = 280
235 self.HEIGHT = 250
236 self.HEIGHT = 250
236 self.WIDTHPROF = 120
237 self.WIDTHPROF = 120
237 self.HEIGHTPROF = 0
238 self.HEIGHTPROF = 0
238 self.counter_imagwr = 0
239 self.counter_imagwr = 0
239
240
240 self.PLOT_CODE = MOMENTS_CODE
241 self.PLOT_CODE = MOMENTS_CODE
241
242
242 self.FTP_WEI = None
243 self.FTP_WEI = None
243 self.EXP_CODE = None
244 self.EXP_CODE = None
244 self.SUB_EXP_CODE = None
245 self.SUB_EXP_CODE = None
245 self.PLOT_POS = None
246 self.PLOT_POS = None
246
247
247 def getSubplots(self):
248 def getSubplots(self):
248
249
249 ncol = int(numpy.sqrt(self.nplots)+0.9)
250 ncol = int(numpy.sqrt(self.nplots)+0.9)
250 nrow = int(self.nplots*1./ncol + 0.9)
251 nrow = int(self.nplots*1./ncol + 0.9)
251
252
252 return nrow, ncol
253 return nrow, ncol
253
254
254 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
255 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
255
256
256 self.__showprofile = showprofile
257 self.__showprofile = showprofile
257 self.nplots = nplots
258 self.nplots = nplots
258
259
259 ncolspan = 1
260 ncolspan = 1
260 colspan = 1
261 colspan = 1
261 if showprofile:
262 if showprofile:
262 ncolspan = 3
263 ncolspan = 3
263 colspan = 2
264 colspan = 2
264 self.__nsubplots = 2
265 self.__nsubplots = 2
265
266
266 self.createFigure(id = id,
267 self.createFigure(id = id,
267 wintitle = wintitle,
268 wintitle = wintitle,
268 widthplot = self.WIDTH + self.WIDTHPROF,
269 widthplot = self.WIDTH + self.WIDTHPROF,
269 heightplot = self.HEIGHT + self.HEIGHTPROF,
270 heightplot = self.HEIGHT + self.HEIGHTPROF,
270 show=show)
271 show=show)
271
272
272 nrow, ncol = self.getSubplots()
273 nrow, ncol = self.getSubplots()
273
274
274 counter = 0
275 counter = 0
275 for y in range(nrow):
276 for y in range(nrow):
276 for x in range(ncol):
277 for x in range(ncol):
277
278
278 if counter >= self.nplots:
279 if counter >= self.nplots:
279 break
280 break
280
281
281 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
282 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
282
283
283 if showprofile:
284 if showprofile:
284 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
285 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
285
286
286 counter += 1
287 counter += 1
287
288
288 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
289 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
289 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
290 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
290 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
291 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
291 server=None, folder=None, username=None, password=None,
292 server=None, folder=None, username=None, password=None,
292 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
293 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
293
294
294 """
295 """
295
296
296 Input:
297 Input:
297 dataOut :
298 dataOut :
298 id :
299 id :
299 wintitle :
300 wintitle :
300 channelList :
301 channelList :
301 showProfile :
302 showProfile :
302 xmin : None,
303 xmin : None,
303 xmax : None,
304 xmax : None,
304 ymin : None,
305 ymin : None,
305 ymax : None,
306 ymax : None,
306 zmin : None,
307 zmin : None,
307 zmax : None
308 zmax : None
308 """
309 """
309
310
310 if dataOut.flagNoData:
311 if dataOut.flagNoData:
311 return None
312 return None
312
313
313 if realtime:
314 if realtime:
314 if not(isRealtime(utcdatatime = dataOut.utctime)):
315 if not(isRealtime(utcdatatime = dataOut.utctime)):
315 print 'Skipping this plot function'
316 print 'Skipping this plot function'
316 return
317 return
317
318
318 if channelList == None:
319 if channelList == None:
319 channelIndexList = dataOut.channelIndexList
320 channelIndexList = dataOut.channelIndexList
320 else:
321 else:
321 channelIndexList = []
322 channelIndexList = []
322 for channel in channelList:
323 for channel in channelList:
323 if channel not in dataOut.channelList:
324 if channel not in dataOut.channelList:
324 raise ValueError, "Channel %d is not in dataOut.channelList"
325 raise ValueError, "Channel %d is not in dataOut.channelList"
325 channelIndexList.append(dataOut.channelList.index(channel))
326 channelIndexList.append(dataOut.channelList.index(channel))
326
327
327 factor = dataOut.normFactor
328 factor = dataOut.normFactor
328 x = dataOut.abscissaList
329 x = dataOut.abscissaList
329 y = dataOut.heightList
330 y = dataOut.heightList
330
331
331 z = dataOut.data_pre[channelIndexList,:,:]/factor
332 z = dataOut.data_pre[channelIndexList,:,:]/factor
332 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
333 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
333 avg = numpy.average(z, axis=1)
334 avg = numpy.average(z, axis=1)
334 noise = dataOut.noise/factor
335 noise = dataOut.noise/factor
335
336
336 zdB = 10*numpy.log10(z)
337 zdB = 10*numpy.log10(z)
337 avgdB = 10*numpy.log10(avg)
338 avgdB = 10*numpy.log10(avg)
338 noisedB = 10*numpy.log10(noise)
339 noisedB = 10*numpy.log10(noise)
339
340
340 #thisDatetime = dataOut.datatime
341 #thisDatetime = dataOut.datatime
341 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
342 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
342 title = wintitle + " Parameters"
343 title = wintitle + " Parameters"
343 xlabel = "Velocity (m/s)"
344 xlabel = "Velocity (m/s)"
344 ylabel = "Range (Km)"
345 ylabel = "Range (Km)"
345
346
346 update_figfile = False
347 update_figfile = False
347
348
348 if not self.isConfig:
349 if not self.isConfig:
349
350
350 nplots = len(channelIndexList)
351 nplots = len(channelIndexList)
351
352
352 self.setup(id=id,
353 self.setup(id=id,
353 nplots=nplots,
354 nplots=nplots,
354 wintitle=wintitle,
355 wintitle=wintitle,
355 showprofile=showprofile,
356 showprofile=showprofile,
356 show=show)
357 show=show)
357
358
358 if xmin == None: xmin = numpy.nanmin(x)
359 if xmin == None: xmin = numpy.nanmin(x)
359 if xmax == None: xmax = numpy.nanmax(x)
360 if xmax == None: xmax = numpy.nanmax(x)
360 if ymin == None: ymin = numpy.nanmin(y)
361 if ymin == None: ymin = numpy.nanmin(y)
361 if ymax == None: ymax = numpy.nanmax(y)
362 if ymax == None: ymax = numpy.nanmax(y)
362 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
363 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
363 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
364 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
364
365
365 self.FTP_WEI = ftp_wei
366 self.FTP_WEI = ftp_wei
366 self.EXP_CODE = exp_code
367 self.EXP_CODE = exp_code
367 self.SUB_EXP_CODE = sub_exp_code
368 self.SUB_EXP_CODE = sub_exp_code
368 self.PLOT_POS = plot_pos
369 self.PLOT_POS = plot_pos
369
370
370 self.isConfig = True
371 self.isConfig = True
371 update_figfile = True
372 update_figfile = True
372
373
373 self.setWinTitle(title)
374 self.setWinTitle(title)
374
375
375 for i in range(self.nplots):
376 for i in range(self.nplots):
376 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
377 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
377 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i], noisedB[i], str_datetime)
378 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i], noisedB[i], str_datetime)
378 axes = self.axesList[i*self.__nsubplots]
379 axes = self.axesList[i*self.__nsubplots]
379 axes.pcolor(x, y, zdB[i,:,:],
380 axes.pcolor(x, y, zdB[i,:,:],
380 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
381 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
381 xlabel=xlabel, ylabel=ylabel, title=title,
382 xlabel=xlabel, ylabel=ylabel, title=title,
382 ticksize=9, cblabel='')
383 ticksize=9, cblabel='')
383 #Mean Line
384 #Mean Line
384 mean = dataOut.data_param[i, 1, :]
385 mean = dataOut.data_param[i, 1, :]
385 axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1)
386 axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1)
386
387
387 if self.__showprofile:
388 if self.__showprofile:
388 axes = self.axesList[i*self.__nsubplots +1]
389 axes = self.axesList[i*self.__nsubplots +1]
389 axes.pline(avgdB[i], y,
390 axes.pline(avgdB[i], y,
390 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
391 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
391 xlabel='dB', ylabel='', title='',
392 xlabel='dB', ylabel='', title='',
392 ytick_visible=False,
393 ytick_visible=False,
393 grid='x')
394 grid='x')
394
395
395 noiseline = numpy.repeat(noisedB[i], len(y))
396 noiseline = numpy.repeat(noisedB[i], len(y))
396 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
397 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
397
398
398 self.draw()
399 self.draw()
399
400
400 self.save(figpath=figpath,
401 self.save(figpath=figpath,
401 figfile=figfile,
402 figfile=figfile,
402 save=save,
403 save=save,
403 ftp=ftp,
404 ftp=ftp,
404 wr_period=wr_period,
405 wr_period=wr_period,
405 thisDatetime=thisDatetime)
406 thisDatetime=thisDatetime)
406
407
407
408
408
409
409 class SkyMapPlot(Figure):
410 class SkyMapPlot(Figure):
410
411
411 __isConfig = None
412 __isConfig = None
412 __nsubplots = None
413 __nsubplots = None
413
414
414 WIDTHPROF = None
415 WIDTHPROF = None
415 HEIGHTPROF = None
416 HEIGHTPROF = None
416 PREFIX = 'mmap'
417 PREFIX = 'mmap'
417
418
418 def __init__(self, **kwargs):
419 def __init__(self, **kwargs):
419 Figure.__init__(self, **kwargs)
420 Figure.__init__(self, **kwargs)
420 self.isConfig = False
421 self.isConfig = False
421 self.__nsubplots = 1
422 self.__nsubplots = 1
422
423
423 # self.WIDTH = 280
424 # self.WIDTH = 280
424 # self.HEIGHT = 250
425 # self.HEIGHT = 250
425 self.WIDTH = 600
426 self.WIDTH = 600
426 self.HEIGHT = 600
427 self.HEIGHT = 600
427 self.WIDTHPROF = 120
428 self.WIDTHPROF = 120
428 self.HEIGHTPROF = 0
429 self.HEIGHTPROF = 0
429 self.counter_imagwr = 0
430 self.counter_imagwr = 0
430
431
431 self.PLOT_CODE = MSKYMAP_CODE
432 self.PLOT_CODE = MSKYMAP_CODE
432
433
433 self.FTP_WEI = None
434 self.FTP_WEI = None
434 self.EXP_CODE = None
435 self.EXP_CODE = None
435 self.SUB_EXP_CODE = None
436 self.SUB_EXP_CODE = None
436 self.PLOT_POS = None
437 self.PLOT_POS = None
437
438
438 def getSubplots(self):
439 def getSubplots(self):
439
440
440 ncol = int(numpy.sqrt(self.nplots)+0.9)
441 ncol = int(numpy.sqrt(self.nplots)+0.9)
441 nrow = int(self.nplots*1./ncol + 0.9)
442 nrow = int(self.nplots*1./ncol + 0.9)
442
443
443 return nrow, ncol
444 return nrow, ncol
444
445
445 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
446 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
446
447
447 self.__showprofile = showprofile
448 self.__showprofile = showprofile
448 self.nplots = nplots
449 self.nplots = nplots
449
450
450 ncolspan = 1
451 ncolspan = 1
451 colspan = 1
452 colspan = 1
452
453
453 self.createFigure(id = id,
454 self.createFigure(id = id,
454 wintitle = wintitle,
455 wintitle = wintitle,
455 widthplot = self.WIDTH, #+ self.WIDTHPROF,
456 widthplot = self.WIDTH, #+ self.WIDTHPROF,
456 heightplot = self.HEIGHT,# + self.HEIGHTPROF,
457 heightplot = self.HEIGHT,# + self.HEIGHTPROF,
457 show=show)
458 show=show)
458
459
459 nrow, ncol = 1,1
460 nrow, ncol = 1,1
460 counter = 0
461 counter = 0
461 x = 0
462 x = 0
462 y = 0
463 y = 0
463 self.addAxes(1, 1, 0, 0, 1, 1, True)
464 self.addAxes(1, 1, 0, 0, 1, 1, True)
464
465
465 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
466 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
466 tmin=0, tmax=24, timerange=None,
467 tmin=0, tmax=24, timerange=None,
467 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
468 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
468 server=None, folder=None, username=None, password=None,
469 server=None, folder=None, username=None, password=None,
469 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
470 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
470
471
471 """
472 """
472
473
473 Input:
474 Input:
474 dataOut :
475 dataOut :
475 id :
476 id :
476 wintitle :
477 wintitle :
477 channelList :
478 channelList :
478 showProfile :
479 showProfile :
479 xmin : None,
480 xmin : None,
480 xmax : None,
481 xmax : None,
481 ymin : None,
482 ymin : None,
482 ymax : None,
483 ymax : None,
483 zmin : None,
484 zmin : None,
484 zmax : None
485 zmax : None
485 """
486 """
486
487
487 arrayParameters = dataOut.data_param
488 arrayParameters = dataOut.data_param
488 error = arrayParameters[:,-1]
489 error = arrayParameters[:,-1]
489 indValid = numpy.where(error == 0)[0]
490 indValid = numpy.where(error == 0)[0]
490 finalMeteor = arrayParameters[indValid,:]
491 finalMeteor = arrayParameters[indValid,:]
491 finalAzimuth = finalMeteor[:,3]
492 finalAzimuth = finalMeteor[:,3]
492 finalZenith = finalMeteor[:,4]
493 finalZenith = finalMeteor[:,4]
493
494
494 x = finalAzimuth*numpy.pi/180
495 x = finalAzimuth*numpy.pi/180
495 y = finalZenith
496 y = finalZenith
496 x1 = [dataOut.ltctime, dataOut.ltctime]
497 x1 = [dataOut.ltctime, dataOut.ltctime]
497
498
498 #thisDatetime = dataOut.datatime
499 #thisDatetime = dataOut.datatime
499 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
500 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
500 title = wintitle + " Parameters"
501 title = wintitle + " Parameters"
501 xlabel = "Zonal Zenith Angle (deg) "
502 xlabel = "Zonal Zenith Angle (deg) "
502 ylabel = "Meridional Zenith Angle (deg)"
503 ylabel = "Meridional Zenith Angle (deg)"
503 update_figfile = False
504 update_figfile = False
504
505
505 if not self.isConfig:
506 if not self.isConfig:
506
507
507 nplots = 1
508 nplots = 1
508
509
509 self.setup(id=id,
510 self.setup(id=id,
510 nplots=nplots,
511 nplots=nplots,
511 wintitle=wintitle,
512 wintitle=wintitle,
512 showprofile=showprofile,
513 showprofile=showprofile,
513 show=show)
514 show=show)
514
515
515 if self.xmin is None and self.xmax is None:
516 if self.xmin is None and self.xmax is None:
516 self.xmin, self.xmax = self.getTimeLim(x1, tmin, tmax, timerange)
517 self.xmin, self.xmax = self.getTimeLim(x1, tmin, tmax, timerange)
517
518
518 if timerange != None:
519 if timerange != None:
519 self.timerange = timerange
520 self.timerange = timerange
520 else:
521 else:
521 self.timerange = self.xmax - self.xmin
522 self.timerange = self.xmax - self.xmin
522
523
523 self.FTP_WEI = ftp_wei
524 self.FTP_WEI = ftp_wei
524 self.EXP_CODE = exp_code
525 self.EXP_CODE = exp_code
525 self.SUB_EXP_CODE = sub_exp_code
526 self.SUB_EXP_CODE = sub_exp_code
526 self.PLOT_POS = plot_pos
527 self.PLOT_POS = plot_pos
527 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
528 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
528 self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
529 self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
529 self.isConfig = True
530 self.isConfig = True
530 update_figfile = True
531 update_figfile = True
531
532
532 self.setWinTitle(title)
533 self.setWinTitle(title)
533
534
534 i = 0
535 i = 0
535 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
536 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
536
537
537 axes = self.axesList[i*self.__nsubplots]
538 axes = self.axesList[i*self.__nsubplots]
538 nevents = axes.x_buffer.shape[0] + x.shape[0]
539 nevents = axes.x_buffer.shape[0] + x.shape[0]
539 title = "Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n" %(self.firstdate,str_datetime,nevents)
540 title = "Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n" %(self.firstdate,str_datetime,nevents)
540 axes.polar(x, y,
541 axes.polar(x, y,
541 title=title, xlabel=xlabel, ylabel=ylabel,
542 title=title, xlabel=xlabel, ylabel=ylabel,
542 ticksize=9, cblabel='')
543 ticksize=9, cblabel='')
543
544
544 self.draw()
545 self.draw()
545
546
546 self.save(figpath=figpath,
547 self.save(figpath=figpath,
547 figfile=figfile,
548 figfile=figfile,
548 save=save,
549 save=save,
549 ftp=ftp,
550 ftp=ftp,
550 wr_period=wr_period,
551 wr_period=wr_period,
551 thisDatetime=thisDatetime,
552 thisDatetime=thisDatetime,
552 update_figfile=update_figfile)
553 update_figfile=update_figfile)
553
554
554 if dataOut.ltctime >= self.xmax:
555 if dataOut.ltctime >= self.xmax:
555 self.isConfigmagwr = wr_period
556 self.isConfigmagwr = wr_period
556 self.isConfig = False
557 self.isConfig = False
557 update_figfile = True
558 update_figfile = True
558 axes.__firsttime = True
559 axes.__firsttime = True
559 self.xmin += self.timerange
560 self.xmin += self.timerange
560 self.xmax += self.timerange
561 self.xmax += self.timerange
561
562
562
563
563
564
564
565
565 class WindProfilerPlot(Figure):
566 class WindProfilerPlot(Figure):
566
567
567 __isConfig = None
568 __isConfig = None
568 __nsubplots = None
569 __nsubplots = None
569
570
570 WIDTHPROF = None
571 WIDTHPROF = None
571 HEIGHTPROF = None
572 HEIGHTPROF = None
572 PREFIX = 'wind'
573 PREFIX = 'wind'
573
574
574 def __init__(self, **kwargs):
575 def __init__(self, **kwargs):
575 Figure.__init__(self, **kwargs)
576 Figure.__init__(self, **kwargs)
576 self.timerange = None
577 self.timerange = None
577 self.isConfig = False
578 self.isConfig = False
578 self.__nsubplots = 1
579 self.__nsubplots = 1
579
580
580 self.WIDTH = 800
581 self.WIDTH = 800
581 self.HEIGHT = 300
582 self.HEIGHT = 300
582 self.WIDTHPROF = 120
583 self.WIDTHPROF = 120
583 self.HEIGHTPROF = 0
584 self.HEIGHTPROF = 0
584 self.counter_imagwr = 0
585 self.counter_imagwr = 0
585
586
586 self.PLOT_CODE = WIND_CODE
587 self.PLOT_CODE = WIND_CODE
587
588
588 self.FTP_WEI = None
589 self.FTP_WEI = None
589 self.EXP_CODE = None
590 self.EXP_CODE = None
590 self.SUB_EXP_CODE = None
591 self.SUB_EXP_CODE = None
591 self.PLOT_POS = None
592 self.PLOT_POS = None
592 self.tmin = None
593 self.tmin = None
593 self.tmax = None
594 self.tmax = None
594
595
595 self.xmin = None
596 self.xmin = None
596 self.xmax = None
597 self.xmax = None
597
598
598 self.figfile = None
599 self.figfile = None
599
600
600 def getSubplots(self):
601 def getSubplots(self):
601
602
602 ncol = 1
603 ncol = 1
603 nrow = self.nplots
604 nrow = self.nplots
604
605
605 return nrow, ncol
606 return nrow, ncol
606
607
607 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
608 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
608
609
609 self.__showprofile = showprofile
610 self.__showprofile = showprofile
610 self.nplots = nplots
611 self.nplots = nplots
611
612
612 ncolspan = 1
613 ncolspan = 1
613 colspan = 1
614 colspan = 1
614
615
615 self.createFigure(id = id,
616 self.createFigure(id = id,
616 wintitle = wintitle,
617 wintitle = wintitle,
617 widthplot = self.WIDTH + self.WIDTHPROF,
618 widthplot = self.WIDTH + self.WIDTHPROF,
618 heightplot = self.HEIGHT + self.HEIGHTPROF,
619 heightplot = self.HEIGHT + self.HEIGHTPROF,
619 show=show)
620 show=show)
620
621
621 nrow, ncol = self.getSubplots()
622 nrow, ncol = self.getSubplots()
622
623
623 counter = 0
624 counter = 0
624 for y in range(nrow):
625 for y in range(nrow):
625 if counter >= self.nplots:
626 if counter >= self.nplots:
626 break
627 break
627
628
628 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
629 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
629 counter += 1
630 counter += 1
630
631
631 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='False',
632 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='False',
632 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
633 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
633 zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None,
634 zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None,
634 timerange=None, SNRthresh = None,
635 timerange=None, SNRthresh = None,
635 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
636 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
636 server=None, folder=None, username=None, password=None,
637 server=None, folder=None, username=None, password=None,
637 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
638 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
638 """
639 """
639
640
640 Input:
641 Input:
641 dataOut :
642 dataOut :
642 id :
643 id :
643 wintitle :
644 wintitle :
644 channelList :
645 channelList :
645 showProfile :
646 showProfile :
646 xmin : None,
647 xmin : None,
647 xmax : None,
648 xmax : None,
648 ymin : None,
649 ymin : None,
649 ymax : None,
650 ymax : None,
650 zmin : None,
651 zmin : None,
651 zmax : None
652 zmax : None
652 """
653 """
653
654
654 # if timerange is not None:
655 # if timerange is not None:
655 # self.timerange = timerange
656 # self.timerange = timerange
656 #
657 #
657 # tmin = None
658 # tmin = None
658 # tmax = None
659 # tmax = None
659
660
660 x = dataOut.getTimeRange1(dataOut.paramInterval)
661 x = dataOut.getTimeRange1(dataOut.paramInterval)
661 y = dataOut.heightList
662 y = dataOut.heightList
662 z = dataOut.data_output.copy()
663 z = dataOut.data_output.copy()
663 nplots = z.shape[0] #Number of wind dimensions estimated
664 nplots = z.shape[0] #Number of wind dimensions estimated
664 nplotsw = nplots
665 nplotsw = nplots
665
666
666
667
667 #If there is a SNR function defined
668 #If there is a SNR function defined
668 if dataOut.data_SNR is not None:
669 if dataOut.data_SNR is not None:
669 nplots += 1
670 nplots += 1
670 SNR = dataOut.data_SNR[0]
671 SNR = dataOut.data_SNR[0]
671 SNRavg = SNR#numpy.average(SNR, axis=0)
672 SNRavg = SNR#numpy.average(SNR, axis=0)
672
673
673 SNRdB = 10*numpy.log10(SNR)
674 SNRdB = 10*numpy.log10(SNR)
674 SNRavgdB = 10*numpy.log10(SNRavg)
675 SNRavgdB = 10*numpy.log10(SNRavg)
675
676
676 if SNRthresh == None:
677 if SNRthresh == None:
677 SNRthresh = -5.0
678 SNRthresh = -5.0
678 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
679 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
679
680
680 for i in range(nplotsw):
681 for i in range(nplotsw):
681 z[i,ind] = numpy.nan
682 z[i,ind] = numpy.nan
682
683
683 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
684 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
684 #thisDatetime = datetime.datetime.now()
685 #thisDatetime = datetime.datetime.now()
685 title = wintitle + "Wind"
686 title = wintitle + "Wind"
686 xlabel = ""
687 xlabel = ""
687 ylabel = "Height (km)"
688 ylabel = "Height (km)"
688 update_figfile = False
689 update_figfile = False
689
690
690 if not self.isConfig:
691 if not self.isConfig:
691
692
692 self.setup(id=id,
693 self.setup(id=id,
693 nplots=nplots,
694 nplots=nplots,
694 wintitle=wintitle,
695 wintitle=wintitle,
695 showprofile=showprofile,
696 showprofile=showprofile,
696 show=show)
697 show=show)
697
698
698 if timerange is not None:
699 if timerange is not None:
699 self.timerange = timerange
700 self.timerange = timerange
700
701
701 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
702 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
702
703
703 if ymin == None: ymin = numpy.nanmin(y)
704 if ymin == None: ymin = numpy.nanmin(y)
704 if ymax == None: ymax = numpy.nanmax(y)
705 if ymax == None: ymax = numpy.nanmax(y)
705
706
706 if zmax == None: zmax = numpy.nanmax(abs(z[range(2),:]))
707 if zmax == None: zmax = numpy.nanmax(abs(z[range(2),:]))
707 #if numpy.isnan(zmax): zmax = 50
708 #if numpy.isnan(zmax): zmax = 50
708 if zmin == None: zmin = -zmax
709 if zmin == None: zmin = -zmax
709
710
710 if nplotsw == 3:
711 if nplotsw == 3:
711 if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:]))
712 if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:]))
712 if zmin_ver == None: zmin_ver = -zmax_ver
713 if zmin_ver == None: zmin_ver = -zmax_ver
713
714
714 if dataOut.data_SNR is not None:
715 if dataOut.data_SNR is not None:
715 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
716 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
716 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
717 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
717
718
718
719
719 self.FTP_WEI = ftp_wei
720 self.FTP_WEI = ftp_wei
720 self.EXP_CODE = exp_code
721 self.EXP_CODE = exp_code
721 self.SUB_EXP_CODE = sub_exp_code
722 self.SUB_EXP_CODE = sub_exp_code
722 self.PLOT_POS = plot_pos
723 self.PLOT_POS = plot_pos
723
724
724 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
725 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
725 self.isConfig = True
726 self.isConfig = True
726 self.figfile = figfile
727 self.figfile = figfile
727 update_figfile = True
728 update_figfile = True
728
729
729 self.setWinTitle(title)
730 self.setWinTitle(title)
730
731
731 if ((self.xmax - x[1]) < (x[1]-x[0])):
732 if ((self.xmax - x[1]) < (x[1]-x[0])):
732 x[1] = self.xmax
733 x[1] = self.xmax
733
734
734 strWind = ['Zonal', 'Meridional', 'Vertical']
735 strWind = ['Zonal', 'Meridional', 'Vertical']
735 strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)']
736 strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)']
736 zmaxVector = [zmax, zmax, zmax_ver]
737 zmaxVector = [zmax, zmax, zmax_ver]
737 zminVector = [zmin, zmin, zmin_ver]
738 zminVector = [zmin, zmin, zmin_ver]
738 windFactor = [1,1,100]
739 windFactor = [1,1,100]
739
740
740 for i in range(nplotsw):
741 for i in range(nplotsw):
741
742
742 title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
743 title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
743 axes = self.axesList[i*self.__nsubplots]
744 axes = self.axesList[i*self.__nsubplots]
744
745
745 z1 = z[i,:].reshape((1,-1))*windFactor[i]
746 z1 = z[i,:].reshape((1,-1))*windFactor[i]
746
747
747 print 'x', x
748 print 'x', x
748 print datetime.datetime.utcfromtimestamp(x[0])
749 print datetime.datetime.utcfromtimestamp(x[0])
749 print datetime.datetime.utcfromtimestamp(x[1])
750 print datetime.datetime.utcfromtimestamp(x[1])
750
751
751 #z1=numpy.ma.masked_where(z1==0.,z1)
752 #z1=numpy.ma.masked_where(z1==0.,z1)
752
753
753 axes.pcolorbuffer(x, y, z1,
754 axes.pcolorbuffer(x, y, z1,
754 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
755 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
755 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
756 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
756 ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="seismic" )
757 ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="seismic" )
757
758
758 if dataOut.data_SNR is not None:
759 if dataOut.data_SNR is not None:
759 i += 1
760 i += 1
760 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
761 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
761 axes = self.axesList[i*self.__nsubplots]
762 axes = self.axesList[i*self.__nsubplots]
762 SNRavgdB = SNRavgdB.reshape((1,-1))
763 SNRavgdB = SNRavgdB.reshape((1,-1))
763 axes.pcolorbuffer(x, y, SNRavgdB,
764 axes.pcolorbuffer(x, y, SNRavgdB,
764 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
765 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
765 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
766 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
766 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
767 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
767
768
768 self.draw()
769 self.draw()
769
770
770 self.save(figpath=figpath,
771 self.save(figpath=figpath,
771 figfile=figfile,
772 figfile=figfile,
772 save=save,
773 save=save,
773 ftp=ftp,
774 ftp=ftp,
774 wr_period=wr_period,
775 wr_period=wr_period,
775 thisDatetime=thisDatetime,
776 thisDatetime=thisDatetime,
776 update_figfile=update_figfile)
777 update_figfile=update_figfile)
777
778
778 if dataOut.ltctime + dataOut.paramInterval >= self.xmax:
779 if dataOut.ltctime + dataOut.paramInterval >= self.xmax:
779 self.counter_imagwr = wr_period
780 self.counter_imagwr = wr_period
780 self.isConfig = False
781 self.isConfig = False
781 update_figfile = True
782 update_figfile = True
782
783
783
784
784 class ParametersPlot(Figure):
785 class ParametersPlot(Figure):
785
786
786 __isConfig = None
787 __isConfig = None
787 __nsubplots = None
788 __nsubplots = None
788
789
789 WIDTHPROF = None
790 WIDTHPROF = None
790 HEIGHTPROF = None
791 HEIGHTPROF = None
791 PREFIX = 'param'
792 PREFIX = 'param'
792
793
793 nplots = None
794 nplots = None
794 nchan = None
795 nchan = None
795
796
796 def __init__(self, **kwargs):
797 def __init__(self, **kwargs):
797 Figure.__init__(self, **kwargs)
798 Figure.__init__(self, **kwargs)
798 self.timerange = None
799 self.timerange = None
799 self.isConfig = False
800 self.isConfig = False
800 self.__nsubplots = 1
801 self.__nsubplots = 1
801
802
802 self.WIDTH = 800
803 self.WIDTH = 800
803 self.HEIGHT = 180
804 self.HEIGHT = 180
804 self.WIDTHPROF = 120
805 self.WIDTHPROF = 120
805 self.HEIGHTPROF = 0
806 self.HEIGHTPROF = 0
806 self.counter_imagwr = 0
807 self.counter_imagwr = 0
807
808
808 self.PLOT_CODE = RTI_CODE
809 self.PLOT_CODE = RTI_CODE
809
810
810 self.FTP_WEI = None
811 self.FTP_WEI = None
811 self.EXP_CODE = None
812 self.EXP_CODE = None
812 self.SUB_EXP_CODE = None
813 self.SUB_EXP_CODE = None
813 self.PLOT_POS = None
814 self.PLOT_POS = None
814 self.tmin = None
815 self.tmin = None
815 self.tmax = None
816 self.tmax = None
816
817
817 self.xmin = None
818 self.xmin = None
818 self.xmax = None
819 self.xmax = None
819
820
820 self.figfile = None
821 self.figfile = None
821
822
822 def getSubplots(self):
823 def getSubplots(self):
823
824
824 ncol = 1
825 ncol = 1
825 nrow = self.nplots
826 nrow = self.nplots
826
827
827 return nrow, ncol
828 return nrow, ncol
828
829
829 def setup(self, id, nplots, wintitle, show=True):
830 def setup(self, id, nplots, wintitle, show=True):
830
831
831 self.nplots = nplots
832 self.nplots = nplots
832
833
833 ncolspan = 1
834 ncolspan = 1
834 colspan = 1
835 colspan = 1
835
836
836 self.createFigure(id = id,
837 self.createFigure(id = id,
837 wintitle = wintitle,
838 wintitle = wintitle,
838 widthplot = self.WIDTH + self.WIDTHPROF,
839 widthplot = self.WIDTH + self.WIDTHPROF,
839 heightplot = self.HEIGHT + self.HEIGHTPROF,
840 heightplot = self.HEIGHT + self.HEIGHTPROF,
840 show=show)
841 show=show)
841
842
842 nrow, ncol = self.getSubplots()
843 nrow, ncol = self.getSubplots()
843
844
844 counter = 0
845 counter = 0
845 for y in range(nrow):
846 for y in range(nrow):
846 for x in range(ncol):
847 for x in range(ncol):
847
848
848 if counter >= self.nplots:
849 if counter >= self.nplots:
849 break
850 break
850
851
851 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
852 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
852
853
853 counter += 1
854 counter += 1
854
855
855 def run(self, dataOut, id, wintitle="", channelList=None, paramIndex = 0, colormap="jet",
856 def run(self, dataOut, id, wintitle="", channelList=None, paramIndex = 0, colormap="jet",
856 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, timerange=None,
857 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, timerange=None,
857 showSNR=False, SNRthresh = -numpy.inf, SNRmin=None, SNRmax=None,
858 showSNR=False, SNRthresh = -numpy.inf, SNRmin=None, SNRmax=None,
858 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
859 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
859 server=None, folder=None, username=None, password=None,
860 server=None, folder=None, username=None, password=None,
860 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, HEIGHT=None):
861 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, HEIGHT=None):
861 """
862 """
862
863
863 Input:
864 Input:
864 dataOut :
865 dataOut :
865 id :
866 id :
866 wintitle :
867 wintitle :
867 channelList :
868 channelList :
868 showProfile :
869 showProfile :
869 xmin : None,
870 xmin : None,
870 xmax : None,
871 xmax : None,
871 ymin : None,
872 ymin : None,
872 ymax : None,
873 ymax : None,
873 zmin : None,
874 zmin : None,
874 zmax : None
875 zmax : None
875 """
876 """
876
877
877 if HEIGHT is not None:
878 if HEIGHT is not None:
878 self.HEIGHT = HEIGHT
879 self.HEIGHT = HEIGHT
879
880
880
881
881 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
882 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
882 return
883 return
883
884
884 if channelList == None:
885 if channelList == None:
885 channelIndexList = range(dataOut.data_param.shape[0])
886 channelIndexList = range(dataOut.data_param.shape[0])
886 else:
887 else:
887 channelIndexList = []
888 channelIndexList = []
888 for channel in channelList:
889 for channel in channelList:
889 if channel not in dataOut.channelList:
890 if channel not in dataOut.channelList:
890 raise ValueError, "Channel %d is not in dataOut.channelList"
891 raise ValueError, "Channel %d is not in dataOut.channelList"
891 channelIndexList.append(dataOut.channelList.index(channel))
892 channelIndexList.append(dataOut.channelList.index(channel))
892
893
893 x = dataOut.getTimeRange1(dataOut.paramInterval)
894 x = dataOut.getTimeRange1(dataOut.paramInterval)
894 y = dataOut.getHeiRange()
895 y = dataOut.getHeiRange()
895
896
896 if dataOut.data_param.ndim == 3:
897 if dataOut.data_param.ndim == 3:
897 z = dataOut.data_param[channelIndexList,paramIndex,:]
898 z = dataOut.data_param[channelIndexList,paramIndex,:]
898 else:
899 else:
899 z = dataOut.data_param[channelIndexList,:]
900 z = dataOut.data_param[channelIndexList,:]
900
901
901 if showSNR:
902 if showSNR:
902 #SNR data
903 #SNR data
903 SNRarray = dataOut.data_SNR[channelIndexList,:]
904 SNRarray = dataOut.data_SNR[channelIndexList,:]
904 SNRdB = 10*numpy.log10(SNRarray)
905 SNRdB = 10*numpy.log10(SNRarray)
905 ind = numpy.where(SNRdB < SNRthresh)
906 ind = numpy.where(SNRdB < SNRthresh)
906 z[ind] = numpy.nan
907 z[ind] = numpy.nan
907
908
908 thisDatetime = dataOut.datatime
909 thisDatetime = dataOut.datatime
909 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
910 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
910 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
911 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
911 xlabel = ""
912 xlabel = ""
912 ylabel = "Range (Km)"
913 ylabel = "Range (Km)"
913
914
914 update_figfile = False
915 update_figfile = False
915
916
916 if not self.isConfig:
917 if not self.isConfig:
917
918
918 nchan = len(channelIndexList)
919 nchan = len(channelIndexList)
919 self.nchan = nchan
920 self.nchan = nchan
920 self.plotFact = 1
921 self.plotFact = 1
921 nplots = nchan
922 nplots = nchan
922
923
923 if showSNR:
924 if showSNR:
924 nplots = nchan*2
925 nplots = nchan*2
925 self.plotFact = 2
926 self.plotFact = 2
926 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
927 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
927 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
928 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
928
929
929 self.setup(id=id,
930 self.setup(id=id,
930 nplots=nplots,
931 nplots=nplots,
931 wintitle=wintitle,
932 wintitle=wintitle,
932 show=show)
933 show=show)
933
934
934 if timerange != None:
935 if timerange != None:
935 self.timerange = timerange
936 self.timerange = timerange
936
937
937 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
938 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
938
939
939 if ymin == None: ymin = numpy.nanmin(y)
940 if ymin == None: ymin = numpy.nanmin(y)
940 if ymax == None: ymax = numpy.nanmax(y)
941 if ymax == None: ymax = numpy.nanmax(y)
941 if zmin == None: zmin = numpy.nanmin(z)
942 if zmin == None: zmin = numpy.nanmin(z)
942 if zmax == None: zmax = numpy.nanmax(z)
943 if zmax == None: zmax = numpy.nanmax(z)
943
944
944 self.FTP_WEI = ftp_wei
945 self.FTP_WEI = ftp_wei
945 self.EXP_CODE = exp_code
946 self.EXP_CODE = exp_code
946 self.SUB_EXP_CODE = sub_exp_code
947 self.SUB_EXP_CODE = sub_exp_code
947 self.PLOT_POS = plot_pos
948 self.PLOT_POS = plot_pos
948
949
949 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
950 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
950 self.isConfig = True
951 self.isConfig = True
951 self.figfile = figfile
952 self.figfile = figfile
952 update_figfile = True
953 update_figfile = True
953
954
954 self.setWinTitle(title)
955 self.setWinTitle(title)
955
956
956 for i in range(self.nchan):
957 for i in range(self.nchan):
957 index = channelIndexList[i]
958 index = channelIndexList[i]
958 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
959 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
959 axes = self.axesList[i*self.plotFact]
960 axes = self.axesList[i*self.plotFact]
960 z1 = z[i,:].reshape((1,-1))
961 z1 = z[i,:].reshape((1,-1))
961 axes.pcolorbuffer(x, y, z1,
962 axes.pcolorbuffer(x, y, z1,
962 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
963 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
963 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
964 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
964 ticksize=9, cblabel='', cbsize="1%",colormap=colormap)
965 ticksize=9, cblabel='', cbsize="1%",colormap=colormap)
965
966
966 if showSNR:
967 if showSNR:
967 title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
968 title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
968 axes = self.axesList[i*self.plotFact + 1]
969 axes = self.axesList[i*self.plotFact + 1]
969 SNRdB1 = SNRdB[i,:].reshape((1,-1))
970 SNRdB1 = SNRdB[i,:].reshape((1,-1))
970 axes.pcolorbuffer(x, y, SNRdB1,
971 axes.pcolorbuffer(x, y, SNRdB1,
971 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
972 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
972 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
973 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
973 ticksize=9, cblabel='', cbsize="1%",colormap='jet')
974 ticksize=9, cblabel='', cbsize="1%",colormap='jet')
974
975
975
976
976 self.draw()
977 self.draw()
977
978
978 if dataOut.ltctime >= self.xmax:
979 if dataOut.ltctime >= self.xmax:
979 self.counter_imagwr = wr_period
980 self.counter_imagwr = wr_period
980 self.isConfig = False
981 self.isConfig = False
981 update_figfile = True
982 update_figfile = True
982
983
983 self.save(figpath=figpath,
984 self.save(figpath=figpath,
984 figfile=figfile,
985 figfile=figfile,
985 save=save,
986 save=save,
986 ftp=ftp,
987 ftp=ftp,
987 wr_period=wr_period,
988 wr_period=wr_period,
988 thisDatetime=thisDatetime,
989 thisDatetime=thisDatetime,
989 update_figfile=update_figfile)
990 update_figfile=update_figfile)
990
991
991
992
992
993
993 class Parameters1Plot(Figure):
994 class Parameters1Plot(Figure):
994
995
995 __isConfig = None
996 __isConfig = None
996 __nsubplots = None
997 __nsubplots = None
997
998
998 WIDTHPROF = None
999 WIDTHPROF = None
999 HEIGHTPROF = None
1000 HEIGHTPROF = None
1000 PREFIX = 'prm'
1001 PREFIX = 'prm'
1001
1002
1002 def __init__(self, **kwargs):
1003 def __init__(self, **kwargs):
1003 Figure.__init__(self, **kwargs)
1004 Figure.__init__(self, **kwargs)
1004 self.timerange = 2*60*60
1005 self.timerange = 2*60*60
1005 self.isConfig = False
1006 self.isConfig = False
1006 self.__nsubplots = 1
1007 self.__nsubplots = 1
1007
1008
1008 self.WIDTH = 800
1009 self.WIDTH = 800
1009 self.HEIGHT = 180
1010 self.HEIGHT = 180
1010 self.WIDTHPROF = 120
1011 self.WIDTHPROF = 120
1011 self.HEIGHTPROF = 0
1012 self.HEIGHTPROF = 0
1012 self.counter_imagwr = 0
1013 self.counter_imagwr = 0
1013
1014
1014 self.PLOT_CODE = PARMS_CODE
1015 self.PLOT_CODE = PARMS_CODE
1015
1016
1016 self.FTP_WEI = None
1017 self.FTP_WEI = None
1017 self.EXP_CODE = None
1018 self.EXP_CODE = None
1018 self.SUB_EXP_CODE = None
1019 self.SUB_EXP_CODE = None
1019 self.PLOT_POS = None
1020 self.PLOT_POS = None
1020 self.tmin = None
1021 self.tmin = None
1021 self.tmax = None
1022 self.tmax = None
1022
1023
1023 self.xmin = None
1024 self.xmin = None
1024 self.xmax = None
1025 self.xmax = None
1025
1026
1026 self.figfile = None
1027 self.figfile = None
1027
1028
1028 def getSubplots(self):
1029 def getSubplots(self):
1029
1030
1030 ncol = 1
1031 ncol = 1
1031 nrow = self.nplots
1032 nrow = self.nplots
1032
1033
1033 return nrow, ncol
1034 return nrow, ncol
1034
1035
1035 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1036 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1036
1037
1037 self.__showprofile = showprofile
1038 self.__showprofile = showprofile
1038 self.nplots = nplots
1039 self.nplots = nplots
1039
1040
1040 ncolspan = 1
1041 ncolspan = 1
1041 colspan = 1
1042 colspan = 1
1042
1043
1043 self.createFigure(id = id,
1044 self.createFigure(id = id,
1044 wintitle = wintitle,
1045 wintitle = wintitle,
1045 widthplot = self.WIDTH + self.WIDTHPROF,
1046 widthplot = self.WIDTH + self.WIDTHPROF,
1046 heightplot = self.HEIGHT + self.HEIGHTPROF,
1047 heightplot = self.HEIGHT + self.HEIGHTPROF,
1047 show=show)
1048 show=show)
1048
1049
1049 nrow, ncol = self.getSubplots()
1050 nrow, ncol = self.getSubplots()
1050
1051
1051 counter = 0
1052 counter = 0
1052 for y in range(nrow):
1053 for y in range(nrow):
1053 for x in range(ncol):
1054 for x in range(ncol):
1054
1055
1055 if counter >= self.nplots:
1056 if counter >= self.nplots:
1056 break
1057 break
1057
1058
1058 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1059 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1059
1060
1060 if showprofile:
1061 if showprofile:
1061 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1062 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1062
1063
1063 counter += 1
1064 counter += 1
1064
1065
1065 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
1066 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
1066 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None,
1067 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None,
1067 parameterIndex = None, onlyPositive = False,
1068 parameterIndex = None, onlyPositive = False,
1068 SNRthresh = -numpy.inf, SNR = True, SNRmin = None, SNRmax = None, onlySNR = False,
1069 SNRthresh = -numpy.inf, SNR = True, SNRmin = None, SNRmax = None, onlySNR = False,
1069 DOP = True,
1070 DOP = True,
1070 zlabel = "", parameterName = "", parameterObject = "data_param",
1071 zlabel = "", parameterName = "", parameterObject = "data_param",
1071 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1072 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1072 server=None, folder=None, username=None, password=None,
1073 server=None, folder=None, username=None, password=None,
1073 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1074 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1074 #print inspect.getargspec(self.run).args
1075 #print inspect.getargspec(self.run).args
1075 """
1076 """
1076
1077
1077 Input:
1078 Input:
1078 dataOut :
1079 dataOut :
1079 id :
1080 id :
1080 wintitle :
1081 wintitle :
1081 channelList :
1082 channelList :
1082 showProfile :
1083 showProfile :
1083 xmin : None,
1084 xmin : None,
1084 xmax : None,
1085 xmax : None,
1085 ymin : None,
1086 ymin : None,
1086 ymax : None,
1087 ymax : None,
1087 zmin : None,
1088 zmin : None,
1088 zmax : None
1089 zmax : None
1089 """
1090 """
1090
1091
1091 data_param = getattr(dataOut, parameterObject)
1092 data_param = getattr(dataOut, parameterObject)
1092
1093
1093 if channelList == None:
1094 if channelList == None:
1094 channelIndexList = numpy.arange(data_param.shape[0])
1095 channelIndexList = numpy.arange(data_param.shape[0])
1095 else:
1096 else:
1096 channelIndexList = numpy.array(channelList)
1097 channelIndexList = numpy.array(channelList)
1097
1098
1098 nchan = len(channelIndexList) #Number of channels being plotted
1099 nchan = len(channelIndexList) #Number of channels being plotted
1099
1100
1100 if nchan < 1:
1101 if nchan < 1:
1101 return
1102 return
1102
1103
1103 nGraphsByChannel = 0
1104 nGraphsByChannel = 0
1104
1105
1105 if SNR:
1106 if SNR:
1106 nGraphsByChannel += 1
1107 nGraphsByChannel += 1
1107 if DOP:
1108 if DOP:
1108 nGraphsByChannel += 1
1109 nGraphsByChannel += 1
1109
1110
1110 if nGraphsByChannel < 1:
1111 if nGraphsByChannel < 1:
1111 return
1112 return
1112
1113
1113 nplots = nGraphsByChannel*nchan
1114 nplots = nGraphsByChannel*nchan
1114
1115
1115 if timerange is not None:
1116 if timerange is not None:
1116 self.timerange = timerange
1117 self.timerange = timerange
1117
1118
1118 #tmin = None
1119 #tmin = None
1119 #tmax = None
1120 #tmax = None
1120 if parameterIndex == None:
1121 if parameterIndex == None:
1121 parameterIndex = 1
1122 parameterIndex = 1
1122
1123
1123 x = dataOut.getTimeRange1(dataOut.paramInterval)
1124 x = dataOut.getTimeRange1(dataOut.paramInterval)
1124 y = dataOut.heightList
1125 y = dataOut.heightList
1125 z = data_param[channelIndexList,parameterIndex,:].copy()
1126 z = data_param[channelIndexList,parameterIndex,:].copy()
1126
1127
1127 zRange = dataOut.abscissaList
1128 zRange = dataOut.abscissaList
1128 # nChannels = z.shape[0] #Number of wind dimensions estimated
1129 # nChannels = z.shape[0] #Number of wind dimensions estimated
1129 # thisDatetime = dataOut.datatime
1130 # thisDatetime = dataOut.datatime
1130
1131
1131 if dataOut.data_SNR is not None:
1132 if dataOut.data_SNR is not None:
1132 SNRarray = dataOut.data_SNR[channelIndexList,:]
1133 SNRarray = dataOut.data_SNR[channelIndexList,:]
1133 SNRdB = 10*numpy.log10(SNRarray)
1134 SNRdB = 10*numpy.log10(SNRarray)
1134 # SNRavgdB = 10*numpy.log10(SNRavg)
1135 # SNRavgdB = 10*numpy.log10(SNRavg)
1135 ind = numpy.where(SNRdB < 10**(SNRthresh/10))
1136 ind = numpy.where(SNRdB < 10**(SNRthresh/10))
1136 z[ind] = numpy.nan
1137 z[ind] = numpy.nan
1137
1138
1138 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1139 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1139 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
1140 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
1140 xlabel = ""
1141 xlabel = ""
1141 ylabel = "Range (Km)"
1142 ylabel = "Range (Km)"
1142
1143
1143 if (SNR and not onlySNR): nplots = 2*nplots
1144 if (SNR and not onlySNR): nplots = 2*nplots
1144
1145
1145 if onlyPositive:
1146 if onlyPositive:
1146 colormap = "jet"
1147 colormap = "jet"
1147 zmin = 0
1148 zmin = 0
1148 else: colormap = "RdBu_r"
1149 else: colormap = "RdBu_r"
1149
1150
1150 if not self.isConfig:
1151 if not self.isConfig:
1151
1152
1152 self.setup(id=id,
1153 self.setup(id=id,
1153 nplots=nplots,
1154 nplots=nplots,
1154 wintitle=wintitle,
1155 wintitle=wintitle,
1155 showprofile=showprofile,
1156 showprofile=showprofile,
1156 show=show)
1157 show=show)
1157
1158
1158 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1159 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1159
1160
1160 if ymin == None: ymin = numpy.nanmin(y)
1161 if ymin == None: ymin = numpy.nanmin(y)
1161 if ymax == None: ymax = numpy.nanmax(y)
1162 if ymax == None: ymax = numpy.nanmax(y)
1162 if zmin == None: zmin = numpy.nanmin(zRange)
1163 if zmin == None: zmin = numpy.nanmin(zRange)
1163 if zmax == None: zmax = numpy.nanmax(zRange)
1164 if zmax == None: zmax = numpy.nanmax(zRange)
1164
1165
1165 if SNR:
1166 if SNR:
1166 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
1167 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
1167 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
1168 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
1168
1169
1169 self.FTP_WEI = ftp_wei
1170 self.FTP_WEI = ftp_wei
1170 self.EXP_CODE = exp_code
1171 self.EXP_CODE = exp_code
1171 self.SUB_EXP_CODE = sub_exp_code
1172 self.SUB_EXP_CODE = sub_exp_code
1172 self.PLOT_POS = plot_pos
1173 self.PLOT_POS = plot_pos
1173
1174
1174 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1175 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1175 self.isConfig = True
1176 self.isConfig = True
1176 self.figfile = figfile
1177 self.figfile = figfile
1177
1178
1178 self.setWinTitle(title)
1179 self.setWinTitle(title)
1179
1180
1180 if ((self.xmax - x[1]) < (x[1]-x[0])):
1181 if ((self.xmax - x[1]) < (x[1]-x[0])):
1181 x[1] = self.xmax
1182 x[1] = self.xmax
1182
1183
1183 for i in range(nchan):
1184 for i in range(nchan):
1184
1185
1185 if (SNR and not onlySNR): j = 2*i
1186 if (SNR and not onlySNR): j = 2*i
1186 else: j = i
1187 else: j = i
1187
1188
1188 j = nGraphsByChannel*i
1189 j = nGraphsByChannel*i
1189
1190
1190 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1191 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1191 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
1192 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
1192
1193
1193 if not onlySNR:
1194 if not onlySNR:
1194 axes = self.axesList[j*self.__nsubplots]
1195 axes = self.axesList[j*self.__nsubplots]
1195 z1 = z[i,:].reshape((1,-1))
1196 z1 = z[i,:].reshape((1,-1))
1196 axes.pcolorbuffer(x, y, z1,
1197 axes.pcolorbuffer(x, y, z1,
1197 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
1198 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
1198 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
1199 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
1199 ticksize=9, cblabel=zlabel, cbsize="1%")
1200 ticksize=9, cblabel=zlabel, cbsize="1%")
1200
1201
1201 if DOP:
1202 if DOP:
1202 title = "%s Channel %d: %s" %(parameterName, channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1203 title = "%s Channel %d: %s" %(parameterName, channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1203
1204
1204 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1205 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1205 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
1206 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
1206 axes = self.axesList[j]
1207 axes = self.axesList[j]
1207 z1 = z[i,:].reshape((1,-1))
1208 z1 = z[i,:].reshape((1,-1))
1208 axes.pcolorbuffer(x, y, z1,
1209 axes.pcolorbuffer(x, y, z1,
1209 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
1210 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
1210 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
1211 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
1211 ticksize=9, cblabel=zlabel, cbsize="1%")
1212 ticksize=9, cblabel=zlabel, cbsize="1%")
1212
1213
1213 if SNR:
1214 if SNR:
1214 title = "Channel %d Signal Noise Ratio (SNR): %s" %(channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1215 title = "Channel %d Signal Noise Ratio (SNR): %s" %(channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1215 axes = self.axesList[(j)*self.__nsubplots]
1216 axes = self.axesList[(j)*self.__nsubplots]
1216 if not onlySNR:
1217 if not onlySNR:
1217 axes = self.axesList[(j + 1)*self.__nsubplots]
1218 axes = self.axesList[(j + 1)*self.__nsubplots]
1218
1219
1219 axes = self.axesList[(j + nGraphsByChannel-1)]
1220 axes = self.axesList[(j + nGraphsByChannel-1)]
1220
1221
1221 z1 = SNRdB[i,:].reshape((1,-1))
1222 z1 = SNRdB[i,:].reshape((1,-1))
1222 axes.pcolorbuffer(x, y, z1,
1223 axes.pcolorbuffer(x, y, z1,
1223 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1224 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1224 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap="jet",
1225 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap="jet",
1225 ticksize=9, cblabel=zlabel, cbsize="1%")
1226 ticksize=9, cblabel=zlabel, cbsize="1%")
1226
1227
1227
1228
1228
1229
1229 self.draw()
1230 self.draw()
1230
1231
1231 if x[1] >= self.axesList[0].xmax:
1232 if x[1] >= self.axesList[0].xmax:
1232 self.counter_imagwr = wr_period
1233 self.counter_imagwr = wr_period
1233 self.isConfig = False
1234 self.isConfig = False
1234 self.figfile = None
1235 self.figfile = None
1235
1236
1236 self.save(figpath=figpath,
1237 self.save(figpath=figpath,
1237 figfile=figfile,
1238 figfile=figfile,
1238 save=save,
1239 save=save,
1239 ftp=ftp,
1240 ftp=ftp,
1240 wr_period=wr_period,
1241 wr_period=wr_period,
1241 thisDatetime=thisDatetime,
1242 thisDatetime=thisDatetime,
1242 update_figfile=False)
1243 update_figfile=False)
1243
1244
1244 class SpectralFittingPlot(Figure):
1245 class SpectralFittingPlot(Figure):
1245
1246
1246 __isConfig = None
1247 __isConfig = None
1247 __nsubplots = None
1248 __nsubplots = None
1248
1249
1249 WIDTHPROF = None
1250 WIDTHPROF = None
1250 HEIGHTPROF = None
1251 HEIGHTPROF = None
1251 PREFIX = 'prm'
1252 PREFIX = 'prm'
1252
1253
1253
1254
1254 N = None
1255 N = None
1255 ippSeconds = None
1256 ippSeconds = None
1256
1257
1257 def __init__(self, **kwargs):
1258 def __init__(self, **kwargs):
1258 Figure.__init__(self, **kwargs)
1259 Figure.__init__(self, **kwargs)
1259 self.isConfig = False
1260 self.isConfig = False
1260 self.__nsubplots = 1
1261 self.__nsubplots = 1
1261
1262
1262 self.PLOT_CODE = SPECFIT_CODE
1263 self.PLOT_CODE = SPECFIT_CODE
1263
1264
1264 self.WIDTH = 450
1265 self.WIDTH = 450
1265 self.HEIGHT = 250
1266 self.HEIGHT = 250
1266 self.WIDTHPROF = 0
1267 self.WIDTHPROF = 0
1267 self.HEIGHTPROF = 0
1268 self.HEIGHTPROF = 0
1268
1269
1269 def getSubplots(self):
1270 def getSubplots(self):
1270
1271
1271 ncol = int(numpy.sqrt(self.nplots)+0.9)
1272 ncol = int(numpy.sqrt(self.nplots)+0.9)
1272 nrow = int(self.nplots*1./ncol + 0.9)
1273 nrow = int(self.nplots*1./ncol + 0.9)
1273
1274
1274 return nrow, ncol
1275 return nrow, ncol
1275
1276
1276 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
1277 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
1277
1278
1278 showprofile = False
1279 showprofile = False
1279 self.__showprofile = showprofile
1280 self.__showprofile = showprofile
1280 self.nplots = nplots
1281 self.nplots = nplots
1281
1282
1282 ncolspan = 5
1283 ncolspan = 5
1283 colspan = 4
1284 colspan = 4
1284 if showprofile:
1285 if showprofile:
1285 ncolspan = 5
1286 ncolspan = 5
1286 colspan = 4
1287 colspan = 4
1287 self.__nsubplots = 2
1288 self.__nsubplots = 2
1288
1289
1289 self.createFigure(id = id,
1290 self.createFigure(id = id,
1290 wintitle = wintitle,
1291 wintitle = wintitle,
1291 widthplot = self.WIDTH + self.WIDTHPROF,
1292 widthplot = self.WIDTH + self.WIDTHPROF,
1292 heightplot = self.HEIGHT + self.HEIGHTPROF,
1293 heightplot = self.HEIGHT + self.HEIGHTPROF,
1293 show=show)
1294 show=show)
1294
1295
1295 nrow, ncol = self.getSubplots()
1296 nrow, ncol = self.getSubplots()
1296
1297
1297 counter = 0
1298 counter = 0
1298 for y in range(nrow):
1299 for y in range(nrow):
1299 for x in range(ncol):
1300 for x in range(ncol):
1300
1301
1301 if counter >= self.nplots:
1302 if counter >= self.nplots:
1302 break
1303 break
1303
1304
1304 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1305 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1305
1306
1306 if showprofile:
1307 if showprofile:
1307 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1308 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1308
1309
1309 counter += 1
1310 counter += 1
1310
1311
1311 def run(self, dataOut, id, cutHeight=None, fit=False, wintitle="", channelList=None, showprofile=True,
1312 def run(self, dataOut, id, cutHeight=None, fit=False, wintitle="", channelList=None, showprofile=True,
1312 xmin=None, xmax=None, ymin=None, ymax=None,
1313 xmin=None, xmax=None, ymin=None, ymax=None,
1313 save=False, figpath='./', figfile=None, show=True):
1314 save=False, figpath='./', figfile=None, show=True):
1314
1315
1315 """
1316 """
1316
1317
1317 Input:
1318 Input:
1318 dataOut :
1319 dataOut :
1319 id :
1320 id :
1320 wintitle :
1321 wintitle :
1321 channelList :
1322 channelList :
1322 showProfile :
1323 showProfile :
1323 xmin : None,
1324 xmin : None,
1324 xmax : None,
1325 xmax : None,
1325 zmin : None,
1326 zmin : None,
1326 zmax : None
1327 zmax : None
1327 """
1328 """
1328
1329
1329 if cutHeight==None:
1330 if cutHeight==None:
1330 h=270
1331 h=270
1331 heightindex = numpy.abs(cutHeight - dataOut.heightList).argmin()
1332 heightindex = numpy.abs(cutHeight - dataOut.heightList).argmin()
1332 cutHeight = dataOut.heightList[heightindex]
1333 cutHeight = dataOut.heightList[heightindex]
1333
1334
1334 factor = dataOut.normFactor
1335 factor = dataOut.normFactor
1335 x = dataOut.abscissaList[:-1]
1336 x = dataOut.abscissaList[:-1]
1336 #y = dataOut.getHeiRange()
1337 #y = dataOut.getHeiRange()
1337
1338
1338 z = dataOut.data_pre[:,:,heightindex]/factor
1339 z = dataOut.data_pre[:,:,heightindex]/factor
1339 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1340 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1340 avg = numpy.average(z, axis=1)
1341 avg = numpy.average(z, axis=1)
1341 listChannels = z.shape[0]
1342 listChannels = z.shape[0]
1342
1343
1343 #Reconstruct Function
1344 #Reconstruct Function
1344 if fit==True:
1345 if fit==True:
1345 groupArray = dataOut.groupList
1346 groupArray = dataOut.groupList
1346 listChannels = groupArray.reshape((groupArray.size))
1347 listChannels = groupArray.reshape((groupArray.size))
1347 listChannels.sort()
1348 listChannels.sort()
1348 spcFitLine = numpy.zeros(z.shape)
1349 spcFitLine = numpy.zeros(z.shape)
1349 constants = dataOut.constants
1350 constants = dataOut.constants
1350
1351
1351 nGroups = groupArray.shape[0]
1352 nGroups = groupArray.shape[0]
1352 nChannels = groupArray.shape[1]
1353 nChannels = groupArray.shape[1]
1353 nProfiles = z.shape[1]
1354 nProfiles = z.shape[1]
1354
1355
1355 for f in range(nGroups):
1356 for f in range(nGroups):
1356 groupChann = groupArray[f,:]
1357 groupChann = groupArray[f,:]
1357 p = dataOut.data_param[f,:,heightindex]
1358 p = dataOut.data_param[f,:,heightindex]
1358 # p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167])
1359 # p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167])
1359 fitLineAux = dataOut.library.modelFunction(p, constants)*nProfiles
1360 fitLineAux = dataOut.library.modelFunction(p, constants)*nProfiles
1360 fitLineAux = fitLineAux.reshape((nChannels,nProfiles))
1361 fitLineAux = fitLineAux.reshape((nChannels,nProfiles))
1361 spcFitLine[groupChann,:] = fitLineAux
1362 spcFitLine[groupChann,:] = fitLineAux
1362 # spcFitLine = spcFitLine/factor
1363 # spcFitLine = spcFitLine/factor
1363
1364
1364 z = z[listChannels,:]
1365 z = z[listChannels,:]
1365 spcFitLine = spcFitLine[listChannels,:]
1366 spcFitLine = spcFitLine[listChannels,:]
1366 spcFitLinedB = 10*numpy.log10(spcFitLine)
1367 spcFitLinedB = 10*numpy.log10(spcFitLine)
1367
1368
1368 zdB = 10*numpy.log10(z)
1369 zdB = 10*numpy.log10(z)
1369 #thisDatetime = dataOut.datatime
1370 #thisDatetime = dataOut.datatime
1370 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1371 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1371 title = wintitle + " Doppler Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1372 title = wintitle + " Doppler Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1372 xlabel = "Velocity (m/s)"
1373 xlabel = "Velocity (m/s)"
1373 ylabel = "Spectrum"
1374 ylabel = "Spectrum"
1374
1375
1375 if not self.isConfig:
1376 if not self.isConfig:
1376
1377
1377 nplots = listChannels.size
1378 nplots = listChannels.size
1378
1379
1379 self.setup(id=id,
1380 self.setup(id=id,
1380 nplots=nplots,
1381 nplots=nplots,
1381 wintitle=wintitle,
1382 wintitle=wintitle,
1382 showprofile=showprofile,
1383 showprofile=showprofile,
1383 show=show)
1384 show=show)
1384
1385
1385 if xmin == None: xmin = numpy.nanmin(x)
1386 if xmin == None: xmin = numpy.nanmin(x)
1386 if xmax == None: xmax = numpy.nanmax(x)
1387 if xmax == None: xmax = numpy.nanmax(x)
1387 if ymin == None: ymin = numpy.nanmin(zdB)
1388 if ymin == None: ymin = numpy.nanmin(zdB)
1388 if ymax == None: ymax = numpy.nanmax(zdB)+2
1389 if ymax == None: ymax = numpy.nanmax(zdB)+2
1389
1390
1390 self.isConfig = True
1391 self.isConfig = True
1391
1392
1392 self.setWinTitle(title)
1393 self.setWinTitle(title)
1393 for i in range(self.nplots):
1394 for i in range(self.nplots):
1394 # title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i])
1395 # title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i])
1395 title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i])
1396 title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i])
1396 axes = self.axesList[i*self.__nsubplots]
1397 axes = self.axesList[i*self.__nsubplots]
1397 if fit == False:
1398 if fit == False:
1398 axes.pline(x, zdB[i,:],
1399 axes.pline(x, zdB[i,:],
1399 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1400 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1400 xlabel=xlabel, ylabel=ylabel, title=title
1401 xlabel=xlabel, ylabel=ylabel, title=title
1401 )
1402 )
1402 if fit == True:
1403 if fit == True:
1403 fitline=spcFitLinedB[i,:]
1404 fitline=spcFitLinedB[i,:]
1404 y=numpy.vstack([zdB[i,:],fitline] )
1405 y=numpy.vstack([zdB[i,:],fitline] )
1405 legendlabels=['Data','Fitting']
1406 legendlabels=['Data','Fitting']
1406 axes.pmultilineyaxis(x, y,
1407 axes.pmultilineyaxis(x, y,
1407 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1408 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1408 xlabel=xlabel, ylabel=ylabel, title=title,
1409 xlabel=xlabel, ylabel=ylabel, title=title,
1409 legendlabels=legendlabels, marker=None,
1410 legendlabels=legendlabels, marker=None,
1410 linestyle='solid', grid='both')
1411 linestyle='solid', grid='both')
1411
1412
1412 self.draw()
1413 self.draw()
1413
1414
1414 self.save(figpath=figpath,
1415 self.save(figpath=figpath,
1415 figfile=figfile,
1416 figfile=figfile,
1416 save=save,
1417 save=save,
1417 ftp=ftp,
1418 ftp=ftp,
1418 wr_period=wr_period,
1419 wr_period=wr_period,
1419 thisDatetime=thisDatetime)
1420 thisDatetime=thisDatetime)
1420
1421
1421
1422
1422 class EWDriftsPlot(Figure):
1423 class EWDriftsPlot(Figure):
1423
1424
1424 __isConfig = None
1425 __isConfig = None
1425 __nsubplots = None
1426 __nsubplots = None
1426
1427
1427 WIDTHPROF = None
1428 WIDTHPROF = None
1428 HEIGHTPROF = None
1429 HEIGHTPROF = None
1429 PREFIX = 'drift'
1430 PREFIX = 'drift'
1430
1431
1431 def __init__(self, **kwargs):
1432 def __init__(self, **kwargs):
1432 Figure.__init__(self, **kwargs)
1433 Figure.__init__(self, **kwargs)
1433 self.timerange = 2*60*60
1434 self.timerange = 2*60*60
1434 self.isConfig = False
1435 self.isConfig = False
1435 self.__nsubplots = 1
1436 self.__nsubplots = 1
1436
1437
1437 self.WIDTH = 800
1438 self.WIDTH = 800
1438 self.HEIGHT = 150
1439 self.HEIGHT = 150
1439 self.WIDTHPROF = 120
1440 self.WIDTHPROF = 120
1440 self.HEIGHTPROF = 0
1441 self.HEIGHTPROF = 0
1441 self.counter_imagwr = 0
1442 self.counter_imagwr = 0
1442
1443
1443 self.PLOT_CODE = EWDRIFT_CODE
1444 self.PLOT_CODE = EWDRIFT_CODE
1444
1445
1445 self.FTP_WEI = None
1446 self.FTP_WEI = None
1446 self.EXP_CODE = None
1447 self.EXP_CODE = None
1447 self.SUB_EXP_CODE = None
1448 self.SUB_EXP_CODE = None
1448 self.PLOT_POS = None
1449 self.PLOT_POS = None
1449 self.tmin = None
1450 self.tmin = None
1450 self.tmax = None
1451 self.tmax = None
1451
1452
1452 self.xmin = None
1453 self.xmin = None
1453 self.xmax = None
1454 self.xmax = None
1454
1455
1455 self.figfile = None
1456 self.figfile = None
1456
1457
1457 def getSubplots(self):
1458 def getSubplots(self):
1458
1459
1459 ncol = 1
1460 ncol = 1
1460 nrow = self.nplots
1461 nrow = self.nplots
1461
1462
1462 return nrow, ncol
1463 return nrow, ncol
1463
1464
1464 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1465 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1465
1466
1466 self.__showprofile = showprofile
1467 self.__showprofile = showprofile
1467 self.nplots = nplots
1468 self.nplots = nplots
1468
1469
1469 ncolspan = 1
1470 ncolspan = 1
1470 colspan = 1
1471 colspan = 1
1471
1472
1472 self.createFigure(id = id,
1473 self.createFigure(id = id,
1473 wintitle = wintitle,
1474 wintitle = wintitle,
1474 widthplot = self.WIDTH + self.WIDTHPROF,
1475 widthplot = self.WIDTH + self.WIDTHPROF,
1475 heightplot = self.HEIGHT + self.HEIGHTPROF,
1476 heightplot = self.HEIGHT + self.HEIGHTPROF,
1476 show=show)
1477 show=show)
1477
1478
1478 nrow, ncol = self.getSubplots()
1479 nrow, ncol = self.getSubplots()
1479
1480
1480 counter = 0
1481 counter = 0
1481 for y in range(nrow):
1482 for y in range(nrow):
1482 if counter >= self.nplots:
1483 if counter >= self.nplots:
1483 break
1484 break
1484
1485
1485 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
1486 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
1486 counter += 1
1487 counter += 1
1487
1488
1488 def run(self, dataOut, id, wintitle="", channelList=None,
1489 def run(self, dataOut, id, wintitle="", channelList=None,
1489 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
1490 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
1490 zmaxVertical = None, zminVertical = None, zmaxZonal = None, zminZonal = None,
1491 zmaxVertical = None, zminVertical = None, zmaxZonal = None, zminZonal = None,
1491 timerange=None, SNRthresh = -numpy.inf, SNRmin = None, SNRmax = None, SNR_1 = False,
1492 timerange=None, SNRthresh = -numpy.inf, SNRmin = None, SNRmax = None, SNR_1 = False,
1492 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1493 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1493 server=None, folder=None, username=None, password=None,
1494 server=None, folder=None, username=None, password=None,
1494 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1495 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1495 """
1496 """
1496
1497
1497 Input:
1498 Input:
1498 dataOut :
1499 dataOut :
1499 id :
1500 id :
1500 wintitle :
1501 wintitle :
1501 channelList :
1502 channelList :
1502 showProfile :
1503 showProfile :
1503 xmin : None,
1504 xmin : None,
1504 xmax : None,
1505 xmax : None,
1505 ymin : None,
1506 ymin : None,
1506 ymax : None,
1507 ymax : None,
1507 zmin : None,
1508 zmin : None,
1508 zmax : None
1509 zmax : None
1509 """
1510 """
1510
1511
1511 if timerange is not None:
1512 if timerange is not None:
1512 self.timerange = timerange
1513 self.timerange = timerange
1513
1514
1514 tmin = None
1515 tmin = None
1515 tmax = None
1516 tmax = None
1516
1517
1517 x = dataOut.getTimeRange1(dataOut.outputInterval)
1518 x = dataOut.getTimeRange1(dataOut.outputInterval)
1518 # y = dataOut.heightList
1519 # y = dataOut.heightList
1519 y = dataOut.heightList
1520 y = dataOut.heightList
1520
1521
1521 z = dataOut.data_output
1522 z = dataOut.data_output
1522 nplots = z.shape[0] #Number of wind dimensions estimated
1523 nplots = z.shape[0] #Number of wind dimensions estimated
1523 nplotsw = nplots
1524 nplotsw = nplots
1524
1525
1525 #If there is a SNR function defined
1526 #If there is a SNR function defined
1526 if dataOut.data_SNR is not None:
1527 if dataOut.data_SNR is not None:
1527 nplots += 1
1528 nplots += 1
1528 SNR = dataOut.data_SNR
1529 SNR = dataOut.data_SNR
1529
1530
1530 if SNR_1:
1531 if SNR_1:
1531 SNR += 1
1532 SNR += 1
1532
1533
1533 SNRavg = numpy.average(SNR, axis=0)
1534 SNRavg = numpy.average(SNR, axis=0)
1534
1535
1535 SNRdB = 10*numpy.log10(SNR)
1536 SNRdB = 10*numpy.log10(SNR)
1536 SNRavgdB = 10*numpy.log10(SNRavg)
1537 SNRavgdB = 10*numpy.log10(SNRavg)
1537
1538
1538 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
1539 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
1539
1540
1540 for i in range(nplotsw):
1541 for i in range(nplotsw):
1541 z[i,ind] = numpy.nan
1542 z[i,ind] = numpy.nan
1542
1543
1543
1544
1544 showprofile = False
1545 showprofile = False
1545 # thisDatetime = dataOut.datatime
1546 # thisDatetime = dataOut.datatime
1546 thisDatetime = datetime.datetime.utcfromtimestamp(x[1])
1547 thisDatetime = datetime.datetime.utcfromtimestamp(x[1])
1547 title = wintitle + " EW Drifts"
1548 title = wintitle + " EW Drifts"
1548 xlabel = ""
1549 xlabel = ""
1549 ylabel = "Height (Km)"
1550 ylabel = "Height (Km)"
1550
1551
1551 if not self.isConfig:
1552 if not self.isConfig:
1552
1553
1553 self.setup(id=id,
1554 self.setup(id=id,
1554 nplots=nplots,
1555 nplots=nplots,
1555 wintitle=wintitle,
1556 wintitle=wintitle,
1556 showprofile=showprofile,
1557 showprofile=showprofile,
1557 show=show)
1558 show=show)
1558
1559
1559 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1560 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1560
1561
1561 if ymin == None: ymin = numpy.nanmin(y)
1562 if ymin == None: ymin = numpy.nanmin(y)
1562 if ymax == None: ymax = numpy.nanmax(y)
1563 if ymax == None: ymax = numpy.nanmax(y)
1563
1564
1564 if zmaxZonal == None: zmaxZonal = numpy.nanmax(abs(z[0,:]))
1565 if zmaxZonal == None: zmaxZonal = numpy.nanmax(abs(z[0,:]))
1565 if zminZonal == None: zminZonal = -zmaxZonal
1566 if zminZonal == None: zminZonal = -zmaxZonal
1566 if zmaxVertical == None: zmaxVertical = numpy.nanmax(abs(z[1,:]))
1567 if zmaxVertical == None: zmaxVertical = numpy.nanmax(abs(z[1,:]))
1567 if zminVertical == None: zminVertical = -zmaxVertical
1568 if zminVertical == None: zminVertical = -zmaxVertical
1568
1569
1569 if dataOut.data_SNR is not None:
1570 if dataOut.data_SNR is not None:
1570 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
1571 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
1571 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
1572 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
1572
1573
1573 self.FTP_WEI = ftp_wei
1574 self.FTP_WEI = ftp_wei
1574 self.EXP_CODE = exp_code
1575 self.EXP_CODE = exp_code
1575 self.SUB_EXP_CODE = sub_exp_code
1576 self.SUB_EXP_CODE = sub_exp_code
1576 self.PLOT_POS = plot_pos
1577 self.PLOT_POS = plot_pos
1577
1578
1578 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1579 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1579 self.isConfig = True
1580 self.isConfig = True
1580
1581
1581
1582
1582 self.setWinTitle(title)
1583 self.setWinTitle(title)
1583
1584
1584 if ((self.xmax - x[1]) < (x[1]-x[0])):
1585 if ((self.xmax - x[1]) < (x[1]-x[0])):
1585 x[1] = self.xmax
1586 x[1] = self.xmax
1586
1587
1587 strWind = ['Zonal','Vertical']
1588 strWind = ['Zonal','Vertical']
1588 strCb = 'Velocity (m/s)'
1589 strCb = 'Velocity (m/s)'
1589 zmaxVector = [zmaxZonal, zmaxVertical]
1590 zmaxVector = [zmaxZonal, zmaxVertical]
1590 zminVector = [zminZonal, zminVertical]
1591 zminVector = [zminZonal, zminVertical]
1591
1592
1592 for i in range(nplotsw):
1593 for i in range(nplotsw):
1593
1594
1594 title = "%s Drifts: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1595 title = "%s Drifts: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1595 axes = self.axesList[i*self.__nsubplots]
1596 axes = self.axesList[i*self.__nsubplots]
1596
1597
1597 z1 = z[i,:].reshape((1,-1))
1598 z1 = z[i,:].reshape((1,-1))
1598
1599
1599 axes.pcolorbuffer(x, y, z1,
1600 axes.pcolorbuffer(x, y, z1,
1600 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
1601 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
1601 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1602 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1602 ticksize=9, cblabel=strCb, cbsize="1%", colormap="RdBu_r")
1603 ticksize=9, cblabel=strCb, cbsize="1%", colormap="RdBu_r")
1603
1604
1604 if dataOut.data_SNR is not None:
1605 if dataOut.data_SNR is not None:
1605 i += 1
1606 i += 1
1606 if SNR_1:
1607 if SNR_1:
1607 title = "Signal Noise Ratio + 1 (SNR+1): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1608 title = "Signal Noise Ratio + 1 (SNR+1): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1608 else:
1609 else:
1609 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1610 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1610 axes = self.axesList[i*self.__nsubplots]
1611 axes = self.axesList[i*self.__nsubplots]
1611 SNRavgdB = SNRavgdB.reshape((1,-1))
1612 SNRavgdB = SNRavgdB.reshape((1,-1))
1612
1613
1613 axes.pcolorbuffer(x, y, SNRavgdB,
1614 axes.pcolorbuffer(x, y, SNRavgdB,
1614 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1615 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1615 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1616 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1616 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
1617 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
1617
1618
1618 self.draw()
1619 self.draw()
1619
1620
1620 if x[1] >= self.axesList[0].xmax:
1621 if x[1] >= self.axesList[0].xmax:
1621 self.counter_imagwr = wr_period
1622 self.counter_imagwr = wr_period
1622 self.isConfig = False
1623 self.isConfig = False
1623 self.figfile = None
1624 self.figfile = None
1624
1625
1625
1626
1626
1627
1627
1628
1628 class PhasePlot(Figure):
1629 class PhasePlot(Figure):
1629
1630
1630 __isConfig = None
1631 __isConfig = None
1631 __nsubplots = None
1632 __nsubplots = None
1632
1633
1633 PREFIX = 'mphase'
1634 PREFIX = 'mphase'
1634
1635
1635 def __init__(self, **kwargs):
1636 def __init__(self, **kwargs):
1636 Figure.__init__(self, **kwargs)
1637 Figure.__init__(self, **kwargs)
1637 self.timerange = 24*60*60
1638 self.timerange = 24*60*60
1638 self.isConfig = False
1639 self.isConfig = False
1639 self.__nsubplots = 1
1640 self.__nsubplots = 1
1640 self.counter_imagwr = 0
1641 self.counter_imagwr = 0
1641 self.WIDTH = 600
1642 self.WIDTH = 600
1642 self.HEIGHT = 300
1643 self.HEIGHT = 300
1643 self.WIDTHPROF = 120
1644 self.WIDTHPROF = 120
1644 self.HEIGHTPROF = 0
1645 self.HEIGHTPROF = 0
1645 self.xdata = None
1646 self.xdata = None
1646 self.ydata = None
1647 self.ydata = None
1647
1648
1648 self.PLOT_CODE = MPHASE_CODE
1649 self.PLOT_CODE = MPHASE_CODE
1649
1650
1650 self.FTP_WEI = None
1651 self.FTP_WEI = None
1651 self.EXP_CODE = None
1652 self.EXP_CODE = None
1652 self.SUB_EXP_CODE = None
1653 self.SUB_EXP_CODE = None
1653 self.PLOT_POS = None
1654 self.PLOT_POS = None
1654
1655
1655
1656
1656 self.filename_phase = None
1657 self.filename_phase = None
1657
1658
1658 self.figfile = None
1659 self.figfile = None
1659
1660
1660 def getSubplots(self):
1661 def getSubplots(self):
1661
1662
1662 ncol = 1
1663 ncol = 1
1663 nrow = 1
1664 nrow = 1
1664
1665
1665 return nrow, ncol
1666 return nrow, ncol
1666
1667
1667 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1668 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1668
1669
1669 self.__showprofile = showprofile
1670 self.__showprofile = showprofile
1670 self.nplots = nplots
1671 self.nplots = nplots
1671
1672
1672 ncolspan = 7
1673 ncolspan = 7
1673 colspan = 6
1674 colspan = 6
1674 self.__nsubplots = 2
1675 self.__nsubplots = 2
1675
1676
1676 self.createFigure(id = id,
1677 self.createFigure(id = id,
1677 wintitle = wintitle,
1678 wintitle = wintitle,
1678 widthplot = self.WIDTH+self.WIDTHPROF,
1679 widthplot = self.WIDTH+self.WIDTHPROF,
1679 heightplot = self.HEIGHT+self.HEIGHTPROF,
1680 heightplot = self.HEIGHT+self.HEIGHTPROF,
1680 show=show)
1681 show=show)
1681
1682
1682 nrow, ncol = self.getSubplots()
1683 nrow, ncol = self.getSubplots()
1683
1684
1684 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1685 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1685
1686
1686
1687
1687 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1688 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1688 xmin=None, xmax=None, ymin=None, ymax=None,
1689 xmin=None, xmax=None, ymin=None, ymax=None,
1689 timerange=None,
1690 timerange=None,
1690 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1691 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1691 server=None, folder=None, username=None, password=None,
1692 server=None, folder=None, username=None, password=None,
1692 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1693 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1693
1694
1694
1695
1695 tmin = None
1696 tmin = None
1696 tmax = None
1697 tmax = None
1697 x = dataOut.getTimeRange1(dataOut.outputInterval)
1698 x = dataOut.getTimeRange1(dataOut.outputInterval)
1698 y = dataOut.getHeiRange()
1699 y = dataOut.getHeiRange()
1699
1700
1700
1701
1701 #thisDatetime = dataOut.datatime
1702 #thisDatetime = dataOut.datatime
1702 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1703 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1703 title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1704 title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1704 xlabel = "Local Time"
1705 xlabel = "Local Time"
1705 ylabel = "Phase"
1706 ylabel = "Phase"
1706
1707
1707
1708
1708 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1709 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1709 phase_beacon = dataOut.data_output
1710 phase_beacon = dataOut.data_output
1710 update_figfile = False
1711 update_figfile = False
1711
1712
1712 if not self.isConfig:
1713 if not self.isConfig:
1713
1714
1714 self.nplots = phase_beacon.size
1715 self.nplots = phase_beacon.size
1715
1716
1716 self.setup(id=id,
1717 self.setup(id=id,
1717 nplots=self.nplots,
1718 nplots=self.nplots,
1718 wintitle=wintitle,
1719 wintitle=wintitle,
1719 showprofile=showprofile,
1720 showprofile=showprofile,
1720 show=show)
1721 show=show)
1721
1722
1722 if timerange is not None:
1723 if timerange is not None:
1723 self.timerange = timerange
1724 self.timerange = timerange
1724
1725
1725 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1726 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1726
1727
1727 if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0
1728 if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0
1728 if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0
1729 if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0
1729
1730
1730 self.FTP_WEI = ftp_wei
1731 self.FTP_WEI = ftp_wei
1731 self.EXP_CODE = exp_code
1732 self.EXP_CODE = exp_code
1732 self.SUB_EXP_CODE = sub_exp_code
1733 self.SUB_EXP_CODE = sub_exp_code
1733 self.PLOT_POS = plot_pos
1734 self.PLOT_POS = plot_pos
1734
1735
1735 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1736 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1736 self.isConfig = True
1737 self.isConfig = True
1737 self.figfile = figfile
1738 self.figfile = figfile
1738 self.xdata = numpy.array([])
1739 self.xdata = numpy.array([])
1739 self.ydata = numpy.array([])
1740 self.ydata = numpy.array([])
1740
1741
1741 #open file beacon phase
1742 #open file beacon phase
1742 path = '%s%03d' %(self.PREFIX, self.id)
1743 path = '%s%03d' %(self.PREFIX, self.id)
1743 beacon_file = os.path.join(path,'%s.txt'%self.name)
1744 beacon_file = os.path.join(path,'%s.txt'%self.name)
1744 self.filename_phase = os.path.join(figpath,beacon_file)
1745 self.filename_phase = os.path.join(figpath,beacon_file)
1745 update_figfile = True
1746 update_figfile = True
1746
1747
1747
1748
1748 #store data beacon phase
1749 #store data beacon phase
1749 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1750 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1750
1751
1751 self.setWinTitle(title)
1752 self.setWinTitle(title)
1752
1753
1753
1754
1754 title = "Phase Offset %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1755 title = "Phase Offset %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1755
1756
1756 legendlabels = ["phase %d"%(chan) for chan in numpy.arange(self.nplots)]
1757 legendlabels = ["phase %d"%(chan) for chan in numpy.arange(self.nplots)]
1757
1758
1758 axes = self.axesList[0]
1759 axes = self.axesList[0]
1759
1760
1760 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1761 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1761
1762
1762 if len(self.ydata)==0:
1763 if len(self.ydata)==0:
1763 self.ydata = phase_beacon.reshape(-1,1)
1764 self.ydata = phase_beacon.reshape(-1,1)
1764 else:
1765 else:
1765 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1766 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1766
1767
1767
1768
1768 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1769 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1769 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1770 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1770 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1771 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1771 XAxisAsTime=True, grid='both'
1772 XAxisAsTime=True, grid='both'
1772 )
1773 )
1773
1774
1774 self.draw()
1775 self.draw()
1775
1776
1776 self.save(figpath=figpath,
1777 self.save(figpath=figpath,
1777 figfile=figfile,
1778 figfile=figfile,
1778 save=save,
1779 save=save,
1779 ftp=ftp,
1780 ftp=ftp,
1780 wr_period=wr_period,
1781 wr_period=wr_period,
1781 thisDatetime=thisDatetime,
1782 thisDatetime=thisDatetime,
1782 update_figfile=update_figfile)
1783 update_figfile=update_figfile)
1783
1784
1784 if dataOut.ltctime + dataOut.outputInterval >= self.xmax:
1785 if dataOut.ltctime + dataOut.outputInterval >= self.xmax:
1785 self.counter_imagwr = wr_period
1786 self.counter_imagwr = wr_period
1786 self.isConfig = False
1787 self.isConfig = False
1787 update_figfile = True
1788 update_figfile = True
1788
1789
1789
1790
1790
1791
1791 class NSMeteorDetection1Plot(Figure):
1792 class NSMeteorDetection1Plot(Figure):
1792
1793
1793 isConfig = None
1794 isConfig = None
1794 __nsubplots = None
1795 __nsubplots = None
1795
1796
1796 WIDTHPROF = None
1797 WIDTHPROF = None
1797 HEIGHTPROF = None
1798 HEIGHTPROF = None
1798 PREFIX = 'nsm'
1799 PREFIX = 'nsm'
1799
1800
1800 zminList = None
1801 zminList = None
1801 zmaxList = None
1802 zmaxList = None
1802 cmapList = None
1803 cmapList = None
1803 titleList = None
1804 titleList = None
1804 nPairs = None
1805 nPairs = None
1805 nChannels = None
1806 nChannels = None
1806 nParam = None
1807 nParam = None
1807
1808
1808 def __init__(self, **kwargs):
1809 def __init__(self, **kwargs):
1809 Figure.__init__(self, **kwargs)
1810 Figure.__init__(self, **kwargs)
1810 self.isConfig = False
1811 self.isConfig = False
1811 self.__nsubplots = 1
1812 self.__nsubplots = 1
1812
1813
1813 self.WIDTH = 750
1814 self.WIDTH = 750
1814 self.HEIGHT = 250
1815 self.HEIGHT = 250
1815 self.WIDTHPROF = 120
1816 self.WIDTHPROF = 120
1816 self.HEIGHTPROF = 0
1817 self.HEIGHTPROF = 0
1817 self.counter_imagwr = 0
1818 self.counter_imagwr = 0
1818
1819
1819 self.PLOT_CODE = SPEC_CODE
1820 self.PLOT_CODE = SPEC_CODE
1820
1821
1821 self.FTP_WEI = None
1822 self.FTP_WEI = None
1822 self.EXP_CODE = None
1823 self.EXP_CODE = None
1823 self.SUB_EXP_CODE = None
1824 self.SUB_EXP_CODE = None
1824 self.PLOT_POS = None
1825 self.PLOT_POS = None
1825
1826
1826 self.__xfilter_ena = False
1827 self.__xfilter_ena = False
1827 self.__yfilter_ena = False
1828 self.__yfilter_ena = False
1828
1829
1829 def getSubplots(self):
1830 def getSubplots(self):
1830
1831
1831 ncol = 3
1832 ncol = 3
1832 nrow = int(numpy.ceil(self.nplots/3.0))
1833 nrow = int(numpy.ceil(self.nplots/3.0))
1833
1834
1834 return nrow, ncol
1835 return nrow, ncol
1835
1836
1836 def setup(self, id, nplots, wintitle, show=True):
1837 def setup(self, id, nplots, wintitle, show=True):
1837
1838
1838 self.nplots = nplots
1839 self.nplots = nplots
1839
1840
1840 ncolspan = 1
1841 ncolspan = 1
1841 colspan = 1
1842 colspan = 1
1842
1843
1843 self.createFigure(id = id,
1844 self.createFigure(id = id,
1844 wintitle = wintitle,
1845 wintitle = wintitle,
1845 widthplot = self.WIDTH + self.WIDTHPROF,
1846 widthplot = self.WIDTH + self.WIDTHPROF,
1846 heightplot = self.HEIGHT + self.HEIGHTPROF,
1847 heightplot = self.HEIGHT + self.HEIGHTPROF,
1847 show=show)
1848 show=show)
1848
1849
1849 nrow, ncol = self.getSubplots()
1850 nrow, ncol = self.getSubplots()
1850
1851
1851 counter = 0
1852 counter = 0
1852 for y in range(nrow):
1853 for y in range(nrow):
1853 for x in range(ncol):
1854 for x in range(ncol):
1854
1855
1855 if counter >= self.nplots:
1856 if counter >= self.nplots:
1856 break
1857 break
1857
1858
1858 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1859 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1859
1860
1860 counter += 1
1861 counter += 1
1861
1862
1862 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
1863 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
1863 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
1864 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
1864 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
1865 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
1865 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1866 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1866 server=None, folder=None, username=None, password=None,
1867 server=None, folder=None, username=None, password=None,
1867 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
1868 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
1868 xaxis="frequency"):
1869 xaxis="frequency"):
1869
1870
1870 """
1871 """
1871
1872
1872 Input:
1873 Input:
1873 dataOut :
1874 dataOut :
1874 id :
1875 id :
1875 wintitle :
1876 wintitle :
1876 channelList :
1877 channelList :
1877 showProfile :
1878 showProfile :
1878 xmin : None,
1879 xmin : None,
1879 xmax : None,
1880 xmax : None,
1880 ymin : None,
1881 ymin : None,
1881 ymax : None,
1882 ymax : None,
1882 zmin : None,
1883 zmin : None,
1883 zmax : None
1884 zmax : None
1884 """
1885 """
1885 #SEPARAR EN DOS PLOTS
1886 #SEPARAR EN DOS PLOTS
1886 nParam = dataOut.data_param.shape[1] - 3
1887 nParam = dataOut.data_param.shape[1] - 3
1887
1888
1888 utctime = dataOut.data_param[0,0]
1889 utctime = dataOut.data_param[0,0]
1889 tmet = dataOut.data_param[:,1].astype(int)
1890 tmet = dataOut.data_param[:,1].astype(int)
1890 hmet = dataOut.data_param[:,2].astype(int)
1891 hmet = dataOut.data_param[:,2].astype(int)
1891
1892
1892 x = dataOut.abscissaList
1893 x = dataOut.abscissaList
1893 y = dataOut.heightList
1894 y = dataOut.heightList
1894
1895
1895 z = numpy.zeros((nParam, y.size, x.size - 1))
1896 z = numpy.zeros((nParam, y.size, x.size - 1))
1896 z[:,:] = numpy.nan
1897 z[:,:] = numpy.nan
1897 z[:,hmet,tmet] = dataOut.data_param[:,3:].T
1898 z[:,hmet,tmet] = dataOut.data_param[:,3:].T
1898 z[0,:,:] = 10*numpy.log10(z[0,:,:])
1899 z[0,:,:] = 10*numpy.log10(z[0,:,:])
1899
1900
1900 xlabel = "Time (s)"
1901 xlabel = "Time (s)"
1901 ylabel = "Range (km)"
1902 ylabel = "Range (km)"
1902
1903
1903 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1904 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1904
1905
1905 if not self.isConfig:
1906 if not self.isConfig:
1906
1907
1907 nplots = nParam
1908 nplots = nParam
1908
1909
1909 self.setup(id=id,
1910 self.setup(id=id,
1910 nplots=nplots,
1911 nplots=nplots,
1911 wintitle=wintitle,
1912 wintitle=wintitle,
1912 show=show)
1913 show=show)
1913
1914
1914 if xmin is None: xmin = numpy.nanmin(x)
1915 if xmin is None: xmin = numpy.nanmin(x)
1915 if xmax is None: xmax = numpy.nanmax(x)
1916 if xmax is None: xmax = numpy.nanmax(x)
1916 if ymin is None: ymin = numpy.nanmin(y)
1917 if ymin is None: ymin = numpy.nanmin(y)
1917 if ymax is None: ymax = numpy.nanmax(y)
1918 if ymax is None: ymax = numpy.nanmax(y)
1918 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
1919 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
1919 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
1920 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
1920 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
1921 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
1921 if vmin is None: vmin = -vmax
1922 if vmin is None: vmin = -vmax
1922 if wmin is None: wmin = 0
1923 if wmin is None: wmin = 0
1923 if wmax is None: wmax = 50
1924 if wmax is None: wmax = 50
1924
1925
1925 pairsList = dataOut.groupList
1926 pairsList = dataOut.groupList
1926 self.nPairs = len(dataOut.groupList)
1927 self.nPairs = len(dataOut.groupList)
1927
1928
1928 zminList = [SNRmin, vmin, cmin] + [pmin]*self.nPairs
1929 zminList = [SNRmin, vmin, cmin] + [pmin]*self.nPairs
1929 zmaxList = [SNRmax, vmax, cmax] + [pmax]*self.nPairs
1930 zmaxList = [SNRmax, vmax, cmax] + [pmax]*self.nPairs
1930 titleList = ["SNR","Radial Velocity","Coherence"]
1931 titleList = ["SNR","Radial Velocity","Coherence"]
1931 cmapList = ["jet","RdBu_r","jet"]
1932 cmapList = ["jet","RdBu_r","jet"]
1932
1933
1933 for i in range(self.nPairs):
1934 for i in range(self.nPairs):
1934 strAux1 = "Phase Difference "+ str(pairsList[i][0]) + str(pairsList[i][1])
1935 strAux1 = "Phase Difference "+ str(pairsList[i][0]) + str(pairsList[i][1])
1935 titleList = titleList + [strAux1]
1936 titleList = titleList + [strAux1]
1936 cmapList = cmapList + ["RdBu_r"]
1937 cmapList = cmapList + ["RdBu_r"]
1937
1938
1938 self.zminList = zminList
1939 self.zminList = zminList
1939 self.zmaxList = zmaxList
1940 self.zmaxList = zmaxList
1940 self.cmapList = cmapList
1941 self.cmapList = cmapList
1941 self.titleList = titleList
1942 self.titleList = titleList
1942
1943
1943 self.FTP_WEI = ftp_wei
1944 self.FTP_WEI = ftp_wei
1944 self.EXP_CODE = exp_code
1945 self.EXP_CODE = exp_code
1945 self.SUB_EXP_CODE = sub_exp_code
1946 self.SUB_EXP_CODE = sub_exp_code
1946 self.PLOT_POS = plot_pos
1947 self.PLOT_POS = plot_pos
1947
1948
1948 self.isConfig = True
1949 self.isConfig = True
1949
1950
1950 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
1951 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
1951
1952
1952 for i in range(nParam):
1953 for i in range(nParam):
1953 title = self.titleList[i] + ": " +str_datetime
1954 title = self.titleList[i] + ": " +str_datetime
1954 axes = self.axesList[i]
1955 axes = self.axesList[i]
1955 axes.pcolor(x, y, z[i,:].T,
1956 axes.pcolor(x, y, z[i,:].T,
1956 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
1957 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
1957 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
1958 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
1958 self.draw()
1959 self.draw()
1959
1960
1960 if figfile == None:
1961 if figfile == None:
1961 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
1962 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
1962 name = str_datetime
1963 name = str_datetime
1963 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1964 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1964 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
1965 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
1965 figfile = self.getFilename(name)
1966 figfile = self.getFilename(name)
1966
1967
1967 self.save(figpath=figpath,
1968 self.save(figpath=figpath,
1968 figfile=figfile,
1969 figfile=figfile,
1969 save=save,
1970 save=save,
1970 ftp=ftp,
1971 ftp=ftp,
1971 wr_period=wr_period,
1972 wr_period=wr_period,
1972 thisDatetime=thisDatetime)
1973 thisDatetime=thisDatetime)
1973
1974
1974
1975
1975 class NSMeteorDetection2Plot(Figure):
1976 class NSMeteorDetection2Plot(Figure):
1976
1977
1977 isConfig = None
1978 isConfig = None
1978 __nsubplots = None
1979 __nsubplots = None
1979
1980
1980 WIDTHPROF = None
1981 WIDTHPROF = None
1981 HEIGHTPROF = None
1982 HEIGHTPROF = None
1982 PREFIX = 'nsm'
1983 PREFIX = 'nsm'
1983
1984
1984 zminList = None
1985 zminList = None
1985 zmaxList = None
1986 zmaxList = None
1986 cmapList = None
1987 cmapList = None
1987 titleList = None
1988 titleList = None
1988 nPairs = None
1989 nPairs = None
1989 nChannels = None
1990 nChannels = None
1990 nParam = None
1991 nParam = None
1991
1992
1992 def __init__(self, **kwargs):
1993 def __init__(self, **kwargs):
1993 Figure.__init__(self, **kwargs)
1994 Figure.__init__(self, **kwargs)
1994 self.isConfig = False
1995 self.isConfig = False
1995 self.__nsubplots = 1
1996 self.__nsubplots = 1
1996
1997
1997 self.WIDTH = 750
1998 self.WIDTH = 750
1998 self.HEIGHT = 250
1999 self.HEIGHT = 250
1999 self.WIDTHPROF = 120
2000 self.WIDTHPROF = 120
2000 self.HEIGHTPROF = 0
2001 self.HEIGHTPROF = 0
2001 self.counter_imagwr = 0
2002 self.counter_imagwr = 0
2002
2003
2003 self.PLOT_CODE = SPEC_CODE
2004 self.PLOT_CODE = SPEC_CODE
2004
2005
2005 self.FTP_WEI = None
2006 self.FTP_WEI = None
2006 self.EXP_CODE = None
2007 self.EXP_CODE = None
2007 self.SUB_EXP_CODE = None
2008 self.SUB_EXP_CODE = None
2008 self.PLOT_POS = None
2009 self.PLOT_POS = None
2009
2010
2010 self.__xfilter_ena = False
2011 self.__xfilter_ena = False
2011 self.__yfilter_ena = False
2012 self.__yfilter_ena = False
2012
2013
2013 def getSubplots(self):
2014 def getSubplots(self):
2014
2015
2015 ncol = 3
2016 ncol = 3
2016 nrow = int(numpy.ceil(self.nplots/3.0))
2017 nrow = int(numpy.ceil(self.nplots/3.0))
2017
2018
2018 return nrow, ncol
2019 return nrow, ncol
2019
2020
2020 def setup(self, id, nplots, wintitle, show=True):
2021 def setup(self, id, nplots, wintitle, show=True):
2021
2022
2022 self.nplots = nplots
2023 self.nplots = nplots
2023
2024
2024 ncolspan = 1
2025 ncolspan = 1
2025 colspan = 1
2026 colspan = 1
2026
2027
2027 self.createFigure(id = id,
2028 self.createFigure(id = id,
2028 wintitle = wintitle,
2029 wintitle = wintitle,
2029 widthplot = self.WIDTH + self.WIDTHPROF,
2030 widthplot = self.WIDTH + self.WIDTHPROF,
2030 heightplot = self.HEIGHT + self.HEIGHTPROF,
2031 heightplot = self.HEIGHT + self.HEIGHTPROF,
2031 show=show)
2032 show=show)
2032
2033
2033 nrow, ncol = self.getSubplots()
2034 nrow, ncol = self.getSubplots()
2034
2035
2035 counter = 0
2036 counter = 0
2036 for y in range(nrow):
2037 for y in range(nrow):
2037 for x in range(ncol):
2038 for x in range(ncol):
2038
2039
2039 if counter >= self.nplots:
2040 if counter >= self.nplots:
2040 break
2041 break
2041
2042
2042 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
2043 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
2043
2044
2044 counter += 1
2045 counter += 1
2045
2046
2046 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
2047 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
2047 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
2048 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
2048 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
2049 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
2049 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
2050 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
2050 server=None, folder=None, username=None, password=None,
2051 server=None, folder=None, username=None, password=None,
2051 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
2052 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
2052 xaxis="frequency"):
2053 xaxis="frequency"):
2053
2054
2054 """
2055 """
2055
2056
2056 Input:
2057 Input:
2057 dataOut :
2058 dataOut :
2058 id :
2059 id :
2059 wintitle :
2060 wintitle :
2060 channelList :
2061 channelList :
2061 showProfile :
2062 showProfile :
2062 xmin : None,
2063 xmin : None,
2063 xmax : None,
2064 xmax : None,
2064 ymin : None,
2065 ymin : None,
2065 ymax : None,
2066 ymax : None,
2066 zmin : None,
2067 zmin : None,
2067 zmax : None
2068 zmax : None
2068 """
2069 """
2069 #Rebuild matrix
2070 #Rebuild matrix
2070 utctime = dataOut.data_param[0,0]
2071 utctime = dataOut.data_param[0,0]
2071 cmet = dataOut.data_param[:,1].astype(int)
2072 cmet = dataOut.data_param[:,1].astype(int)
2072 tmet = dataOut.data_param[:,2].astype(int)
2073 tmet = dataOut.data_param[:,2].astype(int)
2073 hmet = dataOut.data_param[:,3].astype(int)
2074 hmet = dataOut.data_param[:,3].astype(int)
2074
2075
2075 nParam = 3
2076 nParam = 3
2076 nChan = len(dataOut.groupList)
2077 nChan = len(dataOut.groupList)
2077 x = dataOut.abscissaList
2078 x = dataOut.abscissaList
2078 y = dataOut.heightList
2079 y = dataOut.heightList
2079
2080
2080 z = numpy.full((nChan, nParam, y.size, x.size - 1),numpy.nan)
2081 z = numpy.full((nChan, nParam, y.size, x.size - 1),numpy.nan)
2081 z[cmet,:,hmet,tmet] = dataOut.data_param[:,4:]
2082 z[cmet,:,hmet,tmet] = dataOut.data_param[:,4:]
2082 z[:,0,:,:] = 10*numpy.log10(z[:,0,:,:]) #logarithmic scale
2083 z[:,0,:,:] = 10*numpy.log10(z[:,0,:,:]) #logarithmic scale
2083 z = numpy.reshape(z, (nChan*nParam, y.size, x.size-1))
2084 z = numpy.reshape(z, (nChan*nParam, y.size, x.size-1))
2084
2085
2085 xlabel = "Time (s)"
2086 xlabel = "Time (s)"
2086 ylabel = "Range (km)"
2087 ylabel = "Range (km)"
2087
2088
2088 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
2089 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
2089
2090
2090 if not self.isConfig:
2091 if not self.isConfig:
2091
2092
2092 nplots = nParam*nChan
2093 nplots = nParam*nChan
2093
2094
2094 self.setup(id=id,
2095 self.setup(id=id,
2095 nplots=nplots,
2096 nplots=nplots,
2096 wintitle=wintitle,
2097 wintitle=wintitle,
2097 show=show)
2098 show=show)
2098
2099
2099 if xmin is None: xmin = numpy.nanmin(x)
2100 if xmin is None: xmin = numpy.nanmin(x)
2100 if xmax is None: xmax = numpy.nanmax(x)
2101 if xmax is None: xmax = numpy.nanmax(x)
2101 if ymin is None: ymin = numpy.nanmin(y)
2102 if ymin is None: ymin = numpy.nanmin(y)
2102 if ymax is None: ymax = numpy.nanmax(y)
2103 if ymax is None: ymax = numpy.nanmax(y)
2103 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
2104 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
2104 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
2105 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
2105 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
2106 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
2106 if vmin is None: vmin = -vmax
2107 if vmin is None: vmin = -vmax
2107 if wmin is None: wmin = 0
2108 if wmin is None: wmin = 0
2108 if wmax is None: wmax = 50
2109 if wmax is None: wmax = 50
2109
2110
2110 self.nChannels = nChan
2111 self.nChannels = nChan
2111
2112
2112 zminList = []
2113 zminList = []
2113 zmaxList = []
2114 zmaxList = []
2114 titleList = []
2115 titleList = []
2115 cmapList = []
2116 cmapList = []
2116 for i in range(self.nChannels):
2117 for i in range(self.nChannels):
2117 strAux1 = "SNR Channel "+ str(i)
2118 strAux1 = "SNR Channel "+ str(i)
2118 strAux2 = "Radial Velocity Channel "+ str(i)
2119 strAux2 = "Radial Velocity Channel "+ str(i)
2119 strAux3 = "Spectral Width Channel "+ str(i)
2120 strAux3 = "Spectral Width Channel "+ str(i)
2120
2121
2121 titleList = titleList + [strAux1,strAux2,strAux3]
2122 titleList = titleList + [strAux1,strAux2,strAux3]
2122 cmapList = cmapList + ["jet","RdBu_r","jet"]
2123 cmapList = cmapList + ["jet","RdBu_r","jet"]
2123 zminList = zminList + [SNRmin,vmin,wmin]
2124 zminList = zminList + [SNRmin,vmin,wmin]
2124 zmaxList = zmaxList + [SNRmax,vmax,wmax]
2125 zmaxList = zmaxList + [SNRmax,vmax,wmax]
2125
2126
2126 self.zminList = zminList
2127 self.zminList = zminList
2127 self.zmaxList = zmaxList
2128 self.zmaxList = zmaxList
2128 self.cmapList = cmapList
2129 self.cmapList = cmapList
2129 self.titleList = titleList
2130 self.titleList = titleList
2130
2131
2131 self.FTP_WEI = ftp_wei
2132 self.FTP_WEI = ftp_wei
2132 self.EXP_CODE = exp_code
2133 self.EXP_CODE = exp_code
2133 self.SUB_EXP_CODE = sub_exp_code
2134 self.SUB_EXP_CODE = sub_exp_code
2134 self.PLOT_POS = plot_pos
2135 self.PLOT_POS = plot_pos
2135
2136
2136 self.isConfig = True
2137 self.isConfig = True
2137
2138
2138 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
2139 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
2139
2140
2140 for i in range(self.nplots):
2141 for i in range(self.nplots):
2141 title = self.titleList[i] + ": " +str_datetime
2142 title = self.titleList[i] + ": " +str_datetime
2142 axes = self.axesList[i]
2143 axes = self.axesList[i]
2143 axes.pcolor(x, y, z[i,:].T,
2144 axes.pcolor(x, y, z[i,:].T,
2144 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
2145 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
2145 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
2146 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
2146 self.draw()
2147 self.draw()
2147
2148
2148 if figfile == None:
2149 if figfile == None:
2149 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
2150 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
2150 name = str_datetime
2151 name = str_datetime
2151 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
2152 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
2152 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
2153 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
2153 figfile = self.getFilename(name)
2154 figfile = self.getFilename(name)
2154
2155
2155 self.save(figpath=figpath,
2156 self.save(figpath=figpath,
2156 figfile=figfile,
2157 figfile=figfile,
2157 save=save,
2158 save=save,
2158 ftp=ftp,
2159 ftp=ftp,
2159 wr_period=wr_period,
2160 wr_period=wr_period,
2160 thisDatetime=thisDatetime)
2161 thisDatetime=thisDatetime)
@@ -1,1605 +1,1605
1 '''
1 '''
2 Created on Jul 9, 2014
2 Created on Jul 9, 2014
3
3
4 @author: roj-idl71
4 @author: roj-idl71
5 '''
5 '''
6 import os
6 import os
7 import datetime
7 import datetime
8 import numpy
8 import numpy
9
9
10 import matplotlib.pyplot as plt
10 import matplotlib.pyplot as plt
11
11
12 from figure import Figure, isRealtime, isTimeInHourRange
12 from figure import Figure, isRealtime, isTimeInHourRange
13 from plotting_codes import *
13 from plotting_codes import *
14 from matplotlib.pyplot import savefig
14 from matplotlib.pyplot import savefig
15
15
16 class SpectraPlot(Figure):
16 class SpectraPlot(Figure):
17
17
18 isConfig = None
18 isConfig = None
19 __nsubplots = None
19 __nsubplots = None
20
20
21 WIDTHPROF = None
21 WIDTHPROF = None
22 HEIGHTPROF = None
22 HEIGHTPROF = None
23 PREFIX = 'spc'
23 PREFIX = 'spc'
24
24
25 def __init__(self, **kwargs):
25 def __init__(self, **kwargs):
26 Figure.__init__(self, **kwargs)
26 Figure.__init__(self, **kwargs)
27 self.isConfig = False
27 self.isConfig = False
28 self.__nsubplots = 1
28 self.__nsubplots = 1
29
29
30 self.WIDTH = 300
30 self.WIDTH = 300
31 self.HEIGHT = 300
31 self.HEIGHT = 300
32 self.WIDTHPROF = 120
32 self.WIDTHPROF = 120
33 self.HEIGHTPROF = 0
33 self.HEIGHTPROF = 0
34 self.counter_imagwr = 0
34 self.counter_imagwr = 0
35
35
36 self.PLOT_CODE = SPEC_CODE
36 self.PLOT_CODE = SPEC_CODE
37
37
38 self.FTP_WEI = None
38 self.FTP_WEI = None
39 self.EXP_CODE = None
39 self.EXP_CODE = None
40 self.SUB_EXP_CODE = None
40 self.SUB_EXP_CODE = None
41 self.PLOT_POS = None
41 self.PLOT_POS = None
42
42
43 self.__xfilter_ena = False
43 self.__xfilter_ena = False
44 self.__yfilter_ena = False
44 self.__yfilter_ena = False
45
45
46 self.indice=1
46 self.indice=1
47
47
48 def getSubplots(self):
48 def getSubplots(self):
49
49
50 ncol = int(numpy.sqrt(self.nplots)+0.9)
50 ncol = int(numpy.sqrt(self.nplots)+0.9)
51 nrow = int(self.nplots*1./ncol + 0.9)
51 nrow = int(self.nplots*1./ncol + 0.9)
52
52
53 return nrow, ncol
53 return nrow, ncol
54
54
55 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
55 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
56
56
57 self.__showprofile = showprofile
57 self.__showprofile = showprofile
58 self.nplots = nplots
58 self.nplots = nplots
59
59
60 ncolspan = 1
60 ncolspan = 1
61 colspan = 1
61 colspan = 1
62 if showprofile:
62 if showprofile:
63 ncolspan = 3
63 ncolspan = 3
64 colspan = 2
64 colspan = 2
65 self.__nsubplots = 2
65 self.__nsubplots = 2
66
66
67 self.createFigure(id = id,
67 self.createFigure(id = id,
68 wintitle = wintitle,
68 wintitle = wintitle,
69 widthplot = self.WIDTH + self.WIDTHPROF,
69 widthplot = self.WIDTH + self.WIDTHPROF,
70 heightplot = self.HEIGHT + self.HEIGHTPROF,
70 heightplot = self.HEIGHT + self.HEIGHTPROF,
71 show=show)
71 show=show)
72
72
73 nrow, ncol = self.getSubplots()
73 nrow, ncol = self.getSubplots()
74
74
75 counter = 0
75 counter = 0
76 for y in range(nrow):
76 for y in range(nrow):
77 for x in range(ncol):
77 for x in range(ncol):
78
78
79 if counter >= self.nplots:
79 if counter >= self.nplots:
80 break
80 break
81
81
82 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
82 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
83
83
84 if showprofile:
84 if showprofile:
85 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
85 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
86
86
87 counter += 1
87 counter += 1
88
88
89 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
89 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
90 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
90 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
91 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
91 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
92 server=None, folder=None, username=None, password=None,
92 server=None, folder=None, username=None, password=None,
93 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
93 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
94 xaxis="frequency", colormap='jet', normFactor=None):
94 xaxis="frequency", colormap='jet', normFactor=None):
95
95
96 """
96 """
97
97
98 Input:
98 Input:
99 dataOut :
99 dataOut :
100 id :
100 id :
101 wintitle :
101 wintitle :
102 channelList :
102 channelList :
103 showProfile :
103 showProfile :
104 xmin : None,
104 xmin : None,
105 xmax : None,
105 xmax : None,
106 ymin : None,
106 ymin : None,
107 ymax : None,
107 ymax : None,
108 zmin : None,
108 zmin : None,
109 zmax : None
109 zmax : None
110 """
110 """
111 if realtime:
111 if realtime:
112 if not(isRealtime(utcdatatime = dataOut.utctime)):
112 if not(isRealtime(utcdatatime = dataOut.utctime)):
113 print 'Skipping this plot function'
113 print 'Skipping this plot function'
114 return
114 return
115
115
116 if channelList == None:
116 if channelList == None:
117 channelIndexList = dataOut.channelIndexList
117 channelIndexList = dataOut.channelIndexList
118 else:
118 else:
119 channelIndexList = []
119 channelIndexList = []
120 for channel in channelList:
120 for channel in channelList:
121 if channel not in dataOut.channelList:
121 if channel not in dataOut.channelList:
122 raise ValueError, "Channel %d is not in dataOut.channelList" %channel
122 raise ValueError, "Channel %d is not in dataOut.channelList" %channel
123 channelIndexList.append(dataOut.channelList.index(channel))
123 channelIndexList.append(dataOut.channelList.index(channel))
124
124
125 if normFactor is None:
125 if normFactor is None:
126 factor = dataOut.normFactor
126 factor = dataOut.normFactor
127 else:
127 else:
128 factor = normFactor
128 factor = normFactor
129 if xaxis == "frequency":
129 if xaxis == "frequency":
130 x = dataOut.getFreqRange(1)/1000.
130 x = dataOut.getFreqRange(1)/1000.
131 xlabel = "Frequency (kHz)"
131 xlabel = "Frequency (kHz)"
132
132
133 elif xaxis == "time":
133 elif xaxis == "time":
134 x = dataOut.getAcfRange(1)
134 x = dataOut.getAcfRange(1)
135 xlabel = "Time (ms)"
135 xlabel = "Time (ms)"
136
136
137 else:
137 else:
138 x = dataOut.getVelRange(1)
138 x = dataOut.getVelRange(1)
139 xlabel = "Velocity (m/s)"
139 xlabel = "Velocity (m/s)"
140
140
141 ylabel = "Range (Km)"
141 ylabel = "Range (Km)"
142
142
143 y = dataOut.getHeiRange()
143 y = dataOut.getHeiRange()
144
144 print 'dataOut.normFactor', dataOut.normFactor
145 z = dataOut.data_spc/factor
145 z = dataOut.data_spc/factor
146 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
146 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
147 zdB = 10*numpy.log10(z)
147 zdB = 10*numpy.log10(z)
148
148
149 avg = numpy.average(z, axis=1)
149 avg = numpy.average(z, axis=1)
150 avgdB = 10*numpy.log10(avg)
150 avgdB = 10*numpy.log10(avg)
151
151
152 noise = dataOut.getNoise()/factor
152 noise = dataOut.getNoise()/factor
153 noisedB = 10*numpy.log10(noise)
153 noisedB = 10*numpy.log10(noise)
154
154
155 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
155 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
156 title = wintitle + " Spectra"
156 title = wintitle + " Spectra"
157
157
158
158
159
159
160 print 'len de X',len(x), numpy.shape(x), 'len de spc line',len(dataOut.data_spc[1,:,15]), numpy.shape(dataOut.data_spc)
160 print 'len de X',len(x), numpy.shape(x), 'len de spc line',len(dataOut.data_spc[1,:,15]), numpy.shape(dataOut.data_spc)
161 print 'Altura:', y[0], y[1], y[13], y[14], y[10]
161 print 'Altura:', y[0], y[1], y[13], y[14], y[10]
162 #a=z[1,:,15]
162 #a=z[1,:,15]
163
163
164 # fig = plt.figure(10+self.indice)
164 # fig = plt.figure(10+self.indice)
165 # plt.plot( x[0:128], zdB[0,:,10] )
165 # plt.plot( x[0:128], zdB[0,:,10] )
166 # plt.axis([-12, 12, 15, 50])
166 # plt.axis([-12, 12, 15, 50])
167 # plt.title(" %s" %( '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))) )
167 # plt.title(" %s" %( '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))) )
168 # plt.ylabel('Intensidad [dB]')
168 # plt.ylabel('Intensidad [dB]')
169 # plt.xlabel('Velocidad [m/s]')
169 # plt.xlabel('Velocidad [m/s]')
170 # fig.savefig('/home/erick/Documents/Pics/to{}.png'.format(self.indice))
170 # fig.savefig('/home/erick/Documents/Pics/to{}.png'.format(self.indice))
171 #
171 #
172 # plt.show()
172 # plt.show()
173 #
173 #
174 # self.indice=self.indice+1
174 # self.indice=self.indice+1
175
175
176
176
177
177
178 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
178 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
179 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
179 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
180
180
181 if not self.isConfig:
181 if not self.isConfig:
182
182
183 nplots = len(channelIndexList)
183 nplots = len(channelIndexList)
184
184
185 self.setup(id=id,
185 self.setup(id=id,
186 nplots=nplots,
186 nplots=nplots,
187 wintitle=wintitle,
187 wintitle=wintitle,
188 showprofile=showprofile,
188 showprofile=showprofile,
189 show=show)
189 show=show)
190
190
191 if xmin == None: xmin = numpy.nanmin(x)
191 if xmin == None: xmin = numpy.nanmin(x)
192 if xmax == None: xmax = numpy.nanmax(x)
192 if xmax == None: xmax = numpy.nanmax(x)
193 if ymin == None: ymin = numpy.nanmin(y)
193 if ymin == None: ymin = numpy.nanmin(y)
194 if ymax == None: ymax = numpy.nanmax(y)
194 if ymax == None: ymax = numpy.nanmax(y)
195 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
195 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
196 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
196 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
197
197
198 self.FTP_WEI = ftp_wei
198 self.FTP_WEI = ftp_wei
199 self.EXP_CODE = exp_code
199 self.EXP_CODE = exp_code
200 self.SUB_EXP_CODE = sub_exp_code
200 self.SUB_EXP_CODE = sub_exp_code
201 self.PLOT_POS = plot_pos
201 self.PLOT_POS = plot_pos
202
202
203 self.isConfig = True
203 self.isConfig = True
204
204
205 self.setWinTitle(title)
205 self.setWinTitle(title)
206
206
207 for i in range(self.nplots):
207 for i in range(self.nplots):
208 index = channelIndexList[i]
208 index = channelIndexList[i]
209 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
209 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
210 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime)
210 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime)
211 if len(dataOut.beam.codeList) != 0:
211 if len(dataOut.beam.codeList) != 0:
212 title = "Ch%d:%4.2fdB,%2.2f,%2.2f:%s" %(dataOut.channelList[index], noisedB[index], dataOut.beam.azimuthList[index], dataOut.beam.zenithList[index], str_datetime)
212 title = "Ch%d:%4.2fdB,%2.2f,%2.2f:%s" %(dataOut.channelList[index], noisedB[index], dataOut.beam.azimuthList[index], dataOut.beam.zenithList[index], str_datetime)
213
213
214 axes = self.axesList[i*self.__nsubplots]
214 axes = self.axesList[i*self.__nsubplots]
215 axes.pcolor(x, y, zdB[index,:,:],
215 axes.pcolor(x, y, zdB[index,:,:],
216 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
216 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
217 xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap,
217 xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap,
218 ticksize=9, cblabel='')
218 ticksize=9, cblabel='')
219
219
220 if self.__showprofile:
220 if self.__showprofile:
221 axes = self.axesList[i*self.__nsubplots +1]
221 axes = self.axesList[i*self.__nsubplots +1]
222 axes.pline(avgdB[index,:], y,
222 axes.pline(avgdB[index,:], y,
223 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
223 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
224 xlabel='dB', ylabel='', title='',
224 xlabel='dB', ylabel='', title='',
225 ytick_visible=False,
225 ytick_visible=False,
226 grid='x')
226 grid='x')
227
227
228 noiseline = numpy.repeat(noisedB[index], len(y))
228 noiseline = numpy.repeat(noisedB[index], len(y))
229 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
229 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
230
230
231 self.draw()
231 self.draw()
232
232
233 if figfile == None:
233 if figfile == None:
234 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
234 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
235 name = str_datetime
235 name = str_datetime
236 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
236 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
237 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
237 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
238 figfile = self.getFilename(name)
238 figfile = self.getFilename(name)
239
239
240 self.save(figpath=figpath,
240 self.save(figpath=figpath,
241 figfile=figfile,
241 figfile=figfile,
242 save=save,
242 save=save,
243 ftp=ftp,
243 ftp=ftp,
244 wr_period=wr_period,
244 wr_period=wr_period,
245 thisDatetime=thisDatetime)
245 thisDatetime=thisDatetime)
246
246
247
247
248 class CrossSpectraPlot(Figure):
248 class CrossSpectraPlot(Figure):
249
249
250 isConfig = None
250 isConfig = None
251 __nsubplots = None
251 __nsubplots = None
252
252
253 WIDTH = None
253 WIDTH = None
254 HEIGHT = None
254 HEIGHT = None
255 WIDTHPROF = None
255 WIDTHPROF = None
256 HEIGHTPROF = None
256 HEIGHTPROF = None
257 PREFIX = 'cspc'
257 PREFIX = 'cspc'
258
258
259 def __init__(self, **kwargs):
259 def __init__(self, **kwargs):
260 Figure.__init__(self, **kwargs)
260 Figure.__init__(self, **kwargs)
261 self.isConfig = False
261 self.isConfig = False
262 self.__nsubplots = 4
262 self.__nsubplots = 4
263 self.counter_imagwr = 0
263 self.counter_imagwr = 0
264 self.WIDTH = 250
264 self.WIDTH = 250
265 self.HEIGHT = 250
265 self.HEIGHT = 250
266 self.WIDTHPROF = 0
266 self.WIDTHPROF = 0
267 self.HEIGHTPROF = 0
267 self.HEIGHTPROF = 0
268
268
269 self.PLOT_CODE = CROSS_CODE
269 self.PLOT_CODE = CROSS_CODE
270 self.FTP_WEI = None
270 self.FTP_WEI = None
271 self.EXP_CODE = None
271 self.EXP_CODE = None
272 self.SUB_EXP_CODE = None
272 self.SUB_EXP_CODE = None
273 self.PLOT_POS = None
273 self.PLOT_POS = None
274
274
275 self.indice=0
275 self.indice=0
276
276
277 def getSubplots(self):
277 def getSubplots(self):
278
278
279 ncol = 4
279 ncol = 4
280 nrow = self.nplots
280 nrow = self.nplots
281
281
282 return nrow, ncol
282 return nrow, ncol
283
283
284 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
284 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
285
285
286 self.__showprofile = showprofile
286 self.__showprofile = showprofile
287 self.nplots = nplots
287 self.nplots = nplots
288
288
289 ncolspan = 1
289 ncolspan = 1
290 colspan = 1
290 colspan = 1
291
291
292 self.createFigure(id = id,
292 self.createFigure(id = id,
293 wintitle = wintitle,
293 wintitle = wintitle,
294 widthplot = self.WIDTH + self.WIDTHPROF,
294 widthplot = self.WIDTH + self.WIDTHPROF,
295 heightplot = self.HEIGHT + self.HEIGHTPROF,
295 heightplot = self.HEIGHT + self.HEIGHTPROF,
296 show=True)
296 show=True)
297
297
298 nrow, ncol = self.getSubplots()
298 nrow, ncol = self.getSubplots()
299
299
300 counter = 0
300 counter = 0
301 for y in range(nrow):
301 for y in range(nrow):
302 for x in range(ncol):
302 for x in range(ncol):
303 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
303 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
304
304
305 counter += 1
305 counter += 1
306
306
307 def run(self, dataOut, id, wintitle="", pairsList=None,
307 def run(self, dataOut, id, wintitle="", pairsList=None,
308 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
308 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
309 coh_min=None, coh_max=None, phase_min=None, phase_max=None,
309 coh_min=None, coh_max=None, phase_min=None, phase_max=None,
310 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
310 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
311 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
311 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
312 server=None, folder=None, username=None, password=None,
312 server=None, folder=None, username=None, password=None,
313 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None,
313 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None,
314 xaxis='frequency'):
314 xaxis='frequency'):
315
315
316 """
316 """
317
317
318 Input:
318 Input:
319 dataOut :
319 dataOut :
320 id :
320 id :
321 wintitle :
321 wintitle :
322 channelList :
322 channelList :
323 showProfile :
323 showProfile :
324 xmin : None,
324 xmin : None,
325 xmax : None,
325 xmax : None,
326 ymin : None,
326 ymin : None,
327 ymax : None,
327 ymax : None,
328 zmin : None,
328 zmin : None,
329 zmax : None
329 zmax : None
330 """
330 """
331
331
332 if pairsList == None:
332 if pairsList == None:
333 pairsIndexList = dataOut.pairsIndexList
333 pairsIndexList = dataOut.pairsIndexList
334 else:
334 else:
335 pairsIndexList = []
335 pairsIndexList = []
336 for pair in pairsList:
336 for pair in pairsList:
337 if pair not in dataOut.pairsList:
337 if pair not in dataOut.pairsList:
338 raise ValueError, "Pair %s is not in dataOut.pairsList" %str(pair)
338 raise ValueError, "Pair %s is not in dataOut.pairsList" %str(pair)
339 pairsIndexList.append(dataOut.pairsList.index(pair))
339 pairsIndexList.append(dataOut.pairsList.index(pair))
340
340
341 if not pairsIndexList:
341 if not pairsIndexList:
342 return
342 return
343
343
344 if len(pairsIndexList) > 4:
344 if len(pairsIndexList) > 4:
345 pairsIndexList = pairsIndexList[0:4]
345 pairsIndexList = pairsIndexList[0:4]
346
346
347 if normFactor is None:
347 if normFactor is None:
348 factor = dataOut.normFactor
348 factor = dataOut.normFactor
349 else:
349 else:
350 factor = normFactor
350 factor = normFactor
351 x = dataOut.getVelRange(1)
351 x = dataOut.getVelRange(1)
352 y = dataOut.getHeiRange()
352 y = dataOut.getHeiRange()
353 z = dataOut.data_spc[:,:,:]/factor
353 z = dataOut.data_spc[:,:,:]/factor
354 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
354 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
355
355
356 noise = dataOut.noise/factor
356 noise = dataOut.noise/factor
357
357
358 zdB = 10*numpy.log10(z)
358 zdB = 10*numpy.log10(z)
359 noisedB = 10*numpy.log10(noise)
359 noisedB = 10*numpy.log10(noise)
360
360
361 if coh_min == None:
361 if coh_min == None:
362 coh_min = 0.0
362 coh_min = 0.0
363 if coh_max == None:
363 if coh_max == None:
364 coh_max = 1.0
364 coh_max = 1.0
365
365
366 if phase_min == None:
366 if phase_min == None:
367 phase_min = -180
367 phase_min = -180
368 if phase_max == None:
368 if phase_max == None:
369 phase_max = 180
369 phase_max = 180
370
370
371 #thisDatetime = dataOut.datatime
371 #thisDatetime = dataOut.datatime
372 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
372 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
373 title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
373 title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
374 # xlabel = "Velocity (m/s)"
374 # xlabel = "Velocity (m/s)"
375 ylabel = "Range (Km)"
375 ylabel = "Range (Km)"
376
376
377 if xaxis == "frequency":
377 if xaxis == "frequency":
378 x = dataOut.getFreqRange(1)/1000.
378 x = dataOut.getFreqRange(1)/1000.
379 xlabel = "Frequency (kHz)"
379 xlabel = "Frequency (kHz)"
380
380
381 elif xaxis == "time":
381 elif xaxis == "time":
382 x = dataOut.getAcfRange(1)
382 x = dataOut.getAcfRange(1)
383 xlabel = "Time (ms)"
383 xlabel = "Time (ms)"
384
384
385 else:
385 else:
386 x = dataOut.getVelRange(1)
386 x = dataOut.getVelRange(1)
387 xlabel = "Velocity (m/s)"
387 xlabel = "Velocity (m/s)"
388
388
389 if not self.isConfig:
389 if not self.isConfig:
390
390
391 nplots = len(pairsIndexList)
391 nplots = len(pairsIndexList)
392
392
393 self.setup(id=id,
393 self.setup(id=id,
394 nplots=nplots,
394 nplots=nplots,
395 wintitle=wintitle,
395 wintitle=wintitle,
396 showprofile=False,
396 showprofile=False,
397 show=show)
397 show=show)
398
398
399 avg = numpy.abs(numpy.average(z, axis=1))
399 avg = numpy.abs(numpy.average(z, axis=1))
400 avgdB = 10*numpy.log10(avg)
400 avgdB = 10*numpy.log10(avg)
401
401
402 if xmin == None: xmin = numpy.nanmin(x)
402 if xmin == None: xmin = numpy.nanmin(x)
403 if xmax == None: xmax = numpy.nanmax(x)
403 if xmax == None: xmax = numpy.nanmax(x)
404 if ymin == None: ymin = numpy.nanmin(y)
404 if ymin == None: ymin = numpy.nanmin(y)
405 if ymax == None: ymax = numpy.nanmax(y)
405 if ymax == None: ymax = numpy.nanmax(y)
406 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
406 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
407 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
407 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
408
408
409 self.FTP_WEI = ftp_wei
409 self.FTP_WEI = ftp_wei
410 self.EXP_CODE = exp_code
410 self.EXP_CODE = exp_code
411 self.SUB_EXP_CODE = sub_exp_code
411 self.SUB_EXP_CODE = sub_exp_code
412 self.PLOT_POS = plot_pos
412 self.PLOT_POS = plot_pos
413
413
414 self.isConfig = True
414 self.isConfig = True
415
415
416 self.setWinTitle(title)
416 self.setWinTitle(title)
417
417
418
418
419 for i in range(self.nplots):
419 for i in range(self.nplots):
420 pair = dataOut.pairsList[pairsIndexList[i]]
420 pair = dataOut.pairsList[pairsIndexList[i]]
421
421
422 chan_index0 = dataOut.channelList.index(pair[0])
422 chan_index0 = dataOut.channelList.index(pair[0])
423 chan_index1 = dataOut.channelList.index(pair[1])
423 chan_index1 = dataOut.channelList.index(pair[1])
424
424
425 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
425 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
426 title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[chan_index0], str_datetime)
426 title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[chan_index0], str_datetime)
427 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index0,:,:]/factor)
427 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index0,:,:]/factor)
428 axes0 = self.axesList[i*self.__nsubplots]
428 axes0 = self.axesList[i*self.__nsubplots]
429 axes0.pcolor(x, y, zdB,
429 axes0.pcolor(x, y, zdB,
430 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
430 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
431 xlabel=xlabel, ylabel=ylabel, title=title,
431 xlabel=xlabel, ylabel=ylabel, title=title,
432 ticksize=9, colormap=power_cmap, cblabel='')
432 ticksize=9, colormap=power_cmap, cblabel='')
433
433
434 title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[chan_index1], str_datetime)
434 title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[chan_index1], str_datetime)
435 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index1,:,:]/factor)
435 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index1,:,:]/factor)
436 axes0 = self.axesList[i*self.__nsubplots+1]
436 axes0 = self.axesList[i*self.__nsubplots+1]
437 axes0.pcolor(x, y, zdB,
437 axes0.pcolor(x, y, zdB,
438 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
438 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
439 xlabel=xlabel, ylabel=ylabel, title=title,
439 xlabel=xlabel, ylabel=ylabel, title=title,
440 ticksize=9, colormap=power_cmap, cblabel='')
440 ticksize=9, colormap=power_cmap, cblabel='')
441
441
442 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:] / numpy.sqrt( dataOut.data_spc[chan_index0,:,:]*dataOut.data_spc[chan_index1,:,:] )
442 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:] / numpy.sqrt( dataOut.data_spc[chan_index0,:,:]*dataOut.data_spc[chan_index1,:,:] )
443 coherence = numpy.abs(coherenceComplex)
443 coherence = numpy.abs(coherenceComplex)
444 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
444 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
445 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
445 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
446
446
447
447
448
448
449
449
450 # #print 'FASE', numpy.shape(phase), y[25]
450 # #print 'FASE', numpy.shape(phase), y[25]
451 # fig = plt.figure(10+self.indice)
451 # fig = plt.figure(10+self.indice)
452 # #plt.plot( x[0:256],coherence[:,25] )
452 # #plt.plot( x[0:256],coherence[:,25] )
453 # cohAv = numpy.average(coherence,1)
453 # cohAv = numpy.average(coherence,1)
454 #
454 #
455 # plt.plot( x[0:256],cohAv )
455 # plt.plot( x[0:256],cohAv )
456 # #plt.axis([-12, 12, 15, 50])
456 # #plt.axis([-12, 12, 15, 50])
457 # plt.title("%s" %( '%s %s, Channel %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S") , i)))
457 # plt.title("%s" %( '%s %s, Channel %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S") , i)))
458 # plt.ylabel('Desfase [grados]')
458 # plt.ylabel('Desfase [grados]')
459 # plt.xlabel('Velocidad [m/s]')
459 # plt.xlabel('Velocidad [m/s]')
460 # fig.savefig('/home/erick/Documents/Pics/to{}.png'.format(self.indice))
460 # fig.savefig('/home/erick/Documents/Pics/to{}.png'.format(self.indice))
461 #
461 #
462 # plt.show()
462 # plt.show()
463 # self.indice=self.indice+1
463 # self.indice=self.indice+1
464
464
465
465
466 # print 'FASE', numpy.shape(phase), y[25]
466 # print 'FASE', numpy.shape(phase), y[25]
467 # fig = plt.figure(10+self.indice)
467 # fig = plt.figure(10+self.indice)
468 # plt.plot( x[0:256],phase[:,25] )
468 # plt.plot( x[0:256],phase[:,25] )
469 # #plt.axis([-12, 12, 15, 50])
469 # #plt.axis([-12, 12, 15, 50])
470 # plt.title("%s" %( '%s %s, Channel %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S") , i)))
470 # plt.title("%s" %( '%s %s, Channel %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S") , i)))
471 # plt.ylabel('Desfase [grados]')
471 # plt.ylabel('Desfase [grados]')
472 # plt.xlabel('Velocidad [m/s]')
472 # plt.xlabel('Velocidad [m/s]')
473 # fig.savefig('/home/erick/Documents/Pics/to{}.png'.format(self.indice))
473 # fig.savefig('/home/erick/Documents/Pics/to{}.png'.format(self.indice))
474 #
474 #
475 # plt.show()
475 # plt.show()
476 # self.indice=self.indice+1
476 # self.indice=self.indice+1
477
477
478
478
479
479
480
480
481 title = "Coherence Ch%d * Ch%d" %(pair[0], pair[1])
481 title = "Coherence Ch%d * Ch%d" %(pair[0], pair[1])
482 axes0 = self.axesList[i*self.__nsubplots+2]
482 axes0 = self.axesList[i*self.__nsubplots+2]
483 axes0.pcolor(x, y, coherence,
483 axes0.pcolor(x, y, coherence,
484 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=coh_min, zmax=coh_max,
484 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=coh_min, zmax=coh_max,
485 xlabel=xlabel, ylabel=ylabel, title=title,
485 xlabel=xlabel, ylabel=ylabel, title=title,
486 ticksize=9, colormap=coherence_cmap, cblabel='')
486 ticksize=9, colormap=coherence_cmap, cblabel='')
487
487
488 title = "Phase Ch%d * Ch%d" %(pair[0], pair[1])
488 title = "Phase Ch%d * Ch%d" %(pair[0], pair[1])
489 axes0 = self.axesList[i*self.__nsubplots+3]
489 axes0 = self.axesList[i*self.__nsubplots+3]
490 axes0.pcolor(x, y, phase,
490 axes0.pcolor(x, y, phase,
491 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
491 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
492 xlabel=xlabel, ylabel=ylabel, title=title,
492 xlabel=xlabel, ylabel=ylabel, title=title,
493 ticksize=9, colormap=phase_cmap, cblabel='')
493 ticksize=9, colormap=phase_cmap, cblabel='')
494
494
495
495
496
496
497 self.draw()
497 self.draw()
498
498
499 self.save(figpath=figpath,
499 self.save(figpath=figpath,
500 figfile=figfile,
500 figfile=figfile,
501 save=save,
501 save=save,
502 ftp=ftp,
502 ftp=ftp,
503 wr_period=wr_period,
503 wr_period=wr_period,
504 thisDatetime=thisDatetime)
504 thisDatetime=thisDatetime)
505
505
506
506
507 class RTIPlot(Figure):
507 class RTIPlot(Figure):
508
508
509 __isConfig = None
509 __isConfig = None
510 __nsubplots = None
510 __nsubplots = None
511
511
512 WIDTHPROF = None
512 WIDTHPROF = None
513 HEIGHTPROF = None
513 HEIGHTPROF = None
514 PREFIX = 'rti'
514 PREFIX = 'rti'
515
515
516 def __init__(self, **kwargs):
516 def __init__(self, **kwargs):
517
517
518 Figure.__init__(self, **kwargs)
518 Figure.__init__(self, **kwargs)
519 self.timerange = None
519 self.timerange = None
520 self.isConfig = False
520 self.isConfig = False
521 self.__nsubplots = 1
521 self.__nsubplots = 1
522
522
523 self.WIDTH = 800
523 self.WIDTH = 800
524 self.HEIGHT = 250
524 self.HEIGHT = 250
525 self.WIDTHPROF = 120
525 self.WIDTHPROF = 120
526 self.HEIGHTPROF = 0
526 self.HEIGHTPROF = 0
527 self.counter_imagwr = 0
527 self.counter_imagwr = 0
528
528
529 self.PLOT_CODE = RTI_CODE
529 self.PLOT_CODE = RTI_CODE
530
530
531 self.FTP_WEI = None
531 self.FTP_WEI = None
532 self.EXP_CODE = None
532 self.EXP_CODE = None
533 self.SUB_EXP_CODE = None
533 self.SUB_EXP_CODE = None
534 self.PLOT_POS = None
534 self.PLOT_POS = None
535 self.tmin = None
535 self.tmin = None
536 self.tmax = None
536 self.tmax = None
537
537
538 self.xmin = None
538 self.xmin = None
539 self.xmax = None
539 self.xmax = None
540
540
541 self.figfile = None
541 self.figfile = None
542
542
543 def getSubplots(self):
543 def getSubplots(self):
544
544
545 ncol = 1
545 ncol = 1
546 nrow = self.nplots
546 nrow = self.nplots
547
547
548 return nrow, ncol
548 return nrow, ncol
549
549
550 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
550 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
551
551
552 self.__showprofile = showprofile
552 self.__showprofile = showprofile
553 self.nplots = nplots
553 self.nplots = nplots
554
554
555 ncolspan = 1
555 ncolspan = 1
556 colspan = 1
556 colspan = 1
557 if showprofile:
557 if showprofile:
558 ncolspan = 7
558 ncolspan = 7
559 colspan = 6
559 colspan = 6
560 self.__nsubplots = 2
560 self.__nsubplots = 2
561
561
562 self.createFigure(id = id,
562 self.createFigure(id = id,
563 wintitle = wintitle,
563 wintitle = wintitle,
564 widthplot = self.WIDTH + self.WIDTHPROF,
564 widthplot = self.WIDTH + self.WIDTHPROF,
565 heightplot = self.HEIGHT + self.HEIGHTPROF,
565 heightplot = self.HEIGHT + self.HEIGHTPROF,
566 show=show)
566 show=show)
567
567
568 nrow, ncol = self.getSubplots()
568 nrow, ncol = self.getSubplots()
569
569
570 counter = 0
570 counter = 0
571 for y in range(nrow):
571 for y in range(nrow):
572 for x in range(ncol):
572 for x in range(ncol):
573
573
574 if counter >= self.nplots:
574 if counter >= self.nplots:
575 break
575 break
576
576
577 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
577 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
578
578
579 if showprofile:
579 if showprofile:
580 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
580 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
581
581
582 counter += 1
582 counter += 1
583
583
584 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
584 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
585 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
585 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
586 timerange=None, colormap='jet',
586 timerange=None, colormap='jet',
587 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
587 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
588 server=None, folder=None, username=None, password=None,
588 server=None, folder=None, username=None, password=None,
589 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None, HEIGHT=None):
589 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None, HEIGHT=None):
590
590
591 """
591 """
592
592
593 Input:
593 Input:
594 dataOut :
594 dataOut :
595 id :
595 id :
596 wintitle :
596 wintitle :
597 channelList :
597 channelList :
598 showProfile :
598 showProfile :
599 xmin : None,
599 xmin : None,
600 xmax : None,
600 xmax : None,
601 ymin : None,
601 ymin : None,
602 ymax : None,
602 ymax : None,
603 zmin : None,
603 zmin : None,
604 zmax : None
604 zmax : None
605 """
605 """
606
606
607 #colormap = kwargs.get('colormap', 'jet')
607 #colormap = kwargs.get('colormap', 'jet')
608 if HEIGHT is not None:
608 if HEIGHT is not None:
609 self.HEIGHT = HEIGHT
609 self.HEIGHT = HEIGHT
610
610
611 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
611 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
612 return
612 return
613
613
614 if channelList == None:
614 if channelList == None:
615 channelIndexList = dataOut.channelIndexList
615 channelIndexList = dataOut.channelIndexList
616 else:
616 else:
617 channelIndexList = []
617 channelIndexList = []
618 for channel in channelList:
618 for channel in channelList:
619 if channel not in dataOut.channelList:
619 if channel not in dataOut.channelList:
620 raise ValueError, "Channel %d is not in dataOut.channelList"
620 raise ValueError, "Channel %d is not in dataOut.channelList"
621 channelIndexList.append(dataOut.channelList.index(channel))
621 channelIndexList.append(dataOut.channelList.index(channel))
622
622
623 if normFactor is None:
623 if normFactor is None:
624 factor = dataOut.normFactor
624 factor = dataOut.normFactor
625 else:
625 else:
626 factor = normFactor
626 factor = normFactor
627
627
628 # factor = dataOut.normFactor
628 # factor = dataOut.normFactor
629 x = dataOut.getTimeRange()
629 x = dataOut.getTimeRange()
630 y = dataOut.getHeiRange()
630 y = dataOut.getHeiRange()
631
631
632 z = dataOut.data_spc/factor
632 z = dataOut.data_spc/factor
633 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
633 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
634 avg = numpy.average(z, axis=1)
634 avg = numpy.average(z, axis=1)
635 avgdB = 10.*numpy.log10(avg)
635 avgdB = 10.*numpy.log10(avg)
636 # avgdB = dataOut.getPower()
636 # avgdB = dataOut.getPower()
637
637
638
638
639 thisDatetime = dataOut.datatime
639 thisDatetime = dataOut.datatime
640 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
640 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
641 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
641 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
642 xlabel = ""
642 xlabel = ""
643 ylabel = "Range (Km)"
643 ylabel = "Range (Km)"
644
644
645 update_figfile = False
645 update_figfile = False
646
646
647 if dataOut.ltctime >= self.xmax:
647 if dataOut.ltctime >= self.xmax:
648 self.counter_imagwr = wr_period
648 self.counter_imagwr = wr_period
649 self.isConfig = False
649 self.isConfig = False
650 update_figfile = True
650 update_figfile = True
651
651
652 if not self.isConfig:
652 if not self.isConfig:
653
653
654 nplots = len(channelIndexList)
654 nplots = len(channelIndexList)
655
655
656 self.setup(id=id,
656 self.setup(id=id,
657 nplots=nplots,
657 nplots=nplots,
658 wintitle=wintitle,
658 wintitle=wintitle,
659 showprofile=showprofile,
659 showprofile=showprofile,
660 show=show)
660 show=show)
661
661
662 if timerange != None:
662 if timerange != None:
663 self.timerange = timerange
663 self.timerange = timerange
664
664
665 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
665 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
666
666
667 noise = dataOut.noise/factor
667 noise = dataOut.noise/factor
668 noisedB = 10*numpy.log10(noise)
668 noisedB = 10*numpy.log10(noise)
669
669
670 if ymin == None: ymin = numpy.nanmin(y)
670 if ymin == None: ymin = numpy.nanmin(y)
671 if ymax == None: ymax = numpy.nanmax(y)
671 if ymax == None: ymax = numpy.nanmax(y)
672 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
672 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
673 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
673 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
674
674
675 self.FTP_WEI = ftp_wei
675 self.FTP_WEI = ftp_wei
676 self.EXP_CODE = exp_code
676 self.EXP_CODE = exp_code
677 self.SUB_EXP_CODE = sub_exp_code
677 self.SUB_EXP_CODE = sub_exp_code
678 self.PLOT_POS = plot_pos
678 self.PLOT_POS = plot_pos
679
679
680 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
680 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
681 self.isConfig = True
681 self.isConfig = True
682 self.figfile = figfile
682 self.figfile = figfile
683 update_figfile = True
683 update_figfile = True
684
684
685 self.setWinTitle(title)
685 self.setWinTitle(title)
686
686
687 for i in range(self.nplots):
687 for i in range(self.nplots):
688 index = channelIndexList[i]
688 index = channelIndexList[i]
689 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
689 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
690 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
690 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
691 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
691 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
692 axes = self.axesList[i*self.__nsubplots]
692 axes = self.axesList[i*self.__nsubplots]
693 zdB = avgdB[index].reshape((1,-1))
693 zdB = avgdB[index].reshape((1,-1))
694 axes.pcolorbuffer(x, y, zdB,
694 axes.pcolorbuffer(x, y, zdB,
695 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
695 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
696 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
696 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
697 ticksize=9, cblabel='', cbsize="1%", colormap=colormap)
697 ticksize=9, cblabel='', cbsize="1%", colormap=colormap)
698
698
699 if self.__showprofile:
699 if self.__showprofile:
700 axes = self.axesList[i*self.__nsubplots +1]
700 axes = self.axesList[i*self.__nsubplots +1]
701 axes.pline(avgdB[index], y,
701 axes.pline(avgdB[index], y,
702 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
702 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
703 xlabel='dB', ylabel='', title='',
703 xlabel='dB', ylabel='', title='',
704 ytick_visible=False,
704 ytick_visible=False,
705 grid='x')
705 grid='x')
706
706
707 self.draw()
707 self.draw()
708
708
709 self.save(figpath=figpath,
709 self.save(figpath=figpath,
710 figfile=figfile,
710 figfile=figfile,
711 save=save,
711 save=save,
712 ftp=ftp,
712 ftp=ftp,
713 wr_period=wr_period,
713 wr_period=wr_period,
714 thisDatetime=thisDatetime,
714 thisDatetime=thisDatetime,
715 update_figfile=update_figfile)
715 update_figfile=update_figfile)
716
716
717 class CoherenceMap(Figure):
717 class CoherenceMap(Figure):
718 isConfig = None
718 isConfig = None
719 __nsubplots = None
719 __nsubplots = None
720
720
721 WIDTHPROF = None
721 WIDTHPROF = None
722 HEIGHTPROF = None
722 HEIGHTPROF = None
723 PREFIX = 'cmap'
723 PREFIX = 'cmap'
724
724
725 def __init__(self, **kwargs):
725 def __init__(self, **kwargs):
726 Figure.__init__(self, **kwargs)
726 Figure.__init__(self, **kwargs)
727 self.timerange = 2*60*60
727 self.timerange = 2*60*60
728 self.isConfig = False
728 self.isConfig = False
729 self.__nsubplots = 1
729 self.__nsubplots = 1
730
730
731 self.WIDTH = 800
731 self.WIDTH = 800
732 self.HEIGHT = 180
732 self.HEIGHT = 180
733 self.WIDTHPROF = 120
733 self.WIDTHPROF = 120
734 self.HEIGHTPROF = 0
734 self.HEIGHTPROF = 0
735 self.counter_imagwr = 0
735 self.counter_imagwr = 0
736
736
737 self.PLOT_CODE = COH_CODE
737 self.PLOT_CODE = COH_CODE
738
738
739 self.FTP_WEI = None
739 self.FTP_WEI = None
740 self.EXP_CODE = None
740 self.EXP_CODE = None
741 self.SUB_EXP_CODE = None
741 self.SUB_EXP_CODE = None
742 self.PLOT_POS = None
742 self.PLOT_POS = None
743 self.counter_imagwr = 0
743 self.counter_imagwr = 0
744
744
745 self.xmin = None
745 self.xmin = None
746 self.xmax = None
746 self.xmax = None
747
747
748 def getSubplots(self):
748 def getSubplots(self):
749 ncol = 1
749 ncol = 1
750 nrow = self.nplots*2
750 nrow = self.nplots*2
751
751
752 return nrow, ncol
752 return nrow, ncol
753
753
754 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
754 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
755 self.__showprofile = showprofile
755 self.__showprofile = showprofile
756 self.nplots = nplots
756 self.nplots = nplots
757
757
758 ncolspan = 1
758 ncolspan = 1
759 colspan = 1
759 colspan = 1
760 if showprofile:
760 if showprofile:
761 ncolspan = 7
761 ncolspan = 7
762 colspan = 6
762 colspan = 6
763 self.__nsubplots = 2
763 self.__nsubplots = 2
764
764
765 self.createFigure(id = id,
765 self.createFigure(id = id,
766 wintitle = wintitle,
766 wintitle = wintitle,
767 widthplot = self.WIDTH + self.WIDTHPROF,
767 widthplot = self.WIDTH + self.WIDTHPROF,
768 heightplot = self.HEIGHT + self.HEIGHTPROF,
768 heightplot = self.HEIGHT + self.HEIGHTPROF,
769 show=True)
769 show=True)
770
770
771 nrow, ncol = self.getSubplots()
771 nrow, ncol = self.getSubplots()
772
772
773 for y in range(nrow):
773 for y in range(nrow):
774 for x in range(ncol):
774 for x in range(ncol):
775
775
776 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
776 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
777
777
778 if showprofile:
778 if showprofile:
779 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
779 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
780
780
781 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
781 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
782 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
782 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
783 timerange=None, phase_min=None, phase_max=None,
783 timerange=None, phase_min=None, phase_max=None,
784 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
784 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
785 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
785 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
786 server=None, folder=None, username=None, password=None,
786 server=None, folder=None, username=None, password=None,
787 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
787 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
788
788
789 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
789 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
790 return
790 return
791
791
792 if pairsList == None:
792 if pairsList == None:
793 pairsIndexList = dataOut.pairsIndexList
793 pairsIndexList = dataOut.pairsIndexList
794 else:
794 else:
795 pairsIndexList = []
795 pairsIndexList = []
796 for pair in pairsList:
796 for pair in pairsList:
797 if pair not in dataOut.pairsList:
797 if pair not in dataOut.pairsList:
798 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
798 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
799 pairsIndexList.append(dataOut.pairsList.index(pair))
799 pairsIndexList.append(dataOut.pairsList.index(pair))
800
800
801 if pairsIndexList == []:
801 if pairsIndexList == []:
802 return
802 return
803
803
804 if len(pairsIndexList) > 4:
804 if len(pairsIndexList) > 4:
805 pairsIndexList = pairsIndexList[0:4]
805 pairsIndexList = pairsIndexList[0:4]
806
806
807 if phase_min == None:
807 if phase_min == None:
808 phase_min = -180
808 phase_min = -180
809 if phase_max == None:
809 if phase_max == None:
810 phase_max = 180
810 phase_max = 180
811
811
812 x = dataOut.getTimeRange()
812 x = dataOut.getTimeRange()
813 y = dataOut.getHeiRange()
813 y = dataOut.getHeiRange()
814
814
815 thisDatetime = dataOut.datatime
815 thisDatetime = dataOut.datatime
816
816
817 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
817 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
818 xlabel = ""
818 xlabel = ""
819 ylabel = "Range (Km)"
819 ylabel = "Range (Km)"
820 update_figfile = False
820 update_figfile = False
821
821
822 if not self.isConfig:
822 if not self.isConfig:
823 nplots = len(pairsIndexList)
823 nplots = len(pairsIndexList)
824 self.setup(id=id,
824 self.setup(id=id,
825 nplots=nplots,
825 nplots=nplots,
826 wintitle=wintitle,
826 wintitle=wintitle,
827 showprofile=showprofile,
827 showprofile=showprofile,
828 show=show)
828 show=show)
829
829
830 if timerange != None:
830 if timerange != None:
831 self.timerange = timerange
831 self.timerange = timerange
832
832
833 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
833 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
834
834
835 if ymin == None: ymin = numpy.nanmin(y)
835 if ymin == None: ymin = numpy.nanmin(y)
836 if ymax == None: ymax = numpy.nanmax(y)
836 if ymax == None: ymax = numpy.nanmax(y)
837 if zmin == None: zmin = 0.
837 if zmin == None: zmin = 0.
838 if zmax == None: zmax = 1.
838 if zmax == None: zmax = 1.
839
839
840 self.FTP_WEI = ftp_wei
840 self.FTP_WEI = ftp_wei
841 self.EXP_CODE = exp_code
841 self.EXP_CODE = exp_code
842 self.SUB_EXP_CODE = sub_exp_code
842 self.SUB_EXP_CODE = sub_exp_code
843 self.PLOT_POS = plot_pos
843 self.PLOT_POS = plot_pos
844
844
845 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
845 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
846
846
847 self.isConfig = True
847 self.isConfig = True
848 update_figfile = True
848 update_figfile = True
849
849
850 self.setWinTitle(title)
850 self.setWinTitle(title)
851
851
852 for i in range(self.nplots):
852 for i in range(self.nplots):
853
853
854 pair = dataOut.pairsList[pairsIndexList[i]]
854 pair = dataOut.pairsList[pairsIndexList[i]]
855
855
856 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
856 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
857 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
857 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
858 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
858 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
859
859
860
860
861 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
861 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
862 coherence = numpy.abs(avgcoherenceComplex)
862 coherence = numpy.abs(avgcoherenceComplex)
863
863
864 z = coherence.reshape((1,-1))
864 z = coherence.reshape((1,-1))
865
865
866 counter = 0
866 counter = 0
867
867
868 title = "Coherence Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
868 title = "Coherence Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
869 axes = self.axesList[i*self.__nsubplots*2]
869 axes = self.axesList[i*self.__nsubplots*2]
870 axes.pcolorbuffer(x, y, z,
870 axes.pcolorbuffer(x, y, z,
871 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
871 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
872 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
872 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
873 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
873 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
874
874
875 if self.__showprofile:
875 if self.__showprofile:
876 counter += 1
876 counter += 1
877 axes = self.axesList[i*self.__nsubplots*2 + counter]
877 axes = self.axesList[i*self.__nsubplots*2 + counter]
878 axes.pline(coherence, y,
878 axes.pline(coherence, y,
879 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
879 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
880 xlabel='', ylabel='', title='', ticksize=7,
880 xlabel='', ylabel='', title='', ticksize=7,
881 ytick_visible=False, nxticks=5,
881 ytick_visible=False, nxticks=5,
882 grid='x')
882 grid='x')
883
883
884 counter += 1
884 counter += 1
885
885
886 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
886 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
887
887
888 z = phase.reshape((1,-1))
888 z = phase.reshape((1,-1))
889
889
890 title = "Phase Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
890 title = "Phase Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
891 axes = self.axesList[i*self.__nsubplots*2 + counter]
891 axes = self.axesList[i*self.__nsubplots*2 + counter]
892 axes.pcolorbuffer(x, y, z,
892 axes.pcolorbuffer(x, y, z,
893 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
893 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
894 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
894 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
895 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
895 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
896
896
897 if self.__showprofile:
897 if self.__showprofile:
898 counter += 1
898 counter += 1
899 axes = self.axesList[i*self.__nsubplots*2 + counter]
899 axes = self.axesList[i*self.__nsubplots*2 + counter]
900 axes.pline(phase, y,
900 axes.pline(phase, y,
901 xmin=phase_min, xmax=phase_max, ymin=ymin, ymax=ymax,
901 xmin=phase_min, xmax=phase_max, ymin=ymin, ymax=ymax,
902 xlabel='', ylabel='', title='', ticksize=7,
902 xlabel='', ylabel='', title='', ticksize=7,
903 ytick_visible=False, nxticks=4,
903 ytick_visible=False, nxticks=4,
904 grid='x')
904 grid='x')
905
905
906 self.draw()
906 self.draw()
907
907
908 if dataOut.ltctime >= self.xmax:
908 if dataOut.ltctime >= self.xmax:
909 self.counter_imagwr = wr_period
909 self.counter_imagwr = wr_period
910 self.isConfig = False
910 self.isConfig = False
911 update_figfile = True
911 update_figfile = True
912
912
913 self.save(figpath=figpath,
913 self.save(figpath=figpath,
914 figfile=figfile,
914 figfile=figfile,
915 save=save,
915 save=save,
916 ftp=ftp,
916 ftp=ftp,
917 wr_period=wr_period,
917 wr_period=wr_period,
918 thisDatetime=thisDatetime,
918 thisDatetime=thisDatetime,
919 update_figfile=update_figfile)
919 update_figfile=update_figfile)
920
920
921 class PowerProfilePlot(Figure):
921 class PowerProfilePlot(Figure):
922
922
923 isConfig = None
923 isConfig = None
924 __nsubplots = None
924 __nsubplots = None
925
925
926 WIDTHPROF = None
926 WIDTHPROF = None
927 HEIGHTPROF = None
927 HEIGHTPROF = None
928 PREFIX = 'spcprofile'
928 PREFIX = 'spcprofile'
929
929
930 def __init__(self, **kwargs):
930 def __init__(self, **kwargs):
931 Figure.__init__(self, **kwargs)
931 Figure.__init__(self, **kwargs)
932 self.isConfig = False
932 self.isConfig = False
933 self.__nsubplots = 1
933 self.__nsubplots = 1
934
934
935 self.PLOT_CODE = POWER_CODE
935 self.PLOT_CODE = POWER_CODE
936
936
937 self.WIDTH = 300
937 self.WIDTH = 300
938 self.HEIGHT = 500
938 self.HEIGHT = 500
939 self.counter_imagwr = 0
939 self.counter_imagwr = 0
940
940
941 def getSubplots(self):
941 def getSubplots(self):
942 ncol = 1
942 ncol = 1
943 nrow = 1
943 nrow = 1
944
944
945 return nrow, ncol
945 return nrow, ncol
946
946
947 def setup(self, id, nplots, wintitle, show):
947 def setup(self, id, nplots, wintitle, show):
948
948
949 self.nplots = nplots
949 self.nplots = nplots
950
950
951 ncolspan = 1
951 ncolspan = 1
952 colspan = 1
952 colspan = 1
953
953
954 self.createFigure(id = id,
954 self.createFigure(id = id,
955 wintitle = wintitle,
955 wintitle = wintitle,
956 widthplot = self.WIDTH,
956 widthplot = self.WIDTH,
957 heightplot = self.HEIGHT,
957 heightplot = self.HEIGHT,
958 show=show)
958 show=show)
959
959
960 nrow, ncol = self.getSubplots()
960 nrow, ncol = self.getSubplots()
961
961
962 counter = 0
962 counter = 0
963 for y in range(nrow):
963 for y in range(nrow):
964 for x in range(ncol):
964 for x in range(ncol):
965 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
965 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
966
966
967 def run(self, dataOut, id, wintitle="", channelList=None,
967 def run(self, dataOut, id, wintitle="", channelList=None,
968 xmin=None, xmax=None, ymin=None, ymax=None,
968 xmin=None, xmax=None, ymin=None, ymax=None,
969 save=False, figpath='./', figfile=None, show=True,
969 save=False, figpath='./', figfile=None, show=True,
970 ftp=False, wr_period=1, server=None,
970 ftp=False, wr_period=1, server=None,
971 folder=None, username=None, password=None):
971 folder=None, username=None, password=None):
972
972
973
973
974 if channelList == None:
974 if channelList == None:
975 channelIndexList = dataOut.channelIndexList
975 channelIndexList = dataOut.channelIndexList
976 channelList = dataOut.channelList
976 channelList = dataOut.channelList
977 else:
977 else:
978 channelIndexList = []
978 channelIndexList = []
979 for channel in channelList:
979 for channel in channelList:
980 if channel not in dataOut.channelList:
980 if channel not in dataOut.channelList:
981 raise ValueError, "Channel %d is not in dataOut.channelList"
981 raise ValueError, "Channel %d is not in dataOut.channelList"
982 channelIndexList.append(dataOut.channelList.index(channel))
982 channelIndexList.append(dataOut.channelList.index(channel))
983
983
984 factor = dataOut.normFactor
984 factor = dataOut.normFactor
985
985
986 y = dataOut.getHeiRange()
986 y = dataOut.getHeiRange()
987
987
988 #for voltage
988 #for voltage
989 if dataOut.type == 'Voltage':
989 if dataOut.type == 'Voltage':
990 x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
990 x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
991 x = x.real
991 x = x.real
992 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
992 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
993
993
994 #for spectra
994 #for spectra
995 if dataOut.type == 'Spectra':
995 if dataOut.type == 'Spectra':
996 x = dataOut.data_spc[channelIndexList,:,:]/factor
996 x = dataOut.data_spc[channelIndexList,:,:]/factor
997 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
997 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
998 x = numpy.average(x, axis=1)
998 x = numpy.average(x, axis=1)
999
999
1000
1000
1001 xdB = 10*numpy.log10(x)
1001 xdB = 10*numpy.log10(x)
1002
1002
1003 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1003 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1004 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
1004 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
1005 xlabel = "dB"
1005 xlabel = "dB"
1006 ylabel = "Range (Km)"
1006 ylabel = "Range (Km)"
1007
1007
1008 if not self.isConfig:
1008 if not self.isConfig:
1009
1009
1010 nplots = 1
1010 nplots = 1
1011
1011
1012 self.setup(id=id,
1012 self.setup(id=id,
1013 nplots=nplots,
1013 nplots=nplots,
1014 wintitle=wintitle,
1014 wintitle=wintitle,
1015 show=show)
1015 show=show)
1016
1016
1017 if ymin == None: ymin = numpy.nanmin(y)
1017 if ymin == None: ymin = numpy.nanmin(y)
1018 if ymax == None: ymax = numpy.nanmax(y)
1018 if ymax == None: ymax = numpy.nanmax(y)
1019 if xmin == None: xmin = numpy.nanmin(xdB)*0.9
1019 if xmin == None: xmin = numpy.nanmin(xdB)*0.9
1020 if xmax == None: xmax = numpy.nanmax(xdB)*1.1
1020 if xmax == None: xmax = numpy.nanmax(xdB)*1.1
1021
1021
1022 self.isConfig = True
1022 self.isConfig = True
1023
1023
1024 self.setWinTitle(title)
1024 self.setWinTitle(title)
1025
1025
1026 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1026 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1027 axes = self.axesList[0]
1027 axes = self.axesList[0]
1028
1028
1029 legendlabels = ["channel %d"%x for x in channelList]
1029 legendlabels = ["channel %d"%x for x in channelList]
1030 axes.pmultiline(xdB, y,
1030 axes.pmultiline(xdB, y,
1031 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1031 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1032 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
1032 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
1033 ytick_visible=True, nxticks=5,
1033 ytick_visible=True, nxticks=5,
1034 grid='x')
1034 grid='x')
1035
1035
1036 self.draw()
1036 self.draw()
1037
1037
1038 self.save(figpath=figpath,
1038 self.save(figpath=figpath,
1039 figfile=figfile,
1039 figfile=figfile,
1040 save=save,
1040 save=save,
1041 ftp=ftp,
1041 ftp=ftp,
1042 wr_period=wr_period,
1042 wr_period=wr_period,
1043 thisDatetime=thisDatetime)
1043 thisDatetime=thisDatetime)
1044
1044
1045 class SpectraCutPlot(Figure):
1045 class SpectraCutPlot(Figure):
1046
1046
1047 isConfig = None
1047 isConfig = None
1048 __nsubplots = None
1048 __nsubplots = None
1049
1049
1050 WIDTHPROF = None
1050 WIDTHPROF = None
1051 HEIGHTPROF = None
1051 HEIGHTPROF = None
1052 PREFIX = 'spc_cut'
1052 PREFIX = 'spc_cut'
1053
1053
1054 def __init__(self, **kwargs):
1054 def __init__(self, **kwargs):
1055 Figure.__init__(self, **kwargs)
1055 Figure.__init__(self, **kwargs)
1056 self.isConfig = False
1056 self.isConfig = False
1057 self.__nsubplots = 1
1057 self.__nsubplots = 1
1058
1058
1059 self.PLOT_CODE = POWER_CODE
1059 self.PLOT_CODE = POWER_CODE
1060
1060
1061 self.WIDTH = 700
1061 self.WIDTH = 700
1062 self.HEIGHT = 500
1062 self.HEIGHT = 500
1063 self.counter_imagwr = 0
1063 self.counter_imagwr = 0
1064
1064
1065 def getSubplots(self):
1065 def getSubplots(self):
1066 ncol = 1
1066 ncol = 1
1067 nrow = 1
1067 nrow = 1
1068
1068
1069 return nrow, ncol
1069 return nrow, ncol
1070
1070
1071 def setup(self, id, nplots, wintitle, show):
1071 def setup(self, id, nplots, wintitle, show):
1072
1072
1073 self.nplots = nplots
1073 self.nplots = nplots
1074
1074
1075 ncolspan = 1
1075 ncolspan = 1
1076 colspan = 1
1076 colspan = 1
1077
1077
1078 self.createFigure(id = id,
1078 self.createFigure(id = id,
1079 wintitle = wintitle,
1079 wintitle = wintitle,
1080 widthplot = self.WIDTH,
1080 widthplot = self.WIDTH,
1081 heightplot = self.HEIGHT,
1081 heightplot = self.HEIGHT,
1082 show=show)
1082 show=show)
1083
1083
1084 nrow, ncol = self.getSubplots()
1084 nrow, ncol = self.getSubplots()
1085
1085
1086 counter = 0
1086 counter = 0
1087 for y in range(nrow):
1087 for y in range(nrow):
1088 for x in range(ncol):
1088 for x in range(ncol):
1089 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1089 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1090
1090
1091 def run(self, dataOut, id, wintitle="", channelList=None,
1091 def run(self, dataOut, id, wintitle="", channelList=None,
1092 xmin=None, xmax=None, ymin=None, ymax=None,
1092 xmin=None, xmax=None, ymin=None, ymax=None,
1093 save=False, figpath='./', figfile=None, show=True,
1093 save=False, figpath='./', figfile=None, show=True,
1094 ftp=False, wr_period=1, server=None,
1094 ftp=False, wr_period=1, server=None,
1095 folder=None, username=None, password=None,
1095 folder=None, username=None, password=None,
1096 xaxis="frequency"):
1096 xaxis="frequency"):
1097
1097
1098
1098
1099 if channelList == None:
1099 if channelList == None:
1100 channelIndexList = dataOut.channelIndexList
1100 channelIndexList = dataOut.channelIndexList
1101 channelList = dataOut.channelList
1101 channelList = dataOut.channelList
1102 else:
1102 else:
1103 channelIndexList = []
1103 channelIndexList = []
1104 for channel in channelList:
1104 for channel in channelList:
1105 if channel not in dataOut.channelList:
1105 if channel not in dataOut.channelList:
1106 raise ValueError, "Channel %d is not in dataOut.channelList"
1106 raise ValueError, "Channel %d is not in dataOut.channelList"
1107 channelIndexList.append(dataOut.channelList.index(channel))
1107 channelIndexList.append(dataOut.channelList.index(channel))
1108
1108
1109 factor = dataOut.normFactor
1109 factor = dataOut.normFactor
1110
1110
1111 y = dataOut.getHeiRange()
1111 y = dataOut.getHeiRange()
1112
1112
1113 z = dataOut.data_spc/factor
1113 z = dataOut.data_spc/factor
1114 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1114 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1115
1115
1116 hei_index = numpy.arange(25)*3 + 20
1116 hei_index = numpy.arange(25)*3 + 20
1117
1117
1118 if xaxis == "frequency":
1118 if xaxis == "frequency":
1119 x = dataOut.getFreqRange()/1000.
1119 x = dataOut.getFreqRange()/1000.
1120 zdB = 10*numpy.log10(z[0,:,hei_index])
1120 zdB = 10*numpy.log10(z[0,:,hei_index])
1121 xlabel = "Frequency (kHz)"
1121 xlabel = "Frequency (kHz)"
1122 ylabel = "Power (dB)"
1122 ylabel = "Power (dB)"
1123
1123
1124 elif xaxis == "time":
1124 elif xaxis == "time":
1125 x = dataOut.getAcfRange()
1125 x = dataOut.getAcfRange()
1126 zdB = z[0,:,hei_index]
1126 zdB = z[0,:,hei_index]
1127 xlabel = "Time (ms)"
1127 xlabel = "Time (ms)"
1128 ylabel = "ACF"
1128 ylabel = "ACF"
1129
1129
1130 else:
1130 else:
1131 x = dataOut.getVelRange()
1131 x = dataOut.getVelRange()
1132 zdB = 10*numpy.log10(z[0,:,hei_index])
1132 zdB = 10*numpy.log10(z[0,:,hei_index])
1133 xlabel = "Velocity (m/s)"
1133 xlabel = "Velocity (m/s)"
1134 ylabel = "Power (dB)"
1134 ylabel = "Power (dB)"
1135
1135
1136 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1136 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1137 title = wintitle + " Range Cuts %s" %(thisDatetime.strftime("%d-%b-%Y"))
1137 title = wintitle + " Range Cuts %s" %(thisDatetime.strftime("%d-%b-%Y"))
1138
1138
1139 if not self.isConfig:
1139 if not self.isConfig:
1140
1140
1141 nplots = 1
1141 nplots = 1
1142
1142
1143 self.setup(id=id,
1143 self.setup(id=id,
1144 nplots=nplots,
1144 nplots=nplots,
1145 wintitle=wintitle,
1145 wintitle=wintitle,
1146 show=show)
1146 show=show)
1147
1147
1148 if xmin == None: xmin = numpy.nanmin(x)*0.9
1148 if xmin == None: xmin = numpy.nanmin(x)*0.9
1149 if xmax == None: xmax = numpy.nanmax(x)*1.1
1149 if xmax == None: xmax = numpy.nanmax(x)*1.1
1150 if ymin == None: ymin = numpy.nanmin(zdB)
1150 if ymin == None: ymin = numpy.nanmin(zdB)
1151 if ymax == None: ymax = numpy.nanmax(zdB)
1151 if ymax == None: ymax = numpy.nanmax(zdB)
1152
1152
1153 self.isConfig = True
1153 self.isConfig = True
1154
1154
1155 self.setWinTitle(title)
1155 self.setWinTitle(title)
1156
1156
1157 title = "Spectra Cuts: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1157 title = "Spectra Cuts: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1158 axes = self.axesList[0]
1158 axes = self.axesList[0]
1159
1159
1160 legendlabels = ["Range = %dKm" %y[i] for i in hei_index]
1160 legendlabels = ["Range = %dKm" %y[i] for i in hei_index]
1161
1161
1162 axes.pmultilineyaxis( x, zdB,
1162 axes.pmultilineyaxis( x, zdB,
1163 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1163 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1164 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
1164 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
1165 ytick_visible=True, nxticks=5,
1165 ytick_visible=True, nxticks=5,
1166 grid='x')
1166 grid='x')
1167
1167
1168 self.draw()
1168 self.draw()
1169
1169
1170 self.save(figpath=figpath,
1170 self.save(figpath=figpath,
1171 figfile=figfile,
1171 figfile=figfile,
1172 save=save,
1172 save=save,
1173 ftp=ftp,
1173 ftp=ftp,
1174 wr_period=wr_period,
1174 wr_period=wr_period,
1175 thisDatetime=thisDatetime)
1175 thisDatetime=thisDatetime)
1176
1176
1177 class Noise(Figure):
1177 class Noise(Figure):
1178
1178
1179 isConfig = None
1179 isConfig = None
1180 __nsubplots = None
1180 __nsubplots = None
1181
1181
1182 PREFIX = 'noise'
1182 PREFIX = 'noise'
1183
1183
1184
1184
1185 def __init__(self, **kwargs):
1185 def __init__(self, **kwargs):
1186 Figure.__init__(self, **kwargs)
1186 Figure.__init__(self, **kwargs)
1187 self.timerange = 24*60*60
1187 self.timerange = 24*60*60
1188 self.isConfig = False
1188 self.isConfig = False
1189 self.__nsubplots = 1
1189 self.__nsubplots = 1
1190 self.counter_imagwr = 0
1190 self.counter_imagwr = 0
1191 self.WIDTH = 800
1191 self.WIDTH = 800
1192 self.HEIGHT = 400
1192 self.HEIGHT = 400
1193 self.WIDTHPROF = 120
1193 self.WIDTHPROF = 120
1194 self.HEIGHTPROF = 0
1194 self.HEIGHTPROF = 0
1195 self.xdata = None
1195 self.xdata = None
1196 self.ydata = None
1196 self.ydata = None
1197
1197
1198 self.PLOT_CODE = NOISE_CODE
1198 self.PLOT_CODE = NOISE_CODE
1199
1199
1200 self.FTP_WEI = None
1200 self.FTP_WEI = None
1201 self.EXP_CODE = None
1201 self.EXP_CODE = None
1202 self.SUB_EXP_CODE = None
1202 self.SUB_EXP_CODE = None
1203 self.PLOT_POS = None
1203 self.PLOT_POS = None
1204 self.figfile = None
1204 self.figfile = None
1205
1205
1206 self.xmin = None
1206 self.xmin = None
1207 self.xmax = None
1207 self.xmax = None
1208
1208
1209 def getSubplots(self):
1209 def getSubplots(self):
1210
1210
1211 ncol = 1
1211 ncol = 1
1212 nrow = 1
1212 nrow = 1
1213
1213
1214 return nrow, ncol
1214 return nrow, ncol
1215
1215
1216 def openfile(self, filename):
1216 def openfile(self, filename):
1217 dirname = os.path.dirname(filename)
1217 dirname = os.path.dirname(filename)
1218
1218
1219 if not os.path.exists(dirname):
1219 if not os.path.exists(dirname):
1220 os.mkdir(dirname)
1220 os.mkdir(dirname)
1221
1221
1222 f = open(filename,'w+')
1222 f = open(filename,'w+')
1223 f.write('\n\n')
1223 f.write('\n\n')
1224 f.write('JICAMARCA RADIO OBSERVATORY - Noise \n')
1224 f.write('JICAMARCA RADIO OBSERVATORY - Noise \n')
1225 f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' )
1225 f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' )
1226 f.close()
1226 f.close()
1227
1227
1228 def save_data(self, filename_phase, data, data_datetime):
1228 def save_data(self, filename_phase, data, data_datetime):
1229
1229
1230 f=open(filename_phase,'a')
1230 f=open(filename_phase,'a')
1231
1231
1232 timetuple_data = data_datetime.timetuple()
1232 timetuple_data = data_datetime.timetuple()
1233 day = str(timetuple_data.tm_mday)
1233 day = str(timetuple_data.tm_mday)
1234 month = str(timetuple_data.tm_mon)
1234 month = str(timetuple_data.tm_mon)
1235 year = str(timetuple_data.tm_year)
1235 year = str(timetuple_data.tm_year)
1236 hour = str(timetuple_data.tm_hour)
1236 hour = str(timetuple_data.tm_hour)
1237 minute = str(timetuple_data.tm_min)
1237 minute = str(timetuple_data.tm_min)
1238 second = str(timetuple_data.tm_sec)
1238 second = str(timetuple_data.tm_sec)
1239
1239
1240 data_msg = ''
1240 data_msg = ''
1241 for i in range(len(data)):
1241 for i in range(len(data)):
1242 data_msg += str(data[i]) + ' '
1242 data_msg += str(data[i]) + ' '
1243
1243
1244 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' ' + data_msg + '\n')
1244 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' ' + data_msg + '\n')
1245 f.close()
1245 f.close()
1246
1246
1247
1247
1248 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1248 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1249
1249
1250 self.__showprofile = showprofile
1250 self.__showprofile = showprofile
1251 self.nplots = nplots
1251 self.nplots = nplots
1252
1252
1253 ncolspan = 7
1253 ncolspan = 7
1254 colspan = 6
1254 colspan = 6
1255 self.__nsubplots = 2
1255 self.__nsubplots = 2
1256
1256
1257 self.createFigure(id = id,
1257 self.createFigure(id = id,
1258 wintitle = wintitle,
1258 wintitle = wintitle,
1259 widthplot = self.WIDTH+self.WIDTHPROF,
1259 widthplot = self.WIDTH+self.WIDTHPROF,
1260 heightplot = self.HEIGHT+self.HEIGHTPROF,
1260 heightplot = self.HEIGHT+self.HEIGHTPROF,
1261 show=show)
1261 show=show)
1262
1262
1263 nrow, ncol = self.getSubplots()
1263 nrow, ncol = self.getSubplots()
1264
1264
1265 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1265 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1266
1266
1267
1267
1268 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1268 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1269 xmin=None, xmax=None, ymin=None, ymax=None,
1269 xmin=None, xmax=None, ymin=None, ymax=None,
1270 timerange=None,
1270 timerange=None,
1271 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1271 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1272 server=None, folder=None, username=None, password=None,
1272 server=None, folder=None, username=None, password=None,
1273 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1273 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1274
1274
1275 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1275 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1276 return
1276 return
1277
1277
1278 if channelList == None:
1278 if channelList == None:
1279 channelIndexList = dataOut.channelIndexList
1279 channelIndexList = dataOut.channelIndexList
1280 channelList = dataOut.channelList
1280 channelList = dataOut.channelList
1281 else:
1281 else:
1282 channelIndexList = []
1282 channelIndexList = []
1283 for channel in channelList:
1283 for channel in channelList:
1284 if channel not in dataOut.channelList:
1284 if channel not in dataOut.channelList:
1285 raise ValueError, "Channel %d is not in dataOut.channelList"
1285 raise ValueError, "Channel %d is not in dataOut.channelList"
1286 channelIndexList.append(dataOut.channelList.index(channel))
1286 channelIndexList.append(dataOut.channelList.index(channel))
1287
1287
1288 x = dataOut.getTimeRange()
1288 x = dataOut.getTimeRange()
1289 #y = dataOut.getHeiRange()
1289 #y = dataOut.getHeiRange()
1290 factor = dataOut.normFactor
1290 factor = dataOut.normFactor
1291 noise = dataOut.noise[channelIndexList]/factor
1291 noise = dataOut.noise[channelIndexList]/factor
1292 noisedB = 10*numpy.log10(noise)
1292 noisedB = 10*numpy.log10(noise)
1293
1293
1294 thisDatetime = dataOut.datatime
1294 thisDatetime = dataOut.datatime
1295
1295
1296 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1296 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1297 xlabel = ""
1297 xlabel = ""
1298 ylabel = "Intensity (dB)"
1298 ylabel = "Intensity (dB)"
1299 update_figfile = False
1299 update_figfile = False
1300
1300
1301 if not self.isConfig:
1301 if not self.isConfig:
1302
1302
1303 nplots = 1
1303 nplots = 1
1304
1304
1305 self.setup(id=id,
1305 self.setup(id=id,
1306 nplots=nplots,
1306 nplots=nplots,
1307 wintitle=wintitle,
1307 wintitle=wintitle,
1308 showprofile=showprofile,
1308 showprofile=showprofile,
1309 show=show)
1309 show=show)
1310
1310
1311 if timerange != None:
1311 if timerange != None:
1312 self.timerange = timerange
1312 self.timerange = timerange
1313
1313
1314 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1314 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1315
1315
1316 if ymin == None: ymin = numpy.floor(numpy.nanmin(noisedB)) - 10.0
1316 if ymin == None: ymin = numpy.floor(numpy.nanmin(noisedB)) - 10.0
1317 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1317 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1318
1318
1319 self.FTP_WEI = ftp_wei
1319 self.FTP_WEI = ftp_wei
1320 self.EXP_CODE = exp_code
1320 self.EXP_CODE = exp_code
1321 self.SUB_EXP_CODE = sub_exp_code
1321 self.SUB_EXP_CODE = sub_exp_code
1322 self.PLOT_POS = plot_pos
1322 self.PLOT_POS = plot_pos
1323
1323
1324
1324
1325 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1325 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1326 self.isConfig = True
1326 self.isConfig = True
1327 self.figfile = figfile
1327 self.figfile = figfile
1328 self.xdata = numpy.array([])
1328 self.xdata = numpy.array([])
1329 self.ydata = numpy.array([])
1329 self.ydata = numpy.array([])
1330
1330
1331 update_figfile = True
1331 update_figfile = True
1332
1332
1333 #open file beacon phase
1333 #open file beacon phase
1334 path = '%s%03d' %(self.PREFIX, self.id)
1334 path = '%s%03d' %(self.PREFIX, self.id)
1335 noise_file = os.path.join(path,'%s.txt'%self.name)
1335 noise_file = os.path.join(path,'%s.txt'%self.name)
1336 self.filename_noise = os.path.join(figpath,noise_file)
1336 self.filename_noise = os.path.join(figpath,noise_file)
1337
1337
1338 self.setWinTitle(title)
1338 self.setWinTitle(title)
1339
1339
1340 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1340 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1341
1341
1342 legendlabels = ["channel %d"%(idchannel) for idchannel in channelList]
1342 legendlabels = ["channel %d"%(idchannel) for idchannel in channelList]
1343 axes = self.axesList[0]
1343 axes = self.axesList[0]
1344
1344
1345 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1345 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1346
1346
1347 if len(self.ydata)==0:
1347 if len(self.ydata)==0:
1348 self.ydata = noisedB.reshape(-1,1)
1348 self.ydata = noisedB.reshape(-1,1)
1349 else:
1349 else:
1350 self.ydata = numpy.hstack((self.ydata, noisedB.reshape(-1,1)))
1350 self.ydata = numpy.hstack((self.ydata, noisedB.reshape(-1,1)))
1351
1351
1352
1352
1353 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1353 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1354 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1354 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1355 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1355 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1356 XAxisAsTime=True, grid='both'
1356 XAxisAsTime=True, grid='both'
1357 )
1357 )
1358
1358
1359 self.draw()
1359 self.draw()
1360
1360
1361 if dataOut.ltctime >= self.xmax:
1361 if dataOut.ltctime >= self.xmax:
1362 self.counter_imagwr = wr_period
1362 self.counter_imagwr = wr_period
1363 self.isConfig = False
1363 self.isConfig = False
1364 update_figfile = True
1364 update_figfile = True
1365
1365
1366 self.save(figpath=figpath,
1366 self.save(figpath=figpath,
1367 figfile=figfile,
1367 figfile=figfile,
1368 save=save,
1368 save=save,
1369 ftp=ftp,
1369 ftp=ftp,
1370 wr_period=wr_period,
1370 wr_period=wr_period,
1371 thisDatetime=thisDatetime,
1371 thisDatetime=thisDatetime,
1372 update_figfile=update_figfile)
1372 update_figfile=update_figfile)
1373
1373
1374 #store data beacon phase
1374 #store data beacon phase
1375 if save:
1375 if save:
1376 self.save_data(self.filename_noise, noisedB, thisDatetime)
1376 self.save_data(self.filename_noise, noisedB, thisDatetime)
1377
1377
1378 class BeaconPhase(Figure):
1378 class BeaconPhase(Figure):
1379
1379
1380 __isConfig = None
1380 __isConfig = None
1381 __nsubplots = None
1381 __nsubplots = None
1382
1382
1383 PREFIX = 'beacon_phase'
1383 PREFIX = 'beacon_phase'
1384
1384
1385 def __init__(self, **kwargs):
1385 def __init__(self, **kwargs):
1386 Figure.__init__(self, **kwargs)
1386 Figure.__init__(self, **kwargs)
1387 self.timerange = 24*60*60
1387 self.timerange = 24*60*60
1388 self.isConfig = False
1388 self.isConfig = False
1389 self.__nsubplots = 1
1389 self.__nsubplots = 1
1390 self.counter_imagwr = 0
1390 self.counter_imagwr = 0
1391 self.WIDTH = 800
1391 self.WIDTH = 800
1392 self.HEIGHT = 400
1392 self.HEIGHT = 400
1393 self.WIDTHPROF = 120
1393 self.WIDTHPROF = 120
1394 self.HEIGHTPROF = 0
1394 self.HEIGHTPROF = 0
1395 self.xdata = None
1395 self.xdata = None
1396 self.ydata = None
1396 self.ydata = None
1397
1397
1398 self.PLOT_CODE = BEACON_CODE
1398 self.PLOT_CODE = BEACON_CODE
1399
1399
1400 self.FTP_WEI = None
1400 self.FTP_WEI = None
1401 self.EXP_CODE = None
1401 self.EXP_CODE = None
1402 self.SUB_EXP_CODE = None
1402 self.SUB_EXP_CODE = None
1403 self.PLOT_POS = None
1403 self.PLOT_POS = None
1404
1404
1405 self.filename_phase = None
1405 self.filename_phase = None
1406
1406
1407 self.figfile = None
1407 self.figfile = None
1408
1408
1409 self.xmin = None
1409 self.xmin = None
1410 self.xmax = None
1410 self.xmax = None
1411
1411
1412 def getSubplots(self):
1412 def getSubplots(self):
1413
1413
1414 ncol = 1
1414 ncol = 1
1415 nrow = 1
1415 nrow = 1
1416
1416
1417 return nrow, ncol
1417 return nrow, ncol
1418
1418
1419 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1419 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1420
1420
1421 self.__showprofile = showprofile
1421 self.__showprofile = showprofile
1422 self.nplots = nplots
1422 self.nplots = nplots
1423
1423
1424 ncolspan = 7
1424 ncolspan = 7
1425 colspan = 6
1425 colspan = 6
1426 self.__nsubplots = 2
1426 self.__nsubplots = 2
1427
1427
1428 self.createFigure(id = id,
1428 self.createFigure(id = id,
1429 wintitle = wintitle,
1429 wintitle = wintitle,
1430 widthplot = self.WIDTH+self.WIDTHPROF,
1430 widthplot = self.WIDTH+self.WIDTHPROF,
1431 heightplot = self.HEIGHT+self.HEIGHTPROF,
1431 heightplot = self.HEIGHT+self.HEIGHTPROF,
1432 show=show)
1432 show=show)
1433
1433
1434 nrow, ncol = self.getSubplots()
1434 nrow, ncol = self.getSubplots()
1435
1435
1436 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1436 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1437
1437
1438 def save_phase(self, filename_phase):
1438 def save_phase(self, filename_phase):
1439 f = open(filename_phase,'w+')
1439 f = open(filename_phase,'w+')
1440 f.write('\n\n')
1440 f.write('\n\n')
1441 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
1441 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
1442 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
1442 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
1443 f.close()
1443 f.close()
1444
1444
1445 def save_data(self, filename_phase, data, data_datetime):
1445 def save_data(self, filename_phase, data, data_datetime):
1446 f=open(filename_phase,'a')
1446 f=open(filename_phase,'a')
1447 timetuple_data = data_datetime.timetuple()
1447 timetuple_data = data_datetime.timetuple()
1448 day = str(timetuple_data.tm_mday)
1448 day = str(timetuple_data.tm_mday)
1449 month = str(timetuple_data.tm_mon)
1449 month = str(timetuple_data.tm_mon)
1450 year = str(timetuple_data.tm_year)
1450 year = str(timetuple_data.tm_year)
1451 hour = str(timetuple_data.tm_hour)
1451 hour = str(timetuple_data.tm_hour)
1452 minute = str(timetuple_data.tm_min)
1452 minute = str(timetuple_data.tm_min)
1453 second = str(timetuple_data.tm_sec)
1453 second = str(timetuple_data.tm_sec)
1454 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1454 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1455 f.close()
1455 f.close()
1456
1456
1457
1457
1458 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1458 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1459 xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None,
1459 xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None,
1460 timerange=None,
1460 timerange=None,
1461 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1461 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1462 server=None, folder=None, username=None, password=None,
1462 server=None, folder=None, username=None, password=None,
1463 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1463 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1464
1464
1465 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1465 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1466 return
1466 return
1467
1467
1468 if pairsList == None:
1468 if pairsList == None:
1469 pairsIndexList = dataOut.pairsIndexList[:10]
1469 pairsIndexList = dataOut.pairsIndexList[:10]
1470 else:
1470 else:
1471 pairsIndexList = []
1471 pairsIndexList = []
1472 for pair in pairsList:
1472 for pair in pairsList:
1473 if pair not in dataOut.pairsList:
1473 if pair not in dataOut.pairsList:
1474 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
1474 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
1475 pairsIndexList.append(dataOut.pairsList.index(pair))
1475 pairsIndexList.append(dataOut.pairsList.index(pair))
1476
1476
1477 if pairsIndexList == []:
1477 if pairsIndexList == []:
1478 return
1478 return
1479
1479
1480 # if len(pairsIndexList) > 4:
1480 # if len(pairsIndexList) > 4:
1481 # pairsIndexList = pairsIndexList[0:4]
1481 # pairsIndexList = pairsIndexList[0:4]
1482
1482
1483 hmin_index = None
1483 hmin_index = None
1484 hmax_index = None
1484 hmax_index = None
1485
1485
1486 if hmin != None and hmax != None:
1486 if hmin != None and hmax != None:
1487 indexes = numpy.arange(dataOut.nHeights)
1487 indexes = numpy.arange(dataOut.nHeights)
1488 hmin_list = indexes[dataOut.heightList >= hmin]
1488 hmin_list = indexes[dataOut.heightList >= hmin]
1489 hmax_list = indexes[dataOut.heightList <= hmax]
1489 hmax_list = indexes[dataOut.heightList <= hmax]
1490
1490
1491 if hmin_list.any():
1491 if hmin_list.any():
1492 hmin_index = hmin_list[0]
1492 hmin_index = hmin_list[0]
1493
1493
1494 if hmax_list.any():
1494 if hmax_list.any():
1495 hmax_index = hmax_list[-1]+1
1495 hmax_index = hmax_list[-1]+1
1496
1496
1497 x = dataOut.getTimeRange()
1497 x = dataOut.getTimeRange()
1498 #y = dataOut.getHeiRange()
1498 #y = dataOut.getHeiRange()
1499
1499
1500
1500
1501 thisDatetime = dataOut.datatime
1501 thisDatetime = dataOut.datatime
1502
1502
1503 title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1503 title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1504 xlabel = "Local Time"
1504 xlabel = "Local Time"
1505 ylabel = "Phase (degrees)"
1505 ylabel = "Phase (degrees)"
1506
1506
1507 update_figfile = False
1507 update_figfile = False
1508
1508
1509 nplots = len(pairsIndexList)
1509 nplots = len(pairsIndexList)
1510 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1510 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1511 phase_beacon = numpy.zeros(len(pairsIndexList))
1511 phase_beacon = numpy.zeros(len(pairsIndexList))
1512 for i in range(nplots):
1512 for i in range(nplots):
1513 pair = dataOut.pairsList[pairsIndexList[i]]
1513 pair = dataOut.pairsList[pairsIndexList[i]]
1514 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0)
1514 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0)
1515 powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0)
1515 powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0)
1516 powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0)
1516 powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0)
1517 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
1517 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
1518 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1518 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1519
1519
1520 #print "Phase %d%d" %(pair[0], pair[1])
1520 #print "Phase %d%d" %(pair[0], pair[1])
1521 #print phase[dataOut.beacon_heiIndexList]
1521 #print phase[dataOut.beacon_heiIndexList]
1522
1522
1523 if dataOut.beacon_heiIndexList:
1523 if dataOut.beacon_heiIndexList:
1524 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
1524 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
1525 else:
1525 else:
1526 phase_beacon[i] = numpy.average(phase)
1526 phase_beacon[i] = numpy.average(phase)
1527
1527
1528 if not self.isConfig:
1528 if not self.isConfig:
1529
1529
1530 nplots = len(pairsIndexList)
1530 nplots = len(pairsIndexList)
1531
1531
1532 self.setup(id=id,
1532 self.setup(id=id,
1533 nplots=nplots,
1533 nplots=nplots,
1534 wintitle=wintitle,
1534 wintitle=wintitle,
1535 showprofile=showprofile,
1535 showprofile=showprofile,
1536 show=show)
1536 show=show)
1537
1537
1538 if timerange != None:
1538 if timerange != None:
1539 self.timerange = timerange
1539 self.timerange = timerange
1540
1540
1541 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1541 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1542
1542
1543 if ymin == None: ymin = 0
1543 if ymin == None: ymin = 0
1544 if ymax == None: ymax = 360
1544 if ymax == None: ymax = 360
1545
1545
1546 self.FTP_WEI = ftp_wei
1546 self.FTP_WEI = ftp_wei
1547 self.EXP_CODE = exp_code
1547 self.EXP_CODE = exp_code
1548 self.SUB_EXP_CODE = sub_exp_code
1548 self.SUB_EXP_CODE = sub_exp_code
1549 self.PLOT_POS = plot_pos
1549 self.PLOT_POS = plot_pos
1550
1550
1551 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1551 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1552 self.isConfig = True
1552 self.isConfig = True
1553 self.figfile = figfile
1553 self.figfile = figfile
1554 self.xdata = numpy.array([])
1554 self.xdata = numpy.array([])
1555 self.ydata = numpy.array([])
1555 self.ydata = numpy.array([])
1556
1556
1557 update_figfile = True
1557 update_figfile = True
1558
1558
1559 #open file beacon phase
1559 #open file beacon phase
1560 path = '%s%03d' %(self.PREFIX, self.id)
1560 path = '%s%03d' %(self.PREFIX, self.id)
1561 beacon_file = os.path.join(path,'%s.txt'%self.name)
1561 beacon_file = os.path.join(path,'%s.txt'%self.name)
1562 self.filename_phase = os.path.join(figpath,beacon_file)
1562 self.filename_phase = os.path.join(figpath,beacon_file)
1563 #self.save_phase(self.filename_phase)
1563 #self.save_phase(self.filename_phase)
1564
1564
1565
1565
1566 #store data beacon phase
1566 #store data beacon phase
1567 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1567 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1568
1568
1569 self.setWinTitle(title)
1569 self.setWinTitle(title)
1570
1570
1571
1571
1572 title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1572 title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1573
1573
1574 legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList]
1574 legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList]
1575
1575
1576 axes = self.axesList[0]
1576 axes = self.axesList[0]
1577
1577
1578 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1578 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1579
1579
1580 if len(self.ydata)==0:
1580 if len(self.ydata)==0:
1581 self.ydata = phase_beacon.reshape(-1,1)
1581 self.ydata = phase_beacon.reshape(-1,1)
1582 else:
1582 else:
1583 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1583 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1584
1584
1585
1585
1586 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1586 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1587 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1587 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1588 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1588 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1589 XAxisAsTime=True, grid='both'
1589 XAxisAsTime=True, grid='both'
1590 )
1590 )
1591
1591
1592 self.draw()
1592 self.draw()
1593
1593
1594 if dataOut.ltctime >= self.xmax:
1594 if dataOut.ltctime >= self.xmax:
1595 self.counter_imagwr = wr_period
1595 self.counter_imagwr = wr_period
1596 self.isConfig = False
1596 self.isConfig = False
1597 update_figfile = True
1597 update_figfile = True
1598
1598
1599 self.save(figpath=figpath,
1599 self.save(figpath=figpath,
1600 figfile=figfile,
1600 figfile=figfile,
1601 save=save,
1601 save=save,
1602 ftp=ftp,
1602 ftp=ftp,
1603 wr_period=wr_period,
1603 wr_period=wr_period,
1604 thisDatetime=thisDatetime,
1604 thisDatetime=thisDatetime,
1605 update_figfile=update_figfile)
1605 update_figfile=update_figfile)
@@ -1,3982 +1,4015
1 import numpy
1 import numpy
2 import math
2 import math
3 from scipy import optimize, interpolate, signal, stats, ndimage
3 from scipy import optimize, interpolate, signal, stats, ndimage
4 import scipy
4 import scipy
5 import re
5 import re
6 import datetime
6 import datetime
7 import copy
7 import copy
8 import sys
8 import sys
9 import importlib
9 import importlib
10 import itertools
10 import itertools
11 from multiprocessing import Pool, TimeoutError
11 from multiprocessing import Pool, TimeoutError
12 from multiprocessing.pool import ThreadPool
12 from multiprocessing.pool import ThreadPool
13 import copy_reg
13 import copy_reg
14 import cPickle
14 import cPickle
15 import types
15 import types
16 from functools import partial
16 from functools import partial
17 import time
17 import time
18 #from sklearn.cluster import KMeans
18 #from sklearn.cluster import KMeans
19
19
20 import matplotlib.pyplot as plt
20 import matplotlib.pyplot as plt
21
21
22 from scipy.optimize import fmin_l_bfgs_b #optimize with bounds on state papameters
22 from scipy.optimize import fmin_l_bfgs_b #optimize with bounds on state papameters
23 from jroproc_base import ProcessingUnit, Operation
23 from jroproc_base import ProcessingUnit, Operation
24 from schainpy.model.data.jrodata import Parameters, hildebrand_sekhon
24 from schainpy.model.data.jrodata import Parameters, hildebrand_sekhon
25 from scipy import asarray as ar,exp
25 from scipy import asarray as ar,exp
26 from scipy.optimize import curve_fit
26 from scipy.optimize import curve_fit
27
27
28 import warnings
28 import warnings
29 from numpy import NaN
29 from numpy import NaN
30 from scipy.optimize.optimize import OptimizeWarning
30 from scipy.optimize.optimize import OptimizeWarning
31 from IPython.parallel.controller.scheduler import numpy
32 warnings.filterwarnings('ignore')
31 warnings.filterwarnings('ignore')
33
32
34
33
35 SPEED_OF_LIGHT = 299792458
34 SPEED_OF_LIGHT = 299792458
36
35
37
36
38 '''solving pickling issue'''
37 '''solving pickling issue'''
39
38
40 def _pickle_method(method):
39 def _pickle_method(method):
41 func_name = method.im_func.__name__
40 func_name = method.im_func.__name__
42 obj = method.im_self
41 obj = method.im_self
43 cls = method.im_class
42 cls = method.im_class
44 return _unpickle_method, (func_name, obj, cls)
43 return _unpickle_method, (func_name, obj, cls)
45
44
46 def _unpickle_method(func_name, obj, cls):
45 def _unpickle_method(func_name, obj, cls):
47 for cls in cls.mro():
46 for cls in cls.mro():
48 try:
47 try:
49 func = cls.__dict__[func_name]
48 func = cls.__dict__[func_name]
50 except KeyError:
49 except KeyError:
51 pass
50 pass
52 else:
51 else:
53 break
52 break
54 return func.__get__(obj, cls)
53 return func.__get__(obj, cls)
55
54
56 class ParametersProc(ProcessingUnit):
55 class ParametersProc(ProcessingUnit):
57
56
58 nSeconds = None
57 nSeconds = None
59
58
60 def __init__(self):
59 def __init__(self):
61 ProcessingUnit.__init__(self)
60 ProcessingUnit.__init__(self)
62
61
63 # self.objectDict = {}
62 # self.objectDict = {}
64 self.buffer = None
63 self.buffer = None
65 self.firstdatatime = None
64 self.firstdatatime = None
66 self.profIndex = 0
65 self.profIndex = 0
67 self.dataOut = Parameters()
66 self.dataOut = Parameters()
68
67
69 def __updateObjFromInput(self):
68 def __updateObjFromInput(self):
70
69
71 self.dataOut.inputUnit = self.dataIn.type
70 self.dataOut.inputUnit = self.dataIn.type
72
71
73 self.dataOut.timeZone = self.dataIn.timeZone
72 self.dataOut.timeZone = self.dataIn.timeZone
74 self.dataOut.dstFlag = self.dataIn.dstFlag
73 self.dataOut.dstFlag = self.dataIn.dstFlag
75 self.dataOut.errorCount = self.dataIn.errorCount
74 self.dataOut.errorCount = self.dataIn.errorCount
76 self.dataOut.useLocalTime = self.dataIn.useLocalTime
75 self.dataOut.useLocalTime = self.dataIn.useLocalTime
77
76
78 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
77 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
79 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
78 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
80 self.dataOut.channelList = self.dataIn.channelList
79 self.dataOut.channelList = self.dataIn.channelList
81 self.dataOut.heightList = self.dataIn.heightList
80 self.dataOut.heightList = self.dataIn.heightList
82 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
81 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
83 # self.dataOut.nHeights = self.dataIn.nHeights
82 # self.dataOut.nHeights = self.dataIn.nHeights
84 # self.dataOut.nChannels = self.dataIn.nChannels
83 # self.dataOut.nChannels = self.dataIn.nChannels
85 self.dataOut.nBaud = self.dataIn.nBaud
84 self.dataOut.nBaud = self.dataIn.nBaud
86 self.dataOut.nCode = self.dataIn.nCode
85 self.dataOut.nCode = self.dataIn.nCode
87 self.dataOut.code = self.dataIn.code
86 self.dataOut.code = self.dataIn.code
88 # self.dataOut.nProfiles = self.dataOut.nFFTPoints
87 # self.dataOut.nProfiles = self.dataOut.nFFTPoints
89 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
88 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
90 # self.dataOut.utctime = self.firstdatatime
89 # self.dataOut.utctime = self.firstdatatime
91 self.dataOut.utctime = self.dataIn.utctime
90 self.dataOut.utctime = self.dataIn.utctime
92 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
91 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
93 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
92 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
94 self.dataOut.nCohInt = self.dataIn.nCohInt
93 self.dataOut.nCohInt = self.dataIn.nCohInt
95 # self.dataOut.nIncohInt = 1
94 # self.dataOut.nIncohInt = 1
96 self.dataOut.ippSeconds = self.dataIn.ippSeconds
95 self.dataOut.ippSeconds = self.dataIn.ippSeconds
97 # self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
96 # self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
98 self.dataOut.timeInterval1 = self.dataIn.timeInterval
97 self.dataOut.timeInterval1 = self.dataIn.timeInterval
99 self.dataOut.heightList = self.dataIn.getHeiRange()
98 self.dataOut.heightList = self.dataIn.getHeiRange()
100 self.dataOut.frequency = self.dataIn.frequency
99 self.dataOut.frequency = self.dataIn.frequency
101 self.dataOut.noise = self.dataIn.noise
100 self.dataOut.noise = self.dataIn.noise
102
101
103
102
104
103
105 def run(self):
104 def run(self):
106
105
107 #---------------------- Voltage Data ---------------------------
106 #---------------------- Voltage Data ---------------------------
108
107
109 if self.dataIn.type == "Voltage":
108 if self.dataIn.type == "Voltage":
110
109
111 self.__updateObjFromInput()
110 self.__updateObjFromInput()
112 self.dataOut.data_pre = self.dataIn.data.copy()
111 self.dataOut.data_pre = self.dataIn.data.copy()
113 self.dataOut.flagNoData = False
112 self.dataOut.flagNoData = False
114 self.dataOut.utctimeInit = self.dataIn.utctime
113 self.dataOut.utctimeInit = self.dataIn.utctime
115 self.dataOut.paramInterval = self.dataIn.nProfiles*self.dataIn.nCohInt*self.dataIn.ippSeconds
114 self.dataOut.paramInterval = self.dataIn.nProfiles*self.dataIn.nCohInt*self.dataIn.ippSeconds
116 return
115 return
117
116
118 #---------------------- Spectra Data ---------------------------
117 #---------------------- Spectra Data ---------------------------
119
118
120 if self.dataIn.type == "Spectra":
119 if self.dataIn.type == "Spectra":
121
120
122 self.dataOut.data_pre = (self.dataIn.data_spc , self.dataIn.data_cspc)
121 self.dataOut.data_pre = (self.dataIn.data_spc , self.dataIn.data_cspc)
123 print 'self.dataIn.data_spc', self.dataIn.data_spc.shape
122 print 'self.dataIn.data_spc', self.dataIn.data_spc.shape
124 self.dataOut.abscissaList = self.dataIn.getVelRange(1)
123 self.dataOut.abscissaList = self.dataIn.getVelRange(1)
125 self.dataOut.spc_noise = self.dataIn.getNoise()
124 self.dataOut.spc_noise = self.dataIn.getNoise()
126 self.dataOut.spc_range = numpy.asanyarray((self.dataIn.getFreqRange(1) , self.dataIn.getAcfRange(1) , self.dataIn.getVelRange(1) ))
125 self.dataOut.spc_range = numpy.asanyarray((self.dataIn.getFreqRange(1) , self.dataIn.getAcfRange(1) , self.dataIn.getVelRange(1) ))
127
126
128 self.dataOut.normFactor = self.dataIn.normFactor
127 self.dataOut.normFactor = self.dataIn.normFactor
129 #self.dataOut.outputInterval = self.dataIn.outputInterval
128 #self.dataOut.outputInterval = self.dataIn.outputInterval
130 self.dataOut.groupList = self.dataIn.pairsList
129 self.dataOut.groupList = self.dataIn.pairsList
131 self.dataOut.flagNoData = False
130 self.dataOut.flagNoData = False
132 #print 'datain chandist ',self.dataIn.ChanDist
131 #print 'datain chandist ',self.dataIn.ChanDist
133 if hasattr(self.dataIn, 'ChanDist'): #Distances of receiver channels
132 if hasattr(self.dataIn, 'ChanDist'): #Distances of receiver channels
134 self.dataOut.ChanDist = self.dataIn.ChanDist
133 self.dataOut.ChanDist = self.dataIn.ChanDist
135 else: self.dataOut.ChanDist = None
134 else: self.dataOut.ChanDist = None
136
135
137 print 'datain chandist ',self.dataOut.ChanDist
136 print 'datain chandist ',self.dataOut.ChanDist
138
137
139 #if hasattr(self.dataIn, 'VelRange'): #Velocities range
138 #if hasattr(self.dataIn, 'VelRange'): #Velocities range
140 # self.dataOut.VelRange = self.dataIn.VelRange
139 # self.dataOut.VelRange = self.dataIn.VelRange
141 #else: self.dataOut.VelRange = None
140 #else: self.dataOut.VelRange = None
142
141
143 if hasattr(self.dataIn, 'RadarConst'): #Radar Constant
142 if hasattr(self.dataIn, 'RadarConst'): #Radar Constant
144 self.dataOut.RadarConst = self.dataIn.RadarConst
143 self.dataOut.RadarConst = self.dataIn.RadarConst
145
144
146 if hasattr(self.dataIn, 'NPW'): #NPW
145 if hasattr(self.dataIn, 'NPW'): #NPW
147 self.dataOut.NPW = self.dataIn.NPW
146 self.dataOut.NPW = self.dataIn.NPW
148
147
149 if hasattr(self.dataIn, 'COFA'): #COFA
148 if hasattr(self.dataIn, 'COFA'): #COFA
150 self.dataOut.COFA = self.dataIn.COFA
149 self.dataOut.COFA = self.dataIn.COFA
151
150
152
151
153
152
154 #---------------------- Correlation Data ---------------------------
153 #---------------------- Correlation Data ---------------------------
155
154
156 if self.dataIn.type == "Correlation":
155 if self.dataIn.type == "Correlation":
157 acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.dataIn.splitFunctions()
156 acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.dataIn.splitFunctions()
158
157
159 self.dataOut.data_pre = (self.dataIn.data_cf[acf_ind,:], self.dataIn.data_cf[ccf_ind,:,:])
158 self.dataOut.data_pre = (self.dataIn.data_cf[acf_ind,:], self.dataIn.data_cf[ccf_ind,:,:])
160 self.dataOut.normFactor = (self.dataIn.normFactor[acf_ind,:], self.dataIn.normFactor[ccf_ind,:])
159 self.dataOut.normFactor = (self.dataIn.normFactor[acf_ind,:], self.dataIn.normFactor[ccf_ind,:])
161 self.dataOut.groupList = (acf_pairs, ccf_pairs)
160 self.dataOut.groupList = (acf_pairs, ccf_pairs)
162
161
163 self.dataOut.abscissaList = self.dataIn.lagRange
162 self.dataOut.abscissaList = self.dataIn.lagRange
164 self.dataOut.noise = self.dataIn.noise
163 self.dataOut.noise = self.dataIn.noise
165 self.dataOut.data_SNR = self.dataIn.SNR
164 self.dataOut.data_SNR = self.dataIn.SNR
166 self.dataOut.flagNoData = False
165 self.dataOut.flagNoData = False
167 self.dataOut.nAvg = self.dataIn.nAvg
166 self.dataOut.nAvg = self.dataIn.nAvg
168
167
169 #---------------------- Parameters Data ---------------------------
168 #---------------------- Parameters Data ---------------------------
170
169
171 if self.dataIn.type == "Parameters":
170 if self.dataIn.type == "Parameters":
172 self.dataOut.copy(self.dataIn)
171 self.dataOut.copy(self.dataIn)
173 self.dataOut.flagNoData = False
172 self.dataOut.flagNoData = False
174
173
175 return True
174 return True
176
175
177 self.__updateObjFromInput()
176 self.__updateObjFromInput()
178 self.dataOut.utctimeInit = self.dataIn.utctime
177 self.dataOut.utctimeInit = self.dataIn.utctime
179 self.dataOut.paramInterval = self.dataIn.timeInterval
178 self.dataOut.paramInterval = self.dataIn.timeInterval
180
179
181 return
180 return
182
181
183
182
184 def target(tups):
183 def target(tups):
185
184
186 obj, args = tups
185 obj, args = tups
187 #print 'TARGETTT', obj, args
186 #print 'TARGETTT', obj, args
188 return obj.FitGau(args)
187 return obj.FitGau(args)
189
188
190
189
191 class SpectralFilters(Operation):
190 class SpectralFilters(Operation):
192
191
193 '''This class allows the Rainfall / Wind Selection for CLAIRE RADAR
192 '''This class allows the Rainfall / Wind Selection for CLAIRE RADAR
194
193
195 LimitR : It is the limit in m/s of Rainfall
194 LimitR : It is the limit in m/s of Rainfall
196 LimitW : It is the limit in m/s for Winds
195 LimitW : It is the limit in m/s for Winds
197
196
198 Input:
197 Input:
199
198
200 self.dataOut.data_pre : SPC and CSPC
199 self.dataOut.data_pre : SPC and CSPC
201 self.dataOut.spc_range : To select wind and rainfall velocities
200 self.dataOut.spc_range : To select wind and rainfall velocities
202
201
203 Affected:
202 Affected:
204
203
205 self.dataOut.data_pre : It is used for the new SPC and CSPC ranges of wind
204 self.dataOut.data_pre : It is used for the new SPC and CSPC ranges of wind
206 self.dataOut.spcparam_range : Used in SpcParamPlot
205 self.dataOut.spcparam_range : Used in SpcParamPlot
207 self.dataOut.SPCparam : Used in PrecipitationProc
206 self.dataOut.SPCparam : Used in PrecipitationProc
208
207
209
208
210 '''
209 '''
211
210
212 def __init__(self, **kwargs):
211 def __init__(self, **kwargs):
213 Operation.__init__(self, **kwargs)
212 Operation.__init__(self, **kwargs)
214 self.i=0
213 self.i=0
215
214
216 def run(self, dataOut, Rain_Velocity_Limit=1.5, Wind_Velocity_Limit=2.5):
215 def run(self, dataOut, PositiveLimit=1.5, NegativeLimit=2.5):
216
217
217
218 #Limite de vientos
218 #Limite de vientos
219 LimitR = Rain_Velocity_Limit
219 LimitR = PositiveLimit
220 LimitW = Wind_Velocity_Limit
220 LimitN = NegativeLimit
221
221
222 self.spc = dataOut.data_pre[0].copy()
222 self.spc = dataOut.data_pre[0].copy()
223 self.cspc = dataOut.data_pre[1].copy()
223 self.cspc = dataOut.data_pre[1].copy()
224
224
225 self.Num_Hei = self.spc.shape[2]
225 self.Num_Hei = self.spc.shape[2]
226 self.Num_Bin = self.spc.shape[1]
226 self.Num_Bin = self.spc.shape[1]
227 self.Num_Chn = self.spc.shape[0]
227 self.Num_Chn = self.spc.shape[0]
228
228
229 VelRange = dataOut.spc_range[2]
229 VelRange = dataOut.spc_range[2]
230 TimeRange = dataOut.spc_range[1]
230 TimeRange = dataOut.spc_range[1]
231 FrecRange = dataOut.spc_range[0]
231 FrecRange = dataOut.spc_range[0]
232
232
233 Vmax= 2*numpy.max(dataOut.spc_range[2])
233 Vmax= 2*numpy.max(dataOut.spc_range[2])
234 Tmax= 2*numpy.max(dataOut.spc_range[1])
234 Tmax= 2*numpy.max(dataOut.spc_range[1])
235 Fmax= 2*numpy.max(dataOut.spc_range[0])
235 Fmax= 2*numpy.max(dataOut.spc_range[0])
236
236
237 Breaker1R=VelRange[numpy.abs(VelRange-(-LimitR)).argmin()]
237 Breaker1R=VelRange[numpy.abs(VelRange-(-LimitN)).argmin()]
238 Breaker1R=numpy.where(VelRange == Breaker1R)
238 Breaker1R=numpy.where(VelRange == Breaker1R)
239
239
240 Breaker1W=VelRange[numpy.abs(VelRange-(-LimitW)).argmin()]
240 Delta = self.Num_Bin/2 - Breaker1R[0]
241 Breaker1W=numpy.where(VelRange == Breaker1W)
241
242 #Breaker1W=VelRange[numpy.abs(VelRange-(-LimitW)).argmin()]
243 #Breaker1W=numpy.where(VelRange == Breaker1W)
242
244
243 Breaker2W=VelRange[numpy.abs(VelRange-(LimitW)).argmin()]
245 #Breaker2W=VelRange[numpy.abs(VelRange-(LimitW)).argmin()]
244 Breaker2W=numpy.where(VelRange == Breaker2W)
246 #Breaker2W=numpy.where(VelRange == Breaker2W)
245
247
246
248
247 '''Reacomodando SPCrange'''
249 '''Reacomodando SPCrange'''
248
250
249 VelRange=numpy.roll(VelRange,-Breaker1R[0],axis=0)
251 VelRange=numpy.roll(VelRange,-(self.Num_Bin/2) ,axis=0)
250
252
251 VelRange[-int(Breaker1R[0]):]+= Vmax
253 VelRange[-(self.Num_Bin/2):]+= Vmax
252
254
253 FrecRange=numpy.roll(FrecRange,-Breaker1R[0],axis=0)
255 FrecRange=numpy.roll(FrecRange,-(self.Num_Bin/2),axis=0)
254
256
255 FrecRange[-int(Breaker1R[0]):]+= Fmax
257 FrecRange[-(self.Num_Bin/2):]+= Fmax
256
258
257 TimeRange=numpy.roll(TimeRange,-Breaker1R[0],axis=0)
259 TimeRange=numpy.roll(TimeRange,-(self.Num_Bin/2),axis=0)
258
260
259 TimeRange[-int(Breaker1R[0]):]+= Tmax
261 TimeRange[-(self.Num_Bin/2):]+= Tmax
260
262
261 ''' ------------------ '''
263 ''' ------------------ '''
262
264
263 Breaker2R=VelRange[numpy.abs(VelRange-(LimitR)).argmin()]
265 Breaker2R=VelRange[numpy.abs(VelRange-(LimitR)).argmin()]
264 Breaker2R=numpy.where(VelRange == Breaker2R)
266 Breaker2R=numpy.where(VelRange == Breaker2R)
265
267
266
268
267
269 SPCroll = numpy.roll(self.spc,-(self.Num_Bin/2) ,axis=1)
268
269 SPCroll = numpy.roll(self.spc,-Breaker1R[0],axis=1)
270
270
271 SPCcut = SPCroll.copy()
271 SPCcut = SPCroll.copy()
272 for i in range(self.Num_Chn):
272 for i in range(self.Num_Chn):
273
273 SPCcut[i,0:int(Breaker2R[0]),:] = dataOut.noise[i]
274 SPCcut[i,0:int(Breaker2R[0]),:] = dataOut.noise[i]
275 SPCcut[i,-int(Delta):,:] = dataOut.noise[i]
274
276
275 self.spc[i, 0:int(Breaker1W[0]) ,:] = dataOut.noise[i]
277 #self.spc[i, 0:int(Breaker1W[0]) ,:] = dataOut.noise[i]
276 self.spc[i, int(Breaker2W[0]):self.Num_Bin ,:] = dataOut.noise[i]
278 #self.spc[i, int(Breaker2W[0]):self.Num_Bin ,:] = dataOut.noise[i]
277
279
278 self.cspc[i, 0:int(Breaker1W[0]) ,:] = dataOut.noise[i]
280 #self.cspc[i, 0:int(Breaker1W[0]) ,:] = dataOut.noise[i]
279 self.cspc[i, int(Breaker2W[0]):self.Num_Bin ,:] = dataOut.noise[i]
281 #self.cspc[i, int(Breaker2W[0]):self.Num_Bin ,:] = dataOut.noise[i]
280
282
281
283
284
285
282 SPC_ch1 = SPCroll
286 SPC_ch1 = SPCroll
283
287
284 SPC_ch2 = SPCcut
288 SPC_ch2 = SPCcut
285
289
286 SPCparam = (SPC_ch1, SPC_ch2, self.spc)
290 SPCparam = (SPC_ch1, SPC_ch2, self.spc)
287 dataOut.SPCparam = numpy.asarray(SPCparam)
291 dataOut.SPCparam = numpy.asarray(SPCparam)
288
292
289 dataOut.data_pre= (self.spc , self.cspc)
293 #dataOut.data_pre= (self.spc , self.cspc)
290
294
291 #dataOut.data_preParam = (self.spc , self.cspc)
295 #dataOut.data_preParam = (self.spc , self.cspc)
292
296
293 dataOut.spcparam_range=numpy.zeros([self.Num_Chn,self.Num_Bin+1])
297 dataOut.spcparam_range=numpy.zeros([self.Num_Chn,self.Num_Bin+1])
294
298
295 dataOut.spcparam_range[2]=VelRange
299 dataOut.spcparam_range[2]=VelRange
296 dataOut.spcparam_range[1]=TimeRange
300 dataOut.spcparam_range[1]=TimeRange
297 dataOut.spcparam_range[0]=FrecRange
301 dataOut.spcparam_range[0]=FrecRange
298
302
299
303
300
304
301
305
302 class GaussianFit(Operation):
306 class GaussianFit(Operation):
303
307
304 '''
308 '''
305 Function that fit of one and two generalized gaussians (gg) based
309 Function that fit of one and two generalized gaussians (gg) based
306 on the PSD shape across an "power band" identified from a cumsum of
310 on the PSD shape across an "power band" identified from a cumsum of
307 the measured spectrum - noise.
311 the measured spectrum - noise.
308
312
309 Input:
313 Input:
310 self.dataOut.data_pre : SelfSpectra
314 self.dataOut.data_pre : SelfSpectra
311
315
312 Output:
316 Output:
313 self.dataOut.SPCparam : SPC_ch1, SPC_ch2
317 self.dataOut.SPCparam : SPC_ch1, SPC_ch2
314
318
315 '''
319 '''
316 def __init__(self, **kwargs):
320 def __init__(self, **kwargs):
317 Operation.__init__(self, **kwargs)
321 Operation.__init__(self, **kwargs)
318 self.i=0
322 self.i=0
319
323
320
324
321 def run(self, dataOut, num_intg=7, pnoise=1., SNRlimit=-9): #num_intg: Incoherent integrations, pnoise: Noise, vel_arr: range of velocities, similar to the ftt points
325 def run(self, dataOut, num_intg=7, pnoise=1., SNRlimit=-9): #num_intg: Incoherent integrations, pnoise: Noise, vel_arr: range of velocities, similar to the ftt points
322 """This routine will find a couple of generalized Gaussians to a power spectrum
326 """This routine will find a couple of generalized Gaussians to a power spectrum
323 input: spc
327 input: spc
324 output:
328 output:
325 Amplitude0,shift0,width0,p0,Amplitude1,shift1,width1,p1,noise
329 Amplitude0,shift0,width0,p0,Amplitude1,shift1,width1,p1,noise
326 """
330 """
327
331
328 self.spc = dataOut.data_pre[0].copy()
332 self.spc = dataOut.data_pre[0].copy()
329
333
330
334
331 print 'SelfSpectra Shape', numpy.asarray(self.spc).shape
335 print 'SelfSpectra Shape', numpy.asarray(self.spc).shape
332
336
333
337
334 #plt.figure(50)
338 #plt.figure(50)
335 #plt.subplot(121)
339 #plt.subplot(121)
336 #plt.plot(self.spc,'k',label='spc(66)')
340 #plt.plot(self.spc,'k',label='spc(66)')
337 #plt.plot(xFrec,ySamples[1],'g',label='Ch1')
341 #plt.plot(xFrec,ySamples[1],'g',label='Ch1')
338 #plt.plot(xFrec,ySamples[2],'r',label='Ch2')
342 #plt.plot(xFrec,ySamples[2],'r',label='Ch2')
339 #plt.plot(xFrec,FitGauss,'yo:',label='fit')
343 #plt.plot(xFrec,FitGauss,'yo:',label='fit')
340 #plt.legend()
344 #plt.legend()
341 #plt.title('DATOS A ALTURA DE 7500 METROS')
345 #plt.title('DATOS A ALTURA DE 7500 METROS')
342 #plt.show()
346 #plt.show()
343
347
344 self.Num_Hei = self.spc.shape[2]
348 self.Num_Hei = self.spc.shape[2]
345 #self.Num_Bin = len(self.spc)
349 #self.Num_Bin = len(self.spc)
346 self.Num_Bin = self.spc.shape[1]
350 self.Num_Bin = self.spc.shape[1]
347 self.Num_Chn = self.spc.shape[0]
351 self.Num_Chn = self.spc.shape[0]
348 Vrange = dataOut.abscissaList
352 Vrange = dataOut.abscissaList
349
353
350 GauSPC = numpy.empty([self.Num_Chn,self.Num_Bin,self.Num_Hei])
354 GauSPC = numpy.empty([self.Num_Chn,self.Num_Bin,self.Num_Hei])
351 SPC_ch1 = numpy.empty([self.Num_Bin,self.Num_Hei])
355 SPC_ch1 = numpy.empty([self.Num_Bin,self.Num_Hei])
352 SPC_ch2 = numpy.empty([self.Num_Bin,self.Num_Hei])
356 SPC_ch2 = numpy.empty([self.Num_Bin,self.Num_Hei])
353 SPC_ch1[:] = numpy.NaN
357 SPC_ch1[:] = numpy.NaN
354 SPC_ch2[:] = numpy.NaN
358 SPC_ch2[:] = numpy.NaN
355
359
356
360
357 start_time = time.time()
361 start_time = time.time()
358
362
359 noise_ = dataOut.spc_noise[0].copy()
363 noise_ = dataOut.spc_noise[0].copy()
360
364
361
365
362 pool = Pool(processes=self.Num_Chn)
366 pool = Pool(processes=self.Num_Chn)
363 args = [(Vrange, Ch, pnoise, noise_, num_intg, SNRlimit) for Ch in range(self.Num_Chn)]
367 args = [(Vrange, Ch, pnoise, noise_, num_intg, SNRlimit) for Ch in range(self.Num_Chn)]
364 objs = [self for __ in range(self.Num_Chn)]
368 objs = [self for __ in range(self.Num_Chn)]
365 attrs = zip(objs, args)
369 attrs = zip(objs, args)
366 gauSPC = pool.map(target, attrs)
370 gauSPC = pool.map(target, attrs)
367 dataOut.SPCparam = numpy.asarray(SPCparam)
371 dataOut.SPCparam = numpy.asarray(SPCparam)
368
372
369
373
370
374
371 print '========================================================'
375 print '========================================================'
372 print 'total_time: ', time.time()-start_time
376 print 'total_time: ', time.time()-start_time
373
377
374 # re-normalizing spc and noise
378 # re-normalizing spc and noise
375 # This part differs from gg1
379 # This part differs from gg1
376
380
377
381
378
382
379 ''' Parameters:
383 ''' Parameters:
380 1. Amplitude
384 1. Amplitude
381 2. Shift
385 2. Shift
382 3. Width
386 3. Width
383 4. Power
387 4. Power
384 '''
388 '''
385
389
386
390
387 ###############################################################################
391 ###############################################################################
388 def FitGau(self, X):
392 def FitGau(self, X):
389
393
390 Vrange, ch, pnoise, noise_, num_intg, SNRlimit = X
394 Vrange, ch, pnoise, noise_, num_intg, SNRlimit = X
391 #print 'VARSSSS', ch, pnoise, noise, num_intg
395 #print 'VARSSSS', ch, pnoise, noise, num_intg
392
396
393 #print 'HEIGHTS', self.Num_Hei
397 #print 'HEIGHTS', self.Num_Hei
394
398
395 SPCparam = []
399 SPCparam = []
396 SPC_ch1 = numpy.empty([self.Num_Bin,self.Num_Hei])
400 SPC_ch1 = numpy.empty([self.Num_Bin,self.Num_Hei])
397 SPC_ch2 = numpy.empty([self.Num_Bin,self.Num_Hei])
401 SPC_ch2 = numpy.empty([self.Num_Bin,self.Num_Hei])
398 SPC_ch1[:] = 0#numpy.NaN
402 SPC_ch1[:] = 0#numpy.NaN
399 SPC_ch2[:] = 0#numpy.NaN
403 SPC_ch2[:] = 0#numpy.NaN
400
404
401
405
402
406
403 for ht in range(self.Num_Hei):
407 for ht in range(self.Num_Hei):
404 #print (numpy.asarray(self.spc).shape)
408 #print (numpy.asarray(self.spc).shape)
405
409
406 #print 'TTTTT', ch , ht
410 #print 'TTTTT', ch , ht
407 #print self.spc.shape
411 #print self.spc.shape
408
412
409
413
410 spc = numpy.asarray(self.spc)[ch,:,ht]
414 spc = numpy.asarray(self.spc)[ch,:,ht]
411
415
412 #############################################
416 #############################################
413 # normalizing spc and noise
417 # normalizing spc and noise
414 # This part differs from gg1
418 # This part differs from gg1
415 spc_norm_max = max(spc)
419 spc_norm_max = max(spc)
416 #spc = spc / spc_norm_max
420 #spc = spc / spc_norm_max
417 pnoise = pnoise #/ spc_norm_max
421 pnoise = pnoise #/ spc_norm_max
418 #############################################
422 #############################################
419
423
420 fatspectra=1.0
424 fatspectra=1.0
421
425
422 wnoise = noise_ #/ spc_norm_max
426 wnoise = noise_ #/ spc_norm_max
423 #wnoise,stdv,i_max,index =enoise(spc,num_intg) #noise estimate using Hildebrand Sekhon, only wnoise is used
427 #wnoise,stdv,i_max,index =enoise(spc,num_intg) #noise estimate using Hildebrand Sekhon, only wnoise is used
424 #if wnoise>1.1*pnoise: # to be tested later
428 #if wnoise>1.1*pnoise: # to be tested later
425 # wnoise=pnoise
429 # wnoise=pnoise
426 noisebl=wnoise*0.9;
430 noisebl=wnoise*0.9;
427 noisebh=wnoise*1.1
431 noisebh=wnoise*1.1
428 spc=spc-wnoise
432 spc=spc-wnoise
429 # print 'wnoise', noise_[0], spc_norm_max, wnoise
433 # print 'wnoise', noise_[0], spc_norm_max, wnoise
430 minx=numpy.argmin(spc)
434 minx=numpy.argmin(spc)
431 #spcs=spc.copy()
435 #spcs=spc.copy()
432 spcs=numpy.roll(spc,-minx)
436 spcs=numpy.roll(spc,-minx)
433 cum=numpy.cumsum(spcs)
437 cum=numpy.cumsum(spcs)
434 tot_noise=wnoise * self.Num_Bin #64;
438 tot_noise=wnoise * self.Num_Bin #64;
435 #print 'spc' , spcs[5:8] , 'tot_noise', tot_noise
439 #print 'spc' , spcs[5:8] , 'tot_noise', tot_noise
436 #tot_signal=sum(cum[-5:])/5.; ''' How does this line work? '''
440 #tot_signal=sum(cum[-5:])/5.; ''' How does this line work? '''
437 #snr=tot_signal/tot_noise
441 #snr=tot_signal/tot_noise
438 #snr=cum[-1]/tot_noise
442 #snr=cum[-1]/tot_noise
439 snr = sum(spcs)/tot_noise
443 snr = sum(spcs)/tot_noise
440 snrdB=10.*numpy.log10(snr)
444 snrdB=10.*numpy.log10(snr)
441
445
442 if snrdB < SNRlimit :
446 if snrdB < SNRlimit :
443 snr = numpy.NaN
447 snr = numpy.NaN
444 SPC_ch1[:,ht] = 0#numpy.NaN
448 SPC_ch1[:,ht] = 0#numpy.NaN
445 SPC_ch1[:,ht] = 0#numpy.NaN
449 SPC_ch1[:,ht] = 0#numpy.NaN
446 SPCparam = (SPC_ch1,SPC_ch2)
450 SPCparam = (SPC_ch1,SPC_ch2)
447 continue
451 continue
448 #print 'snr',snrdB #, sum(spcs) , tot_noise
452 #print 'snr',snrdB #, sum(spcs) , tot_noise
449
453
450
454
451
455
452 #if snrdB<-18 or numpy.isnan(snrdB) or num_intg<4:
456 #if snrdB<-18 or numpy.isnan(snrdB) or num_intg<4:
453 # return [None,]*4,[None,]*4,None,snrdB,None,None,[None,]*5,[None,]*9,None
457 # return [None,]*4,[None,]*4,None,snrdB,None,None,[None,]*5,[None,]*9,None
454
458
455 cummax=max(cum);
459 cummax=max(cum);
456 epsi=0.08*fatspectra # cumsum to narrow down the energy region
460 epsi=0.08*fatspectra # cumsum to narrow down the energy region
457 cumlo=cummax*epsi;
461 cumlo=cummax*epsi;
458 cumhi=cummax*(1-epsi)
462 cumhi=cummax*(1-epsi)
459 powerindex=numpy.array(numpy.where(numpy.logical_and(cum>cumlo, cum<cumhi))[0])
463 powerindex=numpy.array(numpy.where(numpy.logical_and(cum>cumlo, cum<cumhi))[0])
460
464
461
465
462 if len(powerindex) < 1:# case for powerindex 0
466 if len(powerindex) < 1:# case for powerindex 0
463 continue
467 continue
464 powerlo=powerindex[0]
468 powerlo=powerindex[0]
465 powerhi=powerindex[-1]
469 powerhi=powerindex[-1]
466 powerwidth=powerhi-powerlo
470 powerwidth=powerhi-powerlo
467
471
468 firstpeak=powerlo+powerwidth/10.# first gaussian energy location
472 firstpeak=powerlo+powerwidth/10.# first gaussian energy location
469 secondpeak=powerhi-powerwidth/10.#second gaussian energy location
473 secondpeak=powerhi-powerwidth/10.#second gaussian energy location
470 midpeak=(firstpeak+secondpeak)/2.
474 midpeak=(firstpeak+secondpeak)/2.
471 firstamp=spcs[int(firstpeak)]
475 firstamp=spcs[int(firstpeak)]
472 secondamp=spcs[int(secondpeak)]
476 secondamp=spcs[int(secondpeak)]
473 midamp=spcs[int(midpeak)]
477 midamp=spcs[int(midpeak)]
474
478
475 x=numpy.arange( self.Num_Bin )
479 x=numpy.arange( self.Num_Bin )
476 y_data=spc+wnoise
480 y_data=spc+wnoise
477
481
478 ''' single Gaussian '''
482 ''' single Gaussian '''
479 shift0=numpy.mod(midpeak+minx, self.Num_Bin )
483 shift0=numpy.mod(midpeak+minx, self.Num_Bin )
480 width0=powerwidth/4.#Initialization entire power of spectrum divided by 4
484 width0=powerwidth/4.#Initialization entire power of spectrum divided by 4
481 power0=2.
485 power0=2.
482 amplitude0=midamp
486 amplitude0=midamp
483 state0=[shift0,width0,amplitude0,power0,wnoise]
487 state0=[shift0,width0,amplitude0,power0,wnoise]
484 bnds=(( 0,(self.Num_Bin-1) ),(1,powerwidth),(0,None),(0.5,3.),(noisebl,noisebh))
488 bnds=(( 0,(self.Num_Bin-1) ),(1,powerwidth),(0,None),(0.5,3.),(noisebl,noisebh))
485 lsq1=fmin_l_bfgs_b(self.misfit1,state0,args=(y_data,x,num_intg),bounds=bnds,approx_grad=True)
489 lsq1=fmin_l_bfgs_b(self.misfit1,state0,args=(y_data,x,num_intg),bounds=bnds,approx_grad=True)
486
490
487 chiSq1=lsq1[1];
491 chiSq1=lsq1[1];
488
492
489
493
490 if fatspectra<1.0 and powerwidth<4:
494 if fatspectra<1.0 and powerwidth<4:
491 choice=0
495 choice=0
492 Amplitude0=lsq1[0][2]
496 Amplitude0=lsq1[0][2]
493 shift0=lsq1[0][0]
497 shift0=lsq1[0][0]
494 width0=lsq1[0][1]
498 width0=lsq1[0][1]
495 p0=lsq1[0][3]
499 p0=lsq1[0][3]
496 Amplitude1=0.
500 Amplitude1=0.
497 shift1=0.
501 shift1=0.
498 width1=0.
502 width1=0.
499 p1=0.
503 p1=0.
500 noise=lsq1[0][4]
504 noise=lsq1[0][4]
501 #return (numpy.array([shift0,width0,Amplitude0,p0]),
505 #return (numpy.array([shift0,width0,Amplitude0,p0]),
502 # numpy.array([shift1,width1,Amplitude1,p1]),noise,snrdB,chiSq1,6.,sigmas1,[None,]*9,choice)
506 # numpy.array([shift1,width1,Amplitude1,p1]),noise,snrdB,chiSq1,6.,sigmas1,[None,]*9,choice)
503
507
504 ''' two gaussians '''
508 ''' two gaussians '''
505 #shift0=numpy.mod(firstpeak+minx,64); shift1=numpy.mod(secondpeak+minx,64)
509 #shift0=numpy.mod(firstpeak+minx,64); shift1=numpy.mod(secondpeak+minx,64)
506 shift0=numpy.mod(firstpeak+minx, self.Num_Bin );
510 shift0=numpy.mod(firstpeak+minx, self.Num_Bin );
507 shift1=numpy.mod(secondpeak+minx, self.Num_Bin )
511 shift1=numpy.mod(secondpeak+minx, self.Num_Bin )
508 width0=powerwidth/6.;
512 width0=powerwidth/6.;
509 width1=width0
513 width1=width0
510 power0=2.;
514 power0=2.;
511 power1=power0
515 power1=power0
512 amplitude0=firstamp;
516 amplitude0=firstamp;
513 amplitude1=secondamp
517 amplitude1=secondamp
514 state0=[shift0,width0,amplitude0,power0,shift1,width1,amplitude1,power1,wnoise]
518 state0=[shift0,width0,amplitude0,power0,shift1,width1,amplitude1,power1,wnoise]
515 #bnds=((0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(noisebl,noisebh))
519 #bnds=((0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(noisebl,noisebh))
516 bnds=(( 0,(self.Num_Bin-1) ),(1,powerwidth/2.),(0,None),(0.5,3.),( 0,(self.Num_Bin-1)),(1,powerwidth/2.),(0,None),(0.5,3.),(noisebl,noisebh))
520 bnds=(( 0,(self.Num_Bin-1) ),(1,powerwidth/2.),(0,None),(0.5,3.),( 0,(self.Num_Bin-1)),(1,powerwidth/2.),(0,None),(0.5,3.),(noisebl,noisebh))
517 #bnds=(( 0,(self.Num_Bin-1) ),(1,powerwidth/2.),(0,None),(0.5,3.),( 0,(self.Num_Bin-1)),(1,powerwidth/2.),(0,None),(0.5,3.),(0.1,0.5))
521 #bnds=(( 0,(self.Num_Bin-1) ),(1,powerwidth/2.),(0,None),(0.5,3.),( 0,(self.Num_Bin-1)),(1,powerwidth/2.),(0,None),(0.5,3.),(0.1,0.5))
518
522
519 lsq2 = fmin_l_bfgs_b( self.misfit2 , state0 , args=(y_data,x,num_intg) , bounds=bnds , approx_grad=True )
523 lsq2 = fmin_l_bfgs_b( self.misfit2 , state0 , args=(y_data,x,num_intg) , bounds=bnds , approx_grad=True )
520
524
521
525
522 chiSq2=lsq2[1];
526 chiSq2=lsq2[1];
523
527
524
528
525
529
526 oneG=(chiSq1<5 and chiSq1/chiSq2<2.0) and (abs(lsq2[0][0]-lsq2[0][4])<(lsq2[0][1]+lsq2[0][5])/3. or abs(lsq2[0][0]-lsq2[0][4])<10)
530 oneG=(chiSq1<5 and chiSq1/chiSq2<2.0) and (abs(lsq2[0][0]-lsq2[0][4])<(lsq2[0][1]+lsq2[0][5])/3. or abs(lsq2[0][0]-lsq2[0][4])<10)
527
531
528 if snrdB>-12: # when SNR is strong pick the peak with least shift (LOS velocity) error
532 if snrdB>-12: # when SNR is strong pick the peak with least shift (LOS velocity) error
529 if oneG:
533 if oneG:
530 choice=0
534 choice=0
531 else:
535 else:
532 w1=lsq2[0][1]; w2=lsq2[0][5]
536 w1=lsq2[0][1]; w2=lsq2[0][5]
533 a1=lsq2[0][2]; a2=lsq2[0][6]
537 a1=lsq2[0][2]; a2=lsq2[0][6]
534 p1=lsq2[0][3]; p2=lsq2[0][7]
538 p1=lsq2[0][3]; p2=lsq2[0][7]
535 s1=(2**(1+1./p1))*scipy.special.gamma(1./p1)/p1;
539 s1=(2**(1+1./p1))*scipy.special.gamma(1./p1)/p1;
536 s2=(2**(1+1./p2))*scipy.special.gamma(1./p2)/p2;
540 s2=(2**(1+1./p2))*scipy.special.gamma(1./p2)/p2;
537 gp1=a1*w1*s1; gp2=a2*w2*s2 # power content of each ggaussian with proper p scaling
541 gp1=a1*w1*s1; gp2=a2*w2*s2 # power content of each ggaussian with proper p scaling
538
542
539 if gp1>gp2:
543 if gp1>gp2:
540 if a1>0.7*a2:
544 if a1>0.7*a2:
541 choice=1
545 choice=1
542 else:
546 else:
543 choice=2
547 choice=2
544 elif gp2>gp1:
548 elif gp2>gp1:
545 if a2>0.7*a1:
549 if a2>0.7*a1:
546 choice=2
550 choice=2
547 else:
551 else:
548 choice=1
552 choice=1
549 else:
553 else:
550 choice=numpy.argmax([a1,a2])+1
554 choice=numpy.argmax([a1,a2])+1
551 #else:
555 #else:
552 #choice=argmin([std2a,std2b])+1
556 #choice=argmin([std2a,std2b])+1
553
557
554 else: # with low SNR go to the most energetic peak
558 else: # with low SNR go to the most energetic peak
555 choice=numpy.argmax([lsq1[0][2]*lsq1[0][1],lsq2[0][2]*lsq2[0][1],lsq2[0][6]*lsq2[0][5]])
559 choice=numpy.argmax([lsq1[0][2]*lsq1[0][1],lsq2[0][2]*lsq2[0][1],lsq2[0][6]*lsq2[0][5]])
556
560
557
561
558 shift0=lsq2[0][0];
562 shift0=lsq2[0][0];
559 vel0=Vrange[0] + shift0*(Vrange[1]-Vrange[0])
563 vel0=Vrange[0] + shift0*(Vrange[1]-Vrange[0])
560 shift1=lsq2[0][4];
564 shift1=lsq2[0][4];
561 vel1=Vrange[0] + shift1*(Vrange[1]-Vrange[0])
565 vel1=Vrange[0] + shift1*(Vrange[1]-Vrange[0])
562
566
563 max_vel = 1.0
567 max_vel = 1.0
564
568
565 #first peak will be 0, second peak will be 1
569 #first peak will be 0, second peak will be 1
566 if vel0 > -1.0 and vel0 < max_vel : #first peak is in the correct range
570 if vel0 > -1.0 and vel0 < max_vel : #first peak is in the correct range
567 shift0=lsq2[0][0]
571 shift0=lsq2[0][0]
568 width0=lsq2[0][1]
572 width0=lsq2[0][1]
569 Amplitude0=lsq2[0][2]
573 Amplitude0=lsq2[0][2]
570 p0=lsq2[0][3]
574 p0=lsq2[0][3]
571
575
572 shift1=lsq2[0][4]
576 shift1=lsq2[0][4]
573 width1=lsq2[0][5]
577 width1=lsq2[0][5]
574 Amplitude1=lsq2[0][6]
578 Amplitude1=lsq2[0][6]
575 p1=lsq2[0][7]
579 p1=lsq2[0][7]
576 noise=lsq2[0][8]
580 noise=lsq2[0][8]
577 else:
581 else:
578 shift1=lsq2[0][0]
582 shift1=lsq2[0][0]
579 width1=lsq2[0][1]
583 width1=lsq2[0][1]
580 Amplitude1=lsq2[0][2]
584 Amplitude1=lsq2[0][2]
581 p1=lsq2[0][3]
585 p1=lsq2[0][3]
582
586
583 shift0=lsq2[0][4]
587 shift0=lsq2[0][4]
584 width0=lsq2[0][5]
588 width0=lsq2[0][5]
585 Amplitude0=lsq2[0][6]
589 Amplitude0=lsq2[0][6]
586 p0=lsq2[0][7]
590 p0=lsq2[0][7]
587 noise=lsq2[0][8]
591 noise=lsq2[0][8]
588
592
589 if Amplitude0<0.05: # in case the peak is noise
593 if Amplitude0<0.05: # in case the peak is noise
590 shift0,width0,Amplitude0,p0 = [0,0,0,0]#4*[numpy.NaN]
594 shift0,width0,Amplitude0,p0 = [0,0,0,0]#4*[numpy.NaN]
591 if Amplitude1<0.05:
595 if Amplitude1<0.05:
592 shift1,width1,Amplitude1,p1 = [0,0,0,0]#4*[numpy.NaN]
596 shift1,width1,Amplitude1,p1 = [0,0,0,0]#4*[numpy.NaN]
593
597
594
598
595 # if choice==0: # pick the single gaussian fit
599 # if choice==0: # pick the single gaussian fit
596 # Amplitude0=lsq1[0][2]
600 # Amplitude0=lsq1[0][2]
597 # shift0=lsq1[0][0]
601 # shift0=lsq1[0][0]
598 # width0=lsq1[0][1]
602 # width0=lsq1[0][1]
599 # p0=lsq1[0][3]
603 # p0=lsq1[0][3]
600 # Amplitude1=0.
604 # Amplitude1=0.
601 # shift1=0.
605 # shift1=0.
602 # width1=0.
606 # width1=0.
603 # p1=0.
607 # p1=0.
604 # noise=lsq1[0][4]
608 # noise=lsq1[0][4]
605 # elif choice==1: # take the first one of the 2 gaussians fitted
609 # elif choice==1: # take the first one of the 2 gaussians fitted
606 # Amplitude0 = lsq2[0][2]
610 # Amplitude0 = lsq2[0][2]
607 # shift0 = lsq2[0][0]
611 # shift0 = lsq2[0][0]
608 # width0 = lsq2[0][1]
612 # width0 = lsq2[0][1]
609 # p0 = lsq2[0][3]
613 # p0 = lsq2[0][3]
610 # Amplitude1 = lsq2[0][6] # This is 0 in gg1
614 # Amplitude1 = lsq2[0][6] # This is 0 in gg1
611 # shift1 = lsq2[0][4] # This is 0 in gg1
615 # shift1 = lsq2[0][4] # This is 0 in gg1
612 # width1 = lsq2[0][5] # This is 0 in gg1
616 # width1 = lsq2[0][5] # This is 0 in gg1
613 # p1 = lsq2[0][7] # This is 0 in gg1
617 # p1 = lsq2[0][7] # This is 0 in gg1
614 # noise = lsq2[0][8]
618 # noise = lsq2[0][8]
615 # else: # the second one
619 # else: # the second one
616 # Amplitude0 = lsq2[0][6]
620 # Amplitude0 = lsq2[0][6]
617 # shift0 = lsq2[0][4]
621 # shift0 = lsq2[0][4]
618 # width0 = lsq2[0][5]
622 # width0 = lsq2[0][5]
619 # p0 = lsq2[0][7]
623 # p0 = lsq2[0][7]
620 # Amplitude1 = lsq2[0][2] # This is 0 in gg1
624 # Amplitude1 = lsq2[0][2] # This is 0 in gg1
621 # shift1 = lsq2[0][0] # This is 0 in gg1
625 # shift1 = lsq2[0][0] # This is 0 in gg1
622 # width1 = lsq2[0][1] # This is 0 in gg1
626 # width1 = lsq2[0][1] # This is 0 in gg1
623 # p1 = lsq2[0][3] # This is 0 in gg1
627 # p1 = lsq2[0][3] # This is 0 in gg1
624 # noise = lsq2[0][8]
628 # noise = lsq2[0][8]
625
629
626 #print len(noise + Amplitude0*numpy.exp(-0.5*(abs(x-shift0))/width0)**p0)
630 #print len(noise + Amplitude0*numpy.exp(-0.5*(abs(x-shift0))/width0)**p0)
627 SPC_ch1[:,ht] = noise + Amplitude0*numpy.exp(-0.5*(abs(x-shift0))/width0)**p0
631 SPC_ch1[:,ht] = noise + Amplitude0*numpy.exp(-0.5*(abs(x-shift0))/width0)**p0
628 SPC_ch2[:,ht] = noise + Amplitude1*numpy.exp(-0.5*(abs(x-shift1))/width1)**p1
632 SPC_ch2[:,ht] = noise + Amplitude1*numpy.exp(-0.5*(abs(x-shift1))/width1)**p1
629 #print 'SPC_ch1.shape',SPC_ch1.shape
633 #print 'SPC_ch1.shape',SPC_ch1.shape
630 #print 'SPC_ch2.shape',SPC_ch2.shape
634 #print 'SPC_ch2.shape',SPC_ch2.shape
631 #dataOut.data_param = SPC_ch1
635 #dataOut.data_param = SPC_ch1
632 SPCparam = (SPC_ch1,SPC_ch2)
636 SPCparam = (SPC_ch1,SPC_ch2)
633 #GauSPC[1] = SPC_ch2
637 #GauSPC[1] = SPC_ch2
634
638
635 # print 'shift0', shift0
639 # print 'shift0', shift0
636 # print 'Amplitude0', Amplitude0
640 # print 'Amplitude0', Amplitude0
637 # print 'width0', width0
641 # print 'width0', width0
638 # print 'p0', p0
642 # print 'p0', p0
639 # print '========================'
643 # print '========================'
640 # print 'shift1', shift1
644 # print 'shift1', shift1
641 # print 'Amplitude1', Amplitude1
645 # print 'Amplitude1', Amplitude1
642 # print 'width1', width1
646 # print 'width1', width1
643 # print 'p1', p1
647 # print 'p1', p1
644 # print 'noise', noise
648 # print 'noise', noise
645 # print 's_noise', wnoise
649 # print 's_noise', wnoise
646
650
647 return GauSPC
651 return GauSPC
648
652
649 def y_model1(self,x,state):
653 def y_model1(self,x,state):
650 shift0,width0,amplitude0,power0,noise=state
654 shift0,width0,amplitude0,power0,noise=state
651 model0=amplitude0*numpy.exp(-0.5*abs((x-shift0)/width0)**power0)
655 model0=amplitude0*numpy.exp(-0.5*abs((x-shift0)/width0)**power0)
652
656
653 model0u=amplitude0*numpy.exp(-0.5*abs((x-shift0- self.Num_Bin )/width0)**power0)
657 model0u=amplitude0*numpy.exp(-0.5*abs((x-shift0- self.Num_Bin )/width0)**power0)
654
658
655 model0d=amplitude0*numpy.exp(-0.5*abs((x-shift0+ self.Num_Bin )/width0)**power0)
659 model0d=amplitude0*numpy.exp(-0.5*abs((x-shift0+ self.Num_Bin )/width0)**power0)
656 return model0+model0u+model0d+noise
660 return model0+model0u+model0d+noise
657
661
658 def y_model2(self,x,state): #Equation for two generalized Gaussians with Nyquist
662 def y_model2(self,x,state): #Equation for two generalized Gaussians with Nyquist
659 shift0,width0,amplitude0,power0,shift1,width1,amplitude1,power1,noise=state
663 shift0,width0,amplitude0,power0,shift1,width1,amplitude1,power1,noise=state
660 model0=amplitude0*numpy.exp(-0.5*abs((x-shift0)/width0)**power0)
664 model0=amplitude0*numpy.exp(-0.5*abs((x-shift0)/width0)**power0)
661
665
662 model0u=amplitude0*numpy.exp(-0.5*abs((x-shift0- self.Num_Bin )/width0)**power0)
666 model0u=amplitude0*numpy.exp(-0.5*abs((x-shift0- self.Num_Bin )/width0)**power0)
663
667
664 model0d=amplitude0*numpy.exp(-0.5*abs((x-shift0+ self.Num_Bin )/width0)**power0)
668 model0d=amplitude0*numpy.exp(-0.5*abs((x-shift0+ self.Num_Bin )/width0)**power0)
665 model1=amplitude1*numpy.exp(-0.5*abs((x-shift1)/width1)**power1)
669 model1=amplitude1*numpy.exp(-0.5*abs((x-shift1)/width1)**power1)
666
670
667 model1u=amplitude1*numpy.exp(-0.5*abs((x-shift1- self.Num_Bin )/width1)**power1)
671 model1u=amplitude1*numpy.exp(-0.5*abs((x-shift1- self.Num_Bin )/width1)**power1)
668
672
669 model1d=amplitude1*numpy.exp(-0.5*abs((x-shift1+ self.Num_Bin )/width1)**power1)
673 model1d=amplitude1*numpy.exp(-0.5*abs((x-shift1+ self.Num_Bin )/width1)**power1)
670 return model0+model0u+model0d+model1+model1u+model1d+noise
674 return model0+model0u+model0d+model1+model1u+model1d+noise
671
675
672 def misfit1(self,state,y_data,x,num_intg): # This function compares how close real data is with the model data, the close it is, the better it is.
676 def misfit1(self,state,y_data,x,num_intg): # This function compares how close real data is with the model data, the close it is, the better it is.
673
677
674 return num_intg*sum((numpy.log(y_data)-numpy.log(self.y_model1(x,state)))**2)#/(64-5.) # /(64-5.) can be commented
678 return num_intg*sum((numpy.log(y_data)-numpy.log(self.y_model1(x,state)))**2)#/(64-5.) # /(64-5.) can be commented
675
679
676 def misfit2(self,state,y_data,x,num_intg):
680 def misfit2(self,state,y_data,x,num_intg):
677 return num_intg*sum((numpy.log(y_data)-numpy.log(self.y_model2(x,state)))**2)#/(64-9.)
681 return num_intg*sum((numpy.log(y_data)-numpy.log(self.y_model2(x,state)))**2)#/(64-9.)
678
682
679
683
680
684
681 class PrecipitationProc(Operation):
685 class PrecipitationProc(Operation):
682
686
683 '''
687 '''
684 Operator that estimates Reflectivity factor (Z), and estimates rainfall Rate (R)
688 Operator that estimates Reflectivity factor (Z), and estimates rainfall Rate (R)
685
689
686 Input:
690 Input:
687 self.dataOut.data_pre : SelfSpectra
691 self.dataOut.data_pre : SelfSpectra
688
692
689 Output:
693 Output:
690
694
691 self.dataOut.data_output : Reflectivity factor, rainfall Rate
695 self.dataOut.data_output : Reflectivity factor, rainfall Rate
692
696
693
697
694 Parameters affected:
698 Parameters affected:
695 '''
699 '''
696 def gaus(self,xSamples,Amp,Mu,Sigma):
700 def gaus(self,xSamples,Amp,Mu,Sigma):
697 return ( Amp / ((2*numpy.pi)**0.5 * Sigma) ) * numpy.exp( -( xSamples - Mu )**2 / ( 2 * (Sigma**2) ))
701 return ( Amp / ((2*numpy.pi)**0.5 * Sigma) ) * numpy.exp( -( xSamples - Mu )**2 / ( 2 * (Sigma**2) ))
698
702
699
703
700
704
701 def Moments(self, ySamples, xSamples):
705 def Moments(self, ySamples, xSamples):
702 Pot = numpy.nansum( ySamples ) # Potencia, momento 0
706 Pot = numpy.nansum( ySamples ) # Potencia, momento 0
703 yNorm = ySamples / Pot
707 yNorm = ySamples / Pot
704
708
705 Vr = numpy.nansum( yNorm * xSamples ) # Velocidad radial, mu, corrimiento doppler, primer momento
709 Vr = numpy.nansum( yNorm * xSamples ) # Velocidad radial, mu, corrimiento doppler, primer momento
706 Sigma2 = abs(numpy.nansum( yNorm * ( xSamples - Vr )**2 )) # Segundo Momento
710 Sigma2 = abs(numpy.nansum( yNorm * ( xSamples - Vr )**2 )) # Segundo Momento
707 Desv = Sigma2**0.5 # Desv. Estandar, Ancho espectral
711 Desv = Sigma2**0.5 # Desv. Estandar, Ancho espectral
708
712
709 return numpy.array([Pot, Vr, Desv])
713 return numpy.array([Pot, Vr, Desv])
710
714
711 def run(self, dataOut, radar=None, Pt=5000, Gt=295.1209, Gr=70.7945, Lambda=0.6741, aL=2.5118,
715 def run(self, dataOut, radar=None, Pt=5000, Gt=295.1209, Gr=70.7945, Lambda=0.6741, aL=2.5118,
712 tauW=4e-06, ThetaT=0.1656317, ThetaR=0.36774087, Km = 0.93, Altitude=3350):
716 tauW=4e-06, ThetaT=0.1656317, ThetaR=0.36774087, Km = 0.93, Altitude=3350):
713
717
714
718
715 Velrange = dataOut.spc_range[2]
719 Velrange = dataOut.spcparam_range[2]
716 FrecRange = dataOut.spc_range[0]
720 FrecRange = dataOut.spcparam_range[0]
717
721
718 dV= Velrange[1]-Velrange[0]
722 dV= Velrange[1]-Velrange[0]
719 dF= FrecRange[1]-FrecRange[0]
723 dF= FrecRange[1]-FrecRange[0]
720
724
721 if radar == "MIRA35C" :
725 if radar == "MIRA35C" :
722
726
723 self.spc = dataOut.data_pre[0].copy()
727 self.spc = dataOut.data_pre[0].copy()
724 self.Num_Hei = self.spc.shape[2]
728 self.Num_Hei = self.spc.shape[2]
725 self.Num_Bin = self.spc.shape[1]
729 self.Num_Bin = self.spc.shape[1]
726 self.Num_Chn = self.spc.shape[0]
730 self.Num_Chn = self.spc.shape[0]
727 Ze = self.dBZeMODE2(dataOut)
731 Ze = self.dBZeMODE2(dataOut)
728
732
729 else:
733 else:
730
734
731 self.spc = dataOut.SPCparam[1] #dataOut.data_pre[0].copy() #
735 self.spc = dataOut.SPCparam[1].copy() #dataOut.data_pre[0].copy() #
732 self.Num_Hei = self.spc.shape[2]
736 self.Num_Hei = self.spc.shape[2]
733 self.Num_Bin = self.spc.shape[1]
737 self.Num_Bin = self.spc.shape[1]
734 self.Num_Chn = self.spc.shape[0]
738 self.Num_Chn = self.spc.shape[0]
735 print '==================== SPC SHAPE',numpy.shape(self.spc)
739 print '==================== SPC SHAPE',numpy.shape(self.spc)
736
740
737
741
738 ''' Se obtiene la constante del RADAR '''
742 ''' Se obtiene la constante del RADAR '''
739
743
740 self.Pt = Pt
744 self.Pt = Pt
741 self.Gt = Gt
745 self.Gt = Gt
742 self.Gr = Gr
746 self.Gr = Gr
743 self.Lambda = Lambda
747 self.Lambda = Lambda
744 self.aL = aL
748 self.aL = aL
745 self.tauW = tauW
749 self.tauW = tauW
746 self.ThetaT = ThetaT
750 self.ThetaT = ThetaT
747 self.ThetaR = ThetaR
751 self.ThetaR = ThetaR
748
752
749 Numerator = ( (4*numpy.pi)**3 * aL**2 * 16 * numpy.log(2) )
753 Numerator = ( (4*numpy.pi)**3 * aL**2 * 16 * numpy.log(2) )
750 Denominator = ( Pt * Gt * Gr * Lambda**2 * SPEED_OF_LIGHT * tauW * numpy.pi * ThetaT * ThetaR)
754 Denominator = ( Pt * Gt * Gr * Lambda**2 * SPEED_OF_LIGHT * tauW * numpy.pi * ThetaT * ThetaR)
751 RadarConstant = 4.1396e+08# Numerator / Denominator
755 RadarConstant = 1/4.1396e+08# Numerator / Denominator #
752 print '***'
756 print '***'
753 print '*** RadarConstant' , RadarConstant, '****'
757 print '*** RadarConstant' , RadarConstant, '****'
754 print '***'
758 print '***'
755 ''' ============================= '''
759 ''' ============================= '''
756
760
757 SPCmean = numpy.mean(self.spc,0)
761 self.spc[0] = self.spc[0]-dataOut.noise[0]
758 ETAf = numpy.zeros([self.Num_Bin,self.Num_Hei])
762 self.spc[1] = self.spc[1]-dataOut.noise[1]
763 self.spc[2] = self.spc[2]-dataOut.noise[2]
764
765 self.spc[ numpy.where(self.spc < 0)] = 0
766
767 SPCmean = numpy.mean(self.spc,0) - numpy.mean(dataOut.noise)
768 SPCmean[ numpy.where(SPCmean < 0)] = 1e-20
769
770 ETAn = numpy.zeros([self.Num_Bin,self.Num_Hei])
759 ETAv = numpy.zeros([self.Num_Bin,self.Num_Hei])
771 ETAv = numpy.zeros([self.Num_Bin,self.Num_Hei])
760 ETAd = numpy.zeros([self.Num_Bin,self.Num_Hei])
772 ETAd = numpy.zeros([self.Num_Bin,self.Num_Hei])
761
773
762 Pr = self.spc[0,:,:]
774 Pr = SPCmean[:,:]
763
775
764 VelMeteoro = numpy.mean(SPCmean,axis=0)
776 VelMeteoro = numpy.mean(SPCmean,axis=0)
765
777
766 #print '==================== Vel SHAPE',VelMeteoro
778 #print '==================== Vel SHAPE',VelMeteoro
767
779
768 D_range = numpy.zeros([self.Num_Bin,self.Num_Hei])
780 D_range = numpy.zeros([self.Num_Bin,self.Num_Hei])
769 SIGMA = numpy.zeros([self.Num_Bin,self.Num_Hei])
781 SIGMA = numpy.zeros([self.Num_Bin,self.Num_Hei])
770 N_dist = numpy.zeros([self.Num_Bin,self.Num_Hei])
782 N_dist = numpy.zeros([self.Num_Bin,self.Num_Hei])
771 D_mean = numpy.zeros(self.Num_Hei)
783 D_mean = numpy.zeros(self.Num_Hei)
772 del_V = numpy.zeros(self.Num_Hei)
784 del_V = numpy.zeros(self.Num_Hei)
773 Z = numpy.zeros(self.Num_Hei)
785 Z = numpy.zeros(self.Num_Hei)
774 Ze = numpy.zeros(self.Num_Hei)
786 Ze = numpy.zeros(self.Num_Hei)
775 RR = numpy.zeros(self.Num_Hei)
787 RR = numpy.zeros(self.Num_Hei)
776
788
789 Range = dataOut.heightList*1000.
777
790
778 for R in range(self.Num_Hei):
791 for R in range(self.Num_Hei):
779
792
780 h = R*75 + Altitude #Range from ground to radar pulse altitude
793 h = Range[R] + Altitude #Range from ground to radar pulse altitude
781 del_V[R] = 1 + 3.68 * 10**-5 * h + 1.71 * 10**-9 * h**2 #Density change correction for velocity
794 del_V[R] = 1 + 3.68 * 10**-5 * h + 1.71 * 10**-9 * h**2 #Density change correction for velocity
782
795
783 D_range[:,R] = numpy.log( (9.65 - (Velrange[0:self.Num_Bin] / del_V[R])) / 10.3 ) / -0.6 #Range of Diameter of drops related to velocity
796 D_range[:,R] = numpy.log( (9.65 - (Velrange[0:self.Num_Bin] / del_V[R])) / 10.3 ) / -0.6 #Diameter range [m]x10**-3
797
798 '''NOTA: ETA(n) dn = ETA(f) df
799
800 dn = 1 Diferencial de muestreo
801 df = ETA(n) / ETA(f)
802
803 '''
784
804
785 ETAf[:,R] = 1/RadarConstant * Pr[:,R] * (R*0.075)**2 #Reflectivity (ETA)
805 ETAn[:,R] = RadarConstant * Pr[:,R] * (Range[R] )**2 #Reflectivity (ETA)
786
806
787 ETAv[:,R]=ETAf[:,R]*dF/dV
807 ETAv[:,R]=ETAn[:,R]/dV
788
808
789 ETAd[:,R]=ETAv[:,R]*6.18*exp(-0.6*D_range[:,R])
809 ETAd[:,R]=ETAv[:,R]*6.18*exp(-0.6*D_range[:,R])
790
810
791 SIGMA[:,R] = numpy.pi**5 / Lambda**4 * Km * D_range[:,R]**6 #Equivalent Section of drops (sigma)
811 SIGMA[:,R] = Km * (D_range[:,R] * 1e-3 )**6 * numpy.pi**5 / Lambda**4 #Equivalent Section of drops (sigma)
792
812
793 N_dist[:,R] = ETAd[:,R] / SIGMA[:,R]
813 N_dist[:,R] = ETAn[:,R] / SIGMA[:,R]
794
814
795 DMoments = self.Moments(Pr[:,R], D_range[:,R])
815 DMoments = self.Moments(Pr[:,R], D_range[:,R])
796
816
797 try:
817 try:
798 popt01,pcov = curve_fit(self.gaus, D_range[:,R] , Pr[:,R] , p0=DMoments)
818 popt01,pcov = curve_fit(self.gaus, D_range[:,R] , Pr[:,R] , p0=DMoments)
799 except:
819 except:
800 popt01=numpy.zeros(3)
820 popt01=numpy.zeros(3)
801 popt01[1]= DMoments[1]
821 popt01[1]= DMoments[1]
802 D_mean[R]=popt01[1]
822 D_mean[R]=popt01[1]
803
823
804 Z[R] = numpy.nansum( N_dist[:,R] * D_range[:,R]**6 )
824 Z[R] = numpy.nansum( N_dist[:,R] * (D_range[:,R])**6 )*1e-18
805
825
806 RR[R] = 6*10**-4.*numpy.pi * numpy.nansum( D_range[:,R]**3 * N_dist[:,R] * Velrange[0:self.Num_Bin] ) #Rainfall rate
826 RR[R] = 6*10**-4.*numpy.pi * numpy.nansum( D_range[:,R]**3 * N_dist[:,R] * Velrange[0:self.Num_Bin] ) #Rainfall rate
807
827
808 Ze[R] = (numpy.nansum(ETAd[:,R]) * Lambda**4) / (numpy.pi * Km)
828 Ze[R] = (numpy.nansum( ETAn[:,R]) * Lambda**4) / ( numpy.pi**5 * Km)
809
829
810
830
811
831
812 RR2 = (Z/200)**(1/1.6)
832 RR2 = (Z/200)**(1/1.6)
813 dBRR = 10*numpy.log10(RR)
833 dBRR = 10*numpy.log10(RR)
814 dBRR2 = 10*numpy.log10(RR2)
834 dBRR2 = 10*numpy.log10(RR2)
815
835
816 dBZe = 10*numpy.log10(Ze)
836 dBZe = 10*numpy.log10(Ze)
817 dBZ = 10*numpy.log10(Z)
837 dBZ = 10*numpy.log10(Z)
818
838
819 dataOut.data_output = Z
839 dataOut.data_output = Z
820 dataOut.data_param = numpy.ones([3,self.Num_Hei])
840 dataOut.data_param = numpy.ones([3,self.Num_Hei])
821 dataOut.channelList = [0,1,2]
841 dataOut.channelList = [0,1,2]
822
842
823 dataOut.data_param[0]=dBZ
843 dataOut.data_param[0]=dBZ
824 dataOut.data_param[1]=dBZe
844 dataOut.data_param[1]=dBZe
825 dataOut.data_param[2]=dBRR2
845 dataOut.data_param[2]=RR
826
846
827 print 'RR SHAPE', dBRR.shape
847 #print 'VELRANGE', Velrange
828 #print 'Ze ', dBZe
848 print 'Range', len(Range)
849 print 'delv',del_V
850 #print 'DRANGE', D_range[:,50]
851 print 'NOISE', dataOut.noise[0]
852 print 'radarconstant', RadarConstant
853 print 'Range', Range
854 print 'ETAn SHAPE', ETAn.shape
855 print 'ETAn ', numpy.nansum(ETAn, axis=0)
856 print 'ETAd ', numpy.nansum(ETAd, axis=0)
857 print 'Pr ', numpy.nansum(Pr, axis=0)
858 print 'dataOut.SPCparam[1]', numpy.nansum(dataOut.SPCparam[1][0], axis=0)
859 print 'Ze ', dBZe
829 print 'Z ', dBZ
860 print 'Z ', dBZ
830 print 'RR ', dBRR
861 #print 'RR2 ', RR2
862 #print 'RR ', RR
831 #print 'RR2 ', dBRR2
863 #print 'RR2 ', dBRR2
832 #print 'D_mean', D_mean
864 #print 'D_mean', D_mean
833 #print 'del_V', del_V
865 #print 'del_V', del_V
834 #print 'D_range',D_range.shape, D_range[:,30]
866 #print 'D_range',D_range.shape, D_range[:,30]
835 #print 'Velrange', Velrange
867 #print 'Velrange', Velrange
836 #print 'numpy.nansum( N_dist[:,R]', numpy.nansum( N_dist, axis=0)
868 #print 'numpy.nansum( N_dist[:,R]', numpy.nansum( N_dist, axis=0)
837 #print 'dataOut.data_param SHAPE', dataOut.data_param.shape
869 #print 'dataOut.data_param SHAPE', dataOut.data_param.shape
838
870
839
871
840 def dBZeMODE2(self, dataOut): # Processing for MIRA35C
872 def dBZeMODE2(self, dataOut): # Processing for MIRA35C
841
873
842 NPW = dataOut.NPW
874 NPW = dataOut.NPW
843 COFA = dataOut.COFA
875 COFA = dataOut.COFA
844
876
845 SNR = numpy.array([self.spc[0,:,:] / NPW[0]]) #, self.spc[1,:,:] / NPW[1]])
877 SNR = numpy.array([self.spc[0,:,:] / NPW[0]]) #, self.spc[1,:,:] / NPW[1]])
846 RadarConst = dataOut.RadarConst
878 RadarConst = dataOut.RadarConst
847 #frequency = 34.85*10**9
879 #frequency = 34.85*10**9
848
880
849 ETA = numpy.zeros(([self.Num_Chn ,self.Num_Hei]))
881 ETA = numpy.zeros(([self.Num_Chn ,self.Num_Hei]))
850 data_output = numpy.ones([self.Num_Chn , self.Num_Hei])*numpy.NaN
882 data_output = numpy.ones([self.Num_Chn , self.Num_Hei])*numpy.NaN
851
883
852 ETA = numpy.sum(SNR,1)
884 ETA = numpy.sum(SNR,1)
853 print 'ETA' , ETA
885 print 'ETA' , ETA
854 ETA = numpy.where(ETA is not 0. , ETA, numpy.NaN)
886 ETA = numpy.where(ETA is not 0. , ETA, numpy.NaN)
855
887
856 Ze = numpy.ones([self.Num_Chn, self.Num_Hei] )
888 Ze = numpy.ones([self.Num_Chn, self.Num_Hei] )
857
889
858 for r in range(self.Num_Hei):
890 for r in range(self.Num_Hei):
859
891
860 Ze[0,r] = ( ETA[0,r] ) * COFA[0,r][0] * RadarConst * ((r/5000.)**2)
892 Ze[0,r] = ( ETA[0,r] ) * COFA[0,r][0] * RadarConst * ((r/5000.)**2)
861 #Ze[1,r] = ( ETA[1,r] ) * COFA[1,r][0] * RadarConst * ((r/5000.)**2)
893 #Ze[1,r] = ( ETA[1,r] ) * COFA[1,r][0] * RadarConst * ((r/5000.)**2)
862
894
863 return Ze
895 return Ze
864
896
865 # def GetRadarConstant(self):
897 # def GetRadarConstant(self):
866 #
898 #
867 # """
899 # """
868 # Constants:
900 # Constants:
869 #
901 #
870 # Pt: Transmission Power dB 5kW 5000
902 # Pt: Transmission Power dB 5kW 5000
871 # Gt: Transmission Gain dB 24.7 dB 295.1209
903 # Gt: Transmission Gain dB 24.7 dB 295.1209
872 # Gr: Reception Gain dB 18.5 dB 70.7945
904 # Gr: Reception Gain dB 18.5 dB 70.7945
873 # Lambda: Wavelenght m 0.6741 m 0.6741
905 # Lambda: Wavelenght m 0.6741 m 0.6741
874 # aL: Attenuation loses dB 4dB 2.5118
906 # aL: Attenuation loses dB 4dB 2.5118
875 # tauW: Width of transmission pulse s 4us 4e-6
907 # tauW: Width of transmission pulse s 4us 4e-6
876 # ThetaT: Transmission antenna bean angle rad 0.1656317 rad 0.1656317
908 # ThetaT: Transmission antenna bean angle rad 0.1656317 rad 0.1656317
877 # ThetaR: Reception antenna beam angle rad 0.36774087 rad 0.36774087
909 # ThetaR: Reception antenna beam angle rad 0.36774087 rad 0.36774087
878 #
910 #
879 # """
911 # """
880 #
912 #
881 # Numerator = ( (4*numpy.pi)**3 * aL**2 * 16 * numpy.log(2) )
913 # Numerator = ( (4*numpy.pi)**3 * aL**2 * 16 * numpy.log(2) )
882 # Denominator = ( Pt * Gt * Gr * Lambda**2 * SPEED_OF_LIGHT * TauW * numpy.pi * ThetaT * TheraR)
914 # Denominator = ( Pt * Gt * Gr * Lambda**2 * SPEED_OF_LIGHT * TauW * numpy.pi * ThetaT * TheraR)
883 # RadarConstant = Numerator / Denominator
915 # RadarConstant = Numerator / Denominator
884 #
916 #
885 # return RadarConstant
917 # return RadarConstant
886
918
887
919
888
920
889 class FullSpectralAnalysis(Operation):
921 class FullSpectralAnalysis(Operation):
890
922
891 """
923 """
892 Function that implements Full Spectral Analisys technique.
924 Function that implements Full Spectral Analisys technique.
893
925
894 Input:
926 Input:
895 self.dataOut.data_pre : SelfSpectra and CrossSPectra data
927 self.dataOut.data_pre : SelfSpectra and CrossSPectra data
896 self.dataOut.groupList : Pairlist of channels
928 self.dataOut.groupList : Pairlist of channels
897 self.dataOut.ChanDist : Physical distance between receivers
929 self.dataOut.ChanDist : Physical distance between receivers
898
930
899
931
900 Output:
932 Output:
901
933
902 self.dataOut.data_output : Zonal wind, Meridional wind and Vertical wind
934 self.dataOut.data_output : Zonal wind, Meridional wind and Vertical wind
903
935
904
936
905 Parameters affected: Winds, height range, SNR
937 Parameters affected: Winds, height range, SNR
906
938
907 """
939 """
908 def run(self, dataOut, E01=None, E02=None, E12=None, N01=None, N02=None, N12=None, SNRlimit=7):
940 def run(self, dataOut, E01=None, E02=None, E12=None, N01=None, N02=None, N12=None, SNRlimit=7):
909
941
910 self.indice=int(numpy.random.rand()*1000)
942 self.indice=int(numpy.random.rand()*1000)
911
943
912 spc = dataOut.data_pre[0].copy()
944 spc = dataOut.data_pre[0].copy()
913 cspc = dataOut.data_pre[1]
945 cspc = dataOut.data_pre[1]
914
946
915 nChannel = spc.shape[0]
947 nChannel = spc.shape[0]
916 nProfiles = spc.shape[1]
948 nProfiles = spc.shape[1]
917 nHeights = spc.shape[2]
949 nHeights = spc.shape[2]
918
950
919 pairsList = dataOut.groupList
951 pairsList = dataOut.groupList
920 if dataOut.ChanDist is not None :
952 if dataOut.ChanDist is not None :
921 ChanDist = dataOut.ChanDist
953 ChanDist = dataOut.ChanDist
922 else:
954 else:
923 ChanDist = numpy.array([[E01, N01],[E02,N02],[E12,N12]])
955 ChanDist = numpy.array([[E01, N01],[E02,N02],[E12,N12]])
924
956
925 FrecRange = dataOut.spc_range[0]
957 FrecRange = dataOut.spc_range[0]
926
958
927 ySamples=numpy.ones([nChannel,nProfiles])
959 ySamples=numpy.ones([nChannel,nProfiles])
928 phase=numpy.ones([nChannel,nProfiles])
960 phase=numpy.ones([nChannel,nProfiles])
929 CSPCSamples=numpy.ones([nChannel,nProfiles],dtype=numpy.complex_)
961 CSPCSamples=numpy.ones([nChannel,nProfiles],dtype=numpy.complex_)
930 coherence=numpy.ones([nChannel,nProfiles])
962 coherence=numpy.ones([nChannel,nProfiles])
931 PhaseSlope=numpy.ones(nChannel)
963 PhaseSlope=numpy.ones(nChannel)
932 PhaseInter=numpy.ones(nChannel)
964 PhaseInter=numpy.ones(nChannel)
933 data_SNR=numpy.zeros([nProfiles])
965 data_SNR=numpy.zeros([nProfiles])
934
966
935 data = dataOut.data_pre
967 data = dataOut.data_pre
936 noise = dataOut.noise
968 noise = dataOut.noise
937
969
938 dataOut.data_SNR = (numpy.mean(spc,axis=1)- noise[0]) / noise[0]
970 dataOut.data_SNR = (numpy.mean(spc,axis=1)- noise[0]) / noise[0]
939
971
972 dataOut.data_SNR[numpy.where( dataOut.data_SNR <0 )] = 1e-20
973
940
974
941
942 print dataOut.data_SNR.shape
943 #FirstMoment = dataOut.moments[0,1,:]#numpy.average(dataOut.data_param[:,1,:],0)
975 #FirstMoment = dataOut.moments[0,1,:]#numpy.average(dataOut.data_param[:,1,:],0)
944 #SecondMoment = numpy.average(dataOut.moments[:,2,:],0)
976 #SecondMoment = numpy.average(dataOut.moments[:,2,:],0)
945
977
946 #SNRdBMean = []
978 #SNRdBMean = []
947
979
948 data_output=numpy.ones([spc.shape[0],spc.shape[2]])*numpy.NaN
980 data_output=numpy.ones([spc.shape[0],spc.shape[2]])*numpy.NaN
949
981
950 velocityX=[]
982 velocityX=[]
951 velocityY=[]
983 velocityY=[]
952 velocityV=[]
984 velocityV=[]
953 PhaseLine=[]
985 PhaseLine=[]
954
986
955 dbSNR = 10*numpy.log10(dataOut.data_SNR)
987 dbSNR = 10*numpy.log10(dataOut.data_SNR)
956 dbSNR = numpy.average(dbSNR,0)
988 dbSNR = numpy.average(dbSNR,0)
957
989
958 for Height in range(nHeights):
990 for Height in range(nHeights):
959
991
960 [Vzon,Vmer,Vver, GaussCenter, PhaseSlope, FitGaussCSPC]= self.WindEstimation(spc, cspc, pairsList, ChanDist, Height, noise, dataOut.spc_range.copy(), dbSNR[Height], SNRlimit)
992 [Vzon,Vmer,Vver, GaussCenter, PhaseSlope, FitGaussCSPC]= self.WindEstimation(spc, cspc, pairsList, ChanDist, Height, noise, dataOut.spc_range.copy(), dbSNR[Height], SNRlimit)
961 PhaseLine = numpy.append(PhaseLine, PhaseSlope)
993 PhaseLine = numpy.append(PhaseLine, PhaseSlope)
962
994
963 if abs(Vzon)<100. and abs(Vzon)> 0.:
995 if abs(Vzon)<100. and abs(Vzon)> 0.:
964 velocityX=numpy.append(velocityX, -Vzon)#Vmag
996 velocityX=numpy.append(velocityX, -Vzon)#Vmag
965
997
966 else:
998 else:
967 #print 'Vzon',Vzon
999 #print 'Vzon',Vzon
968 velocityX=numpy.append(velocityX, numpy.NaN)
1000 velocityX=numpy.append(velocityX, numpy.NaN)
969
1001
970 if abs(Vmer)<100. and abs(Vmer) > 0.:
1002 if abs(Vmer)<100. and abs(Vmer) > 0.:
971 velocityY=numpy.append(velocityY, -Vmer)#Vang
1003 velocityY=numpy.append(velocityY, -Vmer)#Vang
972
1004
973 else:
1005 else:
974 #print 'Vmer',Vmer
1006 #print 'Vmer',Vmer
975 velocityY=numpy.append(velocityY, numpy.NaN)
1007 velocityY=numpy.append(velocityY, numpy.NaN)
976
1008
977 if dbSNR[Height] > SNRlimit:
1009 if dbSNR[Height] > SNRlimit:
978 velocityV=numpy.append(velocityV, -Vver)#FirstMoment[Height])
1010 velocityV=numpy.append(velocityV, -Vver)#FirstMoment[Height])
979 else:
1011 else:
980 velocityV=numpy.append(velocityV, numpy.NaN)
1012 velocityV=numpy.append(velocityV, numpy.NaN)
981 #FirstMoment[Height]= numpy.NaN
1013 #FirstMoment[Height]= numpy.NaN
982 # if SNRdBMean[Height] <12:
1014 # if SNRdBMean[Height] <12:
983 # FirstMoment[Height] = numpy.NaN
1015 # FirstMoment[Height] = numpy.NaN
984 # velocityX[Height] = numpy.NaN
1016 # velocityX[Height] = numpy.NaN
985 # velocityY[Height] = numpy.NaN
1017 # velocityY[Height] = numpy.NaN
986
1018
987
1019
988
1020
989 data_output[0] = numpy.array(velocityX) #self.moving_average(numpy.array(velocityX) , N=1)
1021 data_output[0] = numpy.array(velocityX) #self.moving_average(numpy.array(velocityX) , N=1)
990 data_output[1] = numpy.array(velocityY) #self.moving_average(numpy.array(velocityY) , N=1)
1022 data_output[1] = numpy.array(velocityY) #self.moving_average(numpy.array(velocityY) , N=1)
991 data_output[2] = -velocityV#FirstMoment
1023 data_output[2] = -velocityV#FirstMoment
992
1024
993 print 'FirstMoment', data_output[2]
1025 print 'FirstMoment', data_output[2]
994 #print FirstMoment
1026 #print FirstMoment
995 # print 'velocityX',numpy.shape(data_output[0])
1027 # print 'velocityX',numpy.shape(data_output[0])
996 # print 'velocityX',data_output[0]
1028 # print 'velocityX',data_output[0]
997 # print ' '
1029 # print ' '
998 # print 'velocityY',numpy.shape(data_output[1])
1030 # print 'velocityY',numpy.shape(data_output[1])
999 # print 'velocityY',data_output[1]
1031 # print 'velocityY',data_output[1]
1000 # print 'velocityV',data_output[2]
1032 # print 'velocityV',data_output[2]
1001 # print 'PhaseLine',PhaseLine
1033 # print 'PhaseLine',PhaseLine
1002 #print numpy.array(velocityY)
1034 #print numpy.array(velocityY)
1003 #print 'SNR'
1035 #print 'SNR'
1004 #print 10*numpy.log10(dataOut.data_SNR)
1036 #print 10*numpy.log10(dataOut.data_SNR)
1005 #print numpy.shape(10*numpy.log10(dataOut.data_SNR))
1037 #print numpy.shape(10*numpy.log10(dataOut.data_SNR))
1006 print ' '
1038 print ' '
1007
1039
1008 xFrec=FrecRange[0:spc.shape[1]]
1040 xFrec=FrecRange[0:spc.shape[1]]
1009
1041
1010 dataOut.data_output=data_output
1042 dataOut.data_output=data_output
1011
1043
1012 return
1044 return
1013
1045
1014
1046
1015 def moving_average(self,x, N=2):
1047 def moving_average(self,x, N=2):
1016 return numpy.convolve(x, numpy.ones((N,))/N)[(N-1):]
1048 return numpy.convolve(x, numpy.ones((N,))/N)[(N-1):]
1017
1049
1018 def gaus(self,xSamples,Amp,Mu,Sigma):
1050 def gaus(self,xSamples,Amp,Mu,Sigma):
1019 return ( Amp / ((2*numpy.pi)**0.5 * Sigma) ) * numpy.exp( -( xSamples - Mu )**2 / ( 2 * (Sigma**2) ))
1051 return ( Amp / ((2*numpy.pi)**0.5 * Sigma) ) * numpy.exp( -( xSamples - Mu )**2 / ( 2 * (Sigma**2) ))
1020
1052
1021
1053
1022
1054
1023 def Moments(self, ySamples, xSamples):
1055 def Moments(self, ySamples, xSamples):
1024 Pot = numpy.nansum( ySamples ) # Potencia, momento 0
1056 Pot = numpy.nansum( ySamples ) # Potencia, momento 0
1025 yNorm = ySamples / Pot
1057 yNorm = ySamples / Pot
1026
1027 Vr = numpy.nansum( yNorm * xSamples ) # Velocidad radial, mu, corrimiento doppler, primer momento
1058 Vr = numpy.nansum( yNorm * xSamples ) # Velocidad radial, mu, corrimiento doppler, primer momento
1028 Sigma2 = abs(numpy.nansum( yNorm * ( xSamples - Vr )**2 )) # Segundo Momento
1059 Sigma2 = abs(numpy.nansum( yNorm * ( xSamples - Vr )**2 )) # Segundo Momento
1029 Desv = Sigma2**0.5 # Desv. Estandar, Ancho espectral
1060 Desv = Sigma2**0.5 # Desv. Estandar, Ancho espectral
1030
1061
1031 return numpy.array([Pot, Vr, Desv])
1062 return numpy.array([Pot, Vr, Desv])
1032
1063
1033 def WindEstimation(self, spc, cspc, pairsList, ChanDist, Height, noise, AbbsisaRange, dbSNR, SNRlimit):
1064 def WindEstimation(self, spc, cspc, pairsList, ChanDist, Height, noise, AbbsisaRange, dbSNR, SNRlimit):
1034
1065
1035 # print ' '
1066
1036 # print '######################## Height',Height, (1000 + 75*Height), '##############################'
1037 # print ' '
1038
1067
1039 ySamples=numpy.ones([spc.shape[0],spc.shape[1]])
1068 ySamples=numpy.ones([spc.shape[0],spc.shape[1]])
1040 phase=numpy.ones([spc.shape[0],spc.shape[1]])
1069 phase=numpy.ones([spc.shape[0],spc.shape[1]])
1041 CSPCSamples=numpy.ones([spc.shape[0],spc.shape[1]],dtype=numpy.complex_)
1070 CSPCSamples=numpy.ones([spc.shape[0],spc.shape[1]],dtype=numpy.complex_)
1042 coherence=numpy.ones([spc.shape[0],spc.shape[1]])
1071 coherence=numpy.ones([spc.shape[0],spc.shape[1]])
1043 PhaseSlope=numpy.zeros(spc.shape[0])
1072 PhaseSlope=numpy.zeros(spc.shape[0])
1044 PhaseInter=numpy.ones(spc.shape[0])
1073 PhaseInter=numpy.ones(spc.shape[0])
1045 xFrec=AbbsisaRange[0][0:spc.shape[1]]
1074 xFrec=AbbsisaRange[0][0:spc.shape[1]]
1046 xVel =AbbsisaRange[2][0:spc.shape[1]]
1075 xVel =AbbsisaRange[2][0:spc.shape[1]]
1047 Vv=numpy.empty(spc.shape[2])*0
1076 Vv=numpy.empty(spc.shape[2])*0
1048 SPCav = numpy.average(spc, axis=0)-numpy.average(noise) #spc[0]-noise[0]#
1077 SPCav = numpy.average(spc, axis=0)-numpy.average(noise) #spc[0]-noise[0]#
1049
1078
1050 SPCmoments = self.Moments(SPCav[:,Height], xVel )
1079 SPCmoments = self.Moments(SPCav[:,Height], xVel )
1051 CSPCmoments = []
1080 CSPCmoments = []
1052 cspcNoise = numpy.empty(3)
1081 cspcNoise = numpy.empty(3)
1053
1082
1054 '''Getting Eij and Nij'''
1083 '''Getting Eij and Nij'''
1055
1084
1056 E01=ChanDist[0][0]
1085 E01=ChanDist[0][0]
1057 N01=ChanDist[0][1]
1086 N01=ChanDist[0][1]
1058
1087
1059 E02=ChanDist[1][0]
1088 E02=ChanDist[1][0]
1060 N02=ChanDist[1][1]
1089 N02=ChanDist[1][1]
1061
1090
1062 E12=ChanDist[2][0]
1091 E12=ChanDist[2][0]
1063 N12=ChanDist[2][1]
1092 N12=ChanDist[2][1]
1064
1093
1065 z = spc.copy()
1094 z = spc.copy()
1066 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1095 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1067
1096
1068 for i in range(spc.shape[0]):
1097 for i in range(spc.shape[0]):
1069
1098
1070 '''****** Line of Data SPC ******'''
1099 '''****** Line of Data SPC ******'''
1071 zline=z[i,:,Height].copy() - noise[i] # Se resta ruido
1100 zline=z[i,:,Height].copy() - noise[i] # Se resta ruido
1072
1101
1073 '''****** SPC is normalized ******'''
1102 '''****** SPC is normalized ******'''
1074 SmoothSPC =self.moving_average(zline.copy(),N=1) # Se suaviza el ruido
1103 SmoothSPC =self.moving_average(zline.copy(),N=1) # Se suaviza el ruido
1075 FactNorm = SmoothSPC/numpy.nansum(SmoothSPC) # SPC Normalizado y suavizado
1104 FactNorm = SmoothSPC/numpy.nansum(SmoothSPC) # SPC Normalizado y suavizado
1076
1105
1077 xSamples = xFrec # Se toma el rango de frecuncias
1106 xSamples = xFrec # Se toma el rango de frecuncias
1078 ySamples[i] = FactNorm # Se toman los valores de SPC normalizado
1107 ySamples[i] = FactNorm # Se toman los valores de SPC normalizado
1079
1108
1080 for i in range(spc.shape[0]):
1109 for i in range(spc.shape[0]):
1081
1110
1082 '''****** Line of Data CSPC ******'''
1111 '''****** Line of Data CSPC ******'''
1083 cspcLine = ( cspc[i,:,Height].copy())# - noise[i] ) # no! Se resta el ruido
1112 cspcLine = ( cspc[i,:,Height].copy())# - noise[i] ) # no! Se resta el ruido
1084 SmoothCSPC =self.moving_average(cspcLine,N=1) # Se suaviza el ruido
1113 SmoothCSPC =self.moving_average(cspcLine,N=1) # Se suaviza el ruido
1085 cspcNorm = SmoothCSPC/numpy.nansum(SmoothCSPC) # CSPC normalizado y suavizado
1114 cspcNorm = SmoothCSPC/numpy.nansum(SmoothCSPC) # CSPC normalizado y suavizado
1086
1115
1087 '''****** CSPC is normalized with respect to Briggs and Vincent ******'''
1116 '''****** CSPC is normalized with respect to Briggs and Vincent ******'''
1088 chan_index0 = pairsList[i][0]
1117 chan_index0 = pairsList[i][0]
1089 chan_index1 = pairsList[i][1]
1118 chan_index1 = pairsList[i][1]
1090
1119
1091 CSPCFactor= numpy.abs(numpy.nansum(ySamples[chan_index0]))**2 * numpy.abs(numpy.nansum(ySamples[chan_index1]))**2
1120 CSPCFactor= numpy.abs(numpy.nansum(ySamples[chan_index0]))**2 * numpy.abs(numpy.nansum(ySamples[chan_index1]))**2
1092 CSPCNorm = cspcNorm / numpy.sqrt(CSPCFactor)
1121 CSPCNorm = cspcNorm / numpy.sqrt(CSPCFactor)
1093
1122
1094 CSPCSamples[i] = CSPCNorm
1123 CSPCSamples[i] = CSPCNorm
1095
1124
1096 coherence[i] = numpy.abs(CSPCSamples[i]) / numpy.sqrt(CSPCFactor)
1125 coherence[i] = numpy.abs(CSPCSamples[i]) / numpy.sqrt(CSPCFactor)
1097
1126
1098 #coherence[i]= self.moving_average(coherence[i],N=1)
1127 #coherence[i]= self.moving_average(coherence[i],N=1)
1099
1128
1100 phase[i] = self.moving_average( numpy.arctan2(CSPCSamples[i].imag, CSPCSamples[i].real),N=1)#*180/numpy.pi
1129 phase[i] = self.moving_average( numpy.arctan2(CSPCSamples[i].imag, CSPCSamples[i].real),N=1)#*180/numpy.pi
1101
1130
1102 CSPCmoments = numpy.vstack([self.Moments(numpy.abs(CSPCSamples[0]), xSamples),
1131 CSPCmoments = numpy.vstack([self.Moments(numpy.abs(CSPCSamples[0]), xSamples),
1103 self.Moments(numpy.abs(CSPCSamples[1]), xSamples),
1132 self.Moments(numpy.abs(CSPCSamples[1]), xSamples),
1104 self.Moments(numpy.abs(CSPCSamples[2]), xSamples)])
1133 self.Moments(numpy.abs(CSPCSamples[2]), xSamples)])
1105
1134
1106 #print '##### SUMA de SPC #####', len(ySamples)
1135 #print '##### SUMA de SPC #####', len(ySamples)
1107 #print numpy.sum(ySamples[0])
1136 #print numpy.sum(ySamples[0])
1108 #print '##### SUMA de CSPC #####', len(coherence)
1137 #print '##### SUMA de CSPC #####', len(coherence)
1109 #print numpy.sum(numpy.abs(CSPCNorm))
1138 #print numpy.sum(numpy.abs(CSPCNorm))
1110 #print numpy.sum(coherence[0])
1139 #print numpy.sum(coherence[0])
1111 # print 'len',len(xSamples)
1140 # print 'len',len(xSamples)
1112 # print 'CSPCmoments', numpy.shape(CSPCmoments)
1141 # print 'CSPCmoments', numpy.shape(CSPCmoments)
1113 # print CSPCmoments
1142 # print CSPCmoments
1114 # print '#######################'
1143 # print '#######################'
1115
1144
1116 popt=[1e-10,1e-10,1e-10]
1145 popt=[1e-10,0,1e-10]
1117 popt01, popt02, popt12 = [1e-10,1e-10,1e-10], [1e-10,1e-10,1e-10] ,[1e-10,1e-10,1e-10]
1146 popt01, popt02, popt12 = [1e-10,1e-10,1e-10], [1e-10,1e-10,1e-10] ,[1e-10,1e-10,1e-10]
1118 FitGauss01, FitGauss02, FitGauss12 = numpy.empty(len(xSamples))*0, numpy.empty(len(xSamples))*0, numpy.empty(len(xSamples))*0
1147 FitGauss01, FitGauss02, FitGauss12 = numpy.empty(len(xSamples))*0, numpy.empty(len(xSamples))*0, numpy.empty(len(xSamples))*0
1119
1148
1120 CSPCMask01 = numpy.abs(CSPCSamples[0])
1149 CSPCMask01 = numpy.abs(CSPCSamples[0])
1121 CSPCMask02 = numpy.abs(CSPCSamples[1])
1150 CSPCMask02 = numpy.abs(CSPCSamples[1])
1122 CSPCMask12 = numpy.abs(CSPCSamples[2])
1151 CSPCMask12 = numpy.abs(CSPCSamples[2])
1123
1152
1124 mask01 = ~numpy.isnan(CSPCMask01)
1153 mask01 = ~numpy.isnan(CSPCMask01)
1125 mask02 = ~numpy.isnan(CSPCMask02)
1154 mask02 = ~numpy.isnan(CSPCMask02)
1126 mask12 = ~numpy.isnan(CSPCMask12)
1155 mask12 = ~numpy.isnan(CSPCMask12)
1127
1156
1128 #mask = ~numpy.isnan(CSPCMask01)
1157 #mask = ~numpy.isnan(CSPCMask01)
1129 CSPCMask01 = CSPCMask01[mask01]
1158 CSPCMask01 = CSPCMask01[mask01]
1130 CSPCMask02 = CSPCMask02[mask02]
1159 CSPCMask02 = CSPCMask02[mask02]
1131 CSPCMask12 = CSPCMask12[mask12]
1160 CSPCMask12 = CSPCMask12[mask12]
1132 #CSPCMask01 = numpy.ma.masked_invalid(CSPCMask01)
1161 #CSPCMask01 = numpy.ma.masked_invalid(CSPCMask01)
1133
1162
1134
1163
1135
1164
1136 '''***Fit Gauss CSPC01***'''
1165 '''***Fit Gauss CSPC01***'''
1137 if dbSNR > SNRlimit:
1166 if dbSNR > SNRlimit and numpy.abs(SPCmoments[1])<3 :
1138 try:
1167 try:
1139 popt01,pcov = curve_fit(self.gaus,xSamples[mask01],numpy.abs(CSPCMask01),p0=CSPCmoments[0])
1168 popt01,pcov = curve_fit(self.gaus,xSamples[mask01],numpy.abs(CSPCMask01),p0=CSPCmoments[0])
1140 popt02,pcov = curve_fit(self.gaus,xSamples[mask02],numpy.abs(CSPCMask02),p0=CSPCmoments[1])
1169 popt02,pcov = curve_fit(self.gaus,xSamples[mask02],numpy.abs(CSPCMask02),p0=CSPCmoments[1])
1141 popt12,pcov = curve_fit(self.gaus,xSamples[mask12],numpy.abs(CSPCMask12),p0=CSPCmoments[2])
1170 popt12,pcov = curve_fit(self.gaus,xSamples[mask12],numpy.abs(CSPCMask12),p0=CSPCmoments[2])
1142 FitGauss01 = self.gaus(xSamples,*popt01)
1171 FitGauss01 = self.gaus(xSamples,*popt01)
1143 FitGauss02 = self.gaus(xSamples,*popt02)
1172 FitGauss02 = self.gaus(xSamples,*popt02)
1144 FitGauss12 = self.gaus(xSamples,*popt12)
1173 FitGauss12 = self.gaus(xSamples,*popt12)
1145 except:
1174 except:
1146 FitGauss01=numpy.ones(len(xSamples))*numpy.mean(numpy.abs(CSPCSamples[0]))
1175 FitGauss01=numpy.ones(len(xSamples))*numpy.mean(numpy.abs(CSPCSamples[0]))
1147 FitGauss02=numpy.ones(len(xSamples))*numpy.mean(numpy.abs(CSPCSamples[1]))
1176 FitGauss02=numpy.ones(len(xSamples))*numpy.mean(numpy.abs(CSPCSamples[1]))
1148 FitGauss12=numpy.ones(len(xSamples))*numpy.mean(numpy.abs(CSPCSamples[2]))
1177 FitGauss12=numpy.ones(len(xSamples))*numpy.mean(numpy.abs(CSPCSamples[2]))
1149
1178
1150
1179
1151 CSPCopt = numpy.vstack([popt01,popt02,popt12])
1180 CSPCopt = numpy.vstack([popt01,popt02,popt12])
1152
1181
1153 '''****** Getting fij width ******'''
1182 '''****** Getting fij width ******'''
1154
1183
1155 yMean = numpy.average(ySamples, axis=0) # ySamples[0]
1184 yMean = numpy.average(ySamples, axis=0) # ySamples[0]
1156
1185
1157 '''******* Getting fitting Gaussian *******'''
1186 '''******* Getting fitting Gaussian *******'''
1158 meanGauss = sum(xSamples*yMean) / len(xSamples) # Mu, velocidad radial (frecuencia)
1187 meanGauss = sum(xSamples*yMean) / len(xSamples) # Mu, velocidad radial (frecuencia)
1159 sigma2 = sum(yMean*(xSamples-meanGauss)**2) / len(xSamples) # Varianza, Ancho espectral (frecuencia)
1188 sigma2 = sum(yMean*(xSamples-meanGauss)**2) / len(xSamples) # Varianza, Ancho espectral (frecuencia)
1160
1189
1161 yMoments = self.Moments(yMean, xSamples)
1190 yMoments = self.Moments(yMean, xSamples)
1162
1191
1163 if dbSNR > SNRlimit: # and abs(meanGauss/sigma2) > 0.00001:
1192 if dbSNR > SNRlimit and numpy.abs(SPCmoments[1])<3: # and abs(meanGauss/sigma2) > 0.00001:
1164 try:
1193 try:
1165 popt,pcov = curve_fit(self.gaus,xSamples,yMean,p0=yMoments)
1194 popt,pcov = curve_fit(self.gaus,xSamples,yMean,p0=yMoments)
1166 FitGauss=self.gaus(xSamples,*popt)
1195 FitGauss=self.gaus(xSamples,*popt)
1167
1196
1168 except :#RuntimeError:
1197 except :#RuntimeError:
1169 FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
1198 FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
1170
1199
1171
1200
1172 else:
1201 else:
1173 FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
1202 FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
1174
1203
1175
1204
1176
1205
1177 '''****** Getting Fij ******'''
1206 '''****** Getting Fij ******'''
1178 Fijcspc = CSPCopt[:,2]/2*3
1207 Fijcspc = CSPCopt[:,2]/2*3
1179
1208
1180 #GauWidth = (popt[2]/2)*3
1209
1181 GaussCenter = popt[1] #xFrec[GCpos]
1210 GaussCenter = popt[1] #xFrec[GCpos]
1182 #Punto en Eje X de la Gaussiana donde se encuentra el centro
1211 #Punto en Eje X de la Gaussiana donde se encuentra el centro
1183 ClosestCenter = xSamples[numpy.abs(xSamples-GaussCenter).argmin()]
1212 ClosestCenter = xSamples[numpy.abs(xSamples-GaussCenter).argmin()]
1184 PointGauCenter = numpy.where(xSamples==ClosestCenter)[0][0]
1213 PointGauCenter = numpy.where(xSamples==ClosestCenter)[0][0]
1185
1214
1186 #Punto e^-1 hubicado en la Gaussiana
1215 #Punto e^-1 hubicado en la Gaussiana
1187 PeMinus1 = numpy.max(FitGauss)* numpy.exp(-1)
1216 PeMinus1 = numpy.max(FitGauss)* numpy.exp(-1)
1188 FijClosest = FitGauss[numpy.abs(FitGauss-PeMinus1).argmin()] # El punto mas cercano a "Peminus1" dentro de "FitGauss"
1217 FijClosest = FitGauss[numpy.abs(FitGauss-PeMinus1).argmin()] # El punto mas cercano a "Peminus1" dentro de "FitGauss"
1189 PointFij = numpy.where(FitGauss==FijClosest)[0][0]
1218 PointFij = numpy.where(FitGauss==FijClosest)[0][0]
1190
1219
1191 if xSamples[PointFij] > xSamples[PointGauCenter]:
1220 if xSamples[PointFij] > xSamples[PointGauCenter]:
1192 Fij = xSamples[PointFij] - xSamples[PointGauCenter]
1221 Fij = xSamples[PointFij] - xSamples[PointGauCenter]
1193
1222
1194 else:
1223 else:
1195 Fij = xSamples[PointGauCenter] - xSamples[PointFij]
1224 Fij = xSamples[PointGauCenter] - xSamples[PointFij]
1196
1225
1197 # print 'CSPCopt'
1226 # print 'CSPCopt'
1198 # print CSPCopt
1227 # print CSPCopt
1199 # print 'popt'
1228 # print 'popt'
1200 # print popt
1229 # print popt
1201 # print '#######################################'
1230 # print '#######################################'
1202 #print 'dataOut.data_param', numpy.shape(data_param)
1231 #print 'dataOut.data_param', numpy.shape(data_param)
1203 #print 'dataOut.data_param0', data_param[0,0,Height]
1232 #print 'dataOut.data_param0', data_param[0,0,Height]
1204 #print 'dataOut.data_param1', data_param[0,1,Height]
1233 #print 'dataOut.data_param1', data_param[0,1,Height]
1205 #print 'dataOut.data_param2', data_param[0,2,Height]
1234 #print 'dataOut.data_param2', data_param[0,2,Height]
1206
1235
1207
1236
1208 # print 'yMoments', yMoments
1237 # print 'yMoments', yMoments
1209 # print 'Moments', SPCmoments
1238 # print 'Moments', SPCmoments
1210 # print 'Fij2 Moment', Fij
1239 # print 'Fij2 Moment', Fij
1211 # #print 'Fij', Fij, 'popt[2]/2',popt[2]/2
1240 # #print 'Fij', Fij, 'popt[2]/2',popt[2]/2
1212 # print 'Fijcspc',Fijcspc
1241 # print 'Fijcspc',Fijcspc
1213 # print '#######################################'
1242 # print '#######################################'
1214
1243
1215
1244
1216 '''****** Taking frequency ranges from SPCs ******'''
1245 '''****** Taking frequency ranges from SPCs ******'''
1217
1246
1218
1247
1219 #GaussCenter = popt[1] #Primer momento 01
1248 #GaussCenter = popt[1] #Primer momento 01
1220 GauWidth = popt[2] *3/2 #Ancho de banda de Gau01
1249 GauWidth = popt[2] *3/2 #Ancho de banda de Gau01
1221 Range = numpy.empty(2)
1250 Range = numpy.empty(2)
1222 Range[0] = GaussCenter - GauWidth
1251 Range[0] = GaussCenter - GauWidth
1223 Range[1] = GaussCenter + GauWidth
1252 Range[1] = GaussCenter + GauWidth
1224 #Punto en Eje X de la Gaussiana donde se encuentra ancho de banda (min:max)
1253 #Punto en Eje X de la Gaussiana donde se encuentra ancho de banda (min:max)
1225 ClosRangeMin = xSamples[numpy.abs(xSamples-Range[0]).argmin()]
1254 ClosRangeMin = xSamples[numpy.abs(xSamples-Range[0]).argmin()]
1226 ClosRangeMax = xSamples[numpy.abs(xSamples-Range[1]).argmin()]
1255 ClosRangeMax = xSamples[numpy.abs(xSamples-Range[1]).argmin()]
1227
1256
1228 PointRangeMin = numpy.where(xSamples==ClosRangeMin)[0][0]
1257 PointRangeMin = numpy.where(xSamples==ClosRangeMin)[0][0]
1229 PointRangeMax = numpy.where(xSamples==ClosRangeMax)[0][0]
1258 PointRangeMax = numpy.where(xSamples==ClosRangeMax)[0][0]
1230
1259
1231 Range=numpy.array([ PointRangeMin, PointRangeMax ])
1260 Range=numpy.array([ PointRangeMin, PointRangeMax ])
1232
1261
1233 FrecRange = xFrec[ Range[0] : Range[1] ]
1262 FrecRange = xFrec[ Range[0] : Range[1] ]
1234 VelRange = xVel[ Range[0] : Range[1] ]
1263 VelRange = xVel[ Range[0] : Range[1] ]
1235
1264
1236
1265
1237 #print 'RANGE: ', Range
1266 #print 'RANGE: ', Range
1238 #print 'FrecRange', numpy.shape(FrecRange)#,FrecRange
1267 #print 'FrecRange', numpy.shape(FrecRange)#,FrecRange
1239 #print 'len: ', len(FrecRange)
1268 #print 'len: ', len(FrecRange)
1240
1269
1241 '''****** Getting SCPC Slope ******'''
1270 '''****** Getting SCPC Slope ******'''
1242
1271
1243 for i in range(spc.shape[0]):
1272 for i in range(spc.shape[0]):
1244
1273
1245 if len(FrecRange)>5 and len(FrecRange)<spc.shape[1]*0.6:
1274 if len(FrecRange)>5 and len(FrecRange)<spc.shape[1]*0.3:
1246 PhaseRange=self.moving_average(phase[i,Range[0]:Range[1]],N=3)
1275 PhaseRange=self.moving_average(phase[i,Range[0]:Range[1]],N=3)
1247
1276
1248 #print 'Ancho espectral Frecuencias', FrecRange[-1]-FrecRange[0], 'Hz'
1277 #print 'Ancho espectral Frecuencias', FrecRange[-1]-FrecRange[0], 'Hz'
1249 #print 'Ancho espectral Velocidades', VelRange[-1]-VelRange[0], 'm/s'
1278 #print 'Ancho espectral Velocidades', VelRange[-1]-VelRange[0], 'm/s'
1250 #print 'FrecRange', len(FrecRange) , FrecRange
1279 #print 'FrecRange', len(FrecRange) , FrecRange
1251 #print 'VelRange', len(VelRange) , VelRange
1280 #print 'VelRange', len(VelRange) , VelRange
1252 #print 'PhaseRange', numpy.shape(PhaseRange), PhaseRange
1281 #print 'PhaseRange', numpy.shape(PhaseRange), PhaseRange
1253 #print ' '
1282 #print ' '
1254
1283
1255 '''***********************VelRange******************'''
1284 '''***********************VelRange******************'''
1256
1285
1257 mask = ~numpy.isnan(FrecRange) & ~numpy.isnan(PhaseRange)
1286 mask = ~numpy.isnan(FrecRange) & ~numpy.isnan(PhaseRange)
1258
1287
1259 if len(FrecRange) == len(PhaseRange):
1288 if len(FrecRange) == len(PhaseRange):
1260 try:
1289 try:
1261 slope, intercept, r_value, p_value, std_err = stats.linregress(FrecRange[mask], PhaseRange[mask])
1290 slope, intercept, r_value, p_value, std_err = stats.linregress(FrecRange[mask], PhaseRange[mask])
1262 PhaseSlope[i]=slope
1291 PhaseSlope[i]=slope
1263 PhaseInter[i]=intercept
1292 PhaseInter[i]=intercept
1264 except:
1293 except:
1265 PhaseSlope[i]=0
1294 PhaseSlope[i]=0
1266 PhaseInter[i]=0
1295 PhaseInter[i]=0
1267 else:
1296 else:
1268 PhaseSlope[i]=0
1297 PhaseSlope[i]=0
1269 PhaseInter[i]=0
1298 PhaseInter[i]=0
1270 else:
1299 else:
1271 PhaseSlope[i]=0
1300 PhaseSlope[i]=0
1272 PhaseInter[i]=0
1301 PhaseInter[i]=0
1273
1302
1274
1303
1275 '''Getting constant C'''
1304 '''Getting constant C'''
1276 cC=(Fij*numpy.pi)**2
1305 cC=(Fij*numpy.pi)**2
1277
1306
1278 '''****** Getting constants F and G ******'''
1307 '''****** Getting constants F and G ******'''
1279 MijEijNij=numpy.array([[E02,N02], [E12,N12]])
1308 MijEijNij=numpy.array([[E02,N02], [E12,N12]])
1280 MijResult0=(-PhaseSlope[1]*cC) / (2*numpy.pi)
1309 MijResult0=(-PhaseSlope[1]*cC) / (2*numpy.pi)
1281 MijResult1=(-PhaseSlope[2]*cC) / (2*numpy.pi)
1310 MijResult1=(-PhaseSlope[2]*cC) / (2*numpy.pi)
1282 MijResults=numpy.array([MijResult0,MijResult1])
1311 MijResults=numpy.array([MijResult0,MijResult1])
1283 (cF,cG) = numpy.linalg.solve(MijEijNij, MijResults)
1312 (cF,cG) = numpy.linalg.solve(MijEijNij, MijResults)
1284
1313
1285 '''****** Getting constants A, B and H ******'''
1314 '''****** Getting constants A, B and H ******'''
1286 W01=numpy.nanmax( FitGauss01 ) #numpy.abs(CSPCSamples[0]))
1315 W01=numpy.nanmax( FitGauss01 ) #numpy.abs(CSPCSamples[0]))
1287 W02=numpy.nanmax( FitGauss02 ) #numpy.abs(CSPCSamples[1]))
1316 W02=numpy.nanmax( FitGauss02 ) #numpy.abs(CSPCSamples[1]))
1288 W12=numpy.nanmax( FitGauss12 ) #numpy.abs(CSPCSamples[2]))
1317 W12=numpy.nanmax( FitGauss12 ) #numpy.abs(CSPCSamples[2]))
1289
1318
1290 WijResult0=((cF*E01+cG*N01)**2)/cC - numpy.log(W01 / numpy.sqrt(numpy.pi/cC))
1319 WijResult0=((cF*E01+cG*N01)**2)/cC - numpy.log(W01 / numpy.sqrt(numpy.pi/cC))
1291 WijResult1=((cF*E02+cG*N02)**2)/cC - numpy.log(W02 / numpy.sqrt(numpy.pi/cC))
1320 WijResult1=((cF*E02+cG*N02)**2)/cC - numpy.log(W02 / numpy.sqrt(numpy.pi/cC))
1292 WijResult2=((cF*E12+cG*N12)**2)/cC - numpy.log(W12 / numpy.sqrt(numpy.pi/cC))
1321 WijResult2=((cF*E12+cG*N12)**2)/cC - numpy.log(W12 / numpy.sqrt(numpy.pi/cC))
1293
1322
1294 WijResults=numpy.array([WijResult0, WijResult1, WijResult2])
1323 WijResults=numpy.array([WijResult0, WijResult1, WijResult2])
1295
1324
1296 WijEijNij=numpy.array([ [E01**2, N01**2, 2*E01*N01] , [E02**2, N02**2, 2*E02*N02] , [E12**2, N12**2, 2*E12*N12] ])
1325 WijEijNij=numpy.array([ [E01**2, N01**2, 2*E01*N01] , [E02**2, N02**2, 2*E02*N02] , [E12**2, N12**2, 2*E12*N12] ])
1297 (cA,cB,cH) = numpy.linalg.solve(WijEijNij, WijResults)
1326 (cA,cB,cH) = numpy.linalg.solve(WijEijNij, WijResults)
1298
1327
1299 VxVy=numpy.array([[cA,cH],[cH,cB]])
1328 VxVy=numpy.array([[cA,cH],[cH,cB]])
1300 VxVyResults=numpy.array([-cF,-cG])
1329 VxVyResults=numpy.array([-cF,-cG])
1301 (Vx,Vy) = numpy.linalg.solve(VxVy, VxVyResults)
1330 (Vx,Vy) = numpy.linalg.solve(VxVy, VxVyResults)
1302
1331
1303 #print 'MijResults, cC, PhaseSlope', MijResults, cC, PhaseSlope
1332 #print 'MijResults, cC, PhaseSlope', MijResults, cC, PhaseSlope
1304 #print 'W01,02,12', W01, W02, W12
1333 #print 'W01,02,12', W01, W02, W12
1305 #print 'WijResult0,1,2',WijResult0, WijResult1, WijResult2, 'Results', WijResults
1334 #print 'WijResult0,1,2',WijResult0, WijResult1, WijResult2, 'Results', WijResults
1306 #print 'cA,cB,cH, cF, cG', cA, cB, cH, cF, cG
1335 #print 'cA,cB,cH, cF, cG', cA, cB, cH, cF, cG
1307 #print 'VxVy', VxVyResults
1336 #print 'VxVy', VxVyResults
1308 #print '###########################****************************************'
1337 #print '###########################****************************************'
1309 Vzon = Vy
1338 Vzon = Vy
1310 Vmer = Vx
1339 Vmer = Vx
1311 Vmag=numpy.sqrt(Vzon**2+Vmer**2)
1340 Vmag=numpy.sqrt(Vzon**2+Vmer**2)
1312 Vang=numpy.arctan2(Vmer,Vzon)
1341 Vang=numpy.arctan2(Vmer,Vzon)
1313 Vver=SPCmoments[1]
1342 if numpy.abs( popt[1] ) < 3.5 and len(FrecRange)>4:
1343 Vver=popt[1]
1344 else:
1345 Vver=numpy.NaN
1314 FitGaussCSPC = numpy.array([FitGauss01,FitGauss02,FitGauss12])
1346 FitGaussCSPC = numpy.array([FitGauss01,FitGauss02,FitGauss12])
1315
1347
1316
1348
1317 # ''' Ploteo por altura '''
1349 # ''' Ploteo por altura '''
1318 # if Height == 28:
1350 # if Height == 28:
1319 # for i in range(3):
1351 # for i in range(3):
1320 # #print 'FASE', numpy.shape(phase), y[25]
1352 # #print 'FASE', numpy.shape(phase), y[25]
1321 # #print numpy.shape(coherence)
1353 # #print numpy.shape(coherence)
1322 # fig = plt.figure(10+self.indice)
1354 # fig = plt.figure(10+self.indice)
1323 # #plt.plot( x[0:256],coherence[:,25] )
1355 # #plt.plot( x[0:256],coherence[:,25] )
1324 # #cohAv = numpy.average(coherence[i],1)
1356 # #cohAv = numpy.average(coherence[i],1)
1325 # Pendiente = FrecRange * PhaseSlope[i]
1357 # Pendiente = FrecRange * PhaseSlope[i]
1326 # plt.plot( FrecRange, Pendiente)
1358 # plt.plot( FrecRange, Pendiente)
1327 # plt.plot( xFrec,phase[i])
1359 # plt.plot( xFrec,phase[i])
1328 #
1360 #
1329 # CSPCmean = numpy.mean(numpy.abs(CSPCSamples),0)
1361 # CSPCmean = numpy.mean(numpy.abs(CSPCSamples),0)
1330 # #plt.plot(xFrec, FitGauss01)
1362 # #plt.plot(xFrec, FitGauss01)
1331 # #plt.plot(xFrec, CSPCmean)
1363 # #plt.plot(xFrec, CSPCmean)
1332 # #plt.plot(xFrec, numpy.abs(CSPCSamples[0]))
1364 # #plt.plot(xFrec, numpy.abs(CSPCSamples[0]))
1333 # #plt.plot(xFrec, FitGauss)
1365 # #plt.plot(xFrec, FitGauss)
1334 # #plt.plot(xFrec, yMean)
1366 # #plt.plot(xFrec, yMean)
1335 # #plt.plot(xFrec, numpy.abs(coherence[0]))
1367 # #plt.plot(xFrec, numpy.abs(coherence[0]))
1336 #
1368 #
1337 # #plt.axis([-12, 12, 15, 50])
1369 # #plt.axis([-12, 12, 15, 50])
1338 # #plt.title("%s" %( '%s %s, Channel %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S") , i)))
1370 # #plt.title("%s" %( '%s %s, Channel %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S") , i)))
1339 # plt.ylabel('Desfase [rad]')
1371 # plt.ylabel('Desfase [rad]')
1340 # #plt.ylabel('CSPC normalizado')
1372 # #plt.ylabel('CSPC normalizado')
1341 # plt.xlabel('Frec range [Hz]')
1373 # plt.xlabel('Frec range [Hz]')
1342
1374
1343 #fig.savefig('/home/erick/Documents/Pics/to{}.png'.format(self.indice))
1375 #fig.savefig('/home/erick/Documents/Pics/to{}.png'.format(self.indice))
1344
1376
1345 # plt.show()
1377 # plt.show()
1346 # self.indice=self.indice+1
1378 # self.indice=self.indice+1
1347
1379
1348
1380
1349
1381
1350
1382
1351
1383
1352 # print 'vzon y vmer', Vzon, Vmer
1384 # print 'vzon y vmer', Vzon, Vmer
1353 return Vzon, Vmer, Vver, GaussCenter, PhaseSlope, FitGaussCSPC
1385 return Vzon, Vmer, Vver, GaussCenter, PhaseSlope, FitGaussCSPC
1354
1386
1355 class SpectralMoments(Operation):
1387 class SpectralMoments(Operation):
1356
1388
1357 '''
1389 '''
1358 Function SpectralMoments()
1390 Function SpectralMoments()
1359
1391
1360 Calculates moments (power, mean, standard deviation) and SNR of the signal
1392 Calculates moments (power, mean, standard deviation) and SNR of the signal
1361
1393
1362 Type of dataIn: Spectra
1394 Type of dataIn: Spectra
1363
1395
1364 Configuration Parameters:
1396 Configuration Parameters:
1365
1397
1366 dirCosx : Cosine director in X axis
1398 dirCosx : Cosine director in X axis
1367 dirCosy : Cosine director in Y axis
1399 dirCosy : Cosine director in Y axis
1368
1400
1369 elevation :
1401 elevation :
1370 azimuth :
1402 azimuth :
1371
1403
1372 Input:
1404 Input:
1373 channelList : simple channel list to select e.g. [2,3,7]
1405 channelList : simple channel list to select e.g. [2,3,7]
1374 self.dataOut.data_pre : Spectral data
1406 self.dataOut.data_pre : Spectral data
1375 self.dataOut.abscissaList : List of frequencies
1407 self.dataOut.abscissaList : List of frequencies
1376 self.dataOut.noise : Noise level per channel
1408 self.dataOut.noise : Noise level per channel
1377
1409
1378 Affected:
1410 Affected:
1379 self.dataOut.moments : Parameters per channel
1411 self.dataOut.moments : Parameters per channel
1380 self.dataOut.data_SNR : SNR per channel
1412 self.dataOut.data_SNR : SNR per channel
1381
1413
1382 '''
1414 '''
1383
1415
1384 def run(self, dataOut):
1416 def run(self, dataOut):
1385
1417
1386 #dataOut.data_pre = dataOut.data_pre[0]
1418 #dataOut.data_pre = dataOut.data_pre[0]
1387 data = dataOut.data_pre[0]
1419 data = dataOut.data_pre[0]
1388 absc = dataOut.abscissaList[:-1]
1420 absc = dataOut.abscissaList[:-1]
1389 noise = dataOut.noise
1421 noise = dataOut.noise
1390 nChannel = data.shape[0]
1422 nChannel = data.shape[0]
1391 data_param = numpy.zeros((nChannel, 4, data.shape[2]))
1423 data_param = numpy.zeros((nChannel, 4, data.shape[2]))
1392
1424
1393 for ind in range(nChannel):
1425 for ind in range(nChannel):
1394 data_param[ind,:,:] = self.__calculateMoments( data[ind,:,:] , absc , noise[ind] )
1426 data_param[ind,:,:] = self.__calculateMoments( data[ind,:,:] , absc , noise[ind] )
1395
1427
1396 dataOut.moments = data_param[:,1:,:]
1428 dataOut.moments = data_param[:,1:,:]
1397 dataOut.data_SNR = data_param[:,0]
1429 dataOut.data_SNR = data_param[:,0]
1398 return
1430 return
1399
1431
1400 def __calculateMoments(self, oldspec, oldfreq, n0,
1432 def __calculateMoments(self, oldspec, oldfreq, n0,
1401 nicoh = None, graph = None, smooth = None, type1 = None, fwindow = None, snrth = None, dc = None, aliasing = None, oldfd = None, wwauto = None):
1433 nicoh = None, graph = None, smooth = None, type1 = None, fwindow = None, snrth = None, dc = None, aliasing = None, oldfd = None, wwauto = None):
1402
1434
1403 if (nicoh == None): nicoh = 1
1435 if (nicoh == None): nicoh = 1
1404 if (graph == None): graph = 0
1436 if (graph == None): graph = 0
1405 if (smooth == None): smooth = 0
1437 if (smooth == None): smooth = 0
1406 elif (self.smooth < 3): smooth = 0
1438 elif (self.smooth < 3): smooth = 0
1407
1439
1408 if (type1 == None): type1 = 0
1440 if (type1 == None): type1 = 0
1409 if (fwindow == None): fwindow = numpy.zeros(oldfreq.size) + 1
1441 if (fwindow == None): fwindow = numpy.zeros(oldfreq.size) + 1
1410 if (snrth == None): snrth = -3
1442 if (snrth == None): snrth = -3
1411 if (dc == None): dc = 0
1443 if (dc == None): dc = 0
1412 if (aliasing == None): aliasing = 0
1444 if (aliasing == None): aliasing = 0
1413 if (oldfd == None): oldfd = 0
1445 if (oldfd == None): oldfd = 0
1414 if (wwauto == None): wwauto = 0
1446 if (wwauto == None): wwauto = 0
1415
1447
1416 if (n0 < 1.e-20): n0 = 1.e-20
1448 if (n0 < 1.e-20): n0 = 1.e-20
1417
1449
1418 freq = oldfreq
1450 freq = oldfreq
1419 vec_power = numpy.zeros(oldspec.shape[1])
1451 vec_power = numpy.zeros(oldspec.shape[1])
1420 vec_fd = numpy.zeros(oldspec.shape[1])
1452 vec_fd = numpy.zeros(oldspec.shape[1])
1421 vec_w = numpy.zeros(oldspec.shape[1])
1453 vec_w = numpy.zeros(oldspec.shape[1])
1422 vec_snr = numpy.zeros(oldspec.shape[1])
1454 vec_snr = numpy.zeros(oldspec.shape[1])
1423
1455
1424 oldspec = numpy.ma.masked_invalid(oldspec)
1456 oldspec = numpy.ma.masked_invalid(oldspec)
1425
1457
1426 for ind in range(oldspec.shape[1]):
1458 for ind in range(oldspec.shape[1]):
1427
1459
1428 spec = oldspec[:,ind]
1460 spec = oldspec[:,ind]
1429 aux = spec*fwindow
1461 aux = spec*fwindow
1430 max_spec = aux.max()
1462 max_spec = aux.max()
1431 m = list(aux).index(max_spec)
1463 m = list(aux).index(max_spec)
1432
1464
1433 #Smooth
1465 #Smooth
1434 if (smooth == 0): spec2 = spec
1466 if (smooth == 0): spec2 = spec
1435 else: spec2 = scipy.ndimage.filters.uniform_filter1d(spec,size=smooth)
1467 else: spec2 = scipy.ndimage.filters.uniform_filter1d(spec,size=smooth)
1436
1468
1437 # Calculo de Momentos
1469 # Calculo de Momentos
1438 bb = spec2[range(m,spec2.size)]
1470 bb = spec2[range(m,spec2.size)]
1439 bb = (bb<n0).nonzero()
1471 bb = (bb<n0).nonzero()
1440 bb = bb[0]
1472 bb = bb[0]
1441
1473
1442 ss = spec2[range(0,m + 1)]
1474 ss = spec2[range(0,m + 1)]
1443 ss = (ss<n0).nonzero()
1475 ss = (ss<n0).nonzero()
1444 ss = ss[0]
1476 ss = ss[0]
1445
1477
1446 if (bb.size == 0):
1478 if (bb.size == 0):
1447 bb0 = spec.size - 1 - m
1479 bb0 = spec.size - 1 - m
1448 else:
1480 else:
1449 bb0 = bb[0] - 1
1481 bb0 = bb[0] - 1
1450 if (bb0 < 0):
1482 if (bb0 < 0):
1451 bb0 = 0
1483 bb0 = 0
1452
1484
1453 if (ss.size == 0): ss1 = 1
1485 if (ss.size == 0): ss1 = 1
1454 else: ss1 = max(ss) + 1
1486 else: ss1 = max(ss) + 1
1455
1487
1456 if (ss1 > m): ss1 = m
1488 if (ss1 > m): ss1 = m
1457
1489
1458 valid = numpy.asarray(range(int(m + bb0 - ss1 + 1))) + ss1
1490 valid = numpy.asarray(range(int(m + bb0 - ss1 + 1))) + ss1
1459 power = ( (spec2[valid] - n0) * fwindow[valid] ).sum()
1491 power = ( (spec2[valid] - n0) * fwindow[valid] ).sum()
1460 fd = ( (spec2[valid]- n0) * freq[valid] * fwindow[valid] ).sum() / power
1492 fd = ( (spec2[valid]- n0) * freq[valid] * fwindow[valid] ).sum() / power
1493
1461 w = math.sqrt(((spec2[valid] - n0)*fwindow[valid]*(freq[valid]- fd)**2).sum()/power)
1494 w = math.sqrt(((spec2[valid] - n0)*fwindow[valid]*(freq[valid]- fd)**2).sum()/power)
1462 snr = (spec2.mean()-n0)/n0
1495 snr = (spec2.mean()-n0)/n0
1463
1496
1464 if (snr < 1.e-20) :
1497 if (snr < 1.e-20) :
1465 snr = 1.e-20
1498 snr = 1.e-20
1466
1499
1467 vec_power[ind] = power
1500 vec_power[ind] = power
1468 vec_fd[ind] = fd
1501 vec_fd[ind] = fd
1469 vec_w[ind] = w
1502 vec_w[ind] = w
1470 vec_snr[ind] = snr
1503 vec_snr[ind] = snr
1471
1504
1472 moments = numpy.vstack((vec_snr, vec_power, vec_fd, vec_w))
1505 moments = numpy.vstack((vec_snr, vec_power, vec_fd, vec_w))
1473 return moments
1506 return moments
1474
1507
1475 #------------------ Get SA Parameters --------------------------
1508 #------------------ Get SA Parameters --------------------------
1476
1509
1477 def GetSAParameters(self):
1510 def GetSAParameters(self):
1478 #SA en frecuencia
1511 #SA en frecuencia
1479 pairslist = self.dataOut.groupList
1512 pairslist = self.dataOut.groupList
1480 num_pairs = len(pairslist)
1513 num_pairs = len(pairslist)
1481
1514
1482 vel = self.dataOut.abscissaList
1515 vel = self.dataOut.abscissaList
1483 spectra = self.dataOut.data_pre
1516 spectra = self.dataOut.data_pre
1484 cspectra = self.dataIn.data_cspc
1517 cspectra = self.dataIn.data_cspc
1485 delta_v = vel[1] - vel[0]
1518 delta_v = vel[1] - vel[0]
1486
1519
1487 #Calculating the power spectrum
1520 #Calculating the power spectrum
1488 spc_pow = numpy.sum(spectra, 3)*delta_v
1521 spc_pow = numpy.sum(spectra, 3)*delta_v
1489 #Normalizing Spectra
1522 #Normalizing Spectra
1490 norm_spectra = spectra/spc_pow
1523 norm_spectra = spectra/spc_pow
1491 #Calculating the norm_spectra at peak
1524 #Calculating the norm_spectra at peak
1492 max_spectra = numpy.max(norm_spectra, 3)
1525 max_spectra = numpy.max(norm_spectra, 3)
1493
1526
1494 #Normalizing Cross Spectra
1527 #Normalizing Cross Spectra
1495 norm_cspectra = numpy.zeros(cspectra.shape)
1528 norm_cspectra = numpy.zeros(cspectra.shape)
1496
1529
1497 for i in range(num_chan):
1530 for i in range(num_chan):
1498 norm_cspectra[i,:,:] = cspectra[i,:,:]/numpy.sqrt(spc_pow[pairslist[i][0],:]*spc_pow[pairslist[i][1],:])
1531 norm_cspectra[i,:,:] = cspectra[i,:,:]/numpy.sqrt(spc_pow[pairslist[i][0],:]*spc_pow[pairslist[i][1],:])
1499
1532
1500 max_cspectra = numpy.max(norm_cspectra,2)
1533 max_cspectra = numpy.max(norm_cspectra,2)
1501 max_cspectra_index = numpy.argmax(norm_cspectra, 2)
1534 max_cspectra_index = numpy.argmax(norm_cspectra, 2)
1502
1535
1503 for i in range(num_pairs):
1536 for i in range(num_pairs):
1504 cspc_par[i,:,:] = __calculateMoments(norm_cspectra)
1537 cspc_par[i,:,:] = __calculateMoments(norm_cspectra)
1505 #------------------- Get Lags ----------------------------------
1538 #------------------- Get Lags ----------------------------------
1506
1539
1507 class SALags(Operation):
1540 class SALags(Operation):
1508 '''
1541 '''
1509 Function GetMoments()
1542 Function GetMoments()
1510
1543
1511 Input:
1544 Input:
1512 self.dataOut.data_pre
1545 self.dataOut.data_pre
1513 self.dataOut.abscissaList
1546 self.dataOut.abscissaList
1514 self.dataOut.noise
1547 self.dataOut.noise
1515 self.dataOut.normFactor
1548 self.dataOut.normFactor
1516 self.dataOut.data_SNR
1549 self.dataOut.data_SNR
1517 self.dataOut.groupList
1550 self.dataOut.groupList
1518 self.dataOut.nChannels
1551 self.dataOut.nChannels
1519
1552
1520 Affected:
1553 Affected:
1521 self.dataOut.data_param
1554 self.dataOut.data_param
1522
1555
1523 '''
1556 '''
1524 def run(self, dataOut):
1557 def run(self, dataOut):
1525 data_acf = dataOut.data_pre[0]
1558 data_acf = dataOut.data_pre[0]
1526 data_ccf = dataOut.data_pre[1]
1559 data_ccf = dataOut.data_pre[1]
1527 normFactor_acf = dataOut.normFactor[0]
1560 normFactor_acf = dataOut.normFactor[0]
1528 normFactor_ccf = dataOut.normFactor[1]
1561 normFactor_ccf = dataOut.normFactor[1]
1529 pairs_acf = dataOut.groupList[0]
1562 pairs_acf = dataOut.groupList[0]
1530 pairs_ccf = dataOut.groupList[1]
1563 pairs_ccf = dataOut.groupList[1]
1531
1564
1532 nHeights = dataOut.nHeights
1565 nHeights = dataOut.nHeights
1533 absc = dataOut.abscissaList
1566 absc = dataOut.abscissaList
1534 noise = dataOut.noise
1567 noise = dataOut.noise
1535 SNR = dataOut.data_SNR
1568 SNR = dataOut.data_SNR
1536 nChannels = dataOut.nChannels
1569 nChannels = dataOut.nChannels
1537 # pairsList = dataOut.groupList
1570 # pairsList = dataOut.groupList
1538 # pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairsList, nChannels)
1571 # pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairsList, nChannels)
1539
1572
1540 for l in range(len(pairs_acf)):
1573 for l in range(len(pairs_acf)):
1541 data_acf[l,:,:] = data_acf[l,:,:]/normFactor_acf[l,:]
1574 data_acf[l,:,:] = data_acf[l,:,:]/normFactor_acf[l,:]
1542
1575
1543 for l in range(len(pairs_ccf)):
1576 for l in range(len(pairs_ccf)):
1544 data_ccf[l,:,:] = data_ccf[l,:,:]/normFactor_ccf[l,:]
1577 data_ccf[l,:,:] = data_ccf[l,:,:]/normFactor_ccf[l,:]
1545
1578
1546 dataOut.data_param = numpy.zeros((len(pairs_ccf)*2 + 1, nHeights))
1579 dataOut.data_param = numpy.zeros((len(pairs_ccf)*2 + 1, nHeights))
1547 dataOut.data_param[:-1,:] = self.__calculateTaus(data_acf, data_ccf, absc)
1580 dataOut.data_param[:-1,:] = self.__calculateTaus(data_acf, data_ccf, absc)
1548 dataOut.data_param[-1,:] = self.__calculateLag1Phase(data_acf, absc)
1581 dataOut.data_param[-1,:] = self.__calculateLag1Phase(data_acf, absc)
1549 return
1582 return
1550
1583
1551 # def __getPairsAutoCorr(self, pairsList, nChannels):
1584 # def __getPairsAutoCorr(self, pairsList, nChannels):
1552 #
1585 #
1553 # pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan
1586 # pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan
1554 #
1587 #
1555 # for l in range(len(pairsList)):
1588 # for l in range(len(pairsList)):
1556 # firstChannel = pairsList[l][0]
1589 # firstChannel = pairsList[l][0]
1557 # secondChannel = pairsList[l][1]
1590 # secondChannel = pairsList[l][1]
1558 #
1591 #
1559 # #Obteniendo pares de Autocorrelacion
1592 # #Obteniendo pares de Autocorrelacion
1560 # if firstChannel == secondChannel:
1593 # if firstChannel == secondChannel:
1561 # pairsAutoCorr[firstChannel] = int(l)
1594 # pairsAutoCorr[firstChannel] = int(l)
1562 #
1595 #
1563 # pairsAutoCorr = pairsAutoCorr.astype(int)
1596 # pairsAutoCorr = pairsAutoCorr.astype(int)
1564 #
1597 #
1565 # pairsCrossCorr = range(len(pairsList))
1598 # pairsCrossCorr = range(len(pairsList))
1566 # pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr)
1599 # pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr)
1567 #
1600 #
1568 # return pairsAutoCorr, pairsCrossCorr
1601 # return pairsAutoCorr, pairsCrossCorr
1569
1602
1570 def __calculateTaus(self, data_acf, data_ccf, lagRange):
1603 def __calculateTaus(self, data_acf, data_ccf, lagRange):
1571
1604
1572 lag0 = data_acf.shape[1]/2
1605 lag0 = data_acf.shape[1]/2
1573 #Funcion de Autocorrelacion
1606 #Funcion de Autocorrelacion
1574 mean_acf = stats.nanmean(data_acf, axis = 0)
1607 mean_acf = stats.nanmean(data_acf, axis = 0)
1575
1608
1576 #Obtencion Indice de TauCross
1609 #Obtencion Indice de TauCross
1577 ind_ccf = data_ccf.argmax(axis = 1)
1610 ind_ccf = data_ccf.argmax(axis = 1)
1578 #Obtencion Indice de TauAuto
1611 #Obtencion Indice de TauAuto
1579 ind_acf = numpy.zeros(ind_ccf.shape,dtype = 'int')
1612 ind_acf = numpy.zeros(ind_ccf.shape,dtype = 'int')
1580 ccf_lag0 = data_ccf[:,lag0,:]
1613 ccf_lag0 = data_ccf[:,lag0,:]
1581
1614
1582 for i in range(ccf_lag0.shape[0]):
1615 for i in range(ccf_lag0.shape[0]):
1583 ind_acf[i,:] = numpy.abs(mean_acf - ccf_lag0[i,:]).argmin(axis = 0)
1616 ind_acf[i,:] = numpy.abs(mean_acf - ccf_lag0[i,:]).argmin(axis = 0)
1584
1617
1585 #Obtencion de TauCross y TauAuto
1618 #Obtencion de TauCross y TauAuto
1586 tau_ccf = lagRange[ind_ccf]
1619 tau_ccf = lagRange[ind_ccf]
1587 tau_acf = lagRange[ind_acf]
1620 tau_acf = lagRange[ind_acf]
1588
1621
1589 Nan1, Nan2 = numpy.where(tau_ccf == lagRange[0])
1622 Nan1, Nan2 = numpy.where(tau_ccf == lagRange[0])
1590
1623
1591 tau_ccf[Nan1,Nan2] = numpy.nan
1624 tau_ccf[Nan1,Nan2] = numpy.nan
1592 tau_acf[Nan1,Nan2] = numpy.nan
1625 tau_acf[Nan1,Nan2] = numpy.nan
1593 tau = numpy.vstack((tau_ccf,tau_acf))
1626 tau = numpy.vstack((tau_ccf,tau_acf))
1594
1627
1595 return tau
1628 return tau
1596
1629
1597 def __calculateLag1Phase(self, data, lagTRange):
1630 def __calculateLag1Phase(self, data, lagTRange):
1598 data1 = stats.nanmean(data, axis = 0)
1631 data1 = stats.nanmean(data, axis = 0)
1599 lag1 = numpy.where(lagTRange == 0)[0][0] + 1
1632 lag1 = numpy.where(lagTRange == 0)[0][0] + 1
1600
1633
1601 phase = numpy.angle(data1[lag1,:])
1634 phase = numpy.angle(data1[lag1,:])
1602
1635
1603 return phase
1636 return phase
1604
1637
1605 class SpectralFitting(Operation):
1638 class SpectralFitting(Operation):
1606 '''
1639 '''
1607 Function GetMoments()
1640 Function GetMoments()
1608
1641
1609 Input:
1642 Input:
1610 Output:
1643 Output:
1611 Variables modified:
1644 Variables modified:
1612 '''
1645 '''
1613
1646
1614 def run(self, dataOut, getSNR = True, path=None, file=None, groupList=None):
1647 def run(self, dataOut, getSNR = True, path=None, file=None, groupList=None):
1615
1648
1616
1649
1617 if path != None:
1650 if path != None:
1618 sys.path.append(path)
1651 sys.path.append(path)
1619 self.dataOut.library = importlib.import_module(file)
1652 self.dataOut.library = importlib.import_module(file)
1620
1653
1621 #To be inserted as a parameter
1654 #To be inserted as a parameter
1622 groupArray = numpy.array(groupList)
1655 groupArray = numpy.array(groupList)
1623 # groupArray = numpy.array([[0,1],[2,3]])
1656 # groupArray = numpy.array([[0,1],[2,3]])
1624 self.dataOut.groupList = groupArray
1657 self.dataOut.groupList = groupArray
1625
1658
1626 nGroups = groupArray.shape[0]
1659 nGroups = groupArray.shape[0]
1627 nChannels = self.dataIn.nChannels
1660 nChannels = self.dataIn.nChannels
1628 nHeights=self.dataIn.heightList.size
1661 nHeights=self.dataIn.heightList.size
1629
1662
1630 #Parameters Array
1663 #Parameters Array
1631 self.dataOut.data_param = None
1664 self.dataOut.data_param = None
1632
1665
1633 #Set constants
1666 #Set constants
1634 constants = self.dataOut.library.setConstants(self.dataIn)
1667 constants = self.dataOut.library.setConstants(self.dataIn)
1635 self.dataOut.constants = constants
1668 self.dataOut.constants = constants
1636 M = self.dataIn.normFactor
1669 M = self.dataIn.normFactor
1637 N = self.dataIn.nFFTPoints
1670 N = self.dataIn.nFFTPoints
1638 ippSeconds = self.dataIn.ippSeconds
1671 ippSeconds = self.dataIn.ippSeconds
1639 K = self.dataIn.nIncohInt
1672 K = self.dataIn.nIncohInt
1640 pairsArray = numpy.array(self.dataIn.pairsList)
1673 pairsArray = numpy.array(self.dataIn.pairsList)
1641
1674
1642 #List of possible combinations
1675 #List of possible combinations
1643 listComb = itertools.combinations(numpy.arange(groupArray.shape[1]),2)
1676 listComb = itertools.combinations(numpy.arange(groupArray.shape[1]),2)
1644 indCross = numpy.zeros(len(list(listComb)), dtype = 'int')
1677 indCross = numpy.zeros(len(list(listComb)), dtype = 'int')
1645
1678
1646 if getSNR:
1679 if getSNR:
1647 listChannels = groupArray.reshape((groupArray.size))
1680 listChannels = groupArray.reshape((groupArray.size))
1648 listChannels.sort()
1681 listChannels.sort()
1649 noise = self.dataIn.getNoise()
1682 noise = self.dataIn.getNoise()
1650 self.dataOut.data_SNR = self.__getSNR(self.dataIn.data_spc[listChannels,:,:], noise[listChannels])
1683 self.dataOut.data_SNR = self.__getSNR(self.dataIn.data_spc[listChannels,:,:], noise[listChannels])
1651
1684
1652 for i in range(nGroups):
1685 for i in range(nGroups):
1653 coord = groupArray[i,:]
1686 coord = groupArray[i,:]
1654
1687
1655 #Input data array
1688 #Input data array
1656 data = self.dataIn.data_spc[coord,:,:]/(M*N)
1689 data = self.dataIn.data_spc[coord,:,:]/(M*N)
1657 data = data.reshape((data.shape[0]*data.shape[1],data.shape[2]))
1690 data = data.reshape((data.shape[0]*data.shape[1],data.shape[2]))
1658
1691
1659 #Cross Spectra data array for Covariance Matrixes
1692 #Cross Spectra data array for Covariance Matrixes
1660 ind = 0
1693 ind = 0
1661 for pairs in listComb:
1694 for pairs in listComb:
1662 pairsSel = numpy.array([coord[x],coord[y]])
1695 pairsSel = numpy.array([coord[x],coord[y]])
1663 indCross[ind] = int(numpy.where(numpy.all(pairsArray == pairsSel, axis = 1))[0][0])
1696 indCross[ind] = int(numpy.where(numpy.all(pairsArray == pairsSel, axis = 1))[0][0])
1664 ind += 1
1697 ind += 1
1665 dataCross = self.dataIn.data_cspc[indCross,:,:]/(M*N)
1698 dataCross = self.dataIn.data_cspc[indCross,:,:]/(M*N)
1666 dataCross = dataCross**2/K
1699 dataCross = dataCross**2/K
1667
1700
1668 for h in range(nHeights):
1701 for h in range(nHeights):
1669 # print self.dataOut.heightList[h]
1702 # print self.dataOut.heightList[h]
1670
1703
1671 #Input
1704 #Input
1672 d = data[:,h]
1705 d = data[:,h]
1673
1706
1674 #Covariance Matrix
1707 #Covariance Matrix
1675 D = numpy.diag(d**2/K)
1708 D = numpy.diag(d**2/K)
1676 ind = 0
1709 ind = 0
1677 for pairs in listComb:
1710 for pairs in listComb:
1678 #Coordinates in Covariance Matrix
1711 #Coordinates in Covariance Matrix
1679 x = pairs[0]
1712 x = pairs[0]
1680 y = pairs[1]
1713 y = pairs[1]
1681 #Channel Index
1714 #Channel Index
1682 S12 = dataCross[ind,:,h]
1715 S12 = dataCross[ind,:,h]
1683 D12 = numpy.diag(S12)
1716 D12 = numpy.diag(S12)
1684 #Completing Covariance Matrix with Cross Spectras
1717 #Completing Covariance Matrix with Cross Spectras
1685 D[x*N:(x+1)*N,y*N:(y+1)*N] = D12
1718 D[x*N:(x+1)*N,y*N:(y+1)*N] = D12
1686 D[y*N:(y+1)*N,x*N:(x+1)*N] = D12
1719 D[y*N:(y+1)*N,x*N:(x+1)*N] = D12
1687 ind += 1
1720 ind += 1
1688 Dinv=numpy.linalg.inv(D)
1721 Dinv=numpy.linalg.inv(D)
1689 L=numpy.linalg.cholesky(Dinv)
1722 L=numpy.linalg.cholesky(Dinv)
1690 LT=L.T
1723 LT=L.T
1691
1724
1692 dp = numpy.dot(LT,d)
1725 dp = numpy.dot(LT,d)
1693
1726
1694 #Initial values
1727 #Initial values
1695 data_spc = self.dataIn.data_spc[coord,:,h]
1728 data_spc = self.dataIn.data_spc[coord,:,h]
1696
1729
1697 if (h>0)and(error1[3]<5):
1730 if (h>0)and(error1[3]<5):
1698 p0 = self.dataOut.data_param[i,:,h-1]
1731 p0 = self.dataOut.data_param[i,:,h-1]
1699 else:
1732 else:
1700 p0 = numpy.array(self.dataOut.library.initialValuesFunction(data_spc, constants, i))
1733 p0 = numpy.array(self.dataOut.library.initialValuesFunction(data_spc, constants, i))
1701
1734
1702 try:
1735 try:
1703 #Least Squares
1736 #Least Squares
1704 minp,covp,infodict,mesg,ier = optimize.leastsq(self.__residFunction,p0,args=(dp,LT,constants),full_output=True)
1737 minp,covp,infodict,mesg,ier = optimize.leastsq(self.__residFunction,p0,args=(dp,LT,constants),full_output=True)
1705 # minp,covp = optimize.leastsq(self.__residFunction,p0,args=(dp,LT,constants))
1738 # minp,covp = optimize.leastsq(self.__residFunction,p0,args=(dp,LT,constants))
1706 #Chi square error
1739 #Chi square error
1707 error0 = numpy.sum(infodict['fvec']**2)/(2*N)
1740 error0 = numpy.sum(infodict['fvec']**2)/(2*N)
1708 #Error with Jacobian
1741 #Error with Jacobian
1709 error1 = self.dataOut.library.errorFunction(minp,constants,LT)
1742 error1 = self.dataOut.library.errorFunction(minp,constants,LT)
1710 except:
1743 except:
1711 minp = p0*numpy.nan
1744 minp = p0*numpy.nan
1712 error0 = numpy.nan
1745 error0 = numpy.nan
1713 error1 = p0*numpy.nan
1746 error1 = p0*numpy.nan
1714
1747
1715 #Save
1748 #Save
1716 if self.dataOut.data_param == None:
1749 if self.dataOut.data_param == None:
1717 self.dataOut.data_param = numpy.zeros((nGroups, p0.size, nHeights))*numpy.nan
1750 self.dataOut.data_param = numpy.zeros((nGroups, p0.size, nHeights))*numpy.nan
1718 self.dataOut.data_error = numpy.zeros((nGroups, p0.size + 1, nHeights))*numpy.nan
1751 self.dataOut.data_error = numpy.zeros((nGroups, p0.size + 1, nHeights))*numpy.nan
1719
1752
1720 self.dataOut.data_error[i,:,h] = numpy.hstack((error0,error1))
1753 self.dataOut.data_error[i,:,h] = numpy.hstack((error0,error1))
1721 self.dataOut.data_param[i,:,h] = minp
1754 self.dataOut.data_param[i,:,h] = minp
1722 return
1755 return
1723
1756
1724 def __residFunction(self, p, dp, LT, constants):
1757 def __residFunction(self, p, dp, LT, constants):
1725
1758
1726 fm = self.dataOut.library.modelFunction(p, constants)
1759 fm = self.dataOut.library.modelFunction(p, constants)
1727 fmp=numpy.dot(LT,fm)
1760 fmp=numpy.dot(LT,fm)
1728
1761
1729 return dp-fmp
1762 return dp-fmp
1730
1763
1731 def __getSNR(self, z, noise):
1764 def __getSNR(self, z, noise):
1732
1765
1733 avg = numpy.average(z, axis=1)
1766 avg = numpy.average(z, axis=1)
1734 SNR = (avg.T-noise)/noise
1767 SNR = (avg.T-noise)/noise
1735 SNR = SNR.T
1768 SNR = SNR.T
1736 return SNR
1769 return SNR
1737
1770
1738 def __chisq(p,chindex,hindex):
1771 def __chisq(p,chindex,hindex):
1739 #similar to Resid but calculates CHI**2
1772 #similar to Resid but calculates CHI**2
1740 [LT,d,fm]=setupLTdfm(p,chindex,hindex)
1773 [LT,d,fm]=setupLTdfm(p,chindex,hindex)
1741 dp=numpy.dot(LT,d)
1774 dp=numpy.dot(LT,d)
1742 fmp=numpy.dot(LT,fm)
1775 fmp=numpy.dot(LT,fm)
1743 chisq=numpy.dot((dp-fmp).T,(dp-fmp))
1776 chisq=numpy.dot((dp-fmp).T,(dp-fmp))
1744 return chisq
1777 return chisq
1745
1778
1746 class WindProfiler(Operation):
1779 class WindProfiler(Operation):
1747
1780
1748 __isConfig = False
1781 __isConfig = False
1749
1782
1750 __initime = None
1783 __initime = None
1751 __lastdatatime = None
1784 __lastdatatime = None
1752 __integrationtime = None
1785 __integrationtime = None
1753
1786
1754 __buffer = None
1787 __buffer = None
1755
1788
1756 __dataReady = False
1789 __dataReady = False
1757
1790
1758 __firstdata = None
1791 __firstdata = None
1759
1792
1760 n = None
1793 n = None
1761
1794
1762 def __init__(self, **kwargs):
1795 def __init__(self, **kwargs):
1763 Operation.__init__(self, **kwargs)
1796 Operation.__init__(self, **kwargs)
1764
1797
1765 def __calculateCosDir(self, elev, azim):
1798 def __calculateCosDir(self, elev, azim):
1766 zen = (90 - elev)*numpy.pi/180
1799 zen = (90 - elev)*numpy.pi/180
1767 azim = azim*numpy.pi/180
1800 azim = azim*numpy.pi/180
1768 cosDirX = numpy.sqrt((1-numpy.cos(zen)**2)/((1+numpy.tan(azim)**2)))
1801 cosDirX = numpy.sqrt((1-numpy.cos(zen)**2)/((1+numpy.tan(azim)**2)))
1769 cosDirY = numpy.sqrt(1-numpy.cos(zen)**2-cosDirX**2)
1802 cosDirY = numpy.sqrt(1-numpy.cos(zen)**2-cosDirX**2)
1770
1803
1771 signX = numpy.sign(numpy.cos(azim))
1804 signX = numpy.sign(numpy.cos(azim))
1772 signY = numpy.sign(numpy.sin(azim))
1805 signY = numpy.sign(numpy.sin(azim))
1773
1806
1774 cosDirX = numpy.copysign(cosDirX, signX)
1807 cosDirX = numpy.copysign(cosDirX, signX)
1775 cosDirY = numpy.copysign(cosDirY, signY)
1808 cosDirY = numpy.copysign(cosDirY, signY)
1776 return cosDirX, cosDirY
1809 return cosDirX, cosDirY
1777
1810
1778 def __calculateAngles(self, theta_x, theta_y, azimuth):
1811 def __calculateAngles(self, theta_x, theta_y, azimuth):
1779
1812
1780 dir_cosw = numpy.sqrt(1-theta_x**2-theta_y**2)
1813 dir_cosw = numpy.sqrt(1-theta_x**2-theta_y**2)
1781 zenith_arr = numpy.arccos(dir_cosw)
1814 zenith_arr = numpy.arccos(dir_cosw)
1782 azimuth_arr = numpy.arctan2(theta_x,theta_y) + azimuth*math.pi/180
1815 azimuth_arr = numpy.arctan2(theta_x,theta_y) + azimuth*math.pi/180
1783
1816
1784 dir_cosu = numpy.sin(azimuth_arr)*numpy.sin(zenith_arr)
1817 dir_cosu = numpy.sin(azimuth_arr)*numpy.sin(zenith_arr)
1785 dir_cosv = numpy.cos(azimuth_arr)*numpy.sin(zenith_arr)
1818 dir_cosv = numpy.cos(azimuth_arr)*numpy.sin(zenith_arr)
1786
1819
1787 return azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw
1820 return azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw
1788
1821
1789 def __calculateMatA(self, dir_cosu, dir_cosv, dir_cosw, horOnly):
1822 def __calculateMatA(self, dir_cosu, dir_cosv, dir_cosw, horOnly):
1790
1823
1791 #
1824 #
1792 if horOnly:
1825 if horOnly:
1793 A = numpy.c_[dir_cosu,dir_cosv]
1826 A = numpy.c_[dir_cosu,dir_cosv]
1794 else:
1827 else:
1795 A = numpy.c_[dir_cosu,dir_cosv,dir_cosw]
1828 A = numpy.c_[dir_cosu,dir_cosv,dir_cosw]
1796 A = numpy.asmatrix(A)
1829 A = numpy.asmatrix(A)
1797 A1 = numpy.linalg.inv(A.transpose()*A)*A.transpose()
1830 A1 = numpy.linalg.inv(A.transpose()*A)*A.transpose()
1798
1831
1799 return A1
1832 return A1
1800
1833
1801 def __correctValues(self, heiRang, phi, velRadial, SNR):
1834 def __correctValues(self, heiRang, phi, velRadial, SNR):
1802 listPhi = phi.tolist()
1835 listPhi = phi.tolist()
1803 maxid = listPhi.index(max(listPhi))
1836 maxid = listPhi.index(max(listPhi))
1804 minid = listPhi.index(min(listPhi))
1837 minid = listPhi.index(min(listPhi))
1805
1838
1806 rango = range(len(phi))
1839 rango = range(len(phi))
1807 # rango = numpy.delete(rango,maxid)
1840 # rango = numpy.delete(rango,maxid)
1808
1841
1809 heiRang1 = heiRang*math.cos(phi[maxid])
1842 heiRang1 = heiRang*math.cos(phi[maxid])
1810 heiRangAux = heiRang*math.cos(phi[minid])
1843 heiRangAux = heiRang*math.cos(phi[minid])
1811 indOut = (heiRang1 < heiRangAux[0]).nonzero()
1844 indOut = (heiRang1 < heiRangAux[0]).nonzero()
1812 heiRang1 = numpy.delete(heiRang1,indOut)
1845 heiRang1 = numpy.delete(heiRang1,indOut)
1813
1846
1814 velRadial1 = numpy.zeros([len(phi),len(heiRang1)])
1847 velRadial1 = numpy.zeros([len(phi),len(heiRang1)])
1815 SNR1 = numpy.zeros([len(phi),len(heiRang1)])
1848 SNR1 = numpy.zeros([len(phi),len(heiRang1)])
1816
1849
1817 for i in rango:
1850 for i in rango:
1818 x = heiRang*math.cos(phi[i])
1851 x = heiRang*math.cos(phi[i])
1819 y1 = velRadial[i,:]
1852 y1 = velRadial[i,:]
1820 f1 = interpolate.interp1d(x,y1,kind = 'cubic')
1853 f1 = interpolate.interp1d(x,y1,kind = 'cubic')
1821
1854
1822 x1 = heiRang1
1855 x1 = heiRang1
1823 y11 = f1(x1)
1856 y11 = f1(x1)
1824
1857
1825 y2 = SNR[i,:]
1858 y2 = SNR[i,:]
1826 f2 = interpolate.interp1d(x,y2,kind = 'cubic')
1859 f2 = interpolate.interp1d(x,y2,kind = 'cubic')
1827 y21 = f2(x1)
1860 y21 = f2(x1)
1828
1861
1829 velRadial1[i,:] = y11
1862 velRadial1[i,:] = y11
1830 SNR1[i,:] = y21
1863 SNR1[i,:] = y21
1831
1864
1832 return heiRang1, velRadial1, SNR1
1865 return heiRang1, velRadial1, SNR1
1833
1866
1834 def __calculateVelUVW(self, A, velRadial):
1867 def __calculateVelUVW(self, A, velRadial):
1835
1868
1836 #Operacion Matricial
1869 #Operacion Matricial
1837 # velUVW = numpy.zeros((velRadial.shape[1],3))
1870 # velUVW = numpy.zeros((velRadial.shape[1],3))
1838 # for ind in range(velRadial.shape[1]):
1871 # for ind in range(velRadial.shape[1]):
1839 # velUVW[ind,:] = numpy.dot(A,velRadial[:,ind])
1872 # velUVW[ind,:] = numpy.dot(A,velRadial[:,ind])
1840 # velUVW = velUVW.transpose()
1873 # velUVW = velUVW.transpose()
1841 velUVW = numpy.zeros((A.shape[0],velRadial.shape[1]))
1874 velUVW = numpy.zeros((A.shape[0],velRadial.shape[1]))
1842 velUVW[:,:] = numpy.dot(A,velRadial)
1875 velUVW[:,:] = numpy.dot(A,velRadial)
1843
1876
1844
1877
1845 return velUVW
1878 return velUVW
1846
1879
1847 # def techniqueDBS(self, velRadial0, dirCosx, disrCosy, azimuth, correct, horizontalOnly, heiRang, SNR0):
1880 # def techniqueDBS(self, velRadial0, dirCosx, disrCosy, azimuth, correct, horizontalOnly, heiRang, SNR0):
1848
1881
1849 def techniqueDBS(self, kwargs):
1882 def techniqueDBS(self, kwargs):
1850 """
1883 """
1851 Function that implements Doppler Beam Swinging (DBS) technique.
1884 Function that implements Doppler Beam Swinging (DBS) technique.
1852
1885
1853 Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth,
1886 Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth,
1854 Direction correction (if necessary), Ranges and SNR
1887 Direction correction (if necessary), Ranges and SNR
1855
1888
1856 Output: Winds estimation (Zonal, Meridional and Vertical)
1889 Output: Winds estimation (Zonal, Meridional and Vertical)
1857
1890
1858 Parameters affected: Winds, height range, SNR
1891 Parameters affected: Winds, height range, SNR
1859 """
1892 """
1860 velRadial0 = kwargs['velRadial']
1893 velRadial0 = kwargs['velRadial']
1861 heiRang = kwargs['heightList']
1894 heiRang = kwargs['heightList']
1862 SNR0 = kwargs['SNR']
1895 SNR0 = kwargs['SNR']
1863
1896
1864 if kwargs.has_key('dirCosx') and kwargs.has_key('dirCosy'):
1897 if kwargs.has_key('dirCosx') and kwargs.has_key('dirCosy'):
1865 theta_x = numpy.array(kwargs['dirCosx'])
1898 theta_x = numpy.array(kwargs['dirCosx'])
1866 theta_y = numpy.array(kwargs['dirCosy'])
1899 theta_y = numpy.array(kwargs['dirCosy'])
1867 else:
1900 else:
1868 elev = numpy.array(kwargs['elevation'])
1901 elev = numpy.array(kwargs['elevation'])
1869 azim = numpy.array(kwargs['azimuth'])
1902 azim = numpy.array(kwargs['azimuth'])
1870 theta_x, theta_y = self.__calculateCosDir(elev, azim)
1903 theta_x, theta_y = self.__calculateCosDir(elev, azim)
1871 azimuth = kwargs['correctAzimuth']
1904 azimuth = kwargs['correctAzimuth']
1872 if kwargs.has_key('horizontalOnly'):
1905 if kwargs.has_key('horizontalOnly'):
1873 horizontalOnly = kwargs['horizontalOnly']
1906 horizontalOnly = kwargs['horizontalOnly']
1874 else: horizontalOnly = False
1907 else: horizontalOnly = False
1875 if kwargs.has_key('correctFactor'):
1908 if kwargs.has_key('correctFactor'):
1876 correctFactor = kwargs['correctFactor']
1909 correctFactor = kwargs['correctFactor']
1877 else: correctFactor = 1
1910 else: correctFactor = 1
1878 if kwargs.has_key('channelList'):
1911 if kwargs.has_key('channelList'):
1879 channelList = kwargs['channelList']
1912 channelList = kwargs['channelList']
1880 if len(channelList) == 2:
1913 if len(channelList) == 2:
1881 horizontalOnly = True
1914 horizontalOnly = True
1882 arrayChannel = numpy.array(channelList)
1915 arrayChannel = numpy.array(channelList)
1883 param = param[arrayChannel,:,:]
1916 param = param[arrayChannel,:,:]
1884 theta_x = theta_x[arrayChannel]
1917 theta_x = theta_x[arrayChannel]
1885 theta_y = theta_y[arrayChannel]
1918 theta_y = theta_y[arrayChannel]
1886
1919
1887 azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw = self.__calculateAngles(theta_x, theta_y, azimuth)
1920 azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw = self.__calculateAngles(theta_x, theta_y, azimuth)
1888 heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, zenith_arr, correctFactor*velRadial0, SNR0)
1921 heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, zenith_arr, correctFactor*velRadial0, SNR0)
1889 A = self.__calculateMatA(dir_cosu, dir_cosv, dir_cosw, horizontalOnly)
1922 A = self.__calculateMatA(dir_cosu, dir_cosv, dir_cosw, horizontalOnly)
1890
1923
1891 #Calculo de Componentes de la velocidad con DBS
1924 #Calculo de Componentes de la velocidad con DBS
1892 winds = self.__calculateVelUVW(A,velRadial1)
1925 winds = self.__calculateVelUVW(A,velRadial1)
1893
1926
1894 return winds, heiRang1, SNR1
1927 return winds, heiRang1, SNR1
1895
1928
1896 def __calculateDistance(self, posx, posy, pairs_ccf, azimuth = None):
1929 def __calculateDistance(self, posx, posy, pairs_ccf, azimuth = None):
1897
1930
1898 nPairs = len(pairs_ccf)
1931 nPairs = len(pairs_ccf)
1899 posx = numpy.asarray(posx)
1932 posx = numpy.asarray(posx)
1900 posy = numpy.asarray(posy)
1933 posy = numpy.asarray(posy)
1901
1934
1902 #Rotacion Inversa para alinear con el azimuth
1935 #Rotacion Inversa para alinear con el azimuth
1903 if azimuth!= None:
1936 if azimuth!= None:
1904 azimuth = azimuth*math.pi/180
1937 azimuth = azimuth*math.pi/180
1905 posx1 = posx*math.cos(azimuth) + posy*math.sin(azimuth)
1938 posx1 = posx*math.cos(azimuth) + posy*math.sin(azimuth)
1906 posy1 = -posx*math.sin(azimuth) + posy*math.cos(azimuth)
1939 posy1 = -posx*math.sin(azimuth) + posy*math.cos(azimuth)
1907 else:
1940 else:
1908 posx1 = posx
1941 posx1 = posx
1909 posy1 = posy
1942 posy1 = posy
1910
1943
1911 #Calculo de Distancias
1944 #Calculo de Distancias
1912 distx = numpy.zeros(nPairs)
1945 distx = numpy.zeros(nPairs)
1913 disty = numpy.zeros(nPairs)
1946 disty = numpy.zeros(nPairs)
1914 dist = numpy.zeros(nPairs)
1947 dist = numpy.zeros(nPairs)
1915 ang = numpy.zeros(nPairs)
1948 ang = numpy.zeros(nPairs)
1916
1949
1917 for i in range(nPairs):
1950 for i in range(nPairs):
1918 distx[i] = posx1[pairs_ccf[i][1]] - posx1[pairs_ccf[i][0]]
1951 distx[i] = posx1[pairs_ccf[i][1]] - posx1[pairs_ccf[i][0]]
1919 disty[i] = posy1[pairs_ccf[i][1]] - posy1[pairs_ccf[i][0]]
1952 disty[i] = posy1[pairs_ccf[i][1]] - posy1[pairs_ccf[i][0]]
1920 dist[i] = numpy.sqrt(distx[i]**2 + disty[i]**2)
1953 dist[i] = numpy.sqrt(distx[i]**2 + disty[i]**2)
1921 ang[i] = numpy.arctan2(disty[i],distx[i])
1954 ang[i] = numpy.arctan2(disty[i],distx[i])
1922
1955
1923 return distx, disty, dist, ang
1956 return distx, disty, dist, ang
1924 #Calculo de Matrices
1957 #Calculo de Matrices
1925 # nPairs = len(pairs)
1958 # nPairs = len(pairs)
1926 # ang1 = numpy.zeros((nPairs, 2, 1))
1959 # ang1 = numpy.zeros((nPairs, 2, 1))
1927 # dist1 = numpy.zeros((nPairs, 2, 1))
1960 # dist1 = numpy.zeros((nPairs, 2, 1))
1928 #
1961 #
1929 # for j in range(nPairs):
1962 # for j in range(nPairs):
1930 # dist1[j,0,0] = dist[pairs[j][0]]
1963 # dist1[j,0,0] = dist[pairs[j][0]]
1931 # dist1[j,1,0] = dist[pairs[j][1]]
1964 # dist1[j,1,0] = dist[pairs[j][1]]
1932 # ang1[j,0,0] = ang[pairs[j][0]]
1965 # ang1[j,0,0] = ang[pairs[j][0]]
1933 # ang1[j,1,0] = ang[pairs[j][1]]
1966 # ang1[j,1,0] = ang[pairs[j][1]]
1934 #
1967 #
1935 # return distx,disty, dist1,ang1
1968 # return distx,disty, dist1,ang1
1936
1969
1937
1970
1938 def __calculateVelVer(self, phase, lagTRange, _lambda):
1971 def __calculateVelVer(self, phase, lagTRange, _lambda):
1939
1972
1940 Ts = lagTRange[1] - lagTRange[0]
1973 Ts = lagTRange[1] - lagTRange[0]
1941 velW = -_lambda*phase/(4*math.pi*Ts)
1974 velW = -_lambda*phase/(4*math.pi*Ts)
1942
1975
1943 return velW
1976 return velW
1944
1977
1945 def __calculateVelHorDir(self, dist, tau1, tau2, ang):
1978 def __calculateVelHorDir(self, dist, tau1, tau2, ang):
1946 nPairs = tau1.shape[0]
1979 nPairs = tau1.shape[0]
1947 nHeights = tau1.shape[1]
1980 nHeights = tau1.shape[1]
1948 vel = numpy.zeros((nPairs,3,nHeights))
1981 vel = numpy.zeros((nPairs,3,nHeights))
1949 dist1 = numpy.reshape(dist, (dist.size,1))
1982 dist1 = numpy.reshape(dist, (dist.size,1))
1950
1983
1951 angCos = numpy.cos(ang)
1984 angCos = numpy.cos(ang)
1952 angSin = numpy.sin(ang)
1985 angSin = numpy.sin(ang)
1953
1986
1954 vel0 = dist1*tau1/(2*tau2**2)
1987 vel0 = dist1*tau1/(2*tau2**2)
1955 vel[:,0,:] = (vel0*angCos).sum(axis = 1)
1988 vel[:,0,:] = (vel0*angCos).sum(axis = 1)
1956 vel[:,1,:] = (vel0*angSin).sum(axis = 1)
1989 vel[:,1,:] = (vel0*angSin).sum(axis = 1)
1957
1990
1958 ind = numpy.where(numpy.isinf(vel))
1991 ind = numpy.where(numpy.isinf(vel))
1959 vel[ind] = numpy.nan
1992 vel[ind] = numpy.nan
1960
1993
1961 return vel
1994 return vel
1962
1995
1963 # def __getPairsAutoCorr(self, pairsList, nChannels):
1996 # def __getPairsAutoCorr(self, pairsList, nChannels):
1964 #
1997 #
1965 # pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan
1998 # pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan
1966 #
1999 #
1967 # for l in range(len(pairsList)):
2000 # for l in range(len(pairsList)):
1968 # firstChannel = pairsList[l][0]
2001 # firstChannel = pairsList[l][0]
1969 # secondChannel = pairsList[l][1]
2002 # secondChannel = pairsList[l][1]
1970 #
2003 #
1971 # #Obteniendo pares de Autocorrelacion
2004 # #Obteniendo pares de Autocorrelacion
1972 # if firstChannel == secondChannel:
2005 # if firstChannel == secondChannel:
1973 # pairsAutoCorr[firstChannel] = int(l)
2006 # pairsAutoCorr[firstChannel] = int(l)
1974 #
2007 #
1975 # pairsAutoCorr = pairsAutoCorr.astype(int)
2008 # pairsAutoCorr = pairsAutoCorr.astype(int)
1976 #
2009 #
1977 # pairsCrossCorr = range(len(pairsList))
2010 # pairsCrossCorr = range(len(pairsList))
1978 # pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr)
2011 # pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr)
1979 #
2012 #
1980 # return pairsAutoCorr, pairsCrossCorr
2013 # return pairsAutoCorr, pairsCrossCorr
1981
2014
1982 # def techniqueSA(self, pairsSelected, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, lagTRange, correctFactor):
2015 # def techniqueSA(self, pairsSelected, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, lagTRange, correctFactor):
1983 def techniqueSA(self, kwargs):
2016 def techniqueSA(self, kwargs):
1984
2017
1985 """
2018 """
1986 Function that implements Spaced Antenna (SA) technique.
2019 Function that implements Spaced Antenna (SA) technique.
1987
2020
1988 Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth,
2021 Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth,
1989 Direction correction (if necessary), Ranges and SNR
2022 Direction correction (if necessary), Ranges and SNR
1990
2023
1991 Output: Winds estimation (Zonal, Meridional and Vertical)
2024 Output: Winds estimation (Zonal, Meridional and Vertical)
1992
2025
1993 Parameters affected: Winds
2026 Parameters affected: Winds
1994 """
2027 """
1995 position_x = kwargs['positionX']
2028 position_x = kwargs['positionX']
1996 position_y = kwargs['positionY']
2029 position_y = kwargs['positionY']
1997 azimuth = kwargs['azimuth']
2030 azimuth = kwargs['azimuth']
1998
2031
1999 if kwargs.has_key('correctFactor'):
2032 if kwargs.has_key('correctFactor'):
2000 correctFactor = kwargs['correctFactor']
2033 correctFactor = kwargs['correctFactor']
2001 else:
2034 else:
2002 correctFactor = 1
2035 correctFactor = 1
2003
2036
2004 groupList = kwargs['groupList']
2037 groupList = kwargs['groupList']
2005 pairs_ccf = groupList[1]
2038 pairs_ccf = groupList[1]
2006 tau = kwargs['tau']
2039 tau = kwargs['tau']
2007 _lambda = kwargs['_lambda']
2040 _lambda = kwargs['_lambda']
2008
2041
2009 #Cross Correlation pairs obtained
2042 #Cross Correlation pairs obtained
2010 # pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairssList, nChannels)
2043 # pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairssList, nChannels)
2011 # pairsArray = numpy.array(pairsList)[pairsCrossCorr]
2044 # pairsArray = numpy.array(pairsList)[pairsCrossCorr]
2012 # pairsSelArray = numpy.array(pairsSelected)
2045 # pairsSelArray = numpy.array(pairsSelected)
2013 # pairs = []
2046 # pairs = []
2014 #
2047 #
2015 # #Wind estimation pairs obtained
2048 # #Wind estimation pairs obtained
2016 # for i in range(pairsSelArray.shape[0]/2):
2049 # for i in range(pairsSelArray.shape[0]/2):
2017 # ind1 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i], axis = 1))[0][0]
2050 # ind1 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i], axis = 1))[0][0]
2018 # ind2 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i + 1], axis = 1))[0][0]
2051 # ind2 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i + 1], axis = 1))[0][0]
2019 # pairs.append((ind1,ind2))
2052 # pairs.append((ind1,ind2))
2020
2053
2021 indtau = tau.shape[0]/2
2054 indtau = tau.shape[0]/2
2022 tau1 = tau[:indtau,:]
2055 tau1 = tau[:indtau,:]
2023 tau2 = tau[indtau:-1,:]
2056 tau2 = tau[indtau:-1,:]
2024 # tau1 = tau1[pairs,:]
2057 # tau1 = tau1[pairs,:]
2025 # tau2 = tau2[pairs,:]
2058 # tau2 = tau2[pairs,:]
2026 phase1 = tau[-1,:]
2059 phase1 = tau[-1,:]
2027
2060
2028 #---------------------------------------------------------------------
2061 #---------------------------------------------------------------------
2029 #Metodo Directo
2062 #Metodo Directo
2030 distx, disty, dist, ang = self.__calculateDistance(position_x, position_y, pairs_ccf,azimuth)
2063 distx, disty, dist, ang = self.__calculateDistance(position_x, position_y, pairs_ccf,azimuth)
2031 winds = self.__calculateVelHorDir(dist, tau1, tau2, ang)
2064 winds = self.__calculateVelHorDir(dist, tau1, tau2, ang)
2032 winds = stats.nanmean(winds, axis=0)
2065 winds = stats.nanmean(winds, axis=0)
2033 #---------------------------------------------------------------------
2066 #---------------------------------------------------------------------
2034 #Metodo General
2067 #Metodo General
2035 # distx, disty, dist = self.calculateDistance(position_x,position_y,pairsCrossCorr, pairsList, azimuth)
2068 # distx, disty, dist = self.calculateDistance(position_x,position_y,pairsCrossCorr, pairsList, azimuth)
2036 # #Calculo Coeficientes de Funcion de Correlacion
2069 # #Calculo Coeficientes de Funcion de Correlacion
2037 # F,G,A,B,H = self.calculateCoef(tau1,tau2,distx,disty,n)
2070 # F,G,A,B,H = self.calculateCoef(tau1,tau2,distx,disty,n)
2038 # #Calculo de Velocidades
2071 # #Calculo de Velocidades
2039 # winds = self.calculateVelUV(F,G,A,B,H)
2072 # winds = self.calculateVelUV(F,G,A,B,H)
2040
2073
2041 #---------------------------------------------------------------------
2074 #---------------------------------------------------------------------
2042 winds[2,:] = self.__calculateVelVer(phase1, lagTRange, _lambda)
2075 winds[2,:] = self.__calculateVelVer(phase1, lagTRange, _lambda)
2043 winds = correctFactor*winds
2076 winds = correctFactor*winds
2044 return winds
2077 return winds
2045
2078
2046 def __checkTime(self, currentTime, paramInterval, outputInterval):
2079 def __checkTime(self, currentTime, paramInterval, outputInterval):
2047
2080
2048 dataTime = currentTime + paramInterval
2081 dataTime = currentTime + paramInterval
2049 deltaTime = dataTime - self.__initime
2082 deltaTime = dataTime - self.__initime
2050
2083
2051 if deltaTime >= outputInterval or deltaTime < 0:
2084 if deltaTime >= outputInterval or deltaTime < 0:
2052 self.__dataReady = True
2085 self.__dataReady = True
2053 return
2086 return
2054
2087
2055 def techniqueMeteors(self, arrayMeteor, meteorThresh, heightMin, heightMax):
2088 def techniqueMeteors(self, arrayMeteor, meteorThresh, heightMin, heightMax):
2056 '''
2089 '''
2057 Function that implements winds estimation technique with detected meteors.
2090 Function that implements winds estimation technique with detected meteors.
2058
2091
2059 Input: Detected meteors, Minimum meteor quantity to wind estimation
2092 Input: Detected meteors, Minimum meteor quantity to wind estimation
2060
2093
2061 Output: Winds estimation (Zonal and Meridional)
2094 Output: Winds estimation (Zonal and Meridional)
2062
2095
2063 Parameters affected: Winds
2096 Parameters affected: Winds
2064 '''
2097 '''
2065 # print arrayMeteor.shape
2098 # print arrayMeteor.shape
2066 #Settings
2099 #Settings
2067 nInt = (heightMax - heightMin)/2
2100 nInt = (heightMax - heightMin)/2
2068 # print nInt
2101 # print nInt
2069 nInt = int(nInt)
2102 nInt = int(nInt)
2070 # print nInt
2103 # print nInt
2071 winds = numpy.zeros((2,nInt))*numpy.nan
2104 winds = numpy.zeros((2,nInt))*numpy.nan
2072
2105
2073 #Filter errors
2106 #Filter errors
2074 error = numpy.where(arrayMeteor[:,-1] == 0)[0]
2107 error = numpy.where(arrayMeteor[:,-1] == 0)[0]
2075 finalMeteor = arrayMeteor[error,:]
2108 finalMeteor = arrayMeteor[error,:]
2076
2109
2077 #Meteor Histogram
2110 #Meteor Histogram
2078 finalHeights = finalMeteor[:,2]
2111 finalHeights = finalMeteor[:,2]
2079 hist = numpy.histogram(finalHeights, bins = nInt, range = (heightMin,heightMax))
2112 hist = numpy.histogram(finalHeights, bins = nInt, range = (heightMin,heightMax))
2080 nMeteorsPerI = hist[0]
2113 nMeteorsPerI = hist[0]
2081 heightPerI = hist[1]
2114 heightPerI = hist[1]
2082
2115
2083 #Sort of meteors
2116 #Sort of meteors
2084 indSort = finalHeights.argsort()
2117 indSort = finalHeights.argsort()
2085 finalMeteor2 = finalMeteor[indSort,:]
2118 finalMeteor2 = finalMeteor[indSort,:]
2086
2119
2087 # Calculating winds
2120 # Calculating winds
2088 ind1 = 0
2121 ind1 = 0
2089 ind2 = 0
2122 ind2 = 0
2090
2123
2091 for i in range(nInt):
2124 for i in range(nInt):
2092 nMet = nMeteorsPerI[i]
2125 nMet = nMeteorsPerI[i]
2093 ind1 = ind2
2126 ind1 = ind2
2094 ind2 = ind1 + nMet
2127 ind2 = ind1 + nMet
2095
2128
2096 meteorAux = finalMeteor2[ind1:ind2,:]
2129 meteorAux = finalMeteor2[ind1:ind2,:]
2097
2130
2098 if meteorAux.shape[0] >= meteorThresh:
2131 if meteorAux.shape[0] >= meteorThresh:
2099 vel = meteorAux[:, 6]
2132 vel = meteorAux[:, 6]
2100 zen = meteorAux[:, 4]*numpy.pi/180
2133 zen = meteorAux[:, 4]*numpy.pi/180
2101 azim = meteorAux[:, 3]*numpy.pi/180
2134 azim = meteorAux[:, 3]*numpy.pi/180
2102
2135
2103 n = numpy.cos(zen)
2136 n = numpy.cos(zen)
2104 # m = (1 - n**2)/(1 - numpy.tan(azim)**2)
2137 # m = (1 - n**2)/(1 - numpy.tan(azim)**2)
2105 # l = m*numpy.tan(azim)
2138 # l = m*numpy.tan(azim)
2106 l = numpy.sin(zen)*numpy.sin(azim)
2139 l = numpy.sin(zen)*numpy.sin(azim)
2107 m = numpy.sin(zen)*numpy.cos(azim)
2140 m = numpy.sin(zen)*numpy.cos(azim)
2108
2141
2109 A = numpy.vstack((l, m)).transpose()
2142 A = numpy.vstack((l, m)).transpose()
2110 A1 = numpy.dot(numpy.linalg.inv( numpy.dot(A.transpose(),A) ),A.transpose())
2143 A1 = numpy.dot(numpy.linalg.inv( numpy.dot(A.transpose(),A) ),A.transpose())
2111 windsAux = numpy.dot(A1, vel)
2144 windsAux = numpy.dot(A1, vel)
2112
2145
2113 winds[0,i] = windsAux[0]
2146 winds[0,i] = windsAux[0]
2114 winds[1,i] = windsAux[1]
2147 winds[1,i] = windsAux[1]
2115
2148
2116 return winds, heightPerI[:-1]
2149 return winds, heightPerI[:-1]
2117
2150
2118 def techniqueNSM_SA(self, **kwargs):
2151 def techniqueNSM_SA(self, **kwargs):
2119 metArray = kwargs['metArray']
2152 metArray = kwargs['metArray']
2120 heightList = kwargs['heightList']
2153 heightList = kwargs['heightList']
2121 timeList = kwargs['timeList']
2154 timeList = kwargs['timeList']
2122
2155
2123 rx_location = kwargs['rx_location']
2156 rx_location = kwargs['rx_location']
2124 groupList = kwargs['groupList']
2157 groupList = kwargs['groupList']
2125 azimuth = kwargs['azimuth']
2158 azimuth = kwargs['azimuth']
2126 dfactor = kwargs['dfactor']
2159 dfactor = kwargs['dfactor']
2127 k = kwargs['k']
2160 k = kwargs['k']
2128
2161
2129 azimuth1, dist = self.__calculateAzimuth1(rx_location, groupList, azimuth)
2162 azimuth1, dist = self.__calculateAzimuth1(rx_location, groupList, azimuth)
2130 d = dist*dfactor
2163 d = dist*dfactor
2131 #Phase calculation
2164 #Phase calculation
2132 metArray1 = self.__getPhaseSlope(metArray, heightList, timeList)
2165 metArray1 = self.__getPhaseSlope(metArray, heightList, timeList)
2133
2166
2134 metArray1[:,-2] = metArray1[:,-2]*metArray1[:,2]*1000/(k*d[metArray1[:,1].astype(int)]) #angles into velocities
2167 metArray1[:,-2] = metArray1[:,-2]*metArray1[:,2]*1000/(k*d[metArray1[:,1].astype(int)]) #angles into velocities
2135
2168
2136 velEst = numpy.zeros((heightList.size,2))*numpy.nan
2169 velEst = numpy.zeros((heightList.size,2))*numpy.nan
2137 azimuth1 = azimuth1*numpy.pi/180
2170 azimuth1 = azimuth1*numpy.pi/180
2138
2171
2139 for i in range(heightList.size):
2172 for i in range(heightList.size):
2140 h = heightList[i]
2173 h = heightList[i]
2141 indH = numpy.where((metArray1[:,2] == h)&(numpy.abs(metArray1[:,-2]) < 100))[0]
2174 indH = numpy.where((metArray1[:,2] == h)&(numpy.abs(metArray1[:,-2]) < 100))[0]
2142 metHeight = metArray1[indH,:]
2175 metHeight = metArray1[indH,:]
2143 if metHeight.shape[0] >= 2:
2176 if metHeight.shape[0] >= 2:
2144 velAux = numpy.asmatrix(metHeight[:,-2]).T #Radial Velocities
2177 velAux = numpy.asmatrix(metHeight[:,-2]).T #Radial Velocities
2145 iazim = metHeight[:,1].astype(int)
2178 iazim = metHeight[:,1].astype(int)
2146 azimAux = numpy.asmatrix(azimuth1[iazim]).T #Azimuths
2179 azimAux = numpy.asmatrix(azimuth1[iazim]).T #Azimuths
2147 A = numpy.hstack((numpy.cos(azimAux),numpy.sin(azimAux)))
2180 A = numpy.hstack((numpy.cos(azimAux),numpy.sin(azimAux)))
2148 A = numpy.asmatrix(A)
2181 A = numpy.asmatrix(A)
2149 A1 = numpy.linalg.pinv(A.transpose()*A)*A.transpose()
2182 A1 = numpy.linalg.pinv(A.transpose()*A)*A.transpose()
2150 velHor = numpy.dot(A1,velAux)
2183 velHor = numpy.dot(A1,velAux)
2151
2184
2152 velEst[i,:] = numpy.squeeze(velHor)
2185 velEst[i,:] = numpy.squeeze(velHor)
2153 return velEst
2186 return velEst
2154
2187
2155 def __getPhaseSlope(self, metArray, heightList, timeList):
2188 def __getPhaseSlope(self, metArray, heightList, timeList):
2156 meteorList = []
2189 meteorList = []
2157 #utctime sec1 height SNR velRad ph0 ph1 ph2 coh0 coh1 coh2
2190 #utctime sec1 height SNR velRad ph0 ph1 ph2 coh0 coh1 coh2
2158 #Putting back together the meteor matrix
2191 #Putting back together the meteor matrix
2159 utctime = metArray[:,0]
2192 utctime = metArray[:,0]
2160 uniqueTime = numpy.unique(utctime)
2193 uniqueTime = numpy.unique(utctime)
2161
2194
2162 phaseDerThresh = 0.5
2195 phaseDerThresh = 0.5
2163 ippSeconds = timeList[1] - timeList[0]
2196 ippSeconds = timeList[1] - timeList[0]
2164 sec = numpy.where(timeList>1)[0][0]
2197 sec = numpy.where(timeList>1)[0][0]
2165 nPairs = metArray.shape[1] - 6
2198 nPairs = metArray.shape[1] - 6
2166 nHeights = len(heightList)
2199 nHeights = len(heightList)
2167
2200
2168 for t in uniqueTime:
2201 for t in uniqueTime:
2169 metArray1 = metArray[utctime==t,:]
2202 metArray1 = metArray[utctime==t,:]
2170 # phaseDerThresh = numpy.pi/4 #reducir Phase thresh
2203 # phaseDerThresh = numpy.pi/4 #reducir Phase thresh
2171 tmet = metArray1[:,1].astype(int)
2204 tmet = metArray1[:,1].astype(int)
2172 hmet = metArray1[:,2].astype(int)
2205 hmet = metArray1[:,2].astype(int)
2173
2206
2174 metPhase = numpy.zeros((nPairs, heightList.size, timeList.size - 1))
2207 metPhase = numpy.zeros((nPairs, heightList.size, timeList.size - 1))
2175 metPhase[:,:] = numpy.nan
2208 metPhase[:,:] = numpy.nan
2176 metPhase[:,hmet,tmet] = metArray1[:,6:].T
2209 metPhase[:,hmet,tmet] = metArray1[:,6:].T
2177
2210
2178 #Delete short trails
2211 #Delete short trails
2179 metBool = ~numpy.isnan(metPhase[0,:,:])
2212 metBool = ~numpy.isnan(metPhase[0,:,:])
2180 heightVect = numpy.sum(metBool, axis = 1)
2213 heightVect = numpy.sum(metBool, axis = 1)
2181 metBool[heightVect<sec,:] = False
2214 metBool[heightVect<sec,:] = False
2182 metPhase[:,heightVect<sec,:] = numpy.nan
2215 metPhase[:,heightVect<sec,:] = numpy.nan
2183
2216
2184 #Derivative
2217 #Derivative
2185 metDer = numpy.abs(metPhase[:,:,1:] - metPhase[:,:,:-1])
2218 metDer = numpy.abs(metPhase[:,:,1:] - metPhase[:,:,:-1])
2186 phDerAux = numpy.dstack((numpy.full((nPairs,nHeights,1), False, dtype=bool),metDer > phaseDerThresh))
2219 phDerAux = numpy.dstack((numpy.full((nPairs,nHeights,1), False, dtype=bool),metDer > phaseDerThresh))
2187 metPhase[phDerAux] = numpy.nan
2220 metPhase[phDerAux] = numpy.nan
2188
2221
2189 #--------------------------METEOR DETECTION -----------------------------------------
2222 #--------------------------METEOR DETECTION -----------------------------------------
2190 indMet = numpy.where(numpy.any(metBool,axis=1))[0]
2223 indMet = numpy.where(numpy.any(metBool,axis=1))[0]
2191
2224
2192 for p in numpy.arange(nPairs):
2225 for p in numpy.arange(nPairs):
2193 phase = metPhase[p,:,:]
2226 phase = metPhase[p,:,:]
2194 phDer = metDer[p,:,:]
2227 phDer = metDer[p,:,:]
2195
2228
2196 for h in indMet:
2229 for h in indMet:
2197 height = heightList[h]
2230 height = heightList[h]
2198 phase1 = phase[h,:] #82
2231 phase1 = phase[h,:] #82
2199 phDer1 = phDer[h,:]
2232 phDer1 = phDer[h,:]
2200
2233
2201 phase1[~numpy.isnan(phase1)] = numpy.unwrap(phase1[~numpy.isnan(phase1)]) #Unwrap
2234 phase1[~numpy.isnan(phase1)] = numpy.unwrap(phase1[~numpy.isnan(phase1)]) #Unwrap
2202
2235
2203 indValid = numpy.where(~numpy.isnan(phase1))[0]
2236 indValid = numpy.where(~numpy.isnan(phase1))[0]
2204 initMet = indValid[0]
2237 initMet = indValid[0]
2205 endMet = 0
2238 endMet = 0
2206
2239
2207 for i in range(len(indValid)-1):
2240 for i in range(len(indValid)-1):
2208
2241
2209 #Time difference
2242 #Time difference
2210 inow = indValid[i]
2243 inow = indValid[i]
2211 inext = indValid[i+1]
2244 inext = indValid[i+1]
2212 idiff = inext - inow
2245 idiff = inext - inow
2213 #Phase difference
2246 #Phase difference
2214 phDiff = numpy.abs(phase1[inext] - phase1[inow])
2247 phDiff = numpy.abs(phase1[inext] - phase1[inow])
2215
2248
2216 if idiff>sec or phDiff>numpy.pi/4 or inext==indValid[-1]: #End of Meteor
2249 if idiff>sec or phDiff>numpy.pi/4 or inext==indValid[-1]: #End of Meteor
2217 sizeTrail = inow - initMet + 1
2250 sizeTrail = inow - initMet + 1
2218 if sizeTrail>3*sec: #Too short meteors
2251 if sizeTrail>3*sec: #Too short meteors
2219 x = numpy.arange(initMet,inow+1)*ippSeconds
2252 x = numpy.arange(initMet,inow+1)*ippSeconds
2220 y = phase1[initMet:inow+1]
2253 y = phase1[initMet:inow+1]
2221 ynnan = ~numpy.isnan(y)
2254 ynnan = ~numpy.isnan(y)
2222 x = x[ynnan]
2255 x = x[ynnan]
2223 y = y[ynnan]
2256 y = y[ynnan]
2224 slope, intercept, r_value, p_value, std_err = stats.linregress(x,y)
2257 slope, intercept, r_value, p_value, std_err = stats.linregress(x,y)
2225 ylin = x*slope + intercept
2258 ylin = x*slope + intercept
2226 rsq = r_value**2
2259 rsq = r_value**2
2227 if rsq > 0.5:
2260 if rsq > 0.5:
2228 vel = slope#*height*1000/(k*d)
2261 vel = slope#*height*1000/(k*d)
2229 estAux = numpy.array([utctime,p,height, vel, rsq])
2262 estAux = numpy.array([utctime,p,height, vel, rsq])
2230 meteorList.append(estAux)
2263 meteorList.append(estAux)
2231 initMet = inext
2264 initMet = inext
2232 metArray2 = numpy.array(meteorList)
2265 metArray2 = numpy.array(meteorList)
2233
2266
2234 return metArray2
2267 return metArray2
2235
2268
2236 def __calculateAzimuth1(self, rx_location, pairslist, azimuth0):
2269 def __calculateAzimuth1(self, rx_location, pairslist, azimuth0):
2237
2270
2238 azimuth1 = numpy.zeros(len(pairslist))
2271 azimuth1 = numpy.zeros(len(pairslist))
2239 dist = numpy.zeros(len(pairslist))
2272 dist = numpy.zeros(len(pairslist))
2240
2273
2241 for i in range(len(rx_location)):
2274 for i in range(len(rx_location)):
2242 ch0 = pairslist[i][0]
2275 ch0 = pairslist[i][0]
2243 ch1 = pairslist[i][1]
2276 ch1 = pairslist[i][1]
2244
2277
2245 diffX = rx_location[ch0][0] - rx_location[ch1][0]
2278 diffX = rx_location[ch0][0] - rx_location[ch1][0]
2246 diffY = rx_location[ch0][1] - rx_location[ch1][1]
2279 diffY = rx_location[ch0][1] - rx_location[ch1][1]
2247 azimuth1[i] = numpy.arctan2(diffY,diffX)*180/numpy.pi
2280 azimuth1[i] = numpy.arctan2(diffY,diffX)*180/numpy.pi
2248 dist[i] = numpy.sqrt(diffX**2 + diffY**2)
2281 dist[i] = numpy.sqrt(diffX**2 + diffY**2)
2249
2282
2250 azimuth1 -= azimuth0
2283 azimuth1 -= azimuth0
2251 return azimuth1, dist
2284 return azimuth1, dist
2252
2285
2253 def techniqueNSM_DBS(self, **kwargs):
2286 def techniqueNSM_DBS(self, **kwargs):
2254 metArray = kwargs['metArray']
2287 metArray = kwargs['metArray']
2255 heightList = kwargs['heightList']
2288 heightList = kwargs['heightList']
2256 timeList = kwargs['timeList']
2289 timeList = kwargs['timeList']
2257 zenithList = kwargs['zenithList']
2290 zenithList = kwargs['zenithList']
2258 nChan = numpy.max(cmet) + 1
2291 nChan = numpy.max(cmet) + 1
2259 nHeights = len(heightList)
2292 nHeights = len(heightList)
2260
2293
2261 utctime = metArray[:,0]
2294 utctime = metArray[:,0]
2262 cmet = metArray[:,1]
2295 cmet = metArray[:,1]
2263 hmet = metArray1[:,3].astype(int)
2296 hmet = metArray1[:,3].astype(int)
2264 h1met = heightList[hmet]*zenithList[cmet]
2297 h1met = heightList[hmet]*zenithList[cmet]
2265 vmet = metArray1[:,5]
2298 vmet = metArray1[:,5]
2266
2299
2267 for i in range(nHeights - 1):
2300 for i in range(nHeights - 1):
2268 hmin = heightList[i]
2301 hmin = heightList[i]
2269 hmax = heightList[i + 1]
2302 hmax = heightList[i + 1]
2270
2303
2271 vthisH = vmet[(h1met>=hmin) & (h1met<hmax)]
2304 vthisH = vmet[(h1met>=hmin) & (h1met<hmax)]
2272
2305
2273
2306
2274
2307
2275 return data_output
2308 return data_output
2276
2309
2277 def run(self, dataOut, technique, positionY, positionX, azimuth, **kwargs):
2310 def run(self, dataOut, technique, positionY, positionX, azimuth, **kwargs):
2278
2311
2279 param = dataOut.data_param
2312 param = dataOut.data_param
2280 if dataOut.abscissaList != None:
2313 if dataOut.abscissaList != None:
2281 absc = dataOut.abscissaList[:-1]
2314 absc = dataOut.abscissaList[:-1]
2282 noise = dataOut.noise
2315 noise = dataOut.noise
2283 heightList = dataOut.heightList
2316 heightList = dataOut.heightList
2284 SNR = dataOut.data_SNR
2317 SNR = dataOut.data_SNR
2285
2318
2286 if technique == 'DBS':
2319 if technique == 'DBS':
2287
2320
2288 kwargs['velRadial'] = param[:,1,:] #Radial velocity
2321 kwargs['velRadial'] = param[:,1,:] #Radial velocity
2289 kwargs['heightList'] = heightList
2322 kwargs['heightList'] = heightList
2290 kwargs['SNR'] = SNR
2323 kwargs['SNR'] = SNR
2291
2324
2292 dataOut.data_output, dataOut.heightList, dataOut.data_SNR = self.techniqueDBS(kwargs) #DBS Function
2325 dataOut.data_output, dataOut.heightList, dataOut.data_SNR = self.techniqueDBS(kwargs) #DBS Function
2293 dataOut.utctimeInit = dataOut.utctime
2326 dataOut.utctimeInit = dataOut.utctime
2294 dataOut.outputInterval = dataOut.paramInterval
2327 dataOut.outputInterval = dataOut.paramInterval
2295
2328
2296 elif technique == 'SA':
2329 elif technique == 'SA':
2297
2330
2298 #Parameters
2331 #Parameters
2299 # position_x = kwargs['positionX']
2332 # position_x = kwargs['positionX']
2300 # position_y = kwargs['positionY']
2333 # position_y = kwargs['positionY']
2301 # azimuth = kwargs['azimuth']
2334 # azimuth = kwargs['azimuth']
2302 #
2335 #
2303 # if kwargs.has_key('crosspairsList'):
2336 # if kwargs.has_key('crosspairsList'):
2304 # pairs = kwargs['crosspairsList']
2337 # pairs = kwargs['crosspairsList']
2305 # else:
2338 # else:
2306 # pairs = None
2339 # pairs = None
2307 #
2340 #
2308 # if kwargs.has_key('correctFactor'):
2341 # if kwargs.has_key('correctFactor'):
2309 # correctFactor = kwargs['correctFactor']
2342 # correctFactor = kwargs['correctFactor']
2310 # else:
2343 # else:
2311 # correctFactor = 1
2344 # correctFactor = 1
2312
2345
2313 # tau = dataOut.data_param
2346 # tau = dataOut.data_param
2314 # _lambda = dataOut.C/dataOut.frequency
2347 # _lambda = dataOut.C/dataOut.frequency
2315 # pairsList = dataOut.groupList
2348 # pairsList = dataOut.groupList
2316 # nChannels = dataOut.nChannels
2349 # nChannels = dataOut.nChannels
2317
2350
2318 kwargs['groupList'] = dataOut.groupList
2351 kwargs['groupList'] = dataOut.groupList
2319 kwargs['tau'] = dataOut.data_param
2352 kwargs['tau'] = dataOut.data_param
2320 kwargs['_lambda'] = dataOut.C/dataOut.frequency
2353 kwargs['_lambda'] = dataOut.C/dataOut.frequency
2321 # dataOut.data_output = self.techniqueSA(pairs, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, absc, correctFactor)
2354 # dataOut.data_output = self.techniqueSA(pairs, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, absc, correctFactor)
2322 dataOut.data_output = self.techniqueSA(kwargs)
2355 dataOut.data_output = self.techniqueSA(kwargs)
2323 dataOut.utctimeInit = dataOut.utctime
2356 dataOut.utctimeInit = dataOut.utctime
2324 dataOut.outputInterval = dataOut.timeInterval
2357 dataOut.outputInterval = dataOut.timeInterval
2325
2358
2326 elif technique == 'Meteors':
2359 elif technique == 'Meteors':
2327 dataOut.flagNoData = True
2360 dataOut.flagNoData = True
2328 self.__dataReady = False
2361 self.__dataReady = False
2329
2362
2330 if kwargs.has_key('nHours'):
2363 if kwargs.has_key('nHours'):
2331 nHours = kwargs['nHours']
2364 nHours = kwargs['nHours']
2332 else:
2365 else:
2333 nHours = 1
2366 nHours = 1
2334
2367
2335 if kwargs.has_key('meteorsPerBin'):
2368 if kwargs.has_key('meteorsPerBin'):
2336 meteorThresh = kwargs['meteorsPerBin']
2369 meteorThresh = kwargs['meteorsPerBin']
2337 else:
2370 else:
2338 meteorThresh = 6
2371 meteorThresh = 6
2339
2372
2340 if kwargs.has_key('hmin'):
2373 if kwargs.has_key('hmin'):
2341 hmin = kwargs['hmin']
2374 hmin = kwargs['hmin']
2342 else: hmin = 70
2375 else: hmin = 70
2343 if kwargs.has_key('hmax'):
2376 if kwargs.has_key('hmax'):
2344 hmax = kwargs['hmax']
2377 hmax = kwargs['hmax']
2345 else: hmax = 110
2378 else: hmax = 110
2346
2379
2347 dataOut.outputInterval = nHours*3600
2380 dataOut.outputInterval = nHours*3600
2348
2381
2349 if self.__isConfig == False:
2382 if self.__isConfig == False:
2350 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
2383 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
2351 #Get Initial LTC time
2384 #Get Initial LTC time
2352 self.__initime = datetime.datetime.utcfromtimestamp(dataOut.utctime)
2385 self.__initime = datetime.datetime.utcfromtimestamp(dataOut.utctime)
2353 self.__initime = (self.__initime.replace(minute = 0, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
2386 self.__initime = (self.__initime.replace(minute = 0, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
2354
2387
2355 self.__isConfig = True
2388 self.__isConfig = True
2356
2389
2357 if self.__buffer == None:
2390 if self.__buffer == None:
2358 self.__buffer = dataOut.data_param
2391 self.__buffer = dataOut.data_param
2359 self.__firstdata = copy.copy(dataOut)
2392 self.__firstdata = copy.copy(dataOut)
2360
2393
2361 else:
2394 else:
2362 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
2395 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
2363
2396
2364 self.__checkTime(dataOut.utctime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
2397 self.__checkTime(dataOut.utctime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
2365
2398
2366 if self.__dataReady:
2399 if self.__dataReady:
2367 dataOut.utctimeInit = self.__initime
2400 dataOut.utctimeInit = self.__initime
2368
2401
2369 self.__initime += dataOut.outputInterval #to erase time offset
2402 self.__initime += dataOut.outputInterval #to erase time offset
2370
2403
2371 dataOut.data_output, dataOut.heightList = self.techniqueMeteors(self.__buffer, meteorThresh, hmin, hmax)
2404 dataOut.data_output, dataOut.heightList = self.techniqueMeteors(self.__buffer, meteorThresh, hmin, hmax)
2372 dataOut.flagNoData = False
2405 dataOut.flagNoData = False
2373 self.__buffer = None
2406 self.__buffer = None
2374
2407
2375 elif technique == 'Meteors1':
2408 elif technique == 'Meteors1':
2376 dataOut.flagNoData = True
2409 dataOut.flagNoData = True
2377 self.__dataReady = False
2410 self.__dataReady = False
2378
2411
2379 if kwargs.has_key('nMins'):
2412 if kwargs.has_key('nMins'):
2380 nMins = kwargs['nMins']
2413 nMins = kwargs['nMins']
2381 else: nMins = 20
2414 else: nMins = 20
2382 if kwargs.has_key('rx_location'):
2415 if kwargs.has_key('rx_location'):
2383 rx_location = kwargs['rx_location']
2416 rx_location = kwargs['rx_location']
2384 else: rx_location = [(0,1),(1,1),(1,0)]
2417 else: rx_location = [(0,1),(1,1),(1,0)]
2385 if kwargs.has_key('azimuth'):
2418 if kwargs.has_key('azimuth'):
2386 azimuth = kwargs['azimuth']
2419 azimuth = kwargs['azimuth']
2387 else: azimuth = 51
2420 else: azimuth = 51
2388 if kwargs.has_key('dfactor'):
2421 if kwargs.has_key('dfactor'):
2389 dfactor = kwargs['dfactor']
2422 dfactor = kwargs['dfactor']
2390 if kwargs.has_key('mode'):
2423 if kwargs.has_key('mode'):
2391 mode = kwargs['mode']
2424 mode = kwargs['mode']
2392 else: mode = 'SA'
2425 else: mode = 'SA'
2393
2426
2394 #Borrar luego esto
2427 #Borrar luego esto
2395 if dataOut.groupList == None:
2428 if dataOut.groupList == None:
2396 dataOut.groupList = [(0,1),(0,2),(1,2)]
2429 dataOut.groupList = [(0,1),(0,2),(1,2)]
2397 groupList = dataOut.groupList
2430 groupList = dataOut.groupList
2398 C = 3e8
2431 C = 3e8
2399 freq = 50e6
2432 freq = 50e6
2400 lamb = C/freq
2433 lamb = C/freq
2401 k = 2*numpy.pi/lamb
2434 k = 2*numpy.pi/lamb
2402
2435
2403 timeList = dataOut.abscissaList
2436 timeList = dataOut.abscissaList
2404 heightList = dataOut.heightList
2437 heightList = dataOut.heightList
2405
2438
2406 if self.__isConfig == False:
2439 if self.__isConfig == False:
2407 dataOut.outputInterval = nMins*60
2440 dataOut.outputInterval = nMins*60
2408 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
2441 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
2409 #Get Initial LTC time
2442 #Get Initial LTC time
2410 initime = datetime.datetime.utcfromtimestamp(dataOut.utctime)
2443 initime = datetime.datetime.utcfromtimestamp(dataOut.utctime)
2411 minuteAux = initime.minute
2444 minuteAux = initime.minute
2412 minuteNew = int(numpy.floor(minuteAux/nMins)*nMins)
2445 minuteNew = int(numpy.floor(minuteAux/nMins)*nMins)
2413 self.__initime = (initime.replace(minute = minuteNew, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
2446 self.__initime = (initime.replace(minute = minuteNew, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
2414
2447
2415 self.__isConfig = True
2448 self.__isConfig = True
2416
2449
2417 if self.__buffer == None:
2450 if self.__buffer == None:
2418 self.__buffer = dataOut.data_param
2451 self.__buffer = dataOut.data_param
2419 self.__firstdata = copy.copy(dataOut)
2452 self.__firstdata = copy.copy(dataOut)
2420
2453
2421 else:
2454 else:
2422 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
2455 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
2423
2456
2424 self.__checkTime(dataOut.utctime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
2457 self.__checkTime(dataOut.utctime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
2425
2458
2426 if self.__dataReady:
2459 if self.__dataReady:
2427 dataOut.utctimeInit = self.__initime
2460 dataOut.utctimeInit = self.__initime
2428 self.__initime += dataOut.outputInterval #to erase time offset
2461 self.__initime += dataOut.outputInterval #to erase time offset
2429
2462
2430 metArray = self.__buffer
2463 metArray = self.__buffer
2431 if mode == 'SA':
2464 if mode == 'SA':
2432 dataOut.data_output = self.techniqueNSM_SA(rx_location=rx_location, groupList=groupList, azimuth=azimuth, dfactor=dfactor, k=k,metArray=metArray, heightList=heightList,timeList=timeList)
2465 dataOut.data_output = self.techniqueNSM_SA(rx_location=rx_location, groupList=groupList, azimuth=azimuth, dfactor=dfactor, k=k,metArray=metArray, heightList=heightList,timeList=timeList)
2433 elif mode == 'DBS':
2466 elif mode == 'DBS':
2434 dataOut.data_output = self.techniqueNSM_DBS(metArray=metArray,heightList=heightList,timeList=timeList)
2467 dataOut.data_output = self.techniqueNSM_DBS(metArray=metArray,heightList=heightList,timeList=timeList)
2435 dataOut.data_output = dataOut.data_output.T
2468 dataOut.data_output = dataOut.data_output.T
2436 dataOut.flagNoData = False
2469 dataOut.flagNoData = False
2437 self.__buffer = None
2470 self.__buffer = None
2438
2471
2439 return
2472 return
2440
2473
2441 class EWDriftsEstimation(Operation):
2474 class EWDriftsEstimation(Operation):
2442
2475
2443 def __init__(self):
2476 def __init__(self):
2444 Operation.__init__(self)
2477 Operation.__init__(self)
2445
2478
2446 def __correctValues(self, heiRang, phi, velRadial, SNR):
2479 def __correctValues(self, heiRang, phi, velRadial, SNR):
2447 listPhi = phi.tolist()
2480 listPhi = phi.tolist()
2448 maxid = listPhi.index(max(listPhi))
2481 maxid = listPhi.index(max(listPhi))
2449 minid = listPhi.index(min(listPhi))
2482 minid = listPhi.index(min(listPhi))
2450
2483
2451 rango = range(len(phi))
2484 rango = range(len(phi))
2452 # rango = numpy.delete(rango,maxid)
2485 # rango = numpy.delete(rango,maxid)
2453
2486
2454 heiRang1 = heiRang*math.cos(phi[maxid])
2487 heiRang1 = heiRang*math.cos(phi[maxid])
2455 heiRangAux = heiRang*math.cos(phi[minid])
2488 heiRangAux = heiRang*math.cos(phi[minid])
2456 indOut = (heiRang1 < heiRangAux[0]).nonzero()
2489 indOut = (heiRang1 < heiRangAux[0]).nonzero()
2457 heiRang1 = numpy.delete(heiRang1,indOut)
2490 heiRang1 = numpy.delete(heiRang1,indOut)
2458
2491
2459 velRadial1 = numpy.zeros([len(phi),len(heiRang1)])
2492 velRadial1 = numpy.zeros([len(phi),len(heiRang1)])
2460 SNR1 = numpy.zeros([len(phi),len(heiRang1)])
2493 SNR1 = numpy.zeros([len(phi),len(heiRang1)])
2461
2494
2462 for i in rango:
2495 for i in rango:
2463 x = heiRang*math.cos(phi[i])
2496 x = heiRang*math.cos(phi[i])
2464 y1 = velRadial[i,:]
2497 y1 = velRadial[i,:]
2465 f1 = interpolate.interp1d(x,y1,kind = 'cubic')
2498 f1 = interpolate.interp1d(x,y1,kind = 'cubic')
2466
2499
2467 x1 = heiRang1
2500 x1 = heiRang1
2468 y11 = f1(x1)
2501 y11 = f1(x1)
2469
2502
2470 y2 = SNR[i,:]
2503 y2 = SNR[i,:]
2471 f2 = interpolate.interp1d(x,y2,kind = 'cubic')
2504 f2 = interpolate.interp1d(x,y2,kind = 'cubic')
2472 y21 = f2(x1)
2505 y21 = f2(x1)
2473
2506
2474 velRadial1[i,:] = y11
2507 velRadial1[i,:] = y11
2475 SNR1[i,:] = y21
2508 SNR1[i,:] = y21
2476
2509
2477 return heiRang1, velRadial1, SNR1
2510 return heiRang1, velRadial1, SNR1
2478
2511
2479 def run(self, dataOut, zenith, zenithCorrection):
2512 def run(self, dataOut, zenith, zenithCorrection):
2480 heiRang = dataOut.heightList
2513 heiRang = dataOut.heightList
2481 velRadial = dataOut.data_param[:,3,:]
2514 velRadial = dataOut.data_param[:,3,:]
2482 SNR = dataOut.data_SNR
2515 SNR = dataOut.data_SNR
2483
2516
2484 zenith = numpy.array(zenith)
2517 zenith = numpy.array(zenith)
2485 zenith -= zenithCorrection
2518 zenith -= zenithCorrection
2486 zenith *= numpy.pi/180
2519 zenith *= numpy.pi/180
2487
2520
2488 heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, numpy.abs(zenith), velRadial, SNR)
2521 heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, numpy.abs(zenith), velRadial, SNR)
2489
2522
2490 alp = zenith[0]
2523 alp = zenith[0]
2491 bet = zenith[1]
2524 bet = zenith[1]
2492
2525
2493 w_w = velRadial1[0,:]
2526 w_w = velRadial1[0,:]
2494 w_e = velRadial1[1,:]
2527 w_e = velRadial1[1,:]
2495
2528
2496 w = (w_w*numpy.sin(bet) - w_e*numpy.sin(alp))/(numpy.cos(alp)*numpy.sin(bet) - numpy.cos(bet)*numpy.sin(alp))
2529 w = (w_w*numpy.sin(bet) - w_e*numpy.sin(alp))/(numpy.cos(alp)*numpy.sin(bet) - numpy.cos(bet)*numpy.sin(alp))
2497 u = (w_w*numpy.cos(bet) - w_e*numpy.cos(alp))/(numpy.sin(alp)*numpy.cos(bet) - numpy.sin(bet)*numpy.cos(alp))
2530 u = (w_w*numpy.cos(bet) - w_e*numpy.cos(alp))/(numpy.sin(alp)*numpy.cos(bet) - numpy.sin(bet)*numpy.cos(alp))
2498
2531
2499 winds = numpy.vstack((u,w))
2532 winds = numpy.vstack((u,w))
2500
2533
2501 dataOut.heightList = heiRang1
2534 dataOut.heightList = heiRang1
2502 dataOut.data_output = winds
2535 dataOut.data_output = winds
2503 dataOut.data_SNR = SNR1
2536 dataOut.data_SNR = SNR1
2504
2537
2505 dataOut.utctimeInit = dataOut.utctime
2538 dataOut.utctimeInit = dataOut.utctime
2506 dataOut.outputInterval = dataOut.timeInterval
2539 dataOut.outputInterval = dataOut.timeInterval
2507 return
2540 return
2508
2541
2509 #--------------- Non Specular Meteor ----------------
2542 #--------------- Non Specular Meteor ----------------
2510
2543
2511 class NonSpecularMeteorDetection(Operation):
2544 class NonSpecularMeteorDetection(Operation):
2512
2545
2513 def run(self, mode, SNRthresh=8, phaseDerThresh=0.5, cohThresh=0.8, allData = False):
2546 def run(self, mode, SNRthresh=8, phaseDerThresh=0.5, cohThresh=0.8, allData = False):
2514 data_acf = self.dataOut.data_pre[0]
2547 data_acf = self.dataOut.data_pre[0]
2515 data_ccf = self.dataOut.data_pre[1]
2548 data_ccf = self.dataOut.data_pre[1]
2516
2549
2517 lamb = self.dataOut.C/self.dataOut.frequency
2550 lamb = self.dataOut.C/self.dataOut.frequency
2518 tSamp = self.dataOut.ippSeconds*self.dataOut.nCohInt
2551 tSamp = self.dataOut.ippSeconds*self.dataOut.nCohInt
2519 paramInterval = self.dataOut.paramInterval
2552 paramInterval = self.dataOut.paramInterval
2520
2553
2521 nChannels = data_acf.shape[0]
2554 nChannels = data_acf.shape[0]
2522 nLags = data_acf.shape[1]
2555 nLags = data_acf.shape[1]
2523 nProfiles = data_acf.shape[2]
2556 nProfiles = data_acf.shape[2]
2524 nHeights = self.dataOut.nHeights
2557 nHeights = self.dataOut.nHeights
2525 nCohInt = self.dataOut.nCohInt
2558 nCohInt = self.dataOut.nCohInt
2526 sec = numpy.round(nProfiles/self.dataOut.paramInterval)
2559 sec = numpy.round(nProfiles/self.dataOut.paramInterval)
2527 heightList = self.dataOut.heightList
2560 heightList = self.dataOut.heightList
2528 ippSeconds = self.dataOut.ippSeconds*self.dataOut.nCohInt*self.dataOut.nAvg
2561 ippSeconds = self.dataOut.ippSeconds*self.dataOut.nCohInt*self.dataOut.nAvg
2529 utctime = self.dataOut.utctime
2562 utctime = self.dataOut.utctime
2530
2563
2531 self.dataOut.abscissaList = numpy.arange(0,paramInterval+ippSeconds,ippSeconds)
2564 self.dataOut.abscissaList = numpy.arange(0,paramInterval+ippSeconds,ippSeconds)
2532
2565
2533 #------------------------ SNR --------------------------------------
2566 #------------------------ SNR --------------------------------------
2534 power = data_acf[:,0,:,:].real
2567 power = data_acf[:,0,:,:].real
2535 noise = numpy.zeros(nChannels)
2568 noise = numpy.zeros(nChannels)
2536 SNR = numpy.zeros(power.shape)
2569 SNR = numpy.zeros(power.shape)
2537 for i in range(nChannels):
2570 for i in range(nChannels):
2538 noise[i] = hildebrand_sekhon(power[i,:], nCohInt)
2571 noise[i] = hildebrand_sekhon(power[i,:], nCohInt)
2539 SNR[i] = (power[i]-noise[i])/noise[i]
2572 SNR[i] = (power[i]-noise[i])/noise[i]
2540 SNRm = numpy.nanmean(SNR, axis = 0)
2573 SNRm = numpy.nanmean(SNR, axis = 0)
2541 SNRdB = 10*numpy.log10(SNR)
2574 SNRdB = 10*numpy.log10(SNR)
2542
2575
2543 if mode == 'SA':
2576 if mode == 'SA':
2544 nPairs = data_ccf.shape[0]
2577 nPairs = data_ccf.shape[0]
2545 #---------------------- Coherence and Phase --------------------------
2578 #---------------------- Coherence and Phase --------------------------
2546 phase = numpy.zeros(data_ccf[:,0,:,:].shape)
2579 phase = numpy.zeros(data_ccf[:,0,:,:].shape)
2547 # phase1 = numpy.copy(phase)
2580 # phase1 = numpy.copy(phase)
2548 coh1 = numpy.zeros(data_ccf[:,0,:,:].shape)
2581 coh1 = numpy.zeros(data_ccf[:,0,:,:].shape)
2549
2582
2550 for p in range(nPairs):
2583 for p in range(nPairs):
2551 ch0 = self.dataOut.groupList[p][0]
2584 ch0 = self.dataOut.groupList[p][0]
2552 ch1 = self.dataOut.groupList[p][1]
2585 ch1 = self.dataOut.groupList[p][1]
2553 ccf = data_ccf[p,0,:,:]/numpy.sqrt(data_acf[ch0,0,:,:]*data_acf[ch1,0,:,:])
2586 ccf = data_ccf[p,0,:,:]/numpy.sqrt(data_acf[ch0,0,:,:]*data_acf[ch1,0,:,:])
2554 phase[p,:,:] = ndimage.median_filter(numpy.angle(ccf), size = (5,1)) #median filter
2587 phase[p,:,:] = ndimage.median_filter(numpy.angle(ccf), size = (5,1)) #median filter
2555 # phase1[p,:,:] = numpy.angle(ccf) #median filter
2588 # phase1[p,:,:] = numpy.angle(ccf) #median filter
2556 coh1[p,:,:] = ndimage.median_filter(numpy.abs(ccf), 5) #median filter
2589 coh1[p,:,:] = ndimage.median_filter(numpy.abs(ccf), 5) #median filter
2557 # coh1[p,:,:] = numpy.abs(ccf) #median filter
2590 # coh1[p,:,:] = numpy.abs(ccf) #median filter
2558 coh = numpy.nanmax(coh1, axis = 0)
2591 coh = numpy.nanmax(coh1, axis = 0)
2559 # struc = numpy.ones((5,1))
2592 # struc = numpy.ones((5,1))
2560 # coh = ndimage.morphology.grey_dilation(coh, size=(10,1))
2593 # coh = ndimage.morphology.grey_dilation(coh, size=(10,1))
2561 #---------------------- Radial Velocity ----------------------------
2594 #---------------------- Radial Velocity ----------------------------
2562 phaseAux = numpy.mean(numpy.angle(data_acf[:,1,:,:]), axis = 0)
2595 phaseAux = numpy.mean(numpy.angle(data_acf[:,1,:,:]), axis = 0)
2563 velRad = phaseAux*lamb/(4*numpy.pi*tSamp)
2596 velRad = phaseAux*lamb/(4*numpy.pi*tSamp)
2564
2597
2565 if allData:
2598 if allData:
2566 boolMetFin = ~numpy.isnan(SNRm)
2599 boolMetFin = ~numpy.isnan(SNRm)
2567 # coh[:-1,:] = numpy.nanmean(numpy.abs(phase[:,1:,:] - phase[:,:-1,:]),axis=0)
2600 # coh[:-1,:] = numpy.nanmean(numpy.abs(phase[:,1:,:] - phase[:,:-1,:]),axis=0)
2568 else:
2601 else:
2569 #------------------------ Meteor mask ---------------------------------
2602 #------------------------ Meteor mask ---------------------------------
2570 # #SNR mask
2603 # #SNR mask
2571 # boolMet = (SNRdB>SNRthresh)#|(~numpy.isnan(SNRdB))
2604 # boolMet = (SNRdB>SNRthresh)#|(~numpy.isnan(SNRdB))
2572 #
2605 #
2573 # #Erase small objects
2606 # #Erase small objects
2574 # boolMet1 = self.__erase_small(boolMet, 2*sec, 5)
2607 # boolMet1 = self.__erase_small(boolMet, 2*sec, 5)
2575 #
2608 #
2576 # auxEEJ = numpy.sum(boolMet1,axis=0)
2609 # auxEEJ = numpy.sum(boolMet1,axis=0)
2577 # indOver = auxEEJ>nProfiles*0.8 #Use this later
2610 # indOver = auxEEJ>nProfiles*0.8 #Use this later
2578 # indEEJ = numpy.where(indOver)[0]
2611 # indEEJ = numpy.where(indOver)[0]
2579 # indNEEJ = numpy.where(~indOver)[0]
2612 # indNEEJ = numpy.where(~indOver)[0]
2580 #
2613 #
2581 # boolMetFin = boolMet1
2614 # boolMetFin = boolMet1
2582 #
2615 #
2583 # if indEEJ.size > 0:
2616 # if indEEJ.size > 0:
2584 # boolMet1[:,indEEJ] = False #Erase heights with EEJ
2617 # boolMet1[:,indEEJ] = False #Erase heights with EEJ
2585 #
2618 #
2586 # boolMet2 = coh > cohThresh
2619 # boolMet2 = coh > cohThresh
2587 # boolMet2 = self.__erase_small(boolMet2, 2*sec,5)
2620 # boolMet2 = self.__erase_small(boolMet2, 2*sec,5)
2588 #
2621 #
2589 # #Final Meteor mask
2622 # #Final Meteor mask
2590 # boolMetFin = boolMet1|boolMet2
2623 # boolMetFin = boolMet1|boolMet2
2591
2624
2592 #Coherence mask
2625 #Coherence mask
2593 boolMet1 = coh > 0.75
2626 boolMet1 = coh > 0.75
2594 struc = numpy.ones((30,1))
2627 struc = numpy.ones((30,1))
2595 boolMet1 = ndimage.morphology.binary_dilation(boolMet1, structure=struc)
2628 boolMet1 = ndimage.morphology.binary_dilation(boolMet1, structure=struc)
2596
2629
2597 #Derivative mask
2630 #Derivative mask
2598 derPhase = numpy.nanmean(numpy.abs(phase[:,1:,:] - phase[:,:-1,:]),axis=0)
2631 derPhase = numpy.nanmean(numpy.abs(phase[:,1:,:] - phase[:,:-1,:]),axis=0)
2599 boolMet2 = derPhase < 0.2
2632 boolMet2 = derPhase < 0.2
2600 # boolMet2 = ndimage.morphology.binary_opening(boolMet2)
2633 # boolMet2 = ndimage.morphology.binary_opening(boolMet2)
2601 # boolMet2 = ndimage.morphology.binary_closing(boolMet2, structure = numpy.ones((10,1)))
2634 # boolMet2 = ndimage.morphology.binary_closing(boolMet2, structure = numpy.ones((10,1)))
2602 boolMet2 = ndimage.median_filter(boolMet2,size=5)
2635 boolMet2 = ndimage.median_filter(boolMet2,size=5)
2603 boolMet2 = numpy.vstack((boolMet2,numpy.full((1,nHeights), True, dtype=bool)))
2636 boolMet2 = numpy.vstack((boolMet2,numpy.full((1,nHeights), True, dtype=bool)))
2604 # #Final mask
2637 # #Final mask
2605 # boolMetFin = boolMet2
2638 # boolMetFin = boolMet2
2606 boolMetFin = boolMet1&boolMet2
2639 boolMetFin = boolMet1&boolMet2
2607 # boolMetFin = ndimage.morphology.binary_dilation(boolMetFin)
2640 # boolMetFin = ndimage.morphology.binary_dilation(boolMetFin)
2608 #Creating data_param
2641 #Creating data_param
2609 coordMet = numpy.where(boolMetFin)
2642 coordMet = numpy.where(boolMetFin)
2610
2643
2611 tmet = coordMet[0]
2644 tmet = coordMet[0]
2612 hmet = coordMet[1]
2645 hmet = coordMet[1]
2613
2646
2614 data_param = numpy.zeros((tmet.size, 6 + nPairs))
2647 data_param = numpy.zeros((tmet.size, 6 + nPairs))
2615 data_param[:,0] = utctime
2648 data_param[:,0] = utctime
2616 data_param[:,1] = tmet
2649 data_param[:,1] = tmet
2617 data_param[:,2] = hmet
2650 data_param[:,2] = hmet
2618 data_param[:,3] = SNRm[tmet,hmet]
2651 data_param[:,3] = SNRm[tmet,hmet]
2619 data_param[:,4] = velRad[tmet,hmet]
2652 data_param[:,4] = velRad[tmet,hmet]
2620 data_param[:,5] = coh[tmet,hmet]
2653 data_param[:,5] = coh[tmet,hmet]
2621 data_param[:,6:] = phase[:,tmet,hmet].T
2654 data_param[:,6:] = phase[:,tmet,hmet].T
2622
2655
2623 elif mode == 'DBS':
2656 elif mode == 'DBS':
2624 self.dataOut.groupList = numpy.arange(nChannels)
2657 self.dataOut.groupList = numpy.arange(nChannels)
2625
2658
2626 #Radial Velocities
2659 #Radial Velocities
2627 # phase = numpy.angle(data_acf[:,1,:,:])
2660 # phase = numpy.angle(data_acf[:,1,:,:])
2628 phase = ndimage.median_filter(numpy.angle(data_acf[:,1,:,:]), size = (1,5,1))
2661 phase = ndimage.median_filter(numpy.angle(data_acf[:,1,:,:]), size = (1,5,1))
2629 velRad = phase*lamb/(4*numpy.pi*tSamp)
2662 velRad = phase*lamb/(4*numpy.pi*tSamp)
2630
2663
2631 #Spectral width
2664 #Spectral width
2632 acf1 = ndimage.median_filter(numpy.abs(data_acf[:,1,:,:]), size = (1,5,1))
2665 acf1 = ndimage.median_filter(numpy.abs(data_acf[:,1,:,:]), size = (1,5,1))
2633 acf2 = ndimage.median_filter(numpy.abs(data_acf[:,2,:,:]), size = (1,5,1))
2666 acf2 = ndimage.median_filter(numpy.abs(data_acf[:,2,:,:]), size = (1,5,1))
2634
2667
2635 spcWidth = (lamb/(2*numpy.sqrt(6)*numpy.pi*tSamp))*numpy.sqrt(numpy.log(acf1/acf2))
2668 spcWidth = (lamb/(2*numpy.sqrt(6)*numpy.pi*tSamp))*numpy.sqrt(numpy.log(acf1/acf2))
2636 # velRad = ndimage.median_filter(velRad, size = (1,5,1))
2669 # velRad = ndimage.median_filter(velRad, size = (1,5,1))
2637 if allData:
2670 if allData:
2638 boolMetFin = ~numpy.isnan(SNRdB)
2671 boolMetFin = ~numpy.isnan(SNRdB)
2639 else:
2672 else:
2640 #SNR
2673 #SNR
2641 boolMet1 = (SNRdB>SNRthresh) #SNR mask
2674 boolMet1 = (SNRdB>SNRthresh) #SNR mask
2642 boolMet1 = ndimage.median_filter(boolMet1, size=(1,5,5))
2675 boolMet1 = ndimage.median_filter(boolMet1, size=(1,5,5))
2643
2676
2644 #Radial velocity
2677 #Radial velocity
2645 boolMet2 = numpy.abs(velRad) < 30
2678 boolMet2 = numpy.abs(velRad) < 30
2646 boolMet2 = ndimage.median_filter(boolMet2, (1,5,5))
2679 boolMet2 = ndimage.median_filter(boolMet2, (1,5,5))
2647
2680
2648 #Spectral Width
2681 #Spectral Width
2649 boolMet3 = spcWidth < 30
2682 boolMet3 = spcWidth < 30
2650 boolMet3 = ndimage.median_filter(boolMet3, (1,5,5))
2683 boolMet3 = ndimage.median_filter(boolMet3, (1,5,5))
2651 # boolMetFin = self.__erase_small(boolMet1, 10,5)
2684 # boolMetFin = self.__erase_small(boolMet1, 10,5)
2652 boolMetFin = boolMet1&boolMet2&boolMet3
2685 boolMetFin = boolMet1&boolMet2&boolMet3
2653
2686
2654 #Creating data_param
2687 #Creating data_param
2655 coordMet = numpy.where(boolMetFin)
2688 coordMet = numpy.where(boolMetFin)
2656
2689
2657 cmet = coordMet[0]
2690 cmet = coordMet[0]
2658 tmet = coordMet[1]
2691 tmet = coordMet[1]
2659 hmet = coordMet[2]
2692 hmet = coordMet[2]
2660
2693
2661 data_param = numpy.zeros((tmet.size, 7))
2694 data_param = numpy.zeros((tmet.size, 7))
2662 data_param[:,0] = utctime
2695 data_param[:,0] = utctime
2663 data_param[:,1] = cmet
2696 data_param[:,1] = cmet
2664 data_param[:,2] = tmet
2697 data_param[:,2] = tmet
2665 data_param[:,3] = hmet
2698 data_param[:,3] = hmet
2666 data_param[:,4] = SNR[cmet,tmet,hmet].T
2699 data_param[:,4] = SNR[cmet,tmet,hmet].T
2667 data_param[:,5] = velRad[cmet,tmet,hmet].T
2700 data_param[:,5] = velRad[cmet,tmet,hmet].T
2668 data_param[:,6] = spcWidth[cmet,tmet,hmet].T
2701 data_param[:,6] = spcWidth[cmet,tmet,hmet].T
2669
2702
2670 # self.dataOut.data_param = data_int
2703 # self.dataOut.data_param = data_int
2671 if len(data_param) == 0:
2704 if len(data_param) == 0:
2672 self.dataOut.flagNoData = True
2705 self.dataOut.flagNoData = True
2673 else:
2706 else:
2674 self.dataOut.data_param = data_param
2707 self.dataOut.data_param = data_param
2675
2708
2676 def __erase_small(self, binArray, threshX, threshY):
2709 def __erase_small(self, binArray, threshX, threshY):
2677 labarray, numfeat = ndimage.measurements.label(binArray)
2710 labarray, numfeat = ndimage.measurements.label(binArray)
2678 binArray1 = numpy.copy(binArray)
2711 binArray1 = numpy.copy(binArray)
2679
2712
2680 for i in range(1,numfeat + 1):
2713 for i in range(1,numfeat + 1):
2681 auxBin = (labarray==i)
2714 auxBin = (labarray==i)
2682 auxSize = auxBin.sum()
2715 auxSize = auxBin.sum()
2683
2716
2684 x,y = numpy.where(auxBin)
2717 x,y = numpy.where(auxBin)
2685 widthX = x.max() - x.min()
2718 widthX = x.max() - x.min()
2686 widthY = y.max() - y.min()
2719 widthY = y.max() - y.min()
2687
2720
2688 #width X: 3 seg -> 12.5*3
2721 #width X: 3 seg -> 12.5*3
2689 #width Y:
2722 #width Y:
2690
2723
2691 if (auxSize < 50) or (widthX < threshX) or (widthY < threshY):
2724 if (auxSize < 50) or (widthX < threshX) or (widthY < threshY):
2692 binArray1[auxBin] = False
2725 binArray1[auxBin] = False
2693
2726
2694 return binArray1
2727 return binArray1
2695
2728
2696 #--------------- Specular Meteor ----------------
2729 #--------------- Specular Meteor ----------------
2697
2730
2698 class SMDetection(Operation):
2731 class SMDetection(Operation):
2699 '''
2732 '''
2700 Function DetectMeteors()
2733 Function DetectMeteors()
2701 Project developed with paper:
2734 Project developed with paper:
2702 HOLDSWORTH ET AL. 2004
2735 HOLDSWORTH ET AL. 2004
2703
2736
2704 Input:
2737 Input:
2705 self.dataOut.data_pre
2738 self.dataOut.data_pre
2706
2739
2707 centerReceiverIndex: From the channels, which is the center receiver
2740 centerReceiverIndex: From the channels, which is the center receiver
2708
2741
2709 hei_ref: Height reference for the Beacon signal extraction
2742 hei_ref: Height reference for the Beacon signal extraction
2710 tauindex:
2743 tauindex:
2711 predefinedPhaseShifts: Predefined phase offset for the voltge signals
2744 predefinedPhaseShifts: Predefined phase offset for the voltge signals
2712
2745
2713 cohDetection: Whether to user Coherent detection or not
2746 cohDetection: Whether to user Coherent detection or not
2714 cohDet_timeStep: Coherent Detection calculation time step
2747 cohDet_timeStep: Coherent Detection calculation time step
2715 cohDet_thresh: Coherent Detection phase threshold to correct phases
2748 cohDet_thresh: Coherent Detection phase threshold to correct phases
2716
2749
2717 noise_timeStep: Noise calculation time step
2750 noise_timeStep: Noise calculation time step
2718 noise_multiple: Noise multiple to define signal threshold
2751 noise_multiple: Noise multiple to define signal threshold
2719
2752
2720 multDet_timeLimit: Multiple Detection Removal time limit in seconds
2753 multDet_timeLimit: Multiple Detection Removal time limit in seconds
2721 multDet_rangeLimit: Multiple Detection Removal range limit in km
2754 multDet_rangeLimit: Multiple Detection Removal range limit in km
2722
2755
2723 phaseThresh: Maximum phase difference between receiver to be consider a meteor
2756 phaseThresh: Maximum phase difference between receiver to be consider a meteor
2724 SNRThresh: Minimum SNR threshold of the meteor signal to be consider a meteor
2757 SNRThresh: Minimum SNR threshold of the meteor signal to be consider a meteor
2725
2758
2726 hmin: Minimum Height of the meteor to use it in the further wind estimations
2759 hmin: Minimum Height of the meteor to use it in the further wind estimations
2727 hmax: Maximum Height of the meteor to use it in the further wind estimations
2760 hmax: Maximum Height of the meteor to use it in the further wind estimations
2728 azimuth: Azimuth angle correction
2761 azimuth: Azimuth angle correction
2729
2762
2730 Affected:
2763 Affected:
2731 self.dataOut.data_param
2764 self.dataOut.data_param
2732
2765
2733 Rejection Criteria (Errors):
2766 Rejection Criteria (Errors):
2734 0: No error; analysis OK
2767 0: No error; analysis OK
2735 1: SNR < SNR threshold
2768 1: SNR < SNR threshold
2736 2: angle of arrival (AOA) ambiguously determined
2769 2: angle of arrival (AOA) ambiguously determined
2737 3: AOA estimate not feasible
2770 3: AOA estimate not feasible
2738 4: Large difference in AOAs obtained from different antenna baselines
2771 4: Large difference in AOAs obtained from different antenna baselines
2739 5: echo at start or end of time series
2772 5: echo at start or end of time series
2740 6: echo less than 5 examples long; too short for analysis
2773 6: echo less than 5 examples long; too short for analysis
2741 7: echo rise exceeds 0.3s
2774 7: echo rise exceeds 0.3s
2742 8: echo decay time less than twice rise time
2775 8: echo decay time less than twice rise time
2743 9: large power level before echo
2776 9: large power level before echo
2744 10: large power level after echo
2777 10: large power level after echo
2745 11: poor fit to amplitude for estimation of decay time
2778 11: poor fit to amplitude for estimation of decay time
2746 12: poor fit to CCF phase variation for estimation of radial drift velocity
2779 12: poor fit to CCF phase variation for estimation of radial drift velocity
2747 13: height unresolvable echo: not valid height within 70 to 110 km
2780 13: height unresolvable echo: not valid height within 70 to 110 km
2748 14: height ambiguous echo: more then one possible height within 70 to 110 km
2781 14: height ambiguous echo: more then one possible height within 70 to 110 km
2749 15: radial drift velocity or projected horizontal velocity exceeds 200 m/s
2782 15: radial drift velocity or projected horizontal velocity exceeds 200 m/s
2750 16: oscilatory echo, indicating event most likely not an underdense echo
2783 16: oscilatory echo, indicating event most likely not an underdense echo
2751
2784
2752 17: phase difference in meteor Reestimation
2785 17: phase difference in meteor Reestimation
2753
2786
2754 Data Storage:
2787 Data Storage:
2755 Meteors for Wind Estimation (8):
2788 Meteors for Wind Estimation (8):
2756 Utc Time | Range Height
2789 Utc Time | Range Height
2757 Azimuth Zenith errorCosDir
2790 Azimuth Zenith errorCosDir
2758 VelRad errorVelRad
2791 VelRad errorVelRad
2759 Phase0 Phase1 Phase2 Phase3
2792 Phase0 Phase1 Phase2 Phase3
2760 TypeError
2793 TypeError
2761
2794
2762 '''
2795 '''
2763
2796
2764 def run(self, dataOut, hei_ref = None, tauindex = 0,
2797 def run(self, dataOut, hei_ref = None, tauindex = 0,
2765 phaseOffsets = None,
2798 phaseOffsets = None,
2766 cohDetection = False, cohDet_timeStep = 1, cohDet_thresh = 25,
2799 cohDetection = False, cohDet_timeStep = 1, cohDet_thresh = 25,
2767 noise_timeStep = 4, noise_multiple = 4,
2800 noise_timeStep = 4, noise_multiple = 4,
2768 multDet_timeLimit = 1, multDet_rangeLimit = 3,
2801 multDet_timeLimit = 1, multDet_rangeLimit = 3,
2769 phaseThresh = 20, SNRThresh = 5,
2802 phaseThresh = 20, SNRThresh = 5,
2770 hmin = 50, hmax=150, azimuth = 0,
2803 hmin = 50, hmax=150, azimuth = 0,
2771 channelPositions = None) :
2804 channelPositions = None) :
2772
2805
2773
2806
2774 #Getting Pairslist
2807 #Getting Pairslist
2775 if channelPositions == None:
2808 if channelPositions == None:
2776 # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T
2809 # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T
2777 channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella
2810 channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella
2778 meteorOps = SMOperations()
2811 meteorOps = SMOperations()
2779 pairslist0, distances = meteorOps.getPhasePairs(channelPositions)
2812 pairslist0, distances = meteorOps.getPhasePairs(channelPositions)
2780 heiRang = dataOut.getHeiRange()
2813 heiRang = dataOut.getHeiRange()
2781 #Get Beacon signal - No Beacon signal anymore
2814 #Get Beacon signal - No Beacon signal anymore
2782 # newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex])
2815 # newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex])
2783 #
2816 #
2784 # if hei_ref != None:
2817 # if hei_ref != None:
2785 # newheis = numpy.where(self.dataOut.heightList>hei_ref)
2818 # newheis = numpy.where(self.dataOut.heightList>hei_ref)
2786 #
2819 #
2787
2820
2788
2821
2789 #****************REMOVING HARDWARE PHASE DIFFERENCES***************
2822 #****************REMOVING HARDWARE PHASE DIFFERENCES***************
2790 # see if the user put in pre defined phase shifts
2823 # see if the user put in pre defined phase shifts
2791 voltsPShift = dataOut.data_pre.copy()
2824 voltsPShift = dataOut.data_pre.copy()
2792
2825
2793 # if predefinedPhaseShifts != None:
2826 # if predefinedPhaseShifts != None:
2794 # hardwarePhaseShifts = numpy.array(predefinedPhaseShifts)*numpy.pi/180
2827 # hardwarePhaseShifts = numpy.array(predefinedPhaseShifts)*numpy.pi/180
2795 #
2828 #
2796 # # elif beaconPhaseShifts:
2829 # # elif beaconPhaseShifts:
2797 # # #get hardware phase shifts using beacon signal
2830 # # #get hardware phase shifts using beacon signal
2798 # # hardwarePhaseShifts = self.__getHardwarePhaseDiff(self.dataOut.data_pre, pairslist, newheis, 10)
2831 # # hardwarePhaseShifts = self.__getHardwarePhaseDiff(self.dataOut.data_pre, pairslist, newheis, 10)
2799 # # hardwarePhaseShifts = numpy.insert(hardwarePhaseShifts,centerReceiverIndex,0)
2832 # # hardwarePhaseShifts = numpy.insert(hardwarePhaseShifts,centerReceiverIndex,0)
2800 #
2833 #
2801 # else:
2834 # else:
2802 # hardwarePhaseShifts = numpy.zeros(5)
2835 # hardwarePhaseShifts = numpy.zeros(5)
2803 #
2836 #
2804 # voltsPShift = numpy.zeros((self.dataOut.data_pre.shape[0],self.dataOut.data_pre.shape[1],self.dataOut.data_pre.shape[2]), dtype = 'complex')
2837 # voltsPShift = numpy.zeros((self.dataOut.data_pre.shape[0],self.dataOut.data_pre.shape[1],self.dataOut.data_pre.shape[2]), dtype = 'complex')
2805 # for i in range(self.dataOut.data_pre.shape[0]):
2838 # for i in range(self.dataOut.data_pre.shape[0]):
2806 # voltsPShift[i,:,:] = self.__shiftPhase(self.dataOut.data_pre[i,:,:], hardwarePhaseShifts[i])
2839 # voltsPShift[i,:,:] = self.__shiftPhase(self.dataOut.data_pre[i,:,:], hardwarePhaseShifts[i])
2807
2840
2808 #******************END OF REMOVING HARDWARE PHASE DIFFERENCES*********
2841 #******************END OF REMOVING HARDWARE PHASE DIFFERENCES*********
2809
2842
2810 #Remove DC
2843 #Remove DC
2811 voltsDC = numpy.mean(voltsPShift,1)
2844 voltsDC = numpy.mean(voltsPShift,1)
2812 voltsDC = numpy.mean(voltsDC,1)
2845 voltsDC = numpy.mean(voltsDC,1)
2813 for i in range(voltsDC.shape[0]):
2846 for i in range(voltsDC.shape[0]):
2814 voltsPShift[i] = voltsPShift[i] - voltsDC[i]
2847 voltsPShift[i] = voltsPShift[i] - voltsDC[i]
2815
2848
2816 #Don't considerate last heights, theyre used to calculate Hardware Phase Shift
2849 #Don't considerate last heights, theyre used to calculate Hardware Phase Shift
2817 # voltsPShift = voltsPShift[:,:,:newheis[0][0]]
2850 # voltsPShift = voltsPShift[:,:,:newheis[0][0]]
2818
2851
2819 #************ FIND POWER OF DATA W/COH OR NON COH DETECTION (3.4) **********
2852 #************ FIND POWER OF DATA W/COH OR NON COH DETECTION (3.4) **********
2820 #Coherent Detection
2853 #Coherent Detection
2821 if cohDetection:
2854 if cohDetection:
2822 #use coherent detection to get the net power
2855 #use coherent detection to get the net power
2823 cohDet_thresh = cohDet_thresh*numpy.pi/180
2856 cohDet_thresh = cohDet_thresh*numpy.pi/180
2824 voltsPShift = self.__coherentDetection(voltsPShift, cohDet_timeStep, dataOut.timeInterval, pairslist0, cohDet_thresh)
2857 voltsPShift = self.__coherentDetection(voltsPShift, cohDet_timeStep, dataOut.timeInterval, pairslist0, cohDet_thresh)
2825
2858
2826 #Non-coherent detection!
2859 #Non-coherent detection!
2827 powerNet = numpy.nansum(numpy.abs(voltsPShift[:,:,:])**2,0)
2860 powerNet = numpy.nansum(numpy.abs(voltsPShift[:,:,:])**2,0)
2828 #********** END OF COH/NON-COH POWER CALCULATION**********************
2861 #********** END OF COH/NON-COH POWER CALCULATION**********************
2829
2862
2830 #********** FIND THE NOISE LEVEL AND POSSIBLE METEORS ****************
2863 #********** FIND THE NOISE LEVEL AND POSSIBLE METEORS ****************
2831 #Get noise
2864 #Get noise
2832 noise, noise1 = self.__getNoise(powerNet, noise_timeStep, dataOut.timeInterval)
2865 noise, noise1 = self.__getNoise(powerNet, noise_timeStep, dataOut.timeInterval)
2833 # noise = self.getNoise1(powerNet, noise_timeStep, self.dataOut.timeInterval)
2866 # noise = self.getNoise1(powerNet, noise_timeStep, self.dataOut.timeInterval)
2834 #Get signal threshold
2867 #Get signal threshold
2835 signalThresh = noise_multiple*noise
2868 signalThresh = noise_multiple*noise
2836 #Meteor echoes detection
2869 #Meteor echoes detection
2837 listMeteors = self.__findMeteors(powerNet, signalThresh)
2870 listMeteors = self.__findMeteors(powerNet, signalThresh)
2838 #******* END OF NOISE LEVEL AND POSSIBLE METEORS CACULATION **********
2871 #******* END OF NOISE LEVEL AND POSSIBLE METEORS CACULATION **********
2839
2872
2840 #************** REMOVE MULTIPLE DETECTIONS (3.5) ***************************
2873 #************** REMOVE MULTIPLE DETECTIONS (3.5) ***************************
2841 #Parameters
2874 #Parameters
2842 heiRange = dataOut.getHeiRange()
2875 heiRange = dataOut.getHeiRange()
2843 rangeInterval = heiRange[1] - heiRange[0]
2876 rangeInterval = heiRange[1] - heiRange[0]
2844 rangeLimit = multDet_rangeLimit/rangeInterval
2877 rangeLimit = multDet_rangeLimit/rangeInterval
2845 timeLimit = multDet_timeLimit/dataOut.timeInterval
2878 timeLimit = multDet_timeLimit/dataOut.timeInterval
2846 #Multiple detection removals
2879 #Multiple detection removals
2847 listMeteors1 = self.__removeMultipleDetections(listMeteors, rangeLimit, timeLimit)
2880 listMeteors1 = self.__removeMultipleDetections(listMeteors, rangeLimit, timeLimit)
2848 #************ END OF REMOVE MULTIPLE DETECTIONS **********************
2881 #************ END OF REMOVE MULTIPLE DETECTIONS **********************
2849
2882
2850 #********************* METEOR REESTIMATION (3.7, 3.8, 3.9, 3.10) ********************
2883 #********************* METEOR REESTIMATION (3.7, 3.8, 3.9, 3.10) ********************
2851 #Parameters
2884 #Parameters
2852 phaseThresh = phaseThresh*numpy.pi/180
2885 phaseThresh = phaseThresh*numpy.pi/180
2853 thresh = [phaseThresh, noise_multiple, SNRThresh]
2886 thresh = [phaseThresh, noise_multiple, SNRThresh]
2854 #Meteor reestimation (Errors N 1, 6, 12, 17)
2887 #Meteor reestimation (Errors N 1, 6, 12, 17)
2855 listMeteors2, listMeteorsPower, listMeteorsVolts = self.__meteorReestimation(listMeteors1, voltsPShift, pairslist0, thresh, noise, dataOut.timeInterval, dataOut.frequency)
2888 listMeteors2, listMeteorsPower, listMeteorsVolts = self.__meteorReestimation(listMeteors1, voltsPShift, pairslist0, thresh, noise, dataOut.timeInterval, dataOut.frequency)
2856 # listMeteors2, listMeteorsPower, listMeteorsVolts = self.meteorReestimation3(listMeteors2, listMeteorsPower, listMeteorsVolts, voltsPShift, pairslist, thresh, noise)
2889 # listMeteors2, listMeteorsPower, listMeteorsVolts = self.meteorReestimation3(listMeteors2, listMeteorsPower, listMeteorsVolts, voltsPShift, pairslist, thresh, noise)
2857 #Estimation of decay times (Errors N 7, 8, 11)
2890 #Estimation of decay times (Errors N 7, 8, 11)
2858 listMeteors3 = self.__estimateDecayTime(listMeteors2, listMeteorsPower, dataOut.timeInterval, dataOut.frequency)
2891 listMeteors3 = self.__estimateDecayTime(listMeteors2, listMeteorsPower, dataOut.timeInterval, dataOut.frequency)
2859 #******************* END OF METEOR REESTIMATION *******************
2892 #******************* END OF METEOR REESTIMATION *******************
2860
2893
2861 #********************* METEOR PARAMETERS CALCULATION (3.11, 3.12, 3.13) **************************
2894 #********************* METEOR PARAMETERS CALCULATION (3.11, 3.12, 3.13) **************************
2862 #Calculating Radial Velocity (Error N 15)
2895 #Calculating Radial Velocity (Error N 15)
2863 radialStdThresh = 10
2896 radialStdThresh = 10
2864 listMeteors4 = self.__getRadialVelocity(listMeteors3, listMeteorsVolts, radialStdThresh, pairslist0, dataOut.timeInterval)
2897 listMeteors4 = self.__getRadialVelocity(listMeteors3, listMeteorsVolts, radialStdThresh, pairslist0, dataOut.timeInterval)
2865
2898
2866 if len(listMeteors4) > 0:
2899 if len(listMeteors4) > 0:
2867 #Setting New Array
2900 #Setting New Array
2868 date = dataOut.utctime
2901 date = dataOut.utctime
2869 arrayParameters = self.__setNewArrays(listMeteors4, date, heiRang)
2902 arrayParameters = self.__setNewArrays(listMeteors4, date, heiRang)
2870
2903
2871 #Correcting phase offset
2904 #Correcting phase offset
2872 if phaseOffsets != None:
2905 if phaseOffsets != None:
2873 phaseOffsets = numpy.array(phaseOffsets)*numpy.pi/180
2906 phaseOffsets = numpy.array(phaseOffsets)*numpy.pi/180
2874 arrayParameters[:,8:12] = numpy.unwrap(arrayParameters[:,8:12] + phaseOffsets)
2907 arrayParameters[:,8:12] = numpy.unwrap(arrayParameters[:,8:12] + phaseOffsets)
2875
2908
2876 #Second Pairslist
2909 #Second Pairslist
2877 pairsList = []
2910 pairsList = []
2878 pairx = (0,1)
2911 pairx = (0,1)
2879 pairy = (2,3)
2912 pairy = (2,3)
2880 pairsList.append(pairx)
2913 pairsList.append(pairx)
2881 pairsList.append(pairy)
2914 pairsList.append(pairy)
2882
2915
2883 jph = numpy.array([0,0,0,0])
2916 jph = numpy.array([0,0,0,0])
2884 h = (hmin,hmax)
2917 h = (hmin,hmax)
2885 arrayParameters = meteorOps.getMeteorParams(arrayParameters, azimuth, h, pairsList, distances, jph)
2918 arrayParameters = meteorOps.getMeteorParams(arrayParameters, azimuth, h, pairsList, distances, jph)
2886
2919
2887 # #Calculate AOA (Error N 3, 4)
2920 # #Calculate AOA (Error N 3, 4)
2888 # #JONES ET AL. 1998
2921 # #JONES ET AL. 1998
2889 # error = arrayParameters[:,-1]
2922 # error = arrayParameters[:,-1]
2890 # AOAthresh = numpy.pi/8
2923 # AOAthresh = numpy.pi/8
2891 # phases = -arrayParameters[:,9:13]
2924 # phases = -arrayParameters[:,9:13]
2892 # arrayParameters[:,4:7], arrayParameters[:,-1] = meteorOps.getAOA(phases, pairsList, error, AOAthresh, azimuth)
2925 # arrayParameters[:,4:7], arrayParameters[:,-1] = meteorOps.getAOA(phases, pairsList, error, AOAthresh, azimuth)
2893 #
2926 #
2894 # #Calculate Heights (Error N 13 and 14)
2927 # #Calculate Heights (Error N 13 and 14)
2895 # error = arrayParameters[:,-1]
2928 # error = arrayParameters[:,-1]
2896 # Ranges = arrayParameters[:,2]
2929 # Ranges = arrayParameters[:,2]
2897 # zenith = arrayParameters[:,5]
2930 # zenith = arrayParameters[:,5]
2898 # arrayParameters[:,3], arrayParameters[:,-1] = meteorOps.getHeights(Ranges, zenith, error, hmin, hmax)
2931 # arrayParameters[:,3], arrayParameters[:,-1] = meteorOps.getHeights(Ranges, zenith, error, hmin, hmax)
2899 # error = arrayParameters[:,-1]
2932 # error = arrayParameters[:,-1]
2900 #********************* END OF PARAMETERS CALCULATION **************************
2933 #********************* END OF PARAMETERS CALCULATION **************************
2901
2934
2902 #***************************+ PASS DATA TO NEXT STEP **********************
2935 #***************************+ PASS DATA TO NEXT STEP **********************
2903 # arrayFinal = arrayParameters.reshape((1,arrayParameters.shape[0],arrayParameters.shape[1]))
2936 # arrayFinal = arrayParameters.reshape((1,arrayParameters.shape[0],arrayParameters.shape[1]))
2904 dataOut.data_param = arrayParameters
2937 dataOut.data_param = arrayParameters
2905
2938
2906 if arrayParameters == None:
2939 if arrayParameters == None:
2907 dataOut.flagNoData = True
2940 dataOut.flagNoData = True
2908 else:
2941 else:
2909 dataOut.flagNoData = True
2942 dataOut.flagNoData = True
2910
2943
2911 return
2944 return
2912
2945
2913 def __getHardwarePhaseDiff(self, voltage0, pairslist, newheis, n):
2946 def __getHardwarePhaseDiff(self, voltage0, pairslist, newheis, n):
2914
2947
2915 minIndex = min(newheis[0])
2948 minIndex = min(newheis[0])
2916 maxIndex = max(newheis[0])
2949 maxIndex = max(newheis[0])
2917
2950
2918 voltage = voltage0[:,:,minIndex:maxIndex+1]
2951 voltage = voltage0[:,:,minIndex:maxIndex+1]
2919 nLength = voltage.shape[1]/n
2952 nLength = voltage.shape[1]/n
2920 nMin = 0
2953 nMin = 0
2921 nMax = 0
2954 nMax = 0
2922 phaseOffset = numpy.zeros((len(pairslist),n))
2955 phaseOffset = numpy.zeros((len(pairslist),n))
2923
2956
2924 for i in range(n):
2957 for i in range(n):
2925 nMax += nLength
2958 nMax += nLength
2926 phaseCCF = -numpy.angle(self.__calculateCCF(voltage[:,nMin:nMax,:], pairslist, [0]))
2959 phaseCCF = -numpy.angle(self.__calculateCCF(voltage[:,nMin:nMax,:], pairslist, [0]))
2927 phaseCCF = numpy.mean(phaseCCF, axis = 2)
2960 phaseCCF = numpy.mean(phaseCCF, axis = 2)
2928 phaseOffset[:,i] = phaseCCF.transpose()
2961 phaseOffset[:,i] = phaseCCF.transpose()
2929 nMin = nMax
2962 nMin = nMax
2930 # phaseDiff, phaseArrival = self.estimatePhaseDifference(voltage, pairslist)
2963 # phaseDiff, phaseArrival = self.estimatePhaseDifference(voltage, pairslist)
2931
2964
2932 #Remove Outliers
2965 #Remove Outliers
2933 factor = 2
2966 factor = 2
2934 wt = phaseOffset - signal.medfilt(phaseOffset,(1,5))
2967 wt = phaseOffset - signal.medfilt(phaseOffset,(1,5))
2935 dw = numpy.std(wt,axis = 1)
2968 dw = numpy.std(wt,axis = 1)
2936 dw = dw.reshape((dw.size,1))
2969 dw = dw.reshape((dw.size,1))
2937 ind = numpy.where(numpy.logical_or(wt>dw*factor,wt<-dw*factor))
2970 ind = numpy.where(numpy.logical_or(wt>dw*factor,wt<-dw*factor))
2938 phaseOffset[ind] = numpy.nan
2971 phaseOffset[ind] = numpy.nan
2939 phaseOffset = stats.nanmean(phaseOffset, axis=1)
2972 phaseOffset = stats.nanmean(phaseOffset, axis=1)
2940
2973
2941 return phaseOffset
2974 return phaseOffset
2942
2975
2943 def __shiftPhase(self, data, phaseShift):
2976 def __shiftPhase(self, data, phaseShift):
2944 #this will shift the phase of a complex number
2977 #this will shift the phase of a complex number
2945 dataShifted = numpy.abs(data) * numpy.exp((numpy.angle(data)+phaseShift)*1j)
2978 dataShifted = numpy.abs(data) * numpy.exp((numpy.angle(data)+phaseShift)*1j)
2946 return dataShifted
2979 return dataShifted
2947
2980
2948 def __estimatePhaseDifference(self, array, pairslist):
2981 def __estimatePhaseDifference(self, array, pairslist):
2949 nChannel = array.shape[0]
2982 nChannel = array.shape[0]
2950 nHeights = array.shape[2]
2983 nHeights = array.shape[2]
2951 numPairs = len(pairslist)
2984 numPairs = len(pairslist)
2952 # phaseCCF = numpy.zeros((nChannel, 5, nHeights))
2985 # phaseCCF = numpy.zeros((nChannel, 5, nHeights))
2953 phaseCCF = numpy.angle(self.__calculateCCF(array, pairslist, [-2,-1,0,1,2]))
2986 phaseCCF = numpy.angle(self.__calculateCCF(array, pairslist, [-2,-1,0,1,2]))
2954
2987
2955 #Correct phases
2988 #Correct phases
2956 derPhaseCCF = phaseCCF[:,1:,:] - phaseCCF[:,0:-1,:]
2989 derPhaseCCF = phaseCCF[:,1:,:] - phaseCCF[:,0:-1,:]
2957 indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi)
2990 indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi)
2958
2991
2959 if indDer[0].shape[0] > 0:
2992 if indDer[0].shape[0] > 0:
2960 for i in range(indDer[0].shape[0]):
2993 for i in range(indDer[0].shape[0]):
2961 signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i],indDer[2][i]])
2994 signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i],indDer[2][i]])
2962 phaseCCF[indDer[0][i],indDer[1][i]+1:,:] += signo*2*numpy.pi
2995 phaseCCF[indDer[0][i],indDer[1][i]+1:,:] += signo*2*numpy.pi
2963
2996
2964 # for j in range(numSides):
2997 # for j in range(numSides):
2965 # phaseCCFAux = self.calculateCCF(arrayCenter, arraySides[j,:,:], [-2,1,0,1,2])
2998 # phaseCCFAux = self.calculateCCF(arrayCenter, arraySides[j,:,:], [-2,1,0,1,2])
2966 # phaseCCF[j,:,:] = numpy.angle(phaseCCFAux)
2999 # phaseCCF[j,:,:] = numpy.angle(phaseCCFAux)
2967 #
3000 #
2968 #Linear
3001 #Linear
2969 phaseInt = numpy.zeros((numPairs,1))
3002 phaseInt = numpy.zeros((numPairs,1))
2970 angAllCCF = phaseCCF[:,[0,1,3,4],0]
3003 angAllCCF = phaseCCF[:,[0,1,3,4],0]
2971 for j in range(numPairs):
3004 for j in range(numPairs):
2972 fit = stats.linregress([-2,-1,1,2],angAllCCF[j,:])
3005 fit = stats.linregress([-2,-1,1,2],angAllCCF[j,:])
2973 phaseInt[j] = fit[1]
3006 phaseInt[j] = fit[1]
2974 #Phase Differences
3007 #Phase Differences
2975 phaseDiff = phaseInt - phaseCCF[:,2,:]
3008 phaseDiff = phaseInt - phaseCCF[:,2,:]
2976 phaseArrival = phaseInt.reshape(phaseInt.size)
3009 phaseArrival = phaseInt.reshape(phaseInt.size)
2977
3010
2978 #Dealias
3011 #Dealias
2979 phaseArrival = numpy.angle(numpy.exp(1j*phaseArrival))
3012 phaseArrival = numpy.angle(numpy.exp(1j*phaseArrival))
2980 # indAlias = numpy.where(phaseArrival > numpy.pi)
3013 # indAlias = numpy.where(phaseArrival > numpy.pi)
2981 # phaseArrival[indAlias] -= 2*numpy.pi
3014 # phaseArrival[indAlias] -= 2*numpy.pi
2982 # indAlias = numpy.where(phaseArrival < -numpy.pi)
3015 # indAlias = numpy.where(phaseArrival < -numpy.pi)
2983 # phaseArrival[indAlias] += 2*numpy.pi
3016 # phaseArrival[indAlias] += 2*numpy.pi
2984
3017
2985 return phaseDiff, phaseArrival
3018 return phaseDiff, phaseArrival
2986
3019
2987 def __coherentDetection(self, volts, timeSegment, timeInterval, pairslist, thresh):
3020 def __coherentDetection(self, volts, timeSegment, timeInterval, pairslist, thresh):
2988 #this function will run the coherent detection used in Holdworth et al. 2004 and return the net power
3021 #this function will run the coherent detection used in Holdworth et al. 2004 and return the net power
2989 #find the phase shifts of each channel over 1 second intervals
3022 #find the phase shifts of each channel over 1 second intervals
2990 #only look at ranges below the beacon signal
3023 #only look at ranges below the beacon signal
2991 numProfPerBlock = numpy.ceil(timeSegment/timeInterval)
3024 numProfPerBlock = numpy.ceil(timeSegment/timeInterval)
2992 numBlocks = int(volts.shape[1]/numProfPerBlock)
3025 numBlocks = int(volts.shape[1]/numProfPerBlock)
2993 numHeights = volts.shape[2]
3026 numHeights = volts.shape[2]
2994 nChannel = volts.shape[0]
3027 nChannel = volts.shape[0]
2995 voltsCohDet = volts.copy()
3028 voltsCohDet = volts.copy()
2996
3029
2997 pairsarray = numpy.array(pairslist)
3030 pairsarray = numpy.array(pairslist)
2998 indSides = pairsarray[:,1]
3031 indSides = pairsarray[:,1]
2999 # indSides = numpy.array(range(nChannel))
3032 # indSides = numpy.array(range(nChannel))
3000 # indSides = numpy.delete(indSides, indCenter)
3033 # indSides = numpy.delete(indSides, indCenter)
3001 #
3034 #
3002 # listCenter = numpy.array_split(volts[indCenter,:,:], numBlocks, 0)
3035 # listCenter = numpy.array_split(volts[indCenter,:,:], numBlocks, 0)
3003 listBlocks = numpy.array_split(volts, numBlocks, 1)
3036 listBlocks = numpy.array_split(volts, numBlocks, 1)
3004
3037
3005 startInd = 0
3038 startInd = 0
3006 endInd = 0
3039 endInd = 0
3007
3040
3008 for i in range(numBlocks):
3041 for i in range(numBlocks):
3009 startInd = endInd
3042 startInd = endInd
3010 endInd = endInd + listBlocks[i].shape[1]
3043 endInd = endInd + listBlocks[i].shape[1]
3011
3044
3012 arrayBlock = listBlocks[i]
3045 arrayBlock = listBlocks[i]
3013 # arrayBlockCenter = listCenter[i]
3046 # arrayBlockCenter = listCenter[i]
3014
3047
3015 #Estimate the Phase Difference
3048 #Estimate the Phase Difference
3016 phaseDiff, aux = self.__estimatePhaseDifference(arrayBlock, pairslist)
3049 phaseDiff, aux = self.__estimatePhaseDifference(arrayBlock, pairslist)
3017 #Phase Difference RMS
3050 #Phase Difference RMS
3018 arrayPhaseRMS = numpy.abs(phaseDiff)
3051 arrayPhaseRMS = numpy.abs(phaseDiff)
3019 phaseRMSaux = numpy.sum(arrayPhaseRMS < thresh,0)
3052 phaseRMSaux = numpy.sum(arrayPhaseRMS < thresh,0)
3020 indPhase = numpy.where(phaseRMSaux==4)
3053 indPhase = numpy.where(phaseRMSaux==4)
3021 #Shifting
3054 #Shifting
3022 if indPhase[0].shape[0] > 0:
3055 if indPhase[0].shape[0] > 0:
3023 for j in range(indSides.size):
3056 for j in range(indSides.size):
3024 arrayBlock[indSides[j],:,indPhase] = self.__shiftPhase(arrayBlock[indSides[j],:,indPhase], phaseDiff[j,indPhase].transpose())
3057 arrayBlock[indSides[j],:,indPhase] = self.__shiftPhase(arrayBlock[indSides[j],:,indPhase], phaseDiff[j,indPhase].transpose())
3025 voltsCohDet[:,startInd:endInd,:] = arrayBlock
3058 voltsCohDet[:,startInd:endInd,:] = arrayBlock
3026
3059
3027 return voltsCohDet
3060 return voltsCohDet
3028
3061
3029 def __calculateCCF(self, volts, pairslist ,laglist):
3062 def __calculateCCF(self, volts, pairslist ,laglist):
3030
3063
3031 nHeights = volts.shape[2]
3064 nHeights = volts.shape[2]
3032 nPoints = volts.shape[1]
3065 nPoints = volts.shape[1]
3033 voltsCCF = numpy.zeros((len(pairslist), len(laglist), nHeights),dtype = 'complex')
3066 voltsCCF = numpy.zeros((len(pairslist), len(laglist), nHeights),dtype = 'complex')
3034
3067
3035 for i in range(len(pairslist)):
3068 for i in range(len(pairslist)):
3036 volts1 = volts[pairslist[i][0]]
3069 volts1 = volts[pairslist[i][0]]
3037 volts2 = volts[pairslist[i][1]]
3070 volts2 = volts[pairslist[i][1]]
3038
3071
3039 for t in range(len(laglist)):
3072 for t in range(len(laglist)):
3040 idxT = laglist[t]
3073 idxT = laglist[t]
3041 if idxT >= 0:
3074 if idxT >= 0:
3042 vStacked = numpy.vstack((volts2[idxT:,:],
3075 vStacked = numpy.vstack((volts2[idxT:,:],
3043 numpy.zeros((idxT, nHeights),dtype='complex')))
3076 numpy.zeros((idxT, nHeights),dtype='complex')))
3044 else:
3077 else:
3045 vStacked = numpy.vstack((numpy.zeros((-idxT, nHeights),dtype='complex'),
3078 vStacked = numpy.vstack((numpy.zeros((-idxT, nHeights),dtype='complex'),
3046 volts2[:(nPoints + idxT),:]))
3079 volts2[:(nPoints + idxT),:]))
3047 voltsCCF[i,t,:] = numpy.sum((numpy.conjugate(volts1)*vStacked),axis=0)
3080 voltsCCF[i,t,:] = numpy.sum((numpy.conjugate(volts1)*vStacked),axis=0)
3048
3081
3049 vStacked = None
3082 vStacked = None
3050 return voltsCCF
3083 return voltsCCF
3051
3084
3052 def __getNoise(self, power, timeSegment, timeInterval):
3085 def __getNoise(self, power, timeSegment, timeInterval):
3053 numProfPerBlock = numpy.ceil(timeSegment/timeInterval)
3086 numProfPerBlock = numpy.ceil(timeSegment/timeInterval)
3054 numBlocks = int(power.shape[0]/numProfPerBlock)
3087 numBlocks = int(power.shape[0]/numProfPerBlock)
3055 numHeights = power.shape[1]
3088 numHeights = power.shape[1]
3056
3089
3057 listPower = numpy.array_split(power, numBlocks, 0)
3090 listPower = numpy.array_split(power, numBlocks, 0)
3058 noise = numpy.zeros((power.shape[0], power.shape[1]))
3091 noise = numpy.zeros((power.shape[0], power.shape[1]))
3059 noise1 = numpy.zeros((power.shape[0], power.shape[1]))
3092 noise1 = numpy.zeros((power.shape[0], power.shape[1]))
3060
3093
3061 startInd = 0
3094 startInd = 0
3062 endInd = 0
3095 endInd = 0
3063
3096
3064 for i in range(numBlocks): #split por canal
3097 for i in range(numBlocks): #split por canal
3065 startInd = endInd
3098 startInd = endInd
3066 endInd = endInd + listPower[i].shape[0]
3099 endInd = endInd + listPower[i].shape[0]
3067
3100
3068 arrayBlock = listPower[i]
3101 arrayBlock = listPower[i]
3069 noiseAux = numpy.mean(arrayBlock, 0)
3102 noiseAux = numpy.mean(arrayBlock, 0)
3070 # noiseAux = numpy.median(noiseAux)
3103 # noiseAux = numpy.median(noiseAux)
3071 # noiseAux = numpy.mean(arrayBlock)
3104 # noiseAux = numpy.mean(arrayBlock)
3072 noise[startInd:endInd,:] = noise[startInd:endInd,:] + noiseAux
3105 noise[startInd:endInd,:] = noise[startInd:endInd,:] + noiseAux
3073
3106
3074 noiseAux1 = numpy.mean(arrayBlock)
3107 noiseAux1 = numpy.mean(arrayBlock)
3075 noise1[startInd:endInd,:] = noise1[startInd:endInd,:] + noiseAux1
3108 noise1[startInd:endInd,:] = noise1[startInd:endInd,:] + noiseAux1
3076
3109
3077 return noise, noise1
3110 return noise, noise1
3078
3111
3079 def __findMeteors(self, power, thresh):
3112 def __findMeteors(self, power, thresh):
3080 nProf = power.shape[0]
3113 nProf = power.shape[0]
3081 nHeights = power.shape[1]
3114 nHeights = power.shape[1]
3082 listMeteors = []
3115 listMeteors = []
3083
3116
3084 for i in range(nHeights):
3117 for i in range(nHeights):
3085 powerAux = power[:,i]
3118 powerAux = power[:,i]
3086 threshAux = thresh[:,i]
3119 threshAux = thresh[:,i]
3087
3120
3088 indUPthresh = numpy.where(powerAux > threshAux)[0]
3121 indUPthresh = numpy.where(powerAux > threshAux)[0]
3089 indDNthresh = numpy.where(powerAux <= threshAux)[0]
3122 indDNthresh = numpy.where(powerAux <= threshAux)[0]
3090
3123
3091 j = 0
3124 j = 0
3092
3125
3093 while (j < indUPthresh.size - 2):
3126 while (j < indUPthresh.size - 2):
3094 if (indUPthresh[j + 2] == indUPthresh[j] + 2):
3127 if (indUPthresh[j + 2] == indUPthresh[j] + 2):
3095 indDNAux = numpy.where(indDNthresh > indUPthresh[j])
3128 indDNAux = numpy.where(indDNthresh > indUPthresh[j])
3096 indDNthresh = indDNthresh[indDNAux]
3129 indDNthresh = indDNthresh[indDNAux]
3097
3130
3098 if (indDNthresh.size > 0):
3131 if (indDNthresh.size > 0):
3099 indEnd = indDNthresh[0] - 1
3132 indEnd = indDNthresh[0] - 1
3100 indInit = indUPthresh[j]
3133 indInit = indUPthresh[j]
3101
3134
3102 meteor = powerAux[indInit:indEnd + 1]
3135 meteor = powerAux[indInit:indEnd + 1]
3103 indPeak = meteor.argmax() + indInit
3136 indPeak = meteor.argmax() + indInit
3104 FLA = sum(numpy.conj(meteor)*numpy.hstack((meteor[1:],0)))
3137 FLA = sum(numpy.conj(meteor)*numpy.hstack((meteor[1:],0)))
3105
3138
3106 listMeteors.append(numpy.array([i,indInit,indPeak,indEnd,FLA])) #CHEQUEAR!!!!!
3139 listMeteors.append(numpy.array([i,indInit,indPeak,indEnd,FLA])) #CHEQUEAR!!!!!
3107 j = numpy.where(indUPthresh == indEnd)[0] + 1
3140 j = numpy.where(indUPthresh == indEnd)[0] + 1
3108 else: j+=1
3141 else: j+=1
3109 else: j+=1
3142 else: j+=1
3110
3143
3111 return listMeteors
3144 return listMeteors
3112
3145
3113 def __removeMultipleDetections(self,listMeteors, rangeLimit, timeLimit):
3146 def __removeMultipleDetections(self,listMeteors, rangeLimit, timeLimit):
3114
3147
3115 arrayMeteors = numpy.asarray(listMeteors)
3148 arrayMeteors = numpy.asarray(listMeteors)
3116 listMeteors1 = []
3149 listMeteors1 = []
3117
3150
3118 while arrayMeteors.shape[0] > 0:
3151 while arrayMeteors.shape[0] > 0:
3119 FLAs = arrayMeteors[:,4]
3152 FLAs = arrayMeteors[:,4]
3120 maxFLA = FLAs.argmax()
3153 maxFLA = FLAs.argmax()
3121 listMeteors1.append(arrayMeteors[maxFLA,:])
3154 listMeteors1.append(arrayMeteors[maxFLA,:])
3122
3155
3123 MeteorInitTime = arrayMeteors[maxFLA,1]
3156 MeteorInitTime = arrayMeteors[maxFLA,1]
3124 MeteorEndTime = arrayMeteors[maxFLA,3]
3157 MeteorEndTime = arrayMeteors[maxFLA,3]
3125 MeteorHeight = arrayMeteors[maxFLA,0]
3158 MeteorHeight = arrayMeteors[maxFLA,0]
3126
3159
3127 #Check neighborhood
3160 #Check neighborhood
3128 maxHeightIndex = MeteorHeight + rangeLimit
3161 maxHeightIndex = MeteorHeight + rangeLimit
3129 minHeightIndex = MeteorHeight - rangeLimit
3162 minHeightIndex = MeteorHeight - rangeLimit
3130 minTimeIndex = MeteorInitTime - timeLimit
3163 minTimeIndex = MeteorInitTime - timeLimit
3131 maxTimeIndex = MeteorEndTime + timeLimit
3164 maxTimeIndex = MeteorEndTime + timeLimit
3132
3165
3133 #Check Heights
3166 #Check Heights
3134 indHeight = numpy.logical_and(arrayMeteors[:,0] >= minHeightIndex, arrayMeteors[:,0] <= maxHeightIndex)
3167 indHeight = numpy.logical_and(arrayMeteors[:,0] >= minHeightIndex, arrayMeteors[:,0] <= maxHeightIndex)
3135 indTime = numpy.logical_and(arrayMeteors[:,3] >= minTimeIndex, arrayMeteors[:,1] <= maxTimeIndex)
3168 indTime = numpy.logical_and(arrayMeteors[:,3] >= minTimeIndex, arrayMeteors[:,1] <= maxTimeIndex)
3136 indBoth = numpy.where(numpy.logical_and(indTime,indHeight))
3169 indBoth = numpy.where(numpy.logical_and(indTime,indHeight))
3137
3170
3138 arrayMeteors = numpy.delete(arrayMeteors, indBoth, axis = 0)
3171 arrayMeteors = numpy.delete(arrayMeteors, indBoth, axis = 0)
3139
3172
3140 return listMeteors1
3173 return listMeteors1
3141
3174
3142 def __meteorReestimation(self, listMeteors, volts, pairslist, thresh, noise, timeInterval,frequency):
3175 def __meteorReestimation(self, listMeteors, volts, pairslist, thresh, noise, timeInterval,frequency):
3143 numHeights = volts.shape[2]
3176 numHeights = volts.shape[2]
3144 nChannel = volts.shape[0]
3177 nChannel = volts.shape[0]
3145
3178
3146 thresholdPhase = thresh[0]
3179 thresholdPhase = thresh[0]
3147 thresholdNoise = thresh[1]
3180 thresholdNoise = thresh[1]
3148 thresholdDB = float(thresh[2])
3181 thresholdDB = float(thresh[2])
3149
3182
3150 thresholdDB1 = 10**(thresholdDB/10)
3183 thresholdDB1 = 10**(thresholdDB/10)
3151 pairsarray = numpy.array(pairslist)
3184 pairsarray = numpy.array(pairslist)
3152 indSides = pairsarray[:,1]
3185 indSides = pairsarray[:,1]
3153
3186
3154 pairslist1 = list(pairslist)
3187 pairslist1 = list(pairslist)
3155 pairslist1.append((0,1))
3188 pairslist1.append((0,1))
3156 pairslist1.append((3,4))
3189 pairslist1.append((3,4))
3157
3190
3158 listMeteors1 = []
3191 listMeteors1 = []
3159 listPowerSeries = []
3192 listPowerSeries = []
3160 listVoltageSeries = []
3193 listVoltageSeries = []
3161 #volts has the war data
3194 #volts has the war data
3162
3195
3163 if frequency == 30e6:
3196 if frequency == 30e6:
3164 timeLag = 45*10**-3
3197 timeLag = 45*10**-3
3165 else:
3198 else:
3166 timeLag = 15*10**-3
3199 timeLag = 15*10**-3
3167 lag = numpy.ceil(timeLag/timeInterval)
3200 lag = numpy.ceil(timeLag/timeInterval)
3168
3201
3169 for i in range(len(listMeteors)):
3202 for i in range(len(listMeteors)):
3170
3203
3171 ###################### 3.6 - 3.7 PARAMETERS REESTIMATION #########################
3204 ###################### 3.6 - 3.7 PARAMETERS REESTIMATION #########################
3172 meteorAux = numpy.zeros(16)
3205 meteorAux = numpy.zeros(16)
3173
3206
3174 #Loading meteor Data (mHeight, mStart, mPeak, mEnd)
3207 #Loading meteor Data (mHeight, mStart, mPeak, mEnd)
3175 mHeight = listMeteors[i][0]
3208 mHeight = listMeteors[i][0]
3176 mStart = listMeteors[i][1]
3209 mStart = listMeteors[i][1]
3177 mPeak = listMeteors[i][2]
3210 mPeak = listMeteors[i][2]
3178 mEnd = listMeteors[i][3]
3211 mEnd = listMeteors[i][3]
3179
3212
3180 #get the volt data between the start and end times of the meteor
3213 #get the volt data between the start and end times of the meteor
3181 meteorVolts = volts[:,mStart:mEnd+1,mHeight]
3214 meteorVolts = volts[:,mStart:mEnd+1,mHeight]
3182 meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1)
3215 meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1)
3183
3216
3184 #3.6. Phase Difference estimation
3217 #3.6. Phase Difference estimation
3185 phaseDiff, aux = self.__estimatePhaseDifference(meteorVolts, pairslist)
3218 phaseDiff, aux = self.__estimatePhaseDifference(meteorVolts, pairslist)
3186
3219
3187 #3.7. Phase difference removal & meteor start, peak and end times reestimated
3220 #3.7. Phase difference removal & meteor start, peak and end times reestimated
3188 #meteorVolts0.- all Channels, all Profiles
3221 #meteorVolts0.- all Channels, all Profiles
3189 meteorVolts0 = volts[:,:,mHeight]
3222 meteorVolts0 = volts[:,:,mHeight]
3190 meteorThresh = noise[:,mHeight]*thresholdNoise
3223 meteorThresh = noise[:,mHeight]*thresholdNoise
3191 meteorNoise = noise[:,mHeight]
3224 meteorNoise = noise[:,mHeight]
3192 meteorVolts0[indSides,:] = self.__shiftPhase(meteorVolts0[indSides,:], phaseDiff) #Phase Shifting
3225 meteorVolts0[indSides,:] = self.__shiftPhase(meteorVolts0[indSides,:], phaseDiff) #Phase Shifting
3193 powerNet0 = numpy.nansum(numpy.abs(meteorVolts0)**2, axis = 0) #Power
3226 powerNet0 = numpy.nansum(numpy.abs(meteorVolts0)**2, axis = 0) #Power
3194
3227
3195 #Times reestimation
3228 #Times reestimation
3196 mStart1 = numpy.where(powerNet0[:mPeak] < meteorThresh[:mPeak])[0]
3229 mStart1 = numpy.where(powerNet0[:mPeak] < meteorThresh[:mPeak])[0]
3197 if mStart1.size > 0:
3230 if mStart1.size > 0:
3198 mStart1 = mStart1[-1] + 1
3231 mStart1 = mStart1[-1] + 1
3199
3232
3200 else:
3233 else:
3201 mStart1 = mPeak
3234 mStart1 = mPeak
3202
3235
3203 mEnd1 = numpy.where(powerNet0[mPeak:] < meteorThresh[mPeak:])[0][0] + mPeak - 1
3236 mEnd1 = numpy.where(powerNet0[mPeak:] < meteorThresh[mPeak:])[0][0] + mPeak - 1
3204 mEndDecayTime1 = numpy.where(powerNet0[mPeak:] < meteorNoise[mPeak:])[0]
3237 mEndDecayTime1 = numpy.where(powerNet0[mPeak:] < meteorNoise[mPeak:])[0]
3205 if mEndDecayTime1.size == 0:
3238 if mEndDecayTime1.size == 0:
3206 mEndDecayTime1 = powerNet0.size
3239 mEndDecayTime1 = powerNet0.size
3207 else:
3240 else:
3208 mEndDecayTime1 = mEndDecayTime1[0] + mPeak - 1
3241 mEndDecayTime1 = mEndDecayTime1[0] + mPeak - 1
3209 # mPeak1 = meteorVolts0[mStart1:mEnd1 + 1].argmax()
3242 # mPeak1 = meteorVolts0[mStart1:mEnd1 + 1].argmax()
3210
3243
3211 #meteorVolts1.- all Channels, from start to end
3244 #meteorVolts1.- all Channels, from start to end
3212 meteorVolts1 = meteorVolts0[:,mStart1:mEnd1 + 1]
3245 meteorVolts1 = meteorVolts0[:,mStart1:mEnd1 + 1]
3213 meteorVolts2 = meteorVolts0[:,mPeak + lag:mEnd1 + 1]
3246 meteorVolts2 = meteorVolts0[:,mPeak + lag:mEnd1 + 1]
3214 if meteorVolts2.shape[1] == 0:
3247 if meteorVolts2.shape[1] == 0:
3215 meteorVolts2 = meteorVolts0[:,mPeak:mEnd1 + 1]
3248 meteorVolts2 = meteorVolts0[:,mPeak:mEnd1 + 1]
3216 meteorVolts1 = meteorVolts1.reshape(meteorVolts1.shape[0], meteorVolts1.shape[1], 1)
3249 meteorVolts1 = meteorVolts1.reshape(meteorVolts1.shape[0], meteorVolts1.shape[1], 1)
3217 meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1], 1)
3250 meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1], 1)
3218 ##################### END PARAMETERS REESTIMATION #########################
3251 ##################### END PARAMETERS REESTIMATION #########################
3219
3252
3220 ##################### 3.8 PHASE DIFFERENCE REESTIMATION ########################
3253 ##################### 3.8 PHASE DIFFERENCE REESTIMATION ########################
3221 # if mEnd1 - mStart1 > 4: #Error Number 6: echo less than 5 samples long; too short for analysis
3254 # if mEnd1 - mStart1 > 4: #Error Number 6: echo less than 5 samples long; too short for analysis
3222 if meteorVolts2.shape[1] > 0:
3255 if meteorVolts2.shape[1] > 0:
3223 #Phase Difference re-estimation
3256 #Phase Difference re-estimation
3224 phaseDiff1, phaseDiffint = self.__estimatePhaseDifference(meteorVolts2, pairslist1) #Phase Difference Estimation
3257 phaseDiff1, phaseDiffint = self.__estimatePhaseDifference(meteorVolts2, pairslist1) #Phase Difference Estimation
3225 # phaseDiff1, phaseDiffint = self.estimatePhaseDifference(meteorVolts2, pairslist)
3258 # phaseDiff1, phaseDiffint = self.estimatePhaseDifference(meteorVolts2, pairslist)
3226 meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1])
3259 meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1])
3227 phaseDiff11 = numpy.reshape(phaseDiff1, (phaseDiff1.shape[0],1))
3260 phaseDiff11 = numpy.reshape(phaseDiff1, (phaseDiff1.shape[0],1))
3228 meteorVolts2[indSides,:] = self.__shiftPhase(meteorVolts2[indSides,:], phaseDiff11[0:4]) #Phase Shifting
3261 meteorVolts2[indSides,:] = self.__shiftPhase(meteorVolts2[indSides,:], phaseDiff11[0:4]) #Phase Shifting
3229
3262
3230 #Phase Difference RMS
3263 #Phase Difference RMS
3231 phaseRMS1 = numpy.sqrt(numpy.mean(numpy.square(phaseDiff1)))
3264 phaseRMS1 = numpy.sqrt(numpy.mean(numpy.square(phaseDiff1)))
3232 powerNet1 = numpy.nansum(numpy.abs(meteorVolts1[:,:])**2,0)
3265 powerNet1 = numpy.nansum(numpy.abs(meteorVolts1[:,:])**2,0)
3233 #Data from Meteor
3266 #Data from Meteor
3234 mPeak1 = powerNet1.argmax() + mStart1
3267 mPeak1 = powerNet1.argmax() + mStart1
3235 mPeakPower1 = powerNet1.max()
3268 mPeakPower1 = powerNet1.max()
3236 noiseAux = sum(noise[mStart1:mEnd1 + 1,mHeight])
3269 noiseAux = sum(noise[mStart1:mEnd1 + 1,mHeight])
3237 mSNR1 = (sum(powerNet1)-noiseAux)/noiseAux
3270 mSNR1 = (sum(powerNet1)-noiseAux)/noiseAux
3238 Meteor1 = numpy.array([mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1])
3271 Meteor1 = numpy.array([mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1])
3239 Meteor1 = numpy.hstack((Meteor1,phaseDiffint))
3272 Meteor1 = numpy.hstack((Meteor1,phaseDiffint))
3240 PowerSeries = powerNet0[mStart1:mEndDecayTime1 + 1]
3273 PowerSeries = powerNet0[mStart1:mEndDecayTime1 + 1]
3241 #Vectorize
3274 #Vectorize
3242 meteorAux[0:7] = [mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1]
3275 meteorAux[0:7] = [mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1]
3243 meteorAux[7:11] = phaseDiffint[0:4]
3276 meteorAux[7:11] = phaseDiffint[0:4]
3244
3277
3245 #Rejection Criterions
3278 #Rejection Criterions
3246 if phaseRMS1 > thresholdPhase: #Error Number 17: Phase variation
3279 if phaseRMS1 > thresholdPhase: #Error Number 17: Phase variation
3247 meteorAux[-1] = 17
3280 meteorAux[-1] = 17
3248 elif mSNR1 < thresholdDB1: #Error Number 1: SNR < threshold dB
3281 elif mSNR1 < thresholdDB1: #Error Number 1: SNR < threshold dB
3249 meteorAux[-1] = 1
3282 meteorAux[-1] = 1
3250
3283
3251
3284
3252 else:
3285 else:
3253 meteorAux[0:4] = [mHeight, mStart, mPeak, mEnd]
3286 meteorAux[0:4] = [mHeight, mStart, mPeak, mEnd]
3254 meteorAux[-1] = 6 #Error Number 6: echo less than 5 samples long; too short for analysis
3287 meteorAux[-1] = 6 #Error Number 6: echo less than 5 samples long; too short for analysis
3255 PowerSeries = 0
3288 PowerSeries = 0
3256
3289
3257 listMeteors1.append(meteorAux)
3290 listMeteors1.append(meteorAux)
3258 listPowerSeries.append(PowerSeries)
3291 listPowerSeries.append(PowerSeries)
3259 listVoltageSeries.append(meteorVolts1)
3292 listVoltageSeries.append(meteorVolts1)
3260
3293
3261 return listMeteors1, listPowerSeries, listVoltageSeries
3294 return listMeteors1, listPowerSeries, listVoltageSeries
3262
3295
3263 def __estimateDecayTime(self, listMeteors, listPower, timeInterval, frequency):
3296 def __estimateDecayTime(self, listMeteors, listPower, timeInterval, frequency):
3264
3297
3265 threshError = 10
3298 threshError = 10
3266 #Depending if it is 30 or 50 MHz
3299 #Depending if it is 30 or 50 MHz
3267 if frequency == 30e6:
3300 if frequency == 30e6:
3268 timeLag = 45*10**-3
3301 timeLag = 45*10**-3
3269 else:
3302 else:
3270 timeLag = 15*10**-3
3303 timeLag = 15*10**-3
3271 lag = numpy.ceil(timeLag/timeInterval)
3304 lag = numpy.ceil(timeLag/timeInterval)
3272
3305
3273 listMeteors1 = []
3306 listMeteors1 = []
3274
3307
3275 for i in range(len(listMeteors)):
3308 for i in range(len(listMeteors)):
3276 meteorPower = listPower[i]
3309 meteorPower = listPower[i]
3277 meteorAux = listMeteors[i]
3310 meteorAux = listMeteors[i]
3278
3311
3279 if meteorAux[-1] == 0:
3312 if meteorAux[-1] == 0:
3280
3313
3281 try:
3314 try:
3282 indmax = meteorPower.argmax()
3315 indmax = meteorPower.argmax()
3283 indlag = indmax + lag
3316 indlag = indmax + lag
3284
3317
3285 y = meteorPower[indlag:]
3318 y = meteorPower[indlag:]
3286 x = numpy.arange(0, y.size)*timeLag
3319 x = numpy.arange(0, y.size)*timeLag
3287
3320
3288 #first guess
3321 #first guess
3289 a = y[0]
3322 a = y[0]
3290 tau = timeLag
3323 tau = timeLag
3291 #exponential fit
3324 #exponential fit
3292 popt, pcov = optimize.curve_fit(self.__exponential_function, x, y, p0 = [a, tau])
3325 popt, pcov = optimize.curve_fit(self.__exponential_function, x, y, p0 = [a, tau])
3293 y1 = self.__exponential_function(x, *popt)
3326 y1 = self.__exponential_function(x, *popt)
3294 #error estimation
3327 #error estimation
3295 error = sum((y - y1)**2)/(numpy.var(y)*(y.size - popt.size))
3328 error = sum((y - y1)**2)/(numpy.var(y)*(y.size - popt.size))
3296
3329
3297 decayTime = popt[1]
3330 decayTime = popt[1]
3298 riseTime = indmax*timeInterval
3331 riseTime = indmax*timeInterval
3299 meteorAux[11:13] = [decayTime, error]
3332 meteorAux[11:13] = [decayTime, error]
3300
3333
3301 #Table items 7, 8 and 11
3334 #Table items 7, 8 and 11
3302 if (riseTime > 0.3): #Number 7: Echo rise exceeds 0.3s
3335 if (riseTime > 0.3): #Number 7: Echo rise exceeds 0.3s
3303 meteorAux[-1] = 7
3336 meteorAux[-1] = 7
3304 elif (decayTime < 2*riseTime) : #Number 8: Echo decay time less than than twice rise time
3337 elif (decayTime < 2*riseTime) : #Number 8: Echo decay time less than than twice rise time
3305 meteorAux[-1] = 8
3338 meteorAux[-1] = 8
3306 if (error > threshError): #Number 11: Poor fit to amplitude for estimation of decay time
3339 if (error > threshError): #Number 11: Poor fit to amplitude for estimation of decay time
3307 meteorAux[-1] = 11
3340 meteorAux[-1] = 11
3308
3341
3309
3342
3310 except:
3343 except:
3311 meteorAux[-1] = 11
3344 meteorAux[-1] = 11
3312
3345
3313
3346
3314 listMeteors1.append(meteorAux)
3347 listMeteors1.append(meteorAux)
3315
3348
3316 return listMeteors1
3349 return listMeteors1
3317
3350
3318 #Exponential Function
3351 #Exponential Function
3319
3352
3320 def __exponential_function(self, x, a, tau):
3353 def __exponential_function(self, x, a, tau):
3321 y = a*numpy.exp(-x/tau)
3354 y = a*numpy.exp(-x/tau)
3322 return y
3355 return y
3323
3356
3324 def __getRadialVelocity(self, listMeteors, listVolts, radialStdThresh, pairslist, timeInterval):
3357 def __getRadialVelocity(self, listMeteors, listVolts, radialStdThresh, pairslist, timeInterval):
3325
3358
3326 pairslist1 = list(pairslist)
3359 pairslist1 = list(pairslist)
3327 pairslist1.append((0,1))
3360 pairslist1.append((0,1))
3328 pairslist1.append((3,4))
3361 pairslist1.append((3,4))
3329 numPairs = len(pairslist1)
3362 numPairs = len(pairslist1)
3330 #Time Lag
3363 #Time Lag
3331 timeLag = 45*10**-3
3364 timeLag = 45*10**-3
3332 c = 3e8
3365 c = 3e8
3333 lag = numpy.ceil(timeLag/timeInterval)
3366 lag = numpy.ceil(timeLag/timeInterval)
3334 freq = 30e6
3367 freq = 30e6
3335
3368
3336 listMeteors1 = []
3369 listMeteors1 = []
3337
3370
3338 for i in range(len(listMeteors)):
3371 for i in range(len(listMeteors)):
3339 meteorAux = listMeteors[i]
3372 meteorAux = listMeteors[i]
3340 if meteorAux[-1] == 0:
3373 if meteorAux[-1] == 0:
3341 mStart = listMeteors[i][1]
3374 mStart = listMeteors[i][1]
3342 mPeak = listMeteors[i][2]
3375 mPeak = listMeteors[i][2]
3343 mLag = mPeak - mStart + lag
3376 mLag = mPeak - mStart + lag
3344
3377
3345 #get the volt data between the start and end times of the meteor
3378 #get the volt data between the start and end times of the meteor
3346 meteorVolts = listVolts[i]
3379 meteorVolts = listVolts[i]
3347 meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1)
3380 meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1)
3348
3381
3349 #Get CCF
3382 #Get CCF
3350 allCCFs = self.__calculateCCF(meteorVolts, pairslist1, [-2,-1,0,1,2])
3383 allCCFs = self.__calculateCCF(meteorVolts, pairslist1, [-2,-1,0,1,2])
3351
3384
3352 #Method 2
3385 #Method 2
3353 slopes = numpy.zeros(numPairs)
3386 slopes = numpy.zeros(numPairs)
3354 time = numpy.array([-2,-1,1,2])*timeInterval
3387 time = numpy.array([-2,-1,1,2])*timeInterval
3355 angAllCCF = numpy.angle(allCCFs[:,[0,1,3,4],0])
3388 angAllCCF = numpy.angle(allCCFs[:,[0,1,3,4],0])
3356
3389
3357 #Correct phases
3390 #Correct phases
3358 derPhaseCCF = angAllCCF[:,1:] - angAllCCF[:,0:-1]
3391 derPhaseCCF = angAllCCF[:,1:] - angAllCCF[:,0:-1]
3359 indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi)
3392 indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi)
3360
3393
3361 if indDer[0].shape[0] > 0:
3394 if indDer[0].shape[0] > 0:
3362 for i in range(indDer[0].shape[0]):
3395 for i in range(indDer[0].shape[0]):
3363 signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i]])
3396 signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i]])
3364 angAllCCF[indDer[0][i],indDer[1][i]+1:] += signo*2*numpy.pi
3397 angAllCCF[indDer[0][i],indDer[1][i]+1:] += signo*2*numpy.pi
3365
3398
3366 # fit = scipy.stats.linregress(numpy.array([-2,-1,1,2])*timeInterval, numpy.array([phaseLagN2s[i],phaseLagN1s[i],phaseLag1s[i],phaseLag2s[i]]))
3399 # fit = scipy.stats.linregress(numpy.array([-2,-1,1,2])*timeInterval, numpy.array([phaseLagN2s[i],phaseLagN1s[i],phaseLag1s[i],phaseLag2s[i]]))
3367 for j in range(numPairs):
3400 for j in range(numPairs):
3368 fit = stats.linregress(time, angAllCCF[j,:])
3401 fit = stats.linregress(time, angAllCCF[j,:])
3369 slopes[j] = fit[0]
3402 slopes[j] = fit[0]
3370
3403
3371 #Remove Outlier
3404 #Remove Outlier
3372 # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes)))
3405 # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes)))
3373 # slopes = numpy.delete(slopes,indOut)
3406 # slopes = numpy.delete(slopes,indOut)
3374 # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes)))
3407 # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes)))
3375 # slopes = numpy.delete(slopes,indOut)
3408 # slopes = numpy.delete(slopes,indOut)
3376
3409
3377 radialVelocity = -numpy.mean(slopes)*(0.25/numpy.pi)*(c/freq)
3410 radialVelocity = -numpy.mean(slopes)*(0.25/numpy.pi)*(c/freq)
3378 radialError = numpy.std(slopes)*(0.25/numpy.pi)*(c/freq)
3411 radialError = numpy.std(slopes)*(0.25/numpy.pi)*(c/freq)
3379 meteorAux[-2] = radialError
3412 meteorAux[-2] = radialError
3380 meteorAux[-3] = radialVelocity
3413 meteorAux[-3] = radialVelocity
3381
3414
3382 #Setting Error
3415 #Setting Error
3383 #Number 15: Radial Drift velocity or projected horizontal velocity exceeds 200 m/s
3416 #Number 15: Radial Drift velocity or projected horizontal velocity exceeds 200 m/s
3384 if numpy.abs(radialVelocity) > 200:
3417 if numpy.abs(radialVelocity) > 200:
3385 meteorAux[-1] = 15
3418 meteorAux[-1] = 15
3386 #Number 12: Poor fit to CCF variation for estimation of radial drift velocity
3419 #Number 12: Poor fit to CCF variation for estimation of radial drift velocity
3387 elif radialError > radialStdThresh:
3420 elif radialError > radialStdThresh:
3388 meteorAux[-1] = 12
3421 meteorAux[-1] = 12
3389
3422
3390 listMeteors1.append(meteorAux)
3423 listMeteors1.append(meteorAux)
3391 return listMeteors1
3424 return listMeteors1
3392
3425
3393 def __setNewArrays(self, listMeteors, date, heiRang):
3426 def __setNewArrays(self, listMeteors, date, heiRang):
3394
3427
3395 #New arrays
3428 #New arrays
3396 arrayMeteors = numpy.array(listMeteors)
3429 arrayMeteors = numpy.array(listMeteors)
3397 arrayParameters = numpy.zeros((len(listMeteors), 13))
3430 arrayParameters = numpy.zeros((len(listMeteors), 13))
3398
3431
3399 #Date inclusion
3432 #Date inclusion
3400 # date = re.findall(r'\((.*?)\)', date)
3433 # date = re.findall(r'\((.*?)\)', date)
3401 # date = date[0].split(',')
3434 # date = date[0].split(',')
3402 # date = map(int, date)
3435 # date = map(int, date)
3403 #
3436 #
3404 # if len(date)<6:
3437 # if len(date)<6:
3405 # date.append(0)
3438 # date.append(0)
3406 #
3439 #
3407 # date = [date[0]*10000 + date[1]*100 + date[2], date[3]*10000 + date[4]*100 + date[5]]
3440 # date = [date[0]*10000 + date[1]*100 + date[2], date[3]*10000 + date[4]*100 + date[5]]
3408 # arrayDate = numpy.tile(date, (len(listMeteors), 1))
3441 # arrayDate = numpy.tile(date, (len(listMeteors), 1))
3409 arrayDate = numpy.tile(date, (len(listMeteors)))
3442 arrayDate = numpy.tile(date, (len(listMeteors)))
3410
3443
3411 #Meteor array
3444 #Meteor array
3412 # arrayMeteors[:,0] = heiRang[arrayMeteors[:,0].astype(int)]
3445 # arrayMeteors[:,0] = heiRang[arrayMeteors[:,0].astype(int)]
3413 # arrayMeteors = numpy.hstack((arrayDate, arrayMeteors))
3446 # arrayMeteors = numpy.hstack((arrayDate, arrayMeteors))
3414
3447
3415 #Parameters Array
3448 #Parameters Array
3416 arrayParameters[:,0] = arrayDate #Date
3449 arrayParameters[:,0] = arrayDate #Date
3417 arrayParameters[:,1] = heiRang[arrayMeteors[:,0].astype(int)] #Range
3450 arrayParameters[:,1] = heiRang[arrayMeteors[:,0].astype(int)] #Range
3418 arrayParameters[:,6:8] = arrayMeteors[:,-3:-1] #Radial velocity and its error
3451 arrayParameters[:,6:8] = arrayMeteors[:,-3:-1] #Radial velocity and its error
3419 arrayParameters[:,8:12] = arrayMeteors[:,7:11] #Phases
3452 arrayParameters[:,8:12] = arrayMeteors[:,7:11] #Phases
3420 arrayParameters[:,-1] = arrayMeteors[:,-1] #Error
3453 arrayParameters[:,-1] = arrayMeteors[:,-1] #Error
3421
3454
3422
3455
3423 return arrayParameters
3456 return arrayParameters
3424
3457
3425 class CorrectSMPhases(Operation):
3458 class CorrectSMPhases(Operation):
3426
3459
3427 def run(self, dataOut, phaseOffsets, hmin = 50, hmax = 150, azimuth = 45, channelPositions = None):
3460 def run(self, dataOut, phaseOffsets, hmin = 50, hmax = 150, azimuth = 45, channelPositions = None):
3428
3461
3429 arrayParameters = dataOut.data_param
3462 arrayParameters = dataOut.data_param
3430 pairsList = []
3463 pairsList = []
3431 pairx = (0,1)
3464 pairx = (0,1)
3432 pairy = (2,3)
3465 pairy = (2,3)
3433 pairsList.append(pairx)
3466 pairsList.append(pairx)
3434 pairsList.append(pairy)
3467 pairsList.append(pairy)
3435 jph = numpy.zeros(4)
3468 jph = numpy.zeros(4)
3436
3469
3437 phaseOffsets = numpy.array(phaseOffsets)*numpy.pi/180
3470 phaseOffsets = numpy.array(phaseOffsets)*numpy.pi/180
3438 # arrayParameters[:,8:12] = numpy.unwrap(arrayParameters[:,8:12] + phaseOffsets)
3471 # arrayParameters[:,8:12] = numpy.unwrap(arrayParameters[:,8:12] + phaseOffsets)
3439 arrayParameters[:,8:12] = numpy.angle(numpy.exp(1j*(arrayParameters[:,8:12] + phaseOffsets)))
3472 arrayParameters[:,8:12] = numpy.angle(numpy.exp(1j*(arrayParameters[:,8:12] + phaseOffsets)))
3440
3473
3441 meteorOps = SMOperations()
3474 meteorOps = SMOperations()
3442 if channelPositions == None:
3475 if channelPositions == None:
3443 # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T
3476 # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T
3444 channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella
3477 channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella
3445
3478
3446 pairslist0, distances = meteorOps.getPhasePairs(channelPositions)
3479 pairslist0, distances = meteorOps.getPhasePairs(channelPositions)
3447 h = (hmin,hmax)
3480 h = (hmin,hmax)
3448
3481
3449 arrayParameters = meteorOps.getMeteorParams(arrayParameters, azimuth, h, pairsList, distances, jph)
3482 arrayParameters = meteorOps.getMeteorParams(arrayParameters, azimuth, h, pairsList, distances, jph)
3450
3483
3451 dataOut.data_param = arrayParameters
3484 dataOut.data_param = arrayParameters
3452 return
3485 return
3453
3486
3454 class SMPhaseCalibration(Operation):
3487 class SMPhaseCalibration(Operation):
3455
3488
3456 __buffer = None
3489 __buffer = None
3457
3490
3458 __initime = None
3491 __initime = None
3459
3492
3460 __dataReady = False
3493 __dataReady = False
3461
3494
3462 __isConfig = False
3495 __isConfig = False
3463
3496
3464 def __checkTime(self, currentTime, initTime, paramInterval, outputInterval):
3497 def __checkTime(self, currentTime, initTime, paramInterval, outputInterval):
3465
3498
3466 dataTime = currentTime + paramInterval
3499 dataTime = currentTime + paramInterval
3467 deltaTime = dataTime - initTime
3500 deltaTime = dataTime - initTime
3468
3501
3469 if deltaTime >= outputInterval or deltaTime < 0:
3502 if deltaTime >= outputInterval or deltaTime < 0:
3470 return True
3503 return True
3471
3504
3472 return False
3505 return False
3473
3506
3474 def __getGammas(self, pairs, d, phases):
3507 def __getGammas(self, pairs, d, phases):
3475 gammas = numpy.zeros(2)
3508 gammas = numpy.zeros(2)
3476
3509
3477 for i in range(len(pairs)):
3510 for i in range(len(pairs)):
3478
3511
3479 pairi = pairs[i]
3512 pairi = pairs[i]
3480
3513
3481 phip3 = phases[:,pairi[1]]
3514 phip3 = phases[:,pairi[1]]
3482 d3 = d[pairi[1]]
3515 d3 = d[pairi[1]]
3483 phip2 = phases[:,pairi[0]]
3516 phip2 = phases[:,pairi[0]]
3484 d2 = d[pairi[0]]
3517 d2 = d[pairi[0]]
3485 #Calculating gamma
3518 #Calculating gamma
3486 # jdcos = alp1/(k*d1)
3519 # jdcos = alp1/(k*d1)
3487 # jgamma = numpy.angle(numpy.exp(1j*(d0*alp1/d1 - alp0)))
3520 # jgamma = numpy.angle(numpy.exp(1j*(d0*alp1/d1 - alp0)))
3488 jgamma = -phip2*d3/d2 - phip3
3521 jgamma = -phip2*d3/d2 - phip3
3489 jgamma = numpy.angle(numpy.exp(1j*jgamma))
3522 jgamma = numpy.angle(numpy.exp(1j*jgamma))
3490 # jgamma[jgamma>numpy.pi] -= 2*numpy.pi
3523 # jgamma[jgamma>numpy.pi] -= 2*numpy.pi
3491 # jgamma[jgamma<-numpy.pi] += 2*numpy.pi
3524 # jgamma[jgamma<-numpy.pi] += 2*numpy.pi
3492
3525
3493 #Revised distribution
3526 #Revised distribution
3494 jgammaArray = numpy.hstack((jgamma,jgamma+0.5*numpy.pi,jgamma-0.5*numpy.pi))
3527 jgammaArray = numpy.hstack((jgamma,jgamma+0.5*numpy.pi,jgamma-0.5*numpy.pi))
3495
3528
3496 #Histogram
3529 #Histogram
3497 nBins = 64.0
3530 nBins = 64.0
3498 rmin = -0.5*numpy.pi
3531 rmin = -0.5*numpy.pi
3499 rmax = 0.5*numpy.pi
3532 rmax = 0.5*numpy.pi
3500 phaseHisto = numpy.histogram(jgammaArray, bins=nBins, range=(rmin,rmax))
3533 phaseHisto = numpy.histogram(jgammaArray, bins=nBins, range=(rmin,rmax))
3501
3534
3502 meteorsY = phaseHisto[0]
3535 meteorsY = phaseHisto[0]
3503 phasesX = phaseHisto[1][:-1]
3536 phasesX = phaseHisto[1][:-1]
3504 width = phasesX[1] - phasesX[0]
3537 width = phasesX[1] - phasesX[0]
3505 phasesX += width/2
3538 phasesX += width/2
3506
3539
3507 #Gaussian aproximation
3540 #Gaussian aproximation
3508 bpeak = meteorsY.argmax()
3541 bpeak = meteorsY.argmax()
3509 peak = meteorsY.max()
3542 peak = meteorsY.max()
3510 jmin = bpeak - 5
3543 jmin = bpeak - 5
3511 jmax = bpeak + 5 + 1
3544 jmax = bpeak + 5 + 1
3512
3545
3513 if jmin<0:
3546 if jmin<0:
3514 jmin = 0
3547 jmin = 0
3515 jmax = 6
3548 jmax = 6
3516 elif jmax > meteorsY.size:
3549 elif jmax > meteorsY.size:
3517 jmin = meteorsY.size - 6
3550 jmin = meteorsY.size - 6
3518 jmax = meteorsY.size
3551 jmax = meteorsY.size
3519
3552
3520 x0 = numpy.array([peak,bpeak,50])
3553 x0 = numpy.array([peak,bpeak,50])
3521 coeff = optimize.leastsq(self.__residualFunction, x0, args=(meteorsY[jmin:jmax], phasesX[jmin:jmax]))
3554 coeff = optimize.leastsq(self.__residualFunction, x0, args=(meteorsY[jmin:jmax], phasesX[jmin:jmax]))
3522
3555
3523 #Gammas
3556 #Gammas
3524 gammas[i] = coeff[0][1]
3557 gammas[i] = coeff[0][1]
3525
3558
3526 return gammas
3559 return gammas
3527
3560
3528 def __residualFunction(self, coeffs, y, t):
3561 def __residualFunction(self, coeffs, y, t):
3529
3562
3530 return y - self.__gauss_function(t, coeffs)
3563 return y - self.__gauss_function(t, coeffs)
3531
3564
3532 def __gauss_function(self, t, coeffs):
3565 def __gauss_function(self, t, coeffs):
3533
3566
3534 return coeffs[0]*numpy.exp(-0.5*((t - coeffs[1]) / coeffs[2])**2)
3567 return coeffs[0]*numpy.exp(-0.5*((t - coeffs[1]) / coeffs[2])**2)
3535
3568
3536 def __getPhases(self, azimuth, h, pairsList, d, gammas, meteorsArray):
3569 def __getPhases(self, azimuth, h, pairsList, d, gammas, meteorsArray):
3537 meteorOps = SMOperations()
3570 meteorOps = SMOperations()
3538 nchan = 4
3571 nchan = 4
3539 pairx = pairsList[0]
3572 pairx = pairsList[0]
3540 pairy = pairsList[1]
3573 pairy = pairsList[1]
3541 center_xangle = 0
3574 center_xangle = 0
3542 center_yangle = 0
3575 center_yangle = 0
3543 range_angle = numpy.array([10*numpy.pi,numpy.pi,numpy.pi/2,numpy.pi/4])
3576 range_angle = numpy.array([10*numpy.pi,numpy.pi,numpy.pi/2,numpy.pi/4])
3544 ntimes = len(range_angle)
3577 ntimes = len(range_angle)
3545
3578
3546 nstepsx = 20.0
3579 nstepsx = 20.0
3547 nstepsy = 20.0
3580 nstepsy = 20.0
3548
3581
3549 for iz in range(ntimes):
3582 for iz in range(ntimes):
3550 min_xangle = -range_angle[iz]/2 + center_xangle
3583 min_xangle = -range_angle[iz]/2 + center_xangle
3551 max_xangle = range_angle[iz]/2 + center_xangle
3584 max_xangle = range_angle[iz]/2 + center_xangle
3552 min_yangle = -range_angle[iz]/2 + center_yangle
3585 min_yangle = -range_angle[iz]/2 + center_yangle
3553 max_yangle = range_angle[iz]/2 + center_yangle
3586 max_yangle = range_angle[iz]/2 + center_yangle
3554
3587
3555 inc_x = (max_xangle-min_xangle)/nstepsx
3588 inc_x = (max_xangle-min_xangle)/nstepsx
3556 inc_y = (max_yangle-min_yangle)/nstepsy
3589 inc_y = (max_yangle-min_yangle)/nstepsy
3557
3590
3558 alpha_y = numpy.arange(nstepsy)*inc_y + min_yangle
3591 alpha_y = numpy.arange(nstepsy)*inc_y + min_yangle
3559 alpha_x = numpy.arange(nstepsx)*inc_x + min_xangle
3592 alpha_x = numpy.arange(nstepsx)*inc_x + min_xangle
3560 penalty = numpy.zeros((nstepsx,nstepsy))
3593 penalty = numpy.zeros((nstepsx,nstepsy))
3561 jph_array = numpy.zeros((nchan,nstepsx,nstepsy))
3594 jph_array = numpy.zeros((nchan,nstepsx,nstepsy))
3562 jph = numpy.zeros(nchan)
3595 jph = numpy.zeros(nchan)
3563
3596
3564 # Iterations looking for the offset
3597 # Iterations looking for the offset
3565 for iy in range(int(nstepsy)):
3598 for iy in range(int(nstepsy)):
3566 for ix in range(int(nstepsx)):
3599 for ix in range(int(nstepsx)):
3567 jph[pairy[1]] = alpha_y[iy]
3600 jph[pairy[1]] = alpha_y[iy]
3568 jph[pairy[0]] = -gammas[1] - alpha_y[iy]*d[pairy[1]]/d[pairy[0]]
3601 jph[pairy[0]] = -gammas[1] - alpha_y[iy]*d[pairy[1]]/d[pairy[0]]
3569
3602
3570 jph[pairx[1]] = alpha_x[ix]
3603 jph[pairx[1]] = alpha_x[ix]
3571 jph[pairx[0]] = -gammas[0] - alpha_x[ix]*d[pairx[1]]/d[pairx[0]]
3604 jph[pairx[0]] = -gammas[0] - alpha_x[ix]*d[pairx[1]]/d[pairx[0]]
3572
3605
3573 jph_array[:,ix,iy] = jph
3606 jph_array[:,ix,iy] = jph
3574
3607
3575 meteorsArray1 = meteorOps.getMeteorParams(meteorsArray, azimuth, h, pairsList, d, jph)
3608 meteorsArray1 = meteorOps.getMeteorParams(meteorsArray, azimuth, h, pairsList, d, jph)
3576 error = meteorsArray1[:,-1]
3609 error = meteorsArray1[:,-1]
3577 ind1 = numpy.where(error==0)[0]
3610 ind1 = numpy.where(error==0)[0]
3578 penalty[ix,iy] = ind1.size
3611 penalty[ix,iy] = ind1.size
3579
3612
3580 i,j = numpy.unravel_index(penalty.argmax(), penalty.shape)
3613 i,j = numpy.unravel_index(penalty.argmax(), penalty.shape)
3581 phOffset = jph_array[:,i,j]
3614 phOffset = jph_array[:,i,j]
3582
3615
3583 center_xangle = phOffset[pairx[1]]
3616 center_xangle = phOffset[pairx[1]]
3584 center_yangle = phOffset[pairy[1]]
3617 center_yangle = phOffset[pairy[1]]
3585
3618
3586 phOffset = numpy.angle(numpy.exp(1j*jph_array[:,i,j]))
3619 phOffset = numpy.angle(numpy.exp(1j*jph_array[:,i,j]))
3587 phOffset = phOffset*180/numpy.pi
3620 phOffset = phOffset*180/numpy.pi
3588 return phOffset
3621 return phOffset
3589
3622
3590
3623
3591 def run(self, dataOut, hmin, hmax, channelPositions=None, nHours = 1):
3624 def run(self, dataOut, hmin, hmax, channelPositions=None, nHours = 1):
3592
3625
3593 dataOut.flagNoData = True
3626 dataOut.flagNoData = True
3594 self.__dataReady = False
3627 self.__dataReady = False
3595 dataOut.outputInterval = nHours*3600
3628 dataOut.outputInterval = nHours*3600
3596
3629
3597 if self.__isConfig == False:
3630 if self.__isConfig == False:
3598 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
3631 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
3599 #Get Initial LTC time
3632 #Get Initial LTC time
3600 self.__initime = datetime.datetime.utcfromtimestamp(dataOut.utctime)
3633 self.__initime = datetime.datetime.utcfromtimestamp(dataOut.utctime)
3601 self.__initime = (self.__initime.replace(minute = 0, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
3634 self.__initime = (self.__initime.replace(minute = 0, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
3602
3635
3603 self.__isConfig = True
3636 self.__isConfig = True
3604
3637
3605 if self.__buffer == None:
3638 if self.__buffer == None:
3606 self.__buffer = dataOut.data_param.copy()
3639 self.__buffer = dataOut.data_param.copy()
3607
3640
3608 else:
3641 else:
3609 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
3642 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
3610
3643
3611 self.__dataReady = self.__checkTime(dataOut.utctime, self.__initime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
3644 self.__dataReady = self.__checkTime(dataOut.utctime, self.__initime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
3612
3645
3613 if self.__dataReady:
3646 if self.__dataReady:
3614 dataOut.utctimeInit = self.__initime
3647 dataOut.utctimeInit = self.__initime
3615 self.__initime += dataOut.outputInterval #to erase time offset
3648 self.__initime += dataOut.outputInterval #to erase time offset
3616
3649
3617 freq = dataOut.frequency
3650 freq = dataOut.frequency
3618 c = dataOut.C #m/s
3651 c = dataOut.C #m/s
3619 lamb = c/freq
3652 lamb = c/freq
3620 k = 2*numpy.pi/lamb
3653 k = 2*numpy.pi/lamb
3621 azimuth = 0
3654 azimuth = 0
3622 h = (hmin, hmax)
3655 h = (hmin, hmax)
3623 pairs = ((0,1),(2,3))
3656 pairs = ((0,1),(2,3))
3624
3657
3625 if channelPositions == None:
3658 if channelPositions == None:
3626 # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T
3659 # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T
3627 channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella
3660 channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella
3628 meteorOps = SMOperations()
3661 meteorOps = SMOperations()
3629 pairslist0, distances = meteorOps.getPhasePairs(channelPositions)
3662 pairslist0, distances = meteorOps.getPhasePairs(channelPositions)
3630
3663
3631 # distances1 = [-distances[0]*lamb, distances[1]*lamb, -distances[2]*lamb, distances[3]*lamb]
3664 # distances1 = [-distances[0]*lamb, distances[1]*lamb, -distances[2]*lamb, distances[3]*lamb]
3632
3665
3633 meteorsArray = self.__buffer
3666 meteorsArray = self.__buffer
3634 error = meteorsArray[:,-1]
3667 error = meteorsArray[:,-1]
3635 boolError = (error==0)|(error==3)|(error==4)|(error==13)|(error==14)
3668 boolError = (error==0)|(error==3)|(error==4)|(error==13)|(error==14)
3636 ind1 = numpy.where(boolError)[0]
3669 ind1 = numpy.where(boolError)[0]
3637 meteorsArray = meteorsArray[ind1,:]
3670 meteorsArray = meteorsArray[ind1,:]
3638 meteorsArray[:,-1] = 0
3671 meteorsArray[:,-1] = 0
3639 phases = meteorsArray[:,8:12]
3672 phases = meteorsArray[:,8:12]
3640
3673
3641 #Calculate Gammas
3674 #Calculate Gammas
3642 gammas = self.__getGammas(pairs, distances, phases)
3675 gammas = self.__getGammas(pairs, distances, phases)
3643 # gammas = numpy.array([-21.70409463,45.76935864])*numpy.pi/180
3676 # gammas = numpy.array([-21.70409463,45.76935864])*numpy.pi/180
3644 #Calculate Phases
3677 #Calculate Phases
3645 phasesOff = self.__getPhases(azimuth, h, pairs, distances, gammas, meteorsArray)
3678 phasesOff = self.__getPhases(azimuth, h, pairs, distances, gammas, meteorsArray)
3646 phasesOff = phasesOff.reshape((1,phasesOff.size))
3679 phasesOff = phasesOff.reshape((1,phasesOff.size))
3647 dataOut.data_output = -phasesOff
3680 dataOut.data_output = -phasesOff
3648 dataOut.flagNoData = False
3681 dataOut.flagNoData = False
3649 self.__buffer = None
3682 self.__buffer = None
3650
3683
3651
3684
3652 return
3685 return
3653
3686
3654 class SMOperations():
3687 class SMOperations():
3655
3688
3656 def __init__(self):
3689 def __init__(self):
3657
3690
3658 return
3691 return
3659
3692
3660 def getMeteorParams(self, arrayParameters0, azimuth, h, pairsList, distances, jph):
3693 def getMeteorParams(self, arrayParameters0, azimuth, h, pairsList, distances, jph):
3661
3694
3662 arrayParameters = arrayParameters0.copy()
3695 arrayParameters = arrayParameters0.copy()
3663 hmin = h[0]
3696 hmin = h[0]
3664 hmax = h[1]
3697 hmax = h[1]
3665
3698
3666 #Calculate AOA (Error N 3, 4)
3699 #Calculate AOA (Error N 3, 4)
3667 #JONES ET AL. 1998
3700 #JONES ET AL. 1998
3668 AOAthresh = numpy.pi/8
3701 AOAthresh = numpy.pi/8
3669 error = arrayParameters[:,-1]
3702 error = arrayParameters[:,-1]
3670 phases = -arrayParameters[:,8:12] + jph
3703 phases = -arrayParameters[:,8:12] + jph
3671 # phases = numpy.unwrap(phases)
3704 # phases = numpy.unwrap(phases)
3672 arrayParameters[:,3:6], arrayParameters[:,-1] = self.__getAOA(phases, pairsList, distances, error, AOAthresh, azimuth)
3705 arrayParameters[:,3:6], arrayParameters[:,-1] = self.__getAOA(phases, pairsList, distances, error, AOAthresh, azimuth)
3673
3706
3674 #Calculate Heights (Error N 13 and 14)
3707 #Calculate Heights (Error N 13 and 14)
3675 error = arrayParameters[:,-1]
3708 error = arrayParameters[:,-1]
3676 Ranges = arrayParameters[:,1]
3709 Ranges = arrayParameters[:,1]
3677 zenith = arrayParameters[:,4]
3710 zenith = arrayParameters[:,4]
3678 arrayParameters[:,2], arrayParameters[:,-1] = self.__getHeights(Ranges, zenith, error, hmin, hmax)
3711 arrayParameters[:,2], arrayParameters[:,-1] = self.__getHeights(Ranges, zenith, error, hmin, hmax)
3679
3712
3680 #----------------------- Get Final data ------------------------------------
3713 #----------------------- Get Final data ------------------------------------
3681 # error = arrayParameters[:,-1]
3714 # error = arrayParameters[:,-1]
3682 # ind1 = numpy.where(error==0)[0]
3715 # ind1 = numpy.where(error==0)[0]
3683 # arrayParameters = arrayParameters[ind1,:]
3716 # arrayParameters = arrayParameters[ind1,:]
3684
3717
3685 return arrayParameters
3718 return arrayParameters
3686
3719
3687 def __getAOA(self, phases, pairsList, directions, error, AOAthresh, azimuth):
3720 def __getAOA(self, phases, pairsList, directions, error, AOAthresh, azimuth):
3688
3721
3689 arrayAOA = numpy.zeros((phases.shape[0],3))
3722 arrayAOA = numpy.zeros((phases.shape[0],3))
3690 cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList,directions)
3723 cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList,directions)
3691
3724
3692 arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth)
3725 arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth)
3693 cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1)
3726 cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1)
3694 arrayAOA[:,2] = cosDirError
3727 arrayAOA[:,2] = cosDirError
3695
3728
3696 azimuthAngle = arrayAOA[:,0]
3729 azimuthAngle = arrayAOA[:,0]
3697 zenithAngle = arrayAOA[:,1]
3730 zenithAngle = arrayAOA[:,1]
3698
3731
3699 #Setting Error
3732 #Setting Error
3700 indError = numpy.where(numpy.logical_or(error == 3, error == 4))[0]
3733 indError = numpy.where(numpy.logical_or(error == 3, error == 4))[0]
3701 error[indError] = 0
3734 error[indError] = 0
3702 #Number 3: AOA not fesible
3735 #Number 3: AOA not fesible
3703 indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0]
3736 indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0]
3704 error[indInvalid] = 3
3737 error[indInvalid] = 3
3705 #Number 4: Large difference in AOAs obtained from different antenna baselines
3738 #Number 4: Large difference in AOAs obtained from different antenna baselines
3706 indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0]
3739 indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0]
3707 error[indInvalid] = 4
3740 error[indInvalid] = 4
3708 return arrayAOA, error
3741 return arrayAOA, error
3709
3742
3710 def __getDirectionCosines(self, arrayPhase, pairsList, distances):
3743 def __getDirectionCosines(self, arrayPhase, pairsList, distances):
3711
3744
3712 #Initializing some variables
3745 #Initializing some variables
3713 ang_aux = numpy.array([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])*2*numpy.pi
3746 ang_aux = numpy.array([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])*2*numpy.pi
3714 ang_aux = ang_aux.reshape(1,ang_aux.size)
3747 ang_aux = ang_aux.reshape(1,ang_aux.size)
3715
3748
3716 cosdir = numpy.zeros((arrayPhase.shape[0],2))
3749 cosdir = numpy.zeros((arrayPhase.shape[0],2))
3717 cosdir0 = numpy.zeros((arrayPhase.shape[0],2))
3750 cosdir0 = numpy.zeros((arrayPhase.shape[0],2))
3718
3751
3719
3752
3720 for i in range(2):
3753 for i in range(2):
3721 ph0 = arrayPhase[:,pairsList[i][0]]
3754 ph0 = arrayPhase[:,pairsList[i][0]]
3722 ph1 = arrayPhase[:,pairsList[i][1]]
3755 ph1 = arrayPhase[:,pairsList[i][1]]
3723 d0 = distances[pairsList[i][0]]
3756 d0 = distances[pairsList[i][0]]
3724 d1 = distances[pairsList[i][1]]
3757 d1 = distances[pairsList[i][1]]
3725
3758
3726 ph0_aux = ph0 + ph1
3759 ph0_aux = ph0 + ph1
3727 ph0_aux = numpy.angle(numpy.exp(1j*ph0_aux))
3760 ph0_aux = numpy.angle(numpy.exp(1j*ph0_aux))
3728 # ph0_aux[ph0_aux > numpy.pi] -= 2*numpy.pi
3761 # ph0_aux[ph0_aux > numpy.pi] -= 2*numpy.pi
3729 # ph0_aux[ph0_aux < -numpy.pi] += 2*numpy.pi
3762 # ph0_aux[ph0_aux < -numpy.pi] += 2*numpy.pi
3730 #First Estimation
3763 #First Estimation
3731 cosdir0[:,i] = (ph0_aux)/(2*numpy.pi*(d0 - d1))
3764 cosdir0[:,i] = (ph0_aux)/(2*numpy.pi*(d0 - d1))
3732
3765
3733 #Most-Accurate Second Estimation
3766 #Most-Accurate Second Estimation
3734 phi1_aux = ph0 - ph1
3767 phi1_aux = ph0 - ph1
3735 phi1_aux = phi1_aux.reshape(phi1_aux.size,1)
3768 phi1_aux = phi1_aux.reshape(phi1_aux.size,1)
3736 #Direction Cosine 1
3769 #Direction Cosine 1
3737 cosdir1 = (phi1_aux + ang_aux)/(2*numpy.pi*(d0 + d1))
3770 cosdir1 = (phi1_aux + ang_aux)/(2*numpy.pi*(d0 + d1))
3738
3771
3739 #Searching the correct Direction Cosine
3772 #Searching the correct Direction Cosine
3740 cosdir0_aux = cosdir0[:,i]
3773 cosdir0_aux = cosdir0[:,i]
3741 cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1)
3774 cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1)
3742 #Minimum Distance
3775 #Minimum Distance
3743 cosDiff = (cosdir1 - cosdir0_aux)**2
3776 cosDiff = (cosdir1 - cosdir0_aux)**2
3744 indcos = cosDiff.argmin(axis = 1)
3777 indcos = cosDiff.argmin(axis = 1)
3745 #Saving Value obtained
3778 #Saving Value obtained
3746 cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos]
3779 cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos]
3747
3780
3748 return cosdir0, cosdir
3781 return cosdir0, cosdir
3749
3782
3750 def __calculateAOA(self, cosdir, azimuth):
3783 def __calculateAOA(self, cosdir, azimuth):
3751 cosdirX = cosdir[:,0]
3784 cosdirX = cosdir[:,0]
3752 cosdirY = cosdir[:,1]
3785 cosdirY = cosdir[:,1]
3753
3786
3754 zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi
3787 zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi
3755 azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth#0 deg north, 90 deg east
3788 azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth#0 deg north, 90 deg east
3756 angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose()
3789 angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose()
3757
3790
3758 return angles
3791 return angles
3759
3792
3760 def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight):
3793 def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight):
3761
3794
3762 Ramb = 375 #Ramb = c/(2*PRF)
3795 Ramb = 375 #Ramb = c/(2*PRF)
3763 Re = 6371 #Earth Radius
3796 Re = 6371 #Earth Radius
3764 heights = numpy.zeros(Ranges.shape)
3797 heights = numpy.zeros(Ranges.shape)
3765
3798
3766 R_aux = numpy.array([0,1,2])*Ramb
3799 R_aux = numpy.array([0,1,2])*Ramb
3767 R_aux = R_aux.reshape(1,R_aux.size)
3800 R_aux = R_aux.reshape(1,R_aux.size)
3768
3801
3769 Ranges = Ranges.reshape(Ranges.size,1)
3802 Ranges = Ranges.reshape(Ranges.size,1)
3770
3803
3771 Ri = Ranges + R_aux
3804 Ri = Ranges + R_aux
3772 hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re
3805 hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re
3773
3806
3774 #Check if there is a height between 70 and 110 km
3807 #Check if there is a height between 70 and 110 km
3775 h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1)
3808 h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1)
3776 ind_h = numpy.where(h_bool == 1)[0]
3809 ind_h = numpy.where(h_bool == 1)[0]
3777
3810
3778 hCorr = hi[ind_h, :]
3811 hCorr = hi[ind_h, :]
3779 ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight))
3812 ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight))
3780
3813
3781 hCorr = hi[ind_hCorr]
3814 hCorr = hi[ind_hCorr]
3782 heights[ind_h] = hCorr
3815 heights[ind_h] = hCorr
3783
3816
3784 #Setting Error
3817 #Setting Error
3785 #Number 13: Height unresolvable echo: not valid height within 70 to 110 km
3818 #Number 13: Height unresolvable echo: not valid height within 70 to 110 km
3786 #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km
3819 #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km
3787 indError = numpy.where(numpy.logical_or(error == 13, error == 14))[0]
3820 indError = numpy.where(numpy.logical_or(error == 13, error == 14))[0]
3788 error[indError] = 0
3821 error[indError] = 0
3789 indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0]
3822 indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0]
3790 error[indInvalid2] = 14
3823 error[indInvalid2] = 14
3791 indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0]
3824 indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0]
3792 error[indInvalid1] = 13
3825 error[indInvalid1] = 13
3793
3826
3794 return heights, error
3827 return heights, error
3795
3828
3796 def getPhasePairs(self, channelPositions):
3829 def getPhasePairs(self, channelPositions):
3797 chanPos = numpy.array(channelPositions)
3830 chanPos = numpy.array(channelPositions)
3798 listOper = list(itertools.combinations(range(5),2))
3831 listOper = list(itertools.combinations(range(5),2))
3799
3832
3800 distances = numpy.zeros(4)
3833 distances = numpy.zeros(4)
3801 axisX = []
3834 axisX = []
3802 axisY = []
3835 axisY = []
3803 distX = numpy.zeros(3)
3836 distX = numpy.zeros(3)
3804 distY = numpy.zeros(3)
3837 distY = numpy.zeros(3)
3805 ix = 0
3838 ix = 0
3806 iy = 0
3839 iy = 0
3807
3840
3808 pairX = numpy.zeros((2,2))
3841 pairX = numpy.zeros((2,2))
3809 pairY = numpy.zeros((2,2))
3842 pairY = numpy.zeros((2,2))
3810
3843
3811 for i in range(len(listOper)):
3844 for i in range(len(listOper)):
3812 pairi = listOper[i]
3845 pairi = listOper[i]
3813
3846
3814 posDif = numpy.abs(chanPos[pairi[0],:] - chanPos[pairi[1],:])
3847 posDif = numpy.abs(chanPos[pairi[0],:] - chanPos[pairi[1],:])
3815
3848
3816 if posDif[0] == 0:
3849 if posDif[0] == 0:
3817 axisY.append(pairi)
3850 axisY.append(pairi)
3818 distY[iy] = posDif[1]
3851 distY[iy] = posDif[1]
3819 iy += 1
3852 iy += 1
3820 elif posDif[1] == 0:
3853 elif posDif[1] == 0:
3821 axisX.append(pairi)
3854 axisX.append(pairi)
3822 distX[ix] = posDif[0]
3855 distX[ix] = posDif[0]
3823 ix += 1
3856 ix += 1
3824
3857
3825 for i in range(2):
3858 for i in range(2):
3826 if i==0:
3859 if i==0:
3827 dist0 = distX
3860 dist0 = distX
3828 axis0 = axisX
3861 axis0 = axisX
3829 else:
3862 else:
3830 dist0 = distY
3863 dist0 = distY
3831 axis0 = axisY
3864 axis0 = axisY
3832
3865
3833 side = numpy.argsort(dist0)[:-1]
3866 side = numpy.argsort(dist0)[:-1]
3834 axis0 = numpy.array(axis0)[side,:]
3867 axis0 = numpy.array(axis0)[side,:]
3835 chanC = int(numpy.intersect1d(axis0[0,:], axis0[1,:])[0])
3868 chanC = int(numpy.intersect1d(axis0[0,:], axis0[1,:])[0])
3836 axis1 = numpy.unique(numpy.reshape(axis0,4))
3869 axis1 = numpy.unique(numpy.reshape(axis0,4))
3837 side = axis1[axis1 != chanC]
3870 side = axis1[axis1 != chanC]
3838 diff1 = chanPos[chanC,i] - chanPos[side[0],i]
3871 diff1 = chanPos[chanC,i] - chanPos[side[0],i]
3839 diff2 = chanPos[chanC,i] - chanPos[side[1],i]
3872 diff2 = chanPos[chanC,i] - chanPos[side[1],i]
3840 if diff1<0:
3873 if diff1<0:
3841 chan2 = side[0]
3874 chan2 = side[0]
3842 d2 = numpy.abs(diff1)
3875 d2 = numpy.abs(diff1)
3843 chan1 = side[1]
3876 chan1 = side[1]
3844 d1 = numpy.abs(diff2)
3877 d1 = numpy.abs(diff2)
3845 else:
3878 else:
3846 chan2 = side[1]
3879 chan2 = side[1]
3847 d2 = numpy.abs(diff2)
3880 d2 = numpy.abs(diff2)
3848 chan1 = side[0]
3881 chan1 = side[0]
3849 d1 = numpy.abs(diff1)
3882 d1 = numpy.abs(diff1)
3850
3883
3851 if i==0:
3884 if i==0:
3852 chanCX = chanC
3885 chanCX = chanC
3853 chan1X = chan1
3886 chan1X = chan1
3854 chan2X = chan2
3887 chan2X = chan2
3855 distances[0:2] = numpy.array([d1,d2])
3888 distances[0:2] = numpy.array([d1,d2])
3856 else:
3889 else:
3857 chanCY = chanC
3890 chanCY = chanC
3858 chan1Y = chan1
3891 chan1Y = chan1
3859 chan2Y = chan2
3892 chan2Y = chan2
3860 distances[2:4] = numpy.array([d1,d2])
3893 distances[2:4] = numpy.array([d1,d2])
3861 # axisXsides = numpy.reshape(axisX[ix,:],4)
3894 # axisXsides = numpy.reshape(axisX[ix,:],4)
3862 #
3895 #
3863 # channelCentX = int(numpy.intersect1d(pairX[0,:], pairX[1,:])[0])
3896 # channelCentX = int(numpy.intersect1d(pairX[0,:], pairX[1,:])[0])
3864 # channelCentY = int(numpy.intersect1d(pairY[0,:], pairY[1,:])[0])
3897 # channelCentY = int(numpy.intersect1d(pairY[0,:], pairY[1,:])[0])
3865 #
3898 #
3866 # ind25X = numpy.where(pairX[0,:] != channelCentX)[0][0]
3899 # ind25X = numpy.where(pairX[0,:] != channelCentX)[0][0]
3867 # ind20X = numpy.where(pairX[1,:] != channelCentX)[0][0]
3900 # ind20X = numpy.where(pairX[1,:] != channelCentX)[0][0]
3868 # channel25X = int(pairX[0,ind25X])
3901 # channel25X = int(pairX[0,ind25X])
3869 # channel20X = int(pairX[1,ind20X])
3902 # channel20X = int(pairX[1,ind20X])
3870 # ind25Y = numpy.where(pairY[0,:] != channelCentY)[0][0]
3903 # ind25Y = numpy.where(pairY[0,:] != channelCentY)[0][0]
3871 # ind20Y = numpy.where(pairY[1,:] != channelCentY)[0][0]
3904 # ind20Y = numpy.where(pairY[1,:] != channelCentY)[0][0]
3872 # channel25Y = int(pairY[0,ind25Y])
3905 # channel25Y = int(pairY[0,ind25Y])
3873 # channel20Y = int(pairY[1,ind20Y])
3906 # channel20Y = int(pairY[1,ind20Y])
3874
3907
3875 # pairslist = [(channelCentX, channel25X),(channelCentX, channel20X),(channelCentY,channel25Y),(channelCentY, channel20Y)]
3908 # pairslist = [(channelCentX, channel25X),(channelCentX, channel20X),(channelCentY,channel25Y),(channelCentY, channel20Y)]
3876 pairslist = [(chanCX, chan1X),(chanCX, chan2X),(chanCY,chan1Y),(chanCY, chan2Y)]
3909 pairslist = [(chanCX, chan1X),(chanCX, chan2X),(chanCY,chan1Y),(chanCY, chan2Y)]
3877
3910
3878 return pairslist, distances
3911 return pairslist, distances
3879 # def __getAOA(self, phases, pairsList, error, AOAthresh, azimuth):
3912 # def __getAOA(self, phases, pairsList, error, AOAthresh, azimuth):
3880 #
3913 #
3881 # arrayAOA = numpy.zeros((phases.shape[0],3))
3914 # arrayAOA = numpy.zeros((phases.shape[0],3))
3882 # cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList)
3915 # cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList)
3883 #
3916 #
3884 # arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth)
3917 # arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth)
3885 # cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1)
3918 # cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1)
3886 # arrayAOA[:,2] = cosDirError
3919 # arrayAOA[:,2] = cosDirError
3887 #
3920 #
3888 # azimuthAngle = arrayAOA[:,0]
3921 # azimuthAngle = arrayAOA[:,0]
3889 # zenithAngle = arrayAOA[:,1]
3922 # zenithAngle = arrayAOA[:,1]
3890 #
3923 #
3891 # #Setting Error
3924 # #Setting Error
3892 # #Number 3: AOA not fesible
3925 # #Number 3: AOA not fesible
3893 # indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0]
3926 # indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0]
3894 # error[indInvalid] = 3
3927 # error[indInvalid] = 3
3895 # #Number 4: Large difference in AOAs obtained from different antenna baselines
3928 # #Number 4: Large difference in AOAs obtained from different antenna baselines
3896 # indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0]
3929 # indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0]
3897 # error[indInvalid] = 4
3930 # error[indInvalid] = 4
3898 # return arrayAOA, error
3931 # return arrayAOA, error
3899 #
3932 #
3900 # def __getDirectionCosines(self, arrayPhase, pairsList):
3933 # def __getDirectionCosines(self, arrayPhase, pairsList):
3901 #
3934 #
3902 # #Initializing some variables
3935 # #Initializing some variables
3903 # ang_aux = numpy.array([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])*2*numpy.pi
3936 # ang_aux = numpy.array([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])*2*numpy.pi
3904 # ang_aux = ang_aux.reshape(1,ang_aux.size)
3937 # ang_aux = ang_aux.reshape(1,ang_aux.size)
3905 #
3938 #
3906 # cosdir = numpy.zeros((arrayPhase.shape[0],2))
3939 # cosdir = numpy.zeros((arrayPhase.shape[0],2))
3907 # cosdir0 = numpy.zeros((arrayPhase.shape[0],2))
3940 # cosdir0 = numpy.zeros((arrayPhase.shape[0],2))
3908 #
3941 #
3909 #
3942 #
3910 # for i in range(2):
3943 # for i in range(2):
3911 # #First Estimation
3944 # #First Estimation
3912 # phi0_aux = arrayPhase[:,pairsList[i][0]] + arrayPhase[:,pairsList[i][1]]
3945 # phi0_aux = arrayPhase[:,pairsList[i][0]] + arrayPhase[:,pairsList[i][1]]
3913 # #Dealias
3946 # #Dealias
3914 # indcsi = numpy.where(phi0_aux > numpy.pi)
3947 # indcsi = numpy.where(phi0_aux > numpy.pi)
3915 # phi0_aux[indcsi] -= 2*numpy.pi
3948 # phi0_aux[indcsi] -= 2*numpy.pi
3916 # indcsi = numpy.where(phi0_aux < -numpy.pi)
3949 # indcsi = numpy.where(phi0_aux < -numpy.pi)
3917 # phi0_aux[indcsi] += 2*numpy.pi
3950 # phi0_aux[indcsi] += 2*numpy.pi
3918 # #Direction Cosine 0
3951 # #Direction Cosine 0
3919 # cosdir0[:,i] = -(phi0_aux)/(2*numpy.pi*0.5)
3952 # cosdir0[:,i] = -(phi0_aux)/(2*numpy.pi*0.5)
3920 #
3953 #
3921 # #Most-Accurate Second Estimation
3954 # #Most-Accurate Second Estimation
3922 # phi1_aux = arrayPhase[:,pairsList[i][0]] - arrayPhase[:,pairsList[i][1]]
3955 # phi1_aux = arrayPhase[:,pairsList[i][0]] - arrayPhase[:,pairsList[i][1]]
3923 # phi1_aux = phi1_aux.reshape(phi1_aux.size,1)
3956 # phi1_aux = phi1_aux.reshape(phi1_aux.size,1)
3924 # #Direction Cosine 1
3957 # #Direction Cosine 1
3925 # cosdir1 = -(phi1_aux + ang_aux)/(2*numpy.pi*4.5)
3958 # cosdir1 = -(phi1_aux + ang_aux)/(2*numpy.pi*4.5)
3926 #
3959 #
3927 # #Searching the correct Direction Cosine
3960 # #Searching the correct Direction Cosine
3928 # cosdir0_aux = cosdir0[:,i]
3961 # cosdir0_aux = cosdir0[:,i]
3929 # cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1)
3962 # cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1)
3930 # #Minimum Distance
3963 # #Minimum Distance
3931 # cosDiff = (cosdir1 - cosdir0_aux)**2
3964 # cosDiff = (cosdir1 - cosdir0_aux)**2
3932 # indcos = cosDiff.argmin(axis = 1)
3965 # indcos = cosDiff.argmin(axis = 1)
3933 # #Saving Value obtained
3966 # #Saving Value obtained
3934 # cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos]
3967 # cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos]
3935 #
3968 #
3936 # return cosdir0, cosdir
3969 # return cosdir0, cosdir
3937 #
3970 #
3938 # def __calculateAOA(self, cosdir, azimuth):
3971 # def __calculateAOA(self, cosdir, azimuth):
3939 # cosdirX = cosdir[:,0]
3972 # cosdirX = cosdir[:,0]
3940 # cosdirY = cosdir[:,1]
3973 # cosdirY = cosdir[:,1]
3941 #
3974 #
3942 # zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi
3975 # zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi
3943 # azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth #0 deg north, 90 deg east
3976 # azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth #0 deg north, 90 deg east
3944 # angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose()
3977 # angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose()
3945 #
3978 #
3946 # return angles
3979 # return angles
3947 #
3980 #
3948 # def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight):
3981 # def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight):
3949 #
3982 #
3950 # Ramb = 375 #Ramb = c/(2*PRF)
3983 # Ramb = 375 #Ramb = c/(2*PRF)
3951 # Re = 6371 #Earth Radius
3984 # Re = 6371 #Earth Radius
3952 # heights = numpy.zeros(Ranges.shape)
3985 # heights = numpy.zeros(Ranges.shape)
3953 #
3986 #
3954 # R_aux = numpy.array([0,1,2])*Ramb
3987 # R_aux = numpy.array([0,1,2])*Ramb
3955 # R_aux = R_aux.reshape(1,R_aux.size)
3988 # R_aux = R_aux.reshape(1,R_aux.size)
3956 #
3989 #
3957 # Ranges = Ranges.reshape(Ranges.size,1)
3990 # Ranges = Ranges.reshape(Ranges.size,1)
3958 #
3991 #
3959 # Ri = Ranges + R_aux
3992 # Ri = Ranges + R_aux
3960 # hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re
3993 # hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re
3961 #
3994 #
3962 # #Check if there is a height between 70 and 110 km
3995 # #Check if there is a height between 70 and 110 km
3963 # h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1)
3996 # h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1)
3964 # ind_h = numpy.where(h_bool == 1)[0]
3997 # ind_h = numpy.where(h_bool == 1)[0]
3965 #
3998 #
3966 # hCorr = hi[ind_h, :]
3999 # hCorr = hi[ind_h, :]
3967 # ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight))
4000 # ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight))
3968 #
4001 #
3969 # hCorr = hi[ind_hCorr]
4002 # hCorr = hi[ind_hCorr]
3970 # heights[ind_h] = hCorr
4003 # heights[ind_h] = hCorr
3971 #
4004 #
3972 # #Setting Error
4005 # #Setting Error
3973 # #Number 13: Height unresolvable echo: not valid height within 70 to 110 km
4006 # #Number 13: Height unresolvable echo: not valid height within 70 to 110 km
3974 # #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km
4007 # #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km
3975 #
4008 #
3976 # indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0]
4009 # indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0]
3977 # error[indInvalid2] = 14
4010 # error[indInvalid2] = 14
3978 # indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0]
4011 # indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0]
3979 # error[indInvalid1] = 13
4012 # error[indInvalid1] = 13
3980 #
4013 #
3981 # return heights, error
4014 # return heights, error
3982 No newline at end of file
4015
@@ -1,1 +1,1
1 <Project description="Segundo Test" id="191" name="test01"><ReadUnit datatype="SpectraReader" id="1911" inputId="0" name="SpectraReader"><Operation id="19111" name="run" priority="1" type="self"><Parameter format="str" id="191111" name="datatype" value="SpectraReader" /><Parameter format="str" id="191112" name="path" value="/media/erick/6F60F7113095A154/CLAIRE/CLAIRE_WINDS_2MHZ/DATA/pdataCLAIRE/Extra" /><Parameter format="date" id="191113" name="startDate" value="2018/02/01" /><Parameter format="date" id="191114" name="endDate" value="2018/02/01" /><Parameter format="time" id="191115" name="startTime" value="17:00:00" /><Parameter format="time" id="191116" name="endTime" value="20:00:00" /><Parameter format="int" id="191118" name="online" value="0" /><Parameter format="int" id="191119" name="walk" value="1" /></Operation><Operation id="19112" name="printInfo" priority="2" type="self" /><Operation id="19113" name="printNumberOfBlock" priority="3" type="self" /></ReadUnit><ProcUnit datatype="Parameters" id="1913" inputId="1912" name="ParametersProc"><Operation id="19131" name="run" priority="1" type="self" /><Operation id="19132" name="SpectralFilters" priority="2" type="other"><Parameter format="float" id="191321" name="Wind_Velocity_Limit" value="2.5" /><Parameter format="float" id="191322" name="Rain_Velocity_Limit" value="1.5" /></Operation><Operation id="19133" name="FullSpectralAnalysis" priority="3" type="other"><Parameter format="float" id="191331" name="SNRlimit" value="-16" /><Parameter format="float" id="191332" name="E01" value="1.500" /><Parameter format="float" id="191333" name="E02" value="1.500" /><Parameter format="float" id="191334" name="E12" value="0" /><Parameter format="float" id="191335" name="N01" value="0.875" /><Parameter format="float" id="191336" name="N02" value="-0.875" /><Parameter format="float" id="191337" name="N12" value="-1.750" /></Operation><Operation id="19134" name="WindProfilerPlot" priority="4" type="other"><Parameter format="int" id="191341" name="id" value="4" /><Parameter format="str" id="191342" name="wintitle" value="Wind Profiler" /><Parameter format="float" id="191343" name="xmin" value="17" /><Parameter format="float" id="191344" name="xmax" value="20" /><Parameter format="float" id="191345" name="ymin" value="0" /><Parameter format="int" id="191346" name="ymax" value="8" /><Parameter format="float" id="191347" name="zmin" value="-20" /><Parameter format="float" id="191348" name="zmax" value="20" /><Parameter format="float" id="191349" name="SNRmin" value="-20" /><Parameter format="float" id="191350" name="SNRmax" value="20" /><Parameter format="float" id="191351" name="zmin_ver" value="-200" /><Parameter format="float" id="191352" name="zmax_ver" value="200" /><Parameter format="float" id="191353" name="SNRthresh" value="-20" /><Parameter format="int" id="191354" name="save" value="1" /><Parameter format="str" id="191355" name="figpath" value="/media/erick/6F60F7113095A154/CLAIRE/CLAIRE_WINDS_2MHZ/DATA/pdataCLAIRE/Extra" /></Operation><Operation id="19135" name="PrecipitationProc" priority="5" type="other" /><Operation id="19136" name="ParametersPlot" priority="6" type="other"><Parameter format="int" id="191361" name="id" value="10" /><Parameter format="str" id="191362" name="wintitle" value="First_gg" /><Parameter format="int" id="191363" name="zmin" value="-20" /><Parameter format="int" id="191364" name="zmax" value="60" /><Parameter format="int" id="191365" name="ymin" value="0" /><Parameter format="int" id="191366" name="ymax" value="8" /><Parameter format="int" id="191367" name="xmin" value="17" /><Parameter format="int" id="191368" name="xmax" value="20" /><Parameter format="int" id="191369" name="save" value="1" /><Parameter format="str" id="191370" name="figpath" value="/media/erick/6F60F7113095A154/CLAIRE/CLAIRE_WINDS_2MHZ/DATA/pdataCLAIRE/Extra" /></Operation><Operation id="19137" name="ParamWriter" priority="7" type="other"><Parameter format="str" id="191371" name="path" value="/media/erick/6F60F7113095A154/CLAIRE/CLAIRE_WINDS_2MHZ/DATA/pdatatest/test1024" /><Parameter format="int" id="191372" name="blocksPerFile" value="100" /><Parameter format="list" id="191373" name="metadataList" value="heightList,timeZone,paramInterval" /><Parameter format="list" id="191374" name="dataList" value="data_output,data_SNR,utctime,utctimeInit" /></Operation></ProcUnit><ProcUnit datatype="SpectraProc" id="1912" inputId="1911" name="SpectraProc"><Operation id="19121" name="run" priority="1" type="self" /><Operation id="19122" name="setRadarFrequency" priority="2" type="self"><Parameter format="float" id="191221" name="frequency" value="445.09e6" /></Operation></ProcUnit></Project> No newline at end of file
1 <Project description="Segundo Test" id="191" name="test01"><ReadUnit datatype="SpectraReader" id="1911" inputId="0" name="SpectraReader"><Operation id="19111" name="run" priority="1" type="self"><Parameter format="str" id="191111" name="datatype" value="SpectraReader" /><Parameter format="str" id="191112" name="path" value="/media/erick/6F60F7113095A154/CLAIRE/CLAIRE_WINDS_2MHZ/DATA/pdataCLAIRE/Extra" /><Parameter format="date" id="191113" name="startDate" value="2018/02/01" /><Parameter format="date" id="191114" name="endDate" value="2018/02/01" /><Parameter format="time" id="191115" name="startTime" value="17:00:00" /><Parameter format="time" id="191116" name="endTime" value="20:00:00" /><Parameter format="int" id="191118" name="online" value="0" /><Parameter format="int" id="191119" name="walk" value="1" /></Operation><Operation id="19112" name="printInfo" priority="2" type="self" /><Operation id="19113" name="printNumberOfBlock" priority="3" type="self" /></ReadUnit><ProcUnit datatype="Parameters" id="1913" inputId="1912" name="ParametersProc"><Operation id="19131" name="run" priority="1" type="self" /><Operation id="19132" name="SpectralFilters" priority="2" type="other"><Parameter format="float" id="191321" name="PositiveLimit" value="1.5" /><Parameter format="float" id="191322" name="NegativeLimit" value="3.5" /></Operation><Operation id="19133" name="FullSpectralAnalysis" priority="3" type="other"><Parameter format="float" id="191331" name="SNRlimit" value="-16" /><Parameter format="float" id="191332" name="E01" value="1.500" /><Parameter format="float" id="191333" name="E02" value="1.500" /><Parameter format="float" id="191334" name="E12" value="0" /><Parameter format="float" id="191335" name="N01" value="0.875" /><Parameter format="float" id="191336" name="N02" value="-0.875" /><Parameter format="float" id="191337" name="N12" value="-1.750" /></Operation><Operation id="19134" name="WindProfilerPlot" priority="4" type="other"><Parameter format="int" id="191341" name="id" value="4" /><Parameter format="str" id="191342" name="wintitle" value="Wind Profiler" /><Parameter format="float" id="191343" name="xmin" value="17" /><Parameter format="float" id="191344" name="xmax" value="20" /><Parameter format="float" id="191345" name="ymin" value="0" /><Parameter format="int" id="191346" name="ymax" value="11" /><Parameter format="float" id="191347" name="zmin" value="-20" /><Parameter format="float" id="191348" name="zmax" value="20" /><Parameter format="float" id="191349" name="SNRmin" value="-20" /><Parameter format="float" id="191350" name="SNRmax" value="20" /><Parameter format="float" id="191351" name="zmin_ver" value="-200" /><Parameter format="float" id="191352" name="zmax_ver" value="200" /><Parameter format="float" id="191353" name="SNRthresh" value="-20" /><Parameter format="int" id="191354" name="save" value="1" /><Parameter format="str" id="191355" name="figpath" value="/media/erick/6F60F7113095A154/CLAIRE/CLAIRE_WINDS_2MHZ/DATA/pdataCLAIRE/Extra" /></Operation><Operation id="19135" name="PrecipitationProc" priority="5" type="other" /><Operation id="19136" name="ParametersPlot" priority="6" type="other"><Parameter format="int" id="191361" name="id" value="10" /><Parameter format="str" id="191362" name="wintitle" value="First_gg" /><Parameter format="str" id="191363" name="colormap" value="ocean_r" /><Parameter format="int" id="191364" name="zmin" value="50" /><Parameter format="int" id="191365" name="zmax" value="100" /><Parameter format="int" id="191366" name="ymin" value="0" /><Parameter format="int" id="191367" name="ymax" value="11" /><Parameter format="int" id="191368" name="xmin" value="17" /><Parameter format="int" id="191369" name="xmax" value="20" /><Parameter format="int" id="191370" name="save" value="1" /><Parameter format="str" id="191371" name="figpath" value="/media/erick/6F60F7113095A154/CLAIRE/CLAIRE_WINDS_2MHZ/DATA/pdataCLAIRE/Extra" /></Operation><Operation id="19137" name="SpcParamPlot" priority="7" type="other"><Parameter format="int" id="191371" name="id" value="21" /><Parameter format="str" id="191372" name="wintitle" value="Primer eco removido" /><Parameter format="str" id="191373" name="xaxis" value="velocity" /><Parameter format="int" id="191374" name="showprofile" value="1" /><Parameter format="int" id="191375" name="zmin" value="10" /><Parameter format="int" id="191376" name="zmax" value="40" /><Parameter format="int" id="191377" name="Selector" value="1" /></Operation><Operation id="19138" name="ParamWriter" priority="8" type="other"><Parameter format="str" id="191381" name="path" value="/media/erick/6F60F7113095A154/CLAIRE/CLAIRE_WINDS_2MHZ/DATA/pdatatest/test1024" /><Parameter format="int" id="191382" name="blocksPerFile" value="100" /><Parameter format="list" id="191383" name="metadataList" value="heightList,timeZone,paramInterval" /><Parameter format="list" id="191384" name="dataList" value="data_output,data_SNR,utctime,utctimeInit" /></Operation></ProcUnit><ProcUnit datatype="SpectraProc" id="1912" inputId="1911" name="SpectraProc"><Operation id="19121" name="run" priority="1" type="self" /><Operation id="19122" name="setRadarFrequency" priority="2" type="self"><Parameter format="float" id="191221" name="frequency" value="445.09e6" /></Operation></ProcUnit></Project> No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now