|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "id": "e6eddaf181eacfd3", |
| 6 | + "metadata": {}, |
| 7 | + "source": [ |
| 8 | + "# dewtemp_trh" |
| 9 | + ] |
| 10 | + }, |
| 11 | + { |
| 12 | + "cell_type": "markdown", |
| 13 | + "id": "e6be6389ef38b00b", |
| 14 | + "metadata": {}, |
| 15 | + "source": [ |
| 16 | + "```{warning} This is not meant to be a standalone notebook.\n", |
| 17 | + "This notebook is part of the process we have for adding entries to the NCL Index and is not meant to be used as tutorial or example code.\n", |
| 18 | + "```" |
| 19 | + ] |
| 20 | + }, |
| 21 | + { |
| 22 | + "cell_type": "markdown", |
| 23 | + "id": "536ffded4355d9c6", |
| 24 | + "metadata": {}, |
| 25 | + "source": [ |
| 26 | + "## Functions covered\n", |
| 27 | + "- [dewtemp_trh](https://www.ncl.ucar.edu/Document/Functions/Built-in/dewtemp_trh.shtml)" |
| 28 | + ] |
| 29 | + }, |
| 30 | + { |
| 31 | + "cell_type": "markdown", |
| 32 | + "id": "4a129c971c083695", |
| 33 | + "metadata": {}, |
| 34 | + "source": [ |
| 35 | + "## NCL code" |
| 36 | + ] |
| 37 | + }, |
| 38 | + { |
| 39 | + "cell_type": "markdown", |
| 40 | + "id": "3d70616a8934f0fb", |
| 41 | + "metadata": {}, |
| 42 | + "source": [ |
| 43 | + "```{literalinclude} ../ncl_raw/dewtemp_trh.ncl\n", |
| 44 | + "\n", |
| 45 | + "```" |
| 46 | + ] |
| 47 | + }, |
| 48 | + { |
| 49 | + "cell_type": "markdown", |
| 50 | + "id": "d918dec004b6456b", |
| 51 | + "metadata": {}, |
| 52 | + "source": [ |
| 53 | + "## Python Functionality" |
| 54 | + ] |
| 55 | + }, |
| 56 | + { |
| 57 | + "cell_type": "code", |
| 58 | + "execution_count": null, |
| 59 | + "id": "7af6f81c-2498-4aea-b250-579ec3fd31c8", |
| 60 | + "metadata": {}, |
| 61 | + "outputs": [], |
| 62 | + "source": [ |
| 63 | + "#### Collect NCL values for dewtemp_trh from geocat-datafiles\n", |
| 64 | + "import geocat.datafiles as gdf\n", |
| 65 | + "import numpy as np\n", |
| 66 | + "\n", |
| 67 | + "dewtemp_data = gdf.get('applications_files/ncl_outputs/dewtemp_trh_output.txt')\n", |
| 68 | + "dewtemp_data = np.loadtxt(dewtemp_data, delimiter=',', skiprows=6)" |
| 69 | + ] |
| 70 | + }, |
| 71 | + { |
| 72 | + "cell_type": "code", |
| 73 | + "execution_count": null, |
| 74 | + "id": "3166c583-1290-4300-b96b-beab81cd033d", |
| 75 | + "metadata": {}, |
| 76 | + "outputs": [], |
| 77 | + "source": [ |
| 78 | + "### Collect NCL `dewtemp` value and associated (temperature_kelvin, relative humidity) values\n", |
| 79 | + "ncl_dewtemp = {}\n", |
| 80 | + "tk_rh = tuple(map(tuple, dewtemp_data[::, 0:2]))\n", |
| 81 | + "dewtemp_values = dewtemp_data[::, 2]\n", |
| 82 | + "ncl_dewtemp = dict(zip(tk_rh, dewtemp_values))" |
| 83 | + ] |
| 84 | + }, |
| 85 | + { |
| 86 | + "cell_type": "code", |
| 87 | + "execution_count": null, |
| 88 | + "id": "39fd494c-609b-4dd0-83fd-b08d0daf6aaa", |
| 89 | + "metadata": {}, |
| 90 | + "outputs": [], |
| 91 | + "source": [ |
| 92 | + "### Collect Temperature (Kelvin) and Relative Humidity Pairs\n", |
| 93 | + "tk_rh = []\n", |
| 94 | + "for tk in range(273, 374 + 1):\n", |
| 95 | + " for rh in range(1, 100 + 1):\n", |
| 96 | + " tk_rh.append((tk, rh))\n", |
| 97 | + "\n", |
| 98 | + "### Calculate GeoCAT-Comp `dewtemp` value and tk/rh\n", |
| 99 | + "from geocat.comp import dewtemp\n", |
| 100 | + "\n", |
| 101 | + "geocat_dewtemp = {}\n", |
| 102 | + "\n", |
| 103 | + "for i, pair in enumerate(tk_rh):\n", |
| 104 | + " tk, rh = pair\n", |
| 105 | + " geocat_dewtemp[pair] = dewtemp(tk, rh) - 273.15" |
| 106 | + ] |
| 107 | + }, |
| 108 | + { |
| 109 | + "cell_type": "markdown", |
| 110 | + "id": "3237a0bffc6827fc", |
| 111 | + "metadata": {}, |
| 112 | + "source": [ |
| 113 | + "## Comparison" |
| 114 | + ] |
| 115 | + }, |
| 116 | + { |
| 117 | + "cell_type": "code", |
| 118 | + "execution_count": null, |
| 119 | + "id": "74362fd9-0e9f-4cf9-91da-08cd81be625c", |
| 120 | + "metadata": {}, |
| 121 | + "outputs": [], |
| 122 | + "source": [ |
| 123 | + "import math\n", |
| 124 | + "\n", |
| 125 | + "for pair in ncl_dewtemp.keys():\n", |
| 126 | + " try:\n", |
| 127 | + " assert math.isclose(\n", |
| 128 | + " ncl_dewtemp[pair], geocat_dewtemp[pair], rel_tol=1e-04\n", |
| 129 | + " ) # within 4 decimal points\n", |
| 130 | + " except Exception:\n", |
| 131 | + " assert math.isclose(\n", |
| 132 | + " ncl_dewtemp[pair], geocat_dewtemp[pair], rel_tol=1e-02\n", |
| 133 | + " ) # within 2 decimal points\n", |
| 134 | + " print(f\"{pair}:\")\n", |
| 135 | + " print(f\"\\t{ncl_dewtemp[pair]}, {geocat_dewtemp[pair]}\")\n", |
| 136 | + " print(f\"\\tDifference: {ncl_dewtemp[pair] - geocat_dewtemp[pair]}\")" |
| 137 | + ] |
| 138 | + } |
| 139 | + ], |
| 140 | + "metadata": { |
| 141 | + "kernelspec": { |
| 142 | + "display_name": "Python 3 (ipykernel)", |
| 143 | + "language": "python", |
| 144 | + "name": "python3" |
| 145 | + }, |
| 146 | + "language_info": { |
| 147 | + "codemirror_mode": { |
| 148 | + "name": "ipython", |
| 149 | + "version": 3 |
| 150 | + }, |
| 151 | + "file_extension": ".py", |
| 152 | + "mimetype": "text/x-python", |
| 153 | + "name": "python", |
| 154 | + "nbconvert_exporter": "python", |
| 155 | + "pygments_lexer": "ipython3", |
| 156 | + "version": "3.11.8" |
| 157 | + } |
| 158 | + }, |
| 159 | + "nbformat": 4, |
| 160 | + "nbformat_minor": 5 |
| 161 | +} |
0 commit comments