Bug in `virtual_temperature_from_mixing_ratio`-function
Bug in virtual_temperature_from_mixing_ratio
-function:
The wrong formula for the calculation is used:
It is based on the formula in Wikipedia, but insead of using \varepsilon = \frac{R_{dry air}}{R_w}, \varepsilon = \frac{R_w}{R_{dry air}} is used.
Example
T_v = temperature.virtual_temperature_from_mixing_ratio(
temperature=units.Quantity(30, units.celsius),
mixing_ratio=5 / 1000).to(units.celsius)
T_v is smaller than 30掳C, but it has to be 30.91 掳C
Possible fix
def virtual_temperature_from_mixing_ratio(temperature, mixing_ratio):
r"""
Calculate the virtual temperature :math:`T_\mathrm{v}` via the
mixing_ratio :math:`r`:
.. math::
T_\mathrm{v} = T \cdot
\frac{r + \frac{R_\mathrm{dry air}}{R_\mathrm{w}}}
{
\frac{R_\mathrm{dry air}}{R_\mathrm{w}}
\cdot \left( 1 + r \right)
}
https://en.wikipedia.org/wiki/Virtual_temperature#Variations
"""
ratio = (
constants.GAS_CONSTANT_DRY_AIR / constants.GAS_CONSTANT_WATER_VAPOUR
)
return temperature * (mixing_ratio + ratio) / (ratio * (1 + mixing_ratio))