-
Notifications
You must be signed in to change notification settings - Fork 415
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
Q_Vector returns wrong units #3689
Comments
@sodoesaburningbus thanks for submitting this bug report. The error is in the static stability parameter that is the default value doesn't contain any units, even though the documentation states that the parameter should be a value with units, the default value violates that documentation! |
@kgoebber Good catch and thanks @sodoesaburningbus for the report. I'll note that the reason this isn't currently erroring is because the unit-checking decorator isn't being given a dimensionality for static stability. I'll knock out a quick patch. |
The current test |
There's no reason the units should change in this case, just assign proper units to the default unity value of static stability.
I needed to check back with #661 and the textbooks to confirm this, but from what I recalled the unit difference was intended behavior, as it was accounting for differing definitions of Q-Vector (between Holton and Bluestein...Holton doesn't include the 1/sigma factor). Of course, over-6-year-ago me didn't clarify this in the docstring, so the mismatch in expectations is certainly understandable! Though, @sodoesaburningbus, I did want to check: you mentioned expected units as |
There's no reason the units should change in this case, just assign proper units to the default unity value of static stability.
I have #3690, but I do think we need to think hard about the default for the static stability parameter to |
I now also took a look at Holton (4th ed.) and what is done there is keeping the static stability parameter on the operator side of the equation, which is different than what was done in the traditional QG-omega equation. Why he didn't divide that through in the same fashion to define Q is left unknown. In the Holton and Hakim (5th ed.), Q is derived in a substantially different manner (as is done in other parts of the text as well) from what had been the case through the first four editions. The equation is geared more toward a constant height as opposed to a constant pressure derivation. Lackmann (2011) follows Bluestein, whereas Martin (2005) follows Holton (4th ed). So clear as mud. I think the leaving of the static stability parameter on the operator side is more done of convenience in writing the equation. In the end, static stability is one of the largest factors in modulating rising motion that is not either vorticity advection, temperature advection, or diabatic processes. As a result, this would be why I would advocate for using static stability with units in our function as opposed to not using it. Additionally, since we publish the Bluestein equation, which includes the static stability parameter, it seems logical that we would produce the calculation with the appropriate units for that particular equation. |
Thank you for the rapid response. It was actually one of my students who
caught the bug.
|
It might also be worth checking to see how GEMPAK handles (or doesn't handle) the static stability parameter, if we are looking for feature parity. Or perhaps an optional argument to choose which flavor of the Q-vector to compute. |
I've looked into this in more detail. First, GEMPAK has two Q-vector functions, QVEC, which doesn't include the static stability parameter, and QVCL, which does. Second, in the original Hoskins et al. (1978) paper that introduced Q-vectors (which uses a similar vertical coordinate as Holton/Hakim 5th ed), the static stability parameter ( Thus, the extant literature and software out there seems about equally divided. I think we should leave it up to the user. If they call I would agree with @dopplershift that just tacking on units to the default value of 1 is not a good solution, since a value of 1 with SI units would be a pretty implausible value for Regarding this comment:
The documentation I see says "static_stability (pint.Quantity, optional) – The static stability at the pressure level. Defaults to 1 if not given to calculate the Q-vector without factoring in static stability." This seems to match the current implementation as far as I can tell. |
@jthielen and I chatted during our MetPy call and I think we're in agreement with the last comment from @sgdecker and there isn't really a bug here. The ways I want to address this:
@kgoebber @sodoesaburningbus Does that seem reasonable? Anything else to add to make this more clear for the future? |
That seems reasonable, particularly better documentation of the
static_stability behavior.
Thank you very much for diving so far into this!
|
What went wrong?
mpcalc.q_vector returns values with units of m2/kg/s. Appropriate units should be kg/m2/s2.
Operating System
Windows
Version
1.6.2
Python Version
3.12
Code to Reproduce
Errors, Traceback, and Logs
The text was updated successfully, but these errors were encountered: