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]
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:
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
.