{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Benchmarking nearest-neighbor regridding\n", "\n", "In this notebook we compare the results of three nearest-neighbor regridding methods:\n", "- The CDO (Climate Data Operators) command line program.\n", "- The xESMF xarray extension (based on the Earth System Modelling Framework).\n", "- xarray's `interp` method, wrapped as an accessor by `xarray-regrid`.\n", "\n", "The data to resample is the ERA5 monthly dataset, for the dewpoint temperature.\n", "\n", "We start with importing the required modules, starting up Dask and loading in the data:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from time import time\n", "import dask.distributed\n", "import xarray_regrid # Importing this will make Dataset.regrid accessible.\n", "import xarray as xr\n", "from xarray_regrid import Grid\n", "import xesmf as xe\n", "\n", "client = dask.distributed.Client()\n", "\n", "ds = xr.open_dataset(\n", " \"data/era5_2m_dewpoint_temperature_2000_monthly.nc\",\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Both `xarray-regrid` and `xESMF` require a dataset to resample to. For this you can also use an already existing dataset with the desired grid.\n", "\n", "Here we use the `Grid` dataclass from `xarray-regrid` to create the dataset." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
<xarray.Dataset> Size: 6kB\n",
"Dimensions: (latitude: 265, longitude: 530)\n",
"Coordinates:\n",
" * latitude (latitude) float64 2kB 45.0 45.17 45.34 ... 89.54 89.71 89.88\n",
" * longitude (longitude) float64 4kB 90.0 90.17 90.34 ... 179.6 179.8 179.9\n",
"Data variables:\n",
" *empty*