<p>It looks like your program is using an approximation based on
$q \approx w = w_s*RH$ with an approximation of Clausius-Clapeyron to find $w_s$.  Looking at a few values of RH,T and P, your approximation is pretty close (+/- 5%) to an analytic answer.  Based on the output you quoted it looks like you are providing incorrect values of RH.  Note in the comments to your routine it says:</p>

<pre><code>@param rh relative humidity (proportion, not %) 
</code></pre>

<p>This means you need to provide the RH proportion, not the percentage.  E.g. divide by 100 -- RH=1 for 100%, RH=0.5 for 50%, etc.  </p>

<p>If you adjust your input data you should be able to use your code as-is.  If you wish to compare it to something, you can reference the solution below.</p>

<hr>

<p>If you are given $RH$ (in the range [0,1]), $T$ (K) and $p$ (Pa) you can proceed as follows.</p>

<p>Knowing that $$RH = \dfrac{e}{e_s},$$ $$w = \dfrac{e\ R_d}{R_v(p-e)},$$ and $$q = \dfrac{w}{w+1}$$</p>

<p>Then we can solve for specific humidity $q$.</p>

<p>Rather than combining this into a single formula and solving, it is more straightforward to present this incrementally.</p>

<p>First, find $e_s(T)$ where $$e_s(T) = e_{s0}\exp\left[\left(\dfrac{L_v(T)}{R_v}\right)\left(\dfrac{1}{T_0}-\dfrac{1}{T}\right)\right]$$ and then find $e$ from the first formula ($e = RH*e_s$).  Then plug $e$ into the formula for $w$ and then that result into the formula for $q$. </p>

<hr>

<p>Variables used:<br>
<sub>
$q$ specific humidity or the mass mixing ratio of water vapor to total air (dimensionless)<br>
$w$ mass mixing ratio of water vapor to dry air (dimensionless)<br>
$e_s(T)$ saturation vapor pressure (Pa)<br>
$e_{s0}$ saturation vapor pressure at $T_0$ (Pa)<br>
$R_d$ specific gas constant for dry air (J kg$^{-1}$ K$^{-1}$)<br>
$R_v$ specific gas constant for water vapor (J kg$^{-1}$ K$^{-1}$)<br>
$p$ pressure (Pa)<br>
$L_v(T)$ specific enthalpy of vaporization (J kg$^{-1}$)<br>
$T$ temperature (K)<br>
$T_0$ reference temperature (typically 273.16 K) (K)<br>
</sub></p>

CC BY-SA 3.0
2016-10-20T09:11:11.957Z
How is $L_v(T)$, the specific enthalpy of vaporization, calculated? Is it a function of temperature?
Christo
CC BY-SA 3.0
2015-06-28T01:09:41.170Z
2015-06-28T01:55:15.570Z
2015-06-28T01:55:15.570Z
casey
<p>I know there is this question already <a href="https://earthscience.stackexchange.com/questions/5050/how-do-i-convert-relative-humidity-into-specific-humidity">How do I convert Relative Humidity into specific humidity</a></p>

<p>but I don't have ρws = density of water vapor (kg/m3) and ρ = density of the moist or humid air (kg/m3).</p>

<p>Is there another way to calculate it? Also I have air pressure but it's in the range of 95000-96000.</p>

<p>I have used the <a href="https://github.com/PecanProject/pecan/blob/master/modules/data.atmosphere/R/metutils.R" rel="nofollow noreferrer">rh2qair</a> function from the <a href="https://github.com/PecanProject/pecan/tree/master/modules/data.atmosphere" rel="nofollow noreferrer">PEcAn data.atmosphere R package</a> but I get values such as 1.5463 converts relative humidity to specific humidity</p>

<pre><code>    @title RH to SH 
    @param rh relative humidity (proportion, not %) 
    @param T absolute temperature (Kelvin) 
    @export 
    @author Mike Dietze @aliases rh2rv 
    rh2qair &lt;- function(rh, T) {   
        qair &lt;- rh * 2.541e6 * exp(-5415.0 / T) * 18/29   
        return(qair) 
    }
</code></pre>

CC BY-SA 3.0
2015-06-28T01:16:30.843Z
What input are you providing (rh, T) that gives you the quoted answer?
casey
CC BY-SA 3.0
2015-06-28T02:01:24.860Z
Looks like you are passing rh in % rather than proportion, I've updated my answer to reflect this.
casey
CC BY-SA 3.0
2015-07-02T15:10:50.740Z
note that we've recently [updated this function (to take pressure as an argument)](https://github.com/PecanProject/pecan/commit/572b7a70bc7c50ac999467659504ccc32ef5d92d), per discussions in [this thread on github](https://github.com/PecanProject/pecan/issues/518). And make it more consistent with the qair2rh function discussed in a separate question http://earthscience.stackexchange.com/a/2385/174
David LeBauer
<meteorology><atmosphere><humidity>
How to calculate specific humidity with relative humidity, temperature, and pressure
Herman Toothrot
# How to calculate specific humidity with relative humidity, temperature, and pressure

(Asked by: username_0 on 2015-06-27)

I know there is this question already [How do I convert Relative Humidity into specific humidity](https://earthscience.stackexchange.com/questions/5050/how-do-i-convert-relative-humidity-into-specific-humidity)

but I don't have ρws = density of water vapor (kg/m3) and ρ = density of the moist or humid air (kg/m3).

Is there another way to calculate it? Also I have air pressure but it's in the range of 95000-96000.

I have used the [rh2qair](https://github.com/PecanProject/pecan/blob/master/modules/data.atmosphere/R/metutils.R) function from the [PEcAn data.atmosphere R package](https://github.com/PecanProject/pecan/tree/master/modules/data.atmosphere) but I get values such as 1.5463 converts relative humidity to specific humidity

```
    @title RH to SH 
    @param rh relative humidity (proportion, not %) 
    @param T absolute temperature (Kelvin) 
    @export 
    @author Mike Dietze @aliases rh2rv 
    rh2qair <- function(rh, T) {   
        qair <- rh * 2.541e6 * exp(-5415.0 / T) * 18/29   
        return(qair) 
    }

```

**Tags:** meteorology, atmosphere, humidity

> **Comments:**
> **username_1**: What input are you providing (rh, T) that gives you the quoted answer?  
> **username_1**: Looks like you are passing rh in % rather than proportion, I've updated my answer to reflect this.  
> **username_2**: note that we've recently [updated this function (to take pressure as an argument)](https://github.com/PecanProject/pecan/commit/572b7a70bc7c50ac999467659504ccc32ef5d92d), per discussions in [this thread on github](https://github.com/PecanProject/pecan/issues/518). And make it more consistent with the qair2rh function discussed in a separate question http://earthscience.stackexchange.com/a/2385/174  

---

## 1 answers

### Answer by username_1 on 2015-06-28. Score: 7 | Accepted answer

It looks like your program is using an approximation based on
$q \approx w = w\_s\*RH$ with an approximation of Clausius-Clapeyron to find $w\_s$. Looking at a few values of RH,T and P, your approximation is pretty close (+/- 5%) to an analytic answer. Based on the output you quoted it looks like you are providing incorrect values of RH. Note in the comments to your routine it says:

```
@param rh relative humidity (proportion, not %) 

```

This means you need to provide the RH proportion, not the percentage. E.g. divide by 100 -- RH=1 for 100%, RH=0.5 for 50%, etc.

If you adjust your input data you should be able to use your code as-is. If you wish to compare it to something, you can reference the solution below.

---

If you are given $RH$ (in the range [0,1]), $T$ (K) and $p$ (Pa) you can proceed as follows.

Knowing that $$RH = \dfrac{e}{e\_s},$$ $$w = \dfrac{e\ R\_d}{R\_v(p-e)},$$ and $$q = \dfrac{w}{w+1}$$

Then we can solve for specific humidity $q$.

Rather than combining this into a single formula and solving, it is more straightforward to present this incrementally.

First, find $e\_s(T)$ where $$e\_s(T) = e\_{s0}\exp\left[\left(\dfrac{L\_v(T)}{R\_v}\right)\left(\dfrac{1}{T\_0}-\dfrac{1}{T}\right)\right]$$ and then find $e$ from the first formula ($e = RH\*e\_s$). Then plug $e$ into the formula for $w$ and then that result into the formula for $q$.

---

Variables used:  
$q$ specific humidity or the mass mixing ratio of water vapor to total air (dimensionless)  
$w$ mass mixing ratio of water vapor to dry air (dimensionless)  
$e\_s(T)$ saturation vapor pressure (Pa)  
$e\_{s0}$ saturation vapor pressure at $T\_0$ (Pa)  
$R\_d$ specific gas constant for dry air (J kg$^{-1}$ K$^{-1}$)  
$R\_v$ specific gas constant for water vapor (J kg$^{-1}$ K$^{-1}$)  
$p$ pressure (Pa)  
$L\_v(T)$ specific enthalpy of vaporization (J kg$^{-1}$)  
$T$ temperature (K)  
$T\_0$ reference temperature (typically 273.16 K) (K)

> **Comments:**
> **username_3**: How is $L_v(T)$, the specific enthalpy of vaporization, calculated? Is it a function of temperature?  

---

