Esempio n. 1
0
def plot_region(tensor,
                ax,
                lons,
                lats,
                extent,
                crs=ccrs.PlateCarree(),
                **plot_kwargs):
    if 'cmap' not in plot_kwargs:
        plot_kwargs['cmap'] = 'turbo'
    x0, x1, y0, y1 = extent
    im = ax.pcolormesh(lons, lats, tensor, transform=crs, **plot_kwargs)
    ax.set_extent((x0, x1, y0, y1), crs=crs)
    # longitude[longitude>180] = longitude[longitude>180] - 360
    ax.set_xticks(np.linspace(x1, x0, 5), crs=crs)
    ax.set_yticks(np.linspace(y0, y1, 5), crs=crs)
    lat_formatter = LatitudeFormatter()
    lon_formatter = LongitudeFormatter()
    ax.xaxis.set_major_formatter(lon_formatter)
    ax.yaxis.set_major_formatter(lat_formatter)
    ax.tick_params(axis='both', which='major', labelsize=7)
    ax.add_feature(
        GSHHSFeature(scale='intermediate',
                     facecolor='lightgrey',
                     linewidth=0.2))
    return im
Esempio n. 2
0
def multi_plot(surfaces,
               product='mdt',
               extent=None,
               axtitles=None,
               coastlines=False,
               stacked=True):  # , subplot_titles=None):
    crs = ccrs.PlateCarree()
    panel = len(surfaces)
    central_lon = 0
    cbarwidth = 0.02
    y_ticks = 7
    cmap = 'turbo'
    if product == 'mdt':
        vmin = -1.4
        vmax = 1.4
        cticks_no = 15
    elif product == 'cs':
        vmin = 0
        vmax = 2
        cticks_no = 9
    elif product == 'geoid':
        vmin = -100
        vmax = 100
        cmap = 'RdBu_r'
        cticks_no = 9
    elif product == 'err':
        vmin = 0
        vmax = 0.03
        cticks_no = np.linspace(vmin, vmax, num=4)
        dp = '{:.2f}'
        cmap = 'gist_ncar'
    elif product == 'resid':
        vmin = -0.2
        vmax = 0.2
        cticks_no = 9
        dp = '{:.2f}'
    if extent is not None:
        if extent == 'gs':
            x0, x1 = -85, -60
            y0, y1 = 20, 45
            x_ticks = 6
            y_ticks = 6
        elif extent == 'ag':
            x0, x1 = 0, 50
            y0, y1 = -10, -50
            x_ticks = 6
            y_ticks = 6
        elif extent == 'na':
            x0, x1 = -80, -10
            y0, y1 = 20, 70
            x_ticks = 8
            y_ticks = 6
    else:
        x0, x1 = -180, 180
        y0, y1 = -90, 90
        x_ticks = 9
        y_ticks = 7
    if panel == 2:
        if extent is None:
            if stacked:
                nrows, ncols = 2, 1
                figsize = (12, 12.8)
                wspace, hspace = 0.23, 0.13
                bottom, top = 0.09, 0.96
            else:
                cbarwidth = 0.03
                nrows, ncols = 1, 2
                figsize = (19, 5.75)
                wspace, hspace = 0.08, 0.02
                bottom, top = 0.04, 0.98
        else:
            nrows, ncols = 1, 2
            figsize = (12, 8)
            wspace, hspace = 0.2, 0.5
            bottom, top = 0.25, 0.9
    elif panel == 4:
        nrows, ncols = 2, 2
        figsize = 20, 10.5
        wspace, hspace = 0.18, 0.14
        bottom, top = 0.1, 0.98
        if extent is not None:
            figsize = (11, 11)
            if extent == 'ag':
                figsize = (11, 9.1)
    cticks = np.linspace(vmin, vmax, num=cticks_no)
    # Define the figure and each axis for the 3 rows and 3 columns
    fig, axs = plt.subplots(nrows=nrows,
                            ncols=ncols,
                            subplot_kw={'projection': crs},
                            figsize=figsize)
    axs = axs.flatten()

    for i, surface in enumerate(surfaces):
        surface = bound_arr(surface, vmin, vmax)
        lons, lats = create_coords(get_res(surface), central_lon=central_lon)
        cs = axs[i].pcolormesh(lons,
                               lats,
                               surface,
                               transform=crs,
                               cmap=cmap,
                               vmin=vmin,
                               vmax=vmax)
        if axtitles is not None:
            axs[i].set_title(axtitles[i])
        axs[i].set_extent((x0, x1, y0, y1), crs=crs)
        axs[i].set_xticks(np.linspace(x0, x1, x_ticks), crs=crs)
        axs[i].set_yticks(np.linspace(y0, y1, y_ticks), crs=crs)
        lat_formatter = LatitudeFormatter()
        lon_formatter = LongitudeFormatter()
        axs[i].xaxis.set_major_formatter(lon_formatter)
        axs[i].yaxis.set_major_formatter(lat_formatter)
        axs[i].tick_params(axis='both', which='major', labelsize=9)
        # axs[i].tick_params(axis='both', which='minor', labelsize=8)
        if coastlines:
            for ax in axs:
                ax.add_feature(
                    GSHHSFeature(scale='intermediate',
                                 facecolor='lightgrey',
                                 linewidth=0.2))
    # Delete the unwanted axes
    # for i in [7,8]:
    #     fig.delaxes(axs[i])
    fig.subplots_adjust(bottom=bottom,
                        top=top,
                        left=0.05,
                        right=0.95,
                        wspace=wspace,
                        hspace=hspace)
    # cbar_ax = fig.add_axes([0.1, 0.04, 0.8, 0.02])
    cbar_ax = fig.add_axes([0.1, 0.04, 0.8, cbarwidth])
    cbar_ax.tick_params(labelsize=7)
    cbar = fig.colorbar(cs,
                        cax=cbar_ax,
                        ticks=cticks,
                        orientation='horizontal')
    # plt.suptitle('GOCE GTIM5 Geoid')
    plt.show()
Esempio n. 3
0
"""

import argparse

from cartopy import config
from cartopy.feature import Feature, GSHHSFeature, NaturalEarthFeature
from cartopy.io import Downloader

ALL_SCALES = ('110m', '50m', '10m')

FEATURE_DEFN_GROUPS = {
    # Only need one GSHHS resolution because they *all* get downloaded
    # from one file.
    'gshhs':
    GSHHSFeature(scale='f'),
    'physical':
    (('physical', 'coastline', ALL_SCALES), ('physical', 'land', ALL_SCALES),
     ('physical', 'ocean', ALL_SCALES), ('physical', 'rivers_lake_centerlines',
                                         ALL_SCALES), ('physical', 'lakes',
                                                       ALL_SCALES),
     ('physical', 'geography_regions_polys',
      ALL_SCALES), ('physical', 'geography_regions_points', ALL_SCALES),
     ('physical', 'geography_marine_polys',
      ALL_SCALES), ('physical', 'glaciated_areas', ALL_SCALES)),
    'cultural': (
        ('cultural', 'admin_0_countries', ALL_SCALES),
        ('cultural', 'admin_0_countries_lakes', ALL_SCALES),
        ('cultural', 'admin_0_sovereignty', ALL_SCALES),
        ('cultural', 'admin_0_boundary_lines_land', ALL_SCALES),
        ('cultural', 'urban_areas', ('50m', '10m')),
Esempio n. 4
0
import argparse

from cartopy import config
from cartopy.feature import Feature, GSHHSFeature, NaturalEarthFeature
from cartopy.crs import PlateCarree
import matplotlib.pyplot as plt


ALL_SCALES = ('110m', '50m', '10m')


FEATURE_DEFN_GROUPS = {
    # Only need one GSHHS resolution because they *all* get downloaded
    # from one file.
    'gshhs': GSHHSFeature(scale='f'),
    'physical': (
        ('physical', 'coastline', ALL_SCALES),
        ('physical', 'land', ALL_SCALES),
        ('physical', 'ocean', ALL_SCALES),
        ('physical', 'rivers_lake_centerlines', ALL_SCALES),
        ('physical', 'lakes', ALL_SCALES),
        ('physical', 'geography_regions_polys', ALL_SCALES),
        ('physical', 'geography_regions_points', ALL_SCALES),
        ('physical', 'geography_marine_polys', ALL_SCALES),
        ('physical', 'glaciated_areas', ALL_SCALES)
    ),
    'cultural': (
        ('cultural', 'admin_0_countries', ALL_SCALES),
        ('cultural', 'admin_0_countries_lakes', ALL_SCALES),
        ('cultural', 'admin_0_sovereignty', ALL_SCALES),
Esempio n. 5
0
def plot(arr,
         cmap='turbo',
         central_lon=0,
         bds=1.4,
         coastlines=False,
         land_feature=False,
         title=None,
         product='mdt',
         extent=None,
         lats=None,
         lons=None,
         low_bd=None,
         up_bd=None,
         log=False):
    arr = np.flipud(arr)
    if lats is None and lons is None:
        lons, lats = create_coords(get_res(arr), central_lon=central_lon)
    print(len(lons), len(lats))
    crs = ccrs.PlateCarree(central_longitude=central_lon)
    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1, projection=crs)
    dp = '{:.1f}'
    if low_bd is not None and up_bd is not None:
        vmin = low_bd
        vmax = up_bd
        bds = None
        # ticks = np.linspace(vmin, up_bd, num=10)
    else:
        if product == 'mdt':
            vmin = -bds
            vmax = bds
        elif product == 'cs':
            vmin = 0
            vmax = bds
        elif product == 'geoid':
            vmin = -100
            vmax = 100
            cmap = 'RdBu_r'
            ticks = np.linspace(vmin, vmax, num=9)
            coastlines = True
        elif product == 'err':
            vmin = 0.01
            vmax = 0.03
            ticks = np.linspace(vmin, vmax, num=3)
            dp = '{:.2f}'
            cmap = 'gist_ncar'
            # cmap = 'nipy_spectral'
    if log:
        vmin = 0.1
        norm = colors.LogNorm(vmin, vmax)
    else:
        norm = None
    arr = bound_arr(arr, vmin, vmax)
    im = ax.pcolormesh(lons,
                       lats,
                       arr,
                       transform=crs,
                       cmap=cmap,
                       vmin=vmin,
                       vmax=vmax,
                       norm=norm)
    # else:
    #     im = ax.pcolormesh(lons, lats, arr, transform=crs, cmap=cmap,
    #                        vmin=vmin, vmax=vmax)
    if extent is not None:
        if extent == 'gs':
            x0, x1 = -88, -56
            y0, y1 = 16, 48
            x_ticks = 5
            y_ticks = 5
        elif extent == 'ku':
            x0, x1 = 120, 152
            y0, y1 = 16, 48
            x_ticks = 5
            y_ticks = 5
        elif extent == 'ag':
            x0, x1 = 0, 50
            y0, y1 = -10, -50
            x_ticks = 6
            y_ticks = 6
        elif extent == 'na':
            x0, x1 = -80, -10
            y0, y1 = 20, 70
            x_ticks = 8
            y_ticks = 6
        if extent == 'test':
            x0, x1 = 0, 32
            y0, y1 = -32, -64
            x_ticks = 6
            y_ticks = 6
        ax.set_extent((x0, x1, y0, y1), crs=crs)
        ax.set_xticks(np.linspace(x0, x1, x_ticks), crs=crs)
        ax.set_yticks(np.linspace(y0, y1, y_ticks), crs=crs)
    else:
        ax.set_xticks([-180, -135, -90, -45, 0, 45, 90, 135, 180], crs=crs)
        ax.set_yticks([-90, -60, -30, 0, 30, 60, 90], crs=crs)
    lon_formatter = LongitudeFormatter(zero_direction_label=True)
    lat_formatter = LatitudeFormatter()
    ax.xaxis.set_major_formatter(lon_formatter)
    ax.yaxis.set_major_formatter(lat_formatter)
    ax.yaxis.set_ticks_position('both')
    # if land_feature:
    #     ax.add_feature(cfeature.LAND)
    if coastlines:
        ax.add_feature(GSHHSFeature(facecolor='lightgrey', linewidth=0.2))
        # ax.add_feature(GSHHSFeature(scale='intermediate', facecolor='lightgrey', linewidth=0.2))
        # ax.coastlines()
    if product == 'mdt':
        if bds == 1.5:
            ticks = np.linspace(vmin, vmax, num=7)
        elif bds == 1.4:
            ticks = np.linspace(vmin, vmax, num=15)
        elif bds == 1.25:
            ticks = np.linspace(vmin, vmax, num=11)
            dp = '{:.2f}'
        else:
            ticks = np.linspace(vmin, vmax, num=5)
            dp = '{:.2f}'
    elif product == 'cs':
        if bds == 0.5 and product == 'cs':
            ticks = np.linspace(vmin, vmax, num=6)
        elif bds == 1.5 and product == 'cs':
            ticks = np.linspace(vmin, vmax, num=7)
            dp = '{:.2f}'
        else:
            ticks = np.linspace(vmin, vmax, num=6)
    if extent is None:
        labelsize = 11
        ticksize = 14
        fig.set_size_inches((20, 10.25))
        cbar = fig.colorbar(im,
                            ax=ax,
                            fraction=0.01875,
                            pad=0.05,
                            ticks=ticks,
                            aspect=25)  #fraction=0.0235,
        if product == 'mdt' or product == 'err' or product == 'geoid':
            plt.gcf().text(0.889, 0.858, 'm', fontsize=12)
        if product == 'cs':
            plt.gcf().text(0.8865, 0.86, 'm/s', fontsize=12)
            # plt.gcf().text(0.882, 0.858, 'm/s', fontsize=12)
    else:
        labelsize = 8
        ticksize = 9
        if extent == 'gs' or 'ku':
            fig.set_size_inches((8, 7))
            cbar = fig.colorbar(im,
                                ax=ax,
                                fraction=0.041,
                                pad=0.15,
                                ticks=ticks)
            if product == 'mdt':
                plt.gcf().text(0.8855, 0.858, 'm', fontsize=11)
            elif product == 'cs':
                plt.gcf().text(0.869, 0.87, 'm/s', fontsize=11)
        elif extent == 'ag' or extent == 'na':
            fig.set_size_inches((9, 6))
            cbar = fig.colorbar(im,
                                ax=ax,
                                fraction=0.041,
                                pad=0.15,
                                ticks=ticks)
            # if product == 'mdt':
            #     plt.gcf().text(0.8855, 0.858, 'm', fontsize=11)
            # elif product == 'cs':
            #     plt.gcf().text(0.865, 0.89, 'm/s', fontsize=11)
        elif extent is not None:
            cbar = fig.colorbar(im,
                                ax=ax,
                                fraction=0.041,
                                pad=0.15,
                                ticks=ticks)
    cbar.ax.set_yticklabels([dp.format(tick) for tick in ticks])
    cbar.ax.tick_params(axis='y', length=8, width=1, labelsize=10)
    plt.tick_params(length=10, width=1, labelright='True')
    plt.tick_params(axis='x', pad=8)
    plt.tick_params(axis='y', pad=3)
    plt.xticks(fontsize=ticksize)
    plt.yticks(fontsize=ticksize)
    if title is not None:
        plt.title(title, fontsize=21, pad=15)

    plt.show()
    return fig
Esempio n. 6
0
from __future__ import absolute_import, division, print_function

import argparse

from cartopy import config
from cartopy.feature import Feature, GSHHSFeature, NaturalEarthFeature
from cartopy.io import Downloader


ALL_SCALES = ("110m", "50m", "10m")


FEATURE_DEFN_GROUPS = {
    # Only need one GSHHS resolution because they *all* get downloaded
    # from one file.
    "gshhs": GSHHSFeature(scale="f"),
    "physical": (
        ("physical", "coastline", ALL_SCALES),
        ("physical", "land", ALL_SCALES),
        ("physical", "ocean", ALL_SCALES),
        ("physical", "rivers_lake_centerlines", ALL_SCALES),
        ("physical", "lakes", ALL_SCALES),
        ("physical", "geography_regions_polys", ALL_SCALES),
        ("physical", "geography_regions_points", ALL_SCALES),
        ("physical", "geography_marine_polys", ALL_SCALES),
        ("physical", "glaciated_areas", ALL_SCALES),
    ),
    "cultural": (
        ("cultural", "admin_0_countries", ALL_SCALES),
        ("cultural", "admin_0_countries_lakes", ALL_SCALES),
        ("cultural", "admin_0_sovereignty", ALL_SCALES),