How to use the regionmask.core.regions.Regions function in regionmask

To help you get started, we’ve selected a few regionmask 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 mathause / regionmask / regionmask / defined_regions / natural_earth.py View on Github external
names = _maybe_get_column(df, names)
    abbrevs = _maybe_get_column(df, abbrevs)
    coords = _maybe_get_column(df, coords)

    # create one MultiPolygon of all Polygons (used for land)
    if combine_coords:
        from shapely import geometry

        coords = [geometry.MultiPolygon([p for p in coords])]

    # make sure numbers is a list
    numbers = np.array(numbers)

    source = "http://www.naturalearthdata.com"

    return Regions(
        coords, numbers=numbers, names=names, abbrevs=abbrevs, name=title, source=source
    )
github mathause / regionmask / regionmask / core / regions.py View on Github external
return _mask(
            outlines=outlines,
            regions_is_180=self.lon_180,
            numbers=self.numbers,
            lon_or_obj=lon_or_obj,
            lat=lat,
            lon_name=lon_name,
            lat_name=lat_name,
            method=method,
            xarray=xarray,
            wrap_lon=wrap_lon,
        )


# add the plotting methods
Regions.plot = _plot
Regions.plot_regions = _plot_regions


class Regions_cls(Regions):
    def __init__(
        self, name, numbers, names, abbrevs, outlines, centroids=None, source=""
    ):
        """
        Parameters
        ----------
        name : string
            Name of the collection of regions.
        numbers : list of int
            List of numerical indices for every region.
        names : dict of string
            Long name of each region. Must be accessible as names[number].
github mathause / regionmask / regionmask / core / regions.py View on Github external
lon_or_obj=lon_or_obj,
            lat=lat,
            lon_name=lon_name,
            lat_name=lat_name,
            method=method,
            xarray=xarray,
            wrap_lon=wrap_lon,
        )


# add the plotting methods
Regions.plot = _plot
Regions.plot_regions = _plot_regions


class Regions_cls(Regions):
    def __init__(
        self, name, numbers, names, abbrevs, outlines, centroids=None, source=""
    ):
        """
        Parameters
        ----------
        name : string
            Name of the collection of regions.
        numbers : list of int
            List of numerical indices for every region.
        names : dict of string
            Long name of each region. Must be accessible as names[number].
        abbrevs : dict of string
            List of abbreviations of each region. Must be accessible as
            abbrevs[number].
        outlines : List of Nx2 float array of vertices, Polygon, MultiPolygon
github mathause / regionmask / regionmask / core / regions.py View on Github external
outlines=outlines,
            regions_is_180=self.lon_180,
            numbers=self.numbers,
            lon_or_obj=lon_or_obj,
            lat=lat,
            lon_name=lon_name,
            lat_name=lat_name,
            method=method,
            xarray=xarray,
            wrap_lon=wrap_lon,
        )


# add the plotting methods
Regions.plot = _plot
Regions.plot_regions = _plot_regions


class Regions_cls(Regions):
    def __init__(
        self, name, numbers, names, abbrevs, outlines, centroids=None, source=""
    ):
        """
        Parameters
        ----------
        name : string
            Name of the collection of regions.
        numbers : list of int
            List of numerical indices for every region.
        names : dict of string
            Long name of each region. Must be accessible as names[number].
        abbrevs : dict of string
github mathause / regionmask / regionmask / core / regions.py View on Github external
from shapely.geometry import Polygon

            numbers = [1, 2]
            names = {1:'Unit Square1', 2: 'Unit Square2'}
            abbrevs = {1:'uSq1', 2:'uSq2'}
            poly = {1: Polygon(outl1), 2: Polygon(outl2)}

            r = Regions(outlines, numbers, names, abbrevs, name)

            # arguments are now optional
            r = Regions(outlines)

        """

        super(Regions, self).__init__()

        if numbers is None:
            numbers = range(len(outlines))

        if not _is_numeric(numbers):
            raise ValueError("'numbers' must be numeric")

        outlines = _maybe_to_dict(numbers, outlines)

        names = _sanitize_names_abbrevs(numbers, names, "Region")
        abbrevs = _sanitize_names_abbrevs(numbers, abbrevs, "r")

        regions = dict()

        for n in numbers:
            regions[n] = _OneRegion(n, names[n], abbrevs[n], outlines[n])