Quickstart
xarray-regrid allows you to regrid xarray Datasets or DataArrays to a new resolution.
You can install xarray-regrid with pip:
pip install xarray-regrid
To use the package, import xarray_regrid. This will register the .regrid ‘accessor’ so it can be used.
Next load in the data you want to regrid, and the data with a grid you want to regrid to:
import xarray_regrid
import xarray
ds = xr.open_dataset("input_data.nc")
ds_grid = xr.open_dataset("target_grid.nc")
ds = ds.regrid.linear(ds_grid)
# or, for example:
ds = ds.regrid.conservative(ds_grid, latitude_coord="lat")
Multiple regridding methods are available:
linear interpolation (
.regrid.linear)nearest-neighbor (
.regrid.nearest)cubic interpolation (
.regrid.cubic)conservative regridding (
.regrid.conservative)zonal statistics (
.regrid.stat) is available to compute statistics such as the maximum value, or variance.
Additionally, there are separate methods available to compute the
most common value
(.regrid.most_common) and least common value
(.regrid.least_common). This can be used to upscale very fine categorical data to a more course resolution.