Skip to main content

Regridding tools using xarray and flox.

Project description

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 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

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xarray_regrid-0.4.1.tar.gz (67.7 MB view details)

Uploaded Source

Built Distribution

xarray_regrid-0.4.1-py3-none-any.whl (22.7 kB view details)

Uploaded Python 3

File details

Details for the file xarray_regrid-0.4.1.tar.gz.

File metadata

  • Download URL: xarray_regrid-0.4.1.tar.gz
  • Upload date:
  • Size: 67.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for xarray_regrid-0.4.1.tar.gz
Algorithm Hash digest
SHA256 2c8a7baa321c2451aa42b387fef3b22ecd7bdf693e7ee5c52ebe5168482a1e2a
MD5 ca3559ec6f876df8204e6738f89b33bb
BLAKE2b-256 5823d55ead2418c4421f337297e3413afd8e39f2f7f7dba7935bd374cef6d20f

See more details on using hashes here.

File details

Details for the file xarray_regrid-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: xarray_regrid-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 22.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for xarray_regrid-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 92c7cf676292b29996149b06be56fe0b5cc6f6238fa9e88a45d8022c6a653468
MD5 5f24c7e47b669ffb25328f8f6ebd6a5a
BLAKE2b-256 70af5b36e319b559cc5713b66fcb5941fca1598a36d97f7c3bd50d6873c9d28c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page