@@ -1,1047 +1,1082 | |||
|
1 | 1 | import os |
|
2 | 2 | import datetime |
|
3 | 3 | import numpy |
|
4 | 4 | |
|
5 | 5 | from schainpy.model.graphics.jroplot_base import Plot, plt |
|
6 | 6 | from schainpy.model.graphics.jroplot_spectra import SpectraPlot, RTIPlot, CoherencePlot, SpectraCutPlot |
|
7 | 7 | from schainpy.utils import log |
|
8 | 8 | # libreria wradlib |
|
9 | 9 | import wradlib as wrl |
|
10 | 10 | |
|
11 | 11 | EARTH_RADIUS = 6.3710e3 |
|
12 | 12 | |
|
13 | 13 | |
|
14 | 14 | def ll2xy(lat1, lon1, lat2, lon2): |
|
15 | 15 | |
|
16 | 16 | p = 0.017453292519943295 |
|
17 | 17 | a = 0.5 - numpy.cos((lat2 - lat1) * p)/2 + numpy.cos(lat1 * p) * \ |
|
18 | 18 | numpy.cos(lat2 * p) * (1 - numpy.cos((lon2 - lon1) * p)) / 2 |
|
19 | 19 | r = 12742 * numpy.arcsin(numpy.sqrt(a)) |
|
20 | 20 | theta = numpy.arctan2(numpy.sin((lon2-lon1)*p)*numpy.cos(lat2*p), numpy.cos(lat1*p) |
|
21 | 21 | * numpy.sin(lat2*p)-numpy.sin(lat1*p)*numpy.cos(lat2*p)*numpy.cos((lon2-lon1)*p)) |
|
22 | 22 | theta = -theta + numpy.pi/2 |
|
23 | 23 | return r*numpy.cos(theta), r*numpy.sin(theta) |
|
24 | 24 | |
|
25 | 25 | |
|
26 | 26 | def km2deg(km): |
|
27 | 27 | ''' |
|
28 | 28 | Convert distance in km to degrees |
|
29 | 29 | ''' |
|
30 | 30 | |
|
31 | 31 | return numpy.rad2deg(km/EARTH_RADIUS) |
|
32 | 32 | |
|
33 | 33 | |
|
34 | 34 | |
|
35 | 35 | class SpectralMomentsPlot(SpectraPlot): |
|
36 | 36 | ''' |
|
37 | 37 | Plot for Spectral Moments |
|
38 | 38 | ''' |
|
39 | 39 | CODE = 'spc_moments' |
|
40 | 40 | # colormap = 'jet' |
|
41 | 41 | # plot_type = 'pcolor' |
|
42 | 42 | |
|
43 | 43 | class DobleGaussianPlot(SpectraPlot): |
|
44 | 44 | ''' |
|
45 | 45 | Plot for Double Gaussian Plot |
|
46 | 46 | ''' |
|
47 | 47 | CODE = 'gaussian_fit' |
|
48 | 48 | # colormap = 'jet' |
|
49 | 49 | # plot_type = 'pcolor' |
|
50 | 50 | |
|
51 | 51 | class DoubleGaussianSpectraCutPlot(SpectraCutPlot): |
|
52 | 52 | ''' |
|
53 | 53 | Plot SpectraCut with Double Gaussian Fit |
|
54 | 54 | ''' |
|
55 | 55 | CODE = 'cut_gaussian_fit' |
|
56 | 56 | |
|
57 | 57 | class SnrPlot(RTIPlot): |
|
58 | 58 | ''' |
|
59 | 59 | Plot for SNR Data |
|
60 | 60 | ''' |
|
61 | 61 | |
|
62 | 62 | CODE = 'snr' |
|
63 | 63 | colormap = 'jet' |
|
64 | 64 | |
|
65 | 65 | def update(self, dataOut): |
|
66 | 66 | |
|
67 | 67 | data = { |
|
68 | 68 | 'snr': 10*numpy.log10(dataOut.data_snr) |
|
69 | 69 | } |
|
70 | 70 | |
|
71 | 71 | return data, {} |
|
72 | 72 | |
|
73 | 73 | class DopplerPlot(RTIPlot): |
|
74 | 74 | ''' |
|
75 | 75 | Plot for DOPPLER Data (1st moment) |
|
76 | 76 | ''' |
|
77 | 77 | |
|
78 | 78 | CODE = 'dop' |
|
79 | 79 | colormap = 'jet' |
|
80 | 80 | |
|
81 | 81 | def update(self, dataOut): |
|
82 | 82 | |
|
83 | 83 | data = { |
|
84 | 84 | 'dop': 10*numpy.log10(dataOut.data_dop) |
|
85 | 85 | } |
|
86 | 86 | |
|
87 | 87 | return data, {} |
|
88 | 88 | |
|
89 | 89 | class PowerPlot(RTIPlot): |
|
90 | 90 | ''' |
|
91 | 91 | Plot for Power Data (0 moment) |
|
92 | 92 | ''' |
|
93 | 93 | |
|
94 | 94 | CODE = 'pow' |
|
95 | 95 | colormap = 'jet' |
|
96 | 96 | |
|
97 | 97 | def update(self, dataOut): |
|
98 | 98 | data = { |
|
99 | 99 | 'pow': 10*numpy.log10(dataOut.data_pow/dataOut.normFactor) |
|
100 | 100 | } |
|
101 | 101 | return data, {} |
|
102 | 102 | |
|
103 | 103 | class SpectralWidthPlot(RTIPlot): |
|
104 | 104 | ''' |
|
105 | 105 | Plot for Spectral Width Data (2nd moment) |
|
106 | 106 | ''' |
|
107 | 107 | |
|
108 | 108 | CODE = 'width' |
|
109 | 109 | colormap = 'jet' |
|
110 | 110 | |
|
111 | 111 | def update(self, dataOut): |
|
112 | 112 | |
|
113 | 113 | data = { |
|
114 | 114 | 'width': dataOut.data_width |
|
115 | 115 | } |
|
116 | 116 | |
|
117 | 117 | return data, {} |
|
118 | 118 | |
|
119 | 119 | class SkyMapPlot(Plot): |
|
120 | 120 | ''' |
|
121 | 121 | Plot for meteors detection data |
|
122 | 122 | ''' |
|
123 | 123 | |
|
124 | 124 | CODE = 'param' |
|
125 | 125 | |
|
126 | 126 | def setup(self): |
|
127 | 127 | |
|
128 | 128 | self.ncols = 1 |
|
129 | 129 | self.nrows = 1 |
|
130 | 130 | self.width = 7.2 |
|
131 | 131 | self.height = 7.2 |
|
132 | 132 | self.nplots = 1 |
|
133 | 133 | self.xlabel = 'Zonal Zenith Angle (deg)' |
|
134 | 134 | self.ylabel = 'Meridional Zenith Angle (deg)' |
|
135 | 135 | self.polar = True |
|
136 | 136 | self.ymin = -180 |
|
137 | 137 | self.ymax = 180 |
|
138 | 138 | self.colorbar = False |
|
139 | 139 | |
|
140 | 140 | def plot(self): |
|
141 | 141 | |
|
142 | 142 | arrayParameters = numpy.concatenate(self.data['param']) |
|
143 | 143 | error = arrayParameters[:, -1] |
|
144 | 144 | indValid = numpy.where(error == 0)[0] |
|
145 | 145 | finalMeteor = arrayParameters[indValid, :] |
|
146 | 146 | finalAzimuth = finalMeteor[:, 3] |
|
147 | 147 | finalZenith = finalMeteor[:, 4] |
|
148 | 148 | |
|
149 | 149 | x = finalAzimuth * numpy.pi / 180 |
|
150 | 150 | y = finalZenith |
|
151 | 151 | |
|
152 | 152 | ax = self.axes[0] |
|
153 | 153 | |
|
154 | 154 | if ax.firsttime: |
|
155 | 155 | ax.plot = ax.plot(x, y, 'bo', markersize=5)[0] |
|
156 | 156 | else: |
|
157 | 157 | ax.plot.set_data(x, y) |
|
158 | 158 | |
|
159 | 159 | dt1 = self.getDateTime(self.data.min_time).strftime('%y/%m/%d %H:%M:%S') |
|
160 | 160 | dt2 = self.getDateTime(self.data.max_time).strftime('%y/%m/%d %H:%M:%S') |
|
161 | 161 | title = 'Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n' % (dt1, |
|
162 | 162 | dt2, |
|
163 | 163 | len(x)) |
|
164 | 164 | self.titles[0] = title |
|
165 | 165 | |
|
166 | 166 | |
|
167 | 167 | class GenericRTIPlot(Plot): |
|
168 | 168 | ''' |
|
169 | 169 | Plot for data_xxxx object |
|
170 | 170 | ''' |
|
171 | 171 | |
|
172 | 172 | CODE = 'param' |
|
173 | 173 | colormap = 'viridis' |
|
174 | 174 | plot_type = 'pcolorbuffer' |
|
175 | 175 | |
|
176 | 176 | def setup(self): |
|
177 | 177 | self.xaxis = 'time' |
|
178 | 178 | self.ncols = 1 |
|
179 | 179 | self.nrows = self.data.shape('param')[0] |
|
180 | 180 | self.nplots = self.nrows |
|
181 | 181 | self.plots_adjust.update({'hspace':0.8, 'left': 0.1, 'bottom': 0.08, 'right':0.95, 'top': 0.95}) |
|
182 | 182 | |
|
183 | 183 | if not self.xlabel: |
|
184 | 184 | self.xlabel = 'Time' |
|
185 | 185 | |
|
186 | 186 | self.ylabel = 'Range [km]' |
|
187 | 187 | if not self.titles: |
|
188 | 188 | self.titles = ['Param {}'.format(x) for x in range(self.nrows)] |
|
189 | 189 | |
|
190 | 190 | def update(self, dataOut): |
|
191 | 191 | |
|
192 | 192 | data = { |
|
193 | 193 | 'param' : numpy.concatenate([getattr(dataOut, attr) for attr in self.attr_data], axis=0) |
|
194 | 194 | } |
|
195 | 195 | |
|
196 | 196 | meta = {} |
|
197 | 197 | |
|
198 | 198 | return data, meta |
|
199 | 199 | |
|
200 | 200 | def plot(self): |
|
201 | 201 | # self.data.normalize_heights() |
|
202 | 202 | self.x = self.data.times |
|
203 | 203 | self.y = self.data.yrange |
|
204 | 204 | self.z = self.data['param'] |
|
205 | 205 | self.z = 10*numpy.log10(self.z) |
|
206 | 206 | self.z = numpy.ma.masked_invalid(self.z) |
|
207 | 207 | |
|
208 | 208 | if self.decimation is None: |
|
209 | 209 | x, y, z = self.fill_gaps(self.x, self.y, self.z) |
|
210 | 210 | else: |
|
211 | 211 | x, y, z = self.fill_gaps(*self.decimate()) |
|
212 | 212 | |
|
213 | 213 | for n, ax in enumerate(self.axes): |
|
214 | 214 | |
|
215 | 215 | self.zmax = self.zmax if self.zmax is not None else numpy.max( |
|
216 | 216 | self.z[n]) |
|
217 | 217 | self.zmin = self.zmin if self.zmin is not None else numpy.min( |
|
218 | 218 | self.z[n]) |
|
219 | 219 | |
|
220 | 220 | if ax.firsttime: |
|
221 | 221 | if self.zlimits is not None: |
|
222 | 222 | self.zmin, self.zmax = self.zlimits[n] |
|
223 | 223 | |
|
224 | 224 | ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n], |
|
225 | 225 | vmin=self.zmin, |
|
226 | 226 | vmax=self.zmax, |
|
227 | 227 | cmap=self.cmaps[n] |
|
228 | 228 | ) |
|
229 | 229 | else: |
|
230 | 230 | if self.zlimits is not None: |
|
231 | 231 | self.zmin, self.zmax = self.zlimits[n] |
|
232 | 232 | ax.collections.remove(ax.collections[0]) |
|
233 | 233 | ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n], |
|
234 | 234 | vmin=self.zmin, |
|
235 | 235 | vmax=self.zmax, |
|
236 | 236 | cmap=self.cmaps[n] |
|
237 | 237 | ) |
|
238 | 238 | |
|
239 | 239 | |
|
240 | 240 | class PolarMapPlot(Plot): |
|
241 | 241 | ''' |
|
242 | 242 | Plot for weather radar |
|
243 | 243 | ''' |
|
244 | 244 | |
|
245 | 245 | CODE = 'param' |
|
246 | 246 | colormap = 'seismic' |
|
247 | 247 | |
|
248 | 248 | def setup(self): |
|
249 | 249 | self.ncols = 1 |
|
250 | 250 | self.nrows = 1 |
|
251 | 251 | self.width = 9 |
|
252 | 252 | self.height = 8 |
|
253 | 253 | self.mode = self.data.meta['mode'] |
|
254 | 254 | if self.channels is not None: |
|
255 | 255 | self.nplots = len(self.channels) |
|
256 | 256 | self.nrows = len(self.channels) |
|
257 | 257 | else: |
|
258 | 258 | self.nplots = self.data.shape(self.CODE)[0] |
|
259 | 259 | self.nrows = self.nplots |
|
260 | 260 | self.channels = list(range(self.nplots)) |
|
261 | 261 | if self.mode == 'E': |
|
262 | 262 | self.xlabel = 'Longitude' |
|
263 | 263 | self.ylabel = 'Latitude' |
|
264 | 264 | else: |
|
265 | 265 | self.xlabel = 'Range (km)' |
|
266 | 266 | self.ylabel = 'Height (km)' |
|
267 | 267 | self.bgcolor = 'white' |
|
268 | 268 | self.cb_labels = self.data.meta['units'] |
|
269 | 269 | self.lat = self.data.meta['latitude'] |
|
270 | 270 | self.lon = self.data.meta['longitude'] |
|
271 | 271 | self.xmin, self.xmax = float( |
|
272 | 272 | km2deg(self.xmin) + self.lon), float(km2deg(self.xmax) + self.lon) |
|
273 | 273 | self.ymin, self.ymax = float( |
|
274 | 274 | km2deg(self.ymin) + self.lat), float(km2deg(self.ymax) + self.lat) |
|
275 | 275 | # self.polar = True |
|
276 | 276 | |
|
277 | 277 | def plot(self): |
|
278 | 278 | |
|
279 | 279 | for n, ax in enumerate(self.axes): |
|
280 | 280 | data = self.data['param'][self.channels[n]] |
|
281 | 281 | |
|
282 | 282 | zeniths = numpy.linspace( |
|
283 | 283 | 0, self.data.meta['max_range'], data.shape[1]) |
|
284 | 284 | if self.mode == 'E': |
|
285 | 285 | azimuths = -numpy.radians(self.data.yrange)+numpy.pi/2 |
|
286 | 286 | r, theta = numpy.meshgrid(zeniths, azimuths) |
|
287 | 287 | x, y = r*numpy.cos(theta)*numpy.cos(numpy.radians(self.data.meta['elevation'])), r*numpy.sin( |
|
288 | 288 | theta)*numpy.cos(numpy.radians(self.data.meta['elevation'])) |
|
289 | 289 | x = km2deg(x) + self.lon |
|
290 | 290 | y = km2deg(y) + self.lat |
|
291 | 291 | else: |
|
292 | 292 | azimuths = numpy.radians(self.data.yrange) |
|
293 | 293 | r, theta = numpy.meshgrid(zeniths, azimuths) |
|
294 | 294 | x, y = r*numpy.cos(theta), r*numpy.sin(theta) |
|
295 | 295 | self.y = zeniths |
|
296 | 296 | |
|
297 | 297 | if ax.firsttime: |
|
298 | 298 | if self.zlimits is not None: |
|
299 | 299 | self.zmin, self.zmax = self.zlimits[n] |
|
300 | 300 | ax.plt = ax.pcolormesh( # r, theta, numpy.ma.array(data, mask=numpy.isnan(data)), |
|
301 | 301 | x, y, numpy.ma.array(data, mask=numpy.isnan(data)), |
|
302 | 302 | vmin=self.zmin, |
|
303 | 303 | vmax=self.zmax, |
|
304 | 304 | cmap=self.cmaps[n]) |
|
305 | 305 | else: |
|
306 | 306 | if self.zlimits is not None: |
|
307 | 307 | self.zmin, self.zmax = self.zlimits[n] |
|
308 | 308 | ax.collections.remove(ax.collections[0]) |
|
309 | 309 | ax.plt = ax.pcolormesh( # r, theta, numpy.ma.array(data, mask=numpy.isnan(data)), |
|
310 | 310 | x, y, numpy.ma.array(data, mask=numpy.isnan(data)), |
|
311 | 311 | vmin=self.zmin, |
|
312 | 312 | vmax=self.zmax, |
|
313 | 313 | cmap=self.cmaps[n]) |
|
314 | 314 | |
|
315 | 315 | if self.mode == 'A': |
|
316 | 316 | continue |
|
317 | 317 | |
|
318 | 318 | # plot district names |
|
319 | 319 | f = open('/data/workspace/schain_scripts/distrito.csv') |
|
320 | 320 | for line in f: |
|
321 | 321 | label, lon, lat = [s.strip() for s in line.split(',') if s] |
|
322 | 322 | lat = float(lat) |
|
323 | 323 | lon = float(lon) |
|
324 | 324 | # ax.plot(lon, lat, '.b', ms=2) |
|
325 | 325 | ax.text(lon, lat, label.decode('utf8'), ha='center', |
|
326 | 326 | va='bottom', size='8', color='black') |
|
327 | 327 | |
|
328 | 328 | # plot limites |
|
329 | 329 | limites = [] |
|
330 | 330 | tmp = [] |
|
331 | 331 | for line in open('/data/workspace/schain_scripts/lima.csv'): |
|
332 | 332 | if '#' in line: |
|
333 | 333 | if tmp: |
|
334 | 334 | limites.append(tmp) |
|
335 | 335 | tmp = [] |
|
336 | 336 | continue |
|
337 | 337 | values = line.strip().split(',') |
|
338 | 338 | tmp.append((float(values[0]), float(values[1]))) |
|
339 | 339 | for points in limites: |
|
340 | 340 | ax.add_patch( |
|
341 | 341 | Polygon(points, ec='k', fc='none', ls='--', lw=0.5)) |
|
342 | 342 | |
|
343 | 343 | # plot Cuencas |
|
344 | 344 | for cuenca in ('rimac', 'lurin', 'mala', 'chillon', 'chilca', 'chancay-huaral'): |
|
345 | 345 | f = open('/data/workspace/schain_scripts/{}.csv'.format(cuenca)) |
|
346 | 346 | values = [line.strip().split(',') for line in f] |
|
347 | 347 | points = [(float(s[0]), float(s[1])) for s in values] |
|
348 | 348 | ax.add_patch(Polygon(points, ec='b', fc='none')) |
|
349 | 349 | |
|
350 | 350 | # plot grid |
|
351 | 351 | for r in (15, 30, 45, 60): |
|
352 | 352 | ax.add_artist(plt.Circle((self.lon, self.lat), |
|
353 | 353 | km2deg(r), color='0.6', fill=False, lw=0.2)) |
|
354 | 354 | ax.text( |
|
355 | 355 | self.lon + (km2deg(r))*numpy.cos(60*numpy.pi/180), |
|
356 | 356 | self.lat + (km2deg(r))*numpy.sin(60*numpy.pi/180), |
|
357 | 357 | '{}km'.format(r), |
|
358 | 358 | ha='center', va='bottom', size='8', color='0.6', weight='heavy') |
|
359 | 359 | |
|
360 | 360 | if self.mode == 'E': |
|
361 | 361 | title = 'El={}$^\circ$'.format(self.data.meta['elevation']) |
|
362 | 362 | label = 'E{:02d}'.format(int(self.data.meta['elevation'])) |
|
363 | 363 | else: |
|
364 | 364 | title = 'Az={}$^\circ$'.format(self.data.meta['azimuth']) |
|
365 | 365 | label = 'A{:02d}'.format(int(self.data.meta['azimuth'])) |
|
366 | 366 | |
|
367 | 367 | self.save_labels = ['{}-{}'.format(lbl, label) for lbl in self.labels] |
|
368 | 368 | self.titles = ['{} {}'.format( |
|
369 | 369 | self.data.parameters[x], title) for x in self.channels] |
|
370 | 370 | |
|
371 | 371 | class WeatherPlot(Plot): |
|
372 | 372 | CODE = 'weather' |
|
373 | 373 | plot_name = 'weather' |
|
374 | 374 | plot_type = 'ppistyle' |
|
375 | 375 | buffering = False |
|
376 | 376 | |
|
377 | 377 | def setup(self): |
|
378 | 378 | self.ncols = 1 |
|
379 | 379 | self.nrows = 1 |
|
380 | self.width =8 | |
|
381 | self.height =8 | |
|
380 | 382 | self.nplots= 1 |
|
381 | 383 | self.ylabel= 'Range [Km]' |
|
382 | 384 | self.titles= ['Weather'] |
|
383 | 385 | self.colorbar=False |
|
384 | self.width =8 | |
|
385 | self.height =8 | |
|
386 | 386 | self.ini =0 |
|
387 | 387 | self.len_azi =0 |
|
388 | 388 | self.buffer_ini = None |
|
389 | 389 | self.buffer_azi = None |
|
390 | 390 | self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08}) |
|
391 | 391 | self.flag =0 |
|
392 | 392 | self.indicador= 0 |
|
393 | 393 | self.last_data_azi = None |
|
394 | 394 | self.val_mean = None |
|
395 | 395 | |
|
396 | 396 | def update(self, dataOut): |
|
397 | 397 | |
|
398 | 398 | data = {} |
|
399 | 399 | meta = {} |
|
400 | 400 | if hasattr(dataOut, 'dataPP_POWER'): |
|
401 | 401 | factor = 1 |
|
402 | 402 | if hasattr(dataOut, 'nFFTPoints'): |
|
403 | 403 | factor = dataOut.normFactor |
|
404 | 404 | #print("DIME EL SHAPE PORFAVOR",dataOut.data_360.shape) |
|
405 | 405 | data['weather'] = 10*numpy.log10(dataOut.data_360[1]/(factor)) |
|
406 | 406 | data['azi'] = dataOut.data_azi |
|
407 | 407 | data['ele'] = dataOut.data_ele |
|
408 | 408 | return data, meta |
|
409 | 409 | |
|
410 | 410 | def get2List(self,angulos): |
|
411 | 411 | list1=[] |
|
412 | 412 | list2=[] |
|
413 | 413 | for i in reversed(range(len(angulos))): |
|
414 | 414 | diff_ = angulos[i]-angulos[i-1] |
|
415 | 415 | if diff_ >1.5: |
|
416 | 416 | list1.append(i-1) |
|
417 | 417 | list2.append(diff_) |
|
418 | 418 | return list(reversed(list1)),list(reversed(list2)) |
|
419 | 419 | |
|
420 | 420 | def fixData360(self,list_,ang_): |
|
421 | 421 | if list_[0]==-1: |
|
422 | 422 | vec = numpy.where(ang_<ang_[0]) |
|
423 | 423 | ang_[vec] = ang_[vec]+360 |
|
424 | 424 | return ang_ |
|
425 | 425 | return ang_ |
|
426 | 426 | |
|
427 | 427 | def fixData360HL(self,angulos): |
|
428 | 428 | vec = numpy.where(angulos>=360) |
|
429 | 429 | angulos[vec]=angulos[vec]-360 |
|
430 | 430 | return angulos |
|
431 | 431 | |
|
432 | 432 | def search_pos(self,pos,list_): |
|
433 | 433 | for i in range(len(list_)): |
|
434 | 434 | if pos == list_[i]: |
|
435 | 435 | return True,i |
|
436 | 436 | i=None |
|
437 | 437 | return False,i |
|
438 | 438 | |
|
439 | 439 | def fixDataComp(self,ang_,list1_,list2_): |
|
440 | 440 | size = len(ang_) |
|
441 | 441 | size2 = 0 |
|
442 | 442 | for i in range(len(list2_)): |
|
443 | 443 | size2=size2+round(list2_[i])-1 |
|
444 | 444 | new_size= size+size2 |
|
445 | 445 | ang_new = numpy.zeros(new_size) |
|
446 | 446 | ang_new2 = numpy.zeros(new_size) |
|
447 | 447 | |
|
448 | 448 | tmp = 0 |
|
449 | 449 | c = 0 |
|
450 | 450 | for i in range(len(ang_)): |
|
451 | 451 | ang_new[tmp +c] = ang_[i] |
|
452 | 452 | ang_new2[tmp+c] = ang_[i] |
|
453 | 453 | condition , value = self.search_pos(i,list1_) |
|
454 | 454 | if condition: |
|
455 | 455 | pos = tmp + c + 1 |
|
456 | 456 | for k in range(round(list2_[value])-1): |
|
457 | 457 | ang_new[pos+k] = ang_new[pos+k-1]+1 |
|
458 | 458 | ang_new2[pos+k] = numpy.nan |
|
459 | 459 | tmp = pos +k |
|
460 | 460 | c = 0 |
|
461 | 461 | c=c+1 |
|
462 | 462 | return ang_new,ang_new2 |
|
463 | 463 | |
|
464 | 464 | def globalCheckPED(self,angulos): |
|
465 | 465 | l1,l2 = self.get2List(angulos) |
|
466 | 466 | if len(l1)>0: |
|
467 | 467 | angulos2 = self.fixData360(list_=l1,ang_=angulos) |
|
468 | 468 | l1,l2 = self.get2List(angulos2) |
|
469 | 469 | |
|
470 | 470 | ang1_,ang2_ = self.fixDataComp(ang_=angulos2,list1_=l1,list2_=l2) |
|
471 | 471 | ang1_ = self.fixData360HL(ang1_) |
|
472 | 472 | ang2_ = self.fixData360HL(ang2_) |
|
473 | 473 | else: |
|
474 | 474 | ang1_= angulos |
|
475 | 475 | ang2_= angulos |
|
476 | 476 | return ang1_,ang2_ |
|
477 | 477 | |
|
478 | 478 | def analizeDATA(self,data_azi): |
|
479 | 479 | list1 = [] |
|
480 | 480 | list2 = [] |
|
481 | 481 | dat = data_azi |
|
482 | 482 | for i in reversed(range(1,len(dat))): |
|
483 | 483 | if dat[i]>dat[i-1]: |
|
484 | 484 | diff = int(dat[i])-int(dat[i-1]) |
|
485 | 485 | else: |
|
486 | 486 | diff = 360+int(dat[i])-int(dat[i-1]) |
|
487 | 487 | if diff > 1: |
|
488 | 488 | list1.append(i-1) |
|
489 | 489 | list2.append(diff-1) |
|
490 | 490 | return list1,list2 |
|
491 | 491 | |
|
492 | 492 | def fixDATANEW(self,data_azi,data_weather): |
|
493 | 493 | list1,list2 = self.analizeDATA(data_azi) |
|
494 | 494 | if len(list1)== 0: |
|
495 | 495 | return data_azi,data_weather |
|
496 | 496 | else: |
|
497 | 497 | resize = 0 |
|
498 | 498 | for i in range(len(list2)): |
|
499 | 499 | resize= resize + list2[i] |
|
500 | 500 | new_data_azi = numpy.resize(data_azi,resize) |
|
501 | 501 | new_data_weather= numpy.resize(date_weather,resize) |
|
502 | 502 | |
|
503 | 503 | for i in range(len(list2)): |
|
504 | 504 | j=0 |
|
505 | 505 | position=list1[i]+1 |
|
506 | 506 | for j in range(list2[i]): |
|
507 | 507 | new_data_azi[position+j]=new_data_azi[position+j-1]+1 |
|
508 | 508 | return new_data_azi |
|
509 | 509 | |
|
510 | 510 | def fixDATA(self,data_azi): |
|
511 | 511 | data=data_azi |
|
512 | 512 | for i in range(len(data)): |
|
513 | 513 | if numpy.isnan(data[i]): |
|
514 | 514 | data[i]=data[i-1]+1 |
|
515 | 515 | return data |
|
516 | 516 | |
|
517 | 517 | def replaceNAN(self,data_weather,data_azi,val): |
|
518 | 518 | data= data_azi |
|
519 | 519 | data_T= data_weather |
|
520 | 520 | if data.shape[0]> data_T.shape[0]: |
|
521 | 521 | data_N = numpy.ones( [data.shape[0],data_T.shape[1]]) |
|
522 | 522 | c = 0 |
|
523 | 523 | for i in range(len(data)): |
|
524 | 524 | if numpy.isnan(data[i]): |
|
525 | 525 | data_N[i,:]=numpy.ones(data_T.shape[1])*numpy.nan |
|
526 | 526 | else: |
|
527 | 527 | data_N[i,:]=data_T[c,:] |
|
528 | 528 | c=c+1 |
|
529 | 529 | return data_N |
|
530 | 530 | else: |
|
531 | 531 | for i in range(len(data)): |
|
532 | 532 | if numpy.isnan(data[i]): |
|
533 | 533 | data_T[i,:]=numpy.ones(data_T.shape[1])*numpy.nan |
|
534 | 534 | return data_T |
|
535 | 535 | |
|
536 | 536 | def const_ploteo(self,data_weather,data_azi,step,res): |
|
537 | 537 | if self.ini==0: |
|
538 | 538 | #------- |
|
539 | 539 | n = (360/res)-len(data_azi) |
|
540 | 540 | #--------------------- new ------------------------- |
|
541 | 541 | data_azi_new ,data_azi_old= self.globalCheckPED(data_azi) |
|
542 | 542 | #------------------------ |
|
543 | 543 | start = data_azi_new[-1] + res |
|
544 | 544 | end = data_azi_new[0] - res |
|
545 | 545 | #------ new |
|
546 | 546 | self.last_data_azi = end |
|
547 | 547 | if start>end: |
|
548 | 548 | end = end + 360 |
|
549 | 549 | azi_vacia = numpy.linspace(start,end,int(n)) |
|
550 | 550 | azi_vacia = numpy.where(azi_vacia>360,azi_vacia-360,azi_vacia) |
|
551 | 551 | data_azi = numpy.hstack((data_azi_new,azi_vacia)) |
|
552 | 552 | # RADAR |
|
553 | 553 | val_mean = numpy.mean(data_weather[:,-1]) |
|
554 | 554 | self.val_mean = val_mean |
|
555 | 555 | data_weather_cmp = numpy.ones([(360-data_weather.shape[0]),data_weather.shape[1]])*val_mean |
|
556 | 556 | data_weather = self.replaceNAN(data_weather=data_weather,data_azi=data_azi_old,val=self.val_mean) |
|
557 | 557 | data_weather = numpy.vstack((data_weather,data_weather_cmp)) |
|
558 | 558 | else: |
|
559 | 559 | # azimuth |
|
560 | 560 | flag=0 |
|
561 | 561 | start_azi = self.res_azi[0] |
|
562 | 562 | #-----------new------------ |
|
563 | 563 | data_azi ,data_azi_old= self.globalCheckPED(data_azi) |
|
564 | 564 | data_weather = self.replaceNAN(data_weather=data_weather,data_azi=data_azi_old,val=self.val_mean) |
|
565 | 565 | #-------------------------- |
|
566 | 566 | start = data_azi[0] |
|
567 | 567 | end = data_azi[-1] |
|
568 | 568 | self.last_data_azi= end |
|
569 | 569 | if start< start_azi: |
|
570 | 570 | start = start +360 |
|
571 | 571 | if end <start_azi: |
|
572 | 572 | end = end +360 |
|
573 | 573 | |
|
574 | 574 | pos_ini = int((start-start_azi)/res) |
|
575 | 575 | len_azi = len(data_azi) |
|
576 | 576 | if (360-pos_ini)<len_azi: |
|
577 | 577 | if pos_ini+1==360: |
|
578 | 578 | pos_ini=0 |
|
579 | 579 | else: |
|
580 | 580 | flag=1 |
|
581 | 581 | dif= 360-pos_ini |
|
582 | 582 | comp= len_azi-dif |
|
583 | 583 | #----------------- |
|
584 | 584 | if flag==0: |
|
585 | 585 | # AZIMUTH |
|
586 | 586 | self.res_azi[pos_ini:pos_ini+len_azi] = data_azi |
|
587 | 587 | # RADAR |
|
588 | 588 | self.res_weather[pos_ini:pos_ini+len_azi,:] = data_weather |
|
589 | 589 | else: |
|
590 | 590 | # AZIMUTH |
|
591 | 591 | self.res_azi[pos_ini:pos_ini+dif] = data_azi[0:dif] |
|
592 | 592 | self.res_azi[0:comp] = data_azi[dif:] |
|
593 | 593 | # RADAR |
|
594 | 594 | self.res_weather[pos_ini:pos_ini+dif,:] = data_weather[0:dif,:] |
|
595 | 595 | self.res_weather[0:comp,:] = data_weather[dif:,:] |
|
596 | 596 | flag=0 |
|
597 | 597 | data_azi = self.res_azi |
|
598 | 598 | data_weather = self.res_weather |
|
599 | 599 | |
|
600 | 600 | return data_weather,data_azi |
|
601 | 601 | |
|
602 | 602 | def plot(self): |
|
603 | 603 | thisDatetime = datetime.datetime.utcfromtimestamp(self.data.times[-1]).strftime('%Y-%m-%d %H:%M:%S') |
|
604 | 604 | data = self.data[-1] |
|
605 | 605 | r = self.data.yrange |
|
606 | 606 | delta_height = r[1]-r[0] |
|
607 | 607 | r_mask = numpy.where(r>=0)[0] |
|
608 | 608 | r = numpy.arange(len(r_mask))*delta_height |
|
609 | 609 | self.y = 2*r |
|
610 | 610 | # RADAR |
|
611 | 611 | #data_weather = data['weather'] |
|
612 | 612 | # PEDESTAL |
|
613 | 613 | #data_azi = data['azi'] |
|
614 | 614 | res = 1 |
|
615 | 615 | # STEP |
|
616 | 616 | step = (360/(res*data['weather'].shape[0])) |
|
617 | 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 | 619 | self.res_ele = numpy.mean(data['ele']) |
|
620 | 620 | ################# PLOTEO ################### |
|
621 | 621 | for i,ax in enumerate(self.axes): |
|
622 | 622 | if ax.firsttime: |
|
623 | 623 | plt.clf() |
|
624 | 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 | 625 | else: |
|
626 | 626 | plt.clf() |
|
627 | 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 | 628 | caax = cgax.parasites[0] |
|
629 | 629 | paax = cgax.parasites[1] |
|
630 | 630 | cbar = plt.gcf().colorbar(pm, pad=0.075) |
|
631 | 631 | caax.set_xlabel('x_range [km]') |
|
632 | 632 | caax.set_ylabel('y_range [km]') |
|
633 | 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 | 634 | |
|
635 | 635 | self.ini= self.ini+1 |
|
636 | 636 | |
|
637 | 637 | |
|
638 | 638 | class WeatherRHIPlot(Plot): |
|
639 | 639 | CODE = 'weather' |
|
640 | 640 | plot_name = 'weather' |
|
641 | 641 | plot_type = 'rhistyle' |
|
642 | 642 | buffering = False |
|
643 | 643 | data_ele_tmp = None |
|
644 | 644 | |
|
645 | 645 | def setup(self): |
|
646 | print("********************") | |
|
647 | print("********************") | |
|
648 | print("********************") | |
|
649 | print("SETUP WEATHER PLOT") | |
|
646 | 650 | self.ncols = 1 |
|
647 | 651 | self.nrows = 1 |
|
648 | 652 | self.nplots= 1 |
|
649 | 653 | self.ylabel= 'Range [Km]' |
|
650 | 654 | self.titles= ['Weather'] |
|
655 | if self.channels is not None: | |
|
656 | self.nplots = len(self.channels) | |
|
657 | self.nrows = len(self.channels) | |
|
658 | else: | |
|
659 | self.nplots = self.data.shape(self.CODE)[0] | |
|
660 | self.nrows = self.nplots | |
|
661 | self.channels = list(range(self.nplots)) | |
|
662 | print("channels",self.channels) | |
|
663 | 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 | print("self.titles",self.titles) | |
|
651 | 666 | self.colorbar=False |
|
652 | 667 | self.width =8 |
|
653 | 668 | self.height =8 |
|
654 | 669 | self.ini =0 |
|
655 | 670 | self.len_azi =0 |
|
656 | 671 | self.buffer_ini = None |
|
657 | 672 | self.buffer_ele = None |
|
658 | 673 | self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08}) |
|
659 | 674 | self.flag =0 |
|
660 | 675 | self.indicador= 0 |
|
661 | 676 | self.last_data_ele = None |
|
662 | 677 | self.val_mean = None |
|
663 | 678 | |
|
664 | 679 | def update(self, dataOut): |
|
665 | 680 | |
|
666 | 681 | data = {} |
|
667 | 682 | meta = {} |
|
668 | 683 | if hasattr(dataOut, 'dataPP_POWER'): |
|
669 | 684 | factor = 1 |
|
670 | 685 | if hasattr(dataOut, 'nFFTPoints'): |
|
671 | 686 | factor = dataOut.normFactor |
|
672 | data['weather'] = 10*numpy.log10(dataOut.data_360[1]/(factor)) | |
|
687 | print("dataOut",dataOut.data_360.shape) | |
|
688 | # | |
|
689 | data['weather'] = 10*numpy.log10(dataOut.data_360/(factor)) | |
|
690 | # | |
|
691 | #data['weather'] = 10*numpy.log10(dataOut.data_360[1]/(factor)) | |
|
673 | 692 | data['azi'] = dataOut.data_azi |
|
674 | 693 | data['ele'] = dataOut.data_ele |
|
694 | print("UPDATE") | |
|
695 | print("data[weather]",data['weather'].shape) | |
|
696 | print("data[azi]",data['azi']) | |
|
675 | 697 | return data, meta |
|
676 | 698 | |
|
677 | 699 | def get2List(self,angulos): |
|
678 | 700 | list1=[] |
|
679 | 701 | list2=[] |
|
680 | 702 | for i in reversed(range(len(angulos))): |
|
681 | 703 | if not i==0:#el caso de i=0 evalula el primero de la lista con el ultimo y no es relevante |
|
682 | 704 | diff_ = angulos[i]-angulos[i-1] |
|
683 | 705 | if abs(diff_) >1.5: |
|
684 | 706 | list1.append(i-1) |
|
685 | 707 | list2.append(diff_) |
|
686 | 708 | return list(reversed(list1)),list(reversed(list2)) |
|
687 | 709 | |
|
688 | 710 | def fixData90(self,list_,ang_): |
|
689 | 711 | if list_[0]==-1: |
|
690 | 712 | vec = numpy.where(ang_<ang_[0]) |
|
691 | 713 | ang_[vec] = ang_[vec]+90 |
|
692 | 714 | return ang_ |
|
693 | 715 | return ang_ |
|
694 | 716 | |
|
695 | 717 | def fixData90HL(self,angulos): |
|
696 | 718 | vec = numpy.where(angulos>=90) |
|
697 | 719 | angulos[vec]=angulos[vec]-90 |
|
698 | 720 | return angulos |
|
699 | 721 | |
|
700 | 722 | |
|
701 | 723 | def search_pos(self,pos,list_): |
|
702 | 724 | for i in range(len(list_)): |
|
703 | 725 | if pos == list_[i]: |
|
704 | 726 | return True,i |
|
705 | 727 | i=None |
|
706 | 728 | return False,i |
|
707 | 729 | |
|
708 | 730 | def fixDataComp(self,ang_,list1_,list2_,tipo_case): |
|
709 | 731 | size = len(ang_) |
|
710 | 732 | size2 = 0 |
|
711 | 733 | for i in range(len(list2_)): |
|
712 | 734 | size2=size2+round(abs(list2_[i]))-1 |
|
713 | 735 | new_size= size+size2 |
|
714 | 736 | ang_new = numpy.zeros(new_size) |
|
715 | 737 | ang_new2 = numpy.zeros(new_size) |
|
716 | 738 | |
|
717 | 739 | tmp = 0 |
|
718 | 740 | c = 0 |
|
719 | 741 | for i in range(len(ang_)): |
|
720 | 742 | ang_new[tmp +c] = ang_[i] |
|
721 | 743 | ang_new2[tmp+c] = ang_[i] |
|
722 | 744 | condition , value = self.search_pos(i,list1_) |
|
723 | 745 | if condition: |
|
724 | 746 | pos = tmp + c + 1 |
|
725 | 747 | for k in range(round(abs(list2_[value]))-1): |
|
726 | 748 | if tipo_case==0 or tipo_case==3:#subida |
|
727 | 749 | ang_new[pos+k] = ang_new[pos+k-1]+1 |
|
728 | 750 | ang_new2[pos+k] = numpy.nan |
|
729 | 751 | elif tipo_case==1 or tipo_case==2:#bajada |
|
730 | 752 | ang_new[pos+k] = ang_new[pos+k-1]-1 |
|
731 | 753 | ang_new2[pos+k] = numpy.nan |
|
732 | 754 | |
|
733 | 755 | tmp = pos +k |
|
734 | 756 | c = 0 |
|
735 | 757 | c=c+1 |
|
736 | 758 | return ang_new,ang_new2 |
|
737 | 759 | |
|
738 | 760 | def globalCheckPED(self,angulos,tipo_case): |
|
739 | 761 | l1,l2 = self.get2List(angulos) |
|
740 | 762 | ##print("l1",l1) |
|
741 | 763 | ##print("l2",l2) |
|
742 | 764 | if len(l1)>0: |
|
743 | 765 | #angulos2 = self.fixData90(list_=l1,ang_=angulos) |
|
744 | 766 | #l1,l2 = self.get2List(angulos2) |
|
745 | 767 | ang1_,ang2_ = self.fixDataComp(ang_=angulos,list1_=l1,list2_=l2,tipo_case=tipo_case) |
|
746 | 768 | #ang1_ = self.fixData90HL(ang1_) |
|
747 | 769 | #ang2_ = self.fixData90HL(ang2_) |
|
748 | 770 | else: |
|
749 | 771 | ang1_= angulos |
|
750 | 772 | ang2_= angulos |
|
751 | 773 | return ang1_,ang2_ |
|
752 | 774 | |
|
753 | 775 | |
|
754 | 776 | def replaceNAN(self,data_weather,data_ele,val): |
|
755 | 777 | data= data_ele |
|
756 | 778 | data_T= data_weather |
|
757 | 779 | if data.shape[0]> data_T.shape[0]: |
|
758 | 780 | data_N = numpy.ones( [data.shape[0],data_T.shape[1]]) |
|
759 | 781 | c = 0 |
|
760 | 782 | for i in range(len(data)): |
|
761 | 783 | if numpy.isnan(data[i]): |
|
762 | 784 | data_N[i,:]=numpy.ones(data_T.shape[1])*numpy.nan |
|
763 | 785 | else: |
|
764 | 786 | data_N[i,:]=data_T[c,:] |
|
765 | 787 | c=c+1 |
|
766 | 788 | return data_N |
|
767 | 789 | else: |
|
768 | 790 | for i in range(len(data)): |
|
769 | 791 | if numpy.isnan(data[i]): |
|
770 | 792 | data_T[i,:]=numpy.ones(data_T.shape[1])*numpy.nan |
|
771 | 793 | return data_T |
|
772 | 794 | |
|
773 | 795 | def check_case(self,data_ele,ang_max,ang_min): |
|
774 | 796 | start = data_ele[0] |
|
775 | 797 | end = data_ele[-1] |
|
776 | 798 | number = (end-start) |
|
777 | 799 | len_ang=len(data_ele) |
|
778 | 800 | |
|
779 | 801 | if start<end and (round(abs(number)+1)>=len_ang or (numpy.argmin(data_ele)==0)):#caso subida |
|
780 | 802 | return 0 |
|
781 | 803 | #elif start>end and (round(abs(number)+1)>=len_ang or(numpy.argmax(data_ele)==0)):#caso bajada |
|
782 | 804 | # return 1 |
|
783 | 805 | elif round(abs(number)+1)>=len_ang and (start>end or(numpy.argmax(data_ele)==0)):#caso bajada |
|
784 | 806 | return 1 |
|
785 | 807 | elif round(abs(number)+1)<len_ang and data_ele[-2]>data_ele[-1]:# caso BAJADA CAMBIO ANG MAX |
|
786 | 808 | return 2 |
|
787 | 809 | elif round(abs(number)+1)<len_ang and data_ele[-2]<data_ele[-1] :# caso SUBIDA CAMBIO ANG MIN |
|
788 | 810 | return 3 |
|
789 | 811 | |
|
790 | 812 | |
|
791 | def const_ploteo(self,data_weather,data_ele,step,res,ang_max,ang_min): | |
|
813 | def const_ploteo(self,val_ch,data_weather,data_ele,step,res,ang_max,ang_min): | |
|
792 | 814 | ang_max= ang_max |
|
793 | 815 | ang_min= ang_min |
|
794 | 816 | data_weather=data_weather |
|
817 | val_ch=val_ch | |
|
795 | 818 | ##print("*********************DATA WEATHER**************************************") |
|
796 | 819 | ##print(data_weather) |
|
797 | 820 | if self.ini==0: |
|
798 | 821 | ''' |
|
799 | 822 | print("**********************************************") |
|
800 | 823 | print("**********************************************") |
|
801 | 824 | print("***************ini**************") |
|
802 | 825 | print("**********************************************") |
|
803 | 826 | print("**********************************************") |
|
804 | 827 | ''' |
|
805 | 828 | #print("data_ele",data_ele) |
|
806 | 829 | #---------------------------------------------------------- |
|
807 | 830 | tipo_case = self.check_case(data_ele,ang_max,ang_min) |
|
831 | print("check_case",tipo_case) | |
|
808 | 832 | #--------------------- new ------------------------- |
|
809 | 833 | data_ele_new ,data_ele_old= self.globalCheckPED(data_ele,tipo_case) |
|
810 | 834 | |
|
811 | 835 | #-------------------------CAMBIOS RHI--------------------------------- |
|
812 | 836 | start= ang_min |
|
813 | 837 | end = ang_max |
|
814 | 838 | n= (ang_max-ang_min)/res |
|
815 | 839 | #------ new |
|
816 | 840 | self.start_data_ele = data_ele_new[0] |
|
817 | 841 | self.end_data_ele = data_ele_new[-1] |
|
818 | 842 | if tipo_case==0 or tipo_case==3: # SUBIDA |
|
819 | 843 | n1= round(self.start_data_ele)- start |
|
820 | 844 | n2= end - round(self.end_data_ele) |
|
821 | 845 | if n1>0: |
|
822 | 846 | ele1= numpy.linspace(ang_min+1,self.start_data_ele-1,n1) |
|
823 | 847 | ele1_nan= numpy.ones(n1)*numpy.nan |
|
824 | 848 | data_ele = numpy.hstack((ele1,data_ele_new)) |
|
825 | 849 | data_ele_old = numpy.hstack((ele1_nan,data_ele_old)) |
|
826 | 850 | if n2>0: |
|
827 | 851 | ele2= numpy.linspace(self.end_data_ele+1,end,n2) |
|
828 | 852 | ele2_nan= numpy.ones(n2)*numpy.nan |
|
829 | 853 | data_ele = numpy.hstack((data_ele,ele2)) |
|
830 | 854 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) |
|
831 | 855 | |
|
832 | 856 | if tipo_case==1 or tipo_case==2: # BAJADA |
|
833 | 857 | data_ele_new = data_ele_new[::-1] # reversa |
|
834 | 858 | data_ele_old = data_ele_old[::-1]# reversa |
|
835 | 859 | data_weather = data_weather[::-1,:]# reversa |
|
836 | 860 | vec= numpy.where(data_ele_new<ang_max) |
|
837 | 861 | data_ele_new = data_ele_new[vec] |
|
838 | 862 | data_ele_old = data_ele_old[vec] |
|
839 | 863 | data_weather = data_weather[vec[0]] |
|
840 | 864 | vec2= numpy.where(0<data_ele_new) |
|
841 | 865 | data_ele_new = data_ele_new[vec2] |
|
842 | 866 | data_ele_old = data_ele_old[vec2] |
|
843 | 867 | data_weather = data_weather[vec2[0]] |
|
844 | 868 | self.start_data_ele = data_ele_new[0] |
|
845 | 869 | self.end_data_ele = data_ele_new[-1] |
|
846 | 870 | |
|
847 | 871 | n1= round(self.start_data_ele)- start |
|
848 | n2= end - round(self.end_data_ele) | |
|
872 | n2= end - round(self.end_data_ele)-1 | |
|
873 | print(self.start_data_ele) | |
|
874 | print(self.end_data_ele) | |
|
849 | 875 | if n1>0: |
|
850 | 876 | ele1= numpy.linspace(ang_min+1,self.start_data_ele-1,n1) |
|
851 | 877 | ele1_nan= numpy.ones(n1)*numpy.nan |
|
852 | 878 | data_ele = numpy.hstack((ele1,data_ele_new)) |
|
853 | 879 | data_ele_old = numpy.hstack((ele1_nan,data_ele_old)) |
|
854 | 880 | if n2>0: |
|
855 | 881 | ele2= numpy.linspace(self.end_data_ele+1,end,n2) |
|
856 | 882 | ele2_nan= numpy.ones(n2)*numpy.nan |
|
857 | 883 | data_ele = numpy.hstack((data_ele,ele2)) |
|
858 | 884 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) |
|
859 | 885 | # RADAR |
|
860 | 886 | # NOTA data_ele y data_weather es la variable que retorna |
|
861 | 887 | val_mean = numpy.mean(data_weather[:,-1]) |
|
862 | 888 | self.val_mean = val_mean |
|
863 | 889 | data_weather = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) |
|
864 | self.data_ele_tmp= data_ele_old | |
|
890 | self.data_ele_tmp[val_ch]= data_ele_old | |
|
865 | 891 | else: |
|
866 | 892 | #print("**********************************************") |
|
867 | 893 | #print("****************VARIABLE**********************") |
|
868 | 894 | #-------------------------CAMBIOS RHI--------------------------------- |
|
869 | 895 | #--------------------------------------------------------------------- |
|
870 | 896 | ##print("INPUT data_ele",data_ele) |
|
871 | 897 | flag=0 |
|
872 | 898 | start_ele = self.res_ele[0] |
|
873 | 899 | tipo_case = self.check_case(data_ele,ang_max,ang_min) |
|
874 | 900 | #print("TIPO DE DATA",tipo_case) |
|
875 | 901 | #-----------new------------ |
|
876 | 902 | data_ele ,data_ele_old = self.globalCheckPED(data_ele,tipo_case) |
|
877 | 903 | data_weather = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) |
|
878 | 904 | |
|
879 | 905 | #-------------------------------NEW RHI ITERATIVO------------------------- |
|
880 | 906 | |
|
881 | 907 | if tipo_case==0 : # SUBIDA |
|
882 | 908 | vec = numpy.where(data_ele<ang_max) |
|
883 | 909 | data_ele = data_ele[vec] |
|
884 | 910 | data_ele_old = data_ele_old[vec] |
|
885 | 911 | data_weather = data_weather[vec[0]] |
|
886 | 912 | |
|
887 | 913 | vec2 = numpy.where(0<data_ele) |
|
888 | 914 | data_ele= data_ele[vec2] |
|
889 | 915 | data_ele_old= data_ele_old[vec2] |
|
890 | 916 | ##print(data_ele_new) |
|
891 | 917 | data_weather= data_weather[vec2[0]] |
|
892 | 918 | |
|
893 | 919 | new_i_ele = int(round(data_ele[0])) |
|
894 | 920 | new_f_ele = int(round(data_ele[-1])) |
|
895 | 921 | #print(new_i_ele) |
|
896 | 922 | #print(new_f_ele) |
|
897 | 923 | #print(data_ele,len(data_ele)) |
|
898 | 924 | #print(data_ele_old,len(data_ele_old)) |
|
899 | 925 | if new_i_ele< 2: |
|
900 | self.data_ele_tmp = numpy.ones(ang_max-ang_min)*numpy.nan | |
|
901 | self.res_weather = self.replaceNAN(data_weather=self.res_weather,data_ele=self.data_ele_tmp,val=self.val_mean) | |
|
902 | self.data_ele_tmp[new_i_ele:new_i_ele+len(data_ele)]=data_ele_old | |
|
926 | self.data_ele_tmp[val_ch] = numpy.ones(ang_max-ang_min)*numpy.nan | |
|
927 | 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) | |
|
928 | self.data_ele_tmp[val_ch][new_i_ele:new_i_ele+len(data_ele)]=data_ele_old | |
|
903 | 929 | self.res_ele[new_i_ele:new_i_ele+len(data_ele)]= data_ele |
|
904 | self.res_weather[new_i_ele:new_i_ele+len(data_ele),:]= data_weather | |
|
930 | self.res_weather[val_ch][new_i_ele:new_i_ele+len(data_ele),:]= data_weather | |
|
905 | 931 | data_ele = self.res_ele |
|
906 | data_weather = self.res_weather | |
|
932 | data_weather = self.res_weather[val_ch] | |
|
907 | 933 | |
|
908 | 934 | elif tipo_case==1 : #BAJADA |
|
909 | 935 | data_ele = data_ele[::-1] # reversa |
|
910 | 936 | data_ele_old = data_ele_old[::-1]# reversa |
|
911 | 937 | data_weather = data_weather[::-1,:]# reversa |
|
912 | 938 | vec= numpy.where(data_ele<ang_max) |
|
913 | 939 | data_ele = data_ele[vec] |
|
914 | 940 | data_ele_old = data_ele_old[vec] |
|
915 | 941 | data_weather = data_weather[vec[0]] |
|
916 | 942 | vec2= numpy.where(0<data_ele) |
|
917 | 943 | data_ele = data_ele[vec2] |
|
918 | 944 | data_ele_old = data_ele_old[vec2] |
|
919 | 945 | data_weather = data_weather[vec2[0]] |
|
920 | 946 | |
|
921 | 947 | |
|
922 | 948 | new_i_ele = int(round(data_ele[0])) |
|
923 | 949 | new_f_ele = int(round(data_ele[-1])) |
|
924 | 950 | #print(data_ele) |
|
925 | 951 | #print(ang_max) |
|
926 | 952 | #print(data_ele_old) |
|
927 | 953 | if new_i_ele <= 1: |
|
928 | 954 | new_i_ele = 1 |
|
929 | 955 | if round(data_ele[-1])>=ang_max-1: |
|
930 | self.data_ele_tmp = numpy.ones(ang_max-ang_min)*numpy.nan | |
|
931 | self.res_weather = self.replaceNAN(data_weather=self.res_weather,data_ele=self.data_ele_tmp,val=self.val_mean) | |
|
932 | self.data_ele_tmp[new_i_ele-1:new_i_ele+len(data_ele)-1]=data_ele_old | |
|
956 | self.data_ele_tmp[val_ch] = numpy.ones(ang_max-ang_min)*numpy.nan | |
|
957 | 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) | |
|
958 | self.data_ele_tmp[val_ch][new_i_ele-1:new_i_ele+len(data_ele)-1]=data_ele_old | |
|
933 | 959 | self.res_ele[new_i_ele-1:new_i_ele+len(data_ele)-1]= data_ele |
|
934 | self.res_weather[new_i_ele-1:new_i_ele+len(data_ele)-1,:]= data_weather | |
|
960 | self.res_weather[val_ch][new_i_ele-1:new_i_ele+len(data_ele)-1,:]= data_weather | |
|
935 | 961 | data_ele = self.res_ele |
|
936 | data_weather = self.res_weather | |
|
962 | data_weather = self.res_weather[val_ch] | |
|
937 | 963 | |
|
938 | 964 | elif tipo_case==2: #bajada |
|
939 | 965 | vec = numpy.where(data_ele<ang_max) |
|
940 | 966 | data_ele = data_ele[vec] |
|
941 | 967 | data_weather= data_weather[vec[0]] |
|
942 | 968 | |
|
943 | 969 | len_vec = len(vec) |
|
944 | 970 | data_ele_new = data_ele[::-1] # reversa |
|
945 | 971 | data_weather = data_weather[::-1,:] |
|
946 | 972 | new_i_ele = int(data_ele_new[0]) |
|
947 | 973 | new_f_ele = int(data_ele_new[-1]) |
|
948 | 974 | |
|
949 | 975 | n1= new_i_ele- ang_min |
|
950 | 976 | n2= ang_max - new_f_ele-1 |
|
951 | 977 | if n1>0: |
|
952 | 978 | ele1= numpy.linspace(ang_min+1,new_i_ele-1,n1) |
|
953 | 979 | ele1_nan= numpy.ones(n1)*numpy.nan |
|
954 | 980 | data_ele = numpy.hstack((ele1,data_ele_new)) |
|
955 | 981 | data_ele_old = numpy.hstack((ele1_nan,data_ele_new)) |
|
956 | 982 | if n2>0: |
|
957 | 983 | ele2= numpy.linspace(new_f_ele+1,ang_max,n2) |
|
958 | 984 | ele2_nan= numpy.ones(n2)*numpy.nan |
|
959 | 985 | data_ele = numpy.hstack((data_ele,ele2)) |
|
960 | 986 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) |
|
961 | 987 | |
|
962 | self.data_ele_tmp = data_ele_old | |
|
988 | self.data_ele_tmp[val_ch] = data_ele_old | |
|
963 | 989 | self.res_ele = data_ele |
|
964 | self.res_weather = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) | |
|
990 | self.res_weather[val_ch] = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) | |
|
965 | 991 | data_ele = self.res_ele |
|
966 | data_weather = self.res_weather | |
|
992 | data_weather = self.res_weather[val_ch] | |
|
967 | 993 | |
|
968 | 994 | elif tipo_case==3:#subida |
|
969 | 995 | vec = numpy.where(0<data_ele) |
|
970 | 996 | data_ele= data_ele[vec] |
|
971 | 997 | data_ele_new = data_ele |
|
972 | 998 | data_ele_old= data_ele_old[vec] |
|
973 | 999 | data_weather= data_weather[vec[0]] |
|
974 | 1000 | pos_ini = numpy.argmin(data_ele) |
|
975 | 1001 | if pos_ini>0: |
|
976 | 1002 | len_vec= len(data_ele) |
|
977 | 1003 | vec3 = numpy.linspace(pos_ini,len_vec-1,len_vec-pos_ini).astype(int) |
|
978 | 1004 | #print(vec3) |
|
979 | 1005 | data_ele= data_ele[vec3] |
|
980 | 1006 | data_ele_new = data_ele |
|
981 | 1007 | data_ele_old= data_ele_old[vec3] |
|
982 | 1008 | data_weather= data_weather[vec3] |
|
983 | 1009 | |
|
984 | 1010 | new_i_ele = int(data_ele_new[0]) |
|
985 | 1011 | new_f_ele = int(data_ele_new[-1]) |
|
986 | 1012 | n1= new_i_ele- ang_min |
|
987 | 1013 | n2= ang_max - new_f_ele-1 |
|
988 | 1014 | if n1>0: |
|
989 | 1015 | ele1= numpy.linspace(ang_min+1,new_i_ele-1,n1) |
|
990 | 1016 | ele1_nan= numpy.ones(n1)*numpy.nan |
|
991 | 1017 | data_ele = numpy.hstack((ele1,data_ele_new)) |
|
992 | 1018 | data_ele_old = numpy.hstack((ele1_nan,data_ele_new)) |
|
993 | 1019 | if n2>0: |
|
994 | 1020 | ele2= numpy.linspace(new_f_ele+1,ang_max,n2) |
|
995 | 1021 | ele2_nan= numpy.ones(n2)*numpy.nan |
|
996 | 1022 | data_ele = numpy.hstack((data_ele,ele2)) |
|
997 | 1023 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) |
|
998 | 1024 | |
|
999 | self.data_ele_tmp = data_ele_old | |
|
1025 | self.data_ele_tmp[val_ch] = data_ele_old | |
|
1000 | 1026 | self.res_ele = data_ele |
|
1001 | self.res_weather = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) | |
|
1027 | self.res_weather[val_ch] = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) | |
|
1002 | 1028 | data_ele = self.res_ele |
|
1003 | data_weather = self.res_weather | |
|
1029 | data_weather = self.res_weather[val_ch] | |
|
1004 | 1030 | #print("self.data_ele_tmp",self.data_ele_tmp) |
|
1005 | 1031 | return data_weather,data_ele |
|
1006 | 1032 | |
|
1007 | 1033 | |
|
1008 | 1034 | def plot(self): |
|
1009 | 1035 | thisDatetime = datetime.datetime.utcfromtimestamp(self.data.times[-1]).strftime('%Y-%m-%d %H:%M:%S') |
|
1010 | 1036 | data = self.data[-1] |
|
1011 | 1037 | r = self.data.yrange |
|
1012 | 1038 | delta_height = r[1]-r[0] |
|
1013 | 1039 | r_mask = numpy.where(r>=0)[0] |
|
1014 | 1040 | ##print("delta_height",delta_height) |
|
1015 | 1041 | #print("r_mask",r_mask,len(r_mask)) |
|
1016 | 1042 | r = numpy.arange(len(r_mask))*delta_height |
|
1017 | 1043 | self.y = 2*r |
|
1018 | 1044 | res = 1 |
|
1019 | 1045 | ###print("data['weather'].shape[0]",data['weather'].shape[0]) |
|
1020 | 1046 | ang_max = self.ang_max |
|
1021 | 1047 | ang_min = self.ang_min |
|
1022 | 1048 | var_ang =ang_max - ang_min |
|
1023 | 1049 | step = (int(var_ang)/(res*data['weather'].shape[0])) |
|
1024 | 1050 | ###print("step",step) |
|
1025 | 1051 | #-------------------------------------------------------- |
|
1026 | 1052 | ##print('weather',data['weather'].shape) |
|
1027 | 1053 | ##print('ele',data['ele'].shape) |
|
1028 | 1054 | |
|
1029 | 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) | |
|
1030 | self.res_azi = numpy.mean(data['azi']) | |
|
1055 | ###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) | |
|
1056 | ###self.res_azi = numpy.mean(data['azi']) | |
|
1031 | 1057 | ###print("self.res_ele",self.res_ele) |
|
1058 | plt.clf() | |
|
1059 | subplots = [121, 122] | |
|
1060 | if self.ini==0: | |
|
1061 | self.data_ele_tmp = numpy.ones([self.nplots,int(var_ang)])*numpy.nan | |
|
1062 | self.res_weather= numpy.ones([self.nplots,int(var_ang),len(r_mask)])*numpy.nan | |
|
1063 | print("SHAPE",self.data_ele_tmp.shape) | |
|
1064 | ||
|
1032 | 1065 | for i,ax in enumerate(self.axes): |
|
1066 | 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) | |
|
1067 | self.res_azi = numpy.mean(data['azi']) | |
|
1033 | 1068 | if ax.firsttime: |
|
1034 | plt.clf() | |
|
1035 |
cgax, pm = wrl.vis.plot_rhi(self.res_weather,r=r,th=self.res_ele, |
|
|
1069 | #plt.clf() | |
|
1070 | 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) | |
|
1071 | #fig=self.figures[0] | |
|
1036 | 1072 | else: |
|
1037 | plt.clf() | |
|
1038 |
cgax, pm = wrl.vis.plot_rhi(self.res_weather,r=r,th=self.res_ele, |
|
|
1039 | caax = cgax.parasites[0] | |
|
1040 | paax = cgax.parasites[1] | |
|
1041 | cbar = plt.gcf().colorbar(pm, pad=0.075) | |
|
1042 | caax.set_xlabel('x_range [km]') | |
|
1043 | caax.set_ylabel('y_range [km]') | |
|
1044 | 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') | |
|
1045 | ||
|
1046 | #print("***************************self.ini****************************",self.ini) | |
|
1073 | #plt.clf() | |
|
1074 | 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) | |
|
1075 | caax = cgax.parasites[0] | |
|
1076 | paax = cgax.parasites[1] | |
|
1077 | cbar = plt.gcf().colorbar(pm, pad=0.075) | |
|
1078 | caax.set_xlabel('x_range [km]') | |
|
1079 | caax.set_ylabel('y_range [km]') | |
|
1080 | 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') | |
|
1081 | print("***************************self.ini****************************",self.ini) | |
|
1047 | 1082 | self.ini= self.ini+1 |
General Comments 0
You need to be logged in to leave comments.
Login now