https://github.com/xarray-contrib/xarray-regrid
Regridding utility for xarray
https://github.com/xarray-contrib/xarray-regrid
Last synced: 11 months ago
JSON representation
Regridding utility for xarray
- Host: GitHub
- URL: https://github.com/xarray-contrib/xarray-regrid
- Owner: xarray-contrib
- License: apache-2.0
- Created: 2023-08-04T08:59:17.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-12-20T00:04:36.000Z (about 1 year ago)
- Last Synced: 2025-04-02T11:50:00.274Z (11 months ago)
- Language: Python
- Homepage: https://xarray-regrid.readthedocs.org/
- Size: 76.6 MB
- Stars: 80
- Watchers: 7
- Forks: 8
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Citation: CITATION.cff
Awesome Lists containing this project
README
# xarray-regrid: Regridding utilities for xarray.

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](https://docs.xarray.dev/en/latest/user-guide/dask.html).
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.
[](https://pypi.python.org/pypi/xarray-regrid/)
[](https://doi.org/10.5281/zenodo.10203304)
[](https://xarray-regrid.readthedocs.org/)
## 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:
```console
pip install xarray-regrid
```
To improve performance in certain cases:
```console
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:
```py
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](https://mamba.readthedocs.io/en/latest/user_guide/micromamba.html) is a lightweight version of the much faster "mamba" conda alternative.
```sh
micromamba create -n environment_name -f environment.yml
```
## Acknowledgements
This package was developed under Netherlands eScience Center grant [NLESC.OEC.2022.017](https://research-software-directory.org/projects/excited).