##// 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 from mpl_toolkits.axes_grid1 import make_axes_locatable
33 from mpl_toolkits.axes_grid1 import make_axes_locatable
34 from matplotlib.ticker import FuncFormatter, LinearLocator, MultipleLocator
34 from matplotlib.ticker import FuncFormatter, LinearLocator, MultipleLocator
35
35
36 import cartopy.crs as ccrs
37
36 from .plotting_codes import register_cmap
38 from .plotting_codes import register_cmap
37
39
38 from schainpy.model.data.jrodata import PlotterData
40 from schainpy.model.data.jrodata import PlotterData
@@ -218,7 +220,8 class Plot(Operation):
218 self.zlimits = kwargs.get('zlimits', None)
220 self.zlimits = kwargs.get('zlimits', None)
219 self.xmin = kwargs.get('xmin', None)
221 self.xmin = kwargs.get('xmin', None)
220 self.xmax = kwargs.get('xmax', None)
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 self.xscale = kwargs.get('xscale', None)
225 self.xscale = kwargs.get('xscale', None)
223 self.ymin = kwargs.get('ymin', None)
226 self.ymin = kwargs.get('ymin', None)
224 self.ymax = kwargs.get('ymax', None)
227 self.ymax = kwargs.get('ymax', None)
@@ -253,6 +256,9 class Plot(Operation):
253 self.mode = kwargs.get('mode', None)
256 self.mode = kwargs.get('mode', None)
254 self.mask = kwargs.get('mask', False)
257 self.mask = kwargs.get('mask', False)
255 self.shapes = kwargs.get('shapes', './')
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 if self.server:
263 if self.server:
258 if not self.server.startswith('tcp://'):
264 if not self.server.startswith('tcp://'):
@@ -264,6 +270,7 class Plot(Operation):
264
270
265 if isinstance(self.attr_data, str):
271 if isinstance(self.attr_data, str):
266 self.attr_data = [self.attr_data]
272 self.attr_data = [self.attr_data]
273
267
274
268 def __setup_plot(self):
275 def __setup_plot(self):
269 '''
276 '''
@@ -297,8 +304,12 class Plot(Operation):
297 facecolor='w')
304 facecolor='w')
298 self.figures['PPI'].append(fig_p)
305 self.figures['PPI'].append(fig_p)
299 self.figures['RHI'].append(fig_r)
306 self.figures['RHI'].append(fig_r)
300 for n in range(self.nplots):
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 ax_r = fig_r.add_subplot(self.nrows, self.ncols, n+1, polar=self.polar)
313 ax_r = fig_r.add_subplot(self.nrows, self.ncols, n+1, polar=self.polar)
303 ax_p.tick_params(labelsize=8)
314 ax_p.tick_params(labelsize=8)
304 ax_p.firsttime = True
315 ax_p.firsttime = True
@@ -323,7 +334,12 class Plot(Operation):
323 fig = plt.figure(figsize=(self.width, self.height),
334 fig = plt.figure(figsize=(self.width, self.height),
324 edgecolor='k',
335 edgecolor='k',
325 facecolor='w')
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 ax_r = fig.add_subplot(1, 1, 1, polar=self.polar)
343 ax_r = fig.add_subplot(1, 1, 1, polar=self.polar)
328 ax_p.tick_params(labelsize=8)
344 ax_p.tick_params(labelsize=8)
329 ax_p.firsttime = True
345 ax_p.firsttime = True
@@ -399,7 +415,7 class Plot(Operation):
399 if ax.firsttime:
415 if ax.firsttime:
400 if self.xaxis != 'time':
416 if self.xaxis != 'time':
401 xmin = self.xmin
417 xmin = self.xmin
402 xmax = self.xmax
418 xmax = self.xmax
403 else:
419 else:
404 xmin = self.tmin
420 xmin = self.tmin
405 xmax = self.tmin + self.xrange*60*60
421 xmax = self.tmin + self.xrange*60*60
@@ -442,9 +458,10 class Plot(Operation):
442 ax.cbar.set_label(self.cb_labels[n], size=8)
458 ax.cbar.set_label(self.cb_labels[n], size=8)
443 else:
459 else:
444 ax.cbar = None
460 ax.cbar = None
445 if self.mode == 'RHI':
461 #if self.mode == 'RHI':
446 ax.set_xlim(xmin, xmax)
462 ax.set_xlim(xmin, xmax)
447 ax.set_ylim(ymin, ymax)
463 ax.set_ylim(ymin, ymax)
464
448 ax.firsttime = False
465 ax.firsttime = False
449 if self.grid:
466 if self.grid:
450 ax.grid(True)
467 ax.grid(True)
@@ -463,7 +480,6 class Plot(Operation):
463 '%Y-%m-%d %H:%M:%S'),
480 '%Y-%m-%d %H:%M:%S'),
464 self.time_label),
481 self.time_label),
465 size=8)
482 size=8)
466 ax.set_ylim(0, self.ymax)
467 if self.mode == 'PPI':
483 if self.mode == 'PPI':
468 ax.set_yticks(ax.get_yticks(), labels=ax.get_yticks(), color='white')
484 ax.set_yticks(ax.get_yticks(), labels=ax.get_yticks(), color='white')
469 ax.yaxis.labelpad = 28
485 ax.yaxis.labelpad = 28
@@ -4,11 +4,10 import warnings
4 import numpy
4 import numpy
5 from mpl_toolkits.axisartist.grid_finder import FixedLocator, DictFormatter
5 from mpl_toolkits.axisartist.grid_finder import FixedLocator, DictFormatter
6 from matplotlib.patches import Circle
6 from matplotlib.patches import Circle
7 import cartopy.crs as ccrs
8 from cartopy.feature import ShapelyFeature
7 from cartopy.feature import ShapelyFeature
9 import cartopy.io.shapereader as shpreader
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 from schainpy.model.graphics.jroplot_spectra import SpectraPlot, RTIPlot, CoherencePlot, SpectraCutPlot
11 from schainpy.model.graphics.jroplot_spectra import SpectraPlot, RTIPlot, CoherencePlot, SpectraCutPlot
13 from schainpy.utils import log
12 from schainpy.utils import log
14 from schainpy.model.graphics.plotting_codes import cb_tables
13 from schainpy.model.graphics.plotting_codes import cb_tables
@@ -515,19 +514,15 class PolarMapPlot(Plot):
515 self.data.parameters[x], title) for x in self.channels]
514 self.data.parameters[x], title) for x in self.channels]
516
515
517 class WeatherParamsPlot(Plot):
516 class WeatherParamsPlot(Plot):
518 #CODE = 'RHI'
517
519 #plot_name = 'RHI'
520 plot_type = 'scattermap'
518 plot_type = 'scattermap'
521 buffering = False
519 buffering = False
522 projection = ccrs.PlateCarree()
523
520
524 def setup(self):
521 def setup(self):
525
522
526 self.ncols = 1
523 self.ncols = 1
527 self.nrows = 1
524 self.nrows = 1
528 self.nplots= 1
525 self.nplots= 1
529 self.ylabel= 'Height [km]'
530 self.xlabel= 'Distance from radar [km]'
531
526
532 if self.channels is not None:
527 if self.channels is not None:
533 self.nplots = len(self.channels)
528 self.nplots = len(self.channels)
@@ -629,9 +624,7 class WeatherParamsPlot(Plot):
629 z = data['data']
624 z = data['data']
630 r = data['r']
625 r = data['r']
631 self.titles = []
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 self.zmax = self.zmax if self.zmax else numpy.nanmax(z)
628 self.zmax = self.zmax if self.zmax else numpy.nanmax(z)
636 self.zmin = self.zmin if self.zmin is not None else numpy.nanmin(z)
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 len_aux = int(data['azi'].shape[0]/4)
636 len_aux = int(data['azi'].shape[0]/4)
644 mean = numpy.mean(data['azi'][len_aux:-len_aux])
637 mean = numpy.mean(data['azi'][len_aux:-len_aux])
645 x, y = r*numpy.cos(theta), r*numpy.sin(theta)
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 elif data['mode_op'] == 'PPI':
653 elif data['mode_op'] == 'PPI':
647 r, theta = numpy.meshgrid(r, -numpy.radians(data['azi'])+numpy.pi/2)
654 r, theta = numpy.meshgrid(r, -numpy.radians(data['azi'])+numpy.pi/2)
648 len_aux = int(data['ele'].shape[0]/4)
655 len_aux = int(data['ele'].shape[0]/4)
649 mean = numpy.mean(data['ele'][len_aux:-len_aux])
656 mean = numpy.mean(data['ele'][len_aux:-len_aux])
650 x, y = r*numpy.cos(theta)*numpy.cos(numpy.radians(mean)), r*numpy.sin(
657 x, y = r*numpy.cos(theta)*numpy.cos(numpy.radians(mean)), r*numpy.sin(
651 theta)*numpy.cos(numpy.radians(mean))
658 theta)*numpy.cos(numpy.radians(mean))
652 x = km2deg(x) + -75.295893
659 x = km2deg(x) + self.longitude
653 y = km2deg(y) + -12.040436
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 self.clear_figures()
677 self.clear_figures()
656
678
@@ -664,9 +686,7 class WeatherParamsPlot(Plot):
664 else:
686 else:
665 norm = None
687 norm = None
666
688
667 for i, ax in enumerate(axes):
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 if norm is None:
691 if norm is None:
672 ax.plt = ax.pcolormesh(x, y, z[i], cmap=self.colormap, vmin=self.zmin, vmax=self.zmax)
692 ax.plt = ax.pcolormesh(x, y, z[i], cmap=self.colormap, vmin=self.zmin, vmax=self.zmax)
@@ -690,47 +710,48 class WeatherParamsPlot(Plot):
690 self.mode_value = round(mean,1)
710 self.mode_value = round(mean,1)
691
711
692 if data['mode_op'] == 'PPI':
712 if data['mode_op'] == 'PPI':
693 gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True,
713 if self.map:
694 linewidth=1, color='gray', alpha=0.5, linestyle='--')
714 gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True,
695 gl.xlabel_style = {'size': 8}
715 linewidth=1, color='gray', alpha=0.5, linestyle='--')
696 gl.ylabel_style = {'size': 8}
716 gl.xlabel_style = {'size': 8}
697 gl.xlabels_top = False
717 gl.ylabel_style = {'size': 8}
698 gl.ylabels_right = False
718 gl.xlabels_top = False
699 #self.shapes="/home/soporte/workspace/sirm/volumes/schain/shapes/"
719 gl.ylabels_right = False
700 #print("self.shapes",self.shapes)
720 shape_p = os.path.join(self.shapes,'PER_ADM2/PER_ADM2.shp')
701 shape_p = os.path.join(self.shapes,'PER_ADM2/PER_ADM2.shp')
721 shape_d = os.path.join(self.shapes,'PER_ADM1/PER_ADM1.shp')
702 shape_d = os.path.join(self.shapes,'PER_ADM1/PER_ADM1.shp')
722 capitales = os.path.join(self.shapes,'CAPITALES/cap_provincia.shp')
703 capitales = os.path.join(self.shapes,'CAPITALES/cap_provincia.shp')
723 vias = os.path.join(self.shapes,'Carreteras/VIAS_NACIONAL_250000.shp')
704 vias = os.path.join(self.shapes,'Carreteras/VIAS_NACIONAL_250000.shp')
724 reader_d = shpreader.BasicReader(shape_p, encoding='latin1')
705 reader_d = shpreader.BasicReader(shape_p, encoding='latin1')
725 reader_p = shpreader.BasicReader(shape_d, encoding='latin1')
706 reader_p = shpreader.BasicReader(shape_d, encoding='latin1')
726 reader_c = shpreader.BasicReader(capitales, encoding='latin1')
707 reader_c = shpreader.BasicReader(capitales, encoding='latin1')
727 reader_v = shpreader.BasicReader(vias, encoding='latin1')
708 reader_v = shpreader.BasicReader(vias, encoding='latin1')
728 caps = [x for x in reader_c.records() ]#if x.attributes["Departa"] in ("JUNIN", "LIMA", "ICA", "PIURA")]
709 caps = [x for x in reader_c.records() if x.attributes["Departa"] in ("JUNIN", "LIMA", "AYACUCHO", "HUANCAVELICA")]
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")]
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")]
730 provs = [x for x in reader_p.records()]# if x.attributes["NAME"] in ("Junín", "Lima")]
711 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")]
712 vias = [x for x in reader_v.records() if x.attributes["DEP"] in ("JUNIN", "LIMA")]
732
713
733 # Display limits and streets
714 # Display limits and streets
734 shape_feature = ShapelyFeature([x.geometry for x in districts], ccrs.PlateCarree(), facecolor="none", edgecolor='grey', lw=0.5)
715 shape_feature = ShapelyFeature([x.geometry for x in districts], ccrs.PlateCarree(), facecolor="none", edgecolor='grey', lw=0.5)
735 ax.add_feature(shape_feature)
716 ax.add_feature(shape_feature)
736 shape_feature = ShapelyFeature([x.geometry for x in provs], ccrs.PlateCarree(), facecolor="none", edgecolor='white', lw=1)
717 shape_feature = ShapelyFeature([x.geometry for x in provs], ccrs.PlateCarree(), facecolor="none", edgecolor='white', lw=1)
737 ax.add_feature(shape_feature)
718 ax.add_feature(shape_feature)
738 shape_feature = ShapelyFeature([x.geometry for x in vias], ccrs.PlateCarree(), facecolor="none", edgecolor='yellow', lw=1)
719 shape_feature = ShapelyFeature([x.geometry for x in vias], ccrs.PlateCarree(), facecolor="none", edgecolor='yellow', lw=1)
739 ax.add_feature(shape_feature)
720 ax.add_feature(shape_feature)
740
721
741 for cap in caps:
722 for cap in caps:
742 #if cap.attributes['Nombre'] in ("LA OROYA", "CONCEPCIÓN", "HUANCAYO", "JAUJA", "CHUPACA", "YAUYOS", "HUANTA", "PAMPAS"):
723 if cap.attributes['Nombre'] in ("LA OROYA", "CONCEPCIÓN", "HUANCAYO", "JAUJA", "CHUPACA", "YAUYOS", "HUANTA", "PAMPAS"):
724 ax.text(cap.attributes['X'], cap.attributes['Y'], cap.attributes['Nombre'].title(), size=7, color='white')
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')
744 #ax.text(-75.052003, -11.915552, 'Huaytapallana', size=7, color='cyan')
726 ax.plot(-75.052003, -11.915552, '*')
745 #ax.plot(-75.052003, -11.915552, '*')
727
746 else:
747 ax.grid(color='grey', alpha=0.5, linestyle='--', linewidth=1)
728 for R in (10, 20, 30 , 40, 50):
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:
730 edgecolor='skyblue', linewidth=1, alpha=0.5)
750 circle = Circle((self.longitude, self.latitude), km2deg(R), facecolor='none',
731 ax.add_patch(circle)
751 edgecolor='skyblue', linewidth=1, alpha=0.5)
732 ax.text(km2deg(R)*numpy.cos(numpy.radians(45))-75.295893,
752 ax.add_patch(circle)
733 km2deg(R)*numpy.sin(numpy.radians(45))-12.040436,
753 ax.text(km2deg(R)*numpy.cos(numpy.radians(45))+self.longitude,
734 '{}km'.format(R), color='skyblue', size=7)
754 km2deg(R)*numpy.sin(numpy.radians(45))+self.latitude,
755 '{}km'.format(R), color='skyblue', size=7)
735 elif data['mode_op'] == 'RHI':
756 elif data['mode_op'] == 'RHI':
736 ax.grid(color='grey', alpha=0.5, linestyle='--', linewidth=1)
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