##// END OF EJS Templates
Update WeatherParamPlot maps and xlmits ylmits
jespinoza -
r1715:e1fb60c9a537
parent child
Show More
@@ -33,6 +33,8 from matplotlib.patches import Polygon
33 33 from mpl_toolkits.axes_grid1 import make_axes_locatable
34 34 from matplotlib.ticker import FuncFormatter, LinearLocator, MultipleLocator
35 35
36 import cartopy.crs as ccrs
37
36 38 from .plotting_codes import register_cmap
37 39
38 40 from schainpy.model.data.jrodata import PlotterData
@@ -218,7 +220,8 class Plot(Operation):
218 220 self.zlimits = kwargs.get('zlimits', None)
219 221 self.xmin = kwargs.get('xmin', None)
220 222 self.xmax = kwargs.get('xmax', None)
221 self.xrange = kwargs.get('xrange', 12)
223 self.yrange = kwargs.get('yrange', None)
224 self.xrange = kwargs.get('xrange', None)
222 225 self.xscale = kwargs.get('xscale', None)
223 226 self.ymin = kwargs.get('ymin', None)
224 227 self.ymax = kwargs.get('ymax', None)
@@ -253,6 +256,9 class Plot(Operation):
253 256 self.mode = kwargs.get('mode', None)
254 257 self.mask = kwargs.get('mask', False)
255 258 self.shapes = kwargs.get('shapes', './')
259 self.map = kwargs.get('map', False)
260 self.latitude = kwargs.get('latitude', -12)
261 self.longitude = kwargs.get('longitude', -74)
256 262
257 263 if self.server:
258 264 if not self.server.startswith('tcp://'):
@@ -265,6 +271,7 class Plot(Operation):
265 271 if isinstance(self.attr_data, str):
266 272 self.attr_data = [self.attr_data]
267 273
274
268 275 def __setup_plot(self):
269 276 '''
270 277 Common setup for all figures, here figures and axes are created
@@ -298,7 +305,11 class Plot(Operation):
298 305 self.figures['PPI'].append(fig_p)
299 306 self.figures['RHI'].append(fig_r)
300 307 for n in range(self.nplots):
301 ax_p = fig_p.add_subplot(self.nrows, self.ncols, n+1, polar=self.polar, projection=self.projection)
308 if self.map:
309 ax_p = fig_p.add_subplot(self.nrows, self.ncols, n+1, polar=self.polar, projection=ccrs.PlateCarree())
310 else:
311 ax_p = fig_p.add_subplot(self.nrows, self.ncols, n+1, polar=self.polar)
312 print('sin projection')
302 313 ax_r = fig_r.add_subplot(self.nrows, self.ncols, n+1, polar=self.polar)
303 314 ax_p.tick_params(labelsize=8)
304 315 ax_p.firsttime = True
@@ -323,7 +334,12 class Plot(Operation):
323 334 fig = plt.figure(figsize=(self.width, self.height),
324 335 edgecolor='k',
325 336 facecolor='w')
326 ax_p = fig.add_subplot(1, 1, 1, polar=self.polar, projection=self.projection)
337 if self.map:
338 ax_p = fig.add_subplot(1, 1, 1, polar=self.polar, projection=ccrs.PlateCarree())
339 else:
340 ax_p = fig.add_subplot(1, 1, 1, polar=self.polar)
341 print('sin projection')
342
327 343 ax_r = fig.add_subplot(1, 1, 1, polar=self.polar)
328 344 ax_p.tick_params(labelsize=8)
329 345 ax_p.firsttime = True
@@ -442,9 +458,10 class Plot(Operation):
442 458 ax.cbar.set_label(self.cb_labels[n], size=8)
443 459 else:
444 460 ax.cbar = None
445 if self.mode == 'RHI':
461 #if self.mode == 'RHI':
446 462 ax.set_xlim(xmin, xmax)
447 463 ax.set_ylim(ymin, ymax)
464
448 465 ax.firsttime = False
449 466 if self.grid:
450 467 ax.grid(True)
@@ -463,7 +480,6 class Plot(Operation):
463 480 '%Y-%m-%d %H:%M:%S'),
464 481 self.time_label),
465 482 size=8)
466 ax.set_ylim(0, self.ymax)
467 483 if self.mode == 'PPI':
468 484 ax.set_yticks(ax.get_yticks(), labels=ax.get_yticks(), color='white')
469 485 ax.yaxis.labelpad = 28
@@ -4,11 +4,10 import warnings
4 4 import numpy
5 5 from mpl_toolkits.axisartist.grid_finder import FixedLocator, DictFormatter
6 6 from matplotlib.patches import Circle
7 import cartopy.crs as ccrs
8 7 from cartopy.feature import ShapelyFeature
9 8 import cartopy.io.shapereader as shpreader
10 9
11 from schainpy.model.graphics.jroplot_base import Plot, plt
10 from schainpy.model.graphics.jroplot_base import Plot, plt, ccrs
12 11 from schainpy.model.graphics.jroplot_spectra import SpectraPlot, RTIPlot, CoherencePlot, SpectraCutPlot
13 12 from schainpy.utils import log
14 13 from schainpy.model.graphics.plotting_codes import cb_tables
@@ -515,19 +514,15 class PolarMapPlot(Plot):
515 514 self.data.parameters[x], title) for x in self.channels]
516 515
517 516 class WeatherParamsPlot(Plot):
518 #CODE = 'RHI'
519 #plot_name = 'RHI'
517
520 518 plot_type = 'scattermap'
521 519 buffering = False
522 projection = ccrs.PlateCarree()
523 520
524 521 def setup(self):
525 522
526 523 self.ncols = 1
527 524 self.nrows = 1
528 525 self.nplots= 1
529 self.ylabel= 'Height [km]'
530 self.xlabel= 'Distance from radar [km]'
531 526
532 527 if self.channels is not None:
533 528 self.nplots = len(self.channels)
@@ -630,8 +625,6 class WeatherParamsPlot(Plot):
630 625 r = data['r']
631 626 self.titles = []
632 627
633 self.ymax = self.ymax if self.ymax else numpy.nanmax(r)
634 self.ymin = self.ymin if self.ymin else numpy.nanmin(r)
635 628 self.zmax = self.zmax if self.zmax else numpy.nanmax(z)
636 629 self.zmin = self.zmin if self.zmin is not None else numpy.nanmin(z)
637 630
@@ -643,14 +636,43 class WeatherParamsPlot(Plot):
643 636 len_aux = int(data['azi'].shape[0]/4)
644 637 mean = numpy.mean(data['azi'][len_aux:-len_aux])
645 638 x, y = r*numpy.cos(theta), r*numpy.sin(theta)
639 if self.yrange:
640 self.ylabel= 'Height [km]'
641 self.xlabel= 'Distance from radar [km]'
642 self.ymax = self.yrange
643 self.ymin = 0
644 self.xmax = self.xrange if self.xrange else numpy.nanmax(r)
645 self.xmin = -self.xrange if self.xrange else -numpy.nanmax(r)
646 self.setrhilimits = False
647 else:
648 self.ymin = 0
649 self.ymax = numpy.nanmax(r)
650 self.xmin = -numpy.nanmax(r)
651 self.xmax = numpy.nanmax(r)
652
646 653 elif data['mode_op'] == 'PPI':
647 654 r, theta = numpy.meshgrid(r, -numpy.radians(data['azi'])+numpy.pi/2)
648 655 len_aux = int(data['ele'].shape[0]/4)
649 656 mean = numpy.mean(data['ele'][len_aux:-len_aux])
650 657 x, y = r*numpy.cos(theta)*numpy.cos(numpy.radians(mean)), r*numpy.sin(
651 658 theta)*numpy.cos(numpy.radians(mean))
652 x = km2deg(x) + -75.295893
653 y = km2deg(y) + -12.040436
659 x = km2deg(x) + self.longitude
660 y = km2deg(y) + self.latitude
661 if self.xrange:
662 self.ylabel= 'Latitude'
663 self.xlabel= 'Longitude'
664
665 self.xmin = km2deg(-self.xrange) + self.longitude
666 self.xmax = km2deg(self.xrange) + self.longitude
667
668 self.ymin = km2deg(-self.xrange) + self.latitude
669 self.ymax = km2deg(self.xrange) + self.latitude
670 else:
671 self.xmin = km2deg(-numpy.nanmax(r)) + self.longitude
672 self.xmax = km2deg(numpy.nanmax(r)) + self.longitude
673
674 self.ymin = km2deg(-numpy.nanmax(r)) + self.latitude
675 self.ymax = km2deg(numpy.nanmax(r)) + self.latitude
654 676
655 677 self.clear_figures()
656 678
@@ -665,8 +687,6 class WeatherParamsPlot(Plot):
665 687 norm = None
666 688
667 689 for i, ax in enumerate(axes):
668 if data['mode_op'] == 'PPI':
669 ax.set_extent([-75.745893, -74.845893, -12.490436, -11.590436])
670 690
671 691 if norm is None:
672 692 ax.plt = ax.pcolormesh(x, y, z[i], cmap=self.colormap, vmin=self.zmin, vmax=self.zmax)
@@ -690,14 +710,13 class WeatherParamsPlot(Plot):
690 710 self.mode_value = round(mean,1)
691 711
692 712 if data['mode_op'] == 'PPI':
713 if self.map:
693 714 gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True,
694 715 linewidth=1, color='gray', alpha=0.5, linestyle='--')
695 716 gl.xlabel_style = {'size': 8}
696 717 gl.ylabel_style = {'size': 8}
697 718 gl.xlabels_top = False
698 719 gl.ylabels_right = False
699 #self.shapes="/home/soporte/workspace/sirm/volumes/schain/shapes/"
700 #print("self.shapes",self.shapes)
701 720 shape_p = os.path.join(self.shapes,'PER_ADM2/PER_ADM2.shp')
702 721 shape_d = os.path.join(self.shapes,'PER_ADM1/PER_ADM1.shp')
703 722 capitales = os.path.join(self.shapes,'CAPITALES/cap_provincia.shp')
@@ -706,10 +725,10 class WeatherParamsPlot(Plot):
706 725 reader_p = shpreader.BasicReader(shape_d, encoding='latin1')
707 726 reader_c = shpreader.BasicReader(capitales, encoding='latin1')
708 727 reader_v = shpreader.BasicReader(vias, encoding='latin1')
709 caps = [x for x in reader_c.records() if x.attributes["Departa"] in ("JUNIN", "LIMA", "AYACUCHO", "HUANCAVELICA")]
710 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")]
711 provs = [x for x in reader_p.records() if x.attributes["NAME"] in ("Junín", "Lima")]
712 vias = [x for x in reader_v.records() if x.attributes["DEP"] in ("JUNIN", "LIMA")]
728 caps = [x for x in reader_c.records() ]#if x.attributes["Departa"] in ("JUNIN", "LIMA", "ICA", "PIURA")]
729 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")]
730 provs = [x for x in reader_p.records()]# if x.attributes["NAME"] in ("Junín", "Lima")]
731 vias = [x for x in reader_v.records()]# if x.attributes["DEP"] in ("JUNIN", "LIMA")]
713 732
714 733 # Display limits and streets
715 734 shape_feature = ShapelyFeature([x.geometry for x in districts], ccrs.PlateCarree(), facecolor="none", edgecolor='grey', lw=0.5)
@@ -720,17 +739,19 class WeatherParamsPlot(Plot):
720 739 ax.add_feature(shape_feature)
721 740
722 741 for cap in caps:
723 if cap.attributes['Nombre'] in ("LA OROYA", "CONCEPCIÓN", "HUANCAYO", "JAUJA", "CHUPACA", "YAUYOS", "HUANTA", "PAMPAS"):
742 #if cap.attributes['Nombre'] in ("LA OROYA", "CONCEPCIÓN", "HUANCAYO", "JAUJA", "CHUPACA", "YAUYOS", "HUANTA", "PAMPAS"):
724 743 ax.text(cap.attributes['X'], cap.attributes['Y'], cap.attributes['Nombre'].title(), size=7, color='white')
725 ax.text(-75.052003, -11.915552, 'Huaytapallana', size=7, color='cyan')
726 ax.plot(-75.052003, -11.915552, '*')
727
744 #ax.text(-75.052003, -11.915552, 'Huaytapallana', size=7, color='cyan')
745 #ax.plot(-75.052003, -11.915552, '*')
746 else:
747 ax.grid(color='grey', alpha=0.5, linestyle='--', linewidth=1)
728 748 for R in (10, 20, 30 , 40, 50):
729 circle = Circle((-75.295893, -12.040436), km2deg(R), facecolor='none',
749 if R <= self.xrange:
750 circle = Circle((self.longitude, self.latitude), km2deg(R), facecolor='none',
730 751 edgecolor='skyblue', linewidth=1, alpha=0.5)
731 752 ax.add_patch(circle)
732 ax.text(km2deg(R)*numpy.cos(numpy.radians(45))-75.295893,
733 km2deg(R)*numpy.sin(numpy.radians(45))-12.040436,
753 ax.text(km2deg(R)*numpy.cos(numpy.radians(45))+self.longitude,
754 km2deg(R)*numpy.sin(numpy.radians(45))+self.latitude,
734 755 '{}km'.format(R), color='skyblue', size=7)
735 756 elif data['mode_op'] == 'RHI':
736 757 ax.grid(color='grey', alpha=0.5, linestyle='--', linewidth=1)
General Comments 0
You need to be logged in to leave comments. Login now