I'm trying to make a weather simulator using the article Interactive Meso-scale Simulation of Skyscapes. It gives the formula for calculating the mean static energy:

$$MSE_i = C_p \cdot T_i + g \cdot \Theta_i + L_v \cdot Q_i$$

But I don't understand how to calculate specific humidity, the article says that it can be calculated using absolute humidity ($H_i$) and height above the ground ($\Theta_i$) (quote: $Q_i$ is the specific humidity of the air layer (and can be derived from $H_i$ and $\Theta_i$)). Is there any specific formula for calculating specific humidity or am I missing something?

Update 1.

So I have implemented a function to calculate specific humidity in python. Here AH is the absolute humidity in $g/m^3$, p is the pressure in pascals at the calculation point and t is temperature in Celsius.

def get_specific_humidity(AH, t, p):
    e = (AH / 1000) * 461.5 * (t + 273.15)
    r =  (0.622 * e) / (p - e)
    return r / (1 + r)

First I calculated the vapor pressure e using the formula: $$\frac{m}{V} = \frac{e}{R_vT}$$ The calculation assumes that the dry air is evenly mixed with water. Also $R_v=461.5$ is specific gas constant for water vapor. Next, I calculated the mixing ratio using this equation:


And finally using the mixing ratio it is possible to calculate the specific humidity: $$q=\frac{r}{1+r}$$

Did I do everything right?


1 Answer 1


The specific humidity is the ratio of the mass of water vapor to the total mass of the air parcel. The absolute humidity is the mass of the water vapor by the volume of the air parcel. To connect both, you simply need the density of air, which you can estimate from the height above ground by assuming some standard atmosphere.

So, you can not, without further assumptions calculate the specific humidity by using absolute humidity and height above ground, but you can get a fair estimate using some standard assumption.

  • $\begingroup$ Okay, I assume that air consists of a mixture of dry air and water vapor. At the same time this mixture is evenly mixed. I also use a standard ISO atmosphere. Can I calculate the specific humidity based on these assumptions? $\endgroup$
    – w.ilia.m
    Feb 22, 2023 at 10:51
  • $\begingroup$ Yes. From the standard atmosphere assumption, you can get the pressure depending on height p(H) and, hence, also the density. $\endgroup$
    – hschoell
    Feb 22, 2023 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.