Skip to content

Commit 796b294

Browse files
authored
saturation_vapor_pressure (#154)
1 parent c5c85a6 commit 796b294

File tree

6 files changed

+190
-43
lines changed

6 files changed

+190
-43
lines changed

ncl/ncl_entries/meteorology.ipynb

+48-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"This section covers meteorology functions from NCL:\n",
1717
"\n",
1818
"- [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)"
19+
"- [daylight_fao56](https://www.ncl.ucar.edu/Document/Functions/Crop/daylight_fao56.shtml)\n",
20+
"- [satvpr_temp_fao56](https://www.ncl.ucar.edu/Document/Functions/Crop/satvpr_temp_fao56.shtml)"
2021
]
2122
},
2223
{
@@ -116,6 +117,50 @@
116117
"max_daylight(days_of_year, latitudes)"
117118
]
118119
},
120+
{
121+
"cell_type": "markdown",
122+
"metadata": {},
123+
"source": [
124+
"## satvpr_temp_fao56\n",
125+
"\n",
126+
"NCL's `satvpr_temp_fao56` calculates saturation vapor pressure using temperature as described in the Food and Agriculture Organization (FAO) Irrigation and Drainage Paper 56 [(Chapter 3, Equation 11)](https://www.fao.org/4/x0490e/x0490e07.htm) {footcite}`allan_fao_1998`"
127+
]
128+
},
129+
{
130+
"cell_type": "markdown",
131+
"metadata": {},
132+
"source": [
133+
"### Grab and Go"
134+
]
135+
},
136+
{
137+
"cell_type": "code",
138+
"execution_count": null,
139+
"metadata": {},
140+
"outputs": [],
141+
"source": [
142+
"# Input: Single Value\n",
143+
"from geocat.comp import saturation_vapor_pressure\n",
144+
"\n",
145+
"temp = 50 # Fahrenheit\n",
146+
"\n",
147+
"saturation_vapor_pressure(temp)"
148+
]
149+
},
150+
{
151+
"cell_type": "code",
152+
"execution_count": null,
153+
"metadata": {},
154+
"outputs": [],
155+
"source": [
156+
"# Input: List/Array\n",
157+
"from geocat.comp import saturation_vapor_pressure\n",
158+
"\n",
159+
"temp = [33, 50, 100, 212] # Fahrenheit\n",
160+
"\n",
161+
"saturation_vapor_pressure(temp)"
162+
]
163+
},
119164
{
120165
"cell_type": "markdown",
121166
"metadata": {},
@@ -131,6 +176,7 @@
131176
"- [GeoCAT-comp `dewtemp` documentation](https://geocat-comp.readthedocs.io/en/latest/user_api/generated/geocat.comp.meteorology.dewtemp.html)\n",
132177
"- [Convert between different temperature scales in SciPy](https://docs.scipy.org/doc/scipy/reference/generated/scipy.constants.convert_temperature.html)\n",
133178
"- [GeoCAT-comp `max_daylight` Documentation](https://geocat-comp.readthedocs.io/en/latest/user_api/generated/geocat.comp.meteorology.max_daylight.html)\n",
179+
"- [GeoCAT-comp `saturation_vapor_pressure` Documentation](https://geocat-comp.readthedocs.io/en/latest/user_api/generated/geocat.comp.meteorology.saturation_vapor_pressure.html)\n",
134180
"\n",
135181
"## Additional Reading\n",
136182
"- [NOAA: Dew Point vs. Humidity](https://www.weather.gov/arx/why_dewpoint_vs_humidity)"
@@ -163,7 +209,7 @@
163209
"name": "python",
164210
"nbconvert_exporter": "python",
165211
"pygments_lexer": "ipython3",
166-
"version": "3.11.8"
212+
"version": "3.12.7"
167213
}
168214
},
169215
"nbformat": 4,

ncl/ncl_index/ncl-index-table.csv

+1
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,4 @@ NCL Function,Description,Python Equivalent,Notes
4646
`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>`__
4747
`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>`__
4848
`area_poly_sphere <https://www.ncl.ucar.edu/Document/Functions/Built-in/area_poly_sphere.shtml>`__,"Calculates the area enclosed by an arbitrary polygon on the sphere","``pyproj.Geod()`` and ``shapely.geometry.polygon.Polygon()``",`example notebook <../ncl_entries/great_circle.ipynb#area-poly-sphere>`__
49+
`satvpr_temp_fao56 <https://www.ncl.ucar.edu/Document/Functions/Crop/satvpr_temp_fao56.shtml>`__," Compute saturation vapor pressure using temperature as described in FAO 56","``geocat.comp.saturation_vapor_pressure()``",`example notebook <../ncl_entries/meteorology.ipynb#satvpr-temp-fao56>`__

ncl/ncl_raw/daylight_fao56.ncl

-14
This file was deleted.

ncl/ncl_raw/dewtemp_trh.ncl

-14
This file was deleted.

ncl/ncl_raw/meteorology.ncl

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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
15+
16+
; dewtemp_trh
17+
; Adapted from https://www.ncl.ucar.edu/Document/Functions/Built-in/dewtemp_trh.shtml
18+
19+
; ncl -n dewtemp_trh.ncl >> dewtemp_trh_output.txt
20+
21+
print("Temperature (K), Relative Humidity (%), Dew Temperature (C)")
22+
do tk=273,374
23+
do rh=1,100
24+
begin
25+
dewtemp = dewtemp_trh(tk,rh)-273.15
26+
print (tk +","+ rh +","+ dewtemp)
27+
end
28+
end do
29+
end do
30+
31+
; satvpr_temp_fao56
32+
; Adapted from https://www.ncl.ucar.edu/Document/Functions/Crop/satvpr_temp_fao56.shtml
33+
34+
; ncl -n satvpr_temp_fao56.ncl >> satvpr_temp_fao56_output.txt
35+
36+
print("Temperature (F), Saturation Vapor Pressure (kPa)")
37+
do temp=33,212
38+
begin
39+
sat_vpr_pressure = satvpr_temp_fao56(temp, (/2, 2/))
40+
print (temp + "," + sat_vpr_pressure)
41+
end
42+
end do

ncl/receipts/meteorology.ipynb

+99-13
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"source": [
2626
"## Functions covered\n",
2727
"- [dewtemp_trh](https://www.ncl.ucar.edu/Document/Functions/Built-in/dewtemp_trh.shtml)\n",
28-
"- [daylight_fao56](https://www.ncl.ucar.edu/Document/Functions/Crop/daylight_fao56.shtml)"
28+
"- [daylight_fao56](https://www.ncl.ucar.edu/Document/Functions/Crop/daylight_fao56.shtml)\n",
29+
"- [satvpr_temp_fao56](https://www.ncl.ucar.edu/Document/Functions/Crop/satvpr_temp_fao56.shtml)"
2930
]
3031
},
3132
{
@@ -41,17 +42,7 @@
4142
"id": "3d70616a8934f0fb",
4243
"metadata": {},
4344
"source": [
44-
"```{literalinclude} ../ncl_raw/dewtemp_trh.ncl\n",
45-
"\n",
46-
"```"
47-
]
48-
},
49-
{
50-
"cell_type": "markdown",
51-
"id": "3b32a066-055f-454b-a843-e57dca954dad",
52-
"metadata": {},
53-
"source": [
54-
"```{literalinclude} ../ncl_raw/daylight_fao56.ncl\n",
45+
"```{literalinclude} ../ncl_raw/meteorology.ncl\n",
5546
"\n",
5647
"```"
5748
]
@@ -184,6 +175,60 @@
184175
" geocat_daylight[pair] = max_daylight(doy, lat)"
185176
]
186177
},
178+
{
179+
"cell_type": "markdown",
180+
"id": "a1401358-81a8-4477-9bc9-bbdaf4224c76",
181+
"metadata": {},
182+
"source": [
183+
"### satvpr_temp_fao56"
184+
]
185+
},
186+
{
187+
"cell_type": "code",
188+
"execution_count": null,
189+
"id": "39c75093-80bc-44c8-880e-ad7f3cfc605c",
190+
"metadata": {},
191+
"outputs": [],
192+
"source": [
193+
"#### Collect NCL values for satvpr_temp_fao56 from geocat-datafiles\n",
194+
"import geocat.datafiles as gdf\n",
195+
"import numpy as np\n",
196+
"\n",
197+
"satvpr_temp_fao56_data = gdf.get(\n",
198+
" 'applications_files/ncl_outputs/satvpr_temp_fao56_output.txt'\n",
199+
")\n",
200+
"satvpr_temp_fao56_data = np.loadtxt(satvpr_temp_fao56_data, delimiter=',', skiprows=6)"
201+
]
202+
},
203+
{
204+
"cell_type": "code",
205+
"execution_count": null,
206+
"id": "00f0ba20-176f-4139-bc65-a14e01695494",
207+
"metadata": {},
208+
"outputs": [],
209+
"source": [
210+
"### Collect NCL `satvpr_temp_fao56` value and associated (temp, satvpr_temp) values\n",
211+
"ncl_satvpr_temp_fao56 = dict(\n",
212+
" zip(satvpr_temp_fao56_data[::, 0], satvpr_temp_fao56_data[::, 1])\n",
213+
")"
214+
]
215+
},
216+
{
217+
"cell_type": "code",
218+
"execution_count": null,
219+
"id": "128843eb-c4ad-425a-a1ec-de89545bcb15",
220+
"metadata": {},
221+
"outputs": [],
222+
"source": [
223+
"### Calculate GeoCAT-Comp `satvpr_temp_fao56`\n",
224+
"from geocat.comp import saturation_vapor_pressure\n",
225+
"\n",
226+
"geocat_satvpr_temp_fao56 = {}\n",
227+
"\n",
228+
"for temp in range(33, 212 + 1):\n",
229+
" geocat_satvpr_temp_fao56[temp] = saturation_vapor_pressure(temp)"
230+
]
231+
},
187232
{
188233
"cell_type": "markdown",
189234
"id": "3237a0bffc6827fc",
@@ -192,6 +237,14 @@
192237
"## Comparison"
193238
]
194239
},
240+
{
241+
"cell_type": "markdown",
242+
"id": "38089ce5-395d-4956-8297-cde6ef5aa99e",
243+
"metadata": {},
244+
"source": [
245+
"### dewtemp_trh"
246+
]
247+
},
195248
{
196249
"cell_type": "code",
197250
"execution_count": null,
@@ -215,18 +268,51 @@
215268
" print(f\"\\tDifference: {ncl_dewtemp[pair] - geocat_dewtemp[pair]}\")"
216269
]
217270
},
271+
{
272+
"cell_type": "markdown",
273+
"id": "b9cd9ad4-f898-460c-b79b-eef6f7a8e89d",
274+
"metadata": {},
275+
"source": [
276+
"### daylight_fao56"
277+
]
278+
},
218279
{
219280
"cell_type": "code",
220281
"execution_count": null,
221282
"id": "840d88ab-7ecc-485a-9aaf-d8de846196a9",
222283
"metadata": {},
223284
"outputs": [],
224285
"source": [
286+
"import math\n",
287+
"\n",
225288
"for pair in ncl_daylight.keys():\n",
226289
" assert math.isclose(\n",
227290
" ncl_daylight[pair], geocat_daylight[pair].flatten()[0], rel_tol=1e-05\n",
228291
" ) # within 5 decimal points"
229292
]
293+
},
294+
{
295+
"cell_type": "markdown",
296+
"id": "db0d8bbd-4899-4932-a28d-107c08e12a15",
297+
"metadata": {},
298+
"source": [
299+
"### satvpr_temp_fao56"
300+
]
301+
},
302+
{
303+
"cell_type": "code",
304+
"execution_count": null,
305+
"id": "134f8583-0e96-43fe-8b0b-94a5e58566be",
306+
"metadata": {},
307+
"outputs": [],
308+
"source": [
309+
"import math\n",
310+
"\n",
311+
"for key in ncl_satvpr_temp_fao56.keys():\n",
312+
" assert math.isclose(\n",
313+
" ncl_satvpr_temp_fao56[key], geocat_satvpr_temp_fao56[key], rel_tol=1e-05\n",
314+
" ) # within 5 decimal points"
315+
]
230316
}
231317
],
232318
"metadata": {
@@ -245,7 +331,7 @@
245331
"name": "python",
246332
"nbconvert_exporter": "python",
247333
"pygments_lexer": "ipython3",
248-
"version": "3.11.8"
334+
"version": "3.12.7"
249335
}
250336
},
251337
"nbformat": 4,

0 commit comments

Comments
 (0)