Skip to content

Commit e46046b

Browse files
authored
dewtemp_trh (#101)
1 parent c751ded commit e46046b

File tree

6 files changed

+286
-0
lines changed

6 files changed

+286
-0
lines changed

ncl/ncl_entries/dewtemp.ipynb

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# dewtemp_trh"
8+
]
9+
},
10+
{
11+
"cell_type": "markdown",
12+
"metadata": {},
13+
"source": [
14+
"## Overview\n",
15+
"NCL's [`dewtemp_trh`](https://www.ncl.ucar.edu/Document/Functions/Built-in/dewtemp_trh.shtml) calculates the dew point temperature given temperature and relative humidity using the equations from John Dutton's _\"Ceaseless Wind\"_ (pg. 273-274){footcite}`dutton_1986` and returns a temperature in Kelvin.\n",
16+
"\n",
17+
"<div class=\"admonition alert alert-info\">\n",
18+
" <p class=\"admonition-title\" style=\"font-weight:bold\">Important Note</p>\n",
19+
" To convert from Kelvin to Celsius <code>-273.15</code> and to convert from Celsius to Kelvin <code>+273.15</code>\n",
20+
"</div>"
21+
]
22+
},
23+
{
24+
"cell_type": "markdown",
25+
"metadata": {},
26+
"source": [
27+
"## Grab and Go"
28+
]
29+
},
30+
{
31+
"cell_type": "code",
32+
"execution_count": null,
33+
"metadata": {},
34+
"outputs": [],
35+
"source": [
36+
"# Input: Single Value\n",
37+
"from geocat.comp import dewtemp\n",
38+
"\n",
39+
"temp_c = 18 # Celsius\n",
40+
"relative_humidity = 46.5 # %\n",
41+
"\n",
42+
"dewtemp(temp_c + 273.15, relative_humidity) - 273.15 # Returns in Celsius"
43+
]
44+
},
45+
{
46+
"cell_type": "code",
47+
"execution_count": null,
48+
"metadata": {},
49+
"outputs": [],
50+
"source": [
51+
"# Input: List/Array\n",
52+
"from geocat.comp import dewtemp\n",
53+
"\n",
54+
"temp_kelvin = [291.15, 274.14, 360.3, 314] # Kelvin\n",
55+
"relative_humidity = [46.5, 5, 96.5, 1] # %\n",
56+
"\n",
57+
"dewtemp(temp_kelvin, relative_humidity) - 273.15 # Returns in Celsius"
58+
]
59+
},
60+
{
61+
"cell_type": "markdown",
62+
"metadata": {},
63+
"source": [
64+
"---"
65+
]
66+
},
67+
{
68+
"cell_type": "markdown",
69+
"metadata": {},
70+
"source": [
71+
"## Python Resources\n",
72+
"- [GeoCAT-comp Documentation](https://geocat-comp.readthedocs.io/en/latest/user_api/generated/geocat.comp.meteorology.dewtemp.html)\n",
73+
"- [Convert between different temperature scales in SciPy](https://docs.scipy.org/doc/scipy/reference/generated/scipy.constants.convert_temperature.html)\n",
74+
"\n",
75+
"## Additional Reading\n",
76+
"- [NOAA: Dew Point vs. Humidity](https://www.weather.gov/arx/why_dewpoint_vs_humidity)"
77+
]
78+
}
79+
],
80+
"metadata": {
81+
"kernelspec": {
82+
"display_name": "Python 3 (ipykernel)",
83+
"language": "python",
84+
"name": "python3"
85+
},
86+
"language_info": {
87+
"codemirror_mode": {
88+
"name": "ipython",
89+
"version": 3
90+
},
91+
"file_extension": ".py",
92+
"mimetype": "text/x-python",
93+
"name": "python",
94+
"nbconvert_exporter": "python",
95+
"pygments_lexer": "ipython3",
96+
"version": "3.11.8"
97+
}
98+
},
99+
"nbformat": 4,
100+
"nbformat_minor": 4
101+
}

ncl/ncl_entries/ncl_entries.rst

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Data Analysis
1111
climatology_functions.ipynb
1212
trigonometric_functions.ipynb
1313
general_applied_math.ipynb
14+
dewtemp.ipynb
1415
specx_specxy_anal.ipynb
1516

1617
Dates and Times

ncl/ncl_index/ncl-index-table.csv

+1
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,4 @@ NCL Function,Description,Python Equivalent,Notes
4343
`sqrt <https://www.ncl.ucar.edu/Document/Functions/Built-in/sqrt.shtml>`__,"Computes the square root of its input","``math.sqrt()`` or ``numpy.sqrt()``",`example notebook <../ncl_entries/general_applied_math.ipynb#sqrt>`__
4444
`sign_matlab <https://www.ncl.ucar.edu/Document/Functions/Contributed/sign_matlab.shtml>`__,"Mimic the behavior of Matlab's sign function","``numpy.sign()``",`example notebook <../ncl_entries/general_applied_math.ipynb#sign-matlab>`__
4545
`round <https://www.ncl.ucar.edu/Document/Functions/Built-in/round.shtml>`__,"Rounds a float or double variable to the nearest whole number","``round()`` or ``numpy.round()``",`example notebook <../ncl_entries/general_applied_math.ipynb#decimalplaces-round>`__
46+
`dewtemp_trh <https://www.ncl.ucar.edu/Document/Functions/Built-in/dewtemp_trh.shtml>`__,"Calculates the dew point temperature given temperature and relative humidity","``geocat.comp.dewtemp()``",`example notebook <../ncl_entries/dewtemp.ipynb>`__

ncl/ncl_raw/dewtemp_trh.ncl

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
; dewtemp_trh
2+
; Adapted from https://www.ncl.ucar.edu/Document/Functions/Built-in/dewtemp_trh.shtml
3+
4+
; ncl -n dewtemp_trh.ncl >> dewtemp_trh_output.txt
5+
6+
print("Temperature (K), Relative Humidity (%), Dew Temperature (C)")
7+
do tk=273,374
8+
do rh=1,100
9+
begin
10+
dewtemp = dewtemp_trh(tk,rh)-273.15
11+
print (tk +","+ rh +","+ dewtemp)
12+
end
13+
end do
14+
end do

ncl/receipts/dewtemp_trh.ipynb

+161
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
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+
}

references.bib

+8
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,11 @@ @book{monteith_2008
107107
year = {2008},
108108
publisher = {Academic Press}
109109
}
110+
111+
@book{dutton_1986,
112+
author = {John A. Dutton},
113+
title = {The Ceaseless Wind: An Introduction to the Theory of Atmospheric Motion},
114+
year = {1986},
115+
pages={273-274},
116+
publisher = {Dover Publications}
117+
}

0 commit comments

Comments
 (0)