diff --git a/docs/source/examples/index.md b/docs/source/examples/index.md index 5cd18d9d..bc9eee1a 100644 --- a/docs/source/examples/index.md +++ b/docs/source/examples/index.md @@ -11,4 +11,5 @@ lateral-fill-idealized.ipynb lateral-fill-model-grid.ipynb pop_div_curl_xr_xgcm_metrics_compare.ipynb CloseHeatBudget_POP2.ipynb +xoak-example.ipynb ``` diff --git a/docs/source/examples/xoak-example.ipynb b/docs/source/examples/xoak-example.ipynb new file mode 100644 index 00000000..6fc1fd88 --- /dev/null +++ b/docs/source/examples/xoak-example.ipynb @@ -0,0 +1,2496 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "buried-texas", + "metadata": {}, + "source": [ + "# Nearest-neighbour indexing using xoak\n", + "\n", + "This notebook experiments subsetting datasets using `TLONG, TLAT, ULONG, ULAT` by making use of the [xoak](https://xoak.readthedocs.io/en/latest/) package" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "id": "hungarian-switzerland", + "metadata": {}, + "outputs": [], + "source": [ + "import matplotlib as mpl\n", + "import numpy as np\n", + "import xarray as xr\n", + "import xoak\n", + "\n", + "import pop_tools" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "hybrid-senator", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
<xarray.Dataset>\n", + "Dimensions: (bnds: 2, nlat: 305, nlon: 1301, time: 1, z_t: 62, z_t_150m: 15, z_w: 62, z_w_bot: 62, z_w_top: 62)\n", + "Coordinates:\n", + " * time (time) object 0036-12-07 00:00:00\n", + " TLONG (nlat, nlon) float64 ...\n", + " ULAT (nlat, nlon) float64 ...\n", + " * z_t (z_t) float32 500.0 1.5e+03 ... 5.625e+05 5.875e+05\n", + " TLAT (nlat, nlon) float64 ...\n", + " ULONG (nlat, nlon) float64 ...\n", + " * z_t_150m (z_t_150m) float32 500.0 1.5e+03 ... 1.35e+04 1.45e+04\n", + " * z_w (z_w) float32 0.0 1e+03 2e+03 ... 5.5e+05 5.75e+05\n", + " * z_w_bot (z_w_bot) float32 1e+03 2e+03 3e+03 ... 5.75e+05 6e+05\n", + " * z_w_top (z_w_top) float32 0.0 1e+03 2e+03 ... 5.5e+05 5.75e+05\n", + "Dimensions without coordinates: bnds, nlat, nlon\n", + "Data variables: (12/32)\n", + " time_bnds (time, bnds) object 0036-12-02 00:00:00 0036-12-07 00:...\n", + " UAREA (nlat, nlon) float64 ...\n", + " TAREA (nlat, nlon) float64 ...\n", + " DXU (nlat, nlon) float64 ...\n", + " DYU (nlat, nlon) float64 ...\n", + " DXT (nlat, nlon) float64 ...\n", + " ... ...\n", + " dzw (z_w) float32 500.0 1e+03 1e+03 ... 2.5e+04 2.5e+04\n", + " grav float64 980.6\n", + " nsurface_t float64 5.413e+06\n", + " nsurface_u float64 5.372e+06\n", + " omega float64 7.292e-05\n", + " radius float64 6.371e+08\n", + "Attributes: (12/13)\n", + " CDI: Climate Data Interface version 1.9.2 (http://mpimet.mp...\n", + " history: Tue Mar 24 11:51:32 2020: cdo selvar,UVEL,VVEL,DXT,DXU...\n", + " source: CCSM POP2, the CCSM Ocean Component\n", + " Conventions: CF-1.0; http://www.cgd.ucar.edu/cms/eaton/netcdf/CF-cu...\n", + " title: g.e20.G.TL319_t13.control.001_hfreq\n", + " time_period_freq: day_5\n", + " ... ...\n", + " contents: Diagnostic and Prognostic Variables\n", + " revision: $Id: tavg.F90 89091 2018-04-30 15:58:32Z altuntas@ucar...\n", + " calendar: All years have exactly 365 days.\n", + " start_time: This dataset was created on 2018-12-14 at 16:05:58.8\n", + " cell_methods: cell_methods = time: mean ==> the variable values are ...\n", + " CDO: Climate Data Operators version 1.9.2 (http://mpimet.mp...
array([cftime.DatetimeNoLeap(36, 12, 7, 0, 0, 0, 0)], dtype=object)
[396805 values with dtype=float64]
[396805 values with dtype=float64]
array([5.000000e+02, 1.500000e+03, 2.500000e+03, 3.500000e+03, 4.500000e+03,\n", + " 5.500000e+03, 6.500000e+03, 7.500000e+03, 8.500000e+03, 9.500000e+03,\n", + " 1.050000e+04, 1.150000e+04, 1.250000e+04, 1.350000e+04, 1.450000e+04,\n", + " 1.550000e+04, 1.650984e+04, 1.754790e+04, 1.862913e+04, 1.976603e+04,\n", + " 2.097114e+04, 2.225783e+04, 2.364088e+04, 2.513702e+04, 2.676542e+04,\n", + " 2.854837e+04, 3.051192e+04, 3.268680e+04, 3.510935e+04, 3.782276e+04,\n", + " 4.087846e+04, 4.433777e+04, 4.827367e+04, 5.277280e+04, 5.793729e+04,\n", + " 6.388626e+04, 7.075633e+04, 7.870025e+04, 8.788252e+04, 9.847059e+04,\n", + " 1.106204e+05, 1.244567e+05, 1.400497e+05, 1.573946e+05, 1.764003e+05,\n", + " 1.968944e+05, 2.186457e+05, 2.413972e+05, 2.649001e+05, 2.889385e+05,\n", + " 3.133405e+05, 3.379793e+05, 3.627670e+05, 3.876452e+05, 4.125768e+05,\n", + " 4.375392e+05, 4.625190e+05, 4.875083e+05, 5.125028e+05, 5.375000e+05,\n", + " 5.624991e+05, 5.874991e+05], dtype=float32)
[396805 values with dtype=float64]
[396805 values with dtype=float64]
array([ 500., 1500., 2500., 3500., 4500., 5500., 6500., 7500., 8500.,\n", + " 9500., 10500., 11500., 12500., 13500., 14500.], dtype=float32)
array([ 0. , 1000. , 2000. , 3000. , 4000. , 5000. ,\n", + " 6000. , 7000. , 8000. , 9000. , 10000. , 11000. ,\n", + " 12000. , 13000. , 14000. , 15000. , 16000. , 17019.682,\n", + " 18076.129, 19182.125, 20349.932, 21592.344, 22923.312, 24358.453,\n", + " 25915.58 , 27615.26 , 29481.47 , 31542.373, 33831.227, 36387.473,\n", + " 39258.047, 42498.887, 46176.656, 50370.688, 55174.91 , 60699.668,\n", + " 67072.86 , 74439.805, 82960.695, 92804.35 , 104136.82 , 117104.016,\n", + " 131809.36 , 148290.08 , 166499.2 , 186301.44 , 207487.39 , 229803.9 ,\n", + " 252990.4 , 276809.84 , 301067.06 , 325613.84 , 350344.88 , 375189.2 ,\n", + " 400101.16 , 425052.47 , 450026.06 , 475012. , 500004.7 , 525000.94 ,\n", + " 549999.06 , 574999.06 ], dtype=float32)
array([ 1000. , 2000. , 3000. , 4000. , 5000. , 6000. ,\n", + " 7000. , 8000. , 9000. , 10000. , 11000. , 12000. ,\n", + " 13000. , 14000. , 15000. , 16000. , 17019.682, 18076.129,\n", + " 19182.125, 20349.932, 21592.344, 22923.312, 24358.453, 25915.58 ,\n", + " 27615.26 , 29481.47 , 31542.373, 33831.227, 36387.473, 39258.047,\n", + " 42498.887, 46176.656, 50370.688, 55174.91 , 60699.668, 67072.86 ,\n", + " 74439.805, 82960.695, 92804.35 , 104136.82 , 117104.016, 131809.36 ,\n", + " 148290.08 , 166499.2 , 186301.44 , 207487.39 , 229803.9 , 252990.4 ,\n", + " 276809.84 , 301067.06 , 325613.84 , 350344.88 , 375189.2 , 400101.16 ,\n", + " 425052.47 , 450026.06 , 475012. , 500004.7 , 525000.94 , 549999.06 ,\n", + " 574999.06 , 599999.06 ], dtype=float32)
array([ 0. , 1000. , 2000. , 3000. , 4000. , 5000. ,\n", + " 6000. , 7000. , 8000. , 9000. , 10000. , 11000. ,\n", + " 12000. , 13000. , 14000. , 15000. , 16000. , 17019.682,\n", + " 18076.129, 19182.125, 20349.932, 21592.344, 22923.312, 24358.453,\n", + " 25915.58 , 27615.26 , 29481.47 , 31542.373, 33831.227, 36387.473,\n", + " 39258.047, 42498.887, 46176.656, 50370.688, 55174.91 , 60699.668,\n", + " 67072.86 , 74439.805, 82960.695, 92804.35 , 104136.82 , 117104.016,\n", + " 131809.36 , 148290.08 , 166499.2 , 186301.44 , 207487.39 , 229803.9 ,\n", + " 252990.4 , 276809.84 , 301067.06 , 325613.84 , 350344.88 , 375189.2 ,\n", + " 400101.16 , 425052.47 , 450026.06 , 475012. , 500004.7 , 525000.94 ,\n", + " 549999.06 , 574999.06 ], dtype=float32)
array([[cftime.DatetimeNoLeap(36, 12, 2, 0, 0, 0, 0),\n", + " cftime.DatetimeNoLeap(36, 12, 7, 0, 0, 0, 0)]], dtype=object)
[396805 values with dtype=float64]
[396805 values with dtype=float64]
[396805 values with dtype=float64]
[396805 values with dtype=float64]
[396805 values with dtype=float64]
[396805 values with dtype=float64]
[24601910 values with dtype=float32]
[24601910 values with dtype=float32]
[24601910 values with dtype=float32]
[396805 values with dtype=float64]
[396805 values with dtype=float64]
[396805 values with dtype=float32]
[24601910 values with dtype=float32]
[24601910 values with dtype=float32]
[396805 values with dtype=float64]
[396805 values with dtype=float64]
[396805 values with dtype=float64]
[396805 values with dtype=float64]
[396805 values with dtype=float64]
[396805 values with dtype=float64]
[396805 values with dtype=float64]
[396805 values with dtype=float64]
[396805 values with dtype=float64]
array(31536000000000000, dtype='timedelta64[ns]')
array([ 1000. , 1000. , 1000. , 1000. , 1000. , 1000. ,\n", + " 1000. , 1000. , 1000. , 1000. , 1000. , 1000. ,\n", + " 1000. , 1000. , 1000. , 1000. , 1019.6808, 1056.4484,\n", + " 1105.9951, 1167.807 , 1242.4133, 1330.9678, 1435.141 , 1557.1259,\n", + " 1699.6796, 1866.2124, 2060.9023, 2288.852 , 2556.247 , 2870.575 ,\n", + " 3240.8372, 3677.7725, 4194.031 , 4804.2236, 5524.7544, 6373.192 ,\n", + " 7366.945 , 8520.893 , 9843.658 , 11332.466 , 12967.199 , 14705.344 ,\n", + " 16480.709 , 18209.135 , 19802.234 , 21185.957 , 22316.51 , 23186.494 ,\n", + " 23819.45 , 24257.217 , 24546.78 , 24731.014 , 24844.328 , 24911.975 ,\n", + " 24951.291 , 24973.594 , 24985.96 , 24992.674 , 24996.244 , 24998.11 ,\n", + " 25000. , 25000. ], dtype=float32)
array([ 500. , 1000. , 1000. , 1000. , 1000. , 1000. ,\n", + " 1000. , 1000. , 1000. , 1000. , 1000. , 1000. ,\n", + " 1000. , 1000. , 1000. , 1000. , 1009.8404, 1038.0646,\n", + " 1081.2218, 1136.901 , 1205.1101, 1286.6906, 1383.0544, 1496.1334,\n", + " 1628.4027, 1782.946 , 1963.5574, 2174.8772, 2422.5496, 2713.4111,\n", + " 3055.706 , 3459.305 , 3935.9016, 4499.1274, 5164.489 , 5948.973 ,\n", + " 6870.0684, 7943.9185, 9182.275 , 10588.062 , 12149.832 , 13836.271 ,\n", + " 15593.026 , 17344.922 , 19005.686 , 20494.096 , 21751.234 , 22751.502 ,\n", + " 23502.97 , 24038.332 , 24401.998 , 24638.896 , 24787.672 , 24878.15 ,\n", + " 24931.633 , 24962.443 , 24979.777 , 24989.316 , 24994.459 , 24997.176 ,\n", + " 24999.055 , 25000. ], dtype=float32)
array(980.616)
array(5413142.)
array(5371534.)
array(7.292124e-05)
array(6.37122e+08)
<xarray.DataArray (x: 2, time: 13)>\n", + "array([[ 1., 2., nan, 3., 4., 5., nan, nan, nan, 4., 6., nan, 2.],\n", + " [nan, 2., nan, nan, nan, 5., nan, nan, nan, 4., nan, nan, nan]])\n", + "Dimensions without coordinates: x, time
array([[ 1., 2., nan, 3., 4., 5., nan, nan, nan, 4., 6., nan, 2.],\n", + " [nan, 2., nan, nan, nan, 5., nan, nan, nan, 4., nan, nan, nan]])
<xarray.DataArray (x: 2, time: 13)>\n", + "array([[ 1., 3., 0., 3., 7., 12., 0., 0., 0., 4., 10., 0., 2.],\n", + " [ 0., 2., 0., 0., 0., 5., 0., 0., 0., 4., 0., 0., 0.]])\n", + "Dimensions without coordinates: x, time
array([[ 1., 3., 0., 3., 7., 12., 0., 0., 0., 4., 10., 0., 2.],\n", + " [ 0., 2., 0., 0., 0., 5., 0., 0., 0., 4., 0., 0., 0.]])
<xarray.DataArray (x: 2, time: 13)>\n", + "array([[ 1., 3., 0., 3., 7., 12., 0., 0., 0., 4., 10., 0., 2.],\n", + " [ 0., 2., 0., 0., 0., 5., 0., 0., 0., 4., 0., 0., 0.]])\n", + "Dimensions without coordinates: x, time
array([[ 1., 3., 0., 3., 7., 12., 0., 0., 0., 4., 10., 0., 2.],\n", + " [ 0., 2., 0., 0., 0., 5., 0., 0., 0., 4., 0., 0., 0.]])