Air humidity#

Air humidity calculations

This module was written by Matthias Cuntz while at Department of Computational Hydrosystems, Helmholtz Centre for Environmental Research - UFZ, Leipzig, Germany, and continued while at Institut National de Recherche pour l’Agriculture, l’Alimentation et l’Environnement (INRAE), Nancy, France.

copyright:

Copyright 2012- Matthias Cuntz, see AUTHORS.rst for details.

license:

MIT License, see LICENSE for details.

The following functions are provided

eair2mrair(ea, p[, mol, undef])

Mixing ratio from partial pressure of water vapour and total pressure

eair2rhair(ea, T[, undef])

Relative humidity from partial pressure of water vapour and temperature

eair2shair(ea, p[, undef])

Specific humidity from partial pressure of water vapour and total pressure

eair2vpd(ea, T[, undef])

Air vapour pressure deficit from partial pressure and temperature

esat(T[, formula, undef, liquid])

Calculates the saturation vapour pressure over water and/or ice

mrair2eair(mr, p[, mol, undef])

Partial pressure of water vapour from mixing ratio and total pressure

rhair2eair(rh, T[, undef])

Partial pressure of water vapour from relative humidity and temperature

rhair2vpd(rh, T[, undef])

Air vapour pressure deficit from relative humidity and temperature

shair2eair(sh, p[, undef])

Partial pressure of water vapour from specific humidity and total pressure

vpd2eair(vpd, T[, undef])

Partial pressure of vapour from air vapour pressure deficit and temperature

vpd2rhair(vpd, T[, undef])

Relative humidity from air vapour pressure deficit and temperature

History
  • Written Jan 2012 by Matthias Cuntz (mc (at) macu (dot) de)

  • Ported to Python 3, Feb 2013, Matthias Cuntz

  • Changed handling of masked arrays, Oct 2013, Matthias Cuntz

  • Assert T>0, Apr 2014, Matthias Cuntz

  • Using numpy docstring format, May 2020, Matthias Cuntz

  • Ported to pyjams, Jan 2022, Matthias Cuntz

  • Return same type as input type, Jan 2022, Matthias Cuntz

  • Raise AssertionError rather than assuming Celcius, Jan 2022, Matthias Cuntz

  • Use warnings for T < 100 K, Jan 2022, Matthias Cuntz

  • Change handling of return type to allow more (unspecific) iterable types such as pandas time series, Jan 2022, Matthias Cuntz

  • Return numpy array if type(input)(output) fails for unknown iterable types, Jan 2022, Matthias Cuntz

  • Use helper functions input2array and array2input, Jan 2022, Matthias Cuntz

  • Renamed module from esat to to air_humidity, Jan 2023, Matthias Cuntz

  • Added eair2rhair, eair2vpd, rhair2vpd, eair2shair, eair2mrair, Jan 2023, Matthias Cuntz

  • Bug if multi-dimensional array: wrong array index taken for > or < T0, Jun 2023, Matthias Cuntz

eair2mrair(ea, p, mol=False, undef=-9999.0)[source]#

Mixing ratio from partial pressure of water vapour and total pressure

Mixing ratio is the ratio of the mass of water vapour to the total dry mass of the air parcel.

Parameters:
  • ea (float or array_like) – Partial pressure of water vapour [Pa]

  • p (float or array_like) – Total air pressure [Pa]

  • mol (bool, optional) – It True, return mixing ratio in mol/mol instead of kg/kg

  • undef (float, optional) – Exclude undef from calculations (default: -9999.)

Returns:

Mixing ratio [kg/kg] (or in [mol/mol] if mol==True)

Return type:

float or array_like

Examples

>>> mr = eair2mrair(1000., 101325.)
>>> print('{:.2f}'.format(mr * 1000.))
6.20
>>> mr = eair2mrair(1000., 101325., mol=True)
>>> print('{:.2f}'.format(mr * 1000.))
9.97
eair2rhair(ea, T, undef=-9999.0)[source]#

Relative humidity from partial pressure of water vapour and temperature

Relative humidity is the ratio of the partial pressure of water vapour in air to the saturation vapour pressure of water at the same temperature.

\[h = e_a / e_{sat}(T)\]
Parameters:
  • ea (float or array_like) – Partial pressure of water vapour [Pa]

  • T (float or array_like) – Temperature [K]

  • undef (float, optional) – Exclude undef from calculations (default: -9999.)

Returns:

Relative humidity [0-1]

Return type:

float or array_like

Examples

>>> rh = eair2rhair(1000., 293.15)
>>> print('{:.2f}'.format(rh * 100.))
42.81
eair2shair(ea, p, undef=-9999.0)[source]#

Specific humidity from partial pressure of water vapour and total pressure

Specific humidity is the ratio of the mass of water vapour to the total wet mass of the air parcel.

Parameters:
  • ea (float or array_like) – Partial pressure of water vapour [Pa]

  • p (float or array_like) – Total air pressure [Pa]

  • undef (float, optional) – Exclude undef from calculations (default: -9999.)

Returns:

Specific humidity [kg/kg]

Return type:

float or array_like

Examples

>>> sh = eair2shair(1000., 101325.)
>>> print('{:.2f}'.format(sh * 1000.))
6.16
eair2vpd(ea, T, undef=-9999.0)[source]#

Air vapour pressure deficit from partial pressure and temperature

Air vapour pressure deficit is the difference between the saturation vapour pressure of water at a given temperature and the partial pressure of water vapour in air.

\[VPD = e_{sat}(T) - e_a\]
Parameters:
  • ea (float or array_like) – Partial pressure of water vapour [Pa]

  • T (float or array_like) – Temperature [K]

  • undef (float, optional) – Exclude undef from calculations (default: -9999.)

Returns:

Air vapour pressure deficit [Pa]

Return type:

float or array_like

Examples

>>> vpd = eair2vpd(1000., 293.15)
>>> print('{:.2f}'.format(vpd))
1335.85
esat(T, formula='GoffGratch', undef=-9999.0, liquid=False)[source]#

Calculates the saturation vapour pressure over water and/or ice

For temperatures above (and equal to) 0 degree C (273.15 K), the vapour pressure over liquid water is calculated; for temperatures below 0 degree C, the vapour pressure over ice is calculated.

Parameters:
  • T (float or array_like) – Temperature [K]

  • formula (str, optional) –

    Formula name to use for calculations; case-insensitive. Available formulations are: GoffGratch (default) [1], WMO [2], IAPWS [3], MagnusTeten [4], MartiMauersberger [5], Buck_original [6], Buck [7], Wexler [8], Sonntag [9], Bolton [10], Fukuta [11], HylandWexler [12], MurphyKoop [13]

    Note that several formulations do not provide a vapour pressure formulation over ice and Marti and Mauersberger do not provide a formula over liquid: GoffGratch is used in theses cases.

  • undef (float, optional) – Exclude T == undef from calculations (default: -9999.)

  • liquid (bool, optional) – If True, use liquid formula for all temperatures.

Returns:

Saturation water pressure at temperature T in Pascal [Pa].

Return type:

float or array_like

Notes

Taken from Holger Voemel: https://cires.colorado.edu/~voemel/vp.html

References

[1]

Goff Gratch formulation Smithsonian Meteorological Tables, 5th edition, p. 350, 1984 Original source: Goff and Gratch (1946), p. 107

[2]

Intended WMO formulation, originally published by Goff (1957) incorrectly referenced by WMO technical regulations, WMO-NO 49, Vol I, General Meteorological Standards and Recommended Practices, App. A, 1988, Corrigendum Aug 2000

[3]

Wagner W. and A. Pruss (2002) The IAPWS formulation 1995 for the thermodynamic properties of ordinary water substance for general and scientific use, J. Phys. Chem. Ref. Data, 31(2), 387-535 This is the ‘official’ formulation from the International Association for the Properties of Water and Steam The valid range of this formulation is 273.16 <= T <= 647.096 K and is based on the ITS90 temperature scale.

[4]

Murray, F. W., On the computation of saturation vapour pressure, J. Appl. Meteorol., 6, 203-204, 1967

[5]

Marti, J. and K Mauersberger, A survey and new measurements of ice vapour pressure at temperatures between 170 and 250 K, GRL 20, 363-366, 1993

[6]

Bucks vapour pressure formulation based on Tetens formula Buck, A. L., New equations for computing vapour pressure and enhancement factor, J. Appl. Meteorol., 20, 1527-1532, 1981

[7]

Bucks vapour pressure formulation based on Tetens formula Buck Research, Model CR-1A Hygrometer Operating Manual, Sep 2001

[8]

Wexler, A., Vapour pressure formulation for ice Journal of Research of the National Bureau of Standards-A. 81A, 5-20, 1977

[9]

Sonntag, D., Advancements in the field of hygrometry, Meteorol. Z., N. F., 3, 51-66, 1994

[10]

Bolton, D., The computation of equivalent potential temperature Monthly Weather Report, 108, 1046-1053, 1980. equation (10)

[11]

Fukuta, N. and C. M. Gramada, Vapour pressure measurement of supercooled water, J. Atmos. Sci., 60, 1871-1875, 2003 This paper does not give a vapour pressure formulation, but rather a correction over the Smithsonian Tables. Thus calculate the table value first, then use the correction to get to the measured value. This is done only for -39 < TC < 0.

[12]

Hyland, R. W. and A. Wexler, Formulations for the Thermodynamic Properties of the saturated Phases of H2O from 173.15K to 473.15K, ASHRAE Trans, 89(2A), 500-519, 1983

[13]

Murphy and Koop, Review of the vapour pressure of ice and supercooled water for atmospheric applications Q. J. R. Meteorol. Soc (2005), 131, pp. 1539-1565

Examples

>>> print('{:.3f}'.format(esat(293.15)))
2335.847
>>> print('{:.3f}'.format(esat(253.15)))
103.074
>>> print('{:.3f} {:.3f}'.format(*esat([293.15,253.15])))
2335.847 103.074
>>> print('{:.3f} {:.3f}'.format(*esat([293.15,253.15],
...     formula='GoffGratch')))
2335.847 103.074
>>> print('{:.3f} {:.3f}'.format(*esat([293.15,253.15],
...     formula='MartiMauersberger')))
2335.847 103.650
>>> print('{:.3f} {:.3f}'.format(*esat([293.15,253.15],
...     formula='MagnusTeten')))
2335.201 102.771
>>> print('{:.3f} {:.3f}'.format(*esat([293.15,253.15],formula='buck')))
2338.340 103.286
>>> print('{:.3f} {:.3f}'.format(*esat([293.15,253.15],
...     formula='Buck_original')))
2337.282 103.267
>>> print('{:.3f} {:.3f}'.format(*esat([293.15,253.15],formula='wmo')))
2337.080 103.153
>>> print('{:.3f} {:.3f}'.format(*esat([293.15,253.15],formula='WEXLER')))
2323.254 103.074
>>> print('{:.3f} {:.3f}'.format(*esat([293.15,253.15],formula='Sonntag')))
2339.249 103.249
>>> print('{:.3f} {:.3f}'.format(*esat([293.15,253.15],formula='Bolton')))
2336.947 103.074
>>> print('{:.3f} {:.3f}'.format(*esat([293.15,253.15],formula='Fukuta')))
2335.847 103.074
>>> print('{:.3f} {:.3f}'.format(*esat([293.15,253.15],
...     formula='HylandWexler')))
2338.804 103.260
>>> print('{:.3f} {:.3f}'.format(*esat([293.15,253.15],formula='IAPWS')))
2339.194 103.074
>>> print('{:.3f} {:.3f}'.format(*esat([293.15,253.15],
...     formula='MurphyKoop')))
2339.399 103.252
>>> print('{:.3f} {:.3f}'.format(*esat(np.array([293.15,253.15]),
...     liquid=True)))
2335.847 125.292
>>> print('{:.3f} {:.3f}'.format(*esat([293.15,253.15], formula='Fukuta',
...     liquid=True)))
2335.847 125.079
>>> out = esat(np.ma.array([253.15,-9999.], mask=[False,True]))
>>> print('{:.3f} {:.3f}'.format(*out.filled(-9999.)))
103.074 -9999.000
mrair2eair(mr, p, mol=False, undef=-9999.0)[source]#

Partial pressure of water vapour from mixing ratio and total pressure

Mixing ratio is the ratio of the mass of water vapour to the total dry mass of the air parcel.

Parameters:
  • mr (float or array_like) – Mixing ratio [kg/kg] (or in [mol/mol] if mol==True)

  • p (float or array_like) – Total air pressure [Pa]

  • mol (bool, optional) – It True, input mixing ratio is in mol/mol instead of kg/kg

  • undef (float, optional) – Exclude undef from calculations (default: -9999.)

Returns:

Partial pressure of water vapour [Pa]

Return type:

float or array_like

Examples

>>> ea = mrair2eair(0.006, 101325.)
>>> print('{:.2f}'.format(ea))
968.10
>>> ea = mrair2eair(0.006, 101325., mol=True)
>>> print('{:.2f}'.format(ea))
604.32
rhair2eair(rh, T, undef=-9999.0)[source]#

Partial pressure of water vapour from relative humidity and temperature

Relative humidity is the ratio of the partial pressure of water vapour in air to the saturation vapour pressure of water at the same temperature.

\[e_a = h * e_{sat}(T)\]
Parameters:
  • rh (float or array_like) – Relative humidity of air [0-1]

  • T (float or array_like) – Temperature [K]

  • undef (float, optional) – Exclude undef from calculations (default: -9999.)

Returns:

Partial pressure of water vapour [Pa]

Return type:

float or array_like

Examples

>>> ea = rhair2eair(0.5, 293.15)
>>> print('{:.2f}'.format(ea))
1167.92
rhair2vpd(rh, T, undef=-9999.0)[source]#

Air vapour pressure deficit from relative humidity and temperature

Air vapour pressure deficit is the difference between the saturation vapour pressure of water at a given temperature and the partial pressure of water vapour in air.

\[VPD = e_{sat}(T) - h * e_{sat}(T)\]
Parameters:
  • rh (float or array_like) – Relative humidity [0-1]

  • T (float or array_like) – Temperature [K]

  • undef (float, optional) – Exclude undef from calculations (default: -9999.)

Returns:

Air vapour pressure deficit [Pa]

Return type:

float or array_like

Examples

>>> vpd = rhair2vpd(0.5, 293.15)
>>> print('{:.2f}'.format(vpd))
1167.92
shair2eair(sh, p, undef=-9999.0)[source]#

Partial pressure of water vapour from specific humidity and total pressure

Specific humidity is the ratio of the mass of water vapour to the total wet mass of the air parcel.

Parameters:
  • sh (float or array_like) – Specific humidity [kg/kg]

  • p (float or array_like) – Total air pressure [Pa]

  • undef (float, optional) – Exclude undef from calculations (default: -9999.)

Returns:

Partial pressure of water vapour [Pa]

Return type:

float or array_like

Examples

>>> ea = shair2eair(0.006, 101325.)
>>> print('{:.2f}'.format(ea))
973.89
vpd2eair(vpd, T, undef=-9999.0)[source]#

Partial pressure of vapour from air vapour pressure deficit and temperature

Air vapour pressure deficit is the difference between the saturation vapour pressure of water at a given temperature and the partial pressure of water vapour in air.

\[e_a = e_{sat}(T) - VPD\]
Parameters:
  • vpd (float or array_like) – Air vapour pressure deficit [Pa]

  • T (float or array_like) – Temperature [K]

  • undef (float, optional) – Exclude undef from calculations (default: -9999.)

Returns:

Partial pressure of water vapour [Pa]

Return type:

float or array_like

Examples

>>> ea = vpd2eair(1000., 293.15)
>>> print('{:.2f}'.format(ea))
1335.85
vpd2rhair(vpd, T, undef=-9999.0)[source]#

Relative humidity from air vapour pressure deficit and temperature

Air vapour pressure deficit is the difference between the saturation vapour pressure of water at a given temperature and the partial pressure of water vapour in air.

\[h = 1 - VPD / e_{sat}(T)\]
Parameters:
  • vpd (float or array_like) – Air vapour pressure deficit [Pa]

  • T (float or array_like) – Temperature [K]

  • undef (float, optional) – Exclude undef from calculations (default: -9999.)

Returns:

Relative humidity [0-1]

Return type:

float or array_like

Examples

>>> rh = vpd2rhair(1000., 293.15)
>>> print('{:.2f}'.format(rh))
0.57