Skip to content

Interp

resample_rioxarray(ds, resolution=(1000, 1000), method='bilinear')

Resamples a raster dataset using rasterio-xarray.

Parameters:

Name Type Description Default
ds Dataset

The input dataset to be resampled.

required
resolution int

The desired resolution of the resampled dataset. Default is 1_000.

(1000, 1000)
method str

The resampling method to be used. Default is "bilinear".

'bilinear'

Returns:

Type Description
Dataset

xr.Dataset: The resampled dataset.

Source code in rs_tools/_src/geoprocessing/interp.py
def resample_rioxarray(ds: xr.Dataset, resolution: Tuple[int, int]=(1_000, 1_000), method: str="bilinear") -> xr.Dataset:
    """
    Resamples a raster dataset using rasterio-xarray.

    Parameters:
        ds (xr.Dataset): The input dataset to be resampled.
        resolution (int): The desired resolution of the resampled dataset. Default is 1_000.
        method (str): The resampling method to be used. Default is "bilinear".

    Returns:
        xr.Dataset: The resampled dataset.
    """

    ds = ds.rio.reproject(
        ds.rio.crs,
        resolution=resolution,
        resample=rioxarray_samplers[method], 
    )
    return ds