skillfed

regionmask

create masks of geospatial regions for arbitrary grids

regionmask v0.13.0 177.3K downloads/30d#10,216 on PyPI261
Permissive license MIT Active released

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 regionmask

uv

uv add regionmask

poetry

poetry add regionmask

Installing 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

Development Status :: 5 - Production/StableIntended Audience :: Science/ResearchLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Topic :: Scientific/EngineeringTopic :: Scientific/Engineering :: Atmospheric ScienceTopic :: Scientific/Engineering :: GIS

Tags

geospatial region masksgridded data regional aggregationclimate model region maskingspatial region definitiongeographic grid maskingcountry mask generationreanalysis data regional averaging
geospatialclimate-datagridded-data

More Scientific/Engineering packages