Skip to content

Commit

Permalink
BUG: Fix q_vector units w/ default static stability (Fixes Unidata#3689)
Browse files Browse the repository at this point in the history
There's no reason the units should change in this case, just assign
proper units to the default unity value of static stability.
  • Loading branch information
dopplershift committed Nov 13, 2024
1 parent ab1b956 commit e1e3ae8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/metpy/calc/kinematics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1266,15 +1266,16 @@ def inertial_advective_wind(
broadcast=('u', 'v', 'temperature', 'pressure', 'static_stability', 'parallel_scale',
'meridional_scale')
)
@check_units('[speed]', '[speed]', '[temperature]', '[pressure]', '[length]', '[length]')
@check_units('[speed]', '[speed]', '[temperature]', '[pressure]', '[length]', '[length]',
'[energy] / [mass] / [pressure]**2')
def q_vector(
u,
v,
temperature,
pressure,
dx=None,
dy=None,
static_stability=1,
static_stability=units.Quantity(1, 'J kg^-1 Pa^-2'),
x_dim=-1,
y_dim=-2,
*,
Expand Down
8 changes: 4 additions & 4 deletions tests/calc/test_kinematics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1262,12 +1262,12 @@ def test_q_vector_without_static_stability(q_vector_data):
[-1.8952185e-13, -2.2269905e-14, -2.2269905e-14, -1.8952185e-13],
[-1.9918390e-13, -2.3370829e-14, -2.3370829e-14, -1.9918390e-13],
[-5.6160772e-14, -3.5145951e-13, -3.5145951e-13, -5.6160772e-14]])
* units('m^2 kg^-1 s^-1'))
* units('kg m^-2 s^-3'))
q2_truth = (np.array([[-4.4976059e-14, -4.3582378e-13, 4.3582378e-13, 4.4976059e-14],
[-3.0124244e-13, -3.5724617e-14, 3.5724617e-14, 3.0124244e-13],
[3.1216232e-13, 3.6662900e-14, -3.6662900e-14, -3.1216232e-13],
[8.6038280e-14, 4.6968342e-13, -4.6968342e-13, -8.6038280e-14]])
* units('m^2 kg^-1 s^-1'))
* units('kg m^-2 s^-3'))

assert_almost_equal(q1, q1_truth, 16)
assert_almost_equal(q2, q2_truth, 16)
Expand Down Expand Up @@ -1840,7 +1840,7 @@ def test_q_vector_4d(data_4d):
[2.50227841e-13, 2.70855069e-13, 4.03362348e-13, 5.22065702e-13],
[3.37119836e-13, 3.17667714e-13, 2.25387106e-13, 6.46265259e-13],
[2.05548507e-13, 3.55426850e-13, -1.74728156e-14,
5.04028133e-13]]]]) * units('m^2 kg^-1 s^-1')
5.04028133e-13]]]]) * units('kg m^-2 s^-3')
q2_truth = np.array([[[[3.34318820e-12, -1.32561232e-13, 1.01510711e-12, 6.03331800e-12],
[2.51737448e-13, -1.71044158e-13, -8.25290924e-13, 1.68843717e-13],
[-3.50533924e-12, -1.68864979e-12, 7.74026063e-13, 1.53811977e-12],
Expand Down Expand Up @@ -1884,7 +1884,7 @@ def test_q_vector_4d(data_4d):
[-1.39578146e-13, -1.36744814e-13, 3.12352497e-14, 4.55339789e-13],
[-1.06614836e-13, -2.19878930e-13, -8.37992151e-14, 1.87868902e-13],
[-2.27057581e-13, -2.74474045e-13, -1.10759455e-13,
-3.90242255e-13]]]]) * units('m^2 kg^-1 s^-1')
-3.90242255e-13]]]]) * units('kg m^-2 s^-3')
assert_array_almost_equal(q1.data, q1_truth, 15)
assert_array_almost_equal(q2.data, q2_truth, 15)

Expand Down

0 comments on commit e1e3ae8

Please sign in to comment.