##// END OF EJS Templates
07/09/2017
ebocanegra -
r1027:f11c2da27e74
parent child
Show More
@@ -1,1541 +1,1584
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
11
10 from figure import Figure, isRealtime, isTimeInHourRange
12 from figure import Figure, isRealtime, isTimeInHourRange
11 from plotting_codes import *
13 from plotting_codes import *
14 from matplotlib.pyplot import savefig
12
15
13 class SpectraPlot(Figure):
16 class SpectraPlot(Figure):
14
17
15 isConfig = None
18 isConfig = None
16 __nsubplots = None
19 __nsubplots = None
17
20
18 WIDTHPROF = None
21 WIDTHPROF = None
19 HEIGHTPROF = None
22 HEIGHTPROF = None
20 PREFIX = 'spc'
23 PREFIX = 'spc'
21
24
22 def __init__(self, **kwargs):
25 def __init__(self, **kwargs):
23 Figure.__init__(self, **kwargs)
26 Figure.__init__(self, **kwargs)
24 self.isConfig = False
27 self.isConfig = False
25 self.__nsubplots = 1
28 self.__nsubplots = 1
26
29
27 self.WIDTH = 250
30 self.WIDTH = 250
28 self.HEIGHT = 250
31 self.HEIGHT = 250
29 self.WIDTHPROF = 120
32 self.WIDTHPROF = 120
30 self.HEIGHTPROF = 0
33 self.HEIGHTPROF = 0
31 self.counter_imagwr = 0
34 self.counter_imagwr = 0
32
35
33 self.PLOT_CODE = SPEC_CODE
36 self.PLOT_CODE = SPEC_CODE
34
37
35 self.FTP_WEI = None
38 self.FTP_WEI = None
36 self.EXP_CODE = None
39 self.EXP_CODE = None
37 self.SUB_EXP_CODE = None
40 self.SUB_EXP_CODE = None
38 self.PLOT_POS = None
41 self.PLOT_POS = None
39
42
40 self.__xfilter_ena = False
43 self.__xfilter_ena = False
41 self.__yfilter_ena = False
44 self.__yfilter_ena = False
45
46 self.indice=1
42
47
43 def getSubplots(self):
48 def getSubplots(self):
44
49
45 ncol = int(numpy.sqrt(self.nplots)+0.9)
50 ncol = int(numpy.sqrt(self.nplots)+0.9)
46 nrow = int(self.nplots*1./ncol + 0.9)
51 nrow = int(self.nplots*1./ncol + 0.9)
47
52
48 return nrow, ncol
53 return nrow, ncol
49
54
50 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
55 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
51
56
52 self.__showprofile = showprofile
57 self.__showprofile = showprofile
53 self.nplots = nplots
58 self.nplots = nplots
54
59
55 ncolspan = 1
60 ncolspan = 1
56 colspan = 1
61 colspan = 1
57 if showprofile:
62 if showprofile:
58 ncolspan = 3
63 ncolspan = 3
59 colspan = 2
64 colspan = 2
60 self.__nsubplots = 2
65 self.__nsubplots = 2
61
66
62 self.createFigure(id = id,
67 self.createFigure(id = id,
63 wintitle = wintitle,
68 wintitle = wintitle,
64 widthplot = self.WIDTH + self.WIDTHPROF,
69 widthplot = self.WIDTH + self.WIDTHPROF,
65 heightplot = self.HEIGHT + self.HEIGHTPROF,
70 heightplot = self.HEIGHT + self.HEIGHTPROF,
66 show=show)
71 show=show)
67
72
68 nrow, ncol = self.getSubplots()
73 nrow, ncol = self.getSubplots()
69
74
70 counter = 0
75 counter = 0
71 for y in range(nrow):
76 for y in range(nrow):
72 for x in range(ncol):
77 for x in range(ncol):
73
78
74 if counter >= self.nplots:
79 if counter >= self.nplots:
75 break
80 break
76
81
77 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
82 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
78
83
79 if showprofile:
84 if showprofile:
80 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
85 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
81
86
82 counter += 1
87 counter += 1
83
88
84 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
89 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
85 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,
86 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,
87 server=None, folder=None, username=None, password=None,
92 server=None, folder=None, username=None, password=None,
88 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,
89 xaxis="frequency", colormap='jet', normFactor=None):
94 xaxis="frequency", colormap='jet', normFactor=None):
90
95
91 """
96 """
92
97
93 Input:
98 Input:
94 dataOut :
99 dataOut :
95 id :
100 id :
96 wintitle :
101 wintitle :
97 channelList :
102 channelList :
98 showProfile :
103 showProfile :
99 xmin : None,
104 xmin : None,
100 xmax : None,
105 xmax : None,
101 ymin : None,
106 ymin : None,
102 ymax : None,
107 ymax : None,
103 zmin : None,
108 zmin : None,
104 zmax : None
109 zmax : None
105 """
110 """
106 if realtime:
111 if realtime:
107 if not(isRealtime(utcdatatime = dataOut.utctime)):
112 if not(isRealtime(utcdatatime = dataOut.utctime)):
108 print 'Skipping this plot function'
113 print 'Skipping this plot function'
109 return
114 return
110
115
111 if channelList == None:
116 if channelList == None:
112 channelIndexList = dataOut.channelIndexList
117 channelIndexList = dataOut.channelIndexList
113 else:
118 else:
114 channelIndexList = []
119 channelIndexList = []
115 for channel in channelList:
120 for channel in channelList:
116 if channel not in dataOut.channelList:
121 if channel not in dataOut.channelList:
117 raise ValueError, "Channel %d is not in dataOut.channelList" %channel
122 raise ValueError, "Channel %d is not in dataOut.channelList" %channel
118 channelIndexList.append(dataOut.channelList.index(channel))
123 channelIndexList.append(dataOut.channelList.index(channel))
119
124
120 if normFactor is None:
125 if normFactor is None:
121 factor = dataOut.normFactor
126 factor = dataOut.normFactor
122 else:
127 else:
123 factor = normFactor
128 factor = normFactor
124 if xaxis == "frequency":
129 if xaxis == "frequency":
125 x = dataOut.getFreqRange(1)/1000.
130 x = dataOut.getFreqRange(1)/1000.
126 xlabel = "Frequency (kHz)"
131 xlabel = "Frequency (kHz)"
127
132
128 elif xaxis == "time":
133 elif xaxis == "time":
129 x = dataOut.getAcfRange(1)
134 x = dataOut.getAcfRange(1)
130 xlabel = "Time (ms)"
135 xlabel = "Time (ms)"
131
136
132 else:
137 else:
133 x = dataOut.getVelRange(1)
138 x = dataOut.getVelRange(1)
134 xlabel = "Velocity (m/s)"
139 xlabel = "Velocity (m/s)"
135
140
136 ylabel = "Range (Km)"
141 ylabel = "Range (Km)"
137
142
138 y = dataOut.getHeiRange()
143 y = dataOut.getHeiRange()
139
144
140 z = dataOut.data_spc/factor
145 z = dataOut.data_spc/factor
141 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
146 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
142 zdB = 10*numpy.log10(z)
147 zdB = 10*numpy.log10(z)
143
148
144 avg = numpy.average(z, axis=1)
149 avg = numpy.average(z, axis=1)
145 avgdB = 10*numpy.log10(avg)
150 avgdB = 10*numpy.log10(avg)
146
151
147 noise = dataOut.getNoise()/factor
152 noise = dataOut.getNoise()/factor
148 noisedB = 10*numpy.log10(noise)
153 noisedB = 10*numpy.log10(noise)
149
154
150 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
155 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
151 title = wintitle + " Spectra"
156 title = wintitle + " Spectra"
157
158
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)
161 print 'Altura:', y[0], y[1], y[13], y[14], y[10]
162 #a=z[1,:,15]
163
164 # fig = plt.figure(10+self.indice)
165 # plt.plot( x[0:128], zdB[0,:,10] )
166 # plt.axis([-12, 12, 15, 50])
167 # plt.title(" %s" %( '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))) )
168 # plt.ylabel('Intensidad [dB]')
169 # plt.xlabel('Velocidad [m/s]')
170 # fig.savefig('/home/erick/Documents/Pics/to{}.png'.format(self.indice))
171 #
172 # plt.show()
173 #
174 # self.indice=self.indice+1
175
176
177
152 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
178 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
153 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)
154
180
155 if not self.isConfig:
181 if not self.isConfig:
156
182
157 nplots = len(channelIndexList)
183 nplots = len(channelIndexList)
158
184
159 self.setup(id=id,
185 self.setup(id=id,
160 nplots=nplots,
186 nplots=nplots,
161 wintitle=wintitle,
187 wintitle=wintitle,
162 showprofile=showprofile,
188 showprofile=showprofile,
163 show=show)
189 show=show)
164
190
165 if xmin == None: xmin = numpy.nanmin(x)
191 if xmin == None: xmin = numpy.nanmin(x)
166 if xmax == None: xmax = numpy.nanmax(x)
192 if xmax == None: xmax = numpy.nanmax(x)
167 if ymin == None: ymin = numpy.nanmin(y)
193 if ymin == None: ymin = numpy.nanmin(y)
168 if ymax == None: ymax = numpy.nanmax(y)
194 if ymax == None: ymax = numpy.nanmax(y)
169 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
195 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
170 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
196 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
171
197
172 self.FTP_WEI = ftp_wei
198 self.FTP_WEI = ftp_wei
173 self.EXP_CODE = exp_code
199 self.EXP_CODE = exp_code
174 self.SUB_EXP_CODE = sub_exp_code
200 self.SUB_EXP_CODE = sub_exp_code
175 self.PLOT_POS = plot_pos
201 self.PLOT_POS = plot_pos
176
202
177 self.isConfig = True
203 self.isConfig = True
178
204
179 self.setWinTitle(title)
205 self.setWinTitle(title)
180
206
181 for i in range(self.nplots):
207 for i in range(self.nplots):
182 index = channelIndexList[i]
208 index = channelIndexList[i]
183 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"))
184 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)
185 if len(dataOut.beam.codeList) != 0:
211 if len(dataOut.beam.codeList) != 0:
186 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)
187
213
188 axes = self.axesList[i*self.__nsubplots]
214 axes = self.axesList[i*self.__nsubplots]
189 axes.pcolor(x, y, zdB[index,:,:],
215 axes.pcolor(x, y, zdB[index,:,:],
190 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,
191 xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap,
217 xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap,
192 ticksize=9, cblabel='')
218 ticksize=9, cblabel='')
193
219
194 if self.__showprofile:
220 if self.__showprofile:
195 axes = self.axesList[i*self.__nsubplots +1]
221 axes = self.axesList[i*self.__nsubplots +1]
196 axes.pline(avgdB[index,:], y,
222 axes.pline(avgdB[index,:], y,
197 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
223 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
198 xlabel='dB', ylabel='', title='',
224 xlabel='dB', ylabel='', title='',
199 ytick_visible=False,
225 ytick_visible=False,
200 grid='x')
226 grid='x')
201
227
202 noiseline = numpy.repeat(noisedB[index], len(y))
228 noiseline = numpy.repeat(noisedB[index], len(y))
203 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)
204
230
205 self.draw()
231 self.draw()
206
232
207 if figfile == None:
233 if figfile == None:
208 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
234 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
209 name = str_datetime
235 name = str_datetime
210 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
236 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
211 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)
212 figfile = self.getFilename(name)
238 figfile = self.getFilename(name)
213
239
214 self.save(figpath=figpath,
240 self.save(figpath=figpath,
215 figfile=figfile,
241 figfile=figfile,
216 save=save,
242 save=save,
217 ftp=ftp,
243 ftp=ftp,
218 wr_period=wr_period,
244 wr_period=wr_period,
219 thisDatetime=thisDatetime)
245 thisDatetime=thisDatetime)
246
220
247
221 class CrossSpectraPlot(Figure):
248 class CrossSpectraPlot(Figure):
222
249
223 isConfig = None
250 isConfig = None
224 __nsubplots = None
251 __nsubplots = None
225
252
226 WIDTH = None
253 WIDTH = None
227 HEIGHT = None
254 HEIGHT = None
228 WIDTHPROF = None
255 WIDTHPROF = None
229 HEIGHTPROF = None
256 HEIGHTPROF = None
230 PREFIX = 'cspc'
257 PREFIX = 'cspc'
231
258
232 def __init__(self, **kwargs):
259 def __init__(self, **kwargs):
233 Figure.__init__(self, **kwargs)
260 Figure.__init__(self, **kwargs)
234 self.isConfig = False
261 self.isConfig = False
235 self.__nsubplots = 4
262 self.__nsubplots = 4
236 self.counter_imagwr = 0
263 self.counter_imagwr = 0
237 self.WIDTH = 250
264 self.WIDTH = 250
238 self.HEIGHT = 250
265 self.HEIGHT = 250
239 self.WIDTHPROF = 0
266 self.WIDTHPROF = 0
240 self.HEIGHTPROF = 0
267 self.HEIGHTPROF = 0
241
268
242 self.PLOT_CODE = CROSS_CODE
269 self.PLOT_CODE = CROSS_CODE
243 self.FTP_WEI = None
270 self.FTP_WEI = None
244 self.EXP_CODE = None
271 self.EXP_CODE = None
245 self.SUB_EXP_CODE = None
272 self.SUB_EXP_CODE = None
246 self.PLOT_POS = None
273 self.PLOT_POS = None
274
275 self.indice=0
247
276
248 def getSubplots(self):
277 def getSubplots(self):
249
278
250 ncol = 4
279 ncol = 4
251 nrow = self.nplots
280 nrow = self.nplots
252
281
253 return nrow, ncol
282 return nrow, ncol
254
283
255 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
284 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
256
285
257 self.__showprofile = showprofile
286 self.__showprofile = showprofile
258 self.nplots = nplots
287 self.nplots = nplots
259
288
260 ncolspan = 1
289 ncolspan = 1
261 colspan = 1
290 colspan = 1
262
291
263 self.createFigure(id = id,
292 self.createFigure(id = id,
264 wintitle = wintitle,
293 wintitle = wintitle,
265 widthplot = self.WIDTH + self.WIDTHPROF,
294 widthplot = self.WIDTH + self.WIDTHPROF,
266 heightplot = self.HEIGHT + self.HEIGHTPROF,
295 heightplot = self.HEIGHT + self.HEIGHTPROF,
267 show=True)
296 show=True)
268
297
269 nrow, ncol = self.getSubplots()
298 nrow, ncol = self.getSubplots()
270
299
271 counter = 0
300 counter = 0
272 for y in range(nrow):
301 for y in range(nrow):
273 for x in range(ncol):
302 for x in range(ncol):
274 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
303 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
275
304
276 counter += 1
305 counter += 1
277
306
278 def run(self, dataOut, id, wintitle="", pairsList=None,
307 def run(self, dataOut, id, wintitle="", pairsList=None,
279 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,
280 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,
281 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
310 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
282 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,
283 server=None, folder=None, username=None, password=None,
312 server=None, folder=None, username=None, password=None,
284 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,
285 xaxis='frequency'):
314 xaxis='frequency'):
286
315
287 """
316 """
288
317
289 Input:
318 Input:
290 dataOut :
319 dataOut :
291 id :
320 id :
292 wintitle :
321 wintitle :
293 channelList :
322 channelList :
294 showProfile :
323 showProfile :
295 xmin : None,
324 xmin : None,
296 xmax : None,
325 xmax : None,
297 ymin : None,
326 ymin : None,
298 ymax : None,
327 ymax : None,
299 zmin : None,
328 zmin : None,
300 zmax : None
329 zmax : None
301 """
330 """
302
331
303 if pairsList == None:
332 if pairsList == None:
304 pairsIndexList = dataOut.pairsIndexList
333 pairsIndexList = dataOut.pairsIndexList
305 else:
334 else:
306 pairsIndexList = []
335 pairsIndexList = []
307 for pair in pairsList:
336 for pair in pairsList:
308 if pair not in dataOut.pairsList:
337 if pair not in dataOut.pairsList:
309 raise ValueError, "Pair %s is not in dataOut.pairsList" %str(pair)
338 raise ValueError, "Pair %s is not in dataOut.pairsList" %str(pair)
310 pairsIndexList.append(dataOut.pairsList.index(pair))
339 pairsIndexList.append(dataOut.pairsList.index(pair))
311
340
312 if not pairsIndexList:
341 if not pairsIndexList:
313 return
342 return
314
343
315 if len(pairsIndexList) > 4:
344 if len(pairsIndexList) > 4:
316 pairsIndexList = pairsIndexList[0:4]
345 pairsIndexList = pairsIndexList[0:4]
317
346
318 if normFactor is None:
347 if normFactor is None:
319 factor = dataOut.normFactor
348 factor = dataOut.normFactor
320 else:
349 else:
321 factor = normFactor
350 factor = normFactor
322 x = dataOut.getVelRange(1)
351 x = dataOut.getVelRange(1)
323 y = dataOut.getHeiRange()
352 y = dataOut.getHeiRange()
324 z = dataOut.data_spc[:,:,:]/factor
353 z = dataOut.data_spc[:,:,:]/factor
325 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
354 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
326
355
327 noise = dataOut.noise/factor
356 noise = dataOut.noise/factor
328
357
329 zdB = 10*numpy.log10(z)
358 zdB = 10*numpy.log10(z)
330 noisedB = 10*numpy.log10(noise)
359 noisedB = 10*numpy.log10(noise)
331
360
332 if coh_min == None:
361 if coh_min == None:
333 coh_min = 0.0
362 coh_min = 0.0
334 if coh_max == None:
363 if coh_max == None:
335 coh_max = 1.0
364 coh_max = 1.0
336
365
337 if phase_min == None:
366 if phase_min == None:
338 phase_min = -180
367 phase_min = -180
339 if phase_max == None:
368 if phase_max == None:
340 phase_max = 180
369 phase_max = 180
341
370
342 #thisDatetime = dataOut.datatime
371 #thisDatetime = dataOut.datatime
343 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
372 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
344 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"))
345 # xlabel = "Velocity (m/s)"
374 # xlabel = "Velocity (m/s)"
346 ylabel = "Range (Km)"
375 ylabel = "Range (Km)"
347
376
348 if xaxis == "frequency":
377 if xaxis == "frequency":
349 x = dataOut.getFreqRange(1)/1000.
378 x = dataOut.getFreqRange(1)/1000.
350 xlabel = "Frequency (kHz)"
379 xlabel = "Frequency (kHz)"
351
380
352 elif xaxis == "time":
381 elif xaxis == "time":
353 x = dataOut.getAcfRange(1)
382 x = dataOut.getAcfRange(1)
354 xlabel = "Time (ms)"
383 xlabel = "Time (ms)"
355
384
356 else:
385 else:
357 x = dataOut.getVelRange(1)
386 x = dataOut.getVelRange(1)
358 xlabel = "Velocity (m/s)"
387 xlabel = "Velocity (m/s)"
359
388
360 if not self.isConfig:
389 if not self.isConfig:
361
390
362 nplots = len(pairsIndexList)
391 nplots = len(pairsIndexList)
363
392
364 self.setup(id=id,
393 self.setup(id=id,
365 nplots=nplots,
394 nplots=nplots,
366 wintitle=wintitle,
395 wintitle=wintitle,
367 showprofile=False,
396 showprofile=False,
368 show=show)
397 show=show)
369
398
370 avg = numpy.abs(numpy.average(z, axis=1))
399 avg = numpy.abs(numpy.average(z, axis=1))
371 avgdB = 10*numpy.log10(avg)
400 avgdB = 10*numpy.log10(avg)
372
401
373 if xmin == None: xmin = numpy.nanmin(x)
402 if xmin == None: xmin = numpy.nanmin(x)
374 if xmax == None: xmax = numpy.nanmax(x)
403 if xmax == None: xmax = numpy.nanmax(x)
375 if ymin == None: ymin = numpy.nanmin(y)
404 if ymin == None: ymin = numpy.nanmin(y)
376 if ymax == None: ymax = numpy.nanmax(y)
405 if ymax == None: ymax = numpy.nanmax(y)
377 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
406 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
378 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
407 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
379
408
380 self.FTP_WEI = ftp_wei
409 self.FTP_WEI = ftp_wei
381 self.EXP_CODE = exp_code
410 self.EXP_CODE = exp_code
382 self.SUB_EXP_CODE = sub_exp_code
411 self.SUB_EXP_CODE = sub_exp_code
383 self.PLOT_POS = plot_pos
412 self.PLOT_POS = plot_pos
384
413
385 self.isConfig = True
414 self.isConfig = True
386
415
387 self.setWinTitle(title)
416 self.setWinTitle(title)
417
388
418
389 for i in range(self.nplots):
419 for i in range(self.nplots):
390 pair = dataOut.pairsList[pairsIndexList[i]]
420 pair = dataOut.pairsList[pairsIndexList[i]]
391
421
392 chan_index0 = dataOut.channelList.index(pair[0])
422 chan_index0 = dataOut.channelList.index(pair[0])
393 chan_index1 = dataOut.channelList.index(pair[1])
423 chan_index1 = dataOut.channelList.index(pair[1])
394
424
395 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"))
396 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)
397 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index0,:,:]/factor)
427 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index0,:,:]/factor)
398 axes0 = self.axesList[i*self.__nsubplots]
428 axes0 = self.axesList[i*self.__nsubplots]
399 axes0.pcolor(x, y, zdB,
429 axes0.pcolor(x, y, zdB,
400 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,
401 xlabel=xlabel, ylabel=ylabel, title=title,
431 xlabel=xlabel, ylabel=ylabel, title=title,
402 ticksize=9, colormap=power_cmap, cblabel='')
432 ticksize=9, colormap=power_cmap, cblabel='')
403
433
404 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)
405 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index1,:,:]/factor)
435 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index1,:,:]/factor)
406 axes0 = self.axesList[i*self.__nsubplots+1]
436 axes0 = self.axesList[i*self.__nsubplots+1]
407 axes0.pcolor(x, y, zdB,
437 axes0.pcolor(x, y, zdB,
408 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,
409 xlabel=xlabel, ylabel=ylabel, title=title,
439 xlabel=xlabel, ylabel=ylabel, title=title,
410 ticksize=9, colormap=power_cmap, cblabel='')
440 ticksize=9, colormap=power_cmap, cblabel='')
411
441
412 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,:,:])
413 coherence = numpy.abs(coherenceComplex)
443 coherence = numpy.abs(coherenceComplex)
414 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
444 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
415 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
445 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
446
447
448 # print 'FASE', numpy.shape(phase), y[10]
449 # fig = plt.figure(10+self.indice)
450 # plt.plot( x[0:128],phase[:,10] )
451 # #plt.axis([-12, 12, 15, 50])
452 # plt.title("%s" %( '%s %s, Channel %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S") , i)))
453 # plt.ylabel('Desfase [grados]')
454 # plt.xlabel('Velocidad [m/s]')
455 # fig.savefig('/home/erick/Documents/Pics/to{}.png'.format(self.indice))
456 #
457 # plt.show()
458 # self.indice=self.indice+1
416
459
417 title = "Coherence Ch%d * Ch%d" %(pair[0], pair[1])
460 title = "Coherence Ch%d * Ch%d" %(pair[0], pair[1])
418 axes0 = self.axesList[i*self.__nsubplots+2]
461 axes0 = self.axesList[i*self.__nsubplots+2]
419 axes0.pcolor(x, y, coherence,
462 axes0.pcolor(x, y, coherence,
420 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=coh_min, zmax=coh_max,
463 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=coh_min, zmax=coh_max,
421 xlabel=xlabel, ylabel=ylabel, title=title,
464 xlabel=xlabel, ylabel=ylabel, title=title,
422 ticksize=9, colormap=coherence_cmap, cblabel='')
465 ticksize=9, colormap=coherence_cmap, cblabel='')
423
466
424 title = "Phase Ch%d * Ch%d" %(pair[0], pair[1])
467 title = "Phase Ch%d * Ch%d" %(pair[0], pair[1])
425 axes0 = self.axesList[i*self.__nsubplots+3]
468 axes0 = self.axesList[i*self.__nsubplots+3]
426 axes0.pcolor(x, y, phase,
469 axes0.pcolor(x, y, phase,
427 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
470 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
428 xlabel=xlabel, ylabel=ylabel, title=title,
471 xlabel=xlabel, ylabel=ylabel, title=title,
429 ticksize=9, colormap=phase_cmap, cblabel='')
472 ticksize=9, colormap=phase_cmap, cblabel='')
430
473
431
474
432
475
433 self.draw()
476 self.draw()
434
477
435 self.save(figpath=figpath,
478 self.save(figpath=figpath,
436 figfile=figfile,
479 figfile=figfile,
437 save=save,
480 save=save,
438 ftp=ftp,
481 ftp=ftp,
439 wr_period=wr_period,
482 wr_period=wr_period,
440 thisDatetime=thisDatetime)
483 thisDatetime=thisDatetime)
441
484
442
485
443 class RTIPlot(Figure):
486 class RTIPlot(Figure):
444
487
445 __isConfig = None
488 __isConfig = None
446 __nsubplots = None
489 __nsubplots = None
447
490
448 WIDTHPROF = None
491 WIDTHPROF = None
449 HEIGHTPROF = None
492 HEIGHTPROF = None
450 PREFIX = 'rti'
493 PREFIX = 'rti'
451
494
452 def __init__(self, **kwargs):
495 def __init__(self, **kwargs):
453
496
454 Figure.__init__(self, **kwargs)
497 Figure.__init__(self, **kwargs)
455 self.timerange = None
498 self.timerange = None
456 self.isConfig = False
499 self.isConfig = False
457 self.__nsubplots = 1
500 self.__nsubplots = 1
458
501
459 self.WIDTH = 800
502 self.WIDTH = 800
460 self.HEIGHT = 180
503 self.HEIGHT = 180
461 self.WIDTHPROF = 120
504 self.WIDTHPROF = 120
462 self.HEIGHTPROF = 0
505 self.HEIGHTPROF = 0
463 self.counter_imagwr = 0
506 self.counter_imagwr = 0
464
507
465 self.PLOT_CODE = RTI_CODE
508 self.PLOT_CODE = RTI_CODE
466
509
467 self.FTP_WEI = None
510 self.FTP_WEI = None
468 self.EXP_CODE = None
511 self.EXP_CODE = None
469 self.SUB_EXP_CODE = None
512 self.SUB_EXP_CODE = None
470 self.PLOT_POS = None
513 self.PLOT_POS = None
471 self.tmin = None
514 self.tmin = None
472 self.tmax = None
515 self.tmax = None
473
516
474 self.xmin = None
517 self.xmin = None
475 self.xmax = None
518 self.xmax = None
476
519
477 self.figfile = None
520 self.figfile = None
478
521
479 def getSubplots(self):
522 def getSubplots(self):
480
523
481 ncol = 1
524 ncol = 1
482 nrow = self.nplots
525 nrow = self.nplots
483
526
484 return nrow, ncol
527 return nrow, ncol
485
528
486 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
529 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
487
530
488 self.__showprofile = showprofile
531 self.__showprofile = showprofile
489 self.nplots = nplots
532 self.nplots = nplots
490
533
491 ncolspan = 1
534 ncolspan = 1
492 colspan = 1
535 colspan = 1
493 if showprofile:
536 if showprofile:
494 ncolspan = 7
537 ncolspan = 7
495 colspan = 6
538 colspan = 6
496 self.__nsubplots = 2
539 self.__nsubplots = 2
497
540
498 self.createFigure(id = id,
541 self.createFigure(id = id,
499 wintitle = wintitle,
542 wintitle = wintitle,
500 widthplot = self.WIDTH + self.WIDTHPROF,
543 widthplot = self.WIDTH + self.WIDTHPROF,
501 heightplot = self.HEIGHT + self.HEIGHTPROF,
544 heightplot = self.HEIGHT + self.HEIGHTPROF,
502 show=show)
545 show=show)
503
546
504 nrow, ncol = self.getSubplots()
547 nrow, ncol = self.getSubplots()
505
548
506 counter = 0
549 counter = 0
507 for y in range(nrow):
550 for y in range(nrow):
508 for x in range(ncol):
551 for x in range(ncol):
509
552
510 if counter >= self.nplots:
553 if counter >= self.nplots:
511 break
554 break
512
555
513 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
556 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
514
557
515 if showprofile:
558 if showprofile:
516 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
559 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
517
560
518 counter += 1
561 counter += 1
519
562
520 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
563 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
521 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
564 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
522 timerange=None, colormap='jet',
565 timerange=None, colormap='jet',
523 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
566 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
524 server=None, folder=None, username=None, password=None,
567 server=None, folder=None, username=None, password=None,
525 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None, HEIGHT=None):
568 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None, HEIGHT=None):
526
569
527 """
570 """
528
571
529 Input:
572 Input:
530 dataOut :
573 dataOut :
531 id :
574 id :
532 wintitle :
575 wintitle :
533 channelList :
576 channelList :
534 showProfile :
577 showProfile :
535 xmin : None,
578 xmin : None,
536 xmax : None,
579 xmax : None,
537 ymin : None,
580 ymin : None,
538 ymax : None,
581 ymax : None,
539 zmin : None,
582 zmin : None,
540 zmax : None
583 zmax : None
541 """
584 """
542
585
543 #colormap = kwargs.get('colormap', 'jet')
586 #colormap = kwargs.get('colormap', 'jet')
544 if HEIGHT is not None:
587 if HEIGHT is not None:
545 self.HEIGHT = HEIGHT
588 self.HEIGHT = HEIGHT
546
589
547 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
590 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
548 return
591 return
549
592
550 if channelList == None:
593 if channelList == None:
551 channelIndexList = dataOut.channelIndexList
594 channelIndexList = dataOut.channelIndexList
552 else:
595 else:
553 channelIndexList = []
596 channelIndexList = []
554 for channel in channelList:
597 for channel in channelList:
555 if channel not in dataOut.channelList:
598 if channel not in dataOut.channelList:
556 raise ValueError, "Channel %d is not in dataOut.channelList"
599 raise ValueError, "Channel %d is not in dataOut.channelList"
557 channelIndexList.append(dataOut.channelList.index(channel))
600 channelIndexList.append(dataOut.channelList.index(channel))
558
601
559 if normFactor is None:
602 if normFactor is None:
560 factor = dataOut.normFactor
603 factor = dataOut.normFactor
561 else:
604 else:
562 factor = normFactor
605 factor = normFactor
563
606
564 # factor = dataOut.normFactor
607 # factor = dataOut.normFactor
565 x = dataOut.getTimeRange()
608 x = dataOut.getTimeRange()
566 y = dataOut.getHeiRange()
609 y = dataOut.getHeiRange()
567
610
568 z = dataOut.data_spc/factor
611 z = dataOut.data_spc/factor
569 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
612 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
570 avg = numpy.average(z, axis=1)
613 avg = numpy.average(z, axis=1)
571 avgdB = 10.*numpy.log10(avg)
614 avgdB = 10.*numpy.log10(avg)
572 # avgdB = dataOut.getPower()
615 # avgdB = dataOut.getPower()
573
616
574
617
575 thisDatetime = dataOut.datatime
618 thisDatetime = dataOut.datatime
576 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
619 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
577 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
620 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
578 xlabel = ""
621 xlabel = ""
579 ylabel = "Range (Km)"
622 ylabel = "Range (Km)"
580
623
581 update_figfile = False
624 update_figfile = False
582
625
583 if dataOut.ltctime >= self.xmax:
626 if dataOut.ltctime >= self.xmax:
584 self.counter_imagwr = wr_period
627 self.counter_imagwr = wr_period
585 self.isConfig = False
628 self.isConfig = False
586 update_figfile = True
629 update_figfile = True
587
630
588 if not self.isConfig:
631 if not self.isConfig:
589
632
590 nplots = len(channelIndexList)
633 nplots = len(channelIndexList)
591
634
592 self.setup(id=id,
635 self.setup(id=id,
593 nplots=nplots,
636 nplots=nplots,
594 wintitle=wintitle,
637 wintitle=wintitle,
595 showprofile=showprofile,
638 showprofile=showprofile,
596 show=show)
639 show=show)
597
640
598 if timerange != None:
641 if timerange != None:
599 self.timerange = timerange
642 self.timerange = timerange
600
643
601 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
644 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
602
645
603 noise = dataOut.noise/factor
646 noise = dataOut.noise/factor
604 noisedB = 10*numpy.log10(noise)
647 noisedB = 10*numpy.log10(noise)
605
648
606 if ymin == None: ymin = numpy.nanmin(y)
649 if ymin == None: ymin = numpy.nanmin(y)
607 if ymax == None: ymax = numpy.nanmax(y)
650 if ymax == None: ymax = numpy.nanmax(y)
608 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
651 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
609 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
652 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
610
653
611 self.FTP_WEI = ftp_wei
654 self.FTP_WEI = ftp_wei
612 self.EXP_CODE = exp_code
655 self.EXP_CODE = exp_code
613 self.SUB_EXP_CODE = sub_exp_code
656 self.SUB_EXP_CODE = sub_exp_code
614 self.PLOT_POS = plot_pos
657 self.PLOT_POS = plot_pos
615
658
616 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
659 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
617 self.isConfig = True
660 self.isConfig = True
618 self.figfile = figfile
661 self.figfile = figfile
619 update_figfile = True
662 update_figfile = True
620
663
621 self.setWinTitle(title)
664 self.setWinTitle(title)
622
665
623 for i in range(self.nplots):
666 for i in range(self.nplots):
624 index = channelIndexList[i]
667 index = channelIndexList[i]
625 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
668 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
626 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
669 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
627 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
670 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
628 axes = self.axesList[i*self.__nsubplots]
671 axes = self.axesList[i*self.__nsubplots]
629 zdB = avgdB[index].reshape((1,-1))
672 zdB = avgdB[index].reshape((1,-1))
630 axes.pcolorbuffer(x, y, zdB,
673 axes.pcolorbuffer(x, y, zdB,
631 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
674 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
632 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
675 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
633 ticksize=9, cblabel='', cbsize="1%", colormap=colormap)
676 ticksize=9, cblabel='', cbsize="1%", colormap=colormap)
634
677
635 if self.__showprofile:
678 if self.__showprofile:
636 axes = self.axesList[i*self.__nsubplots +1]
679 axes = self.axesList[i*self.__nsubplots +1]
637 axes.pline(avgdB[index], y,
680 axes.pline(avgdB[index], y,
638 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
681 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
639 xlabel='dB', ylabel='', title='',
682 xlabel='dB', ylabel='', title='',
640 ytick_visible=False,
683 ytick_visible=False,
641 grid='x')
684 grid='x')
642
685
643 self.draw()
686 self.draw()
644
687
645 self.save(figpath=figpath,
688 self.save(figpath=figpath,
646 figfile=figfile,
689 figfile=figfile,
647 save=save,
690 save=save,
648 ftp=ftp,
691 ftp=ftp,
649 wr_period=wr_period,
692 wr_period=wr_period,
650 thisDatetime=thisDatetime,
693 thisDatetime=thisDatetime,
651 update_figfile=update_figfile)
694 update_figfile=update_figfile)
652
695
653 class CoherenceMap(Figure):
696 class CoherenceMap(Figure):
654 isConfig = None
697 isConfig = None
655 __nsubplots = None
698 __nsubplots = None
656
699
657 WIDTHPROF = None
700 WIDTHPROF = None
658 HEIGHTPROF = None
701 HEIGHTPROF = None
659 PREFIX = 'cmap'
702 PREFIX = 'cmap'
660
703
661 def __init__(self, **kwargs):
704 def __init__(self, **kwargs):
662 Figure.__init__(self, **kwargs)
705 Figure.__init__(self, **kwargs)
663 self.timerange = 2*60*60
706 self.timerange = 2*60*60
664 self.isConfig = False
707 self.isConfig = False
665 self.__nsubplots = 1
708 self.__nsubplots = 1
666
709
667 self.WIDTH = 800
710 self.WIDTH = 800
668 self.HEIGHT = 180
711 self.HEIGHT = 180
669 self.WIDTHPROF = 120
712 self.WIDTHPROF = 120
670 self.HEIGHTPROF = 0
713 self.HEIGHTPROF = 0
671 self.counter_imagwr = 0
714 self.counter_imagwr = 0
672
715
673 self.PLOT_CODE = COH_CODE
716 self.PLOT_CODE = COH_CODE
674
717
675 self.FTP_WEI = None
718 self.FTP_WEI = None
676 self.EXP_CODE = None
719 self.EXP_CODE = None
677 self.SUB_EXP_CODE = None
720 self.SUB_EXP_CODE = None
678 self.PLOT_POS = None
721 self.PLOT_POS = None
679 self.counter_imagwr = 0
722 self.counter_imagwr = 0
680
723
681 self.xmin = None
724 self.xmin = None
682 self.xmax = None
725 self.xmax = None
683
726
684 def getSubplots(self):
727 def getSubplots(self):
685 ncol = 1
728 ncol = 1
686 nrow = self.nplots*2
729 nrow = self.nplots*2
687
730
688 return nrow, ncol
731 return nrow, ncol
689
732
690 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
733 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
691 self.__showprofile = showprofile
734 self.__showprofile = showprofile
692 self.nplots = nplots
735 self.nplots = nplots
693
736
694 ncolspan = 1
737 ncolspan = 1
695 colspan = 1
738 colspan = 1
696 if showprofile:
739 if showprofile:
697 ncolspan = 7
740 ncolspan = 7
698 colspan = 6
741 colspan = 6
699 self.__nsubplots = 2
742 self.__nsubplots = 2
700
743
701 self.createFigure(id = id,
744 self.createFigure(id = id,
702 wintitle = wintitle,
745 wintitle = wintitle,
703 widthplot = self.WIDTH + self.WIDTHPROF,
746 widthplot = self.WIDTH + self.WIDTHPROF,
704 heightplot = self.HEIGHT + self.HEIGHTPROF,
747 heightplot = self.HEIGHT + self.HEIGHTPROF,
705 show=True)
748 show=True)
706
749
707 nrow, ncol = self.getSubplots()
750 nrow, ncol = self.getSubplots()
708
751
709 for y in range(nrow):
752 for y in range(nrow):
710 for x in range(ncol):
753 for x in range(ncol):
711
754
712 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
755 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
713
756
714 if showprofile:
757 if showprofile:
715 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
758 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
716
759
717 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
760 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
718 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
761 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
719 timerange=None, phase_min=None, phase_max=None,
762 timerange=None, phase_min=None, phase_max=None,
720 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
763 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
721 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
764 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
722 server=None, folder=None, username=None, password=None,
765 server=None, folder=None, username=None, password=None,
723 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
766 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
724
767
725 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
768 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
726 return
769 return
727
770
728 if pairsList == None:
771 if pairsList == None:
729 pairsIndexList = dataOut.pairsIndexList
772 pairsIndexList = dataOut.pairsIndexList
730 else:
773 else:
731 pairsIndexList = []
774 pairsIndexList = []
732 for pair in pairsList:
775 for pair in pairsList:
733 if pair not in dataOut.pairsList:
776 if pair not in dataOut.pairsList:
734 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
777 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
735 pairsIndexList.append(dataOut.pairsList.index(pair))
778 pairsIndexList.append(dataOut.pairsList.index(pair))
736
779
737 if pairsIndexList == []:
780 if pairsIndexList == []:
738 return
781 return
739
782
740 if len(pairsIndexList) > 4:
783 if len(pairsIndexList) > 4:
741 pairsIndexList = pairsIndexList[0:4]
784 pairsIndexList = pairsIndexList[0:4]
742
785
743 if phase_min == None:
786 if phase_min == None:
744 phase_min = -180
787 phase_min = -180
745 if phase_max == None:
788 if phase_max == None:
746 phase_max = 180
789 phase_max = 180
747
790
748 x = dataOut.getTimeRange()
791 x = dataOut.getTimeRange()
749 y = dataOut.getHeiRange()
792 y = dataOut.getHeiRange()
750
793
751 thisDatetime = dataOut.datatime
794 thisDatetime = dataOut.datatime
752
795
753 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
796 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
754 xlabel = ""
797 xlabel = ""
755 ylabel = "Range (Km)"
798 ylabel = "Range (Km)"
756 update_figfile = False
799 update_figfile = False
757
800
758 if not self.isConfig:
801 if not self.isConfig:
759 nplots = len(pairsIndexList)
802 nplots = len(pairsIndexList)
760 self.setup(id=id,
803 self.setup(id=id,
761 nplots=nplots,
804 nplots=nplots,
762 wintitle=wintitle,
805 wintitle=wintitle,
763 showprofile=showprofile,
806 showprofile=showprofile,
764 show=show)
807 show=show)
765
808
766 if timerange != None:
809 if timerange != None:
767 self.timerange = timerange
810 self.timerange = timerange
768
811
769 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
812 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
770
813
771 if ymin == None: ymin = numpy.nanmin(y)
814 if ymin == None: ymin = numpy.nanmin(y)
772 if ymax == None: ymax = numpy.nanmax(y)
815 if ymax == None: ymax = numpy.nanmax(y)
773 if zmin == None: zmin = 0.
816 if zmin == None: zmin = 0.
774 if zmax == None: zmax = 1.
817 if zmax == None: zmax = 1.
775
818
776 self.FTP_WEI = ftp_wei
819 self.FTP_WEI = ftp_wei
777 self.EXP_CODE = exp_code
820 self.EXP_CODE = exp_code
778 self.SUB_EXP_CODE = sub_exp_code
821 self.SUB_EXP_CODE = sub_exp_code
779 self.PLOT_POS = plot_pos
822 self.PLOT_POS = plot_pos
780
823
781 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
824 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
782
825
783 self.isConfig = True
826 self.isConfig = True
784 update_figfile = True
827 update_figfile = True
785
828
786 self.setWinTitle(title)
829 self.setWinTitle(title)
787
830
788 for i in range(self.nplots):
831 for i in range(self.nplots):
789
832
790 pair = dataOut.pairsList[pairsIndexList[i]]
833 pair = dataOut.pairsList[pairsIndexList[i]]
791
834
792 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
835 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
793 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
836 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
794 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
837 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
795
838
796
839
797 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
840 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
798 coherence = numpy.abs(avgcoherenceComplex)
841 coherence = numpy.abs(avgcoherenceComplex)
799
842
800 z = coherence.reshape((1,-1))
843 z = coherence.reshape((1,-1))
801
844
802 counter = 0
845 counter = 0
803
846
804 title = "Coherence Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
847 title = "Coherence Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
805 axes = self.axesList[i*self.__nsubplots*2]
848 axes = self.axesList[i*self.__nsubplots*2]
806 axes.pcolorbuffer(x, y, z,
849 axes.pcolorbuffer(x, y, z,
807 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
850 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
808 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
851 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
809 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
852 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
810
853
811 if self.__showprofile:
854 if self.__showprofile:
812 counter += 1
855 counter += 1
813 axes = self.axesList[i*self.__nsubplots*2 + counter]
856 axes = self.axesList[i*self.__nsubplots*2 + counter]
814 axes.pline(coherence, y,
857 axes.pline(coherence, y,
815 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
858 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
816 xlabel='', ylabel='', title='', ticksize=7,
859 xlabel='', ylabel='', title='', ticksize=7,
817 ytick_visible=False, nxticks=5,
860 ytick_visible=False, nxticks=5,
818 grid='x')
861 grid='x')
819
862
820 counter += 1
863 counter += 1
821
864
822 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
865 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
823
866
824 z = phase.reshape((1,-1))
867 z = phase.reshape((1,-1))
825
868
826 title = "Phase Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
869 title = "Phase Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
827 axes = self.axesList[i*self.__nsubplots*2 + counter]
870 axes = self.axesList[i*self.__nsubplots*2 + counter]
828 axes.pcolorbuffer(x, y, z,
871 axes.pcolorbuffer(x, y, z,
829 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
872 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
830 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
873 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
831 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
874 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
832
875
833 if self.__showprofile:
876 if self.__showprofile:
834 counter += 1
877 counter += 1
835 axes = self.axesList[i*self.__nsubplots*2 + counter]
878 axes = self.axesList[i*self.__nsubplots*2 + counter]
836 axes.pline(phase, y,
879 axes.pline(phase, y,
837 xmin=phase_min, xmax=phase_max, ymin=ymin, ymax=ymax,
880 xmin=phase_min, xmax=phase_max, ymin=ymin, ymax=ymax,
838 xlabel='', ylabel='', title='', ticksize=7,
881 xlabel='', ylabel='', title='', ticksize=7,
839 ytick_visible=False, nxticks=4,
882 ytick_visible=False, nxticks=4,
840 grid='x')
883 grid='x')
841
884
842 self.draw()
885 self.draw()
843
886
844 if dataOut.ltctime >= self.xmax:
887 if dataOut.ltctime >= self.xmax:
845 self.counter_imagwr = wr_period
888 self.counter_imagwr = wr_period
846 self.isConfig = False
889 self.isConfig = False
847 update_figfile = True
890 update_figfile = True
848
891
849 self.save(figpath=figpath,
892 self.save(figpath=figpath,
850 figfile=figfile,
893 figfile=figfile,
851 save=save,
894 save=save,
852 ftp=ftp,
895 ftp=ftp,
853 wr_period=wr_period,
896 wr_period=wr_period,
854 thisDatetime=thisDatetime,
897 thisDatetime=thisDatetime,
855 update_figfile=update_figfile)
898 update_figfile=update_figfile)
856
899
857 class PowerProfilePlot(Figure):
900 class PowerProfilePlot(Figure):
858
901
859 isConfig = None
902 isConfig = None
860 __nsubplots = None
903 __nsubplots = None
861
904
862 WIDTHPROF = None
905 WIDTHPROF = None
863 HEIGHTPROF = None
906 HEIGHTPROF = None
864 PREFIX = 'spcprofile'
907 PREFIX = 'spcprofile'
865
908
866 def __init__(self, **kwargs):
909 def __init__(self, **kwargs):
867 Figure.__init__(self, **kwargs)
910 Figure.__init__(self, **kwargs)
868 self.isConfig = False
911 self.isConfig = False
869 self.__nsubplots = 1
912 self.__nsubplots = 1
870
913
871 self.PLOT_CODE = POWER_CODE
914 self.PLOT_CODE = POWER_CODE
872
915
873 self.WIDTH = 300
916 self.WIDTH = 300
874 self.HEIGHT = 500
917 self.HEIGHT = 500
875 self.counter_imagwr = 0
918 self.counter_imagwr = 0
876
919
877 def getSubplots(self):
920 def getSubplots(self):
878 ncol = 1
921 ncol = 1
879 nrow = 1
922 nrow = 1
880
923
881 return nrow, ncol
924 return nrow, ncol
882
925
883 def setup(self, id, nplots, wintitle, show):
926 def setup(self, id, nplots, wintitle, show):
884
927
885 self.nplots = nplots
928 self.nplots = nplots
886
929
887 ncolspan = 1
930 ncolspan = 1
888 colspan = 1
931 colspan = 1
889
932
890 self.createFigure(id = id,
933 self.createFigure(id = id,
891 wintitle = wintitle,
934 wintitle = wintitle,
892 widthplot = self.WIDTH,
935 widthplot = self.WIDTH,
893 heightplot = self.HEIGHT,
936 heightplot = self.HEIGHT,
894 show=show)
937 show=show)
895
938
896 nrow, ncol = self.getSubplots()
939 nrow, ncol = self.getSubplots()
897
940
898 counter = 0
941 counter = 0
899 for y in range(nrow):
942 for y in range(nrow):
900 for x in range(ncol):
943 for x in range(ncol):
901 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
944 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
902
945
903 def run(self, dataOut, id, wintitle="", channelList=None,
946 def run(self, dataOut, id, wintitle="", channelList=None,
904 xmin=None, xmax=None, ymin=None, ymax=None,
947 xmin=None, xmax=None, ymin=None, ymax=None,
905 save=False, figpath='./', figfile=None, show=True,
948 save=False, figpath='./', figfile=None, show=True,
906 ftp=False, wr_period=1, server=None,
949 ftp=False, wr_period=1, server=None,
907 folder=None, username=None, password=None):
950 folder=None, username=None, password=None):
908
951
909
952
910 if channelList == None:
953 if channelList == None:
911 channelIndexList = dataOut.channelIndexList
954 channelIndexList = dataOut.channelIndexList
912 channelList = dataOut.channelList
955 channelList = dataOut.channelList
913 else:
956 else:
914 channelIndexList = []
957 channelIndexList = []
915 for channel in channelList:
958 for channel in channelList:
916 if channel not in dataOut.channelList:
959 if channel not in dataOut.channelList:
917 raise ValueError, "Channel %d is not in dataOut.channelList"
960 raise ValueError, "Channel %d is not in dataOut.channelList"
918 channelIndexList.append(dataOut.channelList.index(channel))
961 channelIndexList.append(dataOut.channelList.index(channel))
919
962
920 factor = dataOut.normFactor
963 factor = dataOut.normFactor
921
964
922 y = dataOut.getHeiRange()
965 y = dataOut.getHeiRange()
923
966
924 #for voltage
967 #for voltage
925 if dataOut.type == 'Voltage':
968 if dataOut.type == 'Voltage':
926 x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
969 x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
927 x = x.real
970 x = x.real
928 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
971 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
929
972
930 #for spectra
973 #for spectra
931 if dataOut.type == 'Spectra':
974 if dataOut.type == 'Spectra':
932 x = dataOut.data_spc[channelIndexList,:,:]/factor
975 x = dataOut.data_spc[channelIndexList,:,:]/factor
933 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
976 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
934 x = numpy.average(x, axis=1)
977 x = numpy.average(x, axis=1)
935
978
936
979
937 xdB = 10*numpy.log10(x)
980 xdB = 10*numpy.log10(x)
938
981
939 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
982 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
940 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
983 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
941 xlabel = "dB"
984 xlabel = "dB"
942 ylabel = "Range (Km)"
985 ylabel = "Range (Km)"
943
986
944 if not self.isConfig:
987 if not self.isConfig:
945
988
946 nplots = 1
989 nplots = 1
947
990
948 self.setup(id=id,
991 self.setup(id=id,
949 nplots=nplots,
992 nplots=nplots,
950 wintitle=wintitle,
993 wintitle=wintitle,
951 show=show)
994 show=show)
952
995
953 if ymin == None: ymin = numpy.nanmin(y)
996 if ymin == None: ymin = numpy.nanmin(y)
954 if ymax == None: ymax = numpy.nanmax(y)
997 if ymax == None: ymax = numpy.nanmax(y)
955 if xmin == None: xmin = numpy.nanmin(xdB)*0.9
998 if xmin == None: xmin = numpy.nanmin(xdB)*0.9
956 if xmax == None: xmax = numpy.nanmax(xdB)*1.1
999 if xmax == None: xmax = numpy.nanmax(xdB)*1.1
957
1000
958 self.isConfig = True
1001 self.isConfig = True
959
1002
960 self.setWinTitle(title)
1003 self.setWinTitle(title)
961
1004
962 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1005 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
963 axes = self.axesList[0]
1006 axes = self.axesList[0]
964
1007
965 legendlabels = ["channel %d"%x for x in channelList]
1008 legendlabels = ["channel %d"%x for x in channelList]
966 axes.pmultiline(xdB, y,
1009 axes.pmultiline(xdB, y,
967 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1010 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
968 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
1011 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
969 ytick_visible=True, nxticks=5,
1012 ytick_visible=True, nxticks=5,
970 grid='x')
1013 grid='x')
971
1014
972 self.draw()
1015 self.draw()
973
1016
974 self.save(figpath=figpath,
1017 self.save(figpath=figpath,
975 figfile=figfile,
1018 figfile=figfile,
976 save=save,
1019 save=save,
977 ftp=ftp,
1020 ftp=ftp,
978 wr_period=wr_period,
1021 wr_period=wr_period,
979 thisDatetime=thisDatetime)
1022 thisDatetime=thisDatetime)
980
1023
981 class SpectraCutPlot(Figure):
1024 class SpectraCutPlot(Figure):
982
1025
983 isConfig = None
1026 isConfig = None
984 __nsubplots = None
1027 __nsubplots = None
985
1028
986 WIDTHPROF = None
1029 WIDTHPROF = None
987 HEIGHTPROF = None
1030 HEIGHTPROF = None
988 PREFIX = 'spc_cut'
1031 PREFIX = 'spc_cut'
989
1032
990 def __init__(self, **kwargs):
1033 def __init__(self, **kwargs):
991 Figure.__init__(self, **kwargs)
1034 Figure.__init__(self, **kwargs)
992 self.isConfig = False
1035 self.isConfig = False
993 self.__nsubplots = 1
1036 self.__nsubplots = 1
994
1037
995 self.PLOT_CODE = POWER_CODE
1038 self.PLOT_CODE = POWER_CODE
996
1039
997 self.WIDTH = 700
1040 self.WIDTH = 700
998 self.HEIGHT = 500
1041 self.HEIGHT = 500
999 self.counter_imagwr = 0
1042 self.counter_imagwr = 0
1000
1043
1001 def getSubplots(self):
1044 def getSubplots(self):
1002 ncol = 1
1045 ncol = 1
1003 nrow = 1
1046 nrow = 1
1004
1047
1005 return nrow, ncol
1048 return nrow, ncol
1006
1049
1007 def setup(self, id, nplots, wintitle, show):
1050 def setup(self, id, nplots, wintitle, show):
1008
1051
1009 self.nplots = nplots
1052 self.nplots = nplots
1010
1053
1011 ncolspan = 1
1054 ncolspan = 1
1012 colspan = 1
1055 colspan = 1
1013
1056
1014 self.createFigure(id = id,
1057 self.createFigure(id = id,
1015 wintitle = wintitle,
1058 wintitle = wintitle,
1016 widthplot = self.WIDTH,
1059 widthplot = self.WIDTH,
1017 heightplot = self.HEIGHT,
1060 heightplot = self.HEIGHT,
1018 show=show)
1061 show=show)
1019
1062
1020 nrow, ncol = self.getSubplots()
1063 nrow, ncol = self.getSubplots()
1021
1064
1022 counter = 0
1065 counter = 0
1023 for y in range(nrow):
1066 for y in range(nrow):
1024 for x in range(ncol):
1067 for x in range(ncol):
1025 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1068 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1026
1069
1027 def run(self, dataOut, id, wintitle="", channelList=None,
1070 def run(self, dataOut, id, wintitle="", channelList=None,
1028 xmin=None, xmax=None, ymin=None, ymax=None,
1071 xmin=None, xmax=None, ymin=None, ymax=None,
1029 save=False, figpath='./', figfile=None, show=True,
1072 save=False, figpath='./', figfile=None, show=True,
1030 ftp=False, wr_period=1, server=None,
1073 ftp=False, wr_period=1, server=None,
1031 folder=None, username=None, password=None,
1074 folder=None, username=None, password=None,
1032 xaxis="frequency"):
1075 xaxis="frequency"):
1033
1076
1034
1077
1035 if channelList == None:
1078 if channelList == None:
1036 channelIndexList = dataOut.channelIndexList
1079 channelIndexList = dataOut.channelIndexList
1037 channelList = dataOut.channelList
1080 channelList = dataOut.channelList
1038 else:
1081 else:
1039 channelIndexList = []
1082 channelIndexList = []
1040 for channel in channelList:
1083 for channel in channelList:
1041 if channel not in dataOut.channelList:
1084 if channel not in dataOut.channelList:
1042 raise ValueError, "Channel %d is not in dataOut.channelList"
1085 raise ValueError, "Channel %d is not in dataOut.channelList"
1043 channelIndexList.append(dataOut.channelList.index(channel))
1086 channelIndexList.append(dataOut.channelList.index(channel))
1044
1087
1045 factor = dataOut.normFactor
1088 factor = dataOut.normFactor
1046
1089
1047 y = dataOut.getHeiRange()
1090 y = dataOut.getHeiRange()
1048
1091
1049 z = dataOut.data_spc/factor
1092 z = dataOut.data_spc/factor
1050 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1093 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1051
1094
1052 hei_index = numpy.arange(25)*3 + 20
1095 hei_index = numpy.arange(25)*3 + 20
1053
1096
1054 if xaxis == "frequency":
1097 if xaxis == "frequency":
1055 x = dataOut.getFreqRange()/1000.
1098 x = dataOut.getFreqRange()/1000.
1056 zdB = 10*numpy.log10(z[0,:,hei_index])
1099 zdB = 10*numpy.log10(z[0,:,hei_index])
1057 xlabel = "Frequency (kHz)"
1100 xlabel = "Frequency (kHz)"
1058 ylabel = "Power (dB)"
1101 ylabel = "Power (dB)"
1059
1102
1060 elif xaxis == "time":
1103 elif xaxis == "time":
1061 x = dataOut.getAcfRange()
1104 x = dataOut.getAcfRange()
1062 zdB = z[0,:,hei_index]
1105 zdB = z[0,:,hei_index]
1063 xlabel = "Time (ms)"
1106 xlabel = "Time (ms)"
1064 ylabel = "ACF"
1107 ylabel = "ACF"
1065
1108
1066 else:
1109 else:
1067 x = dataOut.getVelRange()
1110 x = dataOut.getVelRange()
1068 zdB = 10*numpy.log10(z[0,:,hei_index])
1111 zdB = 10*numpy.log10(z[0,:,hei_index])
1069 xlabel = "Velocity (m/s)"
1112 xlabel = "Velocity (m/s)"
1070 ylabel = "Power (dB)"
1113 ylabel = "Power (dB)"
1071
1114
1072 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1115 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1073 title = wintitle + " Range Cuts %s" %(thisDatetime.strftime("%d-%b-%Y"))
1116 title = wintitle + " Range Cuts %s" %(thisDatetime.strftime("%d-%b-%Y"))
1074
1117
1075 if not self.isConfig:
1118 if not self.isConfig:
1076
1119
1077 nplots = 1
1120 nplots = 1
1078
1121
1079 self.setup(id=id,
1122 self.setup(id=id,
1080 nplots=nplots,
1123 nplots=nplots,
1081 wintitle=wintitle,
1124 wintitle=wintitle,
1082 show=show)
1125 show=show)
1083
1126
1084 if xmin == None: xmin = numpy.nanmin(x)*0.9
1127 if xmin == None: xmin = numpy.nanmin(x)*0.9
1085 if xmax == None: xmax = numpy.nanmax(x)*1.1
1128 if xmax == None: xmax = numpy.nanmax(x)*1.1
1086 if ymin == None: ymin = numpy.nanmin(zdB)
1129 if ymin == None: ymin = numpy.nanmin(zdB)
1087 if ymax == None: ymax = numpy.nanmax(zdB)
1130 if ymax == None: ymax = numpy.nanmax(zdB)
1088
1131
1089 self.isConfig = True
1132 self.isConfig = True
1090
1133
1091 self.setWinTitle(title)
1134 self.setWinTitle(title)
1092
1135
1093 title = "Spectra Cuts: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1136 title = "Spectra Cuts: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1094 axes = self.axesList[0]
1137 axes = self.axesList[0]
1095
1138
1096 legendlabels = ["Range = %dKm" %y[i] for i in hei_index]
1139 legendlabels = ["Range = %dKm" %y[i] for i in hei_index]
1097
1140
1098 axes.pmultilineyaxis( x, zdB,
1141 axes.pmultilineyaxis( x, zdB,
1099 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1142 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1100 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
1143 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
1101 ytick_visible=True, nxticks=5,
1144 ytick_visible=True, nxticks=5,
1102 grid='x')
1145 grid='x')
1103
1146
1104 self.draw()
1147 self.draw()
1105
1148
1106 self.save(figpath=figpath,
1149 self.save(figpath=figpath,
1107 figfile=figfile,
1150 figfile=figfile,
1108 save=save,
1151 save=save,
1109 ftp=ftp,
1152 ftp=ftp,
1110 wr_period=wr_period,
1153 wr_period=wr_period,
1111 thisDatetime=thisDatetime)
1154 thisDatetime=thisDatetime)
1112
1155
1113 class Noise(Figure):
1156 class Noise(Figure):
1114
1157
1115 isConfig = None
1158 isConfig = None
1116 __nsubplots = None
1159 __nsubplots = None
1117
1160
1118 PREFIX = 'noise'
1161 PREFIX = 'noise'
1119
1162
1120
1163
1121 def __init__(self, **kwargs):
1164 def __init__(self, **kwargs):
1122 Figure.__init__(self, **kwargs)
1165 Figure.__init__(self, **kwargs)
1123 self.timerange = 24*60*60
1166 self.timerange = 24*60*60
1124 self.isConfig = False
1167 self.isConfig = False
1125 self.__nsubplots = 1
1168 self.__nsubplots = 1
1126 self.counter_imagwr = 0
1169 self.counter_imagwr = 0
1127 self.WIDTH = 800
1170 self.WIDTH = 800
1128 self.HEIGHT = 400
1171 self.HEIGHT = 400
1129 self.WIDTHPROF = 120
1172 self.WIDTHPROF = 120
1130 self.HEIGHTPROF = 0
1173 self.HEIGHTPROF = 0
1131 self.xdata = None
1174 self.xdata = None
1132 self.ydata = None
1175 self.ydata = None
1133
1176
1134 self.PLOT_CODE = NOISE_CODE
1177 self.PLOT_CODE = NOISE_CODE
1135
1178
1136 self.FTP_WEI = None
1179 self.FTP_WEI = None
1137 self.EXP_CODE = None
1180 self.EXP_CODE = None
1138 self.SUB_EXP_CODE = None
1181 self.SUB_EXP_CODE = None
1139 self.PLOT_POS = None
1182 self.PLOT_POS = None
1140 self.figfile = None
1183 self.figfile = None
1141
1184
1142 self.xmin = None
1185 self.xmin = None
1143 self.xmax = None
1186 self.xmax = None
1144
1187
1145 def getSubplots(self):
1188 def getSubplots(self):
1146
1189
1147 ncol = 1
1190 ncol = 1
1148 nrow = 1
1191 nrow = 1
1149
1192
1150 return nrow, ncol
1193 return nrow, ncol
1151
1194
1152 def openfile(self, filename):
1195 def openfile(self, filename):
1153 dirname = os.path.dirname(filename)
1196 dirname = os.path.dirname(filename)
1154
1197
1155 if not os.path.exists(dirname):
1198 if not os.path.exists(dirname):
1156 os.mkdir(dirname)
1199 os.mkdir(dirname)
1157
1200
1158 f = open(filename,'w+')
1201 f = open(filename,'w+')
1159 f.write('\n\n')
1202 f.write('\n\n')
1160 f.write('JICAMARCA RADIO OBSERVATORY - Noise \n')
1203 f.write('JICAMARCA RADIO OBSERVATORY - Noise \n')
1161 f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' )
1204 f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' )
1162 f.close()
1205 f.close()
1163
1206
1164 def save_data(self, filename_phase, data, data_datetime):
1207 def save_data(self, filename_phase, data, data_datetime):
1165
1208
1166 f=open(filename_phase,'a')
1209 f=open(filename_phase,'a')
1167
1210
1168 timetuple_data = data_datetime.timetuple()
1211 timetuple_data = data_datetime.timetuple()
1169 day = str(timetuple_data.tm_mday)
1212 day = str(timetuple_data.tm_mday)
1170 month = str(timetuple_data.tm_mon)
1213 month = str(timetuple_data.tm_mon)
1171 year = str(timetuple_data.tm_year)
1214 year = str(timetuple_data.tm_year)
1172 hour = str(timetuple_data.tm_hour)
1215 hour = str(timetuple_data.tm_hour)
1173 minute = str(timetuple_data.tm_min)
1216 minute = str(timetuple_data.tm_min)
1174 second = str(timetuple_data.tm_sec)
1217 second = str(timetuple_data.tm_sec)
1175
1218
1176 data_msg = ''
1219 data_msg = ''
1177 for i in range(len(data)):
1220 for i in range(len(data)):
1178 data_msg += str(data[i]) + ' '
1221 data_msg += str(data[i]) + ' '
1179
1222
1180 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' ' + data_msg + '\n')
1223 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' ' + data_msg + '\n')
1181 f.close()
1224 f.close()
1182
1225
1183
1226
1184 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1227 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1185
1228
1186 self.__showprofile = showprofile
1229 self.__showprofile = showprofile
1187 self.nplots = nplots
1230 self.nplots = nplots
1188
1231
1189 ncolspan = 7
1232 ncolspan = 7
1190 colspan = 6
1233 colspan = 6
1191 self.__nsubplots = 2
1234 self.__nsubplots = 2
1192
1235
1193 self.createFigure(id = id,
1236 self.createFigure(id = id,
1194 wintitle = wintitle,
1237 wintitle = wintitle,
1195 widthplot = self.WIDTH+self.WIDTHPROF,
1238 widthplot = self.WIDTH+self.WIDTHPROF,
1196 heightplot = self.HEIGHT+self.HEIGHTPROF,
1239 heightplot = self.HEIGHT+self.HEIGHTPROF,
1197 show=show)
1240 show=show)
1198
1241
1199 nrow, ncol = self.getSubplots()
1242 nrow, ncol = self.getSubplots()
1200
1243
1201 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1244 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1202
1245
1203
1246
1204 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1247 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1205 xmin=None, xmax=None, ymin=None, ymax=None,
1248 xmin=None, xmax=None, ymin=None, ymax=None,
1206 timerange=None,
1249 timerange=None,
1207 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1250 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1208 server=None, folder=None, username=None, password=None,
1251 server=None, folder=None, username=None, password=None,
1209 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1252 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1210
1253
1211 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1254 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1212 return
1255 return
1213
1256
1214 if channelList == None:
1257 if channelList == None:
1215 channelIndexList = dataOut.channelIndexList
1258 channelIndexList = dataOut.channelIndexList
1216 channelList = dataOut.channelList
1259 channelList = dataOut.channelList
1217 else:
1260 else:
1218 channelIndexList = []
1261 channelIndexList = []
1219 for channel in channelList:
1262 for channel in channelList:
1220 if channel not in dataOut.channelList:
1263 if channel not in dataOut.channelList:
1221 raise ValueError, "Channel %d is not in dataOut.channelList"
1264 raise ValueError, "Channel %d is not in dataOut.channelList"
1222 channelIndexList.append(dataOut.channelList.index(channel))
1265 channelIndexList.append(dataOut.channelList.index(channel))
1223
1266
1224 x = dataOut.getTimeRange()
1267 x = dataOut.getTimeRange()
1225 #y = dataOut.getHeiRange()
1268 #y = dataOut.getHeiRange()
1226 factor = dataOut.normFactor
1269 factor = dataOut.normFactor
1227 noise = dataOut.noise[channelIndexList]/factor
1270 noise = dataOut.noise[channelIndexList]/factor
1228 noisedB = 10*numpy.log10(noise)
1271 noisedB = 10*numpy.log10(noise)
1229
1272
1230 thisDatetime = dataOut.datatime
1273 thisDatetime = dataOut.datatime
1231
1274
1232 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1275 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1233 xlabel = ""
1276 xlabel = ""
1234 ylabel = "Intensity (dB)"
1277 ylabel = "Intensity (dB)"
1235 update_figfile = False
1278 update_figfile = False
1236
1279
1237 if not self.isConfig:
1280 if not self.isConfig:
1238
1281
1239 nplots = 1
1282 nplots = 1
1240
1283
1241 self.setup(id=id,
1284 self.setup(id=id,
1242 nplots=nplots,
1285 nplots=nplots,
1243 wintitle=wintitle,
1286 wintitle=wintitle,
1244 showprofile=showprofile,
1287 showprofile=showprofile,
1245 show=show)
1288 show=show)
1246
1289
1247 if timerange != None:
1290 if timerange != None:
1248 self.timerange = timerange
1291 self.timerange = timerange
1249
1292
1250 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1293 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1251
1294
1252 if ymin == None: ymin = numpy.floor(numpy.nanmin(noisedB)) - 10.0
1295 if ymin == None: ymin = numpy.floor(numpy.nanmin(noisedB)) - 10.0
1253 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1296 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1254
1297
1255 self.FTP_WEI = ftp_wei
1298 self.FTP_WEI = ftp_wei
1256 self.EXP_CODE = exp_code
1299 self.EXP_CODE = exp_code
1257 self.SUB_EXP_CODE = sub_exp_code
1300 self.SUB_EXP_CODE = sub_exp_code
1258 self.PLOT_POS = plot_pos
1301 self.PLOT_POS = plot_pos
1259
1302
1260
1303
1261 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1304 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1262 self.isConfig = True
1305 self.isConfig = True
1263 self.figfile = figfile
1306 self.figfile = figfile
1264 self.xdata = numpy.array([])
1307 self.xdata = numpy.array([])
1265 self.ydata = numpy.array([])
1308 self.ydata = numpy.array([])
1266
1309
1267 update_figfile = True
1310 update_figfile = True
1268
1311
1269 #open file beacon phase
1312 #open file beacon phase
1270 path = '%s%03d' %(self.PREFIX, self.id)
1313 path = '%s%03d' %(self.PREFIX, self.id)
1271 noise_file = os.path.join(path,'%s.txt'%self.name)
1314 noise_file = os.path.join(path,'%s.txt'%self.name)
1272 self.filename_noise = os.path.join(figpath,noise_file)
1315 self.filename_noise = os.path.join(figpath,noise_file)
1273
1316
1274 self.setWinTitle(title)
1317 self.setWinTitle(title)
1275
1318
1276 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1319 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1277
1320
1278 legendlabels = ["channel %d"%(idchannel) for idchannel in channelList]
1321 legendlabels = ["channel %d"%(idchannel) for idchannel in channelList]
1279 axes = self.axesList[0]
1322 axes = self.axesList[0]
1280
1323
1281 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1324 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1282
1325
1283 if len(self.ydata)==0:
1326 if len(self.ydata)==0:
1284 self.ydata = noisedB.reshape(-1,1)
1327 self.ydata = noisedB.reshape(-1,1)
1285 else:
1328 else:
1286 self.ydata = numpy.hstack((self.ydata, noisedB.reshape(-1,1)))
1329 self.ydata = numpy.hstack((self.ydata, noisedB.reshape(-1,1)))
1287
1330
1288
1331
1289 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1332 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1290 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1333 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1291 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1334 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1292 XAxisAsTime=True, grid='both'
1335 XAxisAsTime=True, grid='both'
1293 )
1336 )
1294
1337
1295 self.draw()
1338 self.draw()
1296
1339
1297 if dataOut.ltctime >= self.xmax:
1340 if dataOut.ltctime >= self.xmax:
1298 self.counter_imagwr = wr_period
1341 self.counter_imagwr = wr_period
1299 self.isConfig = False
1342 self.isConfig = False
1300 update_figfile = True
1343 update_figfile = True
1301
1344
1302 self.save(figpath=figpath,
1345 self.save(figpath=figpath,
1303 figfile=figfile,
1346 figfile=figfile,
1304 save=save,
1347 save=save,
1305 ftp=ftp,
1348 ftp=ftp,
1306 wr_period=wr_period,
1349 wr_period=wr_period,
1307 thisDatetime=thisDatetime,
1350 thisDatetime=thisDatetime,
1308 update_figfile=update_figfile)
1351 update_figfile=update_figfile)
1309
1352
1310 #store data beacon phase
1353 #store data beacon phase
1311 if save:
1354 if save:
1312 self.save_data(self.filename_noise, noisedB, thisDatetime)
1355 self.save_data(self.filename_noise, noisedB, thisDatetime)
1313
1356
1314 class BeaconPhase(Figure):
1357 class BeaconPhase(Figure):
1315
1358
1316 __isConfig = None
1359 __isConfig = None
1317 __nsubplots = None
1360 __nsubplots = None
1318
1361
1319 PREFIX = 'beacon_phase'
1362 PREFIX = 'beacon_phase'
1320
1363
1321 def __init__(self, **kwargs):
1364 def __init__(self, **kwargs):
1322 Figure.__init__(self, **kwargs)
1365 Figure.__init__(self, **kwargs)
1323 self.timerange = 24*60*60
1366 self.timerange = 24*60*60
1324 self.isConfig = False
1367 self.isConfig = False
1325 self.__nsubplots = 1
1368 self.__nsubplots = 1
1326 self.counter_imagwr = 0
1369 self.counter_imagwr = 0
1327 self.WIDTH = 800
1370 self.WIDTH = 800
1328 self.HEIGHT = 400
1371 self.HEIGHT = 400
1329 self.WIDTHPROF = 120
1372 self.WIDTHPROF = 120
1330 self.HEIGHTPROF = 0
1373 self.HEIGHTPROF = 0
1331 self.xdata = None
1374 self.xdata = None
1332 self.ydata = None
1375 self.ydata = None
1333
1376
1334 self.PLOT_CODE = BEACON_CODE
1377 self.PLOT_CODE = BEACON_CODE
1335
1378
1336 self.FTP_WEI = None
1379 self.FTP_WEI = None
1337 self.EXP_CODE = None
1380 self.EXP_CODE = None
1338 self.SUB_EXP_CODE = None
1381 self.SUB_EXP_CODE = None
1339 self.PLOT_POS = None
1382 self.PLOT_POS = None
1340
1383
1341 self.filename_phase = None
1384 self.filename_phase = None
1342
1385
1343 self.figfile = None
1386 self.figfile = None
1344
1387
1345 self.xmin = None
1388 self.xmin = None
1346 self.xmax = None
1389 self.xmax = None
1347
1390
1348 def getSubplots(self):
1391 def getSubplots(self):
1349
1392
1350 ncol = 1
1393 ncol = 1
1351 nrow = 1
1394 nrow = 1
1352
1395
1353 return nrow, ncol
1396 return nrow, ncol
1354
1397
1355 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1398 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1356
1399
1357 self.__showprofile = showprofile
1400 self.__showprofile = showprofile
1358 self.nplots = nplots
1401 self.nplots = nplots
1359
1402
1360 ncolspan = 7
1403 ncolspan = 7
1361 colspan = 6
1404 colspan = 6
1362 self.__nsubplots = 2
1405 self.__nsubplots = 2
1363
1406
1364 self.createFigure(id = id,
1407 self.createFigure(id = id,
1365 wintitle = wintitle,
1408 wintitle = wintitle,
1366 widthplot = self.WIDTH+self.WIDTHPROF,
1409 widthplot = self.WIDTH+self.WIDTHPROF,
1367 heightplot = self.HEIGHT+self.HEIGHTPROF,
1410 heightplot = self.HEIGHT+self.HEIGHTPROF,
1368 show=show)
1411 show=show)
1369
1412
1370 nrow, ncol = self.getSubplots()
1413 nrow, ncol = self.getSubplots()
1371
1414
1372 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1415 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1373
1416
1374 def save_phase(self, filename_phase):
1417 def save_phase(self, filename_phase):
1375 f = open(filename_phase,'w+')
1418 f = open(filename_phase,'w+')
1376 f.write('\n\n')
1419 f.write('\n\n')
1377 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
1420 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
1378 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
1421 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
1379 f.close()
1422 f.close()
1380
1423
1381 def save_data(self, filename_phase, data, data_datetime):
1424 def save_data(self, filename_phase, data, data_datetime):
1382 f=open(filename_phase,'a')
1425 f=open(filename_phase,'a')
1383 timetuple_data = data_datetime.timetuple()
1426 timetuple_data = data_datetime.timetuple()
1384 day = str(timetuple_data.tm_mday)
1427 day = str(timetuple_data.tm_mday)
1385 month = str(timetuple_data.tm_mon)
1428 month = str(timetuple_data.tm_mon)
1386 year = str(timetuple_data.tm_year)
1429 year = str(timetuple_data.tm_year)
1387 hour = str(timetuple_data.tm_hour)
1430 hour = str(timetuple_data.tm_hour)
1388 minute = str(timetuple_data.tm_min)
1431 minute = str(timetuple_data.tm_min)
1389 second = str(timetuple_data.tm_sec)
1432 second = str(timetuple_data.tm_sec)
1390 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1433 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1391 f.close()
1434 f.close()
1392
1435
1393
1436
1394 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1437 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1395 xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None,
1438 xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None,
1396 timerange=None,
1439 timerange=None,
1397 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1440 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1398 server=None, folder=None, username=None, password=None,
1441 server=None, folder=None, username=None, password=None,
1399 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1442 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1400
1443
1401 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1444 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1402 return
1445 return
1403
1446
1404 if pairsList == None:
1447 if pairsList == None:
1405 pairsIndexList = dataOut.pairsIndexList[:10]
1448 pairsIndexList = dataOut.pairsIndexList[:10]
1406 else:
1449 else:
1407 pairsIndexList = []
1450 pairsIndexList = []
1408 for pair in pairsList:
1451 for pair in pairsList:
1409 if pair not in dataOut.pairsList:
1452 if pair not in dataOut.pairsList:
1410 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
1453 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
1411 pairsIndexList.append(dataOut.pairsList.index(pair))
1454 pairsIndexList.append(dataOut.pairsList.index(pair))
1412
1455
1413 if pairsIndexList == []:
1456 if pairsIndexList == []:
1414 return
1457 return
1415
1458
1416 # if len(pairsIndexList) > 4:
1459 # if len(pairsIndexList) > 4:
1417 # pairsIndexList = pairsIndexList[0:4]
1460 # pairsIndexList = pairsIndexList[0:4]
1418
1461
1419 hmin_index = None
1462 hmin_index = None
1420 hmax_index = None
1463 hmax_index = None
1421
1464
1422 if hmin != None and hmax != None:
1465 if hmin != None and hmax != None:
1423 indexes = numpy.arange(dataOut.nHeights)
1466 indexes = numpy.arange(dataOut.nHeights)
1424 hmin_list = indexes[dataOut.heightList >= hmin]
1467 hmin_list = indexes[dataOut.heightList >= hmin]
1425 hmax_list = indexes[dataOut.heightList <= hmax]
1468 hmax_list = indexes[dataOut.heightList <= hmax]
1426
1469
1427 if hmin_list.any():
1470 if hmin_list.any():
1428 hmin_index = hmin_list[0]
1471 hmin_index = hmin_list[0]
1429
1472
1430 if hmax_list.any():
1473 if hmax_list.any():
1431 hmax_index = hmax_list[-1]+1
1474 hmax_index = hmax_list[-1]+1
1432
1475
1433 x = dataOut.getTimeRange()
1476 x = dataOut.getTimeRange()
1434 #y = dataOut.getHeiRange()
1477 #y = dataOut.getHeiRange()
1435
1478
1436
1479
1437 thisDatetime = dataOut.datatime
1480 thisDatetime = dataOut.datatime
1438
1481
1439 title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1482 title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1440 xlabel = "Local Time"
1483 xlabel = "Local Time"
1441 ylabel = "Phase (degrees)"
1484 ylabel = "Phase (degrees)"
1442
1485
1443 update_figfile = False
1486 update_figfile = False
1444
1487
1445 nplots = len(pairsIndexList)
1488 nplots = len(pairsIndexList)
1446 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1489 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1447 phase_beacon = numpy.zeros(len(pairsIndexList))
1490 phase_beacon = numpy.zeros(len(pairsIndexList))
1448 for i in range(nplots):
1491 for i in range(nplots):
1449 pair = dataOut.pairsList[pairsIndexList[i]]
1492 pair = dataOut.pairsList[pairsIndexList[i]]
1450 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0)
1493 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0)
1451 powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0)
1494 powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0)
1452 powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0)
1495 powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0)
1453 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
1496 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
1454 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1497 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1455
1498
1456 #print "Phase %d%d" %(pair[0], pair[1])
1499 #print "Phase %d%d" %(pair[0], pair[1])
1457 #print phase[dataOut.beacon_heiIndexList]
1500 #print phase[dataOut.beacon_heiIndexList]
1458
1501
1459 if dataOut.beacon_heiIndexList:
1502 if dataOut.beacon_heiIndexList:
1460 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
1503 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
1461 else:
1504 else:
1462 phase_beacon[i] = numpy.average(phase)
1505 phase_beacon[i] = numpy.average(phase)
1463
1506
1464 if not self.isConfig:
1507 if not self.isConfig:
1465
1508
1466 nplots = len(pairsIndexList)
1509 nplots = len(pairsIndexList)
1467
1510
1468 self.setup(id=id,
1511 self.setup(id=id,
1469 nplots=nplots,
1512 nplots=nplots,
1470 wintitle=wintitle,
1513 wintitle=wintitle,
1471 showprofile=showprofile,
1514 showprofile=showprofile,
1472 show=show)
1515 show=show)
1473
1516
1474 if timerange != None:
1517 if timerange != None:
1475 self.timerange = timerange
1518 self.timerange = timerange
1476
1519
1477 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1520 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1478
1521
1479 if ymin == None: ymin = 0
1522 if ymin == None: ymin = 0
1480 if ymax == None: ymax = 360
1523 if ymax == None: ymax = 360
1481
1524
1482 self.FTP_WEI = ftp_wei
1525 self.FTP_WEI = ftp_wei
1483 self.EXP_CODE = exp_code
1526 self.EXP_CODE = exp_code
1484 self.SUB_EXP_CODE = sub_exp_code
1527 self.SUB_EXP_CODE = sub_exp_code
1485 self.PLOT_POS = plot_pos
1528 self.PLOT_POS = plot_pos
1486
1529
1487 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1530 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1488 self.isConfig = True
1531 self.isConfig = True
1489 self.figfile = figfile
1532 self.figfile = figfile
1490 self.xdata = numpy.array([])
1533 self.xdata = numpy.array([])
1491 self.ydata = numpy.array([])
1534 self.ydata = numpy.array([])
1492
1535
1493 update_figfile = True
1536 update_figfile = True
1494
1537
1495 #open file beacon phase
1538 #open file beacon phase
1496 path = '%s%03d' %(self.PREFIX, self.id)
1539 path = '%s%03d' %(self.PREFIX, self.id)
1497 beacon_file = os.path.join(path,'%s.txt'%self.name)
1540 beacon_file = os.path.join(path,'%s.txt'%self.name)
1498 self.filename_phase = os.path.join(figpath,beacon_file)
1541 self.filename_phase = os.path.join(figpath,beacon_file)
1499 #self.save_phase(self.filename_phase)
1542 #self.save_phase(self.filename_phase)
1500
1543
1501
1544
1502 #store data beacon phase
1545 #store data beacon phase
1503 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1546 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1504
1547
1505 self.setWinTitle(title)
1548 self.setWinTitle(title)
1506
1549
1507
1550
1508 title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1551 title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1509
1552
1510 legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList]
1553 legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList]
1511
1554
1512 axes = self.axesList[0]
1555 axes = self.axesList[0]
1513
1556
1514 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1557 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1515
1558
1516 if len(self.ydata)==0:
1559 if len(self.ydata)==0:
1517 self.ydata = phase_beacon.reshape(-1,1)
1560 self.ydata = phase_beacon.reshape(-1,1)
1518 else:
1561 else:
1519 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1562 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1520
1563
1521
1564
1522 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1565 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1523 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1566 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1524 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1567 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1525 XAxisAsTime=True, grid='both'
1568 XAxisAsTime=True, grid='both'
1526 )
1569 )
1527
1570
1528 self.draw()
1571 self.draw()
1529
1572
1530 if dataOut.ltctime >= self.xmax:
1573 if dataOut.ltctime >= self.xmax:
1531 self.counter_imagwr = wr_period
1574 self.counter_imagwr = wr_period
1532 self.isConfig = False
1575 self.isConfig = False
1533 update_figfile = True
1576 update_figfile = True
1534
1577
1535 self.save(figpath=figpath,
1578 self.save(figpath=figpath,
1536 figfile=figfile,
1579 figfile=figfile,
1537 save=save,
1580 save=save,
1538 ftp=ftp,
1581 ftp=ftp,
1539 wr_period=wr_period,
1582 wr_period=wr_period,
1540 thisDatetime=thisDatetime,
1583 thisDatetime=thisDatetime,
1541 update_figfile=update_figfile)
1584 update_figfile=update_figfile)
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
@@ -1,1193 +1,1194
1 import os, sys
1 import os, sys
2 import glob
2 import glob
3 import fnmatch
3 import fnmatch
4 import datetime
4 import datetime
5 import time
5 import time
6 import re
6 import re
7 import h5py
7 import h5py
8 import numpy
8 import numpy
9 import matplotlib.pyplot as plt
9 import matplotlib.pyplot as plt
10
10
11 import pylab as plb
11 import pylab as plb
12 from scipy.optimize import curve_fit
12 from scipy.optimize import curve_fit
13 from scipy import asarray as ar,exp
13 from scipy import asarray as ar,exp
14 from scipy import stats
14 from scipy import stats
15
15
16 from duplicity.path import Path
16 from duplicity.path import Path
17 from numpy.ma.core import getdata
17 from numpy.ma.core import getdata
18
18
19 SPEED_OF_LIGHT = 299792458
19 SPEED_OF_LIGHT = 299792458
20 SPEED_OF_LIGHT = 3e8
20 SPEED_OF_LIGHT = 3e8
21
21
22 try:
22 try:
23 from gevent import sleep
23 from gevent import sleep
24 except:
24 except:
25 from time import sleep
25 from time import sleep
26
26
27 from schainpy.model.data.jrodata import Spectra
27 from schainpy.model.data.jrodata import Spectra
28 #from schainpy.model.data.BLTRheaderIO import FileHeader, RecordHeader
28 #from schainpy.model.data.BLTRheaderIO import FileHeader, RecordHeader
29 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
29 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
30 #from schainpy.model.io.jroIO_bltr import BLTRReader
30 #from schainpy.model.io.jroIO_bltr import BLTRReader
31 from numpy import imag, shape, NaN
31 from numpy import imag, shape, NaN
32
32
33 from jroIO_base import JRODataReader
33 from jroIO_base import JRODataReader
34
34
35
35
36 class Header(object):
36 class Header(object):
37
37
38 def __init__(self):
38 def __init__(self):
39 raise NotImplementedError
39 raise NotImplementedError
40
40
41
41
42 def read(self):
42 def read(self):
43
43
44 raise NotImplementedError
44 raise NotImplementedError
45
45
46 def write(self):
46 def write(self):
47
47
48 raise NotImplementedError
48 raise NotImplementedError
49
49
50 def printInfo(self):
50 def printInfo(self):
51
51
52 message = "#"*50 + "\n"
52 message = "#"*50 + "\n"
53 message += self.__class__.__name__.upper() + "\n"
53 message += self.__class__.__name__.upper() + "\n"
54 message += "#"*50 + "\n"
54 message += "#"*50 + "\n"
55
55
56 keyList = self.__dict__.keys()
56 keyList = self.__dict__.keys()
57 keyList.sort()
57 keyList.sort()
58
58
59 for key in keyList:
59 for key in keyList:
60 message += "%s = %s" %(key, self.__dict__[key]) + "\n"
60 message += "%s = %s" %(key, self.__dict__[key]) + "\n"
61
61
62 if "size" not in keyList:
62 if "size" not in keyList:
63 attr = getattr(self, "size")
63 attr = getattr(self, "size")
64
64
65 if attr:
65 if attr:
66 message += "%s = %s" %("size", attr) + "\n"
66 message += "%s = %s" %("size", attr) + "\n"
67
67
68 #print message
68 #print message
69
69
70
70
71
71
72
72
73
73
74 FILE_STRUCTURE = numpy.dtype([ #HEADER 48bytes
74 FILE_STRUCTURE = numpy.dtype([ #HEADER 48bytes
75 ('FileMgcNumber','<u4'), #0x23020100
75 ('FileMgcNumber','<u4'), #0x23020100
76 ('nFDTdataRecors','<u4'), #No Of FDT data records in this file (0 or more)
76 ('nFDTdataRecors','<u4'), #No Of FDT data records in this file (0 or more)
77 ('OffsetStartHeader','<u4'),
77 ('OffsetStartHeader','<u4'),
78 ('RadarUnitId','<u4'),
78 ('RadarUnitId','<u4'),
79 ('SiteName',numpy.str_,32), #Null terminated
79 ('SiteName',numpy.str_,32), #Null terminated
80 ])
80 ])
81
81
82 class FileHeaderBLTR(Header):
82 class FileHeaderBLTR(Header):
83
83
84 def __init__(self):
84 def __init__(self):
85
85
86 self.FileMgcNumber= 0 #0x23020100
86 self.FileMgcNumber= 0 #0x23020100
87 self.nFDTdataRecors=0 #No Of FDT data records in this file (0 or more)
87 self.nFDTdataRecors=0 #No Of FDT data records in this file (0 or more)
88 self.RadarUnitId= 0
88 self.RadarUnitId= 0
89 self.OffsetStartHeader=0
89 self.OffsetStartHeader=0
90 self.SiteName= ""
90 self.SiteName= ""
91 self.size = 48
91 self.size = 48
92
92
93 def FHread(self, fp):
93 def FHread(self, fp):
94 #try:
94 #try:
95 startFp = open(fp,"rb")
95 startFp = open(fp,"rb")
96
96
97 header = numpy.fromfile(startFp, FILE_STRUCTURE,1)
97 header = numpy.fromfile(startFp, FILE_STRUCTURE,1)
98
98
99 print ' '
99 print ' '
100 print 'puntero file header', startFp.tell()
100 print 'puntero file header', startFp.tell()
101 print ' '
101 print ' '
102
102
103
103
104 ''' numpy.fromfile(file, dtype, count, sep='')
104 ''' numpy.fromfile(file, dtype, count, sep='')
105 file : file or str
105 file : file or str
106 Open file object or filename.
106 Open file object or filename.
107
107
108 dtype : data-type
108 dtype : data-type
109 Data type of the returned array. For binary files, it is used to determine
109 Data type of the returned array. For binary files, it is used to determine
110 the size and byte-order of the items in the file.
110 the size and byte-order of the items in the file.
111
111
112 count : int
112 count : int
113 Number of items to read. -1 means all items (i.e., the complete file).
113 Number of items to read. -1 means all items (i.e., the complete file).
114
114
115 sep : str
115 sep : str
116 Separator between items if file is a text file. Empty ("") separator means
116 Separator between items if file is a text file. Empty ("") separator means
117 the file should be treated as binary. Spaces (" ") in the separator match zero
117 the file should be treated as binary. Spaces (" ") in the separator match zero
118 or more whitespace characters. A separator consisting only of spaces must match
118 or more whitespace characters. A separator consisting only of spaces must match
119 at least one whitespace.
119 at least one whitespace.
120
120
121 '''
121 '''
122
122
123
123
124
124
125 self.FileMgcNumber= hex(header['FileMgcNumber'][0])
125 self.FileMgcNumber= hex(header['FileMgcNumber'][0])
126 self.nFDTdataRecors=int(header['nFDTdataRecors'][0]) #No Of FDT data records in this file (0 or more)
126 self.nFDTdataRecors=int(header['nFDTdataRecors'][0]) #No Of FDT data records in this file (0 or more)
127 self.RadarUnitId= int(header['RadarUnitId'][0])
127 self.RadarUnitId= int(header['RadarUnitId'][0])
128 self.OffsetStartHeader= int(header['OffsetStartHeader'][0])
128 self.OffsetStartHeader= int(header['OffsetStartHeader'][0])
129 self.SiteName= str(header['SiteName'][0])
129 self.SiteName= str(header['SiteName'][0])
130
130
131 #print 'Numero de bloques', self.nFDTdataRecors
131 #print 'Numero de bloques', self.nFDTdataRecors
132
132
133
133
134 if self.size <48:
134 if self.size <48:
135 return 0
135 return 0
136
136
137 return 1
137 return 1
138
138
139
139
140 def write(self, fp):
140 def write(self, fp):
141
141
142 headerTuple = (self.FileMgcNumber,
142 headerTuple = (self.FileMgcNumber,
143 self.nFDTdataRecors,
143 self.nFDTdataRecors,
144 self.RadarUnitId,
144 self.RadarUnitId,
145 self.SiteName,
145 self.SiteName,
146 self.size)
146 self.size)
147
147
148
148
149 header = numpy.array(headerTuple, FILE_STRUCTURE)
149 header = numpy.array(headerTuple, FILE_STRUCTURE)
150 # numpy.array(object, dtype=None, copy=True, order=None, subok=False, ndmin=0)
150 # numpy.array(object, dtype=None, copy=True, order=None, subok=False, ndmin=0)
151 header.tofile(fp)
151 header.tofile(fp)
152 ''' ndarray.tofile(fid, sep, format) Write array to a file as text or binary (default).
152 ''' ndarray.tofile(fid, sep, format) Write array to a file as text or binary (default).
153
153
154 fid : file or str
154 fid : file or str
155 An open file object, or a string containing a filename.
155 An open file object, or a string containing a filename.
156
156
157 sep : str
157 sep : str
158 Separator between array items for text output. If "" (empty), a binary file is written,
158 Separator between array items for text output. If "" (empty), a binary file is written,
159 equivalent to file.write(a.tobytes()).
159 equivalent to file.write(a.tobytes()).
160
160
161 format : str
161 format : str
162 Format string for text file output. Each entry in the array is formatted to text by
162 Format string for text file output. Each entry in the array is formatted to text by
163 first converting it to the closest Python type, and then using "format" % item.
163 first converting it to the closest Python type, and then using "format" % item.
164
164
165 '''
165 '''
166
166
167 return 1
167 return 1
168
168
169
169
170
170
171
171
172
172
173 RECORD_STRUCTURE = numpy.dtype([ #RECORD HEADER 180+20N bytes
173 RECORD_STRUCTURE = numpy.dtype([ #RECORD HEADER 180+20N bytes
174 ('RecMgcNumber','<u4'), #0x23030001
174 ('RecMgcNumber','<u4'), #0x23030001
175 ('RecCounter','<u4'), #Record counter(0,1, ...)
175 ('RecCounter','<u4'), #Record counter(0,1, ...)
176 ('Off2StartNxtRec','<u4'), #Offset to start of next record form start of this record
176 ('Off2StartNxtRec','<u4'), #Offset to start of next record form start of this record
177 ('Off2StartData','<u4'), #Offset to start of data from start of this record
177 ('Off2StartData','<u4'), #Offset to start of data from start of this record
178 ('nUtime','<i4'), #Epoch time stamp of start of acquisition (seconds)
178 ('nUtime','<i4'), #Epoch time stamp of start of acquisition (seconds)
179 ('nMilisec','<u4'), #Millisecond component of time stamp (0,...,999)
179 ('nMilisec','<u4'), #Millisecond component of time stamp (0,...,999)
180 ('ExpTagName',numpy.str_,32), #Experiment tag name (null terminated)
180 ('ExpTagName',numpy.str_,32), #Experiment tag name (null terminated)
181 ('ExpComment',numpy.str_,32), #Experiment comment (null terminated)
181 ('ExpComment',numpy.str_,32), #Experiment comment (null terminated)
182 ('SiteLatDegrees','<f4'), #Site latitude (from GPS) in degrees (positive implies North)
182 ('SiteLatDegrees','<f4'), #Site latitude (from GPS) in degrees (positive implies North)
183 ('SiteLongDegrees','<f4'), #Site longitude (from GPS) in degrees (positive implies East)
183 ('SiteLongDegrees','<f4'), #Site longitude (from GPS) in degrees (positive implies East)
184 ('RTCgpsStatus','<u4'), #RTC GPS engine status (0=SEEK, 1=LOCK, 2=NOT FITTED, 3=UNAVAILABLE)
184 ('RTCgpsStatus','<u4'), #RTC GPS engine status (0=SEEK, 1=LOCK, 2=NOT FITTED, 3=UNAVAILABLE)
185 ('TransmitFrec','<u4'), #Transmit frequency (Hz)
185 ('TransmitFrec','<u4'), #Transmit frequency (Hz)
186 ('ReceiveFrec','<u4'), #Receive frequency
186 ('ReceiveFrec','<u4'), #Receive frequency
187 ('FirstOsciFrec','<u4'), #First local oscillator frequency (Hz)
187 ('FirstOsciFrec','<u4'), #First local oscillator frequency (Hz)
188 ('Polarisation','<u4'), #(0="O", 1="E", 2="linear 1", 3="linear2")
188 ('Polarisation','<u4'), #(0="O", 1="E", 2="linear 1", 3="linear2")
189 ('ReceiverFiltSett','<u4'), #Receiver filter settings (0,1,2,3)
189 ('ReceiverFiltSett','<u4'), #Receiver filter settings (0,1,2,3)
190 ('nModesInUse','<u4'), #Number of modes in use (1 or 2)
190 ('nModesInUse','<u4'), #Number of modes in use (1 or 2)
191 ('DualModeIndex','<u4'), #Dual Mode index number for these data (0 or 1)
191 ('DualModeIndex','<u4'), #Dual Mode index number for these data (0 or 1)
192 ('DualModeRange','<u4'), #Dual Mode range correction for these data (m)
192 ('DualModeRange','<u4'), #Dual Mode range correction for these data (m)
193 ('nDigChannels','<u4'), #Number of digital channels acquired (2*N)
193 ('nDigChannels','<u4'), #Number of digital channels acquired (2*N)
194 ('SampResolution','<u4'), #Sampling resolution (meters)
194 ('SampResolution','<u4'), #Sampling resolution (meters)
195 ('nHeights','<u4'), #Number of range gates sampled
195 ('nHeights','<u4'), #Number of range gates sampled
196 ('StartRangeSamp','<u4'), #Start range of sampling (meters)
196 ('StartRangeSamp','<u4'), #Start range of sampling (meters)
197 ('PRFhz','<u4'), #PRF (Hz)
197 ('PRFhz','<u4'), #PRF (Hz)
198 ('nCohInt','<u4'), #Integrations
198 ('nCohInt','<u4'), #Integrations
199 ('nProfiles','<u4'), #Number of data points transformed
199 ('nProfiles','<u4'), #Number of data points transformed
200 ('nChannels','<u4'), #Number of receive beams stored in file (1 or N)
200 ('nChannels','<u4'), #Number of receive beams stored in file (1 or N)
201 ('nIncohInt','<u4'), #Number of spectral averages
201 ('nIncohInt','<u4'), #Number of spectral averages
202 ('FFTwindowingInd','<u4'), #FFT windowing index (0 = no window)
202 ('FFTwindowingInd','<u4'), #FFT windowing index (0 = no window)
203 ('BeamAngleAzim','<f4'), #Beam steer angle (azimuth) in degrees (clockwise from true North)
203 ('BeamAngleAzim','<f4'), #Beam steer angle (azimuth) in degrees (clockwise from true North)
204 ('BeamAngleZen','<f4'), #Beam steer angle (zenith) in degrees (0=> vertical)
204 ('BeamAngleZen','<f4'), #Beam steer angle (zenith) in degrees (0=> vertical)
205 ('AntennaCoord0','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
205 ('AntennaCoord0','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
206 ('AntennaAngl0','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
206 ('AntennaAngl0','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
207 ('AntennaCoord1','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
207 ('AntennaCoord1','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
208 ('AntennaAngl1','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
208 ('AntennaAngl1','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
209 ('AntennaCoord2','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
209 ('AntennaCoord2','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
210 ('AntennaAngl2','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
210 ('AntennaAngl2','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
211 ('RecPhaseCalibr0','<f4'), #Receiver phase calibration (degrees) - N values
211 ('RecPhaseCalibr0','<f4'), #Receiver phase calibration (degrees) - N values
212 ('RecPhaseCalibr1','<f4'), #Receiver phase calibration (degrees) - N values
212 ('RecPhaseCalibr1','<f4'), #Receiver phase calibration (degrees) - N values
213 ('RecPhaseCalibr2','<f4'), #Receiver phase calibration (degrees) - N values
213 ('RecPhaseCalibr2','<f4'), #Receiver phase calibration (degrees) - N values
214 ('RecAmpCalibr0','<f4'), #Receiver amplitude calibration (ratio relative to receiver one) - N values
214 ('RecAmpCalibr0','<f4'), #Receiver amplitude calibration (ratio relative to receiver one) - N values
215 ('RecAmpCalibr1','<f4'), #Receiver amplitude calibration (ratio relative to receiver one) - N values
215 ('RecAmpCalibr1','<f4'), #Receiver amplitude calibration (ratio relative to receiver one) - N values
216 ('RecAmpCalibr2','<f4'), #Receiver amplitude calibration (ratio relative to receiver one) - N values
216 ('RecAmpCalibr2','<f4'), #Receiver amplitude calibration (ratio relative to receiver one) - N values
217 ('ReceiverGaindB0','<i4'), #Receiver gains in dB - N values
217 ('ReceiverGaindB0','<i4'), #Receiver gains in dB - N values
218 ('ReceiverGaindB1','<i4'), #Receiver gains in dB - N values
218 ('ReceiverGaindB1','<i4'), #Receiver gains in dB - N values
219 ('ReceiverGaindB2','<i4'), #Receiver gains in dB - N values
219 ('ReceiverGaindB2','<i4'), #Receiver gains in dB - N values
220 ])
220 ])
221
221
222
222
223 class RecordHeaderBLTR(Header):
223 class RecordHeaderBLTR(Header):
224
224
225 def __init__(self, RecMgcNumber=None, RecCounter= 0, Off2StartNxtRec= 811248,
225 def __init__(self, RecMgcNumber=None, RecCounter= 0, Off2StartNxtRec= 811248,
226 nUtime= 0, nMilisec= 0, ExpTagName= None,
226 nUtime= 0, nMilisec= 0, ExpTagName= None,
227 ExpComment=None, SiteLatDegrees=0, SiteLongDegrees= 0,
227 ExpComment=None, SiteLatDegrees=0, SiteLongDegrees= 0,
228 RTCgpsStatus= 0, TransmitFrec= 0, ReceiveFrec= 0,
228 RTCgpsStatus= 0, TransmitFrec= 0, ReceiveFrec= 0,
229 FirstOsciFrec= 0, Polarisation= 0, ReceiverFiltSett= 0,
229 FirstOsciFrec= 0, Polarisation= 0, ReceiverFiltSett= 0,
230 nModesInUse= 0, DualModeIndex= 0, DualModeRange= 0,
230 nModesInUse= 0, DualModeIndex= 0, DualModeRange= 0,
231 nDigChannels= 0, SampResolution= 0, nHeights= 0,
231 nDigChannels= 0, SampResolution= 0, nHeights= 0,
232 StartRangeSamp= 0, PRFhz= 0, nCohInt= 0,
232 StartRangeSamp= 0, PRFhz= 0, nCohInt= 0,
233 nProfiles= 0, nChannels= 0, nIncohInt= 0,
233 nProfiles= 0, nChannels= 0, nIncohInt= 0,
234 FFTwindowingInd= 0, BeamAngleAzim= 0, BeamAngleZen= 0,
234 FFTwindowingInd= 0, BeamAngleAzim= 0, BeamAngleZen= 0,
235 AntennaCoord0= 0, AntennaCoord1= 0, AntennaCoord2= 0,
235 AntennaCoord0= 0, AntennaCoord1= 0, AntennaCoord2= 0,
236 RecPhaseCalibr0= 0, RecPhaseCalibr1= 0, RecPhaseCalibr2= 0,
236 RecPhaseCalibr0= 0, RecPhaseCalibr1= 0, RecPhaseCalibr2= 0,
237 RecAmpCalibr0= 0, RecAmpCalibr1= 0, RecAmpCalibr2= 0,
237 RecAmpCalibr0= 0, RecAmpCalibr1= 0, RecAmpCalibr2= 0,
238 AntennaAngl0=0, AntennaAngl1=0, AntennaAngl2=0,
238 AntennaAngl0=0, AntennaAngl1=0, AntennaAngl2=0,
239 ReceiverGaindB0= 0, ReceiverGaindB1= 0, ReceiverGaindB2= 0, Off2StartData=0, OffsetStartHeader=0):
239 ReceiverGaindB0= 0, ReceiverGaindB1= 0, ReceiverGaindB2= 0, Off2StartData=0, OffsetStartHeader=0):
240
240
241 self.RecMgcNumber = RecMgcNumber #0x23030001
241 self.RecMgcNumber = RecMgcNumber #0x23030001
242 self.RecCounter = RecCounter
242 self.RecCounter = RecCounter
243 self.Off2StartNxtRec = Off2StartNxtRec
243 self.Off2StartNxtRec = Off2StartNxtRec
244 self.Off2StartData = Off2StartData
244 self.Off2StartData = Off2StartData
245 self.nUtime = nUtime
245 self.nUtime = nUtime
246 self.nMilisec = nMilisec
246 self.nMilisec = nMilisec
247 self.ExpTagName = ExpTagName
247 self.ExpTagName = ExpTagName
248 self.ExpComment = ExpComment
248 self.ExpComment = ExpComment
249 self.SiteLatDegrees = SiteLatDegrees
249 self.SiteLatDegrees = SiteLatDegrees
250 self.SiteLongDegrees = SiteLongDegrees
250 self.SiteLongDegrees = SiteLongDegrees
251 self.RTCgpsStatus = RTCgpsStatus
251 self.RTCgpsStatus = RTCgpsStatus
252 self.TransmitFrec = TransmitFrec
252 self.TransmitFrec = TransmitFrec
253 self.ReceiveFrec = ReceiveFrec
253 self.ReceiveFrec = ReceiveFrec
254 self.FirstOsciFrec = FirstOsciFrec
254 self.FirstOsciFrec = FirstOsciFrec
255 self.Polarisation = Polarisation
255 self.Polarisation = Polarisation
256 self.ReceiverFiltSett = ReceiverFiltSett
256 self.ReceiverFiltSett = ReceiverFiltSett
257 self.nModesInUse = nModesInUse
257 self.nModesInUse = nModesInUse
258 self.DualModeIndex = DualModeIndex
258 self.DualModeIndex = DualModeIndex
259 self.DualModeRange = DualModeRange
259 self.DualModeRange = DualModeRange
260 self.nDigChannels = nDigChannels
260 self.nDigChannels = nDigChannels
261 self.SampResolution = SampResolution
261 self.SampResolution = SampResolution
262 self.nHeights = nHeights
262 self.nHeights = nHeights
263 self.StartRangeSamp = StartRangeSamp
263 self.StartRangeSamp = StartRangeSamp
264 self.PRFhz = PRFhz
264 self.PRFhz = PRFhz
265 self.nCohInt = nCohInt
265 self.nCohInt = nCohInt
266 self.nProfiles = nProfiles
266 self.nProfiles = nProfiles
267 self.nChannels = nChannels
267 self.nChannels = nChannels
268 self.nIncohInt = nIncohInt
268 self.nIncohInt = nIncohInt
269 self.FFTwindowingInd = FFTwindowingInd
269 self.FFTwindowingInd = FFTwindowingInd
270 self.BeamAngleAzim = BeamAngleAzim
270 self.BeamAngleAzim = BeamAngleAzim
271 self.BeamAngleZen = BeamAngleZen
271 self.BeamAngleZen = BeamAngleZen
272 self.AntennaCoord0 = AntennaCoord0
272 self.AntennaCoord0 = AntennaCoord0
273 self.AntennaAngl0 = AntennaAngl0
273 self.AntennaAngl0 = AntennaAngl0
274 self.AntennaAngl1 = AntennaAngl1
274 self.AntennaAngl1 = AntennaAngl1
275 self.AntennaAngl2 = AntennaAngl2
275 self.AntennaAngl2 = AntennaAngl2
276 self.AntennaCoord1 = AntennaCoord1
276 self.AntennaCoord1 = AntennaCoord1
277 self.AntennaCoord2 = AntennaCoord2
277 self.AntennaCoord2 = AntennaCoord2
278 self.RecPhaseCalibr0 = RecPhaseCalibr0
278 self.RecPhaseCalibr0 = RecPhaseCalibr0
279 self.RecPhaseCalibr1 = RecPhaseCalibr1
279 self.RecPhaseCalibr1 = RecPhaseCalibr1
280 self.RecPhaseCalibr2 = RecPhaseCalibr2
280 self.RecPhaseCalibr2 = RecPhaseCalibr2
281 self.RecAmpCalibr0 = RecAmpCalibr0
281 self.RecAmpCalibr0 = RecAmpCalibr0
282 self.RecAmpCalibr1 = RecAmpCalibr1
282 self.RecAmpCalibr1 = RecAmpCalibr1
283 self.RecAmpCalibr2 = RecAmpCalibr2
283 self.RecAmpCalibr2 = RecAmpCalibr2
284 self.ReceiverGaindB0 = ReceiverGaindB0
284 self.ReceiverGaindB0 = ReceiverGaindB0
285 self.ReceiverGaindB1 = ReceiverGaindB1
285 self.ReceiverGaindB1 = ReceiverGaindB1
286 self.ReceiverGaindB2 = ReceiverGaindB2
286 self.ReceiverGaindB2 = ReceiverGaindB2
287 self.OffsetStartHeader = 48
287 self.OffsetStartHeader = 48
288
288
289
289
290
290
291 def RHread(self, fp):
291 def RHread(self, fp):
292 #print fp
292 #print fp
293 #startFp = open('/home/erick/Documents/Data/huancayo.20161019.22.fdt',"rb") #The method tell() returns the current position of the file read/write pointer within the file.
293 #startFp = open('/home/erick/Documents/Data/huancayo.20161019.22.fdt',"rb") #The method tell() returns the current position of the file read/write pointer within the file.
294 startFp = open(fp,"rb") #The method tell() returns the current position of the file read/write pointer within the file.
294 startFp = open(fp,"rb") #The method tell() returns the current position of the file read/write pointer within the file.
295 #RecCounter=0
295 #RecCounter=0
296 #Off2StartNxtRec=811248
296 #Off2StartNxtRec=811248
297 OffRHeader= self.OffsetStartHeader + self.RecCounter*self.Off2StartNxtRec
297 OffRHeader= self.OffsetStartHeader + self.RecCounter*self.Off2StartNxtRec
298 print ' '
298 print ' '
299 print 'puntero Record Header', startFp.tell()
299 print 'puntero Record Header', startFp.tell()
300 print ' '
300 print ' '
301
301
302
302
303 startFp.seek(OffRHeader, os.SEEK_SET)
303 startFp.seek(OffRHeader, os.SEEK_SET)
304
304
305 print ' '
305 print ' '
306 print 'puntero Record Header con seek', startFp.tell()
306 print 'puntero Record Header con seek', startFp.tell()
307 print ' '
307 print ' '
308
308
309 #print 'Posicion del bloque: ',OffRHeader
309 #print 'Posicion del bloque: ',OffRHeader
310
310
311 header = numpy.fromfile(startFp,RECORD_STRUCTURE,1)
311 header = numpy.fromfile(startFp,RECORD_STRUCTURE,1)
312
312
313 print ' '
313 print ' '
314 print 'puntero Record Header con seek', startFp.tell()
314 print 'puntero Record Header con seek', startFp.tell()
315 print ' '
315 print ' '
316
316
317 print ' '
317 print ' '
318 #
318 #
319 #print 'puntero Record Header despues de seek', header.tell()
319 #print 'puntero Record Header despues de seek', header.tell()
320 print ' '
320 print ' '
321
321
322 self.RecMgcNumber = hex(header['RecMgcNumber'][0]) #0x23030001
322 self.RecMgcNumber = hex(header['RecMgcNumber'][0]) #0x23030001
323 self.RecCounter = int(header['RecCounter'][0])
323 self.RecCounter = int(header['RecCounter'][0])
324 self.Off2StartNxtRec = int(header['Off2StartNxtRec'][0])
324 self.Off2StartNxtRec = int(header['Off2StartNxtRec'][0])
325 self.Off2StartData = int(header['Off2StartData'][0])
325 self.Off2StartData = int(header['Off2StartData'][0])
326 self.nUtime = header['nUtime'][0]
326 self.nUtime = header['nUtime'][0]
327 self.nMilisec = header['nMilisec'][0]
327 self.nMilisec = header['nMilisec'][0]
328 self.ExpTagName = str(header['ExpTagName'][0])
328 self.ExpTagName = str(header['ExpTagName'][0])
329 self.ExpComment = str(header['ExpComment'][0])
329 self.ExpComment = str(header['ExpComment'][0])
330 self.SiteLatDegrees = header['SiteLatDegrees'][0]
330 self.SiteLatDegrees = header['SiteLatDegrees'][0]
331 self.SiteLongDegrees = header['SiteLongDegrees'][0]
331 self.SiteLongDegrees = header['SiteLongDegrees'][0]
332 self.RTCgpsStatus = header['RTCgpsStatus'][0]
332 self.RTCgpsStatus = header['RTCgpsStatus'][0]
333 self.TransmitFrec = header['TransmitFrec'][0]
333 self.TransmitFrec = header['TransmitFrec'][0]
334 self.ReceiveFrec = header['ReceiveFrec'][0]
334 self.ReceiveFrec = header['ReceiveFrec'][0]
335 self.FirstOsciFrec = header['FirstOsciFrec'][0]
335 self.FirstOsciFrec = header['FirstOsciFrec'][0]
336 self.Polarisation = header['Polarisation'][0]
336 self.Polarisation = header['Polarisation'][0]
337 self.ReceiverFiltSett = header['ReceiverFiltSett'][0]
337 self.ReceiverFiltSett = header['ReceiverFiltSett'][0]
338 self.nModesInUse = header['nModesInUse'][0]
338 self.nModesInUse = header['nModesInUse'][0]
339 self.DualModeIndex = header['DualModeIndex'][0]
339 self.DualModeIndex = header['DualModeIndex'][0]
340 self.DualModeRange = header['DualModeRange'][0]
340 self.DualModeRange = header['DualModeRange'][0]
341 self.nDigChannels = header['nDigChannels'][0]
341 self.nDigChannels = header['nDigChannels'][0]
342 self.SampResolution = header['SampResolution'][0]
342 self.SampResolution = header['SampResolution'][0]
343 self.nHeights = header['nHeights'][0]
343 self.nHeights = header['nHeights'][0]
344 self.StartRangeSamp = header['StartRangeSamp'][0]
344 self.StartRangeSamp = header['StartRangeSamp'][0]
345 self.PRFhz = header['PRFhz'][0]
345 self.PRFhz = header['PRFhz'][0]
346 self.nCohInt = header['nCohInt'][0]
346 self.nCohInt = header['nCohInt'][0]
347 self.nProfiles = header['nProfiles'][0]
347 self.nProfiles = header['nProfiles'][0]
348 self.nChannels = header['nChannels'][0]
348 self.nChannels = header['nChannels'][0]
349 self.nIncohInt = header['nIncohInt'][0]
349 self.nIncohInt = header['nIncohInt'][0]
350 self.FFTwindowingInd = header['FFTwindowingInd'][0]
350 self.FFTwindowingInd = header['FFTwindowingInd'][0]
351 self.BeamAngleAzim = header['BeamAngleAzim'][0]
351 self.BeamAngleAzim = header['BeamAngleAzim'][0]
352 self.BeamAngleZen = header['BeamAngleZen'][0]
352 self.BeamAngleZen = header['BeamAngleZen'][0]
353 self.AntennaCoord0 = header['AntennaCoord0'][0]
353 self.AntennaCoord0 = header['AntennaCoord0'][0]
354 self.AntennaAngl0 = header['AntennaAngl0'][0]
354 self.AntennaAngl0 = header['AntennaAngl0'][0]
355 self.AntennaCoord1 = header['AntennaCoord1'][0]
355 self.AntennaCoord1 = header['AntennaCoord1'][0]
356 self.AntennaAngl1 = header['AntennaAngl1'][0]
356 self.AntennaAngl1 = header['AntennaAngl1'][0]
357 self.AntennaCoord2 = header['AntennaCoord2'][0]
357 self.AntennaCoord2 = header['AntennaCoord2'][0]
358 self.AntennaAngl2 = header['AntennaAngl2'][0]
358 self.AntennaAngl2 = header['AntennaAngl2'][0]
359 self.RecPhaseCalibr0 = header['RecPhaseCalibr0'][0]
359 self.RecPhaseCalibr0 = header['RecPhaseCalibr0'][0]
360 self.RecPhaseCalibr1 = header['RecPhaseCalibr1'][0]
360 self.RecPhaseCalibr1 = header['RecPhaseCalibr1'][0]
361 self.RecPhaseCalibr2 = header['RecPhaseCalibr2'][0]
361 self.RecPhaseCalibr2 = header['RecPhaseCalibr2'][0]
362 self.RecAmpCalibr0 = header['RecAmpCalibr0'][0]
362 self.RecAmpCalibr0 = header['RecAmpCalibr0'][0]
363 self.RecAmpCalibr1 = header['RecAmpCalibr1'][0]
363 self.RecAmpCalibr1 = header['RecAmpCalibr1'][0]
364 self.RecAmpCalibr2 = header['RecAmpCalibr2'][0]
364 self.RecAmpCalibr2 = header['RecAmpCalibr2'][0]
365 self.ReceiverGaindB0 = header['ReceiverGaindB0'][0]
365 self.ReceiverGaindB0 = header['ReceiverGaindB0'][0]
366 self.ReceiverGaindB1 = header['ReceiverGaindB1'][0]
366 self.ReceiverGaindB1 = header['ReceiverGaindB1'][0]
367 self.ReceiverGaindB2 = header['ReceiverGaindB2'][0]
367 self.ReceiverGaindB2 = header['ReceiverGaindB2'][0]
368
368
369 self.ipp= 0.5*(SPEED_OF_LIGHT/self.PRFhz)
369 self.ipp= 0.5*(SPEED_OF_LIGHT/self.PRFhz)
370
370
371 self.RHsize = 180+20*self.nChannels
371 self.RHsize = 180+20*self.nChannels
372 self.Datasize= self.nProfiles*self.nChannels*self.nHeights*2*4
372 self.Datasize= self.nProfiles*self.nChannels*self.nHeights*2*4
373 #print 'Datasize',self.Datasize
373 #print 'Datasize',self.Datasize
374 endFp = self.OffsetStartHeader + self.RecCounter*self.Off2StartNxtRec
374 endFp = self.OffsetStartHeader + self.RecCounter*self.Off2StartNxtRec
375
375
376 print '=============================================='
376 print '=============================================='
377 print 'RecMgcNumber ',self.RecMgcNumber
377 print 'RecMgcNumber ',self.RecMgcNumber
378 print 'RecCounter ',self.RecCounter
378 print 'RecCounter ',self.RecCounter
379 print 'Off2StartNxtRec ',self.Off2StartNxtRec
379 print 'Off2StartNxtRec ',self.Off2StartNxtRec
380 print 'Off2StartData ',self.Off2StartData
380 print 'Off2StartData ',self.Off2StartData
381 print 'Range Resolution ',self.SampResolution
381 print 'Range Resolution ',self.SampResolution
382 print 'First Height ',self.StartRangeSamp
382 print 'First Height ',self.StartRangeSamp
383 print 'PRF (Hz) ',self.PRFhz
383 print 'PRF (Hz) ',self.PRFhz
384 print 'Heights (K) ',self.nHeights
384 print 'Heights (K) ',self.nHeights
385 print 'Channels (N) ',self.nChannels
385 print 'Channels (N) ',self.nChannels
386 print 'Profiles (J) ',self.nProfiles
386 print 'Profiles (J) ',self.nProfiles
387 print 'iCoh ',self.nCohInt
387 print 'iCoh ',self.nCohInt
388 print 'iInCoh ',self.nIncohInt
388 print 'iInCoh ',self.nIncohInt
389 print 'BeamAngleAzim ',self.BeamAngleAzim
389 print 'BeamAngleAzim ',self.BeamAngleAzim
390 print 'BeamAngleZen ',self.BeamAngleZen
390 print 'BeamAngleZen ',self.BeamAngleZen
391
391
392 #print 'ModoEnUso ',self.DualModeIndex
392 #print 'ModoEnUso ',self.DualModeIndex
393 #print 'UtcTime ',self.nUtime
393 #print 'UtcTime ',self.nUtime
394 #print 'MiliSec ',self.nMilisec
394 #print 'MiliSec ',self.nMilisec
395 #print 'Exp TagName ',self.ExpTagName
395 #print 'Exp TagName ',self.ExpTagName
396 #print 'Exp Comment ',self.ExpComment
396 #print 'Exp Comment ',self.ExpComment
397 #print 'FFT Window Index ',self.FFTwindowingInd
397 #print 'FFT Window Index ',self.FFTwindowingInd
398 #print 'N Dig. Channels ',self.nDigChannels
398 #print 'N Dig. Channels ',self.nDigChannels
399 print 'Size de bloque ',self.RHsize
399 print 'Size de bloque ',self.RHsize
400 print 'DataSize ',self.Datasize
400 print 'DataSize ',self.Datasize
401 print 'BeamAngleAzim ',self.BeamAngleAzim
401 print 'BeamAngleAzim ',self.BeamAngleAzim
402 #print 'AntennaCoord0 ',self.AntennaCoord0
402 #print 'AntennaCoord0 ',self.AntennaCoord0
403 #print 'AntennaAngl0 ',self.AntennaAngl0
403 #print 'AntennaAngl0 ',self.AntennaAngl0
404 #print 'AntennaCoord1 ',self.AntennaCoord1
404 #print 'AntennaCoord1 ',self.AntennaCoord1
405 #print 'AntennaAngl1 ',self.AntennaAngl1
405 #print 'AntennaAngl1 ',self.AntennaAngl1
406 #print 'AntennaCoord2 ',self.AntennaCoord2
406 #print 'AntennaCoord2 ',self.AntennaCoord2
407 #print 'AntennaAngl2 ',self.AntennaAngl2
407 #print 'AntennaAngl2 ',self.AntennaAngl2
408 print 'RecPhaseCalibr0 ',self.RecPhaseCalibr0
408 print 'RecPhaseCalibr0 ',self.RecPhaseCalibr0
409 print 'RecPhaseCalibr1 ',self.RecPhaseCalibr1
409 print 'RecPhaseCalibr1 ',self.RecPhaseCalibr1
410 print 'RecPhaseCalibr2 ',self.RecPhaseCalibr2
410 print 'RecPhaseCalibr2 ',self.RecPhaseCalibr2
411 print 'RecAmpCalibr0 ',self.RecAmpCalibr0
411 print 'RecAmpCalibr0 ',self.RecAmpCalibr0
412 print 'RecAmpCalibr1 ',self.RecAmpCalibr1
412 print 'RecAmpCalibr1 ',self.RecAmpCalibr1
413 print 'RecAmpCalibr2 ',self.RecAmpCalibr2
413 print 'RecAmpCalibr2 ',self.RecAmpCalibr2
414 print 'ReceiverGaindB0 ',self.ReceiverGaindB0
414 print 'ReceiverGaindB0 ',self.ReceiverGaindB0
415 print 'ReceiverGaindB1 ',self.ReceiverGaindB1
415 print 'ReceiverGaindB1 ',self.ReceiverGaindB1
416 print 'ReceiverGaindB2 ',self.ReceiverGaindB2
416 print 'ReceiverGaindB2 ',self.ReceiverGaindB2
417 print '=============================================='
417 print '=============================================='
418
418
419 if OffRHeader > endFp:
419 if OffRHeader > endFp:
420 sys.stderr.write("Warning %s: Size value read from System Header is lower than it has to be\n" %fp)
420 sys.stderr.write("Warning %s: Size value read from System Header is lower than it has to be\n" %fp)
421 return 0
421 return 0
422
422
423 if OffRHeader < endFp:
423 if OffRHeader < endFp:
424 sys.stderr.write("Warning %s: Size value read from System Header size is greater than it has to be\n" %fp)
424 sys.stderr.write("Warning %s: Size value read from System Header size is greater than it has to be\n" %fp)
425 return 0
425 return 0
426
426
427 return 1
427 return 1
428
428
429
429
430 class BLTRReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODataReader):
430 class BLTRReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODataReader):
431
431
432 path = None
432 path = None
433 startDate = None
433 startDate = None
434 endDate = None
434 endDate = None
435 startTime = None
435 startTime = None
436 endTime = None
436 endTime = None
437 walk = None
437 walk = None
438 isConfig = False
438 isConfig = False
439
439
440
440
441 fileList= None
441 fileList= None
442
442
443 #metadata
443 #metadata
444 TimeZone= None
444 TimeZone= None
445 Interval= None
445 Interval= None
446 heightList= None
446 heightList= None
447
447
448 #data
448 #data
449 data= None
449 data= None
450 utctime= None
450 utctime= None
451
451
452
452
453
453
454 def __init__(self, **kwargs):
454 def __init__(self, **kwargs):
455
455
456 #Eliminar de la base la herencia
456 #Eliminar de la base la herencia
457 ProcessingUnit.__init__(self, **kwargs)
457 ProcessingUnit.__init__(self, **kwargs)
458
458
459 # self.isConfig = False
459 # self.isConfig = False
460
460
461 #self.pts2read_SelfSpectra = 0
461 #self.pts2read_SelfSpectra = 0
462 #self.pts2read_CrossSpectra = 0
462 #self.pts2read_CrossSpectra = 0
463 #self.pts2read_DCchannels = 0
463 #self.pts2read_DCchannels = 0
464 #self.datablock = None
464 #self.datablock = None
465 self.utc = None
465 self.utc = None
466 self.ext = ".fdt"
466 self.ext = ".fdt"
467 self.optchar = "P"
467 self.optchar = "P"
468 self.fpFile=None
468 self.fpFile=None
469 self.fp = None
469 self.fp = None
470 self.BlockCounter=0
470 self.BlockCounter=0
471 self.dtype = None
471 self.dtype = None
472 self.fileSizeByHeader = None
472 self.fileSizeByHeader = None
473 self.filenameList = []
473 self.filenameList = []
474 self.fileSelector = 0
474 self.fileSelector = 0
475 self.Off2StartNxtRec=0
475 self.Off2StartNxtRec=0
476 self.RecCounter=0
476 self.RecCounter=0
477 self.flagNoMoreFiles = 0
477 self.flagNoMoreFiles = 0
478 self.data_spc=None
478 self.data_spc=None
479 self.data_cspc=None
479 self.data_cspc=None
480 self.data_output=None
480 self.data_output=None
481 self.path = None
481 self.path = None
482 self.OffsetStartHeader=0
482 self.OffsetStartHeader=0
483 self.Off2StartData=0
483 self.Off2StartData=0
484 self.ipp = 0
484 self.ipp = 0
485 self.nFDTdataRecors=0
485 self.nFDTdataRecors=0
486 self.blocksize = 0
486 self.blocksize = 0
487 self.dataOut = Spectra()
487 self.dataOut = Spectra()
488 self.profileIndex = 1 #Always
488 self.profileIndex = 1 #Always
489 self.dataOut.flagNoData=False
489 self.dataOut.flagNoData=False
490 self.dataOut.nRdPairs = 0
490 self.dataOut.nRdPairs = 0
491 self.dataOut.pairsList = []
491 self.dataOut.pairsList = []
492 self.dataOut.data_spc=None
492 self.dataOut.data_spc=None
493 self.dataOut.noise=[]
493 self.dataOut.noise=[]
494 self.dataOut.velocityX=[]
494 self.dataOut.velocityX=[]
495 self.dataOut.velocityY=[]
495 self.dataOut.velocityY=[]
496 self.dataOut.velocityV=[]
496 self.dataOut.velocityV=[]
497
497
498
498
499
499
500 def Files2Read(self, fp):
500 def Files2Read(self, fp):
501 '''
501 '''
502 Function that indicates the number of .fdt files that exist in the folder to be read.
502 Function that indicates the number of .fdt files that exist in the folder to be read.
503 It also creates an organized list with the names of the files to read.
503 It also creates an organized list with the names of the files to read.
504 '''
504 '''
505 #self.__checkPath()
505 #self.__checkPath()
506
506
507 ListaData=os.listdir(fp) #Gets the list of files within the fp address
507 ListaData=os.listdir(fp) #Gets the list of files within the fp address
508 ListaData=sorted(ListaData) #Sort the list of files from least to largest by names
508 ListaData=sorted(ListaData) #Sort the list of files from least to largest by names
509 nFiles=0 #File Counter
509 nFiles=0 #File Counter
510 FileList=[] #A list is created that will contain the .fdt files
510 FileList=[] #A list is created that will contain the .fdt files
511 for IndexFile in ListaData :
511 for IndexFile in ListaData :
512 if '.fdt' in IndexFile:
512 if '.fdt' in IndexFile:
513 FileList.append(IndexFile)
513 FileList.append(IndexFile)
514 nFiles+=1
514 nFiles+=1
515
515
516 #print 'Files2Read'
516 #print 'Files2Read'
517 #print 'Existen '+str(nFiles)+' archivos .fdt'
517 #print 'Existen '+str(nFiles)+' archivos .fdt'
518
518
519 self.filenameList=FileList #List of files from least to largest by names
519 self.filenameList=FileList #List of files from least to largest by names
520
520
521
521
522 def run(self, **kwargs):
522 def run(self, **kwargs):
523 '''
523 '''
524 This method will be the one that will initiate the data entry, will be called constantly.
524 This method will be the one that will initiate the data entry, will be called constantly.
525 You should first verify that your Setup () is set up and then continue to acquire
525 You should first verify that your Setup () is set up and then continue to acquire
526 the data to be processed with getData ().
526 the data to be processed with getData ().
527 '''
527 '''
528 if not self.isConfig:
528 if not self.isConfig:
529 self.setup(**kwargs)
529 self.setup(**kwargs)
530 self.isConfig = True
530 self.isConfig = True
531
531
532 self.getData()
532 self.getData()
533 #print 'running'
533 #print 'running'
534
534
535
535
536 def setup(self, path=None,
536 def setup(self, path=None,
537 startDate=None,
537 startDate=None,
538 endDate=None,
538 endDate=None,
539 startTime=None,
539 startTime=None,
540 endTime=None,
540 endTime=None,
541 walk=True,
541 walk=True,
542 timezone='utc',
542 timezone='utc',
543 code = None,
543 code = None,
544 online=False,
544 online=False,
545 ReadMode=None,
545 ReadMode=None,
546 **kwargs):
546 **kwargs):
547
547
548 self.isConfig = True
548 self.isConfig = True
549
549
550 self.path=path
550 self.path=path
551 self.startDate=startDate
551 self.startDate=startDate
552 self.endDate=endDate
552 self.endDate=endDate
553 self.startTime=startTime
553 self.startTime=startTime
554 self.endTime=endTime
554 self.endTime=endTime
555 self.walk=walk
555 self.walk=walk
556 self.ReadMode=int(ReadMode)
556 self.ReadMode=int(ReadMode)
557
557
558 pass
558 pass
559
559
560
560
561 def getData(self):
561 def getData(self):
562 '''
562 '''
563 Before starting this function, you should check that there is still an unread file,
563 Before starting this function, you should check that there is still an unread file,
564 If there are still blocks to read or if the data block is empty.
564 If there are still blocks to read or if the data block is empty.
565
565
566 You should call the file "read".
566 You should call the file "read".
567
567
568 '''
568 '''
569
569
570 if self.flagNoMoreFiles:
570 if self.flagNoMoreFiles:
571 self.dataOut.flagNoData = True
571 self.dataOut.flagNoData = True
572 print 'NoData se vuelve true'
572 print 'NoData se vuelve true'
573 return 0
573 return 0
574
574
575 self.fp=self.path
575 self.fp=self.path
576 self.Files2Read(self.fp)
576 self.Files2Read(self.fp)
577 self.readFile(self.fp)
577 self.readFile(self.fp)
578 self.dataOut.data_spc = self.data_spc
578 self.dataOut.data_spc = self.data_spc
579 self.dataOut.data_cspc =self.data_cspc
579 self.dataOut.data_cspc =self.data_cspc
580 self.dataOut.data_output=self.data_output
580 self.dataOut.data_output=self.data_output
581
581
582 print 'self.dataOut.data_output', shape(self.dataOut.data_output)
582 print 'self.dataOut.data_output', shape(self.dataOut.data_output)
583
583
584 #self.removeDC()
584 #self.removeDC()
585 return self.dataOut.data_spc
585 return self.dataOut.data_spc
586
586
587
587
588 def readFile(self,fp):
588 def readFile(self,fp):
589 '''
589 '''
590 You must indicate if you are reading in Online or Offline mode and load the
590 You must indicate if you are reading in Online or Offline mode and load the
591 The parameters for this file reading mode.
591 The parameters for this file reading mode.
592
592
593 Then you must do 2 actions:
593 Then you must do 2 actions:
594
594
595 1. Get the BLTR FileHeader.
595 1. Get the BLTR FileHeader.
596 2. Start reading the first block.
596 2. Start reading the first block.
597 '''
597 '''
598
598
599 #The address of the folder is generated the name of the .fdt file that will be read
599 #The address of the folder is generated the name of the .fdt file that will be read
600 print "File: ",self.fileSelector+1
600 print "File: ",self.fileSelector+1
601
601
602 if self.fileSelector < len(self.filenameList):
602 if self.fileSelector < len(self.filenameList):
603
603
604 self.fpFile=str(fp)+'/'+str(self.filenameList[self.fileSelector])
604 self.fpFile=str(fp)+'/'+str(self.filenameList[self.fileSelector])
605 #print self.fpFile
605 #print self.fpFile
606 fheader = FileHeaderBLTR()
606 fheader = FileHeaderBLTR()
607 fheader.FHread(self.fpFile) #Bltr FileHeader Reading
607 fheader.FHread(self.fpFile) #Bltr FileHeader Reading
608 self.nFDTdataRecors=fheader.nFDTdataRecors
608 self.nFDTdataRecors=fheader.nFDTdataRecors
609
609
610 self.readBlock() #Block reading
610 self.readBlock() #Block reading
611 else:
611 else:
612 print 'readFile FlagNoData becomes true'
612 print 'readFile FlagNoData becomes true'
613 self.flagNoMoreFiles=True
613 self.flagNoMoreFiles=True
614 self.dataOut.flagNoData = True
614 self.dataOut.flagNoData = True
615 return 0
615 return 0
616
616
617 def getVelRange(self, extrapoints=0):
617 def getVelRange(self, extrapoints=0):
618 Lambda= SPEED_OF_LIGHT/50000000
618 Lambda= SPEED_OF_LIGHT/50000000
619 PRF = self.dataOut.PRF#1./(self.dataOut.ippSeconds * self.dataOut.nCohInt)
619 PRF = self.dataOut.PRF#1./(self.dataOut.ippSeconds * self.dataOut.nCohInt)
620 Vmax=-Lambda/(4.*(1./PRF)*self.dataOut.nCohInt*2.)
620 Vmax=-Lambda/(4.*(1./PRF)*self.dataOut.nCohInt*2.)
621 deltafreq = PRF / (self.nProfiles)
621 deltafreq = PRF / (self.nProfiles)
622 deltavel = (Vmax*2) / (self.nProfiles)
622 deltavel = (Vmax*2) / (self.nProfiles)
623 freqrange = deltafreq*(numpy.arange(self.nProfiles)-self.nProfiles/2.) - deltafreq/2
623 freqrange = deltafreq*(numpy.arange(self.nProfiles)-self.nProfiles/2.) - deltafreq/2
624 velrange = deltavel*(numpy.arange(self.nProfiles)-self.nProfiles/2.)
624 velrange = deltavel*(numpy.arange(self.nProfiles)-self.nProfiles/2.)
625 return velrange
625 return velrange
626
626
627 def readBlock(self):
627 def readBlock(self):
628 '''
628 '''
629 It should be checked if the block has data, if it is not passed to the next file.
629 It should be checked if the block has data, if it is not passed to the next file.
630
630
631 Then the following is done:
631 Then the following is done:
632
632
633 1. Read the RecordHeader
633 1. Read the RecordHeader
634 2. Fill the buffer with the current block number.
634 2. Fill the buffer with the current block number.
635
635
636 '''
636 '''
637
637
638 if self.BlockCounter < self.nFDTdataRecors-2:
638 if self.BlockCounter < self.nFDTdataRecors-2:
639 print self.nFDTdataRecors, 'CONDICION!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
639 print self.nFDTdataRecors, 'CONDICION!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
640 if self.ReadMode==1:
640 if self.ReadMode==1:
641 rheader = RecordHeaderBLTR(RecCounter=self.BlockCounter+1)
641 rheader = RecordHeaderBLTR(RecCounter=self.BlockCounter+1)
642 elif self.ReadMode==0:
642 elif self.ReadMode==0:
643 rheader = RecordHeaderBLTR(RecCounter=self.BlockCounter)
643 rheader = RecordHeaderBLTR(RecCounter=self.BlockCounter)
644
644
645 rheader.RHread(self.fpFile) #Bltr FileHeader Reading
645 rheader.RHread(self.fpFile) #Bltr FileHeader Reading
646
646
647 self.OffsetStartHeader=rheader.OffsetStartHeader
647 self.OffsetStartHeader=rheader.OffsetStartHeader
648 self.RecCounter=rheader.RecCounter
648 self.RecCounter=rheader.RecCounter
649 self.Off2StartNxtRec=rheader.Off2StartNxtRec
649 self.Off2StartNxtRec=rheader.Off2StartNxtRec
650 self.Off2StartData=rheader.Off2StartData
650 self.Off2StartData=rheader.Off2StartData
651 self.nProfiles=rheader.nProfiles
651 self.nProfiles=rheader.nProfiles
652 self.nChannels=rheader.nChannels
652 self.nChannels=rheader.nChannels
653 self.nHeights=rheader.nHeights
653 self.nHeights=rheader.nHeights
654 self.frequency=rheader.TransmitFrec
654 self.frequency=rheader.TransmitFrec
655 self.DualModeIndex=rheader.DualModeIndex
655 self.DualModeIndex=rheader.DualModeIndex
656
656
657 self.pairsList =[(0,1),(0,2),(1,2)]
657 self.pairsList =[(0,1),(0,2),(1,2)]
658 self.dataOut.pairsList = self.pairsList
658 self.dataOut.pairsList = self.pairsList
659
659
660 self.nRdPairs=len(self.dataOut.pairsList)
660 self.nRdPairs=len(self.dataOut.pairsList)
661 self.dataOut.nRdPairs = self.nRdPairs
661 self.dataOut.nRdPairs = self.nRdPairs
662
662
663 self.__firstHeigth=rheader.StartRangeSamp
663 self.__firstHeigth=rheader.StartRangeSamp
664 self.__deltaHeigth=rheader.SampResolution
664 self.__deltaHeigth=rheader.SampResolution
665 self.dataOut.heightList= self.__firstHeigth + numpy.array(range(self.nHeights))*self.__deltaHeigth
665 self.dataOut.heightList= self.__firstHeigth + numpy.array(range(self.nHeights))*self.__deltaHeigth
666 self.dataOut.channelList = range(self.nChannels)
666 self.dataOut.channelList = range(self.nChannels)
667 self.dataOut.nProfiles=rheader.nProfiles
667 self.dataOut.nProfiles=rheader.nProfiles
668 self.dataOut.nIncohInt=rheader.nIncohInt
668 self.dataOut.nIncohInt=rheader.nIncohInt
669 self.dataOut.nCohInt=rheader.nCohInt
669 self.dataOut.nCohInt=rheader.nCohInt
670 self.dataOut.ippSeconds= 1/float(rheader.PRFhz)
670 self.dataOut.ippSeconds= 1/float(rheader.PRFhz)
671 self.dataOut.PRF=rheader.PRFhz
671 self.dataOut.PRF=rheader.PRFhz
672 self.dataOut.nFFTPoints=rheader.nProfiles
672 self.dataOut.nFFTPoints=rheader.nProfiles
673 self.dataOut.utctime=rheader.nUtime
673 self.dataOut.utctime=rheader.nUtime
674 self.dataOut.timeZone=0
674 self.dataOut.timeZone=0
675 self.dataOut.normFactor= self.dataOut.nProfiles*self.dataOut.nIncohInt*self.dataOut.nCohInt
675 self.dataOut.normFactor= self.dataOut.nProfiles*self.dataOut.nIncohInt*self.dataOut.nCohInt
676 self.dataOut.outputInterval= self.dataOut.ippSeconds * self.dataOut.nCohInt * self.dataOut.nIncohInt * self.nProfiles
676 self.dataOut.outputInterval= self.dataOut.ippSeconds * self.dataOut.nCohInt * self.dataOut.nIncohInt * self.nProfiles
677
677
678 self.data_output=numpy.ones([3,rheader.nHeights])*numpy.NaN
678 self.data_output=numpy.ones([3,rheader.nHeights])*numpy.NaN
679 print 'self.data_output', shape(self.data_output)
679 print 'self.data_output', shape(self.data_output)
680 self.dataOut.velocityX=[]
680 self.dataOut.velocityX=[]
681 self.dataOut.velocityY=[]
681 self.dataOut.velocityY=[]
682 self.dataOut.velocityV=[]
682 self.dataOut.velocityV=[]
683
683
684 '''Block Reading, the Block Data is received and Reshape is used to give it
684 '''Block Reading, the Block Data is received and Reshape is used to give it
685 shape.
685 shape.
686 '''
686 '''
687
687
688 #Procedure to take the pointer to where the date block starts
688 #Procedure to take the pointer to where the date block starts
689 startDATA = open(self.fpFile,"rb")
689 startDATA = open(self.fpFile,"rb")
690 OffDATA= self.OffsetStartHeader + self.RecCounter*self.Off2StartNxtRec+self.Off2StartData
690 OffDATA= self.OffsetStartHeader + self.RecCounter*self.Off2StartNxtRec+self.Off2StartData
691 startDATA.seek(OffDATA, os.SEEK_SET)
691 startDATA.seek(OffDATA, os.SEEK_SET)
692
692
693 def moving_average(x, N=2):
693 def moving_average(x, N=2):
694 return numpy.convolve(x, numpy.ones((N,))/N)[(N-1):]
694 return numpy.convolve(x, numpy.ones((N,))/N)[(N-1):]
695
695
696 def gaus(xSamples,a,x0,sigma):
696 def gaus(xSamples,a,x0,sigma):
697 return a*exp(-(xSamples-x0)**2/(2*sigma**2))
697 return a*exp(-(xSamples-x0)**2/(2*sigma**2))
698
698
699 def Find(x,value):
699 def Find(x,value):
700 for index in range(len(x)):
700 for index in range(len(x)):
701 if x[index]==value:
701 if x[index]==value:
702 return index
702 return index
703
703
704 def pol2cart(rho, phi):
704 def pol2cart(rho, phi):
705 x = rho * numpy.cos(phi)
705 x = rho * numpy.cos(phi)
706 y = rho * numpy.sin(phi)
706 y = rho * numpy.sin(phi)
707 return(x, y)
707 return(x, y)
708
708
709
709
710
710
711
711
712 if self.DualModeIndex==self.ReadMode:
712 if self.DualModeIndex==self.ReadMode:
713
713
714 self.data_fft = numpy.fromfile( startDATA, [('complex','<c8')],self.nProfiles*self.nChannels*self.nHeights )
714 self.data_fft = numpy.fromfile( startDATA, [('complex','<c8')],self.nProfiles*self.nChannels*self.nHeights )
715
715
716 self.data_fft=self.data_fft.astype(numpy.dtype('complex'))
716 self.data_fft=self.data_fft.astype(numpy.dtype('complex'))
717
717
718 self.data_block=numpy.reshape(self.data_fft,(self.nHeights, self.nChannels, self.nProfiles ))
718 self.data_block=numpy.reshape(self.data_fft,(self.nHeights, self.nChannels, self.nProfiles ))
719
719
720 self.data_block = numpy.transpose(self.data_block, (1,2,0))
720 self.data_block = numpy.transpose(self.data_block, (1,2,0))
721
721
722 copy = self.data_block.copy()
722 copy = self.data_block.copy()
723 spc = copy * numpy.conjugate(copy)
723 spc = copy * numpy.conjugate(copy)
724
724
725 self.data_spc = numpy.absolute(spc) # valor absoluto o magnitud
725 self.data_spc = numpy.absolute(spc) # valor absoluto o magnitud
726
726
727 factor = self.dataOut.normFactor
727 factor = self.dataOut.normFactor
728
728
729
729
730 z = self.data_spc.copy()#/factor
730 z = self.data_spc.copy()#/factor
731 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
731 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
732 #zdB = 10*numpy.log10(z)
732 #zdB = 10*numpy.log10(z)
733 print ' '
733 print ' '
734 print 'Z: '
734 print 'Z: '
735 print shape(z)
735 print shape(z)
736 print ' '
736 print ' '
737 print ' '
737 print ' '
738
738
739 self.dataOut.data_spc=self.data_spc
739 self.dataOut.data_spc=self.data_spc
740
740
741 self.noise = self.dataOut.getNoise(ymin_index=80, ymax_index=132)#/factor
741 self.noise = self.dataOut.getNoise(ymin_index=80, ymax_index=132)#/factor
742 #noisedB = 10*numpy.log10(self.noise)
742 #noisedB = 10*numpy.log10(self.noise)
743
743
744
744
745 ySamples=numpy.ones([3,self.nProfiles])
745 ySamples=numpy.ones([3,self.nProfiles])
746 phase=numpy.ones([3,self.nProfiles])
746 phase=numpy.ones([3,self.nProfiles])
747 CSPCSamples=numpy.ones([3,self.nProfiles],dtype=numpy.complex_)
747 CSPCSamples=numpy.ones([3,self.nProfiles],dtype=numpy.complex_)
748 coherence=numpy.ones([3,self.nProfiles])
748 coherence=numpy.ones([3,self.nProfiles])
749 PhaseSlope=numpy.ones(3)
749 PhaseSlope=numpy.ones(3)
750 PhaseInter=numpy.ones(3)
750 PhaseInter=numpy.ones(3)
751
751
752 '''****** Getting CrossSpectra ******'''
752 '''****** Getting CrossSpectra ******'''
753 cspc=self.data_block.copy()
753 cspc=self.data_block.copy()
754 self.data_cspc=self.data_block.copy()
754 self.data_cspc=self.data_block.copy()
755
755
756 xFrec=self.getVelRange(1)
756 xFrec=self.getVelRange(1)
757 VelRange=self.getVelRange(1)
757 VelRange=self.getVelRange(1)
758 self.dataOut.VelRange=VelRange
758 self.dataOut.VelRange=VelRange
759 #print ' '
759 #print ' '
760 #print ' '
760 #print ' '
761 #print 'xFrec',xFrec
761 #print 'xFrec',xFrec
762 #print ' '
762 #print ' '
763 #print ' '
763 #print ' '
764 #Height=35
764 #Height=35
765
765 for i in range(self.nRdPairs):
766 for i in range(self.nRdPairs):
766
767
767 chan_index0 = self.dataOut.pairsList[i][0]
768 chan_index0 = self.dataOut.pairsList[i][0]
768 chan_index1 = self.dataOut.pairsList[i][1]
769 chan_index1 = self.dataOut.pairsList[i][1]
769
770
770 self.data_cspc[i,:,:]=cspc[chan_index0,:,:] * numpy.conjugate(cspc[chan_index1,:,:])
771 self.data_cspc[i,:,:]=cspc[chan_index0,:,:] * numpy.conjugate(cspc[chan_index1,:,:])
771
772
772
773
773 '''Getting Eij and Nij'''
774 '''Getting Eij and Nij'''
774 (AntennaX0,AntennaY0)=pol2cart(rheader.AntennaCoord0, rheader.AntennaAngl0*numpy.pi/180)
775 (AntennaX0,AntennaY0)=pol2cart(rheader.AntennaCoord0, rheader.AntennaAngl0*numpy.pi/180)
775 (AntennaX1,AntennaY1)=pol2cart(rheader.AntennaCoord1, rheader.AntennaAngl1*numpy.pi/180)
776 (AntennaX1,AntennaY1)=pol2cart(rheader.AntennaCoord1, rheader.AntennaAngl1*numpy.pi/180)
776 (AntennaX2,AntennaY2)=pol2cart(rheader.AntennaCoord2, rheader.AntennaAngl2*numpy.pi/180)
777 (AntennaX2,AntennaY2)=pol2cart(rheader.AntennaCoord2, rheader.AntennaAngl2*numpy.pi/180)
777
778
778 E01=AntennaX0-AntennaX1
779 E01=AntennaX0-AntennaX1
779 N01=AntennaY0-AntennaY1
780 N01=AntennaY0-AntennaY1
780
781
781 E02=AntennaX0-AntennaX2
782 E02=AntennaX0-AntennaX2
782 N02=AntennaY0-AntennaY2
783 N02=AntennaY0-AntennaY2
783
784
784 E12=AntennaX1-AntennaX2
785 E12=AntennaX1-AntennaX2
785 N12=AntennaY1-AntennaY2
786 N12=AntennaY1-AntennaY2
786
787
787 self.ChanDist= numpy.array([[E01, N01],[E02,N02],[E12,N12]])
788 self.ChanDist= numpy.array([[E01, N01],[E02,N02],[E12,N12]])
788
789
789 self.dataOut.ChanDist = self.ChanDist
790 self.dataOut.ChanDist = self.ChanDist
790
791
791
792
792 # for Height in range(self.nHeights):
793 # for Height in range(self.nHeights):
793 #
794 #
794 # for i in range(self.nRdPairs):
795 # for i in range(self.nRdPairs):
795 #
796 #
796 # '''****** Line of Data SPC ******'''
797 # '''****** Line of Data SPC ******'''
797 # zline=z[i,:,Height]
798 # zline=z[i,:,Height]
798 #
799 #
799 # '''****** DC is removed ******'''
800 # '''****** DC is removed ******'''
800 # DC=Find(zline,numpy.amax(zline))
801 # DC=Find(zline,numpy.amax(zline))
801 # zline[DC]=(zline[DC-1]+zline[DC+1])/2
802 # zline[DC]=(zline[DC-1]+zline[DC+1])/2
802 #
803 #
803 #
804 #
804 # '''****** SPC is normalized ******'''
805 # '''****** SPC is normalized ******'''
805 # FactNorm= zline.copy() / numpy.sum(zline.copy())
806 # FactNorm= zline.copy() / numpy.sum(zline.copy())
806 # FactNorm= FactNorm/numpy.sum(FactNorm)
807 # FactNorm= FactNorm/numpy.sum(FactNorm)
807 #
808 #
808 # SmoothSPC=moving_average(FactNorm,N=3)
809 # SmoothSPC=moving_average(FactNorm,N=3)
809 #
810 #
810 # xSamples = ar(range(len(SmoothSPC)))
811 # xSamples = ar(range(len(SmoothSPC)))
811 # ySamples[i] = SmoothSPC-self.noise[i]
812 # ySamples[i] = SmoothSPC-self.noise[i]
812 #
813 #
813 # for i in range(self.nRdPairs):
814 # for i in range(self.nRdPairs):
814 #
815 #
815 # '''****** Line of Data CSPC ******'''
816 # '''****** Line of Data CSPC ******'''
816 # cspcLine=self.data_cspc[i,:,Height].copy()
817 # cspcLine=self.data_cspc[i,:,Height].copy()
817 #
818 #
818 #
819 #
819 #
820 #
820 # '''****** CSPC is normalized ******'''
821 # '''****** CSPC is normalized ******'''
821 # chan_index0 = self.dataOut.pairsList[i][0]
822 # chan_index0 = self.dataOut.pairsList[i][0]
822 # chan_index1 = self.dataOut.pairsList[i][1]
823 # chan_index1 = self.dataOut.pairsList[i][1]
823 # CSPCFactor= numpy.sum(ySamples[chan_index0]) * numpy.sum(ySamples[chan_index1])
824 # CSPCFactor= numpy.sum(ySamples[chan_index0]) * numpy.sum(ySamples[chan_index1])
824 #
825 #
825 #
826 #
826 # CSPCNorm= cspcLine.copy() / numpy.sqrt(CSPCFactor)
827 # CSPCNorm= cspcLine.copy() / numpy.sqrt(CSPCFactor)
827 #
828 #
828 #
829 #
829 # CSPCSamples[i] = CSPCNorm-self.noise[i]
830 # CSPCSamples[i] = CSPCNorm-self.noise[i]
830 # coherence[i] = numpy.abs(CSPCSamples[i]) / numpy.sqrt(CSPCFactor)
831 # coherence[i] = numpy.abs(CSPCSamples[i]) / numpy.sqrt(CSPCFactor)
831 #
832 #
832 # '''****** DC is removed ******'''
833 # '''****** DC is removed ******'''
833 # DC=Find(coherence[i],numpy.amax(coherence[i]))
834 # DC=Find(coherence[i],numpy.amax(coherence[i]))
834 # coherence[i][DC]=(coherence[i][DC-1]+coherence[i][DC+1])/2
835 # coherence[i][DC]=(coherence[i][DC-1]+coherence[i][DC+1])/2
835 # coherence[i]= moving_average(coherence[i],N=2)
836 # coherence[i]= moving_average(coherence[i],N=2)
836 #
837 #
837 # phase[i] = moving_average( numpy.arctan2(CSPCSamples[i].imag, CSPCSamples[i].real),N=1)#*180/numpy.pi
838 # phase[i] = moving_average( numpy.arctan2(CSPCSamples[i].imag, CSPCSamples[i].real),N=1)#*180/numpy.pi
838 #
839 #
839 #
840 #
840 # '''****** Getting fij width ******'''
841 # '''****** Getting fij width ******'''
841 #
842 #
842 # yMean=[]
843 # yMean=[]
843 # yMean2=[]
844 # yMean2=[]
844 #
845 #
845 # for j in range(len(ySamples[1])):
846 # for j in range(len(ySamples[1])):
846 # yMean=numpy.append(yMean,numpy.average([ySamples[0,j],ySamples[1,j],ySamples[2,j]]))
847 # yMean=numpy.append(yMean,numpy.average([ySamples[0,j],ySamples[1,j],ySamples[2,j]]))
847 #
848 #
848 # '''******* Getting fitting Gaussian ******'''
849 # '''******* Getting fitting Gaussian ******'''
849 # meanGauss=sum(xSamples*yMean) / len(xSamples)
850 # meanGauss=sum(xSamples*yMean) / len(xSamples)
850 # sigma=sum(yMean*(xSamples-meanGauss)**2) / len(xSamples)
851 # sigma=sum(yMean*(xSamples-meanGauss)**2) / len(xSamples)
851 # #print 'Height',Height,'SNR', meanGauss/sigma**2
852 # #print 'Height',Height,'SNR', meanGauss/sigma**2
852 #
853 #
853 # if (abs(meanGauss/sigma**2) > 0.0001) :
854 # if (abs(meanGauss/sigma**2) > 0.0001) :
854 #
855 #
855 # try:
856 # try:
856 # popt,pcov = curve_fit(gaus,xSamples,yMean,p0=[1,meanGauss,sigma])
857 # popt,pcov = curve_fit(gaus,xSamples,yMean,p0=[1,meanGauss,sigma])
857 #
858 #
858 # if numpy.amax(popt)>numpy.amax(yMean)*0.3:
859 # if numpy.amax(popt)>numpy.amax(yMean)*0.3:
859 # FitGauss=gaus(xSamples,*popt)
860 # FitGauss=gaus(xSamples,*popt)
860 #
861 #
861 # else:
862 # else:
862 # FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
863 # FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
863 # print 'Verificador: Dentro', Height
864 # print 'Verificador: Dentro', Height
864 # except RuntimeError:
865 # except RuntimeError:
865 #
866 #
866 # try:
867 # try:
867 # for j in range(len(ySamples[1])):
868 # for j in range(len(ySamples[1])):
868 # yMean2=numpy.append(yMean2,numpy.average([ySamples[1,j],ySamples[2,j]]))
869 # yMean2=numpy.append(yMean2,numpy.average([ySamples[1,j],ySamples[2,j]]))
869 # popt,pcov = curve_fit(gaus,xSamples,yMean2,p0=[1,meanGauss,sigma])
870 # popt,pcov = curve_fit(gaus,xSamples,yMean2,p0=[1,meanGauss,sigma])
870 # FitGauss=gaus(xSamples,*popt)
871 # FitGauss=gaus(xSamples,*popt)
871 # print 'Verificador: Exepcion1', Height
872 # print 'Verificador: Exepcion1', Height
872 # except RuntimeError:
873 # except RuntimeError:
873 #
874 #
874 # try:
875 # try:
875 # popt,pcov = curve_fit(gaus,xSamples,ySamples[1],p0=[1,meanGauss,sigma])
876 # popt,pcov = curve_fit(gaus,xSamples,ySamples[1],p0=[1,meanGauss,sigma])
876 # FitGauss=gaus(xSamples,*popt)
877 # FitGauss=gaus(xSamples,*popt)
877 # print 'Verificador: Exepcion2', Height
878 # print 'Verificador: Exepcion2', Height
878 # except RuntimeError:
879 # except RuntimeError:
879 # FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
880 # FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
880 # print 'Verificador: Exepcion3', Height
881 # print 'Verificador: Exepcion3', Height
881 # else:
882 # else:
882 # FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
883 # FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
883 # #print 'Verificador: Fuera', Height
884 # #print 'Verificador: Fuera', Height
884 #
885 #
885 #
886 #
886 #
887 #
887 # Maximun=numpy.amax(yMean)
888 # Maximun=numpy.amax(yMean)
888 # eMinus1=Maximun*numpy.exp(-1)
889 # eMinus1=Maximun*numpy.exp(-1)
889 #
890 #
890 # HWpos=Find(FitGauss,min(FitGauss, key=lambda value:abs(value-eMinus1)))
891 # HWpos=Find(FitGauss,min(FitGauss, key=lambda value:abs(value-eMinus1)))
891 # HalfWidth= xFrec[HWpos]
892 # HalfWidth= xFrec[HWpos]
892 # GCpos=Find(FitGauss, numpy.amax(FitGauss))
893 # GCpos=Find(FitGauss, numpy.amax(FitGauss))
893 # Vpos=Find(FactNorm, numpy.amax(FactNorm))
894 # Vpos=Find(FactNorm, numpy.amax(FactNorm))
894 # #Vpos=numpy.sum(FactNorm)/len(FactNorm)
895 # #Vpos=numpy.sum(FactNorm)/len(FactNorm)
895 # #Vpos=Find(FactNorm, min(FactNorm, key=lambda value:abs(value- numpy.mean(FactNorm) )))
896 # #Vpos=Find(FactNorm, min(FactNorm, key=lambda value:abs(value- numpy.mean(FactNorm) )))
896 # #print 'GCpos',GCpos, numpy.amax(FitGauss), 'HWpos',HWpos
897 # #print 'GCpos',GCpos, numpy.amax(FitGauss), 'HWpos',HWpos
897 # '''****** Getting Fij ******'''
898 # '''****** Getting Fij ******'''
898 #
899 #
899 # GaussCenter=xFrec[GCpos]
900 # GaussCenter=xFrec[GCpos]
900 # if (GaussCenter<0 and HalfWidth>0) or (GaussCenter>0 and HalfWidth<0):
901 # if (GaussCenter<0 and HalfWidth>0) or (GaussCenter>0 and HalfWidth<0):
901 # Fij=abs(GaussCenter)+abs(HalfWidth)+0.0000001
902 # Fij=abs(GaussCenter)+abs(HalfWidth)+0.0000001
902 # else:
903 # else:
903 # Fij=abs(GaussCenter-HalfWidth)+0.0000001
904 # Fij=abs(GaussCenter-HalfWidth)+0.0000001
904 #
905 #
905 # '''****** Getting Frecuency range of significant data ******'''
906 # '''****** Getting Frecuency range of significant data ******'''
906 #
907 #
907 # Rangpos=Find(FitGauss,min(FitGauss, key=lambda value:abs(value-Maximun*0.10)))
908 # Rangpos=Find(FitGauss,min(FitGauss, key=lambda value:abs(value-Maximun*0.10)))
908 #
909 #
909 # if Rangpos<GCpos:
910 # if Rangpos<GCpos:
910 # Range=numpy.array([Rangpos,2*GCpos-Rangpos])
911 # Range=numpy.array([Rangpos,2*GCpos-Rangpos])
911 # else:
912 # else:
912 # Range=numpy.array([2*GCpos-Rangpos,Rangpos])
913 # Range=numpy.array([2*GCpos-Rangpos,Rangpos])
913 #
914 #
914 # FrecRange=xFrec[Range[0]:Range[1]]
915 # FrecRange=xFrec[Range[0]:Range[1]]
915 #
916 #
916 # #print 'FrecRange', FrecRange
917 # #print 'FrecRange', FrecRange
917 # '''****** Getting SCPC Slope ******'''
918 # '''****** Getting SCPC Slope ******'''
918 #
919 #
919 # for i in range(self.nRdPairs):
920 # for i in range(self.nRdPairs):
920 #
921 #
921 # if len(FrecRange)>5 and len(FrecRange)<self.nProfiles*0.5:
922 # if len(FrecRange)>5 and len(FrecRange)<self.nProfiles*0.5:
922 # PhaseRange=moving_average(phase[i,Range[0]:Range[1]],N=3)
923 # PhaseRange=moving_average(phase[i,Range[0]:Range[1]],N=3)
923 #
924 #
924 # slope, intercept, r_value, p_value, std_err = stats.linregress(FrecRange,PhaseRange)
925 # slope, intercept, r_value, p_value, std_err = stats.linregress(FrecRange,PhaseRange)
925 # PhaseSlope[i]=slope
926 # PhaseSlope[i]=slope
926 # PhaseInter[i]=intercept
927 # PhaseInter[i]=intercept
927 # else:
928 # else:
928 # PhaseSlope[i]=0
929 # PhaseSlope[i]=0
929 # PhaseInter[i]=0
930 # PhaseInter[i]=0
930 #
931 #
931 # # plt.figure(i+15)
932 # # plt.figure(i+15)
932 # # plt.title('FASE ( CH%s*CH%s )' %(self.dataOut.pairsList[i][0],self.dataOut.pairsList[i][1]))
933 # # plt.title('FASE ( CH%s*CH%s )' %(self.dataOut.pairsList[i][0],self.dataOut.pairsList[i][1]))
933 # # plt.xlabel('Frecuencia (KHz)')
934 # # plt.xlabel('Frecuencia (KHz)')
934 # # plt.ylabel('Magnitud')
935 # # plt.ylabel('Magnitud')
935 # # #plt.subplot(311+i)
936 # # #plt.subplot(311+i)
936 # # plt.plot(FrecRange,PhaseRange,'b')
937 # # plt.plot(FrecRange,PhaseRange,'b')
937 # # plt.plot(FrecRange,FrecRange*PhaseSlope[i]+PhaseInter[i],'r')
938 # # plt.plot(FrecRange,FrecRange*PhaseSlope[i]+PhaseInter[i],'r')
938 #
939 #
939 # #plt.axis([-0.6, 0.2, -3.2, 3.2])
940 # #plt.axis([-0.6, 0.2, -3.2, 3.2])
940 #
941 #
941 #
942 #
942 # '''Getting constant C'''
943 # '''Getting constant C'''
943 # cC=(Fij*numpy.pi)**2
944 # cC=(Fij*numpy.pi)**2
944 #
945 #
945 # # '''Getting Eij and Nij'''
946 # # '''Getting Eij and Nij'''
946 # # (AntennaX0,AntennaY0)=pol2cart(rheader.AntennaCoord0, rheader.AntennaAngl0*numpy.pi/180)
947 # # (AntennaX0,AntennaY0)=pol2cart(rheader.AntennaCoord0, rheader.AntennaAngl0*numpy.pi/180)
947 # # (AntennaX1,AntennaY1)=pol2cart(rheader.AntennaCoord1, rheader.AntennaAngl1*numpy.pi/180)
948 # # (AntennaX1,AntennaY1)=pol2cart(rheader.AntennaCoord1, rheader.AntennaAngl1*numpy.pi/180)
948 # # (AntennaX2,AntennaY2)=pol2cart(rheader.AntennaCoord2, rheader.AntennaAngl2*numpy.pi/180)
949 # # (AntennaX2,AntennaY2)=pol2cart(rheader.AntennaCoord2, rheader.AntennaAngl2*numpy.pi/180)
949 # #
950 # #
950 # # E01=AntennaX0-AntennaX1
951 # # E01=AntennaX0-AntennaX1
951 # # N01=AntennaY0-AntennaY1
952 # # N01=AntennaY0-AntennaY1
952 # #
953 # #
953 # # E02=AntennaX0-AntennaX2
954 # # E02=AntennaX0-AntennaX2
954 # # N02=AntennaY0-AntennaY2
955 # # N02=AntennaY0-AntennaY2
955 # #
956 # #
956 # # E12=AntennaX1-AntennaX2
957 # # E12=AntennaX1-AntennaX2
957 # # N12=AntennaY1-AntennaY2
958 # # N12=AntennaY1-AntennaY2
958 #
959 #
959 # '''****** Getting constants F and G ******'''
960 # '''****** Getting constants F and G ******'''
960 # MijEijNij=numpy.array([[E02,N02], [E12,N12]])
961 # MijEijNij=numpy.array([[E02,N02], [E12,N12]])
961 # MijResult0=(-PhaseSlope[1]*cC) / (2*numpy.pi)
962 # MijResult0=(-PhaseSlope[1]*cC) / (2*numpy.pi)
962 # MijResult1=(-PhaseSlope[2]*cC) / (2*numpy.pi)
963 # MijResult1=(-PhaseSlope[2]*cC) / (2*numpy.pi)
963 # MijResults=numpy.array([MijResult0,MijResult1])
964 # MijResults=numpy.array([MijResult0,MijResult1])
964 # (cF,cG) = numpy.linalg.solve(MijEijNij, MijResults)
965 # (cF,cG) = numpy.linalg.solve(MijEijNij, MijResults)
965 #
966 #
966 # '''****** Getting constants A, B and H ******'''
967 # '''****** Getting constants A, B and H ******'''
967 # W01=numpy.amax(coherence[0])
968 # W01=numpy.amax(coherence[0])
968 # W02=numpy.amax(coherence[1])
969 # W02=numpy.amax(coherence[1])
969 # W12=numpy.amax(coherence[2])
970 # W12=numpy.amax(coherence[2])
970 #
971 #
971 # WijResult0=((cF*E01+cG*N01)**2)/cC - numpy.log(W01 / numpy.sqrt(numpy.pi/cC))
972 # WijResult0=((cF*E01+cG*N01)**2)/cC - numpy.log(W01 / numpy.sqrt(numpy.pi/cC))
972 # WijResult1=((cF*E02+cG*N02)**2)/cC - numpy.log(W02 / numpy.sqrt(numpy.pi/cC))
973 # WijResult1=((cF*E02+cG*N02)**2)/cC - numpy.log(W02 / numpy.sqrt(numpy.pi/cC))
973 # WijResult2=((cF*E12+cG*N12)**2)/cC - numpy.log(W12 / numpy.sqrt(numpy.pi/cC))
974 # WijResult2=((cF*E12+cG*N12)**2)/cC - numpy.log(W12 / numpy.sqrt(numpy.pi/cC))
974 #
975 #
975 # WijResults=numpy.array([WijResult0, WijResult1, WijResult2])
976 # WijResults=numpy.array([WijResult0, WijResult1, WijResult2])
976 #
977 #
977 # WijEijNij=numpy.array([ [E01**2, N01**2, 2*E01*N01] , [E02**2, N02**2, 2*E02*N02] , [E12**2, N12**2, 2*E12*N12] ])
978 # WijEijNij=numpy.array([ [E01**2, N01**2, 2*E01*N01] , [E02**2, N02**2, 2*E02*N02] , [E12**2, N12**2, 2*E12*N12] ])
978 # (cA,cB,cH) = numpy.linalg.solve(WijEijNij, WijResults)
979 # (cA,cB,cH) = numpy.linalg.solve(WijEijNij, WijResults)
979 #
980 #
980 # VxVy=numpy.array([[cA,cH],[cH,cB]])
981 # VxVy=numpy.array([[cA,cH],[cH,cB]])
981 #
982 #
982 # VxVyResults=numpy.array([-cF,-cG])
983 # VxVyResults=numpy.array([-cF,-cG])
983 # (Vx,Vy) = numpy.linalg.solve(VxVy, VxVyResults)
984 # (Vx,Vy) = numpy.linalg.solve(VxVy, VxVyResults)
984 # Vzon = Vy
985 # Vzon = Vy
985 # Vmer = Vx
986 # Vmer = Vx
986 # Vmag=numpy.sqrt(Vzon**2+Vmer**2)
987 # Vmag=numpy.sqrt(Vzon**2+Vmer**2)
987 # Vang=numpy.arctan2(Vmer,Vzon)
988 # Vang=numpy.arctan2(Vmer,Vzon)
988 #
989 #
989 # if abs(Vy)<100 and abs(Vy)> 0.:
990 # if abs(Vy)<100 and abs(Vy)> 0.:
990 # self.dataOut.velocityX=numpy.append(self.dataOut.velocityX, Vzon) #Vmag
991 # self.dataOut.velocityX=numpy.append(self.dataOut.velocityX, Vzon) #Vmag
991 # #print 'Vmag',Vmag
992 # #print 'Vmag',Vmag
992 # else:
993 # else:
993 # self.dataOut.velocityX=numpy.append(self.dataOut.velocityX, NaN)
994 # self.dataOut.velocityX=numpy.append(self.dataOut.velocityX, NaN)
994 #
995 #
995 # if abs(Vx)<100 and abs(Vx) > 0.:
996 # if abs(Vx)<100 and abs(Vx) > 0.:
996 # self.dataOut.velocityY=numpy.append(self.dataOut.velocityY, Vmer) #Vang
997 # self.dataOut.velocityY=numpy.append(self.dataOut.velocityY, Vmer) #Vang
997 # #print 'Vang',Vang
998 # #print 'Vang',Vang
998 # else:
999 # else:
999 # self.dataOut.velocityY=numpy.append(self.dataOut.velocityY, NaN)
1000 # self.dataOut.velocityY=numpy.append(self.dataOut.velocityY, NaN)
1000 #
1001 #
1001 # if abs(GaussCenter)<2:
1002 # if abs(GaussCenter)<2:
1002 # self.dataOut.velocityV=numpy.append(self.dataOut.velocityV, xFrec[Vpos])
1003 # self.dataOut.velocityV=numpy.append(self.dataOut.velocityV, xFrec[Vpos])
1003 #
1004 #
1004 # else:
1005 # else:
1005 # self.dataOut.velocityV=numpy.append(self.dataOut.velocityV, NaN)
1006 # self.dataOut.velocityV=numpy.append(self.dataOut.velocityV, NaN)
1006 #
1007 #
1007 #
1008 #
1008 # # print '********************************************'
1009 # # print '********************************************'
1009 # # print 'HalfWidth ', HalfWidth
1010 # # print 'HalfWidth ', HalfWidth
1010 # # print 'Maximun ', Maximun
1011 # # print 'Maximun ', Maximun
1011 # # print 'eMinus1 ', eMinus1
1012 # # print 'eMinus1 ', eMinus1
1012 # # print 'Rangpos ', Rangpos
1013 # # print 'Rangpos ', Rangpos
1013 # # print 'GaussCenter ',GaussCenter
1014 # # print 'GaussCenter ',GaussCenter
1014 # # print 'E01 ',E01
1015 # # print 'E01 ',E01
1015 # # print 'N01 ',N01
1016 # # print 'N01 ',N01
1016 # # print 'E02 ',E02
1017 # # print 'E02 ',E02
1017 # # print 'N02 ',N02
1018 # # print 'N02 ',N02
1018 # # print 'E12 ',E12
1019 # # print 'E12 ',E12
1019 # # print 'N12 ',N12
1020 # # print 'N12 ',N12
1020 # #print 'self.dataOut.velocityX ', self.dataOut.velocityX
1021 # #print 'self.dataOut.velocityX ', self.dataOut.velocityX
1021 # # print 'Fij ', Fij
1022 # # print 'Fij ', Fij
1022 # # print 'cC ', cC
1023 # # print 'cC ', cC
1023 # # print 'cF ', cF
1024 # # print 'cF ', cF
1024 # # print 'cG ', cG
1025 # # print 'cG ', cG
1025 # # print 'cA ', cA
1026 # # print 'cA ', cA
1026 # # print 'cB ', cB
1027 # # print 'cB ', cB
1027 # # print 'cH ', cH
1028 # # print 'cH ', cH
1028 # # print 'Vx ', Vx
1029 # # print 'Vx ', Vx
1029 # # print 'Vy ', Vy
1030 # # print 'Vy ', Vy
1030 # # print 'Vmag ', Vmag
1031 # # print 'Vmag ', Vmag
1031 # # print 'Vang ', Vang*180/numpy.pi
1032 # # print 'Vang ', Vang*180/numpy.pi
1032 # # print 'PhaseSlope ',PhaseSlope[0]
1033 # # print 'PhaseSlope ',PhaseSlope[0]
1033 # # print 'PhaseSlope ',PhaseSlope[1]
1034 # # print 'PhaseSlope ',PhaseSlope[1]
1034 # # print 'PhaseSlope ',PhaseSlope[2]
1035 # # print 'PhaseSlope ',PhaseSlope[2]
1035 # # print '********************************************'
1036 # # print '********************************************'
1036 # #print 'data_output',shape(self.dataOut.velocityX), shape(self.dataOut.velocityY)
1037 # #print 'data_output',shape(self.dataOut.velocityX), shape(self.dataOut.velocityY)
1037 #
1038 #
1038 # #print 'self.dataOut.velocityX', len(self.dataOut.velocityX)
1039 # #print 'self.dataOut.velocityX', len(self.dataOut.velocityX)
1039 # #print 'self.dataOut.velocityY', len(self.dataOut.velocityY)
1040 # #print 'self.dataOut.velocityY', len(self.dataOut.velocityY)
1040 # #print 'self.dataOut.velocityV', self.dataOut.velocityV
1041 # #print 'self.dataOut.velocityV', self.dataOut.velocityV
1041 #
1042 #
1042 # self.data_output[0]=numpy.array(self.dataOut.velocityX)
1043 # self.data_output[0]=numpy.array(self.dataOut.velocityX)
1043 # self.data_output[1]=numpy.array(self.dataOut.velocityY)
1044 # self.data_output[1]=numpy.array(self.dataOut.velocityY)
1044 # self.data_output[2]=numpy.array(self.dataOut.velocityV)
1045 # self.data_output[2]=numpy.array(self.dataOut.velocityV)
1045 #
1046 #
1046 # prin= self.data_output[0][~numpy.isnan(self.data_output[0])]
1047 # prin= self.data_output[0][~numpy.isnan(self.data_output[0])]
1047 # print ' '
1048 # print ' '
1048 # print 'VmagAverage',numpy.mean(prin)
1049 # print 'VmagAverage',numpy.mean(prin)
1049 # print ' '
1050 # print ' '
1050 # # plt.figure(5)
1051 # # plt.figure(5)
1051 # # plt.subplot(211)
1052 # # plt.subplot(211)
1052 # # plt.plot(self.dataOut.velocityX,'yo:')
1053 # # plt.plot(self.dataOut.velocityX,'yo:')
1053 # # plt.subplot(212)
1054 # # plt.subplot(212)
1054 # # plt.plot(self.dataOut.velocityY,'yo:')
1055 # # plt.plot(self.dataOut.velocityY,'yo:')
1055 #
1056 #
1056 # # plt.figure(1)
1057 # # plt.figure(1)
1057 # # # plt.subplot(121)
1058 # # # plt.subplot(121)
1058 # # # plt.plot(xFrec,ySamples[0],'k',label='Ch0')
1059 # # # plt.plot(xFrec,ySamples[0],'k',label='Ch0')
1059 # # # plt.plot(xFrec,ySamples[1],'g',label='Ch1')
1060 # # # plt.plot(xFrec,ySamples[1],'g',label='Ch1')
1060 # # # plt.plot(xFrec,ySamples[2],'r',label='Ch2')
1061 # # # plt.plot(xFrec,ySamples[2],'r',label='Ch2')
1061 # # # plt.plot(xFrec,FitGauss,'yo:',label='fit')
1062 # # # plt.plot(xFrec,FitGauss,'yo:',label='fit')
1062 # # # plt.legend()
1063 # # # plt.legend()
1063 # # plt.title('DATOS A ALTURA DE 2850 METROS')
1064 # # plt.title('DATOS A ALTURA DE 2850 METROS')
1064 # #
1065 # #
1065 # # plt.xlabel('Frecuencia (KHz)')
1066 # # plt.xlabel('Frecuencia (KHz)')
1066 # # plt.ylabel('Magnitud')
1067 # # plt.ylabel('Magnitud')
1067 # # # plt.subplot(122)
1068 # # # plt.subplot(122)
1068 # # # plt.title('Fit for Time Constant')
1069 # # # plt.title('Fit for Time Constant')
1069 # # #plt.plot(xFrec,zline)
1070 # # #plt.plot(xFrec,zline)
1070 # # #plt.plot(xFrec,SmoothSPC,'g')
1071 # # #plt.plot(xFrec,SmoothSPC,'g')
1071 # # plt.plot(xFrec,FactNorm)
1072 # # plt.plot(xFrec,FactNorm)
1072 # # plt.axis([-4, 4, 0, 0.15])
1073 # # plt.axis([-4, 4, 0, 0.15])
1073 # # # plt.xlabel('SelfSpectra KHz')
1074 # # # plt.xlabel('SelfSpectra KHz')
1074 # #
1075 # #
1075 # # plt.figure(10)
1076 # # plt.figure(10)
1076 # # # plt.subplot(121)
1077 # # # plt.subplot(121)
1077 # # plt.plot(xFrec,ySamples[0],'b',label='Ch0')
1078 # # plt.plot(xFrec,ySamples[0],'b',label='Ch0')
1078 # # plt.plot(xFrec,ySamples[1],'y',label='Ch1')
1079 # # plt.plot(xFrec,ySamples[1],'y',label='Ch1')
1079 # # plt.plot(xFrec,ySamples[2],'r',label='Ch2')
1080 # # plt.plot(xFrec,ySamples[2],'r',label='Ch2')
1080 # # # plt.plot(xFrec,FitGauss,'yo:',label='fit')
1081 # # # plt.plot(xFrec,FitGauss,'yo:',label='fit')
1081 # # plt.legend()
1082 # # plt.legend()
1082 # # plt.title('SELFSPECTRA EN CANALES')
1083 # # plt.title('SELFSPECTRA EN CANALES')
1083 # #
1084 # #
1084 # # plt.xlabel('Frecuencia (KHz)')
1085 # # plt.xlabel('Frecuencia (KHz)')
1085 # # plt.ylabel('Magnitud')
1086 # # plt.ylabel('Magnitud')
1086 # # # plt.subplot(122)
1087 # # # plt.subplot(122)
1087 # # # plt.title('Fit for Time Constant')
1088 # # # plt.title('Fit for Time Constant')
1088 # # #plt.plot(xFrec,zline)
1089 # # #plt.plot(xFrec,zline)
1089 # # #plt.plot(xFrec,SmoothSPC,'g')
1090 # # #plt.plot(xFrec,SmoothSPC,'g')
1090 # # # plt.plot(xFrec,FactNorm)
1091 # # # plt.plot(xFrec,FactNorm)
1091 # # # plt.axis([-4, 4, 0, 0.15])
1092 # # # plt.axis([-4, 4, 0, 0.15])
1092 # # # plt.xlabel('SelfSpectra KHz')
1093 # # # plt.xlabel('SelfSpectra KHz')
1093 # #
1094 # #
1094 # # plt.figure(9)
1095 # # plt.figure(9)
1095 # #
1096 # #
1096 # #
1097 # #
1097 # # plt.title('DATOS SUAVIZADOS')
1098 # # plt.title('DATOS SUAVIZADOS')
1098 # # plt.xlabel('Frecuencia (KHz)')
1099 # # plt.xlabel('Frecuencia (KHz)')
1099 # # plt.ylabel('Magnitud')
1100 # # plt.ylabel('Magnitud')
1100 # # plt.plot(xFrec,SmoothSPC,'g')
1101 # # plt.plot(xFrec,SmoothSPC,'g')
1101 # #
1102 # #
1102 # # #plt.plot(xFrec,FactNorm)
1103 # # #plt.plot(xFrec,FactNorm)
1103 # # plt.axis([-4, 4, 0, 0.15])
1104 # # plt.axis([-4, 4, 0, 0.15])
1104 # # # plt.xlabel('SelfSpectra KHz')
1105 # # # plt.xlabel('SelfSpectra KHz')
1105 # # #
1106 # # #
1106 # # plt.figure(2)
1107 # # plt.figure(2)
1107 # # # #plt.subplot(121)
1108 # # # #plt.subplot(121)
1108 # # plt.plot(xFrec,yMean,'r',label='Mean SelfSpectra')
1109 # # plt.plot(xFrec,yMean,'r',label='Mean SelfSpectra')
1109 # # plt.plot(xFrec,FitGauss,'yo:',label='Ajuste Gaussiano')
1110 # # plt.plot(xFrec,FitGauss,'yo:',label='Ajuste Gaussiano')
1110 # # # plt.plot(xFrec[Rangpos],FitGauss[Find(FitGauss,min(FitGauss, key=lambda value:abs(value-Maximun*0.1)))],'bo')
1111 # # # plt.plot(xFrec[Rangpos],FitGauss[Find(FitGauss,min(FitGauss, key=lambda value:abs(value-Maximun*0.1)))],'bo')
1111 # # # #plt.plot(xFrec,phase)
1112 # # # #plt.plot(xFrec,phase)
1112 # # # plt.xlabel('Suavizado, promediado KHz')
1113 # # # plt.xlabel('Suavizado, promediado KHz')
1113 # # plt.title('SELFSPECTRA PROMEDIADO')
1114 # # plt.title('SELFSPECTRA PROMEDIADO')
1114 # # # #plt.subplot(122)
1115 # # # #plt.subplot(122)
1115 # # # #plt.plot(xSamples,zline)
1116 # # # #plt.plot(xSamples,zline)
1116 # # plt.xlabel('Frecuencia (KHz)')
1117 # # plt.xlabel('Frecuencia (KHz)')
1117 # # plt.ylabel('Magnitud')
1118 # # plt.ylabel('Magnitud')
1118 # # plt.legend()
1119 # # plt.legend()
1119 # # #
1120 # # #
1120 # # # plt.figure(3)
1121 # # # plt.figure(3)
1121 # # # plt.subplot(311)
1122 # # # plt.subplot(311)
1122 # # # #plt.plot(xFrec,phase[0])
1123 # # # #plt.plot(xFrec,phase[0])
1123 # # # plt.plot(xFrec,phase[0],'g')
1124 # # # plt.plot(xFrec,phase[0],'g')
1124 # # # plt.subplot(312)
1125 # # # plt.subplot(312)
1125 # # # plt.plot(xFrec,phase[1],'g')
1126 # # # plt.plot(xFrec,phase[1],'g')
1126 # # # plt.subplot(313)
1127 # # # plt.subplot(313)
1127 # # # plt.plot(xFrec,phase[2],'g')
1128 # # # plt.plot(xFrec,phase[2],'g')
1128 # # # #plt.plot(xFrec,phase[2])
1129 # # # #plt.plot(xFrec,phase[2])
1129 # # #
1130 # # #
1130 # # # plt.figure(4)
1131 # # # plt.figure(4)
1131 # # #
1132 # # #
1132 # # # plt.plot(xSamples,coherence[0],'b')
1133 # # # plt.plot(xSamples,coherence[0],'b')
1133 # # # plt.plot(xSamples,coherence[1],'r')
1134 # # # plt.plot(xSamples,coherence[1],'r')
1134 # # # plt.plot(xSamples,coherence[2],'g')
1135 # # # plt.plot(xSamples,coherence[2],'g')
1135 # # plt.show()
1136 # # plt.show()
1136 # # #
1137 # # #
1137 # # # plt.clf()
1138 # # # plt.clf()
1138 # # # plt.cla()
1139 # # # plt.cla()
1139 # # # plt.close()
1140 # # # plt.close()
1140 #
1141 #
1141 # print ' '
1142 # print ' '
1142
1143
1143
1144
1144
1145
1145 self.BlockCounter+=2
1146 self.BlockCounter+=2
1146
1147
1147 else:
1148 else:
1148 self.fileSelector+=1
1149 self.fileSelector+=1
1149 self.BlockCounter=0
1150 self.BlockCounter=0
1150 print "Next File"
1151 print "Next File"
1151
1152
1152
1153
1153
1154
1154 class BLTRWriter(ProcessingUnit):
1155 class BLTRWriter(ProcessingUnit):
1155 '''
1156 '''
1156 classdocs
1157 classdocs
1157 '''
1158 '''
1158
1159
1159 def __init__(self):
1160 def __init__(self):
1160 '''
1161 '''
1161 Constructor
1162 Constructor
1162 '''
1163 '''
1163 self.dataOut = None
1164 self.dataOut = None
1164
1165
1165 self.isConfig = False
1166 self.isConfig = False
1166
1167
1167 def setup(self, dataIn, path, blocksPerFile, set=0, ext=None):
1168 def setup(self, dataIn, path, blocksPerFile, set=0, ext=None):
1168 '''
1169 '''
1169 In this method we should set all initial parameters.
1170 In this method we should set all initial parameters.
1170
1171
1171 Input:
1172 Input:
1172 dataIn : Input data will also be outputa data
1173 dataIn : Input data will also be outputa data
1173
1174
1174 '''
1175 '''
1175 self.dataOut = dataIn
1176 self.dataOut = dataIn
1176
1177
1177 self.isConfig = True
1178 self.isConfig = True
1178
1179
1179 return
1180 return
1180
1181
1181 def run(self, dataIn, **kwargs):
1182 def run(self, dataIn, **kwargs):
1182 '''
1183 '''
1183 This method will be called many times so here you should put all your code
1184 This method will be called many times so here you should put all your code
1184
1185
1185 Inputs:
1186 Inputs:
1186
1187
1187 dataIn : object with the data
1188 dataIn : object with the data
1188
1189
1189 '''
1190 '''
1190
1191
1191 if not self.isConfig:
1192 if not self.isConfig:
1192 self.setup(dataIn, **kwargs)
1193 self.setup(dataIn, **kwargs)
1193
1194
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
@@ -1,3994 +1,4001
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 warnings.filterwarnings('ignore')
31 warnings.filterwarnings('ignore')
32
32
33
33
34 SPEED_OF_LIGHT = 299792458
34 SPEED_OF_LIGHT = 299792458
35
35
36
36
37 '''solving pickling issue'''
37 '''solving pickling issue'''
38
38
39 def _pickle_method(method):
39 def _pickle_method(method):
40 func_name = method.im_func.__name__
40 func_name = method.im_func.__name__
41 obj = method.im_self
41 obj = method.im_self
42 cls = method.im_class
42 cls = method.im_class
43 return _unpickle_method, (func_name, obj, cls)
43 return _unpickle_method, (func_name, obj, cls)
44
44
45 def _unpickle_method(func_name, obj, cls):
45 def _unpickle_method(func_name, obj, cls):
46 for cls in cls.mro():
46 for cls in cls.mro():
47 try:
47 try:
48 func = cls.__dict__[func_name]
48 func = cls.__dict__[func_name]
49 except KeyError:
49 except KeyError:
50 pass
50 pass
51 else:
51 else:
52 break
52 break
53 return func.__get__(obj, cls)
53 return func.__get__(obj, cls)
54
54
55
55
56
56
57
57
58
58
59
59
60
60
61
61
62 class ParametersProc(ProcessingUnit):
62 class ParametersProc(ProcessingUnit):
63
63
64 nSeconds = None
64 nSeconds = None
65
65
66 def __init__(self):
66 def __init__(self):
67 ProcessingUnit.__init__(self)
67 ProcessingUnit.__init__(self)
68
68
69 # self.objectDict = {}
69 # self.objectDict = {}
70 self.buffer = None
70 self.buffer = None
71 self.firstdatatime = None
71 self.firstdatatime = None
72 self.profIndex = 0
72 self.profIndex = 0
73 self.dataOut = Parameters()
73 self.dataOut = Parameters()
74
74
75 def __updateObjFromInput(self):
75 def __updateObjFromInput(self):
76
76
77 self.dataOut.inputUnit = self.dataIn.type
77 self.dataOut.inputUnit = self.dataIn.type
78
78
79 self.dataOut.timeZone = self.dataIn.timeZone
79 self.dataOut.timeZone = self.dataIn.timeZone
80 self.dataOut.dstFlag = self.dataIn.dstFlag
80 self.dataOut.dstFlag = self.dataIn.dstFlag
81 self.dataOut.errorCount = self.dataIn.errorCount
81 self.dataOut.errorCount = self.dataIn.errorCount
82 self.dataOut.useLocalTime = self.dataIn.useLocalTime
82 self.dataOut.useLocalTime = self.dataIn.useLocalTime
83
83
84 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
84 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
85 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
85 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
86 self.dataOut.channelList = self.dataIn.channelList
86 self.dataOut.channelList = self.dataIn.channelList
87 self.dataOut.heightList = self.dataIn.heightList
87 self.dataOut.heightList = self.dataIn.heightList
88 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
88 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
89 # self.dataOut.nHeights = self.dataIn.nHeights
89 # self.dataOut.nHeights = self.dataIn.nHeights
90 # self.dataOut.nChannels = self.dataIn.nChannels
90 # self.dataOut.nChannels = self.dataIn.nChannels
91 self.dataOut.nBaud = self.dataIn.nBaud
91 self.dataOut.nBaud = self.dataIn.nBaud
92 self.dataOut.nCode = self.dataIn.nCode
92 self.dataOut.nCode = self.dataIn.nCode
93 self.dataOut.code = self.dataIn.code
93 self.dataOut.code = self.dataIn.code
94 # self.dataOut.nProfiles = self.dataOut.nFFTPoints
94 # self.dataOut.nProfiles = self.dataOut.nFFTPoints
95 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
95 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
96 # self.dataOut.utctime = self.firstdatatime
96 # self.dataOut.utctime = self.firstdatatime
97 self.dataOut.utctime = self.dataIn.utctime
97 self.dataOut.utctime = self.dataIn.utctime
98 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
98 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
99 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
99 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
100 self.dataOut.nCohInt = self.dataIn.nCohInt
100 self.dataOut.nCohInt = self.dataIn.nCohInt
101 # self.dataOut.nIncohInt = 1
101 # self.dataOut.nIncohInt = 1
102 self.dataOut.ippSeconds = self.dataIn.ippSeconds
102 self.dataOut.ippSeconds = self.dataIn.ippSeconds
103 # self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
103 # self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
104 self.dataOut.timeInterval1 = self.dataIn.timeInterval
104 self.dataOut.timeInterval1 = self.dataIn.timeInterval
105 self.dataOut.heightList = self.dataIn.getHeiRange()
105 self.dataOut.heightList = self.dataIn.getHeiRange()
106 self.dataOut.frequency = self.dataIn.frequency
106 self.dataOut.frequency = self.dataIn.frequency
107 self.dataOut.noise = self.dataIn.noise
107 self.dataOut.noise = self.dataIn.noise
108
108
109
109
110
110
111 def run(self):
111 def run(self):
112
112
113 #---------------------- Voltage Data ---------------------------
113 #---------------------- Voltage Data ---------------------------
114
114
115 if self.dataIn.type == "Voltage":
115 if self.dataIn.type == "Voltage":
116
116
117 self.__updateObjFromInput()
117 self.__updateObjFromInput()
118 self.dataOut.data_pre = self.dataIn.data.copy()
118 self.dataOut.data_pre = self.dataIn.data.copy()
119 self.dataOut.flagNoData = False
119 self.dataOut.flagNoData = False
120 self.dataOut.utctimeInit = self.dataIn.utctime
120 self.dataOut.utctimeInit = self.dataIn.utctime
121 self.dataOut.paramInterval = self.dataIn.nProfiles*self.dataIn.nCohInt*self.dataIn.ippSeconds
121 self.dataOut.paramInterval = self.dataIn.nProfiles*self.dataIn.nCohInt*self.dataIn.ippSeconds
122 return
122 return
123
123
124 #---------------------- Spectra Data ---------------------------
124 #---------------------- Spectra Data ---------------------------
125
125
126 if self.dataIn.type == "Spectra":
126 if self.dataIn.type == "Spectra":
127
127
128 self.dataOut.data_pre = (self.dataIn.data_spc,self.dataIn.data_cspc)
128 self.dataOut.data_pre = (self.dataIn.data_spc,self.dataIn.data_cspc)
129 print 'self.dataIn.data_spc', self.dataIn.data_spc.shape
129 print 'self.dataIn.data_spc', self.dataIn.data_spc.shape
130 self.dataOut.abscissaList = self.dataIn.getVelRange(1)
130 self.dataOut.abscissaList = self.dataIn.getVelRange(1)
131 self.dataOut.spc_noise = self.dataIn.getNoise()
131 self.dataOut.spc_noise = self.dataIn.getNoise()
132 self.dataOut.spc_range = (self.dataIn.getFreqRange(1)/1000. , self.dataIn.getAcfRange(1) , self.dataIn.getVelRange(1) )
132 self.dataOut.spc_range = (self.dataIn.getFreqRange(1)/1000. , self.dataIn.getAcfRange(1) , self.dataIn.getVelRange(1) )
133
133
134 self.dataOut.normFactor = self.dataIn.normFactor
134 self.dataOut.normFactor = self.dataIn.normFactor
135 #self.dataOut.outputInterval = self.dataIn.outputInterval
135 #self.dataOut.outputInterval = self.dataIn.outputInterval
136 self.dataOut.groupList = self.dataIn.pairsList
136 self.dataOut.groupList = self.dataIn.pairsList
137 self.dataOut.flagNoData = False
137 self.dataOut.flagNoData = False
138 #print 'datain chandist ',self.dataIn.ChanDist
138 #print 'datain chandist ',self.dataIn.ChanDist
139 if hasattr(self.dataIn, 'ChanDist'): #Distances of receiver channels
139 if hasattr(self.dataIn, 'ChanDist'): #Distances of receiver channels
140 self.dataOut.ChanDist = self.dataIn.ChanDist
140 self.dataOut.ChanDist = self.dataIn.ChanDist
141 else: self.dataOut.ChanDist = None
141 else: self.dataOut.ChanDist = None
142
142
143 print 'datain chandist ',self.dataOut.ChanDist
143 print 'datain chandist ',self.dataOut.ChanDist
144
144
145 if hasattr(self.dataIn, 'VelRange'): #Velocities range
145 if hasattr(self.dataIn, 'VelRange'): #Velocities range
146 self.dataOut.VelRange = self.dataIn.VelRange
146 self.dataOut.VelRange = self.dataIn.VelRange
147 else: self.dataOut.VelRange = None
147 else: self.dataOut.VelRange = None
148
148
149 if hasattr(self.dataIn, 'RadarConst'): #Radar Constant
149 if hasattr(self.dataIn, 'RadarConst'): #Radar Constant
150 self.dataOut.RadarConst = self.dataIn.RadarConst
150 self.dataOut.RadarConst = self.dataIn.RadarConst
151
151
152 if hasattr(self.dataIn, 'NPW'): #NPW
152 if hasattr(self.dataIn, 'NPW'): #NPW
153 self.dataOut.NPW = self.dataIn.NPW
153 self.dataOut.NPW = self.dataIn.NPW
154
154
155 if hasattr(self.dataIn, 'COFA'): #COFA
155 if hasattr(self.dataIn, 'COFA'): #COFA
156 self.dataOut.COFA = self.dataIn.COFA
156 self.dataOut.COFA = self.dataIn.COFA
157
157
158
158
159
159
160 #---------------------- Correlation Data ---------------------------
160 #---------------------- Correlation Data ---------------------------
161
161
162 if self.dataIn.type == "Correlation":
162 if self.dataIn.type == "Correlation":
163 acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.dataIn.splitFunctions()
163 acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.dataIn.splitFunctions()
164
164
165 self.dataOut.data_pre = (self.dataIn.data_cf[acf_ind,:], self.dataIn.data_cf[ccf_ind,:,:])
165 self.dataOut.data_pre = (self.dataIn.data_cf[acf_ind,:], self.dataIn.data_cf[ccf_ind,:,:])
166 self.dataOut.normFactor = (self.dataIn.normFactor[acf_ind,:], self.dataIn.normFactor[ccf_ind,:])
166 self.dataOut.normFactor = (self.dataIn.normFactor[acf_ind,:], self.dataIn.normFactor[ccf_ind,:])
167 self.dataOut.groupList = (acf_pairs, ccf_pairs)
167 self.dataOut.groupList = (acf_pairs, ccf_pairs)
168
168
169 self.dataOut.abscissaList = self.dataIn.lagRange
169 self.dataOut.abscissaList = self.dataIn.lagRange
170 self.dataOut.noise = self.dataIn.noise
170 self.dataOut.noise = self.dataIn.noise
171 self.dataOut.data_SNR = self.dataIn.SNR
171 self.dataOut.data_SNR = self.dataIn.SNR
172 self.dataOut.flagNoData = False
172 self.dataOut.flagNoData = False
173 self.dataOut.nAvg = self.dataIn.nAvg
173 self.dataOut.nAvg = self.dataIn.nAvg
174
174
175 #---------------------- Parameters Data ---------------------------
175 #---------------------- Parameters Data ---------------------------
176
176
177 if self.dataIn.type == "Parameters":
177 if self.dataIn.type == "Parameters":
178 self.dataOut.copy(self.dataIn)
178 self.dataOut.copy(self.dataIn)
179 self.dataOut.flagNoData = False
179 self.dataOut.flagNoData = False
180
180
181 return True
181 return True
182
182
183 self.__updateObjFromInput()
183 self.__updateObjFromInput()
184 self.dataOut.utctimeInit = self.dataIn.utctime
184 self.dataOut.utctimeInit = self.dataIn.utctime
185 self.dataOut.paramInterval = self.dataIn.timeInterval
185 self.dataOut.paramInterval = self.dataIn.timeInterval
186
186
187 return
187 return
188
188
189
189
190 def target(tups):
190 def target(tups):
191
191
192 obj, args = tups
192 obj, args = tups
193 #print 'TARGETTT', obj, args
193 #print 'TARGETTT', obj, args
194 return obj.FitGau(args)
194 return obj.FitGau(args)
195
195
196 class GaussianFit(Operation):
196 class GaussianFit(Operation):
197
197
198 '''
198 '''
199 Function that fit of one and two generalized gaussians (gg) based
199 Function that fit of one and two generalized gaussians (gg) based
200 on the PSD shape across an "power band" identified from a cumsum of
200 on the PSD shape across an "power band" identified from a cumsum of
201 the measured spectrum - noise.
201 the measured spectrum - noise.
202
202
203 Input:
203 Input:
204 self.dataOut.data_pre : SelfSpectra
204 self.dataOut.data_pre : SelfSpectra
205
205
206 Output:
206 Output:
207 self.dataOut.GauSPC : SPC_ch1, SPC_ch2
207 self.dataOut.GauSPC : SPC_ch1, SPC_ch2
208
208
209 '''
209 '''
210 def __init__(self, **kwargs):
210 def __init__(self, **kwargs):
211 Operation.__init__(self, **kwargs)
211 Operation.__init__(self, **kwargs)
212 self.i=0
212 self.i=0
213
213
214
214
215 def run(self, dataOut, num_intg=7, pnoise=1., vel_arr=None, SNRlimit=-9): #num_intg: Incoherent integrations, pnoise: Noise, vel_arr: range of velocities, similar to the ftt points
215 def run(self, dataOut, num_intg=7, pnoise=1., vel_arr=None, SNRlimit=-9): #num_intg: Incoherent integrations, pnoise: Noise, vel_arr: range of velocities, similar to the ftt points
216 """This routine will find a couple of generalized Gaussians to a power spectrum
216 """This routine will find a couple of generalized Gaussians to a power spectrum
217 input: spc
217 input: spc
218 output:
218 output:
219 Amplitude0,shift0,width0,p0,Amplitude1,shift1,width1,p1,noise
219 Amplitude0,shift0,width0,p0,Amplitude1,shift1,width1,p1,noise
220 """
220 """
221
221
222 self.spc = dataOut.data_pre[0].copy()
222 self.spc = dataOut.data_pre[0].copy()
223
223
224
224
225 print 'SelfSpectra Shape', numpy.asarray(self.spc).shape
225 print 'SelfSpectra Shape', numpy.asarray(self.spc).shape
226
226
227
227
228 #plt.figure(50)
228 #plt.figure(50)
229 #plt.subplot(121)
229 #plt.subplot(121)
230 #plt.plot(self.spc,'k',label='spc(66)')
230 #plt.plot(self.spc,'k',label='spc(66)')
231 #plt.plot(xFrec,ySamples[1],'g',label='Ch1')
231 #plt.plot(xFrec,ySamples[1],'g',label='Ch1')
232 #plt.plot(xFrec,ySamples[2],'r',label='Ch2')
232 #plt.plot(xFrec,ySamples[2],'r',label='Ch2')
233 #plt.plot(xFrec,FitGauss,'yo:',label='fit')
233 #plt.plot(xFrec,FitGauss,'yo:',label='fit')
234 #plt.legend()
234 #plt.legend()
235 #plt.title('DATOS A ALTURA DE 7500 METROS')
235 #plt.title('DATOS A ALTURA DE 7500 METROS')
236 #plt.show()
236 #plt.show()
237
237
238 self.Num_Hei = self.spc.shape[2]
238 self.Num_Hei = self.spc.shape[2]
239 #self.Num_Bin = len(self.spc)
239 #self.Num_Bin = len(self.spc)
240 self.Num_Bin = self.spc.shape[1]
240 self.Num_Bin = self.spc.shape[1]
241 self.Num_Chn = self.spc.shape[0]
241 self.Num_Chn = self.spc.shape[0]
242
242
243 Vrange = dataOut.abscissaList
243 Vrange = dataOut.abscissaList
244
244
245 #print 'self.spc2', numpy.asarray(self.spc).shape
245 #print 'self.spc2', numpy.asarray(self.spc).shape
246
246
247 GauSPC = numpy.empty([2,self.Num_Bin,self.Num_Hei])
247 GauSPC = numpy.empty([2,self.Num_Bin,self.Num_Hei])
248 SPC_ch1 = numpy.empty([self.Num_Bin,self.Num_Hei])
248 SPC_ch1 = numpy.empty([self.Num_Bin,self.Num_Hei])
249 SPC_ch2 = numpy.empty([self.Num_Bin,self.Num_Hei])
249 SPC_ch2 = numpy.empty([self.Num_Bin,self.Num_Hei])
250 SPC_ch1[:] = numpy.NaN
250 SPC_ch1[:] = numpy.NaN
251 SPC_ch2[:] = numpy.NaN
251 SPC_ch2[:] = numpy.NaN
252
252
253
253
254 start_time = time.time()
254 start_time = time.time()
255
255
256 noise_ = dataOut.spc_noise[0].copy()
256 noise_ = dataOut.spc_noise[0].copy()
257
257
258
258
259
259
260 pool = Pool(processes=self.Num_Chn)
260 pool = Pool(processes=self.Num_Chn)
261 args = [(Vrange, Ch, pnoise, noise_, num_intg, SNRlimit) for Ch in range(self.Num_Chn)]
261 args = [(Vrange, Ch, pnoise, noise_, num_intg, SNRlimit) for Ch in range(self.Num_Chn)]
262 objs = [self for __ in range(self.Num_Chn)]
262 objs = [self for __ in range(self.Num_Chn)]
263 attrs = zip(objs, args)
263 attrs = zip(objs, args)
264 gauSPC = pool.map(target, attrs)
264 gauSPC = pool.map(target, attrs)
265 dataOut.GauSPC = numpy.asarray(gauSPC)
265 dataOut.GauSPC = numpy.asarray(gauSPC)
266 # ret = []
266 # ret = []
267 # for n in range(self.Num_Chn):
267 # for n in range(self.Num_Chn):
268 # self.FitGau(args[n])
268 # self.FitGau(args[n])
269 # dataOut.GauSPC = ret
269 # dataOut.GauSPC = ret
270
270
271
271
272
272
273 # for ch in range(self.Num_Chn):
273 # for ch in range(self.Num_Chn):
274 #
274 #
275 # for ht in range(self.Num_Hei):
275 # for ht in range(self.Num_Hei):
276 # #print (numpy.asarray(self.spc).shape)
276 # #print (numpy.asarray(self.spc).shape)
277 # spc = numpy.asarray(self.spc)[ch,:,ht]
277 # spc = numpy.asarray(self.spc)[ch,:,ht]
278 #
278 #
279 # #############################################
279 # #############################################
280 # # normalizing spc and noise
280 # # normalizing spc and noise
281 # # This part differs from gg1
281 # # This part differs from gg1
282 # spc_norm_max = max(spc)
282 # spc_norm_max = max(spc)
283 # spc = spc / spc_norm_max
283 # spc = spc / spc_norm_max
284 # pnoise = pnoise / spc_norm_max
284 # pnoise = pnoise / spc_norm_max
285 # #############################################
285 # #############################################
286 #
286 #
287 # if abs(vel_arr[0])<15.0: # this switch is for spectra collected with different length IPP's
287 # if abs(vel_arr[0])<15.0: # this switch is for spectra collected with different length IPP's
288 # fatspectra=1.0
288 # fatspectra=1.0
289 # else:
289 # else:
290 # fatspectra=0.5
290 # fatspectra=0.5
291 #
291 #
292 # wnoise = noise_ / spc_norm_max
292 # wnoise = noise_ / spc_norm_max
293 # #print 'wnoise', noise_, dataOut.spc_noise[0], wnoise
293 # #print 'wnoise', noise_, dataOut.spc_noise[0], wnoise
294 # #wnoise,stdv,i_max,index =enoise(spc,num_intg) #noise estimate using Hildebrand Sekhon, only wnoise is used
294 # #wnoise,stdv,i_max,index =enoise(spc,num_intg) #noise estimate using Hildebrand Sekhon, only wnoise is used
295 # #if wnoise>1.1*pnoise: # to be tested later
295 # #if wnoise>1.1*pnoise: # to be tested later
296 # # wnoise=pnoise
296 # # wnoise=pnoise
297 # noisebl=wnoise*0.9; noisebh=wnoise*1.1
297 # noisebl=wnoise*0.9; noisebh=wnoise*1.1
298 # spc=spc-wnoise
298 # spc=spc-wnoise
299 #
299 #
300 # minx=numpy.argmin(spc)
300 # minx=numpy.argmin(spc)
301 # spcs=numpy.roll(spc,-minx)
301 # spcs=numpy.roll(spc,-minx)
302 # cum=numpy.cumsum(spcs)
302 # cum=numpy.cumsum(spcs)
303 # tot_noise=wnoise * self.Num_Bin #64;
303 # tot_noise=wnoise * self.Num_Bin #64;
304 # #tot_signal=sum(cum[-5:])/5.; ''' How does this line work? '''
304 # #tot_signal=sum(cum[-5:])/5.; ''' How does this line work? '''
305 # #snr=tot_signal/tot_noise
305 # #snr=tot_signal/tot_noise
306 # #snr=cum[-1]/tot_noise
306 # #snr=cum[-1]/tot_noise
307 #
307 #
308 # #print 'spc' , spcs[5:8] , 'tot_noise', tot_noise
308 # #print 'spc' , spcs[5:8] , 'tot_noise', tot_noise
309 #
309 #
310 # snr = sum(spcs)/tot_noise
310 # snr = sum(spcs)/tot_noise
311 # snrdB=10.*numpy.log10(snr)
311 # snrdB=10.*numpy.log10(snr)
312 #
312 #
313 # #if snrdB < -9 :
313 # #if snrdB < -9 :
314 # # snrdB = numpy.NaN
314 # # snrdB = numpy.NaN
315 # # continue
315 # # continue
316 #
316 #
317 # #print 'snr',snrdB # , sum(spcs) , tot_noise
317 # #print 'snr',snrdB # , sum(spcs) , tot_noise
318 #
318 #
319 #
319 #
320 # #if snrdB<-18 or numpy.isnan(snrdB) or num_intg<4:
320 # #if snrdB<-18 or numpy.isnan(snrdB) or num_intg<4:
321 # # return [None,]*4,[None,]*4,None,snrdB,None,None,[None,]*5,[None,]*9,None
321 # # return [None,]*4,[None,]*4,None,snrdB,None,None,[None,]*5,[None,]*9,None
322 #
322 #
323 # cummax=max(cum); epsi=0.08*fatspectra # cumsum to narrow down the energy region
323 # cummax=max(cum); epsi=0.08*fatspectra # cumsum to narrow down the energy region
324 # cumlo=cummax*epsi;
324 # cumlo=cummax*epsi;
325 # cumhi=cummax*(1-epsi)
325 # cumhi=cummax*(1-epsi)
326 # powerindex=numpy.array(numpy.where(numpy.logical_and(cum>cumlo, cum<cumhi))[0])
326 # powerindex=numpy.array(numpy.where(numpy.logical_and(cum>cumlo, cum<cumhi))[0])
327 #
327 #
328 # #if len(powerindex)==1:
328 # #if len(powerindex)==1:
329 # ##return [numpy.mod(powerindex[0]+minx,64),None,None,None,],[None,]*4,None,snrdB,None,None,[None,]*5,[None,]*9,None
329 # ##return [numpy.mod(powerindex[0]+minx,64),None,None,None,],[None,]*4,None,snrdB,None,None,[None,]*5,[None,]*9,None
330 # #return [numpy.mod(powerindex[0]+minx, self.Num_Bin ),None,None,None,],[None,]*4,None,snrdB,None,None,[None,]*5,[None,]*9,None
330 # #return [numpy.mod(powerindex[0]+minx, self.Num_Bin ),None,None,None,],[None,]*4,None,snrdB,None,None,[None,]*5,[None,]*9,None
331 # #elif len(powerindex)<4*fatspectra:
331 # #elif len(powerindex)<4*fatspectra:
332 # #return [None,]*4,[None,]*4,None,snrdB,None,None,[None,]*5,[None,]*9,None
332 # #return [None,]*4,[None,]*4,None,snrdB,None,None,[None,]*5,[None,]*9,None
333 #
333 #
334 # if len(powerindex) < 1:# case for powerindex 0
334 # if len(powerindex) < 1:# case for powerindex 0
335 # continue
335 # continue
336 # powerlo=powerindex[0]
336 # powerlo=powerindex[0]
337 # powerhi=powerindex[-1]
337 # powerhi=powerindex[-1]
338 # powerwidth=powerhi-powerlo
338 # powerwidth=powerhi-powerlo
339 #
339 #
340 # firstpeak=powerlo+powerwidth/10.# first gaussian energy location
340 # firstpeak=powerlo+powerwidth/10.# first gaussian energy location
341 # secondpeak=powerhi-powerwidth/10.#second gaussian energy location
341 # secondpeak=powerhi-powerwidth/10.#second gaussian energy location
342 # midpeak=(firstpeak+secondpeak)/2.
342 # midpeak=(firstpeak+secondpeak)/2.
343 # firstamp=spcs[int(firstpeak)]
343 # firstamp=spcs[int(firstpeak)]
344 # secondamp=spcs[int(secondpeak)]
344 # secondamp=spcs[int(secondpeak)]
345 # midamp=spcs[int(midpeak)]
345 # midamp=spcs[int(midpeak)]
346 # #x=numpy.spc.shape[1]
346 # #x=numpy.spc.shape[1]
347 #
347 #
348 # #x=numpy.arange(64)
348 # #x=numpy.arange(64)
349 # x=numpy.arange( self.Num_Bin )
349 # x=numpy.arange( self.Num_Bin )
350 # y_data=spc+wnoise
350 # y_data=spc+wnoise
351 #
351 #
352 # # single gaussian
352 # # single gaussian
353 # #shift0=numpy.mod(midpeak+minx,64)
353 # #shift0=numpy.mod(midpeak+minx,64)
354 # shift0=numpy.mod(midpeak+minx, self.Num_Bin )
354 # shift0=numpy.mod(midpeak+minx, self.Num_Bin )
355 # width0=powerwidth/4.#Initialization entire power of spectrum divided by 4
355 # width0=powerwidth/4.#Initialization entire power of spectrum divided by 4
356 # power0=2.
356 # power0=2.
357 # amplitude0=midamp
357 # amplitude0=midamp
358 # state0=[shift0,width0,amplitude0,power0,wnoise]
358 # state0=[shift0,width0,amplitude0,power0,wnoise]
359 # #bnds=((0,63),(1,powerwidth),(0,None),(0.5,3.),(noisebl,noisebh))
359 # #bnds=((0,63),(1,powerwidth),(0,None),(0.5,3.),(noisebl,noisebh))
360 # bnds=(( 0,(self.Num_Bin-1) ),(1,powerwidth),(0,None),(0.5,3.),(noisebl,noisebh))
360 # bnds=(( 0,(self.Num_Bin-1) ),(1,powerwidth),(0,None),(0.5,3.),(noisebl,noisebh))
361 # #bnds=(( 0,(self.Num_Bin-1) ),(1,powerwidth),(0,None),(0.5,3.),(0.1,0.5))
361 # #bnds=(( 0,(self.Num_Bin-1) ),(1,powerwidth),(0,None),(0.5,3.),(0.1,0.5))
362 # # bnds = range of fft, power width, amplitude, power, noise
362 # # bnds = range of fft, power width, amplitude, power, noise
363 # lsq1=fmin_l_bfgs_b(self.misfit1,state0,args=(y_data,x,num_intg),bounds=bnds,approx_grad=True)
363 # lsq1=fmin_l_bfgs_b(self.misfit1,state0,args=(y_data,x,num_intg),bounds=bnds,approx_grad=True)
364 #
364 #
365 # chiSq1=lsq1[1];
365 # chiSq1=lsq1[1];
366 # jack1= self.y_jacobian1(x,lsq1[0])
366 # jack1= self.y_jacobian1(x,lsq1[0])
367 #
367 #
368 #
368 #
369 # try:
369 # try:
370 # sigmas1=numpy.sqrt(chiSq1*numpy.diag(numpy.linalg.inv(numpy.dot(jack1.T,jack1))))
370 # sigmas1=numpy.sqrt(chiSq1*numpy.diag(numpy.linalg.inv(numpy.dot(jack1.T,jack1))))
371 # except:
371 # except:
372 # std1=32.; sigmas1=numpy.ones(5)
372 # std1=32.; sigmas1=numpy.ones(5)
373 # else:
373 # else:
374 # std1=sigmas1[0]
374 # std1=sigmas1[0]
375 #
375 #
376 #
376 #
377 # if fatspectra<1.0 and powerwidth<4:
377 # if fatspectra<1.0 and powerwidth<4:
378 # choice=0
378 # choice=0
379 # Amplitude0=lsq1[0][2]
379 # Amplitude0=lsq1[0][2]
380 # shift0=lsq1[0][0]
380 # shift0=lsq1[0][0]
381 # width0=lsq1[0][1]
381 # width0=lsq1[0][1]
382 # p0=lsq1[0][3]
382 # p0=lsq1[0][3]
383 # Amplitude1=0.
383 # Amplitude1=0.
384 # shift1=0.
384 # shift1=0.
385 # width1=0.
385 # width1=0.
386 # p1=0.
386 # p1=0.
387 # noise=lsq1[0][4]
387 # noise=lsq1[0][4]
388 # #return (numpy.array([shift0,width0,Amplitude0,p0]),
388 # #return (numpy.array([shift0,width0,Amplitude0,p0]),
389 # # numpy.array([shift1,width1,Amplitude1,p1]),noise,snrdB,chiSq1,6.,sigmas1,[None,]*9,choice)
389 # # numpy.array([shift1,width1,Amplitude1,p1]),noise,snrdB,chiSq1,6.,sigmas1,[None,]*9,choice)
390 #
390 #
391 # # two gaussians
391 # # two gaussians
392 # #shift0=numpy.mod(firstpeak+minx,64); shift1=numpy.mod(secondpeak+minx,64)
392 # #shift0=numpy.mod(firstpeak+minx,64); shift1=numpy.mod(secondpeak+minx,64)
393 # shift0=numpy.mod(firstpeak+minx, self.Num_Bin );
393 # shift0=numpy.mod(firstpeak+minx, self.Num_Bin );
394 # shift1=numpy.mod(secondpeak+minx, self.Num_Bin )
394 # shift1=numpy.mod(secondpeak+minx, self.Num_Bin )
395 # width0=powerwidth/6.;
395 # width0=powerwidth/6.;
396 # width1=width0
396 # width1=width0
397 # power0=2.;
397 # power0=2.;
398 # power1=power0
398 # power1=power0
399 # amplitude0=firstamp;
399 # amplitude0=firstamp;
400 # amplitude1=secondamp
400 # amplitude1=secondamp
401 # state0=[shift0,width0,amplitude0,power0,shift1,width1,amplitude1,power1,wnoise]
401 # state0=[shift0,width0,amplitude0,power0,shift1,width1,amplitude1,power1,wnoise]
402 # #bnds=((0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(noisebl,noisebh))
402 # #bnds=((0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(noisebl,noisebh))
403 # 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))
403 # 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))
404 # #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))
404 # #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))
405 #
405 #
406 # lsq2=fmin_l_bfgs_b(self.misfit2,state0,args=(y_data,x,num_intg),bounds=bnds,approx_grad=True)
406 # lsq2=fmin_l_bfgs_b(self.misfit2,state0,args=(y_data,x,num_intg),bounds=bnds,approx_grad=True)
407 #
407 #
408 #
408 #
409 # chiSq2=lsq2[1]; jack2=self.y_jacobian2(x,lsq2[0])
409 # chiSq2=lsq2[1]; jack2=self.y_jacobian2(x,lsq2[0])
410 #
410 #
411 #
411 #
412 # try:
412 # try:
413 # sigmas2=numpy.sqrt(chiSq2*numpy.diag(numpy.linalg.inv(numpy.dot(jack2.T,jack2))))
413 # sigmas2=numpy.sqrt(chiSq2*numpy.diag(numpy.linalg.inv(numpy.dot(jack2.T,jack2))))
414 # except:
414 # except:
415 # std2a=32.; std2b=32.; sigmas2=numpy.ones(9)
415 # std2a=32.; std2b=32.; sigmas2=numpy.ones(9)
416 # else:
416 # else:
417 # std2a=sigmas2[0]; std2b=sigmas2[4]
417 # std2a=sigmas2[0]; std2b=sigmas2[4]
418 #
418 #
419 #
419 #
420 #
420 #
421 # 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)
421 # 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)
422 #
422 #
423 # if snrdB>-9: # when SNR is strong pick the peak with least shift (LOS velocity) error
423 # if snrdB>-9: # when SNR is strong pick the peak with least shift (LOS velocity) error
424 # if oneG:
424 # if oneG:
425 # choice=0
425 # choice=0
426 # else:
426 # else:
427 # w1=lsq2[0][1]; w2=lsq2[0][5]
427 # w1=lsq2[0][1]; w2=lsq2[0][5]
428 # a1=lsq2[0][2]; a2=lsq2[0][6]
428 # a1=lsq2[0][2]; a2=lsq2[0][6]
429 # p1=lsq2[0][3]; p2=lsq2[0][7]
429 # p1=lsq2[0][3]; p2=lsq2[0][7]
430 # s1=(2**(1+1./p1))*scipy.special.gamma(1./p1)/p1; s2=(2**(1+1./p2))*scipy.special.gamma(1./p2)/p2;
430 # s1=(2**(1+1./p1))*scipy.special.gamma(1./p1)/p1; s2=(2**(1+1./p2))*scipy.special.gamma(1./p2)/p2;
431 # gp1=a1*w1*s1; gp2=a2*w2*s2 # power content of each ggaussian with proper p scaling
431 # gp1=a1*w1*s1; gp2=a2*w2*s2 # power content of each ggaussian with proper p scaling
432 #
432 #
433 # if gp1>gp2:
433 # if gp1>gp2:
434 # if a1>0.7*a2:
434 # if a1>0.7*a2:
435 # choice=1
435 # choice=1
436 # else:
436 # else:
437 # choice=2
437 # choice=2
438 # elif gp2>gp1:
438 # elif gp2>gp1:
439 # if a2>0.7*a1:
439 # if a2>0.7*a1:
440 # choice=2
440 # choice=2
441 # else:
441 # else:
442 # choice=1
442 # choice=1
443 # else:
443 # else:
444 # choice=numpy.argmax([a1,a2])+1
444 # choice=numpy.argmax([a1,a2])+1
445 # #else:
445 # #else:
446 # #choice=argmin([std2a,std2b])+1
446 # #choice=argmin([std2a,std2b])+1
447 #
447 #
448 # else: # with low SNR go to the most energetic peak
448 # else: # with low SNR go to the most energetic peak
449 # choice=numpy.argmax([lsq1[0][2]*lsq1[0][1],lsq2[0][2]*lsq2[0][1],lsq2[0][6]*lsq2[0][5]])
449 # choice=numpy.argmax([lsq1[0][2]*lsq1[0][1],lsq2[0][2]*lsq2[0][1],lsq2[0][6]*lsq2[0][5]])
450 #
450 #
451 # #print 'choice',choice
451 # #print 'choice',choice
452 #
452 #
453 # if choice==0: # pick the single gaussian fit
453 # if choice==0: # pick the single gaussian fit
454 # Amplitude0=lsq1[0][2]
454 # Amplitude0=lsq1[0][2]
455 # shift0=lsq1[0][0]
455 # shift0=lsq1[0][0]
456 # width0=lsq1[0][1]
456 # width0=lsq1[0][1]
457 # p0=lsq1[0][3]
457 # p0=lsq1[0][3]
458 # Amplitude1=0.
458 # Amplitude1=0.
459 # shift1=0.
459 # shift1=0.
460 # width1=0.
460 # width1=0.
461 # p1=0.
461 # p1=0.
462 # noise=lsq1[0][4]
462 # noise=lsq1[0][4]
463 # elif choice==1: # take the first one of the 2 gaussians fitted
463 # elif choice==1: # take the first one of the 2 gaussians fitted
464 # Amplitude0 = lsq2[0][2]
464 # Amplitude0 = lsq2[0][2]
465 # shift0 = lsq2[0][0]
465 # shift0 = lsq2[0][0]
466 # width0 = lsq2[0][1]
466 # width0 = lsq2[0][1]
467 # p0 = lsq2[0][3]
467 # p0 = lsq2[0][3]
468 # Amplitude1 = lsq2[0][6] # This is 0 in gg1
468 # Amplitude1 = lsq2[0][6] # This is 0 in gg1
469 # shift1 = lsq2[0][4] # This is 0 in gg1
469 # shift1 = lsq2[0][4] # This is 0 in gg1
470 # width1 = lsq2[0][5] # This is 0 in gg1
470 # width1 = lsq2[0][5] # This is 0 in gg1
471 # p1 = lsq2[0][7] # This is 0 in gg1
471 # p1 = lsq2[0][7] # This is 0 in gg1
472 # noise = lsq2[0][8]
472 # noise = lsq2[0][8]
473 # else: # the second one
473 # else: # the second one
474 # Amplitude0 = lsq2[0][6]
474 # Amplitude0 = lsq2[0][6]
475 # shift0 = lsq2[0][4]
475 # shift0 = lsq2[0][4]
476 # width0 = lsq2[0][5]
476 # width0 = lsq2[0][5]
477 # p0 = lsq2[0][7]
477 # p0 = lsq2[0][7]
478 # Amplitude1 = lsq2[0][2] # This is 0 in gg1
478 # Amplitude1 = lsq2[0][2] # This is 0 in gg1
479 # shift1 = lsq2[0][0] # This is 0 in gg1
479 # shift1 = lsq2[0][0] # This is 0 in gg1
480 # width1 = lsq2[0][1] # This is 0 in gg1
480 # width1 = lsq2[0][1] # This is 0 in gg1
481 # p1 = lsq2[0][3] # This is 0 in gg1
481 # p1 = lsq2[0][3] # This is 0 in gg1
482 # noise = lsq2[0][8]
482 # noise = lsq2[0][8]
483 #
483 #
484 # #print len(noise + Amplitude0*numpy.exp(-0.5*(abs(x-shift0))/width0)**p0)
484 # #print len(noise + Amplitude0*numpy.exp(-0.5*(abs(x-shift0))/width0)**p0)
485 # SPC_ch1[:,ht] = noise + Amplitude0*numpy.exp(-0.5*(abs(x-shift0))/width0)**p0
485 # SPC_ch1[:,ht] = noise + Amplitude0*numpy.exp(-0.5*(abs(x-shift0))/width0)**p0
486 # SPC_ch2[:,ht] = noise + Amplitude1*numpy.exp(-0.5*(abs(x-shift1))/width1)**p1
486 # SPC_ch2[:,ht] = noise + Amplitude1*numpy.exp(-0.5*(abs(x-shift1))/width1)**p1
487 # #print 'SPC_ch1.shape',SPC_ch1.shape
487 # #print 'SPC_ch1.shape',SPC_ch1.shape
488 # #print 'SPC_ch2.shape',SPC_ch2.shape
488 # #print 'SPC_ch2.shape',SPC_ch2.shape
489 # #dataOut.data_param = SPC_ch1
489 # #dataOut.data_param = SPC_ch1
490 # GauSPC[0] = SPC_ch1
490 # GauSPC[0] = SPC_ch1
491 # GauSPC[1] = SPC_ch2
491 # GauSPC[1] = SPC_ch2
492
492
493 # #plt.gcf().clear()
493 # #plt.gcf().clear()
494 # plt.figure(50+self.i)
494 # plt.figure(50+self.i)
495 # self.i=self.i+1
495 # self.i=self.i+1
496 # #plt.subplot(121)
496 # #plt.subplot(121)
497 # plt.plot(self.spc,'k')#,label='spc(66)')
497 # plt.plot(self.spc,'k')#,label='spc(66)')
498 # plt.plot(SPC_ch1[ch,ht],'b')#,label='gg1')
498 # plt.plot(SPC_ch1[ch,ht],'b')#,label='gg1')
499 # #plt.plot(SPC_ch2,'r')#,label='gg2')
499 # #plt.plot(SPC_ch2,'r')#,label='gg2')
500 # #plt.plot(xFrec,ySamples[1],'g',label='Ch1')
500 # #plt.plot(xFrec,ySamples[1],'g',label='Ch1')
501 # #plt.plot(xFrec,ySamples[2],'r',label='Ch2')
501 # #plt.plot(xFrec,ySamples[2],'r',label='Ch2')
502 # #plt.plot(xFrec,FitGauss,'yo:',label='fit')
502 # #plt.plot(xFrec,FitGauss,'yo:',label='fit')
503 # plt.legend()
503 # plt.legend()
504 # plt.title('DATOS A ALTURA DE 7500 METROS')
504 # plt.title('DATOS A ALTURA DE 7500 METROS')
505 # plt.show()
505 # plt.show()
506 # print 'shift0', shift0
506 # print 'shift0', shift0
507 # print 'Amplitude0', Amplitude0
507 # print 'Amplitude0', Amplitude0
508 # print 'width0', width0
508 # print 'width0', width0
509 # print 'p0', p0
509 # print 'p0', p0
510 # print '========================'
510 # print '========================'
511 # print 'shift1', shift1
511 # print 'shift1', shift1
512 # print 'Amplitude1', Amplitude1
512 # print 'Amplitude1', Amplitude1
513 # print 'width1', width1
513 # print 'width1', width1
514 # print 'p1', p1
514 # print 'p1', p1
515 # print 'noise', noise
515 # print 'noise', noise
516 # print 's_noise', wnoise
516 # print 's_noise', wnoise
517
517
518 print '========================================================'
518 print '========================================================'
519 print 'total_time: ', time.time()-start_time
519 print 'total_time: ', time.time()-start_time
520
520
521 # re-normalizing spc and noise
521 # re-normalizing spc and noise
522 # This part differs from gg1
522 # This part differs from gg1
523
523
524
524
525
525
526 ''' Parameters:
526 ''' Parameters:
527 1. Amplitude
527 1. Amplitude
528 2. Shift
528 2. Shift
529 3. Width
529 3. Width
530 4. Power
530 4. Power
531 '''
531 '''
532
532
533
533
534 ###############################################################################
534 ###############################################################################
535 def FitGau(self, X):
535 def FitGau(self, X):
536
536
537 Vrange, ch, pnoise, noise_, num_intg, SNRlimit = X
537 Vrange, ch, pnoise, noise_, num_intg, SNRlimit = X
538 #print 'VARSSSS', ch, pnoise, noise, num_intg
538 #print 'VARSSSS', ch, pnoise, noise, num_intg
539
539
540 #print 'HEIGHTS', self.Num_Hei
540 #print 'HEIGHTS', self.Num_Hei
541
541
542 GauSPC = []
542 GauSPC = []
543 SPC_ch1 = numpy.empty([self.Num_Bin,self.Num_Hei])
543 SPC_ch1 = numpy.empty([self.Num_Bin,self.Num_Hei])
544 SPC_ch2 = numpy.empty([self.Num_Bin,self.Num_Hei])
544 SPC_ch2 = numpy.empty([self.Num_Bin,self.Num_Hei])
545 SPC_ch1[:] = 0#numpy.NaN
545 SPC_ch1[:] = 0#numpy.NaN
546 SPC_ch2[:] = 0#numpy.NaN
546 SPC_ch2[:] = 0#numpy.NaN
547
547
548
548
549
549
550 for ht in range(self.Num_Hei):
550 for ht in range(self.Num_Hei):
551 #print (numpy.asarray(self.spc).shape)
551 #print (numpy.asarray(self.spc).shape)
552
552
553 #print 'TTTTT', ch , ht
553 #print 'TTTTT', ch , ht
554 #print self.spc.shape
554 #print self.spc.shape
555
555
556
556
557 spc = numpy.asarray(self.spc)[ch,:,ht]
557 spc = numpy.asarray(self.spc)[ch,:,ht]
558
558
559 #############################################
559 #############################################
560 # normalizing spc and noise
560 # normalizing spc and noise
561 # This part differs from gg1
561 # This part differs from gg1
562 spc_norm_max = max(spc)
562 spc_norm_max = max(spc)
563 spc = spc / spc_norm_max
563 spc = spc / spc_norm_max
564 pnoise = pnoise / spc_norm_max
564 pnoise = pnoise / spc_norm_max
565 #############################################
565 #############################################
566
566
567 fatspectra=1.0
567 fatspectra=1.0
568
568
569 wnoise = noise_ / spc_norm_max
569 wnoise = noise_ / spc_norm_max
570 #wnoise,stdv,i_max,index =enoise(spc,num_intg) #noise estimate using Hildebrand Sekhon, only wnoise is used
570 #wnoise,stdv,i_max,index =enoise(spc,num_intg) #noise estimate using Hildebrand Sekhon, only wnoise is used
571 #if wnoise>1.1*pnoise: # to be tested later
571 #if wnoise>1.1*pnoise: # to be tested later
572 # wnoise=pnoise
572 # wnoise=pnoise
573 noisebl=wnoise*0.9; noisebh=wnoise*1.1
573 noisebl=wnoise*0.9; noisebh=wnoise*1.1
574 spc=spc-wnoise
574 spc=spc-wnoise
575 # print 'wnoise', noise_[0], spc_norm_max, wnoise
575 # print 'wnoise', noise_[0], spc_norm_max, wnoise
576 minx=numpy.argmin(spc)
576 minx=numpy.argmin(spc)
577 spcs=numpy.roll(spc,-minx)
577 spcs=numpy.roll(spc,-minx)
578 cum=numpy.cumsum(spcs)
578 cum=numpy.cumsum(spcs)
579 tot_noise=wnoise * self.Num_Bin #64;
579 tot_noise=wnoise * self.Num_Bin #64;
580 #print 'spc' , spcs[5:8] , 'tot_noise', tot_noise
580 #print 'spc' , spcs[5:8] , 'tot_noise', tot_noise
581 #tot_signal=sum(cum[-5:])/5.; ''' How does this line work? '''
581 #tot_signal=sum(cum[-5:])/5.; ''' How does this line work? '''
582 #snr=tot_signal/tot_noise
582 #snr=tot_signal/tot_noise
583 #snr=cum[-1]/tot_noise
583 #snr=cum[-1]/tot_noise
584 snr = sum(spcs)/tot_noise
584 snr = sum(spcs)/tot_noise
585 snrdB=10.*numpy.log10(snr)
585 snrdB=10.*numpy.log10(snr)
586
586
587 if snrdB < SNRlimit :
587 if snrdB < SNRlimit :
588 snr = numpy.NaN
588 snr = numpy.NaN
589 SPC_ch1[:,ht] = 0#numpy.NaN
589 SPC_ch1[:,ht] = 0#numpy.NaN
590 SPC_ch1[:,ht] = 0#numpy.NaN
590 SPC_ch1[:,ht] = 0#numpy.NaN
591 GauSPC = (SPC_ch1,SPC_ch2)
591 GauSPC = (SPC_ch1,SPC_ch2)
592 continue
592 continue
593 #print 'snr',snrdB #, sum(spcs) , tot_noise
593 #print 'snr',snrdB #, sum(spcs) , tot_noise
594
594
595
595
596
596
597 #if snrdB<-18 or numpy.isnan(snrdB) or num_intg<4:
597 #if snrdB<-18 or numpy.isnan(snrdB) or num_intg<4:
598 # return [None,]*4,[None,]*4,None,snrdB,None,None,[None,]*5,[None,]*9,None
598 # return [None,]*4,[None,]*4,None,snrdB,None,None,[None,]*5,[None,]*9,None
599
599
600 cummax=max(cum); epsi=0.08*fatspectra # cumsum to narrow down the energy region
600 cummax=max(cum); epsi=0.08*fatspectra # cumsum to narrow down the energy region
601 cumlo=cummax*epsi;
601 cumlo=cummax*epsi;
602 cumhi=cummax*(1-epsi)
602 cumhi=cummax*(1-epsi)
603 powerindex=numpy.array(numpy.where(numpy.logical_and(cum>cumlo, cum<cumhi))[0])
603 powerindex=numpy.array(numpy.where(numpy.logical_and(cum>cumlo, cum<cumhi))[0])
604
604
605
605
606 if len(powerindex) < 1:# case for powerindex 0
606 if len(powerindex) < 1:# case for powerindex 0
607 continue
607 continue
608 powerlo=powerindex[0]
608 powerlo=powerindex[0]
609 powerhi=powerindex[-1]
609 powerhi=powerindex[-1]
610 powerwidth=powerhi-powerlo
610 powerwidth=powerhi-powerlo
611
611
612 firstpeak=powerlo+powerwidth/10.# first gaussian energy location
612 firstpeak=powerlo+powerwidth/10.# first gaussian energy location
613 secondpeak=powerhi-powerwidth/10.#second gaussian energy location
613 secondpeak=powerhi-powerwidth/10.#second gaussian energy location
614 midpeak=(firstpeak+secondpeak)/2.
614 midpeak=(firstpeak+secondpeak)/2.
615 firstamp=spcs[int(firstpeak)]
615 firstamp=spcs[int(firstpeak)]
616 secondamp=spcs[int(secondpeak)]
616 secondamp=spcs[int(secondpeak)]
617 midamp=spcs[int(midpeak)]
617 midamp=spcs[int(midpeak)]
618
618
619 x=numpy.arange( self.Num_Bin )
619 x=numpy.arange( self.Num_Bin )
620 y_data=spc+wnoise
620 y_data=spc+wnoise
621
621
622 # single gaussian
622 # single gaussian
623 shift0=numpy.mod(midpeak+minx, self.Num_Bin )
623 shift0=numpy.mod(midpeak+minx, self.Num_Bin )
624 width0=powerwidth/4.#Initialization entire power of spectrum divided by 4
624 width0=powerwidth/4.#Initialization entire power of spectrum divided by 4
625 power0=2.
625 power0=2.
626 amplitude0=midamp
626 amplitude0=midamp
627 state0=[shift0,width0,amplitude0,power0,wnoise]
627 state0=[shift0,width0,amplitude0,power0,wnoise]
628 bnds=(( 0,(self.Num_Bin-1) ),(1,powerwidth),(0,None),(0.5,3.),(noisebl,noisebh))
628 bnds=(( 0,(self.Num_Bin-1) ),(1,powerwidth),(0,None),(0.5,3.),(noisebl,noisebh))
629 lsq1=fmin_l_bfgs_b(self.misfit1,state0,args=(y_data,x,num_intg),bounds=bnds,approx_grad=True)
629 lsq1=fmin_l_bfgs_b(self.misfit1,state0,args=(y_data,x,num_intg),bounds=bnds,approx_grad=True)
630
630
631 chiSq1=lsq1[1];
631 chiSq1=lsq1[1];
632 jack1= self.y_jacobian1(x,lsq1[0])
632 jack1= self.y_jacobian1(x,lsq1[0])
633
633
634
634
635 try:
635 try:
636 sigmas1=numpy.sqrt(chiSq1*numpy.diag(numpy.linalg.inv(numpy.dot(jack1.T,jack1))))
636 sigmas1=numpy.sqrt(chiSq1*numpy.diag(numpy.linalg.inv(numpy.dot(jack1.T,jack1))))
637 except:
637 except:
638 std1=32.; sigmas1=numpy.ones(5)
638 std1=32.; sigmas1=numpy.ones(5)
639 else:
639 else:
640 std1=sigmas1[0]
640 std1=sigmas1[0]
641
641
642
642
643 if fatspectra<1.0 and powerwidth<4:
643 if fatspectra<1.0 and powerwidth<4:
644 choice=0
644 choice=0
645 Amplitude0=lsq1[0][2]
645 Amplitude0=lsq1[0][2]
646 shift0=lsq1[0][0]
646 shift0=lsq1[0][0]
647 width0=lsq1[0][1]
647 width0=lsq1[0][1]
648 p0=lsq1[0][3]
648 p0=lsq1[0][3]
649 Amplitude1=0.
649 Amplitude1=0.
650 shift1=0.
650 shift1=0.
651 width1=0.
651 width1=0.
652 p1=0.
652 p1=0.
653 noise=lsq1[0][4]
653 noise=lsq1[0][4]
654 #return (numpy.array([shift0,width0,Amplitude0,p0]),
654 #return (numpy.array([shift0,width0,Amplitude0,p0]),
655 # numpy.array([shift1,width1,Amplitude1,p1]),noise,snrdB,chiSq1,6.,sigmas1,[None,]*9,choice)
655 # numpy.array([shift1,width1,Amplitude1,p1]),noise,snrdB,chiSq1,6.,sigmas1,[None,]*9,choice)
656
656
657 # two gaussians
657 # two gaussians
658 #shift0=numpy.mod(firstpeak+minx,64); shift1=numpy.mod(secondpeak+minx,64)
658 #shift0=numpy.mod(firstpeak+minx,64); shift1=numpy.mod(secondpeak+minx,64)
659 shift0=numpy.mod(firstpeak+minx, self.Num_Bin );
659 shift0=numpy.mod(firstpeak+minx, self.Num_Bin );
660 shift1=numpy.mod(secondpeak+minx, self.Num_Bin )
660 shift1=numpy.mod(secondpeak+minx, self.Num_Bin )
661 width0=powerwidth/6.;
661 width0=powerwidth/6.;
662 width1=width0
662 width1=width0
663 power0=2.;
663 power0=2.;
664 power1=power0
664 power1=power0
665 amplitude0=firstamp;
665 amplitude0=firstamp;
666 amplitude1=secondamp
666 amplitude1=secondamp
667 state0=[shift0,width0,amplitude0,power0,shift1,width1,amplitude1,power1,wnoise]
667 state0=[shift0,width0,amplitude0,power0,shift1,width1,amplitude1,power1,wnoise]
668 #bnds=((0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(noisebl,noisebh))
668 #bnds=((0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(noisebl,noisebh))
669 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))
669 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))
670 #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))
670 #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))
671
671
672 lsq2=fmin_l_bfgs_b(self.misfit2,state0,args=(y_data,x,num_intg),bounds=bnds,approx_grad=True)
672 lsq2=fmin_l_bfgs_b(self.misfit2,state0,args=(y_data,x,num_intg),bounds=bnds,approx_grad=True)
673
673
674
674
675 chiSq2=lsq2[1]; jack2=self.y_jacobian2(x,lsq2[0])
675 chiSq2=lsq2[1]; jack2=self.y_jacobian2(x,lsq2[0])
676
676
677
677
678 try:
678 try:
679 sigmas2=numpy.sqrt(chiSq2*numpy.diag(numpy.linalg.inv(numpy.dot(jack2.T,jack2))))
679 sigmas2=numpy.sqrt(chiSq2*numpy.diag(numpy.linalg.inv(numpy.dot(jack2.T,jack2))))
680 except:
680 except:
681 std2a=32.; std2b=32.; sigmas2=numpy.ones(9)
681 std2a=32.; std2b=32.; sigmas2=numpy.ones(9)
682 else:
682 else:
683 std2a=sigmas2[0]; std2b=sigmas2[4]
683 std2a=sigmas2[0]; std2b=sigmas2[4]
684
684
685
685
686
686
687 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)
687 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)
688
688
689 if snrdB>-6: # when SNR is strong pick the peak with least shift (LOS velocity) error
689 if snrdB>-6: # when SNR is strong pick the peak with least shift (LOS velocity) error
690 if oneG:
690 if oneG:
691 choice=0
691 choice=0
692 else:
692 else:
693 w1=lsq2[0][1]; w2=lsq2[0][5]
693 w1=lsq2[0][1]; w2=lsq2[0][5]
694 a1=lsq2[0][2]; a2=lsq2[0][6]
694 a1=lsq2[0][2]; a2=lsq2[0][6]
695 p1=lsq2[0][3]; p2=lsq2[0][7]
695 p1=lsq2[0][3]; p2=lsq2[0][7]
696 s1=(2**(1+1./p1))*scipy.special.gamma(1./p1)/p1;
696 s1=(2**(1+1./p1))*scipy.special.gamma(1./p1)/p1;
697 s2=(2**(1+1./p2))*scipy.special.gamma(1./p2)/p2;
697 s2=(2**(1+1./p2))*scipy.special.gamma(1./p2)/p2;
698 gp1=a1*w1*s1; gp2=a2*w2*s2 # power content of each ggaussian with proper p scaling
698 gp1=a1*w1*s1; gp2=a2*w2*s2 # power content of each ggaussian with proper p scaling
699
699
700 if gp1>gp2:
700 if gp1>gp2:
701 if a1>0.7*a2:
701 if a1>0.7*a2:
702 choice=1
702 choice=1
703 else:
703 else:
704 choice=2
704 choice=2
705 elif gp2>gp1:
705 elif gp2>gp1:
706 if a2>0.7*a1:
706 if a2>0.7*a1:
707 choice=2
707 choice=2
708 else:
708 else:
709 choice=1
709 choice=1
710 else:
710 else:
711 choice=numpy.argmax([a1,a2])+1
711 choice=numpy.argmax([a1,a2])+1
712 #else:
712 #else:
713 #choice=argmin([std2a,std2b])+1
713 #choice=argmin([std2a,std2b])+1
714
714
715 else: # with low SNR go to the most energetic peak
715 else: # with low SNR go to the most energetic peak
716 choice=numpy.argmax([lsq1[0][2]*lsq1[0][1],lsq2[0][2]*lsq2[0][1],lsq2[0][6]*lsq2[0][5]])
716 choice=numpy.argmax([lsq1[0][2]*lsq1[0][1],lsq2[0][2]*lsq2[0][1],lsq2[0][6]*lsq2[0][5]])
717
717
718
718
719 shift0=lsq2[0][0]; vel0=Vrange[0] + shift0*(Vrange[1]-Vrange[0])
719 shift0=lsq2[0][0]; vel0=Vrange[0] + shift0*(Vrange[1]-Vrange[0])
720 shift1=lsq2[0][4]; vel1=Vrange[0] + shift1*(Vrange[1]-Vrange[0])
720 shift1=lsq2[0][4]; vel1=Vrange[0] + shift1*(Vrange[1]-Vrange[0])
721
721
722 max_vel = 20
722 max_vel = 20
723
723
724 #first peak will be 0, second peak will be 1
724 #first peak will be 0, second peak will be 1
725 if vel0 > 0 and vel0 < max_vel : #first peak is in the correct range
725 if vel0 > 0 and vel0 < max_vel : #first peak is in the correct range
726 shift0=lsq2[0][0]
726 shift0=lsq2[0][0]
727 width0=lsq2[0][1]
727 width0=lsq2[0][1]
728 Amplitude0=lsq2[0][2]
728 Amplitude0=lsq2[0][2]
729 p0=lsq2[0][3]
729 p0=lsq2[0][3]
730
730
731 shift1=lsq2[0][4]
731 shift1=lsq2[0][4]
732 width1=lsq2[0][5]
732 width1=lsq2[0][5]
733 Amplitude1=lsq2[0][6]
733 Amplitude1=lsq2[0][6]
734 p1=lsq2[0][7]
734 p1=lsq2[0][7]
735 noise=lsq2[0][8]
735 noise=lsq2[0][8]
736 else:
736 else:
737 shift1=lsq2[0][0]
737 shift1=lsq2[0][0]
738 width1=lsq2[0][1]
738 width1=lsq2[0][1]
739 Amplitude1=lsq2[0][2]
739 Amplitude1=lsq2[0][2]
740 p1=lsq2[0][3]
740 p1=lsq2[0][3]
741
741
742 shift0=lsq2[0][4]
742 shift0=lsq2[0][4]
743 width0=lsq2[0][5]
743 width0=lsq2[0][5]
744 Amplitude0=lsq2[0][6]
744 Amplitude0=lsq2[0][6]
745 p0=lsq2[0][7]
745 p0=lsq2[0][7]
746 noise=lsq2[0][8]
746 noise=lsq2[0][8]
747
747
748 if Amplitude0<0.1: # in case the peak is noise
748 if Amplitude0<0.1: # in case the peak is noise
749 shift0,width0,Amplitude0,p0 = 4*[numpy.NaN]
749 shift0,width0,Amplitude0,p0 = 4*[numpy.NaN]
750 if Amplitude1<0.1:
750 if Amplitude1<0.1:
751 shift1,width1,Amplitude1,p1 = 4*[numpy.NaN]
751 shift1,width1,Amplitude1,p1 = 4*[numpy.NaN]
752
752
753
753
754 # if choice==0: # pick the single gaussian fit
754 # if choice==0: # pick the single gaussian fit
755 # Amplitude0=lsq1[0][2]
755 # Amplitude0=lsq1[0][2]
756 # shift0=lsq1[0][0]
756 # shift0=lsq1[0][0]
757 # width0=lsq1[0][1]
757 # width0=lsq1[0][1]
758 # p0=lsq1[0][3]
758 # p0=lsq1[0][3]
759 # Amplitude1=0.
759 # Amplitude1=0.
760 # shift1=0.
760 # shift1=0.
761 # width1=0.
761 # width1=0.
762 # p1=0.
762 # p1=0.
763 # noise=lsq1[0][4]
763 # noise=lsq1[0][4]
764 # elif choice==1: # take the first one of the 2 gaussians fitted
764 # elif choice==1: # take the first one of the 2 gaussians fitted
765 # Amplitude0 = lsq2[0][2]
765 # Amplitude0 = lsq2[0][2]
766 # shift0 = lsq2[0][0]
766 # shift0 = lsq2[0][0]
767 # width0 = lsq2[0][1]
767 # width0 = lsq2[0][1]
768 # p0 = lsq2[0][3]
768 # p0 = lsq2[0][3]
769 # Amplitude1 = lsq2[0][6] # This is 0 in gg1
769 # Amplitude1 = lsq2[0][6] # This is 0 in gg1
770 # shift1 = lsq2[0][4] # This is 0 in gg1
770 # shift1 = lsq2[0][4] # This is 0 in gg1
771 # width1 = lsq2[0][5] # This is 0 in gg1
771 # width1 = lsq2[0][5] # This is 0 in gg1
772 # p1 = lsq2[0][7] # This is 0 in gg1
772 # p1 = lsq2[0][7] # This is 0 in gg1
773 # noise = lsq2[0][8]
773 # noise = lsq2[0][8]
774 # else: # the second one
774 # else: # the second one
775 # Amplitude0 = lsq2[0][6]
775 # Amplitude0 = lsq2[0][6]
776 # shift0 = lsq2[0][4]
776 # shift0 = lsq2[0][4]
777 # width0 = lsq2[0][5]
777 # width0 = lsq2[0][5]
778 # p0 = lsq2[0][7]
778 # p0 = lsq2[0][7]
779 # Amplitude1 = lsq2[0][2] # This is 0 in gg1
779 # Amplitude1 = lsq2[0][2] # This is 0 in gg1
780 # shift1 = lsq2[0][0] # This is 0 in gg1
780 # shift1 = lsq2[0][0] # This is 0 in gg1
781 # width1 = lsq2[0][1] # This is 0 in gg1
781 # width1 = lsq2[0][1] # This is 0 in gg1
782 # p1 = lsq2[0][3] # This is 0 in gg1
782 # p1 = lsq2[0][3] # This is 0 in gg1
783 # noise = lsq2[0][8]
783 # noise = lsq2[0][8]
784
784
785 #print len(noise + Amplitude0*numpy.exp(-0.5*(abs(x-shift0))/width0)**p0)
785 #print len(noise + Amplitude0*numpy.exp(-0.5*(abs(x-shift0))/width0)**p0)
786 SPC_ch1[:,ht] = noise + Amplitude0*numpy.exp(-0.5*(abs(x-shift0))/width0)**p0
786 SPC_ch1[:,ht] = noise + Amplitude0*numpy.exp(-0.5*(abs(x-shift0))/width0)**p0
787 SPC_ch2[:,ht] = noise + Amplitude1*numpy.exp(-0.5*(abs(x-shift1))/width1)**p1
787 SPC_ch2[:,ht] = noise + Amplitude1*numpy.exp(-0.5*(abs(x-shift1))/width1)**p1
788 #print 'SPC_ch1.shape',SPC_ch1.shape
788 #print 'SPC_ch1.shape',SPC_ch1.shape
789 #print 'SPC_ch2.shape',SPC_ch2.shape
789 #print 'SPC_ch2.shape',SPC_ch2.shape
790 #dataOut.data_param = SPC_ch1
790 #dataOut.data_param = SPC_ch1
791 GauSPC = (SPC_ch1,SPC_ch2)
791 GauSPC = (SPC_ch1,SPC_ch2)
792 #GauSPC[1] = SPC_ch2
792 #GauSPC[1] = SPC_ch2
793
793
794 # print 'shift0', shift0
794 # print 'shift0', shift0
795 # print 'Amplitude0', Amplitude0
795 # print 'Amplitude0', Amplitude0
796 # print 'width0', width0
796 # print 'width0', width0
797 # print 'p0', p0
797 # print 'p0', p0
798 # print '========================'
798 # print '========================'
799 # print 'shift1', shift1
799 # print 'shift1', shift1
800 # print 'Amplitude1', Amplitude1
800 # print 'Amplitude1', Amplitude1
801 # print 'width1', width1
801 # print 'width1', width1
802 # print 'p1', p1
802 # print 'p1', p1
803 # print 'noise', noise
803 # print 'noise', noise
804 # print 's_noise', wnoise
804 # print 's_noise', wnoise
805
805
806 return GauSPC
806 return GauSPC
807
807
808
808
809 def y_jacobian1(self,x,state): # This function is for further analysis of generalized Gaussians, it is not too importan for the signal discrimination.
809 def y_jacobian1(self,x,state): # This function is for further analysis of generalized Gaussians, it is not too importan for the signal discrimination.
810 y_model=self.y_model1(x,state)
810 y_model=self.y_model1(x,state)
811 s0,w0,a0,p0,n=state
811 s0,w0,a0,p0,n=state
812 e0=((x-s0)/w0)**2;
812 e0=((x-s0)/w0)**2;
813
813
814 e0u=((x-s0-self.Num_Bin)/w0)**2;
814 e0u=((x-s0-self.Num_Bin)/w0)**2;
815
815
816 e0d=((x-s0+self.Num_Bin)/w0)**2
816 e0d=((x-s0+self.Num_Bin)/w0)**2
817 m0=numpy.exp(-0.5*e0**(p0/2.));
817 m0=numpy.exp(-0.5*e0**(p0/2.));
818 m0u=numpy.exp(-0.5*e0u**(p0/2.));
818 m0u=numpy.exp(-0.5*e0u**(p0/2.));
819 m0d=numpy.exp(-0.5*e0d**(p0/2.))
819 m0d=numpy.exp(-0.5*e0d**(p0/2.))
820 JA=m0+m0u+m0d
820 JA=m0+m0u+m0d
821 JP=(-1/4.)*a0*m0*e0**(p0/2.)*numpy.log(e0)+(-1/4.)*a0*m0u*e0u**(p0/2.)*numpy.log(e0u)+(-1/4.)*a0*m0d*e0d**(p0/2.)*numpy.log(e0d)
821 JP=(-1/4.)*a0*m0*e0**(p0/2.)*numpy.log(e0)+(-1/4.)*a0*m0u*e0u**(p0/2.)*numpy.log(e0u)+(-1/4.)*a0*m0d*e0d**(p0/2.)*numpy.log(e0d)
822
822
823 JS=(p0/w0/2.)*a0*m0*e0**(p0/2.-1)*((x-s0)/w0)+(p0/w0/2.)*a0*m0u*e0u**(p0/2.-1)*((x-s0- self.Num_Bin )/w0)+(p0/w0/2.)*a0*m0d*e0d**(p0/2.-1)*((x-s0+ self.Num_Bin )/w0)
823 JS=(p0/w0/2.)*a0*m0*e0**(p0/2.-1)*((x-s0)/w0)+(p0/w0/2.)*a0*m0u*e0u**(p0/2.-1)*((x-s0- self.Num_Bin )/w0)+(p0/w0/2.)*a0*m0d*e0d**(p0/2.-1)*((x-s0+ self.Num_Bin )/w0)
824
824
825 JW=(p0/w0/2.)*a0*m0*e0**(p0/2.-1)*((x-s0)/w0)**2+(p0/w0/2.)*a0*m0u*e0u**(p0/2.-1)*((x-s0- self.Num_Bin )/w0)**2+(p0/w0/2.)*a0*m0d*e0d**(p0/2.-1)*((x-s0+ self.Num_Bin )/w0)**2
825 JW=(p0/w0/2.)*a0*m0*e0**(p0/2.-1)*((x-s0)/w0)**2+(p0/w0/2.)*a0*m0u*e0u**(p0/2.-1)*((x-s0- self.Num_Bin )/w0)**2+(p0/w0/2.)*a0*m0d*e0d**(p0/2.-1)*((x-s0+ self.Num_Bin )/w0)**2
826 jack1=numpy.sqrt(7)*numpy.array([JS/y_model,JW/y_model,JA/y_model,JP/y_model,1./y_model])
826 jack1=numpy.sqrt(7)*numpy.array([JS/y_model,JW/y_model,JA/y_model,JP/y_model,1./y_model])
827 return jack1.T
827 return jack1.T
828
828
829 def y_jacobian2(self,x,state):
829 def y_jacobian2(self,x,state):
830 y_model=self.y_model2(x,state)
830 y_model=self.y_model2(x,state)
831 s0,w0,a0,p0,s1,w1,a1,p1,n=state
831 s0,w0,a0,p0,s1,w1,a1,p1,n=state
832 e0=((x-s0)/w0)**2;
832 e0=((x-s0)/w0)**2;
833
833
834 e0u=((x-s0- self.Num_Bin )/w0)**2;
834 e0u=((x-s0- self.Num_Bin )/w0)**2;
835
835
836 e0d=((x-s0+ self.Num_Bin )/w0)**2
836 e0d=((x-s0+ self.Num_Bin )/w0)**2
837 e1=((x-s1)/w1)**2;
837 e1=((x-s1)/w1)**2;
838
838
839 e1u=((x-s1- self.Num_Bin )/w1)**2;
839 e1u=((x-s1- self.Num_Bin )/w1)**2;
840
840
841 e1d=((x-s1+ self.Num_Bin )/w1)**2
841 e1d=((x-s1+ self.Num_Bin )/w1)**2
842 m0=numpy.exp(-0.5*e0**(p0/2.));
842 m0=numpy.exp(-0.5*e0**(p0/2.));
843 m0u=numpy.exp(-0.5*e0u**(p0/2.));
843 m0u=numpy.exp(-0.5*e0u**(p0/2.));
844 m0d=numpy.exp(-0.5*e0d**(p0/2.))
844 m0d=numpy.exp(-0.5*e0d**(p0/2.))
845 m1=numpy.exp(-0.5*e1**(p1/2.));
845 m1=numpy.exp(-0.5*e1**(p1/2.));
846 m1u=numpy.exp(-0.5*e1u**(p1/2.));
846 m1u=numpy.exp(-0.5*e1u**(p1/2.));
847 m1d=numpy.exp(-0.5*e1d**(p1/2.))
847 m1d=numpy.exp(-0.5*e1d**(p1/2.))
848 JA=m0+m0u+m0d
848 JA=m0+m0u+m0d
849 JA1=m1+m1u+m1d
849 JA1=m1+m1u+m1d
850 JP=(-1/4.)*a0*m0*e0**(p0/2.)*numpy.log(e0)+(-1/4.)*a0*m0u*e0u**(p0/2.)*numpy.log(e0u)+(-1/4.)*a0*m0d*e0d**(p0/2.)*numpy.log(e0d)
850 JP=(-1/4.)*a0*m0*e0**(p0/2.)*numpy.log(e0)+(-1/4.)*a0*m0u*e0u**(p0/2.)*numpy.log(e0u)+(-1/4.)*a0*m0d*e0d**(p0/2.)*numpy.log(e0d)
851 JP1=(-1/4.)*a1*m1*e1**(p1/2.)*numpy.log(e1)+(-1/4.)*a1*m1u*e1u**(p1/2.)*numpy.log(e1u)+(-1/4.)*a1*m1d*e1d**(p1/2.)*numpy.log(e1d)
851 JP1=(-1/4.)*a1*m1*e1**(p1/2.)*numpy.log(e1)+(-1/4.)*a1*m1u*e1u**(p1/2.)*numpy.log(e1u)+(-1/4.)*a1*m1d*e1d**(p1/2.)*numpy.log(e1d)
852
852
853 JS=(p0/w0/2.)*a0*m0*e0**(p0/2.-1)*((x-s0)/w0)+(p0/w0/2.)*a0*m0u*e0u**(p0/2.-1)*((x-s0- self.Num_Bin )/w0)+(p0/w0/2.)*a0*m0d*e0d**(p0/2.-1)*((x-s0+ self.Num_Bin )/w0)
853 JS=(p0/w0/2.)*a0*m0*e0**(p0/2.-1)*((x-s0)/w0)+(p0/w0/2.)*a0*m0u*e0u**(p0/2.-1)*((x-s0- self.Num_Bin )/w0)+(p0/w0/2.)*a0*m0d*e0d**(p0/2.-1)*((x-s0+ self.Num_Bin )/w0)
854
854
855 JS1=(p1/w1/2.)*a1*m1*e1**(p1/2.-1)*((x-s1)/w1)+(p1/w1/2.)*a1*m1u*e1u**(p1/2.-1)*((x-s1- self.Num_Bin )/w1)+(p1/w1/2.)*a1*m1d*e1d**(p1/2.-1)*((x-s1+ self.Num_Bin )/w1)
855 JS1=(p1/w1/2.)*a1*m1*e1**(p1/2.-1)*((x-s1)/w1)+(p1/w1/2.)*a1*m1u*e1u**(p1/2.-1)*((x-s1- self.Num_Bin )/w1)+(p1/w1/2.)*a1*m1d*e1d**(p1/2.-1)*((x-s1+ self.Num_Bin )/w1)
856
856
857 JW=(p0/w0/2.)*a0*m0*e0**(p0/2.-1)*((x-s0)/w0)**2+(p0/w0/2.)*a0*m0u*e0u**(p0/2.-1)*((x-s0- self.Num_Bin )/w0)**2+(p0/w0/2.)*a0*m0d*e0d**(p0/2.-1)*((x-s0+ self.Num_Bin )/w0)**2
857 JW=(p0/w0/2.)*a0*m0*e0**(p0/2.-1)*((x-s0)/w0)**2+(p0/w0/2.)*a0*m0u*e0u**(p0/2.-1)*((x-s0- self.Num_Bin )/w0)**2+(p0/w0/2.)*a0*m0d*e0d**(p0/2.-1)*((x-s0+ self.Num_Bin )/w0)**2
858
858
859 JW1=(p1/w1/2.)*a1*m1*e1**(p1/2.-1)*((x-s1)/w1)**2+(p1/w1/2.)*a1*m1u*e1u**(p1/2.-1)*((x-s1- self.Num_Bin )/w1)**2+(p1/w1/2.)*a1*m1d*e1d**(p1/2.-1)*((x-s1+ self.Num_Bin )/w1)**2
859 JW1=(p1/w1/2.)*a1*m1*e1**(p1/2.-1)*((x-s1)/w1)**2+(p1/w1/2.)*a1*m1u*e1u**(p1/2.-1)*((x-s1- self.Num_Bin )/w1)**2+(p1/w1/2.)*a1*m1d*e1d**(p1/2.-1)*((x-s1+ self.Num_Bin )/w1)**2
860 jack2=numpy.sqrt(7)*numpy.array([JS/y_model,JW/y_model,JA/y_model,JP/y_model,JS1/y_model,JW1/y_model,JA1/y_model,JP1/y_model,1./y_model])
860 jack2=numpy.sqrt(7)*numpy.array([JS/y_model,JW/y_model,JA/y_model,JP/y_model,JS1/y_model,JW1/y_model,JA1/y_model,JP1/y_model,1./y_model])
861 return jack2.T
861 return jack2.T
862
862
863 def y_model1(self,x,state):
863 def y_model1(self,x,state):
864 shift0,width0,amplitude0,power0,noise=state
864 shift0,width0,amplitude0,power0,noise=state
865 model0=amplitude0*numpy.exp(-0.5*abs((x-shift0)/width0)**power0)
865 model0=amplitude0*numpy.exp(-0.5*abs((x-shift0)/width0)**power0)
866
866
867 model0u=amplitude0*numpy.exp(-0.5*abs((x-shift0- self.Num_Bin )/width0)**power0)
867 model0u=amplitude0*numpy.exp(-0.5*abs((x-shift0- self.Num_Bin )/width0)**power0)
868
868
869 model0d=amplitude0*numpy.exp(-0.5*abs((x-shift0+ self.Num_Bin )/width0)**power0)
869 model0d=amplitude0*numpy.exp(-0.5*abs((x-shift0+ self.Num_Bin )/width0)**power0)
870 return model0+model0u+model0d+noise
870 return model0+model0u+model0d+noise
871
871
872 def y_model2(self,x,state): #Equation for two generalized Gaussians with Nyquist
872 def y_model2(self,x,state): #Equation for two generalized Gaussians with Nyquist
873 shift0,width0,amplitude0,power0,shift1,width1,amplitude1,power1,noise=state
873 shift0,width0,amplitude0,power0,shift1,width1,amplitude1,power1,noise=state
874 model0=amplitude0*numpy.exp(-0.5*abs((x-shift0)/width0)**power0)
874 model0=amplitude0*numpy.exp(-0.5*abs((x-shift0)/width0)**power0)
875
875
876 model0u=amplitude0*numpy.exp(-0.5*abs((x-shift0- self.Num_Bin )/width0)**power0)
876 model0u=amplitude0*numpy.exp(-0.5*abs((x-shift0- self.Num_Bin )/width0)**power0)
877
877
878 model0d=amplitude0*numpy.exp(-0.5*abs((x-shift0+ self.Num_Bin )/width0)**power0)
878 model0d=amplitude0*numpy.exp(-0.5*abs((x-shift0+ self.Num_Bin )/width0)**power0)
879 model1=amplitude1*numpy.exp(-0.5*abs((x-shift1)/width1)**power1)
879 model1=amplitude1*numpy.exp(-0.5*abs((x-shift1)/width1)**power1)
880
880
881 model1u=amplitude1*numpy.exp(-0.5*abs((x-shift1- self.Num_Bin )/width1)**power1)
881 model1u=amplitude1*numpy.exp(-0.5*abs((x-shift1- self.Num_Bin )/width1)**power1)
882
882
883 model1d=amplitude1*numpy.exp(-0.5*abs((x-shift1+ self.Num_Bin )/width1)**power1)
883 model1d=amplitude1*numpy.exp(-0.5*abs((x-shift1+ self.Num_Bin )/width1)**power1)
884 return model0+model0u+model0d+model1+model1u+model1d+noise
884 return model0+model0u+model0d+model1+model1u+model1d+noise
885
885
886 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.
886 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.
887
887
888 return num_intg*sum((numpy.log(y_data)-numpy.log(self.y_model1(x,state)))**2)#/(64-5.) # /(64-5.) can be commented
888 return num_intg*sum((numpy.log(y_data)-numpy.log(self.y_model1(x,state)))**2)#/(64-5.) # /(64-5.) can be commented
889
889
890 def misfit2(self,state,y_data,x,num_intg):
890 def misfit2(self,state,y_data,x,num_intg):
891 return num_intg*sum((numpy.log(y_data)-numpy.log(self.y_model2(x,state)))**2)#/(64-9.)
891 return num_intg*sum((numpy.log(y_data)-numpy.log(self.y_model2(x,state)))**2)#/(64-9.)
892
892
893
893
894 class PrecipitationProc(Operation):
894 class PrecipitationProc(Operation):
895
895
896 '''
896 '''
897 Operator that estimates Reflectivity factor (Z), and estimates rainfall Rate (R)
897 Operator that estimates Reflectivity factor (Z), and estimates rainfall Rate (R)
898
898
899 Input:
899 Input:
900 self.dataOut.data_pre : SelfSpectra
900 self.dataOut.data_pre : SelfSpectra
901
901
902 Output:
902 Output:
903
903
904 self.dataOut.data_output : Reflectivity factor, rainfall Rate
904 self.dataOut.data_output : Reflectivity factor, rainfall Rate
905
905
906
906
907 Parameters affected:
907 Parameters affected:
908 '''
908 '''
909
909
910
910
911 def run(self, dataOut, radar=None, Pt=None, Gt=None, Gr=None, Lambda=None, aL=None,
911 def run(self, dataOut, radar=None, Pt=None, Gt=None, Gr=None, Lambda=None, aL=None,
912 tauW=None, ThetaT=None, ThetaR=None, Km = 0.93, Altitude=None):
912 tauW=None, ThetaT=None, ThetaR=None, Km = 0.93, Altitude=None):
913
913
914 self.spc = dataOut.data_pre[0].copy()
914 self.spc = dataOut.data_pre[0].copy()
915 self.Num_Hei = self.spc.shape[2]
915 self.Num_Hei = self.spc.shape[2]
916 self.Num_Bin = self.spc.shape[1]
916 self.Num_Bin = self.spc.shape[1]
917 self.Num_Chn = self.spc.shape[0]
917 self.Num_Chn = self.spc.shape[0]
918
918
919 Velrange = dataOut.abscissaList
919 Velrange = dataOut.abscissaList
920
920
921 if radar == "MIRA35C" :
921 if radar == "MIRA35C" :
922
922
923 Ze = self.dBZeMODE2(dataOut)
923 Ze = self.dBZeMODE2(dataOut)
924
924
925 else:
925 else:
926
926
927 self.Pt = Pt
927 self.Pt = Pt
928 self.Gt = Gt
928 self.Gt = Gt
929 self.Gr = Gr
929 self.Gr = Gr
930 self.Lambda = Lambda
930 self.Lambda = Lambda
931 self.aL = aL
931 self.aL = aL
932 self.tauW = tauW
932 self.tauW = tauW
933 self.ThetaT = ThetaT
933 self.ThetaT = ThetaT
934 self.ThetaR = ThetaR
934 self.ThetaR = ThetaR
935
935
936 RadarConstant = GetRadarConstant()
936 RadarConstant = GetRadarConstant()
937 SPCmean = numpy.mean(self.spc,0)
937 SPCmean = numpy.mean(self.spc,0)
938 ETA = numpy.zeros(self.Num_Hei)
938 ETA = numpy.zeros(self.Num_Hei)
939 Pr = numpy.sum(SPCmean,0)
939 Pr = numpy.sum(SPCmean,0)
940
940
941 #for R in range(self.Num_Hei):
941 #for R in range(self.Num_Hei):
942 # ETA[R] = RadarConstant * Pr[R] * R**2 #Reflectivity (ETA)
942 # ETA[R] = RadarConstant * Pr[R] * R**2 #Reflectivity (ETA)
943
943
944 D_range = numpy.zeros(self.Num_Hei)
944 D_range = numpy.zeros(self.Num_Hei)
945 EqSec = numpy.zeros(self.Num_Hei)
945 EqSec = numpy.zeros(self.Num_Hei)
946 del_V = numpy.zeros(self.Num_Hei)
946 del_V = numpy.zeros(self.Num_Hei)
947
947
948 for R in range(self.Num_Hei):
948 for R in range(self.Num_Hei):
949 ETA[R] = RadarConstant * Pr[R] * R**2 #Reflectivity (ETA)
949 ETA[R] = RadarConstant * Pr[R] * R**2 #Reflectivity (ETA)
950
950
951 h = R + Altitude #Range from ground to radar pulse altitude
951 h = R + Altitude #Range from ground to radar pulse altitude
952 del_V[R] = 1 + 3.68 * 10**-5 * h + 1.71 * 10**-9 * h**2 #Density change correction for velocity
952 del_V[R] = 1 + 3.68 * 10**-5 * h + 1.71 * 10**-9 * h**2 #Density change correction for velocity
953
953
954 D_range[R] = numpy.log( (9.65 - (Velrange[R]/del_V[R])) / 10.3 ) / -0.6 #Range of Diameter of drops related to velocity
954 D_range[R] = numpy.log( (9.65 - (Velrange[R]/del_V[R])) / 10.3 ) / -0.6 #Range of Diameter of drops related to velocity
955 SIGMA[R] = numpy.pi**5 / Lambda**4 * Km * D_range[R]**6 #Equivalent Section of drops (sigma)
955 SIGMA[R] = numpy.pi**5 / Lambda**4 * Km * D_range[R]**6 #Equivalent Section of drops (sigma)
956
956
957 N_dist[R] = ETA[R] / SIGMA[R]
957 N_dist[R] = ETA[R] / SIGMA[R]
958
958
959 Ze = (ETA * Lambda**4) / (numpy.pi * Km)
959 Ze = (ETA * Lambda**4) / (numpy.pi * Km)
960 Z = numpy.sum( N_dist * D_range**6 )
960 Z = numpy.sum( N_dist * D_range**6 )
961 RR = 6*10**-4*numpy.pi * numpy.sum( D_range**3 * N_dist * Velrange ) #Rainfall rate
961 RR = 6*10**-4*numpy.pi * numpy.sum( D_range**3 * N_dist * Velrange ) #Rainfall rate
962
962
963
963
964 RR = (Ze/200)**(1/1.6)
964 RR = (Ze/200)**(1/1.6)
965 dBRR = 10*numpy.log10(RR)
965 dBRR = 10*numpy.log10(RR)
966
966
967 dBZe = 10*numpy.log10(Ze)
967 dBZe = 10*numpy.log10(Ze)
968 dataOut.data_output = Ze
968 dataOut.data_output = Ze
969 dataOut.data_param = numpy.ones([2,self.Num_Hei])
969 dataOut.data_param = numpy.ones([2,self.Num_Hei])
970 dataOut.channelList = [0,1]
970 dataOut.channelList = [0,1]
971 print 'channelList', dataOut.channelList
971 print 'channelList', dataOut.channelList
972 dataOut.data_param[0]=dBZe
972 dataOut.data_param[0]=dBZe
973 dataOut.data_param[1]=dBRR
973 dataOut.data_param[1]=dBRR
974 print 'RR SHAPE', dBRR.shape
974 print 'RR SHAPE', dBRR.shape
975 print 'Ze SHAPE', dBZe.shape
975 print 'Ze SHAPE', dBZe.shape
976 print 'dataOut.data_param SHAPE', dataOut.data_param.shape
976 print 'dataOut.data_param SHAPE', dataOut.data_param.shape
977
977
978
978
979 def dBZeMODE2(self, dataOut): # Processing for MIRA35C
979 def dBZeMODE2(self, dataOut): # Processing for MIRA35C
980
980
981 NPW = dataOut.NPW
981 NPW = dataOut.NPW
982 COFA = dataOut.COFA
982 COFA = dataOut.COFA
983
983
984 SNR = numpy.array([self.spc[0,:,:] / NPW[0]]) #, self.spc[1,:,:] / NPW[1]])
984 SNR = numpy.array([self.spc[0,:,:] / NPW[0]]) #, self.spc[1,:,:] / NPW[1]])
985 RadarConst = dataOut.RadarConst
985 RadarConst = dataOut.RadarConst
986 #frequency = 34.85*10**9
986 #frequency = 34.85*10**9
987
987
988 ETA = numpy.zeros(([self.Num_Chn ,self.Num_Hei]))
988 ETA = numpy.zeros(([self.Num_Chn ,self.Num_Hei]))
989 data_output = numpy.ones([self.Num_Chn , self.Num_Hei])*numpy.NaN
989 data_output = numpy.ones([self.Num_Chn , self.Num_Hei])*numpy.NaN
990
990
991 ETA = numpy.sum(SNR,1)
991 ETA = numpy.sum(SNR,1)
992 print 'ETA' , ETA
992 print 'ETA' , ETA
993 ETA = numpy.where(ETA is not 0. , ETA, numpy.NaN)
993 ETA = numpy.where(ETA is not 0. , ETA, numpy.NaN)
994
994
995 Ze = numpy.ones([self.Num_Chn, self.Num_Hei] )
995 Ze = numpy.ones([self.Num_Chn, self.Num_Hei] )
996
996
997 for r in range(self.Num_Hei):
997 for r in range(self.Num_Hei):
998
998
999 Ze[0,r] = ( ETA[0,r] ) * COFA[0,r][0] * RadarConst * ((r/5000.)**2)
999 Ze[0,r] = ( ETA[0,r] ) * COFA[0,r][0] * RadarConst * ((r/5000.)**2)
1000 #Ze[1,r] = ( ETA[1,r] ) * COFA[1,r][0] * RadarConst * ((r/5000.)**2)
1000 #Ze[1,r] = ( ETA[1,r] ) * COFA[1,r][0] * RadarConst * ((r/5000.)**2)
1001
1001
1002 return Ze
1002 return Ze
1003
1003
1004 def GetRadarConstant(self):
1004 def GetRadarConstant(self):
1005
1005
1006 """
1006 """
1007 Constants:
1007 Constants:
1008
1008
1009 Pt: Transmission Power dB
1009 Pt: Transmission Power dB 5kW
1010 Gt: Transmission Gain dB
1010 Gt: Transmission Gain dB 24.7 dB
1011 Gr: Reception Gain dB
1011 Gr: Reception Gain dB 18.5 dB
1012 Lambda: Wavelenght m
1012 Lambda: Wavelenght m 0.6741 m
1013 aL: Attenuation loses dB
1013 aL: Attenuation loses dB
1014 tauW: Width of transmission pulse s
1014 tauW: Width of transmission pulse s
1015 ThetaT: Transmission antenna bean angle rad
1015 ThetaT: Transmission antenna bean angle rad 0.1656317 rad
1016 ThetaR: Reception antenna beam angle rad
1016 ThetaR: Reception antenna beam angle rad 0.36774087 rad
1017
1017
1018 """
1018 """
1019 Numerator = ( (4*numpy.pi)**3 * aL**2 * 16 * numpy.log(2) )
1019 Numerator = ( (4*numpy.pi)**3 * aL**2 * 16 * numpy.log(2) )
1020 Denominator = ( Pt * Gt * Gr * Lambda**2 * SPEED_OF_LIGHT * TauW * numpy.pi * ThetaT * TheraR)
1020 Denominator = ( Pt * Gt * Gr * Lambda**2 * SPEED_OF_LIGHT * TauW * numpy.pi * ThetaT * TheraR)
1021 RadarConstant = Numerator / Denominator
1021 RadarConstant = Numerator / Denominator
1022
1022
1023 return RadarConstant
1023 return RadarConstant
1024
1024
1025
1025
1026
1026
1027 class FullSpectralAnalysis(Operation):
1027 class FullSpectralAnalysis(Operation):
1028
1028
1029 """
1029 """
1030 Function that implements Full Spectral Analisys technique.
1030 Function that implements Full Spectral Analisys technique.
1031
1031
1032 Input:
1032 Input:
1033 self.dataOut.data_pre : SelfSpectra and CrossSPectra data
1033 self.dataOut.data_pre : SelfSpectra and CrossSPectra data
1034 self.dataOut.groupList : Pairlist of channels
1034 self.dataOut.groupList : Pairlist of channels
1035 self.dataOut.ChanDist : Physical distance between receivers
1035 self.dataOut.ChanDist : Physical distance between receivers
1036
1036
1037
1037
1038 Output:
1038 Output:
1039
1039
1040 self.dataOut.data_output : Zonal wind, Meridional wind and Vertical wind
1040 self.dataOut.data_output : Zonal wind, Meridional wind and Vertical wind
1041
1041
1042
1042
1043 Parameters affected: Winds, height range, SNR
1043 Parameters affected: Winds, height range, SNR
1044
1044
1045 """
1045 """
1046 def run(self, dataOut, E01=None, E02=None, E12=None, N01=None, N02=None, N12=None, SNRlimit=7):
1046 def run(self, dataOut, E01=None, E02=None, E12=None, N01=None, N02=None, N12=None, SNRlimit=7):
1047
1047
1048 spc = dataOut.data_pre[0].copy()
1048 spc = dataOut.data_pre[0].copy()
1049 cspc = dataOut.data_pre[1].copy()
1049 cspc = dataOut.data_pre[1].copy()
1050
1050
1051 nChannel = spc.shape[0]
1051 nChannel = spc.shape[0]
1052 nProfiles = spc.shape[1]
1052 nProfiles = spc.shape[1]
1053 nHeights = spc.shape[2]
1053 nHeights = spc.shape[2]
1054
1054
1055 pairsList = dataOut.groupList
1055 pairsList = dataOut.groupList
1056 if dataOut.ChanDist is not None :
1056 if dataOut.ChanDist is not None :
1057 ChanDist = dataOut.ChanDist
1057 ChanDist = dataOut.ChanDist
1058 else:
1058 else:
1059 ChanDist = numpy.array([[E01, N01],[E02,N02],[E12,N12]])
1059 ChanDist = numpy.array([[E01, N01],[E02,N02],[E12,N12]])
1060
1060
1061 #print 'ChanDist', ChanDist
1061 #print 'ChanDist', ChanDist
1062
1062
1063 if dataOut.VelRange is not None:
1063 if dataOut.VelRange is not None:
1064 VelRange= dataOut.VelRange
1064 VelRange= dataOut.VelRange
1065 else:
1065 else:
1066 VelRange= dataOut.abscissaList
1066 VelRange= dataOut.abscissaList
1067
1067
1068 ySamples=numpy.ones([nChannel,nProfiles])
1068 ySamples=numpy.ones([nChannel,nProfiles])
1069 phase=numpy.ones([nChannel,nProfiles])
1069 phase=numpy.ones([nChannel,nProfiles])
1070 CSPCSamples=numpy.ones([nChannel,nProfiles],dtype=numpy.complex_)
1070 CSPCSamples=numpy.ones([nChannel,nProfiles],dtype=numpy.complex_)
1071 coherence=numpy.ones([nChannel,nProfiles])
1071 coherence=numpy.ones([nChannel,nProfiles])
1072 PhaseSlope=numpy.ones(nChannel)
1072 PhaseSlope=numpy.ones(nChannel)
1073 PhaseInter=numpy.ones(nChannel)
1073 PhaseInter=numpy.ones(nChannel)
1074 dataSNR = dataOut.data_SNR
1074 dataSNR = dataOut.data_SNR
1075
1075
1076
1076
1077
1077
1078 data = dataOut.data_pre
1078 data = dataOut.data_pre
1079 noise = dataOut.noise
1079 noise = dataOut.noise
1080 print 'noise',noise
1080 #print 'noise',noise
1081 #SNRdB = 10*numpy.log10(dataOut.data_SNR)
1081 #SNRdB = 10*numpy.log10(dataOut.data_SNR)
1082
1082
1083 FirstMoment = numpy.average(dataOut.data_param[:,1,:],0)
1083 FirstMoment = numpy.average(dataOut.data_param[:,1,:],0)
1084 #SNRdBMean = []
1084 #SNRdBMean = []
1085
1085
1086
1086
1087 #for j in range(nHeights):
1087 #for j in range(nHeights):
1088 # FirstMoment = numpy.append(FirstMoment,numpy.mean([dataOut.data_param[0,1,j],dataOut.data_param[1,1,j],dataOut.data_param[2,1,j]]))
1088 # FirstMoment = numpy.append(FirstMoment,numpy.mean([dataOut.data_param[0,1,j],dataOut.data_param[1,1,j],dataOut.data_param[2,1,j]]))
1089 # SNRdBMean = numpy.append(SNRdBMean,numpy.mean([SNRdB[0,j],SNRdB[1,j],SNRdB[2,j]]))
1089 # SNRdBMean = numpy.append(SNRdBMean,numpy.mean([SNRdB[0,j],SNRdB[1,j],SNRdB[2,j]]))
1090
1090
1091 data_output=numpy.ones([3,spc.shape[2]])*numpy.NaN
1091 data_output=numpy.ones([3,spc.shape[2]])*numpy.NaN
1092
1092
1093 velocityX=[]
1093 velocityX=[]
1094 velocityY=[]
1094 velocityY=[]
1095 velocityV=[]
1095 velocityV=[]
1096 PhaseLine=[]
1096
1097
1097 dbSNR = 10*numpy.log10(dataSNR)
1098 dbSNR = 10*numpy.log10(dataSNR)
1098 dbSNR = numpy.average(dbSNR,0)
1099 dbSNR = numpy.average(dbSNR,0)
1099 for Height in range(nHeights):
1100 for Height in range(nHeights):
1100
1101
1101 [Vzon,Vmer,Vver, GaussCenter]= self.WindEstimation(spc, cspc, pairsList, ChanDist, Height, noise, VelRange, dbSNR[Height], SNRlimit)
1102 [Vzon,Vmer,Vver, GaussCenter, PhaseSlope]= self.WindEstimation(spc, cspc, pairsList, ChanDist, Height, noise, VelRange, dbSNR[Height], SNRlimit)
1103
1104 PhaseLine = numpy.append(PhaseLine, PhaseSlope)
1102
1105
1103 if abs(Vzon)<100. and abs(Vzon)> 0.:
1106 if abs(Vzon)<100. and abs(Vzon)> 0.:
1104 velocityX=numpy.append(velocityX, Vzon)#Vmag
1107 velocityX=numpy.append(velocityX, Vzon)#Vmag
1105
1108
1106 else:
1109 else:
1107 print 'Vzon',Vzon
1110 #print 'Vzon',Vzon
1108 velocityX=numpy.append(velocityX, numpy.NaN)
1111 velocityX=numpy.append(velocityX, numpy.NaN)
1109
1112
1110 if abs(Vmer)<100. and abs(Vmer) > 0.:
1113 if abs(Vmer)<100. and abs(Vmer) > 0.:
1111 velocityY=numpy.append(velocityY, Vmer)#Vang
1114 velocityY=numpy.append(velocityY, Vmer)#Vang
1112
1115
1113 else:
1116 else:
1114 print 'Vmer',Vmer
1117 #print 'Vmer',Vmer
1115 velocityY=numpy.append(velocityY, numpy.NaN)
1118 velocityY=numpy.append(velocityY, numpy.NaN)
1116
1119
1117 if dbSNR[Height] > SNRlimit:
1120 if dbSNR[Height] > SNRlimit:
1118 velocityV=numpy.append(velocityV, FirstMoment[Height])
1121 velocityV=numpy.append(velocityV, FirstMoment[Height])
1119 else:
1122 else:
1120 velocityV=numpy.append(velocityV, numpy.NaN)
1123 velocityV=numpy.append(velocityV, numpy.NaN)
1121 #FirstMoment[Height]= numpy.NaN
1124 #FirstMoment[Height]= numpy.NaN
1122 # if SNRdBMean[Height] <12:
1125 # if SNRdBMean[Height] <12:
1123 # FirstMoment[Height] = numpy.NaN
1126 # FirstMoment[Height] = numpy.NaN
1124 # velocityX[Height] = numpy.NaN
1127 # velocityX[Height] = numpy.NaN
1125 # velocityY[Height] = numpy.NaN
1128 # velocityY[Height] = numpy.NaN
1126
1129
1130
1127
1131
1128 data_output[0]=numpy.array(velocityX)
1132 data_output[0]=numpy.array(velocityX)
1129 data_output[1]=numpy.array(velocityY)
1133 data_output[1]=numpy.array(velocityY)
1130 data_output[2]=-velocityV#FirstMoment
1134 data_output[2]=-velocityV#FirstMoment
1131
1135
1132 print ' '
1136 print ' '
1133 #print 'FirstMoment'
1137 #print 'FirstMoment'
1134 #print FirstMoment
1138 #print FirstMoment
1135 print 'velocityX',data_output[0]
1139 print 'velocityX',data_output[0]
1136 print ' '
1140 print ' '
1137 print 'velocityY',data_output[1]
1141 print 'velocityY',data_output[1]
1142 print 'PhaseLine',PhaseLine
1138 #print numpy.array(velocityY)
1143 #print numpy.array(velocityY)
1139 print ' '
1144 print ' '
1140 #print 'SNR'
1145 #print 'SNR'
1141 #print 10*numpy.log10(dataOut.data_SNR)
1146 #print 10*numpy.log10(dataOut.data_SNR)
1142 #print numpy.shape(10*numpy.log10(dataOut.data_SNR))
1147 #print numpy.shape(10*numpy.log10(dataOut.data_SNR))
1143 print ' '
1148 print ' '
1144
1149
1145
1150
1146 dataOut.data_output=data_output
1151 dataOut.data_output=data_output
1152
1147 return
1153 return
1148
1154
1149
1155
1150 def moving_average(self,x, N=2):
1156 def moving_average(self,x, N=2):
1151 return numpy.convolve(x, numpy.ones((N,))/N)[(N-1):]
1157 return numpy.convolve(x, numpy.ones((N,))/N)[(N-1):]
1152
1158
1153 def gaus(self,xSamples,a,x0,sigma):
1159 def gaus(self,xSamples,a,x0,sigma):
1154 return a*numpy.exp(-(xSamples-x0)**2/(2*sigma**2))
1160 return a*numpy.exp(-(xSamples-x0)**2/(2*sigma**2))
1155
1161
1156 def Find(self,x,value):
1162 def Find(self,x,value):
1157 for index in range(len(x)):
1163 for index in range(len(x)):
1158 if x[index]==value:
1164 if x[index]==value:
1159 return index
1165 return index
1160
1166
1161 def WindEstimation(self, spc, cspc, pairsList, ChanDist, Height, noise, VelRange, dbSNR, SNRlimit):
1167 def WindEstimation(self, spc, cspc, pairsList, ChanDist, Height, noise, VelRange, dbSNR, SNRlimit):
1162
1168
1163 ySamples=numpy.ones([spc.shape[0],spc.shape[1]])
1169 ySamples=numpy.ones([spc.shape[0],spc.shape[1]])
1164 phase=numpy.ones([spc.shape[0],spc.shape[1]])
1170 phase=numpy.ones([spc.shape[0],spc.shape[1]])
1165 CSPCSamples=numpy.ones([spc.shape[0],spc.shape[1]],dtype=numpy.complex_)
1171 CSPCSamples=numpy.ones([spc.shape[0],spc.shape[1]],dtype=numpy.complex_)
1166 coherence=numpy.ones([spc.shape[0],spc.shape[1]])
1172 coherence=numpy.ones([spc.shape[0],spc.shape[1]])
1167 PhaseSlope=numpy.ones(spc.shape[0])
1173 PhaseSlope=numpy.zeros(spc.shape[0])
1168 PhaseInter=numpy.ones(spc.shape[0])
1174 PhaseInter=numpy.ones(spc.shape[0])
1169 xFrec=VelRange
1175 xFrec=VelRange
1170
1176
1171 '''Getting Eij and Nij'''
1177 '''Getting Eij and Nij'''
1172
1178
1173 E01=ChanDist[0][0]
1179 E01=ChanDist[0][0]
1174 N01=ChanDist[0][1]
1180 N01=ChanDist[0][1]
1175
1181
1176 E02=ChanDist[1][0]
1182 E02=ChanDist[1][0]
1177 N02=ChanDist[1][1]
1183 N02=ChanDist[1][1]
1178
1184
1179 E12=ChanDist[2][0]
1185 E12=ChanDist[2][0]
1180 N12=ChanDist[2][1]
1186 N12=ChanDist[2][1]
1181
1187
1182 z = spc.copy()
1188 z = spc.copy()
1183 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1189 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1184
1190
1185 for i in range(spc.shape[0]):
1191 for i in range(spc.shape[0]):
1186
1192
1187 '''****** Line of Data SPC ******'''
1193 '''****** Line of Data SPC ******'''
1188 zline=z[i,:,Height]
1194 zline=z[i,:,Height]
1189
1195
1190 '''****** SPC is normalized ******'''
1196 '''****** SPC is normalized ******'''
1191 FactNorm= (zline.copy()-noise[i]) / numpy.sum(zline.copy())
1197 FactNorm= (zline.copy()-noise[i]) / numpy.sum(zline.copy())
1192 FactNorm= FactNorm/numpy.sum(FactNorm)
1198 FactNorm= FactNorm/numpy.sum(FactNorm)
1193
1199
1194 SmoothSPC=self.moving_average(FactNorm,N=3)
1200 SmoothSPC=self.moving_average(FactNorm,N=3)
1195
1201
1196 xSamples = ar(range(len(SmoothSPC)))
1202 xSamples = ar(range(len(SmoothSPC)))
1197 ySamples[i] = SmoothSPC
1203 ySamples[i] = SmoothSPC
1198
1204
1199 #dbSNR=10*numpy.log10(dataSNR)
1205 #dbSNR=10*numpy.log10(dataSNR)
1200 print ' '
1206 print ' '
1201 print ' '
1207 print ' '
1202 print ' '
1208 print ' '
1203
1209
1204 #print 'dataSNR', dbSNR.shape, dbSNR[0,40:120]
1210 #print 'dataSNR', dbSNR.shape, dbSNR[0,40:120]
1205 print 'SmoothSPC', SmoothSPC.shape, SmoothSPC[0:20]
1211 #print 'SmoothSPC', SmoothSPC.shape, SmoothSPC[0:20]
1206 print 'noise',noise
1212 #print 'noise',noise
1207 print 'zline',zline.shape, zline[0:20]
1213 #print 'zline',zline.shape, zline[0:20]
1208 print 'FactNorm',FactNorm.shape, FactNorm[0:20]
1214 #print 'FactNorm',FactNorm.shape, FactNorm[0:20]
1209 print 'FactNorm suma', numpy.sum(FactNorm)
1215 #print 'FactNorm suma', numpy.sum(FactNorm)
1210
1216
1211 for i in range(spc.shape[0]):
1217 for i in range(spc.shape[0]):
1212
1218
1213 '''****** Line of Data CSPC ******'''
1219 '''****** Line of Data CSPC ******'''
1214 cspcLine=cspc[i,:,Height].copy()
1220 cspcLine=cspc[i,:,Height].copy()
1215
1221
1216 '''****** CSPC is normalized ******'''
1222 '''****** CSPC is normalized ******'''
1217 chan_index0 = pairsList[i][0]
1223 chan_index0 = pairsList[i][0]
1218 chan_index1 = pairsList[i][1]
1224 chan_index1 = pairsList[i][1]
1219 CSPCFactor= abs(numpy.sum(ySamples[chan_index0]) * numpy.sum(ySamples[chan_index1])) #
1225 CSPCFactor= abs(numpy.sum(ySamples[chan_index0]) * numpy.sum(ySamples[chan_index1])) #
1220
1226
1221 CSPCNorm = (cspcLine.copy() -noise[i]) / numpy.sqrt(CSPCFactor)
1227 CSPCNorm = (cspcLine.copy() -noise[i]) / numpy.sqrt(CSPCFactor)
1222
1228
1223 CSPCSamples[i] = CSPCNorm
1229 CSPCSamples[i] = CSPCNorm
1224 coherence[i] = numpy.abs(CSPCSamples[i]) / numpy.sqrt(CSPCFactor)
1230 coherence[i] = numpy.abs(CSPCSamples[i]) / numpy.sqrt(CSPCFactor)
1225
1231
1226 coherence[i]= self.moving_average(coherence[i],N=2)
1232 coherence[i]= self.moving_average(coherence[i],N=2)
1227
1233
1228 phase[i] = self.moving_average( numpy.arctan2(CSPCSamples[i].imag, CSPCSamples[i].real),N=1)#*180/numpy.pi
1234 phase[i] = self.moving_average( numpy.arctan2(CSPCSamples[i].imag, CSPCSamples[i].real),N=1)#*180/numpy.pi
1229
1235
1230 print 'cspcLine', cspcLine.shape, cspcLine[0:20]
1236 #print 'cspcLine', cspcLine.shape, cspcLine[0:20]
1231 print 'CSPCFactor', CSPCFactor#, CSPCFactor[0:20]
1237 #print 'CSPCFactor', CSPCFactor#, CSPCFactor[0:20]
1232 print numpy.sum(ySamples[chan_index0]), numpy.sum(ySamples[chan_index1]), -noise[i]
1238 #print numpy.sum(ySamples[chan_index0]), numpy.sum(ySamples[chan_index1]), -noise[i]
1233 print 'CSPCNorm', CSPCNorm.shape, CSPCNorm[0:20]
1239 #print 'CSPCNorm', CSPCNorm.shape, CSPCNorm[0:20]
1234 print 'CSPCNorm suma', numpy.sum(CSPCNorm)
1240 #print 'CSPCNorm suma', numpy.sum(CSPCNorm)
1235 print 'CSPCSamples', CSPCSamples.shape, CSPCSamples[0,0:20]
1241 #print 'CSPCSamples', CSPCSamples.shape, CSPCSamples[0,0:20]
1236
1242
1237 '''****** Getting fij width ******'''
1243 '''****** Getting fij width ******'''
1238
1244
1239 yMean=[]
1245 yMean=[]
1240 yMean2=[]
1246 yMean2=[]
1241
1247
1242 for j in range(len(ySamples[1])):
1248 for j in range(len(ySamples[1])):
1243 yMean=numpy.append(yMean,numpy.mean([ySamples[0,j],ySamples[1,j],ySamples[2,j]]))
1249 yMean=numpy.append(yMean,numpy.mean([ySamples[0,j],ySamples[1,j],ySamples[2,j]]))
1244
1250
1245 '''******* Getting fitting Gaussian ******'''
1251 '''******* Getting fitting Gaussian ******'''
1246 meanGauss=sum(xSamples*yMean) / len(xSamples)
1252 meanGauss=sum(xSamples*yMean) / len(xSamples)
1247 sigma=sum(yMean*(xSamples-meanGauss)**2) / len(xSamples)
1253 sigma=sum(yMean*(xSamples-meanGauss)**2) / len(xSamples)
1248
1254
1249 print '****************************'
1255 #print '****************************'
1250 print 'len(xSamples): ',len(xSamples)
1256 #print 'len(xSamples): ',len(xSamples)
1251 print 'yMean: ', yMean.shape, yMean[0:20]
1257 #print 'yMean: ', yMean.shape, yMean[0:20]
1252 print 'ySamples', ySamples.shape, ySamples[0,0:20]
1258 #print 'ySamples', ySamples.shape, ySamples[0,0:20]
1253 print 'xSamples: ',xSamples.shape, xSamples[0:20]
1259 #print 'xSamples: ',xSamples.shape, xSamples[0:20]
1254
1260
1255 print 'meanGauss',meanGauss
1261 #print 'meanGauss',meanGauss
1256 print 'sigma',sigma
1262 #print 'sigma',sigma
1257
1263
1258 #if (abs(meanGauss/sigma**2) > 0.0001) : #0.000000001):
1264 #if (abs(meanGauss/sigma**2) > 0.0001) : #0.000000001):
1259 if dbSNR > SNRlimit :
1265 if dbSNR > SNRlimit and abs(meanGauss/sigma**2) > 0.0001:
1260 try:
1266 try:
1261 popt,pcov = curve_fit(self.gaus,xSamples,yMean,p0=[1,meanGauss,sigma])
1267 popt,pcov = curve_fit(self.gaus,xSamples,yMean,p0=[1,meanGauss,sigma])
1262
1268
1263 if numpy.amax(popt)>numpy.amax(yMean)*0.3:
1269 if numpy.amax(popt)>numpy.amax(yMean)*0.3:
1264 FitGauss=self.gaus(xSamples,*popt)
1270 FitGauss=self.gaus(xSamples,*popt)
1265
1271
1266 else:
1272 else:
1267 FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
1273 FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
1268 print 'Verificador: Dentro', Height
1274 print 'Verificador: Dentro', Height
1269 except :#RuntimeError:
1275 except :#RuntimeError:
1270 FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
1276 FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
1271
1277
1272
1278
1273 else:
1279 else:
1274 FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
1280 FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
1275
1281
1276 Maximun=numpy.amax(yMean)
1282 Maximun=numpy.amax(yMean)
1277 eMinus1=Maximun*numpy.exp(-1)#*0.8
1283 eMinus1=Maximun*numpy.exp(-1)#*0.8
1278
1284
1279 HWpos=self.Find(FitGauss,min(FitGauss, key=lambda value:abs(value-eMinus1)))
1285 HWpos=self.Find(FitGauss,min(FitGauss, key=lambda value:abs(value-eMinus1)))
1280 HalfWidth= xFrec[HWpos]
1286 HalfWidth= xFrec[HWpos]
1281 GCpos=self.Find(FitGauss, numpy.amax(FitGauss))
1287 GCpos=self.Find(FitGauss, numpy.amax(FitGauss))
1282 Vpos=self.Find(FactNorm, numpy.amax(FactNorm))
1288 Vpos=self.Find(FactNorm, numpy.amax(FactNorm))
1283
1289
1284 #Vpos=FirstMoment[]
1290 #Vpos=FirstMoment[]
1285
1291
1286 '''****** Getting Fij ******'''
1292 '''****** Getting Fij ******'''
1287
1293
1288 GaussCenter=xFrec[GCpos]
1294 GaussCenter=xFrec[GCpos]
1289 if (GaussCenter<0 and HalfWidth>0) or (GaussCenter>0 and HalfWidth<0):
1295 if (GaussCenter<0 and HalfWidth>0) or (GaussCenter>0 and HalfWidth<0):
1290 Fij=abs(GaussCenter)+abs(HalfWidth)+0.0000001
1296 Fij=abs(GaussCenter)+abs(HalfWidth)+0.0000001
1291 else:
1297 else:
1292 Fij=abs(GaussCenter-HalfWidth)+0.0000001
1298 Fij=abs(GaussCenter-HalfWidth)+0.0000001
1293
1299
1294 '''****** Getting Frecuency range of significant data ******'''
1300 '''****** Getting Frecuency range of significant data ******'''
1295
1301
1296 Rangpos=self.Find(FitGauss,min(FitGauss, key=lambda value:abs(value-Maximun*0.10)))
1302 Rangpos=self.Find(FitGauss,min(FitGauss, key=lambda value:abs(value-Maximun*0.10)))
1297
1303
1298 if Rangpos<GCpos:
1304 if Rangpos<GCpos:
1299 Range=numpy.array([Rangpos,2*GCpos-Rangpos])
1305 Range=numpy.array([Rangpos,2*GCpos-Rangpos])
1300 elif Rangpos< ( len(xFrec)- len(xFrec)*0.1):
1306 elif Rangpos< ( len(xFrec)- len(xFrec)*0.1):
1301 Range=numpy.array([2*GCpos-Rangpos,Rangpos])
1307 Range=numpy.array([2*GCpos-Rangpos,Rangpos])
1302 else:
1308 else:
1303 Range = numpy.array([0,0])
1309 Range = numpy.array([0,0])
1304
1310
1305 print ' '
1311 #print ' '
1306 print 'GCpos',GCpos, ( len(xFrec)- len(xFrec)*0.1)
1312 #print 'GCpos',GCpos, ( len(xFrec)- len(xFrec)*0.1)
1307 print 'Rangpos',Rangpos
1313 #print 'Rangpos',Rangpos
1308 print 'RANGE: ', Range
1314 print 'RANGE: ', Range
1309 FrecRange=xFrec[Range[0]:Range[1]]
1315 FrecRange=xFrec[Range[0]:Range[1]]
1310
1316
1311 '''****** Getting SCPC Slope ******'''
1317 '''****** Getting SCPC Slope ******'''
1312
1318
1313 for i in range(spc.shape[0]):
1319 for i in range(spc.shape[0]):
1314
1320
1315 if len(FrecRange)>5 and len(FrecRange)<spc.shape[1]*0.5:
1321 if len(FrecRange)>5 and len(FrecRange)<spc.shape[1]*0.5:
1316 PhaseRange=self.moving_average(phase[i,Range[0]:Range[1]],N=3)
1322 PhaseRange=self.moving_average(phase[i,Range[0]:Range[1]],N=3)
1317
1323
1318 print 'FrecRange', len(FrecRange) , FrecRange
1324 print 'FrecRange', len(FrecRange) , FrecRange
1319 print 'PhaseRange', len(PhaseRange), PhaseRange
1325 print 'PhaseRange', len(PhaseRange), PhaseRange
1320 print ' '
1326 print ' '
1321 if len(FrecRange) == len(PhaseRange):
1327 if len(FrecRange) == len(PhaseRange):
1322 slope, intercept, r_value, p_value, std_err = stats.linregress(FrecRange,PhaseRange)
1328 slope, intercept, r_value, p_value, std_err = stats.linregress(FrecRange,PhaseRange)
1323 PhaseSlope[i]=slope
1329 PhaseSlope[i]=slope
1324 PhaseInter[i]=intercept
1330 PhaseInter[i]=intercept
1325 else:
1331 else:
1326 PhaseSlope[i]=0
1332 PhaseSlope[i]=0
1327 PhaseInter[i]=0
1333 PhaseInter[i]=0
1328 else:
1334 else:
1329 PhaseSlope[i]=0
1335 PhaseSlope[i]=0
1330 PhaseInter[i]=0
1336 PhaseInter[i]=0
1331
1337
1332 '''Getting constant C'''
1338 '''Getting constant C'''
1333 cC=(Fij*numpy.pi)**2
1339 cC=(Fij*numpy.pi)**2
1334
1340
1335 '''****** Getting constants F and G ******'''
1341 '''****** Getting constants F and G ******'''
1336 MijEijNij=numpy.array([[E02,N02], [E12,N12]])
1342 MijEijNij=numpy.array([[E02,N02], [E12,N12]])
1337 MijResult0=(-PhaseSlope[1]*cC) / (2*numpy.pi)
1343 MijResult0=(-PhaseSlope[1]*cC) / (2*numpy.pi)
1338 MijResult1=(-PhaseSlope[2]*cC) / (2*numpy.pi)
1344 MijResult1=(-PhaseSlope[2]*cC) / (2*numpy.pi)
1339 MijResults=numpy.array([MijResult0,MijResult1])
1345 MijResults=numpy.array([MijResult0,MijResult1])
1340 (cF,cG) = numpy.linalg.solve(MijEijNij, MijResults)
1346 (cF,cG) = numpy.linalg.solve(MijEijNij, MijResults)
1341
1347
1342 '''****** Getting constants A, B and H ******'''
1348 '''****** Getting constants A, B and H ******'''
1343 W01=numpy.amax(coherence[0])
1349 W01=numpy.amax(coherence[0])
1344 W02=numpy.amax(coherence[1])
1350 W02=numpy.amax(coherence[1])
1345 W12=numpy.amax(coherence[2])
1351 W12=numpy.amax(coherence[2])
1346
1352
1347 WijResult0=((cF*E01+cG*N01)**2)/cC - numpy.log(W01 / numpy.sqrt(numpy.pi/cC))
1353 WijResult0=((cF*E01+cG*N01)**2)/cC - numpy.log(W01 / numpy.sqrt(numpy.pi/cC))
1348 WijResult1=((cF*E02+cG*N02)**2)/cC - numpy.log(W02 / numpy.sqrt(numpy.pi/cC))
1354 WijResult1=((cF*E02+cG*N02)**2)/cC - numpy.log(W02 / numpy.sqrt(numpy.pi/cC))
1349 WijResult2=((cF*E12+cG*N12)**2)/cC - numpy.log(W12 / numpy.sqrt(numpy.pi/cC))
1355 WijResult2=((cF*E12+cG*N12)**2)/cC - numpy.log(W12 / numpy.sqrt(numpy.pi/cC))
1350
1356
1351 WijResults=numpy.array([WijResult0, WijResult1, WijResult2])
1357 WijResults=numpy.array([WijResult0, WijResult1, WijResult2])
1352
1358
1353 WijEijNij=numpy.array([ [E01**2, N01**2, 2*E01*N01] , [E02**2, N02**2, 2*E02*N02] , [E12**2, N12**2, 2*E12*N12] ])
1359 WijEijNij=numpy.array([ [E01**2, N01**2, 2*E01*N01] , [E02**2, N02**2, 2*E02*N02] , [E12**2, N12**2, 2*E12*N12] ])
1354 (cA,cB,cH) = numpy.linalg.solve(WijEijNij, WijResults)
1360 (cA,cB,cH) = numpy.linalg.solve(WijEijNij, WijResults)
1355
1361
1356 VxVy=numpy.array([[cA,cH],[cH,cB]])
1362 VxVy=numpy.array([[cA,cH],[cH,cB]])
1357
1363
1358 VxVyResults=numpy.array([-cF,-cG])
1364 VxVyResults=numpy.array([-cF,-cG])
1359 (Vx,Vy) = numpy.linalg.solve(VxVy, VxVyResults)
1365 (Vx,Vy) = numpy.linalg.solve(VxVy, VxVyResults)
1360
1366
1361 Vzon = Vy
1367 Vzon = Vy
1362 Vmer = Vx
1368 Vmer = Vx
1363 Vmag=numpy.sqrt(Vzon**2+Vmer**2)
1369 Vmag=numpy.sqrt(Vzon**2+Vmer**2)
1364 Vang=numpy.arctan2(Vmer,Vzon)
1370 Vang=numpy.arctan2(Vmer,Vzon)
1365 Vver=xFrec[Vpos]
1371 Vver=xFrec[Vpos]
1372 print 'Height',Height
1366 print 'vzon y vmer', Vzon, Vmer
1373 print 'vzon y vmer', Vzon, Vmer
1367 return Vzon, Vmer, Vver, GaussCenter
1374 return Vzon, Vmer, Vver, GaussCenter, PhaseSlope
1368
1375
1369 class SpectralMoments(Operation):
1376 class SpectralMoments(Operation):
1370
1377
1371 '''
1378 '''
1372 Function SpectralMoments()
1379 Function SpectralMoments()
1373
1380
1374 Calculates moments (power, mean, standard deviation) and SNR of the signal
1381 Calculates moments (power, mean, standard deviation) and SNR of the signal
1375
1382
1376 Type of dataIn: Spectra
1383 Type of dataIn: Spectra
1377
1384
1378 Configuration Parameters:
1385 Configuration Parameters:
1379
1386
1380 dirCosx : Cosine director in X axis
1387 dirCosx : Cosine director in X axis
1381 dirCosy : Cosine director in Y axis
1388 dirCosy : Cosine director in Y axis
1382
1389
1383 elevation :
1390 elevation :
1384 azimuth :
1391 azimuth :
1385
1392
1386 Input:
1393 Input:
1387 channelList : simple channel list to select e.g. [2,3,7]
1394 channelList : simple channel list to select e.g. [2,3,7]
1388 self.dataOut.data_pre : Spectral data
1395 self.dataOut.data_pre : Spectral data
1389 self.dataOut.abscissaList : List of frequencies
1396 self.dataOut.abscissaList : List of frequencies
1390 self.dataOut.noise : Noise level per channel
1397 self.dataOut.noise : Noise level per channel
1391
1398
1392 Affected:
1399 Affected:
1393 self.dataOut.data_param : Parameters per channel
1400 self.dataOut.data_param : Parameters per channel
1394 self.dataOut.data_SNR : SNR per channel
1401 self.dataOut.data_SNR : SNR per channel
1395
1402
1396 '''
1403 '''
1397
1404
1398 def run(self, dataOut):
1405 def run(self, dataOut):
1399
1406
1400 #dataOut.data_pre = dataOut.data_pre[0]
1407 #dataOut.data_pre = dataOut.data_pre[0]
1401 data = dataOut.data_pre[0]
1408 data = dataOut.data_pre[0]
1402 absc = dataOut.abscissaList[:-1]
1409 absc = dataOut.abscissaList[:-1]
1403 noise = dataOut.noise
1410 noise = dataOut.noise
1404 nChannel = data.shape[0]
1411 nChannel = data.shape[0]
1405 data_param = numpy.zeros((nChannel, 4, data.shape[2]))
1412 data_param = numpy.zeros((nChannel, 4, data.shape[2]))
1406
1413
1407 for ind in range(nChannel):
1414 for ind in range(nChannel):
1408 data_param[ind,:,:] = self.__calculateMoments( data[ind,:,:] , absc , noise[ind] )
1415 data_param[ind,:,:] = self.__calculateMoments( data[ind,:,:] , absc , noise[ind] )
1409
1416
1410 dataOut.data_param = data_param[:,1:,:]
1417 dataOut.data_param = data_param[:,1:,:]
1411 dataOut.data_SNR = data_param[:,0]
1418 dataOut.data_SNR = data_param[:,0]
1412 return
1419 return
1413
1420
1414 def __calculateMoments(self, oldspec, oldfreq, n0,
1421 def __calculateMoments(self, oldspec, oldfreq, n0,
1415 nicoh = None, graph = None, smooth = None, type1 = None, fwindow = None, snrth = None, dc = None, aliasing = None, oldfd = None, wwauto = None):
1422 nicoh = None, graph = None, smooth = None, type1 = None, fwindow = None, snrth = None, dc = None, aliasing = None, oldfd = None, wwauto = None):
1416
1423
1417 if (nicoh == None): nicoh = 1
1424 if (nicoh == None): nicoh = 1
1418 if (graph == None): graph = 0
1425 if (graph == None): graph = 0
1419 if (smooth == None): smooth = 0
1426 if (smooth == None): smooth = 0
1420 elif (self.smooth < 3): smooth = 0
1427 elif (self.smooth < 3): smooth = 0
1421
1428
1422 if (type1 == None): type1 = 0
1429 if (type1 == None): type1 = 0
1423 if (fwindow == None): fwindow = numpy.zeros(oldfreq.size) + 1
1430 if (fwindow == None): fwindow = numpy.zeros(oldfreq.size) + 1
1424 if (snrth == None): snrth = -3
1431 if (snrth == None): snrth = -3
1425 if (dc == None): dc = 0
1432 if (dc == None): dc = 0
1426 if (aliasing == None): aliasing = 0
1433 if (aliasing == None): aliasing = 0
1427 if (oldfd == None): oldfd = 0
1434 if (oldfd == None): oldfd = 0
1428 if (wwauto == None): wwauto = 0
1435 if (wwauto == None): wwauto = 0
1429
1436
1430 if (n0 < 1.e-20): n0 = 1.e-20
1437 if (n0 < 1.e-20): n0 = 1.e-20
1431
1438
1432 freq = oldfreq
1439 freq = oldfreq
1433 vec_power = numpy.zeros(oldspec.shape[1])
1440 vec_power = numpy.zeros(oldspec.shape[1])
1434 vec_fd = numpy.zeros(oldspec.shape[1])
1441 vec_fd = numpy.zeros(oldspec.shape[1])
1435 vec_w = numpy.zeros(oldspec.shape[1])
1442 vec_w = numpy.zeros(oldspec.shape[1])
1436 vec_snr = numpy.zeros(oldspec.shape[1])
1443 vec_snr = numpy.zeros(oldspec.shape[1])
1437
1444
1438 for ind in range(oldspec.shape[1]):
1445 for ind in range(oldspec.shape[1]):
1439
1446
1440 spec = oldspec[:,ind]
1447 spec = oldspec[:,ind]
1441 aux = spec*fwindow
1448 aux = spec*fwindow
1442 max_spec = aux.max()
1449 max_spec = aux.max()
1443 m = list(aux).index(max_spec)
1450 m = list(aux).index(max_spec)
1444
1451
1445 #Smooth
1452 #Smooth
1446 if (smooth == 0): spec2 = spec
1453 if (smooth == 0): spec2 = spec
1447 else: spec2 = scipy.ndimage.filters.uniform_filter1d(spec,size=smooth)
1454 else: spec2 = scipy.ndimage.filters.uniform_filter1d(spec,size=smooth)
1448
1455
1449 # Calculo de Momentos
1456 # Calculo de Momentos
1450 bb = spec2[range(m,spec2.size)]
1457 bb = spec2[range(m,spec2.size)]
1451 bb = (bb<n0).nonzero()
1458 bb = (bb<n0).nonzero()
1452 bb = bb[0]
1459 bb = bb[0]
1453
1460
1454 ss = spec2[range(0,m + 1)]
1461 ss = spec2[range(0,m + 1)]
1455 ss = (ss<n0).nonzero()
1462 ss = (ss<n0).nonzero()
1456 ss = ss[0]
1463 ss = ss[0]
1457
1464
1458 if (bb.size == 0):
1465 if (bb.size == 0):
1459 bb0 = spec.size - 1 - m
1466 bb0 = spec.size - 1 - m
1460 else:
1467 else:
1461 bb0 = bb[0] - 1
1468 bb0 = bb[0] - 1
1462 if (bb0 < 0):
1469 if (bb0 < 0):
1463 bb0 = 0
1470 bb0 = 0
1464
1471
1465 if (ss.size == 0): ss1 = 1
1472 if (ss.size == 0): ss1 = 1
1466 else: ss1 = max(ss) + 1
1473 else: ss1 = max(ss) + 1
1467
1474
1468 if (ss1 > m): ss1 = m
1475 if (ss1 > m): ss1 = m
1469
1476
1470 valid = numpy.asarray(range(int(m + bb0 - ss1 + 1))) + ss1
1477 valid = numpy.asarray(range(int(m + bb0 - ss1 + 1))) + ss1
1471 power = ((spec2[valid] - n0)*fwindow[valid]).sum()
1478 power = ((spec2[valid] - n0)*fwindow[valid]).sum()
1472 fd = ((spec2[valid]- n0)*freq[valid]*fwindow[valid]).sum()/power
1479 fd = ((spec2[valid]- n0)*freq[valid]*fwindow[valid]).sum()/power
1473 w = math.sqrt(((spec2[valid] - n0)*fwindow[valid]*(freq[valid]- fd)**2).sum()/power)
1480 w = math.sqrt(((spec2[valid] - n0)*fwindow[valid]*(freq[valid]- fd)**2).sum()/power)
1474 snr = (spec2.mean()-n0)/n0
1481 snr = (spec2.mean()-n0)/n0
1475
1482
1476 if (snr < 1.e-20) :
1483 if (snr < 1.e-20) :
1477 snr = 1.e-20
1484 snr = 1.e-20
1478
1485
1479 vec_power[ind] = power
1486 vec_power[ind] = power
1480 vec_fd[ind] = fd
1487 vec_fd[ind] = fd
1481 vec_w[ind] = w
1488 vec_w[ind] = w
1482 vec_snr[ind] = snr
1489 vec_snr[ind] = snr
1483
1490
1484 moments = numpy.vstack((vec_snr, vec_power, vec_fd, vec_w))
1491 moments = numpy.vstack((vec_snr, vec_power, vec_fd, vec_w))
1485 return moments
1492 return moments
1486
1493
1487 #------------------ Get SA Parameters --------------------------
1494 #------------------ Get SA Parameters --------------------------
1488
1495
1489 def GetSAParameters(self):
1496 def GetSAParameters(self):
1490 #SA en frecuencia
1497 #SA en frecuencia
1491 pairslist = self.dataOut.groupList
1498 pairslist = self.dataOut.groupList
1492 num_pairs = len(pairslist)
1499 num_pairs = len(pairslist)
1493
1500
1494 vel = self.dataOut.abscissaList
1501 vel = self.dataOut.abscissaList
1495 spectra = self.dataOut.data_pre
1502 spectra = self.dataOut.data_pre
1496 cspectra = self.dataIn.data_cspc
1503 cspectra = self.dataIn.data_cspc
1497 delta_v = vel[1] - vel[0]
1504 delta_v = vel[1] - vel[0]
1498
1505
1499 #Calculating the power spectrum
1506 #Calculating the power spectrum
1500 spc_pow = numpy.sum(spectra, 3)*delta_v
1507 spc_pow = numpy.sum(spectra, 3)*delta_v
1501 #Normalizing Spectra
1508 #Normalizing Spectra
1502 norm_spectra = spectra/spc_pow
1509 norm_spectra = spectra/spc_pow
1503 #Calculating the norm_spectra at peak
1510 #Calculating the norm_spectra at peak
1504 max_spectra = numpy.max(norm_spectra, 3)
1511 max_spectra = numpy.max(norm_spectra, 3)
1505
1512
1506 #Normalizing Cross Spectra
1513 #Normalizing Cross Spectra
1507 norm_cspectra = numpy.zeros(cspectra.shape)
1514 norm_cspectra = numpy.zeros(cspectra.shape)
1508
1515
1509 for i in range(num_chan):
1516 for i in range(num_chan):
1510 norm_cspectra[i,:,:] = cspectra[i,:,:]/numpy.sqrt(spc_pow[pairslist[i][0],:]*spc_pow[pairslist[i][1],:])
1517 norm_cspectra[i,:,:] = cspectra[i,:,:]/numpy.sqrt(spc_pow[pairslist[i][0],:]*spc_pow[pairslist[i][1],:])
1511
1518
1512 max_cspectra = numpy.max(norm_cspectra,2)
1519 max_cspectra = numpy.max(norm_cspectra,2)
1513 max_cspectra_index = numpy.argmax(norm_cspectra, 2)
1520 max_cspectra_index = numpy.argmax(norm_cspectra, 2)
1514
1521
1515 for i in range(num_pairs):
1522 for i in range(num_pairs):
1516 cspc_par[i,:,:] = __calculateMoments(norm_cspectra)
1523 cspc_par[i,:,:] = __calculateMoments(norm_cspectra)
1517 #------------------- Get Lags ----------------------------------
1524 #------------------- Get Lags ----------------------------------
1518
1525
1519 class SALags(Operation):
1526 class SALags(Operation):
1520 '''
1527 '''
1521 Function GetMoments()
1528 Function GetMoments()
1522
1529
1523 Input:
1530 Input:
1524 self.dataOut.data_pre
1531 self.dataOut.data_pre
1525 self.dataOut.abscissaList
1532 self.dataOut.abscissaList
1526 self.dataOut.noise
1533 self.dataOut.noise
1527 self.dataOut.normFactor
1534 self.dataOut.normFactor
1528 self.dataOut.data_SNR
1535 self.dataOut.data_SNR
1529 self.dataOut.groupList
1536 self.dataOut.groupList
1530 self.dataOut.nChannels
1537 self.dataOut.nChannels
1531
1538
1532 Affected:
1539 Affected:
1533 self.dataOut.data_param
1540 self.dataOut.data_param
1534
1541
1535 '''
1542 '''
1536 def run(self, dataOut):
1543 def run(self, dataOut):
1537 data_acf = dataOut.data_pre[0]
1544 data_acf = dataOut.data_pre[0]
1538 data_ccf = dataOut.data_pre[1]
1545 data_ccf = dataOut.data_pre[1]
1539 normFactor_acf = dataOut.normFactor[0]
1546 normFactor_acf = dataOut.normFactor[0]
1540 normFactor_ccf = dataOut.normFactor[1]
1547 normFactor_ccf = dataOut.normFactor[1]
1541 pairs_acf = dataOut.groupList[0]
1548 pairs_acf = dataOut.groupList[0]
1542 pairs_ccf = dataOut.groupList[1]
1549 pairs_ccf = dataOut.groupList[1]
1543
1550
1544 nHeights = dataOut.nHeights
1551 nHeights = dataOut.nHeights
1545 absc = dataOut.abscissaList
1552 absc = dataOut.abscissaList
1546 noise = dataOut.noise
1553 noise = dataOut.noise
1547 SNR = dataOut.data_SNR
1554 SNR = dataOut.data_SNR
1548 nChannels = dataOut.nChannels
1555 nChannels = dataOut.nChannels
1549 # pairsList = dataOut.groupList
1556 # pairsList = dataOut.groupList
1550 # pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairsList, nChannels)
1557 # pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairsList, nChannels)
1551
1558
1552 for l in range(len(pairs_acf)):
1559 for l in range(len(pairs_acf)):
1553 data_acf[l,:,:] = data_acf[l,:,:]/normFactor_acf[l,:]
1560 data_acf[l,:,:] = data_acf[l,:,:]/normFactor_acf[l,:]
1554
1561
1555 for l in range(len(pairs_ccf)):
1562 for l in range(len(pairs_ccf)):
1556 data_ccf[l,:,:] = data_ccf[l,:,:]/normFactor_ccf[l,:]
1563 data_ccf[l,:,:] = data_ccf[l,:,:]/normFactor_ccf[l,:]
1557
1564
1558 dataOut.data_param = numpy.zeros((len(pairs_ccf)*2 + 1, nHeights))
1565 dataOut.data_param = numpy.zeros((len(pairs_ccf)*2 + 1, nHeights))
1559 dataOut.data_param[:-1,:] = self.__calculateTaus(data_acf, data_ccf, absc)
1566 dataOut.data_param[:-1,:] = self.__calculateTaus(data_acf, data_ccf, absc)
1560 dataOut.data_param[-1,:] = self.__calculateLag1Phase(data_acf, absc)
1567 dataOut.data_param[-1,:] = self.__calculateLag1Phase(data_acf, absc)
1561 return
1568 return
1562
1569
1563 # def __getPairsAutoCorr(self, pairsList, nChannels):
1570 # def __getPairsAutoCorr(self, pairsList, nChannels):
1564 #
1571 #
1565 # pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan
1572 # pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan
1566 #
1573 #
1567 # for l in range(len(pairsList)):
1574 # for l in range(len(pairsList)):
1568 # firstChannel = pairsList[l][0]
1575 # firstChannel = pairsList[l][0]
1569 # secondChannel = pairsList[l][1]
1576 # secondChannel = pairsList[l][1]
1570 #
1577 #
1571 # #Obteniendo pares de Autocorrelacion
1578 # #Obteniendo pares de Autocorrelacion
1572 # if firstChannel == secondChannel:
1579 # if firstChannel == secondChannel:
1573 # pairsAutoCorr[firstChannel] = int(l)
1580 # pairsAutoCorr[firstChannel] = int(l)
1574 #
1581 #
1575 # pairsAutoCorr = pairsAutoCorr.astype(int)
1582 # pairsAutoCorr = pairsAutoCorr.astype(int)
1576 #
1583 #
1577 # pairsCrossCorr = range(len(pairsList))
1584 # pairsCrossCorr = range(len(pairsList))
1578 # pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr)
1585 # pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr)
1579 #
1586 #
1580 # return pairsAutoCorr, pairsCrossCorr
1587 # return pairsAutoCorr, pairsCrossCorr
1581
1588
1582 def __calculateTaus(self, data_acf, data_ccf, lagRange):
1589 def __calculateTaus(self, data_acf, data_ccf, lagRange):
1583
1590
1584 lag0 = data_acf.shape[1]/2
1591 lag0 = data_acf.shape[1]/2
1585 #Funcion de Autocorrelacion
1592 #Funcion de Autocorrelacion
1586 mean_acf = stats.nanmean(data_acf, axis = 0)
1593 mean_acf = stats.nanmean(data_acf, axis = 0)
1587
1594
1588 #Obtencion Indice de TauCross
1595 #Obtencion Indice de TauCross
1589 ind_ccf = data_ccf.argmax(axis = 1)
1596 ind_ccf = data_ccf.argmax(axis = 1)
1590 #Obtencion Indice de TauAuto
1597 #Obtencion Indice de TauAuto
1591 ind_acf = numpy.zeros(ind_ccf.shape,dtype = 'int')
1598 ind_acf = numpy.zeros(ind_ccf.shape,dtype = 'int')
1592 ccf_lag0 = data_ccf[:,lag0,:]
1599 ccf_lag0 = data_ccf[:,lag0,:]
1593
1600
1594 for i in range(ccf_lag0.shape[0]):
1601 for i in range(ccf_lag0.shape[0]):
1595 ind_acf[i,:] = numpy.abs(mean_acf - ccf_lag0[i,:]).argmin(axis = 0)
1602 ind_acf[i,:] = numpy.abs(mean_acf - ccf_lag0[i,:]).argmin(axis = 0)
1596
1603
1597 #Obtencion de TauCross y TauAuto
1604 #Obtencion de TauCross y TauAuto
1598 tau_ccf = lagRange[ind_ccf]
1605 tau_ccf = lagRange[ind_ccf]
1599 tau_acf = lagRange[ind_acf]
1606 tau_acf = lagRange[ind_acf]
1600
1607
1601 Nan1, Nan2 = numpy.where(tau_ccf == lagRange[0])
1608 Nan1, Nan2 = numpy.where(tau_ccf == lagRange[0])
1602
1609
1603 tau_ccf[Nan1,Nan2] = numpy.nan
1610 tau_ccf[Nan1,Nan2] = numpy.nan
1604 tau_acf[Nan1,Nan2] = numpy.nan
1611 tau_acf[Nan1,Nan2] = numpy.nan
1605 tau = numpy.vstack((tau_ccf,tau_acf))
1612 tau = numpy.vstack((tau_ccf,tau_acf))
1606
1613
1607 return tau
1614 return tau
1608
1615
1609 def __calculateLag1Phase(self, data, lagTRange):
1616 def __calculateLag1Phase(self, data, lagTRange):
1610 data1 = stats.nanmean(data, axis = 0)
1617 data1 = stats.nanmean(data, axis = 0)
1611 lag1 = numpy.where(lagTRange == 0)[0][0] + 1
1618 lag1 = numpy.where(lagTRange == 0)[0][0] + 1
1612
1619
1613 phase = numpy.angle(data1[lag1,:])
1620 phase = numpy.angle(data1[lag1,:])
1614
1621
1615 return phase
1622 return phase
1616
1623
1617 class SpectralFitting(Operation):
1624 class SpectralFitting(Operation):
1618 '''
1625 '''
1619 Function GetMoments()
1626 Function GetMoments()
1620
1627
1621 Input:
1628 Input:
1622 Output:
1629 Output:
1623 Variables modified:
1630 Variables modified:
1624 '''
1631 '''
1625
1632
1626 def run(self, dataOut, getSNR = True, path=None, file=None, groupList=None):
1633 def run(self, dataOut, getSNR = True, path=None, file=None, groupList=None):
1627
1634
1628
1635
1629 if path != None:
1636 if path != None:
1630 sys.path.append(path)
1637 sys.path.append(path)
1631 self.dataOut.library = importlib.import_module(file)
1638 self.dataOut.library = importlib.import_module(file)
1632
1639
1633 #To be inserted as a parameter
1640 #To be inserted as a parameter
1634 groupArray = numpy.array(groupList)
1641 groupArray = numpy.array(groupList)
1635 # groupArray = numpy.array([[0,1],[2,3]])
1642 # groupArray = numpy.array([[0,1],[2,3]])
1636 self.dataOut.groupList = groupArray
1643 self.dataOut.groupList = groupArray
1637
1644
1638 nGroups = groupArray.shape[0]
1645 nGroups = groupArray.shape[0]
1639 nChannels = self.dataIn.nChannels
1646 nChannels = self.dataIn.nChannels
1640 nHeights=self.dataIn.heightList.size
1647 nHeights=self.dataIn.heightList.size
1641
1648
1642 #Parameters Array
1649 #Parameters Array
1643 self.dataOut.data_param = None
1650 self.dataOut.data_param = None
1644
1651
1645 #Set constants
1652 #Set constants
1646 constants = self.dataOut.library.setConstants(self.dataIn)
1653 constants = self.dataOut.library.setConstants(self.dataIn)
1647 self.dataOut.constants = constants
1654 self.dataOut.constants = constants
1648 M = self.dataIn.normFactor
1655 M = self.dataIn.normFactor
1649 N = self.dataIn.nFFTPoints
1656 N = self.dataIn.nFFTPoints
1650 ippSeconds = self.dataIn.ippSeconds
1657 ippSeconds = self.dataIn.ippSeconds
1651 K = self.dataIn.nIncohInt
1658 K = self.dataIn.nIncohInt
1652 pairsArray = numpy.array(self.dataIn.pairsList)
1659 pairsArray = numpy.array(self.dataIn.pairsList)
1653
1660
1654 #List of possible combinations
1661 #List of possible combinations
1655 listComb = itertools.combinations(numpy.arange(groupArray.shape[1]),2)
1662 listComb = itertools.combinations(numpy.arange(groupArray.shape[1]),2)
1656 indCross = numpy.zeros(len(list(listComb)), dtype = 'int')
1663 indCross = numpy.zeros(len(list(listComb)), dtype = 'int')
1657
1664
1658 if getSNR:
1665 if getSNR:
1659 listChannels = groupArray.reshape((groupArray.size))
1666 listChannels = groupArray.reshape((groupArray.size))
1660 listChannels.sort()
1667 listChannels.sort()
1661 noise = self.dataIn.getNoise()
1668 noise = self.dataIn.getNoise()
1662 self.dataOut.data_SNR = self.__getSNR(self.dataIn.data_spc[listChannels,:,:], noise[listChannels])
1669 self.dataOut.data_SNR = self.__getSNR(self.dataIn.data_spc[listChannels,:,:], noise[listChannels])
1663
1670
1664 for i in range(nGroups):
1671 for i in range(nGroups):
1665 coord = groupArray[i,:]
1672 coord = groupArray[i,:]
1666
1673
1667 #Input data array
1674 #Input data array
1668 data = self.dataIn.data_spc[coord,:,:]/(M*N)
1675 data = self.dataIn.data_spc[coord,:,:]/(M*N)
1669 data = data.reshape((data.shape[0]*data.shape[1],data.shape[2]))
1676 data = data.reshape((data.shape[0]*data.shape[1],data.shape[2]))
1670
1677
1671 #Cross Spectra data array for Covariance Matrixes
1678 #Cross Spectra data array for Covariance Matrixes
1672 ind = 0
1679 ind = 0
1673 for pairs in listComb:
1680 for pairs in listComb:
1674 pairsSel = numpy.array([coord[x],coord[y]])
1681 pairsSel = numpy.array([coord[x],coord[y]])
1675 indCross[ind] = int(numpy.where(numpy.all(pairsArray == pairsSel, axis = 1))[0][0])
1682 indCross[ind] = int(numpy.where(numpy.all(pairsArray == pairsSel, axis = 1))[0][0])
1676 ind += 1
1683 ind += 1
1677 dataCross = self.dataIn.data_cspc[indCross,:,:]/(M*N)
1684 dataCross = self.dataIn.data_cspc[indCross,:,:]/(M*N)
1678 dataCross = dataCross**2/K
1685 dataCross = dataCross**2/K
1679
1686
1680 for h in range(nHeights):
1687 for h in range(nHeights):
1681 # print self.dataOut.heightList[h]
1688 # print self.dataOut.heightList[h]
1682
1689
1683 #Input
1690 #Input
1684 d = data[:,h]
1691 d = data[:,h]
1685
1692
1686 #Covariance Matrix
1693 #Covariance Matrix
1687 D = numpy.diag(d**2/K)
1694 D = numpy.diag(d**2/K)
1688 ind = 0
1695 ind = 0
1689 for pairs in listComb:
1696 for pairs in listComb:
1690 #Coordinates in Covariance Matrix
1697 #Coordinates in Covariance Matrix
1691 x = pairs[0]
1698 x = pairs[0]
1692 y = pairs[1]
1699 y = pairs[1]
1693 #Channel Index
1700 #Channel Index
1694 S12 = dataCross[ind,:,h]
1701 S12 = dataCross[ind,:,h]
1695 D12 = numpy.diag(S12)
1702 D12 = numpy.diag(S12)
1696 #Completing Covariance Matrix with Cross Spectras
1703 #Completing Covariance Matrix with Cross Spectras
1697 D[x*N:(x+1)*N,y*N:(y+1)*N] = D12
1704 D[x*N:(x+1)*N,y*N:(y+1)*N] = D12
1698 D[y*N:(y+1)*N,x*N:(x+1)*N] = D12
1705 D[y*N:(y+1)*N,x*N:(x+1)*N] = D12
1699 ind += 1
1706 ind += 1
1700 Dinv=numpy.linalg.inv(D)
1707 Dinv=numpy.linalg.inv(D)
1701 L=numpy.linalg.cholesky(Dinv)
1708 L=numpy.linalg.cholesky(Dinv)
1702 LT=L.T
1709 LT=L.T
1703
1710
1704 dp = numpy.dot(LT,d)
1711 dp = numpy.dot(LT,d)
1705
1712
1706 #Initial values
1713 #Initial values
1707 data_spc = self.dataIn.data_spc[coord,:,h]
1714 data_spc = self.dataIn.data_spc[coord,:,h]
1708
1715
1709 if (h>0)and(error1[3]<5):
1716 if (h>0)and(error1[3]<5):
1710 p0 = self.dataOut.data_param[i,:,h-1]
1717 p0 = self.dataOut.data_param[i,:,h-1]
1711 else:
1718 else:
1712 p0 = numpy.array(self.dataOut.library.initialValuesFunction(data_spc, constants, i))
1719 p0 = numpy.array(self.dataOut.library.initialValuesFunction(data_spc, constants, i))
1713
1720
1714 try:
1721 try:
1715 #Least Squares
1722 #Least Squares
1716 minp,covp,infodict,mesg,ier = optimize.leastsq(self.__residFunction,p0,args=(dp,LT,constants),full_output=True)
1723 minp,covp,infodict,mesg,ier = optimize.leastsq(self.__residFunction,p0,args=(dp,LT,constants),full_output=True)
1717 # minp,covp = optimize.leastsq(self.__residFunction,p0,args=(dp,LT,constants))
1724 # minp,covp = optimize.leastsq(self.__residFunction,p0,args=(dp,LT,constants))
1718 #Chi square error
1725 #Chi square error
1719 error0 = numpy.sum(infodict['fvec']**2)/(2*N)
1726 error0 = numpy.sum(infodict['fvec']**2)/(2*N)
1720 #Error with Jacobian
1727 #Error with Jacobian
1721 error1 = self.dataOut.library.errorFunction(minp,constants,LT)
1728 error1 = self.dataOut.library.errorFunction(minp,constants,LT)
1722 except:
1729 except:
1723 minp = p0*numpy.nan
1730 minp = p0*numpy.nan
1724 error0 = numpy.nan
1731 error0 = numpy.nan
1725 error1 = p0*numpy.nan
1732 error1 = p0*numpy.nan
1726
1733
1727 #Save
1734 #Save
1728 if self.dataOut.data_param == None:
1735 if self.dataOut.data_param == None:
1729 self.dataOut.data_param = numpy.zeros((nGroups, p0.size, nHeights))*numpy.nan
1736 self.dataOut.data_param = numpy.zeros((nGroups, p0.size, nHeights))*numpy.nan
1730 self.dataOut.data_error = numpy.zeros((nGroups, p0.size + 1, nHeights))*numpy.nan
1737 self.dataOut.data_error = numpy.zeros((nGroups, p0.size + 1, nHeights))*numpy.nan
1731
1738
1732 self.dataOut.data_error[i,:,h] = numpy.hstack((error0,error1))
1739 self.dataOut.data_error[i,:,h] = numpy.hstack((error0,error1))
1733 self.dataOut.data_param[i,:,h] = minp
1740 self.dataOut.data_param[i,:,h] = minp
1734 return
1741 return
1735
1742
1736 def __residFunction(self, p, dp, LT, constants):
1743 def __residFunction(self, p, dp, LT, constants):
1737
1744
1738 fm = self.dataOut.library.modelFunction(p, constants)
1745 fm = self.dataOut.library.modelFunction(p, constants)
1739 fmp=numpy.dot(LT,fm)
1746 fmp=numpy.dot(LT,fm)
1740
1747
1741 return dp-fmp
1748 return dp-fmp
1742
1749
1743 def __getSNR(self, z, noise):
1750 def __getSNR(self, z, noise):
1744
1751
1745 avg = numpy.average(z, axis=1)
1752 avg = numpy.average(z, axis=1)
1746 SNR = (avg.T-noise)/noise
1753 SNR = (avg.T-noise)/noise
1747 SNR = SNR.T
1754 SNR = SNR.T
1748 return SNR
1755 return SNR
1749
1756
1750 def __chisq(p,chindex,hindex):
1757 def __chisq(p,chindex,hindex):
1751 #similar to Resid but calculates CHI**2
1758 #similar to Resid but calculates CHI**2
1752 [LT,d,fm]=setupLTdfm(p,chindex,hindex)
1759 [LT,d,fm]=setupLTdfm(p,chindex,hindex)
1753 dp=numpy.dot(LT,d)
1760 dp=numpy.dot(LT,d)
1754 fmp=numpy.dot(LT,fm)
1761 fmp=numpy.dot(LT,fm)
1755 chisq=numpy.dot((dp-fmp).T,(dp-fmp))
1762 chisq=numpy.dot((dp-fmp).T,(dp-fmp))
1756 return chisq
1763 return chisq
1757
1764
1758 class WindProfiler(Operation):
1765 class WindProfiler(Operation):
1759
1766
1760 __isConfig = False
1767 __isConfig = False
1761
1768
1762 __initime = None
1769 __initime = None
1763 __lastdatatime = None
1770 __lastdatatime = None
1764 __integrationtime = None
1771 __integrationtime = None
1765
1772
1766 __buffer = None
1773 __buffer = None
1767
1774
1768 __dataReady = False
1775 __dataReady = False
1769
1776
1770 __firstdata = None
1777 __firstdata = None
1771
1778
1772 n = None
1779 n = None
1773
1780
1774 def __init__(self):
1781 def __init__(self):
1775 Operation.__init__(self)
1782 Operation.__init__(self)
1776
1783
1777 def __calculateCosDir(self, elev, azim):
1784 def __calculateCosDir(self, elev, azim):
1778 zen = (90 - elev)*numpy.pi/180
1785 zen = (90 - elev)*numpy.pi/180
1779 azim = azim*numpy.pi/180
1786 azim = azim*numpy.pi/180
1780 cosDirX = numpy.sqrt((1-numpy.cos(zen)**2)/((1+numpy.tan(azim)**2)))
1787 cosDirX = numpy.sqrt((1-numpy.cos(zen)**2)/((1+numpy.tan(azim)**2)))
1781 cosDirY = numpy.sqrt(1-numpy.cos(zen)**2-cosDirX**2)
1788 cosDirY = numpy.sqrt(1-numpy.cos(zen)**2-cosDirX**2)
1782
1789
1783 signX = numpy.sign(numpy.cos(azim))
1790 signX = numpy.sign(numpy.cos(azim))
1784 signY = numpy.sign(numpy.sin(azim))
1791 signY = numpy.sign(numpy.sin(azim))
1785
1792
1786 cosDirX = numpy.copysign(cosDirX, signX)
1793 cosDirX = numpy.copysign(cosDirX, signX)
1787 cosDirY = numpy.copysign(cosDirY, signY)
1794 cosDirY = numpy.copysign(cosDirY, signY)
1788 return cosDirX, cosDirY
1795 return cosDirX, cosDirY
1789
1796
1790 def __calculateAngles(self, theta_x, theta_y, azimuth):
1797 def __calculateAngles(self, theta_x, theta_y, azimuth):
1791
1798
1792 dir_cosw = numpy.sqrt(1-theta_x**2-theta_y**2)
1799 dir_cosw = numpy.sqrt(1-theta_x**2-theta_y**2)
1793 zenith_arr = numpy.arccos(dir_cosw)
1800 zenith_arr = numpy.arccos(dir_cosw)
1794 azimuth_arr = numpy.arctan2(theta_x,theta_y) + azimuth*math.pi/180
1801 azimuth_arr = numpy.arctan2(theta_x,theta_y) + azimuth*math.pi/180
1795
1802
1796 dir_cosu = numpy.sin(azimuth_arr)*numpy.sin(zenith_arr)
1803 dir_cosu = numpy.sin(azimuth_arr)*numpy.sin(zenith_arr)
1797 dir_cosv = numpy.cos(azimuth_arr)*numpy.sin(zenith_arr)
1804 dir_cosv = numpy.cos(azimuth_arr)*numpy.sin(zenith_arr)
1798
1805
1799 return azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw
1806 return azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw
1800
1807
1801 def __calculateMatA(self, dir_cosu, dir_cosv, dir_cosw, horOnly):
1808 def __calculateMatA(self, dir_cosu, dir_cosv, dir_cosw, horOnly):
1802
1809
1803 #
1810 #
1804 if horOnly:
1811 if horOnly:
1805 A = numpy.c_[dir_cosu,dir_cosv]
1812 A = numpy.c_[dir_cosu,dir_cosv]
1806 else:
1813 else:
1807 A = numpy.c_[dir_cosu,dir_cosv,dir_cosw]
1814 A = numpy.c_[dir_cosu,dir_cosv,dir_cosw]
1808 A = numpy.asmatrix(A)
1815 A = numpy.asmatrix(A)
1809 A1 = numpy.linalg.inv(A.transpose()*A)*A.transpose()
1816 A1 = numpy.linalg.inv(A.transpose()*A)*A.transpose()
1810
1817
1811 return A1
1818 return A1
1812
1819
1813 def __correctValues(self, heiRang, phi, velRadial, SNR):
1820 def __correctValues(self, heiRang, phi, velRadial, SNR):
1814 listPhi = phi.tolist()
1821 listPhi = phi.tolist()
1815 maxid = listPhi.index(max(listPhi))
1822 maxid = listPhi.index(max(listPhi))
1816 minid = listPhi.index(min(listPhi))
1823 minid = listPhi.index(min(listPhi))
1817
1824
1818 rango = range(len(phi))
1825 rango = range(len(phi))
1819 # rango = numpy.delete(rango,maxid)
1826 # rango = numpy.delete(rango,maxid)
1820
1827
1821 heiRang1 = heiRang*math.cos(phi[maxid])
1828 heiRang1 = heiRang*math.cos(phi[maxid])
1822 heiRangAux = heiRang*math.cos(phi[minid])
1829 heiRangAux = heiRang*math.cos(phi[minid])
1823 indOut = (heiRang1 < heiRangAux[0]).nonzero()
1830 indOut = (heiRang1 < heiRangAux[0]).nonzero()
1824 heiRang1 = numpy.delete(heiRang1,indOut)
1831 heiRang1 = numpy.delete(heiRang1,indOut)
1825
1832
1826 velRadial1 = numpy.zeros([len(phi),len(heiRang1)])
1833 velRadial1 = numpy.zeros([len(phi),len(heiRang1)])
1827 SNR1 = numpy.zeros([len(phi),len(heiRang1)])
1834 SNR1 = numpy.zeros([len(phi),len(heiRang1)])
1828
1835
1829 for i in rango:
1836 for i in rango:
1830 x = heiRang*math.cos(phi[i])
1837 x = heiRang*math.cos(phi[i])
1831 y1 = velRadial[i,:]
1838 y1 = velRadial[i,:]
1832 f1 = interpolate.interp1d(x,y1,kind = 'cubic')
1839 f1 = interpolate.interp1d(x,y1,kind = 'cubic')
1833
1840
1834 x1 = heiRang1
1841 x1 = heiRang1
1835 y11 = f1(x1)
1842 y11 = f1(x1)
1836
1843
1837 y2 = SNR[i,:]
1844 y2 = SNR[i,:]
1838 f2 = interpolate.interp1d(x,y2,kind = 'cubic')
1845 f2 = interpolate.interp1d(x,y2,kind = 'cubic')
1839 y21 = f2(x1)
1846 y21 = f2(x1)
1840
1847
1841 velRadial1[i,:] = y11
1848 velRadial1[i,:] = y11
1842 SNR1[i,:] = y21
1849 SNR1[i,:] = y21
1843
1850
1844 return heiRang1, velRadial1, SNR1
1851 return heiRang1, velRadial1, SNR1
1845
1852
1846 def __calculateVelUVW(self, A, velRadial):
1853 def __calculateVelUVW(self, A, velRadial):
1847
1854
1848 #Operacion Matricial
1855 #Operacion Matricial
1849 # velUVW = numpy.zeros((velRadial.shape[1],3))
1856 # velUVW = numpy.zeros((velRadial.shape[1],3))
1850 # for ind in range(velRadial.shape[1]):
1857 # for ind in range(velRadial.shape[1]):
1851 # velUVW[ind,:] = numpy.dot(A,velRadial[:,ind])
1858 # velUVW[ind,:] = numpy.dot(A,velRadial[:,ind])
1852 # velUVW = velUVW.transpose()
1859 # velUVW = velUVW.transpose()
1853 velUVW = numpy.zeros((A.shape[0],velRadial.shape[1]))
1860 velUVW = numpy.zeros((A.shape[0],velRadial.shape[1]))
1854 velUVW[:,:] = numpy.dot(A,velRadial)
1861 velUVW[:,:] = numpy.dot(A,velRadial)
1855
1862
1856
1863
1857 return velUVW
1864 return velUVW
1858
1865
1859 # def techniqueDBS(self, velRadial0, dirCosx, disrCosy, azimuth, correct, horizontalOnly, heiRang, SNR0):
1866 # def techniqueDBS(self, velRadial0, dirCosx, disrCosy, azimuth, correct, horizontalOnly, heiRang, SNR0):
1860
1867
1861 def techniqueDBS(self, kwargs):
1868 def techniqueDBS(self, kwargs):
1862 """
1869 """
1863 Function that implements Doppler Beam Swinging (DBS) technique.
1870 Function that implements Doppler Beam Swinging (DBS) technique.
1864
1871
1865 Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth,
1872 Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth,
1866 Direction correction (if necessary), Ranges and SNR
1873 Direction correction (if necessary), Ranges and SNR
1867
1874
1868 Output: Winds estimation (Zonal, Meridional and Vertical)
1875 Output: Winds estimation (Zonal, Meridional and Vertical)
1869
1876
1870 Parameters affected: Winds, height range, SNR
1877 Parameters affected: Winds, height range, SNR
1871 """
1878 """
1872 velRadial0 = kwargs['velRadial']
1879 velRadial0 = kwargs['velRadial']
1873 heiRang = kwargs['heightList']
1880 heiRang = kwargs['heightList']
1874 SNR0 = kwargs['SNR']
1881 SNR0 = kwargs['SNR']
1875
1882
1876 if kwargs.has_key('dirCosx') and kwargs.has_key('dirCosy'):
1883 if kwargs.has_key('dirCosx') and kwargs.has_key('dirCosy'):
1877 theta_x = numpy.array(kwargs['dirCosx'])
1884 theta_x = numpy.array(kwargs['dirCosx'])
1878 theta_y = numpy.array(kwargs['dirCosy'])
1885 theta_y = numpy.array(kwargs['dirCosy'])
1879 else:
1886 else:
1880 elev = numpy.array(kwargs['elevation'])
1887 elev = numpy.array(kwargs['elevation'])
1881 azim = numpy.array(kwargs['azimuth'])
1888 azim = numpy.array(kwargs['azimuth'])
1882 theta_x, theta_y = self.__calculateCosDir(elev, azim)
1889 theta_x, theta_y = self.__calculateCosDir(elev, azim)
1883 azimuth = kwargs['correctAzimuth']
1890 azimuth = kwargs['correctAzimuth']
1884 if kwargs.has_key('horizontalOnly'):
1891 if kwargs.has_key('horizontalOnly'):
1885 horizontalOnly = kwargs['horizontalOnly']
1892 horizontalOnly = kwargs['horizontalOnly']
1886 else: horizontalOnly = False
1893 else: horizontalOnly = False
1887 if kwargs.has_key('correctFactor'):
1894 if kwargs.has_key('correctFactor'):
1888 correctFactor = kwargs['correctFactor']
1895 correctFactor = kwargs['correctFactor']
1889 else: correctFactor = 1
1896 else: correctFactor = 1
1890 if kwargs.has_key('channelList'):
1897 if kwargs.has_key('channelList'):
1891 channelList = kwargs['channelList']
1898 channelList = kwargs['channelList']
1892 if len(channelList) == 2:
1899 if len(channelList) == 2:
1893 horizontalOnly = True
1900 horizontalOnly = True
1894 arrayChannel = numpy.array(channelList)
1901 arrayChannel = numpy.array(channelList)
1895 param = param[arrayChannel,:,:]
1902 param = param[arrayChannel,:,:]
1896 theta_x = theta_x[arrayChannel]
1903 theta_x = theta_x[arrayChannel]
1897 theta_y = theta_y[arrayChannel]
1904 theta_y = theta_y[arrayChannel]
1898
1905
1899 azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw = self.__calculateAngles(theta_x, theta_y, azimuth)
1906 azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw = self.__calculateAngles(theta_x, theta_y, azimuth)
1900 heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, zenith_arr, correctFactor*velRadial0, SNR0)
1907 heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, zenith_arr, correctFactor*velRadial0, SNR0)
1901 A = self.__calculateMatA(dir_cosu, dir_cosv, dir_cosw, horizontalOnly)
1908 A = self.__calculateMatA(dir_cosu, dir_cosv, dir_cosw, horizontalOnly)
1902
1909
1903 #Calculo de Componentes de la velocidad con DBS
1910 #Calculo de Componentes de la velocidad con DBS
1904 winds = self.__calculateVelUVW(A,velRadial1)
1911 winds = self.__calculateVelUVW(A,velRadial1)
1905
1912
1906 return winds, heiRang1, SNR1
1913 return winds, heiRang1, SNR1
1907
1914
1908 def __calculateDistance(self, posx, posy, pairs_ccf, azimuth = None):
1915 def __calculateDistance(self, posx, posy, pairs_ccf, azimuth = None):
1909
1916
1910 nPairs = len(pairs_ccf)
1917 nPairs = len(pairs_ccf)
1911 posx = numpy.asarray(posx)
1918 posx = numpy.asarray(posx)
1912 posy = numpy.asarray(posy)
1919 posy = numpy.asarray(posy)
1913
1920
1914 #Rotacion Inversa para alinear con el azimuth
1921 #Rotacion Inversa para alinear con el azimuth
1915 if azimuth!= None:
1922 if azimuth!= None:
1916 azimuth = azimuth*math.pi/180
1923 azimuth = azimuth*math.pi/180
1917 posx1 = posx*math.cos(azimuth) + posy*math.sin(azimuth)
1924 posx1 = posx*math.cos(azimuth) + posy*math.sin(azimuth)
1918 posy1 = -posx*math.sin(azimuth) + posy*math.cos(azimuth)
1925 posy1 = -posx*math.sin(azimuth) + posy*math.cos(azimuth)
1919 else:
1926 else:
1920 posx1 = posx
1927 posx1 = posx
1921 posy1 = posy
1928 posy1 = posy
1922
1929
1923 #Calculo de Distancias
1930 #Calculo de Distancias
1924 distx = numpy.zeros(nPairs)
1931 distx = numpy.zeros(nPairs)
1925 disty = numpy.zeros(nPairs)
1932 disty = numpy.zeros(nPairs)
1926 dist = numpy.zeros(nPairs)
1933 dist = numpy.zeros(nPairs)
1927 ang = numpy.zeros(nPairs)
1934 ang = numpy.zeros(nPairs)
1928
1935
1929 for i in range(nPairs):
1936 for i in range(nPairs):
1930 distx[i] = posx1[pairs_ccf[i][1]] - posx1[pairs_ccf[i][0]]
1937 distx[i] = posx1[pairs_ccf[i][1]] - posx1[pairs_ccf[i][0]]
1931 disty[i] = posy1[pairs_ccf[i][1]] - posy1[pairs_ccf[i][0]]
1938 disty[i] = posy1[pairs_ccf[i][1]] - posy1[pairs_ccf[i][0]]
1932 dist[i] = numpy.sqrt(distx[i]**2 + disty[i]**2)
1939 dist[i] = numpy.sqrt(distx[i]**2 + disty[i]**2)
1933 ang[i] = numpy.arctan2(disty[i],distx[i])
1940 ang[i] = numpy.arctan2(disty[i],distx[i])
1934
1941
1935 return distx, disty, dist, ang
1942 return distx, disty, dist, ang
1936 #Calculo de Matrices
1943 #Calculo de Matrices
1937 # nPairs = len(pairs)
1944 # nPairs = len(pairs)
1938 # ang1 = numpy.zeros((nPairs, 2, 1))
1945 # ang1 = numpy.zeros((nPairs, 2, 1))
1939 # dist1 = numpy.zeros((nPairs, 2, 1))
1946 # dist1 = numpy.zeros((nPairs, 2, 1))
1940 #
1947 #
1941 # for j in range(nPairs):
1948 # for j in range(nPairs):
1942 # dist1[j,0,0] = dist[pairs[j][0]]
1949 # dist1[j,0,0] = dist[pairs[j][0]]
1943 # dist1[j,1,0] = dist[pairs[j][1]]
1950 # dist1[j,1,0] = dist[pairs[j][1]]
1944 # ang1[j,0,0] = ang[pairs[j][0]]
1951 # ang1[j,0,0] = ang[pairs[j][0]]
1945 # ang1[j,1,0] = ang[pairs[j][1]]
1952 # ang1[j,1,0] = ang[pairs[j][1]]
1946 #
1953 #
1947 # return distx,disty, dist1,ang1
1954 # return distx,disty, dist1,ang1
1948
1955
1949
1956
1950 def __calculateVelVer(self, phase, lagTRange, _lambda):
1957 def __calculateVelVer(self, phase, lagTRange, _lambda):
1951
1958
1952 Ts = lagTRange[1] - lagTRange[0]
1959 Ts = lagTRange[1] - lagTRange[0]
1953 velW = -_lambda*phase/(4*math.pi*Ts)
1960 velW = -_lambda*phase/(4*math.pi*Ts)
1954
1961
1955 return velW
1962 return velW
1956
1963
1957 def __calculateVelHorDir(self, dist, tau1, tau2, ang):
1964 def __calculateVelHorDir(self, dist, tau1, tau2, ang):
1958 nPairs = tau1.shape[0]
1965 nPairs = tau1.shape[0]
1959 nHeights = tau1.shape[1]
1966 nHeights = tau1.shape[1]
1960 vel = numpy.zeros((nPairs,3,nHeights))
1967 vel = numpy.zeros((nPairs,3,nHeights))
1961 dist1 = numpy.reshape(dist, (dist.size,1))
1968 dist1 = numpy.reshape(dist, (dist.size,1))
1962
1969
1963 angCos = numpy.cos(ang)
1970 angCos = numpy.cos(ang)
1964 angSin = numpy.sin(ang)
1971 angSin = numpy.sin(ang)
1965
1972
1966 vel0 = dist1*tau1/(2*tau2**2)
1973 vel0 = dist1*tau1/(2*tau2**2)
1967 vel[:,0,:] = (vel0*angCos).sum(axis = 1)
1974 vel[:,0,:] = (vel0*angCos).sum(axis = 1)
1968 vel[:,1,:] = (vel0*angSin).sum(axis = 1)
1975 vel[:,1,:] = (vel0*angSin).sum(axis = 1)
1969
1976
1970 ind = numpy.where(numpy.isinf(vel))
1977 ind = numpy.where(numpy.isinf(vel))
1971 vel[ind] = numpy.nan
1978 vel[ind] = numpy.nan
1972
1979
1973 return vel
1980 return vel
1974
1981
1975 # def __getPairsAutoCorr(self, pairsList, nChannels):
1982 # def __getPairsAutoCorr(self, pairsList, nChannels):
1976 #
1983 #
1977 # pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan
1984 # pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan
1978 #
1985 #
1979 # for l in range(len(pairsList)):
1986 # for l in range(len(pairsList)):
1980 # firstChannel = pairsList[l][0]
1987 # firstChannel = pairsList[l][0]
1981 # secondChannel = pairsList[l][1]
1988 # secondChannel = pairsList[l][1]
1982 #
1989 #
1983 # #Obteniendo pares de Autocorrelacion
1990 # #Obteniendo pares de Autocorrelacion
1984 # if firstChannel == secondChannel:
1991 # if firstChannel == secondChannel:
1985 # pairsAutoCorr[firstChannel] = int(l)
1992 # pairsAutoCorr[firstChannel] = int(l)
1986 #
1993 #
1987 # pairsAutoCorr = pairsAutoCorr.astype(int)
1994 # pairsAutoCorr = pairsAutoCorr.astype(int)
1988 #
1995 #
1989 # pairsCrossCorr = range(len(pairsList))
1996 # pairsCrossCorr = range(len(pairsList))
1990 # pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr)
1997 # pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr)
1991 #
1998 #
1992 # return pairsAutoCorr, pairsCrossCorr
1999 # return pairsAutoCorr, pairsCrossCorr
1993
2000
1994 # def techniqueSA(self, pairsSelected, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, lagTRange, correctFactor):
2001 # def techniqueSA(self, pairsSelected, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, lagTRange, correctFactor):
1995 def techniqueSA(self, kwargs):
2002 def techniqueSA(self, kwargs):
1996
2003
1997 """
2004 """
1998 Function that implements Spaced Antenna (SA) technique.
2005 Function that implements Spaced Antenna (SA) technique.
1999
2006
2000 Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth,
2007 Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth,
2001 Direction correction (if necessary), Ranges and SNR
2008 Direction correction (if necessary), Ranges and SNR
2002
2009
2003 Output: Winds estimation (Zonal, Meridional and Vertical)
2010 Output: Winds estimation (Zonal, Meridional and Vertical)
2004
2011
2005 Parameters affected: Winds
2012 Parameters affected: Winds
2006 """
2013 """
2007 position_x = kwargs['positionX']
2014 position_x = kwargs['positionX']
2008 position_y = kwargs['positionY']
2015 position_y = kwargs['positionY']
2009 azimuth = kwargs['azimuth']
2016 azimuth = kwargs['azimuth']
2010
2017
2011 if kwargs.has_key('correctFactor'):
2018 if kwargs.has_key('correctFactor'):
2012 correctFactor = kwargs['correctFactor']
2019 correctFactor = kwargs['correctFactor']
2013 else:
2020 else:
2014 correctFactor = 1
2021 correctFactor = 1
2015
2022
2016 groupList = kwargs['groupList']
2023 groupList = kwargs['groupList']
2017 pairs_ccf = groupList[1]
2024 pairs_ccf = groupList[1]
2018 tau = kwargs['tau']
2025 tau = kwargs['tau']
2019 _lambda = kwargs['_lambda']
2026 _lambda = kwargs['_lambda']
2020
2027
2021 #Cross Correlation pairs obtained
2028 #Cross Correlation pairs obtained
2022 # pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairssList, nChannels)
2029 # pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairssList, nChannels)
2023 # pairsArray = numpy.array(pairsList)[pairsCrossCorr]
2030 # pairsArray = numpy.array(pairsList)[pairsCrossCorr]
2024 # pairsSelArray = numpy.array(pairsSelected)
2031 # pairsSelArray = numpy.array(pairsSelected)
2025 # pairs = []
2032 # pairs = []
2026 #
2033 #
2027 # #Wind estimation pairs obtained
2034 # #Wind estimation pairs obtained
2028 # for i in range(pairsSelArray.shape[0]/2):
2035 # for i in range(pairsSelArray.shape[0]/2):
2029 # ind1 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i], axis = 1))[0][0]
2036 # ind1 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i], axis = 1))[0][0]
2030 # ind2 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i + 1], axis = 1))[0][0]
2037 # ind2 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i + 1], axis = 1))[0][0]
2031 # pairs.append((ind1,ind2))
2038 # pairs.append((ind1,ind2))
2032
2039
2033 indtau = tau.shape[0]/2
2040 indtau = tau.shape[0]/2
2034 tau1 = tau[:indtau,:]
2041 tau1 = tau[:indtau,:]
2035 tau2 = tau[indtau:-1,:]
2042 tau2 = tau[indtau:-1,:]
2036 # tau1 = tau1[pairs,:]
2043 # tau1 = tau1[pairs,:]
2037 # tau2 = tau2[pairs,:]
2044 # tau2 = tau2[pairs,:]
2038 phase1 = tau[-1,:]
2045 phase1 = tau[-1,:]
2039
2046
2040 #---------------------------------------------------------------------
2047 #---------------------------------------------------------------------
2041 #Metodo Directo
2048 #Metodo Directo
2042 distx, disty, dist, ang = self.__calculateDistance(position_x, position_y, pairs_ccf,azimuth)
2049 distx, disty, dist, ang = self.__calculateDistance(position_x, position_y, pairs_ccf,azimuth)
2043 winds = self.__calculateVelHorDir(dist, tau1, tau2, ang)
2050 winds = self.__calculateVelHorDir(dist, tau1, tau2, ang)
2044 winds = stats.nanmean(winds, axis=0)
2051 winds = stats.nanmean(winds, axis=0)
2045 #---------------------------------------------------------------------
2052 #---------------------------------------------------------------------
2046 #Metodo General
2053 #Metodo General
2047 # distx, disty, dist = self.calculateDistance(position_x,position_y,pairsCrossCorr, pairsList, azimuth)
2054 # distx, disty, dist = self.calculateDistance(position_x,position_y,pairsCrossCorr, pairsList, azimuth)
2048 # #Calculo Coeficientes de Funcion de Correlacion
2055 # #Calculo Coeficientes de Funcion de Correlacion
2049 # F,G,A,B,H = self.calculateCoef(tau1,tau2,distx,disty,n)
2056 # F,G,A,B,H = self.calculateCoef(tau1,tau2,distx,disty,n)
2050 # #Calculo de Velocidades
2057 # #Calculo de Velocidades
2051 # winds = self.calculateVelUV(F,G,A,B,H)
2058 # winds = self.calculateVelUV(F,G,A,B,H)
2052
2059
2053 #---------------------------------------------------------------------
2060 #---------------------------------------------------------------------
2054 winds[2,:] = self.__calculateVelVer(phase1, lagTRange, _lambda)
2061 winds[2,:] = self.__calculateVelVer(phase1, lagTRange, _lambda)
2055 winds = correctFactor*winds
2062 winds = correctFactor*winds
2056 return winds
2063 return winds
2057
2064
2058 def __checkTime(self, currentTime, paramInterval, outputInterval):
2065 def __checkTime(self, currentTime, paramInterval, outputInterval):
2059
2066
2060 dataTime = currentTime + paramInterval
2067 dataTime = currentTime + paramInterval
2061 deltaTime = dataTime - self.__initime
2068 deltaTime = dataTime - self.__initime
2062
2069
2063 if deltaTime >= outputInterval or deltaTime < 0:
2070 if deltaTime >= outputInterval or deltaTime < 0:
2064 self.__dataReady = True
2071 self.__dataReady = True
2065 return
2072 return
2066
2073
2067 def techniqueMeteors(self, arrayMeteor, meteorThresh, heightMin, heightMax):
2074 def techniqueMeteors(self, arrayMeteor, meteorThresh, heightMin, heightMax):
2068 '''
2075 '''
2069 Function that implements winds estimation technique with detected meteors.
2076 Function that implements winds estimation technique with detected meteors.
2070
2077
2071 Input: Detected meteors, Minimum meteor quantity to wind estimation
2078 Input: Detected meteors, Minimum meteor quantity to wind estimation
2072
2079
2073 Output: Winds estimation (Zonal and Meridional)
2080 Output: Winds estimation (Zonal and Meridional)
2074
2081
2075 Parameters affected: Winds
2082 Parameters affected: Winds
2076 '''
2083 '''
2077 # print arrayMeteor.shape
2084 # print arrayMeteor.shape
2078 #Settings
2085 #Settings
2079 nInt = (heightMax - heightMin)/2
2086 nInt = (heightMax - heightMin)/2
2080 # print nInt
2087 # print nInt
2081 nInt = int(nInt)
2088 nInt = int(nInt)
2082 # print nInt
2089 # print nInt
2083 winds = numpy.zeros((2,nInt))*numpy.nan
2090 winds = numpy.zeros((2,nInt))*numpy.nan
2084
2091
2085 #Filter errors
2092 #Filter errors
2086 error = numpy.where(arrayMeteor[:,-1] == 0)[0]
2093 error = numpy.where(arrayMeteor[:,-1] == 0)[0]
2087 finalMeteor = arrayMeteor[error,:]
2094 finalMeteor = arrayMeteor[error,:]
2088
2095
2089 #Meteor Histogram
2096 #Meteor Histogram
2090 finalHeights = finalMeteor[:,2]
2097 finalHeights = finalMeteor[:,2]
2091 hist = numpy.histogram(finalHeights, bins = nInt, range = (heightMin,heightMax))
2098 hist = numpy.histogram(finalHeights, bins = nInt, range = (heightMin,heightMax))
2092 nMeteorsPerI = hist[0]
2099 nMeteorsPerI = hist[0]
2093 heightPerI = hist[1]
2100 heightPerI = hist[1]
2094
2101
2095 #Sort of meteors
2102 #Sort of meteors
2096 indSort = finalHeights.argsort()
2103 indSort = finalHeights.argsort()
2097 finalMeteor2 = finalMeteor[indSort,:]
2104 finalMeteor2 = finalMeteor[indSort,:]
2098
2105
2099 # Calculating winds
2106 # Calculating winds
2100 ind1 = 0
2107 ind1 = 0
2101 ind2 = 0
2108 ind2 = 0
2102
2109
2103 for i in range(nInt):
2110 for i in range(nInt):
2104 nMet = nMeteorsPerI[i]
2111 nMet = nMeteorsPerI[i]
2105 ind1 = ind2
2112 ind1 = ind2
2106 ind2 = ind1 + nMet
2113 ind2 = ind1 + nMet
2107
2114
2108 meteorAux = finalMeteor2[ind1:ind2,:]
2115 meteorAux = finalMeteor2[ind1:ind2,:]
2109
2116
2110 if meteorAux.shape[0] >= meteorThresh:
2117 if meteorAux.shape[0] >= meteorThresh:
2111 vel = meteorAux[:, 6]
2118 vel = meteorAux[:, 6]
2112 zen = meteorAux[:, 4]*numpy.pi/180
2119 zen = meteorAux[:, 4]*numpy.pi/180
2113 azim = meteorAux[:, 3]*numpy.pi/180
2120 azim = meteorAux[:, 3]*numpy.pi/180
2114
2121
2115 n = numpy.cos(zen)
2122 n = numpy.cos(zen)
2116 # m = (1 - n**2)/(1 - numpy.tan(azim)**2)
2123 # m = (1 - n**2)/(1 - numpy.tan(azim)**2)
2117 # l = m*numpy.tan(azim)
2124 # l = m*numpy.tan(azim)
2118 l = numpy.sin(zen)*numpy.sin(azim)
2125 l = numpy.sin(zen)*numpy.sin(azim)
2119 m = numpy.sin(zen)*numpy.cos(azim)
2126 m = numpy.sin(zen)*numpy.cos(azim)
2120
2127
2121 A = numpy.vstack((l, m)).transpose()
2128 A = numpy.vstack((l, m)).transpose()
2122 A1 = numpy.dot(numpy.linalg.inv( numpy.dot(A.transpose(),A) ),A.transpose())
2129 A1 = numpy.dot(numpy.linalg.inv( numpy.dot(A.transpose(),A) ),A.transpose())
2123 windsAux = numpy.dot(A1, vel)
2130 windsAux = numpy.dot(A1, vel)
2124
2131
2125 winds[0,i] = windsAux[0]
2132 winds[0,i] = windsAux[0]
2126 winds[1,i] = windsAux[1]
2133 winds[1,i] = windsAux[1]
2127
2134
2128 return winds, heightPerI[:-1]
2135 return winds, heightPerI[:-1]
2129
2136
2130 def techniqueNSM_SA(self, **kwargs):
2137 def techniqueNSM_SA(self, **kwargs):
2131 metArray = kwargs['metArray']
2138 metArray = kwargs['metArray']
2132 heightList = kwargs['heightList']
2139 heightList = kwargs['heightList']
2133 timeList = kwargs['timeList']
2140 timeList = kwargs['timeList']
2134
2141
2135 rx_location = kwargs['rx_location']
2142 rx_location = kwargs['rx_location']
2136 groupList = kwargs['groupList']
2143 groupList = kwargs['groupList']
2137 azimuth = kwargs['azimuth']
2144 azimuth = kwargs['azimuth']
2138 dfactor = kwargs['dfactor']
2145 dfactor = kwargs['dfactor']
2139 k = kwargs['k']
2146 k = kwargs['k']
2140
2147
2141 azimuth1, dist = self.__calculateAzimuth1(rx_location, groupList, azimuth)
2148 azimuth1, dist = self.__calculateAzimuth1(rx_location, groupList, azimuth)
2142 d = dist*dfactor
2149 d = dist*dfactor
2143 #Phase calculation
2150 #Phase calculation
2144 metArray1 = self.__getPhaseSlope(metArray, heightList, timeList)
2151 metArray1 = self.__getPhaseSlope(metArray, heightList, timeList)
2145
2152
2146 metArray1[:,-2] = metArray1[:,-2]*metArray1[:,2]*1000/(k*d[metArray1[:,1].astype(int)]) #angles into velocities
2153 metArray1[:,-2] = metArray1[:,-2]*metArray1[:,2]*1000/(k*d[metArray1[:,1].astype(int)]) #angles into velocities
2147
2154
2148 velEst = numpy.zeros((heightList.size,2))*numpy.nan
2155 velEst = numpy.zeros((heightList.size,2))*numpy.nan
2149 azimuth1 = azimuth1*numpy.pi/180
2156 azimuth1 = azimuth1*numpy.pi/180
2150
2157
2151 for i in range(heightList.size):
2158 for i in range(heightList.size):
2152 h = heightList[i]
2159 h = heightList[i]
2153 indH = numpy.where((metArray1[:,2] == h)&(numpy.abs(metArray1[:,-2]) < 100))[0]
2160 indH = numpy.where((metArray1[:,2] == h)&(numpy.abs(metArray1[:,-2]) < 100))[0]
2154 metHeight = metArray1[indH,:]
2161 metHeight = metArray1[indH,:]
2155 if metHeight.shape[0] >= 2:
2162 if metHeight.shape[0] >= 2:
2156 velAux = numpy.asmatrix(metHeight[:,-2]).T #Radial Velocities
2163 velAux = numpy.asmatrix(metHeight[:,-2]).T #Radial Velocities
2157 iazim = metHeight[:,1].astype(int)
2164 iazim = metHeight[:,1].astype(int)
2158 azimAux = numpy.asmatrix(azimuth1[iazim]).T #Azimuths
2165 azimAux = numpy.asmatrix(azimuth1[iazim]).T #Azimuths
2159 A = numpy.hstack((numpy.cos(azimAux),numpy.sin(azimAux)))
2166 A = numpy.hstack((numpy.cos(azimAux),numpy.sin(azimAux)))
2160 A = numpy.asmatrix(A)
2167 A = numpy.asmatrix(A)
2161 A1 = numpy.linalg.pinv(A.transpose()*A)*A.transpose()
2168 A1 = numpy.linalg.pinv(A.transpose()*A)*A.transpose()
2162 velHor = numpy.dot(A1,velAux)
2169 velHor = numpy.dot(A1,velAux)
2163
2170
2164 velEst[i,:] = numpy.squeeze(velHor)
2171 velEst[i,:] = numpy.squeeze(velHor)
2165 return velEst
2172 return velEst
2166
2173
2167 def __getPhaseSlope(self, metArray, heightList, timeList):
2174 def __getPhaseSlope(self, metArray, heightList, timeList):
2168 meteorList = []
2175 meteorList = []
2169 #utctime sec1 height SNR velRad ph0 ph1 ph2 coh0 coh1 coh2
2176 #utctime sec1 height SNR velRad ph0 ph1 ph2 coh0 coh1 coh2
2170 #Putting back together the meteor matrix
2177 #Putting back together the meteor matrix
2171 utctime = metArray[:,0]
2178 utctime = metArray[:,0]
2172 uniqueTime = numpy.unique(utctime)
2179 uniqueTime = numpy.unique(utctime)
2173
2180
2174 phaseDerThresh = 0.5
2181 phaseDerThresh = 0.5
2175 ippSeconds = timeList[1] - timeList[0]
2182 ippSeconds = timeList[1] - timeList[0]
2176 sec = numpy.where(timeList>1)[0][0]
2183 sec = numpy.where(timeList>1)[0][0]
2177 nPairs = metArray.shape[1] - 6
2184 nPairs = metArray.shape[1] - 6
2178 nHeights = len(heightList)
2185 nHeights = len(heightList)
2179
2186
2180 for t in uniqueTime:
2187 for t in uniqueTime:
2181 metArray1 = metArray[utctime==t,:]
2188 metArray1 = metArray[utctime==t,:]
2182 # phaseDerThresh = numpy.pi/4 #reducir Phase thresh
2189 # phaseDerThresh = numpy.pi/4 #reducir Phase thresh
2183 tmet = metArray1[:,1].astype(int)
2190 tmet = metArray1[:,1].astype(int)
2184 hmet = metArray1[:,2].astype(int)
2191 hmet = metArray1[:,2].astype(int)
2185
2192
2186 metPhase = numpy.zeros((nPairs, heightList.size, timeList.size - 1))
2193 metPhase = numpy.zeros((nPairs, heightList.size, timeList.size - 1))
2187 metPhase[:,:] = numpy.nan
2194 metPhase[:,:] = numpy.nan
2188 metPhase[:,hmet,tmet] = metArray1[:,6:].T
2195 metPhase[:,hmet,tmet] = metArray1[:,6:].T
2189
2196
2190 #Delete short trails
2197 #Delete short trails
2191 metBool = ~numpy.isnan(metPhase[0,:,:])
2198 metBool = ~numpy.isnan(metPhase[0,:,:])
2192 heightVect = numpy.sum(metBool, axis = 1)
2199 heightVect = numpy.sum(metBool, axis = 1)
2193 metBool[heightVect<sec,:] = False
2200 metBool[heightVect<sec,:] = False
2194 metPhase[:,heightVect<sec,:] = numpy.nan
2201 metPhase[:,heightVect<sec,:] = numpy.nan
2195
2202
2196 #Derivative
2203 #Derivative
2197 metDer = numpy.abs(metPhase[:,:,1:] - metPhase[:,:,:-1])
2204 metDer = numpy.abs(metPhase[:,:,1:] - metPhase[:,:,:-1])
2198 phDerAux = numpy.dstack((numpy.full((nPairs,nHeights,1), False, dtype=bool),metDer > phaseDerThresh))
2205 phDerAux = numpy.dstack((numpy.full((nPairs,nHeights,1), False, dtype=bool),metDer > phaseDerThresh))
2199 metPhase[phDerAux] = numpy.nan
2206 metPhase[phDerAux] = numpy.nan
2200
2207
2201 #--------------------------METEOR DETECTION -----------------------------------------
2208 #--------------------------METEOR DETECTION -----------------------------------------
2202 indMet = numpy.where(numpy.any(metBool,axis=1))[0]
2209 indMet = numpy.where(numpy.any(metBool,axis=1))[0]
2203
2210
2204 for p in numpy.arange(nPairs):
2211 for p in numpy.arange(nPairs):
2205 phase = metPhase[p,:,:]
2212 phase = metPhase[p,:,:]
2206 phDer = metDer[p,:,:]
2213 phDer = metDer[p,:,:]
2207
2214
2208 for h in indMet:
2215 for h in indMet:
2209 height = heightList[h]
2216 height = heightList[h]
2210 phase1 = phase[h,:] #82
2217 phase1 = phase[h,:] #82
2211 phDer1 = phDer[h,:]
2218 phDer1 = phDer[h,:]
2212
2219
2213 phase1[~numpy.isnan(phase1)] = numpy.unwrap(phase1[~numpy.isnan(phase1)]) #Unwrap
2220 phase1[~numpy.isnan(phase1)] = numpy.unwrap(phase1[~numpy.isnan(phase1)]) #Unwrap
2214
2221
2215 indValid = numpy.where(~numpy.isnan(phase1))[0]
2222 indValid = numpy.where(~numpy.isnan(phase1))[0]
2216 initMet = indValid[0]
2223 initMet = indValid[0]
2217 endMet = 0
2224 endMet = 0
2218
2225
2219 for i in range(len(indValid)-1):
2226 for i in range(len(indValid)-1):
2220
2227
2221 #Time difference
2228 #Time difference
2222 inow = indValid[i]
2229 inow = indValid[i]
2223 inext = indValid[i+1]
2230 inext = indValid[i+1]
2224 idiff = inext - inow
2231 idiff = inext - inow
2225 #Phase difference
2232 #Phase difference
2226 phDiff = numpy.abs(phase1[inext] - phase1[inow])
2233 phDiff = numpy.abs(phase1[inext] - phase1[inow])
2227
2234
2228 if idiff>sec or phDiff>numpy.pi/4 or inext==indValid[-1]: #End of Meteor
2235 if idiff>sec or phDiff>numpy.pi/4 or inext==indValid[-1]: #End of Meteor
2229 sizeTrail = inow - initMet + 1
2236 sizeTrail = inow - initMet + 1
2230 if sizeTrail>3*sec: #Too short meteors
2237 if sizeTrail>3*sec: #Too short meteors
2231 x = numpy.arange(initMet,inow+1)*ippSeconds
2238 x = numpy.arange(initMet,inow+1)*ippSeconds
2232 y = phase1[initMet:inow+1]
2239 y = phase1[initMet:inow+1]
2233 ynnan = ~numpy.isnan(y)
2240 ynnan = ~numpy.isnan(y)
2234 x = x[ynnan]
2241 x = x[ynnan]
2235 y = y[ynnan]
2242 y = y[ynnan]
2236 slope, intercept, r_value, p_value, std_err = stats.linregress(x,y)
2243 slope, intercept, r_value, p_value, std_err = stats.linregress(x,y)
2237 ylin = x*slope + intercept
2244 ylin = x*slope + intercept
2238 rsq = r_value**2
2245 rsq = r_value**2
2239 if rsq > 0.5:
2246 if rsq > 0.5:
2240 vel = slope#*height*1000/(k*d)
2247 vel = slope#*height*1000/(k*d)
2241 estAux = numpy.array([utctime,p,height, vel, rsq])
2248 estAux = numpy.array([utctime,p,height, vel, rsq])
2242 meteorList.append(estAux)
2249 meteorList.append(estAux)
2243 initMet = inext
2250 initMet = inext
2244 metArray2 = numpy.array(meteorList)
2251 metArray2 = numpy.array(meteorList)
2245
2252
2246 return metArray2
2253 return metArray2
2247
2254
2248 def __calculateAzimuth1(self, rx_location, pairslist, azimuth0):
2255 def __calculateAzimuth1(self, rx_location, pairslist, azimuth0):
2249
2256
2250 azimuth1 = numpy.zeros(len(pairslist))
2257 azimuth1 = numpy.zeros(len(pairslist))
2251 dist = numpy.zeros(len(pairslist))
2258 dist = numpy.zeros(len(pairslist))
2252
2259
2253 for i in range(len(rx_location)):
2260 for i in range(len(rx_location)):
2254 ch0 = pairslist[i][0]
2261 ch0 = pairslist[i][0]
2255 ch1 = pairslist[i][1]
2262 ch1 = pairslist[i][1]
2256
2263
2257 diffX = rx_location[ch0][0] - rx_location[ch1][0]
2264 diffX = rx_location[ch0][0] - rx_location[ch1][0]
2258 diffY = rx_location[ch0][1] - rx_location[ch1][1]
2265 diffY = rx_location[ch0][1] - rx_location[ch1][1]
2259 azimuth1[i] = numpy.arctan2(diffY,diffX)*180/numpy.pi
2266 azimuth1[i] = numpy.arctan2(diffY,diffX)*180/numpy.pi
2260 dist[i] = numpy.sqrt(diffX**2 + diffY**2)
2267 dist[i] = numpy.sqrt(diffX**2 + diffY**2)
2261
2268
2262 azimuth1 -= azimuth0
2269 azimuth1 -= azimuth0
2263 return azimuth1, dist
2270 return azimuth1, dist
2264
2271
2265 def techniqueNSM_DBS(self, **kwargs):
2272 def techniqueNSM_DBS(self, **kwargs):
2266 metArray = kwargs['metArray']
2273 metArray = kwargs['metArray']
2267 heightList = kwargs['heightList']
2274 heightList = kwargs['heightList']
2268 timeList = kwargs['timeList']
2275 timeList = kwargs['timeList']
2269 zenithList = kwargs['zenithList']
2276 zenithList = kwargs['zenithList']
2270 nChan = numpy.max(cmet) + 1
2277 nChan = numpy.max(cmet) + 1
2271 nHeights = len(heightList)
2278 nHeights = len(heightList)
2272
2279
2273 utctime = metArray[:,0]
2280 utctime = metArray[:,0]
2274 cmet = metArray[:,1]
2281 cmet = metArray[:,1]
2275 hmet = metArray1[:,3].astype(int)
2282 hmet = metArray1[:,3].astype(int)
2276 h1met = heightList[hmet]*zenithList[cmet]
2283 h1met = heightList[hmet]*zenithList[cmet]
2277 vmet = metArray1[:,5]
2284 vmet = metArray1[:,5]
2278
2285
2279 for i in range(nHeights - 1):
2286 for i in range(nHeights - 1):
2280 hmin = heightList[i]
2287 hmin = heightList[i]
2281 hmax = heightList[i + 1]
2288 hmax = heightList[i + 1]
2282
2289
2283 vthisH = vmet[(h1met>=hmin) & (h1met<hmax)]
2290 vthisH = vmet[(h1met>=hmin) & (h1met<hmax)]
2284
2291
2285
2292
2286
2293
2287 return data_output
2294 return data_output
2288
2295
2289 def run(self, dataOut, technique, **kwargs):
2296 def run(self, dataOut, technique, **kwargs):
2290
2297
2291 param = dataOut.data_param
2298 param = dataOut.data_param
2292 if dataOut.abscissaList != None:
2299 if dataOut.abscissaList != None:
2293 absc = dataOut.abscissaList[:-1]
2300 absc = dataOut.abscissaList[:-1]
2294 noise = dataOut.noise
2301 noise = dataOut.noise
2295 heightList = dataOut.heightList
2302 heightList = dataOut.heightList
2296 SNR = dataOut.data_SNR
2303 SNR = dataOut.data_SNR
2297
2304
2298 if technique == 'DBS':
2305 if technique == 'DBS':
2299
2306
2300 kwargs['velRadial'] = param[:,1,:] #Radial velocity
2307 kwargs['velRadial'] = param[:,1,:] #Radial velocity
2301 kwargs['heightList'] = heightList
2308 kwargs['heightList'] = heightList
2302 kwargs['SNR'] = SNR
2309 kwargs['SNR'] = SNR
2303
2310
2304 dataOut.data_output, dataOut.heightList, dataOut.data_SNR = self.techniqueDBS(kwargs) #DBS Function
2311 dataOut.data_output, dataOut.heightList, dataOut.data_SNR = self.techniqueDBS(kwargs) #DBS Function
2305 dataOut.utctimeInit = dataOut.utctime
2312 dataOut.utctimeInit = dataOut.utctime
2306 dataOut.outputInterval = dataOut.paramInterval
2313 dataOut.outputInterval = dataOut.paramInterval
2307
2314
2308 elif technique == 'SA':
2315 elif technique == 'SA':
2309
2316
2310 #Parameters
2317 #Parameters
2311 # position_x = kwargs['positionX']
2318 # position_x = kwargs['positionX']
2312 # position_y = kwargs['positionY']
2319 # position_y = kwargs['positionY']
2313 # azimuth = kwargs['azimuth']
2320 # azimuth = kwargs['azimuth']
2314 #
2321 #
2315 # if kwargs.has_key('crosspairsList'):
2322 # if kwargs.has_key('crosspairsList'):
2316 # pairs = kwargs['crosspairsList']
2323 # pairs = kwargs['crosspairsList']
2317 # else:
2324 # else:
2318 # pairs = None
2325 # pairs = None
2319 #
2326 #
2320 # if kwargs.has_key('correctFactor'):
2327 # if kwargs.has_key('correctFactor'):
2321 # correctFactor = kwargs['correctFactor']
2328 # correctFactor = kwargs['correctFactor']
2322 # else:
2329 # else:
2323 # correctFactor = 1
2330 # correctFactor = 1
2324
2331
2325 # tau = dataOut.data_param
2332 # tau = dataOut.data_param
2326 # _lambda = dataOut.C/dataOut.frequency
2333 # _lambda = dataOut.C/dataOut.frequency
2327 # pairsList = dataOut.groupList
2334 # pairsList = dataOut.groupList
2328 # nChannels = dataOut.nChannels
2335 # nChannels = dataOut.nChannels
2329
2336
2330 kwargs['groupList'] = dataOut.groupList
2337 kwargs['groupList'] = dataOut.groupList
2331 kwargs['tau'] = dataOut.data_param
2338 kwargs['tau'] = dataOut.data_param
2332 kwargs['_lambda'] = dataOut.C/dataOut.frequency
2339 kwargs['_lambda'] = dataOut.C/dataOut.frequency
2333 # dataOut.data_output = self.techniqueSA(pairs, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, absc, correctFactor)
2340 # dataOut.data_output = self.techniqueSA(pairs, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, absc, correctFactor)
2334 dataOut.data_output = self.techniqueSA(kwargs)
2341 dataOut.data_output = self.techniqueSA(kwargs)
2335 dataOut.utctimeInit = dataOut.utctime
2342 dataOut.utctimeInit = dataOut.utctime
2336 dataOut.outputInterval = dataOut.timeInterval
2343 dataOut.outputInterval = dataOut.timeInterval
2337
2344
2338 elif technique == 'Meteors':
2345 elif technique == 'Meteors':
2339 dataOut.flagNoData = True
2346 dataOut.flagNoData = True
2340 self.__dataReady = False
2347 self.__dataReady = False
2341
2348
2342 if kwargs.has_key('nHours'):
2349 if kwargs.has_key('nHours'):
2343 nHours = kwargs['nHours']
2350 nHours = kwargs['nHours']
2344 else:
2351 else:
2345 nHours = 1
2352 nHours = 1
2346
2353
2347 if kwargs.has_key('meteorsPerBin'):
2354 if kwargs.has_key('meteorsPerBin'):
2348 meteorThresh = kwargs['meteorsPerBin']
2355 meteorThresh = kwargs['meteorsPerBin']
2349 else:
2356 else:
2350 meteorThresh = 6
2357 meteorThresh = 6
2351
2358
2352 if kwargs.has_key('hmin'):
2359 if kwargs.has_key('hmin'):
2353 hmin = kwargs['hmin']
2360 hmin = kwargs['hmin']
2354 else: hmin = 70
2361 else: hmin = 70
2355 if kwargs.has_key('hmax'):
2362 if kwargs.has_key('hmax'):
2356 hmax = kwargs['hmax']
2363 hmax = kwargs['hmax']
2357 else: hmax = 110
2364 else: hmax = 110
2358
2365
2359 dataOut.outputInterval = nHours*3600
2366 dataOut.outputInterval = nHours*3600
2360
2367
2361 if self.__isConfig == False:
2368 if self.__isConfig == False:
2362 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
2369 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
2363 #Get Initial LTC time
2370 #Get Initial LTC time
2364 self.__initime = datetime.datetime.utcfromtimestamp(dataOut.utctime)
2371 self.__initime = datetime.datetime.utcfromtimestamp(dataOut.utctime)
2365 self.__initime = (self.__initime.replace(minute = 0, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
2372 self.__initime = (self.__initime.replace(minute = 0, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
2366
2373
2367 self.__isConfig = True
2374 self.__isConfig = True
2368
2375
2369 if self.__buffer == None:
2376 if self.__buffer == None:
2370 self.__buffer = dataOut.data_param
2377 self.__buffer = dataOut.data_param
2371 self.__firstdata = copy.copy(dataOut)
2378 self.__firstdata = copy.copy(dataOut)
2372
2379
2373 else:
2380 else:
2374 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
2381 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
2375
2382
2376 self.__checkTime(dataOut.utctime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
2383 self.__checkTime(dataOut.utctime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
2377
2384
2378 if self.__dataReady:
2385 if self.__dataReady:
2379 dataOut.utctimeInit = self.__initime
2386 dataOut.utctimeInit = self.__initime
2380
2387
2381 self.__initime += dataOut.outputInterval #to erase time offset
2388 self.__initime += dataOut.outputInterval #to erase time offset
2382
2389
2383 dataOut.data_output, dataOut.heightList = self.techniqueMeteors(self.__buffer, meteorThresh, hmin, hmax)
2390 dataOut.data_output, dataOut.heightList = self.techniqueMeteors(self.__buffer, meteorThresh, hmin, hmax)
2384 dataOut.flagNoData = False
2391 dataOut.flagNoData = False
2385 self.__buffer = None
2392 self.__buffer = None
2386
2393
2387 elif technique == 'Meteors1':
2394 elif technique == 'Meteors1':
2388 dataOut.flagNoData = True
2395 dataOut.flagNoData = True
2389 self.__dataReady = False
2396 self.__dataReady = False
2390
2397
2391 if kwargs.has_key('nMins'):
2398 if kwargs.has_key('nMins'):
2392 nMins = kwargs['nMins']
2399 nMins = kwargs['nMins']
2393 else: nMins = 20
2400 else: nMins = 20
2394 if kwargs.has_key('rx_location'):
2401 if kwargs.has_key('rx_location'):
2395 rx_location = kwargs['rx_location']
2402 rx_location = kwargs['rx_location']
2396 else: rx_location = [(0,1),(1,1),(1,0)]
2403 else: rx_location = [(0,1),(1,1),(1,0)]
2397 if kwargs.has_key('azimuth'):
2404 if kwargs.has_key('azimuth'):
2398 azimuth = kwargs['azimuth']
2405 azimuth = kwargs['azimuth']
2399 else: azimuth = 51
2406 else: azimuth = 51
2400 if kwargs.has_key('dfactor'):
2407 if kwargs.has_key('dfactor'):
2401 dfactor = kwargs['dfactor']
2408 dfactor = kwargs['dfactor']
2402 if kwargs.has_key('mode'):
2409 if kwargs.has_key('mode'):
2403 mode = kwargs['mode']
2410 mode = kwargs['mode']
2404 else: mode = 'SA'
2411 else: mode = 'SA'
2405
2412
2406 #Borrar luego esto
2413 #Borrar luego esto
2407 if dataOut.groupList == None:
2414 if dataOut.groupList == None:
2408 dataOut.groupList = [(0,1),(0,2),(1,2)]
2415 dataOut.groupList = [(0,1),(0,2),(1,2)]
2409 groupList = dataOut.groupList
2416 groupList = dataOut.groupList
2410 C = 3e8
2417 C = 3e8
2411 freq = 50e6
2418 freq = 50e6
2412 lamb = C/freq
2419 lamb = C/freq
2413 k = 2*numpy.pi/lamb
2420 k = 2*numpy.pi/lamb
2414
2421
2415 timeList = dataOut.abscissaList
2422 timeList = dataOut.abscissaList
2416 heightList = dataOut.heightList
2423 heightList = dataOut.heightList
2417
2424
2418 if self.__isConfig == False:
2425 if self.__isConfig == False:
2419 dataOut.outputInterval = nMins*60
2426 dataOut.outputInterval = nMins*60
2420 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
2427 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
2421 #Get Initial LTC time
2428 #Get Initial LTC time
2422 initime = datetime.datetime.utcfromtimestamp(dataOut.utctime)
2429 initime = datetime.datetime.utcfromtimestamp(dataOut.utctime)
2423 minuteAux = initime.minute
2430 minuteAux = initime.minute
2424 minuteNew = int(numpy.floor(minuteAux/nMins)*nMins)
2431 minuteNew = int(numpy.floor(minuteAux/nMins)*nMins)
2425 self.__initime = (initime.replace(minute = minuteNew, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
2432 self.__initime = (initime.replace(minute = minuteNew, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
2426
2433
2427 self.__isConfig = True
2434 self.__isConfig = True
2428
2435
2429 if self.__buffer == None:
2436 if self.__buffer == None:
2430 self.__buffer = dataOut.data_param
2437 self.__buffer = dataOut.data_param
2431 self.__firstdata = copy.copy(dataOut)
2438 self.__firstdata = copy.copy(dataOut)
2432
2439
2433 else:
2440 else:
2434 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
2441 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
2435
2442
2436 self.__checkTime(dataOut.utctime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
2443 self.__checkTime(dataOut.utctime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
2437
2444
2438 if self.__dataReady:
2445 if self.__dataReady:
2439 dataOut.utctimeInit = self.__initime
2446 dataOut.utctimeInit = self.__initime
2440 self.__initime += dataOut.outputInterval #to erase time offset
2447 self.__initime += dataOut.outputInterval #to erase time offset
2441
2448
2442 metArray = self.__buffer
2449 metArray = self.__buffer
2443 if mode == 'SA':
2450 if mode == 'SA':
2444 dataOut.data_output = self.techniqueNSM_SA(rx_location=rx_location, groupList=groupList, azimuth=azimuth, dfactor=dfactor, k=k,metArray=metArray, heightList=heightList,timeList=timeList)
2451 dataOut.data_output = self.techniqueNSM_SA(rx_location=rx_location, groupList=groupList, azimuth=azimuth, dfactor=dfactor, k=k,metArray=metArray, heightList=heightList,timeList=timeList)
2445 elif mode == 'DBS':
2452 elif mode == 'DBS':
2446 dataOut.data_output = self.techniqueNSM_DBS(metArray=metArray,heightList=heightList,timeList=timeList)
2453 dataOut.data_output = self.techniqueNSM_DBS(metArray=metArray,heightList=heightList,timeList=timeList)
2447 dataOut.data_output = dataOut.data_output.T
2454 dataOut.data_output = dataOut.data_output.T
2448 dataOut.flagNoData = False
2455 dataOut.flagNoData = False
2449 self.__buffer = None
2456 self.__buffer = None
2450
2457
2451 return
2458 return
2452
2459
2453 class EWDriftsEstimation(Operation):
2460 class EWDriftsEstimation(Operation):
2454
2461
2455 def __init__(self):
2462 def __init__(self):
2456 Operation.__init__(self)
2463 Operation.__init__(self)
2457
2464
2458 def __correctValues(self, heiRang, phi, velRadial, SNR):
2465 def __correctValues(self, heiRang, phi, velRadial, SNR):
2459 listPhi = phi.tolist()
2466 listPhi = phi.tolist()
2460 maxid = listPhi.index(max(listPhi))
2467 maxid = listPhi.index(max(listPhi))
2461 minid = listPhi.index(min(listPhi))
2468 minid = listPhi.index(min(listPhi))
2462
2469
2463 rango = range(len(phi))
2470 rango = range(len(phi))
2464 # rango = numpy.delete(rango,maxid)
2471 # rango = numpy.delete(rango,maxid)
2465
2472
2466 heiRang1 = heiRang*math.cos(phi[maxid])
2473 heiRang1 = heiRang*math.cos(phi[maxid])
2467 heiRangAux = heiRang*math.cos(phi[minid])
2474 heiRangAux = heiRang*math.cos(phi[minid])
2468 indOut = (heiRang1 < heiRangAux[0]).nonzero()
2475 indOut = (heiRang1 < heiRangAux[0]).nonzero()
2469 heiRang1 = numpy.delete(heiRang1,indOut)
2476 heiRang1 = numpy.delete(heiRang1,indOut)
2470
2477
2471 velRadial1 = numpy.zeros([len(phi),len(heiRang1)])
2478 velRadial1 = numpy.zeros([len(phi),len(heiRang1)])
2472 SNR1 = numpy.zeros([len(phi),len(heiRang1)])
2479 SNR1 = numpy.zeros([len(phi),len(heiRang1)])
2473
2480
2474 for i in rango:
2481 for i in rango:
2475 x = heiRang*math.cos(phi[i])
2482 x = heiRang*math.cos(phi[i])
2476 y1 = velRadial[i,:]
2483 y1 = velRadial[i,:]
2477 f1 = interpolate.interp1d(x,y1,kind = 'cubic')
2484 f1 = interpolate.interp1d(x,y1,kind = 'cubic')
2478
2485
2479 x1 = heiRang1
2486 x1 = heiRang1
2480 y11 = f1(x1)
2487 y11 = f1(x1)
2481
2488
2482 y2 = SNR[i,:]
2489 y2 = SNR[i,:]
2483 f2 = interpolate.interp1d(x,y2,kind = 'cubic')
2490 f2 = interpolate.interp1d(x,y2,kind = 'cubic')
2484 y21 = f2(x1)
2491 y21 = f2(x1)
2485
2492
2486 velRadial1[i,:] = y11
2493 velRadial1[i,:] = y11
2487 SNR1[i,:] = y21
2494 SNR1[i,:] = y21
2488
2495
2489 return heiRang1, velRadial1, SNR1
2496 return heiRang1, velRadial1, SNR1
2490
2497
2491 def run(self, dataOut, zenith, zenithCorrection):
2498 def run(self, dataOut, zenith, zenithCorrection):
2492 heiRang = dataOut.heightList
2499 heiRang = dataOut.heightList
2493 velRadial = dataOut.data_param[:,3,:]
2500 velRadial = dataOut.data_param[:,3,:]
2494 SNR = dataOut.data_SNR
2501 SNR = dataOut.data_SNR
2495
2502
2496 zenith = numpy.array(zenith)
2503 zenith = numpy.array(zenith)
2497 zenith -= zenithCorrection
2504 zenith -= zenithCorrection
2498 zenith *= numpy.pi/180
2505 zenith *= numpy.pi/180
2499
2506
2500 heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, numpy.abs(zenith), velRadial, SNR)
2507 heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, numpy.abs(zenith), velRadial, SNR)
2501
2508
2502 alp = zenith[0]
2509 alp = zenith[0]
2503 bet = zenith[1]
2510 bet = zenith[1]
2504
2511
2505 w_w = velRadial1[0,:]
2512 w_w = velRadial1[0,:]
2506 w_e = velRadial1[1,:]
2513 w_e = velRadial1[1,:]
2507
2514
2508 w = (w_w*numpy.sin(bet) - w_e*numpy.sin(alp))/(numpy.cos(alp)*numpy.sin(bet) - numpy.cos(bet)*numpy.sin(alp))
2515 w = (w_w*numpy.sin(bet) - w_e*numpy.sin(alp))/(numpy.cos(alp)*numpy.sin(bet) - numpy.cos(bet)*numpy.sin(alp))
2509 u = (w_w*numpy.cos(bet) - w_e*numpy.cos(alp))/(numpy.sin(alp)*numpy.cos(bet) - numpy.sin(bet)*numpy.cos(alp))
2516 u = (w_w*numpy.cos(bet) - w_e*numpy.cos(alp))/(numpy.sin(alp)*numpy.cos(bet) - numpy.sin(bet)*numpy.cos(alp))
2510
2517
2511 winds = numpy.vstack((u,w))
2518 winds = numpy.vstack((u,w))
2512
2519
2513 dataOut.heightList = heiRang1
2520 dataOut.heightList = heiRang1
2514 dataOut.data_output = winds
2521 dataOut.data_output = winds
2515 dataOut.data_SNR = SNR1
2522 dataOut.data_SNR = SNR1
2516
2523
2517 dataOut.utctimeInit = dataOut.utctime
2524 dataOut.utctimeInit = dataOut.utctime
2518 dataOut.outputInterval = dataOut.timeInterval
2525 dataOut.outputInterval = dataOut.timeInterval
2519 return
2526 return
2520
2527
2521 #--------------- Non Specular Meteor ----------------
2528 #--------------- Non Specular Meteor ----------------
2522
2529
2523 class NonSpecularMeteorDetection(Operation):
2530 class NonSpecularMeteorDetection(Operation):
2524
2531
2525 def run(self, mode, SNRthresh=8, phaseDerThresh=0.5, cohThresh=0.8, allData = False):
2532 def run(self, mode, SNRthresh=8, phaseDerThresh=0.5, cohThresh=0.8, allData = False):
2526 data_acf = self.dataOut.data_pre[0]
2533 data_acf = self.dataOut.data_pre[0]
2527 data_ccf = self.dataOut.data_pre[1]
2534 data_ccf = self.dataOut.data_pre[1]
2528
2535
2529 lamb = self.dataOut.C/self.dataOut.frequency
2536 lamb = self.dataOut.C/self.dataOut.frequency
2530 tSamp = self.dataOut.ippSeconds*self.dataOut.nCohInt
2537 tSamp = self.dataOut.ippSeconds*self.dataOut.nCohInt
2531 paramInterval = self.dataOut.paramInterval
2538 paramInterval = self.dataOut.paramInterval
2532
2539
2533 nChannels = data_acf.shape[0]
2540 nChannels = data_acf.shape[0]
2534 nLags = data_acf.shape[1]
2541 nLags = data_acf.shape[1]
2535 nProfiles = data_acf.shape[2]
2542 nProfiles = data_acf.shape[2]
2536 nHeights = self.dataOut.nHeights
2543 nHeights = self.dataOut.nHeights
2537 nCohInt = self.dataOut.nCohInt
2544 nCohInt = self.dataOut.nCohInt
2538 sec = numpy.round(nProfiles/self.dataOut.paramInterval)
2545 sec = numpy.round(nProfiles/self.dataOut.paramInterval)
2539 heightList = self.dataOut.heightList
2546 heightList = self.dataOut.heightList
2540 ippSeconds = self.dataOut.ippSeconds*self.dataOut.nCohInt*self.dataOut.nAvg
2547 ippSeconds = self.dataOut.ippSeconds*self.dataOut.nCohInt*self.dataOut.nAvg
2541 utctime = self.dataOut.utctime
2548 utctime = self.dataOut.utctime
2542
2549
2543 self.dataOut.abscissaList = numpy.arange(0,paramInterval+ippSeconds,ippSeconds)
2550 self.dataOut.abscissaList = numpy.arange(0,paramInterval+ippSeconds,ippSeconds)
2544
2551
2545 #------------------------ SNR --------------------------------------
2552 #------------------------ SNR --------------------------------------
2546 power = data_acf[:,0,:,:].real
2553 power = data_acf[:,0,:,:].real
2547 noise = numpy.zeros(nChannels)
2554 noise = numpy.zeros(nChannels)
2548 SNR = numpy.zeros(power.shape)
2555 SNR = numpy.zeros(power.shape)
2549 for i in range(nChannels):
2556 for i in range(nChannels):
2550 noise[i] = hildebrand_sekhon(power[i,:], nCohInt)
2557 noise[i] = hildebrand_sekhon(power[i,:], nCohInt)
2551 SNR[i] = (power[i]-noise[i])/noise[i]
2558 SNR[i] = (power[i]-noise[i])/noise[i]
2552 SNRm = numpy.nanmean(SNR, axis = 0)
2559 SNRm = numpy.nanmean(SNR, axis = 0)
2553 SNRdB = 10*numpy.log10(SNR)
2560 SNRdB = 10*numpy.log10(SNR)
2554
2561
2555 if mode == 'SA':
2562 if mode == 'SA':
2556 nPairs = data_ccf.shape[0]
2563 nPairs = data_ccf.shape[0]
2557 #---------------------- Coherence and Phase --------------------------
2564 #---------------------- Coherence and Phase --------------------------
2558 phase = numpy.zeros(data_ccf[:,0,:,:].shape)
2565 phase = numpy.zeros(data_ccf[:,0,:,:].shape)
2559 # phase1 = numpy.copy(phase)
2566 # phase1 = numpy.copy(phase)
2560 coh1 = numpy.zeros(data_ccf[:,0,:,:].shape)
2567 coh1 = numpy.zeros(data_ccf[:,0,:,:].shape)
2561
2568
2562 for p in range(nPairs):
2569 for p in range(nPairs):
2563 ch0 = self.dataOut.groupList[p][0]
2570 ch0 = self.dataOut.groupList[p][0]
2564 ch1 = self.dataOut.groupList[p][1]
2571 ch1 = self.dataOut.groupList[p][1]
2565 ccf = data_ccf[p,0,:,:]/numpy.sqrt(data_acf[ch0,0,:,:]*data_acf[ch1,0,:,:])
2572 ccf = data_ccf[p,0,:,:]/numpy.sqrt(data_acf[ch0,0,:,:]*data_acf[ch1,0,:,:])
2566 phase[p,:,:] = ndimage.median_filter(numpy.angle(ccf), size = (5,1)) #median filter
2573 phase[p,:,:] = ndimage.median_filter(numpy.angle(ccf), size = (5,1)) #median filter
2567 # phase1[p,:,:] = numpy.angle(ccf) #median filter
2574 # phase1[p,:,:] = numpy.angle(ccf) #median filter
2568 coh1[p,:,:] = ndimage.median_filter(numpy.abs(ccf), 5) #median filter
2575 coh1[p,:,:] = ndimage.median_filter(numpy.abs(ccf), 5) #median filter
2569 # coh1[p,:,:] = numpy.abs(ccf) #median filter
2576 # coh1[p,:,:] = numpy.abs(ccf) #median filter
2570 coh = numpy.nanmax(coh1, axis = 0)
2577 coh = numpy.nanmax(coh1, axis = 0)
2571 # struc = numpy.ones((5,1))
2578 # struc = numpy.ones((5,1))
2572 # coh = ndimage.morphology.grey_dilation(coh, size=(10,1))
2579 # coh = ndimage.morphology.grey_dilation(coh, size=(10,1))
2573 #---------------------- Radial Velocity ----------------------------
2580 #---------------------- Radial Velocity ----------------------------
2574 phaseAux = numpy.mean(numpy.angle(data_acf[:,1,:,:]), axis = 0)
2581 phaseAux = numpy.mean(numpy.angle(data_acf[:,1,:,:]), axis = 0)
2575 velRad = phaseAux*lamb/(4*numpy.pi*tSamp)
2582 velRad = phaseAux*lamb/(4*numpy.pi*tSamp)
2576
2583
2577 if allData:
2584 if allData:
2578 boolMetFin = ~numpy.isnan(SNRm)
2585 boolMetFin = ~numpy.isnan(SNRm)
2579 # coh[:-1,:] = numpy.nanmean(numpy.abs(phase[:,1:,:] - phase[:,:-1,:]),axis=0)
2586 # coh[:-1,:] = numpy.nanmean(numpy.abs(phase[:,1:,:] - phase[:,:-1,:]),axis=0)
2580 else:
2587 else:
2581 #------------------------ Meteor mask ---------------------------------
2588 #------------------------ Meteor mask ---------------------------------
2582 # #SNR mask
2589 # #SNR mask
2583 # boolMet = (SNRdB>SNRthresh)#|(~numpy.isnan(SNRdB))
2590 # boolMet = (SNRdB>SNRthresh)#|(~numpy.isnan(SNRdB))
2584 #
2591 #
2585 # #Erase small objects
2592 # #Erase small objects
2586 # boolMet1 = self.__erase_small(boolMet, 2*sec, 5)
2593 # boolMet1 = self.__erase_small(boolMet, 2*sec, 5)
2587 #
2594 #
2588 # auxEEJ = numpy.sum(boolMet1,axis=0)
2595 # auxEEJ = numpy.sum(boolMet1,axis=0)
2589 # indOver = auxEEJ>nProfiles*0.8 #Use this later
2596 # indOver = auxEEJ>nProfiles*0.8 #Use this later
2590 # indEEJ = numpy.where(indOver)[0]
2597 # indEEJ = numpy.where(indOver)[0]
2591 # indNEEJ = numpy.where(~indOver)[0]
2598 # indNEEJ = numpy.where(~indOver)[0]
2592 #
2599 #
2593 # boolMetFin = boolMet1
2600 # boolMetFin = boolMet1
2594 #
2601 #
2595 # if indEEJ.size > 0:
2602 # if indEEJ.size > 0:
2596 # boolMet1[:,indEEJ] = False #Erase heights with EEJ
2603 # boolMet1[:,indEEJ] = False #Erase heights with EEJ
2597 #
2604 #
2598 # boolMet2 = coh > cohThresh
2605 # boolMet2 = coh > cohThresh
2599 # boolMet2 = self.__erase_small(boolMet2, 2*sec,5)
2606 # boolMet2 = self.__erase_small(boolMet2, 2*sec,5)
2600 #
2607 #
2601 # #Final Meteor mask
2608 # #Final Meteor mask
2602 # boolMetFin = boolMet1|boolMet2
2609 # boolMetFin = boolMet1|boolMet2
2603
2610
2604 #Coherence mask
2611 #Coherence mask
2605 boolMet1 = coh > 0.75
2612 boolMet1 = coh > 0.75
2606 struc = numpy.ones((30,1))
2613 struc = numpy.ones((30,1))
2607 boolMet1 = ndimage.morphology.binary_dilation(boolMet1, structure=struc)
2614 boolMet1 = ndimage.morphology.binary_dilation(boolMet1, structure=struc)
2608
2615
2609 #Derivative mask
2616 #Derivative mask
2610 derPhase = numpy.nanmean(numpy.abs(phase[:,1:,:] - phase[:,:-1,:]),axis=0)
2617 derPhase = numpy.nanmean(numpy.abs(phase[:,1:,:] - phase[:,:-1,:]),axis=0)
2611 boolMet2 = derPhase < 0.2
2618 boolMet2 = derPhase < 0.2
2612 # boolMet2 = ndimage.morphology.binary_opening(boolMet2)
2619 # boolMet2 = ndimage.morphology.binary_opening(boolMet2)
2613 # boolMet2 = ndimage.morphology.binary_closing(boolMet2, structure = numpy.ones((10,1)))
2620 # boolMet2 = ndimage.morphology.binary_closing(boolMet2, structure = numpy.ones((10,1)))
2614 boolMet2 = ndimage.median_filter(boolMet2,size=5)
2621 boolMet2 = ndimage.median_filter(boolMet2,size=5)
2615 boolMet2 = numpy.vstack((boolMet2,numpy.full((1,nHeights), True, dtype=bool)))
2622 boolMet2 = numpy.vstack((boolMet2,numpy.full((1,nHeights), True, dtype=bool)))
2616 # #Final mask
2623 # #Final mask
2617 # boolMetFin = boolMet2
2624 # boolMetFin = boolMet2
2618 boolMetFin = boolMet1&boolMet2
2625 boolMetFin = boolMet1&boolMet2
2619 # boolMetFin = ndimage.morphology.binary_dilation(boolMetFin)
2626 # boolMetFin = ndimage.morphology.binary_dilation(boolMetFin)
2620 #Creating data_param
2627 #Creating data_param
2621 coordMet = numpy.where(boolMetFin)
2628 coordMet = numpy.where(boolMetFin)
2622
2629
2623 tmet = coordMet[0]
2630 tmet = coordMet[0]
2624 hmet = coordMet[1]
2631 hmet = coordMet[1]
2625
2632
2626 data_param = numpy.zeros((tmet.size, 6 + nPairs))
2633 data_param = numpy.zeros((tmet.size, 6 + nPairs))
2627 data_param[:,0] = utctime
2634 data_param[:,0] = utctime
2628 data_param[:,1] = tmet
2635 data_param[:,1] = tmet
2629 data_param[:,2] = hmet
2636 data_param[:,2] = hmet
2630 data_param[:,3] = SNRm[tmet,hmet]
2637 data_param[:,3] = SNRm[tmet,hmet]
2631 data_param[:,4] = velRad[tmet,hmet]
2638 data_param[:,4] = velRad[tmet,hmet]
2632 data_param[:,5] = coh[tmet,hmet]
2639 data_param[:,5] = coh[tmet,hmet]
2633 data_param[:,6:] = phase[:,tmet,hmet].T
2640 data_param[:,6:] = phase[:,tmet,hmet].T
2634
2641
2635 elif mode == 'DBS':
2642 elif mode == 'DBS':
2636 self.dataOut.groupList = numpy.arange(nChannels)
2643 self.dataOut.groupList = numpy.arange(nChannels)
2637
2644
2638 #Radial Velocities
2645 #Radial Velocities
2639 # phase = numpy.angle(data_acf[:,1,:,:])
2646 # phase = numpy.angle(data_acf[:,1,:,:])
2640 phase = ndimage.median_filter(numpy.angle(data_acf[:,1,:,:]), size = (1,5,1))
2647 phase = ndimage.median_filter(numpy.angle(data_acf[:,1,:,:]), size = (1,5,1))
2641 velRad = phase*lamb/(4*numpy.pi*tSamp)
2648 velRad = phase*lamb/(4*numpy.pi*tSamp)
2642
2649
2643 #Spectral width
2650 #Spectral width
2644 acf1 = ndimage.median_filter(numpy.abs(data_acf[:,1,:,:]), size = (1,5,1))
2651 acf1 = ndimage.median_filter(numpy.abs(data_acf[:,1,:,:]), size = (1,5,1))
2645 acf2 = ndimage.median_filter(numpy.abs(data_acf[:,2,:,:]), size = (1,5,1))
2652 acf2 = ndimage.median_filter(numpy.abs(data_acf[:,2,:,:]), size = (1,5,1))
2646
2653
2647 spcWidth = (lamb/(2*numpy.sqrt(6)*numpy.pi*tSamp))*numpy.sqrt(numpy.log(acf1/acf2))
2654 spcWidth = (lamb/(2*numpy.sqrt(6)*numpy.pi*tSamp))*numpy.sqrt(numpy.log(acf1/acf2))
2648 # velRad = ndimage.median_filter(velRad, size = (1,5,1))
2655 # velRad = ndimage.median_filter(velRad, size = (1,5,1))
2649 if allData:
2656 if allData:
2650 boolMetFin = ~numpy.isnan(SNRdB)
2657 boolMetFin = ~numpy.isnan(SNRdB)
2651 else:
2658 else:
2652 #SNR
2659 #SNR
2653 boolMet1 = (SNRdB>SNRthresh) #SNR mask
2660 boolMet1 = (SNRdB>SNRthresh) #SNR mask
2654 boolMet1 = ndimage.median_filter(boolMet1, size=(1,5,5))
2661 boolMet1 = ndimage.median_filter(boolMet1, size=(1,5,5))
2655
2662
2656 #Radial velocity
2663 #Radial velocity
2657 boolMet2 = numpy.abs(velRad) < 30
2664 boolMet2 = numpy.abs(velRad) < 30
2658 boolMet2 = ndimage.median_filter(boolMet2, (1,5,5))
2665 boolMet2 = ndimage.median_filter(boolMet2, (1,5,5))
2659
2666
2660 #Spectral Width
2667 #Spectral Width
2661 boolMet3 = spcWidth < 30
2668 boolMet3 = spcWidth < 30
2662 boolMet3 = ndimage.median_filter(boolMet3, (1,5,5))
2669 boolMet3 = ndimage.median_filter(boolMet3, (1,5,5))
2663 # boolMetFin = self.__erase_small(boolMet1, 10,5)
2670 # boolMetFin = self.__erase_small(boolMet1, 10,5)
2664 boolMetFin = boolMet1&boolMet2&boolMet3
2671 boolMetFin = boolMet1&boolMet2&boolMet3
2665
2672
2666 #Creating data_param
2673 #Creating data_param
2667 coordMet = numpy.where(boolMetFin)
2674 coordMet = numpy.where(boolMetFin)
2668
2675
2669 cmet = coordMet[0]
2676 cmet = coordMet[0]
2670 tmet = coordMet[1]
2677 tmet = coordMet[1]
2671 hmet = coordMet[2]
2678 hmet = coordMet[2]
2672
2679
2673 data_param = numpy.zeros((tmet.size, 7))
2680 data_param = numpy.zeros((tmet.size, 7))
2674 data_param[:,0] = utctime
2681 data_param[:,0] = utctime
2675 data_param[:,1] = cmet
2682 data_param[:,1] = cmet
2676 data_param[:,2] = tmet
2683 data_param[:,2] = tmet
2677 data_param[:,3] = hmet
2684 data_param[:,3] = hmet
2678 data_param[:,4] = SNR[cmet,tmet,hmet].T
2685 data_param[:,4] = SNR[cmet,tmet,hmet].T
2679 data_param[:,5] = velRad[cmet,tmet,hmet].T
2686 data_param[:,5] = velRad[cmet,tmet,hmet].T
2680 data_param[:,6] = spcWidth[cmet,tmet,hmet].T
2687 data_param[:,6] = spcWidth[cmet,tmet,hmet].T
2681
2688
2682 # self.dataOut.data_param = data_int
2689 # self.dataOut.data_param = data_int
2683 if len(data_param) == 0:
2690 if len(data_param) == 0:
2684 self.dataOut.flagNoData = True
2691 self.dataOut.flagNoData = True
2685 else:
2692 else:
2686 self.dataOut.data_param = data_param
2693 self.dataOut.data_param = data_param
2687
2694
2688 def __erase_small(self, binArray, threshX, threshY):
2695 def __erase_small(self, binArray, threshX, threshY):
2689 labarray, numfeat = ndimage.measurements.label(binArray)
2696 labarray, numfeat = ndimage.measurements.label(binArray)
2690 binArray1 = numpy.copy(binArray)
2697 binArray1 = numpy.copy(binArray)
2691
2698
2692 for i in range(1,numfeat + 1):
2699 for i in range(1,numfeat + 1):
2693 auxBin = (labarray==i)
2700 auxBin = (labarray==i)
2694 auxSize = auxBin.sum()
2701 auxSize = auxBin.sum()
2695
2702
2696 x,y = numpy.where(auxBin)
2703 x,y = numpy.where(auxBin)
2697 widthX = x.max() - x.min()
2704 widthX = x.max() - x.min()
2698 widthY = y.max() - y.min()
2705 widthY = y.max() - y.min()
2699
2706
2700 #width X: 3 seg -> 12.5*3
2707 #width X: 3 seg -> 12.5*3
2701 #width Y:
2708 #width Y:
2702
2709
2703 if (auxSize < 50) or (widthX < threshX) or (widthY < threshY):
2710 if (auxSize < 50) or (widthX < threshX) or (widthY < threshY):
2704 binArray1[auxBin] = False
2711 binArray1[auxBin] = False
2705
2712
2706 return binArray1
2713 return binArray1
2707
2714
2708 #--------------- Specular Meteor ----------------
2715 #--------------- Specular Meteor ----------------
2709
2716
2710 class SMDetection(Operation):
2717 class SMDetection(Operation):
2711 '''
2718 '''
2712 Function DetectMeteors()
2719 Function DetectMeteors()
2713 Project developed with paper:
2720 Project developed with paper:
2714 HOLDSWORTH ET AL. 2004
2721 HOLDSWORTH ET AL. 2004
2715
2722
2716 Input:
2723 Input:
2717 self.dataOut.data_pre
2724 self.dataOut.data_pre
2718
2725
2719 centerReceiverIndex: From the channels, which is the center receiver
2726 centerReceiverIndex: From the channels, which is the center receiver
2720
2727
2721 hei_ref: Height reference for the Beacon signal extraction
2728 hei_ref: Height reference for the Beacon signal extraction
2722 tauindex:
2729 tauindex:
2723 predefinedPhaseShifts: Predefined phase offset for the voltge signals
2730 predefinedPhaseShifts: Predefined phase offset for the voltge signals
2724
2731
2725 cohDetection: Whether to user Coherent detection or not
2732 cohDetection: Whether to user Coherent detection or not
2726 cohDet_timeStep: Coherent Detection calculation time step
2733 cohDet_timeStep: Coherent Detection calculation time step
2727 cohDet_thresh: Coherent Detection phase threshold to correct phases
2734 cohDet_thresh: Coherent Detection phase threshold to correct phases
2728
2735
2729 noise_timeStep: Noise calculation time step
2736 noise_timeStep: Noise calculation time step
2730 noise_multiple: Noise multiple to define signal threshold
2737 noise_multiple: Noise multiple to define signal threshold
2731
2738
2732 multDet_timeLimit: Multiple Detection Removal time limit in seconds
2739 multDet_timeLimit: Multiple Detection Removal time limit in seconds
2733 multDet_rangeLimit: Multiple Detection Removal range limit in km
2740 multDet_rangeLimit: Multiple Detection Removal range limit in km
2734
2741
2735 phaseThresh: Maximum phase difference between receiver to be consider a meteor
2742 phaseThresh: Maximum phase difference between receiver to be consider a meteor
2736 SNRThresh: Minimum SNR threshold of the meteor signal to be consider a meteor
2743 SNRThresh: Minimum SNR threshold of the meteor signal to be consider a meteor
2737
2744
2738 hmin: Minimum Height of the meteor to use it in the further wind estimations
2745 hmin: Minimum Height of the meteor to use it in the further wind estimations
2739 hmax: Maximum Height of the meteor to use it in the further wind estimations
2746 hmax: Maximum Height of the meteor to use it in the further wind estimations
2740 azimuth: Azimuth angle correction
2747 azimuth: Azimuth angle correction
2741
2748
2742 Affected:
2749 Affected:
2743 self.dataOut.data_param
2750 self.dataOut.data_param
2744
2751
2745 Rejection Criteria (Errors):
2752 Rejection Criteria (Errors):
2746 0: No error; analysis OK
2753 0: No error; analysis OK
2747 1: SNR < SNR threshold
2754 1: SNR < SNR threshold
2748 2: angle of arrival (AOA) ambiguously determined
2755 2: angle of arrival (AOA) ambiguously determined
2749 3: AOA estimate not feasible
2756 3: AOA estimate not feasible
2750 4: Large difference in AOAs obtained from different antenna baselines
2757 4: Large difference in AOAs obtained from different antenna baselines
2751 5: echo at start or end of time series
2758 5: echo at start or end of time series
2752 6: echo less than 5 examples long; too short for analysis
2759 6: echo less than 5 examples long; too short for analysis
2753 7: echo rise exceeds 0.3s
2760 7: echo rise exceeds 0.3s
2754 8: echo decay time less than twice rise time
2761 8: echo decay time less than twice rise time
2755 9: large power level before echo
2762 9: large power level before echo
2756 10: large power level after echo
2763 10: large power level after echo
2757 11: poor fit to amplitude for estimation of decay time
2764 11: poor fit to amplitude for estimation of decay time
2758 12: poor fit to CCF phase variation for estimation of radial drift velocity
2765 12: poor fit to CCF phase variation for estimation of radial drift velocity
2759 13: height unresolvable echo: not valid height within 70 to 110 km
2766 13: height unresolvable echo: not valid height within 70 to 110 km
2760 14: height ambiguous echo: more then one possible height within 70 to 110 km
2767 14: height ambiguous echo: more then one possible height within 70 to 110 km
2761 15: radial drift velocity or projected horizontal velocity exceeds 200 m/s
2768 15: radial drift velocity or projected horizontal velocity exceeds 200 m/s
2762 16: oscilatory echo, indicating event most likely not an underdense echo
2769 16: oscilatory echo, indicating event most likely not an underdense echo
2763
2770
2764 17: phase difference in meteor Reestimation
2771 17: phase difference in meteor Reestimation
2765
2772
2766 Data Storage:
2773 Data Storage:
2767 Meteors for Wind Estimation (8):
2774 Meteors for Wind Estimation (8):
2768 Utc Time | Range Height
2775 Utc Time | Range Height
2769 Azimuth Zenith errorCosDir
2776 Azimuth Zenith errorCosDir
2770 VelRad errorVelRad
2777 VelRad errorVelRad
2771 Phase0 Phase1 Phase2 Phase3
2778 Phase0 Phase1 Phase2 Phase3
2772 TypeError
2779 TypeError
2773
2780
2774 '''
2781 '''
2775
2782
2776 def run(self, dataOut, hei_ref = None, tauindex = 0,
2783 def run(self, dataOut, hei_ref = None, tauindex = 0,
2777 phaseOffsets = None,
2784 phaseOffsets = None,
2778 cohDetection = False, cohDet_timeStep = 1, cohDet_thresh = 25,
2785 cohDetection = False, cohDet_timeStep = 1, cohDet_thresh = 25,
2779 noise_timeStep = 4, noise_multiple = 4,
2786 noise_timeStep = 4, noise_multiple = 4,
2780 multDet_timeLimit = 1, multDet_rangeLimit = 3,
2787 multDet_timeLimit = 1, multDet_rangeLimit = 3,
2781 phaseThresh = 20, SNRThresh = 5,
2788 phaseThresh = 20, SNRThresh = 5,
2782 hmin = 50, hmax=150, azimuth = 0,
2789 hmin = 50, hmax=150, azimuth = 0,
2783 channelPositions = None) :
2790 channelPositions = None) :
2784
2791
2785
2792
2786 #Getting Pairslist
2793 #Getting Pairslist
2787 if channelPositions == None:
2794 if channelPositions == None:
2788 # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T
2795 # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T
2789 channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella
2796 channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella
2790 meteorOps = SMOperations()
2797 meteorOps = SMOperations()
2791 pairslist0, distances = meteorOps.getPhasePairs(channelPositions)
2798 pairslist0, distances = meteorOps.getPhasePairs(channelPositions)
2792 heiRang = dataOut.getHeiRange()
2799 heiRang = dataOut.getHeiRange()
2793 #Get Beacon signal - No Beacon signal anymore
2800 #Get Beacon signal - No Beacon signal anymore
2794 # newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex])
2801 # newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex])
2795 #
2802 #
2796 # if hei_ref != None:
2803 # if hei_ref != None:
2797 # newheis = numpy.where(self.dataOut.heightList>hei_ref)
2804 # newheis = numpy.where(self.dataOut.heightList>hei_ref)
2798 #
2805 #
2799
2806
2800
2807
2801 #****************REMOVING HARDWARE PHASE DIFFERENCES***************
2808 #****************REMOVING HARDWARE PHASE DIFFERENCES***************
2802 # see if the user put in pre defined phase shifts
2809 # see if the user put in pre defined phase shifts
2803 voltsPShift = dataOut.data_pre.copy()
2810 voltsPShift = dataOut.data_pre.copy()
2804
2811
2805 # if predefinedPhaseShifts != None:
2812 # if predefinedPhaseShifts != None:
2806 # hardwarePhaseShifts = numpy.array(predefinedPhaseShifts)*numpy.pi/180
2813 # hardwarePhaseShifts = numpy.array(predefinedPhaseShifts)*numpy.pi/180
2807 #
2814 #
2808 # # elif beaconPhaseShifts:
2815 # # elif beaconPhaseShifts:
2809 # # #get hardware phase shifts using beacon signal
2816 # # #get hardware phase shifts using beacon signal
2810 # # hardwarePhaseShifts = self.__getHardwarePhaseDiff(self.dataOut.data_pre, pairslist, newheis, 10)
2817 # # hardwarePhaseShifts = self.__getHardwarePhaseDiff(self.dataOut.data_pre, pairslist, newheis, 10)
2811 # # hardwarePhaseShifts = numpy.insert(hardwarePhaseShifts,centerReceiverIndex,0)
2818 # # hardwarePhaseShifts = numpy.insert(hardwarePhaseShifts,centerReceiverIndex,0)
2812 #
2819 #
2813 # else:
2820 # else:
2814 # hardwarePhaseShifts = numpy.zeros(5)
2821 # hardwarePhaseShifts = numpy.zeros(5)
2815 #
2822 #
2816 # voltsPShift = numpy.zeros((self.dataOut.data_pre.shape[0],self.dataOut.data_pre.shape[1],self.dataOut.data_pre.shape[2]), dtype = 'complex')
2823 # voltsPShift = numpy.zeros((self.dataOut.data_pre.shape[0],self.dataOut.data_pre.shape[1],self.dataOut.data_pre.shape[2]), dtype = 'complex')
2817 # for i in range(self.dataOut.data_pre.shape[0]):
2824 # for i in range(self.dataOut.data_pre.shape[0]):
2818 # voltsPShift[i,:,:] = self.__shiftPhase(self.dataOut.data_pre[i,:,:], hardwarePhaseShifts[i])
2825 # voltsPShift[i,:,:] = self.__shiftPhase(self.dataOut.data_pre[i,:,:], hardwarePhaseShifts[i])
2819
2826
2820 #******************END OF REMOVING HARDWARE PHASE DIFFERENCES*********
2827 #******************END OF REMOVING HARDWARE PHASE DIFFERENCES*********
2821
2828
2822 #Remove DC
2829 #Remove DC
2823 voltsDC = numpy.mean(voltsPShift,1)
2830 voltsDC = numpy.mean(voltsPShift,1)
2824 voltsDC = numpy.mean(voltsDC,1)
2831 voltsDC = numpy.mean(voltsDC,1)
2825 for i in range(voltsDC.shape[0]):
2832 for i in range(voltsDC.shape[0]):
2826 voltsPShift[i] = voltsPShift[i] - voltsDC[i]
2833 voltsPShift[i] = voltsPShift[i] - voltsDC[i]
2827
2834
2828 #Don't considerate last heights, theyre used to calculate Hardware Phase Shift
2835 #Don't considerate last heights, theyre used to calculate Hardware Phase Shift
2829 # voltsPShift = voltsPShift[:,:,:newheis[0][0]]
2836 # voltsPShift = voltsPShift[:,:,:newheis[0][0]]
2830
2837
2831 #************ FIND POWER OF DATA W/COH OR NON COH DETECTION (3.4) **********
2838 #************ FIND POWER OF DATA W/COH OR NON COH DETECTION (3.4) **********
2832 #Coherent Detection
2839 #Coherent Detection
2833 if cohDetection:
2840 if cohDetection:
2834 #use coherent detection to get the net power
2841 #use coherent detection to get the net power
2835 cohDet_thresh = cohDet_thresh*numpy.pi/180
2842 cohDet_thresh = cohDet_thresh*numpy.pi/180
2836 voltsPShift = self.__coherentDetection(voltsPShift, cohDet_timeStep, dataOut.timeInterval, pairslist0, cohDet_thresh)
2843 voltsPShift = self.__coherentDetection(voltsPShift, cohDet_timeStep, dataOut.timeInterval, pairslist0, cohDet_thresh)
2837
2844
2838 #Non-coherent detection!
2845 #Non-coherent detection!
2839 powerNet = numpy.nansum(numpy.abs(voltsPShift[:,:,:])**2,0)
2846 powerNet = numpy.nansum(numpy.abs(voltsPShift[:,:,:])**2,0)
2840 #********** END OF COH/NON-COH POWER CALCULATION**********************
2847 #********** END OF COH/NON-COH POWER CALCULATION**********************
2841
2848
2842 #********** FIND THE NOISE LEVEL AND POSSIBLE METEORS ****************
2849 #********** FIND THE NOISE LEVEL AND POSSIBLE METEORS ****************
2843 #Get noise
2850 #Get noise
2844 noise, noise1 = self.__getNoise(powerNet, noise_timeStep, dataOut.timeInterval)
2851 noise, noise1 = self.__getNoise(powerNet, noise_timeStep, dataOut.timeInterval)
2845 # noise = self.getNoise1(powerNet, noise_timeStep, self.dataOut.timeInterval)
2852 # noise = self.getNoise1(powerNet, noise_timeStep, self.dataOut.timeInterval)
2846 #Get signal threshold
2853 #Get signal threshold
2847 signalThresh = noise_multiple*noise
2854 signalThresh = noise_multiple*noise
2848 #Meteor echoes detection
2855 #Meteor echoes detection
2849 listMeteors = self.__findMeteors(powerNet, signalThresh)
2856 listMeteors = self.__findMeteors(powerNet, signalThresh)
2850 #******* END OF NOISE LEVEL AND POSSIBLE METEORS CACULATION **********
2857 #******* END OF NOISE LEVEL AND POSSIBLE METEORS CACULATION **********
2851
2858
2852 #************** REMOVE MULTIPLE DETECTIONS (3.5) ***************************
2859 #************** REMOVE MULTIPLE DETECTIONS (3.5) ***************************
2853 #Parameters
2860 #Parameters
2854 heiRange = dataOut.getHeiRange()
2861 heiRange = dataOut.getHeiRange()
2855 rangeInterval = heiRange[1] - heiRange[0]
2862 rangeInterval = heiRange[1] - heiRange[0]
2856 rangeLimit = multDet_rangeLimit/rangeInterval
2863 rangeLimit = multDet_rangeLimit/rangeInterval
2857 timeLimit = multDet_timeLimit/dataOut.timeInterval
2864 timeLimit = multDet_timeLimit/dataOut.timeInterval
2858 #Multiple detection removals
2865 #Multiple detection removals
2859 listMeteors1 = self.__removeMultipleDetections(listMeteors, rangeLimit, timeLimit)
2866 listMeteors1 = self.__removeMultipleDetections(listMeteors, rangeLimit, timeLimit)
2860 #************ END OF REMOVE MULTIPLE DETECTIONS **********************
2867 #************ END OF REMOVE MULTIPLE DETECTIONS **********************
2861
2868
2862 #********************* METEOR REESTIMATION (3.7, 3.8, 3.9, 3.10) ********************
2869 #********************* METEOR REESTIMATION (3.7, 3.8, 3.9, 3.10) ********************
2863 #Parameters
2870 #Parameters
2864 phaseThresh = phaseThresh*numpy.pi/180
2871 phaseThresh = phaseThresh*numpy.pi/180
2865 thresh = [phaseThresh, noise_multiple, SNRThresh]
2872 thresh = [phaseThresh, noise_multiple, SNRThresh]
2866 #Meteor reestimation (Errors N 1, 6, 12, 17)
2873 #Meteor reestimation (Errors N 1, 6, 12, 17)
2867 listMeteors2, listMeteorsPower, listMeteorsVolts = self.__meteorReestimation(listMeteors1, voltsPShift, pairslist0, thresh, noise, dataOut.timeInterval, dataOut.frequency)
2874 listMeteors2, listMeteorsPower, listMeteorsVolts = self.__meteorReestimation(listMeteors1, voltsPShift, pairslist0, thresh, noise, dataOut.timeInterval, dataOut.frequency)
2868 # listMeteors2, listMeteorsPower, listMeteorsVolts = self.meteorReestimation3(listMeteors2, listMeteorsPower, listMeteorsVolts, voltsPShift, pairslist, thresh, noise)
2875 # listMeteors2, listMeteorsPower, listMeteorsVolts = self.meteorReestimation3(listMeteors2, listMeteorsPower, listMeteorsVolts, voltsPShift, pairslist, thresh, noise)
2869 #Estimation of decay times (Errors N 7, 8, 11)
2876 #Estimation of decay times (Errors N 7, 8, 11)
2870 listMeteors3 = self.__estimateDecayTime(listMeteors2, listMeteorsPower, dataOut.timeInterval, dataOut.frequency)
2877 listMeteors3 = self.__estimateDecayTime(listMeteors2, listMeteorsPower, dataOut.timeInterval, dataOut.frequency)
2871 #******************* END OF METEOR REESTIMATION *******************
2878 #******************* END OF METEOR REESTIMATION *******************
2872
2879
2873 #********************* METEOR PARAMETERS CALCULATION (3.11, 3.12, 3.13) **************************
2880 #********************* METEOR PARAMETERS CALCULATION (3.11, 3.12, 3.13) **************************
2874 #Calculating Radial Velocity (Error N 15)
2881 #Calculating Radial Velocity (Error N 15)
2875 radialStdThresh = 10
2882 radialStdThresh = 10
2876 listMeteors4 = self.__getRadialVelocity(listMeteors3, listMeteorsVolts, radialStdThresh, pairslist0, dataOut.timeInterval)
2883 listMeteors4 = self.__getRadialVelocity(listMeteors3, listMeteorsVolts, radialStdThresh, pairslist0, dataOut.timeInterval)
2877
2884
2878 if len(listMeteors4) > 0:
2885 if len(listMeteors4) > 0:
2879 #Setting New Array
2886 #Setting New Array
2880 date = dataOut.utctime
2887 date = dataOut.utctime
2881 arrayParameters = self.__setNewArrays(listMeteors4, date, heiRang)
2888 arrayParameters = self.__setNewArrays(listMeteors4, date, heiRang)
2882
2889
2883 #Correcting phase offset
2890 #Correcting phase offset
2884 if phaseOffsets != None:
2891 if phaseOffsets != None:
2885 phaseOffsets = numpy.array(phaseOffsets)*numpy.pi/180
2892 phaseOffsets = numpy.array(phaseOffsets)*numpy.pi/180
2886 arrayParameters[:,8:12] = numpy.unwrap(arrayParameters[:,8:12] + phaseOffsets)
2893 arrayParameters[:,8:12] = numpy.unwrap(arrayParameters[:,8:12] + phaseOffsets)
2887
2894
2888 #Second Pairslist
2895 #Second Pairslist
2889 pairsList = []
2896 pairsList = []
2890 pairx = (0,1)
2897 pairx = (0,1)
2891 pairy = (2,3)
2898 pairy = (2,3)
2892 pairsList.append(pairx)
2899 pairsList.append(pairx)
2893 pairsList.append(pairy)
2900 pairsList.append(pairy)
2894
2901
2895 jph = numpy.array([0,0,0,0])
2902 jph = numpy.array([0,0,0,0])
2896 h = (hmin,hmax)
2903 h = (hmin,hmax)
2897 arrayParameters = meteorOps.getMeteorParams(arrayParameters, azimuth, h, pairsList, distances, jph)
2904 arrayParameters = meteorOps.getMeteorParams(arrayParameters, azimuth, h, pairsList, distances, jph)
2898
2905
2899 # #Calculate AOA (Error N 3, 4)
2906 # #Calculate AOA (Error N 3, 4)
2900 # #JONES ET AL. 1998
2907 # #JONES ET AL. 1998
2901 # error = arrayParameters[:,-1]
2908 # error = arrayParameters[:,-1]
2902 # AOAthresh = numpy.pi/8
2909 # AOAthresh = numpy.pi/8
2903 # phases = -arrayParameters[:,9:13]
2910 # phases = -arrayParameters[:,9:13]
2904 # arrayParameters[:,4:7], arrayParameters[:,-1] = meteorOps.getAOA(phases, pairsList, error, AOAthresh, azimuth)
2911 # arrayParameters[:,4:7], arrayParameters[:,-1] = meteorOps.getAOA(phases, pairsList, error, AOAthresh, azimuth)
2905 #
2912 #
2906 # #Calculate Heights (Error N 13 and 14)
2913 # #Calculate Heights (Error N 13 and 14)
2907 # error = arrayParameters[:,-1]
2914 # error = arrayParameters[:,-1]
2908 # Ranges = arrayParameters[:,2]
2915 # Ranges = arrayParameters[:,2]
2909 # zenith = arrayParameters[:,5]
2916 # zenith = arrayParameters[:,5]
2910 # arrayParameters[:,3], arrayParameters[:,-1] = meteorOps.getHeights(Ranges, zenith, error, hmin, hmax)
2917 # arrayParameters[:,3], arrayParameters[:,-1] = meteorOps.getHeights(Ranges, zenith, error, hmin, hmax)
2911 # error = arrayParameters[:,-1]
2918 # error = arrayParameters[:,-1]
2912 #********************* END OF PARAMETERS CALCULATION **************************
2919 #********************* END OF PARAMETERS CALCULATION **************************
2913
2920
2914 #***************************+ PASS DATA TO NEXT STEP **********************
2921 #***************************+ PASS DATA TO NEXT STEP **********************
2915 # arrayFinal = arrayParameters.reshape((1,arrayParameters.shape[0],arrayParameters.shape[1]))
2922 # arrayFinal = arrayParameters.reshape((1,arrayParameters.shape[0],arrayParameters.shape[1]))
2916 dataOut.data_param = arrayParameters
2923 dataOut.data_param = arrayParameters
2917
2924
2918 if arrayParameters == None:
2925 if arrayParameters == None:
2919 dataOut.flagNoData = True
2926 dataOut.flagNoData = True
2920 else:
2927 else:
2921 dataOut.flagNoData = True
2928 dataOut.flagNoData = True
2922
2929
2923 return
2930 return
2924
2931
2925 def __getHardwarePhaseDiff(self, voltage0, pairslist, newheis, n):
2932 def __getHardwarePhaseDiff(self, voltage0, pairslist, newheis, n):
2926
2933
2927 minIndex = min(newheis[0])
2934 minIndex = min(newheis[0])
2928 maxIndex = max(newheis[0])
2935 maxIndex = max(newheis[0])
2929
2936
2930 voltage = voltage0[:,:,minIndex:maxIndex+1]
2937 voltage = voltage0[:,:,minIndex:maxIndex+1]
2931 nLength = voltage.shape[1]/n
2938 nLength = voltage.shape[1]/n
2932 nMin = 0
2939 nMin = 0
2933 nMax = 0
2940 nMax = 0
2934 phaseOffset = numpy.zeros((len(pairslist),n))
2941 phaseOffset = numpy.zeros((len(pairslist),n))
2935
2942
2936 for i in range(n):
2943 for i in range(n):
2937 nMax += nLength
2944 nMax += nLength
2938 phaseCCF = -numpy.angle(self.__calculateCCF(voltage[:,nMin:nMax,:], pairslist, [0]))
2945 phaseCCF = -numpy.angle(self.__calculateCCF(voltage[:,nMin:nMax,:], pairslist, [0]))
2939 phaseCCF = numpy.mean(phaseCCF, axis = 2)
2946 phaseCCF = numpy.mean(phaseCCF, axis = 2)
2940 phaseOffset[:,i] = phaseCCF.transpose()
2947 phaseOffset[:,i] = phaseCCF.transpose()
2941 nMin = nMax
2948 nMin = nMax
2942 # phaseDiff, phaseArrival = self.estimatePhaseDifference(voltage, pairslist)
2949 # phaseDiff, phaseArrival = self.estimatePhaseDifference(voltage, pairslist)
2943
2950
2944 #Remove Outliers
2951 #Remove Outliers
2945 factor = 2
2952 factor = 2
2946 wt = phaseOffset - signal.medfilt(phaseOffset,(1,5))
2953 wt = phaseOffset - signal.medfilt(phaseOffset,(1,5))
2947 dw = numpy.std(wt,axis = 1)
2954 dw = numpy.std(wt,axis = 1)
2948 dw = dw.reshape((dw.size,1))
2955 dw = dw.reshape((dw.size,1))
2949 ind = numpy.where(numpy.logical_or(wt>dw*factor,wt<-dw*factor))
2956 ind = numpy.where(numpy.logical_or(wt>dw*factor,wt<-dw*factor))
2950 phaseOffset[ind] = numpy.nan
2957 phaseOffset[ind] = numpy.nan
2951 phaseOffset = stats.nanmean(phaseOffset, axis=1)
2958 phaseOffset = stats.nanmean(phaseOffset, axis=1)
2952
2959
2953 return phaseOffset
2960 return phaseOffset
2954
2961
2955 def __shiftPhase(self, data, phaseShift):
2962 def __shiftPhase(self, data, phaseShift):
2956 #this will shift the phase of a complex number
2963 #this will shift the phase of a complex number
2957 dataShifted = numpy.abs(data) * numpy.exp((numpy.angle(data)+phaseShift)*1j)
2964 dataShifted = numpy.abs(data) * numpy.exp((numpy.angle(data)+phaseShift)*1j)
2958 return dataShifted
2965 return dataShifted
2959
2966
2960 def __estimatePhaseDifference(self, array, pairslist):
2967 def __estimatePhaseDifference(self, array, pairslist):
2961 nChannel = array.shape[0]
2968 nChannel = array.shape[0]
2962 nHeights = array.shape[2]
2969 nHeights = array.shape[2]
2963 numPairs = len(pairslist)
2970 numPairs = len(pairslist)
2964 # phaseCCF = numpy.zeros((nChannel, 5, nHeights))
2971 # phaseCCF = numpy.zeros((nChannel, 5, nHeights))
2965 phaseCCF = numpy.angle(self.__calculateCCF(array, pairslist, [-2,-1,0,1,2]))
2972 phaseCCF = numpy.angle(self.__calculateCCF(array, pairslist, [-2,-1,0,1,2]))
2966
2973
2967 #Correct phases
2974 #Correct phases
2968 derPhaseCCF = phaseCCF[:,1:,:] - phaseCCF[:,0:-1,:]
2975 derPhaseCCF = phaseCCF[:,1:,:] - phaseCCF[:,0:-1,:]
2969 indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi)
2976 indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi)
2970
2977
2971 if indDer[0].shape[0] > 0:
2978 if indDer[0].shape[0] > 0:
2972 for i in range(indDer[0].shape[0]):
2979 for i in range(indDer[0].shape[0]):
2973 signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i],indDer[2][i]])
2980 signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i],indDer[2][i]])
2974 phaseCCF[indDer[0][i],indDer[1][i]+1:,:] += signo*2*numpy.pi
2981 phaseCCF[indDer[0][i],indDer[1][i]+1:,:] += signo*2*numpy.pi
2975
2982
2976 # for j in range(numSides):
2983 # for j in range(numSides):
2977 # phaseCCFAux = self.calculateCCF(arrayCenter, arraySides[j,:,:], [-2,1,0,1,2])
2984 # phaseCCFAux = self.calculateCCF(arrayCenter, arraySides[j,:,:], [-2,1,0,1,2])
2978 # phaseCCF[j,:,:] = numpy.angle(phaseCCFAux)
2985 # phaseCCF[j,:,:] = numpy.angle(phaseCCFAux)
2979 #
2986 #
2980 #Linear
2987 #Linear
2981 phaseInt = numpy.zeros((numPairs,1))
2988 phaseInt = numpy.zeros((numPairs,1))
2982 angAllCCF = phaseCCF[:,[0,1,3,4],0]
2989 angAllCCF = phaseCCF[:,[0,1,3,4],0]
2983 for j in range(numPairs):
2990 for j in range(numPairs):
2984 fit = stats.linregress([-2,-1,1,2],angAllCCF[j,:])
2991 fit = stats.linregress([-2,-1,1,2],angAllCCF[j,:])
2985 phaseInt[j] = fit[1]
2992 phaseInt[j] = fit[1]
2986 #Phase Differences
2993 #Phase Differences
2987 phaseDiff = phaseInt - phaseCCF[:,2,:]
2994 phaseDiff = phaseInt - phaseCCF[:,2,:]
2988 phaseArrival = phaseInt.reshape(phaseInt.size)
2995 phaseArrival = phaseInt.reshape(phaseInt.size)
2989
2996
2990 #Dealias
2997 #Dealias
2991 phaseArrival = numpy.angle(numpy.exp(1j*phaseArrival))
2998 phaseArrival = numpy.angle(numpy.exp(1j*phaseArrival))
2992 # indAlias = numpy.where(phaseArrival > numpy.pi)
2999 # indAlias = numpy.where(phaseArrival > numpy.pi)
2993 # phaseArrival[indAlias] -= 2*numpy.pi
3000 # phaseArrival[indAlias] -= 2*numpy.pi
2994 # indAlias = numpy.where(phaseArrival < -numpy.pi)
3001 # indAlias = numpy.where(phaseArrival < -numpy.pi)
2995 # phaseArrival[indAlias] += 2*numpy.pi
3002 # phaseArrival[indAlias] += 2*numpy.pi
2996
3003
2997 return phaseDiff, phaseArrival
3004 return phaseDiff, phaseArrival
2998
3005
2999 def __coherentDetection(self, volts, timeSegment, timeInterval, pairslist, thresh):
3006 def __coherentDetection(self, volts, timeSegment, timeInterval, pairslist, thresh):
3000 #this function will run the coherent detection used in Holdworth et al. 2004 and return the net power
3007 #this function will run the coherent detection used in Holdworth et al. 2004 and return the net power
3001 #find the phase shifts of each channel over 1 second intervals
3008 #find the phase shifts of each channel over 1 second intervals
3002 #only look at ranges below the beacon signal
3009 #only look at ranges below the beacon signal
3003 numProfPerBlock = numpy.ceil(timeSegment/timeInterval)
3010 numProfPerBlock = numpy.ceil(timeSegment/timeInterval)
3004 numBlocks = int(volts.shape[1]/numProfPerBlock)
3011 numBlocks = int(volts.shape[1]/numProfPerBlock)
3005 numHeights = volts.shape[2]
3012 numHeights = volts.shape[2]
3006 nChannel = volts.shape[0]
3013 nChannel = volts.shape[0]
3007 voltsCohDet = volts.copy()
3014 voltsCohDet = volts.copy()
3008
3015
3009 pairsarray = numpy.array(pairslist)
3016 pairsarray = numpy.array(pairslist)
3010 indSides = pairsarray[:,1]
3017 indSides = pairsarray[:,1]
3011 # indSides = numpy.array(range(nChannel))
3018 # indSides = numpy.array(range(nChannel))
3012 # indSides = numpy.delete(indSides, indCenter)
3019 # indSides = numpy.delete(indSides, indCenter)
3013 #
3020 #
3014 # listCenter = numpy.array_split(volts[indCenter,:,:], numBlocks, 0)
3021 # listCenter = numpy.array_split(volts[indCenter,:,:], numBlocks, 0)
3015 listBlocks = numpy.array_split(volts, numBlocks, 1)
3022 listBlocks = numpy.array_split(volts, numBlocks, 1)
3016
3023
3017 startInd = 0
3024 startInd = 0
3018 endInd = 0
3025 endInd = 0
3019
3026
3020 for i in range(numBlocks):
3027 for i in range(numBlocks):
3021 startInd = endInd
3028 startInd = endInd
3022 endInd = endInd + listBlocks[i].shape[1]
3029 endInd = endInd + listBlocks[i].shape[1]
3023
3030
3024 arrayBlock = listBlocks[i]
3031 arrayBlock = listBlocks[i]
3025 # arrayBlockCenter = listCenter[i]
3032 # arrayBlockCenter = listCenter[i]
3026
3033
3027 #Estimate the Phase Difference
3034 #Estimate the Phase Difference
3028 phaseDiff, aux = self.__estimatePhaseDifference(arrayBlock, pairslist)
3035 phaseDiff, aux = self.__estimatePhaseDifference(arrayBlock, pairslist)
3029 #Phase Difference RMS
3036 #Phase Difference RMS
3030 arrayPhaseRMS = numpy.abs(phaseDiff)
3037 arrayPhaseRMS = numpy.abs(phaseDiff)
3031 phaseRMSaux = numpy.sum(arrayPhaseRMS < thresh,0)
3038 phaseRMSaux = numpy.sum(arrayPhaseRMS < thresh,0)
3032 indPhase = numpy.where(phaseRMSaux==4)
3039 indPhase = numpy.where(phaseRMSaux==4)
3033 #Shifting
3040 #Shifting
3034 if indPhase[0].shape[0] > 0:
3041 if indPhase[0].shape[0] > 0:
3035 for j in range(indSides.size):
3042 for j in range(indSides.size):
3036 arrayBlock[indSides[j],:,indPhase] = self.__shiftPhase(arrayBlock[indSides[j],:,indPhase], phaseDiff[j,indPhase].transpose())
3043 arrayBlock[indSides[j],:,indPhase] = self.__shiftPhase(arrayBlock[indSides[j],:,indPhase], phaseDiff[j,indPhase].transpose())
3037 voltsCohDet[:,startInd:endInd,:] = arrayBlock
3044 voltsCohDet[:,startInd:endInd,:] = arrayBlock
3038
3045
3039 return voltsCohDet
3046 return voltsCohDet
3040
3047
3041 def __calculateCCF(self, volts, pairslist ,laglist):
3048 def __calculateCCF(self, volts, pairslist ,laglist):
3042
3049
3043 nHeights = volts.shape[2]
3050 nHeights = volts.shape[2]
3044 nPoints = volts.shape[1]
3051 nPoints = volts.shape[1]
3045 voltsCCF = numpy.zeros((len(pairslist), len(laglist), nHeights),dtype = 'complex')
3052 voltsCCF = numpy.zeros((len(pairslist), len(laglist), nHeights),dtype = 'complex')
3046
3053
3047 for i in range(len(pairslist)):
3054 for i in range(len(pairslist)):
3048 volts1 = volts[pairslist[i][0]]
3055 volts1 = volts[pairslist[i][0]]
3049 volts2 = volts[pairslist[i][1]]
3056 volts2 = volts[pairslist[i][1]]
3050
3057
3051 for t in range(len(laglist)):
3058 for t in range(len(laglist)):
3052 idxT = laglist[t]
3059 idxT = laglist[t]
3053 if idxT >= 0:
3060 if idxT >= 0:
3054 vStacked = numpy.vstack((volts2[idxT:,:],
3061 vStacked = numpy.vstack((volts2[idxT:,:],
3055 numpy.zeros((idxT, nHeights),dtype='complex')))
3062 numpy.zeros((idxT, nHeights),dtype='complex')))
3056 else:
3063 else:
3057 vStacked = numpy.vstack((numpy.zeros((-idxT, nHeights),dtype='complex'),
3064 vStacked = numpy.vstack((numpy.zeros((-idxT, nHeights),dtype='complex'),
3058 volts2[:(nPoints + idxT),:]))
3065 volts2[:(nPoints + idxT),:]))
3059 voltsCCF[i,t,:] = numpy.sum((numpy.conjugate(volts1)*vStacked),axis=0)
3066 voltsCCF[i,t,:] = numpy.sum((numpy.conjugate(volts1)*vStacked),axis=0)
3060
3067
3061 vStacked = None
3068 vStacked = None
3062 return voltsCCF
3069 return voltsCCF
3063
3070
3064 def __getNoise(self, power, timeSegment, timeInterval):
3071 def __getNoise(self, power, timeSegment, timeInterval):
3065 numProfPerBlock = numpy.ceil(timeSegment/timeInterval)
3072 numProfPerBlock = numpy.ceil(timeSegment/timeInterval)
3066 numBlocks = int(power.shape[0]/numProfPerBlock)
3073 numBlocks = int(power.shape[0]/numProfPerBlock)
3067 numHeights = power.shape[1]
3074 numHeights = power.shape[1]
3068
3075
3069 listPower = numpy.array_split(power, numBlocks, 0)
3076 listPower = numpy.array_split(power, numBlocks, 0)
3070 noise = numpy.zeros((power.shape[0], power.shape[1]))
3077 noise = numpy.zeros((power.shape[0], power.shape[1]))
3071 noise1 = numpy.zeros((power.shape[0], power.shape[1]))
3078 noise1 = numpy.zeros((power.shape[0], power.shape[1]))
3072
3079
3073 startInd = 0
3080 startInd = 0
3074 endInd = 0
3081 endInd = 0
3075
3082
3076 for i in range(numBlocks): #split por canal
3083 for i in range(numBlocks): #split por canal
3077 startInd = endInd
3084 startInd = endInd
3078 endInd = endInd + listPower[i].shape[0]
3085 endInd = endInd + listPower[i].shape[0]
3079
3086
3080 arrayBlock = listPower[i]
3087 arrayBlock = listPower[i]
3081 noiseAux = numpy.mean(arrayBlock, 0)
3088 noiseAux = numpy.mean(arrayBlock, 0)
3082 # noiseAux = numpy.median(noiseAux)
3089 # noiseAux = numpy.median(noiseAux)
3083 # noiseAux = numpy.mean(arrayBlock)
3090 # noiseAux = numpy.mean(arrayBlock)
3084 noise[startInd:endInd,:] = noise[startInd:endInd,:] + noiseAux
3091 noise[startInd:endInd,:] = noise[startInd:endInd,:] + noiseAux
3085
3092
3086 noiseAux1 = numpy.mean(arrayBlock)
3093 noiseAux1 = numpy.mean(arrayBlock)
3087 noise1[startInd:endInd,:] = noise1[startInd:endInd,:] + noiseAux1
3094 noise1[startInd:endInd,:] = noise1[startInd:endInd,:] + noiseAux1
3088
3095
3089 return noise, noise1
3096 return noise, noise1
3090
3097
3091 def __findMeteors(self, power, thresh):
3098 def __findMeteors(self, power, thresh):
3092 nProf = power.shape[0]
3099 nProf = power.shape[0]
3093 nHeights = power.shape[1]
3100 nHeights = power.shape[1]
3094 listMeteors = []
3101 listMeteors = []
3095
3102
3096 for i in range(nHeights):
3103 for i in range(nHeights):
3097 powerAux = power[:,i]
3104 powerAux = power[:,i]
3098 threshAux = thresh[:,i]
3105 threshAux = thresh[:,i]
3099
3106
3100 indUPthresh = numpy.where(powerAux > threshAux)[0]
3107 indUPthresh = numpy.where(powerAux > threshAux)[0]
3101 indDNthresh = numpy.where(powerAux <= threshAux)[0]
3108 indDNthresh = numpy.where(powerAux <= threshAux)[0]
3102
3109
3103 j = 0
3110 j = 0
3104
3111
3105 while (j < indUPthresh.size - 2):
3112 while (j < indUPthresh.size - 2):
3106 if (indUPthresh[j + 2] == indUPthresh[j] + 2):
3113 if (indUPthresh[j + 2] == indUPthresh[j] + 2):
3107 indDNAux = numpy.where(indDNthresh > indUPthresh[j])
3114 indDNAux = numpy.where(indDNthresh > indUPthresh[j])
3108 indDNthresh = indDNthresh[indDNAux]
3115 indDNthresh = indDNthresh[indDNAux]
3109
3116
3110 if (indDNthresh.size > 0):
3117 if (indDNthresh.size > 0):
3111 indEnd = indDNthresh[0] - 1
3118 indEnd = indDNthresh[0] - 1
3112 indInit = indUPthresh[j]
3119 indInit = indUPthresh[j]
3113
3120
3114 meteor = powerAux[indInit:indEnd + 1]
3121 meteor = powerAux[indInit:indEnd + 1]
3115 indPeak = meteor.argmax() + indInit
3122 indPeak = meteor.argmax() + indInit
3116 FLA = sum(numpy.conj(meteor)*numpy.hstack((meteor[1:],0)))
3123 FLA = sum(numpy.conj(meteor)*numpy.hstack((meteor[1:],0)))
3117
3124
3118 listMeteors.append(numpy.array([i,indInit,indPeak,indEnd,FLA])) #CHEQUEAR!!!!!
3125 listMeteors.append(numpy.array([i,indInit,indPeak,indEnd,FLA])) #CHEQUEAR!!!!!
3119 j = numpy.where(indUPthresh == indEnd)[0] + 1
3126 j = numpy.where(indUPthresh == indEnd)[0] + 1
3120 else: j+=1
3127 else: j+=1
3121 else: j+=1
3128 else: j+=1
3122
3129
3123 return listMeteors
3130 return listMeteors
3124
3131
3125 def __removeMultipleDetections(self,listMeteors, rangeLimit, timeLimit):
3132 def __removeMultipleDetections(self,listMeteors, rangeLimit, timeLimit):
3126
3133
3127 arrayMeteors = numpy.asarray(listMeteors)
3134 arrayMeteors = numpy.asarray(listMeteors)
3128 listMeteors1 = []
3135 listMeteors1 = []
3129
3136
3130 while arrayMeteors.shape[0] > 0:
3137 while arrayMeteors.shape[0] > 0:
3131 FLAs = arrayMeteors[:,4]
3138 FLAs = arrayMeteors[:,4]
3132 maxFLA = FLAs.argmax()
3139 maxFLA = FLAs.argmax()
3133 listMeteors1.append(arrayMeteors[maxFLA,:])
3140 listMeteors1.append(arrayMeteors[maxFLA,:])
3134
3141
3135 MeteorInitTime = arrayMeteors[maxFLA,1]
3142 MeteorInitTime = arrayMeteors[maxFLA,1]
3136 MeteorEndTime = arrayMeteors[maxFLA,3]
3143 MeteorEndTime = arrayMeteors[maxFLA,3]
3137 MeteorHeight = arrayMeteors[maxFLA,0]
3144 MeteorHeight = arrayMeteors[maxFLA,0]
3138
3145
3139 #Check neighborhood
3146 #Check neighborhood
3140 maxHeightIndex = MeteorHeight + rangeLimit
3147 maxHeightIndex = MeteorHeight + rangeLimit
3141 minHeightIndex = MeteorHeight - rangeLimit
3148 minHeightIndex = MeteorHeight - rangeLimit
3142 minTimeIndex = MeteorInitTime - timeLimit
3149 minTimeIndex = MeteorInitTime - timeLimit
3143 maxTimeIndex = MeteorEndTime + timeLimit
3150 maxTimeIndex = MeteorEndTime + timeLimit
3144
3151
3145 #Check Heights
3152 #Check Heights
3146 indHeight = numpy.logical_and(arrayMeteors[:,0] >= minHeightIndex, arrayMeteors[:,0] <= maxHeightIndex)
3153 indHeight = numpy.logical_and(arrayMeteors[:,0] >= minHeightIndex, arrayMeteors[:,0] <= maxHeightIndex)
3147 indTime = numpy.logical_and(arrayMeteors[:,3] >= minTimeIndex, arrayMeteors[:,1] <= maxTimeIndex)
3154 indTime = numpy.logical_and(arrayMeteors[:,3] >= minTimeIndex, arrayMeteors[:,1] <= maxTimeIndex)
3148 indBoth = numpy.where(numpy.logical_and(indTime,indHeight))
3155 indBoth = numpy.where(numpy.logical_and(indTime,indHeight))
3149
3156
3150 arrayMeteors = numpy.delete(arrayMeteors, indBoth, axis = 0)
3157 arrayMeteors = numpy.delete(arrayMeteors, indBoth, axis = 0)
3151
3158
3152 return listMeteors1
3159 return listMeteors1
3153
3160
3154 def __meteorReestimation(self, listMeteors, volts, pairslist, thresh, noise, timeInterval,frequency):
3161 def __meteorReestimation(self, listMeteors, volts, pairslist, thresh, noise, timeInterval,frequency):
3155 numHeights = volts.shape[2]
3162 numHeights = volts.shape[2]
3156 nChannel = volts.shape[0]
3163 nChannel = volts.shape[0]
3157
3164
3158 thresholdPhase = thresh[0]
3165 thresholdPhase = thresh[0]
3159 thresholdNoise = thresh[1]
3166 thresholdNoise = thresh[1]
3160 thresholdDB = float(thresh[2])
3167 thresholdDB = float(thresh[2])
3161
3168
3162 thresholdDB1 = 10**(thresholdDB/10)
3169 thresholdDB1 = 10**(thresholdDB/10)
3163 pairsarray = numpy.array(pairslist)
3170 pairsarray = numpy.array(pairslist)
3164 indSides = pairsarray[:,1]
3171 indSides = pairsarray[:,1]
3165
3172
3166 pairslist1 = list(pairslist)
3173 pairslist1 = list(pairslist)
3167 pairslist1.append((0,1))
3174 pairslist1.append((0,1))
3168 pairslist1.append((3,4))
3175 pairslist1.append((3,4))
3169
3176
3170 listMeteors1 = []
3177 listMeteors1 = []
3171 listPowerSeries = []
3178 listPowerSeries = []
3172 listVoltageSeries = []
3179 listVoltageSeries = []
3173 #volts has the war data
3180 #volts has the war data
3174
3181
3175 if frequency == 30e6:
3182 if frequency == 30e6:
3176 timeLag = 45*10**-3
3183 timeLag = 45*10**-3
3177 else:
3184 else:
3178 timeLag = 15*10**-3
3185 timeLag = 15*10**-3
3179 lag = numpy.ceil(timeLag/timeInterval)
3186 lag = numpy.ceil(timeLag/timeInterval)
3180
3187
3181 for i in range(len(listMeteors)):
3188 for i in range(len(listMeteors)):
3182
3189
3183 ###################### 3.6 - 3.7 PARAMETERS REESTIMATION #########################
3190 ###################### 3.6 - 3.7 PARAMETERS REESTIMATION #########################
3184 meteorAux = numpy.zeros(16)
3191 meteorAux = numpy.zeros(16)
3185
3192
3186 #Loading meteor Data (mHeight, mStart, mPeak, mEnd)
3193 #Loading meteor Data (mHeight, mStart, mPeak, mEnd)
3187 mHeight = listMeteors[i][0]
3194 mHeight = listMeteors[i][0]
3188 mStart = listMeteors[i][1]
3195 mStart = listMeteors[i][1]
3189 mPeak = listMeteors[i][2]
3196 mPeak = listMeteors[i][2]
3190 mEnd = listMeteors[i][3]
3197 mEnd = listMeteors[i][3]
3191
3198
3192 #get the volt data between the start and end times of the meteor
3199 #get the volt data between the start and end times of the meteor
3193 meteorVolts = volts[:,mStart:mEnd+1,mHeight]
3200 meteorVolts = volts[:,mStart:mEnd+1,mHeight]
3194 meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1)
3201 meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1)
3195
3202
3196 #3.6. Phase Difference estimation
3203 #3.6. Phase Difference estimation
3197 phaseDiff, aux = self.__estimatePhaseDifference(meteorVolts, pairslist)
3204 phaseDiff, aux = self.__estimatePhaseDifference(meteorVolts, pairslist)
3198
3205
3199 #3.7. Phase difference removal & meteor start, peak and end times reestimated
3206 #3.7. Phase difference removal & meteor start, peak and end times reestimated
3200 #meteorVolts0.- all Channels, all Profiles
3207 #meteorVolts0.- all Channels, all Profiles
3201 meteorVolts0 = volts[:,:,mHeight]
3208 meteorVolts0 = volts[:,:,mHeight]
3202 meteorThresh = noise[:,mHeight]*thresholdNoise
3209 meteorThresh = noise[:,mHeight]*thresholdNoise
3203 meteorNoise = noise[:,mHeight]
3210 meteorNoise = noise[:,mHeight]
3204 meteorVolts0[indSides,:] = self.__shiftPhase(meteorVolts0[indSides,:], phaseDiff) #Phase Shifting
3211 meteorVolts0[indSides,:] = self.__shiftPhase(meteorVolts0[indSides,:], phaseDiff) #Phase Shifting
3205 powerNet0 = numpy.nansum(numpy.abs(meteorVolts0)**2, axis = 0) #Power
3212 powerNet0 = numpy.nansum(numpy.abs(meteorVolts0)**2, axis = 0) #Power
3206
3213
3207 #Times reestimation
3214 #Times reestimation
3208 mStart1 = numpy.where(powerNet0[:mPeak] < meteorThresh[:mPeak])[0]
3215 mStart1 = numpy.where(powerNet0[:mPeak] < meteorThresh[:mPeak])[0]
3209 if mStart1.size > 0:
3216 if mStart1.size > 0:
3210 mStart1 = mStart1[-1] + 1
3217 mStart1 = mStart1[-1] + 1
3211
3218
3212 else:
3219 else:
3213 mStart1 = mPeak
3220 mStart1 = mPeak
3214
3221
3215 mEnd1 = numpy.where(powerNet0[mPeak:] < meteorThresh[mPeak:])[0][0] + mPeak - 1
3222 mEnd1 = numpy.where(powerNet0[mPeak:] < meteorThresh[mPeak:])[0][0] + mPeak - 1
3216 mEndDecayTime1 = numpy.where(powerNet0[mPeak:] < meteorNoise[mPeak:])[0]
3223 mEndDecayTime1 = numpy.where(powerNet0[mPeak:] < meteorNoise[mPeak:])[0]
3217 if mEndDecayTime1.size == 0:
3224 if mEndDecayTime1.size == 0:
3218 mEndDecayTime1 = powerNet0.size
3225 mEndDecayTime1 = powerNet0.size
3219 else:
3226 else:
3220 mEndDecayTime1 = mEndDecayTime1[0] + mPeak - 1
3227 mEndDecayTime1 = mEndDecayTime1[0] + mPeak - 1
3221 # mPeak1 = meteorVolts0[mStart1:mEnd1 + 1].argmax()
3228 # mPeak1 = meteorVolts0[mStart1:mEnd1 + 1].argmax()
3222
3229
3223 #meteorVolts1.- all Channels, from start to end
3230 #meteorVolts1.- all Channels, from start to end
3224 meteorVolts1 = meteorVolts0[:,mStart1:mEnd1 + 1]
3231 meteorVolts1 = meteorVolts0[:,mStart1:mEnd1 + 1]
3225 meteorVolts2 = meteorVolts0[:,mPeak + lag:mEnd1 + 1]
3232 meteorVolts2 = meteorVolts0[:,mPeak + lag:mEnd1 + 1]
3226 if meteorVolts2.shape[1] == 0:
3233 if meteorVolts2.shape[1] == 0:
3227 meteorVolts2 = meteorVolts0[:,mPeak:mEnd1 + 1]
3234 meteorVolts2 = meteorVolts0[:,mPeak:mEnd1 + 1]
3228 meteorVolts1 = meteorVolts1.reshape(meteorVolts1.shape[0], meteorVolts1.shape[1], 1)
3235 meteorVolts1 = meteorVolts1.reshape(meteorVolts1.shape[0], meteorVolts1.shape[1], 1)
3229 meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1], 1)
3236 meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1], 1)
3230 ##################### END PARAMETERS REESTIMATION #########################
3237 ##################### END PARAMETERS REESTIMATION #########################
3231
3238
3232 ##################### 3.8 PHASE DIFFERENCE REESTIMATION ########################
3239 ##################### 3.8 PHASE DIFFERENCE REESTIMATION ########################
3233 # if mEnd1 - mStart1 > 4: #Error Number 6: echo less than 5 samples long; too short for analysis
3240 # if mEnd1 - mStart1 > 4: #Error Number 6: echo less than 5 samples long; too short for analysis
3234 if meteorVolts2.shape[1] > 0:
3241 if meteorVolts2.shape[1] > 0:
3235 #Phase Difference re-estimation
3242 #Phase Difference re-estimation
3236 phaseDiff1, phaseDiffint = self.__estimatePhaseDifference(meteorVolts2, pairslist1) #Phase Difference Estimation
3243 phaseDiff1, phaseDiffint = self.__estimatePhaseDifference(meteorVolts2, pairslist1) #Phase Difference Estimation
3237 # phaseDiff1, phaseDiffint = self.estimatePhaseDifference(meteorVolts2, pairslist)
3244 # phaseDiff1, phaseDiffint = self.estimatePhaseDifference(meteorVolts2, pairslist)
3238 meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1])
3245 meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1])
3239 phaseDiff11 = numpy.reshape(phaseDiff1, (phaseDiff1.shape[0],1))
3246 phaseDiff11 = numpy.reshape(phaseDiff1, (phaseDiff1.shape[0],1))
3240 meteorVolts2[indSides,:] = self.__shiftPhase(meteorVolts2[indSides,:], phaseDiff11[0:4]) #Phase Shifting
3247 meteorVolts2[indSides,:] = self.__shiftPhase(meteorVolts2[indSides,:], phaseDiff11[0:4]) #Phase Shifting
3241
3248
3242 #Phase Difference RMS
3249 #Phase Difference RMS
3243 phaseRMS1 = numpy.sqrt(numpy.mean(numpy.square(phaseDiff1)))
3250 phaseRMS1 = numpy.sqrt(numpy.mean(numpy.square(phaseDiff1)))
3244 powerNet1 = numpy.nansum(numpy.abs(meteorVolts1[:,:])**2,0)
3251 powerNet1 = numpy.nansum(numpy.abs(meteorVolts1[:,:])**2,0)
3245 #Data from Meteor
3252 #Data from Meteor
3246 mPeak1 = powerNet1.argmax() + mStart1
3253 mPeak1 = powerNet1.argmax() + mStart1
3247 mPeakPower1 = powerNet1.max()
3254 mPeakPower1 = powerNet1.max()
3248 noiseAux = sum(noise[mStart1:mEnd1 + 1,mHeight])
3255 noiseAux = sum(noise[mStart1:mEnd1 + 1,mHeight])
3249 mSNR1 = (sum(powerNet1)-noiseAux)/noiseAux
3256 mSNR1 = (sum(powerNet1)-noiseAux)/noiseAux
3250 Meteor1 = numpy.array([mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1])
3257 Meteor1 = numpy.array([mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1])
3251 Meteor1 = numpy.hstack((Meteor1,phaseDiffint))
3258 Meteor1 = numpy.hstack((Meteor1,phaseDiffint))
3252 PowerSeries = powerNet0[mStart1:mEndDecayTime1 + 1]
3259 PowerSeries = powerNet0[mStart1:mEndDecayTime1 + 1]
3253 #Vectorize
3260 #Vectorize
3254 meteorAux[0:7] = [mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1]
3261 meteorAux[0:7] = [mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1]
3255 meteorAux[7:11] = phaseDiffint[0:4]
3262 meteorAux[7:11] = phaseDiffint[0:4]
3256
3263
3257 #Rejection Criterions
3264 #Rejection Criterions
3258 if phaseRMS1 > thresholdPhase: #Error Number 17: Phase variation
3265 if phaseRMS1 > thresholdPhase: #Error Number 17: Phase variation
3259 meteorAux[-1] = 17
3266 meteorAux[-1] = 17
3260 elif mSNR1 < thresholdDB1: #Error Number 1: SNR < threshold dB
3267 elif mSNR1 < thresholdDB1: #Error Number 1: SNR < threshold dB
3261 meteorAux[-1] = 1
3268 meteorAux[-1] = 1
3262
3269
3263
3270
3264 else:
3271 else:
3265 meteorAux[0:4] = [mHeight, mStart, mPeak, mEnd]
3272 meteorAux[0:4] = [mHeight, mStart, mPeak, mEnd]
3266 meteorAux[-1] = 6 #Error Number 6: echo less than 5 samples long; too short for analysis
3273 meteorAux[-1] = 6 #Error Number 6: echo less than 5 samples long; too short for analysis
3267 PowerSeries = 0
3274 PowerSeries = 0
3268
3275
3269 listMeteors1.append(meteorAux)
3276 listMeteors1.append(meteorAux)
3270 listPowerSeries.append(PowerSeries)
3277 listPowerSeries.append(PowerSeries)
3271 listVoltageSeries.append(meteorVolts1)
3278 listVoltageSeries.append(meteorVolts1)
3272
3279
3273 return listMeteors1, listPowerSeries, listVoltageSeries
3280 return listMeteors1, listPowerSeries, listVoltageSeries
3274
3281
3275 def __estimateDecayTime(self, listMeteors, listPower, timeInterval, frequency):
3282 def __estimateDecayTime(self, listMeteors, listPower, timeInterval, frequency):
3276
3283
3277 threshError = 10
3284 threshError = 10
3278 #Depending if it is 30 or 50 MHz
3285 #Depending if it is 30 or 50 MHz
3279 if frequency == 30e6:
3286 if frequency == 30e6:
3280 timeLag = 45*10**-3
3287 timeLag = 45*10**-3
3281 else:
3288 else:
3282 timeLag = 15*10**-3
3289 timeLag = 15*10**-3
3283 lag = numpy.ceil(timeLag/timeInterval)
3290 lag = numpy.ceil(timeLag/timeInterval)
3284
3291
3285 listMeteors1 = []
3292 listMeteors1 = []
3286
3293
3287 for i in range(len(listMeteors)):
3294 for i in range(len(listMeteors)):
3288 meteorPower = listPower[i]
3295 meteorPower = listPower[i]
3289 meteorAux = listMeteors[i]
3296 meteorAux = listMeteors[i]
3290
3297
3291 if meteorAux[-1] == 0:
3298 if meteorAux[-1] == 0:
3292
3299
3293 try:
3300 try:
3294 indmax = meteorPower.argmax()
3301 indmax = meteorPower.argmax()
3295 indlag = indmax + lag
3302 indlag = indmax + lag
3296
3303
3297 y = meteorPower[indlag:]
3304 y = meteorPower[indlag:]
3298 x = numpy.arange(0, y.size)*timeLag
3305 x = numpy.arange(0, y.size)*timeLag
3299
3306
3300 #first guess
3307 #first guess
3301 a = y[0]
3308 a = y[0]
3302 tau = timeLag
3309 tau = timeLag
3303 #exponential fit
3310 #exponential fit
3304 popt, pcov = optimize.curve_fit(self.__exponential_function, x, y, p0 = [a, tau])
3311 popt, pcov = optimize.curve_fit(self.__exponential_function, x, y, p0 = [a, tau])
3305 y1 = self.__exponential_function(x, *popt)
3312 y1 = self.__exponential_function(x, *popt)
3306 #error estimation
3313 #error estimation
3307 error = sum((y - y1)**2)/(numpy.var(y)*(y.size - popt.size))
3314 error = sum((y - y1)**2)/(numpy.var(y)*(y.size - popt.size))
3308
3315
3309 decayTime = popt[1]
3316 decayTime = popt[1]
3310 riseTime = indmax*timeInterval
3317 riseTime = indmax*timeInterval
3311 meteorAux[11:13] = [decayTime, error]
3318 meteorAux[11:13] = [decayTime, error]
3312
3319
3313 #Table items 7, 8 and 11
3320 #Table items 7, 8 and 11
3314 if (riseTime > 0.3): #Number 7: Echo rise exceeds 0.3s
3321 if (riseTime > 0.3): #Number 7: Echo rise exceeds 0.3s
3315 meteorAux[-1] = 7
3322 meteorAux[-1] = 7
3316 elif (decayTime < 2*riseTime) : #Number 8: Echo decay time less than than twice rise time
3323 elif (decayTime < 2*riseTime) : #Number 8: Echo decay time less than than twice rise time
3317 meteorAux[-1] = 8
3324 meteorAux[-1] = 8
3318 if (error > threshError): #Number 11: Poor fit to amplitude for estimation of decay time
3325 if (error > threshError): #Number 11: Poor fit to amplitude for estimation of decay time
3319 meteorAux[-1] = 11
3326 meteorAux[-1] = 11
3320
3327
3321
3328
3322 except:
3329 except:
3323 meteorAux[-1] = 11
3330 meteorAux[-1] = 11
3324
3331
3325
3332
3326 listMeteors1.append(meteorAux)
3333 listMeteors1.append(meteorAux)
3327
3334
3328 return listMeteors1
3335 return listMeteors1
3329
3336
3330 #Exponential Function
3337 #Exponential Function
3331
3338
3332 def __exponential_function(self, x, a, tau):
3339 def __exponential_function(self, x, a, tau):
3333 y = a*numpy.exp(-x/tau)
3340 y = a*numpy.exp(-x/tau)
3334 return y
3341 return y
3335
3342
3336 def __getRadialVelocity(self, listMeteors, listVolts, radialStdThresh, pairslist, timeInterval):
3343 def __getRadialVelocity(self, listMeteors, listVolts, radialStdThresh, pairslist, timeInterval):
3337
3344
3338 pairslist1 = list(pairslist)
3345 pairslist1 = list(pairslist)
3339 pairslist1.append((0,1))
3346 pairslist1.append((0,1))
3340 pairslist1.append((3,4))
3347 pairslist1.append((3,4))
3341 numPairs = len(pairslist1)
3348 numPairs = len(pairslist1)
3342 #Time Lag
3349 #Time Lag
3343 timeLag = 45*10**-3
3350 timeLag = 45*10**-3
3344 c = 3e8
3351 c = 3e8
3345 lag = numpy.ceil(timeLag/timeInterval)
3352 lag = numpy.ceil(timeLag/timeInterval)
3346 freq = 30e6
3353 freq = 30e6
3347
3354
3348 listMeteors1 = []
3355 listMeteors1 = []
3349
3356
3350 for i in range(len(listMeteors)):
3357 for i in range(len(listMeteors)):
3351 meteorAux = listMeteors[i]
3358 meteorAux = listMeteors[i]
3352 if meteorAux[-1] == 0:
3359 if meteorAux[-1] == 0:
3353 mStart = listMeteors[i][1]
3360 mStart = listMeteors[i][1]
3354 mPeak = listMeteors[i][2]
3361 mPeak = listMeteors[i][2]
3355 mLag = mPeak - mStart + lag
3362 mLag = mPeak - mStart + lag
3356
3363
3357 #get the volt data between the start and end times of the meteor
3364 #get the volt data between the start and end times of the meteor
3358 meteorVolts = listVolts[i]
3365 meteorVolts = listVolts[i]
3359 meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1)
3366 meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1)
3360
3367
3361 #Get CCF
3368 #Get CCF
3362 allCCFs = self.__calculateCCF(meteorVolts, pairslist1, [-2,-1,0,1,2])
3369 allCCFs = self.__calculateCCF(meteorVolts, pairslist1, [-2,-1,0,1,2])
3363
3370
3364 #Method 2
3371 #Method 2
3365 slopes = numpy.zeros(numPairs)
3372 slopes = numpy.zeros(numPairs)
3366 time = numpy.array([-2,-1,1,2])*timeInterval
3373 time = numpy.array([-2,-1,1,2])*timeInterval
3367 angAllCCF = numpy.angle(allCCFs[:,[0,1,3,4],0])
3374 angAllCCF = numpy.angle(allCCFs[:,[0,1,3,4],0])
3368
3375
3369 #Correct phases
3376 #Correct phases
3370 derPhaseCCF = angAllCCF[:,1:] - angAllCCF[:,0:-1]
3377 derPhaseCCF = angAllCCF[:,1:] - angAllCCF[:,0:-1]
3371 indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi)
3378 indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi)
3372
3379
3373 if indDer[0].shape[0] > 0:
3380 if indDer[0].shape[0] > 0:
3374 for i in range(indDer[0].shape[0]):
3381 for i in range(indDer[0].shape[0]):
3375 signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i]])
3382 signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i]])
3376 angAllCCF[indDer[0][i],indDer[1][i]+1:] += signo*2*numpy.pi
3383 angAllCCF[indDer[0][i],indDer[1][i]+1:] += signo*2*numpy.pi
3377
3384
3378 # fit = scipy.stats.linregress(numpy.array([-2,-1,1,2])*timeInterval, numpy.array([phaseLagN2s[i],phaseLagN1s[i],phaseLag1s[i],phaseLag2s[i]]))
3385 # fit = scipy.stats.linregress(numpy.array([-2,-1,1,2])*timeInterval, numpy.array([phaseLagN2s[i],phaseLagN1s[i],phaseLag1s[i],phaseLag2s[i]]))
3379 for j in range(numPairs):
3386 for j in range(numPairs):
3380 fit = stats.linregress(time, angAllCCF[j,:])
3387 fit = stats.linregress(time, angAllCCF[j,:])
3381 slopes[j] = fit[0]
3388 slopes[j] = fit[0]
3382
3389
3383 #Remove Outlier
3390 #Remove Outlier
3384 # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes)))
3391 # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes)))
3385 # slopes = numpy.delete(slopes,indOut)
3392 # slopes = numpy.delete(slopes,indOut)
3386 # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes)))
3393 # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes)))
3387 # slopes = numpy.delete(slopes,indOut)
3394 # slopes = numpy.delete(slopes,indOut)
3388
3395
3389 radialVelocity = -numpy.mean(slopes)*(0.25/numpy.pi)*(c/freq)
3396 radialVelocity = -numpy.mean(slopes)*(0.25/numpy.pi)*(c/freq)
3390 radialError = numpy.std(slopes)*(0.25/numpy.pi)*(c/freq)
3397 radialError = numpy.std(slopes)*(0.25/numpy.pi)*(c/freq)
3391 meteorAux[-2] = radialError
3398 meteorAux[-2] = radialError
3392 meteorAux[-3] = radialVelocity
3399 meteorAux[-3] = radialVelocity
3393
3400
3394 #Setting Error
3401 #Setting Error
3395 #Number 15: Radial Drift velocity or projected horizontal velocity exceeds 200 m/s
3402 #Number 15: Radial Drift velocity or projected horizontal velocity exceeds 200 m/s
3396 if numpy.abs(radialVelocity) > 200:
3403 if numpy.abs(radialVelocity) > 200:
3397 meteorAux[-1] = 15
3404 meteorAux[-1] = 15
3398 #Number 12: Poor fit to CCF variation for estimation of radial drift velocity
3405 #Number 12: Poor fit to CCF variation for estimation of radial drift velocity
3399 elif radialError > radialStdThresh:
3406 elif radialError > radialStdThresh:
3400 meteorAux[-1] = 12
3407 meteorAux[-1] = 12
3401
3408
3402 listMeteors1.append(meteorAux)
3409 listMeteors1.append(meteorAux)
3403 return listMeteors1
3410 return listMeteors1
3404
3411
3405 def __setNewArrays(self, listMeteors, date, heiRang):
3412 def __setNewArrays(self, listMeteors, date, heiRang):
3406
3413
3407 #New arrays
3414 #New arrays
3408 arrayMeteors = numpy.array(listMeteors)
3415 arrayMeteors = numpy.array(listMeteors)
3409 arrayParameters = numpy.zeros((len(listMeteors), 13))
3416 arrayParameters = numpy.zeros((len(listMeteors), 13))
3410
3417
3411 #Date inclusion
3418 #Date inclusion
3412 # date = re.findall(r'\((.*?)\)', date)
3419 # date = re.findall(r'\((.*?)\)', date)
3413 # date = date[0].split(',')
3420 # date = date[0].split(',')
3414 # date = map(int, date)
3421 # date = map(int, date)
3415 #
3422 #
3416 # if len(date)<6:
3423 # if len(date)<6:
3417 # date.append(0)
3424 # date.append(0)
3418 #
3425 #
3419 # date = [date[0]*10000 + date[1]*100 + date[2], date[3]*10000 + date[4]*100 + date[5]]
3426 # date = [date[0]*10000 + date[1]*100 + date[2], date[3]*10000 + date[4]*100 + date[5]]
3420 # arrayDate = numpy.tile(date, (len(listMeteors), 1))
3427 # arrayDate = numpy.tile(date, (len(listMeteors), 1))
3421 arrayDate = numpy.tile(date, (len(listMeteors)))
3428 arrayDate = numpy.tile(date, (len(listMeteors)))
3422
3429
3423 #Meteor array
3430 #Meteor array
3424 # arrayMeteors[:,0] = heiRang[arrayMeteors[:,0].astype(int)]
3431 # arrayMeteors[:,0] = heiRang[arrayMeteors[:,0].astype(int)]
3425 # arrayMeteors = numpy.hstack((arrayDate, arrayMeteors))
3432 # arrayMeteors = numpy.hstack((arrayDate, arrayMeteors))
3426
3433
3427 #Parameters Array
3434 #Parameters Array
3428 arrayParameters[:,0] = arrayDate #Date
3435 arrayParameters[:,0] = arrayDate #Date
3429 arrayParameters[:,1] = heiRang[arrayMeteors[:,0].astype(int)] #Range
3436 arrayParameters[:,1] = heiRang[arrayMeteors[:,0].astype(int)] #Range
3430 arrayParameters[:,6:8] = arrayMeteors[:,-3:-1] #Radial velocity and its error
3437 arrayParameters[:,6:8] = arrayMeteors[:,-3:-1] #Radial velocity and its error
3431 arrayParameters[:,8:12] = arrayMeteors[:,7:11] #Phases
3438 arrayParameters[:,8:12] = arrayMeteors[:,7:11] #Phases
3432 arrayParameters[:,-1] = arrayMeteors[:,-1] #Error
3439 arrayParameters[:,-1] = arrayMeteors[:,-1] #Error
3433
3440
3434
3441
3435 return arrayParameters
3442 return arrayParameters
3436
3443
3437 class CorrectSMPhases(Operation):
3444 class CorrectSMPhases(Operation):
3438
3445
3439 def run(self, dataOut, phaseOffsets, hmin = 50, hmax = 150, azimuth = 45, channelPositions = None):
3446 def run(self, dataOut, phaseOffsets, hmin = 50, hmax = 150, azimuth = 45, channelPositions = None):
3440
3447
3441 arrayParameters = dataOut.data_param
3448 arrayParameters = dataOut.data_param
3442 pairsList = []
3449 pairsList = []
3443 pairx = (0,1)
3450 pairx = (0,1)
3444 pairy = (2,3)
3451 pairy = (2,3)
3445 pairsList.append(pairx)
3452 pairsList.append(pairx)
3446 pairsList.append(pairy)
3453 pairsList.append(pairy)
3447 jph = numpy.zeros(4)
3454 jph = numpy.zeros(4)
3448
3455
3449 phaseOffsets = numpy.array(phaseOffsets)*numpy.pi/180
3456 phaseOffsets = numpy.array(phaseOffsets)*numpy.pi/180
3450 # arrayParameters[:,8:12] = numpy.unwrap(arrayParameters[:,8:12] + phaseOffsets)
3457 # arrayParameters[:,8:12] = numpy.unwrap(arrayParameters[:,8:12] + phaseOffsets)
3451 arrayParameters[:,8:12] = numpy.angle(numpy.exp(1j*(arrayParameters[:,8:12] + phaseOffsets)))
3458 arrayParameters[:,8:12] = numpy.angle(numpy.exp(1j*(arrayParameters[:,8:12] + phaseOffsets)))
3452
3459
3453 meteorOps = SMOperations()
3460 meteorOps = SMOperations()
3454 if channelPositions == None:
3461 if channelPositions == None:
3455 # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T
3462 # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T
3456 channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella
3463 channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella
3457
3464
3458 pairslist0, distances = meteorOps.getPhasePairs(channelPositions)
3465 pairslist0, distances = meteorOps.getPhasePairs(channelPositions)
3459 h = (hmin,hmax)
3466 h = (hmin,hmax)
3460
3467
3461 arrayParameters = meteorOps.getMeteorParams(arrayParameters, azimuth, h, pairsList, distances, jph)
3468 arrayParameters = meteorOps.getMeteorParams(arrayParameters, azimuth, h, pairsList, distances, jph)
3462
3469
3463 dataOut.data_param = arrayParameters
3470 dataOut.data_param = arrayParameters
3464 return
3471 return
3465
3472
3466 class SMPhaseCalibration(Operation):
3473 class SMPhaseCalibration(Operation):
3467
3474
3468 __buffer = None
3475 __buffer = None
3469
3476
3470 __initime = None
3477 __initime = None
3471
3478
3472 __dataReady = False
3479 __dataReady = False
3473
3480
3474 __isConfig = False
3481 __isConfig = False
3475
3482
3476 def __checkTime(self, currentTime, initTime, paramInterval, outputInterval):
3483 def __checkTime(self, currentTime, initTime, paramInterval, outputInterval):
3477
3484
3478 dataTime = currentTime + paramInterval
3485 dataTime = currentTime + paramInterval
3479 deltaTime = dataTime - initTime
3486 deltaTime = dataTime - initTime
3480
3487
3481 if deltaTime >= outputInterval or deltaTime < 0:
3488 if deltaTime >= outputInterval or deltaTime < 0:
3482 return True
3489 return True
3483
3490
3484 return False
3491 return False
3485
3492
3486 def __getGammas(self, pairs, d, phases):
3493 def __getGammas(self, pairs, d, phases):
3487 gammas = numpy.zeros(2)
3494 gammas = numpy.zeros(2)
3488
3495
3489 for i in range(len(pairs)):
3496 for i in range(len(pairs)):
3490
3497
3491 pairi = pairs[i]
3498 pairi = pairs[i]
3492
3499
3493 phip3 = phases[:,pairi[1]]
3500 phip3 = phases[:,pairi[1]]
3494 d3 = d[pairi[1]]
3501 d3 = d[pairi[1]]
3495 phip2 = phases[:,pairi[0]]
3502 phip2 = phases[:,pairi[0]]
3496 d2 = d[pairi[0]]
3503 d2 = d[pairi[0]]
3497 #Calculating gamma
3504 #Calculating gamma
3498 # jdcos = alp1/(k*d1)
3505 # jdcos = alp1/(k*d1)
3499 # jgamma = numpy.angle(numpy.exp(1j*(d0*alp1/d1 - alp0)))
3506 # jgamma = numpy.angle(numpy.exp(1j*(d0*alp1/d1 - alp0)))
3500 jgamma = -phip2*d3/d2 - phip3
3507 jgamma = -phip2*d3/d2 - phip3
3501 jgamma = numpy.angle(numpy.exp(1j*jgamma))
3508 jgamma = numpy.angle(numpy.exp(1j*jgamma))
3502 # jgamma[jgamma>numpy.pi] -= 2*numpy.pi
3509 # jgamma[jgamma>numpy.pi] -= 2*numpy.pi
3503 # jgamma[jgamma<-numpy.pi] += 2*numpy.pi
3510 # jgamma[jgamma<-numpy.pi] += 2*numpy.pi
3504
3511
3505 #Revised distribution
3512 #Revised distribution
3506 jgammaArray = numpy.hstack((jgamma,jgamma+0.5*numpy.pi,jgamma-0.5*numpy.pi))
3513 jgammaArray = numpy.hstack((jgamma,jgamma+0.5*numpy.pi,jgamma-0.5*numpy.pi))
3507
3514
3508 #Histogram
3515 #Histogram
3509 nBins = 64.0
3516 nBins = 64.0
3510 rmin = -0.5*numpy.pi
3517 rmin = -0.5*numpy.pi
3511 rmax = 0.5*numpy.pi
3518 rmax = 0.5*numpy.pi
3512 phaseHisto = numpy.histogram(jgammaArray, bins=nBins, range=(rmin,rmax))
3519 phaseHisto = numpy.histogram(jgammaArray, bins=nBins, range=(rmin,rmax))
3513
3520
3514 meteorsY = phaseHisto[0]
3521 meteorsY = phaseHisto[0]
3515 phasesX = phaseHisto[1][:-1]
3522 phasesX = phaseHisto[1][:-1]
3516 width = phasesX[1] - phasesX[0]
3523 width = phasesX[1] - phasesX[0]
3517 phasesX += width/2
3524 phasesX += width/2
3518
3525
3519 #Gaussian aproximation
3526 #Gaussian aproximation
3520 bpeak = meteorsY.argmax()
3527 bpeak = meteorsY.argmax()
3521 peak = meteorsY.max()
3528 peak = meteorsY.max()
3522 jmin = bpeak - 5
3529 jmin = bpeak - 5
3523 jmax = bpeak + 5 + 1
3530 jmax = bpeak + 5 + 1
3524
3531
3525 if jmin<0:
3532 if jmin<0:
3526 jmin = 0
3533 jmin = 0
3527 jmax = 6
3534 jmax = 6
3528 elif jmax > meteorsY.size:
3535 elif jmax > meteorsY.size:
3529 jmin = meteorsY.size - 6
3536 jmin = meteorsY.size - 6
3530 jmax = meteorsY.size
3537 jmax = meteorsY.size
3531
3538
3532 x0 = numpy.array([peak,bpeak,50])
3539 x0 = numpy.array([peak,bpeak,50])
3533 coeff = optimize.leastsq(self.__residualFunction, x0, args=(meteorsY[jmin:jmax], phasesX[jmin:jmax]))
3540 coeff = optimize.leastsq(self.__residualFunction, x0, args=(meteorsY[jmin:jmax], phasesX[jmin:jmax]))
3534
3541
3535 #Gammas
3542 #Gammas
3536 gammas[i] = coeff[0][1]
3543 gammas[i] = coeff[0][1]
3537
3544
3538 return gammas
3545 return gammas
3539
3546
3540 def __residualFunction(self, coeffs, y, t):
3547 def __residualFunction(self, coeffs, y, t):
3541
3548
3542 return y - self.__gauss_function(t, coeffs)
3549 return y - self.__gauss_function(t, coeffs)
3543
3550
3544 def __gauss_function(self, t, coeffs):
3551 def __gauss_function(self, t, coeffs):
3545
3552
3546 return coeffs[0]*numpy.exp(-0.5*((t - coeffs[1]) / coeffs[2])**2)
3553 return coeffs[0]*numpy.exp(-0.5*((t - coeffs[1]) / coeffs[2])**2)
3547
3554
3548 def __getPhases(self, azimuth, h, pairsList, d, gammas, meteorsArray):
3555 def __getPhases(self, azimuth, h, pairsList, d, gammas, meteorsArray):
3549 meteorOps = SMOperations()
3556 meteorOps = SMOperations()
3550 nchan = 4
3557 nchan = 4
3551 pairx = pairsList[0]
3558 pairx = pairsList[0]
3552 pairy = pairsList[1]
3559 pairy = pairsList[1]
3553 center_xangle = 0
3560 center_xangle = 0
3554 center_yangle = 0
3561 center_yangle = 0
3555 range_angle = numpy.array([10*numpy.pi,numpy.pi,numpy.pi/2,numpy.pi/4])
3562 range_angle = numpy.array([10*numpy.pi,numpy.pi,numpy.pi/2,numpy.pi/4])
3556 ntimes = len(range_angle)
3563 ntimes = len(range_angle)
3557
3564
3558 nstepsx = 20.0
3565 nstepsx = 20.0
3559 nstepsy = 20.0
3566 nstepsy = 20.0
3560
3567
3561 for iz in range(ntimes):
3568 for iz in range(ntimes):
3562 min_xangle = -range_angle[iz]/2 + center_xangle
3569 min_xangle = -range_angle[iz]/2 + center_xangle
3563 max_xangle = range_angle[iz]/2 + center_xangle
3570 max_xangle = range_angle[iz]/2 + center_xangle
3564 min_yangle = -range_angle[iz]/2 + center_yangle
3571 min_yangle = -range_angle[iz]/2 + center_yangle
3565 max_yangle = range_angle[iz]/2 + center_yangle
3572 max_yangle = range_angle[iz]/2 + center_yangle
3566
3573
3567 inc_x = (max_xangle-min_xangle)/nstepsx
3574 inc_x = (max_xangle-min_xangle)/nstepsx
3568 inc_y = (max_yangle-min_yangle)/nstepsy
3575 inc_y = (max_yangle-min_yangle)/nstepsy
3569
3576
3570 alpha_y = numpy.arange(nstepsy)*inc_y + min_yangle
3577 alpha_y = numpy.arange(nstepsy)*inc_y + min_yangle
3571 alpha_x = numpy.arange(nstepsx)*inc_x + min_xangle
3578 alpha_x = numpy.arange(nstepsx)*inc_x + min_xangle
3572 penalty = numpy.zeros((nstepsx,nstepsy))
3579 penalty = numpy.zeros((nstepsx,nstepsy))
3573 jph_array = numpy.zeros((nchan,nstepsx,nstepsy))
3580 jph_array = numpy.zeros((nchan,nstepsx,nstepsy))
3574 jph = numpy.zeros(nchan)
3581 jph = numpy.zeros(nchan)
3575
3582
3576 # Iterations looking for the offset
3583 # Iterations looking for the offset
3577 for iy in range(int(nstepsy)):
3584 for iy in range(int(nstepsy)):
3578 for ix in range(int(nstepsx)):
3585 for ix in range(int(nstepsx)):
3579 jph[pairy[1]] = alpha_y[iy]
3586 jph[pairy[1]] = alpha_y[iy]
3580 jph[pairy[0]] = -gammas[1] - alpha_y[iy]*d[pairy[1]]/d[pairy[0]]
3587 jph[pairy[0]] = -gammas[1] - alpha_y[iy]*d[pairy[1]]/d[pairy[0]]
3581
3588
3582 jph[pairx[1]] = alpha_x[ix]
3589 jph[pairx[1]] = alpha_x[ix]
3583 jph[pairx[0]] = -gammas[0] - alpha_x[ix]*d[pairx[1]]/d[pairx[0]]
3590 jph[pairx[0]] = -gammas[0] - alpha_x[ix]*d[pairx[1]]/d[pairx[0]]
3584
3591
3585 jph_array[:,ix,iy] = jph
3592 jph_array[:,ix,iy] = jph
3586
3593
3587 meteorsArray1 = meteorOps.getMeteorParams(meteorsArray, azimuth, h, pairsList, d, jph)
3594 meteorsArray1 = meteorOps.getMeteorParams(meteorsArray, azimuth, h, pairsList, d, jph)
3588 error = meteorsArray1[:,-1]
3595 error = meteorsArray1[:,-1]
3589 ind1 = numpy.where(error==0)[0]
3596 ind1 = numpy.where(error==0)[0]
3590 penalty[ix,iy] = ind1.size
3597 penalty[ix,iy] = ind1.size
3591
3598
3592 i,j = numpy.unravel_index(penalty.argmax(), penalty.shape)
3599 i,j = numpy.unravel_index(penalty.argmax(), penalty.shape)
3593 phOffset = jph_array[:,i,j]
3600 phOffset = jph_array[:,i,j]
3594
3601
3595 center_xangle = phOffset[pairx[1]]
3602 center_xangle = phOffset[pairx[1]]
3596 center_yangle = phOffset[pairy[1]]
3603 center_yangle = phOffset[pairy[1]]
3597
3604
3598 phOffset = numpy.angle(numpy.exp(1j*jph_array[:,i,j]))
3605 phOffset = numpy.angle(numpy.exp(1j*jph_array[:,i,j]))
3599 phOffset = phOffset*180/numpy.pi
3606 phOffset = phOffset*180/numpy.pi
3600 return phOffset
3607 return phOffset
3601
3608
3602
3609
3603 def run(self, dataOut, hmin, hmax, channelPositions=None, nHours = 1):
3610 def run(self, dataOut, hmin, hmax, channelPositions=None, nHours = 1):
3604
3611
3605 dataOut.flagNoData = True
3612 dataOut.flagNoData = True
3606 self.__dataReady = False
3613 self.__dataReady = False
3607 dataOut.outputInterval = nHours*3600
3614 dataOut.outputInterval = nHours*3600
3608
3615
3609 if self.__isConfig == False:
3616 if self.__isConfig == False:
3610 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
3617 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
3611 #Get Initial LTC time
3618 #Get Initial LTC time
3612 self.__initime = datetime.datetime.utcfromtimestamp(dataOut.utctime)
3619 self.__initime = datetime.datetime.utcfromtimestamp(dataOut.utctime)
3613 self.__initime = (self.__initime.replace(minute = 0, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
3620 self.__initime = (self.__initime.replace(minute = 0, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
3614
3621
3615 self.__isConfig = True
3622 self.__isConfig = True
3616
3623
3617 if self.__buffer == None:
3624 if self.__buffer == None:
3618 self.__buffer = dataOut.data_param.copy()
3625 self.__buffer = dataOut.data_param.copy()
3619
3626
3620 else:
3627 else:
3621 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
3628 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
3622
3629
3623 self.__dataReady = self.__checkTime(dataOut.utctime, self.__initime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
3630 self.__dataReady = self.__checkTime(dataOut.utctime, self.__initime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
3624
3631
3625 if self.__dataReady:
3632 if self.__dataReady:
3626 dataOut.utctimeInit = self.__initime
3633 dataOut.utctimeInit = self.__initime
3627 self.__initime += dataOut.outputInterval #to erase time offset
3634 self.__initime += dataOut.outputInterval #to erase time offset
3628
3635
3629 freq = dataOut.frequency
3636 freq = dataOut.frequency
3630 c = dataOut.C #m/s
3637 c = dataOut.C #m/s
3631 lamb = c/freq
3638 lamb = c/freq
3632 k = 2*numpy.pi/lamb
3639 k = 2*numpy.pi/lamb
3633 azimuth = 0
3640 azimuth = 0
3634 h = (hmin, hmax)
3641 h = (hmin, hmax)
3635 pairs = ((0,1),(2,3))
3642 pairs = ((0,1),(2,3))
3636
3643
3637 if channelPositions == None:
3644 if channelPositions == None:
3638 # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T
3645 # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T
3639 channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella
3646 channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella
3640 meteorOps = SMOperations()
3647 meteorOps = SMOperations()
3641 pairslist0, distances = meteorOps.getPhasePairs(channelPositions)
3648 pairslist0, distances = meteorOps.getPhasePairs(channelPositions)
3642
3649
3643 # distances1 = [-distances[0]*lamb, distances[1]*lamb, -distances[2]*lamb, distances[3]*lamb]
3650 # distances1 = [-distances[0]*lamb, distances[1]*lamb, -distances[2]*lamb, distances[3]*lamb]
3644
3651
3645 meteorsArray = self.__buffer
3652 meteorsArray = self.__buffer
3646 error = meteorsArray[:,-1]
3653 error = meteorsArray[:,-1]
3647 boolError = (error==0)|(error==3)|(error==4)|(error==13)|(error==14)
3654 boolError = (error==0)|(error==3)|(error==4)|(error==13)|(error==14)
3648 ind1 = numpy.where(boolError)[0]
3655 ind1 = numpy.where(boolError)[0]
3649 meteorsArray = meteorsArray[ind1,:]
3656 meteorsArray = meteorsArray[ind1,:]
3650 meteorsArray[:,-1] = 0
3657 meteorsArray[:,-1] = 0
3651 phases = meteorsArray[:,8:12]
3658 phases = meteorsArray[:,8:12]
3652
3659
3653 #Calculate Gammas
3660 #Calculate Gammas
3654 gammas = self.__getGammas(pairs, distances, phases)
3661 gammas = self.__getGammas(pairs, distances, phases)
3655 # gammas = numpy.array([-21.70409463,45.76935864])*numpy.pi/180
3662 # gammas = numpy.array([-21.70409463,45.76935864])*numpy.pi/180
3656 #Calculate Phases
3663 #Calculate Phases
3657 phasesOff = self.__getPhases(azimuth, h, pairs, distances, gammas, meteorsArray)
3664 phasesOff = self.__getPhases(azimuth, h, pairs, distances, gammas, meteorsArray)
3658 phasesOff = phasesOff.reshape((1,phasesOff.size))
3665 phasesOff = phasesOff.reshape((1,phasesOff.size))
3659 dataOut.data_output = -phasesOff
3666 dataOut.data_output = -phasesOff
3660 dataOut.flagNoData = False
3667 dataOut.flagNoData = False
3661 self.__buffer = None
3668 self.__buffer = None
3662
3669
3663
3670
3664 return
3671 return
3665
3672
3666 class SMOperations():
3673 class SMOperations():
3667
3674
3668 def __init__(self):
3675 def __init__(self):
3669
3676
3670 return
3677 return
3671
3678
3672 def getMeteorParams(self, arrayParameters0, azimuth, h, pairsList, distances, jph):
3679 def getMeteorParams(self, arrayParameters0, azimuth, h, pairsList, distances, jph):
3673
3680
3674 arrayParameters = arrayParameters0.copy()
3681 arrayParameters = arrayParameters0.copy()
3675 hmin = h[0]
3682 hmin = h[0]
3676 hmax = h[1]
3683 hmax = h[1]
3677
3684
3678 #Calculate AOA (Error N 3, 4)
3685 #Calculate AOA (Error N 3, 4)
3679 #JONES ET AL. 1998
3686 #JONES ET AL. 1998
3680 AOAthresh = numpy.pi/8
3687 AOAthresh = numpy.pi/8
3681 error = arrayParameters[:,-1]
3688 error = arrayParameters[:,-1]
3682 phases = -arrayParameters[:,8:12] + jph
3689 phases = -arrayParameters[:,8:12] + jph
3683 # phases = numpy.unwrap(phases)
3690 # phases = numpy.unwrap(phases)
3684 arrayParameters[:,3:6], arrayParameters[:,-1] = self.__getAOA(phases, pairsList, distances, error, AOAthresh, azimuth)
3691 arrayParameters[:,3:6], arrayParameters[:,-1] = self.__getAOA(phases, pairsList, distances, error, AOAthresh, azimuth)
3685
3692
3686 #Calculate Heights (Error N 13 and 14)
3693 #Calculate Heights (Error N 13 and 14)
3687 error = arrayParameters[:,-1]
3694 error = arrayParameters[:,-1]
3688 Ranges = arrayParameters[:,1]
3695 Ranges = arrayParameters[:,1]
3689 zenith = arrayParameters[:,4]
3696 zenith = arrayParameters[:,4]
3690 arrayParameters[:,2], arrayParameters[:,-1] = self.__getHeights(Ranges, zenith, error, hmin, hmax)
3697 arrayParameters[:,2], arrayParameters[:,-1] = self.__getHeights(Ranges, zenith, error, hmin, hmax)
3691
3698
3692 #----------------------- Get Final data ------------------------------------
3699 #----------------------- Get Final data ------------------------------------
3693 # error = arrayParameters[:,-1]
3700 # error = arrayParameters[:,-1]
3694 # ind1 = numpy.where(error==0)[0]
3701 # ind1 = numpy.where(error==0)[0]
3695 # arrayParameters = arrayParameters[ind1,:]
3702 # arrayParameters = arrayParameters[ind1,:]
3696
3703
3697 return arrayParameters
3704 return arrayParameters
3698
3705
3699 def __getAOA(self, phases, pairsList, directions, error, AOAthresh, azimuth):
3706 def __getAOA(self, phases, pairsList, directions, error, AOAthresh, azimuth):
3700
3707
3701 arrayAOA = numpy.zeros((phases.shape[0],3))
3708 arrayAOA = numpy.zeros((phases.shape[0],3))
3702 cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList,directions)
3709 cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList,directions)
3703
3710
3704 arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth)
3711 arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth)
3705 cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1)
3712 cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1)
3706 arrayAOA[:,2] = cosDirError
3713 arrayAOA[:,2] = cosDirError
3707
3714
3708 azimuthAngle = arrayAOA[:,0]
3715 azimuthAngle = arrayAOA[:,0]
3709 zenithAngle = arrayAOA[:,1]
3716 zenithAngle = arrayAOA[:,1]
3710
3717
3711 #Setting Error
3718 #Setting Error
3712 indError = numpy.where(numpy.logical_or(error == 3, error == 4))[0]
3719 indError = numpy.where(numpy.logical_or(error == 3, error == 4))[0]
3713 error[indError] = 0
3720 error[indError] = 0
3714 #Number 3: AOA not fesible
3721 #Number 3: AOA not fesible
3715 indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0]
3722 indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0]
3716 error[indInvalid] = 3
3723 error[indInvalid] = 3
3717 #Number 4: Large difference in AOAs obtained from different antenna baselines
3724 #Number 4: Large difference in AOAs obtained from different antenna baselines
3718 indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0]
3725 indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0]
3719 error[indInvalid] = 4
3726 error[indInvalid] = 4
3720 return arrayAOA, error
3727 return arrayAOA, error
3721
3728
3722 def __getDirectionCosines(self, arrayPhase, pairsList, distances):
3729 def __getDirectionCosines(self, arrayPhase, pairsList, distances):
3723
3730
3724 #Initializing some variables
3731 #Initializing some variables
3725 ang_aux = numpy.array([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])*2*numpy.pi
3732 ang_aux = numpy.array([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])*2*numpy.pi
3726 ang_aux = ang_aux.reshape(1,ang_aux.size)
3733 ang_aux = ang_aux.reshape(1,ang_aux.size)
3727
3734
3728 cosdir = numpy.zeros((arrayPhase.shape[0],2))
3735 cosdir = numpy.zeros((arrayPhase.shape[0],2))
3729 cosdir0 = numpy.zeros((arrayPhase.shape[0],2))
3736 cosdir0 = numpy.zeros((arrayPhase.shape[0],2))
3730
3737
3731
3738
3732 for i in range(2):
3739 for i in range(2):
3733 ph0 = arrayPhase[:,pairsList[i][0]]
3740 ph0 = arrayPhase[:,pairsList[i][0]]
3734 ph1 = arrayPhase[:,pairsList[i][1]]
3741 ph1 = arrayPhase[:,pairsList[i][1]]
3735 d0 = distances[pairsList[i][0]]
3742 d0 = distances[pairsList[i][0]]
3736 d1 = distances[pairsList[i][1]]
3743 d1 = distances[pairsList[i][1]]
3737
3744
3738 ph0_aux = ph0 + ph1
3745 ph0_aux = ph0 + ph1
3739 ph0_aux = numpy.angle(numpy.exp(1j*ph0_aux))
3746 ph0_aux = numpy.angle(numpy.exp(1j*ph0_aux))
3740 # ph0_aux[ph0_aux > numpy.pi] -= 2*numpy.pi
3747 # ph0_aux[ph0_aux > numpy.pi] -= 2*numpy.pi
3741 # ph0_aux[ph0_aux < -numpy.pi] += 2*numpy.pi
3748 # ph0_aux[ph0_aux < -numpy.pi] += 2*numpy.pi
3742 #First Estimation
3749 #First Estimation
3743 cosdir0[:,i] = (ph0_aux)/(2*numpy.pi*(d0 - d1))
3750 cosdir0[:,i] = (ph0_aux)/(2*numpy.pi*(d0 - d1))
3744
3751
3745 #Most-Accurate Second Estimation
3752 #Most-Accurate Second Estimation
3746 phi1_aux = ph0 - ph1
3753 phi1_aux = ph0 - ph1
3747 phi1_aux = phi1_aux.reshape(phi1_aux.size,1)
3754 phi1_aux = phi1_aux.reshape(phi1_aux.size,1)
3748 #Direction Cosine 1
3755 #Direction Cosine 1
3749 cosdir1 = (phi1_aux + ang_aux)/(2*numpy.pi*(d0 + d1))
3756 cosdir1 = (phi1_aux + ang_aux)/(2*numpy.pi*(d0 + d1))
3750
3757
3751 #Searching the correct Direction Cosine
3758 #Searching the correct Direction Cosine
3752 cosdir0_aux = cosdir0[:,i]
3759 cosdir0_aux = cosdir0[:,i]
3753 cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1)
3760 cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1)
3754 #Minimum Distance
3761 #Minimum Distance
3755 cosDiff = (cosdir1 - cosdir0_aux)**2
3762 cosDiff = (cosdir1 - cosdir0_aux)**2
3756 indcos = cosDiff.argmin(axis = 1)
3763 indcos = cosDiff.argmin(axis = 1)
3757 #Saving Value obtained
3764 #Saving Value obtained
3758 cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos]
3765 cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos]
3759
3766
3760 return cosdir0, cosdir
3767 return cosdir0, cosdir
3761
3768
3762 def __calculateAOA(self, cosdir, azimuth):
3769 def __calculateAOA(self, cosdir, azimuth):
3763 cosdirX = cosdir[:,0]
3770 cosdirX = cosdir[:,0]
3764 cosdirY = cosdir[:,1]
3771 cosdirY = cosdir[:,1]
3765
3772
3766 zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi
3773 zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi
3767 azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth#0 deg north, 90 deg east
3774 azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth#0 deg north, 90 deg east
3768 angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose()
3775 angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose()
3769
3776
3770 return angles
3777 return angles
3771
3778
3772 def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight):
3779 def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight):
3773
3780
3774 Ramb = 375 #Ramb = c/(2*PRF)
3781 Ramb = 375 #Ramb = c/(2*PRF)
3775 Re = 6371 #Earth Radius
3782 Re = 6371 #Earth Radius
3776 heights = numpy.zeros(Ranges.shape)
3783 heights = numpy.zeros(Ranges.shape)
3777
3784
3778 R_aux = numpy.array([0,1,2])*Ramb
3785 R_aux = numpy.array([0,1,2])*Ramb
3779 R_aux = R_aux.reshape(1,R_aux.size)
3786 R_aux = R_aux.reshape(1,R_aux.size)
3780
3787
3781 Ranges = Ranges.reshape(Ranges.size,1)
3788 Ranges = Ranges.reshape(Ranges.size,1)
3782
3789
3783 Ri = Ranges + R_aux
3790 Ri = Ranges + R_aux
3784 hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re
3791 hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re
3785
3792
3786 #Check if there is a height between 70 and 110 km
3793 #Check if there is a height between 70 and 110 km
3787 h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1)
3794 h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1)
3788 ind_h = numpy.where(h_bool == 1)[0]
3795 ind_h = numpy.where(h_bool == 1)[0]
3789
3796
3790 hCorr = hi[ind_h, :]
3797 hCorr = hi[ind_h, :]
3791 ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight))
3798 ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight))
3792
3799
3793 hCorr = hi[ind_hCorr]
3800 hCorr = hi[ind_hCorr]
3794 heights[ind_h] = hCorr
3801 heights[ind_h] = hCorr
3795
3802
3796 #Setting Error
3803 #Setting Error
3797 #Number 13: Height unresolvable echo: not valid height within 70 to 110 km
3804 #Number 13: Height unresolvable echo: not valid height within 70 to 110 km
3798 #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km
3805 #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km
3799 indError = numpy.where(numpy.logical_or(error == 13, error == 14))[0]
3806 indError = numpy.where(numpy.logical_or(error == 13, error == 14))[0]
3800 error[indError] = 0
3807 error[indError] = 0
3801 indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0]
3808 indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0]
3802 error[indInvalid2] = 14
3809 error[indInvalid2] = 14
3803 indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0]
3810 indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0]
3804 error[indInvalid1] = 13
3811 error[indInvalid1] = 13
3805
3812
3806 return heights, error
3813 return heights, error
3807
3814
3808 def getPhasePairs(self, channelPositions):
3815 def getPhasePairs(self, channelPositions):
3809 chanPos = numpy.array(channelPositions)
3816 chanPos = numpy.array(channelPositions)
3810 listOper = list(itertools.combinations(range(5),2))
3817 listOper = list(itertools.combinations(range(5),2))
3811
3818
3812 distances = numpy.zeros(4)
3819 distances = numpy.zeros(4)
3813 axisX = []
3820 axisX = []
3814 axisY = []
3821 axisY = []
3815 distX = numpy.zeros(3)
3822 distX = numpy.zeros(3)
3816 distY = numpy.zeros(3)
3823 distY = numpy.zeros(3)
3817 ix = 0
3824 ix = 0
3818 iy = 0
3825 iy = 0
3819
3826
3820 pairX = numpy.zeros((2,2))
3827 pairX = numpy.zeros((2,2))
3821 pairY = numpy.zeros((2,2))
3828 pairY = numpy.zeros((2,2))
3822
3829
3823 for i in range(len(listOper)):
3830 for i in range(len(listOper)):
3824 pairi = listOper[i]
3831 pairi = listOper[i]
3825
3832
3826 posDif = numpy.abs(chanPos[pairi[0],:] - chanPos[pairi[1],:])
3833 posDif = numpy.abs(chanPos[pairi[0],:] - chanPos[pairi[1],:])
3827
3834
3828 if posDif[0] == 0:
3835 if posDif[0] == 0:
3829 axisY.append(pairi)
3836 axisY.append(pairi)
3830 distY[iy] = posDif[1]
3837 distY[iy] = posDif[1]
3831 iy += 1
3838 iy += 1
3832 elif posDif[1] == 0:
3839 elif posDif[1] == 0:
3833 axisX.append(pairi)
3840 axisX.append(pairi)
3834 distX[ix] = posDif[0]
3841 distX[ix] = posDif[0]
3835 ix += 1
3842 ix += 1
3836
3843
3837 for i in range(2):
3844 for i in range(2):
3838 if i==0:
3845 if i==0:
3839 dist0 = distX
3846 dist0 = distX
3840 axis0 = axisX
3847 axis0 = axisX
3841 else:
3848 else:
3842 dist0 = distY
3849 dist0 = distY
3843 axis0 = axisY
3850 axis0 = axisY
3844
3851
3845 side = numpy.argsort(dist0)[:-1]
3852 side = numpy.argsort(dist0)[:-1]
3846 axis0 = numpy.array(axis0)[side,:]
3853 axis0 = numpy.array(axis0)[side,:]
3847 chanC = int(numpy.intersect1d(axis0[0,:], axis0[1,:])[0])
3854 chanC = int(numpy.intersect1d(axis0[0,:], axis0[1,:])[0])
3848 axis1 = numpy.unique(numpy.reshape(axis0,4))
3855 axis1 = numpy.unique(numpy.reshape(axis0,4))
3849 side = axis1[axis1 != chanC]
3856 side = axis1[axis1 != chanC]
3850 diff1 = chanPos[chanC,i] - chanPos[side[0],i]
3857 diff1 = chanPos[chanC,i] - chanPos[side[0],i]
3851 diff2 = chanPos[chanC,i] - chanPos[side[1],i]
3858 diff2 = chanPos[chanC,i] - chanPos[side[1],i]
3852 if diff1<0:
3859 if diff1<0:
3853 chan2 = side[0]
3860 chan2 = side[0]
3854 d2 = numpy.abs(diff1)
3861 d2 = numpy.abs(diff1)
3855 chan1 = side[1]
3862 chan1 = side[1]
3856 d1 = numpy.abs(diff2)
3863 d1 = numpy.abs(diff2)
3857 else:
3864 else:
3858 chan2 = side[1]
3865 chan2 = side[1]
3859 d2 = numpy.abs(diff2)
3866 d2 = numpy.abs(diff2)
3860 chan1 = side[0]
3867 chan1 = side[0]
3861 d1 = numpy.abs(diff1)
3868 d1 = numpy.abs(diff1)
3862
3869
3863 if i==0:
3870 if i==0:
3864 chanCX = chanC
3871 chanCX = chanC
3865 chan1X = chan1
3872 chan1X = chan1
3866 chan2X = chan2
3873 chan2X = chan2
3867 distances[0:2] = numpy.array([d1,d2])
3874 distances[0:2] = numpy.array([d1,d2])
3868 else:
3875 else:
3869 chanCY = chanC
3876 chanCY = chanC
3870 chan1Y = chan1
3877 chan1Y = chan1
3871 chan2Y = chan2
3878 chan2Y = chan2
3872 distances[2:4] = numpy.array([d1,d2])
3879 distances[2:4] = numpy.array([d1,d2])
3873 # axisXsides = numpy.reshape(axisX[ix,:],4)
3880 # axisXsides = numpy.reshape(axisX[ix,:],4)
3874 #
3881 #
3875 # channelCentX = int(numpy.intersect1d(pairX[0,:], pairX[1,:])[0])
3882 # channelCentX = int(numpy.intersect1d(pairX[0,:], pairX[1,:])[0])
3876 # channelCentY = int(numpy.intersect1d(pairY[0,:], pairY[1,:])[0])
3883 # channelCentY = int(numpy.intersect1d(pairY[0,:], pairY[1,:])[0])
3877 #
3884 #
3878 # ind25X = numpy.where(pairX[0,:] != channelCentX)[0][0]
3885 # ind25X = numpy.where(pairX[0,:] != channelCentX)[0][0]
3879 # ind20X = numpy.where(pairX[1,:] != channelCentX)[0][0]
3886 # ind20X = numpy.where(pairX[1,:] != channelCentX)[0][0]
3880 # channel25X = int(pairX[0,ind25X])
3887 # channel25X = int(pairX[0,ind25X])
3881 # channel20X = int(pairX[1,ind20X])
3888 # channel20X = int(pairX[1,ind20X])
3882 # ind25Y = numpy.where(pairY[0,:] != channelCentY)[0][0]
3889 # ind25Y = numpy.where(pairY[0,:] != channelCentY)[0][0]
3883 # ind20Y = numpy.where(pairY[1,:] != channelCentY)[0][0]
3890 # ind20Y = numpy.where(pairY[1,:] != channelCentY)[0][0]
3884 # channel25Y = int(pairY[0,ind25Y])
3891 # channel25Y = int(pairY[0,ind25Y])
3885 # channel20Y = int(pairY[1,ind20Y])
3892 # channel20Y = int(pairY[1,ind20Y])
3886
3893
3887 # pairslist = [(channelCentX, channel25X),(channelCentX, channel20X),(channelCentY,channel25Y),(channelCentY, channel20Y)]
3894 # pairslist = [(channelCentX, channel25X),(channelCentX, channel20X),(channelCentY,channel25Y),(channelCentY, channel20Y)]
3888 pairslist = [(chanCX, chan1X),(chanCX, chan2X),(chanCY,chan1Y),(chanCY, chan2Y)]
3895 pairslist = [(chanCX, chan1X),(chanCX, chan2X),(chanCY,chan1Y),(chanCY, chan2Y)]
3889
3896
3890 return pairslist, distances
3897 return pairslist, distances
3891 # def __getAOA(self, phases, pairsList, error, AOAthresh, azimuth):
3898 # def __getAOA(self, phases, pairsList, error, AOAthresh, azimuth):
3892 #
3899 #
3893 # arrayAOA = numpy.zeros((phases.shape[0],3))
3900 # arrayAOA = numpy.zeros((phases.shape[0],3))
3894 # cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList)
3901 # cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList)
3895 #
3902 #
3896 # arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth)
3903 # arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth)
3897 # cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1)
3904 # cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1)
3898 # arrayAOA[:,2] = cosDirError
3905 # arrayAOA[:,2] = cosDirError
3899 #
3906 #
3900 # azimuthAngle = arrayAOA[:,0]
3907 # azimuthAngle = arrayAOA[:,0]
3901 # zenithAngle = arrayAOA[:,1]
3908 # zenithAngle = arrayAOA[:,1]
3902 #
3909 #
3903 # #Setting Error
3910 # #Setting Error
3904 # #Number 3: AOA not fesible
3911 # #Number 3: AOA not fesible
3905 # indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0]
3912 # indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0]
3906 # error[indInvalid] = 3
3913 # error[indInvalid] = 3
3907 # #Number 4: Large difference in AOAs obtained from different antenna baselines
3914 # #Number 4: Large difference in AOAs obtained from different antenna baselines
3908 # indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0]
3915 # indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0]
3909 # error[indInvalid] = 4
3916 # error[indInvalid] = 4
3910 # return arrayAOA, error
3917 # return arrayAOA, error
3911 #
3918 #
3912 # def __getDirectionCosines(self, arrayPhase, pairsList):
3919 # def __getDirectionCosines(self, arrayPhase, pairsList):
3913 #
3920 #
3914 # #Initializing some variables
3921 # #Initializing some variables
3915 # ang_aux = numpy.array([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])*2*numpy.pi
3922 # ang_aux = numpy.array([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])*2*numpy.pi
3916 # ang_aux = ang_aux.reshape(1,ang_aux.size)
3923 # ang_aux = ang_aux.reshape(1,ang_aux.size)
3917 #
3924 #
3918 # cosdir = numpy.zeros((arrayPhase.shape[0],2))
3925 # cosdir = numpy.zeros((arrayPhase.shape[0],2))
3919 # cosdir0 = numpy.zeros((arrayPhase.shape[0],2))
3926 # cosdir0 = numpy.zeros((arrayPhase.shape[0],2))
3920 #
3927 #
3921 #
3928 #
3922 # for i in range(2):
3929 # for i in range(2):
3923 # #First Estimation
3930 # #First Estimation
3924 # phi0_aux = arrayPhase[:,pairsList[i][0]] + arrayPhase[:,pairsList[i][1]]
3931 # phi0_aux = arrayPhase[:,pairsList[i][0]] + arrayPhase[:,pairsList[i][1]]
3925 # #Dealias
3932 # #Dealias
3926 # indcsi = numpy.where(phi0_aux > numpy.pi)
3933 # indcsi = numpy.where(phi0_aux > numpy.pi)
3927 # phi0_aux[indcsi] -= 2*numpy.pi
3934 # phi0_aux[indcsi] -= 2*numpy.pi
3928 # indcsi = numpy.where(phi0_aux < -numpy.pi)
3935 # indcsi = numpy.where(phi0_aux < -numpy.pi)
3929 # phi0_aux[indcsi] += 2*numpy.pi
3936 # phi0_aux[indcsi] += 2*numpy.pi
3930 # #Direction Cosine 0
3937 # #Direction Cosine 0
3931 # cosdir0[:,i] = -(phi0_aux)/(2*numpy.pi*0.5)
3938 # cosdir0[:,i] = -(phi0_aux)/(2*numpy.pi*0.5)
3932 #
3939 #
3933 # #Most-Accurate Second Estimation
3940 # #Most-Accurate Second Estimation
3934 # phi1_aux = arrayPhase[:,pairsList[i][0]] - arrayPhase[:,pairsList[i][1]]
3941 # phi1_aux = arrayPhase[:,pairsList[i][0]] - arrayPhase[:,pairsList[i][1]]
3935 # phi1_aux = phi1_aux.reshape(phi1_aux.size,1)
3942 # phi1_aux = phi1_aux.reshape(phi1_aux.size,1)
3936 # #Direction Cosine 1
3943 # #Direction Cosine 1
3937 # cosdir1 = -(phi1_aux + ang_aux)/(2*numpy.pi*4.5)
3944 # cosdir1 = -(phi1_aux + ang_aux)/(2*numpy.pi*4.5)
3938 #
3945 #
3939 # #Searching the correct Direction Cosine
3946 # #Searching the correct Direction Cosine
3940 # cosdir0_aux = cosdir0[:,i]
3947 # cosdir0_aux = cosdir0[:,i]
3941 # cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1)
3948 # cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1)
3942 # #Minimum Distance
3949 # #Minimum Distance
3943 # cosDiff = (cosdir1 - cosdir0_aux)**2
3950 # cosDiff = (cosdir1 - cosdir0_aux)**2
3944 # indcos = cosDiff.argmin(axis = 1)
3951 # indcos = cosDiff.argmin(axis = 1)
3945 # #Saving Value obtained
3952 # #Saving Value obtained
3946 # cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos]
3953 # cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos]
3947 #
3954 #
3948 # return cosdir0, cosdir
3955 # return cosdir0, cosdir
3949 #
3956 #
3950 # def __calculateAOA(self, cosdir, azimuth):
3957 # def __calculateAOA(self, cosdir, azimuth):
3951 # cosdirX = cosdir[:,0]
3958 # cosdirX = cosdir[:,0]
3952 # cosdirY = cosdir[:,1]
3959 # cosdirY = cosdir[:,1]
3953 #
3960 #
3954 # zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi
3961 # zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi
3955 # azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth #0 deg north, 90 deg east
3962 # azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth #0 deg north, 90 deg east
3956 # angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose()
3963 # angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose()
3957 #
3964 #
3958 # return angles
3965 # return angles
3959 #
3966 #
3960 # def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight):
3967 # def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight):
3961 #
3968 #
3962 # Ramb = 375 #Ramb = c/(2*PRF)
3969 # Ramb = 375 #Ramb = c/(2*PRF)
3963 # Re = 6371 #Earth Radius
3970 # Re = 6371 #Earth Radius
3964 # heights = numpy.zeros(Ranges.shape)
3971 # heights = numpy.zeros(Ranges.shape)
3965 #
3972 #
3966 # R_aux = numpy.array([0,1,2])*Ramb
3973 # R_aux = numpy.array([0,1,2])*Ramb
3967 # R_aux = R_aux.reshape(1,R_aux.size)
3974 # R_aux = R_aux.reshape(1,R_aux.size)
3968 #
3975 #
3969 # Ranges = Ranges.reshape(Ranges.size,1)
3976 # Ranges = Ranges.reshape(Ranges.size,1)
3970 #
3977 #
3971 # Ri = Ranges + R_aux
3978 # Ri = Ranges + R_aux
3972 # hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re
3979 # hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re
3973 #
3980 #
3974 # #Check if there is a height between 70 and 110 km
3981 # #Check if there is a height between 70 and 110 km
3975 # h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1)
3982 # h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1)
3976 # ind_h = numpy.where(h_bool == 1)[0]
3983 # ind_h = numpy.where(h_bool == 1)[0]
3977 #
3984 #
3978 # hCorr = hi[ind_h, :]
3985 # hCorr = hi[ind_h, :]
3979 # ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight))
3986 # ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight))
3980 #
3987 #
3981 # hCorr = hi[ind_hCorr]
3988 # hCorr = hi[ind_hCorr]
3982 # heights[ind_h] = hCorr
3989 # heights[ind_h] = hCorr
3983 #
3990 #
3984 # #Setting Error
3991 # #Setting Error
3985 # #Number 13: Height unresolvable echo: not valid height within 70 to 110 km
3992 # #Number 13: Height unresolvable echo: not valid height within 70 to 110 km
3986 # #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km
3993 # #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km
3987 #
3994 #
3988 # indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0]
3995 # indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0]
3989 # error[indInvalid2] = 14
3996 # error[indInvalid2] = 14
3990 # indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0]
3997 # indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0]
3991 # error[indInvalid1] = 13
3998 # error[indInvalid1] = 13
3992 #
3999 #
3993 # return heights, error
4000 # return heights, error
3994 No newline at end of file
4001
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
@@ -1,1 +1,1
1 <Project description="read bltr data sswma file" id="191" name="test1"><ReadUnit datatype="testBLTRReader" id="1911" inputId="0" name="testBLTRReader"><Operation id="19111" name="run" priority="1" type="self"><Parameter format="str" id="191111" name="datatype" value="testBLTRReader" /><Parameter format="str" id="191112" name="path" value="/media/erick/6F60F7113095A154/BLTR" /><Parameter format="date" id="191113" name="startDate" value="2017/01/17" /><Parameter format="date" id="191114" name="endDate" value="2018/01/01" /><Parameter format="time" id="191115" name="startTime" value="00:00:00" /><Parameter format="time" id="191116" name="endTime" value="23:59:59" /><Parameter format="str" id="191118" name="ext" value="sswma" /></Operation></ReadUnit><ProcUnit datatype="BLTRProcess" id="1912" inputId="1911" name="BLTRProcess"><Operation id="19121" name="run" priority="1" type="self" /><Operation id="19122" name="SnrFilter" priority="2" type="self"><Parameter format="float" id="191221" name="snr_val" value="-20" /><Parameter format="int" id="191222" name="modetofilter" value="2" /></Operation><Operation id="19123" name="OutliersFilter" priority="3" type="self"><Parameter format="str" id="191231" name="svalue" value="meridional" /><Parameter format="str" id="191232" name="svalue2" value="inTime" /><Parameter format="float" id="191233" name="method" value="0" /><Parameter format="float" id="191234" name="factor" value="2" /><Parameter format="float" id="191235" name="filter" value="0" /><Parameter format="float" id="191236" name="npoints" value="9" /><Parameter format="int" id="191237" name="modetofilter" value="2" /></Operation><Operation id="19124" name="OutliersFilter" priority="4" type="self"><Parameter format="str" id="191241" name="svalue" value="zonal" /><Parameter format="str" id="191242" name="svalue2" value="inTime" /><Parameter format="float" id="191243" name="method" value="0" /><Parameter format="float" id="191244" name="factor" value="2" /><Parameter format="float" id="191245" name="filter" value="0" /><Parameter format="float" id="191246" name="npoints" value="9" /><Parameter format="int" id="191247" name="modetofilter" value="2" /></Operation><Operation id="19125" name="OutliersFilter" priority="5" type="self"><Parameter format="str" id="191251" name="svalue" value="vertical" /><Parameter format="str" id="191252" name="svalue2" value="inHeight" /><Parameter format="float" id="191253" name="method" value="0" /><Parameter format="float" id="191254" name="factor" value="2" /><Parameter format="float" id="191255" name="filter" value="0" /><Parameter format="float" id="191256" name="npoints" value="9" /><Parameter format="int" id="191257" name="modetofilter" value="2" /></Operation><Operation id="19126" name="prePlot" priority="6" type="self"><Parameter format="int" id="191261" name="modeselect" value="1" /></Operation><Operation id="19127" name="WindProfilerPlot" priority="7" type="other"><Parameter format="int" id="191271" name="id" value="1" /><Parameter format="str" id="191272" name="wintitle" value="" /><Parameter format="intlist" id="191273" name="channelList" value="0" /><Parameter format="int" id="191274" name="SNRmin" value="-10" /><Parameter format="int" id="191275" name="SNRmax" value="50" /><Parameter format="float" id="191276" name="SNRthresh" value="0" /><Parameter format="float" id="191277" name="xmin" value="0" /><Parameter format="float" id="191278" name="xmax" value="24" /><Parameter format="float" id="191279" name="ymax" value="3" /><Parameter format="float" id="191280" name="zmin" value="-20" /><Parameter format="float" id="191281" name="zmax" value="20" /><Parameter format="float" id="191282" name="zmin_ver" value="-200" /><Parameter format="float" id="191283" name="zmax_ver" value="200" /></Operation><Operation id="19128" name="prePlot" priority="8" type="self"><Parameter format="int" id="191281" name="modeselect" value="2" /></Operation><Operation id="19129" name="WindProfilerPlot" priority="9" type="other"><Parameter format="int" id="191291" name="id" value="2" /><Parameter format="str" id="191292" name="wintitle" value="" /><Parameter format="bool" id="191293" name="save" value="1" /><Parameter format="str" id="191294" name="figpath" value="/media/erick/6F60F7113095A154/BLTR/" /><Parameter format="int" id="191295" name="SNRmin" value="-20" /><Parameter format="int" id="191296" name="SNRmax" value="40" /><Parameter format="float" id="191297" name="SNRthresh" value="0" /><Parameter format="float" id="191298" name="xmin" value="0" /><Parameter format="float" id="191299" name="xmax" value="24" /><Parameter format="float" id="191300" name="ymin" value="0" /><Parameter format="float" id="191301" name="ymax" value="10" /><Parameter format="float" id="191302" name="zmin" value="-4" /><Parameter format="float" id="191303" name="zmax" value="4" /><Parameter format="float" id="191304" name="zmin_ver" value="-200" /><Parameter format="float" id="191305" name="zmax_ver" value="200" /></Operation></ProcUnit></Project> No newline at end of file
1 <Project description="Segundo Test" id="191" name="test01"><ReadUnit datatype="VoltageReader" id="1911" inputId="0" name="VoltageReader"><Operation id="19111" name="run" priority="1" type="self"><Parameter format="str" id="191111" name="datatype" value="VoltageReader" /><Parameter format="str" id="191112" name="path" value="/home/erick/Documents/Data/Claire_Data/raw" /><Parameter format="date" id="191113" name="startDate" value="2017/07/26" /><Parameter format="date" id="191114" name="endDate" value="2017/07/26" /><Parameter format="time" id="191115" name="startTime" value="10:02:00" /><Parameter format="time" id="191116" name="endTime" value="10:11:00" /><Parameter format="int" id="191118" name="online" value="0" /><Parameter format="int" id="191119" name="walk" value="1" /></Operation><Operation id="19112" name="printNumberOfBlock" priority="2" type="self" /></ReadUnit><ProcUnit datatype="SpectraProc" id="1913" inputId="1912" name="SpectraProc"><Operation id="19131" name="run" priority="1" type="self"><Parameter format="int" id="191311" name="nFFTPoints" value="128" /><Parameter format="pairslist" id="191312" name="pairsList" value="(0,1),(0,2),(1,2)" /></Operation><Operation id="19132" name="removeDC" priority="2" type="self" /><Operation id="19133" name="IncohInt" priority="3" type="external"><Parameter format="float" id="191331" name="n" value="30" /></Operation><Operation id="19134" name="CrossSpectraPlot" priority="4" type="other"><Parameter format="str" id="191341" name="phase_cmap" value="bwr" /><Parameter format="int" id="191342" name="id" value="2005" /><Parameter format="str" id="191343" name="wintitle" value="CrossSpectraPlot_ShortPulse" /><Parameter format="str" id="191344" name="xaxis" value="Velocity" /><Parameter format="float" id="191345" name="ymin" value="1" /><Parameter format="int" id="191346" name="ymax" value="7" /><Parameter format="int" id="191347" name="zmin" value="15" /><Parameter format="int" id="191348" name="zmax" value="60" /><Parameter format="int" id="191349" name="save" value="2" /><Parameter format="str" id="191350" name="figpath" value="/media/erick/6F60F7113095A154/CLAIRE/CLAIRE_WINDS_2MHZ/Images" /></Operation></ProcUnit><ProcUnit datatype="VoltageProc" id="1912" inputId="1911" name="VoltageProc"><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><Operation id="19123" name="selectHeights" priority="3" type="self"><Parameter format="float" id="191231" name="minHei" value="0" /><Parameter format="float" id="191232" name="maxHei" value="64" /></Operation></ProcUnit><ProcUnit datatype="Parameters" id="1914" inputId="1913" name="ParametersProc"><Operation id="19141" name="run" priority="1" type="self" /><Operation id="19142" name="GaussianFit" priority="2" type="other" /></ProcUnit></Project> No newline at end of file
@@ -1,171 +1,171
1 '''
1 '''
2 Created on Nov 09, 2016
2 Created on Nov 09, 2016
3
3
4 @author: roj- LouVD
4 @author: roj- LouVD
5 '''
5 '''
6 import os, sys
6 import os, sys
7
7
8
8
9 path = os.path.split(os.getcwd())[0]
9 path = os.path.split(os.getcwd())[0]
10 path = os.path.split(path)[0]
10 path = os.path.split(path)[0]
11
11
12 sys.path.insert(0, path)
12 sys.path.insert(0, path)
13
13
14 from schainpy.controller import Project
14 from schainpy.controller import Project
15
15
16 filename = 'test1.xml'
16 filename = 'test1.xml'
17 # path = '/home/jespinoza/workspace/data/bltr/'
17 # path = '/home/jespinoza/workspace/data/bltr/'
18 path = '/media/erick/6F60F7113095A154/BLTR/'
18 path = '/media/erick/6F60F7113095A154/BLTR/'
19 desc = "read bltr data sswma file"
19 desc = "read bltr data sswma file"
20 figpath = '/media/erick/6F60F7113095A154/BLTR/'
20 figpath = '/media/erick/6F60F7113095A154/BLTR/'
21 pathhdf5 = '/tmp/'
21 pathhdf5 = '/tmp/'
22
22
23 controllerObj = Project()
23 controllerObj = Project()
24
24
25 controllerObj.setup(id = '191', name='test1', description=desc)
25 controllerObj.setup(id = '191', name='test1', description=desc)
26 readUnitConfObj = controllerObj.addReadUnit(datatype='testBLTRReader',
26 readUnitConfObj = controllerObj.addReadUnit(datatype='testBLTRReader',
27 path=path,
27 path=path,
28 startDate='2017/01/17',
28 startDate='2017/01/17',
29 endDate='2018/01/01',
29 endDate='2018/01/01',
30 startTime='00:00:00',
30 startTime='00:00:00',
31 endTime='23:59:59',
31 endTime='23:59:59',
32 ext='sswma')
32 ext='sswma')
33
33
34 procUnitConfObj1 = controllerObj.addProcUnit(datatype='BLTRProcess',
34 procUnitConfObj1 = controllerObj.addProcUnit(datatype='BLTRProcess',
35 inputId=readUnitConfObj.getId())
35 inputId=readUnitConfObj.getId())
36
36
37 '''-------------------------------------------Processing--------------------------------------------'''
37 '''-------------------------------------------Processing--------------------------------------------'''
38
38
39 '''MODE 1: LOW ATMOSPHERE: 0- 3 km'''
39 '''MODE 1: LOW ATMOSPHERE: 0- 3 km'''
40 # opObj10 = procUnitConfObj1.addOperation(name='SnrFilter')
40 # opObj10 = procUnitConfObj1.addOperation(name='SnrFilter')
41 # opObj10.addParameter(name='snr_val', value='-10', format='float')
41 # opObj10.addParameter(name='snr_val', value='-10', format='float')
42 # opObj10.addParameter(name='modetofilter', value='1', format='int')
42 # opObj10.addParameter(name='modetofilter', value='1', format='int')
43 #
43 #
44 # opObj10 = procUnitConfObj1.addOperation(name='OutliersFilter')
44 # opObj10 = procUnitConfObj1.addOperation(name='OutliersFilter')
45 # opObj10.addParameter(name='svalue', value='meridional', format='str')
45 # opObj10.addParameter(name='svalue', value='meridional', format='str')
46 # opObj10.addParameter(name='svalue2', value='inTime', format='str')
46 # opObj10.addParameter(name='svalue2', value='inTime', format='str')
47 # opObj10.addParameter(name='method', value='0', format='float')
47 # opObj10.addParameter(name='method', value='0', format='float')
48 # opObj10.addParameter(name='factor', value='1', format='float')
48 # opObj10.addParameter(name='factor', value='1', format='float')
49 # opObj10.addParameter(name='filter', value='0', format='float')
49 # opObj10.addParameter(name='filter', value='0', format='float')
50 # opObj10.addParameter(name='npoints', value='5', format='float')
50 # opObj10.addParameter(name='npoints', value='5', format='float')
51 # opObj10.addParameter(name='modetofilter', value='1', format='int')
51 # opObj10.addParameter(name='modetofilter', value='1', format='int')
52 # #
52 # #
53 # opObj10 = procUnitConfObj1.addOperation(name='OutliersFilter')
53 # opObj10 = procUnitConfObj1.addOperation(name='OutliersFilter')
54 # opObj10.addParameter(name='svalue', value='zonal', format='str')
54 # opObj10.addParameter(name='svalue', value='zonal', format='str')
55 # opObj10.addParameter(name='svalue2', value='inTime', format='str')
55 # opObj10.addParameter(name='svalue2', value='inTime', format='str')
56 # opObj10.addParameter(name='method', value='0', format='float')
56 # opObj10.addParameter(name='method', value='0', format='float')
57 # opObj10.addParameter(name='factor', value='1', format='float')
57 # opObj10.addParameter(name='factor', value='1', format='float')
58 # opObj10.addParameter(name='filter', value='0', format='float')
58 # opObj10.addParameter(name='filter', value='0', format='float')
59 # opObj10.addParameter(name='npoints', value='5', format='float')
59 # opObj10.addParameter(name='npoints', value='5', format='float')
60 # opObj10.addParameter(name='modetofilter', value='1', format='int')
60 # opObj10.addParameter(name='modetofilter', value='1', format='int')
61 # #
61 # #
62 # opObj10 = procUnitConfObj1.addOperation(name='OutliersFilter')
62 # opObj10 = procUnitConfObj1.addOperation(name='OutliersFilter')
63 # opObj10.addParameter(name='svalue', value='vertical', format='str')
63 # opObj10.addParameter(name='svalue', value='vertical', format='str')
64 # opObj10.addParameter(name='svalue2', value='inHeight', format='str')
64 # opObj10.addParameter(name='svalue2', value='inHeight', format='str')
65 # opObj10.addParameter(name='method', value='0', format='float')
65 # opObj10.addParameter(name='method', value='0', format='float')
66 # opObj10.addParameter(name='factor', value='2', format='float')
66 # opObj10.addParameter(name='factor', value='2', format='float')
67 # opObj10.addParameter(name='filter', value='0', format='float')
67 # opObj10.addParameter(name='filter', value='0', format='float')
68 # opObj10.addParameter(name='npoints', value='9', format='float')
68 # opObj10.addParameter(name='npoints', value='9', format='float')
69 # opObj10.addParameter(name='modetofilter', value='1', format='int')
69 # opObj10.addParameter(name='modetofilter', value='1', format='int')
70 #
70 #
71
71
72 ''' MODE 2: 0 - 10 km '''
72 ''' MODE 2: 0 - 10 km '''
73
73
74 opObj10 = procUnitConfObj1.addOperation(name='SnrFilter')
74 opObj10 = procUnitConfObj1.addOperation(name='SnrFilter')
75 opObj10.addParameter(name='snr_val', value='-20', format='float')
75 opObj10.addParameter(name='snr_val', value='-20', format='float')
76 opObj10.addParameter(name='modetofilter', value='2', format='int')
76 opObj10.addParameter(name='modetofilter', value='2', format='int')
77
77
78 opObj10 = procUnitConfObj1.addOperation(name='OutliersFilter')
78 opObj10 = procUnitConfObj1.addOperation(name='OutliersFilter')
79 opObj10.addParameter(name='svalue', value='meridional', format='str')
79 opObj10.addParameter(name='svalue', value='meridional', format='str')
80 opObj10.addParameter(name='svalue2', value='inTime', format='str')
80 opObj10.addParameter(name='svalue2', value='inTime', format='str')
81 opObj10.addParameter(name='method', value='0', format='float')
81 opObj10.addParameter(name='method', value='0', format='float')
82 opObj10.addParameter(name='factor', value='2', format='float')
82 opObj10.addParameter(name='factor', value='2', format='float')
83 opObj10.addParameter(name='filter', value='0', format='float')
83 opObj10.addParameter(name='filter', value='0', format='float')
84 opObj10.addParameter(name='npoints', value='9', format='float')
84 opObj10.addParameter(name='npoints', value='9', format='float')
85 opObj10.addParameter(name='modetofilter', value='2', format='int')
85 opObj10.addParameter(name='modetofilter', value='2', format='int')
86 # #
86 # #
87 opObj10 = procUnitConfObj1.addOperation(name='OutliersFilter')
87 opObj10 = procUnitConfObj1.addOperation(name='OutliersFilter')
88 opObj10.addParameter(name='svalue', value='zonal', format='str')
88 opObj10.addParameter(name='svalue', value='zonal', format='str')
89 opObj10.addParameter(name='svalue2', value='inTime', format='str')
89 opObj10.addParameter(name='svalue2', value='inTime', format='str')
90 opObj10.addParameter(name='method', value='0', format='float')
90 opObj10.addParameter(name='method', value='0', format='float')
91 opObj10.addParameter(name='factor', value='2', format='float')
91 opObj10.addParameter(name='factor', value='2', format='float')
92 opObj10.addParameter(name='filter', value='0', format='float')
92 opObj10.addParameter(name='filter', value='0', format='float')
93 opObj10.addParameter(name='npoints', value='9', format='float')
93 opObj10.addParameter(name='npoints', value='9', format='float')
94 opObj10.addParameter(name='modetofilter', value='2', format='int')
94 opObj10.addParameter(name='modetofilter', value='2', format='int')
95 # #
95 # #
96 opObj10 = procUnitConfObj1.addOperation(name='OutliersFilter')
96 opObj10 = procUnitConfObj1.addOperation(name='OutliersFilter')
97 opObj10.addParameter(name='svalue', value='vertical', format='str')
97 opObj10.addParameter(name='svalue', value='vertical', format='str')
98 opObj10.addParameter(name='svalue2', value='inHeight', format='str')
98 opObj10.addParameter(name='svalue2', value='inHeight', format='str')
99 opObj10.addParameter(name='method', value='0', format='float')
99 opObj10.addParameter(name='method', value='0', format='float')
100 opObj10.addParameter(name='factor', value='2', format='float')
100 opObj10.addParameter(name='factor', value='2', format='float')
101 opObj10.addParameter(name='filter', value='0', format='float')
101 opObj10.addParameter(name='filter', value='0', format='float')
102 opObj10.addParameter(name='npoints', value='9', format='float')
102 opObj10.addParameter(name='npoints', value='9', format='float')
103 opObj10.addParameter(name='modetofilter', value='2', format='int')
103 opObj10.addParameter(name='modetofilter', value='2', format='int')
104
104
105 # '''-----------------------------------------Writing-------------------------------------------'''
105 # '''-----------------------------------------Writing-------------------------------------------'''
106 #
106 #
107 # # opObj10 = procUnitConfObj1.addOperation(name='testBLTRWriter',optype='other')
107 # # opObj10 = procUnitConfObj1.addOperation(name='testBLTRWriter',optype='other')
108 # # opObj10.addParameter(name='path', value = pathhdf5)
108 # # opObj10.addParameter(name='path', value = pathhdf5)
109 # # opObj10.addParameter(name='modetowrite', value = '2',format='int')
109 # # opObj10.addParameter(name='modetowrite', value = '2',format='int')
110 # #
110 # #
111 # # opObj10 = procUnitConfObj1.addOperation(name='testBLTRWriter',optype='other')
111 # # opObj10 = procUnitConfObj1.addOperation(name='testBLTRWriter',optype='other')
112 # # opObj10.addParameter(name='path', value = pathhdf5)
112 # # opObj10.addParameter(name='path', value = pathhdf5)
113 # # opObj10.addParameter(name='modetowrite', value = '1',format='int')
113 # # opObj10.addParameter(name='modetowrite', value = '1',format='int')
114 #
114 #
115 # '''----------------------------------------Plotting--------------------------------------------'''
115 # '''----------------------------------------Plotting--------------------------------------------'''
116 #
116 #
117 opObj10 = procUnitConfObj1.addOperation(name='prePlot')
117 opObj10 = procUnitConfObj1.addOperation(name='prePlot')
118 opObj10.addParameter(name='modeselect',value='1',format='int')
118 opObj10.addParameter(name='modeselect',value='1',format='int')
119 # #
119 # #
120 opObj10 = procUnitConfObj1.addOperation(name='WindProfilerPlot', optype='other')
120 opObj10 = procUnitConfObj1.addOperation(name='WindProfilerPlot', optype='other')
121 opObj10.addParameter(name='id', value='1', format='int')
121 opObj10.addParameter(name='id', value='1', format='int')
122 opObj10.addParameter(name='wintitle', value='', format='str')
122 opObj10.addParameter(name='wintitle', value='', format='str')
123 opObj10.addParameter(name='channelList', value='0', format='intlist')
123 opObj10.addParameter(name='channelList', value='0', format='intlist')
124 #opObj10.addParameter(name='save', value='1', format='bool')
124 #opObj10.addParameter(name='save', value='1', format='bool')
125 #opObj10.addParameter(name='figpath', value=figpath, format='str')
125 #opObj10.addParameter(name='figpath', value=figpath, format='str')
126 opObj10.addParameter(name='SNRmin', value='-10', format='int')
126 opObj10.addParameter(name='SNRmin', value='-10', format='int')
127 opObj10.addParameter(name='SNRmax', value='50', format='int')
127 opObj10.addParameter(name='SNRmax', value='50', format='int')
128 opObj10.addParameter(name='SNRthresh', value='0', format='float')
128 opObj10.addParameter(name='SNRthresh', value='0', format='float')
129 opObj10.addParameter(name='xmin', value='0', format='float')
129 opObj10.addParameter(name='xmin', value='0', format='float')
130 opObj10.addParameter(name='xmax', value='24', format='float')
130 opObj10.addParameter(name='xmax', value='24', format='float')
131 opObj10.addParameter(name='ymax', value='3', format='float')
131 opObj10.addParameter(name='ymax', value='3', format='float')
132 opObj10.addParameter(name='zmin', value='-20', format='float')
132 opObj10.addParameter(name='zmin', value='-20', format='float')
133 opObj10.addParameter(name='zmax', value='20', format='float')
133 opObj10.addParameter(name='zmax', value='20', format='float')
134 opObj10.addParameter(name='zmin_ver', value='-200', format='float')
134 opObj10.addParameter(name='zmin_ver', value='-200', format='float')
135 opObj10.addParameter(name='zmax_ver', value='200', format='float')
135 opObj10.addParameter(name='zmax_ver', value='200', format='float')
136 #opObj10.addParameter(name='showprofile', value='1', format='bool')
136 #opObj10.addParameter(name='showprofile', value='1', format='bool')
137 #opObj10.addParameter(name='show', value='1', format='bool')
137 #opObj10.addParameter(name='show', value='1', format='bool')
138
138
139 opObj10 = procUnitConfObj1.addOperation(name='prePlot')
139 opObj10 = procUnitConfObj1.addOperation(name='prePlot')
140 opObj10.addParameter(name='modeselect',value='2',format='int')
140 opObj10.addParameter(name='modeselect',value='2',format='int')
141 #
141 #
142 opObj10 = procUnitConfObj1.addOperation(name='WindProfilerPlot', optype='other')
142 opObj10 = procUnitConfObj1.addOperation(name='WindProfilerPlot', optype='other')
143 opObj10.addParameter(name='id', value='2', format='int')
143 opObj10.addParameter(name='id', value='2', format='int')
144 opObj10.addParameter(name='wintitle', value='', format='str')
144 opObj10.addParameter(name='wintitle', value='', format='str')
145 #opObj10.addParameter(name='channelList', value='0', format='intlist')
145 #opObj10.addParameter(name='channelList', value='0', format='intlist')
146 opObj10.addParameter(name='save', value='1', format='bool')
146 opObj10.addParameter(name='save', value='1', format='bool')
147 opObj10.addParameter(name='figpath', value=figpath, format='str')
147 opObj10.addParameter(name='figpath', value=figpath, format='str')
148 opObj10.addParameter(name='SNRmin', value='-20', format='int')
148 opObj10.addParameter(name='SNRmin', value='-20', format='int')
149 opObj10.addParameter(name='SNRmax', value='40', format='int')
149 opObj10.addParameter(name='SNRmax', value='40', format='int')
150 opObj10.addParameter(name='SNRthresh', value='0', format='float')
150 opObj10.addParameter(name='SNRthresh', value='0', format='float')
151 opObj10.addParameter(name='xmin', value='0', format='float')
151 opObj10.addParameter(name='xmin', value='0', format='float')
152 opObj10.addParameter(name='xmax', value='24', format='float')
152 opObj10.addParameter(name='xmax', value='24', format='float')
153 opObj10.addParameter(name='ymin', value='0', format='float')
153 opObj10.addParameter(name='ymin', value='0', format='float')
154 opObj10.addParameter(name='ymax', value='10', format='float')
154 opObj10.addParameter(name='ymax', value='7', format='float')
155 opObj10.addParameter(name='zmin', value='-4', format='float')
155 opObj10.addParameter(name='zmin', value='-4', format='float')
156 opObj10.addParameter(name='zmax', value='4', format='float')
156 opObj10.addParameter(name='zmax', value='4', format='float')
157 opObj10.addParameter(name='zmin_ver', value='-200', format='float')
157 opObj10.addParameter(name='zmin_ver', value='-200', format='float')
158 opObj10.addParameter(name='zmax_ver', value='200', format='float')
158 opObj10.addParameter(name='zmax_ver', value='200', format='float')
159 #opObj10.addParameter(name='showprofile', value='1', format='bool')
159 #opObj10.addParameter(name='showprofile', value='1', format='bool')
160 #opObj10.addParameter(name='show', value='1', format='bool')
160 #opObj10.addParameter(name='show', value='1', format='bool')
161
161
162 # # print "Escribiendo el archivo XML"
162 # # print "Escribiendo el archivo XML"
163 # controllerObj.writeXml(filename)
163 # controllerObj.writeXml(filename)
164 # # print "Leyendo el archivo XML"
164 # # print "Leyendo el archivo XML"
165 # controllerObj.readXml(filename)
165 # controllerObj.readXml(filename)
166
166
167 # controllerObj.createObjects()
167 # controllerObj.createObjects()
168 # controllerObj.connectObjects()
168 # controllerObj.connectObjects()
169 # controllerObj.run()
169 # controllerObj.run()
170 controllerObj.start()
170 controllerObj.start()
171
171
@@ -1,150 +1,151
1 #!/usr/bin/env python
1 #!/usr/bin/env python
2 import os, sys
2 import os, sys
3
3
4 # path = os.path.dirname(os.getcwd())
4 # path = os.path.dirname(os.getcwd())
5 # path = os.path.join(path, 'source')
5 # path = os.path.join(path, 'source')
6 # sys.path.insert(0, '../')
6 # sys.path.insert(0, '../')
7
7
8 from schainpy.controller import Project
8 from schainpy.controller import Project
9
9
10 xmin = '15.5'
10 xmin = '15.5'
11 xmax = '24'
11 xmax = '24'
12
12
13
13
14 desc = "ProcBLTR Test"
14 desc = "ProcBLTR Test"
15 filename = "ProcBLTR.xml"
15 filename = "ProcBLTR.xml"
16 figpath = '/media/erick/6F60F7113095A154/BLTR'
16 figpath = '/media/erick/6F60F7113095A154/BLTR'
17
17
18 controllerObj = Project()
18 controllerObj = Project()
19
19
20
20
21 controllerObj.setup(id='191', name='test01', description=desc)
21 controllerObj.setup(id='191', name='test01', description=desc)
22
22
23 readUnitConfObj = controllerObj.addReadUnit(datatype='BLTRReader',
23 readUnitConfObj = controllerObj.addReadUnit(datatype='BLTRReader',
24 path='/media/erick/6F60F7113095A154/BLTR/',
24 path='/media/erick/6F60F7113095A154/BLTR/',
25
25
26 endDate='2017/10/19',
26 endDate='2017/10/19',
27 startTime='13:00:00',
27 startTime='13:00:00',
28 startDate='2016/11/8',
28 startDate='2016/11/8',
29 endTime='23:59:59',
29 endTime='23:59:59',
30
30
31
31
32 online=0,
32 online=0,
33 walk=0,
33 walk=0,
34 ReadMode='1')
34 ReadMode='1')
35 # expLabel='')
35 # expLabel='')
36
36
37 # opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock')
37 # opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock')
38
38
39 procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=readUnitConfObj.getId())
39 procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=readUnitConfObj.getId())
40
40
41
41
42
42
43 opObj11 = procUnitConfObj1.addOperation(name='IncohInt', optype='other')
43 opObj11 = procUnitConfObj1.addOperation(name='IncohInt', optype='other')
44 opObj11.addParameter(name='n', value='3', format='float')
44 opObj11.addParameter(name='n', value='3', format='float')
45
45
46 opObj10 = procUnitConfObj1.addOperation(name='removeDC')
46 opObj10 = procUnitConfObj1.addOperation(name='removeDC')
47
47
48 # opObj10 = procUnitConfObj1.addOperation(name='calcMag')
48 # opObj10 = procUnitConfObj1.addOperation(name='calcMag')
49
49
50 # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other')
50 # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other')
51 # opObj11.addParameter(name='id', value='21', format='int')
51 # opObj11.addParameter(name='id', value='21', format='int')
52 # opObj11.addParameter(name='wintitle', value='SpectraCutPlot', format='str')
52 # opObj11.addParameter(name='wintitle', value='SpectraCutPlot', format='str')
53 # opObj11.addParameter(name='xaxis', value='frequency', format='str')
53 # opObj11.addParameter(name='xaxis', value='frequency', format='str')
54 # opObj11.addParameter(name='colormap', value='winter', format='str')
54 # opObj11.addParameter(name='colormap', value='winter', format='str')
55 # opObj11.addParameter(name='xmin', value='-0.005', format='float')
55 # opObj11.addParameter(name='xmin', value='-0.005', format='float')
56 # opObj11.addParameter(name='xmax', value='0.005', format='float')
56 # opObj11.addParameter(name='xmax', value='0.005', format='float')
57 # #opObj10 = procUnitConfObj1.addOperation(name='selectChannels')
57 # #opObj10 = procUnitConfObj1.addOperation(name='selectChannels')
58 # #opObj10.addParameter(name='channelList', value='0,1', format='intlist')
58 # #opObj10.addParameter(name='channelList', value='0,1', format='intlist')
59 # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other')
59 # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other')
60 # opObj11.addParameter(name='id', value='21', format='int')
60 # opObj11.addParameter(name='id', value='21', format='int')
61 # opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str')
61 # opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str')
62 # #opObj11.addParameter(name='xaxis', value='Velocity', format='str')
62 # #opObj11.addParameter(name='xaxis', value='Velocity', format='str')
63
63
64 # opObj11.addParameter(name='xaxis', value='velocity', format='str')
64 # opObj11.addParameter(name='xaxis', value='velocity', format='str')
65 # opObj11.addParameter(name='xmin', value='-0.005', format='float')
65 # opObj11.addParameter(name='xmin', value='-0.005', format='float')
66 # opObj11.addParameter(name='xmax', value='0.005', format='float')
66 # opObj11.addParameter(name='xmax', value='0.005', format='float')
67
67
68 # opObj11.addParameter(name='ymin', value='225', format='float')
68 # opObj11.addParameter(name='ymin', value='225', format='float')
69 # opObj11.addParameter(name='ymax', value='3000', format='float')
69 # opObj11.addParameter(name='ymax', value='3000', format='float')
70 # opObj11.addParameter(name='zmin', value='-100', format='int')
70 # opObj11.addParameter(name='zmin', value='-100', format='int')
71 # opObj11.addParameter(name='zmax', value='-65', format='int')
71 # opObj11.addParameter(name='zmax', value='-65', format='int')
72
72
73 # opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other')
73 # opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other')
74 # opObj11.addParameter(name='id', value='10', format='int')
74 # opObj11.addParameter(name='id', value='10', format='int')
75 # opObj11.addParameter(name='wintitle', value='RTI', format='str')
75 # opObj11.addParameter(name='wintitle', value='RTI', format='str')
76 # opObj11.addParameter(name='ymin', value='0', format='float')
76 # opObj11.addParameter(name='ymin', value='0', format='float')
77 # opObj11.addParameter(name='ymax', value='4000', format='float')
77 # opObj11.addParameter(name='ymax', value='4000', format='float')
78 # #opObj11.addParameter(name='zmin', value='-100', format='int')
78 # #opObj11.addParameter(name='zmin', value='-100', format='int')
79 # #opObj11.addParameter(name='zmax', value='-70', format='int')
79 # #opObj11.addParameter(name='zmax', value='-70', format='int')
80 # opObj11.addParameter(name='zmin', value='-90', format='int')
80 # opObj11.addParameter(name='zmin', value='-90', format='int')
81 # opObj11.addParameter(name='zmax', value='-40', format='int')
81 # opObj11.addParameter(name='zmax', value='-40', format='int')
82 # opObj11.addParameter(name='showprofile', value='1', format='int')
82 # opObj11.addParameter(name='showprofile', value='1', format='int')
83 # opObj11.addParameter(name='timerange', value=str(2*60*60), format='int')
83 # opObj11.addParameter(name='timerange', value=str(2*60*60), format='int')
84
84
85 opObj11 = procUnitConfObj1.addOperation(name='CrossSpectraPlot', optype='other')
85 opObj11 = procUnitConfObj1.addOperation(name='CrossSpectraPlot', optype='other')
86 procUnitConfObj1.addParameter(name='pairsList', value='(0,1),(0,2),(1,2)', format='pairsList')
86 procUnitConfObj1.addParameter(name='pairsList', value='(0,1),(0,2),(1,2)', format='pairsList')
87 opObj11.addParameter(name='id', value='2005', format='int')
87 opObj11.addParameter(name='id', value='2005', format='int')
88 opObj11.addParameter(name='wintitle', value='CrossSpectraPlot_ShortPulse', format='str')
88 opObj11.addParameter(name='wintitle', value='CrossSpectraPlot_ShortPulse', format='str')
89 # opObj11.addParameter(name='exp_code', value='13', format='int')
89 # opObj11.addParameter(name='exp_code', value='13', format='int')
90 opObj11.addParameter(name='xaxis', value='Velocity', format='str')
90 opObj11.addParameter(name='xaxis', value='Velocity', format='str')
91 #opObj11.addParameter(name='xmin', value='-10', format='float')
91 #opObj11.addParameter(name='xmin', value='-10', format='float')
92 #opObj11.addParameter(name='xmax', value='10', format='float')
92 #opObj11.addParameter(name='xmax', value='10', format='float')
93 #opObj11.addParameter(name='ymin', value='225', format='float')
93 #opObj11.addParameter(name='ymin', value='225', format='float')
94 #opObj11.addParameter(name='ymax', value='3000', format='float')
94 #opObj11.addParameter(name='ymax', value='3000', format='float')
95 #opObj11.addParameter(name='phase_min', value='-4', format='int')
95 #opObj11.addParameter(name='phase_min', value='-4', format='int')
96 #opObj11.addParameter(name='phase_max', value='4', format='int')
96 #opObj11.addParameter(name='phase_max', value='4', format='int')
97
97
98 # procUnitConfObj2 = controllerObj.addProcUnit(datatype='CorrelationProc', inputId=procUnitConfObj1.getId())
98 # procUnitConfObj2 = controllerObj.addProcUnit(datatype='CorrelationProc', inputId=procUnitConfObj1.getId())
99 # procUnitConfObj2.addParameter(name='pairsList', value='(0,1),(0,2),(1,2)', format='pairsList')
99 # procUnitConfObj2.addParameter(name='pairsList', value='(0,1),(0,2),(1,2)', format='pairsList')
100
100
101 procUnitConfObj2 = controllerObj.addProcUnit(datatype='Parameters', inputId=procUnitConfObj1.getId())
101 procUnitConfObj2 = controllerObj.addProcUnit(datatype='Parameters', inputId=procUnitConfObj1.getId())
102 opObj11 = procUnitConfObj2.addOperation(name='SpectralMoments', optype='other')
102 opObj11 = procUnitConfObj2.addOperation(name='SpectralMoments', optype='other')
103 opObj22 = procUnitConfObj2.addOperation(name='FullSpectralAnalysis', optype='other')
103 opObj22 = procUnitConfObj2.addOperation(name='FullSpectralAnalysis', optype='other')
104 opObj22.addParameter(name='SNRlimit', value='-4', format='float')
104 #
105 #
105 opObj22 = procUnitConfObj2.addOperation(name='WindProfilerPlot', optype='other')
106 opObj22 = procUnitConfObj2.addOperation(name='WindProfilerPlot', optype='other')
106 opObj22.addParameter(name='id', value='4', format='int')
107 opObj22.addParameter(name='id', value='4', format='int')
107 opObj22.addParameter(name='wintitle', value='Wind Profiler', format='str')
108 opObj22.addParameter(name='wintitle', value='Wind Profiler', format='str')
108 opObj22.addParameter(name='save', value='1', format='bool')
109 opObj22.addParameter(name='save', value='1', format='bool')
109 # opObj22.addParameter(name='figpath', value = '/home/erick/Pictures', format='str')
110 # opObj22.addParameter(name='figpath', value = '/home/erick/Pictures', format='str')
110
111
111 opObj22.addParameter(name='zmin', value='-20', format='int')
112 opObj22.addParameter(name='zmin', value='-20', format='int')
112 opObj22.addParameter(name='zmax', value='20', format='int')
113 opObj22.addParameter(name='zmax', value='20', format='int')
113 opObj22.addParameter(name='zmin_ver', value='-250', format='float')
114 opObj22.addParameter(name='zmin_ver', value='-250', format='float')
114 opObj22.addParameter(name='zmax_ver', value='250', format='float')
115 opObj22.addParameter(name='zmax_ver', value='250', format='float')
115 opObj22.addParameter(name='SNRmin', value='-5', format='int')
116 opObj22.addParameter(name='SNRmin', value='-5', format='int')
116 opObj22.addParameter(name='SNRmax', value='30', format='int')
117 opObj22.addParameter(name='SNRmax', value='30', format='int')
117 # opObj22.addParameter(name='SNRthresh', value='-3.5', format='float')
118 # opObj22.addParameter(name='SNRthresh', value='-3.5', format='float')
118 opObj22.addParameter(name='xmin', value=0, format='float')
119 opObj22.addParameter(name='xmin', value='0', format='float')
119 opObj22.addParameter(name='xmax', value=24, format='float')
120 opObj22.addParameter(name='xmax', value='24', format='float')
120 opObj22.addParameter(name='ymin', value='225', format='float')
121 opObj22.addParameter(name='ymin', value='225', format='float')
121 #opObj22.addParameter(name='ymax', value='2000', format='float')
122 #opObj22.addParameter(name='ymax', value='2000', format='float')
122 opObj22.addParameter(name='save', value='1', format='int')
123 opObj22.addParameter(name='save', value='1', format='int')
123 opObj22.addParameter(name='figpath', value=figpath, format='str')
124 opObj22.addParameter(name='figpath', value=figpath, format='str')
124
125
125
126
126 # opObj11.addParameter(name='pairlist', value='(1,0),(0,2),(1,2)', format='pairsList')
127 # opObj11.addParameter(name='pairlist', value='(1,0),(0,2),(1,2)', format='pairsList')
127 #opObj10 = procUnitConfObj1.addOperation(name='selectHeights')
128 #opObj10 = procUnitConfObj1.addOperation(name='selectHeights')
128 #opObj10.addParameter(name='minHei', value='225', format='float')
129 #opObj10.addParameter(name='minHei', value='225', format='float')
129 #opObj10.addParameter(name='maxHei', value='1000', format='float')
130 #opObj10.addParameter(name='maxHei', value='1000', format='float')
130
131
131 # opObj11 = procUnitConfObj1.addOperation(name='CoherenceMap', optype='other')
132 # opObj11 = procUnitConfObj1.addOperation(name='CoherenceMap', optype='other')
132 # opObj11.addParameter(name='id', value='102', format='int')
133 # opObj11.addParameter(name='id', value='102', format='int')
133 # opObj11.addParameter(name='wintitle', value='Coherence', format='str')
134 # opObj11.addParameter(name='wintitle', value='Coherence', format='str')
134 # opObj11.addParameter(name='ymin', value='225', format='float')
135 # opObj11.addParameter(name='ymin', value='225', format='float')
135 # opObj11.addParameter(name='ymax', value='4000', format='float')
136 # opObj11.addParameter(name='ymax', value='4000', format='float')
136
137
137 # opObj11.addParameter(name='phase_cmap', value='jet', format='str')
138 # opObj11.addParameter(name='phase_cmap', value='jet', format='str')
138 # opObj11.addParameter(name='xmin', value='8.5', format='float')
139 # opObj11.addParameter(name='xmin', value='8.5', format='float')
139 # opObj11.addParameter(name='xmax', value='9.5', format='float')
140 # opObj11.addParameter(name='xmax', value='9.5', format='float')
140 # opObj11.addParameter(name='figpath', value=figpath, format='str')
141 # opObj11.addParameter(name='figpath', value=figpath, format='str')
141 # opObj11.addParameter(name='save', value=1, format='bool')
142 # opObj11.addParameter(name='save', value=1, format='bool')
142 # opObj11.addParameter(name='pairsList', value='(1,0),(3,2)', format='pairsList')
143 # opObj11.addParameter(name='pairsList', value='(1,0),(3,2)', format='pairsList')
143
144
144 # opObj12 = procUnitConfObj1.addOperation(name='PublishData', optype='other')
145 # opObj12 = procUnitConfObj1.addOperation(name='PublishData', optype='other')
145 # opObj12.addParameter(name='zeromq', value=1, format='int')
146 # opObj12.addParameter(name='zeromq', value=1, format='int')
146 # opObj12.addParameter(name='verbose', value=0, format='bool')
147 # opObj12.addParameter(name='verbose', value=0, format='bool')
147 # opObj12.addParameter(name='server', value='erick2', format='str')
148 # opObj12.addParameter(name='server', value='erick2', format='str')
148 controllerObj.start()
149 controllerObj.start()
149
150
150
151
General Comments 0
You need to be logged in to leave comments. Login now