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

Fix q_vector units w/ default static stability #3690

Merged
merged 2 commits into from
Jan 6, 2025
Merged
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
6 changes: 4 additions & 2 deletions examples/calculations/QVector.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
# Calculate the temperature advection of the flow
tadv = mpcalc.advection(ds.temperature, ds.uwind, ds.vwind)

# Calculate the q-vectors
u_qvect, v_qvect = mpcalc.q_vector(ds.uwind, ds.vwind, ds.temperature, 850 * units.hPa)
# Calculate the q-vectors. Passing in a fixed value of static stability, but could also
# use `mpcalc.static_stability()`.
u_qvect, v_qvect = mpcalc.q_vector(ds.uwind, ds.vwind, ds.temperature, 850 * units.hPa,
static_stability=0.02 * units('J / kg / Pa^2'))

# start figure and set axis
fig, ax = plt.subplots(figsize=(5, 5))
Expand Down
9 changes: 8 additions & 1 deletion src/metpy/calc/kinematics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1275,7 +1275,8 @@ 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,
Expand Down Expand Up @@ -1307,6 +1308,12 @@ def q_vector(
- 2 \nabla_p \cdot \vec{Q} -
\frac{R}{\sigma p} \beta \frac{\partial T}{\partial x}
By default, this function uses a unitless value of 1 for ``static_stability``, which
replicates the functionality of the GEMPAK ``QVEC`` function. If a value is given for
``static_stability``, it should have dimensionality of ``energy / mass / pressure^2``, and
will result in behavior that matches that of GEMPAK's ``QVCL`` function;
`static_stability` can be used to calculate this value if desired.
Parameters
----------
u : (..., M, N) `xarray.DataArray` or `pint.Quantity`
Expand Down
Loading