Skip to content

Commit 04b8dab

Browse files
authored
Merge pull request Unidata#739 from jrleeman/ageostrophic_wind
Ageostrophic wind
2 parents 4052a11 + 971aa2f commit 04b8dab

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

metpy/calc/kinematics.py

+34
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,40 @@ def geostrophic_wind(heights, f, dx, dy):
500500
return -norm_factor * dhdy, norm_factor * dhdx
501501

502502

503+
@exporter.export
504+
@ensure_yx_order
505+
def ageostrophic_wind(heights, f, dx, dy, u, v, dim_order='yx'):
506+
r"""Calculate the ageostrophic wind given from the heights or geopotential.
507+
508+
Parameters
509+
----------
510+
heights : (M, N) ndarray
511+
The height field, with either leading dimensions of (x, y) or trailing dimensions
512+
of (y, x), depending on the value of ``dim_order``.
513+
f : array_like
514+
The coriolis parameter. This can be a scalar to be applied
515+
everywhere or an array of values.
516+
dx : scalar
517+
The grid spacing in the x-direction
518+
dy : scalar
519+
The grid spacing in the y-direction
520+
u : (M, N) ndarray
521+
The u wind field, with either leading dimensions of (x, y) or trailing dimensions
522+
of (y, x), depending on the value of ``dim_order``.
523+
v : (M, N) ndarray
524+
The u wind field, with either leading dimensions of (x, y) or trailing dimensions
525+
of (y, x), depending on the value of ``dim_order``.
526+
527+
Returns
528+
-------
529+
A 2-item tuple of arrays
530+
A tuple of the u-component and v-component of the ageostrophic wind.
531+
532+
"""
533+
u_geostrophic, v_geostrophic = geostrophic_wind(heights, f, dx, dy, dim_order=dim_order)
534+
return u - u_geostrophic, v - v_geostrophic
535+
536+
503537
@exporter.export
504538
@check_units('[length]', '[temperature]')
505539
def montgomery_streamfunction(height, temperature):

metpy/calc/tests/test_kinematics.py

+27-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import numpy as np
77
import pytest
88

9-
from metpy.calc import (advection, convergence_vorticity, divergence,
9+
from metpy.calc import (advection, ageostrophic_wind, convergence_vorticity, divergence,
1010
frontogenesis, geostrophic_wind, get_wind_components, h_convergence,
1111
lat_lon_grid_deltas, lat_lon_grid_spacing, montgomery_streamfunction,
1212
shearing_deformation, shearing_stretching_deformation,
@@ -399,6 +399,32 @@ def test_geostrophic_gempak():
399399
assert_almost_equal(vg[1, 1], true_v[1, 1] * units('m/s'), 2)
400400

401401

402+
def test_no_ageostrophic_geopotential():
403+
"""Test ageostrophic wind calculation with geopotential and no ageostrophic wind."""
404+
z = np.array([[48, 49, 48], [49, 50, 49], [48, 49, 48]]) * 100. * units('m^2/s^2')
405+
u = np.array([[-2, 0, 2]] * 3) * units('m/s')
406+
v = -u.T
407+
uag, vag = ageostrophic_wind(z, 1 / units.sec, 100. * units.meter, 100. * units.meter,
408+
u, v, dim_order='xy')
409+
true = np.array([[0, 0, 0]] * 3) * units('m/s')
410+
assert_array_equal(uag, true)
411+
assert_array_equal(vag, true)
412+
413+
414+
def test_ageostrophic_geopotential():
415+
"""Test ageostrophic wind calculation with geopotential and ageostrophic wind."""
416+
z = np.array([[48, 49, 48], [49, 50, 49], [48, 49, 48]]) * 100. * units('m^2/s^2')
417+
u = v = np.array([[0, 0, 0]] * 3) * units('m/s')
418+
uag, vag = ageostrophic_wind(z, 1 / units.sec, 100. * units.meter, 100. * units.meter,
419+
u, v, dim_order='xy')
420+
421+
u_true = np.array([[2, 0, -2]] * 3) * units('m/s')
422+
v_true = -u_true.T
423+
424+
assert_array_equal(uag, u_true)
425+
assert_array_equal(vag, v_true)
426+
427+
402428
def test_streamfunc():
403429
"""Test of Montgomery Streamfunction calculation."""
404430
t = 287. * units.kelvin

0 commit comments

Comments
 (0)