Beispiel #1
0
def main():

    # Use the waves example to provide some sample data, but make it
    # more dependent on y for more interesting contours.
    x, y, z = sample_data((20, 40))
    z = z * -1.5 * y

    # Setup a global EckertIII map with faint coastlines.
    fig = plt.figure()
    ax1 = fig.add_subplot(2, 1, 1, projection=ccrs.EckertIII())
    ax1.set_title("transform_first=False")
    ax2 = fig.add_subplot(2, 1, 2, projection=ccrs.EckertIII())
    ax2.set_title("transform_first=True")

    for ax, transform_first in zip([ax1, ax2], [False, True]):
        ax.set_global()
        ax.coastlines('110m', alpha=0.1)

        # Add colourful filled contours.
        filled_c = ax.contourf(x,
                               y,
                               z,
                               transform=ccrs.PlateCarree(),
                               transform_first=transform_first)

        # And black line contours.
        ax.contour(x,
                   y,
                   z,
                   levels=filled_c.levels,
                   colors=['black'],
                   transform=ccrs.PlateCarree(),
                   transform_first=transform_first)

    plt.show()
Beispiel #2
0
def test_multiple_projections():

    projections = [
        ccrs.PlateCarree(),
        ccrs.Robinson(),
        ccrs.RotatedPole(pole_latitude=45, pole_longitude=180),
        ccrs.OSGB(approx=True),
        ccrs.TransverseMercator(approx=True),
        ccrs.Mercator(globe=ccrs.Globe(semimajor_axis=math.degrees(1)),
                      min_latitude=-85.,
                      max_latitude=85.),
        ccrs.LambertCylindrical(),
        ccrs.Miller(),
        ccrs.Gnomonic(),
        ccrs.Stereographic(),
        ccrs.NorthPolarStereo(),
        ccrs.SouthPolarStereo(),
        ccrs.Orthographic(),
        ccrs.Mollweide(),
        ccrs.InterruptedGoodeHomolosine(emphasis='land'),
        ccrs.EckertI(),
        ccrs.EckertII(),
        ccrs.EckertIII(),
        ccrs.EckertIV(),
        ccrs.EckertV(),
        ccrs.EckertVI(),
    ]

    rows = np.ceil(len(projections) / 5).astype(int)

    fig = plt.figure(figsize=(10, 2 * rows))
    for i, prj in enumerate(projections, 1):
        ax = fig.add_subplot(rows, 5, i, projection=prj)

        ax.set_global()

        ax.coastlines(resolution="110m")

        plt.plot(-0.08, 51.53, 'o', transform=ccrs.PlateCarree())

        plt.plot([-0.08, 132], [51.53, 43.17],
                 color='red',
                 transform=ccrs.PlateCarree())

        plt.plot([-0.08, 132], [51.53, 43.17],
                 color='blue',
                 transform=ccrs.Geodetic())
Beispiel #3
0
def test_contour_label():
    from cartopy.tests.mpl.test_caching import sample_data
    fig = plt.figure()

    # Setup a global EckertIII map with faint coastlines.
    ax = fig.add_subplot(1, 1, 1, projection=ccrs.EckertIII())
    ax.set_global()
    ax.coastlines('110m', alpha=0.1)

    # Use the waves example to provide some sample data, but make it
    # more dependent on y for more interesting contours.
    x, y, z = sample_data((20, 40))
    z = z * -1.5 * y

    # Add colourful filled contours.
    filled_c = ax.contourf(x, y, z, transform=ccrs.PlateCarree())

    # And black line contours.
    line_c = ax.contour(x,
                        y,
                        z,
                        levels=filled_c.levels,
                        colors=['black'],
                        transform=ccrs.PlateCarree())

    # Uncomment to make the line contours invisible.
    # plt.setp(line_c.collections, visible=False)

    # Add a colorbar for the filled contour.
    fig.colorbar(filled_c, orientation='horizontal')

    # Use the line contours to place contour labels.
    ax.clabel(
        line_c,  # Typically best results when labelling line contours.
        colors=['black'],
        manual=False,  # Automatic placement vs manual placement.
        inline=True,  # Cut the line where the label will be placed.
        fmt=' {:.0f} '.format,  # Labes as integers, with some extra space.
    )

    return fig
Beispiel #4
0
def get_map_projection(
        proj_name,
        central_longitude=0.0,
        central_latitude=0.0,
        false_easting=0.0,
        false_northing=0.0,
        globe=None,
        standard_parallels=(20.0, 50.0),
        scale_factor=None,
        min_latitude=-80.0,
        max_latitude=84.0,
        true_scale_latitude=None,
        latitude_true_scale=None,  ### BOTH
        secant_latitudes=None,
        pole_longitude=0.0,
        pole_latitude=90.0,
        central_rotated_longitude=0.0,
        sweep_axis='y',
        satellite_height=35785831,
        cutoff=-30,
        approx=None,
        southern_hemisphere=False,
        zone=15):  #### numeric UTM zone

    proj_name = proj_name.lower()

    if (proj_name == 'albersequalarea'):
        proj = ccrs.AlbersEqualArea(central_longitude=central_longitude,
                                    central_latitude=central_latitude,
                                    false_easting=false_easting,
                                    false_northing=false_northing,
                                    globe=globe,
                                    standard_parallels=standard_parallels)
    elif (proj_name == 'azimuthalequidistant'):
        proj = ccrs.AzimuthalEquidistant(central_longitude=central_longitude,
                                         central_latitude=central_latitude,
                                         false_easting=false_easting,
                                         false_northing=false_northing,
                                         globe=globe)
    elif (proj_name == 'equidistantconic'):
        proj = ccrs.EquidistantConic(central_longitude=central_longitude,
                                     central_latitude=central_latitude,
                                     false_easting=false_easting,
                                     false_northing=false_northing,
                                     globe=globe,
                                     standard_parallels=standard_parallels)
    elif (proj_name == 'lambertconformal'):
        proj = ccrs.LambertConformal(
            central_longitude=-96.0,  ##########
            central_latitude=39.0,  ##########
            false_easting=false_easting,
            false_northing=false_northing,
            globe=globe,
            secant_latitudes=None,
            standard_parallels=None,  ## default: (33,45)
            cutoff=cutoff)
    elif (proj_name == 'lambertcylindrical'):
        proj = ccrs.LambertCylindrical(central_longitude=central_longitude)
    elif (proj_name == 'mercator'):
        proj = ccrs.Mercator(central_longitude=central_longitude,
                             min_latitude=min_latitude,
                             max_latitude=max_latitude,
                             latitude_true_scale=latitude_true_scale,
                             false_easting=false_easting,
                             false_northing=false_northing,
                             globe=globe,
                             scale_factor=None)  #########
    elif (proj_name == 'miller'):
        proj = ccrs.Miller(central_longitude=central_longitude, globe=globe)
    elif (proj_name == 'mollweide'):
        proj = ccrs.Mollweide(central_longitude=central_longitude,
                              false_easting=false_easting,
                              false_northing=false_northing,
                              globe=globe)
    elif (proj_name == 'orthographic'):
        proj = ccrs.Orthographic(central_longitude=central_longitude,
                                 central_latitude=central_latitude,
                                 globe=globe)
    elif (proj_name == 'robinson'):
        proj = ccrs.Robinson(central_longitude=central_longitude,
                             false_easting=false_easting,
                             false_northing=false_northing,
                             globe=globe)
    elif (proj_name == 'sinusoidal'):
        proj = ccrs.Sinusoidal(central_longitude=central_longitude,
                               false_easting=false_easting,
                               false_northing=false_northing,
                               globe=globe)
    elif (proj_name == 'stereographic'):
        proj = ccrs.Stereographic(central_latitude=central_latitude,
                                  central_longitude=central_longitude,
                                  false_easting=false_easting,
                                  false_northing=false_northing,
                                  globe=globe,
                                  true_scale_latitude=true_scale_latitude,
                                  scale_factor=scale_factor)
    elif (proj_name == 'transversemercator'):
        proj = ccrs.TransverseMercator(
            central_longitude=central_longitude,
            central_latitude=central_latitude,
            false_easting=false_easting,
            false_northing=false_northing,
            globe=globe,
            scale_factor=1.0,  ##########
            approx=approx)
    elif (proj_name == 'utm'):
        proj = ccrs.UTM(zone,
                        southern_hemisphere=southern_hemisphere,
                        globe=globe)
    elif (proj_name == 'interruptedgoodehomolosine'):
        proj = ccrs.InterruptedGoodeHomolosine(
            central_longitude=central_longitude, globe=globe)
    elif (proj_name == 'rotatedpole'):
        proj = ccrs.RotatedPole(
            pole_longitude=pole_longitude,
            pole_latitude=pole_latitude,
            globe=globe,
            central_rotated_longitude=central_rotated_longitude)
    elif (proj_name == 'osgb'):
        proj = ccrs.OSGB(approx=approx)
    elif (proj_name == 'europp'):
        proj = ccrs.EuroPP
    elif (proj_name == 'geostationary'):
        proj = ccrs.Geostationary(central_longitude=central_longitude,
                                  satellite_height=satellite_height,
                                  false_easting=false_easting,
                                  false_northing=false_northing,
                                  globe=globe,
                                  sweep_axis=sweep_axis)
    elif (proj_name == 'nearsideperspective'):
        proj = ccrs.NearsidePerspective(central_longitude=central_longitude,
                                        central_latitude=central_latitude,
                                        satellite_height=satellite_height,
                                        false_easting=false_easting,
                                        false_northing=false_northing,
                                        globe=globe)
    elif (proj_name == 'eckerti'):
        proj = ccrs.EckertI(central_longitude=central_longitude,
                            false_easting=false_easting,
                            false_northing=false_northing,
                            globe=globe)
    elif (proj_name == 'eckertii'):
        proj = ccrs.EckertII(central_longitude=central_longitude,
                             false_easting=false_easting,
                             false_northing=false_northing,
                             globe=globe)
    elif (proj_name == 'eckertiii'):
        proj = ccrs.EckertIII(central_longitude=central_longitude,
                              false_easting=false_easting,
                              false_northing=false_northing,
                              globe=globe)
    elif (proj_name == 'eckertiv'):
        proj = ccrs.EckertIV(central_longitude=central_longitude,
                             false_easting=false_easting,
                             false_northing=false_northing,
                             globe=globe)
    elif (proj_name == 'eckertv'):
        proj = ccrs.EckertV(central_longitude=central_longitude,
                            false_easting=false_easting,
                            false_northing=false_northing,
                            globe=globe)
    elif (proj_name == 'eckertvi'):
        proj = ccrs.EckertVI(central_longitude=central_longitude,
                             false_easting=false_easting,
                             false_northing=false_northing,
                             globe=globe)
    elif (proj_name == 'equalearth'):
        proj = ccrs.EqualEarth(central_longitude=central_longitude,
                               false_easting=false_easting,
                               false_northing=false_northing,
                               globe=globe)
    elif (proj_name == 'gnomonic'):
        proj = ccrs.Gnomonic(central_latitude=central_latitude,
                             central_longitude=central_longitude,
                             globe=globe)
    elif (proj_name == 'lambertazimuthalequalarea'):
        proj = ccrs.LambertAzimuthalEqualArea(
            central_longitude=central_longitude,
            central_latitude=central_latitude,
            globe=globe,
            false_easting=false_easting,
            false_northing=false_northing)
    elif (proj_name == 'northpolarstereo'):
        proj = ccrs.NorthPolarStereo(central_longitude=central_longitude,
                                     true_scale_latitude=true_scale_latitude,
                                     globe=globe)
    elif (proj_name == 'osni'):
        proj = ccrs.OSNI(approx=approx)
    elif (proj_name == 'southpolarstereo'):
        proj = ccrs.SouthPolarStereo(central_longitude=central_longitude,
                                     true_scale_latitude=true_scale_latitude,
                                     globe=globe)
    else:
        # This is same as "Geographic coordinates"
        proj = ccrs.PlateCarree(central_longitude=central_longitude,
                                globe=globe)

    return proj
Beispiel #5
0
def plot_pretty(
        v,
        title=None,
        vmin=None,
        vmax=None,
        fig=None,
        ax=None,
        region="global",
        projection=None,
        extent=None,
        ignore_face=[],
        cmap=None,
        pcolormesh_kwargs={},
        colorbar=False,
        colorbar_kwargs={},
        gridlines=True,
        land=True,
        coast_resolution="110m",
        offline=False,
        figsize=(15, 15),
        savefig=None,
        swot_tracks=False,
        **kwargs,
):
    #
    if vmin is None:
        vmin = v.min().values
    if vmax is None:
        vmax = v.max().values
    if "i_g" in v.dims:
        v = v.rename({"i_g": "i"})
    if "j_g" in v.dims:
        v = v.rename({"j_g": "j"})
    #
    MPL_LOCK = threading.Lock()
    with MPL_LOCK:
        if offline:
            plt.switch_backend("agg")
        colmap = _get_cmap(v, cmap)
        #
        if isinstance(region, dict):
            params = region
        else:
            params = regions[region]
        _extent = params["extent"]
        #
        if "face" not in v.dims:
            # v = v.expand_dims("face")
            _faces = [None]
        elif "faces" in params:
            _faces = (face for face in params["faces"]
                      if face not in ignore_face)
        _projection = params["projection"]
        _dticks = params["dticks"]
        #
        if extent is not None:
            _extent = extent
        if projection is not None:
            _projection = projection
        #
        if fig is None and ax is None:
            fig = plt.figure(figsize=figsize)
            ax = fig.add_subplot(111, projection=_projection)
        # coastlines and land:
        # if coast_resolution is not None:
        #    ax.coastlines(resolution=coast_resolution, color='k')
        if land:
            if isinstance(land, dict):
                land_feature = cfeature.NaturalEarthFeature(
                    *land["args"],
                    **land["kwargs"],
                )
                # land = {'args': ['physical', 'land', '10m'],
                #        'kwargs': {edgecolor='face',
                #                   facecolor=cfeature.COLORS['land'],
                #                  }}
            else:
                land_feature = cfeature.LAND
            ax.add_feature(land_feature, zorder=2)
        if _extent == "global":
            # _extent = ax.set_extent()
            _extent = ax.get_extent()
        elif _extent is not None:
            ax.set_extent(_extent)
        if swot_tracks:
            tracks = load_swot_tracks(bbox=_extent)["swath"]
            swot_kwargs = dict(
                facecolor="grey",
                edgecolor="white",
                alpha=0.5,
            )
            if isinstance(swot_tracks, dict):
                swot_kwargs.update(swot_tracks)
        for face in _faces:
            if face is None:
                vplt = v
            else:
                vplt = v.sel(face=face)
            if face in [6, 7, 8, 9]:
                eps = 0.2  # found empirically
                # this deals with dateline crossing areas
                im = vplt.where((vplt.XC > 0)
                                & (vplt.XC < 180.0 - eps)).plot.pcolormesh(
                                    ax=ax,
                                    transform=ccrs.PlateCarree(),
                                    vmin=vmin,
                                    vmax=vmax,
                                    x="XC",
                                    y="YC",
                                    cmap=colmap,
                                    add_colorbar=False,
                                    **pcolormesh_kwargs,
                                )
                im = vplt.where((vplt.XC < 0)
                                & (vplt.XC > -180.0 + eps)).plot.pcolormesh(
                                    ax=ax,
                                    transform=ccrs.PlateCarree(),
                                    vmin=vmin,
                                    vmax=vmax,
                                    x="XC",
                                    y="YC",
                                    cmap=colmap,
                                    add_colorbar=False,
                                    **pcolormesh_kwargs,
                                )
            else:
                im = vplt.plot.pcolormesh(
                    ax=ax,
                    transform=ccrs.PlateCarree(),
                    vmin=vmin,
                    vmax=vmax,
                    x="XC",
                    y="YC",
                    cmap=colmap,
                    add_colorbar=False,
                    **pcolormesh_kwargs,
                )
        if extent == "global":
            ax.set_extent("global")
        if colorbar:
            cbar = fig.colorbar(im, **colorbar_kwargs)
        else:
            cbar = None
        if gridlines and _extent is not None and _projection != ccrs.EckertIII(
        ):
            # grid lines:
            xticks = np.arange(
                _extent[0],
                _extent[1] + _dticks[0],
                _dticks[1] * np.sign(_extent[1] - _extent[0]),
            )
            ax.set_xticks(xticks, crs=ccrs.PlateCarree())
            yticks = np.arange(
                _extent[2],
                _extent[3] + _dticks[1],
                _dticks[1] * np.sign(_extent[3] - _extent[2]),
            )
            ax.set_yticks(yticks, crs=ccrs.PlateCarree())
            gl = ax.grid()
        else:
            gl = ax.gridlines()  # draw_labels=True
        # ax.set_xticks([0, 60, 120, 180, 240, 300, 360], crs=ccrs.PlateCarree())
        # ax.set_yticks([-90, -60, -30, 0, 30, 60, 90], crs=ccrs.PlateCarree())
        # lon_formatter = LongitudeFormatter(zero_direction_label=True)
        # lat_formatter = LatitudeFormatter()
        # ax.xaxis.set_major_formatter(lon_formatter)
        # ax.yaxis.set_major_formatter(lat_formatter)
        # only with platecarre
        # if projection is 'PlateCarre':
        #    gl=ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True, linewidth=2, color='k',
        #                    alpha=0.5, linestyle='--')
        #    gl.xlabels_top = False
        #
        if swot_tracks:
            crs_proj4 = _projection.proj4_init
            ax.add_geometries(
                tracks.to_crs(crs_proj4)["geometry"],
                crs=_projection,
                **swot_kwargs,
            )
        if title is not None:
            ax.set_title(title,
                         fontdict={
                             "fontsize": 20,
                             "fontweight": "bold"
                         })
        #
        if savefig is not None:
            fig.savefig(savefig, dpi=150)
            plt.close(fig)
        #
        # if not offline:
        #    plt.show()
        return {"fig": fig, "ax": ax, "cbar": cbar}
Beispiel #6
0
     "dticks": [10, 10],
     "projection": ccrs.Mollweide(),
 },
 "south-atlantic": {
     "faces": [1, 11, 0, 12],
     "extent": [-50, 20, -60, 5],
     "dticks": [10, 10],
     "projection":
     ccrs.LambertAzimuthalEqualArea(central_longitude=-15.0,
                                    central_latitude=-30),
 },
 "global": {
     "faces": [i for i in range(13) if i != 6],
     "extent": "global",
     "dticks": [10, 10],
     "projection": ccrs.EckertIII(),
 },
 "global_pacific": {
     "faces": [i for i in range(13) if i != 6],
     "extent": "global",
     "dticks": [10, 10],
     "projection": ccrs.EckertIII(central_longitude=-180),
 },
 "marquises-0": {
     "faces": [5, 7, 8, 11],
     "extent": [-140, -130, -20, -10],
     "projection": ccrs.PlateCarree(),
     "dticks": [5, 5],
 },
 "marquises-1": {
     "faces": [
    def projection(self):
        if self.proj is None:
            return ccrs.PlateCarree()

        proj_dict = ast.literal_eval(self.proj)
        user_proj = proj_dict.pop("proj")
        if user_proj == 'PlateCarree':
            self.xylim_supported = True
            return ccrs.PlateCarree(**proj_dict)
        elif user_proj == 'AlbersEqualArea':
            return ccrs.AlbersEqualArea(**proj_dict)
        elif user_proj == 'AzimuthalEquidistant':
            return ccrs.AzimuthalEquidistant(**proj_dict)
        elif user_proj == 'EquidistantConic':
            return ccrs.EquidistantConic(**proj_dict)
        elif user_proj == 'LambertConformal':
            return ccrs.LambertConformal(**proj_dict)
        elif user_proj == 'LambertCylindrical':
            return ccrs.LambertCylindrical(**proj_dict)
        elif user_proj == 'Mercator':
            return ccrs.Mercator(**proj_dict)
        elif user_proj == 'Miller':
            return ccrs.Miller(**proj_dict)
        elif user_proj == 'Mollweide':
            return ccrs.Mollweide(**proj_dict)
        elif user_proj == 'Orthographic':
            return ccrs.Orthographic(**proj_dict)
        elif user_proj == 'Robinson':
            return ccrs.Robinson(**proj_dict)
        elif user_proj == 'Sinusoidal':
            return ccrs.Sinusoidal(**proj_dict)
        elif user_proj == 'Stereographic':
            return ccrs.Stereographic(**proj_dict)
        elif user_proj == 'TransverseMercator':
            return ccrs.TransverseMercator(**proj_dict)
        elif user_proj == 'UTM':
            return ccrs.UTM(**proj_dict)
        elif user_proj == 'InterruptedGoodeHomolosine':
            return ccrs.InterruptedGoodeHomolosine(**proj_dict)
        elif user_proj == 'RotatedPole':
            return ccrs.RotatedPole(**proj_dict)
        elif user_proj == 'OSGB':
            self.xylim_supported = False
            return ccrs.OSGB(**proj_dict)
        elif user_proj == 'EuroPP':
            self.xylim_supported = False
            return ccrs.EuroPP(**proj_dict)
        elif user_proj == 'Geostationary':
            return ccrs.Geostationary(**proj_dict)
        elif user_proj == 'NearsidePerspective':
            return ccrs.NearsidePerspective(**proj_dict)
        elif user_proj == 'EckertI':
            return ccrs.EckertI(**proj_dict)
        elif user_proj == 'EckertII':
            return ccrs.EckertII(**proj_dict)
        elif user_proj == 'EckertIII':
            return ccrs.EckertIII(**proj_dict)
        elif user_proj == 'EckertIV':
            return ccrs.EckertIV(**proj_dict)
        elif user_proj == 'EckertV':
            return ccrs.EckertV(**proj_dict)
        elif user_proj == 'EckertVI':
            return ccrs.EckertVI(**proj_dict)
        elif user_proj == 'EqualEarth':
            return ccrs.EqualEarth(**proj_dict)
        elif user_proj == 'Gnomonic':
            return ccrs.Gnomonic(**proj_dict)
        elif user_proj == 'LambertAzimuthalEqualArea':
            return ccrs.LambertAzimuthalEqualArea(**proj_dict)
        elif user_proj == 'NorthPolarStereo':
            return ccrs.NorthPolarStereo(**proj_dict)
        elif user_proj == 'OSNI':
            return ccrs.OSNI(**proj_dict)
        elif user_proj == 'SouthPolarStereo':
            return ccrs.SouthPolarStereo(**proj_dict)
Beispiel #8
0
def set_proj(projection='Robinson', proj_default=True):
    """ Set the projection for Cartopy.
    
    Parameters
    ----------
    
    projection : string
        the map projection. Available projections:
        'Robinson' (default), 'PlateCarree', 'AlbertsEqualArea',
        'AzimuthalEquidistant','EquidistantConic','LambertConformal',
        'LambertCylindrical','Mercator','Miller','Mollweide','Orthographic',
        'Sinusoidal','Stereographic','TransverseMercator','UTM',
        'InterruptedGoodeHomolosine','RotatedPole','OSGB','EuroPP',
        'Geostationary','NearsidePerspective','EckertI','EckertII',
        'EckertIII','EckertIV','EckertV','EckertVI','EqualEarth','Gnomonic',
        'LambertAzimuthalEqualArea','NorthPolarStereo','OSNI','SouthPolarStereo'
    proj_default : bool
        If True, uses the standard projection attributes from Cartopy.
        Enter new attributes in a dictionary to change them. Lists of attributes
        can be found in the Cartopy documentation: 
            https://scitools.org.uk/cartopy/docs/latest/crs/projections.html#eckertiv
    
    Returns
    -------
        proj : the Cartopy projection object
        
    See Also
    --------
    pyleoclim.utils.mapping.map_all : mapping function making use of the projection
    
    """
    if proj_default is not True and type(proj_default) is not dict:
        raise TypeError(
            'The default for the projections should either be provided' +
            ' as a dictionary or set to True')

    # Set the projection
    if projection == 'Robinson':
        if proj_default is True:
            proj = ccrs.Robinson()
        else:
            proj = ccrs.Robinson(**proj_default)
    elif projection == 'PlateCarree':
        if proj_default is True:
            proj = ccrs.PlateCarree()
        else:
            proj = ccrs.PlateCarree(**proj_default)
    elif projection == 'AlbersEqualArea':
        if proj_default is True:
            proj = ccrs.AlbersEqualArea()
        else:
            proj = ccrs.AlbersEqualArea(**proj_default)
    elif projection == 'AzimuthalEquidistant':
        if proj_default is True:
            proj = ccrs.AzimuthalEquidistant()
        else:
            proj = ccrs.AzimuthalEquidistant(**proj_default)
    elif projection == 'EquidistantConic':
        if proj_default is True:
            proj = ccrs.EquidistantConic()
        else:
            proj = ccrs.EquidistantConic(**proj_default)
    elif projection == 'LambertConformal':
        if proj_default is True:
            proj = ccrs.LambertConformal()
        else:
            proj = ccrs.LambertConformal(**proj_default)
    elif projection == 'LambertCylindrical':
        if proj_default is True:
            proj = ccrs.LambertCylindrical()
        else:
            proj = ccrs.LambertCylindrical(**proj_default)
    elif projection == 'Mercator':
        if proj_default is True:
            proj = ccrs.Mercator()
        else:
            proj = ccrs.Mercator(**proj_default)
    elif projection == 'Miller':
        if proj_default is True:
            proj = ccrs.Miller()
        else:
            proj = ccrs.Miller(**proj_default)
    elif projection == 'Mollweide':
        if proj_default is True:
            proj = ccrs.Mollweide()
        else:
            proj = ccrs.Mollweide(**proj_default)
    elif projection == 'Orthographic':
        if proj_default is True:
            proj = ccrs.Orthographic()
        else:
            proj = ccrs.Orthographic(**proj_default)
    elif projection == 'Sinusoidal':
        if proj_default is True:
            proj = ccrs.Sinusoidal()
        else:
            proj = ccrs.Sinusoidal(**proj_default)
    elif projection == 'Stereographic':
        if proj_default is True:
            proj = ccrs.Stereographic()
        else:
            proj = ccrs.Stereographic(**proj_default)
    elif projection == 'TransverseMercator':
        if proj_default is True:
            proj = ccrs.TransverseMercator()
        else:
            proj = ccrs.TransverseMercator(**proj_default)
    elif projection == 'TransverseMercator':
        if proj_default is True:
            proj = ccrs.TransverseMercator()
        else:
            proj = ccrs.TransverseMercator(**proj_default)
    elif projection == 'UTM':
        if proj_default is True:
            proj = ccrs.UTM()
        else:
            proj = ccrs.UTM(**proj_default)
    elif projection == 'UTM':
        if proj_default is True:
            proj = ccrs.UTM()
        else:
            proj = ccrs.UTM(**proj_default)
    elif projection == 'InterruptedGoodeHomolosine':
        if proj_default is True:
            proj = ccrs.InterruptedGoodeHomolosine()
        else:
            proj = ccrs.InterruptedGoodeHomolosine(**proj_default)
    elif projection == 'RotatedPole':
        if proj_default is True:
            proj = ccrs.RotatedPole()
        else:
            proj = ccrs.RotatedPole(**proj_default)
    elif projection == 'OSGB':
        if proj_default is True:
            proj = ccrs.OSGB()
        else:
            proj = ccrs.OSGB(**proj_default)
    elif projection == 'EuroPP':
        if proj_default is True:
            proj = ccrs.EuroPP()
        else:
            proj = ccrs.EuroPP(**proj_default)
    elif projection == 'Geostationary':
        if proj_default is True:
            proj = ccrs.Geostationary()
        else:
            proj = ccrs.Geostationary(**proj_default)
    elif projection == 'NearsidePerspective':
        if proj_default is True:
            proj = ccrs.NearsidePerspective()
        else:
            proj = ccrs.NearsidePerspective(**proj_default)
    elif projection == 'EckertI':
        if proj_default is True:
            proj = ccrs.EckertI()
        else:
            proj = ccrs.EckertI(**proj_default)
    elif projection == 'EckertII':
        if proj_default is True:
            proj = ccrs.EckertII()
        else:
            proj = ccrs.EckertII(**proj_default)
    elif projection == 'EckertIII':
        if proj_default is True:
            proj = ccrs.EckertIII()
        else:
            proj = ccrs.EckertIII(**proj_default)
    elif projection == 'EckertIV':
        if proj_default is True:
            proj = ccrs.EckertIV()
        else:
            proj = ccrs.EckertIV(**proj_default)
    elif projection == 'EckertV':
        if proj_default is True:
            proj = ccrs.EckertV()
        else:
            proj = ccrs.EckertV(**proj_default)
    elif projection == 'EckertVI':
        if proj_default is True:
            proj = ccrs.EckertVI()
        else:
            proj = ccrs.EckertVI(**proj_default)
    elif projection == 'EqualEarth':
        if proj_default is True:
            proj = ccrs.EqualEarth()
        else:
            proj = ccrs.EqualEarth(**proj_default)
    elif projection == 'Gnomonic':
        if proj_default is True:
            proj = ccrs.Gnomonic()
        else:
            proj = ccrs.Gnomonic(**proj_default)
    elif projection == 'LambertAzimuthalEqualArea':
        if proj_default is True:
            proj = ccrs.LambertAzimuthalEqualArea()
        else:
            proj = ccrs.LambertAzimuthalEqualArea(**proj_default)
    elif projection == 'NorthPolarStereo':
        if proj_default is True:
            proj = ccrs.NorthPolarStereo()
        else:
            proj = ccrs.NorthPolarStereo(**proj_default)
    elif projection == 'OSNI':
        if proj_default is True:
            proj = ccrs.OSNI()
        else:
            proj = ccrs.OSNI(**proj_default)
    elif projection == 'OSNI':
        if proj_default is True:
            proj = ccrs.SouthPolarStereo()
        else:
            proj = ccrs.SouthPolarStereo(**proj_default)
    else:
        raise ValueError('Invalid projection type')

    return proj
Beispiel #9
0
    def to_cartopy_proj(self):
        """
        Creates a `cartopy.crs.Projection` instance from PROJ4 parameters.

        Returns
        -------
        cartopy.crs.projection
            Cartopy projection representing the projection of the spatial reference system.

        """
        proj4_params = self.to_proj4_dict()
        proj4_name = proj4_params.get('proj')
        central_longitude = proj4_params.get('lon_0', 0.)
        central_latitude = proj4_params.get('lat_0', 0.)
        false_easting = proj4_params.get('x_0', 0.)
        false_northing = proj4_params.get('y_0', 0.)
        scale_factor = proj4_params.get('k', 1.)
        standard_parallels = (proj4_params.get('lat_1', 20.),
                              proj4_params.get('lat_2', 50.))

        if proj4_name == 'longlat':
            ccrs_proj = ccrs.PlateCarree(central_longitude)
        elif proj4_name == 'aeqd':
            ccrs_proj = ccrs.AzimuthalEquidistant(central_longitude,
                                                  central_latitude,
                                                  false_easting,
                                                  false_northing)
        elif proj4_name == 'merc':
            ccrs_proj = ccrs.Mercator(central_longitude,
                                      false_easting=false_easting,
                                      false_northing=false_northing,
                                      scale_factor=scale_factor)
        elif proj4_name == 'eck1':
            ccrs_proj = ccrs.EckertI(central_longitude, false_easting,
                                     false_northing)
        elif proj4_name == 'eck2':
            ccrs_proj = ccrs.EckertII(central_longitude, false_easting,
                                      false_northing)
        elif proj4_name == 'eck3':
            ccrs_proj = ccrs.EckertIII(central_longitude, false_easting,
                                       false_northing)
        elif proj4_name == 'eck4':
            ccrs_proj = ccrs.EckertIV(central_longitude, false_easting,
                                      false_northing)
        elif proj4_name == 'eck5':
            ccrs_proj = ccrs.EckertV(central_longitude, false_easting,
                                     false_northing)
        elif proj4_name == 'eck6':
            ccrs_proj = ccrs.EckertVI(central_longitude, false_easting,
                                      false_northing)
        elif proj4_name == 'aea':
            ccrs_proj = ccrs.AlbersEqualArea(central_longitude,
                                             central_latitude, false_easting,
                                             false_northing,
                                             standard_parallels)
        elif proj4_name == 'eqdc':
            ccrs_proj = ccrs.EquidistantConic(central_longitude,
                                              central_latitude, false_easting,
                                              false_northing,
                                              standard_parallels)
        elif proj4_name == 'gnom':
            ccrs_proj = ccrs.Gnomonic(central_longitude, central_latitude)
        elif proj4_name == 'laea':
            ccrs_proj = ccrs.LambertAzimuthalEqualArea(central_longitude,
                                                       central_latitude,
                                                       false_easting,
                                                       false_northing)
        elif proj4_name == 'lcc':
            ccrs_proj = ccrs.LambertConformal(
                central_longitude,
                central_latitude,
                false_easting,
                false_northing,
                standard_parallels=standard_parallels)
        elif proj4_name == 'mill':
            ccrs_proj = ccrs.Miller(central_longitude)
        elif proj4_name == 'moll':
            ccrs_proj = ccrs.Mollweide(central_longitude,
                                       false_easting=false_easting,
                                       false_northing=false_northing)
        elif proj4_name == 'stere':
            ccrs_proj = ccrs.Stereographic(central_latitude,
                                           central_longitude,
                                           false_easting,
                                           false_northing,
                                           scale_factor=scale_factor)
        elif proj4_name == 'ortho':
            ccrs_proj = ccrs.Orthographic(central_longitude, central_latitude)
        elif proj4_name == 'robin':
            ccrs_proj = ccrs.Robinson(central_longitude,
                                      false_easting=false_easting,
                                      false_northing=false_northing)
        elif proj4_name == 'sinus':
            ccrs_proj = ccrs.Sinusoidal(central_longitude, false_easting,
                                        false_northing)
        elif proj4_name == 'tmerc':
            ccrs_proj = ccrs.TransverseMercator(central_longitude,
                                                central_latitude,
                                                false_easting, false_northing,
                                                scale_factor)
        else:
            err_msg = "Projection '{}' is not supported.".format(proj4_name)
            raise ValueError(err_msg)

        return ccrs_proj
Beispiel #10
0
     coord_sys = cs.GeogCS(6371229)
 if (projection == "EckertIII"):
     fig = plt.figure(figsize=(fig_size, 0.5 * fig_size))
     coord_sys = cs.GeogCS(6371229)
 if (projection == "Orthographic"):
     fig = plt.figure(figsize=(fig_size, fig_size))
     ax = plt.axes(projection=ccrs.Orthographic(central_latitude=0,
                                                central_longitude=0))
     coord_sys = cs.GeogCS(6371229)
 if (projection == "Mollweide"):
     fig = plt.figure(figsize=(fig_size, fig_size))
     ax = plt.axes(projection=ccrs.Mollweide())
     coord_sys = cs.GeogCS(6371229)
 if (projection == "EckertIII"):
     fig = plt.figure(figsize=(fig_size, 0.5 * fig_size))
     ax = plt.axes(projection=ccrs.EckertIII())
     coord_sys = cs.GeogCS(6371229)
 if (projection == "Gnomonic"):
     fig = plt.figure(figsize=(fig_size, fig_size))
     proj = ccrs.Gnomonic(central_latitude=desired_lat_deg,
                          central_longitude=desired_lon_deg,
                          globe=None)
     ax = plt.axes(projection=proj)
     ax.set_extent(
         [-width_map / 2, width_map / 2, -height_map / 2, height_map / 2],
         crs=proj)
 if (projection == "Stereographic"):
     fig = plt.figure(figsize=(fig_size, fig_size))
     if scope == "ARCTIC":
         proj = ccrs.NorthPolarStereo()
         ax = plt.axes(projection=proj)
Beispiel #11
0
print(data.head())

shp = shpreader.natural_earth(resolution='10m',category='cultural',name='admin_0_countries')
df = gpd.read_file(shp,encoding='UTF-8')

# Recherche des pays de data qui ne sont pas dans df
for index, row in data.iterrows():
    if row['Pays'].casefold() in (df['NAME_FR'].str.casefold()).tolist():
        pass
    elif str(row['Nom autre']).casefold() in (df['NAME_FR'].str.casefold()).tolist():
        pass
    else:
        print(index, row['Pays'])


fig, ax = plt.subplots(figsize=(18, 12), subplot_kw=dict(projection=ccrs.EckertIII()))
ax.set_position([0.05, 0.05, 0.85, 0.85])

# Conversion latitude/longitude DMS en DD
dms2dd(data)

# Creation de la colormap
col='LatitudeDD'
mn = min(data[col])
mx = max(data[col])
norm = plt.Normalize(vmin=mn, vmax=mx)
cmapName = plt.cm.ScalarMappable(norm=norm, cmap='Blues')


# Boucle sur les pays
for index, row in df.iterrows():
Beispiel #12
0
    'Miller': ccrs.Miller(),
    'Mollweide': ccrs.Mollweide(),
    'Orthographic': ccrs.Orthographic(),
    'Robinson': ccrs.Robinson(),
    'Sinusoidal': ccrs.Sinusoidal(),
    'Stereographic': ccrs.Stereographic(),
    'TransverseMercator': ccrs.TransverseMercator(),
    'InterruptedGoodeHomolosine': ccrs.InterruptedGoodeHomolosine(),
    'RotatedPole': ccrs.RotatedPole(),
    'OSGB': ccrs.OSGB(),
    'EuroPP': ccrs.EuroPP(),
    'Geostationary': ccrs.Geostationary(),
    'NearsidePerspective': ccrs.NearsidePerspective(),
    'EckertI': ccrs.EckertI(),
    'EckertII': ccrs.EckertII(),
    'EckertIII': ccrs.EckertIII(),
    'EckertIV': ccrs.EckertIV(),
    'EckertV': ccrs.EckertV(),
    'EckertVI': ccrs.EckertVI(),
    'Gnomonic': ccrs.Gnomonic(),
    'LambertAzimuthalEqualArea': ccrs.LambertAzimuthalEqualArea(),
    'NorthPolarStereo': ccrs.NorthPolarStereo(),
    'OSNI': ccrs.OSNI(),
    'SouthPolarStereo': ccrs.SouthPolarStereo()
}

for index, projection in enumerate(projections.items()):
    ax = fig.add_subplot(7, 5, index + 1, projection=projection[1])
    ax.coastlines()
    ax.set_title(projection[0])