Skip to content

Commit 0208817

Browse files
authored
actual_saturation_vapor_pressure (#158)
1 parent 8b7fe46 commit 0208817

File tree

4 files changed

+135
-4
lines changed

4 files changed

+135
-4
lines changed

ncl/ncl_entries/meteorology.ipynb

+40-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"\n",
1818
"- [dewtemp_trh](https://www.ncl.ucar.edu/Document/Functions/Built-in/dewtemp_trh.shtml)\n",
1919
"- [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)"
20+
"- [satvpr_temp_fao56](https://www.ncl.ucar.edu/Document/Functions/Crop/satvpr_temp_fao56.shtml)\n",
21+
"- [satvpr_tdew_fao56](https://www.ncl.ucar.edu/Document/Functions/Crop/satvpr_tdew_fao56.shtml)"
2122
]
2223
},
2324
{
@@ -161,6 +162,43 @@
161162
"saturation_vapor_pressure(temp)"
162163
]
163164
},
165+
{
166+
"cell_type": "markdown",
167+
"metadata": {},
168+
"source": [
169+
"## satvpr_tdew_fao56\n",
170+
"\n",
171+
"NCL's `satvpr_tdew_fao56` calculates the actual saturation vapor pressure using dewpoint temperature as described in the Food and Agriculture Organization (FAO) Irrigation and Drainage Paper 56 [(Chapter 3, Equation 14)](https://www.fao.org/4/x0490e/x0490e07.htm) {footcite}`allan_fao_1998`"
172+
]
173+
},
174+
{
175+
"cell_type": "code",
176+
"execution_count": null,
177+
"metadata": {},
178+
"outputs": [],
179+
"source": [
180+
"# Input: Single Value\n",
181+
"from geocat.comp import actual_saturation_vapor_pressure\n",
182+
"\n",
183+
"temp = 35 # Fahrenheit\n",
184+
"\n",
185+
"actual_saturation_vapor_pressure(temp)"
186+
]
187+
},
188+
{
189+
"cell_type": "code",
190+
"execution_count": null,
191+
"metadata": {},
192+
"outputs": [],
193+
"source": [
194+
"# Input: List/Array\n",
195+
"from geocat.comp import actual_saturation_vapor_pressure\n",
196+
"\n",
197+
"temp = [35, 60, 80, 200] # Fahrenheit\n",
198+
"\n",
199+
"actual_saturation_vapor_pressure(temp)"
200+
]
201+
},
164202
{
165203
"cell_type": "markdown",
166204
"metadata": {},
@@ -177,6 +215,7 @@
177215
"- [Convert between different temperature scales in SciPy](https://docs.scipy.org/doc/scipy/reference/generated/scipy.constants.convert_temperature.html)\n",
178216
"- [GeoCAT-comp `max_daylight` Documentation](https://geocat-comp.readthedocs.io/en/latest/user_api/generated/geocat.comp.meteorology.max_daylight.html)\n",
179217
"- [GeoCAT-comp `saturation_vapor_pressure` Documentation](https://geocat-comp.readthedocs.io/en/latest/user_api/generated/geocat.comp.meteorology.saturation_vapor_pressure.html)\n",
218+
"- [GeoCAT-comp `actual_saturation_vapor_pressure` Documentation](https://geocat-comp.readthedocs.io/en/latest/user_api/generated/geocat.comp.meteorology.actual_saturation_vapor_pressure.html)\n",
180219
"\n",
181220
"## Additional Reading\n",
182221
"- [NOAA: Dew Point vs. Humidity](https://www.weather.gov/arx/why_dewpoint_vs_humidity)"

ncl/ncl_index/ncl-index-table.csv

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,5 @@ NCL Function,Description,Python Equivalent,Notes
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>`__
4949
`css2c <https://www.ncl.ucar.edu/Document/Functions/Built-in/css2c.shtml>`__,"Converts spherical coordinates (lat/lon) to Cartesian coordinates on a unit sphere","``astropy.UnitSphericalRepresentation()``",`example notebook <../ncl_entries/great_circle.ipynb#css2c>`__
50-
`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>`__
50+
`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>`__
51+
`satvpr_tdew_fao56 <https://www.ncl.ucar.edu/Document/Functions/Crop/satvpr_tdew_fao56.shtml>`__,"Compute actual saturation vapor pressure as described in FAO 56","``geocat.comp.actual_saturation_vapor_pressure()``",`example notebook <../ncl_entries/meteorology.ipynb#satvpr-tdew-fao56>`__

ncl/ncl_raw/meteorology.ncl

+13
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,16 @@ do temp=33,212
4040
print (temp + "," + sat_vpr_pressure)
4141
end
4242
end do
43+
44+
; satvpr_tdew_fao56
45+
; Adapted from https://www.ncl.ucar.edu/Document/Functions/Crop/satvpr_tdew_fao56.shtml
46+
47+
; ncl -n satvpr_tdew_fao56.ncl >> satvpr_tdew_fao56_output.txt
48+
49+
print("Temperature (F), Actual Saturation Vapor Pressure (kPa)")
50+
do temp=33,212
51+
begin
52+
act_sat_vpr_pressure = satvpr_tdew_fao56(temp, (/2, 2/))
53+
print (temp + "," + act_sat_vpr_pressure)
54+
end
55+
end do

ncl/receipts/meteorology.ipynb

+80-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"## Functions covered\n",
2727
"- [dewtemp_trh](https://www.ncl.ucar.edu/Document/Functions/Built-in/dewtemp_trh.shtml)\n",
2828
"- [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)"
29+
"- [satvpr_temp_fao56](https://www.ncl.ucar.edu/Document/Functions/Crop/satvpr_temp_fao56.shtml)\n",
30+
"- [satvpr_tdew_fao56](https://www.ncl.ucar.edu/Document/Functions/Crop/satvpr_tdew_fao56.shtml)"
3031
]
3132
},
3233
{
@@ -220,7 +221,7 @@
220221
"metadata": {},
221222
"outputs": [],
222223
"source": [
223-
"### Calculate GeoCAT-Comp `satvpr_temp_fao56`\n",
224+
"### Calculate GeoCAT-Comp `saturation_vapor_pressure`\n",
224225
"from geocat.comp import saturation_vapor_pressure\n",
225226
"\n",
226227
"geocat_satvpr_temp_fao56 = {}\n",
@@ -229,6 +230,60 @@
229230
" geocat_satvpr_temp_fao56[temp] = saturation_vapor_pressure(temp)"
230231
]
231232
},
233+
{
234+
"cell_type": "markdown",
235+
"id": "c4bdc314-ba26-4c76-8e5e-3fe6804aad40",
236+
"metadata": {},
237+
"source": [
238+
"### satvpr_tdew_fao56"
239+
]
240+
},
241+
{
242+
"cell_type": "code",
243+
"execution_count": null,
244+
"id": "ffff46d9-f229-4f02-97eb-b3cd346e9dcf",
245+
"metadata": {},
246+
"outputs": [],
247+
"source": [
248+
"#### Collect NCL values for satvpr_tdew_fao56 from geocat-datafiles\n",
249+
"import geocat.datafiles as gdf\n",
250+
"import numpy as np\n",
251+
"\n",
252+
"satvpr_tdew_fao56_data = gdf.get(\n",
253+
" 'applications_files/ncl_outputs/satvpr_tdew_fao56_output.txt'\n",
254+
")\n",
255+
"satvpr_tdew_fao56_data = np.loadtxt(satvpr_tdew_fao56_data, delimiter=',', skiprows=6)"
256+
]
257+
},
258+
{
259+
"cell_type": "code",
260+
"execution_count": null,
261+
"id": "d6fce921-4897-40a2-9c59-c407834f4294",
262+
"metadata": {},
263+
"outputs": [],
264+
"source": [
265+
"### Collect NCL `satvpr_tdew_fao56` value and associated (temp, act_sat_vapr_pressure) values\n",
266+
"ncl_satvpr_tdew_fao56 = dict(\n",
267+
" zip(satvpr_tdew_fao56_data[::, 0], satvpr_tdew_fao56_data[::, 1])\n",
268+
")"
269+
]
270+
},
271+
{
272+
"cell_type": "code",
273+
"execution_count": null,
274+
"id": "c0220698-cdec-4de9-bcf6-ffa20bdd78c2",
275+
"metadata": {},
276+
"outputs": [],
277+
"source": [
278+
"### Calculate GeoCAT-Comp `actual_saturation_vapor_pressure`\n",
279+
"from geocat.comp import actual_saturation_vapor_pressure\n",
280+
"\n",
281+
"geocat_satvpr_tdew_fao56 = {}\n",
282+
"\n",
283+
"for temp in range(33, 212 + 1):\n",
284+
" geocat_satvpr_tdew_fao56[temp] = actual_saturation_vapor_pressure(temp)"
285+
]
286+
},
232287
{
233288
"cell_type": "markdown",
234289
"id": "3237a0bffc6827fc",
@@ -313,6 +368,29 @@
313368
" ncl_satvpr_temp_fao56[key], geocat_satvpr_temp_fao56[key], rel_tol=1e-05\n",
314369
" ) # within 5 decimal points"
315370
]
371+
},
372+
{
373+
"cell_type": "markdown",
374+
"id": "b0a67250-3136-4b0c-b808-21a15427060a",
375+
"metadata": {},
376+
"source": [
377+
"### satvpr_tdew_fao56"
378+
]
379+
},
380+
{
381+
"cell_type": "code",
382+
"execution_count": null,
383+
"id": "2c037826-8d87-4bf2-9f3a-f98701ba11a7",
384+
"metadata": {},
385+
"outputs": [],
386+
"source": [
387+
"import math\n",
388+
"\n",
389+
"for key in ncl_satvpr_tdew_fao56.keys():\n",
390+
" assert math.isclose(\n",
391+
" ncl_satvpr_tdew_fao56[key], geocat_satvpr_tdew_fao56[key], rel_tol=1e-05\n",
392+
" ) # within 5 decimal points"
393+
]
316394
}
317395
],
318396
"metadata": {

0 commit comments

Comments
 (0)