This diff has been collapsed as it changes many lines, (513 lines changed) Show them Hide them | |||||
@@ -1,1865 +1,2378 | |||||
1 | import os |
|
1 | import os | |
2 | import datetime |
|
2 | import datetime | |
3 | import numpy |
|
3 | import numpy | |
|
4 | from mpl_toolkits.axisartist.grid_finder import FixedLocator, DictFormatter | |||
4 |
|
5 | |||
5 | from schainpy.model.graphics.jroplot_base import Plot, plt |
|
6 | from schainpy.model.graphics.jroplot_base import Plot, plt | |
6 | from schainpy.model.graphics.jroplot_spectra import SpectraPlot, RTIPlot, CoherencePlot, SpectraCutPlot |
|
7 | from schainpy.model.graphics.jroplot_spectra import SpectraPlot, RTIPlot, CoherencePlot, SpectraCutPlot | |
7 | from schainpy.utils import log |
|
8 | from schainpy.utils import log | |
8 | # libreria wradlib |
|
9 | # libreria wradlib | |
9 | import wradlib as wrl |
|
10 | import wradlib as wrl | |
10 |
|
11 | |||
11 | EARTH_RADIUS = 6.3710e3 |
|
12 | EARTH_RADIUS = 6.3710e3 | |
12 |
|
13 | |||
13 |
|
14 | |||
14 | def ll2xy(lat1, lon1, lat2, lon2): |
|
15 | def ll2xy(lat1, lon1, lat2, lon2): | |
15 |
|
16 | |||
16 | p = 0.017453292519943295 |
|
17 | p = 0.017453292519943295 | |
17 | a = 0.5 - numpy.cos((lat2 - lat1) * p)/2 + numpy.cos(lat1 * p) * \ |
|
18 | a = 0.5 - numpy.cos((lat2 - lat1) * p)/2 + numpy.cos(lat1 * p) * \ | |
18 | numpy.cos(lat2 * p) * (1 - numpy.cos((lon2 - lon1) * p)) / 2 |
|
19 | numpy.cos(lat2 * p) * (1 - numpy.cos((lon2 - lon1) * p)) / 2 | |
19 | r = 12742 * numpy.arcsin(numpy.sqrt(a)) |
|
20 | r = 12742 * numpy.arcsin(numpy.sqrt(a)) | |
20 | theta = numpy.arctan2(numpy.sin((lon2-lon1)*p)*numpy.cos(lat2*p), numpy.cos(lat1*p) |
|
21 | theta = numpy.arctan2(numpy.sin((lon2-lon1)*p)*numpy.cos(lat2*p), numpy.cos(lat1*p) | |
21 | * numpy.sin(lat2*p)-numpy.sin(lat1*p)*numpy.cos(lat2*p)*numpy.cos((lon2-lon1)*p)) |
|
22 | * numpy.sin(lat2*p)-numpy.sin(lat1*p)*numpy.cos(lat2*p)*numpy.cos((lon2-lon1)*p)) | |
22 | theta = -theta + numpy.pi/2 |
|
23 | theta = -theta + numpy.pi/2 | |
23 | return r*numpy.cos(theta), r*numpy.sin(theta) |
|
24 | return r*numpy.cos(theta), r*numpy.sin(theta) | |
24 |
|
25 | |||
25 |
|
26 | |||
26 | def km2deg(km): |
|
27 | def km2deg(km): | |
27 | ''' |
|
28 | ''' | |
28 | Convert distance in km to degrees |
|
29 | Convert distance in km to degrees | |
29 | ''' |
|
30 | ''' | |
30 |
|
31 | |||
31 | return numpy.rad2deg(km/EARTH_RADIUS) |
|
32 | return numpy.rad2deg(km/EARTH_RADIUS) | |
32 |
|
33 | |||
33 |
|
34 | |||
34 |
|
35 | |||
35 | class SpectralMomentsPlot(SpectraPlot): |
|
36 | class SpectralMomentsPlot(SpectraPlot): | |
36 | ''' |
|
37 | ''' | |
37 | Plot for Spectral Moments |
|
38 | Plot for Spectral Moments | |
38 | ''' |
|
39 | ''' | |
39 | CODE = 'spc_moments' |
|
40 | CODE = 'spc_moments' | |
40 | # colormap = 'jet' |
|
41 | # colormap = 'jet' | |
41 | # plot_type = 'pcolor' |
|
42 | # plot_type = 'pcolor' | |
42 |
|
43 | |||
43 | class DobleGaussianPlot(SpectraPlot): |
|
44 | class DobleGaussianPlot(SpectraPlot): | |
44 | ''' |
|
45 | ''' | |
45 | Plot for Double Gaussian Plot |
|
46 | Plot for Double Gaussian Plot | |
46 | ''' |
|
47 | ''' | |
47 | CODE = 'gaussian_fit' |
|
48 | CODE = 'gaussian_fit' | |
48 | # colormap = 'jet' |
|
49 | # colormap = 'jet' | |
49 | # plot_type = 'pcolor' |
|
50 | # plot_type = 'pcolor' | |
50 |
|
51 | |||
51 | class DoubleGaussianSpectraCutPlot(SpectraCutPlot): |
|
52 | class DoubleGaussianSpectraCutPlot(SpectraCutPlot): | |
52 | ''' |
|
53 | ''' | |
53 | Plot SpectraCut with Double Gaussian Fit |
|
54 | Plot SpectraCut with Double Gaussian Fit | |
54 | ''' |
|
55 | ''' | |
55 | CODE = 'cut_gaussian_fit' |
|
56 | CODE = 'cut_gaussian_fit' | |
56 |
|
57 | |||
57 | class SnrPlot(RTIPlot): |
|
58 | class SnrPlot(RTIPlot): | |
58 | ''' |
|
59 | ''' | |
59 | Plot for SNR Data |
|
60 | Plot for SNR Data | |
60 | ''' |
|
61 | ''' | |
61 |
|
62 | |||
62 | CODE = 'snr' |
|
63 | CODE = 'snr' | |
63 | colormap = 'jet' |
|
64 | colormap = 'jet' | |
64 |
|
65 | |||
65 | def update(self, dataOut): |
|
66 | def update(self, dataOut): | |
66 |
|
67 | |||
67 | data = { |
|
68 | data = { | |
68 | 'snr': 10*numpy.log10(dataOut.data_snr) |
|
69 | 'snr': 10*numpy.log10(dataOut.data_snr) | |
69 | } |
|
70 | } | |
70 |
|
71 | |||
71 | return data, {} |
|
72 | return data, {} | |
72 |
|
73 | |||
73 | class DopplerPlot(RTIPlot): |
|
74 | class DopplerPlot(RTIPlot): | |
74 | ''' |
|
75 | ''' | |
75 | Plot for DOPPLER Data (1st moment) |
|
76 | Plot for DOPPLER Data (1st moment) | |
76 | ''' |
|
77 | ''' | |
77 |
|
78 | |||
78 | CODE = 'dop' |
|
79 | CODE = 'dop' | |
79 | colormap = 'jet' |
|
80 | colormap = 'jet' | |
80 |
|
81 | |||
81 | def update(self, dataOut): |
|
82 | def update(self, dataOut): | |
82 |
|
83 | |||
83 | data = { |
|
84 | data = { | |
84 | 'dop': 10*numpy.log10(dataOut.data_dop) |
|
85 | 'dop': 10*numpy.log10(dataOut.data_dop) | |
85 | } |
|
86 | } | |
86 |
|
87 | |||
87 | return data, {} |
|
88 | return data, {} | |
88 |
|
89 | |||
89 | class PowerPlot(RTIPlot): |
|
90 | class PowerPlot(RTIPlot): | |
90 | ''' |
|
91 | ''' | |
91 | Plot for Power Data (0 moment) |
|
92 | Plot for Power Data (0 moment) | |
92 | ''' |
|
93 | ''' | |
93 |
|
94 | |||
94 | CODE = 'pow' |
|
95 | CODE = 'pow' | |
95 | colormap = 'jet' |
|
96 | colormap = 'jet' | |
96 |
|
97 | |||
97 | def update(self, dataOut): |
|
98 | def update(self, dataOut): | |
98 | data = { |
|
99 | data = { | |
99 | 'pow': 10*numpy.log10(dataOut.data_pow/dataOut.normFactor) |
|
100 | 'pow': 10*numpy.log10(dataOut.data_pow/dataOut.normFactor) | |
100 | } |
|
101 | } | |
101 | return data, {} |
|
102 | return data, {} | |
102 |
|
103 | |||
103 | class SpectralWidthPlot(RTIPlot): |
|
104 | class SpectralWidthPlot(RTIPlot): | |
104 | ''' |
|
105 | ''' | |
105 | Plot for Spectral Width Data (2nd moment) |
|
106 | Plot for Spectral Width Data (2nd moment) | |
106 | ''' |
|
107 | ''' | |
107 |
|
108 | |||
108 | CODE = 'width' |
|
109 | CODE = 'width' | |
109 | colormap = 'jet' |
|
110 | colormap = 'jet' | |
110 |
|
111 | |||
111 | def update(self, dataOut): |
|
112 | def update(self, dataOut): | |
112 |
|
113 | |||
113 | data = { |
|
114 | data = { | |
114 | 'width': dataOut.data_width |
|
115 | 'width': dataOut.data_width | |
115 | } |
|
116 | } | |
116 |
|
117 | |||
117 | return data, {} |
|
118 | return data, {} | |
118 |
|
119 | |||
119 | class SkyMapPlot(Plot): |
|
120 | class SkyMapPlot(Plot): | |
120 | ''' |
|
121 | ''' | |
121 | Plot for meteors detection data |
|
122 | Plot for meteors detection data | |
122 | ''' |
|
123 | ''' | |
123 |
|
124 | |||
124 | CODE = 'param' |
|
125 | CODE = 'param' | |
125 |
|
126 | |||
126 | def setup(self): |
|
127 | def setup(self): | |
127 |
|
128 | |||
128 | self.ncols = 1 |
|
129 | self.ncols = 1 | |
129 | self.nrows = 1 |
|
130 | self.nrows = 1 | |
130 | self.width = 7.2 |
|
131 | self.width = 7.2 | |
131 | self.height = 7.2 |
|
132 | self.height = 7.2 | |
132 | self.nplots = 1 |
|
133 | self.nplots = 1 | |
133 | self.xlabel = 'Zonal Zenith Angle (deg)' |
|
134 | self.xlabel = 'Zonal Zenith Angle (deg)' | |
134 | self.ylabel = 'Meridional Zenith Angle (deg)' |
|
135 | self.ylabel = 'Meridional Zenith Angle (deg)' | |
135 | self.polar = True |
|
136 | self.polar = True | |
136 | self.ymin = -180 |
|
137 | self.ymin = -180 | |
137 | self.ymax = 180 |
|
138 | self.ymax = 180 | |
138 | self.colorbar = False |
|
139 | self.colorbar = False | |
139 |
|
140 | |||
140 | def plot(self): |
|
141 | def plot(self): | |
141 |
|
142 | |||
142 | arrayParameters = numpy.concatenate(self.data['param']) |
|
143 | arrayParameters = numpy.concatenate(self.data['param']) | |
143 | error = arrayParameters[:, -1] |
|
144 | error = arrayParameters[:, -1] | |
144 | indValid = numpy.where(error == 0)[0] |
|
145 | indValid = numpy.where(error == 0)[0] | |
145 | finalMeteor = arrayParameters[indValid, :] |
|
146 | finalMeteor = arrayParameters[indValid, :] | |
146 | finalAzimuth = finalMeteor[:, 3] |
|
147 | finalAzimuth = finalMeteor[:, 3] | |
147 | finalZenith = finalMeteor[:, 4] |
|
148 | finalZenith = finalMeteor[:, 4] | |
148 |
|
149 | |||
149 | x = finalAzimuth * numpy.pi / 180 |
|
150 | x = finalAzimuth * numpy.pi / 180 | |
150 | y = finalZenith |
|
151 | y = finalZenith | |
151 |
|
152 | |||
152 | ax = self.axes[0] |
|
153 | ax = self.axes[0] | |
153 |
|
154 | |||
154 | if ax.firsttime: |
|
155 | if ax.firsttime: | |
155 | ax.plot = ax.plot(x, y, 'bo', markersize=5)[0] |
|
156 | ax.plot = ax.plot(x, y, 'bo', markersize=5)[0] | |
156 | else: |
|
157 | else: | |
157 | ax.plot.set_data(x, y) |
|
158 | ax.plot.set_data(x, y) | |
158 |
|
159 | |||
159 | dt1 = self.getDateTime(self.data.min_time).strftime('%y/%m/%d %H:%M:%S') |
|
160 | dt1 = self.getDateTime(self.data.min_time).strftime('%y/%m/%d %H:%M:%S') | |
160 | dt2 = self.getDateTime(self.data.max_time).strftime('%y/%m/%d %H:%M:%S') |
|
161 | dt2 = self.getDateTime(self.data.max_time).strftime('%y/%m/%d %H:%M:%S') | |
161 | title = 'Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n' % (dt1, |
|
162 | title = 'Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n' % (dt1, | |
162 | dt2, |
|
163 | dt2, | |
163 | len(x)) |
|
164 | len(x)) | |
164 | self.titles[0] = title |
|
165 | self.titles[0] = title | |
165 |
|
166 | |||
166 |
|
167 | |||
167 | class GenericRTIPlot(Plot): |
|
168 | class GenericRTIPlot(Plot): | |
168 | ''' |
|
169 | ''' | |
169 | Plot for data_xxxx object |
|
170 | Plot for data_xxxx object | |
170 | ''' |
|
171 | ''' | |
171 |
|
172 | |||
172 | CODE = 'param' |
|
173 | CODE = 'param' | |
173 | colormap = 'viridis' |
|
174 | colormap = 'viridis' | |
174 | plot_type = 'pcolorbuffer' |
|
175 | plot_type = 'pcolorbuffer' | |
175 |
|
176 | |||
176 | def setup(self): |
|
177 | def setup(self): | |
177 | self.xaxis = 'time' |
|
178 | self.xaxis = 'time' | |
178 | self.ncols = 1 |
|
179 | self.ncols = 1 | |
179 | self.nrows = self.data.shape('param')[0] |
|
180 | self.nrows = self.data.shape('param')[0] | |
180 | self.nplots = self.nrows |
|
181 | self.nplots = self.nrows | |
181 | self.plots_adjust.update({'hspace':0.8, 'left': 0.1, 'bottom': 0.08, 'right':0.95, 'top': 0.95}) |
|
182 | self.plots_adjust.update({'hspace':0.8, 'left': 0.1, 'bottom': 0.08, 'right':0.95, 'top': 0.95}) | |
182 |
|
183 | |||
183 | if not self.xlabel: |
|
184 | if not self.xlabel: | |
184 | self.xlabel = 'Time' |
|
185 | self.xlabel = 'Time' | |
185 |
|
186 | |||
186 | self.ylabel = 'Range [km]' |
|
187 | self.ylabel = 'Range [km]' | |
187 | if not self.titles: |
|
188 | if not self.titles: | |
188 | self.titles = ['Param {}'.format(x) for x in range(self.nrows)] |
|
189 | self.titles = ['Param {}'.format(x) for x in range(self.nrows)] | |
189 |
|
190 | |||
190 | def update(self, dataOut): |
|
191 | def update(self, dataOut): | |
191 |
|
192 | |||
192 | data = { |
|
193 | data = { | |
193 | 'param' : numpy.concatenate([getattr(dataOut, attr) for attr in self.attr_data], axis=0) |
|
194 | 'param' : numpy.concatenate([getattr(dataOut, attr) for attr in self.attr_data], axis=0) | |
194 | } |
|
195 | } | |
195 |
|
196 | |||
196 | meta = {} |
|
197 | meta = {} | |
197 |
|
198 | |||
198 | return data, meta |
|
199 | return data, meta | |
199 |
|
200 | |||
200 | def plot(self): |
|
201 | def plot(self): | |
201 | # self.data.normalize_heights() |
|
202 | # self.data.normalize_heights() | |
202 | self.x = self.data.times |
|
203 | self.x = self.data.times | |
203 | self.y = self.data.yrange |
|
204 | self.y = self.data.yrange | |
204 | self.z = self.data['param'] |
|
205 | self.z = self.data['param'] | |
205 | self.z = 10*numpy.log10(self.z) |
|
206 | self.z = 10*numpy.log10(self.z) | |
206 | self.z = numpy.ma.masked_invalid(self.z) |
|
207 | self.z = numpy.ma.masked_invalid(self.z) | |
207 |
|
208 | |||
208 | if self.decimation is None: |
|
209 | if self.decimation is None: | |
209 | x, y, z = self.fill_gaps(self.x, self.y, self.z) |
|
210 | x, y, z = self.fill_gaps(self.x, self.y, self.z) | |
210 | else: |
|
211 | else: | |
211 | x, y, z = self.fill_gaps(*self.decimate()) |
|
212 | x, y, z = self.fill_gaps(*self.decimate()) | |
212 |
|
213 | |||
213 | for n, ax in enumerate(self.axes): |
|
214 | for n, ax in enumerate(self.axes): | |
214 |
|
215 | |||
215 | self.zmax = self.zmax if self.zmax is not None else numpy.max( |
|
216 | self.zmax = self.zmax if self.zmax is not None else numpy.max( | |
216 | self.z[n]) |
|
217 | self.z[n]) | |
217 | self.zmin = self.zmin if self.zmin is not None else numpy.min( |
|
218 | self.zmin = self.zmin if self.zmin is not None else numpy.min( | |
218 | self.z[n]) |
|
219 | self.z[n]) | |
219 |
|
220 | |||
220 | if ax.firsttime: |
|
221 | if ax.firsttime: | |
221 | if self.zlimits is not None: |
|
222 | if self.zlimits is not None: | |
222 | self.zmin, self.zmax = self.zlimits[n] |
|
223 | self.zmin, self.zmax = self.zlimits[n] | |
223 |
|
224 | |||
224 | ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n], |
|
225 | ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n], | |
225 | vmin=self.zmin, |
|
226 | vmin=self.zmin, | |
226 | vmax=self.zmax, |
|
227 | vmax=self.zmax, | |
227 | cmap=self.cmaps[n] |
|
228 | cmap=self.cmaps[n] | |
228 | ) |
|
229 | ) | |
229 | else: |
|
230 | else: | |
230 | if self.zlimits is not None: |
|
231 | if self.zlimits is not None: | |
231 | self.zmin, self.zmax = self.zlimits[n] |
|
232 | self.zmin, self.zmax = self.zlimits[n] | |
232 | ax.collections.remove(ax.collections[0]) |
|
233 | ax.collections.remove(ax.collections[0]) | |
233 | ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n], |
|
234 | ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n], | |
234 | vmin=self.zmin, |
|
235 | vmin=self.zmin, | |
235 | vmax=self.zmax, |
|
236 | vmax=self.zmax, | |
236 | cmap=self.cmaps[n] |
|
237 | cmap=self.cmaps[n] | |
237 | ) |
|
238 | ) | |
238 |
|
239 | |||
239 |
|
240 | |||
240 | class PolarMapPlot(Plot): |
|
241 | class PolarMapPlot(Plot): | |
241 | ''' |
|
242 | ''' | |
242 | Plot for weather radar |
|
243 | Plot for weather radar | |
243 | ''' |
|
244 | ''' | |
244 |
|
245 | |||
245 | CODE = 'param' |
|
246 | CODE = 'param' | |
246 | colormap = 'seismic' |
|
247 | colormap = 'seismic' | |
247 |
|
248 | |||
248 | def setup(self): |
|
249 | def setup(self): | |
249 | self.ncols = 1 |
|
250 | self.ncols = 1 | |
250 | self.nrows = 1 |
|
251 | self.nrows = 1 | |
251 | self.width = 9 |
|
252 | self.width = 9 | |
252 | self.height = 8 |
|
253 | self.height = 8 | |
253 | self.mode = self.data.meta['mode'] |
|
254 | self.mode = self.data.meta['mode'] | |
254 | if self.channels is not None: |
|
255 | if self.channels is not None: | |
255 | self.nplots = len(self.channels) |
|
256 | self.nplots = len(self.channels) | |
256 | self.nrows = len(self.channels) |
|
257 | self.nrows = len(self.channels) | |
257 | else: |
|
258 | else: | |
258 | self.nplots = self.data.shape(self.CODE)[0] |
|
259 | self.nplots = self.data.shape(self.CODE)[0] | |
259 | self.nrows = self.nplots |
|
260 | self.nrows = self.nplots | |
260 | self.channels = list(range(self.nplots)) |
|
261 | self.channels = list(range(self.nplots)) | |
261 | if self.mode == 'E': |
|
262 | if self.mode == 'E': | |
262 | self.xlabel = 'Longitude' |
|
263 | self.xlabel = 'Longitude' | |
263 | self.ylabel = 'Latitude' |
|
264 | self.ylabel = 'Latitude' | |
264 | else: |
|
265 | else: | |
265 | self.xlabel = 'Range (km)' |
|
266 | self.xlabel = 'Range (km)' | |
266 | self.ylabel = 'Height (km)' |
|
267 | self.ylabel = 'Height (km)' | |
267 | self.bgcolor = 'white' |
|
268 | self.bgcolor = 'white' | |
268 | self.cb_labels = self.data.meta['units'] |
|
269 | self.cb_labels = self.data.meta['units'] | |
269 | self.lat = self.data.meta['latitude'] |
|
270 | self.lat = self.data.meta['latitude'] | |
270 | self.lon = self.data.meta['longitude'] |
|
271 | self.lon = self.data.meta['longitude'] | |
271 | self.xmin, self.xmax = float( |
|
272 | self.xmin, self.xmax = float( | |
272 | km2deg(self.xmin) + self.lon), float(km2deg(self.xmax) + self.lon) |
|
273 | km2deg(self.xmin) + self.lon), float(km2deg(self.xmax) + self.lon) | |
273 | self.ymin, self.ymax = float( |
|
274 | self.ymin, self.ymax = float( | |
274 | km2deg(self.ymin) + self.lat), float(km2deg(self.ymax) + self.lat) |
|
275 | km2deg(self.ymin) + self.lat), float(km2deg(self.ymax) + self.lat) | |
275 | # self.polar = True |
|
276 | # self.polar = True | |
276 |
|
277 | |||
277 | def plot(self): |
|
278 | def plot(self): | |
278 |
|
279 | |||
279 | for n, ax in enumerate(self.axes): |
|
280 | for n, ax in enumerate(self.axes): | |
280 | data = self.data['param'][self.channels[n]] |
|
281 | data = self.data['param'][self.channels[n]] | |
281 |
|
282 | |||
282 | zeniths = numpy.linspace( |
|
283 | zeniths = numpy.linspace( | |
283 | 0, self.data.meta['max_range'], data.shape[1]) |
|
284 | 0, self.data.meta['max_range'], data.shape[1]) | |
284 | if self.mode == 'E': |
|
285 | if self.mode == 'E': | |
285 | azimuths = -numpy.radians(self.data.yrange)+numpy.pi/2 |
|
286 | azimuths = -numpy.radians(self.data.yrange)+numpy.pi/2 | |
286 | r, theta = numpy.meshgrid(zeniths, azimuths) |
|
287 | r, theta = numpy.meshgrid(zeniths, azimuths) | |
287 | x, y = r*numpy.cos(theta)*numpy.cos(numpy.radians(self.data.meta['elevation'])), r*numpy.sin( |
|
288 | x, y = r*numpy.cos(theta)*numpy.cos(numpy.radians(self.data.meta['elevation'])), r*numpy.sin( | |
288 | theta)*numpy.cos(numpy.radians(self.data.meta['elevation'])) |
|
289 | theta)*numpy.cos(numpy.radians(self.data.meta['elevation'])) | |
289 | x = km2deg(x) + self.lon |
|
290 | x = km2deg(x) + self.lon | |
290 | y = km2deg(y) + self.lat |
|
291 | y = km2deg(y) + self.lat | |
291 | else: |
|
292 | else: | |
292 | azimuths = numpy.radians(self.data.yrange) |
|
293 | azimuths = numpy.radians(self.data.yrange) | |
293 | r, theta = numpy.meshgrid(zeniths, azimuths) |
|
294 | r, theta = numpy.meshgrid(zeniths, azimuths) | |
294 | x, y = r*numpy.cos(theta), r*numpy.sin(theta) |
|
295 | x, y = r*numpy.cos(theta), r*numpy.sin(theta) | |
295 | self.y = zeniths |
|
296 | self.y = zeniths | |
296 |
|
297 | |||
297 | if ax.firsttime: |
|
298 | if ax.firsttime: | |
298 | if self.zlimits is not None: |
|
299 | if self.zlimits is not None: | |
299 | self.zmin, self.zmax = self.zlimits[n] |
|
300 | self.zmin, self.zmax = self.zlimits[n] | |
300 | ax.plt = ax.pcolormesh( # r, theta, numpy.ma.array(data, mask=numpy.isnan(data)), |
|
301 | ax.plt = ax.pcolormesh( # r, theta, numpy.ma.array(data, mask=numpy.isnan(data)), | |
301 | x, y, numpy.ma.array(data, mask=numpy.isnan(data)), |
|
302 | x, y, numpy.ma.array(data, mask=numpy.isnan(data)), | |
302 | vmin=self.zmin, |
|
303 | vmin=self.zmin, | |
303 | vmax=self.zmax, |
|
304 | vmax=self.zmax, | |
304 | cmap=self.cmaps[n]) |
|
305 | cmap=self.cmaps[n]) | |
305 | else: |
|
306 | else: | |
306 | if self.zlimits is not None: |
|
307 | if self.zlimits is not None: | |
307 | self.zmin, self.zmax = self.zlimits[n] |
|
308 | self.zmin, self.zmax = self.zlimits[n] | |
308 | ax.collections.remove(ax.collections[0]) |
|
309 | ax.collections.remove(ax.collections[0]) | |
309 | ax.plt = ax.pcolormesh( # r, theta, numpy.ma.array(data, mask=numpy.isnan(data)), |
|
310 | ax.plt = ax.pcolormesh( # r, theta, numpy.ma.array(data, mask=numpy.isnan(data)), | |
310 | x, y, numpy.ma.array(data, mask=numpy.isnan(data)), |
|
311 | x, y, numpy.ma.array(data, mask=numpy.isnan(data)), | |
311 | vmin=self.zmin, |
|
312 | vmin=self.zmin, | |
312 | vmax=self.zmax, |
|
313 | vmax=self.zmax, | |
313 | cmap=self.cmaps[n]) |
|
314 | cmap=self.cmaps[n]) | |
314 |
|
315 | |||
315 | if self.mode == 'A': |
|
316 | if self.mode == 'A': | |
316 | continue |
|
317 | continue | |
317 |
|
318 | |||
318 | # plot district names |
|
319 | # plot district names | |
319 | f = open('/data/workspace/schain_scripts/distrito.csv') |
|
320 | f = open('/data/workspace/schain_scripts/distrito.csv') | |
320 | for line in f: |
|
321 | for line in f: | |
321 | label, lon, lat = [s.strip() for s in line.split(',') if s] |
|
322 | label, lon, lat = [s.strip() for s in line.split(',') if s] | |
322 | lat = float(lat) |
|
323 | lat = float(lat) | |
323 | lon = float(lon) |
|
324 | lon = float(lon) | |
324 | # ax.plot(lon, lat, '.b', ms=2) |
|
325 | # ax.plot(lon, lat, '.b', ms=2) | |
325 | ax.text(lon, lat, label.decode('utf8'), ha='center', |
|
326 | ax.text(lon, lat, label.decode('utf8'), ha='center', | |
326 | va='bottom', size='8', color='black') |
|
327 | va='bottom', size='8', color='black') | |
327 |
|
328 | |||
328 | # plot limites |
|
329 | # plot limites | |
329 | limites = [] |
|
330 | limites = [] | |
330 | tmp = [] |
|
331 | tmp = [] | |
331 | for line in open('/data/workspace/schain_scripts/lima.csv'): |
|
332 | for line in open('/data/workspace/schain_scripts/lima.csv'): | |
332 | if '#' in line: |
|
333 | if '#' in line: | |
333 | if tmp: |
|
334 | if tmp: | |
334 | limites.append(tmp) |
|
335 | limites.append(tmp) | |
335 | tmp = [] |
|
336 | tmp = [] | |
336 | continue |
|
337 | continue | |
337 | values = line.strip().split(',') |
|
338 | values = line.strip().split(',') | |
338 | tmp.append((float(values[0]), float(values[1]))) |
|
339 | tmp.append((float(values[0]), float(values[1]))) | |
339 | for points in limites: |
|
340 | for points in limites: | |
340 | ax.add_patch( |
|
341 | ax.add_patch( | |
341 | Polygon(points, ec='k', fc='none', ls='--', lw=0.5)) |
|
342 | Polygon(points, ec='k', fc='none', ls='--', lw=0.5)) | |
342 |
|
343 | |||
343 | # plot Cuencas |
|
344 | # plot Cuencas | |
344 | for cuenca in ('rimac', 'lurin', 'mala', 'chillon', 'chilca', 'chancay-huaral'): |
|
345 | for cuenca in ('rimac', 'lurin', 'mala', 'chillon', 'chilca', 'chancay-huaral'): | |
345 | f = open('/data/workspace/schain_scripts/{}.csv'.format(cuenca)) |
|
346 | f = open('/data/workspace/schain_scripts/{}.csv'.format(cuenca)) | |
346 | values = [line.strip().split(',') for line in f] |
|
347 | values = [line.strip().split(',') for line in f] | |
347 | points = [(float(s[0]), float(s[1])) for s in values] |
|
348 | points = [(float(s[0]), float(s[1])) for s in values] | |
348 | ax.add_patch(Polygon(points, ec='b', fc='none')) |
|
349 | ax.add_patch(Polygon(points, ec='b', fc='none')) | |
349 |
|
350 | |||
350 | # plot grid |
|
351 | # plot grid | |
351 | for r in (15, 30, 45, 60): |
|
352 | for r in (15, 30, 45, 60): | |
352 | ax.add_artist(plt.Circle((self.lon, self.lat), |
|
353 | ax.add_artist(plt.Circle((self.lon, self.lat), | |
353 | km2deg(r), color='0.6', fill=False, lw=0.2)) |
|
354 | km2deg(r), color='0.6', fill=False, lw=0.2)) | |
354 | ax.text( |
|
355 | ax.text( | |
355 | self.lon + (km2deg(r))*numpy.cos(60*numpy.pi/180), |
|
356 | self.lon + (km2deg(r))*numpy.cos(60*numpy.pi/180), | |
356 | self.lat + (km2deg(r))*numpy.sin(60*numpy.pi/180), |
|
357 | self.lat + (km2deg(r))*numpy.sin(60*numpy.pi/180), | |
357 | '{}km'.format(r), |
|
358 | '{}km'.format(r), | |
358 | ha='center', va='bottom', size='8', color='0.6', weight='heavy') |
|
359 | ha='center', va='bottom', size='8', color='0.6', weight='heavy') | |
359 |
|
360 | |||
360 | if self.mode == 'E': |
|
361 | if self.mode == 'E': | |
361 | title = 'El={}$^\circ$'.format(self.data.meta['elevation']) |
|
362 | title = 'El={}$^\circ$'.format(self.data.meta['elevation']) | |
362 | label = 'E{:02d}'.format(int(self.data.meta['elevation'])) |
|
363 | label = 'E{:02d}'.format(int(self.data.meta['elevation'])) | |
363 | else: |
|
364 | else: | |
364 | title = 'Az={}$^\circ$'.format(self.data.meta['azimuth']) |
|
365 | title = 'Az={}$^\circ$'.format(self.data.meta['azimuth']) | |
365 | label = 'A{:02d}'.format(int(self.data.meta['azimuth'])) |
|
366 | label = 'A{:02d}'.format(int(self.data.meta['azimuth'])) | |
366 |
|
367 | |||
367 | self.save_labels = ['{}-{}'.format(lbl, label) for lbl in self.labels] |
|
368 | self.save_labels = ['{}-{}'.format(lbl, label) for lbl in self.labels] | |
368 | self.titles = ['{} {}'.format( |
|
369 | self.titles = ['{} {}'.format( | |
369 | self.data.parameters[x], title) for x in self.channels] |
|
370 | self.data.parameters[x], title) for x in self.channels] | |
370 |
|
371 | |||
371 | class WeatherPlot(Plot): |
|
372 | class WeatherPlot(Plot): | |
372 | CODE = 'weather' |
|
373 | CODE = 'weather' | |
373 | plot_name = 'weather' |
|
374 | plot_name = 'weather' | |
374 | plot_type = 'ppistyle' |
|
375 | plot_type = 'ppistyle' | |
375 | buffering = False |
|
376 | buffering = False | |
376 |
|
377 | |||
377 | def setup(self): |
|
378 | def setup(self): | |
378 | self.ncols = 1 |
|
379 | self.ncols = 1 | |
379 | self.nrows = 1 |
|
380 | self.nrows = 1 | |
380 | self.width =8 |
|
381 | self.width =8 | |
381 | self.height =8 |
|
382 | self.height =8 | |
382 | self.nplots= 1 |
|
383 | self.nplots= 1 | |
383 | self.ylabel= 'Range [Km]' |
|
384 | self.ylabel= 'Range [Km]' | |
384 | self.titles= ['Weather'] |
|
385 | self.titles= ['Weather'] | |
385 | self.colorbar=False |
|
386 | self.colorbar=False | |
386 | self.ini =0 |
|
387 | self.ini =0 | |
387 | self.len_azi =0 |
|
388 | self.len_azi =0 | |
388 | self.buffer_ini = None |
|
389 | self.buffer_ini = None | |
389 | self.buffer_azi = None |
|
390 | self.buffer_azi = None | |
390 | self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08}) |
|
391 | self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08}) | |
391 | self.flag =0 |
|
392 | self.flag =0 | |
392 | self.indicador= 0 |
|
393 | self.indicador= 0 | |
393 | self.last_data_azi = None |
|
394 | self.last_data_azi = None | |
394 | self.val_mean = None |
|
395 | self.val_mean = None | |
395 |
|
396 | |||
396 | def update(self, dataOut): |
|
397 | def update(self, dataOut): | |
397 |
|
398 | |||
398 | data = {} |
|
399 | data = {} | |
399 | meta = {} |
|
400 | meta = {} | |
400 | if hasattr(dataOut, 'dataPP_POWER'): |
|
401 | if hasattr(dataOut, 'dataPP_POWER'): | |
401 | factor = 1 |
|
402 | factor = 1 | |
402 | if hasattr(dataOut, 'nFFTPoints'): |
|
403 | if hasattr(dataOut, 'nFFTPoints'): | |
403 | factor = dataOut.normFactor |
|
404 | factor = dataOut.normFactor | |
404 | #print("DIME EL SHAPE PORFAVOR",dataOut.data_360.shape) |
|
405 | #print("DIME EL SHAPE PORFAVOR",dataOut.data_360.shape) | |
405 | data['weather'] = 10*numpy.log10(dataOut.data_360[1]/(factor)) |
|
406 | data['weather'] = 10*numpy.log10(dataOut.data_360[1]/(factor)) | |
406 | data['azi'] = dataOut.data_azi |
|
407 | data['azi'] = dataOut.data_azi | |
407 | data['ele'] = dataOut.data_ele |
|
408 | data['ele'] = dataOut.data_ele | |
408 | return data, meta |
|
409 | return data, meta | |
409 |
|
410 | |||
410 | def get2List(self,angulos): |
|
411 | def get2List(self,angulos): | |
411 | list1=[] |
|
412 | list1=[] | |
412 | list2=[] |
|
413 | list2=[] | |
413 | for i in reversed(range(len(angulos))): |
|
414 | for i in reversed(range(len(angulos))): | |
414 | diff_ = angulos[i]-angulos[i-1] |
|
415 | diff_ = angulos[i]-angulos[i-1] | |
415 | if diff_ >1.5: |
|
416 | if diff_ >1.5: | |
416 | list1.append(i-1) |
|
417 | list1.append(i-1) | |
417 | list2.append(diff_) |
|
418 | list2.append(diff_) | |
418 | return list(reversed(list1)),list(reversed(list2)) |
|
419 | return list(reversed(list1)),list(reversed(list2)) | |
419 |
|
420 | |||
420 | def fixData360(self,list_,ang_): |
|
421 | def fixData360(self,list_,ang_): | |
421 | if list_[0]==-1: |
|
422 | if list_[0]==-1: | |
422 | vec = numpy.where(ang_<ang_[0]) |
|
423 | vec = numpy.where(ang_<ang_[0]) | |
423 | ang_[vec] = ang_[vec]+360 |
|
424 | ang_[vec] = ang_[vec]+360 | |
424 | return ang_ |
|
425 | return ang_ | |
425 | return ang_ |
|
426 | return ang_ | |
426 |
|
427 | |||
427 | def fixData360HL(self,angulos): |
|
428 | def fixData360HL(self,angulos): | |
428 | vec = numpy.where(angulos>=360) |
|
429 | vec = numpy.where(angulos>=360) | |
429 | angulos[vec]=angulos[vec]-360 |
|
430 | angulos[vec]=angulos[vec]-360 | |
430 | return angulos |
|
431 | return angulos | |
431 |
|
432 | |||
432 | def search_pos(self,pos,list_): |
|
433 | def search_pos(self,pos,list_): | |
433 | for i in range(len(list_)): |
|
434 | for i in range(len(list_)): | |
434 | if pos == list_[i]: |
|
435 | if pos == list_[i]: | |
435 | return True,i |
|
436 | return True,i | |
436 | i=None |
|
437 | i=None | |
437 | return False,i |
|
438 | return False,i | |
438 |
|
439 | |||
439 | def fixDataComp(self,ang_,list1_,list2_): |
|
440 | def fixDataComp(self,ang_,list1_,list2_): | |
440 | size = len(ang_) |
|
441 | size = len(ang_) | |
441 | size2 = 0 |
|
442 | size2 = 0 | |
442 | for i in range(len(list2_)): |
|
443 | for i in range(len(list2_)): | |
443 | size2=size2+round(list2_[i])-1 |
|
444 | size2=size2+round(list2_[i])-1 | |
444 | new_size= size+size2 |
|
445 | new_size= size+size2 | |
445 | ang_new = numpy.zeros(new_size) |
|
446 | ang_new = numpy.zeros(new_size) | |
446 | ang_new2 = numpy.zeros(new_size) |
|
447 | ang_new2 = numpy.zeros(new_size) | |
447 |
|
448 | |||
448 | tmp = 0 |
|
449 | tmp = 0 | |
449 | c = 0 |
|
450 | c = 0 | |
450 | for i in range(len(ang_)): |
|
451 | for i in range(len(ang_)): | |
451 | ang_new[tmp +c] = ang_[i] |
|
452 | ang_new[tmp +c] = ang_[i] | |
452 | ang_new2[tmp+c] = ang_[i] |
|
453 | ang_new2[tmp+c] = ang_[i] | |
453 | condition , value = self.search_pos(i,list1_) |
|
454 | condition , value = self.search_pos(i,list1_) | |
454 | if condition: |
|
455 | if condition: | |
455 | pos = tmp + c + 1 |
|
456 | pos = tmp + c + 1 | |
456 | for k in range(round(list2_[value])-1): |
|
457 | for k in range(round(list2_[value])-1): | |
457 | ang_new[pos+k] = ang_new[pos+k-1]+1 |
|
458 | ang_new[pos+k] = ang_new[pos+k-1]+1 | |
458 | ang_new2[pos+k] = numpy.nan |
|
459 | ang_new2[pos+k] = numpy.nan | |
459 | tmp = pos +k |
|
460 | tmp = pos +k | |
460 | c = 0 |
|
461 | c = 0 | |
461 | c=c+1 |
|
462 | c=c+1 | |
462 | return ang_new,ang_new2 |
|
463 | return ang_new,ang_new2 | |
463 |
|
464 | |||
464 | def globalCheckPED(self,angulos): |
|
465 | def globalCheckPED(self,angulos): | |
465 | l1,l2 = self.get2List(angulos) |
|
466 | l1,l2 = self.get2List(angulos) | |
466 | if len(l1)>0: |
|
467 | if len(l1)>0: | |
467 | angulos2 = self.fixData360(list_=l1,ang_=angulos) |
|
468 | angulos2 = self.fixData360(list_=l1,ang_=angulos) | |
468 | l1,l2 = self.get2List(angulos2) |
|
469 | l1,l2 = self.get2List(angulos2) | |
469 |
|
470 | |||
470 | ang1_,ang2_ = self.fixDataComp(ang_=angulos2,list1_=l1,list2_=l2) |
|
471 | ang1_,ang2_ = self.fixDataComp(ang_=angulos2,list1_=l1,list2_=l2) | |
471 | ang1_ = self.fixData360HL(ang1_) |
|
472 | ang1_ = self.fixData360HL(ang1_) | |
472 | ang2_ = self.fixData360HL(ang2_) |
|
473 | ang2_ = self.fixData360HL(ang2_) | |
473 | else: |
|
474 | else: | |
474 | ang1_= angulos |
|
475 | ang1_= angulos | |
475 | ang2_= angulos |
|
476 | ang2_= angulos | |
476 | return ang1_,ang2_ |
|
477 | return ang1_,ang2_ | |
477 |
|
478 | |||
478 | def analizeDATA(self,data_azi): |
|
479 | def analizeDATA(self,data_azi): | |
479 | list1 = [] |
|
480 | list1 = [] | |
480 | list2 = [] |
|
481 | list2 = [] | |
481 | dat = data_azi |
|
482 | dat = data_azi | |
482 | for i in reversed(range(1,len(dat))): |
|
483 | for i in reversed(range(1,len(dat))): | |
483 | if dat[i]>dat[i-1]: |
|
484 | if dat[i]>dat[i-1]: | |
484 | diff = int(dat[i])-int(dat[i-1]) |
|
485 | diff = int(dat[i])-int(dat[i-1]) | |
485 | else: |
|
486 | else: | |
486 | diff = 360+int(dat[i])-int(dat[i-1]) |
|
487 | diff = 360+int(dat[i])-int(dat[i-1]) | |
487 | if diff > 1: |
|
488 | if diff > 1: | |
488 | list1.append(i-1) |
|
489 | list1.append(i-1) | |
489 | list2.append(diff-1) |
|
490 | list2.append(diff-1) | |
490 | return list1,list2 |
|
491 | return list1,list2 | |
491 |
|
492 | |||
492 | def fixDATANEW(self,data_azi,data_weather): |
|
493 | def fixDATANEW(self,data_azi,data_weather): | |
493 | list1,list2 = self.analizeDATA(data_azi) |
|
494 | list1,list2 = self.analizeDATA(data_azi) | |
494 | if len(list1)== 0: |
|
495 | if len(list1)== 0: | |
495 | return data_azi,data_weather |
|
496 | return data_azi,data_weather | |
496 | else: |
|
497 | else: | |
497 | resize = 0 |
|
498 | resize = 0 | |
498 | for i in range(len(list2)): |
|
499 | for i in range(len(list2)): | |
499 | resize= resize + list2[i] |
|
500 | resize= resize + list2[i] | |
500 | new_data_azi = numpy.resize(data_azi,resize) |
|
501 | new_data_azi = numpy.resize(data_azi,resize) | |
501 | new_data_weather= numpy.resize(date_weather,resize) |
|
502 | new_data_weather= numpy.resize(date_weather,resize) | |
502 |
|
503 | |||
503 | for i in range(len(list2)): |
|
504 | for i in range(len(list2)): | |
504 | j=0 |
|
505 | j=0 | |
505 | position=list1[i]+1 |
|
506 | position=list1[i]+1 | |
506 | for j in range(list2[i]): |
|
507 | for j in range(list2[i]): | |
507 | new_data_azi[position+j]=new_data_azi[position+j-1]+1 |
|
508 | new_data_azi[position+j]=new_data_azi[position+j-1]+1 | |
508 | return new_data_azi |
|
509 | return new_data_azi | |
509 |
|
510 | |||
510 | def fixDATA(self,data_azi): |
|
511 | def fixDATA(self,data_azi): | |
511 | data=data_azi |
|
512 | data=data_azi | |
512 | for i in range(len(data)): |
|
513 | for i in range(len(data)): | |
513 | if numpy.isnan(data[i]): |
|
514 | if numpy.isnan(data[i]): | |
514 | data[i]=data[i-1]+1 |
|
515 | data[i]=data[i-1]+1 | |
515 | return data |
|
516 | return data | |
516 |
|
517 | |||
517 | def replaceNAN(self,data_weather,data_azi,val): |
|
518 | def replaceNAN(self,data_weather,data_azi,val): | |
518 | data= data_azi |
|
519 | data= data_azi | |
519 | data_T= data_weather |
|
520 | data_T= data_weather | |
520 | if data.shape[0]> data_T.shape[0]: |
|
521 | if data.shape[0]> data_T.shape[0]: | |
521 | data_N = numpy.ones( [data.shape[0],data_T.shape[1]]) |
|
522 | data_N = numpy.ones( [data.shape[0],data_T.shape[1]]) | |
522 | c = 0 |
|
523 | c = 0 | |
523 | for i in range(len(data)): |
|
524 | for i in range(len(data)): | |
524 | if numpy.isnan(data[i]): |
|
525 | if numpy.isnan(data[i]): | |
525 | data_N[i,:]=numpy.ones(data_T.shape[1])*numpy.nan |
|
526 | data_N[i,:]=numpy.ones(data_T.shape[1])*numpy.nan | |
526 | else: |
|
527 | else: | |
527 | data_N[i,:]=data_T[c,:] |
|
528 | data_N[i,:]=data_T[c,:] | |
528 | c=c+1 |
|
529 | c=c+1 | |
529 | return data_N |
|
530 | return data_N | |
530 | else: |
|
531 | else: | |
531 | for i in range(len(data)): |
|
532 | for i in range(len(data)): | |
532 | if numpy.isnan(data[i]): |
|
533 | if numpy.isnan(data[i]): | |
533 | data_T[i,:]=numpy.ones(data_T.shape[1])*numpy.nan |
|
534 | data_T[i,:]=numpy.ones(data_T.shape[1])*numpy.nan | |
534 | return data_T |
|
535 | return data_T | |
535 |
|
536 | |||
536 | def const_ploteo(self,data_weather,data_azi,step,res): |
|
537 | def const_ploteo(self,data_weather,data_azi,step,res): | |
537 | if self.ini==0: |
|
538 | if self.ini==0: | |
538 | #------- |
|
539 | #------- | |
539 | n = (360/res)-len(data_azi) |
|
540 | n = (360/res)-len(data_azi) | |
540 | #--------------------- new ------------------------- |
|
541 | #--------------------- new ------------------------- | |
541 | data_azi_new ,data_azi_old= self.globalCheckPED(data_azi) |
|
542 | data_azi_new ,data_azi_old= self.globalCheckPED(data_azi) | |
542 | #------------------------ |
|
543 | #------------------------ | |
543 | start = data_azi_new[-1] + res |
|
544 | start = data_azi_new[-1] + res | |
544 | end = data_azi_new[0] - res |
|
545 | end = data_azi_new[0] - res | |
545 | #------ new |
|
546 | #------ new | |
546 | self.last_data_azi = end |
|
547 | self.last_data_azi = end | |
547 | if start>end: |
|
548 | if start>end: | |
548 | end = end + 360 |
|
549 | end = end + 360 | |
549 | azi_vacia = numpy.linspace(start,end,int(n)) |
|
550 | azi_vacia = numpy.linspace(start,end,int(n)) | |
550 | azi_vacia = numpy.where(azi_vacia>360,azi_vacia-360,azi_vacia) |
|
551 | azi_vacia = numpy.where(azi_vacia>360,azi_vacia-360,azi_vacia) | |
551 | data_azi = numpy.hstack((data_azi_new,azi_vacia)) |
|
552 | data_azi = numpy.hstack((data_azi_new,azi_vacia)) | |
552 | # RADAR |
|
553 | # RADAR | |
553 | val_mean = numpy.mean(data_weather[:,-1]) |
|
554 | val_mean = numpy.mean(data_weather[:,-1]) | |
554 | self.val_mean = val_mean |
|
555 | self.val_mean = val_mean | |
555 | data_weather_cmp = numpy.ones([(360-data_weather.shape[0]),data_weather.shape[1]])*val_mean |
|
556 | data_weather_cmp = numpy.ones([(360-data_weather.shape[0]),data_weather.shape[1]])*val_mean | |
556 | data_weather = self.replaceNAN(data_weather=data_weather,data_azi=data_azi_old,val=self.val_mean) |
|
557 | data_weather = self.replaceNAN(data_weather=data_weather,data_azi=data_azi_old,val=self.val_mean) | |
557 | data_weather = numpy.vstack((data_weather,data_weather_cmp)) |
|
558 | data_weather = numpy.vstack((data_weather,data_weather_cmp)) | |
558 | else: |
|
559 | else: | |
559 | # azimuth |
|
560 | # azimuth | |
560 | flag=0 |
|
561 | flag=0 | |
561 | start_azi = self.res_azi[0] |
|
562 | start_azi = self.res_azi[0] | |
562 | #-----------new------------ |
|
563 | #-----------new------------ | |
563 | data_azi ,data_azi_old= self.globalCheckPED(data_azi) |
|
564 | data_azi ,data_azi_old= self.globalCheckPED(data_azi) | |
564 | data_weather = self.replaceNAN(data_weather=data_weather,data_azi=data_azi_old,val=self.val_mean) |
|
565 | data_weather = self.replaceNAN(data_weather=data_weather,data_azi=data_azi_old,val=self.val_mean) | |
565 | #-------------------------- |
|
566 | #-------------------------- | |
566 | start = data_azi[0] |
|
567 | start = data_azi[0] | |
567 | end = data_azi[-1] |
|
568 | end = data_azi[-1] | |
568 | self.last_data_azi= end |
|
569 | self.last_data_azi= end | |
569 | if start< start_azi: |
|
570 | if start< start_azi: | |
570 | start = start +360 |
|
571 | start = start +360 | |
571 | if end <start_azi: |
|
572 | if end <start_azi: | |
572 | end = end +360 |
|
573 | end = end +360 | |
573 |
|
574 | |||
574 | pos_ini = int((start-start_azi)/res) |
|
575 | pos_ini = int((start-start_azi)/res) | |
575 | len_azi = len(data_azi) |
|
576 | len_azi = len(data_azi) | |
576 | if (360-pos_ini)<len_azi: |
|
577 | if (360-pos_ini)<len_azi: | |
577 | if pos_ini+1==360: |
|
578 | if pos_ini+1==360: | |
578 | pos_ini=0 |
|
579 | pos_ini=0 | |
579 | else: |
|
580 | else: | |
580 | flag=1 |
|
581 | flag=1 | |
581 | dif= 360-pos_ini |
|
582 | dif= 360-pos_ini | |
582 | comp= len_azi-dif |
|
583 | comp= len_azi-dif | |
583 | #----------------- |
|
584 | #----------------- | |
584 | if flag==0: |
|
585 | if flag==0: | |
585 | # AZIMUTH |
|
586 | # AZIMUTH | |
586 | self.res_azi[pos_ini:pos_ini+len_azi] = data_azi |
|
587 | self.res_azi[pos_ini:pos_ini+len_azi] = data_azi | |
587 | # RADAR |
|
588 | # RADAR | |
588 | self.res_weather[pos_ini:pos_ini+len_azi,:] = data_weather |
|
589 | self.res_weather[pos_ini:pos_ini+len_azi,:] = data_weather | |
589 | else: |
|
590 | else: | |
590 | # AZIMUTH |
|
591 | # AZIMUTH | |
591 | self.res_azi[pos_ini:pos_ini+dif] = data_azi[0:dif] |
|
592 | self.res_azi[pos_ini:pos_ini+dif] = data_azi[0:dif] | |
592 | self.res_azi[0:comp] = data_azi[dif:] |
|
593 | self.res_azi[0:comp] = data_azi[dif:] | |
593 | # RADAR |
|
594 | # RADAR | |
594 | self.res_weather[pos_ini:pos_ini+dif,:] = data_weather[0:dif,:] |
|
595 | self.res_weather[pos_ini:pos_ini+dif,:] = data_weather[0:dif,:] | |
595 | self.res_weather[0:comp,:] = data_weather[dif:,:] |
|
596 | self.res_weather[0:comp,:] = data_weather[dif:,:] | |
596 | flag=0 |
|
597 | flag=0 | |
597 | data_azi = self.res_azi |
|
598 | data_azi = self.res_azi | |
598 | data_weather = self.res_weather |
|
599 | data_weather = self.res_weather | |
599 |
|
600 | |||
600 | return data_weather,data_azi |
|
601 | return data_weather,data_azi | |
601 |
|
602 | |||
602 | def plot(self): |
|
603 | def plot(self): | |
603 | thisDatetime = datetime.datetime.utcfromtimestamp(self.data.times[-1]).strftime('%Y-%m-%d %H:%M:%S') |
|
604 | thisDatetime = datetime.datetime.utcfromtimestamp(self.data.times[-1]).strftime('%Y-%m-%d %H:%M:%S') | |
604 | data = self.data[-1] |
|
605 | data = self.data[-1] | |
605 | r = self.data.yrange |
|
606 | r = self.data.yrange | |
606 | delta_height = r[1]-r[0] |
|
607 | delta_height = r[1]-r[0] | |
607 | r_mask = numpy.where(r>=0)[0] |
|
608 | r_mask = numpy.where(r>=0)[0] | |
608 | r = numpy.arange(len(r_mask))*delta_height |
|
609 | r = numpy.arange(len(r_mask))*delta_height | |
609 | self.y = 2*r |
|
610 | self.y = 2*r | |
610 | # RADAR |
|
611 | # RADAR | |
611 | #data_weather = data['weather'] |
|
612 | #data_weather = data['weather'] | |
612 | # PEDESTAL |
|
613 | # PEDESTAL | |
613 | #data_azi = data['azi'] |
|
614 | #data_azi = data['azi'] | |
614 | res = 1 |
|
615 | res = 1 | |
615 | # STEP |
|
616 | # STEP | |
616 | step = (360/(res*data['weather'].shape[0])) |
|
617 | step = (360/(res*data['weather'].shape[0])) | |
617 |
|
618 | |||
618 | self.res_weather, self.res_azi = self.const_ploteo(data_weather=data['weather'][:,r_mask],data_azi=data['azi'],step=step,res=res) |
|
619 | self.res_weather, self.res_azi = self.const_ploteo(data_weather=data['weather'][:,r_mask],data_azi=data['azi'],step=step,res=res) | |
619 | self.res_ele = numpy.mean(data['ele']) |
|
620 | self.res_ele = numpy.mean(data['ele']) | |
620 | ################# PLOTEO ################### |
|
621 | ################# PLOTEO ################### | |
621 | for i,ax in enumerate(self.axes): |
|
622 | for i,ax in enumerate(self.axes): | |
622 | if ax.firsttime: |
|
623 | if ax.firsttime: | |
623 | plt.clf() |
|
624 | plt.clf() | |
624 | cgax, pm = wrl.vis.plot_ppi(self.res_weather,r=r,az=self.res_azi,fig=self.figures[0], proj='cg', vmin=20, vmax=80) |
|
625 | cgax, pm = wrl.vis.plot_ppi(self.res_weather,r=r,az=self.res_azi,fig=self.figures[0], proj='cg', vmin=20, vmax=80) | |
625 | else: |
|
626 | else: | |
626 | plt.clf() |
|
627 | plt.clf() | |
627 | cgax, pm = wrl.vis.plot_ppi(self.res_weather,r=r,az=self.res_azi,fig=self.figures[0], proj='cg', vmin=20, vmax=80) |
|
628 | cgax, pm = wrl.vis.plot_ppi(self.res_weather,r=r,az=self.res_azi,fig=self.figures[0], proj='cg', vmin=20, vmax=80) | |
628 | caax = cgax.parasites[0] |
|
629 | caax = cgax.parasites[0] | |
629 | paax = cgax.parasites[1] |
|
630 | paax = cgax.parasites[1] | |
630 | cbar = plt.gcf().colorbar(pm, pad=0.075) |
|
631 | cbar = plt.gcf().colorbar(pm, pad=0.075) | |
631 | caax.set_xlabel('x_range [km]') |
|
632 | caax.set_xlabel('x_range [km]') | |
632 | caax.set_ylabel('y_range [km]') |
|
633 | caax.set_ylabel('y_range [km]') | |
633 | plt.text(1.0, 1.05, 'Azimuth '+str(thisDatetime)+" Step "+str(self.ini)+ " Elev: "+str(round(self.res_ele,2)), transform=caax.transAxes, va='bottom',ha='right') |
|
634 | plt.text(1.0, 1.05, 'Azimuth '+str(thisDatetime)+" Step "+str(self.ini)+ " Elev: "+str(round(self.res_ele,2)), transform=caax.transAxes, va='bottom',ha='right') | |
634 |
|
635 | |||
635 | self.ini= self.ini+1 |
|
636 | self.ini= self.ini+1 | |
636 |
|
637 | |||
637 |
|
638 | |||
638 | class WeatherRHIPlot(Plot): |
|
639 | class WeatherRHIPlot(Plot): | |
639 | CODE = 'weather' |
|
640 | CODE = 'weather' | |
640 | plot_name = 'weather' |
|
641 | plot_name = 'weather' | |
641 | plot_type = 'rhistyle' |
|
642 | plot_type = 'rhistyle' | |
642 | buffering = False |
|
643 | buffering = False | |
643 | data_ele_tmp = None |
|
644 | data_ele_tmp = None | |
644 |
|
645 | |||
645 | def setup(self): |
|
646 | def setup(self): | |
646 | print("********************") |
|
647 | print("********************") | |
647 | print("********************") |
|
648 | print("********************") | |
648 | print("********************") |
|
649 | print("********************") | |
649 | print("SETUP WEATHER PLOT") |
|
650 | print("SETUP WEATHER PLOT") | |
650 | self.ncols = 1 |
|
651 | self.ncols = 1 | |
651 | self.nrows = 1 |
|
652 | self.nrows = 1 | |
652 | self.nplots= 1 |
|
653 | self.nplots= 1 | |
653 | self.ylabel= 'Range [Km]' |
|
654 | self.ylabel= 'Range [Km]' | |
654 | self.titles= ['Weather'] |
|
655 | self.titles= ['Weather'] | |
655 | if self.channels is not None: |
|
656 | if self.channels is not None: | |
656 | self.nplots = len(self.channels) |
|
657 | self.nplots = len(self.channels) | |
657 | self.nrows = len(self.channels) |
|
658 | self.nrows = len(self.channels) | |
658 | else: |
|
659 | else: | |
659 | self.nplots = self.data.shape(self.CODE)[0] |
|
660 | self.nplots = self.data.shape(self.CODE)[0] | |
660 | self.nrows = self.nplots |
|
661 | self.nrows = self.nplots | |
661 | self.channels = list(range(self.nplots)) |
|
662 | self.channels = list(range(self.nplots)) | |
662 | print("channels",self.channels) |
|
663 | print("channels",self.channels) | |
663 | print("que saldra", self.data.shape(self.CODE)[0]) |
|
664 | print("que saldra", self.data.shape(self.CODE)[0]) | |
664 | self.titles = ['{} Channel {}'.format(self.CODE.upper(), x) for x in range(self.nrows)] |
|
665 | self.titles = ['{} Channel {}'.format(self.CODE.upper(), x) for x in range(self.nrows)] | |
665 | print("self.titles",self.titles) |
|
666 | print("self.titles",self.titles) | |
666 | self.colorbar=False |
|
667 | self.colorbar=False | |
667 | self.width =8 |
|
668 | self.width =8 | |
668 | self.height =8 |
|
669 | self.height =8 | |
669 | self.ini =0 |
|
670 | self.ini =0 | |
670 | self.len_azi =0 |
|
671 | self.len_azi =0 | |
671 | self.buffer_ini = None |
|
672 | self.buffer_ini = None | |
672 | self.buffer_ele = None |
|
673 | self.buffer_ele = None | |
673 | self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08}) |
|
674 | self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08}) | |
674 | self.flag =0 |
|
675 | self.flag =0 | |
675 | self.indicador= 0 |
|
676 | self.indicador= 0 | |
676 | self.last_data_ele = None |
|
677 | self.last_data_ele = None | |
677 | self.val_mean = None |
|
678 | self.val_mean = None | |
678 |
|
679 | |||
679 | def update(self, dataOut): |
|
680 | def update(self, dataOut): | |
680 |
|
681 | |||
681 | data = {} |
|
682 | data = {} | |
682 | meta = {} |
|
683 | meta = {} | |
683 | if hasattr(dataOut, 'dataPP_POWER'): |
|
684 | if hasattr(dataOut, 'dataPP_POWER'): | |
684 | factor = 1 |
|
685 | factor = 1 | |
685 | if hasattr(dataOut, 'nFFTPoints'): |
|
686 | if hasattr(dataOut, 'nFFTPoints'): | |
686 | factor = dataOut.normFactor |
|
687 | factor = dataOut.normFactor | |
687 | print("dataOut",dataOut.data_360.shape) |
|
688 | print("dataOut",dataOut.data_360.shape) | |
688 | # |
|
689 | # | |
689 | data['weather'] = 10*numpy.log10(dataOut.data_360/(factor)) |
|
690 | data['weather'] = 10*numpy.log10(dataOut.data_360/(factor)) | |
690 | # |
|
691 | # | |
691 | #data['weather'] = 10*numpy.log10(dataOut.data_360[1]/(factor)) |
|
692 | #data['weather'] = 10*numpy.log10(dataOut.data_360[1]/(factor)) | |
692 | data['azi'] = dataOut.data_azi |
|
693 | data['azi'] = dataOut.data_azi | |
693 | data['ele'] = dataOut.data_ele |
|
694 | data['ele'] = dataOut.data_ele | |
694 | #print("UPDATE") |
|
695 | #print("UPDATE") | |
695 | #print("data[weather]",data['weather'].shape) |
|
696 | #print("data[weather]",data['weather'].shape) | |
696 | #print("data[azi]",data['azi']) |
|
697 | #print("data[azi]",data['azi']) | |
697 | return data, meta |
|
698 | return data, meta | |
698 |
|
699 | |||
699 | def get2List(self,angulos): |
|
700 | def get2List(self,angulos): | |
700 | list1=[] |
|
701 | list1=[] | |
701 | list2=[] |
|
702 | list2=[] | |
702 | for i in reversed(range(len(angulos))): |
|
703 | for i in reversed(range(len(angulos))): | |
703 | if not i==0:#el caso de i=0 evalula el primero de la lista con el ultimo y no es relevante |
|
704 | if not i==0:#el caso de i=0 evalula el primero de la lista con el ultimo y no es relevante | |
704 | diff_ = angulos[i]-angulos[i-1] |
|
705 | diff_ = angulos[i]-angulos[i-1] | |
705 | if abs(diff_) >1.5: |
|
706 | if abs(diff_) >1.5: | |
706 | list1.append(i-1) |
|
707 | list1.append(i-1) | |
707 | list2.append(diff_) |
|
708 | list2.append(diff_) | |
708 | return list(reversed(list1)),list(reversed(list2)) |
|
709 | return list(reversed(list1)),list(reversed(list2)) | |
709 |
|
710 | |||
710 | def fixData90(self,list_,ang_): |
|
711 | def fixData90(self,list_,ang_): | |
711 | if list_[0]==-1: |
|
712 | if list_[0]==-1: | |
712 | vec = numpy.where(ang_<ang_[0]) |
|
713 | vec = numpy.where(ang_<ang_[0]) | |
713 | ang_[vec] = ang_[vec]+90 |
|
714 | ang_[vec] = ang_[vec]+90 | |
714 | return ang_ |
|
715 | return ang_ | |
715 | return ang_ |
|
716 | return ang_ | |
716 |
|
717 | |||
717 | def fixData90HL(self,angulos): |
|
718 | def fixData90HL(self,angulos): | |
718 | vec = numpy.where(angulos>=90) |
|
719 | vec = numpy.where(angulos>=90) | |
719 | angulos[vec]=angulos[vec]-90 |
|
720 | angulos[vec]=angulos[vec]-90 | |
720 | return angulos |
|
721 | return angulos | |
721 |
|
722 | |||
722 |
|
723 | |||
723 | def search_pos(self,pos,list_): |
|
724 | def search_pos(self,pos,list_): | |
724 | for i in range(len(list_)): |
|
725 | for i in range(len(list_)): | |
725 | if pos == list_[i]: |
|
726 | if pos == list_[i]: | |
726 | return True,i |
|
727 | return True,i | |
727 | i=None |
|
728 | i=None | |
728 | return False,i |
|
729 | return False,i | |
729 |
|
730 | |||
730 | def fixDataComp(self,ang_,list1_,list2_,tipo_case): |
|
731 | def fixDataComp(self,ang_,list1_,list2_,tipo_case): | |
731 | size = len(ang_) |
|
732 | size = len(ang_) | |
732 | size2 = 0 |
|
733 | size2 = 0 | |
733 | for i in range(len(list2_)): |
|
734 | for i in range(len(list2_)): | |
734 | size2=size2+round(abs(list2_[i]))-1 |
|
735 | size2=size2+round(abs(list2_[i]))-1 | |
735 | new_size= size+size2 |
|
736 | new_size= size+size2 | |
736 | ang_new = numpy.zeros(new_size) |
|
737 | ang_new = numpy.zeros(new_size) | |
737 | ang_new2 = numpy.zeros(new_size) |
|
738 | ang_new2 = numpy.zeros(new_size) | |
738 |
|
739 | |||
739 | tmp = 0 |
|
740 | tmp = 0 | |
740 | c = 0 |
|
741 | c = 0 | |
741 | for i in range(len(ang_)): |
|
742 | for i in range(len(ang_)): | |
742 | ang_new[tmp +c] = ang_[i] |
|
743 | ang_new[tmp +c] = ang_[i] | |
743 | ang_new2[tmp+c] = ang_[i] |
|
744 | ang_new2[tmp+c] = ang_[i] | |
744 | condition , value = self.search_pos(i,list1_) |
|
745 | condition , value = self.search_pos(i,list1_) | |
745 | if condition: |
|
746 | if condition: | |
746 | pos = tmp + c + 1 |
|
747 | pos = tmp + c + 1 | |
747 | for k in range(round(abs(list2_[value]))-1): |
|
748 | for k in range(round(abs(list2_[value]))-1): | |
748 | if tipo_case==0 or tipo_case==3:#subida |
|
749 | if tipo_case==0 or tipo_case==3:#subida | |
749 | ang_new[pos+k] = ang_new[pos+k-1]+1 |
|
750 | ang_new[pos+k] = ang_new[pos+k-1]+1 | |
750 | ang_new2[pos+k] = numpy.nan |
|
751 | ang_new2[pos+k] = numpy.nan | |
751 | elif tipo_case==1 or tipo_case==2:#bajada |
|
752 | elif tipo_case==1 or tipo_case==2:#bajada | |
752 | ang_new[pos+k] = ang_new[pos+k-1]-1 |
|
753 | ang_new[pos+k] = ang_new[pos+k-1]-1 | |
753 | ang_new2[pos+k] = numpy.nan |
|
754 | ang_new2[pos+k] = numpy.nan | |
754 |
|
755 | |||
755 | tmp = pos +k |
|
756 | tmp = pos +k | |
756 | c = 0 |
|
757 | c = 0 | |
757 | c=c+1 |
|
758 | c=c+1 | |
758 | return ang_new,ang_new2 |
|
759 | return ang_new,ang_new2 | |
759 |
|
760 | |||
760 | def globalCheckPED(self,angulos,tipo_case): |
|
761 | def globalCheckPED(self,angulos,tipo_case): | |
761 | l1,l2 = self.get2List(angulos) |
|
762 | l1,l2 = self.get2List(angulos) | |
762 | ##print("l1",l1) |
|
763 | ##print("l1",l1) | |
763 | ##print("l2",l2) |
|
764 | ##print("l2",l2) | |
764 | if len(l1)>0: |
|
765 | if len(l1)>0: | |
765 | #angulos2 = self.fixData90(list_=l1,ang_=angulos) |
|
766 | #angulos2 = self.fixData90(list_=l1,ang_=angulos) | |
766 | #l1,l2 = self.get2List(angulos2) |
|
767 | #l1,l2 = self.get2List(angulos2) | |
767 | ang1_,ang2_ = self.fixDataComp(ang_=angulos,list1_=l1,list2_=l2,tipo_case=tipo_case) |
|
768 | ang1_,ang2_ = self.fixDataComp(ang_=angulos,list1_=l1,list2_=l2,tipo_case=tipo_case) | |
768 | #ang1_ = self.fixData90HL(ang1_) |
|
769 | #ang1_ = self.fixData90HL(ang1_) | |
769 | #ang2_ = self.fixData90HL(ang2_) |
|
770 | #ang2_ = self.fixData90HL(ang2_) | |
770 | else: |
|
771 | else: | |
771 | ang1_= angulos |
|
772 | ang1_= angulos | |
772 | ang2_= angulos |
|
773 | ang2_= angulos | |
773 | return ang1_,ang2_ |
|
774 | return ang1_,ang2_ | |
774 |
|
775 | |||
775 |
|
776 | |||
776 | def replaceNAN(self,data_weather,data_ele,val): |
|
777 | def replaceNAN(self,data_weather,data_ele,val): | |
777 | data= data_ele |
|
778 | data= data_ele | |
778 | data_T= data_weather |
|
779 | data_T= data_weather | |
779 | if data.shape[0]> data_T.shape[0]: |
|
780 | if data.shape[0]> data_T.shape[0]: | |
780 | data_N = numpy.ones( [data.shape[0],data_T.shape[1]]) |
|
781 | data_N = numpy.ones( [data.shape[0],data_T.shape[1]]) | |
781 | c = 0 |
|
782 | c = 0 | |
782 | for i in range(len(data)): |
|
783 | for i in range(len(data)): | |
783 | if numpy.isnan(data[i]): |
|
784 | if numpy.isnan(data[i]): | |
784 | data_N[i,:]=numpy.ones(data_T.shape[1])*numpy.nan |
|
785 | data_N[i,:]=numpy.ones(data_T.shape[1])*numpy.nan | |
785 | else: |
|
786 | else: | |
786 | data_N[i,:]=data_T[c,:] |
|
787 | data_N[i,:]=data_T[c,:] | |
787 | c=c+1 |
|
788 | c=c+1 | |
788 | return data_N |
|
789 | return data_N | |
789 | else: |
|
790 | else: | |
790 | for i in range(len(data)): |
|
791 | for i in range(len(data)): | |
791 | if numpy.isnan(data[i]): |
|
792 | if numpy.isnan(data[i]): | |
792 | data_T[i,:]=numpy.ones(data_T.shape[1])*numpy.nan |
|
793 | data_T[i,:]=numpy.ones(data_T.shape[1])*numpy.nan | |
793 | return data_T |
|
794 | return data_T | |
794 |
|
795 | |||
795 | def check_case(self,data_ele,ang_max,ang_min): |
|
796 | def check_case(self,data_ele,ang_max,ang_min): | |
796 | start = data_ele[0] |
|
797 | start = data_ele[0] | |
797 | end = data_ele[-1] |
|
798 | end = data_ele[-1] | |
798 | number = (end-start) |
|
799 | number = (end-start) | |
799 | len_ang=len(data_ele) |
|
800 | len_ang=len(data_ele) | |
800 | print("start",start) |
|
801 | print("start",start) | |
801 | print("end",end) |
|
802 | print("end",end) | |
802 | print("number",number) |
|
803 | print("number",number) | |
803 |
|
804 | |||
804 | print("len_ang",len_ang) |
|
805 | print("len_ang",len_ang) | |
805 |
|
806 | |||
806 | #exit(1) |
|
807 | #exit(1) | |
807 |
|
808 | |||
808 | if start<end and (round(abs(number)+1)>=len_ang or (numpy.argmin(data_ele)==0)):#caso subida |
|
809 | if start<end and (round(abs(number)+1)>=len_ang or (numpy.argmin(data_ele)==0)):#caso subida | |
809 | return 0 |
|
810 | return 0 | |
810 | #elif start>end and (round(abs(number)+1)>=len_ang or(numpy.argmax(data_ele)==0)):#caso bajada |
|
811 | #elif start>end and (round(abs(number)+1)>=len_ang or(numpy.argmax(data_ele)==0)):#caso bajada | |
811 | # return 1 |
|
812 | # return 1 | |
812 | elif round(abs(number)+1)>=len_ang and (start>end or(numpy.argmax(data_ele)==0)):#caso bajada |
|
813 | elif round(abs(number)+1)>=len_ang and (start>end or(numpy.argmax(data_ele)==0)):#caso bajada | |
813 | return 1 |
|
814 | return 1 | |
814 | elif round(abs(number)+1)<len_ang and data_ele[-2]>data_ele[-1]:# caso BAJADA CAMBIO ANG MAX |
|
815 | elif round(abs(number)+1)<len_ang and data_ele[-2]>data_ele[-1]:# caso BAJADA CAMBIO ANG MAX | |
815 | return 2 |
|
816 | return 2 | |
816 | elif round(abs(number)+1)<len_ang and data_ele[-2]<data_ele[-1] :# caso SUBIDA CAMBIO ANG MIN |
|
817 | elif round(abs(number)+1)<len_ang and data_ele[-2]<data_ele[-1] :# caso SUBIDA CAMBIO ANG MIN | |
817 | return 3 |
|
818 | return 3 | |
818 |
|
819 | |||
819 |
|
820 | |||
820 | def const_ploteo(self,val_ch,data_weather,data_ele,step,res,ang_max,ang_min): |
|
821 | def const_ploteo(self,val_ch,data_weather,data_ele,step,res,ang_max,ang_min): | |
821 | ang_max= ang_max |
|
822 | ang_max= ang_max | |
822 | ang_min= ang_min |
|
823 | ang_min= ang_min | |
823 | data_weather=data_weather |
|
824 | data_weather=data_weather | |
824 | val_ch=val_ch |
|
825 | val_ch=val_ch | |
825 | ##print("*********************DATA WEATHER**************************************") |
|
826 | ##print("*********************DATA WEATHER**************************************") | |
826 | ##print(data_weather) |
|
827 | ##print(data_weather) | |
827 | if self.ini==0: |
|
828 | if self.ini==0: | |
828 | ''' |
|
829 | ''' | |
829 | print("**********************************************") |
|
830 | print("**********************************************") | |
830 | print("**********************************************") |
|
831 | print("**********************************************") | |
831 | print("***************ini**************") |
|
832 | print("***************ini**************") | |
832 | print("**********************************************") |
|
833 | print("**********************************************") | |
833 | print("**********************************************") |
|
834 | print("**********************************************") | |
834 | ''' |
|
835 | ''' | |
835 | #print("data_ele",data_ele) |
|
836 | #print("data_ele",data_ele) | |
836 | #---------------------------------------------------------- |
|
837 | #---------------------------------------------------------- | |
837 | tipo_case = self.check_case(data_ele,ang_max,ang_min) |
|
838 | tipo_case = self.check_case(data_ele,ang_max,ang_min) | |
838 | print("check_case",tipo_case) |
|
839 | print("check_case",tipo_case) | |
839 | #exit(1) |
|
840 | #exit(1) | |
840 | #--------------------- new ------------------------- |
|
841 | #--------------------- new ------------------------- | |
841 | data_ele_new ,data_ele_old= self.globalCheckPED(data_ele,tipo_case) |
|
842 | data_ele_new ,data_ele_old= self.globalCheckPED(data_ele,tipo_case) | |
842 |
|
843 | |||
843 | #-------------------------CAMBIOS RHI--------------------------------- |
|
844 | #-------------------------CAMBIOS RHI--------------------------------- | |
844 | start= ang_min |
|
845 | start= ang_min | |
845 | end = ang_max |
|
846 | end = ang_max | |
846 | n= (ang_max-ang_min)/res |
|
847 | n= (ang_max-ang_min)/res | |
847 | #------ new |
|
848 | #------ new | |
848 | self.start_data_ele = data_ele_new[0] |
|
849 | self.start_data_ele = data_ele_new[0] | |
849 | self.end_data_ele = data_ele_new[-1] |
|
850 | self.end_data_ele = data_ele_new[-1] | |
850 | if tipo_case==0 or tipo_case==3: # SUBIDA |
|
851 | if tipo_case==0 or tipo_case==3: # SUBIDA | |
851 | n1= round(self.start_data_ele)- start |
|
852 | n1= round(self.start_data_ele)- start | |
852 | n2= end - round(self.end_data_ele) |
|
853 | n2= end - round(self.end_data_ele) | |
853 | print(self.start_data_ele) |
|
854 | print(self.start_data_ele) | |
854 | print(self.end_data_ele) |
|
855 | print(self.end_data_ele) | |
855 | if n1>0: |
|
856 | if n1>0: | |
856 | ele1= numpy.linspace(ang_min+1,self.start_data_ele-1,n1) |
|
857 | ele1= numpy.linspace(ang_min+1,self.start_data_ele-1,n1) | |
857 | ele1_nan= numpy.ones(n1)*numpy.nan |
|
858 | ele1_nan= numpy.ones(n1)*numpy.nan | |
858 | data_ele = numpy.hstack((ele1,data_ele_new)) |
|
859 | data_ele = numpy.hstack((ele1,data_ele_new)) | |
859 | print("ele1_nan",ele1_nan.shape) |
|
860 | print("ele1_nan",ele1_nan.shape) | |
860 | print("data_ele_old",data_ele_old.shape) |
|
861 | print("data_ele_old",data_ele_old.shape) | |
861 | data_ele_old = numpy.hstack((ele1_nan,data_ele_old)) |
|
862 | data_ele_old = numpy.hstack((ele1_nan,data_ele_old)) | |
862 | if n2>0: |
|
863 | if n2>0: | |
863 | ele2= numpy.linspace(self.end_data_ele+1,end,n2) |
|
864 | ele2= numpy.linspace(self.end_data_ele+1,end,n2) | |
864 | ele2_nan= numpy.ones(n2)*numpy.nan |
|
865 | ele2_nan= numpy.ones(n2)*numpy.nan | |
865 | data_ele = numpy.hstack((data_ele,ele2)) |
|
866 | data_ele = numpy.hstack((data_ele,ele2)) | |
866 | print("ele2_nan",ele2_nan.shape) |
|
867 | print("ele2_nan",ele2_nan.shape) | |
867 | print("data_ele_old",data_ele_old.shape) |
|
868 | print("data_ele_old",data_ele_old.shape) | |
868 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) |
|
869 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) | |
869 |
|
870 | |||
870 | if tipo_case==1 or tipo_case==2: # BAJADA |
|
871 | if tipo_case==1 or tipo_case==2: # BAJADA | |
871 | data_ele_new = data_ele_new[::-1] # reversa |
|
872 | data_ele_new = data_ele_new[::-1] # reversa | |
872 | data_ele_old = data_ele_old[::-1]# reversa |
|
873 | data_ele_old = data_ele_old[::-1]# reversa | |
873 | data_weather = data_weather[::-1,:]# reversa |
|
874 | data_weather = data_weather[::-1,:]# reversa | |
874 | vec= numpy.where(data_ele_new<ang_max) |
|
875 | vec= numpy.where(data_ele_new<ang_max) | |
875 | data_ele_new = data_ele_new[vec] |
|
876 | data_ele_new = data_ele_new[vec] | |
876 | data_ele_old = data_ele_old[vec] |
|
877 | data_ele_old = data_ele_old[vec] | |
877 | data_weather = data_weather[vec[0]] |
|
878 | data_weather = data_weather[vec[0]] | |
878 | vec2= numpy.where(0<data_ele_new) |
|
879 | vec2= numpy.where(0<data_ele_new) | |
879 | data_ele_new = data_ele_new[vec2] |
|
880 | data_ele_new = data_ele_new[vec2] | |
880 | data_ele_old = data_ele_old[vec2] |
|
881 | data_ele_old = data_ele_old[vec2] | |
881 | data_weather = data_weather[vec2[0]] |
|
882 | data_weather = data_weather[vec2[0]] | |
882 | self.start_data_ele = data_ele_new[0] |
|
883 | self.start_data_ele = data_ele_new[0] | |
883 | self.end_data_ele = data_ele_new[-1] |
|
884 | self.end_data_ele = data_ele_new[-1] | |
884 |
|
885 | |||
885 | n1= round(self.start_data_ele)- start |
|
886 | n1= round(self.start_data_ele)- start | |
886 | n2= end - round(self.end_data_ele)-1 |
|
887 | n2= end - round(self.end_data_ele)-1 | |
887 | print(self.start_data_ele) |
|
888 | print(self.start_data_ele) | |
888 | print(self.end_data_ele) |
|
889 | print(self.end_data_ele) | |
889 | if n1>0: |
|
890 | if n1>0: | |
890 | ele1= numpy.linspace(ang_min+1,self.start_data_ele-1,n1) |
|
891 | ele1= numpy.linspace(ang_min+1,self.start_data_ele-1,n1) | |
891 | ele1_nan= numpy.ones(n1)*numpy.nan |
|
892 | ele1_nan= numpy.ones(n1)*numpy.nan | |
892 | data_ele = numpy.hstack((ele1,data_ele_new)) |
|
893 | data_ele = numpy.hstack((ele1,data_ele_new)) | |
893 | data_ele_old = numpy.hstack((ele1_nan,data_ele_old)) |
|
894 | data_ele_old = numpy.hstack((ele1_nan,data_ele_old)) | |
894 | if n2>0: |
|
895 | if n2>0: | |
895 | ele2= numpy.linspace(self.end_data_ele+1,end,n2) |
|
896 | ele2= numpy.linspace(self.end_data_ele+1,end,n2) | |
896 | ele2_nan= numpy.ones(n2)*numpy.nan |
|
897 | ele2_nan= numpy.ones(n2)*numpy.nan | |
897 | data_ele = numpy.hstack((data_ele,ele2)) |
|
898 | data_ele = numpy.hstack((data_ele,ele2)) | |
898 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) |
|
899 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) | |
899 | # RADAR |
|
900 | # RADAR | |
900 | # NOTA data_ele y data_weather es la variable que retorna |
|
901 | # NOTA data_ele y data_weather es la variable que retorna | |
901 | val_mean = numpy.mean(data_weather[:,-1]) |
|
902 | val_mean = numpy.mean(data_weather[:,-1]) | |
902 | self.val_mean = val_mean |
|
903 | self.val_mean = val_mean | |
903 | data_weather = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) |
|
904 | data_weather = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) | |
904 | self.data_ele_tmp[val_ch]= data_ele_old |
|
905 | self.data_ele_tmp[val_ch]= data_ele_old | |
905 | else: |
|
906 | else: | |
906 | #print("**********************************************") |
|
907 | #print("**********************************************") | |
907 | #print("****************VARIABLE**********************") |
|
908 | #print("****************VARIABLE**********************") | |
908 | #-------------------------CAMBIOS RHI--------------------------------- |
|
909 | #-------------------------CAMBIOS RHI--------------------------------- | |
909 | #--------------------------------------------------------------------- |
|
910 | #--------------------------------------------------------------------- | |
910 | ##print("INPUT data_ele",data_ele) |
|
911 | ##print("INPUT data_ele",data_ele) | |
911 | flag=0 |
|
912 | flag=0 | |
912 | start_ele = self.res_ele[0] |
|
913 | start_ele = self.res_ele[0] | |
913 | tipo_case = self.check_case(data_ele,ang_max,ang_min) |
|
914 | tipo_case = self.check_case(data_ele,ang_max,ang_min) | |
914 | #print("TIPO DE DATA",tipo_case) |
|
915 | #print("TIPO DE DATA",tipo_case) | |
915 | #-----------new------------ |
|
916 | #-----------new------------ | |
916 | data_ele ,data_ele_old = self.globalCheckPED(data_ele,tipo_case) |
|
917 | data_ele ,data_ele_old = self.globalCheckPED(data_ele,tipo_case) | |
917 | data_weather = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) |
|
918 | data_weather = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) | |
918 |
|
919 | |||
919 | #-------------------------------NEW RHI ITERATIVO------------------------- |
|
920 | #-------------------------------NEW RHI ITERATIVO------------------------- | |
920 |
|
921 | |||
921 | if tipo_case==0 : # SUBIDA |
|
922 | if tipo_case==0 : # SUBIDA | |
922 | vec = numpy.where(data_ele<ang_max) |
|
923 | vec = numpy.where(data_ele<ang_max) | |
923 | data_ele = data_ele[vec] |
|
924 | data_ele = data_ele[vec] | |
924 | data_ele_old = data_ele_old[vec] |
|
925 | data_ele_old = data_ele_old[vec] | |
925 | data_weather = data_weather[vec[0]] |
|
926 | data_weather = data_weather[vec[0]] | |
926 |
|
927 | |||
927 | vec2 = numpy.where(0<data_ele) |
|
928 | vec2 = numpy.where(0<data_ele) | |
928 | data_ele= data_ele[vec2] |
|
929 | data_ele= data_ele[vec2] | |
929 | data_ele_old= data_ele_old[vec2] |
|
930 | data_ele_old= data_ele_old[vec2] | |
930 | ##print(data_ele_new) |
|
931 | ##print(data_ele_new) | |
931 | data_weather= data_weather[vec2[0]] |
|
932 | data_weather= data_weather[vec2[0]] | |
932 |
|
933 | |||
933 | new_i_ele = int(round(data_ele[0])) |
|
934 | new_i_ele = int(round(data_ele[0])) | |
934 | new_f_ele = int(round(data_ele[-1])) |
|
935 | new_f_ele = int(round(data_ele[-1])) | |
935 | #print(new_i_ele) |
|
936 | #print(new_i_ele) | |
936 | #print(new_f_ele) |
|
937 | #print(new_f_ele) | |
937 | #print(data_ele,len(data_ele)) |
|
938 | #print(data_ele,len(data_ele)) | |
938 | #print(data_ele_old,len(data_ele_old)) |
|
939 | #print(data_ele_old,len(data_ele_old)) | |
939 | if new_i_ele< 2: |
|
940 | if new_i_ele< 2: | |
940 | self.data_ele_tmp[val_ch] = numpy.ones(ang_max-ang_min)*numpy.nan |
|
941 | self.data_ele_tmp[val_ch] = numpy.ones(ang_max-ang_min)*numpy.nan | |
941 | self.res_weather[val_ch] = self.replaceNAN(data_weather=self.res_weather[val_ch],data_ele=self.data_ele_tmp[val_ch],val=self.val_mean) |
|
942 | self.res_weather[val_ch] = self.replaceNAN(data_weather=self.res_weather[val_ch],data_ele=self.data_ele_tmp[val_ch],val=self.val_mean) | |
942 | self.data_ele_tmp[val_ch][new_i_ele:new_i_ele+len(data_ele)]=data_ele_old |
|
943 | self.data_ele_tmp[val_ch][new_i_ele:new_i_ele+len(data_ele)]=data_ele_old | |
943 | self.res_ele[new_i_ele:new_i_ele+len(data_ele)]= data_ele |
|
944 | self.res_ele[new_i_ele:new_i_ele+len(data_ele)]= data_ele | |
944 | self.res_weather[val_ch][new_i_ele:new_i_ele+len(data_ele),:]= data_weather |
|
945 | self.res_weather[val_ch][new_i_ele:new_i_ele+len(data_ele),:]= data_weather | |
945 | data_ele = self.res_ele |
|
946 | data_ele = self.res_ele | |
946 | data_weather = self.res_weather[val_ch] |
|
947 | data_weather = self.res_weather[val_ch] | |
947 |
|
948 | |||
948 | elif tipo_case==1 : #BAJADA |
|
949 | elif tipo_case==1 : #BAJADA | |
949 | data_ele = data_ele[::-1] # reversa |
|
950 | data_ele = data_ele[::-1] # reversa | |
950 | data_ele_old = data_ele_old[::-1]# reversa |
|
951 | data_ele_old = data_ele_old[::-1]# reversa | |
951 | data_weather = data_weather[::-1,:]# reversa |
|
952 | data_weather = data_weather[::-1,:]# reversa | |
952 | vec= numpy.where(data_ele<ang_max) |
|
953 | vec= numpy.where(data_ele<ang_max) | |
953 | data_ele = data_ele[vec] |
|
954 | data_ele = data_ele[vec] | |
954 | data_ele_old = data_ele_old[vec] |
|
955 | data_ele_old = data_ele_old[vec] | |
955 | data_weather = data_weather[vec[0]] |
|
956 | data_weather = data_weather[vec[0]] | |
956 | vec2= numpy.where(0<data_ele) |
|
957 | vec2= numpy.where(0<data_ele) | |
957 | data_ele = data_ele[vec2] |
|
958 | data_ele = data_ele[vec2] | |
958 | data_ele_old = data_ele_old[vec2] |
|
959 | data_ele_old = data_ele_old[vec2] | |
959 | data_weather = data_weather[vec2[0]] |
|
960 | data_weather = data_weather[vec2[0]] | |
960 |
|
961 | |||
961 |
|
962 | |||
962 | new_i_ele = int(round(data_ele[0])) |
|
963 | new_i_ele = int(round(data_ele[0])) | |
963 | new_f_ele = int(round(data_ele[-1])) |
|
964 | new_f_ele = int(round(data_ele[-1])) | |
964 | #print(data_ele) |
|
965 | #print(data_ele) | |
965 | #print(ang_max) |
|
966 | #print(ang_max) | |
966 | #print(data_ele_old) |
|
967 | #print(data_ele_old) | |
967 | if new_i_ele <= 1: |
|
968 | if new_i_ele <= 1: | |
968 | new_i_ele = 1 |
|
969 | new_i_ele = 1 | |
969 | if round(data_ele[-1])>=ang_max-1: |
|
970 | if round(data_ele[-1])>=ang_max-1: | |
970 | self.data_ele_tmp[val_ch] = numpy.ones(ang_max-ang_min)*numpy.nan |
|
971 | self.data_ele_tmp[val_ch] = numpy.ones(ang_max-ang_min)*numpy.nan | |
971 | self.res_weather[val_ch] = self.replaceNAN(data_weather=self.res_weather[val_ch],data_ele=self.data_ele_tmp[val_ch],val=self.val_mean) |
|
972 | self.res_weather[val_ch] = self.replaceNAN(data_weather=self.res_weather[val_ch],data_ele=self.data_ele_tmp[val_ch],val=self.val_mean) | |
972 | self.data_ele_tmp[val_ch][new_i_ele-1:new_i_ele+len(data_ele)-1]=data_ele_old |
|
973 | self.data_ele_tmp[val_ch][new_i_ele-1:new_i_ele+len(data_ele)-1]=data_ele_old | |
973 | self.res_ele[new_i_ele-1:new_i_ele+len(data_ele)-1]= data_ele |
|
974 | self.res_ele[new_i_ele-1:new_i_ele+len(data_ele)-1]= data_ele | |
974 | self.res_weather[val_ch][new_i_ele-1:new_i_ele+len(data_ele)-1,:]= data_weather |
|
975 | self.res_weather[val_ch][new_i_ele-1:new_i_ele+len(data_ele)-1,:]= data_weather | |
975 | data_ele = self.res_ele |
|
976 | data_ele = self.res_ele | |
976 | data_weather = self.res_weather[val_ch] |
|
977 | data_weather = self.res_weather[val_ch] | |
977 |
|
978 | |||
978 | elif tipo_case==2: #bajada |
|
979 | elif tipo_case==2: #bajada | |
979 | vec = numpy.where(data_ele<ang_max) |
|
980 | vec = numpy.where(data_ele<ang_max) | |
980 | data_ele = data_ele[vec] |
|
981 | data_ele = data_ele[vec] | |
981 | data_weather= data_weather[vec[0]] |
|
982 | data_weather= data_weather[vec[0]] | |
982 |
|
983 | |||
983 | len_vec = len(vec) |
|
984 | len_vec = len(vec) | |
984 | data_ele_new = data_ele[::-1] # reversa |
|
985 | data_ele_new = data_ele[::-1] # reversa | |
985 | data_weather = data_weather[::-1,:] |
|
986 | data_weather = data_weather[::-1,:] | |
986 | new_i_ele = int(data_ele_new[0]) |
|
987 | new_i_ele = int(data_ele_new[0]) | |
987 | new_f_ele = int(data_ele_new[-1]) |
|
988 | new_f_ele = int(data_ele_new[-1]) | |
988 |
|
989 | |||
989 | n1= new_i_ele- ang_min |
|
990 | n1= new_i_ele- ang_min | |
990 | n2= ang_max - new_f_ele-1 |
|
991 | n2= ang_max - new_f_ele-1 | |
991 | if n1>0: |
|
992 | if n1>0: | |
992 | ele1= numpy.linspace(ang_min+1,new_i_ele-1,n1) |
|
993 | ele1= numpy.linspace(ang_min+1,new_i_ele-1,n1) | |
993 | ele1_nan= numpy.ones(n1)*numpy.nan |
|
994 | ele1_nan= numpy.ones(n1)*numpy.nan | |
994 | data_ele = numpy.hstack((ele1,data_ele_new)) |
|
995 | data_ele = numpy.hstack((ele1,data_ele_new)) | |
995 | data_ele_old = numpy.hstack((ele1_nan,data_ele_new)) |
|
996 | data_ele_old = numpy.hstack((ele1_nan,data_ele_new)) | |
996 | if n2>0: |
|
997 | if n2>0: | |
997 | ele2= numpy.linspace(new_f_ele+1,ang_max,n2) |
|
998 | ele2= numpy.linspace(new_f_ele+1,ang_max,n2) | |
998 | ele2_nan= numpy.ones(n2)*numpy.nan |
|
999 | ele2_nan= numpy.ones(n2)*numpy.nan | |
999 | data_ele = numpy.hstack((data_ele,ele2)) |
|
1000 | data_ele = numpy.hstack((data_ele,ele2)) | |
1000 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) |
|
1001 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) | |
1001 |
|
1002 | |||
1002 | self.data_ele_tmp[val_ch] = data_ele_old |
|
1003 | self.data_ele_tmp[val_ch] = data_ele_old | |
1003 | self.res_ele = data_ele |
|
1004 | self.res_ele = data_ele | |
1004 | self.res_weather[val_ch] = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) |
|
1005 | self.res_weather[val_ch] = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) | |
1005 | data_ele = self.res_ele |
|
1006 | data_ele = self.res_ele | |
1006 | data_weather = self.res_weather[val_ch] |
|
1007 | data_weather = self.res_weather[val_ch] | |
1007 |
|
1008 | |||
1008 | elif tipo_case==3:#subida |
|
1009 | elif tipo_case==3:#subida | |
1009 | vec = numpy.where(0<data_ele) |
|
1010 | vec = numpy.where(0<data_ele) | |
1010 | data_ele= data_ele[vec] |
|
1011 | data_ele= data_ele[vec] | |
1011 | data_ele_new = data_ele |
|
1012 | data_ele_new = data_ele | |
1012 | data_ele_old= data_ele_old[vec] |
|
1013 | data_ele_old= data_ele_old[vec] | |
1013 | data_weather= data_weather[vec[0]] |
|
1014 | data_weather= data_weather[vec[0]] | |
1014 | pos_ini = numpy.argmin(data_ele) |
|
1015 | pos_ini = numpy.argmin(data_ele) | |
1015 | if pos_ini>0: |
|
1016 | if pos_ini>0: | |
1016 | len_vec= len(data_ele) |
|
1017 | len_vec= len(data_ele) | |
1017 | vec3 = numpy.linspace(pos_ini,len_vec-1,len_vec-pos_ini).astype(int) |
|
1018 | vec3 = numpy.linspace(pos_ini,len_vec-1,len_vec-pos_ini).astype(int) | |
1018 | #print(vec3) |
|
1019 | #print(vec3) | |
1019 | data_ele= data_ele[vec3] |
|
1020 | data_ele= data_ele[vec3] | |
1020 | data_ele_new = data_ele |
|
1021 | data_ele_new = data_ele | |
1021 | data_ele_old= data_ele_old[vec3] |
|
1022 | data_ele_old= data_ele_old[vec3] | |
1022 | data_weather= data_weather[vec3] |
|
1023 | data_weather= data_weather[vec3] | |
1023 |
|
1024 | |||
1024 | new_i_ele = int(data_ele_new[0]) |
|
1025 | new_i_ele = int(data_ele_new[0]) | |
1025 | new_f_ele = int(data_ele_new[-1]) |
|
1026 | new_f_ele = int(data_ele_new[-1]) | |
1026 | n1= new_i_ele- ang_min |
|
1027 | n1= new_i_ele- ang_min | |
1027 | n2= ang_max - new_f_ele-1 |
|
1028 | n2= ang_max - new_f_ele-1 | |
1028 | if n1>0: |
|
1029 | if n1>0: | |
1029 | ele1= numpy.linspace(ang_min+1,new_i_ele-1,n1) |
|
1030 | ele1= numpy.linspace(ang_min+1,new_i_ele-1,n1) | |
1030 | ele1_nan= numpy.ones(n1)*numpy.nan |
|
1031 | ele1_nan= numpy.ones(n1)*numpy.nan | |
1031 | data_ele = numpy.hstack((ele1,data_ele_new)) |
|
1032 | data_ele = numpy.hstack((ele1,data_ele_new)) | |
1032 | data_ele_old = numpy.hstack((ele1_nan,data_ele_new)) |
|
1033 | data_ele_old = numpy.hstack((ele1_nan,data_ele_new)) | |
1033 | if n2>0: |
|
1034 | if n2>0: | |
1034 | ele2= numpy.linspace(new_f_ele+1,ang_max,n2) |
|
1035 | ele2= numpy.linspace(new_f_ele+1,ang_max,n2) | |
1035 | ele2_nan= numpy.ones(n2)*numpy.nan |
|
1036 | ele2_nan= numpy.ones(n2)*numpy.nan | |
1036 | data_ele = numpy.hstack((data_ele,ele2)) |
|
1037 | data_ele = numpy.hstack((data_ele,ele2)) | |
1037 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) |
|
1038 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) | |
1038 |
|
1039 | |||
1039 | self.data_ele_tmp[val_ch] = data_ele_old |
|
1040 | self.data_ele_tmp[val_ch] = data_ele_old | |
1040 | self.res_ele = data_ele |
|
1041 | self.res_ele = data_ele | |
1041 | self.res_weather[val_ch] = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) |
|
1042 | self.res_weather[val_ch] = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) | |
1042 | data_ele = self.res_ele |
|
1043 | data_ele = self.res_ele | |
1043 | data_weather = self.res_weather[val_ch] |
|
1044 | data_weather = self.res_weather[val_ch] | |
1044 | #print("self.data_ele_tmp",self.data_ele_tmp) |
|
1045 | #print("self.data_ele_tmp",self.data_ele_tmp) | |
1045 | return data_weather,data_ele |
|
1046 | return data_weather,data_ele | |
1046 |
|
1047 | |||
1047 |
|
1048 | |||
1048 | def plot(self): |
|
1049 | def plot(self): | |
1049 | thisDatetime = datetime.datetime.utcfromtimestamp(self.data.times[-1]).strftime('%Y-%m-%d %H:%M:%S') |
|
1050 | thisDatetime = datetime.datetime.utcfromtimestamp(self.data.times[-1]).strftime('%Y-%m-%d %H:%M:%S') | |
1050 | data = self.data[-1] |
|
1051 | data = self.data[-1] | |
1051 | r = self.data.yrange |
|
1052 | r = self.data.yrange | |
1052 | delta_height = r[1]-r[0] |
|
1053 | delta_height = r[1]-r[0] | |
1053 | r_mask = numpy.where(r>=0)[0] |
|
1054 | r_mask = numpy.where(r>=0)[0] | |
1054 | ##print("delta_height",delta_height) |
|
1055 | ##print("delta_height",delta_height) | |
1055 | #print("r_mask",r_mask,len(r_mask)) |
|
1056 | #print("r_mask",r_mask,len(r_mask)) | |
1056 | r = numpy.arange(len(r_mask))*delta_height |
|
1057 | r = numpy.arange(len(r_mask))*delta_height | |
1057 | self.y = 2*r |
|
1058 | self.y = 2*r | |
1058 | res = 1 |
|
1059 | res = 1 | |
1059 | ###print("data['weather'].shape[0]",data['weather'].shape[0]) |
|
1060 | ###print("data['weather'].shape[0]",data['weather'].shape[0]) | |
1060 | ang_max = self.ang_max |
|
1061 | ang_max = self.ang_max | |
1061 | ang_min = self.ang_min |
|
1062 | ang_min = self.ang_min | |
1062 | var_ang =ang_max - ang_min |
|
1063 | var_ang =ang_max - ang_min | |
1063 | step = (int(var_ang)/(res*data['weather'].shape[0])) |
|
1064 | step = (int(var_ang)/(res*data['weather'].shape[0])) | |
1064 | ###print("step",step) |
|
1065 | ###print("step",step) | |
1065 | #-------------------------------------------------------- |
|
1066 | #-------------------------------------------------------- | |
1066 | ##print('weather',data['weather'].shape) |
|
1067 | ##print('weather',data['weather'].shape) | |
1067 | ##print('ele',data['ele'].shape) |
|
1068 | ##print('ele',data['ele'].shape) | |
1068 |
|
1069 | |||
1069 | ###self.res_weather, self.res_ele = self.const_ploteo(data_weather=data['weather'][:,r_mask],data_ele=data['ele'],step=step,res=res,ang_max=ang_max,ang_min=ang_min) |
|
1070 | ###self.res_weather, self.res_ele = self.const_ploteo(data_weather=data['weather'][:,r_mask],data_ele=data['ele'],step=step,res=res,ang_max=ang_max,ang_min=ang_min) | |
1070 | ###self.res_azi = numpy.mean(data['azi']) |
|
1071 | ###self.res_azi = numpy.mean(data['azi']) | |
1071 | ###print("self.res_ele",self.res_ele) |
|
1072 | ###print("self.res_ele",self.res_ele) | |
1072 | plt.clf() |
|
1073 | plt.clf() | |
1073 | subplots = [121, 122] |
|
1074 | subplots = [121, 122] | |
1074 | if self.ini==0: |
|
1075 | if self.ini==0: | |
1075 | self.data_ele_tmp = numpy.ones([self.nplots,int(var_ang)])*numpy.nan |
|
1076 | self.data_ele_tmp = numpy.ones([self.nplots,int(var_ang)])*numpy.nan | |
1076 | self.res_weather= numpy.ones([self.nplots,int(var_ang),len(r_mask)])*numpy.nan |
|
1077 | self.res_weather= numpy.ones([self.nplots,int(var_ang),len(r_mask)])*numpy.nan | |
1077 | print("SHAPE",self.data_ele_tmp.shape) |
|
1078 | print("SHAPE",self.data_ele_tmp.shape) | |
1078 |
|
1079 | |||
1079 | for i,ax in enumerate(self.axes): |
|
1080 | for i,ax in enumerate(self.axes): | |
1080 | self.res_weather[i], self.res_ele = self.const_ploteo(val_ch=i, data_weather=data['weather'][i][:,r_mask],data_ele=data['ele'],step=step,res=res,ang_max=ang_max,ang_min=ang_min) |
|
1081 | self.res_weather[i], self.res_ele = self.const_ploteo(val_ch=i, data_weather=data['weather'][i][:,r_mask],data_ele=data['ele'],step=step,res=res,ang_max=ang_max,ang_min=ang_min) | |
1081 | self.res_azi = numpy.mean(data['azi']) |
|
1082 | self.res_azi = numpy.mean(data['azi']) | |
1082 | if i==0: |
|
1083 | if i==0: | |
1083 | print("*****************************************************************************to plot**************************",self.res_weather[i].shape) |
|
1084 | print("*****************************************************************************to plot**************************",self.res_weather[i].shape) | |
1084 | if ax.firsttime: |
|
1085 | if ax.firsttime: | |
1085 | #plt.clf() |
|
1086 | #plt.clf() | |
1086 | cgax, pm = wrl.vis.plot_rhi(self.res_weather[i],r=r,th=self.res_ele,ax=subplots[i], proj='cg',vmin=20, vmax=80) |
|
1087 | cgax, pm = wrl.vis.plot_rhi(self.res_weather[i],r=r,th=self.res_ele,ax=subplots[i], proj='cg',vmin=20, vmax=80) | |
1087 | #fig=self.figures[0] |
|
1088 | #fig=self.figures[0] | |
1088 | else: |
|
1089 | else: | |
1089 | #plt.clf() |
|
1090 | #plt.clf() | |
1090 | if i==0: |
|
1091 | if i==0: | |
1091 | print(self.res_weather[i]) |
|
1092 | print(self.res_weather[i]) | |
1092 | print(self.res_ele) |
|
1093 | print(self.res_ele) | |
1093 | cgax, pm = wrl.vis.plot_rhi(self.res_weather[i],r=r,th=self.res_ele,ax=subplots[i], proj='cg',vmin=20, vmax=80) |
|
1094 | cgax, pm = wrl.vis.plot_rhi(self.res_weather[i],r=r,th=self.res_ele,ax=subplots[i], proj='cg',vmin=20, vmax=80) | |
1094 | caax = cgax.parasites[0] |
|
1095 | caax = cgax.parasites[0] | |
1095 | paax = cgax.parasites[1] |
|
1096 | paax = cgax.parasites[1] | |
1096 | cbar = plt.gcf().colorbar(pm, pad=0.075) |
|
1097 | cbar = plt.gcf().colorbar(pm, pad=0.075) | |
1097 | caax.set_xlabel('x_range [km]') |
|
1098 | caax.set_xlabel('x_range [km]') | |
1098 | caax.set_ylabel('y_range [km]') |
|
1099 | caax.set_ylabel('y_range [km]') | |
1099 | plt.text(1.0, 1.05, 'Elevacion '+str(thisDatetime)+" Step "+str(self.ini)+ " Azi: "+str(round(self.res_azi,2)), transform=caax.transAxes, va='bottom',ha='right') |
|
1100 | plt.text(1.0, 1.05, 'Elevacion '+str(thisDatetime)+" Step "+str(self.ini)+ " Azi: "+str(round(self.res_azi,2)), transform=caax.transAxes, va='bottom',ha='right') | |
1100 | print("***************************self.ini****************************",self.ini) |
|
1101 | print("***************************self.ini****************************",self.ini) | |
1101 | self.ini= self.ini+1 |
|
1102 | self.ini= self.ini+1 | |
1102 |
|
1103 | |||
1103 | class WeatherRHI_vRF2_Plot(Plot): |
|
1104 | class WeatherRHI_vRF2_Plot(Plot): | |
1104 | CODE = 'weather' |
|
1105 | CODE = 'weather' | |
1105 | plot_name = 'weather' |
|
1106 | plot_name = 'weather' | |
1106 | plot_type = 'rhistyle' |
|
1107 | plot_type = 'rhistyle' | |
1107 | buffering = False |
|
1108 | buffering = False | |
1108 | data_ele_tmp = None |
|
1109 | data_ele_tmp = None | |
1109 |
|
1110 | |||
1110 | def setup(self): |
|
1111 | def setup(self): | |
1111 | print("********************") |
|
1112 | print("********************") | |
1112 | print("********************") |
|
1113 | print("********************") | |
1113 | print("********************") |
|
1114 | print("********************") | |
1114 | print("SETUP WEATHER PLOT") |
|
1115 | print("SETUP WEATHER PLOT") | |
1115 | self.ncols = 1 |
|
1116 | self.ncols = 1 | |
1116 | self.nrows = 1 |
|
1117 | self.nrows = 1 | |
1117 | self.nplots= 1 |
|
1118 | self.nplots= 1 | |
1118 | self.ylabel= 'Range [Km]' |
|
1119 | self.ylabel= 'Range [Km]' | |
1119 | self.titles= ['Weather'] |
|
1120 | self.titles= ['Weather'] | |
1120 | if self.channels is not None: |
|
1121 | if self.channels is not None: | |
1121 | self.nplots = len(self.channels) |
|
1122 | self.nplots = len(self.channels) | |
1122 | self.nrows = len(self.channels) |
|
1123 | self.nrows = len(self.channels) | |
1123 | else: |
|
1124 | else: | |
1124 | self.nplots = self.data.shape(self.CODE)[0] |
|
1125 | self.nplots = self.data.shape(self.CODE)[0] | |
1125 | self.nrows = self.nplots |
|
1126 | self.nrows = self.nplots | |
1126 | self.channels = list(range(self.nplots)) |
|
1127 | self.channels = list(range(self.nplots)) | |
1127 | print("channels",self.channels) |
|
1128 | print("channels",self.channels) | |
1128 | print("que saldra", self.data.shape(self.CODE)[0]) |
|
1129 | print("que saldra", self.data.shape(self.CODE)[0]) | |
1129 | self.titles = ['{} Channel {}'.format(self.CODE.upper(), x) for x in range(self.nrows)] |
|
1130 | self.titles = ['{} Channel {}'.format(self.CODE.upper(), x) for x in range(self.nrows)] | |
1130 | print("self.titles",self.titles) |
|
1131 | print("self.titles",self.titles) | |
1131 | self.colorbar=False |
|
1132 | self.colorbar=False | |
1132 | self.width =8 |
|
1133 | self.width =8 | |
1133 | self.height =8 |
|
1134 | self.height =8 | |
1134 | self.ini =0 |
|
1135 | self.ini =0 | |
1135 | self.len_azi =0 |
|
1136 | self.len_azi =0 | |
1136 | self.buffer_ini = None |
|
1137 | self.buffer_ini = None | |
1137 | self.buffer_ele = None |
|
1138 | self.buffer_ele = None | |
1138 | self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08}) |
|
1139 | self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08}) | |
1139 | self.flag =0 |
|
1140 | self.flag =0 | |
1140 | self.indicador= 0 |
|
1141 | self.indicador= 0 | |
1141 | self.last_data_ele = None |
|
1142 | self.last_data_ele = None | |
1142 | self.val_mean = None |
|
1143 | self.val_mean = None | |
1143 |
|
1144 | |||
1144 | def update(self, dataOut): |
|
1145 | def update(self, dataOut): | |
1145 |
|
1146 | |||
1146 | data = {} |
|
1147 | data = {} | |
1147 | meta = {} |
|
1148 | meta = {} | |
1148 | if hasattr(dataOut, 'dataPP_POWER'): |
|
1149 | if hasattr(dataOut, 'dataPP_POWER'): | |
1149 | factor = 1 |
|
1150 | factor = 1 | |
1150 | if hasattr(dataOut, 'nFFTPoints'): |
|
1151 | if hasattr(dataOut, 'nFFTPoints'): | |
1151 | factor = dataOut.normFactor |
|
1152 | factor = dataOut.normFactor | |
1152 | print("dataOut",dataOut.data_360.shape) |
|
1153 | print("dataOut",dataOut.data_360.shape) | |
1153 | # |
|
1154 | # | |
1154 | data['weather'] = 10*numpy.log10(dataOut.data_360/(factor)) |
|
1155 | data['weather'] = 10*numpy.log10(dataOut.data_360/(factor)) | |
1155 | # |
|
1156 | # | |
1156 | #data['weather'] = 10*numpy.log10(dataOut.data_360[1]/(factor)) |
|
1157 | #data['weather'] = 10*numpy.log10(dataOut.data_360[1]/(factor)) | |
1157 | data['azi'] = dataOut.data_azi |
|
1158 | data['azi'] = dataOut.data_azi | |
1158 | data['ele'] = dataOut.data_ele |
|
1159 | data['ele'] = dataOut.data_ele | |
1159 | data['case_flag'] = dataOut.case_flag |
|
1160 | data['case_flag'] = dataOut.case_flag | |
1160 | #print("UPDATE") |
|
1161 | #print("UPDATE") | |
1161 | #print("data[weather]",data['weather'].shape) |
|
1162 | #print("data[weather]",data['weather'].shape) | |
1162 | #print("data[azi]",data['azi']) |
|
1163 | #print("data[azi]",data['azi']) | |
1163 | return data, meta |
|
1164 | return data, meta | |
1164 |
|
1165 | |||
1165 | def get2List(self,angulos): |
|
1166 | def get2List(self,angulos): | |
1166 | list1=[] |
|
1167 | list1=[] | |
1167 | list2=[] |
|
1168 | list2=[] | |
1168 | for i in reversed(range(len(angulos))): |
|
1169 | for i in reversed(range(len(angulos))): | |
1169 | if not i==0:#el caso de i=0 evalula el primero de la lista con el ultimo y no es relevante |
|
1170 | if not i==0:#el caso de i=0 evalula el primero de la lista con el ultimo y no es relevante | |
1170 | diff_ = angulos[i]-angulos[i-1] |
|
1171 | diff_ = angulos[i]-angulos[i-1] | |
1171 | if abs(diff_) >1.5: |
|
1172 | if abs(diff_) >1.5: | |
1172 | list1.append(i-1) |
|
1173 | list1.append(i-1) | |
1173 | list2.append(diff_) |
|
1174 | list2.append(diff_) | |
1174 | return list(reversed(list1)),list(reversed(list2)) |
|
1175 | return list(reversed(list1)),list(reversed(list2)) | |
1175 |
|
1176 | |||
1176 | def fixData90(self,list_,ang_): |
|
1177 | def fixData90(self,list_,ang_): | |
1177 | if list_[0]==-1: |
|
1178 | if list_[0]==-1: | |
1178 | vec = numpy.where(ang_<ang_[0]) |
|
1179 | vec = numpy.where(ang_<ang_[0]) | |
1179 | ang_[vec] = ang_[vec]+90 |
|
1180 | ang_[vec] = ang_[vec]+90 | |
1180 | return ang_ |
|
1181 | return ang_ | |
1181 | return ang_ |
|
1182 | return ang_ | |
1182 |
|
1183 | |||
1183 | def fixData90HL(self,angulos): |
|
1184 | def fixData90HL(self,angulos): | |
1184 | vec = numpy.where(angulos>=90) |
|
1185 | vec = numpy.where(angulos>=90) | |
1185 | angulos[vec]=angulos[vec]-90 |
|
1186 | angulos[vec]=angulos[vec]-90 | |
1186 | return angulos |
|
1187 | return angulos | |
1187 |
|
1188 | |||
1188 |
|
1189 | |||
1189 | def search_pos(self,pos,list_): |
|
1190 | def search_pos(self,pos,list_): | |
1190 | for i in range(len(list_)): |
|
1191 | for i in range(len(list_)): | |
1191 | if pos == list_[i]: |
|
1192 | if pos == list_[i]: | |
1192 | return True,i |
|
1193 | return True,i | |
1193 | i=None |
|
1194 | i=None | |
1194 | return False,i |
|
1195 | return False,i | |
1195 |
|
1196 | |||
1196 | def fixDataComp(self,ang_,list1_,list2_,tipo_case): |
|
1197 | def fixDataComp(self,ang_,list1_,list2_,tipo_case): | |
1197 | size = len(ang_) |
|
1198 | size = len(ang_) | |
1198 | size2 = 0 |
|
1199 | size2 = 0 | |
1199 | for i in range(len(list2_)): |
|
1200 | for i in range(len(list2_)): | |
1200 | size2=size2+round(abs(list2_[i]))-1 |
|
1201 | size2=size2+round(abs(list2_[i]))-1 | |
1201 | new_size= size+size2 |
|
1202 | new_size= size+size2 | |
1202 | ang_new = numpy.zeros(new_size) |
|
1203 | ang_new = numpy.zeros(new_size) | |
1203 | ang_new2 = numpy.zeros(new_size) |
|
1204 | ang_new2 = numpy.zeros(new_size) | |
1204 |
|
1205 | |||
1205 | tmp = 0 |
|
1206 | tmp = 0 | |
1206 | c = 0 |
|
1207 | c = 0 | |
1207 | for i in range(len(ang_)): |
|
1208 | for i in range(len(ang_)): | |
1208 | ang_new[tmp +c] = ang_[i] |
|
1209 | ang_new[tmp +c] = ang_[i] | |
1209 | ang_new2[tmp+c] = ang_[i] |
|
1210 | ang_new2[tmp+c] = ang_[i] | |
1210 | condition , value = self.search_pos(i,list1_) |
|
1211 | condition , value = self.search_pos(i,list1_) | |
1211 | if condition: |
|
1212 | if condition: | |
1212 | pos = tmp + c + 1 |
|
1213 | pos = tmp + c + 1 | |
1213 | for k in range(round(abs(list2_[value]))-1): |
|
1214 | for k in range(round(abs(list2_[value]))-1): | |
1214 | if tipo_case==0 or tipo_case==3:#subida |
|
1215 | if tipo_case==0 or tipo_case==3:#subida | |
1215 | ang_new[pos+k] = ang_new[pos+k-1]+1 |
|
1216 | ang_new[pos+k] = ang_new[pos+k-1]+1 | |
1216 | ang_new2[pos+k] = numpy.nan |
|
1217 | ang_new2[pos+k] = numpy.nan | |
1217 | elif tipo_case==1 or tipo_case==2:#bajada |
|
1218 | elif tipo_case==1 or tipo_case==2:#bajada | |
1218 | ang_new[pos+k] = ang_new[pos+k-1]-1 |
|
1219 | ang_new[pos+k] = ang_new[pos+k-1]-1 | |
1219 | ang_new2[pos+k] = numpy.nan |
|
1220 | ang_new2[pos+k] = numpy.nan | |
1220 |
|
1221 | |||
1221 | tmp = pos +k |
|
1222 | tmp = pos +k | |
1222 | c = 0 |
|
1223 | c = 0 | |
1223 | c=c+1 |
|
1224 | c=c+1 | |
1224 | return ang_new,ang_new2 |
|
1225 | return ang_new,ang_new2 | |
1225 |
|
1226 | |||
1226 | def globalCheckPED(self,angulos,tipo_case): |
|
1227 | def globalCheckPED(self,angulos,tipo_case): | |
1227 | l1,l2 = self.get2List(angulos) |
|
1228 | l1,l2 = self.get2List(angulos) | |
1228 | ##print("l1",l1) |
|
1229 | ##print("l1",l1) | |
1229 | ##print("l2",l2) |
|
1230 | ##print("l2",l2) | |
1230 | if len(l1)>0: |
|
1231 | if len(l1)>0: | |
1231 | #angulos2 = self.fixData90(list_=l1,ang_=angulos) |
|
1232 | #angulos2 = self.fixData90(list_=l1,ang_=angulos) | |
1232 | #l1,l2 = self.get2List(angulos2) |
|
1233 | #l1,l2 = self.get2List(angulos2) | |
1233 | ang1_,ang2_ = self.fixDataComp(ang_=angulos,list1_=l1,list2_=l2,tipo_case=tipo_case) |
|
1234 | ang1_,ang2_ = self.fixDataComp(ang_=angulos,list1_=l1,list2_=l2,tipo_case=tipo_case) | |
1234 | #ang1_ = self.fixData90HL(ang1_) |
|
1235 | #ang1_ = self.fixData90HL(ang1_) | |
1235 | #ang2_ = self.fixData90HL(ang2_) |
|
1236 | #ang2_ = self.fixData90HL(ang2_) | |
1236 | else: |
|
1237 | else: | |
1237 | ang1_= angulos |
|
1238 | ang1_= angulos | |
1238 | ang2_= angulos |
|
1239 | ang2_= angulos | |
1239 | return ang1_,ang2_ |
|
1240 | return ang1_,ang2_ | |
1240 |
|
1241 | |||
1241 |
|
1242 | |||
1242 | def replaceNAN(self,data_weather,data_ele,val): |
|
1243 | def replaceNAN(self,data_weather,data_ele,val): | |
1243 | data= data_ele |
|
1244 | data= data_ele | |
1244 | data_T= data_weather |
|
1245 | data_T= data_weather | |
1245 | if data.shape[0]> data_T.shape[0]: |
|
1246 | if data.shape[0]> data_T.shape[0]: | |
1246 | data_N = numpy.ones( [data.shape[0],data_T.shape[1]]) |
|
1247 | data_N = numpy.ones( [data.shape[0],data_T.shape[1]]) | |
1247 | c = 0 |
|
1248 | c = 0 | |
1248 | for i in range(len(data)): |
|
1249 | for i in range(len(data)): | |
1249 | if numpy.isnan(data[i]): |
|
1250 | if numpy.isnan(data[i]): | |
1250 | data_N[i,:]=numpy.ones(data_T.shape[1])*numpy.nan |
|
1251 | data_N[i,:]=numpy.ones(data_T.shape[1])*numpy.nan | |
1251 | else: |
|
1252 | else: | |
1252 | data_N[i,:]=data_T[c,:] |
|
1253 | data_N[i,:]=data_T[c,:] | |
1253 | c=c+1 |
|
1254 | c=c+1 | |
1254 | return data_N |
|
1255 | return data_N | |
1255 | else: |
|
1256 | else: | |
1256 | for i in range(len(data)): |
|
1257 | for i in range(len(data)): | |
1257 | if numpy.isnan(data[i]): |
|
1258 | if numpy.isnan(data[i]): | |
1258 | data_T[i,:]=numpy.ones(data_T.shape[1])*numpy.nan |
|
1259 | data_T[i,:]=numpy.ones(data_T.shape[1])*numpy.nan | |
1259 | return data_T |
|
1260 | return data_T | |
1260 |
|
1261 | |||
1261 | def check_case(self,data_ele,ang_max,ang_min): |
|
1262 | def check_case(self,data_ele,ang_max,ang_min): | |
1262 | start = data_ele[0] |
|
1263 | start = data_ele[0] | |
1263 | end = data_ele[-1] |
|
1264 | end = data_ele[-1] | |
1264 | number = (end-start) |
|
1265 | number = (end-start) | |
1265 | len_ang=len(data_ele) |
|
1266 | len_ang=len(data_ele) | |
1266 | print("start",start) |
|
1267 | print("start",start) | |
1267 | print("end",end) |
|
1268 | print("end",end) | |
1268 | print("number",number) |
|
1269 | print("number",number) | |
1269 |
|
1270 | |||
1270 | print("len_ang",len_ang) |
|
1271 | print("len_ang",len_ang) | |
1271 |
|
1272 | |||
1272 | #exit(1) |
|
1273 | #exit(1) | |
1273 |
|
1274 | |||
1274 | if start<end and (round(abs(number)+1)>=len_ang or (numpy.argmin(data_ele)==0)):#caso subida |
|
1275 | if start<end and (round(abs(number)+1)>=len_ang or (numpy.argmin(data_ele)==0)):#caso subida | |
1275 | return 0 |
|
1276 | return 0 | |
1276 | #elif start>end and (round(abs(number)+1)>=len_ang or(numpy.argmax(data_ele)==0)):#caso bajada |
|
1277 | #elif start>end and (round(abs(number)+1)>=len_ang or(numpy.argmax(data_ele)==0)):#caso bajada | |
1277 | # return 1 |
|
1278 | # return 1 | |
1278 | elif round(abs(number)+1)>=len_ang and (start>end or(numpy.argmax(data_ele)==0)):#caso bajada |
|
1279 | elif round(abs(number)+1)>=len_ang and (start>end or(numpy.argmax(data_ele)==0)):#caso bajada | |
1279 | return 1 |
|
1280 | return 1 | |
1280 | elif round(abs(number)+1)<len_ang and data_ele[-2]>data_ele[-1]:# caso BAJADA CAMBIO ANG MAX |
|
1281 | elif round(abs(number)+1)<len_ang and data_ele[-2]>data_ele[-1]:# caso BAJADA CAMBIO ANG MAX | |
1281 | return 2 |
|
1282 | return 2 | |
1282 | elif round(abs(number)+1)<len_ang and data_ele[-2]<data_ele[-1] :# caso SUBIDA CAMBIO ANG MIN |
|
1283 | elif round(abs(number)+1)<len_ang and data_ele[-2]<data_ele[-1] :# caso SUBIDA CAMBIO ANG MIN | |
1283 | return 3 |
|
1284 | return 3 | |
1284 |
|
1285 | |||
1285 |
|
1286 | |||
1286 | def const_ploteo(self,val_ch,data_weather,data_ele,step,res,ang_max,ang_min,case_flag): |
|
1287 | def const_ploteo(self,val_ch,data_weather,data_ele,step,res,ang_max,ang_min,case_flag): | |
1287 | ang_max= ang_max |
|
1288 | ang_max= ang_max | |
1288 | ang_min= ang_min |
|
1289 | ang_min= ang_min | |
1289 | data_weather=data_weather |
|
1290 | data_weather=data_weather | |
1290 | val_ch=val_ch |
|
1291 | val_ch=val_ch | |
1291 | ##print("*********************DATA WEATHER**************************************") |
|
1292 | ##print("*********************DATA WEATHER**************************************") | |
1292 | ##print(data_weather) |
|
1293 | ##print(data_weather) | |
1293 | if self.ini==0: |
|
1294 | if self.ini==0: | |
1294 | ''' |
|
1295 | ''' | |
1295 | print("**********************************************") |
|
1296 | print("**********************************************") | |
1296 | print("**********************************************") |
|
1297 | print("**********************************************") | |
1297 | print("***************ini**************") |
|
1298 | print("***************ini**************") | |
1298 | print("**********************************************") |
|
1299 | print("**********************************************") | |
1299 | print("**********************************************") |
|
1300 | print("**********************************************") | |
1300 | ''' |
|
1301 | ''' | |
1301 | #print("data_ele",data_ele) |
|
1302 | #print("data_ele",data_ele) | |
1302 | #---------------------------------------------------------- |
|
1303 | #---------------------------------------------------------- | |
1303 | tipo_case = case_flag[-1] |
|
1304 | tipo_case = case_flag[-1] | |
1304 | #tipo_case = self.check_case(data_ele,ang_max,ang_min) |
|
1305 | #tipo_case = self.check_case(data_ele,ang_max,ang_min) | |
1305 | print("check_case",tipo_case) |
|
1306 | print("check_case",tipo_case) | |
1306 | #exit(1) |
|
1307 | #exit(1) | |
1307 | #--------------------- new ------------------------- |
|
1308 | #--------------------- new ------------------------- | |
1308 | data_ele_new ,data_ele_old= self.globalCheckPED(data_ele,tipo_case) |
|
1309 | data_ele_new ,data_ele_old= self.globalCheckPED(data_ele,tipo_case) | |
1309 |
|
1310 | |||
1310 | #-------------------------CAMBIOS RHI--------------------------------- |
|
1311 | #-------------------------CAMBIOS RHI--------------------------------- | |
1311 | start= ang_min |
|
1312 | start= ang_min | |
1312 | end = ang_max |
|
1313 | end = ang_max | |
1313 | n= (ang_max-ang_min)/res |
|
1314 | n= (ang_max-ang_min)/res | |
1314 | #------ new |
|
1315 | #------ new | |
1315 | self.start_data_ele = data_ele_new[0] |
|
1316 | self.start_data_ele = data_ele_new[0] | |
1316 | self.end_data_ele = data_ele_new[-1] |
|
1317 | self.end_data_ele = data_ele_new[-1] | |
1317 | if tipo_case==0 or tipo_case==3: # SUBIDA |
|
1318 | if tipo_case==0 or tipo_case==3: # SUBIDA | |
1318 | n1= round(self.start_data_ele)- start |
|
1319 | n1= round(self.start_data_ele)- start | |
1319 | n2= end - round(self.end_data_ele) |
|
1320 | n2= end - round(self.end_data_ele) | |
1320 | print(self.start_data_ele) |
|
1321 | print(self.start_data_ele) | |
1321 | print(self.end_data_ele) |
|
1322 | print(self.end_data_ele) | |
1322 | if n1>0: |
|
1323 | if n1>0: | |
1323 | ele1= numpy.linspace(ang_min+1,self.start_data_ele-1,n1) |
|
1324 | ele1= numpy.linspace(ang_min+1,self.start_data_ele-1,n1) | |
1324 | ele1_nan= numpy.ones(n1)*numpy.nan |
|
1325 | ele1_nan= numpy.ones(n1)*numpy.nan | |
1325 | data_ele = numpy.hstack((ele1,data_ele_new)) |
|
1326 | data_ele = numpy.hstack((ele1,data_ele_new)) | |
1326 | print("ele1_nan",ele1_nan.shape) |
|
1327 | print("ele1_nan",ele1_nan.shape) | |
1327 | print("data_ele_old",data_ele_old.shape) |
|
1328 | print("data_ele_old",data_ele_old.shape) | |
1328 | data_ele_old = numpy.hstack((ele1_nan,data_ele_old)) |
|
1329 | data_ele_old = numpy.hstack((ele1_nan,data_ele_old)) | |
1329 | if n2>0: |
|
1330 | if n2>0: | |
1330 | ele2= numpy.linspace(self.end_data_ele+1,end,n2) |
|
1331 | ele2= numpy.linspace(self.end_data_ele+1,end,n2) | |
1331 | ele2_nan= numpy.ones(n2)*numpy.nan |
|
1332 | ele2_nan= numpy.ones(n2)*numpy.nan | |
1332 | data_ele = numpy.hstack((data_ele,ele2)) |
|
1333 | data_ele = numpy.hstack((data_ele,ele2)) | |
1333 | print("ele2_nan",ele2_nan.shape) |
|
1334 | print("ele2_nan",ele2_nan.shape) | |
1334 | print("data_ele_old",data_ele_old.shape) |
|
1335 | print("data_ele_old",data_ele_old.shape) | |
1335 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) |
|
1336 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) | |
1336 |
|
1337 | |||
1337 | if tipo_case==1 or tipo_case==2: # BAJADA |
|
1338 | if tipo_case==1 or tipo_case==2: # BAJADA | |
1338 | data_ele_new = data_ele_new[::-1] # reversa |
|
1339 | data_ele_new = data_ele_new[::-1] # reversa | |
1339 | data_ele_old = data_ele_old[::-1]# reversa |
|
1340 | data_ele_old = data_ele_old[::-1]# reversa | |
1340 | data_weather = data_weather[::-1,:]# reversa |
|
1341 | data_weather = data_weather[::-1,:]# reversa | |
1341 | vec= numpy.where(data_ele_new<ang_max) |
|
1342 | vec= numpy.where(data_ele_new<ang_max) | |
1342 | data_ele_new = data_ele_new[vec] |
|
1343 | data_ele_new = data_ele_new[vec] | |
1343 | data_ele_old = data_ele_old[vec] |
|
1344 | data_ele_old = data_ele_old[vec] | |
1344 | data_weather = data_weather[vec[0]] |
|
1345 | data_weather = data_weather[vec[0]] | |
1345 | vec2= numpy.where(0<data_ele_new) |
|
1346 | vec2= numpy.where(0<data_ele_new) | |
1346 | data_ele_new = data_ele_new[vec2] |
|
1347 | data_ele_new = data_ele_new[vec2] | |
1347 | data_ele_old = data_ele_old[vec2] |
|
1348 | data_ele_old = data_ele_old[vec2] | |
1348 | data_weather = data_weather[vec2[0]] |
|
1349 | data_weather = data_weather[vec2[0]] | |
1349 | self.start_data_ele = data_ele_new[0] |
|
1350 | self.start_data_ele = data_ele_new[0] | |
1350 | self.end_data_ele = data_ele_new[-1] |
|
1351 | self.end_data_ele = data_ele_new[-1] | |
1351 |
|
1352 | |||
1352 | n1= round(self.start_data_ele)- start |
|
1353 | n1= round(self.start_data_ele)- start | |
1353 | n2= end - round(self.end_data_ele)-1 |
|
1354 | n2= end - round(self.end_data_ele)-1 | |
1354 | print(self.start_data_ele) |
|
1355 | print(self.start_data_ele) | |
1355 | print(self.end_data_ele) |
|
1356 | print(self.end_data_ele) | |
1356 | if n1>0: |
|
1357 | if n1>0: | |
1357 | ele1= numpy.linspace(ang_min+1,self.start_data_ele-1,n1) |
|
1358 | ele1= numpy.linspace(ang_min+1,self.start_data_ele-1,n1) | |
1358 | ele1_nan= numpy.ones(n1)*numpy.nan |
|
1359 | ele1_nan= numpy.ones(n1)*numpy.nan | |
1359 | data_ele = numpy.hstack((ele1,data_ele_new)) |
|
1360 | data_ele = numpy.hstack((ele1,data_ele_new)) | |
1360 | data_ele_old = numpy.hstack((ele1_nan,data_ele_old)) |
|
1361 | data_ele_old = numpy.hstack((ele1_nan,data_ele_old)) | |
1361 | if n2>0: |
|
1362 | if n2>0: | |
1362 | ele2= numpy.linspace(self.end_data_ele+1,end,n2) |
|
1363 | ele2= numpy.linspace(self.end_data_ele+1,end,n2) | |
1363 | ele2_nan= numpy.ones(n2)*numpy.nan |
|
1364 | ele2_nan= numpy.ones(n2)*numpy.nan | |
1364 | data_ele = numpy.hstack((data_ele,ele2)) |
|
1365 | data_ele = numpy.hstack((data_ele,ele2)) | |
1365 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) |
|
1366 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) | |
1366 | # RADAR |
|
1367 | # RADAR | |
1367 | # NOTA data_ele y data_weather es la variable que retorna |
|
1368 | # NOTA data_ele y data_weather es la variable que retorna | |
1368 | val_mean = numpy.mean(data_weather[:,-1]) |
|
1369 | val_mean = numpy.mean(data_weather[:,-1]) | |
1369 | self.val_mean = val_mean |
|
1370 | self.val_mean = val_mean | |
1370 | data_weather = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) |
|
1371 | data_weather = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) | |
1371 | print("eleold",data_ele_old) |
|
1372 | print("eleold",data_ele_old) | |
1372 | print(self.data_ele_tmp[val_ch]) |
|
1373 | print(self.data_ele_tmp[val_ch]) | |
1373 | print(data_ele_old.shape[0]) |
|
1374 | print(data_ele_old.shape[0]) | |
1374 | print(self.data_ele_tmp[val_ch].shape[0]) |
|
1375 | print(self.data_ele_tmp[val_ch].shape[0]) | |
1375 | if (data_ele_old.shape[0]==91 or self.data_ele_tmp[val_ch].shape[0]==91): |
|
1376 | if (data_ele_old.shape[0]==91 or self.data_ele_tmp[val_ch].shape[0]==91): | |
1376 | import sys |
|
1377 | import sys | |
1377 | print("EXIT",self.ini) |
|
1378 | print("EXIT",self.ini) | |
1378 |
|
1379 | |||
1379 | sys.exit(1) |
|
1380 | sys.exit(1) | |
1380 | self.data_ele_tmp[val_ch]= data_ele_old |
|
1381 | self.data_ele_tmp[val_ch]= data_ele_old | |
1381 | else: |
|
1382 | else: | |
1382 | #print("**********************************************") |
|
1383 | #print("**********************************************") | |
1383 | #print("****************VARIABLE**********************") |
|
1384 | #print("****************VARIABLE**********************") | |
1384 | #-------------------------CAMBIOS RHI--------------------------------- |
|
1385 | #-------------------------CAMBIOS RHI--------------------------------- | |
1385 | #--------------------------------------------------------------------- |
|
1386 | #--------------------------------------------------------------------- | |
1386 | ##print("INPUT data_ele",data_ele) |
|
1387 | ##print("INPUT data_ele",data_ele) | |
1387 | flag=0 |
|
1388 | flag=0 | |
1388 | start_ele = self.res_ele[0] |
|
1389 | start_ele = self.res_ele[0] | |
1389 | #tipo_case = self.check_case(data_ele,ang_max,ang_min) |
|
1390 | #tipo_case = self.check_case(data_ele,ang_max,ang_min) | |
1390 | tipo_case = case_flag[-1] |
|
1391 | tipo_case = case_flag[-1] | |
1391 | #print("TIPO DE DATA",tipo_case) |
|
1392 | #print("TIPO DE DATA",tipo_case) | |
1392 | #-----------new------------ |
|
1393 | #-----------new------------ | |
1393 | data_ele ,data_ele_old = self.globalCheckPED(data_ele,tipo_case) |
|
1394 | data_ele ,data_ele_old = self.globalCheckPED(data_ele,tipo_case) | |
1394 | data_weather = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) |
|
1395 | data_weather = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) | |
1395 |
|
1396 | |||
1396 | #-------------------------------NEW RHI ITERATIVO------------------------- |
|
1397 | #-------------------------------NEW RHI ITERATIVO------------------------- | |
1397 |
|
1398 | |||
1398 | if tipo_case==0 : # SUBIDA |
|
1399 | if tipo_case==0 : # SUBIDA | |
1399 | vec = numpy.where(data_ele<ang_max) |
|
1400 | vec = numpy.where(data_ele<ang_max) | |
1400 | data_ele = data_ele[vec] |
|
1401 | data_ele = data_ele[vec] | |
1401 | data_ele_old = data_ele_old[vec] |
|
1402 | data_ele_old = data_ele_old[vec] | |
1402 | data_weather = data_weather[vec[0]] |
|
1403 | data_weather = data_weather[vec[0]] | |
1403 |
|
1404 | |||
1404 | vec2 = numpy.where(0<data_ele) |
|
1405 | vec2 = numpy.where(0<data_ele) | |
1405 | data_ele= data_ele[vec2] |
|
1406 | data_ele= data_ele[vec2] | |
1406 | data_ele_old= data_ele_old[vec2] |
|
1407 | data_ele_old= data_ele_old[vec2] | |
1407 | ##print(data_ele_new) |
|
1408 | ##print(data_ele_new) | |
1408 | data_weather= data_weather[vec2[0]] |
|
1409 | data_weather= data_weather[vec2[0]] | |
1409 |
|
1410 | |||
1410 | new_i_ele = int(round(data_ele[0])) |
|
1411 | new_i_ele = int(round(data_ele[0])) | |
1411 | new_f_ele = int(round(data_ele[-1])) |
|
1412 | new_f_ele = int(round(data_ele[-1])) | |
1412 | #print(new_i_ele) |
|
1413 | #print(new_i_ele) | |
1413 | #print(new_f_ele) |
|
1414 | #print(new_f_ele) | |
1414 | #print(data_ele,len(data_ele)) |
|
1415 | #print(data_ele,len(data_ele)) | |
1415 | #print(data_ele_old,len(data_ele_old)) |
|
1416 | #print(data_ele_old,len(data_ele_old)) | |
1416 | if new_i_ele< 2: |
|
1417 | if new_i_ele< 2: | |
1417 | self.data_ele_tmp[val_ch] = numpy.ones(ang_max-ang_min)*numpy.nan |
|
1418 | self.data_ele_tmp[val_ch] = numpy.ones(ang_max-ang_min)*numpy.nan | |
1418 | self.res_weather[val_ch] = self.replaceNAN(data_weather=self.res_weather[val_ch],data_ele=self.data_ele_tmp[val_ch],val=self.val_mean) |
|
1419 | self.res_weather[val_ch] = self.replaceNAN(data_weather=self.res_weather[val_ch],data_ele=self.data_ele_tmp[val_ch],val=self.val_mean) | |
1419 | self.data_ele_tmp[val_ch][new_i_ele:new_i_ele+len(data_ele)]=data_ele_old |
|
1420 | self.data_ele_tmp[val_ch][new_i_ele:new_i_ele+len(data_ele)]=data_ele_old | |
1420 | self.res_ele[new_i_ele:new_i_ele+len(data_ele)]= data_ele |
|
1421 | self.res_ele[new_i_ele:new_i_ele+len(data_ele)]= data_ele | |
1421 | self.res_weather[val_ch][new_i_ele:new_i_ele+len(data_ele),:]= data_weather |
|
1422 | self.res_weather[val_ch][new_i_ele:new_i_ele+len(data_ele),:]= data_weather | |
1422 | data_ele = self.res_ele |
|
1423 | data_ele = self.res_ele | |
1423 | data_weather = self.res_weather[val_ch] |
|
1424 | data_weather = self.res_weather[val_ch] | |
1424 |
|
1425 | |||
1425 | elif tipo_case==1 : #BAJADA |
|
1426 | elif tipo_case==1 : #BAJADA | |
1426 | data_ele = data_ele[::-1] # reversa |
|
1427 | data_ele = data_ele[::-1] # reversa | |
1427 | data_ele_old = data_ele_old[::-1]# reversa |
|
1428 | data_ele_old = data_ele_old[::-1]# reversa | |
1428 | data_weather = data_weather[::-1,:]# reversa |
|
1429 | data_weather = data_weather[::-1,:]# reversa | |
1429 | vec= numpy.where(data_ele<ang_max) |
|
1430 | vec= numpy.where(data_ele<ang_max) | |
1430 | data_ele = data_ele[vec] |
|
1431 | data_ele = data_ele[vec] | |
1431 | data_ele_old = data_ele_old[vec] |
|
1432 | data_ele_old = data_ele_old[vec] | |
1432 | data_weather = data_weather[vec[0]] |
|
1433 | data_weather = data_weather[vec[0]] | |
1433 | vec2= numpy.where(0<data_ele) |
|
1434 | vec2= numpy.where(0<data_ele) | |
1434 | data_ele = data_ele[vec2] |
|
1435 | data_ele = data_ele[vec2] | |
1435 | data_ele_old = data_ele_old[vec2] |
|
1436 | data_ele_old = data_ele_old[vec2] | |
1436 | data_weather = data_weather[vec2[0]] |
|
1437 | data_weather = data_weather[vec2[0]] | |
1437 |
|
1438 | |||
1438 |
|
1439 | |||
1439 | new_i_ele = int(round(data_ele[0])) |
|
1440 | new_i_ele = int(round(data_ele[0])) | |
1440 | new_f_ele = int(round(data_ele[-1])) |
|
1441 | new_f_ele = int(round(data_ele[-1])) | |
1441 | #print(data_ele) |
|
1442 | #print(data_ele) | |
1442 | #print(ang_max) |
|
1443 | #print(ang_max) | |
1443 | #print(data_ele_old) |
|
1444 | #print(data_ele_old) | |
1444 | if new_i_ele <= 1: |
|
1445 | if new_i_ele <= 1: | |
1445 | new_i_ele = 1 |
|
1446 | new_i_ele = 1 | |
1446 | if round(data_ele[-1])>=ang_max-1: |
|
1447 | if round(data_ele[-1])>=ang_max-1: | |
1447 | self.data_ele_tmp[val_ch] = numpy.ones(ang_max-ang_min)*numpy.nan |
|
1448 | self.data_ele_tmp[val_ch] = numpy.ones(ang_max-ang_min)*numpy.nan | |
1448 | self.res_weather[val_ch] = self.replaceNAN(data_weather=self.res_weather[val_ch],data_ele=self.data_ele_tmp[val_ch],val=self.val_mean) |
|
1449 | self.res_weather[val_ch] = self.replaceNAN(data_weather=self.res_weather[val_ch],data_ele=self.data_ele_tmp[val_ch],val=self.val_mean) | |
1449 | self.data_ele_tmp[val_ch][new_i_ele-1:new_i_ele+len(data_ele)-1]=data_ele_old |
|
1450 | self.data_ele_tmp[val_ch][new_i_ele-1:new_i_ele+len(data_ele)-1]=data_ele_old | |
1450 | self.res_ele[new_i_ele-1:new_i_ele+len(data_ele)-1]= data_ele |
|
1451 | self.res_ele[new_i_ele-1:new_i_ele+len(data_ele)-1]= data_ele | |
1451 | self.res_weather[val_ch][new_i_ele-1:new_i_ele+len(data_ele)-1,:]= data_weather |
|
1452 | self.res_weather[val_ch][new_i_ele-1:new_i_ele+len(data_ele)-1,:]= data_weather | |
1452 | data_ele = self.res_ele |
|
1453 | data_ele = self.res_ele | |
1453 | data_weather = self.res_weather[val_ch] |
|
1454 | data_weather = self.res_weather[val_ch] | |
1454 |
|
1455 | |||
1455 | elif tipo_case==2: #bajada |
|
1456 | elif tipo_case==2: #bajada | |
1456 | vec = numpy.where(data_ele<ang_max) |
|
1457 | vec = numpy.where(data_ele<ang_max) | |
1457 | data_ele = data_ele[vec] |
|
1458 | data_ele = data_ele[vec] | |
1458 | data_weather= data_weather[vec[0]] |
|
1459 | data_weather= data_weather[vec[0]] | |
1459 |
|
1460 | |||
1460 | len_vec = len(vec) |
|
1461 | len_vec = len(vec) | |
1461 | data_ele_new = data_ele[::-1] # reversa |
|
1462 | data_ele_new = data_ele[::-1] # reversa | |
1462 | data_weather = data_weather[::-1,:] |
|
1463 | data_weather = data_weather[::-1,:] | |
1463 | new_i_ele = int(data_ele_new[0]) |
|
1464 | new_i_ele = int(data_ele_new[0]) | |
1464 | new_f_ele = int(data_ele_new[-1]) |
|
1465 | new_f_ele = int(data_ele_new[-1]) | |
1465 |
|
1466 | |||
1466 | n1= new_i_ele- ang_min |
|
1467 | n1= new_i_ele- ang_min | |
1467 | n2= ang_max - new_f_ele-1 |
|
1468 | n2= ang_max - new_f_ele-1 | |
1468 | if n1>0: |
|
1469 | if n1>0: | |
1469 | ele1= numpy.linspace(ang_min+1,new_i_ele-1,n1) |
|
1470 | ele1= numpy.linspace(ang_min+1,new_i_ele-1,n1) | |
1470 | ele1_nan= numpy.ones(n1)*numpy.nan |
|
1471 | ele1_nan= numpy.ones(n1)*numpy.nan | |
1471 | data_ele = numpy.hstack((ele1,data_ele_new)) |
|
1472 | data_ele = numpy.hstack((ele1,data_ele_new)) | |
1472 | data_ele_old = numpy.hstack((ele1_nan,data_ele_new)) |
|
1473 | data_ele_old = numpy.hstack((ele1_nan,data_ele_new)) | |
1473 | if n2>0: |
|
1474 | if n2>0: | |
1474 | ele2= numpy.linspace(new_f_ele+1,ang_max,n2) |
|
1475 | ele2= numpy.linspace(new_f_ele+1,ang_max,n2) | |
1475 | ele2_nan= numpy.ones(n2)*numpy.nan |
|
1476 | ele2_nan= numpy.ones(n2)*numpy.nan | |
1476 | data_ele = numpy.hstack((data_ele,ele2)) |
|
1477 | data_ele = numpy.hstack((data_ele,ele2)) | |
1477 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) |
|
1478 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) | |
1478 |
|
1479 | |||
1479 | self.data_ele_tmp[val_ch] = data_ele_old |
|
1480 | self.data_ele_tmp[val_ch] = data_ele_old | |
1480 | self.res_ele = data_ele |
|
1481 | self.res_ele = data_ele | |
1481 | self.res_weather[val_ch] = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) |
|
1482 | self.res_weather[val_ch] = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) | |
1482 | data_ele = self.res_ele |
|
1483 | data_ele = self.res_ele | |
1483 | data_weather = self.res_weather[val_ch] |
|
1484 | data_weather = self.res_weather[val_ch] | |
1484 |
|
1485 | |||
1485 | elif tipo_case==3:#subida |
|
1486 | elif tipo_case==3:#subida | |
1486 | vec = numpy.where(0<data_ele) |
|
1487 | vec = numpy.where(0<data_ele) | |
1487 | data_ele= data_ele[vec] |
|
1488 | data_ele= data_ele[vec] | |
1488 | data_ele_new = data_ele |
|
1489 | data_ele_new = data_ele | |
1489 | data_ele_old= data_ele_old[vec] |
|
1490 | data_ele_old= data_ele_old[vec] | |
1490 | data_weather= data_weather[vec[0]] |
|
1491 | data_weather= data_weather[vec[0]] | |
1491 | pos_ini = numpy.argmin(data_ele) |
|
1492 | pos_ini = numpy.argmin(data_ele) | |
1492 | if pos_ini>0: |
|
1493 | if pos_ini>0: | |
1493 | len_vec= len(data_ele) |
|
1494 | len_vec= len(data_ele) | |
1494 | vec3 = numpy.linspace(pos_ini,len_vec-1,len_vec-pos_ini).astype(int) |
|
1495 | vec3 = numpy.linspace(pos_ini,len_vec-1,len_vec-pos_ini).astype(int) | |
1495 | #print(vec3) |
|
1496 | #print(vec3) | |
1496 | data_ele= data_ele[vec3] |
|
1497 | data_ele= data_ele[vec3] | |
1497 | data_ele_new = data_ele |
|
1498 | data_ele_new = data_ele | |
1498 | data_ele_old= data_ele_old[vec3] |
|
1499 | data_ele_old= data_ele_old[vec3] | |
1499 | data_weather= data_weather[vec3] |
|
1500 | data_weather= data_weather[vec3] | |
1500 |
|
1501 | |||
1501 | new_i_ele = int(data_ele_new[0]) |
|
1502 | new_i_ele = int(data_ele_new[0]) | |
1502 | new_f_ele = int(data_ele_new[-1]) |
|
1503 | new_f_ele = int(data_ele_new[-1]) | |
1503 | n1= new_i_ele- ang_min |
|
1504 | n1= new_i_ele- ang_min | |
1504 | n2= ang_max - new_f_ele-1 |
|
1505 | n2= ang_max - new_f_ele-1 | |
1505 | if n1>0: |
|
1506 | if n1>0: | |
1506 | ele1= numpy.linspace(ang_min+1,new_i_ele-1,n1) |
|
1507 | ele1= numpy.linspace(ang_min+1,new_i_ele-1,n1) | |
1507 | ele1_nan= numpy.ones(n1)*numpy.nan |
|
1508 | ele1_nan= numpy.ones(n1)*numpy.nan | |
1508 | data_ele = numpy.hstack((ele1,data_ele_new)) |
|
1509 | data_ele = numpy.hstack((ele1,data_ele_new)) | |
1509 | data_ele_old = numpy.hstack((ele1_nan,data_ele_new)) |
|
1510 | data_ele_old = numpy.hstack((ele1_nan,data_ele_new)) | |
1510 | if n2>0: |
|
1511 | if n2>0: | |
1511 | ele2= numpy.linspace(new_f_ele+1,ang_max,n2) |
|
1512 | ele2= numpy.linspace(new_f_ele+1,ang_max,n2) | |
1512 | ele2_nan= numpy.ones(n2)*numpy.nan |
|
1513 | ele2_nan= numpy.ones(n2)*numpy.nan | |
1513 | data_ele = numpy.hstack((data_ele,ele2)) |
|
1514 | data_ele = numpy.hstack((data_ele,ele2)) | |
1514 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) |
|
1515 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) | |
1515 |
|
1516 | |||
1516 | self.data_ele_tmp[val_ch] = data_ele_old |
|
1517 | self.data_ele_tmp[val_ch] = data_ele_old | |
1517 | self.res_ele = data_ele |
|
1518 | self.res_ele = data_ele | |
1518 | self.res_weather[val_ch] = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) |
|
1519 | self.res_weather[val_ch] = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) | |
1519 | data_ele = self.res_ele |
|
1520 | data_ele = self.res_ele | |
1520 | data_weather = self.res_weather[val_ch] |
|
1521 | data_weather = self.res_weather[val_ch] | |
1521 | #print("self.data_ele_tmp",self.data_ele_tmp) |
|
1522 | #print("self.data_ele_tmp",self.data_ele_tmp) | |
1522 | return data_weather,data_ele |
|
1523 | return data_weather,data_ele | |
1523 |
|
1524 | |||
1524 |
|
1525 | |||
1525 | def plot(self): |
|
1526 | def plot(self): | |
1526 | thisDatetime = datetime.datetime.utcfromtimestamp(self.data.times[-1]).strftime('%Y-%m-%d %H:%M:%S') |
|
1527 | thisDatetime = datetime.datetime.utcfromtimestamp(self.data.times[-1]).strftime('%Y-%m-%d %H:%M:%S') | |
1527 | data = self.data[-1] |
|
1528 | data = self.data[-1] | |
1528 | r = self.data.yrange |
|
1529 | r = self.data.yrange | |
1529 | delta_height = r[1]-r[0] |
|
1530 | delta_height = r[1]-r[0] | |
1530 | r_mask = numpy.where(r>=0)[0] |
|
1531 | r_mask = numpy.where(r>=0)[0] | |
1531 | ##print("delta_height",delta_height) |
|
1532 | ##print("delta_height",delta_height) | |
1532 | #print("r_mask",r_mask,len(r_mask)) |
|
1533 | #print("r_mask",r_mask,len(r_mask)) | |
1533 | r = numpy.arange(len(r_mask))*delta_height |
|
1534 | r = numpy.arange(len(r_mask))*delta_height | |
1534 | self.y = 2*r |
|
1535 | self.y = 2*r | |
1535 | res = 1 |
|
1536 | res = 1 | |
1536 | ###print("data['weather'].shape[0]",data['weather'].shape[0]) |
|
1537 | ###print("data['weather'].shape[0]",data['weather'].shape[0]) | |
1537 | ang_max = self.ang_max |
|
1538 | ang_max = self.ang_max | |
1538 | ang_min = self.ang_min |
|
1539 | ang_min = self.ang_min | |
1539 | var_ang =ang_max - ang_min |
|
1540 | var_ang =ang_max - ang_min | |
1540 | step = (int(var_ang)/(res*data['weather'].shape[0])) |
|
1541 | step = (int(var_ang)/(res*data['weather'].shape[0])) | |
1541 | ###print("step",step) |
|
1542 | ###print("step",step) | |
1542 | #-------------------------------------------------------- |
|
1543 | #-------------------------------------------------------- | |
1543 | ##print('weather',data['weather'].shape) |
|
1544 | ##print('weather',data['weather'].shape) | |
1544 | ##print('ele',data['ele'].shape) |
|
1545 | ##print('ele',data['ele'].shape) | |
1545 |
|
1546 | |||
1546 | ###self.res_weather, self.res_ele = self.const_ploteo(data_weather=data['weather'][:,r_mask],data_ele=data['ele'],step=step,res=res,ang_max=ang_max,ang_min=ang_min) |
|
1547 | ###self.res_weather, self.res_ele = self.const_ploteo(data_weather=data['weather'][:,r_mask],data_ele=data['ele'],step=step,res=res,ang_max=ang_max,ang_min=ang_min) | |
1547 | ###self.res_azi = numpy.mean(data['azi']) |
|
1548 | ###self.res_azi = numpy.mean(data['azi']) | |
1548 | ###print("self.res_ele",self.res_ele) |
|
1549 | ###print("self.res_ele",self.res_ele) | |
1549 | plt.clf() |
|
1550 | plt.clf() | |
1550 | subplots = [121, 122] |
|
1551 | subplots = [121, 122] | |
1551 | try: |
|
1552 | try: | |
1552 | if self.data[-2]['ele'].max()<data['ele'].max(): |
|
1553 | if self.data[-2]['ele'].max()<data['ele'].max(): | |
1553 | self.ini=0 |
|
1554 | self.ini=0 | |
1554 | except: |
|
1555 | except: | |
1555 | pass |
|
1556 | pass | |
1556 | if self.ini==0: |
|
1557 | if self.ini==0: | |
1557 | self.data_ele_tmp = numpy.ones([self.nplots,int(var_ang)])*numpy.nan |
|
1558 | self.data_ele_tmp = numpy.ones([self.nplots,int(var_ang)])*numpy.nan | |
1558 | self.res_weather= numpy.ones([self.nplots,int(var_ang),len(r_mask)])*numpy.nan |
|
1559 | self.res_weather= numpy.ones([self.nplots,int(var_ang),len(r_mask)])*numpy.nan | |
1559 | print("SHAPE",self.data_ele_tmp.shape) |
|
1560 | print("SHAPE",self.data_ele_tmp.shape) | |
1560 |
|
1561 | |||
1561 | for i,ax in enumerate(self.axes): |
|
1562 | for i,ax in enumerate(self.axes): | |
1562 | self.res_weather[i], self.res_ele = self.const_ploteo(val_ch=i, data_weather=data['weather'][i][:,r_mask],data_ele=data['ele'],step=step,res=res,ang_max=ang_max,ang_min=ang_min,case_flag=self.data['case_flag']) |
|
1563 | self.res_weather[i], self.res_ele = self.const_ploteo(val_ch=i, data_weather=data['weather'][i][:,r_mask],data_ele=data['ele'],step=step,res=res,ang_max=ang_max,ang_min=ang_min,case_flag=self.data['case_flag']) | |
1563 | self.res_azi = numpy.mean(data['azi']) |
|
1564 | self.res_azi = numpy.mean(data['azi']) | |
1564 |
|
1565 | |||
1565 | if ax.firsttime: |
|
1566 | if ax.firsttime: | |
1566 | #plt.clf() |
|
1567 | #plt.clf() | |
1567 | print("Frist Plot") |
|
1568 | print("Frist Plot") | |
1568 | cgax, pm = wrl.vis.plot_rhi(self.res_weather[i],r=r,th=self.res_ele,ax=subplots[i], proj='cg',vmin=20, vmax=80) |
|
1569 | cgax, pm = wrl.vis.plot_rhi(self.res_weather[i],r=r,th=self.res_ele,ax=subplots[i], proj='cg',vmin=20, vmax=80) | |
1569 | #fig=self.figures[0] |
|
1570 | #fig=self.figures[0] | |
1570 | else: |
|
1571 | else: | |
1571 | #plt.clf() |
|
1572 | #plt.clf() | |
1572 | print("ELSE PLOT") |
|
1573 | print("ELSE PLOT") | |
1573 | cgax, pm = wrl.vis.plot_rhi(self.res_weather[i],r=r,th=self.res_ele,ax=subplots[i], proj='cg',vmin=20, vmax=80) |
|
1574 | cgax, pm = wrl.vis.plot_rhi(self.res_weather[i],r=r,th=self.res_ele,ax=subplots[i], proj='cg',vmin=20, vmax=80) | |
1574 | caax = cgax.parasites[0] |
|
1575 | caax = cgax.parasites[0] | |
1575 | paax = cgax.parasites[1] |
|
1576 | paax = cgax.parasites[1] | |
1576 | cbar = plt.gcf().colorbar(pm, pad=0.075) |
|
1577 | cbar = plt.gcf().colorbar(pm, pad=0.075) | |
1577 | caax.set_xlabel('x_range [km]') |
|
1578 | caax.set_xlabel('x_range [km]') | |
1578 | caax.set_ylabel('y_range [km]') |
|
1579 | caax.set_ylabel('y_range [km]') | |
1579 | plt.text(1.0, 1.05, 'Elevacion '+str(thisDatetime)+" Step "+str(self.ini)+ " Azi: "+str(round(self.res_azi,2)), transform=caax.transAxes, va='bottom',ha='right') |
|
1580 | plt.text(1.0, 1.05, 'Elevacion '+str(thisDatetime)+" Step "+str(self.ini)+ " Azi: "+str(round(self.res_azi,2)), transform=caax.transAxes, va='bottom',ha='right') | |
1580 | print("***************************self.ini****************************",self.ini) |
|
1581 | print("***************************self.ini****************************",self.ini) | |
1581 | self.ini= self.ini+1 |
|
1582 | self.ini= self.ini+1 | |
1582 |
|
1583 | |||
1583 | class WeatherRHI_vRF_Plot(Plot): |
|
1584 | class WeatherRHI_vRF_Plot(Plot): | |
1584 | CODE = 'weather' |
|
1585 | CODE = 'weather' | |
1585 | plot_name = 'weather' |
|
1586 | plot_name = 'weather' | |
1586 | plot_type = 'rhistyle' |
|
1587 | plot_type = 'rhistyle' | |
1587 | buffering = False |
|
1588 | buffering = False | |
1588 | data_ele_tmp = None |
|
1589 | data_ele_tmp = None | |
1589 |
|
1590 | |||
1590 | def setup(self): |
|
1591 | def setup(self): | |
1591 | print("********************") |
|
1592 | print("********************") | |
1592 | print("********************") |
|
1593 | print("********************") | |
1593 | print("********************") |
|
1594 | print("********************") | |
1594 | print("SETUP WEATHER PLOT") |
|
1595 | print("SETUP WEATHER PLOT") | |
1595 | self.ncols = 1 |
|
1596 | self.ncols = 1 | |
1596 | self.nrows = 1 |
|
1597 | self.nrows = 1 | |
1597 | self.nplots= 1 |
|
1598 | self.nplots= 1 | |
1598 | self.ylabel= 'Range [Km]' |
|
1599 | self.ylabel= 'Range [Km]' | |
1599 | self.titles= ['Weather'] |
|
1600 | self.titles= ['Weather'] | |
1600 | if self.channels is not None: |
|
1601 | if self.channels is not None: | |
1601 | self.nplots = len(self.channels) |
|
1602 | self.nplots = len(self.channels) | |
1602 | self.nrows = len(self.channels) |
|
1603 | self.nrows = len(self.channels) | |
1603 | else: |
|
1604 | else: | |
1604 | self.nplots = self.data.shape(self.CODE)[0] |
|
1605 | self.nplots = self.data.shape(self.CODE)[0] | |
1605 | self.nrows = self.nplots |
|
1606 | self.nrows = self.nplots | |
1606 | self.channels = list(range(self.nplots)) |
|
1607 | self.channels = list(range(self.nplots)) | |
1607 | print("channels",self.channels) |
|
1608 | print("channels",self.channels) | |
1608 | print("que saldra", self.data.shape(self.CODE)[0]) |
|
1609 | print("que saldra", self.data.shape(self.CODE)[0]) | |
1609 | self.titles = ['{} Channel {}'.format(self.CODE.upper(), x) for x in range(self.nrows)] |
|
1610 | self.titles = ['{} Channel {}'.format(self.CODE.upper(), x) for x in range(self.nrows)] | |
1610 | print("self.titles",self.titles) |
|
1611 | print("self.titles",self.titles) | |
1611 | self.colorbar=False |
|
1612 | self.colorbar=False | |
1612 | self.width =8 |
|
1613 | self.width =8 | |
1613 | self.height =8 |
|
1614 | self.height =8 | |
1614 | self.ini =0 |
|
1615 | self.ini =0 | |
1615 | self.len_azi =0 |
|
1616 | self.len_azi =0 | |
1616 | self.buffer_ini = None |
|
1617 | self.buffer_ini = None | |
1617 | self.buffer_ele = None |
|
1618 | self.buffer_ele = None | |
1618 | self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08}) |
|
1619 | self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08}) | |
1619 | self.flag =0 |
|
1620 | self.flag =0 | |
1620 | self.indicador= 0 |
|
1621 | self.indicador= 0 | |
1621 | self.last_data_ele = None |
|
1622 | self.last_data_ele = None | |
1622 | self.val_mean = None |
|
1623 | self.val_mean = None | |
1623 |
|
1624 | |||
1624 | def update(self, dataOut): |
|
1625 | def update(self, dataOut): | |
1625 |
|
1626 | |||
1626 | data = {} |
|
1627 | data = {} | |
1627 | meta = {} |
|
1628 | meta = {} | |
1628 | if hasattr(dataOut, 'dataPP_POWER'): |
|
1629 | if hasattr(dataOut, 'dataPP_POWER'): | |
1629 | factor = 1 |
|
1630 | factor = 1 | |
1630 | if hasattr(dataOut, 'nFFTPoints'): |
|
1631 | if hasattr(dataOut, 'nFFTPoints'): | |
1631 | factor = dataOut.normFactor |
|
1632 | factor = dataOut.normFactor | |
1632 | print("dataOut",dataOut.data_360.shape) |
|
1633 | print("dataOut",dataOut.data_360.shape) | |
1633 | # |
|
1634 | # | |
1634 | data['weather'] = 10*numpy.log10(dataOut.data_360/(factor)) |
|
1635 | data['weather'] = 10*numpy.log10(dataOut.data_360/(factor)) | |
1635 | # |
|
1636 | # | |
1636 | #data['weather'] = 10*numpy.log10(dataOut.data_360[1]/(factor)) |
|
1637 | #data['weather'] = 10*numpy.log10(dataOut.data_360[1]/(factor)) | |
1637 | data['azi'] = dataOut.data_azi |
|
1638 | data['azi'] = dataOut.data_azi | |
1638 | data['ele'] = dataOut.data_ele |
|
1639 | data['ele'] = dataOut.data_ele | |
1639 | data['case_flag'] = dataOut.case_flag |
|
1640 | data['case_flag'] = dataOut.case_flag | |
1640 | #print("UPDATE") |
|
1641 | #print("UPDATE") | |
1641 | #print("data[weather]",data['weather'].shape) |
|
1642 | #print("data[weather]",data['weather'].shape) | |
1642 | #print("data[azi]",data['azi']) |
|
1643 | #print("data[azi]",data['azi']) | |
1643 | return data, meta |
|
1644 | return data, meta | |
1644 |
|
1645 | |||
1645 | def get2List(self,angulos): |
|
1646 | def get2List(self,angulos): | |
1646 | list1=[] |
|
1647 | list1=[] | |
1647 | list2=[] |
|
1648 | list2=[] | |
1648 | #print(angulos) |
|
1649 | #print(angulos) | |
1649 | #exit(1) |
|
1650 | #exit(1) | |
1650 | for i in reversed(range(len(angulos))): |
|
1651 | for i in reversed(range(len(angulos))): | |
1651 | if not i==0:#el caso de i=0 evalula el primero de la lista con el ultimo y no es relevante |
|
1652 | if not i==0:#el caso de i=0 evalula el primero de la lista con el ultimo y no es relevante | |
1652 | diff_ = angulos[i]-angulos[i-1] |
|
1653 | diff_ = angulos[i]-angulos[i-1] | |
1653 | if abs(diff_) >1.5: |
|
1654 | if abs(diff_) >1.5: | |
1654 | list1.append(i-1) |
|
1655 | list1.append(i-1) | |
1655 | list2.append(diff_) |
|
1656 | list2.append(diff_) | |
1656 | return list(reversed(list1)),list(reversed(list2)) |
|
1657 | return list(reversed(list1)),list(reversed(list2)) | |
1657 |
|
1658 | |||
1658 | def fixData90(self,list_,ang_): |
|
1659 | def fixData90(self,list_,ang_): | |
1659 | if list_[0]==-1: |
|
1660 | if list_[0]==-1: | |
1660 | vec = numpy.where(ang_<ang_[0]) |
|
1661 | vec = numpy.where(ang_<ang_[0]) | |
1661 | ang_[vec] = ang_[vec]+90 |
|
1662 | ang_[vec] = ang_[vec]+90 | |
1662 | return ang_ |
|
1663 | return ang_ | |
1663 | return ang_ |
|
1664 | return ang_ | |
1664 |
|
1665 | |||
1665 | def fixData90HL(self,angulos): |
|
1666 | def fixData90HL(self,angulos): | |
1666 | vec = numpy.where(angulos>=90) |
|
1667 | vec = numpy.where(angulos>=90) | |
1667 | angulos[vec]=angulos[vec]-90 |
|
1668 | angulos[vec]=angulos[vec]-90 | |
1668 | return angulos |
|
1669 | return angulos | |
1669 |
|
1670 | |||
1670 |
|
1671 | |||
1671 | def search_pos(self,pos,list_): |
|
1672 | def search_pos(self,pos,list_): | |
1672 | for i in range(len(list_)): |
|
1673 | for i in range(len(list_)): | |
1673 | if pos == list_[i]: |
|
1674 | if pos == list_[i]: | |
1674 | return True,i |
|
1675 | return True,i | |
1675 | i=None |
|
1676 | i=None | |
1676 | return False,i |
|
1677 | return False,i | |
1677 |
|
1678 | |||
1678 | def fixDataComp(self,ang_,list1_,list2_,tipo_case): |
|
1679 | def fixDataComp(self,ang_,list1_,list2_,tipo_case): | |
1679 | size = len(ang_) |
|
1680 | size = len(ang_) | |
1680 | size2 = 0 |
|
1681 | size2 = 0 | |
1681 | for i in range(len(list2_)): |
|
1682 | for i in range(len(list2_)): | |
1682 | size2=size2+round(abs(list2_[i]))-1 |
|
1683 | size2=size2+round(abs(list2_[i]))-1 | |
1683 | new_size= size+size2 |
|
1684 | new_size= size+size2 | |
1684 | ang_new = numpy.zeros(new_size) |
|
1685 | ang_new = numpy.zeros(new_size) | |
1685 | ang_new2 = numpy.zeros(new_size) |
|
1686 | ang_new2 = numpy.zeros(new_size) | |
1686 |
|
1687 | |||
1687 | tmp = 0 |
|
1688 | tmp = 0 | |
1688 | c = 0 |
|
1689 | c = 0 | |
1689 | for i in range(len(ang_)): |
|
1690 | for i in range(len(ang_)): | |
1690 | ang_new[tmp +c] = ang_[i] |
|
1691 | ang_new[tmp +c] = ang_[i] | |
1691 | ang_new2[tmp+c] = ang_[i] |
|
1692 | ang_new2[tmp+c] = ang_[i] | |
1692 | condition , value = self.search_pos(i,list1_) |
|
1693 | condition , value = self.search_pos(i,list1_) | |
1693 | if condition: |
|
1694 | if condition: | |
1694 | pos = tmp + c + 1 |
|
1695 | pos = tmp + c + 1 | |
1695 | for k in range(round(abs(list2_[value]))-1): |
|
1696 | for k in range(round(abs(list2_[value]))-1): | |
1696 | if tipo_case==0 or tipo_case==3:#subida |
|
1697 | if tipo_case==0 or tipo_case==3:#subida | |
1697 | ang_new[pos+k] = ang_new[pos+k-1]+1 |
|
1698 | ang_new[pos+k] = ang_new[pos+k-1]+1 | |
1698 | ang_new2[pos+k] = numpy.nan |
|
1699 | ang_new2[pos+k] = numpy.nan | |
1699 | elif tipo_case==1 or tipo_case==2:#bajada |
|
1700 | elif tipo_case==1 or tipo_case==2:#bajada | |
1700 | ang_new[pos+k] = ang_new[pos+k-1]-1 |
|
1701 | ang_new[pos+k] = ang_new[pos+k-1]-1 | |
1701 | ang_new2[pos+k] = numpy.nan |
|
1702 | ang_new2[pos+k] = numpy.nan | |
1702 |
|
1703 | |||
1703 | tmp = pos +k |
|
1704 | tmp = pos +k | |
1704 | c = 0 |
|
1705 | c = 0 | |
1705 | c=c+1 |
|
1706 | c=c+1 | |
1706 | return ang_new,ang_new2 |
|
1707 | return ang_new,ang_new2 | |
1707 |
|
1708 | |||
1708 | def globalCheckPED(self,angulos,tipo_case): |
|
1709 | def globalCheckPED(self,angulos,tipo_case): | |
1709 | l1,l2 = self.get2List(angulos) |
|
1710 | l1,l2 = self.get2List(angulos) | |
1710 | print("l1",l1) |
|
1711 | print("l1",l1) | |
1711 | print("l2",l2) |
|
1712 | print("l2",l2) | |
1712 | if len(l1)>0: |
|
1713 | if len(l1)>0: | |
1713 | #angulos2 = self.fixData90(list_=l1,ang_=angulos) |
|
1714 | #angulos2 = self.fixData90(list_=l1,ang_=angulos) | |
1714 | #l1,l2 = self.get2List(angulos2) |
|
1715 | #l1,l2 = self.get2List(angulos2) | |
1715 | ang1_,ang2_ = self.fixDataComp(ang_=angulos,list1_=l1,list2_=l2,tipo_case=tipo_case) |
|
1716 | ang1_,ang2_ = self.fixDataComp(ang_=angulos,list1_=l1,list2_=l2,tipo_case=tipo_case) | |
1716 | #ang1_ = self.fixData90HL(ang1_) |
|
1717 | #ang1_ = self.fixData90HL(ang1_) | |
1717 | #ang2_ = self.fixData90HL(ang2_) |
|
1718 | #ang2_ = self.fixData90HL(ang2_) | |
1718 | else: |
|
1719 | else: | |
1719 | ang1_= angulos |
|
1720 | ang1_= angulos | |
1720 | ang2_= angulos |
|
1721 | ang2_= angulos | |
1721 | return ang1_,ang2_ |
|
1722 | return ang1_,ang2_ | |
1722 |
|
1723 | |||
1723 |
|
1724 | |||
1724 | def replaceNAN(self,data_weather,data_ele,val): |
|
1725 | def replaceNAN(self,data_weather,data_ele,val): | |
1725 | data= data_ele |
|
1726 | data= data_ele | |
1726 | data_T= data_weather |
|
1727 | data_T= data_weather | |
1727 | #print(data.shape[0]) |
|
1728 | #print(data.shape[0]) | |
1728 | #print(data_T.shape[0]) |
|
1729 | #print(data_T.shape[0]) | |
1729 | #exit(1) |
|
1730 | #exit(1) | |
1730 | if data.shape[0]> data_T.shape[0]: |
|
1731 | if data.shape[0]> data_T.shape[0]: | |
1731 | data_N = numpy.ones( [data.shape[0],data_T.shape[1]]) |
|
1732 | data_N = numpy.ones( [data.shape[0],data_T.shape[1]]) | |
1732 | c = 0 |
|
1733 | c = 0 | |
1733 | for i in range(len(data)): |
|
1734 | for i in range(len(data)): | |
1734 | if numpy.isnan(data[i]): |
|
1735 | if numpy.isnan(data[i]): | |
1735 | data_N[i,:]=numpy.ones(data_T.shape[1])*numpy.nan |
|
1736 | data_N[i,:]=numpy.ones(data_T.shape[1])*numpy.nan | |
1736 | else: |
|
1737 | else: | |
1737 | data_N[i,:]=data_T[c,:] |
|
1738 | data_N[i,:]=data_T[c,:] | |
1738 | c=c+1 |
|
1739 | c=c+1 | |
1739 | return data_N |
|
1740 | return data_N | |
1740 | else: |
|
1741 | else: | |
1741 | for i in range(len(data)): |
|
1742 | for i in range(len(data)): | |
1742 | if numpy.isnan(data[i]): |
|
1743 | if numpy.isnan(data[i]): | |
1743 | data_T[i,:]=numpy.ones(data_T.shape[1])*numpy.nan |
|
1744 | data_T[i,:]=numpy.ones(data_T.shape[1])*numpy.nan | |
1744 | return data_T |
|
1745 | return data_T | |
1745 |
|
1746 | |||
1746 |
|
1747 | |||
1747 | def const_ploteo(self,val_ch,data_weather,data_ele,step,res,ang_max,ang_min,case_flag): |
|
1748 | def const_ploteo(self,val_ch,data_weather,data_ele,step,res,ang_max,ang_min,case_flag): | |
1748 | ang_max= ang_max |
|
1749 | ang_max= ang_max | |
1749 | ang_min= ang_min |
|
1750 | ang_min= ang_min | |
1750 | data_weather=data_weather |
|
1751 | data_weather=data_weather | |
1751 | val_ch=val_ch |
|
1752 | val_ch=val_ch | |
1752 | ##print("*********************DATA WEATHER**************************************") |
|
1753 | ##print("*********************DATA WEATHER**************************************") | |
1753 | ##print(data_weather) |
|
1754 | ##print(data_weather) | |
1754 |
|
1755 | |||
1755 | ''' |
|
1756 | ''' | |
1756 | print("**********************************************") |
|
1757 | print("**********************************************") | |
1757 | print("**********************************************") |
|
1758 | print("**********************************************") | |
1758 | print("***************ini**************") |
|
1759 | print("***************ini**************") | |
1759 | print("**********************************************") |
|
1760 | print("**********************************************") | |
1760 | print("**********************************************") |
|
1761 | print("**********************************************") | |
1761 | ''' |
|
1762 | ''' | |
1762 | #print("data_ele",data_ele) |
|
1763 | #print("data_ele",data_ele) | |
1763 | #---------------------------------------------------------- |
|
1764 | #---------------------------------------------------------- | |
1764 |
|
1765 | |||
1765 | #exit(1) |
|
1766 | #exit(1) | |
1766 | tipo_case = case_flag[-1] |
|
1767 | tipo_case = case_flag[-1] | |
1767 | print("tipo_case",tipo_case) |
|
1768 | print("tipo_case",tipo_case) | |
1768 | #--------------------- new ------------------------- |
|
1769 | #--------------------- new ------------------------- | |
1769 | data_ele_new ,data_ele_old= self.globalCheckPED(data_ele,tipo_case) |
|
1770 | data_ele_new ,data_ele_old= self.globalCheckPED(data_ele,tipo_case) | |
1770 |
|
1771 | |||
1771 | #-------------------------CAMBIOS RHI--------------------------------- |
|
1772 | #-------------------------CAMBIOS RHI--------------------------------- | |
1772 |
|
1773 | |||
1773 | vec = numpy.where(data_ele<ang_max) |
|
1774 | vec = numpy.where(data_ele<ang_max) | |
1774 | data_ele = data_ele[vec] |
|
1775 | data_ele = data_ele[vec] | |
1775 | data_weather= data_weather[vec[0]] |
|
1776 | data_weather= data_weather[vec[0]] | |
1776 |
|
1777 | |||
1777 | len_vec = len(vec) |
|
1778 | len_vec = len(vec) | |
1778 | data_ele_new = data_ele[::-1] # reversa |
|
1779 | data_ele_new = data_ele[::-1] # reversa | |
1779 | data_weather = data_weather[::-1,:] |
|
1780 | data_weather = data_weather[::-1,:] | |
1780 | new_i_ele = int(data_ele_new[0]) |
|
1781 | new_i_ele = int(data_ele_new[0]) | |
1781 | new_f_ele = int(data_ele_new[-1]) |
|
1782 | new_f_ele = int(data_ele_new[-1]) | |
1782 |
|
1783 | |||
1783 | n1= new_i_ele- ang_min |
|
1784 | n1= new_i_ele- ang_min | |
1784 | n2= ang_max - new_f_ele-1 |
|
1785 | n2= ang_max - new_f_ele-1 | |
1785 | if n1>0: |
|
1786 | if n1>0: | |
1786 | ele1= numpy.linspace(ang_min+1,new_i_ele-1,n1) |
|
1787 | ele1= numpy.linspace(ang_min+1,new_i_ele-1,n1) | |
1787 | ele1_nan= numpy.ones(n1)*numpy.nan |
|
1788 | ele1_nan= numpy.ones(n1)*numpy.nan | |
1788 | data_ele = numpy.hstack((ele1,data_ele_new)) |
|
1789 | data_ele = numpy.hstack((ele1,data_ele_new)) | |
1789 | data_ele_old = numpy.hstack((ele1_nan,data_ele_new)) |
|
1790 | data_ele_old = numpy.hstack((ele1_nan,data_ele_new)) | |
1790 | if n2>0: |
|
1791 | if n2>0: | |
1791 | ele2= numpy.linspace(new_f_ele+1,ang_max,n2) |
|
1792 | ele2= numpy.linspace(new_f_ele+1,ang_max,n2) | |
1792 | ele2_nan= numpy.ones(n2)*numpy.nan |
|
1793 | ele2_nan= numpy.ones(n2)*numpy.nan | |
1793 | data_ele = numpy.hstack((data_ele,ele2)) |
|
1794 | data_ele = numpy.hstack((data_ele,ele2)) | |
1794 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) |
|
1795 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) | |
1795 |
|
1796 | |||
1796 |
|
1797 | |||
1797 | print("ele shape",data_ele.shape) |
|
1798 | print("ele shape",data_ele.shape) | |
1798 | print(data_ele) |
|
1799 | print(data_ele) | |
1799 |
|
1800 | |||
1800 | #print("self.data_ele_tmp",self.data_ele_tmp) |
|
1801 | #print("self.data_ele_tmp",self.data_ele_tmp) | |
1801 | val_mean = numpy.mean(data_weather[:,-1]) |
|
1802 | val_mean = numpy.mean(data_weather[:,-1]) | |
1802 | self.val_mean = val_mean |
|
1803 | self.val_mean = val_mean | |
1803 | data_weather = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) |
|
1804 | data_weather = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) | |
1804 | self.data_ele_tmp[val_ch]= data_ele_old |
|
1805 | self.data_ele_tmp[val_ch]= data_ele_old | |
1805 |
|
1806 | |||
1806 |
|
1807 | |||
1807 | print("data_weather shape",data_weather.shape) |
|
1808 | print("data_weather shape",data_weather.shape) | |
1808 | print(data_weather) |
|
1809 | print(data_weather) | |
1809 | #exit(1) |
|
1810 | #exit(1) | |
1810 | return data_weather,data_ele |
|
1811 | return data_weather,data_ele | |
1811 |
|
1812 | |||
1812 |
|
1813 | |||
1813 | def plot(self): |
|
1814 | def plot(self): | |
1814 | thisDatetime = datetime.datetime.utcfromtimestamp(self.data.times[-1]).strftime('%Y-%m-%d %H:%M:%S') |
|
1815 | thisDatetime = datetime.datetime.utcfromtimestamp(self.data.times[-1]).strftime('%Y-%m-%d %H:%M:%S') | |
1815 | data = self.data[-1] |
|
1816 | data = self.data[-1] | |
1816 | r = self.data.yrange |
|
1817 | r = self.data.yrange | |
1817 | delta_height = r[1]-r[0] |
|
1818 | delta_height = r[1]-r[0] | |
1818 | r_mask = numpy.where(r>=0)[0] |
|
1819 | r_mask = numpy.where(r>=0)[0] | |
1819 | ##print("delta_height",delta_height) |
|
1820 | ##print("delta_height",delta_height) | |
1820 | #print("r_mask",r_mask,len(r_mask)) |
|
1821 | #print("r_mask",r_mask,len(r_mask)) | |
1821 | r = numpy.arange(len(r_mask))*delta_height |
|
1822 | r = numpy.arange(len(r_mask))*delta_height | |
1822 | self.y = 2*r |
|
1823 | self.y = 2*r | |
1823 | res = 1 |
|
1824 | res = 1 | |
1824 | ###print("data['weather'].shape[0]",data['weather'].shape[0]) |
|
1825 | ###print("data['weather'].shape[0]",data['weather'].shape[0]) | |
1825 | ang_max = self.ang_max |
|
1826 | ang_max = self.ang_max | |
1826 | ang_min = self.ang_min |
|
1827 | ang_min = self.ang_min | |
1827 | var_ang =ang_max - ang_min |
|
1828 | var_ang =ang_max - ang_min | |
1828 | step = (int(var_ang)/(res*data['weather'].shape[0])) |
|
1829 | step = (int(var_ang)/(res*data['weather'].shape[0])) | |
1829 | ###print("step",step) |
|
1830 | ###print("step",step) | |
1830 | #-------------------------------------------------------- |
|
1831 | #-------------------------------------------------------- | |
1831 | ##print('weather',data['weather'].shape) |
|
1832 | ##print('weather',data['weather'].shape) | |
1832 | ##print('ele',data['ele'].shape) |
|
1833 | ##print('ele',data['ele'].shape) | |
1833 |
|
1834 | |||
1834 | ###self.res_weather, self.res_ele = self.const_ploteo(data_weather=data['weather'][:,r_mask],data_ele=data['ele'],step=step,res=res,ang_max=ang_max,ang_min=ang_min) |
|
1835 | ###self.res_weather, self.res_ele = self.const_ploteo(data_weather=data['weather'][:,r_mask],data_ele=data['ele'],step=step,res=res,ang_max=ang_max,ang_min=ang_min) | |
1835 | ###self.res_azi = numpy.mean(data['azi']) |
|
1836 | ###self.res_azi = numpy.mean(data['azi']) | |
1836 | ###print("self.res_ele",self.res_ele) |
|
1837 | ###print("self.res_ele",self.res_ele) | |
1837 | plt.clf() |
|
1838 | plt.clf() | |
1838 | subplots = [121, 122] |
|
1839 | subplots = [121, 122] | |
1839 | if self.ini==0: |
|
1840 | if self.ini==0: | |
1840 | self.data_ele_tmp = numpy.ones([self.nplots,int(var_ang)])*numpy.nan |
|
1841 | self.data_ele_tmp = numpy.ones([self.nplots,int(var_ang)])*numpy.nan | |
1841 | self.res_weather= numpy.ones([self.nplots,int(var_ang),len(r_mask)])*numpy.nan |
|
1842 | self.res_weather= numpy.ones([self.nplots,int(var_ang),len(r_mask)])*numpy.nan | |
1842 | print("SHAPE",self.data_ele_tmp.shape) |
|
1843 | print("SHAPE",self.data_ele_tmp.shape) | |
1843 |
|
1844 | |||
1844 | for i,ax in enumerate(self.axes): |
|
1845 | for i,ax in enumerate(self.axes): | |
1845 | self.res_weather[i], self.res_ele = self.const_ploteo(val_ch=i, data_weather=data['weather'][i][:,r_mask],data_ele=data['ele'],step=step,res=res,ang_max=ang_max,ang_min=ang_min,case_flag=self.data['case_flag']) |
|
1846 | self.res_weather[i], self.res_ele = self.const_ploteo(val_ch=i, data_weather=data['weather'][i][:,r_mask],data_ele=data['ele'],step=step,res=res,ang_max=ang_max,ang_min=ang_min,case_flag=self.data['case_flag']) | |
1846 | self.res_azi = numpy.mean(data['azi']) |
|
1847 | self.res_azi = numpy.mean(data['azi']) | |
1847 |
|
1848 | |||
1848 | print(self.res_ele) |
|
1849 | print(self.res_ele) | |
1849 | #exit(1) |
|
1850 | #exit(1) | |
1850 | if ax.firsttime: |
|
1851 | if ax.firsttime: | |
1851 | #plt.clf() |
|
1852 | #plt.clf() | |
1852 | cgax, pm = wrl.vis.plot_rhi(self.res_weather[i],r=r,th=self.res_ele,ax=subplots[i], proj='cg',vmin=20, vmax=80) |
|
1853 | cgax, pm = wrl.vis.plot_rhi(self.res_weather[i],r=r,th=self.res_ele,ax=subplots[i], proj='cg',vmin=20, vmax=80) | |
1853 | #fig=self.figures[0] |
|
1854 | #fig=self.figures[0] | |
1854 | else: |
|
1855 | else: | |
1855 |
|
1856 | |||
1856 | #plt.clf() |
|
1857 | #plt.clf() | |
1857 | cgax, pm = wrl.vis.plot_rhi(self.res_weather[i],r=r,th=self.res_ele,ax=subplots[i], proj='cg',vmin=20, vmax=80) |
|
1858 | cgax, pm = wrl.vis.plot_rhi(self.res_weather[i],r=r,th=self.res_ele,ax=subplots[i], proj='cg',vmin=20, vmax=80) | |
1858 | caax = cgax.parasites[0] |
|
1859 | caax = cgax.parasites[0] | |
1859 | paax = cgax.parasites[1] |
|
1860 | paax = cgax.parasites[1] | |
1860 | cbar = plt.gcf().colorbar(pm, pad=0.075) |
|
1861 | cbar = plt.gcf().colorbar(pm, pad=0.075) | |
1861 | caax.set_xlabel('x_range [km]') |
|
1862 | caax.set_xlabel('x_range [km]') | |
1862 | caax.set_ylabel('y_range [km]') |
|
1863 | caax.set_ylabel('y_range [km]') | |
1863 | plt.text(1.0, 1.05, 'Elevacion '+str(thisDatetime)+" Step "+str(self.ini)+ " Azi: "+str(round(self.res_azi,2)), transform=caax.transAxes, va='bottom',ha='right') |
|
1864 | plt.text(1.0, 1.05, 'Elevacion '+str(thisDatetime)+" Step "+str(self.ini)+ " Azi: "+str(round(self.res_azi,2)), transform=caax.transAxes, va='bottom',ha='right') | |
1864 | print("***************************self.ini****************************",self.ini) |
|
1865 | print("***************************self.ini****************************",self.ini) | |
1865 | self.ini= self.ini+1 |
|
1866 | self.ini= self.ini+1 | |
|
1867 | ||||
|
1868 | class WeatherRHI_vRF3_Plot(Plot): | |||
|
1869 | CODE = 'weather' | |||
|
1870 | plot_name = 'weather' | |||
|
1871 | plot_type = 'rhistyle' | |||
|
1872 | buffering = False | |||
|
1873 | data_ele_tmp = None | |||
|
1874 | ||||
|
1875 | def setup(self): | |||
|
1876 | print("********************") | |||
|
1877 | print("********************") | |||
|
1878 | print("********************") | |||
|
1879 | print("SETUP WEATHER PLOT") | |||
|
1880 | self.ncols = 1 | |||
|
1881 | self.nrows = 1 | |||
|
1882 | self.nplots= 1 | |||
|
1883 | self.ylabel= 'Range [Km]' | |||
|
1884 | self.titles= ['Weather'] | |||
|
1885 | if self.channels is not None: | |||
|
1886 | self.nplots = len(self.channels) | |||
|
1887 | self.nrows = len(self.channels) | |||
|
1888 | else: | |||
|
1889 | self.nplots = self.data.shape(self.CODE)[0] | |||
|
1890 | self.nrows = self.nplots | |||
|
1891 | self.channels = list(range(self.nplots)) | |||
|
1892 | print("channels",self.channels) | |||
|
1893 | print("que saldra", self.data.shape(self.CODE)[0]) | |||
|
1894 | self.titles = ['{} Channel {}'.format(self.CODE.upper(), x) for x in range(self.nrows)] | |||
|
1895 | print("self.titles",self.titles) | |||
|
1896 | self.colorbar=False | |||
|
1897 | self.width =8 | |||
|
1898 | self.height =8 | |||
|
1899 | self.ini =0 | |||
|
1900 | self.len_azi =0 | |||
|
1901 | self.buffer_ini = None | |||
|
1902 | self.buffer_ele = None | |||
|
1903 | self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08}) | |||
|
1904 | self.flag =0 | |||
|
1905 | self.indicador= 0 | |||
|
1906 | self.last_data_ele = None | |||
|
1907 | self.val_mean = None | |||
|
1908 | ||||
|
1909 | def update(self, dataOut): | |||
|
1910 | ||||
|
1911 | data = {} | |||
|
1912 | meta = {} | |||
|
1913 | if hasattr(dataOut, 'dataPP_POWER'): | |||
|
1914 | factor = 1 | |||
|
1915 | if hasattr(dataOut, 'nFFTPoints'): | |||
|
1916 | factor = dataOut.normFactor | |||
|
1917 | print("dataOut",dataOut.data_360.shape) | |||
|
1918 | # | |||
|
1919 | data['weather'] = 10*numpy.log10(dataOut.data_360/(factor)) | |||
|
1920 | # | |||
|
1921 | #data['weather'] = 10*numpy.log10(dataOut.data_360[1]/(factor)) | |||
|
1922 | data['azi'] = dataOut.data_azi | |||
|
1923 | data['ele'] = dataOut.data_ele | |||
|
1924 | #data['case_flag'] = dataOut.case_flag | |||
|
1925 | #print("UPDATE") | |||
|
1926 | #print("data[weather]",data['weather'].shape) | |||
|
1927 | #print("data[azi]",data['azi']) | |||
|
1928 | return data, meta | |||
|
1929 | ||||
|
1930 | def get2List(self,angulos): | |||
|
1931 | list1=[] | |||
|
1932 | list2=[] | |||
|
1933 | for i in reversed(range(len(angulos))): | |||
|
1934 | if not i==0:#el caso de i=0 evalula el primero de la lista con el ultimo y no es relevante | |||
|
1935 | diff_ = angulos[i]-angulos[i-1] | |||
|
1936 | if abs(diff_) >1.5: | |||
|
1937 | list1.append(i-1) | |||
|
1938 | list2.append(diff_) | |||
|
1939 | return list(reversed(list1)),list(reversed(list2)) | |||
|
1940 | ||||
|
1941 | def fixData90(self,list_,ang_): | |||
|
1942 | if list_[0]==-1: | |||
|
1943 | vec = numpy.where(ang_<ang_[0]) | |||
|
1944 | ang_[vec] = ang_[vec]+90 | |||
|
1945 | return ang_ | |||
|
1946 | return ang_ | |||
|
1947 | ||||
|
1948 | def fixData90HL(self,angulos): | |||
|
1949 | vec = numpy.where(angulos>=90) | |||
|
1950 | angulos[vec]=angulos[vec]-90 | |||
|
1951 | return angulos | |||
|
1952 | ||||
|
1953 | ||||
|
1954 | def search_pos(self,pos,list_): | |||
|
1955 | for i in range(len(list_)): | |||
|
1956 | if pos == list_[i]: | |||
|
1957 | return True,i | |||
|
1958 | i=None | |||
|
1959 | return False,i | |||
|
1960 | ||||
|
1961 | def fixDataComp(self,ang_,list1_,list2_,tipo_case): | |||
|
1962 | size = len(ang_) | |||
|
1963 | size2 = 0 | |||
|
1964 | for i in range(len(list2_)): | |||
|
1965 | size2=size2+round(abs(list2_[i]))-1 | |||
|
1966 | new_size= size+size2 | |||
|
1967 | ang_new = numpy.zeros(new_size) | |||
|
1968 | ang_new2 = numpy.zeros(new_size) | |||
|
1969 | ||||
|
1970 | tmp = 0 | |||
|
1971 | c = 0 | |||
|
1972 | for i in range(len(ang_)): | |||
|
1973 | ang_new[tmp +c] = ang_[i] | |||
|
1974 | ang_new2[tmp+c] = ang_[i] | |||
|
1975 | condition , value = self.search_pos(i,list1_) | |||
|
1976 | if condition: | |||
|
1977 | pos = tmp + c + 1 | |||
|
1978 | for k in range(round(abs(list2_[value]))-1): | |||
|
1979 | if tipo_case==0 or tipo_case==3:#subida | |||
|
1980 | ang_new[pos+k] = ang_new[pos+k-1]+1 | |||
|
1981 | ang_new2[pos+k] = numpy.nan | |||
|
1982 | elif tipo_case==1 or tipo_case==2:#bajada | |||
|
1983 | ang_new[pos+k] = ang_new[pos+k-1]-1 | |||
|
1984 | ang_new2[pos+k] = numpy.nan | |||
|
1985 | ||||
|
1986 | tmp = pos +k | |||
|
1987 | c = 0 | |||
|
1988 | c=c+1 | |||
|
1989 | return ang_new,ang_new2 | |||
|
1990 | ||||
|
1991 | def globalCheckPED(self,angulos,tipo_case): | |||
|
1992 | l1,l2 = self.get2List(angulos) | |||
|
1993 | ##print("l1",l1) | |||
|
1994 | ##print("l2",l2) | |||
|
1995 | if len(l1)>0: | |||
|
1996 | #angulos2 = self.fixData90(list_=l1,ang_=angulos) | |||
|
1997 | #l1,l2 = self.get2List(angulos2) | |||
|
1998 | ang1_,ang2_ = self.fixDataComp(ang_=angulos,list1_=l1,list2_=l2,tipo_case=tipo_case) | |||
|
1999 | #ang1_ = self.fixData90HL(ang1_) | |||
|
2000 | #ang2_ = self.fixData90HL(ang2_) | |||
|
2001 | else: | |||
|
2002 | ang1_= angulos | |||
|
2003 | ang2_= angulos | |||
|
2004 | return ang1_,ang2_ | |||
|
2005 | ||||
|
2006 | ||||
|
2007 | def replaceNAN(self,data_weather,data_ele,val): | |||
|
2008 | data= data_ele | |||
|
2009 | data_T= data_weather | |||
|
2010 | ||||
|
2011 | if data.shape[0]> data_T.shape[0]: | |||
|
2012 | print("IF") | |||
|
2013 | data_N = numpy.ones( [data.shape[0],data_T.shape[1]]) | |||
|
2014 | c = 0 | |||
|
2015 | for i in range(len(data)): | |||
|
2016 | if numpy.isnan(data[i]): | |||
|
2017 | data_N[i,:]=numpy.ones(data_T.shape[1])*numpy.nan | |||
|
2018 | else: | |||
|
2019 | data_N[i,:]=data_T[c,:] | |||
|
2020 | c=c+1 | |||
|
2021 | return data_N | |||
|
2022 | else: | |||
|
2023 | print("else") | |||
|
2024 | for i in range(len(data)): | |||
|
2025 | if numpy.isnan(data[i]): | |||
|
2026 | data_T[i,:]=numpy.ones(data_T.shape[1])*numpy.nan | |||
|
2027 | return data_T | |||
|
2028 | ||||
|
2029 | def check_case(self,data_ele,ang_max,ang_min): | |||
|
2030 | start = data_ele[0] | |||
|
2031 | end = data_ele[-1] | |||
|
2032 | number = (end-start) | |||
|
2033 | len_ang=len(data_ele) | |||
|
2034 | print("start",start) | |||
|
2035 | print("end",end) | |||
|
2036 | print("number",number) | |||
|
2037 | ||||
|
2038 | print("len_ang",len_ang) | |||
|
2039 | ||||
|
2040 | #exit(1) | |||
|
2041 | ||||
|
2042 | if start<end and (round(abs(number)+1)>=len_ang or (numpy.argmin(data_ele)==0)):#caso subida | |||
|
2043 | return 0 | |||
|
2044 | #elif start>end and (round(abs(number)+1)>=len_ang or(numpy.argmax(data_ele)==0)):#caso bajada | |||
|
2045 | # return 1 | |||
|
2046 | elif round(abs(number)+1)>=len_ang and (start>end or(numpy.argmax(data_ele)==0)):#caso bajada | |||
|
2047 | return 1 | |||
|
2048 | elif round(abs(number)+1)<len_ang and data_ele[-2]>data_ele[-1]:# caso BAJADA CAMBIO ANG MAX | |||
|
2049 | return 2 | |||
|
2050 | elif round(abs(number)+1)<len_ang and data_ele[-2]<data_ele[-1] :# caso SUBIDA CAMBIO ANG MIN | |||
|
2051 | return 3 | |||
|
2052 | ||||
|
2053 | ||||
|
2054 | def const_ploteo(self,val_ch,data_weather,data_ele,step,res,ang_max,ang_min,case_flag): | |||
|
2055 | ang_max= ang_max | |||
|
2056 | ang_min= ang_min | |||
|
2057 | data_weather=data_weather | |||
|
2058 | val_ch=val_ch | |||
|
2059 | ##print("*********************DATA WEATHER**************************************") | |||
|
2060 | ##print(data_weather) | |||
|
2061 | if self.ini==0: | |||
|
2062 | ||||
|
2063 | #--------------------- new ------------------------- | |||
|
2064 | data_ele_new ,data_ele_old= self.globalCheckPED(data_ele,tipo_case) | |||
|
2065 | ||||
|
2066 | #-------------------------CAMBIOS RHI--------------------------------- | |||
|
2067 | start= ang_min | |||
|
2068 | end = ang_max | |||
|
2069 | n= (ang_max-ang_min)/res | |||
|
2070 | #------ new | |||
|
2071 | self.start_data_ele = data_ele_new[0] | |||
|
2072 | self.end_data_ele = data_ele_new[-1] | |||
|
2073 | if tipo_case==0 or tipo_case==3: # SUBIDA | |||
|
2074 | n1= round(self.start_data_ele)- start | |||
|
2075 | n2= end - round(self.end_data_ele) | |||
|
2076 | print(self.start_data_ele) | |||
|
2077 | print(self.end_data_ele) | |||
|
2078 | if n1>0: | |||
|
2079 | ele1= numpy.linspace(ang_min+1,self.start_data_ele-1,n1) | |||
|
2080 | ele1_nan= numpy.ones(n1)*numpy.nan | |||
|
2081 | data_ele = numpy.hstack((ele1,data_ele_new)) | |||
|
2082 | print("ele1_nan",ele1_nan.shape) | |||
|
2083 | print("data_ele_old",data_ele_old.shape) | |||
|
2084 | data_ele_old = numpy.hstack((ele1_nan,data_ele_old)) | |||
|
2085 | if n2>0: | |||
|
2086 | ele2= numpy.linspace(self.end_data_ele+1,end,n2) | |||
|
2087 | ele2_nan= numpy.ones(n2)*numpy.nan | |||
|
2088 | data_ele = numpy.hstack((data_ele,ele2)) | |||
|
2089 | print("ele2_nan",ele2_nan.shape) | |||
|
2090 | print("data_ele_old",data_ele_old.shape) | |||
|
2091 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) | |||
|
2092 | ||||
|
2093 | if tipo_case==1 or tipo_case==2: # BAJADA | |||
|
2094 | data_ele_new = data_ele_new[::-1] # reversa | |||
|
2095 | data_ele_old = data_ele_old[::-1]# reversa | |||
|
2096 | data_weather = data_weather[::-1,:]# reversa | |||
|
2097 | vec= numpy.where(data_ele_new<ang_max) | |||
|
2098 | data_ele_new = data_ele_new[vec] | |||
|
2099 | data_ele_old = data_ele_old[vec] | |||
|
2100 | data_weather = data_weather[vec[0]] | |||
|
2101 | vec2= numpy.where(0<data_ele_new) | |||
|
2102 | data_ele_new = data_ele_new[vec2] | |||
|
2103 | data_ele_old = data_ele_old[vec2] | |||
|
2104 | data_weather = data_weather[vec2[0]] | |||
|
2105 | self.start_data_ele = data_ele_new[0] | |||
|
2106 | self.end_data_ele = data_ele_new[-1] | |||
|
2107 | ||||
|
2108 | n1= round(self.start_data_ele)- start | |||
|
2109 | n2= end - round(self.end_data_ele)-1 | |||
|
2110 | print(self.start_data_ele) | |||
|
2111 | print(self.end_data_ele) | |||
|
2112 | if n1>0: | |||
|
2113 | ele1= numpy.linspace(ang_min+1,self.start_data_ele-1,n1) | |||
|
2114 | ele1_nan= numpy.ones(n1)*numpy.nan | |||
|
2115 | data_ele = numpy.hstack((ele1,data_ele_new)) | |||
|
2116 | data_ele_old = numpy.hstack((ele1_nan,data_ele_old)) | |||
|
2117 | if n2>0: | |||
|
2118 | ele2= numpy.linspace(self.end_data_ele+1,end,n2) | |||
|
2119 | ele2_nan= numpy.ones(n2)*numpy.nan | |||
|
2120 | data_ele = numpy.hstack((data_ele,ele2)) | |||
|
2121 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) | |||
|
2122 | # RADAR | |||
|
2123 | # NOTA data_ele y data_weather es la variable que retorna | |||
|
2124 | val_mean = numpy.mean(data_weather[:,-1]) | |||
|
2125 | self.val_mean = val_mean | |||
|
2126 | data_weather = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) | |||
|
2127 | print("eleold",data_ele_old) | |||
|
2128 | print(self.data_ele_tmp[val_ch]) | |||
|
2129 | print(data_ele_old.shape[0]) | |||
|
2130 | print(self.data_ele_tmp[val_ch].shape[0]) | |||
|
2131 | if (data_ele_old.shape[0]==91 or self.data_ele_tmp[val_ch].shape[0]==91): | |||
|
2132 | import sys | |||
|
2133 | print("EXIT",self.ini) | |||
|
2134 | ||||
|
2135 | sys.exit(1) | |||
|
2136 | self.data_ele_tmp[val_ch]= data_ele_old | |||
|
2137 | else: | |||
|
2138 | #print("**********************************************") | |||
|
2139 | #print("****************VARIABLE**********************") | |||
|
2140 | #-------------------------CAMBIOS RHI--------------------------------- | |||
|
2141 | #--------------------------------------------------------------------- | |||
|
2142 | ##print("INPUT data_ele",data_ele) | |||
|
2143 | flag=0 | |||
|
2144 | start_ele = self.res_ele[0] | |||
|
2145 | #tipo_case = self.check_case(data_ele,ang_max,ang_min) | |||
|
2146 | tipo_case = case_flag[-1] | |||
|
2147 | #print("TIPO DE DATA",tipo_case) | |||
|
2148 | #-----------new------------ | |||
|
2149 | data_ele ,data_ele_old = self.globalCheckPED(data_ele,tipo_case) | |||
|
2150 | data_weather = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) | |||
|
2151 | ||||
|
2152 | #-------------------------------NEW RHI ITERATIVO------------------------- | |||
|
2153 | ||||
|
2154 | if tipo_case==0 : # SUBIDA | |||
|
2155 | vec = numpy.where(data_ele<ang_max) | |||
|
2156 | data_ele = data_ele[vec] | |||
|
2157 | data_ele_old = data_ele_old[vec] | |||
|
2158 | data_weather = data_weather[vec[0]] | |||
|
2159 | ||||
|
2160 | vec2 = numpy.where(0<data_ele) | |||
|
2161 | data_ele= data_ele[vec2] | |||
|
2162 | data_ele_old= data_ele_old[vec2] | |||
|
2163 | ##print(data_ele_new) | |||
|
2164 | data_weather= data_weather[vec2[0]] | |||
|
2165 | ||||
|
2166 | new_i_ele = int(round(data_ele[0])) | |||
|
2167 | new_f_ele = int(round(data_ele[-1])) | |||
|
2168 | #print(new_i_ele) | |||
|
2169 | #print(new_f_ele) | |||
|
2170 | #print(data_ele,len(data_ele)) | |||
|
2171 | #print(data_ele_old,len(data_ele_old)) | |||
|
2172 | if new_i_ele< 2: | |||
|
2173 | self.data_ele_tmp[val_ch] = numpy.ones(ang_max-ang_min)*numpy.nan | |||
|
2174 | self.res_weather[val_ch] = self.replaceNAN(data_weather=self.res_weather[val_ch],data_ele=self.data_ele_tmp[val_ch],val=self.val_mean) | |||
|
2175 | self.data_ele_tmp[val_ch][new_i_ele:new_i_ele+len(data_ele)]=data_ele_old | |||
|
2176 | self.res_ele[new_i_ele:new_i_ele+len(data_ele)]= data_ele | |||
|
2177 | self.res_weather[val_ch][new_i_ele:new_i_ele+len(data_ele),:]= data_weather | |||
|
2178 | data_ele = self.res_ele | |||
|
2179 | data_weather = self.res_weather[val_ch] | |||
|
2180 | ||||
|
2181 | elif tipo_case==1 : #BAJADA | |||
|
2182 | data_ele = data_ele[::-1] # reversa | |||
|
2183 | data_ele_old = data_ele_old[::-1]# reversa | |||
|
2184 | data_weather = data_weather[::-1,:]# reversa | |||
|
2185 | vec= numpy.where(data_ele<ang_max) | |||
|
2186 | data_ele = data_ele[vec] | |||
|
2187 | data_ele_old = data_ele_old[vec] | |||
|
2188 | data_weather = data_weather[vec[0]] | |||
|
2189 | vec2= numpy.where(0<data_ele) | |||
|
2190 | data_ele = data_ele[vec2] | |||
|
2191 | data_ele_old = data_ele_old[vec2] | |||
|
2192 | data_weather = data_weather[vec2[0]] | |||
|
2193 | ||||
|
2194 | ||||
|
2195 | new_i_ele = int(round(data_ele[0])) | |||
|
2196 | new_f_ele = int(round(data_ele[-1])) | |||
|
2197 | #print(data_ele) | |||
|
2198 | #print(ang_max) | |||
|
2199 | #print(data_ele_old) | |||
|
2200 | if new_i_ele <= 1: | |||
|
2201 | new_i_ele = 1 | |||
|
2202 | if round(data_ele[-1])>=ang_max-1: | |||
|
2203 | self.data_ele_tmp[val_ch] = numpy.ones(ang_max-ang_min)*numpy.nan | |||
|
2204 | self.res_weather[val_ch] = self.replaceNAN(data_weather=self.res_weather[val_ch],data_ele=self.data_ele_tmp[val_ch],val=self.val_mean) | |||
|
2205 | self.data_ele_tmp[val_ch][new_i_ele-1:new_i_ele+len(data_ele)-1]=data_ele_old | |||
|
2206 | self.res_ele[new_i_ele-1:new_i_ele+len(data_ele)-1]= data_ele | |||
|
2207 | self.res_weather[val_ch][new_i_ele-1:new_i_ele+len(data_ele)-1,:]= data_weather | |||
|
2208 | data_ele = self.res_ele | |||
|
2209 | data_weather = self.res_weather[val_ch] | |||
|
2210 | ||||
|
2211 | elif tipo_case==2: #bajada | |||
|
2212 | vec = numpy.where(data_ele<ang_max) | |||
|
2213 | data_ele = data_ele[vec] | |||
|
2214 | data_weather= data_weather[vec[0]] | |||
|
2215 | ||||
|
2216 | len_vec = len(vec) | |||
|
2217 | data_ele_new = data_ele[::-1] # reversa | |||
|
2218 | data_weather = data_weather[::-1,:] | |||
|
2219 | new_i_ele = int(data_ele_new[0]) | |||
|
2220 | new_f_ele = int(data_ele_new[-1]) | |||
|
2221 | ||||
|
2222 | n1= new_i_ele- ang_min | |||
|
2223 | n2= ang_max - new_f_ele-1 | |||
|
2224 | if n1>0: | |||
|
2225 | ele1= numpy.linspace(ang_min+1,new_i_ele-1,n1) | |||
|
2226 | ele1_nan= numpy.ones(n1)*numpy.nan | |||
|
2227 | data_ele = numpy.hstack((ele1,data_ele_new)) | |||
|
2228 | data_ele_old = numpy.hstack((ele1_nan,data_ele_new)) | |||
|
2229 | if n2>0: | |||
|
2230 | ele2= numpy.linspace(new_f_ele+1,ang_max,n2) | |||
|
2231 | ele2_nan= numpy.ones(n2)*numpy.nan | |||
|
2232 | data_ele = numpy.hstack((data_ele,ele2)) | |||
|
2233 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) | |||
|
2234 | ||||
|
2235 | self.data_ele_tmp[val_ch] = data_ele_old | |||
|
2236 | self.res_ele = data_ele | |||
|
2237 | self.res_weather[val_ch] = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) | |||
|
2238 | data_ele = self.res_ele | |||
|
2239 | data_weather = self.res_weather[val_ch] | |||
|
2240 | ||||
|
2241 | elif tipo_case==3:#subida | |||
|
2242 | vec = numpy.where(0<data_ele) | |||
|
2243 | data_ele= data_ele[vec] | |||
|
2244 | data_ele_new = data_ele | |||
|
2245 | data_ele_old= data_ele_old[vec] | |||
|
2246 | data_weather= data_weather[vec[0]] | |||
|
2247 | pos_ini = numpy.argmin(data_ele) | |||
|
2248 | if pos_ini>0: | |||
|
2249 | len_vec= len(data_ele) | |||
|
2250 | vec3 = numpy.linspace(pos_ini,len_vec-1,len_vec-pos_ini).astype(int) | |||
|
2251 | #print(vec3) | |||
|
2252 | data_ele= data_ele[vec3] | |||
|
2253 | data_ele_new = data_ele | |||
|
2254 | data_ele_old= data_ele_old[vec3] | |||
|
2255 | data_weather= data_weather[vec3] | |||
|
2256 | ||||
|
2257 | new_i_ele = int(data_ele_new[0]) | |||
|
2258 | new_f_ele = int(data_ele_new[-1]) | |||
|
2259 | n1= new_i_ele- ang_min | |||
|
2260 | n2= ang_max - new_f_ele-1 | |||
|
2261 | if n1>0: | |||
|
2262 | ele1= numpy.linspace(ang_min+1,new_i_ele-1,n1) | |||
|
2263 | ele1_nan= numpy.ones(n1)*numpy.nan | |||
|
2264 | data_ele = numpy.hstack((ele1,data_ele_new)) | |||
|
2265 | data_ele_old = numpy.hstack((ele1_nan,data_ele_new)) | |||
|
2266 | if n2>0: | |||
|
2267 | ele2= numpy.linspace(new_f_ele+1,ang_max,n2) | |||
|
2268 | ele2_nan= numpy.ones(n2)*numpy.nan | |||
|
2269 | data_ele = numpy.hstack((data_ele,ele2)) | |||
|
2270 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) | |||
|
2271 | ||||
|
2272 | self.data_ele_tmp[val_ch] = data_ele_old | |||
|
2273 | self.res_ele = data_ele | |||
|
2274 | self.res_weather[val_ch] = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) | |||
|
2275 | data_ele = self.res_ele | |||
|
2276 | data_weather = self.res_weather[val_ch] | |||
|
2277 | #print("self.data_ele_tmp",self.data_ele_tmp) | |||
|
2278 | return data_weather,data_ele | |||
|
2279 | ||||
|
2280 | def const_ploteo_vRF(self,val_ch,data_weather,data_ele,res,ang_max,ang_min): | |||
|
2281 | ||||
|
2282 | data_ele_new ,data_ele_old= self.globalCheckPED(data_ele,1) | |||
|
2283 | ||||
|
2284 | data_ele = data_ele_old.copy() | |||
|
2285 | ||||
|
2286 | diff_1 = ang_max - data_ele[0] | |||
|
2287 | angles_1_nan = numpy.linspace(ang_max,data_ele[0]+1,int(diff_1)-1)#*numpy.nan | |||
|
2288 | ||||
|
2289 | diff_2 = data_ele[-1]-ang_min | |||
|
2290 | angles_2_nan = numpy.linspace(data_ele[-1]-1,ang_min,int(diff_2)-1)#*numpy.nan | |||
|
2291 | ||||
|
2292 | angles_filled = numpy.concatenate((angles_1_nan,data_ele,angles_2_nan)) | |||
|
2293 | ||||
|
2294 | print(angles_filled) | |||
|
2295 | ||||
|
2296 | data_1_nan = numpy.ones([angles_1_nan.shape[0],len(self.r_mask)])*numpy.nan | |||
|
2297 | data_2_nan = numpy.ones([angles_2_nan.shape[0],len(self.r_mask)])*numpy.nan | |||
|
2298 | ||||
|
2299 | data_filled = numpy.concatenate((data_1_nan,data_weather,data_2_nan),axis=0) | |||
|
2300 | #val_mean = numpy.mean(data_weather[:,-1]) | |||
|
2301 | #self.val_mean = val_mean | |||
|
2302 | print(data_filled) | |||
|
2303 | data_filled = self.replaceNAN(data_weather=data_filled,data_ele=angles_filled,val=numpy.nan) | |||
|
2304 | ||||
|
2305 | print(data_filled) | |||
|
2306 | print(data_filled.shape) | |||
|
2307 | print(angles_filled.shape) | |||
|
2308 | ||||
|
2309 | return data_filled,angles_filled | |||
|
2310 | ||||
|
2311 | def plot(self): | |||
|
2312 | thisDatetime = datetime.datetime.utcfromtimestamp(self.data.times[-1]).strftime('%Y-%m-%d %H:%M:%S') | |||
|
2313 | data = self.data[-1] | |||
|
2314 | r = self.data.yrange | |||
|
2315 | delta_height = r[1]-r[0] | |||
|
2316 | r_mask = numpy.where(r>=0)[0] | |||
|
2317 | self.r_mask =r_mask | |||
|
2318 | ##print("delta_height",delta_height) | |||
|
2319 | #print("r_mask",r_mask,len(r_mask)) | |||
|
2320 | r = numpy.arange(len(r_mask))*delta_height | |||
|
2321 | self.y = 2*r | |||
|
2322 | res = 1 | |||
|
2323 | ###print("data['weather'].shape[0]",data['weather'].shape[0]) | |||
|
2324 | ang_max = self.ang_max | |||
|
2325 | ang_min = self.ang_min | |||
|
2326 | var_ang =ang_max - ang_min | |||
|
2327 | step = (int(var_ang)/(res*data['weather'].shape[0])) | |||
|
2328 | ###print("step",step) | |||
|
2329 | #-------------------------------------------------------- | |||
|
2330 | ##print('weather',data['weather'].shape) | |||
|
2331 | ##print('ele',data['ele'].shape) | |||
|
2332 | ||||
|
2333 | ###self.res_weather, self.res_ele = self.const_ploteo(data_weather=data['weather'][:,r_mask],data_ele=data['ele'],step=step,res=res,ang_max=ang_max,ang_min=ang_min) | |||
|
2334 | ###self.res_azi = numpy.mean(data['azi']) | |||
|
2335 | ###print("self.res_ele",self.res_ele) | |||
|
2336 | ||||
|
2337 | plt.clf() | |||
|
2338 | subplots = [121, 122] | |||
|
2339 | #if self.ini==0: | |||
|
2340 | #self.res_weather= numpy.ones([self.nplots,int(var_ang),len(r_mask)])*numpy.nan | |||
|
2341 | #print("SHAPE",self.data_ele_tmp.shape) | |||
|
2342 | ||||
|
2343 | for i,ax in enumerate(self.axes): | |||
|
2344 | res_weather, self.res_ele = self.const_ploteo_vRF(val_ch=i, data_weather=data['weather'][i][:,r_mask],data_ele=data['ele'],res=res,ang_max=ang_max,ang_min=ang_min) | |||
|
2345 | self.res_azi = numpy.mean(data['azi']) | |||
|
2346 | ||||
|
2347 | if ax.firsttime: | |||
|
2348 | #plt.clf() | |||
|
2349 | print("Frist Plot") | |||
|
2350 | print(data['weather'][i][:,r_mask].shape) | |||
|
2351 | print(data['ele'].shape) | |||
|
2352 | cgax, pm = wrl.vis.plot_rhi(res_weather,r=r,th=self.res_ele,ax=subplots[i], proj='cg',vmin=20, vmax=80) | |||
|
2353 | #cgax, pm = wrl.vis.plot_rhi(data['weather'][i][:,r_mask],r=r,th=data['ele'],ax=subplots[i], proj='cg',vmin=20, vmax=80) | |||
|
2354 | gh = cgax.get_grid_helper() | |||
|
2355 | locs = numpy.linspace(ang_min,ang_max,var_ang+1) | |||
|
2356 | gh.grid_finder.grid_locator1 = FixedLocator(locs) | |||
|
2357 | gh.grid_finder.tick_formatter1 = DictFormatter(dict([(i, r"${0:.0f}^\circ$".format(i)) for i in locs])) | |||
|
2358 | ||||
|
2359 | ||||
|
2360 | #fig=self.figures[0] | |||
|
2361 | else: | |||
|
2362 | #plt.clf() | |||
|
2363 | print("ELSE PLOT") | |||
|
2364 | cgax, pm = wrl.vis.plot_rhi(res_weather,r=r,th=self.res_ele,ax=subplots[i], proj='cg',vmin=20, vmax=80) | |||
|
2365 | #cgax, pm = wrl.vis.plot_rhi(data['weather'][i][:,r_mask],r=r,th=data['ele'],ax=subplots[i], proj='cg',vmin=20, vmax=80) | |||
|
2366 | gh = cgax.get_grid_helper() | |||
|
2367 | locs = numpy.linspace(ang_min,ang_max,var_ang+1) | |||
|
2368 | gh.grid_finder.grid_locator1 = FixedLocator(locs) | |||
|
2369 | gh.grid_finder.tick_formatter1 = DictFormatter(dict([(i, r"${0:.0f}^\circ$".format(i)) for i in locs])) | |||
|
2370 | ||||
|
2371 | caax = cgax.parasites[0] | |||
|
2372 | paax = cgax.parasites[1] | |||
|
2373 | cbar = plt.gcf().colorbar(pm, pad=0.075) | |||
|
2374 | caax.set_xlabel('x_range [km]') | |||
|
2375 | caax.set_ylabel('y_range [km]') | |||
|
2376 | plt.text(1.0, 1.05, 'Elevacion '+str(thisDatetime)+" Step "+str(self.ini)+ " Azi: "+str(round(self.res_azi,2)), transform=caax.transAxes, va='bottom',ha='right') | |||
|
2377 | print("***************************self.ini****************************",self.ini) | |||
|
2378 | self.ini= self.ini+1 |
@@ -1,4622 +1,4833 | |||||
1 | import numpy,os,h5py |
|
1 | import numpy,os,h5py | |
2 | import math |
|
2 | import math | |
3 | from scipy import optimize, interpolate, signal, stats, ndimage |
|
3 | from scipy import optimize, interpolate, signal, stats, ndimage | |
4 | import scipy |
|
4 | import scipy | |
5 | import re |
|
5 | import re | |
6 | import datetime |
|
6 | import datetime | |
7 | import copy |
|
7 | import copy | |
8 | import sys |
|
8 | import sys | |
9 | import importlib |
|
9 | import importlib | |
10 | import itertools |
|
10 | import itertools | |
11 | from multiprocessing import Pool, TimeoutError |
|
11 | from multiprocessing import Pool, TimeoutError | |
12 | from multiprocessing.pool import ThreadPool |
|
12 | from multiprocessing.pool import ThreadPool | |
13 | import time |
|
13 | import time | |
14 |
|
14 | |||
15 | from scipy.optimize import fmin_l_bfgs_b #optimize with bounds on state papameters |
|
15 | from scipy.optimize import fmin_l_bfgs_b #optimize with bounds on state papameters | |
16 | from .jroproc_base import ProcessingUnit, Operation, MPDecorator |
|
16 | from .jroproc_base import ProcessingUnit, Operation, MPDecorator | |
17 | from schainpy.model.data.jrodata import Parameters, hildebrand_sekhon |
|
17 | from schainpy.model.data.jrodata import Parameters, hildebrand_sekhon | |
18 | from scipy import asarray as ar,exp |
|
18 | from scipy import asarray as ar,exp | |
19 | from scipy.optimize import curve_fit |
|
19 | from scipy.optimize import curve_fit | |
20 | from schainpy.utils import log |
|
20 | from schainpy.utils import log | |
21 | import warnings |
|
21 | import warnings | |
22 | from numpy import NaN |
|
22 | from numpy import NaN | |
23 | from scipy.optimize.optimize import OptimizeWarning |
|
23 | from scipy.optimize.optimize import OptimizeWarning | |
24 | warnings.filterwarnings('ignore') |
|
24 | warnings.filterwarnings('ignore') | |
25 |
|
25 | |||
26 | from time import sleep |
|
26 | from time import sleep | |
27 |
|
27 | |||
28 | import matplotlib.pyplot as plt |
|
28 | import matplotlib.pyplot as plt | |
29 |
|
29 | |||
30 | SPEED_OF_LIGHT = 299792458 |
|
30 | SPEED_OF_LIGHT = 299792458 | |
31 |
|
31 | |||
32 | '''solving pickling issue''' |
|
32 | '''solving pickling issue''' | |
33 |
|
33 | |||
34 | def _pickle_method(method): |
|
34 | def _pickle_method(method): | |
35 | func_name = method.__func__.__name__ |
|
35 | func_name = method.__func__.__name__ | |
36 | obj = method.__self__ |
|
36 | obj = method.__self__ | |
37 | cls = method.__self__.__class__ |
|
37 | cls = method.__self__.__class__ | |
38 | return _unpickle_method, (func_name, obj, cls) |
|
38 | return _unpickle_method, (func_name, obj, cls) | |
39 |
|
39 | |||
40 | def _unpickle_method(func_name, obj, cls): |
|
40 | def _unpickle_method(func_name, obj, cls): | |
41 | for cls in cls.mro(): |
|
41 | for cls in cls.mro(): | |
42 | try: |
|
42 | try: | |
43 | func = cls.__dict__[func_name] |
|
43 | func = cls.__dict__[func_name] | |
44 | except KeyError: |
|
44 | except KeyError: | |
45 | pass |
|
45 | pass | |
46 | else: |
|
46 | else: | |
47 | break |
|
47 | break | |
48 | return func.__get__(obj, cls) |
|
48 | return func.__get__(obj, cls) | |
49 |
|
49 | |||
50 | def isNumber(str): |
|
50 | def isNumber(str): | |
51 | try: |
|
51 | try: | |
52 | float(str) |
|
52 | float(str) | |
53 | return True |
|
53 | return True | |
54 | except: |
|
54 | except: | |
55 | return False |
|
55 | return False | |
56 |
|
56 | |||
57 | class ParametersProc(ProcessingUnit): |
|
57 | class ParametersProc(ProcessingUnit): | |
58 |
|
58 | |||
59 | METHODS = {} |
|
59 | METHODS = {} | |
60 | nSeconds = None |
|
60 | nSeconds = None | |
61 |
|
61 | |||
62 | def __init__(self): |
|
62 | def __init__(self): | |
63 | ProcessingUnit.__init__(self) |
|
63 | ProcessingUnit.__init__(self) | |
64 |
|
64 | |||
65 | # self.objectDict = {} |
|
65 | # self.objectDict = {} | |
66 | self.buffer = None |
|
66 | self.buffer = None | |
67 | self.firstdatatime = None |
|
67 | self.firstdatatime = None | |
68 | self.profIndex = 0 |
|
68 | self.profIndex = 0 | |
69 | self.dataOut = Parameters() |
|
69 | self.dataOut = Parameters() | |
70 | self.setupReq = False #Agregar a todas las unidades de proc |
|
70 | self.setupReq = False #Agregar a todas las unidades de proc | |
71 |
|
71 | |||
72 | def __updateObjFromInput(self): |
|
72 | def __updateObjFromInput(self): | |
73 |
|
73 | |||
74 | self.dataOut.inputUnit = self.dataIn.type |
|
74 | self.dataOut.inputUnit = self.dataIn.type | |
75 |
|
75 | |||
76 | self.dataOut.timeZone = self.dataIn.timeZone |
|
76 | self.dataOut.timeZone = self.dataIn.timeZone | |
77 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
77 | self.dataOut.dstFlag = self.dataIn.dstFlag | |
78 | self.dataOut.errorCount = self.dataIn.errorCount |
|
78 | self.dataOut.errorCount = self.dataIn.errorCount | |
79 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
79 | self.dataOut.useLocalTime = self.dataIn.useLocalTime | |
80 |
|
80 | |||
81 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() |
|
81 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() | |
82 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() |
|
82 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() | |
83 | self.dataOut.channelList = self.dataIn.channelList |
|
83 | self.dataOut.channelList = self.dataIn.channelList | |
84 | self.dataOut.heightList = self.dataIn.heightList |
|
84 | self.dataOut.heightList = self.dataIn.heightList | |
85 | self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
85 | self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
86 | # self.dataOut.nHeights = self.dataIn.nHeights |
|
86 | # self.dataOut.nHeights = self.dataIn.nHeights | |
87 | # self.dataOut.nChannels = self.dataIn.nChannels |
|
87 | # self.dataOut.nChannels = self.dataIn.nChannels | |
88 | # self.dataOut.nBaud = self.dataIn.nBaud |
|
88 | # self.dataOut.nBaud = self.dataIn.nBaud | |
89 | # self.dataOut.nCode = self.dataIn.nCode |
|
89 | # self.dataOut.nCode = self.dataIn.nCode | |
90 | # self.dataOut.code = self.dataIn.code |
|
90 | # self.dataOut.code = self.dataIn.code | |
91 | # self.dataOut.nProfiles = self.dataOut.nFFTPoints |
|
91 | # self.dataOut.nProfiles = self.dataOut.nFFTPoints | |
92 | self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock |
|
92 | self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock | |
93 | # self.dataOut.utctime = self.firstdatatime |
|
93 | # self.dataOut.utctime = self.firstdatatime | |
94 | self.dataOut.utctime = self.dataIn.utctime |
|
94 | self.dataOut.utctime = self.dataIn.utctime | |
95 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada |
|
95 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada | |
96 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip |
|
96 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip | |
97 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
97 | self.dataOut.nCohInt = self.dataIn.nCohInt | |
98 | # self.dataOut.nIncohInt = 1 |
|
98 | # self.dataOut.nIncohInt = 1 | |
99 | # self.dataOut.ippSeconds = self.dataIn.ippSeconds |
|
99 | # self.dataOut.ippSeconds = self.dataIn.ippSeconds | |
100 | # self.dataOut.windowOfFilter = self.dataIn.windowOfFilter |
|
100 | # self.dataOut.windowOfFilter = self.dataIn.windowOfFilter | |
101 | self.dataOut.timeInterval1 = self.dataIn.timeInterval |
|
101 | self.dataOut.timeInterval1 = self.dataIn.timeInterval | |
102 | self.dataOut.heightList = self.dataIn.heightList |
|
102 | self.dataOut.heightList = self.dataIn.heightList | |
103 | self.dataOut.frequency = self.dataIn.frequency |
|
103 | self.dataOut.frequency = self.dataIn.frequency | |
104 | # self.dataOut.noise = self.dataIn.noise |
|
104 | # self.dataOut.noise = self.dataIn.noise | |
105 |
|
105 | |||
106 | def run(self): |
|
106 | def run(self): | |
107 |
|
107 | |||
108 |
|
108 | |||
109 | #print("HOLA MUNDO SOY YO") |
|
109 | #print("HOLA MUNDO SOY YO") | |
110 | #---------------------- Voltage Data --------------------------- |
|
110 | #---------------------- Voltage Data --------------------------- | |
111 |
|
111 | |||
112 | if self.dataIn.type == "Voltage": |
|
112 | if self.dataIn.type == "Voltage": | |
113 |
|
113 | |||
114 | self.__updateObjFromInput() |
|
114 | self.__updateObjFromInput() | |
115 | self.dataOut.data_pre = self.dataIn.data.copy() |
|
115 | self.dataOut.data_pre = self.dataIn.data.copy() | |
116 | self.dataOut.flagNoData = False |
|
116 | self.dataOut.flagNoData = False | |
117 | self.dataOut.utctimeInit = self.dataIn.utctime |
|
117 | self.dataOut.utctimeInit = self.dataIn.utctime | |
118 | self.dataOut.paramInterval = self.dataIn.nProfiles*self.dataIn.nCohInt*self.dataIn.ippSeconds |
|
118 | self.dataOut.paramInterval = self.dataIn.nProfiles*self.dataIn.nCohInt*self.dataIn.ippSeconds | |
119 |
|
119 | |||
120 | if hasattr(self.dataIn, 'flagDataAsBlock'): |
|
120 | if hasattr(self.dataIn, 'flagDataAsBlock'): | |
121 | self.dataOut.flagDataAsBlock = self.dataIn.flagDataAsBlock |
|
121 | self.dataOut.flagDataAsBlock = self.dataIn.flagDataAsBlock | |
122 |
|
122 | |||
123 | if hasattr(self.dataIn, 'profileIndex'): |
|
123 | if hasattr(self.dataIn, 'profileIndex'): | |
124 | self.dataOut.profileIndex = self.dataIn.profileIndex |
|
124 | self.dataOut.profileIndex = self.dataIn.profileIndex | |
125 |
|
125 | |||
126 | if hasattr(self.dataIn, 'dataPP_POW'): |
|
126 | if hasattr(self.dataIn, 'dataPP_POW'): | |
127 | self.dataOut.dataPP_POW = self.dataIn.dataPP_POW |
|
127 | self.dataOut.dataPP_POW = self.dataIn.dataPP_POW | |
128 |
|
128 | |||
129 | if hasattr(self.dataIn, 'dataPP_POWER'): |
|
129 | if hasattr(self.dataIn, 'dataPP_POWER'): | |
130 | self.dataOut.dataPP_POWER = self.dataIn.dataPP_POWER |
|
130 | self.dataOut.dataPP_POWER = self.dataIn.dataPP_POWER | |
131 |
|
131 | |||
132 | if hasattr(self.dataIn, 'dataPP_DOP'): |
|
132 | if hasattr(self.dataIn, 'dataPP_DOP'): | |
133 | self.dataOut.dataPP_DOP = self.dataIn.dataPP_DOP |
|
133 | self.dataOut.dataPP_DOP = self.dataIn.dataPP_DOP | |
134 |
|
134 | |||
135 | if hasattr(self.dataIn, 'dataPP_SNR'): |
|
135 | if hasattr(self.dataIn, 'dataPP_SNR'): | |
136 | self.dataOut.dataPP_SNR = self.dataIn.dataPP_SNR |
|
136 | self.dataOut.dataPP_SNR = self.dataIn.dataPP_SNR | |
137 |
|
137 | |||
138 | if hasattr(self.dataIn, 'dataPP_WIDTH'): |
|
138 | if hasattr(self.dataIn, 'dataPP_WIDTH'): | |
139 | self.dataOut.dataPP_WIDTH = self.dataIn.dataPP_WIDTH |
|
139 | self.dataOut.dataPP_WIDTH = self.dataIn.dataPP_WIDTH | |
140 | return |
|
140 | return | |
141 |
|
141 | |||
142 | #---------------------- Spectra Data --------------------------- |
|
142 | #---------------------- Spectra Data --------------------------- | |
143 |
|
143 | |||
144 | if self.dataIn.type == "Spectra": |
|
144 | if self.dataIn.type == "Spectra": | |
145 | #print("que paso en spectra") |
|
145 | #print("que paso en spectra") | |
146 | self.dataOut.data_pre = [self.dataIn.data_spc, self.dataIn.data_cspc] |
|
146 | self.dataOut.data_pre = [self.dataIn.data_spc, self.dataIn.data_cspc] | |
147 | self.dataOut.data_spc = self.dataIn.data_spc |
|
147 | self.dataOut.data_spc = self.dataIn.data_spc | |
148 | self.dataOut.data_cspc = self.dataIn.data_cspc |
|
148 | self.dataOut.data_cspc = self.dataIn.data_cspc | |
149 | self.dataOut.nProfiles = self.dataIn.nProfiles |
|
149 | self.dataOut.nProfiles = self.dataIn.nProfiles | |
150 | self.dataOut.nIncohInt = self.dataIn.nIncohInt |
|
150 | self.dataOut.nIncohInt = self.dataIn.nIncohInt | |
151 | self.dataOut.nFFTPoints = self.dataIn.nFFTPoints |
|
151 | self.dataOut.nFFTPoints = self.dataIn.nFFTPoints | |
152 | self.dataOut.ippFactor = self.dataIn.ippFactor |
|
152 | self.dataOut.ippFactor = self.dataIn.ippFactor | |
153 | self.dataOut.abscissaList = self.dataIn.getVelRange(1) |
|
153 | self.dataOut.abscissaList = self.dataIn.getVelRange(1) | |
154 | self.dataOut.spc_noise = self.dataIn.getNoise() |
|
154 | self.dataOut.spc_noise = self.dataIn.getNoise() | |
155 | self.dataOut.spc_range = (self.dataIn.getFreqRange(1) , self.dataIn.getAcfRange(1) , self.dataIn.getVelRange(1)) |
|
155 | self.dataOut.spc_range = (self.dataIn.getFreqRange(1) , self.dataIn.getAcfRange(1) , self.dataIn.getVelRange(1)) | |
156 | # self.dataOut.normFactor = self.dataIn.normFactor |
|
156 | # self.dataOut.normFactor = self.dataIn.normFactor | |
157 | self.dataOut.pairsList = self.dataIn.pairsList |
|
157 | self.dataOut.pairsList = self.dataIn.pairsList | |
158 | self.dataOut.groupList = self.dataIn.pairsList |
|
158 | self.dataOut.groupList = self.dataIn.pairsList | |
159 | self.dataOut.flagNoData = False |
|
159 | self.dataOut.flagNoData = False | |
160 |
|
160 | |||
161 | if hasattr(self.dataIn, 'flagDataAsBlock'): |
|
161 | if hasattr(self.dataIn, 'flagDataAsBlock'): | |
162 | self.dataOut.flagDataAsBlock = self.dataIn.flagDataAsBlock |
|
162 | self.dataOut.flagDataAsBlock = self.dataIn.flagDataAsBlock | |
163 |
|
163 | |||
164 | if hasattr(self.dataIn, 'ChanDist'): #Distances of receiver channels |
|
164 | if hasattr(self.dataIn, 'ChanDist'): #Distances of receiver channels | |
165 | self.dataOut.ChanDist = self.dataIn.ChanDist |
|
165 | self.dataOut.ChanDist = self.dataIn.ChanDist | |
166 | else: self.dataOut.ChanDist = None |
|
166 | else: self.dataOut.ChanDist = None | |
167 |
|
167 | |||
168 | #if hasattr(self.dataIn, 'VelRange'): #Velocities range |
|
168 | #if hasattr(self.dataIn, 'VelRange'): #Velocities range | |
169 | # self.dataOut.VelRange = self.dataIn.VelRange |
|
169 | # self.dataOut.VelRange = self.dataIn.VelRange | |
170 | #else: self.dataOut.VelRange = None |
|
170 | #else: self.dataOut.VelRange = None | |
171 |
|
171 | |||
172 | if hasattr(self.dataIn, 'RadarConst'): #Radar Constant |
|
172 | if hasattr(self.dataIn, 'RadarConst'): #Radar Constant | |
173 | self.dataOut.RadarConst = self.dataIn.RadarConst |
|
173 | self.dataOut.RadarConst = self.dataIn.RadarConst | |
174 |
|
174 | |||
175 | if hasattr(self.dataIn, 'NPW'): #NPW |
|
175 | if hasattr(self.dataIn, 'NPW'): #NPW | |
176 | self.dataOut.NPW = self.dataIn.NPW |
|
176 | self.dataOut.NPW = self.dataIn.NPW | |
177 |
|
177 | |||
178 | if hasattr(self.dataIn, 'COFA'): #COFA |
|
178 | if hasattr(self.dataIn, 'COFA'): #COFA | |
179 | self.dataOut.COFA = self.dataIn.COFA |
|
179 | self.dataOut.COFA = self.dataIn.COFA | |
180 |
|
180 | |||
181 |
|
181 | |||
182 |
|
182 | |||
183 | #---------------------- Correlation Data --------------------------- |
|
183 | #---------------------- Correlation Data --------------------------- | |
184 |
|
184 | |||
185 | if self.dataIn.type == "Correlation": |
|
185 | if self.dataIn.type == "Correlation": | |
186 | acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.dataIn.splitFunctions() |
|
186 | acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.dataIn.splitFunctions() | |
187 |
|
187 | |||
188 | self.dataOut.data_pre = (self.dataIn.data_cf[acf_ind,:], self.dataIn.data_cf[ccf_ind,:,:]) |
|
188 | self.dataOut.data_pre = (self.dataIn.data_cf[acf_ind,:], self.dataIn.data_cf[ccf_ind,:,:]) | |
189 | self.dataOut.normFactor = (self.dataIn.normFactor[acf_ind,:], self.dataIn.normFactor[ccf_ind,:]) |
|
189 | self.dataOut.normFactor = (self.dataIn.normFactor[acf_ind,:], self.dataIn.normFactor[ccf_ind,:]) | |
190 | self.dataOut.groupList = (acf_pairs, ccf_pairs) |
|
190 | self.dataOut.groupList = (acf_pairs, ccf_pairs) | |
191 |
|
191 | |||
192 | self.dataOut.abscissaList = self.dataIn.lagRange |
|
192 | self.dataOut.abscissaList = self.dataIn.lagRange | |
193 | self.dataOut.noise = self.dataIn.noise |
|
193 | self.dataOut.noise = self.dataIn.noise | |
194 | self.dataOut.data_snr = self.dataIn.SNR |
|
194 | self.dataOut.data_snr = self.dataIn.SNR | |
195 | self.dataOut.flagNoData = False |
|
195 | self.dataOut.flagNoData = False | |
196 | self.dataOut.nAvg = self.dataIn.nAvg |
|
196 | self.dataOut.nAvg = self.dataIn.nAvg | |
197 |
|
197 | |||
198 | #---------------------- Parameters Data --------------------------- |
|
198 | #---------------------- Parameters Data --------------------------- | |
199 |
|
199 | |||
200 | if self.dataIn.type == "Parameters": |
|
200 | if self.dataIn.type == "Parameters": | |
201 | self.dataOut.copy(self.dataIn) |
|
201 | self.dataOut.copy(self.dataIn) | |
202 | self.dataOut.flagNoData = False |
|
202 | self.dataOut.flagNoData = False | |
203 | #print("yo si entre") |
|
203 | #print("yo si entre") | |
204 |
|
204 | |||
205 | return True |
|
205 | return True | |
206 |
|
206 | |||
207 | self.__updateObjFromInput() |
|
207 | self.__updateObjFromInput() | |
208 | #print("yo si entre2") |
|
208 | #print("yo si entre2") | |
209 |
|
209 | |||
210 | self.dataOut.utctimeInit = self.dataIn.utctime |
|
210 | self.dataOut.utctimeInit = self.dataIn.utctime | |
211 | self.dataOut.paramInterval = self.dataIn.timeInterval |
|
211 | self.dataOut.paramInterval = self.dataIn.timeInterval | |
212 | #print("soy spectra ",self.dataOut.utctimeInit) |
|
212 | #print("soy spectra ",self.dataOut.utctimeInit) | |
213 | return |
|
213 | return | |
214 |
|
214 | |||
215 |
|
215 | |||
216 | def target(tups): |
|
216 | def target(tups): | |
217 |
|
217 | |||
218 | obj, args = tups |
|
218 | obj, args = tups | |
219 |
|
219 | |||
220 | return obj.FitGau(args) |
|
220 | return obj.FitGau(args) | |
221 |
|
221 | |||
222 | class RemoveWideGC(Operation): |
|
222 | class RemoveWideGC(Operation): | |
223 | ''' This class remove the wide clutter and replace it with a simple interpolation points |
|
223 | ''' This class remove the wide clutter and replace it with a simple interpolation points | |
224 | This mainly applies to CLAIRE radar |
|
224 | This mainly applies to CLAIRE radar | |
225 |
|
225 | |||
226 | ClutterWidth : Width to look for the clutter peak |
|
226 | ClutterWidth : Width to look for the clutter peak | |
227 |
|
227 | |||
228 | Input: |
|
228 | Input: | |
229 |
|
229 | |||
230 | self.dataOut.data_pre : SPC and CSPC |
|
230 | self.dataOut.data_pre : SPC and CSPC | |
231 | self.dataOut.spc_range : To select wind and rainfall velocities |
|
231 | self.dataOut.spc_range : To select wind and rainfall velocities | |
232 |
|
232 | |||
233 | Affected: |
|
233 | Affected: | |
234 |
|
234 | |||
235 | self.dataOut.data_pre : It is used for the new SPC and CSPC ranges of wind |
|
235 | self.dataOut.data_pre : It is used for the new SPC and CSPC ranges of wind | |
236 |
|
236 | |||
237 | Written by D. ScipiΓ³n 25.02.2021 |
|
237 | Written by D. ScipiΓ³n 25.02.2021 | |
238 | ''' |
|
238 | ''' | |
239 | def __init__(self): |
|
239 | def __init__(self): | |
240 | Operation.__init__(self) |
|
240 | Operation.__init__(self) | |
241 | self.i = 0 |
|
241 | self.i = 0 | |
242 | self.ich = 0 |
|
242 | self.ich = 0 | |
243 | self.ir = 0 |
|
243 | self.ir = 0 | |
244 |
|
244 | |||
245 | def run(self, dataOut, ClutterWidth=2.5): |
|
245 | def run(self, dataOut, ClutterWidth=2.5): | |
246 | # print ('Entering RemoveWideGC ... ') |
|
246 | # print ('Entering RemoveWideGC ... ') | |
247 |
|
247 | |||
248 | self.spc = dataOut.data_pre[0].copy() |
|
248 | self.spc = dataOut.data_pre[0].copy() | |
249 | self.spc_out = dataOut.data_pre[0].copy() |
|
249 | self.spc_out = dataOut.data_pre[0].copy() | |
250 | self.Num_Chn = self.spc.shape[0] |
|
250 | self.Num_Chn = self.spc.shape[0] | |
251 | self.Num_Hei = self.spc.shape[2] |
|
251 | self.Num_Hei = self.spc.shape[2] | |
252 | VelRange = dataOut.spc_range[2][:-1] |
|
252 | VelRange = dataOut.spc_range[2][:-1] | |
253 | dv = VelRange[1]-VelRange[0] |
|
253 | dv = VelRange[1]-VelRange[0] | |
254 |
|
254 | |||
255 | # Find the velocities that corresponds to zero |
|
255 | # Find the velocities that corresponds to zero | |
256 | gc_values = numpy.squeeze(numpy.where(numpy.abs(VelRange) <= ClutterWidth)) |
|
256 | gc_values = numpy.squeeze(numpy.where(numpy.abs(VelRange) <= ClutterWidth)) | |
257 |
|
257 | |||
258 | # Removing novalid data from the spectra |
|
258 | # Removing novalid data from the spectra | |
259 | for ich in range(self.Num_Chn) : |
|
259 | for ich in range(self.Num_Chn) : | |
260 | for ir in range(self.Num_Hei) : |
|
260 | for ir in range(self.Num_Hei) : | |
261 | # Estimate the noise at each range |
|
261 | # Estimate the noise at each range | |
262 | HSn = hildebrand_sekhon(self.spc[ich,:,ir],dataOut.nIncohInt) |
|
262 | HSn = hildebrand_sekhon(self.spc[ich,:,ir],dataOut.nIncohInt) | |
263 |
|
263 | |||
264 | # Removing the noise floor at each range |
|
264 | # Removing the noise floor at each range | |
265 | novalid = numpy.where(self.spc[ich,:,ir] < HSn) |
|
265 | novalid = numpy.where(self.spc[ich,:,ir] < HSn) | |
266 | self.spc[ich,novalid,ir] = HSn |
|
266 | self.spc[ich,novalid,ir] = HSn | |
267 |
|
267 | |||
268 | junk = numpy.append(numpy.insert(numpy.squeeze(self.spc[ich,gc_values,ir]),0,HSn),HSn) |
|
268 | junk = numpy.append(numpy.insert(numpy.squeeze(self.spc[ich,gc_values,ir]),0,HSn),HSn) | |
269 | j1index = numpy.squeeze(numpy.where(numpy.diff(junk)>0)) |
|
269 | j1index = numpy.squeeze(numpy.where(numpy.diff(junk)>0)) | |
270 | j2index = numpy.squeeze(numpy.where(numpy.diff(junk)<0)) |
|
270 | j2index = numpy.squeeze(numpy.where(numpy.diff(junk)<0)) | |
271 | if ((numpy.size(j1index)<=1) | (numpy.size(j2index)<=1)) : |
|
271 | if ((numpy.size(j1index)<=1) | (numpy.size(j2index)<=1)) : | |
272 | continue |
|
272 | continue | |
273 | junk3 = numpy.squeeze(numpy.diff(j1index)) |
|
273 | junk3 = numpy.squeeze(numpy.diff(j1index)) | |
274 | junk4 = numpy.squeeze(numpy.diff(j2index)) |
|
274 | junk4 = numpy.squeeze(numpy.diff(j2index)) | |
275 |
|
275 | |||
276 | valleyindex = j2index[numpy.where(junk4>1)] |
|
276 | valleyindex = j2index[numpy.where(junk4>1)] | |
277 | peakindex = j1index[numpy.where(junk3>1)] |
|
277 | peakindex = j1index[numpy.where(junk3>1)] | |
278 |
|
278 | |||
279 | isvalid = numpy.squeeze(numpy.where(numpy.abs(VelRange[gc_values[peakindex]]) <= 2.5*dv)) |
|
279 | isvalid = numpy.squeeze(numpy.where(numpy.abs(VelRange[gc_values[peakindex]]) <= 2.5*dv)) | |
280 | if numpy.size(isvalid) == 0 : |
|
280 | if numpy.size(isvalid) == 0 : | |
281 | continue |
|
281 | continue | |
282 | if numpy.size(isvalid) >1 : |
|
282 | if numpy.size(isvalid) >1 : | |
283 | vindex = numpy.argmax(self.spc[ich,gc_values[peakindex[isvalid]],ir]) |
|
283 | vindex = numpy.argmax(self.spc[ich,gc_values[peakindex[isvalid]],ir]) | |
284 | isvalid = isvalid[vindex] |
|
284 | isvalid = isvalid[vindex] | |
285 |
|
285 | |||
286 | # clutter peak |
|
286 | # clutter peak | |
287 | gcpeak = peakindex[isvalid] |
|
287 | gcpeak = peakindex[isvalid] | |
288 | vl = numpy.where(valleyindex < gcpeak) |
|
288 | vl = numpy.where(valleyindex < gcpeak) | |
289 | if numpy.size(vl) == 0: |
|
289 | if numpy.size(vl) == 0: | |
290 | continue |
|
290 | continue | |
291 | gcvl = valleyindex[vl[0][-1]] |
|
291 | gcvl = valleyindex[vl[0][-1]] | |
292 | vr = numpy.where(valleyindex > gcpeak) |
|
292 | vr = numpy.where(valleyindex > gcpeak) | |
293 | if numpy.size(vr) == 0: |
|
293 | if numpy.size(vr) == 0: | |
294 | continue |
|
294 | continue | |
295 | gcvr = valleyindex[vr[0][0]] |
|
295 | gcvr = valleyindex[vr[0][0]] | |
296 |
|
296 | |||
297 | # Removing the clutter |
|
297 | # Removing the clutter | |
298 | interpindex = numpy.array([gc_values[gcvl], gc_values[gcvr]]) |
|
298 | interpindex = numpy.array([gc_values[gcvl], gc_values[gcvr]]) | |
299 | gcindex = gc_values[gcvl+1:gcvr-1] |
|
299 | gcindex = gc_values[gcvl+1:gcvr-1] | |
300 | self.spc_out[ich,gcindex,ir] = numpy.interp(VelRange[gcindex],VelRange[interpindex],self.spc[ich,interpindex,ir]) |
|
300 | self.spc_out[ich,gcindex,ir] = numpy.interp(VelRange[gcindex],VelRange[interpindex],self.spc[ich,interpindex,ir]) | |
301 |
|
301 | |||
302 | dataOut.data_pre[0] = self.spc_out |
|
302 | dataOut.data_pre[0] = self.spc_out | |
303 | #print ('Leaving RemoveWideGC ... ') |
|
303 | #print ('Leaving RemoveWideGC ... ') | |
304 | return dataOut |
|
304 | return dataOut | |
305 |
|
305 | |||
306 | class SpectralFilters(Operation): |
|
306 | class SpectralFilters(Operation): | |
307 | ''' This class allows to replace the novalid values with noise for each channel |
|
307 | ''' This class allows to replace the novalid values with noise for each channel | |
308 | This applies to CLAIRE RADAR |
|
308 | This applies to CLAIRE RADAR | |
309 |
|
309 | |||
310 | PositiveLimit : RightLimit of novalid data |
|
310 | PositiveLimit : RightLimit of novalid data | |
311 | NegativeLimit : LeftLimit of novalid data |
|
311 | NegativeLimit : LeftLimit of novalid data | |
312 |
|
312 | |||
313 | Input: |
|
313 | Input: | |
314 |
|
314 | |||
315 | self.dataOut.data_pre : SPC and CSPC |
|
315 | self.dataOut.data_pre : SPC and CSPC | |
316 | self.dataOut.spc_range : To select wind and rainfall velocities |
|
316 | self.dataOut.spc_range : To select wind and rainfall velocities | |
317 |
|
317 | |||
318 | Affected: |
|
318 | Affected: | |
319 |
|
319 | |||
320 | self.dataOut.data_pre : It is used for the new SPC and CSPC ranges of wind |
|
320 | self.dataOut.data_pre : It is used for the new SPC and CSPC ranges of wind | |
321 |
|
321 | |||
322 | Written by D. ScipiΓ³n 29.01.2021 |
|
322 | Written by D. ScipiΓ³n 29.01.2021 | |
323 | ''' |
|
323 | ''' | |
324 | def __init__(self): |
|
324 | def __init__(self): | |
325 | Operation.__init__(self) |
|
325 | Operation.__init__(self) | |
326 | self.i = 0 |
|
326 | self.i = 0 | |
327 |
|
327 | |||
328 | def run(self, dataOut, ): |
|
328 | def run(self, dataOut, ): | |
329 |
|
329 | |||
330 | self.spc = dataOut.data_pre[0].copy() |
|
330 | self.spc = dataOut.data_pre[0].copy() | |
331 | self.Num_Chn = self.spc.shape[0] |
|
331 | self.Num_Chn = self.spc.shape[0] | |
332 | VelRange = dataOut.spc_range[2] |
|
332 | VelRange = dataOut.spc_range[2] | |
333 |
|
333 | |||
334 | # novalid corresponds to data within the Negative and PositiveLimit |
|
334 | # novalid corresponds to data within the Negative and PositiveLimit | |
335 |
|
335 | |||
336 |
|
336 | |||
337 | # Removing novalid data from the spectra |
|
337 | # Removing novalid data from the spectra | |
338 | for i in range(self.Num_Chn): |
|
338 | for i in range(self.Num_Chn): | |
339 | self.spc[i,novalid,:] = dataOut.noise[i] |
|
339 | self.spc[i,novalid,:] = dataOut.noise[i] | |
340 | dataOut.data_pre[0] = self.spc |
|
340 | dataOut.data_pre[0] = self.spc | |
341 | return dataOut |
|
341 | return dataOut | |
342 |
|
342 | |||
343 | class GaussianFit(Operation): |
|
343 | class GaussianFit(Operation): | |
344 |
|
344 | |||
345 | ''' |
|
345 | ''' | |
346 | Function that fit of one and two generalized gaussians (gg) based |
|
346 | Function that fit of one and two generalized gaussians (gg) based | |
347 | on the PSD shape across an "power band" identified from a cumsum of |
|
347 | on the PSD shape across an "power band" identified from a cumsum of | |
348 | the measured spectrum - noise. |
|
348 | the measured spectrum - noise. | |
349 |
|
349 | |||
350 | Input: |
|
350 | Input: | |
351 | self.dataOut.data_pre : SelfSpectra |
|
351 | self.dataOut.data_pre : SelfSpectra | |
352 |
|
352 | |||
353 | Output: |
|
353 | Output: | |
354 | self.dataOut.SPCparam : SPC_ch1, SPC_ch2 |
|
354 | self.dataOut.SPCparam : SPC_ch1, SPC_ch2 | |
355 |
|
355 | |||
356 | ''' |
|
356 | ''' | |
357 | def __init__(self): |
|
357 | def __init__(self): | |
358 | Operation.__init__(self) |
|
358 | Operation.__init__(self) | |
359 | self.i=0 |
|
359 | self.i=0 | |
360 |
|
360 | |||
361 |
|
361 | |||
362 | # def run(self, dataOut, num_intg=7, pnoise=1., SNRlimit=-9): #num_intg: Incoherent integrations, pnoise: Noise, vel_arr: range of velocities, similar to the ftt points |
|
362 | # def run(self, dataOut, num_intg=7, pnoise=1., SNRlimit=-9): #num_intg: Incoherent integrations, pnoise: Noise, vel_arr: range of velocities, similar to the ftt points | |
363 | def run(self, dataOut, SNRdBlimit=-9, method='generalized'): |
|
363 | def run(self, dataOut, SNRdBlimit=-9, method='generalized'): | |
364 | """This routine will find a couple of generalized Gaussians to a power spectrum |
|
364 | """This routine will find a couple of generalized Gaussians to a power spectrum | |
365 | methods: generalized, squared |
|
365 | methods: generalized, squared | |
366 | input: spc |
|
366 | input: spc | |
367 | output: |
|
367 | output: | |
368 | noise, amplitude0,shift0,width0,p0,Amplitude1,shift1,width1,p1 |
|
368 | noise, amplitude0,shift0,width0,p0,Amplitude1,shift1,width1,p1 | |
369 | """ |
|
369 | """ | |
370 | print ('Entering ',method,' double Gaussian fit') |
|
370 | print ('Entering ',method,' double Gaussian fit') | |
371 | self.spc = dataOut.data_pre[0].copy() |
|
371 | self.spc = dataOut.data_pre[0].copy() | |
372 | self.Num_Hei = self.spc.shape[2] |
|
372 | self.Num_Hei = self.spc.shape[2] | |
373 | self.Num_Bin = self.spc.shape[1] |
|
373 | self.Num_Bin = self.spc.shape[1] | |
374 | self.Num_Chn = self.spc.shape[0] |
|
374 | self.Num_Chn = self.spc.shape[0] | |
375 |
|
375 | |||
376 | start_time = time.time() |
|
376 | start_time = time.time() | |
377 |
|
377 | |||
378 | pool = Pool(processes=self.Num_Chn) |
|
378 | pool = Pool(processes=self.Num_Chn) | |
379 | args = [(dataOut.spc_range[2], ich, dataOut.spc_noise[ich], dataOut.nIncohInt, SNRdBlimit) for ich in range(self.Num_Chn)] |
|
379 | args = [(dataOut.spc_range[2], ich, dataOut.spc_noise[ich], dataOut.nIncohInt, SNRdBlimit) for ich in range(self.Num_Chn)] | |
380 | objs = [self for __ in range(self.Num_Chn)] |
|
380 | objs = [self for __ in range(self.Num_Chn)] | |
381 | attrs = list(zip(objs, args)) |
|
381 | attrs = list(zip(objs, args)) | |
382 | DGauFitParam = pool.map(target, attrs) |
|
382 | DGauFitParam = pool.map(target, attrs) | |
383 | # Parameters: |
|
383 | # Parameters: | |
384 | # 0. Noise, 1. Amplitude, 2. Shift, 3. Width 4. Power |
|
384 | # 0. Noise, 1. Amplitude, 2. Shift, 3. Width 4. Power | |
385 | dataOut.DGauFitParams = numpy.asarray(DGauFitParam) |
|
385 | dataOut.DGauFitParams = numpy.asarray(DGauFitParam) | |
386 |
|
386 | |||
387 | # Double Gaussian Curves |
|
387 | # Double Gaussian Curves | |
388 | gau0 = numpy.zeros([self.Num_Chn,self.Num_Bin,self.Num_Hei]) |
|
388 | gau0 = numpy.zeros([self.Num_Chn,self.Num_Bin,self.Num_Hei]) | |
389 | gau0[:] = numpy.NaN |
|
389 | gau0[:] = numpy.NaN | |
390 | gau1 = numpy.zeros([self.Num_Chn,self.Num_Bin,self.Num_Hei]) |
|
390 | gau1 = numpy.zeros([self.Num_Chn,self.Num_Bin,self.Num_Hei]) | |
391 | gau1[:] = numpy.NaN |
|
391 | gau1[:] = numpy.NaN | |
392 | x_mtr = numpy.transpose(numpy.tile(dataOut.getVelRange(1)[:-1], (self.Num_Hei,1))) |
|
392 | x_mtr = numpy.transpose(numpy.tile(dataOut.getVelRange(1)[:-1], (self.Num_Hei,1))) | |
393 | for iCh in range(self.Num_Chn): |
|
393 | for iCh in range(self.Num_Chn): | |
394 | N0 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][0,:,0]] * self.Num_Bin)) |
|
394 | N0 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][0,:,0]] * self.Num_Bin)) | |
395 | N1 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][0,:,1]] * self.Num_Bin)) |
|
395 | N1 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][0,:,1]] * self.Num_Bin)) | |
396 | A0 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][1,:,0]] * self.Num_Bin)) |
|
396 | A0 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][1,:,0]] * self.Num_Bin)) | |
397 | A1 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][1,:,1]] * self.Num_Bin)) |
|
397 | A1 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][1,:,1]] * self.Num_Bin)) | |
398 | v0 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][2,:,0]] * self.Num_Bin)) |
|
398 | v0 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][2,:,0]] * self.Num_Bin)) | |
399 | v1 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][2,:,1]] * self.Num_Bin)) |
|
399 | v1 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][2,:,1]] * self.Num_Bin)) | |
400 | s0 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][3,:,0]] * self.Num_Bin)) |
|
400 | s0 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][3,:,0]] * self.Num_Bin)) | |
401 | s1 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][3,:,1]] * self.Num_Bin)) |
|
401 | s1 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][3,:,1]] * self.Num_Bin)) | |
402 | if method == 'genealized': |
|
402 | if method == 'genealized': | |
403 | p0 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][4,:,0]] * self.Num_Bin)) |
|
403 | p0 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][4,:,0]] * self.Num_Bin)) | |
404 | p1 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][4,:,1]] * self.Num_Bin)) |
|
404 | p1 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][4,:,1]] * self.Num_Bin)) | |
405 | elif method == 'squared': |
|
405 | elif method == 'squared': | |
406 | p0 = 2. |
|
406 | p0 = 2. | |
407 | p1 = 2. |
|
407 | p1 = 2. | |
408 | gau0[iCh] = A0*numpy.exp(-0.5*numpy.abs((x_mtr-v0)/s0)**p0)+N0 |
|
408 | gau0[iCh] = A0*numpy.exp(-0.5*numpy.abs((x_mtr-v0)/s0)**p0)+N0 | |
409 | gau1[iCh] = A1*numpy.exp(-0.5*numpy.abs((x_mtr-v1)/s1)**p1)+N1 |
|
409 | gau1[iCh] = A1*numpy.exp(-0.5*numpy.abs((x_mtr-v1)/s1)**p1)+N1 | |
410 | dataOut.GaussFit0 = gau0 |
|
410 | dataOut.GaussFit0 = gau0 | |
411 | dataOut.GaussFit1 = gau1 |
|
411 | dataOut.GaussFit1 = gau1 | |
412 |
|
412 | |||
413 | print('Leaving ',method ,' double Gaussian fit') |
|
413 | print('Leaving ',method ,' double Gaussian fit') | |
414 | return dataOut |
|
414 | return dataOut | |
415 |
|
415 | |||
416 | def FitGau(self, X): |
|
416 | def FitGau(self, X): | |
417 | # print('Entering FitGau') |
|
417 | # print('Entering FitGau') | |
418 | # Assigning the variables |
|
418 | # Assigning the variables | |
419 | Vrange, ch, wnoise, num_intg, SNRlimit = X |
|
419 | Vrange, ch, wnoise, num_intg, SNRlimit = X | |
420 | # Noise Limits |
|
420 | # Noise Limits | |
421 | noisebl = wnoise * 0.9 |
|
421 | noisebl = wnoise * 0.9 | |
422 | noisebh = wnoise * 1.1 |
|
422 | noisebh = wnoise * 1.1 | |
423 | # Radar Velocity |
|
423 | # Radar Velocity | |
424 | Va = max(Vrange) |
|
424 | Va = max(Vrange) | |
425 | deltav = Vrange[1] - Vrange[0] |
|
425 | deltav = Vrange[1] - Vrange[0] | |
426 | x = numpy.arange(self.Num_Bin) |
|
426 | x = numpy.arange(self.Num_Bin) | |
427 |
|
427 | |||
428 | # print ('stop 0') |
|
428 | # print ('stop 0') | |
429 |
|
429 | |||
430 | # 5 parameters, 2 Gaussians |
|
430 | # 5 parameters, 2 Gaussians | |
431 | DGauFitParam = numpy.zeros([5, self.Num_Hei,2]) |
|
431 | DGauFitParam = numpy.zeros([5, self.Num_Hei,2]) | |
432 | DGauFitParam[:] = numpy.NaN |
|
432 | DGauFitParam[:] = numpy.NaN | |
433 |
|
433 | |||
434 | # SPCparam = [] |
|
434 | # SPCparam = [] | |
435 | # SPC_ch1 = numpy.zeros([self.Num_Bin,self.Num_Hei]) |
|
435 | # SPC_ch1 = numpy.zeros([self.Num_Bin,self.Num_Hei]) | |
436 | # SPC_ch2 = numpy.zeros([self.Num_Bin,self.Num_Hei]) |
|
436 | # SPC_ch2 = numpy.zeros([self.Num_Bin,self.Num_Hei]) | |
437 | # SPC_ch1[:] = 0 #numpy.NaN |
|
437 | # SPC_ch1[:] = 0 #numpy.NaN | |
438 | # SPC_ch2[:] = 0 #numpy.NaN |
|
438 | # SPC_ch2[:] = 0 #numpy.NaN | |
439 | # print ('stop 1') |
|
439 | # print ('stop 1') | |
440 | for ht in range(self.Num_Hei): |
|
440 | for ht in range(self.Num_Hei): | |
441 | # print (ht) |
|
441 | # print (ht) | |
442 | # print ('stop 2') |
|
442 | # print ('stop 2') | |
443 | # Spectra at each range |
|
443 | # Spectra at each range | |
444 | spc = numpy.asarray(self.spc)[ch,:,ht] |
|
444 | spc = numpy.asarray(self.spc)[ch,:,ht] | |
445 | snr = ( spc.mean() - wnoise ) / wnoise |
|
445 | snr = ( spc.mean() - wnoise ) / wnoise | |
446 | snrdB = 10.*numpy.log10(snr) |
|
446 | snrdB = 10.*numpy.log10(snr) | |
447 |
|
447 | |||
448 | #print ('stop 3') |
|
448 | #print ('stop 3') | |
449 | if snrdB < SNRlimit : |
|
449 | if snrdB < SNRlimit : | |
450 | # snr = numpy.NaN |
|
450 | # snr = numpy.NaN | |
451 | # SPC_ch1[:,ht] = 0#numpy.NaN |
|
451 | # SPC_ch1[:,ht] = 0#numpy.NaN | |
452 | # SPC_ch1[:,ht] = 0#numpy.NaN |
|
452 | # SPC_ch1[:,ht] = 0#numpy.NaN | |
453 | # SPCparam = (SPC_ch1,SPC_ch2) |
|
453 | # SPCparam = (SPC_ch1,SPC_ch2) | |
454 | # print ('SNR less than SNRth') |
|
454 | # print ('SNR less than SNRth') | |
455 | continue |
|
455 | continue | |
456 | # wnoise = hildebrand_sekhon(spc,num_intg) |
|
456 | # wnoise = hildebrand_sekhon(spc,num_intg) | |
457 | # print ('stop 2.01') |
|
457 | # print ('stop 2.01') | |
458 | ############################################# |
|
458 | ############################################# | |
459 | # normalizing spc and noise |
|
459 | # normalizing spc and noise | |
460 | # This part differs from gg1 |
|
460 | # This part differs from gg1 | |
461 | # spc_norm_max = max(spc) #commented by D. ScipiΓ³n 19.03.2021 |
|
461 | # spc_norm_max = max(spc) #commented by D. ScipiΓ³n 19.03.2021 | |
462 | #spc = spc / spc_norm_max |
|
462 | #spc = spc / spc_norm_max | |
463 | # pnoise = pnoise #/ spc_norm_max #commented by D. ScipiΓ³n 19.03.2021 |
|
463 | # pnoise = pnoise #/ spc_norm_max #commented by D. ScipiΓ³n 19.03.2021 | |
464 | ############################################# |
|
464 | ############################################# | |
465 |
|
465 | |||
466 | # print ('stop 2.1') |
|
466 | # print ('stop 2.1') | |
467 | fatspectra=1.0 |
|
467 | fatspectra=1.0 | |
468 | # noise per channel.... we might want to use the noise at each range |
|
468 | # noise per channel.... we might want to use the noise at each range | |
469 |
|
469 | |||
470 | # wnoise = noise_ #/ spc_norm_max #commented by D. ScipiΓ³n 19.03.2021 |
|
470 | # wnoise = noise_ #/ spc_norm_max #commented by D. ScipiΓ³n 19.03.2021 | |
471 | #wnoise,stdv,i_max,index =enoise(spc,num_intg) #noise estimate using Hildebrand Sekhon, only wnoise is used |
|
471 | #wnoise,stdv,i_max,index =enoise(spc,num_intg) #noise estimate using Hildebrand Sekhon, only wnoise is used | |
472 | #if wnoise>1.1*pnoise: # to be tested later |
|
472 | #if wnoise>1.1*pnoise: # to be tested later | |
473 | # wnoise=pnoise |
|
473 | # wnoise=pnoise | |
474 | # noisebl = wnoise*0.9 |
|
474 | # noisebl = wnoise*0.9 | |
475 | # noisebh = wnoise*1.1 |
|
475 | # noisebh = wnoise*1.1 | |
476 | spc = spc - wnoise # signal |
|
476 | spc = spc - wnoise # signal | |
477 |
|
477 | |||
478 | # print ('stop 2.2') |
|
478 | # print ('stop 2.2') | |
479 | minx = numpy.argmin(spc) |
|
479 | minx = numpy.argmin(spc) | |
480 | #spcs=spc.copy() |
|
480 | #spcs=spc.copy() | |
481 | spcs = numpy.roll(spc,-minx) |
|
481 | spcs = numpy.roll(spc,-minx) | |
482 | cum = numpy.cumsum(spcs) |
|
482 | cum = numpy.cumsum(spcs) | |
483 | # tot_noise = wnoise * self.Num_Bin #64; |
|
483 | # tot_noise = wnoise * self.Num_Bin #64; | |
484 |
|
484 | |||
485 | # print ('stop 2.3') |
|
485 | # print ('stop 2.3') | |
486 | # snr = sum(spcs) / tot_noise |
|
486 | # snr = sum(spcs) / tot_noise | |
487 | # snrdB = 10.*numpy.log10(snr) |
|
487 | # snrdB = 10.*numpy.log10(snr) | |
488 | #print ('stop 3') |
|
488 | #print ('stop 3') | |
489 | # if snrdB < SNRlimit : |
|
489 | # if snrdB < SNRlimit : | |
490 | # snr = numpy.NaN |
|
490 | # snr = numpy.NaN | |
491 | # SPC_ch1[:,ht] = 0#numpy.NaN |
|
491 | # SPC_ch1[:,ht] = 0#numpy.NaN | |
492 | # SPC_ch1[:,ht] = 0#numpy.NaN |
|
492 | # SPC_ch1[:,ht] = 0#numpy.NaN | |
493 | # SPCparam = (SPC_ch1,SPC_ch2) |
|
493 | # SPCparam = (SPC_ch1,SPC_ch2) | |
494 | # print ('SNR less than SNRth') |
|
494 | # print ('SNR less than SNRth') | |
495 | # continue |
|
495 | # continue | |
496 |
|
496 | |||
497 |
|
497 | |||
498 | #if snrdB<-18 or numpy.isnan(snrdB) or num_intg<4: |
|
498 | #if snrdB<-18 or numpy.isnan(snrdB) or num_intg<4: | |
499 | # return [None,]*4,[None,]*4,None,snrdB,None,None,[None,]*5,[None,]*9,None |
|
499 | # return [None,]*4,[None,]*4,None,snrdB,None,None,[None,]*5,[None,]*9,None | |
500 | # print ('stop 4') |
|
500 | # print ('stop 4') | |
501 | cummax = max(cum) |
|
501 | cummax = max(cum) | |
502 | epsi = 0.08 * fatspectra # cumsum to narrow down the energy region |
|
502 | epsi = 0.08 * fatspectra # cumsum to narrow down the energy region | |
503 | cumlo = cummax * epsi |
|
503 | cumlo = cummax * epsi | |
504 | cumhi = cummax * (1-epsi) |
|
504 | cumhi = cummax * (1-epsi) | |
505 | powerindex = numpy.array(numpy.where(numpy.logical_and(cum>cumlo, cum<cumhi))[0]) |
|
505 | powerindex = numpy.array(numpy.where(numpy.logical_and(cum>cumlo, cum<cumhi))[0]) | |
506 |
|
506 | |||
507 | # print ('stop 5') |
|
507 | # print ('stop 5') | |
508 | if len(powerindex) < 1:# case for powerindex 0 |
|
508 | if len(powerindex) < 1:# case for powerindex 0 | |
509 | # print ('powerindex < 1') |
|
509 | # print ('powerindex < 1') | |
510 | continue |
|
510 | continue | |
511 | powerlo = powerindex[0] |
|
511 | powerlo = powerindex[0] | |
512 | powerhi = powerindex[-1] |
|
512 | powerhi = powerindex[-1] | |
513 | powerwidth = powerhi-powerlo |
|
513 | powerwidth = powerhi-powerlo | |
514 | if powerwidth <= 1: |
|
514 | if powerwidth <= 1: | |
515 | # print('powerwidth <= 1') |
|
515 | # print('powerwidth <= 1') | |
516 | continue |
|
516 | continue | |
517 |
|
517 | |||
518 | # print ('stop 6') |
|
518 | # print ('stop 6') | |
519 | firstpeak = powerlo + powerwidth/10.# first gaussian energy location |
|
519 | firstpeak = powerlo + powerwidth/10.# first gaussian energy location | |
520 | secondpeak = powerhi - powerwidth/10. #second gaussian energy location |
|
520 | secondpeak = powerhi - powerwidth/10. #second gaussian energy location | |
521 | midpeak = (firstpeak + secondpeak)/2. |
|
521 | midpeak = (firstpeak + secondpeak)/2. | |
522 | firstamp = spcs[int(firstpeak)] |
|
522 | firstamp = spcs[int(firstpeak)] | |
523 | secondamp = spcs[int(secondpeak)] |
|
523 | secondamp = spcs[int(secondpeak)] | |
524 | midamp = spcs[int(midpeak)] |
|
524 | midamp = spcs[int(midpeak)] | |
525 |
|
525 | |||
526 | y_data = spc + wnoise |
|
526 | y_data = spc + wnoise | |
527 |
|
527 | |||
528 | ''' single Gaussian ''' |
|
528 | ''' single Gaussian ''' | |
529 | shift0 = numpy.mod(midpeak+minx, self.Num_Bin ) |
|
529 | shift0 = numpy.mod(midpeak+minx, self.Num_Bin ) | |
530 | width0 = powerwidth/4.#Initialization entire power of spectrum divided by 4 |
|
530 | width0 = powerwidth/4.#Initialization entire power of spectrum divided by 4 | |
531 | power0 = 2. |
|
531 | power0 = 2. | |
532 | amplitude0 = midamp |
|
532 | amplitude0 = midamp | |
533 | state0 = [shift0,width0,amplitude0,power0,wnoise] |
|
533 | state0 = [shift0,width0,amplitude0,power0,wnoise] | |
534 | bnds = ((0,self.Num_Bin-1),(1,powerwidth),(0,None),(0.5,3.),(noisebl,noisebh)) |
|
534 | bnds = ((0,self.Num_Bin-1),(1,powerwidth),(0,None),(0.5,3.),(noisebl,noisebh)) | |
535 | lsq1 = fmin_l_bfgs_b(self.misfit1, state0, args=(y_data,x,num_intg), bounds=bnds, approx_grad=True) |
|
535 | lsq1 = fmin_l_bfgs_b(self.misfit1, state0, args=(y_data,x,num_intg), bounds=bnds, approx_grad=True) | |
536 | # print ('stop 7.1') |
|
536 | # print ('stop 7.1') | |
537 | # print (bnds) |
|
537 | # print (bnds) | |
538 |
|
538 | |||
539 | chiSq1=lsq1[1] |
|
539 | chiSq1=lsq1[1] | |
540 |
|
540 | |||
541 | # print ('stop 8') |
|
541 | # print ('stop 8') | |
542 | if fatspectra<1.0 and powerwidth<4: |
|
542 | if fatspectra<1.0 and powerwidth<4: | |
543 | choice=0 |
|
543 | choice=0 | |
544 | Amplitude0=lsq1[0][2] |
|
544 | Amplitude0=lsq1[0][2] | |
545 | shift0=lsq1[0][0] |
|
545 | shift0=lsq1[0][0] | |
546 | width0=lsq1[0][1] |
|
546 | width0=lsq1[0][1] | |
547 | p0=lsq1[0][3] |
|
547 | p0=lsq1[0][3] | |
548 | Amplitude1=0. |
|
548 | Amplitude1=0. | |
549 | shift1=0. |
|
549 | shift1=0. | |
550 | width1=0. |
|
550 | width1=0. | |
551 | p1=0. |
|
551 | p1=0. | |
552 | noise=lsq1[0][4] |
|
552 | noise=lsq1[0][4] | |
553 | #return (numpy.array([shift0,width0,Amplitude0,p0]), |
|
553 | #return (numpy.array([shift0,width0,Amplitude0,p0]), | |
554 | # numpy.array([shift1,width1,Amplitude1,p1]),noise,snrdB,chiSq1,6.,sigmas1,[None,]*9,choice) |
|
554 | # numpy.array([shift1,width1,Amplitude1,p1]),noise,snrdB,chiSq1,6.,sigmas1,[None,]*9,choice) | |
555 |
|
555 | |||
556 | # print ('stop 9') |
|
556 | # print ('stop 9') | |
557 | ''' two Gaussians ''' |
|
557 | ''' two Gaussians ''' | |
558 | #shift0=numpy.mod(firstpeak+minx,64); shift1=numpy.mod(secondpeak+minx,64) |
|
558 | #shift0=numpy.mod(firstpeak+minx,64); shift1=numpy.mod(secondpeak+minx,64) | |
559 | shift0 = numpy.mod(firstpeak+minx, self.Num_Bin ) |
|
559 | shift0 = numpy.mod(firstpeak+minx, self.Num_Bin ) | |
560 | shift1 = numpy.mod(secondpeak+minx, self.Num_Bin ) |
|
560 | shift1 = numpy.mod(secondpeak+minx, self.Num_Bin ) | |
561 | width0 = powerwidth/6. |
|
561 | width0 = powerwidth/6. | |
562 | width1 = width0 |
|
562 | width1 = width0 | |
563 | power0 = 2. |
|
563 | power0 = 2. | |
564 | power1 = power0 |
|
564 | power1 = power0 | |
565 | amplitude0 = firstamp |
|
565 | amplitude0 = firstamp | |
566 | amplitude1 = secondamp |
|
566 | amplitude1 = secondamp | |
567 | state0 = [shift0,width0,amplitude0,power0,shift1,width1,amplitude1,power1,wnoise] |
|
567 | state0 = [shift0,width0,amplitude0,power0,shift1,width1,amplitude1,power1,wnoise] | |
568 | #bnds=((0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(noisebl,noisebh)) |
|
568 | #bnds=((0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(noisebl,noisebh)) | |
569 | 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)) |
|
569 | 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)) | |
570 | #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)) |
|
570 | #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)) | |
571 |
|
571 | |||
572 | # print ('stop 10') |
|
572 | # print ('stop 10') | |
573 | lsq2 = fmin_l_bfgs_b( self.misfit2 , state0 , args=(y_data,x,num_intg) , bounds=bnds , approx_grad=True ) |
|
573 | lsq2 = fmin_l_bfgs_b( self.misfit2 , state0 , args=(y_data,x,num_intg) , bounds=bnds , approx_grad=True ) | |
574 |
|
574 | |||
575 | # print ('stop 11') |
|
575 | # print ('stop 11') | |
576 | chiSq2 = lsq2[1] |
|
576 | chiSq2 = lsq2[1] | |
577 |
|
577 | |||
578 | # print ('stop 12') |
|
578 | # print ('stop 12') | |
579 |
|
579 | |||
580 | 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) |
|
580 | 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) | |
581 |
|
581 | |||
582 | # print ('stop 13') |
|
582 | # print ('stop 13') | |
583 | if snrdB>-12: # when SNR is strong pick the peak with least shift (LOS velocity) error |
|
583 | if snrdB>-12: # when SNR is strong pick the peak with least shift (LOS velocity) error | |
584 | if oneG: |
|
584 | if oneG: | |
585 | choice = 0 |
|
585 | choice = 0 | |
586 | else: |
|
586 | else: | |
587 | w1 = lsq2[0][1]; w2 = lsq2[0][5] |
|
587 | w1 = lsq2[0][1]; w2 = lsq2[0][5] | |
588 | a1 = lsq2[0][2]; a2 = lsq2[0][6] |
|
588 | a1 = lsq2[0][2]; a2 = lsq2[0][6] | |
589 | p1 = lsq2[0][3]; p2 = lsq2[0][7] |
|
589 | p1 = lsq2[0][3]; p2 = lsq2[0][7] | |
590 | s1 = (2**(1+1./p1))*scipy.special.gamma(1./p1)/p1 |
|
590 | s1 = (2**(1+1./p1))*scipy.special.gamma(1./p1)/p1 | |
591 | s2 = (2**(1+1./p2))*scipy.special.gamma(1./p2)/p2 |
|
591 | s2 = (2**(1+1./p2))*scipy.special.gamma(1./p2)/p2 | |
592 | gp1 = a1*w1*s1; gp2 = a2*w2*s2 # power content of each ggaussian with proper p scaling |
|
592 | gp1 = a1*w1*s1; gp2 = a2*w2*s2 # power content of each ggaussian with proper p scaling | |
593 |
|
593 | |||
594 | if gp1>gp2: |
|
594 | if gp1>gp2: | |
595 | if a1>0.7*a2: |
|
595 | if a1>0.7*a2: | |
596 | choice = 1 |
|
596 | choice = 1 | |
597 | else: |
|
597 | else: | |
598 | choice = 2 |
|
598 | choice = 2 | |
599 | elif gp2>gp1: |
|
599 | elif gp2>gp1: | |
600 | if a2>0.7*a1: |
|
600 | if a2>0.7*a1: | |
601 | choice = 2 |
|
601 | choice = 2 | |
602 | else: |
|
602 | else: | |
603 | choice = 1 |
|
603 | choice = 1 | |
604 | else: |
|
604 | else: | |
605 | choice = numpy.argmax([a1,a2])+1 |
|
605 | choice = numpy.argmax([a1,a2])+1 | |
606 | #else: |
|
606 | #else: | |
607 | #choice=argmin([std2a,std2b])+1 |
|
607 | #choice=argmin([std2a,std2b])+1 | |
608 |
|
608 | |||
609 | else: # with low SNR go to the most energetic peak |
|
609 | else: # with low SNR go to the most energetic peak | |
610 | choice = numpy.argmax([lsq1[0][2]*lsq1[0][1],lsq2[0][2]*lsq2[0][1],lsq2[0][6]*lsq2[0][5]]) |
|
610 | choice = numpy.argmax([lsq1[0][2]*lsq1[0][1],lsq2[0][2]*lsq2[0][1],lsq2[0][6]*lsq2[0][5]]) | |
611 |
|
611 | |||
612 | # print ('stop 14') |
|
612 | # print ('stop 14') | |
613 | shift0 = lsq2[0][0] |
|
613 | shift0 = lsq2[0][0] | |
614 | vel0 = Vrange[0] + shift0 * deltav |
|
614 | vel0 = Vrange[0] + shift0 * deltav | |
615 | shift1 = lsq2[0][4] |
|
615 | shift1 = lsq2[0][4] | |
616 | # vel1=Vrange[0] + shift1 * deltav |
|
616 | # vel1=Vrange[0] + shift1 * deltav | |
617 |
|
617 | |||
618 | # max_vel = 1.0 |
|
618 | # max_vel = 1.0 | |
619 | # Va = max(Vrange) |
|
619 | # Va = max(Vrange) | |
620 | # deltav = Vrange[1]-Vrange[0] |
|
620 | # deltav = Vrange[1]-Vrange[0] | |
621 | # print ('stop 15') |
|
621 | # print ('stop 15') | |
622 | #first peak will be 0, second peak will be 1 |
|
622 | #first peak will be 0, second peak will be 1 | |
623 | # if vel0 > -1.0 and vel0 < max_vel : #first peak is in the correct range # Commented by D.ScipiΓ³n 19.03.2021 |
|
623 | # if vel0 > -1.0 and vel0 < max_vel : #first peak is in the correct range # Commented by D.ScipiΓ³n 19.03.2021 | |
624 | if vel0 > -Va and vel0 < Va : #first peak is in the correct range |
|
624 | if vel0 > -Va and vel0 < Va : #first peak is in the correct range | |
625 | shift0 = lsq2[0][0] |
|
625 | shift0 = lsq2[0][0] | |
626 | width0 = lsq2[0][1] |
|
626 | width0 = lsq2[0][1] | |
627 | Amplitude0 = lsq2[0][2] |
|
627 | Amplitude0 = lsq2[0][2] | |
628 | p0 = lsq2[0][3] |
|
628 | p0 = lsq2[0][3] | |
629 |
|
629 | |||
630 | shift1 = lsq2[0][4] |
|
630 | shift1 = lsq2[0][4] | |
631 | width1 = lsq2[0][5] |
|
631 | width1 = lsq2[0][5] | |
632 | Amplitude1 = lsq2[0][6] |
|
632 | Amplitude1 = lsq2[0][6] | |
633 | p1 = lsq2[0][7] |
|
633 | p1 = lsq2[0][7] | |
634 | noise = lsq2[0][8] |
|
634 | noise = lsq2[0][8] | |
635 | else: |
|
635 | else: | |
636 | shift1 = lsq2[0][0] |
|
636 | shift1 = lsq2[0][0] | |
637 | width1 = lsq2[0][1] |
|
637 | width1 = lsq2[0][1] | |
638 | Amplitude1 = lsq2[0][2] |
|
638 | Amplitude1 = lsq2[0][2] | |
639 | p1 = lsq2[0][3] |
|
639 | p1 = lsq2[0][3] | |
640 |
|
640 | |||
641 | shift0 = lsq2[0][4] |
|
641 | shift0 = lsq2[0][4] | |
642 | width0 = lsq2[0][5] |
|
642 | width0 = lsq2[0][5] | |
643 | Amplitude0 = lsq2[0][6] |
|
643 | Amplitude0 = lsq2[0][6] | |
644 | p0 = lsq2[0][7] |
|
644 | p0 = lsq2[0][7] | |
645 | noise = lsq2[0][8] |
|
645 | noise = lsq2[0][8] | |
646 |
|
646 | |||
647 | if Amplitude0<0.05: # in case the peak is noise |
|
647 | if Amplitude0<0.05: # in case the peak is noise | |
648 | shift0,width0,Amplitude0,p0 = 4*[numpy.NaN] |
|
648 | shift0,width0,Amplitude0,p0 = 4*[numpy.NaN] | |
649 | if Amplitude1<0.05: |
|
649 | if Amplitude1<0.05: | |
650 | shift1,width1,Amplitude1,p1 = 4*[numpy.NaN] |
|
650 | shift1,width1,Amplitude1,p1 = 4*[numpy.NaN] | |
651 |
|
651 | |||
652 | # print ('stop 16 ') |
|
652 | # print ('stop 16 ') | |
653 | # SPC_ch1[:,ht] = noise + Amplitude0*numpy.exp(-0.5*(abs(x-shift0)/width0)**p0) |
|
653 | # SPC_ch1[:,ht] = noise + Amplitude0*numpy.exp(-0.5*(abs(x-shift0)/width0)**p0) | |
654 | # SPC_ch2[:,ht] = noise + Amplitude1*numpy.exp(-0.5*(abs(x-shift1)/width1)**p1) |
|
654 | # SPC_ch2[:,ht] = noise + Amplitude1*numpy.exp(-0.5*(abs(x-shift1)/width1)**p1) | |
655 | # SPCparam = (SPC_ch1,SPC_ch2) |
|
655 | # SPCparam = (SPC_ch1,SPC_ch2) | |
656 |
|
656 | |||
657 | DGauFitParam[0,ht,0] = noise |
|
657 | DGauFitParam[0,ht,0] = noise | |
658 | DGauFitParam[0,ht,1] = noise |
|
658 | DGauFitParam[0,ht,1] = noise | |
659 | DGauFitParam[1,ht,0] = Amplitude0 |
|
659 | DGauFitParam[1,ht,0] = Amplitude0 | |
660 | DGauFitParam[1,ht,1] = Amplitude1 |
|
660 | DGauFitParam[1,ht,1] = Amplitude1 | |
661 | DGauFitParam[2,ht,0] = Vrange[0] + shift0 * deltav |
|
661 | DGauFitParam[2,ht,0] = Vrange[0] + shift0 * deltav | |
662 | DGauFitParam[2,ht,1] = Vrange[0] + shift1 * deltav |
|
662 | DGauFitParam[2,ht,1] = Vrange[0] + shift1 * deltav | |
663 | DGauFitParam[3,ht,0] = width0 * deltav |
|
663 | DGauFitParam[3,ht,0] = width0 * deltav | |
664 | DGauFitParam[3,ht,1] = width1 * deltav |
|
664 | DGauFitParam[3,ht,1] = width1 * deltav | |
665 | DGauFitParam[4,ht,0] = p0 |
|
665 | DGauFitParam[4,ht,0] = p0 | |
666 | DGauFitParam[4,ht,1] = p1 |
|
666 | DGauFitParam[4,ht,1] = p1 | |
667 |
|
667 | |||
668 | # print (DGauFitParam.shape) |
|
668 | # print (DGauFitParam.shape) | |
669 | # print ('Leaving FitGau') |
|
669 | # print ('Leaving FitGau') | |
670 | return DGauFitParam |
|
670 | return DGauFitParam | |
671 | # return SPCparam |
|
671 | # return SPCparam | |
672 | # return GauSPC |
|
672 | # return GauSPC | |
673 |
|
673 | |||
674 | def y_model1(self,x,state): |
|
674 | def y_model1(self,x,state): | |
675 | shift0, width0, amplitude0, power0, noise = state |
|
675 | shift0, width0, amplitude0, power0, noise = state | |
676 | model0 = amplitude0*numpy.exp(-0.5*abs((x - shift0)/width0)**power0) |
|
676 | model0 = amplitude0*numpy.exp(-0.5*abs((x - shift0)/width0)**power0) | |
677 | model0u = amplitude0*numpy.exp(-0.5*abs((x - shift0 - self.Num_Bin)/width0)**power0) |
|
677 | model0u = amplitude0*numpy.exp(-0.5*abs((x - shift0 - self.Num_Bin)/width0)**power0) | |
678 | model0d = amplitude0*numpy.exp(-0.5*abs((x - shift0 + self.Num_Bin)/width0)**power0) |
|
678 | model0d = amplitude0*numpy.exp(-0.5*abs((x - shift0 + self.Num_Bin)/width0)**power0) | |
679 | return model0 + model0u + model0d + noise |
|
679 | return model0 + model0u + model0d + noise | |
680 |
|
680 | |||
681 | def y_model2(self,x,state): #Equation for two generalized Gaussians with Nyquist |
|
681 | def y_model2(self,x,state): #Equation for two generalized Gaussians with Nyquist | |
682 | shift0, width0, amplitude0, power0, shift1, width1, amplitude1, power1, noise = state |
|
682 | shift0, width0, amplitude0, power0, shift1, width1, amplitude1, power1, noise = state | |
683 | model0 = amplitude0*numpy.exp(-0.5*abs((x-shift0)/width0)**power0) |
|
683 | model0 = amplitude0*numpy.exp(-0.5*abs((x-shift0)/width0)**power0) | |
684 | model0u = amplitude0*numpy.exp(-0.5*abs((x - shift0 - self.Num_Bin)/width0)**power0) |
|
684 | model0u = amplitude0*numpy.exp(-0.5*abs((x - shift0 - self.Num_Bin)/width0)**power0) | |
685 | model0d = amplitude0*numpy.exp(-0.5*abs((x - shift0 + self.Num_Bin)/width0)**power0) |
|
685 | model0d = amplitude0*numpy.exp(-0.5*abs((x - shift0 + self.Num_Bin)/width0)**power0) | |
686 |
|
686 | |||
687 | model1 = amplitude1*numpy.exp(-0.5*abs((x - shift1)/width1)**power1) |
|
687 | model1 = amplitude1*numpy.exp(-0.5*abs((x - shift1)/width1)**power1) | |
688 | model1u = amplitude1*numpy.exp(-0.5*abs((x - shift1 - self.Num_Bin)/width1)**power1) |
|
688 | model1u = amplitude1*numpy.exp(-0.5*abs((x - shift1 - self.Num_Bin)/width1)**power1) | |
689 | model1d = amplitude1*numpy.exp(-0.5*abs((x - shift1 + self.Num_Bin)/width1)**power1) |
|
689 | model1d = amplitude1*numpy.exp(-0.5*abs((x - shift1 + self.Num_Bin)/width1)**power1) | |
690 | return model0 + model0u + model0d + model1 + model1u + model1d + noise |
|
690 | return model0 + model0u + model0d + model1 + model1u + model1d + noise | |
691 |
|
691 | |||
692 | 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. |
|
692 | 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. | |
693 |
|
693 | |||
694 | return num_intg*sum((numpy.log(y_data)-numpy.log(self.y_model1(x,state)))**2)#/(64-5.) # /(64-5.) can be commented |
|
694 | return num_intg*sum((numpy.log(y_data)-numpy.log(self.y_model1(x,state)))**2)#/(64-5.) # /(64-5.) can be commented | |
695 |
|
695 | |||
696 | def misfit2(self,state,y_data,x,num_intg): |
|
696 | def misfit2(self,state,y_data,x,num_intg): | |
697 | return num_intg*sum((numpy.log(y_data)-numpy.log(self.y_model2(x,state)))**2)#/(64-9.) |
|
697 | return num_intg*sum((numpy.log(y_data)-numpy.log(self.y_model2(x,state)))**2)#/(64-9.) | |
698 |
|
698 | |||
699 |
|
699 | |||
700 |
|
700 | |||
701 | class PrecipitationProc(Operation): |
|
701 | class PrecipitationProc(Operation): | |
702 |
|
702 | |||
703 | ''' |
|
703 | ''' | |
704 | Operator that estimates Reflectivity factor (Z), and estimates rainfall Rate (R) |
|
704 | Operator that estimates Reflectivity factor (Z), and estimates rainfall Rate (R) | |
705 |
|
705 | |||
706 | Input: |
|
706 | Input: | |
707 | self.dataOut.data_pre : SelfSpectra |
|
707 | self.dataOut.data_pre : SelfSpectra | |
708 |
|
708 | |||
709 | Output: |
|
709 | Output: | |
710 |
|
710 | |||
711 | self.dataOut.data_output : Reflectivity factor, rainfall Rate |
|
711 | self.dataOut.data_output : Reflectivity factor, rainfall Rate | |
712 |
|
712 | |||
713 |
|
713 | |||
714 | Parameters affected: |
|
714 | Parameters affected: | |
715 | ''' |
|
715 | ''' | |
716 |
|
716 | |||
717 | def __init__(self): |
|
717 | def __init__(self): | |
718 | Operation.__init__(self) |
|
718 | Operation.__init__(self) | |
719 | self.i=0 |
|
719 | self.i=0 | |
720 |
|
720 | |||
721 | def run(self, dataOut, radar=None, Pt=5000, Gt=295.1209, Gr=70.7945, Lambda=0.6741, aL=2.5118, |
|
721 | def run(self, dataOut, radar=None, Pt=5000, Gt=295.1209, Gr=70.7945, Lambda=0.6741, aL=2.5118, | |
722 | tauW=4e-06, ThetaT=0.1656317, ThetaR=0.36774087, Km2 = 0.93, Altitude=3350,SNRdBlimit=-30): |
|
722 | tauW=4e-06, ThetaT=0.1656317, ThetaR=0.36774087, Km2 = 0.93, Altitude=3350,SNRdBlimit=-30): | |
723 |
|
723 | |||
724 | # print ('Entering PrecepitationProc ... ') |
|
724 | # print ('Entering PrecepitationProc ... ') | |
725 |
|
725 | |||
726 | if radar == "MIRA35C" : |
|
726 | if radar == "MIRA35C" : | |
727 |
|
727 | |||
728 | self.spc = dataOut.data_pre[0].copy() |
|
728 | self.spc = dataOut.data_pre[0].copy() | |
729 | self.Num_Hei = self.spc.shape[2] |
|
729 | self.Num_Hei = self.spc.shape[2] | |
730 | self.Num_Bin = self.spc.shape[1] |
|
730 | self.Num_Bin = self.spc.shape[1] | |
731 | self.Num_Chn = self.spc.shape[0] |
|
731 | self.Num_Chn = self.spc.shape[0] | |
732 | Ze = self.dBZeMODE2(dataOut) |
|
732 | Ze = self.dBZeMODE2(dataOut) | |
733 |
|
733 | |||
734 | else: |
|
734 | else: | |
735 |
|
735 | |||
736 | self.spc = dataOut.data_pre[0].copy() |
|
736 | self.spc = dataOut.data_pre[0].copy() | |
737 |
|
737 | |||
738 | #NOTA SE DEBE REMOVER EL RANGO DEL PULSO TX |
|
738 | #NOTA SE DEBE REMOVER EL RANGO DEL PULSO TX | |
739 | self.spc[:,:,0:7]= numpy.NaN |
|
739 | self.spc[:,:,0:7]= numpy.NaN | |
740 |
|
740 | |||
741 | self.Num_Hei = self.spc.shape[2] |
|
741 | self.Num_Hei = self.spc.shape[2] | |
742 | self.Num_Bin = self.spc.shape[1] |
|
742 | self.Num_Bin = self.spc.shape[1] | |
743 | self.Num_Chn = self.spc.shape[0] |
|
743 | self.Num_Chn = self.spc.shape[0] | |
744 |
|
744 | |||
745 | VelRange = dataOut.spc_range[2] |
|
745 | VelRange = dataOut.spc_range[2] | |
746 |
|
746 | |||
747 | ''' Se obtiene la constante del RADAR ''' |
|
747 | ''' Se obtiene la constante del RADAR ''' | |
748 |
|
748 | |||
749 | self.Pt = Pt |
|
749 | self.Pt = Pt | |
750 | self.Gt = Gt |
|
750 | self.Gt = Gt | |
751 | self.Gr = Gr |
|
751 | self.Gr = Gr | |
752 | self.Lambda = Lambda |
|
752 | self.Lambda = Lambda | |
753 | self.aL = aL |
|
753 | self.aL = aL | |
754 | self.tauW = tauW |
|
754 | self.tauW = tauW | |
755 | self.ThetaT = ThetaT |
|
755 | self.ThetaT = ThetaT | |
756 | self.ThetaR = ThetaR |
|
756 | self.ThetaR = ThetaR | |
757 | self.GSys = 10**(36.63/10) # Ganancia de los LNA 36.63 dB |
|
757 | self.GSys = 10**(36.63/10) # Ganancia de los LNA 36.63 dB | |
758 | self.lt = 10**(1.67/10) # Perdida en cables Tx 1.67 dB |
|
758 | self.lt = 10**(1.67/10) # Perdida en cables Tx 1.67 dB | |
759 | self.lr = 10**(5.73/10) # Perdida en cables Rx 5.73 dB |
|
759 | self.lr = 10**(5.73/10) # Perdida en cables Rx 5.73 dB | |
760 |
|
760 | |||
761 | Numerator = ( (4*numpy.pi)**3 * aL**2 * 16 * numpy.log(2) ) |
|
761 | Numerator = ( (4*numpy.pi)**3 * aL**2 * 16 * numpy.log(2) ) | |
762 | Denominator = ( Pt * Gt * Gr * Lambda**2 * SPEED_OF_LIGHT * tauW * numpy.pi * ThetaT * ThetaR) |
|
762 | Denominator = ( Pt * Gt * Gr * Lambda**2 * SPEED_OF_LIGHT * tauW * numpy.pi * ThetaT * ThetaR) | |
763 | RadarConstant = 10e-26 * Numerator / Denominator # |
|
763 | RadarConstant = 10e-26 * Numerator / Denominator # | |
764 | ExpConstant = 10**(40/10) #Constante Experimental |
|
764 | ExpConstant = 10**(40/10) #Constante Experimental | |
765 |
|
765 | |||
766 | SignalPower = numpy.zeros([self.Num_Chn,self.Num_Bin,self.Num_Hei]) |
|
766 | SignalPower = numpy.zeros([self.Num_Chn,self.Num_Bin,self.Num_Hei]) | |
767 | for i in range(self.Num_Chn): |
|
767 | for i in range(self.Num_Chn): | |
768 | SignalPower[i,:,:] = self.spc[i,:,:] - dataOut.noise[i] |
|
768 | SignalPower[i,:,:] = self.spc[i,:,:] - dataOut.noise[i] | |
769 | SignalPower[numpy.where(SignalPower < 0)] = 1e-20 |
|
769 | SignalPower[numpy.where(SignalPower < 0)] = 1e-20 | |
770 |
|
770 | |||
771 | SPCmean = numpy.mean(SignalPower, 0) |
|
771 | SPCmean = numpy.mean(SignalPower, 0) | |
772 | Pr = SPCmean[:,:]/dataOut.normFactor |
|
772 | Pr = SPCmean[:,:]/dataOut.normFactor | |
773 |
|
773 | |||
774 | # Declaring auxiliary variables |
|
774 | # Declaring auxiliary variables | |
775 | Range = dataOut.heightList*1000. #Range in m |
|
775 | Range = dataOut.heightList*1000. #Range in m | |
776 | # replicate the heightlist to obtain a matrix [Num_Bin,Num_Hei] |
|
776 | # replicate the heightlist to obtain a matrix [Num_Bin,Num_Hei] | |
777 | rMtrx = numpy.transpose(numpy.transpose([dataOut.heightList*1000.] * self.Num_Bin)) |
|
777 | rMtrx = numpy.transpose(numpy.transpose([dataOut.heightList*1000.] * self.Num_Bin)) | |
778 | zMtrx = rMtrx+Altitude |
|
778 | zMtrx = rMtrx+Altitude | |
779 | # replicate the VelRange to obtain a matrix [Num_Bin,Num_Hei] |
|
779 | # replicate the VelRange to obtain a matrix [Num_Bin,Num_Hei] | |
780 | VelMtrx = numpy.transpose(numpy.tile(VelRange[:-1], (self.Num_Hei,1))) |
|
780 | VelMtrx = numpy.transpose(numpy.tile(VelRange[:-1], (self.Num_Hei,1))) | |
781 |
|
781 | |||
782 | # height dependence to air density Foote and Du Toit (1969) |
|
782 | # height dependence to air density Foote and Du Toit (1969) | |
783 | delv_z = 1 + 3.68e-5 * zMtrx + 1.71e-9 * zMtrx**2 |
|
783 | delv_z = 1 + 3.68e-5 * zMtrx + 1.71e-9 * zMtrx**2 | |
784 | VMtrx = VelMtrx / delv_z #Normalized velocity |
|
784 | VMtrx = VelMtrx / delv_z #Normalized velocity | |
785 | VMtrx[numpy.where(VMtrx> 9.6)] = numpy.NaN |
|
785 | VMtrx[numpy.where(VMtrx> 9.6)] = numpy.NaN | |
786 | # Diameter is related to the fall speed of falling drops |
|
786 | # Diameter is related to the fall speed of falling drops | |
787 | D_Vz = -1.667 * numpy.log( 0.9369 - 0.097087 * VMtrx ) # D in [mm] |
|
787 | D_Vz = -1.667 * numpy.log( 0.9369 - 0.097087 * VMtrx ) # D in [mm] | |
788 | # Only valid for D>= 0.16 mm |
|
788 | # Only valid for D>= 0.16 mm | |
789 | D_Vz[numpy.where(D_Vz < 0.16)] = numpy.NaN |
|
789 | D_Vz[numpy.where(D_Vz < 0.16)] = numpy.NaN | |
790 |
|
790 | |||
791 | #Calculate Radar Reflectivity ETAn |
|
791 | #Calculate Radar Reflectivity ETAn | |
792 | ETAn = (RadarConstant *ExpConstant) * Pr * rMtrx**2 #Reflectivity (ETA) |
|
792 | ETAn = (RadarConstant *ExpConstant) * Pr * rMtrx**2 #Reflectivity (ETA) | |
793 | ETAd = ETAn * 6.18 * exp( -0.6 * D_Vz ) * delv_z |
|
793 | ETAd = ETAn * 6.18 * exp( -0.6 * D_Vz ) * delv_z | |
794 | # Radar Cross Section |
|
794 | # Radar Cross Section | |
795 | sigmaD = Km2 * (D_Vz * 1e-3 )**6 * numpy.pi**5 / Lambda**4 |
|
795 | sigmaD = Km2 * (D_Vz * 1e-3 )**6 * numpy.pi**5 / Lambda**4 | |
796 | # Drop Size Distribution |
|
796 | # Drop Size Distribution | |
797 | DSD = ETAn / sigmaD |
|
797 | DSD = ETAn / sigmaD | |
798 | # Equivalente Reflectivy |
|
798 | # Equivalente Reflectivy | |
799 | Ze_eqn = numpy.nansum( DSD * D_Vz**6 ,axis=0) |
|
799 | Ze_eqn = numpy.nansum( DSD * D_Vz**6 ,axis=0) | |
800 | Ze_org = numpy.nansum(ETAn * Lambda**4, axis=0) / (1e-18*numpy.pi**5 * Km2) # [mm^6 /m^3] |
|
800 | Ze_org = numpy.nansum(ETAn * Lambda**4, axis=0) / (1e-18*numpy.pi**5 * Km2) # [mm^6 /m^3] | |
801 | # RainFall Rate |
|
801 | # RainFall Rate | |
802 | RR = 0.0006*numpy.pi * numpy.nansum( D_Vz**3 * DSD * VelMtrx ,0) #mm/hr |
|
802 | RR = 0.0006*numpy.pi * numpy.nansum( D_Vz**3 * DSD * VelMtrx ,0) #mm/hr | |
803 |
|
803 | |||
804 | # Censoring the data |
|
804 | # Censoring the data | |
805 | # Removing data with SNRth < 0dB se debe considerar el SNR por canal |
|
805 | # Removing data with SNRth < 0dB se debe considerar el SNR por canal | |
806 | SNRth = 10**(SNRdBlimit/10) #-30dB |
|
806 | SNRth = 10**(SNRdBlimit/10) #-30dB | |
807 | novalid = numpy.where((dataOut.data_snr[0,:] <SNRth) | (dataOut.data_snr[1,:] <SNRth) | (dataOut.data_snr[2,:] <SNRth)) # AND condition. Maybe OR condition better |
|
807 | novalid = numpy.where((dataOut.data_snr[0,:] <SNRth) | (dataOut.data_snr[1,:] <SNRth) | (dataOut.data_snr[2,:] <SNRth)) # AND condition. Maybe OR condition better | |
808 | W = numpy.nanmean(dataOut.data_dop,0) |
|
808 | W = numpy.nanmean(dataOut.data_dop,0) | |
809 | W[novalid] = numpy.NaN |
|
809 | W[novalid] = numpy.NaN | |
810 | Ze_org[novalid] = numpy.NaN |
|
810 | Ze_org[novalid] = numpy.NaN | |
811 | RR[novalid] = numpy.NaN |
|
811 | RR[novalid] = numpy.NaN | |
812 |
|
812 | |||
813 | dataOut.data_output = RR[8] |
|
813 | dataOut.data_output = RR[8] | |
814 | dataOut.data_param = numpy.ones([3,self.Num_Hei]) |
|
814 | dataOut.data_param = numpy.ones([3,self.Num_Hei]) | |
815 | dataOut.channelList = [0,1,2] |
|
815 | dataOut.channelList = [0,1,2] | |
816 |
|
816 | |||
817 | dataOut.data_param[0]=10*numpy.log10(Ze_org) |
|
817 | dataOut.data_param[0]=10*numpy.log10(Ze_org) | |
818 | dataOut.data_param[1]=-W |
|
818 | dataOut.data_param[1]=-W | |
819 | dataOut.data_param[2]=RR |
|
819 | dataOut.data_param[2]=RR | |
820 |
|
820 | |||
821 | # print ('Leaving PrecepitationProc ... ') |
|
821 | # print ('Leaving PrecepitationProc ... ') | |
822 | return dataOut |
|
822 | return dataOut | |
823 |
|
823 | |||
824 | def dBZeMODE2(self, dataOut): # Processing for MIRA35C |
|
824 | def dBZeMODE2(self, dataOut): # Processing for MIRA35C | |
825 |
|
825 | |||
826 | NPW = dataOut.NPW |
|
826 | NPW = dataOut.NPW | |
827 | COFA = dataOut.COFA |
|
827 | COFA = dataOut.COFA | |
828 |
|
828 | |||
829 | SNR = numpy.array([self.spc[0,:,:] / NPW[0]]) #, self.spc[1,:,:] / NPW[1]]) |
|
829 | SNR = numpy.array([self.spc[0,:,:] / NPW[0]]) #, self.spc[1,:,:] / NPW[1]]) | |
830 | RadarConst = dataOut.RadarConst |
|
830 | RadarConst = dataOut.RadarConst | |
831 | #frequency = 34.85*10**9 |
|
831 | #frequency = 34.85*10**9 | |
832 |
|
832 | |||
833 | ETA = numpy.zeros(([self.Num_Chn ,self.Num_Hei])) |
|
833 | ETA = numpy.zeros(([self.Num_Chn ,self.Num_Hei])) | |
834 | data_output = numpy.ones([self.Num_Chn , self.Num_Hei])*numpy.NaN |
|
834 | data_output = numpy.ones([self.Num_Chn , self.Num_Hei])*numpy.NaN | |
835 |
|
835 | |||
836 | ETA = numpy.sum(SNR,1) |
|
836 | ETA = numpy.sum(SNR,1) | |
837 |
|
837 | |||
838 | ETA = numpy.where(ETA != 0. , ETA, numpy.NaN) |
|
838 | ETA = numpy.where(ETA != 0. , ETA, numpy.NaN) | |
839 |
|
839 | |||
840 | Ze = numpy.ones([self.Num_Chn, self.Num_Hei] ) |
|
840 | Ze = numpy.ones([self.Num_Chn, self.Num_Hei] ) | |
841 |
|
841 | |||
842 | for r in range(self.Num_Hei): |
|
842 | for r in range(self.Num_Hei): | |
843 |
|
843 | |||
844 | Ze[0,r] = ( ETA[0,r] ) * COFA[0,r][0] * RadarConst * ((r/5000.)**2) |
|
844 | Ze[0,r] = ( ETA[0,r] ) * COFA[0,r][0] * RadarConst * ((r/5000.)**2) | |
845 | #Ze[1,r] = ( ETA[1,r] ) * COFA[1,r][0] * RadarConst * ((r/5000.)**2) |
|
845 | #Ze[1,r] = ( ETA[1,r] ) * COFA[1,r][0] * RadarConst * ((r/5000.)**2) | |
846 |
|
846 | |||
847 | return Ze |
|
847 | return Ze | |
848 |
|
848 | |||
849 | # def GetRadarConstant(self): |
|
849 | # def GetRadarConstant(self): | |
850 | # |
|
850 | # | |
851 | # """ |
|
851 | # """ | |
852 | # Constants: |
|
852 | # Constants: | |
853 | # |
|
853 | # | |
854 | # Pt: Transmission Power dB 5kW 5000 |
|
854 | # Pt: Transmission Power dB 5kW 5000 | |
855 | # Gt: Transmission Gain dB 24.7 dB 295.1209 |
|
855 | # Gt: Transmission Gain dB 24.7 dB 295.1209 | |
856 | # Gr: Reception Gain dB 18.5 dB 70.7945 |
|
856 | # Gr: Reception Gain dB 18.5 dB 70.7945 | |
857 | # Lambda: Wavelenght m 0.6741 m 0.6741 |
|
857 | # Lambda: Wavelenght m 0.6741 m 0.6741 | |
858 | # aL: Attenuation loses dB 4dB 2.5118 |
|
858 | # aL: Attenuation loses dB 4dB 2.5118 | |
859 | # tauW: Width of transmission pulse s 4us 4e-6 |
|
859 | # tauW: Width of transmission pulse s 4us 4e-6 | |
860 | # ThetaT: Transmission antenna bean angle rad 0.1656317 rad 0.1656317 |
|
860 | # ThetaT: Transmission antenna bean angle rad 0.1656317 rad 0.1656317 | |
861 | # ThetaR: Reception antenna beam angle rad 0.36774087 rad 0.36774087 |
|
861 | # ThetaR: Reception antenna beam angle rad 0.36774087 rad 0.36774087 | |
862 | # |
|
862 | # | |
863 | # """ |
|
863 | # """ | |
864 | # |
|
864 | # | |
865 | # Numerator = ( (4*numpy.pi)**3 * aL**2 * 16 * numpy.log(2) ) |
|
865 | # Numerator = ( (4*numpy.pi)**3 * aL**2 * 16 * numpy.log(2) ) | |
866 | # Denominator = ( Pt * Gt * Gr * Lambda**2 * SPEED_OF_LIGHT * TauW * numpy.pi * ThetaT * TheraR) |
|
866 | # Denominator = ( Pt * Gt * Gr * Lambda**2 * SPEED_OF_LIGHT * TauW * numpy.pi * ThetaT * TheraR) | |
867 | # RadarConstant = Numerator / Denominator |
|
867 | # RadarConstant = Numerator / Denominator | |
868 | # |
|
868 | # | |
869 | # return RadarConstant |
|
869 | # return RadarConstant | |
870 |
|
870 | |||
871 |
|
871 | |||
872 |
|
872 | |||
873 | class FullSpectralAnalysis(Operation): |
|
873 | class FullSpectralAnalysis(Operation): | |
874 |
|
874 | |||
875 | """ |
|
875 | """ | |
876 | Function that implements Full Spectral Analysis technique. |
|
876 | Function that implements Full Spectral Analysis technique. | |
877 |
|
877 | |||
878 | Input: |
|
878 | Input: | |
879 | self.dataOut.data_pre : SelfSpectra and CrossSpectra data |
|
879 | self.dataOut.data_pre : SelfSpectra and CrossSpectra data | |
880 | self.dataOut.groupList : Pairlist of channels |
|
880 | self.dataOut.groupList : Pairlist of channels | |
881 | self.dataOut.ChanDist : Physical distance between receivers |
|
881 | self.dataOut.ChanDist : Physical distance between receivers | |
882 |
|
882 | |||
883 |
|
883 | |||
884 | Output: |
|
884 | Output: | |
885 |
|
885 | |||
886 | self.dataOut.data_output : Zonal wind, Meridional wind, and Vertical wind |
|
886 | self.dataOut.data_output : Zonal wind, Meridional wind, and Vertical wind | |
887 |
|
887 | |||
888 |
|
888 | |||
889 | Parameters affected: Winds, height range, SNR |
|
889 | Parameters affected: Winds, height range, SNR | |
890 |
|
890 | |||
891 | """ |
|
891 | """ | |
892 | def run(self, dataOut, Xi01=None, Xi02=None, Xi12=None, Eta01=None, Eta02=None, Eta12=None, SNRdBlimit=-30, |
|
892 | def run(self, dataOut, Xi01=None, Xi02=None, Xi12=None, Eta01=None, Eta02=None, Eta12=None, SNRdBlimit=-30, | |
893 | minheight=None, maxheight=None, NegativeLimit=None, PositiveLimit=None): |
|
893 | minheight=None, maxheight=None, NegativeLimit=None, PositiveLimit=None): | |
894 |
|
894 | |||
895 | spc = dataOut.data_pre[0].copy() |
|
895 | spc = dataOut.data_pre[0].copy() | |
896 | cspc = dataOut.data_pre[1] |
|
896 | cspc = dataOut.data_pre[1] | |
897 | nHeights = spc.shape[2] |
|
897 | nHeights = spc.shape[2] | |
898 |
|
898 | |||
899 | # first_height = 0.75 #km (ref: data header 20170822) |
|
899 | # first_height = 0.75 #km (ref: data header 20170822) | |
900 | # resolution_height = 0.075 #km |
|
900 | # resolution_height = 0.075 #km | |
901 | ''' |
|
901 | ''' | |
902 | finding height range. check this when radar parameters are changed! |
|
902 | finding height range. check this when radar parameters are changed! | |
903 | ''' |
|
903 | ''' | |
904 | if maxheight is not None: |
|
904 | if maxheight is not None: | |
905 | # range_max = math.ceil((maxheight - first_height) / resolution_height) # theoretical |
|
905 | # range_max = math.ceil((maxheight - first_height) / resolution_height) # theoretical | |
906 | range_max = math.ceil(13.26 * maxheight - 3) # empirical, works better |
|
906 | range_max = math.ceil(13.26 * maxheight - 3) # empirical, works better | |
907 | else: |
|
907 | else: | |
908 | range_max = nHeights |
|
908 | range_max = nHeights | |
909 | if minheight is not None: |
|
909 | if minheight is not None: | |
910 | # range_min = int((minheight - first_height) / resolution_height) # theoretical |
|
910 | # range_min = int((minheight - first_height) / resolution_height) # theoretical | |
911 | range_min = int(13.26 * minheight - 5) # empirical, works better |
|
911 | range_min = int(13.26 * minheight - 5) # empirical, works better | |
912 | if range_min < 0: |
|
912 | if range_min < 0: | |
913 | range_min = 0 |
|
913 | range_min = 0 | |
914 | else: |
|
914 | else: | |
915 | range_min = 0 |
|
915 | range_min = 0 | |
916 |
|
916 | |||
917 | pairsList = dataOut.groupList |
|
917 | pairsList = dataOut.groupList | |
918 | if dataOut.ChanDist is not None : |
|
918 | if dataOut.ChanDist is not None : | |
919 | ChanDist = dataOut.ChanDist |
|
919 | ChanDist = dataOut.ChanDist | |
920 | else: |
|
920 | else: | |
921 | ChanDist = numpy.array([[Xi01, Eta01],[Xi02,Eta02],[Xi12,Eta12]]) |
|
921 | ChanDist = numpy.array([[Xi01, Eta01],[Xi02,Eta02],[Xi12,Eta12]]) | |
922 |
|
922 | |||
923 | # 4 variables: zonal, meridional, vertical, and average SNR |
|
923 | # 4 variables: zonal, meridional, vertical, and average SNR | |
924 | data_param = numpy.zeros([4,nHeights]) * numpy.NaN |
|
924 | data_param = numpy.zeros([4,nHeights]) * numpy.NaN | |
925 | velocityX = numpy.zeros([nHeights]) * numpy.NaN |
|
925 | velocityX = numpy.zeros([nHeights]) * numpy.NaN | |
926 | velocityY = numpy.zeros([nHeights]) * numpy.NaN |
|
926 | velocityY = numpy.zeros([nHeights]) * numpy.NaN | |
927 | velocityZ = numpy.zeros([nHeights]) * numpy.NaN |
|
927 | velocityZ = numpy.zeros([nHeights]) * numpy.NaN | |
928 |
|
928 | |||
929 | dbSNR = 10*numpy.log10(numpy.average(dataOut.data_snr,0)) |
|
929 | dbSNR = 10*numpy.log10(numpy.average(dataOut.data_snr,0)) | |
930 |
|
930 | |||
931 | '''***********************************************WIND ESTIMATION**************************************''' |
|
931 | '''***********************************************WIND ESTIMATION**************************************''' | |
932 | for Height in range(nHeights): |
|
932 | for Height in range(nHeights): | |
933 |
|
933 | |||
934 | if Height >= range_min and Height < range_max: |
|
934 | if Height >= range_min and Height < range_max: | |
935 | # error_code will be useful in future analysis |
|
935 | # error_code will be useful in future analysis | |
936 | [Vzon,Vmer,Vver, error_code] = self.WindEstimation(spc[:,:,Height], cspc[:,:,Height], pairsList, |
|
936 | [Vzon,Vmer,Vver, error_code] = self.WindEstimation(spc[:,:,Height], cspc[:,:,Height], pairsList, | |
937 | ChanDist, Height, dataOut.noise, dataOut.spc_range, dbSNR[Height], SNRdBlimit, NegativeLimit, PositiveLimit,dataOut.frequency) |
|
937 | ChanDist, Height, dataOut.noise, dataOut.spc_range, dbSNR[Height], SNRdBlimit, NegativeLimit, PositiveLimit,dataOut.frequency) | |
938 |
|
938 | |||
939 | if abs(Vzon) < 100. and abs(Vmer) < 100.: |
|
939 | if abs(Vzon) < 100. and abs(Vmer) < 100.: | |
940 | velocityX[Height] = Vzon |
|
940 | velocityX[Height] = Vzon | |
941 | velocityY[Height] = -Vmer |
|
941 | velocityY[Height] = -Vmer | |
942 | velocityZ[Height] = Vver |
|
942 | velocityZ[Height] = Vver | |
943 |
|
943 | |||
944 | # Censoring data with SNR threshold |
|
944 | # Censoring data with SNR threshold | |
945 | dbSNR [dbSNR < SNRdBlimit] = numpy.NaN |
|
945 | dbSNR [dbSNR < SNRdBlimit] = numpy.NaN | |
946 |
|
946 | |||
947 | data_param[0] = velocityX |
|
947 | data_param[0] = velocityX | |
948 | data_param[1] = velocityY |
|
948 | data_param[1] = velocityY | |
949 | data_param[2] = velocityZ |
|
949 | data_param[2] = velocityZ | |
950 | data_param[3] = dbSNR |
|
950 | data_param[3] = dbSNR | |
951 | dataOut.data_param = data_param |
|
951 | dataOut.data_param = data_param | |
952 | return dataOut |
|
952 | return dataOut | |
953 |
|
953 | |||
954 | def moving_average(self,x, N=2): |
|
954 | def moving_average(self,x, N=2): | |
955 | """ convolution for smoothenig data. note that last N-1 values are convolution with zeroes """ |
|
955 | """ convolution for smoothenig data. note that last N-1 values are convolution with zeroes """ | |
956 | return numpy.convolve(x, numpy.ones((N,))/N)[(N-1):] |
|
956 | return numpy.convolve(x, numpy.ones((N,))/N)[(N-1):] | |
957 |
|
957 | |||
958 | def gaus(self,xSamples,Amp,Mu,Sigma): |
|
958 | def gaus(self,xSamples,Amp,Mu,Sigma): | |
959 | return Amp * numpy.exp(-0.5*((xSamples - Mu)/Sigma)**2) |
|
959 | return Amp * numpy.exp(-0.5*((xSamples - Mu)/Sigma)**2) | |
960 |
|
960 | |||
961 | def Moments(self, ySamples, xSamples): |
|
961 | def Moments(self, ySamples, xSamples): | |
962 | Power = numpy.nanmean(ySamples) # Power, 0th Moment |
|
962 | Power = numpy.nanmean(ySamples) # Power, 0th Moment | |
963 | yNorm = ySamples / numpy.nansum(ySamples) |
|
963 | yNorm = ySamples / numpy.nansum(ySamples) | |
964 | RadVel = numpy.nansum(xSamples * yNorm) # Radial Velocity, 1st Moment |
|
964 | RadVel = numpy.nansum(xSamples * yNorm) # Radial Velocity, 1st Moment | |
965 | Sigma2 = numpy.nansum(yNorm * (xSamples - RadVel)**2) # Spectral Width, 2nd Moment |
|
965 | Sigma2 = numpy.nansum(yNorm * (xSamples - RadVel)**2) # Spectral Width, 2nd Moment | |
966 | StdDev = numpy.sqrt(numpy.abs(Sigma2)) # Desv. Estandar, Ancho espectral |
|
966 | StdDev = numpy.sqrt(numpy.abs(Sigma2)) # Desv. Estandar, Ancho espectral | |
967 | return numpy.array([Power,RadVel,StdDev]) |
|
967 | return numpy.array([Power,RadVel,StdDev]) | |
968 |
|
968 | |||
969 | def StopWindEstimation(self, error_code): |
|
969 | def StopWindEstimation(self, error_code): | |
970 | Vzon = numpy.NaN |
|
970 | Vzon = numpy.NaN | |
971 | Vmer = numpy.NaN |
|
971 | Vmer = numpy.NaN | |
972 | Vver = numpy.NaN |
|
972 | Vver = numpy.NaN | |
973 | return Vzon, Vmer, Vver, error_code |
|
973 | return Vzon, Vmer, Vver, error_code | |
974 |
|
974 | |||
975 | def AntiAliasing(self, interval, maxstep): |
|
975 | def AntiAliasing(self, interval, maxstep): | |
976 | """ |
|
976 | """ | |
977 | function to prevent errors from aliased values when computing phaseslope |
|
977 | function to prevent errors from aliased values when computing phaseslope | |
978 | """ |
|
978 | """ | |
979 | antialiased = numpy.zeros(len(interval)) |
|
979 | antialiased = numpy.zeros(len(interval)) | |
980 | copyinterval = interval.copy() |
|
980 | copyinterval = interval.copy() | |
981 |
|
981 | |||
982 | antialiased[0] = copyinterval[0] |
|
982 | antialiased[0] = copyinterval[0] | |
983 |
|
983 | |||
984 | for i in range(1,len(antialiased)): |
|
984 | for i in range(1,len(antialiased)): | |
985 | step = interval[i] - interval[i-1] |
|
985 | step = interval[i] - interval[i-1] | |
986 | if step > maxstep: |
|
986 | if step > maxstep: | |
987 | copyinterval -= 2*numpy.pi |
|
987 | copyinterval -= 2*numpy.pi | |
988 | antialiased[i] = copyinterval[i] |
|
988 | antialiased[i] = copyinterval[i] | |
989 | elif step < maxstep*(-1): |
|
989 | elif step < maxstep*(-1): | |
990 | copyinterval += 2*numpy.pi |
|
990 | copyinterval += 2*numpy.pi | |
991 | antialiased[i] = copyinterval[i] |
|
991 | antialiased[i] = copyinterval[i] | |
992 | else: |
|
992 | else: | |
993 | antialiased[i] = copyinterval[i].copy() |
|
993 | antialiased[i] = copyinterval[i].copy() | |
994 |
|
994 | |||
995 | return antialiased |
|
995 | return antialiased | |
996 |
|
996 | |||
997 | def WindEstimation(self, spc, cspc, pairsList, ChanDist, Height, noise, AbbsisaRange, dbSNR, SNRlimit, NegativeLimit, PositiveLimit, radfreq): |
|
997 | def WindEstimation(self, spc, cspc, pairsList, ChanDist, Height, noise, AbbsisaRange, dbSNR, SNRlimit, NegativeLimit, PositiveLimit, radfreq): | |
998 | """ |
|
998 | """ | |
999 | Function that Calculates Zonal, Meridional and Vertical wind velocities. |
|
999 | Function that Calculates Zonal, Meridional and Vertical wind velocities. | |
1000 | Initial Version by E. Bocanegra updated by J. Zibell until Nov. 2019. |
|
1000 | Initial Version by E. Bocanegra updated by J. Zibell until Nov. 2019. | |
1001 |
|
1001 | |||
1002 | Input: |
|
1002 | Input: | |
1003 | spc, cspc : self spectra and cross spectra data. In Briggs notation something like S_i*(S_i)_conj, (S_j)_conj respectively. |
|
1003 | spc, cspc : self spectra and cross spectra data. In Briggs notation something like S_i*(S_i)_conj, (S_j)_conj respectively. | |
1004 | pairsList : Pairlist of channels |
|
1004 | pairsList : Pairlist of channels | |
1005 | ChanDist : array of xi_ij and eta_ij |
|
1005 | ChanDist : array of xi_ij and eta_ij | |
1006 | Height : height at which data is processed |
|
1006 | Height : height at which data is processed | |
1007 | noise : noise in [channels] format for specific height |
|
1007 | noise : noise in [channels] format for specific height | |
1008 | Abbsisarange : range of the frequencies or velocities |
|
1008 | Abbsisarange : range of the frequencies or velocities | |
1009 | dbSNR, SNRlimit : signal to noise ratio in db, lower limit |
|
1009 | dbSNR, SNRlimit : signal to noise ratio in db, lower limit | |
1010 |
|
1010 | |||
1011 | Output: |
|
1011 | Output: | |
1012 | Vzon, Vmer, Vver : wind velocities |
|
1012 | Vzon, Vmer, Vver : wind velocities | |
1013 | error_code : int that states where code is terminated |
|
1013 | error_code : int that states where code is terminated | |
1014 |
|
1014 | |||
1015 | 0 : no error detected |
|
1015 | 0 : no error detected | |
1016 | 1 : Gaussian of mean spc exceeds widthlimit |
|
1016 | 1 : Gaussian of mean spc exceeds widthlimit | |
1017 | 2 : no Gaussian of mean spc found |
|
1017 | 2 : no Gaussian of mean spc found | |
1018 | 3 : SNR to low or velocity to high -> prec. e.g. |
|
1018 | 3 : SNR to low or velocity to high -> prec. e.g. | |
1019 | 4 : at least one Gaussian of cspc exceeds widthlimit |
|
1019 | 4 : at least one Gaussian of cspc exceeds widthlimit | |
1020 | 5 : zero out of three cspc Gaussian fits converged |
|
1020 | 5 : zero out of three cspc Gaussian fits converged | |
1021 | 6 : phase slope fit could not be found |
|
1021 | 6 : phase slope fit could not be found | |
1022 | 7 : arrays used to fit phase have different length |
|
1022 | 7 : arrays used to fit phase have different length | |
1023 | 8 : frequency range is either too short (len <= 5) or very long (> 30% of cspc) |
|
1023 | 8 : frequency range is either too short (len <= 5) or very long (> 30% of cspc) | |
1024 |
|
1024 | |||
1025 | """ |
|
1025 | """ | |
1026 |
|
1026 | |||
1027 | error_code = 0 |
|
1027 | error_code = 0 | |
1028 |
|
1028 | |||
1029 | nChan = spc.shape[0] |
|
1029 | nChan = spc.shape[0] | |
1030 | nProf = spc.shape[1] |
|
1030 | nProf = spc.shape[1] | |
1031 | nPair = cspc.shape[0] |
|
1031 | nPair = cspc.shape[0] | |
1032 |
|
1032 | |||
1033 | SPC_Samples = numpy.zeros([nChan, nProf]) # for normalized spc values for one height |
|
1033 | SPC_Samples = numpy.zeros([nChan, nProf]) # for normalized spc values for one height | |
1034 | CSPC_Samples = numpy.zeros([nPair, nProf], dtype=numpy.complex_) # for normalized cspc values |
|
1034 | CSPC_Samples = numpy.zeros([nPair, nProf], dtype=numpy.complex_) # for normalized cspc values | |
1035 | phase = numpy.zeros([nPair, nProf]) # phase between channels |
|
1035 | phase = numpy.zeros([nPair, nProf]) # phase between channels | |
1036 | PhaseSlope = numpy.zeros(nPair) # slope of the phases, channelwise |
|
1036 | PhaseSlope = numpy.zeros(nPair) # slope of the phases, channelwise | |
1037 | PhaseInter = numpy.zeros(nPair) # intercept to the slope of the phases, channelwise |
|
1037 | PhaseInter = numpy.zeros(nPair) # intercept to the slope of the phases, channelwise | |
1038 | xFrec = AbbsisaRange[0][:-1] # frequency range |
|
1038 | xFrec = AbbsisaRange[0][:-1] # frequency range | |
1039 | xVel = AbbsisaRange[2][:-1] # velocity range |
|
1039 | xVel = AbbsisaRange[2][:-1] # velocity range | |
1040 | xSamples = xFrec # the frequency range is taken |
|
1040 | xSamples = xFrec # the frequency range is taken | |
1041 | delta_x = xSamples[1] - xSamples[0] # delta_f or delta_x |
|
1041 | delta_x = xSamples[1] - xSamples[0] # delta_f or delta_x | |
1042 |
|
1042 | |||
1043 | # only consider velocities with in NegativeLimit and PositiveLimit |
|
1043 | # only consider velocities with in NegativeLimit and PositiveLimit | |
1044 | if (NegativeLimit is None): |
|
1044 | if (NegativeLimit is None): | |
1045 | NegativeLimit = numpy.min(xVel) |
|
1045 | NegativeLimit = numpy.min(xVel) | |
1046 | if (PositiveLimit is None): |
|
1046 | if (PositiveLimit is None): | |
1047 | PositiveLimit = numpy.max(xVel) |
|
1047 | PositiveLimit = numpy.max(xVel) | |
1048 | xvalid = numpy.where((xVel > NegativeLimit) & (xVel < PositiveLimit)) |
|
1048 | xvalid = numpy.where((xVel > NegativeLimit) & (xVel < PositiveLimit)) | |
1049 | xSamples_zoom = xSamples[xvalid] |
|
1049 | xSamples_zoom = xSamples[xvalid] | |
1050 |
|
1050 | |||
1051 | '''Getting Eij and Nij''' |
|
1051 | '''Getting Eij and Nij''' | |
1052 | Xi01, Xi02, Xi12 = ChanDist[:,0] |
|
1052 | Xi01, Xi02, Xi12 = ChanDist[:,0] | |
1053 | Eta01, Eta02, Eta12 = ChanDist[:,1] |
|
1053 | Eta01, Eta02, Eta12 = ChanDist[:,1] | |
1054 |
|
1054 | |||
1055 | # spwd limit - updated by D. ScipiΓ³n 30.03.2021 |
|
1055 | # spwd limit - updated by D. ScipiΓ³n 30.03.2021 | |
1056 | widthlimit = 10 |
|
1056 | widthlimit = 10 | |
1057 | '''************************* SPC is normalized ********************************''' |
|
1057 | '''************************* SPC is normalized ********************************''' | |
1058 | spc_norm = spc.copy() |
|
1058 | spc_norm = spc.copy() | |
1059 | # For each channel |
|
1059 | # For each channel | |
1060 | for i in range(nChan): |
|
1060 | for i in range(nChan): | |
1061 | spc_sub = spc_norm[i,:] - noise[i] # only the signal power |
|
1061 | spc_sub = spc_norm[i,:] - noise[i] # only the signal power | |
1062 | SPC_Samples[i] = spc_sub / (numpy.nansum(spc_sub) * delta_x) |
|
1062 | SPC_Samples[i] = spc_sub / (numpy.nansum(spc_sub) * delta_x) | |
1063 |
|
1063 | |||
1064 | '''********************** FITTING MEAN SPC GAUSSIAN **********************''' |
|
1064 | '''********************** FITTING MEAN SPC GAUSSIAN **********************''' | |
1065 |
|
1065 | |||
1066 | """ the gaussian of the mean: first subtract noise, then normalize. this is legal because |
|
1066 | """ the gaussian of the mean: first subtract noise, then normalize. this is legal because | |
1067 | you only fit the curve and don't need the absolute value of height for calculation, |
|
1067 | you only fit the curve and don't need the absolute value of height for calculation, | |
1068 | only for estimation of width. for normalization of cross spectra, you need initial, |
|
1068 | only for estimation of width. for normalization of cross spectra, you need initial, | |
1069 | unnormalized self-spectra With noise. |
|
1069 | unnormalized self-spectra With noise. | |
1070 |
|
1070 | |||
1071 | Technically, you don't even need to normalize the self-spectra, as you only need the |
|
1071 | Technically, you don't even need to normalize the self-spectra, as you only need the | |
1072 | width of the peak. However, it was left this way. Note that the normalization has a flaw: |
|
1072 | width of the peak. However, it was left this way. Note that the normalization has a flaw: | |
1073 | due to subtraction of the noise, some values are below zero. Raw "spc" values should be |
|
1073 | due to subtraction of the noise, some values are below zero. Raw "spc" values should be | |
1074 | >= 0, as it is the modulus squared of the signals (complex * it's conjugate) |
|
1074 | >= 0, as it is the modulus squared of the signals (complex * it's conjugate) | |
1075 | """ |
|
1075 | """ | |
1076 | # initial conditions |
|
1076 | # initial conditions | |
1077 | popt = [1e-10,0,1e-10] |
|
1077 | popt = [1e-10,0,1e-10] | |
1078 | # Spectra average |
|
1078 | # Spectra average | |
1079 | SPCMean = numpy.average(SPC_Samples,0) |
|
1079 | SPCMean = numpy.average(SPC_Samples,0) | |
1080 | # Moments in frequency |
|
1080 | # Moments in frequency | |
1081 | SPCMoments = self.Moments(SPCMean[xvalid], xSamples_zoom) |
|
1081 | SPCMoments = self.Moments(SPCMean[xvalid], xSamples_zoom) | |
1082 |
|
1082 | |||
1083 | # Gauss Fit SPC in frequency domain |
|
1083 | # Gauss Fit SPC in frequency domain | |
1084 | if dbSNR > SNRlimit: # only if SNR > SNRth |
|
1084 | if dbSNR > SNRlimit: # only if SNR > SNRth | |
1085 | try: |
|
1085 | try: | |
1086 | popt,pcov = curve_fit(self.gaus,xSamples_zoom,SPCMean[xvalid],p0=SPCMoments) |
|
1086 | popt,pcov = curve_fit(self.gaus,xSamples_zoom,SPCMean[xvalid],p0=SPCMoments) | |
1087 | if popt[2] <= 0 or popt[2] > widthlimit: # CONDITION |
|
1087 | if popt[2] <= 0 or popt[2] > widthlimit: # CONDITION | |
1088 | return self.StopWindEstimation(error_code = 1) |
|
1088 | return self.StopWindEstimation(error_code = 1) | |
1089 | FitGauss = self.gaus(xSamples_zoom,*popt) |
|
1089 | FitGauss = self.gaus(xSamples_zoom,*popt) | |
1090 | except :#RuntimeError: |
|
1090 | except :#RuntimeError: | |
1091 | return self.StopWindEstimation(error_code = 2) |
|
1091 | return self.StopWindEstimation(error_code = 2) | |
1092 | else: |
|
1092 | else: | |
1093 | return self.StopWindEstimation(error_code = 3) |
|
1093 | return self.StopWindEstimation(error_code = 3) | |
1094 |
|
1094 | |||
1095 | '''***************************** CSPC Normalization ************************* |
|
1095 | '''***************************** CSPC Normalization ************************* | |
1096 | The Spc spectra are used to normalize the crossspectra. Peaks from precipitation |
|
1096 | The Spc spectra are used to normalize the crossspectra. Peaks from precipitation | |
1097 | influence the norm which is not desired. First, a range is identified where the |
|
1097 | influence the norm which is not desired. First, a range is identified where the | |
1098 | wind peak is estimated -> sum_wind is sum of those frequencies. Next, the area |
|
1098 | wind peak is estimated -> sum_wind is sum of those frequencies. Next, the area | |
1099 | around it gets cut off and values replaced by mean determined by the boundary |
|
1099 | around it gets cut off and values replaced by mean determined by the boundary | |
1100 | data -> sum_noise (spc is not normalized here, thats why the noise is important) |
|
1100 | data -> sum_noise (spc is not normalized here, thats why the noise is important) | |
1101 |
|
1101 | |||
1102 | The sums are then added and multiplied by range/datapoints, because you need |
|
1102 | The sums are then added and multiplied by range/datapoints, because you need | |
1103 | an integral and not a sum for normalization. |
|
1103 | an integral and not a sum for normalization. | |
1104 |
|
1104 | |||
1105 | A norm is found according to Briggs 92. |
|
1105 | A norm is found according to Briggs 92. | |
1106 | ''' |
|
1106 | ''' | |
1107 | # for each pair |
|
1107 | # for each pair | |
1108 | for i in range(nPair): |
|
1108 | for i in range(nPair): | |
1109 | cspc_norm = cspc[i,:].copy() |
|
1109 | cspc_norm = cspc[i,:].copy() | |
1110 | chan_index0 = pairsList[i][0] |
|
1110 | chan_index0 = pairsList[i][0] | |
1111 | chan_index1 = pairsList[i][1] |
|
1111 | chan_index1 = pairsList[i][1] | |
1112 | CSPC_Samples[i] = cspc_norm / (numpy.sqrt(numpy.nansum(spc_norm[chan_index0])*numpy.nansum(spc_norm[chan_index1])) * delta_x) |
|
1112 | CSPC_Samples[i] = cspc_norm / (numpy.sqrt(numpy.nansum(spc_norm[chan_index0])*numpy.nansum(spc_norm[chan_index1])) * delta_x) | |
1113 | phase[i] = numpy.arctan2(CSPC_Samples[i].imag, CSPC_Samples[i].real) |
|
1113 | phase[i] = numpy.arctan2(CSPC_Samples[i].imag, CSPC_Samples[i].real) | |
1114 |
|
1114 | |||
1115 | CSPCmoments = numpy.vstack([self.Moments(numpy.abs(CSPC_Samples[0,xvalid]), xSamples_zoom), |
|
1115 | CSPCmoments = numpy.vstack([self.Moments(numpy.abs(CSPC_Samples[0,xvalid]), xSamples_zoom), | |
1116 | self.Moments(numpy.abs(CSPC_Samples[1,xvalid]), xSamples_zoom), |
|
1116 | self.Moments(numpy.abs(CSPC_Samples[1,xvalid]), xSamples_zoom), | |
1117 | self.Moments(numpy.abs(CSPC_Samples[2,xvalid]), xSamples_zoom)]) |
|
1117 | self.Moments(numpy.abs(CSPC_Samples[2,xvalid]), xSamples_zoom)]) | |
1118 |
|
1118 | |||
1119 | popt01, popt02, popt12 = [1e-10,0,1e-10], [1e-10,0,1e-10] ,[1e-10,0,1e-10] |
|
1119 | popt01, popt02, popt12 = [1e-10,0,1e-10], [1e-10,0,1e-10] ,[1e-10,0,1e-10] | |
1120 | FitGauss01, FitGauss02, FitGauss12 = numpy.zeros(len(xSamples)), numpy.zeros(len(xSamples)), numpy.zeros(len(xSamples)) |
|
1120 | FitGauss01, FitGauss02, FitGauss12 = numpy.zeros(len(xSamples)), numpy.zeros(len(xSamples)), numpy.zeros(len(xSamples)) | |
1121 |
|
1121 | |||
1122 | '''*******************************FIT GAUSS CSPC************************************''' |
|
1122 | '''*******************************FIT GAUSS CSPC************************************''' | |
1123 | try: |
|
1123 | try: | |
1124 | popt01,pcov = curve_fit(self.gaus,xSamples_zoom,numpy.abs(CSPC_Samples[0][xvalid]),p0=CSPCmoments[0]) |
|
1124 | popt01,pcov = curve_fit(self.gaus,xSamples_zoom,numpy.abs(CSPC_Samples[0][xvalid]),p0=CSPCmoments[0]) | |
1125 | if popt01[2] > widthlimit: # CONDITION |
|
1125 | if popt01[2] > widthlimit: # CONDITION | |
1126 | return self.StopWindEstimation(error_code = 4) |
|
1126 | return self.StopWindEstimation(error_code = 4) | |
1127 | popt02,pcov = curve_fit(self.gaus,xSamples_zoom,numpy.abs(CSPC_Samples[1][xvalid]),p0=CSPCmoments[1]) |
|
1127 | popt02,pcov = curve_fit(self.gaus,xSamples_zoom,numpy.abs(CSPC_Samples[1][xvalid]),p0=CSPCmoments[1]) | |
1128 | if popt02[2] > widthlimit: # CONDITION |
|
1128 | if popt02[2] > widthlimit: # CONDITION | |
1129 | return self.StopWindEstimation(error_code = 4) |
|
1129 | return self.StopWindEstimation(error_code = 4) | |
1130 | popt12,pcov = curve_fit(self.gaus,xSamples_zoom,numpy.abs(CSPC_Samples[2][xvalid]),p0=CSPCmoments[2]) |
|
1130 | popt12,pcov = curve_fit(self.gaus,xSamples_zoom,numpy.abs(CSPC_Samples[2][xvalid]),p0=CSPCmoments[2]) | |
1131 | if popt12[2] > widthlimit: # CONDITION |
|
1131 | if popt12[2] > widthlimit: # CONDITION | |
1132 | return self.StopWindEstimation(error_code = 4) |
|
1132 | return self.StopWindEstimation(error_code = 4) | |
1133 |
|
1133 | |||
1134 | FitGauss01 = self.gaus(xSamples_zoom, *popt01) |
|
1134 | FitGauss01 = self.gaus(xSamples_zoom, *popt01) | |
1135 | FitGauss02 = self.gaus(xSamples_zoom, *popt02) |
|
1135 | FitGauss02 = self.gaus(xSamples_zoom, *popt02) | |
1136 | FitGauss12 = self.gaus(xSamples_zoom, *popt12) |
|
1136 | FitGauss12 = self.gaus(xSamples_zoom, *popt12) | |
1137 | except: |
|
1137 | except: | |
1138 | return self.StopWindEstimation(error_code = 5) |
|
1138 | return self.StopWindEstimation(error_code = 5) | |
1139 |
|
1139 | |||
1140 |
|
1140 | |||
1141 | '''************* Getting Fij ***************''' |
|
1141 | '''************* Getting Fij ***************''' | |
1142 | # x-axis point of the gaussian where the center is located from GaussFit of spectra |
|
1142 | # x-axis point of the gaussian where the center is located from GaussFit of spectra | |
1143 | GaussCenter = popt[1] |
|
1143 | GaussCenter = popt[1] | |
1144 | ClosestCenter = xSamples_zoom[numpy.abs(xSamples_zoom-GaussCenter).argmin()] |
|
1144 | ClosestCenter = xSamples_zoom[numpy.abs(xSamples_zoom-GaussCenter).argmin()] | |
1145 | PointGauCenter = numpy.where(xSamples_zoom==ClosestCenter)[0][0] |
|
1145 | PointGauCenter = numpy.where(xSamples_zoom==ClosestCenter)[0][0] | |
1146 |
|
1146 | |||
1147 | # Point where e^-1 is located in the gaussian |
|
1147 | # Point where e^-1 is located in the gaussian | |
1148 | PeMinus1 = numpy.max(FitGauss) * numpy.exp(-1) |
|
1148 | PeMinus1 = numpy.max(FitGauss) * numpy.exp(-1) | |
1149 | FijClosest = FitGauss[numpy.abs(FitGauss-PeMinus1).argmin()] # The closest point to"Peminus1" in "FitGauss" |
|
1149 | FijClosest = FitGauss[numpy.abs(FitGauss-PeMinus1).argmin()] # The closest point to"Peminus1" in "FitGauss" | |
1150 | PointFij = numpy.where(FitGauss==FijClosest)[0][0] |
|
1150 | PointFij = numpy.where(FitGauss==FijClosest)[0][0] | |
1151 | Fij = numpy.abs(xSamples_zoom[PointFij] - xSamples_zoom[PointGauCenter]) |
|
1151 | Fij = numpy.abs(xSamples_zoom[PointFij] - xSamples_zoom[PointGauCenter]) | |
1152 |
|
1152 | |||
1153 | '''********** Taking frequency ranges from mean SPCs **********''' |
|
1153 | '''********** Taking frequency ranges from mean SPCs **********''' | |
1154 | GauWidth = popt[2] * 3/2 # Bandwidth of Gau01 |
|
1154 | GauWidth = popt[2] * 3/2 # Bandwidth of Gau01 | |
1155 | Range = numpy.empty(2) |
|
1155 | Range = numpy.empty(2) | |
1156 | Range[0] = GaussCenter - GauWidth |
|
1156 | Range[0] = GaussCenter - GauWidth | |
1157 | Range[1] = GaussCenter + GauWidth |
|
1157 | Range[1] = GaussCenter + GauWidth | |
1158 | # Point in x-axis where the bandwidth is located (min:max) |
|
1158 | # Point in x-axis where the bandwidth is located (min:max) | |
1159 | ClosRangeMin = xSamples_zoom[numpy.abs(xSamples_zoom-Range[0]).argmin()] |
|
1159 | ClosRangeMin = xSamples_zoom[numpy.abs(xSamples_zoom-Range[0]).argmin()] | |
1160 | ClosRangeMax = xSamples_zoom[numpy.abs(xSamples_zoom-Range[1]).argmin()] |
|
1160 | ClosRangeMax = xSamples_zoom[numpy.abs(xSamples_zoom-Range[1]).argmin()] | |
1161 | PointRangeMin = numpy.where(xSamples_zoom==ClosRangeMin)[0][0] |
|
1161 | PointRangeMin = numpy.where(xSamples_zoom==ClosRangeMin)[0][0] | |
1162 | PointRangeMax = numpy.where(xSamples_zoom==ClosRangeMax)[0][0] |
|
1162 | PointRangeMax = numpy.where(xSamples_zoom==ClosRangeMax)[0][0] | |
1163 | Range = numpy.array([ PointRangeMin, PointRangeMax ]) |
|
1163 | Range = numpy.array([ PointRangeMin, PointRangeMax ]) | |
1164 | FrecRange = xSamples_zoom[ Range[0] : Range[1] ] |
|
1164 | FrecRange = xSamples_zoom[ Range[0] : Range[1] ] | |
1165 |
|
1165 | |||
1166 | '''************************** Getting Phase Slope ***************************''' |
|
1166 | '''************************** Getting Phase Slope ***************************''' | |
1167 | for i in range(nPair): |
|
1167 | for i in range(nPair): | |
1168 | if len(FrecRange) > 5: |
|
1168 | if len(FrecRange) > 5: | |
1169 | PhaseRange = phase[i, xvalid[0][Range[0]:Range[1]]].copy() |
|
1169 | PhaseRange = phase[i, xvalid[0][Range[0]:Range[1]]].copy() | |
1170 | mask = ~numpy.isnan(FrecRange) & ~numpy.isnan(PhaseRange) |
|
1170 | mask = ~numpy.isnan(FrecRange) & ~numpy.isnan(PhaseRange) | |
1171 | if len(FrecRange) == len(PhaseRange): |
|
1171 | if len(FrecRange) == len(PhaseRange): | |
1172 | try: |
|
1172 | try: | |
1173 | slope, intercept, _, _, _ = stats.linregress(FrecRange[mask], self.AntiAliasing(PhaseRange[mask], 4.5)) |
|
1173 | slope, intercept, _, _, _ = stats.linregress(FrecRange[mask], self.AntiAliasing(PhaseRange[mask], 4.5)) | |
1174 | PhaseSlope[i] = slope |
|
1174 | PhaseSlope[i] = slope | |
1175 | PhaseInter[i] = intercept |
|
1175 | PhaseInter[i] = intercept | |
1176 | except: |
|
1176 | except: | |
1177 | return self.StopWindEstimation(error_code = 6) |
|
1177 | return self.StopWindEstimation(error_code = 6) | |
1178 | else: |
|
1178 | else: | |
1179 | return self.StopWindEstimation(error_code = 7) |
|
1179 | return self.StopWindEstimation(error_code = 7) | |
1180 | else: |
|
1180 | else: | |
1181 | return self.StopWindEstimation(error_code = 8) |
|
1181 | return self.StopWindEstimation(error_code = 8) | |
1182 |
|
1182 | |||
1183 | '''*** Constants A-H correspond to the convention as in Briggs and Vincent 1992 ***''' |
|
1183 | '''*** Constants A-H correspond to the convention as in Briggs and Vincent 1992 ***''' | |
1184 |
|
1184 | |||
1185 | '''Getting constant C''' |
|
1185 | '''Getting constant C''' | |
1186 | cC=(Fij*numpy.pi)**2 |
|
1186 | cC=(Fij*numpy.pi)**2 | |
1187 |
|
1187 | |||
1188 | '''****** Getting constants F and G ******''' |
|
1188 | '''****** Getting constants F and G ******''' | |
1189 | MijEijNij = numpy.array([[Xi02,Eta02], [Xi12,Eta12]]) |
|
1189 | MijEijNij = numpy.array([[Xi02,Eta02], [Xi12,Eta12]]) | |
1190 | # MijEijNij = numpy.array([[Xi01,Eta01], [Xi02,Eta02], [Xi12,Eta12]]) |
|
1190 | # MijEijNij = numpy.array([[Xi01,Eta01], [Xi02,Eta02], [Xi12,Eta12]]) | |
1191 | # MijResult0 = (-PhaseSlope[0] * cC) / (2*numpy.pi) |
|
1191 | # MijResult0 = (-PhaseSlope[0] * cC) / (2*numpy.pi) | |
1192 | MijResult1 = (-PhaseSlope[1] * cC) / (2*numpy.pi) |
|
1192 | MijResult1 = (-PhaseSlope[1] * cC) / (2*numpy.pi) | |
1193 | MijResult2 = (-PhaseSlope[2] * cC) / (2*numpy.pi) |
|
1193 | MijResult2 = (-PhaseSlope[2] * cC) / (2*numpy.pi) | |
1194 | # MijResults = numpy.array([MijResult0, MijResult1, MijResult2]) |
|
1194 | # MijResults = numpy.array([MijResult0, MijResult1, MijResult2]) | |
1195 | MijResults = numpy.array([MijResult1, MijResult2]) |
|
1195 | MijResults = numpy.array([MijResult1, MijResult2]) | |
1196 | (cF,cG) = numpy.linalg.solve(MijEijNij, MijResults) |
|
1196 | (cF,cG) = numpy.linalg.solve(MijEijNij, MijResults) | |
1197 |
|
1197 | |||
1198 | '''****** Getting constants A, B and H ******''' |
|
1198 | '''****** Getting constants A, B and H ******''' | |
1199 | W01 = numpy.nanmax( FitGauss01 ) |
|
1199 | W01 = numpy.nanmax( FitGauss01 ) | |
1200 | W02 = numpy.nanmax( FitGauss02 ) |
|
1200 | W02 = numpy.nanmax( FitGauss02 ) | |
1201 | W12 = numpy.nanmax( FitGauss12 ) |
|
1201 | W12 = numpy.nanmax( FitGauss12 ) | |
1202 |
|
1202 | |||
1203 | WijResult01 = ((cF * Xi01 + cG * Eta01)**2)/cC - numpy.log(W01 / numpy.sqrt(numpy.pi / cC)) |
|
1203 | WijResult01 = ((cF * Xi01 + cG * Eta01)**2)/cC - numpy.log(W01 / numpy.sqrt(numpy.pi / cC)) | |
1204 | WijResult02 = ((cF * Xi02 + cG * Eta02)**2)/cC - numpy.log(W02 / numpy.sqrt(numpy.pi / cC)) |
|
1204 | WijResult02 = ((cF * Xi02 + cG * Eta02)**2)/cC - numpy.log(W02 / numpy.sqrt(numpy.pi / cC)) | |
1205 | WijResult12 = ((cF * Xi12 + cG * Eta12)**2)/cC - numpy.log(W12 / numpy.sqrt(numpy.pi / cC)) |
|
1205 | WijResult12 = ((cF * Xi12 + cG * Eta12)**2)/cC - numpy.log(W12 / numpy.sqrt(numpy.pi / cC)) | |
1206 | WijResults = numpy.array([WijResult01, WijResult02, WijResult12]) |
|
1206 | WijResults = numpy.array([WijResult01, WijResult02, WijResult12]) | |
1207 |
|
1207 | |||
1208 | WijEijNij = numpy.array([ [Xi01**2, Eta01**2, 2*Xi01*Eta01] , [Xi02**2, Eta02**2, 2*Xi02*Eta02] , [Xi12**2, Eta12**2, 2*Xi12*Eta12] ]) |
|
1208 | WijEijNij = numpy.array([ [Xi01**2, Eta01**2, 2*Xi01*Eta01] , [Xi02**2, Eta02**2, 2*Xi02*Eta02] , [Xi12**2, Eta12**2, 2*Xi12*Eta12] ]) | |
1209 | (cA,cB,cH) = numpy.linalg.solve(WijEijNij, WijResults) |
|
1209 | (cA,cB,cH) = numpy.linalg.solve(WijEijNij, WijResults) | |
1210 |
|
1210 | |||
1211 | VxVy = numpy.array([[cA,cH],[cH,cB]]) |
|
1211 | VxVy = numpy.array([[cA,cH],[cH,cB]]) | |
1212 | VxVyResults = numpy.array([-cF,-cG]) |
|
1212 | VxVyResults = numpy.array([-cF,-cG]) | |
1213 | (Vmer,Vzon) = numpy.linalg.solve(VxVy, VxVyResults) |
|
1213 | (Vmer,Vzon) = numpy.linalg.solve(VxVy, VxVyResults) | |
1214 | Vver = -SPCMoments[1]*SPEED_OF_LIGHT/(2*radfreq) |
|
1214 | Vver = -SPCMoments[1]*SPEED_OF_LIGHT/(2*radfreq) | |
1215 | error_code = 0 |
|
1215 | error_code = 0 | |
1216 |
|
1216 | |||
1217 | return Vzon, Vmer, Vver, error_code |
|
1217 | return Vzon, Vmer, Vver, error_code | |
1218 |
|
1218 | |||
1219 | class SpectralMoments(Operation): |
|
1219 | class SpectralMoments(Operation): | |
1220 |
|
1220 | |||
1221 | ''' |
|
1221 | ''' | |
1222 | Function SpectralMoments() |
|
1222 | Function SpectralMoments() | |
1223 |
|
1223 | |||
1224 | Calculates moments (power, mean, standard deviation) and SNR of the signal |
|
1224 | Calculates moments (power, mean, standard deviation) and SNR of the signal | |
1225 |
|
1225 | |||
1226 | Type of dataIn: Spectra |
|
1226 | Type of dataIn: Spectra | |
1227 |
|
1227 | |||
1228 | Configuration Parameters: |
|
1228 | Configuration Parameters: | |
1229 |
|
1229 | |||
1230 | dirCosx : Cosine director in X axis |
|
1230 | dirCosx : Cosine director in X axis | |
1231 | dirCosy : Cosine director in Y axis |
|
1231 | dirCosy : Cosine director in Y axis | |
1232 |
|
1232 | |||
1233 | elevation : |
|
1233 | elevation : | |
1234 | azimuth : |
|
1234 | azimuth : | |
1235 |
|
1235 | |||
1236 | Input: |
|
1236 | Input: | |
1237 | channelList : simple channel list to select e.g. [2,3,7] |
|
1237 | channelList : simple channel list to select e.g. [2,3,7] | |
1238 | self.dataOut.data_pre : Spectral data |
|
1238 | self.dataOut.data_pre : Spectral data | |
1239 | self.dataOut.abscissaList : List of frequencies |
|
1239 | self.dataOut.abscissaList : List of frequencies | |
1240 | self.dataOut.noise : Noise level per channel |
|
1240 | self.dataOut.noise : Noise level per channel | |
1241 |
|
1241 | |||
1242 | Affected: |
|
1242 | Affected: | |
1243 | self.dataOut.moments : Parameters per channel |
|
1243 | self.dataOut.moments : Parameters per channel | |
1244 | self.dataOut.data_snr : SNR per channel |
|
1244 | self.dataOut.data_snr : SNR per channel | |
1245 |
|
1245 | |||
1246 | ''' |
|
1246 | ''' | |
1247 |
|
1247 | |||
1248 | def run(self, dataOut): |
|
1248 | def run(self, dataOut): | |
1249 |
|
1249 | |||
1250 | data = dataOut.data_pre[0] |
|
1250 | data = dataOut.data_pre[0] | |
1251 | absc = dataOut.abscissaList[:-1] |
|
1251 | absc = dataOut.abscissaList[:-1] | |
1252 | noise = dataOut.noise |
|
1252 | noise = dataOut.noise | |
1253 | nChannel = data.shape[0] |
|
1253 | nChannel = data.shape[0] | |
1254 | data_param = numpy.zeros((nChannel, 4, data.shape[2])) |
|
1254 | data_param = numpy.zeros((nChannel, 4, data.shape[2])) | |
1255 |
|
1255 | |||
1256 | for ind in range(nChannel): |
|
1256 | for ind in range(nChannel): | |
1257 | data_param[ind,:,:] = self.__calculateMoments( data[ind,:,:] , absc , noise[ind] ) |
|
1257 | data_param[ind,:,:] = self.__calculateMoments( data[ind,:,:] , absc , noise[ind] ) | |
1258 |
|
1258 | |||
1259 | dataOut.moments = data_param[:,1:,:] |
|
1259 | dataOut.moments = data_param[:,1:,:] | |
1260 | dataOut.data_snr = data_param[:,0] |
|
1260 | dataOut.data_snr = data_param[:,0] | |
1261 | dataOut.data_pow = data_param[:,1] |
|
1261 | dataOut.data_pow = data_param[:,1] | |
1262 | dataOut.data_dop = data_param[:,2] |
|
1262 | dataOut.data_dop = data_param[:,2] | |
1263 | dataOut.data_width = data_param[:,3] |
|
1263 | dataOut.data_width = data_param[:,3] | |
1264 | return dataOut |
|
1264 | return dataOut | |
1265 |
|
1265 | |||
1266 | def __calculateMoments(self, oldspec, oldfreq, n0, |
|
1266 | def __calculateMoments(self, oldspec, oldfreq, n0, | |
1267 | nicoh = None, graph = None, smooth = None, type1 = None, fwindow = None, snrth = None, dc = None, aliasing = None, oldfd = None, wwauto = None): |
|
1267 | nicoh = None, graph = None, smooth = None, type1 = None, fwindow = None, snrth = None, dc = None, aliasing = None, oldfd = None, wwauto = None): | |
1268 |
|
1268 | |||
1269 | if (nicoh is None): nicoh = 1 |
|
1269 | if (nicoh is None): nicoh = 1 | |
1270 | if (graph is None): graph = 0 |
|
1270 | if (graph is None): graph = 0 | |
1271 | if (smooth is None): smooth = 0 |
|
1271 | if (smooth is None): smooth = 0 | |
1272 | elif (self.smooth < 3): smooth = 0 |
|
1272 | elif (self.smooth < 3): smooth = 0 | |
1273 |
|
1273 | |||
1274 | if (type1 is None): type1 = 0 |
|
1274 | if (type1 is None): type1 = 0 | |
1275 | if (fwindow is None): fwindow = numpy.zeros(oldfreq.size) + 1 |
|
1275 | if (fwindow is None): fwindow = numpy.zeros(oldfreq.size) + 1 | |
1276 | if (snrth is None): snrth = -3 |
|
1276 | if (snrth is None): snrth = -3 | |
1277 | if (dc is None): dc = 0 |
|
1277 | if (dc is None): dc = 0 | |
1278 | if (aliasing is None): aliasing = 0 |
|
1278 | if (aliasing is None): aliasing = 0 | |
1279 | if (oldfd is None): oldfd = 0 |
|
1279 | if (oldfd is None): oldfd = 0 | |
1280 | if (wwauto is None): wwauto = 0 |
|
1280 | if (wwauto is None): wwauto = 0 | |
1281 |
|
1281 | |||
1282 | if (n0 < 1.e-20): n0 = 1.e-20 |
|
1282 | if (n0 < 1.e-20): n0 = 1.e-20 | |
1283 |
|
1283 | |||
1284 | freq = oldfreq |
|
1284 | freq = oldfreq | |
1285 | vec_power = numpy.zeros(oldspec.shape[1]) |
|
1285 | vec_power = numpy.zeros(oldspec.shape[1]) | |
1286 | vec_fd = numpy.zeros(oldspec.shape[1]) |
|
1286 | vec_fd = numpy.zeros(oldspec.shape[1]) | |
1287 | vec_w = numpy.zeros(oldspec.shape[1]) |
|
1287 | vec_w = numpy.zeros(oldspec.shape[1]) | |
1288 | vec_snr = numpy.zeros(oldspec.shape[1]) |
|
1288 | vec_snr = numpy.zeros(oldspec.shape[1]) | |
1289 |
|
1289 | |||
1290 | # oldspec = numpy.ma.masked_invalid(oldspec) |
|
1290 | # oldspec = numpy.ma.masked_invalid(oldspec) | |
1291 | for ind in range(oldspec.shape[1]): |
|
1291 | for ind in range(oldspec.shape[1]): | |
1292 |
|
1292 | |||
1293 | spec = oldspec[:,ind] |
|
1293 | spec = oldspec[:,ind] | |
1294 | aux = spec*fwindow |
|
1294 | aux = spec*fwindow | |
1295 | max_spec = aux.max() |
|
1295 | max_spec = aux.max() | |
1296 | m = aux.tolist().index(max_spec) |
|
1296 | m = aux.tolist().index(max_spec) | |
1297 |
|
1297 | |||
1298 | # Smooth |
|
1298 | # Smooth | |
1299 | if (smooth == 0): |
|
1299 | if (smooth == 0): | |
1300 | spec2 = spec |
|
1300 | spec2 = spec | |
1301 | else: |
|
1301 | else: | |
1302 | spec2 = scipy.ndimage.filters.uniform_filter1d(spec,size=smooth) |
|
1302 | spec2 = scipy.ndimage.filters.uniform_filter1d(spec,size=smooth) | |
1303 |
|
1303 | |||
1304 | # Moments Estimation |
|
1304 | # Moments Estimation | |
1305 | bb = spec2[numpy.arange(m,spec2.size)] |
|
1305 | bb = spec2[numpy.arange(m,spec2.size)] | |
1306 | bb = (bb<n0).nonzero() |
|
1306 | bb = (bb<n0).nonzero() | |
1307 | bb = bb[0] |
|
1307 | bb = bb[0] | |
1308 |
|
1308 | |||
1309 | ss = spec2[numpy.arange(0,m + 1)] |
|
1309 | ss = spec2[numpy.arange(0,m + 1)] | |
1310 | ss = (ss<n0).nonzero() |
|
1310 | ss = (ss<n0).nonzero() | |
1311 | ss = ss[0] |
|
1311 | ss = ss[0] | |
1312 |
|
1312 | |||
1313 | if (bb.size == 0): |
|
1313 | if (bb.size == 0): | |
1314 | bb0 = spec.size - 1 - m |
|
1314 | bb0 = spec.size - 1 - m | |
1315 | else: |
|
1315 | else: | |
1316 | bb0 = bb[0] - 1 |
|
1316 | bb0 = bb[0] - 1 | |
1317 | if (bb0 < 0): |
|
1317 | if (bb0 < 0): | |
1318 | bb0 = 0 |
|
1318 | bb0 = 0 | |
1319 |
|
1319 | |||
1320 | if (ss.size == 0): |
|
1320 | if (ss.size == 0): | |
1321 | ss1 = 1 |
|
1321 | ss1 = 1 | |
1322 | else: |
|
1322 | else: | |
1323 | ss1 = max(ss) + 1 |
|
1323 | ss1 = max(ss) + 1 | |
1324 |
|
1324 | |||
1325 | if (ss1 > m): |
|
1325 | if (ss1 > m): | |
1326 | ss1 = m |
|
1326 | ss1 = m | |
1327 |
|
1327 | |||
1328 | #valid = numpy.arange(int(m + bb0 - ss1 + 1)) + ss1 |
|
1328 | #valid = numpy.arange(int(m + bb0 - ss1 + 1)) + ss1 | |
1329 | valid = numpy.arange(1,oldspec.shape[0])# valid perfil completo igual pulsepair |
|
1329 | valid = numpy.arange(1,oldspec.shape[0])# valid perfil completo igual pulsepair | |
1330 | signal_power = ((spec2[valid] - n0) * fwindow[valid]).mean() # D. ScipiΓ³n added with correct definition |
|
1330 | signal_power = ((spec2[valid] - n0) * fwindow[valid]).mean() # D. ScipiΓ³n added with correct definition | |
1331 | total_power = (spec2[valid] * fwindow[valid]).mean() # D. ScipiΓ³n added with correct definition |
|
1331 | total_power = (spec2[valid] * fwindow[valid]).mean() # D. ScipiΓ³n added with correct definition | |
1332 | power = ((spec2[valid] - n0) * fwindow[valid]).sum() |
|
1332 | power = ((spec2[valid] - n0) * fwindow[valid]).sum() | |
1333 | fd = ((spec2[valid]- n0)*freq[valid] * fwindow[valid]).sum() / power |
|
1333 | fd = ((spec2[valid]- n0)*freq[valid] * fwindow[valid]).sum() / power | |
1334 | w = numpy.sqrt(((spec2[valid] - n0)*fwindow[valid]*(freq[valid]- fd)**2).sum() / power) |
|
1334 | w = numpy.sqrt(((spec2[valid] - n0)*fwindow[valid]*(freq[valid]- fd)**2).sum() / power) | |
1335 | snr = (spec2.mean()-n0)/n0 |
|
1335 | snr = (spec2.mean()-n0)/n0 | |
1336 | if (snr < 1.e-20) : |
|
1336 | if (snr < 1.e-20) : | |
1337 | snr = 1.e-20 |
|
1337 | snr = 1.e-20 | |
1338 |
|
1338 | |||
1339 | # vec_power[ind] = power #D. ScipiΓ³n replaced with the line below |
|
1339 | # vec_power[ind] = power #D. ScipiΓ³n replaced with the line below | |
1340 | vec_power[ind] = total_power |
|
1340 | vec_power[ind] = total_power | |
1341 | vec_fd[ind] = fd |
|
1341 | vec_fd[ind] = fd | |
1342 | vec_w[ind] = w |
|
1342 | vec_w[ind] = w | |
1343 | vec_snr[ind] = snr |
|
1343 | vec_snr[ind] = snr | |
1344 |
|
1344 | |||
1345 | return numpy.vstack((vec_snr, vec_power, vec_fd, vec_w)) |
|
1345 | return numpy.vstack((vec_snr, vec_power, vec_fd, vec_w)) | |
1346 |
|
1346 | |||
1347 | #------------------ Get SA Parameters -------------------------- |
|
1347 | #------------------ Get SA Parameters -------------------------- | |
1348 |
|
1348 | |||
1349 | def GetSAParameters(self): |
|
1349 | def GetSAParameters(self): | |
1350 | #SA en frecuencia |
|
1350 | #SA en frecuencia | |
1351 | pairslist = self.dataOut.groupList |
|
1351 | pairslist = self.dataOut.groupList | |
1352 | num_pairs = len(pairslist) |
|
1352 | num_pairs = len(pairslist) | |
1353 |
|
1353 | |||
1354 | vel = self.dataOut.abscissaList |
|
1354 | vel = self.dataOut.abscissaList | |
1355 | spectra = self.dataOut.data_pre |
|
1355 | spectra = self.dataOut.data_pre | |
1356 | cspectra = self.dataIn.data_cspc |
|
1356 | cspectra = self.dataIn.data_cspc | |
1357 | delta_v = vel[1] - vel[0] |
|
1357 | delta_v = vel[1] - vel[0] | |
1358 |
|
1358 | |||
1359 | #Calculating the power spectrum |
|
1359 | #Calculating the power spectrum | |
1360 | spc_pow = numpy.sum(spectra, 3)*delta_v |
|
1360 | spc_pow = numpy.sum(spectra, 3)*delta_v | |
1361 | #Normalizing Spectra |
|
1361 | #Normalizing Spectra | |
1362 | norm_spectra = spectra/spc_pow |
|
1362 | norm_spectra = spectra/spc_pow | |
1363 | #Calculating the norm_spectra at peak |
|
1363 | #Calculating the norm_spectra at peak | |
1364 | max_spectra = numpy.max(norm_spectra, 3) |
|
1364 | max_spectra = numpy.max(norm_spectra, 3) | |
1365 |
|
1365 | |||
1366 | #Normalizing Cross Spectra |
|
1366 | #Normalizing Cross Spectra | |
1367 | norm_cspectra = numpy.zeros(cspectra.shape) |
|
1367 | norm_cspectra = numpy.zeros(cspectra.shape) | |
1368 |
|
1368 | |||
1369 | for i in range(num_chan): |
|
1369 | for i in range(num_chan): | |
1370 | norm_cspectra[i,:,:] = cspectra[i,:,:]/numpy.sqrt(spc_pow[pairslist[i][0],:]*spc_pow[pairslist[i][1],:]) |
|
1370 | norm_cspectra[i,:,:] = cspectra[i,:,:]/numpy.sqrt(spc_pow[pairslist[i][0],:]*spc_pow[pairslist[i][1],:]) | |
1371 |
|
1371 | |||
1372 | max_cspectra = numpy.max(norm_cspectra,2) |
|
1372 | max_cspectra = numpy.max(norm_cspectra,2) | |
1373 | max_cspectra_index = numpy.argmax(norm_cspectra, 2) |
|
1373 | max_cspectra_index = numpy.argmax(norm_cspectra, 2) | |
1374 |
|
1374 | |||
1375 | for i in range(num_pairs): |
|
1375 | for i in range(num_pairs): | |
1376 | cspc_par[i,:,:] = __calculateMoments(norm_cspectra) |
|
1376 | cspc_par[i,:,:] = __calculateMoments(norm_cspectra) | |
1377 | #------------------- Get Lags ---------------------------------- |
|
1377 | #------------------- Get Lags ---------------------------------- | |
1378 |
|
1378 | |||
1379 | class SALags(Operation): |
|
1379 | class SALags(Operation): | |
1380 | ''' |
|
1380 | ''' | |
1381 | Function GetMoments() |
|
1381 | Function GetMoments() | |
1382 |
|
1382 | |||
1383 | Input: |
|
1383 | Input: | |
1384 | self.dataOut.data_pre |
|
1384 | self.dataOut.data_pre | |
1385 | self.dataOut.abscissaList |
|
1385 | self.dataOut.abscissaList | |
1386 | self.dataOut.noise |
|
1386 | self.dataOut.noise | |
1387 | self.dataOut.normFactor |
|
1387 | self.dataOut.normFactor | |
1388 | self.dataOut.data_snr |
|
1388 | self.dataOut.data_snr | |
1389 | self.dataOut.groupList |
|
1389 | self.dataOut.groupList | |
1390 | self.dataOut.nChannels |
|
1390 | self.dataOut.nChannels | |
1391 |
|
1391 | |||
1392 | Affected: |
|
1392 | Affected: | |
1393 | self.dataOut.data_param |
|
1393 | self.dataOut.data_param | |
1394 |
|
1394 | |||
1395 | ''' |
|
1395 | ''' | |
1396 | def run(self, dataOut): |
|
1396 | def run(self, dataOut): | |
1397 | data_acf = dataOut.data_pre[0] |
|
1397 | data_acf = dataOut.data_pre[0] | |
1398 | data_ccf = dataOut.data_pre[1] |
|
1398 | data_ccf = dataOut.data_pre[1] | |
1399 | normFactor_acf = dataOut.normFactor[0] |
|
1399 | normFactor_acf = dataOut.normFactor[0] | |
1400 | normFactor_ccf = dataOut.normFactor[1] |
|
1400 | normFactor_ccf = dataOut.normFactor[1] | |
1401 | pairs_acf = dataOut.groupList[0] |
|
1401 | pairs_acf = dataOut.groupList[0] | |
1402 | pairs_ccf = dataOut.groupList[1] |
|
1402 | pairs_ccf = dataOut.groupList[1] | |
1403 |
|
1403 | |||
1404 | nHeights = dataOut.nHeights |
|
1404 | nHeights = dataOut.nHeights | |
1405 | absc = dataOut.abscissaList |
|
1405 | absc = dataOut.abscissaList | |
1406 | noise = dataOut.noise |
|
1406 | noise = dataOut.noise | |
1407 | SNR = dataOut.data_snr |
|
1407 | SNR = dataOut.data_snr | |
1408 | nChannels = dataOut.nChannels |
|
1408 | nChannels = dataOut.nChannels | |
1409 | # pairsList = dataOut.groupList |
|
1409 | # pairsList = dataOut.groupList | |
1410 | # pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairsList, nChannels) |
|
1410 | # pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairsList, nChannels) | |
1411 |
|
1411 | |||
1412 | for l in range(len(pairs_acf)): |
|
1412 | for l in range(len(pairs_acf)): | |
1413 | data_acf[l,:,:] = data_acf[l,:,:]/normFactor_acf[l,:] |
|
1413 | data_acf[l,:,:] = data_acf[l,:,:]/normFactor_acf[l,:] | |
1414 |
|
1414 | |||
1415 | for l in range(len(pairs_ccf)): |
|
1415 | for l in range(len(pairs_ccf)): | |
1416 | data_ccf[l,:,:] = data_ccf[l,:,:]/normFactor_ccf[l,:] |
|
1416 | data_ccf[l,:,:] = data_ccf[l,:,:]/normFactor_ccf[l,:] | |
1417 |
|
1417 | |||
1418 | dataOut.data_param = numpy.zeros((len(pairs_ccf)*2 + 1, nHeights)) |
|
1418 | dataOut.data_param = numpy.zeros((len(pairs_ccf)*2 + 1, nHeights)) | |
1419 | dataOut.data_param[:-1,:] = self.__calculateTaus(data_acf, data_ccf, absc) |
|
1419 | dataOut.data_param[:-1,:] = self.__calculateTaus(data_acf, data_ccf, absc) | |
1420 | dataOut.data_param[-1,:] = self.__calculateLag1Phase(data_acf, absc) |
|
1420 | dataOut.data_param[-1,:] = self.__calculateLag1Phase(data_acf, absc) | |
1421 | return |
|
1421 | return | |
1422 |
|
1422 | |||
1423 | # def __getPairsAutoCorr(self, pairsList, nChannels): |
|
1423 | # def __getPairsAutoCorr(self, pairsList, nChannels): | |
1424 | # |
|
1424 | # | |
1425 | # pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan |
|
1425 | # pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan | |
1426 | # |
|
1426 | # | |
1427 | # for l in range(len(pairsList)): |
|
1427 | # for l in range(len(pairsList)): | |
1428 | # firstChannel = pairsList[l][0] |
|
1428 | # firstChannel = pairsList[l][0] | |
1429 | # secondChannel = pairsList[l][1] |
|
1429 | # secondChannel = pairsList[l][1] | |
1430 | # |
|
1430 | # | |
1431 | # #Obteniendo pares de Autocorrelacion |
|
1431 | # #Obteniendo pares de Autocorrelacion | |
1432 | # if firstChannel == secondChannel: |
|
1432 | # if firstChannel == secondChannel: | |
1433 | # pairsAutoCorr[firstChannel] = int(l) |
|
1433 | # pairsAutoCorr[firstChannel] = int(l) | |
1434 | # |
|
1434 | # | |
1435 | # pairsAutoCorr = pairsAutoCorr.astype(int) |
|
1435 | # pairsAutoCorr = pairsAutoCorr.astype(int) | |
1436 | # |
|
1436 | # | |
1437 | # pairsCrossCorr = range(len(pairsList)) |
|
1437 | # pairsCrossCorr = range(len(pairsList)) | |
1438 | # pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr) |
|
1438 | # pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr) | |
1439 | # |
|
1439 | # | |
1440 | # return pairsAutoCorr, pairsCrossCorr |
|
1440 | # return pairsAutoCorr, pairsCrossCorr | |
1441 |
|
1441 | |||
1442 | def __calculateTaus(self, data_acf, data_ccf, lagRange): |
|
1442 | def __calculateTaus(self, data_acf, data_ccf, lagRange): | |
1443 |
|
1443 | |||
1444 | lag0 = data_acf.shape[1]/2 |
|
1444 | lag0 = data_acf.shape[1]/2 | |
1445 | #Funcion de Autocorrelacion |
|
1445 | #Funcion de Autocorrelacion | |
1446 | mean_acf = stats.nanmean(data_acf, axis = 0) |
|
1446 | mean_acf = stats.nanmean(data_acf, axis = 0) | |
1447 |
|
1447 | |||
1448 | #Obtencion Indice de TauCross |
|
1448 | #Obtencion Indice de TauCross | |
1449 | ind_ccf = data_ccf.argmax(axis = 1) |
|
1449 | ind_ccf = data_ccf.argmax(axis = 1) | |
1450 | #Obtencion Indice de TauAuto |
|
1450 | #Obtencion Indice de TauAuto | |
1451 | ind_acf = numpy.zeros(ind_ccf.shape,dtype = 'int') |
|
1451 | ind_acf = numpy.zeros(ind_ccf.shape,dtype = 'int') | |
1452 | ccf_lag0 = data_ccf[:,lag0,:] |
|
1452 | ccf_lag0 = data_ccf[:,lag0,:] | |
1453 |
|
1453 | |||
1454 | for i in range(ccf_lag0.shape[0]): |
|
1454 | for i in range(ccf_lag0.shape[0]): | |
1455 | ind_acf[i,:] = numpy.abs(mean_acf - ccf_lag0[i,:]).argmin(axis = 0) |
|
1455 | ind_acf[i,:] = numpy.abs(mean_acf - ccf_lag0[i,:]).argmin(axis = 0) | |
1456 |
|
1456 | |||
1457 | #Obtencion de TauCross y TauAuto |
|
1457 | #Obtencion de TauCross y TauAuto | |
1458 | tau_ccf = lagRange[ind_ccf] |
|
1458 | tau_ccf = lagRange[ind_ccf] | |
1459 | tau_acf = lagRange[ind_acf] |
|
1459 | tau_acf = lagRange[ind_acf] | |
1460 |
|
1460 | |||
1461 | Nan1, Nan2 = numpy.where(tau_ccf == lagRange[0]) |
|
1461 | Nan1, Nan2 = numpy.where(tau_ccf == lagRange[0]) | |
1462 |
|
1462 | |||
1463 | tau_ccf[Nan1,Nan2] = numpy.nan |
|
1463 | tau_ccf[Nan1,Nan2] = numpy.nan | |
1464 | tau_acf[Nan1,Nan2] = numpy.nan |
|
1464 | tau_acf[Nan1,Nan2] = numpy.nan | |
1465 | tau = numpy.vstack((tau_ccf,tau_acf)) |
|
1465 | tau = numpy.vstack((tau_ccf,tau_acf)) | |
1466 |
|
1466 | |||
1467 | return tau |
|
1467 | return tau | |
1468 |
|
1468 | |||
1469 | def __calculateLag1Phase(self, data, lagTRange): |
|
1469 | def __calculateLag1Phase(self, data, lagTRange): | |
1470 | data1 = stats.nanmean(data, axis = 0) |
|
1470 | data1 = stats.nanmean(data, axis = 0) | |
1471 | lag1 = numpy.where(lagTRange == 0)[0][0] + 1 |
|
1471 | lag1 = numpy.where(lagTRange == 0)[0][0] + 1 | |
1472 |
|
1472 | |||
1473 | phase = numpy.angle(data1[lag1,:]) |
|
1473 | phase = numpy.angle(data1[lag1,:]) | |
1474 |
|
1474 | |||
1475 | return phase |
|
1475 | return phase | |
1476 |
|
1476 | |||
1477 | class SpectralFitting(Operation): |
|
1477 | class SpectralFitting(Operation): | |
1478 | ''' |
|
1478 | ''' | |
1479 | Function GetMoments() |
|
1479 | Function GetMoments() | |
1480 |
|
1480 | |||
1481 | Input: |
|
1481 | Input: | |
1482 | Output: |
|
1482 | Output: | |
1483 | Variables modified: |
|
1483 | Variables modified: | |
1484 | ''' |
|
1484 | ''' | |
1485 |
|
1485 | |||
1486 | def run(self, dataOut, getSNR = True, path=None, file=None, groupList=None): |
|
1486 | def run(self, dataOut, getSNR = True, path=None, file=None, groupList=None): | |
1487 |
|
1487 | |||
1488 |
|
1488 | |||
1489 | if path != None: |
|
1489 | if path != None: | |
1490 | sys.path.append(path) |
|
1490 | sys.path.append(path) | |
1491 | self.dataOut.library = importlib.import_module(file) |
|
1491 | self.dataOut.library = importlib.import_module(file) | |
1492 |
|
1492 | |||
1493 | #To be inserted as a parameter |
|
1493 | #To be inserted as a parameter | |
1494 | groupArray = numpy.array(groupList) |
|
1494 | groupArray = numpy.array(groupList) | |
1495 | # groupArray = numpy.array([[0,1],[2,3]]) |
|
1495 | # groupArray = numpy.array([[0,1],[2,3]]) | |
1496 | self.dataOut.groupList = groupArray |
|
1496 | self.dataOut.groupList = groupArray | |
1497 |
|
1497 | |||
1498 | nGroups = groupArray.shape[0] |
|
1498 | nGroups = groupArray.shape[0] | |
1499 | nChannels = self.dataIn.nChannels |
|
1499 | nChannels = self.dataIn.nChannels | |
1500 | nHeights=self.dataIn.heightList.size |
|
1500 | nHeights=self.dataIn.heightList.size | |
1501 |
|
1501 | |||
1502 | #Parameters Array |
|
1502 | #Parameters Array | |
1503 | self.dataOut.data_param = None |
|
1503 | self.dataOut.data_param = None | |
1504 |
|
1504 | |||
1505 | #Set constants |
|
1505 | #Set constants | |
1506 | constants = self.dataOut.library.setConstants(self.dataIn) |
|
1506 | constants = self.dataOut.library.setConstants(self.dataIn) | |
1507 | self.dataOut.constants = constants |
|
1507 | self.dataOut.constants = constants | |
1508 | M = self.dataIn.normFactor |
|
1508 | M = self.dataIn.normFactor | |
1509 | N = self.dataIn.nFFTPoints |
|
1509 | N = self.dataIn.nFFTPoints | |
1510 | ippSeconds = self.dataIn.ippSeconds |
|
1510 | ippSeconds = self.dataIn.ippSeconds | |
1511 | K = self.dataIn.nIncohInt |
|
1511 | K = self.dataIn.nIncohInt | |
1512 | pairsArray = numpy.array(self.dataIn.pairsList) |
|
1512 | pairsArray = numpy.array(self.dataIn.pairsList) | |
1513 |
|
1513 | |||
1514 | #List of possible combinations |
|
1514 | #List of possible combinations | |
1515 | listComb = itertools.combinations(numpy.arange(groupArray.shape[1]),2) |
|
1515 | listComb = itertools.combinations(numpy.arange(groupArray.shape[1]),2) | |
1516 | indCross = numpy.zeros(len(list(listComb)), dtype = 'int') |
|
1516 | indCross = numpy.zeros(len(list(listComb)), dtype = 'int') | |
1517 |
|
1517 | |||
1518 | if getSNR: |
|
1518 | if getSNR: | |
1519 | listChannels = groupArray.reshape((groupArray.size)) |
|
1519 | listChannels = groupArray.reshape((groupArray.size)) | |
1520 | listChannels.sort() |
|
1520 | listChannels.sort() | |
1521 | noise = self.dataIn.getNoise() |
|
1521 | noise = self.dataIn.getNoise() | |
1522 | self.dataOut.data_snr = self.__getSNR(self.dataIn.data_spc[listChannels,:,:], noise[listChannels]) |
|
1522 | self.dataOut.data_snr = self.__getSNR(self.dataIn.data_spc[listChannels,:,:], noise[listChannels]) | |
1523 |
|
1523 | |||
1524 | for i in range(nGroups): |
|
1524 | for i in range(nGroups): | |
1525 | coord = groupArray[i,:] |
|
1525 | coord = groupArray[i,:] | |
1526 |
|
1526 | |||
1527 | #Input data array |
|
1527 | #Input data array | |
1528 | data = self.dataIn.data_spc[coord,:,:]/(M*N) |
|
1528 | data = self.dataIn.data_spc[coord,:,:]/(M*N) | |
1529 | data = data.reshape((data.shape[0]*data.shape[1],data.shape[2])) |
|
1529 | data = data.reshape((data.shape[0]*data.shape[1],data.shape[2])) | |
1530 |
|
1530 | |||
1531 | #Cross Spectra data array for Covariance Matrixes |
|
1531 | #Cross Spectra data array for Covariance Matrixes | |
1532 | ind = 0 |
|
1532 | ind = 0 | |
1533 | for pairs in listComb: |
|
1533 | for pairs in listComb: | |
1534 | pairsSel = numpy.array([coord[x],coord[y]]) |
|
1534 | pairsSel = numpy.array([coord[x],coord[y]]) | |
1535 | indCross[ind] = int(numpy.where(numpy.all(pairsArray == pairsSel, axis = 1))[0][0]) |
|
1535 | indCross[ind] = int(numpy.where(numpy.all(pairsArray == pairsSel, axis = 1))[0][0]) | |
1536 | ind += 1 |
|
1536 | ind += 1 | |
1537 | dataCross = self.dataIn.data_cspc[indCross,:,:]/(M*N) |
|
1537 | dataCross = self.dataIn.data_cspc[indCross,:,:]/(M*N) | |
1538 | dataCross = dataCross**2/K |
|
1538 | dataCross = dataCross**2/K | |
1539 |
|
1539 | |||
1540 | for h in range(nHeights): |
|
1540 | for h in range(nHeights): | |
1541 |
|
1541 | |||
1542 | #Input |
|
1542 | #Input | |
1543 | d = data[:,h] |
|
1543 | d = data[:,h] | |
1544 |
|
1544 | |||
1545 | #Covariance Matrix |
|
1545 | #Covariance Matrix | |
1546 | D = numpy.diag(d**2/K) |
|
1546 | D = numpy.diag(d**2/K) | |
1547 | ind = 0 |
|
1547 | ind = 0 | |
1548 | for pairs in listComb: |
|
1548 | for pairs in listComb: | |
1549 | #Coordinates in Covariance Matrix |
|
1549 | #Coordinates in Covariance Matrix | |
1550 | x = pairs[0] |
|
1550 | x = pairs[0] | |
1551 | y = pairs[1] |
|
1551 | y = pairs[1] | |
1552 | #Channel Index |
|
1552 | #Channel Index | |
1553 | S12 = dataCross[ind,:,h] |
|
1553 | S12 = dataCross[ind,:,h] | |
1554 | D12 = numpy.diag(S12) |
|
1554 | D12 = numpy.diag(S12) | |
1555 | #Completing Covariance Matrix with Cross Spectras |
|
1555 | #Completing Covariance Matrix with Cross Spectras | |
1556 | D[x*N:(x+1)*N,y*N:(y+1)*N] = D12 |
|
1556 | D[x*N:(x+1)*N,y*N:(y+1)*N] = D12 | |
1557 | D[y*N:(y+1)*N,x*N:(x+1)*N] = D12 |
|
1557 | D[y*N:(y+1)*N,x*N:(x+1)*N] = D12 | |
1558 | ind += 1 |
|
1558 | ind += 1 | |
1559 | Dinv=numpy.linalg.inv(D) |
|
1559 | Dinv=numpy.linalg.inv(D) | |
1560 | L=numpy.linalg.cholesky(Dinv) |
|
1560 | L=numpy.linalg.cholesky(Dinv) | |
1561 | LT=L.T |
|
1561 | LT=L.T | |
1562 |
|
1562 | |||
1563 | dp = numpy.dot(LT,d) |
|
1563 | dp = numpy.dot(LT,d) | |
1564 |
|
1564 | |||
1565 | #Initial values |
|
1565 | #Initial values | |
1566 | data_spc = self.dataIn.data_spc[coord,:,h] |
|
1566 | data_spc = self.dataIn.data_spc[coord,:,h] | |
1567 |
|
1567 | |||
1568 | if (h>0)and(error1[3]<5): |
|
1568 | if (h>0)and(error1[3]<5): | |
1569 | p0 = self.dataOut.data_param[i,:,h-1] |
|
1569 | p0 = self.dataOut.data_param[i,:,h-1] | |
1570 | else: |
|
1570 | else: | |
1571 | p0 = numpy.array(self.dataOut.library.initialValuesFunction(data_spc, constants, i)) |
|
1571 | p0 = numpy.array(self.dataOut.library.initialValuesFunction(data_spc, constants, i)) | |
1572 |
|
1572 | |||
1573 | try: |
|
1573 | try: | |
1574 | #Least Squares |
|
1574 | #Least Squares | |
1575 | minp,covp,infodict,mesg,ier = optimize.leastsq(self.__residFunction,p0,args=(dp,LT,constants),full_output=True) |
|
1575 | minp,covp,infodict,mesg,ier = optimize.leastsq(self.__residFunction,p0,args=(dp,LT,constants),full_output=True) | |
1576 | # minp,covp = optimize.leastsq(self.__residFunction,p0,args=(dp,LT,constants)) |
|
1576 | # minp,covp = optimize.leastsq(self.__residFunction,p0,args=(dp,LT,constants)) | |
1577 | #Chi square error |
|
1577 | #Chi square error | |
1578 | error0 = numpy.sum(infodict['fvec']**2)/(2*N) |
|
1578 | error0 = numpy.sum(infodict['fvec']**2)/(2*N) | |
1579 | #Error with Jacobian |
|
1579 | #Error with Jacobian | |
1580 | error1 = self.dataOut.library.errorFunction(minp,constants,LT) |
|
1580 | error1 = self.dataOut.library.errorFunction(minp,constants,LT) | |
1581 | except: |
|
1581 | except: | |
1582 | minp = p0*numpy.nan |
|
1582 | minp = p0*numpy.nan | |
1583 | error0 = numpy.nan |
|
1583 | error0 = numpy.nan | |
1584 | error1 = p0*numpy.nan |
|
1584 | error1 = p0*numpy.nan | |
1585 |
|
1585 | |||
1586 | #Save |
|
1586 | #Save | |
1587 | if self.dataOut.data_param is None: |
|
1587 | if self.dataOut.data_param is None: | |
1588 | self.dataOut.data_param = numpy.zeros((nGroups, p0.size, nHeights))*numpy.nan |
|
1588 | self.dataOut.data_param = numpy.zeros((nGroups, p0.size, nHeights))*numpy.nan | |
1589 | self.dataOut.data_error = numpy.zeros((nGroups, p0.size + 1, nHeights))*numpy.nan |
|
1589 | self.dataOut.data_error = numpy.zeros((nGroups, p0.size + 1, nHeights))*numpy.nan | |
1590 |
|
1590 | |||
1591 | self.dataOut.data_error[i,:,h] = numpy.hstack((error0,error1)) |
|
1591 | self.dataOut.data_error[i,:,h] = numpy.hstack((error0,error1)) | |
1592 | self.dataOut.data_param[i,:,h] = minp |
|
1592 | self.dataOut.data_param[i,:,h] = minp | |
1593 | return |
|
1593 | return | |
1594 |
|
1594 | |||
1595 | def __residFunction(self, p, dp, LT, constants): |
|
1595 | def __residFunction(self, p, dp, LT, constants): | |
1596 |
|
1596 | |||
1597 | fm = self.dataOut.library.modelFunction(p, constants) |
|
1597 | fm = self.dataOut.library.modelFunction(p, constants) | |
1598 | fmp=numpy.dot(LT,fm) |
|
1598 | fmp=numpy.dot(LT,fm) | |
1599 |
|
1599 | |||
1600 | return dp-fmp |
|
1600 | return dp-fmp | |
1601 |
|
1601 | |||
1602 | def __getSNR(self, z, noise): |
|
1602 | def __getSNR(self, z, noise): | |
1603 |
|
1603 | |||
1604 | avg = numpy.average(z, axis=1) |
|
1604 | avg = numpy.average(z, axis=1) | |
1605 | SNR = (avg.T-noise)/noise |
|
1605 | SNR = (avg.T-noise)/noise | |
1606 | SNR = SNR.T |
|
1606 | SNR = SNR.T | |
1607 | return SNR |
|
1607 | return SNR | |
1608 |
|
1608 | |||
1609 | def __chisq(p,chindex,hindex): |
|
1609 | def __chisq(p,chindex,hindex): | |
1610 | #similar to Resid but calculates CHI**2 |
|
1610 | #similar to Resid but calculates CHI**2 | |
1611 | [LT,d,fm]=setupLTdfm(p,chindex,hindex) |
|
1611 | [LT,d,fm]=setupLTdfm(p,chindex,hindex) | |
1612 | dp=numpy.dot(LT,d) |
|
1612 | dp=numpy.dot(LT,d) | |
1613 | fmp=numpy.dot(LT,fm) |
|
1613 | fmp=numpy.dot(LT,fm) | |
1614 | chisq=numpy.dot((dp-fmp).T,(dp-fmp)) |
|
1614 | chisq=numpy.dot((dp-fmp).T,(dp-fmp)) | |
1615 | return chisq |
|
1615 | return chisq | |
1616 |
|
1616 | |||
1617 | class WindProfiler(Operation): |
|
1617 | class WindProfiler(Operation): | |
1618 |
|
1618 | |||
1619 | __isConfig = False |
|
1619 | __isConfig = False | |
1620 |
|
1620 | |||
1621 | __initime = None |
|
1621 | __initime = None | |
1622 | __lastdatatime = None |
|
1622 | __lastdatatime = None | |
1623 | __integrationtime = None |
|
1623 | __integrationtime = None | |
1624 |
|
1624 | |||
1625 | __buffer = None |
|
1625 | __buffer = None | |
1626 |
|
1626 | |||
1627 | __dataReady = False |
|
1627 | __dataReady = False | |
1628 |
|
1628 | |||
1629 | __firstdata = None |
|
1629 | __firstdata = None | |
1630 |
|
1630 | |||
1631 | n = None |
|
1631 | n = None | |
1632 |
|
1632 | |||
1633 | def __init__(self): |
|
1633 | def __init__(self): | |
1634 | Operation.__init__(self) |
|
1634 | Operation.__init__(self) | |
1635 |
|
1635 | |||
1636 | def __calculateCosDir(self, elev, azim): |
|
1636 | def __calculateCosDir(self, elev, azim): | |
1637 | zen = (90 - elev)*numpy.pi/180 |
|
1637 | zen = (90 - elev)*numpy.pi/180 | |
1638 | azim = azim*numpy.pi/180 |
|
1638 | azim = azim*numpy.pi/180 | |
1639 | cosDirX = numpy.sqrt((1-numpy.cos(zen)**2)/((1+numpy.tan(azim)**2))) |
|
1639 | cosDirX = numpy.sqrt((1-numpy.cos(zen)**2)/((1+numpy.tan(azim)**2))) | |
1640 | cosDirY = numpy.sqrt(1-numpy.cos(zen)**2-cosDirX**2) |
|
1640 | cosDirY = numpy.sqrt(1-numpy.cos(zen)**2-cosDirX**2) | |
1641 |
|
1641 | |||
1642 | signX = numpy.sign(numpy.cos(azim)) |
|
1642 | signX = numpy.sign(numpy.cos(azim)) | |
1643 | signY = numpy.sign(numpy.sin(azim)) |
|
1643 | signY = numpy.sign(numpy.sin(azim)) | |
1644 |
|
1644 | |||
1645 | cosDirX = numpy.copysign(cosDirX, signX) |
|
1645 | cosDirX = numpy.copysign(cosDirX, signX) | |
1646 | cosDirY = numpy.copysign(cosDirY, signY) |
|
1646 | cosDirY = numpy.copysign(cosDirY, signY) | |
1647 | return cosDirX, cosDirY |
|
1647 | return cosDirX, cosDirY | |
1648 |
|
1648 | |||
1649 | def __calculateAngles(self, theta_x, theta_y, azimuth): |
|
1649 | def __calculateAngles(self, theta_x, theta_y, azimuth): | |
1650 |
|
1650 | |||
1651 | dir_cosw = numpy.sqrt(1-theta_x**2-theta_y**2) |
|
1651 | dir_cosw = numpy.sqrt(1-theta_x**2-theta_y**2) | |
1652 | zenith_arr = numpy.arccos(dir_cosw) |
|
1652 | zenith_arr = numpy.arccos(dir_cosw) | |
1653 | azimuth_arr = numpy.arctan2(theta_x,theta_y) + azimuth*math.pi/180 |
|
1653 | azimuth_arr = numpy.arctan2(theta_x,theta_y) + azimuth*math.pi/180 | |
1654 |
|
1654 | |||
1655 | dir_cosu = numpy.sin(azimuth_arr)*numpy.sin(zenith_arr) |
|
1655 | dir_cosu = numpy.sin(azimuth_arr)*numpy.sin(zenith_arr) | |
1656 | dir_cosv = numpy.cos(azimuth_arr)*numpy.sin(zenith_arr) |
|
1656 | dir_cosv = numpy.cos(azimuth_arr)*numpy.sin(zenith_arr) | |
1657 |
|
1657 | |||
1658 | return azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw |
|
1658 | return azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw | |
1659 |
|
1659 | |||
1660 | def __calculateMatA(self, dir_cosu, dir_cosv, dir_cosw, horOnly): |
|
1660 | def __calculateMatA(self, dir_cosu, dir_cosv, dir_cosw, horOnly): | |
1661 |
|
1661 | |||
1662 | # |
|
1662 | # | |
1663 | if horOnly: |
|
1663 | if horOnly: | |
1664 | A = numpy.c_[dir_cosu,dir_cosv] |
|
1664 | A = numpy.c_[dir_cosu,dir_cosv] | |
1665 | else: |
|
1665 | else: | |
1666 | A = numpy.c_[dir_cosu,dir_cosv,dir_cosw] |
|
1666 | A = numpy.c_[dir_cosu,dir_cosv,dir_cosw] | |
1667 | A = numpy.asmatrix(A) |
|
1667 | A = numpy.asmatrix(A) | |
1668 | A1 = numpy.linalg.inv(A.transpose()*A)*A.transpose() |
|
1668 | A1 = numpy.linalg.inv(A.transpose()*A)*A.transpose() | |
1669 |
|
1669 | |||
1670 | return A1 |
|
1670 | return A1 | |
1671 |
|
1671 | |||
1672 | def __correctValues(self, heiRang, phi, velRadial, SNR): |
|
1672 | def __correctValues(self, heiRang, phi, velRadial, SNR): | |
1673 | listPhi = phi.tolist() |
|
1673 | listPhi = phi.tolist() | |
1674 | maxid = listPhi.index(max(listPhi)) |
|
1674 | maxid = listPhi.index(max(listPhi)) | |
1675 | minid = listPhi.index(min(listPhi)) |
|
1675 | minid = listPhi.index(min(listPhi)) | |
1676 |
|
1676 | |||
1677 | rango = list(range(len(phi))) |
|
1677 | rango = list(range(len(phi))) | |
1678 | # rango = numpy.delete(rango,maxid) |
|
1678 | # rango = numpy.delete(rango,maxid) | |
1679 |
|
1679 | |||
1680 | heiRang1 = heiRang*math.cos(phi[maxid]) |
|
1680 | heiRang1 = heiRang*math.cos(phi[maxid]) | |
1681 | heiRangAux = heiRang*math.cos(phi[minid]) |
|
1681 | heiRangAux = heiRang*math.cos(phi[minid]) | |
1682 | indOut = (heiRang1 < heiRangAux[0]).nonzero() |
|
1682 | indOut = (heiRang1 < heiRangAux[0]).nonzero() | |
1683 | heiRang1 = numpy.delete(heiRang1,indOut) |
|
1683 | heiRang1 = numpy.delete(heiRang1,indOut) | |
1684 |
|
1684 | |||
1685 | velRadial1 = numpy.zeros([len(phi),len(heiRang1)]) |
|
1685 | velRadial1 = numpy.zeros([len(phi),len(heiRang1)]) | |
1686 | SNR1 = numpy.zeros([len(phi),len(heiRang1)]) |
|
1686 | SNR1 = numpy.zeros([len(phi),len(heiRang1)]) | |
1687 |
|
1687 | |||
1688 | for i in rango: |
|
1688 | for i in rango: | |
1689 | x = heiRang*math.cos(phi[i]) |
|
1689 | x = heiRang*math.cos(phi[i]) | |
1690 | y1 = velRadial[i,:] |
|
1690 | y1 = velRadial[i,:] | |
1691 | f1 = interpolate.interp1d(x,y1,kind = 'cubic') |
|
1691 | f1 = interpolate.interp1d(x,y1,kind = 'cubic') | |
1692 |
|
1692 | |||
1693 | x1 = heiRang1 |
|
1693 | x1 = heiRang1 | |
1694 | y11 = f1(x1) |
|
1694 | y11 = f1(x1) | |
1695 |
|
1695 | |||
1696 | y2 = SNR[i,:] |
|
1696 | y2 = SNR[i,:] | |
1697 | f2 = interpolate.interp1d(x,y2,kind = 'cubic') |
|
1697 | f2 = interpolate.interp1d(x,y2,kind = 'cubic') | |
1698 | y21 = f2(x1) |
|
1698 | y21 = f2(x1) | |
1699 |
|
1699 | |||
1700 | velRadial1[i,:] = y11 |
|
1700 | velRadial1[i,:] = y11 | |
1701 | SNR1[i,:] = y21 |
|
1701 | SNR1[i,:] = y21 | |
1702 |
|
1702 | |||
1703 | return heiRang1, velRadial1, SNR1 |
|
1703 | return heiRang1, velRadial1, SNR1 | |
1704 |
|
1704 | |||
1705 | def __calculateVelUVW(self, A, velRadial): |
|
1705 | def __calculateVelUVW(self, A, velRadial): | |
1706 |
|
1706 | |||
1707 | #Operacion Matricial |
|
1707 | #Operacion Matricial | |
1708 | # velUVW = numpy.zeros((velRadial.shape[1],3)) |
|
1708 | # velUVW = numpy.zeros((velRadial.shape[1],3)) | |
1709 | # for ind in range(velRadial.shape[1]): |
|
1709 | # for ind in range(velRadial.shape[1]): | |
1710 | # velUVW[ind,:] = numpy.dot(A,velRadial[:,ind]) |
|
1710 | # velUVW[ind,:] = numpy.dot(A,velRadial[:,ind]) | |
1711 | # velUVW = velUVW.transpose() |
|
1711 | # velUVW = velUVW.transpose() | |
1712 | velUVW = numpy.zeros((A.shape[0],velRadial.shape[1])) |
|
1712 | velUVW = numpy.zeros((A.shape[0],velRadial.shape[1])) | |
1713 | velUVW[:,:] = numpy.dot(A,velRadial) |
|
1713 | velUVW[:,:] = numpy.dot(A,velRadial) | |
1714 |
|
1714 | |||
1715 |
|
1715 | |||
1716 | return velUVW |
|
1716 | return velUVW | |
1717 |
|
1717 | |||
1718 | # def techniqueDBS(self, velRadial0, dirCosx, disrCosy, azimuth, correct, horizontalOnly, heiRang, SNR0): |
|
1718 | # def techniqueDBS(self, velRadial0, dirCosx, disrCosy, azimuth, correct, horizontalOnly, heiRang, SNR0): | |
1719 |
|
1719 | |||
1720 | def techniqueDBS(self, kwargs): |
|
1720 | def techniqueDBS(self, kwargs): | |
1721 | """ |
|
1721 | """ | |
1722 | Function that implements Doppler Beam Swinging (DBS) technique. |
|
1722 | Function that implements Doppler Beam Swinging (DBS) technique. | |
1723 |
|
1723 | |||
1724 | Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth, |
|
1724 | Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth, | |
1725 | Direction correction (if necessary), Ranges and SNR |
|
1725 | Direction correction (if necessary), Ranges and SNR | |
1726 |
|
1726 | |||
1727 | Output: Winds estimation (Zonal, Meridional and Vertical) |
|
1727 | Output: Winds estimation (Zonal, Meridional and Vertical) | |
1728 |
|
1728 | |||
1729 | Parameters affected: Winds, height range, SNR |
|
1729 | Parameters affected: Winds, height range, SNR | |
1730 | """ |
|
1730 | """ | |
1731 | velRadial0 = kwargs['velRadial'] |
|
1731 | velRadial0 = kwargs['velRadial'] | |
1732 | heiRang = kwargs['heightList'] |
|
1732 | heiRang = kwargs['heightList'] | |
1733 | SNR0 = kwargs['SNR'] |
|
1733 | SNR0 = kwargs['SNR'] | |
1734 |
|
1734 | |||
1735 | if 'dirCosx' in kwargs and 'dirCosy' in kwargs: |
|
1735 | if 'dirCosx' in kwargs and 'dirCosy' in kwargs: | |
1736 | theta_x = numpy.array(kwargs['dirCosx']) |
|
1736 | theta_x = numpy.array(kwargs['dirCosx']) | |
1737 | theta_y = numpy.array(kwargs['dirCosy']) |
|
1737 | theta_y = numpy.array(kwargs['dirCosy']) | |
1738 | else: |
|
1738 | else: | |
1739 | elev = numpy.array(kwargs['elevation']) |
|
1739 | elev = numpy.array(kwargs['elevation']) | |
1740 | azim = numpy.array(kwargs['azimuth']) |
|
1740 | azim = numpy.array(kwargs['azimuth']) | |
1741 | theta_x, theta_y = self.__calculateCosDir(elev, azim) |
|
1741 | theta_x, theta_y = self.__calculateCosDir(elev, azim) | |
1742 | azimuth = kwargs['correctAzimuth'] |
|
1742 | azimuth = kwargs['correctAzimuth'] | |
1743 | if 'horizontalOnly' in kwargs: |
|
1743 | if 'horizontalOnly' in kwargs: | |
1744 | horizontalOnly = kwargs['horizontalOnly'] |
|
1744 | horizontalOnly = kwargs['horizontalOnly'] | |
1745 | else: horizontalOnly = False |
|
1745 | else: horizontalOnly = False | |
1746 | if 'correctFactor' in kwargs: |
|
1746 | if 'correctFactor' in kwargs: | |
1747 | correctFactor = kwargs['correctFactor'] |
|
1747 | correctFactor = kwargs['correctFactor'] | |
1748 | else: correctFactor = 1 |
|
1748 | else: correctFactor = 1 | |
1749 | if 'channelList' in kwargs: |
|
1749 | if 'channelList' in kwargs: | |
1750 | channelList = kwargs['channelList'] |
|
1750 | channelList = kwargs['channelList'] | |
1751 | if len(channelList) == 2: |
|
1751 | if len(channelList) == 2: | |
1752 | horizontalOnly = True |
|
1752 | horizontalOnly = True | |
1753 | arrayChannel = numpy.array(channelList) |
|
1753 | arrayChannel = numpy.array(channelList) | |
1754 | param = param[arrayChannel,:,:] |
|
1754 | param = param[arrayChannel,:,:] | |
1755 | theta_x = theta_x[arrayChannel] |
|
1755 | theta_x = theta_x[arrayChannel] | |
1756 | theta_y = theta_y[arrayChannel] |
|
1756 | theta_y = theta_y[arrayChannel] | |
1757 |
|
1757 | |||
1758 | azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw = self.__calculateAngles(theta_x, theta_y, azimuth) |
|
1758 | azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw = self.__calculateAngles(theta_x, theta_y, azimuth) | |
1759 | heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, zenith_arr, correctFactor*velRadial0, SNR0) |
|
1759 | heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, zenith_arr, correctFactor*velRadial0, SNR0) | |
1760 | A = self.__calculateMatA(dir_cosu, dir_cosv, dir_cosw, horizontalOnly) |
|
1760 | A = self.__calculateMatA(dir_cosu, dir_cosv, dir_cosw, horizontalOnly) | |
1761 |
|
1761 | |||
1762 | #Calculo de Componentes de la velocidad con DBS |
|
1762 | #Calculo de Componentes de la velocidad con DBS | |
1763 | winds = self.__calculateVelUVW(A,velRadial1) |
|
1763 | winds = self.__calculateVelUVW(A,velRadial1) | |
1764 |
|
1764 | |||
1765 | return winds, heiRang1, SNR1 |
|
1765 | return winds, heiRang1, SNR1 | |
1766 |
|
1766 | |||
1767 | def __calculateDistance(self, posx, posy, pairs_ccf, azimuth = None): |
|
1767 | def __calculateDistance(self, posx, posy, pairs_ccf, azimuth = None): | |
1768 |
|
1768 | |||
1769 | nPairs = len(pairs_ccf) |
|
1769 | nPairs = len(pairs_ccf) | |
1770 | posx = numpy.asarray(posx) |
|
1770 | posx = numpy.asarray(posx) | |
1771 | posy = numpy.asarray(posy) |
|
1771 | posy = numpy.asarray(posy) | |
1772 |
|
1772 | |||
1773 | #Rotacion Inversa para alinear con el azimuth |
|
1773 | #Rotacion Inversa para alinear con el azimuth | |
1774 | if azimuth!= None: |
|
1774 | if azimuth!= None: | |
1775 | azimuth = azimuth*math.pi/180 |
|
1775 | azimuth = azimuth*math.pi/180 | |
1776 | posx1 = posx*math.cos(azimuth) + posy*math.sin(azimuth) |
|
1776 | posx1 = posx*math.cos(azimuth) + posy*math.sin(azimuth) | |
1777 | posy1 = -posx*math.sin(azimuth) + posy*math.cos(azimuth) |
|
1777 | posy1 = -posx*math.sin(azimuth) + posy*math.cos(azimuth) | |
1778 | else: |
|
1778 | else: | |
1779 | posx1 = posx |
|
1779 | posx1 = posx | |
1780 | posy1 = posy |
|
1780 | posy1 = posy | |
1781 |
|
1781 | |||
1782 | #Calculo de Distancias |
|
1782 | #Calculo de Distancias | |
1783 | distx = numpy.zeros(nPairs) |
|
1783 | distx = numpy.zeros(nPairs) | |
1784 | disty = numpy.zeros(nPairs) |
|
1784 | disty = numpy.zeros(nPairs) | |
1785 | dist = numpy.zeros(nPairs) |
|
1785 | dist = numpy.zeros(nPairs) | |
1786 | ang = numpy.zeros(nPairs) |
|
1786 | ang = numpy.zeros(nPairs) | |
1787 |
|
1787 | |||
1788 | for i in range(nPairs): |
|
1788 | for i in range(nPairs): | |
1789 | distx[i] = posx1[pairs_ccf[i][1]] - posx1[pairs_ccf[i][0]] |
|
1789 | distx[i] = posx1[pairs_ccf[i][1]] - posx1[pairs_ccf[i][0]] | |
1790 | disty[i] = posy1[pairs_ccf[i][1]] - posy1[pairs_ccf[i][0]] |
|
1790 | disty[i] = posy1[pairs_ccf[i][1]] - posy1[pairs_ccf[i][0]] | |
1791 | dist[i] = numpy.sqrt(distx[i]**2 + disty[i]**2) |
|
1791 | dist[i] = numpy.sqrt(distx[i]**2 + disty[i]**2) | |
1792 | ang[i] = numpy.arctan2(disty[i],distx[i]) |
|
1792 | ang[i] = numpy.arctan2(disty[i],distx[i]) | |
1793 |
|
1793 | |||
1794 | return distx, disty, dist, ang |
|
1794 | return distx, disty, dist, ang | |
1795 | #Calculo de Matrices |
|
1795 | #Calculo de Matrices | |
1796 | # nPairs = len(pairs) |
|
1796 | # nPairs = len(pairs) | |
1797 | # ang1 = numpy.zeros((nPairs, 2, 1)) |
|
1797 | # ang1 = numpy.zeros((nPairs, 2, 1)) | |
1798 | # dist1 = numpy.zeros((nPairs, 2, 1)) |
|
1798 | # dist1 = numpy.zeros((nPairs, 2, 1)) | |
1799 | # |
|
1799 | # | |
1800 | # for j in range(nPairs): |
|
1800 | # for j in range(nPairs): | |
1801 | # dist1[j,0,0] = dist[pairs[j][0]] |
|
1801 | # dist1[j,0,0] = dist[pairs[j][0]] | |
1802 | # dist1[j,1,0] = dist[pairs[j][1]] |
|
1802 | # dist1[j,1,0] = dist[pairs[j][1]] | |
1803 | # ang1[j,0,0] = ang[pairs[j][0]] |
|
1803 | # ang1[j,0,0] = ang[pairs[j][0]] | |
1804 | # ang1[j,1,0] = ang[pairs[j][1]] |
|
1804 | # ang1[j,1,0] = ang[pairs[j][1]] | |
1805 | # |
|
1805 | # | |
1806 | # return distx,disty, dist1,ang1 |
|
1806 | # return distx,disty, dist1,ang1 | |
1807 |
|
1807 | |||
1808 |
|
1808 | |||
1809 | def __calculateVelVer(self, phase, lagTRange, _lambda): |
|
1809 | def __calculateVelVer(self, phase, lagTRange, _lambda): | |
1810 |
|
1810 | |||
1811 | Ts = lagTRange[1] - lagTRange[0] |
|
1811 | Ts = lagTRange[1] - lagTRange[0] | |
1812 | velW = -_lambda*phase/(4*math.pi*Ts) |
|
1812 | velW = -_lambda*phase/(4*math.pi*Ts) | |
1813 |
|
1813 | |||
1814 | return velW |
|
1814 | return velW | |
1815 |
|
1815 | |||
1816 | def __calculateVelHorDir(self, dist, tau1, tau2, ang): |
|
1816 | def __calculateVelHorDir(self, dist, tau1, tau2, ang): | |
1817 | nPairs = tau1.shape[0] |
|
1817 | nPairs = tau1.shape[0] | |
1818 | nHeights = tau1.shape[1] |
|
1818 | nHeights = tau1.shape[1] | |
1819 | vel = numpy.zeros((nPairs,3,nHeights)) |
|
1819 | vel = numpy.zeros((nPairs,3,nHeights)) | |
1820 | dist1 = numpy.reshape(dist, (dist.size,1)) |
|
1820 | dist1 = numpy.reshape(dist, (dist.size,1)) | |
1821 |
|
1821 | |||
1822 | angCos = numpy.cos(ang) |
|
1822 | angCos = numpy.cos(ang) | |
1823 | angSin = numpy.sin(ang) |
|
1823 | angSin = numpy.sin(ang) | |
1824 |
|
1824 | |||
1825 | vel0 = dist1*tau1/(2*tau2**2) |
|
1825 | vel0 = dist1*tau1/(2*tau2**2) | |
1826 | vel[:,0,:] = (vel0*angCos).sum(axis = 1) |
|
1826 | vel[:,0,:] = (vel0*angCos).sum(axis = 1) | |
1827 | vel[:,1,:] = (vel0*angSin).sum(axis = 1) |
|
1827 | vel[:,1,:] = (vel0*angSin).sum(axis = 1) | |
1828 |
|
1828 | |||
1829 | ind = numpy.where(numpy.isinf(vel)) |
|
1829 | ind = numpy.where(numpy.isinf(vel)) | |
1830 | vel[ind] = numpy.nan |
|
1830 | vel[ind] = numpy.nan | |
1831 |
|
1831 | |||
1832 | return vel |
|
1832 | return vel | |
1833 |
|
1833 | |||
1834 | # def __getPairsAutoCorr(self, pairsList, nChannels): |
|
1834 | # def __getPairsAutoCorr(self, pairsList, nChannels): | |
1835 | # |
|
1835 | # | |
1836 | # pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan |
|
1836 | # pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan | |
1837 | # |
|
1837 | # | |
1838 | # for l in range(len(pairsList)): |
|
1838 | # for l in range(len(pairsList)): | |
1839 | # firstChannel = pairsList[l][0] |
|
1839 | # firstChannel = pairsList[l][0] | |
1840 | # secondChannel = pairsList[l][1] |
|
1840 | # secondChannel = pairsList[l][1] | |
1841 | # |
|
1841 | # | |
1842 | # #Obteniendo pares de Autocorrelacion |
|
1842 | # #Obteniendo pares de Autocorrelacion | |
1843 | # if firstChannel == secondChannel: |
|
1843 | # if firstChannel == secondChannel: | |
1844 | # pairsAutoCorr[firstChannel] = int(l) |
|
1844 | # pairsAutoCorr[firstChannel] = int(l) | |
1845 | # |
|
1845 | # | |
1846 | # pairsAutoCorr = pairsAutoCorr.astype(int) |
|
1846 | # pairsAutoCorr = pairsAutoCorr.astype(int) | |
1847 | # |
|
1847 | # | |
1848 | # pairsCrossCorr = range(len(pairsList)) |
|
1848 | # pairsCrossCorr = range(len(pairsList)) | |
1849 | # pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr) |
|
1849 | # pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr) | |
1850 | # |
|
1850 | # | |
1851 | # return pairsAutoCorr, pairsCrossCorr |
|
1851 | # return pairsAutoCorr, pairsCrossCorr | |
1852 |
|
1852 | |||
1853 | # def techniqueSA(self, pairsSelected, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, lagTRange, correctFactor): |
|
1853 | # def techniqueSA(self, pairsSelected, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, lagTRange, correctFactor): | |
1854 | def techniqueSA(self, kwargs): |
|
1854 | def techniqueSA(self, kwargs): | |
1855 |
|
1855 | |||
1856 | """ |
|
1856 | """ | |
1857 | Function that implements Spaced Antenna (SA) technique. |
|
1857 | Function that implements Spaced Antenna (SA) technique. | |
1858 |
|
1858 | |||
1859 | Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth, |
|
1859 | Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth, | |
1860 | Direction correction (if necessary), Ranges and SNR |
|
1860 | Direction correction (if necessary), Ranges and SNR | |
1861 |
|
1861 | |||
1862 | Output: Winds estimation (Zonal, Meridional and Vertical) |
|
1862 | Output: Winds estimation (Zonal, Meridional and Vertical) | |
1863 |
|
1863 | |||
1864 | Parameters affected: Winds |
|
1864 | Parameters affected: Winds | |
1865 | """ |
|
1865 | """ | |
1866 | position_x = kwargs['positionX'] |
|
1866 | position_x = kwargs['positionX'] | |
1867 | position_y = kwargs['positionY'] |
|
1867 | position_y = kwargs['positionY'] | |
1868 | azimuth = kwargs['azimuth'] |
|
1868 | azimuth = kwargs['azimuth'] | |
1869 |
|
1869 | |||
1870 | if 'correctFactor' in kwargs: |
|
1870 | if 'correctFactor' in kwargs: | |
1871 | correctFactor = kwargs['correctFactor'] |
|
1871 | correctFactor = kwargs['correctFactor'] | |
1872 | else: |
|
1872 | else: | |
1873 | correctFactor = 1 |
|
1873 | correctFactor = 1 | |
1874 |
|
1874 | |||
1875 | groupList = kwargs['groupList'] |
|
1875 | groupList = kwargs['groupList'] | |
1876 | pairs_ccf = groupList[1] |
|
1876 | pairs_ccf = groupList[1] | |
1877 | tau = kwargs['tau'] |
|
1877 | tau = kwargs['tau'] | |
1878 | _lambda = kwargs['_lambda'] |
|
1878 | _lambda = kwargs['_lambda'] | |
1879 |
|
1879 | |||
1880 | #Cross Correlation pairs obtained |
|
1880 | #Cross Correlation pairs obtained | |
1881 | # pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairssList, nChannels) |
|
1881 | # pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairssList, nChannels) | |
1882 | # pairsArray = numpy.array(pairsList)[pairsCrossCorr] |
|
1882 | # pairsArray = numpy.array(pairsList)[pairsCrossCorr] | |
1883 | # pairsSelArray = numpy.array(pairsSelected) |
|
1883 | # pairsSelArray = numpy.array(pairsSelected) | |
1884 | # pairs = [] |
|
1884 | # pairs = [] | |
1885 | # |
|
1885 | # | |
1886 | # #Wind estimation pairs obtained |
|
1886 | # #Wind estimation pairs obtained | |
1887 | # for i in range(pairsSelArray.shape[0]/2): |
|
1887 | # for i in range(pairsSelArray.shape[0]/2): | |
1888 | # ind1 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i], axis = 1))[0][0] |
|
1888 | # ind1 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i], axis = 1))[0][0] | |
1889 | # ind2 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i + 1], axis = 1))[0][0] |
|
1889 | # ind2 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i + 1], axis = 1))[0][0] | |
1890 | # pairs.append((ind1,ind2)) |
|
1890 | # pairs.append((ind1,ind2)) | |
1891 |
|
1891 | |||
1892 | indtau = tau.shape[0]/2 |
|
1892 | indtau = tau.shape[0]/2 | |
1893 | tau1 = tau[:indtau,:] |
|
1893 | tau1 = tau[:indtau,:] | |
1894 | tau2 = tau[indtau:-1,:] |
|
1894 | tau2 = tau[indtau:-1,:] | |
1895 | # tau1 = tau1[pairs,:] |
|
1895 | # tau1 = tau1[pairs,:] | |
1896 | # tau2 = tau2[pairs,:] |
|
1896 | # tau2 = tau2[pairs,:] | |
1897 | phase1 = tau[-1,:] |
|
1897 | phase1 = tau[-1,:] | |
1898 |
|
1898 | |||
1899 | #--------------------------------------------------------------------- |
|
1899 | #--------------------------------------------------------------------- | |
1900 | #Metodo Directo |
|
1900 | #Metodo Directo | |
1901 | distx, disty, dist, ang = self.__calculateDistance(position_x, position_y, pairs_ccf,azimuth) |
|
1901 | distx, disty, dist, ang = self.__calculateDistance(position_x, position_y, pairs_ccf,azimuth) | |
1902 | winds = self.__calculateVelHorDir(dist, tau1, tau2, ang) |
|
1902 | winds = self.__calculateVelHorDir(dist, tau1, tau2, ang) | |
1903 | winds = stats.nanmean(winds, axis=0) |
|
1903 | winds = stats.nanmean(winds, axis=0) | |
1904 | #--------------------------------------------------------------------- |
|
1904 | #--------------------------------------------------------------------- | |
1905 | #Metodo General |
|
1905 | #Metodo General | |
1906 | # distx, disty, dist = self.calculateDistance(position_x,position_y,pairsCrossCorr, pairsList, azimuth) |
|
1906 | # distx, disty, dist = self.calculateDistance(position_x,position_y,pairsCrossCorr, pairsList, azimuth) | |
1907 | # #Calculo Coeficientes de Funcion de Correlacion |
|
1907 | # #Calculo Coeficientes de Funcion de Correlacion | |
1908 | # F,G,A,B,H = self.calculateCoef(tau1,tau2,distx,disty,n) |
|
1908 | # F,G,A,B,H = self.calculateCoef(tau1,tau2,distx,disty,n) | |
1909 | # #Calculo de Velocidades |
|
1909 | # #Calculo de Velocidades | |
1910 | # winds = self.calculateVelUV(F,G,A,B,H) |
|
1910 | # winds = self.calculateVelUV(F,G,A,B,H) | |
1911 |
|
1911 | |||
1912 | #--------------------------------------------------------------------- |
|
1912 | #--------------------------------------------------------------------- | |
1913 | winds[2,:] = self.__calculateVelVer(phase1, lagTRange, _lambda) |
|
1913 | winds[2,:] = self.__calculateVelVer(phase1, lagTRange, _lambda) | |
1914 | winds = correctFactor*winds |
|
1914 | winds = correctFactor*winds | |
1915 | return winds |
|
1915 | return winds | |
1916 |
|
1916 | |||
1917 | def __checkTime(self, currentTime, paramInterval, outputInterval): |
|
1917 | def __checkTime(self, currentTime, paramInterval, outputInterval): | |
1918 |
|
1918 | |||
1919 | dataTime = currentTime + paramInterval |
|
1919 | dataTime = currentTime + paramInterval | |
1920 | deltaTime = dataTime - self.__initime |
|
1920 | deltaTime = dataTime - self.__initime | |
1921 |
|
1921 | |||
1922 | if deltaTime >= outputInterval or deltaTime < 0: |
|
1922 | if deltaTime >= outputInterval or deltaTime < 0: | |
1923 | self.__dataReady = True |
|
1923 | self.__dataReady = True | |
1924 | return |
|
1924 | return | |
1925 |
|
1925 | |||
1926 | def techniqueMeteors(self, arrayMeteor, meteorThresh, heightMin, heightMax): |
|
1926 | def techniqueMeteors(self, arrayMeteor, meteorThresh, heightMin, heightMax): | |
1927 | ''' |
|
1927 | ''' | |
1928 | Function that implements winds estimation technique with detected meteors. |
|
1928 | Function that implements winds estimation technique with detected meteors. | |
1929 |
|
1929 | |||
1930 | Input: Detected meteors, Minimum meteor quantity to wind estimation |
|
1930 | Input: Detected meteors, Minimum meteor quantity to wind estimation | |
1931 |
|
1931 | |||
1932 | Output: Winds estimation (Zonal and Meridional) |
|
1932 | Output: Winds estimation (Zonal and Meridional) | |
1933 |
|
1933 | |||
1934 | Parameters affected: Winds |
|
1934 | Parameters affected: Winds | |
1935 | ''' |
|
1935 | ''' | |
1936 | #Settings |
|
1936 | #Settings | |
1937 | nInt = (heightMax - heightMin)/2 |
|
1937 | nInt = (heightMax - heightMin)/2 | |
1938 | nInt = int(nInt) |
|
1938 | nInt = int(nInt) | |
1939 | winds = numpy.zeros((2,nInt))*numpy.nan |
|
1939 | winds = numpy.zeros((2,nInt))*numpy.nan | |
1940 |
|
1940 | |||
1941 | #Filter errors |
|
1941 | #Filter errors | |
1942 | error = numpy.where(arrayMeteor[:,-1] == 0)[0] |
|
1942 | error = numpy.where(arrayMeteor[:,-1] == 0)[0] | |
1943 | finalMeteor = arrayMeteor[error,:] |
|
1943 | finalMeteor = arrayMeteor[error,:] | |
1944 |
|
1944 | |||
1945 | #Meteor Histogram |
|
1945 | #Meteor Histogram | |
1946 | finalHeights = finalMeteor[:,2] |
|
1946 | finalHeights = finalMeteor[:,2] | |
1947 | hist = numpy.histogram(finalHeights, bins = nInt, range = (heightMin,heightMax)) |
|
1947 | hist = numpy.histogram(finalHeights, bins = nInt, range = (heightMin,heightMax)) | |
1948 | nMeteorsPerI = hist[0] |
|
1948 | nMeteorsPerI = hist[0] | |
1949 | heightPerI = hist[1] |
|
1949 | heightPerI = hist[1] | |
1950 |
|
1950 | |||
1951 | #Sort of meteors |
|
1951 | #Sort of meteors | |
1952 | indSort = finalHeights.argsort() |
|
1952 | indSort = finalHeights.argsort() | |
1953 | finalMeteor2 = finalMeteor[indSort,:] |
|
1953 | finalMeteor2 = finalMeteor[indSort,:] | |
1954 |
|
1954 | |||
1955 | # Calculating winds |
|
1955 | # Calculating winds | |
1956 | ind1 = 0 |
|
1956 | ind1 = 0 | |
1957 | ind2 = 0 |
|
1957 | ind2 = 0 | |
1958 |
|
1958 | |||
1959 | for i in range(nInt): |
|
1959 | for i in range(nInt): | |
1960 | nMet = nMeteorsPerI[i] |
|
1960 | nMet = nMeteorsPerI[i] | |
1961 | ind1 = ind2 |
|
1961 | ind1 = ind2 | |
1962 | ind2 = ind1 + nMet |
|
1962 | ind2 = ind1 + nMet | |
1963 |
|
1963 | |||
1964 | meteorAux = finalMeteor2[ind1:ind2,:] |
|
1964 | meteorAux = finalMeteor2[ind1:ind2,:] | |
1965 |
|
1965 | |||
1966 | if meteorAux.shape[0] >= meteorThresh: |
|
1966 | if meteorAux.shape[0] >= meteorThresh: | |
1967 | vel = meteorAux[:, 6] |
|
1967 | vel = meteorAux[:, 6] | |
1968 | zen = meteorAux[:, 4]*numpy.pi/180 |
|
1968 | zen = meteorAux[:, 4]*numpy.pi/180 | |
1969 | azim = meteorAux[:, 3]*numpy.pi/180 |
|
1969 | azim = meteorAux[:, 3]*numpy.pi/180 | |
1970 |
|
1970 | |||
1971 | n = numpy.cos(zen) |
|
1971 | n = numpy.cos(zen) | |
1972 | # m = (1 - n**2)/(1 - numpy.tan(azim)**2) |
|
1972 | # m = (1 - n**2)/(1 - numpy.tan(azim)**2) | |
1973 | # l = m*numpy.tan(azim) |
|
1973 | # l = m*numpy.tan(azim) | |
1974 | l = numpy.sin(zen)*numpy.sin(azim) |
|
1974 | l = numpy.sin(zen)*numpy.sin(azim) | |
1975 | m = numpy.sin(zen)*numpy.cos(azim) |
|
1975 | m = numpy.sin(zen)*numpy.cos(azim) | |
1976 |
|
1976 | |||
1977 | A = numpy.vstack((l, m)).transpose() |
|
1977 | A = numpy.vstack((l, m)).transpose() | |
1978 | A1 = numpy.dot(numpy.linalg.inv( numpy.dot(A.transpose(),A) ),A.transpose()) |
|
1978 | A1 = numpy.dot(numpy.linalg.inv( numpy.dot(A.transpose(),A) ),A.transpose()) | |
1979 | windsAux = numpy.dot(A1, vel) |
|
1979 | windsAux = numpy.dot(A1, vel) | |
1980 |
|
1980 | |||
1981 | winds[0,i] = windsAux[0] |
|
1981 | winds[0,i] = windsAux[0] | |
1982 | winds[1,i] = windsAux[1] |
|
1982 | winds[1,i] = windsAux[1] | |
1983 |
|
1983 | |||
1984 | return winds, heightPerI[:-1] |
|
1984 | return winds, heightPerI[:-1] | |
1985 |
|
1985 | |||
1986 | def techniqueNSM_SA(self, **kwargs): |
|
1986 | def techniqueNSM_SA(self, **kwargs): | |
1987 | metArray = kwargs['metArray'] |
|
1987 | metArray = kwargs['metArray'] | |
1988 | heightList = kwargs['heightList'] |
|
1988 | heightList = kwargs['heightList'] | |
1989 | timeList = kwargs['timeList'] |
|
1989 | timeList = kwargs['timeList'] | |
1990 |
|
1990 | |||
1991 | rx_location = kwargs['rx_location'] |
|
1991 | rx_location = kwargs['rx_location'] | |
1992 | groupList = kwargs['groupList'] |
|
1992 | groupList = kwargs['groupList'] | |
1993 | azimuth = kwargs['azimuth'] |
|
1993 | azimuth = kwargs['azimuth'] | |
1994 | dfactor = kwargs['dfactor'] |
|
1994 | dfactor = kwargs['dfactor'] | |
1995 | k = kwargs['k'] |
|
1995 | k = kwargs['k'] | |
1996 |
|
1996 | |||
1997 | azimuth1, dist = self.__calculateAzimuth1(rx_location, groupList, azimuth) |
|
1997 | azimuth1, dist = self.__calculateAzimuth1(rx_location, groupList, azimuth) | |
1998 | d = dist*dfactor |
|
1998 | d = dist*dfactor | |
1999 | #Phase calculation |
|
1999 | #Phase calculation | |
2000 | metArray1 = self.__getPhaseSlope(metArray, heightList, timeList) |
|
2000 | metArray1 = self.__getPhaseSlope(metArray, heightList, timeList) | |
2001 |
|
2001 | |||
2002 | metArray1[:,-2] = metArray1[:,-2]*metArray1[:,2]*1000/(k*d[metArray1[:,1].astype(int)]) #angles into velocities |
|
2002 | metArray1[:,-2] = metArray1[:,-2]*metArray1[:,2]*1000/(k*d[metArray1[:,1].astype(int)]) #angles into velocities | |
2003 |
|
2003 | |||
2004 | velEst = numpy.zeros((heightList.size,2))*numpy.nan |
|
2004 | velEst = numpy.zeros((heightList.size,2))*numpy.nan | |
2005 | azimuth1 = azimuth1*numpy.pi/180 |
|
2005 | azimuth1 = azimuth1*numpy.pi/180 | |
2006 |
|
2006 | |||
2007 | for i in range(heightList.size): |
|
2007 | for i in range(heightList.size): | |
2008 | h = heightList[i] |
|
2008 | h = heightList[i] | |
2009 | indH = numpy.where((metArray1[:,2] == h)&(numpy.abs(metArray1[:,-2]) < 100))[0] |
|
2009 | indH = numpy.where((metArray1[:,2] == h)&(numpy.abs(metArray1[:,-2]) < 100))[0] | |
2010 | metHeight = metArray1[indH,:] |
|
2010 | metHeight = metArray1[indH,:] | |
2011 | if metHeight.shape[0] >= 2: |
|
2011 | if metHeight.shape[0] >= 2: | |
2012 | velAux = numpy.asmatrix(metHeight[:,-2]).T #Radial Velocities |
|
2012 | velAux = numpy.asmatrix(metHeight[:,-2]).T #Radial Velocities | |
2013 | iazim = metHeight[:,1].astype(int) |
|
2013 | iazim = metHeight[:,1].astype(int) | |
2014 | azimAux = numpy.asmatrix(azimuth1[iazim]).T #Azimuths |
|
2014 | azimAux = numpy.asmatrix(azimuth1[iazim]).T #Azimuths | |
2015 | A = numpy.hstack((numpy.cos(azimAux),numpy.sin(azimAux))) |
|
2015 | A = numpy.hstack((numpy.cos(azimAux),numpy.sin(azimAux))) | |
2016 | A = numpy.asmatrix(A) |
|
2016 | A = numpy.asmatrix(A) | |
2017 | A1 = numpy.linalg.pinv(A.transpose()*A)*A.transpose() |
|
2017 | A1 = numpy.linalg.pinv(A.transpose()*A)*A.transpose() | |
2018 | velHor = numpy.dot(A1,velAux) |
|
2018 | velHor = numpy.dot(A1,velAux) | |
2019 |
|
2019 | |||
2020 | velEst[i,:] = numpy.squeeze(velHor) |
|
2020 | velEst[i,:] = numpy.squeeze(velHor) | |
2021 | return velEst |
|
2021 | return velEst | |
2022 |
|
2022 | |||
2023 | def __getPhaseSlope(self, metArray, heightList, timeList): |
|
2023 | def __getPhaseSlope(self, metArray, heightList, timeList): | |
2024 | meteorList = [] |
|
2024 | meteorList = [] | |
2025 | #utctime sec1 height SNR velRad ph0 ph1 ph2 coh0 coh1 coh2 |
|
2025 | #utctime sec1 height SNR velRad ph0 ph1 ph2 coh0 coh1 coh2 | |
2026 | #Putting back together the meteor matrix |
|
2026 | #Putting back together the meteor matrix | |
2027 | utctime = metArray[:,0] |
|
2027 | utctime = metArray[:,0] | |
2028 | uniqueTime = numpy.unique(utctime) |
|
2028 | uniqueTime = numpy.unique(utctime) | |
2029 |
|
2029 | |||
2030 | phaseDerThresh = 0.5 |
|
2030 | phaseDerThresh = 0.5 | |
2031 | ippSeconds = timeList[1] - timeList[0] |
|
2031 | ippSeconds = timeList[1] - timeList[0] | |
2032 | sec = numpy.where(timeList>1)[0][0] |
|
2032 | sec = numpy.where(timeList>1)[0][0] | |
2033 | nPairs = metArray.shape[1] - 6 |
|
2033 | nPairs = metArray.shape[1] - 6 | |
2034 | nHeights = len(heightList) |
|
2034 | nHeights = len(heightList) | |
2035 |
|
2035 | |||
2036 | for t in uniqueTime: |
|
2036 | for t in uniqueTime: | |
2037 | metArray1 = metArray[utctime==t,:] |
|
2037 | metArray1 = metArray[utctime==t,:] | |
2038 | # phaseDerThresh = numpy.pi/4 #reducir Phase thresh |
|
2038 | # phaseDerThresh = numpy.pi/4 #reducir Phase thresh | |
2039 | tmet = metArray1[:,1].astype(int) |
|
2039 | tmet = metArray1[:,1].astype(int) | |
2040 | hmet = metArray1[:,2].astype(int) |
|
2040 | hmet = metArray1[:,2].astype(int) | |
2041 |
|
2041 | |||
2042 | metPhase = numpy.zeros((nPairs, heightList.size, timeList.size - 1)) |
|
2042 | metPhase = numpy.zeros((nPairs, heightList.size, timeList.size - 1)) | |
2043 | metPhase[:,:] = numpy.nan |
|
2043 | metPhase[:,:] = numpy.nan | |
2044 | metPhase[:,hmet,tmet] = metArray1[:,6:].T |
|
2044 | metPhase[:,hmet,tmet] = metArray1[:,6:].T | |
2045 |
|
2045 | |||
2046 | #Delete short trails |
|
2046 | #Delete short trails | |
2047 | metBool = ~numpy.isnan(metPhase[0,:,:]) |
|
2047 | metBool = ~numpy.isnan(metPhase[0,:,:]) | |
2048 | heightVect = numpy.sum(metBool, axis = 1) |
|
2048 | heightVect = numpy.sum(metBool, axis = 1) | |
2049 | metBool[heightVect<sec,:] = False |
|
2049 | metBool[heightVect<sec,:] = False | |
2050 | metPhase[:,heightVect<sec,:] = numpy.nan |
|
2050 | metPhase[:,heightVect<sec,:] = numpy.nan | |
2051 |
|
2051 | |||
2052 | #Derivative |
|
2052 | #Derivative | |
2053 | metDer = numpy.abs(metPhase[:,:,1:] - metPhase[:,:,:-1]) |
|
2053 | metDer = numpy.abs(metPhase[:,:,1:] - metPhase[:,:,:-1]) | |
2054 | phDerAux = numpy.dstack((numpy.full((nPairs,nHeights,1), False, dtype=bool),metDer > phaseDerThresh)) |
|
2054 | phDerAux = numpy.dstack((numpy.full((nPairs,nHeights,1), False, dtype=bool),metDer > phaseDerThresh)) | |
2055 | metPhase[phDerAux] = numpy.nan |
|
2055 | metPhase[phDerAux] = numpy.nan | |
2056 |
|
2056 | |||
2057 | #--------------------------METEOR DETECTION ----------------------------------------- |
|
2057 | #--------------------------METEOR DETECTION ----------------------------------------- | |
2058 | indMet = numpy.where(numpy.any(metBool,axis=1))[0] |
|
2058 | indMet = numpy.where(numpy.any(metBool,axis=1))[0] | |
2059 |
|
2059 | |||
2060 | for p in numpy.arange(nPairs): |
|
2060 | for p in numpy.arange(nPairs): | |
2061 | phase = metPhase[p,:,:] |
|
2061 | phase = metPhase[p,:,:] | |
2062 | phDer = metDer[p,:,:] |
|
2062 | phDer = metDer[p,:,:] | |
2063 |
|
2063 | |||
2064 | for h in indMet: |
|
2064 | for h in indMet: | |
2065 | height = heightList[h] |
|
2065 | height = heightList[h] | |
2066 | phase1 = phase[h,:] #82 |
|
2066 | phase1 = phase[h,:] #82 | |
2067 | phDer1 = phDer[h,:] |
|
2067 | phDer1 = phDer[h,:] | |
2068 |
|
2068 | |||
2069 | phase1[~numpy.isnan(phase1)] = numpy.unwrap(phase1[~numpy.isnan(phase1)]) #Unwrap |
|
2069 | phase1[~numpy.isnan(phase1)] = numpy.unwrap(phase1[~numpy.isnan(phase1)]) #Unwrap | |
2070 |
|
2070 | |||
2071 | indValid = numpy.where(~numpy.isnan(phase1))[0] |
|
2071 | indValid = numpy.where(~numpy.isnan(phase1))[0] | |
2072 | initMet = indValid[0] |
|
2072 | initMet = indValid[0] | |
2073 | endMet = 0 |
|
2073 | endMet = 0 | |
2074 |
|
2074 | |||
2075 | for i in range(len(indValid)-1): |
|
2075 | for i in range(len(indValid)-1): | |
2076 |
|
2076 | |||
2077 | #Time difference |
|
2077 | #Time difference | |
2078 | inow = indValid[i] |
|
2078 | inow = indValid[i] | |
2079 | inext = indValid[i+1] |
|
2079 | inext = indValid[i+1] | |
2080 | idiff = inext - inow |
|
2080 | idiff = inext - inow | |
2081 | #Phase difference |
|
2081 | #Phase difference | |
2082 | phDiff = numpy.abs(phase1[inext] - phase1[inow]) |
|
2082 | phDiff = numpy.abs(phase1[inext] - phase1[inow]) | |
2083 |
|
2083 | |||
2084 | if idiff>sec or phDiff>numpy.pi/4 or inext==indValid[-1]: #End of Meteor |
|
2084 | if idiff>sec or phDiff>numpy.pi/4 or inext==indValid[-1]: #End of Meteor | |
2085 | sizeTrail = inow - initMet + 1 |
|
2085 | sizeTrail = inow - initMet + 1 | |
2086 | if sizeTrail>3*sec: #Too short meteors |
|
2086 | if sizeTrail>3*sec: #Too short meteors | |
2087 | x = numpy.arange(initMet,inow+1)*ippSeconds |
|
2087 | x = numpy.arange(initMet,inow+1)*ippSeconds | |
2088 | y = phase1[initMet:inow+1] |
|
2088 | y = phase1[initMet:inow+1] | |
2089 | ynnan = ~numpy.isnan(y) |
|
2089 | ynnan = ~numpy.isnan(y) | |
2090 | x = x[ynnan] |
|
2090 | x = x[ynnan] | |
2091 | y = y[ynnan] |
|
2091 | y = y[ynnan] | |
2092 | slope, intercept, r_value, p_value, std_err = stats.linregress(x,y) |
|
2092 | slope, intercept, r_value, p_value, std_err = stats.linregress(x,y) | |
2093 | ylin = x*slope + intercept |
|
2093 | ylin = x*slope + intercept | |
2094 | rsq = r_value**2 |
|
2094 | rsq = r_value**2 | |
2095 | if rsq > 0.5: |
|
2095 | if rsq > 0.5: | |
2096 | vel = slope#*height*1000/(k*d) |
|
2096 | vel = slope#*height*1000/(k*d) | |
2097 | estAux = numpy.array([utctime,p,height, vel, rsq]) |
|
2097 | estAux = numpy.array([utctime,p,height, vel, rsq]) | |
2098 | meteorList.append(estAux) |
|
2098 | meteorList.append(estAux) | |
2099 | initMet = inext |
|
2099 | initMet = inext | |
2100 | metArray2 = numpy.array(meteorList) |
|
2100 | metArray2 = numpy.array(meteorList) | |
2101 |
|
2101 | |||
2102 | return metArray2 |
|
2102 | return metArray2 | |
2103 |
|
2103 | |||
2104 | def __calculateAzimuth1(self, rx_location, pairslist, azimuth0): |
|
2104 | def __calculateAzimuth1(self, rx_location, pairslist, azimuth0): | |
2105 |
|
2105 | |||
2106 | azimuth1 = numpy.zeros(len(pairslist)) |
|
2106 | azimuth1 = numpy.zeros(len(pairslist)) | |
2107 | dist = numpy.zeros(len(pairslist)) |
|
2107 | dist = numpy.zeros(len(pairslist)) | |
2108 |
|
2108 | |||
2109 | for i in range(len(rx_location)): |
|
2109 | for i in range(len(rx_location)): | |
2110 | ch0 = pairslist[i][0] |
|
2110 | ch0 = pairslist[i][0] | |
2111 | ch1 = pairslist[i][1] |
|
2111 | ch1 = pairslist[i][1] | |
2112 |
|
2112 | |||
2113 | diffX = rx_location[ch0][0] - rx_location[ch1][0] |
|
2113 | diffX = rx_location[ch0][0] - rx_location[ch1][0] | |
2114 | diffY = rx_location[ch0][1] - rx_location[ch1][1] |
|
2114 | diffY = rx_location[ch0][1] - rx_location[ch1][1] | |
2115 | azimuth1[i] = numpy.arctan2(diffY,diffX)*180/numpy.pi |
|
2115 | azimuth1[i] = numpy.arctan2(diffY,diffX)*180/numpy.pi | |
2116 | dist[i] = numpy.sqrt(diffX**2 + diffY**2) |
|
2116 | dist[i] = numpy.sqrt(diffX**2 + diffY**2) | |
2117 |
|
2117 | |||
2118 | azimuth1 -= azimuth0 |
|
2118 | azimuth1 -= azimuth0 | |
2119 | return azimuth1, dist |
|
2119 | return azimuth1, dist | |
2120 |
|
2120 | |||
2121 | def techniqueNSM_DBS(self, **kwargs): |
|
2121 | def techniqueNSM_DBS(self, **kwargs): | |
2122 | metArray = kwargs['metArray'] |
|
2122 | metArray = kwargs['metArray'] | |
2123 | heightList = kwargs['heightList'] |
|
2123 | heightList = kwargs['heightList'] | |
2124 | timeList = kwargs['timeList'] |
|
2124 | timeList = kwargs['timeList'] | |
2125 | azimuth = kwargs['azimuth'] |
|
2125 | azimuth = kwargs['azimuth'] | |
2126 | theta_x = numpy.array(kwargs['theta_x']) |
|
2126 | theta_x = numpy.array(kwargs['theta_x']) | |
2127 | theta_y = numpy.array(kwargs['theta_y']) |
|
2127 | theta_y = numpy.array(kwargs['theta_y']) | |
2128 |
|
2128 | |||
2129 | utctime = metArray[:,0] |
|
2129 | utctime = metArray[:,0] | |
2130 | cmet = metArray[:,1].astype(int) |
|
2130 | cmet = metArray[:,1].astype(int) | |
2131 | hmet = metArray[:,3].astype(int) |
|
2131 | hmet = metArray[:,3].astype(int) | |
2132 | SNRmet = metArray[:,4] |
|
2132 | SNRmet = metArray[:,4] | |
2133 | vmet = metArray[:,5] |
|
2133 | vmet = metArray[:,5] | |
2134 | spcmet = metArray[:,6] |
|
2134 | spcmet = metArray[:,6] | |
2135 |
|
2135 | |||
2136 | nChan = numpy.max(cmet) + 1 |
|
2136 | nChan = numpy.max(cmet) + 1 | |
2137 | nHeights = len(heightList) |
|
2137 | nHeights = len(heightList) | |
2138 |
|
2138 | |||
2139 | azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw = self.__calculateAngles(theta_x, theta_y, azimuth) |
|
2139 | azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw = self.__calculateAngles(theta_x, theta_y, azimuth) | |
2140 | hmet = heightList[hmet] |
|
2140 | hmet = heightList[hmet] | |
2141 | h1met = hmet*numpy.cos(zenith_arr[cmet]) #Corrected heights |
|
2141 | h1met = hmet*numpy.cos(zenith_arr[cmet]) #Corrected heights | |
2142 |
|
2142 | |||
2143 | velEst = numpy.zeros((heightList.size,2))*numpy.nan |
|
2143 | velEst = numpy.zeros((heightList.size,2))*numpy.nan | |
2144 |
|
2144 | |||
2145 | for i in range(nHeights - 1): |
|
2145 | for i in range(nHeights - 1): | |
2146 | hmin = heightList[i] |
|
2146 | hmin = heightList[i] | |
2147 | hmax = heightList[i + 1] |
|
2147 | hmax = heightList[i + 1] | |
2148 |
|
2148 | |||
2149 | thisH = (h1met>=hmin) & (h1met<hmax) & (cmet!=2) & (SNRmet>8) & (vmet<50) & (spcmet<10) |
|
2149 | thisH = (h1met>=hmin) & (h1met<hmax) & (cmet!=2) & (SNRmet>8) & (vmet<50) & (spcmet<10) | |
2150 | indthisH = numpy.where(thisH) |
|
2150 | indthisH = numpy.where(thisH) | |
2151 |
|
2151 | |||
2152 | if numpy.size(indthisH) > 3: |
|
2152 | if numpy.size(indthisH) > 3: | |
2153 |
|
2153 | |||
2154 | vel_aux = vmet[thisH] |
|
2154 | vel_aux = vmet[thisH] | |
2155 | chan_aux = cmet[thisH] |
|
2155 | chan_aux = cmet[thisH] | |
2156 | cosu_aux = dir_cosu[chan_aux] |
|
2156 | cosu_aux = dir_cosu[chan_aux] | |
2157 | cosv_aux = dir_cosv[chan_aux] |
|
2157 | cosv_aux = dir_cosv[chan_aux] | |
2158 | cosw_aux = dir_cosw[chan_aux] |
|
2158 | cosw_aux = dir_cosw[chan_aux] | |
2159 |
|
2159 | |||
2160 | nch = numpy.size(numpy.unique(chan_aux)) |
|
2160 | nch = numpy.size(numpy.unique(chan_aux)) | |
2161 | if nch > 1: |
|
2161 | if nch > 1: | |
2162 | A = self.__calculateMatA(cosu_aux, cosv_aux, cosw_aux, True) |
|
2162 | A = self.__calculateMatA(cosu_aux, cosv_aux, cosw_aux, True) | |
2163 | velEst[i,:] = numpy.dot(A,vel_aux) |
|
2163 | velEst[i,:] = numpy.dot(A,vel_aux) | |
2164 |
|
2164 | |||
2165 | return velEst |
|
2165 | return velEst | |
2166 |
|
2166 | |||
2167 | def run(self, dataOut, technique, nHours=1, hmin=70, hmax=110, **kwargs): |
|
2167 | def run(self, dataOut, technique, nHours=1, hmin=70, hmax=110, **kwargs): | |
2168 |
|
2168 | |||
2169 | param = dataOut.data_param |
|
2169 | param = dataOut.data_param | |
2170 | if dataOut.abscissaList != None: |
|
2170 | if dataOut.abscissaList != None: | |
2171 | absc = dataOut.abscissaList[:-1] |
|
2171 | absc = dataOut.abscissaList[:-1] | |
2172 | # noise = dataOut.noise |
|
2172 | # noise = dataOut.noise | |
2173 | heightList = dataOut.heightList |
|
2173 | heightList = dataOut.heightList | |
2174 | SNR = dataOut.data_snr |
|
2174 | SNR = dataOut.data_snr | |
2175 |
|
2175 | |||
2176 | if technique == 'DBS': |
|
2176 | if technique == 'DBS': | |
2177 |
|
2177 | |||
2178 | kwargs['velRadial'] = param[:,1,:] #Radial velocity |
|
2178 | kwargs['velRadial'] = param[:,1,:] #Radial velocity | |
2179 | kwargs['heightList'] = heightList |
|
2179 | kwargs['heightList'] = heightList | |
2180 | kwargs['SNR'] = SNR |
|
2180 | kwargs['SNR'] = SNR | |
2181 |
|
2181 | |||
2182 | dataOut.data_output, dataOut.heightList, dataOut.data_snr = self.techniqueDBS(kwargs) #DBS Function |
|
2182 | dataOut.data_output, dataOut.heightList, dataOut.data_snr = self.techniqueDBS(kwargs) #DBS Function | |
2183 | dataOut.utctimeInit = dataOut.utctime |
|
2183 | dataOut.utctimeInit = dataOut.utctime | |
2184 | dataOut.outputInterval = dataOut.paramInterval |
|
2184 | dataOut.outputInterval = dataOut.paramInterval | |
2185 |
|
2185 | |||
2186 | elif technique == 'SA': |
|
2186 | elif technique == 'SA': | |
2187 |
|
2187 | |||
2188 | #Parameters |
|
2188 | #Parameters | |
2189 | # position_x = kwargs['positionX'] |
|
2189 | # position_x = kwargs['positionX'] | |
2190 | # position_y = kwargs['positionY'] |
|
2190 | # position_y = kwargs['positionY'] | |
2191 | # azimuth = kwargs['azimuth'] |
|
2191 | # azimuth = kwargs['azimuth'] | |
2192 | # |
|
2192 | # | |
2193 | # if kwargs.has_key('crosspairsList'): |
|
2193 | # if kwargs.has_key('crosspairsList'): | |
2194 | # pairs = kwargs['crosspairsList'] |
|
2194 | # pairs = kwargs['crosspairsList'] | |
2195 | # else: |
|
2195 | # else: | |
2196 | # pairs = None |
|
2196 | # pairs = None | |
2197 | # |
|
2197 | # | |
2198 | # if kwargs.has_key('correctFactor'): |
|
2198 | # if kwargs.has_key('correctFactor'): | |
2199 | # correctFactor = kwargs['correctFactor'] |
|
2199 | # correctFactor = kwargs['correctFactor'] | |
2200 | # else: |
|
2200 | # else: | |
2201 | # correctFactor = 1 |
|
2201 | # correctFactor = 1 | |
2202 |
|
2202 | |||
2203 | # tau = dataOut.data_param |
|
2203 | # tau = dataOut.data_param | |
2204 | # _lambda = dataOut.C/dataOut.frequency |
|
2204 | # _lambda = dataOut.C/dataOut.frequency | |
2205 | # pairsList = dataOut.groupList |
|
2205 | # pairsList = dataOut.groupList | |
2206 | # nChannels = dataOut.nChannels |
|
2206 | # nChannels = dataOut.nChannels | |
2207 |
|
2207 | |||
2208 | kwargs['groupList'] = dataOut.groupList |
|
2208 | kwargs['groupList'] = dataOut.groupList | |
2209 | kwargs['tau'] = dataOut.data_param |
|
2209 | kwargs['tau'] = dataOut.data_param | |
2210 | kwargs['_lambda'] = dataOut.C/dataOut.frequency |
|
2210 | kwargs['_lambda'] = dataOut.C/dataOut.frequency | |
2211 | # dataOut.data_output = self.techniqueSA(pairs, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, absc, correctFactor) |
|
2211 | # dataOut.data_output = self.techniqueSA(pairs, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, absc, correctFactor) | |
2212 | dataOut.data_output = self.techniqueSA(kwargs) |
|
2212 | dataOut.data_output = self.techniqueSA(kwargs) | |
2213 | dataOut.utctimeInit = dataOut.utctime |
|
2213 | dataOut.utctimeInit = dataOut.utctime | |
2214 | dataOut.outputInterval = dataOut.timeInterval |
|
2214 | dataOut.outputInterval = dataOut.timeInterval | |
2215 |
|
2215 | |||
2216 | elif technique == 'Meteors': |
|
2216 | elif technique == 'Meteors': | |
2217 | dataOut.flagNoData = True |
|
2217 | dataOut.flagNoData = True | |
2218 | self.__dataReady = False |
|
2218 | self.__dataReady = False | |
2219 |
|
2219 | |||
2220 | if 'nHours' in kwargs: |
|
2220 | if 'nHours' in kwargs: | |
2221 | nHours = kwargs['nHours'] |
|
2221 | nHours = kwargs['nHours'] | |
2222 | else: |
|
2222 | else: | |
2223 | nHours = 1 |
|
2223 | nHours = 1 | |
2224 |
|
2224 | |||
2225 | if 'meteorsPerBin' in kwargs: |
|
2225 | if 'meteorsPerBin' in kwargs: | |
2226 | meteorThresh = kwargs['meteorsPerBin'] |
|
2226 | meteorThresh = kwargs['meteorsPerBin'] | |
2227 | else: |
|
2227 | else: | |
2228 | meteorThresh = 6 |
|
2228 | meteorThresh = 6 | |
2229 |
|
2229 | |||
2230 | if 'hmin' in kwargs: |
|
2230 | if 'hmin' in kwargs: | |
2231 | hmin = kwargs['hmin'] |
|
2231 | hmin = kwargs['hmin'] | |
2232 | else: hmin = 70 |
|
2232 | else: hmin = 70 | |
2233 | if 'hmax' in kwargs: |
|
2233 | if 'hmax' in kwargs: | |
2234 | hmax = kwargs['hmax'] |
|
2234 | hmax = kwargs['hmax'] | |
2235 | else: hmax = 110 |
|
2235 | else: hmax = 110 | |
2236 |
|
2236 | |||
2237 | dataOut.outputInterval = nHours*3600 |
|
2237 | dataOut.outputInterval = nHours*3600 | |
2238 |
|
2238 | |||
2239 | if self.__isConfig == False: |
|
2239 | if self.__isConfig == False: | |
2240 | # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03) |
|
2240 | # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03) | |
2241 | #Get Initial LTC time |
|
2241 | #Get Initial LTC time | |
2242 | self.__initime = datetime.datetime.utcfromtimestamp(dataOut.utctime) |
|
2242 | self.__initime = datetime.datetime.utcfromtimestamp(dataOut.utctime) | |
2243 | self.__initime = (self.__initime.replace(minute = 0, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds() |
|
2243 | self.__initime = (self.__initime.replace(minute = 0, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds() | |
2244 |
|
2244 | |||
2245 | self.__isConfig = True |
|
2245 | self.__isConfig = True | |
2246 |
|
2246 | |||
2247 | if self.__buffer is None: |
|
2247 | if self.__buffer is None: | |
2248 | self.__buffer = dataOut.data_param |
|
2248 | self.__buffer = dataOut.data_param | |
2249 | self.__firstdata = copy.copy(dataOut) |
|
2249 | self.__firstdata = copy.copy(dataOut) | |
2250 |
|
2250 | |||
2251 | else: |
|
2251 | else: | |
2252 | self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param)) |
|
2252 | self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param)) | |
2253 |
|
2253 | |||
2254 | self.__checkTime(dataOut.utctime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready |
|
2254 | self.__checkTime(dataOut.utctime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready | |
2255 |
|
2255 | |||
2256 | if self.__dataReady: |
|
2256 | if self.__dataReady: | |
2257 | dataOut.utctimeInit = self.__initime |
|
2257 | dataOut.utctimeInit = self.__initime | |
2258 |
|
2258 | |||
2259 | self.__initime += dataOut.outputInterval #to erase time offset |
|
2259 | self.__initime += dataOut.outputInterval #to erase time offset | |
2260 |
|
2260 | |||
2261 | dataOut.data_output, dataOut.heightList = self.techniqueMeteors(self.__buffer, meteorThresh, hmin, hmax) |
|
2261 | dataOut.data_output, dataOut.heightList = self.techniqueMeteors(self.__buffer, meteorThresh, hmin, hmax) | |
2262 | dataOut.flagNoData = False |
|
2262 | dataOut.flagNoData = False | |
2263 | self.__buffer = None |
|
2263 | self.__buffer = None | |
2264 |
|
2264 | |||
2265 | elif technique == 'Meteors1': |
|
2265 | elif technique == 'Meteors1': | |
2266 | dataOut.flagNoData = True |
|
2266 | dataOut.flagNoData = True | |
2267 | self.__dataReady = False |
|
2267 | self.__dataReady = False | |
2268 |
|
2268 | |||
2269 | if 'nMins' in kwargs: |
|
2269 | if 'nMins' in kwargs: | |
2270 | nMins = kwargs['nMins'] |
|
2270 | nMins = kwargs['nMins'] | |
2271 | else: nMins = 20 |
|
2271 | else: nMins = 20 | |
2272 | if 'rx_location' in kwargs: |
|
2272 | if 'rx_location' in kwargs: | |
2273 | rx_location = kwargs['rx_location'] |
|
2273 | rx_location = kwargs['rx_location'] | |
2274 | else: rx_location = [(0,1),(1,1),(1,0)] |
|
2274 | else: rx_location = [(0,1),(1,1),(1,0)] | |
2275 | if 'azimuth' in kwargs: |
|
2275 | if 'azimuth' in kwargs: | |
2276 | azimuth = kwargs['azimuth'] |
|
2276 | azimuth = kwargs['azimuth'] | |
2277 | else: azimuth = 51.06 |
|
2277 | else: azimuth = 51.06 | |
2278 | if 'dfactor' in kwargs: |
|
2278 | if 'dfactor' in kwargs: | |
2279 | dfactor = kwargs['dfactor'] |
|
2279 | dfactor = kwargs['dfactor'] | |
2280 | if 'mode' in kwargs: |
|
2280 | if 'mode' in kwargs: | |
2281 | mode = kwargs['mode'] |
|
2281 | mode = kwargs['mode'] | |
2282 | if 'theta_x' in kwargs: |
|
2282 | if 'theta_x' in kwargs: | |
2283 | theta_x = kwargs['theta_x'] |
|
2283 | theta_x = kwargs['theta_x'] | |
2284 | if 'theta_y' in kwargs: |
|
2284 | if 'theta_y' in kwargs: | |
2285 | theta_y = kwargs['theta_y'] |
|
2285 | theta_y = kwargs['theta_y'] | |
2286 | else: mode = 'SA' |
|
2286 | else: mode = 'SA' | |
2287 |
|
2287 | |||
2288 | #Borrar luego esto |
|
2288 | #Borrar luego esto | |
2289 | if dataOut.groupList is None: |
|
2289 | if dataOut.groupList is None: | |
2290 | dataOut.groupList = [(0,1),(0,2),(1,2)] |
|
2290 | dataOut.groupList = [(0,1),(0,2),(1,2)] | |
2291 | groupList = dataOut.groupList |
|
2291 | groupList = dataOut.groupList | |
2292 | C = 3e8 |
|
2292 | C = 3e8 | |
2293 | freq = 50e6 |
|
2293 | freq = 50e6 | |
2294 | lamb = C/freq |
|
2294 | lamb = C/freq | |
2295 | k = 2*numpy.pi/lamb |
|
2295 | k = 2*numpy.pi/lamb | |
2296 |
|
2296 | |||
2297 | timeList = dataOut.abscissaList |
|
2297 | timeList = dataOut.abscissaList | |
2298 | heightList = dataOut.heightList |
|
2298 | heightList = dataOut.heightList | |
2299 |
|
2299 | |||
2300 | if self.__isConfig == False: |
|
2300 | if self.__isConfig == False: | |
2301 | dataOut.outputInterval = nMins*60 |
|
2301 | dataOut.outputInterval = nMins*60 | |
2302 | # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03) |
|
2302 | # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03) | |
2303 | #Get Initial LTC time |
|
2303 | #Get Initial LTC time | |
2304 | initime = datetime.datetime.utcfromtimestamp(dataOut.utctime) |
|
2304 | initime = datetime.datetime.utcfromtimestamp(dataOut.utctime) | |
2305 | minuteAux = initime.minute |
|
2305 | minuteAux = initime.minute | |
2306 | minuteNew = int(numpy.floor(minuteAux/nMins)*nMins) |
|
2306 | minuteNew = int(numpy.floor(minuteAux/nMins)*nMins) | |
2307 | self.__initime = (initime.replace(minute = minuteNew, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds() |
|
2307 | self.__initime = (initime.replace(minute = minuteNew, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds() | |
2308 |
|
2308 | |||
2309 | self.__isConfig = True |
|
2309 | self.__isConfig = True | |
2310 |
|
2310 | |||
2311 | if self.__buffer is None: |
|
2311 | if self.__buffer is None: | |
2312 | self.__buffer = dataOut.data_param |
|
2312 | self.__buffer = dataOut.data_param | |
2313 | self.__firstdata = copy.copy(dataOut) |
|
2313 | self.__firstdata = copy.copy(dataOut) | |
2314 |
|
2314 | |||
2315 | else: |
|
2315 | else: | |
2316 | self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param)) |
|
2316 | self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param)) | |
2317 |
|
2317 | |||
2318 | self.__checkTime(dataOut.utctime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready |
|
2318 | self.__checkTime(dataOut.utctime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready | |
2319 |
|
2319 | |||
2320 | if self.__dataReady: |
|
2320 | if self.__dataReady: | |
2321 | dataOut.utctimeInit = self.__initime |
|
2321 | dataOut.utctimeInit = self.__initime | |
2322 | self.__initime += dataOut.outputInterval #to erase time offset |
|
2322 | self.__initime += dataOut.outputInterval #to erase time offset | |
2323 |
|
2323 | |||
2324 | metArray = self.__buffer |
|
2324 | metArray = self.__buffer | |
2325 | if mode == 'SA': |
|
2325 | if mode == 'SA': | |
2326 | dataOut.data_output = self.techniqueNSM_SA(rx_location=rx_location, groupList=groupList, azimuth=azimuth, dfactor=dfactor, k=k,metArray=metArray, heightList=heightList,timeList=timeList) |
|
2326 | dataOut.data_output = self.techniqueNSM_SA(rx_location=rx_location, groupList=groupList, azimuth=azimuth, dfactor=dfactor, k=k,metArray=metArray, heightList=heightList,timeList=timeList) | |
2327 | elif mode == 'DBS': |
|
2327 | elif mode == 'DBS': | |
2328 | dataOut.data_output = self.techniqueNSM_DBS(metArray=metArray,heightList=heightList,timeList=timeList, azimuth=azimuth, theta_x=theta_x, theta_y=theta_y) |
|
2328 | dataOut.data_output = self.techniqueNSM_DBS(metArray=metArray,heightList=heightList,timeList=timeList, azimuth=azimuth, theta_x=theta_x, theta_y=theta_y) | |
2329 | dataOut.data_output = dataOut.data_output.T |
|
2329 | dataOut.data_output = dataOut.data_output.T | |
2330 | dataOut.flagNoData = False |
|
2330 | dataOut.flagNoData = False | |
2331 | self.__buffer = None |
|
2331 | self.__buffer = None | |
2332 |
|
2332 | |||
2333 | return |
|
2333 | return | |
2334 |
|
2334 | |||
2335 | class EWDriftsEstimation(Operation): |
|
2335 | class EWDriftsEstimation(Operation): | |
2336 |
|
2336 | |||
2337 | def __init__(self): |
|
2337 | def __init__(self): | |
2338 | Operation.__init__(self) |
|
2338 | Operation.__init__(self) | |
2339 |
|
2339 | |||
2340 | def __correctValues(self, heiRang, phi, velRadial, SNR): |
|
2340 | def __correctValues(self, heiRang, phi, velRadial, SNR): | |
2341 | listPhi = phi.tolist() |
|
2341 | listPhi = phi.tolist() | |
2342 | maxid = listPhi.index(max(listPhi)) |
|
2342 | maxid = listPhi.index(max(listPhi)) | |
2343 | minid = listPhi.index(min(listPhi)) |
|
2343 | minid = listPhi.index(min(listPhi)) | |
2344 |
|
2344 | |||
2345 | rango = list(range(len(phi))) |
|
2345 | rango = list(range(len(phi))) | |
2346 | # rango = numpy.delete(rango,maxid) |
|
2346 | # rango = numpy.delete(rango,maxid) | |
2347 |
|
2347 | |||
2348 | heiRang1 = heiRang*math.cos(phi[maxid]) |
|
2348 | heiRang1 = heiRang*math.cos(phi[maxid]) | |
2349 | heiRangAux = heiRang*math.cos(phi[minid]) |
|
2349 | heiRangAux = heiRang*math.cos(phi[minid]) | |
2350 | indOut = (heiRang1 < heiRangAux[0]).nonzero() |
|
2350 | indOut = (heiRang1 < heiRangAux[0]).nonzero() | |
2351 | heiRang1 = numpy.delete(heiRang1,indOut) |
|
2351 | heiRang1 = numpy.delete(heiRang1,indOut) | |
2352 |
|
2352 | |||
2353 | velRadial1 = numpy.zeros([len(phi),len(heiRang1)]) |
|
2353 | velRadial1 = numpy.zeros([len(phi),len(heiRang1)]) | |
2354 | SNR1 = numpy.zeros([len(phi),len(heiRang1)]) |
|
2354 | SNR1 = numpy.zeros([len(phi),len(heiRang1)]) | |
2355 |
|
2355 | |||
2356 | for i in rango: |
|
2356 | for i in rango: | |
2357 | x = heiRang*math.cos(phi[i]) |
|
2357 | x = heiRang*math.cos(phi[i]) | |
2358 | y1 = velRadial[i,:] |
|
2358 | y1 = velRadial[i,:] | |
2359 | f1 = interpolate.interp1d(x,y1,kind = 'cubic') |
|
2359 | f1 = interpolate.interp1d(x,y1,kind = 'cubic') | |
2360 |
|
2360 | |||
2361 | x1 = heiRang1 |
|
2361 | x1 = heiRang1 | |
2362 | y11 = f1(x1) |
|
2362 | y11 = f1(x1) | |
2363 |
|
2363 | |||
2364 | y2 = SNR[i,:] |
|
2364 | y2 = SNR[i,:] | |
2365 | f2 = interpolate.interp1d(x,y2,kind = 'cubic') |
|
2365 | f2 = interpolate.interp1d(x,y2,kind = 'cubic') | |
2366 | y21 = f2(x1) |
|
2366 | y21 = f2(x1) | |
2367 |
|
2367 | |||
2368 | velRadial1[i,:] = y11 |
|
2368 | velRadial1[i,:] = y11 | |
2369 | SNR1[i,:] = y21 |
|
2369 | SNR1[i,:] = y21 | |
2370 |
|
2370 | |||
2371 | return heiRang1, velRadial1, SNR1 |
|
2371 | return heiRang1, velRadial1, SNR1 | |
2372 |
|
2372 | |||
2373 | def run(self, dataOut, zenith, zenithCorrection): |
|
2373 | def run(self, dataOut, zenith, zenithCorrection): | |
2374 | heiRang = dataOut.heightList |
|
2374 | heiRang = dataOut.heightList | |
2375 | velRadial = dataOut.data_param[:,3,:] |
|
2375 | velRadial = dataOut.data_param[:,3,:] | |
2376 | SNR = dataOut.data_snr |
|
2376 | SNR = dataOut.data_snr | |
2377 |
|
2377 | |||
2378 | zenith = numpy.array(zenith) |
|
2378 | zenith = numpy.array(zenith) | |
2379 | zenith -= zenithCorrection |
|
2379 | zenith -= zenithCorrection | |
2380 | zenith *= numpy.pi/180 |
|
2380 | zenith *= numpy.pi/180 | |
2381 |
|
2381 | |||
2382 | heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, numpy.abs(zenith), velRadial, SNR) |
|
2382 | heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, numpy.abs(zenith), velRadial, SNR) | |
2383 |
|
2383 | |||
2384 | alp = zenith[0] |
|
2384 | alp = zenith[0] | |
2385 | bet = zenith[1] |
|
2385 | bet = zenith[1] | |
2386 |
|
2386 | |||
2387 | w_w = velRadial1[0,:] |
|
2387 | w_w = velRadial1[0,:] | |
2388 | w_e = velRadial1[1,:] |
|
2388 | w_e = velRadial1[1,:] | |
2389 |
|
2389 | |||
2390 | w = (w_w*numpy.sin(bet) - w_e*numpy.sin(alp))/(numpy.cos(alp)*numpy.sin(bet) - numpy.cos(bet)*numpy.sin(alp)) |
|
2390 | w = (w_w*numpy.sin(bet) - w_e*numpy.sin(alp))/(numpy.cos(alp)*numpy.sin(bet) - numpy.cos(bet)*numpy.sin(alp)) | |
2391 | u = (w_w*numpy.cos(bet) - w_e*numpy.cos(alp))/(numpy.sin(alp)*numpy.cos(bet) - numpy.sin(bet)*numpy.cos(alp)) |
|
2391 | u = (w_w*numpy.cos(bet) - w_e*numpy.cos(alp))/(numpy.sin(alp)*numpy.cos(bet) - numpy.sin(bet)*numpy.cos(alp)) | |
2392 |
|
2392 | |||
2393 | winds = numpy.vstack((u,w)) |
|
2393 | winds = numpy.vstack((u,w)) | |
2394 |
|
2394 | |||
2395 | dataOut.heightList = heiRang1 |
|
2395 | dataOut.heightList = heiRang1 | |
2396 | dataOut.data_output = winds |
|
2396 | dataOut.data_output = winds | |
2397 | dataOut.data_snr = SNR1 |
|
2397 | dataOut.data_snr = SNR1 | |
2398 |
|
2398 | |||
2399 | dataOut.utctimeInit = dataOut.utctime |
|
2399 | dataOut.utctimeInit = dataOut.utctime | |
2400 | dataOut.outputInterval = dataOut.timeInterval |
|
2400 | dataOut.outputInterval = dataOut.timeInterval | |
2401 | return |
|
2401 | return | |
2402 |
|
2402 | |||
2403 | #--------------- Non Specular Meteor ---------------- |
|
2403 | #--------------- Non Specular Meteor ---------------- | |
2404 |
|
2404 | |||
2405 | class NonSpecularMeteorDetection(Operation): |
|
2405 | class NonSpecularMeteorDetection(Operation): | |
2406 |
|
2406 | |||
2407 | def run(self, dataOut, mode, SNRthresh=8, phaseDerThresh=0.5, cohThresh=0.8, allData = False): |
|
2407 | def run(self, dataOut, mode, SNRthresh=8, phaseDerThresh=0.5, cohThresh=0.8, allData = False): | |
2408 | data_acf = dataOut.data_pre[0] |
|
2408 | data_acf = dataOut.data_pre[0] | |
2409 | data_ccf = dataOut.data_pre[1] |
|
2409 | data_ccf = dataOut.data_pre[1] | |
2410 | pairsList = dataOut.groupList[1] |
|
2410 | pairsList = dataOut.groupList[1] | |
2411 |
|
2411 | |||
2412 | lamb = dataOut.C/dataOut.frequency |
|
2412 | lamb = dataOut.C/dataOut.frequency | |
2413 | tSamp = dataOut.ippSeconds*dataOut.nCohInt |
|
2413 | tSamp = dataOut.ippSeconds*dataOut.nCohInt | |
2414 | paramInterval = dataOut.paramInterval |
|
2414 | paramInterval = dataOut.paramInterval | |
2415 |
|
2415 | |||
2416 | nChannels = data_acf.shape[0] |
|
2416 | nChannels = data_acf.shape[0] | |
2417 | nLags = data_acf.shape[1] |
|
2417 | nLags = data_acf.shape[1] | |
2418 | nProfiles = data_acf.shape[2] |
|
2418 | nProfiles = data_acf.shape[2] | |
2419 | nHeights = dataOut.nHeights |
|
2419 | nHeights = dataOut.nHeights | |
2420 | nCohInt = dataOut.nCohInt |
|
2420 | nCohInt = dataOut.nCohInt | |
2421 | sec = numpy.round(nProfiles/dataOut.paramInterval) |
|
2421 | sec = numpy.round(nProfiles/dataOut.paramInterval) | |
2422 | heightList = dataOut.heightList |
|
2422 | heightList = dataOut.heightList | |
2423 | ippSeconds = dataOut.ippSeconds*dataOut.nCohInt*dataOut.nAvg |
|
2423 | ippSeconds = dataOut.ippSeconds*dataOut.nCohInt*dataOut.nAvg | |
2424 | utctime = dataOut.utctime |
|
2424 | utctime = dataOut.utctime | |
2425 |
|
2425 | |||
2426 | dataOut.abscissaList = numpy.arange(0,paramInterval+ippSeconds,ippSeconds) |
|
2426 | dataOut.abscissaList = numpy.arange(0,paramInterval+ippSeconds,ippSeconds) | |
2427 |
|
2427 | |||
2428 | #------------------------ SNR -------------------------------------- |
|
2428 | #------------------------ SNR -------------------------------------- | |
2429 | power = data_acf[:,0,:,:].real |
|
2429 | power = data_acf[:,0,:,:].real | |
2430 | noise = numpy.zeros(nChannels) |
|
2430 | noise = numpy.zeros(nChannels) | |
2431 | SNR = numpy.zeros(power.shape) |
|
2431 | SNR = numpy.zeros(power.shape) | |
2432 | for i in range(nChannels): |
|
2432 | for i in range(nChannels): | |
2433 | noise[i] = hildebrand_sekhon(power[i,:], nCohInt) |
|
2433 | noise[i] = hildebrand_sekhon(power[i,:], nCohInt) | |
2434 | SNR[i] = (power[i]-noise[i])/noise[i] |
|
2434 | SNR[i] = (power[i]-noise[i])/noise[i] | |
2435 | SNRm = numpy.nanmean(SNR, axis = 0) |
|
2435 | SNRm = numpy.nanmean(SNR, axis = 0) | |
2436 | SNRdB = 10*numpy.log10(SNR) |
|
2436 | SNRdB = 10*numpy.log10(SNR) | |
2437 |
|
2437 | |||
2438 | if mode == 'SA': |
|
2438 | if mode == 'SA': | |
2439 | dataOut.groupList = dataOut.groupList[1] |
|
2439 | dataOut.groupList = dataOut.groupList[1] | |
2440 | nPairs = data_ccf.shape[0] |
|
2440 | nPairs = data_ccf.shape[0] | |
2441 | #---------------------- Coherence and Phase -------------------------- |
|
2441 | #---------------------- Coherence and Phase -------------------------- | |
2442 | phase = numpy.zeros(data_ccf[:,0,:,:].shape) |
|
2442 | phase = numpy.zeros(data_ccf[:,0,:,:].shape) | |
2443 | # phase1 = numpy.copy(phase) |
|
2443 | # phase1 = numpy.copy(phase) | |
2444 | coh1 = numpy.zeros(data_ccf[:,0,:,:].shape) |
|
2444 | coh1 = numpy.zeros(data_ccf[:,0,:,:].shape) | |
2445 |
|
2445 | |||
2446 | for p in range(nPairs): |
|
2446 | for p in range(nPairs): | |
2447 | ch0 = pairsList[p][0] |
|
2447 | ch0 = pairsList[p][0] | |
2448 | ch1 = pairsList[p][1] |
|
2448 | ch1 = pairsList[p][1] | |
2449 | ccf = data_ccf[p,0,:,:]/numpy.sqrt(data_acf[ch0,0,:,:]*data_acf[ch1,0,:,:]) |
|
2449 | ccf = data_ccf[p,0,:,:]/numpy.sqrt(data_acf[ch0,0,:,:]*data_acf[ch1,0,:,:]) | |
2450 | phase[p,:,:] = ndimage.median_filter(numpy.angle(ccf), size = (5,1)) #median filter |
|
2450 | phase[p,:,:] = ndimage.median_filter(numpy.angle(ccf), size = (5,1)) #median filter | |
2451 | # phase1[p,:,:] = numpy.angle(ccf) #median filter |
|
2451 | # phase1[p,:,:] = numpy.angle(ccf) #median filter | |
2452 | coh1[p,:,:] = ndimage.median_filter(numpy.abs(ccf), 5) #median filter |
|
2452 | coh1[p,:,:] = ndimage.median_filter(numpy.abs(ccf), 5) #median filter | |
2453 | # coh1[p,:,:] = numpy.abs(ccf) #median filter |
|
2453 | # coh1[p,:,:] = numpy.abs(ccf) #median filter | |
2454 | coh = numpy.nanmax(coh1, axis = 0) |
|
2454 | coh = numpy.nanmax(coh1, axis = 0) | |
2455 | # struc = numpy.ones((5,1)) |
|
2455 | # struc = numpy.ones((5,1)) | |
2456 | # coh = ndimage.morphology.grey_dilation(coh, size=(10,1)) |
|
2456 | # coh = ndimage.morphology.grey_dilation(coh, size=(10,1)) | |
2457 | #---------------------- Radial Velocity ---------------------------- |
|
2457 | #---------------------- Radial Velocity ---------------------------- | |
2458 | phaseAux = numpy.mean(numpy.angle(data_acf[:,1,:,:]), axis = 0) |
|
2458 | phaseAux = numpy.mean(numpy.angle(data_acf[:,1,:,:]), axis = 0) | |
2459 | velRad = phaseAux*lamb/(4*numpy.pi*tSamp) |
|
2459 | velRad = phaseAux*lamb/(4*numpy.pi*tSamp) | |
2460 |
|
2460 | |||
2461 | if allData: |
|
2461 | if allData: | |
2462 | boolMetFin = ~numpy.isnan(SNRm) |
|
2462 | boolMetFin = ~numpy.isnan(SNRm) | |
2463 | # coh[:-1,:] = numpy.nanmean(numpy.abs(phase[:,1:,:] - phase[:,:-1,:]),axis=0) |
|
2463 | # coh[:-1,:] = numpy.nanmean(numpy.abs(phase[:,1:,:] - phase[:,:-1,:]),axis=0) | |
2464 | else: |
|
2464 | else: | |
2465 | #------------------------ Meteor mask --------------------------------- |
|
2465 | #------------------------ Meteor mask --------------------------------- | |
2466 | # #SNR mask |
|
2466 | # #SNR mask | |
2467 | # boolMet = (SNRdB>SNRthresh)#|(~numpy.isnan(SNRdB)) |
|
2467 | # boolMet = (SNRdB>SNRthresh)#|(~numpy.isnan(SNRdB)) | |
2468 | # |
|
2468 | # | |
2469 | # #Erase small objects |
|
2469 | # #Erase small objects | |
2470 | # boolMet1 = self.__erase_small(boolMet, 2*sec, 5) |
|
2470 | # boolMet1 = self.__erase_small(boolMet, 2*sec, 5) | |
2471 | # |
|
2471 | # | |
2472 | # auxEEJ = numpy.sum(boolMet1,axis=0) |
|
2472 | # auxEEJ = numpy.sum(boolMet1,axis=0) | |
2473 | # indOver = auxEEJ>nProfiles*0.8 #Use this later |
|
2473 | # indOver = auxEEJ>nProfiles*0.8 #Use this later | |
2474 | # indEEJ = numpy.where(indOver)[0] |
|
2474 | # indEEJ = numpy.where(indOver)[0] | |
2475 | # indNEEJ = numpy.where(~indOver)[0] |
|
2475 | # indNEEJ = numpy.where(~indOver)[0] | |
2476 | # |
|
2476 | # | |
2477 | # boolMetFin = boolMet1 |
|
2477 | # boolMetFin = boolMet1 | |
2478 | # |
|
2478 | # | |
2479 | # if indEEJ.size > 0: |
|
2479 | # if indEEJ.size > 0: | |
2480 | # boolMet1[:,indEEJ] = False #Erase heights with EEJ |
|
2480 | # boolMet1[:,indEEJ] = False #Erase heights with EEJ | |
2481 | # |
|
2481 | # | |
2482 | # boolMet2 = coh > cohThresh |
|
2482 | # boolMet2 = coh > cohThresh | |
2483 | # boolMet2 = self.__erase_small(boolMet2, 2*sec,5) |
|
2483 | # boolMet2 = self.__erase_small(boolMet2, 2*sec,5) | |
2484 | # |
|
2484 | # | |
2485 | # #Final Meteor mask |
|
2485 | # #Final Meteor mask | |
2486 | # boolMetFin = boolMet1|boolMet2 |
|
2486 | # boolMetFin = boolMet1|boolMet2 | |
2487 |
|
2487 | |||
2488 | #Coherence mask |
|
2488 | #Coherence mask | |
2489 | boolMet1 = coh > 0.75 |
|
2489 | boolMet1 = coh > 0.75 | |
2490 | struc = numpy.ones((30,1)) |
|
2490 | struc = numpy.ones((30,1)) | |
2491 | boolMet1 = ndimage.morphology.binary_dilation(boolMet1, structure=struc) |
|
2491 | boolMet1 = ndimage.morphology.binary_dilation(boolMet1, structure=struc) | |
2492 |
|
2492 | |||
2493 | #Derivative mask |
|
2493 | #Derivative mask | |
2494 | derPhase = numpy.nanmean(numpy.abs(phase[:,1:,:] - phase[:,:-1,:]),axis=0) |
|
2494 | derPhase = numpy.nanmean(numpy.abs(phase[:,1:,:] - phase[:,:-1,:]),axis=0) | |
2495 | boolMet2 = derPhase < 0.2 |
|
2495 | boolMet2 = derPhase < 0.2 | |
2496 | # boolMet2 = ndimage.morphology.binary_opening(boolMet2) |
|
2496 | # boolMet2 = ndimage.morphology.binary_opening(boolMet2) | |
2497 | # boolMet2 = ndimage.morphology.binary_closing(boolMet2, structure = numpy.ones((10,1))) |
|
2497 | # boolMet2 = ndimage.morphology.binary_closing(boolMet2, structure = numpy.ones((10,1))) | |
2498 | boolMet2 = ndimage.median_filter(boolMet2,size=5) |
|
2498 | boolMet2 = ndimage.median_filter(boolMet2,size=5) | |
2499 | boolMet2 = numpy.vstack((boolMet2,numpy.full((1,nHeights), True, dtype=bool))) |
|
2499 | boolMet2 = numpy.vstack((boolMet2,numpy.full((1,nHeights), True, dtype=bool))) | |
2500 | # #Final mask |
|
2500 | # #Final mask | |
2501 | # boolMetFin = boolMet2 |
|
2501 | # boolMetFin = boolMet2 | |
2502 | boolMetFin = boolMet1&boolMet2 |
|
2502 | boolMetFin = boolMet1&boolMet2 | |
2503 | # boolMetFin = ndimage.morphology.binary_dilation(boolMetFin) |
|
2503 | # boolMetFin = ndimage.morphology.binary_dilation(boolMetFin) | |
2504 | #Creating data_param |
|
2504 | #Creating data_param | |
2505 | coordMet = numpy.where(boolMetFin) |
|
2505 | coordMet = numpy.where(boolMetFin) | |
2506 |
|
2506 | |||
2507 | tmet = coordMet[0] |
|
2507 | tmet = coordMet[0] | |
2508 | hmet = coordMet[1] |
|
2508 | hmet = coordMet[1] | |
2509 |
|
2509 | |||
2510 | data_param = numpy.zeros((tmet.size, 6 + nPairs)) |
|
2510 | data_param = numpy.zeros((tmet.size, 6 + nPairs)) | |
2511 | data_param[:,0] = utctime |
|
2511 | data_param[:,0] = utctime | |
2512 | data_param[:,1] = tmet |
|
2512 | data_param[:,1] = tmet | |
2513 | data_param[:,2] = hmet |
|
2513 | data_param[:,2] = hmet | |
2514 | data_param[:,3] = SNRm[tmet,hmet] |
|
2514 | data_param[:,3] = SNRm[tmet,hmet] | |
2515 | data_param[:,4] = velRad[tmet,hmet] |
|
2515 | data_param[:,4] = velRad[tmet,hmet] | |
2516 | data_param[:,5] = coh[tmet,hmet] |
|
2516 | data_param[:,5] = coh[tmet,hmet] | |
2517 | data_param[:,6:] = phase[:,tmet,hmet].T |
|
2517 | data_param[:,6:] = phase[:,tmet,hmet].T | |
2518 |
|
2518 | |||
2519 | elif mode == 'DBS': |
|
2519 | elif mode == 'DBS': | |
2520 | dataOut.groupList = numpy.arange(nChannels) |
|
2520 | dataOut.groupList = numpy.arange(nChannels) | |
2521 |
|
2521 | |||
2522 | #Radial Velocities |
|
2522 | #Radial Velocities | |
2523 | phase = numpy.angle(data_acf[:,1,:,:]) |
|
2523 | phase = numpy.angle(data_acf[:,1,:,:]) | |
2524 | # phase = ndimage.median_filter(numpy.angle(data_acf[:,1,:,:]), size = (1,5,1)) |
|
2524 | # phase = ndimage.median_filter(numpy.angle(data_acf[:,1,:,:]), size = (1,5,1)) | |
2525 | velRad = phase*lamb/(4*numpy.pi*tSamp) |
|
2525 | velRad = phase*lamb/(4*numpy.pi*tSamp) | |
2526 |
|
2526 | |||
2527 | #Spectral width |
|
2527 | #Spectral width | |
2528 | # acf1 = ndimage.median_filter(numpy.abs(data_acf[:,1,:,:]), size = (1,5,1)) |
|
2528 | # acf1 = ndimage.median_filter(numpy.abs(data_acf[:,1,:,:]), size = (1,5,1)) | |
2529 | # acf2 = ndimage.median_filter(numpy.abs(data_acf[:,2,:,:]), size = (1,5,1)) |
|
2529 | # acf2 = ndimage.median_filter(numpy.abs(data_acf[:,2,:,:]), size = (1,5,1)) | |
2530 | acf1 = data_acf[:,1,:,:] |
|
2530 | acf1 = data_acf[:,1,:,:] | |
2531 | acf2 = data_acf[:,2,:,:] |
|
2531 | acf2 = data_acf[:,2,:,:] | |
2532 |
|
2532 | |||
2533 | spcWidth = (lamb/(2*numpy.sqrt(6)*numpy.pi*tSamp))*numpy.sqrt(numpy.log(acf1/acf2)) |
|
2533 | spcWidth = (lamb/(2*numpy.sqrt(6)*numpy.pi*tSamp))*numpy.sqrt(numpy.log(acf1/acf2)) | |
2534 | # velRad = ndimage.median_filter(velRad, size = (1,5,1)) |
|
2534 | # velRad = ndimage.median_filter(velRad, size = (1,5,1)) | |
2535 | if allData: |
|
2535 | if allData: | |
2536 | boolMetFin = ~numpy.isnan(SNRdB) |
|
2536 | boolMetFin = ~numpy.isnan(SNRdB) | |
2537 | else: |
|
2537 | else: | |
2538 | #SNR |
|
2538 | #SNR | |
2539 | boolMet1 = (SNRdB>SNRthresh) #SNR mask |
|
2539 | boolMet1 = (SNRdB>SNRthresh) #SNR mask | |
2540 | boolMet1 = ndimage.median_filter(boolMet1, size=(1,5,5)) |
|
2540 | boolMet1 = ndimage.median_filter(boolMet1, size=(1,5,5)) | |
2541 |
|
2541 | |||
2542 | #Radial velocity |
|
2542 | #Radial velocity | |
2543 | boolMet2 = numpy.abs(velRad) < 20 |
|
2543 | boolMet2 = numpy.abs(velRad) < 20 | |
2544 | boolMet2 = ndimage.median_filter(boolMet2, (1,5,5)) |
|
2544 | boolMet2 = ndimage.median_filter(boolMet2, (1,5,5)) | |
2545 |
|
2545 | |||
2546 | #Spectral Width |
|
2546 | #Spectral Width | |
2547 | boolMet3 = spcWidth < 30 |
|
2547 | boolMet3 = spcWidth < 30 | |
2548 | boolMet3 = ndimage.median_filter(boolMet3, (1,5,5)) |
|
2548 | boolMet3 = ndimage.median_filter(boolMet3, (1,5,5)) | |
2549 | # boolMetFin = self.__erase_small(boolMet1, 10,5) |
|
2549 | # boolMetFin = self.__erase_small(boolMet1, 10,5) | |
2550 | boolMetFin = boolMet1&boolMet2&boolMet3 |
|
2550 | boolMetFin = boolMet1&boolMet2&boolMet3 | |
2551 |
|
2551 | |||
2552 | #Creating data_param |
|
2552 | #Creating data_param | |
2553 | coordMet = numpy.where(boolMetFin) |
|
2553 | coordMet = numpy.where(boolMetFin) | |
2554 |
|
2554 | |||
2555 | cmet = coordMet[0] |
|
2555 | cmet = coordMet[0] | |
2556 | tmet = coordMet[1] |
|
2556 | tmet = coordMet[1] | |
2557 | hmet = coordMet[2] |
|
2557 | hmet = coordMet[2] | |
2558 |
|
2558 | |||
2559 | data_param = numpy.zeros((tmet.size, 7)) |
|
2559 | data_param = numpy.zeros((tmet.size, 7)) | |
2560 | data_param[:,0] = utctime |
|
2560 | data_param[:,0] = utctime | |
2561 | data_param[:,1] = cmet |
|
2561 | data_param[:,1] = cmet | |
2562 | data_param[:,2] = tmet |
|
2562 | data_param[:,2] = tmet | |
2563 | data_param[:,3] = hmet |
|
2563 | data_param[:,3] = hmet | |
2564 | data_param[:,4] = SNR[cmet,tmet,hmet].T |
|
2564 | data_param[:,4] = SNR[cmet,tmet,hmet].T | |
2565 | data_param[:,5] = velRad[cmet,tmet,hmet].T |
|
2565 | data_param[:,5] = velRad[cmet,tmet,hmet].T | |
2566 | data_param[:,6] = spcWidth[cmet,tmet,hmet].T |
|
2566 | data_param[:,6] = spcWidth[cmet,tmet,hmet].T | |
2567 |
|
2567 | |||
2568 | # self.dataOut.data_param = data_int |
|
2568 | # self.dataOut.data_param = data_int | |
2569 | if len(data_param) == 0: |
|
2569 | if len(data_param) == 0: | |
2570 | dataOut.flagNoData = True |
|
2570 | dataOut.flagNoData = True | |
2571 | else: |
|
2571 | else: | |
2572 | dataOut.data_param = data_param |
|
2572 | dataOut.data_param = data_param | |
2573 |
|
2573 | |||
2574 | def __erase_small(self, binArray, threshX, threshY): |
|
2574 | def __erase_small(self, binArray, threshX, threshY): | |
2575 | labarray, numfeat = ndimage.measurements.label(binArray) |
|
2575 | labarray, numfeat = ndimage.measurements.label(binArray) | |
2576 | binArray1 = numpy.copy(binArray) |
|
2576 | binArray1 = numpy.copy(binArray) | |
2577 |
|
2577 | |||
2578 | for i in range(1,numfeat + 1): |
|
2578 | for i in range(1,numfeat + 1): | |
2579 | auxBin = (labarray==i) |
|
2579 | auxBin = (labarray==i) | |
2580 | auxSize = auxBin.sum() |
|
2580 | auxSize = auxBin.sum() | |
2581 |
|
2581 | |||
2582 | x,y = numpy.where(auxBin) |
|
2582 | x,y = numpy.where(auxBin) | |
2583 | widthX = x.max() - x.min() |
|
2583 | widthX = x.max() - x.min() | |
2584 | widthY = y.max() - y.min() |
|
2584 | widthY = y.max() - y.min() | |
2585 |
|
2585 | |||
2586 | #width X: 3 seg -> 12.5*3 |
|
2586 | #width X: 3 seg -> 12.5*3 | |
2587 | #width Y: |
|
2587 | #width Y: | |
2588 |
|
2588 | |||
2589 | if (auxSize < 50) or (widthX < threshX) or (widthY < threshY): |
|
2589 | if (auxSize < 50) or (widthX < threshX) or (widthY < threshY): | |
2590 | binArray1[auxBin] = False |
|
2590 | binArray1[auxBin] = False | |
2591 |
|
2591 | |||
2592 | return binArray1 |
|
2592 | return binArray1 | |
2593 |
|
2593 | |||
2594 | #--------------- Specular Meteor ---------------- |
|
2594 | #--------------- Specular Meteor ---------------- | |
2595 |
|
2595 | |||
2596 | class SMDetection(Operation): |
|
2596 | class SMDetection(Operation): | |
2597 | ''' |
|
2597 | ''' | |
2598 | Function DetectMeteors() |
|
2598 | Function DetectMeteors() | |
2599 | Project developed with paper: |
|
2599 | Project developed with paper: | |
2600 | HOLDSWORTH ET AL. 2004 |
|
2600 | HOLDSWORTH ET AL. 2004 | |
2601 |
|
2601 | |||
2602 | Input: |
|
2602 | Input: | |
2603 | self.dataOut.data_pre |
|
2603 | self.dataOut.data_pre | |
2604 |
|
2604 | |||
2605 | centerReceiverIndex: From the channels, which is the center receiver |
|
2605 | centerReceiverIndex: From the channels, which is the center receiver | |
2606 |
|
2606 | |||
2607 | hei_ref: Height reference for the Beacon signal extraction |
|
2607 | hei_ref: Height reference for the Beacon signal extraction | |
2608 | tauindex: |
|
2608 | tauindex: | |
2609 | predefinedPhaseShifts: Predefined phase offset for the voltge signals |
|
2609 | predefinedPhaseShifts: Predefined phase offset for the voltge signals | |
2610 |
|
2610 | |||
2611 | cohDetection: Whether to user Coherent detection or not |
|
2611 | cohDetection: Whether to user Coherent detection or not | |
2612 | cohDet_timeStep: Coherent Detection calculation time step |
|
2612 | cohDet_timeStep: Coherent Detection calculation time step | |
2613 | cohDet_thresh: Coherent Detection phase threshold to correct phases |
|
2613 | cohDet_thresh: Coherent Detection phase threshold to correct phases | |
2614 |
|
2614 | |||
2615 | noise_timeStep: Noise calculation time step |
|
2615 | noise_timeStep: Noise calculation time step | |
2616 | noise_multiple: Noise multiple to define signal threshold |
|
2616 | noise_multiple: Noise multiple to define signal threshold | |
2617 |
|
2617 | |||
2618 | multDet_timeLimit: Multiple Detection Removal time limit in seconds |
|
2618 | multDet_timeLimit: Multiple Detection Removal time limit in seconds | |
2619 | multDet_rangeLimit: Multiple Detection Removal range limit in km |
|
2619 | multDet_rangeLimit: Multiple Detection Removal range limit in km | |
2620 |
|
2620 | |||
2621 | phaseThresh: Maximum phase difference between receiver to be consider a meteor |
|
2621 | phaseThresh: Maximum phase difference between receiver to be consider a meteor | |
2622 | SNRThresh: Minimum SNR threshold of the meteor signal to be consider a meteor |
|
2622 | SNRThresh: Minimum SNR threshold of the meteor signal to be consider a meteor | |
2623 |
|
2623 | |||
2624 | hmin: Minimum Height of the meteor to use it in the further wind estimations |
|
2624 | hmin: Minimum Height of the meteor to use it in the further wind estimations | |
2625 | hmax: Maximum Height of the meteor to use it in the further wind estimations |
|
2625 | hmax: Maximum Height of the meteor to use it in the further wind estimations | |
2626 | azimuth: Azimuth angle correction |
|
2626 | azimuth: Azimuth angle correction | |
2627 |
|
2627 | |||
2628 | Affected: |
|
2628 | Affected: | |
2629 | self.dataOut.data_param |
|
2629 | self.dataOut.data_param | |
2630 |
|
2630 | |||
2631 | Rejection Criteria (Errors): |
|
2631 | Rejection Criteria (Errors): | |
2632 | 0: No error; analysis OK |
|
2632 | 0: No error; analysis OK | |
2633 | 1: SNR < SNR threshold |
|
2633 | 1: SNR < SNR threshold | |
2634 | 2: angle of arrival (AOA) ambiguously determined |
|
2634 | 2: angle of arrival (AOA) ambiguously determined | |
2635 | 3: AOA estimate not feasible |
|
2635 | 3: AOA estimate not feasible | |
2636 | 4: Large difference in AOAs obtained from different antenna baselines |
|
2636 | 4: Large difference in AOAs obtained from different antenna baselines | |
2637 | 5: echo at start or end of time series |
|
2637 | 5: echo at start or end of time series | |
2638 | 6: echo less than 5 examples long; too short for analysis |
|
2638 | 6: echo less than 5 examples long; too short for analysis | |
2639 | 7: echo rise exceeds 0.3s |
|
2639 | 7: echo rise exceeds 0.3s | |
2640 | 8: echo decay time less than twice rise time |
|
2640 | 8: echo decay time less than twice rise time | |
2641 | 9: large power level before echo |
|
2641 | 9: large power level before echo | |
2642 | 10: large power level after echo |
|
2642 | 10: large power level after echo | |
2643 | 11: poor fit to amplitude for estimation of decay time |
|
2643 | 11: poor fit to amplitude for estimation of decay time | |
2644 | 12: poor fit to CCF phase variation for estimation of radial drift velocity |
|
2644 | 12: poor fit to CCF phase variation for estimation of radial drift velocity | |
2645 | 13: height unresolvable echo: not valid height within 70 to 110 km |
|
2645 | 13: height unresolvable echo: not valid height within 70 to 110 km | |
2646 | 14: height ambiguous echo: more then one possible height within 70 to 110 km |
|
2646 | 14: height ambiguous echo: more then one possible height within 70 to 110 km | |
2647 | 15: radial drift velocity or projected horizontal velocity exceeds 200 m/s |
|
2647 | 15: radial drift velocity or projected horizontal velocity exceeds 200 m/s | |
2648 | 16: oscilatory echo, indicating event most likely not an underdense echo |
|
2648 | 16: oscilatory echo, indicating event most likely not an underdense echo | |
2649 |
|
2649 | |||
2650 | 17: phase difference in meteor Reestimation |
|
2650 | 17: phase difference in meteor Reestimation | |
2651 |
|
2651 | |||
2652 | Data Storage: |
|
2652 | Data Storage: | |
2653 | Meteors for Wind Estimation (8): |
|
2653 | Meteors for Wind Estimation (8): | |
2654 | Utc Time | Range Height |
|
2654 | Utc Time | Range Height | |
2655 | Azimuth Zenith errorCosDir |
|
2655 | Azimuth Zenith errorCosDir | |
2656 | VelRad errorVelRad |
|
2656 | VelRad errorVelRad | |
2657 | Phase0 Phase1 Phase2 Phase3 |
|
2657 | Phase0 Phase1 Phase2 Phase3 | |
2658 | TypeError |
|
2658 | TypeError | |
2659 |
|
2659 | |||
2660 | ''' |
|
2660 | ''' | |
2661 |
|
2661 | |||
2662 | def run(self, dataOut, hei_ref = None, tauindex = 0, |
|
2662 | def run(self, dataOut, hei_ref = None, tauindex = 0, | |
2663 | phaseOffsets = None, |
|
2663 | phaseOffsets = None, | |
2664 | cohDetection = False, cohDet_timeStep = 1, cohDet_thresh = 25, |
|
2664 | cohDetection = False, cohDet_timeStep = 1, cohDet_thresh = 25, | |
2665 | noise_timeStep = 4, noise_multiple = 4, |
|
2665 | noise_timeStep = 4, noise_multiple = 4, | |
2666 | multDet_timeLimit = 1, multDet_rangeLimit = 3, |
|
2666 | multDet_timeLimit = 1, multDet_rangeLimit = 3, | |
2667 | phaseThresh = 20, SNRThresh = 5, |
|
2667 | phaseThresh = 20, SNRThresh = 5, | |
2668 | hmin = 50, hmax=150, azimuth = 0, |
|
2668 | hmin = 50, hmax=150, azimuth = 0, | |
2669 | channelPositions = None) : |
|
2669 | channelPositions = None) : | |
2670 |
|
2670 | |||
2671 |
|
2671 | |||
2672 | #Getting Pairslist |
|
2672 | #Getting Pairslist | |
2673 | if channelPositions is None: |
|
2673 | if channelPositions is None: | |
2674 | # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T |
|
2674 | # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T | |
2675 | channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella |
|
2675 | channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella | |
2676 | meteorOps = SMOperations() |
|
2676 | meteorOps = SMOperations() | |
2677 | pairslist0, distances = meteorOps.getPhasePairs(channelPositions) |
|
2677 | pairslist0, distances = meteorOps.getPhasePairs(channelPositions) | |
2678 | heiRang = dataOut.heightList |
|
2678 | heiRang = dataOut.heightList | |
2679 | #Get Beacon signal - No Beacon signal anymore |
|
2679 | #Get Beacon signal - No Beacon signal anymore | |
2680 | # newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex]) |
|
2680 | # newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex]) | |
2681 | # |
|
2681 | # | |
2682 | # if hei_ref != None: |
|
2682 | # if hei_ref != None: | |
2683 | # newheis = numpy.where(self.dataOut.heightList>hei_ref) |
|
2683 | # newheis = numpy.where(self.dataOut.heightList>hei_ref) | |
2684 | # |
|
2684 | # | |
2685 |
|
2685 | |||
2686 |
|
2686 | |||
2687 | #****************REMOVING HARDWARE PHASE DIFFERENCES*************** |
|
2687 | #****************REMOVING HARDWARE PHASE DIFFERENCES*************** | |
2688 | # see if the user put in pre defined phase shifts |
|
2688 | # see if the user put in pre defined phase shifts | |
2689 | voltsPShift = dataOut.data_pre.copy() |
|
2689 | voltsPShift = dataOut.data_pre.copy() | |
2690 |
|
2690 | |||
2691 | # if predefinedPhaseShifts != None: |
|
2691 | # if predefinedPhaseShifts != None: | |
2692 | # hardwarePhaseShifts = numpy.array(predefinedPhaseShifts)*numpy.pi/180 |
|
2692 | # hardwarePhaseShifts = numpy.array(predefinedPhaseShifts)*numpy.pi/180 | |
2693 | # |
|
2693 | # | |
2694 | # # elif beaconPhaseShifts: |
|
2694 | # # elif beaconPhaseShifts: | |
2695 | # # #get hardware phase shifts using beacon signal |
|
2695 | # # #get hardware phase shifts using beacon signal | |
2696 | # # hardwarePhaseShifts = self.__getHardwarePhaseDiff(self.dataOut.data_pre, pairslist, newheis, 10) |
|
2696 | # # hardwarePhaseShifts = self.__getHardwarePhaseDiff(self.dataOut.data_pre, pairslist, newheis, 10) | |
2697 | # # hardwarePhaseShifts = numpy.insert(hardwarePhaseShifts,centerReceiverIndex,0) |
|
2697 | # # hardwarePhaseShifts = numpy.insert(hardwarePhaseShifts,centerReceiverIndex,0) | |
2698 | # |
|
2698 | # | |
2699 | # else: |
|
2699 | # else: | |
2700 | # hardwarePhaseShifts = numpy.zeros(5) |
|
2700 | # hardwarePhaseShifts = numpy.zeros(5) | |
2701 | # |
|
2701 | # | |
2702 | # voltsPShift = numpy.zeros((self.dataOut.data_pre.shape[0],self.dataOut.data_pre.shape[1],self.dataOut.data_pre.shape[2]), dtype = 'complex') |
|
2702 | # voltsPShift = numpy.zeros((self.dataOut.data_pre.shape[0],self.dataOut.data_pre.shape[1],self.dataOut.data_pre.shape[2]), dtype = 'complex') | |
2703 | # for i in range(self.dataOut.data_pre.shape[0]): |
|
2703 | # for i in range(self.dataOut.data_pre.shape[0]): | |
2704 | # voltsPShift[i,:,:] = self.__shiftPhase(self.dataOut.data_pre[i,:,:], hardwarePhaseShifts[i]) |
|
2704 | # voltsPShift[i,:,:] = self.__shiftPhase(self.dataOut.data_pre[i,:,:], hardwarePhaseShifts[i]) | |
2705 |
|
2705 | |||
2706 | #******************END OF REMOVING HARDWARE PHASE DIFFERENCES********* |
|
2706 | #******************END OF REMOVING HARDWARE PHASE DIFFERENCES********* | |
2707 |
|
2707 | |||
2708 | #Remove DC |
|
2708 | #Remove DC | |
2709 | voltsDC = numpy.mean(voltsPShift,1) |
|
2709 | voltsDC = numpy.mean(voltsPShift,1) | |
2710 | voltsDC = numpy.mean(voltsDC,1) |
|
2710 | voltsDC = numpy.mean(voltsDC,1) | |
2711 | for i in range(voltsDC.shape[0]): |
|
2711 | for i in range(voltsDC.shape[0]): | |
2712 | voltsPShift[i] = voltsPShift[i] - voltsDC[i] |
|
2712 | voltsPShift[i] = voltsPShift[i] - voltsDC[i] | |
2713 |
|
2713 | |||
2714 | #Don't considerate last heights, theyre used to calculate Hardware Phase Shift |
|
2714 | #Don't considerate last heights, theyre used to calculate Hardware Phase Shift | |
2715 | # voltsPShift = voltsPShift[:,:,:newheis[0][0]] |
|
2715 | # voltsPShift = voltsPShift[:,:,:newheis[0][0]] | |
2716 |
|
2716 | |||
2717 | #************ FIND POWER OF DATA W/COH OR NON COH DETECTION (3.4) ********** |
|
2717 | #************ FIND POWER OF DATA W/COH OR NON COH DETECTION (3.4) ********** | |
2718 | #Coherent Detection |
|
2718 | #Coherent Detection | |
2719 | if cohDetection: |
|
2719 | if cohDetection: | |
2720 | #use coherent detection to get the net power |
|
2720 | #use coherent detection to get the net power | |
2721 | cohDet_thresh = cohDet_thresh*numpy.pi/180 |
|
2721 | cohDet_thresh = cohDet_thresh*numpy.pi/180 | |
2722 | voltsPShift = self.__coherentDetection(voltsPShift, cohDet_timeStep, dataOut.timeInterval, pairslist0, cohDet_thresh) |
|
2722 | voltsPShift = self.__coherentDetection(voltsPShift, cohDet_timeStep, dataOut.timeInterval, pairslist0, cohDet_thresh) | |
2723 |
|
2723 | |||
2724 | #Non-coherent detection! |
|
2724 | #Non-coherent detection! | |
2725 | powerNet = numpy.nansum(numpy.abs(voltsPShift[:,:,:])**2,0) |
|
2725 | powerNet = numpy.nansum(numpy.abs(voltsPShift[:,:,:])**2,0) | |
2726 | #********** END OF COH/NON-COH POWER CALCULATION********************** |
|
2726 | #********** END OF COH/NON-COH POWER CALCULATION********************** | |
2727 |
|
2727 | |||
2728 | #********** FIND THE NOISE LEVEL AND POSSIBLE METEORS **************** |
|
2728 | #********** FIND THE NOISE LEVEL AND POSSIBLE METEORS **************** | |
2729 | #Get noise |
|
2729 | #Get noise | |
2730 | noise, noise1 = self.__getNoise(powerNet, noise_timeStep, dataOut.timeInterval) |
|
2730 | noise, noise1 = self.__getNoise(powerNet, noise_timeStep, dataOut.timeInterval) | |
2731 | # noise = self.getNoise1(powerNet, noise_timeStep, self.dataOut.timeInterval) |
|
2731 | # noise = self.getNoise1(powerNet, noise_timeStep, self.dataOut.timeInterval) | |
2732 | #Get signal threshold |
|
2732 | #Get signal threshold | |
2733 | signalThresh = noise_multiple*noise |
|
2733 | signalThresh = noise_multiple*noise | |
2734 | #Meteor echoes detection |
|
2734 | #Meteor echoes detection | |
2735 | listMeteors = self.__findMeteors(powerNet, signalThresh) |
|
2735 | listMeteors = self.__findMeteors(powerNet, signalThresh) | |
2736 | #******* END OF NOISE LEVEL AND POSSIBLE METEORS CACULATION ********** |
|
2736 | #******* END OF NOISE LEVEL AND POSSIBLE METEORS CACULATION ********** | |
2737 |
|
2737 | |||
2738 | #************** REMOVE MULTIPLE DETECTIONS (3.5) *************************** |
|
2738 | #************** REMOVE MULTIPLE DETECTIONS (3.5) *************************** | |
2739 | #Parameters |
|
2739 | #Parameters | |
2740 | heiRange = dataOut.heightList |
|
2740 | heiRange = dataOut.heightList | |
2741 | rangeInterval = heiRange[1] - heiRange[0] |
|
2741 | rangeInterval = heiRange[1] - heiRange[0] | |
2742 | rangeLimit = multDet_rangeLimit/rangeInterval |
|
2742 | rangeLimit = multDet_rangeLimit/rangeInterval | |
2743 | timeLimit = multDet_timeLimit/dataOut.timeInterval |
|
2743 | timeLimit = multDet_timeLimit/dataOut.timeInterval | |
2744 | #Multiple detection removals |
|
2744 | #Multiple detection removals | |
2745 | listMeteors1 = self.__removeMultipleDetections(listMeteors, rangeLimit, timeLimit) |
|
2745 | listMeteors1 = self.__removeMultipleDetections(listMeteors, rangeLimit, timeLimit) | |
2746 | #************ END OF REMOVE MULTIPLE DETECTIONS ********************** |
|
2746 | #************ END OF REMOVE MULTIPLE DETECTIONS ********************** | |
2747 |
|
2747 | |||
2748 | #********************* METEOR REESTIMATION (3.7, 3.8, 3.9, 3.10) ******************** |
|
2748 | #********************* METEOR REESTIMATION (3.7, 3.8, 3.9, 3.10) ******************** | |
2749 | #Parameters |
|
2749 | #Parameters | |
2750 | phaseThresh = phaseThresh*numpy.pi/180 |
|
2750 | phaseThresh = phaseThresh*numpy.pi/180 | |
2751 | thresh = [phaseThresh, noise_multiple, SNRThresh] |
|
2751 | thresh = [phaseThresh, noise_multiple, SNRThresh] | |
2752 | #Meteor reestimation (Errors N 1, 6, 12, 17) |
|
2752 | #Meteor reestimation (Errors N 1, 6, 12, 17) | |
2753 | listMeteors2, listMeteorsPower, listMeteorsVolts = self.__meteorReestimation(listMeteors1, voltsPShift, pairslist0, thresh, noise, dataOut.timeInterval, dataOut.frequency) |
|
2753 | listMeteors2, listMeteorsPower, listMeteorsVolts = self.__meteorReestimation(listMeteors1, voltsPShift, pairslist0, thresh, noise, dataOut.timeInterval, dataOut.frequency) | |
2754 | # listMeteors2, listMeteorsPower, listMeteorsVolts = self.meteorReestimation3(listMeteors2, listMeteorsPower, listMeteorsVolts, voltsPShift, pairslist, thresh, noise) |
|
2754 | # listMeteors2, listMeteorsPower, listMeteorsVolts = self.meteorReestimation3(listMeteors2, listMeteorsPower, listMeteorsVolts, voltsPShift, pairslist, thresh, noise) | |
2755 | #Estimation of decay times (Errors N 7, 8, 11) |
|
2755 | #Estimation of decay times (Errors N 7, 8, 11) | |
2756 | listMeteors3 = self.__estimateDecayTime(listMeteors2, listMeteorsPower, dataOut.timeInterval, dataOut.frequency) |
|
2756 | listMeteors3 = self.__estimateDecayTime(listMeteors2, listMeteorsPower, dataOut.timeInterval, dataOut.frequency) | |
2757 | #******************* END OF METEOR REESTIMATION ******************* |
|
2757 | #******************* END OF METEOR REESTIMATION ******************* | |
2758 |
|
2758 | |||
2759 | #********************* METEOR PARAMETERS CALCULATION (3.11, 3.12, 3.13) ************************** |
|
2759 | #********************* METEOR PARAMETERS CALCULATION (3.11, 3.12, 3.13) ************************** | |
2760 | #Calculating Radial Velocity (Error N 15) |
|
2760 | #Calculating Radial Velocity (Error N 15) | |
2761 | radialStdThresh = 10 |
|
2761 | radialStdThresh = 10 | |
2762 | listMeteors4 = self.__getRadialVelocity(listMeteors3, listMeteorsVolts, radialStdThresh, pairslist0, dataOut.timeInterval) |
|
2762 | listMeteors4 = self.__getRadialVelocity(listMeteors3, listMeteorsVolts, radialStdThresh, pairslist0, dataOut.timeInterval) | |
2763 |
|
2763 | |||
2764 | if len(listMeteors4) > 0: |
|
2764 | if len(listMeteors4) > 0: | |
2765 | #Setting New Array |
|
2765 | #Setting New Array | |
2766 | date = dataOut.utctime |
|
2766 | date = dataOut.utctime | |
2767 | arrayParameters = self.__setNewArrays(listMeteors4, date, heiRang) |
|
2767 | arrayParameters = self.__setNewArrays(listMeteors4, date, heiRang) | |
2768 |
|
2768 | |||
2769 | #Correcting phase offset |
|
2769 | #Correcting phase offset | |
2770 | if phaseOffsets != None: |
|
2770 | if phaseOffsets != None: | |
2771 | phaseOffsets = numpy.array(phaseOffsets)*numpy.pi/180 |
|
2771 | phaseOffsets = numpy.array(phaseOffsets)*numpy.pi/180 | |
2772 | arrayParameters[:,8:12] = numpy.unwrap(arrayParameters[:,8:12] + phaseOffsets) |
|
2772 | arrayParameters[:,8:12] = numpy.unwrap(arrayParameters[:,8:12] + phaseOffsets) | |
2773 |
|
2773 | |||
2774 | #Second Pairslist |
|
2774 | #Second Pairslist | |
2775 | pairsList = [] |
|
2775 | pairsList = [] | |
2776 | pairx = (0,1) |
|
2776 | pairx = (0,1) | |
2777 | pairy = (2,3) |
|
2777 | pairy = (2,3) | |
2778 | pairsList.append(pairx) |
|
2778 | pairsList.append(pairx) | |
2779 | pairsList.append(pairy) |
|
2779 | pairsList.append(pairy) | |
2780 |
|
2780 | |||
2781 | jph = numpy.array([0,0,0,0]) |
|
2781 | jph = numpy.array([0,0,0,0]) | |
2782 | h = (hmin,hmax) |
|
2782 | h = (hmin,hmax) | |
2783 | arrayParameters = meteorOps.getMeteorParams(arrayParameters, azimuth, h, pairsList, distances, jph) |
|
2783 | arrayParameters = meteorOps.getMeteorParams(arrayParameters, azimuth, h, pairsList, distances, jph) | |
2784 |
|
2784 | |||
2785 | # #Calculate AOA (Error N 3, 4) |
|
2785 | # #Calculate AOA (Error N 3, 4) | |
2786 | # #JONES ET AL. 1998 |
|
2786 | # #JONES ET AL. 1998 | |
2787 | # error = arrayParameters[:,-1] |
|
2787 | # error = arrayParameters[:,-1] | |
2788 | # AOAthresh = numpy.pi/8 |
|
2788 | # AOAthresh = numpy.pi/8 | |
2789 | # phases = -arrayParameters[:,9:13] |
|
2789 | # phases = -arrayParameters[:,9:13] | |
2790 | # arrayParameters[:,4:7], arrayParameters[:,-1] = meteorOps.getAOA(phases, pairsList, error, AOAthresh, azimuth) |
|
2790 | # arrayParameters[:,4:7], arrayParameters[:,-1] = meteorOps.getAOA(phases, pairsList, error, AOAthresh, azimuth) | |
2791 | # |
|
2791 | # | |
2792 | # #Calculate Heights (Error N 13 and 14) |
|
2792 | # #Calculate Heights (Error N 13 and 14) | |
2793 | # error = arrayParameters[:,-1] |
|
2793 | # error = arrayParameters[:,-1] | |
2794 | # Ranges = arrayParameters[:,2] |
|
2794 | # Ranges = arrayParameters[:,2] | |
2795 | # zenith = arrayParameters[:,5] |
|
2795 | # zenith = arrayParameters[:,5] | |
2796 | # arrayParameters[:,3], arrayParameters[:,-1] = meteorOps.getHeights(Ranges, zenith, error, hmin, hmax) |
|
2796 | # arrayParameters[:,3], arrayParameters[:,-1] = meteorOps.getHeights(Ranges, zenith, error, hmin, hmax) | |
2797 | # error = arrayParameters[:,-1] |
|
2797 | # error = arrayParameters[:,-1] | |
2798 | #********************* END OF PARAMETERS CALCULATION ************************** |
|
2798 | #********************* END OF PARAMETERS CALCULATION ************************** | |
2799 |
|
2799 | |||
2800 | #***************************+ PASS DATA TO NEXT STEP ********************** |
|
2800 | #***************************+ PASS DATA TO NEXT STEP ********************** | |
2801 | # arrayFinal = arrayParameters.reshape((1,arrayParameters.shape[0],arrayParameters.shape[1])) |
|
2801 | # arrayFinal = arrayParameters.reshape((1,arrayParameters.shape[0],arrayParameters.shape[1])) | |
2802 | dataOut.data_param = arrayParameters |
|
2802 | dataOut.data_param = arrayParameters | |
2803 |
|
2803 | |||
2804 | if arrayParameters is None: |
|
2804 | if arrayParameters is None: | |
2805 | dataOut.flagNoData = True |
|
2805 | dataOut.flagNoData = True | |
2806 | else: |
|
2806 | else: | |
2807 | dataOut.flagNoData = True |
|
2807 | dataOut.flagNoData = True | |
2808 |
|
2808 | |||
2809 | return |
|
2809 | return | |
2810 |
|
2810 | |||
2811 | def __getHardwarePhaseDiff(self, voltage0, pairslist, newheis, n): |
|
2811 | def __getHardwarePhaseDiff(self, voltage0, pairslist, newheis, n): | |
2812 |
|
2812 | |||
2813 | minIndex = min(newheis[0]) |
|
2813 | minIndex = min(newheis[0]) | |
2814 | maxIndex = max(newheis[0]) |
|
2814 | maxIndex = max(newheis[0]) | |
2815 |
|
2815 | |||
2816 | voltage = voltage0[:,:,minIndex:maxIndex+1] |
|
2816 | voltage = voltage0[:,:,minIndex:maxIndex+1] | |
2817 | nLength = voltage.shape[1]/n |
|
2817 | nLength = voltage.shape[1]/n | |
2818 | nMin = 0 |
|
2818 | nMin = 0 | |
2819 | nMax = 0 |
|
2819 | nMax = 0 | |
2820 | phaseOffset = numpy.zeros((len(pairslist),n)) |
|
2820 | phaseOffset = numpy.zeros((len(pairslist),n)) | |
2821 |
|
2821 | |||
2822 | for i in range(n): |
|
2822 | for i in range(n): | |
2823 | nMax += nLength |
|
2823 | nMax += nLength | |
2824 | phaseCCF = -numpy.angle(self.__calculateCCF(voltage[:,nMin:nMax,:], pairslist, [0])) |
|
2824 | phaseCCF = -numpy.angle(self.__calculateCCF(voltage[:,nMin:nMax,:], pairslist, [0])) | |
2825 | phaseCCF = numpy.mean(phaseCCF, axis = 2) |
|
2825 | phaseCCF = numpy.mean(phaseCCF, axis = 2) | |
2826 | phaseOffset[:,i] = phaseCCF.transpose() |
|
2826 | phaseOffset[:,i] = phaseCCF.transpose() | |
2827 | nMin = nMax |
|
2827 | nMin = nMax | |
2828 | # phaseDiff, phaseArrival = self.estimatePhaseDifference(voltage, pairslist) |
|
2828 | # phaseDiff, phaseArrival = self.estimatePhaseDifference(voltage, pairslist) | |
2829 |
|
2829 | |||
2830 | #Remove Outliers |
|
2830 | #Remove Outliers | |
2831 | factor = 2 |
|
2831 | factor = 2 | |
2832 | wt = phaseOffset - signal.medfilt(phaseOffset,(1,5)) |
|
2832 | wt = phaseOffset - signal.medfilt(phaseOffset,(1,5)) | |
2833 | dw = numpy.std(wt,axis = 1) |
|
2833 | dw = numpy.std(wt,axis = 1) | |
2834 | dw = dw.reshape((dw.size,1)) |
|
2834 | dw = dw.reshape((dw.size,1)) | |
2835 | ind = numpy.where(numpy.logical_or(wt>dw*factor,wt<-dw*factor)) |
|
2835 | ind = numpy.where(numpy.logical_or(wt>dw*factor,wt<-dw*factor)) | |
2836 | phaseOffset[ind] = numpy.nan |
|
2836 | phaseOffset[ind] = numpy.nan | |
2837 | phaseOffset = stats.nanmean(phaseOffset, axis=1) |
|
2837 | phaseOffset = stats.nanmean(phaseOffset, axis=1) | |
2838 |
|
2838 | |||
2839 | return phaseOffset |
|
2839 | return phaseOffset | |
2840 |
|
2840 | |||
2841 | def __shiftPhase(self, data, phaseShift): |
|
2841 | def __shiftPhase(self, data, phaseShift): | |
2842 | #this will shift the phase of a complex number |
|
2842 | #this will shift the phase of a complex number | |
2843 | dataShifted = numpy.abs(data) * numpy.exp((numpy.angle(data)+phaseShift)*1j) |
|
2843 | dataShifted = numpy.abs(data) * numpy.exp((numpy.angle(data)+phaseShift)*1j) | |
2844 | return dataShifted |
|
2844 | return dataShifted | |
2845 |
|
2845 | |||
2846 | def __estimatePhaseDifference(self, array, pairslist): |
|
2846 | def __estimatePhaseDifference(self, array, pairslist): | |
2847 | nChannel = array.shape[0] |
|
2847 | nChannel = array.shape[0] | |
2848 | nHeights = array.shape[2] |
|
2848 | nHeights = array.shape[2] | |
2849 | numPairs = len(pairslist) |
|
2849 | numPairs = len(pairslist) | |
2850 | # phaseCCF = numpy.zeros((nChannel, 5, nHeights)) |
|
2850 | # phaseCCF = numpy.zeros((nChannel, 5, nHeights)) | |
2851 | phaseCCF = numpy.angle(self.__calculateCCF(array, pairslist, [-2,-1,0,1,2])) |
|
2851 | phaseCCF = numpy.angle(self.__calculateCCF(array, pairslist, [-2,-1,0,1,2])) | |
2852 |
|
2852 | |||
2853 | #Correct phases |
|
2853 | #Correct phases | |
2854 | derPhaseCCF = phaseCCF[:,1:,:] - phaseCCF[:,0:-1,:] |
|
2854 | derPhaseCCF = phaseCCF[:,1:,:] - phaseCCF[:,0:-1,:] | |
2855 | indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi) |
|
2855 | indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi) | |
2856 |
|
2856 | |||
2857 | if indDer[0].shape[0] > 0: |
|
2857 | if indDer[0].shape[0] > 0: | |
2858 | for i in range(indDer[0].shape[0]): |
|
2858 | for i in range(indDer[0].shape[0]): | |
2859 | signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i],indDer[2][i]]) |
|
2859 | signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i],indDer[2][i]]) | |
2860 | phaseCCF[indDer[0][i],indDer[1][i]+1:,:] += signo*2*numpy.pi |
|
2860 | phaseCCF[indDer[0][i],indDer[1][i]+1:,:] += signo*2*numpy.pi | |
2861 |
|
2861 | |||
2862 | # for j in range(numSides): |
|
2862 | # for j in range(numSides): | |
2863 | # phaseCCFAux = self.calculateCCF(arrayCenter, arraySides[j,:,:], [-2,1,0,1,2]) |
|
2863 | # phaseCCFAux = self.calculateCCF(arrayCenter, arraySides[j,:,:], [-2,1,0,1,2]) | |
2864 | # phaseCCF[j,:,:] = numpy.angle(phaseCCFAux) |
|
2864 | # phaseCCF[j,:,:] = numpy.angle(phaseCCFAux) | |
2865 | # |
|
2865 | # | |
2866 | #Linear |
|
2866 | #Linear | |
2867 | phaseInt = numpy.zeros((numPairs,1)) |
|
2867 | phaseInt = numpy.zeros((numPairs,1)) | |
2868 | angAllCCF = phaseCCF[:,[0,1,3,4],0] |
|
2868 | angAllCCF = phaseCCF[:,[0,1,3,4],0] | |
2869 | for j in range(numPairs): |
|
2869 | for j in range(numPairs): | |
2870 | fit = stats.linregress([-2,-1,1,2],angAllCCF[j,:]) |
|
2870 | fit = stats.linregress([-2,-1,1,2],angAllCCF[j,:]) | |
2871 | phaseInt[j] = fit[1] |
|
2871 | phaseInt[j] = fit[1] | |
2872 | #Phase Differences |
|
2872 | #Phase Differences | |
2873 | phaseDiff = phaseInt - phaseCCF[:,2,:] |
|
2873 | phaseDiff = phaseInt - phaseCCF[:,2,:] | |
2874 | phaseArrival = phaseInt.reshape(phaseInt.size) |
|
2874 | phaseArrival = phaseInt.reshape(phaseInt.size) | |
2875 |
|
2875 | |||
2876 | #Dealias |
|
2876 | #Dealias | |
2877 | phaseArrival = numpy.angle(numpy.exp(1j*phaseArrival)) |
|
2877 | phaseArrival = numpy.angle(numpy.exp(1j*phaseArrival)) | |
2878 | # indAlias = numpy.where(phaseArrival > numpy.pi) |
|
2878 | # indAlias = numpy.where(phaseArrival > numpy.pi) | |
2879 | # phaseArrival[indAlias] -= 2*numpy.pi |
|
2879 | # phaseArrival[indAlias] -= 2*numpy.pi | |
2880 | # indAlias = numpy.where(phaseArrival < -numpy.pi) |
|
2880 | # indAlias = numpy.where(phaseArrival < -numpy.pi) | |
2881 | # phaseArrival[indAlias] += 2*numpy.pi |
|
2881 | # phaseArrival[indAlias] += 2*numpy.pi | |
2882 |
|
2882 | |||
2883 | return phaseDiff, phaseArrival |
|
2883 | return phaseDiff, phaseArrival | |
2884 |
|
2884 | |||
2885 | def __coherentDetection(self, volts, timeSegment, timeInterval, pairslist, thresh): |
|
2885 | def __coherentDetection(self, volts, timeSegment, timeInterval, pairslist, thresh): | |
2886 | #this function will run the coherent detection used in Holdworth et al. 2004 and return the net power |
|
2886 | #this function will run the coherent detection used in Holdworth et al. 2004 and return the net power | |
2887 | #find the phase shifts of each channel over 1 second intervals |
|
2887 | #find the phase shifts of each channel over 1 second intervals | |
2888 | #only look at ranges below the beacon signal |
|
2888 | #only look at ranges below the beacon signal | |
2889 | numProfPerBlock = numpy.ceil(timeSegment/timeInterval) |
|
2889 | numProfPerBlock = numpy.ceil(timeSegment/timeInterval) | |
2890 | numBlocks = int(volts.shape[1]/numProfPerBlock) |
|
2890 | numBlocks = int(volts.shape[1]/numProfPerBlock) | |
2891 | numHeights = volts.shape[2] |
|
2891 | numHeights = volts.shape[2] | |
2892 | nChannel = volts.shape[0] |
|
2892 | nChannel = volts.shape[0] | |
2893 | voltsCohDet = volts.copy() |
|
2893 | voltsCohDet = volts.copy() | |
2894 |
|
2894 | |||
2895 | pairsarray = numpy.array(pairslist) |
|
2895 | pairsarray = numpy.array(pairslist) | |
2896 | indSides = pairsarray[:,1] |
|
2896 | indSides = pairsarray[:,1] | |
2897 | # indSides = numpy.array(range(nChannel)) |
|
2897 | # indSides = numpy.array(range(nChannel)) | |
2898 | # indSides = numpy.delete(indSides, indCenter) |
|
2898 | # indSides = numpy.delete(indSides, indCenter) | |
2899 | # |
|
2899 | # | |
2900 | # listCenter = numpy.array_split(volts[indCenter,:,:], numBlocks, 0) |
|
2900 | # listCenter = numpy.array_split(volts[indCenter,:,:], numBlocks, 0) | |
2901 | listBlocks = numpy.array_split(volts, numBlocks, 1) |
|
2901 | listBlocks = numpy.array_split(volts, numBlocks, 1) | |
2902 |
|
2902 | |||
2903 | startInd = 0 |
|
2903 | startInd = 0 | |
2904 | endInd = 0 |
|
2904 | endInd = 0 | |
2905 |
|
2905 | |||
2906 | for i in range(numBlocks): |
|
2906 | for i in range(numBlocks): | |
2907 | startInd = endInd |
|
2907 | startInd = endInd | |
2908 | endInd = endInd + listBlocks[i].shape[1] |
|
2908 | endInd = endInd + listBlocks[i].shape[1] | |
2909 |
|
2909 | |||
2910 | arrayBlock = listBlocks[i] |
|
2910 | arrayBlock = listBlocks[i] | |
2911 | # arrayBlockCenter = listCenter[i] |
|
2911 | # arrayBlockCenter = listCenter[i] | |
2912 |
|
2912 | |||
2913 | #Estimate the Phase Difference |
|
2913 | #Estimate the Phase Difference | |
2914 | phaseDiff, aux = self.__estimatePhaseDifference(arrayBlock, pairslist) |
|
2914 | phaseDiff, aux = self.__estimatePhaseDifference(arrayBlock, pairslist) | |
2915 | #Phase Difference RMS |
|
2915 | #Phase Difference RMS | |
2916 | arrayPhaseRMS = numpy.abs(phaseDiff) |
|
2916 | arrayPhaseRMS = numpy.abs(phaseDiff) | |
2917 | phaseRMSaux = numpy.sum(arrayPhaseRMS < thresh,0) |
|
2917 | phaseRMSaux = numpy.sum(arrayPhaseRMS < thresh,0) | |
2918 | indPhase = numpy.where(phaseRMSaux==4) |
|
2918 | indPhase = numpy.where(phaseRMSaux==4) | |
2919 | #Shifting |
|
2919 | #Shifting | |
2920 | if indPhase[0].shape[0] > 0: |
|
2920 | if indPhase[0].shape[0] > 0: | |
2921 | for j in range(indSides.size): |
|
2921 | for j in range(indSides.size): | |
2922 | arrayBlock[indSides[j],:,indPhase] = self.__shiftPhase(arrayBlock[indSides[j],:,indPhase], phaseDiff[j,indPhase].transpose()) |
|
2922 | arrayBlock[indSides[j],:,indPhase] = self.__shiftPhase(arrayBlock[indSides[j],:,indPhase], phaseDiff[j,indPhase].transpose()) | |
2923 | voltsCohDet[:,startInd:endInd,:] = arrayBlock |
|
2923 | voltsCohDet[:,startInd:endInd,:] = arrayBlock | |
2924 |
|
2924 | |||
2925 | return voltsCohDet |
|
2925 | return voltsCohDet | |
2926 |
|
2926 | |||
2927 | def __calculateCCF(self, volts, pairslist ,laglist): |
|
2927 | def __calculateCCF(self, volts, pairslist ,laglist): | |
2928 |
|
2928 | |||
2929 | nHeights = volts.shape[2] |
|
2929 | nHeights = volts.shape[2] | |
2930 | nPoints = volts.shape[1] |
|
2930 | nPoints = volts.shape[1] | |
2931 | voltsCCF = numpy.zeros((len(pairslist), len(laglist), nHeights),dtype = 'complex') |
|
2931 | voltsCCF = numpy.zeros((len(pairslist), len(laglist), nHeights),dtype = 'complex') | |
2932 |
|
2932 | |||
2933 | for i in range(len(pairslist)): |
|
2933 | for i in range(len(pairslist)): | |
2934 | volts1 = volts[pairslist[i][0]] |
|
2934 | volts1 = volts[pairslist[i][0]] | |
2935 | volts2 = volts[pairslist[i][1]] |
|
2935 | volts2 = volts[pairslist[i][1]] | |
2936 |
|
2936 | |||
2937 | for t in range(len(laglist)): |
|
2937 | for t in range(len(laglist)): | |
2938 | idxT = laglist[t] |
|
2938 | idxT = laglist[t] | |
2939 | if idxT >= 0: |
|
2939 | if idxT >= 0: | |
2940 | vStacked = numpy.vstack((volts2[idxT:,:], |
|
2940 | vStacked = numpy.vstack((volts2[idxT:,:], | |
2941 | numpy.zeros((idxT, nHeights),dtype='complex'))) |
|
2941 | numpy.zeros((idxT, nHeights),dtype='complex'))) | |
2942 | else: |
|
2942 | else: | |
2943 | vStacked = numpy.vstack((numpy.zeros((-idxT, nHeights),dtype='complex'), |
|
2943 | vStacked = numpy.vstack((numpy.zeros((-idxT, nHeights),dtype='complex'), | |
2944 | volts2[:(nPoints + idxT),:])) |
|
2944 | volts2[:(nPoints + idxT),:])) | |
2945 | voltsCCF[i,t,:] = numpy.sum((numpy.conjugate(volts1)*vStacked),axis=0) |
|
2945 | voltsCCF[i,t,:] = numpy.sum((numpy.conjugate(volts1)*vStacked),axis=0) | |
2946 |
|
2946 | |||
2947 | vStacked = None |
|
2947 | vStacked = None | |
2948 | return voltsCCF |
|
2948 | return voltsCCF | |
2949 |
|
2949 | |||
2950 | def __getNoise(self, power, timeSegment, timeInterval): |
|
2950 | def __getNoise(self, power, timeSegment, timeInterval): | |
2951 | numProfPerBlock = numpy.ceil(timeSegment/timeInterval) |
|
2951 | numProfPerBlock = numpy.ceil(timeSegment/timeInterval) | |
2952 | numBlocks = int(power.shape[0]/numProfPerBlock) |
|
2952 | numBlocks = int(power.shape[0]/numProfPerBlock) | |
2953 | numHeights = power.shape[1] |
|
2953 | numHeights = power.shape[1] | |
2954 |
|
2954 | |||
2955 | listPower = numpy.array_split(power, numBlocks, 0) |
|
2955 | listPower = numpy.array_split(power, numBlocks, 0) | |
2956 | noise = numpy.zeros((power.shape[0], power.shape[1])) |
|
2956 | noise = numpy.zeros((power.shape[0], power.shape[1])) | |
2957 | noise1 = numpy.zeros((power.shape[0], power.shape[1])) |
|
2957 | noise1 = numpy.zeros((power.shape[0], power.shape[1])) | |
2958 |
|
2958 | |||
2959 | startInd = 0 |
|
2959 | startInd = 0 | |
2960 | endInd = 0 |
|
2960 | endInd = 0 | |
2961 |
|
2961 | |||
2962 | for i in range(numBlocks): #split por canal |
|
2962 | for i in range(numBlocks): #split por canal | |
2963 | startInd = endInd |
|
2963 | startInd = endInd | |
2964 | endInd = endInd + listPower[i].shape[0] |
|
2964 | endInd = endInd + listPower[i].shape[0] | |
2965 |
|
2965 | |||
2966 | arrayBlock = listPower[i] |
|
2966 | arrayBlock = listPower[i] | |
2967 | noiseAux = numpy.mean(arrayBlock, 0) |
|
2967 | noiseAux = numpy.mean(arrayBlock, 0) | |
2968 | # noiseAux = numpy.median(noiseAux) |
|
2968 | # noiseAux = numpy.median(noiseAux) | |
2969 | # noiseAux = numpy.mean(arrayBlock) |
|
2969 | # noiseAux = numpy.mean(arrayBlock) | |
2970 | noise[startInd:endInd,:] = noise[startInd:endInd,:] + noiseAux |
|
2970 | noise[startInd:endInd,:] = noise[startInd:endInd,:] + noiseAux | |
2971 |
|
2971 | |||
2972 | noiseAux1 = numpy.mean(arrayBlock) |
|
2972 | noiseAux1 = numpy.mean(arrayBlock) | |
2973 | noise1[startInd:endInd,:] = noise1[startInd:endInd,:] + noiseAux1 |
|
2973 | noise1[startInd:endInd,:] = noise1[startInd:endInd,:] + noiseAux1 | |
2974 |
|
2974 | |||
2975 | return noise, noise1 |
|
2975 | return noise, noise1 | |
2976 |
|
2976 | |||
2977 | def __findMeteors(self, power, thresh): |
|
2977 | def __findMeteors(self, power, thresh): | |
2978 | nProf = power.shape[0] |
|
2978 | nProf = power.shape[0] | |
2979 | nHeights = power.shape[1] |
|
2979 | nHeights = power.shape[1] | |
2980 | listMeteors = [] |
|
2980 | listMeteors = [] | |
2981 |
|
2981 | |||
2982 | for i in range(nHeights): |
|
2982 | for i in range(nHeights): | |
2983 | powerAux = power[:,i] |
|
2983 | powerAux = power[:,i] | |
2984 | threshAux = thresh[:,i] |
|
2984 | threshAux = thresh[:,i] | |
2985 |
|
2985 | |||
2986 | indUPthresh = numpy.where(powerAux > threshAux)[0] |
|
2986 | indUPthresh = numpy.where(powerAux > threshAux)[0] | |
2987 | indDNthresh = numpy.where(powerAux <= threshAux)[0] |
|
2987 | indDNthresh = numpy.where(powerAux <= threshAux)[0] | |
2988 |
|
2988 | |||
2989 | j = 0 |
|
2989 | j = 0 | |
2990 |
|
2990 | |||
2991 | while (j < indUPthresh.size - 2): |
|
2991 | while (j < indUPthresh.size - 2): | |
2992 | if (indUPthresh[j + 2] == indUPthresh[j] + 2): |
|
2992 | if (indUPthresh[j + 2] == indUPthresh[j] + 2): | |
2993 | indDNAux = numpy.where(indDNthresh > indUPthresh[j]) |
|
2993 | indDNAux = numpy.where(indDNthresh > indUPthresh[j]) | |
2994 | indDNthresh = indDNthresh[indDNAux] |
|
2994 | indDNthresh = indDNthresh[indDNAux] | |
2995 |
|
2995 | |||
2996 | if (indDNthresh.size > 0): |
|
2996 | if (indDNthresh.size > 0): | |
2997 | indEnd = indDNthresh[0] - 1 |
|
2997 | indEnd = indDNthresh[0] - 1 | |
2998 | indInit = indUPthresh[j] |
|
2998 | indInit = indUPthresh[j] | |
2999 |
|
2999 | |||
3000 | meteor = powerAux[indInit:indEnd + 1] |
|
3000 | meteor = powerAux[indInit:indEnd + 1] | |
3001 | indPeak = meteor.argmax() + indInit |
|
3001 | indPeak = meteor.argmax() + indInit | |
3002 | FLA = sum(numpy.conj(meteor)*numpy.hstack((meteor[1:],0))) |
|
3002 | FLA = sum(numpy.conj(meteor)*numpy.hstack((meteor[1:],0))) | |
3003 |
|
3003 | |||
3004 | listMeteors.append(numpy.array([i,indInit,indPeak,indEnd,FLA])) #CHEQUEAR!!!!! |
|
3004 | listMeteors.append(numpy.array([i,indInit,indPeak,indEnd,FLA])) #CHEQUEAR!!!!! | |
3005 | j = numpy.where(indUPthresh == indEnd)[0] + 1 |
|
3005 | j = numpy.where(indUPthresh == indEnd)[0] + 1 | |
3006 | else: j+=1 |
|
3006 | else: j+=1 | |
3007 | else: j+=1 |
|
3007 | else: j+=1 | |
3008 |
|
3008 | |||
3009 | return listMeteors |
|
3009 | return listMeteors | |
3010 |
|
3010 | |||
3011 | def __removeMultipleDetections(self,listMeteors, rangeLimit, timeLimit): |
|
3011 | def __removeMultipleDetections(self,listMeteors, rangeLimit, timeLimit): | |
3012 |
|
3012 | |||
3013 | arrayMeteors = numpy.asarray(listMeteors) |
|
3013 | arrayMeteors = numpy.asarray(listMeteors) | |
3014 | listMeteors1 = [] |
|
3014 | listMeteors1 = [] | |
3015 |
|
3015 | |||
3016 | while arrayMeteors.shape[0] > 0: |
|
3016 | while arrayMeteors.shape[0] > 0: | |
3017 | FLAs = arrayMeteors[:,4] |
|
3017 | FLAs = arrayMeteors[:,4] | |
3018 | maxFLA = FLAs.argmax() |
|
3018 | maxFLA = FLAs.argmax() | |
3019 | listMeteors1.append(arrayMeteors[maxFLA,:]) |
|
3019 | listMeteors1.append(arrayMeteors[maxFLA,:]) | |
3020 |
|
3020 | |||
3021 | MeteorInitTime = arrayMeteors[maxFLA,1] |
|
3021 | MeteorInitTime = arrayMeteors[maxFLA,1] | |
3022 | MeteorEndTime = arrayMeteors[maxFLA,3] |
|
3022 | MeteorEndTime = arrayMeteors[maxFLA,3] | |
3023 | MeteorHeight = arrayMeteors[maxFLA,0] |
|
3023 | MeteorHeight = arrayMeteors[maxFLA,0] | |
3024 |
|
3024 | |||
3025 | #Check neighborhood |
|
3025 | #Check neighborhood | |
3026 | maxHeightIndex = MeteorHeight + rangeLimit |
|
3026 | maxHeightIndex = MeteorHeight + rangeLimit | |
3027 | minHeightIndex = MeteorHeight - rangeLimit |
|
3027 | minHeightIndex = MeteorHeight - rangeLimit | |
3028 | minTimeIndex = MeteorInitTime - timeLimit |
|
3028 | minTimeIndex = MeteorInitTime - timeLimit | |
3029 | maxTimeIndex = MeteorEndTime + timeLimit |
|
3029 | maxTimeIndex = MeteorEndTime + timeLimit | |
3030 |
|
3030 | |||
3031 | #Check Heights |
|
3031 | #Check Heights | |
3032 | indHeight = numpy.logical_and(arrayMeteors[:,0] >= minHeightIndex, arrayMeteors[:,0] <= maxHeightIndex) |
|
3032 | indHeight = numpy.logical_and(arrayMeteors[:,0] >= minHeightIndex, arrayMeteors[:,0] <= maxHeightIndex) | |
3033 | indTime = numpy.logical_and(arrayMeteors[:,3] >= minTimeIndex, arrayMeteors[:,1] <= maxTimeIndex) |
|
3033 | indTime = numpy.logical_and(arrayMeteors[:,3] >= minTimeIndex, arrayMeteors[:,1] <= maxTimeIndex) | |
3034 | indBoth = numpy.where(numpy.logical_and(indTime,indHeight)) |
|
3034 | indBoth = numpy.where(numpy.logical_and(indTime,indHeight)) | |
3035 |
|
3035 | |||
3036 | arrayMeteors = numpy.delete(arrayMeteors, indBoth, axis = 0) |
|
3036 | arrayMeteors = numpy.delete(arrayMeteors, indBoth, axis = 0) | |
3037 |
|
3037 | |||
3038 | return listMeteors1 |
|
3038 | return listMeteors1 | |
3039 |
|
3039 | |||
3040 | def __meteorReestimation(self, listMeteors, volts, pairslist, thresh, noise, timeInterval,frequency): |
|
3040 | def __meteorReestimation(self, listMeteors, volts, pairslist, thresh, noise, timeInterval,frequency): | |
3041 | numHeights = volts.shape[2] |
|
3041 | numHeights = volts.shape[2] | |
3042 | nChannel = volts.shape[0] |
|
3042 | nChannel = volts.shape[0] | |
3043 |
|
3043 | |||
3044 | thresholdPhase = thresh[0] |
|
3044 | thresholdPhase = thresh[0] | |
3045 | thresholdNoise = thresh[1] |
|
3045 | thresholdNoise = thresh[1] | |
3046 | thresholdDB = float(thresh[2]) |
|
3046 | thresholdDB = float(thresh[2]) | |
3047 |
|
3047 | |||
3048 | thresholdDB1 = 10**(thresholdDB/10) |
|
3048 | thresholdDB1 = 10**(thresholdDB/10) | |
3049 | pairsarray = numpy.array(pairslist) |
|
3049 | pairsarray = numpy.array(pairslist) | |
3050 | indSides = pairsarray[:,1] |
|
3050 | indSides = pairsarray[:,1] | |
3051 |
|
3051 | |||
3052 | pairslist1 = list(pairslist) |
|
3052 | pairslist1 = list(pairslist) | |
3053 | pairslist1.append((0,1)) |
|
3053 | pairslist1.append((0,1)) | |
3054 | pairslist1.append((3,4)) |
|
3054 | pairslist1.append((3,4)) | |
3055 |
|
3055 | |||
3056 | listMeteors1 = [] |
|
3056 | listMeteors1 = [] | |
3057 | listPowerSeries = [] |
|
3057 | listPowerSeries = [] | |
3058 | listVoltageSeries = [] |
|
3058 | listVoltageSeries = [] | |
3059 | #volts has the war data |
|
3059 | #volts has the war data | |
3060 |
|
3060 | |||
3061 | if frequency == 30e6: |
|
3061 | if frequency == 30e6: | |
3062 | timeLag = 45*10**-3 |
|
3062 | timeLag = 45*10**-3 | |
3063 | else: |
|
3063 | else: | |
3064 | timeLag = 15*10**-3 |
|
3064 | timeLag = 15*10**-3 | |
3065 | lag = numpy.ceil(timeLag/timeInterval) |
|
3065 | lag = numpy.ceil(timeLag/timeInterval) | |
3066 |
|
3066 | |||
3067 | for i in range(len(listMeteors)): |
|
3067 | for i in range(len(listMeteors)): | |
3068 |
|
3068 | |||
3069 | ###################### 3.6 - 3.7 PARAMETERS REESTIMATION ######################### |
|
3069 | ###################### 3.6 - 3.7 PARAMETERS REESTIMATION ######################### | |
3070 | meteorAux = numpy.zeros(16) |
|
3070 | meteorAux = numpy.zeros(16) | |
3071 |
|
3071 | |||
3072 | #Loading meteor Data (mHeight, mStart, mPeak, mEnd) |
|
3072 | #Loading meteor Data (mHeight, mStart, mPeak, mEnd) | |
3073 | mHeight = listMeteors[i][0] |
|
3073 | mHeight = listMeteors[i][0] | |
3074 | mStart = listMeteors[i][1] |
|
3074 | mStart = listMeteors[i][1] | |
3075 | mPeak = listMeteors[i][2] |
|
3075 | mPeak = listMeteors[i][2] | |
3076 | mEnd = listMeteors[i][3] |
|
3076 | mEnd = listMeteors[i][3] | |
3077 |
|
3077 | |||
3078 | #get the volt data between the start and end times of the meteor |
|
3078 | #get the volt data between the start and end times of the meteor | |
3079 | meteorVolts = volts[:,mStart:mEnd+1,mHeight] |
|
3079 | meteorVolts = volts[:,mStart:mEnd+1,mHeight] | |
3080 | meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1) |
|
3080 | meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1) | |
3081 |
|
3081 | |||
3082 | #3.6. Phase Difference estimation |
|
3082 | #3.6. Phase Difference estimation | |
3083 | phaseDiff, aux = self.__estimatePhaseDifference(meteorVolts, pairslist) |
|
3083 | phaseDiff, aux = self.__estimatePhaseDifference(meteorVolts, pairslist) | |
3084 |
|
3084 | |||
3085 | #3.7. Phase difference removal & meteor start, peak and end times reestimated |
|
3085 | #3.7. Phase difference removal & meteor start, peak and end times reestimated | |
3086 | #meteorVolts0.- all Channels, all Profiles |
|
3086 | #meteorVolts0.- all Channels, all Profiles | |
3087 | meteorVolts0 = volts[:,:,mHeight] |
|
3087 | meteorVolts0 = volts[:,:,mHeight] | |
3088 | meteorThresh = noise[:,mHeight]*thresholdNoise |
|
3088 | meteorThresh = noise[:,mHeight]*thresholdNoise | |
3089 | meteorNoise = noise[:,mHeight] |
|
3089 | meteorNoise = noise[:,mHeight] | |
3090 | meteorVolts0[indSides,:] = self.__shiftPhase(meteorVolts0[indSides,:], phaseDiff) #Phase Shifting |
|
3090 | meteorVolts0[indSides,:] = self.__shiftPhase(meteorVolts0[indSides,:], phaseDiff) #Phase Shifting | |
3091 | powerNet0 = numpy.nansum(numpy.abs(meteorVolts0)**2, axis = 0) #Power |
|
3091 | powerNet0 = numpy.nansum(numpy.abs(meteorVolts0)**2, axis = 0) #Power | |
3092 |
|
3092 | |||
3093 | #Times reestimation |
|
3093 | #Times reestimation | |
3094 | mStart1 = numpy.where(powerNet0[:mPeak] < meteorThresh[:mPeak])[0] |
|
3094 | mStart1 = numpy.where(powerNet0[:mPeak] < meteorThresh[:mPeak])[0] | |
3095 | if mStart1.size > 0: |
|
3095 | if mStart1.size > 0: | |
3096 | mStart1 = mStart1[-1] + 1 |
|
3096 | mStart1 = mStart1[-1] + 1 | |
3097 |
|
3097 | |||
3098 | else: |
|
3098 | else: | |
3099 | mStart1 = mPeak |
|
3099 | mStart1 = mPeak | |
3100 |
|
3100 | |||
3101 | mEnd1 = numpy.where(powerNet0[mPeak:] < meteorThresh[mPeak:])[0][0] + mPeak - 1 |
|
3101 | mEnd1 = numpy.where(powerNet0[mPeak:] < meteorThresh[mPeak:])[0][0] + mPeak - 1 | |
3102 | mEndDecayTime1 = numpy.where(powerNet0[mPeak:] < meteorNoise[mPeak:])[0] |
|
3102 | mEndDecayTime1 = numpy.where(powerNet0[mPeak:] < meteorNoise[mPeak:])[0] | |
3103 | if mEndDecayTime1.size == 0: |
|
3103 | if mEndDecayTime1.size == 0: | |
3104 | mEndDecayTime1 = powerNet0.size |
|
3104 | mEndDecayTime1 = powerNet0.size | |
3105 | else: |
|
3105 | else: | |
3106 | mEndDecayTime1 = mEndDecayTime1[0] + mPeak - 1 |
|
3106 | mEndDecayTime1 = mEndDecayTime1[0] + mPeak - 1 | |
3107 | # mPeak1 = meteorVolts0[mStart1:mEnd1 + 1].argmax() |
|
3107 | # mPeak1 = meteorVolts0[mStart1:mEnd1 + 1].argmax() | |
3108 |
|
3108 | |||
3109 | #meteorVolts1.- all Channels, from start to end |
|
3109 | #meteorVolts1.- all Channels, from start to end | |
3110 | meteorVolts1 = meteorVolts0[:,mStart1:mEnd1 + 1] |
|
3110 | meteorVolts1 = meteorVolts0[:,mStart1:mEnd1 + 1] | |
3111 | meteorVolts2 = meteorVolts0[:,mPeak + lag:mEnd1 + 1] |
|
3111 | meteorVolts2 = meteorVolts0[:,mPeak + lag:mEnd1 + 1] | |
3112 | if meteorVolts2.shape[1] == 0: |
|
3112 | if meteorVolts2.shape[1] == 0: | |
3113 | meteorVolts2 = meteorVolts0[:,mPeak:mEnd1 + 1] |
|
3113 | meteorVolts2 = meteorVolts0[:,mPeak:mEnd1 + 1] | |
3114 | meteorVolts1 = meteorVolts1.reshape(meteorVolts1.shape[0], meteorVolts1.shape[1], 1) |
|
3114 | meteorVolts1 = meteorVolts1.reshape(meteorVolts1.shape[0], meteorVolts1.shape[1], 1) | |
3115 | meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1], 1) |
|
3115 | meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1], 1) | |
3116 | ##################### END PARAMETERS REESTIMATION ######################### |
|
3116 | ##################### END PARAMETERS REESTIMATION ######################### | |
3117 |
|
3117 | |||
3118 | ##################### 3.8 PHASE DIFFERENCE REESTIMATION ######################## |
|
3118 | ##################### 3.8 PHASE DIFFERENCE REESTIMATION ######################## | |
3119 | # if mEnd1 - mStart1 > 4: #Error Number 6: echo less than 5 samples long; too short for analysis |
|
3119 | # if mEnd1 - mStart1 > 4: #Error Number 6: echo less than 5 samples long; too short for analysis | |
3120 | if meteorVolts2.shape[1] > 0: |
|
3120 | if meteorVolts2.shape[1] > 0: | |
3121 | #Phase Difference re-estimation |
|
3121 | #Phase Difference re-estimation | |
3122 | phaseDiff1, phaseDiffint = self.__estimatePhaseDifference(meteorVolts2, pairslist1) #Phase Difference Estimation |
|
3122 | phaseDiff1, phaseDiffint = self.__estimatePhaseDifference(meteorVolts2, pairslist1) #Phase Difference Estimation | |
3123 | # phaseDiff1, phaseDiffint = self.estimatePhaseDifference(meteorVolts2, pairslist) |
|
3123 | # phaseDiff1, phaseDiffint = self.estimatePhaseDifference(meteorVolts2, pairslist) | |
3124 | meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1]) |
|
3124 | meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1]) | |
3125 | phaseDiff11 = numpy.reshape(phaseDiff1, (phaseDiff1.shape[0],1)) |
|
3125 | phaseDiff11 = numpy.reshape(phaseDiff1, (phaseDiff1.shape[0],1)) | |
3126 | meteorVolts2[indSides,:] = self.__shiftPhase(meteorVolts2[indSides,:], phaseDiff11[0:4]) #Phase Shifting |
|
3126 | meteorVolts2[indSides,:] = self.__shiftPhase(meteorVolts2[indSides,:], phaseDiff11[0:4]) #Phase Shifting | |
3127 |
|
3127 | |||
3128 | #Phase Difference RMS |
|
3128 | #Phase Difference RMS | |
3129 | phaseRMS1 = numpy.sqrt(numpy.mean(numpy.square(phaseDiff1))) |
|
3129 | phaseRMS1 = numpy.sqrt(numpy.mean(numpy.square(phaseDiff1))) | |
3130 | powerNet1 = numpy.nansum(numpy.abs(meteorVolts1[:,:])**2,0) |
|
3130 | powerNet1 = numpy.nansum(numpy.abs(meteorVolts1[:,:])**2,0) | |
3131 | #Data from Meteor |
|
3131 | #Data from Meteor | |
3132 | mPeak1 = powerNet1.argmax() + mStart1 |
|
3132 | mPeak1 = powerNet1.argmax() + mStart1 | |
3133 | mPeakPower1 = powerNet1.max() |
|
3133 | mPeakPower1 = powerNet1.max() | |
3134 | noiseAux = sum(noise[mStart1:mEnd1 + 1,mHeight]) |
|
3134 | noiseAux = sum(noise[mStart1:mEnd1 + 1,mHeight]) | |
3135 | mSNR1 = (sum(powerNet1)-noiseAux)/noiseAux |
|
3135 | mSNR1 = (sum(powerNet1)-noiseAux)/noiseAux | |
3136 | Meteor1 = numpy.array([mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1]) |
|
3136 | Meteor1 = numpy.array([mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1]) | |
3137 | Meteor1 = numpy.hstack((Meteor1,phaseDiffint)) |
|
3137 | Meteor1 = numpy.hstack((Meteor1,phaseDiffint)) | |
3138 | PowerSeries = powerNet0[mStart1:mEndDecayTime1 + 1] |
|
3138 | PowerSeries = powerNet0[mStart1:mEndDecayTime1 + 1] | |
3139 | #Vectorize |
|
3139 | #Vectorize | |
3140 | meteorAux[0:7] = [mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1] |
|
3140 | meteorAux[0:7] = [mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1] | |
3141 | meteorAux[7:11] = phaseDiffint[0:4] |
|
3141 | meteorAux[7:11] = phaseDiffint[0:4] | |
3142 |
|
3142 | |||
3143 | #Rejection Criterions |
|
3143 | #Rejection Criterions | |
3144 | if phaseRMS1 > thresholdPhase: #Error Number 17: Phase variation |
|
3144 | if phaseRMS1 > thresholdPhase: #Error Number 17: Phase variation | |
3145 | meteorAux[-1] = 17 |
|
3145 | meteorAux[-1] = 17 | |
3146 | elif mSNR1 < thresholdDB1: #Error Number 1: SNR < threshold dB |
|
3146 | elif mSNR1 < thresholdDB1: #Error Number 1: SNR < threshold dB | |
3147 | meteorAux[-1] = 1 |
|
3147 | meteorAux[-1] = 1 | |
3148 |
|
3148 | |||
3149 |
|
3149 | |||
3150 | else: |
|
3150 | else: | |
3151 | meteorAux[0:4] = [mHeight, mStart, mPeak, mEnd] |
|
3151 | meteorAux[0:4] = [mHeight, mStart, mPeak, mEnd] | |
3152 | meteorAux[-1] = 6 #Error Number 6: echo less than 5 samples long; too short for analysis |
|
3152 | meteorAux[-1] = 6 #Error Number 6: echo less than 5 samples long; too short for analysis | |
3153 | PowerSeries = 0 |
|
3153 | PowerSeries = 0 | |
3154 |
|
3154 | |||
3155 | listMeteors1.append(meteorAux) |
|
3155 | listMeteors1.append(meteorAux) | |
3156 | listPowerSeries.append(PowerSeries) |
|
3156 | listPowerSeries.append(PowerSeries) | |
3157 | listVoltageSeries.append(meteorVolts1) |
|
3157 | listVoltageSeries.append(meteorVolts1) | |
3158 |
|
3158 | |||
3159 | return listMeteors1, listPowerSeries, listVoltageSeries |
|
3159 | return listMeteors1, listPowerSeries, listVoltageSeries | |
3160 |
|
3160 | |||
3161 | def __estimateDecayTime(self, listMeteors, listPower, timeInterval, frequency): |
|
3161 | def __estimateDecayTime(self, listMeteors, listPower, timeInterval, frequency): | |
3162 |
|
3162 | |||
3163 | threshError = 10 |
|
3163 | threshError = 10 | |
3164 | #Depending if it is 30 or 50 MHz |
|
3164 | #Depending if it is 30 or 50 MHz | |
3165 | if frequency == 30e6: |
|
3165 | if frequency == 30e6: | |
3166 | timeLag = 45*10**-3 |
|
3166 | timeLag = 45*10**-3 | |
3167 | else: |
|
3167 | else: | |
3168 | timeLag = 15*10**-3 |
|
3168 | timeLag = 15*10**-3 | |
3169 | lag = numpy.ceil(timeLag/timeInterval) |
|
3169 | lag = numpy.ceil(timeLag/timeInterval) | |
3170 |
|
3170 | |||
3171 | listMeteors1 = [] |
|
3171 | listMeteors1 = [] | |
3172 |
|
3172 | |||
3173 | for i in range(len(listMeteors)): |
|
3173 | for i in range(len(listMeteors)): | |
3174 | meteorPower = listPower[i] |
|
3174 | meteorPower = listPower[i] | |
3175 | meteorAux = listMeteors[i] |
|
3175 | meteorAux = listMeteors[i] | |
3176 |
|
3176 | |||
3177 | if meteorAux[-1] == 0: |
|
3177 | if meteorAux[-1] == 0: | |
3178 |
|
3178 | |||
3179 | try: |
|
3179 | try: | |
3180 | indmax = meteorPower.argmax() |
|
3180 | indmax = meteorPower.argmax() | |
3181 | indlag = indmax + lag |
|
3181 | indlag = indmax + lag | |
3182 |
|
3182 | |||
3183 | y = meteorPower[indlag:] |
|
3183 | y = meteorPower[indlag:] | |
3184 | x = numpy.arange(0, y.size)*timeLag |
|
3184 | x = numpy.arange(0, y.size)*timeLag | |
3185 |
|
3185 | |||
3186 | #first guess |
|
3186 | #first guess | |
3187 | a = y[0] |
|
3187 | a = y[0] | |
3188 | tau = timeLag |
|
3188 | tau = timeLag | |
3189 | #exponential fit |
|
3189 | #exponential fit | |
3190 | popt, pcov = optimize.curve_fit(self.__exponential_function, x, y, p0 = [a, tau]) |
|
3190 | popt, pcov = optimize.curve_fit(self.__exponential_function, x, y, p0 = [a, tau]) | |
3191 | y1 = self.__exponential_function(x, *popt) |
|
3191 | y1 = self.__exponential_function(x, *popt) | |
3192 | #error estimation |
|
3192 | #error estimation | |
3193 | error = sum((y - y1)**2)/(numpy.var(y)*(y.size - popt.size)) |
|
3193 | error = sum((y - y1)**2)/(numpy.var(y)*(y.size - popt.size)) | |
3194 |
|
3194 | |||
3195 | decayTime = popt[1] |
|
3195 | decayTime = popt[1] | |
3196 | riseTime = indmax*timeInterval |
|
3196 | riseTime = indmax*timeInterval | |
3197 | meteorAux[11:13] = [decayTime, error] |
|
3197 | meteorAux[11:13] = [decayTime, error] | |
3198 |
|
3198 | |||
3199 | #Table items 7, 8 and 11 |
|
3199 | #Table items 7, 8 and 11 | |
3200 | if (riseTime > 0.3): #Number 7: Echo rise exceeds 0.3s |
|
3200 | if (riseTime > 0.3): #Number 7: Echo rise exceeds 0.3s | |
3201 | meteorAux[-1] = 7 |
|
3201 | meteorAux[-1] = 7 | |
3202 | elif (decayTime < 2*riseTime) : #Number 8: Echo decay time less than than twice rise time |
|
3202 | elif (decayTime < 2*riseTime) : #Number 8: Echo decay time less than than twice rise time | |
3203 | meteorAux[-1] = 8 |
|
3203 | meteorAux[-1] = 8 | |
3204 | if (error > threshError): #Number 11: Poor fit to amplitude for estimation of decay time |
|
3204 | if (error > threshError): #Number 11: Poor fit to amplitude for estimation of decay time | |
3205 | meteorAux[-1] = 11 |
|
3205 | meteorAux[-1] = 11 | |
3206 |
|
3206 | |||
3207 |
|
3207 | |||
3208 | except: |
|
3208 | except: | |
3209 | meteorAux[-1] = 11 |
|
3209 | meteorAux[-1] = 11 | |
3210 |
|
3210 | |||
3211 |
|
3211 | |||
3212 | listMeteors1.append(meteorAux) |
|
3212 | listMeteors1.append(meteorAux) | |
3213 |
|
3213 | |||
3214 | return listMeteors1 |
|
3214 | return listMeteors1 | |
3215 |
|
3215 | |||
3216 | #Exponential Function |
|
3216 | #Exponential Function | |
3217 |
|
3217 | |||
3218 | def __exponential_function(self, x, a, tau): |
|
3218 | def __exponential_function(self, x, a, tau): | |
3219 | y = a*numpy.exp(-x/tau) |
|
3219 | y = a*numpy.exp(-x/tau) | |
3220 | return y |
|
3220 | return y | |
3221 |
|
3221 | |||
3222 | def __getRadialVelocity(self, listMeteors, listVolts, radialStdThresh, pairslist, timeInterval): |
|
3222 | def __getRadialVelocity(self, listMeteors, listVolts, radialStdThresh, pairslist, timeInterval): | |
3223 |
|
3223 | |||
3224 | pairslist1 = list(pairslist) |
|
3224 | pairslist1 = list(pairslist) | |
3225 | pairslist1.append((0,1)) |
|
3225 | pairslist1.append((0,1)) | |
3226 | pairslist1.append((3,4)) |
|
3226 | pairslist1.append((3,4)) | |
3227 | numPairs = len(pairslist1) |
|
3227 | numPairs = len(pairslist1) | |
3228 | #Time Lag |
|
3228 | #Time Lag | |
3229 | timeLag = 45*10**-3 |
|
3229 | timeLag = 45*10**-3 | |
3230 | c = 3e8 |
|
3230 | c = 3e8 | |
3231 | lag = numpy.ceil(timeLag/timeInterval) |
|
3231 | lag = numpy.ceil(timeLag/timeInterval) | |
3232 | freq = 30e6 |
|
3232 | freq = 30e6 | |
3233 |
|
3233 | |||
3234 | listMeteors1 = [] |
|
3234 | listMeteors1 = [] | |
3235 |
|
3235 | |||
3236 | for i in range(len(listMeteors)): |
|
3236 | for i in range(len(listMeteors)): | |
3237 | meteorAux = listMeteors[i] |
|
3237 | meteorAux = listMeteors[i] | |
3238 | if meteorAux[-1] == 0: |
|
3238 | if meteorAux[-1] == 0: | |
3239 | mStart = listMeteors[i][1] |
|
3239 | mStart = listMeteors[i][1] | |
3240 | mPeak = listMeteors[i][2] |
|
3240 | mPeak = listMeteors[i][2] | |
3241 | mLag = mPeak - mStart + lag |
|
3241 | mLag = mPeak - mStart + lag | |
3242 |
|
3242 | |||
3243 | #get the volt data between the start and end times of the meteor |
|
3243 | #get the volt data between the start and end times of the meteor | |
3244 | meteorVolts = listVolts[i] |
|
3244 | meteorVolts = listVolts[i] | |
3245 | meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1) |
|
3245 | meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1) | |
3246 |
|
3246 | |||
3247 | #Get CCF |
|
3247 | #Get CCF | |
3248 | allCCFs = self.__calculateCCF(meteorVolts, pairslist1, [-2,-1,0,1,2]) |
|
3248 | allCCFs = self.__calculateCCF(meteorVolts, pairslist1, [-2,-1,0,1,2]) | |
3249 |
|
3249 | |||
3250 | #Method 2 |
|
3250 | #Method 2 | |
3251 | slopes = numpy.zeros(numPairs) |
|
3251 | slopes = numpy.zeros(numPairs) | |
3252 | time = numpy.array([-2,-1,1,2])*timeInterval |
|
3252 | time = numpy.array([-2,-1,1,2])*timeInterval | |
3253 | angAllCCF = numpy.angle(allCCFs[:,[0,1,3,4],0]) |
|
3253 | angAllCCF = numpy.angle(allCCFs[:,[0,1,3,4],0]) | |
3254 |
|
3254 | |||
3255 | #Correct phases |
|
3255 | #Correct phases | |
3256 | derPhaseCCF = angAllCCF[:,1:] - angAllCCF[:,0:-1] |
|
3256 | derPhaseCCF = angAllCCF[:,1:] - angAllCCF[:,0:-1] | |
3257 | indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi) |
|
3257 | indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi) | |
3258 |
|
3258 | |||
3259 | if indDer[0].shape[0] > 0: |
|
3259 | if indDer[0].shape[0] > 0: | |
3260 | for i in range(indDer[0].shape[0]): |
|
3260 | for i in range(indDer[0].shape[0]): | |
3261 | signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i]]) |
|
3261 | signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i]]) | |
3262 | angAllCCF[indDer[0][i],indDer[1][i]+1:] += signo*2*numpy.pi |
|
3262 | angAllCCF[indDer[0][i],indDer[1][i]+1:] += signo*2*numpy.pi | |
3263 |
|
3263 | |||
3264 | # fit = scipy.stats.linregress(numpy.array([-2,-1,1,2])*timeInterval, numpy.array([phaseLagN2s[i],phaseLagN1s[i],phaseLag1s[i],phaseLag2s[i]])) |
|
3264 | # fit = scipy.stats.linregress(numpy.array([-2,-1,1,2])*timeInterval, numpy.array([phaseLagN2s[i],phaseLagN1s[i],phaseLag1s[i],phaseLag2s[i]])) | |
3265 | for j in range(numPairs): |
|
3265 | for j in range(numPairs): | |
3266 | fit = stats.linregress(time, angAllCCF[j,:]) |
|
3266 | fit = stats.linregress(time, angAllCCF[j,:]) | |
3267 | slopes[j] = fit[0] |
|
3267 | slopes[j] = fit[0] | |
3268 |
|
3268 | |||
3269 | #Remove Outlier |
|
3269 | #Remove Outlier | |
3270 | # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes))) |
|
3270 | # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes))) | |
3271 | # slopes = numpy.delete(slopes,indOut) |
|
3271 | # slopes = numpy.delete(slopes,indOut) | |
3272 | # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes))) |
|
3272 | # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes))) | |
3273 | # slopes = numpy.delete(slopes,indOut) |
|
3273 | # slopes = numpy.delete(slopes,indOut) | |
3274 |
|
3274 | |||
3275 | radialVelocity = -numpy.mean(slopes)*(0.25/numpy.pi)*(c/freq) |
|
3275 | radialVelocity = -numpy.mean(slopes)*(0.25/numpy.pi)*(c/freq) | |
3276 | radialError = numpy.std(slopes)*(0.25/numpy.pi)*(c/freq) |
|
3276 | radialError = numpy.std(slopes)*(0.25/numpy.pi)*(c/freq) | |
3277 | meteorAux[-2] = radialError |
|
3277 | meteorAux[-2] = radialError | |
3278 | meteorAux[-3] = radialVelocity |
|
3278 | meteorAux[-3] = radialVelocity | |
3279 |
|
3279 | |||
3280 | #Setting Error |
|
3280 | #Setting Error | |
3281 | #Number 15: Radial Drift velocity or projected horizontal velocity exceeds 200 m/s |
|
3281 | #Number 15: Radial Drift velocity or projected horizontal velocity exceeds 200 m/s | |
3282 | if numpy.abs(radialVelocity) > 200: |
|
3282 | if numpy.abs(radialVelocity) > 200: | |
3283 | meteorAux[-1] = 15 |
|
3283 | meteorAux[-1] = 15 | |
3284 | #Number 12: Poor fit to CCF variation for estimation of radial drift velocity |
|
3284 | #Number 12: Poor fit to CCF variation for estimation of radial drift velocity | |
3285 | elif radialError > radialStdThresh: |
|
3285 | elif radialError > radialStdThresh: | |
3286 | meteorAux[-1] = 12 |
|
3286 | meteorAux[-1] = 12 | |
3287 |
|
3287 | |||
3288 | listMeteors1.append(meteorAux) |
|
3288 | listMeteors1.append(meteorAux) | |
3289 | return listMeteors1 |
|
3289 | return listMeteors1 | |
3290 |
|
3290 | |||
3291 | def __setNewArrays(self, listMeteors, date, heiRang): |
|
3291 | def __setNewArrays(self, listMeteors, date, heiRang): | |
3292 |
|
3292 | |||
3293 | #New arrays |
|
3293 | #New arrays | |
3294 | arrayMeteors = numpy.array(listMeteors) |
|
3294 | arrayMeteors = numpy.array(listMeteors) | |
3295 | arrayParameters = numpy.zeros((len(listMeteors), 13)) |
|
3295 | arrayParameters = numpy.zeros((len(listMeteors), 13)) | |
3296 |
|
3296 | |||
3297 | #Date inclusion |
|
3297 | #Date inclusion | |
3298 | # date = re.findall(r'\((.*?)\)', date) |
|
3298 | # date = re.findall(r'\((.*?)\)', date) | |
3299 | # date = date[0].split(',') |
|
3299 | # date = date[0].split(',') | |
3300 | # date = map(int, date) |
|
3300 | # date = map(int, date) | |
3301 | # |
|
3301 | # | |
3302 | # if len(date)<6: |
|
3302 | # if len(date)<6: | |
3303 | # date.append(0) |
|
3303 | # date.append(0) | |
3304 | # |
|
3304 | # | |
3305 | # date = [date[0]*10000 + date[1]*100 + date[2], date[3]*10000 + date[4]*100 + date[5]] |
|
3305 | # date = [date[0]*10000 + date[1]*100 + date[2], date[3]*10000 + date[4]*100 + date[5]] | |
3306 | # arrayDate = numpy.tile(date, (len(listMeteors), 1)) |
|
3306 | # arrayDate = numpy.tile(date, (len(listMeteors), 1)) | |
3307 | arrayDate = numpy.tile(date, (len(listMeteors))) |
|
3307 | arrayDate = numpy.tile(date, (len(listMeteors))) | |
3308 |
|
3308 | |||
3309 | #Meteor array |
|
3309 | #Meteor array | |
3310 | # arrayMeteors[:,0] = heiRang[arrayMeteors[:,0].astype(int)] |
|
3310 | # arrayMeteors[:,0] = heiRang[arrayMeteors[:,0].astype(int)] | |
3311 | # arrayMeteors = numpy.hstack((arrayDate, arrayMeteors)) |
|
3311 | # arrayMeteors = numpy.hstack((arrayDate, arrayMeteors)) | |
3312 |
|
3312 | |||
3313 | #Parameters Array |
|
3313 | #Parameters Array | |
3314 | arrayParameters[:,0] = arrayDate #Date |
|
3314 | arrayParameters[:,0] = arrayDate #Date | |
3315 | arrayParameters[:,1] = heiRang[arrayMeteors[:,0].astype(int)] #Range |
|
3315 | arrayParameters[:,1] = heiRang[arrayMeteors[:,0].astype(int)] #Range | |
3316 | arrayParameters[:,6:8] = arrayMeteors[:,-3:-1] #Radial velocity and its error |
|
3316 | arrayParameters[:,6:8] = arrayMeteors[:,-3:-1] #Radial velocity and its error | |
3317 | arrayParameters[:,8:12] = arrayMeteors[:,7:11] #Phases |
|
3317 | arrayParameters[:,8:12] = arrayMeteors[:,7:11] #Phases | |
3318 | arrayParameters[:,-1] = arrayMeteors[:,-1] #Error |
|
3318 | arrayParameters[:,-1] = arrayMeteors[:,-1] #Error | |
3319 |
|
3319 | |||
3320 |
|
3320 | |||
3321 | return arrayParameters |
|
3321 | return arrayParameters | |
3322 |
|
3322 | |||
3323 | class CorrectSMPhases(Operation): |
|
3323 | class CorrectSMPhases(Operation): | |
3324 |
|
3324 | |||
3325 | def run(self, dataOut, phaseOffsets, hmin = 50, hmax = 150, azimuth = 45, channelPositions = None): |
|
3325 | def run(self, dataOut, phaseOffsets, hmin = 50, hmax = 150, azimuth = 45, channelPositions = None): | |
3326 |
|
3326 | |||
3327 | arrayParameters = dataOut.data_param |
|
3327 | arrayParameters = dataOut.data_param | |
3328 | pairsList = [] |
|
3328 | pairsList = [] | |
3329 | pairx = (0,1) |
|
3329 | pairx = (0,1) | |
3330 | pairy = (2,3) |
|
3330 | pairy = (2,3) | |
3331 | pairsList.append(pairx) |
|
3331 | pairsList.append(pairx) | |
3332 | pairsList.append(pairy) |
|
3332 | pairsList.append(pairy) | |
3333 | jph = numpy.zeros(4) |
|
3333 | jph = numpy.zeros(4) | |
3334 |
|
3334 | |||
3335 | phaseOffsets = numpy.array(phaseOffsets)*numpy.pi/180 |
|
3335 | phaseOffsets = numpy.array(phaseOffsets)*numpy.pi/180 | |
3336 | # arrayParameters[:,8:12] = numpy.unwrap(arrayParameters[:,8:12] + phaseOffsets) |
|
3336 | # arrayParameters[:,8:12] = numpy.unwrap(arrayParameters[:,8:12] + phaseOffsets) | |
3337 | arrayParameters[:,8:12] = numpy.angle(numpy.exp(1j*(arrayParameters[:,8:12] + phaseOffsets))) |
|
3337 | arrayParameters[:,8:12] = numpy.angle(numpy.exp(1j*(arrayParameters[:,8:12] + phaseOffsets))) | |
3338 |
|
3338 | |||
3339 | meteorOps = SMOperations() |
|
3339 | meteorOps = SMOperations() | |
3340 | if channelPositions is None: |
|
3340 | if channelPositions is None: | |
3341 | # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T |
|
3341 | # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T | |
3342 | channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella |
|
3342 | channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella | |
3343 |
|
3343 | |||
3344 | pairslist0, distances = meteorOps.getPhasePairs(channelPositions) |
|
3344 | pairslist0, distances = meteorOps.getPhasePairs(channelPositions) | |
3345 | h = (hmin,hmax) |
|
3345 | h = (hmin,hmax) | |
3346 |
|
3346 | |||
3347 | arrayParameters = meteorOps.getMeteorParams(arrayParameters, azimuth, h, pairsList, distances, jph) |
|
3347 | arrayParameters = meteorOps.getMeteorParams(arrayParameters, azimuth, h, pairsList, distances, jph) | |
3348 |
|
3348 | |||
3349 | dataOut.data_param = arrayParameters |
|
3349 | dataOut.data_param = arrayParameters | |
3350 | return |
|
3350 | return | |
3351 |
|
3351 | |||
3352 | class SMPhaseCalibration(Operation): |
|
3352 | class SMPhaseCalibration(Operation): | |
3353 |
|
3353 | |||
3354 | __buffer = None |
|
3354 | __buffer = None | |
3355 |
|
3355 | |||
3356 | __initime = None |
|
3356 | __initime = None | |
3357 |
|
3357 | |||
3358 | __dataReady = False |
|
3358 | __dataReady = False | |
3359 |
|
3359 | |||
3360 | __isConfig = False |
|
3360 | __isConfig = False | |
3361 |
|
3361 | |||
3362 | def __checkTime(self, currentTime, initTime, paramInterval, outputInterval): |
|
3362 | def __checkTime(self, currentTime, initTime, paramInterval, outputInterval): | |
3363 |
|
3363 | |||
3364 | dataTime = currentTime + paramInterval |
|
3364 | dataTime = currentTime + paramInterval | |
3365 | deltaTime = dataTime - initTime |
|
3365 | deltaTime = dataTime - initTime | |
3366 |
|
3366 | |||
3367 | if deltaTime >= outputInterval or deltaTime < 0: |
|
3367 | if deltaTime >= outputInterval or deltaTime < 0: | |
3368 | return True |
|
3368 | return True | |
3369 |
|
3369 | |||
3370 | return False |
|
3370 | return False | |
3371 |
|
3371 | |||
3372 | def __getGammas(self, pairs, d, phases): |
|
3372 | def __getGammas(self, pairs, d, phases): | |
3373 | gammas = numpy.zeros(2) |
|
3373 | gammas = numpy.zeros(2) | |
3374 |
|
3374 | |||
3375 | for i in range(len(pairs)): |
|
3375 | for i in range(len(pairs)): | |
3376 |
|
3376 | |||
3377 | pairi = pairs[i] |
|
3377 | pairi = pairs[i] | |
3378 |
|
3378 | |||
3379 | phip3 = phases[:,pairi[0]] |
|
3379 | phip3 = phases[:,pairi[0]] | |
3380 | d3 = d[pairi[0]] |
|
3380 | d3 = d[pairi[0]] | |
3381 | phip2 = phases[:,pairi[1]] |
|
3381 | phip2 = phases[:,pairi[1]] | |
3382 | d2 = d[pairi[1]] |
|
3382 | d2 = d[pairi[1]] | |
3383 | #Calculating gamma |
|
3383 | #Calculating gamma | |
3384 | # jdcos = alp1/(k*d1) |
|
3384 | # jdcos = alp1/(k*d1) | |
3385 | # jgamma = numpy.angle(numpy.exp(1j*(d0*alp1/d1 - alp0))) |
|
3385 | # jgamma = numpy.angle(numpy.exp(1j*(d0*alp1/d1 - alp0))) | |
3386 | jgamma = -phip2*d3/d2 - phip3 |
|
3386 | jgamma = -phip2*d3/d2 - phip3 | |
3387 | jgamma = numpy.angle(numpy.exp(1j*jgamma)) |
|
3387 | jgamma = numpy.angle(numpy.exp(1j*jgamma)) | |
3388 | # jgamma[jgamma>numpy.pi] -= 2*numpy.pi |
|
3388 | # jgamma[jgamma>numpy.pi] -= 2*numpy.pi | |
3389 | # jgamma[jgamma<-numpy.pi] += 2*numpy.pi |
|
3389 | # jgamma[jgamma<-numpy.pi] += 2*numpy.pi | |
3390 |
|
3390 | |||
3391 | #Revised distribution |
|
3391 | #Revised distribution | |
3392 | jgammaArray = numpy.hstack((jgamma,jgamma+0.5*numpy.pi,jgamma-0.5*numpy.pi)) |
|
3392 | jgammaArray = numpy.hstack((jgamma,jgamma+0.5*numpy.pi,jgamma-0.5*numpy.pi)) | |
3393 |
|
3393 | |||
3394 | #Histogram |
|
3394 | #Histogram | |
3395 | nBins = 64 |
|
3395 | nBins = 64 | |
3396 | rmin = -0.5*numpy.pi |
|
3396 | rmin = -0.5*numpy.pi | |
3397 | rmax = 0.5*numpy.pi |
|
3397 | rmax = 0.5*numpy.pi | |
3398 | phaseHisto = numpy.histogram(jgammaArray, bins=nBins, range=(rmin,rmax)) |
|
3398 | phaseHisto = numpy.histogram(jgammaArray, bins=nBins, range=(rmin,rmax)) | |
3399 |
|
3399 | |||
3400 | meteorsY = phaseHisto[0] |
|
3400 | meteorsY = phaseHisto[0] | |
3401 | phasesX = phaseHisto[1][:-1] |
|
3401 | phasesX = phaseHisto[1][:-1] | |
3402 | width = phasesX[1] - phasesX[0] |
|
3402 | width = phasesX[1] - phasesX[0] | |
3403 | phasesX += width/2 |
|
3403 | phasesX += width/2 | |
3404 |
|
3404 | |||
3405 | #Gaussian aproximation |
|
3405 | #Gaussian aproximation | |
3406 | bpeak = meteorsY.argmax() |
|
3406 | bpeak = meteorsY.argmax() | |
3407 | peak = meteorsY.max() |
|
3407 | peak = meteorsY.max() | |
3408 | jmin = bpeak - 5 |
|
3408 | jmin = bpeak - 5 | |
3409 | jmax = bpeak + 5 + 1 |
|
3409 | jmax = bpeak + 5 + 1 | |
3410 |
|
3410 | |||
3411 | if jmin<0: |
|
3411 | if jmin<0: | |
3412 | jmin = 0 |
|
3412 | jmin = 0 | |
3413 | jmax = 6 |
|
3413 | jmax = 6 | |
3414 | elif jmax > meteorsY.size: |
|
3414 | elif jmax > meteorsY.size: | |
3415 | jmin = meteorsY.size - 6 |
|
3415 | jmin = meteorsY.size - 6 | |
3416 | jmax = meteorsY.size |
|
3416 | jmax = meteorsY.size | |
3417 |
|
3417 | |||
3418 | x0 = numpy.array([peak,bpeak,50]) |
|
3418 | x0 = numpy.array([peak,bpeak,50]) | |
3419 | coeff = optimize.leastsq(self.__residualFunction, x0, args=(meteorsY[jmin:jmax], phasesX[jmin:jmax])) |
|
3419 | coeff = optimize.leastsq(self.__residualFunction, x0, args=(meteorsY[jmin:jmax], phasesX[jmin:jmax])) | |
3420 |
|
3420 | |||
3421 | #Gammas |
|
3421 | #Gammas | |
3422 | gammas[i] = coeff[0][1] |
|
3422 | gammas[i] = coeff[0][1] | |
3423 |
|
3423 | |||
3424 | return gammas |
|
3424 | return gammas | |
3425 |
|
3425 | |||
3426 | def __residualFunction(self, coeffs, y, t): |
|
3426 | def __residualFunction(self, coeffs, y, t): | |
3427 |
|
3427 | |||
3428 | return y - self.__gauss_function(t, coeffs) |
|
3428 | return y - self.__gauss_function(t, coeffs) | |
3429 |
|
3429 | |||
3430 | def __gauss_function(self, t, coeffs): |
|
3430 | def __gauss_function(self, t, coeffs): | |
3431 |
|
3431 | |||
3432 | return coeffs[0]*numpy.exp(-0.5*((t - coeffs[1]) / coeffs[2])**2) |
|
3432 | return coeffs[0]*numpy.exp(-0.5*((t - coeffs[1]) / coeffs[2])**2) | |
3433 |
|
3433 | |||
3434 | def __getPhases(self, azimuth, h, pairsList, d, gammas, meteorsArray): |
|
3434 | def __getPhases(self, azimuth, h, pairsList, d, gammas, meteorsArray): | |
3435 | meteorOps = SMOperations() |
|
3435 | meteorOps = SMOperations() | |
3436 | nchan = 4 |
|
3436 | nchan = 4 | |
3437 | pairx = pairsList[0] #x es 0 |
|
3437 | pairx = pairsList[0] #x es 0 | |
3438 | pairy = pairsList[1] #y es 1 |
|
3438 | pairy = pairsList[1] #y es 1 | |
3439 | center_xangle = 0 |
|
3439 | center_xangle = 0 | |
3440 | center_yangle = 0 |
|
3440 | center_yangle = 0 | |
3441 | range_angle = numpy.array([10*numpy.pi,numpy.pi,numpy.pi/2,numpy.pi/4]) |
|
3441 | range_angle = numpy.array([10*numpy.pi,numpy.pi,numpy.pi/2,numpy.pi/4]) | |
3442 | ntimes = len(range_angle) |
|
3442 | ntimes = len(range_angle) | |
3443 |
|
3443 | |||
3444 | nstepsx = 20 |
|
3444 | nstepsx = 20 | |
3445 | nstepsy = 20 |
|
3445 | nstepsy = 20 | |
3446 |
|
3446 | |||
3447 | for iz in range(ntimes): |
|
3447 | for iz in range(ntimes): | |
3448 | min_xangle = -range_angle[iz]/2 + center_xangle |
|
3448 | min_xangle = -range_angle[iz]/2 + center_xangle | |
3449 | max_xangle = range_angle[iz]/2 + center_xangle |
|
3449 | max_xangle = range_angle[iz]/2 + center_xangle | |
3450 | min_yangle = -range_angle[iz]/2 + center_yangle |
|
3450 | min_yangle = -range_angle[iz]/2 + center_yangle | |
3451 | max_yangle = range_angle[iz]/2 + center_yangle |
|
3451 | max_yangle = range_angle[iz]/2 + center_yangle | |
3452 |
|
3452 | |||
3453 | inc_x = (max_xangle-min_xangle)/nstepsx |
|
3453 | inc_x = (max_xangle-min_xangle)/nstepsx | |
3454 | inc_y = (max_yangle-min_yangle)/nstepsy |
|
3454 | inc_y = (max_yangle-min_yangle)/nstepsy | |
3455 |
|
3455 | |||
3456 | alpha_y = numpy.arange(nstepsy)*inc_y + min_yangle |
|
3456 | alpha_y = numpy.arange(nstepsy)*inc_y + min_yangle | |
3457 | alpha_x = numpy.arange(nstepsx)*inc_x + min_xangle |
|
3457 | alpha_x = numpy.arange(nstepsx)*inc_x + min_xangle | |
3458 | penalty = numpy.zeros((nstepsx,nstepsy)) |
|
3458 | penalty = numpy.zeros((nstepsx,nstepsy)) | |
3459 | jph_array = numpy.zeros((nchan,nstepsx,nstepsy)) |
|
3459 | jph_array = numpy.zeros((nchan,nstepsx,nstepsy)) | |
3460 | jph = numpy.zeros(nchan) |
|
3460 | jph = numpy.zeros(nchan) | |
3461 |
|
3461 | |||
3462 | # Iterations looking for the offset |
|
3462 | # Iterations looking for the offset | |
3463 | for iy in range(int(nstepsy)): |
|
3463 | for iy in range(int(nstepsy)): | |
3464 | for ix in range(int(nstepsx)): |
|
3464 | for ix in range(int(nstepsx)): | |
3465 | d3 = d[pairsList[1][0]] |
|
3465 | d3 = d[pairsList[1][0]] | |
3466 | d2 = d[pairsList[1][1]] |
|
3466 | d2 = d[pairsList[1][1]] | |
3467 | d5 = d[pairsList[0][0]] |
|
3467 | d5 = d[pairsList[0][0]] | |
3468 | d4 = d[pairsList[0][1]] |
|
3468 | d4 = d[pairsList[0][1]] | |
3469 |
|
3469 | |||
3470 | alp2 = alpha_y[iy] #gamma 1 |
|
3470 | alp2 = alpha_y[iy] #gamma 1 | |
3471 | alp4 = alpha_x[ix] #gamma 0 |
|
3471 | alp4 = alpha_x[ix] #gamma 0 | |
3472 |
|
3472 | |||
3473 | alp3 = -alp2*d3/d2 - gammas[1] |
|
3473 | alp3 = -alp2*d3/d2 - gammas[1] | |
3474 | alp5 = -alp4*d5/d4 - gammas[0] |
|
3474 | alp5 = -alp4*d5/d4 - gammas[0] | |
3475 | # jph[pairy[1]] = alpha_y[iy] |
|
3475 | # jph[pairy[1]] = alpha_y[iy] | |
3476 | # jph[pairy[0]] = -gammas[1] - alpha_y[iy]*d[pairy[1]]/d[pairy[0]] |
|
3476 | # jph[pairy[0]] = -gammas[1] - alpha_y[iy]*d[pairy[1]]/d[pairy[0]] | |
3477 |
|
3477 | |||
3478 | # jph[pairx[1]] = alpha_x[ix] |
|
3478 | # jph[pairx[1]] = alpha_x[ix] | |
3479 | # jph[pairx[0]] = -gammas[0] - alpha_x[ix]*d[pairx[1]]/d[pairx[0]] |
|
3479 | # jph[pairx[0]] = -gammas[0] - alpha_x[ix]*d[pairx[1]]/d[pairx[0]] | |
3480 | jph[pairsList[0][1]] = alp4 |
|
3480 | jph[pairsList[0][1]] = alp4 | |
3481 | jph[pairsList[0][0]] = alp5 |
|
3481 | jph[pairsList[0][0]] = alp5 | |
3482 | jph[pairsList[1][0]] = alp3 |
|
3482 | jph[pairsList[1][0]] = alp3 | |
3483 | jph[pairsList[1][1]] = alp2 |
|
3483 | jph[pairsList[1][1]] = alp2 | |
3484 | jph_array[:,ix,iy] = jph |
|
3484 | jph_array[:,ix,iy] = jph | |
3485 | # d = [2.0,2.5,2.5,2.0] |
|
3485 | # d = [2.0,2.5,2.5,2.0] | |
3486 | #falta chequear si va a leer bien los meteoros |
|
3486 | #falta chequear si va a leer bien los meteoros | |
3487 | meteorsArray1 = meteorOps.getMeteorParams(meteorsArray, azimuth, h, pairsList, d, jph) |
|
3487 | meteorsArray1 = meteorOps.getMeteorParams(meteorsArray, azimuth, h, pairsList, d, jph) | |
3488 | error = meteorsArray1[:,-1] |
|
3488 | error = meteorsArray1[:,-1] | |
3489 | ind1 = numpy.where(error==0)[0] |
|
3489 | ind1 = numpy.where(error==0)[0] | |
3490 | penalty[ix,iy] = ind1.size |
|
3490 | penalty[ix,iy] = ind1.size | |
3491 |
|
3491 | |||
3492 | i,j = numpy.unravel_index(penalty.argmax(), penalty.shape) |
|
3492 | i,j = numpy.unravel_index(penalty.argmax(), penalty.shape) | |
3493 | phOffset = jph_array[:,i,j] |
|
3493 | phOffset = jph_array[:,i,j] | |
3494 |
|
3494 | |||
3495 | center_xangle = phOffset[pairx[1]] |
|
3495 | center_xangle = phOffset[pairx[1]] | |
3496 | center_yangle = phOffset[pairy[1]] |
|
3496 | center_yangle = phOffset[pairy[1]] | |
3497 |
|
3497 | |||
3498 | phOffset = numpy.angle(numpy.exp(1j*jph_array[:,i,j])) |
|
3498 | phOffset = numpy.angle(numpy.exp(1j*jph_array[:,i,j])) | |
3499 | phOffset = phOffset*180/numpy.pi |
|
3499 | phOffset = phOffset*180/numpy.pi | |
3500 | return phOffset |
|
3500 | return phOffset | |
3501 |
|
3501 | |||
3502 |
|
3502 | |||
3503 | def run(self, dataOut, hmin, hmax, channelPositions=None, nHours = 1): |
|
3503 | def run(self, dataOut, hmin, hmax, channelPositions=None, nHours = 1): | |
3504 |
|
3504 | |||
3505 | dataOut.flagNoData = True |
|
3505 | dataOut.flagNoData = True | |
3506 | self.__dataReady = False |
|
3506 | self.__dataReady = False | |
3507 | dataOut.outputInterval = nHours*3600 |
|
3507 | dataOut.outputInterval = nHours*3600 | |
3508 |
|
3508 | |||
3509 | if self.__isConfig == False: |
|
3509 | if self.__isConfig == False: | |
3510 | # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03) |
|
3510 | # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03) | |
3511 | #Get Initial LTC time |
|
3511 | #Get Initial LTC time | |
3512 | self.__initime = datetime.datetime.utcfromtimestamp(dataOut.utctime) |
|
3512 | self.__initime = datetime.datetime.utcfromtimestamp(dataOut.utctime) | |
3513 | self.__initime = (self.__initime.replace(minute = 0, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds() |
|
3513 | self.__initime = (self.__initime.replace(minute = 0, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds() | |
3514 |
|
3514 | |||
3515 | self.__isConfig = True |
|
3515 | self.__isConfig = True | |
3516 |
|
3516 | |||
3517 | if self.__buffer is None: |
|
3517 | if self.__buffer is None: | |
3518 | self.__buffer = dataOut.data_param.copy() |
|
3518 | self.__buffer = dataOut.data_param.copy() | |
3519 |
|
3519 | |||
3520 | else: |
|
3520 | else: | |
3521 | self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param)) |
|
3521 | self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param)) | |
3522 |
|
3522 | |||
3523 | self.__dataReady = self.__checkTime(dataOut.utctime, self.__initime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready |
|
3523 | self.__dataReady = self.__checkTime(dataOut.utctime, self.__initime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready | |
3524 |
|
3524 | |||
3525 | if self.__dataReady: |
|
3525 | if self.__dataReady: | |
3526 | dataOut.utctimeInit = self.__initime |
|
3526 | dataOut.utctimeInit = self.__initime | |
3527 | self.__initime += dataOut.outputInterval #to erase time offset |
|
3527 | self.__initime += dataOut.outputInterval #to erase time offset | |
3528 |
|
3528 | |||
3529 | freq = dataOut.frequency |
|
3529 | freq = dataOut.frequency | |
3530 | c = dataOut.C #m/s |
|
3530 | c = dataOut.C #m/s | |
3531 | lamb = c/freq |
|
3531 | lamb = c/freq | |
3532 | k = 2*numpy.pi/lamb |
|
3532 | k = 2*numpy.pi/lamb | |
3533 | azimuth = 0 |
|
3533 | azimuth = 0 | |
3534 | h = (hmin, hmax) |
|
3534 | h = (hmin, hmax) | |
3535 | # pairs = ((0,1),(2,3)) #Estrella |
|
3535 | # pairs = ((0,1),(2,3)) #Estrella | |
3536 | # pairs = ((1,0),(2,3)) #T |
|
3536 | # pairs = ((1,0),(2,3)) #T | |
3537 |
|
3537 | |||
3538 | if channelPositions is None: |
|
3538 | if channelPositions is None: | |
3539 | # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T |
|
3539 | # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T | |
3540 | channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella |
|
3540 | channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella | |
3541 | meteorOps = SMOperations() |
|
3541 | meteorOps = SMOperations() | |
3542 | pairslist0, distances = meteorOps.getPhasePairs(channelPositions) |
|
3542 | pairslist0, distances = meteorOps.getPhasePairs(channelPositions) | |
3543 |
|
3543 | |||
3544 | #Checking correct order of pairs |
|
3544 | #Checking correct order of pairs | |
3545 | pairs = [] |
|
3545 | pairs = [] | |
3546 | if distances[1] > distances[0]: |
|
3546 | if distances[1] > distances[0]: | |
3547 | pairs.append((1,0)) |
|
3547 | pairs.append((1,0)) | |
3548 | else: |
|
3548 | else: | |
3549 | pairs.append((0,1)) |
|
3549 | pairs.append((0,1)) | |
3550 |
|
3550 | |||
3551 | if distances[3] > distances[2]: |
|
3551 | if distances[3] > distances[2]: | |
3552 | pairs.append((3,2)) |
|
3552 | pairs.append((3,2)) | |
3553 | else: |
|
3553 | else: | |
3554 | pairs.append((2,3)) |
|
3554 | pairs.append((2,3)) | |
3555 | # distances1 = [-distances[0]*lamb, distances[1]*lamb, -distances[2]*lamb, distances[3]*lamb] |
|
3555 | # distances1 = [-distances[0]*lamb, distances[1]*lamb, -distances[2]*lamb, distances[3]*lamb] | |
3556 |
|
3556 | |||
3557 | meteorsArray = self.__buffer |
|
3557 | meteorsArray = self.__buffer | |
3558 | error = meteorsArray[:,-1] |
|
3558 | error = meteorsArray[:,-1] | |
3559 | boolError = (error==0)|(error==3)|(error==4)|(error==13)|(error==14) |
|
3559 | boolError = (error==0)|(error==3)|(error==4)|(error==13)|(error==14) | |
3560 | ind1 = numpy.where(boolError)[0] |
|
3560 | ind1 = numpy.where(boolError)[0] | |
3561 | meteorsArray = meteorsArray[ind1,:] |
|
3561 | meteorsArray = meteorsArray[ind1,:] | |
3562 | meteorsArray[:,-1] = 0 |
|
3562 | meteorsArray[:,-1] = 0 | |
3563 | phases = meteorsArray[:,8:12] |
|
3563 | phases = meteorsArray[:,8:12] | |
3564 |
|
3564 | |||
3565 | #Calculate Gammas |
|
3565 | #Calculate Gammas | |
3566 | gammas = self.__getGammas(pairs, distances, phases) |
|
3566 | gammas = self.__getGammas(pairs, distances, phases) | |
3567 | # gammas = numpy.array([-21.70409463,45.76935864])*numpy.pi/180 |
|
3567 | # gammas = numpy.array([-21.70409463,45.76935864])*numpy.pi/180 | |
3568 | #Calculate Phases |
|
3568 | #Calculate Phases | |
3569 | phasesOff = self.__getPhases(azimuth, h, pairs, distances, gammas, meteorsArray) |
|
3569 | phasesOff = self.__getPhases(azimuth, h, pairs, distances, gammas, meteorsArray) | |
3570 | phasesOff = phasesOff.reshape((1,phasesOff.size)) |
|
3570 | phasesOff = phasesOff.reshape((1,phasesOff.size)) | |
3571 | dataOut.data_output = -phasesOff |
|
3571 | dataOut.data_output = -phasesOff | |
3572 | dataOut.flagNoData = False |
|
3572 | dataOut.flagNoData = False | |
3573 | self.__buffer = None |
|
3573 | self.__buffer = None | |
3574 |
|
3574 | |||
3575 |
|
3575 | |||
3576 | return |
|
3576 | return | |
3577 |
|
3577 | |||
3578 | class SMOperations(): |
|
3578 | class SMOperations(): | |
3579 |
|
3579 | |||
3580 | def __init__(self): |
|
3580 | def __init__(self): | |
3581 |
|
3581 | |||
3582 | return |
|
3582 | return | |
3583 |
|
3583 | |||
3584 | def getMeteorParams(self, arrayParameters0, azimuth, h, pairsList, distances, jph): |
|
3584 | def getMeteorParams(self, arrayParameters0, azimuth, h, pairsList, distances, jph): | |
3585 |
|
3585 | |||
3586 | arrayParameters = arrayParameters0.copy() |
|
3586 | arrayParameters = arrayParameters0.copy() | |
3587 | hmin = h[0] |
|
3587 | hmin = h[0] | |
3588 | hmax = h[1] |
|
3588 | hmax = h[1] | |
3589 |
|
3589 | |||
3590 | #Calculate AOA (Error N 3, 4) |
|
3590 | #Calculate AOA (Error N 3, 4) | |
3591 | #JONES ET AL. 1998 |
|
3591 | #JONES ET AL. 1998 | |
3592 | AOAthresh = numpy.pi/8 |
|
3592 | AOAthresh = numpy.pi/8 | |
3593 | error = arrayParameters[:,-1] |
|
3593 | error = arrayParameters[:,-1] | |
3594 | phases = -arrayParameters[:,8:12] + jph |
|
3594 | phases = -arrayParameters[:,8:12] + jph | |
3595 | # phases = numpy.unwrap(phases) |
|
3595 | # phases = numpy.unwrap(phases) | |
3596 | arrayParameters[:,3:6], arrayParameters[:,-1] = self.__getAOA(phases, pairsList, distances, error, AOAthresh, azimuth) |
|
3596 | arrayParameters[:,3:6], arrayParameters[:,-1] = self.__getAOA(phases, pairsList, distances, error, AOAthresh, azimuth) | |
3597 |
|
3597 | |||
3598 | #Calculate Heights (Error N 13 and 14) |
|
3598 | #Calculate Heights (Error N 13 and 14) | |
3599 | error = arrayParameters[:,-1] |
|
3599 | error = arrayParameters[:,-1] | |
3600 | Ranges = arrayParameters[:,1] |
|
3600 | Ranges = arrayParameters[:,1] | |
3601 | zenith = arrayParameters[:,4] |
|
3601 | zenith = arrayParameters[:,4] | |
3602 | arrayParameters[:,2], arrayParameters[:,-1] = self.__getHeights(Ranges, zenith, error, hmin, hmax) |
|
3602 | arrayParameters[:,2], arrayParameters[:,-1] = self.__getHeights(Ranges, zenith, error, hmin, hmax) | |
3603 |
|
3603 | |||
3604 | #----------------------- Get Final data ------------------------------------ |
|
3604 | #----------------------- Get Final data ------------------------------------ | |
3605 | # error = arrayParameters[:,-1] |
|
3605 | # error = arrayParameters[:,-1] | |
3606 | # ind1 = numpy.where(error==0)[0] |
|
3606 | # ind1 = numpy.where(error==0)[0] | |
3607 | # arrayParameters = arrayParameters[ind1,:] |
|
3607 | # arrayParameters = arrayParameters[ind1,:] | |
3608 |
|
3608 | |||
3609 | return arrayParameters |
|
3609 | return arrayParameters | |
3610 |
|
3610 | |||
3611 | def __getAOA(self, phases, pairsList, directions, error, AOAthresh, azimuth): |
|
3611 | def __getAOA(self, phases, pairsList, directions, error, AOAthresh, azimuth): | |
3612 |
|
3612 | |||
3613 | arrayAOA = numpy.zeros((phases.shape[0],3)) |
|
3613 | arrayAOA = numpy.zeros((phases.shape[0],3)) | |
3614 | cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList,directions) |
|
3614 | cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList,directions) | |
3615 |
|
3615 | |||
3616 | arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth) |
|
3616 | arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth) | |
3617 | cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1) |
|
3617 | cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1) | |
3618 | arrayAOA[:,2] = cosDirError |
|
3618 | arrayAOA[:,2] = cosDirError | |
3619 |
|
3619 | |||
3620 | azimuthAngle = arrayAOA[:,0] |
|
3620 | azimuthAngle = arrayAOA[:,0] | |
3621 | zenithAngle = arrayAOA[:,1] |
|
3621 | zenithAngle = arrayAOA[:,1] | |
3622 |
|
3622 | |||
3623 | #Setting Error |
|
3623 | #Setting Error | |
3624 | indError = numpy.where(numpy.logical_or(error == 3, error == 4))[0] |
|
3624 | indError = numpy.where(numpy.logical_or(error == 3, error == 4))[0] | |
3625 | error[indError] = 0 |
|
3625 | error[indError] = 0 | |
3626 | #Number 3: AOA not fesible |
|
3626 | #Number 3: AOA not fesible | |
3627 | indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0] |
|
3627 | indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0] | |
3628 | error[indInvalid] = 3 |
|
3628 | error[indInvalid] = 3 | |
3629 | #Number 4: Large difference in AOAs obtained from different antenna baselines |
|
3629 | #Number 4: Large difference in AOAs obtained from different antenna baselines | |
3630 | indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0] |
|
3630 | indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0] | |
3631 | error[indInvalid] = 4 |
|
3631 | error[indInvalid] = 4 | |
3632 | return arrayAOA, error |
|
3632 | return arrayAOA, error | |
3633 |
|
3633 | |||
3634 | def __getDirectionCosines(self, arrayPhase, pairsList, distances): |
|
3634 | def __getDirectionCosines(self, arrayPhase, pairsList, distances): | |
3635 |
|
3635 | |||
3636 | #Initializing some variables |
|
3636 | #Initializing some variables | |
3637 | ang_aux = numpy.array([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])*2*numpy.pi |
|
3637 | ang_aux = numpy.array([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])*2*numpy.pi | |
3638 | ang_aux = ang_aux.reshape(1,ang_aux.size) |
|
3638 | ang_aux = ang_aux.reshape(1,ang_aux.size) | |
3639 |
|
3639 | |||
3640 | cosdir = numpy.zeros((arrayPhase.shape[0],2)) |
|
3640 | cosdir = numpy.zeros((arrayPhase.shape[0],2)) | |
3641 | cosdir0 = numpy.zeros((arrayPhase.shape[0],2)) |
|
3641 | cosdir0 = numpy.zeros((arrayPhase.shape[0],2)) | |
3642 |
|
3642 | |||
3643 |
|
3643 | |||
3644 | for i in range(2): |
|
3644 | for i in range(2): | |
3645 | ph0 = arrayPhase[:,pairsList[i][0]] |
|
3645 | ph0 = arrayPhase[:,pairsList[i][0]] | |
3646 | ph1 = arrayPhase[:,pairsList[i][1]] |
|
3646 | ph1 = arrayPhase[:,pairsList[i][1]] | |
3647 | d0 = distances[pairsList[i][0]] |
|
3647 | d0 = distances[pairsList[i][0]] | |
3648 | d1 = distances[pairsList[i][1]] |
|
3648 | d1 = distances[pairsList[i][1]] | |
3649 |
|
3649 | |||
3650 | ph0_aux = ph0 + ph1 |
|
3650 | ph0_aux = ph0 + ph1 | |
3651 | ph0_aux = numpy.angle(numpy.exp(1j*ph0_aux)) |
|
3651 | ph0_aux = numpy.angle(numpy.exp(1j*ph0_aux)) | |
3652 | # ph0_aux[ph0_aux > numpy.pi] -= 2*numpy.pi |
|
3652 | # ph0_aux[ph0_aux > numpy.pi] -= 2*numpy.pi | |
3653 | # ph0_aux[ph0_aux < -numpy.pi] += 2*numpy.pi |
|
3653 | # ph0_aux[ph0_aux < -numpy.pi] += 2*numpy.pi | |
3654 | #First Estimation |
|
3654 | #First Estimation | |
3655 | cosdir0[:,i] = (ph0_aux)/(2*numpy.pi*(d0 - d1)) |
|
3655 | cosdir0[:,i] = (ph0_aux)/(2*numpy.pi*(d0 - d1)) | |
3656 |
|
3656 | |||
3657 | #Most-Accurate Second Estimation |
|
3657 | #Most-Accurate Second Estimation | |
3658 | phi1_aux = ph0 - ph1 |
|
3658 | phi1_aux = ph0 - ph1 | |
3659 | phi1_aux = phi1_aux.reshape(phi1_aux.size,1) |
|
3659 | phi1_aux = phi1_aux.reshape(phi1_aux.size,1) | |
3660 | #Direction Cosine 1 |
|
3660 | #Direction Cosine 1 | |
3661 | cosdir1 = (phi1_aux + ang_aux)/(2*numpy.pi*(d0 + d1)) |
|
3661 | cosdir1 = (phi1_aux + ang_aux)/(2*numpy.pi*(d0 + d1)) | |
3662 |
|
3662 | |||
3663 | #Searching the correct Direction Cosine |
|
3663 | #Searching the correct Direction Cosine | |
3664 | cosdir0_aux = cosdir0[:,i] |
|
3664 | cosdir0_aux = cosdir0[:,i] | |
3665 | cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1) |
|
3665 | cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1) | |
3666 | #Minimum Distance |
|
3666 | #Minimum Distance | |
3667 | cosDiff = (cosdir1 - cosdir0_aux)**2 |
|
3667 | cosDiff = (cosdir1 - cosdir0_aux)**2 | |
3668 | indcos = cosDiff.argmin(axis = 1) |
|
3668 | indcos = cosDiff.argmin(axis = 1) | |
3669 | #Saving Value obtained |
|
3669 | #Saving Value obtained | |
3670 | cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos] |
|
3670 | cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos] | |
3671 |
|
3671 | |||
3672 | return cosdir0, cosdir |
|
3672 | return cosdir0, cosdir | |
3673 |
|
3673 | |||
3674 | def __calculateAOA(self, cosdir, azimuth): |
|
3674 | def __calculateAOA(self, cosdir, azimuth): | |
3675 | cosdirX = cosdir[:,0] |
|
3675 | cosdirX = cosdir[:,0] | |
3676 | cosdirY = cosdir[:,1] |
|
3676 | cosdirY = cosdir[:,1] | |
3677 |
|
3677 | |||
3678 | zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi |
|
3678 | zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi | |
3679 | azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth#0 deg north, 90 deg east |
|
3679 | azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth#0 deg north, 90 deg east | |
3680 | angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose() |
|
3680 | angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose() | |
3681 |
|
3681 | |||
3682 | return angles |
|
3682 | return angles | |
3683 |
|
3683 | |||
3684 | def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight): |
|
3684 | def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight): | |
3685 |
|
3685 | |||
3686 | Ramb = 375 #Ramb = c/(2*PRF) |
|
3686 | Ramb = 375 #Ramb = c/(2*PRF) | |
3687 | Re = 6371 #Earth Radius |
|
3687 | Re = 6371 #Earth Radius | |
3688 | heights = numpy.zeros(Ranges.shape) |
|
3688 | heights = numpy.zeros(Ranges.shape) | |
3689 |
|
3689 | |||
3690 | R_aux = numpy.array([0,1,2])*Ramb |
|
3690 | R_aux = numpy.array([0,1,2])*Ramb | |
3691 | R_aux = R_aux.reshape(1,R_aux.size) |
|
3691 | R_aux = R_aux.reshape(1,R_aux.size) | |
3692 |
|
3692 | |||
3693 | Ranges = Ranges.reshape(Ranges.size,1) |
|
3693 | Ranges = Ranges.reshape(Ranges.size,1) | |
3694 |
|
3694 | |||
3695 | Ri = Ranges + R_aux |
|
3695 | Ri = Ranges + R_aux | |
3696 | hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re |
|
3696 | hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re | |
3697 |
|
3697 | |||
3698 | #Check if there is a height between 70 and 110 km |
|
3698 | #Check if there is a height between 70 and 110 km | |
3699 | h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1) |
|
3699 | h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1) | |
3700 | ind_h = numpy.where(h_bool == 1)[0] |
|
3700 | ind_h = numpy.where(h_bool == 1)[0] | |
3701 |
|
3701 | |||
3702 | hCorr = hi[ind_h, :] |
|
3702 | hCorr = hi[ind_h, :] | |
3703 | ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight)) |
|
3703 | ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight)) | |
3704 |
|
3704 | |||
3705 | hCorr = hi[ind_hCorr][:len(ind_h)] |
|
3705 | hCorr = hi[ind_hCorr][:len(ind_h)] | |
3706 | heights[ind_h] = hCorr |
|
3706 | heights[ind_h] = hCorr | |
3707 |
|
3707 | |||
3708 | #Setting Error |
|
3708 | #Setting Error | |
3709 | #Number 13: Height unresolvable echo: not valid height within 70 to 110 km |
|
3709 | #Number 13: Height unresolvable echo: not valid height within 70 to 110 km | |
3710 | #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km |
|
3710 | #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km | |
3711 | indError = numpy.where(numpy.logical_or(error == 13, error == 14))[0] |
|
3711 | indError = numpy.where(numpy.logical_or(error == 13, error == 14))[0] | |
3712 | error[indError] = 0 |
|
3712 | error[indError] = 0 | |
3713 | indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0] |
|
3713 | indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0] | |
3714 | error[indInvalid2] = 14 |
|
3714 | error[indInvalid2] = 14 | |
3715 | indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0] |
|
3715 | indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0] | |
3716 | error[indInvalid1] = 13 |
|
3716 | error[indInvalid1] = 13 | |
3717 |
|
3717 | |||
3718 | return heights, error |
|
3718 | return heights, error | |
3719 |
|
3719 | |||
3720 | def getPhasePairs(self, channelPositions): |
|
3720 | def getPhasePairs(self, channelPositions): | |
3721 | chanPos = numpy.array(channelPositions) |
|
3721 | chanPos = numpy.array(channelPositions) | |
3722 | listOper = list(itertools.combinations(list(range(5)),2)) |
|
3722 | listOper = list(itertools.combinations(list(range(5)),2)) | |
3723 |
|
3723 | |||
3724 | distances = numpy.zeros(4) |
|
3724 | distances = numpy.zeros(4) | |
3725 | axisX = [] |
|
3725 | axisX = [] | |
3726 | axisY = [] |
|
3726 | axisY = [] | |
3727 | distX = numpy.zeros(3) |
|
3727 | distX = numpy.zeros(3) | |
3728 | distY = numpy.zeros(3) |
|
3728 | distY = numpy.zeros(3) | |
3729 | ix = 0 |
|
3729 | ix = 0 | |
3730 | iy = 0 |
|
3730 | iy = 0 | |
3731 |
|
3731 | |||
3732 | pairX = numpy.zeros((2,2)) |
|
3732 | pairX = numpy.zeros((2,2)) | |
3733 | pairY = numpy.zeros((2,2)) |
|
3733 | pairY = numpy.zeros((2,2)) | |
3734 |
|
3734 | |||
3735 | for i in range(len(listOper)): |
|
3735 | for i in range(len(listOper)): | |
3736 | pairi = listOper[i] |
|
3736 | pairi = listOper[i] | |
3737 |
|
3737 | |||
3738 | posDif = numpy.abs(chanPos[pairi[0],:] - chanPos[pairi[1],:]) |
|
3738 | posDif = numpy.abs(chanPos[pairi[0],:] - chanPos[pairi[1],:]) | |
3739 |
|
3739 | |||
3740 | if posDif[0] == 0: |
|
3740 | if posDif[0] == 0: | |
3741 | axisY.append(pairi) |
|
3741 | axisY.append(pairi) | |
3742 | distY[iy] = posDif[1] |
|
3742 | distY[iy] = posDif[1] | |
3743 | iy += 1 |
|
3743 | iy += 1 | |
3744 | elif posDif[1] == 0: |
|
3744 | elif posDif[1] == 0: | |
3745 | axisX.append(pairi) |
|
3745 | axisX.append(pairi) | |
3746 | distX[ix] = posDif[0] |
|
3746 | distX[ix] = posDif[0] | |
3747 | ix += 1 |
|
3747 | ix += 1 | |
3748 |
|
3748 | |||
3749 | for i in range(2): |
|
3749 | for i in range(2): | |
3750 | if i==0: |
|
3750 | if i==0: | |
3751 | dist0 = distX |
|
3751 | dist0 = distX | |
3752 | axis0 = axisX |
|
3752 | axis0 = axisX | |
3753 | else: |
|
3753 | else: | |
3754 | dist0 = distY |
|
3754 | dist0 = distY | |
3755 | axis0 = axisY |
|
3755 | axis0 = axisY | |
3756 |
|
3756 | |||
3757 | side = numpy.argsort(dist0)[:-1] |
|
3757 | side = numpy.argsort(dist0)[:-1] | |
3758 | axis0 = numpy.array(axis0)[side,:] |
|
3758 | axis0 = numpy.array(axis0)[side,:] | |
3759 | chanC = int(numpy.intersect1d(axis0[0,:], axis0[1,:])[0]) |
|
3759 | chanC = int(numpy.intersect1d(axis0[0,:], axis0[1,:])[0]) | |
3760 | axis1 = numpy.unique(numpy.reshape(axis0,4)) |
|
3760 | axis1 = numpy.unique(numpy.reshape(axis0,4)) | |
3761 | side = axis1[axis1 != chanC] |
|
3761 | side = axis1[axis1 != chanC] | |
3762 | diff1 = chanPos[chanC,i] - chanPos[side[0],i] |
|
3762 | diff1 = chanPos[chanC,i] - chanPos[side[0],i] | |
3763 | diff2 = chanPos[chanC,i] - chanPos[side[1],i] |
|
3763 | diff2 = chanPos[chanC,i] - chanPos[side[1],i] | |
3764 | if diff1<0: |
|
3764 | if diff1<0: | |
3765 | chan2 = side[0] |
|
3765 | chan2 = side[0] | |
3766 | d2 = numpy.abs(diff1) |
|
3766 | d2 = numpy.abs(diff1) | |
3767 | chan1 = side[1] |
|
3767 | chan1 = side[1] | |
3768 | d1 = numpy.abs(diff2) |
|
3768 | d1 = numpy.abs(diff2) | |
3769 | else: |
|
3769 | else: | |
3770 | chan2 = side[1] |
|
3770 | chan2 = side[1] | |
3771 | d2 = numpy.abs(diff2) |
|
3771 | d2 = numpy.abs(diff2) | |
3772 | chan1 = side[0] |
|
3772 | chan1 = side[0] | |
3773 | d1 = numpy.abs(diff1) |
|
3773 | d1 = numpy.abs(diff1) | |
3774 |
|
3774 | |||
3775 | if i==0: |
|
3775 | if i==0: | |
3776 | chanCX = chanC |
|
3776 | chanCX = chanC | |
3777 | chan1X = chan1 |
|
3777 | chan1X = chan1 | |
3778 | chan2X = chan2 |
|
3778 | chan2X = chan2 | |
3779 | distances[0:2] = numpy.array([d1,d2]) |
|
3779 | distances[0:2] = numpy.array([d1,d2]) | |
3780 | else: |
|
3780 | else: | |
3781 | chanCY = chanC |
|
3781 | chanCY = chanC | |
3782 | chan1Y = chan1 |
|
3782 | chan1Y = chan1 | |
3783 | chan2Y = chan2 |
|
3783 | chan2Y = chan2 | |
3784 | distances[2:4] = numpy.array([d1,d2]) |
|
3784 | distances[2:4] = numpy.array([d1,d2]) | |
3785 | # axisXsides = numpy.reshape(axisX[ix,:],4) |
|
3785 | # axisXsides = numpy.reshape(axisX[ix,:],4) | |
3786 | # |
|
3786 | # | |
3787 | # channelCentX = int(numpy.intersect1d(pairX[0,:], pairX[1,:])[0]) |
|
3787 | # channelCentX = int(numpy.intersect1d(pairX[0,:], pairX[1,:])[0]) | |
3788 | # channelCentY = int(numpy.intersect1d(pairY[0,:], pairY[1,:])[0]) |
|
3788 | # channelCentY = int(numpy.intersect1d(pairY[0,:], pairY[1,:])[0]) | |
3789 | # |
|
3789 | # | |
3790 | # ind25X = numpy.where(pairX[0,:] != channelCentX)[0][0] |
|
3790 | # ind25X = numpy.where(pairX[0,:] != channelCentX)[0][0] | |
3791 | # ind20X = numpy.where(pairX[1,:] != channelCentX)[0][0] |
|
3791 | # ind20X = numpy.where(pairX[1,:] != channelCentX)[0][0] | |
3792 | # channel25X = int(pairX[0,ind25X]) |
|
3792 | # channel25X = int(pairX[0,ind25X]) | |
3793 | # channel20X = int(pairX[1,ind20X]) |
|
3793 | # channel20X = int(pairX[1,ind20X]) | |
3794 | # ind25Y = numpy.where(pairY[0,:] != channelCentY)[0][0] |
|
3794 | # ind25Y = numpy.where(pairY[0,:] != channelCentY)[0][0] | |
3795 | # ind20Y = numpy.where(pairY[1,:] != channelCentY)[0][0] |
|
3795 | # ind20Y = numpy.where(pairY[1,:] != channelCentY)[0][0] | |
3796 | # channel25Y = int(pairY[0,ind25Y]) |
|
3796 | # channel25Y = int(pairY[0,ind25Y]) | |
3797 | # channel20Y = int(pairY[1,ind20Y]) |
|
3797 | # channel20Y = int(pairY[1,ind20Y]) | |
3798 |
|
3798 | |||
3799 | # pairslist = [(channelCentX, channel25X),(channelCentX, channel20X),(channelCentY,channel25Y),(channelCentY, channel20Y)] |
|
3799 | # pairslist = [(channelCentX, channel25X),(channelCentX, channel20X),(channelCentY,channel25Y),(channelCentY, channel20Y)] | |
3800 | pairslist = [(chanCX, chan1X),(chanCX, chan2X),(chanCY,chan1Y),(chanCY, chan2Y)] |
|
3800 | pairslist = [(chanCX, chan1X),(chanCX, chan2X),(chanCY,chan1Y),(chanCY, chan2Y)] | |
3801 |
|
3801 | |||
3802 | return pairslist, distances |
|
3802 | return pairslist, distances | |
3803 | # def __getAOA(self, phases, pairsList, error, AOAthresh, azimuth): |
|
3803 | # def __getAOA(self, phases, pairsList, error, AOAthresh, azimuth): | |
3804 | # |
|
3804 | # | |
3805 | # arrayAOA = numpy.zeros((phases.shape[0],3)) |
|
3805 | # arrayAOA = numpy.zeros((phases.shape[0],3)) | |
3806 | # cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList) |
|
3806 | # cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList) | |
3807 | # |
|
3807 | # | |
3808 | # arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth) |
|
3808 | # arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth) | |
3809 | # cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1) |
|
3809 | # cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1) | |
3810 | # arrayAOA[:,2] = cosDirError |
|
3810 | # arrayAOA[:,2] = cosDirError | |
3811 | # |
|
3811 | # | |
3812 | # azimuthAngle = arrayAOA[:,0] |
|
3812 | # azimuthAngle = arrayAOA[:,0] | |
3813 | # zenithAngle = arrayAOA[:,1] |
|
3813 | # zenithAngle = arrayAOA[:,1] | |
3814 | # |
|
3814 | # | |
3815 | # #Setting Error |
|
3815 | # #Setting Error | |
3816 | # #Number 3: AOA not fesible |
|
3816 | # #Number 3: AOA not fesible | |
3817 | # indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0] |
|
3817 | # indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0] | |
3818 | # error[indInvalid] = 3 |
|
3818 | # error[indInvalid] = 3 | |
3819 | # #Number 4: Large difference in AOAs obtained from different antenna baselines |
|
3819 | # #Number 4: Large difference in AOAs obtained from different antenna baselines | |
3820 | # indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0] |
|
3820 | # indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0] | |
3821 | # error[indInvalid] = 4 |
|
3821 | # error[indInvalid] = 4 | |
3822 | # return arrayAOA, error |
|
3822 | # return arrayAOA, error | |
3823 | # |
|
3823 | # | |
3824 | # def __getDirectionCosines(self, arrayPhase, pairsList): |
|
3824 | # def __getDirectionCosines(self, arrayPhase, pairsList): | |
3825 | # |
|
3825 | # | |
3826 | # #Initializing some variables |
|
3826 | # #Initializing some variables | |
3827 | # ang_aux = numpy.array([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])*2*numpy.pi |
|
3827 | # ang_aux = numpy.array([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])*2*numpy.pi | |
3828 | # ang_aux = ang_aux.reshape(1,ang_aux.size) |
|
3828 | # ang_aux = ang_aux.reshape(1,ang_aux.size) | |
3829 | # |
|
3829 | # | |
3830 | # cosdir = numpy.zeros((arrayPhase.shape[0],2)) |
|
3830 | # cosdir = numpy.zeros((arrayPhase.shape[0],2)) | |
3831 | # cosdir0 = numpy.zeros((arrayPhase.shape[0],2)) |
|
3831 | # cosdir0 = numpy.zeros((arrayPhase.shape[0],2)) | |
3832 | # |
|
3832 | # | |
3833 | # |
|
3833 | # | |
3834 | # for i in range(2): |
|
3834 | # for i in range(2): | |
3835 | # #First Estimation |
|
3835 | # #First Estimation | |
3836 | # phi0_aux = arrayPhase[:,pairsList[i][0]] + arrayPhase[:,pairsList[i][1]] |
|
3836 | # phi0_aux = arrayPhase[:,pairsList[i][0]] + arrayPhase[:,pairsList[i][1]] | |
3837 | # #Dealias |
|
3837 | # #Dealias | |
3838 | # indcsi = numpy.where(phi0_aux > numpy.pi) |
|
3838 | # indcsi = numpy.where(phi0_aux > numpy.pi) | |
3839 | # phi0_aux[indcsi] -= 2*numpy.pi |
|
3839 | # phi0_aux[indcsi] -= 2*numpy.pi | |
3840 | # indcsi = numpy.where(phi0_aux < -numpy.pi) |
|
3840 | # indcsi = numpy.where(phi0_aux < -numpy.pi) | |
3841 | # phi0_aux[indcsi] += 2*numpy.pi |
|
3841 | # phi0_aux[indcsi] += 2*numpy.pi | |
3842 | # #Direction Cosine 0 |
|
3842 | # #Direction Cosine 0 | |
3843 | # cosdir0[:,i] = -(phi0_aux)/(2*numpy.pi*0.5) |
|
3843 | # cosdir0[:,i] = -(phi0_aux)/(2*numpy.pi*0.5) | |
3844 | # |
|
3844 | # | |
3845 | # #Most-Accurate Second Estimation |
|
3845 | # #Most-Accurate Second Estimation | |
3846 | # phi1_aux = arrayPhase[:,pairsList[i][0]] - arrayPhase[:,pairsList[i][1]] |
|
3846 | # phi1_aux = arrayPhase[:,pairsList[i][0]] - arrayPhase[:,pairsList[i][1]] | |
3847 | # phi1_aux = phi1_aux.reshape(phi1_aux.size,1) |
|
3847 | # phi1_aux = phi1_aux.reshape(phi1_aux.size,1) | |
3848 | # #Direction Cosine 1 |
|
3848 | # #Direction Cosine 1 | |
3849 | # cosdir1 = -(phi1_aux + ang_aux)/(2*numpy.pi*4.5) |
|
3849 | # cosdir1 = -(phi1_aux + ang_aux)/(2*numpy.pi*4.5) | |
3850 | # |
|
3850 | # | |
3851 | # #Searching the correct Direction Cosine |
|
3851 | # #Searching the correct Direction Cosine | |
3852 | # cosdir0_aux = cosdir0[:,i] |
|
3852 | # cosdir0_aux = cosdir0[:,i] | |
3853 | # cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1) |
|
3853 | # cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1) | |
3854 | # #Minimum Distance |
|
3854 | # #Minimum Distance | |
3855 | # cosDiff = (cosdir1 - cosdir0_aux)**2 |
|
3855 | # cosDiff = (cosdir1 - cosdir0_aux)**2 | |
3856 | # indcos = cosDiff.argmin(axis = 1) |
|
3856 | # indcos = cosDiff.argmin(axis = 1) | |
3857 | # #Saving Value obtained |
|
3857 | # #Saving Value obtained | |
3858 | # cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos] |
|
3858 | # cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos] | |
3859 | # |
|
3859 | # | |
3860 | # return cosdir0, cosdir |
|
3860 | # return cosdir0, cosdir | |
3861 | # |
|
3861 | # | |
3862 | # def __calculateAOA(self, cosdir, azimuth): |
|
3862 | # def __calculateAOA(self, cosdir, azimuth): | |
3863 | # cosdirX = cosdir[:,0] |
|
3863 | # cosdirX = cosdir[:,0] | |
3864 | # cosdirY = cosdir[:,1] |
|
3864 | # cosdirY = cosdir[:,1] | |
3865 | # |
|
3865 | # | |
3866 | # zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi |
|
3866 | # zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi | |
3867 | # azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth #0 deg north, 90 deg east |
|
3867 | # azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth #0 deg north, 90 deg east | |
3868 | # angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose() |
|
3868 | # angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose() | |
3869 | # |
|
3869 | # | |
3870 | # return angles |
|
3870 | # return angles | |
3871 | # |
|
3871 | # | |
3872 | # def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight): |
|
3872 | # def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight): | |
3873 | # |
|
3873 | # | |
3874 | # Ramb = 375 #Ramb = c/(2*PRF) |
|
3874 | # Ramb = 375 #Ramb = c/(2*PRF) | |
3875 | # Re = 6371 #Earth Radius |
|
3875 | # Re = 6371 #Earth Radius | |
3876 | # heights = numpy.zeros(Ranges.shape) |
|
3876 | # heights = numpy.zeros(Ranges.shape) | |
3877 | # |
|
3877 | # | |
3878 | # R_aux = numpy.array([0,1,2])*Ramb |
|
3878 | # R_aux = numpy.array([0,1,2])*Ramb | |
3879 | # R_aux = R_aux.reshape(1,R_aux.size) |
|
3879 | # R_aux = R_aux.reshape(1,R_aux.size) | |
3880 | # |
|
3880 | # | |
3881 | # Ranges = Ranges.reshape(Ranges.size,1) |
|
3881 | # Ranges = Ranges.reshape(Ranges.size,1) | |
3882 | # |
|
3882 | # | |
3883 | # Ri = Ranges + R_aux |
|
3883 | # Ri = Ranges + R_aux | |
3884 | # hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re |
|
3884 | # hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re | |
3885 | # |
|
3885 | # | |
3886 | # #Check if there is a height between 70 and 110 km |
|
3886 | # #Check if there is a height between 70 and 110 km | |
3887 | # h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1) |
|
3887 | # h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1) | |
3888 | # ind_h = numpy.where(h_bool == 1)[0] |
|
3888 | # ind_h = numpy.where(h_bool == 1)[0] | |
3889 | # |
|
3889 | # | |
3890 | # hCorr = hi[ind_h, :] |
|
3890 | # hCorr = hi[ind_h, :] | |
3891 | # ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight)) |
|
3891 | # ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight)) | |
3892 | # |
|
3892 | # | |
3893 | # hCorr = hi[ind_hCorr] |
|
3893 | # hCorr = hi[ind_hCorr] | |
3894 | # heights[ind_h] = hCorr |
|
3894 | # heights[ind_h] = hCorr | |
3895 | # |
|
3895 | # | |
3896 | # #Setting Error |
|
3896 | # #Setting Error | |
3897 | # #Number 13: Height unresolvable echo: not valid height within 70 to 110 km |
|
3897 | # #Number 13: Height unresolvable echo: not valid height within 70 to 110 km | |
3898 | # #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km |
|
3898 | # #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km | |
3899 | # |
|
3899 | # | |
3900 | # indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0] |
|
3900 | # indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0] | |
3901 | # error[indInvalid2] = 14 |
|
3901 | # error[indInvalid2] = 14 | |
3902 | # indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0] |
|
3902 | # indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0] | |
3903 | # error[indInvalid1] = 13 |
|
3903 | # error[indInvalid1] = 13 | |
3904 | # |
|
3904 | # | |
3905 | # return heights, error |
|
3905 | # return heights, error | |
3906 |
|
3906 | |||
3907 |
|
3907 | |||
3908 | class WeatherRadar(Operation): |
|
3908 | class WeatherRadar(Operation): | |
3909 | ''' |
|
3909 | ''' | |
3910 | Function tat implements Weather Radar operations- |
|
3910 | Function tat implements Weather Radar operations- | |
3911 | Input: |
|
3911 | Input: | |
3912 | Output: |
|
3912 | Output: | |
3913 | Parameters affected: |
|
3913 | Parameters affected: | |
3914 | ''' |
|
3914 | ''' | |
3915 | isConfig = False |
|
3915 | isConfig = False | |
3916 | variableList = None |
|
3916 | variableList = None | |
3917 |
|
3917 | |||
3918 | def __init__(self): |
|
3918 | def __init__(self): | |
3919 | Operation.__init__(self) |
|
3919 | Operation.__init__(self) | |
3920 |
|
3920 | |||
3921 | def setup(self,dataOut,variableList= None,Pt=0,Gt=0,Gr=0,lambda_=0, aL=0, |
|
3921 | def setup(self,dataOut,variableList= None,Pt=0,Gt=0,Gr=0,lambda_=0, aL=0, | |
3922 | tauW= 0,thetaT=0,thetaR=0,Km =0): |
|
3922 | tauW= 0,thetaT=0,thetaR=0,Km =0): | |
3923 | self.nCh = dataOut.nChannels |
|
3923 | self.nCh = dataOut.nChannels | |
3924 | self.nHeis = dataOut.nHeights |
|
3924 | self.nHeis = dataOut.nHeights | |
3925 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
3925 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
3926 | self.Range = numpy.arange(dataOut.nHeights)*deltaHeight + dataOut.heightList[0] |
|
3926 | self.Range = numpy.arange(dataOut.nHeights)*deltaHeight + dataOut.heightList[0] | |
3927 | self.Range = self.Range.reshape(1,self.nHeis) |
|
3927 | self.Range = self.Range.reshape(1,self.nHeis) | |
3928 | self.Range = numpy.tile(self.Range,[self.nCh,1]) |
|
3928 | self.Range = numpy.tile(self.Range,[self.nCh,1]) | |
3929 | '''-----------1 Constante del Radar----------''' |
|
3929 | '''-----------1 Constante del Radar----------''' | |
3930 | self.Pt = Pt |
|
3930 | self.Pt = Pt | |
3931 | self.Gt = Gt |
|
3931 | self.Gt = Gt | |
3932 | self.Gr = Gr |
|
3932 | self.Gr = Gr | |
3933 | self.lambda_ = lambda_ |
|
3933 | self.lambda_ = lambda_ | |
3934 | self.aL = aL |
|
3934 | self.aL = aL | |
3935 | self.tauW = tauW |
|
3935 | self.tauW = tauW | |
3936 | self.thetaT = thetaT |
|
3936 | self.thetaT = thetaT | |
3937 | self.thetaR = thetaR |
|
3937 | self.thetaR = thetaR | |
3938 | self.Km = Km |
|
3938 | self.Km = Km | |
3939 | Numerator = ((4*numpy.pi)**3 * aL**2 * 16 *numpy.log(2)) |
|
3939 | Numerator = ((4*numpy.pi)**3 * aL**2 * 16 *numpy.log(2)) | |
3940 | Denominator = (Pt * Gt * Gr * lambda_**2 * SPEED_OF_LIGHT * tauW * numpy.pi*thetaT*thetaR) |
|
3940 | Denominator = (Pt * Gt * Gr * lambda_**2 * SPEED_OF_LIGHT * tauW * numpy.pi*thetaT*thetaR) | |
3941 | self.RadarConstant = Numerator/Denominator |
|
3941 | self.RadarConstant = Numerator/Denominator | |
3942 | self.variableList= variableList |
|
3942 | self.variableList= variableList | |
3943 |
|
3943 | |||
3944 | def setMoments(self,dataOut,i): |
|
3944 | def setMoments(self,dataOut,i): | |
3945 |
|
3945 | |||
3946 | type = dataOut.inputUnit |
|
3946 | type = dataOut.inputUnit | |
3947 | nCh = dataOut.nChannels |
|
3947 | nCh = dataOut.nChannels | |
3948 | nHeis = dataOut.nHeights |
|
3948 | nHeis = dataOut.nHeights | |
3949 | data_param = numpy.zeros((nCh,4,nHeis)) |
|
3949 | data_param = numpy.zeros((nCh,4,nHeis)) | |
3950 | if type == "Voltage": |
|
3950 | if type == "Voltage": | |
3951 | factor = dataOut.normFactor |
|
3951 | factor = dataOut.normFactor | |
3952 | data_param[:,0,:] = dataOut.dataPP_POW/(factor) |
|
3952 | data_param[:,0,:] = dataOut.dataPP_POW/(factor) | |
3953 | data_param[:,1,:] = dataOut.dataPP_DOP |
|
3953 | data_param[:,1,:] = dataOut.dataPP_DOP | |
3954 | data_param[:,2,:] = dataOut.dataPP_WIDTH |
|
3954 | data_param[:,2,:] = dataOut.dataPP_WIDTH | |
3955 | data_param[:,3,:] = dataOut.dataPP_SNR |
|
3955 | data_param[:,3,:] = dataOut.dataPP_SNR | |
3956 | if type == "Spectra": |
|
3956 | if type == "Spectra": | |
3957 | data_param[:,0,:] = dataOut.data_POW |
|
3957 | data_param[:,0,:] = dataOut.data_POW | |
3958 | data_param[:,1,:] = dataOut.data_DOP |
|
3958 | data_param[:,1,:] = dataOut.data_DOP | |
3959 | data_param[:,2,:] = dataOut.data_WIDTH |
|
3959 | data_param[:,2,:] = dataOut.data_WIDTH | |
3960 | data_param[:,3,:] = dataOut.data_SNR |
|
3960 | data_param[:,3,:] = dataOut.data_SNR | |
3961 |
|
3961 | |||
3962 | return data_param[:,i,:] |
|
3962 | return data_param[:,i,:] | |
3963 |
|
3963 | |||
3964 | def getCoeficienteCorrelacionROhv_R(self,dataOut): |
|
3964 | def getCoeficienteCorrelacionROhv_R(self,dataOut): | |
3965 | type = dataOut.inputUnit |
|
3965 | type = dataOut.inputUnit | |
3966 | nHeis = dataOut.nHeights |
|
3966 | nHeis = dataOut.nHeights | |
3967 | data_RhoHV_R = numpy.zeros((nHeis)) |
|
3967 | data_RhoHV_R = numpy.zeros((nHeis)) | |
3968 | if type == "Voltage": |
|
3968 | if type == "Voltage": | |
3969 | powa = dataOut.dataPP_POWER[0] |
|
3969 | powa = dataOut.dataPP_POWER[0] | |
3970 | powb = dataOut.dataPP_POWER[1] |
|
3970 | powb = dataOut.dataPP_POWER[1] | |
3971 | ccf = dataOut.dataPP_CCF |
|
3971 | ccf = dataOut.dataPP_CCF | |
3972 | avgcoherenceComplex = ccf / numpy.sqrt(powa * powb) |
|
3972 | avgcoherenceComplex = ccf / numpy.sqrt(powa * powb) | |
3973 | data_RhoHV_R = numpy.abs(avgcoherenceComplex) |
|
3973 | data_RhoHV_R = numpy.abs(avgcoherenceComplex) | |
3974 | if type == "Spectra": |
|
3974 | if type == "Spectra": | |
3975 | data_RhoHV_R = dataOut.getCoherence() |
|
3975 | data_RhoHV_R = dataOut.getCoherence() | |
3976 |
|
3976 | |||
3977 | return data_RhoHV_R |
|
3977 | return data_RhoHV_R | |
3978 |
|
3978 | |||
3979 | def getFasediferencialPhiD_P(self,dataOut,phase= True): |
|
3979 | def getFasediferencialPhiD_P(self,dataOut,phase= True): | |
3980 | type = dataOut.inputUnit |
|
3980 | type = dataOut.inputUnit | |
3981 | nHeis = dataOut.nHeights |
|
3981 | nHeis = dataOut.nHeights | |
3982 | data_PhiD_P = numpy.zeros((nHeis)) |
|
3982 | data_PhiD_P = numpy.zeros((nHeis)) | |
3983 | if type == "Voltage": |
|
3983 | if type == "Voltage": | |
3984 | powa = dataOut.dataPP_POWER[0] |
|
3984 | powa = dataOut.dataPP_POWER[0] | |
3985 | powb = dataOut.dataPP_POWER[1] |
|
3985 | powb = dataOut.dataPP_POWER[1] | |
3986 | ccf = dataOut.dataPP_CCF |
|
3986 | ccf = dataOut.dataPP_CCF | |
3987 | avgcoherenceComplex = ccf / numpy.sqrt(powa * powb) |
|
3987 | avgcoherenceComplex = ccf / numpy.sqrt(powa * powb) | |
3988 | if phase: |
|
3988 | if phase: | |
3989 | data_PhiD_P = numpy.arctan2(avgcoherenceComplex.imag, |
|
3989 | data_PhiD_P = numpy.arctan2(avgcoherenceComplex.imag, | |
3990 | avgcoherenceComplex.real) * 180 / numpy.pi |
|
3990 | avgcoherenceComplex.real) * 180 / numpy.pi | |
3991 | if type == "Spectra": |
|
3991 | if type == "Spectra": | |
3992 | data_PhiD_P = dataOut.getCoherence(phase = phase) |
|
3992 | data_PhiD_P = dataOut.getCoherence(phase = phase) | |
3993 |
|
3993 | |||
3994 | return data_PhiD_P |
|
3994 | return data_PhiD_P | |
3995 |
|
3995 | |||
3996 | def getReflectividad_D(self,dataOut): |
|
3996 | def getReflectividad_D(self,dataOut): | |
3997 | '''-----------------------------Potencia de Radar -Signal S-----------------------------''' |
|
3997 | '''-----------------------------Potencia de Radar -Signal S-----------------------------''' | |
3998 |
|
3998 | |||
3999 | Pr = self.setMoments(dataOut,0) |
|
3999 | Pr = self.setMoments(dataOut,0) | |
4000 |
|
4000 | |||
4001 | '''-----------2 Reflectividad del Radar y Factor de Reflectividad------''' |
|
4001 | '''-----------2 Reflectividad del Radar y Factor de Reflectividad------''' | |
4002 | self.n_radar = numpy.zeros((self.nCh,self.nHeis)) |
|
4002 | self.n_radar = numpy.zeros((self.nCh,self.nHeis)) | |
4003 | self.Z_radar = numpy.zeros((self.nCh,self.nHeis)) |
|
4003 | self.Z_radar = numpy.zeros((self.nCh,self.nHeis)) | |
4004 | for R in range(self.nHeis): |
|
4004 | for R in range(self.nHeis): | |
4005 | self.n_radar[:,R] = self.RadarConstant*Pr[:,R]* (self.Range[:,R])**2 |
|
4005 | self.n_radar[:,R] = self.RadarConstant*Pr[:,R]* (self.Range[:,R])**2 | |
4006 |
|
4006 | |||
4007 | self.Z_radar[:,R] = self.n_radar[:,R]* self.lambda_**4/( numpy.pi**5 * self.Km**2) |
|
4007 | self.Z_radar[:,R] = self.n_radar[:,R]* self.lambda_**4/( numpy.pi**5 * self.Km**2) | |
4008 |
|
4008 | |||
4009 | '''----------- Factor de Reflectividad Equivalente lamda_ < 10 cm , lamda_= 3.2cm-------''' |
|
4009 | '''----------- Factor de Reflectividad Equivalente lamda_ < 10 cm , lamda_= 3.2cm-------''' | |
4010 | Zeh = self.Z_radar |
|
4010 | Zeh = self.Z_radar | |
4011 | dBZeh = 10*numpy.log10(Zeh) |
|
4011 | dBZeh = 10*numpy.log10(Zeh) | |
4012 | Zdb_D = dBZeh[0] - dBZeh[1] |
|
4012 | Zdb_D = dBZeh[0] - dBZeh[1] | |
4013 | return Zdb_D |
|
4013 | return Zdb_D | |
4014 |
|
4014 | |||
4015 | def getRadialVelocity_V(self,dataOut): |
|
4015 | def getRadialVelocity_V(self,dataOut): | |
4016 | velRadial_V = self.setMoments(dataOut,1) |
|
4016 | velRadial_V = self.setMoments(dataOut,1) | |
4017 | return velRadial_V |
|
4017 | return velRadial_V | |
4018 |
|
4018 | |||
4019 | def getAnchoEspectral_W(self,dataOut): |
|
4019 | def getAnchoEspectral_W(self,dataOut): | |
4020 | Sigmav_W = self.setMoments(dataOut,2) |
|
4020 | Sigmav_W = self.setMoments(dataOut,2) | |
4021 | return Sigmav_W |
|
4021 | return Sigmav_W | |
4022 |
|
4022 | |||
4023 |
|
4023 | |||
4024 | def run(self,dataOut,variableList=None,Pt=25,Gt=200.0,Gr=50.0,lambda_=0.32, aL=2.5118, |
|
4024 | def run(self,dataOut,variableList=None,Pt=25,Gt=200.0,Gr=50.0,lambda_=0.32, aL=2.5118, | |
4025 | tauW= 4.0e-6,thetaT=0.165,thetaR=0.367,Km =0.93): |
|
4025 | tauW= 4.0e-6,thetaT=0.165,thetaR=0.367,Km =0.93): | |
4026 |
|
4026 | |||
4027 | if not self.isConfig: |
|
4027 | if not self.isConfig: | |
4028 | self.setup(dataOut= dataOut,variableList=None,Pt=25,Gt=200.0,Gr=50.0,lambda_=0.32, aL=2.5118, |
|
4028 | self.setup(dataOut= dataOut,variableList=None,Pt=25,Gt=200.0,Gr=50.0,lambda_=0.32, aL=2.5118, | |
4029 | tauW= 4.0e-6,thetaT=0.165,thetaR=0.367,Km =0.93) |
|
4029 | tauW= 4.0e-6,thetaT=0.165,thetaR=0.367,Km =0.93) | |
4030 | self.isConfig = True |
|
4030 | self.isConfig = True | |
4031 |
|
4031 | |||
4032 | for i in range(len(self.variableList)): |
|
4032 | for i in range(len(self.variableList)): | |
4033 | if self.variableList[i]=='ReflectividadDiferencial': |
|
4033 | if self.variableList[i]=='ReflectividadDiferencial': | |
4034 | dataOut.Zdb_D =self.getReflectividad_D(dataOut=dataOut) |
|
4034 | dataOut.Zdb_D =self.getReflectividad_D(dataOut=dataOut) | |
4035 | if self.variableList[i]=='FaseDiferencial': |
|
4035 | if self.variableList[i]=='FaseDiferencial': | |
4036 | dataOut.PhiD_P =self.getFasediferencialPhiD_P(dataOut=dataOut, phase=True) |
|
4036 | dataOut.PhiD_P =self.getFasediferencialPhiD_P(dataOut=dataOut, phase=True) | |
4037 | if self.variableList[i] == "CoeficienteCorrelacion": |
|
4037 | if self.variableList[i] == "CoeficienteCorrelacion": | |
4038 | dataOut.RhoHV_R = self.getCoeficienteCorrelacionROhv_R(dataOut) |
|
4038 | dataOut.RhoHV_R = self.getCoeficienteCorrelacionROhv_R(dataOut) | |
4039 | if self.variableList[i] =="VelocidadRadial": |
|
4039 | if self.variableList[i] =="VelocidadRadial": | |
4040 | dataOut.velRadial_V = self.getRadialVelocity_V(dataOut) |
|
4040 | dataOut.velRadial_V = self.getRadialVelocity_V(dataOut) | |
4041 | if self.variableList[i] =="AnchoEspectral": |
|
4041 | if self.variableList[i] =="AnchoEspectral": | |
4042 | dataOut.Sigmav_W = self.getAnchoEspectral_W(dataOut) |
|
4042 | dataOut.Sigmav_W = self.getAnchoEspectral_W(dataOut) | |
4043 | return dataOut |
|
4043 | return dataOut | |
4044 |
|
4044 | |||
4045 | class PedestalInformation(Operation): |
|
4045 | class PedestalInformation(Operation): | |
4046 | path_ped = None |
|
4046 | path_ped = None | |
4047 | path_adq = None |
|
4047 | path_adq = None | |
4048 | samp_rate_ped= None |
|
4048 | samp_rate_ped= None | |
4049 | t_Interval_p = None |
|
4049 | t_Interval_p = None | |
4050 | n_Muestras_p = None |
|
4050 | n_Muestras_p = None | |
4051 | isConfig = False |
|
4051 | isConfig = False | |
4052 | blocksPerfile= None |
|
4052 | blocksPerfile= None | |
4053 | f_a_p = None |
|
4053 | f_a_p = None | |
4054 | online = None |
|
4054 | online = None | |
4055 | angulo_adq = None |
|
4055 | angulo_adq = None | |
4056 | nro_file = None |
|
4056 | nro_file = None | |
4057 | nro_key_p = None |
|
4057 | nro_key_p = None | |
4058 | tmp = None |
|
4058 | tmp = None | |
4059 |
|
4059 | |||
4060 |
|
4060 | |||
4061 | def __init__(self): |
|
4061 | def __init__(self): | |
4062 | Operation.__init__(self) |
|
4062 | Operation.__init__(self) | |
4063 |
|
4063 | |||
4064 |
|
4064 | |||
4065 | def getAnguloProfile(self,utc_adq,utc_ped_list): |
|
4065 | def getAnguloProfile(self,utc_adq,utc_ped_list): | |
4066 | utc_adq = utc_adq |
|
4066 | utc_adq = utc_adq | |
4067 | ##list_pedestal = list_pedestal |
|
4067 | ##list_pedestal = list_pedestal | |
4068 | utc_ped_list = utc_ped_list |
|
4068 | utc_ped_list = utc_ped_list | |
4069 | #for i in range(len(list_pedestal)): |
|
4069 | #for i in range(len(list_pedestal)): | |
4070 | # #print(i)# OJO IDENTIFICADOR DE SINCRONISMO |
|
4070 | # #print(i)# OJO IDENTIFICADOR DE SINCRONISMO | |
4071 | # utc_ped_list.append(self.gettimeutcfromDirFilename(path=self.path_ped,file=list_pedestal[i])) |
|
4071 | # utc_ped_list.append(self.gettimeutcfromDirFilename(path=self.path_ped,file=list_pedestal[i])) | |
4072 | nro_file,utc_ped,utc_ped_1 =self.getNROFile(utc_adq,utc_ped_list) |
|
4072 | nro_file,utc_ped,utc_ped_1 =self.getNROFile(utc_adq,utc_ped_list) | |
4073 | #print("NROFILE************************************", nro_file,utc_ped) |
|
4073 | #print("NROFILE************************************", nro_file,utc_ped) | |
4074 | #print(nro_file) |
|
4074 | #print(nro_file) | |
4075 | if nro_file < 0: |
|
4075 | if nro_file < 0: | |
4076 | return numpy.NaN,numpy.NaN |
|
4076 | return numpy.NaN,numpy.NaN | |
4077 | else: |
|
4077 | else: | |
4078 | nro_key_p = int((utc_adq-utc_ped)/self.t_Interval_p)-1 # ojito al -1 estimado alex |
|
4078 | nro_key_p = int((utc_adq-utc_ped)/self.t_Interval_p)-1 # ojito al -1 estimado alex | |
4079 | #print("nro_key_p",nro_key_p) |
|
4079 | #print("nro_key_p",nro_key_p) | |
4080 | ff_pedestal = self.list_pedestal[nro_file] |
|
4080 | ff_pedestal = self.list_pedestal[nro_file] | |
4081 | #angulo = self.getDatavaluefromDirFilename(path=self.path_ped,file=ff_pedestal,value="azimuth") |
|
4081 | #angulo = self.getDatavaluefromDirFilename(path=self.path_ped,file=ff_pedestal,value="azimuth") | |
4082 | angulo = self.getDatavaluefromDirFilename(path=self.path_ped,file=ff_pedestal,value="azi_pos") |
|
4082 | angulo = self.getDatavaluefromDirFilename(path=self.path_ped,file=ff_pedestal,value="azi_pos") | |
4083 | angulo_ele = self.getDatavaluefromDirFilename(path=self.path_ped,file=ff_pedestal,value="ele_pos") |
|
4083 | angulo_ele = self.getDatavaluefromDirFilename(path=self.path_ped,file=ff_pedestal,value="ele_pos") | |
4084 | #-----Adicion de filtro........................ |
|
4084 | #-----Adicion de filtro........................ | |
4085 | vel_ele = self.getDatavaluefromDirFilename(path=self.path_ped,file=ff_pedestal,value="ele_speed")## ele_speed |
|
4085 | vel_ele = self.getDatavaluefromDirFilename(path=self.path_ped,file=ff_pedestal,value="ele_speed")## ele_speed | |
4086 | ''' |
|
4086 | ''' | |
4087 | vel_mean = numpy.mean(vel_ele) |
|
4087 | vel_mean = numpy.mean(vel_ele) | |
4088 | print("#############################################################") |
|
4088 | print("#############################################################") | |
4089 | print("VEL MEAN----------------:",vel_mean) |
|
4089 | print("VEL MEAN----------------:",vel_mean) | |
4090 | f vel_mean<7.7 or vel_mean>8.3: |
|
4090 | f vel_mean<7.7 or vel_mean>8.3: | |
4091 | return numpy.NaN,numpy.NaN |
|
4091 | return numpy.NaN,numpy.NaN | |
4092 | #------------------------------------------------------------------------------------------------------ |
|
4092 | #------------------------------------------------------------------------------------------------------ | |
4093 | ''' |
|
4093 | ''' | |
4094 | #print(int(self.samp_rate_ped)) |
|
4094 | #print(int(self.samp_rate_ped)) | |
4095 | #print(nro_key_p) |
|
4095 | #print(nro_key_p) | |
4096 | if int(self.samp_rate_ped)-1>=nro_key_p>0: |
|
4096 | if int(self.samp_rate_ped)-1>=nro_key_p>0: | |
4097 | #print("angulo_array :",angulo[nro_key_p]) |
|
4097 | #print("angulo_array :",angulo[nro_key_p]) | |
4098 | return angulo[nro_key_p],angulo_ele[nro_key_p] |
|
4098 | return angulo[nro_key_p],angulo_ele[nro_key_p] | |
4099 | else: |
|
4099 | else: | |
4100 | #print("-----------------------------------------------------------------") |
|
4100 | #print("-----------------------------------------------------------------") | |
4101 | return numpy.NaN,numpy.NaN |
|
4101 | return numpy.NaN,numpy.NaN | |
4102 |
|
4102 | |||
4103 |
|
4103 | |||
4104 | def getfirstFilefromPath(self,path,meta,ext): |
|
4104 | def getfirstFilefromPath(self,path,meta,ext): | |
4105 | validFilelist = [] |
|
4105 | validFilelist = [] | |
4106 | #("SEARH",path) |
|
4106 | #("SEARH",path) | |
4107 | try: |
|
4107 | try: | |
4108 | fileList = os.listdir(path) |
|
4108 | fileList = os.listdir(path) | |
4109 | except: |
|
4109 | except: | |
4110 | print("check path - fileList") |
|
4110 | print("check path - fileList") | |
4111 | if len(fileList)<1: |
|
4111 | if len(fileList)<1: | |
4112 | return None |
|
4112 | return None | |
4113 | # meta 1234 567 8-18 BCDE |
|
4113 | # meta 1234 567 8-18 BCDE | |
4114 | # H,D,PE YYYY DDD EPOC .ext |
|
4114 | # H,D,PE YYYY DDD EPOC .ext | |
4115 |
|
4115 | |||
4116 | for thisFile in fileList: |
|
4116 | for thisFile in fileList: | |
4117 | #print("HI",thisFile) |
|
4117 | #print("HI",thisFile) | |
4118 | if meta =="PE": |
|
4118 | if meta =="PE": | |
4119 | try: |
|
4119 | try: | |
4120 | number= int(thisFile[len(meta)+7:len(meta)+17]) |
|
4120 | number= int(thisFile[len(meta)+7:len(meta)+17]) | |
4121 | except: |
|
4121 | except: | |
4122 | print("There is a file or folder with different format") |
|
4122 | print("There is a file or folder with different format") | |
4123 | if meta =="pos@": |
|
4123 | if meta =="pos@": | |
4124 | try: |
|
4124 | try: | |
4125 | number= int(thisFile[len(meta):len(meta)+10]) |
|
4125 | number= int(thisFile[len(meta):len(meta)+10]) | |
4126 | except: |
|
4126 | except: | |
4127 | print("There is a file or folder with different format") |
|
4127 | print("There is a file or folder with different format") | |
4128 | if meta == "D": |
|
4128 | if meta == "D": | |
4129 | try: |
|
4129 | try: | |
4130 | number= int(thisFile[8:11]) |
|
4130 | number= int(thisFile[8:11]) | |
4131 | except: |
|
4131 | except: | |
4132 | print("There is a file or folder with different format") |
|
4132 | print("There is a file or folder with different format") | |
4133 |
|
4133 | |||
4134 | if not isNumber(str=number): |
|
4134 | if not isNumber(str=number): | |
4135 | continue |
|
4135 | continue | |
4136 | if (os.path.splitext(thisFile)[-1].lower() != ext.lower()): |
|
4136 | if (os.path.splitext(thisFile)[-1].lower() != ext.lower()): | |
4137 | continue |
|
4137 | continue | |
4138 | validFilelist.sort() |
|
4138 | validFilelist.sort() | |
4139 | validFilelist.append(thisFile) |
|
4139 | validFilelist.append(thisFile) | |
4140 |
|
4140 | |||
4141 | if len(validFilelist)>0: |
|
4141 | if len(validFilelist)>0: | |
4142 | validFilelist = sorted(validFilelist,key=str.lower) |
|
4142 | validFilelist = sorted(validFilelist,key=str.lower) | |
4143 | #print(validFilelist) |
|
4143 | #print(validFilelist) | |
4144 | return validFilelist |
|
4144 | return validFilelist | |
4145 | return None |
|
4145 | return None | |
4146 |
|
4146 | |||
4147 | def gettimeutcfromDirFilename(self,path,file): |
|
4147 | def gettimeutcfromDirFilename(self,path,file): | |
4148 | dir_file= path+"/"+file |
|
4148 | dir_file= path+"/"+file | |
4149 | fp = h5py.File(dir_file,'r') |
|
4149 | fp = h5py.File(dir_file,'r') | |
4150 | #epoc = fp['Metadata'].get('utctimeInit')[()] |
|
4150 | #epoc = fp['Metadata'].get('utctimeInit')[()] | |
4151 | epoc = fp['Data'].get('utc')[()] |
|
4151 | epoc = fp['Data'].get('utc')[()] | |
4152 | epoc = epoc[0] |
|
4152 | epoc = epoc[0] | |
4153 | #print("hola",epoc) |
|
4153 | #print("hola",epoc) | |
4154 | fp.close() |
|
4154 | fp.close() | |
4155 | return epoc |
|
4155 | return epoc | |
4156 |
|
4156 | |||
4157 | def gettimeutcadqfromDirFilename(self,path,file): |
|
4157 | def gettimeutcadqfromDirFilename(self,path,file): | |
4158 | pass |
|
4158 | pass | |
4159 |
|
4159 | |||
4160 | def getDatavaluefromDirFilename(self,path,file,value): |
|
4160 | def getDatavaluefromDirFilename(self,path,file,value): | |
4161 | dir_file= path+"/"+file |
|
4161 | dir_file= path+"/"+file | |
4162 | fp = h5py.File(dir_file,'r') |
|
4162 | fp = h5py.File(dir_file,'r') | |
4163 | array = fp['Data'].get(value)[()] |
|
4163 | array = fp['Data'].get(value)[()] | |
4164 | fp.close() |
|
4164 | fp.close() | |
4165 | return array |
|
4165 | return array | |
4166 |
|
4166 | |||
4167 |
|
4167 | |||
4168 | def getNROFile(self,utc_adq,utc_ped_list): |
|
4168 | def getNROFile(self,utc_adq,utc_ped_list): | |
4169 | c=0 |
|
4169 | c=0 | |
4170 | #print(utc_adq) |
|
4170 | #print(utc_adq) | |
4171 | #print(len(utc_ped_list)) |
|
4171 | #print(len(utc_ped_list)) | |
4172 | ###print(utc_ped_list) |
|
4172 | ###print(utc_ped_list) | |
4173 | if utc_adq<utc_ped_list[0]: |
|
4173 | if utc_adq<utc_ped_list[0]: | |
4174 | pass |
|
4174 | pass | |
4175 | else: |
|
4175 | else: | |
4176 | for i in range(len(utc_ped_list)): |
|
4176 | for i in range(len(utc_ped_list)): | |
4177 | if utc_adq>utc_ped_list[i]: |
|
4177 | if utc_adq>utc_ped_list[i]: | |
4178 | #print("mayor") |
|
4178 | #print("mayor") | |
4179 | #print("utc_ped_list",utc_ped_list[i]) |
|
4179 | #print("utc_ped_list",utc_ped_list[i]) | |
4180 | c +=1 |
|
4180 | c +=1 | |
4181 |
|
4181 | |||
4182 | return c-1,utc_ped_list[c-1],utc_ped_list[c] |
|
4182 | return c-1,utc_ped_list[c-1],utc_ped_list[c] | |
4183 |
|
4183 | |||
4184 | def verificarNROFILE(self,dataOut,utc_ped,f_a_p,n_Muestras_p): |
|
4184 | def verificarNROFILE(self,dataOut,utc_ped,f_a_p,n_Muestras_p): | |
4185 | pass |
|
4185 | pass | |
4186 |
|
4186 | |||
4187 | def setup_offline(self,dataOut,list_pedestal): |
|
4187 | def setup_offline(self,dataOut,list_pedestal): | |
4188 | pass |
|
4188 | pass | |
4189 |
|
4189 | |||
4190 | def setup_online(self,dataOut): |
|
4190 | def setup_online(self,dataOut): | |
4191 | pass |
|
4191 | pass | |
4192 |
|
4192 | |||
4193 | #def setup(self,dataOut,path_ped,path_adq,t_Interval_p,n_Muestras_p,blocksPerfile,f_a_p,online): |
|
4193 | #def setup(self,dataOut,path_ped,path_adq,t_Interval_p,n_Muestras_p,blocksPerfile,f_a_p,online): | |
4194 | def setup(self,dataOut,path_ped,samp_rate_ped,t_Interval_p,wr_exp): |
|
4194 | def setup(self,dataOut,path_ped,samp_rate_ped,t_Interval_p,wr_exp): | |
4195 | #print("**************SETUP******************") |
|
4195 | #print("**************SETUP******************") | |
4196 | self.__dataReady = False |
|
4196 | self.__dataReady = False | |
4197 | self.path_ped = path_ped |
|
4197 | self.path_ped = path_ped | |
4198 | self.samp_rate_ped= samp_rate_ped |
|
4198 | self.samp_rate_ped= samp_rate_ped | |
4199 | self.t_Interval_p = t_Interval_p |
|
4199 | self.t_Interval_p = t_Interval_p | |
4200 | self.list_pedestal = self.getfirstFilefromPath(path=self.path_ped,meta="pos@",ext=".h5") |
|
4200 | self.list_pedestal = self.getfirstFilefromPath(path=self.path_ped,meta="pos@",ext=".h5") | |
4201 |
|
4201 | |||
4202 | self.utc_ped_list= [] |
|
4202 | self.utc_ped_list= [] | |
4203 | for i in range(len(self.list_pedestal)): |
|
4203 | for i in range(len(self.list_pedestal)): | |
4204 | #print(i,self.gettimeutcfromDirFilename(path=self.path_ped,file=self.list_pedestal[i]))# OJO IDENTIFICADOR DE SINCRONISMO |
|
4204 | #print(i,self.gettimeutcfromDirFilename(path=self.path_ped,file=self.list_pedestal[i]))# OJO IDENTIFICADOR DE SINCRONISMO | |
4205 | self.utc_ped_list.append(self.gettimeutcfromDirFilename(path=self.path_ped,file=self.list_pedestal[i])) |
|
4205 | self.utc_ped_list.append(self.gettimeutcfromDirFilename(path=self.path_ped,file=self.list_pedestal[i])) | |
4206 | #print(self.utc_ped_list) |
|
4206 | #print(self.utc_ped_list) | |
4207 | #exit(1) |
|
4207 | #exit(1) | |
4208 | #print("que paso") |
|
4208 | #print("que paso") | |
4209 | dataOut.wr_exp = wr_exp |
|
4209 | dataOut.wr_exp = wr_exp | |
4210 | #print("SETUP READY") |
|
4210 | #print("SETUP READY") | |
4211 |
|
4211 | |||
4212 |
|
4212 | |||
4213 | def setNextFileP(self,dataOut): |
|
4213 | def setNextFileP(self,dataOut): | |
4214 | pass |
|
4214 | pass | |
4215 |
|
4215 | |||
4216 | def checkPedFile(self,path,nro_file): |
|
4216 | def checkPedFile(self,path,nro_file): | |
4217 | pass |
|
4217 | pass | |
4218 |
|
4218 | |||
4219 | def setNextFileoffline(self,dataOut): |
|
4219 | def setNextFileoffline(self,dataOut): | |
4220 | pass |
|
4220 | pass | |
4221 |
|
4221 | |||
4222 | def setNextFileonline(self): |
|
4222 | def setNextFileonline(self): | |
4223 | pass |
|
4223 | pass | |
4224 |
|
4224 | |||
4225 | def run(self, dataOut,path_ped,samp_rate_ped,t_Interval_p,wr_exp): |
|
4225 | def run(self, dataOut,path_ped,samp_rate_ped,t_Interval_p,wr_exp): | |
4226 | #print("INTEGRATION -----") |
|
4226 | #print("INTEGRATION -----") | |
4227 | #print("PEDESTAL") |
|
4227 | #print("PEDESTAL") | |
4228 |
|
4228 | |||
4229 | if not self.isConfig: |
|
4229 | if not self.isConfig: | |
4230 | self.setup(dataOut, path_ped,samp_rate_ped,t_Interval_p,wr_exp) |
|
4230 | self.setup(dataOut, path_ped,samp_rate_ped,t_Interval_p,wr_exp) | |
4231 | self.__dataReady = True |
|
4231 | self.__dataReady = True | |
4232 | self.isConfig = True |
|
4232 | self.isConfig = True | |
4233 | #print("config TRUE") |
|
4233 | #print("config TRUE") | |
4234 | utc_adq = dataOut.utctime |
|
4234 | utc_adq = dataOut.utctime | |
4235 | #print("utc_adq---------------",utc_adq) |
|
4235 | #print("utc_adq---------------",utc_adq) | |
4236 |
|
4236 | |||
4237 | list_pedestal = self.list_pedestal |
|
4237 | list_pedestal = self.list_pedestal | |
4238 | #print("list_pedestal",list_pedestal[:20]) |
|
4238 | #print("list_pedestal",list_pedestal[:20]) | |
4239 | angulo,angulo_ele = self.getAnguloProfile(utc_adq=utc_adq,utc_ped_list=self.utc_ped_list) |
|
4239 | angulo,angulo_ele = self.getAnguloProfile(utc_adq=utc_adq,utc_ped_list=self.utc_ped_list) | |
4240 | #print("angulo**********",angulo) |
|
4240 | #print("angulo**********",angulo) | |
4241 | dataOut.flagNoData = False |
|
4241 | dataOut.flagNoData = False | |
4242 |
|
4242 | |||
4243 | if numpy.isnan(angulo) or numpy.isnan(angulo_ele) : |
|
4243 | if numpy.isnan(angulo) or numpy.isnan(angulo_ele) : | |
4244 | #print("PEDESTAL 3") |
|
4244 | #print("PEDESTAL 3") | |
4245 | #exit(1) |
|
4245 | #exit(1) | |
4246 | dataOut.flagNoData = True |
|
4246 | dataOut.flagNoData = True | |
4247 | return dataOut |
|
4247 | return dataOut | |
4248 | dataOut.azimuth = angulo |
|
4248 | dataOut.azimuth = angulo | |
4249 | dataOut.elevation = angulo_ele |
|
4249 | dataOut.elevation = angulo_ele | |
4250 | #print("PEDESTAL END") |
|
4250 | #print("PEDESTAL END") | |
4251 | #print(dataOut.azimuth) |
|
4251 | #print(dataOut.azimuth) | |
4252 | #print(dataOut.elevation) |
|
4252 | #print(dataOut.elevation) | |
4253 | #exit(1) |
|
4253 | #exit(1) | |
4254 | return dataOut |
|
4254 | return dataOut | |
4255 |
|
4255 | |||
4256 | class Block360(Operation): |
|
4256 | class Block360(Operation): | |
4257 | ''' |
|
4257 | ''' | |
4258 | ''' |
|
4258 | ''' | |
4259 | isConfig = False |
|
4259 | isConfig = False | |
4260 | __profIndex = 0 |
|
4260 | __profIndex = 0 | |
4261 | __initime = None |
|
4261 | __initime = None | |
4262 | __lastdatatime = None |
|
4262 | __lastdatatime = None | |
4263 | __buffer = None |
|
4263 | __buffer = None | |
4264 | __dataReady = False |
|
4264 | __dataReady = False | |
4265 | n = None |
|
4265 | n = None | |
4266 | __nch = 0 |
|
4266 | __nch = 0 | |
4267 | __nHeis = 0 |
|
4267 | __nHeis = 0 | |
4268 | index = 0 |
|
4268 | index = 0 | |
4269 | mode = 0 |
|
4269 | mode = 0 | |
4270 |
|
4270 | |||
4271 | def __init__(self,**kwargs): |
|
4271 | def __init__(self,**kwargs): | |
4272 | Operation.__init__(self,**kwargs) |
|
4272 | Operation.__init__(self,**kwargs) | |
4273 |
|
4273 | |||
4274 | def setup(self, dataOut, n = None, mode = None): |
|
4274 | def setup(self, dataOut, n = None, mode = None): | |
4275 | ''' |
|
4275 | ''' | |
4276 | n= Numero de PRF's de entrada |
|
4276 | n= Numero de PRF's de entrada | |
4277 | ''' |
|
4277 | ''' | |
4278 | self.__initime = None |
|
4278 | self.__initime = None | |
4279 | self.__lastdatatime = 0 |
|
4279 | self.__lastdatatime = 0 | |
4280 | self.__dataReady = False |
|
4280 | self.__dataReady = False | |
4281 | self.__buffer = 0 |
|
4281 | self.__buffer = 0 | |
4282 | self.__buffer_1D = 0 |
|
4282 | self.__buffer_1D = 0 | |
4283 | self.__profIndex = 0 |
|
4283 | self.__profIndex = 0 | |
4284 | self.index = 0 |
|
4284 | self.index = 0 | |
4285 | self.__nch = dataOut.nChannels |
|
4285 | self.__nch = dataOut.nChannels | |
4286 | self.__nHeis = dataOut.nHeights |
|
4286 | self.__nHeis = dataOut.nHeights | |
4287 | ##print("ELVALOR DE n es:", n) |
|
4287 | ##print("ELVALOR DE n es:", n) | |
4288 | if n == None: |
|
4288 | if n == None: | |
4289 | raise ValueError("n should be specified.") |
|
4289 | raise ValueError("n should be specified.") | |
4290 |
|
4290 | |||
4291 | if mode == None: |
|
4291 | if mode == None: | |
4292 | raise ValueError("mode should be specified.") |
|
4292 | raise ValueError("mode should be specified.") | |
4293 |
|
4293 | |||
4294 | if n != None: |
|
4294 | if n != None: | |
4295 | if n<1: |
|
4295 | if n<1: | |
4296 | print("n should be greater than 2") |
|
4296 | print("n should be greater than 2") | |
4297 | raise ValueError("n should be greater than 2") |
|
4297 | raise ValueError("n should be greater than 2") | |
4298 |
|
4298 | |||
4299 | self.n = n |
|
4299 | self.n = n | |
4300 | self.mode = mode |
|
4300 | self.mode = mode | |
4301 | #print("self.mode",self.mode) |
|
4301 | #print("self.mode",self.mode) | |
4302 | #print("nHeights") |
|
4302 | #print("nHeights") | |
4303 | self.__buffer = numpy.zeros(( dataOut.nChannels,n, dataOut.nHeights)) |
|
4303 | self.__buffer = numpy.zeros(( dataOut.nChannels,n, dataOut.nHeights)) | |
4304 | self.__buffer2 = numpy.zeros(n) |
|
4304 | self.__buffer2 = numpy.zeros(n) | |
4305 | self.__buffer3 = numpy.zeros(n) |
|
4305 | self.__buffer3 = numpy.zeros(n) | |
4306 |
|
4306 | |||
4307 |
|
4307 | |||
4308 |
|
4308 | |||
4309 |
|
4309 | |||
4310 | def putData(self,data,mode): |
|
4310 | def putData(self,data,mode): | |
4311 | ''' |
|
4311 | ''' | |
4312 | Add a profile to he __buffer and increase in one the __profiel Index |
|
4312 | Add a profile to he __buffer and increase in one the __profiel Index | |
4313 | ''' |
|
4313 | ''' | |
4314 | #print("line 4049",data.dataPP_POW.shape,data.dataPP_POW[:10]) |
|
4314 | #print("line 4049",data.dataPP_POW.shape,data.dataPP_POW[:10]) | |
4315 | #print("line 4049",data.azimuth.shape,data.azimuth) |
|
4315 | #print("line 4049",data.azimuth.shape,data.azimuth) | |
4316 | if self.mode==0: |
|
4316 | if self.mode==0: | |
4317 | self.__buffer[:,self.__profIndex,:]= data.dataPP_POWER# PRIMER MOMENTO |
|
4317 | self.__buffer[:,self.__profIndex,:]= data.dataPP_POWER# PRIMER MOMENTO | |
4318 | if self.mode==1: |
|
4318 | if self.mode==1: | |
4319 | self.__buffer[:,self.__profIndex,:]= data.data_pow |
|
4319 | self.__buffer[:,self.__profIndex,:]= data.data_pow | |
4320 | #print("me casi",self.index,data.azimuth[self.index]) |
|
4320 | #print("me casi",self.index,data.azimuth[self.index]) | |
4321 | #print(self.__profIndex, self.index , data.azimuth[self.index] ) |
|
4321 | #print(self.__profIndex, self.index , data.azimuth[self.index] ) | |
4322 | #print("magic",data.profileIndex) |
|
4322 | #print("magic",data.profileIndex) | |
4323 | #print(data.azimuth[self.index]) |
|
4323 | #print(data.azimuth[self.index]) | |
4324 | #print("index",self.index) |
|
4324 | #print("index",self.index) | |
4325 |
|
4325 | |||
4326 | #####self.__buffer2[self.__profIndex] = data.azimuth[self.index] |
|
4326 | #####self.__buffer2[self.__profIndex] = data.azimuth[self.index] | |
4327 | self.__buffer2[self.__profIndex] = data.azimuth |
|
4327 | self.__buffer2[self.__profIndex] = data.azimuth | |
4328 | self.__buffer3[self.__profIndex] = data.elevation |
|
4328 | self.__buffer3[self.__profIndex] = data.elevation | |
4329 | #print("q pasa") |
|
4329 | #print("q pasa") | |
4330 | #####self.index+=1 |
|
4330 | #####self.index+=1 | |
4331 | #print("index",self.index,data.azimuth[:10]) |
|
4331 | #print("index",self.index,data.azimuth[:10]) | |
4332 | self.__profIndex += 1 |
|
4332 | self.__profIndex += 1 | |
4333 | return #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· Remove DCΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· |
|
4333 | return #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· Remove DCΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· | |
4334 |
|
4334 | |||
4335 | def pushData(self,data): |
|
4335 | def pushData(self,data): | |
4336 | ''' |
|
4336 | ''' | |
4337 | Return the PULSEPAIR and the profiles used in the operation |
|
4337 | Return the PULSEPAIR and the profiles used in the operation | |
4338 | Affected : self.__profileIndex |
|
4338 | Affected : self.__profileIndex | |
4339 | ''' |
|
4339 | ''' | |
4340 | #print("pushData") |
|
4340 | #print("pushData") | |
4341 |
|
4341 | |||
4342 | data_360 = self.__buffer |
|
4342 | data_360 = self.__buffer | |
4343 | data_p = self.__buffer2 |
|
4343 | data_p = self.__buffer2 | |
4344 | data_e = self.__buffer3 |
|
4344 | data_e = self.__buffer3 | |
4345 | n = self.__profIndex |
|
4345 | n = self.__profIndex | |
4346 |
|
4346 | |||
4347 | self.__buffer = numpy.zeros((self.__nch, self.n,self.__nHeis)) |
|
4347 | self.__buffer = numpy.zeros((self.__nch, self.n,self.__nHeis)) | |
4348 | self.__buffer2 = numpy.zeros(self.n) |
|
4348 | self.__buffer2 = numpy.zeros(self.n) | |
4349 | self.__buffer3 = numpy.zeros(self.n) |
|
4349 | self.__buffer3 = numpy.zeros(self.n) | |
4350 | self.__profIndex = 0 |
|
4350 | self.__profIndex = 0 | |
4351 | #print("pushData") |
|
4351 | #print("pushData") | |
4352 | return data_360,n,data_p,data_e |
|
4352 | return data_360,n,data_p,data_e | |
4353 |
|
4353 | |||
4354 |
|
4354 | |||
4355 | def byProfiles(self,dataOut): |
|
4355 | def byProfiles(self,dataOut): | |
4356 |
|
4356 | |||
4357 | self.__dataReady = False |
|
4357 | self.__dataReady = False | |
4358 | data_360 = None |
|
4358 | data_360 = None | |
4359 | data_p = None |
|
4359 | data_p = None | |
4360 | data_e = None |
|
4360 | data_e = None | |
4361 | #print("dataOu",dataOut.dataPP_POW) |
|
4361 | #print("dataOu",dataOut.dataPP_POW) | |
4362 | self.putData(data=dataOut,mode = self.mode) |
|
4362 | self.putData(data=dataOut,mode = self.mode) | |
4363 | ##### print("profIndex",self.__profIndex) |
|
4363 | ##### print("profIndex",self.__profIndex) | |
4364 | if self.__profIndex == self.n: |
|
4364 | if self.__profIndex == self.n: | |
4365 | data_360,n,data_p,data_e = self.pushData(data=dataOut) |
|
4365 | data_360,n,data_p,data_e = self.pushData(data=dataOut) | |
4366 | self.__dataReady = True |
|
4366 | self.__dataReady = True | |
4367 |
|
4367 | |||
4368 | return data_360,data_p,data_e |
|
4368 | return data_360,data_p,data_e | |
4369 |
|
4369 | |||
4370 |
|
4370 | |||
4371 | def blockOp(self, dataOut, datatime= None): |
|
4371 | def blockOp(self, dataOut, datatime= None): | |
4372 | if self.__initime == None: |
|
4372 | if self.__initime == None: | |
4373 | self.__initime = datatime |
|
4373 | self.__initime = datatime | |
4374 | data_360,data_p,data_e = self.byProfiles(dataOut) |
|
4374 | data_360,data_p,data_e = self.byProfiles(dataOut) | |
4375 | self.__lastdatatime = datatime |
|
4375 | self.__lastdatatime = datatime | |
4376 |
|
4376 | |||
4377 | if data_360 is None: |
|
4377 | if data_360 is None: | |
4378 | return None, None,None,None |
|
4378 | return None, None,None,None | |
4379 |
|
4379 | |||
4380 |
|
4380 | |||
4381 | avgdatatime = self.__initime |
|
4381 | avgdatatime = self.__initime | |
4382 | if self.n==1: |
|
4382 | if self.n==1: | |
4383 | avgdatatime = datatime |
|
4383 | avgdatatime = datatime | |
4384 | deltatime = datatime - self.__lastdatatime |
|
4384 | deltatime = datatime - self.__lastdatatime | |
4385 | self.__initime = datatime |
|
4385 | self.__initime = datatime | |
4386 | #print(data_360.shape,avgdatatime,data_p.shape) |
|
4386 | #print(data_360.shape,avgdatatime,data_p.shape) | |
4387 | return data_360,avgdatatime,data_p,data_e |
|
4387 | return data_360,avgdatatime,data_p,data_e | |
4388 |
|
4388 | |||
4389 | def run(self, dataOut,n = None,mode=None,**kwargs): |
|
4389 | def run(self, dataOut,n = None,mode=None,**kwargs): | |
4390 | #print("BLOCK 360 HERE WE GO MOMENTOS") |
|
4390 | #print("BLOCK 360 HERE WE GO MOMENTOS") | |
4391 | print("Block 360") |
|
4391 | print("Block 360") | |
4392 | #exit(1) |
|
4392 | #exit(1) | |
4393 | if not self.isConfig: |
|
4393 | if not self.isConfig: | |
4394 | self.setup(dataOut = dataOut, n = n ,mode= mode ,**kwargs) |
|
4394 | self.setup(dataOut = dataOut, n = n ,mode= mode ,**kwargs) | |
4395 | ####self.index = 0 |
|
4395 | ####self.index = 0 | |
4396 | #print("comova",self.isConfig) |
|
4396 | #print("comova",self.isConfig) | |
4397 | self.isConfig = True |
|
4397 | self.isConfig = True | |
4398 | ####if self.index==dataOut.azimuth.shape[0]: |
|
4398 | ####if self.index==dataOut.azimuth.shape[0]: | |
4399 | #### self.index=0 |
|
4399 | #### self.index=0 | |
4400 | data_360, avgdatatime,data_p,data_e = self.blockOp(dataOut, dataOut.utctime) |
|
4400 | data_360, avgdatatime,data_p,data_e = self.blockOp(dataOut, dataOut.utctime) | |
4401 | dataOut.flagNoData = True |
|
4401 | dataOut.flagNoData = True | |
4402 |
|
4402 | |||
4403 | if self.__dataReady: |
|
4403 | if self.__dataReady: | |
4404 | dataOut.data_360 = data_360 # S |
|
4404 | dataOut.data_360 = data_360 # S | |
4405 | #print("DATA 360") |
|
4405 | #print("DATA 360") | |
4406 | #print(dataOut.data_360) |
|
4406 | #print(dataOut.data_360) | |
4407 | #print("---------------------------------------------------------------------------------") |
|
4407 | #print("---------------------------------------------------------------------------------") | |
4408 | print("---------------------------DATAREADY---------------------------------------------") |
|
4408 | print("---------------------------DATAREADY---------------------------------------------") | |
4409 | #print("---------------------------------------------------------------------------------") |
|
4409 | #print("---------------------------------------------------------------------------------") | |
4410 | #print("data_360",dataOut.data_360.shape) |
|
4410 | #print("data_360",dataOut.data_360.shape) | |
4411 | dataOut.data_azi = data_p |
|
4411 | dataOut.data_azi = data_p | |
4412 | dataOut.data_ele = data_e |
|
4412 | dataOut.data_ele = data_e | |
4413 | ###print("azi: ",dataOut.data_azi) |
|
4413 | ###print("azi: ",dataOut.data_azi) | |
4414 | #print("ele: ",dataOut.data_ele) |
|
4414 | #print("ele: ",dataOut.data_ele) | |
4415 | #print("jroproc_parameters",data_p[0],data_p[-1])#,data_360.shape,avgdatatime) |
|
4415 | #print("jroproc_parameters",data_p[0],data_p[-1])#,data_360.shape,avgdatatime) | |
4416 | dataOut.utctime = avgdatatime |
|
4416 | dataOut.utctime = avgdatatime | |
4417 | dataOut.flagNoData = False |
|
4417 | dataOut.flagNoData = False | |
4418 | return dataOut |
|
4418 | return dataOut | |
4419 |
|
4419 | |||
4420 | class Block360_vRF(Operation): |
|
4420 | class Block360_vRF(Operation): | |
4421 | ''' |
|
4421 | ''' | |
4422 | ''' |
|
4422 | ''' | |
4423 | isConfig = False |
|
4423 | isConfig = False | |
4424 | __profIndex = 0 |
|
4424 | __profIndex = 0 | |
4425 | __initime = None |
|
4425 | __initime = None | |
4426 | __lastdatatime = None |
|
4426 | __lastdatatime = None | |
4427 | __buffer = None |
|
4427 | __buffer = None | |
4428 | __dataReady = False |
|
4428 | __dataReady = False | |
4429 | n = None |
|
4429 | n = None | |
4430 | __nch = 0 |
|
4430 | __nch = 0 | |
4431 | __nHeis = 0 |
|
4431 | __nHeis = 0 | |
4432 | index = 0 |
|
4432 | index = 0 | |
4433 | mode = 0 |
|
4433 | mode = 0 | |
4434 |
|
4434 | |||
4435 | def __init__(self,**kwargs): |
|
4435 | def __init__(self,**kwargs): | |
4436 | Operation.__init__(self,**kwargs) |
|
4436 | Operation.__init__(self,**kwargs) | |
4437 |
|
4437 | |||
4438 | def setup(self, dataOut, n = None, mode = None): |
|
4438 | def setup(self, dataOut, n = None, mode = None): | |
4439 | ''' |
|
4439 | ''' | |
4440 | n= Numero de PRF's de entrada |
|
4440 | n= Numero de PRF's de entrada | |
4441 | ''' |
|
4441 | ''' | |
4442 | self.__initime = None |
|
4442 | self.__initime = None | |
4443 | self.__lastdatatime = 0 |
|
4443 | self.__lastdatatime = 0 | |
4444 | self.__dataReady = False |
|
4444 | self.__dataReady = False | |
4445 | self.__buffer = 0 |
|
4445 | self.__buffer = 0 | |
4446 | self.__buffer_1D = 0 |
|
4446 | self.__buffer_1D = 0 | |
4447 | self.__profIndex = 0 |
|
4447 | self.__profIndex = 0 | |
4448 | self.index = 0 |
|
4448 | self.index = 0 | |
4449 | self.__nch = dataOut.nChannels |
|
4449 | self.__nch = dataOut.nChannels | |
4450 | self.__nHeis = dataOut.nHeights |
|
4450 | self.__nHeis = dataOut.nHeights | |
4451 | ##print("ELVALOR DE n es:", n) |
|
4451 | ##print("ELVALOR DE n es:", n) | |
4452 | if n == None: |
|
4452 | if n == None: | |
4453 | raise ValueError("n should be specified.") |
|
4453 | raise ValueError("n should be specified.") | |
4454 |
|
4454 | |||
4455 | if mode == None: |
|
4455 | if mode == None: | |
4456 | raise ValueError("mode should be specified.") |
|
4456 | raise ValueError("mode should be specified.") | |
4457 |
|
4457 | |||
4458 | if n != None: |
|
4458 | if n != None: | |
4459 | if n<1: |
|
4459 | if n<1: | |
4460 | print("n should be greater than 2") |
|
4460 | print("n should be greater than 2") | |
4461 | raise ValueError("n should be greater than 2") |
|
4461 | raise ValueError("n should be greater than 2") | |
4462 |
|
4462 | |||
4463 | self.n = n |
|
4463 | self.n = n | |
4464 | self.mode = mode |
|
4464 | self.mode = mode | |
4465 | #print("self.mode",self.mode) |
|
4465 | #print("self.mode",self.mode) | |
4466 | #print("nHeights") |
|
4466 | #print("nHeights") | |
4467 | self.__buffer = numpy.zeros(( dataOut.nChannels,n, dataOut.nHeights)) |
|
4467 | self.__buffer = numpy.zeros(( dataOut.nChannels,n, dataOut.nHeights)) | |
4468 | self.__buffer2 = numpy.zeros(n) |
|
4468 | self.__buffer2 = numpy.zeros(n) | |
4469 | self.__buffer3 = numpy.zeros(n) |
|
4469 | self.__buffer3 = numpy.zeros(n) | |
4470 |
|
4470 | |||
4471 |
|
4471 | |||
4472 |
|
4472 | |||
4473 |
|
4473 | |||
4474 | def putData(self,data,mode): |
|
4474 | def putData(self,data,mode): | |
4475 | ''' |
|
4475 | ''' | |
4476 | Add a profile to he __buffer and increase in one the __profiel Index |
|
4476 | Add a profile to he __buffer and increase in one the __profiel Index | |
4477 | ''' |
|
4477 | ''' | |
4478 | #print("line 4049",data.dataPP_POW.shape,data.dataPP_POW[:10]) |
|
4478 | #print("line 4049",data.dataPP_POW.shape,data.dataPP_POW[:10]) | |
4479 | #print("line 4049",data.azimuth.shape,data.azimuth) |
|
4479 | #print("line 4049",data.azimuth.shape,data.azimuth) | |
4480 | if self.mode==0: |
|
4480 | if self.mode==0: | |
4481 | self.__buffer[:,self.__profIndex,:]= data.dataPP_POWER# PRIMER MOMENTO |
|
4481 | self.__buffer[:,self.__profIndex,:]= data.dataPP_POWER# PRIMER MOMENTO | |
4482 | if self.mode==1: |
|
4482 | if self.mode==1: | |
4483 | self.__buffer[:,self.__profIndex,:]= data.data_pow |
|
4483 | self.__buffer[:,self.__profIndex,:]= data.data_pow | |
4484 | #print("me casi",self.index,data.azimuth[self.index]) |
|
4484 | #print("me casi",self.index,data.azimuth[self.index]) | |
4485 | #print(self.__profIndex, self.index , data.azimuth[self.index] ) |
|
4485 | #print(self.__profIndex, self.index , data.azimuth[self.index] ) | |
4486 | #print("magic",data.profileIndex) |
|
4486 | #print("magic",data.profileIndex) | |
4487 | #print(data.azimuth[self.index]) |
|
4487 | #print(data.azimuth[self.index]) | |
4488 | #print("index",self.index) |
|
4488 | #print("index",self.index) | |
4489 |
|
4489 | |||
4490 | #####self.__buffer2[self.__profIndex] = data.azimuth[self.index] |
|
4490 | #####self.__buffer2[self.__profIndex] = data.azimuth[self.index] | |
4491 | self.__buffer2[self.__profIndex] = data.azimuth |
|
4491 | self.__buffer2[self.__profIndex] = data.azimuth | |
4492 | self.__buffer3[self.__profIndex] = data.elevation |
|
4492 | self.__buffer3[self.__profIndex] = data.elevation | |
4493 | #print("q pasa") |
|
4493 | #print("q pasa") | |
4494 | #####self.index+=1 |
|
4494 | #####self.index+=1 | |
4495 | #print("index",self.index,data.azimuth[:10]) |
|
4495 | #print("index",self.index,data.azimuth[:10]) | |
4496 | self.__profIndex += 1 |
|
4496 | self.__profIndex += 1 | |
4497 | return #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· Remove DCΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· |
|
4497 | return #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· Remove DCΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· | |
4498 |
|
4498 | |||
4499 | def pushData(self,data): |
|
4499 | def pushData(self,data): | |
4500 | ''' |
|
4500 | ''' | |
4501 | Return the PULSEPAIR and the profiles used in the operation |
|
4501 | Return the PULSEPAIR and the profiles used in the operation | |
4502 | Affected : self.__profileIndex |
|
4502 | Affected : self.__profileIndex | |
4503 | ''' |
|
4503 | ''' | |
4504 | #print("pushData") |
|
4504 | #print("pushData") | |
4505 |
|
4505 | |||
4506 | data_360 = self.__buffer |
|
4506 | data_360 = self.__buffer | |
4507 | data_p = self.__buffer2 |
|
4507 | data_p = self.__buffer2 | |
4508 | data_e = self.__buffer3 |
|
4508 | data_e = self.__buffer3 | |
4509 | n = self.__profIndex |
|
4509 | n = self.__profIndex | |
4510 |
|
4510 | |||
4511 | self.__buffer = numpy.zeros((self.__nch, self.n,self.__nHeis)) |
|
4511 | self.__buffer = numpy.zeros((self.__nch, self.n,self.__nHeis)) | |
4512 | self.__buffer2 = numpy.zeros(self.n) |
|
4512 | self.__buffer2 = numpy.zeros(self.n) | |
4513 | self.__buffer3 = numpy.zeros(self.n) |
|
4513 | self.__buffer3 = numpy.zeros(self.n) | |
4514 | self.__profIndex = 0 |
|
4514 | self.__profIndex = 0 | |
4515 | #print("pushData") |
|
4515 | #print("pushData") | |
4516 | return data_360,n,data_p,data_e |
|
4516 | return data_360,n,data_p,data_e | |
4517 |
|
4517 | |||
4518 |
|
4518 | |||
4519 | def byProfiles(self,dataOut): |
|
4519 | def byProfiles(self,dataOut): | |
4520 |
|
4520 | |||
4521 | self.__dataReady = False |
|
4521 | self.__dataReady = False | |
4522 | data_360 = None |
|
4522 | data_360 = None | |
4523 | data_p = None |
|
4523 | data_p = None | |
4524 | data_e = None |
|
4524 | data_e = None | |
4525 | #print("dataOu",dataOut.dataPP_POW) |
|
4525 | #print("dataOu",dataOut.dataPP_POW) | |
4526 | self.putData(data=dataOut,mode = self.mode) |
|
4526 | self.putData(data=dataOut,mode = self.mode) | |
4527 | ##### print("profIndex",self.__profIndex) |
|
4527 | ##### print("profIndex",self.__profIndex) | |
4528 | if self.__profIndex == self.n: |
|
4528 | if self.__profIndex == self.n: | |
4529 | data_360,n,data_p,data_e = self.pushData(data=dataOut) |
|
4529 | data_360,n,data_p,data_e = self.pushData(data=dataOut) | |
4530 | self.__dataReady = True |
|
4530 | self.__dataReady = True | |
4531 |
|
4531 | |||
4532 | return data_360,data_p,data_e |
|
4532 | return data_360,data_p,data_e | |
4533 |
|
4533 | |||
4534 |
|
4534 | |||
4535 | def blockOp(self, dataOut, datatime= None): |
|
4535 | def blockOp(self, dataOut, datatime= None): | |
4536 | if self.__initime == None: |
|
4536 | if self.__initime == None: | |
4537 | self.__initime = datatime |
|
4537 | self.__initime = datatime | |
4538 | data_360,data_p,data_e = self.byProfiles(dataOut) |
|
4538 | data_360,data_p,data_e = self.byProfiles(dataOut) | |
4539 | self.__lastdatatime = datatime |
|
4539 | self.__lastdatatime = datatime | |
4540 |
|
4540 | |||
4541 | if data_360 is None: |
|
4541 | if data_360 is None: | |
4542 | return None, None,None,None |
|
4542 | return None, None,None,None | |
4543 |
|
4543 | |||
4544 |
|
4544 | |||
4545 | avgdatatime = self.__initime |
|
4545 | avgdatatime = self.__initime | |
4546 | if self.n==1: |
|
4546 | if self.n==1: | |
4547 | avgdatatime = datatime |
|
4547 | avgdatatime = datatime | |
4548 | deltatime = datatime - self.__lastdatatime |
|
4548 | deltatime = datatime - self.__lastdatatime | |
4549 | self.__initime = datatime |
|
4549 | self.__initime = datatime | |
4550 | #print(data_360.shape,avgdatatime,data_p.shape) |
|
4550 | #print(data_360.shape,avgdatatime,data_p.shape) | |
4551 | return data_360,avgdatatime,data_p,data_e |
|
4551 | return data_360,avgdatatime,data_p,data_e | |
4552 |
|
4552 | |||
4553 | def checkcase(self,data_ele): |
|
4553 | def checkcase(self,data_ele): | |
4554 | start = data_ele[0] |
|
4554 | start = data_ele[0] | |
4555 | end = data_ele[-1] |
|
4555 | end = data_ele[-1] | |
4556 | diff_angle = (end-start) |
|
4556 | diff_angle = (end-start) | |
4557 | len_ang=len(data_ele) |
|
4557 | len_ang=len(data_ele) | |
4558 | print("start",start) |
|
4558 | print("start",start) | |
4559 | print("end",end) |
|
4559 | print("end",end) | |
4560 | print("number",diff_angle) |
|
4560 | print("number",diff_angle) | |
4561 |
|
4561 | |||
4562 | print("len_ang",len_ang) |
|
4562 | print("len_ang",len_ang) | |
4563 |
|
4563 | |||
4564 | aux = (data_ele<0).any(axis=0) |
|
4564 | aux = (data_ele<0).any(axis=0) | |
4565 |
|
4565 | |||
4566 | #exit(1) |
|
4566 | #exit(1) | |
4567 | if diff_angle<0 and aux!=1: #Bajada |
|
4567 | if diff_angle<0 and aux!=1: #Bajada | |
4568 | return 1 |
|
4568 | return 1 | |
4569 | elif diff_angle<0 and aux==1: #Bajada con angulos negativos |
|
4569 | elif diff_angle<0 and aux==1: #Bajada con angulos negativos | |
4570 | return 0 |
|
4570 | return 0 | |
4571 | elif diff_angle == 0: # This case happens when the angle reaches the max_angle if n = 2 |
|
4571 | elif diff_angle == 0: # This case happens when the angle reaches the max_angle if n = 2 | |
4572 | self.flagEraseFirstData = 1 |
|
4572 | self.flagEraseFirstData = 1 | |
4573 | print("ToDO this case") |
|
4573 | print("ToDO this case") | |
4574 | exit(1) |
|
4574 | exit(1) | |
4575 | elif diff_angle>0: #Subida |
|
4575 | elif diff_angle>0: #Subida | |
4576 | return 0 |
|
4576 | return 0 | |
4577 |
|
4577 | |||
4578 | def run(self, dataOut,n = None,mode=None,**kwargs): |
|
4578 | def run(self, dataOut,n = None,mode=None,**kwargs): | |
4579 | #print("BLOCK 360 HERE WE GO MOMENTOS") |
|
4579 | #print("BLOCK 360 HERE WE GO MOMENTOS") | |
4580 | print("Block 360") |
|
4580 | print("Block 360") | |
4581 |
|
4581 | |||
4582 | #exit(1) |
|
4582 | #exit(1) | |
4583 | if not self.isConfig: |
|
4583 | if not self.isConfig: | |
4584 | if n == 1: |
|
4584 | if n == 1: | |
4585 | print("*******************Min Value is 2. Setting n = 2*******************") |
|
4585 | print("*******************Min Value is 2. Setting n = 2*******************") | |
4586 | n = 2 |
|
4586 | n = 2 | |
4587 | #exit(1) |
|
4587 | #exit(1) | |
4588 | print(n) |
|
4588 | print(n) | |
4589 | self.setup(dataOut = dataOut, n = n ,mode= mode ,**kwargs) |
|
4589 | self.setup(dataOut = dataOut, n = n ,mode= mode ,**kwargs) | |
4590 | ####self.index = 0 |
|
4590 | ####self.index = 0 | |
4591 | #print("comova",self.isConfig) |
|
4591 | #print("comova",self.isConfig) | |
4592 | self.isConfig = True |
|
4592 | self.isConfig = True | |
4593 | ####if self.index==dataOut.azimuth.shape[0]: |
|
4593 | ####if self.index==dataOut.azimuth.shape[0]: | |
4594 | #### self.index=0 |
|
4594 | #### self.index=0 | |
4595 | data_360, avgdatatime,data_p,data_e = self.blockOp(dataOut, dataOut.utctime) |
|
4595 | data_360, avgdatatime,data_p,data_e = self.blockOp(dataOut, dataOut.utctime) | |
4596 | dataOut.flagNoData = True |
|
4596 | dataOut.flagNoData = True | |
4597 |
|
4597 | |||
4598 | if self.__dataReady: |
|
4598 | if self.__dataReady: | |
4599 | dataOut.data_360 = data_360 # S |
|
4599 | dataOut.data_360 = data_360 # S | |
4600 | #print("DATA 360") |
|
4600 | #print("DATA 360") | |
4601 | #print(dataOut.data_360) |
|
4601 | #print(dataOut.data_360) | |
4602 | #print("---------------------------------------------------------------------------------") |
|
4602 | #print("---------------------------------------------------------------------------------") | |
4603 | print("---------------------------DATAREADY---------------------------------------------") |
|
4603 | print("---------------------------DATAREADY---------------------------------------------") | |
4604 | #print("---------------------------------------------------------------------------------") |
|
4604 | #print("---------------------------------------------------------------------------------") | |
4605 | #print("data_360",dataOut.data_360.shape) |
|
4605 | #print("data_360",dataOut.data_360.shape) | |
4606 | dataOut.data_azi = data_p |
|
4606 | dataOut.data_azi = data_p | |
4607 | dataOut.data_ele = data_e |
|
4607 | dataOut.data_ele = data_e | |
4608 | ###print("azi: ",dataOut.data_azi) |
|
4608 | ###print("azi: ",dataOut.data_azi) | |
4609 | #print("ele: ",dataOut.data_ele) |
|
4609 | #print("ele: ",dataOut.data_ele) | |
4610 | #print("jroproc_parameters",data_p[0],data_p[-1])#,data_360.shape,avgdatatime) |
|
4610 | #print("jroproc_parameters",data_p[0],data_p[-1])#,data_360.shape,avgdatatime) | |
4611 | dataOut.utctime = avgdatatime |
|
4611 | dataOut.utctime = avgdatatime | |
4612 |
|
4612 | |||
4613 | dataOut.case_flag = self.checkcase(dataOut.data_ele) |
|
4613 | dataOut.case_flag = self.checkcase(dataOut.data_ele) | |
4614 | if dataOut.case_flag: #Si estΓ‘ de bajada empieza a plotear |
|
4614 | if dataOut.case_flag: #Si estΓ‘ de bajada empieza a plotear | |
4615 | print("INSIDE CASE FLAG BAJADA") |
|
4615 | print("INSIDE CASE FLAG BAJADA") | |
4616 | dataOut.flagNoData = False |
|
4616 | dataOut.flagNoData = False | |
4617 | else: |
|
4617 | else: | |
4618 | print("CASE SUBIDA") |
|
4618 | print("CASE SUBIDA") | |
4619 | dataOut.flagNoData = True |
|
4619 | dataOut.flagNoData = True | |
4620 |
|
4620 | |||
4621 | #dataOut.flagNoData = False |
|
4621 | #dataOut.flagNoData = False | |
4622 | return dataOut |
|
4622 | return dataOut | |
|
4623 | ||||
|
4624 | class Block360_vRF2(Operation): | |||
|
4625 | ''' | |||
|
4626 | ''' | |||
|
4627 | isConfig = False | |||
|
4628 | __profIndex = 0 | |||
|
4629 | __initime = None | |||
|
4630 | __lastdatatime = None | |||
|
4631 | __buffer = None | |||
|
4632 | __dataReady = False | |||
|
4633 | n = None | |||
|
4634 | __nch = 0 | |||
|
4635 | __nHeis = 0 | |||
|
4636 | index = 0 | |||
|
4637 | mode = 0 | |||
|
4638 | ||||
|
4639 | def __init__(self,**kwargs): | |||
|
4640 | Operation.__init__(self,**kwargs) | |||
|
4641 | ||||
|
4642 | def setup(self, dataOut, n = None, mode = None): | |||
|
4643 | ''' | |||
|
4644 | n= Numero de PRF's de entrada | |||
|
4645 | ''' | |||
|
4646 | self.__initime = None | |||
|
4647 | self.__lastdatatime = 0 | |||
|
4648 | self.__dataReady = False | |||
|
4649 | self.__buffer = 0 | |||
|
4650 | self.__buffer_1D = 0 | |||
|
4651 | #self.__profIndex = 0 | |||
|
4652 | self.index = 0 | |||
|
4653 | self.__nch = dataOut.nChannels | |||
|
4654 | self.__nHeis = dataOut.nHeights | |||
|
4655 | ||||
|
4656 | self.mode = mode | |||
|
4657 | #print("self.mode",self.mode) | |||
|
4658 | #print("nHeights") | |||
|
4659 | self.__buffer = [] | |||
|
4660 | self.__buffer2 = [] | |||
|
4661 | self.__buffer3 = [] | |||
|
4662 | ||||
|
4663 | def putData(self,data,mode): | |||
|
4664 | ''' | |||
|
4665 | Add a profile to he __buffer and increase in one the __profiel Index | |||
|
4666 | ''' | |||
|
4667 | #print("line 4049",data.dataPP_POW.shape,data.dataPP_POW[:10]) | |||
|
4668 | #print("line 4049",data.azimuth.shape,data.azimuth) | |||
|
4669 | if self.mode==0: | |||
|
4670 | self.__buffer.append(data.dataPP_POWER)# PRIMER MOMENTO | |||
|
4671 | if self.mode==1: | |||
|
4672 | self.__buffer.append(data.data_pow) | |||
|
4673 | #print("me casi",self.index,data.azimuth[self.index]) | |||
|
4674 | #print(self.__profIndex, self.index , data.azimuth[self.index] ) | |||
|
4675 | #print("magic",data.profileIndex) | |||
|
4676 | #print(data.azimuth[self.index]) | |||
|
4677 | #print("index",self.index) | |||
|
4678 | ||||
|
4679 | #####self.__buffer2[self.__profIndex] = data.azimuth[self.index] | |||
|
4680 | self.__buffer2.append(data.azimuth) | |||
|
4681 | self.__buffer3.append(data.elevation) | |||
|
4682 | self.__profIndex += 1 | |||
|
4683 | #print("q pasa") | |||
|
4684 | return numpy.array(self.__buffer3) #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· Remove DCΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· | |||
|
4685 | ||||
|
4686 | def pushData(self,data): | |||
|
4687 | ''' | |||
|
4688 | Return the PULSEPAIR and the profiles used in the operation | |||
|
4689 | Affected : self.__profileIndex | |||
|
4690 | ''' | |||
|
4691 | #print("pushData") | |||
|
4692 | ||||
|
4693 | data_360 = numpy.array(self.__buffer).transpose(1,0,2) | |||
|
4694 | data_p = numpy.array(self.__buffer2) | |||
|
4695 | data_e = numpy.array(self.__buffer3) | |||
|
4696 | n = self.__profIndex | |||
|
4697 | ||||
|
4698 | self.__buffer = [] | |||
|
4699 | self.__buffer2 = [] | |||
|
4700 | self.__buffer3 = [] | |||
|
4701 | self.__profIndex = 0 | |||
|
4702 | #print("pushData") | |||
|
4703 | return data_360,n,data_p,data_e | |||
|
4704 | ||||
|
4705 | ||||
|
4706 | def byProfiles(self,dataOut): | |||
|
4707 | ||||
|
4708 | self.__dataReady = False | |||
|
4709 | data_360 = None | |||
|
4710 | data_p = None | |||
|
4711 | data_e = None | |||
|
4712 | #print("dataOu",dataOut.dataPP_POW) | |||
|
4713 | ||||
|
4714 | elevations = self.putData(data=dataOut,mode = self.mode) | |||
|
4715 | ##### print("profIndex",self.__profIndex) | |||
|
4716 | ||||
|
4717 | ||||
|
4718 | if self.__profIndex > 1: | |||
|
4719 | case_flag = self.checkcase(elevations) | |||
|
4720 | ||||
|
4721 | if case_flag == 0: #Subida | |||
|
4722 | #Se borra el dato anterior para liberar buffer y comparar el dato actual con el siguiente | |||
|
4723 | if len(self.__buffer) == 2: #Cuando estΓ‘ de subida | |||
|
4724 | self.__buffer.pop(0) #Erase first data | |||
|
4725 | self.__buffer2.pop(0) | |||
|
4726 | self.__buffer3.pop(0) | |||
|
4727 | self.__profIndex -= 1 | |||
|
4728 | else: #Cuando ha estado de bajada y ha vuelto a subir | |||
|
4729 | #print("else",self.__buffer3) | |||
|
4730 | self.__buffer.pop() #Erase last data | |||
|
4731 | self.__buffer2.pop() | |||
|
4732 | self.__buffer3.pop() | |||
|
4733 | data_360,n,data_p,data_e = self.pushData(data=dataOut) | |||
|
4734 | #print(data_360.shape) | |||
|
4735 | #print(data_e.shape) | |||
|
4736 | #exit(1) | |||
|
4737 | self.__dataReady = True | |||
|
4738 | ''' | |||
|
4739 | elif elevations[-1]<0.: | |||
|
4740 | if len(self.__buffer) == 2: | |||
|
4741 | self.__buffer.pop(0) #Erase first data | |||
|
4742 | self.__buffer2.pop(0) | |||
|
4743 | self.__buffer3.pop(0) | |||
|
4744 | self.__profIndex -= 1 | |||
|
4745 | else: | |||
|
4746 | self.__buffer.pop() #Erase last data | |||
|
4747 | self.__buffer2.pop() | |||
|
4748 | self.__buffer3.pop() | |||
|
4749 | data_360,n,data_p,data_e = self.pushData(data=dataOut) | |||
|
4750 | self.__dataReady = True | |||
|
4751 | ''' | |||
|
4752 | ||||
|
4753 | ||||
|
4754 | ''' | |||
|
4755 | if self.__profIndex == self.n: | |||
|
4756 | data_360,n,data_p,data_e = self.pushData(data=dataOut) | |||
|
4757 | self.__dataReady = True | |||
|
4758 | ''' | |||
|
4759 | ||||
|
4760 | return data_360,data_p,data_e | |||
|
4761 | ||||
|
4762 | ||||
|
4763 | def blockOp(self, dataOut, datatime= None): | |||
|
4764 | if self.__initime == None: | |||
|
4765 | self.__initime = datatime | |||
|
4766 | data_360,data_p,data_e = self.byProfiles(dataOut) | |||
|
4767 | self.__lastdatatime = datatime | |||
|
4768 | ||||
|
4769 | if data_360 is None: | |||
|
4770 | return None, None,None,None | |||
|
4771 | ||||
|
4772 | ||||
|
4773 | avgdatatime = self.__initime | |||
|
4774 | if self.n==1: | |||
|
4775 | avgdatatime = datatime | |||
|
4776 | deltatime = datatime - self.__lastdatatime | |||
|
4777 | self.__initime = datatime | |||
|
4778 | #print(data_360.shape,avgdatatime,data_p.shape) | |||
|
4779 | return data_360,avgdatatime,data_p,data_e | |||
|
4780 | ||||
|
4781 | def checkcase(self,data_ele): | |||
|
4782 | print(data_ele) | |||
|
4783 | start = data_ele[-2] | |||
|
4784 | end = data_ele[-1] | |||
|
4785 | diff_angle = (end-start) | |||
|
4786 | len_ang=len(data_ele) | |||
|
4787 | ||||
|
4788 | if diff_angle > 0: #Subida | |||
|
4789 | return 0 | |||
|
4790 | ||||
|
4791 | def run(self, dataOut,n = None,mode=None,**kwargs): | |||
|
4792 | #print("BLOCK 360 HERE WE GO MOMENTOS") | |||
|
4793 | print("Block 360") | |||
|
4794 | ||||
|
4795 | #exit(1) | |||
|
4796 | if not self.isConfig: | |||
|
4797 | ||||
|
4798 | print(n) | |||
|
4799 | self.setup(dataOut = dataOut ,mode= mode ,**kwargs) | |||
|
4800 | ####self.index = 0 | |||
|
4801 | #print("comova",self.isConfig) | |||
|
4802 | self.isConfig = True | |||
|
4803 | ####if self.index==dataOut.azimuth.shape[0]: | |||
|
4804 | #### self.index=0 | |||
|
4805 | ||||
|
4806 | data_360, avgdatatime,data_p,data_e = self.blockOp(dataOut, dataOut.utctime) | |||
|
4807 | ||||
|
4808 | ||||
|
4809 | ||||
|
4810 | ||||
|
4811 | dataOut.flagNoData = True | |||
|
4812 | ||||
|
4813 | if self.__dataReady: | |||
|
4814 | dataOut.data_360 = data_360 # S | |||
|
4815 | #print("DATA 360") | |||
|
4816 | #print(dataOut.data_360) | |||
|
4817 | #print("---------------------------------------------------------------------------------") | |||
|
4818 | print("---------------------------DATAREADY---------------------------------------------") | |||
|
4819 | #print("---------------------------------------------------------------------------------") | |||
|
4820 | #print("data_360",dataOut.data_360.shape) | |||
|
4821 | print(data_e) | |||
|
4822 | #exit(1) | |||
|
4823 | dataOut.data_azi = data_p | |||
|
4824 | dataOut.data_ele = data_e | |||
|
4825 | ###print("azi: ",dataOut.data_azi) | |||
|
4826 | #print("ele: ",dataOut.data_ele) | |||
|
4827 | #print("jroproc_parameters",data_p[0],data_p[-1])#,data_360.shape,avgdatatime) | |||
|
4828 | dataOut.utctime = avgdatatime | |||
|
4829 | ||||
|
4830 | ||||
|
4831 | ||||
|
4832 | dataOut.flagNoData = False | |||
|
4833 | return dataOut |
General Comments 0
You need to be logged in to leave comments.
Login now