1

The mean pressure weighted function defined here seems to be based on an odd formulation(see code below). Holton(fifth edition ,page 86), and many otheres calculate the sum the of the desired variable multiplied by dp and not by pdp as shown in the code below. Also most authors normalize the result by summation of dp which is sufrace pressure - top pressure. Yet, the code below use sufrace pressure^2 - top pressure^2. Is there is any reference for the formula used below. Thanks

# Taking the integral of the weights (pressure) to feed into the weighting
# function. Said integral works out to this function:
pres_int = 0.5 * (pres_prof[-1] ** 2 - pres_prof[0] ** 2)

# Perform integration on the profile for each variable
return [np.trapz(var_prof * pres_prof, x=pres_prof) / pres_int for var_prof in others]
Kernel
  • 591
  • 12
  • 23

1 Answers1

1

Unfortunately I don't have access to my copy of Holton right now, so I can't look at what's done there. I can say that if you weight by dp rather than p * dp, you're not calculating the pressure weighted mean, you're only calculating the mean.

The formula used falls out directly from the definition of a weighted average using an integral, most importantly:

enter image description here

When you substitute in w(x) as p and dx as p you get the integral of p * dp, which has an antiderivative of p**2.

It would probably be useful to add to MetPy a function that does the same set of integrals without any weighting, since that is different than simply using numpy.mean.

DopplerShift
  • 5,472
  • 1
  • 21
  • 20
  • Thanks, Not sure if there is a description for the formulas used by the functions provided by the MetPy. I thought that they are calculating the weighted (normalized) vertical integeration, like that calculated by NCL www.ncl.ucar.edu/Document/Functions/Built-in/vibeta.shtml . I think that the weighted vertical integration might be vague, it could be understood as the vertical integeration of variable divided by the integration of dp. or it could be understood in terms of the equation you provided above. – – Kernel Sep 11 '21 at 12:28
  • 1
    Yeah, we could definitely be more clear. I opened an issue about that: https://github.com/Unidata/MetPy/issues/2094 – DopplerShift Sep 11 '21 at 16:50
  • Hi again, The formula given above for the weighted average is different from the one documented here https://unidata.github.io/MetPy/latest/api/generated/metpy.calc.weighted_continuous_average.html#metpy.calc.weighted_continuous_average is the one listed here (StackOverflow) is the old version of the function? – Kernel Mar 26 '23 at 11:49
  • The formula above is correct for `mean_pressure_weighted`. `weighted_continuous_average` is the name for an average of a continuous variable that doesn't do any specific weighting and is a different formula--you need to remove w(x) from the above to get that. – DopplerShift Mar 27 '23 at 19:21
  • For clarity, just wondering if the equation above could be added to the definition of the ```mean_pressure_weighted``` as has been done to the ```weighted_continous_average```. Also, Holton defines the mean pressure weighted as the one used without any additional weights, which is opposite to what is defined by the ```mean_pressure_weighted```. I think that ```mean_pressure_weighted``` should be called ```weighted_continous_average``` and vice versa. – Kernel Mar 27 '23 at 23:28
  • 1
    Done in https://github.com/Unidata/MetPy/pull/2971 – DopplerShift Mar 28 '23 at 20:37