Skip to content

Commit

Permalink
coriolis_param (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyschneck authored Feb 4, 2025
1 parent bc78660 commit 3008321
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 4 deletions.
55 changes: 52 additions & 3 deletions ncl/ncl_entries/meteorology.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"- [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)\n",
"- [satvpr_tdew_fao56](https://www.ncl.ucar.edu/Document/Functions/Crop/satvpr_tdew_fao56.shtml)\n",
"- [satvpr_slope_fao56](https://www.ncl.ucar.edu/Document/Functions/Crop/satvpr_slope_fao56.shtml)"
"- [satvpr_slope_fao56](https://www.ncl.ucar.edu/Document/Functions/Crop/satvpr_slope_fao56.shtml)\n",
"- [coriolis_param](https://www.ncl.ucar.edu/Document/Functions/Contributed/coriolis_param.shtml)"
]
},
{
Expand Down Expand Up @@ -92,9 +93,9 @@
"\n",
"{math}`N = \\frac{24}{{\\pi}} {\\omega}_{s}`\n",
"\n",
"And {math}`{\\omega}_{s}` is the sunset hour angle in radians [(Chapter 3, Equation 25)](https://www.fao.org/4/X0490E/x0490e07.htm#chapter%203%20%20%20meteorological%20data) {footcite}`allan_fao_1998` which is calculated from the latitude of the observer on Earth ({math}`\\phi`) and the sun's declination ({math}`\\delta`):\n",
"And {math}`{\\omega}_{s}` is the sunset hour angle in radians [(Chapter 3, Equation 25)](https://www.fao.org/4/X0490E/x0490e07.htm#chapter%203%20%20%20meteorological%20data) {footcite}`allan_fao_1998` which is calculated from the latitude of the observer on Earth ({math}`\\varphi`) and the sun's declination ({math}`\\delta`):\n",
"\n",
"{math}`{\\omega}_{s} = arccos[-tan({\\phi})tan({\\delta})]`"
"{math}`{\\omega}_{s} = arccos[-tan({\\varphi})tan({\\delta})]`"
]
},
{
Expand Down Expand Up @@ -265,6 +266,53 @@
"saturation_vapor_pressure_slope(temp)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## coriolis_param\n",
"\n",
"NCL's `coriolis_param` calculates the Coriolis parameter at a given latitude\n",
"\n",
"The Coriolis parameter (also known as the Coriolis frequency or the Coriolis coefficient) is calculated as twice the rotation rate ({math}`{\\Omega}`) of the Earth times the sine of the latitude ({math}`{\\varphi}`){footcite}`hobbs_wallace_1997`\n",
"\n",
"{math}`f = 2{\\Omega}sin({\\varphi})`\n",
"\n",
"The rotation rate depends on the length of the rotation period of the Earth (T) which is defined as one sidereal day (23 hours and 56 minutes):\n",
"\n",
"{math}`{\\Omega} = \\frac{2 * {\\pi}}{T} = 7.292\\text{e-5} \\frac{rad}{s}`"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Input: Single Value\n",
"from metpy.calc import coriolis_parameter\n",
"from metpy.units import units\n",
"\n",
"latitude = 40 # degrees\n",
"\n",
"coriolis_parameter(latitude * units.degree).magnitude"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Input: List/Array\n",
"from metpy.calc import coriolis_parameter\n",
"from metpy.units import units\n",
"\n",
"latitude = [-20, 40, 65] # degrees\n",
"\n",
"coriolis_parameter(latitude * units.degree).magnitude"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -283,6 +331,7 @@
"- [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",
"- [GeoCAT-comp `saturation_vapor_pressure_slope` Documentation](https://geocat-comp.readthedocs.io/en/latest/user_api/generated/geocat.comp.meteorology.saturation_vapor_pressure_slope.html)\n",
"- [MetPy `coriolis_parameter` Documentation](https://unidata.github.io/MetPy/latest/api/generated/metpy.calc.coriolis_parameter.html)\n",
"\n",
"## Additional Reading\n",
"- [NOAA: Dew Point vs. Humidity](https://www.weather.gov/arx/why_dewpoint_vs_humidity)"
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 @@ -50,3 +50,4 @@ NCL Function,Description,Python Equivalent,Notes
`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>`__
`satvpr_slope_fao56 <https://www.ncl.ucar.edu/Document/Functions/Crop/satvpr_slope_fao56.shtml>`__," Compute the slope of the saturation vapor pressure curve as described in FAO 56","``geocat.comp.saturation_vapor_pressure_slope()``",`example notebook <../ncl_entries/meteorology.ipynb#satvpr-slope-fao56>`__
`coriolis_param <https://www.ncl.ucar.edu/Document/Functions/Contributed/coriolis_param.shtml>`__,"Calculate the Coriolis parameter","``metpy.calc.coriolis_parameter()``",`example notebook <../ncl_entries/meteorology.ipynb#coriolis-param>`__
10 changes: 10 additions & 0 deletions ncl/ncl_raw/meteorology.ncl
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,13 @@ do temp=33,212
print (temp + "," + slope_satvpr)
end
end do

; coriolis_param
; Adapted from https://www.ncl.ucar.edu/Document/Functions/Contributed/coriolis_param.shtml

; ncl -n coriolis_param.ncl >> coriolis_param_output.txt

print("Latitude (Degree), Coriolis Parameter")
do lat=-90,90
print(lat + "," + coriolis_param(lat))
end do
79 changes: 78 additions & 1 deletion ncl/receipts/meteorology.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"- [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)\n",
"- [satvpr_tdew_fao56](https://www.ncl.ucar.edu/Document/Functions/Crop/satvpr_tdew_fao56.shtml)\n",
"- [satvpr_slope_fao56](https://www.ncl.ucar.edu/Document/Functions/Crop/satvpr_slope_fao56.shtml)"
"- [satvpr_slope_fao56](https://www.ncl.ucar.edu/Document/Functions/Crop/satvpr_slope_fao56.shtml)\n",
"- [coriolis_param](https://www.ncl.ucar.edu/Document/Functions/Contributed/coriolis_param.shtml)"
]
},
{
Expand Down Expand Up @@ -339,6 +340,59 @@
" geocat_satvpr_slope_fao56[temp] = saturation_vapor_pressure_slope(temp)"
]
},
{
"cell_type": "markdown",
"id": "3b9ce2e3-833a-4dbc-8d6a-35eb86397b19",
"metadata": {},
"source": [
"### coriolis_param"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c2646150-8327-4faa-8979-b70e98be9631",
"metadata": {},
"outputs": [],
"source": [
"#### Collect NCL values for coriolis_param from geocat-datafiles\n",
"import geocat.datafiles as gdf\n",
"import numpy as np\n",
"\n",
"coriolis_param_data = gdf.get(\n",
" 'applications_files/ncl_outputs/coriolis_param_output.txt'\n",
")\n",
"coriolis_param_data = np.loadtxt(coriolis_param_data, delimiter=',', skiprows=6)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9a699cc2-5a21-4a49-92f9-353635036d06",
"metadata": {},
"outputs": [],
"source": [
"### Collect NCL `coriolis_param_data` value and associated coriolis parameter values\n",
"ncl_coriolis_param = dict(zip(coriolis_param_data[::, 0], coriolis_param_data[::, 1]))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "04410fd1-3033-4c6b-812f-e6b12b3e884e",
"metadata": {},
"outputs": [],
"source": [
"### Calculate MetPy \"coriolis_parameter\"\n",
"from metpy.calc import coriolis_parameter\n",
"from metpy.units import units\n",
"\n",
"metpy_coriolis_para = {}\n",
"\n",
"for lat in range(-90, 90 + 1):\n",
" metpy_coriolis_para[lat] = coriolis_parameter(lat * units.degree).magnitude"
]
},
{
"cell_type": "markdown",
"id": "3237a0bffc6827fc",
Expand Down Expand Up @@ -469,6 +523,29 @@
" ncl_satvpr_slope_fao56[key], geocat_satvpr_slope_fao56[key], rel_tol=1e-05\n",
" ) # within 5 decimal points"
]
},
{
"cell_type": "markdown",
"id": "980c82cf-3860-4f46-bb98-65e4bea9f3cf",
"metadata": {},
"source": [
"### coriolis_param"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1229100a-0e88-46ef-afad-d557b043a713",
"metadata": {},
"outputs": [],
"source": [
"import math\n",
"\n",
"for key in ncl_coriolis_param.keys():\n",
" assert math.isclose(\n",
" ncl_coriolis_param[key], metpy_coriolis_para[key], rel_tol=1e-04\n",
" ) # within 4 decimal points"
]
}
],
"metadata": {
Expand Down
8 changes: 8 additions & 0 deletions references.bib
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,11 @@ @misc{usgs_1987
title = {Map projections: A working manual},
doi = {10.3133/pp1395}
}

@book{hobbs_wallace_1997,
author = {Hobbs, Peter V. and Wallace, John Michael},
title = {Atmospheric Science: An Introductory Survey},
year = {1977},
pages = {277},
publisher = {Academic Press}
}

0 comments on commit 3008321

Please sign in to comment.