Skip to content

Commit

Permalink
actual_saturation_vapor_pressure (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyschneck authored Dec 19, 2024
1 parent 8b7fe46 commit 0208817
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 4 deletions.
41 changes: 40 additions & 1 deletion ncl/ncl_entries/meteorology.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"\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)\n",
"- [satvpr_temp_fao56](https://www.ncl.ucar.edu/Document/Functions/Crop/satvpr_temp_fao56.shtml)"
"- [satvpr_temp_fao56](https://www.ncl.ucar.edu/Document/Functions/Crop/satvpr_temp_fao56.shtml)\n",
"- [satvpr_tdew_fao56](https://www.ncl.ucar.edu/Document/Functions/Crop/satvpr_tdew_fao56.shtml)"
]
},
{
Expand Down Expand Up @@ -161,6 +162,43 @@
"saturation_vapor_pressure(temp)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## satvpr_tdew_fao56\n",
"\n",
"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`"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Input: Single Value\n",
"from geocat.comp import actual_saturation_vapor_pressure\n",
"\n",
"temp = 35 # Fahrenheit\n",
"\n",
"actual_saturation_vapor_pressure(temp)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Input: List/Array\n",
"from geocat.comp import actual_saturation_vapor_pressure\n",
"\n",
"temp = [35, 60, 80, 200] # Fahrenheit\n",
"\n",
"actual_saturation_vapor_pressure(temp)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -177,6 +215,7 @@
"- [Convert between different temperature scales in SciPy](https://docs.scipy.org/doc/scipy/reference/generated/scipy.constants.convert_temperature.html)\n",
"- [GeoCAT-comp `max_daylight` Documentation](https://geocat-comp.readthedocs.io/en/latest/user_api/generated/geocat.comp.meteorology.max_daylight.html)\n",
"- [GeoCAT-comp `saturation_vapor_pressure` Documentation](https://geocat-comp.readthedocs.io/en/latest/user_api/generated/geocat.comp.meteorology.saturation_vapor_pressure.html)\n",
"- [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",
"\n",
"## Additional Reading\n",
"- [NOAA: Dew Point vs. Humidity](https://www.weather.gov/arx/why_dewpoint_vs_humidity)"
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 @@ -47,4 +47,5 @@ NCL Function,Description,Python Equivalent,Notes
`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>`__
`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>`__
`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>`__
`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>`__
`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>`__
`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>`__
13 changes: 13 additions & 0 deletions ncl/ncl_raw/meteorology.ncl
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,16 @@ do temp=33,212
print (temp + "," + sat_vpr_pressure)
end
end do

; satvpr_tdew_fao56
; Adapted from https://www.ncl.ucar.edu/Document/Functions/Crop/satvpr_tdew_fao56.shtml

; ncl -n satvpr_tdew_fao56.ncl >> satvpr_tdew_fao56_output.txt

print("Temperature (F), Actual Saturation Vapor Pressure (kPa)")
do temp=33,212
begin
act_sat_vpr_pressure = satvpr_tdew_fao56(temp, (/2, 2/))
print (temp + "," + act_sat_vpr_pressure)
end
end do
82 changes: 80 additions & 2 deletions ncl/receipts/meteorology.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"## Functions covered\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)\n",
"- [satvpr_temp_fao56](https://www.ncl.ucar.edu/Document/Functions/Crop/satvpr_temp_fao56.shtml)"
"- [satvpr_temp_fao56](https://www.ncl.ucar.edu/Document/Functions/Crop/satvpr_temp_fao56.shtml)\n",
"- [satvpr_tdew_fao56](https://www.ncl.ucar.edu/Document/Functions/Crop/satvpr_tdew_fao56.shtml)"
]
},
{
Expand Down Expand Up @@ -220,7 +221,7 @@
"metadata": {},
"outputs": [],
"source": [
"### Calculate GeoCAT-Comp `satvpr_temp_fao56`\n",
"### Calculate GeoCAT-Comp `saturation_vapor_pressure`\n",
"from geocat.comp import saturation_vapor_pressure\n",
"\n",
"geocat_satvpr_temp_fao56 = {}\n",
Expand All @@ -229,6 +230,60 @@
" geocat_satvpr_temp_fao56[temp] = saturation_vapor_pressure(temp)"
]
},
{
"cell_type": "markdown",
"id": "c4bdc314-ba26-4c76-8e5e-3fe6804aad40",
"metadata": {},
"source": [
"### satvpr_tdew_fao56"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ffff46d9-f229-4f02-97eb-b3cd346e9dcf",
"metadata": {},
"outputs": [],
"source": [
"#### Collect NCL values for satvpr_tdew_fao56 from geocat-datafiles\n",
"import geocat.datafiles as gdf\n",
"import numpy as np\n",
"\n",
"satvpr_tdew_fao56_data = gdf.get(\n",
" 'applications_files/ncl_outputs/satvpr_tdew_fao56_output.txt'\n",
")\n",
"satvpr_tdew_fao56_data = np.loadtxt(satvpr_tdew_fao56_data, delimiter=',', skiprows=6)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d6fce921-4897-40a2-9c59-c407834f4294",
"metadata": {},
"outputs": [],
"source": [
"### Collect NCL `satvpr_tdew_fao56` value and associated (temp, act_sat_vapr_pressure) values\n",
"ncl_satvpr_tdew_fao56 = dict(\n",
" zip(satvpr_tdew_fao56_data[::, 0], satvpr_tdew_fao56_data[::, 1])\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c0220698-cdec-4de9-bcf6-ffa20bdd78c2",
"metadata": {},
"outputs": [],
"source": [
"### Calculate GeoCAT-Comp `actual_saturation_vapor_pressure`\n",
"from geocat.comp import actual_saturation_vapor_pressure\n",
"\n",
"geocat_satvpr_tdew_fao56 = {}\n",
"\n",
"for temp in range(33, 212 + 1):\n",
" geocat_satvpr_tdew_fao56[temp] = actual_saturation_vapor_pressure(temp)"
]
},
{
"cell_type": "markdown",
"id": "3237a0bffc6827fc",
Expand Down Expand Up @@ -313,6 +368,29 @@
" ncl_satvpr_temp_fao56[key], geocat_satvpr_temp_fao56[key], rel_tol=1e-05\n",
" ) # within 5 decimal points"
]
},
{
"cell_type": "markdown",
"id": "b0a67250-3136-4b0c-b808-21a15427060a",
"metadata": {},
"source": [
"### satvpr_tdew_fao56"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2c037826-8d87-4bf2-9f3a-f98701ba11a7",
"metadata": {},
"outputs": [],
"source": [
"import math\n",
"\n",
"for key in ncl_satvpr_tdew_fao56.keys():\n",
" assert math.isclose(\n",
" ncl_satvpr_tdew_fao56[key], geocat_satvpr_tdew_fao56[key], rel_tol=1e-05\n",
" ) # within 5 decimal points"
]
}
],
"metadata": {
Expand Down

0 comments on commit 0208817

Please sign in to comment.