##// END OF EJS Templates
sin matplotlib de los modulos de claire
José Chávez -
r1075:eb67833bff79
parent child
Show More
@@ -1,12 +1,12
1 #from schainpy.model.data.jrodata import *
1 #from schainpy.model.data.jrodata import *
2 # from schainpy.model.io.jrodataIO import *
2 # from schainpy.model.io.jrodataIO import *
3 # from schainpy.model.proc.jroprocessing import *
3 # from schainpy.model.proc.jroprocessing import *
4 # from schainpy.model.graphics.jroplot import *
4 # from schainpy.model.graphics.jroplot import *
5 # from schainpy.model.utils.jroutils import *
5 # from schainpy.model.utils.jroutils import *
6 # from schainpy.serializer import *
6 # from schainpy.serializer import *
7
7
8 from graphics import *
8 from data import *
9 from data import *
9 from io import *
10 from io import *
10 from proc import *
11 from proc import *
11 from graphics import *
12 from utils import *
12 from utils import * No newline at end of file
@@ -1,468 +1,495
1 import numpy
1 import numpy
2 import datetime
2 import datetime
3 import sys
3 import sys
4 import matplotlib
4 import matplotlib
5
5
6 if 'linux' in sys.platform:
6 if 'linux' in sys.platform:
7 matplotlib.use("TKAgg")
7 matplotlib.use("TkAgg")
8
8
9 if 'darwin' in sys.platform:
9 if 'darwin' in sys.platform:
10 matplotlib.use('TKAgg')
10 matplotlib.use('TKAgg')
11 #Qt4Agg', 'GTK', 'GTKAgg', 'ps', 'agg', 'cairo', 'MacOSX', 'GTKCairo', 'WXAgg', 'template', 'TkAgg', 'GTK3Cairo', 'GTK3Agg', 'svg', 'WebAgg', 'CocoaAgg', 'emf', 'gdk', 'WX'
11 # Qt4Agg', 'GTK', 'GTKAgg', 'ps', 'agg', 'cairo', 'MacOSX', 'GTKCairo', 'WXAgg', 'template', 'TkAgg', 'GTK3Cairo', 'GTK3Agg', 'svg', 'WebAgg', 'CocoaAgg', 'emf', 'gdk', 'WX'
12 import matplotlib.pyplot
12 import matplotlib.pyplot
13
13
14 from mpl_toolkits.axes_grid1 import make_axes_locatable
14 from mpl_toolkits.axes_grid1 import make_axes_locatable
15 from matplotlib.ticker import FuncFormatter, LinearLocator
15 from matplotlib.ticker import FuncFormatter, LinearLocator
16
16
17 ###########################################
17 ###########################################
18 #Actualizacion de las funciones del driver
18 # Actualizacion de las funciones del driver
19 ###########################################
19 ###########################################
20
20
21 # create jro colormap
21 # create jro colormap
22
22
23 jet_values = matplotlib.pyplot.get_cmap("jet", 100)(numpy.arange(100))[10:90]
23 jet_values = matplotlib.pyplot.get_cmap("jet", 100)(numpy.arange(100))[10:90]
24 blu_values = matplotlib.pyplot.get_cmap("seismic_r", 20)(numpy.arange(20))[10:15]
24 blu_values = matplotlib.pyplot.get_cmap(
25 ncmap = matplotlib.colors.LinearSegmentedColormap.from_list("jro", numpy.vstack((blu_values, jet_values)))
25 "seismic_r", 20)(numpy.arange(20))[10:15]
26 ncmap = matplotlib.colors.LinearSegmentedColormap.from_list(
27 "jro", numpy.vstack((blu_values, jet_values)))
26 matplotlib.pyplot.register_cmap(cmap=ncmap)
28 matplotlib.pyplot.register_cmap(cmap=ncmap)
27
29
28 def createFigure(id, wintitle, width, height, facecolor="w", show=True, dpi = 80):
30
31 def createFigure(id, wintitle, width, height, facecolor="w", show=True, dpi=80):
29
32
30 matplotlib.pyplot.ioff()
33 matplotlib.pyplot.ioff()
31
34
32 fig = matplotlib.pyplot.figure(num=id, facecolor=facecolor, figsize=(1.0*width/dpi, 1.0*height/dpi))
35 fig = matplotlib.pyplot.figure(num=id, facecolor=facecolor, figsize=(
36 1.0 * width / dpi, 1.0 * height / dpi))
33 fig.canvas.manager.set_window_title(wintitle)
37 fig.canvas.manager.set_window_title(wintitle)
34 # fig.canvas.manager.resize(width, height)
38 # fig.canvas.manager.resize(width, height)
35 matplotlib.pyplot.ion()
39 matplotlib.pyplot.ion()
36
40
37 if show:
41 if show:
38 matplotlib.pyplot.show()
42 matplotlib.pyplot.show()
39
43
40 return fig
44 return fig
41
45
46
42 def closeFigure(show=False, fig=None):
47 def closeFigure(show=False, fig=None):
43
48
44 # matplotlib.pyplot.ioff()
49 # matplotlib.pyplot.ioff()
45 # matplotlib.pyplot.pause(0)
50 # matplotlib.pyplot.pause(0)
46
51
47 if show:
52 if show:
48 matplotlib.pyplot.show()
53 matplotlib.pyplot.show()
49
54
50 if fig != None:
55 if fig != None:
51 matplotlib.pyplot.close(fig)
56 matplotlib.pyplot.close(fig)
52 # matplotlib.pyplot.pause(0)
57 # matplotlib.pyplot.pause(0)
53 # matplotlib.pyplot.ion()
58 # matplotlib.pyplot.ion()
54
59
55 return
60 return
56
61
57 matplotlib.pyplot.close("all")
62 matplotlib.pyplot.close("all")
58 # matplotlib.pyplot.pause(0)
63 # matplotlib.pyplot.pause(0)
59 # matplotlib.pyplot.ion()
64 # matplotlib.pyplot.ion()
60
65
61 return
66 return
62
67
68
63 def saveFigure(fig, filename):
69 def saveFigure(fig, filename):
64
70
65 # matplotlib.pyplot.ioff()
71 # matplotlib.pyplot.ioff()
66 fig.savefig(filename, dpi=matplotlib.pyplot.gcf().dpi)
72 fig.savefig(filename, dpi=matplotlib.pyplot.gcf().dpi)
67 # matplotlib.pyplot.ion()
73 # matplotlib.pyplot.ion()
68
74
75
69 def clearFigure(fig):
76 def clearFigure(fig):
70
77
71 fig.clf()
78 fig.clf()
72
79
80
73 def setWinTitle(fig, title):
81 def setWinTitle(fig, title):
74
82
75 fig.canvas.manager.set_window_title(title)
83 fig.canvas.manager.set_window_title(title)
76
84
85
77 def setTitle(fig, title):
86 def setTitle(fig, title):
78
87
79 fig.suptitle(title)
88 fig.suptitle(title)
80
89
90
81 def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan, polar=False):
91 def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan, polar=False):
82
92
83 matplotlib.pyplot.ioff()
93 matplotlib.pyplot.ioff()
84 matplotlib.pyplot.figure(fig.number)
94 matplotlib.pyplot.figure(fig.number)
85 axes = matplotlib.pyplot.subplot2grid((nrow, ncol),
95 axes = matplotlib.pyplot.subplot2grid((nrow, ncol),
86 (xpos, ypos),
96 (xpos, ypos),
87 colspan=colspan,
97 colspan=colspan,
88 rowspan=rowspan,
98 rowspan=rowspan,
89 polar=polar)
99 polar=polar)
90
100
91 matplotlib.pyplot.ion()
101 matplotlib.pyplot.ion()
92 return axes
102 return axes
93
103
104
94 def setAxesText(ax, text):
105 def setAxesText(ax, text):
95
106
96 ax.annotate(text,
107 ax.annotate(text,
97 xy = (.1, .99),
108 xy=(.1, .99),
98 xycoords = 'figure fraction',
109 xycoords='figure fraction',
99 horizontalalignment = 'left',
110 horizontalalignment='left',
100 verticalalignment = 'top',
111 verticalalignment='top',
101 fontsize = 10)
112 fontsize=10)
113
102
114
103 def printLabels(ax, xlabel, ylabel, title):
115 def printLabels(ax, xlabel, ylabel, title):
104
116
105 ax.set_xlabel(xlabel, size=11)
117 ax.set_xlabel(xlabel, size=11)
106 ax.set_ylabel(ylabel, size=11)
118 ax.set_ylabel(ylabel, size=11)
107 ax.set_title(title, size=8)
119 ax.set_title(title, size=8)
108
120
121
109 def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='',
122 def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='',
110 ticksize=9, xtick_visible=True, ytick_visible=True,
123 ticksize=9, xtick_visible=True, ytick_visible=True,
111 nxticks=4, nyticks=10,
124 nxticks=4, nyticks=10,
112 grid=None,color='blue'):
125 grid=None, color='blue'):
113
114 """
126 """
115
127
116 Input:
128 Input:
117 grid : None, 'both', 'x', 'y'
129 grid : None, 'both', 'x', 'y'
118 """
130 """
119
131
120 matplotlib.pyplot.ioff()
132 matplotlib.pyplot.ioff()
121
133
122 ax.set_xlim([xmin,xmax])
134 ax.set_xlim([xmin, xmax])
123 ax.set_ylim([ymin,ymax])
135 ax.set_ylim([ymin, ymax])
124
136
125 printLabels(ax, xlabel, ylabel, title)
137 printLabels(ax, xlabel, ylabel, title)
126
138
127 ######################################################
139 ######################################################
128 if (xmax-xmin)<=1:
140 if (xmax - xmin) <= 1:
129 xtickspos = numpy.linspace(xmin,xmax,nxticks)
141 xtickspos = numpy.linspace(xmin, xmax, nxticks)
130 xtickspos = numpy.array([float("%.1f"%i) for i in xtickspos])
142 xtickspos = numpy.array([float("%.1f" % i) for i in xtickspos])
131 ax.set_xticks(xtickspos)
143 ax.set_xticks(xtickspos)
132 else:
144 else:
133 xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
145 xtickspos = numpy.arange(nxticks) * \
146 int((xmax - xmin) / (nxticks)) + int(xmin)
134 # xtickspos = numpy.arange(nxticks)*float(xmax-xmin)/float(nxticks) + int(xmin)
147 # xtickspos = numpy.arange(nxticks)*float(xmax-xmin)/float(nxticks) + int(xmin)
135 ax.set_xticks(xtickspos)
148 ax.set_xticks(xtickspos)
136
149
137 for tick in ax.get_xticklabels():
150 for tick in ax.get_xticklabels():
138 tick.set_visible(xtick_visible)
151 tick.set_visible(xtick_visible)
139
152
140 for tick in ax.xaxis.get_major_ticks():
153 for tick in ax.xaxis.get_major_ticks():
141 tick.label.set_fontsize(ticksize)
154 tick.label.set_fontsize(ticksize)
142
155
143 ######################################################
156 ######################################################
144 for tick in ax.get_yticklabels():
157 for tick in ax.get_yticklabels():
145 tick.set_visible(ytick_visible)
158 tick.set_visible(ytick_visible)
146
159
147 for tick in ax.yaxis.get_major_ticks():
160 for tick in ax.yaxis.get_major_ticks():
148 tick.label.set_fontsize(ticksize)
161 tick.label.set_fontsize(ticksize)
149
162
150 ax.plot(x, y, color=color)
163 ax.plot(x, y, color=color)
151 iplot = ax.lines[-1]
164 iplot = ax.lines[-1]
152
165
153 ######################################################
166 ######################################################
154 if '0.' in matplotlib.__version__[0:2]:
167 if '0.' in matplotlib.__version__[0:2]:
155 print "The matplotlib version has to be updated to 1.1 or newer"
168 print "The matplotlib version has to be updated to 1.1 or newer"
156 return iplot
169 return iplot
157
170
158 if '1.0.' in matplotlib.__version__[0:4]:
171 if '1.0.' in matplotlib.__version__[0:4]:
159 print "The matplotlib version has to be updated to 1.1 or newer"
172 print "The matplotlib version has to be updated to 1.1 or newer"
160 return iplot
173 return iplot
161
174
162 if grid != None:
175 if grid != None:
163 ax.grid(b=True, which='major', axis=grid)
176 ax.grid(b=True, which='major', axis=grid)
164
177
165 matplotlib.pyplot.tight_layout()
178 matplotlib.pyplot.tight_layout()
166
179
167 matplotlib.pyplot.ion()
180 matplotlib.pyplot.ion()
168
181
169 return iplot
182 return iplot
170
183
184
171 def set_linedata(ax, x, y, idline):
185 def set_linedata(ax, x, y, idline):
172
186
173 ax.lines[idline].set_data(x,y)
187 ax.lines[idline].set_data(x, y)
188
174
189
175 def pline(iplot, x, y, xlabel='', ylabel='', title=''):
190 def pline(iplot, x, y, xlabel='', ylabel='', title=''):
176
191
177 ax = iplot.axes
192 ax = iplot.axes
178
193
179 printLabels(ax, xlabel, ylabel, title)
194 printLabels(ax, xlabel, ylabel, title)
180
195
181 set_linedata(ax, x, y, idline=0)
196 set_linedata(ax, x, y, idline=0)
182
197
198
183 def addpline(ax, x, y, color, linestyle, lw):
199 def addpline(ax, x, y, color, linestyle, lw):
184
200
185 ax.plot(x,y,color=color,linestyle=linestyle,lw=lw)
201 ax.plot(x, y, color=color, linestyle=linestyle, lw=lw)
186
202
187
203
188 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax,
204 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax,
189 xlabel='', ylabel='', title='', ticksize = 9,
205 xlabel='', ylabel='', title='', ticksize=9,
190 colormap='jet',cblabel='', cbsize="5%",
206 colormap='jet', cblabel='', cbsize="5%",
191 XAxisAsTime=False):
207 XAxisAsTime=False):
192
208
193 matplotlib.pyplot.ioff()
209 matplotlib.pyplot.ioff()
194
210
195 divider = make_axes_locatable(ax)
211 divider = make_axes_locatable(ax)
196 ax_cb = divider.new_horizontal(size=cbsize, pad=0.05)
212 ax_cb = divider.new_horizontal(size=cbsize, pad=0.05)
197 fig = ax.get_figure()
213 fig = ax.get_figure()
198 fig.add_axes(ax_cb)
214 fig.add_axes(ax_cb)
199
215
200 ax.set_xlim([xmin,xmax])
216 ax.set_xlim([xmin, xmax])
201 ax.set_ylim([ymin,ymax])
217 ax.set_ylim([ymin, ymax])
202
218
203 printLabels(ax, xlabel, ylabel, title)
219 printLabels(ax, xlabel, ylabel, title)
204
220
205 z = numpy.ma.masked_invalid(z)
221 z = numpy.ma.masked_invalid(z)
206 cmap=matplotlib.pyplot.get_cmap(colormap)
222 cmap = matplotlib.pyplot.get_cmap(colormap)
207 cmap.set_bad('black', 1.)
223 cmap.set_bad('black', 1.)
208 imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=cmap)
224 imesh = ax.pcolormesh(x, y, z.T, vmin=zmin, vmax=zmax, cmap=cmap)
209 cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb)
225 cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb)
210 cb.set_label(cblabel)
226 cb.set_label(cblabel)
211
227
212 # for tl in ax_cb.get_yticklabels():
228 # for tl in ax_cb.get_yticklabels():
213 # tl.set_visible(True)
229 # tl.set_visible(True)
214
230
215 for tick in ax.yaxis.get_major_ticks():
231 for tick in ax.yaxis.get_major_ticks():
216 tick.label.set_fontsize(ticksize)
232 tick.label.set_fontsize(ticksize)
217
233
218 for tick in ax.xaxis.get_major_ticks():
234 for tick in ax.xaxis.get_major_ticks():
219 tick.label.set_fontsize(ticksize)
235 tick.label.set_fontsize(ticksize)
220
236
221 for tick in cb.ax.get_yticklabels():
237 for tick in cb.ax.get_yticklabels():
222 tick.set_fontsize(ticksize)
238 tick.set_fontsize(ticksize)
223
239
224 ax_cb.yaxis.tick_right()
240 ax_cb.yaxis.tick_right()
225
241
226 if '0.' in matplotlib.__version__[0:2]:
242 if '0.' in matplotlib.__version__[0:2]:
227 print "The matplotlib version has to be updated to 1.1 or newer"
243 print "The matplotlib version has to be updated to 1.1 or newer"
228 return imesh
244 return imesh
229
245
230 if '1.0.' in matplotlib.__version__[0:4]:
246 if '1.0.' in matplotlib.__version__[0:4]:
231 print "The matplotlib version has to be updated to 1.1 or newer"
247 print "The matplotlib version has to be updated to 1.1 or newer"
232 return imesh
248 return imesh
233
249
234 matplotlib.pyplot.tight_layout()
250 matplotlib.pyplot.tight_layout()
235
251
236 if XAxisAsTime:
252 if XAxisAsTime:
237
253
238 func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
254 def func(x, pos): return ('%s') % (
255 datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
239 ax.xaxis.set_major_formatter(FuncFormatter(func))
256 ax.xaxis.set_major_formatter(FuncFormatter(func))
240 ax.xaxis.set_major_locator(LinearLocator(7))
257 ax.xaxis.set_major_locator(LinearLocator(7))
241
258
242 matplotlib.pyplot.ion()
259 matplotlib.pyplot.ion()
243 return imesh
260 return imesh
244
261
262
245 def pcolor(imesh, z, xlabel='', ylabel='', title=''):
263 def pcolor(imesh, z, xlabel='', ylabel='', title=''):
246
264
247 z = z.T
265 z = z.T
248 ax = imesh.axes
266 ax = imesh.axes
249 printLabels(ax, xlabel, ylabel, title)
267 printLabels(ax, xlabel, ylabel, title)
250 imesh.set_array(z.ravel())
268 imesh.set_array(z.ravel())
251
269
270
252 def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
271 def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
253
272
254 printLabels(ax, xlabel, ylabel, title)
273 printLabels(ax, xlabel, ylabel, title)
255
274
256 ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap))
275 ax.pcolormesh(x, y, z.T, vmin=zmin, vmax=zmax,
276 cmap=matplotlib.pyplot.get_cmap(colormap))
277
257
278
258 def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
279 def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
259
280
260 printLabels(ax, xlabel, ylabel, title)
281 printLabels(ax, xlabel, ylabel, title)
261
282
262 ax.collections.remove(ax.collections[0])
283 ax.collections.remove(ax.collections[0])
263
284
264 z = numpy.ma.masked_invalid(z)
285 z = numpy.ma.masked_invalid(z)
265
286
266 cmap=matplotlib.pyplot.get_cmap(colormap)
287 cmap = matplotlib.pyplot.get_cmap(colormap)
267 cmap.set_bad('black', 1.)
288 cmap.set_bad('black', 1.)
268
289
290 ax.pcolormesh(x, y, z.T, vmin=zmin, vmax=zmax, cmap=cmap)
269
291
270 ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=cmap)
271
292
272 def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
293 def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
273 ticksize=9, xtick_visible=True, ytick_visible=True,
294 ticksize=9, xtick_visible=True, ytick_visible=True,
274 nxticks=4, nyticks=10,
295 nxticks=4, nyticks=10,
275 grid=None):
296 grid=None):
276
277 """
297 """
278
298
279 Input:
299 Input:
280 grid : None, 'both', 'x', 'y'
300 grid : None, 'both', 'x', 'y'
281 """
301 """
282
302
283 matplotlib.pyplot.ioff()
303 matplotlib.pyplot.ioff()
284
304
285 lines = ax.plot(x.T, y)
305 lines = ax.plot(x.T, y)
286 leg = ax.legend(lines, legendlabels, loc='upper right')
306 leg = ax.legend(lines, legendlabels, loc='upper right')
287 leg.get_frame().set_alpha(0.5)
307 leg.get_frame().set_alpha(0.5)
288 ax.set_xlim([xmin,xmax])
308 ax.set_xlim([xmin, xmax])
289 ax.set_ylim([ymin,ymax])
309 ax.set_ylim([ymin, ymax])
290 printLabels(ax, xlabel, ylabel, title)
310 printLabels(ax, xlabel, ylabel, title)
291
311
292 xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
312 xtickspos = numpy.arange(nxticks) * \
313 int((xmax - xmin) / (nxticks)) + int(xmin)
293 ax.set_xticks(xtickspos)
314 ax.set_xticks(xtickspos)
294
315
295 for tick in ax.get_xticklabels():
316 for tick in ax.get_xticklabels():
296 tick.set_visible(xtick_visible)
317 tick.set_visible(xtick_visible)
297
318
298 for tick in ax.xaxis.get_major_ticks():
319 for tick in ax.xaxis.get_major_ticks():
299 tick.label.set_fontsize(ticksize)
320 tick.label.set_fontsize(ticksize)
300
321
301 for tick in ax.get_yticklabels():
322 for tick in ax.get_yticklabels():
302 tick.set_visible(ytick_visible)
323 tick.set_visible(ytick_visible)
303
324
304 for tick in ax.yaxis.get_major_ticks():
325 for tick in ax.yaxis.get_major_ticks():
305 tick.label.set_fontsize(ticksize)
326 tick.label.set_fontsize(ticksize)
306
327
307 iplot = ax.lines[-1]
328 iplot = ax.lines[-1]
308
329
309 if '0.' in matplotlib.__version__[0:2]:
330 if '0.' in matplotlib.__version__[0:2]:
310 print "The matplotlib version has to be updated to 1.1 or newer"
331 print "The matplotlib version has to be updated to 1.1 or newer"
311 return iplot
332 return iplot
312
333
313 if '1.0.' in matplotlib.__version__[0:4]:
334 if '1.0.' in matplotlib.__version__[0:4]:
314 print "The matplotlib version has to be updated to 1.1 or newer"
335 print "The matplotlib version has to be updated to 1.1 or newer"
315 return iplot
336 return iplot
316
337
317 if grid != None:
338 if grid != None:
318 ax.grid(b=True, which='major', axis=grid)
339 ax.grid(b=True, which='major', axis=grid)
319
340
320 matplotlib.pyplot.tight_layout()
341 matplotlib.pyplot.tight_layout()
321
342
322 matplotlib.pyplot.ion()
343 matplotlib.pyplot.ion()
323
344
324 return iplot
345 return iplot
325
346
326
347
327 def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''):
348 def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''):
328
349
329 ax = iplot.axes
350 ax = iplot.axes
330
351
331 printLabels(ax, xlabel, ylabel, title)
352 printLabels(ax, xlabel, ylabel, title)
332
353
333 for i in range(len(ax.lines)):
354 for i in range(len(ax.lines)):
334 line = ax.lines[i]
355 line = ax.lines[i]
335 line.set_data(x[i,:],y)
356 line.set_data(x[i, :], y)
336
357
337 def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
338 ticksize=9, xtick_visible=True, ytick_visible=True,
339 nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None",
340 grid=None, XAxisAsTime=False):
341
358
359 def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
360 ticksize=9, xtick_visible=True, ytick_visible=True,
361 nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None",
362 grid=None, XAxisAsTime=False):
342 """
363 """
343
364
344 Input:
365 Input:
345 grid : None, 'both', 'x', 'y'
366 grid : None, 'both', 'x', 'y'
346 """
367 """
347
368
348 matplotlib.pyplot.ioff()
369 matplotlib.pyplot.ioff()
349
370
350 # lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle)
371 # lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle)
351 lines = ax.plot(x, y.T)
372 lines = ax.plot(x, y.T)
352 # leg = ax.legend(lines, legendlabels, loc=2, bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \
373 # leg = ax.legend(lines, legendlabels, loc=2, bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \
353 # handletextpad=0.5, borderpad=0.5, labelspacing=0.5, borderaxespad=0.)
374 # handletextpad=0.5, borderpad=0.5, labelspacing=0.5, borderaxespad=0.)
354
375
355 leg = ax.legend(lines, legendlabels,
376 leg = ax.legend(lines, legendlabels,
356 loc='upper right', bbox_to_anchor=(1.16, 1), borderaxespad=0)
377 loc='upper right', bbox_to_anchor=(1.16, 1), borderaxespad=0)
357
378
358 for label in leg.get_texts(): label.set_fontsize(9)
379 for label in leg.get_texts():
380 label.set_fontsize(9)
359
381
360 ax.set_xlim([xmin,xmax])
382 ax.set_xlim([xmin, xmax])
361 ax.set_ylim([ymin,ymax])
383 ax.set_ylim([ymin, ymax])
362 printLabels(ax, xlabel, ylabel, title)
384 printLabels(ax, xlabel, ylabel, title)
363
385
364 # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
386 # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
365 # ax.set_xticks(xtickspos)
387 # ax.set_xticks(xtickspos)
366
388
367 for tick in ax.get_xticklabels():
389 for tick in ax.get_xticklabels():
368 tick.set_visible(xtick_visible)
390 tick.set_visible(xtick_visible)
369
391
370 for tick in ax.xaxis.get_major_ticks():
392 for tick in ax.xaxis.get_major_ticks():
371 tick.label.set_fontsize(ticksize)
393 tick.label.set_fontsize(ticksize)
372
394
373 for tick in ax.get_yticklabels():
395 for tick in ax.get_yticklabels():
374 tick.set_visible(ytick_visible)
396 tick.set_visible(ytick_visible)
375
397
376 for tick in ax.yaxis.get_major_ticks():
398 for tick in ax.yaxis.get_major_ticks():
377 tick.label.set_fontsize(ticksize)
399 tick.label.set_fontsize(ticksize)
378
400
379 iplot = ax.lines[-1]
401 iplot = ax.lines[-1]
380
402
381 if '0.' in matplotlib.__version__[0:2]:
403 if '0.' in matplotlib.__version__[0:2]:
382 print "The matplotlib version has to be updated to 1.1 or newer"
404 print "The matplotlib version has to be updated to 1.1 or newer"
383 return iplot
405 return iplot
384
406
385 if '1.0.' in matplotlib.__version__[0:4]:
407 if '1.0.' in matplotlib.__version__[0:4]:
386 print "The matplotlib version has to be updated to 1.1 or newer"
408 print "The matplotlib version has to be updated to 1.1 or newer"
387 return iplot
409 return iplot
388
410
389 if grid != None:
411 if grid != None:
390 ax.grid(b=True, which='major', axis=grid)
412 ax.grid(b=True, which='major', axis=grid)
391
413
392 matplotlib.pyplot.tight_layout()
414 matplotlib.pyplot.tight_layout()
393
415
394 if XAxisAsTime:
416 if XAxisAsTime:
395
417
396 func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
418 def func(x, pos): return ('%s') % (
419 datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
397 ax.xaxis.set_major_formatter(FuncFormatter(func))
420 ax.xaxis.set_major_formatter(FuncFormatter(func))
398 ax.xaxis.set_major_locator(LinearLocator(7))
421 ax.xaxis.set_major_locator(LinearLocator(7))
399
422
400 matplotlib.pyplot.ion()
423 matplotlib.pyplot.ion()
401
424
402 return iplot
425 return iplot
403
426
427
404 def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''):
428 def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''):
405
429
406 ax = iplot.axes
430 ax = iplot.axes
407
431
408 printLabels(ax, xlabel, ylabel, title)
432 printLabels(ax, xlabel, ylabel, title)
409
433
410 for i in range(len(ax.lines)):
434 for i in range(len(ax.lines)):
411 line = ax.lines[i]
435 line = ax.lines[i]
412 line.set_data(x,y[i,:])
436 line.set_data(x, y[i, :])
437
413
438
414 def createPolar(ax, x, y,
439 def createPolar(ax, x, y,
415 xlabel='', ylabel='', title='', ticksize = 9,
440 xlabel='', ylabel='', title='', ticksize=9,
416 colormap='jet',cblabel='', cbsize="5%",
441 colormap='jet', cblabel='', cbsize="5%",
417 XAxisAsTime=False):
442 XAxisAsTime=False):
418
443
419 matplotlib.pyplot.ioff()
444 matplotlib.pyplot.ioff()
420
445
421 ax.plot(x,y,'bo', markersize=5)
446 ax.plot(x, y, 'bo', markersize=5)
422 # ax.set_rmax(90)
447 # ax.set_rmax(90)
423 ax.set_ylim(0,90)
448 ax.set_ylim(0, 90)
424 ax.set_yticks(numpy.arange(0,90,20))
449 ax.set_yticks(numpy.arange(0, 90, 20))
425 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center' ,size='11')
450 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center' ,size='11')
426 # ax.text(0, 50, ylabel, rotation='vertical', va ='center', ha = 'left' ,size='11')
451 # ax.text(0, 50, ylabel, rotation='vertical', va ='center', ha = 'left' ,size='11')
427 # ax.text(100, 100, 'example', ha='left', va='center', rotation='vertical')
452 # ax.text(100, 100, 'example', ha='left', va='center', rotation='vertical')
428 ax.yaxis.labelpad = 40
453 ax.yaxis.labelpad = 40
429 printLabels(ax, xlabel, ylabel, title)
454 printLabels(ax, xlabel, ylabel, title)
430 iplot = ax.lines[-1]
455 iplot = ax.lines[-1]
431
456
432 if '0.' in matplotlib.__version__[0:2]:
457 if '0.' in matplotlib.__version__[0:2]:
433 print "The matplotlib version has to be updated to 1.1 or newer"
458 print "The matplotlib version has to be updated to 1.1 or newer"
434 return iplot
459 return iplot
435
460
436 if '1.0.' in matplotlib.__version__[0:4]:
461 if '1.0.' in matplotlib.__version__[0:4]:
437 print "The matplotlib version has to be updated to 1.1 or newer"
462 print "The matplotlib version has to be updated to 1.1 or newer"
438 return iplot
463 return iplot
439
464
440 # if grid != None:
465 # if grid != None:
441 # ax.grid(b=True, which='major', axis=grid)
466 # ax.grid(b=True, which='major', axis=grid)
442
467
443 matplotlib.pyplot.tight_layout()
468 matplotlib.pyplot.tight_layout()
444
469
445 matplotlib.pyplot.ion()
470 matplotlib.pyplot.ion()
446
471
447
448 return iplot
472 return iplot
449
473
474
450 def polar(iplot, x, y, xlabel='', ylabel='', title=''):
475 def polar(iplot, x, y, xlabel='', ylabel='', title=''):
451
476
452 ax = iplot.axes
477 ax = iplot.axes
453
478
454 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center',size='11')
479 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center',size='11')
455 printLabels(ax, xlabel, ylabel, title)
480 printLabels(ax, xlabel, ylabel, title)
456
481
457 set_linedata(ax, x, y, idline=0)
482 set_linedata(ax, x, y, idline=0)
458
483
484
459 def draw(fig):
485 def draw(fig):
460
486
461 if type(fig) == 'int':
487 if type(fig) == 'int':
462 raise ValueError, "Error drawing: Fig parameter should be a matplotlib figure object figure"
488 raise ValueError, "Error drawing: Fig parameter should be a matplotlib figure object figure"
463
489
464 fig.canvas.draw()
490 fig.canvas.draw()
465
491
492
466 def pause(interval=0.000001):
493 def pause(interval=0.000001):
467
494
468 matplotlib.pyplot.pause(interval)
495 matplotlib.pyplot.pause(interval)
@@ -1,321 +1,331
1 import os, sys
1 import os
2 import sys
2 import glob
3 import glob
3 import fnmatch
4 import fnmatch
4 import datetime
5 import datetime
5 import time
6 import time
6 import re
7 import re
7 import h5py
8 import h5py
8 import numpy
9 import numpy
9 import matplotlib.pyplot as plt
10
10
11 import pylab as plb
12 from scipy.optimize import curve_fit
11 from scipy.optimize import curve_fit
13 from scipy import asarray as ar,exp
12 from scipy import asarray as ar, exp
14 from scipy import stats
13 from scipy import stats
15
14
16 from duplicity.path import Path
15 from duplicity.path import Path
17 from numpy.ma.core import getdata
16 from numpy.ma.core import getdata
18
17
19 SPEED_OF_LIGHT = 299792458
18 SPEED_OF_LIGHT = 299792458
20 SPEED_OF_LIGHT = 3e8
19 SPEED_OF_LIGHT = 3e8
21
20
22 try:
21 try:
23 from gevent import sleep
22 from gevent import sleep
24 except:
23 except:
25 from time import sleep
24 from time import sleep
26
25
27 from schainpy.model.data.jrodata import Spectra
26 from schainpy.model.data.jrodata import Spectra
28 #from schainpy.model.data.BLTRheaderIO import FileHeader, RecordHeader
27 #from schainpy.model.data.BLTRheaderIO import FileHeader, RecordHeader
29 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
28 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
30 #from schainpy.model.io.jroIO_bltr import BLTRReader
29 #from schainpy.model.io.jroIO_bltr import BLTRReader
31 from numpy import imag, shape, NaN
30 from numpy import imag, shape, NaN
32
31
33
32
34 startFp = open('/home/erick/Documents/MIRA35C/20160117/20160117_0000.zspc',"rb")
33 startFp = open(
35
34 '/home/erick/Documents/MIRA35C/20160117/20160117_0000.zspc', "rb")
36
35
37 FILE_HEADER = numpy.dtype([ #HEADER 1024bytes
36
38 ('Hname',numpy.str_,32), #Original file name
37 FILE_HEADER = numpy.dtype([ # HEADER 1024bytes
39 ('Htime',numpy.str_,32), #Date and time when the file was created
38 ('Hname', numpy.str_, 32), # Original file name
40 ('Hoper',numpy.str_,64), #Name of operator who created the file
39 # Date and time when the file was created
41 ('Hplace',numpy.str_,128), #Place where the measurements was carried out
40 ('Htime', numpy.str_, 32),
42 ('Hdescr',numpy.str_,256), #Description of measurements
41 # Name of operator who created the file
43 ('Hdummy',numpy.str_,512), #Reserved space
42 ('Hoper', numpy.str_, 64),
44 #Main chunk
43 # Place where the measurements was carried out
45 ('Msign','<i4'), #Main chunk signature FZKF or NUIG
44 ('Hplace', numpy.str_, 128),
46 ('MsizeData','<i4'), #Size of data block main chunk
45 # Description of measurements
47 #Processing DSP parameters
46 ('Hdescr', numpy.str_, 256),
48 ('PPARsign','<i4'), #PPAR signature
47 ('Hdummy', numpy.str_, 512), # Reserved space
49 ('PPARsize','<i4'), #PPAR size of block
48 # Main chunk
50 ('PPARprf','<i4'), #Pulse repetition frequency
49 ('Msign', '<i4'), # Main chunk signature FZKF or NUIG
51 ('PPARpdr','<i4'), #Pulse duration
50 ('MsizeData', '<i4'), # Size of data block main chunk
52 ('PPARsft','<i4'), #FFT length
51 # Processing DSP parameters
53 ('PPARavc','<i4'), #Number of spectral (in-coherent) averages
52 ('PPARsign', '<i4'), # PPAR signature
54 ('PPARihp','<i4'), #Number of lowest range gate for moment estimation
53 ('PPARsize', '<i4'), # PPAR size of block
55 ('PPARchg','<i4'), #Count for gates for moment estimation
54 ('PPARprf', '<i4'), # Pulse repetition frequency
56 ('PPARpol','<i4'), #switch on/off polarimetric measurements. Should be 1.
55 ('PPARpdr', '<i4'), # Pulse duration
57 #Service DSP parameters
56 ('PPARsft', '<i4'), # FFT length
58 ('SPARatt','<i4'), #STC attenuation on the lowest ranges on/off
57 # Number of spectral (in-coherent) averages
59 ('SPARtx','<i4'), #OBSOLETE
58 ('PPARavc', '<i4'),
60 ('SPARaddGain0','<f4'), #OBSOLETE
59 # Number of lowest range gate for moment estimation
61 ('SPARaddGain1','<f4'), #OBSOLETE
60 ('PPARihp', '<i4'),
62 ('SPARwnd','<i4'), #Debug only. It normal mode it is 0.
61 # Count for gates for moment estimation
63 ('SPARpos','<i4'), #Delay between sync pulse and tx pulse for phase corr, ns
62 ('PPARchg', '<i4'),
64 ('SPARadd','<i4'), #"add to pulse" to compensate for delay between the leading edge of driver pulse and envelope of the RF signal.
63 # switch on/off polarimetric measurements. Should be 1.
65 ('SPARlen','<i4'), #Time for measuring txn pulse phase. OBSOLETE
64 ('PPARpol', '<i4'),
66 ('SPARcal','<i4'), #OBSOLETE
65 # Service DSP parameters
67 ('SPARnos','<i4'), #OBSOLETE
66 # STC attenuation on the lowest ranges on/off
68 ('SPARof0','<i4'), #detection threshold
67 ('SPARatt', '<i4'),
69 ('SPARof1','<i4'), #OBSOLETE
68 ('SPARtx', '<i4'), # OBSOLETE
70 ('SPARswt','<i4'), #2nd moment estimation threshold
69 ('SPARaddGain0', '<f4'), # OBSOLETE
71 ('SPARsum','<i4'), #OBSOLETE
70 ('SPARaddGain1', '<f4'), # OBSOLETE
72 ('SPARosc','<i4'), #flag Oscillosgram mode
71 # Debug only. It normal mode it is 0.
73 ('SPARtst','<i4'), #OBSOLETE
72 ('SPARwnd', '<i4'),
74 ('SPARcor','<i4'), #OBSOLETE
73 # Delay between sync pulse and tx pulse for phase corr, ns
75 ('SPARofs','<i4'), #OBSOLETE
74 ('SPARpos', '<i4'),
76 ('SPARhsn','<i4'), #Hildebrand div noise detection on noise gate
75 # "add to pulse" to compensate for delay between the leading edge of driver pulse and envelope of the RF signal.
77 ('SPARhsa','<f4'), #Hildebrand div noise detection on all gates
76 ('SPARadd', '<i4'),
78 ('SPARcalibPow_M','<f4'), #OBSOLETE
77 # Time for measuring txn pulse phase. OBSOLETE
79 ('SPARcalibSNR_M','<f4'), #OBSOLETE
78 ('SPARlen', '<i4'),
80 ('SPARcalibPow_S','<f4'), #OBSOLETE
79 ('SPARcal', '<i4'), # OBSOLETE
81 ('SPARcalibSNR_S','<f4'), #OBSOLETE
80 ('SPARnos', '<i4'), # OBSOLETE
82 ('SPARrawGate1','<i4'), #Lowest range gate for spectra saving Raw_Gate1 >=5
81 ('SPARof0', '<i4'), # detection threshold
83 ('SPARrawGate2','<i4'), #Number of range gates with atmospheric signal
82 ('SPARof1', '<i4'), # OBSOLETE
84 ('SPARraw','<i4'), #flag - IQ or spectra saving on/off
83 ('SPARswt', '<i4'), # 2nd moment estimation threshold
85 ('SPARprc','<i4'),]) #flag - Moment estimation switched on/off
84 ('SPARsum', '<i4'), # OBSOLETE
86
85 ('SPARosc', '<i4'), # flag Oscillosgram mode
87
86 ('SPARtst', '<i4'), # OBSOLETE
88
87 ('SPARcor', '<i4'), # OBSOLETE
89 self.Hname= None
88 ('SPARofs', '<i4'), # OBSOLETE
90 self.Htime= None
89 # Hildebrand div noise detection on noise gate
91 self.Hoper= None
90 ('SPARhsn', '<i4'),
92 self.Hplace= None
91 # Hildebrand div noise detection on all gates
93 self.Hdescr= None
92 ('SPARhsa', '<f4'),
94 self.Hdummy= None
93 ('SPARcalibPow_M', '<f4'), # OBSOLETE
95
94 ('SPARcalibSNR_M', '<f4'), # OBSOLETE
96 self.Msign=None
95 ('SPARcalibPow_S', '<f4'), # OBSOLETE
97 self.MsizeData=None
96 ('SPARcalibSNR_S', '<f4'), # OBSOLETE
98
97 # Lowest range gate for spectra saving Raw_Gate1 >=5
99 self.PPARsign=None
98 ('SPARrawGate1', '<i4'),
100 self.PPARsize=None
99 # Number of range gates with atmospheric signal
101 self.PPARprf=None
100 ('SPARrawGate2', '<i4'),
102 self.PPARpdr=None
101 # flag - IQ or spectra saving on/off
103 self.PPARsft=None
102 ('SPARraw', '<i4'),
104 self.PPARavc=None
103 ('SPARprc', '<i4'), ]) # flag - Moment estimation switched on/off
105 self.PPARihp=None
104
106 self.PPARchg=None
105
107 self.PPARpol=None
106 self.Hname = None
108 #Service DSP parameters
107 self.Htime = None
109 self.SPARatt=None
108 self.Hoper = None
110 self.SPARtx=None
109 self.Hplace = None
111 self.SPARaddGain0=None
110 self.Hdescr = None
112 self.SPARaddGain1=None
111 self.Hdummy = None
113 self.SPARwnd=None
112
114 self.SPARpos=None
113 self.Msign = None
115 self.SPARadd=None
114 self.MsizeData = None
116 self.SPARlen=None
115
117 self.SPARcal=None
116 self.PPARsign = None
118 self.SPARnos=None
117 self.PPARsize = None
119 self.SPARof0=None
118 self.PPARprf = None
120 self.SPARof1=None
119 self.PPARpdr = None
121 self.SPARswt=None
120 self.PPARsft = None
122 self.SPARsum=None
121 self.PPARavc = None
123 self.SPARosc=None
122 self.PPARihp = None
124 self.SPARtst=None
123 self.PPARchg = None
125 self.SPARcor=None
124 self.PPARpol = None
126 self.SPARofs=None
125 # Service DSP parameters
127 self.SPARhsn=None
126 self.SPARatt = None
128 self.SPARhsa=None
127 self.SPARtx = None
129 self.SPARcalibPow_M=None
128 self.SPARaddGain0 = None
130 self.SPARcalibSNR_M=None
129 self.SPARaddGain1 = None
131 self.SPARcalibPow_S=None
130 self.SPARwnd = None
132 self.SPARcalibSNR_S=None
131 self.SPARpos = None
133 self.SPARrawGate1=None
132 self.SPARadd = None
134 self.SPARrawGate2=None
133 self.SPARlen = None
135 self.SPARraw=None
134 self.SPARcal = None
136 self.SPARprc=None
135 self.SPARnos = None
137
136 self.SPARof0 = None
138
137 self.SPARof1 = None
139
138 self.SPARswt = None
140 header = numpy.fromfile(fp, FILE_HEADER,1)
139 self.SPARsum = None
140 self.SPARosc = None
141 self.SPARtst = None
142 self.SPARcor = None
143 self.SPARofs = None
144 self.SPARhsn = None
145 self.SPARhsa = None
146 self.SPARcalibPow_M = None
147 self.SPARcalibSNR_M = None
148 self.SPARcalibPow_S = None
149 self.SPARcalibSNR_S = None
150 self.SPARrawGate1 = None
151 self.SPARrawGate2 = None
152 self.SPARraw = None
153 self.SPARprc = None
154
155
156 header = numpy.fromfile(fp, FILE_HEADER, 1)
141 ''' numpy.fromfile(file, dtype, count, sep='')
157 ''' numpy.fromfile(file, dtype, count, sep='')
142 file : file or str
158 file : file or str
143 Open file object or filename.
159 Open file object or filename.
144
160
145 dtype : data-type
161 dtype : data-type
146 Data type of the returned array. For binary files, it is used to determine
162 Data type of the returned array. For binary files, it is used to determine
147 the size and byte-order of the items in the file.
163 the size and byte-order of the items in the file.
148
164
149 count : int
165 count : int
150 Number of items to read. -1 means all items (i.e., the complete file).
166 Number of items to read. -1 means all items (i.e., the complete file).
151
167
152 sep : str
168 sep : str
153 Separator between items if file is a text file. Empty ("") separator means
169 Separator between items if file is a text file. Empty ("") separator means
154 the file should be treated as binary. Spaces (" ") in the separator match zero
170 the file should be treated as binary. Spaces (" ") in the separator match zero
155 or more whitespace characters. A separator consisting only of spaces must match
171 or more whitespace characters. A separator consisting only of spaces must match
156 at least one whitespace.
172 at least one whitespace.
157
173
158 '''
174 '''
159
175
160 Hname= str(header['Hname'][0])
176 Hname = str(header['Hname'][0])
161 Htime= str(header['Htime'][0])
177 Htime = str(header['Htime'][0])
162 Hoper= str(header['Hoper'][0])
178 Hoper = str(header['Hoper'][0])
163 Hplace= str(header['Hplace'][0])
179 Hplace = str(header['Hplace'][0])
164 Hdescr= str(header['Hdescr'][0])
180 Hdescr = str(header['Hdescr'][0])
165 Hdummy= str(header['Hdummy'][0])
181 Hdummy = str(header['Hdummy'][0])
166
182
167 Msign=header['Msign'][0]
183 Msign = header['Msign'][0]
168 MsizeData=header['MsizeData'][0]
184 MsizeData = header['MsizeData'][0]
169
185
170 PPARsign=header['PPARsign'][0]
186 PPARsign = header['PPARsign'][0]
171 PPARsize=header['PPARsize'][0]
187 PPARsize = header['PPARsize'][0]
172 PPARprf=header['PPARprf'][0]
188 PPARprf = header['PPARprf'][0]
173 PPARpdr=header['PPARpdr'][0]
189 PPARpdr = header['PPARpdr'][0]
174 PPARsft=header['PPARsft'][0]
190 PPARsft = header['PPARsft'][0]
175 PPARavc=header['PPARavc'][0]
191 PPARavc = header['PPARavc'][0]
176 PPARihp=header['PPARihp'][0]
192 PPARihp = header['PPARihp'][0]
177 PPARchg=header['PPARchg'][0]
193 PPARchg = header['PPARchg'][0]
178 PPARpol=header['PPARpol'][0]
194 PPARpol = header['PPARpol'][0]
179 #Service DSP parameters
195 # Service DSP parameters
180 SPARatt=header['SPARatt'][0]
196 SPARatt = header['SPARatt'][0]
181 SPARtx=header['SPARtx'][0]
197 SPARtx = header['SPARtx'][0]
182 SPARaddGain0=header['SPARaddGain0'][0]
198 SPARaddGain0 = header['SPARaddGain0'][0]
183 SPARaddGain1=header['SPARaddGain1'][0]
199 SPARaddGain1 = header['SPARaddGain1'][0]
184 SPARwnd=header['SPARwnd'][0]
200 SPARwnd = header['SPARwnd'][0]
185 SPARpos=header['SPARpos'][0]
201 SPARpos = header['SPARpos'][0]
186 SPARadd=header['SPARadd'][0]
202 SPARadd = header['SPARadd'][0]
187 SPARlen=header['SPARlen'][0]
203 SPARlen = header['SPARlen'][0]
188 SPARcal=header['SPARcal'][0]
204 SPARcal = header['SPARcal'][0]
189 SPARnos=header['SPARnos'][0]
205 SPARnos = header['SPARnos'][0]
190 SPARof0=header['SPARof0'][0]
206 SPARof0 = header['SPARof0'][0]
191 SPARof1=header['SPARof1'][0]
207 SPARof1 = header['SPARof1'][0]
192 SPARswt=header['SPARswt'][0]
208 SPARswt = header['SPARswt'][0]
193 SPARsum=header['SPARsum'][0]
209 SPARsum = header['SPARsum'][0]
194 SPARosc=header['SPARosc'][0]
210 SPARosc = header['SPARosc'][0]
195 SPARtst=header['SPARtst'][0]
211 SPARtst = header['SPARtst'][0]
196 SPARcor=header['SPARcor'][0]
212 SPARcor = header['SPARcor'][0]
197 SPARofs=header['SPARofs'][0]
213 SPARofs = header['SPARofs'][0]
198 SPARhsn=header['SPARhsn'][0]
214 SPARhsn = header['SPARhsn'][0]
199 SPARhsa=header['SPARhsa'][0]
215 SPARhsa = header['SPARhsa'][0]
200 SPARcalibPow_M=header['SPARcalibPow_M'][0]
216 SPARcalibPow_M = header['SPARcalibPow_M'][0]
201 SPARcalibSNR_M=header['SPARcalibSNR_M'][0]
217 SPARcalibSNR_M = header['SPARcalibSNR_M'][0]
202 SPARcalibPow_S=header['SPARcalibPow_S'][0]
218 SPARcalibPow_S = header['SPARcalibPow_S'][0]
203 SPARcalibSNR_S=header['SPARcalibSNR_S'][0]
219 SPARcalibSNR_S = header['SPARcalibSNR_S'][0]
204 SPARrawGate1=header['SPARrawGate1'][0]
220 SPARrawGate1 = header['SPARrawGate1'][0]
205 SPARrawGate2=header['SPARrawGate2'][0]
221 SPARrawGate2 = header['SPARrawGate2'][0]
206 SPARraw=header['SPARraw'][0]
222 SPARraw = header['SPARraw'][0]
207 SPARprc=header['SPARprc'][0]
223 SPARprc = header['SPARprc'][0]
208
224
209
225
210
226 SRVI_STRUCTURE = numpy.dtype([
211 SRVI_STRUCTURE = numpy.dtype([
227 ('frame_cnt', '<u4'),
212 ('frame_cnt','<u4'),#
228 ('time_t', '<u4'), #
213 ('time_t','<u4'), #
229 ('tpow', '<f4'), #
214 ('tpow','<f4'), #
230 ('npw1', '<f4'), #
215 ('npw1','<f4'), #
231 ('npw2', '<f4'), #
216 ('npw2','<f4'), #
232 ('cpw1', '<f4'), #
217 ('cpw1','<f4'), #
233 ('pcw2', '<f4'), #
218 ('pcw2','<f4'), #
234 ('ps_err', '<u4'), #
219 ('ps_err','<u4'), #
235 ('te_err', '<u4'), #
220 ('te_err','<u4'), #
236 ('rc_err', '<u4'), #
221 ('rc_err','<u4'), #
237 ('grs1', '<u4'), #
222 ('grs1','<u4'), #
238 ('grs2', '<u4'), #
223 ('grs2','<u4'), #
239 ('azipos', '<f4'), #
224 ('azipos','<f4'), #
240 ('azivel', '<f4'), #
225 ('azivel','<f4'), #
241 ('elvpos', '<f4'), #
226 ('elvpos','<f4'), #
242 ('elvvel', '<f4'), #
227 ('elvvel','<f4'), #
243 ('northAngle', '<f4'),
228 ('northAngle','<f4'), #
244 ('microsec', '<u4'), #
229 ('microsec','<u4'), #
245 ('azisetvel', '<f4'), #
230 ('azisetvel','<f4'), #
246 ('elvsetpos', '<f4'), #
231 ('elvsetpos','<f4'), #
247 ('RadarConst', '<f4'), ]) #
232 ('RadarConst','<f4'),]) #
248
233
249 JUMP_STRUCTURE = numpy.dtype([
234 JUMP_STRUCTURE = numpy.dtype([
250 ('jump', '<u140'),
235 ('jump','<u140'),#
251 ('SizeOfDataBlock1', numpy.str_, 32),
236 ('SizeOfDataBlock1',numpy.str_,32),#
252 ('jump', '<i4'),
237 ('jump','<i4'),#
253 ('DataBlockTitleSRVI1', numpy.str_, 32),
238 ('DataBlockTitleSRVI1',numpy.str_,32),#
254 ('SizeOfSRVI1', '<i4'), ])
239 ('SizeOfSRVI1','<i4'),])#
255
240
256
241
257 # frame_cnt=0, time_t= 0, tpow=0, npw1=0, npw2=0,
242
258 # cpw1=0, pcw2=0, ps_err=0, te_err=0, rc_err=0, grs1=0,
243 #frame_cnt=0, time_t= 0, tpow=0, npw1=0, npw2=0,
259 # grs2=0, azipos=0, azivel=0, elvpos=0, elvvel=0, northangle=0,
244 #cpw1=0, pcw2=0, ps_err=0, te_err=0, rc_err=0, grs1=0,
260 # microsec=0, azisetvel=0, elvsetpos=0, RadarConst=0
245 #grs2=0, azipos=0, azivel=0, elvpos=0, elvvel=0, northangle=0,
261
246 #microsec=0, azisetvel=0, elvsetpos=0, RadarConst=0
262
247
248
249 frame_cnt = frame_cnt
263 frame_cnt = frame_cnt
250 dwell = time_t
264 dwell = time_t
251 tpow = tpow
265 tpow = tpow
252 npw1 = npw1
266 npw1 = npw1
253 npw2 = npw2
267 npw2 = npw2
254 cpw1 = cpw1
268 cpw1 = cpw1
255 pcw2 = pcw2
269 pcw2 = pcw2
256 ps_err = ps_err
270 ps_err = ps_err
257 te_err = te_err
271 te_err = te_err
258 rc_err = rc_err
272 rc_err = rc_err
259 grs1 = grs1
273 grs1 = grs1
260 grs2 = grs2
274 grs2 = grs2
261 azipos = azipos
275 azipos = azipos
262 azivel = azivel
276 azivel = azivel
263 elvpos = elvpos
277 elvpos = elvpos
264 elvvel = elvvel
278 elvvel = elvvel
265 northAngle = northAngle
279 northAngle = northAngle
266 microsec = microsec
280 microsec = microsec
267 azisetvel = azisetvel
281 azisetvel = azisetvel
268 elvsetpos = elvsetpos
282 elvsetpos = elvsetpos
269 RadarConst5 = RadarConst
283 RadarConst5 = RadarConst
270
271
284
272
285
273 #print fp
286 # print fp
274 #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.
287 # 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.
275 #startFp = open(fp,"rb") #The method tell() returns the current position of the file read/write pointer within the file.
288 # startFp = open(fp,"rb") #The method tell() returns the current position of the file read/write pointer within the file.
276 #RecCounter=0
289 # RecCounter=0
277 #Off2StartNxtRec=811248
290 # Off2StartNxtRec=811248
278 #print 'OffsetStartHeader ',self.OffsetStartHeader,'RecCounter ', self.RecCounter, 'Off2StartNxtRec ' , self.Off2StartNxtRec
291 # print 'OffsetStartHeader ',self.OffsetStartHeader,'RecCounter ', self.RecCounter, 'Off2StartNxtRec ' , self.Off2StartNxtRec
279 #OffRHeader= self.OffsetStartHeader + self.RecCounter*self.Off2StartNxtRec
292 #OffRHeader= self.OffsetStartHeader + self.RecCounter*self.Off2StartNxtRec
280 #startFp.seek(OffRHeader, os.SEEK_SET)
293 #startFp.seek(OffRHeader, os.SEEK_SET)
281 print 'debe ser 48, RecCounter*811248', self.OffsetStartHeader,self.RecCounter,self.Off2StartNxtRec
294 print 'debe ser 48, RecCounter*811248', self.OffsetStartHeader, self.RecCounter, self.Off2StartNxtRec
282 print 'Posicion del bloque: ',OffRHeader
295 print 'Posicion del bloque: ', OffRHeader
283
296
284 header = numpy.fromfile(startFp,SRVI_STRUCTURE,1)
297 header = numpy.fromfile(startFp, SRVI_STRUCTURE, 1)
285
298
286 self.frame_cnt = header['frame_cnt'][0]#
299 self.frame_cnt = header['frame_cnt'][0]
287 self.time_t = header['frame_cnt'][0] #
300 self.time_t = header['frame_cnt'][0] #
288 self.tpow = header['frame_cnt'][0] #
301 self.tpow = header['frame_cnt'][0] #
289 self.npw1 = header['frame_cnt'][0] #
302 self.npw1 = header['frame_cnt'][0] #
290 self.npw2 = header['frame_cnt'][0] #
303 self.npw2 = header['frame_cnt'][0] #
291 self.cpw1 = header['frame_cnt'][0] #
304 self.cpw1 = header['frame_cnt'][0] #
292 self.pcw2 = header['frame_cnt'][0] #
305 self.pcw2 = header['frame_cnt'][0] #
293 self.ps_err = header['frame_cnt'][0] #
306 self.ps_err = header['frame_cnt'][0] #
294 self.te_err = header['frame_cnt'][0] #
307 self.te_err = header['frame_cnt'][0] #
295 self.rc_err = header['frame_cnt'][0] #
308 self.rc_err = header['frame_cnt'][0] #
296 self.grs1 = header['frame_cnt'][0] #
309 self.grs1 = header['frame_cnt'][0] #
297 self.grs2 = header['frame_cnt'][0] #
310 self.grs2 = header['frame_cnt'][0] #
298 self.azipos = header['frame_cnt'][0] #
311 self.azipos = header['frame_cnt'][0] #
299 self.azivel = header['frame_cnt'][0] #
312 self.azivel = header['frame_cnt'][0] #
300 self.elvpos = header['frame_cnt'][0] #
313 self.elvpos = header['frame_cnt'][0] #
301 self.elvvel = header['frame_cnt'][0] #
314 self.elvvel = header['frame_cnt'][0] #
302 self.northAngle = header['frame_cnt'][0] #
315 self.northAngle = header['frame_cnt'][0] #
303 self.microsec = header['frame_cnt'][0] #
316 self.microsec = header['frame_cnt'][0] #
304 self.azisetvel = header['frame_cnt'][0] #
317 self.azisetvel = header['frame_cnt'][0] #
305 self.elvsetpos = header['frame_cnt'][0] #
318 self.elvsetpos = header['frame_cnt'][0] #
306 self.RadarConst = header['frame_cnt'][0] #
319 self.RadarConst = header['frame_cnt'][0] #
307
320
308
321
309 self.ipp= 0.5*(SPEED_OF_LIGHT/self.PRFhz)
322 self.ipp = 0.5 * (SPEED_OF_LIGHT / self.PRFhz)
310
323
311 self.RHsize = 180+20*self.nChannels
324 self.RHsize = 180 + 20 * self.nChannels
312 self.Datasize= self.nProfiles*self.nChannels*self.nHeights*2*4
325 self.Datasize = self.nProfiles * self.nChannels * self.nHeights * 2 * 4
313 #print 'Datasize',self.Datasize
326 # print 'Datasize',self.Datasize
314 endFp = self.OffsetStartHeader + self.RecCounter*self.Off2StartNxtRec
327 endFp = self.OffsetStartHeader + self.RecCounter * self.Off2StartNxtRec
315
328
316 print '=============================================='
329 print '=============================================='
317
330
318 print '=============================================='
331 print '=============================================='
319
320
321 No newline at end of file
This diff has been collapsed as it changes many lines, (1270 lines changed) Show them Hide them
@@ -1,1154 +1,1182
1 import os, sys
1 import os
2 import sys
2 import glob
3 import glob
3 import fnmatch
4 import fnmatch
4 import datetime
5 import datetime
5 import time
6 import time
6 import re
7 import re
7 import h5py
8 import h5py
8 import numpy
9 import numpy
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 numpy.ma.core import getdata
16 from numpy.ma.core import getdata
17
17
18 SPEED_OF_LIGHT = 299792458
18 SPEED_OF_LIGHT = 299792458
19 SPEED_OF_LIGHT = 3e8
19 SPEED_OF_LIGHT = 3e8
20
20
21 try:
21 try:
22 from gevent import sleep
22 from gevent import sleep
23 except:
23 except:
24 from time import sleep
24 from time import sleep
25
25
26 from schainpy.model.data.jrodata import Spectra
26 from schainpy.model.data.jrodata import Spectra
27 #from schainpy.model.data.BLTRheaderIO import FileHeader, RecordHeader
27 #from schainpy.model.data.BLTRheaderIO import FileHeader, RecordHeader
28 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
28 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
29 #from schainpy.model.io.jroIO_bltr import BLTRReader
29 #from schainpy.model.io.jroIO_bltr import BLTRReader
30 from numpy import imag, shape, NaN
30 from numpy import imag, shape, NaN
31
31
32 from jroIO_base import JRODataReader
32 from jroIO_base import JRODataReader
33
33
34
34
35 class Header(object):
35 class Header(object):
36
36
37 def __init__(self):
37 def __init__(self):
38 raise NotImplementedError
38 raise NotImplementedError
39
39
40
41 def read(self):
40 def read(self):
42
41
43 raise NotImplementedError
42 raise NotImplementedError
44
43
45 def write(self):
44 def write(self):
46
45
47 raise NotImplementedError
46 raise NotImplementedError
48
47
49 def printInfo(self):
48 def printInfo(self):
50
49
51 message = "#"*50 + "\n"
50 message = "#" * 50 + "\n"
52 message += self.__class__.__name__.upper() + "\n"
51 message += self.__class__.__name__.upper() + "\n"
53 message += "#"*50 + "\n"
52 message += "#" * 50 + "\n"
54
53
55 keyList = self.__dict__.keys()
54 keyList = self.__dict__.keys()
56 keyList.sort()
55 keyList.sort()
57
56
58 for key in keyList:
57 for key in keyList:
59 message += "%s = %s" %(key, self.__dict__[key]) + "\n"
58 message += "%s = %s" % (key, self.__dict__[key]) + "\n"
60
59
61 if "size" not in keyList:
60 if "size" not in keyList:
62 attr = getattr(self, "size")
61 attr = getattr(self, "size")
63
64 if attr:
65 message += "%s = %s" %("size", attr) + "\n"
66
67 #print message
68
62
63 if attr:
64 message += "%s = %s" % ("size", attr) + "\n"
69
65
66 # print message
70
67
71
68
69 FILE_STRUCTURE = numpy.dtype([ # HEADER 48bytes
70 ('FileMgcNumber', '<u4'), # 0x23020100
71 # No Of FDT data records in this file (0 or more)
72 ('nFDTdataRecors', '<u4'),
73 ('OffsetStartHeader', '<u4'),
74 ('RadarUnitId', '<u4'),
75 ('SiteName', numpy.str_, 32), # Null terminated
76 ])
72
77
73 FILE_STRUCTURE = numpy.dtype([ #HEADER 48bytes
74 ('FileMgcNumber','<u4'), #0x23020100
75 ('nFDTdataRecors','<u4'), #No Of FDT data records in this file (0 or more)
76 ('OffsetStartHeader','<u4'),
77 ('RadarUnitId','<u4'),
78 ('SiteName',numpy.str_,32), #Null terminated
79 ])
80
78
81 class FileHeaderBLTR(Header):
79 class FileHeaderBLTR(Header):
82
80
83 def __init__(self):
81 def __init__(self):
84
82
85 self.FileMgcNumber= 0 #0x23020100
83 self.FileMgcNumber = 0 # 0x23020100
86 self.nFDTdataRecors=0 #No Of FDT data records in this file (0 or more)
84 # No Of FDT data records in this file (0 or more)
87 self.RadarUnitId= 0
85 self.nFDTdataRecors = 0
88 self.OffsetStartHeader=0
86 self.RadarUnitId = 0
89 self.SiteName= ""
87 self.OffsetStartHeader = 0
88 self.SiteName = ""
90 self.size = 48
89 self.size = 48
91
90
92 def FHread(self, fp):
91 def FHread(self, fp):
93 #try:
92 # try:
94 startFp = open(fp,"rb")
93 startFp = open(fp, "rb")
95
94
96 header = numpy.fromfile(startFp, FILE_STRUCTURE,1)
95 header = numpy.fromfile(startFp, FILE_STRUCTURE, 1)
97
96
98 print ' '
97 print ' '
99 print 'puntero file header', startFp.tell()
98 print 'puntero file header', startFp.tell()
100 print ' '
99 print ' '
101
100
102
103 ''' numpy.fromfile(file, dtype, count, sep='')
101 ''' numpy.fromfile(file, dtype, count, sep='')
104 file : file or str
102 file : file or str
105 Open file object or filename.
103 Open file object or filename.
106
104
107 dtype : data-type
105 dtype : data-type
108 Data type of the returned array. For binary files, it is used to determine
106 Data type of the returned array. For binary files, it is used to determine
109 the size and byte-order of the items in the file.
107 the size and byte-order of the items in the file.
110
108
111 count : int
109 count : int
112 Number of items to read. -1 means all items (i.e., the complete file).
110 Number of items to read. -1 means all items (i.e., the complete file).
113
111
114 sep : str
112 sep : str
115 Separator between items if file is a text file. Empty ("") separator means
113 Separator between items if file is a text file. Empty ("") separator means
116 the file should be treated as binary. Spaces (" ") in the separator match zero
114 the file should be treated as binary. Spaces (" ") in the separator match zero
117 or more whitespace characters. A separator consisting only of spaces must match
115 or more whitespace characters. A separator consisting only of spaces must match
118 at least one whitespace.
116 at least one whitespace.
119
117
120 '''
118 '''
121
119
120 self.FileMgcNumber = hex(header['FileMgcNumber'][0])
121 # No Of FDT data records in this file (0 or more)
122 self.nFDTdataRecors = int(header['nFDTdataRecors'][0])
123 self.RadarUnitId = int(header['RadarUnitId'][0])
124 self.OffsetStartHeader = int(header['OffsetStartHeader'][0])
125 self.SiteName = str(header['SiteName'][0])
126
127 # print 'Numero de bloques', self.nFDTdataRecors
122
128
123
129 if self.size < 48:
124 self.FileMgcNumber= hex(header['FileMgcNumber'][0])
125 self.nFDTdataRecors=int(header['nFDTdataRecors'][0]) #No Of FDT data records in this file (0 or more)
126 self.RadarUnitId= int(header['RadarUnitId'][0])
127 self.OffsetStartHeader= int(header['OffsetStartHeader'][0])
128 self.SiteName= str(header['SiteName'][0])
129
130 #print 'Numero de bloques', self.nFDTdataRecors
131
132
133 if self.size <48:
134 return 0
130 return 0
135
131
136 return 1
132 return 1
137
133
138
139 def write(self, fp):
134 def write(self, fp):
140
135
141 headerTuple = (self.FileMgcNumber,
136 headerTuple = (self.FileMgcNumber,
142 self.nFDTdataRecors,
137 self.nFDTdataRecors,
143 self.RadarUnitId,
138 self.RadarUnitId,
144 self.SiteName,
139 self.SiteName,
145 self.size)
140 self.size)
146
141
147
148 header = numpy.array(headerTuple, FILE_STRUCTURE)
142 header = numpy.array(headerTuple, FILE_STRUCTURE)
149 # numpy.array(object, dtype=None, copy=True, order=None, subok=False, ndmin=0)
143 # numpy.array(object, dtype=None, copy=True, order=None, subok=False, ndmin=0)
150 header.tofile(fp)
144 header.tofile(fp)
151 ''' ndarray.tofile(fid, sep, format) Write array to a file as text or binary (default).
145 ''' ndarray.tofile(fid, sep, format) Write array to a file as text or binary (default).
152
146
153 fid : file or str
147 fid : file or str
154 An open file object, or a string containing a filename.
148 An open file object, or a string containing a filename.
155
149
156 sep : str
150 sep : str
157 Separator between array items for text output. If "" (empty), a binary file is written,
151 Separator between array items for text output. If "" (empty), a binary file is written,
158 equivalent to file.write(a.tobytes()).
152 equivalent to file.write(a.tobytes()).
159
153
160 format : str
154 format : str
161 Format string for text file output. Each entry in the array is formatted to text by
155 Format string for text file output. Each entry in the array is formatted to text by
162 first converting it to the closest Python type, and then using "format" % item.
156 first converting it to the closest Python type, and then using "format" % item.
163
157
164 '''
158 '''
165
166 return 1
167
159
160 return 1
168
161
169
162
163 RECORD_STRUCTURE = numpy.dtype([ # RECORD HEADER 180+20N bytes
164 ('RecMgcNumber', '<u4'), # 0x23030001
165 ('RecCounter', '<u4'), # Record counter(0,1, ...)
166 # Offset to start of next record form start of this record
167 ('Off2StartNxtRec', '<u4'),
168 # Offset to start of data from start of this record
169 ('Off2StartData', '<u4'),
170 # Epoch time stamp of start of acquisition (seconds)
171 ('nUtime', '<i4'),
172 # Millisecond component of time stamp (0,...,999)
173 ('nMilisec', '<u4'),
174 # Experiment tag name (null terminated)
175 ('ExpTagName', numpy.str_, 32),
176 # Experiment comment (null terminated)
177 ('ExpComment', numpy.str_, 32),
178 # Site latitude (from GPS) in degrees (positive implies North)
179 ('SiteLatDegrees', '<f4'),
180 # Site longitude (from GPS) in degrees (positive implies East)
181 ('SiteLongDegrees', '<f4'),
182 # RTC GPS engine status (0=SEEK, 1=LOCK, 2=NOT FITTED, 3=UNAVAILABLE)
183 ('RTCgpsStatus', '<u4'),
184 ('TransmitFrec', '<u4'), # Transmit frequency (Hz)
185 ('ReceiveFrec', '<u4'), # Receive frequency
186 # First local oscillator frequency (Hz)
187 ('FirstOsciFrec', '<u4'),
188 # (0="O", 1="E", 2="linear 1", 3="linear2")
189 ('Polarisation', '<u4'),
190 # Receiver filter settings (0,1,2,3)
191 ('ReceiverFiltSett', '<u4'),
192 # Number of modes in use (1 or 2)
193 ('nModesInUse', '<u4'),
194 # Dual Mode index number for these data (0 or 1)
195 ('DualModeIndex', '<u4'),
196 # Dual Mode range correction for these data (m)
197 ('DualModeRange', '<u4'),
198 # Number of digital channels acquired (2*N)
199 ('nDigChannels', '<u4'),
200 # Sampling resolution (meters)
201 ('SampResolution', '<u4'),
202 # Number of range gates sampled
203 ('nHeights', '<u4'),
204 # Start range of sampling (meters)
205 ('StartRangeSamp', '<u4'),
206 ('PRFhz', '<u4'), # PRF (Hz)
207 ('nCohInt', '<u4'), # Integrations
208 # Number of data points transformed
209 ('nProfiles', '<u4'),
210 # Number of receive beams stored in file (1 or N)
211 ('nChannels', '<u4'),
212 ('nIncohInt', '<u4'), # Number of spectral averages
213 # FFT windowing index (0 = no window)
214 ('FFTwindowingInd', '<u4'),
215 # Beam steer angle (azimuth) in degrees (clockwise from true North)
216 ('BeamAngleAzim', '<f4'),
217 # Beam steer angle (zenith) in degrees (0=> vertical)
218 ('BeamAngleZen', '<f4'),
219 # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
220 ('AntennaCoord0', '<f4'),
221 # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
222 ('AntennaAngl0', '<f4'),
223 # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
224 ('AntennaCoord1', '<f4'),
225 # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
226 ('AntennaAngl1', '<f4'),
227 # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
228 ('AntennaCoord2', '<f4'),
229 # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
230 ('AntennaAngl2', '<f4'),
231 # Receiver phase calibration (degrees) - N values
232 ('RecPhaseCalibr0', '<f4'),
233 # Receiver phase calibration (degrees) - N values
234 ('RecPhaseCalibr1', '<f4'),
235 # Receiver phase calibration (degrees) - N values
236 ('RecPhaseCalibr2', '<f4'),
237 # Receiver amplitude calibration (ratio relative to receiver one) - N values
238 ('RecAmpCalibr0', '<f4'),
239 # Receiver amplitude calibration (ratio relative to receiver one) - N values
240 ('RecAmpCalibr1', '<f4'),
241 # Receiver amplitude calibration (ratio relative to receiver one) - N values
242 ('RecAmpCalibr2', '<f4'),
243 # Receiver gains in dB - N values
244 ('ReceiverGaindB0', '<i4'),
245 # Receiver gains in dB - N values
246 ('ReceiverGaindB1', '<i4'),
247 # Receiver gains in dB - N values
248 ('ReceiverGaindB2', '<i4'),
249 ])
170
250
171
251
172 RECORD_STRUCTURE = numpy.dtype([ #RECORD HEADER 180+20N bytes
252 class RecordHeaderBLTR(Header):
173 ('RecMgcNumber','<u4'), #0x23030001
174 ('RecCounter','<u4'), #Record counter(0,1, ...)
175 ('Off2StartNxtRec','<u4'), #Offset to start of next record form start of this record
176 ('Off2StartData','<u4'), #Offset to start of data from start of this record
177 ('nUtime','<i4'), #Epoch time stamp of start of acquisition (seconds)
178 ('nMilisec','<u4'), #Millisecond component of time stamp (0,...,999)
179 ('ExpTagName',numpy.str_,32), #Experiment tag name (null terminated)
180 ('ExpComment',numpy.str_,32), #Experiment comment (null terminated)
181 ('SiteLatDegrees','<f4'), #Site latitude (from GPS) in degrees (positive implies North)
182 ('SiteLongDegrees','<f4'), #Site longitude (from GPS) in degrees (positive implies East)
183 ('RTCgpsStatus','<u4'), #RTC GPS engine status (0=SEEK, 1=LOCK, 2=NOT FITTED, 3=UNAVAILABLE)
184 ('TransmitFrec','<u4'), #Transmit frequency (Hz)
185 ('ReceiveFrec','<u4'), #Receive frequency
186 ('FirstOsciFrec','<u4'), #First local oscillator frequency (Hz)
187 ('Polarisation','<u4'), #(0="O", 1="E", 2="linear 1", 3="linear2")
188 ('ReceiverFiltSett','<u4'), #Receiver filter settings (0,1,2,3)
189 ('nModesInUse','<u4'), #Number of modes in use (1 or 2)
190 ('DualModeIndex','<u4'), #Dual Mode index number for these data (0 or 1)
191 ('DualModeRange','<u4'), #Dual Mode range correction for these data (m)
192 ('nDigChannels','<u4'), #Number of digital channels acquired (2*N)
193 ('SampResolution','<u4'), #Sampling resolution (meters)
194 ('nHeights','<u4'), #Number of range gates sampled
195 ('StartRangeSamp','<u4'), #Start range of sampling (meters)
196 ('PRFhz','<u4'), #PRF (Hz)
197 ('nCohInt','<u4'), #Integrations
198 ('nProfiles','<u4'), #Number of data points transformed
199 ('nChannels','<u4'), #Number of receive beams stored in file (1 or N)
200 ('nIncohInt','<u4'), #Number of spectral averages
201 ('FFTwindowingInd','<u4'), #FFT windowing index (0 = no window)
202 ('BeamAngleAzim','<f4'), #Beam steer angle (azimuth) in degrees (clockwise from true North)
203 ('BeamAngleZen','<f4'), #Beam steer angle (zenith) in degrees (0=> vertical)
204 ('AntennaCoord0','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
205 ('AntennaAngl0','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
206 ('AntennaCoord1','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
207 ('AntennaAngl1','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
208 ('AntennaCoord2','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
209 ('AntennaAngl2','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
210 ('RecPhaseCalibr0','<f4'), #Receiver phase calibration (degrees) - N values
211 ('RecPhaseCalibr1','<f4'), #Receiver phase calibration (degrees) - N values
212 ('RecPhaseCalibr2','<f4'), #Receiver phase calibration (degrees) - N values
213 ('RecAmpCalibr0','<f4'), #Receiver amplitude calibration (ratio relative to receiver one) - N values
214 ('RecAmpCalibr1','<f4'), #Receiver amplitude calibration (ratio relative to receiver one) - N values
215 ('RecAmpCalibr2','<f4'), #Receiver amplitude calibration (ratio relative to receiver one) - N values
216 ('ReceiverGaindB0','<i4'), #Receiver gains in dB - N values
217 ('ReceiverGaindB1','<i4'), #Receiver gains in dB - N values
218 ('ReceiverGaindB2','<i4'), #Receiver gains in dB - N values
219 ])
220
253
254 def __init__(self, RecMgcNumber=None, RecCounter=0, Off2StartNxtRec=811248,
255 nUtime=0, nMilisec=0, ExpTagName=None,
256 ExpComment=None, SiteLatDegrees=0, SiteLongDegrees=0,
257 RTCgpsStatus=0, TransmitFrec=0, ReceiveFrec=0,
258 FirstOsciFrec=0, Polarisation=0, ReceiverFiltSett=0,
259 nModesInUse=0, DualModeIndex=0, DualModeRange=0,
260 nDigChannels=0, SampResolution=0, nHeights=0,
261 StartRangeSamp=0, PRFhz=0, nCohInt=0,
262 nProfiles=0, nChannels=0, nIncohInt=0,
263 FFTwindowingInd=0, BeamAngleAzim=0, BeamAngleZen=0,
264 AntennaCoord0=0, AntennaCoord1=0, AntennaCoord2=0,
265 RecPhaseCalibr0=0, RecPhaseCalibr1=0, RecPhaseCalibr2=0,
266 RecAmpCalibr0=0, RecAmpCalibr1=0, RecAmpCalibr2=0,
267 AntennaAngl0=0, AntennaAngl1=0, AntennaAngl2=0,
268 ReceiverGaindB0=0, ReceiverGaindB1=0, ReceiverGaindB2=0, Off2StartData=0, OffsetStartHeader=0):
221
269
222 class RecordHeaderBLTR(Header):
270 self.RecMgcNumber = RecMgcNumber # 0x23030001
223
271 self.RecCounter = RecCounter
224 def __init__(self, RecMgcNumber=None, RecCounter= 0, Off2StartNxtRec= 811248,
272 self.Off2StartNxtRec = Off2StartNxtRec
225 nUtime= 0, nMilisec= 0, ExpTagName= None,
226 ExpComment=None, SiteLatDegrees=0, SiteLongDegrees= 0,
227 RTCgpsStatus= 0, TransmitFrec= 0, ReceiveFrec= 0,
228 FirstOsciFrec= 0, Polarisation= 0, ReceiverFiltSett= 0,
229 nModesInUse= 0, DualModeIndex= 0, DualModeRange= 0,
230 nDigChannels= 0, SampResolution= 0, nHeights= 0,
231 StartRangeSamp= 0, PRFhz= 0, nCohInt= 0,
232 nProfiles= 0, nChannels= 0, nIncohInt= 0,
233 FFTwindowingInd= 0, BeamAngleAzim= 0, BeamAngleZen= 0,
234 AntennaCoord0= 0, AntennaCoord1= 0, AntennaCoord2= 0,
235 RecPhaseCalibr0= 0, RecPhaseCalibr1= 0, RecPhaseCalibr2= 0,
236 RecAmpCalibr0= 0, RecAmpCalibr1= 0, RecAmpCalibr2= 0,
237 AntennaAngl0=0, AntennaAngl1=0, AntennaAngl2=0,
238 ReceiverGaindB0= 0, ReceiverGaindB1= 0, ReceiverGaindB2= 0, Off2StartData=0, OffsetStartHeader=0):
239
240 self.RecMgcNumber = RecMgcNumber #0x23030001
241 self.RecCounter = RecCounter
242 self.Off2StartNxtRec = Off2StartNxtRec
243 self.Off2StartData = Off2StartData
273 self.Off2StartData = Off2StartData
244 self.nUtime = nUtime
274 self.nUtime = nUtime
245 self.nMilisec = nMilisec
275 self.nMilisec = nMilisec
246 self.ExpTagName = ExpTagName
276 self.ExpTagName = ExpTagName
247 self.ExpComment = ExpComment
277 self.ExpComment = ExpComment
248 self.SiteLatDegrees = SiteLatDegrees
278 self.SiteLatDegrees = SiteLatDegrees
249 self.SiteLongDegrees = SiteLongDegrees
279 self.SiteLongDegrees = SiteLongDegrees
250 self.RTCgpsStatus = RTCgpsStatus
280 self.RTCgpsStatus = RTCgpsStatus
251 self.TransmitFrec = TransmitFrec
281 self.TransmitFrec = TransmitFrec
252 self.ReceiveFrec = ReceiveFrec
282 self.ReceiveFrec = ReceiveFrec
253 self.FirstOsciFrec = FirstOsciFrec
283 self.FirstOsciFrec = FirstOsciFrec
254 self.Polarisation = Polarisation
284 self.Polarisation = Polarisation
255 self.ReceiverFiltSett = ReceiverFiltSett
285 self.ReceiverFiltSett = ReceiverFiltSett
256 self.nModesInUse = nModesInUse
286 self.nModesInUse = nModesInUse
257 self.DualModeIndex = DualModeIndex
287 self.DualModeIndex = DualModeIndex
258 self.DualModeRange = DualModeRange
288 self.DualModeRange = DualModeRange
259 self.nDigChannels = nDigChannels
289 self.nDigChannels = nDigChannels
260 self.SampResolution = SampResolution
290 self.SampResolution = SampResolution
261 self.nHeights = nHeights
291 self.nHeights = nHeights
262 self.StartRangeSamp = StartRangeSamp
292 self.StartRangeSamp = StartRangeSamp
263 self.PRFhz = PRFhz
293 self.PRFhz = PRFhz
264 self.nCohInt = nCohInt
294 self.nCohInt = nCohInt
265 self.nProfiles = nProfiles
295 self.nProfiles = nProfiles
266 self.nChannels = nChannels
296 self.nChannels = nChannels
267 self.nIncohInt = nIncohInt
297 self.nIncohInt = nIncohInt
268 self.FFTwindowingInd = FFTwindowingInd
298 self.FFTwindowingInd = FFTwindowingInd
269 self.BeamAngleAzim = BeamAngleAzim
299 self.BeamAngleAzim = BeamAngleAzim
270 self.BeamAngleZen = BeamAngleZen
300 self.BeamAngleZen = BeamAngleZen
271 self.AntennaCoord0 = AntennaCoord0
301 self.AntennaCoord0 = AntennaCoord0
272 self.AntennaAngl0 = AntennaAngl0
302 self.AntennaAngl0 = AntennaAngl0
273 self.AntennaAngl1 = AntennaAngl1
303 self.AntennaAngl1 = AntennaAngl1
274 self.AntennaAngl2 = AntennaAngl2
304 self.AntennaAngl2 = AntennaAngl2
275 self.AntennaCoord1 = AntennaCoord1
305 self.AntennaCoord1 = AntennaCoord1
276 self.AntennaCoord2 = AntennaCoord2
306 self.AntennaCoord2 = AntennaCoord2
277 self.RecPhaseCalibr0 = RecPhaseCalibr0
307 self.RecPhaseCalibr0 = RecPhaseCalibr0
278 self.RecPhaseCalibr1 = RecPhaseCalibr1
308 self.RecPhaseCalibr1 = RecPhaseCalibr1
279 self.RecPhaseCalibr2 = RecPhaseCalibr2
309 self.RecPhaseCalibr2 = RecPhaseCalibr2
280 self.RecAmpCalibr0 = RecAmpCalibr0
310 self.RecAmpCalibr0 = RecAmpCalibr0
281 self.RecAmpCalibr1 = RecAmpCalibr1
311 self.RecAmpCalibr1 = RecAmpCalibr1
282 self.RecAmpCalibr2 = RecAmpCalibr2
312 self.RecAmpCalibr2 = RecAmpCalibr2
283 self.ReceiverGaindB0 = ReceiverGaindB0
313 self.ReceiverGaindB0 = ReceiverGaindB0
284 self.ReceiverGaindB1 = ReceiverGaindB1
314 self.ReceiverGaindB1 = ReceiverGaindB1
285 self.ReceiverGaindB2 = ReceiverGaindB2
315 self.ReceiverGaindB2 = ReceiverGaindB2
286 self.OffsetStartHeader = 48
316 self.OffsetStartHeader = 48
287
317
288
289
290 def RHread(self, fp):
318 def RHread(self, fp):
291 #print fp
319 # print fp
292 #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.
320 # 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(fp,"rb") #The method tell() returns the current position of the file read/write pointer within the file.
321 # The method tell() returns the current position of the file read/write pointer within the file.
294 #RecCounter=0
322 startFp = open(fp, "rb")
295 #Off2StartNxtRec=811248
323 # RecCounter=0
296 OffRHeader= self.OffsetStartHeader + self.RecCounter*self.Off2StartNxtRec
324 # Off2StartNxtRec=811248
325 OffRHeader = self.OffsetStartHeader + self.RecCounter * self.Off2StartNxtRec
297 print ' '
326 print ' '
298 print 'puntero Record Header', startFp.tell()
327 print 'puntero Record Header', startFp.tell()
299 print ' '
328 print ' '
300
329
301
302 startFp.seek(OffRHeader, os.SEEK_SET)
330 startFp.seek(OffRHeader, os.SEEK_SET)
303
331
304 print ' '
332 print ' '
305 print 'puntero Record Header con seek', startFp.tell()
333 print 'puntero Record Header con seek', startFp.tell()
306 print ' '
334 print ' '
307
335
308 #print 'Posicion del bloque: ',OffRHeader
336 # print 'Posicion del bloque: ',OffRHeader
309
337
310 header = numpy.fromfile(startFp,RECORD_STRUCTURE,1)
338 header = numpy.fromfile(startFp, RECORD_STRUCTURE, 1)
311
339
312 print ' '
340 print ' '
313 print 'puntero Record Header con seek', startFp.tell()
341 print 'puntero Record Header con seek', startFp.tell()
314 print ' '
342 print ' '
315
343
316 print ' '
344 print ' '
317 #
345 #
318 #print 'puntero Record Header despues de seek', header.tell()
346 # print 'puntero Record Header despues de seek', header.tell()
319 print ' '
347 print ' '
320
348
321 self.RecMgcNumber = hex(header['RecMgcNumber'][0]) #0x23030001
349 self.RecMgcNumber = hex(header['RecMgcNumber'][0]) # 0x23030001
322 self.RecCounter = int(header['RecCounter'][0])
350 self.RecCounter = int(header['RecCounter'][0])
323 self.Off2StartNxtRec = int(header['Off2StartNxtRec'][0])
351 self.Off2StartNxtRec = int(header['Off2StartNxtRec'][0])
324 self.Off2StartData = int(header['Off2StartData'][0])
352 self.Off2StartData = int(header['Off2StartData'][0])
325 self.nUtime = header['nUtime'][0]
353 self.nUtime = header['nUtime'][0]
326 self.nMilisec = header['nMilisec'][0]
354 self.nMilisec = header['nMilisec'][0]
327 self.ExpTagName = str(header['ExpTagName'][0])
355 self.ExpTagName = str(header['ExpTagName'][0])
328 self.ExpComment = str(header['ExpComment'][0])
356 self.ExpComment = str(header['ExpComment'][0])
329 self.SiteLatDegrees = header['SiteLatDegrees'][0]
357 self.SiteLatDegrees = header['SiteLatDegrees'][0]
330 self.SiteLongDegrees = header['SiteLongDegrees'][0]
358 self.SiteLongDegrees = header['SiteLongDegrees'][0]
331 self.RTCgpsStatus = header['RTCgpsStatus'][0]
359 self.RTCgpsStatus = header['RTCgpsStatus'][0]
332 self.TransmitFrec = header['TransmitFrec'][0]
360 self.TransmitFrec = header['TransmitFrec'][0]
333 self.ReceiveFrec = header['ReceiveFrec'][0]
361 self.ReceiveFrec = header['ReceiveFrec'][0]
334 self.FirstOsciFrec = header['FirstOsciFrec'][0]
362 self.FirstOsciFrec = header['FirstOsciFrec'][0]
335 self.Polarisation = header['Polarisation'][0]
363 self.Polarisation = header['Polarisation'][0]
336 self.ReceiverFiltSett = header['ReceiverFiltSett'][0]
364 self.ReceiverFiltSett = header['ReceiverFiltSett'][0]
337 self.nModesInUse = header['nModesInUse'][0]
365 self.nModesInUse = header['nModesInUse'][0]
338 self.DualModeIndex = header['DualModeIndex'][0]
366 self.DualModeIndex = header['DualModeIndex'][0]
339 self.DualModeRange = header['DualModeRange'][0]
367 self.DualModeRange = header['DualModeRange'][0]
340 self.nDigChannels = header['nDigChannels'][0]
368 self.nDigChannels = header['nDigChannels'][0]
341 self.SampResolution = header['SampResolution'][0]
369 self.SampResolution = header['SampResolution'][0]
342 self.nHeights = header['nHeights'][0]
370 self.nHeights = header['nHeights'][0]
343 self.StartRangeSamp = header['StartRangeSamp'][0]
371 self.StartRangeSamp = header['StartRangeSamp'][0]
344 self.PRFhz = header['PRFhz'][0]
372 self.PRFhz = header['PRFhz'][0]
345 self.nCohInt = header['nCohInt'][0]
373 self.nCohInt = header['nCohInt'][0]
346 self.nProfiles = header['nProfiles'][0]
374 self.nProfiles = header['nProfiles'][0]
347 self.nChannels = header['nChannels'][0]
375 self.nChannels = header['nChannels'][0]
348 self.nIncohInt = header['nIncohInt'][0]
376 self.nIncohInt = header['nIncohInt'][0]
349 self.FFTwindowingInd = header['FFTwindowingInd'][0]
377 self.FFTwindowingInd = header['FFTwindowingInd'][0]
350 self.BeamAngleAzim = header['BeamAngleAzim'][0]
378 self.BeamAngleAzim = header['BeamAngleAzim'][0]
351 self.BeamAngleZen = header['BeamAngleZen'][0]
379 self.BeamAngleZen = header['BeamAngleZen'][0]
352 self.AntennaCoord0 = header['AntennaCoord0'][0]
380 self.AntennaCoord0 = header['AntennaCoord0'][0]
353 self.AntennaAngl0 = header['AntennaAngl0'][0]
381 self.AntennaAngl0 = header['AntennaAngl0'][0]
354 self.AntennaCoord1 = header['AntennaCoord1'][0]
382 self.AntennaCoord1 = header['AntennaCoord1'][0]
355 self.AntennaAngl1 = header['AntennaAngl1'][0]
383 self.AntennaAngl1 = header['AntennaAngl1'][0]
356 self.AntennaCoord2 = header['AntennaCoord2'][0]
384 self.AntennaCoord2 = header['AntennaCoord2'][0]
357 self.AntennaAngl2 = header['AntennaAngl2'][0]
385 self.AntennaAngl2 = header['AntennaAngl2'][0]
358 self.RecPhaseCalibr0 = header['RecPhaseCalibr0'][0]
386 self.RecPhaseCalibr0 = header['RecPhaseCalibr0'][0]
359 self.RecPhaseCalibr1 = header['RecPhaseCalibr1'][0]
387 self.RecPhaseCalibr1 = header['RecPhaseCalibr1'][0]
360 self.RecPhaseCalibr2 = header['RecPhaseCalibr2'][0]
388 self.RecPhaseCalibr2 = header['RecPhaseCalibr2'][0]
361 self.RecAmpCalibr0 = header['RecAmpCalibr0'][0]
389 self.RecAmpCalibr0 = header['RecAmpCalibr0'][0]
362 self.RecAmpCalibr1 = header['RecAmpCalibr1'][0]
390 self.RecAmpCalibr1 = header['RecAmpCalibr1'][0]
363 self.RecAmpCalibr2 = header['RecAmpCalibr2'][0]
391 self.RecAmpCalibr2 = header['RecAmpCalibr2'][0]
364 self.ReceiverGaindB0 = header['ReceiverGaindB0'][0]
392 self.ReceiverGaindB0 = header['ReceiverGaindB0'][0]
365 self.ReceiverGaindB1 = header['ReceiverGaindB1'][0]
393 self.ReceiverGaindB1 = header['ReceiverGaindB1'][0]
366 self.ReceiverGaindB2 = header['ReceiverGaindB2'][0]
394 self.ReceiverGaindB2 = header['ReceiverGaindB2'][0]
367
395
368 self.ipp= 0.5*(SPEED_OF_LIGHT/self.PRFhz)
396 self.ipp = 0.5 * (SPEED_OF_LIGHT / self.PRFhz)
369
397
370 self.RHsize = 180+20*self.nChannels
398 self.RHsize = 180 + 20 * self.nChannels
371 self.Datasize= self.nProfiles*self.nChannels*self.nHeights*2*4
399 self.Datasize = self.nProfiles * self.nChannels * self.nHeights * 2 * 4
372 #print 'Datasize',self.Datasize
400 # print 'Datasize',self.Datasize
373 endFp = self.OffsetStartHeader + self.RecCounter*self.Off2StartNxtRec
401 endFp = self.OffsetStartHeader + self.RecCounter * self.Off2StartNxtRec
374
402
375 print '=============================================='
403 print '=============================================='
376 print 'RecMgcNumber ',self.RecMgcNumber
404 print 'RecMgcNumber ', self.RecMgcNumber
377 print 'RecCounter ',self.RecCounter
405 print 'RecCounter ', self.RecCounter
378 print 'Off2StartNxtRec ',self.Off2StartNxtRec
406 print 'Off2StartNxtRec ', self.Off2StartNxtRec
379 print 'Off2StartData ',self.Off2StartData
407 print 'Off2StartData ', self.Off2StartData
380 print 'Range Resolution ',self.SampResolution
408 print 'Range Resolution ', self.SampResolution
381 print 'First Height ',self.StartRangeSamp
409 print 'First Height ', self.StartRangeSamp
382 print 'PRF (Hz) ',self.PRFhz
410 print 'PRF (Hz) ', self.PRFhz
383 print 'Heights (K) ',self.nHeights
411 print 'Heights (K) ', self.nHeights
384 print 'Channels (N) ',self.nChannels
412 print 'Channels (N) ', self.nChannels
385 print 'Profiles (J) ',self.nProfiles
413 print 'Profiles (J) ', self.nProfiles
386 print 'iCoh ',self.nCohInt
414 print 'iCoh ', self.nCohInt
387 print 'iInCoh ',self.nIncohInt
415 print 'iInCoh ', self.nIncohInt
388 print 'BeamAngleAzim ',self.BeamAngleAzim
416 print 'BeamAngleAzim ', self.BeamAngleAzim
389 print 'BeamAngleZen ',self.BeamAngleZen
417 print 'BeamAngleZen ', self.BeamAngleZen
390
418
391 #print 'ModoEnUso ',self.DualModeIndex
419 # print 'ModoEnUso ',self.DualModeIndex
392 #print 'UtcTime ',self.nUtime
420 # print 'UtcTime ',self.nUtime
393 #print 'MiliSec ',self.nMilisec
421 # print 'MiliSec ',self.nMilisec
394 #print 'Exp TagName ',self.ExpTagName
422 # print 'Exp TagName ',self.ExpTagName
395 #print 'Exp Comment ',self.ExpComment
423 # print 'Exp Comment ',self.ExpComment
396 #print 'FFT Window Index ',self.FFTwindowingInd
424 # print 'FFT Window Index ',self.FFTwindowingInd
397 #print 'N Dig. Channels ',self.nDigChannels
425 # print 'N Dig. Channels ',self.nDigChannels
398 print 'Size de bloque ',self.RHsize
426 print 'Size de bloque ', self.RHsize
399 print 'DataSize ',self.Datasize
427 print 'DataSize ', self.Datasize
400 print 'BeamAngleAzim ',self.BeamAngleAzim
428 print 'BeamAngleAzim ', self.BeamAngleAzim
401 #print 'AntennaCoord0 ',self.AntennaCoord0
429 # print 'AntennaCoord0 ',self.AntennaCoord0
402 #print 'AntennaAngl0 ',self.AntennaAngl0
430 # print 'AntennaAngl0 ',self.AntennaAngl0
403 #print 'AntennaCoord1 ',self.AntennaCoord1
431 # print 'AntennaCoord1 ',self.AntennaCoord1
404 #print 'AntennaAngl1 ',self.AntennaAngl1
432 # print 'AntennaAngl1 ',self.AntennaAngl1
405 #print 'AntennaCoord2 ',self.AntennaCoord2
433 # print 'AntennaCoord2 ',self.AntennaCoord2
406 #print 'AntennaAngl2 ',self.AntennaAngl2
434 # print 'AntennaAngl2 ',self.AntennaAngl2
407 print 'RecPhaseCalibr0 ',self.RecPhaseCalibr0
435 print 'RecPhaseCalibr0 ', self.RecPhaseCalibr0
408 print 'RecPhaseCalibr1 ',self.RecPhaseCalibr1
436 print 'RecPhaseCalibr1 ', self.RecPhaseCalibr1
409 print 'RecPhaseCalibr2 ',self.RecPhaseCalibr2
437 print 'RecPhaseCalibr2 ', self.RecPhaseCalibr2
410 print 'RecAmpCalibr0 ',self.RecAmpCalibr0
438 print 'RecAmpCalibr0 ', self.RecAmpCalibr0
411 print 'RecAmpCalibr1 ',self.RecAmpCalibr1
439 print 'RecAmpCalibr1 ', self.RecAmpCalibr1
412 print 'RecAmpCalibr2 ',self.RecAmpCalibr2
440 print 'RecAmpCalibr2 ', self.RecAmpCalibr2
413 print 'ReceiverGaindB0 ',self.ReceiverGaindB0
441 print 'ReceiverGaindB0 ', self.ReceiverGaindB0
414 print 'ReceiverGaindB1 ',self.ReceiverGaindB1
442 print 'ReceiverGaindB1 ', self.ReceiverGaindB1
415 print 'ReceiverGaindB2 ',self.ReceiverGaindB2
443 print 'ReceiverGaindB2 ', self.ReceiverGaindB2
416 print '=============================================='
444 print '=============================================='
417
445
418 if OffRHeader > endFp:
446 if OffRHeader > endFp:
419 sys.stderr.write("Warning %s: Size value read from System Header is lower than it has to be\n" %fp)
447 sys.stderr.write(
448 "Warning %s: Size value read from System Header is lower than it has to be\n" % fp)
420 return 0
449 return 0
421
450
422 if OffRHeader < endFp:
451 if OffRHeader < endFp:
423 sys.stderr.write("Warning %s: Size value read from System Header size is greater than it has to be\n" %fp)
452 sys.stderr.write(
453 "Warning %s: Size value read from System Header size is greater than it has to be\n" % fp)
424 return 0
454 return 0
425
455
426 return 1
456 return 1
427
457
428
458
429 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODataReader):
459 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODataReader):
430
460
431 path = None
461 path = None
432 startDate = None
462 startDate = None
433 endDate = None
463 endDate = None
434 startTime = None
464 startTime = None
435 endTime = None
465 endTime = None
436 walk = None
466 walk = None
437 isConfig = False
467 isConfig = False
438
468
439
469 fileList = None
440 fileList= None
470
441
471 # metadata
442 #metadata
472 TimeZone = None
443 TimeZone= None
473 Interval = None
444 Interval= None
474 heightList = None
445 heightList= None
475
446
476 # data
447 #data
477 data = None
448 data= None
478 utctime = None
449 utctime= None
479
450
451
452
453 def __init__(self, **kwargs):
480 def __init__(self, **kwargs):
454
481
455 #Eliminar de la base la herencia
482 # Eliminar de la base la herencia
456 ProcessingUnit.__init__(self, **kwargs)
483 ProcessingUnit.__init__(self, **kwargs)
457
484
458 #self.isConfig = False
485 #self.isConfig = False
459
486
460 #self.pts2read_SelfSpectra = 0
487 #self.pts2read_SelfSpectra = 0
461 #self.pts2read_CrossSpectra = 0
488 #self.pts2read_CrossSpectra = 0
462 #self.pts2read_DCchannels = 0
489 #self.pts2read_DCchannels = 0
463 #self.datablock = None
490 #self.datablock = None
464 self.utc = None
491 self.utc = None
465 self.ext = ".fdt"
492 self.ext = ".fdt"
466 self.optchar = "P"
493 self.optchar = "P"
467 self.fpFile=None
494 self.fpFile = None
468 self.fp = None
495 self.fp = None
469 self.BlockCounter=0
496 self.BlockCounter = 0
470 self.dtype = None
497 self.dtype = None
471 self.fileSizeByHeader = None
498 self.fileSizeByHeader = None
472 self.filenameList = []
499 self.filenameList = []
473 self.fileSelector = 0
500 self.fileSelector = 0
474 self.Off2StartNxtRec=0
501 self.Off2StartNxtRec = 0
475 self.RecCounter=0
502 self.RecCounter = 0
476 self.flagNoMoreFiles = 0
503 self.flagNoMoreFiles = 0
477 self.data_spc=None
504 self.data_spc = None
478 self.data_cspc=None
505 self.data_cspc = None
479 self.data_output=None
506 self.data_output = None
480 self.path = None
507 self.path = None
481 self.OffsetStartHeader=0
508 self.OffsetStartHeader = 0
482 self.Off2StartData=0
509 self.Off2StartData = 0
483 self.ipp = 0
510 self.ipp = 0
484 self.nFDTdataRecors=0
511 self.nFDTdataRecors = 0
485 self.blocksize = 0
512 self.blocksize = 0
486 self.dataOut = Spectra()
513 self.dataOut = Spectra()
487 self.profileIndex = 1 #Always
514 self.profileIndex = 1 # Always
488 self.dataOut.flagNoData=False
515 self.dataOut.flagNoData = False
489 self.dataOut.nRdPairs = 0
516 self.dataOut.nRdPairs = 0
490 self.dataOut.pairsList = []
517 self.dataOut.pairsList = []
491 self.dataOut.data_spc=None
518 self.dataOut.data_spc = None
492 self.dataOut.noise=[]
519 self.dataOut.noise = []
493 self.dataOut.velocityX=[]
520 self.dataOut.velocityX = []
494 self.dataOut.velocityY=[]
521 self.dataOut.velocityY = []
495 self.dataOut.velocityV=[]
522 self.dataOut.velocityV = []
496
497
498
523
499 def Files2Read(self, fp):
524 def Files2Read(self, fp):
500 '''
525 '''
501 Function that indicates the number of .fdt files that exist in the folder to be read.
526 Function that indicates the number of .fdt files that exist in the folder to be read.
502 It also creates an organized list with the names of the files to read.
527 It also creates an organized list with the names of the files to read.
503 '''
528 '''
504 #self.__checkPath()
529 # self.__checkPath()
505
530
506 ListaData=os.listdir(fp) #Gets the list of files within the fp address
531 # Gets the list of files within the fp address
507 ListaData=sorted(ListaData) #Sort the list of files from least to largest by names
532 ListaData = os.listdir(fp)
508 nFiles=0 #File Counter
533 # Sort the list of files from least to largest by names
509 FileList=[] #A list is created that will contain the .fdt files
534 ListaData = sorted(ListaData)
510 for IndexFile in ListaData :
535 nFiles = 0 # File Counter
511 if '.fdt' in IndexFile:
536 FileList = [] # A list is created that will contain the .fdt files
537 for IndexFile in ListaData:
538 if '.fdt' in IndexFile:
512 FileList.append(IndexFile)
539 FileList.append(IndexFile)
513 nFiles+=1
540 nFiles += 1
514
541
515 #print 'Files2Read'
542 # print 'Files2Read'
516 #print 'Existen '+str(nFiles)+' archivos .fdt'
543 # print 'Existen '+str(nFiles)+' archivos .fdt'
517
544
518 self.filenameList=FileList #List of files from least to largest by names
545 self.filenameList = FileList # List of files from least to largest by names
519
546
520
521 def run(self, **kwargs):
547 def run(self, **kwargs):
522 '''
548 '''
523 This method will be the one that will initiate the data entry, will be called constantly.
549 This method will be the one that will initiate the data entry, will be called constantly.
524 You should first verify that your Setup () is set up and then continue to acquire
550 You should first verify that your Setup () is set up and then continue to acquire
525 the data to be processed with getData ().
551 the data to be processed with getData ().
526 '''
552 '''
527 if not self.isConfig:
553 if not self.isConfig:
528 self.setup(**kwargs)
554 self.setup(**kwargs)
529 self.isConfig = True
555 self.isConfig = True
530
556
531 self.getData()
557 self.getData()
532 #print 'running'
558 # print 'running'
533
559
534
535 def setup(self, path=None,
560 def setup(self, path=None,
536 startDate=None,
561 startDate=None,
537 endDate=None,
562 endDate=None,
538 startTime=None,
563 startTime=None,
539 endTime=None,
564 endTime=None,
540 walk=True,
565 walk=True,
541 timezone='utc',
566 timezone='utc',
542 code = None,
567 code=None,
543 online=False,
568 online=False,
544 ReadMode=None,
569 ReadMode=None,
545 **kwargs):
570 **kwargs):
546
571
547 self.isConfig = True
572 self.isConfig = True
548
573
549 self.path=path
574 self.path = path
550 self.startDate=startDate
575 self.startDate = startDate
551 self.endDate=endDate
576 self.endDate = endDate
552 self.startTime=startTime
577 self.startTime = startTime
553 self.endTime=endTime
578 self.endTime = endTime
554 self.walk=walk
579 self.walk = walk
555 self.ReadMode=int(ReadMode)
580 self.ReadMode = int(ReadMode)
556
581
557 pass
582 pass
558
583
559
560 def getData(self):
584 def getData(self):
561 '''
585 '''
562 Before starting this function, you should check that there is still an unread file,
586 Before starting this function, you should check that there is still an unread file,
563 If there are still blocks to read or if the data block is empty.
587 If there are still blocks to read or if the data block is empty.
564
588
565 You should call the file "read".
589 You should call the file "read".
566
590
567 '''
591 '''
568
592
569 if self.flagNoMoreFiles:
593 if self.flagNoMoreFiles:
570 self.dataOut.flagNoData = True
594 self.dataOut.flagNoData = True
571 print 'NoData se vuelve true'
595 print 'NoData se vuelve true'
572 return 0
596 return 0
573
597
574 self.fp=self.path
598 self.fp = self.path
575 self.Files2Read(self.fp)
599 self.Files2Read(self.fp)
576 self.readFile(self.fp)
600 self.readFile(self.fp)
577 self.dataOut.data_spc = self.data_spc
601 self.dataOut.data_spc = self.data_spc
578 self.dataOut.data_cspc =self.data_cspc
602 self.dataOut.data_cspc = self.data_cspc
579 self.dataOut.data_output=self.data_output
603 self.dataOut.data_output = self.data_output
580
604
581 print 'self.dataOut.data_output', shape(self.dataOut.data_output)
605 print 'self.dataOut.data_output', shape(self.dataOut.data_output)
582
606
583 #self.removeDC()
607 # self.removeDC()
584 return self.dataOut.data_spc
608 return self.dataOut.data_spc
585
609
586
610 def readFile(self, fp):
587 def readFile(self,fp):
588 '''
611 '''
589 You must indicate if you are reading in Online or Offline mode and load the
612 You must indicate if you are reading in Online or Offline mode and load the
590 The parameters for this file reading mode.
613 The parameters for this file reading mode.
591
614
592 Then you must do 2 actions:
615 Then you must do 2 actions:
593
616
594 1. Get the BLTR FileHeader.
617 1. Get the BLTR FileHeader.
595 2. Start reading the first block.
618 2. Start reading the first block.
596 '''
619 '''
597
620
598 #The address of the folder is generated the name of the .fdt file that will be read
621 # The address of the folder is generated the name of the .fdt file that will be read
599 print "File: ",self.fileSelector+1
622 print "File: ", self.fileSelector + 1
600
623
601 if self.fileSelector < len(self.filenameList):
624 if self.fileSelector < len(self.filenameList):
602
625
603 self.fpFile=str(fp)+'/'+str(self.filenameList[self.fileSelector])
626 self.fpFile = str(fp) + '/' + \
604 #print self.fpFile
627 str(self.filenameList[self.fileSelector])
628 # print self.fpFile
605 fheader = FileHeaderBLTR()
629 fheader = FileHeaderBLTR()
606 fheader.FHread(self.fpFile) #Bltr FileHeader Reading
630 fheader.FHread(self.fpFile) # Bltr FileHeader Reading
607 self.nFDTdataRecors=fheader.nFDTdataRecors
631 self.nFDTdataRecors = fheader.nFDTdataRecors
608
632
609 self.readBlock() #Block reading
633 self.readBlock() # Block reading
610 else:
634 else:
611 print 'readFile FlagNoData becomes true'
635 print 'readFile FlagNoData becomes true'
612 self.flagNoMoreFiles=True
636 self.flagNoMoreFiles = True
613 self.dataOut.flagNoData = True
637 self.dataOut.flagNoData = True
614 return 0
638 return 0
615
639
616 def getVelRange(self, extrapoints=0):
640 def getVelRange(self, extrapoints=0):
617 Lambda= SPEED_OF_LIGHT/50000000
641 Lambda = SPEED_OF_LIGHT / 50000000
618 PRF = self.dataOut.PRF#1./(self.dataOut.ippSeconds * self.dataOut.nCohInt)
642 # 1./(self.dataOut.ippSeconds * self.dataOut.nCohInt)
619 Vmax=-Lambda/(4.*(1./PRF)*self.dataOut.nCohInt*2.)
643 PRF = self.dataOut.PRF
620 deltafreq = PRF / (self.nProfiles)
644 Vmax = -Lambda / (4. * (1. / PRF) * self.dataOut.nCohInt * 2.)
621 deltavel = (Vmax*2) / (self.nProfiles)
645 deltafreq = PRF / (self.nProfiles)
622 freqrange = deltafreq*(numpy.arange(self.nProfiles)-self.nProfiles/2.) - deltafreq/2
646 deltavel = (Vmax * 2) / (self.nProfiles)
623 velrange = deltavel*(numpy.arange(self.nProfiles)-self.nProfiles/2.)
647 freqrange = deltafreq * \
624 return velrange
648 (numpy.arange(self.nProfiles) - self.nProfiles / 2.) - deltafreq / 2
625
649 velrange = deltavel * \
626 def readBlock(self):
650 (numpy.arange(self.nProfiles) - self.nProfiles / 2.)
651 return velrange
652
653 def readBlock(self):
627 '''
654 '''
628 It should be checked if the block has data, if it is not passed to the next file.
655 It should be checked if the block has data, if it is not passed to the next file.
629
656
630 Then the following is done:
657 Then the following is done:
631
658
632 1. Read the RecordHeader
659 1. Read the RecordHeader
633 2. Fill the buffer with the current block number.
660 2. Fill the buffer with the current block number.
634
661
635 '''
662 '''
636
663
637 if self.BlockCounter < self.nFDTdataRecors-2:
664 if self.BlockCounter < self.nFDTdataRecors - 2:
638 print self.nFDTdataRecors, 'CONDICION!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
665 print self.nFDTdataRecors, 'CONDICION!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
639 if self.ReadMode==1:
666 if self.ReadMode == 1:
640 rheader = RecordHeaderBLTR(RecCounter=self.BlockCounter+1)
667 rheader = RecordHeaderBLTR(RecCounter=self.BlockCounter + 1)
641 elif self.ReadMode==0:
668 elif self.ReadMode == 0:
642 rheader = RecordHeaderBLTR(RecCounter=self.BlockCounter)
669 rheader = RecordHeaderBLTR(RecCounter=self.BlockCounter)
643
670
644 rheader.RHread(self.fpFile) #Bltr FileHeader Reading
671 rheader.RHread(self.fpFile) # Bltr FileHeader Reading
645
672
646 self.OffsetStartHeader=rheader.OffsetStartHeader
673 self.OffsetStartHeader = rheader.OffsetStartHeader
647 self.RecCounter=rheader.RecCounter
674 self.RecCounter = rheader.RecCounter
648 self.Off2StartNxtRec=rheader.Off2StartNxtRec
675 self.Off2StartNxtRec = rheader.Off2StartNxtRec
649 self.Off2StartData=rheader.Off2StartData
676 self.Off2StartData = rheader.Off2StartData
650 self.nProfiles=rheader.nProfiles
677 self.nProfiles = rheader.nProfiles
651 self.nChannels=rheader.nChannels
678 self.nChannels = rheader.nChannels
652 self.nHeights=rheader.nHeights
679 self.nHeights = rheader.nHeights
653 self.frequency=rheader.TransmitFrec
680 self.frequency = rheader.TransmitFrec
654 self.DualModeIndex=rheader.DualModeIndex
681 self.DualModeIndex = rheader.DualModeIndex
655
682
656 self.pairsList =[(0,1),(0,2),(1,2)]
683 self.pairsList = [(0, 1), (0, 2), (1, 2)]
657 self.dataOut.pairsList = self.pairsList
684 self.dataOut.pairsList = self.pairsList
658
685
659 self.nRdPairs=len(self.dataOut.pairsList)
686 self.nRdPairs = len(self.dataOut.pairsList)
660 self.dataOut.nRdPairs = self.nRdPairs
687 self.dataOut.nRdPairs = self.nRdPairs
661
688
662 self.__firstHeigth=rheader.StartRangeSamp
689 self.__firstHeigth = rheader.StartRangeSamp
663 self.__deltaHeigth=rheader.SampResolution
690 self.__deltaHeigth = rheader.SampResolution
664 self.dataOut.heightList= self.__firstHeigth + numpy.array(range(self.nHeights))*self.__deltaHeigth
691 self.dataOut.heightList = self.__firstHeigth + \
692 numpy.array(range(self.nHeights)) * self.__deltaHeigth
665 self.dataOut.channelList = range(self.nChannels)
693 self.dataOut.channelList = range(self.nChannels)
666 self.dataOut.nProfiles=rheader.nProfiles
694 self.dataOut.nProfiles = rheader.nProfiles
667 self.dataOut.nIncohInt=rheader.nIncohInt
695 self.dataOut.nIncohInt = rheader.nIncohInt
668 self.dataOut.nCohInt=rheader.nCohInt
696 self.dataOut.nCohInt = rheader.nCohInt
669 self.dataOut.ippSeconds= 1/float(rheader.PRFhz)
697 self.dataOut.ippSeconds = 1 / float(rheader.PRFhz)
670 self.dataOut.PRF=rheader.PRFhz
698 self.dataOut.PRF = rheader.PRFhz
671 self.dataOut.nFFTPoints=rheader.nProfiles
699 self.dataOut.nFFTPoints = rheader.nProfiles
672 self.dataOut.utctime=rheader.nUtime
700 self.dataOut.utctime = rheader.nUtime
673 self.dataOut.timeZone=0
701 self.dataOut.timeZone = 0
674 self.dataOut.normFactor= self.dataOut.nProfiles*self.dataOut.nIncohInt*self.dataOut.nCohInt
702 self.dataOut.normFactor = self.dataOut.nProfiles * \
675 self.dataOut.outputInterval= self.dataOut.ippSeconds * self.dataOut.nCohInt * self.dataOut.nIncohInt * self.nProfiles
703 self.dataOut.nIncohInt * self.dataOut.nCohInt
676
704 self.dataOut.outputInterval = self.dataOut.ippSeconds * \
677 self.data_output=numpy.ones([3,rheader.nHeights])*numpy.NaN
705 self.dataOut.nCohInt * self.dataOut.nIncohInt * self.nProfiles
706
707 self.data_output = numpy.ones([3, rheader.nHeights]) * numpy.NaN
678 print 'self.data_output', shape(self.data_output)
708 print 'self.data_output', shape(self.data_output)
679 self.dataOut.velocityX=[]
709 self.dataOut.velocityX = []
680 self.dataOut.velocityY=[]
710 self.dataOut.velocityY = []
681 self.dataOut.velocityV=[]
711 self.dataOut.velocityV = []
682
712
683 '''Block Reading, the Block Data is received and Reshape is used to give it
713 '''Block Reading, the Block Data is received and Reshape is used to give it
684 shape.
714 shape.
685 '''
715 '''
686
716
687 #Procedure to take the pointer to where the date block starts
717 # Procedure to take the pointer to where the date block starts
688 startDATA = open(self.fpFile,"rb")
718 startDATA = open(self.fpFile, "rb")
689 OffDATA= self.OffsetStartHeader + self.RecCounter*self.Off2StartNxtRec+self.Off2StartData
719 OffDATA = self.OffsetStartHeader + self.RecCounter * \
720 self.Off2StartNxtRec + self.Off2StartData
690 startDATA.seek(OffDATA, os.SEEK_SET)
721 startDATA.seek(OffDATA, os.SEEK_SET)
691
722
692 def moving_average(x, N=2):
723 def moving_average(x, N=2):
693 return numpy.convolve(x, numpy.ones((N,))/N)[(N-1):]
724 return numpy.convolve(x, numpy.ones((N,)) / N)[(N - 1):]
694
725
695 def gaus(xSamples,a,x0,sigma):
726 def gaus(xSamples, a, x0, sigma):
696 return a*exp(-(xSamples-x0)**2/(2*sigma**2))
727 return a * exp(-(xSamples - x0)**2 / (2 * sigma**2))
697
728
698 def Find(x,value):
729 def Find(x, value):
699 for index in range(len(x)):
730 for index in range(len(x)):
700 if x[index]==value:
731 if x[index] == value:
701 return index
732 return index
702
733
703 def pol2cart(rho, phi):
734 def pol2cart(rho, phi):
704 x = rho * numpy.cos(phi)
735 x = rho * numpy.cos(phi)
705 y = rho * numpy.sin(phi)
736 y = rho * numpy.sin(phi)
706 return(x, y)
737 return(x, y)
707
738
708
739 if self.DualModeIndex == self.ReadMode:
709
740
710
741 self.data_fft = numpy.fromfile(
711 if self.DualModeIndex==self.ReadMode:
742 startDATA, [('complex', '<c8')], self.nProfiles * self.nChannels * self.nHeights)
712
743
713 self.data_fft = numpy.fromfile( startDATA, [('complex','<c8')],self.nProfiles*self.nChannels*self.nHeights )
744 self.data_fft = self.data_fft.astype(numpy.dtype('complex'))
714
745
715 self.data_fft=self.data_fft.astype(numpy.dtype('complex'))
746 self.data_block = numpy.reshape(
716
747 self.data_fft, (self.nHeights, self.nChannels, self.nProfiles))
717 self.data_block=numpy.reshape(self.data_fft,(self.nHeights, self.nChannels, self.nProfiles ))
748
718
749 self.data_block = numpy.transpose(self.data_block, (1, 2, 0))
719 self.data_block = numpy.transpose(self.data_block, (1,2,0))
750
720
721 copy = self.data_block.copy()
751 copy = self.data_block.copy()
722 spc = copy * numpy.conjugate(copy)
752 spc = copy * numpy.conjugate(copy)
723
753
724 self.data_spc = numpy.absolute(spc) # valor absoluto o magnitud
754 self.data_spc = numpy.absolute(
725
755 spc) # valor absoluto o magnitud
756
726 factor = self.dataOut.normFactor
757 factor = self.dataOut.normFactor
727
758
728
759 z = self.data_spc.copy() # /factor
729 z = self.data_spc.copy()#/factor
730 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
760 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
731 #zdB = 10*numpy.log10(z)
761 #zdB = 10*numpy.log10(z)
732 print ' '
762 print ' '
733 print 'Z: '
763 print 'Z: '
734 print shape(z)
764 print shape(z)
735 print ' '
765 print ' '
736 print ' '
766 print ' '
737
767
738 self.dataOut.data_spc=self.data_spc
768 self.dataOut.data_spc = self.data_spc
739
769
740 self.noise = self.dataOut.getNoise(ymin_index=80, ymax_index=132)#/factor
770 self.noise = self.dataOut.getNoise(
771 ymin_index=80, ymax_index=132) # /factor
741 #noisedB = 10*numpy.log10(self.noise)
772 #noisedB = 10*numpy.log10(self.noise)
742
773
743
774 ySamples = numpy.ones([3, self.nProfiles])
744 ySamples=numpy.ones([3,self.nProfiles])
775 phase = numpy.ones([3, self.nProfiles])
745 phase=numpy.ones([3,self.nProfiles])
776 CSPCSamples = numpy.ones(
746 CSPCSamples=numpy.ones([3,self.nProfiles],dtype=numpy.complex_)
777 [3, self.nProfiles], dtype=numpy.complex_)
747 coherence=numpy.ones([3,self.nProfiles])
778 coherence = numpy.ones([3, self.nProfiles])
748 PhaseSlope=numpy.ones(3)
779 PhaseSlope = numpy.ones(3)
749 PhaseInter=numpy.ones(3)
780 PhaseInter = numpy.ones(3)
750
781
751 '''****** Getting CrossSpectra ******'''
782 '''****** Getting CrossSpectra ******'''
752 cspc=self.data_block.copy()
783 cspc = self.data_block.copy()
753 self.data_cspc=self.data_block.copy()
784 self.data_cspc = self.data_block.copy()
754
785
755 xFrec=self.getVelRange(1)
786 xFrec = self.getVelRange(1)
756 VelRange=self.getVelRange(1)
787 VelRange = self.getVelRange(1)
757 self.dataOut.VelRange=VelRange
788 self.dataOut.VelRange = VelRange
758 #print ' '
789 # print ' '
759 #print ' '
790 # print ' '
760 #print 'xFrec',xFrec
791 # print 'xFrec',xFrec
761 #print ' '
792 # print ' '
762 #print ' '
793 # print ' '
763 #Height=35
794 # Height=35
764 for i in range(self.nRdPairs):
795 for i in range(self.nRdPairs):
765
796
766 chan_index0 = self.dataOut.pairsList[i][0]
797 chan_index0 = self.dataOut.pairsList[i][0]
767 chan_index1 = self.dataOut.pairsList[i][1]
798 chan_index1 = self.dataOut.pairsList[i][1]
768
799
769 self.data_cspc[i,:,:]=cspc[chan_index0,:,:] * numpy.conjugate(cspc[chan_index1,:,:])
800 self.data_cspc[i, :, :] = cspc[chan_index0, :,
770
801 :] * numpy.conjugate(cspc[chan_index1, :, :])
771
802
772 '''Getting Eij and Nij'''
803 '''Getting Eij and Nij'''
773 (AntennaX0,AntennaY0)=pol2cart(rheader.AntennaCoord0, rheader.AntennaAngl0*numpy.pi/180)
804 (AntennaX0, AntennaY0) = pol2cart(
774 (AntennaX1,AntennaY1)=pol2cart(rheader.AntennaCoord1, rheader.AntennaAngl1*numpy.pi/180)
805 rheader.AntennaCoord0, rheader.AntennaAngl0 * numpy.pi / 180)
775 (AntennaX2,AntennaY2)=pol2cart(rheader.AntennaCoord2, rheader.AntennaAngl2*numpy.pi/180)
806 (AntennaX1, AntennaY1) = pol2cart(
776
807 rheader.AntennaCoord1, rheader.AntennaAngl1 * numpy.pi / 180)
777 E01=AntennaX0-AntennaX1
808 (AntennaX2, AntennaY2) = pol2cart(
778 N01=AntennaY0-AntennaY1
809 rheader.AntennaCoord2, rheader.AntennaAngl2 * numpy.pi / 180)
779
810
780 E02=AntennaX0-AntennaX2
811 E01 = AntennaX0 - AntennaX1
781 N02=AntennaY0-AntennaY2
812 N01 = AntennaY0 - AntennaY1
782
813
783 E12=AntennaX1-AntennaX2
814 E02 = AntennaX0 - AntennaX2
784 N12=AntennaY1-AntennaY2
815 N02 = AntennaY0 - AntennaY2
785
816
786 self.ChanDist= numpy.array([[E01, N01],[E02,N02],[E12,N12]])
817 E12 = AntennaX1 - AntennaX2
787
818 N12 = AntennaY1 - AntennaY2
819
820 self.ChanDist = numpy.array(
821 [[E01, N01], [E02, N02], [E12, N12]])
822
788 self.dataOut.ChanDist = self.ChanDist
823 self.dataOut.ChanDist = self.ChanDist
789
824
790
825
791 # for Height in range(self.nHeights):
826 # for Height in range(self.nHeights):
792 #
827 #
793 # for i in range(self.nRdPairs):
828 # for i in range(self.nRdPairs):
794 #
829 #
795 # '''****** Line of Data SPC ******'''
830 # '''****** Line of Data SPC ******'''
796 # zline=z[i,:,Height]
831 # zline=z[i,:,Height]
797 #
832 #
798 # '''****** DC is removed ******'''
833 # '''****** DC is removed ******'''
799 # DC=Find(zline,numpy.amax(zline))
834 # DC=Find(zline,numpy.amax(zline))
800 # zline[DC]=(zline[DC-1]+zline[DC+1])/2
835 # zline[DC]=(zline[DC-1]+zline[DC+1])/2
801 #
836 #
802 #
837 #
803 # '''****** SPC is normalized ******'''
838 # '''****** SPC is normalized ******'''
804 # FactNorm= zline.copy() / numpy.sum(zline.copy())
839 # FactNorm= zline.copy() / numpy.sum(zline.copy())
805 # FactNorm= FactNorm/numpy.sum(FactNorm)
840 # FactNorm= FactNorm/numpy.sum(FactNorm)
806 #
841 #
807 # SmoothSPC=moving_average(FactNorm,N=3)
842 # SmoothSPC=moving_average(FactNorm,N=3)
808 #
843 #
809 # xSamples = ar(range(len(SmoothSPC)))
844 # xSamples = ar(range(len(SmoothSPC)))
810 # ySamples[i] = SmoothSPC-self.noise[i]
845 # ySamples[i] = SmoothSPC-self.noise[i]
811 #
846 #
812 # for i in range(self.nRdPairs):
847 # for i in range(self.nRdPairs):
813 #
848 #
814 # '''****** Line of Data CSPC ******'''
849 # '''****** Line of Data CSPC ******'''
815 # cspcLine=self.data_cspc[i,:,Height].copy()
850 # cspcLine=self.data_cspc[i,:,Height].copy()
816 #
851 #
817 #
852 #
818 #
853 #
819 # '''****** CSPC is normalized ******'''
854 # '''****** CSPC is normalized ******'''
820 # chan_index0 = self.dataOut.pairsList[i][0]
855 # chan_index0 = self.dataOut.pairsList[i][0]
821 # chan_index1 = self.dataOut.pairsList[i][1]
856 # chan_index1 = self.dataOut.pairsList[i][1]
822 # CSPCFactor= numpy.sum(ySamples[chan_index0]) * numpy.sum(ySamples[chan_index1])
857 # CSPCFactor= numpy.sum(ySamples[chan_index0]) * numpy.sum(ySamples[chan_index1])
823 #
858 #
824 #
859 #
825 # CSPCNorm= cspcLine.copy() / numpy.sqrt(CSPCFactor)
860 # CSPCNorm= cspcLine.copy() / numpy.sqrt(CSPCFactor)
826 #
861 #
827 #
862 #
828 # CSPCSamples[i] = CSPCNorm-self.noise[i]
863 # CSPCSamples[i] = CSPCNorm-self.noise[i]
829 # coherence[i] = numpy.abs(CSPCSamples[i]) / numpy.sqrt(CSPCFactor)
864 # coherence[i] = numpy.abs(CSPCSamples[i]) / numpy.sqrt(CSPCFactor)
830 #
865 #
831 # '''****** DC is removed ******'''
866 # '''****** DC is removed ******'''
832 # DC=Find(coherence[i],numpy.amax(coherence[i]))
867 # DC=Find(coherence[i],numpy.amax(coherence[i]))
833 # coherence[i][DC]=(coherence[i][DC-1]+coherence[i][DC+1])/2
868 # coherence[i][DC]=(coherence[i][DC-1]+coherence[i][DC+1])/2
834 # coherence[i]= moving_average(coherence[i],N=2)
869 # coherence[i]= moving_average(coherence[i],N=2)
835 #
870 #
836 # phase[i] = moving_average( numpy.arctan2(CSPCSamples[i].imag, CSPCSamples[i].real),N=1)#*180/numpy.pi
871 # phase[i] = moving_average( numpy.arctan2(CSPCSamples[i].imag, CSPCSamples[i].real),N=1)#*180/numpy.pi
837 #
872 #
838 #
873 #
839 # '''****** Getting fij width ******'''
874 # '''****** Getting fij width ******'''
840 #
875 #
841 # yMean=[]
876 # yMean=[]
842 # yMean2=[]
877 # yMean2=[]
843 #
878 #
844 # for j in range(len(ySamples[1])):
879 # for j in range(len(ySamples[1])):
845 # yMean=numpy.append(yMean,numpy.average([ySamples[0,j],ySamples[1,j],ySamples[2,j]]))
880 # yMean=numpy.append(yMean,numpy.average([ySamples[0,j],ySamples[1,j],ySamples[2,j]]))
846 #
881 #
847 # '''******* Getting fitting Gaussian ******'''
882 # '''******* Getting fitting Gaussian ******'''
848 # meanGauss=sum(xSamples*yMean) / len(xSamples)
883 # meanGauss=sum(xSamples*yMean) / len(xSamples)
849 # sigma=sum(yMean*(xSamples-meanGauss)**2) / len(xSamples)
884 # sigma=sum(yMean*(xSamples-meanGauss)**2) / len(xSamples)
850 # #print 'Height',Height,'SNR', meanGauss/sigma**2
885 # #print 'Height',Height,'SNR', meanGauss/sigma**2
851 #
886 #
852 # if (abs(meanGauss/sigma**2) > 0.0001) :
887 # if (abs(meanGauss/sigma**2) > 0.0001) :
853 #
888 #
854 # try:
889 # try:
855 # popt,pcov = curve_fit(gaus,xSamples,yMean,p0=[1,meanGauss,sigma])
890 # popt,pcov = curve_fit(gaus,xSamples,yMean,p0=[1,meanGauss,sigma])
856 #
891 #
857 # if numpy.amax(popt)>numpy.amax(yMean)*0.3:
892 # if numpy.amax(popt)>numpy.amax(yMean)*0.3:
858 # FitGauss=gaus(xSamples,*popt)
893 # FitGauss=gaus(xSamples,*popt)
859 #
894 #
860 # else:
895 # else:
861 # FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
896 # FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
862 # print 'Verificador: Dentro', Height
897 # print 'Verificador: Dentro', Height
863 # except RuntimeError:
898 # except RuntimeError:
864 #
899 #
865 # try:
900 # try:
866 # for j in range(len(ySamples[1])):
901 # for j in range(len(ySamples[1])):
867 # yMean2=numpy.append(yMean2,numpy.average([ySamples[1,j],ySamples[2,j]]))
902 # yMean2=numpy.append(yMean2,numpy.average([ySamples[1,j],ySamples[2,j]]))
868 # popt,pcov = curve_fit(gaus,xSamples,yMean2,p0=[1,meanGauss,sigma])
903 # popt,pcov = curve_fit(gaus,xSamples,yMean2,p0=[1,meanGauss,sigma])
869 # FitGauss=gaus(xSamples,*popt)
904 # FitGauss=gaus(xSamples,*popt)
870 # print 'Verificador: Exepcion1', Height
905 # print 'Verificador: Exepcion1', Height
871 # except RuntimeError:
906 # except RuntimeError:
872 #
907 #
873 # try:
908 # try:
874 # popt,pcov = curve_fit(gaus,xSamples,ySamples[1],p0=[1,meanGauss,sigma])
909 # popt,pcov = curve_fit(gaus,xSamples,ySamples[1],p0=[1,meanGauss,sigma])
875 # FitGauss=gaus(xSamples,*popt)
910 # FitGauss=gaus(xSamples,*popt)
876 # print 'Verificador: Exepcion2', Height
911 # print 'Verificador: Exepcion2', Height
877 # except RuntimeError:
912 # except RuntimeError:
878 # FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
913 # FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
879 # print 'Verificador: Exepcion3', Height
914 # print 'Verificador: Exepcion3', Height
880 # else:
915 # else:
881 # FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
916 # FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
882 # #print 'Verificador: Fuera', Height
917 # #print 'Verificador: Fuera', Height
883 #
918 #
884 #
919 #
885 #
920 #
886 # Maximun=numpy.amax(yMean)
921 # Maximun=numpy.amax(yMean)
887 # eMinus1=Maximun*numpy.exp(-1)
922 # eMinus1=Maximun*numpy.exp(-1)
888 #
923 #
889 # HWpos=Find(FitGauss,min(FitGauss, key=lambda value:abs(value-eMinus1)))
924 # HWpos=Find(FitGauss,min(FitGauss, key=lambda value:abs(value-eMinus1)))
890 # HalfWidth= xFrec[HWpos]
925 # HalfWidth= xFrec[HWpos]
891 # GCpos=Find(FitGauss, numpy.amax(FitGauss))
926 # GCpos=Find(FitGauss, numpy.amax(FitGauss))
892 # Vpos=Find(FactNorm, numpy.amax(FactNorm))
927 # Vpos=Find(FactNorm, numpy.amax(FactNorm))
893 # #Vpos=numpy.sum(FactNorm)/len(FactNorm)
928 # #Vpos=numpy.sum(FactNorm)/len(FactNorm)
894 # #Vpos=Find(FactNorm, min(FactNorm, key=lambda value:abs(value- numpy.mean(FactNorm) )))
929 # #Vpos=Find(FactNorm, min(FactNorm, key=lambda value:abs(value- numpy.mean(FactNorm) )))
895 # #print 'GCpos',GCpos, numpy.amax(FitGauss), 'HWpos',HWpos
930 # #print 'GCpos',GCpos, numpy.amax(FitGauss), 'HWpos',HWpos
896 # '''****** Getting Fij ******'''
931 # '''****** Getting Fij ******'''
897 #
932 #
898 # GaussCenter=xFrec[GCpos]
933 # GaussCenter=xFrec[GCpos]
899 # if (GaussCenter<0 and HalfWidth>0) or (GaussCenter>0 and HalfWidth<0):
934 # if (GaussCenter<0 and HalfWidth>0) or (GaussCenter>0 and HalfWidth<0):
900 # Fij=abs(GaussCenter)+abs(HalfWidth)+0.0000001
935 # Fij=abs(GaussCenter)+abs(HalfWidth)+0.0000001
901 # else:
936 # else:
902 # Fij=abs(GaussCenter-HalfWidth)+0.0000001
937 # Fij=abs(GaussCenter-HalfWidth)+0.0000001
903 #
938 #
904 # '''****** Getting Frecuency range of significant data ******'''
939 # '''****** Getting Frecuency range of significant data ******'''
905 #
940 #
906 # Rangpos=Find(FitGauss,min(FitGauss, key=lambda value:abs(value-Maximun*0.10)))
941 # Rangpos=Find(FitGauss,min(FitGauss, key=lambda value:abs(value-Maximun*0.10)))
907 #
942 #
908 # if Rangpos<GCpos:
943 # if Rangpos<GCpos:
909 # Range=numpy.array([Rangpos,2*GCpos-Rangpos])
944 # Range=numpy.array([Rangpos,2*GCpos-Rangpos])
910 # else:
945 # else:
911 # Range=numpy.array([2*GCpos-Rangpos,Rangpos])
946 # Range=numpy.array([2*GCpos-Rangpos,Rangpos])
912 #
947 #
913 # FrecRange=xFrec[Range[0]:Range[1]]
948 # FrecRange=xFrec[Range[0]:Range[1]]
914 #
949 #
915 # #print 'FrecRange', FrecRange
950 # #print 'FrecRange', FrecRange
916 # '''****** Getting SCPC Slope ******'''
951 # '''****** Getting SCPC Slope ******'''
917 #
952 #
918 # for i in range(self.nRdPairs):
953 # for i in range(self.nRdPairs):
919 #
954 #
920 # if len(FrecRange)>5 and len(FrecRange)<self.nProfiles*0.5:
955 # if len(FrecRange)>5 and len(FrecRange)<self.nProfiles*0.5:
921 # PhaseRange=moving_average(phase[i,Range[0]:Range[1]],N=3)
956 # PhaseRange=moving_average(phase[i,Range[0]:Range[1]],N=3)
922 #
957 #
923 # slope, intercept, r_value, p_value, std_err = stats.linregress(FrecRange,PhaseRange)
958 # slope, intercept, r_value, p_value, std_err = stats.linregress(FrecRange,PhaseRange)
924 # PhaseSlope[i]=slope
959 # PhaseSlope[i]=slope
925 # PhaseInter[i]=intercept
960 # PhaseInter[i]=intercept
926 # else:
961 # else:
927 # PhaseSlope[i]=0
962 # PhaseSlope[i]=0
928 # PhaseInter[i]=0
963 # PhaseInter[i]=0
929 #
964 #
930 # # plt.figure(i+15)
965 # # plt.figure(i+15)
931 # # plt.title('FASE ( CH%s*CH%s )' %(self.dataOut.pairsList[i][0],self.dataOut.pairsList[i][1]))
966 # # plt.title('FASE ( CH%s*CH%s )' %(self.dataOut.pairsList[i][0],self.dataOut.pairsList[i][1]))
932 # # plt.xlabel('Frecuencia (KHz)')
967 # # plt.xlabel('Frecuencia (KHz)')
933 # # plt.ylabel('Magnitud')
968 # # plt.ylabel('Magnitud')
934 # # #plt.subplot(311+i)
969 # # #plt.subplot(311+i)
935 # # plt.plot(FrecRange,PhaseRange,'b')
970 # # plt.plot(FrecRange,PhaseRange,'b')
936 # # plt.plot(FrecRange,FrecRange*PhaseSlope[i]+PhaseInter[i],'r')
971 # # plt.plot(FrecRange,FrecRange*PhaseSlope[i]+PhaseInter[i],'r')
937 #
972 #
938 # #plt.axis([-0.6, 0.2, -3.2, 3.2])
973 # #plt.axis([-0.6, 0.2, -3.2, 3.2])
939 #
974 #
940 #
975 #
941 # '''Getting constant C'''
976 # '''Getting constant C'''
942 # cC=(Fij*numpy.pi)**2
977 # cC=(Fij*numpy.pi)**2
943 #
978 #
944 # # '''Getting Eij and Nij'''
979 # # '''Getting Eij and Nij'''
945 # # (AntennaX0,AntennaY0)=pol2cart(rheader.AntennaCoord0, rheader.AntennaAngl0*numpy.pi/180)
980 # # (AntennaX0,AntennaY0)=pol2cart(rheader.AntennaCoord0, rheader.AntennaAngl0*numpy.pi/180)
946 # # (AntennaX1,AntennaY1)=pol2cart(rheader.AntennaCoord1, rheader.AntennaAngl1*numpy.pi/180)
981 # # (AntennaX1,AntennaY1)=pol2cart(rheader.AntennaCoord1, rheader.AntennaAngl1*numpy.pi/180)
947 # # (AntennaX2,AntennaY2)=pol2cart(rheader.AntennaCoord2, rheader.AntennaAngl2*numpy.pi/180)
982 # # (AntennaX2,AntennaY2)=pol2cart(rheader.AntennaCoord2, rheader.AntennaAngl2*numpy.pi/180)
948 # #
983 # #
949 # # E01=AntennaX0-AntennaX1
984 # # E01=AntennaX0-AntennaX1
950 # # N01=AntennaY0-AntennaY1
985 # # N01=AntennaY0-AntennaY1
951 # #
986 # #
952 # # E02=AntennaX0-AntennaX2
987 # # E02=AntennaX0-AntennaX2
953 # # N02=AntennaY0-AntennaY2
988 # # N02=AntennaY0-AntennaY2
954 # #
989 # #
955 # # E12=AntennaX1-AntennaX2
990 # # E12=AntennaX1-AntennaX2
956 # # N12=AntennaY1-AntennaY2
991 # # N12=AntennaY1-AntennaY2
957 #
992 #
958 # '''****** Getting constants F and G ******'''
993 # '''****** Getting constants F and G ******'''
959 # MijEijNij=numpy.array([[E02,N02], [E12,N12]])
994 # MijEijNij=numpy.array([[E02,N02], [E12,N12]])
960 # MijResult0=(-PhaseSlope[1]*cC) / (2*numpy.pi)
995 # MijResult0=(-PhaseSlope[1]*cC) / (2*numpy.pi)
961 # MijResult1=(-PhaseSlope[2]*cC) / (2*numpy.pi)
996 # MijResult1=(-PhaseSlope[2]*cC) / (2*numpy.pi)
962 # MijResults=numpy.array([MijResult0,MijResult1])
997 # MijResults=numpy.array([MijResult0,MijResult1])
963 # (cF,cG) = numpy.linalg.solve(MijEijNij, MijResults)
998 # (cF,cG) = numpy.linalg.solve(MijEijNij, MijResults)
964 #
999 #
965 # '''****** Getting constants A, B and H ******'''
1000 # '''****** Getting constants A, B and H ******'''
966 # W01=numpy.amax(coherence[0])
1001 # W01=numpy.amax(coherence[0])
967 # W02=numpy.amax(coherence[1])
1002 # W02=numpy.amax(coherence[1])
968 # W12=numpy.amax(coherence[2])
1003 # W12=numpy.amax(coherence[2])
969 #
1004 #
970 # WijResult0=((cF*E01+cG*N01)**2)/cC - numpy.log(W01 / numpy.sqrt(numpy.pi/cC))
1005 # WijResult0=((cF*E01+cG*N01)**2)/cC - numpy.log(W01 / numpy.sqrt(numpy.pi/cC))
971 # WijResult1=((cF*E02+cG*N02)**2)/cC - numpy.log(W02 / numpy.sqrt(numpy.pi/cC))
1006 # WijResult1=((cF*E02+cG*N02)**2)/cC - numpy.log(W02 / numpy.sqrt(numpy.pi/cC))
972 # WijResult2=((cF*E12+cG*N12)**2)/cC - numpy.log(W12 / numpy.sqrt(numpy.pi/cC))
1007 # WijResult2=((cF*E12+cG*N12)**2)/cC - numpy.log(W12 / numpy.sqrt(numpy.pi/cC))
973 #
1008 #
974 # WijResults=numpy.array([WijResult0, WijResult1, WijResult2])
1009 # WijResults=numpy.array([WijResult0, WijResult1, WijResult2])
975 #
1010 #
976 # WijEijNij=numpy.array([ [E01**2, N01**2, 2*E01*N01] , [E02**2, N02**2, 2*E02*N02] , [E12**2, N12**2, 2*E12*N12] ])
1011 # WijEijNij=numpy.array([ [E01**2, N01**2, 2*E01*N01] , [E02**2, N02**2, 2*E02*N02] , [E12**2, N12**2, 2*E12*N12] ])
977 # (cA,cB,cH) = numpy.linalg.solve(WijEijNij, WijResults)
1012 # (cA,cB,cH) = numpy.linalg.solve(WijEijNij, WijResults)
978 #
1013 #
979 # VxVy=numpy.array([[cA,cH],[cH,cB]])
1014 # VxVy=numpy.array([[cA,cH],[cH,cB]])
980 #
1015 #
981 # VxVyResults=numpy.array([-cF,-cG])
1016 # VxVyResults=numpy.array([-cF,-cG])
982 # (Vx,Vy) = numpy.linalg.solve(VxVy, VxVyResults)
1017 # (Vx,Vy) = numpy.linalg.solve(VxVy, VxVyResults)
983 # Vzon = Vy
1018 # Vzon = Vy
984 # Vmer = Vx
1019 # Vmer = Vx
985 # Vmag=numpy.sqrt(Vzon**2+Vmer**2)
1020 # Vmag=numpy.sqrt(Vzon**2+Vmer**2)
986 # Vang=numpy.arctan2(Vmer,Vzon)
1021 # Vang=numpy.arctan2(Vmer,Vzon)
987 #
1022 #
988 # if abs(Vy)<100 and abs(Vy)> 0.:
1023 # if abs(Vy)<100 and abs(Vy)> 0.:
989 # self.dataOut.velocityX=numpy.append(self.dataOut.velocityX, Vzon) #Vmag
1024 # self.dataOut.velocityX=numpy.append(self.dataOut.velocityX, Vzon) #Vmag
990 # #print 'Vmag',Vmag
1025 # #print 'Vmag',Vmag
991 # else:
1026 # else:
992 # self.dataOut.velocityX=numpy.append(self.dataOut.velocityX, NaN)
1027 # self.dataOut.velocityX=numpy.append(self.dataOut.velocityX, NaN)
993 #
1028 #
994 # if abs(Vx)<100 and abs(Vx) > 0.:
1029 # if abs(Vx)<100 and abs(Vx) > 0.:
995 # self.dataOut.velocityY=numpy.append(self.dataOut.velocityY, Vmer) #Vang
1030 # self.dataOut.velocityY=numpy.append(self.dataOut.velocityY, Vmer) #Vang
996 # #print 'Vang',Vang
1031 # #print 'Vang',Vang
997 # else:
1032 # else:
998 # self.dataOut.velocityY=numpy.append(self.dataOut.velocityY, NaN)
1033 # self.dataOut.velocityY=numpy.append(self.dataOut.velocityY, NaN)
999 #
1034 #
1000 # if abs(GaussCenter)<2:
1035 # if abs(GaussCenter)<2:
1001 # self.dataOut.velocityV=numpy.append(self.dataOut.velocityV, xFrec[Vpos])
1036 # self.dataOut.velocityV=numpy.append(self.dataOut.velocityV, xFrec[Vpos])
1002 #
1037 #
1003 # else:
1038 # else:
1004 # self.dataOut.velocityV=numpy.append(self.dataOut.velocityV, NaN)
1039 # self.dataOut.velocityV=numpy.append(self.dataOut.velocityV, NaN)
1005 #
1040 #
1006 #
1041 #
1007 # # print '********************************************'
1042 # # print '********************************************'
1008 # # print 'HalfWidth ', HalfWidth
1043 # # print 'HalfWidth ', HalfWidth
1009 # # print 'Maximun ', Maximun
1044 # # print 'Maximun ', Maximun
1010 # # print 'eMinus1 ', eMinus1
1045 # # print 'eMinus1 ', eMinus1
1011 # # print 'Rangpos ', Rangpos
1046 # # print 'Rangpos ', Rangpos
1012 # # print 'GaussCenter ',GaussCenter
1047 # # print 'GaussCenter ',GaussCenter
1013 # # print 'E01 ',E01
1048 # # print 'E01 ',E01
1014 # # print 'N01 ',N01
1049 # # print 'N01 ',N01
1015 # # print 'E02 ',E02
1050 # # print 'E02 ',E02
1016 # # print 'N02 ',N02
1051 # # print 'N02 ',N02
1017 # # print 'E12 ',E12
1052 # # print 'E12 ',E12
1018 # # print 'N12 ',N12
1053 # # print 'N12 ',N12
1019 # #print 'self.dataOut.velocityX ', self.dataOut.velocityX
1054 # #print 'self.dataOut.velocityX ', self.dataOut.velocityX
1020 # # print 'Fij ', Fij
1055 # # print 'Fij ', Fij
1021 # # print 'cC ', cC
1056 # # print 'cC ', cC
1022 # # print 'cF ', cF
1057 # # print 'cF ', cF
1023 # # print 'cG ', cG
1058 # # print 'cG ', cG
1024 # # print 'cA ', cA
1059 # # print 'cA ', cA
1025 # # print 'cB ', cB
1060 # # print 'cB ', cB
1026 # # print 'cH ', cH
1061 # # print 'cH ', cH
1027 # # print 'Vx ', Vx
1062 # # print 'Vx ', Vx
1028 # # print 'Vy ', Vy
1063 # # print 'Vy ', Vy
1029 # # print 'Vmag ', Vmag
1064 # # print 'Vmag ', Vmag
1030 # # print 'Vang ', Vang*180/numpy.pi
1065 # # print 'Vang ', Vang*180/numpy.pi
1031 # # print 'PhaseSlope ',PhaseSlope[0]
1066 # # print 'PhaseSlope ',PhaseSlope[0]
1032 # # print 'PhaseSlope ',PhaseSlope[1]
1067 # # print 'PhaseSlope ',PhaseSlope[1]
1033 # # print 'PhaseSlope ',PhaseSlope[2]
1068 # # print 'PhaseSlope ',PhaseSlope[2]
1034 # # print '********************************************'
1069 # # print '********************************************'
1035 # #print 'data_output',shape(self.dataOut.velocityX), shape(self.dataOut.velocityY)
1070 # #print 'data_output',shape(self.dataOut.velocityX), shape(self.dataOut.velocityY)
1036 #
1071 #
1037 # #print 'self.dataOut.velocityX', len(self.dataOut.velocityX)
1072 # #print 'self.dataOut.velocityX', len(self.dataOut.velocityX)
1038 # #print 'self.dataOut.velocityY', len(self.dataOut.velocityY)
1073 # #print 'self.dataOut.velocityY', len(self.dataOut.velocityY)
1039 # #print 'self.dataOut.velocityV', self.dataOut.velocityV
1074 # #print 'self.dataOut.velocityV', self.dataOut.velocityV
1040 #
1075 #
1041 # self.data_output[0]=numpy.array(self.dataOut.velocityX)
1076 # self.data_output[0]=numpy.array(self.dataOut.velocityX)
1042 # self.data_output[1]=numpy.array(self.dataOut.velocityY)
1077 # self.data_output[1]=numpy.array(self.dataOut.velocityY)
1043 # self.data_output[2]=numpy.array(self.dataOut.velocityV)
1078 # self.data_output[2]=numpy.array(self.dataOut.velocityV)
1044 #
1079 #
1045 # prin= self.data_output[0][~numpy.isnan(self.data_output[0])]
1080 # prin= self.data_output[0][~numpy.isnan(self.data_output[0])]
1046 # print ' '
1081 # print ' '
1047 # print 'VmagAverage',numpy.mean(prin)
1082 # print 'VmagAverage',numpy.mean(prin)
1048 # print ' '
1083 # print ' '
1049 # # plt.figure(5)
1084 # # plt.figure(5)
1050 # # plt.subplot(211)
1085 # # plt.subplot(211)
1051 # # plt.plot(self.dataOut.velocityX,'yo:')
1086 # # plt.plot(self.dataOut.velocityX,'yo:')
1052 # # plt.subplot(212)
1087 # # plt.subplot(212)
1053 # # plt.plot(self.dataOut.velocityY,'yo:')
1088 # # plt.plot(self.dataOut.velocityY,'yo:')
1054 #
1089 #
1055 # # plt.figure(1)
1090 # # plt.figure(1)
1056 # # # plt.subplot(121)
1091 # # # plt.subplot(121)
1057 # # # plt.plot(xFrec,ySamples[0],'k',label='Ch0')
1092 # # # plt.plot(xFrec,ySamples[0],'k',label='Ch0')
1058 # # # plt.plot(xFrec,ySamples[1],'g',label='Ch1')
1093 # # # plt.plot(xFrec,ySamples[1],'g',label='Ch1')
1059 # # # plt.plot(xFrec,ySamples[2],'r',label='Ch2')
1094 # # # plt.plot(xFrec,ySamples[2],'r',label='Ch2')
1060 # # # plt.plot(xFrec,FitGauss,'yo:',label='fit')
1095 # # # plt.plot(xFrec,FitGauss,'yo:',label='fit')
1061 # # # plt.legend()
1096 # # # plt.legend()
1062 # # plt.title('DATOS A ALTURA DE 2850 METROS')
1097 # # plt.title('DATOS A ALTURA DE 2850 METROS')
1063 # #
1098 # #
1064 # # plt.xlabel('Frecuencia (KHz)')
1099 # # plt.xlabel('Frecuencia (KHz)')
1065 # # plt.ylabel('Magnitud')
1100 # # plt.ylabel('Magnitud')
1066 # # # plt.subplot(122)
1101 # # # plt.subplot(122)
1067 # # # plt.title('Fit for Time Constant')
1102 # # # plt.title('Fit for Time Constant')
1068 # # #plt.plot(xFrec,zline)
1103 # # #plt.plot(xFrec,zline)
1069 # # #plt.plot(xFrec,SmoothSPC,'g')
1104 # # #plt.plot(xFrec,SmoothSPC,'g')
1070 # # plt.plot(xFrec,FactNorm)
1105 # # plt.plot(xFrec,FactNorm)
1071 # # plt.axis([-4, 4, 0, 0.15])
1106 # # plt.axis([-4, 4, 0, 0.15])
1072 # # # plt.xlabel('SelfSpectra KHz')
1107 # # # plt.xlabel('SelfSpectra KHz')
1073 # #
1108 # #
1074 # # plt.figure(10)
1109 # # plt.figure(10)
1075 # # # plt.subplot(121)
1110 # # # plt.subplot(121)
1076 # # plt.plot(xFrec,ySamples[0],'b',label='Ch0')
1111 # # plt.plot(xFrec,ySamples[0],'b',label='Ch0')
1077 # # plt.plot(xFrec,ySamples[1],'y',label='Ch1')
1112 # # plt.plot(xFrec,ySamples[1],'y',label='Ch1')
1078 # # plt.plot(xFrec,ySamples[2],'r',label='Ch2')
1113 # # plt.plot(xFrec,ySamples[2],'r',label='Ch2')
1079 # # # plt.plot(xFrec,FitGauss,'yo:',label='fit')
1114 # # # plt.plot(xFrec,FitGauss,'yo:',label='fit')
1080 # # plt.legend()
1115 # # plt.legend()
1081 # # plt.title('SELFSPECTRA EN CANALES')
1116 # # plt.title('SELFSPECTRA EN CANALES')
1082 # #
1117 # #
1083 # # plt.xlabel('Frecuencia (KHz)')
1118 # # plt.xlabel('Frecuencia (KHz)')
1084 # # plt.ylabel('Magnitud')
1119 # # plt.ylabel('Magnitud')
1085 # # # plt.subplot(122)
1120 # # # plt.subplot(122)
1086 # # # plt.title('Fit for Time Constant')
1121 # # # plt.title('Fit for Time Constant')
1087 # # #plt.plot(xFrec,zline)
1122 # # #plt.plot(xFrec,zline)
1088 # # #plt.plot(xFrec,SmoothSPC,'g')
1123 # # #plt.plot(xFrec,SmoothSPC,'g')
1089 # # # plt.plot(xFrec,FactNorm)
1124 # # # plt.plot(xFrec,FactNorm)
1090 # # # plt.axis([-4, 4, 0, 0.15])
1125 # # # plt.axis([-4, 4, 0, 0.15])
1091 # # # plt.xlabel('SelfSpectra KHz')
1126 # # # plt.xlabel('SelfSpectra KHz')
1092 # #
1127 # #
1093 # # plt.figure(9)
1128 # # plt.figure(9)
1094 # #
1129 # #
1095 # #
1130 # #
1096 # # plt.title('DATOS SUAVIZADOS')
1131 # # plt.title('DATOS SUAVIZADOS')
1097 # # plt.xlabel('Frecuencia (KHz)')
1132 # # plt.xlabel('Frecuencia (KHz)')
1098 # # plt.ylabel('Magnitud')
1133 # # plt.ylabel('Magnitud')
1099 # # plt.plot(xFrec,SmoothSPC,'g')
1134 # # plt.plot(xFrec,SmoothSPC,'g')
1100 # #
1135 # #
1101 # # #plt.plot(xFrec,FactNorm)
1136 # # #plt.plot(xFrec,FactNorm)
1102 # # plt.axis([-4, 4, 0, 0.15])
1137 # # plt.axis([-4, 4, 0, 0.15])
1103 # # # plt.xlabel('SelfSpectra KHz')
1138 # # # plt.xlabel('SelfSpectra KHz')
1104 # # #
1139 # # #
1105 # # plt.figure(2)
1140 # # plt.figure(2)
1106 # # # #plt.subplot(121)
1141 # # # #plt.subplot(121)
1107 # # plt.plot(xFrec,yMean,'r',label='Mean SelfSpectra')
1142 # # plt.plot(xFrec,yMean,'r',label='Mean SelfSpectra')
1108 # # plt.plot(xFrec,FitGauss,'yo:',label='Ajuste Gaussiano')
1143 # # plt.plot(xFrec,FitGauss,'yo:',label='Ajuste Gaussiano')
1109 # # # plt.plot(xFrec[Rangpos],FitGauss[Find(FitGauss,min(FitGauss, key=lambda value:abs(value-Maximun*0.1)))],'bo')
1144 # # # plt.plot(xFrec[Rangpos],FitGauss[Find(FitGauss,min(FitGauss, key=lambda value:abs(value-Maximun*0.1)))],'bo')
1110 # # # #plt.plot(xFrec,phase)
1145 # # # #plt.plot(xFrec,phase)
1111 # # # plt.xlabel('Suavizado, promediado KHz')
1146 # # # plt.xlabel('Suavizado, promediado KHz')
1112 # # plt.title('SELFSPECTRA PROMEDIADO')
1147 # # plt.title('SELFSPECTRA PROMEDIADO')
1113 # # # #plt.subplot(122)
1148 # # # #plt.subplot(122)
1114 # # # #plt.plot(xSamples,zline)
1149 # # # #plt.plot(xSamples,zline)
1115 # # plt.xlabel('Frecuencia (KHz)')
1150 # # plt.xlabel('Frecuencia (KHz)')
1116 # # plt.ylabel('Magnitud')
1151 # # plt.ylabel('Magnitud')
1117 # # plt.legend()
1152 # # plt.legend()
1118 # # #
1153 # # #
1119 # # # plt.figure(3)
1154 # # # plt.figure(3)
1120 # # # plt.subplot(311)
1155 # # # plt.subplot(311)
1121 # # # #plt.plot(xFrec,phase[0])
1156 # # # #plt.plot(xFrec,phase[0])
1122 # # # plt.plot(xFrec,phase[0],'g')
1157 # # # plt.plot(xFrec,phase[0],'g')
1123 # # # plt.subplot(312)
1158 # # # plt.subplot(312)
1124 # # # plt.plot(xFrec,phase[1],'g')
1159 # # # plt.plot(xFrec,phase[1],'g')
1125 # # # plt.subplot(313)
1160 # # # plt.subplot(313)
1126 # # # plt.plot(xFrec,phase[2],'g')
1161 # # # plt.plot(xFrec,phase[2],'g')
1127 # # # #plt.plot(xFrec,phase[2])
1162 # # # #plt.plot(xFrec,phase[2])
1128 # # #
1163 # # #
1129 # # # plt.figure(4)
1164 # # # plt.figure(4)
1130 # # #
1165 # # #
1131 # # # plt.plot(xSamples,coherence[0],'b')
1166 # # # plt.plot(xSamples,coherence[0],'b')
1132 # # # plt.plot(xSamples,coherence[1],'r')
1167 # # # plt.plot(xSamples,coherence[1],'r')
1133 # # # plt.plot(xSamples,coherence[2],'g')
1168 # # # plt.plot(xSamples,coherence[2],'g')
1134 # # plt.show()
1169 # # plt.show()
1135 # # #
1170 # # #
1136 # # # plt.clf()
1171 # # # plt.clf()
1137 # # # plt.cla()
1172 # # # plt.cla()
1138 # # # plt.close()
1173 # # # plt.close()
1139 #
1174 #
1140 # print ' '
1175 # print ' '
1141
1176
1142
1177 self.BlockCounter += 2
1143
1178
1144 self.BlockCounter+=2
1145
1146 else:
1179 else:
1147 self.fileSelector+=1
1180 self.fileSelector += 1
1148 self.BlockCounter=0
1181 self.BlockCounter = 0
1149 print "Next File"
1182 print "Next File"
1150
1151
1152
1153
1154
This diff has been collapsed as it changes many lines, (1027 lines changed) Show them Hide them
@@ -1,803 +1,802
1 import os, sys
1 import os
2 import sys
2 import glob
3 import glob
3 import fnmatch
4 import fnmatch
4 import datetime
5 import datetime
5 import time
6 import time
6 import re
7 import re
7 import h5py
8 import h5py
8 import numpy
9 import numpy
9 import matplotlib.pyplot as plt
10
10
11 import pylab as plb
12 from scipy.optimize import curve_fit
11 from scipy.optimize import curve_fit
13 from scipy import asarray as ar,exp
12 from scipy import asarray as ar, exp
14 from scipy import stats
13 from scipy import stats
15
14
16 from numpy.ma.core import getdata
15 from numpy.ma.core import getdata
17
16
18 SPEED_OF_LIGHT = 299792458
17 SPEED_OF_LIGHT = 299792458
19 SPEED_OF_LIGHT = 3e8
18 SPEED_OF_LIGHT = 3e8
20
19
21 try:
20 try:
22 from gevent import sleep
21 from gevent import sleep
23 except:
22 except:
24 from time import sleep
23 from time import sleep
25
24
26 from schainpy.model.data.jrodata import Spectra
25 from schainpy.model.data.jrodata import Spectra
27 #from schainpy.model.data.BLTRheaderIO import FileHeader, RecordHeader
26 #from schainpy.model.data.BLTRheaderIO import FileHeader, RecordHeader
28 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
27 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
29 #from schainpy.model.io.jroIO_bltr import BLTRReader
28 #from schainpy.model.io.jroIO_bltr import BLTRReader
30 from numpy import imag, shape, NaN, empty
29 from numpy import imag, shape, NaN, empty
31
30
32
31
33
34 class Header(object):
32 class Header(object):
35
33
36 def __init__(self):
34 def __init__(self):
37 raise NotImplementedError
35 raise NotImplementedError
38
36
39
40 def read(self):
37 def read(self):
41
38
42 raise NotImplementedError
39 raise NotImplementedError
43
40
44 def write(self):
41 def write(self):
45
42
46 raise NotImplementedError
43 raise NotImplementedError
47
44
48 def printInfo(self):
45 def printInfo(self):
49
46
50 message = "#"*50 + "\n"
47 message = "#" * 50 + "\n"
51 message += self.__class__.__name__.upper() + "\n"
48 message += self.__class__.__name__.upper() + "\n"
52 message += "#"*50 + "\n"
49 message += "#" * 50 + "\n"
53
50
54 keyList = self.__dict__.keys()
51 keyList = self.__dict__.keys()
55 keyList.sort()
52 keyList.sort()
56
53
57 for key in keyList:
54 for key in keyList:
58 message += "%s = %s" %(key, self.__dict__[key]) + "\n"
55 message += "%s = %s" % (key, self.__dict__[key]) + "\n"
59
56
60 if "size" not in keyList:
57 if "size" not in keyList:
61 attr = getattr(self, "size")
58 attr = getattr(self, "size")
62
59
63 if attr:
60 if attr:
64 message += "%s = %s" %("size", attr) + "\n"
61 message += "%s = %s" % ("size", attr) + "\n"
65
62
66 #print message
63 # print message
67
64
68
65
69 FILE_HEADER = numpy.dtype([ #HEADER 1024bytes
66 FILE_HEADER = numpy.dtype([ # HEADER 1024bytes
70 ('Hname','a32'), #Original file name
67 ('Hname', 'a32'), # Original file name
71 ('Htime',numpy.str_,32), #Date and time when the file was created
68 # Date and time when the file was created
72 ('Hoper',numpy.str_,64), #Name of operator who created the file
69 ('Htime', numpy.str_, 32),
73 ('Hplace',numpy.str_,128), #Place where the measurements was carried out
70 # Name of operator who created the file
74 ('Hdescr',numpy.str_,256), #Description of measurements
71 ('Hoper', numpy.str_, 64),
75 ('Hdummy',numpy.str_,512), #Reserved space
72 # Place where the measurements was carried out
76 #Main chunk 8bytes
73 ('Hplace', numpy.str_, 128),
77 ('Msign',numpy.str_,4), #Main chunk signature FZKF or NUIG
74 # Description of measurements
78 ('MsizeData','<i4'), #Size of data block main chunk
75 ('Hdescr', numpy.str_, 256),
79 #Processing DSP parameters 36bytes
76 ('Hdummy', numpy.str_, 512), # Reserved space
80 ('PPARsign',numpy.str_,4), #PPAR signature
77 # Main chunk 8bytes
81 ('PPARsize','<i4'), #PPAR size of block
78 # Main chunk signature FZKF or NUIG
82 ('PPARprf','<i4'), #Pulse repetition frequency
79 ('Msign', numpy.str_, 4),
83 ('PPARpdr','<i4'), #Pulse duration
80 ('MsizeData', '<i4'), # Size of data block main chunk
84 ('PPARsft','<i4'), #FFT length
81 # Processing DSP parameters 36bytes
85 ('PPARavc','<i4'), #Number of spectral (in-coherent) averages
82 ('PPARsign', numpy.str_, 4), # PPAR signature
86 ('PPARihp','<i4'), #Number of lowest range gate for moment estimation
83 ('PPARsize', '<i4'), # PPAR size of block
87 ('PPARchg','<i4'), #Count for gates for moment estimation
84 ('PPARprf', '<i4'), # Pulse repetition frequency
88 ('PPARpol','<i4'), #switch on/off polarimetric measurements. Should be 1.
85 ('PPARpdr', '<i4'), # Pulse duration
89 #Service DSP parameters 112bytes
86 ('PPARsft', '<i4'), # FFT length
90 ('SPARatt','<i4'), #STC attenuation on the lowest ranges on/off
87 # Number of spectral (in-coherent) averages
91 ('SPARtx','<i4'), #OBSOLETE
88 ('PPARavc', '<i4'),
92 ('SPARaddGain0','<f4'), #OBSOLETE
89 # Number of lowest range gate for moment estimation
93 ('SPARaddGain1','<f4'), #OBSOLETE
90 ('PPARihp', '<i4'),
94 ('SPARwnd','<i4'), #Debug only. It normal mode it is 0.
91 # Count for gates for moment estimation
95 ('SPARpos','<i4'), #Delay between sync pulse and tx pulse for phase corr, ns
92 ('PPARchg', '<i4'),
96 ('SPARadd','<i4'), #"add to pulse" to compensate for delay between the leading edge of driver pulse and envelope of the RF signal.
93 # switch on/off polarimetric measurements. Should be 1.
97 ('SPARlen','<i4'), #Time for measuring txn pulse phase. OBSOLETE
94 ('PPARpol', '<i4'),
98 ('SPARcal','<i4'), #OBSOLETE
95 # Service DSP parameters 112bytes
99 ('SPARnos','<i4'), #OBSOLETE
96 # STC attenuation on the lowest ranges on/off
100 ('SPARof0','<i4'), #detection threshold
97 ('SPARatt', '<i4'),
101 ('SPARof1','<i4'), #OBSOLETE
98 ('SPARtx', '<i4'), # OBSOLETE
102 ('SPARswt','<i4'), #2nd moment estimation threshold
99 ('SPARaddGain0', '<f4'), # OBSOLETE
103 ('SPARsum','<i4'), #OBSOLETE
100 ('SPARaddGain1', '<f4'), # OBSOLETE
104 ('SPARosc','<i4'), #flag Oscillosgram mode
101 # Debug only. It normal mode it is 0.
105 ('SPARtst','<i4'), #OBSOLETE
102 ('SPARwnd', '<i4'),
106 ('SPARcor','<i4'), #OBSOLETE
103 # Delay between sync pulse and tx pulse for phase corr, ns
107 ('SPARofs','<i4'), #OBSOLETE
104 ('SPARpos', '<i4'),
108 ('SPARhsn','<i4'), #Hildebrand div noise detection on noise gate
105 # "add to pulse" to compensate for delay between the leading edge of driver pulse and envelope of the RF signal.
109 ('SPARhsa','<f4'), #Hildebrand div noise detection on all gates
106 ('SPARadd', '<i4'),
110 ('SPARcalibPow_M','<f4'), #OBSOLETE
107 # Time for measuring txn pulse phase. OBSOLETE
111 ('SPARcalibSNR_M','<f4'), #OBSOLETE
108 ('SPARlen', '<i4'),
112 ('SPARcalibPow_S','<f4'), #OBSOLETE
109 ('SPARcal', '<i4'), # OBSOLETE
113 ('SPARcalibSNR_S','<f4'), #OBSOLETE
110 ('SPARnos', '<i4'), # OBSOLETE
114 ('SPARrawGate1','<i4'), #Lowest range gate for spectra saving Raw_Gate1 >=5
111 ('SPARof0', '<i4'), # detection threshold
115 ('SPARrawGate2','<i4'), #Number of range gates with atmospheric signal
112 ('SPARof1', '<i4'), # OBSOLETE
116 ('SPARraw','<i4'), #flag - IQ or spectra saving on/off
113 ('SPARswt', '<i4'), # 2nd moment estimation threshold
117 ('SPARprc','<i4'),]) #flag - Moment estimation switched on/off
114 ('SPARsum', '<i4'), # OBSOLETE
118
115 ('SPARosc', '<i4'), # flag Oscillosgram mode
119
116 ('SPARtst', '<i4'), # OBSOLETE
120
117 ('SPARcor', '<i4'), # OBSOLETE
118 ('SPARofs', '<i4'), # OBSOLETE
119 # Hildebrand div noise detection on noise gate
120 ('SPARhsn', '<i4'),
121 # Hildebrand div noise detection on all gates
122 ('SPARhsa', '<f4'),
123 ('SPARcalibPow_M', '<f4'), # OBSOLETE
124 ('SPARcalibSNR_M', '<f4'), # OBSOLETE
125 ('SPARcalibPow_S', '<f4'), # OBSOLETE
126 ('SPARcalibSNR_S', '<f4'), # OBSOLETE
127 # Lowest range gate for spectra saving Raw_Gate1 >=5
128 ('SPARrawGate1', '<i4'),
129 # Number of range gates with atmospheric signal
130 ('SPARrawGate2', '<i4'),
131 # flag - IQ or spectra saving on/off
132 ('SPARraw', '<i4'),
133 ('SPARprc', '<i4'), ]) # flag - Moment estimation switched on/off
134
135
121 class FileHeaderMIRA35c(Header):
136 class FileHeaderMIRA35c(Header):
122
137
123 def __init__(self):
138 def __init__(self):
124
139
125 self.Hname= None
140 self.Hname = None
126 self.Htime= None
141 self.Htime = None
127 self.Hoper= None
142 self.Hoper = None
128 self.Hplace= None
143 self.Hplace = None
129 self.Hdescr= None
144 self.Hdescr = None
130 self.Hdummy= None
145 self.Hdummy = None
131
146
132 self.Msign=None
147 self.Msign = None
133 self.MsizeData=None
148 self.MsizeData = None
134
149
135 self.PPARsign=None
150 self.PPARsign = None
136 self.PPARsize=None
151 self.PPARsize = None
137 self.PPARprf=None
152 self.PPARprf = None
138 self.PPARpdr=None
153 self.PPARpdr = None
139 self.PPARsft=None
154 self.PPARsft = None
140 self.PPARavc=None
155 self.PPARavc = None
141 self.PPARihp=None
156 self.PPARihp = None
142 self.PPARchg=None
157 self.PPARchg = None
143 self.PPARpol=None
158 self.PPARpol = None
144 #Service DSP parameters
159 # Service DSP parameters
145 self.SPARatt=None
160 self.SPARatt = None
146 self.SPARtx=None
161 self.SPARtx = None
147 self.SPARaddGain0=None
162 self.SPARaddGain0 = None
148 self.SPARaddGain1=None
163 self.SPARaddGain1 = None
149 self.SPARwnd=None
164 self.SPARwnd = None
150 self.SPARpos=None
165 self.SPARpos = None
151 self.SPARadd=None
166 self.SPARadd = None
152 self.SPARlen=None
167 self.SPARlen = None
153 self.SPARcal=None
168 self.SPARcal = None
154 self.SPARnos=None
169 self.SPARnos = None
155 self.SPARof0=None
170 self.SPARof0 = None
156 self.SPARof1=None
171 self.SPARof1 = None
157 self.SPARswt=None
172 self.SPARswt = None
158 self.SPARsum=None
173 self.SPARsum = None
159 self.SPARosc=None
174 self.SPARosc = None
160 self.SPARtst=None
175 self.SPARtst = None
161 self.SPARcor=None
176 self.SPARcor = None
162 self.SPARofs=None
177 self.SPARofs = None
163 self.SPARhsn=None
178 self.SPARhsn = None
164 self.SPARhsa=None
179 self.SPARhsa = None
165 self.SPARcalibPow_M=None
180 self.SPARcalibPow_M = None
166 self.SPARcalibSNR_M=None
181 self.SPARcalibSNR_M = None
167 self.SPARcalibPow_S=None
182 self.SPARcalibPow_S = None
168 self.SPARcalibSNR_S=None
183 self.SPARcalibSNR_S = None
169 self.SPARrawGate1=None
184 self.SPARrawGate1 = None
170 self.SPARrawGate2=None
185 self.SPARrawGate2 = None
171 self.SPARraw=None
186 self.SPARraw = None
172 self.SPARprc=None
187 self.SPARprc = None
173
188
174 self.FHsize=1180
189 self.FHsize = 1180
175
190
176 def FHread(self, fp):
191 def FHread(self, fp):
177
192
178 header = numpy.fromfile(fp, FILE_HEADER,1)
193 header = numpy.fromfile(fp, FILE_HEADER, 1)
179 ''' numpy.fromfile(file, dtype, count, sep='')
194 ''' numpy.fromfile(file, dtype, count, sep='')
180 file : file or str
195 file : file or str
181 Open file object or filename.
196 Open file object or filename.
182
197
183 dtype : data-type
198 dtype : data-type
184 Data type of the returned array. For binary files, it is used to determine
199 Data type of the returned array. For binary files, it is used to determine
185 the size and byte-order of the items in the file.
200 the size and byte-order of the items in the file.
186
201
187 count : int
202 count : int
188 Number of items to read. -1 means all items (i.e., the complete file).
203 Number of items to read. -1 means all items (i.e., the complete file).
189
204
190 sep : str
205 sep : str
191 Separator between items if file is a text file. Empty ("") separator means
206 Separator between items if file is a text file. Empty ("") separator means
192 the file should be treated as binary. Spaces (" ") in the separator match zero
207 the file should be treated as binary. Spaces (" ") in the separator match zero
193 or more whitespace characters. A separator consisting only of spaces must match
208 or more whitespace characters. A separator consisting only of spaces must match
194 at least one whitespace.
209 at least one whitespace.
195
210
196 '''
211 '''
197
212
198
213 self.Hname = str(header['Hname'][0])
199 self.Hname= str(header['Hname'][0])
214 self.Htime = str(header['Htime'][0])
200 self.Htime= str(header['Htime'][0])
215 self.Hoper = str(header['Hoper'][0])
201 self.Hoper= str(header['Hoper'][0])
216 self.Hplace = str(header['Hplace'][0])
202 self.Hplace= str(header['Hplace'][0])
217 self.Hdescr = str(header['Hdescr'][0])
203 self.Hdescr= str(header['Hdescr'][0])
218 self.Hdummy = str(header['Hdummy'][0])
204 self.Hdummy= str(header['Hdummy'][0])
219 # 1024
205 #1024
220
206
221 self.Msign = str(header['Msign'][0])
207 self.Msign=str(header['Msign'][0])
222 self.MsizeData = header['MsizeData'][0]
208 self.MsizeData=header['MsizeData'][0]
223 # 8
209 #8
224
210
225 self.PPARsign = str(header['PPARsign'][0])
211 self.PPARsign=str(header['PPARsign'][0])
226 self.PPARsize = header['PPARsize'][0]
212 self.PPARsize=header['PPARsize'][0]
227 self.PPARprf = header['PPARprf'][0]
213 self.PPARprf=header['PPARprf'][0]
228 self.PPARpdr = header['PPARpdr'][0]
214 self.PPARpdr=header['PPARpdr'][0]
229 self.PPARsft = header['PPARsft'][0]
215 self.PPARsft=header['PPARsft'][0]
230 self.PPARavc = header['PPARavc'][0]
216 self.PPARavc=header['PPARavc'][0]
231 self.PPARihp = header['PPARihp'][0]
217 self.PPARihp=header['PPARihp'][0]
232 self.PPARchg = header['PPARchg'][0]
218 self.PPARchg=header['PPARchg'][0]
233 self.PPARpol = header['PPARpol'][0]
219 self.PPARpol=header['PPARpol'][0]
234 # Service DSP parameters
220 #Service DSP parameters
235 # 36
221 #36
236
222
237 self.SPARatt = header['SPARatt'][0]
223 self.SPARatt=header['SPARatt'][0]
238 self.SPARtx = header['SPARtx'][0]
224 self.SPARtx=header['SPARtx'][0]
239 self.SPARaddGain0 = header['SPARaddGain0'][0]
225 self.SPARaddGain0=header['SPARaddGain0'][0]
240 self.SPARaddGain1 = header['SPARaddGain1'][0]
226 self.SPARaddGain1=header['SPARaddGain1'][0]
241 self.SPARwnd = header['SPARwnd'][0]
227 self.SPARwnd=header['SPARwnd'][0]
242 self.SPARpos = header['SPARpos'][0]
228 self.SPARpos=header['SPARpos'][0]
243 self.SPARadd = header['SPARadd'][0]
229 self.SPARadd=header['SPARadd'][0]
244 self.SPARlen = header['SPARlen'][0]
230 self.SPARlen=header['SPARlen'][0]
245 self.SPARcal = header['SPARcal'][0]
231 self.SPARcal=header['SPARcal'][0]
246 self.SPARnos = header['SPARnos'][0]
232 self.SPARnos=header['SPARnos'][0]
247 self.SPARof0 = header['SPARof0'][0]
233 self.SPARof0=header['SPARof0'][0]
248 self.SPARof1 = header['SPARof1'][0]
234 self.SPARof1=header['SPARof1'][0]
249 self.SPARswt = header['SPARswt'][0]
235 self.SPARswt=header['SPARswt'][0]
250 self.SPARsum = header['SPARsum'][0]
236 self.SPARsum=header['SPARsum'][0]
251 self.SPARosc = header['SPARosc'][0]
237 self.SPARosc=header['SPARosc'][0]
252 self.SPARtst = header['SPARtst'][0]
238 self.SPARtst=header['SPARtst'][0]
253 self.SPARcor = header['SPARcor'][0]
239 self.SPARcor=header['SPARcor'][0]
254 self.SPARofs = header['SPARofs'][0]
240 self.SPARofs=header['SPARofs'][0]
255 self.SPARhsn = header['SPARhsn'][0]
241 self.SPARhsn=header['SPARhsn'][0]
256 self.SPARhsa = header['SPARhsa'][0]
242 self.SPARhsa=header['SPARhsa'][0]
257 self.SPARcalibPow_M = header['SPARcalibPow_M'][0]
243 self.SPARcalibPow_M=header['SPARcalibPow_M'][0]
258 self.SPARcalibSNR_M = header['SPARcalibSNR_M'][0]
244 self.SPARcalibSNR_M=header['SPARcalibSNR_M'][0]
259 self.SPARcalibPow_S = header['SPARcalibPow_S'][0]
245 self.SPARcalibPow_S=header['SPARcalibPow_S'][0]
260 self.SPARcalibSNR_S = header['SPARcalibSNR_S'][0]
246 self.SPARcalibSNR_S=header['SPARcalibSNR_S'][0]
261 self.SPARrawGate1 = header['SPARrawGate1'][0]
247 self.SPARrawGate1=header['SPARrawGate1'][0]
262 self.SPARrawGate2 = header['SPARrawGate2'][0]
248 self.SPARrawGate2=header['SPARrawGate2'][0]
263 self.SPARraw = header['SPARraw'][0]
249 self.SPARraw=header['SPARraw'][0]
264 self.SPARprc = header['SPARprc'][0]
250 self.SPARprc=header['SPARprc'][0]
265 # 112
251 #112
266 # 1180
252 #1180
267 # print 'Pointer fp header', fp.tell()
253 #print 'Pointer fp header', fp.tell()
268 # print ' '
254 #print ' '
269 # print 'SPARrawGate'
255 #print 'SPARrawGate'
270 # print self.SPARrawGate2 - self.SPARrawGate1
256 #print self.SPARrawGate2 - self.SPARrawGate1
271
257
272 # print ' '
258 #print ' '
273 # print 'Hname'
259 #print 'Hname'
274 # print self.Hname
260 #print self.Hname
275
261
276 # print ' '
262 #print ' '
277 # print 'Msign'
263 #print 'Msign'
278 # print self.Msign
264 #print self.Msign
279
265
266 def write(self, fp):
280 def write(self, fp):
267
281
268 headerTuple = (self.Hname,
282 headerTuple = (self.Hname,
269 self.Htime,
283 self.Htime,
270 self.Hoper,
284 self.Hoper,
271 self.Hplace,
285 self.Hplace,
272 self.Hdescr,
286 self.Hdescr,
273 self.Hdummy)
287 self.Hdummy)
274
288
275
276 header = numpy.array(headerTuple, FILE_HEADER)
289 header = numpy.array(headerTuple, FILE_HEADER)
277 # numpy.array(object, dtype=None, copy=True, order=None, subok=False, ndmin=0)
290 # numpy.array(object, dtype=None, copy=True, order=None, subok=False, ndmin=0)
278 header.tofile(fp)
291 header.tofile(fp)
279 ''' ndarray.tofile(fid, sep, format) Write array to a file as text or binary (default).
292 ''' ndarray.tofile(fid, sep, format) Write array to a file as text or binary (default).
280
293
281 fid : file or str
294 fid : file or str
282 An open file object, or a string containing a filename.
295 An open file object, or a string containing a filename.
283
296
284 sep : str
297 sep : str
285 Separator between array items for text output. If "" (empty), a binary file is written,
298 Separator between array items for text output. If "" (empty), a binary file is written,
286 equivalent to file.write(a.tobytes()).
299 equivalent to file.write(a.tobytes()).
287
300
288 format : str
301 format : str
289 Format string for text file output. Each entry in the array is formatted to text by
302 Format string for text file output. Each entry in the array is formatted to text by
290 first converting it to the closest Python type, and then using "format" % item.
303 first converting it to the closest Python type, and then using "format" % item.
291
304
292 '''
305 '''
293
306
294 return 1
307 return 1
295
308
296 SRVI_HEADER = numpy.dtype([
309
297 ('SignatureSRVI1',numpy.str_,4),#
310 SRVI_HEADER = numpy.dtype([
298 ('SizeOfDataBlock1','<i4'),#
311 ('SignatureSRVI1', numpy.str_, 4),
299 ('DataBlockTitleSRVI1',numpy.str_,4),#
312 ('SizeOfDataBlock1', '<i4'),
300 ('SizeOfSRVI1','<i4'),])#
313 ('DataBlockTitleSRVI1', numpy.str_, 4),
301
314 ('SizeOfSRVI1', '<i4'), ])
302 class SRVIHeader(Header):
315
316
317 class SRVIHeader(Header):
303 def __init__(self, SignatureSRVI1=0, SizeOfDataBlock1=0, DataBlockTitleSRVI1=0, SizeOfSRVI1=0):
318 def __init__(self, SignatureSRVI1=0, SizeOfDataBlock1=0, DataBlockTitleSRVI1=0, SizeOfSRVI1=0):
304
319
305 self.SignatureSRVI1 = SignatureSRVI1
320 self.SignatureSRVI1 = SignatureSRVI1
306 self.SizeOfDataBlock1 = SizeOfDataBlock1
321 self.SizeOfDataBlock1 = SizeOfDataBlock1
307 self.DataBlockTitleSRVI1 = DataBlockTitleSRVI1
322 self.DataBlockTitleSRVI1 = DataBlockTitleSRVI1
308 self.SizeOfSRVI1 = SizeOfSRVI1
323 self.SizeOfSRVI1 = SizeOfSRVI1
309
324
310 self.SRVIHsize=16
325 self.SRVIHsize = 16
311
326
312 def SRVIread(self, fp):
327 def SRVIread(self, fp):
313
328
314 header = numpy.fromfile(fp, SRVI_HEADER,1)
329 header = numpy.fromfile(fp, SRVI_HEADER, 1)
315
330
316 self.SignatureSRVI1 = str(header['SignatureSRVI1'][0])
331 self.SignatureSRVI1 = str(header['SignatureSRVI1'][0])
317 self.SizeOfDataBlock1 = header['SizeOfDataBlock1'][0]
332 self.SizeOfDataBlock1 = header['SizeOfDataBlock1'][0]
318 self.DataBlockTitleSRVI1 = str(header['DataBlockTitleSRVI1'][0])
333 self.DataBlockTitleSRVI1 = str(header['DataBlockTitleSRVI1'][0])
319 self.SizeOfSRVI1 = header['SizeOfSRVI1'][0]
334 self.SizeOfSRVI1 = header['SizeOfSRVI1'][0]
320 #16
335 # 16
321 print 'Pointer fp SRVIheader', fp.tell()
336 print 'Pointer fp SRVIheader', fp.tell()
322
323
324 SRVI_STRUCTURE = numpy.dtype([
325 ('frame_cnt','<u4'),#
326 ('time_t','<u4'), #
327 ('tpow','<f4'), #
328 ('npw1','<f4'), #
329 ('npw2','<f4'), #
330 ('cpw1','<f4'), #
331 ('pcw2','<f4'), #
332 ('ps_err','<u4'), #
333 ('te_err','<u4'), #
334 ('rc_err','<u4'), #
335 ('grs1','<u4'), #
336 ('grs2','<u4'), #
337 ('azipos','<f4'), #
338 ('azivel','<f4'), #
339 ('elvpos','<f4'), #
340 ('elvvel','<f4'), #
341 ('northAngle','<f4'), #
342 ('microsec','<u4'), #
343 ('azisetvel','<f4'), #
344 ('elvsetpos','<f4'), #
345 ('RadarConst','<f4'),]) #
346
337
347
338
339 SRVI_STRUCTURE = numpy.dtype([
340 ('frame_cnt', '<u4'),
341 ('time_t', '<u4'), #
342 ('tpow', '<f4'), #
343 ('npw1', '<f4'), #
344 ('npw2', '<f4'), #
345 ('cpw1', '<f4'), #
346 ('pcw2', '<f4'), #
347 ('ps_err', '<u4'), #
348 ('te_err', '<u4'), #
349 ('rc_err', '<u4'), #
350 ('grs1', '<u4'), #
351 ('grs2', '<u4'), #
352 ('azipos', '<f4'), #
353 ('azivel', '<f4'), #
354 ('elvpos', '<f4'), #
355 ('elvvel', '<f4'), #
356 ('northAngle', '<f4'),
357 ('microsec', '<u4'), #
358 ('azisetvel', '<f4'), #
359 ('elvsetpos', '<f4'), #
360 ('RadarConst', '<f4'), ]) #
348
361
349
362
350 class RecordHeader(Header):
363 class RecordHeader(Header):
351
364
352
365 def __init__(self, frame_cnt=0, time_t=0, tpow=0, npw1=0, npw2=0,
353 def __init__(self, frame_cnt=0, time_t= 0, tpow=0, npw1=0, npw2=0,
366 cpw1=0, pcw2=0, ps_err=0, te_err=0, rc_err=0, grs1=0,
354 cpw1=0, pcw2=0, ps_err=0, te_err=0, rc_err=0, grs1=0,
367 grs2=0, azipos=0, azivel=0, elvpos=0, elvvel=0, northangle=0,
355 grs2=0, azipos=0, azivel=0, elvpos=0, elvvel=0, northangle=0,
368 microsec=0, azisetvel=0, elvsetpos=0, RadarConst=0, RecCounter=0, Off2StartNxtRec=0):
356 microsec=0, azisetvel=0, elvsetpos=0, RadarConst=0 , RecCounter=0, Off2StartNxtRec=0):
369
357
358
359 self.frame_cnt = frame_cnt
370 self.frame_cnt = frame_cnt
360 self.dwell = time_t
371 self.dwell = time_t
361 self.tpow = tpow
372 self.tpow = tpow
362 self.npw1 = npw1
373 self.npw1 = npw1
363 self.npw2 = npw2
374 self.npw2 = npw2
364 self.cpw1 = cpw1
375 self.cpw1 = cpw1
365 self.pcw2 = pcw2
376 self.pcw2 = pcw2
366 self.ps_err = ps_err
377 self.ps_err = ps_err
367 self.te_err = te_err
378 self.te_err = te_err
368 self.rc_err = rc_err
379 self.rc_err = rc_err
369 self.grs1 = grs1
380 self.grs1 = grs1
370 self.grs2 = grs2
381 self.grs2 = grs2
371 self.azipos = azipos
382 self.azipos = azipos
372 self.azivel = azivel
383 self.azivel = azivel
373 self.elvpos = elvpos
384 self.elvpos = elvpos
374 self.elvvel = elvvel
385 self.elvvel = elvvel
375 self.northAngle = northangle
386 self.northAngle = northangle
376 self.microsec = microsec
387 self.microsec = microsec
377 self.azisetvel = azisetvel
388 self.azisetvel = azisetvel
378 self.elvsetpos = elvsetpos
389 self.elvsetpos = elvsetpos
379 self.RadarConst = RadarConst
390 self.RadarConst = RadarConst
380 self.RHsize=84
391 self.RHsize = 84
381 self.RecCounter = RecCounter
392 self.RecCounter = RecCounter
382 self.Off2StartNxtRec=Off2StartNxtRec
393 self.Off2StartNxtRec = Off2StartNxtRec
383
394
384 def RHread(self, fp):
395 def RHread(self, fp):
385
396
386 #startFp = open(fp,"rb") #The method tell() returns the current position of the file read/write pointer within the file.
397 # startFp = open(fp,"rb") #The method tell() returns the current position of the file read/write pointer within the file.
387
398
388 #OffRHeader= 1180 + self.RecCounter*(self.Off2StartNxtRec)
399 #OffRHeader= 1180 + self.RecCounter*(self.Off2StartNxtRec)
389 #startFp.seek(OffRHeader, os.SEEK_SET)
400 #startFp.seek(OffRHeader, os.SEEK_SET)
390
401
391 #print 'Posicion del bloque: ',OffRHeader
402 # print 'Posicion del bloque: ',OffRHeader
392
403
393 header = numpy.fromfile(fp,SRVI_STRUCTURE,1)
404 header = numpy.fromfile(fp, SRVI_STRUCTURE, 1)
394
405
395 self.frame_cnt = header['frame_cnt'][0]#
406 self.frame_cnt = header['frame_cnt'][0]
396 self.time_t = header['time_t'][0] #
407 self.time_t = header['time_t'][0] #
397 self.tpow = header['tpow'][0] #
408 self.tpow = header['tpow'][0] #
398 self.npw1 = header['npw1'][0] #
409 self.npw1 = header['npw1'][0] #
399 self.npw2 = header['npw2'][0] #
410 self.npw2 = header['npw2'][0] #
400 self.cpw1 = header['cpw1'][0] #
411 self.cpw1 = header['cpw1'][0] #
401 self.pcw2 = header['pcw2'][0] #
412 self.pcw2 = header['pcw2'][0] #
402 self.ps_err = header['ps_err'][0] #
413 self.ps_err = header['ps_err'][0] #
403 self.te_err = header['te_err'][0] #
414 self.te_err = header['te_err'][0] #
404 self.rc_err = header['rc_err'][0] #
415 self.rc_err = header['rc_err'][0] #
405 self.grs1 = header['grs1'][0] #
416 self.grs1 = header['grs1'][0] #
406 self.grs2 = header['grs2'][0] #
417 self.grs2 = header['grs2'][0] #
407 self.azipos = header['azipos'][0] #
418 self.azipos = header['azipos'][0] #
408 self.azivel = header['azivel'][0] #
419 self.azivel = header['azivel'][0] #
409 self.elvpos = header['elvpos'][0] #
420 self.elvpos = header['elvpos'][0] #
410 self.elvvel = header['elvvel'][0] #
421 self.elvvel = header['elvvel'][0] #
411 self.northAngle = header['northAngle'][0] #
422 self.northAngle = header['northAngle'][0] #
412 self.microsec = header['microsec'][0] #
423 self.microsec = header['microsec'][0] #
413 self.azisetvel = header['azisetvel'][0] #
424 self.azisetvel = header['azisetvel'][0] #
414 self.elvsetpos = header['elvsetpos'][0] #
425 self.elvsetpos = header['elvsetpos'][0] #
415 self.RadarConst = header['RadarConst'][0] #
426 self.RadarConst = header['RadarConst'][0] #
416 #84
427 # 84
417
428
418 #print 'Pointer fp RECheader', fp.tell()
429 # print 'Pointer fp RECheader', fp.tell()
419
430
420 #self.ipp= 0.5*(SPEED_OF_LIGHT/self.PRFhz)
431 #self.ipp= 0.5*(SPEED_OF_LIGHT/self.PRFhz)
421
432
422 #self.RHsize = 180+20*self.nChannels
433 #self.RHsize = 180+20*self.nChannels
423 #self.Datasize= self.nProfiles*self.nChannels*self.nHeights*2*4
434 #self.Datasize= self.nProfiles*self.nChannels*self.nHeights*2*4
424 #print 'Datasize',self.Datasize
435 # print 'Datasize',self.Datasize
425 #endFp = self.OffsetStartHeader + self.RecCounter*self.Off2StartNxtRec
436 #endFp = self.OffsetStartHeader + self.RecCounter*self.Off2StartNxtRec
426
437
427 print '=============================================='
438 print '=============================================='
428
439
429 print '=============================================='
440 print '=============================================='
430
441
431
432 return 1
442 return 1
433
443
434 class MIRA35CReader (ProcessingUnit,FileHeaderMIRA35c,SRVIHeader,RecordHeader):
444
435
445 class MIRA35CReader (ProcessingUnit, FileHeaderMIRA35c, SRVIHeader, RecordHeader):
446
436 path = None
447 path = None
437 startDate = None
448 startDate = None
438 endDate = None
449 endDate = None
439 startTime = None
450 startTime = None
440 endTime = None
451 endTime = None
441 walk = None
452 walk = None
442 isConfig = False
453 isConfig = False
443
454
444
455 fileList = None
445 fileList= None
456
446
457 # metadata
447 #metadata
458 TimeZone = None
448 TimeZone= None
459 Interval = None
449 Interval= None
460 heightList = None
450 heightList= None
461
451
462 # data
452 #data
463 data = None
453 data= None
464 utctime = None
454 utctime= None
465
455
466 def __init__(self, **kwargs):
456
467
457
468 # Eliminar de la base la herencia
458 def __init__(self, **kwargs):
459
460 #Eliminar de la base la herencia
461 ProcessingUnit.__init__(self, **kwargs)
469 ProcessingUnit.__init__(self, **kwargs)
462 self.PointerReader = 0
470 self.PointerReader = 0
463 self.FileHeaderFlag = False
471 self.FileHeaderFlag = False
464 self.utc = None
472 self.utc = None
465 self.ext = ".zspca"
473 self.ext = ".zspca"
466 self.optchar = "P"
474 self.optchar = "P"
467 self.fpFile=None
475 self.fpFile = None
468 self.fp = None
476 self.fp = None
469 self.BlockCounter=0
477 self.BlockCounter = 0
470 self.dtype = None
478 self.dtype = None
471 self.fileSizeByHeader = None
479 self.fileSizeByHeader = None
472 self.filenameList = []
480 self.filenameList = []
473 self.fileSelector = 0
481 self.fileSelector = 0
474 self.Off2StartNxtRec=0
482 self.Off2StartNxtRec = 0
475 self.RecCounter=0
483 self.RecCounter = 0
476 self.flagNoMoreFiles = 0
484 self.flagNoMoreFiles = 0
477 self.data_spc=None
485 self.data_spc = None
478 #self.data_cspc=None
486 # self.data_cspc=None
479 self.data_output=None
487 self.data_output = None
480 self.path = None
488 self.path = None
481 self.OffsetStartHeader=0
489 self.OffsetStartHeader = 0
482 self.Off2StartData=0
490 self.Off2StartData = 0
483 self.ipp = 0
491 self.ipp = 0
484 self.nFDTdataRecors=0
492 self.nFDTdataRecors = 0
485 self.blocksize = 0
493 self.blocksize = 0
486 self.dataOut = Spectra()
494 self.dataOut = Spectra()
487 self.profileIndex = 1 #Always
495 self.profileIndex = 1 # Always
488 self.dataOut.flagNoData=False
496 self.dataOut.flagNoData = False
489 self.dataOut.nRdPairs = 0
497 self.dataOut.nRdPairs = 0
490 self.dataOut.pairsList = []
498 self.dataOut.pairsList = []
491 self.dataOut.data_spc=None
499 self.dataOut.data_spc = None
492
500
493 self.dataOut.normFactor=1
501 self.dataOut.normFactor = 1
494 self.nextfileflag = True
502 self.nextfileflag = True
495 self.dataOut.RadarConst = 0
503 self.dataOut.RadarConst = 0
496 self.dataOut.HSDV = []
504 self.dataOut.HSDV = []
497 self.dataOut.NPW = []
505 self.dataOut.NPW = []
498 self.dataOut.COFA = []
506 self.dataOut.COFA = []
499 self.dataOut.noise = 0
507 self.dataOut.noise = 0
500
508
501
502 def Files2Read(self, fp):
509 def Files2Read(self, fp):
503 '''
510 '''
504 Function that indicates the number of .fdt files that exist in the folder to be read.
511 Function that indicates the number of .fdt files that exist in the folder to be read.
505 It also creates an organized list with the names of the files to read.
512 It also creates an organized list with the names of the files to read.
506 '''
513 '''
507 #self.__checkPath()
514 # self.__checkPath()
508
515
509 ListaData=os.listdir(fp) #Gets the list of files within the fp address
516 # Gets the list of files within the fp address
510 ListaData=sorted(ListaData) #Sort the list of files from least to largest by names
517 ListaData = os.listdir(fp)
511 nFiles=0 #File Counter
518 # Sort the list of files from least to largest by names
512 FileList=[] #A list is created that will contain the .fdt files
519 ListaData = sorted(ListaData)
513 for IndexFile in ListaData :
520 nFiles = 0 # File Counter
514 if '.zspca' in IndexFile and '.gz' not in IndexFile:
521 FileList = [] # A list is created that will contain the .fdt files
522 for IndexFile in ListaData:
523 if '.zspca' in IndexFile and '.gz' not in IndexFile:
515 FileList.append(IndexFile)
524 FileList.append(IndexFile)
516 nFiles+=1
525 nFiles += 1
517
526
518 #print 'Files2Read'
527 # print 'Files2Read'
519 #print 'Existen '+str(nFiles)+' archivos .fdt'
528 # print 'Existen '+str(nFiles)+' archivos .fdt'
520
529
521 self.filenameList=FileList #List of files from least to largest by names
530 self.filenameList = FileList # List of files from least to largest by names
522
531
523
524 def run(self, **kwargs):
532 def run(self, **kwargs):
525 '''
533 '''
526 This method will be the one that will initiate the data entry, will be called constantly.
534 This method will be the one that will initiate the data entry, will be called constantly.
527 You should first verify that your Setup () is set up and then continue to acquire
535 You should first verify that your Setup () is set up and then continue to acquire
528 the data to be processed with getData ().
536 the data to be processed with getData ().
529 '''
537 '''
530 if not self.isConfig:
538 if not self.isConfig:
531 self.setup(**kwargs)
539 self.setup(**kwargs)
532 self.isConfig = True
540 self.isConfig = True
533
541
534 self.getData()
542 self.getData()
535
543
536
537 def setup(self, path=None,
544 def setup(self, path=None,
538 startDate=None,
545 startDate=None,
539 endDate=None,
546 endDate=None,
540 startTime=None,
547 startTime=None,
541 endTime=None,
548 endTime=None,
542 walk=True,
549 walk=True,
543 timezone='utc',
550 timezone='utc',
544 code = None,
551 code=None,
545 online=False,
552 online=False,
546 ReadMode=None, **kwargs):
553 ReadMode=None, **kwargs):
547
554
548 self.isConfig = True
555 self.isConfig = True
549
556
550 self.path=path
557 self.path = path
551 self.startDate=startDate
558 self.startDate = startDate
552 self.endDate=endDate
559 self.endDate = endDate
553 self.startTime=startTime
560 self.startTime = startTime
554 self.endTime=endTime
561 self.endTime = endTime
555 self.walk=walk
562 self.walk = walk
556 #self.ReadMode=int(ReadMode)
563 # self.ReadMode=int(ReadMode)
557
564
558 pass
565 pass
559
566
560
561 def getData(self):
567 def getData(self):
562 '''
568 '''
563 Before starting this function, you should check that there is still an unread file,
569 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.
570 If there are still blocks to read or if the data block is empty.
565
571
566 You should call the file "read".
572 You should call the file "read".
567
573
568 '''
574 '''
569
575
570 if self.flagNoMoreFiles:
576 if self.flagNoMoreFiles:
571 self.dataOut.flagNoData = True
577 self.dataOut.flagNoData = True
572 print 'NoData se vuelve true'
578 print 'NoData se vuelve true'
573 return 0
579 return 0
574
580
575 self.fp=self.path
581 self.fp = self.path
576 self.Files2Read(self.fp)
582 self.Files2Read(self.fp)
577 self.readFile(self.fp)
583 self.readFile(self.fp)
578
584
579 self.dataOut.data_spc = self.dataOut_spc#self.data_spc.copy()
585 self.dataOut.data_spc = self.dataOut_spc # self.data_spc.copy()
580 self.dataOut.RadarConst = self.RadarConst
586 self.dataOut.RadarConst = self.RadarConst
581 self.dataOut.data_output=self.data_output
587 self.dataOut.data_output = self.data_output
582 self.dataOut.noise = self.dataOut.getNoise()
588 self.dataOut.noise = self.dataOut.getNoise()
583 #print 'ACAAAAAA', self.dataOut.noise
589 # print 'ACAAAAAA', self.dataOut.noise
584 self.dataOut.data_spc = self.dataOut.data_spc+self.dataOut.noise
590 self.dataOut.data_spc = self.dataOut.data_spc + self.dataOut.noise
585 #print 'self.dataOut.noise',self.dataOut.noise
591 # print 'self.dataOut.noise',self.dataOut.noise
586
592
587
588 return self.dataOut.data_spc
593 return self.dataOut.data_spc
589
594
590
595 def readFile(self, fp):
591 def readFile(self,fp):
592 '''
596 '''
593 You must indicate if you are reading in Online or Offline mode and load the
597 You must indicate if you are reading in Online or Offline mode and load the
594 The parameters for this file reading mode.
598 The parameters for this file reading mode.
595
599
596 Then you must do 2 actions:
600 Then you must do 2 actions:
597
601
598 1. Get the BLTR FileHeader.
602 1. Get the BLTR FileHeader.
599 2. Start reading the first block.
603 2. Start reading the first block.
600 '''
604 '''
601
605
602 #The address of the folder is generated the name of the .fdt file that will be read
606 # The address of the folder is generated the name of the .fdt file that will be read
603 print "File: ",self.fileSelector+1
607 print "File: ", self.fileSelector + 1
604
608
605 if self.fileSelector < len(self.filenameList):
609 if self.fileSelector < len(self.filenameList):
606
610
607 self.fpFile=str(fp)+'/'+str(self.filenameList[self.fileSelector])
611 self.fpFile = str(fp) + '/' + \
608
612 str(self.filenameList[self.fileSelector])
609 if self.nextfileflag==True:
613
610 self.fp = open(self.fpFile,"rb")
614 if self.nextfileflag == True:
611 self.nextfileflag==False
615 self.fp = open(self.fpFile, "rb")
612
616 self.nextfileflag == False
617
613 '''HERE STARTING THE FILE READING'''
618 '''HERE STARTING THE FILE READING'''
614
619
615
616 self.fheader = FileHeaderMIRA35c()
620 self.fheader = FileHeaderMIRA35c()
617 self.fheader.FHread(self.fp) #Bltr FileHeader Reading
621 self.fheader.FHread(self.fp) # Bltr FileHeader Reading
618
619
622
620 self.SPARrawGate1 = self.fheader.SPARrawGate1
623 self.SPARrawGate1 = self.fheader.SPARrawGate1
621 self.SPARrawGate2 = self.fheader.SPARrawGate2
624 self.SPARrawGate2 = self.fheader.SPARrawGate2
622 self.Num_Hei = self.SPARrawGate2 - self.SPARrawGate1
625 self.Num_Hei = self.SPARrawGate2 - self.SPARrawGate1
623 self.Num_Bins = self.fheader.PPARsft
626 self.Num_Bins = self.fheader.PPARsft
624 self.dataOut.nFFTPoints = self.fheader.PPARsft
627 self.dataOut.nFFTPoints = self.fheader.PPARsft
625
628
626
627 self.Num_inCoh = self.fheader.PPARavc
629 self.Num_inCoh = self.fheader.PPARavc
628 self.dataOut.PRF = self.fheader.PPARprf
630 self.dataOut.PRF = self.fheader.PPARprf
629 self.dataOut.frequency = 34.85*10**9
631 self.dataOut.frequency = 34.85 * 10**9
630 self.Lambda = SPEED_OF_LIGHT/self.dataOut.frequency
632 self.Lambda = SPEED_OF_LIGHT / self.dataOut.frequency
631 self.dataOut.ippSeconds= 1./float(self.dataOut.PRF)
633 self.dataOut.ippSeconds = 1. / float(self.dataOut.PRF)
632
634
633 pulse_width = self.fheader.PPARpdr * 10**-9
635 pulse_width = self.fheader.PPARpdr * 10**-9
634 self.__deltaHeigth = 0.5 * SPEED_OF_LIGHT * pulse_width
636 self.__deltaHeigth = 0.5 * SPEED_OF_LIGHT * pulse_width
635
637
636 self.data_spc = numpy.zeros((self.Num_Hei, self.Num_Bins,2))#
638 self.data_spc = numpy.zeros((self.Num_Hei, self.Num_Bins, 2))
637 self.dataOut.HSDV = numpy.zeros((self.Num_Hei, 2))
639 self.dataOut.HSDV = numpy.zeros((self.Num_Hei, 2))
638
640
639 self.Ze = numpy.zeros(self.Num_Hei)
641 self.Ze = numpy.zeros(self.Num_Hei)
640 self.ETA = numpy.zeros(([2,self.Num_Hei]))
642 self.ETA = numpy.zeros(([2, self.Num_Hei]))
641
643
642
644 self.readBlock() # Block reading
643
645
644 self.readBlock() #Block reading
645
646 else:
646 else:
647 print 'readFile FlagNoData becomes true'
647 print 'readFile FlagNoData becomes true'
648 self.flagNoMoreFiles=True
648 self.flagNoMoreFiles = True
649 self.dataOut.flagNoData = True
649 self.dataOut.flagNoData = True
650 self.FileHeaderFlag == True
650 self.FileHeaderFlag == True
651 return 0
651 return 0
652
652
653
653 def readBlock(self):
654
655 def readBlock(self):
656 '''
654 '''
657 It should be checked if the block has data, if it is not passed to the next file.
655 It should be checked if the block has data, if it is not passed to the next file.
658
656
659 Then the following is done:
657 Then the following is done:
660
658
661 1. Read the RecordHeader
659 1. Read the RecordHeader
662 2. Fill the buffer with the current block number.
660 2. Fill the buffer with the current block number.
663
661
664 '''
662 '''
665
663
666 if self.PointerReader > 1180:
664 if self.PointerReader > 1180:
667 self.fp.seek(self.PointerReader , os.SEEK_SET)
665 self.fp.seek(self.PointerReader, os.SEEK_SET)
668 self.FirstPoint = self.PointerReader
666 self.FirstPoint = self.PointerReader
669
667
670 else :
668 else:
671 self.FirstPoint = 1180
669 self.FirstPoint = 1180
672
670
673
674
675 self.srviHeader = SRVIHeader()
671 self.srviHeader = SRVIHeader()
676
672
677 self.srviHeader.SRVIread(self.fp) #Se obtiene la cabecera del SRVI
673 self.srviHeader.SRVIread(self.fp) # Se obtiene la cabecera del SRVI
678
674
679 self.blocksize = self.srviHeader.SizeOfDataBlock1 # Se obtiene el tamao del bloque
675 self.blocksize = self.srviHeader.SizeOfDataBlock1 # Se obtiene el tamao del bloque
680
676
681 if self.blocksize == 148:
677 if self.blocksize == 148:
682 print 'blocksize == 148 bug'
678 print 'blocksize == 148 bug'
683 jump = numpy.fromfile(self.fp,[('jump',numpy.str_,140)] ,1)
679 jump = numpy.fromfile(self.fp, [('jump', numpy.str_, 140)], 1)
684
680
685 self.srviHeader.SRVIread(self.fp) #Se obtiene la cabecera del SRVI
681 # Se obtiene la cabecera del SRVI
686
682 self.srviHeader.SRVIread(self.fp)
683
687 if not self.srviHeader.SizeOfSRVI1:
684 if not self.srviHeader.SizeOfSRVI1:
688 self.fileSelector+=1
685 self.fileSelector += 1
689 self.nextfileflag==True
686 self.nextfileflag == True
690 self.FileHeaderFlag == True
687 self.FileHeaderFlag == True
691
688
692 self.recordheader = RecordHeader()
689 self.recordheader = RecordHeader()
693 self.recordheader.RHread(self.fp)
690 self.recordheader.RHread(self.fp)
694 self.RadarConst = self.recordheader.RadarConst
691 self.RadarConst = self.recordheader.RadarConst
695 dwell = self.recordheader.time_t
692 dwell = self.recordheader.time_t
696 npw1 = self.recordheader.npw1
693 npw1 = self.recordheader.npw1
697 npw2 = self.recordheader.npw2
694 npw2 = self.recordheader.npw2
698
695
699
700 self.dataOut.channelList = range(1)
696 self.dataOut.channelList = range(1)
701 self.dataOut.nIncohInt = self.Num_inCoh
697 self.dataOut.nIncohInt = self.Num_inCoh
702 self.dataOut.nProfiles = self.Num_Bins
698 self.dataOut.nProfiles = self.Num_Bins
703 self.dataOut.nCohInt = 1
699 self.dataOut.nCohInt = 1
704 self.dataOut.windowOfFilter = 1
700 self.dataOut.windowOfFilter = 1
705 self.dataOut.utctime = dwell
701 self.dataOut.utctime = dwell
706 self.dataOut.timeZone=0
702 self.dataOut.timeZone = 0
707
703
708 self.dataOut.outputInterval = self.dataOut.getTimeInterval()
704 self.dataOut.outputInterval = self.dataOut.getTimeInterval()
709 self.dataOut.heightList = self.SPARrawGate1*self.__deltaHeigth + numpy.array(range(self.Num_Hei))*self.__deltaHeigth
705 self.dataOut.heightList = self.SPARrawGate1 * self.__deltaHeigth + \
710
706 numpy.array(range(self.Num_Hei)) * self.__deltaHeigth
711
707
712
708 self.HSDVsign = numpy.fromfile(self.fp, [('HSDV', numpy.str_, 4)], 1)
713 self.HSDVsign = numpy.fromfile( self.fp, [('HSDV',numpy.str_,4)],1)
709 self.SizeHSDV = numpy.fromfile(self.fp, [('SizeHSDV', '<i4')], 1)
714 self.SizeHSDV = numpy.fromfile( self.fp, [('SizeHSDV','<i4')],1)
710 self.HSDV_Co = numpy.fromfile(
715 self.HSDV_Co = numpy.fromfile( self.fp, [('HSDV_Co','<f4')],self.Num_Hei)
711 self.fp, [('HSDV_Co', '<f4')], self.Num_Hei)
716 self.HSDV_Cx = numpy.fromfile( self.fp, [('HSDV_Cx','<f4')],self.Num_Hei)
712 self.HSDV_Cx = numpy.fromfile(
717
713 self.fp, [('HSDV_Cx', '<f4')], self.Num_Hei)
718 self.COFAsign = numpy.fromfile( self.fp, [('COFA',numpy.str_,4)],1)
714
719 self.SizeCOFA = numpy.fromfile( self.fp, [('SizeCOFA','<i4')],1)
715 self.COFAsign = numpy.fromfile(self.fp, [('COFA', numpy.str_, 4)], 1)
720 self.COFA_Co = numpy.fromfile( self.fp, [('COFA_Co','<f4')],self.Num_Hei)
716 self.SizeCOFA = numpy.fromfile(self.fp, [('SizeCOFA', '<i4')], 1)
721 self.COFA_Cx = numpy.fromfile( self.fp, [('COFA_Cx','<f4')],self.Num_Hei)
717 self.COFA_Co = numpy.fromfile(
722
718 self.fp, [('COFA_Co', '<f4')], self.Num_Hei)
723 self.ZSPCsign = numpy.fromfile(self.fp, [('ZSPCsign',numpy.str_,4)],1)
719 self.COFA_Cx = numpy.fromfile(
724 self.SizeZSPC = numpy.fromfile(self.fp, [('SizeZSPC','<i4')],1)
720 self.fp, [('COFA_Cx', '<f4')], self.Num_Hei)
725
721
726 self.dataOut.HSDV[0]=self.HSDV_Co[:][0]
722 self.ZSPCsign = numpy.fromfile(
727 self.dataOut.HSDV[1]=self.HSDV_Cx[:][0]
723 self.fp, [('ZSPCsign', numpy.str_, 4)], 1)
728
724 self.SizeZSPC = numpy.fromfile(self.fp, [('SizeZSPC', '<i4')], 1)
725
726 self.dataOut.HSDV[0] = self.HSDV_Co[:][0]
727 self.dataOut.HSDV[1] = self.HSDV_Cx[:][0]
728
729 for irg in range(self.Num_Hei):
729 for irg in range(self.Num_Hei):
730 nspc = numpy.fromfile(self.fp, [('nspc','int16')],1)[0][0] # Number of spectral sub pieces containing significant power
730 # Number of spectral sub pieces containing significant power
731
731 nspc = numpy.fromfile(self.fp, [('nspc', 'int16')], 1)[0][0]
732
732 for k in range(nspc):
733 for k in range(nspc):
733 binIndex = numpy.fromfile(self.fp, [('binIndex','int16')],1)[0][0] # Index of the spectral bin where the piece is beginning
734 # Index of the spectral bin where the piece is beginning
734 nbins = numpy.fromfile(self.fp, [('nbins','int16')],1)[0][0] # Number of bins of the piece
735 binIndex = numpy.fromfile(
735
736 self.fp, [('binIndex', 'int16')], 1)[0][0]
736 #Co_Channel
737 nbins = numpy.fromfile(self.fp, [('nbins', 'int16')], 1)[
737 jbin = numpy.fromfile(self.fp, [('jbin','uint16')],nbins)[0][0] # Spectrum piece to be normaliced
738 0][0] # Number of bins of the piece
738 jmax = numpy.fromfile(self.fp, [('jmax','float32')],1)[0][0] # Maximun piece to be normaliced
739
739
740 # Co_Channel
740
741 jbin = numpy.fromfile(self.fp, [('jbin', 'uint16')], nbins)[
741 self.data_spc[irg,binIndex:binIndex+nbins,0] = self.data_spc[irg,binIndex:binIndex+nbins,0]+jbin/65530.*jmax
742 0][0] # Spectrum piece to be normaliced
742
743 jmax = numpy.fromfile(self.fp, [('jmax', 'float32')], 1)[
743 #Cx_Channel
744 0][0] # Maximun piece to be normaliced
744 jbin = numpy.fromfile(self.fp, [('jbin','uint16')],nbins)[0][0]
745
745 jmax = numpy.fromfile(self.fp, [('jmax','float32')],1)[0][0]
746 self.data_spc[irg, binIndex:binIndex + nbins, 0] = self.data_spc[irg,
746
747 binIndex:binIndex + nbins, 0] + jbin / 65530. * jmax
747
748
748 self.data_spc[irg,binIndex:binIndex+nbins,1] = self.data_spc[irg,binIndex:binIndex+nbins,1]+jbin/65530.*jmax
749 # Cx_Channel
749
750 jbin = numpy.fromfile(
750 for bin in range(self.Num_Bins):
751 self.fp, [('jbin', 'uint16')], nbins)[0][0]
751
752 jmax = numpy.fromfile(self.fp, [('jmax', 'float32')], 1)[0][0]
752 self.data_spc[:,bin,0] = self.data_spc[:,bin,0] - self.dataOut.HSDV[:,0]
753
753
754 self.data_spc[irg, binIndex:binIndex + nbins, 1] = self.data_spc[irg,
754 self.data_spc[:,bin,1] = self.data_spc[:,bin,1] - self.dataOut.HSDV[:,1]
755 binIndex:binIndex + nbins, 1] + jbin / 65530. * jmax
755
756
756
757 for bin in range(self.Num_Bins):
758
759 self.data_spc[:, bin, 0] = self.data_spc[:,
760 bin, 0] - self.dataOut.HSDV[:, 0]
761
762 self.data_spc[:, bin, 1] = self.data_spc[:,
763 bin, 1] - self.dataOut.HSDV[:, 1]
764
757 numpy.set_printoptions(threshold='nan')
765 numpy.set_printoptions(threshold='nan')
758
766
759 self.data_spc = numpy.where(self.data_spc > 0. , self.data_spc, 0)
767 self.data_spc = numpy.where(self.data_spc > 0., self.data_spc, 0)
760
768
761 self.dataOut.COFA = numpy.array([self.COFA_Co , self.COFA_Cx])
769 self.dataOut.COFA = numpy.array([self.COFA_Co, self.COFA_Cx])
762
770
763 print ' '
771 print ' '
764 print 'SPC',numpy.shape(self.dataOut.data_spc)
772 print 'SPC', numpy.shape(self.dataOut.data_spc)
765 #print 'SPC',self.dataOut.data_spc
773 # print 'SPC',self.dataOut.data_spc
766
774
767 noinor1 = 713031680
775 noinor1 = 713031680
768 noinor2 = 30
776 noinor2 = 30
769
777
770 npw1 = 1#0**(npw1/10) * noinor1 * noinor2
778 npw1 = 1 # 0**(npw1/10) * noinor1 * noinor2
771 npw2 = 1#0**(npw2/10) * noinor1 * noinor2
779 npw2 = 1 # 0**(npw2/10) * noinor1 * noinor2
772 self.dataOut.NPW = numpy.array([npw1, npw2])
780 self.dataOut.NPW = numpy.array([npw1, npw2])
773
781
774 print ' '
782 print ' '
775
783
776 self.data_spc = numpy.transpose(self.data_spc, (2,1,0))
784 self.data_spc = numpy.transpose(self.data_spc, (2, 1, 0))
777 self.data_spc = numpy.fft.fftshift(self.data_spc, axes = 1)
785 self.data_spc = numpy.fft.fftshift(self.data_spc, axes=1)
778
786
779 self.data_spc = numpy.fliplr(self.data_spc)
787 self.data_spc = numpy.fliplr(self.data_spc)
780
788
781 self.data_spc = numpy.where(self.data_spc > 0. , self.data_spc, 0)
789 self.data_spc = numpy.where(self.data_spc > 0., self.data_spc, 0)
782 self.dataOut_spc= numpy.ones([1, self.Num_Bins , self.Num_Hei])
790 self.dataOut_spc = numpy.ones([1, self.Num_Bins, self.Num_Hei])
783 self.dataOut_spc[0,:,:] = self.data_spc[0,:,:]
791 self.dataOut_spc[0, :, :] = self.data_spc[0, :, :]
784 #print 'SHAPE', self.dataOut_spc.shape
792 # print 'SHAPE', self.dataOut_spc.shape
785 #For nyquist correction:
793 # For nyquist correction:
786 #fix = 20 # ~3m/s
794 # fix = 20 # ~3m/s
787 #shift = self.Num_Bins/2 + fix
795 #shift = self.Num_Bins/2 + fix
788 #self.data_spc = numpy.array([ self.data_spc[: , self.Num_Bins-shift+1: , :] , self.data_spc[: , 0:self.Num_Bins-shift , :]])
796 #self.data_spc = numpy.array([ self.data_spc[: , self.Num_Bins-shift+1: , :] , self.data_spc[: , 0:self.Num_Bins-shift , :]])
789
797
790
791
792 '''Block Reading, the Block Data is received and Reshape is used to give it
798 '''Block Reading, the Block Data is received and Reshape is used to give it
793 shape.
799 shape.
794 '''
800 '''
795
801
796 self.PointerReader = self.fp.tell()
802 self.PointerReader = self.fp.tell()
797
798
799
800
801
802
803 No newline at end of file
@@ -1,4045 +1,4044
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
21
20
22 from scipy.optimize import fmin_l_bfgs_b #optimize with bounds on state papameters
21 from scipy.optimize import fmin_l_bfgs_b #optimize with bounds on state papameters
23 from jroproc_base import ProcessingUnit, Operation
22 from jroproc_base import ProcessingUnit, Operation
24 from schainpy.model.data.jrodata import Parameters, hildebrand_sekhon
23 from schainpy.model.data.jrodata import Parameters, hildebrand_sekhon
25 from scipy import asarray as ar,exp
24 from scipy import asarray as ar,exp
26 from scipy.optimize import curve_fit
25 from scipy.optimize import curve_fit
27
26
28 import warnings
27 import warnings
29 from numpy import NaN
28 from numpy import NaN
30 from scipy.optimize.optimize import OptimizeWarning
29 from scipy.optimize.optimize import OptimizeWarning
31 warnings.filterwarnings('ignore')
30 warnings.filterwarnings('ignore')
32
31
33
32
34 SPEED_OF_LIGHT = 299792458
33 SPEED_OF_LIGHT = 299792458
35
34
36
35
37 '''solving pickling issue'''
36 '''solving pickling issue'''
38
37
39 def _pickle_method(method):
38 def _pickle_method(method):
40 func_name = method.im_func.__name__
39 func_name = method.im_func.__name__
41 obj = method.im_self
40 obj = method.im_self
42 cls = method.im_class
41 cls = method.im_class
43 return _unpickle_method, (func_name, obj, cls)
42 return _unpickle_method, (func_name, obj, cls)
44
43
45 def _unpickle_method(func_name, obj, cls):
44 def _unpickle_method(func_name, obj, cls):
46 for cls in cls.mro():
45 for cls in cls.mro():
47 try:
46 try:
48 func = cls.__dict__[func_name]
47 func = cls.__dict__[func_name]
49 except KeyError:
48 except KeyError:
50 pass
49 pass
51 else:
50 else:
52 break
51 break
53 return func.__get__(obj, cls)
52 return func.__get__(obj, cls)
54
53
55 class ParametersProc(ProcessingUnit):
54 class ParametersProc(ProcessingUnit):
56
55
57 nSeconds = None
56 nSeconds = None
58
57
59 def __init__(self):
58 def __init__(self):
60 ProcessingUnit.__init__(self)
59 ProcessingUnit.__init__(self)
61
60
62 # self.objectDict = {}
61 # self.objectDict = {}
63 self.buffer = None
62 self.buffer = None
64 self.firstdatatime = None
63 self.firstdatatime = None
65 self.profIndex = 0
64 self.profIndex = 0
66 self.dataOut = Parameters()
65 self.dataOut = Parameters()
67
66
68 def __updateObjFromInput(self):
67 def __updateObjFromInput(self):
69
68
70 self.dataOut.inputUnit = self.dataIn.type
69 self.dataOut.inputUnit = self.dataIn.type
71
70
72 self.dataOut.timeZone = self.dataIn.timeZone
71 self.dataOut.timeZone = self.dataIn.timeZone
73 self.dataOut.dstFlag = self.dataIn.dstFlag
72 self.dataOut.dstFlag = self.dataIn.dstFlag
74 self.dataOut.errorCount = self.dataIn.errorCount
73 self.dataOut.errorCount = self.dataIn.errorCount
75 self.dataOut.useLocalTime = self.dataIn.useLocalTime
74 self.dataOut.useLocalTime = self.dataIn.useLocalTime
76
75
77 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
76 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
78 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
77 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
79 self.dataOut.channelList = self.dataIn.channelList
78 self.dataOut.channelList = self.dataIn.channelList
80 self.dataOut.heightList = self.dataIn.heightList
79 self.dataOut.heightList = self.dataIn.heightList
81 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
80 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
82 # self.dataOut.nHeights = self.dataIn.nHeights
81 # self.dataOut.nHeights = self.dataIn.nHeights
83 # self.dataOut.nChannels = self.dataIn.nChannels
82 # self.dataOut.nChannels = self.dataIn.nChannels
84 self.dataOut.nBaud = self.dataIn.nBaud
83 self.dataOut.nBaud = self.dataIn.nBaud
85 self.dataOut.nCode = self.dataIn.nCode
84 self.dataOut.nCode = self.dataIn.nCode
86 self.dataOut.code = self.dataIn.code
85 self.dataOut.code = self.dataIn.code
87 # self.dataOut.nProfiles = self.dataOut.nFFTPoints
86 # self.dataOut.nProfiles = self.dataOut.nFFTPoints
88 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
87 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
89 # self.dataOut.utctime = self.firstdatatime
88 # self.dataOut.utctime = self.firstdatatime
90 self.dataOut.utctime = self.dataIn.utctime
89 self.dataOut.utctime = self.dataIn.utctime
91 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
90 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
92 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
91 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
93 self.dataOut.nCohInt = self.dataIn.nCohInt
92 self.dataOut.nCohInt = self.dataIn.nCohInt
94 # self.dataOut.nIncohInt = 1
93 # self.dataOut.nIncohInt = 1
95 self.dataOut.ippSeconds = self.dataIn.ippSeconds
94 self.dataOut.ippSeconds = self.dataIn.ippSeconds
96 # self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
95 # self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
97 self.dataOut.timeInterval1 = self.dataIn.timeInterval
96 self.dataOut.timeInterval1 = self.dataIn.timeInterval
98 self.dataOut.heightList = self.dataIn.getHeiRange()
97 self.dataOut.heightList = self.dataIn.getHeiRange()
99 self.dataOut.frequency = self.dataIn.frequency
98 self.dataOut.frequency = self.dataIn.frequency
100 # self.dataOut.noise = self.dataIn.noise
99 # self.dataOut.noise = self.dataIn.noise
101
100
102 def run(self):
101 def run(self):
103
102
104 #---------------------- Voltage Data ---------------------------
103 #---------------------- Voltage Data ---------------------------
105
104
106 if self.dataIn.type == "Voltage":
105 if self.dataIn.type == "Voltage":
107
106
108 self.__updateObjFromInput()
107 self.__updateObjFromInput()
109 self.dataOut.data_pre = self.dataIn.data.copy()
108 self.dataOut.data_pre = self.dataIn.data.copy()
110 self.dataOut.flagNoData = False
109 self.dataOut.flagNoData = False
111 self.dataOut.utctimeInit = self.dataIn.utctime
110 self.dataOut.utctimeInit = self.dataIn.utctime
112 self.dataOut.paramInterval = self.dataIn.nProfiles*self.dataIn.nCohInt*self.dataIn.ippSeconds
111 self.dataOut.paramInterval = self.dataIn.nProfiles*self.dataIn.nCohInt*self.dataIn.ippSeconds
113 return
112 return
114
113
115 #---------------------- Spectra Data ---------------------------
114 #---------------------- Spectra Data ---------------------------
116
115
117 if self.dataIn.type == "Spectra":
116 if self.dataIn.type == "Spectra":
118
117
119 self.dataOut.data_pre = (self.dataIn.data_spc, self.dataIn.data_cspc)
118 self.dataOut.data_pre = (self.dataIn.data_spc, self.dataIn.data_cspc)
120 self.dataOut.data_spc = self.dataIn.data_spc
119 self.dataOut.data_spc = self.dataIn.data_spc
121 self.dataOut.data_cspc = self.dataIn.data_cspc
120 self.dataOut.data_cspc = self.dataIn.data_cspc
122 self.dataOut.nProfiles = self.dataIn.nProfiles
121 self.dataOut.nProfiles = self.dataIn.nProfiles
123 self.dataOut.nIncohInt = self.dataIn.nIncohInt
122 self.dataOut.nIncohInt = self.dataIn.nIncohInt
124 self.dataOut.nFFTPoints = self.dataIn.nFFTPoints
123 self.dataOut.nFFTPoints = self.dataIn.nFFTPoints
125 self.dataOut.ippFactor = self.dataIn.ippFactor
124 self.dataOut.ippFactor = self.dataIn.ippFactor
126 self.dataOut.abscissaList = self.dataIn.getVelRange(1)
125 self.dataOut.abscissaList = self.dataIn.getVelRange(1)
127 self.dataOut.spc_noise = self.dataIn.getNoise()
126 self.dataOut.spc_noise = self.dataIn.getNoise()
128 self.dataOut.spc_range = (self.dataIn.getFreqRange(1)/1000. , self.dataIn.getAcfRange(1) , self.dataIn.getVelRange(1))
127 self.dataOut.spc_range = (self.dataIn.getFreqRange(1)/1000. , self.dataIn.getAcfRange(1) , self.dataIn.getVelRange(1))
129 self.dataOut.pairsList = self.dataIn.pairsList
128 self.dataOut.pairsList = self.dataIn.pairsList
130 self.dataOut.groupList = self.dataIn.pairsList
129 self.dataOut.groupList = self.dataIn.pairsList
131 self.dataOut.flagNoData = False
130 self.dataOut.flagNoData = False
132
131
133 if hasattr(self.dataIn, 'ChanDist'): #Distances of receiver channels
132 if hasattr(self.dataIn, 'ChanDist'): #Distances of receiver channels
134 self.dataOut.ChanDist = self.dataIn.ChanDist
133 self.dataOut.ChanDist = self.dataIn.ChanDist
135 else: self.dataOut.ChanDist = None
134 else: self.dataOut.ChanDist = None
136
135
137 if hasattr(self.dataIn, 'VelRange'): #Velocities range
136 if hasattr(self.dataIn, 'VelRange'): #Velocities range
138 self.dataOut.VelRange = self.dataIn.VelRange
137 self.dataOut.VelRange = self.dataIn.VelRange
139 else: self.dataOut.VelRange = None
138 else: self.dataOut.VelRange = None
140
139
141 if hasattr(self.dataIn, 'RadarConst'): #Radar Constant
140 if hasattr(self.dataIn, 'RadarConst'): #Radar Constant
142 self.dataOut.RadarConst = self.dataIn.RadarConst
141 self.dataOut.RadarConst = self.dataIn.RadarConst
143
142
144 if hasattr(self.dataIn, 'NPW'): #NPW
143 if hasattr(self.dataIn, 'NPW'): #NPW
145 self.dataOut.NPW = self.dataIn.NPW
144 self.dataOut.NPW = self.dataIn.NPW
146
145
147 if hasattr(self.dataIn, 'COFA'): #COFA
146 if hasattr(self.dataIn, 'COFA'): #COFA
148 self.dataOut.COFA = self.dataIn.COFA
147 self.dataOut.COFA = self.dataIn.COFA
149
148
150
149
151
150
152 #---------------------- Correlation Data ---------------------------
151 #---------------------- Correlation Data ---------------------------
153
152
154 if self.dataIn.type == "Correlation":
153 if self.dataIn.type == "Correlation":
155 acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.dataIn.splitFunctions()
154 acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.dataIn.splitFunctions()
156
155
157 self.dataOut.data_pre = (self.dataIn.data_cf[acf_ind,:], self.dataIn.data_cf[ccf_ind,:,:])
156 self.dataOut.data_pre = (self.dataIn.data_cf[acf_ind,:], self.dataIn.data_cf[ccf_ind,:,:])
158 self.dataOut.normFactor = (self.dataIn.normFactor[acf_ind,:], self.dataIn.normFactor[ccf_ind,:])
157 self.dataOut.normFactor = (self.dataIn.normFactor[acf_ind,:], self.dataIn.normFactor[ccf_ind,:])
159 self.dataOut.groupList = (acf_pairs, ccf_pairs)
158 self.dataOut.groupList = (acf_pairs, ccf_pairs)
160
159
161 self.dataOut.abscissaList = self.dataIn.lagRange
160 self.dataOut.abscissaList = self.dataIn.lagRange
162 self.dataOut.noise = self.dataIn.noise
161 self.dataOut.noise = self.dataIn.noise
163 self.dataOut.data_SNR = self.dataIn.SNR
162 self.dataOut.data_SNR = self.dataIn.SNR
164 self.dataOut.flagNoData = False
163 self.dataOut.flagNoData = False
165 self.dataOut.nAvg = self.dataIn.nAvg
164 self.dataOut.nAvg = self.dataIn.nAvg
166
165
167 #---------------------- Parameters Data ---------------------------
166 #---------------------- Parameters Data ---------------------------
168
167
169 if self.dataIn.type == "Parameters":
168 if self.dataIn.type == "Parameters":
170 self.dataOut.copy(self.dataIn)
169 self.dataOut.copy(self.dataIn)
171 self.dataOut.flagNoData = False
170 self.dataOut.flagNoData = False
172
171
173 return True
172 return True
174
173
175 self.__updateObjFromInput()
174 self.__updateObjFromInput()
176 self.dataOut.utctimeInit = self.dataIn.utctime
175 self.dataOut.utctimeInit = self.dataIn.utctime
177 self.dataOut.paramInterval = self.dataIn.timeInterval
176 self.dataOut.paramInterval = self.dataIn.timeInterval
178
177
179 return
178 return
180
179
181
180
182 def target(tups):
181 def target(tups):
183
182
184 obj, args = tups
183 obj, args = tups
185 #print 'TARGETTT', obj, args
184 #print 'TARGETTT', obj, args
186 return obj.FitGau(args)
185 return obj.FitGau(args)
187
186
188 class GaussianFit(Operation):
187 class GaussianFit(Operation):
189
188
190 '''
189 '''
191 Function that fit of one and two generalized gaussians (gg) based
190 Function that fit of one and two generalized gaussians (gg) based
192 on the PSD shape across an "power band" identified from a cumsum of
191 on the PSD shape across an "power band" identified from a cumsum of
193 the measured spectrum - noise.
192 the measured spectrum - noise.
194
193
195 Input:
194 Input:
196 self.dataOut.data_pre : SelfSpectra
195 self.dataOut.data_pre : SelfSpectra
197
196
198 Output:
197 Output:
199 self.dataOut.GauSPC : SPC_ch1, SPC_ch2
198 self.dataOut.GauSPC : SPC_ch1, SPC_ch2
200
199
201 '''
200 '''
202 def __init__(self, **kwargs):
201 def __init__(self, **kwargs):
203 Operation.__init__(self, **kwargs)
202 Operation.__init__(self, **kwargs)
204 self.i=0
203 self.i=0
205
204
206
205
207 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
206 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
208 """This routine will find a couple of generalized Gaussians to a power spectrum
207 """This routine will find a couple of generalized Gaussians to a power spectrum
209 input: spc
208 input: spc
210 output:
209 output:
211 Amplitude0,shift0,width0,p0,Amplitude1,shift1,width1,p1,noise
210 Amplitude0,shift0,width0,p0,Amplitude1,shift1,width1,p1,noise
212 """
211 """
213
212
214 self.spc = dataOut.data_pre[0].copy()
213 self.spc = dataOut.data_pre[0].copy()
215
214
216
215
217 print 'SelfSpectra Shape', numpy.asarray(self.spc).shape
216 print 'SelfSpectra Shape', numpy.asarray(self.spc).shape
218
217
219
218
220 #plt.figure(50)
219 #plt.figure(50)
221 #plt.subplot(121)
220 #plt.subplot(121)
222 #plt.plot(self.spc,'k',label='spc(66)')
221 #plt.plot(self.spc,'k',label='spc(66)')
223 #plt.plot(xFrec,ySamples[1],'g',label='Ch1')
222 #plt.plot(xFrec,ySamples[1],'g',label='Ch1')
224 #plt.plot(xFrec,ySamples[2],'r',label='Ch2')
223 #plt.plot(xFrec,ySamples[2],'r',label='Ch2')
225 #plt.plot(xFrec,FitGauss,'yo:',label='fit')
224 #plt.plot(xFrec,FitGauss,'yo:',label='fit')
226 #plt.legend()
225 #plt.legend()
227 #plt.title('DATOS A ALTURA DE 7500 METROS')
226 #plt.title('DATOS A ALTURA DE 7500 METROS')
228 #plt.show()
227 #plt.show()
229
228
230 self.Num_Hei = self.spc.shape[2]
229 self.Num_Hei = self.spc.shape[2]
231 #self.Num_Bin = len(self.spc)
230 #self.Num_Bin = len(self.spc)
232 self.Num_Bin = self.spc.shape[1]
231 self.Num_Bin = self.spc.shape[1]
233 self.Num_Chn = self.spc.shape[0]
232 self.Num_Chn = self.spc.shape[0]
234
233
235 Vrange = dataOut.abscissaList
234 Vrange = dataOut.abscissaList
236
235
237 #print 'self.spc2', numpy.asarray(self.spc).shape
236 #print 'self.spc2', numpy.asarray(self.spc).shape
238
237
239 GauSPC = numpy.empty([2,self.Num_Bin,self.Num_Hei])
238 GauSPC = numpy.empty([2,self.Num_Bin,self.Num_Hei])
240 SPC_ch1 = numpy.empty([self.Num_Bin,self.Num_Hei])
239 SPC_ch1 = numpy.empty([self.Num_Bin,self.Num_Hei])
241 SPC_ch2 = numpy.empty([self.Num_Bin,self.Num_Hei])
240 SPC_ch2 = numpy.empty([self.Num_Bin,self.Num_Hei])
242 SPC_ch1[:] = numpy.NaN
241 SPC_ch1[:] = numpy.NaN
243 SPC_ch2[:] = numpy.NaN
242 SPC_ch2[:] = numpy.NaN
244
243
245
244
246 start_time = time.time()
245 start_time = time.time()
247
246
248 noise_ = dataOut.spc_noise[0].copy()
247 noise_ = dataOut.spc_noise[0].copy()
249
248
250
249
251
250
252 pool = Pool(processes=self.Num_Chn)
251 pool = Pool(processes=self.Num_Chn)
253 args = [(Vrange, Ch, pnoise, noise_, num_intg, SNRlimit) for Ch in range(self.Num_Chn)]
252 args = [(Vrange, Ch, pnoise, noise_, num_intg, SNRlimit) for Ch in range(self.Num_Chn)]
254 objs = [self for __ in range(self.Num_Chn)]
253 objs = [self for __ in range(self.Num_Chn)]
255 attrs = zip(objs, args)
254 attrs = zip(objs, args)
256 gauSPC = pool.map(target, attrs)
255 gauSPC = pool.map(target, attrs)
257 dataOut.GauSPC = numpy.asarray(gauSPC)
256 dataOut.GauSPC = numpy.asarray(gauSPC)
258 # ret = []
257 # ret = []
259 # for n in range(self.Num_Chn):
258 # for n in range(self.Num_Chn):
260 # self.FitGau(args[n])
259 # self.FitGau(args[n])
261 # dataOut.GauSPC = ret
260 # dataOut.GauSPC = ret
262
261
263
262
264
263
265 # for ch in range(self.Num_Chn):
264 # for ch in range(self.Num_Chn):
266 #
265 #
267 # for ht in range(self.Num_Hei):
266 # for ht in range(self.Num_Hei):
268 # #print (numpy.asarray(self.spc).shape)
267 # #print (numpy.asarray(self.spc).shape)
269 # spc = numpy.asarray(self.spc)[ch,:,ht]
268 # spc = numpy.asarray(self.spc)[ch,:,ht]
270 #
269 #
271 # #############################################
270 # #############################################
272 # # normalizing spc and noise
271 # # normalizing spc and noise
273 # # This part differs from gg1
272 # # This part differs from gg1
274 # spc_norm_max = max(spc)
273 # spc_norm_max = max(spc)
275 # spc = spc / spc_norm_max
274 # spc = spc / spc_norm_max
276 # pnoise = pnoise / spc_norm_max
275 # pnoise = pnoise / spc_norm_max
277 # #############################################
276 # #############################################
278 #
277 #
279 # if abs(vel_arr[0])<15.0: # this switch is for spectra collected with different length IPP's
278 # if abs(vel_arr[0])<15.0: # this switch is for spectra collected with different length IPP's
280 # fatspectra=1.0
279 # fatspectra=1.0
281 # else:
280 # else:
282 # fatspectra=0.5
281 # fatspectra=0.5
283 #
282 #
284 # wnoise = noise_ / spc_norm_max
283 # wnoise = noise_ / spc_norm_max
285 # #print 'wnoise', noise_, dataOut.spc_noise[0], wnoise
284 # #print 'wnoise', noise_, dataOut.spc_noise[0], wnoise
286 # #wnoise,stdv,i_max,index =enoise(spc,num_intg) #noise estimate using Hildebrand Sekhon, only wnoise is used
285 # #wnoise,stdv,i_max,index =enoise(spc,num_intg) #noise estimate using Hildebrand Sekhon, only wnoise is used
287 # #if wnoise>1.1*pnoise: # to be tested later
286 # #if wnoise>1.1*pnoise: # to be tested later
288 # # wnoise=pnoise
287 # # wnoise=pnoise
289 # noisebl=wnoise*0.9; noisebh=wnoise*1.1
288 # noisebl=wnoise*0.9; noisebh=wnoise*1.1
290 # spc=spc-wnoise
289 # spc=spc-wnoise
291 #
290 #
292 # minx=numpy.argmin(spc)
291 # minx=numpy.argmin(spc)
293 # spcs=numpy.roll(spc,-minx)
292 # spcs=numpy.roll(spc,-minx)
294 # cum=numpy.cumsum(spcs)
293 # cum=numpy.cumsum(spcs)
295 # tot_noise=wnoise * self.Num_Bin #64;
294 # tot_noise=wnoise * self.Num_Bin #64;
296 # #tot_signal=sum(cum[-5:])/5.; ''' How does this line work? '''
295 # #tot_signal=sum(cum[-5:])/5.; ''' How does this line work? '''
297 # #snr=tot_signal/tot_noise
296 # #snr=tot_signal/tot_noise
298 # #snr=cum[-1]/tot_noise
297 # #snr=cum[-1]/tot_noise
299 #
298 #
300 # #print 'spc' , spcs[5:8] , 'tot_noise', tot_noise
299 # #print 'spc' , spcs[5:8] , 'tot_noise', tot_noise
301 #
300 #
302 # snr = sum(spcs)/tot_noise
301 # snr = sum(spcs)/tot_noise
303 # snrdB=10.*numpy.log10(snr)
302 # snrdB=10.*numpy.log10(snr)
304 #
303 #
305 # #if snrdB < -9 :
304 # #if snrdB < -9 :
306 # # snrdB = numpy.NaN
305 # # snrdB = numpy.NaN
307 # # continue
306 # # continue
308 #
307 #
309 # #print 'snr',snrdB # , sum(spcs) , tot_noise
308 # #print 'snr',snrdB # , sum(spcs) , tot_noise
310 #
309 #
311 #
310 #
312 # #if snrdB<-18 or numpy.isnan(snrdB) or num_intg<4:
311 # #if snrdB<-18 or numpy.isnan(snrdB) or num_intg<4:
313 # # return [None,]*4,[None,]*4,None,snrdB,None,None,[None,]*5,[None,]*9,None
312 # # return [None,]*4,[None,]*4,None,snrdB,None,None,[None,]*5,[None,]*9,None
314 #
313 #
315 # cummax=max(cum); epsi=0.08*fatspectra # cumsum to narrow down the energy region
314 # cummax=max(cum); epsi=0.08*fatspectra # cumsum to narrow down the energy region
316 # cumlo=cummax*epsi;
315 # cumlo=cummax*epsi;
317 # cumhi=cummax*(1-epsi)
316 # cumhi=cummax*(1-epsi)
318 # powerindex=numpy.array(numpy.where(numpy.logical_and(cum>cumlo, cum<cumhi))[0])
317 # powerindex=numpy.array(numpy.where(numpy.logical_and(cum>cumlo, cum<cumhi))[0])
319 #
318 #
320 # #if len(powerindex)==1:
319 # #if len(powerindex)==1:
321 # ##return [numpy.mod(powerindex[0]+minx,64),None,None,None,],[None,]*4,None,snrdB,None,None,[None,]*5,[None,]*9,None
320 # ##return [numpy.mod(powerindex[0]+minx,64),None,None,None,],[None,]*4,None,snrdB,None,None,[None,]*5,[None,]*9,None
322 # #return [numpy.mod(powerindex[0]+minx, self.Num_Bin ),None,None,None,],[None,]*4,None,snrdB,None,None,[None,]*5,[None,]*9,None
321 # #return [numpy.mod(powerindex[0]+minx, self.Num_Bin ),None,None,None,],[None,]*4,None,snrdB,None,None,[None,]*5,[None,]*9,None
323 # #elif len(powerindex)<4*fatspectra:
322 # #elif len(powerindex)<4*fatspectra:
324 # #return [None,]*4,[None,]*4,None,snrdB,None,None,[None,]*5,[None,]*9,None
323 # #return [None,]*4,[None,]*4,None,snrdB,None,None,[None,]*5,[None,]*9,None
325 #
324 #
326 # if len(powerindex) < 1:# case for powerindex 0
325 # if len(powerindex) < 1:# case for powerindex 0
327 # continue
326 # continue
328 # powerlo=powerindex[0]
327 # powerlo=powerindex[0]
329 # powerhi=powerindex[-1]
328 # powerhi=powerindex[-1]
330 # powerwidth=powerhi-powerlo
329 # powerwidth=powerhi-powerlo
331 #
330 #
332 # firstpeak=powerlo+powerwidth/10.# first gaussian energy location
331 # firstpeak=powerlo+powerwidth/10.# first gaussian energy location
333 # secondpeak=powerhi-powerwidth/10.#second gaussian energy location
332 # secondpeak=powerhi-powerwidth/10.#second gaussian energy location
334 # midpeak=(firstpeak+secondpeak)/2.
333 # midpeak=(firstpeak+secondpeak)/2.
335 # firstamp=spcs[int(firstpeak)]
334 # firstamp=spcs[int(firstpeak)]
336 # secondamp=spcs[int(secondpeak)]
335 # secondamp=spcs[int(secondpeak)]
337 # midamp=spcs[int(midpeak)]
336 # midamp=spcs[int(midpeak)]
338 # #x=numpy.spc.shape[1]
337 # #x=numpy.spc.shape[1]
339 #
338 #
340 # #x=numpy.arange(64)
339 # #x=numpy.arange(64)
341 # x=numpy.arange( self.Num_Bin )
340 # x=numpy.arange( self.Num_Bin )
342 # y_data=spc+wnoise
341 # y_data=spc+wnoise
343 #
342 #
344 # # single gaussian
343 # # single gaussian
345 # #shift0=numpy.mod(midpeak+minx,64)
344 # #shift0=numpy.mod(midpeak+minx,64)
346 # shift0=numpy.mod(midpeak+minx, self.Num_Bin )
345 # shift0=numpy.mod(midpeak+minx, self.Num_Bin )
347 # width0=powerwidth/4.#Initialization entire power of spectrum divided by 4
346 # width0=powerwidth/4.#Initialization entire power of spectrum divided by 4
348 # power0=2.
347 # power0=2.
349 # amplitude0=midamp
348 # amplitude0=midamp
350 # state0=[shift0,width0,amplitude0,power0,wnoise]
349 # state0=[shift0,width0,amplitude0,power0,wnoise]
351 # #bnds=((0,63),(1,powerwidth),(0,None),(0.5,3.),(noisebl,noisebh))
350 # #bnds=((0,63),(1,powerwidth),(0,None),(0.5,3.),(noisebl,noisebh))
352 # bnds=(( 0,(self.Num_Bin-1) ),(1,powerwidth),(0,None),(0.5,3.),(noisebl,noisebh))
351 # bnds=(( 0,(self.Num_Bin-1) ),(1,powerwidth),(0,None),(0.5,3.),(noisebl,noisebh))
353 # #bnds=(( 0,(self.Num_Bin-1) ),(1,powerwidth),(0,None),(0.5,3.),(0.1,0.5))
352 # #bnds=(( 0,(self.Num_Bin-1) ),(1,powerwidth),(0,None),(0.5,3.),(0.1,0.5))
354 # # bnds = range of fft, power width, amplitude, power, noise
353 # # bnds = range of fft, power width, amplitude, power, noise
355 # lsq1=fmin_l_bfgs_b(self.misfit1,state0,args=(y_data,x,num_intg),bounds=bnds,approx_grad=True)
354 # lsq1=fmin_l_bfgs_b(self.misfit1,state0,args=(y_data,x,num_intg),bounds=bnds,approx_grad=True)
356 #
355 #
357 # chiSq1=lsq1[1];
356 # chiSq1=lsq1[1];
358 # jack1= self.y_jacobian1(x,lsq1[0])
357 # jack1= self.y_jacobian1(x,lsq1[0])
359 #
358 #
360 #
359 #
361 # try:
360 # try:
362 # sigmas1=numpy.sqrt(chiSq1*numpy.diag(numpy.linalg.inv(numpy.dot(jack1.T,jack1))))
361 # sigmas1=numpy.sqrt(chiSq1*numpy.diag(numpy.linalg.inv(numpy.dot(jack1.T,jack1))))
363 # except:
362 # except:
364 # std1=32.; sigmas1=numpy.ones(5)
363 # std1=32.; sigmas1=numpy.ones(5)
365 # else:
364 # else:
366 # std1=sigmas1[0]
365 # std1=sigmas1[0]
367 #
366 #
368 #
367 #
369 # if fatspectra<1.0 and powerwidth<4:
368 # if fatspectra<1.0 and powerwidth<4:
370 # choice=0
369 # choice=0
371 # Amplitude0=lsq1[0][2]
370 # Amplitude0=lsq1[0][2]
372 # shift0=lsq1[0][0]
371 # shift0=lsq1[0][0]
373 # width0=lsq1[0][1]
372 # width0=lsq1[0][1]
374 # p0=lsq1[0][3]
373 # p0=lsq1[0][3]
375 # Amplitude1=0.
374 # Amplitude1=0.
376 # shift1=0.
375 # shift1=0.
377 # width1=0.
376 # width1=0.
378 # p1=0.
377 # p1=0.
379 # noise=lsq1[0][4]
378 # noise=lsq1[0][4]
380 # #return (numpy.array([shift0,width0,Amplitude0,p0]),
379 # #return (numpy.array([shift0,width0,Amplitude0,p0]),
381 # # numpy.array([shift1,width1,Amplitude1,p1]),noise,snrdB,chiSq1,6.,sigmas1,[None,]*9,choice)
380 # # numpy.array([shift1,width1,Amplitude1,p1]),noise,snrdB,chiSq1,6.,sigmas1,[None,]*9,choice)
382 #
381 #
383 # # two gaussians
382 # # two gaussians
384 # #shift0=numpy.mod(firstpeak+minx,64); shift1=numpy.mod(secondpeak+minx,64)
383 # #shift0=numpy.mod(firstpeak+minx,64); shift1=numpy.mod(secondpeak+minx,64)
385 # shift0=numpy.mod(firstpeak+minx, self.Num_Bin );
384 # shift0=numpy.mod(firstpeak+minx, self.Num_Bin );
386 # shift1=numpy.mod(secondpeak+minx, self.Num_Bin )
385 # shift1=numpy.mod(secondpeak+minx, self.Num_Bin )
387 # width0=powerwidth/6.;
386 # width0=powerwidth/6.;
388 # width1=width0
387 # width1=width0
389 # power0=2.;
388 # power0=2.;
390 # power1=power0
389 # power1=power0
391 # amplitude0=firstamp;
390 # amplitude0=firstamp;
392 # amplitude1=secondamp
391 # amplitude1=secondamp
393 # state0=[shift0,width0,amplitude0,power0,shift1,width1,amplitude1,power1,wnoise]
392 # state0=[shift0,width0,amplitude0,power0,shift1,width1,amplitude1,power1,wnoise]
394 # #bnds=((0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(noisebl,noisebh))
393 # #bnds=((0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(noisebl,noisebh))
395 # 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))
394 # 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))
396 # #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))
395 # #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))
397 #
396 #
398 # lsq2=fmin_l_bfgs_b(self.misfit2,state0,args=(y_data,x,num_intg),bounds=bnds,approx_grad=True)
397 # lsq2=fmin_l_bfgs_b(self.misfit2,state0,args=(y_data,x,num_intg),bounds=bnds,approx_grad=True)
399 #
398 #
400 #
399 #
401 # chiSq2=lsq2[1]; jack2=self.y_jacobian2(x,lsq2[0])
400 # chiSq2=lsq2[1]; jack2=self.y_jacobian2(x,lsq2[0])
402 #
401 #
403 #
402 #
404 # try:
403 # try:
405 # sigmas2=numpy.sqrt(chiSq2*numpy.diag(numpy.linalg.inv(numpy.dot(jack2.T,jack2))))
404 # sigmas2=numpy.sqrt(chiSq2*numpy.diag(numpy.linalg.inv(numpy.dot(jack2.T,jack2))))
406 # except:
405 # except:
407 # std2a=32.; std2b=32.; sigmas2=numpy.ones(9)
406 # std2a=32.; std2b=32.; sigmas2=numpy.ones(9)
408 # else:
407 # else:
409 # std2a=sigmas2[0]; std2b=sigmas2[4]
408 # std2a=sigmas2[0]; std2b=sigmas2[4]
410 #
409 #
411 #
410 #
412 #
411 #
413 # 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)
412 # 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)
414 #
413 #
415 # if snrdB>-9: # when SNR is strong pick the peak with least shift (LOS velocity) error
414 # if snrdB>-9: # when SNR is strong pick the peak with least shift (LOS velocity) error
416 # if oneG:
415 # if oneG:
417 # choice=0
416 # choice=0
418 # else:
417 # else:
419 # w1=lsq2[0][1]; w2=lsq2[0][5]
418 # w1=lsq2[0][1]; w2=lsq2[0][5]
420 # a1=lsq2[0][2]; a2=lsq2[0][6]
419 # a1=lsq2[0][2]; a2=lsq2[0][6]
421 # p1=lsq2[0][3]; p2=lsq2[0][7]
420 # p1=lsq2[0][3]; p2=lsq2[0][7]
422 # s1=(2**(1+1./p1))*scipy.special.gamma(1./p1)/p1; s2=(2**(1+1./p2))*scipy.special.gamma(1./p2)/p2;
421 # s1=(2**(1+1./p1))*scipy.special.gamma(1./p1)/p1; s2=(2**(1+1./p2))*scipy.special.gamma(1./p2)/p2;
423 # gp1=a1*w1*s1; gp2=a2*w2*s2 # power content of each ggaussian with proper p scaling
422 # gp1=a1*w1*s1; gp2=a2*w2*s2 # power content of each ggaussian with proper p scaling
424 #
423 #
425 # if gp1>gp2:
424 # if gp1>gp2:
426 # if a1>0.7*a2:
425 # if a1>0.7*a2:
427 # choice=1
426 # choice=1
428 # else:
427 # else:
429 # choice=2
428 # choice=2
430 # elif gp2>gp1:
429 # elif gp2>gp1:
431 # if a2>0.7*a1:
430 # if a2>0.7*a1:
432 # choice=2
431 # choice=2
433 # else:
432 # else:
434 # choice=1
433 # choice=1
435 # else:
434 # else:
436 # choice=numpy.argmax([a1,a2])+1
435 # choice=numpy.argmax([a1,a2])+1
437 # #else:
436 # #else:
438 # #choice=argmin([std2a,std2b])+1
437 # #choice=argmin([std2a,std2b])+1
439 #
438 #
440 # else: # with low SNR go to the most energetic peak
439 # else: # with low SNR go to the most energetic peak
441 # choice=numpy.argmax([lsq1[0][2]*lsq1[0][1],lsq2[0][2]*lsq2[0][1],lsq2[0][6]*lsq2[0][5]])
440 # choice=numpy.argmax([lsq1[0][2]*lsq1[0][1],lsq2[0][2]*lsq2[0][1],lsq2[0][6]*lsq2[0][5]])
442 #
441 #
443 # #print 'choice',choice
442 # #print 'choice',choice
444 #
443 #
445 # if choice==0: # pick the single gaussian fit
444 # if choice==0: # pick the single gaussian fit
446 # Amplitude0=lsq1[0][2]
445 # Amplitude0=lsq1[0][2]
447 # shift0=lsq1[0][0]
446 # shift0=lsq1[0][0]
448 # width0=lsq1[0][1]
447 # width0=lsq1[0][1]
449 # p0=lsq1[0][3]
448 # p0=lsq1[0][3]
450 # Amplitude1=0.
449 # Amplitude1=0.
451 # shift1=0.
450 # shift1=0.
452 # width1=0.
451 # width1=0.
453 # p1=0.
452 # p1=0.
454 # noise=lsq1[0][4]
453 # noise=lsq1[0][4]
455 # elif choice==1: # take the first one of the 2 gaussians fitted
454 # elif choice==1: # take the first one of the 2 gaussians fitted
456 # Amplitude0 = lsq2[0][2]
455 # Amplitude0 = lsq2[0][2]
457 # shift0 = lsq2[0][0]
456 # shift0 = lsq2[0][0]
458 # width0 = lsq2[0][1]
457 # width0 = lsq2[0][1]
459 # p0 = lsq2[0][3]
458 # p0 = lsq2[0][3]
460 # Amplitude1 = lsq2[0][6] # This is 0 in gg1
459 # Amplitude1 = lsq2[0][6] # This is 0 in gg1
461 # shift1 = lsq2[0][4] # This is 0 in gg1
460 # shift1 = lsq2[0][4] # This is 0 in gg1
462 # width1 = lsq2[0][5] # This is 0 in gg1
461 # width1 = lsq2[0][5] # This is 0 in gg1
463 # p1 = lsq2[0][7] # This is 0 in gg1
462 # p1 = lsq2[0][7] # This is 0 in gg1
464 # noise = lsq2[0][8]
463 # noise = lsq2[0][8]
465 # else: # the second one
464 # else: # the second one
466 # Amplitude0 = lsq2[0][6]
465 # Amplitude0 = lsq2[0][6]
467 # shift0 = lsq2[0][4]
466 # shift0 = lsq2[0][4]
468 # width0 = lsq2[0][5]
467 # width0 = lsq2[0][5]
469 # p0 = lsq2[0][7]
468 # p0 = lsq2[0][7]
470 # Amplitude1 = lsq2[0][2] # This is 0 in gg1
469 # Amplitude1 = lsq2[0][2] # This is 0 in gg1
471 # shift1 = lsq2[0][0] # This is 0 in gg1
470 # shift1 = lsq2[0][0] # This is 0 in gg1
472 # width1 = lsq2[0][1] # This is 0 in gg1
471 # width1 = lsq2[0][1] # This is 0 in gg1
473 # p1 = lsq2[0][3] # This is 0 in gg1
472 # p1 = lsq2[0][3] # This is 0 in gg1
474 # noise = lsq2[0][8]
473 # noise = lsq2[0][8]
475 #
474 #
476 # #print len(noise + Amplitude0*numpy.exp(-0.5*(abs(x-shift0))/width0)**p0)
475 # #print len(noise + Amplitude0*numpy.exp(-0.5*(abs(x-shift0))/width0)**p0)
477 # SPC_ch1[:,ht] = noise + Amplitude0*numpy.exp(-0.5*(abs(x-shift0))/width0)**p0
476 # SPC_ch1[:,ht] = noise + Amplitude0*numpy.exp(-0.5*(abs(x-shift0))/width0)**p0
478 # SPC_ch2[:,ht] = noise + Amplitude1*numpy.exp(-0.5*(abs(x-shift1))/width1)**p1
477 # SPC_ch2[:,ht] = noise + Amplitude1*numpy.exp(-0.5*(abs(x-shift1))/width1)**p1
479 # #print 'SPC_ch1.shape',SPC_ch1.shape
478 # #print 'SPC_ch1.shape',SPC_ch1.shape
480 # #print 'SPC_ch2.shape',SPC_ch2.shape
479 # #print 'SPC_ch2.shape',SPC_ch2.shape
481 # #dataOut.data_param = SPC_ch1
480 # #dataOut.data_param = SPC_ch1
482 # GauSPC[0] = SPC_ch1
481 # GauSPC[0] = SPC_ch1
483 # GauSPC[1] = SPC_ch2
482 # GauSPC[1] = SPC_ch2
484
483
485 # #plt.gcf().clear()
484 # #plt.gcf().clear()
486 # plt.figure(50+self.i)
485 # plt.figure(50+self.i)
487 # self.i=self.i+1
486 # self.i=self.i+1
488 # #plt.subplot(121)
487 # #plt.subplot(121)
489 # plt.plot(self.spc,'k')#,label='spc(66)')
488 # plt.plot(self.spc,'k')#,label='spc(66)')
490 # plt.plot(SPC_ch1[ch,ht],'b')#,label='gg1')
489 # plt.plot(SPC_ch1[ch,ht],'b')#,label='gg1')
491 # #plt.plot(SPC_ch2,'r')#,label='gg2')
490 # #plt.plot(SPC_ch2,'r')#,label='gg2')
492 # #plt.plot(xFrec,ySamples[1],'g',label='Ch1')
491 # #plt.plot(xFrec,ySamples[1],'g',label='Ch1')
493 # #plt.plot(xFrec,ySamples[2],'r',label='Ch2')
492 # #plt.plot(xFrec,ySamples[2],'r',label='Ch2')
494 # #plt.plot(xFrec,FitGauss,'yo:',label='fit')
493 # #plt.plot(xFrec,FitGauss,'yo:',label='fit')
495 # plt.legend()
494 # plt.legend()
496 # plt.title('DATOS A ALTURA DE 7500 METROS')
495 # plt.title('DATOS A ALTURA DE 7500 METROS')
497 # plt.show()
496 # plt.show()
498 # print 'shift0', shift0
497 # print 'shift0', shift0
499 # print 'Amplitude0', Amplitude0
498 # print 'Amplitude0', Amplitude0
500 # print 'width0', width0
499 # print 'width0', width0
501 # print 'p0', p0
500 # print 'p0', p0
502 # print '========================'
501 # print '========================'
503 # print 'shift1', shift1
502 # print 'shift1', shift1
504 # print 'Amplitude1', Amplitude1
503 # print 'Amplitude1', Amplitude1
505 # print 'width1', width1
504 # print 'width1', width1
506 # print 'p1', p1
505 # print 'p1', p1
507 # print 'noise', noise
506 # print 'noise', noise
508 # print 's_noise', wnoise
507 # print 's_noise', wnoise
509
508
510 print '========================================================'
509 print '========================================================'
511 print 'total_time: ', time.time()-start_time
510 print 'total_time: ', time.time()-start_time
512
511
513 # re-normalizing spc and noise
512 # re-normalizing spc and noise
514 # This part differs from gg1
513 # This part differs from gg1
515
514
516
515
517
516
518 ''' Parameters:
517 ''' Parameters:
519 1. Amplitude
518 1. Amplitude
520 2. Shift
519 2. Shift
521 3. Width
520 3. Width
522 4. Power
521 4. Power
523 '''
522 '''
524
523
525
524
526 ###############################################################################
525 ###############################################################################
527 def FitGau(self, X):
526 def FitGau(self, X):
528
527
529 Vrange, ch, pnoise, noise_, num_intg, SNRlimit = X
528 Vrange, ch, pnoise, noise_, num_intg, SNRlimit = X
530 #print 'VARSSSS', ch, pnoise, noise, num_intg
529 #print 'VARSSSS', ch, pnoise, noise, num_intg
531
530
532 #print 'HEIGHTS', self.Num_Hei
531 #print 'HEIGHTS', self.Num_Hei
533
532
534 GauSPC = []
533 GauSPC = []
535 SPC_ch1 = numpy.empty([self.Num_Bin,self.Num_Hei])
534 SPC_ch1 = numpy.empty([self.Num_Bin,self.Num_Hei])
536 SPC_ch2 = numpy.empty([self.Num_Bin,self.Num_Hei])
535 SPC_ch2 = numpy.empty([self.Num_Bin,self.Num_Hei])
537 SPC_ch1[:] = 0#numpy.NaN
536 SPC_ch1[:] = 0#numpy.NaN
538 SPC_ch2[:] = 0#numpy.NaN
537 SPC_ch2[:] = 0#numpy.NaN
539
538
540
539
541
540
542 for ht in range(self.Num_Hei):
541 for ht in range(self.Num_Hei):
543 #print (numpy.asarray(self.spc).shape)
542 #print (numpy.asarray(self.spc).shape)
544
543
545 #print 'TTTTT', ch , ht
544 #print 'TTTTT', ch , ht
546 #print self.spc.shape
545 #print self.spc.shape
547
546
548
547
549 spc = numpy.asarray(self.spc)[ch,:,ht]
548 spc = numpy.asarray(self.spc)[ch,:,ht]
550
549
551 #############################################
550 #############################################
552 # normalizing spc and noise
551 # normalizing spc and noise
553 # This part differs from gg1
552 # This part differs from gg1
554 spc_norm_max = max(spc)
553 spc_norm_max = max(spc)
555 spc = spc / spc_norm_max
554 spc = spc / spc_norm_max
556 pnoise = pnoise / spc_norm_max
555 pnoise = pnoise / spc_norm_max
557 #############################################
556 #############################################
558
557
559 fatspectra=1.0
558 fatspectra=1.0
560
559
561 wnoise = noise_ / spc_norm_max
560 wnoise = noise_ / spc_norm_max
562 #wnoise,stdv,i_max,index =enoise(spc,num_intg) #noise estimate using Hildebrand Sekhon, only wnoise is used
561 #wnoise,stdv,i_max,index =enoise(spc,num_intg) #noise estimate using Hildebrand Sekhon, only wnoise is used
563 #if wnoise>1.1*pnoise: # to be tested later
562 #if wnoise>1.1*pnoise: # to be tested later
564 # wnoise=pnoise
563 # wnoise=pnoise
565 noisebl=wnoise*0.9; noisebh=wnoise*1.1
564 noisebl=wnoise*0.9; noisebh=wnoise*1.1
566 spc=spc-wnoise
565 spc=spc-wnoise
567 # print 'wnoise', noise_[0], spc_norm_max, wnoise
566 # print 'wnoise', noise_[0], spc_norm_max, wnoise
568 minx=numpy.argmin(spc)
567 minx=numpy.argmin(spc)
569 spcs=numpy.roll(spc,-minx)
568 spcs=numpy.roll(spc,-minx)
570 cum=numpy.cumsum(spcs)
569 cum=numpy.cumsum(spcs)
571 tot_noise=wnoise * self.Num_Bin #64;
570 tot_noise=wnoise * self.Num_Bin #64;
572 #print 'spc' , spcs[5:8] , 'tot_noise', tot_noise
571 #print 'spc' , spcs[5:8] , 'tot_noise', tot_noise
573 #tot_signal=sum(cum[-5:])/5.; ''' How does this line work? '''
572 #tot_signal=sum(cum[-5:])/5.; ''' How does this line work? '''
574 #snr=tot_signal/tot_noise
573 #snr=tot_signal/tot_noise
575 #snr=cum[-1]/tot_noise
574 #snr=cum[-1]/tot_noise
576 snr = sum(spcs)/tot_noise
575 snr = sum(spcs)/tot_noise
577 snrdB=10.*numpy.log10(snr)
576 snrdB=10.*numpy.log10(snr)
578
577
579 if snrdB < SNRlimit :
578 if snrdB < SNRlimit :
580 snr = numpy.NaN
579 snr = numpy.NaN
581 SPC_ch1[:,ht] = 0#numpy.NaN
580 SPC_ch1[:,ht] = 0#numpy.NaN
582 SPC_ch1[:,ht] = 0#numpy.NaN
581 SPC_ch1[:,ht] = 0#numpy.NaN
583 GauSPC = (SPC_ch1,SPC_ch2)
582 GauSPC = (SPC_ch1,SPC_ch2)
584 continue
583 continue
585 #print 'snr',snrdB #, sum(spcs) , tot_noise
584 #print 'snr',snrdB #, sum(spcs) , tot_noise
586
585
587
586
588
587
589 #if snrdB<-18 or numpy.isnan(snrdB) or num_intg<4:
588 #if snrdB<-18 or numpy.isnan(snrdB) or num_intg<4:
590 # return [None,]*4,[None,]*4,None,snrdB,None,None,[None,]*5,[None,]*9,None
589 # return [None,]*4,[None,]*4,None,snrdB,None,None,[None,]*5,[None,]*9,None
591
590
592 cummax=max(cum); epsi=0.08*fatspectra # cumsum to narrow down the energy region
591 cummax=max(cum); epsi=0.08*fatspectra # cumsum to narrow down the energy region
593 cumlo=cummax*epsi;
592 cumlo=cummax*epsi;
594 cumhi=cummax*(1-epsi)
593 cumhi=cummax*(1-epsi)
595 powerindex=numpy.array(numpy.where(numpy.logical_and(cum>cumlo, cum<cumhi))[0])
594 powerindex=numpy.array(numpy.where(numpy.logical_and(cum>cumlo, cum<cumhi))[0])
596
595
597
596
598 if len(powerindex) < 1:# case for powerindex 0
597 if len(powerindex) < 1:# case for powerindex 0
599 continue
598 continue
600 powerlo=powerindex[0]
599 powerlo=powerindex[0]
601 powerhi=powerindex[-1]
600 powerhi=powerindex[-1]
602 powerwidth=powerhi-powerlo
601 powerwidth=powerhi-powerlo
603
602
604 firstpeak=powerlo+powerwidth/10.# first gaussian energy location
603 firstpeak=powerlo+powerwidth/10.# first gaussian energy location
605 secondpeak=powerhi-powerwidth/10.#second gaussian energy location
604 secondpeak=powerhi-powerwidth/10.#second gaussian energy location
606 midpeak=(firstpeak+secondpeak)/2.
605 midpeak=(firstpeak+secondpeak)/2.
607 firstamp=spcs[int(firstpeak)]
606 firstamp=spcs[int(firstpeak)]
608 secondamp=spcs[int(secondpeak)]
607 secondamp=spcs[int(secondpeak)]
609 midamp=spcs[int(midpeak)]
608 midamp=spcs[int(midpeak)]
610
609
611 x=numpy.arange( self.Num_Bin )
610 x=numpy.arange( self.Num_Bin )
612 y_data=spc+wnoise
611 y_data=spc+wnoise
613
612
614 # single gaussian
613 # single gaussian
615 shift0=numpy.mod(midpeak+minx, self.Num_Bin )
614 shift0=numpy.mod(midpeak+minx, self.Num_Bin )
616 width0=powerwidth/4.#Initialization entire power of spectrum divided by 4
615 width0=powerwidth/4.#Initialization entire power of spectrum divided by 4
617 power0=2.
616 power0=2.
618 amplitude0=midamp
617 amplitude0=midamp
619 state0=[shift0,width0,amplitude0,power0,wnoise]
618 state0=[shift0,width0,amplitude0,power0,wnoise]
620 bnds=(( 0,(self.Num_Bin-1) ),(1,powerwidth),(0,None),(0.5,3.),(noisebl,noisebh))
619 bnds=(( 0,(self.Num_Bin-1) ),(1,powerwidth),(0,None),(0.5,3.),(noisebl,noisebh))
621 lsq1=fmin_l_bfgs_b(self.misfit1,state0,args=(y_data,x,num_intg),bounds=bnds,approx_grad=True)
620 lsq1=fmin_l_bfgs_b(self.misfit1,state0,args=(y_data,x,num_intg),bounds=bnds,approx_grad=True)
622
621
623 chiSq1=lsq1[1];
622 chiSq1=lsq1[1];
624 jack1= self.y_jacobian1(x,lsq1[0])
623 jack1= self.y_jacobian1(x,lsq1[0])
625
624
626
625
627 try:
626 try:
628 sigmas1=numpy.sqrt(chiSq1*numpy.diag(numpy.linalg.inv(numpy.dot(jack1.T,jack1))))
627 sigmas1=numpy.sqrt(chiSq1*numpy.diag(numpy.linalg.inv(numpy.dot(jack1.T,jack1))))
629 except:
628 except:
630 std1=32.; sigmas1=numpy.ones(5)
629 std1=32.; sigmas1=numpy.ones(5)
631 else:
630 else:
632 std1=sigmas1[0]
631 std1=sigmas1[0]
633
632
634
633
635 if fatspectra<1.0 and powerwidth<4:
634 if fatspectra<1.0 and powerwidth<4:
636 choice=0
635 choice=0
637 Amplitude0=lsq1[0][2]
636 Amplitude0=lsq1[0][2]
638 shift0=lsq1[0][0]
637 shift0=lsq1[0][0]
639 width0=lsq1[0][1]
638 width0=lsq1[0][1]
640 p0=lsq1[0][3]
639 p0=lsq1[0][3]
641 Amplitude1=0.
640 Amplitude1=0.
642 shift1=0.
641 shift1=0.
643 width1=0.
642 width1=0.
644 p1=0.
643 p1=0.
645 noise=lsq1[0][4]
644 noise=lsq1[0][4]
646 #return (numpy.array([shift0,width0,Amplitude0,p0]),
645 #return (numpy.array([shift0,width0,Amplitude0,p0]),
647 # numpy.array([shift1,width1,Amplitude1,p1]),noise,snrdB,chiSq1,6.,sigmas1,[None,]*9,choice)
646 # numpy.array([shift1,width1,Amplitude1,p1]),noise,snrdB,chiSq1,6.,sigmas1,[None,]*9,choice)
648
647
649 # two gaussians
648 # two gaussians
650 #shift0=numpy.mod(firstpeak+minx,64); shift1=numpy.mod(secondpeak+minx,64)
649 #shift0=numpy.mod(firstpeak+minx,64); shift1=numpy.mod(secondpeak+minx,64)
651 shift0=numpy.mod(firstpeak+minx, self.Num_Bin );
650 shift0=numpy.mod(firstpeak+minx, self.Num_Bin );
652 shift1=numpy.mod(secondpeak+minx, self.Num_Bin )
651 shift1=numpy.mod(secondpeak+minx, self.Num_Bin )
653 width0=powerwidth/6.;
652 width0=powerwidth/6.;
654 width1=width0
653 width1=width0
655 power0=2.;
654 power0=2.;
656 power1=power0
655 power1=power0
657 amplitude0=firstamp;
656 amplitude0=firstamp;
658 amplitude1=secondamp
657 amplitude1=secondamp
659 state0=[shift0,width0,amplitude0,power0,shift1,width1,amplitude1,power1,wnoise]
658 state0=[shift0,width0,amplitude0,power0,shift1,width1,amplitude1,power1,wnoise]
660 #bnds=((0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(noisebl,noisebh))
659 #bnds=((0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(noisebl,noisebh))
661 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))
660 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))
662 #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))
661 #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))
663
662
664 lsq2=fmin_l_bfgs_b(self.misfit2,state0,args=(y_data,x,num_intg),bounds=bnds,approx_grad=True)
663 lsq2=fmin_l_bfgs_b(self.misfit2,state0,args=(y_data,x,num_intg),bounds=bnds,approx_grad=True)
665
664
666
665
667 chiSq2=lsq2[1]; jack2=self.y_jacobian2(x,lsq2[0])
666 chiSq2=lsq2[1]; jack2=self.y_jacobian2(x,lsq2[0])
668
667
669
668
670 try:
669 try:
671 sigmas2=numpy.sqrt(chiSq2*numpy.diag(numpy.linalg.inv(numpy.dot(jack2.T,jack2))))
670 sigmas2=numpy.sqrt(chiSq2*numpy.diag(numpy.linalg.inv(numpy.dot(jack2.T,jack2))))
672 except:
671 except:
673 std2a=32.; std2b=32.; sigmas2=numpy.ones(9)
672 std2a=32.; std2b=32.; sigmas2=numpy.ones(9)
674 else:
673 else:
675 std2a=sigmas2[0]; std2b=sigmas2[4]
674 std2a=sigmas2[0]; std2b=sigmas2[4]
676
675
677
676
678
677
679 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)
678 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)
680
679
681 if snrdB>-6: # when SNR is strong pick the peak with least shift (LOS velocity) error
680 if snrdB>-6: # when SNR is strong pick the peak with least shift (LOS velocity) error
682 if oneG:
681 if oneG:
683 choice=0
682 choice=0
684 else:
683 else:
685 w1=lsq2[0][1]; w2=lsq2[0][5]
684 w1=lsq2[0][1]; w2=lsq2[0][5]
686 a1=lsq2[0][2]; a2=lsq2[0][6]
685 a1=lsq2[0][2]; a2=lsq2[0][6]
687 p1=lsq2[0][3]; p2=lsq2[0][7]
686 p1=lsq2[0][3]; p2=lsq2[0][7]
688 s1=(2**(1+1./p1))*scipy.special.gamma(1./p1)/p1;
687 s1=(2**(1+1./p1))*scipy.special.gamma(1./p1)/p1;
689 s2=(2**(1+1./p2))*scipy.special.gamma(1./p2)/p2;
688 s2=(2**(1+1./p2))*scipy.special.gamma(1./p2)/p2;
690 gp1=a1*w1*s1; gp2=a2*w2*s2 # power content of each ggaussian with proper p scaling
689 gp1=a1*w1*s1; gp2=a2*w2*s2 # power content of each ggaussian with proper p scaling
691
690
692 if gp1>gp2:
691 if gp1>gp2:
693 if a1>0.7*a2:
692 if a1>0.7*a2:
694 choice=1
693 choice=1
695 else:
694 else:
696 choice=2
695 choice=2
697 elif gp2>gp1:
696 elif gp2>gp1:
698 if a2>0.7*a1:
697 if a2>0.7*a1:
699 choice=2
698 choice=2
700 else:
699 else:
701 choice=1
700 choice=1
702 else:
701 else:
703 choice=numpy.argmax([a1,a2])+1
702 choice=numpy.argmax([a1,a2])+1
704 #else:
703 #else:
705 #choice=argmin([std2a,std2b])+1
704 #choice=argmin([std2a,std2b])+1
706
705
707 else: # with low SNR go to the most energetic peak
706 else: # with low SNR go to the most energetic peak
708 choice=numpy.argmax([lsq1[0][2]*lsq1[0][1],lsq2[0][2]*lsq2[0][1],lsq2[0][6]*lsq2[0][5]])
707 choice=numpy.argmax([lsq1[0][2]*lsq1[0][1],lsq2[0][2]*lsq2[0][1],lsq2[0][6]*lsq2[0][5]])
709
708
710
709
711 shift0=lsq2[0][0]; vel0=Vrange[0] + shift0*(Vrange[1]-Vrange[0])
710 shift0=lsq2[0][0]; vel0=Vrange[0] + shift0*(Vrange[1]-Vrange[0])
712 shift1=lsq2[0][4]; vel1=Vrange[0] + shift1*(Vrange[1]-Vrange[0])
711 shift1=lsq2[0][4]; vel1=Vrange[0] + shift1*(Vrange[1]-Vrange[0])
713
712
714 max_vel = 20
713 max_vel = 20
715
714
716 #first peak will be 0, second peak will be 1
715 #first peak will be 0, second peak will be 1
717 if vel0 > 0 and vel0 < max_vel : #first peak is in the correct range
716 if vel0 > 0 and vel0 < max_vel : #first peak is in the correct range
718 shift0=lsq2[0][0]
717 shift0=lsq2[0][0]
719 width0=lsq2[0][1]
718 width0=lsq2[0][1]
720 Amplitude0=lsq2[0][2]
719 Amplitude0=lsq2[0][2]
721 p0=lsq2[0][3]
720 p0=lsq2[0][3]
722
721
723 shift1=lsq2[0][4]
722 shift1=lsq2[0][4]
724 width1=lsq2[0][5]
723 width1=lsq2[0][5]
725 Amplitude1=lsq2[0][6]
724 Amplitude1=lsq2[0][6]
726 p1=lsq2[0][7]
725 p1=lsq2[0][7]
727 noise=lsq2[0][8]
726 noise=lsq2[0][8]
728 else:
727 else:
729 shift1=lsq2[0][0]
728 shift1=lsq2[0][0]
730 width1=lsq2[0][1]
729 width1=lsq2[0][1]
731 Amplitude1=lsq2[0][2]
730 Amplitude1=lsq2[0][2]
732 p1=lsq2[0][3]
731 p1=lsq2[0][3]
733
732
734 shift0=lsq2[0][4]
733 shift0=lsq2[0][4]
735 width0=lsq2[0][5]
734 width0=lsq2[0][5]
736 Amplitude0=lsq2[0][6]
735 Amplitude0=lsq2[0][6]
737 p0=lsq2[0][7]
736 p0=lsq2[0][7]
738 noise=lsq2[0][8]
737 noise=lsq2[0][8]
739
738
740 if Amplitude0<0.1: # in case the peak is noise
739 if Amplitude0<0.1: # in case the peak is noise
741 shift0,width0,Amplitude0,p0 = 4*[numpy.NaN]
740 shift0,width0,Amplitude0,p0 = 4*[numpy.NaN]
742 if Amplitude1<0.1:
741 if Amplitude1<0.1:
743 shift1,width1,Amplitude1,p1 = 4*[numpy.NaN]
742 shift1,width1,Amplitude1,p1 = 4*[numpy.NaN]
744
743
745
744
746 # if choice==0: # pick the single gaussian fit
745 # if choice==0: # pick the single gaussian fit
747 # Amplitude0=lsq1[0][2]
746 # Amplitude0=lsq1[0][2]
748 # shift0=lsq1[0][0]
747 # shift0=lsq1[0][0]
749 # width0=lsq1[0][1]
748 # width0=lsq1[0][1]
750 # p0=lsq1[0][3]
749 # p0=lsq1[0][3]
751 # Amplitude1=0.
750 # Amplitude1=0.
752 # shift1=0.
751 # shift1=0.
753 # width1=0.
752 # width1=0.
754 # p1=0.
753 # p1=0.
755 # noise=lsq1[0][4]
754 # noise=lsq1[0][4]
756 # elif choice==1: # take the first one of the 2 gaussians fitted
755 # elif choice==1: # take the first one of the 2 gaussians fitted
757 # Amplitude0 = lsq2[0][2]
756 # Amplitude0 = lsq2[0][2]
758 # shift0 = lsq2[0][0]
757 # shift0 = lsq2[0][0]
759 # width0 = lsq2[0][1]
758 # width0 = lsq2[0][1]
760 # p0 = lsq2[0][3]
759 # p0 = lsq2[0][3]
761 # Amplitude1 = lsq2[0][6] # This is 0 in gg1
760 # Amplitude1 = lsq2[0][6] # This is 0 in gg1
762 # shift1 = lsq2[0][4] # This is 0 in gg1
761 # shift1 = lsq2[0][4] # This is 0 in gg1
763 # width1 = lsq2[0][5] # This is 0 in gg1
762 # width1 = lsq2[0][5] # This is 0 in gg1
764 # p1 = lsq2[0][7] # This is 0 in gg1
763 # p1 = lsq2[0][7] # This is 0 in gg1
765 # noise = lsq2[0][8]
764 # noise = lsq2[0][8]
766 # else: # the second one
765 # else: # the second one
767 # Amplitude0 = lsq2[0][6]
766 # Amplitude0 = lsq2[0][6]
768 # shift0 = lsq2[0][4]
767 # shift0 = lsq2[0][4]
769 # width0 = lsq2[0][5]
768 # width0 = lsq2[0][5]
770 # p0 = lsq2[0][7]
769 # p0 = lsq2[0][7]
771 # Amplitude1 = lsq2[0][2] # This is 0 in gg1
770 # Amplitude1 = lsq2[0][2] # This is 0 in gg1
772 # shift1 = lsq2[0][0] # This is 0 in gg1
771 # shift1 = lsq2[0][0] # This is 0 in gg1
773 # width1 = lsq2[0][1] # This is 0 in gg1
772 # width1 = lsq2[0][1] # This is 0 in gg1
774 # p1 = lsq2[0][3] # This is 0 in gg1
773 # p1 = lsq2[0][3] # This is 0 in gg1
775 # noise = lsq2[0][8]
774 # noise = lsq2[0][8]
776
775
777 #print len(noise + Amplitude0*numpy.exp(-0.5*(abs(x-shift0))/width0)**p0)
776 #print len(noise + Amplitude0*numpy.exp(-0.5*(abs(x-shift0))/width0)**p0)
778 SPC_ch1[:,ht] = noise + Amplitude0*numpy.exp(-0.5*(abs(x-shift0))/width0)**p0
777 SPC_ch1[:,ht] = noise + Amplitude0*numpy.exp(-0.5*(abs(x-shift0))/width0)**p0
779 SPC_ch2[:,ht] = noise + Amplitude1*numpy.exp(-0.5*(abs(x-shift1))/width1)**p1
778 SPC_ch2[:,ht] = noise + Amplitude1*numpy.exp(-0.5*(abs(x-shift1))/width1)**p1
780 #print 'SPC_ch1.shape',SPC_ch1.shape
779 #print 'SPC_ch1.shape',SPC_ch1.shape
781 #print 'SPC_ch2.shape',SPC_ch2.shape
780 #print 'SPC_ch2.shape',SPC_ch2.shape
782 #dataOut.data_param = SPC_ch1
781 #dataOut.data_param = SPC_ch1
783 GauSPC = (SPC_ch1,SPC_ch2)
782 GauSPC = (SPC_ch1,SPC_ch2)
784 #GauSPC[1] = SPC_ch2
783 #GauSPC[1] = SPC_ch2
785
784
786 # print 'shift0', shift0
785 # print 'shift0', shift0
787 # print 'Amplitude0', Amplitude0
786 # print 'Amplitude0', Amplitude0
788 # print 'width0', width0
787 # print 'width0', width0
789 # print 'p0', p0
788 # print 'p0', p0
790 # print '========================'
789 # print '========================'
791 # print 'shift1', shift1
790 # print 'shift1', shift1
792 # print 'Amplitude1', Amplitude1
791 # print 'Amplitude1', Amplitude1
793 # print 'width1', width1
792 # print 'width1', width1
794 # print 'p1', p1
793 # print 'p1', p1
795 # print 'noise', noise
794 # print 'noise', noise
796 # print 's_noise', wnoise
795 # print 's_noise', wnoise
797
796
798 return GauSPC
797 return GauSPC
799
798
800
799
801 def y_jacobian1(self,x,state): # This function is for further analysis of generalized Gaussians, it is not too importan for the signal discrimination.
800 def y_jacobian1(self,x,state): # This function is for further analysis of generalized Gaussians, it is not too importan for the signal discrimination.
802 y_model=self.y_model1(x,state)
801 y_model=self.y_model1(x,state)
803 s0,w0,a0,p0,n=state
802 s0,w0,a0,p0,n=state
804 e0=((x-s0)/w0)**2;
803 e0=((x-s0)/w0)**2;
805
804
806 e0u=((x-s0-self.Num_Bin)/w0)**2;
805 e0u=((x-s0-self.Num_Bin)/w0)**2;
807
806
808 e0d=((x-s0+self.Num_Bin)/w0)**2
807 e0d=((x-s0+self.Num_Bin)/w0)**2
809 m0=numpy.exp(-0.5*e0**(p0/2.));
808 m0=numpy.exp(-0.5*e0**(p0/2.));
810 m0u=numpy.exp(-0.5*e0u**(p0/2.));
809 m0u=numpy.exp(-0.5*e0u**(p0/2.));
811 m0d=numpy.exp(-0.5*e0d**(p0/2.))
810 m0d=numpy.exp(-0.5*e0d**(p0/2.))
812 JA=m0+m0u+m0d
811 JA=m0+m0u+m0d
813 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)
812 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)
814
813
815 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)
814 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)
816
815
817 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
816 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
818 jack1=numpy.sqrt(7)*numpy.array([JS/y_model,JW/y_model,JA/y_model,JP/y_model,1./y_model])
817 jack1=numpy.sqrt(7)*numpy.array([JS/y_model,JW/y_model,JA/y_model,JP/y_model,1./y_model])
819 return jack1.T
818 return jack1.T
820
819
821 def y_jacobian2(self,x,state):
820 def y_jacobian2(self,x,state):
822 y_model=self.y_model2(x,state)
821 y_model=self.y_model2(x,state)
823 s0,w0,a0,p0,s1,w1,a1,p1,n=state
822 s0,w0,a0,p0,s1,w1,a1,p1,n=state
824 e0=((x-s0)/w0)**2;
823 e0=((x-s0)/w0)**2;
825
824
826 e0u=((x-s0- self.Num_Bin )/w0)**2;
825 e0u=((x-s0- self.Num_Bin )/w0)**2;
827
826
828 e0d=((x-s0+ self.Num_Bin )/w0)**2
827 e0d=((x-s0+ self.Num_Bin )/w0)**2
829 e1=((x-s1)/w1)**2;
828 e1=((x-s1)/w1)**2;
830
829
831 e1u=((x-s1- self.Num_Bin )/w1)**2;
830 e1u=((x-s1- self.Num_Bin )/w1)**2;
832
831
833 e1d=((x-s1+ self.Num_Bin )/w1)**2
832 e1d=((x-s1+ self.Num_Bin )/w1)**2
834 m0=numpy.exp(-0.5*e0**(p0/2.));
833 m0=numpy.exp(-0.5*e0**(p0/2.));
835 m0u=numpy.exp(-0.5*e0u**(p0/2.));
834 m0u=numpy.exp(-0.5*e0u**(p0/2.));
836 m0d=numpy.exp(-0.5*e0d**(p0/2.))
835 m0d=numpy.exp(-0.5*e0d**(p0/2.))
837 m1=numpy.exp(-0.5*e1**(p1/2.));
836 m1=numpy.exp(-0.5*e1**(p1/2.));
838 m1u=numpy.exp(-0.5*e1u**(p1/2.));
837 m1u=numpy.exp(-0.5*e1u**(p1/2.));
839 m1d=numpy.exp(-0.5*e1d**(p1/2.))
838 m1d=numpy.exp(-0.5*e1d**(p1/2.))
840 JA=m0+m0u+m0d
839 JA=m0+m0u+m0d
841 JA1=m1+m1u+m1d
840 JA1=m1+m1u+m1d
842 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)
841 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)
843 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)
842 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)
844
843
845 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)
844 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)
846
845
847 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)
846 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)
848
847
849 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
848 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
850
849
851 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
850 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
852 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])
851 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])
853 return jack2.T
852 return jack2.T
854
853
855 def y_model1(self,x,state):
854 def y_model1(self,x,state):
856 shift0,width0,amplitude0,power0,noise=state
855 shift0,width0,amplitude0,power0,noise=state
857 model0=amplitude0*numpy.exp(-0.5*abs((x-shift0)/width0)**power0)
856 model0=amplitude0*numpy.exp(-0.5*abs((x-shift0)/width0)**power0)
858
857
859 model0u=amplitude0*numpy.exp(-0.5*abs((x-shift0- self.Num_Bin )/width0)**power0)
858 model0u=amplitude0*numpy.exp(-0.5*abs((x-shift0- self.Num_Bin )/width0)**power0)
860
859
861 model0d=amplitude0*numpy.exp(-0.5*abs((x-shift0+ self.Num_Bin )/width0)**power0)
860 model0d=amplitude0*numpy.exp(-0.5*abs((x-shift0+ self.Num_Bin )/width0)**power0)
862 return model0+model0u+model0d+noise
861 return model0+model0u+model0d+noise
863
862
864 def y_model2(self,x,state): #Equation for two generalized Gaussians with Nyquist
863 def y_model2(self,x,state): #Equation for two generalized Gaussians with Nyquist
865 shift0,width0,amplitude0,power0,shift1,width1,amplitude1,power1,noise=state
864 shift0,width0,amplitude0,power0,shift1,width1,amplitude1,power1,noise=state
866 model0=amplitude0*numpy.exp(-0.5*abs((x-shift0)/width0)**power0)
865 model0=amplitude0*numpy.exp(-0.5*abs((x-shift0)/width0)**power0)
867
866
868 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)
869
868
870 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)
871 model1=amplitude1*numpy.exp(-0.5*abs((x-shift1)/width1)**power1)
870 model1=amplitude1*numpy.exp(-0.5*abs((x-shift1)/width1)**power1)
872
871
873 model1u=amplitude1*numpy.exp(-0.5*abs((x-shift1- self.Num_Bin )/width1)**power1)
872 model1u=amplitude1*numpy.exp(-0.5*abs((x-shift1- self.Num_Bin )/width1)**power1)
874
873
875 model1d=amplitude1*numpy.exp(-0.5*abs((x-shift1+ self.Num_Bin )/width1)**power1)
874 model1d=amplitude1*numpy.exp(-0.5*abs((x-shift1+ self.Num_Bin )/width1)**power1)
876 return model0+model0u+model0d+model1+model1u+model1d+noise
875 return model0+model0u+model0d+model1+model1u+model1d+noise
877
876
878 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.
877 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.
879
878
880 return num_intg*sum((numpy.log(y_data)-numpy.log(self.y_model1(x,state)))**2)#/(64-5.) # /(64-5.) can be commented
879 return num_intg*sum((numpy.log(y_data)-numpy.log(self.y_model1(x,state)))**2)#/(64-5.) # /(64-5.) can be commented
881
880
882 def misfit2(self,state,y_data,x,num_intg):
881 def misfit2(self,state,y_data,x,num_intg):
883 return num_intg*sum((numpy.log(y_data)-numpy.log(self.y_model2(x,state)))**2)#/(64-9.)
882 return num_intg*sum((numpy.log(y_data)-numpy.log(self.y_model2(x,state)))**2)#/(64-9.)
884
883
885
884
886 class PrecipitationProc(Operation):
885 class PrecipitationProc(Operation):
887
886
888 '''
887 '''
889 Operator that estimates Reflectivity factor (Z), and estimates rainfall Rate (R)
888 Operator that estimates Reflectivity factor (Z), and estimates rainfall Rate (R)
890
889
891 Input:
890 Input:
892 self.dataOut.data_pre : SelfSpectra
891 self.dataOut.data_pre : SelfSpectra
893
892
894 Output:
893 Output:
895
894
896 self.dataOut.data_output : Reflectivity factor, rainfall Rate
895 self.dataOut.data_output : Reflectivity factor, rainfall Rate
897
896
898
897
899 Parameters affected:
898 Parameters affected:
900 '''
899 '''
901
900
902
901
903 def run(self, dataOut, radar=None, Pt=None, Gt=None, Gr=None, Lambda=None, aL=None,
902 def run(self, dataOut, radar=None, Pt=None, Gt=None, Gr=None, Lambda=None, aL=None,
904 tauW=None, ThetaT=None, ThetaR=None, Km = 0.93, Altitude=None):
903 tauW=None, ThetaT=None, ThetaR=None, Km = 0.93, Altitude=None):
905
904
906 self.spc = dataOut.data_pre[0].copy()
905 self.spc = dataOut.data_pre[0].copy()
907 self.Num_Hei = self.spc.shape[2]
906 self.Num_Hei = self.spc.shape[2]
908 self.Num_Bin = self.spc.shape[1]
907 self.Num_Bin = self.spc.shape[1]
909 self.Num_Chn = self.spc.shape[0]
908 self.Num_Chn = self.spc.shape[0]
910
909
911 Velrange = dataOut.abscissaList
910 Velrange = dataOut.abscissaList
912
911
913 if radar == "MIRA35C" :
912 if radar == "MIRA35C" :
914
913
915 Ze = self.dBZeMODE2(dataOut)
914 Ze = self.dBZeMODE2(dataOut)
916
915
917 else:
916 else:
918
917
919 self.Pt = Pt
918 self.Pt = Pt
920 self.Gt = Gt
919 self.Gt = Gt
921 self.Gr = Gr
920 self.Gr = Gr
922 self.Lambda = Lambda
921 self.Lambda = Lambda
923 self.aL = aL
922 self.aL = aL
924 self.tauW = tauW
923 self.tauW = tauW
925 self.ThetaT = ThetaT
924 self.ThetaT = ThetaT
926 self.ThetaR = ThetaR
925 self.ThetaR = ThetaR
927
926
928 RadarConstant = GetRadarConstant()
927 RadarConstant = GetRadarConstant()
929 SPCmean = numpy.mean(self.spc,0)
928 SPCmean = numpy.mean(self.spc,0)
930 ETA = numpy.zeros(self.Num_Hei)
929 ETA = numpy.zeros(self.Num_Hei)
931 Pr = numpy.sum(SPCmean,0)
930 Pr = numpy.sum(SPCmean,0)
932
931
933 #for R in range(self.Num_Hei):
932 #for R in range(self.Num_Hei):
934 # ETA[R] = RadarConstant * Pr[R] * R**2 #Reflectivity (ETA)
933 # ETA[R] = RadarConstant * Pr[R] * R**2 #Reflectivity (ETA)
935
934
936 D_range = numpy.zeros(self.Num_Hei)
935 D_range = numpy.zeros(self.Num_Hei)
937 EqSec = numpy.zeros(self.Num_Hei)
936 EqSec = numpy.zeros(self.Num_Hei)
938 del_V = numpy.zeros(self.Num_Hei)
937 del_V = numpy.zeros(self.Num_Hei)
939
938
940 for R in range(self.Num_Hei):
939 for R in range(self.Num_Hei):
941 ETA[R] = RadarConstant * Pr[R] * R**2 #Reflectivity (ETA)
940 ETA[R] = RadarConstant * Pr[R] * R**2 #Reflectivity (ETA)
942
941
943 h = R + Altitude #Range from ground to radar pulse altitude
942 h = R + Altitude #Range from ground to radar pulse altitude
944 del_V[R] = 1 + 3.68 * 10**-5 * h + 1.71 * 10**-9 * h**2 #Density change correction for velocity
943 del_V[R] = 1 + 3.68 * 10**-5 * h + 1.71 * 10**-9 * h**2 #Density change correction for velocity
945
944
946 D_range[R] = numpy.log( (9.65 - (Velrange[R]/del_V[R])) / 10.3 ) / -0.6 #Range of Diameter of drops related to velocity
945 D_range[R] = numpy.log( (9.65 - (Velrange[R]/del_V[R])) / 10.3 ) / -0.6 #Range of Diameter of drops related to velocity
947 SIGMA[R] = numpy.pi**5 / Lambda**4 * Km * D_range[R]**6 #Equivalent Section of drops (sigma)
946 SIGMA[R] = numpy.pi**5 / Lambda**4 * Km * D_range[R]**6 #Equivalent Section of drops (sigma)
948
947
949 N_dist[R] = ETA[R] / SIGMA[R]
948 N_dist[R] = ETA[R] / SIGMA[R]
950
949
951 Ze = (ETA * Lambda**4) / (numpy.pi * Km)
950 Ze = (ETA * Lambda**4) / (numpy.pi * Km)
952 Z = numpy.sum( N_dist * D_range**6 )
951 Z = numpy.sum( N_dist * D_range**6 )
953 RR = 6*10**-4*numpy.pi * numpy.sum( D_range**3 * N_dist * Velrange ) #Rainfall rate
952 RR = 6*10**-4*numpy.pi * numpy.sum( D_range**3 * N_dist * Velrange ) #Rainfall rate
954
953
955
954
956 RR = (Ze/200)**(1/1.6)
955 RR = (Ze/200)**(1/1.6)
957 dBRR = 10*numpy.log10(RR)
956 dBRR = 10*numpy.log10(RR)
958
957
959 dBZe = 10*numpy.log10(Ze)
958 dBZe = 10*numpy.log10(Ze)
960 dataOut.data_output = Ze
959 dataOut.data_output = Ze
961 dataOut.data_param = numpy.ones([2,self.Num_Hei])
960 dataOut.data_param = numpy.ones([2,self.Num_Hei])
962 dataOut.channelList = [0,1]
961 dataOut.channelList = [0,1]
963 print 'channelList', dataOut.channelList
962 print 'channelList', dataOut.channelList
964 dataOut.data_param[0]=dBZe
963 dataOut.data_param[0]=dBZe
965 dataOut.data_param[1]=dBRR
964 dataOut.data_param[1]=dBRR
966 print 'RR SHAPE', dBRR.shape
965 print 'RR SHAPE', dBRR.shape
967 print 'Ze SHAPE', dBZe.shape
966 print 'Ze SHAPE', dBZe.shape
968 print 'dataOut.data_param SHAPE', dataOut.data_param.shape
967 print 'dataOut.data_param SHAPE', dataOut.data_param.shape
969
968
970
969
971 def dBZeMODE2(self, dataOut): # Processing for MIRA35C
970 def dBZeMODE2(self, dataOut): # Processing for MIRA35C
972
971
973 NPW = dataOut.NPW
972 NPW = dataOut.NPW
974 COFA = dataOut.COFA
973 COFA = dataOut.COFA
975
974
976 SNR = numpy.array([self.spc[0,:,:] / NPW[0]]) #, self.spc[1,:,:] / NPW[1]])
975 SNR = numpy.array([self.spc[0,:,:] / NPW[0]]) #, self.spc[1,:,:] / NPW[1]])
977 RadarConst = dataOut.RadarConst
976 RadarConst = dataOut.RadarConst
978 #frequency = 34.85*10**9
977 #frequency = 34.85*10**9
979
978
980 ETA = numpy.zeros(([self.Num_Chn ,self.Num_Hei]))
979 ETA = numpy.zeros(([self.Num_Chn ,self.Num_Hei]))
981 data_output = numpy.ones([self.Num_Chn , self.Num_Hei])*numpy.NaN
980 data_output = numpy.ones([self.Num_Chn , self.Num_Hei])*numpy.NaN
982
981
983 ETA = numpy.sum(SNR,1)
982 ETA = numpy.sum(SNR,1)
984 print 'ETA' , ETA
983 print 'ETA' , ETA
985 ETA = numpy.where(ETA is not 0. , ETA, numpy.NaN)
984 ETA = numpy.where(ETA is not 0. , ETA, numpy.NaN)
986
985
987 Ze = numpy.ones([self.Num_Chn, self.Num_Hei] )
986 Ze = numpy.ones([self.Num_Chn, self.Num_Hei] )
988
987
989 for r in range(self.Num_Hei):
988 for r in range(self.Num_Hei):
990
989
991 Ze[0,r] = ( ETA[0,r] ) * COFA[0,r][0] * RadarConst * ((r/5000.)**2)
990 Ze[0,r] = ( ETA[0,r] ) * COFA[0,r][0] * RadarConst * ((r/5000.)**2)
992 #Ze[1,r] = ( ETA[1,r] ) * COFA[1,r][0] * RadarConst * ((r/5000.)**2)
991 #Ze[1,r] = ( ETA[1,r] ) * COFA[1,r][0] * RadarConst * ((r/5000.)**2)
993
992
994 return Ze
993 return Ze
995
994
996 def GetRadarConstant(self):
995 def GetRadarConstant(self):
997
996
998 """
997 """
999 Constants:
998 Constants:
1000
999
1001 Pt: Transmission Power dB
1000 Pt: Transmission Power dB
1002 Gt: Transmission Gain dB
1001 Gt: Transmission Gain dB
1003 Gr: Reception Gain dB
1002 Gr: Reception Gain dB
1004 Lambda: Wavelenght m
1003 Lambda: Wavelenght m
1005 aL: Attenuation loses dB
1004 aL: Attenuation loses dB
1006 tauW: Width of transmission pulse s
1005 tauW: Width of transmission pulse s
1007 ThetaT: Transmission antenna bean angle rad
1006 ThetaT: Transmission antenna bean angle rad
1008 ThetaR: Reception antenna beam angle rad
1007 ThetaR: Reception antenna beam angle rad
1009
1008
1010 """
1009 """
1011 Numerator = ( (4*numpy.pi)**3 * aL**2 * 16 * numpy.log(2) )
1010 Numerator = ( (4*numpy.pi)**3 * aL**2 * 16 * numpy.log(2) )
1012 Denominator = ( Pt * Gt * Gr * Lambda**2 * SPEED_OF_LIGHT * TauW * numpy.pi * ThetaT * TheraR)
1011 Denominator = ( Pt * Gt * Gr * Lambda**2 * SPEED_OF_LIGHT * TauW * numpy.pi * ThetaT * TheraR)
1013 RadarConstant = Numerator / Denominator
1012 RadarConstant = Numerator / Denominator
1014
1013
1015 return RadarConstant
1014 return RadarConstant
1016
1015
1017
1016
1018
1017
1019 class FullSpectralAnalysis(Operation):
1018 class FullSpectralAnalysis(Operation):
1020
1019
1021 """
1020 """
1022 Function that implements Full Spectral Analisys technique.
1021 Function that implements Full Spectral Analisys technique.
1023
1022
1024 Input:
1023 Input:
1025 self.dataOut.data_pre : SelfSpectra and CrossSPectra data
1024 self.dataOut.data_pre : SelfSpectra and CrossSPectra data
1026 self.dataOut.groupList : Pairlist of channels
1025 self.dataOut.groupList : Pairlist of channels
1027 self.dataOut.ChanDist : Physical distance between receivers
1026 self.dataOut.ChanDist : Physical distance between receivers
1028
1027
1029
1028
1030 Output:
1029 Output:
1031
1030
1032 self.dataOut.data_output : Zonal wind, Meridional wind and Vertical wind
1031 self.dataOut.data_output : Zonal wind, Meridional wind and Vertical wind
1033
1032
1034
1033
1035 Parameters affected: Winds, height range, SNR
1034 Parameters affected: Winds, height range, SNR
1036
1035
1037 """
1036 """
1038 def run(self, dataOut, E01=None, E02=None, E12=None, N01=None, N02=None, N12=None, SNRlimit=7):
1037 def run(self, dataOut, E01=None, E02=None, E12=None, N01=None, N02=None, N12=None, SNRlimit=7):
1039
1038
1040 spc = dataOut.data_pre[0].copy()
1039 spc = dataOut.data_pre[0].copy()
1041 cspc = dataOut.data_pre[1].copy()
1040 cspc = dataOut.data_pre[1].copy()
1042
1041
1043 nChannel = spc.shape[0]
1042 nChannel = spc.shape[0]
1044 nProfiles = spc.shape[1]
1043 nProfiles = spc.shape[1]
1045 nHeights = spc.shape[2]
1044 nHeights = spc.shape[2]
1046
1045
1047 pairsList = dataOut.groupList
1046 pairsList = dataOut.groupList
1048 if dataOut.ChanDist is not None :
1047 if dataOut.ChanDist is not None :
1049 ChanDist = dataOut.ChanDist
1048 ChanDist = dataOut.ChanDist
1050 else:
1049 else:
1051 ChanDist = numpy.array([[E01, N01],[E02,N02],[E12,N12]])
1050 ChanDist = numpy.array([[E01, N01],[E02,N02],[E12,N12]])
1052
1051
1053 #print 'ChanDist', ChanDist
1052 #print 'ChanDist', ChanDist
1054
1053
1055 if dataOut.VelRange is not None:
1054 if dataOut.VelRange is not None:
1056 VelRange= dataOut.VelRange
1055 VelRange= dataOut.VelRange
1057 else:
1056 else:
1058 VelRange= dataOut.abscissaList
1057 VelRange= dataOut.abscissaList
1059
1058
1060 ySamples=numpy.ones([nChannel,nProfiles])
1059 ySamples=numpy.ones([nChannel,nProfiles])
1061 phase=numpy.ones([nChannel,nProfiles])
1060 phase=numpy.ones([nChannel,nProfiles])
1062 CSPCSamples=numpy.ones([nChannel,nProfiles],dtype=numpy.complex_)
1061 CSPCSamples=numpy.ones([nChannel,nProfiles],dtype=numpy.complex_)
1063 coherence=numpy.ones([nChannel,nProfiles])
1062 coherence=numpy.ones([nChannel,nProfiles])
1064 PhaseSlope=numpy.ones(nChannel)
1063 PhaseSlope=numpy.ones(nChannel)
1065 PhaseInter=numpy.ones(nChannel)
1064 PhaseInter=numpy.ones(nChannel)
1066 dataSNR = dataOut.data_SNR
1065 dataSNR = dataOut.data_SNR
1067
1066
1068
1067
1069
1068
1070 data = dataOut.data_pre
1069 data = dataOut.data_pre
1071 noise = dataOut.noise
1070 noise = dataOut.noise
1072 print 'noise',noise
1071 print 'noise',noise
1073 #SNRdB = 10*numpy.log10(dataOut.data_SNR)
1072 #SNRdB = 10*numpy.log10(dataOut.data_SNR)
1074
1073
1075 FirstMoment = numpy.average(dataOut.data_param[:,1,:],0)
1074 FirstMoment = numpy.average(dataOut.data_param[:,1,:],0)
1076 #SNRdBMean = []
1075 #SNRdBMean = []
1077
1076
1078
1077
1079 #for j in range(nHeights):
1078 #for j in range(nHeights):
1080 # FirstMoment = numpy.append(FirstMoment,numpy.mean([dataOut.data_param[0,1,j],dataOut.data_param[1,1,j],dataOut.data_param[2,1,j]]))
1079 # FirstMoment = numpy.append(FirstMoment,numpy.mean([dataOut.data_param[0,1,j],dataOut.data_param[1,1,j],dataOut.data_param[2,1,j]]))
1081 # SNRdBMean = numpy.append(SNRdBMean,numpy.mean([SNRdB[0,j],SNRdB[1,j],SNRdB[2,j]]))
1080 # SNRdBMean = numpy.append(SNRdBMean,numpy.mean([SNRdB[0,j],SNRdB[1,j],SNRdB[2,j]]))
1082
1081
1083 data_output=numpy.ones([3,spc.shape[2]])*numpy.NaN
1082 data_output=numpy.ones([3,spc.shape[2]])*numpy.NaN
1084
1083
1085 velocityX=[]
1084 velocityX=[]
1086 velocityY=[]
1085 velocityY=[]
1087 velocityV=[]
1086 velocityV=[]
1088
1087
1089 dbSNR = 10*numpy.log10(dataSNR)
1088 dbSNR = 10*numpy.log10(dataSNR)
1090 dbSNR = numpy.average(dbSNR,0)
1089 dbSNR = numpy.average(dbSNR,0)
1091 for Height in range(nHeights):
1090 for Height in range(nHeights):
1092
1091
1093 [Vzon,Vmer,Vver, GaussCenter]= self.WindEstimation(spc, cspc, pairsList, ChanDist, Height, noise, VelRange, dbSNR[Height], SNRlimit)
1092 [Vzon,Vmer,Vver, GaussCenter]= self.WindEstimation(spc, cspc, pairsList, ChanDist, Height, noise, VelRange, dbSNR[Height], SNRlimit)
1094
1093
1095 if abs(Vzon)<100. and abs(Vzon)> 0.:
1094 if abs(Vzon)<100. and abs(Vzon)> 0.:
1096 velocityX=numpy.append(velocityX, Vzon)#Vmag
1095 velocityX=numpy.append(velocityX, Vzon)#Vmag
1097
1096
1098 else:
1097 else:
1099 print 'Vzon',Vzon
1098 print 'Vzon',Vzon
1100 velocityX=numpy.append(velocityX, numpy.NaN)
1099 velocityX=numpy.append(velocityX, numpy.NaN)
1101
1100
1102 if abs(Vmer)<100. and abs(Vmer) > 0.:
1101 if abs(Vmer)<100. and abs(Vmer) > 0.:
1103 velocityY=numpy.append(velocityY, Vmer)#Vang
1102 velocityY=numpy.append(velocityY, Vmer)#Vang
1104
1103
1105 else:
1104 else:
1106 print 'Vmer',Vmer
1105 print 'Vmer',Vmer
1107 velocityY=numpy.append(velocityY, numpy.NaN)
1106 velocityY=numpy.append(velocityY, numpy.NaN)
1108
1107
1109 if dbSNR[Height] > SNRlimit:
1108 if dbSNR[Height] > SNRlimit:
1110 velocityV=numpy.append(velocityV, FirstMoment[Height])
1109 velocityV=numpy.append(velocityV, FirstMoment[Height])
1111 else:
1110 else:
1112 velocityV=numpy.append(velocityV, numpy.NaN)
1111 velocityV=numpy.append(velocityV, numpy.NaN)
1113 #FirstMoment[Height]= numpy.NaN
1112 #FirstMoment[Height]= numpy.NaN
1114 # if SNRdBMean[Height] <12:
1113 # if SNRdBMean[Height] <12:
1115 # FirstMoment[Height] = numpy.NaN
1114 # FirstMoment[Height] = numpy.NaN
1116 # velocityX[Height] = numpy.NaN
1115 # velocityX[Height] = numpy.NaN
1117 # velocityY[Height] = numpy.NaN
1116 # velocityY[Height] = numpy.NaN
1118
1117
1119
1118
1120 data_output[0]=numpy.array(velocityX)
1119 data_output[0]=numpy.array(velocityX)
1121 data_output[1]=numpy.array(velocityY)
1120 data_output[1]=numpy.array(velocityY)
1122 data_output[2]=-velocityV#FirstMoment
1121 data_output[2]=-velocityV#FirstMoment
1123
1122
1124 print ' '
1123 print ' '
1125 #print 'FirstMoment'
1124 #print 'FirstMoment'
1126 #print FirstMoment
1125 #print FirstMoment
1127 print 'velocityX',data_output[0]
1126 print 'velocityX',data_output[0]
1128 print ' '
1127 print ' '
1129 print 'velocityY',data_output[1]
1128 print 'velocityY',data_output[1]
1130 #print numpy.array(velocityY)
1129 #print numpy.array(velocityY)
1131 print ' '
1130 print ' '
1132 #print 'SNR'
1131 #print 'SNR'
1133 #print 10*numpy.log10(dataOut.data_SNR)
1132 #print 10*numpy.log10(dataOut.data_SNR)
1134 #print numpy.shape(10*numpy.log10(dataOut.data_SNR))
1133 #print numpy.shape(10*numpy.log10(dataOut.data_SNR))
1135 print ' '
1134 print ' '
1136
1135
1137
1136
1138 dataOut.data_output=data_output
1137 dataOut.data_output=data_output
1139 return
1138 return
1140
1139
1141
1140
1142 def moving_average(self,x, N=2):
1141 def moving_average(self,x, N=2):
1143 return numpy.convolve(x, numpy.ones((N,))/N)[(N-1):]
1142 return numpy.convolve(x, numpy.ones((N,))/N)[(N-1):]
1144
1143
1145 def gaus(self,xSamples,a,x0,sigma):
1144 def gaus(self,xSamples,a,x0,sigma):
1146 return a*numpy.exp(-(xSamples-x0)**2/(2*sigma**2))
1145 return a*numpy.exp(-(xSamples-x0)**2/(2*sigma**2))
1147
1146
1148 def Find(self,x,value):
1147 def Find(self,x,value):
1149 for index in range(len(x)):
1148 for index in range(len(x)):
1150 if x[index]==value:
1149 if x[index]==value:
1151 return index
1150 return index
1152
1151
1153 def WindEstimation(self, spc, cspc, pairsList, ChanDist, Height, noise, VelRange, dbSNR, SNRlimit):
1152 def WindEstimation(self, spc, cspc, pairsList, ChanDist, Height, noise, VelRange, dbSNR, SNRlimit):
1154
1153
1155 ySamples=numpy.ones([spc.shape[0],spc.shape[1]])
1154 ySamples=numpy.ones([spc.shape[0],spc.shape[1]])
1156 phase=numpy.ones([spc.shape[0],spc.shape[1]])
1155 phase=numpy.ones([spc.shape[0],spc.shape[1]])
1157 CSPCSamples=numpy.ones([spc.shape[0],spc.shape[1]],dtype=numpy.complex_)
1156 CSPCSamples=numpy.ones([spc.shape[0],spc.shape[1]],dtype=numpy.complex_)
1158 coherence=numpy.ones([spc.shape[0],spc.shape[1]])
1157 coherence=numpy.ones([spc.shape[0],spc.shape[1]])
1159 PhaseSlope=numpy.ones(spc.shape[0])
1158 PhaseSlope=numpy.ones(spc.shape[0])
1160 PhaseInter=numpy.ones(spc.shape[0])
1159 PhaseInter=numpy.ones(spc.shape[0])
1161 xFrec=VelRange
1160 xFrec=VelRange
1162
1161
1163 '''Getting Eij and Nij'''
1162 '''Getting Eij and Nij'''
1164
1163
1165 E01=ChanDist[0][0]
1164 E01=ChanDist[0][0]
1166 N01=ChanDist[0][1]
1165 N01=ChanDist[0][1]
1167
1166
1168 E02=ChanDist[1][0]
1167 E02=ChanDist[1][0]
1169 N02=ChanDist[1][1]
1168 N02=ChanDist[1][1]
1170
1169
1171 E12=ChanDist[2][0]
1170 E12=ChanDist[2][0]
1172 N12=ChanDist[2][1]
1171 N12=ChanDist[2][1]
1173
1172
1174 z = spc.copy()
1173 z = spc.copy()
1175 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1174 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1176
1175
1177 for i in range(spc.shape[0]):
1176 for i in range(spc.shape[0]):
1178
1177
1179 '''****** Line of Data SPC ******'''
1178 '''****** Line of Data SPC ******'''
1180 zline=z[i,:,Height]
1179 zline=z[i,:,Height]
1181
1180
1182 '''****** SPC is normalized ******'''
1181 '''****** SPC is normalized ******'''
1183 FactNorm= (zline.copy()-noise[i]) / numpy.sum(zline.copy())
1182 FactNorm= (zline.copy()-noise[i]) / numpy.sum(zline.copy())
1184 FactNorm= FactNorm/numpy.sum(FactNorm)
1183 FactNorm= FactNorm/numpy.sum(FactNorm)
1185
1184
1186 SmoothSPC=self.moving_average(FactNorm,N=3)
1185 SmoothSPC=self.moving_average(FactNorm,N=3)
1187
1186
1188 xSamples = ar(range(len(SmoothSPC)))
1187 xSamples = ar(range(len(SmoothSPC)))
1189 ySamples[i] = SmoothSPC
1188 ySamples[i] = SmoothSPC
1190
1189
1191 #dbSNR=10*numpy.log10(dataSNR)
1190 #dbSNR=10*numpy.log10(dataSNR)
1192 print ' '
1191 print ' '
1193 print ' '
1192 print ' '
1194 print ' '
1193 print ' '
1195
1194
1196 #print 'dataSNR', dbSNR.shape, dbSNR[0,40:120]
1195 #print 'dataSNR', dbSNR.shape, dbSNR[0,40:120]
1197 print 'SmoothSPC', SmoothSPC.shape, SmoothSPC[0:20]
1196 print 'SmoothSPC', SmoothSPC.shape, SmoothSPC[0:20]
1198 print 'noise',noise
1197 print 'noise',noise
1199 print 'zline',zline.shape, zline[0:20]
1198 print 'zline',zline.shape, zline[0:20]
1200 print 'FactNorm',FactNorm.shape, FactNorm[0:20]
1199 print 'FactNorm',FactNorm.shape, FactNorm[0:20]
1201 print 'FactNorm suma', numpy.sum(FactNorm)
1200 print 'FactNorm suma', numpy.sum(FactNorm)
1202
1201
1203 for i in range(spc.shape[0]):
1202 for i in range(spc.shape[0]):
1204
1203
1205 '''****** Line of Data CSPC ******'''
1204 '''****** Line of Data CSPC ******'''
1206 cspcLine=cspc[i,:,Height].copy()
1205 cspcLine=cspc[i,:,Height].copy()
1207
1206
1208 '''****** CSPC is normalized ******'''
1207 '''****** CSPC is normalized ******'''
1209 chan_index0 = pairsList[i][0]
1208 chan_index0 = pairsList[i][0]
1210 chan_index1 = pairsList[i][1]
1209 chan_index1 = pairsList[i][1]
1211 CSPCFactor= abs(numpy.sum(ySamples[chan_index0]) * numpy.sum(ySamples[chan_index1])) #
1210 CSPCFactor= abs(numpy.sum(ySamples[chan_index0]) * numpy.sum(ySamples[chan_index1])) #
1212
1211
1213 CSPCNorm = (cspcLine.copy() -noise[i]) / numpy.sqrt(CSPCFactor)
1212 CSPCNorm = (cspcLine.copy() -noise[i]) / numpy.sqrt(CSPCFactor)
1214
1213
1215 CSPCSamples[i] = CSPCNorm
1214 CSPCSamples[i] = CSPCNorm
1216 coherence[i] = numpy.abs(CSPCSamples[i]) / numpy.sqrt(CSPCFactor)
1215 coherence[i] = numpy.abs(CSPCSamples[i]) / numpy.sqrt(CSPCFactor)
1217
1216
1218 coherence[i]= self.moving_average(coherence[i],N=2)
1217 coherence[i]= self.moving_average(coherence[i],N=2)
1219
1218
1220 phase[i] = self.moving_average( numpy.arctan2(CSPCSamples[i].imag, CSPCSamples[i].real),N=1)#*180/numpy.pi
1219 phase[i] = self.moving_average( numpy.arctan2(CSPCSamples[i].imag, CSPCSamples[i].real),N=1)#*180/numpy.pi
1221
1220
1222 print 'cspcLine', cspcLine.shape, cspcLine[0:20]
1221 print 'cspcLine', cspcLine.shape, cspcLine[0:20]
1223 print 'CSPCFactor', CSPCFactor#, CSPCFactor[0:20]
1222 print 'CSPCFactor', CSPCFactor#, CSPCFactor[0:20]
1224 print numpy.sum(ySamples[chan_index0]), numpy.sum(ySamples[chan_index1]), -noise[i]
1223 print numpy.sum(ySamples[chan_index0]), numpy.sum(ySamples[chan_index1]), -noise[i]
1225 print 'CSPCNorm', CSPCNorm.shape, CSPCNorm[0:20]
1224 print 'CSPCNorm', CSPCNorm.shape, CSPCNorm[0:20]
1226 print 'CSPCNorm suma', numpy.sum(CSPCNorm)
1225 print 'CSPCNorm suma', numpy.sum(CSPCNorm)
1227 print 'CSPCSamples', CSPCSamples.shape, CSPCSamples[0,0:20]
1226 print 'CSPCSamples', CSPCSamples.shape, CSPCSamples[0,0:20]
1228
1227
1229 '''****** Getting fij width ******'''
1228 '''****** Getting fij width ******'''
1230
1229
1231 yMean=[]
1230 yMean=[]
1232 yMean2=[]
1231 yMean2=[]
1233
1232
1234 for j in range(len(ySamples[1])):
1233 for j in range(len(ySamples[1])):
1235 yMean=numpy.append(yMean,numpy.mean([ySamples[0,j],ySamples[1,j],ySamples[2,j]]))
1234 yMean=numpy.append(yMean,numpy.mean([ySamples[0,j],ySamples[1,j],ySamples[2,j]]))
1236
1235
1237 '''******* Getting fitting Gaussian ******'''
1236 '''******* Getting fitting Gaussian ******'''
1238 meanGauss=sum(xSamples*yMean) / len(xSamples)
1237 meanGauss=sum(xSamples*yMean) / len(xSamples)
1239 sigma=sum(yMean*(xSamples-meanGauss)**2) / len(xSamples)
1238 sigma=sum(yMean*(xSamples-meanGauss)**2) / len(xSamples)
1240
1239
1241 print '****************************'
1240 print '****************************'
1242 print 'len(xSamples): ',len(xSamples)
1241 print 'len(xSamples): ',len(xSamples)
1243 print 'yMean: ', yMean.shape, yMean[0:20]
1242 print 'yMean: ', yMean.shape, yMean[0:20]
1244 print 'ySamples', ySamples.shape, ySamples[0,0:20]
1243 print 'ySamples', ySamples.shape, ySamples[0,0:20]
1245 print 'xSamples: ',xSamples.shape, xSamples[0:20]
1244 print 'xSamples: ',xSamples.shape, xSamples[0:20]
1246
1245
1247 print 'meanGauss',meanGauss
1246 print 'meanGauss',meanGauss
1248 print 'sigma',sigma
1247 print 'sigma',sigma
1249
1248
1250 #if (abs(meanGauss/sigma**2) > 0.0001) : #0.000000001):
1249 #if (abs(meanGauss/sigma**2) > 0.0001) : #0.000000001):
1251 if dbSNR > SNRlimit :
1250 if dbSNR > SNRlimit :
1252 try:
1251 try:
1253 popt,pcov = curve_fit(self.gaus,xSamples,yMean,p0=[1,meanGauss,sigma])
1252 popt,pcov = curve_fit(self.gaus,xSamples,yMean,p0=[1,meanGauss,sigma])
1254
1253
1255 if numpy.amax(popt)>numpy.amax(yMean)*0.3:
1254 if numpy.amax(popt)>numpy.amax(yMean)*0.3:
1256 FitGauss=self.gaus(xSamples,*popt)
1255 FitGauss=self.gaus(xSamples,*popt)
1257
1256
1258 else:
1257 else:
1259 FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
1258 FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
1260 print 'Verificador: Dentro', Height
1259 print 'Verificador: Dentro', Height
1261 except :#RuntimeError:
1260 except :#RuntimeError:
1262 FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
1261 FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
1263
1262
1264
1263
1265 else:
1264 else:
1266 FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
1265 FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
1267
1266
1268 Maximun=numpy.amax(yMean)
1267 Maximun=numpy.amax(yMean)
1269 eMinus1=Maximun*numpy.exp(-1)#*0.8
1268 eMinus1=Maximun*numpy.exp(-1)#*0.8
1270
1269
1271 HWpos=self.Find(FitGauss,min(FitGauss, key=lambda value:abs(value-eMinus1)))
1270 HWpos=self.Find(FitGauss,min(FitGauss, key=lambda value:abs(value-eMinus1)))
1272 HalfWidth= xFrec[HWpos]
1271 HalfWidth= xFrec[HWpos]
1273 GCpos=self.Find(FitGauss, numpy.amax(FitGauss))
1272 GCpos=self.Find(FitGauss, numpy.amax(FitGauss))
1274 Vpos=self.Find(FactNorm, numpy.amax(FactNorm))
1273 Vpos=self.Find(FactNorm, numpy.amax(FactNorm))
1275
1274
1276 #Vpos=FirstMoment[]
1275 #Vpos=FirstMoment[]
1277
1276
1278 '''****** Getting Fij ******'''
1277 '''****** Getting Fij ******'''
1279
1278
1280 GaussCenter=xFrec[GCpos]
1279 GaussCenter=xFrec[GCpos]
1281 if (GaussCenter<0 and HalfWidth>0) or (GaussCenter>0 and HalfWidth<0):
1280 if (GaussCenter<0 and HalfWidth>0) or (GaussCenter>0 and HalfWidth<0):
1282 Fij=abs(GaussCenter)+abs(HalfWidth)+0.0000001
1281 Fij=abs(GaussCenter)+abs(HalfWidth)+0.0000001
1283 else:
1282 else:
1284 Fij=abs(GaussCenter-HalfWidth)+0.0000001
1283 Fij=abs(GaussCenter-HalfWidth)+0.0000001
1285
1284
1286 '''****** Getting Frecuency range of significant data ******'''
1285 '''****** Getting Frecuency range of significant data ******'''
1287
1286
1288 Rangpos=self.Find(FitGauss,min(FitGauss, key=lambda value:abs(value-Maximun*0.10)))
1287 Rangpos=self.Find(FitGauss,min(FitGauss, key=lambda value:abs(value-Maximun*0.10)))
1289
1288
1290 if Rangpos<GCpos:
1289 if Rangpos<GCpos:
1291 Range=numpy.array([Rangpos,2*GCpos-Rangpos])
1290 Range=numpy.array([Rangpos,2*GCpos-Rangpos])
1292 elif Rangpos< ( len(xFrec)- len(xFrec)*0.1):
1291 elif Rangpos< ( len(xFrec)- len(xFrec)*0.1):
1293 Range=numpy.array([2*GCpos-Rangpos,Rangpos])
1292 Range=numpy.array([2*GCpos-Rangpos,Rangpos])
1294 else:
1293 else:
1295 Range = numpy.array([0,0])
1294 Range = numpy.array([0,0])
1296
1295
1297 print ' '
1296 print ' '
1298 print 'GCpos',GCpos, ( len(xFrec)- len(xFrec)*0.1)
1297 print 'GCpos',GCpos, ( len(xFrec)- len(xFrec)*0.1)
1299 print 'Rangpos',Rangpos
1298 print 'Rangpos',Rangpos
1300 print 'RANGE: ', Range
1299 print 'RANGE: ', Range
1301 FrecRange=xFrec[Range[0]:Range[1]]
1300 FrecRange=xFrec[Range[0]:Range[1]]
1302
1301
1303 '''****** Getting SCPC Slope ******'''
1302 '''****** Getting SCPC Slope ******'''
1304
1303
1305 for i in range(spc.shape[0]):
1304 for i in range(spc.shape[0]):
1306
1305
1307 if len(FrecRange)>5 and len(FrecRange)<spc.shape[1]*0.5:
1306 if len(FrecRange)>5 and len(FrecRange)<spc.shape[1]*0.5:
1308 PhaseRange=self.moving_average(phase[i,Range[0]:Range[1]],N=3)
1307 PhaseRange=self.moving_average(phase[i,Range[0]:Range[1]],N=3)
1309
1308
1310 print 'FrecRange', len(FrecRange) , FrecRange
1309 print 'FrecRange', len(FrecRange) , FrecRange
1311 print 'PhaseRange', len(PhaseRange), PhaseRange
1310 print 'PhaseRange', len(PhaseRange), PhaseRange
1312 print ' '
1311 print ' '
1313 if len(FrecRange) == len(PhaseRange):
1312 if len(FrecRange) == len(PhaseRange):
1314 slope, intercept, r_value, p_value, std_err = stats.linregress(FrecRange,PhaseRange)
1313 slope, intercept, r_value, p_value, std_err = stats.linregress(FrecRange,PhaseRange)
1315 PhaseSlope[i]=slope
1314 PhaseSlope[i]=slope
1316 PhaseInter[i]=intercept
1315 PhaseInter[i]=intercept
1317 else:
1316 else:
1318 PhaseSlope[i]=0
1317 PhaseSlope[i]=0
1319 PhaseInter[i]=0
1318 PhaseInter[i]=0
1320 else:
1319 else:
1321 PhaseSlope[i]=0
1320 PhaseSlope[i]=0
1322 PhaseInter[i]=0
1321 PhaseInter[i]=0
1323
1322
1324 '''Getting constant C'''
1323 '''Getting constant C'''
1325 cC=(Fij*numpy.pi)**2
1324 cC=(Fij*numpy.pi)**2
1326
1325
1327 '''****** Getting constants F and G ******'''
1326 '''****** Getting constants F and G ******'''
1328 MijEijNij=numpy.array([[E02,N02], [E12,N12]])
1327 MijEijNij=numpy.array([[E02,N02], [E12,N12]])
1329 MijResult0=(-PhaseSlope[1]*cC) / (2*numpy.pi)
1328 MijResult0=(-PhaseSlope[1]*cC) / (2*numpy.pi)
1330 MijResult1=(-PhaseSlope[2]*cC) / (2*numpy.pi)
1329 MijResult1=(-PhaseSlope[2]*cC) / (2*numpy.pi)
1331 MijResults=numpy.array([MijResult0,MijResult1])
1330 MijResults=numpy.array([MijResult0,MijResult1])
1332 (cF,cG) = numpy.linalg.solve(MijEijNij, MijResults)
1331 (cF,cG) = numpy.linalg.solve(MijEijNij, MijResults)
1333
1332
1334 '''****** Getting constants A, B and H ******'''
1333 '''****** Getting constants A, B and H ******'''
1335 W01=numpy.amax(coherence[0])
1334 W01=numpy.amax(coherence[0])
1336 W02=numpy.amax(coherence[1])
1335 W02=numpy.amax(coherence[1])
1337 W12=numpy.amax(coherence[2])
1336 W12=numpy.amax(coherence[2])
1338
1337
1339 WijResult0=((cF*E01+cG*N01)**2)/cC - numpy.log(W01 / numpy.sqrt(numpy.pi/cC))
1338 WijResult0=((cF*E01+cG*N01)**2)/cC - numpy.log(W01 / numpy.sqrt(numpy.pi/cC))
1340 WijResult1=((cF*E02+cG*N02)**2)/cC - numpy.log(W02 / numpy.sqrt(numpy.pi/cC))
1339 WijResult1=((cF*E02+cG*N02)**2)/cC - numpy.log(W02 / numpy.sqrt(numpy.pi/cC))
1341 WijResult2=((cF*E12+cG*N12)**2)/cC - numpy.log(W12 / numpy.sqrt(numpy.pi/cC))
1340 WijResult2=((cF*E12+cG*N12)**2)/cC - numpy.log(W12 / numpy.sqrt(numpy.pi/cC))
1342
1341
1343 WijResults=numpy.array([WijResult0, WijResult1, WijResult2])
1342 WijResults=numpy.array([WijResult0, WijResult1, WijResult2])
1344
1343
1345 WijEijNij=numpy.array([ [E01**2, N01**2, 2*E01*N01] , [E02**2, N02**2, 2*E02*N02] , [E12**2, N12**2, 2*E12*N12] ])
1344 WijEijNij=numpy.array([ [E01**2, N01**2, 2*E01*N01] , [E02**2, N02**2, 2*E02*N02] , [E12**2, N12**2, 2*E12*N12] ])
1346 (cA,cB,cH) = numpy.linalg.solve(WijEijNij, WijResults)
1345 (cA,cB,cH) = numpy.linalg.solve(WijEijNij, WijResults)
1347
1346
1348 VxVy=numpy.array([[cA,cH],[cH,cB]])
1347 VxVy=numpy.array([[cA,cH],[cH,cB]])
1349
1348
1350 VxVyResults=numpy.array([-cF,-cG])
1349 VxVyResults=numpy.array([-cF,-cG])
1351 (Vx,Vy) = numpy.linalg.solve(VxVy, VxVyResults)
1350 (Vx,Vy) = numpy.linalg.solve(VxVy, VxVyResults)
1352
1351
1353 Vzon = Vy
1352 Vzon = Vy
1354 Vmer = Vx
1353 Vmer = Vx
1355 Vmag=numpy.sqrt(Vzon**2+Vmer**2)
1354 Vmag=numpy.sqrt(Vzon**2+Vmer**2)
1356 Vang=numpy.arctan2(Vmer,Vzon)
1355 Vang=numpy.arctan2(Vmer,Vzon)
1357 Vver=xFrec[Vpos]
1356 Vver=xFrec[Vpos]
1358 print 'vzon y vmer', Vzon, Vmer
1357 print 'vzon y vmer', Vzon, Vmer
1359 return Vzon, Vmer, Vver, GaussCenter
1358 return Vzon, Vmer, Vver, GaussCenter
1360
1359
1361 class SpectralMoments(Operation):
1360 class SpectralMoments(Operation):
1362
1361
1363 '''
1362 '''
1364 Function SpectralMoments()
1363 Function SpectralMoments()
1365
1364
1366 Calculates moments (power, mean, standard deviation) and SNR of the signal
1365 Calculates moments (power, mean, standard deviation) and SNR of the signal
1367
1366
1368 Type of dataIn: Spectra
1367 Type of dataIn: Spectra
1369
1368
1370 Configuration Parameters:
1369 Configuration Parameters:
1371
1370
1372 dirCosx : Cosine director in X axis
1371 dirCosx : Cosine director in X axis
1373 dirCosy : Cosine director in Y axis
1372 dirCosy : Cosine director in Y axis
1374
1373
1375 elevation :
1374 elevation :
1376 azimuth :
1375 azimuth :
1377
1376
1378 Input:
1377 Input:
1379 channelList : simple channel list to select e.g. [2,3,7]
1378 channelList : simple channel list to select e.g. [2,3,7]
1380 self.dataOut.data_pre : Spectral data
1379 self.dataOut.data_pre : Spectral data
1381 self.dataOut.abscissaList : List of frequencies
1380 self.dataOut.abscissaList : List of frequencies
1382 self.dataOut.noise : Noise level per channel
1381 self.dataOut.noise : Noise level per channel
1383
1382
1384 Affected:
1383 Affected:
1385 self.dataOut.data_param : Parameters per channel
1384 self.dataOut.data_param : Parameters per channel
1386 self.dataOut.data_SNR : SNR per channel
1385 self.dataOut.data_SNR : SNR per channel
1387
1386
1388 '''
1387 '''
1389
1388
1390 def run(self, dataOut):
1389 def run(self, dataOut):
1391
1390
1392 #dataOut.data_pre = dataOut.data_pre[0]
1391 #dataOut.data_pre = dataOut.data_pre[0]
1393 data = dataOut.data_pre[0]
1392 data = dataOut.data_pre[0]
1394 absc = dataOut.abscissaList[:-1]
1393 absc = dataOut.abscissaList[:-1]
1395 noise = dataOut.noise
1394 noise = dataOut.noise
1396 nChannel = data.shape[0]
1395 nChannel = data.shape[0]
1397 data_param = numpy.zeros((nChannel, 4, data.shape[2]))
1396 data_param = numpy.zeros((nChannel, 4, data.shape[2]))
1398
1397
1399 for ind in range(nChannel):
1398 for ind in range(nChannel):
1400 data_param[ind,:,:] = self.__calculateMoments( data[ind,:,:] , absc , noise[ind] )
1399 data_param[ind,:,:] = self.__calculateMoments( data[ind,:,:] , absc , noise[ind] )
1401
1400
1402 dataOut.data_param = data_param[:,1:,:]
1401 dataOut.data_param = data_param[:,1:,:]
1403 dataOut.data_SNR = data_param[:,0]
1402 dataOut.data_SNR = data_param[:,0]
1404 dataOut.data_DOP = data_param[:,1]
1403 dataOut.data_DOP = data_param[:,1]
1405 dataOut.data_MEAN = data_param[:,2]
1404 dataOut.data_MEAN = data_param[:,2]
1406 dataOut.data_STD = data_param[:,3]
1405 dataOut.data_STD = data_param[:,3]
1407 return
1406 return
1408
1407
1409 def __calculateMoments(self, oldspec, oldfreq, n0,
1408 def __calculateMoments(self, oldspec, oldfreq, n0,
1410 nicoh = None, graph = None, smooth = None, type1 = None, fwindow = None, snrth = None, dc = None, aliasing = None, oldfd = None, wwauto = None):
1409 nicoh = None, graph = None, smooth = None, type1 = None, fwindow = None, snrth = None, dc = None, aliasing = None, oldfd = None, wwauto = None):
1411
1410
1412 if (nicoh == None): nicoh = 1
1411 if (nicoh == None): nicoh = 1
1413 if (graph == None): graph = 0
1412 if (graph == None): graph = 0
1414 if (smooth == None): smooth = 0
1413 if (smooth == None): smooth = 0
1415 elif (self.smooth < 3): smooth = 0
1414 elif (self.smooth < 3): smooth = 0
1416
1415
1417 if (type1 == None): type1 = 0
1416 if (type1 == None): type1 = 0
1418 if (fwindow == None): fwindow = numpy.zeros(oldfreq.size) + 1
1417 if (fwindow == None): fwindow = numpy.zeros(oldfreq.size) + 1
1419 if (snrth == None): snrth = -3
1418 if (snrth == None): snrth = -3
1420 if (dc == None): dc = 0
1419 if (dc == None): dc = 0
1421 if (aliasing == None): aliasing = 0
1420 if (aliasing == None): aliasing = 0
1422 if (oldfd == None): oldfd = 0
1421 if (oldfd == None): oldfd = 0
1423 if (wwauto == None): wwauto = 0
1422 if (wwauto == None): wwauto = 0
1424
1423
1425 if (n0 < 1.e-20): n0 = 1.e-20
1424 if (n0 < 1.e-20): n0 = 1.e-20
1426
1425
1427 freq = oldfreq
1426 freq = oldfreq
1428 vec_power = numpy.zeros(oldspec.shape[1])
1427 vec_power = numpy.zeros(oldspec.shape[1])
1429 vec_fd = numpy.zeros(oldspec.shape[1])
1428 vec_fd = numpy.zeros(oldspec.shape[1])
1430 vec_w = numpy.zeros(oldspec.shape[1])
1429 vec_w = numpy.zeros(oldspec.shape[1])
1431 vec_snr = numpy.zeros(oldspec.shape[1])
1430 vec_snr = numpy.zeros(oldspec.shape[1])
1432
1431
1433 for ind in range(oldspec.shape[1]):
1432 for ind in range(oldspec.shape[1]):
1434
1433
1435 spec = oldspec[:,ind]
1434 spec = oldspec[:,ind]
1436 aux = spec*fwindow
1435 aux = spec*fwindow
1437 max_spec = aux.max()
1436 max_spec = aux.max()
1438 m = list(aux).index(max_spec)
1437 m = list(aux).index(max_spec)
1439
1438
1440 #Smooth
1439 #Smooth
1441 if (smooth == 0): spec2 = spec
1440 if (smooth == 0): spec2 = spec
1442 else: spec2 = scipy.ndimage.filters.uniform_filter1d(spec,size=smooth)
1441 else: spec2 = scipy.ndimage.filters.uniform_filter1d(spec,size=smooth)
1443
1442
1444 # Calculo de Momentos
1443 # Calculo de Momentos
1445 bb = spec2[range(m,spec2.size)]
1444 bb = spec2[range(m,spec2.size)]
1446 bb = (bb<n0).nonzero()
1445 bb = (bb<n0).nonzero()
1447 bb = bb[0]
1446 bb = bb[0]
1448
1447
1449 ss = spec2[range(0,m + 1)]
1448 ss = spec2[range(0,m + 1)]
1450 ss = (ss<n0).nonzero()
1449 ss = (ss<n0).nonzero()
1451 ss = ss[0]
1450 ss = ss[0]
1452
1451
1453 if (bb.size == 0):
1452 if (bb.size == 0):
1454 bb0 = spec.size - 1 - m
1453 bb0 = spec.size - 1 - m
1455 else:
1454 else:
1456 bb0 = bb[0] - 1
1455 bb0 = bb[0] - 1
1457 if (bb0 < 0):
1456 if (bb0 < 0):
1458 bb0 = 0
1457 bb0 = 0
1459
1458
1460 if (ss.size == 0): ss1 = 1
1459 if (ss.size == 0): ss1 = 1
1461 else: ss1 = max(ss) + 1
1460 else: ss1 = max(ss) + 1
1462
1461
1463 if (ss1 > m): ss1 = m
1462 if (ss1 > m): ss1 = m
1464
1463
1465 valid = numpy.asarray(range(int(m + bb0 - ss1 + 1))) + ss1
1464 valid = numpy.asarray(range(int(m + bb0 - ss1 + 1))) + ss1
1466 power = ((spec2[valid] - n0)*fwindow[valid]).sum()
1465 power = ((spec2[valid] - n0)*fwindow[valid]).sum()
1467 fd = ((spec2[valid]- n0)*freq[valid]*fwindow[valid]).sum()/power
1466 fd = ((spec2[valid]- n0)*freq[valid]*fwindow[valid]).sum()/power
1468 w = math.sqrt(((spec2[valid] - n0)*fwindow[valid]*(freq[valid]- fd)**2).sum()/power)
1467 w = math.sqrt(((spec2[valid] - n0)*fwindow[valid]*(freq[valid]- fd)**2).sum()/power)
1469 snr = (spec2.mean()-n0)/n0
1468 snr = (spec2.mean()-n0)/n0
1470
1469
1471 if (snr < 1.e-20) :
1470 if (snr < 1.e-20) :
1472 snr = 1.e-20
1471 snr = 1.e-20
1473
1472
1474 vec_power[ind] = power
1473 vec_power[ind] = power
1475 vec_fd[ind] = fd
1474 vec_fd[ind] = fd
1476 vec_w[ind] = w
1475 vec_w[ind] = w
1477 vec_snr[ind] = snr
1476 vec_snr[ind] = snr
1478
1477
1479 moments = numpy.vstack((vec_snr, vec_power, vec_fd, vec_w))
1478 moments = numpy.vstack((vec_snr, vec_power, vec_fd, vec_w))
1480 return moments
1479 return moments
1481
1480
1482 #------------------ Get SA Parameters --------------------------
1481 #------------------ Get SA Parameters --------------------------
1483
1482
1484 def GetSAParameters(self):
1483 def GetSAParameters(self):
1485 #SA en frecuencia
1484 #SA en frecuencia
1486 pairslist = self.dataOut.groupList
1485 pairslist = self.dataOut.groupList
1487 num_pairs = len(pairslist)
1486 num_pairs = len(pairslist)
1488
1487
1489 vel = self.dataOut.abscissaList
1488 vel = self.dataOut.abscissaList
1490 spectra = self.dataOut.data_pre
1489 spectra = self.dataOut.data_pre
1491 cspectra = self.dataIn.data_cspc
1490 cspectra = self.dataIn.data_cspc
1492 delta_v = vel[1] - vel[0]
1491 delta_v = vel[1] - vel[0]
1493
1492
1494 #Calculating the power spectrum
1493 #Calculating the power spectrum
1495 spc_pow = numpy.sum(spectra, 3)*delta_v
1494 spc_pow = numpy.sum(spectra, 3)*delta_v
1496 #Normalizing Spectra
1495 #Normalizing Spectra
1497 norm_spectra = spectra/spc_pow
1496 norm_spectra = spectra/spc_pow
1498 #Calculating the norm_spectra at peak
1497 #Calculating the norm_spectra at peak
1499 max_spectra = numpy.max(norm_spectra, 3)
1498 max_spectra = numpy.max(norm_spectra, 3)
1500
1499
1501 #Normalizing Cross Spectra
1500 #Normalizing Cross Spectra
1502 norm_cspectra = numpy.zeros(cspectra.shape)
1501 norm_cspectra = numpy.zeros(cspectra.shape)
1503
1502
1504 for i in range(num_chan):
1503 for i in range(num_chan):
1505 norm_cspectra[i,:,:] = cspectra[i,:,:]/numpy.sqrt(spc_pow[pairslist[i][0],:]*spc_pow[pairslist[i][1],:])
1504 norm_cspectra[i,:,:] = cspectra[i,:,:]/numpy.sqrt(spc_pow[pairslist[i][0],:]*spc_pow[pairslist[i][1],:])
1506
1505
1507 max_cspectra = numpy.max(norm_cspectra,2)
1506 max_cspectra = numpy.max(norm_cspectra,2)
1508 max_cspectra_index = numpy.argmax(norm_cspectra, 2)
1507 max_cspectra_index = numpy.argmax(norm_cspectra, 2)
1509
1508
1510 for i in range(num_pairs):
1509 for i in range(num_pairs):
1511 cspc_par[i,:,:] = __calculateMoments(norm_cspectra)
1510 cspc_par[i,:,:] = __calculateMoments(norm_cspectra)
1512 #------------------- Get Lags ----------------------------------
1511 #------------------- Get Lags ----------------------------------
1513
1512
1514 class SALags(Operation):
1513 class SALags(Operation):
1515 '''
1514 '''
1516 Function GetMoments()
1515 Function GetMoments()
1517
1516
1518 Input:
1517 Input:
1519 self.dataOut.data_pre
1518 self.dataOut.data_pre
1520 self.dataOut.abscissaList
1519 self.dataOut.abscissaList
1521 self.dataOut.noise
1520 self.dataOut.noise
1522 self.dataOut.normFactor
1521 self.dataOut.normFactor
1523 self.dataOut.data_SNR
1522 self.dataOut.data_SNR
1524 self.dataOut.groupList
1523 self.dataOut.groupList
1525 self.dataOut.nChannels
1524 self.dataOut.nChannels
1526
1525
1527 Affected:
1526 Affected:
1528 self.dataOut.data_param
1527 self.dataOut.data_param
1529
1528
1530 '''
1529 '''
1531 def run(self, dataOut):
1530 def run(self, dataOut):
1532 data_acf = dataOut.data_pre[0]
1531 data_acf = dataOut.data_pre[0]
1533 data_ccf = dataOut.data_pre[1]
1532 data_ccf = dataOut.data_pre[1]
1534 normFactor_acf = dataOut.normFactor[0]
1533 normFactor_acf = dataOut.normFactor[0]
1535 normFactor_ccf = dataOut.normFactor[1]
1534 normFactor_ccf = dataOut.normFactor[1]
1536 pairs_acf = dataOut.groupList[0]
1535 pairs_acf = dataOut.groupList[0]
1537 pairs_ccf = dataOut.groupList[1]
1536 pairs_ccf = dataOut.groupList[1]
1538
1537
1539 nHeights = dataOut.nHeights
1538 nHeights = dataOut.nHeights
1540 absc = dataOut.abscissaList
1539 absc = dataOut.abscissaList
1541 noise = dataOut.noise
1540 noise = dataOut.noise
1542 SNR = dataOut.data_SNR
1541 SNR = dataOut.data_SNR
1543 nChannels = dataOut.nChannels
1542 nChannels = dataOut.nChannels
1544 # pairsList = dataOut.groupList
1543 # pairsList = dataOut.groupList
1545 # pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairsList, nChannels)
1544 # pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairsList, nChannels)
1546
1545
1547 for l in range(len(pairs_acf)):
1546 for l in range(len(pairs_acf)):
1548 data_acf[l,:,:] = data_acf[l,:,:]/normFactor_acf[l,:]
1547 data_acf[l,:,:] = data_acf[l,:,:]/normFactor_acf[l,:]
1549
1548
1550 for l in range(len(pairs_ccf)):
1549 for l in range(len(pairs_ccf)):
1551 data_ccf[l,:,:] = data_ccf[l,:,:]/normFactor_ccf[l,:]
1550 data_ccf[l,:,:] = data_ccf[l,:,:]/normFactor_ccf[l,:]
1552
1551
1553 dataOut.data_param = numpy.zeros((len(pairs_ccf)*2 + 1, nHeights))
1552 dataOut.data_param = numpy.zeros((len(pairs_ccf)*2 + 1, nHeights))
1554 dataOut.data_param[:-1,:] = self.__calculateTaus(data_acf, data_ccf, absc)
1553 dataOut.data_param[:-1,:] = self.__calculateTaus(data_acf, data_ccf, absc)
1555 dataOut.data_param[-1,:] = self.__calculateLag1Phase(data_acf, absc)
1554 dataOut.data_param[-1,:] = self.__calculateLag1Phase(data_acf, absc)
1556 return
1555 return
1557
1556
1558 # def __getPairsAutoCorr(self, pairsList, nChannels):
1557 # def __getPairsAutoCorr(self, pairsList, nChannels):
1559 #
1558 #
1560 # pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan
1559 # pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan
1561 #
1560 #
1562 # for l in range(len(pairsList)):
1561 # for l in range(len(pairsList)):
1563 # firstChannel = pairsList[l][0]
1562 # firstChannel = pairsList[l][0]
1564 # secondChannel = pairsList[l][1]
1563 # secondChannel = pairsList[l][1]
1565 #
1564 #
1566 # #Obteniendo pares de Autocorrelacion
1565 # #Obteniendo pares de Autocorrelacion
1567 # if firstChannel == secondChannel:
1566 # if firstChannel == secondChannel:
1568 # pairsAutoCorr[firstChannel] = int(l)
1567 # pairsAutoCorr[firstChannel] = int(l)
1569 #
1568 #
1570 # pairsAutoCorr = pairsAutoCorr.astype(int)
1569 # pairsAutoCorr = pairsAutoCorr.astype(int)
1571 #
1570 #
1572 # pairsCrossCorr = range(len(pairsList))
1571 # pairsCrossCorr = range(len(pairsList))
1573 # pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr)
1572 # pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr)
1574 #
1573 #
1575 # return pairsAutoCorr, pairsCrossCorr
1574 # return pairsAutoCorr, pairsCrossCorr
1576
1575
1577 def __calculateTaus(self, data_acf, data_ccf, lagRange):
1576 def __calculateTaus(self, data_acf, data_ccf, lagRange):
1578
1577
1579 lag0 = data_acf.shape[1]/2
1578 lag0 = data_acf.shape[1]/2
1580 #Funcion de Autocorrelacion
1579 #Funcion de Autocorrelacion
1581 mean_acf = stats.nanmean(data_acf, axis = 0)
1580 mean_acf = stats.nanmean(data_acf, axis = 0)
1582
1581
1583 #Obtencion Indice de TauCross
1582 #Obtencion Indice de TauCross
1584 ind_ccf = data_ccf.argmax(axis = 1)
1583 ind_ccf = data_ccf.argmax(axis = 1)
1585 #Obtencion Indice de TauAuto
1584 #Obtencion Indice de TauAuto
1586 ind_acf = numpy.zeros(ind_ccf.shape,dtype = 'int')
1585 ind_acf = numpy.zeros(ind_ccf.shape,dtype = 'int')
1587 ccf_lag0 = data_ccf[:,lag0,:]
1586 ccf_lag0 = data_ccf[:,lag0,:]
1588
1587
1589 for i in range(ccf_lag0.shape[0]):
1588 for i in range(ccf_lag0.shape[0]):
1590 ind_acf[i,:] = numpy.abs(mean_acf - ccf_lag0[i,:]).argmin(axis = 0)
1589 ind_acf[i,:] = numpy.abs(mean_acf - ccf_lag0[i,:]).argmin(axis = 0)
1591
1590
1592 #Obtencion de TauCross y TauAuto
1591 #Obtencion de TauCross y TauAuto
1593 tau_ccf = lagRange[ind_ccf]
1592 tau_ccf = lagRange[ind_ccf]
1594 tau_acf = lagRange[ind_acf]
1593 tau_acf = lagRange[ind_acf]
1595
1594
1596 Nan1, Nan2 = numpy.where(tau_ccf == lagRange[0])
1595 Nan1, Nan2 = numpy.where(tau_ccf == lagRange[0])
1597
1596
1598 tau_ccf[Nan1,Nan2] = numpy.nan
1597 tau_ccf[Nan1,Nan2] = numpy.nan
1599 tau_acf[Nan1,Nan2] = numpy.nan
1598 tau_acf[Nan1,Nan2] = numpy.nan
1600 tau = numpy.vstack((tau_ccf,tau_acf))
1599 tau = numpy.vstack((tau_ccf,tau_acf))
1601
1600
1602 return tau
1601 return tau
1603
1602
1604 def __calculateLag1Phase(self, data, lagTRange):
1603 def __calculateLag1Phase(self, data, lagTRange):
1605 data1 = stats.nanmean(data, axis = 0)
1604 data1 = stats.nanmean(data, axis = 0)
1606 lag1 = numpy.where(lagTRange == 0)[0][0] + 1
1605 lag1 = numpy.where(lagTRange == 0)[0][0] + 1
1607
1606
1608 phase = numpy.angle(data1[lag1,:])
1607 phase = numpy.angle(data1[lag1,:])
1609
1608
1610 return phase
1609 return phase
1611
1610
1612 class SpectralFitting(Operation):
1611 class SpectralFitting(Operation):
1613 '''
1612 '''
1614 Function GetMoments()
1613 Function GetMoments()
1615
1614
1616 Input:
1615 Input:
1617 Output:
1616 Output:
1618 Variables modified:
1617 Variables modified:
1619 '''
1618 '''
1620
1619
1621 def run(self, dataOut, getSNR = True, path=None, file=None, groupList=None):
1620 def run(self, dataOut, getSNR = True, path=None, file=None, groupList=None):
1622
1621
1623
1622
1624 if path != None:
1623 if path != None:
1625 sys.path.append(path)
1624 sys.path.append(path)
1626 self.dataOut.library = importlib.import_module(file)
1625 self.dataOut.library = importlib.import_module(file)
1627
1626
1628 #To be inserted as a parameter
1627 #To be inserted as a parameter
1629 groupArray = numpy.array(groupList)
1628 groupArray = numpy.array(groupList)
1630 # groupArray = numpy.array([[0,1],[2,3]])
1629 # groupArray = numpy.array([[0,1],[2,3]])
1631 self.dataOut.groupList = groupArray
1630 self.dataOut.groupList = groupArray
1632
1631
1633 nGroups = groupArray.shape[0]
1632 nGroups = groupArray.shape[0]
1634 nChannels = self.dataIn.nChannels
1633 nChannels = self.dataIn.nChannels
1635 nHeights=self.dataIn.heightList.size
1634 nHeights=self.dataIn.heightList.size
1636
1635
1637 #Parameters Array
1636 #Parameters Array
1638 self.dataOut.data_param = None
1637 self.dataOut.data_param = None
1639
1638
1640 #Set constants
1639 #Set constants
1641 constants = self.dataOut.library.setConstants(self.dataIn)
1640 constants = self.dataOut.library.setConstants(self.dataIn)
1642 self.dataOut.constants = constants
1641 self.dataOut.constants = constants
1643 M = self.dataIn.normFactor
1642 M = self.dataIn.normFactor
1644 N = self.dataIn.nFFTPoints
1643 N = self.dataIn.nFFTPoints
1645 ippSeconds = self.dataIn.ippSeconds
1644 ippSeconds = self.dataIn.ippSeconds
1646 K = self.dataIn.nIncohInt
1645 K = self.dataIn.nIncohInt
1647 pairsArray = numpy.array(self.dataIn.pairsList)
1646 pairsArray = numpy.array(self.dataIn.pairsList)
1648
1647
1649 #List of possible combinations
1648 #List of possible combinations
1650 listComb = itertools.combinations(numpy.arange(groupArray.shape[1]),2)
1649 listComb = itertools.combinations(numpy.arange(groupArray.shape[1]),2)
1651 indCross = numpy.zeros(len(list(listComb)), dtype = 'int')
1650 indCross = numpy.zeros(len(list(listComb)), dtype = 'int')
1652
1651
1653 if getSNR:
1652 if getSNR:
1654 listChannels = groupArray.reshape((groupArray.size))
1653 listChannels = groupArray.reshape((groupArray.size))
1655 listChannels.sort()
1654 listChannels.sort()
1656 noise = self.dataIn.getNoise()
1655 noise = self.dataIn.getNoise()
1657 self.dataOut.data_SNR = self.__getSNR(self.dataIn.data_spc[listChannels,:,:], noise[listChannels])
1656 self.dataOut.data_SNR = self.__getSNR(self.dataIn.data_spc[listChannels,:,:], noise[listChannels])
1658
1657
1659 for i in range(nGroups):
1658 for i in range(nGroups):
1660 coord = groupArray[i,:]
1659 coord = groupArray[i,:]
1661
1660
1662 #Input data array
1661 #Input data array
1663 data = self.dataIn.data_spc[coord,:,:]/(M*N)
1662 data = self.dataIn.data_spc[coord,:,:]/(M*N)
1664 data = data.reshape((data.shape[0]*data.shape[1],data.shape[2]))
1663 data = data.reshape((data.shape[0]*data.shape[1],data.shape[2]))
1665
1664
1666 #Cross Spectra data array for Covariance Matrixes
1665 #Cross Spectra data array for Covariance Matrixes
1667 ind = 0
1666 ind = 0
1668 for pairs in listComb:
1667 for pairs in listComb:
1669 pairsSel = numpy.array([coord[x],coord[y]])
1668 pairsSel = numpy.array([coord[x],coord[y]])
1670 indCross[ind] = int(numpy.where(numpy.all(pairsArray == pairsSel, axis = 1))[0][0])
1669 indCross[ind] = int(numpy.where(numpy.all(pairsArray == pairsSel, axis = 1))[0][0])
1671 ind += 1
1670 ind += 1
1672 dataCross = self.dataIn.data_cspc[indCross,:,:]/(M*N)
1671 dataCross = self.dataIn.data_cspc[indCross,:,:]/(M*N)
1673 dataCross = dataCross**2/K
1672 dataCross = dataCross**2/K
1674
1673
1675 for h in range(nHeights):
1674 for h in range(nHeights):
1676 # print self.dataOut.heightList[h]
1675 # print self.dataOut.heightList[h]
1677
1676
1678 #Input
1677 #Input
1679 d = data[:,h]
1678 d = data[:,h]
1680
1679
1681 #Covariance Matrix
1680 #Covariance Matrix
1682 D = numpy.diag(d**2/K)
1681 D = numpy.diag(d**2/K)
1683 ind = 0
1682 ind = 0
1684 for pairs in listComb:
1683 for pairs in listComb:
1685 #Coordinates in Covariance Matrix
1684 #Coordinates in Covariance Matrix
1686 x = pairs[0]
1685 x = pairs[0]
1687 y = pairs[1]
1686 y = pairs[1]
1688 #Channel Index
1687 #Channel Index
1689 S12 = dataCross[ind,:,h]
1688 S12 = dataCross[ind,:,h]
1690 D12 = numpy.diag(S12)
1689 D12 = numpy.diag(S12)
1691 #Completing Covariance Matrix with Cross Spectras
1690 #Completing Covariance Matrix with Cross Spectras
1692 D[x*N:(x+1)*N,y*N:(y+1)*N] = D12
1691 D[x*N:(x+1)*N,y*N:(y+1)*N] = D12
1693 D[y*N:(y+1)*N,x*N:(x+1)*N] = D12
1692 D[y*N:(y+1)*N,x*N:(x+1)*N] = D12
1694 ind += 1
1693 ind += 1
1695 Dinv=numpy.linalg.inv(D)
1694 Dinv=numpy.linalg.inv(D)
1696 L=numpy.linalg.cholesky(Dinv)
1695 L=numpy.linalg.cholesky(Dinv)
1697 LT=L.T
1696 LT=L.T
1698
1697
1699 dp = numpy.dot(LT,d)
1698 dp = numpy.dot(LT,d)
1700
1699
1701 #Initial values
1700 #Initial values
1702 data_spc = self.dataIn.data_spc[coord,:,h]
1701 data_spc = self.dataIn.data_spc[coord,:,h]
1703
1702
1704 if (h>0)and(error1[3]<5):
1703 if (h>0)and(error1[3]<5):
1705 p0 = self.dataOut.data_param[i,:,h-1]
1704 p0 = self.dataOut.data_param[i,:,h-1]
1706 else:
1705 else:
1707 p0 = numpy.array(self.dataOut.library.initialValuesFunction(data_spc, constants, i))
1706 p0 = numpy.array(self.dataOut.library.initialValuesFunction(data_spc, constants, i))
1708
1707
1709 try:
1708 try:
1710 #Least Squares
1709 #Least Squares
1711 minp,covp,infodict,mesg,ier = optimize.leastsq(self.__residFunction,p0,args=(dp,LT,constants),full_output=True)
1710 minp,covp,infodict,mesg,ier = optimize.leastsq(self.__residFunction,p0,args=(dp,LT,constants),full_output=True)
1712 # minp,covp = optimize.leastsq(self.__residFunction,p0,args=(dp,LT,constants))
1711 # minp,covp = optimize.leastsq(self.__residFunction,p0,args=(dp,LT,constants))
1713 #Chi square error
1712 #Chi square error
1714 error0 = numpy.sum(infodict['fvec']**2)/(2*N)
1713 error0 = numpy.sum(infodict['fvec']**2)/(2*N)
1715 #Error with Jacobian
1714 #Error with Jacobian
1716 error1 = self.dataOut.library.errorFunction(minp,constants,LT)
1715 error1 = self.dataOut.library.errorFunction(minp,constants,LT)
1717 except:
1716 except:
1718 minp = p0*numpy.nan
1717 minp = p0*numpy.nan
1719 error0 = numpy.nan
1718 error0 = numpy.nan
1720 error1 = p0*numpy.nan
1719 error1 = p0*numpy.nan
1721
1720
1722 #Save
1721 #Save
1723 if self.dataOut.data_param == None:
1722 if self.dataOut.data_param == None:
1724 self.dataOut.data_param = numpy.zeros((nGroups, p0.size, nHeights))*numpy.nan
1723 self.dataOut.data_param = numpy.zeros((nGroups, p0.size, nHeights))*numpy.nan
1725 self.dataOut.data_error = numpy.zeros((nGroups, p0.size + 1, nHeights))*numpy.nan
1724 self.dataOut.data_error = numpy.zeros((nGroups, p0.size + 1, nHeights))*numpy.nan
1726
1725
1727 self.dataOut.data_error[i,:,h] = numpy.hstack((error0,error1))
1726 self.dataOut.data_error[i,:,h] = numpy.hstack((error0,error1))
1728 self.dataOut.data_param[i,:,h] = minp
1727 self.dataOut.data_param[i,:,h] = minp
1729 return
1728 return
1730
1729
1731 def __residFunction(self, p, dp, LT, constants):
1730 def __residFunction(self, p, dp, LT, constants):
1732
1731
1733 fm = self.dataOut.library.modelFunction(p, constants)
1732 fm = self.dataOut.library.modelFunction(p, constants)
1734 fmp=numpy.dot(LT,fm)
1733 fmp=numpy.dot(LT,fm)
1735
1734
1736 return dp-fmp
1735 return dp-fmp
1737
1736
1738 def __getSNR(self, z, noise):
1737 def __getSNR(self, z, noise):
1739
1738
1740 avg = numpy.average(z, axis=1)
1739 avg = numpy.average(z, axis=1)
1741 SNR = (avg.T-noise)/noise
1740 SNR = (avg.T-noise)/noise
1742 SNR = SNR.T
1741 SNR = SNR.T
1743 return SNR
1742 return SNR
1744
1743
1745 def __chisq(p,chindex,hindex):
1744 def __chisq(p,chindex,hindex):
1746 #similar to Resid but calculates CHI**2
1745 #similar to Resid but calculates CHI**2
1747 [LT,d,fm]=setupLTdfm(p,chindex,hindex)
1746 [LT,d,fm]=setupLTdfm(p,chindex,hindex)
1748 dp=numpy.dot(LT,d)
1747 dp=numpy.dot(LT,d)
1749 fmp=numpy.dot(LT,fm)
1748 fmp=numpy.dot(LT,fm)
1750 chisq=numpy.dot((dp-fmp).T,(dp-fmp))
1749 chisq=numpy.dot((dp-fmp).T,(dp-fmp))
1751 return chisq
1750 return chisq
1752
1751
1753 class WindProfiler(Operation):
1752 class WindProfiler(Operation):
1754
1753
1755 __isConfig = False
1754 __isConfig = False
1756
1755
1757 __initime = None
1756 __initime = None
1758 __lastdatatime = None
1757 __lastdatatime = None
1759 __integrationtime = None
1758 __integrationtime = None
1760
1759
1761 __buffer = None
1760 __buffer = None
1762
1761
1763 __dataReady = False
1762 __dataReady = False
1764
1763
1765 __firstdata = None
1764 __firstdata = None
1766
1765
1767 n = None
1766 n = None
1768
1767
1769 def __init__(self):
1768 def __init__(self):
1770 Operation.__init__(self)
1769 Operation.__init__(self)
1771
1770
1772 def __calculateCosDir(self, elev, azim):
1771 def __calculateCosDir(self, elev, azim):
1773 zen = (90 - elev)*numpy.pi/180
1772 zen = (90 - elev)*numpy.pi/180
1774 azim = azim*numpy.pi/180
1773 azim = azim*numpy.pi/180
1775 cosDirX = numpy.sqrt((1-numpy.cos(zen)**2)/((1+numpy.tan(azim)**2)))
1774 cosDirX = numpy.sqrt((1-numpy.cos(zen)**2)/((1+numpy.tan(azim)**2)))
1776 cosDirY = numpy.sqrt(1-numpy.cos(zen)**2-cosDirX**2)
1775 cosDirY = numpy.sqrt(1-numpy.cos(zen)**2-cosDirX**2)
1777
1776
1778 signX = numpy.sign(numpy.cos(azim))
1777 signX = numpy.sign(numpy.cos(azim))
1779 signY = numpy.sign(numpy.sin(azim))
1778 signY = numpy.sign(numpy.sin(azim))
1780
1779
1781 cosDirX = numpy.copysign(cosDirX, signX)
1780 cosDirX = numpy.copysign(cosDirX, signX)
1782 cosDirY = numpy.copysign(cosDirY, signY)
1781 cosDirY = numpy.copysign(cosDirY, signY)
1783 return cosDirX, cosDirY
1782 return cosDirX, cosDirY
1784
1783
1785 def __calculateAngles(self, theta_x, theta_y, azimuth):
1784 def __calculateAngles(self, theta_x, theta_y, azimuth):
1786
1785
1787 dir_cosw = numpy.sqrt(1-theta_x**2-theta_y**2)
1786 dir_cosw = numpy.sqrt(1-theta_x**2-theta_y**2)
1788 zenith_arr = numpy.arccos(dir_cosw)
1787 zenith_arr = numpy.arccos(dir_cosw)
1789 azimuth_arr = numpy.arctan2(theta_x,theta_y) + azimuth*math.pi/180
1788 azimuth_arr = numpy.arctan2(theta_x,theta_y) + azimuth*math.pi/180
1790
1789
1791 dir_cosu = numpy.sin(azimuth_arr)*numpy.sin(zenith_arr)
1790 dir_cosu = numpy.sin(azimuth_arr)*numpy.sin(zenith_arr)
1792 dir_cosv = numpy.cos(azimuth_arr)*numpy.sin(zenith_arr)
1791 dir_cosv = numpy.cos(azimuth_arr)*numpy.sin(zenith_arr)
1793
1792
1794 return azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw
1793 return azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw
1795
1794
1796 def __calculateMatA(self, dir_cosu, dir_cosv, dir_cosw, horOnly):
1795 def __calculateMatA(self, dir_cosu, dir_cosv, dir_cosw, horOnly):
1797
1796
1798 #
1797 #
1799 if horOnly:
1798 if horOnly:
1800 A = numpy.c_[dir_cosu,dir_cosv]
1799 A = numpy.c_[dir_cosu,dir_cosv]
1801 else:
1800 else:
1802 A = numpy.c_[dir_cosu,dir_cosv,dir_cosw]
1801 A = numpy.c_[dir_cosu,dir_cosv,dir_cosw]
1803 A = numpy.asmatrix(A)
1802 A = numpy.asmatrix(A)
1804 A1 = numpy.linalg.inv(A.transpose()*A)*A.transpose()
1803 A1 = numpy.linalg.inv(A.transpose()*A)*A.transpose()
1805
1804
1806 return A1
1805 return A1
1807
1806
1808 def __correctValues(self, heiRang, phi, velRadial, SNR):
1807 def __correctValues(self, heiRang, phi, velRadial, SNR):
1809 listPhi = phi.tolist()
1808 listPhi = phi.tolist()
1810 maxid = listPhi.index(max(listPhi))
1809 maxid = listPhi.index(max(listPhi))
1811 minid = listPhi.index(min(listPhi))
1810 minid = listPhi.index(min(listPhi))
1812
1811
1813 rango = range(len(phi))
1812 rango = range(len(phi))
1814 # rango = numpy.delete(rango,maxid)
1813 # rango = numpy.delete(rango,maxid)
1815
1814
1816 heiRang1 = heiRang*math.cos(phi[maxid])
1815 heiRang1 = heiRang*math.cos(phi[maxid])
1817 heiRangAux = heiRang*math.cos(phi[minid])
1816 heiRangAux = heiRang*math.cos(phi[minid])
1818 indOut = (heiRang1 < heiRangAux[0]).nonzero()
1817 indOut = (heiRang1 < heiRangAux[0]).nonzero()
1819 heiRang1 = numpy.delete(heiRang1,indOut)
1818 heiRang1 = numpy.delete(heiRang1,indOut)
1820
1819
1821 velRadial1 = numpy.zeros([len(phi),len(heiRang1)])
1820 velRadial1 = numpy.zeros([len(phi),len(heiRang1)])
1822 SNR1 = numpy.zeros([len(phi),len(heiRang1)])
1821 SNR1 = numpy.zeros([len(phi),len(heiRang1)])
1823
1822
1824 for i in rango:
1823 for i in rango:
1825 x = heiRang*math.cos(phi[i])
1824 x = heiRang*math.cos(phi[i])
1826 y1 = velRadial[i,:]
1825 y1 = velRadial[i,:]
1827 f1 = interpolate.interp1d(x,y1,kind = 'cubic')
1826 f1 = interpolate.interp1d(x,y1,kind = 'cubic')
1828
1827
1829 x1 = heiRang1
1828 x1 = heiRang1
1830 y11 = f1(x1)
1829 y11 = f1(x1)
1831
1830
1832 y2 = SNR[i,:]
1831 y2 = SNR[i,:]
1833 f2 = interpolate.interp1d(x,y2,kind = 'cubic')
1832 f2 = interpolate.interp1d(x,y2,kind = 'cubic')
1834 y21 = f2(x1)
1833 y21 = f2(x1)
1835
1834
1836 velRadial1[i,:] = y11
1835 velRadial1[i,:] = y11
1837 SNR1[i,:] = y21
1836 SNR1[i,:] = y21
1838
1837
1839 return heiRang1, velRadial1, SNR1
1838 return heiRang1, velRadial1, SNR1
1840
1839
1841 def __calculateVelUVW(self, A, velRadial):
1840 def __calculateVelUVW(self, A, velRadial):
1842
1841
1843 #Operacion Matricial
1842 #Operacion Matricial
1844 # velUVW = numpy.zeros((velRadial.shape[1],3))
1843 # velUVW = numpy.zeros((velRadial.shape[1],3))
1845 # for ind in range(velRadial.shape[1]):
1844 # for ind in range(velRadial.shape[1]):
1846 # velUVW[ind,:] = numpy.dot(A,velRadial[:,ind])
1845 # velUVW[ind,:] = numpy.dot(A,velRadial[:,ind])
1847 # velUVW = velUVW.transpose()
1846 # velUVW = velUVW.transpose()
1848 velUVW = numpy.zeros((A.shape[0],velRadial.shape[1]))
1847 velUVW = numpy.zeros((A.shape[0],velRadial.shape[1]))
1849 velUVW[:,:] = numpy.dot(A,velRadial)
1848 velUVW[:,:] = numpy.dot(A,velRadial)
1850
1849
1851
1850
1852 return velUVW
1851 return velUVW
1853
1852
1854 # def techniqueDBS(self, velRadial0, dirCosx, disrCosy, azimuth, correct, horizontalOnly, heiRang, SNR0):
1853 # def techniqueDBS(self, velRadial0, dirCosx, disrCosy, azimuth, correct, horizontalOnly, heiRang, SNR0):
1855
1854
1856 def techniqueDBS(self, kwargs):
1855 def techniqueDBS(self, kwargs):
1857 """
1856 """
1858 Function that implements Doppler Beam Swinging (DBS) technique.
1857 Function that implements Doppler Beam Swinging (DBS) technique.
1859
1858
1860 Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth,
1859 Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth,
1861 Direction correction (if necessary), Ranges and SNR
1860 Direction correction (if necessary), Ranges and SNR
1862
1861
1863 Output: Winds estimation (Zonal, Meridional and Vertical)
1862 Output: Winds estimation (Zonal, Meridional and Vertical)
1864
1863
1865 Parameters affected: Winds, height range, SNR
1864 Parameters affected: Winds, height range, SNR
1866 """
1865 """
1867 velRadial0 = kwargs['velRadial']
1866 velRadial0 = kwargs['velRadial']
1868 heiRang = kwargs['heightList']
1867 heiRang = kwargs['heightList']
1869 SNR0 = kwargs['SNR']
1868 SNR0 = kwargs['SNR']
1870
1869
1871 if kwargs.has_key('dirCosx') and kwargs.has_key('dirCosy'):
1870 if kwargs.has_key('dirCosx') and kwargs.has_key('dirCosy'):
1872 theta_x = numpy.array(kwargs['dirCosx'])
1871 theta_x = numpy.array(kwargs['dirCosx'])
1873 theta_y = numpy.array(kwargs['dirCosy'])
1872 theta_y = numpy.array(kwargs['dirCosy'])
1874 else:
1873 else:
1875 elev = numpy.array(kwargs['elevation'])
1874 elev = numpy.array(kwargs['elevation'])
1876 azim = numpy.array(kwargs['azimuth'])
1875 azim = numpy.array(kwargs['azimuth'])
1877 theta_x, theta_y = self.__calculateCosDir(elev, azim)
1876 theta_x, theta_y = self.__calculateCosDir(elev, azim)
1878 azimuth = kwargs['correctAzimuth']
1877 azimuth = kwargs['correctAzimuth']
1879 if kwargs.has_key('horizontalOnly'):
1878 if kwargs.has_key('horizontalOnly'):
1880 horizontalOnly = kwargs['horizontalOnly']
1879 horizontalOnly = kwargs['horizontalOnly']
1881 else: horizontalOnly = False
1880 else: horizontalOnly = False
1882 if kwargs.has_key('correctFactor'):
1881 if kwargs.has_key('correctFactor'):
1883 correctFactor = kwargs['correctFactor']
1882 correctFactor = kwargs['correctFactor']
1884 else: correctFactor = 1
1883 else: correctFactor = 1
1885 if kwargs.has_key('channelList'):
1884 if kwargs.has_key('channelList'):
1886 channelList = kwargs['channelList']
1885 channelList = kwargs['channelList']
1887 if len(channelList) == 2:
1886 if len(channelList) == 2:
1888 horizontalOnly = True
1887 horizontalOnly = True
1889 arrayChannel = numpy.array(channelList)
1888 arrayChannel = numpy.array(channelList)
1890 param = param[arrayChannel,:,:]
1889 param = param[arrayChannel,:,:]
1891 theta_x = theta_x[arrayChannel]
1890 theta_x = theta_x[arrayChannel]
1892 theta_y = theta_y[arrayChannel]
1891 theta_y = theta_y[arrayChannel]
1893
1892
1894 azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw = self.__calculateAngles(theta_x, theta_y, azimuth)
1893 azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw = self.__calculateAngles(theta_x, theta_y, azimuth)
1895 heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, zenith_arr, correctFactor*velRadial0, SNR0)
1894 heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, zenith_arr, correctFactor*velRadial0, SNR0)
1896 A = self.__calculateMatA(dir_cosu, dir_cosv, dir_cosw, horizontalOnly)
1895 A = self.__calculateMatA(dir_cosu, dir_cosv, dir_cosw, horizontalOnly)
1897
1896
1898 #Calculo de Componentes de la velocidad con DBS
1897 #Calculo de Componentes de la velocidad con DBS
1899 winds = self.__calculateVelUVW(A,velRadial1)
1898 winds = self.__calculateVelUVW(A,velRadial1)
1900
1899
1901 return winds, heiRang1, SNR1
1900 return winds, heiRang1, SNR1
1902
1901
1903 def __calculateDistance(self, posx, posy, pairs_ccf, azimuth = None):
1902 def __calculateDistance(self, posx, posy, pairs_ccf, azimuth = None):
1904
1903
1905 nPairs = len(pairs_ccf)
1904 nPairs = len(pairs_ccf)
1906 posx = numpy.asarray(posx)
1905 posx = numpy.asarray(posx)
1907 posy = numpy.asarray(posy)
1906 posy = numpy.asarray(posy)
1908
1907
1909 #Rotacion Inversa para alinear con el azimuth
1908 #Rotacion Inversa para alinear con el azimuth
1910 if azimuth!= None:
1909 if azimuth!= None:
1911 azimuth = azimuth*math.pi/180
1910 azimuth = azimuth*math.pi/180
1912 posx1 = posx*math.cos(azimuth) + posy*math.sin(azimuth)
1911 posx1 = posx*math.cos(azimuth) + posy*math.sin(azimuth)
1913 posy1 = -posx*math.sin(azimuth) + posy*math.cos(azimuth)
1912 posy1 = -posx*math.sin(azimuth) + posy*math.cos(azimuth)
1914 else:
1913 else:
1915 posx1 = posx
1914 posx1 = posx
1916 posy1 = posy
1915 posy1 = posy
1917
1916
1918 #Calculo de Distancias
1917 #Calculo de Distancias
1919 distx = numpy.zeros(nPairs)
1918 distx = numpy.zeros(nPairs)
1920 disty = numpy.zeros(nPairs)
1919 disty = numpy.zeros(nPairs)
1921 dist = numpy.zeros(nPairs)
1920 dist = numpy.zeros(nPairs)
1922 ang = numpy.zeros(nPairs)
1921 ang = numpy.zeros(nPairs)
1923
1922
1924 for i in range(nPairs):
1923 for i in range(nPairs):
1925 distx[i] = posx1[pairs_ccf[i][1]] - posx1[pairs_ccf[i][0]]
1924 distx[i] = posx1[pairs_ccf[i][1]] - posx1[pairs_ccf[i][0]]
1926 disty[i] = posy1[pairs_ccf[i][1]] - posy1[pairs_ccf[i][0]]
1925 disty[i] = posy1[pairs_ccf[i][1]] - posy1[pairs_ccf[i][0]]
1927 dist[i] = numpy.sqrt(distx[i]**2 + disty[i]**2)
1926 dist[i] = numpy.sqrt(distx[i]**2 + disty[i]**2)
1928 ang[i] = numpy.arctan2(disty[i],distx[i])
1927 ang[i] = numpy.arctan2(disty[i],distx[i])
1929
1928
1930 return distx, disty, dist, ang
1929 return distx, disty, dist, ang
1931 #Calculo de Matrices
1930 #Calculo de Matrices
1932 # nPairs = len(pairs)
1931 # nPairs = len(pairs)
1933 # ang1 = numpy.zeros((nPairs, 2, 1))
1932 # ang1 = numpy.zeros((nPairs, 2, 1))
1934 # dist1 = numpy.zeros((nPairs, 2, 1))
1933 # dist1 = numpy.zeros((nPairs, 2, 1))
1935 #
1934 #
1936 # for j in range(nPairs):
1935 # for j in range(nPairs):
1937 # dist1[j,0,0] = dist[pairs[j][0]]
1936 # dist1[j,0,0] = dist[pairs[j][0]]
1938 # dist1[j,1,0] = dist[pairs[j][1]]
1937 # dist1[j,1,0] = dist[pairs[j][1]]
1939 # ang1[j,0,0] = ang[pairs[j][0]]
1938 # ang1[j,0,0] = ang[pairs[j][0]]
1940 # ang1[j,1,0] = ang[pairs[j][1]]
1939 # ang1[j,1,0] = ang[pairs[j][1]]
1941 #
1940 #
1942 # return distx,disty, dist1,ang1
1941 # return distx,disty, dist1,ang1
1943
1942
1944
1943
1945 def __calculateVelVer(self, phase, lagTRange, _lambda):
1944 def __calculateVelVer(self, phase, lagTRange, _lambda):
1946
1945
1947 Ts = lagTRange[1] - lagTRange[0]
1946 Ts = lagTRange[1] - lagTRange[0]
1948 velW = -_lambda*phase/(4*math.pi*Ts)
1947 velW = -_lambda*phase/(4*math.pi*Ts)
1949
1948
1950 return velW
1949 return velW
1951
1950
1952 def __calculateVelHorDir(self, dist, tau1, tau2, ang):
1951 def __calculateVelHorDir(self, dist, tau1, tau2, ang):
1953 nPairs = tau1.shape[0]
1952 nPairs = tau1.shape[0]
1954 nHeights = tau1.shape[1]
1953 nHeights = tau1.shape[1]
1955 vel = numpy.zeros((nPairs,3,nHeights))
1954 vel = numpy.zeros((nPairs,3,nHeights))
1956 dist1 = numpy.reshape(dist, (dist.size,1))
1955 dist1 = numpy.reshape(dist, (dist.size,1))
1957
1956
1958 angCos = numpy.cos(ang)
1957 angCos = numpy.cos(ang)
1959 angSin = numpy.sin(ang)
1958 angSin = numpy.sin(ang)
1960
1959
1961 vel0 = dist1*tau1/(2*tau2**2)
1960 vel0 = dist1*tau1/(2*tau2**2)
1962 vel[:,0,:] = (vel0*angCos).sum(axis = 1)
1961 vel[:,0,:] = (vel0*angCos).sum(axis = 1)
1963 vel[:,1,:] = (vel0*angSin).sum(axis = 1)
1962 vel[:,1,:] = (vel0*angSin).sum(axis = 1)
1964
1963
1965 ind = numpy.where(numpy.isinf(vel))
1964 ind = numpy.where(numpy.isinf(vel))
1966 vel[ind] = numpy.nan
1965 vel[ind] = numpy.nan
1967
1966
1968 return vel
1967 return vel
1969
1968
1970 # def __getPairsAutoCorr(self, pairsList, nChannels):
1969 # def __getPairsAutoCorr(self, pairsList, nChannels):
1971 #
1970 #
1972 # pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan
1971 # pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan
1973 #
1972 #
1974 # for l in range(len(pairsList)):
1973 # for l in range(len(pairsList)):
1975 # firstChannel = pairsList[l][0]
1974 # firstChannel = pairsList[l][0]
1976 # secondChannel = pairsList[l][1]
1975 # secondChannel = pairsList[l][1]
1977 #
1976 #
1978 # #Obteniendo pares de Autocorrelacion
1977 # #Obteniendo pares de Autocorrelacion
1979 # if firstChannel == secondChannel:
1978 # if firstChannel == secondChannel:
1980 # pairsAutoCorr[firstChannel] = int(l)
1979 # pairsAutoCorr[firstChannel] = int(l)
1981 #
1980 #
1982 # pairsAutoCorr = pairsAutoCorr.astype(int)
1981 # pairsAutoCorr = pairsAutoCorr.astype(int)
1983 #
1982 #
1984 # pairsCrossCorr = range(len(pairsList))
1983 # pairsCrossCorr = range(len(pairsList))
1985 # pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr)
1984 # pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr)
1986 #
1985 #
1987 # return pairsAutoCorr, pairsCrossCorr
1986 # return pairsAutoCorr, pairsCrossCorr
1988
1987
1989 # def techniqueSA(self, pairsSelected, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, lagTRange, correctFactor):
1988 # def techniqueSA(self, pairsSelected, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, lagTRange, correctFactor):
1990 def techniqueSA(self, kwargs):
1989 def techniqueSA(self, kwargs):
1991
1990
1992 """
1991 """
1993 Function that implements Spaced Antenna (SA) technique.
1992 Function that implements Spaced Antenna (SA) technique.
1994
1993
1995 Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth,
1994 Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth,
1996 Direction correction (if necessary), Ranges and SNR
1995 Direction correction (if necessary), Ranges and SNR
1997
1996
1998 Output: Winds estimation (Zonal, Meridional and Vertical)
1997 Output: Winds estimation (Zonal, Meridional and Vertical)
1999
1998
2000 Parameters affected: Winds
1999 Parameters affected: Winds
2001 """
2000 """
2002 position_x = kwargs['positionX']
2001 position_x = kwargs['positionX']
2003 position_y = kwargs['positionY']
2002 position_y = kwargs['positionY']
2004 azimuth = kwargs['azimuth']
2003 azimuth = kwargs['azimuth']
2005
2004
2006 if kwargs.has_key('correctFactor'):
2005 if kwargs.has_key('correctFactor'):
2007 correctFactor = kwargs['correctFactor']
2006 correctFactor = kwargs['correctFactor']
2008 else:
2007 else:
2009 correctFactor = 1
2008 correctFactor = 1
2010
2009
2011 groupList = kwargs['groupList']
2010 groupList = kwargs['groupList']
2012 pairs_ccf = groupList[1]
2011 pairs_ccf = groupList[1]
2013 tau = kwargs['tau']
2012 tau = kwargs['tau']
2014 _lambda = kwargs['_lambda']
2013 _lambda = kwargs['_lambda']
2015
2014
2016 #Cross Correlation pairs obtained
2015 #Cross Correlation pairs obtained
2017 # pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairssList, nChannels)
2016 # pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairssList, nChannels)
2018 # pairsArray = numpy.array(pairsList)[pairsCrossCorr]
2017 # pairsArray = numpy.array(pairsList)[pairsCrossCorr]
2019 # pairsSelArray = numpy.array(pairsSelected)
2018 # pairsSelArray = numpy.array(pairsSelected)
2020 # pairs = []
2019 # pairs = []
2021 #
2020 #
2022 # #Wind estimation pairs obtained
2021 # #Wind estimation pairs obtained
2023 # for i in range(pairsSelArray.shape[0]/2):
2022 # for i in range(pairsSelArray.shape[0]/2):
2024 # ind1 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i], axis = 1))[0][0]
2023 # ind1 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i], axis = 1))[0][0]
2025 # ind2 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i + 1], axis = 1))[0][0]
2024 # ind2 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i + 1], axis = 1))[0][0]
2026 # pairs.append((ind1,ind2))
2025 # pairs.append((ind1,ind2))
2027
2026
2028 indtau = tau.shape[0]/2
2027 indtau = tau.shape[0]/2
2029 tau1 = tau[:indtau,:]
2028 tau1 = tau[:indtau,:]
2030 tau2 = tau[indtau:-1,:]
2029 tau2 = tau[indtau:-1,:]
2031 # tau1 = tau1[pairs,:]
2030 # tau1 = tau1[pairs,:]
2032 # tau2 = tau2[pairs,:]
2031 # tau2 = tau2[pairs,:]
2033 phase1 = tau[-1,:]
2032 phase1 = tau[-1,:]
2034
2033
2035 #---------------------------------------------------------------------
2034 #---------------------------------------------------------------------
2036 #Metodo Directo
2035 #Metodo Directo
2037 distx, disty, dist, ang = self.__calculateDistance(position_x, position_y, pairs_ccf,azimuth)
2036 distx, disty, dist, ang = self.__calculateDistance(position_x, position_y, pairs_ccf,azimuth)
2038 winds = self.__calculateVelHorDir(dist, tau1, tau2, ang)
2037 winds = self.__calculateVelHorDir(dist, tau1, tau2, ang)
2039 winds = stats.nanmean(winds, axis=0)
2038 winds = stats.nanmean(winds, axis=0)
2040 #---------------------------------------------------------------------
2039 #---------------------------------------------------------------------
2041 #Metodo General
2040 #Metodo General
2042 # distx, disty, dist = self.calculateDistance(position_x,position_y,pairsCrossCorr, pairsList, azimuth)
2041 # distx, disty, dist = self.calculateDistance(position_x,position_y,pairsCrossCorr, pairsList, azimuth)
2043 # #Calculo Coeficientes de Funcion de Correlacion
2042 # #Calculo Coeficientes de Funcion de Correlacion
2044 # F,G,A,B,H = self.calculateCoef(tau1,tau2,distx,disty,n)
2043 # F,G,A,B,H = self.calculateCoef(tau1,tau2,distx,disty,n)
2045 # #Calculo de Velocidades
2044 # #Calculo de Velocidades
2046 # winds = self.calculateVelUV(F,G,A,B,H)
2045 # winds = self.calculateVelUV(F,G,A,B,H)
2047
2046
2048 #---------------------------------------------------------------------
2047 #---------------------------------------------------------------------
2049 winds[2,:] = self.__calculateVelVer(phase1, lagTRange, _lambda)
2048 winds[2,:] = self.__calculateVelVer(phase1, lagTRange, _lambda)
2050 winds = correctFactor*winds
2049 winds = correctFactor*winds
2051 return winds
2050 return winds
2052
2051
2053 def __checkTime(self, currentTime, paramInterval, outputInterval):
2052 def __checkTime(self, currentTime, paramInterval, outputInterval):
2054
2053
2055 dataTime = currentTime + paramInterval
2054 dataTime = currentTime + paramInterval
2056 deltaTime = dataTime - self.__initime
2055 deltaTime = dataTime - self.__initime
2057
2056
2058 if deltaTime >= outputInterval or deltaTime < 0:
2057 if deltaTime >= outputInterval or deltaTime < 0:
2059 self.__dataReady = True
2058 self.__dataReady = True
2060 return
2059 return
2061
2060
2062 def techniqueMeteors(self, arrayMeteor, meteorThresh, heightMin, heightMax):
2061 def techniqueMeteors(self, arrayMeteor, meteorThresh, heightMin, heightMax):
2063 '''
2062 '''
2064 Function that implements winds estimation technique with detected meteors.
2063 Function that implements winds estimation technique with detected meteors.
2065
2064
2066 Input: Detected meteors, Minimum meteor quantity to wind estimation
2065 Input: Detected meteors, Minimum meteor quantity to wind estimation
2067
2066
2068 Output: Winds estimation (Zonal and Meridional)
2067 Output: Winds estimation (Zonal and Meridional)
2069
2068
2070 Parameters affected: Winds
2069 Parameters affected: Winds
2071 '''
2070 '''
2072 # print arrayMeteor.shape
2071 # print arrayMeteor.shape
2073 #Settings
2072 #Settings
2074 nInt = (heightMax - heightMin)/2
2073 nInt = (heightMax - heightMin)/2
2075 # print nInt
2074 # print nInt
2076 nInt = int(nInt)
2075 nInt = int(nInt)
2077 # print nInt
2076 # print nInt
2078 winds = numpy.zeros((2,nInt))*numpy.nan
2077 winds = numpy.zeros((2,nInt))*numpy.nan
2079
2078
2080 #Filter errors
2079 #Filter errors
2081 error = numpy.where(arrayMeteor[:,-1] == 0)[0]
2080 error = numpy.where(arrayMeteor[:,-1] == 0)[0]
2082 finalMeteor = arrayMeteor[error,:]
2081 finalMeteor = arrayMeteor[error,:]
2083
2082
2084 #Meteor Histogram
2083 #Meteor Histogram
2085 finalHeights = finalMeteor[:,2]
2084 finalHeights = finalMeteor[:,2]
2086 hist = numpy.histogram(finalHeights, bins = nInt, range = (heightMin,heightMax))
2085 hist = numpy.histogram(finalHeights, bins = nInt, range = (heightMin,heightMax))
2087 nMeteorsPerI = hist[0]
2086 nMeteorsPerI = hist[0]
2088 heightPerI = hist[1]
2087 heightPerI = hist[1]
2089
2088
2090 #Sort of meteors
2089 #Sort of meteors
2091 indSort = finalHeights.argsort()
2090 indSort = finalHeights.argsort()
2092 finalMeteor2 = finalMeteor[indSort,:]
2091 finalMeteor2 = finalMeteor[indSort,:]
2093
2092
2094 # Calculating winds
2093 # Calculating winds
2095 ind1 = 0
2094 ind1 = 0
2096 ind2 = 0
2095 ind2 = 0
2097
2096
2098 for i in range(nInt):
2097 for i in range(nInt):
2099 nMet = nMeteorsPerI[i]
2098 nMet = nMeteorsPerI[i]
2100 ind1 = ind2
2099 ind1 = ind2
2101 ind2 = ind1 + nMet
2100 ind2 = ind1 + nMet
2102
2101
2103 meteorAux = finalMeteor2[ind1:ind2,:]
2102 meteorAux = finalMeteor2[ind1:ind2,:]
2104
2103
2105 if meteorAux.shape[0] >= meteorThresh:
2104 if meteorAux.shape[0] >= meteorThresh:
2106 vel = meteorAux[:, 6]
2105 vel = meteorAux[:, 6]
2107 zen = meteorAux[:, 4]*numpy.pi/180
2106 zen = meteorAux[:, 4]*numpy.pi/180
2108 azim = meteorAux[:, 3]*numpy.pi/180
2107 azim = meteorAux[:, 3]*numpy.pi/180
2109
2108
2110 n = numpy.cos(zen)
2109 n = numpy.cos(zen)
2111 # m = (1 - n**2)/(1 - numpy.tan(azim)**2)
2110 # m = (1 - n**2)/(1 - numpy.tan(azim)**2)
2112 # l = m*numpy.tan(azim)
2111 # l = m*numpy.tan(azim)
2113 l = numpy.sin(zen)*numpy.sin(azim)
2112 l = numpy.sin(zen)*numpy.sin(azim)
2114 m = numpy.sin(zen)*numpy.cos(azim)
2113 m = numpy.sin(zen)*numpy.cos(azim)
2115
2114
2116 A = numpy.vstack((l, m)).transpose()
2115 A = numpy.vstack((l, m)).transpose()
2117 A1 = numpy.dot(numpy.linalg.inv( numpy.dot(A.transpose(),A) ),A.transpose())
2116 A1 = numpy.dot(numpy.linalg.inv( numpy.dot(A.transpose(),A) ),A.transpose())
2118 windsAux = numpy.dot(A1, vel)
2117 windsAux = numpy.dot(A1, vel)
2119
2118
2120 winds[0,i] = windsAux[0]
2119 winds[0,i] = windsAux[0]
2121 winds[1,i] = windsAux[1]
2120 winds[1,i] = windsAux[1]
2122
2121
2123 return winds, heightPerI[:-1]
2122 return winds, heightPerI[:-1]
2124
2123
2125 def techniqueNSM_SA(self, **kwargs):
2124 def techniqueNSM_SA(self, **kwargs):
2126 metArray = kwargs['metArray']
2125 metArray = kwargs['metArray']
2127 heightList = kwargs['heightList']
2126 heightList = kwargs['heightList']
2128 timeList = kwargs['timeList']
2127 timeList = kwargs['timeList']
2129
2128
2130 rx_location = kwargs['rx_location']
2129 rx_location = kwargs['rx_location']
2131 groupList = kwargs['groupList']
2130 groupList = kwargs['groupList']
2132 azimuth = kwargs['azimuth']
2131 azimuth = kwargs['azimuth']
2133 dfactor = kwargs['dfactor']
2132 dfactor = kwargs['dfactor']
2134 k = kwargs['k']
2133 k = kwargs['k']
2135
2134
2136 azimuth1, dist = self.__calculateAzimuth1(rx_location, groupList, azimuth)
2135 azimuth1, dist = self.__calculateAzimuth1(rx_location, groupList, azimuth)
2137 d = dist*dfactor
2136 d = dist*dfactor
2138 #Phase calculation
2137 #Phase calculation
2139 metArray1 = self.__getPhaseSlope(metArray, heightList, timeList)
2138 metArray1 = self.__getPhaseSlope(metArray, heightList, timeList)
2140
2139
2141 metArray1[:,-2] = metArray1[:,-2]*metArray1[:,2]*1000/(k*d[metArray1[:,1].astype(int)]) #angles into velocities
2140 metArray1[:,-2] = metArray1[:,-2]*metArray1[:,2]*1000/(k*d[metArray1[:,1].astype(int)]) #angles into velocities
2142
2141
2143 velEst = numpy.zeros((heightList.size,2))*numpy.nan
2142 velEst = numpy.zeros((heightList.size,2))*numpy.nan
2144 azimuth1 = azimuth1*numpy.pi/180
2143 azimuth1 = azimuth1*numpy.pi/180
2145
2144
2146 for i in range(heightList.size):
2145 for i in range(heightList.size):
2147 h = heightList[i]
2146 h = heightList[i]
2148 indH = numpy.where((metArray1[:,2] == h)&(numpy.abs(metArray1[:,-2]) < 100))[0]
2147 indH = numpy.where((metArray1[:,2] == h)&(numpy.abs(metArray1[:,-2]) < 100))[0]
2149 metHeight = metArray1[indH,:]
2148 metHeight = metArray1[indH,:]
2150 if metHeight.shape[0] >= 2:
2149 if metHeight.shape[0] >= 2:
2151 velAux = numpy.asmatrix(metHeight[:,-2]).T #Radial Velocities
2150 velAux = numpy.asmatrix(metHeight[:,-2]).T #Radial Velocities
2152 iazim = metHeight[:,1].astype(int)
2151 iazim = metHeight[:,1].astype(int)
2153 azimAux = numpy.asmatrix(azimuth1[iazim]).T #Azimuths
2152 azimAux = numpy.asmatrix(azimuth1[iazim]).T #Azimuths
2154 A = numpy.hstack((numpy.cos(azimAux),numpy.sin(azimAux)))
2153 A = numpy.hstack((numpy.cos(azimAux),numpy.sin(azimAux)))
2155 A = numpy.asmatrix(A)
2154 A = numpy.asmatrix(A)
2156 A1 = numpy.linalg.pinv(A.transpose()*A)*A.transpose()
2155 A1 = numpy.linalg.pinv(A.transpose()*A)*A.transpose()
2157 velHor = numpy.dot(A1,velAux)
2156 velHor = numpy.dot(A1,velAux)
2158
2157
2159 velEst[i,:] = numpy.squeeze(velHor)
2158 velEst[i,:] = numpy.squeeze(velHor)
2160 return velEst
2159 return velEst
2161
2160
2162 def __getPhaseSlope(self, metArray, heightList, timeList):
2161 def __getPhaseSlope(self, metArray, heightList, timeList):
2163 meteorList = []
2162 meteorList = []
2164 #utctime sec1 height SNR velRad ph0 ph1 ph2 coh0 coh1 coh2
2163 #utctime sec1 height SNR velRad ph0 ph1 ph2 coh0 coh1 coh2
2165 #Putting back together the meteor matrix
2164 #Putting back together the meteor matrix
2166 utctime = metArray[:,0]
2165 utctime = metArray[:,0]
2167 uniqueTime = numpy.unique(utctime)
2166 uniqueTime = numpy.unique(utctime)
2168
2167
2169 phaseDerThresh = 0.5
2168 phaseDerThresh = 0.5
2170 ippSeconds = timeList[1] - timeList[0]
2169 ippSeconds = timeList[1] - timeList[0]
2171 sec = numpy.where(timeList>1)[0][0]
2170 sec = numpy.where(timeList>1)[0][0]
2172 nPairs = metArray.shape[1] - 6
2171 nPairs = metArray.shape[1] - 6
2173 nHeights = len(heightList)
2172 nHeights = len(heightList)
2174
2173
2175 for t in uniqueTime:
2174 for t in uniqueTime:
2176 metArray1 = metArray[utctime==t,:]
2175 metArray1 = metArray[utctime==t,:]
2177 # phaseDerThresh = numpy.pi/4 #reducir Phase thresh
2176 # phaseDerThresh = numpy.pi/4 #reducir Phase thresh
2178 tmet = metArray1[:,1].astype(int)
2177 tmet = metArray1[:,1].astype(int)
2179 hmet = metArray1[:,2].astype(int)
2178 hmet = metArray1[:,2].astype(int)
2180
2179
2181 metPhase = numpy.zeros((nPairs, heightList.size, timeList.size - 1))
2180 metPhase = numpy.zeros((nPairs, heightList.size, timeList.size - 1))
2182 metPhase[:,:] = numpy.nan
2181 metPhase[:,:] = numpy.nan
2183 metPhase[:,hmet,tmet] = metArray1[:,6:].T
2182 metPhase[:,hmet,tmet] = metArray1[:,6:].T
2184
2183
2185 #Delete short trails
2184 #Delete short trails
2186 metBool = ~numpy.isnan(metPhase[0,:,:])
2185 metBool = ~numpy.isnan(metPhase[0,:,:])
2187 heightVect = numpy.sum(metBool, axis = 1)
2186 heightVect = numpy.sum(metBool, axis = 1)
2188 metBool[heightVect<sec,:] = False
2187 metBool[heightVect<sec,:] = False
2189 metPhase[:,heightVect<sec,:] = numpy.nan
2188 metPhase[:,heightVect<sec,:] = numpy.nan
2190
2189
2191 #Derivative
2190 #Derivative
2192 metDer = numpy.abs(metPhase[:,:,1:] - metPhase[:,:,:-1])
2191 metDer = numpy.abs(metPhase[:,:,1:] - metPhase[:,:,:-1])
2193 phDerAux = numpy.dstack((numpy.full((nPairs,nHeights,1), False, dtype=bool),metDer > phaseDerThresh))
2192 phDerAux = numpy.dstack((numpy.full((nPairs,nHeights,1), False, dtype=bool),metDer > phaseDerThresh))
2194 metPhase[phDerAux] = numpy.nan
2193 metPhase[phDerAux] = numpy.nan
2195
2194
2196 #--------------------------METEOR DETECTION -----------------------------------------
2195 #--------------------------METEOR DETECTION -----------------------------------------
2197 indMet = numpy.where(numpy.any(metBool,axis=1))[0]
2196 indMet = numpy.where(numpy.any(metBool,axis=1))[0]
2198
2197
2199 for p in numpy.arange(nPairs):
2198 for p in numpy.arange(nPairs):
2200 phase = metPhase[p,:,:]
2199 phase = metPhase[p,:,:]
2201 phDer = metDer[p,:,:]
2200 phDer = metDer[p,:,:]
2202
2201
2203 for h in indMet:
2202 for h in indMet:
2204 height = heightList[h]
2203 height = heightList[h]
2205 phase1 = phase[h,:] #82
2204 phase1 = phase[h,:] #82
2206 phDer1 = phDer[h,:]
2205 phDer1 = phDer[h,:]
2207
2206
2208 phase1[~numpy.isnan(phase1)] = numpy.unwrap(phase1[~numpy.isnan(phase1)]) #Unwrap
2207 phase1[~numpy.isnan(phase1)] = numpy.unwrap(phase1[~numpy.isnan(phase1)]) #Unwrap
2209
2208
2210 indValid = numpy.where(~numpy.isnan(phase1))[0]
2209 indValid = numpy.where(~numpy.isnan(phase1))[0]
2211 initMet = indValid[0]
2210 initMet = indValid[0]
2212 endMet = 0
2211 endMet = 0
2213
2212
2214 for i in range(len(indValid)-1):
2213 for i in range(len(indValid)-1):
2215
2214
2216 #Time difference
2215 #Time difference
2217 inow = indValid[i]
2216 inow = indValid[i]
2218 inext = indValid[i+1]
2217 inext = indValid[i+1]
2219 idiff = inext - inow
2218 idiff = inext - inow
2220 #Phase difference
2219 #Phase difference
2221 phDiff = numpy.abs(phase1[inext] - phase1[inow])
2220 phDiff = numpy.abs(phase1[inext] - phase1[inow])
2222
2221
2223 if idiff>sec or phDiff>numpy.pi/4 or inext==indValid[-1]: #End of Meteor
2222 if idiff>sec or phDiff>numpy.pi/4 or inext==indValid[-1]: #End of Meteor
2224 sizeTrail = inow - initMet + 1
2223 sizeTrail = inow - initMet + 1
2225 if sizeTrail>3*sec: #Too short meteors
2224 if sizeTrail>3*sec: #Too short meteors
2226 x = numpy.arange(initMet,inow+1)*ippSeconds
2225 x = numpy.arange(initMet,inow+1)*ippSeconds
2227 y = phase1[initMet:inow+1]
2226 y = phase1[initMet:inow+1]
2228 ynnan = ~numpy.isnan(y)
2227 ynnan = ~numpy.isnan(y)
2229 x = x[ynnan]
2228 x = x[ynnan]
2230 y = y[ynnan]
2229 y = y[ynnan]
2231 slope, intercept, r_value, p_value, std_err = stats.linregress(x,y)
2230 slope, intercept, r_value, p_value, std_err = stats.linregress(x,y)
2232 ylin = x*slope + intercept
2231 ylin = x*slope + intercept
2233 rsq = r_value**2
2232 rsq = r_value**2
2234 if rsq > 0.5:
2233 if rsq > 0.5:
2235 vel = slope#*height*1000/(k*d)
2234 vel = slope#*height*1000/(k*d)
2236 estAux = numpy.array([utctime,p,height, vel, rsq])
2235 estAux = numpy.array([utctime,p,height, vel, rsq])
2237 meteorList.append(estAux)
2236 meteorList.append(estAux)
2238 initMet = inext
2237 initMet = inext
2239 metArray2 = numpy.array(meteorList)
2238 metArray2 = numpy.array(meteorList)
2240
2239
2241 return metArray2
2240 return metArray2
2242
2241
2243 def __calculateAzimuth1(self, rx_location, pairslist, azimuth0):
2242 def __calculateAzimuth1(self, rx_location, pairslist, azimuth0):
2244
2243
2245 azimuth1 = numpy.zeros(len(pairslist))
2244 azimuth1 = numpy.zeros(len(pairslist))
2246 dist = numpy.zeros(len(pairslist))
2245 dist = numpy.zeros(len(pairslist))
2247
2246
2248 for i in range(len(rx_location)):
2247 for i in range(len(rx_location)):
2249 ch0 = pairslist[i][0]
2248 ch0 = pairslist[i][0]
2250 ch1 = pairslist[i][1]
2249 ch1 = pairslist[i][1]
2251
2250
2252 diffX = rx_location[ch0][0] - rx_location[ch1][0]
2251 diffX = rx_location[ch0][0] - rx_location[ch1][0]
2253 diffY = rx_location[ch0][1] - rx_location[ch1][1]
2252 diffY = rx_location[ch0][1] - rx_location[ch1][1]
2254 azimuth1[i] = numpy.arctan2(diffY,diffX)*180/numpy.pi
2253 azimuth1[i] = numpy.arctan2(diffY,diffX)*180/numpy.pi
2255 dist[i] = numpy.sqrt(diffX**2 + diffY**2)
2254 dist[i] = numpy.sqrt(diffX**2 + diffY**2)
2256
2255
2257 azimuth1 -= azimuth0
2256 azimuth1 -= azimuth0
2258 return azimuth1, dist
2257 return azimuth1, dist
2259
2258
2260 def techniqueNSM_DBS(self, **kwargs):
2259 def techniqueNSM_DBS(self, **kwargs):
2261 metArray = kwargs['metArray']
2260 metArray = kwargs['metArray']
2262 heightList = kwargs['heightList']
2261 heightList = kwargs['heightList']
2263 timeList = kwargs['timeList']
2262 timeList = kwargs['timeList']
2264 azimuth = kwargs['azimuth']
2263 azimuth = kwargs['azimuth']
2265 theta_x = numpy.array(kwargs['theta_x'])
2264 theta_x = numpy.array(kwargs['theta_x'])
2266 theta_y = numpy.array(kwargs['theta_y'])
2265 theta_y = numpy.array(kwargs['theta_y'])
2267
2266
2268 utctime = metArray[:,0]
2267 utctime = metArray[:,0]
2269 cmet = metArray[:,1].astype(int)
2268 cmet = metArray[:,1].astype(int)
2270 hmet = metArray[:,3].astype(int)
2269 hmet = metArray[:,3].astype(int)
2271 SNRmet = metArray[:,4]
2270 SNRmet = metArray[:,4]
2272 vmet = metArray[:,5]
2271 vmet = metArray[:,5]
2273 spcmet = metArray[:,6]
2272 spcmet = metArray[:,6]
2274
2273
2275 nChan = numpy.max(cmet) + 1
2274 nChan = numpy.max(cmet) + 1
2276 nHeights = len(heightList)
2275 nHeights = len(heightList)
2277
2276
2278 azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw = self.__calculateAngles(theta_x, theta_y, azimuth)
2277 azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw = self.__calculateAngles(theta_x, theta_y, azimuth)
2279 hmet = heightList[hmet]
2278 hmet = heightList[hmet]
2280 h1met = hmet*numpy.cos(zenith_arr[cmet]) #Corrected heights
2279 h1met = hmet*numpy.cos(zenith_arr[cmet]) #Corrected heights
2281
2280
2282 velEst = numpy.zeros((heightList.size,2))*numpy.nan
2281 velEst = numpy.zeros((heightList.size,2))*numpy.nan
2283
2282
2284 for i in range(nHeights - 1):
2283 for i in range(nHeights - 1):
2285 hmin = heightList[i]
2284 hmin = heightList[i]
2286 hmax = heightList[i + 1]
2285 hmax = heightList[i + 1]
2287
2286
2288 thisH = (h1met>=hmin) & (h1met<hmax) & (cmet!=2) & (SNRmet>8) & (vmet<50) & (spcmet<10)
2287 thisH = (h1met>=hmin) & (h1met<hmax) & (cmet!=2) & (SNRmet>8) & (vmet<50) & (spcmet<10)
2289 indthisH = numpy.where(thisH)
2288 indthisH = numpy.where(thisH)
2290
2289
2291 if numpy.size(indthisH) > 3:
2290 if numpy.size(indthisH) > 3:
2292
2291
2293 vel_aux = vmet[thisH]
2292 vel_aux = vmet[thisH]
2294 chan_aux = cmet[thisH]
2293 chan_aux = cmet[thisH]
2295 cosu_aux = dir_cosu[chan_aux]
2294 cosu_aux = dir_cosu[chan_aux]
2296 cosv_aux = dir_cosv[chan_aux]
2295 cosv_aux = dir_cosv[chan_aux]
2297 cosw_aux = dir_cosw[chan_aux]
2296 cosw_aux = dir_cosw[chan_aux]
2298
2297
2299 nch = numpy.size(numpy.unique(chan_aux))
2298 nch = numpy.size(numpy.unique(chan_aux))
2300 if nch > 1:
2299 if nch > 1:
2301 A = self.__calculateMatA(cosu_aux, cosv_aux, cosw_aux, True)
2300 A = self.__calculateMatA(cosu_aux, cosv_aux, cosw_aux, True)
2302 velEst[i,:] = numpy.dot(A,vel_aux)
2301 velEst[i,:] = numpy.dot(A,vel_aux)
2303
2302
2304 return velEst
2303 return velEst
2305
2304
2306 def run(self, dataOut, technique, nHours=1, hmin=70, hmax=110, **kwargs):
2305 def run(self, dataOut, technique, nHours=1, hmin=70, hmax=110, **kwargs):
2307
2306
2308 param = dataOut.data_param
2307 param = dataOut.data_param
2309 if dataOut.abscissaList != None:
2308 if dataOut.abscissaList != None:
2310 absc = dataOut.abscissaList[:-1]
2309 absc = dataOut.abscissaList[:-1]
2311 # noise = dataOut.noise
2310 # noise = dataOut.noise
2312 heightList = dataOut.heightList
2311 heightList = dataOut.heightList
2313 SNR = dataOut.data_SNR
2312 SNR = dataOut.data_SNR
2314
2313
2315 if technique == 'DBS':
2314 if technique == 'DBS':
2316
2315
2317 kwargs['velRadial'] = param[:,1,:] #Radial velocity
2316 kwargs['velRadial'] = param[:,1,:] #Radial velocity
2318 kwargs['heightList'] = heightList
2317 kwargs['heightList'] = heightList
2319 kwargs['SNR'] = SNR
2318 kwargs['SNR'] = SNR
2320
2319
2321 dataOut.data_output, dataOut.heightList, dataOut.data_SNR = self.techniqueDBS(kwargs) #DBS Function
2320 dataOut.data_output, dataOut.heightList, dataOut.data_SNR = self.techniqueDBS(kwargs) #DBS Function
2322 dataOut.utctimeInit = dataOut.utctime
2321 dataOut.utctimeInit = dataOut.utctime
2323 dataOut.outputInterval = dataOut.paramInterval
2322 dataOut.outputInterval = dataOut.paramInterval
2324
2323
2325 elif technique == 'SA':
2324 elif technique == 'SA':
2326
2325
2327 #Parameters
2326 #Parameters
2328 # position_x = kwargs['positionX']
2327 # position_x = kwargs['positionX']
2329 # position_y = kwargs['positionY']
2328 # position_y = kwargs['positionY']
2330 # azimuth = kwargs['azimuth']
2329 # azimuth = kwargs['azimuth']
2331 #
2330 #
2332 # if kwargs.has_key('crosspairsList'):
2331 # if kwargs.has_key('crosspairsList'):
2333 # pairs = kwargs['crosspairsList']
2332 # pairs = kwargs['crosspairsList']
2334 # else:
2333 # else:
2335 # pairs = None
2334 # pairs = None
2336 #
2335 #
2337 # if kwargs.has_key('correctFactor'):
2336 # if kwargs.has_key('correctFactor'):
2338 # correctFactor = kwargs['correctFactor']
2337 # correctFactor = kwargs['correctFactor']
2339 # else:
2338 # else:
2340 # correctFactor = 1
2339 # correctFactor = 1
2341
2340
2342 # tau = dataOut.data_param
2341 # tau = dataOut.data_param
2343 # _lambda = dataOut.C/dataOut.frequency
2342 # _lambda = dataOut.C/dataOut.frequency
2344 # pairsList = dataOut.groupList
2343 # pairsList = dataOut.groupList
2345 # nChannels = dataOut.nChannels
2344 # nChannels = dataOut.nChannels
2346
2345
2347 kwargs['groupList'] = dataOut.groupList
2346 kwargs['groupList'] = dataOut.groupList
2348 kwargs['tau'] = dataOut.data_param
2347 kwargs['tau'] = dataOut.data_param
2349 kwargs['_lambda'] = dataOut.C/dataOut.frequency
2348 kwargs['_lambda'] = dataOut.C/dataOut.frequency
2350 # dataOut.data_output = self.techniqueSA(pairs, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, absc, correctFactor)
2349 # dataOut.data_output = self.techniqueSA(pairs, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, absc, correctFactor)
2351 dataOut.data_output = self.techniqueSA(kwargs)
2350 dataOut.data_output = self.techniqueSA(kwargs)
2352 dataOut.utctimeInit = dataOut.utctime
2351 dataOut.utctimeInit = dataOut.utctime
2353 dataOut.outputInterval = dataOut.timeInterval
2352 dataOut.outputInterval = dataOut.timeInterval
2354
2353
2355 elif technique == 'Meteors':
2354 elif technique == 'Meteors':
2356 dataOut.flagNoData = True
2355 dataOut.flagNoData = True
2357 self.__dataReady = False
2356 self.__dataReady = False
2358
2357
2359 if kwargs.has_key('nHours'):
2358 if kwargs.has_key('nHours'):
2360 nHours = kwargs['nHours']
2359 nHours = kwargs['nHours']
2361 else:
2360 else:
2362 nHours = 1
2361 nHours = 1
2363
2362
2364 if kwargs.has_key('meteorsPerBin'):
2363 if kwargs.has_key('meteorsPerBin'):
2365 meteorThresh = kwargs['meteorsPerBin']
2364 meteorThresh = kwargs['meteorsPerBin']
2366 else:
2365 else:
2367 meteorThresh = 6
2366 meteorThresh = 6
2368
2367
2369 if kwargs.has_key('hmin'):
2368 if kwargs.has_key('hmin'):
2370 hmin = kwargs['hmin']
2369 hmin = kwargs['hmin']
2371 else: hmin = 70
2370 else: hmin = 70
2372 if kwargs.has_key('hmax'):
2371 if kwargs.has_key('hmax'):
2373 hmax = kwargs['hmax']
2372 hmax = kwargs['hmax']
2374 else: hmax = 110
2373 else: hmax = 110
2375
2374
2376 dataOut.outputInterval = nHours*3600
2375 dataOut.outputInterval = nHours*3600
2377
2376
2378 if self.__isConfig == False:
2377 if self.__isConfig == False:
2379 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
2378 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
2380 #Get Initial LTC time
2379 #Get Initial LTC time
2381 self.__initime = datetime.datetime.utcfromtimestamp(dataOut.utctime)
2380 self.__initime = datetime.datetime.utcfromtimestamp(dataOut.utctime)
2382 self.__initime = (self.__initime.replace(minute = 0, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
2381 self.__initime = (self.__initime.replace(minute = 0, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
2383
2382
2384 self.__isConfig = True
2383 self.__isConfig = True
2385
2384
2386 if self.__buffer == None:
2385 if self.__buffer == None:
2387 self.__buffer = dataOut.data_param
2386 self.__buffer = dataOut.data_param
2388 self.__firstdata = copy.copy(dataOut)
2387 self.__firstdata = copy.copy(dataOut)
2389
2388
2390 else:
2389 else:
2391 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
2390 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
2392
2391
2393 self.__checkTime(dataOut.utctime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
2392 self.__checkTime(dataOut.utctime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
2394
2393
2395 if self.__dataReady:
2394 if self.__dataReady:
2396 dataOut.utctimeInit = self.__initime
2395 dataOut.utctimeInit = self.__initime
2397
2396
2398 self.__initime += dataOut.outputInterval #to erase time offset
2397 self.__initime += dataOut.outputInterval #to erase time offset
2399
2398
2400 dataOut.data_output, dataOut.heightList = self.techniqueMeteors(self.__buffer, meteorThresh, hmin, hmax)
2399 dataOut.data_output, dataOut.heightList = self.techniqueMeteors(self.__buffer, meteorThresh, hmin, hmax)
2401 dataOut.flagNoData = False
2400 dataOut.flagNoData = False
2402 self.__buffer = None
2401 self.__buffer = None
2403
2402
2404 elif technique == 'Meteors1':
2403 elif technique == 'Meteors1':
2405 dataOut.flagNoData = True
2404 dataOut.flagNoData = True
2406 self.__dataReady = False
2405 self.__dataReady = False
2407
2406
2408 if kwargs.has_key('nMins'):
2407 if kwargs.has_key('nMins'):
2409 nMins = kwargs['nMins']
2408 nMins = kwargs['nMins']
2410 else: nMins = 20
2409 else: nMins = 20
2411 if kwargs.has_key('rx_location'):
2410 if kwargs.has_key('rx_location'):
2412 rx_location = kwargs['rx_location']
2411 rx_location = kwargs['rx_location']
2413 else: rx_location = [(0,1),(1,1),(1,0)]
2412 else: rx_location = [(0,1),(1,1),(1,0)]
2414 if kwargs.has_key('azimuth'):
2413 if kwargs.has_key('azimuth'):
2415 azimuth = kwargs['azimuth']
2414 azimuth = kwargs['azimuth']
2416 else: azimuth = 51.06
2415 else: azimuth = 51.06
2417 if kwargs.has_key('dfactor'):
2416 if kwargs.has_key('dfactor'):
2418 dfactor = kwargs['dfactor']
2417 dfactor = kwargs['dfactor']
2419 if kwargs.has_key('mode'):
2418 if kwargs.has_key('mode'):
2420 mode = kwargs['mode']
2419 mode = kwargs['mode']
2421 if kwargs.has_key('theta_x'):
2420 if kwargs.has_key('theta_x'):
2422 theta_x = kwargs['theta_x']
2421 theta_x = kwargs['theta_x']
2423 if kwargs.has_key('theta_y'):
2422 if kwargs.has_key('theta_y'):
2424 theta_y = kwargs['theta_y']
2423 theta_y = kwargs['theta_y']
2425 else: mode = 'SA'
2424 else: mode = 'SA'
2426
2425
2427 #Borrar luego esto
2426 #Borrar luego esto
2428 if dataOut.groupList == None:
2427 if dataOut.groupList == None:
2429 dataOut.groupList = [(0,1),(0,2),(1,2)]
2428 dataOut.groupList = [(0,1),(0,2),(1,2)]
2430 groupList = dataOut.groupList
2429 groupList = dataOut.groupList
2431 C = 3e8
2430 C = 3e8
2432 freq = 50e6
2431 freq = 50e6
2433 lamb = C/freq
2432 lamb = C/freq
2434 k = 2*numpy.pi/lamb
2433 k = 2*numpy.pi/lamb
2435
2434
2436 timeList = dataOut.abscissaList
2435 timeList = dataOut.abscissaList
2437 heightList = dataOut.heightList
2436 heightList = dataOut.heightList
2438
2437
2439 if self.__isConfig == False:
2438 if self.__isConfig == False:
2440 dataOut.outputInterval = nMins*60
2439 dataOut.outputInterval = nMins*60
2441 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
2440 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
2442 #Get Initial LTC time
2441 #Get Initial LTC time
2443 initime = datetime.datetime.utcfromtimestamp(dataOut.utctime)
2442 initime = datetime.datetime.utcfromtimestamp(dataOut.utctime)
2444 minuteAux = initime.minute
2443 minuteAux = initime.minute
2445 minuteNew = int(numpy.floor(minuteAux/nMins)*nMins)
2444 minuteNew = int(numpy.floor(minuteAux/nMins)*nMins)
2446 self.__initime = (initime.replace(minute = minuteNew, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
2445 self.__initime = (initime.replace(minute = minuteNew, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
2447
2446
2448 self.__isConfig = True
2447 self.__isConfig = True
2449
2448
2450 if self.__buffer == None:
2449 if self.__buffer == None:
2451 self.__buffer = dataOut.data_param
2450 self.__buffer = dataOut.data_param
2452 self.__firstdata = copy.copy(dataOut)
2451 self.__firstdata = copy.copy(dataOut)
2453
2452
2454 else:
2453 else:
2455 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
2454 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
2456
2455
2457 self.__checkTime(dataOut.utctime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
2456 self.__checkTime(dataOut.utctime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
2458
2457
2459 if self.__dataReady:
2458 if self.__dataReady:
2460 dataOut.utctimeInit = self.__initime
2459 dataOut.utctimeInit = self.__initime
2461 self.__initime += dataOut.outputInterval #to erase time offset
2460 self.__initime += dataOut.outputInterval #to erase time offset
2462
2461
2463 metArray = self.__buffer
2462 metArray = self.__buffer
2464 if mode == 'SA':
2463 if mode == 'SA':
2465 dataOut.data_output = self.techniqueNSM_SA(rx_location=rx_location, groupList=groupList, azimuth=azimuth, dfactor=dfactor, k=k,metArray=metArray, heightList=heightList,timeList=timeList)
2464 dataOut.data_output = self.techniqueNSM_SA(rx_location=rx_location, groupList=groupList, azimuth=azimuth, dfactor=dfactor, k=k,metArray=metArray, heightList=heightList,timeList=timeList)
2466 elif mode == 'DBS':
2465 elif mode == 'DBS':
2467 dataOut.data_output = self.techniqueNSM_DBS(metArray=metArray,heightList=heightList,timeList=timeList, azimuth=azimuth, theta_x=theta_x, theta_y=theta_y)
2466 dataOut.data_output = self.techniqueNSM_DBS(metArray=metArray,heightList=heightList,timeList=timeList, azimuth=azimuth, theta_x=theta_x, theta_y=theta_y)
2468 dataOut.data_output = dataOut.data_output.T
2467 dataOut.data_output = dataOut.data_output.T
2469 dataOut.flagNoData = False
2468 dataOut.flagNoData = False
2470 self.__buffer = None
2469 self.__buffer = None
2471
2470
2472 return
2471 return
2473
2472
2474 class EWDriftsEstimation(Operation):
2473 class EWDriftsEstimation(Operation):
2475
2474
2476 def __init__(self):
2475 def __init__(self):
2477 Operation.__init__(self)
2476 Operation.__init__(self)
2478
2477
2479 def __correctValues(self, heiRang, phi, velRadial, SNR):
2478 def __correctValues(self, heiRang, phi, velRadial, SNR):
2480 listPhi = phi.tolist()
2479 listPhi = phi.tolist()
2481 maxid = listPhi.index(max(listPhi))
2480 maxid = listPhi.index(max(listPhi))
2482 minid = listPhi.index(min(listPhi))
2481 minid = listPhi.index(min(listPhi))
2483
2482
2484 rango = range(len(phi))
2483 rango = range(len(phi))
2485 # rango = numpy.delete(rango,maxid)
2484 # rango = numpy.delete(rango,maxid)
2486
2485
2487 heiRang1 = heiRang*math.cos(phi[maxid])
2486 heiRang1 = heiRang*math.cos(phi[maxid])
2488 heiRangAux = heiRang*math.cos(phi[minid])
2487 heiRangAux = heiRang*math.cos(phi[minid])
2489 indOut = (heiRang1 < heiRangAux[0]).nonzero()
2488 indOut = (heiRang1 < heiRangAux[0]).nonzero()
2490 heiRang1 = numpy.delete(heiRang1,indOut)
2489 heiRang1 = numpy.delete(heiRang1,indOut)
2491
2490
2492 velRadial1 = numpy.zeros([len(phi),len(heiRang1)])
2491 velRadial1 = numpy.zeros([len(phi),len(heiRang1)])
2493 SNR1 = numpy.zeros([len(phi),len(heiRang1)])
2492 SNR1 = numpy.zeros([len(phi),len(heiRang1)])
2494
2493
2495 for i in rango:
2494 for i in rango:
2496 x = heiRang*math.cos(phi[i])
2495 x = heiRang*math.cos(phi[i])
2497 y1 = velRadial[i,:]
2496 y1 = velRadial[i,:]
2498 f1 = interpolate.interp1d(x,y1,kind = 'cubic')
2497 f1 = interpolate.interp1d(x,y1,kind = 'cubic')
2499
2498
2500 x1 = heiRang1
2499 x1 = heiRang1
2501 y11 = f1(x1)
2500 y11 = f1(x1)
2502
2501
2503 y2 = SNR[i,:]
2502 y2 = SNR[i,:]
2504 f2 = interpolate.interp1d(x,y2,kind = 'cubic')
2503 f2 = interpolate.interp1d(x,y2,kind = 'cubic')
2505 y21 = f2(x1)
2504 y21 = f2(x1)
2506
2505
2507 velRadial1[i,:] = y11
2506 velRadial1[i,:] = y11
2508 SNR1[i,:] = y21
2507 SNR1[i,:] = y21
2509
2508
2510 return heiRang1, velRadial1, SNR1
2509 return heiRang1, velRadial1, SNR1
2511
2510
2512 def run(self, dataOut, zenith, zenithCorrection):
2511 def run(self, dataOut, zenith, zenithCorrection):
2513 heiRang = dataOut.heightList
2512 heiRang = dataOut.heightList
2514 velRadial = dataOut.data_param[:,3,:]
2513 velRadial = dataOut.data_param[:,3,:]
2515 SNR = dataOut.data_SNR
2514 SNR = dataOut.data_SNR
2516
2515
2517 zenith = numpy.array(zenith)
2516 zenith = numpy.array(zenith)
2518 zenith -= zenithCorrection
2517 zenith -= zenithCorrection
2519 zenith *= numpy.pi/180
2518 zenith *= numpy.pi/180
2520
2519
2521 heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, numpy.abs(zenith), velRadial, SNR)
2520 heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, numpy.abs(zenith), velRadial, SNR)
2522
2521
2523 alp = zenith[0]
2522 alp = zenith[0]
2524 bet = zenith[1]
2523 bet = zenith[1]
2525
2524
2526 w_w = velRadial1[0,:]
2525 w_w = velRadial1[0,:]
2527 w_e = velRadial1[1,:]
2526 w_e = velRadial1[1,:]
2528
2527
2529 w = (w_w*numpy.sin(bet) - w_e*numpy.sin(alp))/(numpy.cos(alp)*numpy.sin(bet) - numpy.cos(bet)*numpy.sin(alp))
2528 w = (w_w*numpy.sin(bet) - w_e*numpy.sin(alp))/(numpy.cos(alp)*numpy.sin(bet) - numpy.cos(bet)*numpy.sin(alp))
2530 u = (w_w*numpy.cos(bet) - w_e*numpy.cos(alp))/(numpy.sin(alp)*numpy.cos(bet) - numpy.sin(bet)*numpy.cos(alp))
2529 u = (w_w*numpy.cos(bet) - w_e*numpy.cos(alp))/(numpy.sin(alp)*numpy.cos(bet) - numpy.sin(bet)*numpy.cos(alp))
2531
2530
2532 winds = numpy.vstack((u,w))
2531 winds = numpy.vstack((u,w))
2533
2532
2534 dataOut.heightList = heiRang1
2533 dataOut.heightList = heiRang1
2535 dataOut.data_output = winds
2534 dataOut.data_output = winds
2536 dataOut.data_SNR = SNR1
2535 dataOut.data_SNR = SNR1
2537
2536
2538 dataOut.utctimeInit = dataOut.utctime
2537 dataOut.utctimeInit = dataOut.utctime
2539 dataOut.outputInterval = dataOut.timeInterval
2538 dataOut.outputInterval = dataOut.timeInterval
2540 return
2539 return
2541
2540
2542 #--------------- Non Specular Meteor ----------------
2541 #--------------- Non Specular Meteor ----------------
2543
2542
2544 class NonSpecularMeteorDetection(Operation):
2543 class NonSpecularMeteorDetection(Operation):
2545
2544
2546 def run(self, dataOut, mode, SNRthresh=8, phaseDerThresh=0.5, cohThresh=0.8, allData = False):
2545 def run(self, dataOut, mode, SNRthresh=8, phaseDerThresh=0.5, cohThresh=0.8, allData = False):
2547 data_acf = dataOut.data_pre[0]
2546 data_acf = dataOut.data_pre[0]
2548 data_ccf = dataOut.data_pre[1]
2547 data_ccf = dataOut.data_pre[1]
2549 pairsList = dataOut.groupList[1]
2548 pairsList = dataOut.groupList[1]
2550
2549
2551 lamb = dataOut.C/dataOut.frequency
2550 lamb = dataOut.C/dataOut.frequency
2552 tSamp = dataOut.ippSeconds*dataOut.nCohInt
2551 tSamp = dataOut.ippSeconds*dataOut.nCohInt
2553 paramInterval = dataOut.paramInterval
2552 paramInterval = dataOut.paramInterval
2554
2553
2555 nChannels = data_acf.shape[0]
2554 nChannels = data_acf.shape[0]
2556 nLags = data_acf.shape[1]
2555 nLags = data_acf.shape[1]
2557 nProfiles = data_acf.shape[2]
2556 nProfiles = data_acf.shape[2]
2558 nHeights = dataOut.nHeights
2557 nHeights = dataOut.nHeights
2559 nCohInt = dataOut.nCohInt
2558 nCohInt = dataOut.nCohInt
2560 sec = numpy.round(nProfiles/dataOut.paramInterval)
2559 sec = numpy.round(nProfiles/dataOut.paramInterval)
2561 heightList = dataOut.heightList
2560 heightList = dataOut.heightList
2562 ippSeconds = dataOut.ippSeconds*dataOut.nCohInt*dataOut.nAvg
2561 ippSeconds = dataOut.ippSeconds*dataOut.nCohInt*dataOut.nAvg
2563 utctime = dataOut.utctime
2562 utctime = dataOut.utctime
2564
2563
2565 dataOut.abscissaList = numpy.arange(0,paramInterval+ippSeconds,ippSeconds)
2564 dataOut.abscissaList = numpy.arange(0,paramInterval+ippSeconds,ippSeconds)
2566
2565
2567 #------------------------ SNR --------------------------------------
2566 #------------------------ SNR --------------------------------------
2568 power = data_acf[:,0,:,:].real
2567 power = data_acf[:,0,:,:].real
2569 noise = numpy.zeros(nChannels)
2568 noise = numpy.zeros(nChannels)
2570 SNR = numpy.zeros(power.shape)
2569 SNR = numpy.zeros(power.shape)
2571 for i in range(nChannels):
2570 for i in range(nChannels):
2572 noise[i] = hildebrand_sekhon(power[i,:], nCohInt)
2571 noise[i] = hildebrand_sekhon(power[i,:], nCohInt)
2573 SNR[i] = (power[i]-noise[i])/noise[i]
2572 SNR[i] = (power[i]-noise[i])/noise[i]
2574 SNRm = numpy.nanmean(SNR, axis = 0)
2573 SNRm = numpy.nanmean(SNR, axis = 0)
2575 SNRdB = 10*numpy.log10(SNR)
2574 SNRdB = 10*numpy.log10(SNR)
2576
2575
2577 if mode == 'SA':
2576 if mode == 'SA':
2578 dataOut.groupList = dataOut.groupList[1]
2577 dataOut.groupList = dataOut.groupList[1]
2579 nPairs = data_ccf.shape[0]
2578 nPairs = data_ccf.shape[0]
2580 #---------------------- Coherence and Phase --------------------------
2579 #---------------------- Coherence and Phase --------------------------
2581 phase = numpy.zeros(data_ccf[:,0,:,:].shape)
2580 phase = numpy.zeros(data_ccf[:,0,:,:].shape)
2582 # phase1 = numpy.copy(phase)
2581 # phase1 = numpy.copy(phase)
2583 coh1 = numpy.zeros(data_ccf[:,0,:,:].shape)
2582 coh1 = numpy.zeros(data_ccf[:,0,:,:].shape)
2584
2583
2585 for p in range(nPairs):
2584 for p in range(nPairs):
2586 ch0 = pairsList[p][0]
2585 ch0 = pairsList[p][0]
2587 ch1 = pairsList[p][1]
2586 ch1 = pairsList[p][1]
2588 ccf = data_ccf[p,0,:,:]/numpy.sqrt(data_acf[ch0,0,:,:]*data_acf[ch1,0,:,:])
2587 ccf = data_ccf[p,0,:,:]/numpy.sqrt(data_acf[ch0,0,:,:]*data_acf[ch1,0,:,:])
2589 phase[p,:,:] = ndimage.median_filter(numpy.angle(ccf), size = (5,1)) #median filter
2588 phase[p,:,:] = ndimage.median_filter(numpy.angle(ccf), size = (5,1)) #median filter
2590 # phase1[p,:,:] = numpy.angle(ccf) #median filter
2589 # phase1[p,:,:] = numpy.angle(ccf) #median filter
2591 coh1[p,:,:] = ndimage.median_filter(numpy.abs(ccf), 5) #median filter
2590 coh1[p,:,:] = ndimage.median_filter(numpy.abs(ccf), 5) #median filter
2592 # coh1[p,:,:] = numpy.abs(ccf) #median filter
2591 # coh1[p,:,:] = numpy.abs(ccf) #median filter
2593 coh = numpy.nanmax(coh1, axis = 0)
2592 coh = numpy.nanmax(coh1, axis = 0)
2594 # struc = numpy.ones((5,1))
2593 # struc = numpy.ones((5,1))
2595 # coh = ndimage.morphology.grey_dilation(coh, size=(10,1))
2594 # coh = ndimage.morphology.grey_dilation(coh, size=(10,1))
2596 #---------------------- Radial Velocity ----------------------------
2595 #---------------------- Radial Velocity ----------------------------
2597 phaseAux = numpy.mean(numpy.angle(data_acf[:,1,:,:]), axis = 0)
2596 phaseAux = numpy.mean(numpy.angle(data_acf[:,1,:,:]), axis = 0)
2598 velRad = phaseAux*lamb/(4*numpy.pi*tSamp)
2597 velRad = phaseAux*lamb/(4*numpy.pi*tSamp)
2599
2598
2600 if allData:
2599 if allData:
2601 boolMetFin = ~numpy.isnan(SNRm)
2600 boolMetFin = ~numpy.isnan(SNRm)
2602 # coh[:-1,:] = numpy.nanmean(numpy.abs(phase[:,1:,:] - phase[:,:-1,:]),axis=0)
2601 # coh[:-1,:] = numpy.nanmean(numpy.abs(phase[:,1:,:] - phase[:,:-1,:]),axis=0)
2603 else:
2602 else:
2604 #------------------------ Meteor mask ---------------------------------
2603 #------------------------ Meteor mask ---------------------------------
2605 # #SNR mask
2604 # #SNR mask
2606 # boolMet = (SNRdB>SNRthresh)#|(~numpy.isnan(SNRdB))
2605 # boolMet = (SNRdB>SNRthresh)#|(~numpy.isnan(SNRdB))
2607 #
2606 #
2608 # #Erase small objects
2607 # #Erase small objects
2609 # boolMet1 = self.__erase_small(boolMet, 2*sec, 5)
2608 # boolMet1 = self.__erase_small(boolMet, 2*sec, 5)
2610 #
2609 #
2611 # auxEEJ = numpy.sum(boolMet1,axis=0)
2610 # auxEEJ = numpy.sum(boolMet1,axis=0)
2612 # indOver = auxEEJ>nProfiles*0.8 #Use this later
2611 # indOver = auxEEJ>nProfiles*0.8 #Use this later
2613 # indEEJ = numpy.where(indOver)[0]
2612 # indEEJ = numpy.where(indOver)[0]
2614 # indNEEJ = numpy.where(~indOver)[0]
2613 # indNEEJ = numpy.where(~indOver)[0]
2615 #
2614 #
2616 # boolMetFin = boolMet1
2615 # boolMetFin = boolMet1
2617 #
2616 #
2618 # if indEEJ.size > 0:
2617 # if indEEJ.size > 0:
2619 # boolMet1[:,indEEJ] = False #Erase heights with EEJ
2618 # boolMet1[:,indEEJ] = False #Erase heights with EEJ
2620 #
2619 #
2621 # boolMet2 = coh > cohThresh
2620 # boolMet2 = coh > cohThresh
2622 # boolMet2 = self.__erase_small(boolMet2, 2*sec,5)
2621 # boolMet2 = self.__erase_small(boolMet2, 2*sec,5)
2623 #
2622 #
2624 # #Final Meteor mask
2623 # #Final Meteor mask
2625 # boolMetFin = boolMet1|boolMet2
2624 # boolMetFin = boolMet1|boolMet2
2626
2625
2627 #Coherence mask
2626 #Coherence mask
2628 boolMet1 = coh > 0.75
2627 boolMet1 = coh > 0.75
2629 struc = numpy.ones((30,1))
2628 struc = numpy.ones((30,1))
2630 boolMet1 = ndimage.morphology.binary_dilation(boolMet1, structure=struc)
2629 boolMet1 = ndimage.morphology.binary_dilation(boolMet1, structure=struc)
2631
2630
2632 #Derivative mask
2631 #Derivative mask
2633 derPhase = numpy.nanmean(numpy.abs(phase[:,1:,:] - phase[:,:-1,:]),axis=0)
2632 derPhase = numpy.nanmean(numpy.abs(phase[:,1:,:] - phase[:,:-1,:]),axis=0)
2634 boolMet2 = derPhase < 0.2
2633 boolMet2 = derPhase < 0.2
2635 # boolMet2 = ndimage.morphology.binary_opening(boolMet2)
2634 # boolMet2 = ndimage.morphology.binary_opening(boolMet2)
2636 # boolMet2 = ndimage.morphology.binary_closing(boolMet2, structure = numpy.ones((10,1)))
2635 # boolMet2 = ndimage.morphology.binary_closing(boolMet2, structure = numpy.ones((10,1)))
2637 boolMet2 = ndimage.median_filter(boolMet2,size=5)
2636 boolMet2 = ndimage.median_filter(boolMet2,size=5)
2638 boolMet2 = numpy.vstack((boolMet2,numpy.full((1,nHeights), True, dtype=bool)))
2637 boolMet2 = numpy.vstack((boolMet2,numpy.full((1,nHeights), True, dtype=bool)))
2639 # #Final mask
2638 # #Final mask
2640 # boolMetFin = boolMet2
2639 # boolMetFin = boolMet2
2641 boolMetFin = boolMet1&boolMet2
2640 boolMetFin = boolMet1&boolMet2
2642 # boolMetFin = ndimage.morphology.binary_dilation(boolMetFin)
2641 # boolMetFin = ndimage.morphology.binary_dilation(boolMetFin)
2643 #Creating data_param
2642 #Creating data_param
2644 coordMet = numpy.where(boolMetFin)
2643 coordMet = numpy.where(boolMetFin)
2645
2644
2646 tmet = coordMet[0]
2645 tmet = coordMet[0]
2647 hmet = coordMet[1]
2646 hmet = coordMet[1]
2648
2647
2649 data_param = numpy.zeros((tmet.size, 6 + nPairs))
2648 data_param = numpy.zeros((tmet.size, 6 + nPairs))
2650 data_param[:,0] = utctime
2649 data_param[:,0] = utctime
2651 data_param[:,1] = tmet
2650 data_param[:,1] = tmet
2652 data_param[:,2] = hmet
2651 data_param[:,2] = hmet
2653 data_param[:,3] = SNRm[tmet,hmet]
2652 data_param[:,3] = SNRm[tmet,hmet]
2654 data_param[:,4] = velRad[tmet,hmet]
2653 data_param[:,4] = velRad[tmet,hmet]
2655 data_param[:,5] = coh[tmet,hmet]
2654 data_param[:,5] = coh[tmet,hmet]
2656 data_param[:,6:] = phase[:,tmet,hmet].T
2655 data_param[:,6:] = phase[:,tmet,hmet].T
2657
2656
2658 elif mode == 'DBS':
2657 elif mode == 'DBS':
2659 dataOut.groupList = numpy.arange(nChannels)
2658 dataOut.groupList = numpy.arange(nChannels)
2660
2659
2661 #Radial Velocities
2660 #Radial Velocities
2662 phase = numpy.angle(data_acf[:,1,:,:])
2661 phase = numpy.angle(data_acf[:,1,:,:])
2663 # phase = ndimage.median_filter(numpy.angle(data_acf[:,1,:,:]), size = (1,5,1))
2662 # phase = ndimage.median_filter(numpy.angle(data_acf[:,1,:,:]), size = (1,5,1))
2664 velRad = phase*lamb/(4*numpy.pi*tSamp)
2663 velRad = phase*lamb/(4*numpy.pi*tSamp)
2665
2664
2666 #Spectral width
2665 #Spectral width
2667 # acf1 = ndimage.median_filter(numpy.abs(data_acf[:,1,:,:]), size = (1,5,1))
2666 # acf1 = ndimage.median_filter(numpy.abs(data_acf[:,1,:,:]), size = (1,5,1))
2668 # acf2 = ndimage.median_filter(numpy.abs(data_acf[:,2,:,:]), size = (1,5,1))
2667 # acf2 = ndimage.median_filter(numpy.abs(data_acf[:,2,:,:]), size = (1,5,1))
2669 acf1 = data_acf[:,1,:,:]
2668 acf1 = data_acf[:,1,:,:]
2670 acf2 = data_acf[:,2,:,:]
2669 acf2 = data_acf[:,2,:,:]
2671
2670
2672 spcWidth = (lamb/(2*numpy.sqrt(6)*numpy.pi*tSamp))*numpy.sqrt(numpy.log(acf1/acf2))
2671 spcWidth = (lamb/(2*numpy.sqrt(6)*numpy.pi*tSamp))*numpy.sqrt(numpy.log(acf1/acf2))
2673 # velRad = ndimage.median_filter(velRad, size = (1,5,1))
2672 # velRad = ndimage.median_filter(velRad, size = (1,5,1))
2674 if allData:
2673 if allData:
2675 boolMetFin = ~numpy.isnan(SNRdB)
2674 boolMetFin = ~numpy.isnan(SNRdB)
2676 else:
2675 else:
2677 #SNR
2676 #SNR
2678 boolMet1 = (SNRdB>SNRthresh) #SNR mask
2677 boolMet1 = (SNRdB>SNRthresh) #SNR mask
2679 boolMet1 = ndimage.median_filter(boolMet1, size=(1,5,5))
2678 boolMet1 = ndimage.median_filter(boolMet1, size=(1,5,5))
2680
2679
2681 #Radial velocity
2680 #Radial velocity
2682 boolMet2 = numpy.abs(velRad) < 20
2681 boolMet2 = numpy.abs(velRad) < 20
2683 boolMet2 = ndimage.median_filter(boolMet2, (1,5,5))
2682 boolMet2 = ndimage.median_filter(boolMet2, (1,5,5))
2684
2683
2685 #Spectral Width
2684 #Spectral Width
2686 boolMet3 = spcWidth < 30
2685 boolMet3 = spcWidth < 30
2687 boolMet3 = ndimage.median_filter(boolMet3, (1,5,5))
2686 boolMet3 = ndimage.median_filter(boolMet3, (1,5,5))
2688 # boolMetFin = self.__erase_small(boolMet1, 10,5)
2687 # boolMetFin = self.__erase_small(boolMet1, 10,5)
2689 boolMetFin = boolMet1&boolMet2&boolMet3
2688 boolMetFin = boolMet1&boolMet2&boolMet3
2690
2689
2691 #Creating data_param
2690 #Creating data_param
2692 coordMet = numpy.where(boolMetFin)
2691 coordMet = numpy.where(boolMetFin)
2693
2692
2694 cmet = coordMet[0]
2693 cmet = coordMet[0]
2695 tmet = coordMet[1]
2694 tmet = coordMet[1]
2696 hmet = coordMet[2]
2695 hmet = coordMet[2]
2697
2696
2698 data_param = numpy.zeros((tmet.size, 7))
2697 data_param = numpy.zeros((tmet.size, 7))
2699 data_param[:,0] = utctime
2698 data_param[:,0] = utctime
2700 data_param[:,1] = cmet
2699 data_param[:,1] = cmet
2701 data_param[:,2] = tmet
2700 data_param[:,2] = tmet
2702 data_param[:,3] = hmet
2701 data_param[:,3] = hmet
2703 data_param[:,4] = SNR[cmet,tmet,hmet].T
2702 data_param[:,4] = SNR[cmet,tmet,hmet].T
2704 data_param[:,5] = velRad[cmet,tmet,hmet].T
2703 data_param[:,5] = velRad[cmet,tmet,hmet].T
2705 data_param[:,6] = spcWidth[cmet,tmet,hmet].T
2704 data_param[:,6] = spcWidth[cmet,tmet,hmet].T
2706
2705
2707 # self.dataOut.data_param = data_int
2706 # self.dataOut.data_param = data_int
2708 if len(data_param) == 0:
2707 if len(data_param) == 0:
2709 dataOut.flagNoData = True
2708 dataOut.flagNoData = True
2710 else:
2709 else:
2711 dataOut.data_param = data_param
2710 dataOut.data_param = data_param
2712
2711
2713 def __erase_small(self, binArray, threshX, threshY):
2712 def __erase_small(self, binArray, threshX, threshY):
2714 labarray, numfeat = ndimage.measurements.label(binArray)
2713 labarray, numfeat = ndimage.measurements.label(binArray)
2715 binArray1 = numpy.copy(binArray)
2714 binArray1 = numpy.copy(binArray)
2716
2715
2717 for i in range(1,numfeat + 1):
2716 for i in range(1,numfeat + 1):
2718 auxBin = (labarray==i)
2717 auxBin = (labarray==i)
2719 auxSize = auxBin.sum()
2718 auxSize = auxBin.sum()
2720
2719
2721 x,y = numpy.where(auxBin)
2720 x,y = numpy.where(auxBin)
2722 widthX = x.max() - x.min()
2721 widthX = x.max() - x.min()
2723 widthY = y.max() - y.min()
2722 widthY = y.max() - y.min()
2724
2723
2725 #width X: 3 seg -> 12.5*3
2724 #width X: 3 seg -> 12.5*3
2726 #width Y:
2725 #width Y:
2727
2726
2728 if (auxSize < 50) or (widthX < threshX) or (widthY < threshY):
2727 if (auxSize < 50) or (widthX < threshX) or (widthY < threshY):
2729 binArray1[auxBin] = False
2728 binArray1[auxBin] = False
2730
2729
2731 return binArray1
2730 return binArray1
2732
2731
2733 #--------------- Specular Meteor ----------------
2732 #--------------- Specular Meteor ----------------
2734
2733
2735 class SMDetection(Operation):
2734 class SMDetection(Operation):
2736 '''
2735 '''
2737 Function DetectMeteors()
2736 Function DetectMeteors()
2738 Project developed with paper:
2737 Project developed with paper:
2739 HOLDSWORTH ET AL. 2004
2738 HOLDSWORTH ET AL. 2004
2740
2739
2741 Input:
2740 Input:
2742 self.dataOut.data_pre
2741 self.dataOut.data_pre
2743
2742
2744 centerReceiverIndex: From the channels, which is the center receiver
2743 centerReceiverIndex: From the channels, which is the center receiver
2745
2744
2746 hei_ref: Height reference for the Beacon signal extraction
2745 hei_ref: Height reference for the Beacon signal extraction
2747 tauindex:
2746 tauindex:
2748 predefinedPhaseShifts: Predefined phase offset for the voltge signals
2747 predefinedPhaseShifts: Predefined phase offset for the voltge signals
2749
2748
2750 cohDetection: Whether to user Coherent detection or not
2749 cohDetection: Whether to user Coherent detection or not
2751 cohDet_timeStep: Coherent Detection calculation time step
2750 cohDet_timeStep: Coherent Detection calculation time step
2752 cohDet_thresh: Coherent Detection phase threshold to correct phases
2751 cohDet_thresh: Coherent Detection phase threshold to correct phases
2753
2752
2754 noise_timeStep: Noise calculation time step
2753 noise_timeStep: Noise calculation time step
2755 noise_multiple: Noise multiple to define signal threshold
2754 noise_multiple: Noise multiple to define signal threshold
2756
2755
2757 multDet_timeLimit: Multiple Detection Removal time limit in seconds
2756 multDet_timeLimit: Multiple Detection Removal time limit in seconds
2758 multDet_rangeLimit: Multiple Detection Removal range limit in km
2757 multDet_rangeLimit: Multiple Detection Removal range limit in km
2759
2758
2760 phaseThresh: Maximum phase difference between receiver to be consider a meteor
2759 phaseThresh: Maximum phase difference between receiver to be consider a meteor
2761 SNRThresh: Minimum SNR threshold of the meteor signal to be consider a meteor
2760 SNRThresh: Minimum SNR threshold of the meteor signal to be consider a meteor
2762
2761
2763 hmin: Minimum Height of the meteor to use it in the further wind estimations
2762 hmin: Minimum Height of the meteor to use it in the further wind estimations
2764 hmax: Maximum Height of the meteor to use it in the further wind estimations
2763 hmax: Maximum Height of the meteor to use it in the further wind estimations
2765 azimuth: Azimuth angle correction
2764 azimuth: Azimuth angle correction
2766
2765
2767 Affected:
2766 Affected:
2768 self.dataOut.data_param
2767 self.dataOut.data_param
2769
2768
2770 Rejection Criteria (Errors):
2769 Rejection Criteria (Errors):
2771 0: No error; analysis OK
2770 0: No error; analysis OK
2772 1: SNR < SNR threshold
2771 1: SNR < SNR threshold
2773 2: angle of arrival (AOA) ambiguously determined
2772 2: angle of arrival (AOA) ambiguously determined
2774 3: AOA estimate not feasible
2773 3: AOA estimate not feasible
2775 4: Large difference in AOAs obtained from different antenna baselines
2774 4: Large difference in AOAs obtained from different antenna baselines
2776 5: echo at start or end of time series
2775 5: echo at start or end of time series
2777 6: echo less than 5 examples long; too short for analysis
2776 6: echo less than 5 examples long; too short for analysis
2778 7: echo rise exceeds 0.3s
2777 7: echo rise exceeds 0.3s
2779 8: echo decay time less than twice rise time
2778 8: echo decay time less than twice rise time
2780 9: large power level before echo
2779 9: large power level before echo
2781 10: large power level after echo
2780 10: large power level after echo
2782 11: poor fit to amplitude for estimation of decay time
2781 11: poor fit to amplitude for estimation of decay time
2783 12: poor fit to CCF phase variation for estimation of radial drift velocity
2782 12: poor fit to CCF phase variation for estimation of radial drift velocity
2784 13: height unresolvable echo: not valid height within 70 to 110 km
2783 13: height unresolvable echo: not valid height within 70 to 110 km
2785 14: height ambiguous echo: more then one possible height within 70 to 110 km
2784 14: height ambiguous echo: more then one possible height within 70 to 110 km
2786 15: radial drift velocity or projected horizontal velocity exceeds 200 m/s
2785 15: radial drift velocity or projected horizontal velocity exceeds 200 m/s
2787 16: oscilatory echo, indicating event most likely not an underdense echo
2786 16: oscilatory echo, indicating event most likely not an underdense echo
2788
2787
2789 17: phase difference in meteor Reestimation
2788 17: phase difference in meteor Reestimation
2790
2789
2791 Data Storage:
2790 Data Storage:
2792 Meteors for Wind Estimation (8):
2791 Meteors for Wind Estimation (8):
2793 Utc Time | Range Height
2792 Utc Time | Range Height
2794 Azimuth Zenith errorCosDir
2793 Azimuth Zenith errorCosDir
2795 VelRad errorVelRad
2794 VelRad errorVelRad
2796 Phase0 Phase1 Phase2 Phase3
2795 Phase0 Phase1 Phase2 Phase3
2797 TypeError
2796 TypeError
2798
2797
2799 '''
2798 '''
2800
2799
2801 def run(self, dataOut, hei_ref = None, tauindex = 0,
2800 def run(self, dataOut, hei_ref = None, tauindex = 0,
2802 phaseOffsets = None,
2801 phaseOffsets = None,
2803 cohDetection = False, cohDet_timeStep = 1, cohDet_thresh = 25,
2802 cohDetection = False, cohDet_timeStep = 1, cohDet_thresh = 25,
2804 noise_timeStep = 4, noise_multiple = 4,
2803 noise_timeStep = 4, noise_multiple = 4,
2805 multDet_timeLimit = 1, multDet_rangeLimit = 3,
2804 multDet_timeLimit = 1, multDet_rangeLimit = 3,
2806 phaseThresh = 20, SNRThresh = 5,
2805 phaseThresh = 20, SNRThresh = 5,
2807 hmin = 50, hmax=150, azimuth = 0,
2806 hmin = 50, hmax=150, azimuth = 0,
2808 channelPositions = None) :
2807 channelPositions = None) :
2809
2808
2810
2809
2811 #Getting Pairslist
2810 #Getting Pairslist
2812 if channelPositions == None:
2811 if channelPositions == None:
2813 # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T
2812 # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T
2814 channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella
2813 channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella
2815 meteorOps = SMOperations()
2814 meteorOps = SMOperations()
2816 pairslist0, distances = meteorOps.getPhasePairs(channelPositions)
2815 pairslist0, distances = meteorOps.getPhasePairs(channelPositions)
2817 heiRang = dataOut.getHeiRange()
2816 heiRang = dataOut.getHeiRange()
2818 #Get Beacon signal - No Beacon signal anymore
2817 #Get Beacon signal - No Beacon signal anymore
2819 # newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex])
2818 # newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex])
2820 #
2819 #
2821 # if hei_ref != None:
2820 # if hei_ref != None:
2822 # newheis = numpy.where(self.dataOut.heightList>hei_ref)
2821 # newheis = numpy.where(self.dataOut.heightList>hei_ref)
2823 #
2822 #
2824
2823
2825
2824
2826 #****************REMOVING HARDWARE PHASE DIFFERENCES***************
2825 #****************REMOVING HARDWARE PHASE DIFFERENCES***************
2827 # see if the user put in pre defined phase shifts
2826 # see if the user put in pre defined phase shifts
2828 voltsPShift = dataOut.data_pre.copy()
2827 voltsPShift = dataOut.data_pre.copy()
2829
2828
2830 # if predefinedPhaseShifts != None:
2829 # if predefinedPhaseShifts != None:
2831 # hardwarePhaseShifts = numpy.array(predefinedPhaseShifts)*numpy.pi/180
2830 # hardwarePhaseShifts = numpy.array(predefinedPhaseShifts)*numpy.pi/180
2832 #
2831 #
2833 # # elif beaconPhaseShifts:
2832 # # elif beaconPhaseShifts:
2834 # # #get hardware phase shifts using beacon signal
2833 # # #get hardware phase shifts using beacon signal
2835 # # hardwarePhaseShifts = self.__getHardwarePhaseDiff(self.dataOut.data_pre, pairslist, newheis, 10)
2834 # # hardwarePhaseShifts = self.__getHardwarePhaseDiff(self.dataOut.data_pre, pairslist, newheis, 10)
2836 # # hardwarePhaseShifts = numpy.insert(hardwarePhaseShifts,centerReceiverIndex,0)
2835 # # hardwarePhaseShifts = numpy.insert(hardwarePhaseShifts,centerReceiverIndex,0)
2837 #
2836 #
2838 # else:
2837 # else:
2839 # hardwarePhaseShifts = numpy.zeros(5)
2838 # hardwarePhaseShifts = numpy.zeros(5)
2840 #
2839 #
2841 # voltsPShift = numpy.zeros((self.dataOut.data_pre.shape[0],self.dataOut.data_pre.shape[1],self.dataOut.data_pre.shape[2]), dtype = 'complex')
2840 # voltsPShift = numpy.zeros((self.dataOut.data_pre.shape[0],self.dataOut.data_pre.shape[1],self.dataOut.data_pre.shape[2]), dtype = 'complex')
2842 # for i in range(self.dataOut.data_pre.shape[0]):
2841 # for i in range(self.dataOut.data_pre.shape[0]):
2843 # voltsPShift[i,:,:] = self.__shiftPhase(self.dataOut.data_pre[i,:,:], hardwarePhaseShifts[i])
2842 # voltsPShift[i,:,:] = self.__shiftPhase(self.dataOut.data_pre[i,:,:], hardwarePhaseShifts[i])
2844
2843
2845 #******************END OF REMOVING HARDWARE PHASE DIFFERENCES*********
2844 #******************END OF REMOVING HARDWARE PHASE DIFFERENCES*********
2846
2845
2847 #Remove DC
2846 #Remove DC
2848 voltsDC = numpy.mean(voltsPShift,1)
2847 voltsDC = numpy.mean(voltsPShift,1)
2849 voltsDC = numpy.mean(voltsDC,1)
2848 voltsDC = numpy.mean(voltsDC,1)
2850 for i in range(voltsDC.shape[0]):
2849 for i in range(voltsDC.shape[0]):
2851 voltsPShift[i] = voltsPShift[i] - voltsDC[i]
2850 voltsPShift[i] = voltsPShift[i] - voltsDC[i]
2852
2851
2853 #Don't considerate last heights, theyre used to calculate Hardware Phase Shift
2852 #Don't considerate last heights, theyre used to calculate Hardware Phase Shift
2854 # voltsPShift = voltsPShift[:,:,:newheis[0][0]]
2853 # voltsPShift = voltsPShift[:,:,:newheis[0][0]]
2855
2854
2856 #************ FIND POWER OF DATA W/COH OR NON COH DETECTION (3.4) **********
2855 #************ FIND POWER OF DATA W/COH OR NON COH DETECTION (3.4) **********
2857 #Coherent Detection
2856 #Coherent Detection
2858 if cohDetection:
2857 if cohDetection:
2859 #use coherent detection to get the net power
2858 #use coherent detection to get the net power
2860 cohDet_thresh = cohDet_thresh*numpy.pi/180
2859 cohDet_thresh = cohDet_thresh*numpy.pi/180
2861 voltsPShift = self.__coherentDetection(voltsPShift, cohDet_timeStep, dataOut.timeInterval, pairslist0, cohDet_thresh)
2860 voltsPShift = self.__coherentDetection(voltsPShift, cohDet_timeStep, dataOut.timeInterval, pairslist0, cohDet_thresh)
2862
2861
2863 #Non-coherent detection!
2862 #Non-coherent detection!
2864 powerNet = numpy.nansum(numpy.abs(voltsPShift[:,:,:])**2,0)
2863 powerNet = numpy.nansum(numpy.abs(voltsPShift[:,:,:])**2,0)
2865 #********** END OF COH/NON-COH POWER CALCULATION**********************
2864 #********** END OF COH/NON-COH POWER CALCULATION**********************
2866
2865
2867 #********** FIND THE NOISE LEVEL AND POSSIBLE METEORS ****************
2866 #********** FIND THE NOISE LEVEL AND POSSIBLE METEORS ****************
2868 #Get noise
2867 #Get noise
2869 noise, noise1 = self.__getNoise(powerNet, noise_timeStep, dataOut.timeInterval)
2868 noise, noise1 = self.__getNoise(powerNet, noise_timeStep, dataOut.timeInterval)
2870 # noise = self.getNoise1(powerNet, noise_timeStep, self.dataOut.timeInterval)
2869 # noise = self.getNoise1(powerNet, noise_timeStep, self.dataOut.timeInterval)
2871 #Get signal threshold
2870 #Get signal threshold
2872 signalThresh = noise_multiple*noise
2871 signalThresh = noise_multiple*noise
2873 #Meteor echoes detection
2872 #Meteor echoes detection
2874 listMeteors = self.__findMeteors(powerNet, signalThresh)
2873 listMeteors = self.__findMeteors(powerNet, signalThresh)
2875 #******* END OF NOISE LEVEL AND POSSIBLE METEORS CACULATION **********
2874 #******* END OF NOISE LEVEL AND POSSIBLE METEORS CACULATION **********
2876
2875
2877 #************** REMOVE MULTIPLE DETECTIONS (3.5) ***************************
2876 #************** REMOVE MULTIPLE DETECTIONS (3.5) ***************************
2878 #Parameters
2877 #Parameters
2879 heiRange = dataOut.getHeiRange()
2878 heiRange = dataOut.getHeiRange()
2880 rangeInterval = heiRange[1] - heiRange[0]
2879 rangeInterval = heiRange[1] - heiRange[0]
2881 rangeLimit = multDet_rangeLimit/rangeInterval
2880 rangeLimit = multDet_rangeLimit/rangeInterval
2882 timeLimit = multDet_timeLimit/dataOut.timeInterval
2881 timeLimit = multDet_timeLimit/dataOut.timeInterval
2883 #Multiple detection removals
2882 #Multiple detection removals
2884 listMeteors1 = self.__removeMultipleDetections(listMeteors, rangeLimit, timeLimit)
2883 listMeteors1 = self.__removeMultipleDetections(listMeteors, rangeLimit, timeLimit)
2885 #************ END OF REMOVE MULTIPLE DETECTIONS **********************
2884 #************ END OF REMOVE MULTIPLE DETECTIONS **********************
2886
2885
2887 #********************* METEOR REESTIMATION (3.7, 3.8, 3.9, 3.10) ********************
2886 #********************* METEOR REESTIMATION (3.7, 3.8, 3.9, 3.10) ********************
2888 #Parameters
2887 #Parameters
2889 phaseThresh = phaseThresh*numpy.pi/180
2888 phaseThresh = phaseThresh*numpy.pi/180
2890 thresh = [phaseThresh, noise_multiple, SNRThresh]
2889 thresh = [phaseThresh, noise_multiple, SNRThresh]
2891 #Meteor reestimation (Errors N 1, 6, 12, 17)
2890 #Meteor reestimation (Errors N 1, 6, 12, 17)
2892 listMeteors2, listMeteorsPower, listMeteorsVolts = self.__meteorReestimation(listMeteors1, voltsPShift, pairslist0, thresh, noise, dataOut.timeInterval, dataOut.frequency)
2891 listMeteors2, listMeteorsPower, listMeteorsVolts = self.__meteorReestimation(listMeteors1, voltsPShift, pairslist0, thresh, noise, dataOut.timeInterval, dataOut.frequency)
2893 # listMeteors2, listMeteorsPower, listMeteorsVolts = self.meteorReestimation3(listMeteors2, listMeteorsPower, listMeteorsVolts, voltsPShift, pairslist, thresh, noise)
2892 # listMeteors2, listMeteorsPower, listMeteorsVolts = self.meteorReestimation3(listMeteors2, listMeteorsPower, listMeteorsVolts, voltsPShift, pairslist, thresh, noise)
2894 #Estimation of decay times (Errors N 7, 8, 11)
2893 #Estimation of decay times (Errors N 7, 8, 11)
2895 listMeteors3 = self.__estimateDecayTime(listMeteors2, listMeteorsPower, dataOut.timeInterval, dataOut.frequency)
2894 listMeteors3 = self.__estimateDecayTime(listMeteors2, listMeteorsPower, dataOut.timeInterval, dataOut.frequency)
2896 #******************* END OF METEOR REESTIMATION *******************
2895 #******************* END OF METEOR REESTIMATION *******************
2897
2896
2898 #********************* METEOR PARAMETERS CALCULATION (3.11, 3.12, 3.13) **************************
2897 #********************* METEOR PARAMETERS CALCULATION (3.11, 3.12, 3.13) **************************
2899 #Calculating Radial Velocity (Error N 15)
2898 #Calculating Radial Velocity (Error N 15)
2900 radialStdThresh = 10
2899 radialStdThresh = 10
2901 listMeteors4 = self.__getRadialVelocity(listMeteors3, listMeteorsVolts, radialStdThresh, pairslist0, dataOut.timeInterval)
2900 listMeteors4 = self.__getRadialVelocity(listMeteors3, listMeteorsVolts, radialStdThresh, pairslist0, dataOut.timeInterval)
2902
2901
2903 if len(listMeteors4) > 0:
2902 if len(listMeteors4) > 0:
2904 #Setting New Array
2903 #Setting New Array
2905 date = dataOut.utctime
2904 date = dataOut.utctime
2906 arrayParameters = self.__setNewArrays(listMeteors4, date, heiRang)
2905 arrayParameters = self.__setNewArrays(listMeteors4, date, heiRang)
2907
2906
2908 #Correcting phase offset
2907 #Correcting phase offset
2909 if phaseOffsets != None:
2908 if phaseOffsets != None:
2910 phaseOffsets = numpy.array(phaseOffsets)*numpy.pi/180
2909 phaseOffsets = numpy.array(phaseOffsets)*numpy.pi/180
2911 arrayParameters[:,8:12] = numpy.unwrap(arrayParameters[:,8:12] + phaseOffsets)
2910 arrayParameters[:,8:12] = numpy.unwrap(arrayParameters[:,8:12] + phaseOffsets)
2912
2911
2913 #Second Pairslist
2912 #Second Pairslist
2914 pairsList = []
2913 pairsList = []
2915 pairx = (0,1)
2914 pairx = (0,1)
2916 pairy = (2,3)
2915 pairy = (2,3)
2917 pairsList.append(pairx)
2916 pairsList.append(pairx)
2918 pairsList.append(pairy)
2917 pairsList.append(pairy)
2919
2918
2920 jph = numpy.array([0,0,0,0])
2919 jph = numpy.array([0,0,0,0])
2921 h = (hmin,hmax)
2920 h = (hmin,hmax)
2922 arrayParameters = meteorOps.getMeteorParams(arrayParameters, azimuth, h, pairsList, distances, jph)
2921 arrayParameters = meteorOps.getMeteorParams(arrayParameters, azimuth, h, pairsList, distances, jph)
2923
2922
2924 # #Calculate AOA (Error N 3, 4)
2923 # #Calculate AOA (Error N 3, 4)
2925 # #JONES ET AL. 1998
2924 # #JONES ET AL. 1998
2926 # error = arrayParameters[:,-1]
2925 # error = arrayParameters[:,-1]
2927 # AOAthresh = numpy.pi/8
2926 # AOAthresh = numpy.pi/8
2928 # phases = -arrayParameters[:,9:13]
2927 # phases = -arrayParameters[:,9:13]
2929 # arrayParameters[:,4:7], arrayParameters[:,-1] = meteorOps.getAOA(phases, pairsList, error, AOAthresh, azimuth)
2928 # arrayParameters[:,4:7], arrayParameters[:,-1] = meteorOps.getAOA(phases, pairsList, error, AOAthresh, azimuth)
2930 #
2929 #
2931 # #Calculate Heights (Error N 13 and 14)
2930 # #Calculate Heights (Error N 13 and 14)
2932 # error = arrayParameters[:,-1]
2931 # error = arrayParameters[:,-1]
2933 # Ranges = arrayParameters[:,2]
2932 # Ranges = arrayParameters[:,2]
2934 # zenith = arrayParameters[:,5]
2933 # zenith = arrayParameters[:,5]
2935 # arrayParameters[:,3], arrayParameters[:,-1] = meteorOps.getHeights(Ranges, zenith, error, hmin, hmax)
2934 # arrayParameters[:,3], arrayParameters[:,-1] = meteorOps.getHeights(Ranges, zenith, error, hmin, hmax)
2936 # error = arrayParameters[:,-1]
2935 # error = arrayParameters[:,-1]
2937 #********************* END OF PARAMETERS CALCULATION **************************
2936 #********************* END OF PARAMETERS CALCULATION **************************
2938
2937
2939 #***************************+ PASS DATA TO NEXT STEP **********************
2938 #***************************+ PASS DATA TO NEXT STEP **********************
2940 # arrayFinal = arrayParameters.reshape((1,arrayParameters.shape[0],arrayParameters.shape[1]))
2939 # arrayFinal = arrayParameters.reshape((1,arrayParameters.shape[0],arrayParameters.shape[1]))
2941 dataOut.data_param = arrayParameters
2940 dataOut.data_param = arrayParameters
2942
2941
2943 if arrayParameters == None:
2942 if arrayParameters == None:
2944 dataOut.flagNoData = True
2943 dataOut.flagNoData = True
2945 else:
2944 else:
2946 dataOut.flagNoData = True
2945 dataOut.flagNoData = True
2947
2946
2948 return
2947 return
2949
2948
2950 def __getHardwarePhaseDiff(self, voltage0, pairslist, newheis, n):
2949 def __getHardwarePhaseDiff(self, voltage0, pairslist, newheis, n):
2951
2950
2952 minIndex = min(newheis[0])
2951 minIndex = min(newheis[0])
2953 maxIndex = max(newheis[0])
2952 maxIndex = max(newheis[0])
2954
2953
2955 voltage = voltage0[:,:,minIndex:maxIndex+1]
2954 voltage = voltage0[:,:,minIndex:maxIndex+1]
2956 nLength = voltage.shape[1]/n
2955 nLength = voltage.shape[1]/n
2957 nMin = 0
2956 nMin = 0
2958 nMax = 0
2957 nMax = 0
2959 phaseOffset = numpy.zeros((len(pairslist),n))
2958 phaseOffset = numpy.zeros((len(pairslist),n))
2960
2959
2961 for i in range(n):
2960 for i in range(n):
2962 nMax += nLength
2961 nMax += nLength
2963 phaseCCF = -numpy.angle(self.__calculateCCF(voltage[:,nMin:nMax,:], pairslist, [0]))
2962 phaseCCF = -numpy.angle(self.__calculateCCF(voltage[:,nMin:nMax,:], pairslist, [0]))
2964 phaseCCF = numpy.mean(phaseCCF, axis = 2)
2963 phaseCCF = numpy.mean(phaseCCF, axis = 2)
2965 phaseOffset[:,i] = phaseCCF.transpose()
2964 phaseOffset[:,i] = phaseCCF.transpose()
2966 nMin = nMax
2965 nMin = nMax
2967 # phaseDiff, phaseArrival = self.estimatePhaseDifference(voltage, pairslist)
2966 # phaseDiff, phaseArrival = self.estimatePhaseDifference(voltage, pairslist)
2968
2967
2969 #Remove Outliers
2968 #Remove Outliers
2970 factor = 2
2969 factor = 2
2971 wt = phaseOffset - signal.medfilt(phaseOffset,(1,5))
2970 wt = phaseOffset - signal.medfilt(phaseOffset,(1,5))
2972 dw = numpy.std(wt,axis = 1)
2971 dw = numpy.std(wt,axis = 1)
2973 dw = dw.reshape((dw.size,1))
2972 dw = dw.reshape((dw.size,1))
2974 ind = numpy.where(numpy.logical_or(wt>dw*factor,wt<-dw*factor))
2973 ind = numpy.where(numpy.logical_or(wt>dw*factor,wt<-dw*factor))
2975 phaseOffset[ind] = numpy.nan
2974 phaseOffset[ind] = numpy.nan
2976 phaseOffset = stats.nanmean(phaseOffset, axis=1)
2975 phaseOffset = stats.nanmean(phaseOffset, axis=1)
2977
2976
2978 return phaseOffset
2977 return phaseOffset
2979
2978
2980 def __shiftPhase(self, data, phaseShift):
2979 def __shiftPhase(self, data, phaseShift):
2981 #this will shift the phase of a complex number
2980 #this will shift the phase of a complex number
2982 dataShifted = numpy.abs(data) * numpy.exp((numpy.angle(data)+phaseShift)*1j)
2981 dataShifted = numpy.abs(data) * numpy.exp((numpy.angle(data)+phaseShift)*1j)
2983 return dataShifted
2982 return dataShifted
2984
2983
2985 def __estimatePhaseDifference(self, array, pairslist):
2984 def __estimatePhaseDifference(self, array, pairslist):
2986 nChannel = array.shape[0]
2985 nChannel = array.shape[0]
2987 nHeights = array.shape[2]
2986 nHeights = array.shape[2]
2988 numPairs = len(pairslist)
2987 numPairs = len(pairslist)
2989 # phaseCCF = numpy.zeros((nChannel, 5, nHeights))
2988 # phaseCCF = numpy.zeros((nChannel, 5, nHeights))
2990 phaseCCF = numpy.angle(self.__calculateCCF(array, pairslist, [-2,-1,0,1,2]))
2989 phaseCCF = numpy.angle(self.__calculateCCF(array, pairslist, [-2,-1,0,1,2]))
2991
2990
2992 #Correct phases
2991 #Correct phases
2993 derPhaseCCF = phaseCCF[:,1:,:] - phaseCCF[:,0:-1,:]
2992 derPhaseCCF = phaseCCF[:,1:,:] - phaseCCF[:,0:-1,:]
2994 indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi)
2993 indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi)
2995
2994
2996 if indDer[0].shape[0] > 0:
2995 if indDer[0].shape[0] > 0:
2997 for i in range(indDer[0].shape[0]):
2996 for i in range(indDer[0].shape[0]):
2998 signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i],indDer[2][i]])
2997 signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i],indDer[2][i]])
2999 phaseCCF[indDer[0][i],indDer[1][i]+1:,:] += signo*2*numpy.pi
2998 phaseCCF[indDer[0][i],indDer[1][i]+1:,:] += signo*2*numpy.pi
3000
2999
3001 # for j in range(numSides):
3000 # for j in range(numSides):
3002 # phaseCCFAux = self.calculateCCF(arrayCenter, arraySides[j,:,:], [-2,1,0,1,2])
3001 # phaseCCFAux = self.calculateCCF(arrayCenter, arraySides[j,:,:], [-2,1,0,1,2])
3003 # phaseCCF[j,:,:] = numpy.angle(phaseCCFAux)
3002 # phaseCCF[j,:,:] = numpy.angle(phaseCCFAux)
3004 #
3003 #
3005 #Linear
3004 #Linear
3006 phaseInt = numpy.zeros((numPairs,1))
3005 phaseInt = numpy.zeros((numPairs,1))
3007 angAllCCF = phaseCCF[:,[0,1,3,4],0]
3006 angAllCCF = phaseCCF[:,[0,1,3,4],0]
3008 for j in range(numPairs):
3007 for j in range(numPairs):
3009 fit = stats.linregress([-2,-1,1,2],angAllCCF[j,:])
3008 fit = stats.linregress([-2,-1,1,2],angAllCCF[j,:])
3010 phaseInt[j] = fit[1]
3009 phaseInt[j] = fit[1]
3011 #Phase Differences
3010 #Phase Differences
3012 phaseDiff = phaseInt - phaseCCF[:,2,:]
3011 phaseDiff = phaseInt - phaseCCF[:,2,:]
3013 phaseArrival = phaseInt.reshape(phaseInt.size)
3012 phaseArrival = phaseInt.reshape(phaseInt.size)
3014
3013
3015 #Dealias
3014 #Dealias
3016 phaseArrival = numpy.angle(numpy.exp(1j*phaseArrival))
3015 phaseArrival = numpy.angle(numpy.exp(1j*phaseArrival))
3017 # indAlias = numpy.where(phaseArrival > numpy.pi)
3016 # indAlias = numpy.where(phaseArrival > numpy.pi)
3018 # phaseArrival[indAlias] -= 2*numpy.pi
3017 # phaseArrival[indAlias] -= 2*numpy.pi
3019 # indAlias = numpy.where(phaseArrival < -numpy.pi)
3018 # indAlias = numpy.where(phaseArrival < -numpy.pi)
3020 # phaseArrival[indAlias] += 2*numpy.pi
3019 # phaseArrival[indAlias] += 2*numpy.pi
3021
3020
3022 return phaseDiff, phaseArrival
3021 return phaseDiff, phaseArrival
3023
3022
3024 def __coherentDetection(self, volts, timeSegment, timeInterval, pairslist, thresh):
3023 def __coherentDetection(self, volts, timeSegment, timeInterval, pairslist, thresh):
3025 #this function will run the coherent detection used in Holdworth et al. 2004 and return the net power
3024 #this function will run the coherent detection used in Holdworth et al. 2004 and return the net power
3026 #find the phase shifts of each channel over 1 second intervals
3025 #find the phase shifts of each channel over 1 second intervals
3027 #only look at ranges below the beacon signal
3026 #only look at ranges below the beacon signal
3028 numProfPerBlock = numpy.ceil(timeSegment/timeInterval)
3027 numProfPerBlock = numpy.ceil(timeSegment/timeInterval)
3029 numBlocks = int(volts.shape[1]/numProfPerBlock)
3028 numBlocks = int(volts.shape[1]/numProfPerBlock)
3030 numHeights = volts.shape[2]
3029 numHeights = volts.shape[2]
3031 nChannel = volts.shape[0]
3030 nChannel = volts.shape[0]
3032 voltsCohDet = volts.copy()
3031 voltsCohDet = volts.copy()
3033
3032
3034 pairsarray = numpy.array(pairslist)
3033 pairsarray = numpy.array(pairslist)
3035 indSides = pairsarray[:,1]
3034 indSides = pairsarray[:,1]
3036 # indSides = numpy.array(range(nChannel))
3035 # indSides = numpy.array(range(nChannel))
3037 # indSides = numpy.delete(indSides, indCenter)
3036 # indSides = numpy.delete(indSides, indCenter)
3038 #
3037 #
3039 # listCenter = numpy.array_split(volts[indCenter,:,:], numBlocks, 0)
3038 # listCenter = numpy.array_split(volts[indCenter,:,:], numBlocks, 0)
3040 listBlocks = numpy.array_split(volts, numBlocks, 1)
3039 listBlocks = numpy.array_split(volts, numBlocks, 1)
3041
3040
3042 startInd = 0
3041 startInd = 0
3043 endInd = 0
3042 endInd = 0
3044
3043
3045 for i in range(numBlocks):
3044 for i in range(numBlocks):
3046 startInd = endInd
3045 startInd = endInd
3047 endInd = endInd + listBlocks[i].shape[1]
3046 endInd = endInd + listBlocks[i].shape[1]
3048
3047
3049 arrayBlock = listBlocks[i]
3048 arrayBlock = listBlocks[i]
3050 # arrayBlockCenter = listCenter[i]
3049 # arrayBlockCenter = listCenter[i]
3051
3050
3052 #Estimate the Phase Difference
3051 #Estimate the Phase Difference
3053 phaseDiff, aux = self.__estimatePhaseDifference(arrayBlock, pairslist)
3052 phaseDiff, aux = self.__estimatePhaseDifference(arrayBlock, pairslist)
3054 #Phase Difference RMS
3053 #Phase Difference RMS
3055 arrayPhaseRMS = numpy.abs(phaseDiff)
3054 arrayPhaseRMS = numpy.abs(phaseDiff)
3056 phaseRMSaux = numpy.sum(arrayPhaseRMS < thresh,0)
3055 phaseRMSaux = numpy.sum(arrayPhaseRMS < thresh,0)
3057 indPhase = numpy.where(phaseRMSaux==4)
3056 indPhase = numpy.where(phaseRMSaux==4)
3058 #Shifting
3057 #Shifting
3059 if indPhase[0].shape[0] > 0:
3058 if indPhase[0].shape[0] > 0:
3060 for j in range(indSides.size):
3059 for j in range(indSides.size):
3061 arrayBlock[indSides[j],:,indPhase] = self.__shiftPhase(arrayBlock[indSides[j],:,indPhase], phaseDiff[j,indPhase].transpose())
3060 arrayBlock[indSides[j],:,indPhase] = self.__shiftPhase(arrayBlock[indSides[j],:,indPhase], phaseDiff[j,indPhase].transpose())
3062 voltsCohDet[:,startInd:endInd,:] = arrayBlock
3061 voltsCohDet[:,startInd:endInd,:] = arrayBlock
3063
3062
3064 return voltsCohDet
3063 return voltsCohDet
3065
3064
3066 def __calculateCCF(self, volts, pairslist ,laglist):
3065 def __calculateCCF(self, volts, pairslist ,laglist):
3067
3066
3068 nHeights = volts.shape[2]
3067 nHeights = volts.shape[2]
3069 nPoints = volts.shape[1]
3068 nPoints = volts.shape[1]
3070 voltsCCF = numpy.zeros((len(pairslist), len(laglist), nHeights),dtype = 'complex')
3069 voltsCCF = numpy.zeros((len(pairslist), len(laglist), nHeights),dtype = 'complex')
3071
3070
3072 for i in range(len(pairslist)):
3071 for i in range(len(pairslist)):
3073 volts1 = volts[pairslist[i][0]]
3072 volts1 = volts[pairslist[i][0]]
3074 volts2 = volts[pairslist[i][1]]
3073 volts2 = volts[pairslist[i][1]]
3075
3074
3076 for t in range(len(laglist)):
3075 for t in range(len(laglist)):
3077 idxT = laglist[t]
3076 idxT = laglist[t]
3078 if idxT >= 0:
3077 if idxT >= 0:
3079 vStacked = numpy.vstack((volts2[idxT:,:],
3078 vStacked = numpy.vstack((volts2[idxT:,:],
3080 numpy.zeros((idxT, nHeights),dtype='complex')))
3079 numpy.zeros((idxT, nHeights),dtype='complex')))
3081 else:
3080 else:
3082 vStacked = numpy.vstack((numpy.zeros((-idxT, nHeights),dtype='complex'),
3081 vStacked = numpy.vstack((numpy.zeros((-idxT, nHeights),dtype='complex'),
3083 volts2[:(nPoints + idxT),:]))
3082 volts2[:(nPoints + idxT),:]))
3084 voltsCCF[i,t,:] = numpy.sum((numpy.conjugate(volts1)*vStacked),axis=0)
3083 voltsCCF[i,t,:] = numpy.sum((numpy.conjugate(volts1)*vStacked),axis=0)
3085
3084
3086 vStacked = None
3085 vStacked = None
3087 return voltsCCF
3086 return voltsCCF
3088
3087
3089 def __getNoise(self, power, timeSegment, timeInterval):
3088 def __getNoise(self, power, timeSegment, timeInterval):
3090 numProfPerBlock = numpy.ceil(timeSegment/timeInterval)
3089 numProfPerBlock = numpy.ceil(timeSegment/timeInterval)
3091 numBlocks = int(power.shape[0]/numProfPerBlock)
3090 numBlocks = int(power.shape[0]/numProfPerBlock)
3092 numHeights = power.shape[1]
3091 numHeights = power.shape[1]
3093
3092
3094 listPower = numpy.array_split(power, numBlocks, 0)
3093 listPower = numpy.array_split(power, numBlocks, 0)
3095 noise = numpy.zeros((power.shape[0], power.shape[1]))
3094 noise = numpy.zeros((power.shape[0], power.shape[1]))
3096 noise1 = numpy.zeros((power.shape[0], power.shape[1]))
3095 noise1 = numpy.zeros((power.shape[0], power.shape[1]))
3097
3096
3098 startInd = 0
3097 startInd = 0
3099 endInd = 0
3098 endInd = 0
3100
3099
3101 for i in range(numBlocks): #split por canal
3100 for i in range(numBlocks): #split por canal
3102 startInd = endInd
3101 startInd = endInd
3103 endInd = endInd + listPower[i].shape[0]
3102 endInd = endInd + listPower[i].shape[0]
3104
3103
3105 arrayBlock = listPower[i]
3104 arrayBlock = listPower[i]
3106 noiseAux = numpy.mean(arrayBlock, 0)
3105 noiseAux = numpy.mean(arrayBlock, 0)
3107 # noiseAux = numpy.median(noiseAux)
3106 # noiseAux = numpy.median(noiseAux)
3108 # noiseAux = numpy.mean(arrayBlock)
3107 # noiseAux = numpy.mean(arrayBlock)
3109 noise[startInd:endInd,:] = noise[startInd:endInd,:] + noiseAux
3108 noise[startInd:endInd,:] = noise[startInd:endInd,:] + noiseAux
3110
3109
3111 noiseAux1 = numpy.mean(arrayBlock)
3110 noiseAux1 = numpy.mean(arrayBlock)
3112 noise1[startInd:endInd,:] = noise1[startInd:endInd,:] + noiseAux1
3111 noise1[startInd:endInd,:] = noise1[startInd:endInd,:] + noiseAux1
3113
3112
3114 return noise, noise1
3113 return noise, noise1
3115
3114
3116 def __findMeteors(self, power, thresh):
3115 def __findMeteors(self, power, thresh):
3117 nProf = power.shape[0]
3116 nProf = power.shape[0]
3118 nHeights = power.shape[1]
3117 nHeights = power.shape[1]
3119 listMeteors = []
3118 listMeteors = []
3120
3119
3121 for i in range(nHeights):
3120 for i in range(nHeights):
3122 powerAux = power[:,i]
3121 powerAux = power[:,i]
3123 threshAux = thresh[:,i]
3122 threshAux = thresh[:,i]
3124
3123
3125 indUPthresh = numpy.where(powerAux > threshAux)[0]
3124 indUPthresh = numpy.where(powerAux > threshAux)[0]
3126 indDNthresh = numpy.where(powerAux <= threshAux)[0]
3125 indDNthresh = numpy.where(powerAux <= threshAux)[0]
3127
3126
3128 j = 0
3127 j = 0
3129
3128
3130 while (j < indUPthresh.size - 2):
3129 while (j < indUPthresh.size - 2):
3131 if (indUPthresh[j + 2] == indUPthresh[j] + 2):
3130 if (indUPthresh[j + 2] == indUPthresh[j] + 2):
3132 indDNAux = numpy.where(indDNthresh > indUPthresh[j])
3131 indDNAux = numpy.where(indDNthresh > indUPthresh[j])
3133 indDNthresh = indDNthresh[indDNAux]
3132 indDNthresh = indDNthresh[indDNAux]
3134
3133
3135 if (indDNthresh.size > 0):
3134 if (indDNthresh.size > 0):
3136 indEnd = indDNthresh[0] - 1
3135 indEnd = indDNthresh[0] - 1
3137 indInit = indUPthresh[j]
3136 indInit = indUPthresh[j]
3138
3137
3139 meteor = powerAux[indInit:indEnd + 1]
3138 meteor = powerAux[indInit:indEnd + 1]
3140 indPeak = meteor.argmax() + indInit
3139 indPeak = meteor.argmax() + indInit
3141 FLA = sum(numpy.conj(meteor)*numpy.hstack((meteor[1:],0)))
3140 FLA = sum(numpy.conj(meteor)*numpy.hstack((meteor[1:],0)))
3142
3141
3143 listMeteors.append(numpy.array([i,indInit,indPeak,indEnd,FLA])) #CHEQUEAR!!!!!
3142 listMeteors.append(numpy.array([i,indInit,indPeak,indEnd,FLA])) #CHEQUEAR!!!!!
3144 j = numpy.where(indUPthresh == indEnd)[0] + 1
3143 j = numpy.where(indUPthresh == indEnd)[0] + 1
3145 else: j+=1
3144 else: j+=1
3146 else: j+=1
3145 else: j+=1
3147
3146
3148 return listMeteors
3147 return listMeteors
3149
3148
3150 def __removeMultipleDetections(self,listMeteors, rangeLimit, timeLimit):
3149 def __removeMultipleDetections(self,listMeteors, rangeLimit, timeLimit):
3151
3150
3152 arrayMeteors = numpy.asarray(listMeteors)
3151 arrayMeteors = numpy.asarray(listMeteors)
3153 listMeteors1 = []
3152 listMeteors1 = []
3154
3153
3155 while arrayMeteors.shape[0] > 0:
3154 while arrayMeteors.shape[0] > 0:
3156 FLAs = arrayMeteors[:,4]
3155 FLAs = arrayMeteors[:,4]
3157 maxFLA = FLAs.argmax()
3156 maxFLA = FLAs.argmax()
3158 listMeteors1.append(arrayMeteors[maxFLA,:])
3157 listMeteors1.append(arrayMeteors[maxFLA,:])
3159
3158
3160 MeteorInitTime = arrayMeteors[maxFLA,1]
3159 MeteorInitTime = arrayMeteors[maxFLA,1]
3161 MeteorEndTime = arrayMeteors[maxFLA,3]
3160 MeteorEndTime = arrayMeteors[maxFLA,3]
3162 MeteorHeight = arrayMeteors[maxFLA,0]
3161 MeteorHeight = arrayMeteors[maxFLA,0]
3163
3162
3164 #Check neighborhood
3163 #Check neighborhood
3165 maxHeightIndex = MeteorHeight + rangeLimit
3164 maxHeightIndex = MeteorHeight + rangeLimit
3166 minHeightIndex = MeteorHeight - rangeLimit
3165 minHeightIndex = MeteorHeight - rangeLimit
3167 minTimeIndex = MeteorInitTime - timeLimit
3166 minTimeIndex = MeteorInitTime - timeLimit
3168 maxTimeIndex = MeteorEndTime + timeLimit
3167 maxTimeIndex = MeteorEndTime + timeLimit
3169
3168
3170 #Check Heights
3169 #Check Heights
3171 indHeight = numpy.logical_and(arrayMeteors[:,0] >= minHeightIndex, arrayMeteors[:,0] <= maxHeightIndex)
3170 indHeight = numpy.logical_and(arrayMeteors[:,0] >= minHeightIndex, arrayMeteors[:,0] <= maxHeightIndex)
3172 indTime = numpy.logical_and(arrayMeteors[:,3] >= minTimeIndex, arrayMeteors[:,1] <= maxTimeIndex)
3171 indTime = numpy.logical_and(arrayMeteors[:,3] >= minTimeIndex, arrayMeteors[:,1] <= maxTimeIndex)
3173 indBoth = numpy.where(numpy.logical_and(indTime,indHeight))
3172 indBoth = numpy.where(numpy.logical_and(indTime,indHeight))
3174
3173
3175 arrayMeteors = numpy.delete(arrayMeteors, indBoth, axis = 0)
3174 arrayMeteors = numpy.delete(arrayMeteors, indBoth, axis = 0)
3176
3175
3177 return listMeteors1
3176 return listMeteors1
3178
3177
3179 def __meteorReestimation(self, listMeteors, volts, pairslist, thresh, noise, timeInterval,frequency):
3178 def __meteorReestimation(self, listMeteors, volts, pairslist, thresh, noise, timeInterval,frequency):
3180 numHeights = volts.shape[2]
3179 numHeights = volts.shape[2]
3181 nChannel = volts.shape[0]
3180 nChannel = volts.shape[0]
3182
3181
3183 thresholdPhase = thresh[0]
3182 thresholdPhase = thresh[0]
3184 thresholdNoise = thresh[1]
3183 thresholdNoise = thresh[1]
3185 thresholdDB = float(thresh[2])
3184 thresholdDB = float(thresh[2])
3186
3185
3187 thresholdDB1 = 10**(thresholdDB/10)
3186 thresholdDB1 = 10**(thresholdDB/10)
3188 pairsarray = numpy.array(pairslist)
3187 pairsarray = numpy.array(pairslist)
3189 indSides = pairsarray[:,1]
3188 indSides = pairsarray[:,1]
3190
3189
3191 pairslist1 = list(pairslist)
3190 pairslist1 = list(pairslist)
3192 pairslist1.append((0,1))
3191 pairslist1.append((0,1))
3193 pairslist1.append((3,4))
3192 pairslist1.append((3,4))
3194
3193
3195 listMeteors1 = []
3194 listMeteors1 = []
3196 listPowerSeries = []
3195 listPowerSeries = []
3197 listVoltageSeries = []
3196 listVoltageSeries = []
3198 #volts has the war data
3197 #volts has the war data
3199
3198
3200 if frequency == 30e6:
3199 if frequency == 30e6:
3201 timeLag = 45*10**-3
3200 timeLag = 45*10**-3
3202 else:
3201 else:
3203 timeLag = 15*10**-3
3202 timeLag = 15*10**-3
3204 lag = numpy.ceil(timeLag/timeInterval)
3203 lag = numpy.ceil(timeLag/timeInterval)
3205
3204
3206 for i in range(len(listMeteors)):
3205 for i in range(len(listMeteors)):
3207
3206
3208 ###################### 3.6 - 3.7 PARAMETERS REESTIMATION #########################
3207 ###################### 3.6 - 3.7 PARAMETERS REESTIMATION #########################
3209 meteorAux = numpy.zeros(16)
3208 meteorAux = numpy.zeros(16)
3210
3209
3211 #Loading meteor Data (mHeight, mStart, mPeak, mEnd)
3210 #Loading meteor Data (mHeight, mStart, mPeak, mEnd)
3212 mHeight = listMeteors[i][0]
3211 mHeight = listMeteors[i][0]
3213 mStart = listMeteors[i][1]
3212 mStart = listMeteors[i][1]
3214 mPeak = listMeteors[i][2]
3213 mPeak = listMeteors[i][2]
3215 mEnd = listMeteors[i][3]
3214 mEnd = listMeteors[i][3]
3216
3215
3217 #get the volt data between the start and end times of the meteor
3216 #get the volt data between the start and end times of the meteor
3218 meteorVolts = volts[:,mStart:mEnd+1,mHeight]
3217 meteorVolts = volts[:,mStart:mEnd+1,mHeight]
3219 meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1)
3218 meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1)
3220
3219
3221 #3.6. Phase Difference estimation
3220 #3.6. Phase Difference estimation
3222 phaseDiff, aux = self.__estimatePhaseDifference(meteorVolts, pairslist)
3221 phaseDiff, aux = self.__estimatePhaseDifference(meteorVolts, pairslist)
3223
3222
3224 #3.7. Phase difference removal & meteor start, peak and end times reestimated
3223 #3.7. Phase difference removal & meteor start, peak and end times reestimated
3225 #meteorVolts0.- all Channels, all Profiles
3224 #meteorVolts0.- all Channels, all Profiles
3226 meteorVolts0 = volts[:,:,mHeight]
3225 meteorVolts0 = volts[:,:,mHeight]
3227 meteorThresh = noise[:,mHeight]*thresholdNoise
3226 meteorThresh = noise[:,mHeight]*thresholdNoise
3228 meteorNoise = noise[:,mHeight]
3227 meteorNoise = noise[:,mHeight]
3229 meteorVolts0[indSides,:] = self.__shiftPhase(meteorVolts0[indSides,:], phaseDiff) #Phase Shifting
3228 meteorVolts0[indSides,:] = self.__shiftPhase(meteorVolts0[indSides,:], phaseDiff) #Phase Shifting
3230 powerNet0 = numpy.nansum(numpy.abs(meteorVolts0)**2, axis = 0) #Power
3229 powerNet0 = numpy.nansum(numpy.abs(meteorVolts0)**2, axis = 0) #Power
3231
3230
3232 #Times reestimation
3231 #Times reestimation
3233 mStart1 = numpy.where(powerNet0[:mPeak] < meteorThresh[:mPeak])[0]
3232 mStart1 = numpy.where(powerNet0[:mPeak] < meteorThresh[:mPeak])[0]
3234 if mStart1.size > 0:
3233 if mStart1.size > 0:
3235 mStart1 = mStart1[-1] + 1
3234 mStart1 = mStart1[-1] + 1
3236
3235
3237 else:
3236 else:
3238 mStart1 = mPeak
3237 mStart1 = mPeak
3239
3238
3240 mEnd1 = numpy.where(powerNet0[mPeak:] < meteorThresh[mPeak:])[0][0] + mPeak - 1
3239 mEnd1 = numpy.where(powerNet0[mPeak:] < meteorThresh[mPeak:])[0][0] + mPeak - 1
3241 mEndDecayTime1 = numpy.where(powerNet0[mPeak:] < meteorNoise[mPeak:])[0]
3240 mEndDecayTime1 = numpy.where(powerNet0[mPeak:] < meteorNoise[mPeak:])[0]
3242 if mEndDecayTime1.size == 0:
3241 if mEndDecayTime1.size == 0:
3243 mEndDecayTime1 = powerNet0.size
3242 mEndDecayTime1 = powerNet0.size
3244 else:
3243 else:
3245 mEndDecayTime1 = mEndDecayTime1[0] + mPeak - 1
3244 mEndDecayTime1 = mEndDecayTime1[0] + mPeak - 1
3246 # mPeak1 = meteorVolts0[mStart1:mEnd1 + 1].argmax()
3245 # mPeak1 = meteorVolts0[mStart1:mEnd1 + 1].argmax()
3247
3246
3248 #meteorVolts1.- all Channels, from start to end
3247 #meteorVolts1.- all Channels, from start to end
3249 meteorVolts1 = meteorVolts0[:,mStart1:mEnd1 + 1]
3248 meteorVolts1 = meteorVolts0[:,mStart1:mEnd1 + 1]
3250 meteorVolts2 = meteorVolts0[:,mPeak + lag:mEnd1 + 1]
3249 meteorVolts2 = meteorVolts0[:,mPeak + lag:mEnd1 + 1]
3251 if meteorVolts2.shape[1] == 0:
3250 if meteorVolts2.shape[1] == 0:
3252 meteorVolts2 = meteorVolts0[:,mPeak:mEnd1 + 1]
3251 meteorVolts2 = meteorVolts0[:,mPeak:mEnd1 + 1]
3253 meteorVolts1 = meteorVolts1.reshape(meteorVolts1.shape[0], meteorVolts1.shape[1], 1)
3252 meteorVolts1 = meteorVolts1.reshape(meteorVolts1.shape[0], meteorVolts1.shape[1], 1)
3254 meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1], 1)
3253 meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1], 1)
3255 ##################### END PARAMETERS REESTIMATION #########################
3254 ##################### END PARAMETERS REESTIMATION #########################
3256
3255
3257 ##################### 3.8 PHASE DIFFERENCE REESTIMATION ########################
3256 ##################### 3.8 PHASE DIFFERENCE REESTIMATION ########################
3258 # if mEnd1 - mStart1 > 4: #Error Number 6: echo less than 5 samples long; too short for analysis
3257 # if mEnd1 - mStart1 > 4: #Error Number 6: echo less than 5 samples long; too short for analysis
3259 if meteorVolts2.shape[1] > 0:
3258 if meteorVolts2.shape[1] > 0:
3260 #Phase Difference re-estimation
3259 #Phase Difference re-estimation
3261 phaseDiff1, phaseDiffint = self.__estimatePhaseDifference(meteorVolts2, pairslist1) #Phase Difference Estimation
3260 phaseDiff1, phaseDiffint = self.__estimatePhaseDifference(meteorVolts2, pairslist1) #Phase Difference Estimation
3262 # phaseDiff1, phaseDiffint = self.estimatePhaseDifference(meteorVolts2, pairslist)
3261 # phaseDiff1, phaseDiffint = self.estimatePhaseDifference(meteorVolts2, pairslist)
3263 meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1])
3262 meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1])
3264 phaseDiff11 = numpy.reshape(phaseDiff1, (phaseDiff1.shape[0],1))
3263 phaseDiff11 = numpy.reshape(phaseDiff1, (phaseDiff1.shape[0],1))
3265 meteorVolts2[indSides,:] = self.__shiftPhase(meteorVolts2[indSides,:], phaseDiff11[0:4]) #Phase Shifting
3264 meteorVolts2[indSides,:] = self.__shiftPhase(meteorVolts2[indSides,:], phaseDiff11[0:4]) #Phase Shifting
3266
3265
3267 #Phase Difference RMS
3266 #Phase Difference RMS
3268 phaseRMS1 = numpy.sqrt(numpy.mean(numpy.square(phaseDiff1)))
3267 phaseRMS1 = numpy.sqrt(numpy.mean(numpy.square(phaseDiff1)))
3269 powerNet1 = numpy.nansum(numpy.abs(meteorVolts1[:,:])**2,0)
3268 powerNet1 = numpy.nansum(numpy.abs(meteorVolts1[:,:])**2,0)
3270 #Data from Meteor
3269 #Data from Meteor
3271 mPeak1 = powerNet1.argmax() + mStart1
3270 mPeak1 = powerNet1.argmax() + mStart1
3272 mPeakPower1 = powerNet1.max()
3271 mPeakPower1 = powerNet1.max()
3273 noiseAux = sum(noise[mStart1:mEnd1 + 1,mHeight])
3272 noiseAux = sum(noise[mStart1:mEnd1 + 1,mHeight])
3274 mSNR1 = (sum(powerNet1)-noiseAux)/noiseAux
3273 mSNR1 = (sum(powerNet1)-noiseAux)/noiseAux
3275 Meteor1 = numpy.array([mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1])
3274 Meteor1 = numpy.array([mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1])
3276 Meteor1 = numpy.hstack((Meteor1,phaseDiffint))
3275 Meteor1 = numpy.hstack((Meteor1,phaseDiffint))
3277 PowerSeries = powerNet0[mStart1:mEndDecayTime1 + 1]
3276 PowerSeries = powerNet0[mStart1:mEndDecayTime1 + 1]
3278 #Vectorize
3277 #Vectorize
3279 meteorAux[0:7] = [mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1]
3278 meteorAux[0:7] = [mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1]
3280 meteorAux[7:11] = phaseDiffint[0:4]
3279 meteorAux[7:11] = phaseDiffint[0:4]
3281
3280
3282 #Rejection Criterions
3281 #Rejection Criterions
3283 if phaseRMS1 > thresholdPhase: #Error Number 17: Phase variation
3282 if phaseRMS1 > thresholdPhase: #Error Number 17: Phase variation
3284 meteorAux[-1] = 17
3283 meteorAux[-1] = 17
3285 elif mSNR1 < thresholdDB1: #Error Number 1: SNR < threshold dB
3284 elif mSNR1 < thresholdDB1: #Error Number 1: SNR < threshold dB
3286 meteorAux[-1] = 1
3285 meteorAux[-1] = 1
3287
3286
3288
3287
3289 else:
3288 else:
3290 meteorAux[0:4] = [mHeight, mStart, mPeak, mEnd]
3289 meteorAux[0:4] = [mHeight, mStart, mPeak, mEnd]
3291 meteorAux[-1] = 6 #Error Number 6: echo less than 5 samples long; too short for analysis
3290 meteorAux[-1] = 6 #Error Number 6: echo less than 5 samples long; too short for analysis
3292 PowerSeries = 0
3291 PowerSeries = 0
3293
3292
3294 listMeteors1.append(meteorAux)
3293 listMeteors1.append(meteorAux)
3295 listPowerSeries.append(PowerSeries)
3294 listPowerSeries.append(PowerSeries)
3296 listVoltageSeries.append(meteorVolts1)
3295 listVoltageSeries.append(meteorVolts1)
3297
3296
3298 return listMeteors1, listPowerSeries, listVoltageSeries
3297 return listMeteors1, listPowerSeries, listVoltageSeries
3299
3298
3300 def __estimateDecayTime(self, listMeteors, listPower, timeInterval, frequency):
3299 def __estimateDecayTime(self, listMeteors, listPower, timeInterval, frequency):
3301
3300
3302 threshError = 10
3301 threshError = 10
3303 #Depending if it is 30 or 50 MHz
3302 #Depending if it is 30 or 50 MHz
3304 if frequency == 30e6:
3303 if frequency == 30e6:
3305 timeLag = 45*10**-3
3304 timeLag = 45*10**-3
3306 else:
3305 else:
3307 timeLag = 15*10**-3
3306 timeLag = 15*10**-3
3308 lag = numpy.ceil(timeLag/timeInterval)
3307 lag = numpy.ceil(timeLag/timeInterval)
3309
3308
3310 listMeteors1 = []
3309 listMeteors1 = []
3311
3310
3312 for i in range(len(listMeteors)):
3311 for i in range(len(listMeteors)):
3313 meteorPower = listPower[i]
3312 meteorPower = listPower[i]
3314 meteorAux = listMeteors[i]
3313 meteorAux = listMeteors[i]
3315
3314
3316 if meteorAux[-1] == 0:
3315 if meteorAux[-1] == 0:
3317
3316
3318 try:
3317 try:
3319 indmax = meteorPower.argmax()
3318 indmax = meteorPower.argmax()
3320 indlag = indmax + lag
3319 indlag = indmax + lag
3321
3320
3322 y = meteorPower[indlag:]
3321 y = meteorPower[indlag:]
3323 x = numpy.arange(0, y.size)*timeLag
3322 x = numpy.arange(0, y.size)*timeLag
3324
3323
3325 #first guess
3324 #first guess
3326 a = y[0]
3325 a = y[0]
3327 tau = timeLag
3326 tau = timeLag
3328 #exponential fit
3327 #exponential fit
3329 popt, pcov = optimize.curve_fit(self.__exponential_function, x, y, p0 = [a, tau])
3328 popt, pcov = optimize.curve_fit(self.__exponential_function, x, y, p0 = [a, tau])
3330 y1 = self.__exponential_function(x, *popt)
3329 y1 = self.__exponential_function(x, *popt)
3331 #error estimation
3330 #error estimation
3332 error = sum((y - y1)**2)/(numpy.var(y)*(y.size - popt.size))
3331 error = sum((y - y1)**2)/(numpy.var(y)*(y.size - popt.size))
3333
3332
3334 decayTime = popt[1]
3333 decayTime = popt[1]
3335 riseTime = indmax*timeInterval
3334 riseTime = indmax*timeInterval
3336 meteorAux[11:13] = [decayTime, error]
3335 meteorAux[11:13] = [decayTime, error]
3337
3336
3338 #Table items 7, 8 and 11
3337 #Table items 7, 8 and 11
3339 if (riseTime > 0.3): #Number 7: Echo rise exceeds 0.3s
3338 if (riseTime > 0.3): #Number 7: Echo rise exceeds 0.3s
3340 meteorAux[-1] = 7
3339 meteorAux[-1] = 7
3341 elif (decayTime < 2*riseTime) : #Number 8: Echo decay time less than than twice rise time
3340 elif (decayTime < 2*riseTime) : #Number 8: Echo decay time less than than twice rise time
3342 meteorAux[-1] = 8
3341 meteorAux[-1] = 8
3343 if (error > threshError): #Number 11: Poor fit to amplitude for estimation of decay time
3342 if (error > threshError): #Number 11: Poor fit to amplitude for estimation of decay time
3344 meteorAux[-1] = 11
3343 meteorAux[-1] = 11
3345
3344
3346
3345
3347 except:
3346 except:
3348 meteorAux[-1] = 11
3347 meteorAux[-1] = 11
3349
3348
3350
3349
3351 listMeteors1.append(meteorAux)
3350 listMeteors1.append(meteorAux)
3352
3351
3353 return listMeteors1
3352 return listMeteors1
3354
3353
3355 #Exponential Function
3354 #Exponential Function
3356
3355
3357 def __exponential_function(self, x, a, tau):
3356 def __exponential_function(self, x, a, tau):
3358 y = a*numpy.exp(-x/tau)
3357 y = a*numpy.exp(-x/tau)
3359 return y
3358 return y
3360
3359
3361 def __getRadialVelocity(self, listMeteors, listVolts, radialStdThresh, pairslist, timeInterval):
3360 def __getRadialVelocity(self, listMeteors, listVolts, radialStdThresh, pairslist, timeInterval):
3362
3361
3363 pairslist1 = list(pairslist)
3362 pairslist1 = list(pairslist)
3364 pairslist1.append((0,1))
3363 pairslist1.append((0,1))
3365 pairslist1.append((3,4))
3364 pairslist1.append((3,4))
3366 numPairs = len(pairslist1)
3365 numPairs = len(pairslist1)
3367 #Time Lag
3366 #Time Lag
3368 timeLag = 45*10**-3
3367 timeLag = 45*10**-3
3369 c = 3e8
3368 c = 3e8
3370 lag = numpy.ceil(timeLag/timeInterval)
3369 lag = numpy.ceil(timeLag/timeInterval)
3371 freq = 30e6
3370 freq = 30e6
3372
3371
3373 listMeteors1 = []
3372 listMeteors1 = []
3374
3373
3375 for i in range(len(listMeteors)):
3374 for i in range(len(listMeteors)):
3376 meteorAux = listMeteors[i]
3375 meteorAux = listMeteors[i]
3377 if meteorAux[-1] == 0:
3376 if meteorAux[-1] == 0:
3378 mStart = listMeteors[i][1]
3377 mStart = listMeteors[i][1]
3379 mPeak = listMeteors[i][2]
3378 mPeak = listMeteors[i][2]
3380 mLag = mPeak - mStart + lag
3379 mLag = mPeak - mStart + lag
3381
3380
3382 #get the volt data between the start and end times of the meteor
3381 #get the volt data between the start and end times of the meteor
3383 meteorVolts = listVolts[i]
3382 meteorVolts = listVolts[i]
3384 meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1)
3383 meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1)
3385
3384
3386 #Get CCF
3385 #Get CCF
3387 allCCFs = self.__calculateCCF(meteorVolts, pairslist1, [-2,-1,0,1,2])
3386 allCCFs = self.__calculateCCF(meteorVolts, pairslist1, [-2,-1,0,1,2])
3388
3387
3389 #Method 2
3388 #Method 2
3390 slopes = numpy.zeros(numPairs)
3389 slopes = numpy.zeros(numPairs)
3391 time = numpy.array([-2,-1,1,2])*timeInterval
3390 time = numpy.array([-2,-1,1,2])*timeInterval
3392 angAllCCF = numpy.angle(allCCFs[:,[0,1,3,4],0])
3391 angAllCCF = numpy.angle(allCCFs[:,[0,1,3,4],0])
3393
3392
3394 #Correct phases
3393 #Correct phases
3395 derPhaseCCF = angAllCCF[:,1:] - angAllCCF[:,0:-1]
3394 derPhaseCCF = angAllCCF[:,1:] - angAllCCF[:,0:-1]
3396 indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi)
3395 indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi)
3397
3396
3398 if indDer[0].shape[0] > 0:
3397 if indDer[0].shape[0] > 0:
3399 for i in range(indDer[0].shape[0]):
3398 for i in range(indDer[0].shape[0]):
3400 signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i]])
3399 signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i]])
3401 angAllCCF[indDer[0][i],indDer[1][i]+1:] += signo*2*numpy.pi
3400 angAllCCF[indDer[0][i],indDer[1][i]+1:] += signo*2*numpy.pi
3402
3401
3403 # fit = scipy.stats.linregress(numpy.array([-2,-1,1,2])*timeInterval, numpy.array([phaseLagN2s[i],phaseLagN1s[i],phaseLag1s[i],phaseLag2s[i]]))
3402 # fit = scipy.stats.linregress(numpy.array([-2,-1,1,2])*timeInterval, numpy.array([phaseLagN2s[i],phaseLagN1s[i],phaseLag1s[i],phaseLag2s[i]]))
3404 for j in range(numPairs):
3403 for j in range(numPairs):
3405 fit = stats.linregress(time, angAllCCF[j,:])
3404 fit = stats.linregress(time, angAllCCF[j,:])
3406 slopes[j] = fit[0]
3405 slopes[j] = fit[0]
3407
3406
3408 #Remove Outlier
3407 #Remove Outlier
3409 # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes)))
3408 # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes)))
3410 # slopes = numpy.delete(slopes,indOut)
3409 # slopes = numpy.delete(slopes,indOut)
3411 # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes)))
3410 # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes)))
3412 # slopes = numpy.delete(slopes,indOut)
3411 # slopes = numpy.delete(slopes,indOut)
3413
3412
3414 radialVelocity = -numpy.mean(slopes)*(0.25/numpy.pi)*(c/freq)
3413 radialVelocity = -numpy.mean(slopes)*(0.25/numpy.pi)*(c/freq)
3415 radialError = numpy.std(slopes)*(0.25/numpy.pi)*(c/freq)
3414 radialError = numpy.std(slopes)*(0.25/numpy.pi)*(c/freq)
3416 meteorAux[-2] = radialError
3415 meteorAux[-2] = radialError
3417 meteorAux[-3] = radialVelocity
3416 meteorAux[-3] = radialVelocity
3418
3417
3419 #Setting Error
3418 #Setting Error
3420 #Number 15: Radial Drift velocity or projected horizontal velocity exceeds 200 m/s
3419 #Number 15: Radial Drift velocity or projected horizontal velocity exceeds 200 m/s
3421 if numpy.abs(radialVelocity) > 200:
3420 if numpy.abs(radialVelocity) > 200:
3422 meteorAux[-1] = 15
3421 meteorAux[-1] = 15
3423 #Number 12: Poor fit to CCF variation for estimation of radial drift velocity
3422 #Number 12: Poor fit to CCF variation for estimation of radial drift velocity
3424 elif radialError > radialStdThresh:
3423 elif radialError > radialStdThresh:
3425 meteorAux[-1] = 12
3424 meteorAux[-1] = 12
3426
3425
3427 listMeteors1.append(meteorAux)
3426 listMeteors1.append(meteorAux)
3428 return listMeteors1
3427 return listMeteors1
3429
3428
3430 def __setNewArrays(self, listMeteors, date, heiRang):
3429 def __setNewArrays(self, listMeteors, date, heiRang):
3431
3430
3432 #New arrays
3431 #New arrays
3433 arrayMeteors = numpy.array(listMeteors)
3432 arrayMeteors = numpy.array(listMeteors)
3434 arrayParameters = numpy.zeros((len(listMeteors), 13))
3433 arrayParameters = numpy.zeros((len(listMeteors), 13))
3435
3434
3436 #Date inclusion
3435 #Date inclusion
3437 # date = re.findall(r'\((.*?)\)', date)
3436 # date = re.findall(r'\((.*?)\)', date)
3438 # date = date[0].split(',')
3437 # date = date[0].split(',')
3439 # date = map(int, date)
3438 # date = map(int, date)
3440 #
3439 #
3441 # if len(date)<6:
3440 # if len(date)<6:
3442 # date.append(0)
3441 # date.append(0)
3443 #
3442 #
3444 # date = [date[0]*10000 + date[1]*100 + date[2], date[3]*10000 + date[4]*100 + date[5]]
3443 # date = [date[0]*10000 + date[1]*100 + date[2], date[3]*10000 + date[4]*100 + date[5]]
3445 # arrayDate = numpy.tile(date, (len(listMeteors), 1))
3444 # arrayDate = numpy.tile(date, (len(listMeteors), 1))
3446 arrayDate = numpy.tile(date, (len(listMeteors)))
3445 arrayDate = numpy.tile(date, (len(listMeteors)))
3447
3446
3448 #Meteor array
3447 #Meteor array
3449 # arrayMeteors[:,0] = heiRang[arrayMeteors[:,0].astype(int)]
3448 # arrayMeteors[:,0] = heiRang[arrayMeteors[:,0].astype(int)]
3450 # arrayMeteors = numpy.hstack((arrayDate, arrayMeteors))
3449 # arrayMeteors = numpy.hstack((arrayDate, arrayMeteors))
3451
3450
3452 #Parameters Array
3451 #Parameters Array
3453 arrayParameters[:,0] = arrayDate #Date
3452 arrayParameters[:,0] = arrayDate #Date
3454 arrayParameters[:,1] = heiRang[arrayMeteors[:,0].astype(int)] #Range
3453 arrayParameters[:,1] = heiRang[arrayMeteors[:,0].astype(int)] #Range
3455 arrayParameters[:,6:8] = arrayMeteors[:,-3:-1] #Radial velocity and its error
3454 arrayParameters[:,6:8] = arrayMeteors[:,-3:-1] #Radial velocity and its error
3456 arrayParameters[:,8:12] = arrayMeteors[:,7:11] #Phases
3455 arrayParameters[:,8:12] = arrayMeteors[:,7:11] #Phases
3457 arrayParameters[:,-1] = arrayMeteors[:,-1] #Error
3456 arrayParameters[:,-1] = arrayMeteors[:,-1] #Error
3458
3457
3459
3458
3460 return arrayParameters
3459 return arrayParameters
3461
3460
3462 class CorrectSMPhases(Operation):
3461 class CorrectSMPhases(Operation):
3463
3462
3464 def run(self, dataOut, phaseOffsets, hmin = 50, hmax = 150, azimuth = 45, channelPositions = None):
3463 def run(self, dataOut, phaseOffsets, hmin = 50, hmax = 150, azimuth = 45, channelPositions = None):
3465
3464
3466 arrayParameters = dataOut.data_param
3465 arrayParameters = dataOut.data_param
3467 pairsList = []
3466 pairsList = []
3468 pairx = (0,1)
3467 pairx = (0,1)
3469 pairy = (2,3)
3468 pairy = (2,3)
3470 pairsList.append(pairx)
3469 pairsList.append(pairx)
3471 pairsList.append(pairy)
3470 pairsList.append(pairy)
3472 jph = numpy.zeros(4)
3471 jph = numpy.zeros(4)
3473
3472
3474 phaseOffsets = numpy.array(phaseOffsets)*numpy.pi/180
3473 phaseOffsets = numpy.array(phaseOffsets)*numpy.pi/180
3475 # arrayParameters[:,8:12] = numpy.unwrap(arrayParameters[:,8:12] + phaseOffsets)
3474 # arrayParameters[:,8:12] = numpy.unwrap(arrayParameters[:,8:12] + phaseOffsets)
3476 arrayParameters[:,8:12] = numpy.angle(numpy.exp(1j*(arrayParameters[:,8:12] + phaseOffsets)))
3475 arrayParameters[:,8:12] = numpy.angle(numpy.exp(1j*(arrayParameters[:,8:12] + phaseOffsets)))
3477
3476
3478 meteorOps = SMOperations()
3477 meteorOps = SMOperations()
3479 if channelPositions == None:
3478 if channelPositions == None:
3480 # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T
3479 # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T
3481 channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella
3480 channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella
3482
3481
3483 pairslist0, distances = meteorOps.getPhasePairs(channelPositions)
3482 pairslist0, distances = meteorOps.getPhasePairs(channelPositions)
3484 h = (hmin,hmax)
3483 h = (hmin,hmax)
3485
3484
3486 arrayParameters = meteorOps.getMeteorParams(arrayParameters, azimuth, h, pairsList, distances, jph)
3485 arrayParameters = meteorOps.getMeteorParams(arrayParameters, azimuth, h, pairsList, distances, jph)
3487
3486
3488 dataOut.data_param = arrayParameters
3487 dataOut.data_param = arrayParameters
3489 return
3488 return
3490
3489
3491 class SMPhaseCalibration(Operation):
3490 class SMPhaseCalibration(Operation):
3492
3491
3493 __buffer = None
3492 __buffer = None
3494
3493
3495 __initime = None
3494 __initime = None
3496
3495
3497 __dataReady = False
3496 __dataReady = False
3498
3497
3499 __isConfig = False
3498 __isConfig = False
3500
3499
3501 def __checkTime(self, currentTime, initTime, paramInterval, outputInterval):
3500 def __checkTime(self, currentTime, initTime, paramInterval, outputInterval):
3502
3501
3503 dataTime = currentTime + paramInterval
3502 dataTime = currentTime + paramInterval
3504 deltaTime = dataTime - initTime
3503 deltaTime = dataTime - initTime
3505
3504
3506 if deltaTime >= outputInterval or deltaTime < 0:
3505 if deltaTime >= outputInterval or deltaTime < 0:
3507 return True
3506 return True
3508
3507
3509 return False
3508 return False
3510
3509
3511 def __getGammas(self, pairs, d, phases):
3510 def __getGammas(self, pairs, d, phases):
3512 gammas = numpy.zeros(2)
3511 gammas = numpy.zeros(2)
3513
3512
3514 for i in range(len(pairs)):
3513 for i in range(len(pairs)):
3515
3514
3516 pairi = pairs[i]
3515 pairi = pairs[i]
3517
3516
3518 phip3 = phases[:,pairi[0]]
3517 phip3 = phases[:,pairi[0]]
3519 d3 = d[pairi[0]]
3518 d3 = d[pairi[0]]
3520 phip2 = phases[:,pairi[1]]
3519 phip2 = phases[:,pairi[1]]
3521 d2 = d[pairi[1]]
3520 d2 = d[pairi[1]]
3522 #Calculating gamma
3521 #Calculating gamma
3523 # jdcos = alp1/(k*d1)
3522 # jdcos = alp1/(k*d1)
3524 # jgamma = numpy.angle(numpy.exp(1j*(d0*alp1/d1 - alp0)))
3523 # jgamma = numpy.angle(numpy.exp(1j*(d0*alp1/d1 - alp0)))
3525 jgamma = -phip2*d3/d2 - phip3
3524 jgamma = -phip2*d3/d2 - phip3
3526 jgamma = numpy.angle(numpy.exp(1j*jgamma))
3525 jgamma = numpy.angle(numpy.exp(1j*jgamma))
3527 # jgamma[jgamma>numpy.pi] -= 2*numpy.pi
3526 # jgamma[jgamma>numpy.pi] -= 2*numpy.pi
3528 # jgamma[jgamma<-numpy.pi] += 2*numpy.pi
3527 # jgamma[jgamma<-numpy.pi] += 2*numpy.pi
3529
3528
3530 #Revised distribution
3529 #Revised distribution
3531 jgammaArray = numpy.hstack((jgamma,jgamma+0.5*numpy.pi,jgamma-0.5*numpy.pi))
3530 jgammaArray = numpy.hstack((jgamma,jgamma+0.5*numpy.pi,jgamma-0.5*numpy.pi))
3532
3531
3533 #Histogram
3532 #Histogram
3534 nBins = 64
3533 nBins = 64
3535 rmin = -0.5*numpy.pi
3534 rmin = -0.5*numpy.pi
3536 rmax = 0.5*numpy.pi
3535 rmax = 0.5*numpy.pi
3537 phaseHisto = numpy.histogram(jgammaArray, bins=nBins, range=(rmin,rmax))
3536 phaseHisto = numpy.histogram(jgammaArray, bins=nBins, range=(rmin,rmax))
3538
3537
3539 meteorsY = phaseHisto[0]
3538 meteorsY = phaseHisto[0]
3540 phasesX = phaseHisto[1][:-1]
3539 phasesX = phaseHisto[1][:-1]
3541 width = phasesX[1] - phasesX[0]
3540 width = phasesX[1] - phasesX[0]
3542 phasesX += width/2
3541 phasesX += width/2
3543
3542
3544 #Gaussian aproximation
3543 #Gaussian aproximation
3545 bpeak = meteorsY.argmax()
3544 bpeak = meteorsY.argmax()
3546 peak = meteorsY.max()
3545 peak = meteorsY.max()
3547 jmin = bpeak - 5
3546 jmin = bpeak - 5
3548 jmax = bpeak + 5 + 1
3547 jmax = bpeak + 5 + 1
3549
3548
3550 if jmin<0:
3549 if jmin<0:
3551 jmin = 0
3550 jmin = 0
3552 jmax = 6
3551 jmax = 6
3553 elif jmax > meteorsY.size:
3552 elif jmax > meteorsY.size:
3554 jmin = meteorsY.size - 6
3553 jmin = meteorsY.size - 6
3555 jmax = meteorsY.size
3554 jmax = meteorsY.size
3556
3555
3557 x0 = numpy.array([peak,bpeak,50])
3556 x0 = numpy.array([peak,bpeak,50])
3558 coeff = optimize.leastsq(self.__residualFunction, x0, args=(meteorsY[jmin:jmax], phasesX[jmin:jmax]))
3557 coeff = optimize.leastsq(self.__residualFunction, x0, args=(meteorsY[jmin:jmax], phasesX[jmin:jmax]))
3559
3558
3560 #Gammas
3559 #Gammas
3561 gammas[i] = coeff[0][1]
3560 gammas[i] = coeff[0][1]
3562
3561
3563 return gammas
3562 return gammas
3564
3563
3565 def __residualFunction(self, coeffs, y, t):
3564 def __residualFunction(self, coeffs, y, t):
3566
3565
3567 return y - self.__gauss_function(t, coeffs)
3566 return y - self.__gauss_function(t, coeffs)
3568
3567
3569 def __gauss_function(self, t, coeffs):
3568 def __gauss_function(self, t, coeffs):
3570
3569
3571 return coeffs[0]*numpy.exp(-0.5*((t - coeffs[1]) / coeffs[2])**2)
3570 return coeffs[0]*numpy.exp(-0.5*((t - coeffs[1]) / coeffs[2])**2)
3572
3571
3573 def __getPhases(self, azimuth, h, pairsList, d, gammas, meteorsArray):
3572 def __getPhases(self, azimuth, h, pairsList, d, gammas, meteorsArray):
3574 meteorOps = SMOperations()
3573 meteorOps = SMOperations()
3575 nchan = 4
3574 nchan = 4
3576 pairx = pairsList[0] #x es 0
3575 pairx = pairsList[0] #x es 0
3577 pairy = pairsList[1] #y es 1
3576 pairy = pairsList[1] #y es 1
3578 center_xangle = 0
3577 center_xangle = 0
3579 center_yangle = 0
3578 center_yangle = 0
3580 range_angle = numpy.array([10*numpy.pi,numpy.pi,numpy.pi/2,numpy.pi/4])
3579 range_angle = numpy.array([10*numpy.pi,numpy.pi,numpy.pi/2,numpy.pi/4])
3581 ntimes = len(range_angle)
3580 ntimes = len(range_angle)
3582
3581
3583 nstepsx = 20
3582 nstepsx = 20
3584 nstepsy = 20
3583 nstepsy = 20
3585
3584
3586 for iz in range(ntimes):
3585 for iz in range(ntimes):
3587 min_xangle = -range_angle[iz]/2 + center_xangle
3586 min_xangle = -range_angle[iz]/2 + center_xangle
3588 max_xangle = range_angle[iz]/2 + center_xangle
3587 max_xangle = range_angle[iz]/2 + center_xangle
3589 min_yangle = -range_angle[iz]/2 + center_yangle
3588 min_yangle = -range_angle[iz]/2 + center_yangle
3590 max_yangle = range_angle[iz]/2 + center_yangle
3589 max_yangle = range_angle[iz]/2 + center_yangle
3591
3590
3592 inc_x = (max_xangle-min_xangle)/nstepsx
3591 inc_x = (max_xangle-min_xangle)/nstepsx
3593 inc_y = (max_yangle-min_yangle)/nstepsy
3592 inc_y = (max_yangle-min_yangle)/nstepsy
3594
3593
3595 alpha_y = numpy.arange(nstepsy)*inc_y + min_yangle
3594 alpha_y = numpy.arange(nstepsy)*inc_y + min_yangle
3596 alpha_x = numpy.arange(nstepsx)*inc_x + min_xangle
3595 alpha_x = numpy.arange(nstepsx)*inc_x + min_xangle
3597 penalty = numpy.zeros((nstepsx,nstepsy))
3596 penalty = numpy.zeros((nstepsx,nstepsy))
3598 jph_array = numpy.zeros((nchan,nstepsx,nstepsy))
3597 jph_array = numpy.zeros((nchan,nstepsx,nstepsy))
3599 jph = numpy.zeros(nchan)
3598 jph = numpy.zeros(nchan)
3600
3599
3601 # Iterations looking for the offset
3600 # Iterations looking for the offset
3602 for iy in range(int(nstepsy)):
3601 for iy in range(int(nstepsy)):
3603 for ix in range(int(nstepsx)):
3602 for ix in range(int(nstepsx)):
3604 d3 = d[pairsList[1][0]]
3603 d3 = d[pairsList[1][0]]
3605 d2 = d[pairsList[1][1]]
3604 d2 = d[pairsList[1][1]]
3606 d5 = d[pairsList[0][0]]
3605 d5 = d[pairsList[0][0]]
3607 d4 = d[pairsList[0][1]]
3606 d4 = d[pairsList[0][1]]
3608
3607
3609 alp2 = alpha_y[iy] #gamma 1
3608 alp2 = alpha_y[iy] #gamma 1
3610 alp4 = alpha_x[ix] #gamma 0
3609 alp4 = alpha_x[ix] #gamma 0
3611
3610
3612 alp3 = -alp2*d3/d2 - gammas[1]
3611 alp3 = -alp2*d3/d2 - gammas[1]
3613 alp5 = -alp4*d5/d4 - gammas[0]
3612 alp5 = -alp4*d5/d4 - gammas[0]
3614 # jph[pairy[1]] = alpha_y[iy]
3613 # jph[pairy[1]] = alpha_y[iy]
3615 # jph[pairy[0]] = -gammas[1] - alpha_y[iy]*d[pairy[1]]/d[pairy[0]]
3614 # jph[pairy[0]] = -gammas[1] - alpha_y[iy]*d[pairy[1]]/d[pairy[0]]
3616
3615
3617 # jph[pairx[1]] = alpha_x[ix]
3616 # jph[pairx[1]] = alpha_x[ix]
3618 # jph[pairx[0]] = -gammas[0] - alpha_x[ix]*d[pairx[1]]/d[pairx[0]]
3617 # jph[pairx[0]] = -gammas[0] - alpha_x[ix]*d[pairx[1]]/d[pairx[0]]
3619 jph[pairsList[0][1]] = alp4
3618 jph[pairsList[0][1]] = alp4
3620 jph[pairsList[0][0]] = alp5
3619 jph[pairsList[0][0]] = alp5
3621 jph[pairsList[1][0]] = alp3
3620 jph[pairsList[1][0]] = alp3
3622 jph[pairsList[1][1]] = alp2
3621 jph[pairsList[1][1]] = alp2
3623 jph_array[:,ix,iy] = jph
3622 jph_array[:,ix,iy] = jph
3624 # d = [2.0,2.5,2.5,2.0]
3623 # d = [2.0,2.5,2.5,2.0]
3625 #falta chequear si va a leer bien los meteoros
3624 #falta chequear si va a leer bien los meteoros
3626 meteorsArray1 = meteorOps.getMeteorParams(meteorsArray, azimuth, h, pairsList, d, jph)
3625 meteorsArray1 = meteorOps.getMeteorParams(meteorsArray, azimuth, h, pairsList, d, jph)
3627 error = meteorsArray1[:,-1]
3626 error = meteorsArray1[:,-1]
3628 ind1 = numpy.where(error==0)[0]
3627 ind1 = numpy.where(error==0)[0]
3629 penalty[ix,iy] = ind1.size
3628 penalty[ix,iy] = ind1.size
3630
3629
3631 i,j = numpy.unravel_index(penalty.argmax(), penalty.shape)
3630 i,j = numpy.unravel_index(penalty.argmax(), penalty.shape)
3632 phOffset = jph_array[:,i,j]
3631 phOffset = jph_array[:,i,j]
3633
3632
3634 center_xangle = phOffset[pairx[1]]
3633 center_xangle = phOffset[pairx[1]]
3635 center_yangle = phOffset[pairy[1]]
3634 center_yangle = phOffset[pairy[1]]
3636
3635
3637 phOffset = numpy.angle(numpy.exp(1j*jph_array[:,i,j]))
3636 phOffset = numpy.angle(numpy.exp(1j*jph_array[:,i,j]))
3638 phOffset = phOffset*180/numpy.pi
3637 phOffset = phOffset*180/numpy.pi
3639 return phOffset
3638 return phOffset
3640
3639
3641
3640
3642 def run(self, dataOut, hmin, hmax, channelPositions=None, nHours = 1):
3641 def run(self, dataOut, hmin, hmax, channelPositions=None, nHours = 1):
3643
3642
3644 dataOut.flagNoData = True
3643 dataOut.flagNoData = True
3645 self.__dataReady = False
3644 self.__dataReady = False
3646 dataOut.outputInterval = nHours*3600
3645 dataOut.outputInterval = nHours*3600
3647
3646
3648 if self.__isConfig == False:
3647 if self.__isConfig == False:
3649 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
3648 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
3650 #Get Initial LTC time
3649 #Get Initial LTC time
3651 self.__initime = datetime.datetime.utcfromtimestamp(dataOut.utctime)
3650 self.__initime = datetime.datetime.utcfromtimestamp(dataOut.utctime)
3652 self.__initime = (self.__initime.replace(minute = 0, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
3651 self.__initime = (self.__initime.replace(minute = 0, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
3653
3652
3654 self.__isConfig = True
3653 self.__isConfig = True
3655
3654
3656 if self.__buffer == None:
3655 if self.__buffer == None:
3657 self.__buffer = dataOut.data_param.copy()
3656 self.__buffer = dataOut.data_param.copy()
3658
3657
3659 else:
3658 else:
3660 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
3659 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
3661
3660
3662 self.__dataReady = self.__checkTime(dataOut.utctime, self.__initime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
3661 self.__dataReady = self.__checkTime(dataOut.utctime, self.__initime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
3663
3662
3664 if self.__dataReady:
3663 if self.__dataReady:
3665 dataOut.utctimeInit = self.__initime
3664 dataOut.utctimeInit = self.__initime
3666 self.__initime += dataOut.outputInterval #to erase time offset
3665 self.__initime += dataOut.outputInterval #to erase time offset
3667
3666
3668 freq = dataOut.frequency
3667 freq = dataOut.frequency
3669 c = dataOut.C #m/s
3668 c = dataOut.C #m/s
3670 lamb = c/freq
3669 lamb = c/freq
3671 k = 2*numpy.pi/lamb
3670 k = 2*numpy.pi/lamb
3672 azimuth = 0
3671 azimuth = 0
3673 h = (hmin, hmax)
3672 h = (hmin, hmax)
3674 # pairs = ((0,1),(2,3)) #Estrella
3673 # pairs = ((0,1),(2,3)) #Estrella
3675 # pairs = ((1,0),(2,3)) #T
3674 # pairs = ((1,0),(2,3)) #T
3676
3675
3677 if channelPositions is None:
3676 if channelPositions is None:
3678 # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T
3677 # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T
3679 channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella
3678 channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella
3680 meteorOps = SMOperations()
3679 meteorOps = SMOperations()
3681 pairslist0, distances = meteorOps.getPhasePairs(channelPositions)
3680 pairslist0, distances = meteorOps.getPhasePairs(channelPositions)
3682
3681
3683 #Checking correct order of pairs
3682 #Checking correct order of pairs
3684 pairs = []
3683 pairs = []
3685 if distances[1] > distances[0]:
3684 if distances[1] > distances[0]:
3686 pairs.append((1,0))
3685 pairs.append((1,0))
3687 else:
3686 else:
3688 pairs.append((0,1))
3687 pairs.append((0,1))
3689
3688
3690 if distances[3] > distances[2]:
3689 if distances[3] > distances[2]:
3691 pairs.append((3,2))
3690 pairs.append((3,2))
3692 else:
3691 else:
3693 pairs.append((2,3))
3692 pairs.append((2,3))
3694 # distances1 = [-distances[0]*lamb, distances[1]*lamb, -distances[2]*lamb, distances[3]*lamb]
3693 # distances1 = [-distances[0]*lamb, distances[1]*lamb, -distances[2]*lamb, distances[3]*lamb]
3695
3694
3696 meteorsArray = self.__buffer
3695 meteorsArray = self.__buffer
3697 error = meteorsArray[:,-1]
3696 error = meteorsArray[:,-1]
3698 boolError = (error==0)|(error==3)|(error==4)|(error==13)|(error==14)
3697 boolError = (error==0)|(error==3)|(error==4)|(error==13)|(error==14)
3699 ind1 = numpy.where(boolError)[0]
3698 ind1 = numpy.where(boolError)[0]
3700 meteorsArray = meteorsArray[ind1,:]
3699 meteorsArray = meteorsArray[ind1,:]
3701 meteorsArray[:,-1] = 0
3700 meteorsArray[:,-1] = 0
3702 phases = meteorsArray[:,8:12]
3701 phases = meteorsArray[:,8:12]
3703
3702
3704 #Calculate Gammas
3703 #Calculate Gammas
3705 gammas = self.__getGammas(pairs, distances, phases)
3704 gammas = self.__getGammas(pairs, distances, phases)
3706 # gammas = numpy.array([-21.70409463,45.76935864])*numpy.pi/180
3705 # gammas = numpy.array([-21.70409463,45.76935864])*numpy.pi/180
3707 #Calculate Phases
3706 #Calculate Phases
3708 phasesOff = self.__getPhases(azimuth, h, pairs, distances, gammas, meteorsArray)
3707 phasesOff = self.__getPhases(azimuth, h, pairs, distances, gammas, meteorsArray)
3709 phasesOff = phasesOff.reshape((1,phasesOff.size))
3708 phasesOff = phasesOff.reshape((1,phasesOff.size))
3710 dataOut.data_output = -phasesOff
3709 dataOut.data_output = -phasesOff
3711 dataOut.flagNoData = False
3710 dataOut.flagNoData = False
3712 self.__buffer = None
3711 self.__buffer = None
3713
3712
3714
3713
3715 return
3714 return
3716
3715
3717 class SMOperations():
3716 class SMOperations():
3718
3717
3719 def __init__(self):
3718 def __init__(self):
3720
3719
3721 return
3720 return
3722
3721
3723 def getMeteorParams(self, arrayParameters0, azimuth, h, pairsList, distances, jph):
3722 def getMeteorParams(self, arrayParameters0, azimuth, h, pairsList, distances, jph):
3724
3723
3725 arrayParameters = arrayParameters0.copy()
3724 arrayParameters = arrayParameters0.copy()
3726 hmin = h[0]
3725 hmin = h[0]
3727 hmax = h[1]
3726 hmax = h[1]
3728
3727
3729 #Calculate AOA (Error N 3, 4)
3728 #Calculate AOA (Error N 3, 4)
3730 #JONES ET AL. 1998
3729 #JONES ET AL. 1998
3731 AOAthresh = numpy.pi/8
3730 AOAthresh = numpy.pi/8
3732 error = arrayParameters[:,-1]
3731 error = arrayParameters[:,-1]
3733 phases = -arrayParameters[:,8:12] + jph
3732 phases = -arrayParameters[:,8:12] + jph
3734 # phases = numpy.unwrap(phases)
3733 # phases = numpy.unwrap(phases)
3735 arrayParameters[:,3:6], arrayParameters[:,-1] = self.__getAOA(phases, pairsList, distances, error, AOAthresh, azimuth)
3734 arrayParameters[:,3:6], arrayParameters[:,-1] = self.__getAOA(phases, pairsList, distances, error, AOAthresh, azimuth)
3736
3735
3737 #Calculate Heights (Error N 13 and 14)
3736 #Calculate Heights (Error N 13 and 14)
3738 error = arrayParameters[:,-1]
3737 error = arrayParameters[:,-1]
3739 Ranges = arrayParameters[:,1]
3738 Ranges = arrayParameters[:,1]
3740 zenith = arrayParameters[:,4]
3739 zenith = arrayParameters[:,4]
3741 arrayParameters[:,2], arrayParameters[:,-1] = self.__getHeights(Ranges, zenith, error, hmin, hmax)
3740 arrayParameters[:,2], arrayParameters[:,-1] = self.__getHeights(Ranges, zenith, error, hmin, hmax)
3742
3741
3743 #----------------------- Get Final data ------------------------------------
3742 #----------------------- Get Final data ------------------------------------
3744 # error = arrayParameters[:,-1]
3743 # error = arrayParameters[:,-1]
3745 # ind1 = numpy.where(error==0)[0]
3744 # ind1 = numpy.where(error==0)[0]
3746 # arrayParameters = arrayParameters[ind1,:]
3745 # arrayParameters = arrayParameters[ind1,:]
3747
3746
3748 return arrayParameters
3747 return arrayParameters
3749
3748
3750 def __getAOA(self, phases, pairsList, directions, error, AOAthresh, azimuth):
3749 def __getAOA(self, phases, pairsList, directions, error, AOAthresh, azimuth):
3751
3750
3752 arrayAOA = numpy.zeros((phases.shape[0],3))
3751 arrayAOA = numpy.zeros((phases.shape[0],3))
3753 cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList,directions)
3752 cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList,directions)
3754
3753
3755 arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth)
3754 arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth)
3756 cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1)
3755 cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1)
3757 arrayAOA[:,2] = cosDirError
3756 arrayAOA[:,2] = cosDirError
3758
3757
3759 azimuthAngle = arrayAOA[:,0]
3758 azimuthAngle = arrayAOA[:,0]
3760 zenithAngle = arrayAOA[:,1]
3759 zenithAngle = arrayAOA[:,1]
3761
3760
3762 #Setting Error
3761 #Setting Error
3763 indError = numpy.where(numpy.logical_or(error == 3, error == 4))[0]
3762 indError = numpy.where(numpy.logical_or(error == 3, error == 4))[0]
3764 error[indError] = 0
3763 error[indError] = 0
3765 #Number 3: AOA not fesible
3764 #Number 3: AOA not fesible
3766 indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0]
3765 indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0]
3767 error[indInvalid] = 3
3766 error[indInvalid] = 3
3768 #Number 4: Large difference in AOAs obtained from different antenna baselines
3767 #Number 4: Large difference in AOAs obtained from different antenna baselines
3769 indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0]
3768 indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0]
3770 error[indInvalid] = 4
3769 error[indInvalid] = 4
3771 return arrayAOA, error
3770 return arrayAOA, error
3772
3771
3773 def __getDirectionCosines(self, arrayPhase, pairsList, distances):
3772 def __getDirectionCosines(self, arrayPhase, pairsList, distances):
3774
3773
3775 #Initializing some variables
3774 #Initializing some variables
3776 ang_aux = numpy.array([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])*2*numpy.pi
3775 ang_aux = numpy.array([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])*2*numpy.pi
3777 ang_aux = ang_aux.reshape(1,ang_aux.size)
3776 ang_aux = ang_aux.reshape(1,ang_aux.size)
3778
3777
3779 cosdir = numpy.zeros((arrayPhase.shape[0],2))
3778 cosdir = numpy.zeros((arrayPhase.shape[0],2))
3780 cosdir0 = numpy.zeros((arrayPhase.shape[0],2))
3779 cosdir0 = numpy.zeros((arrayPhase.shape[0],2))
3781
3780
3782
3781
3783 for i in range(2):
3782 for i in range(2):
3784 ph0 = arrayPhase[:,pairsList[i][0]]
3783 ph0 = arrayPhase[:,pairsList[i][0]]
3785 ph1 = arrayPhase[:,pairsList[i][1]]
3784 ph1 = arrayPhase[:,pairsList[i][1]]
3786 d0 = distances[pairsList[i][0]]
3785 d0 = distances[pairsList[i][0]]
3787 d1 = distances[pairsList[i][1]]
3786 d1 = distances[pairsList[i][1]]
3788
3787
3789 ph0_aux = ph0 + ph1
3788 ph0_aux = ph0 + ph1
3790 ph0_aux = numpy.angle(numpy.exp(1j*ph0_aux))
3789 ph0_aux = numpy.angle(numpy.exp(1j*ph0_aux))
3791 # ph0_aux[ph0_aux > numpy.pi] -= 2*numpy.pi
3790 # ph0_aux[ph0_aux > numpy.pi] -= 2*numpy.pi
3792 # ph0_aux[ph0_aux < -numpy.pi] += 2*numpy.pi
3791 # ph0_aux[ph0_aux < -numpy.pi] += 2*numpy.pi
3793 #First Estimation
3792 #First Estimation
3794 cosdir0[:,i] = (ph0_aux)/(2*numpy.pi*(d0 - d1))
3793 cosdir0[:,i] = (ph0_aux)/(2*numpy.pi*(d0 - d1))
3795
3794
3796 #Most-Accurate Second Estimation
3795 #Most-Accurate Second Estimation
3797 phi1_aux = ph0 - ph1
3796 phi1_aux = ph0 - ph1
3798 phi1_aux = phi1_aux.reshape(phi1_aux.size,1)
3797 phi1_aux = phi1_aux.reshape(phi1_aux.size,1)
3799 #Direction Cosine 1
3798 #Direction Cosine 1
3800 cosdir1 = (phi1_aux + ang_aux)/(2*numpy.pi*(d0 + d1))
3799 cosdir1 = (phi1_aux + ang_aux)/(2*numpy.pi*(d0 + d1))
3801
3800
3802 #Searching the correct Direction Cosine
3801 #Searching the correct Direction Cosine
3803 cosdir0_aux = cosdir0[:,i]
3802 cosdir0_aux = cosdir0[:,i]
3804 cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1)
3803 cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1)
3805 #Minimum Distance
3804 #Minimum Distance
3806 cosDiff = (cosdir1 - cosdir0_aux)**2
3805 cosDiff = (cosdir1 - cosdir0_aux)**2
3807 indcos = cosDiff.argmin(axis = 1)
3806 indcos = cosDiff.argmin(axis = 1)
3808 #Saving Value obtained
3807 #Saving Value obtained
3809 cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos]
3808 cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos]
3810
3809
3811 return cosdir0, cosdir
3810 return cosdir0, cosdir
3812
3811
3813 def __calculateAOA(self, cosdir, azimuth):
3812 def __calculateAOA(self, cosdir, azimuth):
3814 cosdirX = cosdir[:,0]
3813 cosdirX = cosdir[:,0]
3815 cosdirY = cosdir[:,1]
3814 cosdirY = cosdir[:,1]
3816
3815
3817 zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi
3816 zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi
3818 azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth#0 deg north, 90 deg east
3817 azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth#0 deg north, 90 deg east
3819 angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose()
3818 angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose()
3820
3819
3821 return angles
3820 return angles
3822
3821
3823 def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight):
3822 def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight):
3824
3823
3825 Ramb = 375 #Ramb = c/(2*PRF)
3824 Ramb = 375 #Ramb = c/(2*PRF)
3826 Re = 6371 #Earth Radius
3825 Re = 6371 #Earth Radius
3827 heights = numpy.zeros(Ranges.shape)
3826 heights = numpy.zeros(Ranges.shape)
3828
3827
3829 R_aux = numpy.array([0,1,2])*Ramb
3828 R_aux = numpy.array([0,1,2])*Ramb
3830 R_aux = R_aux.reshape(1,R_aux.size)
3829 R_aux = R_aux.reshape(1,R_aux.size)
3831
3830
3832 Ranges = Ranges.reshape(Ranges.size,1)
3831 Ranges = Ranges.reshape(Ranges.size,1)
3833
3832
3834 Ri = Ranges + R_aux
3833 Ri = Ranges + R_aux
3835 hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re
3834 hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re
3836
3835
3837 #Check if there is a height between 70 and 110 km
3836 #Check if there is a height between 70 and 110 km
3838 h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1)
3837 h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1)
3839 ind_h = numpy.where(h_bool == 1)[0]
3838 ind_h = numpy.where(h_bool == 1)[0]
3840
3839
3841 hCorr = hi[ind_h, :]
3840 hCorr = hi[ind_h, :]
3842 ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight))
3841 ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight))
3843
3842
3844 hCorr = hi[ind_hCorr][:len(ind_h)]
3843 hCorr = hi[ind_hCorr][:len(ind_h)]
3845 heights[ind_h] = hCorr
3844 heights[ind_h] = hCorr
3846
3845
3847 #Setting Error
3846 #Setting Error
3848 #Number 13: Height unresolvable echo: not valid height within 70 to 110 km
3847 #Number 13: Height unresolvable echo: not valid height within 70 to 110 km
3849 #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km
3848 #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km
3850 indError = numpy.where(numpy.logical_or(error == 13, error == 14))[0]
3849 indError = numpy.where(numpy.logical_or(error == 13, error == 14))[0]
3851 error[indError] = 0
3850 error[indError] = 0
3852 indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0]
3851 indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0]
3853 error[indInvalid2] = 14
3852 error[indInvalid2] = 14
3854 indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0]
3853 indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0]
3855 error[indInvalid1] = 13
3854 error[indInvalid1] = 13
3856
3855
3857 return heights, error
3856 return heights, error
3858
3857
3859 def getPhasePairs(self, channelPositions):
3858 def getPhasePairs(self, channelPositions):
3860 chanPos = numpy.array(channelPositions)
3859 chanPos = numpy.array(channelPositions)
3861 listOper = list(itertools.combinations(range(5),2))
3860 listOper = list(itertools.combinations(range(5),2))
3862
3861
3863 distances = numpy.zeros(4)
3862 distances = numpy.zeros(4)
3864 axisX = []
3863 axisX = []
3865 axisY = []
3864 axisY = []
3866 distX = numpy.zeros(3)
3865 distX = numpy.zeros(3)
3867 distY = numpy.zeros(3)
3866 distY = numpy.zeros(3)
3868 ix = 0
3867 ix = 0
3869 iy = 0
3868 iy = 0
3870
3869
3871 pairX = numpy.zeros((2,2))
3870 pairX = numpy.zeros((2,2))
3872 pairY = numpy.zeros((2,2))
3871 pairY = numpy.zeros((2,2))
3873
3872
3874 for i in range(len(listOper)):
3873 for i in range(len(listOper)):
3875 pairi = listOper[i]
3874 pairi = listOper[i]
3876
3875
3877 posDif = numpy.abs(chanPos[pairi[0],:] - chanPos[pairi[1],:])
3876 posDif = numpy.abs(chanPos[pairi[0],:] - chanPos[pairi[1],:])
3878
3877
3879 if posDif[0] == 0:
3878 if posDif[0] == 0:
3880 axisY.append(pairi)
3879 axisY.append(pairi)
3881 distY[iy] = posDif[1]
3880 distY[iy] = posDif[1]
3882 iy += 1
3881 iy += 1
3883 elif posDif[1] == 0:
3882 elif posDif[1] == 0:
3884 axisX.append(pairi)
3883 axisX.append(pairi)
3885 distX[ix] = posDif[0]
3884 distX[ix] = posDif[0]
3886 ix += 1
3885 ix += 1
3887
3886
3888 for i in range(2):
3887 for i in range(2):
3889 if i==0:
3888 if i==0:
3890 dist0 = distX
3889 dist0 = distX
3891 axis0 = axisX
3890 axis0 = axisX
3892 else:
3891 else:
3893 dist0 = distY
3892 dist0 = distY
3894 axis0 = axisY
3893 axis0 = axisY
3895
3894
3896 side = numpy.argsort(dist0)[:-1]
3895 side = numpy.argsort(dist0)[:-1]
3897 axis0 = numpy.array(axis0)[side,:]
3896 axis0 = numpy.array(axis0)[side,:]
3898 chanC = int(numpy.intersect1d(axis0[0,:], axis0[1,:])[0])
3897 chanC = int(numpy.intersect1d(axis0[0,:], axis0[1,:])[0])
3899 axis1 = numpy.unique(numpy.reshape(axis0,4))
3898 axis1 = numpy.unique(numpy.reshape(axis0,4))
3900 side = axis1[axis1 != chanC]
3899 side = axis1[axis1 != chanC]
3901 diff1 = chanPos[chanC,i] - chanPos[side[0],i]
3900 diff1 = chanPos[chanC,i] - chanPos[side[0],i]
3902 diff2 = chanPos[chanC,i] - chanPos[side[1],i]
3901 diff2 = chanPos[chanC,i] - chanPos[side[1],i]
3903 if diff1<0:
3902 if diff1<0:
3904 chan2 = side[0]
3903 chan2 = side[0]
3905 d2 = numpy.abs(diff1)
3904 d2 = numpy.abs(diff1)
3906 chan1 = side[1]
3905 chan1 = side[1]
3907 d1 = numpy.abs(diff2)
3906 d1 = numpy.abs(diff2)
3908 else:
3907 else:
3909 chan2 = side[1]
3908 chan2 = side[1]
3910 d2 = numpy.abs(diff2)
3909 d2 = numpy.abs(diff2)
3911 chan1 = side[0]
3910 chan1 = side[0]
3912 d1 = numpy.abs(diff1)
3911 d1 = numpy.abs(diff1)
3913
3912
3914 if i==0:
3913 if i==0:
3915 chanCX = chanC
3914 chanCX = chanC
3916 chan1X = chan1
3915 chan1X = chan1
3917 chan2X = chan2
3916 chan2X = chan2
3918 distances[0:2] = numpy.array([d1,d2])
3917 distances[0:2] = numpy.array([d1,d2])
3919 else:
3918 else:
3920 chanCY = chanC
3919 chanCY = chanC
3921 chan1Y = chan1
3920 chan1Y = chan1
3922 chan2Y = chan2
3921 chan2Y = chan2
3923 distances[2:4] = numpy.array([d1,d2])
3922 distances[2:4] = numpy.array([d1,d2])
3924 # axisXsides = numpy.reshape(axisX[ix,:],4)
3923 # axisXsides = numpy.reshape(axisX[ix,:],4)
3925 #
3924 #
3926 # channelCentX = int(numpy.intersect1d(pairX[0,:], pairX[1,:])[0])
3925 # channelCentX = int(numpy.intersect1d(pairX[0,:], pairX[1,:])[0])
3927 # channelCentY = int(numpy.intersect1d(pairY[0,:], pairY[1,:])[0])
3926 # channelCentY = int(numpy.intersect1d(pairY[0,:], pairY[1,:])[0])
3928 #
3927 #
3929 # ind25X = numpy.where(pairX[0,:] != channelCentX)[0][0]
3928 # ind25X = numpy.where(pairX[0,:] != channelCentX)[0][0]
3930 # ind20X = numpy.where(pairX[1,:] != channelCentX)[0][0]
3929 # ind20X = numpy.where(pairX[1,:] != channelCentX)[0][0]
3931 # channel25X = int(pairX[0,ind25X])
3930 # channel25X = int(pairX[0,ind25X])
3932 # channel20X = int(pairX[1,ind20X])
3931 # channel20X = int(pairX[1,ind20X])
3933 # ind25Y = numpy.where(pairY[0,:] != channelCentY)[0][0]
3932 # ind25Y = numpy.where(pairY[0,:] != channelCentY)[0][0]
3934 # ind20Y = numpy.where(pairY[1,:] != channelCentY)[0][0]
3933 # ind20Y = numpy.where(pairY[1,:] != channelCentY)[0][0]
3935 # channel25Y = int(pairY[0,ind25Y])
3934 # channel25Y = int(pairY[0,ind25Y])
3936 # channel20Y = int(pairY[1,ind20Y])
3935 # channel20Y = int(pairY[1,ind20Y])
3937
3936
3938 # pairslist = [(channelCentX, channel25X),(channelCentX, channel20X),(channelCentY,channel25Y),(channelCentY, channel20Y)]
3937 # pairslist = [(channelCentX, channel25X),(channelCentX, channel20X),(channelCentY,channel25Y),(channelCentY, channel20Y)]
3939 pairslist = [(chanCX, chan1X),(chanCX, chan2X),(chanCY,chan1Y),(chanCY, chan2Y)]
3938 pairslist = [(chanCX, chan1X),(chanCX, chan2X),(chanCY,chan1Y),(chanCY, chan2Y)]
3940
3939
3941 return pairslist, distances
3940 return pairslist, distances
3942 # def __getAOA(self, phases, pairsList, error, AOAthresh, azimuth):
3941 # def __getAOA(self, phases, pairsList, error, AOAthresh, azimuth):
3943 #
3942 #
3944 # arrayAOA = numpy.zeros((phases.shape[0],3))
3943 # arrayAOA = numpy.zeros((phases.shape[0],3))
3945 # cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList)
3944 # cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList)
3946 #
3945 #
3947 # arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth)
3946 # arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth)
3948 # cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1)
3947 # cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1)
3949 # arrayAOA[:,2] = cosDirError
3948 # arrayAOA[:,2] = cosDirError
3950 #
3949 #
3951 # azimuthAngle = arrayAOA[:,0]
3950 # azimuthAngle = arrayAOA[:,0]
3952 # zenithAngle = arrayAOA[:,1]
3951 # zenithAngle = arrayAOA[:,1]
3953 #
3952 #
3954 # #Setting Error
3953 # #Setting Error
3955 # #Number 3: AOA not fesible
3954 # #Number 3: AOA not fesible
3956 # indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0]
3955 # indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0]
3957 # error[indInvalid] = 3
3956 # error[indInvalid] = 3
3958 # #Number 4: Large difference in AOAs obtained from different antenna baselines
3957 # #Number 4: Large difference in AOAs obtained from different antenna baselines
3959 # indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0]
3958 # indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0]
3960 # error[indInvalid] = 4
3959 # error[indInvalid] = 4
3961 # return arrayAOA, error
3960 # return arrayAOA, error
3962 #
3961 #
3963 # def __getDirectionCosines(self, arrayPhase, pairsList):
3962 # def __getDirectionCosines(self, arrayPhase, pairsList):
3964 #
3963 #
3965 # #Initializing some variables
3964 # #Initializing some variables
3966 # ang_aux = numpy.array([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])*2*numpy.pi
3965 # ang_aux = numpy.array([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])*2*numpy.pi
3967 # ang_aux = ang_aux.reshape(1,ang_aux.size)
3966 # ang_aux = ang_aux.reshape(1,ang_aux.size)
3968 #
3967 #
3969 # cosdir = numpy.zeros((arrayPhase.shape[0],2))
3968 # cosdir = numpy.zeros((arrayPhase.shape[0],2))
3970 # cosdir0 = numpy.zeros((arrayPhase.shape[0],2))
3969 # cosdir0 = numpy.zeros((arrayPhase.shape[0],2))
3971 #
3970 #
3972 #
3971 #
3973 # for i in range(2):
3972 # for i in range(2):
3974 # #First Estimation
3973 # #First Estimation
3975 # phi0_aux = arrayPhase[:,pairsList[i][0]] + arrayPhase[:,pairsList[i][1]]
3974 # phi0_aux = arrayPhase[:,pairsList[i][0]] + arrayPhase[:,pairsList[i][1]]
3976 # #Dealias
3975 # #Dealias
3977 # indcsi = numpy.where(phi0_aux > numpy.pi)
3976 # indcsi = numpy.where(phi0_aux > numpy.pi)
3978 # phi0_aux[indcsi] -= 2*numpy.pi
3977 # phi0_aux[indcsi] -= 2*numpy.pi
3979 # indcsi = numpy.where(phi0_aux < -numpy.pi)
3978 # indcsi = numpy.where(phi0_aux < -numpy.pi)
3980 # phi0_aux[indcsi] += 2*numpy.pi
3979 # phi0_aux[indcsi] += 2*numpy.pi
3981 # #Direction Cosine 0
3980 # #Direction Cosine 0
3982 # cosdir0[:,i] = -(phi0_aux)/(2*numpy.pi*0.5)
3981 # cosdir0[:,i] = -(phi0_aux)/(2*numpy.pi*0.5)
3983 #
3982 #
3984 # #Most-Accurate Second Estimation
3983 # #Most-Accurate Second Estimation
3985 # phi1_aux = arrayPhase[:,pairsList[i][0]] - arrayPhase[:,pairsList[i][1]]
3984 # phi1_aux = arrayPhase[:,pairsList[i][0]] - arrayPhase[:,pairsList[i][1]]
3986 # phi1_aux = phi1_aux.reshape(phi1_aux.size,1)
3985 # phi1_aux = phi1_aux.reshape(phi1_aux.size,1)
3987 # #Direction Cosine 1
3986 # #Direction Cosine 1
3988 # cosdir1 = -(phi1_aux + ang_aux)/(2*numpy.pi*4.5)
3987 # cosdir1 = -(phi1_aux + ang_aux)/(2*numpy.pi*4.5)
3989 #
3988 #
3990 # #Searching the correct Direction Cosine
3989 # #Searching the correct Direction Cosine
3991 # cosdir0_aux = cosdir0[:,i]
3990 # cosdir0_aux = cosdir0[:,i]
3992 # cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1)
3991 # cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1)
3993 # #Minimum Distance
3992 # #Minimum Distance
3994 # cosDiff = (cosdir1 - cosdir0_aux)**2
3993 # cosDiff = (cosdir1 - cosdir0_aux)**2
3995 # indcos = cosDiff.argmin(axis = 1)
3994 # indcos = cosDiff.argmin(axis = 1)
3996 # #Saving Value obtained
3995 # #Saving Value obtained
3997 # cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos]
3996 # cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos]
3998 #
3997 #
3999 # return cosdir0, cosdir
3998 # return cosdir0, cosdir
4000 #
3999 #
4001 # def __calculateAOA(self, cosdir, azimuth):
4000 # def __calculateAOA(self, cosdir, azimuth):
4002 # cosdirX = cosdir[:,0]
4001 # cosdirX = cosdir[:,0]
4003 # cosdirY = cosdir[:,1]
4002 # cosdirY = cosdir[:,1]
4004 #
4003 #
4005 # zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi
4004 # zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi
4006 # azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth #0 deg north, 90 deg east
4005 # azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth #0 deg north, 90 deg east
4007 # angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose()
4006 # angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose()
4008 #
4007 #
4009 # return angles
4008 # return angles
4010 #
4009 #
4011 # def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight):
4010 # def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight):
4012 #
4011 #
4013 # Ramb = 375 #Ramb = c/(2*PRF)
4012 # Ramb = 375 #Ramb = c/(2*PRF)
4014 # Re = 6371 #Earth Radius
4013 # Re = 6371 #Earth Radius
4015 # heights = numpy.zeros(Ranges.shape)
4014 # heights = numpy.zeros(Ranges.shape)
4016 #
4015 #
4017 # R_aux = numpy.array([0,1,2])*Ramb
4016 # R_aux = numpy.array([0,1,2])*Ramb
4018 # R_aux = R_aux.reshape(1,R_aux.size)
4017 # R_aux = R_aux.reshape(1,R_aux.size)
4019 #
4018 #
4020 # Ranges = Ranges.reshape(Ranges.size,1)
4019 # Ranges = Ranges.reshape(Ranges.size,1)
4021 #
4020 #
4022 # Ri = Ranges + R_aux
4021 # Ri = Ranges + R_aux
4023 # hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re
4022 # hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re
4024 #
4023 #
4025 # #Check if there is a height between 70 and 110 km
4024 # #Check if there is a height between 70 and 110 km
4026 # h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1)
4025 # h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1)
4027 # ind_h = numpy.where(h_bool == 1)[0]
4026 # ind_h = numpy.where(h_bool == 1)[0]
4028 #
4027 #
4029 # hCorr = hi[ind_h, :]
4028 # hCorr = hi[ind_h, :]
4030 # ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight))
4029 # ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight))
4031 #
4030 #
4032 # hCorr = hi[ind_hCorr]
4031 # hCorr = hi[ind_hCorr]
4033 # heights[ind_h] = hCorr
4032 # heights[ind_h] = hCorr
4034 #
4033 #
4035 # #Setting Error
4034 # #Setting Error
4036 # #Number 13: Height unresolvable echo: not valid height within 70 to 110 km
4035 # #Number 13: Height unresolvable echo: not valid height within 70 to 110 km
4037 # #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km
4036 # #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km
4038 #
4037 #
4039 # indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0]
4038 # indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0]
4040 # error[indInvalid2] = 14
4039 # error[indInvalid2] = 14
4041 # indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0]
4040 # indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0]
4042 # error[indInvalid1] = 13
4041 # error[indInvalid1] = 13
4043 #
4042 #
4044 # return heights, error
4043 # return heights, error
4045 No newline at end of file
4044
General Comments 0
You need to be logged in to leave comments. Login now