regionmask.Regions¶
-
class
regionmask.
Regions
(outlines, numbers=None, names=None, abbrevs=None, name='unnamed', source=None)¶ class for plotting regions and creating region masks
-
__init__
(self, outlines, numbers=None, names=None, abbrevs=None, name='unnamed', source=None)¶ - Parameters
outlines (iterable or dict of: Nx2 array of vertices, Polygon or MultiPolygon) – List of the coordinates of the vertices (outline) of the region as shapely Polygon/ MultiPolygon or list.
numbers (iterable of int, optional) – List of numerical indices for every region. Default: range(0, len(outlines))
names (iterable or dict of string, optional) – Long name of each region. Default: [“Region0”, .., “RegionN”]
abbrevs (iterable or dict of string, optional) – Abbreviations of each region. Default: [“r0”, …, “rN”]
name (string, optional) – Name of the collection of regions. Default: “unnamed”
source (string, optional) – Source of the region definitions. Default: “”.
Example
Create your own
Regions
:from regionmask import Regions name = 'Example' numbers = [0, 1] names = ['Unit Square1', 'Unit Square2'] abbrevs = ['uSq1', 'uSq2'] outl1 = ((0, 0), (0, 1), (1, 1.), (1, 0)) outl2 = ((0, 1), (0, 2), (1, 2.), (1, 1)) outlines = [outl1, outl2] r = Regions(outlines, numbers, names, abbrevs, name)
It’s also possible to pass shapely Poylgons:
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)
Methods
__init__
(self, outlines[, numbers, names, …])- param outlines
List of the coordinates of the vertices (outline) of the region as
combiner
(self, prop)combines attributes from single regions
map_keys
(self, key)map from names and abbrevs of the regions to numbers
mask
(self, lon_or_obj[, lat, lon_name, …])create a grid as mask of a set of regions for given lat/ lon grid
mask_3D
(self, lon_or_obj[, lat, drop, …])create a 3D boolean as mask of a set of regions for given lat/ lon grid
plot
(self[, ax, proj, regions, add_label, …])plot map with with region outlines
plot_regions
(self[, ax, regions, add_label, …])plot map with with srex regions
Attributes
list of abbreviations of the regions
list of the bounds of the regions (min_lon, min_lat, max_lon, max_lat)
global bounds over all regions (min_lon, min_lat, max_lon, max_lat)
list of the center of mass of the regions
list of coordinates of the region vertices as numpy array
if the regions extend from -180 to 180
if the regions extend from 0 to 360
list of names of the regions
list of the numbers of the regions
list of shapely Polygon/ MultiPolygon of the regions
dictionary that maps all names and abbrevs to the region number
-