{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Regrid between curvilinear grids\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%matplotlib inline\n", "import matplotlib.pyplot as plt\n", "import cartopy.crs as ccrs\n", "import numpy as np\n", "import xarray as xr\n", "import xesmf as xe" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Prepare data\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Input data\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here we regrid the built-in \"rasm\" demo data. This data is used by another\n", "[xarray tutorial](http://xarray.pydata.org/en/stable/examples/multidimensional-coords.html#examples-multidim).\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
<xarray.Dataset> Size: 17MB\n",
"Dimensions: (time: 36, y: 205, x: 275)\n",
"Coordinates:\n",
" * time (time) object 288B 1980-09-16 12:00:00 ... 1983-08-17 00:00:00\n",
" xc (y, x) float64 451kB ...\n",
" yc (y, x) float64 451kB ...\n",
"Dimensions without coordinates: y, x\n",
"Data variables:\n",
" Tair (time, y, x) float64 16MB ...\n",
"Attributes:\n",
" title: /workspace/jhamman/processed/R1002RBRxaaa01a/l...\n",
" institution: U.W.\n",
" source: RACM R1002RBRxaaa01a\n",
" output_frequency: daily\n",
" output_mode: averaged\n",
" convention: CF-1.4\n",
" references: Based on the initial model of Liang et al., 19...\n",
" comment: Output from the Variable Infiltration Capacity...\n",
" nco_openmp_thread_number: 1\n",
" NCO: netCDF Operators version 4.7.9 (Homepage = htt...\n",
" history: Fri Aug 7 17:57:38 2020: ncatted -a bounds,,d...<xarray.DataArray 'Tair' (time: 36, y: 205, x: 275)> Size: 16MB\n",
"[2029500 values with dtype=float64]\n",
"Coordinates:\n",
" * time (time) object 288B 1980-09-16 12:00:00 ... 1983-08-17 00:00:00\n",
" xc (y, x) float64 451kB ...\n",
" yc (y, x) float64 451kB ...\n",
"Dimensions without coordinates: y, x\n",
"Attributes:\n",
" units: C\n",
" long_name: Surface air temperature\n",
" type_preferred: double\n",
" time_rep: instantaneous"
],
"text/plain": [
"<xarray.Dataset> Size: 17MB\n",
"Dimensions: (time: 36, y: 205, x: 275)\n",
"Coordinates:\n",
" * time (time) object 288B 1980-09-16 12:00:00 ... 1983-08-17 00:00:00\n",
" lon (y, x) float64 451kB 189.2 189.4 189.6 189.7 ... 17.4 17.15 16.91\n",
" lat (y, x) float64 451kB 16.53 16.78 17.02 17.27 ... 28.01 27.76 27.51\n",
"Dimensions without coordinates: y, x\n",
"Data variables:\n",
" Tair (time, y, x) float64 16MB ...\n",
"Attributes:\n",
" title: /workspace/jhamman/processed/R1002RBRxaaa01a/l...\n",
" institution: U.W.\n",
" source: RACM R1002RBRxaaa01a\n",
" output_frequency: daily\n",
" output_mode: averaged\n",
" convention: CF-1.4\n",
" references: Based on the initial model of Liang et al., 19...\n",
" comment: Output from the Variable Infiltration Capacity...\n",
" nco_openmp_thread_number: 1\n",
" NCO: netCDF Operators version 4.7.9 (Homepage = htt...\n",
" history: Fri Aug 7 17:57:38 2020: ncatted -a bounds,,d...<xarray.Dataset> Size: 106kB\n",
"Dimensions: (y: 45, x: 72, y_b: 46, x_b: 73)\n",
"Coordinates:\n",
" lon (y, x) float64 26kB -177.5 -172.5 -167.5 ... 167.5 172.5 177.5\n",
" lat (y, x) float64 26kB -88.0 -88.0 -88.0 -88.0 ... 88.0 88.0 88.0 88.0\n",
" lon_b (y_b, x_b) float64 27kB -180.0 -175.0 -170.0 ... 170.0 175.0 180.0\n",
" lat_b (y_b, x_b) float64 27kB -90.0 -90.0 -90.0 -90.0 ... 90.0 90.0 90.0\n",
"Dimensions without coordinates: y, x, y_b, x_b\n",
"Data variables:\n",
" *empty*<xarray.DataArray (time: 36, y: 45, x: 72)> Size: 933kB\n",
"array([[[ 0., 0., 0., ..., 0., 0., 0.],\n",
" [ 0., 0., 0., ..., 0., 0., 0.],\n",
" [ 0., 0., 0., ..., 0., 0., 0.],\n",
" ...,\n",
" [nan, nan, nan, ..., nan, nan, nan],\n",
" [nan, nan, nan, ..., nan, nan, nan],\n",
" [nan, nan, nan, ..., nan, nan, nan]],\n",
"\n",
" [[ 0., 0., 0., ..., 0., 0., 0.],\n",
" [ 0., 0., 0., ..., 0., 0., 0.],\n",
" [ 0., 0., 0., ..., 0., 0., 0.],\n",
" ...,\n",
" [nan, nan, nan, ..., nan, nan, nan],\n",
" [nan, nan, nan, ..., nan, nan, nan],\n",
" [nan, nan, nan, ..., nan, nan, nan]],\n",
"\n",
" [[ 0., 0., 0., ..., 0., 0., 0.],\n",
" [ 0., 0., 0., ..., 0., 0., 0.],\n",
" [ 0., 0., 0., ..., 0., 0., 0.],\n",
" ...,\n",
"...\n",
" ...,\n",
" [nan, nan, nan, ..., nan, nan, nan],\n",
" [nan, nan, nan, ..., nan, nan, nan],\n",
" [nan, nan, nan, ..., nan, nan, nan]],\n",
"\n",
" [[ 0., 0., 0., ..., 0., 0., 0.],\n",
" [ 0., 0., 0., ..., 0., 0., 0.],\n",
" [ 0., 0., 0., ..., 0., 0., 0.],\n",
" ...,\n",
" [nan, nan, nan, ..., nan, nan, nan],\n",
" [nan, nan, nan, ..., nan, nan, nan],\n",
" [nan, nan, nan, ..., nan, nan, nan]],\n",
"\n",
" [[ 0., 0., 0., ..., 0., 0., 0.],\n",
" [ 0., 0., 0., ..., 0., 0., 0.],\n",
" [ 0., 0., 0., ..., 0., 0., 0.],\n",
" ...,\n",
" [nan, nan, nan, ..., nan, nan, nan],\n",
" [nan, nan, nan, ..., nan, nan, nan],\n",
" [nan, nan, nan, ..., nan, nan, nan]]], shape=(36, 45, 72))\n",
"Coordinates:\n",
" * time (time) object 288B 1980-09-16 12:00:00 ... 1983-08-17 00:00:00\n",
" lon (y, x) float64 26kB -177.5 -172.5 -167.5 ... 167.5 172.5 177.5\n",
" lat (y, x) float64 26kB -88.0 -88.0 -88.0 -88.0 ... 88.0 88.0 88.0 88.0\n",
"Dimensions without coordinates: y, x\n",
"Attributes:\n",
" regrid_method: bilinear