diff --git a/mlair/data_handler/data_handler_wrf_chem.py b/mlair/data_handler/data_handler_wrf_chem.py index 03346a5c383a308adef71aa9bd24f23a314d62da..57c8d67825947ee27fbebc4393e369f2e6a092e3 100644 --- a/mlair/data_handler/data_handler_wrf_chem.py +++ b/mlair/data_handler/data_handler_wrf_chem.py @@ -393,6 +393,8 @@ if __name__ == '__main__': def plot_map_proj(data, xlim=None, ylim=None, filename=None, point=None, radius=None, **kwargs): cmap = kwargs.pop('cmap', plt.cm.Reds) set_background = kwargs.pop('set_background', False) + edgecolors = kwargs.pop('edgecolors', 'face') + circle = kwargs.pop('circle', False) crs_latlon = ccrs.PlateCarree() if ylim is None: @@ -408,17 +410,19 @@ if __name__ == '__main__': ax = plt.axes(projection=ccrs.PlateCarree()) ax.set_global() pm = data.squeeze().plot.pcolormesh(ax=ax, transform=ccrs.PlateCarree(), x='XLONG', y='XLAT', - cmap=cmap, edgecolors=None, + cmap=cmap, edgecolors=edgecolors, **kwargs) ax.coastlines(resolution='50m') + ##### Idea to draw circle from https://stackoverflow.com/a/58735566 #### own try: - circle_points = Geodesic().circle(lon=lon, lat=lat, - radius=radius*1000., # radius_in_meters, - ) - geom = shapely.geometry.Polygon(circle_points) - ax.add_geometries((geom,), crs=ccrs.PlateCarree(), facecolor='none', edgecolor='blue', linewidth=1) + if circle: + circle_points = Geodesic().circle(lon=lon, lat=lat, + radius=radius*1000., # radius_in_meters, + ) + geom = shapely.geometry.Polygon(circle_points) + ax.add_geometries((geom,), crs=ccrs.PlateCarree(), facecolor='none', edgecolor='blue', linewidth=1) # ##### @@ -427,8 +431,8 @@ if __name__ == '__main__': plt.plot(lon, lat, '+k', markersize=7, transform=crs_latlon) if set_background: ax.stock_img() - plt.tight_layout() - plt.savefig(filename) + # plt.tight_layout() + plt.savefig(filename, bbox_inches='tight') plt.close('all') @@ -528,47 +532,59 @@ if __name__ == '__main__': # dummy_plot(geo_info.bearing.where(dist_xr <= radius_from_point), True, [2, 15], [45, 58]) - for i, (data, xlim, ylim, kwargs) in enumerate(((wrf_new._data.T2.isel({'XTIME': 0}), [-42, 66], [23, 80], {}), - (wrf_new.geo_infos.dist, [-42, 66], [23, 80], {}), - (wrf_new.geo_infos.bearing, [-42, 66], [23, 80], {}), + for i, (data, xlim, ylim, kwargs) in enumerate(((wrf_new._data.T2.isel({'XTIME': 0}), [-42, 66], [23, 80], + {'circle': True, 'cbar_kwargs': {'orientation': 'horizontal', 'pad': 0.01}}), + (wrf_new._data.o3.isel({'XTIME': 0, 'bottom_top': 0}), + [-42, 66], [23, 80], {'circle': True, 'cbar_kwargs': {'orientation': 'horizontal', 'pad': 0.01}}), + (wrf_new.geo_infos.dist, [-42, 66], [23, 80], + {'cmap': plt.cm.get_cmap('Greys'), 'circle': True, 'cbar_kwargs': {'orientation': 'horizontal', 'pad': 0.01}}), + (wrf_new.geo_infos.bearing, [-42, 66], [23, 80], + {'cmap': plt.cm.get_cmap('twilight'), 'circle': True, 'cbar_kwargs': {'orientation': 'horizontal', 'pad': 0.01}}), (wrf_new.geo_infos.wind_sectors, [-42, 66], [23, 80], { - 'cmap': plt.cm.get_cmap('tab20'), - 'set_background': True, - } - ), + 'cmap': plt.cm.get_cmap('tab20',16), + 'circle': True, + 'cbar_kwargs': {'orientation': 'horizontal', 'pad': 0.01} + #'set_background': True, + # 'levels': 16, + }), (wrf_new._data.T2.isel({'XTIME': 0}).where( windsect.is_in_sector('N', wrf_new.geo_infos['bearing'])), - [-42, 66], [23, 80], {}), + [-42, 66], [23, 80], {'circle': False, 'cbar_kwargs': {'orientation': 'horizontal', 'pad': 0.01}}), (wrf_new._data.T2.isel({'XTIME': 0}).where( wrf_new.geo_infos.dist.sel({'points': 0}).drop('points') <= radius_from_point), [2, 15], - [45, 58], {}), + [45, 58], {'circle': False, 'cbar_kwargs': {'orientation': 'horizontal', 'pad': 0.01}}), (geo_info.dist.where( wrf_new.geo_infos.dist.sel({'points': 0}).drop('points') <= radius_from_point), [2, 15], - [45, 58], {}), + [45, 58], {'circle': False, 'cbar_kwargs': {'orientation': 'horizontal', 'pad': 0.01}}), (wrf_new.geo_infos.bearing.where( dist_xr.sel({'points': 0}).drop('points') <= radius_from_point), [2, 15], - [45, 58], {}), + [45, 58], {'circle': False, 'cbar_kwargs': {'orientation': 'horizontal', 'pad': 0.01}}), (wrf_new.geo_infos.wind_sectors.where( dist_xr.sel({'points': 0}).drop('points') <= radius_from_point), [2, 15], [45, 58], {'cmap': plt.cm.get_cmap('tab20', 16), - 'set_background': True, + 'circle': False, + 'cbar_kwargs': {'orientation': 'horizontal', + 'shrink': .6, 'pad': 0.01} + #'set_background': True, }), (wrf_new.geo_infos.dist.where( wrf_new.geo_infos.dist.sel({'points': 0}).drop('points') <= radius_from_point).where( windsect.is_in_sector('N', wrf_new.geo_infos['bearing'])), [2, 15], - [45, 58], {}), + [45, 58], {'circle': False, 'cbar_kwargs': {'orientation': 'horizontal', + 'fraction':.1, 'pad': 0.01}}), )): plot_map_proj(data, xlim=xlim, ylim=ylim, # point=[lat_np, lon_np], point=[wrf_new.get_nearest_coords()['lat'][0], wrf_new.get_nearest_coords()['lon'][0]], - filename=f'Example_dist{i}.pdf', + filename=f'EEExample_dist{i}.png', radius=radius_from_point, + # cbar_kwargs={'orientation': 'horizontal'}, **kwargs, )