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

daylight_fao56 #115

Merged
merged 17 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
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: 0 additions & 101 deletions ncl/ncl_entries/dewtemp.ipynb

This file was deleted.

209 changes: 209 additions & 0 deletions ncl/ncl_entries/meteorology.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Meteorology"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Overview\n",
"\n",
"This section covers meteorology functions from NCL:\n",
"\n",
"- [dewtemp_trh](https://www.ncl.ucar.edu/Document/Functions/Built-in/dewtemp_trh.shtml)\n",
"- [daylight_fao56](https://www.ncl.ucar.edu/Document/Functions/Crop/daylight_fao56.shtml)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## dewtemp_trh\n",
"NCL's `dewtemp_trh` 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",
" <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"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"6.298141316024157"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"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": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 6.29814132, -35.12955277, 86.22114845, -27.40981025])"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"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"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## daylight_fao56\n",
"\n",
"NCL's `daylight_fao56` calculate maximum number of daylight hours as described in the Food and Agriculture Organization (FAO) Irrigation and Drainage Paper 56 [(Chapter 3, Equation 34)](https://www.fao.org/4/X0490E/x0490e07.htm#chapter%203%20%20%20meteorological%20data) {footcite}`allan_fao_1998`"
cyschneck marked this conversation as resolved.
Show resolved Hide resolved
cyschneck marked this conversation as resolved.
Show resolved Hide resolved
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Grab and Go"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
cyschneck marked this conversation as resolved.
Show resolved Hide resolved
{
"data": {
"text/plain": [
"array([[11.66559195]])"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Input: Single Value\n",
"from geocat.comp.meteorology import max_daylight\n",
cyschneck marked this conversation as resolved.
Show resolved Hide resolved
"\n",
"day_of_year = 246 # Sept. 3\n",
"latitude = -20 # 20 Degrees South\n",
"\n",
"max_daylight(day_of_year, latitude)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[11.92114937],\n",
" [14.84320154],\n",
" [11.92090136],\n",
" [ 9.15643116]])"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Input: List/Array\n",
"from geocat.comp.meteorology import max_daylight\n",
cyschneck marked this conversation as resolved.
Show resolved Hide resolved
"\n",
"# Spring Equinox (March 20), Summer Solstice (June 20), Autumn Equinox (Sept. 22), Winter Solstice (Dec. 21)\n",
"days_of_year = [79, 171, 265, 355]\n",
"latitudes = 40 # Boulder\n",
"\n",
"max_daylight(days_of_year, latitudes)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"---"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Python Resources\n",
"- [GeoCAT-comp dewtemp Documentation](https://geocat-comp.readthedocs.io/en/latest/user_api/generated/geocat.comp.meteorology.dewtemp.html)\n",
cyschneck marked this conversation as resolved.
Show resolved Hide resolved
"- [Convert between different temperature scales in SciPy](https://docs.scipy.org/doc/scipy/reference/generated/scipy.constants.convert_temperature.html)\n",
"- [GeoCAT-comp daylight Documentation](https://www.ncl.ucar.edu/Document/Functions/Crop/daylight_fao56.shtml)\n",
cyschneck marked this conversation as resolved.
Show resolved Hide resolved
"\n",
"## Additional Reading\n",
"- [NOAA: Dew Point vs. Humidity](https://www.weather.gov/arx/why_dewpoint_vs_humidity)\n",
"- [Crop evapotranspiration - Guidelines for computing crop water requirements - FAO Irrigation and drainage paper 56](https://www.fao.org/4/X0490E/x0490e00.htm#Contents)"
cyschneck marked this conversation as resolved.
Show resolved Hide resolved
]
}
],
"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
}
2 changes: 1 addition & 1 deletion ncl/ncl_entries/ncl_entries.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Data Analysis
climatology_functions.ipynb
trigonometric_functions.ipynb
general_applied_math.ipynb
dewtemp.ipynb
meteorology.ipynb
specx_specxy_anal.ipynb

Dates and Times
Expand Down
3 changes: 2 additions & 1 deletion ncl/ncl_index/ncl-index-table.csv
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ 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>`__
`daylight_fao56 <https://www.ncl.ucar.edu/Document/Functions/Crop/daylight_fao56.shtml>`__," Compute maximum number of daylight hours as described in FAO 56","``geocat.comp.meteorology.max_daylight()``",`example notebook <../ncl_entries/meteorology.ipynb#daylight-fao56>`__
`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/meteorology.ipynb#dewtemp-trh>`__
14 changes: 14 additions & 0 deletions ncl/ncl_raw/daylight_fao56.ncl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
; daylight_fao56
; Adapted from https://www.ncl.ucar.edu/Document/Functions/Crop/daylight_fao56.shtml

; ncl -n daylight_fao56.ncl >> daylight_fao56_output.txt

print("DOY, Latitude (Degrees), Daylight Hours")
do doy=0,365
do lat=-66,66
begin
daylight_hours = daylight_fao56(doy, lat)
print (doy +","+ lat +","+ daylight_hours)
end
end do
end do
Loading