regionmask
create masks of geospatial regions for arbitrary grids
What it is and what it does
regionmask is a Python package for creating spatial masks that map grid points in geospatial datasets to geographic regions. It solves the common problem in climate science and geospatial analysis of needing to aggregate gridded data (such as climate model output or reanalysis data) by region—countries, continents, or custom areas—by determining which region each grid point belongs to. The package generates masks in multiple formats (2D integer, 3D boolean, or 3D fractional) and handles edge cases like region boundaries and overlaps carefully.
The package includes a library of predefined regions (countries, landmasks, and regions from scientific literature) and can also work with user-defined regions from shapefiles via geopandas, numpy arrays, or shapely geometries. It depends on geopandas, numpy, xarray, rasterio, shapely, pooch, and packaging to handle data I/O, spatial operations, and grid manipulation. It is actively maintained, supports modern Python versions, and carries no known security vulnerabilities.
Use it for:
- Compute regional climate averages from global model output by masking grid points to countries or continents.
- Aggregate reanalysis data over custom geographic regions defined in scientific literature.
- Generate land-sea masks or other binary spatial masks for filtering gridded datasets.
- Create visualizations of predefined or custom regions overlaid on geospatial grids.
- Build workflows that combine multiple region definitions (overlapping or non-overlapping) for multi-scale analysis.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
regionmask creates spatial masks for gridded data that identify which region each grid point belongs to, enabling regional aggregation of climate, reanalysis, and other geospatial datasets.
Yes. regionmask is actively maintained, has no known vulnerabilities, installs with low friction, and is licensed permissively. It directly solves a common and specific need in climate and geospatial data workflows. Install it if you work with gridded data and need to aggregate or mask by geographic region.
Install
regionmask on PyPI
pip
pip install regionmaskuv
uv add regionmaskpoetry
poetry add regionmaskInstalling regionmask
Before you install
Low friction install with a wheel distribution. Active maintenance with recent commits and stable production status; supports current Python versions (3.10–3.13).
License in practice
MIT license is permissive; you can use, modify, and distribute regionmask with minimal restrictions, making it suitable for both open and proprietary projects.
Quickstart
import regionmask
import xarray as xr
# Load gridded data
data = xr.open_dataset('climate_data.nc')
# Create a mask for a predefined region
mask = regionmask.defined_regions.countries.mask(data)
Requires Python >= 3.10; rasterio may need system libraries (GDAL) depending on your environment.
Verify before relying
- Whether predefined regions (countries, landmasks, literature regions) are current and comprehensive enough for typical use cases.
- Performance characteristics when masking very large grids or many overlapping regions.
- Availability and quality of shapefile support for custom region definitions beyond the built-in set.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 7 — geopandas, numpy, packaging, pooch, rasterio, shapely, xarray |
| Maintenance | actively maintained — 619 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 177,263/month — #10,216 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: regionmask-0.13.0-py3-none-any.whl
Tags
More Scientific/Engineering packages
NumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
pandaspandas provides fast, flexible data structures…
permissive · top 100 on PyPI
scipyscipy provides numerical algorithms for…
permissive · top 100 on PyPI
scikit-learnscikit-learn provides a comprehensive Python…
permissive · top 1,000 on PyPI
dilldill extends Python's pickle module to…
permissive · top 1,000 on PyPI
multiprocessMultiprocess is an enhanced fork of Python's…
permissive · top 1,000 on PyPI
geocifGenerates climatic impact drivers from Earth…
permissive · top 15,000 on PyPI
GridDataFormatsGridDataFormats reads and writes n-dimensional…
copyleft · top 15,000 on PyPI
regionsRegions provides tools for defining,…
permissive · top 15,000 on PyPI
pystac-ext-gridExtends PySTAC to describe gridded data…
permissive · top 5,000 on PyPI
spoptSpopt solves spatial optimization problems…
permissive · top 15,000 on PyPI
aws-cdk.region-infoProvides a queryable database of AWS…
permissive · top 15,000 on PyPI
morecantileConstruct and work with map tile grids…
permissive · top 15,000 on PyPI
dask-geopandasDask-GeoPandas parallelizes geospatial…
permissive · top 15,000 on PyPI
inequalityInequality provides methods for measuring…
permissive · top 15,000 on PyPI
drain3Drain3 extracts recurring patterns (templates)…
permissive · top 15,000 on PyPI