Beispiel #1
0
def test_igh_ocean():
    crs = ccrs.InterruptedGoodeHomolosine(central_longitude=-160,
                                          emphasis="ocean")
    ax = plt.axes(projection=crs)
    ax.coastlines()
    ax.gridlines()
    return ax.figure
Beispiel #2
0
def main():
    ax = plt.axes(projection=ccrs.InterruptedGoodeHomolosine())
    ax.coastlines()

    ax.add_wms(wms='http://vmap0.tiles.osgeo.org/wms/vmap0', layers=['basic'])

    plt.show()
Beispiel #3
0
def main():
    fig = plt.figure(figsize=(10, 5))
    ax = fig.add_subplot(1, 1, 1, projection=ccrs.InterruptedGoodeHomolosine())
    ax.coastlines()

    ax.add_wms(wms='http://vmap0.tiles.osgeo.org/wms/vmap0', layers=['basic'])

    plt.show()
Beispiel #4
0
def igh_plot():
    import matplotlib.pyplot as plt
    import cartopy.crs as ccrs

    fig = plt.figure(figsize=(6.9228, 6))

    ax1 = fig.add_subplot(2, 1, 1,
                          projection=ccrs.InterruptedGoodeHomolosine(
                              emphasis='land'))
    ax1.coastlines(resolution='110m')
    ax1.gridlines()

    ax2 = fig.add_subplot(2, 1, 2,
                          projection=ccrs.InterruptedGoodeHomolosine(
                              central_longitude=-160, emphasis='ocean'))
    ax2.coastlines(resolution='110m')
    ax2.gridlines()
def test_eccentric_globe():
    globe = ccrs.Globe(semimajor_axis=1000, semiminor_axis=500, ellipse=None)
    igh = ccrs.InterruptedGoodeHomolosine(globe=globe)
    other_args = {'a=1000', 'b=500', 'lon_0=0'}
    check_proj4_params(igh, other_args)

    assert_almost_equal(np.array(igh.x_limits), [-3141.5926536, 3141.5926536])
    assert_almost_equal(np.array(igh.y_limits), [-1361.410035, 1361.410035])
Beispiel #6
0
def test_default():
    igh = ccrs.InterruptedGoodeHomolosine()
    other_args = {'ellps=WGS84', 'lon_0=0'}
    check_proj_params('igh', igh, other_args)

    assert_almost_equal(np.array(igh.x_limits),
                        [-20037508.3427892, 20037508.3427892])
    assert_almost_equal(np.array(igh.y_limits),
                        [-8683259.7164347, 8683259.7164347])
Beispiel #7
0
def test_central_longitude(lon):
    igh = ccrs.InterruptedGoodeHomolosine(central_longitude=lon)
    other_args = {'ellps=WGS84', 'lon_0={}'.format(lon)}
    check_proj_params('igh', igh, other_args)

    assert_almost_equal(np.array(igh.x_limits),
                        [-20037508.3427892, 20037508.3427892],
                        decimal=5)
    assert_almost_equal(np.array(igh.y_limits),
                        [-8683259.7164347, 8683259.7164347])
def test_eccentric_globe(emphasis):
    globe = ccrs.Globe(semimajor_axis=1000, semiminor_axis=500, ellipse=None)
    igh = ccrs.InterruptedGoodeHomolosine(globe=globe, emphasis=emphasis)
    other_args = {"a=1000", "b=500", "lon_0=0"}
    if emphasis == "land":
        check_proj_params("igh", igh, other_args)
    elif emphasis == "ocean":
        check_proj_params("igh_o", igh, other_args)

    assert_almost_equal(np.array(igh.x_limits), [-3141.5926536, 3141.5926536])
    assert_almost_equal(np.array(igh.y_limits), [-1361.410035, 1361.410035])
Beispiel #9
0
def test_pcolormesh_goode_wrap():
    # global data on an Interrupted Goode Homolosine projection
    # shouldn't spill outside projection boundary
    x = np.linspace(0, 360, 73)
    y = np.linspace(-87.5, 87.5, 36)
    X, Y = np.meshgrid(*[np.deg2rad(c) for c in (x, y)])
    Z = np.cos(Y) + 0.375 * np.sin(2. * X)
    Z = Z[:-1, :-1]
    ax = plt.axes(projection=ccrs.InterruptedGoodeHomolosine())
    ax.coastlines()
    ax.pcolormesh(x, y, Z, transform=ccrs.PlateCarree())
def test_default(emphasis):
    if emphasis == "ocean" and ccrs.PROJ4_VERSION < (7, 1, 0):
        pytest.skip()
    igh = ccrs.InterruptedGoodeHomolosine(emphasis=emphasis)
    other_args = {"ellps=WGS84", "lon_0=0"}
    if emphasis == "land":
        check_proj_params("igh", igh, other_args)
    elif emphasis == "ocean":
        check_proj_params("igh_o", igh, other_args)
    assert_almost_equal(np.array(igh.x_limits),
                        [-20037508.3427892, 20037508.3427892])
    assert_almost_equal(np.array(igh.y_limits),
                        [-8683259.7164347, 8683259.7164347])
Beispiel #11
0
def test_pcolormesh_goode_wrap():
    # global data on an Interrupted Goode Homolosine projection
    # shouldn't spill outside projection boundary
    x = np.linspace(0, 360, 73)
    y = np.linspace(-87.5, 87.5, 36)
    X, Y = np.meshgrid(*[np.deg2rad(c) for c in (x, y)])
    Z = np.cos(Y) + 0.375 * np.sin(2. * X)
    Z = Z[:-1, :-1]
    ax = plt.axes(projection=ccrs.InterruptedGoodeHomolosine(emphasis='land'))
    ax.coastlines()
    # TODO: Remove snap when updating this image
    ax.pcolormesh(x, y, Z, transform=ccrs.PlateCarree(), snap=False)
    return ax.figure
Beispiel #12
0
def main():

    rotated_crs = ccrs.RotatedPole(pole_longitude=120.0, pole_latitude=70.0)
    ax0 = plt.axes(projection=rotated_crs)
    ax0.set_extent([-6, 1, 47.5, 51.5], crs=ccrs.PlateCarree())
    ax0.add_feature(cfeature.LAND.with_scale('110m'))
    ax0.gridlines(draw_labels=True, dms=True, x_inline=False, y_inline=False)

    plt.figure(figsize=(6.9228, 3))
    ax1 = plt.axes(projection=ccrs.InterruptedGoodeHomolosine())
    ax1.coastlines(resolution='110m')
    ax1.gridlines(draw_labels=True)

    plt.show()
Beispiel #13
0
def main():

    rotated_crs = ccrs.RotatedPole(pole_longitude=120.0, pole_latitude=70.0)
    ax0 = plt.axes(projection=rotated_crs)
    ax0.set_extent([-6, 1, 47.5, 51.5], crs=ccrs.PlateCarree())
    ax0.add_feature(cfeature.LAND.with_scale('110m'))
    ax0.gridlines(draw_labels=True, dms=True, x_inline=False, y_inline=False)

    plt.figure(figsize=(6.9228, 3))
    ax1 = plt.axes(projection=ccrs.InterruptedGoodeHomolosine())
    ax1.coastlines(resolution='110m')
    ax1.gridlines(draw_labels=True)

    plt.figure(figsize=(7, 3))
    ax2 = plt.axes(projection=ccrs.PlateCarree())
    ax2.coastlines(resolution='110m')
    gl = ax2.gridlines(draw_labels=True)
    gl.top_labels = False
    gl.right_labels = False
    plt.show()

    plt.figure(figsize=(7, 3))
    ax3 = plt.axes(projection=ccrs.PlateCarree())
    ax3.set_extent([-65, -40, -15, 10])

    # Create a feature for States/Admin 1 regions at 1:50m from Natural Earth
    states_provinces = cfeature.NaturalEarthFeature(
        category='cultural',
        name='admin_1_states_provinces_lines',
        scale='50m',
        facecolor='none')
    ax3.add_feature(states_provinces, edgecolor='gray')

    ax3.coastlines(resolution='110m')
    ax3.coastlines(resolution='110m')
    gl = ax3.gridlines(draw_labels=True)

    gl.change_gridline_tick_decimal_separator('{0:.3f}',
                                              axis='both')

    gl.set_latitude_hemisphere_str('Norte', 'Sul')

    gl.set_longitude_hemisphere_str('O', 'L')

    gl.top_labels = False
    gl.right_labels = False
    plt.show()

    return plt.gcf().get_axes(), gl
def test_multiple_projections():

    projections = [
        ccrs.PlateCarree(),
        ccrs.Robinson(),
        ccrs.RotatedPole(pole_latitude=45, pole_longitude=180),
        ccrs.OSGB(),
        ccrs.TransverseMercator(),
        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(),
    ]

    if ccrs.PROJ4_VERSION < (5, 0, 0):
        # Produce the same sized image for old proj, to avoid having to replace
        # the image. If this figure is regenerated for both old and new proj,
        # then drop this condition.
        rows = 5
    else:
        rows = np.ceil(len(projections) / 5)

    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()

        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 #15
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 #16
0
    def test_cartopy_projection(self):
        cube = iris.load_cube(
            tests.get_data_path(('PP', 'aPPglob1', 'global.pp')))
        projections = {}
        projections['RotatedPole'] = ccrs.RotatedPole(pole_longitude=177.5,
                                                      pole_latitude=37.5)
        projections['Robinson'] = ccrs.Robinson()
        projections['PlateCarree'] = ccrs.PlateCarree()
        projections['NorthPolarStereo'] = ccrs.NorthPolarStereo()
        projections['Orthographic'] = ccrs.Orthographic(central_longitude=-90,
                                                        central_latitude=45)
        projections[
            'InterruptedGoodeHomolosine'] = ccrs.InterruptedGoodeHomolosine()
        projections['LambertCylindrical'] = ccrs.LambertCylindrical()

        # Set up figure
        fig = plt.figure(figsize=(10, 10))
        gs = matplotlib.gridspec.GridSpec(nrows=3,
                                          ncols=3,
                                          hspace=1.5,
                                          wspace=0.5)
        for subplot_spec, (name, target_proj) in itertools.izip(
                gs, projections.iteritems()):
            # Set up axes and title
            ax = plt.subplot(subplot_spec,
                             frameon=False,
                             projection=target_proj)
            ax.set_title(name)
            # Transform cube to target projection
            new_cube, extent = iris.analysis.cartography.project(cube,
                                                                 target_proj,
                                                                 nx=150,
                                                                 ny=150)
            # Plot
            plt.pcolor(
                new_cube.coord('projection_x_coordinate').points,
                new_cube.coord('projection_y_coordinate').points,
                new_cube.data)
            # Add coastlines
            ax.coastlines()

        # Tighten up layout
        gs.tight_layout(plt.gcf())

        # Verify resulting plot
        self.check_graphic(tol=6e-4)
def test_central_longitude(emphasis, lon):
    if emphasis == "ocean" and ccrs.PROJ4_VERSION < (7, 1, 0):
        pytest.skip()
    igh = ccrs.InterruptedGoodeHomolosine(central_longitude=lon,
                                          emphasis=emphasis)
    other_args = {"ellps=WGS84", "lon_0={}".format(lon)}
    if emphasis == "land":
        check_proj_params("igh", igh, other_args)
    elif emphasis == "ocean":
        check_proj_params("igh_o", igh, other_args)

    assert_almost_equal(
        np.array(igh.x_limits),
        [-20037508.3427892, 20037508.3427892],
        decimal=5,
    )
    assert_almost_equal(np.array(igh.y_limits),
                        [-8683259.7164347, 8683259.7164347])
Beispiel #18
0
def test_regrid_image():
    # Source data
    fname = os.path.join(config["repo_data_dir"], 'raster', 'natural_earth',
                         '50-natural-earth-1-downsampled.png')
    nx = 720
    ny = 360
    source_proj = ccrs.PlateCarree()
    source_x, source_y, _ = im_trans.mesh_projection(source_proj, nx, ny)
    data = plt.imread(fname)
    # Flip vertically to match source_x/source_y orientation
    data = data[::-1]

    # Target grid
    target_nx = 300
    target_ny = 300
    target_proj = ccrs.InterruptedGoodeHomolosine(emphasis='land')
    target_x, target_y, target_extent = im_trans.mesh_projection(
        target_proj, target_nx, target_ny)

    # Perform regrid
    new_array = im_trans.regrid(data, source_x, source_y, source_proj,
                                target_proj, target_x, target_y)

    # Plot
    fig = plt.figure(figsize=(10, 10))
    gs = mpl.gridspec.GridSpec(nrows=4, ncols=1, hspace=1.5, wspace=0.5)
    # Set up axes and title
    ax = fig.add_subplot(gs[0], projection=target_proj)
    ax.imshow(new_array, origin='lower', extent=target_extent)
    ax.coastlines()
    # Plot each color slice (tests masking)
    cmaps = {'red': 'Reds', 'green': 'Greens', 'blue': 'Blues'}
    for i, color in enumerate(['red', 'green', 'blue']):
        ax = fig.add_subplot(gs[i + 1], projection=target_proj)
        ax.imshow(new_array[:, :, i],
                  extent=target_extent,
                  origin='lower',
                  cmap=cmaps[color])
        ax.coastlines()

    # Tighten up layout
    gs.tight_layout(fig)
    return fig
Beispiel #19
0
def test_regrid_blue_marble_img():
    # Source data
    filename = '/data/local/dataZoo/cartography/raster/blue_marble_720_360.png'
    nx = 720
    ny = 360
    source_proj = ccrs.PlateCarree()
    source_x, source_y, source_extent = cartopy.img_transform.mesh_projection(source_proj, nx, ny)
    data = plt.imread(filename)
    # Flip vertically to match source_x/source_y orientation
    data = data[::-1]

    # Target grid
    target_nx = 300
    target_ny = 300
    target_proj = ccrs.InterruptedGoodeHomolosine()
    target_x, target_y, target_extent = cartopy.img_transform.mesh_projection(target_proj,
                                                                              target_nx,
                                                                              target_ny)

    # Perform regrid
    new_array = cartopy.img_transform.regrid(data, source_x, source_y, source_proj,
                                             target_proj, target_x, target_y)

    # Plot
    fig = plt.figure(figsize=(10, 10))
    gs = matplotlib.gridspec.GridSpec(nrows=4, ncols=1, hspace=1.5, wspace=0.5)
    # Set up axes and title
    ax = plt.subplot(gs[0], frameon=False, projection=target_proj)
    plt.imshow(new_array, origin='lower', extent=target_extent)
    ax.coastlines()
    # Plot each colour slice (tests masking)
    cmaps = {'red': 'Reds', 'green': 'Greens', 'blue': 'Blues'}
    for i, colour in enumerate(['red', 'green', 'blue']):
        ax = plt.subplot(gs[i + 1], frameon=False, projection=target_proj)
        ax.set_title(colour)
        plt.pcolormesh(target_x[0, :], target_y[:, 0], new_array[:, :, i],
                       cmap=cmaps[colour])
        ax.coastlines()

    # Tighten up layout
    gs.tight_layout(plt.gcf())
Beispiel #20
0
def test_multiple_projections():

    projections = [
        ccrs.PlateCarree(),
        ccrs.Robinson(),
        ccrs.RotatedPole(pole_latitude=45, pole_longitude=180),
        ccrs.OSGB(),
        ccrs.TransverseMercator(),
        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(),
    ]

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

        ax.set_global()

        ax.coastlines()

        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())
def plot_pcolormesh_global(xx,
                           yy,
                           data,
                           data_projection_code,
                           global_code,
                           cmin,
                           cmax,
                           subplots=[1, 1, 1]):
    plt.subplots = subplots
    #  https://scitools.org.uk/cartopy/docs/latest/crs/projections.html
    if global_code == 0:
        ax = plt.axes(projection=ccrs.Robinson())
    elif global_code == 1:
        ax = plt.axes(projection=ccrs.EqualEarth())
    elif global_code == 2:
        ax = plt.axes(projection=ccrs.InterruptedGoodeHomolosine())
    elif global_code == 3:
        ax = plt.axes(projection=ccrs.PlateCarree())  # lat/lon

    ax.gridlines(crs=ccrs.PlateCarree(),
                 draw_labels=False,
                 linewidth=1,
                 color='white',
                 alpha=0.5,
                 linestyle='--')

    projection = ccrs.epsg(data_projection_code)

    plt.pcolormesh(xx,
                   yy,
                   data,
                   transform=projection,
                   vmin=cmin,
                   vmax=cmax,
                   cmap='jet')
    plt.colorbar()
    ax.coastlines('110m', linewidth=0.8)
    ax.add_feature(cfeature.LAND)
Beispiel #22
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
def _create_projection_axis(projection_type, user_lon_0, lat_lim, subplot_grid,
                            less_output):
    """Set appropriate axis for projection type
    See plot_proj_to_latlon_grid for input parameter definitions.

    Returns
    -------
    ax :  matplotlib axis object
        defined with the correct projection
    show_grid_labels : logical
        True = show the grid labels, only currently
        supported for PlateCarree and Mercator projections
    """

    # initialize (optional) subplot variables
    row = []
    col = []
    ind = []

    if subplot_grid is not None:

        if type(subplot_grid) is dict:
            row = subplot_grid['nrows']
            col = subplot_grid['ncols']
            ind = subplot_grid['index']

        elif type(subplot_grid) is list:
            row = subplot_grid[0]
            col = subplot_grid[1]
            ind = subplot_grid[2]

        else:
            raise TypeError('Unexpected subplot_grid type: ',
                            type(subplot_grid))

    if projection_type == 'Mercator':
        if subplot_grid is not None:
            ax = plt.subplot(
                row,
                col,
                ind,
                projection=ccrs.Mercator(central_longitude=user_lon_0))
        else:
            ax = plt.axes(projection=ccrs.Mercator(
                central_longitude=user_lon_0))
        show_grid_labels = True

    elif projection_type == 'PlateCaree':
        if subplot_grid is not None:
            ax = plt.subplot(
                row,
                col,
                ind,
                projection=ccrs.PlateCarree(central_longitude=user_lon_0))
        else:
            ax = plt.axes(projection=ccrs.PlateCarree(
                central_longitude=user_lon_0))
        show_grid_labels = True

    elif projection_type == 'cyl':
        if subplot_grid is not None:
            ax = plt.subplot(row,
                             col,
                             ind,
                             projection=ccrs.LambertCylindrical(
                                 central_longitude=user_lon_0))
        else:
            ax = plt.axes(projection=ccrs.LambertCylindrical(
                central_longitude=user_lon_0))
        show_grid_labels = False

    elif projection_type == 'robin':
        if subplot_grid is not None:
            ax = plt.subplot(
                row,
                col,
                ind,
                projection=ccrs.Robinson(central_longitude=user_lon_0))
        else:
            ax = plt.axes(projection=ccrs.Robinson(
                central_longitude=user_lon_0))
        show_grid_labels = False

    elif projection_type == 'ortho':
        if subplot_grid is not None:
            ax = plt.subplot(
                row,
                col,
                ind,
                projection=ccrs.Orthographic(central_longitude=user_lon_0))
        else:
            ax = plt.axes(projection=ccrs.Orthographic(
                central_longitude=user_lon_0))
        show_grid_labels = False

    elif projection_type == 'stereo':
        if lat_lim > 0:
            stereo_proj = ccrs.NorthPolarStereo()
        else:
            stereo_proj = ccrs.SouthPolarStereo()

        if subplot_grid is not None:
            ax = plt.subplot(row, col, ind, projection=stereo_proj)
        else:
            ax = plt.axes(projection=stereo_proj)

        show_grid_labels = False

    elif projection_type == 'InterruptedGoodeHomolosine':
        if subplot_grid is not None:
            ax = plt.subplot(row,
                             col,
                             ind,
                             projection=ccrs.InterruptedGoodeHomolosine(
                                 central_longitude=user_lon_0))
        else:
            ax = plt.axes(projection=ccrs.InterruptedGoodeHomolosine(
                central_longitude=user_lon_0))
        show_grid_labels = False

    else:
        raise NotImplementedError(
            'projection type must be either "Mercator", "PlateCaree",  "cyl", "robin", "ortho", "stereo", or "InterruptedGoodeHomolosine"'
        )

    if not less_output:
        print('Projection type: ', projection_type)

    return (ax, show_grid_labels)
Beispiel #24
0
##########################################################
# Set up map and plot data

# Open a figure
plt.figure(1)
plt.clf()

# data coordinates: Use Geodetic (or PlateCarree) for data in lat-lon coordinates
datacoord = ccrs.Geodetic()
datacoord = ccrs.PlateCarree()

# Map projection for Global
ax = plt.axes(projection=ccrs.PlateCarree())
ax = plt.axes(projection=ccrs.Robinson())
ax = plt.axes(projection=ccrs.InterruptedGoodeHomolosine())

# Map projection for North Pole
ax = plt.axes(projection=ccrs.NorthPolarStereo())
ax.set_extent([-180, 180, 60, 90], ccrs.PlateCarree())

# Map projection for CONUS
ax = plt.axes(projection=ccrs.LambertConformal())
#ax = plt.axes(projection=ccrs.LambertConformal(central_longitude=-96,central_latitude=39,standard_parallels=(33,45)))
# Set lat-lon of map edges. These are reasonable for CONUS
ax.set_extent([-120, -73, 25, 50], ccrs.PlateCarree())

# Add your gridded data
plt.pcolormesh(lonedge, latedge, data, transform=datacoord)

# Add your point data
Beispiel #25
0
def time_ocean_igh():
    ccrs.InterruptedGoodeHomolosine().project_geometry(OCEAN.geoms)
Beispiel #26
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 #27
0
    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 #28
0
def test_igh_land():
    crs = ccrs.InterruptedGoodeHomolosine(emphasis="land")
    ax = plt.axes(projection=crs)
    ax.coastlines()
    ax.gridlines()
    return ax.figure
Beispiel #29
0
    p = ccrs.PlateCarree(central_longitude=0)
    threshold = 0
if projection == 'mollweide':
    p = ccrs.Mollweide(central_longitude=0)
    threshold = 1e6
if projection == 'robinson':
    p = ccrs.Robinson(central_longitude=0)
    threshold = 0
if projection == 'equalearth':
    p = ccrs.EqualEarth(central_longitude=0)
    threshold = 0
if projection == 'geostationary':
    p = ccrs.Geostationary(central_longitude=0)
    threshold = 0
if projection == 'goodehomolosine':
    p = ccrs.InterruptedGoodeHomolosine(central_longitude=0)
    threshold = 0
if projection == 'europp':
    p = ccrs.EuroPP()
    threshold = 0
if projection == 'northpolarstereo':
    p = ccrs.NorthPolarStereo()
    threshold = 0
if projection == 'southpolarstereo':
    p = ccrs.SouthPolarStereo()
    threshold = 0
if projection == 'lambertconformal':
    p = ccrs.LambertConformal(central_longitude=0)
    threshold = 0

#----------------------------------------------------------------------------
Beispiel #30
0
def main():
    rp = ccrs.RotatedPole(pole_latitude=45, pole_longitude=180)
    pc = ccrs.PlateCarree()
    
#    ax = plt.subplot(211, projection=rp)
#    ax.bluemarble()
#    ax.coastlines()
    # XXX The change in projection is a result of plt.plot making a poly or a line depending on some things...
    x, y = [-44, -44, 45, 45], [-45, 45, 45, -45]
#    x, y = [-44, -44, 45, 45, -44], [-45, 45, 45, -45, -45]
#    # XXX why is the horizontal line on the native projection not straight? BUG!
#    ax.plot(x, y, marker='o', transform=rp)
#    ax.gridlines()   
    
    
#    ax = plt.subplot(212, projection=pc)
    ax = plt.axes(projection=pc)
    ax = plt.axes(projection=ccrs.InterruptedGoodeHomolosine())
#    ax = plt.axes(projection=rp)
    
    x, y = [-20, -20, 20, 20], [-20, 20, 20, -20]
#    x, y = [-40, -40, 20, 20], [-20, 20, 20, -20]
    ax.plot(x, y, transform=rp)
    
    
    #ax.ll_boundary_poly_draw()
    
#    ax.stock_img('bluemarble')
#    ax.coastlines()
#    ax.ll_extents_draw()
    #ax.gshhs_line(outline_color='gray')
    
    plt.show()
    
    return
    
    
#    ax.bluemarble()
#    ax.coastlines()
#    ax.gshhs_line()

    x, y = [-20, -20, 20, 20], [-20, 20, 20, -20]
    ax.plot(x, y, transform=rp)
    x, y = [20, -20], [-20, -20]
    ax.plot(x, y, transform=rp)
#    ax.gridlines()

    print ax.ll_extents()
#    ax.set_xlim(-50, 50)
#    ax.set_ylim(30, 70)
    
    
    x1, y1, x2, y2 =  ax.ll_boundary_poly().bounds
    from matplotlib.patches import Rectangle    
    rect = Rectangle([x1, y1], x2-x1, y2-y1, edgecolor='gray', facecolor='none')
    ax.add_patch(rect)
    
#    ax.gshhs_line(outline_color='gray')
    #ax.gshhs_line()
    
    ax.stock_img('ne_shaded')
    
    plt.draw()
    plt.show()