Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dewtemp_trh #101

Merged
merged 31 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
ae89d49
dewtemp_trh entry
cyschneck Aug 26, 2024
9545b31
Merge branch 'dewtemp_100' of https://github.com/cyschneck/geocat-app…
cyschneck Aug 26, 2024
56e2982
add to NCL Applications sidebar
cyschneck Aug 26, 2024
bb450a8
single/array input
cyschneck Aug 27, 2024
26f2c71
Merge branch 'NCAR:main' into dewtemp_100
cyschneck Aug 27, 2024
84bc121
collect dewtemp from datafiles
cyschneck Aug 30, 2024
32ac550
Merge branch 'main' into dewtemp_100
cyschneck Aug 30, 2024
37ec397
remove env change
cyschneck Aug 30, 2024
2397ad3
remove gc from env
cyschneck Aug 30, 2024
f5b768c
Merge branch 'main' into dewtemp_100
cyschneck Aug 30, 2024
94d8272
remove redundant print
cyschneck Aug 30, 2024
6ef5c5a
Merge branch 'main' into dewtemp_100
cyschneck Sep 3, 2024
8c14267
Merge branch 'main' into dewtemp_100
cyschneck Sep 3, 2024
c70bbd0
Merge branch 'main' into dewtemp_100
cyschneck Sep 3, 2024
0c01ee7
consistent import, fix ncl_raw
cyschneck Sep 3, 2024
9cf166a
Update ncl/ncl_entries/dewtemp.ipynb
cyschneck Sep 3, 2024
79b83ae
pr edits
cyschneck Sep 3, 2024
10b1f9b
{important} syntax
cyschneck Sep 4, 2024
e217890
Merge branch 'main' into dewtemp_100
cyschneck Sep 5, 2024
b2d8e52
Update ncl/ncl_entries/dewtemp.ipynb
cyschneck Sep 17, 2024
ebd7e9a
Update ncl/ncl_entries/dewtemp.ipynb
cyschneck Sep 17, 2024
8fd0d74
Merge branch 'main' into dewtemp_100
cyschneck Sep 17, 2024
4155cba
remove kelvin as variable
cyschneck Sep 17, 2024
d649234
Merge branch 'main' into dewtemp_100
cyschneck Sep 25, 2024
f9fc52a
Update ncl/ncl_index/ncl-index-table.csv
cyschneck Sep 26, 2024
b7a43a4
Update ncl/ncl_entries/dewtemp.ipynb
cyschneck Sep 26, 2024
22c7c1f
Update ncl/ncl_entries/dewtemp.ipynb
cyschneck Sep 26, 2024
fd00698
remove output, update info note
cyschneck Sep 26, 2024
e272322
Merge branch 'main' into dewtemp_100
cyschneck Oct 7, 2024
f4be3a6
add dutton citation
cyschneck Oct 7, 2024
d2ef995
Merge branch 'main' into dewtemp_100
cyschneck Oct 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions ncl/ncl_entries/dewtemp.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# dewtemp_trh"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Overview\n",
"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",
"\n",
"<div class=\"admonition alert alert-info\">\n",
cyschneck marked this conversation as resolved.
Show resolved Hide resolved
" <p class=\"admonition-title\" style=\"font-weight:bold\">Important Note</p>\n",
" To convert from Kelvin to Celsius <code>-273.15</code> and to convert from Celsius to Kelvin <code>+273.15</code>\n",
"</div>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Grab and Go"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering if we want to keep the "Grab and Go" label if all of the code is within this section. I interpreted it more as a way to differentiate the fast code from the minutiae - but this notebook is very streamlined.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point, I think it is currently worth keeping for consistency with the templates and in this case, I was planning on seeing if any other meteorology functions were short enough to put in one notebook with this one (i.e. daylight)

]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Input: Single Value\n",
"from geocat.comp import dewtemp\n",
"\n",
"temp_c = 18 # Celsius\n",
"relative_humidity = 46.5 # %\n",
"\n",
"dewtemp(temp_c + 273.15, relative_humidity) - 273.15 # Returns in Celsius"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Input: List/Array\n",
"from geocat.comp import dewtemp\n",
"\n",
"temp_kelvin = [291.15, 274.14, 360.3, 314] # Kelvin\n",
"relative_humidity = [46.5, 5, 96.5, 1] # %\n",
"\n",
"dewtemp(temp_kelvin, relative_humidity) - 273.15 # Returns in Celsius"
cyschneck marked this conversation as resolved.
Show resolved Hide resolved
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"---"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Python Resources\n",
"- [GeoCAT-comp Documentation](https://geocat-comp.readthedocs.io/en/latest/user_api/generated/geocat.comp.meteorology.dewtemp.html)\n",
"- [Convert between different temperature scales in SciPy](https://docs.scipy.org/doc/scipy/reference/generated/scipy.constants.convert_temperature.html)\n",
"\n",
"## Additional Reading\n",
"- [NOAA: Dew Point vs. Humidity](https://www.weather.gov/arx/why_dewpoint_vs_humidity)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
1 change: 1 addition & 0 deletions ncl/ncl_entries/ncl_entries.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Data Analysis
climatology_functions.ipynb
trigonometric_functions.ipynb
general_applied_math.ipynb
dewtemp.ipynb
cyschneck marked this conversation as resolved.
Show resolved Hide resolved
specx_specxy_anal.ipynb

Dates and Times
Expand Down
1 change: 1 addition & 0 deletions ncl/ncl_index/ncl-index-table.csv
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ NCL Function,Description,Python Equivalent,Notes
`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>`__
`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>`__
`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>`__
`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>`__
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this point to the NCL receipt notebook?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually none of them do, so I'm pretty sure this is correct as is. Are NCL receipts only visible from the GitHub repository (for those really LOOKING for them)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can get to the receipts from the website, though it's not obvious.

If you scroll down to the end of the NCL index, there's a link to the receipts page

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh I think I used to see it was there when the table was shorter, but now that it's so long we might want a better solution (of course not in this PR).

14 changes: 14 additions & 0 deletions ncl/ncl_raw/dewtemp_trh.ncl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
; dewtemp_trh
; Adapted from https://www.ncl.ucar.edu/Document/Functions/Built-in/dewtemp_trh.shtml

; ncl -n dewtemp_trh.ncl >> dewtemp_trh_output.txt

print("Temperature (K), Relative Humidity (%), Dew Temperature (C)")
do tk=273,374
do rh=1,100
begin
dewtemp = dewtemp_trh(tk,rh)-273.15
print (tk +","+ rh +","+ dewtemp)
end
end do
end do
161 changes: 161 additions & 0 deletions ncl/receipts/dewtemp_trh.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "e6eddaf181eacfd3",
"metadata": {},
"source": [
"# dewtemp_trh"
]
},
{
"cell_type": "markdown",
"id": "e6be6389ef38b00b",
"metadata": {},
"source": [
"```{warning} This is not meant to be a standalone notebook.\n",
"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",
"```"
]
},
{
"cell_type": "markdown",
"id": "536ffded4355d9c6",
"metadata": {},
"source": [
"## Functions covered\n",
"- [dewtemp_trh](https://www.ncl.ucar.edu/Document/Functions/Built-in/dewtemp_trh.shtml)"
]
},
{
"cell_type": "markdown",
"id": "4a129c971c083695",
"metadata": {},
"source": [
"## NCL code"
]
},
{
"cell_type": "markdown",
"id": "3d70616a8934f0fb",
"metadata": {},
"source": [
"```{literalinclude} ../ncl_raw/dewtemp_trh.ncl\n",
"\n",
"```"
]
},
{
"cell_type": "markdown",
"id": "d918dec004b6456b",
"metadata": {},
"source": [
"## Python Functionality"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7af6f81c-2498-4aea-b250-579ec3fd31c8",
"metadata": {},
"outputs": [],
"source": [
"#### Collect NCL values for dewtemp_trh from geocat-datafiles\n",
"import geocat.datafiles as gdf\n",
"import numpy as np\n",
"\n",
"dewtemp_data = gdf.get('applications_files/ncl_outputs/dewtemp_trh_output.txt')\n",
"dewtemp_data = np.loadtxt(dewtemp_data, delimiter=',', skiprows=6)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3166c583-1290-4300-b96b-beab81cd033d",
"metadata": {},
"outputs": [],
"source": [
"### Collect NCL `dewtemp` value and associated (temperature_kelvin, relative humidity) values\n",
"ncl_dewtemp = {}\n",
"tk_rh = tuple(map(tuple, dewtemp_data[::, 0:2]))\n",
"dewtemp_values = dewtemp_data[::, 2]\n",
"ncl_dewtemp = dict(zip(tk_rh, dewtemp_values))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "39fd494c-609b-4dd0-83fd-b08d0daf6aaa",
"metadata": {},
"outputs": [],
"source": [
"### Collect Temperature (Kelvin) and Relative Humidity Pairs\n",
"tk_rh = []\n",
"for tk in range(273, 374 + 1):\n",
" for rh in range(1, 100 + 1):\n",
" tk_rh.append((tk, rh))\n",
"\n",
"### Calculate GeoCAT-Comp `dewtemp` value and tk/rh\n",
"from geocat.comp import dewtemp\n",
"\n",
"geocat_dewtemp = {}\n",
"\n",
"for i, pair in enumerate(tk_rh):\n",
" tk, rh = pair\n",
" geocat_dewtemp[pair] = dewtemp(tk, rh) - 273.15"
]
},
{
"cell_type": "markdown",
"id": "3237a0bffc6827fc",
"metadata": {},
"source": [
"## Comparison"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "74362fd9-0e9f-4cf9-91da-08cd81be625c",
"metadata": {},
"outputs": [],
"source": [
"import math\n",
"\n",
"for pair in ncl_dewtemp.keys():\n",
" try:\n",
" assert math.isclose(\n",
" ncl_dewtemp[pair], geocat_dewtemp[pair], rel_tol=1e-04\n",
" ) # within 4 decimal points\n",
" except Exception:\n",
" assert math.isclose(\n",
" ncl_dewtemp[pair], geocat_dewtemp[pair], rel_tol=1e-02\n",
" ) # within 2 decimal points\n",
" print(f\"{pair}:\")\n",
" print(f\"\\t{ncl_dewtemp[pair]}, {geocat_dewtemp[pair]}\")\n",
" print(f\"\\tDifference: {ncl_dewtemp[pair] - geocat_dewtemp[pair]}\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
8 changes: 8 additions & 0 deletions references.bib
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,11 @@ @book{monteith_2008
year = {2008},
publisher = {Academic Press}
}

@book{dutton_1986,
author = {John A. Dutton},
title = {The Ceaseless Wind: An Introduction to the Theory of Atmospheric Motion},
year = {1986},
pages={273-274},
publisher = {Dover Publications}
}