Countries/ States (NaturalEarth)¶
The outline of the countries are obtained from Natural Earth. They are automatically downloaded on-the-fly (but only once) with cartopy and opened with geopandas. The following countries and regions are defined in regionmask.
- Countries 1:110m
- Countries 1:50m
- US States 1:50m
- US States 1:10m
Note
A mask obtained with a fine resolution dataset is not necessarily better. Always check your mask!
The following imports are necessary for the examples.
In [1]: import regionmask
In [2]: import matplotlib.pyplot as plt
Countries¶
In [3]: regionmask.defined_regions.natural_earth.countries_110.plot(add_label=False);
In [4]: plt.tight_layout()
US States¶
In [5]: states = regionmask.defined_regions.natural_earth.us_states_50
In [6]: states.plot(add_label=False);
In [7]: plt.tight_layout()
Also create a mask for a 1° grid over the US:
In [8]: import numpy as np
# create a grid
In [9]: lon = np.arange(200.5, 325)
In [10]: lat = np.arange(74.5, 14, -1)
In [11]: mask = states.mask(lon, lat, wrap_lon=True)
In [12]: mask_ma = np.ma.masked_invalid(mask)
In [13]: states.plot(add_label=False);
In [14]: LON_EDGE = np.arange(200, 326)
In [15]: LAT_EDGE = np.arange(75, 13, -1)
In [16]: plt.pcolormesh(LON_EDGE, LAT_EDGE, mask_ma, cmap='viridis');
In [17]: plt.tight_layout()