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

saturation_vapor_pressure #154

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
50 changes: 48 additions & 2 deletions ncl/ncl_entries/meteorology.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"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)"
"- [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)"
]
},
{
Expand Down Expand Up @@ -116,6 +117,50 @@
"max_daylight(days_of_year, latitudes)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## satvpr_temp_fao56\n",
"\n",
"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`"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Grab and Go"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Input: Single Value\n",
"from geocat.comp import saturation_vapor_pressure\n",
"\n",
"temp = 50 # Fahrenheit\n",
"\n",
"saturation_vapor_pressure(temp)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Input: List/Array\n",
"from geocat.comp import saturation_vapor_pressure\n",
"\n",
"temp = [33, 50, 100, 212] # Fahrenheit\n",
"\n",
"saturation_vapor_pressure(temp)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -131,6 +176,7 @@
"- [GeoCAT-comp `dewtemp` documentation](https://geocat-comp.readthedocs.io/en/latest/user_api/generated/geocat.comp.meteorology.dewtemp.html)\n",
"- [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",
"\n",
"## Additional Reading\n",
"- [NOAA: Dew Point vs. Humidity](https://www.weather.gov/arx/why_dewpoint_vs_humidity)"
Expand Down Expand Up @@ -163,7 +209,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down
1 change: 1 addition & 0 deletions ncl/ncl_index/ncl-index-table.csv
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ NCL Function,Description,Python Equivalent,Notes
`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>`__
`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>`__
`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>`__
14 changes: 0 additions & 14 deletions ncl/ncl_raw/daylight_fao56.ncl

This file was deleted.

14 changes: 0 additions & 14 deletions ncl/ncl_raw/dewtemp_trh.ncl

This file was deleted.

42 changes: 42 additions & 0 deletions ncl/ncl_raw/meteorology.ncl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
; 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

; dewtemp_trh
; Adapted from https://www.ncl.ucar.edu/Document/Functions/Built-in/dewtemp_trh.shtml

; ncl -n dewtemp_trh.ncl >> dewtemp_trh_output.txt

print("Temperature (K), Relative Humidity (%), Dew Temperature (C)")
do tk=273,374
do rh=1,100
begin
dewtemp = dewtemp_trh(tk,rh)-273.15
print (tk +","+ rh +","+ dewtemp)
end
end do
end do

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

; ncl -n satvpr_temp_fao56.ncl >> satvpr_temp_fao56_output.txt

print("Temperature (F), Saturation Vapor Pressure (kPa)")
do temp=33,212
begin
sat_vpr_pressure = satvpr_temp_fao56(temp, (/2, 2/))
print (temp + "," + sat_vpr_pressure)
end
end do
112 changes: 99 additions & 13 deletions ncl/receipts/meteorology.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"source": [
"## 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)"
"- [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)"
]
},
{
Expand All @@ -41,17 +42,7 @@
"id": "3d70616a8934f0fb",
"metadata": {},
"source": [
"```{literalinclude} ../ncl_raw/dewtemp_trh.ncl\n",
"\n",
"```"
]
},
{
"cell_type": "markdown",
"id": "3b32a066-055f-454b-a843-e57dca954dad",
"metadata": {},
"source": [
"```{literalinclude} ../ncl_raw/daylight_fao56.ncl\n",
"```{literalinclude} ../ncl_raw/meteorology.ncl\n",
"\n",
"```"
]
Expand Down Expand Up @@ -184,6 +175,60 @@
" geocat_daylight[pair] = max_daylight(doy, lat)"
]
},
{
"cell_type": "markdown",
"id": "a1401358-81a8-4477-9bc9-bbdaf4224c76",
"metadata": {},
"source": [
"### satvpr_temp_fao56"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "39c75093-80bc-44c8-880e-ad7f3cfc605c",
"metadata": {},
"outputs": [],
"source": [
"#### Collect NCL values for satvpr_temp_fao56 from geocat-datafiles\n",
"import geocat.datafiles as gdf\n",
"import numpy as np\n",
"\n",
"satvpr_temp_fao56_data = gdf.get(\n",
" 'applications_files/ncl_outputs/satvpr_temp_fao56_output.txt'\n",
")\n",
"satvpr_temp_fao56_data = np.loadtxt(satvpr_temp_fao56_data, delimiter=',', skiprows=6)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "00f0ba20-176f-4139-bc65-a14e01695494",
"metadata": {},
"outputs": [],
"source": [
"### Collect NCL `satvpr_temp_fao56` value and associated (temp, satvpr_temp) values\n",
"ncl_satvpr_temp_fao56 = dict(\n",
" zip(satvpr_temp_fao56_data[::, 0], satvpr_temp_fao56_data[::, 1])\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "128843eb-c4ad-425a-a1ec-de89545bcb15",
"metadata": {},
"outputs": [],
"source": [
"### Calculate GeoCAT-Comp `satvpr_temp_fao56`\n",
"from geocat.comp import saturation_vapor_pressure\n",
"\n",
"geocat_satvpr_temp_fao56 = {}\n",
"\n",
"for temp in range(33, 212 + 1):\n",
" geocat_satvpr_temp_fao56[temp] = saturation_vapor_pressure(temp)"
]
},
{
"cell_type": "markdown",
"id": "3237a0bffc6827fc",
Expand All @@ -192,6 +237,14 @@
"## Comparison"
]
},
{
"cell_type": "markdown",
"id": "38089ce5-395d-4956-8297-cde6ef5aa99e",
"metadata": {},
"source": [
"### dewtemp_trh"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -215,18 +268,51 @@
" print(f\"\\tDifference: {ncl_dewtemp[pair] - geocat_dewtemp[pair]}\")"
]
},
{
"cell_type": "markdown",
"id": "b9cd9ad4-f898-460c-b79b-eef6f7a8e89d",
"metadata": {},
"source": [
"### daylight_fao56"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "840d88ab-7ecc-485a-9aaf-d8de846196a9",
"metadata": {},
"outputs": [],
"source": [
"import math\n",
"\n",
"for pair in ncl_daylight.keys():\n",
" assert math.isclose(\n",
" ncl_daylight[pair], geocat_daylight[pair].flatten()[0], rel_tol=1e-05\n",
" ) # within 5 decimal points"
]
},
{
"cell_type": "markdown",
"id": "db0d8bbd-4899-4932-a28d-107c08e12a15",
"metadata": {},
"source": [
"### satvpr_temp_fao56"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "134f8583-0e96-43fe-8b0b-94a5e58566be",
"metadata": {},
"outputs": [],
"source": [
"import math\n",
"\n",
"for key in ncl_satvpr_temp_fao56.keys():\n",
" assert math.isclose(\n",
" ncl_satvpr_temp_fao56[key], geocat_satvpr_temp_fao56[key], rel_tol=1e-05\n",
" ) # within 5 decimal points"
]
}
],
"metadata": {
Expand All @@ -245,7 +331,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down