Skip to main content

xarray-regrid: Regridding utilities for xarray.

Logo

With xarray-regrid it is possible to regrid between two rectilinear grids. The following methods are supported:

  • Linear
  • Nearest-neighbor
  • Conservative
  • Cubic
  • "Most common value", as well as other zonal statistics (e.g., variance or median).

All regridding methods can operate lazily on Dask arrays.

Note that "Most common value" is designed to regrid categorical data to a coarse resolution. For regridding categorical data to a finer resolution, please use "nearest-neighbor" regridder.

PyPI conda-forge DOI Docs

Why xarray-regrid?

Regridding is a common operation in earth science and other fields. While xarray does have some interpolation methods available, these are not always straightforward to use. Additionally, methods such as conservative regridding, or taking the most common value, are not available in xarray.

Installation

For a minimal install:

pip install xarray-regrid

Note: xarray-regrid is also available on conda-forge.

To improve performance in certain cases:

pip install xarray-regrid[accel]

which includes optional extras such as:

  • dask: parallelization over chunked data
  • sparse: for performing conservative regridding using sparse weight matrices
  • opt-einsum: optimized einsum routines used in conservative regridding

Benchmarking varies across different hardware specifications, but the inclusion of these extras can often provide significant speedups.

Usage

The xarray-regrid routines are accessed using the "regrid" accessor on an xarray Dataset:

import xarray_regrid

ds = xr.open_dataset("input_data.nc")
ds_grid = xr.open_dataset("target_grid.nc")

ds.regrid.linear(ds_grid)

For examples, see the benchmark notebooks and the demo notebooks.

Benchmarks

The benchmark notebooks contain comparisons to more standard methods (CDO, xESMF).

To be able to run the notebooks, a conda environment is required (due to ESMF and CDO). You can install this environment using the environment.yml file in this repository. Micromamba is a lightweight version of the much faster "mamba" conda alternative.

micromamba create -n environment_name -f environment.yml

Acknowledgements

This package was developed under Netherlands eScience Center grant NLESC.OEC.2022.017.

Metadata

Release files for xarray-regrid 0.4.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xarray-regrid 0.4.2
File Size Uploaded
xarray_regrid-0.4.2.tar.gz 67.7 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for xarray-regrid 0.4.2
File Interpreter ABI Platform
xarray_regrid-0.4.2-py3-none-any.whl Python 3 none any Details

Total release size: 67.7 MB

Release files / xarray_regrid-0.4.2.tar.gz

Download URL xarray_regrid-0.4.2.tar.gz
Size 67.7 MB
Tags Source
SHA-256 checksum
How to use checksums
96525d39b0290efa59e0255cebd35be028052f1b347bfb10fd259b4380289673
BLAKE2b-256 checksum
How to use checksums
989ef3b0a63917a6bd4b7e2b290cebc447c8db8e6ff63b4125e30fdcd1e378e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / xarray_regrid-0.4.2-py3-none-any.whl

Download URL xarray_regrid-0.4.2-py3-none-any.whl
Size 22.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
85c575fd5683b296b18a333038f743617d06c1994cd52562e7cfae4a5b8d862f
BLAKE2b-256 checksum
How to use checksums
4a94e7f02068c654a1d94e0d01dd0f6a35730a7284dd0dc3277c45b1ec3a48a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release history Release notifications | RSS feed

This release

0.4.2 This release

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page