How to use the cartopy.crs.Geodetic function in Cartopy

To help you get started, we’ve selected a few Cartopy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github silburt / DeepMoon / tests / test_input_data_gen.py View on Github external
self.imgsize = self.img.size

        # Crater catalogue.
        self.craters = igen.ReadLROCHeadCombinedCraterCSV(
            filelroc="../catalogues/LROCCraters.csv",
            filehead="../catalogues/HeadCraters.csv",
            sortlat=True)

        # Long/lat limits
        self.cdim = [-180., 180., -60., 60.]

        # Coordinate systems.
        self.iglobe = ccrs.Globe(semimajor_axis=1737400,
                                 semiminor_axis=1737400,
                                 ellipse=None)
        self.geoproj = ccrs.Geodetic(globe=self.iglobe)
        self.iproj = ccrs.PlateCarree(globe=self.iglobe)
github linsalrob / crAssphage / bin / map_drawing / drawing.py View on Github external
"""

    linesizes = []
    # plot the lines first so the circles are on top!
    for tple in linedata:
        if not plotsingle and linedata[tple]['count'] < 2:
            continue

        lc = line_color(linedata[tple]['count'], verbose=verbose)
        linealpha = get_alpha(linedata[tple]['count'], verbose=verbose)
        if not linedata[tple]['samecontinent'] and colorcontinents:
            sys.stderr.write("Color by continents is currently disabled. Sorry, Liz\n")

        plt.plot(linedata[tple]['x'], linedata[tple]['y'], color=lc,
                 linewidth=linedata[tple]['linewidth'], alpha=linealpha,
                 zorder=linedata[tple]['count'], transform=ccrs.Geodetic())
        linesizes.append(linedata[tple]['count'])

    return linesizes
github akrherz / pyIEM / src / pyiem / plot / util.py View on Github external
ylim = ax.get_ylim()
    # Verticies of the plot boundaries in clockwise order
    verts = np.array(
        [
            (xlim[0], ylim[0]),
            (xlim[0], ylim[1]),
            (xlim[1], ylim[1]),
            (xlim[1], ylim[0]),
            (xlim[0], ylim[0]),
        ]
    )
    codes = [mpath.Path.MOVETO] + (len(verts) - 1) * [mpath.Path.LINETO]
    for geo in geom:
        ccw = np.asarray(geo.exterior)[::-1]
        points = ax.projection.transform_points(
            ccrs.Geodetic(), ccw[:, 0], ccw[:, 1]
        )
        verts = np.concatenate([verts, points[:, :2]])
        codes = np.concatenate(
            [
                codes,
                [mpath.Path.MOVETO]
                + (points.shape[0] - 1) * [mpath.Path.LINETO],
            ]
        )

    path = mpath.Path(verts, codes)
    # Removes any external data
    patch = mpatches.PathPatch(
        path, facecolor="white", edgecolor="none", zorder=reference.Z_CLIP
    )
    ax.add_patch(patch)
github silburt / DeepMoon / input_data_gen.py View on Github external
Craters with transformed x, y pixel positions and pixel radii.
    distortion_coefficient : float
        Ratio between the central heights of the transformed image and original
        image.
    centrallonglat_xy : pandas.DataFrame
        xy position of the central longitude and latitude.
    """

    # If user doesn't provide Moon globe properties.
    if not iglobe:
        iglobe = ccrs.Globe(semimajor_axis=arad*1000.,
                            semiminor_axis=arad*1000., ellipse=None)

    # Set up Geodetic (long/lat), Plate Carree (usually long/lat, but not when
    # globe != WGS84) and Orthographic projections.
    geoproj = ccrs.Geodetic(globe=iglobe)
    iproj = ccrs.PlateCarree(globe=iglobe)
    oproj = ccrs.Orthographic(central_longitude=np.mean(llbd[:2]),
                              central_latitude=np.mean(llbd[2:]),
                              globe=iglobe)

    # Create and transform coordinates of image corners and edge midpoints.
    # Due to Plate Carree and Orthographic's symmetries, max/min x/y values of
    # these 9 points represent extrema of the transformed image.
    xll = np.array([llbd[0], np.mean(llbd[:2]), llbd[1]])
    yll = np.array([llbd[2], np.mean(llbd[2:]), llbd[3]])
    xll, yll = np.meshgrid(xll, yll)
    xll = xll.ravel()
    yll = yll.ravel()

    # [:,:2] because we don't need elevation data.
    res = iproj.transform_points(x=xll, y=yll, src_crs=geoproj)[:, :2]
github SciTools / cartopy / lib / cartopy / examples / wmts_time.py View on Github external
def main():
    # URL of NASA GIBS
    URL = 'https://gibs.earthdata.nasa.gov/wmts/epsg4326/best/wmts.cgi'
    wmts = WebMapTileService(URL)

    # Layers for MODIS true color and snow RGB
    layers = ['MODIS_Terra_SurfaceReflectance_Bands143',
              'MODIS_Terra_CorrectedReflectance_Bands367']

    date_str = '2016-02-05'

    # Plot setup
    plot_CRS = ccrs.Mercator()
    geodetic_CRS = ccrs.Geodetic()
    x0, y0 = plot_CRS.transform_point(4.6, 43.1, geodetic_CRS)
    x1, y1 = plot_CRS.transform_point(11.0, 47.4, geodetic_CRS)
    ysize = 8
    xsize = 2 * ysize * (x1 - x0) / (y1 - y0)
    fig = plt.figure(figsize=(xsize, ysize), dpi=100)

    for layer, offset in zip(layers, [0, 0.5]):
        ax = fig.add_axes([offset, 0, 0.5, 1], projection=plot_CRS)
        ax.set_xlim((x0, x1))
        ax.set_ylim((y0, y1))
        ax.add_wmts(wmts, layer, wmts_kwargs={'time': date_str})
        txt = ax.text(4.7, 43.2, wmts[layer].title, fontsize=18, color='wheat',
                      transform=geodetic_CRS)
        txt.set_path_effects([PathEffects.withStroke(linewidth=5,
                                                     foreground='black')])
    plt.show()
github SciTools / iris / lib / iris / experimental / regrid_conservative.py View on Github external
"""
Support for conservative regridding via ESMPy.

"""

import cartopy.crs as ccrs
import numpy as np

import iris
from iris.analysis._interpolation import get_xy_dim_coords
from iris.analysis._regrid import RectilinearRegridder
from iris.util import _meshgrid


#: A static Cartopy Geodetic() instance for transforming to true-lat-lons.
_CRS_TRUELATLON = ccrs.Geodetic()


def _convert_latlons(crs, x_array, y_array):
    """
    Convert x+y coords in a given crs to (x,y) values in true-lat-lons.

    .. note::

        Uses a plain Cartopy Geodetic to convert to true-lat-lons.  This makes
        no allowance for a non-spherical earth.  But then, neither does ESMF.

    """
    ll_values = _CRS_TRUELATLON.transform_points(crs, x_array, y_array)
    return ll_values[..., 0], ll_values[..., 1]
github bird-house / flyingpigeon / scripts / modis_fetch2.py View on Github external
def main():
    # URL of NASA GIBS
    URL = 'http://gibs.earthdata.nasa.gov/wmts/epsg4326/best/wmts.cgi'
    wmts = WebMapTileService(URL)

    # Layers for MODIS true color and snow RGB
    layers = ['MODIS_Terra_SurfaceReflectance_Bands143',
              'MODIS_Terra_CorrectedReflectance_Bands367']

    date_str = '2016-02-05'

    # Plot setup
    plot_CRS = ccrs.Mercator()
    geodetic_CRS = ccrs.Geodetic()
    x0, y0 = plot_CRS.transform_point(4.6, 43.1, geodetic_CRS)
    x1, y1 = plot_CRS.transform_point(11.0, 47.4, geodetic_CRS)
    ysize = 8
    xsize = 2 * ysize * (x1 - x0) / (y1 - y0)
    fig = plt.figure(figsize=(xsize, ysize), dpi=100)
github linsalrob / crAssphage / bin / matrix2map.py View on Github external
for tple in lineat:
        if plotintensity:
            idx = int((lineat[tple] / maxline) * len(red2blue)) - 1
            if linedata[tple]['samecontinent']:
                colorline = red2blue[idx]
            else:
                colorline = green2yellow[idx]
        else:
            idx = lineval.index(lineat[tple])
            if linedata[tple]['samecontinent']:
                colorline = linecolors[idx]
            else:
                colorline = green2yellowline[idx]

        plt.plot(linedata[tple]['x'], linedata[tple]['y'], color=colorline, linewidth=linedata[tple]['linewidth'],
                 alpha=linedata[tple]['alpha'], transform=ccrs.Geodetic())



    #    plt.colorbar(CS3)

    # add a color bar for the lines and circles
    rect = Rectangle((10, 10), 140, 130, linewidth=5, edgecolor='b', facecolor='none')
    #plt.legend(handles=[rect])

    #grad = plt.imshow([[0.,1.], [0.,1.]], cmap = plt.cm.Reds, interpolation = 'bicubic')
    #plt.legend(handles=[grad])
    #fig = plt.figure()
    #ax2 = fig.add_axes()
    #ax2.add_patch(rect)
github akrherz / pyIEM / src / pyiem / plot / geoplot.py View on Github external
s = load_pickle_geo("us_states.pickle")
            mask_outside_geom(self.ax, s[self.state]["geom"])
            return
        if sector == "cwa":
            s = load_pickle_geo("cwa.pickle")
            mask_outside_geom(self.ax, s[self.cwa]["geom"])
            return
        if sector == "iowawfo":
            s = load_pickle_geo("iowawfo.pickle")
            geo = s["iowawfo"]["geom"]
            ccw = np.asarray(geo.exterior)[::-1]
        else:
            ccw = load_bounds("%s_ccw" % (sector,))
        # in map coords
        points = self.ax.projection.transform_points(
            ccrs.Geodetic(), ccw[:, 0], ccw[:, 1]
        )
        mask_outside_polygon(points[:, :2], ax=self.ax)