{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Benchmarking bilinear regridding\n", "\n", "In this notebook we compare the results of three bilinear 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 and `create_regridding_dataset` function from `xarray-regrid` to create the dataset." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
<xarray.Dataset>\n",
"Dimensions: (latitude: 265, longitude: 530)\n",
"Coordinates:\n",
" * latitude (latitude) float64 45.0 45.17 45.34 45.51 ... 89.54 89.71 89.88\n",
" * longitude (longitude) float64 90.0 90.17 90.34 90.51 ... 179.6 179.8 179.9\n",
"Data variables:\n",
" *empty*<xarray.Dataset>\n",
"Dimensions: (time: 12, latitude: 265, longitude: 530)\n",
"Coordinates:\n",
" * time (time) datetime64[ns] 2000-01-01 2000-02-01 ... 2000-12-01\n",
" * latitude (latitude) float64 45.0 45.17 45.34 45.51 ... 89.54 89.71 89.88\n",
" * longitude (longitude) float64 90.0 90.17 90.34 90.51 ... 179.6 179.8 179.9\n",
"Data variables:\n",
" d2m (time, latitude, longitude) float64 253.4 253.3 ... 249.1 249.1\n",
"Attributes:\n",
" Conventions: CF-1.6\n",
" history: 2023-06-19 14:51:03 UTC by era5cli 1.4.0: reanalysis-era5-s...