atmos package reference¶

Module contents¶

atmos¶

An atmospheric sciences utility library¶

atmos is a library of Python programming utilities for the atmospheric sciences. It is in ongoing development.

Information on how to use the module can be found predominantly by using the built-in help() function in Python. Many docstrings are automatically generated by the module and so information may appear to be missing in the source code. HTML documentation will be available at a later date.

This module is currently alpha. The API of components at the base module level should stay backwards-compatible, but sub-modules are subject to change. In particular, features in the util module are likely to be changed or removed entirely.

atmos.constants module¶

constants.py: Scientific constants in SI units.

Included constants:

• g0 : standard acceleration of gravity
• r_earth : mean radius of Earth
• Omega : angular velocity of Earth
• Rd : specific gas constant for dry air
• Rv : specific gas constant for water vapor
• Cpd : specific heat capacity of dry air at constant pressure at 300K
• Cl : specific heat capacity of liquid water
• Lv0 : latent heat of vaporization for water at 0C

atmos.decorators module¶

decorators.py: Function decorators used by the rest of this module.

atmos.decorators.assumes(*args)

Stores a function’s assumptions as an attribute.

atmos.decorators.equation_docstring(quantity_dict, assumption_dict, equation=None, references=None, notes=None)

Creates a decorator that adds a docstring to an equation function.

Parameters: quantity_dict (dict) – A dictionary describing the quantities used in the equations. Its keys should be abbreviations for the quantities, and its values should be a dictionary of the form {‘name’: string, ‘units’: string}. assumption_dict (dict) – A dictionary describing the assumptions used by the equations. Its keys should be short forms of the assumptions, and its values should be long forms of the assumptions, as you would insert into the sentence ‘Calculates (quantity) assuming (assumption 1), (assumption 2), and (assumption 3).’ equation (string, optional) – A string describing the equation the function uses. Should be wrapped to be no more than 80 characters in length. references (string, optional) – A string providing references for the function. Should be wrapped to be no more than 80 characters in length. ValueError – If the function name does not follow (varname)_from_(any text here), or if an argument of the function or the varname (as above) is not present in quantity_dict, or if an assumption in func.assumptions is not present in the assumption_dict.
atmos.decorators.overridden_by_assumptions(*args)

Stores what assumptions a function is overridden by as an attribute.

atmos.equations module¶

equations.py: Fluid dynamics equations for atmospheric sciences.

atmos.equations.AH_from_qv_rho(qv, rho)

Calculates absolute humidity (kg/m^3).

$$AH = q_v \rho$$

Parameters: qv (float or ndarray) – Data for specific humidity (kg/kg). rho (float or ndarray) – Data for density (kg/m^3). AH – Data for absolute humidity (kg/m^3). float or ndarray
atmos.equations.DSE_from_T_Phi(T, Phi)

Calculates dry static energy (J).

$$DSE = C_{pd} T + \Phi$$

Parameters: T (float or ndarray) – Data for temperature (K). Phi (float or ndarray) – Data for geopotential (m^2/s^2). DSE – Data for dry static energy (J). float or ndarray
atmos.equations.DSE_from_T_z(T, z)

Calculates dry static energy (J) assuming g is constant.

$$DSE = C_{pd} T + g_0 z$$

Parameters: T (float or ndarray) – Data for temperature (K). z (float or ndarray) – Data for height (m). DSE – Data for dry static energy (J). float or ndarray
atmos.equations.Gammam_from_rvs_T(rvs, T)

Calculates moist adiabatic lapse rate (K/m) assuming g is constant and latent heat of vaporization of water is constant.

$$Gammam = g_0 \frac{1+\frac{L_{v0}*r_{vs}}{R_d T}}{C_{pd}+\frac{L_{v0}^2*r_{vs}}{R_v T^2}}$$

Parameters: rvs (float or ndarray) – Data for saturation water vapor mixing ratio with respect to liquid water (kg/kg). T (float or ndarray) – Data for temperature (K). Gammam – Data for moist adiabatic lapse rate (K/m). float or ndarray

Notes

References

American Meteorological Society Glossary of Meteorology
atmos.equations.MSE_from_DSE_qv(DSE, qv)

Calculates moist static energy (J) assuming latent heat of vaporization of water is constant.

$$MSE = DSE + L_{v0} q_v$$

Parameters: DSE (float or ndarray) – Data for dry static energy (J). qv (float or ndarray) – Data for specific humidity (kg/kg). MSE – Data for moist static energy (J). float or ndarray
atmos.equations.Phi_from_z(z)

Calculates geopotential (m^2/s^2) assuming g is constant.

$$Phi = g_0 z$$

Parameters: z (float or ndarray) – Data for height (m). Phi – Data for geopotential (m^2/s^2). float or ndarray
atmos.equations.RH_from_qv_qvs_lwv(qv, qvs)

Calculates relative humidity with respect to liquid water (percent) assuming terms that are second-order in moisture quantities can be neglected (eg. qv == rv).

$$RH = \frac{q_{v}}{q_{vs}} \times 100$$

Parameters: qv (float or ndarray) – Data for specific humidity (kg/kg). qvs (float or ndarray) – Data for saturation specific humidity with respect to liquid water (kg/kg). RH – Data for relative humidity with respect to liquid water (percent). float or ndarray
atmos.equations.RH_from_rv_rvs(rv, rvs)

Calculates relative humidity with respect to liquid water (percent).

$$RH = \frac{r_v}{r_{vs}} \times 100$$

Parameters: rv (float or ndarray) – Data for water vapor mixing ratio (kg/kg). rvs (float or ndarray) – Data for saturation water vapor mixing ratio with respect to liquid water (kg/kg). RH – Data for relative humidity with respect to liquid water (percent). float or ndarray
atmos.equations.RHi_from_qv_qvsi_lwv(qv, qvsi)

Calculates relative humidity with respect to ice (percent) assuming terms that are second-order in moisture quantities can be neglected (eg. qv == rv).

$$RH_i = \frac{q_{v}}{q_{vsi}} \times 100$$

Parameters: qv (float or ndarray) – Data for specific humidity (kg/kg). qvsi (float or ndarray) – Data for saturation specific humidity with respect to ice (kg/kg). RHi – Data for relative humidity with respect to ice (percent). float or ndarray
atmos.equations.RHi_from_rv_rvsi(rv, rvsi)

Calculates relative humidity with respect to ice (percent).

$$RH_i = \frac{r_v}{r_{vsi}} \times 100$$

Parameters: rv (float or ndarray) – Data for water vapor mixing ratio (kg/kg). rvsi (float or ndarray) – Data for saturation water vapor mixing ratio with respect to ice (kg/kg). RHi – Data for relative humidity with respect to ice (percent). float or ndarray
atmos.equations.T_from_Tv_assuming_Tv_equals_T(Tv)

Calculates temperature (K) assuming the virtual temperature correction can be neglected.

$$T = T_v$$

Parameters: Tv (float or ndarray) – Data for virtual temperature (K). T – Data for temperature (K). float or ndarray

Notes

This function exists to allow using temperature as virtual temperature.

atmos.equations.T_from_Tv_rv(Tv, rv)

Calculates temperature (K).

$$T = T_v \frac{1 + r_v}{1+ \frac{r_v}{0.622}$$

Parameters: Tv (float or ndarray) – Data for virtual temperature (K). rv (float or ndarray) – Data for water vapor mixing ratio (kg/kg). T – Data for temperature (K). float or ndarray

Notes

Neglects density effects of liquid and solid water

atmos.equations.T_from_Tv_rv_lwv(Tv, rv)

Calculates temperature (K) assuming terms that are second-order in moisture quantities can be neglected (eg. qv == rv).

$$T = \frac{T_v}{1 + (\frac{1}{0.622} - 1) r_v}$$

Parameters: Tv (float or ndarray) – Data for virtual temperature (K). rv (float or ndarray) – Data for water vapor mixing ratio (kg/kg). T – Data for temperature (K). float or ndarray

Notes

Neglects density effects of liquid and solid water

atmos.equations.T_from_es_Bolton(es)

Calculates temperature (K) assuming the assumptions in Bolton (1980) hold.

$$T = \frac{29.65 log(es)-4880.16}{log(es)-19.48}$$

Parameters: es (float or ndarray) – Data for saturation water vapor partial pressure over water (Pa). T – Data for temperature (K). float or ndarray

Notes

Fits Wexler’s formula to an accuracy of 0.1% for temperatures between -35C and 35C.

References

Bolton, D. 1980: The Computation of Equivalent Potential Temperature.
Mon. Wea. Rev., 108, 1046-1053. doi: http://dx.doi.org/10.1175/1520-0493(1980)108<1046:TCOEPT>2.0.CO;2
Wexler, A. (1976): Vapor pressure formulation for water in range 0 to
100 C. A revision. J. Res. Natl. Bur. Stand. A, 80, 775-785.
atmos.equations.T_from_p_e_Tv(p, e, Tv)

Calculates temperature (K).

$$T = T_v (1-\frac{e}{p}(1-0.622))$$

Parameters: p (float or ndarray) – Data for pressure (Pa). e (float or ndarray) – Data for water vapor partial pressure (Pa). Tv (float or ndarray) – Data for virtual temperature (K). T – Data for temperature (K). float or ndarray

Notes

Neglects density effects of liquid and solid water

atmos.equations.T_from_p_theta(p, theta)

Calculates temperature (K) assuming Cp is constant and equal to Cp for dry air at 0C.

$$T = \theta (\frac{10^5}{p})^{-\frac{R_d}{C_{pd}}}$$

Parameters: p (float or ndarray) – Data for pressure (Pa). theta (float or ndarray) – Data for potential temperature (K). T – Data for temperature (K). float or ndarray
atmos.equations.Td_from_e_Bolton(e)

Calculates dewpoint temperature (K) assuming the assumptions in Bolton (1980) hold.

$$T_d = \frac{17.67*273.15 - 29.65 ln(\frac{e}{611.2})}{17.67-ln(\frac{e}{611.2})}$$

Parameters: e (float or ndarray) – Data for water vapor partial pressure (Pa). Td – Data for dewpoint temperature (K). float or ndarray

Notes

Obtained by inverting Bolton’s formula, es(Td) = T.

References

Bolton, D. 1980: The Computation of Equivalent Potential Temperature.
Mon. Wea. Rev., 108, 1046-1053. doi: http://dx.doi.org/10.1175/1520-0493(1980)108<1046:TCOEPT>2.0.CO;2
atmos.equations.Tlcl_from_T_RH(T, RH)

Calculates temperature at lifting condensation level (K) assuming the assumptions in Bolton (1980) hold.

$$T_{lcl} = ((\frac{1}{T-55}-(\frac{log(\frac{RH}{100})}{2840}))^{-1} + 55$$

Parameters: T (float or ndarray) – Data for temperature (K). RH (float or ndarray) – Data for relative humidity with respect to liquid water (percent). Tlcl – Data for temperature at lifting condensation level (K). float or ndarray

Notes

Uses Bolton (1980) equation 22.

References

Bolton, D. 1980: The Computation of Equivalent Potential Temperature.
Mon. Wea. Rev., 108, 1046-1053. doi: http://dx.doi.org/10.1175/1520-0493(1980)108<1046:TCOEPT>2.0.CO;2
atmos.equations.Tlcl_from_T_Td(T, Td)

Calculates temperature at lifting condensation level (K) assuming the assumptions in Bolton (1980) hold.

$$T_{lcl} = ((1./(Td-56.))-(log(T/Td)/800.))^{-1} + 56.$$

Parameters: T (float or ndarray) – Data for temperature (K). Td (float or ndarray) – Data for dewpoint temperature (K). Tlcl – Data for temperature at lifting condensation level (K). float or ndarray

Notes

Uses Bolton (1980) equation 15.

References

Bolton, D. 1980: The Computation of Equivalent Potential Temperature.
Mon. Wea. Rev., 108, 1046-1053. doi: http://dx.doi.org/10.1175/1520-0493(1980)108<1046:TCOEPT>2.0.CO;2
atmos.equations.Tlcl_from_T_e(T, e)

Calculates temperature at lifting condensation level (K) assuming the assumptions in Bolton (1980) hold.

$$T_{lcl} = \frac{2840}{3.5 log(T) - log(e) - 4.805} + 55$$

Parameters: T (float or ndarray) – Data for temperature (K). e (float or ndarray) – Data for water vapor partial pressure (Pa). Tlcl – Data for temperature at lifting condensation level (K). float or ndarray

Notes

Uses Bolton(1980) equation 21.

References

Bolton, D. 1980: The Computation of Equivalent Potential Temperature.
Mon. Wea. Rev., 108, 1046-1053. doi: http://dx.doi.org/10.1175/1520-0493(1980)108<1046:TCOEPT>2.0.CO;2
atmos.equations.Tv_from_T_assuming_Tv_equals_T(T)

Calculates virtual temperature (K) assuming the virtual temperature correction can be neglected.

$$T_v = T$$

Parameters: T (float or ndarray) – Data for temperature (K). Tv – Data for virtual temperature (K). float or ndarray

Notes

This function exists to allow using temperature as virtual temperature.

atmos.equations.Tv_from_T_rv(T, rv)

Calculates virtual temperature (K).

$$T_v = T \frac{1 + \frac{r_v}{0.622}}{1+r_v}$$

Parameters: T (float or ndarray) – Data for temperature (K). rv (float or ndarray) – Data for water vapor mixing ratio (kg/kg). Tv – Data for virtual temperature (K). float or ndarray

Notes

Neglects density effects of liquid and solid water

atmos.equations.Tv_from_T_rv_lwv(T, rv)

Calculates virtual temperature (K) assuming terms that are second-order in moisture quantities can be neglected (eg. qv == rv).

$$T_v = T (1 + (\frac{1}{0.622} - 1) r_v)$$

Parameters: T (float or ndarray) – Data for temperature (K). rv (float or ndarray) – Data for water vapor mixing ratio (kg/kg). Tv – Data for virtual temperature (K). float or ndarray

Notes

Neglects density effects of liquid and solid water

atmos.equations.Tv_from_p_e_T(p, e, T)

Calculates virtual temperature (K).

$$T_v = \frac{T}{1-\frac{e}{p}(1-0.622)}$$

Parameters: p (float or ndarray) – Data for pressure (Pa). e (float or ndarray) – Data for water vapor partial pressure (Pa). T (float or ndarray) – Data for temperature (K). Tv – Data for virtual temperature (K). float or ndarray

Notes

Neglects density effects of liquid and solid water

atmos.equations.Tv_from_p_rho_ideal_gas(p, rho)

Calculates virtual temperature (K) assuming the ideal gas law holds.

$$T_v = \frac{p}{\rho R_d}$$

Parameters: p (float or ndarray) – Data for pressure (Pa). rho (float or ndarray) – Data for density (kg/m^3). Tv – Data for virtual temperature (K). float or ndarray
atmos.equations.Tw_from_T_RH_Stull(T, RH)

Calculates wet bulb temperature (K).

Parameters: T (float or ndarray) – Data for temperature (K). RH (float or ndarray) – Data for relative humidity with respect to liquid water (percent). Tw – Data for wet bulb temperature (K). float or ndarray

Notes

Uses the empirical inverse solution from Stull (2011). Only valid at 101.3kPa.

References

Stull, R. 2011: Wet-Bulb Temperature from Relative Humidity and Air
Temperature. J. Appl. Meteor. Climatol., 50, 2267-2269. doi: http://dx.doi.org/10.1175/JAMC-D-11-0143.1
atmos.equations.autodoc(**kwargs)
atmos.equations.e_from_Td_Bolton(Td)

Calculates water vapor partial pressure (Pa) assuming the assumptions in Bolton (1980) hold.

$$e = es(Td)$$

Parameters: Td (float or ndarray) – Data for dewpoint temperature (K). e – Data for water vapor partial pressure (Pa). float or ndarray
atmos.equations.e_from_Td_Goff_Gratch(Td)

Calculates water vapor partial pressure (Pa) assuming the Goff-Gratch equation for es and esi.

$$e = es(Td)$$

Parameters: Td (float or ndarray) – Data for dewpoint temperature (K). e – Data for water vapor partial pressure (Pa). float or ndarray

Notes

References

Goff, J. A., and Gratch, S. 1946: Low-pressure properties of water
from -160 to 212 F, in Transactions of the American Society of Heating and Ventilating Engineers, pp 95-122, presented at the 52nd annual meeting of the American Society of Heating and Ventilating Engineers, New York, 1946.
atmos.equations.e_from_p_T_Tw_Bolton(p, T, Tw)

Calculates water vapor partial pressure (Pa) assuming the bulb is not frozen and the assumptions in Bolton (1980) hold.

$$e = es(T_w) - (6.60 \times 10^{-4}) (1 + 0.00115 (T_w-273.15) (T-T_w)) p$$

Parameters: p (float or ndarray) – Data for pressure (Pa). T (float or ndarray) – Data for temperature (K). Tw (float or ndarray) – Data for wet bulb temperature (K). e – Data for water vapor partial pressure (Pa). float or ndarray

Notes

References

Petty, G.W. 2008: A First Course in Atmospheric Thermodynamics. 1st Ed.
Sundog Publishing.
atmos.equations.e_from_p_T_Tw_Goff_Gratch(p, T, Tw)

Calculates water vapor partial pressure (Pa) assuming the bulb is not frozen and the Goff-Gratch equation for es and esi.

$$e = es(T_w) - (6.60 \times 10^{-4}) (1 + 0.00115 (T_w-273.15) (T-T_w)) p$$

Parameters: p (float or ndarray) – Data for pressure (Pa). T (float or ndarray) – Data for temperature (K). Tw (float or ndarray) – Data for wet bulb temperature (K). e – Data for water vapor partial pressure (Pa). float or ndarray

Notes

References

Petty, G.W. 2008: A First Course in Atmospheric Thermodynamics. 1st Ed.
Sundog Publishing.
atmos.equations.e_from_p_T_Tw_frozen_bulb_Bolton(p, T, Tw)

Calculates water vapor partial pressure (Pa) assuming the bulb is frozen and the assumptions in Bolton (1980) hold.

$$e = es(T_w) - (5.82 \times 10^{-4}) (1 + 0.00115 (T_w-273.15) (T-T_w)) p$$

Parameters: p (float or ndarray) – Data for pressure (Pa). T (float or ndarray) – Data for temperature (K). Tw (float or ndarray) – Data for wet bulb temperature (K). e – Data for water vapor partial pressure (Pa). float or ndarray

Notes

References

Petty, G.W. 2008: A First Course in Atmospheric Thermodynamics. 1st Ed.
Sundog Publishing.
atmos.equations.e_from_p_T_Tw_frozen_bulb_Goff_Gratch(p, T, Tw)

Calculates water vapor partial pressure (Pa) assuming the bulb is frozen and the Goff-Gratch equation for es and esi.

$$e = es(T_w) - (5.82 \times 10^{-4}) (1 + 0.00115 (T_w-273.15) (T-T_w)) p$$

Parameters: p (float or ndarray) – Data for pressure (Pa). T (float or ndarray) – Data for temperature (K). Tw (float or ndarray) – Data for wet bulb temperature (K). e – Data for water vapor partial pressure (Pa). float or ndarray

Notes

References

Petty, G.W. 2008: A First Course in Atmospheric Thermodynamics. 1st Ed.
Sundog Publishing.
atmos.equations.e_from_p_qv(p, qv)

Calculates water vapor partial pressure (Pa).

$$e = p \frac{q_v}{0.622+q_v}$$

Parameters: p (float or ndarray) – Data for pressure (Pa). qv (float or ndarray) – Data for specific humidity (kg/kg). e – Data for water vapor partial pressure (Pa). float or ndarray
atmos.equations.es_from_T_Bolton(T)

Calculates saturation water vapor partial pressure over water (Pa) assuming the assumptions in Bolton (1980) hold.

$$es(T) = 611.2 exp(17.67 rac{T-273.15}{T-29.65})$$

Parameters: T (float or ndarray) – Data for temperature (K). es – Data for saturation water vapor partial pressure over water (Pa). float or ndarray

Notes

Fits Wexler’s formula to an accuracy of 0.1% for temperatures between -35C and 35C.

References

Bolton, D. 1980: The Computation of Equivalent Potential Temperature.
Mon. Wea. Rev., 108, 1046-1053. doi: http://dx.doi.org/10.1175/1520-0493(1980)108<1046:TCOEPT>2.0.CO;2
Wexler, A. (1976): Vapor pressure formulation for water in range 0 to
100 C. A revision. J. Res. Natl. Bur. Stand. A, 80, 775-785.
atmos.equations.es_from_T_Goff_Gratch(T)

Calculates saturation water vapor partial pressure over water (Pa) assuming the Goff-Gratch equation for es and esi.

Parameters: T (float or ndarray) – Data for temperature (K). es – Data for saturation water vapor partial pressure over water (Pa). float or ndarray

Notes

The original Goff-Gratch (1946) equation reads as follows:

Log10(es) = -7.90298 (Tst/T-1)
+ 5.02808 Log10(Tst/T)
- 1.3816*10-7 (10^(11.344 (1-T/Tst)) - 1)
+ 8.1328*10-3 (10^(-3.49149 (Tst/T-1)) - 1)
+ Log10(es_st)

where: * Log10 refers to the logarithm in base 10 * es is the saturation water vapor pressure (hPa) * T is the absolute air temperature in kelvins * Tst is the steam-point (i.e. boiling point at 1 atm.) temperature (373.16K) * es_st is es at the steam-point pressure (1 atm = 1013.25 hPa)

This formula is accurate but computationally intensive. For most purposes, a more approximate formula is appropriate.

References

Goff, J. A., and Gratch, S. 1946: Low-pressure properties of water
from -160 to 212 F, in Transactions of the American Society of Heating and Ventilating Engineers, pp 95-122, presented at the 52nd annual meeting of the American Society of Heating and Ventilating Engineers, New York, 1946.
Goff, J. A. (1957) Saturation pressure of water on the new Kelvin
temperature scale, Transactions of the American Society of Heating and Ventilating Engineers, pp 347-354, presented at the semi-annual meeting of the American Society of Heating and Ventilating Engineers, Murray Bay, Que. Canada.
World Meteorological Organization (1988) General meteorological
standards and recommended practices, Appendix A, WMO Technical Regulations, WMO-No. 49.
World Meteorological Organization (2000) General meteorological
standards and recommended practices, Appendix A, WMO Technical Regulations, WMO-No. 49, corrigendum.
Murphy, D. M. and Koop, T. (2005): Review of the vapour pressures of
ice and supercooled water for atmospheric applications, Quarterly Journal of the Royal Meteorological Society 131(608): 1539-1565. doi:10.1256/qj.04.94
atmos.equations.esi_from_T_CIMO(T)

Calculates saturation water vapor partial pressure over ice (Pa) assuming the CIMO guide equation for esi.

$$esi = 6.112*e^{22.46*\frac{T - 273.15}{T - 0.53}}$$

Parameters: T (float or ndarray) – Data for temperature (K). esi – Data for saturation water vapor partial pressure over ice (Pa). float or ndarray

Notes

Matches Goff-Gratch within 0.2% from -70C to 0C, 2.5% from -100C to -70C.

atmos.equations.esi_from_T_Goff_Gratch(T)

Calculates saturation water vapor partial pressure over ice (Pa) assuming the Goff-Gratch equation for es and esi.

$$esi(T) = 610.71 * 10^{9.09718 (273.16/T - 1) - 3.56654 log_{10}(273.16/T) + 0.876793 (1 - T/273.16)}$$

Parameters: T (float or ndarray) – Data for temperature (K). esi – Data for saturation water vapor partial pressure over ice (Pa). float or ndarray

Notes

Valid between -100C and 0C.

atmos.equations.f_from_lat(lat)

Calculates Coriolis parameter (Hz).

$$f = 2 \Omega sin(\frac{\pi}{180.} lat)$$

Parameters: lat (float or ndarray) – Data for latitude (degrees). f – Data for Coriolis parameter (Hz). float or ndarray
atmos.equations.omega_from_w_rho_hydrostatic(w, rho)

Calculates vertical velocity expressed as tendency of pressure (Pa/s) assuming hydrostatic balance and g is constant.

$$\omega = - \rho g_0 w$$

Parameters: w (float or ndarray) – Data for vertical velocity (m/s). rho (float or ndarray) – Data for density (kg/m^3). omega – Data for vertical velocity expressed as tendency of pressure (Pa/s). float or ndarray
atmos.equations.p_from_rho_Tv_ideal_gas(rho, Tv)

Calculates pressure (Pa) assuming the ideal gas law holds.

$$p = \rho R_d T_v$$

Parameters: rho (float or ndarray) – Data for density (kg/m^3). Tv (float or ndarray) – Data for virtual temperature (K). p – Data for pressure (Pa). float or ndarray
atmos.equations.plcl_from_p_T_Tlcl(p, T, Tlcl)

Calculates pressure at lifting condensation level (Pa) assuming Cp is constant and equal to Cp for dry air at 0C.

$$p_{lcl} = p (\frac{T_{lcl}}{T})^(\frac{C_{pd}}{R_d})$$

Parameters: p (float or ndarray) – Data for pressure (Pa). T (float or ndarray) – Data for temperature (K). Tlcl (float or ndarray) – Data for temperature at lifting condensation level (K). plcl – Data for pressure at lifting condensation level (Pa). float or ndarray
atmos.equations.qi_from_qt_qv(qt, qv)

Calculates specific humidity with respect to ice (kg/kg) assuming liquid water can be neglected.

$$q_i = q_t-q_v$$

Parameters: qt (float or ndarray) – Data for specific humidity with respect to total water (kg/kg). qv (float or ndarray) – Data for specific humidity (kg/kg). qi – Data for specific humidity with respect to ice (kg/kg). float or ndarray
atmos.equations.qi_from_qt_qv_ql(qt, qv, ql)

Calculates specific humidity with respect to ice (kg/kg).

$$q_i = q_t-q_v-q_l$$

Parameters: qt (float or ndarray) – Data for specific humidity with respect to total water (kg/kg). qv (float or ndarray) – Data for specific humidity (kg/kg). ql (float or ndarray) – Data for specific humidity with respect to liquid water (kg/kg). qi – Data for specific humidity with respect to ice (kg/kg). float or ndarray
atmos.equations.ql_from_qt_qv(qt, qv)

Calculates specific humidity with respect to liquid water (kg/kg) assuming ice can be neglected.

$$q_l = q_t-q_v$$

Parameters: qt (float or ndarray) – Data for specific humidity with respect to total water (kg/kg). qv (float or ndarray) – Data for specific humidity (kg/kg). ql – Data for specific humidity with respect to liquid water (kg/kg). float or ndarray
atmos.equations.ql_from_qt_qv_qi(qt, qv, qi)

Calculates specific humidity with respect to liquid water (kg/kg).

$$q_l = q_t-q_v-q_i$$

Parameters: qt (float or ndarray) – Data for specific humidity with respect to total water (kg/kg). qv (float or ndarray) – Data for specific humidity (kg/kg). qi (float or ndarray) – Data for specific humidity with respect to ice (kg/kg). ql – Data for specific humidity with respect to liquid water (kg/kg). float or ndarray
atmos.equations.qt_from_qi_qv_ql(qi, qv, ql)

Calculates specific humidity with respect to total water (kg/kg).

$$q_t = q_i+q_v+q_l$$

Parameters: qi (float or ndarray) – Data for specific humidity with respect to ice (kg/kg). qv (float or ndarray) – Data for specific humidity (kg/kg). ql (float or ndarray) – Data for specific humidity with respect to liquid water (kg/kg). qt – Data for specific humidity with respect to total water (kg/kg). float or ndarray
atmos.equations.qt_from_qv(qv)

Calculates specific humidity with respect to total water (kg/kg) assuming liquid water can be neglected and ice can be neglected.

$$q_t = q_v$$

Parameters: qv (float or ndarray) – Data for specific humidity (kg/kg). qt – Data for specific humidity with respect to total water (kg/kg). float or ndarray
atmos.equations.qt_from_qv_qi(qv, qi)

Calculates specific humidity with respect to total water (kg/kg) assuming liquid water can be neglected.

$$q_t = q_v+q_l$$

Parameters: qv (float or ndarray) – Data for specific humidity (kg/kg). qi (float or ndarray) – Data for specific humidity with respect to ice (kg/kg). qt – Data for specific humidity with respect to total water (kg/kg). float or ndarray
atmos.equations.qt_from_qv_ql(qv, ql)

Calculates specific humidity with respect to total water (kg/kg) assuming ice can be neglected.

$$q_t = q_v+q_l$$

Parameters: qv (float or ndarray) – Data for specific humidity (kg/kg). ql (float or ndarray) – Data for specific humidity with respect to liquid water (kg/kg). qt – Data for specific humidity with respect to total water (kg/kg). float or ndarray
atmos.equations.qv_from_AH_rho(AH, rho)

Calculates specific humidity (kg/kg).

$$q_v = \frac{AH}{\rho}$$

Parameters: AH (float or ndarray) – Data for absolute humidity (kg/m^3). rho (float or ndarray) – Data for density (kg/m^3). qv – Data for specific humidity (kg/kg). float or ndarray
atmos.equations.qv_from_p_e(p, e)

Calculates specific humidity (kg/kg).

$$q_v = \frac{R_d}{R_v} \frac{e}{p-(1-\frac{R_d}{R_v}) e}$$

Parameters: p (float or ndarray) – Data for pressure (Pa). e (float or ndarray) – Data for water vapor partial pressure (Pa). qv – Data for specific humidity (kg/kg). float or ndarray
atmos.equations.qv_from_p_e_lwv(p, e)

Calculates specific humidity (kg/kg) assuming terms that are second-order in moisture quantities can be neglected (eg. qv == rv).

$$qv = (\frac{R_d}{R_v}) \frac{e}{p}$$

Parameters: p (float or ndarray) – Data for pressure (Pa). e (float or ndarray) – Data for water vapor partial pressure (Pa). qv – Data for specific humidity (kg/kg). float or ndarray
atmos.equations.qv_from_qt(qt)

Calculates specific humidity (kg/kg) assuming liquid water can be neglected and ice can be neglected.

$$q_v = q_t$$

Parameters: qt (float or ndarray) – Data for specific humidity with respect to total water (kg/kg). qv – Data for specific humidity (kg/kg). float or ndarray
atmos.equations.qv_from_qt_qi(qt, qi)

Calculates specific humidity (kg/kg) assuming liquid water can be neglected.

$$q_v = q_t - q_i$$

Parameters: qt (float or ndarray) – Data for specific humidity with respect to total water (kg/kg). qi (float or ndarray) – Data for specific humidity with respect to ice (kg/kg). qv – Data for specific humidity (kg/kg). float or ndarray
atmos.equations.qv_from_qt_ql(qt, ql)

Calculates specific humidity (kg/kg) assuming ice can be neglected.

$$q_v = q_t-q_l$$

Parameters: qt (float or ndarray) – Data for specific humidity with respect to total water (kg/kg). ql (float or ndarray) – Data for specific humidity with respect to liquid water (kg/kg). qv – Data for specific humidity (kg/kg). float or ndarray
atmos.equations.qv_from_qt_ql_qi(qt, ql, qi)

Calculates specific humidity (kg/kg).

$$q_v = q_t-q_l-q_i$$

Parameters: qt (float or ndarray) – Data for specific humidity with respect to total water (kg/kg). ql (float or ndarray) – Data for specific humidity with respect to liquid water (kg/kg). qi (float or ndarray) – Data for specific humidity with respect to ice (kg/kg). qv – Data for specific humidity (kg/kg). float or ndarray
atmos.equations.qv_from_rv(rv)

Calculates specific humidity (kg/kg).

$$q_v = \frac{r_v}{1+r_v}$$

Parameters: rv (float or ndarray) – Data for water vapor mixing ratio (kg/kg). qv – Data for specific humidity (kg/kg). float or ndarray
atmos.equations.qv_from_rv_lwv(rv)

Calculates specific humidity (kg/kg) assuming terms that are second-order in moisture quantities can be neglected (eg. qv == rv).

$$q_v = r_v$$

Parameters: rv (float or ndarray) – Data for water vapor mixing ratio (kg/kg). qv – Data for specific humidity (kg/kg). float or ndarray
atmos.equations.qvs_from_p_es(p, es)

Calculates saturation specific humidity with respect to liquid water (kg/kg).

$$q_{vs} = qv\_from\_p\_e(p, e_s)$$

Parameters: p (float or ndarray) – Data for pressure (Pa). es (float or ndarray) – Data for saturation water vapor partial pressure over water (Pa). qvs – Data for saturation specific humidity with respect to liquid water (kg/kg). float or ndarray
atmos.equations.qvs_from_p_es_lwv(p, es)

Calculates saturation specific humidity with respect to liquid water (kg/kg) assuming terms that are second-order in moisture quantities can be neglected (eg. qv == rv).

$$q_{vs} = qv\_from\_p\_e\_lwv(p, e_s)$$

Parameters: p (float or ndarray) – Data for pressure (Pa). es (float or ndarray) – Data for saturation water vapor partial pressure over water (Pa). qvs – Data for saturation specific humidity with respect to liquid water (kg/kg). float or ndarray
atmos.equations.qvs_from_rvs(rvs)

Calculates saturation specific humidity with respect to liquid water (kg/kg).

$$q_{vs} = \frac{r_{vs}}{1+r_{vs}}$$

Parameters: rvs (float or ndarray) – Data for saturation water vapor mixing ratio with respect to liquid water (kg/kg). qvs – Data for saturation specific humidity with respect to liquid water (kg/kg). float or ndarray
atmos.equations.qvs_from_rvs_lwv(rvs)

Calculates saturation specific humidity with respect to liquid water (kg/kg) assuming terms that are second-order in moisture quantities can be neglected (eg. qv == rv).

$$q_v = r_v$$

Parameters: rvs (float or ndarray) – Data for saturation water vapor mixing ratio with respect to liquid water (kg/kg). qvs – Data for saturation specific humidity with respect to liquid water (kg/kg). float or ndarray
atmos.equations.qvsi_from_p_esi(p, esi)

Calculates saturation specific humidity with respect to ice (kg/kg).

$$q_{vsi} = qv\_from\_p\_e(p, e_{si})$$

Parameters: p (float or ndarray) – Data for pressure (Pa). esi (float or ndarray) – Data for saturation water vapor partial pressure over ice (Pa). qvsi – Data for saturation specific humidity with respect to ice (kg/kg). float or ndarray
atmos.equations.qvsi_from_p_esi_lwv(p, esi)

Calculates saturation specific humidity with respect to ice (kg/kg) assuming terms that are second-order in moisture quantities can be neglected (eg. qv == rv).

$$q_{vsi} = qv\_from\_p\_e\_lwv(p, e_{si})$$

Parameters: p (float or ndarray) – Data for pressure (Pa). esi (float or ndarray) – Data for saturation water vapor partial pressure over ice (Pa). qvsi – Data for saturation specific humidity with respect to ice (kg/kg). float or ndarray
atmos.equations.rho_from_p_Tv_ideal_gas(p, Tv)

Calculates density (kg/m^3) assuming the ideal gas law holds.

$$\rho = \frac{p}{R_d T_v}$$

Parameters: p (float or ndarray) – Data for pressure (Pa). Tv (float or ndarray) – Data for virtual temperature (K). rho – Data for density (kg/m^3). float or ndarray
atmos.equations.rho_from_qv_AH(qv, AH)

Calculates density (kg/m^3).

$$\rho = \frac{AH}{q_v}$$

Parameters: qv (float or ndarray) – Data for specific humidity (kg/kg). AH (float or ndarray) – Data for absolute humidity (kg/m^3). rho – Data for density (kg/m^3). float or ndarray
atmos.equations.ri_from_rt_rv(rt, rv)

Calculates ice mixing ratio (kg/kg) assuming liquid water can be neglected.

$$r_i = r_t-r_v$$

Parameters: rt (float or ndarray) – Data for total water mixing ratio (kg/kg). rv (float or ndarray) – Data for water vapor mixing ratio (kg/kg). ri – Data for ice mixing ratio (kg/kg). float or ndarray
atmos.equations.ri_from_rt_rv_rl(rt, rv, rl)

Calculates ice mixing ratio (kg/kg).

$$r_i = r_t-r_v-r_l$$

Parameters: rt (float or ndarray) – Data for total water mixing ratio (kg/kg). rv (float or ndarray) – Data for water vapor mixing ratio (kg/kg). rl (float or ndarray) – Data for liquid water mixing ratio (kg/kg). ri – Data for ice mixing ratio (kg/kg). float or ndarray
atmos.equations.rl_from_rt_rv(rt, rv)

Calculates liquid water mixing ratio (kg/kg) assuming ice can be neglected.

$$r_l = r_t-r_v$$

Parameters: rt (float or ndarray) – Data for total water mixing ratio (kg/kg). rv (float or ndarray) – Data for water vapor mixing ratio (kg/kg). rl – Data for liquid water mixing ratio (kg/kg). float or ndarray
atmos.equations.rl_from_rt_rv_ri(rt, rv, ri)

Calculates liquid water mixing ratio (kg/kg).

$$r_l = r_t-r_v-r_i$$

Parameters: rt (float or ndarray) – Data for total water mixing ratio (kg/kg). rv (float or ndarray) – Data for water vapor mixing ratio (kg/kg). ri (float or ndarray) – Data for ice mixing ratio (kg/kg). rl – Data for liquid water mixing ratio (kg/kg). float or ndarray
atmos.equations.rt_from_ri_rv_rl(ri, rv, rl)

Calculates total water mixing ratio (kg/kg).

$$r_t = r_i+r_v+r_l$$

Parameters: ri (float or ndarray) – Data for ice mixing ratio (kg/kg). rv (float or ndarray) – Data for water vapor mixing ratio (kg/kg). rl (float or ndarray) – Data for liquid water mixing ratio (kg/kg). rt – Data for total water mixing ratio (kg/kg). float or ndarray
atmos.equations.rt_from_rv(rv)

Calculates total water mixing ratio (kg/kg) assuming liquid water can be neglected and ice can be neglected.

$$r_t = r_v$$

Parameters: rv (float or ndarray) – Data for water vapor mixing ratio (kg/kg). rt – Data for total water mixing ratio (kg/kg). float or ndarray
atmos.equations.rt_from_rv_ri(rv, ri)

Calculates total water mixing ratio (kg/kg) assuming liquid water can be neglected.

$$r_t = r_v+r_l$$

Parameters: rv (float or ndarray) – Data for water vapor mixing ratio (kg/kg). ri (float or ndarray) – Data for ice mixing ratio (kg/kg). rt – Data for total water mixing ratio (kg/kg). float or ndarray
atmos.equations.rt_from_rv_rl(rv, rl)

Calculates total water mixing ratio (kg/kg) assuming ice can be neglected.

$$r_t = r_v+r_l$$

Parameters: rv (float or ndarray) – Data for water vapor mixing ratio (kg/kg). rl (float or ndarray) – Data for liquid water mixing ratio (kg/kg). rt – Data for total water mixing ratio (kg/kg). float or ndarray
atmos.equations.rv_from_RH_rvs(RH, rvs)

Calculates water vapor mixing ratio (kg/kg).

$$r_v = \frac{RH}{100} r_{vs}$$

Parameters: RH (float or ndarray) – Data for relative humidity with respect to liquid water (percent). rvs (float or ndarray) – Data for saturation water vapor mixing ratio with respect to liquid water (kg/kg). rv – Data for water vapor mixing ratio (kg/kg). float or ndarray
atmos.equations.rv_from_RHi_rvsi(RHi, rvsi)

Calculates water vapor mixing ratio (kg/kg).

$$r_v = \frac{RH_i}{100} r_{vsi}$$

Parameters: RHi (float or ndarray) – Data for relative humidity with respect to ice (percent). rvsi (float or ndarray) – Data for saturation water vapor mixing ratio with respect to ice (kg/kg). rv – Data for water vapor mixing ratio (kg/kg). float or ndarray
atmos.equations.rv_from_Tv_T(Tv, T)

Calculates water vapor mixing ratio (kg/kg).

$$r_v = rac{-311 (T-T_v)}{500 T - 311 T_v}$$

Parameters: Tv (float or ndarray) – Data for virtual temperature (K). T (float or ndarray) – Data for temperature (K). rv – Data for water vapor mixing ratio (kg/kg). float or ndarray
atmos.equations.rv_from_Tv_T_lwv(Tv, T)

Calculates water vapor mixing ratio (kg/kg) assuming terms that are second-order in moisture quantities can be neglected (eg. qv == rv).

$$r_v = ( rac{T_v}{T} - 1) rac{0.622}{1-0.622}$$

Parameters: Tv (float or ndarray) – Data for virtual temperature (K). T (float or ndarray) – Data for temperature (K). rv – Data for water vapor mixing ratio (kg/kg). float or ndarray
atmos.equations.rv_from_p_e(p, e)

Calculates water vapor mixing ratio (kg/kg).

$$rv = (\frac{Rd}{Rv}) \frac{e}{p-e}$$

Parameters: p (float or ndarray) – Data for pressure (Pa). e (float or ndarray) – Data for water vapor partial pressure (Pa). rv – Data for water vapor mixing ratio (kg/kg). float or ndarray
atmos.equations.rv_from_qv(qv)

Calculates water vapor mixing ratio (kg/kg).

$$r_v = \frac{q_v}{1-q_v}$$

Parameters: qv (float or ndarray) – Data for specific humidity (kg/kg). rv – Data for water vapor mixing ratio (kg/kg). float or ndarray
atmos.equations.rv_from_qv_lwv(qv)

Calculates water vapor mixing ratio (kg/kg) assuming terms that are second-order in moisture quantities can be neglected (eg. qv == rv).

$$r_v = q_v$$

Parameters: qv (float or ndarray) – Data for specific humidity (kg/kg). rv – Data for water vapor mixing ratio (kg/kg). float or ndarray
atmos.equations.rv_from_rt(rt)

Calculates water vapor mixing ratio (kg/kg) assuming liquid water can be neglected and ice can be neglected.

$$r_v = r_t$$

Parameters: rt (float or ndarray) – Data for total water mixing ratio (kg/kg). rv – Data for water vapor mixing ratio (kg/kg). float or ndarray
atmos.equations.rv_from_rt_ri(rt, ri)

Calculates water vapor mixing ratio (kg/kg) assuming liquid water can be neglected.

$$r_v = r_t - r_i$$

Parameters: rt (float or ndarray) – Data for total water mixing ratio (kg/kg). ri (float or ndarray) – Data for ice mixing ratio (kg/kg). rv – Data for water vapor mixing ratio (kg/kg). float or ndarray
atmos.equations.rv_from_rt_rl(rt, rl)

Calculates water vapor mixing ratio (kg/kg) assuming ice can be neglected.

$$r_v = r_t-r_l$$

Parameters: rt (float or ndarray) – Data for total water mixing ratio (kg/kg). rl (float or ndarray) – Data for liquid water mixing ratio (kg/kg). rv – Data for water vapor mixing ratio (kg/kg). float or ndarray
atmos.equations.rv_from_rt_rl_ri(rt, rl, ri)

Calculates water vapor mixing ratio (kg/kg).

$$r_v = r_t-r_l-r_i$$

Parameters: rt (float or ndarray) – Data for total water mixing ratio (kg/kg). rl (float or ndarray) – Data for liquid water mixing ratio (kg/kg). ri (float or ndarray) – Data for ice mixing ratio (kg/kg). rv – Data for water vapor mixing ratio (kg/kg). float or ndarray
atmos.equations.rvs_from_p_es(p, es)

Calculates saturation water vapor mixing ratio with respect to liquid water (kg/kg).

$$r_{vs} = rv\_from\_p\_e(p, e_s)$$

Parameters: p (float or ndarray) – Data for pressure (Pa). es (float or ndarray) – Data for saturation water vapor partial pressure over water (Pa). rvs – Data for saturation water vapor mixing ratio with respect to liquid water (kg/kg). float or ndarray
atmos.equations.rvs_from_qvs(qvs)

Calculates saturation water vapor mixing ratio with respect to liquid water (kg/kg).

$$r_{vs} = rv\_from\_qv(q_{vs})$$

Parameters: qvs (float or ndarray) – Data for saturation specific humidity with respect to liquid water (kg/kg). rvs – Data for saturation water vapor mixing ratio with respect to liquid water (kg/kg). float or ndarray
atmos.equations.rvs_from_qvs_lwv(qvs)

Calculates saturation water vapor mixing ratio with respect to liquid water (kg/kg) assuming terms that are second-order in moisture quantities can be neglected (eg. qv == rv).

$$r_v = rv\_from\_qv(q_{vs})$$

Parameters: qvs (float or ndarray) – Data for saturation specific humidity with respect to liquid water (kg/kg). rvs – Data for saturation water vapor mixing ratio with respect to liquid water (kg/kg). float or ndarray
atmos.equations.rvsi_from_p_esi(p, esi)

Calculates saturation water vapor mixing ratio with respect to ice (kg/kg).

$$r_{vsi} = rv\_from\_p\_e(p, e_{si})$$

Parameters: p (float or ndarray) – Data for pressure (Pa). esi (float or ndarray) – Data for saturation water vapor partial pressure over ice (Pa). rvsi – Data for saturation water vapor mixing ratio with respect to ice (kg/kg). float or ndarray
atmos.equations.rvsi_from_qvsi(qvsi)

Calculates saturation water vapor mixing ratio with respect to ice (kg/kg).

$$r_{vsi} = rv\_from\_qv(q_{vsi})$$

Parameters: qvsi (float or ndarray) – Data for saturation specific humidity with respect to ice (kg/kg). rvsi – Data for saturation water vapor mixing ratio with respect to ice (kg/kg). float or ndarray
atmos.equations.rvsi_from_qvsi_lwv(qvsi)

Calculates saturation water vapor mixing ratio with respect to ice (kg/kg) assuming terms that are second-order in moisture quantities can be neglected (eg. qv == rv).

$$r_{vsi} = rv\_from\_qv(q_{vsi})$$

Parameters: qvsi (float or ndarray) – Data for saturation specific humidity with respect to ice (kg/kg). rvsi – Data for saturation water vapor mixing ratio with respect to ice (kg/kg). float or ndarray
atmos.equations.theta_from_p_T(p, T)

Calculates potential temperature (K) assuming Cp is constant and equal to Cp for dry air at 0C.

$$\theta = T (\frac{10^5}{p})^(\frac{R_d}{C_{pd}})$$

Parameters: p (float or ndarray) – Data for pressure (Pa). T (float or ndarray) – Data for temperature (K). theta – Data for potential temperature (K). float or ndarray
atmos.equations.thetae_from_T_RH_rv_lwv(T, RH, rv)

Calculates equivalent temperature (K) assuming terms that are second-order in moisture quantities can be neglected (eg. qv == rv).

$$\theta_e = T*(\frac{10^5}{p})^(\frac{R_d}{C_{pd}}) RH^{-r_v \frac{Rv}{C_{pd}}} exp(L_v \frac{Rv}{C_{pd}})$$

Parameters: T (float or ndarray) – Data for temperature (K). RH (float or ndarray) – Data for relative humidity with respect to liquid water (percent). rv (float or ndarray) – Data for water vapor mixing ratio (kg/kg). thetae – Data for equivalent temperature (K). float or ndarray
atmos.equations.thetae_from_p_T_Tlcl_rv_Bolton(p, T, Tlcl, rv)

Calculates equivalent temperature (K) assuming the assumptions in Bolton (1980) hold, Cp is constant and equal to Cp for dry air at 0C, and liquid water can be neglected.

$$\theta_e = T (\frac{10^5}{p})^(\frac{R_d}{C_{pd}})(1-0.28 r_v)) exp((\frac{3.376}{T_{lcl}}-0.00254) (r_v \times 10^3) (1+0.81 r_v))$$

Parameters: p (float or ndarray) – Data for pressure (Pa). T (float or ndarray) – Data for temperature (K). Tlcl (float or ndarray) – Data for temperature at lifting condensation level (K). rv (float or ndarray) – Data for water vapor mixing ratio (kg/kg). thetae – Data for equivalent temperature (K). float or ndarray

Notes

This is one of the most accurate ways of computing thetae, with an error of less than 0.2K due mainly to assuming Cp does not vary with temperature or pressure.

References

Bolton, D. 1980: The Computation of Equivalent Potential Temperature.
Mon. Wea. Rev., 108, 1046-1053. doi: http://dx.doi.org/10.1175/1520-0493(1980)108<1046:TCOEPT>2.0.CO;2
Davies-Jones, R. 2009: On Formulas for Equivalent Potential
Temperature. Mon. Wea. Rev., 137, 3137-3148. doi: http://dx.doi.org/10.1175/2009MWR2774.1
atmos.equations.thetae_from_p_e_T_RH_rv_rt(p, e, T, RH, rv, rt)

Calculates equivalent temperature (K).

$$\theta_e = T (\frac{10^5}{p})^(\frac{R_d}{C_{pd}) + r_t C_l}) RH^{-r_v \frac{R_v}{C_{pd} +r_t C_l}} exp(L_v \frac{r_v}{C_{pd}+r_t C_l})$$

Parameters: p (float or ndarray) – Data for pressure (Pa). e (float or ndarray) – Data for water vapor partial pressure (Pa). T (float or ndarray) – Data for temperature (K). RH (float or ndarray) – Data for relative humidity with respect to liquid water (percent). rv (float or ndarray) – Data for water vapor mixing ratio (kg/kg). rt (float or ndarray) – Data for total water mixing ratio (kg/kg). thetae – Data for equivalent temperature (K). float or ndarray

Notes

References

American Meteorological Society Glossary of Meteorology
http://glossary.ametsoc.org/wiki/Equivalent_potential_temperature Retrieved April 23, 2015
atmos.equations.thetaes_from_p_T_rvs_Bolton(p, T, rvs)

Calculates saturation equivalent temperature (K) assuming the assumptions in Bolton (1980) hold and Cp is constant and equal to Cp for dry air at 0C.

$$\theta_{es} = thetae\_from\_p\_T\_Tlcl\_rv\_Bolton(p, T, T, r_{vs})$$

Parameters: p (float or ndarray) – Data for pressure (Pa). T (float or ndarray) – Data for temperature (K). rvs (float or ndarray) – Data for saturation water vapor mixing ratio with respect to liquid water (kg/kg). thetaes – Data for saturation equivalent temperature (K). float or ndarray

Notes

References

Bolton, D. 1980: The Computation of Equivalent Potential Temperature.
Mon. Wea. Rev., 108, 1046-1053. doi: http://dx.doi.org/10.1175/1520-0493(1980)108<1046:TCOEPT>2.0.CO;2
Davies-Jones, R. 2009: On Formulas for Equivalent Potential
Temperature. Mon. Wea. Rev., 137, 3137-3148. doi: http://dx.doi.org/10.1175/2009MWR2774.1
atmos.equations.w_from_omega_rho_hydrostatic(omega, rho)

Calculates vertical velocity (m/s) assuming g is constant and hydrostatic balance.

$$w = - \frac{\omega}{\rho g_0}$$

Parameters: omega (float or ndarray) – Data for vertical velocity expressed as tendency of pressure (Pa/s). rho (float or ndarray) – Data for density (kg/m^3). w – Data for vertical velocity (m/s). float or ndarray
atmos.equations.z_from_Phi(Phi)

Calculates height (m) assuming g is constant.

$$z = \frac{\Phi}{g_0}$$

Parameters: Phi (float or ndarray) – Data for geopotential (m^2/s^2). z – Data for height (m). float or ndarray

atmos.solve module¶

solve.py: Utilities that use equations to solve for quantities, given other
quantities and a set of assumptions.
class atmos.solve.BaseSolver(**kwargs)

Bases: object

Base class for solving systems of equations. Should not be instantiated, as it is not associated with any equations.

Initializes with the given assumptions enabled, and variables passed as keyword arguments stored.

Parameters: assumptions (tuple, optional) – Strings specifying which assumptions to enable. Overrides the default assumptions. See below for a list of default assumptions. add_assumptions (tuple, optional) – Strings specifying assumptions to use in addition to the default assumptions. May not be given in combination with the assumptions kwarg. remove_assumptions (tuple, optional) – Strings specifying assumptions not to use from the default assumptions. May not be given in combination with the assumptions kwarg. May not contain strings that are contained in add_assumptions, if given. **kwargs – Keyword arguments used to pass in arrays of data that correspond to quantities used for calculations, or unit specifications for quantities. For a complete list of kwargs that may be used, see the Quantity Parameters section below. out – A BaseSolver object with the specified assumptions and variables. BaseSolver

Notes

Quantity kwargs

<quantity parameter list goes here>

In addition to the quantities above, kwargs of the form <quantity>_unit or <quantity>_units can be used with a string specifying a unit for the quantity. This will cause input data for that quantity to be assumed to be in that unit, and output data for that quantity to be given in that unit. Note this must be specified separately for each quantity. Acceptable units are the units available in the Pint package, with the exception that RH can be in units of “fraction” or “percent”.

Assumptions

<default assumptions list goes here>

Assumption descriptions

<assumptions list goes here>

calculate(*args)

Calculates and returns a requested quantity from quantities stored in this object at initialization.

Parameters: *args – Name of quantity to be calculated. quantity – Calculated quantity, in units listed under quantity parameters. ndarray

Notes

See the documentation for this object for a complete list of quantities that may be calculated, in the “Quantity Parameters” section.

Raises: ValueError – If the output quantity cannot be determined from the input quantities.

Examples

Calculating pressure from virtual temperature and density:

>>> solver = FluidSolver(Tv=273., rho=1.27)
>>> solver.calculate('p')
99519.638400000011


Same calculation, but also returning a list of functions used:

>>> solver = FluidSolver(Tv=273., rho=1.27, debug=True)
>>> p, funcs = solver.calculate('p')
>>> funcs
(<function atmos.equations.p_from_rho_Tv_ideal_gas>,)


Same calculation with temperature instead, ignoring virtual temperature correction:

>>> solver = FluidSolver(T=273., rho=1.27, add_assumptions=('Tv equals T',))
>>> solver.calculate('p',)
99519.638400000011

exception atmos.solve.ExcludeError

Bases: exceptions.Exception

Used in calculating shortest solutions to indicate solutions where all remaining variables to calculated are excluded.

class atmos.solve.FluidSolver(**kwargs)

Bases: atmos.solve.BaseSolver

Initializes with the given assumptions enabled, and variables passed as keyword arguments stored.

Parameters: assumptions (tuple, optional) – Strings specifying which assumptions to enable. Overrides the default assumptions. See below for a list of default assumptions. add_assumptions (tuple, optional) – Strings specifying assumptions to use in addition to the default assumptions. May not be given in combination with the assumptions kwarg. remove_assumptions (tuple, optional) – Strings specifying assumptions not to use from the default assumptions. May not be given in combination with the assumptions kwarg. May not contain strings that are contained in add_assumptions, if given. **kwargs – Keyword arguments used to pass in arrays of data that correspond to quantities used for calculations, or unit specifications for quantities. For a complete list of kwargs that may be used, see the Quantity Parameters section below. out – A FluidSolver object with the specified assumptions and variables. FluidSolver

Notes

Quantity kwargs

• AH – absolute humidity (kg/m^3)
• DSE – dry static energy (J)
• e – water vapor partial pressure (Pa)
• es – saturation water vapor partial pressure over water (Pa)
• esi – saturation water vapor partial pressure over ice (Pa)
• f – Coriolis parameter (Hz)
• Gammam – moist adiabatic lapse rate (K/m)
• lat – latitude (degrees)
• lon – longitude (degrees)
• MSE – moist static energy (J)
• N2 – squared Brunt-Vaisala frequency (Hz^2)
• omega – vertical velocity expressed as tendency of pressure (Pa/s)
• p – pressure (Pa)
• Phi – geopotential (m^2/s^2)
• plcl – pressure at lifting condensation level (Pa)
• qi – specific humidity with respect to ice (kg/kg)
• ql – specific humidity with respect to liquid water (kg/kg)
• qt – specific humidity with respect to total water (kg/kg)
• qv – specific humidity (kg/kg)
• qvs – saturation specific humidity with respect to liquid water (kg/kg)
• qvsi – saturation specific humidity with respect to ice (kg/kg)
• RB – bulk Richardson number (dimensionless)
• RH – relative humidity with respect to liquid water (percent)
• RHi – relative humidity with respect to ice (percent)
• rho – density (kg/m^3)
• ri – ice mixing ratio (kg/kg)
• rl – liquid water mixing ratio (kg/kg)
• rt – total water mixing ratio (kg/kg)
• rv – water vapor mixing ratio (kg/kg)
• rvs – saturation water vapor mixing ratio with respect to liquid water (kg/kg)
• rvsi – saturation water vapor mixing ratio with respect to ice (kg/kg)
• T – temperature (K)
• Td – dewpoint temperature (K)
• theta – potential temperature (K)
• thetae – equivalent temperature (K)
• thetaes – saturation equivalent temperature (K)
• Tlcl – temperature at lifting condensation level (K)
• Tv – virtual temperature (K)
• Tw – wet bulb temperature (K)
• u – eastward zonal wind velocity (m/s)
• v – northward meridional wind velocity (m/s)
• w – vertical velocity (m/s)
• x – x (m)
• y – y (m)
• Z – geopotential height (m)
• z – height (m)

In addition to the quantities above, kwargs of the form <quantity>_unit or <quantity>_units can be used with a string specifying a unit for the quantity. This will cause input data for that quantity to be assumed to be in that unit, and output data for that quantity to be given in that unit. Note this must be specified separately for each quantity. Acceptable units are the units available in the Pint package, with the exception that RH can be in units of “fraction” or “percent”.

Assumptions

Default assumptions are ‘ideal gas’, ‘hydrostatic’, ‘constant g’, ‘constant Lv’, ‘constant Cp’, ‘no liquid water’, ‘no ice’, ‘bolton’, ‘cimo’.

Assumption descriptions

• bolton – the assumptions in Bolton (1980) hold
• cimo – the CIMO guide equation for esi
• constant Cp – Cp is constant and equal to Cp for dry air at 0C
• constant g – g is constant
• constant Lv – latent heat of vaporization of water is constant
• frozen bulb – the bulb is frozen
• goff-gratch – the Goff-Gratch equation for es and esi
• hydrostatic – hydrostatic balance
• ideal gas – the ideal gas law holds
• low water vapor – terms that are second-order in moisture quantities can be neglected (eg. qv == rv)
• no ice – ice can be neglected
• no liquid water – liquid water can be neglected
• Tv equals T – the virtual temperature correction can be neglected
• unfrozen bulb – the bulb is not frozen

Examples

Calculating pressure from virtual temperature and density:

>>> solver = FluidSolver(Tv=273., rho=1.27)
>>> solver.calculate('p')
99519.638400000011


Same calculation, but also returning a list of functions used:

>>> solver = FluidSolver(Tv=273., rho=1.27, debug=True)
>>> p, funcs = solver.calculate('p')
>>> funcs
(<function atmos.equations.p_from_rho_Tv_ideal_gas>,)


Same calculation with temperature instead, ignoring virtual temperature correction:

>>> solver = FluidSolver(T=273., rho=1.27, add_assumptions=('Tv equals T',))
>>> solver.calculate('p',)
99519.638400000011

all_assumptions = ('constant g', 'frozen bulb', 'unfrozen bulb', 'cimo', 'no ice', 'goff-gratch', 'ideal gas', 'no liquid water', 'constant Cp', 'Tv equals T', 'hydrostatic', 'bolton', 'constant Lv', 'low water vapor')
default_assumptions = (u'ideal gas', u'hydrostatic', u'constant g', u'constant Lv', u'constant Cp', u'no liquid water', u'no ice', u'bolton', u'cimo')
class atmos.solve.SolverMeta

Bases: type

Metaclass for BaseSolver to automatically generate docstrings and assumption lists for subclasses of BaseSolver.

atmos.solve.calculate(*args, **kwargs)

Calculates and returns a requested quantity from quantities passed in as keyword arguments.

Parameters: *args (string) – Names of quantities to be calculated. assumptions (tuple, optional) – Strings specifying which assumptions to enable. Overrides the default assumptions. See below for a list of default assumptions. add_assumptions (tuple, optional) – Strings specifying assumptions to use in addition to the default assumptions. May not be given in combination with the assumptions kwarg. remove_assumptions (tuple, optional) – Strings specifying assumptions not to use from the default assumptions. May not be given in combination with the assumptions kwarg. May not contain strings that are contained in add_assumptions, if given. **kwargs (ndarray, optional) – Keyword arguments used to pass in arrays of data that correspond to quantities used for calculations, or unit specifications for quantities. For a complete list of kwargs that may be used, see the Quantity Parameters section below. quantity – Calculated quantity. Return type is the same as quantity parameter types. If multiple quantities are requested, returns a tuple containing the quantities. ndarray

Notes

Calculating multiple quantities at once can avoid re-computing intermediate quantities, but requires more memory.

Quantity kwargs

• AH – absolute humidity (kg/m^3)
• DSE – dry static energy (J)
• e – water vapor partial pressure (Pa)
• es – saturation water vapor partial pressure over water (Pa)
• esi – saturation water vapor partial pressure over ice (Pa)
• f – Coriolis parameter (Hz)
• Gammam – moist adiabatic lapse rate (K/m)
• lat – latitude (degrees)
• lon – longitude (degrees)
• MSE – moist static energy (J)
• N2 – squared Brunt-Vaisala frequency (Hz^2)
• omega – vertical velocity expressed as tendency of pressure (Pa/s)
• p – pressure (Pa)
• Phi – geopotential (m^2/s^2)
• plcl – pressure at lifting condensation level (Pa)
• qi – specific humidity with respect to ice (kg/kg)
• ql – specific humidity with respect to liquid water (kg/kg)
• qt – specific humidity with respect to total water (kg/kg)
• qv – specific humidity (kg/kg)
• qvs – saturation specific humidity with respect to liquid water (kg/kg)
• qvsi – saturation specific humidity with respect to ice (kg/kg)
• RB – bulk Richardson number (dimensionless)
• RH – relative humidity with respect to liquid water (percent)
• RHi – relative humidity with respect to ice (percent)
• rho – density (kg/m^3)
• ri – ice mixing ratio (kg/kg)
• rl – liquid water mixing ratio (kg/kg)
• rt – total water mixing ratio (kg/kg)
• rv – water vapor mixing ratio (kg/kg)
• rvs – saturation water vapor mixing ratio with respect to liquid water (kg/kg)
• rvsi – saturation water vapor mixing ratio with respect to ice (kg/kg)
• T – temperature (K)
• Td – dewpoint temperature (K)
• theta – potential temperature (K)
• thetae – equivalent temperature (K)
• thetaes – saturation equivalent temperature (K)
• Tlcl – temperature at lifting condensation level (K)
• Tv – virtual temperature (K)
• Tw – wet bulb temperature (K)
• u – eastward zonal wind velocity (m/s)
• v – northward meridional wind velocity (m/s)
• w – vertical velocity (m/s)
• x – x (m)
• y – y (m)
• Z – geopotential height (m)
• z – height (m)

In addition to the quantities above, kwargs of the form <quantity>_unit or <quantity>_units can be used with a string specifying a unit for the quantity. This will cause input data for that quantity to be assumed to be in that unit, and output data for that quantity to be given in that unit. Note this must be specified separately for each quantity. Acceptable units are the units available in the Pint package, with the exception that RH can be in units of “fraction” or “percent”.

Assumptions

Default assumptions are ‘ideal gas’, ‘hydrostatic’, ‘constant g’, ‘constant Lv’, ‘constant Cp’, ‘no liquid water’, ‘no ice’, ‘bolton’, ‘cimo’.

Assumption descriptions

• bolton – the assumptions in Bolton (1980) hold
• cimo – the CIMO guide equation for esi
• constant Cp – Cp is constant and equal to Cp for dry air at 0C
• constant g – g is constant
• constant Lv – latent heat of vaporization of water is constant
• frozen bulb – the bulb is frozen
• goff-gratch – the Goff-Gratch equation for es and esi
• hydrostatic – hydrostatic balance
• ideal gas – the ideal gas law holds
• low water vapor – terms that are second-order in moisture quantities can be neglected (eg. qv == rv)
• no ice – ice can be neglected
• no liquid water – liquid water can be neglected
• Tv equals T – the virtual temperature correction can be neglected
• unfrozen bulb – the bulb is not frozen

Examples

Calculating pressure from virtual temperature and density:

>>> calculate('p', Tv=273., rho=1.27)
99519.638400000011


Same calculation, but also returning a list of functions used:

>>> p, funcs = calculate('p', Tv=273., rho=1.27, debug=True)
>>> funcs
(<function atmos.equations.p_from_rho_Tv_ideal_gas>,)


Same calculation with temperature instead, ignoring virtual temperature correction:

>>> calculate('p', T=273., rho=1.27, add_assumptions=('Tv equals T',))
99519.638400000011

atmos.solve.get_calculatable_quantities(inputs, methods)

Given an interable of input quantity names and a methods dictionary, returns a list of output quantities that can be calculated.

atmos.util module¶

Created on Fri Mar 27 13:11:26 2015

@author: mcgibbon

atmos.util.area_poly_sphere(lat, lon, r_sphere)

Calculates the area enclosed by an arbitrary polygon on the sphere.

Parameters: lat (iterable) – The latitudes, in degrees, of the vertex locations of the polygon, in clockwise order. lon (iterable) – The longitudes, in degrees, of the vertex locations of the polygon, in clockwise order. area – The desired spherical area in the same units as r_sphere. float

Notes

This function assumes the vertices form a valid polygon (edges do not intersect each other).

References

Computing the Area of a Spherical Polygon of Arbitrary Shape Bevis and Cambareri (1987) Mathematical Geology, vol.19, Issue 4, pp 335-346

atmos.util.assumption_list_string(assumptions, assumption_dict)

Takes in a list of short forms of assumptions and an assumption dictionary, and returns a “list” form of the long form of the assumptions.

Raises: ValueError – if one of the assumptions is not in assumption_dict.
atmos.util.closest_val(x, L)

Finds the index value in an iterable closest to a desired value.

Parameters: x (object) – The desired value. L (iterable) – The iterable in which to search for the desired value. index – The index of the closest value to x in L. int

Notes

Assumes x and the entries of L are of comparable types.

Raises: ValueError – if L is empty
atmos.util.d_x(data, axis, boundary=u'forward-backward')

Calculates a second-order centered finite difference of data along the specified axis.

Parameters: data (ndarray) – Data on which we are taking a derivative. axis (int) – Index of the data array on which to take the difference. boundary (string, optional) – Boundary condition. If ‘periodic’, assume periodic boundary condition for centered difference. If ‘forward-backward’, take first-order forward or backward derivatives at boundary. derivative – Derivative of the data along the specified axis. ndarray ValueError – If an invalid boundary condition choice is given, if both dx and x are specified, if axis is out of the valid range for the shape of the data, or if x is specified and axis_x is out of the valid range for the shape of x.
atmos.util.ddx(data, axis=0, dx=None, x=None, axis_x=0, boundary=u'forward-backward')

Calculates a second-order centered finite difference derivative of data along the specified axis.

Parameters: data (ndarray) – Data on which we are taking a derivative. axis (int) – Index of the data array on which to take the derivative. dx (float, optional) – Constant grid spacing value. Will assume constant grid spacing if given. May not be used with argument x. Default value is 1 unless x is given. x (ndarray, optional) – Values of the axis along which we are taking a derivative to allow variable grid spacing. May not be given with argument dx. axis_x (int, optional) – Index of the x array on which to take the derivative. Does nothing if x is not given as an argument. boundary (string, optional) – Boundary condition. If ‘periodic’, assume periodic boundary condition for centered difference. If ‘forward-backward’, take first-order forward or backward derivatives at boundary. derivative – Derivative of the data along the specified axis. ndarray ValueError – If an invalid boundary condition choice is given, if both dx and x are specified, if axis is out of the valid range for the shape of the data, or if x is specified and axis_x is out of the valid range for the shape of x.
atmos.util.doc_paragraph(s, indent=0)

Takes in a string without wrapping corresponding to a paragraph, and returns a version of that string wrapped to be at most 80 characters in length on each line. If indent is given, ensures each line is indented to that number of spaces.

atmos.util.parse_derivative_string(string, quantity_dict)

Assuming the string is of the form d(var1)d(var2), returns var1, var2. Raises ValueError if the string is not of this form, or if the vars are not keys in the quantity_dict, or if var2 is not a coordinate-like variable.

atmos.util.quantity_spec_string(name, quantity_dict)

Returns a quantity specification for docstrings.

Example

>>> quantity_spec_string('Tv')
>>> 'Tv : float or ndarray
Data for virtual temperature.'

atmos.util.quantity_string(name, quantity_dict)

Takes in an abbreviation for a quantity and a quantity dictionary, and returns a more descriptive string of the quantity as “name (units).” Raises ValueError if the name is not in quantity_dict

atmos.util.strings_to_list_string(strings)

Takes a list of strings presumably containing words and phrases, and returns a “list” form of those strings, like:

>>> strings_to_list_string(('cats', 'dogs'))
>>> 'cats and dogs'


or

>>> strings_to_list_string(('pizza', 'pop', 'chips'))
>>> 'pizza, pop, and chips'


Raises ValueError if strings is empty.