Skip to content

Commit

Permalink
Added function to calculate richardson number.
Browse files Browse the repository at this point in the history
  • Loading branch information
joernu76 committed Apr 7, 2020
1 parent 3aa0118 commit 8dc0195
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/references.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ References
.. [Garratt1994] Garratt, J.R., 1994: *The Atmospheric Boundary Layer*. Cambridge
University Press, 316 pp.
.. [Holton2004] Holton, J.R. 2004: *An Introduction to Dynamic Meteorology*.
4th ed. Academic Press, 535 pp.
.. [Koch1983] Koch, S. E., M. DesJardins, and P. J. Kocin, 1983: An interactive Barnes
objective map analysis scheme for use with satellite and conventional data.
**J. Appl. Meteor. Climatol.**, *22*, 1487-1503,
Expand Down
37 changes: 37 additions & 0 deletions src/metpy/calc/thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2574,3 +2574,40 @@ def specific_humidity_from_dewpoint(pressure, dewpoint):
"""
mixing_ratio = saturation_mixing_ratio(pressure, dewpoint)
return specific_humidity_from_mixing_ratio(mixing_ratio)


@exporter.export
@preprocess_xarray
@check_units('[length]', '[temperature]', '[length]/[time]', '[length]/[time]')
def gradient_richardson_number(height, potential_temperature, u, v, axis=0):
r"""Calculate the gradient (or flux) Richardson number.
.. math:: Ri = (g/\theta) * \frac{\left(\partial \theta/\partial z\)}
{[\left(\partial u / \partial z\right)^2 + \left(\partial v / \partial z\right)^2}
See [Holton2004]_ pg. 121-122. As noted by [Holton2004]_, flux Richardson
number values below 0.25 indicate turbulence.
Parameters
----------
height : `pint.Quantity`
Atmospheric height
potential_temperature : `pint.Quantity`
Atmospheric potential temperature
u : `pint.Quantity`
x component of the wind
v : `pint.Quantity`
y component of the wind
axis : int, optional
The axis corresponding to vertical, defaults to 0.
Returns
-------
`pint.Quantity`
Gradient Richardson number
"""
dthetadz = first_derivative(potential_temperature, x=height, axis=axis)
dudz = first_derivative(u, x=height, axis=axis)
dvdz = first_derivative(v, x=height, axis=axis)

return (mpconsts.g / potential_temperature) * (dthetadz / (dudz ** 2 + dvdz ** 2))
14 changes: 14 additions & 0 deletions tests/calc/test_thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
relative_humidity_from_mixing_ratio,
relative_humidity_from_specific_humidity,
relative_humidity_wet_psychrometric,
gradient_richardson_number,
saturation_equivalent_potential_temperature,
saturation_mixing_ratio,
saturation_vapor_pressure,
Expand Down Expand Up @@ -1557,3 +1558,16 @@ def test_lcl_grid_surface_LCLs():
temp_truth = np.array([15, 9.10391763, 13]) * units.degC
assert_array_almost_equal(lcl_pressure, pres_truth, 4)
assert_array_almost_equal(lcl_temperature, temp_truth, 4)


def test_gradient_richardson_number():
"""Test gradient Richardson number calculation."""
theta = units('K') * np.asarray([254.5, 258.3, 262.2])
u_wnd = units('m/s') * np.asarray([-2., -1.1, 0.23])
v_wnd = units('m/s') * np.asarray([3.3, 4.2, 5.2])
height = units('km') * np.asarray([0.2, 0.4, 0.6])

result = gradient_richardson_number(height, theta, u_wnd, v_wnd)
expected = np.asarray([24.2503551, 13.6242603, 8.4673744])

assert_array_almost_equal(result, expected, 4)

0 comments on commit 8dc0195

Please sign in to comment.