@@ -700,7 +700,7 class Spectra(JROData): | |||
|
700 | 700 | for pair in pairsList: |
|
701 | 701 | if pair not in self.pairsList: |
|
702 | 702 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
703 | pairsIndexList.append(self.pairsList.index(pair)) | |
|
703 | pairsIndexList.append(self.pairsList.index(pair)) | |
|
704 | 704 | for i in range(len(pairsIndexList)): |
|
705 | 705 | pair = self.pairsList[pairsIndexList[i]] |
|
706 | 706 | ccf = numpy.average(self.data_cspc[pairsIndexList[i], :, :], axis=0) |
This diff has been collapsed as it changes many lines, (1208 lines changed) Show them Hide them | |||
@@ -1,32 +1,33 | |||
|
1 | 1 | |
|
2 | 2 | import os |
|
3 | import zmq | |
|
4 | 3 | import time |
|
5 |
import |
|
|
4 | import glob | |
|
6 | 5 | import datetime |
|
7 | import numpy as np | |
|
6 | from multiprocessing import Process | |
|
7 | ||
|
8 | import zmq | |
|
9 | import numpy | |
|
8 | 10 | import matplotlib |
|
9 | import glob | |
|
10 | matplotlib.use('TkAgg') | |
|
11 | 11 | import matplotlib.pyplot as plt |
|
12 | 12 | from mpl_toolkits.axes_grid1 import make_axes_locatable |
|
13 | from matplotlib.ticker import FuncFormatter, LinearLocator | |
|
14 | from multiprocessing import Process | |
|
13 | from matplotlib.ticker import FuncFormatter, LinearLocator, MultipleLocator | |
|
15 | 14 | |
|
16 | 15 | from schainpy.model.proc.jroproc_base import Operation |
|
17 | ||
|
18 | plt.ion() | |
|
16 | from schainpy.utils import log | |
|
19 | 17 | |
|
20 | 18 | func = lambda x, pos: ('%s') %(datetime.datetime.fromtimestamp(x).strftime('%H:%M')) |
|
21 | fromtimestamp = lambda x, mintime : (datetime.datetime.utcfromtimestamp(mintime).replace(hour=(x + 5), minute=0) - d1970).total_seconds() | |
|
22 | 19 | |
|
20 | d1970 = datetime.datetime(1970, 1, 1) | |
|
23 | 21 | |
|
24 | d1970 = datetime.datetime(1970,1,1) | |
|
25 | 22 | |
|
26 | 23 | class PlotData(Operation, Process): |
|
24 | ''' | |
|
25 | Base class for Schain plotting operations | |
|
26 | ''' | |
|
27 | 27 | |
|
28 | 28 | CODE = 'Figure' |
|
29 | 29 | colormap = 'jro' |
|
30 | bgcolor = 'white' | |
|
30 | 31 | CONFLATE = False |
|
31 | 32 | __MAXNUMX = 80 |
|
32 | 33 | __missing = 1E30 |
@@ -37,54 +38,143 class PlotData(Operation, Process): | |||
|
37 | 38 | Process.__init__(self) |
|
38 | 39 | self.kwargs['code'] = self.CODE |
|
39 | 40 | self.mp = False |
|
40 |
self.data |
|
|
41 | self.isConfig = False | |
|
42 |
self.figure = |
|
|
41 | self.data = None | |
|
42 | self.isConfig = False | |
|
43 | self.figures = [] | |
|
43 | 44 | self.axes = [] |
|
45 | self.cb_axes = [] | |
|
44 | 46 | self.localtime = kwargs.pop('localtime', True) |
|
45 | 47 | self.show = kwargs.get('show', True) |
|
46 | 48 | self.save = kwargs.get('save', False) |
|
47 | 49 | self.colormap = kwargs.get('colormap', self.colormap) |
|
48 | 50 | self.colormap_coh = kwargs.get('colormap_coh', 'jet') |
|
49 | 51 | self.colormap_phase = kwargs.get('colormap_phase', 'RdBu_r') |
|
50 |
self. |
|
|
51 |
self. |
|
|
52 | self.colormaps = kwargs.get('colormaps', None) | |
|
53 | self.bgcolor = kwargs.get('bgcolor', self.bgcolor) | |
|
54 | self.showprofile = kwargs.get('showprofile', False) | |
|
55 | self.title = kwargs.get('wintitle', self.CODE.upper()) | |
|
56 | self.cb_label = kwargs.get('cb_label', None) | |
|
57 | self.cb_labels = kwargs.get('cb_labels', None) | |
|
52 | 58 | self.xaxis = kwargs.get('xaxis', 'frequency') |
|
53 | 59 | self.zmin = kwargs.get('zmin', None) |
|
54 | 60 | self.zmax = kwargs.get('zmax', None) |
|
61 | self.zlimits = kwargs.get('zlimits', None) | |
|
55 | 62 | self.xmin = kwargs.get('xmin', None) |
|
63 | if self.xmin is not None: | |
|
64 | self.xmin += 5 | |
|
56 | 65 | self.xmax = kwargs.get('xmax', None) |
|
57 | 66 | self.xrange = kwargs.get('xrange', 24) |
|
58 | 67 | self.ymin = kwargs.get('ymin', None) |
|
59 | 68 | self.ymax = kwargs.get('ymax', None) |
|
60 |
self. |
|
|
61 | self.throttle_value = 5 | |
|
62 | self.times = [] | |
|
63 | #self.interactive = self.kwargs['parent'] | |
|
69 | self.xlabel = kwargs.get('xlabel', None) | |
|
70 | self.__MAXNUMY = kwargs.get('decimation', 100) | |
|
71 | self.showSNR = kwargs.get('showSNR', False) | |
|
72 | self.oneFigure = kwargs.get('oneFigure', True) | |
|
73 | self.width = kwargs.get('width', None) | |
|
74 | self.height = kwargs.get('height', None) | |
|
75 | self.colorbar = kwargs.get('colorbar', True) | |
|
76 | self.factors = kwargs.get('factors', [1, 1, 1, 1, 1, 1, 1, 1]) | |
|
77 | self.titles = ['' for __ in range(16)] | |
|
78 | ||
|
79 | def __setup(self): | |
|
80 | ''' | |
|
81 | Common setup for all figures, here figures and axes are created | |
|
82 | ''' | |
|
83 | ||
|
84 | self.setup() | |
|
85 | ||
|
86 | if self.width is None: | |
|
87 | self.width = 8 | |
|
64 | 88 | |
|
89 | self.figures = [] | |
|
90 | self.axes = [] | |
|
91 | self.cb_axes = [] | |
|
92 | self.pf_axes = [] | |
|
93 | self.cmaps = [] | |
|
94 | ||
|
95 | size = '15%' if self.ncols==1 else '30%' | |
|
96 | pad = '4%' if self.ncols==1 else '8%' | |
|
97 | ||
|
98 | if self.oneFigure: | |
|
99 | if self.height is None: | |
|
100 | self.height = 1.4*self.nrows + 1 | |
|
101 | fig = plt.figure(figsize=(self.width, self.height), | |
|
102 | edgecolor='k', | |
|
103 | facecolor='w') | |
|
104 | self.figures.append(fig) | |
|
105 | for n in range(self.nplots): | |
|
106 | ax = fig.add_subplot(self.nrows, self.ncols, n+1) | |
|
107 | ax.tick_params(labelsize=8) | |
|
108 | ax.firsttime = True | |
|
109 | self.axes.append(ax) | |
|
110 | if self.showprofile: | |
|
111 | cax = self.__add_axes(ax, size=size, pad=pad) | |
|
112 | cax.tick_params(labelsize=8) | |
|
113 | self.pf_axes.append(cax) | |
|
114 | else: | |
|
115 | if self.height is None: | |
|
116 | self.height = 3 | |
|
117 | for n in range(self.nplots): | |
|
118 | fig = plt.figure(figsize=(self.width, self.height), | |
|
119 | edgecolor='k', | |
|
120 | facecolor='w') | |
|
121 | ax = fig.add_subplot(1, 1, 1) | |
|
122 | ax.tick_params(labelsize=8) | |
|
123 | ax.firsttime = True | |
|
124 | self.figures.append(fig) | |
|
125 | self.axes.append(ax) | |
|
126 | if self.showprofile: | |
|
127 | cax = self.__add_axes(ax, size=size, pad=pad) | |
|
128 | cax.tick_params(labelsize=8) | |
|
129 | self.pf_axes.append(cax) | |
|
130 | ||
|
131 | for n in range(self.nrows): | |
|
132 | if self.colormaps is not None: | |
|
133 | cmap = plt.get_cmap(self.colormaps[n]) | |
|
134 | else: | |
|
135 | cmap = plt.get_cmap(self.colormap) | |
|
136 | cmap.set_bad(self.bgcolor, 1.) | |
|
137 | self.cmaps.append(cmap) | |
|
138 | ||
|
139 | def __add_axes(self, ax, size='30%', pad='8%'): | |
|
65 | 140 | ''' |
|
66 | this new parameter is created to plot data from varius channels at different figures | |
|
67 | 1. crear una lista de figuras donde se puedan plotear las figuras, | |
|
68 | 2. dar las opciones de configuracion a cada figura, estas opciones son iguales para ambas figuras | |
|
69 | 3. probar? | |
|
141 | Add new axes to the given figure | |
|
70 | 142 | ''' |
|
71 | self.ind_plt_ch = kwargs.get('ind_plt_ch', False) | |
|
72 | self.figurelist = None | |
|
143 | divider = make_axes_locatable(ax) | |
|
144 | nax = divider.new_horizontal(size=size, pad=pad) | |
|
145 | ax.figure.add_axes(nax) | |
|
146 | return nax | |
|
73 | 147 | |
|
74 | 148 | |
|
75 | def fill_gaps(self, x_buffer, y_buffer, z_buffer): | |
|
149 | def setup(self): | |
|
150 | ''' | |
|
151 | This method should be implemented in the child class, the following | |
|
152 | attributes should be set: | |
|
153 | ||
|
154 | self.nrows: number of rows | |
|
155 | self.ncols: number of cols | |
|
156 | self.nplots: number of plots (channels or pairs) | |
|
157 | self.ylabel: label for Y axes | |
|
158 | self.titles: list of axes title | |
|
159 | ||
|
160 | ''' | |
|
161 | raise(NotImplementedError, 'Implement this method in child class') | |
|
76 | 162 | |
|
163 | def fill_gaps(self, x_buffer, y_buffer, z_buffer): | |
|
164 | ''' | |
|
165 | Create a masked array for missing data | |
|
166 | ''' | |
|
77 | 167 | if x_buffer.shape[0] < 2: |
|
78 | 168 | return x_buffer, y_buffer, z_buffer |
|
79 | 169 | |
|
80 | 170 | deltas = x_buffer[1:] - x_buffer[0:-1] |
|
81 | x_median = np.median(deltas) | |
|
171 | x_median = numpy.median(deltas) | |
|
82 | 172 | |
|
83 | index = np.where(deltas > 5*x_median) | |
|
173 | index = numpy.where(deltas > 5*x_median) | |
|
84 | 174 | |
|
85 | 175 | if len(index[0]) != 0: |
|
86 | 176 | z_buffer[::, index[0], ::] = self.__missing |
|
87 | z_buffer = np.ma.masked_inside(z_buffer, | |
|
177 | z_buffer = numpy.ma.masked_inside(z_buffer, | |
|
88 | 178 | 0.99*self.__missing, |
|
89 | 179 | 1.01*self.__missing) |
|
90 | 180 | |
@@ -99,110 +189,117 class PlotData(Operation, Process): | |||
|
99 | 189 | x = self.x |
|
100 | 190 | y = self.y[::dy] |
|
101 | 191 | z = self.z[::, ::, ::dy] |
|
102 | ||
|
192 | ||
|
103 | 193 | return x, y, z |
|
104 | 194 | |
|
105 | ''' | |
|
106 | JM: | |
|
107 | elimana las otras imagenes generadas debido a que lso workers no llegan en orden y le pueden | |
|
108 | poner otro tiempo a la figura q no necesariamente es el ultimo. | |
|
109 | Solo se realiza cuando termina la imagen. | |
|
110 | Problemas: | |
|
195 | def format(self): | |
|
196 | ''' | |
|
197 | Set min and max values, labels, ticks and titles | |
|
198 | ''' | |
|
111 | 199 | |
|
112 | File "/home/ci-81/workspace/schainv2.3/schainpy/model/graphics/jroplot_data.py", line 145, in __plot | |
|
113 | for n, eachfigure in enumerate(self.figurelist): | |
|
114 | TypeError: 'NoneType' object is not iterable | |
|
200 | if self.xmin is None: | |
|
201 | xmin = self.min_time | |
|
202 | else: | |
|
203 | if self.xaxis is 'time': | |
|
204 | dt = datetime.datetime.fromtimestamp(self.min_time) | |
|
205 | xmin = (datetime.datetime.combine(dt.date(), | |
|
206 | datetime.time(int(self.xmin), 0, 0))-d1970).total_seconds() | |
|
207 | else: | |
|
208 | xmin = self.xmin | |
|
115 | 209 | |
|
116 | ''' | |
|
117 | def deleteanotherfiles(self): | |
|
118 | figurenames=[] | |
|
119 | if self.figurelist != None: | |
|
120 | for n, eachfigure in enumerate(self.figurelist): | |
|
121 | #add specific name for each channel in channelList | |
|
122 | ghostfigname = os.path.join(self.save, '{}_{}_{}'.format(self.titles[n].replace(' ',''),self.CODE, | |
|
123 | datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d'))) | |
|
124 | figname = os.path.join(self.save, '{}_{}_{}.png'.format(self.titles[n].replace(' ',''),self.CODE, | |
|
125 | datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S'))) | |
|
126 | ||
|
127 | for ghostfigure in glob.glob(ghostfigname+'*'): #ghostfigure will adopt all posible names of figures | |
|
128 | if ghostfigure != figname: | |
|
129 | os.remove(ghostfigure) | |
|
130 | print 'Removing GhostFigures:' , figname | |
|
131 | else : | |
|
132 | '''Erasing ghost images for just on******************''' | |
|
133 | ghostfigname = os.path.join(self.save, '{}_{}'.format(self.CODE,datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d'))) | |
|
134 | figname = os.path.join(self.save, '{}_{}.png'.format(self.CODE,datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S'))) | |
|
135 | for ghostfigure in glob.glob(ghostfigname+'*'): #ghostfigure will adopt all posible names of figures | |
|
136 | if ghostfigure != figname: | |
|
137 | os.remove(ghostfigure) | |
|
138 | print 'Removing GhostFigures:' , figname | |
|
210 | if self.xmax is None: | |
|
211 | xmax = xmin+self.xrange*60*60 | |
|
212 | else: | |
|
213 | if self.xaxis is 'time': | |
|
214 | dt = datetime.datetime.fromtimestamp(self.min_time) | |
|
215 | xmax = (datetime.datetime.combine(dt.date(), | |
|
216 | datetime.time(int(self.xmax), 0, 0))-d1970).total_seconds() | |
|
217 | else: | |
|
218 | xmax = self.xmax | |
|
219 | ||
|
220 | ymin = self.ymin if self.ymin else numpy.nanmin(self.y) | |
|
221 | ymax = self.ymax if self.ymax else numpy.nanmax(self.y) | |
|
222 | ||
|
223 | ystep = 200 if ymax>= 800 else 100 if ymax>=400 else 50 if ymax>=200 else 20 | |
|
224 | ||
|
225 | for n, ax in enumerate(self.axes): | |
|
226 | if ax.firsttime: | |
|
227 | ax.set_facecolor(self.bgcolor) | |
|
228 | ax.yaxis.set_major_locator(MultipleLocator(ystep)) | |
|
229 | if self.xaxis is 'time': | |
|
230 | ax.xaxis.set_major_formatter(FuncFormatter(func)) | |
|
231 | ax.xaxis.set_major_locator(LinearLocator(9)) | |
|
232 | if self.xlabel is not None: | |
|
233 | ax.set_xlabel(self.xlabel) | |
|
234 | ax.set_ylabel(self.ylabel) | |
|
235 | ax.firsttime = False | |
|
236 | if self.showprofile: | |
|
237 | self.pf_axes[n].set_ylim(ymin, ymax) | |
|
238 | self.pf_axes[n].set_xlim(self.zmin, self.zmax) | |
|
239 | self.pf_axes[n].set_xlabel('dB') | |
|
240 | self.pf_axes[n].grid(b=True, axis='x') | |
|
241 | [tick.set_visible(False) for tick in self.pf_axes[n].get_yticklabels()] | |
|
242 | if self.colorbar: | |
|
243 | cb = plt.colorbar(ax.plt, ax=ax, pad=0.02) | |
|
244 | cb.ax.tick_params(labelsize=8) | |
|
245 | if self.cb_label: | |
|
246 | cb.set_label(self.cb_label, size=8) | |
|
247 | elif self.cb_labels: | |
|
248 | cb.set_label(self.cb_labels[n], size=8) | |
|
249 | ||
|
250 | ax.set_title('{} - {} UTC'.format( | |
|
251 | self.titles[n], | |
|
252 | datetime.datetime.fromtimestamp(self.max_time).strftime('%H:%M:%S')), | |
|
253 | size=8) | |
|
254 | ax.set_xlim(xmin, xmax) | |
|
255 | ax.set_ylim(ymin, ymax) | |
|
256 | ||
|
139 | 257 | |
|
140 | 258 | def __plot(self): |
|
141 | ||
|
142 | print 'plotting...{}'.format(self.CODE) | |
|
143 | if self.ind_plt_ch is False : #standard | |
|
259 | ''' | |
|
260 | ''' | |
|
261 | log.success('Plotting', self.name) | |
|
262 | ||
|
263 | self.plot() | |
|
264 | self.format() | |
|
265 | ||
|
266 | for n, fig in enumerate(self.figures): | |
|
267 | if self.nrows == 0 or self.nplots == 0: | |
|
268 | log.warning('No data', self.name) | |
|
269 | continue | |
|
144 | 270 | if self.show: |
|
145 |
|
|
|
146 |
|
|
|
147 |
|
|
|
148 |
|
|
|
149 |
|
|
|
150 | else : | |
|
151 | print 'len(self.figurelist): ',len(self.figurelist) | |
|
152 | for n, eachfigure in enumerate(self.figurelist): | |
|
153 |
|
|
|
154 |
|
|
|
155 | ||
|
156 |
|
|
|
157 | eachfigure.tight_layout() # ajuste de cada subplot | |
|
158 | eachfigure.canvas.manager.set_window_title('{} {} - {}'.format(self.title[n], self.CODE.upper(), | |
|
159 | datetime.datetime.fromtimestamp(self.max_time).strftime('%Y/%m/%d'))) | |
|
160 | ||
|
161 | # if self.save: | |
|
162 | # if self.ind_plt_ch is False : #standard | |
|
163 | # figname = os.path.join(self.save, '{}_{}.png'.format(self.CODE, | |
|
164 | # datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S'))) | |
|
165 | # print 'Saving figure: {}'.format(figname) | |
|
166 | # self.figure.savefig(figname) | |
|
167 | # else : | |
|
168 | # for n, eachfigure in enumerate(self.figurelist): | |
|
169 | # #add specific name for each channel in channelList | |
|
170 | # figname = os.path.join(self.save, '{}_{}_{}.png'.format(self.titles[n],self.CODE, | |
|
171 | # datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S'))) | |
|
172 | # | |
|
173 | # print 'Saving figure: {}'.format(figname) | |
|
174 | # eachfigure.savefig(figname) | |
|
175 | ||
|
176 | if self.ind_plt_ch is False : | |
|
177 | self.figure.canvas.draw() | |
|
178 | else : | |
|
179 | for eachfigure in self.figurelist: | |
|
180 | eachfigure.canvas.draw() | |
|
181 | ||
|
182 | if self.save: | |
|
183 | if self.ind_plt_ch is False : #standard | |
|
184 | figname = os.path.join(self.save, '{}_{}.png'.format(self.CODE, | |
|
185 | datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S'))) | |
|
271 | fig.show() | |
|
272 | ||
|
273 | fig.tight_layout() | |
|
274 | fig.canvas.manager.set_window_title('{} - {}'.format(self.title, | |
|
275 | datetime.datetime.fromtimestamp(self.max_time).strftime('%Y/%m/%d'))) | |
|
276 | # fig.canvas.draw() | |
|
277 | ||
|
278 | if self.save and self.data.ended: | |
|
279 | channels = range(self.nrows) | |
|
280 | if self.oneFigure: | |
|
281 | label = '' | |
|
282 | else: | |
|
283 | label = '_{}'.format(channels[n]) | |
|
284 | figname = os.path.join( | |
|
285 | self.save, | |
|
286 | '{}{}_{}.png'.format( | |
|
287 | self.CODE, | |
|
288 | label, | |
|
289 | datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S') | |
|
290 | ) | |
|
291 | ) | |
|
186 | 292 | print 'Saving figure: {}'.format(figname) |
|
187 |
|
|
|
188 | else : | |
|
189 | for n, eachfigure in enumerate(self.figurelist): | |
|
190 | #add specific name for each channel in channelList | |
|
191 | figname = os.path.join(self.save, '{}_{}_{}.png'.format(self.titles[n].replace(' ',''),self.CODE, | |
|
192 | datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S'))) | |
|
193 | ||
|
194 | print 'Saving figure: {}'.format(figname) | |
|
195 | eachfigure.savefig(figname) | |
|
196 | ||
|
293 | fig.savefig(figname) | |
|
197 | 294 | |
|
198 | 295 | def plot(self): |
|
199 | ||
|
200 | print 'plotting...{}'.format(self.CODE.upper()) | |
|
201 | return | |
|
296 | ''' | |
|
297 | ''' | |
|
298 | raise(NotImplementedError, 'Implement this method in child class') | |
|
202 | 299 | |
|
203 | 300 | def run(self): |
|
204 | 301 | |
|
205 |
|
|
|
302 | log.success('Starting', self.name) | |
|
206 | 303 | |
|
207 | 304 | context = zmq.Context() |
|
208 | 305 | receiver = context.socket(zmq.SUB) |
@@ -212,152 +309,104 class PlotData(Operation, Process): | |||
|
212 | 309 | if 'server' in self.kwargs['parent']: |
|
213 | 310 | receiver.connect('ipc:///tmp/{}.plots'.format(self.kwargs['parent']['server'])) |
|
214 | 311 | else: |
|
215 | receiver.connect("ipc:///tmp/zmq.plots") | |
|
216 | ||
|
217 | seconds_passed = 0 | |
|
312 | receiver.connect("ipc:///tmp/zmq.plots") | |
|
218 | 313 | |
|
219 | 314 | while True: |
|
220 | 315 | try: |
|
221 |
self.data = receiver.recv_pyobj(flags=zmq.NOBLOCK) |
|
|
222 | self.started = self.data['STARTED'] | |
|
223 |
self. |
|
|
224 | ||
|
225 | if (len(self.times) < len(self.data['times']) and not self.started and self.data['ENDED']): | |
|
226 | continue | |
|
227 | ||
|
228 | self.times = self.data['times'] | |
|
229 | self.times.sort() | |
|
230 | self.throttle_value = self.data['throttle'] | |
|
231 | self.min_time = self.times[0] | |
|
232 | self.max_time = self.times[-1] | |
|
316 | self.data = receiver.recv_pyobj(flags=zmq.NOBLOCK) | |
|
317 | ||
|
318 | self.min_time = self.data.times[0] | |
|
319 | self.max_time = self.data.times[-1] | |
|
233 | 320 | |
|
234 | 321 | if self.isConfig is False: |
|
235 |
|
|
|
236 | self.setup() | |
|
322 | self.__setup() | |
|
237 | 323 | self.isConfig = True |
|
238 | self.__plot() | |
|
239 | ||
|
240 | if self.data['ENDED'] is True: | |
|
241 | print '********GRAPHIC ENDED********' | |
|
242 | self.ended = True | |
|
243 | self.isConfig = False | |
|
244 | self.__plot() | |
|
245 | self.deleteanotherfiles() #CLPDG | |
|
246 | elif seconds_passed >= self.data['throttle']: | |
|
247 | print 'passed', seconds_passed | |
|
248 | self.__plot() | |
|
249 | seconds_passed = 0 | |
|
324 | ||
|
325 | self.__plot() | |
|
250 | 326 | |
|
251 | 327 | except zmq.Again as e: |
|
252 |
|
|
|
253 |
|
|
|
254 | seconds_passed += 2 | |
|
328 | log.log('Waiting for data...') | |
|
329 | if self.data: | |
|
330 | plt.pause(self.data.throttle) | |
|
331 | else: | |
|
332 | time.sleep(2) | |
|
255 | 333 | |
|
256 | 334 | def close(self): |
|
257 |
if self.data |
|
|
335 | if self.data: | |
|
258 | 336 | self.__plot() |
|
259 | 337 | |
|
260 | 338 | |
|
261 | 339 | class PlotSpectraData(PlotData): |
|
340 | ''' | |
|
341 | Plot for Spectra data | |
|
342 | ''' | |
|
262 | 343 | |
|
263 | 344 | CODE = 'spc' |
|
264 | colormap = 'jro' | |
|
265 | CONFLATE = False | |
|
345 | colormap = 'jro' | |
|
266 | 346 | |
|
267 | 347 | def setup(self): |
|
268 | ||
|
269 | ncolspan = 1 | |
|
270 | colspan = 1 | |
|
271 | self.ncols = int(numpy.sqrt(self.dataOut.nChannels)+0.9) | |
|
272 | self.nrows = int(self.dataOut.nChannels*1./self.ncols + 0.9) | |
|
273 | self.width = 3.6*self.ncols | |
|
274 | self.height = 3.2*self.nrows | |
|
275 | if self.showprofile: | |
|
276 | ncolspan = 3 | |
|
277 | colspan = 2 | |
|
278 | self.width += 1.2*self.ncols | |
|
348 | self.nplots = len(self.data.channels) | |
|
349 | self.ncols = int(numpy.sqrt(self.nplots)+ 0.9) | |
|
350 | self.nrows = int((1.0*self.nplots/self.ncols) + 0.9) | |
|
351 | self.width = 3.4*self.ncols | |
|
352 | self.height = 3*self.nrows | |
|
353 | self.cb_label = 'dB' | |
|
354 | if self.showprofile: | |
|
355 | self.width += 0.8*self.ncols | |
|
279 | 356 | |
|
280 | 357 | self.ylabel = 'Range [Km]' |
|
281 | self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList] | |
|
282 | ||
|
283 | if self.figure is None: | |
|
284 | self.figure = plt.figure(figsize=(self.width, self.height), | |
|
285 | edgecolor='k', | |
|
286 | facecolor='w') | |
|
287 | else: | |
|
288 | self.figure.clf() | |
|
289 | ||
|
290 | n = 0 | |
|
291 | for y in range(self.nrows): | |
|
292 | for x in range(self.ncols): | |
|
293 | if n >= self.dataOut.nChannels: | |
|
294 | break | |
|
295 | ax = plt.subplot2grid((self.nrows, self.ncols*ncolspan), (y, x*ncolspan), 1, colspan) | |
|
296 | if self.showprofile: | |
|
297 | ax.ax_profile = plt.subplot2grid((self.nrows, self.ncols*ncolspan), (y, x*ncolspan+colspan), 1, 1) | |
|
298 | ||
|
299 | ax.firsttime = True | |
|
300 | self.axes.append(ax) | |
|
301 | n += 1 | |
|
302 | 358 | |
|
303 | 359 | def plot(self): |
|
304 | ||
|
305 | 360 | if self.xaxis == "frequency": |
|
306 |
x = self.data |
|
|
307 | xlabel = "Frequency (kHz)" | |
|
361 | x = self.data.xrange[0] | |
|
362 | self.xlabel = "Frequency (kHz)" | |
|
308 | 363 | elif self.xaxis == "time": |
|
309 |
x = self.data |
|
|
310 | xlabel = "Time (ms)" | |
|
364 | x = self.data.xrange[1] | |
|
365 | self.xlabel = "Time (ms)" | |
|
311 | 366 | else: |
|
312 |
x = self.data |
|
|
313 | xlabel = "Velocity (m/s)" | |
|
367 | x = self.data.xrange[2] | |
|
368 | self.xlabel = "Velocity (m/s)" | |
|
369 | ||
|
370 | if self.CODE == 'spc_mean': | |
|
371 | x = self.data.xrange[2] | |
|
372 | self.xlabel = "Velocity (m/s)" | |
|
314 | 373 | |
|
315 | y = self.dataOut.getHeiRange() | |
|
316 | z = self.data[self.CODE] | |
|
374 | self.titles = [] | |
|
317 | 375 | |
|
376 | y = self.data.heights | |
|
377 | self.y = y | |
|
378 | z = self.data['spc'] | |
|
379 | ||
|
318 | 380 | for n, ax in enumerate(self.axes): |
|
381 | noise = self.data['noise'][n][-1] | |
|
382 | if self.CODE == 'spc_mean': | |
|
383 | mean = self.data['mean'][n][-1] | |
|
319 | 384 | if ax.firsttime: |
|
320 | self.xmax = self.xmax if self.xmax else np.nanmax(x) | |
|
385 | self.xmax = self.xmax if self.xmax else numpy.nanmax(x) | |
|
321 | 386 | self.xmin = self.xmin if self.xmin else -self.xmax |
|
322 |
self. |
|
|
323 |
self. |
|
|
324 | self.zmin = self.zmin if self.zmin else np.nanmin(z) | |
|
325 | self.zmax = self.zmax if self.zmax else np.nanmax(z) | |
|
326 | ax.plot = ax.pcolormesh(x, y, z[n].T, | |
|
327 |
|
|
|
328 |
|
|
|
329 | cmap=plt.get_cmap(self.colormap) | |
|
330 | ) | |
|
331 | divider = make_axes_locatable(ax) | |
|
332 | cax = divider.new_horizontal(size='3%', pad=0.05) | |
|
333 | self.figure.add_axes(cax) | |
|
334 | plt.colorbar(ax.plot, cax) | |
|
335 | ||
|
336 | ax.set_xlim(self.xmin, self.xmax) | |
|
337 | ax.set_ylim(self.ymin, self.ymax) | |
|
338 | ||
|
339 | ax.set_ylabel(self.ylabel) | |
|
340 | ax.set_xlabel(xlabel) | |
|
341 | ||
|
342 | ax.firsttime = False | |
|
387 | self.zmin = self.zmin if self.zmin else numpy.nanmin(z) | |
|
388 | self.zmax = self.zmax if self.zmax else numpy.nanmax(z) | |
|
389 | ax.plt = ax.pcolormesh(x, y, z[n].T, | |
|
390 | vmin=self.zmin, | |
|
391 | vmax=self.zmax, | |
|
392 | cmap=plt.get_cmap(self.colormap) | |
|
393 | ) | |
|
343 | 394 | |
|
344 | 395 | if self.showprofile: |
|
345 |
ax.pl |
|
|
346 | ax.ax_profile.set_xlim(self.zmin, self.zmax) | |
|
347 | ax.ax_profile.set_ylim(self.ymin, self.ymax) | |
|
348 | ax.ax_profile.set_xlabel('dB') | |
|
349 | ax.ax_profile.grid(b=True, axis='x') | |
|
350 | ax.plot_noise = ax.ax_profile.plot(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y, | |
|
351 | color="k", linestyle="dashed", lw=2)[0] | |
|
352 | [tick.set_visible(False) for tick in ax.ax_profile.get_yticklabels()] | |
|
396 | ax.plt_profile= self.pf_axes[n].plot(self.data['rti'][n][-1], y)[0] | |
|
397 | ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y, | |
|
398 | color="k", linestyle="dashed", lw=1)[0] | |
|
399 | if self.CODE == 'spc_mean': | |
|
400 | ax.plt_mean = ax.plot(mean, y, color='k')[0] | |
|
353 | 401 | else: |
|
354 |
ax.pl |
|
|
402 | ax.plt.set_array(z[n].T.ravel()) | |
|
355 | 403 | if self.showprofile: |
|
356 |
ax.pl |
|
|
357 |
ax.pl |
|
|
404 | ax.plt_profile.set_data(self.data['rti'][n][-1], y) | |
|
405 | ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y) | |
|
406 | if self.CODE == 'spc_mean': | |
|
407 | ax.plt_mean.set_data(mean, y) | |
|
358 | 408 | |
|
359 | ax.set_title('{} - Noise: {:.2f} dB'.format(self.titles[n], self.data['noise'][self.max_time][n]), | |
|
360 | size=8) | |
|
409 | self.titles.append('CH {}: {:3.2f}dB'.format(n, noise)) | |
|
361 | 410 | self.saveTime = self.max_time |
|
362 | 411 | |
|
363 | 412 | |
@@ -367,545 +416,245 class PlotCrossSpectraData(PlotData): | |||
|
367 | 416 | zmin_coh = None |
|
368 | 417 | zmax_coh = None |
|
369 | 418 | zmin_phase = None |
|
370 | zmax_phase = None | |
|
371 | CONFLATE = False | |
|
419 | zmax_phase = None | |
|
372 | 420 | |
|
373 | 421 | def setup(self): |
|
374 | 422 | |
|
375 |
ncols |
|
|
376 | colspan = 1 | |
|
377 |
self.n |
|
|
378 |
self. |
|
|
379 |
self. |
|
|
380 | self.height = 3.2*self.nrows | |
|
381 | ||
|
423 | self.ncols = 4 | |
|
424 | self.nrows = len(self.data.pairs) | |
|
425 | self.nplots = self.nrows*4 | |
|
426 | self.width = 3.4*self.ncols | |
|
427 | self.height = 3*self.nrows | |
|
382 | 428 | self.ylabel = 'Range [Km]' |
|
383 | self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList] | |
|
384 | ||
|
385 | if self.figure is None: | |
|
386 | self.figure = plt.figure(figsize=(self.width, self.height), | |
|
387 | edgecolor='k', | |
|
388 | facecolor='w') | |
|
389 | else: | |
|
390 | self.figure.clf() | |
|
391 | ||
|
392 | for y in range(self.nrows): | |
|
393 | for x in range(self.ncols): | |
|
394 | ax = plt.subplot2grid((self.nrows, self.ncols), (y, x), 1, 1) | |
|
395 | ax.firsttime = True | |
|
396 | self.axes.append(ax) | |
|
429 | self.showprofile = False | |
|
397 | 430 | |
|
398 | 431 | def plot(self): |
|
399 | 432 | |
|
400 | 433 | if self.xaxis == "frequency": |
|
401 |
x = self.data |
|
|
402 | xlabel = "Frequency (kHz)" | |
|
434 | x = self.data.xrange[0] | |
|
435 | self.xlabel = "Frequency (kHz)" | |
|
403 | 436 | elif self.xaxis == "time": |
|
404 |
x = self.data |
|
|
405 | xlabel = "Time (ms)" | |
|
437 | x = self.data.xrange[1] | |
|
438 | self.xlabel = "Time (ms)" | |
|
406 | 439 | else: |
|
407 |
x = self.data |
|
|
408 | xlabel = "Velocity (m/s)" | |
|
440 | x = self.data.xrange[2] | |
|
441 | self.xlabel = "Velocity (m/s)" | |
|
442 | ||
|
443 | self.titles = [] | |
|
409 | 444 | |
|
410 |
y = self.data |
|
|
411 | z_coh = self.data['cspc_coh'] | |
|
412 |
|
|
|
445 | y = self.data.heights | |
|
446 | self.y = y | |
|
447 | spc = self.data['spc'] | |
|
448 | cspc = self.data['cspc'] | |
|
413 | 449 | |
|
414 | 450 | for n in range(self.nrows): |
|
415 |
|
|
|
416 |
|
|
|
451 | noise = self.data['noise'][n][-1] | |
|
452 | pair = self.data.pairs[n] | |
|
453 | ax = self.axes[4*n] | |
|
454 | ax3 = self.axes[4*n+3] | |
|
417 | 455 | if ax.firsttime: |
|
418 | self.xmax = self.xmax if self.xmax else np.nanmax(x) | |
|
456 | self.xmax = self.xmax if self.xmax else numpy.nanmax(x) | |
|
419 | 457 | self.xmin = self.xmin if self.xmin else -self.xmax |
|
420 |
self. |
|
|
421 |
self. |
|
|
422 | self.zmin_coh = self.zmin_coh if self.zmin_coh else 0.0 | |
|
423 | self.zmax_coh = self.zmax_coh if self.zmax_coh else 1.0 | |
|
424 | self.zmin_phase = self.zmin_phase if self.zmin_phase else -180 | |
|
425 | self.zmax_phase = self.zmax_phase if self.zmax_phase else 180 | |
|
426 | ||
|
427 | ax.plot = ax.pcolormesh(x, y, z_coh[n].T, | |
|
428 | vmin=self.zmin_coh, | |
|
429 | vmax=self.zmax_coh, | |
|
430 | cmap=plt.get_cmap(self.colormap_coh) | |
|
431 | ) | |
|
432 | divider = make_axes_locatable(ax) | |
|
433 | cax = divider.new_horizontal(size='3%', pad=0.05) | |
|
434 | self.figure.add_axes(cax) | |
|
435 | plt.colorbar(ax.plot, cax) | |
|
436 | ||
|
437 | ax.set_xlim(self.xmin, self.xmax) | |
|
438 | ax.set_ylim(self.ymin, self.ymax) | |
|
439 | ||
|
440 | ax.set_ylabel(self.ylabel) | |
|
441 | ax.set_xlabel(xlabel) | |
|
442 | ax.firsttime = False | |
|
443 | ||
|
444 | ax1.plot = ax1.pcolormesh(x, y, z_phase[n].T, | |
|
445 | vmin=self.zmin_phase, | |
|
446 | vmax=self.zmax_phase, | |
|
447 | cmap=plt.get_cmap(self.colormap_phase) | |
|
448 | ) | |
|
449 | divider = make_axes_locatable(ax1) | |
|
450 | cax = divider.new_horizontal(size='3%', pad=0.05) | |
|
451 | self.figure.add_axes(cax) | |
|
452 | plt.colorbar(ax1.plot, cax) | |
|
453 | ||
|
454 | ax1.set_xlim(self.xmin, self.xmax) | |
|
455 | ax1.set_ylim(self.ymin, self.ymax) | |
|
456 | ||
|
457 | ax1.set_ylabel(self.ylabel) | |
|
458 | ax1.set_xlabel(xlabel) | |
|
459 | ax1.firsttime = False | |
|
458 | self.zmin = self.zmin if self.zmin else numpy.nanmin(spc) | |
|
459 | self.zmax = self.zmax if self.zmax else numpy.nanmax(spc) | |
|
460 | ax.plt = ax.pcolormesh(x, y, spc[pair[0]].T, | |
|
461 | vmin=self.zmin, | |
|
462 | vmax=self.zmax, | |
|
463 | cmap=plt.get_cmap(self.colormap) | |
|
464 | ) | |
|
460 | 465 | else: |
|
461 |
ax.pl |
|
|
462 | ax1.plot.set_array(z_phase[n].T.ravel()) | |
|
463 | ||
|
464 | ax.set_title('Coherence Ch{} * Ch{}'.format(self.dataOut.pairsList[n][0], self.dataOut.pairsList[n][1]), size=8) | |
|
465 | ax1.set_title('Phase Ch{} * Ch{}'.format(self.dataOut.pairsList[n][0], self.dataOut.pairsList[n][1]), size=8) | |
|
466 | self.saveTime = self.max_time | |
|
467 | ||
|
466 | ax.plt.set_array(spc[pair[0]].T.ravel()) | |
|
467 | self.titles.append('CH {}: {:3.2f}dB'.format(n, noise)) | |
|
468 | 468 | |
|
469 | class PlotSpectraMeanData(PlotSpectraData): | |
|
470 | ||
|
471 | CODE = 'spc_mean' | |
|
472 | colormap = 'jet' | |
|
473 | ||
|
474 | def plot(self): | |
|
475 | ||
|
476 | if self.xaxis == "frequency": | |
|
477 | x = self.dataOut.getFreqRange(1)/1000. | |
|
478 | xlabel = "Frequency (kHz)" | |
|
479 | elif self.xaxis == "time": | |
|
480 | x = self.dataOut.getAcfRange(1) | |
|
481 | xlabel = "Time (ms)" | |
|
482 | else: | |
|
483 | x = self.dataOut.getVelRange(1) | |
|
484 | xlabel = "Velocity (m/s)" | |
|
485 | ||
|
486 | y = self.dataOut.getHeiRange() | |
|
487 | z = self.data['spc'] | |
|
488 | mean = self.data['mean'][self.max_time] | |
|
489 | ||
|
490 | for n, ax in enumerate(self.axes): | |
|
491 | ||
|
492 | if ax.firsttime: | |
|
493 | self.xmax = self.xmax if self.xmax else np.nanmax(x) | |
|
494 | self.xmin = self.xmin if self.xmin else -self.xmax | |
|
495 | self.ymin = self.ymin if self.ymin else np.nanmin(y) | |
|
496 | self.ymax = self.ymax if self.ymax else np.nanmax(y) | |
|
497 | self.zmin = self.zmin if self.zmin else np.nanmin(z) | |
|
498 | self.zmax = self.zmax if self.zmax else np.nanmax(z) | |
|
499 | ax.plt = ax.pcolormesh(x, y, z[n].T, | |
|
469 | ax = self.axes[4*n+1] | |
|
470 | if ax.firsttime: | |
|
471 | ax.plt = ax.pcolormesh(x, y, spc[pair[1]].T, | |
|
500 | 472 | vmin=self.zmin, |
|
501 | 473 | vmax=self.zmax, |
|
502 | 474 | cmap=plt.get_cmap(self.colormap) |
|
503 | 475 | ) |
|
504 | ax.plt_dop = ax.plot(mean[n], y, | |
|
505 | color='k')[0] | |
|
506 | ||
|
507 | divider = make_axes_locatable(ax) | |
|
508 | cax = divider.new_horizontal(size='3%', pad=0.05) | |
|
509 | self.figure.add_axes(cax) | |
|
510 | plt.colorbar(ax.plt, cax) | |
|
511 | ||
|
512 | ax.set_xlim(self.xmin, self.xmax) | |
|
513 | ax.set_ylim(self.ymin, self.ymax) | |
|
514 | ||
|
515 | ax.set_ylabel(self.ylabel) | |
|
516 | ax.set_xlabel(xlabel) | |
|
517 | ||
|
518 | ax.firsttime = False | |
|
519 | ||
|
520 | if self.showprofile: | |
|
521 | ax.plt_profile= ax.ax_profile.plot(self.data['rti'][self.max_time][n], y)[0] | |
|
522 | ax.ax_profile.set_xlim(self.zmin, self.zmax) | |
|
523 | ax.ax_profile.set_ylim(self.ymin, self.ymax) | |
|
524 | ax.ax_profile.set_xlabel('dB') | |
|
525 | ax.ax_profile.grid(b=True, axis='x') | |
|
526 | ax.plt_noise = ax.ax_profile.plot(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y, | |
|
527 | color="k", linestyle="dashed", lw=2)[0] | |
|
528 | [tick.set_visible(False) for tick in ax.ax_profile.get_yticklabels()] | |
|
529 | 476 | else: |
|
530 |
ax.plt.set_array( |
|
|
531 | ax.plt_dop.set_data(mean[n], y) | |
|
532 | if self.showprofile: | |
|
533 | ax.plt_profile.set_data(self.data['rti'][self.max_time][n], y) | |
|
534 | ax.plt_noise.set_data(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y) | |
|
477 | ax.plt.set_array(spc[pair[1]].T.ravel()) | |
|
478 | self.titles.append('CH {}: {:3.2f}dB'.format(n, noise)) | |
|
479 | ||
|
480 | out = cspc[n]/numpy.sqrt(spc[pair[0]]*spc[pair[1]]) | |
|
481 | coh = numpy.abs(out) | |
|
482 | phase = numpy.arctan2(out.imag, out.real)*180/numpy.pi | |
|
483 | ||
|
484 | ax = self.axes[4*n+2] | |
|
485 | if ax.firsttime: | |
|
486 | ax.plt = ax.pcolormesh(x, y, coh.T, | |
|
487 | vmin=0, | |
|
488 | vmax=1, | |
|
489 | cmap=plt.get_cmap(self.colormap_coh) | |
|
490 | ) | |
|
491 | else: | |
|
492 | ax.plt.set_array(coh.T.ravel()) | |
|
493 | self.titles.append('Coherence Ch{} * Ch{}'.format(pair[0], pair[1])) | |
|
535 | 494 | |
|
536 | ax.set_title('{} - Noise: {:.2f} dB'.format(self.titles[n], self.data['noise'][self.max_time][n]), | |
|
537 | size=8) | |
|
495 | ax = self.axes[4*n+3] | |
|
496 | if ax.firsttime: | |
|
497 | ax.plt = ax.pcolormesh(x, y, phase.T, | |
|
498 | vmin=-180, | |
|
499 | vmax=180, | |
|
500 | cmap=plt.get_cmap(self.colormap_phase) | |
|
501 | ) | |
|
502 | else: | |
|
503 | ax.plt.set_array(phase.T.ravel()) | |
|
504 | self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1])) | |
|
505 | ||
|
538 | 506 | self.saveTime = self.max_time |
|
539 | 507 | |
|
540 | 508 | |
|
509 | class PlotSpectraMeanData(PlotSpectraData): | |
|
510 | ''' | |
|
511 | Plot for Spectra and Mean | |
|
512 | ''' | |
|
513 | CODE = 'spc_mean' | |
|
514 | colormap = 'jro' | |
|
515 | ||
|
516 | ||
|
541 | 517 | class PlotRTIData(PlotData): |
|
518 | ''' | |
|
519 | Plot for RTI data | |
|
520 | ''' | |
|
542 | 521 | |
|
543 | 522 | CODE = 'rti' |
|
544 | 523 | colormap = 'jro' |
|
545 | 524 | |
|
546 | 525 | def setup(self): |
|
547 |
self. |
|
|
548 | self.nrows = self.dataOut.nChannels | |
|
549 | self.width = 10 | |
|
550 | #TODO : arreglar la altura de la figura, esta hardcodeada. | |
|
551 | #Se arreglo, testear! | |
|
552 | if self.ind_plt_ch: | |
|
553 | self.height = 3.2#*self.nrows if self.nrows<6 else 12 | |
|
554 | else: | |
|
555 | self.height = 2.2*self.nrows if self.nrows<6 else 12 | |
|
556 | ||
|
557 | ''' | |
|
558 | if self.nrows==1: | |
|
559 | self.height += 1 | |
|
560 | ''' | |
|
526 | self.xaxis = 'time' | |
|
527 | self.ncols = 1 | |
|
528 | self.nrows = len(self.data.channels) | |
|
529 | self.nplots = len(self.data.channels) | |
|
561 | 530 | self.ylabel = 'Range [Km]' |
|
562 | self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList] | |
|
563 | ||
|
564 | ''' | |
|
565 | Logica: | |
|
566 | 1) Si la variable ind_plt_ch es True, va a crear mas de 1 figura | |
|
567 | 2) guardamos "Figures" en una lista y "axes" en otra, quizas se deberia guardar el | |
|
568 | axis dentro de "Figures" como un diccionario. | |
|
569 | ''' | |
|
570 | if self.ind_plt_ch is False: #standard mode | |
|
571 | ||
|
572 | if self.figure is None: #solo para la priemra vez | |
|
573 | self.figure = plt.figure(figsize=(self.width, self.height), | |
|
574 | edgecolor='k', | |
|
575 | facecolor='w') | |
|
576 | else: | |
|
577 | self.figure.clf() | |
|
578 | self.axes = [] | |
|
579 | ||
|
580 | ||
|
581 | for n in range(self.nrows): | |
|
582 | ax = self.figure.add_subplot(self.nrows, self.ncols, n+1) | |
|
583 | #ax = self.figure(n+1) | |
|
584 | ax.firsttime = True | |
|
585 | self.axes.append(ax) | |
|
586 | ||
|
587 | else : #append one figure foreach channel in channelList | |
|
588 | if self.figurelist == None: | |
|
589 | self.figurelist = [] | |
|
590 | for n in range(self.nrows): | |
|
591 | self.figure = plt.figure(figsize=(self.width, self.height), | |
|
592 | edgecolor='k', | |
|
593 | facecolor='w') | |
|
594 | #add always one subplot | |
|
595 | self.figurelist.append(self.figure) | |
|
596 | ||
|
597 | else : # cada dia nuevo limpia el axes, pero mantiene el figure | |
|
598 | for eachfigure in self.figurelist: | |
|
599 | eachfigure.clf() # eliminaria todas las figuras de la lista? | |
|
600 | self.axes = [] | |
|
601 | ||
|
602 | for eachfigure in self.figurelist: | |
|
603 | ax = eachfigure.add_subplot(1,1,1) #solo 1 axis por figura | |
|
604 | #ax = self.figure(n+1) | |
|
605 | ax.firsttime = True | |
|
606 | #Cada figura tiene un distinto puntero | |
|
607 | self.axes.append(ax) | |
|
608 | #plt.close(eachfigure) | |
|
609 | ||
|
531 | self.cb_label = 'dB' | |
|
532 | self.titles = ['{} Channel {}'.format(self.CODE.upper(), x) for x in range(self.nrows)] | |
|
610 | 533 | |
|
611 | 534 | def plot(self): |
|
535 | self.x = self.data.times | |
|
536 | self.y = self.data.heights | |
|
537 | self.z = self.data[self.CODE] | |
|
538 | self.z = numpy.ma.masked_invalid(self.z) | |
|
612 | 539 | |
|
613 | if self.ind_plt_ch is False: #standard mode | |
|
614 | self.x = np.array(self.times) | |
|
615 | self.y = self.dataOut.getHeiRange() | |
|
616 | self.z = [] | |
|
617 | ||
|
618 | for ch in range(self.nrows): | |
|
619 | self.z.append([self.data[self.CODE][t][ch] for t in self.times]) | |
|
620 | ||
|
621 | self.z = np.array(self.z) | |
|
622 | for n, ax in enumerate(self.axes): | |
|
623 | x, y, z = self.fill_gaps(*self.decimate()) | |
|
624 | if self.xmin is None: | |
|
625 | xmin = self.min_time | |
|
626 | else: | |
|
627 | xmin = fromtimestamp(int(self.xmin), self.min_time) | |
|
628 | if self.xmax is None: | |
|
629 | xmax = xmin + self.xrange*60*60 | |
|
630 | else: | |
|
631 | xmax = xmin + (self.xmax - self.xmin) * 60 * 60 | |
|
632 | self.zmin = self.zmin if self.zmin else np.min(self.z) | |
|
633 | self.zmax = self.zmax if self.zmax else np.max(self.z) | |
|
634 |
if |
|
|
635 | self.ymin = self.ymin if self.ymin else np.nanmin(self.y) | |
|
636 | self.ymax = self.ymax if self.ymax else np.nanmax(self.y) | |
|
637 | plot = ax.pcolormesh(x, y, z[n].T, | |
|
638 | vmin=self.zmin, | |
|
639 | vmax=self.zmax, | |
|
640 | cmap=plt.get_cmap(self.colormap) | |
|
641 | ) | |
|
642 | divider = make_axes_locatable(ax) | |
|
643 | cax = divider.new_horizontal(size='2%', pad=0.05) | |
|
644 | self.figure.add_axes(cax) | |
|
645 | plt.colorbar(plot, cax) | |
|
646 | ax.set_ylim(self.ymin, self.ymax) | |
|
647 | ax.xaxis.set_major_formatter(FuncFormatter(func)) | |
|
648 | ax.xaxis.set_major_locator(LinearLocator(6)) | |
|
649 | ax.set_ylabel(self.ylabel) | |
|
650 | # if self.xmin is None: | |
|
651 | # xmin = self.min_time | |
|
652 | # else: | |
|
653 | # xmin = (datetime.datetime.combine(self.dataOut.datatime.date(), | |
|
654 | # datetime.time(self.xmin, 0, 0))-d1970).total_seconds() | |
|
655 | ||
|
656 | ax.set_xlim(xmin, xmax) | |
|
657 | ax.firsttime = False | |
|
658 | else: | |
|
659 | ax.collections.remove(ax.collections[0]) | |
|
660 | ax.set_xlim(xmin, xmax) | |
|
661 | plot = ax.pcolormesh(x, y, z[n].T, | |
|
662 | vmin=self.zmin, | |
|
663 | vmax=self.zmax, | |
|
664 | cmap=plt.get_cmap(self.colormap) | |
|
665 | ) | |
|
666 | ax.set_title('{} {}'.format(self.titles[n], | |
|
667 | datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')), | |
|
668 | size=8) | |
|
669 | ||
|
670 | self.saveTime = self.min_time | |
|
671 | else : | |
|
672 | self.x = np.array(self.times) | |
|
673 | self.y = self.dataOut.getHeiRange() | |
|
674 | self.z = [] | |
|
675 | ||
|
676 | for ch in range(self.nrows): | |
|
677 | self.z.append([self.data[self.CODE][t][ch] for t in self.times]) | |
|
678 | ||
|
679 | self.z = np.array(self.z) | |
|
680 | for n, eachfigure in enumerate(self.figurelist): #estaba ax in axes | |
|
681 | ||
|
682 | x, y, z = self.fill_gaps(*self.decimate()) | |
|
683 | xmin = self.min_time | |
|
684 | xmax = xmin+self.xrange*60*60 | |
|
685 | self.zmin = self.zmin if self.zmin else np.min(self.z) | |
|
686 | self.zmax = self.zmax if self.zmax else np.max(self.z) | |
|
687 | if self.axes[n].firsttime: | |
|
688 | self.ymin = self.ymin if self.ymin else np.nanmin(self.y) | |
|
689 | self.ymax = self.ymax if self.ymax else np.nanmax(self.y) | |
|
690 | plot = self.axes[n].pcolormesh(x, y, z[n].T, | |
|
691 | vmin=self.zmin, | |
|
692 | vmax=self.zmax, | |
|
693 | cmap=plt.get_cmap(self.colormap) | |
|
694 | ) | |
|
695 | divider = make_axes_locatable(self.axes[n]) | |
|
696 | cax = divider.new_horizontal(size='2%', pad=0.05) | |
|
697 | eachfigure.add_axes(cax) | |
|
698 | #self.figure2.add_axes(cax) | |
|
699 | plt.colorbar(plot, cax) | |
|
700 | self.axes[n].set_ylim(self.ymin, self.ymax) | |
|
701 | ||
|
702 | self.axes[n].xaxis.set_major_formatter(FuncFormatter(func)) | |
|
703 | self.axes[n].xaxis.set_major_locator(LinearLocator(6)) | |
|
704 | ||
|
705 | self.axes[n].set_ylabel(self.ylabel) | |
|
706 | ||
|
707 | if self.xmin is None: | |
|
708 | xmin = self.min_time | |
|
709 | else: | |
|
710 | xmin = (datetime.datetime.combine(self.dataOut.datatime.date(), | |
|
711 | datetime.time(self.xmin, 0, 0))-d1970).total_seconds() | |
|
712 | ||
|
713 | self.axes[n].set_xlim(xmin, xmax) | |
|
714 | self.axes[n].firsttime = False | |
|
715 | else: | |
|
716 | self.axes[n].collections.remove(self.axes[n].collections[0]) | |
|
717 | self.axes[n].set_xlim(xmin, xmax) | |
|
718 | plot = self.axes[n].pcolormesh(x, y, z[n].T, | |
|
719 | vmin=self.zmin, | |
|
720 | vmax=self.zmax, | |
|
721 | cmap=plt.get_cmap(self.colormap) | |
|
722 | ) | |
|
723 | self.axes[n].set_title('{} {}'.format(self.titles[n], | |
|
724 | datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')), | |
|
725 | size=8) | |
|
540 | for n, ax in enumerate(self.axes): | |
|
541 | x, y, z = self.fill_gaps(*self.decimate()) | |
|
542 | self.zmin = self.zmin if self.zmin else numpy.min(self.z) | |
|
543 | self.zmax = self.zmax if self.zmax else numpy.max(self.z) | |
|
544 | if ax.firsttime: | |
|
545 | ax.plt = ax.pcolormesh(x, y, z[n].T, | |
|
546 | vmin=self.zmin, | |
|
547 | vmax=self.zmax, | |
|
548 | cmap=plt.get_cmap(self.colormap) | |
|
549 | ) | |
|
550 | if self.showprofile: | |
|
551 | ax.plot_profile= self.pf_axes[n].plot(self.data['rti'][n][-1], self.y)[0] | |
|
552 | ax.plot_noise = self.pf_axes[n].plot(numpy.repeat(self.data['noise'][n][-1], len(self.y)), self.y, | |
|
553 | color="k", linestyle="dashed", lw=1)[0] | |
|
554 | else: | |
|
555 | ax.collections.remove(ax.collections[0]) | |
|
556 | ax.plt = ax.pcolormesh(x, y, z[n].T, | |
|
557 | vmin=self.zmin, | |
|
558 | vmax=self.zmax, | |
|
559 | cmap=plt.get_cmap(self.colormap) | |
|
560 | ) | |
|
561 | if self.showprofile: | |
|
562 | ax.plot_profile.set_data(self.data['rti'][n][-1], self.y) | |
|
563 | ax.plot_noise.set_data(numpy.repeat(self.data['noise'][n][-1], len(self.y)), self.y) | |
|
726 | 564 | |
|
727 |
|
|
|
565 | self.saveTime = self.min_time | |
|
728 | 566 | |
|
729 | 567 | |
|
730 | 568 | class PlotCOHData(PlotRTIData): |
|
569 | ''' | |
|
570 | Plot for Coherence data | |
|
571 | ''' | |
|
731 | 572 | |
|
732 | 573 | CODE = 'coh' |
|
733 | 574 | |
|
734 | 575 | def setup(self): |
|
735 | ||
|
576 | self.xaxis = 'time' | |
|
736 | 577 | self.ncols = 1 |
|
737 |
self.nrows = self.data |
|
|
738 | self.width = 10 | |
|
739 | self.height = 2.2*self.nrows if self.nrows<6 else 12 | |
|
740 | self.ind_plt_ch = False #just for coherence and phase | |
|
741 | if self.nrows==1: | |
|
742 | self.height += 1 | |
|
743 | self.ylabel = 'Range [Km]' | |
|
744 | self.titles = ['{} Ch{} * Ch{}'.format(self.CODE.upper(), x[0], x[1]) for x in self.dataOut.pairsList] | |
|
745 | ||
|
746 | if self.figure is None: | |
|
747 | self.figure = plt.figure(figsize=(self.width, self.height), | |
|
748 | edgecolor='k', | |
|
749 | facecolor='w') | |
|
578 | self.nrows = len(self.data.pairs) | |
|
579 | self.nplots = len(self.data.pairs) | |
|
580 | self.ylabel = 'Range [Km]' | |
|
581 | if self.CODE == 'coh': | |
|
582 | self.cb_label = '' | |
|
583 | self.titles = ['Coherence Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs] | |
|
750 | 584 | else: |
|
751 |
self. |
|
|
752 | self.axes = [] | |
|
585 | self.cb_label = 'Degrees' | |
|
586 | self.titles = ['Phase Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs] | |
|
753 | 587 | |
|
754 | for n in range(self.nrows): | |
|
755 | ax = self.figure.add_subplot(self.nrows, self.ncols, n+1) | |
|
756 | ax.firsttime = True | |
|
757 | self.axes.append(ax) | |
|
588 | ||
|
589 | class PlotPHASEData(PlotCOHData): | |
|
590 | ''' | |
|
591 | Plot for Phase map data | |
|
592 | ''' | |
|
593 | ||
|
594 | CODE = 'phase' | |
|
595 | colormap = 'seismic' | |
|
758 | 596 | |
|
759 | 597 | |
|
760 | 598 | class PlotNoiseData(PlotData): |
|
599 | ''' | |
|
600 | Plot for noise | |
|
601 | ''' | |
|
602 | ||
|
761 | 603 | CODE = 'noise' |
|
762 | 604 | |
|
763 | 605 | def setup(self): |
|
764 | ||
|
606 | self.xaxis = 'time' | |
|
765 | 607 | self.ncols = 1 |
|
766 | 608 | self.nrows = 1 |
|
767 |
self. |
|
|
768 | self.height = 3.2 | |
|
609 | self.nplots = 1 | |
|
769 | 610 | self.ylabel = 'Intensity [dB]' |
|
770 | 611 | self.titles = ['Noise'] |
|
771 | ||
|
772 | if self.figure is None: | |
|
773 | self.figure = plt.figure(figsize=(self.width, self.height), | |
|
774 | edgecolor='k', | |
|
775 | facecolor='w') | |
|
776 | else: | |
|
777 | self.figure.clf() | |
|
778 | self.axes = [] | |
|
779 | ||
|
780 | self.ax = self.figure.add_subplot(self.nrows, self.ncols, 1) | |
|
781 | self.ax.firsttime = True | |
|
612 | self.colorbar = False | |
|
782 | 613 | |
|
783 | 614 | def plot(self): |
|
784 | 615 | |
|
785 | x = self.times | |
|
616 | x = self.data.times | |
|
786 | 617 | xmin = self.min_time |
|
787 | 618 | xmax = xmin+self.xrange*60*60 |
|
788 | if self.ax.firsttime: | |
|
789 | for ch in self.dataOut.channelList: | |
|
790 | y = [self.data[self.CODE][t][ch] for t in self.times] | |
|
791 | self.ax.plot(x, y, lw=1, label='Ch{}'.format(ch)) | |
|
792 | self.ax.firsttime = False | |
|
793 | self.ax.xaxis.set_major_formatter(FuncFormatter(func)) | |
|
794 | self.ax.xaxis.set_major_locator(LinearLocator(6)) | |
|
795 | self.ax.set_ylabel(self.ylabel) | |
|
619 | Y = self.data[self.CODE] | |
|
620 | ||
|
621 | if self.axes[0].firsttime: | |
|
622 | for ch in self.data.channels: | |
|
623 | y = Y[ch] | |
|
624 | self.axes[0].plot(x, y, lw=1, label='Ch{}'.format(ch)) | |
|
796 | 625 | plt.legend() |
|
797 | 626 | else: |
|
798 |
for ch in self.data |
|
|
799 | y = [self.data[self.CODE][t][ch] for t in self.times] | |
|
800 | self.ax.lines[ch].set_data(x, y) | |
|
801 | ||
|
802 | self.ax.set_xlim(xmin, xmax) | |
|
803 | self.ax.set_ylim(min(y)-5, max(y)+5) | |
|
627 | for ch in self.data.channels: | |
|
628 | y = Y[ch] | |
|
629 | self.axes[0].lines[ch].set_data(x, y) | |
|
630 | ||
|
631 | self.ymin = numpy.nanmin(Y) - 5 | |
|
632 | self.ymax = numpy.nanmax(Y) + 5 | |
|
804 | 633 | self.saveTime = self.min_time |
|
805 | 634 | |
|
806 | 635 | |
|
807 | class PlotWindProfilerData(PlotRTIData): | |
|
808 | ||
|
809 | CODE = 'wind' | |
|
810 | colormap = 'seismic' | |
|
811 | ||
|
812 | def setup(self): | |
|
813 | self.ncols = 1 | |
|
814 | self.nrows = self.dataOut.data_output.shape[0] | |
|
815 | self.width = 10 | |
|
816 | self.height = 2.2*self.nrows | |
|
817 | self.ylabel = 'Height [Km]' | |
|
818 | self.titles = ['Zonal Wind' ,'Meridional Wind', 'Vertical Wind'] | |
|
819 | self.clabels = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)'] | |
|
820 | self.windFactor = [1, 1, 100] | |
|
821 | ||
|
822 | if self.figure is None: | |
|
823 | self.figure = plt.figure(figsize=(self.width, self.height), | |
|
824 | edgecolor='k', | |
|
825 | facecolor='w') | |
|
826 | else: | |
|
827 | self.figure.clf() | |
|
828 | self.axes = [] | |
|
829 | ||
|
830 | for n in range(self.nrows): | |
|
831 | ax = self.figure.add_subplot(self.nrows, self.ncols, n+1) | |
|
832 | ax.firsttime = True | |
|
833 | self.axes.append(ax) | |
|
834 | ||
|
835 | def plot(self): | |
|
836 | ||
|
837 | self.x = np.array(self.times) | |
|
838 | self.y = self.dataOut.heightList | |
|
839 | self.z = [] | |
|
840 | ||
|
841 | for ch in range(self.nrows): | |
|
842 | self.z.append([self.data['output'][t][ch] for t in self.times]) | |
|
843 | ||
|
844 | self.z = np.array(self.z) | |
|
845 | self.z = numpy.ma.masked_invalid(self.z) | |
|
846 | ||
|
847 | cmap=plt.get_cmap(self.colormap) | |
|
848 | cmap.set_bad('black', 1.) | |
|
849 | ||
|
850 | for n, ax in enumerate(self.axes): | |
|
851 | x, y, z = self.fill_gaps(*self.decimate()) | |
|
852 | xmin = self.min_time | |
|
853 | xmax = xmin+self.xrange*60*60 | |
|
854 | if ax.firsttime: | |
|
855 | self.ymin = self.ymin if self.ymin else np.nanmin(self.y) | |
|
856 | self.ymax = self.ymax if self.ymax else np.nanmax(self.y) | |
|
857 | self.zmax = self.zmax if self.zmax else numpy.nanmax(abs(self.z[:-1, :])) | |
|
858 | self.zmin = self.zmin if self.zmin else -self.zmax | |
|
859 | ||
|
860 | plot = ax.pcolormesh(x, y, z[n].T*self.windFactor[n], | |
|
861 | vmin=self.zmin, | |
|
862 | vmax=self.zmax, | |
|
863 | cmap=cmap | |
|
864 | ) | |
|
865 | divider = make_axes_locatable(ax) | |
|
866 | cax = divider.new_horizontal(size='2%', pad=0.05) | |
|
867 | self.figure.add_axes(cax) | |
|
868 | cb = plt.colorbar(plot, cax) | |
|
869 | cb.set_label(self.clabels[n]) | |
|
870 | ax.set_ylim(self.ymin, self.ymax) | |
|
871 | ||
|
872 | ax.xaxis.set_major_formatter(FuncFormatter(func)) | |
|
873 | ax.xaxis.set_major_locator(LinearLocator(6)) | |
|
874 | ||
|
875 | ax.set_ylabel(self.ylabel) | |
|
876 | ||
|
877 | ax.set_xlim(xmin, xmax) | |
|
878 | ax.firsttime = False | |
|
879 | else: | |
|
880 | ax.collections.remove(ax.collections[0]) | |
|
881 | ax.set_xlim(xmin, xmax) | |
|
882 | plot = ax.pcolormesh(x, y, z[n].T*self.windFactor[n], | |
|
883 | vmin=self.zmin, | |
|
884 | vmax=self.zmax, | |
|
885 | cmap=plt.get_cmap(self.colormap) | |
|
886 | ) | |
|
887 | ax.set_title('{} {}'.format(self.titles[n], | |
|
888 | datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')), | |
|
889 | size=8) | |
|
890 | ||
|
891 | self.saveTime = self.min_time | |
|
892 | ||
|
893 | ||
|
894 | 636 | class PlotSNRData(PlotRTIData): |
|
637 | ''' | |
|
638 | Plot for SNR Data | |
|
639 | ''' | |
|
640 | ||
|
895 | 641 | CODE = 'snr' |
|
896 | 642 | colormap = 'jet' |
|
897 | 643 | |
|
644 | ||
|
898 | 645 | class PlotDOPData(PlotRTIData): |
|
646 | ''' | |
|
647 | Plot for DOPPLER Data | |
|
648 | ''' | |
|
649 | ||
|
899 | 650 | CODE = 'dop' |
|
900 | 651 | colormap = 'jet' |
|
901 | 652 | |
|
902 | 653 | |
|
903 | class PlotPHASEData(PlotCOHData): | |
|
904 | CODE = 'phase' | |
|
905 | colormap = 'seismic' | |
|
906 | ||
|
907 | ||
|
908 | 654 | class PlotSkyMapData(PlotData): |
|
655 | ''' | |
|
656 | Plot for meteors detection data | |
|
657 | ''' | |
|
909 | 658 | |
|
910 | 659 | CODE = 'met' |
|
911 | 660 | |
@@ -932,7 +681,7 class PlotSkyMapData(PlotData): | |||
|
932 | 681 | |
|
933 | 682 | def plot(self): |
|
934 | 683 | |
|
935 | arrayParameters = np.concatenate([self.data['param'][t] for t in self.times]) | |
|
684 | arrayParameters = numpy.concatenate([self.data['param'][t] for t in self.data.times]) | |
|
936 | 685 | error = arrayParameters[:,-1] |
|
937 | 686 | indValid = numpy.where(error == 0)[0] |
|
938 | 687 | finalMeteor = arrayParameters[indValid,:] |
@@ -962,3 +711,72 class PlotSkyMapData(PlotData): | |||
|
962 | 711 | self.ax.set_title(title, size=8) |
|
963 | 712 | |
|
964 | 713 | self.saveTime = self.max_time |
|
714 | ||
|
715 | class PlotParamData(PlotRTIData): | |
|
716 | ''' | |
|
717 | Plot for data_param object | |
|
718 | ''' | |
|
719 | ||
|
720 | CODE = 'param' | |
|
721 | colormap = 'seismic' | |
|
722 | ||
|
723 | def setup(self): | |
|
724 | self.xaxis = 'time' | |
|
725 | self.ncols = 1 | |
|
726 | self.nrows = self.data.shape(self.CODE)[0] | |
|
727 | self.nplots = self.nrows | |
|
728 | if self.showSNR: | |
|
729 | self.nrows += 1 | |
|
730 | ||
|
731 | self.ylabel = 'Height [Km]' | |
|
732 | self.titles = self.data.parameters \ | |
|
733 | if self.data.parameters else ['Param {}'.format(x) for x in xrange(self.nrows)] | |
|
734 | if self.showSNR: | |
|
735 | self.titles.append('SNR') | |
|
736 | ||
|
737 | def plot(self): | |
|
738 | self.data.normalize_heights() | |
|
739 | self.x = self.data.times | |
|
740 | self.y = self.data.heights | |
|
741 | if self.showSNR: | |
|
742 | self.z = numpy.concatenate( | |
|
743 | (self.data[self.CODE], self.data['snr']) | |
|
744 | ) | |
|
745 | else: | |
|
746 | self.z = self.data[self.CODE] | |
|
747 | ||
|
748 | self.z = numpy.ma.masked_invalid(self.z) | |
|
749 | ||
|
750 | for n, ax in enumerate(self.axes): | |
|
751 | ||
|
752 | x, y, z = self.fill_gaps(*self.decimate()) | |
|
753 | ||
|
754 | if ax.firsttime: | |
|
755 | if self.zlimits is not None: | |
|
756 | self.zmin, self.zmax = self.zlimits[n] | |
|
757 | self.zmax = self.zmax if self.zmax is not None else numpy.nanmax(abs(self.z[:-1, :])) | |
|
758 | self.zmin = self.zmin if self.zmin is not None else -self.zmax | |
|
759 | ax.plt = ax.pcolormesh(x, y, z[n, :, :].T*self.factors[n], | |
|
760 | vmin=self.zmin, | |
|
761 | vmax=self.zmax, | |
|
762 | cmap=self.cmaps[n] | |
|
763 | ) | |
|
764 | else: | |
|
765 | if self.zlimits is not None: | |
|
766 | self.zmin, self.zmax = self.zlimits[n] | |
|
767 | ax.collections.remove(ax.collections[0]) | |
|
768 | ax.plt = ax.pcolormesh(x, y, z[n, :, :].T*self.factors[n], | |
|
769 | vmin=self.zmin, | |
|
770 | vmax=self.zmax, | |
|
771 | cmap=self.cmaps[n] | |
|
772 | ) | |
|
773 | ||
|
774 | self.saveTime = self.min_time | |
|
775 | ||
|
776 | class PlotOuputData(PlotParamData): | |
|
777 | ''' | |
|
778 | Plot data_output object | |
|
779 | ''' | |
|
780 | ||
|
781 | CODE = 'output' | |
|
782 | colormap = 'seismic' No newline at end of file |
This diff has been collapsed as it changes many lines, (2660 lines changed) Show them Hide them | |||
@@ -1,39 +1,79 | |||
|
1 | 1 | import numpy |
|
2 | 2 |
|
|
3 | 3 |
|
|
4 | import scipy | |
|
4 | 5 |
|
|
5 | 6 |
|
|
6 | 7 |
|
|
7 | 8 |
|
|
8 | 9 |
|
|
9 | 10 |
|
|
10 | ||
|
11 | from multiprocessing import Pool, TimeoutError | |
|
12 | from multiprocessing.pool import ThreadPool | |
|
13 | import copy_reg | |
|
14 | import cPickle | |
|
15 | import types | |
|
16 | from functools import partial | |
|
17 | import time | |
|
18 | #from sklearn.cluster import KMeans | |
|
19 | ||
|
20 | import matplotlib.pyplot as plt | |
|
21 | ||
|
22 | from scipy.optimize import fmin_l_bfgs_b #optimize with bounds on state papameters | |
|
11 | 23 |
|
|
12 | 24 |
|
|
25 | from scipy import asarray as ar,exp | |
|
26 | from scipy.optimize import curve_fit | |
|
13 | 27 | |
|
28 | import warnings | |
|
29 | from numpy import NaN | |
|
30 | from scipy.optimize.optimize import OptimizeWarning | |
|
31 | warnings.filterwarnings('ignore') | |
|
14 | 32 | |
|
15 | class ParametersProc(ProcessingUnit): | |
|
16 | 33 | |
|
34 | SPEED_OF_LIGHT = 299792458 | |
|
35 | ||
|
36 | ||
|
37 | '''solving pickling issue''' | |
|
38 | ||
|
39 | def _pickle_method(method): | |
|
40 | func_name = method.im_func.__name__ | |
|
41 | obj = method.im_self | |
|
42 | cls = method.im_class | |
|
43 | return _unpickle_method, (func_name, obj, cls) | |
|
44 | ||
|
45 | def _unpickle_method(func_name, obj, cls): | |
|
46 | for cls in cls.mro(): | |
|
47 | try: | |
|
48 | func = cls.__dict__[func_name] | |
|
49 | except KeyError: | |
|
50 | pass | |
|
51 | else: | |
|
52 | break | |
|
53 | return func.__get__(obj, cls) | |
|
54 | ||
|
55 | class ParametersProc(ProcessingUnit): | |
|
56 | ||
|
17 | 57 |
|
|
18 | 58 | |
|
19 | 59 |
|
|
20 | 60 |
|
|
21 | ||
|
61 | ||
|
22 | 62 |
|
|
23 | 63 |
|
|
24 | 64 |
|
|
25 | 65 |
|
|
26 | 66 |
|
|
27 | ||
|
67 | ||
|
28 | 68 |
|
|
29 | ||
|
69 | ||
|
30 | 70 |
|
|
31 | ||
|
71 | ||
|
32 | 72 |
|
|
33 | 73 |
|
|
34 | 74 |
|
|
35 | 75 |
|
|
36 | ||
|
76 | ||
|
37 | 77 |
|
|
38 | 78 |
|
|
39 | 79 |
|
@@ -55,25 +95,25 class ParametersProc(ProcessingUnit): | |||
|
55 | 95 |
|
|
56 | 96 |
|
|
57 | 97 |
|
|
58 |
|
|
|
98 | self.dataOut.heightList = self.dataIn.getHeiRange() | |
|
59 | 99 |
|
|
60 |
|
|
|
61 | ||
|
100 | # self.dataOut.noise = self.dataIn.noise | |
|
101 | ||
|
62 | 102 |
|
|
63 | ||
|
103 | ||
|
64 | 104 |
|
|
65 | ||
|
105 | ||
|
66 | 106 |
|
|
67 | 107 | |
|
68 | 108 |
|
|
69 | 109 |
|
|
70 | 110 |
|
|
71 | 111 |
|
|
72 |
|
|
|
112 | self.dataOut.paramInterval = self.dataIn.nProfiles*self.dataIn.nCohInt*self.dataIn.ippSeconds | |
|
73 | 113 |
|
|
74 | ||
|
114 | ||
|
75 | 115 |
|
|
76 | ||
|
116 | ||
|
77 | 117 |
|
|
78 | 118 | |
|
79 | 119 |
|
@@ -83,107 +123,1307 class ParametersProc(ProcessingUnit): | |||
|
83 | 123 |
|
|
84 | 124 |
|
|
85 | 125 |
|
|
86 | #self.dataOut.normFactor = self.dataIn.getNormFactor() | |
|
87 | self.dataOut.pairsList = self.dataIn.pairsList | |
|
88 | self.dataOut.groupList = self.dataIn.pairsList | |
|
89 | 126 |
|
|
127 | 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)) | |
|
129 | self.dataOut.pairsList = self.dataIn.pairsList | |
|
130 | self.dataOut.groupList = self.dataIn.pairsList | |
|
90 | 131 |
|
|
91 | ||
|
132 | ||
|
133 | if hasattr(self.dataIn, 'ChanDist'): #Distances of receiver channels | |
|
134 | self.dataOut.ChanDist = self.dataIn.ChanDist | |
|
135 | else: self.dataOut.ChanDist = None | |
|
136 | ||
|
137 | if hasattr(self.dataIn, 'VelRange'): #Velocities range | |
|
138 | self.dataOut.VelRange = self.dataIn.VelRange | |
|
139 | else: self.dataOut.VelRange = None | |
|
140 | ||
|
141 | if hasattr(self.dataIn, 'RadarConst'): #Radar Constant | |
|
142 | self.dataOut.RadarConst = self.dataIn.RadarConst | |
|
143 | ||
|
144 | if hasattr(self.dataIn, 'NPW'): #NPW | |
|
145 | self.dataOut.NPW = self.dataIn.NPW | |
|
146 | ||
|
147 | if hasattr(self.dataIn, 'COFA'): #COFA | |
|
148 | self.dataOut.COFA = self.dataIn.COFA | |
|
149 | ||
|
150 | ||
|
151 | ||
|
92 | 152 |
|
|
93 | ||
|
153 | ||
|
94 | 154 |
|
|
95 | 155 |
|
|
96 | ||
|
156 | ||
|
97 | 157 |
|
|
98 | 158 |
|
|
99 | 159 |
|
|
100 | ||
|
160 | ||
|
101 | 161 |
|
|
102 | 162 |
|
|
103 | 163 |
|
|
104 | 164 |
|
|
105 | 165 |
|
|
106 | ||
|
166 | ||
|
107 | 167 |
|
|
108 | ||
|
168 | ||
|
109 | 169 |
|
|
110 | 170 |
|
|
111 | self.dataOut.utctimeInit = self.dataIn.utctime | |
|
112 | 171 |
|
|
113 | ||
|
172 | ||
|
114 | 173 |
|
|
115 | ||
|
174 | ||
|
116 | 175 |
|
|
117 | 176 |
|
|
118 | 177 |
|
|
119 | ||
|
178 | ||
|
120 | 179 |
|
|
121 | 180 | |
|
122 | class SpectralMoments(Operation): | |
|
123 | 181 | |
|
182 | def target(tups): | |
|
183 | ||
|
184 | obj, args = tups | |
|
185 | #print 'TARGETTT', obj, args | |
|
186 | return obj.FitGau(args) | |
|
187 | ||
|
188 | class GaussianFit(Operation): | |
|
189 | ||
|
124 | 190 |
|
|
125 | Function SpectralMoments() | |
|
191 | 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 | |
|
193 | the measured spectrum - noise. | |
|
194 | ||
|
195 | Input: | |
|
196 | self.dataOut.data_pre : SelfSpectra | |
|
197 | ||
|
198 | Output: | |
|
199 | self.dataOut.GauSPC : SPC_ch1, SPC_ch2 | |
|
200 | ||
|
201 | ''' | |
|
202 | def __init__(self, **kwargs): | |
|
203 | Operation.__init__(self, **kwargs) | |
|
204 | self.i=0 | |
|
205 | ||
|
206 | ||
|
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 | |
|
208 | """This routine will find a couple of generalized Gaussians to a power spectrum | |
|
209 | input: spc | |
|
210 | output: | |
|
211 | Amplitude0,shift0,width0,p0,Amplitude1,shift1,width1,p1,noise | |
|
212 | """ | |
|
213 | ||
|
214 | self.spc = dataOut.data_pre[0].copy() | |
|
215 | ||
|
216 | ||
|
217 | print 'SelfSpectra Shape', numpy.asarray(self.spc).shape | |
|
218 | ||
|
219 | ||
|
220 | #plt.figure(50) | |
|
221 | #plt.subplot(121) | |
|
222 | #plt.plot(self.spc,'k',label='spc(66)') | |
|
223 | #plt.plot(xFrec,ySamples[1],'g',label='Ch1') | |
|
224 | #plt.plot(xFrec,ySamples[2],'r',label='Ch2') | |
|
225 | #plt.plot(xFrec,FitGauss,'yo:',label='fit') | |
|
226 | #plt.legend() | |
|
227 | #plt.title('DATOS A ALTURA DE 7500 METROS') | |
|
228 | #plt.show() | |
|
229 | ||
|
230 | self.Num_Hei = self.spc.shape[2] | |
|
231 | #self.Num_Bin = len(self.spc) | |
|
232 | self.Num_Bin = self.spc.shape[1] | |
|
233 | self.Num_Chn = self.spc.shape[0] | |
|
234 | ||
|
235 | Vrange = dataOut.abscissaList | |
|
236 | ||
|
237 | #print 'self.spc2', numpy.asarray(self.spc).shape | |
|
238 | ||
|
239 | GauSPC = numpy.empty([2,self.Num_Bin,self.Num_Hei]) | |
|
240 | SPC_ch1 = numpy.empty([self.Num_Bin,self.Num_Hei]) | |
|
241 | SPC_ch2 = numpy.empty([self.Num_Bin,self.Num_Hei]) | |
|
242 | SPC_ch1[:] = numpy.NaN | |
|
243 | SPC_ch2[:] = numpy.NaN | |
|
126 | 244 | |
|
127 | Calculates moments (power, mean, standard deviation) and SNR of the signal | |
|
245 | ||
|
246 | start_time = time.time() | |
|
247 | ||
|
248 | noise_ = dataOut.spc_noise[0].copy() | |
|
249 | ||
|
250 | ||
|
251 | ||
|
252 | pool = Pool(processes=self.Num_Chn) | |
|
253 | args = [(Vrange, Ch, pnoise, noise_, num_intg, SNRlimit) for Ch in range(self.Num_Chn)] | |
|
254 | objs = [self for __ in range(self.Num_Chn)] | |
|
255 | attrs = zip(objs, args) | |
|
256 | gauSPC = pool.map(target, attrs) | |
|
257 | dataOut.GauSPC = numpy.asarray(gauSPC) | |
|
258 | # ret = [] | |
|
259 | # for n in range(self.Num_Chn): | |
|
260 | # self.FitGau(args[n]) | |
|
261 | # dataOut.GauSPC = ret | |
|
262 | ||
|
263 | ||
|
264 | ||
|
265 | # for ch in range(self.Num_Chn): | |
|
266 | # | |
|
267 | # for ht in range(self.Num_Hei): | |
|
268 | # #print (numpy.asarray(self.spc).shape) | |
|
269 | # spc = numpy.asarray(self.spc)[ch,:,ht] | |
|
270 | # | |
|
271 | # ############################################# | |
|
272 | # # normalizing spc and noise | |
|
273 | # # This part differs from gg1 | |
|
274 | # spc_norm_max = max(spc) | |
|
275 | # spc = spc / spc_norm_max | |
|
276 | # pnoise = pnoise / spc_norm_max | |
|
277 | # ############################################# | |
|
278 | # | |
|
279 | # if abs(vel_arr[0])<15.0: # this switch is for spectra collected with different length IPP's | |
|
280 | # fatspectra=1.0 | |
|
281 | # else: | |
|
282 | # fatspectra=0.5 | |
|
283 | # | |
|
284 | # wnoise = noise_ / spc_norm_max | |
|
285 | # #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 | |
|
287 | # #if wnoise>1.1*pnoise: # to be tested later | |
|
288 | # # wnoise=pnoise | |
|
289 | # noisebl=wnoise*0.9; noisebh=wnoise*1.1 | |
|
290 | # spc=spc-wnoise | |
|
291 | # | |
|
292 | # minx=numpy.argmin(spc) | |
|
293 | # spcs=numpy.roll(spc,-minx) | |
|
294 | # cum=numpy.cumsum(spcs) | |
|
295 | # tot_noise=wnoise * self.Num_Bin #64; | |
|
296 | # #tot_signal=sum(cum[-5:])/5.; ''' How does this line work? ''' | |
|
297 | # #snr=tot_signal/tot_noise | |
|
298 | # #snr=cum[-1]/tot_noise | |
|
299 | # | |
|
300 | # #print 'spc' , spcs[5:8] , 'tot_noise', tot_noise | |
|
301 | # | |
|
302 | # snr = sum(spcs)/tot_noise | |
|
303 | # snrdB=10.*numpy.log10(snr) | |
|
304 | # | |
|
305 | # #if snrdB < -9 : | |
|
306 | # # snrdB = numpy.NaN | |
|
307 | # # continue | |
|
308 | # | |
|
309 | # #print 'snr',snrdB # , sum(spcs) , tot_noise | |
|
310 | # | |
|
311 | # | |
|
312 | # #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 | |
|
314 | # | |
|
315 | # cummax=max(cum); epsi=0.08*fatspectra # cumsum to narrow down the energy region | |
|
316 | # cumlo=cummax*epsi; | |
|
317 | # cumhi=cummax*(1-epsi) | |
|
318 | # powerindex=numpy.array(numpy.where(numpy.logical_and(cum>cumlo, cum<cumhi))[0]) | |
|
319 | # | |
|
320 | # #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 | |
|
322 | # #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: | |
|
324 | # #return [None,]*4,[None,]*4,None,snrdB,None,None,[None,]*5,[None,]*9,None | |
|
325 | # | |
|
326 | # if len(powerindex) < 1:# case for powerindex 0 | |
|
327 | # continue | |
|
328 | # powerlo=powerindex[0] | |
|
329 | # powerhi=powerindex[-1] | |
|
330 | # powerwidth=powerhi-powerlo | |
|
331 | # | |
|
332 | # firstpeak=powerlo+powerwidth/10.# first gaussian energy location | |
|
333 | # secondpeak=powerhi-powerwidth/10.#second gaussian energy location | |
|
334 | # midpeak=(firstpeak+secondpeak)/2. | |
|
335 | # firstamp=spcs[int(firstpeak)] | |
|
336 | # secondamp=spcs[int(secondpeak)] | |
|
337 | # midamp=spcs[int(midpeak)] | |
|
338 | # #x=numpy.spc.shape[1] | |
|
339 | # | |
|
340 | # #x=numpy.arange(64) | |
|
341 | # x=numpy.arange( self.Num_Bin ) | |
|
342 | # y_data=spc+wnoise | |
|
343 | # | |
|
344 | # # single gaussian | |
|
345 | # #shift0=numpy.mod(midpeak+minx,64) | |
|
346 | # shift0=numpy.mod(midpeak+minx, self.Num_Bin ) | |
|
347 | # width0=powerwidth/4.#Initialization entire power of spectrum divided by 4 | |
|
348 | # power0=2. | |
|
349 | # amplitude0=midamp | |
|
350 | # state0=[shift0,width0,amplitude0,power0,wnoise] | |
|
351 | # #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)) | |
|
353 | # #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 | |
|
355 | # lsq1=fmin_l_bfgs_b(self.misfit1,state0,args=(y_data,x,num_intg),bounds=bnds,approx_grad=True) | |
|
356 | # | |
|
357 | # chiSq1=lsq1[1]; | |
|
358 | # jack1= self.y_jacobian1(x,lsq1[0]) | |
|
359 | # | |
|
360 | # | |
|
361 | # try: | |
|
362 | # sigmas1=numpy.sqrt(chiSq1*numpy.diag(numpy.linalg.inv(numpy.dot(jack1.T,jack1)))) | |
|
363 | # except: | |
|
364 | # std1=32.; sigmas1=numpy.ones(5) | |
|
365 | # else: | |
|
366 | # std1=sigmas1[0] | |
|
367 | # | |
|
368 | # | |
|
369 | # if fatspectra<1.0 and powerwidth<4: | |
|
370 | # choice=0 | |
|
371 | # Amplitude0=lsq1[0][2] | |
|
372 | # shift0=lsq1[0][0] | |
|
373 | # width0=lsq1[0][1] | |
|
374 | # p0=lsq1[0][3] | |
|
375 | # Amplitude1=0. | |
|
376 | # shift1=0. | |
|
377 | # width1=0. | |
|
378 | # p1=0. | |
|
379 | # noise=lsq1[0][4] | |
|
380 | # #return (numpy.array([shift0,width0,Amplitude0,p0]), | |
|
381 | # # numpy.array([shift1,width1,Amplitude1,p1]),noise,snrdB,chiSq1,6.,sigmas1,[None,]*9,choice) | |
|
382 | # | |
|
383 | # # two gaussians | |
|
384 | # #shift0=numpy.mod(firstpeak+minx,64); shift1=numpy.mod(secondpeak+minx,64) | |
|
385 | # shift0=numpy.mod(firstpeak+minx, self.Num_Bin ); | |
|
386 | # shift1=numpy.mod(secondpeak+minx, self.Num_Bin ) | |
|
387 | # width0=powerwidth/6.; | |
|
388 | # width1=width0 | |
|
389 | # power0=2.; | |
|
390 | # power1=power0 | |
|
391 | # amplitude0=firstamp; | |
|
392 | # amplitude1=secondamp | |
|
393 | # 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)) | |
|
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)) | |
|
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)) | |
|
397 | # | |
|
398 | # lsq2=fmin_l_bfgs_b(self.misfit2,state0,args=(y_data,x,num_intg),bounds=bnds,approx_grad=True) | |
|
399 | # | |
|
400 | # | |
|
401 | # chiSq2=lsq2[1]; jack2=self.y_jacobian2(x,lsq2[0]) | |
|
402 | # | |
|
403 | # | |
|
404 | # try: | |
|
405 | # sigmas2=numpy.sqrt(chiSq2*numpy.diag(numpy.linalg.inv(numpy.dot(jack2.T,jack2)))) | |
|
406 | # except: | |
|
407 | # std2a=32.; std2b=32.; sigmas2=numpy.ones(9) | |
|
408 | # else: | |
|
409 | # std2a=sigmas2[0]; std2b=sigmas2[4] | |
|
410 | # | |
|
411 | # | |
|
412 | # | |
|
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) | |
|
414 | # | |
|
415 | # if snrdB>-9: # when SNR is strong pick the peak with least shift (LOS velocity) error | |
|
416 | # if oneG: | |
|
417 | # choice=0 | |
|
418 | # else: | |
|
419 | # w1=lsq2[0][1]; w2=lsq2[0][5] | |
|
420 | # a1=lsq2[0][2]; a2=lsq2[0][6] | |
|
421 | # 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; | |
|
423 | # gp1=a1*w1*s1; gp2=a2*w2*s2 # power content of each ggaussian with proper p scaling | |
|
424 | # | |
|
425 | # if gp1>gp2: | |
|
426 | # if a1>0.7*a2: | |
|
427 | # choice=1 | |
|
428 | # else: | |
|
429 | # choice=2 | |
|
430 | # elif gp2>gp1: | |
|
431 | # if a2>0.7*a1: | |
|
432 | # choice=2 | |
|
433 | # else: | |
|
434 | # choice=1 | |
|
435 | # else: | |
|
436 | # choice=numpy.argmax([a1,a2])+1 | |
|
437 | # #else: | |
|
438 | # #choice=argmin([std2a,std2b])+1 | |
|
439 | # | |
|
440 | # 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]]) | |
|
442 | # | |
|
443 | # #print 'choice',choice | |
|
444 | # | |
|
445 | # if choice==0: # pick the single gaussian fit | |
|
446 | # Amplitude0=lsq1[0][2] | |
|
447 | # shift0=lsq1[0][0] | |
|
448 | # width0=lsq1[0][1] | |
|
449 | # p0=lsq1[0][3] | |
|
450 | # Amplitude1=0. | |
|
451 | # shift1=0. | |
|
452 | # width1=0. | |
|
453 | # p1=0. | |
|
454 | # noise=lsq1[0][4] | |
|
455 | # elif choice==1: # take the first one of the 2 gaussians fitted | |
|
456 | # Amplitude0 = lsq2[0][2] | |
|
457 | # shift0 = lsq2[0][0] | |
|
458 | # width0 = lsq2[0][1] | |
|
459 | # p0 = lsq2[0][3] | |
|
460 | # Amplitude1 = lsq2[0][6] # This is 0 in gg1 | |
|
461 | # shift1 = lsq2[0][4] # This is 0 in gg1 | |
|
462 | # width1 = lsq2[0][5] # This is 0 in gg1 | |
|
463 | # p1 = lsq2[0][7] # This is 0 in gg1 | |
|
464 | # noise = lsq2[0][8] | |
|
465 | # else: # the second one | |
|
466 | # Amplitude0 = lsq2[0][6] | |
|
467 | # shift0 = lsq2[0][4] | |
|
468 | # width0 = lsq2[0][5] | |
|
469 | # p0 = lsq2[0][7] | |
|
470 | # Amplitude1 = lsq2[0][2] # This is 0 in gg1 | |
|
471 | # shift1 = lsq2[0][0] # This is 0 in gg1 | |
|
472 | # width1 = lsq2[0][1] # This is 0 in gg1 | |
|
473 | # p1 = lsq2[0][3] # This is 0 in gg1 | |
|
474 | # noise = lsq2[0][8] | |
|
475 | # | |
|
476 | # #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 | |
|
478 | # SPC_ch2[:,ht] = noise + Amplitude1*numpy.exp(-0.5*(abs(x-shift1))/width1)**p1 | |
|
479 | # #print 'SPC_ch1.shape',SPC_ch1.shape | |
|
480 | # #print 'SPC_ch2.shape',SPC_ch2.shape | |
|
481 | # #dataOut.data_param = SPC_ch1 | |
|
482 | # GauSPC[0] = SPC_ch1 | |
|
483 | # GauSPC[1] = SPC_ch2 | |
|
484 | ||
|
485 | # #plt.gcf().clear() | |
|
486 | # plt.figure(50+self.i) | |
|
487 | # self.i=self.i+1 | |
|
488 | # #plt.subplot(121) | |
|
489 | # plt.plot(self.spc,'k')#,label='spc(66)') | |
|
490 | # plt.plot(SPC_ch1[ch,ht],'b')#,label='gg1') | |
|
491 | # #plt.plot(SPC_ch2,'r')#,label='gg2') | |
|
492 | # #plt.plot(xFrec,ySamples[1],'g',label='Ch1') | |
|
493 | # #plt.plot(xFrec,ySamples[2],'r',label='Ch2') | |
|
494 | # #plt.plot(xFrec,FitGauss,'yo:',label='fit') | |
|
495 | # plt.legend() | |
|
496 | # plt.title('DATOS A ALTURA DE 7500 METROS') | |
|
497 | # plt.show() | |
|
498 | # print 'shift0', shift0 | |
|
499 | # print 'Amplitude0', Amplitude0 | |
|
500 | # print 'width0', width0 | |
|
501 | # print 'p0', p0 | |
|
502 | # print '========================' | |
|
503 | # print 'shift1', shift1 | |
|
504 | # print 'Amplitude1', Amplitude1 | |
|
505 | # print 'width1', width1 | |
|
506 | # print 'p1', p1 | |
|
507 | # print 'noise', noise | |
|
508 | # print 's_noise', wnoise | |
|
509 | ||
|
510 | print '========================================================' | |
|
511 | print 'total_time: ', time.time()-start_time | |
|
512 | ||
|
513 | # re-normalizing spc and noise | |
|
514 | # This part differs from gg1 | |
|
515 | ||
|
516 | ||
|
517 | ||
|
518 | ''' Parameters: | |
|
519 | 1. Amplitude | |
|
520 | 2. Shift | |
|
521 | 3. Width | |
|
522 | 4. Power | |
|
523 | ''' | |
|
524 | ||
|
525 | ||
|
526 | ############################################################################### | |
|
527 | def FitGau(self, X): | |
|
528 | ||
|
529 | Vrange, ch, pnoise, noise_, num_intg, SNRlimit = X | |
|
530 | #print 'VARSSSS', ch, pnoise, noise, num_intg | |
|
531 | ||
|
532 | #print 'HEIGHTS', self.Num_Hei | |
|
533 | ||
|
534 | GauSPC = [] | |
|
535 | SPC_ch1 = numpy.empty([self.Num_Bin,self.Num_Hei]) | |
|
536 | SPC_ch2 = numpy.empty([self.Num_Bin,self.Num_Hei]) | |
|
537 | SPC_ch1[:] = 0#numpy.NaN | |
|
538 | SPC_ch2[:] = 0#numpy.NaN | |
|
539 | ||
|
540 | ||
|
541 | ||
|
542 | for ht in range(self.Num_Hei): | |
|
543 | #print (numpy.asarray(self.spc).shape) | |
|
544 | ||
|
545 | #print 'TTTTT', ch , ht | |
|
546 | #print self.spc.shape | |
|
547 | ||
|
548 | ||
|
549 | spc = numpy.asarray(self.spc)[ch,:,ht] | |
|
550 | ||
|
551 | ############################################# | |
|
552 | # normalizing spc and noise | |
|
553 | # This part differs from gg1 | |
|
554 | spc_norm_max = max(spc) | |
|
555 | spc = spc / spc_norm_max | |
|
556 | pnoise = pnoise / spc_norm_max | |
|
557 | ############################################# | |
|
558 | ||
|
559 | fatspectra=1.0 | |
|
560 | ||
|
561 | wnoise = noise_ / spc_norm_max | |
|
562 | #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 | |
|
564 | # wnoise=pnoise | |
|
565 | noisebl=wnoise*0.9; noisebh=wnoise*1.1 | |
|
566 | spc=spc-wnoise | |
|
567 | # print 'wnoise', noise_[0], spc_norm_max, wnoise | |
|
568 | minx=numpy.argmin(spc) | |
|
569 | spcs=numpy.roll(spc,-minx) | |
|
570 | cum=numpy.cumsum(spcs) | |
|
571 | tot_noise=wnoise * self.Num_Bin #64; | |
|
572 | #print 'spc' , spcs[5:8] , 'tot_noise', tot_noise | |
|
573 | #tot_signal=sum(cum[-5:])/5.; ''' How does this line work? ''' | |
|
574 | #snr=tot_signal/tot_noise | |
|
575 | #snr=cum[-1]/tot_noise | |
|
576 | snr = sum(spcs)/tot_noise | |
|
577 | snrdB=10.*numpy.log10(snr) | |
|
578 | ||
|
579 | if snrdB < SNRlimit : | |
|
580 | snr = numpy.NaN | |
|
581 | SPC_ch1[:,ht] = 0#numpy.NaN | |
|
582 | SPC_ch1[:,ht] = 0#numpy.NaN | |
|
583 | GauSPC = (SPC_ch1,SPC_ch2) | |
|
584 | continue | |
|
585 | #print 'snr',snrdB #, sum(spcs) , tot_noise | |
|
586 | ||
|
587 | ||
|
588 | ||
|
589 | #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 | |
|
591 | ||
|
592 | cummax=max(cum); epsi=0.08*fatspectra # cumsum to narrow down the energy region | |
|
593 | cumlo=cummax*epsi; | |
|
594 | cumhi=cummax*(1-epsi) | |
|
595 | powerindex=numpy.array(numpy.where(numpy.logical_and(cum>cumlo, cum<cumhi))[0]) | |
|
596 | ||
|
597 | ||
|
598 | if len(powerindex) < 1:# case for powerindex 0 | |
|
599 | continue | |
|
600 | powerlo=powerindex[0] | |
|
601 | powerhi=powerindex[-1] | |
|
602 | powerwidth=powerhi-powerlo | |
|
603 | ||
|
604 | firstpeak=powerlo+powerwidth/10.# first gaussian energy location | |
|
605 | secondpeak=powerhi-powerwidth/10.#second gaussian energy location | |
|
606 | midpeak=(firstpeak+secondpeak)/2. | |
|
607 | firstamp=spcs[int(firstpeak)] | |
|
608 | secondamp=spcs[int(secondpeak)] | |
|
609 | midamp=spcs[int(midpeak)] | |
|
610 | ||
|
611 | x=numpy.arange( self.Num_Bin ) | |
|
612 | y_data=spc+wnoise | |
|
613 | ||
|
614 | # single gaussian | |
|
615 | shift0=numpy.mod(midpeak+minx, self.Num_Bin ) | |
|
616 | width0=powerwidth/4.#Initialization entire power of spectrum divided by 4 | |
|
617 | power0=2. | |
|
618 | amplitude0=midamp | |
|
619 | state0=[shift0,width0,amplitude0,power0,wnoise] | |
|
620 | 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) | |
|
622 | ||
|
623 | chiSq1=lsq1[1]; | |
|
624 | jack1= self.y_jacobian1(x,lsq1[0]) | |
|
625 | ||
|
626 | ||
|
627 | try: | |
|
628 | sigmas1=numpy.sqrt(chiSq1*numpy.diag(numpy.linalg.inv(numpy.dot(jack1.T,jack1)))) | |
|
629 | except: | |
|
630 | std1=32.; sigmas1=numpy.ones(5) | |
|
631 | else: | |
|
632 | std1=sigmas1[0] | |
|
633 | ||
|
634 | ||
|
635 | if fatspectra<1.0 and powerwidth<4: | |
|
636 | choice=0 | |
|
637 | Amplitude0=lsq1[0][2] | |
|
638 | shift0=lsq1[0][0] | |
|
639 | width0=lsq1[0][1] | |
|
640 | p0=lsq1[0][3] | |
|
641 | Amplitude1=0. | |
|
642 | shift1=0. | |
|
643 | width1=0. | |
|
644 | p1=0. | |
|
645 | noise=lsq1[0][4] | |
|
646 | #return (numpy.array([shift0,width0,Amplitude0,p0]), | |
|
647 | # numpy.array([shift1,width1,Amplitude1,p1]),noise,snrdB,chiSq1,6.,sigmas1,[None,]*9,choice) | |
|
648 | ||
|
649 | # two gaussians | |
|
650 | #shift0=numpy.mod(firstpeak+minx,64); shift1=numpy.mod(secondpeak+minx,64) | |
|
651 | shift0=numpy.mod(firstpeak+minx, self.Num_Bin ); | |
|
652 | shift1=numpy.mod(secondpeak+minx, self.Num_Bin ) | |
|
653 | width0=powerwidth/6.; | |
|
654 | width1=width0 | |
|
655 | power0=2.; | |
|
656 | power1=power0 | |
|
657 | amplitude0=firstamp; | |
|
658 | amplitude1=secondamp | |
|
659 | 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)) | |
|
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)) | |
|
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)) | |
|
663 | ||
|
664 | lsq2=fmin_l_bfgs_b(self.misfit2,state0,args=(y_data,x,num_intg),bounds=bnds,approx_grad=True) | |
|
665 | ||
|
666 | ||
|
667 | chiSq2=lsq2[1]; jack2=self.y_jacobian2(x,lsq2[0]) | |
|
668 | ||
|
669 | ||
|
670 | try: | |
|
671 | sigmas2=numpy.sqrt(chiSq2*numpy.diag(numpy.linalg.inv(numpy.dot(jack2.T,jack2)))) | |
|
672 | except: | |
|
673 | std2a=32.; std2b=32.; sigmas2=numpy.ones(9) | |
|
674 | else: | |
|
675 | std2a=sigmas2[0]; std2b=sigmas2[4] | |
|
676 | ||
|
677 | ||
|
678 | ||
|
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) | |
|
680 | ||
|
681 | if snrdB>-6: # when SNR is strong pick the peak with least shift (LOS velocity) error | |
|
682 | if oneG: | |
|
683 | choice=0 | |
|
684 | else: | |
|
685 | w1=lsq2[0][1]; w2=lsq2[0][5] | |
|
686 | a1=lsq2[0][2]; a2=lsq2[0][6] | |
|
687 | p1=lsq2[0][3]; p2=lsq2[0][7] | |
|
688 | s1=(2**(1+1./p1))*scipy.special.gamma(1./p1)/p1; | |
|
689 | 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 | |
|
691 | ||
|
692 | if gp1>gp2: | |
|
693 | if a1>0.7*a2: | |
|
694 | choice=1 | |
|
695 | else: | |
|
696 | choice=2 | |
|
697 | elif gp2>gp1: | |
|
698 | if a2>0.7*a1: | |
|
699 | choice=2 | |
|
700 | else: | |
|
701 | choice=1 | |
|
702 | else: | |
|
703 | choice=numpy.argmax([a1,a2])+1 | |
|
704 | #else: | |
|
705 | #choice=argmin([std2a,std2b])+1 | |
|
706 | ||
|
707 | 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]]) | |
|
709 | ||
|
710 | ||
|
711 | 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]) | |
|
713 | ||
|
714 | max_vel = 20 | |
|
715 | ||
|
716 | #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 | |
|
718 | shift0=lsq2[0][0] | |
|
719 | width0=lsq2[0][1] | |
|
720 | Amplitude0=lsq2[0][2] | |
|
721 | p0=lsq2[0][3] | |
|
722 | ||
|
723 | shift1=lsq2[0][4] | |
|
724 | width1=lsq2[0][5] | |
|
725 | Amplitude1=lsq2[0][6] | |
|
726 | p1=lsq2[0][7] | |
|
727 | noise=lsq2[0][8] | |
|
728 | else: | |
|
729 | shift1=lsq2[0][0] | |
|
730 | width1=lsq2[0][1] | |
|
731 | Amplitude1=lsq2[0][2] | |
|
732 | p1=lsq2[0][3] | |
|
733 | ||
|
734 | shift0=lsq2[0][4] | |
|
735 | width0=lsq2[0][5] | |
|
736 | Amplitude0=lsq2[0][6] | |
|
737 | p0=lsq2[0][7] | |
|
738 | noise=lsq2[0][8] | |
|
739 | ||
|
740 | if Amplitude0<0.1: # in case the peak is noise | |
|
741 | shift0,width0,Amplitude0,p0 = 4*[numpy.NaN] | |
|
742 | if Amplitude1<0.1: | |
|
743 | shift1,width1,Amplitude1,p1 = 4*[numpy.NaN] | |
|
744 | ||
|
745 | ||
|
746 | # if choice==0: # pick the single gaussian fit | |
|
747 | # Amplitude0=lsq1[0][2] | |
|
748 | # shift0=lsq1[0][0] | |
|
749 | # width0=lsq1[0][1] | |
|
750 | # p0=lsq1[0][3] | |
|
751 | # Amplitude1=0. | |
|
752 | # shift1=0. | |
|
753 | # width1=0. | |
|
754 | # p1=0. | |
|
755 | # noise=lsq1[0][4] | |
|
756 | # elif choice==1: # take the first one of the 2 gaussians fitted | |
|
757 | # Amplitude0 = lsq2[0][2] | |
|
758 | # shift0 = lsq2[0][0] | |
|
759 | # width0 = lsq2[0][1] | |
|
760 | # p0 = lsq2[0][3] | |
|
761 | # Amplitude1 = lsq2[0][6] # This is 0 in gg1 | |
|
762 | # shift1 = lsq2[0][4] # This is 0 in gg1 | |
|
763 | # width1 = lsq2[0][5] # This is 0 in gg1 | |
|
764 | # p1 = lsq2[0][7] # This is 0 in gg1 | |
|
765 | # noise = lsq2[0][8] | |
|
766 | # else: # the second one | |
|
767 | # Amplitude0 = lsq2[0][6] | |
|
768 | # shift0 = lsq2[0][4] | |
|
769 | # width0 = lsq2[0][5] | |
|
770 | # p0 = lsq2[0][7] | |
|
771 | # Amplitude1 = lsq2[0][2] # This is 0 in gg1 | |
|
772 | # shift1 = lsq2[0][0] # This is 0 in gg1 | |
|
773 | # width1 = lsq2[0][1] # This is 0 in gg1 | |
|
774 | # p1 = lsq2[0][3] # This is 0 in gg1 | |
|
775 | # noise = lsq2[0][8] | |
|
776 | ||
|
777 | #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 | |
|
779 | SPC_ch2[:,ht] = noise + Amplitude1*numpy.exp(-0.5*(abs(x-shift1))/width1)**p1 | |
|
780 | #print 'SPC_ch1.shape',SPC_ch1.shape | |
|
781 | #print 'SPC_ch2.shape',SPC_ch2.shape | |
|
782 | #dataOut.data_param = SPC_ch1 | |
|
783 | GauSPC = (SPC_ch1,SPC_ch2) | |
|
784 | #GauSPC[1] = SPC_ch2 | |
|
785 | ||
|
786 | # print 'shift0', shift0 | |
|
787 | # print 'Amplitude0', Amplitude0 | |
|
788 | # print 'width0', width0 | |
|
789 | # print 'p0', p0 | |
|
790 | # print '========================' | |
|
791 | # print 'shift1', shift1 | |
|
792 | # print 'Amplitude1', Amplitude1 | |
|
793 | # print 'width1', width1 | |
|
794 | # print 'p1', p1 | |
|
795 | # print 'noise', noise | |
|
796 | # print 's_noise', wnoise | |
|
797 | ||
|
798 | return GauSPC | |
|
799 | ||
|
800 | ||
|
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. | |
|
802 | y_model=self.y_model1(x,state) | |
|
803 | s0,w0,a0,p0,n=state | |
|
804 | e0=((x-s0)/w0)**2; | |
|
805 | ||
|
806 | e0u=((x-s0-self.Num_Bin)/w0)**2; | |
|
807 | ||
|
808 | e0d=((x-s0+self.Num_Bin)/w0)**2 | |
|
809 | m0=numpy.exp(-0.5*e0**(p0/2.)); | |
|
810 | m0u=numpy.exp(-0.5*e0u**(p0/2.)); | |
|
811 | m0d=numpy.exp(-0.5*e0d**(p0/2.)) | |
|
812 | 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) | |
|
814 | ||
|
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) | |
|
816 | ||
|
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 | |
|
818 | 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 | |
|
820 | ||
|
821 | def y_jacobian2(self,x,state): | |
|
822 | y_model=self.y_model2(x,state) | |
|
823 | s0,w0,a0,p0,s1,w1,a1,p1,n=state | |
|
824 | e0=((x-s0)/w0)**2; | |
|
825 | ||
|
826 | e0u=((x-s0- self.Num_Bin )/w0)**2; | |
|
827 | ||
|
828 | e0d=((x-s0+ self.Num_Bin )/w0)**2 | |
|
829 | e1=((x-s1)/w1)**2; | |
|
830 | ||
|
831 | e1u=((x-s1- self.Num_Bin )/w1)**2; | |
|
832 | ||
|
833 | e1d=((x-s1+ self.Num_Bin )/w1)**2 | |
|
834 | m0=numpy.exp(-0.5*e0**(p0/2.)); | |
|
835 | m0u=numpy.exp(-0.5*e0u**(p0/2.)); | |
|
836 | m0d=numpy.exp(-0.5*e0d**(p0/2.)) | |
|
837 | m1=numpy.exp(-0.5*e1**(p1/2.)); | |
|
838 | m1u=numpy.exp(-0.5*e1u**(p1/2.)); | |
|
839 | m1d=numpy.exp(-0.5*e1d**(p1/2.)) | |
|
840 | JA=m0+m0u+m0d | |
|
841 | 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) | |
|
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) | |
|
844 | ||
|
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) | |
|
846 | ||
|
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) | |
|
848 | ||
|
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 | |
|
850 | ||
|
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 | |
|
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]) | |
|
853 | return jack2.T | |
|
854 | ||
|
855 | def y_model1(self,x,state): | |
|
856 | shift0,width0,amplitude0,power0,noise=state | |
|
857 | model0=amplitude0*numpy.exp(-0.5*abs((x-shift0)/width0)**power0) | |
|
858 | ||
|
859 | model0u=amplitude0*numpy.exp(-0.5*abs((x-shift0- self.Num_Bin )/width0)**power0) | |
|
860 | ||
|
861 | model0d=amplitude0*numpy.exp(-0.5*abs((x-shift0+ self.Num_Bin )/width0)**power0) | |
|
862 | return model0+model0u+model0d+noise | |
|
863 | ||
|
864 | def y_model2(self,x,state): #Equation for two generalized Gaussians with Nyquist | |
|
865 | shift0,width0,amplitude0,power0,shift1,width1,amplitude1,power1,noise=state | |
|
866 | model0=amplitude0*numpy.exp(-0.5*abs((x-shift0)/width0)**power0) | |
|
867 | ||
|
868 | model0u=amplitude0*numpy.exp(-0.5*abs((x-shift0- self.Num_Bin )/width0)**power0) | |
|
869 | ||
|
870 | 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) | |
|
872 | ||
|
873 | model1u=amplitude1*numpy.exp(-0.5*abs((x-shift1- self.Num_Bin )/width1)**power1) | |
|
874 | ||
|
875 | model1d=amplitude1*numpy.exp(-0.5*abs((x-shift1+ self.Num_Bin )/width1)**power1) | |
|
876 | return model0+model0u+model0d+model1+model1u+model1d+noise | |
|
877 | ||
|
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. | |
|
128 | 879 | |
|
129 | Type of dataIn: Spectra | |
|
880 | return num_intg*sum((numpy.log(y_data)-numpy.log(self.y_model1(x,state)))**2)#/(64-5.) # /(64-5.) can be commented | |
|
881 | ||
|
882 | 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.) | |
|
884 | ||
|
130 | 885 | |
|
131 | Configuration Parameters: | |
|
886 | class PrecipitationProc(Operation): | |
|
887 | ||
|
888 | ''' | |
|
889 | Operator that estimates Reflectivity factor (Z), and estimates rainfall Rate (R) | |
|
890 | ||
|
891 | Input: | |
|
892 | self.dataOut.data_pre : SelfSpectra | |
|
893 | ||
|
894 | Output: | |
|
895 | ||
|
896 | self.dataOut.data_output : Reflectivity factor, rainfall Rate | |
|
897 | ||
|
898 | ||
|
899 | Parameters affected: | |
|
900 | ''' | |
|
901 | ||
|
902 | ||
|
903 | 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): | |
|
905 | ||
|
906 | self.spc = dataOut.data_pre[0].copy() | |
|
907 | self.Num_Hei = self.spc.shape[2] | |
|
908 | self.Num_Bin = self.spc.shape[1] | |
|
909 | self.Num_Chn = self.spc.shape[0] | |
|
910 | ||
|
911 | Velrange = dataOut.abscissaList | |
|
912 | ||
|
913 | if radar == "MIRA35C" : | |
|
914 | ||
|
915 | Ze = self.dBZeMODE2(dataOut) | |
|
916 | ||
|
917 | else: | |
|
918 | ||
|
919 | self.Pt = Pt | |
|
920 | self.Gt = Gt | |
|
921 | self.Gr = Gr | |
|
922 | self.Lambda = Lambda | |
|
923 | self.aL = aL | |
|
924 | self.tauW = tauW | |
|
925 | self.ThetaT = ThetaT | |
|
926 | self.ThetaR = ThetaR | |
|
927 | ||
|
928 | RadarConstant = GetRadarConstant() | |
|
929 | SPCmean = numpy.mean(self.spc,0) | |
|
930 | ETA = numpy.zeros(self.Num_Hei) | |
|
931 | Pr = numpy.sum(SPCmean,0) | |
|
932 | ||
|
933 | #for R in range(self.Num_Hei): | |
|
934 | # ETA[R] = RadarConstant * Pr[R] * R**2 #Reflectivity (ETA) | |
|
935 | ||
|
936 | D_range = numpy.zeros(self.Num_Hei) | |
|
937 | EqSec = numpy.zeros(self.Num_Hei) | |
|
938 | del_V = numpy.zeros(self.Num_Hei) | |
|
939 | ||
|
940 | for R in range(self.Num_Hei): | |
|
941 | ETA[R] = RadarConstant * Pr[R] * R**2 #Reflectivity (ETA) | |
|
942 | ||
|
943 | 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 | |
|
945 | ||
|
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 | |
|
947 | SIGMA[R] = numpy.pi**5 / Lambda**4 * Km * D_range[R]**6 #Equivalent Section of drops (sigma) | |
|
948 | ||
|
949 | N_dist[R] = ETA[R] / SIGMA[R] | |
|
950 | ||
|
951 | Ze = (ETA * Lambda**4) / (numpy.pi * Km) | |
|
952 | 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 | |
|
954 | ||
|
955 | ||
|
956 | RR = (Ze/200)**(1/1.6) | |
|
957 | dBRR = 10*numpy.log10(RR) | |
|
958 | ||
|
959 | dBZe = 10*numpy.log10(Ze) | |
|
960 | dataOut.data_output = Ze | |
|
961 | dataOut.data_param = numpy.ones([2,self.Num_Hei]) | |
|
962 | dataOut.channelList = [0,1] | |
|
963 | print 'channelList', dataOut.channelList | |
|
964 | dataOut.data_param[0]=dBZe | |
|
965 | dataOut.data_param[1]=dBRR | |
|
966 | print 'RR SHAPE', dBRR.shape | |
|
967 | print 'Ze SHAPE', dBZe.shape | |
|
968 | print 'dataOut.data_param SHAPE', dataOut.data_param.shape | |
|
969 | ||
|
970 | ||
|
971 | def dBZeMODE2(self, dataOut): # Processing for MIRA35C | |
|
972 | ||
|
973 | NPW = dataOut.NPW | |
|
974 | COFA = dataOut.COFA | |
|
975 | ||
|
976 | SNR = numpy.array([self.spc[0,:,:] / NPW[0]]) #, self.spc[1,:,:] / NPW[1]]) | |
|
977 | RadarConst = dataOut.RadarConst | |
|
978 | #frequency = 34.85*10**9 | |
|
979 | ||
|
980 | ETA = numpy.zeros(([self.Num_Chn ,self.Num_Hei])) | |
|
981 | data_output = numpy.ones([self.Num_Chn , self.Num_Hei])*numpy.NaN | |
|
982 | ||
|
983 | ETA = numpy.sum(SNR,1) | |
|
984 | print 'ETA' , ETA | |
|
985 | ETA = numpy.where(ETA is not 0. , ETA, numpy.NaN) | |
|
986 | ||
|
987 | Ze = numpy.ones([self.Num_Chn, self.Num_Hei] ) | |
|
988 | ||
|
989 | for r in range(self.Num_Hei): | |
|
990 | ||
|
991 | 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) | |
|
993 | ||
|
994 | return Ze | |
|
995 | ||
|
996 | def GetRadarConstant(self): | |
|
997 | ||
|
998 | """ | |
|
999 | Constants: | |
|
1000 | ||
|
1001 | Pt: Transmission Power dB | |
|
1002 | Gt: Transmission Gain dB | |
|
1003 | Gr: Reception Gain dB | |
|
1004 | Lambda: Wavelenght m | |
|
1005 | aL: Attenuation loses dB | |
|
1006 | tauW: Width of transmission pulse s | |
|
1007 | ThetaT: Transmission antenna bean angle rad | |
|
1008 | ThetaR: Reception antenna beam angle rad | |
|
1009 | ||
|
1010 | """ | |
|
1011 | 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) | |
|
1013 | RadarConstant = Numerator / Denominator | |
|
1014 | ||
|
1015 | return RadarConstant | |
|
1016 | ||
|
1017 | ||
|
1018 | ||
|
1019 | class FullSpectralAnalysis(Operation): | |
|
1020 | ||
|
1021 | """ | |
|
1022 | Function that implements Full Spectral Analisys technique. | |
|
1023 | ||
|
1024 | Input: | |
|
1025 | self.dataOut.data_pre : SelfSpectra and CrossSPectra data | |
|
1026 | self.dataOut.groupList : Pairlist of channels | |
|
1027 | self.dataOut.ChanDist : Physical distance between receivers | |
|
1028 | ||
|
1029 | ||
|
1030 | Output: | |
|
1031 | ||
|
1032 | self.dataOut.data_output : Zonal wind, Meridional wind and Vertical wind | |
|
1033 | ||
|
1034 | ||
|
1035 | Parameters affected: Winds, height range, SNR | |
|
1036 | ||
|
1037 | """ | |
|
1038 | def run(self, dataOut, E01=None, E02=None, E12=None, N01=None, N02=None, N12=None, SNRlimit=7): | |
|
1039 | ||
|
1040 | spc = dataOut.data_pre[0].copy() | |
|
1041 | cspc = dataOut.data_pre[1].copy() | |
|
1042 | ||
|
1043 | nChannel = spc.shape[0] | |
|
1044 | nProfiles = spc.shape[1] | |
|
1045 | nHeights = spc.shape[2] | |
|
1046 | ||
|
1047 | pairsList = dataOut.groupList | |
|
1048 | if dataOut.ChanDist is not None : | |
|
1049 | ChanDist = dataOut.ChanDist | |
|
1050 | else: | |
|
1051 | ChanDist = numpy.array([[E01, N01],[E02,N02],[E12,N12]]) | |
|
1052 | ||
|
1053 | #print 'ChanDist', ChanDist | |
|
1054 | ||
|
1055 | if dataOut.VelRange is not None: | |
|
1056 | VelRange= dataOut.VelRange | |
|
1057 | else: | |
|
1058 | VelRange= dataOut.abscissaList | |
|
1059 | ||
|
1060 | ySamples=numpy.ones([nChannel,nProfiles]) | |
|
1061 | phase=numpy.ones([nChannel,nProfiles]) | |
|
1062 | CSPCSamples=numpy.ones([nChannel,nProfiles],dtype=numpy.complex_) | |
|
1063 | coherence=numpy.ones([nChannel,nProfiles]) | |
|
1064 | PhaseSlope=numpy.ones(nChannel) | |
|
1065 | PhaseInter=numpy.ones(nChannel) | |
|
1066 | dataSNR = dataOut.data_SNR | |
|
1067 | ||
|
1068 | ||
|
1069 | ||
|
1070 | data = dataOut.data_pre | |
|
1071 | noise = dataOut.noise | |
|
1072 | print 'noise',noise | |
|
1073 | #SNRdB = 10*numpy.log10(dataOut.data_SNR) | |
|
1074 | ||
|
1075 | FirstMoment = numpy.average(dataOut.data_param[:,1,:],0) | |
|
1076 | #SNRdBMean = [] | |
|
132 | 1077 | |
|
1078 | ||
|
1079 | #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]])) | |
|
1081 | # SNRdBMean = numpy.append(SNRdBMean,numpy.mean([SNRdB[0,j],SNRdB[1,j],SNRdB[2,j]])) | |
|
1082 | ||
|
1083 | data_output=numpy.ones([3,spc.shape[2]])*numpy.NaN | |
|
1084 | ||
|
1085 | velocityX=[] | |
|
1086 | velocityY=[] | |
|
1087 | velocityV=[] | |
|
1088 | ||
|
1089 | dbSNR = 10*numpy.log10(dataSNR) | |
|
1090 | dbSNR = numpy.average(dbSNR,0) | |
|
1091 | for Height in range(nHeights): | |
|
1092 | ||
|
1093 | [Vzon,Vmer,Vver, GaussCenter]= self.WindEstimation(spc, cspc, pairsList, ChanDist, Height, noise, VelRange, dbSNR[Height], SNRlimit) | |
|
1094 | ||
|
1095 | if abs(Vzon)<100. and abs(Vzon)> 0.: | |
|
1096 | velocityX=numpy.append(velocityX, Vzon)#Vmag | |
|
1097 | ||
|
1098 | else: | |
|
1099 | print 'Vzon',Vzon | |
|
1100 | velocityX=numpy.append(velocityX, numpy.NaN) | |
|
1101 | ||
|
1102 | if abs(Vmer)<100. and abs(Vmer) > 0.: | |
|
1103 | velocityY=numpy.append(velocityY, Vmer)#Vang | |
|
1104 | ||
|
1105 | else: | |
|
1106 | print 'Vmer',Vmer | |
|
1107 | velocityY=numpy.append(velocityY, numpy.NaN) | |
|
1108 | ||
|
1109 | if dbSNR[Height] > SNRlimit: | |
|
1110 | velocityV=numpy.append(velocityV, FirstMoment[Height]) | |
|
1111 | else: | |
|
1112 | velocityV=numpy.append(velocityV, numpy.NaN) | |
|
1113 | #FirstMoment[Height]= numpy.NaN | |
|
1114 | # if SNRdBMean[Height] <12: | |
|
1115 | # FirstMoment[Height] = numpy.NaN | |
|
1116 | # velocityX[Height] = numpy.NaN | |
|
1117 | # velocityY[Height] = numpy.NaN | |
|
1118 | ||
|
1119 | ||
|
1120 | data_output[0]=numpy.array(velocityX) | |
|
1121 | data_output[1]=numpy.array(velocityY) | |
|
1122 | data_output[2]=-velocityV#FirstMoment | |
|
1123 | ||
|
1124 | print ' ' | |
|
1125 | #print 'FirstMoment' | |
|
1126 | #print FirstMoment | |
|
1127 | print 'velocityX',data_output[0] | |
|
1128 | print ' ' | |
|
1129 | print 'velocityY',data_output[1] | |
|
1130 | #print numpy.array(velocityY) | |
|
1131 | print ' ' | |
|
1132 | #print 'SNR' | |
|
1133 | #print 10*numpy.log10(dataOut.data_SNR) | |
|
1134 | #print numpy.shape(10*numpy.log10(dataOut.data_SNR)) | |
|
1135 | print ' ' | |
|
1136 | ||
|
1137 | ||
|
1138 | dataOut.data_output=data_output | |
|
1139 | return | |
|
1140 | ||
|
1141 | ||
|
1142 | def moving_average(self,x, N=2): | |
|
1143 | return numpy.convolve(x, numpy.ones((N,))/N)[(N-1):] | |
|
1144 | ||
|
1145 | def gaus(self,xSamples,a,x0,sigma): | |
|
1146 | return a*numpy.exp(-(xSamples-x0)**2/(2*sigma**2)) | |
|
1147 | ||
|
1148 | def Find(self,x,value): | |
|
1149 | for index in range(len(x)): | |
|
1150 | if x[index]==value: | |
|
1151 | return index | |
|
1152 | ||
|
1153 | def WindEstimation(self, spc, cspc, pairsList, ChanDist, Height, noise, VelRange, dbSNR, SNRlimit): | |
|
1154 | ||
|
1155 | ySamples=numpy.ones([spc.shape[0],spc.shape[1]]) | |
|
1156 | phase=numpy.ones([spc.shape[0],spc.shape[1]]) | |
|
1157 | CSPCSamples=numpy.ones([spc.shape[0],spc.shape[1]],dtype=numpy.complex_) | |
|
1158 | coherence=numpy.ones([spc.shape[0],spc.shape[1]]) | |
|
1159 | PhaseSlope=numpy.ones(spc.shape[0]) | |
|
1160 | PhaseInter=numpy.ones(spc.shape[0]) | |
|
1161 | xFrec=VelRange | |
|
1162 | ||
|
1163 | '''Getting Eij and Nij''' | |
|
1164 | ||
|
1165 | E01=ChanDist[0][0] | |
|
1166 | N01=ChanDist[0][1] | |
|
1167 | ||
|
1168 | E02=ChanDist[1][0] | |
|
1169 | N02=ChanDist[1][1] | |
|
1170 | ||
|
1171 | E12=ChanDist[2][0] | |
|
1172 | N12=ChanDist[2][1] | |
|
1173 | ||
|
1174 | z = spc.copy() | |
|
1175 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
|
1176 | ||
|
1177 | for i in range(spc.shape[0]): | |
|
1178 | ||
|
1179 | '''****** Line of Data SPC ******''' | |
|
1180 | zline=z[i,:,Height] | |
|
1181 | ||
|
1182 | '''****** SPC is normalized ******''' | |
|
1183 | FactNorm= (zline.copy()-noise[i]) / numpy.sum(zline.copy()) | |
|
1184 | FactNorm= FactNorm/numpy.sum(FactNorm) | |
|
1185 | ||
|
1186 | SmoothSPC=self.moving_average(FactNorm,N=3) | |
|
1187 | ||
|
1188 | xSamples = ar(range(len(SmoothSPC))) | |
|
1189 | ySamples[i] = SmoothSPC | |
|
1190 | ||
|
1191 | #dbSNR=10*numpy.log10(dataSNR) | |
|
1192 | print ' ' | |
|
1193 | print ' ' | |
|
1194 | print ' ' | |
|
1195 | ||
|
1196 | #print 'dataSNR', dbSNR.shape, dbSNR[0,40:120] | |
|
1197 | print 'SmoothSPC', SmoothSPC.shape, SmoothSPC[0:20] | |
|
1198 | print 'noise',noise | |
|
1199 | print 'zline',zline.shape, zline[0:20] | |
|
1200 | print 'FactNorm',FactNorm.shape, FactNorm[0:20] | |
|
1201 | print 'FactNorm suma', numpy.sum(FactNorm) | |
|
1202 | ||
|
1203 | for i in range(spc.shape[0]): | |
|
1204 | ||
|
1205 | '''****** Line of Data CSPC ******''' | |
|
1206 | cspcLine=cspc[i,:,Height].copy() | |
|
1207 | ||
|
1208 | '''****** CSPC is normalized ******''' | |
|
1209 | chan_index0 = pairsList[i][0] | |
|
1210 | chan_index1 = pairsList[i][1] | |
|
1211 | CSPCFactor= abs(numpy.sum(ySamples[chan_index0]) * numpy.sum(ySamples[chan_index1])) # | |
|
1212 | ||
|
1213 | CSPCNorm = (cspcLine.copy() -noise[i]) / numpy.sqrt(CSPCFactor) | |
|
1214 | ||
|
1215 | CSPCSamples[i] = CSPCNorm | |
|
1216 | coherence[i] = numpy.abs(CSPCSamples[i]) / numpy.sqrt(CSPCFactor) | |
|
1217 | ||
|
1218 | coherence[i]= self.moving_average(coherence[i],N=2) | |
|
1219 | ||
|
1220 | phase[i] = self.moving_average( numpy.arctan2(CSPCSamples[i].imag, CSPCSamples[i].real),N=1)#*180/numpy.pi | |
|
1221 | ||
|
1222 | print 'cspcLine', cspcLine.shape, cspcLine[0:20] | |
|
1223 | print 'CSPCFactor', CSPCFactor#, CSPCFactor[0:20] | |
|
1224 | print numpy.sum(ySamples[chan_index0]), numpy.sum(ySamples[chan_index1]), -noise[i] | |
|
1225 | print 'CSPCNorm', CSPCNorm.shape, CSPCNorm[0:20] | |
|
1226 | print 'CSPCNorm suma', numpy.sum(CSPCNorm) | |
|
1227 | print 'CSPCSamples', CSPCSamples.shape, CSPCSamples[0,0:20] | |
|
1228 | ||
|
1229 | '''****** Getting fij width ******''' | |
|
1230 | ||
|
1231 | yMean=[] | |
|
1232 | yMean2=[] | |
|
1233 | ||
|
1234 | for j in range(len(ySamples[1])): | |
|
1235 | yMean=numpy.append(yMean,numpy.mean([ySamples[0,j],ySamples[1,j],ySamples[2,j]])) | |
|
1236 | ||
|
1237 | '''******* Getting fitting Gaussian ******''' | |
|
1238 | meanGauss=sum(xSamples*yMean) / len(xSamples) | |
|
1239 | sigma=sum(yMean*(xSamples-meanGauss)**2) / len(xSamples) | |
|
1240 | ||
|
1241 | print '****************************' | |
|
1242 | print 'len(xSamples): ',len(xSamples) | |
|
1243 | print 'yMean: ', yMean.shape, yMean[0:20] | |
|
1244 | print 'ySamples', ySamples.shape, ySamples[0,0:20] | |
|
1245 | print 'xSamples: ',xSamples.shape, xSamples[0:20] | |
|
1246 | ||
|
1247 | print 'meanGauss',meanGauss | |
|
1248 | print 'sigma',sigma | |
|
1249 | ||
|
1250 | #if (abs(meanGauss/sigma**2) > 0.0001) : #0.000000001): | |
|
1251 | if dbSNR > SNRlimit : | |
|
1252 | try: | |
|
1253 | popt,pcov = curve_fit(self.gaus,xSamples,yMean,p0=[1,meanGauss,sigma]) | |
|
1254 | ||
|
1255 | if numpy.amax(popt)>numpy.amax(yMean)*0.3: | |
|
1256 | FitGauss=self.gaus(xSamples,*popt) | |
|
1257 | ||
|
1258 | else: | |
|
1259 | FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean) | |
|
1260 | print 'Verificador: Dentro', Height | |
|
1261 | except :#RuntimeError: | |
|
1262 | FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean) | |
|
1263 | ||
|
1264 | ||
|
1265 | else: | |
|
1266 | FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean) | |
|
1267 | ||
|
1268 | Maximun=numpy.amax(yMean) | |
|
1269 | eMinus1=Maximun*numpy.exp(-1)#*0.8 | |
|
1270 | ||
|
1271 | HWpos=self.Find(FitGauss,min(FitGauss, key=lambda value:abs(value-eMinus1))) | |
|
1272 | HalfWidth= xFrec[HWpos] | |
|
1273 | GCpos=self.Find(FitGauss, numpy.amax(FitGauss)) | |
|
1274 | Vpos=self.Find(FactNorm, numpy.amax(FactNorm)) | |
|
1275 | ||
|
1276 | #Vpos=FirstMoment[] | |
|
1277 | ||
|
1278 | '''****** Getting Fij ******''' | |
|
1279 | ||
|
1280 | GaussCenter=xFrec[GCpos] | |
|
1281 | if (GaussCenter<0 and HalfWidth>0) or (GaussCenter>0 and HalfWidth<0): | |
|
1282 | Fij=abs(GaussCenter)+abs(HalfWidth)+0.0000001 | |
|
1283 | else: | |
|
1284 | Fij=abs(GaussCenter-HalfWidth)+0.0000001 | |
|
1285 | ||
|
1286 | '''****** Getting Frecuency range of significant data ******''' | |
|
1287 | ||
|
1288 | Rangpos=self.Find(FitGauss,min(FitGauss, key=lambda value:abs(value-Maximun*0.10))) | |
|
1289 | ||
|
1290 | if Rangpos<GCpos: | |
|
1291 | Range=numpy.array([Rangpos,2*GCpos-Rangpos]) | |
|
1292 | elif Rangpos< ( len(xFrec)- len(xFrec)*0.1): | |
|
1293 | Range=numpy.array([2*GCpos-Rangpos,Rangpos]) | |
|
1294 | else: | |
|
1295 | Range = numpy.array([0,0]) | |
|
1296 | ||
|
1297 | print ' ' | |
|
1298 | print 'GCpos',GCpos, ( len(xFrec)- len(xFrec)*0.1) | |
|
1299 | print 'Rangpos',Rangpos | |
|
1300 | print 'RANGE: ', Range | |
|
1301 | FrecRange=xFrec[Range[0]:Range[1]] | |
|
1302 | ||
|
1303 | '''****** Getting SCPC Slope ******''' | |
|
1304 | ||
|
1305 | for i in range(spc.shape[0]): | |
|
1306 | ||
|
1307 | 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) | |
|
1309 | ||
|
1310 | print 'FrecRange', len(FrecRange) , FrecRange | |
|
1311 | print 'PhaseRange', len(PhaseRange), PhaseRange | |
|
1312 | print ' ' | |
|
1313 | if len(FrecRange) == len(PhaseRange): | |
|
1314 | slope, intercept, r_value, p_value, std_err = stats.linregress(FrecRange,PhaseRange) | |
|
1315 | PhaseSlope[i]=slope | |
|
1316 | PhaseInter[i]=intercept | |
|
1317 | else: | |
|
1318 | PhaseSlope[i]=0 | |
|
1319 | PhaseInter[i]=0 | |
|
1320 | else: | |
|
1321 | PhaseSlope[i]=0 | |
|
1322 | PhaseInter[i]=0 | |
|
1323 | ||
|
1324 | '''Getting constant C''' | |
|
1325 | cC=(Fij*numpy.pi)**2 | |
|
1326 | ||
|
1327 | '''****** Getting constants F and G ******''' | |
|
1328 | MijEijNij=numpy.array([[E02,N02], [E12,N12]]) | |
|
1329 | MijResult0=(-PhaseSlope[1]*cC) / (2*numpy.pi) | |
|
1330 | MijResult1=(-PhaseSlope[2]*cC) / (2*numpy.pi) | |
|
1331 | MijResults=numpy.array([MijResult0,MijResult1]) | |
|
1332 | (cF,cG) = numpy.linalg.solve(MijEijNij, MijResults) | |
|
1333 | ||
|
1334 | '''****** Getting constants A, B and H ******''' | |
|
1335 | W01=numpy.amax(coherence[0]) | |
|
1336 | W02=numpy.amax(coherence[1]) | |
|
1337 | W12=numpy.amax(coherence[2]) | |
|
1338 | ||
|
1339 | 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)) | |
|
1341 | WijResult2=((cF*E12+cG*N12)**2)/cC - numpy.log(W12 / numpy.sqrt(numpy.pi/cC)) | |
|
1342 | ||
|
1343 | WijResults=numpy.array([WijResult0, WijResult1, WijResult2]) | |
|
1344 | ||
|
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] ]) | |
|
1346 | (cA,cB,cH) = numpy.linalg.solve(WijEijNij, WijResults) | |
|
1347 | ||
|
1348 | VxVy=numpy.array([[cA,cH],[cH,cB]]) | |
|
1349 | ||
|
1350 | VxVyResults=numpy.array([-cF,-cG]) | |
|
1351 | (Vx,Vy) = numpy.linalg.solve(VxVy, VxVyResults) | |
|
1352 | ||
|
1353 | Vzon = Vy | |
|
1354 | Vmer = Vx | |
|
1355 | Vmag=numpy.sqrt(Vzon**2+Vmer**2) | |
|
1356 | Vang=numpy.arctan2(Vmer,Vzon) | |
|
1357 | Vver=xFrec[Vpos] | |
|
1358 | print 'vzon y vmer', Vzon, Vmer | |
|
1359 | return Vzon, Vmer, Vver, GaussCenter | |
|
1360 | ||
|
1361 | class SpectralMoments(Operation): | |
|
1362 | ||
|
1363 | ''' | |
|
1364 | Function SpectralMoments() | |
|
1365 | ||
|
1366 | Calculates moments (power, mean, standard deviation) and SNR of the signal | |
|
1367 | ||
|
1368 | Type of dataIn: Spectra | |
|
1369 | ||
|
1370 | Configuration Parameters: | |
|
1371 | ||
|
133 | 1372 | dirCosx : Cosine director in X axis |
|
134 | 1373 | dirCosy : Cosine director in Y axis |
|
135 | ||
|
1374 | ||
|
136 | 1375 | elevation : |
|
137 | 1376 | azimuth : |
|
138 | ||
|
1377 | ||
|
139 | 1378 | Input: |
|
140 | channelList : simple channel list to select e.g. [2,3,7] | |
|
1379 | channelList : simple channel list to select e.g. [2,3,7] | |
|
141 | 1380 | self.dataOut.data_pre : Spectral data |
|
142 | 1381 | self.dataOut.abscissaList : List of frequencies |
|
143 | 1382 | self.dataOut.noise : Noise level per channel |
|
144 | ||
|
1383 | ||
|
145 | 1384 | Affected: |
|
146 | 1385 | self.dataOut.data_param : Parameters per channel |
|
147 | 1386 | self.dataOut.data_SNR : SNR per channel |
|
148 | ||
|
1387 | ||
|
149 | 1388 | ''' |
|
150 | ||
|
1389 | ||
|
151 | 1390 |
|
|
152 | ||
|
1391 | ||
|
153 | 1392 |
|
|
154 | 1393 |
|
|
155 | 1394 |
|
|
156 | 1395 |
|
|
157 | 1396 |
|
|
158 | 1397 |
|
|
159 | ||
|
1398 | ||
|
160 | 1399 |
|
|
161 |
|
|
|
162 | ||
|
1400 | data_param[ind,:,:] = self.__calculateMoments( data[ind,:,:] , absc , noise[ind] ) | |
|
1401 | ||
|
163 | 1402 |
|
|
164 | 1403 |
|
|
165 | 1404 |
|
|
166 | 1405 |
|
|
167 | 1406 |
|
|
168 | 1407 |
|
|
169 | ||
|
170 | def __calculateMoments(self, oldspec, oldfreq, n0, nicoh = None, graph = None, smooth = None, type1 = None, fwindow = None, snrth = None, dc = None, aliasing = None, oldfd = None, wwauto = None): | |
|
171 | ||
|
172 | if (nicoh is None): nicoh = 1 | |
|
173 |
|
|
|
174 |
|
|
|
1408 | ||
|
1409 | 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): | |
|
1411 | ||
|
1412 | if (nicoh == None): nicoh = 1 | |
|
1413 | if (graph == None): graph = 0 | |
|
1414 | if (smooth == None): smooth = 0 | |
|
175 | 1415 |
|
|
176 | 1416 | |
|
177 |
|
|
|
178 |
|
|
|
179 |
|
|
|
180 |
|
|
|
181 |
|
|
|
182 |
|
|
|
183 |
|
|
|
184 | ||
|
1417 | if (type1 == None): type1 = 0 | |
|
1418 | if (fwindow == None): fwindow = numpy.zeros(oldfreq.size) + 1 | |
|
1419 | if (snrth == None): snrth = -3 | |
|
1420 | if (dc == None): dc = 0 | |
|
1421 | if (aliasing == None): aliasing = 0 | |
|
1422 | if (oldfd == None): oldfd = 0 | |
|
1423 | if (wwauto == None): wwauto = 0 | |
|
1424 | ||
|
185 | 1425 |
|
|
186 | ||
|
1426 | ||
|
187 | 1427 |
|
|
188 | 1428 |
|
|
189 | 1429 |
|
@@ -191,86 +1431,86 class SpectralMoments(Operation): | |||
|
191 | 1431 |
|
|
192 | 1432 | |
|
193 | 1433 |
|
|
194 | ||
|
1434 | ||
|
195 | 1435 |
|
|
196 | 1436 |
|
|
197 | 1437 |
|
|
198 | 1438 |
|
|
199 | ||
|
200 |
|
|
|
1439 | ||
|
1440 | #Smooth | |
|
201 | 1441 |
|
|
202 | 1442 |
|
|
203 | ||
|
1443 | ||
|
204 | 1444 |
|
|
205 | 1445 |
|
|
206 | 1446 |
|
|
207 | 1447 |
|
|
208 | ||
|
1448 | ||
|
209 | 1449 |
|
|
210 | 1450 |
|
|
211 | 1451 |
|
|
212 | ||
|
1452 | ||
|
213 | 1453 |
|
|
214 | 1454 |
|
|
215 |
|
|
|
1455 | else: | |
|
216 | 1456 |
|
|
217 | 1457 |
|
|
218 | 1458 |
|
|
219 | ||
|
1459 | ||
|
220 | 1460 |
|
|
221 | 1461 |
|
|
222 | ||
|
1462 | ||
|
223 | 1463 |
|
|
224 | ||
|
225 |
|
|
|
1464 | ||
|
1465 | valid = numpy.asarray(range(int(m + bb0 - ss1 + 1))) + ss1 | |
|
226 | 1466 |
|
|
227 | 1467 |
|
|
228 | 1468 |
|
|
229 |
|
|
|
230 | ||
|
231 |
|
|
|
1469 | snr = (spec2.mean()-n0)/n0 | |
|
1470 | ||
|
1471 | if (snr < 1.e-20) : | |
|
232 | 1472 |
|
|
233 | ||
|
1473 | ||
|
234 | 1474 |
|
|
235 | 1475 |
|
|
236 | 1476 |
|
|
237 | 1477 |
|
|
238 | ||
|
1478 | ||
|
239 | 1479 |
|
|
240 | 1480 |
|
|
241 | ||
|
1481 | ||
|
242 | 1482 |
|
|
243 | ||
|
1483 | ||
|
244 | 1484 |
|
|
245 | 1485 |
|
|
246 | 1486 |
|
|
247 | 1487 |
|
|
248 | ||
|
1488 | ||
|
249 | 1489 |
|
|
250 |
|
|
|
251 |
|
|
|
252 |
|
|
|
253 | ||
|
1490 | spectra = self.dataOut.data_pre | |
|
1491 | cspectra = self.dataIn.data_cspc | |
|
1492 | delta_v = vel[1] - vel[0] | |
|
1493 | ||
|
254 | 1494 |
|
|
255 | 1495 |
|
|
256 | 1496 |
|
|
257 | 1497 |
|
|
258 | 1498 |
|
|
259 |
|
|
|
260 | ||
|
1499 | max_spectra = numpy.max(norm_spectra, 3) | |
|
1500 | ||
|
261 | 1501 |
|
|
262 | 1502 |
|
|
263 | ||
|
1503 | ||
|
264 | 1504 |
|
|
265 | 1505 |
|
|
266 | ||
|
1506 | ||
|
267 | 1507 |
|
|
268 | 1508 |
|
|
269 | ||
|
1509 | ||
|
270 | 1510 |
|
|
271 | 1511 |
|
|
272 | 1512 |
|
|
273 | ||
|
1513 | ||
|
274 | 1514 |
|
|
275 | 1515 |
|
|
276 | 1516 | Function GetMoments() |
@@ -283,19 +1523,19 class SALags(Operation): | |||
|
283 | 1523 | self.dataOut.data_SNR |
|
284 | 1524 | self.dataOut.groupList |
|
285 | 1525 | self.dataOut.nChannels |
|
286 | ||
|
1526 | ||
|
287 | 1527 | Affected: |
|
288 | 1528 | self.dataOut.data_param |
|
289 | ||
|
1529 | ||
|
290 | 1530 | ''' |
|
291 |
|
|
|
1531 | def run(self, dataOut): | |
|
292 | 1532 |
|
|
293 | 1533 |
|
|
294 | 1534 |
|
|
295 | 1535 |
|
|
296 | 1536 |
|
|
297 | 1537 |
|
|
298 | ||
|
1538 | ||
|
299 | 1539 |
|
|
300 | 1540 |
|
|
301 | 1541 |
|
@@ -306,97 +1546,97 class SALags(Operation): | |||
|
306 | 1546 | |
|
307 | 1547 |
|
|
308 | 1548 |
|
|
309 | ||
|
1549 | ||
|
310 | 1550 |
|
|
311 | 1551 |
|
|
312 | ||
|
1552 | ||
|
313 | 1553 |
|
|
314 | 1554 |
|
|
315 | 1555 |
|
|
316 | 1556 |
|
|
317 | ||
|
1557 | ||
|
318 | 1558 |
|
|
319 | # | |
|
1559 | # | |
|
320 | 1560 |
|
|
321 | # | |
|
322 | # for l in range(len(pairsList)): | |
|
1561 | # | |
|
1562 | # for l in range(len(pairsList)): | |
|
323 | 1563 |
|
|
324 | 1564 |
|
|
325 | # | |
|
326 | # #Obteniendo pares de Autocorrelacion | |
|
1565 | # | |
|
1566 | # #Obteniendo pares de Autocorrelacion | |
|
327 | 1567 |
|
|
328 | 1568 |
|
|
329 | # | |
|
1569 | # | |
|
330 | 1570 |
|
|
331 | # | |
|
1571 | # | |
|
332 | 1572 |
|
|
333 | 1573 |
|
|
334 | # | |
|
1574 | # | |
|
335 | 1575 |
|
|
336 | ||
|
1576 | ||
|
337 | 1577 |
|
|
338 | ||
|
1578 | ||
|
339 | 1579 |
|
|
340 | 1580 |
|
|
341 | 1581 |
|
|
342 | ||
|
1582 | ||
|
343 | 1583 |
|
|
344 | 1584 |
|
|
345 | 1585 |
|
|
346 | 1586 |
|
|
347 | 1587 |
|
|
348 | ||
|
1588 | ||
|
349 | 1589 |
|
|
350 | 1590 |
|
|
351 | ||
|
1591 | ||
|
352 | 1592 |
|
|
353 | 1593 |
|
|
354 | 1594 |
|
|
355 | ||
|
1595 | ||
|
356 | 1596 |
|
|
357 | ||
|
1597 | ||
|
358 | 1598 |
|
|
359 | 1599 |
|
|
360 | 1600 |
|
|
361 | ||
|
1601 | ||
|
362 | 1602 |
|
|
363 | ||
|
1603 | ||
|
364 | 1604 |
|
|
365 | 1605 |
|
|
366 | 1606 |
|
|
367 | 1607 | |
|
368 | 1608 |
|
|
369 | ||
|
1609 | ||
|
370 | 1610 |
|
|
371 | ||
|
1611 | ||
|
372 | 1612 |
|
|
373 | 1613 |
|
|
374 | 1614 | Function GetMoments() |
|
375 | ||
|
1615 | ||
|
376 | 1616 | Input: |
|
377 | 1617 | Output: |
|
378 | 1618 | Variables modified: |
|
379 | 1619 | ''' |
|
380 | ||
|
381 |
|
|
|
382 | ||
|
383 | ||
|
1620 | ||
|
1621 | def run(self, dataOut, getSNR = True, path=None, file=None, groupList=None): | |
|
1622 | ||
|
1623 | ||
|
384 | 1624 |
|
|
385 | 1625 |
|
|
386 | 1626 |
|
|
387 | ||
|
1627 | ||
|
388 | 1628 |
|
|
389 | 1629 |
|
|
390 | # groupArray = numpy.array([[0,1],[2,3]]) | |
|
1630 | # groupArray = numpy.array([[0,1],[2,3]]) | |
|
391 | 1631 |
|
|
392 | ||
|
1632 | ||
|
393 | 1633 |
|
|
394 | 1634 |
|
|
395 | 1635 |
|
|
396 | ||
|
1636 | ||
|
397 | 1637 |
|
|
398 | 1638 |
|
|
399 | ||
|
1639 | ||
|
400 | 1640 |
|
|
401 | 1641 |
|
|
402 | 1642 |
|
@@ -405,24 +1645,24 class SpectralFitting(Operation): | |||
|
405 | 1645 |
|
|
406 | 1646 |
|
|
407 | 1647 |
|
|
408 | ||
|
1648 | ||
|
409 | 1649 |
|
|
410 | 1650 |
|
|
411 | 1651 |
|
|
412 | ||
|
1652 | ||
|
413 | 1653 |
|
|
414 | 1654 |
|
|
415 | 1655 |
|
|
416 | 1656 |
|
|
417 | 1657 |
|
|
418 | ||
|
419 |
|
|
|
1658 | ||
|
1659 | for i in range(nGroups): | |
|
420 | 1660 |
|
|
421 | ||
|
1661 | ||
|
422 | 1662 |
|
|
423 | 1663 |
|
|
424 | 1664 |
|
|
425 | ||
|
1665 | ||
|
426 | 1666 |
|
|
427 | 1667 |
|
|
428 | 1668 |
|
@@ -431,10 +1671,10 class SpectralFitting(Operation): | |||
|
431 | 1671 |
|
|
432 | 1672 |
|
|
433 | 1673 |
|
|
434 | ||
|
1674 | ||
|
435 | 1675 |
|
|
436 | 1676 |
|
|
437 | ||
|
1677 | ||
|
438 | 1678 |
|
|
439 | 1679 |
|
|
440 | 1680 | |
@@ -443,7 +1683,7 class SpectralFitting(Operation): | |||
|
443 | 1683 |
|
|
444 | 1684 |
|
|
445 | 1685 |
|
|
446 |
|
|
|
1686 | x = pairs[0] | |
|
447 | 1687 |
|
|
448 | 1688 |
|
|
449 | 1689 |
|
@@ -457,15 +1697,15 class SpectralFitting(Operation): | |||
|
457 | 1697 |
|
|
458 | 1698 | |
|
459 | 1699 |
|
|
460 | ||
|
1700 | ||
|
461 | 1701 |
|
|
462 | 1702 |
|
|
463 | ||
|
1703 | ||
|
464 | 1704 |
|
|
465 | 1705 |
|
|
466 | 1706 |
|
|
467 | 1707 |
|
|
468 | ||
|
1708 | ||
|
469 | 1709 |
|
|
470 | 1710 |
|
|
471 | 1711 |
|
@@ -478,30 +1718,30 class SpectralFitting(Operation): | |||
|
478 | 1718 |
|
|
479 | 1719 |
|
|
480 | 1720 |
|
|
481 | ||
|
1721 | ||
|
482 | 1722 |
|
|
483 |
|
|
|
1723 | if self.dataOut.data_param == None: | |
|
484 | 1724 |
|
|
485 | 1725 |
|
|
486 | ||
|
1726 | ||
|
487 | 1727 |
|
|
488 | 1728 |
|
|
489 | 1729 |
|
|
490 | ||
|
1730 | ||
|
491 | 1731 |
|
|
492 | 1732 | |
|
493 | 1733 |
|
|
494 | 1734 |
|
|
495 | ||
|
1735 | ||
|
496 | 1736 |
|
|
497 | 1737 | |
|
498 | 1738 |
|
|
499 | ||
|
1739 | ||
|
500 | 1740 |
|
|
501 | 1741 |
|
|
502 | 1742 |
|
|
503 | 1743 |
|
|
504 | ||
|
1744 | ||
|
505 | 1745 |
|
|
506 | 1746 |
|
|
507 | 1747 |
|
@@ -509,50 +1749,53 class SpectralFitting(Operation): | |||
|
509 | 1749 |
|
|
510 | 1750 |
|
|
511 | 1751 |
|
|
512 | ||
|
1752 | ||
|
513 | 1753 |
|
|
514 | ||
|
1754 | ||
|
515 | 1755 |
|
|
516 | ||
|
1756 | ||
|
517 | 1757 |
|
|
518 | 1758 |
|
|
519 | 1759 |
|
|
520 | ||
|
1760 | ||
|
521 | 1761 |
|
|
522 | ||
|
1762 | ||
|
523 | 1763 |
|
|
524 | ||
|
1764 | ||
|
525 | 1765 |
|
|
526 | ||
|
1766 | ||
|
527 | 1767 |
|
|
528 | ||
|
1768 | ||
|
1769 | def __init__(self): | |
|
1770 | Operation.__init__(self) | |
|
1771 | ||
|
529 | 1772 |
|
|
530 | 1773 |
|
|
531 | 1774 |
|
|
532 |
|
|
|
1775 | cosDirX = numpy.sqrt((1-numpy.cos(zen)**2)/((1+numpy.tan(azim)**2))) | |
|
533 | 1776 |
|
|
534 | ||
|
1777 | ||
|
535 | 1778 |
|
|
536 | 1779 |
|
|
537 | ||
|
1780 | ||
|
538 | 1781 |
|
|
539 | 1782 |
|
|
540 | 1783 |
|
|
541 | ||
|
1784 | ||
|
542 | 1785 |
|
|
543 | ||
|
1786 | ||
|
544 | 1787 |
|
|
545 | 1788 |
|
|
546 | 1789 |
|
|
547 | ||
|
1790 | ||
|
548 | 1791 |
|
|
549 | 1792 |
|
|
550 | ||
|
1793 | ||
|
551 | 1794 |
|
|
552 | 1795 | |
|
553 | 1796 |
|
|
554 | ||
|
555 | # | |
|
1797 | ||
|
1798 | # | |
|
556 | 1799 |
|
|
557 | 1800 |
|
|
558 | 1801 |
|
@@ -566,37 +1809,37 class WindProfiler(Operation): | |||
|
566 | 1809 |
|
|
567 | 1810 |
|
|
568 | 1811 |
|
|
569 | ||
|
570 |
|
|
|
1812 | ||
|
1813 | rango = range(len(phi)) | |
|
571 | 1814 |
|
|
572 | ||
|
1815 | ||
|
573 | 1816 |
|
|
574 | 1817 |
|
|
575 | 1818 |
|
|
576 | 1819 |
|
|
577 | ||
|
1820 | ||
|
578 | 1821 |
|
|
579 | 1822 |
|
|
580 | ||
|
1823 | ||
|
581 | 1824 |
|
|
582 | 1825 |
|
|
583 | 1826 |
|
|
584 | 1827 |
|
|
585 | ||
|
1828 | ||
|
586 | 1829 |
|
|
587 | 1830 |
|
|
588 | ||
|
1831 | ||
|
589 | 1832 |
|
|
590 | 1833 |
|
|
591 | 1834 |
|
|
592 | ||
|
1835 | ||
|
593 | 1836 |
|
|
594 | 1837 |
|
|
595 | ||
|
1838 | ||
|
596 | 1839 |
|
|
597 | 1840 | |
|
598 | 1841 |
|
|
599 | ||
|
1842 | ||
|
600 | 1843 |
|
|
601 | 1844 |
|
|
602 | 1845 |
|
@@ -604,27 +1847,27 class WindProfiler(Operation): | |||
|
604 | 1847 |
|
|
605 | 1848 |
|
|
606 | 1849 |
|
|
607 | ||
|
608 | ||
|
1850 | ||
|
1851 | ||
|
609 | 1852 |
|
|
610 | ||
|
1853 | ||
|
611 | 1854 |
|
|
612 | ||
|
1855 | ||
|
613 | 1856 |
|
|
614 | 1857 |
|
|
615 | 1858 | Function that implements Doppler Beam Swinging (DBS) technique. |
|
616 | ||
|
1859 | ||
|
617 | 1860 | Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth, |
|
618 | 1861 | Direction correction (if necessary), Ranges and SNR |
|
619 | ||
|
1862 | ||
|
620 | 1863 | Output: Winds estimation (Zonal, Meridional and Vertical) |
|
621 | ||
|
1864 | ||
|
622 | 1865 | Parameters affected: Winds, height range, SNR |
|
623 | 1866 | """ |
|
624 | 1867 |
|
|
625 | 1868 |
|
|
626 | 1869 |
|
|
627 | ||
|
1870 | ||
|
628 | 1871 |
|
|
629 | 1872 |
|
|
630 | 1873 |
|
@@ -632,7 +1875,7 class WindProfiler(Operation): | |||
|
632 | 1875 |
|
|
633 | 1876 |
|
|
634 | 1877 |
|
|
635 |
|
|
|
1878 | azimuth = kwargs['correctAzimuth'] | |
|
636 | 1879 |
|
|
637 | 1880 |
|
|
638 | 1881 |
|
@@ -647,22 +1890,22 class WindProfiler(Operation): | |||
|
647 | 1890 |
|
|
648 | 1891 |
|
|
649 | 1892 |
|
|
650 | ||
|
651 |
|
|
|
652 |
|
|
|
1893 | ||
|
1894 | 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) | |
|
653 | 1896 |
|
|
654 | ||
|
1897 | ||
|
655 | 1898 |
|
|
656 | 1899 |
|
|
657 | ||
|
1900 | ||
|
658 | 1901 |
|
|
659 | ||
|
1902 | ||
|
660 | 1903 |
|
|
661 | ||
|
1904 | ||
|
662 | 1905 |
|
|
663 | 1906 |
|
|
664 | 1907 |
|
|
665 | ||
|
1908 | ||
|
666 | 1909 |
|
|
667 | 1910 |
|
|
668 | 1911 |
|
@@ -671,126 +1914,126 class WindProfiler(Operation): | |||
|
671 | 1914 |
|
|
672 | 1915 |
|
|
673 | 1916 |
|
|
674 | ||
|
1917 | ||
|
675 | 1918 |
|
|
676 | 1919 |
|
|
677 | 1920 |
|
|
678 | 1921 |
|
|
679 | 1922 |
|
|
680 | ||
|
1923 | ||
|
681 | 1924 |
|
|
682 | 1925 |
|
|
683 |
|
|
|
1926 | disty[i] = posy1[pairs_ccf[i][1]] - posy1[pairs_ccf[i][0]] | |
|
684 | 1927 |
|
|
685 | 1928 |
|
|
686 | ||
|
1929 | ||
|
687 | 1930 |
|
|
688 |
|
|
|
1931 | #Calculo de Matrices | |
|
689 | 1932 |
|
|
690 | 1933 |
|
|
691 | 1934 |
|
|
692 | # | |
|
1935 | # | |
|
693 | 1936 |
|
|
694 | 1937 |
|
|
695 | 1938 |
|
|
696 | 1939 |
|
|
697 | 1940 |
|
|
698 | # | |
|
1941 | # | |
|
699 | 1942 |
|
|
700 | 1943 | |
|
701 | ||
|
1944 | ||
|
702 | 1945 |
|
|
703 | 1946 | |
|
704 | 1947 |
|
|
705 | 1948 |
|
|
706 | ||
|
1949 | ||
|
707 | 1950 |
|
|
708 | ||
|
1951 | ||
|
709 | 1952 |
|
|
710 | 1953 |
|
|
711 | 1954 |
|
|
712 |
|
|
|
1955 | vel = numpy.zeros((nPairs,3,nHeights)) | |
|
713 | 1956 |
|
|
714 | ||
|
1957 | ||
|
715 | 1958 |
|
|
716 | 1959 |
|
|
717 | ||
|
718 |
|
|
|
1960 | ||
|
1961 | vel0 = dist1*tau1/(2*tau2**2) | |
|
719 | 1962 |
|
|
720 | 1963 |
|
|
721 | ||
|
1964 | ||
|
722 | 1965 |
|
|
723 | 1966 |
|
|
724 | ||
|
1967 | ||
|
725 | 1968 |
|
|
726 | ||
|
1969 | ||
|
727 | 1970 |
|
|
728 | # | |
|
1971 | # | |
|
729 | 1972 |
|
|
730 | # | |
|
731 | # for l in range(len(pairsList)): | |
|
1973 | # | |
|
1974 | # for l in range(len(pairsList)): | |
|
732 | 1975 |
|
|
733 | 1976 |
|
|
734 | # | |
|
735 | # #Obteniendo pares de Autocorrelacion | |
|
1977 | # | |
|
1978 | # #Obteniendo pares de Autocorrelacion | |
|
736 | 1979 |
|
|
737 | 1980 |
|
|
738 | # | |
|
1981 | # | |
|
739 | 1982 |
|
|
740 | # | |
|
1983 | # | |
|
741 | 1984 |
|
|
742 | 1985 |
|
|
743 | # | |
|
1986 | # | |
|
744 | 1987 |
|
|
745 | ||
|
1988 | ||
|
746 | 1989 |
|
|
747 | 1990 |
|
|
748 | ||
|
749 |
|
|
|
1991 | ||
|
1992 | """ | |
|
750 | 1993 | Function that implements Spaced Antenna (SA) technique. |
|
751 | ||
|
1994 | ||
|
752 | 1995 | Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth, |
|
753 | 1996 | Direction correction (if necessary), Ranges and SNR |
|
754 | ||
|
1997 | ||
|
755 | 1998 | Output: Winds estimation (Zonal, Meridional and Vertical) |
|
756 | ||
|
1999 | ||
|
757 | 2000 | Parameters affected: Winds |
|
758 | 2001 | """ |
|
759 | 2002 |
|
|
760 | 2003 |
|
|
761 | 2004 |
|
|
762 | ||
|
2005 | ||
|
763 | 2006 |
|
|
764 | 2007 |
|
|
765 | 2008 |
|
|
766 | 2009 |
|
|
767 | ||
|
2010 | ||
|
768 | 2011 |
|
|
769 | 2012 |
|
|
770 | 2013 |
|
|
771 | 2014 |
|
|
772 | ||
|
2015 | ||
|
773 | 2016 |
|
|
774 | 2017 |
|
|
775 | 2018 |
|
|
776 | 2019 |
|
|
777 | 2020 |
|
|
778 | # | |
|
2021 | # | |
|
779 | 2022 |
|
|
780 | 2023 |
|
|
781 | 2024 |
|
|
782 | 2025 |
|
|
783 | 2026 |
|
|
784 | ||
|
2027 | ||
|
785 | 2028 |
|
|
786 | 2029 |
|
|
787 | 2030 |
|
|
788 | 2031 |
|
|
789 | 2032 |
|
|
790 | 2033 |
|
|
791 | ||
|
2034 | ||
|
792 | 2035 |
|
|
793 |
|
|
|
2036 | #Metodo Directo | |
|
794 | 2037 |
|
|
795 | 2038 |
|
|
796 | 2039 |
|
@@ -806,100 +2049,100 class WindProfiler(Operation): | |||
|
806 | 2049 |
|
|
807 | 2050 |
|
|
808 | 2051 |
|
|
809 | ||
|
2052 | ||
|
810 | 2053 |
|
|
811 | ||
|
2054 | ||
|
812 | 2055 |
|
|
813 | 2056 |
|
|
814 | ||
|
2057 | ||
|
815 | 2058 |
|
|
816 | 2059 |
|
|
817 |
|
|
|
818 | ||
|
819 |
|
|
|
2060 | return | |
|
2061 | ||
|
2062 | def techniqueMeteors(self, arrayMeteor, meteorThresh, heightMin, heightMax): | |
|
820 | 2063 |
|
|
821 | 2064 | Function that implements winds estimation technique with detected meteors. |
|
822 | ||
|
2065 | ||
|
823 | 2066 | Input: Detected meteors, Minimum meteor quantity to wind estimation |
|
824 | ||
|
2067 | ||
|
825 | 2068 | Output: Winds estimation (Zonal and Meridional) |
|
826 | ||
|
2069 | ||
|
827 | 2070 | Parameters affected: Winds |
|
828 | ''' | |
|
829 | # print arrayMeteor.shape | |
|
2071 | ''' | |
|
2072 | # print arrayMeteor.shape | |
|
830 | 2073 |
|
|
831 |
|
|
|
2074 | nInt = (heightMax - heightMin)/2 | |
|
832 | 2075 |
|
|
833 | 2076 |
|
|
834 | 2077 |
|
|
835 |
|
|
|
836 | ||
|
2078 | winds = numpy.zeros((2,nInt))*numpy.nan | |
|
2079 | ||
|
837 | 2080 |
|
|
838 | 2081 |
|
|
839 | 2082 |
|
|
840 | ||
|
2083 | ||
|
841 | 2084 |
|
|
842 | 2085 |
|
|
843 | 2086 |
|
|
844 | 2087 |
|
|
845 | 2088 |
|
|
846 | ||
|
2089 | ||
|
847 | 2090 |
|
|
848 | 2091 |
|
|
849 | 2092 |
|
|
850 | ||
|
2093 | ||
|
851 | 2094 |
|
|
852 | 2095 |
|
|
853 |
|
|
|
854 | ||
|
2096 | ind2 = 0 | |
|
2097 | ||
|
855 | 2098 |
|
|
856 | 2099 |
|
|
857 | 2100 |
|
|
858 | 2101 |
|
|
859 | ||
|
2102 | ||
|
860 | 2103 |
|
|
861 | ||
|
2104 | ||
|
862 | 2105 |
|
|
863 | 2106 |
|
|
864 | 2107 |
|
|
865 | 2108 |
|
|
866 | ||
|
2109 | ||
|
867 | 2110 |
|
|
868 | 2111 |
|
|
869 | 2112 |
|
|
870 | 2113 |
|
|
871 | 2114 |
|
|
872 | ||
|
2115 | ||
|
873 | 2116 |
|
|
874 | 2117 |
|
|
875 | 2118 |
|
|
876 | ||
|
2119 | ||
|
877 | 2120 |
|
|
878 | 2121 |
|
|
879 | ||
|
2122 | ||
|
880 | 2123 |
|
|
881 | ||
|
2124 | ||
|
882 | 2125 |
|
|
883 | 2126 |
|
|
884 | 2127 |
|
|
885 | 2128 |
|
|
886 | ||
|
2129 | ||
|
887 | 2130 |
|
|
888 | 2131 |
|
|
889 | 2132 |
|
|
890 | 2133 |
|
|
891 | 2134 |
|
|
892 | ||
|
2135 | ||
|
893 | 2136 |
|
|
894 | 2137 |
|
|
895 | 2138 |
|
|
896 | 2139 |
|
|
897 | ||
|
2140 | ||
|
898 | 2141 |
|
|
899 | ||
|
2142 | ||
|
900 | 2143 |
|
|
901 | 2144 |
|
|
902 | ||
|
2145 | ||
|
903 | 2146 |
|
|
904 | 2147 |
|
|
905 | 2148 |
|
@@ -912,71 +2155,71 class WindProfiler(Operation): | |||
|
912 | 2155 |
|
|
913 | 2156 |
|
|
914 | 2157 |
|
|
915 | ||
|
2158 | ||
|
916 | 2159 |
|
|
917 | 2160 |
|
|
918 | ||
|
2161 | ||
|
919 | 2162 |
|
|
920 | 2163 |
|
|
921 | 2164 |
|
|
922 | 2165 |
|
|
923 | 2166 |
|
|
924 | 2167 |
|
|
925 | ||
|
2168 | ||
|
926 | 2169 |
|
|
927 | 2170 |
|
|
928 | 2171 |
|
|
929 | 2172 |
|
|
930 | 2173 |
|
|
931 | ||
|
2174 | ||
|
932 | 2175 |
|
|
933 | 2176 |
|
|
934 | 2177 |
|
|
935 | 2178 |
|
|
936 | 2179 |
|
|
937 | ||
|
2180 | ||
|
938 | 2181 |
|
|
939 | 2182 |
|
|
940 | 2183 |
|
|
941 | ||
|
2184 | ||
|
942 | 2185 |
|
|
943 | 2186 |
|
|
944 | 2187 |
|
|
945 | 2188 |
|
|
946 | 2189 |
|
|
947 | ||
|
2190 | ||
|
948 | 2191 |
|
|
949 | 2192 |
|
|
950 | 2193 |
|
|
951 | 2194 |
|
|
952 | ||
|
2195 | ||
|
953 | 2196 |
|
|
954 | 2197 |
|
|
955 | ||
|
2198 | ||
|
956 | 2199 |
|
|
957 | 2200 |
|
|
958 | 2201 |
|
|
959 | ||
|
2202 | ||
|
960 | 2203 |
|
|
961 | 2204 |
|
|
962 | 2205 |
|
|
963 | 2206 |
|
|
964 | ||
|
2207 | ||
|
965 | 2208 |
|
|
966 | ||
|
2209 | ||
|
967 | 2210 |
|
|
968 | 2211 |
|
|
969 | 2212 |
|
|
970 | ||
|
2213 | ||
|
971 | 2214 |
|
|
972 | ||
|
2215 | ||
|
973 | 2216 |
|
|
974 | 2217 |
|
|
975 | 2218 |
|
|
976 | 2219 |
|
|
977 | 2220 |
|
|
978 |
|
|
|
979 | ||
|
2221 | phDiff = numpy.abs(phase1[inext] - phase1[inow]) | |
|
2222 | ||
|
980 | 2223 |
|
|
981 | 2224 |
|
|
982 | 2225 |
|
@@ -992,28 +2235,28 class WindProfiler(Operation): | |||
|
992 | 2235 |
|
|
993 | 2236 |
|
|
994 | 2237 |
|
|
995 |
|
|
|
2238 | initMet = inext | |
|
996 | 2239 |
|
|
997 | ||
|
2240 | ||
|
998 | 2241 |
|
|
999 | ||
|
2242 | ||
|
1000 | 2243 |
|
|
1001 | ||
|
2244 | ||
|
1002 | 2245 |
|
|
1003 | 2246 |
|
|
1004 | ||
|
2247 | ||
|
1005 | 2248 |
|
|
1006 | 2249 |
|
|
1007 | 2250 |
|
|
1008 | ||
|
2251 | ||
|
1009 | 2252 |
|
|
1010 | 2253 |
|
|
1011 | 2254 |
|
|
1012 | 2255 |
|
|
1013 | ||
|
2256 | ||
|
1014 | 2257 |
|
|
1015 | 2258 |
|
|
1016 | ||
|
2259 | ||
|
1017 | 2260 |
|
|
1018 | 2261 |
|
|
1019 | 2262 |
|
@@ -1068,39 +2311,39 class WindProfiler(Operation): | |||
|
1068 | 2311 |
|
|
1069 | 2312 |
|
|
1070 | 2313 |
|
|
1071 | ||
|
2314 | ||
|
1072 | 2315 |
|
|
1073 | ||
|
1074 |
|
|
|
2316 | ||
|
2317 | kwargs['velRadial'] = param[:,1,:] #Radial velocity | |
|
1075 | 2318 |
|
|
1076 | 2319 |
|
|
1077 | ||
|
2320 | ||
|
1078 | 2321 |
|
|
1079 | 2322 |
|
|
1080 | 2323 |
|
|
1081 | ||
|
2324 | ||
|
1082 | 2325 |
|
|
1083 | ||
|
2326 | ||
|
1084 | 2327 |
|
|
1085 | 2328 |
|
|
1086 | 2329 |
|
|
1087 | 2330 |
|
|
1088 | # | |
|
2331 | # | |
|
1089 | 2332 |
|
|
1090 | 2333 |
|
|
1091 | 2334 |
|
|
1092 | # pairs = None | |
|
1093 | # | |
|
2335 | # pairs = None | |
|
2336 | # | |
|
1094 | 2337 |
|
|
1095 | 2338 |
|
|
1096 | 2339 |
|
|
1097 | 2340 |
|
|
1098 | ||
|
2341 | ||
|
1099 | 2342 |
|
|
1100 | 2343 |
|
|
1101 | 2344 |
|
|
1102 | 2345 |
|
|
1103 | ||
|
2346 | ||
|
1104 | 2347 |
|
|
1105 | 2348 |
|
|
1106 | 2349 |
|
@@ -1108,35 +2351,30 class WindProfiler(Operation): | |||
|
1108 | 2351 |
|
|
1109 | 2352 |
|
|
1110 | 2353 |
|
|
1111 | ||
|
1112 |
|
|
|
2354 | ||
|
2355 | elif technique == 'Meteors': | |
|
1113 | 2356 |
|
|
1114 | 2357 |
|
|
1115 | ||
|
2358 | ||
|
1116 | 2359 |
|
|
1117 | 2360 |
|
|
1118 |
|
|
|
2361 | else: | |
|
1119 | 2362 |
|
|
1120 | ||
|
2363 | ||
|
1121 | 2364 |
|
|
1122 | 2365 |
|
|
1123 | 2366 |
|
|
1124 | 2367 |
|
|
1125 | ||
|
2368 | ||
|
1126 | 2369 |
|
|
1127 | 2370 |
|
|
1128 | 2371 |
|
|
1129 | 2372 |
|
|
1130 | 2373 |
|
|
1131 | 2374 |
|
|
1132 | ||
|
1133 | if kwargs.has_key('BinKm'): | |
|
1134 | binkm = kwargs['BinKm'] | |
|
1135 | else: | |
|
1136 | binkm = 2 | |
|
1137 | ||
|
2375 | ||
|
1138 | 2376 |
|
|
1139 | ||
|
2377 | ||
|
1140 | 2378 |
|
|
1141 | 2379 |
|
|
1142 | 2380 |
|
@@ -1144,29 +2382,29 class WindProfiler(Operation): | |||
|
1144 | 2382 |
|
|
1145 | 2383 | |
|
1146 | 2384 |
|
|
1147 | ||
|
1148 |
|
|
|
2385 | ||
|
2386 | if self.__buffer == None: | |
|
1149 | 2387 |
|
|
1150 | 2388 |
|
|
1151 | 2389 | |
|
1152 | 2390 |
|
|
1153 | 2391 |
|
|
1154 | ||
|
2392 | ||
|
1155 | 2393 |
|
|
1156 | ||
|
2394 | ||
|
1157 | 2395 |
|
|
1158 | 2396 |
|
|
1159 | ||
|
2397 | ||
|
1160 | 2398 |
|
|
1161 | ||
|
1162 |
|
|
|
2399 | ||
|
2400 | dataOut.data_output, dataOut.heightList = self.techniqueMeteors(self.__buffer, meteorThresh, hmin, hmax) | |
|
1163 | 2401 |
|
|
1164 | 2402 |
|
|
1165 | ||
|
2403 | ||
|
1166 | 2404 |
|
|
1167 | 2405 |
|
|
1168 | 2406 |
|
|
1169 | ||
|
2407 | ||
|
1170 | 2408 |
|
|
1171 | 2409 |
|
|
1172 | 2410 |
|
@@ -1187,17 +2425,17 class WindProfiler(Operation): | |||
|
1187 | 2425 |
|
|
1188 | 2426 | |
|
1189 | 2427 |
|
|
1190 |
|
|
|
2428 | if dataOut.groupList == None: | |
|
1191 | 2429 |
|
|
1192 | 2430 |
|
|
1193 | 2431 |
|
|
1194 | 2432 |
|
|
1195 | 2433 |
|
|
1196 | 2434 |
|
|
1197 | ||
|
2435 | ||
|
1198 | 2436 |
|
|
1199 | 2437 |
|
|
1200 | ||
|
2438 | ||
|
1201 | 2439 |
|
|
1202 | 2440 |
|
|
1203 | 2441 |
|
@@ -1208,20 +2446,20 class WindProfiler(Operation): | |||
|
1208 | 2446 |
|
|
1209 | 2447 | |
|
1210 | 2448 |
|
|
1211 | ||
|
1212 |
|
|
|
2449 | ||
|
2450 | if self.__buffer == None: | |
|
1213 | 2451 |
|
|
1214 | 2452 |
|
|
1215 | 2453 | |
|
1216 | 2454 |
|
|
1217 | 2455 |
|
|
1218 | ||
|
2456 | ||
|
1219 | 2457 |
|
|
1220 | ||
|
2458 | ||
|
1221 | 2459 |
|
|
1222 | 2460 |
|
|
1223 | 2461 |
|
|
1224 | ||
|
2462 | ||
|
1225 | 2463 |
|
|
1226 | 2464 |
|
|
1227 | 2465 |
|
@@ -1232,69 +2470,71 class WindProfiler(Operation): | |||
|
1232 | 2470 |
|
|
1233 | 2471 | |
|
1234 | 2472 |
|
|
1235 | ||
|
2473 | ||
|
1236 | 2474 |
|
|
1237 | ||
|
1238 | ||
|
2475 | ||
|
2476 | def __init__(self): | |
|
2477 | Operation.__init__(self) | |
|
2478 | ||
|
1239 | 2479 |
|
|
1240 | 2480 |
|
|
1241 | 2481 |
|
|
1242 | 2482 |
|
|
1243 | ||
|
1244 |
|
|
|
2483 | ||
|
2484 | rango = range(len(phi)) | |
|
1245 | 2485 |
|
|
1246 | ||
|
2486 | ||
|
1247 | 2487 |
|
|
1248 | 2488 |
|
|
1249 | 2489 |
|
|
1250 | 2490 |
|
|
1251 | ||
|
2491 | ||
|
1252 | 2492 |
|
|
1253 | 2493 |
|
|
1254 | ||
|
2494 | ||
|
1255 | 2495 |
|
|
1256 | 2496 |
|
|
1257 | 2497 |
|
|
1258 | 2498 |
|
|
1259 | ||
|
2499 | ||
|
1260 | 2500 |
|
|
1261 | 2501 |
|
|
1262 | ||
|
2502 | ||
|
1263 | 2503 |
|
|
1264 | 2504 |
|
|
1265 | 2505 |
|
|
1266 | ||
|
2506 | ||
|
1267 | 2507 |
|
|
1268 | 2508 |
|
|
1269 | ||
|
2509 | ||
|
1270 | 2510 |
|
|
1271 | 2511 | |
|
1272 | 2512 |
|
|
1273 | 2513 |
|
|
1274 | 2514 |
|
|
1275 | 2515 |
|
|
1276 | ||
|
2516 | ||
|
1277 | 2517 |
|
|
1278 |
|
|
|
2518 | zenith -= zenithCorrection | |
|
1279 | 2519 |
|
|
1280 | ||
|
2520 | ||
|
1281 | 2521 |
|
|
1282 | ||
|
2522 | ||
|
1283 | 2523 |
|
|
1284 | 2524 |
|
|
1285 | ||
|
2525 | ||
|
1286 | 2526 |
|
|
1287 | 2527 |
|
|
1288 | ||
|
1289 |
|
|
|
1290 |
|
|
|
1291 | ||
|
2528 | ||
|
2529 | 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)) | |
|
2531 | ||
|
1292 | 2532 |
|
|
1293 | ||
|
2533 | ||
|
1294 | 2534 |
|
|
1295 | 2535 |
|
|
1296 | 2536 |
|
|
1297 | ||
|
2537 | ||
|
1298 | 2538 |
|
|
1299 | 2539 |
|
|
1300 | 2540 |
|
@@ -1333,7 +2573,7 class NonSpecularMeteorDetection(Operation): | |||
|
1333 | 2573 |
|
|
1334 | 2574 |
|
|
1335 | 2575 |
|
|
1336 | ||
|
2576 | ||
|
1337 | 2577 |
|
|
1338 | 2578 |
|
|
1339 | 2579 |
|
@@ -1341,22 +2581,22 class NonSpecularMeteorDetection(Operation): | |||
|
1341 | 2581 |
|
|
1342 | 2582 |
|
|
1343 | 2583 |
|
|
1344 | ||
|
2584 | ||
|
1345 | 2585 |
|
|
1346 | 2586 |
|
|
1347 | 2587 |
|
|
1348 | 2588 |
|
|
1349 |
|
|
|
1350 | # phase1[p,:,:] = numpy.angle(ccf) #median filter | |
|
1351 |
|
|
|
1352 | # coh1[p,:,:] = numpy.abs(ccf) #median filter | |
|
2589 | phase[p,:,:] = ndimage.median_filter(numpy.angle(ccf), size = (5,1)) #median filter | |
|
2590 | # phase1[p,:,:] = numpy.angle(ccf) #median filter | |
|
2591 | coh1[p,:,:] = ndimage.median_filter(numpy.abs(ccf), 5) #median filter | |
|
2592 | # coh1[p,:,:] = numpy.abs(ccf) #median filter | |
|
1353 | 2593 |
|
|
1354 | 2594 |
|
|
1355 | 2595 |
|
|
1356 | 2596 |
|
|
1357 | 2597 |
|
|
1358 | 2598 |
|
|
1359 | ||
|
2599 | ||
|
1360 | 2600 |
|
|
1361 | 2601 |
|
|
1362 | 2602 |
|
@@ -1364,31 +2604,31 class NonSpecularMeteorDetection(Operation): | |||
|
1364 | 2604 |
|
|
1365 | 2605 |
|
|
1366 | 2606 |
|
|
1367 | # | |
|
2607 | # | |
|
1368 | 2608 |
|
|
1369 | # boolMet1 = self.__erase_small(boolMet, 2*sec, 5) | |
|
1370 | # | |
|
2609 | # boolMet1 = self.__erase_small(boolMet, 2*sec, 5) | |
|
2610 | # | |
|
1371 | 2611 |
|
|
1372 | 2612 |
|
|
1373 | 2613 |
|
|
1374 | 2614 |
|
|
1375 | # | |
|
2615 | # | |
|
1376 | 2616 |
|
|
1377 | # | |
|
2617 | # | |
|
1378 | 2618 |
|
|
1379 | # boolMet1[:,indEEJ] = False #Erase heights with EEJ | |
|
1380 | # | |
|
2619 | # boolMet1[:,indEEJ] = False #Erase heights with EEJ | |
|
2620 | # | |
|
1381 | 2621 |
|
|
1382 | 2622 |
|
|
1383 | # | |
|
2623 | # | |
|
1384 | 2624 |
|
|
1385 | 2625 |
|
|
1386 | ||
|
2626 | ||
|
1387 | 2627 |
|
|
1388 | 2628 |
|
|
1389 | 2629 |
|
|
1390 | 2630 |
|
|
1391 | ||
|
2631 | ||
|
1392 | 2632 |
|
|
1393 | 2633 |
|
|
1394 | 2634 |
|
@@ -1405,7 +2645,7 class NonSpecularMeteorDetection(Operation): | |||
|
1405 | 2645 | |
|
1406 | 2646 |
|
|
1407 | 2647 |
|
|
1408 | ||
|
2648 | ||
|
1409 | 2649 |
|
|
1410 | 2650 |
|
|
1411 | 2651 |
|
@@ -1414,7 +2654,7 class NonSpecularMeteorDetection(Operation): | |||
|
1414 | 2654 |
|
|
1415 | 2655 |
|
|
1416 | 2656 |
|
|
1417 | ||
|
2657 | ||
|
1418 | 2658 |
|
|
1419 | 2659 |
|
|
1420 | 2660 | |
@@ -1422,7 +2662,7 class NonSpecularMeteorDetection(Operation): | |||
|
1422 | 2662 |
|
|
1423 | 2663 |
|
|
1424 | 2664 |
|
|
1425 | ||
|
2665 | ||
|
1426 | 2666 |
|
|
1427 | 2667 |
|
|
1428 | 2668 |
|
@@ -1437,24 +2677,24 class NonSpecularMeteorDetection(Operation): | |||
|
1437 | 2677 |
|
|
1438 | 2678 |
|
|
1439 | 2679 |
|
|
1440 | ||
|
2680 | ||
|
1441 | 2681 |
|
|
1442 | 2682 |
|
|
1443 | 2683 |
|
|
1444 | ||
|
2684 | ||
|
1445 | 2685 |
|
|
1446 | 2686 |
|
|
1447 | 2687 |
|
|
1448 | 2688 |
|
|
1449 | 2689 |
|
|
1450 | ||
|
2690 | ||
|
1451 | 2691 |
|
|
1452 | 2692 |
|
|
1453 | 2693 | |
|
1454 | 2694 |
|
|
1455 | 2695 |
|
|
1456 | 2696 |
|
|
1457 | ||
|
2697 | ||
|
1458 | 2698 |
|
|
1459 | 2699 |
|
|
1460 | 2700 |
|
@@ -1463,7 +2703,7 class NonSpecularMeteorDetection(Operation): | |||
|
1463 | 2703 |
|
|
1464 | 2704 |
|
|
1465 | 2705 |
|
|
1466 | ||
|
2706 | ||
|
1467 | 2707 |
|
|
1468 | 2708 |
|
|
1469 | 2709 |
|
@@ -1473,21 +2713,21 class NonSpecularMeteorDetection(Operation): | |||
|
1473 | 2713 |
|
|
1474 | 2714 |
|
|
1475 | 2715 |
|
|
1476 | ||
|
2716 | ||
|
1477 | 2717 |
|
|
1478 | 2718 |
|
|
1479 | 2719 |
|
|
1480 | ||
|
2720 | ||
|
1481 | 2721 |
|
|
1482 | 2722 |
|
|
1483 | 2723 |
|
|
1484 | ||
|
2724 | ||
|
1485 | 2725 |
|
|
1486 |
|
|
|
1487 | ||
|
2726 | #width Y: | |
|
2727 | ||
|
1488 | 2728 |
|
|
1489 | 2729 |
|
|
1490 | ||
|
2730 | ||
|
1491 | 2731 |
|
|
1492 | 2732 | |
|
1493 | 2733 |
|
@@ -1497,36 +2737,36 class SMDetection(Operation): | |||
|
1497 | 2737 | Function DetectMeteors() |
|
1498 | 2738 | Project developed with paper: |
|
1499 | 2739 | HOLDSWORTH ET AL. 2004 |
|
1500 | ||
|
2740 | ||
|
1501 | 2741 | Input: |
|
1502 | 2742 | self.dataOut.data_pre |
|
1503 | ||
|
2743 | ||
|
1504 | 2744 | centerReceiverIndex: From the channels, which is the center receiver |
|
1505 | ||
|
2745 | ||
|
1506 | 2746 | hei_ref: Height reference for the Beacon signal extraction |
|
1507 | 2747 | tauindex: |
|
1508 | 2748 | predefinedPhaseShifts: Predefined phase offset for the voltge signals |
|
1509 | ||
|
2749 | ||
|
1510 | 2750 | cohDetection: Whether to user Coherent detection or not |
|
1511 | 2751 | cohDet_timeStep: Coherent Detection calculation time step |
|
1512 | 2752 | cohDet_thresh: Coherent Detection phase threshold to correct phases |
|
1513 | ||
|
2753 | ||
|
1514 | 2754 | noise_timeStep: Noise calculation time step |
|
1515 | 2755 | noise_multiple: Noise multiple to define signal threshold |
|
1516 | ||
|
2756 | ||
|
1517 | 2757 | multDet_timeLimit: Multiple Detection Removal time limit in seconds |
|
1518 | 2758 | multDet_rangeLimit: Multiple Detection Removal range limit in km |
|
1519 | ||
|
2759 | ||
|
1520 | 2760 | phaseThresh: Maximum phase difference between receiver to be consider a meteor |
|
1521 | SNRThresh: Minimum SNR threshold of the meteor signal to be consider a meteor | |
|
1522 | ||
|
2761 | SNRThresh: Minimum SNR threshold of the meteor signal to be consider a meteor | |
|
2762 | ||
|
1523 | 2763 | hmin: Minimum Height of the meteor to use it in the further wind estimations |
|
1524 | 2764 | hmax: Maximum Height of the meteor to use it in the further wind estimations |
|
1525 | 2765 | azimuth: Azimuth angle correction |
|
1526 | ||
|
2766 | ||
|
1527 | 2767 | Affected: |
|
1528 | 2768 | self.dataOut.data_param |
|
1529 | ||
|
2769 | ||
|
1530 | 2770 | Rejection Criteria (Errors): |
|
1531 | 2771 | 0: No error; analysis OK |
|
1532 | 2772 | 1: SNR < SNR threshold |
@@ -1545,9 +2785,9 class SMDetection(Operation): | |||
|
1545 | 2785 | 14: height ambiguous echo: more then one possible height within 70 to 110 km |
|
1546 | 2786 | 15: radial drift velocity or projected horizontal velocity exceeds 200 m/s |
|
1547 | 2787 | 16: oscilatory echo, indicating event most likely not an underdense echo |
|
1548 | ||
|
2788 | ||
|
1549 | 2789 | 17: phase difference in meteor Reestimation |
|
1550 | ||
|
2790 | ||
|
1551 | 2791 | Data Storage: |
|
1552 | 2792 | Meteors for Wind Estimation (8): |
|
1553 | 2793 | Utc Time | Range Height |
@@ -1555,21 +2795,21 class SMDetection(Operation): | |||
|
1555 | 2795 | VelRad errorVelRad |
|
1556 | 2796 | Phase0 Phase1 Phase2 Phase3 |
|
1557 | 2797 | TypeError |
|
1558 | ||
|
1559 | ''' | |
|
1560 | ||
|
2798 | ||
|
2799 | ''' | |
|
2800 | ||
|
1561 | 2801 |
|
|
1562 | 2802 |
|
|
1563 |
|
|
|
2803 | cohDetection = False, cohDet_timeStep = 1, cohDet_thresh = 25, | |
|
1564 | 2804 |
|
|
1565 | 2805 |
|
|
1566 | 2806 |
|
|
1567 | 2807 |
|
|
1568 | 2808 |
|
|
1569 | ||
|
1570 | ||
|
2809 | ||
|
2810 | ||
|
1571 | 2811 |
|
|
1572 |
|
|
|
2812 | if channelPositions == None: | |
|
1573 | 2813 |
|
|
1574 | 2814 |
|
|
1575 | 2815 |
|
@@ -1577,53 +2817,53 class SMDetection(Operation): | |||
|
1577 | 2817 |
|
|
1578 | 2818 |
|
|
1579 | 2819 |
|
|
1580 | # | |
|
2820 | # | |
|
1581 | 2821 |
|
|
1582 | 2822 |
|
|
1583 | # | |
|
1584 | ||
|
1585 | ||
|
2823 | # | |
|
2824 | ||
|
2825 | ||
|
1586 | 2826 |
|
|
1587 | 2827 |
|
|
1588 | 2828 |
|
|
1589 | ||
|
2829 | ||
|
1590 | 2830 |
|
|
1591 | 2831 |
|
|
1592 | # | |
|
2832 | # | |
|
1593 | 2833 |
|
|
1594 | 2834 |
|
|
1595 | 2835 |
|
|
1596 | 2836 |
|
|
1597 | # | |
|
2837 | # | |
|
1598 | 2838 |
|
|
1599 | # hardwarePhaseShifts = numpy.zeros(5) | |
|
1600 | # | |
|
2839 | # hardwarePhaseShifts = numpy.zeros(5) | |
|
2840 | # | |
|
1601 | 2841 |
|
|
1602 | 2842 |
|
|
1603 | 2843 |
|
|
1604 | 2844 | |
|
1605 | 2845 |
|
|
1606 | ||
|
2846 | ||
|
1607 | 2847 |
|
|
1608 | 2848 |
|
|
1609 | 2849 |
|
|
1610 | 2850 |
|
|
1611 | 2851 |
|
|
1612 | ||
|
1613 |
|
|
|
2852 | ||
|
2853 | #Don't considerate last heights, theyre used to calculate Hardware Phase Shift | |
|
1614 | 2854 |
|
|
1615 | ||
|
2855 | ||
|
1616 | 2856 |
|
|
1617 | 2857 |
|
|
1618 | 2858 |
|
|
1619 | 2859 |
|
|
1620 | 2860 |
|
|
1621 | 2861 |
|
|
1622 | ||
|
2862 | ||
|
1623 | 2863 |
|
|
1624 | 2864 |
|
|
1625 | 2865 |
|
|
1626 | ||
|
2866 | ||
|
1627 | 2867 |
|
|
1628 | 2868 |
|
|
1629 | 2869 |
|
@@ -1633,7 +2873,7 class SMDetection(Operation): | |||
|
1633 | 2873 |
|
|
1634 | 2874 |
|
|
1635 | 2875 |
|
|
1636 | ||
|
2876 | ||
|
1637 | 2877 |
|
|
1638 | 2878 |
|
|
1639 | 2879 |
|
@@ -1643,7 +2883,7 class SMDetection(Operation): | |||
|
1643 | 2883 |
|
|
1644 | 2884 |
|
|
1645 | 2885 |
|
|
1646 | ||
|
2886 | ||
|
1647 | 2887 |
|
|
1648 | 2888 |
|
|
1649 | 2889 |
|
@@ -1654,40 +2894,40 class SMDetection(Operation): | |||
|
1654 | 2894 |
|
|
1655 | 2895 |
|
|
1656 | 2896 |
|
|
1657 | ||
|
2897 | ||
|
1658 | 2898 |
|
|
1659 | 2899 |
|
|
1660 | 2900 |
|
|
1661 |
|
|
|
2901 | listMeteors4 = self.__getRadialVelocity(listMeteors3, listMeteorsVolts, radialStdThresh, pairslist0, dataOut.timeInterval) | |
|
1662 | 2902 | |
|
1663 | 2903 |
|
|
1664 | 2904 |
|
|
1665 | 2905 |
|
|
1666 | 2906 |
|
|
1667 | ||
|
2907 | ||
|
1668 | 2908 |
|
|
1669 | 2909 |
|
|
1670 | 2910 |
|
|
1671 | 2911 |
|
|
1672 | ||
|
2912 | ||
|
1673 | 2913 |
|
|
1674 | 2914 |
|
|
1675 | 2915 |
|
|
1676 | 2916 |
|
|
1677 | 2917 |
|
|
1678 | 2918 |
|
|
1679 | ||
|
2919 | ||
|
1680 | 2920 |
|
|
1681 | 2921 |
|
|
1682 | 2922 |
|
|
1683 | ||
|
2923 | ||
|
1684 | 2924 |
|
|
1685 | 2925 |
|
|
1686 | 2926 |
|
|
1687 | 2927 |
|
|
1688 | 2928 |
|
|
1689 | 2929 |
|
|
1690 | # | |
|
2930 | # | |
|
1691 | 2931 |
|
|
1692 | 2932 |
|
|
1693 | 2933 |
|
@@ -1695,73 +2935,73 class SMDetection(Operation): | |||
|
1695 | 2935 |
|
|
1696 | 2936 |
|
|
1697 | 2937 |
|
|
1698 | ||
|
1699 |
|
|
|
2938 | ||
|
2939 | #***************************+ PASS DATA TO NEXT STEP ********************** | |
|
1700 | 2940 |
|
|
1701 | 2941 |
|
|
1702 | ||
|
1703 |
|
|
|
2942 | ||
|
2943 | if arrayParameters == None: | |
|
1704 | 2944 |
|
|
1705 | 2945 |
|
|
1706 | 2946 |
|
|
1707 | ||
|
2947 | ||
|
1708 | 2948 |
|
|
1709 | ||
|
2949 | ||
|
1710 | 2950 |
|
|
1711 | ||
|
2951 | ||
|
1712 | 2952 |
|
|
1713 | 2953 |
|
|
1714 | ||
|
2954 | ||
|
1715 | 2955 |
|
|
1716 | 2956 |
|
|
1717 | 2957 |
|
|
1718 | 2958 |
|
|
1719 | 2959 |
|
|
1720 | ||
|
2960 | ||
|
1721 | 2961 |
|
|
1722 | 2962 |
|
|
1723 | 2963 |
|
|
1724 | 2964 |
|
|
1725 |
|
|
|
2965 | phaseOffset[:,i] = phaseCCF.transpose() | |
|
1726 | 2966 |
|
|
1727 | 2967 |
|
|
1728 | ||
|
2968 | ||
|
1729 | 2969 |
|
|
1730 | 2970 |
|
|
1731 | 2971 |
|
|
1732 | 2972 |
|
|
1733 | 2973 |
|
|
1734 |
|
|
|
2974 | ind = numpy.where(numpy.logical_or(wt>dw*factor,wt<-dw*factor)) | |
|
1735 | 2975 |
|
|
1736 |
|
|
|
1737 | ||
|
2976 | phaseOffset = stats.nanmean(phaseOffset, axis=1) | |
|
2977 | ||
|
1738 | 2978 |
|
|
1739 | ||
|
2979 | ||
|
1740 | 2980 |
|
|
1741 | 2981 |
|
|
1742 |
|
|
|
2982 | dataShifted = numpy.abs(data) * numpy.exp((numpy.angle(data)+phaseShift)*1j) | |
|
1743 | 2983 |
|
|
1744 | ||
|
2984 | ||
|
1745 | 2985 |
|
|
1746 | 2986 |
|
|
1747 | 2987 |
|
|
1748 | 2988 |
|
|
1749 | 2989 |
|
|
1750 | 2990 |
|
|
1751 | ||
|
2991 | ||
|
1752 | 2992 |
|
|
1753 | 2993 |
|
|
1754 | 2994 |
|
|
1755 | ||
|
1756 |
|
|
|
2995 | ||
|
2996 | if indDer[0].shape[0] > 0: | |
|
1757 | 2997 |
|
|
1758 | 2998 |
|
|
1759 | 2999 |
|
|
1760 | ||
|
3000 | ||
|
1761 | 3001 |
|
|
1762 | 3002 |
|
|
1763 | 3003 |
|
|
1764 | # | |
|
3004 | # | |
|
1765 | 3005 |
|
|
1766 | 3006 |
|
|
1767 | 3007 |
|
@@ -1771,16 +3011,16 class SMDetection(Operation): | |||
|
1771 | 3011 |
|
|
1772 | 3012 |
|
|
1773 | 3013 |
|
|
1774 | ||
|
3014 | ||
|
1775 | 3015 |
|
|
1776 | 3016 |
|
|
1777 | 3017 |
|
|
1778 | 3018 |
|
|
1779 | 3019 |
|
|
1780 | 3020 |
|
|
1781 | ||
|
3021 | ||
|
1782 | 3022 |
|
|
1783 | ||
|
3023 | ||
|
1784 | 3024 |
|
|
1785 | 3025 |
|
|
1786 | 3026 |
|
@@ -1790,25 +3030,25 class SMDetection(Operation): | |||
|
1790 | 3030 |
|
|
1791 | 3031 |
|
|
1792 | 3032 |
|
|
1793 | ||
|
3033 | ||
|
1794 | 3034 |
|
|
1795 | 3035 |
|
|
1796 | 3036 |
|
|
1797 | 3037 |
|
|
1798 | # | |
|
3038 | # | |
|
1799 | 3039 |
|
|
1800 | 3040 |
|
|
1801 | ||
|
3041 | ||
|
1802 | 3042 |
|
|
1803 | 3043 |
|
|
1804 | ||
|
3044 | ||
|
1805 | 3045 |
|
|
1806 | 3046 |
|
|
1807 |
|
|
|
1808 | ||
|
3047 | endInd = endInd + listBlocks[i].shape[1] | |
|
3048 | ||
|
1809 | 3049 |
|
|
1810 | 3050 |
|
|
1811 | ||
|
3051 | ||
|
1812 | 3052 |
|
|
1813 | 3053 |
|
|
1814 | 3054 |
|
@@ -1820,21 +3060,21 class SMDetection(Operation): | |||
|
1820 | 3060 |
|
|
1821 | 3061 |
|
|
1822 | 3062 |
|
|
1823 | ||
|
3063 | ||
|
1824 | 3064 |
|
|
1825 | ||
|
3065 | ||
|
1826 | 3066 |
|
|
1827 | ||
|
3067 | ||
|
1828 | 3068 |
|
|
1829 |
|
|
|
3069 | nPoints = volts.shape[1] | |
|
1830 | 3070 |
|
|
1831 | ||
|
3071 | ||
|
1832 | 3072 |
|
|
1833 | 3073 |
|
|
1834 |
|
|
|
1835 | ||
|
3074 | volts2 = volts[pairslist[i][1]] | |
|
3075 | ||
|
1836 | 3076 |
|
|
1837 |
|
|
|
3077 | idxT = laglist[t] | |
|
1838 | 3078 |
|
|
1839 | 3079 |
|
|
1840 | 3080 |
|
@@ -1842,10 +3082,10 class SMDetection(Operation): | |||
|
1842 | 3082 |
|
|
1843 | 3083 |
|
|
1844 | 3084 |
|
|
1845 | ||
|
3085 | ||
|
1846 | 3086 |
|
|
1847 | 3087 |
|
|
1848 | ||
|
3088 | ||
|
1849 | 3089 |
|
|
1850 | 3090 |
|
|
1851 | 3091 |
|
@@ -1854,133 +3094,133 class SMDetection(Operation): | |||
|
1854 | 3094 |
|
|
1855 | 3095 |
|
|
1856 | 3096 |
|
|
1857 | ||
|
3097 | ||
|
1858 | 3098 |
|
|
1859 | 3099 |
|
|
1860 | ||
|
3100 | ||
|
1861 | 3101 |
|
|
1862 | 3102 |
|
|
1863 |
|
|
|
1864 | ||
|
3103 | endInd = endInd + listPower[i].shape[0] | |
|
3104 | ||
|
1865 | 3105 |
|
|
1866 | 3106 |
|
|
1867 | 3107 |
|
|
1868 | 3108 |
|
|
1869 |
|
|
|
1870 | ||
|
3109 | noise[startInd:endInd,:] = noise[startInd:endInd,:] + noiseAux | |
|
3110 | ||
|
1871 | 3111 |
|
|
1872 |
|
|
|
1873 | ||
|
3112 | noise1[startInd:endInd,:] = noise1[startInd:endInd,:] + noiseAux1 | |
|
3113 | ||
|
1874 | 3114 |
|
|
1875 | ||
|
3115 | ||
|
1876 | 3116 |
|
|
1877 | 3117 |
|
|
1878 | 3118 |
|
|
1879 | 3119 |
|
|
1880 | ||
|
3120 | ||
|
1881 | 3121 |
|
|
1882 | 3122 |
|
|
1883 | 3123 |
|
|
1884 | ||
|
3124 | ||
|
1885 | 3125 |
|
|
1886 | 3126 |
|
|
1887 | ||
|
3127 | ||
|
1888 | 3128 |
|
|
1889 | ||
|
3129 | ||
|
1890 | 3130 |
|
|
1891 | 3131 |
|
|
1892 | 3132 |
|
|
1893 | 3133 |
|
|
1894 | ||
|
3134 | ||
|
1895 | 3135 |
|
|
1896 | 3136 |
|
|
1897 | indInit = indUPthresh[j] if isinstance(indUPthresh[j], (int, float)) else indUPthresh[j][0] ##CHECK!!!! | |
|
1898 | ||
|
3137 | indInit = indUPthresh[j] | |
|
3138 | ||
|
1899 | 3139 |
|
|
1900 | 3140 |
|
|
1901 | 3141 |
|
|
1902 | ||
|
3142 | ||
|
1903 | 3143 |
|
|
1904 | 3144 |
|
|
1905 | 3145 |
|
|
1906 | 3146 |
|
|
1907 | ||
|
3147 | ||
|
1908 | 3148 |
|
|
1909 | ||
|
3149 | ||
|
1910 | 3150 |
|
|
1911 | ||
|
1912 |
|
|
|
3151 | ||
|
3152 | arrayMeteors = numpy.asarray(listMeteors) | |
|
1913 | 3153 |
|
|
1914 | ||
|
3154 | ||
|
1915 | 3155 |
|
|
1916 | 3156 |
|
|
1917 | 3157 |
|
|
1918 | 3158 |
|
|
1919 | ||
|
3159 | ||
|
1920 | 3160 |
|
|
1921 | 3161 |
|
|
1922 | 3162 |
|
|
1923 | ||
|
3163 | ||
|
1924 | 3164 |
|
|
1925 | 3165 |
|
|
1926 | 3166 |
|
|
1927 | 3167 |
|
|
1928 | 3168 |
|
|
1929 | ||
|
3169 | ||
|
1930 | 3170 |
|
|
1931 | 3171 |
|
|
1932 | 3172 |
|
|
1933 | 3173 |
|
|
1934 | ||
|
3174 | ||
|
1935 | 3175 |
|
|
1936 | ||
|
3176 | ||
|
1937 | 3177 |
|
|
1938 | ||
|
3178 | ||
|
1939 | 3179 |
|
|
1940 | 3180 |
|
|
1941 | 3181 |
|
|
1942 | ||
|
3182 | ||
|
1943 | 3183 |
|
|
1944 | 3184 |
|
|
1945 | 3185 |
|
|
1946 | ||
|
3186 | ||
|
1947 | 3187 |
|
|
1948 | 3188 |
|
|
1949 | 3189 |
|
|
1950 | ||
|
3190 | ||
|
1951 | 3191 |
|
|
1952 |
|
|
|
1953 |
|
|
|
3192 | pairslist1.append((0,1)) | |
|
3193 | pairslist1.append((3,4)) | |
|
1954 | 3194 | |
|
1955 | 3195 |
|
|
1956 | 3196 |
|
|
1957 | 3197 |
|
|
1958 | 3198 |
|
|
1959 | ||
|
1960 |
|
|
|
3199 | ||
|
3200 | if frequency == 30e6: | |
|
1961 | 3201 |
|
|
1962 | 3202 |
|
|
1963 | 3203 |
|
|
1964 |
|
|
|
1965 | ||
|
3204 | lag = numpy.ceil(timeLag/timeInterval) | |
|
3205 | ||
|
1966 | 3206 |
|
|
1967 | ||
|
3207 | ||
|
1968 | 3208 |
|
|
1969 | 3209 |
|
|
1970 | ||
|
3210 | ||
|
1971 | 3211 |
|
|
1972 |
|
|
|
1973 |
|
|
|
1974 |
|
|
|
1975 |
|
|
|
1976 | ||
|
3212 | mHeight = listMeteors[i][0] | |
|
3213 | mStart = listMeteors[i][1] | |
|
3214 | mPeak = listMeteors[i][2] | |
|
3215 | mEnd = listMeteors[i][3] | |
|
3216 | ||
|
1977 | 3217 |
|
|
1978 | 3218 |
|
|
1979 | 3219 |
|
|
1980 | ||
|
3220 | ||
|
1981 | 3221 |
|
|
1982 | 3222 |
|
|
1983 | ||
|
3223 | ||
|
1984 | 3224 |
|
|
1985 | 3225 |
|
|
1986 | 3226 |
|
@@ -1988,15 +3228,15 class SMDetection(Operation): | |||
|
1988 | 3228 |
|
|
1989 | 3229 |
|
|
1990 | 3230 |
|
|
1991 | ||
|
3231 | ||
|
1992 | 3232 |
|
|
1993 | 3233 |
|
|
1994 | 3234 |
|
|
1995 |
|
|
|
1996 | ||
|
1997 |
|
|
|
3235 | mStart1 = mStart1[-1] + 1 | |
|
3236 | ||
|
3237 | else: | |
|
1998 | 3238 |
|
|
1999 | ||
|
3239 | ||
|
2000 | 3240 |
|
|
2001 | 3241 |
|
|
2002 | 3242 |
|
@@ -2004,7 +3244,7 class SMDetection(Operation): | |||
|
2004 | 3244 |
|
|
2005 | 3245 |
|
|
2006 | 3246 |
|
|
2007 | ||
|
3247 | ||
|
2008 | 3248 |
|
|
2009 | 3249 |
|
|
2010 | 3250 |
|
@@ -2013,17 +3253,17 class SMDetection(Operation): | |||
|
2013 | 3253 |
|
|
2014 | 3254 |
|
|
2015 | 3255 |
|
|
2016 | ||
|
3256 | ||
|
2017 | 3257 |
|
|
2018 | 3258 |
|
|
2019 |
|
|
|
3259 | if meteorVolts2.shape[1] > 0: | |
|
2020 | 3260 |
|
|
2021 | 3261 |
|
|
2022 | 3262 |
|
|
2023 | 3263 |
|
|
2024 | 3264 |
|
|
2025 | 3265 |
|
|
2026 | ||
|
3266 | ||
|
2027 | 3267 |
|
|
2028 | 3268 |
|
|
2029 | 3269 |
|
@@ -2038,50 +3278,50 class SMDetection(Operation): | |||
|
2038 | 3278 |
|
|
2039 | 3279 |
|
|
2040 | 3280 |
|
|
2041 | ||
|
3281 | ||
|
2042 | 3282 |
|
|
2043 | 3283 |
|
|
2044 | 3284 |
|
|
2045 | 3285 |
|
|
2046 | 3286 |
|
|
2047 | ||
|
2048 | ||
|
2049 |
|
|
|
3287 | ||
|
3288 | ||
|
3289 | else: | |
|
2050 | 3290 |
|
|
2051 | 3291 |
|
|
2052 | 3292 |
|
|
2053 | ||
|
3293 | ||
|
2054 | 3294 |
|
|
2055 | 3295 |
|
|
2056 | 3296 |
|
|
2057 | ||
|
2058 |
|
|
|
2059 | ||
|
3297 | ||
|
3298 | return listMeteors1, listPowerSeries, listVoltageSeries | |
|
3299 | ||
|
2060 | 3300 |
|
|
2061 | ||
|
3301 | ||
|
2062 | 3302 |
|
|
2063 | 3303 |
|
|
2064 |
|
|
|
3304 | if frequency == 30e6: | |
|
2065 | 3305 |
|
|
2066 | 3306 |
|
|
2067 | 3307 |
|
|
2068 |
|
|
|
2069 | ||
|
3308 | lag = numpy.ceil(timeLag/timeInterval) | |
|
3309 | ||
|
2070 | 3310 |
|
|
2071 | ||
|
3311 | ||
|
2072 | 3312 |
|
|
2073 | 3313 |
|
|
2074 | 3314 |
|
|
2075 | ||
|
3315 | ||
|
2076 | 3316 |
|
|
2077 | 3317 | |
|
2078 |
|
|
|
3318 | try: | |
|
2079 | 3319 |
|
|
2080 | 3320 |
|
|
2081 | ||
|
3321 | ||
|
2082 | 3322 |
|
|
2083 | 3323 |
|
|
2084 | ||
|
3324 | ||
|
2085 | 3325 |
|
|
2086 | 3326 |
|
|
2087 | 3327 |
|
@@ -2090,26 +3330,26 class SMDetection(Operation): | |||
|
2090 | 3330 |
|
|
2091 | 3331 |
|
|
2092 | 3332 |
|
|
2093 | ||
|
3333 | ||
|
2094 | 3334 |
|
|
2095 | 3335 |
|
|
2096 | 3336 |
|
|
2097 | ||
|
3337 | ||
|
2098 | 3338 |
|
|
2099 | 3339 |
|
|
2100 |
|
|
|
3340 | meteorAux[-1] = 7 | |
|
2101 | 3341 |
|
|
2102 | 3342 |
|
|
2103 | 3343 |
|
|
2104 |
|
|
|
2105 | ||
|
2106 | ||
|
3344 | meteorAux[-1] = 11 | |
|
3345 | ||
|
3346 | ||
|
2107 | 3347 |
|
|
2108 |
|
|
|
2109 | ||
|
2110 | ||
|
3348 | meteorAux[-1] = 11 | |
|
3349 | ||
|
3350 | ||
|
2111 | 3351 |
|
|
2112 | ||
|
3352 | ||
|
2113 | 3353 |
|
|
2114 | 3354 | |
|
2115 | 3355 |
|
@@ -2117,45 +3357,45 class SMDetection(Operation): | |||
|
2117 | 3357 |
|
|
2118 | 3358 |
|
|
2119 | 3359 |
|
|
2120 | ||
|
3360 | ||
|
2121 | 3361 |
|
|
2122 | ||
|
3362 | ||
|
2123 | 3363 |
|
|
2124 |
|
|
|
2125 |
|
|
|
3364 | pairslist1.append((0,1)) | |
|
3365 | pairslist1.append((3,4)) | |
|
2126 | 3366 |
|
|
2127 | 3367 |
|
|
2128 | 3368 |
|
|
2129 | 3369 |
|
|
2130 | 3370 |
|
|
2131 |
|
|
|
2132 | ||
|
3371 | freq = 30e6 | |
|
3372 | ||
|
2133 | 3373 |
|
|
2134 | ||
|
3374 | ||
|
2135 | 3375 |
|
|
2136 | 3376 |
|
|
2137 | 3377 |
|
|
2138 | 3378 |
|
|
2139 |
|
|
|
3379 | mPeak = listMeteors[i][2] | |
|
2140 | 3380 |
|
|
2141 | ||
|
3381 | ||
|
2142 | 3382 |
|
|
2143 | 3383 |
|
|
2144 | 3384 |
|
|
2145 | 3385 | |
|
2146 | 3386 |
|
|
2147 | 3387 |
|
|
2148 | ||
|
3388 | ||
|
2149 | 3389 |
|
|
2150 | 3390 |
|
|
2151 | 3391 |
|
|
2152 |
|
|
|
2153 | ||
|
3392 | angAllCCF = numpy.angle(allCCFs[:,[0,1,3,4],0]) | |
|
3393 | ||
|
2154 | 3394 |
|
|
2155 | 3395 |
|
|
2156 | 3396 |
|
|
2157 | ||
|
2158 |
|
|
|
3397 | ||
|
3398 | if indDer[0].shape[0] > 0: | |
|
2159 | 3399 |
|
|
2160 | 3400 |
|
|
2161 | 3401 |
|
@@ -2164,51 +3404,51 class SMDetection(Operation): | |||
|
2164 | 3404 |
|
|
2165 | 3405 |
|
|
2166 | 3406 |
|
|
2167 | ||
|
3407 | ||
|
2168 | 3408 |
|
|
2169 | 3409 |
|
|
2170 | 3410 |
|
|
2171 | 3411 |
|
|
2172 | 3412 |
|
|
2173 | ||
|
3413 | ||
|
2174 | 3414 |
|
|
2175 | 3415 |
|
|
2176 | 3416 |
|
|
2177 | 3417 |
|
|
2178 | ||
|
3418 | ||
|
2179 | 3419 |
|
|
2180 | 3420 |
|
|
2181 |
|
|
|
3421 | if numpy.abs(radialVelocity) > 200: | |
|
2182 | 3422 |
|
|
2183 | 3423 |
|
|
2184 | 3424 |
|
|
2185 | 3425 |
|
|
2186 | ||
|
3426 | ||
|
2187 | 3427 |
|
|
2188 | 3428 |
|
|
2189 | ||
|
3429 | ||
|
2190 | 3430 |
|
|
2191 | ||
|
3431 | ||
|
2192 | 3432 |
|
|
2193 | 3433 |
|
|
2194 | 3434 |
|
|
2195 | ||
|
3435 | ||
|
2196 | 3436 |
|
|
2197 | 3437 |
|
|
2198 | 3438 |
|
|
2199 | 3439 |
|
|
2200 | # | |
|
3440 | # | |
|
2201 | 3441 |
|
|
2202 | 3442 |
|
|
2203 | # | |
|
3443 | # | |
|
2204 | 3444 |
|
|
2205 | 3445 |
|
|
2206 | 3446 |
|
|
2207 | ||
|
3447 | ||
|
2208 | 3448 |
|
|
2209 | 3449 |
|
|
2210 | 3450 |
|
|
2211 | ||
|
3451 | ||
|
2212 | 3452 |
|
|
2213 | 3453 |
|
|
2214 | 3454 |
|
@@ -2216,13 +3456,13 class SMDetection(Operation): | |||
|
2216 | 3456 |
|
|
2217 | 3457 |
|
|
2218 | 3458 | |
|
2219 | ||
|
3459 | ||
|
2220 | 3460 |
|
|
2221 | ||
|
3461 | ||
|
2222 | 3462 |
|
|
2223 | ||
|
3463 | ||
|
2224 | 3464 |
|
|
2225 | ||
|
3465 | ||
|
2226 | 3466 |
|
|
2227 | 3467 |
|
|
2228 | 3468 |
|
@@ -2230,49 +3470,49 class CorrectSMPhases(Operation): | |||
|
2230 | 3470 |
|
|
2231 | 3471 |
|
|
2232 | 3472 |
|
|
2233 | ||
|
3473 | ||
|
2234 | 3474 |
|
|
2235 | 3475 |
|
|
2236 | 3476 |
|
|
2237 | ||
|
3477 | ||
|
2238 | 3478 |
|
|
2239 |
|
|
|
3479 | if channelPositions == None: | |
|
2240 | 3480 |
|
|
2241 | 3481 |
|
|
2242 | ||
|
3482 | ||
|
2243 | 3483 |
|
|
2244 | 3484 |
|
|
2245 | ||
|
3485 | ||
|
2246 | 3486 |
|
|
2247 | ||
|
3487 | ||
|
2248 | 3488 |
|
|
2249 | 3489 |
|
|
2250 | 3490 | |
|
2251 | 3491 |
|
|
2252 | ||
|
3492 | ||
|
2253 | 3493 |
|
|
2254 | 3494 | |
|
2255 | 3495 |
|
|
2256 | 3496 | |
|
2257 | 3497 |
|
|
2258 | ||
|
3498 | ||
|
2259 | 3499 |
|
|
2260 | ||
|
3500 | ||
|
2261 | 3501 |
|
|
2262 | ||
|
3502 | ||
|
2263 | 3503 |
|
|
2264 | 3504 |
|
|
2265 | ||
|
3505 | ||
|
2266 | 3506 |
|
|
2267 | 3507 |
|
|
2268 | ||
|
3508 | ||
|
2269 | 3509 |
|
|
2270 | ||
|
3510 | ||
|
2271 | 3511 |
|
|
2272 | 3512 |
|
|
2273 | ||
|
3513 | ||
|
2274 | 3514 |
|
|
2275 | ||
|
3515 | ||
|
2276 | 3516 |
|
|
2277 | 3517 | |
|
2278 | 3518 |
|
@@ -2286,7 +3526,7 class SMPhaseCalibration(Operation): | |||
|
2286 | 3526 |
|
|
2287 | 3527 |
|
|
2288 | 3528 |
|
|
2289 | ||
|
3529 | ||
|
2290 | 3530 |
|
|
2291 | 3531 |
|
|
2292 | 3532 | |
@@ -2295,39 +3535,39 class SMPhaseCalibration(Operation): | |||
|
2295 | 3535 |
|
|
2296 | 3536 |
|
|
2297 | 3537 |
|
|
2298 | ||
|
3538 | ||
|
2299 | 3539 |
|
|
2300 | 3540 |
|
|
2301 | 3541 |
|
|
2302 | 3542 |
|
|
2303 | ||
|
3543 | ||
|
2304 | 3544 |
|
|
2305 | 3545 |
|
|
2306 | 3546 |
|
|
2307 | 3547 |
|
|
2308 | 3548 |
|
|
2309 | ||
|
3549 | ||
|
2310 | 3550 |
|
|
2311 | 3551 |
|
|
2312 | 3552 |
|
|
2313 | 3553 |
|
|
2314 | 3554 |
|
|
2315 | 3555 |
|
|
2316 | ||
|
3556 | ||
|
2317 | 3557 |
|
|
2318 | 3558 |
|
|
2319 | ||
|
3559 | ||
|
2320 | 3560 |
|
|
2321 | 3561 |
|
|
2322 | ||
|
3562 | ||
|
2323 | 3563 |
|
|
2324 | ||
|
3564 | ||
|
2325 | 3565 |
|
|
2326 | ||
|
3566 | ||
|
2327 | 3567 |
|
|
2328 | 3568 | |
|
2329 | 3569 |
|
|
2330 | ||
|
3570 | ||
|
2331 | 3571 |
|
|
2332 | 3572 | |
|
2333 | 3573 |
|
@@ -2348,16 +3588,16 class SMPhaseCalibration(Operation): | |||
|
2348 | 3588 |
|
|
2349 | 3589 |
|
|
2350 | 3590 |
|
|
2351 | ||
|
3591 | ||
|
2352 | 3592 |
|
|
2353 | 3593 |
|
|
2354 | ||
|
3594 | ||
|
2355 | 3595 |
|
|
2356 | 3596 |
|
|
2357 | 3597 |
|
|
2358 | 3598 |
|
|
2359 | 3599 |
|
|
2360 | ||
|
3600 | ||
|
2361 | 3601 |
|
|
2362 | 3602 |
|
|
2363 | 3603 |
|
@@ -2387,24 +3627,24 class SMPhaseCalibration(Operation): | |||
|
2387 | 3627 |
|
|
2388 | 3628 |
|
|
2389 | 3629 |
|
|
2390 | ||
|
3630 | ||
|
2391 | 3631 |
|
|
2392 | 3632 |
|
|
2393 | ||
|
3633 | ||
|
2394 | 3634 |
|
|
2395 | 3635 |
|
|
2396 | ||
|
3636 | ||
|
2397 | 3637 |
|
|
2398 |
|
|
|
3638 | phOffset = phOffset*180/numpy.pi | |
|
2399 | 3639 |
|
|
2400 | ||
|
2401 | ||
|
3640 | ||
|
3641 | ||
|
2402 | 3642 |
|
|
2403 | ||
|
3643 | ||
|
2404 | 3644 |
|
|
2405 |
|
|
|
3645 | self.__dataReady = False | |
|
2406 | 3646 |
|
|
2407 | ||
|
3647 | ||
|
2408 | 3648 |
|
|
2409 | 3649 |
|
|
2410 | 3650 |
|
@@ -2412,19 +3652,19 class SMPhaseCalibration(Operation): | |||
|
2412 | 3652 |
|
|
2413 | 3653 | |
|
2414 | 3654 |
|
|
2415 | ||
|
2416 |
|
|
|
3655 | ||
|
3656 | if self.__buffer == None: | |
|
2417 | 3657 |
|
|
2418 | 3658 | |
|
2419 | 3659 |
|
|
2420 | 3660 |
|
|
2421 | ||
|
3661 | ||
|
2422 | 3662 |
|
|
2423 | ||
|
3663 | ||
|
2424 | 3664 |
|
|
2425 | 3665 |
|
|
2426 | 3666 |
|
|
2427 | ||
|
3667 | ||
|
2428 | 3668 |
|
|
2429 | 3669 |
|
|
2430 | 3670 |
|
@@ -2452,7 +3692,7 class SMPhaseCalibration(Operation): | |||
|
2452 | 3692 |
|
|
2453 | 3693 |
|
|
2454 | 3694 |
|
|
2455 | ||
|
3695 | ||
|
2456 | 3696 |
|
|
2457 | 3697 |
|
|
2458 | 3698 |
|
@@ -2460,7 +3700,7 class SMPhaseCalibration(Operation): | |||
|
2460 | 3700 |
|
|
2461 | 3701 |
|
|
2462 | 3702 |
|
|
2463 | ||
|
3703 | ||
|
2464 | 3704 |
|
|
2465 | 3705 |
|
|
2466 | 3706 |
|
@@ -2469,24 +3709,23 class SMPhaseCalibration(Operation): | |||
|
2469 | 3709 |
|
|
2470 | 3710 |
|
|
2471 | 3711 |
|
|
2472 | dataOut.channelList = pairslist0 | |
|
2473 | 3712 |
|
|
2474 | ||
|
2475 | ||
|
3713 | ||
|
3714 | ||
|
2476 | 3715 |
|
|
2477 | ||
|
3716 | ||
|
2478 | 3717 |
|
|
2479 | ||
|
3718 | ||
|
2480 | 3719 |
|
|
2481 | ||
|
3720 | ||
|
2482 | 3721 |
|
|
2483 | ||
|
3722 | ||
|
2484 | 3723 |
|
|
2485 | ||
|
3724 | ||
|
2486 | 3725 |
|
|
2487 | 3726 |
|
|
2488 | 3727 |
|
|
2489 | ||
|
3728 | ||
|
2490 | 3729 |
|
|
2491 | 3730 |
|
|
2492 | 3731 |
|
@@ -2494,72 +3733,72 class SMOperations(): | |||
|
2494 | 3733 |
|
|
2495 | 3734 |
|
|
2496 | 3735 |
|
|
2497 | ||
|
3736 | ||
|
2498 | 3737 |
|
|
2499 | 3738 |
|
|
2500 | 3739 |
|
|
2501 | 3740 |
|
|
2502 | 3741 |
|
|
2503 | ||
|
3742 | ||
|
2504 | 3743 |
|
|
2505 | 3744 |
|
|
2506 | 3745 |
|
|
2507 | 3746 |
|
|
2508 | ||
|
3747 | ||
|
2509 | 3748 |
|
|
2510 | ||
|
3749 | ||
|
2511 | 3750 |
|
|
2512 | ||
|
3751 | ||
|
2513 | 3752 |
|
|
2514 | 3753 |
|
|
2515 | ||
|
3754 | ||
|
2516 | 3755 |
|
|
2517 | 3756 |
|
|
2518 | 3757 |
|
|
2519 | ||
|
3758 | ||
|
2520 | 3759 |
|
|
2521 | 3760 |
|
|
2522 | ||
|
3761 | ||
|
2523 | 3762 |
|
|
2524 | 3763 |
|
|
2525 | 3764 |
|
|
2526 | 3765 |
|
|
2527 | 3766 |
|
|
2528 |
|
|
|
3767 | error[indInvalid] = 3 | |
|
2529 | 3768 |
|
|
2530 | 3769 |
|
|
2531 |
|
|
|
3770 | error[indInvalid] = 4 | |
|
2532 | 3771 |
|
|
2533 | ||
|
3772 | ||
|
2534 | 3773 |
|
|
2535 | ||
|
3774 | ||
|
2536 | 3775 |
|
|
2537 | 3776 |
|
|
2538 | 3777 |
|
|
2539 | ||
|
3778 | ||
|
2540 | 3779 |
|
|
2541 | 3780 |
|
|
2542 | ||
|
2543 | ||
|
3781 | ||
|
3782 | ||
|
2544 | 3783 |
|
|
2545 | 3784 |
|
|
2546 | 3785 |
|
|
2547 | 3786 |
|
|
2548 | 3787 |
|
|
2549 | ||
|
2550 |
|
|
|
3788 | ||
|
3789 | ph0_aux = ph0 + ph1 | |
|
2551 | 3790 |
|
|
2552 | 3791 |
|
|
2553 | # ph0_aux[ph0_aux < -numpy.pi] += 2*numpy.pi | |
|
3792 | # ph0_aux[ph0_aux < -numpy.pi] += 2*numpy.pi | |
|
2554 | 3793 |
|
|
2555 | 3794 |
|
|
2556 | ||
|
3795 | ||
|
2557 | 3796 |
|
|
2558 | 3797 |
|
|
2559 | 3798 |
|
|
2560 | 3799 |
|
|
2561 | 3800 |
|
|
2562 | ||
|
3801 | ||
|
2563 | 3802 |
|
|
2564 | 3803 |
|
|
2565 | 3804 |
|
@@ -2568,59 +3807,59 class SMOperations(): | |||
|
2568 | 3807 |
|
|
2569 | 3808 |
|
|
2570 | 3809 |
|
|
2571 | ||
|
3810 | ||
|
2572 | 3811 |
|
|
2573 | ||
|
3812 | ||
|
2574 | 3813 |
|
|
2575 | 3814 |
|
|
2576 | 3815 |
|
|
2577 | ||
|
3816 | ||
|
2578 | 3817 |
|
|
2579 | 3818 |
|
|
2580 | 3819 |
|
|
2581 | ||
|
3820 | ||
|
2582 | 3821 |
|
|
2583 | ||
|
3822 | ||
|
2584 | 3823 |
|
|
2585 | ||
|
3824 | ||
|
2586 | 3825 |
|
|
2587 | 3826 |
|
|
2588 | 3827 |
|
|
2589 | ||
|
3828 | ||
|
2590 | 3829 |
|
|
2591 | 3830 |
|
|
2592 | 3831 | |
|
2593 | 3832 |
|
|
2594 | ||
|
3833 | ||
|
2595 | 3834 |
|
|
2596 | 3835 |
|
|
2597 | ||
|
3836 | ||
|
2598 | 3837 |
|
|
2599 | 3838 |
|
|
2600 | 3839 |
|
|
2601 | ||
|
3840 | ||
|
2602 | 3841 |
|
|
2603 | 3842 |
|
|
2604 | 3843 |
|
|
2605 | 3844 |
|
|
2606 | 3845 |
|
|
2607 | ||
|
3846 | ||
|
2608 | 3847 |
|
|
2609 | 3848 |
|
|
2610 |
|
|
|
3849 | #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km | |
|
2611 | 3850 |
|
|
2612 | 3851 |
|
|
2613 |
|
|
|
3852 | indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0] | |
|
2614 | 3853 |
|
|
2615 | 3854 |
|
|
2616 |
|
|
|
2617 | ||
|
3855 | error[indInvalid1] = 13 | |
|
3856 | ||
|
2618 | 3857 |
|
|
2619 | ||
|
3858 | ||
|
2620 | 3859 |
|
|
2621 | 3860 |
|
|
2622 | 3861 |
|
|
2623 | ||
|
3862 | ||
|
2624 | 3863 |
|
|
2625 | 3864 |
|
|
2626 | 3865 |
|
@@ -2628,15 +3867,15 class SMOperations(): | |||
|
2628 | 3867 |
|
|
2629 | 3868 |
|
|
2630 | 3869 |
|
|
2631 | ||
|
3870 | ||
|
2632 | 3871 |
|
|
2633 | 3872 |
|
|
2634 | ||
|
3873 | ||
|
2635 | 3874 |
|
|
2636 | 3875 |
|
|
2637 | ||
|
3876 | ||
|
2638 | 3877 |
|
|
2639 | ||
|
3878 | ||
|
2640 | 3879 |
|
|
2641 | 3880 |
|
|
2642 | 3881 |
|
@@ -2645,7 +3884,7 class SMOperations(): | |||
|
2645 | 3884 |
|
|
2646 | 3885 |
|
|
2647 | 3886 |
|
|
2648 | ||
|
3887 | ||
|
2649 | 3888 |
|
|
2650 | 3889 |
|
|
2651 | 3890 |
|
@@ -2653,7 +3892,7 class SMOperations(): | |||
|
2653 | 3892 |
|
|
2654 | 3893 |
|
|
2655 | 3894 |
|
|
2656 | ||
|
3895 | ||
|
2657 | 3896 |
|
|
2658 | 3897 |
|
|
2659 | 3898 |
|
@@ -2661,7 +3900,7 class SMOperations(): | |||
|
2661 | 3900 |
|
|
2662 | 3901 |
|
|
2663 | 3902 |
|
|
2664 |
|
|
|
3903 | if diff1<0: | |
|
2665 | 3904 |
|
|
2666 | 3905 |
|
|
2667 | 3906 |
|
@@ -2671,7 +3910,7 class SMOperations(): | |||
|
2671 | 3910 |
|
|
2672 | 3911 |
|
|
2673 | 3912 |
|
|
2674 | ||
|
3913 | ||
|
2675 | 3914 |
|
|
2676 | 3915 |
|
|
2677 | 3916 |
|
@@ -2683,10 +3922,10 class SMOperations(): | |||
|
2683 | 3922 |
|
|
2684 | 3923 |
|
|
2685 | 3924 |
|
|
2686 | # | |
|
3925 | # | |
|
2687 | 3926 |
|
|
2688 | 3927 |
|
|
2689 | # | |
|
3928 | # | |
|
2690 | 3929 |
|
|
2691 | 3930 |
|
|
2692 | 3931 |
|
@@ -2695,59 +3934,59 class SMOperations(): | |||
|
2695 | 3934 |
|
|
2696 | 3935 |
|
|
2697 | 3936 |
|
|
2698 | ||
|
3937 | ||
|
2699 | 3938 |
|
|
2700 |
|
|
|
2701 | ||
|
3939 | pairslist = [(chanCX, chan1X),(chanCX, chan2X),(chanCY,chan1Y),(chanCY, chan2Y)] | |
|
3940 | ||
|
2702 | 3941 |
|
|
2703 | 3942 |
|
|
2704 | # | |
|
3943 | # | |
|
2705 | 3944 |
|
|
2706 | 3945 |
|
|
2707 | # | |
|
3946 | # | |
|
2708 | 3947 |
|
|
2709 | 3948 |
|
|
2710 | 3949 |
|
|
2711 | # | |
|
3950 | # | |
|
2712 | 3951 |
|
|
2713 | 3952 |
|
|
2714 | # | |
|
3953 | # | |
|
2715 | 3954 |
|
|
2716 | 3955 |
|
|
2717 | 3956 |
|
|
2718 | # error[indInvalid] = 3 | |
|
3957 | # error[indInvalid] = 3 | |
|
2719 | 3958 |
|
|
2720 | 3959 |
|
|
2721 | # error[indInvalid] = 4 | |
|
3960 | # error[indInvalid] = 4 | |
|
2722 | 3961 |
|
|
2723 | # | |
|
3962 | # | |
|
2724 | 3963 |
|
|
2725 | # | |
|
3964 | # | |
|
2726 | 3965 |
|
|
2727 | 3966 |
|
|
2728 | 3967 |
|
|
2729 | # | |
|
3968 | # | |
|
2730 | 3969 |
|
|
2731 | 3970 |
|
|
2732 | # | |
|
2733 | # | |
|
3971 | # | |
|
3972 | # | |
|
2734 | 3973 |
|
|
2735 | 3974 |
|
|
2736 | 3975 |
|
|
2737 | 3976 |
|
|
2738 | 3977 |
|
|
2739 | # phi0_aux[indcsi] -= 2*numpy.pi | |
|
3978 | # phi0_aux[indcsi] -= 2*numpy.pi | |
|
2740 | 3979 |
|
|
2741 | # phi0_aux[indcsi] += 2*numpy.pi | |
|
3980 | # phi0_aux[indcsi] += 2*numpy.pi | |
|
2742 | 3981 |
|
|
2743 | 3982 |
|
|
2744 | # | |
|
3983 | # | |
|
2745 | 3984 |
|
|
2746 | 3985 |
|
|
2747 | 3986 |
|
|
2748 | 3987 |
|
|
2749 | 3988 |
|
|
2750 | # | |
|
3989 | # | |
|
2751 | 3990 |
|
|
2752 | 3991 |
|
|
2753 | 3992 |
|
@@ -2756,50 +3995,51 class SMOperations(): | |||
|
2756 | 3995 |
|
|
2757 | 3996 |
|
|
2758 | 3997 |
|
|
2759 | # | |
|
3998 | # | |
|
2760 | 3999 |
|
|
2761 | # | |
|
4000 | # | |
|
2762 | 4001 |
|
|
2763 | 4002 |
|
|
2764 | 4003 |
|
|
2765 | # | |
|
4004 | # | |
|
2766 | 4005 |
|
|
2767 | 4006 |
|
|
2768 | 4007 |
|
|
2769 | # | |
|
4008 | # | |
|
2770 | 4009 |
|
|
2771 | # | |
|
4010 | # | |
|
2772 | 4011 |
|
|
2773 | # | |
|
4012 | # | |
|
2774 | 4013 |
|
|
2775 | 4014 |
|
|
2776 | 4015 |
|
|
2777 | # | |
|
4016 | # | |
|
2778 | 4017 |
|
|
2779 | 4018 |
|
|
2780 | # | |
|
4019 | # | |
|
2781 | 4020 |
|
|
2782 | # | |
|
4021 | # | |
|
2783 | 4022 |
|
|
2784 | 4023 |
|
|
2785 | # | |
|
4024 | # | |
|
2786 | 4025 |
|
|
2787 | 4026 |
|
|
2788 | 4027 |
|
|
2789 | # | |
|
4028 | # | |
|
2790 | 4029 |
|
|
2791 | 4030 |
|
|
2792 | # | |
|
2793 | # hCorr = hi[ind_hCorr] | |
|
4031 | # | |
|
4032 | # hCorr = hi[ind_hCorr] | |
|
2794 | 4033 |
|
|
2795 | # | |
|
4034 | # | |
|
2796 | 4035 |
|
|
2797 | 4036 |
|
|
2798 | # #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km | |
|
2799 | # | |
|
2800 | # indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0] | |
|
4037 | # #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km | |
|
4038 | # | |
|
4039 | # indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0] | |
|
2801 | 4040 |
|
|
2802 | 4041 |
|
|
2803 | # error[indInvalid1] = 13 | |
|
2804 | # | |
|
2805 | # return heights, error | |
|
4042 | # error[indInvalid1] = 13 | |
|
4043 | # | |
|
4044 | # return heights, error | |
|
4045 | No newline at end of file |
@@ -1,3 +1,5 | |||
|
1 | import itertools | |
|
2 | ||
|
1 | 3 | import numpy |
|
2 | 4 | |
|
3 | 5 | from jroproc_base import ProcessingUnit, Operation |
@@ -109,7 +111,10 class SpectraProc(ProcessingUnit): | |||
|
109 | 111 | |
|
110 | 112 | if self.dataIn.type == "Spectra": |
|
111 | 113 | self.dataOut.copy(self.dataIn) |
|
112 |
|
|
|
114 | if not pairsList: | |
|
115 | pairsList = itertools.combinations(self.dataOut.channelList, 2) | |
|
116 | if self.dataOut.data_cspc is not None: | |
|
117 | self.__selectPairs(pairsList) | |
|
113 | 118 | return True |
|
114 | 119 | |
|
115 | 120 | if self.dataIn.type == "Voltage": |
@@ -178,27 +183,21 class SpectraProc(ProcessingUnit): | |||
|
178 | 183 | |
|
179 | 184 | def __selectPairs(self, pairsList): |
|
180 | 185 | |
|
181 | if channelList == None: | |
|
186 | if not pairsList: | |
|
182 | 187 | return |
|
183 | 188 | |
|
184 |
pairs |
|
|
185 | ||
|
186 | for thisPair in pairsList: | |
|
189 | pairs = [] | |
|
190 | pairsIndex = [] | |
|
187 | 191 | |
|
188 |
|
|
|
192 | for pair in pairsList: | |
|
193 | if pair[0] not in self.dataOut.channelList or pair[1] not in self.dataOut.channelList: | |
|
189 | 194 | continue |
|
190 | ||
|
191 |
pairIndex |
|
|
192 | ||
|
193 | pairsIndexListSelected.append(pairIndex) | |
|
194 | ||
|
195 | if not pairsIndexListSelected: | |
|
196 | self.dataOut.data_cspc = None | |
|
197 | self.dataOut.pairsList = [] | |
|
198 | return | |
|
199 | ||
|
200 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected] | |
|
201 | self.dataOut.pairsList = [self.dataOut.pairsList[i] for i in pairsIndexListSelected] | |
|
195 | pairs.append(pair) | |
|
196 | pairsIndex.append(pairs.index(pair)) | |
|
197 | ||
|
198 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndex] | |
|
199 | self.dataOut.pairsList = pairs | |
|
200 | self.dataOut.pairsIndexList = pairsIndex | |
|
202 | 201 | |
|
203 | 202 | return |
|
204 | 203 |
@@ -15,6 +15,7 from multiprocessing import Process | |||
|
15 | 15 | |
|
16 | 16 | from schainpy.model.proc.jroproc_base import Operation, ProcessingUnit |
|
17 | 17 | from schainpy.model.data.jrodata import JROData |
|
18 | from schainpy.utils import log | |
|
18 | 19 | |
|
19 | 20 | MAXNUMX = 100 |
|
20 | 21 | MAXNUMY = 100 |
@@ -30,14 +31,13 def roundFloats(obj): | |||
|
30 | 31 | return round(obj, 2) |
|
31 | 32 | |
|
32 | 33 | def decimate(z, MAXNUMY): |
|
33 | # dx = int(len(self.x)/self.__MAXNUMX) + 1 | |
|
34 | ||
|
35 | 34 | dy = int(len(z[0])/MAXNUMY) + 1 |
|
36 | 35 | |
|
37 | 36 | return z[::, ::dy] |
|
38 | 37 | |
|
39 | 38 | class throttle(object): |
|
40 | """Decorator that prevents a function from being called more than once every | |
|
39 | ''' | |
|
40 | Decorator that prevents a function from being called more than once every | |
|
41 | 41 | time period. |
|
42 | 42 | To create a function that cannot be called more than once a minute, but |
|
43 | 43 | will sleep until it can be called: |
@@ -48,7 +48,7 class throttle(object): | |||
|
48 | 48 | for i in range(10): |
|
49 | 49 | foo() |
|
50 | 50 | print "This function has run %s times." % i |
|
51 | """ | |
|
51 | ''' | |
|
52 | 52 | |
|
53 | 53 | def __init__(self, seconds=0, minutes=0, hours=0): |
|
54 | 54 | self.throttle_period = datetime.timedelta( |
@@ -72,9 +72,169 class throttle(object): | |||
|
72 | 72 | |
|
73 | 73 | return wrapper |
|
74 | 74 | |
|
75 | class Data(object): | |
|
76 | ''' | |
|
77 | Object to hold data to be plotted | |
|
78 | ''' | |
|
79 | ||
|
80 | def __init__(self, plottypes, throttle_value): | |
|
81 | self.plottypes = plottypes | |
|
82 | self.throttle = throttle_value | |
|
83 | self.ended = False | |
|
84 | self.__times = [] | |
|
85 | ||
|
86 | def __str__(self): | |
|
87 | dum = ['{}{}'.format(key, self.shape(key)) for key in self.data] | |
|
88 | return 'Data[{}][{}]'.format(';'.join(dum), len(self.__times)) | |
|
89 | ||
|
90 | def __len__(self): | |
|
91 | return len(self.__times) | |
|
92 | ||
|
93 | def __getitem__(self, key): | |
|
94 | if key not in self.data: | |
|
95 | raise KeyError(log.error('Missing key: {}'.format(key))) | |
|
96 | ||
|
97 | if 'spc' in key: | |
|
98 | ret = self.data[key] | |
|
99 | else: | |
|
100 | ret = numpy.array([self.data[key][x] for x in self.times]) | |
|
101 | if ret.ndim > 1: | |
|
102 | ret = numpy.swapaxes(ret, 0, 1) | |
|
103 | return ret | |
|
104 | ||
|
105 | def setup(self): | |
|
106 | ''' | |
|
107 | Configure object | |
|
108 | ''' | |
|
109 | ||
|
110 | self.ended = False | |
|
111 | self.data = {} | |
|
112 | self.__times = [] | |
|
113 | self.__heights = [] | |
|
114 | self.__all_heights = set() | |
|
115 | for plot in self.plottypes: | |
|
116 | self.data[plot] = {} | |
|
117 | ||
|
118 | def shape(self, key): | |
|
119 | ''' | |
|
120 | Get the shape of the one-element data for the given key | |
|
121 | ''' | |
|
122 | ||
|
123 | if len(self.data[key]): | |
|
124 | if 'spc' in key: | |
|
125 | return self.data[key].shape | |
|
126 | return self.data[key][self.__times[0]].shape | |
|
127 | return (0,) | |
|
128 | ||
|
129 | def update(self, dataOut): | |
|
130 | ''' | |
|
131 | Update data object with new dataOut | |
|
132 | ''' | |
|
133 | ||
|
134 | tm = dataOut.utctime | |
|
135 | if tm in self.__times: | |
|
136 | return | |
|
137 | ||
|
138 | self.parameters = getattr(dataOut, 'parameters', []) | |
|
139 | self.pairs = dataOut.pairsList | |
|
140 | self.channels = dataOut.channelList | |
|
141 | self.xrange = (dataOut.getFreqRange(1)/1000. , dataOut.getAcfRange(1) , dataOut.getVelRange(1)) | |
|
142 | self.interval = dataOut.getTimeInterval() | |
|
143 | self.__heights.append(dataOut.heightList) | |
|
144 | self.__all_heights.update(dataOut.heightList) | |
|
145 | self.__times.append(tm) | |
|
146 | ||
|
147 | for plot in self.plottypes: | |
|
148 | if plot == 'spc': | |
|
149 | z = dataOut.data_spc/dataOut.normFactor | |
|
150 | self.data[plot] = 10*numpy.log10(z) | |
|
151 | if plot == 'cspc': | |
|
152 | self.data[plot] = dataOut.data_cspc | |
|
153 | if plot == 'noise': | |
|
154 | self.data[plot][tm] = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor) | |
|
155 | if plot == 'rti': | |
|
156 | self.data[plot][tm] = dataOut.getPower() | |
|
157 | if plot == 'snr_db': | |
|
158 | self.data['snr'][tm] = dataOut.data_SNR | |
|
159 | if plot == 'snr': | |
|
160 | self.data[plot][tm] = 10*numpy.log10(dataOut.data_SNR) | |
|
161 | if plot == 'dop': | |
|
162 | self.data[plot][tm] = 10*numpy.log10(dataOut.data_DOP) | |
|
163 | if plot == 'mean': | |
|
164 | self.data[plot][tm] = dataOut.data_MEAN | |
|
165 | if plot == 'std': | |
|
166 | self.data[plot][tm] = dataOut.data_STD | |
|
167 | if plot == 'coh': | |
|
168 | self.data[plot][tm] = dataOut.getCoherence() | |
|
169 | if plot == 'phase': | |
|
170 | self.data[plot][tm] = dataOut.getCoherence(phase=True) | |
|
171 | if plot == 'output': | |
|
172 | self.data[plot][tm] = dataOut.data_output | |
|
173 | if plot == 'param': | |
|
174 | self.data[plot][tm] = dataOut.data_param | |
|
175 | ||
|
176 | def normalize_heights(self): | |
|
177 | ''' | |
|
178 | Ensure same-dimension of the data for different heighList | |
|
179 | ''' | |
|
180 | ||
|
181 | H = numpy.array(list(self.__all_heights)) | |
|
182 | H.sort() | |
|
183 | for key in self.data: | |
|
184 | shape = self.shape(key)[:-1] + H.shape | |
|
185 | for tm, obj in self.data[key].items(): | |
|
186 | h = self.__heights[self.__times.index(tm)] | |
|
187 | if H.size == h.size: | |
|
188 | continue | |
|
189 | index = numpy.where(numpy.in1d(H, h))[0] | |
|
190 | dummy = numpy.zeros(shape) + numpy.nan | |
|
191 | if len(shape) == 2: | |
|
192 | dummy[:, index] = obj | |
|
193 | else: | |
|
194 | dummy[index] = obj | |
|
195 | self.data[key][tm] = dummy | |
|
196 | ||
|
197 | self.__heights = [H for tm in self.__times] | |
|
198 | ||
|
199 | def jsonify(self, decimate=False): | |
|
200 | ''' | |
|
201 | Convert data to json | |
|
202 | ''' | |
|
203 | ||
|
204 | ret = {} | |
|
205 | tm = self.times[-1] | |
|
206 | ||
|
207 | for key, value in self.data: | |
|
208 | if key in ('spc', 'cspc'): | |
|
209 | ret[key] = roundFloats(self.data[key].to_list()) | |
|
210 | else: | |
|
211 | ret[key] = roundFloats(self.data[key][tm].to_list()) | |
|
212 | ||
|
213 | ret['timestamp'] = tm | |
|
214 | ret['interval'] = self.interval | |
|
215 | ||
|
216 | @property | |
|
217 | def times(self): | |
|
218 | ''' | |
|
219 | Return the list of times of the current data | |
|
220 | ''' | |
|
221 | ||
|
222 | ret = numpy.array(self.__times) | |
|
223 | ret.sort() | |
|
224 | return ret | |
|
225 | ||
|
226 | @property | |
|
227 | def heights(self): | |
|
228 | ''' | |
|
229 | Return the list of heights of the current data | |
|
230 | ''' | |
|
231 | ||
|
232 | return numpy.array(self.__heights[-1]) | |
|
75 | 233 | |
|
76 | 234 | class PublishData(Operation): |
|
77 | """Clase publish.""" | |
|
235 | ''' | |
|
236 | Operation to send data over zmq. | |
|
237 | ''' | |
|
78 | 238 | |
|
79 | 239 | def __init__(self, **kwargs): |
|
80 | 240 | """Inicio.""" |
@@ -86,11 +246,11 class PublishData(Operation): | |||
|
86 | 246 | |
|
87 | 247 | def on_disconnect(self, client, userdata, rc): |
|
88 | 248 | if rc != 0: |
|
89 |
|
|
|
249 | log.warning('Unexpected disconnection.') | |
|
90 | 250 | self.connect() |
|
91 | 251 | |
|
92 | 252 | def connect(self): |
|
93 |
|
|
|
253 | log.warning('trying to connect') | |
|
94 | 254 | try: |
|
95 | 255 | self.client.connect( |
|
96 | 256 | host=self.host, |
@@ -104,7 +264,7 class PublishData(Operation): | |||
|
104 | 264 | # retain=True |
|
105 | 265 | # ) |
|
106 | 266 | except: |
|
107 |
|
|
|
267 | log.error('MQTT Conection error.') | |
|
108 | 268 | self.client = False |
|
109 | 269 | |
|
110 | 270 | def setup(self, port=1883, username=None, password=None, clientId="user", zeromq=1, verbose=True, **kwargs): |
@@ -119,8 +279,7 class PublishData(Operation): | |||
|
119 | 279 | self.zeromq = zeromq |
|
120 | 280 | self.mqtt = kwargs.get('plottype', 0) |
|
121 | 281 | self.client = None |
|
122 | self.verbose = verbose | |
|
123 | self.dataOut.firstdata = True | |
|
282 | self.verbose = verbose | |
|
124 | 283 | setup = [] |
|
125 | 284 | if mqtt is 1: |
|
126 | 285 | self.client = mqtt.Client( |
@@ -175,7 +334,6 class PublishData(Operation): | |||
|
175 | 334 | 'type': self.plottype, |
|
176 | 335 | 'yData': yData |
|
177 | 336 | } |
|
178 | # print payload | |
|
179 | 337 | |
|
180 | 338 | elif self.plottype in ('rti', 'power'): |
|
181 | 339 | data = getattr(self.dataOut, 'data_spc') |
@@ -229,15 +387,16 class PublishData(Operation): | |||
|
229 | 387 | 'timestamp': 'None', |
|
230 | 388 | 'type': None |
|
231 | 389 | } |
|
232 | # print 'Publishing data to {}'.format(self.host) | |
|
390 | ||
|
233 | 391 | self.client.publish(self.topic + self.plottype, json.dumps(payload), qos=0) |
|
234 | 392 | |
|
235 | 393 | if self.zeromq is 1: |
|
236 | 394 | if self.verbose: |
|
237 | print '[Sending] {} - {}'.format(self.dataOut.type, self.dataOut.datatime) | |
|
395 | log.log( | |
|
396 | '{} - {}'.format(self.dataOut.type, self.dataOut.datatime), | |
|
397 | 'Sending' | |
|
398 | ) | |
|
238 | 399 | self.zmq_socket.send_pyobj(self.dataOut) |
|
239 | self.dataOut.firstdata = False | |
|
240 | ||
|
241 | 400 | |
|
242 | 401 | def run(self, dataOut, **kwargs): |
|
243 | 402 | self.dataOut = dataOut |
@@ -252,6 +411,7 class PublishData(Operation): | |||
|
252 | 411 | if self.zeromq is 1: |
|
253 | 412 | self.dataOut.finished = True |
|
254 | 413 | self.zmq_socket.send_pyobj(self.dataOut) |
|
414 | time.sleep(0.1) | |
|
255 | 415 | self.zmq_socket.close() |
|
256 | 416 | if self.client: |
|
257 | 417 | self.client.loop_stop() |
@@ -280,7 +440,7 class ReceiverData(ProcessingUnit): | |||
|
280 | 440 | self.receiver = self.context.socket(zmq.PULL) |
|
281 | 441 | self.receiver.bind(self.address) |
|
282 | 442 | time.sleep(0.5) |
|
283 |
|
|
|
443 | log.success('ReceiverData from {}'.format(self.address)) | |
|
284 | 444 | |
|
285 | 445 | |
|
286 | 446 | def run(self): |
@@ -290,8 +450,9 class ReceiverData(ProcessingUnit): | |||
|
290 | 450 | self.isConfig = True |
|
291 | 451 | |
|
292 | 452 | self.dataOut = self.receiver.recv_pyobj() |
|
293 |
|
|
|
294 |
|
|
|
453 | log.log('{} - {}'.format(self.dataOut.type, | |
|
454 | self.dataOut.datatime.ctime(),), | |
|
455 | 'Receiving') | |
|
295 | 456 | |
|
296 | 457 | |
|
297 | 458 | class PlotterReceiver(ProcessingUnit, Process): |
@@ -305,7 +466,6 class PlotterReceiver(ProcessingUnit, Process): | |||
|
305 | 466 | self.mp = False |
|
306 | 467 | self.isConfig = False |
|
307 | 468 | self.isWebConfig = False |
|
308 | self.plottypes = [] | |
|
309 | 469 | self.connections = 0 |
|
310 | 470 | server = kwargs.get('server', 'zmq.pipe') |
|
311 | 471 | plot_server = kwargs.get('plot_server', 'zmq.web') |
@@ -325,19 +485,13 class PlotterReceiver(ProcessingUnit, Process): | |||
|
325 | 485 | self.realtime = kwargs.get('realtime', False) |
|
326 | 486 | self.throttle_value = kwargs.get('throttle', 5) |
|
327 | 487 | self.sendData = self.initThrottle(self.throttle_value) |
|
488 | self.dates = [] | |
|
328 | 489 | self.setup() |
|
329 | 490 | |
|
330 | 491 | def setup(self): |
|
331 | 492 | |
|
332 | self.data = {} | |
|
333 | self.data['times'] = [] | |
|
334 | for plottype in self.plottypes: | |
|
335 | self.data[plottype] = {} | |
|
336 | self.data['noise'] = {} | |
|
337 | self.data['throttle'] = self.throttle_value | |
|
338 | self.data['ENDED'] = False | |
|
339 | self.isConfig = True | |
|
340 | self.data_web = {} | |
|
493 | self.data = Data(self.plottypes, self.throttle_value) | |
|
494 | self.isConfig = True | |
|
341 | 495 | |
|
342 | 496 | def event_monitor(self, monitor): |
|
343 | 497 | |
@@ -354,15 +508,13 class PlotterReceiver(ProcessingUnit, Process): | |||
|
354 | 508 | self.connections += 1 |
|
355 | 509 | if evt['event'] == 512: |
|
356 | 510 | pass |
|
357 | if self.connections == 0 and self.started is True: | |
|
358 | self.ended = True | |
|
359 | 511 | |
|
360 | 512 | evt.update({'description': events[evt['event']]}) |
|
361 | 513 | |
|
362 | 514 | if evt['event'] == zmq.EVENT_MONITOR_STOPPED: |
|
363 | 515 | break |
|
364 | 516 | monitor.close() |
|
365 |
print( |
|
|
517 | print('event monitor thread done!') | |
|
366 | 518 | |
|
367 | 519 | def initThrottle(self, throttle_value): |
|
368 | 520 | |
@@ -372,65 +524,16 class PlotterReceiver(ProcessingUnit, Process): | |||
|
372 | 524 | |
|
373 | 525 | return sendDataThrottled |
|
374 | 526 | |
|
375 | ||
|
376 | 527 | def send(self, data): |
|
377 | # print '[sending] data=%s size=%s' % (data.keys(), len(data['times'])) | |
|
528 | log.success('Sending {}'.format(data), self.name) | |
|
378 | 529 | self.sender.send_pyobj(data) |
|
379 | 530 | |
|
380 | ||
|
381 | def update(self): | |
|
382 | t = self.dataOut.utctime | |
|
383 | ||
|
384 | if t in self.data['times']: | |
|
385 | return | |
|
386 | ||
|
387 | self.data['times'].append(t) | |
|
388 | self.data['dataOut'] = self.dataOut | |
|
389 | ||
|
390 | for plottype in self.plottypes: | |
|
391 | if plottype == 'spc': | |
|
392 | z = self.dataOut.data_spc/self.dataOut.normFactor | |
|
393 | self.data[plottype] = 10*numpy.log10(z) | |
|
394 | self.data['noise'][t] = 10*numpy.log10(self.dataOut.getNoise()/self.dataOut.normFactor) | |
|
395 | if plottype == 'cspc': | |
|
396 | jcoherence = self.dataOut.data_cspc/numpy.sqrt(self.dataOut.data_spc*self.dataOut.data_spc) | |
|
397 | self.data['cspc_coh'] = numpy.abs(jcoherence) | |
|
398 | self.data['cspc_phase'] = numpy.arctan2(jcoherence.imag, jcoherence.real)*180/numpy.pi | |
|
399 | if plottype == 'rti': | |
|
400 | self.data[plottype][t] = self.dataOut.getPower() | |
|
401 | if plottype == 'snr': | |
|
402 | self.data[plottype][t] = 10*numpy.log10(self.dataOut.data_SNR) | |
|
403 | if plottype == 'dop': | |
|
404 | self.data[plottype][t] = 10*numpy.log10(self.dataOut.data_DOP) | |
|
405 | if plottype == 'mean': | |
|
406 | self.data[plottype][t] = self.dataOut.data_MEAN | |
|
407 | if plottype == 'std': | |
|
408 | self.data[plottype][t] = self.dataOut.data_STD | |
|
409 | if plottype == 'coh': | |
|
410 | self.data[plottype][t] = self.dataOut.getCoherence() | |
|
411 | if plottype == 'phase': | |
|
412 | self.data[plottype][t] = self.dataOut.getCoherence(phase=True) | |
|
413 | if plottype == 'output': | |
|
414 | self.data[plottype][t] = self.dataOut.data_output | |
|
415 | if plottype == 'param': | |
|
416 | self.data[plottype][t] = self.dataOut.data_param | |
|
417 | if self.realtime: | |
|
418 | self.data_web['timestamp'] = t | |
|
419 | if plottype == 'spc': | |
|
420 | self.data_web[plottype] = roundFloats(decimate(self.data[plottype]).tolist()) | |
|
421 | elif plottype == 'cspc': | |
|
422 | self.data_web['cspc_coh'] = roundFloats(decimate(self.data['cspc_coh']).tolist()) | |
|
423 | self.data_web['cspc_phase'] = roundFloats(decimate(self.data['cspc_phase']).tolist()) | |
|
424 | elif plottype == 'noise': | |
|
425 | self.data_web['noise'] = roundFloats(self.data['noise'][t].tolist()) | |
|
426 | else: | |
|
427 | self.data_web[plottype] = roundFloats(decimate(self.data[plottype][t]).tolist()) | |
|
428 | self.data_web['interval'] = self.dataOut.getTimeInterval() | |
|
429 | self.data_web['type'] = plottype | |
|
430 | ||
|
431 | 531 | def run(self): |
|
432 | 532 | |
|
433 | print '[Starting] {} from {}'.format(self.name, self.address) | |
|
533 | log.success( | |
|
534 | 'Starting from {}'.format(self.address), | |
|
535 | self.name | |
|
536 | ) | |
|
434 | 537 | |
|
435 | 538 | self.context = zmq.Context() |
|
436 | 539 | self.receiver = self.context.socket(zmq.PULL) |
@@ -447,39 +550,39 class PlotterReceiver(ProcessingUnit, Process): | |||
|
447 | 550 | else: |
|
448 | 551 | self.sender.bind("ipc:///tmp/zmq.plots") |
|
449 | 552 | |
|
450 |
time.sleep( |
|
|
553 | time.sleep(2) | |
|
451 | 554 | |
|
452 | 555 | t = Thread(target=self.event_monitor, args=(monitor,)) |
|
453 | 556 | t.start() |
|
454 | 557 | |
|
455 | 558 | while True: |
|
456 |
|
|
|
457 | # print '[Receiving] {} - {}'.format(self.dataOut.type, | |
|
458 | # self.dataOut.datatime.ctime()) | |
|
459 | ||
|
460 |
self. |
|
|
559 | dataOut = self.receiver.recv_pyobj() | |
|
560 | dt = datetime.datetime.fromtimestamp(dataOut.utctime).date() | |
|
561 | sended = False | |
|
562 | if dt not in self.dates: | |
|
563 | if self.data: | |
|
564 | self.data.ended = True | |
|
565 | self.send(self.data) | |
|
566 | sended = True | |
|
567 | self.data.setup() | |
|
568 | self.dates.append(dt) | |
|
461 | 569 | |
|
462 |
|
|
|
463 | self.data['STARTED'] = True | |
|
570 | self.data.update(dataOut) | |
|
464 | 571 | |
|
465 |
if |
|
|
466 | self.send(self.data) | |
|
572 | if dataOut.finished is True: | |
|
467 | 573 | self.connections -= 1 |
|
468 |
if self.connections == 0 and self. |
|
|
469 | self.ended = True | |
|
470 | self.data['ENDED'] = True | |
|
574 | if self.connections == 0 and dt in self.dates: | |
|
575 | self.data.ended = True | |
|
471 | 576 | self.send(self.data) |
|
472 | self.setup() | |
|
473 | self.started = False | |
|
577 | self.data.setup() | |
|
474 | 578 | else: |
|
475 | 579 | if self.realtime: |
|
476 | 580 | self.send(self.data) |
|
477 |
self.sender_web.send_string( |
|
|
581 | # self.sender_web.send_string(self.data.jsonify()) | |
|
478 | 582 | else: |
|
479 |
|
|
|
480 | self.started = True | |
|
583 | if not sended: | |
|
584 | self.sendData(self.send, self.data) | |
|
481 | 585 | |
|
482 | self.data['STARTED'] = False | |
|
483 | 586 | return |
|
484 | 587 | |
|
485 | 588 | def sendToWeb(self): |
@@ -496,6 +599,6 class PlotterReceiver(ProcessingUnit, Process): | |||
|
496 | 599 | time.sleep(1) |
|
497 | 600 | for kwargs in self.operationKwargs.values(): |
|
498 | 601 | if 'plot' in kwargs: |
|
499 |
|
|
|
602 | log.success('[Sending] Config data to web for {}'.format(kwargs['code'].upper())) | |
|
500 | 603 | sender_web_config.send_string(json.dumps(kwargs)) |
|
501 |
self.isWebConfig = True |
|
|
604 | self.isWebConfig = True No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now