@@ -20,7 +20,7 import matplotlib,re | |||
|
20 | 20 | if 'BACKEND' in os.environ: |
|
21 | 21 | matplotlib.use(os.environ['BACKEND']) |
|
22 | 22 | elif 'linux' in sys.platform: |
|
23 |
matplotlib.use(" |
|
|
23 | matplotlib.use("Agg") | |
|
24 | 24 | elif 'darwin' in sys.platform: |
|
25 | 25 | matplotlib.use('MacOSX') |
|
26 | 26 | else: |
@@ -168,6 +168,7 class Plot(Operation): | |||
|
168 | 168 | bgcolor = 'white' |
|
169 | 169 | buffering = True |
|
170 | 170 | __missing = 1E30 |
|
171 | projection = None | |
|
171 | 172 | |
|
172 | 173 | __attrs__ = ['show', 'save', 'ymin', 'ymax', 'zmin', 'zmax', 'title', |
|
173 | 174 | 'showprofile'] |
@@ -252,7 +253,7 class Plot(Operation): | |||
|
252 | 253 | self.ang_max = kwargs.get('ang_max', None) |
|
253 | 254 | self.mode = kwargs.get('mode', None) |
|
254 | 255 | self.mask = kwargs.get('mask', False) |
|
255 | ||
|
256 | self.shapes = kwargs.get('shapes', './') | |
|
256 | 257 | |
|
257 | 258 | if self.server: |
|
258 | 259 | if not self.server.startswith('tcp://'): |
@@ -277,8 +278,8 class Plot(Operation): | |||
|
277 | 278 | if self.width is None: |
|
278 | 279 | self.width = 8 |
|
279 | 280 | |
|
280 | self.figures = [] | |
|
281 | self.axes = [] | |
|
281 | self.figures = {'PPI':[], 'RHI':[]} | |
|
282 | self.axes = {'PPI':[], 'RHI':[]} | |
|
282 | 283 | self.cb_axes = [] |
|
283 | 284 | self.pf_axes = [] |
|
284 | 285 | self.cmaps = [] |
@@ -289,18 +290,29 class Plot(Operation): | |||
|
289 | 290 | if self.oneFigure: |
|
290 | 291 | if self.height is None: |
|
291 | 292 | self.height = 1.4 * self.nrows + 1 |
|
292 | fig = plt.figure(figsize=(self.width, self.height), | |
|
293 | fig_p = plt.figure(figsize=(self.width, self.height), | |
|
293 | 294 | edgecolor='k', |
|
294 | 295 | facecolor='w') |
|
295 | self.figures.append(fig) | |
|
296 | for n in range(self.nplots): | |
|
297 | ax = fig.add_subplot(self.nrows, self.ncols, | |
|
298 | n + 1, polar=self.polar) | |
|
299 | ax.tick_params(labelsize=8) | |
|
300 | ax.firsttime = True | |
|
301 | ax.index = 0 | |
|
302 | ax.press = None | |
|
303 | self.axes.append(ax) | |
|
296 | fig_r = plt.figure(figsize=(self.width, self.height), | |
|
297 | edgecolor='k', | |
|
298 | facecolor='w') | |
|
299 | self.figures['PPI'].append(fig_p) | |
|
300 | self.figures['RHI'].append(fig_r) | |
|
301 | for n in range(self.nplots): | |
|
302 | ax_p = fig_p.add_subplot(self.nrows, self.ncols, n+1, polar=self.polar, projection=self.projection) | |
|
303 | ax_r = fig_r.add_subplot(self.nrows, self.ncols, n+1, polar=self.polar) | |
|
304 | ax_p.tick_params(labelsize=8) | |
|
305 | ax_p.firsttime = True | |
|
306 | ax_p.index = 0 | |
|
307 | ax_p.press = None | |
|
308 | ax_r.tick_params(labelsize=8) | |
|
309 | ax_r.firsttime = True | |
|
310 | ax_r.index = 0 | |
|
311 | ax_r.press = None | |
|
312 | ||
|
313 | self.axes['PPI'].append(ax_p) | |
|
314 | self.axes['RHI'].append(ax_r) | |
|
315 | ||
|
304 | 316 | if self.showprofile: |
|
305 | 317 | cax = self.__add_axes(ax, size=size, pad=pad) |
|
306 | 318 | cax.tick_params(labelsize=8) |
@@ -312,13 +324,19 class Plot(Operation): | |||
|
312 | 324 | fig = plt.figure(figsize=(self.width, self.height), |
|
313 | 325 | edgecolor='k', |
|
314 | 326 | facecolor='w') |
|
315 | ax = fig.add_subplot(1, 1, 1, polar=self.polar) | |
|
316 | ax.tick_params(labelsize=8) | |
|
317 |
ax. |
|
|
318 |
ax. |
|
|
319 |
ax. |
|
|
327 | ax_p = fig.add_subplot(1, 1, 1, polar=self.polar, projection=self.projection) | |
|
328 | ax_r = fig.add_subplot(1, 1, 1, polar=self.polar) | |
|
329 | ax_p.tick_params(labelsize=8) | |
|
330 | ax_p.firsttime = True | |
|
331 | ax_p.index = 0 | |
|
332 | ax_p.press = None | |
|
333 | ax_r.tick_params(labelsize=8) | |
|
334 | ax_r.firsttime = True | |
|
335 | ax_r.index = 0 | |
|
336 | ax_r.press = None | |
|
320 | 337 | self.figures.append(fig) |
|
321 | self.axes.append(ax) | |
|
338 | self.axes['PPI'].append(ax_p) | |
|
339 | self.axes['RHI'].append(ax_r) | |
|
322 | 340 | if self.showprofile: |
|
323 | 341 | cax = self.__add_axes(ax, size=size, pad=pad) |
|
324 | 342 | cax.tick_params(labelsize=8) |
@@ -378,7 +396,7 class Plot(Operation): | |||
|
378 | 396 | Set min and max values, labels, ticks and titles |
|
379 | 397 | ''' |
|
380 | 398 | |
|
381 | for n, ax in enumerate(self.axes): | |
|
399 | for n, ax in enumerate(self.axes[self.mode]): | |
|
382 | 400 | if ax.firsttime: |
|
383 | 401 | if self.xaxis != 'time': |
|
384 | 402 | xmin = self.xmin |
@@ -390,7 +408,9 class Plot(Operation): | |||
|
390 | 408 | ax.xaxis.set_major_locator(LinearLocator(9)) |
|
391 | 409 | ymin = self.ymin if self.ymin is not None else numpy.nanmin(self.y[numpy.isfinite(self.y)]) |
|
392 | 410 | ymax = self.ymax if self.ymax is not None else numpy.nanmax(self.y[numpy.isfinite(self.y)]) |
|
411 | ||
|
393 | 412 | ax.set_facecolor(self.bgcolor) |
|
413 | ||
|
394 | 414 | if self.xscale: |
|
395 | 415 | ax.xaxis.set_major_formatter(FuncFormatter( |
|
396 | 416 | lambda x, pos: '{0:g}'.format(x*self.xscale))) |
@@ -407,7 +427,7 class Plot(Operation): | |||
|
407 | 427 | self.pf_axes[n].set_xlabel('dB') |
|
408 | 428 | self.pf_axes[n].grid(b=True, axis='x') |
|
409 | 429 | [tick.set_visible(False) |
|
410 |
|
|
|
430 | for tick in self.pf_axes[n].get_yticklabels()] | |
|
411 | 431 | if self.colorbar: |
|
412 | 432 | ax.cbar = plt.colorbar( |
|
413 | 433 | ax.plt, ax=ax, fraction=0.05, pad=0.06, aspect=10) |
@@ -419,8 +439,9 class Plot(Operation): | |||
|
419 | 439 | ax.cbar.set_label(self.cb_labels[n], size=8) |
|
420 | 440 | else: |
|
421 | 441 | ax.cbar = None |
|
422 | ax.set_xlim(xmin, xmax) | |
|
423 |
ax.set_ |
|
|
442 | if self.mode == 'RHI': | |
|
443 | ax.set_xlim(xmin, xmax) | |
|
444 | ax.set_ylim(ymin, ymax) | |
|
424 | 445 | ax.firsttime = False |
|
425 | 446 | if self.grid: |
|
426 | 447 | ax.grid(True) |
@@ -447,7 +468,7 class Plot(Operation): | |||
|
447 | 468 | ax.xaxis.labelpad = 16 |
|
448 | 469 | |
|
449 | 470 | if self.firsttime: |
|
450 |
for |
|
|
471 | for fig in self.figures['PPI'] + self.figures['RHI']: | |
|
451 | 472 | fig.subplots_adjust(**self.plots_adjust) |
|
452 | 473 | self.firsttime = False |
|
453 | 474 | |
@@ -456,7 +477,9 class Plot(Operation): | |||
|
456 | 477 | Reset axes for redraw plots |
|
457 | 478 | ''' |
|
458 | 479 | |
|
459 |
|
|
|
480 | axes = self.pf_axes + self.cb_axes + self.axes[self.mode] | |
|
481 | ||
|
482 | for ax in axes: | |
|
460 | 483 | ax.clear() |
|
461 | 484 | ax.firsttime = True |
|
462 | 485 | if hasattr(ax, 'cbar') and ax.cbar: |
@@ -469,8 +492,8 class Plot(Operation): | |||
|
469 | 492 | |
|
470 | 493 | self.plot() |
|
471 | 494 | self.format() |
|
472 | ||
|
473 |
for n, fig in enumerate( |
|
|
495 | figures = self.figures[self.mode] | |
|
496 | for n, fig in enumerate(figures): | |
|
474 | 497 | if self.nrows == 0 or self.nplots == 0: |
|
475 | 498 | log.warning('No data', self.name) |
|
476 | 499 | fig.text(0.5, 0.5, 'No Data', fontsize='large', ha='center') |
@@ -511,8 +534,10 class Plot(Operation): | |||
|
511 | 534 | ''' |
|
512 | 535 | if self.mode is not None: |
|
513 | 536 | ang = 'AZ' if self.mode == 'RHI' else 'EL' |
|
514 |
|
|
|
537 | folder = '_{}_{}_{}'.format(self.mode, ang, self.mode_value) | |
|
538 | label = '{}{}_{}'.format(ang[0], self.mode_value, self.save_code) | |
|
515 | 539 | else: |
|
540 | folder = '' | |
|
516 | 541 | label = '' |
|
517 | 542 | |
|
518 | 543 | if self.oneFigure: |
@@ -521,18 +546,19 class Plot(Operation): | |||
|
521 | 546 | |
|
522 | 547 | self.save_time = self.data.max_time |
|
523 | 548 | |
|
524 | fig = self.figures[n] | |
|
549 | fig = self.figures[self.mode][n] | |
|
525 | 550 | |
|
526 | 551 | if self.throttle == 0: |
|
527 | 552 | if self.oneFigure: |
|
528 | 553 | figname = os.path.join( |
|
529 | 554 | self.save, |
|
530 |
self.save_code + |
|
|
531 | '{}_{}.png'.format( | |
|
532 |
|
|
|
555 | self.save_code + folder, | |
|
556 | '{}_{}_{}.png'.format( | |
|
557 | 'SOPHY', | |
|
533 | 558 | self.getDateTime(self.data.max_time).strftime( |
|
534 | 559 | '%Y%m%d_%H%M%S' |
|
535 | 560 | ), |
|
561 | label | |
|
536 | 562 | ) |
|
537 | 563 | ) |
|
538 | 564 | else: |
@@ -3,6 +3,10 import datetime | |||
|
3 | 3 | import warnings |
|
4 | 4 | import numpy |
|
5 | 5 | from mpl_toolkits.axisartist.grid_finder import FixedLocator, DictFormatter |
|
6 | from matplotlib.patches import Circle | |
|
7 | import cartopy.crs as ccrs | |
|
8 | from cartopy.feature import ShapelyFeature | |
|
9 | import cartopy.io.shapereader as shpreader | |
|
6 | 10 | |
|
7 | 11 | from schainpy.model.graphics.jroplot_base import Plot, plt |
|
8 | 12 | from schainpy.model.graphics.jroplot_spectra import SpectraPlot, RTIPlot, CoherencePlot, SpectraCutPlot |
@@ -514,6 +518,7 class WeatherParamsPlot(Plot): | |||
|
514 | 518 | #plot_name = 'RHI' |
|
515 | 519 | plot_type = 'scattermap' |
|
516 | 520 | buffering = False |
|
521 | projection = ccrs.PlateCarree() | |
|
517 | 522 | |
|
518 | 523 | def setup(self): |
|
519 | 524 | |
@@ -522,8 +527,7 class WeatherParamsPlot(Plot): | |||
|
522 | 527 | self.nplots= 1 |
|
523 | 528 | self.ylabel= 'Range [km]' |
|
524 | 529 | self.xlabel= 'Range [km]' |
|
525 | self.polar = True | |
|
526 | self.grid = True | |
|
530 | ||
|
527 | 531 | if self.channels is not None: |
|
528 | 532 | self.nplots = len(self.channels) |
|
529 | 533 | self.ncols = len(self.channels) |
@@ -537,7 +541,7 class WeatherParamsPlot(Plot): | |||
|
537 | 541 | self.width = 12 |
|
538 | 542 | else: |
|
539 | 543 | self.width =8 |
|
540 |
self.height = |
|
|
544 | self.height =7 | |
|
541 | 545 | self.ini =0 |
|
542 | 546 | self.len_azi =0 |
|
543 | 547 | self.buffer_ini = None |
@@ -589,11 +593,12 class WeatherParamsPlot(Plot): | |||
|
589 | 593 | |
|
590 | 594 | data['data'] = [0, 0] |
|
591 | 595 | |
|
592 |
|
|
|
593 | data['data'][0] = tmp[0][:,valid] | |
|
594 | data['data'][1] = tmp[1][:,valid] | |
|
595 |
|
|
|
596 |
|
|
|
596 | try: | |
|
597 | data['data'][0] = tmp[0][:,valid] | |
|
598 | data['data'][1] = tmp[1][:,valid] | |
|
599 | except: | |
|
600 | data['data'][0] = tmp[0][:,valid] | |
|
601 | data['data'][1] = tmp[0][:,valid] | |
|
597 | 602 | |
|
598 | 603 | if dataOut.mode_op == 'PPI': |
|
599 | 604 | self.CODE = 'PPI' |
@@ -606,23 +611,6 class WeatherParamsPlot(Plot): | |||
|
606 | 611 | data['ele'] = dataOut.data_ele |
|
607 | 612 | data['mode_op'] = dataOut.mode_op |
|
608 | 613 | self.mode = dataOut.mode_op |
|
609 | var = data['data'][0].flatten() | |
|
610 | r = numpy.tile(data['r'], data['data'][0].shape[0]) | |
|
611 | az = numpy.repeat(data['azi'], data['data'][0].shape[1]) | |
|
612 | el = numpy.repeat(data['ele'], data['data'][0].shape[1]) | |
|
613 | ||
|
614 | # lla = georef.spherical_to_proj(r, data['azi'], data['ele'], (-75.295893, -12.040436, 3379.2147)) | |
|
615 | ||
|
616 | latlon = antenna_to_geographic(r, az, el, (-75.295893, -12.040436)) | |
|
617 | ||
|
618 | if self.mask: | |
|
619 | meta['lat'] = latlon[1][var.mask==False] | |
|
620 | meta['lon'] = latlon[0][var.mask==False] | |
|
621 | data['var'] = numpy.array([var[var.mask==False]]) | |
|
622 | else: | |
|
623 | meta['lat'] = latlon[1] | |
|
624 | meta['lon'] = latlon[0] | |
|
625 | data['var'] = numpy.array([var]) | |
|
626 | 614 | |
|
627 | 615 | return data, meta |
|
628 | 616 | |
@@ -641,45 +629,32 class WeatherParamsPlot(Plot): | |||
|
641 | 629 | data['mode_op'] = data['mode_op'].decode() |
|
642 | 630 | |
|
643 | 631 | if data['mode_op'] == 'RHI': |
|
644 | try: | |
|
645 | if self.data['mode_op'][-2] == 'PPI': | |
|
646 | self.ang_min = None | |
|
647 | self.ang_max = None | |
|
648 | except: | |
|
649 | pass | |
|
650 | self.ang_min = self.ang_min if self.ang_min else 0 | |
|
651 | self.ang_max = self.ang_max if self.ang_max else 90 | |
|
652 | r, theta = numpy.meshgrid(r, numpy.radians(data['ele']) ) | |
|
653 | elif data['mode_op'] == 'PPI': | |
|
654 | try: | |
|
655 | if self.data['mode_op'][-2] == 'RHI': | |
|
656 | self.ang_min = None | |
|
657 | self.ang_max = None | |
|
658 | except: | |
|
659 | pass | |
|
660 | self.ang_min = self.ang_min if self.ang_min else 0 | |
|
661 | self.ang_max = self.ang_max if self.ang_max else 360 | |
|
662 | r, theta = numpy.meshgrid(r, numpy.radians(data['azi']) ) | |
|
632 | r, theta = numpy.meshgrid(r, numpy.radians(data['ele'])) | |
|
633 | len_aux = int(data['azi'].shape[0]/4) | |
|
634 | mean = numpy.mean(data['azi'][len_aux:-len_aux]) | |
|
635 | x, y = r*numpy.cos(theta), r*numpy.sin(theta) | |
|
636 | elif data['mode_op'] == 'PPI': | |
|
637 | r, theta = numpy.meshgrid(r, -numpy.radians(data['azi'])+numpy.pi/2) | |
|
638 | len_aux = int(data['ele'].shape[0]/4) | |
|
639 | mean = numpy.mean(data['ele'][len_aux:-len_aux]) | |
|
640 | x, y = r*numpy.cos(theta)*numpy.cos(numpy.radians(mean)), r*numpy.sin( | |
|
641 | theta)*numpy.cos(numpy.radians(mean)) | |
|
642 | x = km2deg(x) + -75.295893 | |
|
643 | y = km2deg(y) + -12.040436 | |
|
663 | 644 | |
|
664 | 645 | self.clear_figures() |
|
665 | 646 | |
|
666 | for i,ax in enumerate(self.axes): | |
|
667 | ||
|
668 | if ax.firsttime: | |
|
669 | ax.set_xlim(numpy.radians(self.ang_min),numpy.radians(self.ang_max)) | |
|
670 | ax.plt = ax.pcolormesh(theta, r, z[i], cmap=self.colormap, vmin=self.zmin, vmax=self.zmax) | |
|
671 | if data['mode_op'] == 'PPI': | |
|
672 | ax.set_theta_direction(-1) | |
|
673 | ax.set_theta_offset(numpy.pi/2) | |
|
647 | if data['mode_op'] == 'PPI': | |
|
648 | axes = self.axes['PPI'] | |
|
649 | else: | |
|
650 | axes = self.axes['RHI'] | |
|
674 | 651 | |
|
675 | else: | |
|
676 | ax.set_xlim(numpy.radians(self.ang_min),numpy.radians(self.ang_max)) | |
|
677 | ax.plt = ax.pcolormesh(theta, r, z[i], cmap=self.colormap, vmin=self.zmin, vmax=self.zmax) | |
|
678 | if data['mode_op'] == 'PPI': | |
|
679 | ax.set_theta_direction(-1) | |
|
680 | ax.set_theta_offset(numpy.pi/2) | |
|
652 | for i, ax in enumerate(axes): | |
|
653 | if data['mode_op'] == 'PPI': | |
|
654 | ax.set_extent([-75.745893, -74.845893, -12.490436, -11.590436]) | |
|
655 | ||
|
656 | ax.plt = ax.pcolormesh(x, y, z[i], cmap=self.colormap, vmin=self.zmin, vmax=self.zmax) | |
|
681 | 657 | |
|
682 | ax.grid(True) | |
|
683 | 658 | if data['mode_op'] == 'RHI': |
|
684 | 659 | len_aux = int(data['azi'].shape[0]/4) |
|
685 | 660 | mean = numpy.mean(data['azi'][len_aux:-len_aux]) |
@@ -694,4 +669,48 class WeatherParamsPlot(Plot): | |||
|
694 | 669 | self.titles = ['PPI {} at EL: {} CH {}'.format(self.labels[x], str(round(mean,1)), x) for x in self.channels] |
|
695 | 670 | else: |
|
696 | 671 | self.titles = ['PPI {} at EL: {} CH {}'.format(self.labels[0], str(round(mean,1)), self.channels[0])] |
|
697 | self.mode_value = round(mean,1) No newline at end of file | |
|
672 | self.mode_value = round(mean,1) | |
|
673 | ||
|
674 | if data['mode_op'] == 'PPI': | |
|
675 | gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True, | |
|
676 | linewidth=1, color='gray', alpha=0.5, linestyle='--') | |
|
677 | gl.xlabel_style = {'size': 8} | |
|
678 | gl.ylabel_style = {'size': 8} | |
|
679 | gl.xlabels_top = False | |
|
680 | gl.ylabels_right = False | |
|
681 | shape_p = os.path.join(self.shapes,'PER_ADM2/PER_ADM2.shp') | |
|
682 | shape_d = os.path.join(self.shapes,'PER_ADM1/PER_ADM1.shp') | |
|
683 | capitales = os.path.join(self.shapes,'CAPITALES/cap_provincia.shp') | |
|
684 | vias = os.path.join(self.shapes,'Carreteras/VIAS_NACIONAL_250000.shp') | |
|
685 | reader_d = shpreader.BasicReader(shape_p, encoding='latin1') | |
|
686 | reader_p = shpreader.BasicReader(shape_d, encoding='latin1') | |
|
687 | reader_c = shpreader.BasicReader(capitales, encoding='latin1') | |
|
688 | reader_v = shpreader.BasicReader(vias, encoding='latin1') | |
|
689 | caps = [x for x in reader_c.records() if x.attributes["Departa"] in ("JUNIN", "LIMA", "AYACUCHO", "HUANCAVELICA")] | |
|
690 | districts = [x for x in reader_d.records() if x.attributes["Name"] in ("JUNΓN", "CHANCHAMAYO", "CHUPACA", "CONCEPCIΓN", "HUANCAYO", "JAUJA", "SATIPO", "TARMA", "YAUYOS", "HUAROCHIRΓ", "CANTA", "HUANTA", "TAYACAJA")] | |
|
691 | provs = [x for x in reader_p.records() if x.attributes["NAME"] in ("JunΓn", "Lima")] | |
|
692 | vias = [x for x in reader_v.records() if x.attributes["DEP"] in ("JUNIN", "LIMA")] | |
|
693 | ||
|
694 | # Display Kenya's shape | |
|
695 | shape_feature = ShapelyFeature([x.geometry for x in districts], ccrs.PlateCarree(), facecolor="none", edgecolor='grey', lw=0.5) | |
|
696 | ax.add_feature(shape_feature) | |
|
697 | shape_feature = ShapelyFeature([x.geometry for x in provs], ccrs.PlateCarree(), facecolor="none", edgecolor='white', lw=1) | |
|
698 | ax.add_feature(shape_feature) | |
|
699 | shape_feature = ShapelyFeature([x.geometry for x in vias], ccrs.PlateCarree(), facecolor="none", edgecolor='yellow', lw=1) | |
|
700 | ax.add_feature(shape_feature) | |
|
701 | ||
|
702 | for cap in caps: | |
|
703 | if cap.attributes['Nombre'] in ("LA OROYA", "CONCEPCIΓN", "HUANCAYO", "JAUJA", "CHUPACA", "YAUYOS", "HUANTA", "PAMPAS"): | |
|
704 | ax.text(cap.attributes['X'], cap.attributes['Y'], cap.attributes['Nombre'].title(), size=7, color='white') | |
|
705 | ax.text(-75.052003, -11.915552, 'Huaytapallana', size=7, color='cyan') | |
|
706 | ax.plot(-75.052003, -11.915552, '*') | |
|
707 | ||
|
708 | for R in (10, 20, 30 , 40, 50): | |
|
709 | circle = Circle((-75.295893, -12.040436), km2deg(R), facecolor='none', | |
|
710 | edgecolor='skyblue', linewidth=1, alpha=0.5) | |
|
711 | ax.add_patch(circle) | |
|
712 | ax.text(km2deg(R)*numpy.cos(numpy.radians(45))-75.295893, | |
|
713 | km2deg(R)*numpy.sin(numpy.radians(45))-12.040436, | |
|
714 | '{}km'.format(R), color='skyblue', size=7) | |
|
715 | elif data['mode_op'] == 'RHI': | |
|
716 | ax.grid(color='grey', alpha=0.5, linestyle='--', linewidth=1) |
@@ -505,6 +505,7 class HDFWriter(Operation): | |||
|
505 | 505 | |
|
506 | 506 | if self.setType == 'weather': |
|
507 | 507 | subfolder = dt.strftime('%Y-%m-%dT%H-00-00') |
|
508 | subfolder = '' | |
|
508 | 509 | else: |
|
509 | 510 | subfolder = dt.strftime('d%Y%j') |
|
510 | 511 | |
@@ -541,12 +542,14 class HDFWriter(Operation): | |||
|
541 | 542 | #SOPHY_20200505_140215_E10.0_Z.h5 |
|
542 | 543 | #SOPHY_20200505_140215_A40.0_Z.h5 |
|
543 | 544 | if self.dataOut.flagMode == 1: #'AZI' #PPI |
|
544 | ang_type = 'E' | |
|
545 | ang_type = 'EL' | |
|
546 | mode_type = 'PPI' | |
|
545 | 547 | len_aux = int(self.dataOut.data_ele.shape[0]/4) |
|
546 | 548 | mean = numpy.mean(self.dataOut.data_ele[len_aux:-len_aux]) |
|
547 | 549 | ang_ = round(mean,1) |
|
548 | 550 | elif self.dataOut.flagMode == 0: #'ELE' #RHI |
|
549 | ang_type = 'A' | |
|
551 | ang_type = 'AZ' | |
|
552 | mode_type = 'RHI' | |
|
550 | 553 | len_aux = int(self.dataOut.data_azi.shape[0]/4) |
|
551 | 554 | mean = numpy.mean(self.dataOut.data_azi[len_aux:-len_aux]) |
|
552 | 555 | ang_ = round(mean,1) |
@@ -559,11 +562,14 class HDFWriter(Operation): | |||
|
559 | 562 | dt.hour, |
|
560 | 563 | dt.minute, |
|
561 | 564 | dt.second, |
|
562 | ang_type, | |
|
565 | ang_type[0], | |
|
563 | 566 | ang_, |
|
564 | 567 | self.weather_var, |
|
565 | 568 | ext ) |
|
566 | ||
|
569 | subfolder = '{}_{}_{}_{:2.1f}'.format(self.weather_var, mode_type, ang_type, ang_) | |
|
570 | fullpath = os.path.join(path, subfolder) | |
|
571 | if not os.path.exists(fullpath): | |
|
572 | os.makedirs(fullpath) | |
|
567 | 573 | else: |
|
568 | 574 | setFile = dt.hour*60+dt.minute |
|
569 | 575 | file = '%s%4.4d%3.3d%04d%s' % (self.optchar, |
@@ -4143,6 +4143,9 class PedestalInformation(Operation): | |||
|
4143 | 4143 | continue |
|
4144 | 4144 | self.fp.close() |
|
4145 | 4145 | self.fp = h5py.File(self.filename, 'r') |
|
4146 | self.ele = self.fp['Data']['ele_pos'][:] | |
|
4147 | self.azi = self.fp['Data']['azi_pos'][:] + 26.27 | |
|
4148 | self.azi[self.azi>360] = self.azi[self.azi>360] - 360 | |
|
4146 | 4149 | log.log('Opening file: {}'.format(self.filename), self.name) |
|
4147 | 4150 | ok = True |
|
4148 | 4151 | break |
@@ -4162,25 +4165,25 class PedestalInformation(Operation): | |||
|
4162 | 4165 | raise IOError('No new position files found in {}'.format(path)) |
|
4163 | 4166 | |
|
4164 | 4167 | |
|
4165 | def find_mode(self,index): | |
|
4168 | def find_mode(self, index): | |
|
4166 | 4169 | sample_max = 20 |
|
4167 | 4170 | start = index |
|
4168 | flag_mode = None | |
|
4169 | azi = self.fp['Data']['azi_pos'][:] | |
|
4170 | ele = self.fp['Data']['ele_pos'][:] | |
|
4171 | flag_mode = None | |
|
4171 | 4172 | |
|
4172 | 4173 | while True: |
|
4173 |
|
|
|
4174 | print("CANNOT KNOW IF MODE IS PPI OR RHI, ANALIZE NEXT FILE") | |
|
4175 | print("ele",ele[start-sample_max:start+sample_max]) | |
|
4176 | print("azi",azi[start-sample_max:start+sample_max]) | |
|
4174 | print(start, sample_max, numpy.shape(self.ele)) | |
|
4175 | if start+sample_max > numpy.shape(self.ele)[0]: | |
|
4177 | 4176 | if sample_max == 10: |
|
4177 | print("CANNOT KNOW IF MODE IS PPI OR RHI, ANALIZE NEXT FILE") | |
|
4178 | 4178 | break |
|
4179 | 4179 | else: |
|
4180 | 4180 | sample_max = 10 |
|
4181 | 4181 | continue |
|
4182 | sigma_ele = numpy.nanstd(ele[start:start+sample_max]) | |
|
4183 | sigma_azi = numpy.nanstd(azi[start:start+sample_max]) | |
|
4182 | sigma_ele = numpy.nanstd(self.ele[start:start+sample_max]) | |
|
4183 | sigma_azi = numpy.nanstd(self.azi[start:start+sample_max]) | |
|
4184 | print("ele",self.ele[start-sample_max:start+sample_max]) | |
|
4185 | print("azi",self.azi[start-sample_max:start+sample_max]) | |
|
4186 | print(sigma_azi, sigma_ele) | |
|
4184 | 4187 | |
|
4185 | 4188 | if sigma_ele<.5 and sigma_azi<.5: |
|
4186 | 4189 | if sigma_ele<sigma_azi: |
@@ -4206,14 +4209,20 class PedestalInformation(Operation): | |||
|
4206 | 4209 | return numpy.nan, numpy.nan, numpy.nan #Should be self.mode? |
|
4207 | 4210 | else: |
|
4208 | 4211 | index = int((self.utctime-self.utcfile)/self.interval) |
|
4212 | try: | |
|
4213 | #print( self.azi[index], self.ele[index], None) | |
|
4214 | return self.azi[index], self.ele[index], None | |
|
4215 | except: | |
|
4216 | return numpy.nan, numpy.nan, numpy.nan | |
|
4209 | 4217 | |
|
4210 | 4218 | if self.flagAskMode: |
|
4211 | 4219 | mode = self.find_mode(index) |
|
4220 | print('MODE: ', mode) | |
|
4212 | 4221 | else: |
|
4213 | 4222 | mode = self.mode |
|
4214 | 4223 | |
|
4215 | 4224 | if mode is not None: |
|
4216 |
return self. |
|
|
4225 | return self.azi[index], self.ele[index], mode | |
|
4217 | 4226 | else: |
|
4218 | 4227 | return numpy.nan, numpy.nan, numpy.nan |
|
4219 | 4228 | |
@@ -4242,6 +4251,10 class PedestalInformation(Operation): | |||
|
4242 | 4251 | try: |
|
4243 | 4252 | self.fp = h5py.File(self.filename, 'r') |
|
4244 | 4253 | self.utcfile = int(self.filename.split('/')[-1][4:14]) |
|
4254 | ||
|
4255 | self.ele = self.fp['Data']['ele_pos'][:] | |
|
4256 | self.azi = self.fp['Data']['azi_pos'][:] + 26.27 | |
|
4257 | self.azi[self.azi>360] = self.azi[self.azi>360] - 360 | |
|
4245 | 4258 | break |
|
4246 | 4259 | except: |
|
4247 | 4260 | log.warning('Waiting {}s for position file to be ready...'.format(self.delay), self.name) |
@@ -4258,12 +4271,13 class PedestalInformation(Operation): | |||
|
4258 | 4271 | self.find_next_file() |
|
4259 | 4272 | |
|
4260 | 4273 | az, el, scan = self.get_values() |
|
4274 | ||
|
4261 | 4275 | dataOut.flagNoData = False |
|
4262 | 4276 | if numpy.isnan(az) or numpy.isnan(el) : |
|
4263 | 4277 | dataOut.flagNoData = True |
|
4264 | 4278 | return dataOut |
|
4265 | ||
|
4266 | dataOut.azimuth = round(az, 2) | |
|
4279 | ||
|
4280 | dataOut.azimuth = round(az, 2) | |
|
4267 | 4281 | dataOut.elevation = round(el, 2) |
|
4268 | 4282 | dataOut.mode_op = scan |
|
4269 | 4283 | |
@@ -4303,146 +4317,150 class Block360(Operation): | |||
|
4303 | 4317 | self.attr = attr |
|
4304 | 4318 | |
|
4305 | 4319 | self.__buffer = [] |
|
4306 |
self. |
|
|
4307 |
self. |
|
|
4308 | self.__buffer4 = [] | |
|
4320 | self.azi = [] | |
|
4321 | self.ele = [] | |
|
4309 | 4322 | |
|
4310 |
def putData(self, data, attr |
|
|
4323 | def putData(self, data, attr): | |
|
4311 | 4324 | ''' |
|
4312 | 4325 | Add a profile to he __buffer and increase in one the __profiel Index |
|
4313 | 4326 | ''' |
|
4314 | 4327 | tmp= getattr(data, attr) |
|
4315 | 4328 | self.__buffer.append(tmp) |
|
4316 |
self. |
|
|
4317 |
self. |
|
|
4329 | self.azi.append(data.azimuth) | |
|
4330 | self.ele.append(data.elevation) | |
|
4318 | 4331 | self.__profIndex += 1 |
|
4319 | 4332 | |
|
4320 | if flagMode == 1: #'AZI' | |
|
4321 | return numpy.array(self.__buffer2) | |
|
4322 | elif flagMode == 0: #'ELE' | |
|
4323 | return numpy.array(self.__buffer3) | |
|
4324 | ||
|
4325 | def pushData(self, data,flagMode,case_flag): | |
|
4333 | def pushData(self, data, case_flag): | |
|
4326 | 4334 | ''' |
|
4327 | Return the PULSEPAIR and the profiles used in the operation | |
|
4328 | Affected : self.__profileIndex | |
|
4329 | 4335 | ''' |
|
4330 | 4336 | |
|
4331 | 4337 | data_360 = numpy.array(self.__buffer).transpose(1, 2, 0, 3) |
|
4332 |
data_p = numpy.array(self. |
|
|
4333 |
data_e = numpy.array(self. |
|
|
4338 | data_p = numpy.array(self.azi) | |
|
4339 | data_e = numpy.array(self.ele) | |
|
4334 | 4340 | n = self.__profIndex |
|
4335 | 4341 | |
|
4336 | 4342 | self.__buffer = [] |
|
4337 |
self. |
|
|
4338 |
self. |
|
|
4339 | self.__buffer4 = [] | |
|
4343 | self.azi = [] | |
|
4344 | self.ele = [] | |
|
4340 | 4345 | self.__profIndex = 0 |
|
4341 | 4346 | |
|
4342 | if flagMode == 1 and case_flag == 0: #'AZI' y ha girado | |
|
4343 |
self.putData(data=data, attr = self.attr |
|
|
4347 | if case_flag in (0, 1, -1): | |
|
4348 | self.putData(data=data, attr = self.attr) | |
|
4344 | 4349 | |
|
4345 | 4350 | return data_360, n, data_p, data_e |
|
4346 | 4351 | |
|
4347 |
def byProfiles(self,dataOut |
|
|
4352 | def byProfiles(self, dataOut): | |
|
4348 | 4353 | |
|
4349 |
self.__dataReady |
|
|
4354 | self.__dataReady = False | |
|
4350 | 4355 | data_360 = [] |
|
4351 |
data_p |
|
|
4352 |
data_e |
|
|
4356 | data_p = None | |
|
4357 | data_e = None | |
|
4353 | 4358 | |
|
4354 |
|
|
|
4355 | if self.__profIndex > 1: | |
|
4356 | case_flag = self.checkcase(angles,flagMode) | |
|
4359 | self.putData(data=dataOut, attr = self.attr) | |
|
4360 | ||
|
4361 | if self.__profIndex > 5: | |
|
4362 | case_flag = self.checkcase() | |
|
4357 | 4363 | |
|
4358 | if flagMode == 1: #'AZI': | |
|
4364 | if self.flagMode == 1: #'AZI': | |
|
4359 | 4365 | if case_flag == 0: #Ya girΓ³ |
|
4360 | 4366 | self.__buffer.pop() #Erase last data |
|
4361 |
self. |
|
|
4362 |
self. |
|
|
4363 |
data_360 ,n,data_p,data_e = self.pushData( |
|
|
4364 |
|
|
|
4365 | ||
|
4366 | elif flagMode == 0: #'ELE' | |
|
4367 | ||
|
4368 | if case_flag == 0: #Subida | |
|
4369 | ||
|
4370 | if len(self.__buffer) == 2: #Cuando estΓ‘ de subida | |
|
4371 | #Se borra el dato anterior para liberar buffer y comparar el dato actual con el siguiente | |
|
4372 | self.__buffer.pop(0) #Erase first data | |
|
4373 | self.__buffer2.pop(0) | |
|
4374 | self.__buffer3.pop(0) | |
|
4375 | self.__profIndex -= 1 | |
|
4376 | else: #Cuando ha estado de bajada y ha vuelto a subir | |
|
4377 | #Se borra el ΓΊltimo dato | |
|
4378 | self.__buffer.pop() #Erase last data | |
|
4379 | self.__buffer2.pop() | |
|
4380 | self.__buffer3.pop() | |
|
4381 | data_360, n, data_p, data_e = self.pushData(data=dataOut,flagMode=flagMode,case_flag=case_flag) | |
|
4367 | self.azi.pop() | |
|
4368 | self.ele.pop() | |
|
4369 | data_360 ,n,data_p,data_e = self.pushData(dataOut, case_flag) | |
|
4370 | if len(data_p)>350: | |
|
4382 | 4371 | self.__dataReady = True |
|
4372 | elif self.flagMode == 0: #'ELE' | |
|
4373 | if case_flag == 1: #Bajada | |
|
4374 | self.__buffer.pop() #Erase last data | |
|
4375 | self.azi.pop() | |
|
4376 | self.ele.pop() | |
|
4377 | data_360, n, data_p, data_e = self.pushData(dataOut, case_flag) | |
|
4378 | self.__dataReady = True | |
|
4379 | if case_flag == -1: #Subida | |
|
4380 | self.__buffer.pop() #Erase last data | |
|
4381 | self.azi.pop() | |
|
4382 | self.ele.pop() | |
|
4383 | data_360, n, data_p, data_e = self.pushData(dataOut, case_flag) | |
|
4384 | #self.__dataReady = True | |
|
4383 | 4385 | |
|
4384 | 4386 | return data_360, data_p, data_e |
|
4385 | 4387 | |
|
4386 | 4388 | |
|
4387 |
def blockOp(self, dataOut, |
|
|
4389 | def blockOp(self, dataOut, datatime= None): | |
|
4388 | 4390 | if self.__initime == None: |
|
4389 | 4391 | self.__initime = datatime |
|
4390 |
data_360, data_p, data_e = self.byProfiles(dataOut |
|
|
4391 |
self.__lastdatatime |
|
|
4392 | data_360, data_p, data_e = self.byProfiles(dataOut) | |
|
4393 | self.__lastdatatime = datatime | |
|
4392 | 4394 | |
|
4393 |
avgdatatime |
|
|
4395 | avgdatatime = self.__initime | |
|
4394 | 4396 | if self.n==1: |
|
4395 | 4397 | avgdatatime = datatime |
|
4396 | deltatime = datatime - self.__lastdatatime | |
|
4398 | ||
|
4397 | 4399 | self.__initime = datatime |
|
4398 | 4400 | return data_360, avgdatatime, data_p, data_e |
|
4399 | 4401 | |
|
4400 |
def checkcase(self |
|
|
4402 | def checkcase(self): | |
|
4403 | ||
|
4404 | sigma_ele = numpy.nanstd(self.ele[-5:]) | |
|
4405 | sigma_azi = numpy.nanstd(self.azi[-5:]) | |
|
4401 | 4406 | |
|
4402 | if flagMode == 1: #'AZI' | |
|
4403 | start = angles[-2] | |
|
4404 |
|
|
|
4407 | if sigma_ele<.5 and sigma_azi<.5: | |
|
4408 | if sigma_ele<sigma_azi: | |
|
4409 | self.flagMode = 1 | |
|
4410 | self.mode_op = 'PPI' | |
|
4411 | else: | |
|
4412 | self.flagMode = 0 | |
|
4413 | self.mode_op = 'RHI' | |
|
4414 | elif sigma_ele < .5: | |
|
4415 | self.flagMode = 1 | |
|
4416 | self.mode_op = 'PPI' | |
|
4417 | elif sigma_azi < .5: | |
|
4418 | self.flagMode = 0 | |
|
4419 | self.mode_op = 'RHI' | |
|
4420 | else: | |
|
4421 | self.flagMode = None | |
|
4422 | self.mode_op = 'None' | |
|
4423 | ||
|
4424 | if self.flagMode == 1: #'AZI' | |
|
4425 | start = self.azi[-2] | |
|
4426 | end = self.azi[-1] | |
|
4405 | 4427 | diff_angle = (end-start) |
|
4406 | 4428 | |
|
4407 | 4429 | if diff_angle < 0: #Ya girΓ³ |
|
4408 | 4430 | return 0 |
|
4409 | 4431 | |
|
4410 | elif flagMode == 0: #'ELE' | |
|
4432 | elif self.flagMode == 0: #'ELE' | |
|
4411 | 4433 | |
|
4412 |
start = |
|
|
4413 |
|
|
|
4414 | diff_angle = (end-start) | |
|
4434 | start = self.ele[-3] | |
|
4435 | middle = self.ele[-2] | |
|
4436 | end = self.ele[-1] | |
|
4415 | 4437 | |
|
4416 |
if d |
|
|
4417 |
return |
|
|
4438 | if end < 0: | |
|
4439 | return 1 | |
|
4440 | elif (middle>start and end<middle): | |
|
4441 | return -1 | |
|
4418 | 4442 | |
|
4419 | 4443 | def run(self, dataOut, attr_data='dataPP_POWER', runNextOp = False,**kwargs): |
|
4420 | 4444 | |
|
4421 | 4445 | dataOut.attr_data = attr_data |
|
4422 | 4446 | dataOut.runNextOp = runNextOp |
|
4423 | dataOut.flagAskMode = False | |
|
4424 | ||
|
4425 | if dataOut.mode_op == 'PPI': | |
|
4426 | dataOut.flagMode = 1 | |
|
4427 | elif dataOut.mode_op == 'RHI': | |
|
4428 | dataOut.flagMode = 0 | |
|
4429 | 4447 | |
|
4430 | 4448 | if not self.isConfig: |
|
4431 | 4449 | self.setup(dataOut = dataOut, attr = attr_data ,**kwargs) |
|
4432 | 4450 | self.isConfig = True |
|
4433 | 4451 | |
|
4434 |
data_360, avgdatatime, data_p, data_e = self.blockOp(dataOut, dataOut. |
|
|
4452 | data_360, avgdatatime, data_p, data_e = self.blockOp(dataOut, dataOut.utctime) | |
|
4435 | 4453 | |
|
4436 | 4454 | dataOut.flagNoData = True |
|
4437 | 4455 | |
|
4438 | 4456 | if self.__dataReady: |
|
4439 | 4457 | setattr(dataOut, attr_data, data_360 ) |
|
4440 |
dataOut.data_azi = data_p |
|
|
4441 | dataOut.data_azi[dataOut.data_azi>360] = dataOut.data_azi[dataOut.data_azi>360] - 360 | |
|
4458 | dataOut.data_azi = data_p | |
|
4442 | 4459 | dataOut.data_ele = data_e |
|
4443 | 4460 | dataOut.utctime = avgdatatime |
|
4444 | dataOut.flagNoData = False | |
|
4445 |
dataOut.flag |
|
|
4461 | dataOut.flagNoData = False | |
|
4462 | dataOut.flagMode = self.flagMode | |
|
4463 | dataOut.mode_op = self.mode_op | |
|
4446 | 4464 | |
|
4447 | 4465 | return dataOut |
|
4448 | 4466 |
General Comments 0
You need to be logged in to leave comments.
Login now