Skip to content

Commit 118cb1b

Browse files
authored
daylight_fao56 (#115)
1 parent e46046b commit 118cb1b

8 files changed

+296
-110
lines changed

.pre-commit-config.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ repos:
1414
- id: ruff-format
1515
types_or: [ python, pyi, jupyter ]
1616

17-
- repo: https://github.com/PyCQA/docformatter # To format the doc strings to conform PEP257
18-
rev: v1.7.5
19-
hooks:
20-
- id: docformatter
21-
args: [--in-place]
17+
#- repo: https://github.com/PyCQA/docformatter # To format the doc strings to conform PEP257
18+
# rev: v1.7.5
19+
# hooks:
20+
# - id: docformatter
21+
# args: [--in-place]
2222

2323
- repo: https://github.com/codespell-project/codespell
2424
rev: v2.3.0

ncl/ncl_entries/dewtemp.ipynb

-101
This file was deleted.

ncl/ncl_entries/meteorology.ipynb

+171
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Meteorology"
8+
]
9+
},
10+
{
11+
"cell_type": "markdown",
12+
"metadata": {},
13+
"source": [
14+
"## Overview\n",
15+
"\n",
16+
"This section covers meteorology functions from NCL:\n",
17+
"\n",
18+
"- [dewtemp_trh](https://www.ncl.ucar.edu/Document/Functions/Built-in/dewtemp_trh.shtml)\n",
19+
"- [daylight_fao56](https://www.ncl.ucar.edu/Document/Functions/Crop/daylight_fao56.shtml)"
20+
]
21+
},
22+
{
23+
"cell_type": "markdown",
24+
"metadata": {},
25+
"source": [
26+
"## dewtemp_trh\n",
27+
"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",
28+
"\n",
29+
"<div class=\"admonition alert alert-info\">\n",
30+
" <p class=\"admonition-title\" style=\"font-weight:bold\">Important Note</p>\n",
31+
" To convert from Kelvin to Celsius <code>-273.15</code> and to convert from Celsius to Kelvin <code>+273.15</code>\n",
32+
"</div>"
33+
]
34+
},
35+
{
36+
"cell_type": "markdown",
37+
"metadata": {},
38+
"source": [
39+
"### Grab and Go"
40+
]
41+
},
42+
{
43+
"cell_type": "code",
44+
"execution_count": null,
45+
"metadata": {},
46+
"outputs": [],
47+
"source": [
48+
"# Input: Single Value\n",
49+
"from geocat.comp import dewtemp\n",
50+
"\n",
51+
"temp_c = 18 # Celsius\n",
52+
"relative_humidity = 46.5 # %\n",
53+
"\n",
54+
"dewtemp(temp_c + 273.15, relative_humidity) - 273.15 # Returns in Celsius"
55+
]
56+
},
57+
{
58+
"cell_type": "code",
59+
"execution_count": null,
60+
"metadata": {},
61+
"outputs": [],
62+
"source": [
63+
"# Input: List/Array\n",
64+
"from geocat.comp import dewtemp\n",
65+
"\n",
66+
"temp_kelvin = [291.15, 274.14, 360.3, 314] # Kelvin\n",
67+
"relative_humidity = [46.5, 5, 96.5, 1] # %\n",
68+
"\n",
69+
"dewtemp(temp_kelvin, relative_humidity) - 273.15 # Returns in Celsius"
70+
]
71+
},
72+
{
73+
"cell_type": "markdown",
74+
"metadata": {},
75+
"source": [
76+
"## daylight_fao56\n",
77+
"\n",
78+
"NCL's `daylight_fao56` calculates the 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`"
79+
]
80+
},
81+
{
82+
"cell_type": "markdown",
83+
"metadata": {},
84+
"source": [
85+
"### Grab and Go"
86+
]
87+
},
88+
{
89+
"cell_type": "code",
90+
"execution_count": null,
91+
"metadata": {},
92+
"outputs": [],
93+
"source": [
94+
"# Input: Single Value\n",
95+
"from geocat.comp import max_daylight\n",
96+
"\n",
97+
"day_of_year = 246 # Sept. 3\n",
98+
"latitude = -20 # 20 Degrees South\n",
99+
"\n",
100+
"max_daylight(day_of_year, latitude)"
101+
]
102+
},
103+
{
104+
"cell_type": "code",
105+
"execution_count": null,
106+
"metadata": {},
107+
"outputs": [],
108+
"source": [
109+
"# Input: List/Array\n",
110+
"from geocat.comp import max_daylight\n",
111+
"\n",
112+
"# Spring Equinox (March 20), Summer Solstice (June 20), Autumn Equinox (Sept. 22), Winter Solstice (Dec. 21)\n",
113+
"days_of_year = [79, 171, 265, 355]\n",
114+
"latitudes = 40 # Boulder\n",
115+
"\n",
116+
"max_daylight(days_of_year, latitudes)"
117+
]
118+
},
119+
{
120+
"cell_type": "markdown",
121+
"metadata": {},
122+
"source": [
123+
"---"
124+
]
125+
},
126+
{
127+
"cell_type": "markdown",
128+
"metadata": {},
129+
"source": [
130+
"## Python Resources\n",
131+
"- [GeoCAT-comp `dewtemp` documentation](https://geocat-comp.readthedocs.io/en/latest/user_api/generated/geocat.comp.meteorology.dewtemp.html)\n",
132+
"- [Convert between different temperature scales in SciPy](https://docs.scipy.org/doc/scipy/reference/generated/scipy.constants.convert_temperature.html)\n",
133+
"- [GeoCAT-comp `max_daylight` Documentation](https://geocat-comp.readthedocs.io/en/latest/user_api/generated/geocat.comp.meteorology.max_daylight.html)\n",
134+
"\n",
135+
"## Additional Reading\n",
136+
"- [NOAA: Dew Point vs. Humidity](https://www.weather.gov/arx/why_dewpoint_vs_humidity)"
137+
]
138+
},
139+
{
140+
"cell_type": "markdown",
141+
"metadata": {},
142+
"source": [
143+
"## References:\n",
144+
"\n",
145+
"```{footbibliography}\n",
146+
"```"
147+
]
148+
}
149+
],
150+
"metadata": {
151+
"kernelspec": {
152+
"display_name": "Python 3 (ipykernel)",
153+
"language": "python",
154+
"name": "python3"
155+
},
156+
"language_info": {
157+
"codemirror_mode": {
158+
"name": "ipython",
159+
"version": 3
160+
},
161+
"file_extension": ".py",
162+
"mimetype": "text/x-python",
163+
"name": "python",
164+
"nbconvert_exporter": "python",
165+
"pygments_lexer": "ipython3",
166+
"version": "3.11.8"
167+
}
168+
},
169+
"nbformat": 4,
170+
"nbformat_minor": 4
171+
}

ncl/ncl_entries/ncl_entries.rst

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

1717
Dates and Times

ncl/ncl_index/ncl-index-table.csv

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,5 @@ 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>`__
46+
`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>`__
47+
`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>`__

ncl/ncl_raw/daylight_fao56.ncl

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
; daylight_fao56
2+
; Adapted from https://www.ncl.ucar.edu/Document/Functions/Crop/daylight_fao56.shtml
3+
4+
; ncl -n daylight_fao56.ncl >> daylight_fao56_output.txt
5+
6+
print("DOY, Latitude (Degrees), Daylight Hours")
7+
do doy=0,365
8+
do lat=-66,66
9+
begin
10+
daylight_hours = daylight_fao56(doy, lat)
11+
print (doy +","+ lat +","+ daylight_hours)
12+
end
13+
end do
14+
end do

0 commit comments

Comments
 (0)