コード例 #1
0
def map_lakepct(var,
                lon,
                lat,
                levels,
                title_str,
                clrmap,
                fig_name,
                alone=True,
                ax=False):

    # figure creation
    if alone:
        fig, ax = plt.subplots(1,
                               1,
                               figsize=(13, 8),
                               subplot_kw={'projection': ccrs.PlateCarree()})

    ax.add_feature(ctp.feature.OCEAN, color='gainsboro')
    ax.coastlines(color='darkgrey')

    #ax.coastlines(color="grey")

    LON, LAT = mpu.infer_interval_breaks(lon, lat)

    # add the data to the map (more info on colormaps: https://matplotlib.org/users/colormaps.html)
    cmap, norm = mpu.from_levels_and_cmap(levels, clrmap)

    # do not show zeros
    var[var == 0] = np.nan
    cmap.set_over(cmap(0.99))
    h = ax.pcolormesh(LON, LAT, var, cmap=cmap, norm=norm)
    # set the extent of the cartopy geoAxes to "global"
    ax.set_global()
    ax.set_title(title_str, pad=10, loc='right')

    # remove the frame
    ax.outline_patch.set_visible(False)

    # plot the colorbar
    cbar = mpu.colorbar(h, ax, orientation='horizontal', pad=0.1, extend='max')
    cbar.ax.set_xlabel('Natural lake area fraction [%]', size=16)
    cbar.set_ticks(np.arange(0, 110, 10))  # horizontal colorbar
    #cbar.ax.set_xticklabels(['Low', 'Medium', 'High'])  # horizontal colorbar
    # if so, save the figure
    if fig_name != 0 and alone:
        plt.savefig(fig_name + '.jpeg', dpi=1000, bbox_inches='tight')
コード例 #2
0
    def plot_region_hc_map(var, region_props, lakes_path, indir_lakedata):

        # get region specific info from dictionary
        extent = region_props['extent']
        continent_extent = region_props['continent_extent']
        name = region_props['name']
        name_str = region_props['name_str']
        ax_location = region_props['ax_location']
        levels = region_props['levels']
        fig_size = region_props['fig_size']
        cb_orientation = region_props['cb_orientation']

        path_lakes = lakes_path + name + '.shp'

        # settings
        clb_label = 'Joule'
        title_str = name_str + ' heat content anomaly'
        fig_name = 'Heat_content_' + name
        cmap = 'YlOrBr'

        cmap, norm = mpu.from_levels_and_cmap(levels, cmap, extend='max')
        lon, lat = get_lonlat(indir_lakedata)
        LON, LAT = mpu.infer_interval_breaks(lon, lat)
        lakes = gpd.read_file(path_lakes)

        # plotting
        fig, ax = plt.subplots(1,
                               1,
                               figsize=fig_size,
                               subplot_kw={'projection': ccrs.PlateCarree()})

        ax.add_feature(ctp.feature.OCEAN, color='gainsboro')
        ax.coastlines(color="grey")
        # add the data to the map (more info on colormaps: https://matplotlib.org/users/colormaps.html)
        h = ax.pcolormesh(LON, LAT, var, cmap=cmap, norm=norm)
        # load the lake shapefile

        lakes.plot(ax=ax, edgecolor='gray', facecolor='none')

        # set grid lines
        gl = ax.gridlines(crs=ccrs.PlateCarree(),
                          draw_labels=True,
                          linewidth=0.5,
                          color='gainsboro',
                          alpha=0.5)
        gl.xlines = True
        gl.xformatter = LONGITUDE_FORMATTER
        gl.yformatter = LATITUDE_FORMATTER
        gl.xlabels_bottom = None
        gl.ylabels_right = None

        # set extent (in right way)
        extent[1], extent[2] = extent[2], extent[1]
        ax.set_extent(extent)

        # create effect for map borders:
        effect = Stroke(linewidth=1.5, foreground='darkgray')
        # set effect for main ax
        ax.outline_patch.set_path_effects([effect])

        # Create an inset GeoAxes showing the location of the lakes region
        #x0 y0 width height
        sub_ax = fig.add_axes(ax_location, projection=ccrs.PlateCarree())
        sub_ax.set_extent(continent_extent)
        #lakes.plot(ax=sub_ax)

        sub_ax.outline_patch.set_path_effects([effect])
        extent_box = sgeom.box(extent[0], extent[2], extent[1], extent[3])
        sub_ax.add_geometries([extent_box],
                              ccrs.PlateCarree(),
                              facecolor='none',
                              edgecolor='red',
                              linewidth=2)

        # Add the land, coastlines and the extent of the inset axis
        sub_ax.add_feature(cfeature.LAND, edgecolor='gray')
        sub_ax.coastlines(color='gray')
        extent_box = sgeom.box(extent[0], extent[2], extent[1], extent[3])
        sub_ax.add_geometries([extent_box],
                              ccrs.PlateCarree(),
                              facecolor='none',
                              edgecolor='black',
                              linewidth=2)

        # plot the colorbar
        cbar = mpu.colorbar(h,
                            ax,
                            extend='max',
                            orientation=cb_orientation,
                            pad=0.05)
        if cb_orientation == 'vertical':
            cbar.ax.set_ylabel(clb_label, size=16)
        elif cb_orientation == 'horizontal':
            cbar.ax.set_xlabel(clb_label, size=16)

        #ax.set_title(title_str, pad=10)

        plotdir = '/home/inne/documents/phd/data/processed/isimip_lakeheat/plots/'
        plt.savefig(plotdir + fig_name + '.png', dpi=500)
コード例 #3
0
    def plot_global_hc_map(name_str, var, lakes_path, indir_lakedata):

        # get region specific info from dictionary
        if name_str == 'global_absolute':
            levels = np.arange(-1e17, 1.1e17, 0.1e17)
        elif name_str == 'global':
            levels = np.arange(-1e19, 1.1e19, 0.1e19)

        cb_orientation = 'horizontal'
        path_lakes = lakes_path + name_str + '.shp'

        # settings
        clb_label = 'Joule'
        title_str = name_str + ' heat content anomaly'
        fig_name = 'Heat_content_' + name_str
        cmap = 'RdBu_r'  #, 'YlOrBr'

        cmap, norm = mpu.from_levels_and_cmap(levels, cmap, extend='max')
        lon, lat = get_lonlat(indir_lakedata)
        LON, LAT = mpu.infer_interval_breaks(lon, lat)

        # plotting
        fig, ax = plt.subplots(1,
                               1,
                               figsize=(13, 8),
                               subplot_kw={'projection': ccrs.PlateCarree()})

        ax.add_feature(ctp.feature.OCEAN, color='gainsboro')
        ax.coastlines(color="grey")
        # add the data to the map (more info on colormaps: https://matplotlib.org/users/colormaps.html)
        h = ax.pcolormesh(LON, LAT, var, cmap=cmap, norm=norm)

        # set grid lines
        gl = ax.gridlines(crs=ccrs.PlateCarree(),
                          draw_labels=True,
                          linewidth=0.5,
                          color='gainsboro',
                          alpha=0.5)
        gl.xlines = True
        gl.xformatter = LONGITUDE_FORMATTER
        gl.yformatter = LATITUDE_FORMATTER
        gl.xlabels_bottom = None
        gl.ylabels_right = None

        effect = Stroke(linewidth=1.5, foreground='darkgray')
        # set effect for main ax
        ax.outline_patch.set_path_effects([effect])

        # plot the colorbar
        cbar = mpu.colorbar(h,
                            ax,
                            extend='max',
                            orientation=cb_orientation,
                            pad=0.05)
        if cb_orientation == 'vertical':
            cbar.ax.set_ylabel(clb_label, size=16)
        elif cb_orientation == 'horizontal':
            cbar.ax.set_xlabel(clb_label, size=16)

        #ax.set_title(title_str, pad=10)

        plotdir = '/home/inne/documents/phd/data/processed/isimip_lakeheat/plots/'
        plt.savefig(plotdir + fig_name + '.png')