{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Transforming Vertical Coordinates\n", "\n", "A common need in the analysis of ocean and atmospheric data is to transform the vertical coordinate from its original coordinate (e.g. depth) to a new coordinate (e.g. density).\n", "Xgcm supports this sort of one-dimensional coordinate transform on `Axis` and `Grid` objects using the `transform` method.\n", "Two algorithms are implemented:\n", "\n", "- _Linear interpolation:_ Linear interpolation is designed to interpolate intensive quantities (e.g. temperature) from one coordinate to another. This method is suitable when the target coordinate is monotonically increasing or decreasing and the data variable is intensive. For example, you want to visualize oxygen on density surfaces from a z-coordinate ocean model.\n", " - _Logarithmic interpolation:_ Logarithmic interpolation (which is linear interpolation done after applying a logarithm to the target coordinate) is also available. This method is suitable when variation of the intensive quantity is best related to the logarithm of the target coordinate, rather than the target coordinate itself. For example, you want to analyze data from a sigma-coordinate atmospheric model on isobaric (constant pressure) surfaces.\n", "- _Conservative remapping:_ This algorithm is designed to conserve extensive quantities (e.g. transport, heat content). It requires knowledge of cell bounds in both the source and target coordinate. It also handles non-monotonic target coordinates.\n", "\n", "On this page, we explain how to use these coordinate transformation capabilities." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from xgcm import Grid\n", "import xarray as xr\n", "import numpy as np\n", "import matplotlib.pyplot as plt" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1D Toy Data Example\n", "\n", "First we will create a simple, one-dimensional dataset to illustrate how the `transform` function works.\n", "This dataset contains\n", "\n", "- a coordinate called `z`, representing the original depth coordinate\n", "\n", "- a data variable called `theta`, a function of `z`, which we want as our new vertical coordinate\n", "\n", "- a data variable called `phi`, also a function of `z`, which represents the data we want to transform into this new coordinate space\n", "\n", "In an oceanic context `theta` might be density and `phi` might be oxygen.\n", "In an atmospheric context, `theta` might be potential temperature and `phi` might be potential vorticity." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "
```<xarray.Dataset>\n",
"Dimensions:  (z: 10)\n",
"Coordinates:\n",
"  * z        (z) int64 2 3 4 5 6 7 8 9 10 11\n",
"Data variables:\n",
"    phi      (z) float64 1.633 1.165 1.233 1.637 ... 1.657 1.358 1.423 1.133\n",
"    theta    (z) float64 0.6931 1.099 1.386 1.609 ... 2.079 2.197 2.303 2.398```