How to use the regionmask.core.regions._OneRegion 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 / core / regions.py View on Github external
lst.append(np.vstack((np.array(poly.exterior.coords), nan)))

            # remove the very last NaN
            self._coords = np.vstack(lst)[:-1, :]

        return self._coords

    @property
    def bounds(self):
        """bounds of the regions ((Multi)Polygon.bounds (min_lon, min_lat, max_lon, max_lat)"""
        if self._bounds is None:
            self._bounds = self.polygon.bounds
        return self._bounds


class Region_cls(_OneRegion):
    def __init__(self, number, name, abbrev, outline, centroid=None):

        msg = "Using 'Region_cls' is deprecated, please use '_OneRegion' instead."
        warnings.warn(msg, FutureWarning, stacklevel=3)

        super(Region_cls, self).__init__(number, name, abbrev, outline, centroid)
github mathause / regionmask / regionmask / core / regions.py View on Github external
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])

        self.regions = regions
        self.name = name
        self.source = source
github mathause / regionmask / regionmask / core / regions.py View on Github external
-------

        ``_OneRegion`` can be created with numpy-style outlines::

            outl = ((0, 0), (0, 1), (1, 1.), (1, 0))
            r = _OneRegion(1, 'Unit Square', 'USq', outl)

        or by passing shapely Polygons::

            from shapely.geometry import Polygon

            poly = Polygon(outl)
            r = _OneRegion(1, 'Unit Square', 'USq', poly, centroid=[0.5, 0.75])
        """

        super(_OneRegion, self).__init__()

        self.number = number
        self.name = name
        self.abbrev = abbrev

        self._is_polygon = isinstance(outline, (Polygon, MultiPolygon))

        if self._is_polygon:
            self._polygon = outline
            self._coords = None
        else:
            self._polygon = None
            outline = np.asarray(outline)

            assert outline.ndim == 2, "Outline must be 2D"
            assert outline.shape[1] == 2, "Outline must have Nx2 elements"