<p>I have a netCDF file of stream function (psi) having dimension (latitude, level), level is pressure level. There are 5 pressure levels (700,600,500,400,300 hPa). I need to compute the mass weighted vertical average, i.e. before averaging I need to know the atmospheric mass at each pressure level which will be their weights and after that, average of psi will be computed. The final output will be one dimensional i.e. (latitude,). How to compute this weight and how to do it in Python?</p>

CC BY-SA 4.0
2023-09-15T06:27:47.393Z
Have you looked at MetPy's implementation - https://unidata.github.io/MetPy/latest/api/generated/metpy.calc.mixed_layer.html#metpy.calc.mixed_layer ?
gansub
CC BY-SA 4.0
2023-09-15T10:03:09.053Z
I think it is used only when psi will be having only one value at each level. In the above problem psi is having values at each latitude for all levels. Also, in the MetPY documentation ,in the Note section it has been written that "Only functions on 1D profiles not higher-dimension vertical cross sections or grids."
Aman
CC BY-SA 4.0
2023-09-15T10:13:55.603Z
I gave you a hint on how to do it . I did not say anywhere that has to be the final solution. If you are dealing with a big problem and are a python newbie then the first thing to know is to split the problem in smaller steps and ask questions on smaller problem.  Also you can write an enhancement request on MetPy and maybe they can tell you how to use their software as you want it.
gansub
<meteorology><python><pressure>
Mass weighted vertical average of stream function in python
Aman
# Mass weighted vertical average of stream function in python

(Asked by: username_0 on 2023-09-15)

I have a netCDF file of stream function (psi) having dimension (latitude, level), level is pressure level. There are 5 pressure levels (700,600,500,400,300 hPa). I need to compute the mass weighted vertical average, i.e. before averaging I need to know the atmospheric mass at each pressure level which will be their weights and after that, average of psi will be computed. The final output will be one dimensional i.e. (latitude,). How to compute this weight and how to do it in Python?

**Tags:** meteorology, python, pressure

> **Comments:**
> **username_1**: Have you looked at MetPy's implementation - https://unidata.github.io/MetPy/latest/api/generated/metpy.calc.mixed_layer.html#metpy.calc.mixed_layer ?  
> **username_0**: I think it is used only when psi will be having only one value at each level. In the above problem psi is having values at each latitude for all levels. Also, in the MetPY documentation ,in the Note section it has been written that "Only functions on 1D profiles not higher-dimension vertical cross sections or grids."  
> **username_1**: I gave you a hint on how to do it . I did not say anywhere that has to be the final solution. If you are dealing with a big problem and are a python newbie then the first thing to know is to split the problem in smaller steps and ask questions on smaller problem.  Also you can write an enhancement request on MetPy and maybe they can tell you how to use their software as you want it.  

---

## 0 answers

