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.
constants.py: Scientific constants in SI units.
Included constants:
decorators.py: Function decorators used by the rest of this module.
Stores a function’s assumptions as an attribute.
Creates a decorator that adds a docstring to an equation function.
Parameters: |
|
---|---|
Raises: | 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. |
Stores what assumptions a function is overridden by as an attribute.
equations.py: Fluid dynamics equations for atmospheric sciences.
Calculates absolute humidity (kg/m^3).
\(AH = q_v \rho\)
Parameters: |
|
---|---|
Returns: | AH – Data for absolute humidity (kg/m^3). |
Return type: | float or ndarray |
Calculates dry static energy (J).
\(DSE = C_{pd} T + \Phi\)
Parameters: |
|
---|---|
Returns: | DSE – Data for dry static energy (J). |
Return type: | float or ndarray |
Calculates dry static energy (J) assuming g is constant.
\(DSE = C_{pd} T + g_0 z\)
Parameters: |
|
---|---|
Returns: | DSE – Data for dry static energy (J). |
Return type: | float or ndarray |
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: |
|
---|---|
Returns: | Gammam – Data for moist adiabatic lapse rate (K/m). |
Return type: | float or ndarray |
Notes
References
Calculates moist static energy (J) assuming latent heat of vaporization of water is constant.
\(MSE = DSE + L_{v0} q_v\)
Parameters: |
|
---|---|
Returns: | MSE – Data for moist static energy (J). |
Return type: | float or ndarray |
Calculates geopotential (m^2/s^2) assuming g is constant.
\(Phi = g_0 z\)
Parameters: | z (float or ndarray) – Data for height (m). |
---|---|
Returns: | Phi – Data for geopotential (m^2/s^2). |
Return type: | float or ndarray |
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: |
|
---|---|
Returns: | RH – Data for relative humidity with respect to liquid water (percent). |
Return type: | float or ndarray |
Calculates relative humidity with respect to liquid water (percent).
\(RH = \frac{r_v}{r_{vs}} \times 100\)
Parameters: |
|
---|---|
Returns: | RH – Data for relative humidity with respect to liquid water (percent). |
Return type: | float or ndarray |
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: |
|
---|---|
Returns: | RHi – Data for relative humidity with respect to ice (percent). |
Return type: | float or ndarray |
Calculates relative humidity with respect to ice (percent).
\(RH_i = \frac{r_v}{r_{vsi}} \times 100\)
Parameters: |
|
---|---|
Returns: | RHi – Data for relative humidity with respect to ice (percent). |
Return type: | float or ndarray |
Calculates temperature (K) assuming the virtual temperature correction can be neglected.
\(T = T_v\)
Parameters: | Tv (float or ndarray) – Data for virtual temperature (K). |
---|---|
Returns: | T – Data for temperature (K). |
Return type: | float or ndarray |
Notes
This function exists to allow using temperature as virtual temperature.
Calculates temperature (K).
\(T = T_v \frac{1 + r_v}{1+ \frac{r_v}{0.622}\)
Parameters: |
|
---|---|
Returns: | T – Data for temperature (K). |
Return type: | float or ndarray |
Notes
Neglects density effects of liquid and solid water
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: |
|
---|---|
Returns: | T – Data for temperature (K). |
Return type: | float or ndarray |
Notes
Neglects density effects of liquid and solid water
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). |
---|---|
Returns: | T – Data for temperature (K). |
Return type: | float or ndarray |
Notes
Fits Wexler’s formula to an accuracy of 0.1% for temperatures between -35C and 35C.
References
Calculates temperature (K).
\(T = T_v (1-\frac{e}{p}(1-0.622))\)
Parameters: |
|
---|---|
Returns: | T – Data for temperature (K). |
Return type: | float or ndarray |
Notes
Neglects density effects of liquid and solid water
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: |
|
---|---|
Returns: | T – Data for temperature (K). |
Return type: | float or ndarray |
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). |
---|---|
Returns: | Td – Data for dewpoint temperature (K). |
Return type: | float or ndarray |
Notes
Obtained by inverting Bolton’s formula, es(Td) = T.
References
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: |
|
---|---|
Returns: | Tlcl – Data for temperature at lifting condensation level (K). |
Return type: | float or ndarray |
Notes
Uses Bolton (1980) equation 22.
References
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: |
|
---|---|
Returns: | Tlcl – Data for temperature at lifting condensation level (K). |
Return type: | float or ndarray |
Notes
Uses Bolton (1980) equation 15.
References
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: |
|
---|---|
Returns: | Tlcl – Data for temperature at lifting condensation level (K). |
Return type: | float or ndarray |
Notes
Uses Bolton(1980) equation 21.
References
Calculates virtual temperature (K) assuming the virtual temperature correction can be neglected.
\(T_v = T\)
Parameters: | T (float or ndarray) – Data for temperature (K). |
---|---|
Returns: | Tv – Data for virtual temperature (K). |
Return type: | float or ndarray |
Notes
This function exists to allow using temperature as virtual temperature.
Calculates virtual temperature (K).
\(T_v = T \frac{1 + \frac{r_v}{0.622}}{1+r_v}\)
Parameters: |
|
---|---|
Returns: | Tv – Data for virtual temperature (K). |
Return type: | float or ndarray |
Notes
Neglects density effects of liquid and solid water
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: |
|
---|---|
Returns: | Tv – Data for virtual temperature (K). |
Return type: | float or ndarray |
Notes
Neglects density effects of liquid and solid water
Calculates virtual temperature (K).
\(T_v = \frac{T}{1-\frac{e}{p}(1-0.622)}\)
Parameters: |
|
---|---|
Returns: | Tv – Data for virtual temperature (K). |
Return type: | float or ndarray |
Notes
Neglects density effects of liquid and solid water
Calculates virtual temperature (K) assuming the ideal gas law holds.
\(T_v = \frac{p}{\rho R_d}\)
Parameters: |
|
---|---|
Returns: | Tv – Data for virtual temperature (K). |
Return type: | float or ndarray |
Calculates wet bulb temperature (K).
Parameters: |
|
---|---|
Returns: | Tw – Data for wet bulb temperature (K). |
Return type: | float or ndarray |
Notes
Uses the empirical inverse solution from Stull (2011). Only valid at 101.3kPa.
References
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). |
---|---|
Returns: | e – Data for water vapor partial pressure (Pa). |
Return type: | float or ndarray |
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). |
---|---|
Returns: | e – Data for water vapor partial pressure (Pa). |
Return type: | float or ndarray |
Notes
References
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: |
|
---|---|
Returns: | e – Data for water vapor partial pressure (Pa). |
Return type: | float or ndarray |
Notes
References
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: |
|
---|---|
Returns: | e – Data for water vapor partial pressure (Pa). |
Return type: | float or ndarray |
Notes
References
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: |
|
---|---|
Returns: | e – Data for water vapor partial pressure (Pa). |
Return type: | float or ndarray |
Notes
References
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: |
|
---|---|
Returns: | e – Data for water vapor partial pressure (Pa). |
Return type: | float or ndarray |
Notes
References
Calculates water vapor partial pressure (Pa).
\(e = p \frac{q_v}{0.622+q_v}\)
Parameters: |
|
---|---|
Returns: | e – Data for water vapor partial pressure (Pa). |
Return type: | float or ndarray |
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). |
---|---|
Returns: | es – Data for saturation water vapor partial pressure over water (Pa). |
Return type: | float or ndarray |
Notes
Fits Wexler’s formula to an accuracy of 0.1% for temperatures between -35C and 35C.
References
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). |
---|---|
Returns: | es – Data for saturation water vapor partial pressure over water (Pa). |
Return type: | float or ndarray |
Notes
The original Goff-Gratch (1946) equation reads as follows:
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
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). |
---|---|
Returns: | esi – Data for saturation water vapor partial pressure over ice (Pa). |
Return type: | float or ndarray |
Notes
Matches Goff-Gratch within 0.2% from -70C to 0C, 2.5% from -100C to -70C.
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). |
---|---|
Returns: | esi – Data for saturation water vapor partial pressure over ice (Pa). |
Return type: | float or ndarray |
Notes
Valid between -100C and 0C.
Calculates Coriolis parameter (Hz).
\(f = 2 \Omega sin(\frac{\pi}{180.} lat)\)
Parameters: | lat (float or ndarray) – Data for latitude (degrees). |
---|---|
Returns: | f – Data for Coriolis parameter (Hz). |
Return type: | float or ndarray |
Calculates vertical velocity expressed as tendency of pressure (Pa/s) assuming hydrostatic balance and g is constant.
\(\omega = - \rho g_0 w\)
Parameters: |
|
---|---|
Returns: | omega – Data for vertical velocity expressed as tendency of pressure (Pa/s). |
Return type: | float or ndarray |
Calculates pressure (Pa) assuming the ideal gas law holds.
\(p = \rho R_d T_v\)
Parameters: |
|
---|---|
Returns: | p – Data for pressure (Pa). |
Return type: | float or ndarray |
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: |
|
---|---|
Returns: | plcl – Data for pressure at lifting condensation level (Pa). |
Return type: | float or ndarray |
Calculates specific humidity with respect to ice (kg/kg) assuming liquid water can be neglected.
\(q_i = q_t-q_v\)
Parameters: |
|
---|---|
Returns: | qi – Data for specific humidity with respect to ice (kg/kg). |
Return type: | float or ndarray |
Calculates specific humidity with respect to ice (kg/kg).
\(q_i = q_t-q_v-q_l\)
Parameters: |
|
---|---|
Returns: | qi – Data for specific humidity with respect to ice (kg/kg). |
Return type: | float or ndarray |
Calculates specific humidity with respect to liquid water (kg/kg) assuming ice can be neglected.
\(q_l = q_t-q_v\)
Parameters: |
|
---|---|
Returns: | ql – Data for specific humidity with respect to liquid water (kg/kg). |
Return type: | float or ndarray |
Calculates specific humidity with respect to liquid water (kg/kg).
\(q_l = q_t-q_v-q_i\)
Parameters: |
|
---|---|
Returns: | ql – Data for specific humidity with respect to liquid water (kg/kg). |
Return type: | float or ndarray |
Calculates specific humidity with respect to total water (kg/kg).
\(q_t = q_i+q_v+q_l\)
Parameters: |
|
---|---|
Returns: | qt – Data for specific humidity with respect to total water (kg/kg). |
Return type: | float or ndarray |
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). |
---|---|
Returns: | qt – Data for specific humidity with respect to total water (kg/kg). |
Return type: | float or ndarray |
Calculates specific humidity with respect to total water (kg/kg) assuming liquid water can be neglected.
\(q_t = q_v+q_l\)
Parameters: |
|
---|---|
Returns: | qt – Data for specific humidity with respect to total water (kg/kg). |
Return type: | float or ndarray |
Calculates specific humidity with respect to total water (kg/kg) assuming ice can be neglected.
\(q_t = q_v+q_l\)
Parameters: |
|
---|---|
Returns: | qt – Data for specific humidity with respect to total water (kg/kg). |
Return type: | float or ndarray |
Calculates specific humidity (kg/kg).
\(q_v = \frac{AH}{\rho}\)
Parameters: |
|
---|---|
Returns: | qv – Data for specific humidity (kg/kg). |
Return type: | float or ndarray |
Calculates specific humidity (kg/kg).
\(q_v = \frac{R_d}{R_v} \frac{e}{p-(1-\frac{R_d}{R_v}) e}\)
Parameters: |
|
---|---|
Returns: | qv – Data for specific humidity (kg/kg). |
Return type: | float or ndarray |
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: |
|
---|---|
Returns: | qv – Data for specific humidity (kg/kg). |
Return type: | float or ndarray |
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). |
---|---|
Returns: | qv – Data for specific humidity (kg/kg). |
Return type: | float or ndarray |
Calculates specific humidity (kg/kg) assuming liquid water can be neglected.
\(q_v = q_t - q_i\)
Parameters: |
|
---|---|
Returns: | qv – Data for specific humidity (kg/kg). |
Return type: | float or ndarray |
Calculates specific humidity (kg/kg) assuming ice can be neglected.
\(q_v = q_t-q_l\)
Parameters: |
|
---|---|
Returns: | qv – Data for specific humidity (kg/kg). |
Return type: | float or ndarray |
Calculates specific humidity (kg/kg).
\(q_v = q_t-q_l-q_i\)
Parameters: |
|
---|---|
Returns: | qv – Data for specific humidity (kg/kg). |
Return type: | float or ndarray |
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). |
---|---|
Returns: | qv – Data for specific humidity (kg/kg). |
Return type: | float or ndarray |
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). |
---|---|
Returns: | qv – Data for specific humidity (kg/kg). |
Return type: | float or ndarray |
Calculates saturation specific humidity with respect to liquid water (kg/kg).
\(q_{vs} = qv\_from\_p\_e(p, e_s)\)
Parameters: |
|
---|---|
Returns: | qvs – Data for saturation specific humidity with respect to liquid water (kg/kg). |
Return type: | float or ndarray |
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: |
|
---|---|
Returns: | qvs – Data for saturation specific humidity with respect to liquid water (kg/kg). |
Return type: | float or ndarray |
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). |
---|---|
Returns: | qvs – Data for saturation specific humidity with respect to liquid water (kg/kg). |
Return type: | float or ndarray |
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). |
---|---|
Returns: | qvs – Data for saturation specific humidity with respect to liquid water (kg/kg). |
Return type: | float or ndarray |
Calculates saturation specific humidity with respect to ice (kg/kg).
\(q_{vsi} = qv\_from\_p\_e(p, e_{si})\)
Parameters: |
|
---|---|
Returns: | qvsi – Data for saturation specific humidity with respect to ice (kg/kg). |
Return type: | float or ndarray |
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: |
|
---|---|
Returns: | qvsi – Data for saturation specific humidity with respect to ice (kg/kg). |
Return type: | float or ndarray |
Calculates density (kg/m^3) assuming the ideal gas law holds.
\(\rho = \frac{p}{R_d T_v}\)
Parameters: |
|
---|---|
Returns: | rho – Data for density (kg/m^3). |
Return type: | float or ndarray |
Calculates density (kg/m^3).
\(\rho = \frac{AH}{q_v}\)
Parameters: |
|
---|---|
Returns: | rho – Data for density (kg/m^3). |
Return type: | float or ndarray |
Calculates ice mixing ratio (kg/kg) assuming liquid water can be neglected.
\(r_i = r_t-r_v\)
Parameters: |
|
---|---|
Returns: | ri – Data for ice mixing ratio (kg/kg). |
Return type: | float or ndarray |
Calculates ice mixing ratio (kg/kg).
\(r_i = r_t-r_v-r_l\)
Parameters: |
|
---|---|
Returns: | ri – Data for ice mixing ratio (kg/kg). |
Return type: | float or ndarray |
Calculates liquid water mixing ratio (kg/kg) assuming ice can be neglected.
\(r_l = r_t-r_v\)
Parameters: |
|
---|---|
Returns: | rl – Data for liquid water mixing ratio (kg/kg). |
Return type: | float or ndarray |
Calculates liquid water mixing ratio (kg/kg).
\(r_l = r_t-r_v-r_i\)
Parameters: |
|
---|---|
Returns: | rl – Data for liquid water mixing ratio (kg/kg). |
Return type: | float or ndarray |
Calculates total water mixing ratio (kg/kg).
\(r_t = r_i+r_v+r_l\)
Parameters: |
|
---|---|
Returns: | rt – Data for total water mixing ratio (kg/kg). |
Return type: | float or ndarray |
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). |
---|---|
Returns: | rt – Data for total water mixing ratio (kg/kg). |
Return type: | float or ndarray |
Calculates total water mixing ratio (kg/kg) assuming liquid water can be neglected.
\(r_t = r_v+r_l\)
Parameters: |
|
---|---|
Returns: | rt – Data for total water mixing ratio (kg/kg). |
Return type: | float or ndarray |
Calculates total water mixing ratio (kg/kg) assuming ice can be neglected.
\(r_t = r_v+r_l\)
Parameters: |
|
---|---|
Returns: | rt – Data for total water mixing ratio (kg/kg). |
Return type: | float or ndarray |
Calculates water vapor mixing ratio (kg/kg).
\(r_v = \frac{RH}{100} r_{vs}\)
Parameters: |
|
---|---|
Returns: | rv – Data for water vapor mixing ratio (kg/kg). |
Return type: | float or ndarray |
Calculates water vapor mixing ratio (kg/kg).
\(r_v = \frac{RH_i}{100} r_{vsi}\)
Parameters: |
|
---|---|
Returns: | rv – Data for water vapor mixing ratio (kg/kg). |
Return type: | float or ndarray |
Calculates water vapor mixing ratio (kg/kg).
\(r_v = rac{-311 (T-T_v)}{500 T - 311 T_v}\)
Parameters: |
|
---|---|
Returns: | rv – Data for water vapor mixing ratio (kg/kg). |
Return type: | float or ndarray |
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: |
|
---|---|
Returns: | rv – Data for water vapor mixing ratio (kg/kg). |
Return type: | float or ndarray |
Calculates water vapor mixing ratio (kg/kg).
\(rv = (\frac{Rd}{Rv}) \frac{e}{p-e}\)
Parameters: |
|
---|---|
Returns: | rv – Data for water vapor mixing ratio (kg/kg). |
Return type: | float or ndarray |
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). |
---|---|
Returns: | rv – Data for water vapor mixing ratio (kg/kg). |
Return type: | float or ndarray |
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). |
---|---|
Returns: | rv – Data for water vapor mixing ratio (kg/kg). |
Return type: | float or ndarray |
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). |
---|---|
Returns: | rv – Data for water vapor mixing ratio (kg/kg). |
Return type: | float or ndarray |
Calculates water vapor mixing ratio (kg/kg) assuming liquid water can be neglected.
\(r_v = r_t - r_i\)
Parameters: |
|
---|---|
Returns: | rv – Data for water vapor mixing ratio (kg/kg). |
Return type: | float or ndarray |
Calculates water vapor mixing ratio (kg/kg) assuming ice can be neglected.
\(r_v = r_t-r_l\)
Parameters: |
|
---|---|
Returns: | rv – Data for water vapor mixing ratio (kg/kg). |
Return type: | float or ndarray |
Calculates water vapor mixing ratio (kg/kg).
\(r_v = r_t-r_l-r_i\)
Parameters: |
|
---|---|
Returns: | rv – Data for water vapor mixing ratio (kg/kg). |
Return type: | float or ndarray |
Calculates saturation water vapor mixing ratio with respect to liquid water (kg/kg).
\(r_{vs} = rv\_from\_p\_e(p, e_s)\)
Parameters: |
|
---|---|
Returns: | rvs – Data for saturation water vapor mixing ratio with respect to liquid water (kg/kg). |
Return type: | float or ndarray |
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). |
---|---|
Returns: | rvs – Data for saturation water vapor mixing ratio with respect to liquid water (kg/kg). |
Return type: | float or ndarray |
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). |
---|---|
Returns: | rvs – Data for saturation water vapor mixing ratio with respect to liquid water (kg/kg). |
Return type: | float or ndarray |
Calculates saturation water vapor mixing ratio with respect to ice (kg/kg).
\(r_{vsi} = rv\_from\_p\_e(p, e_{si})\)
Parameters: |
|
---|---|
Returns: | rvsi – Data for saturation water vapor mixing ratio with respect to ice (kg/kg). |
Return type: | float or ndarray |
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). |
---|---|
Returns: | rvsi – Data for saturation water vapor mixing ratio with respect to ice (kg/kg). |
Return type: | float or ndarray |
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). |
---|---|
Returns: | rvsi – Data for saturation water vapor mixing ratio with respect to ice (kg/kg). |
Return type: | float or ndarray |
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: |
|
---|---|
Returns: | theta – Data for potential temperature (K). |
Return type: | float or ndarray |
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: |
|
---|---|
Returns: | thetae – Data for equivalent temperature (K). |
Return type: | float or ndarray |
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: |
|
---|---|
Returns: | thetae – Data for equivalent temperature (K). |
Return type: | 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
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: |
|
---|---|
Returns: | thetae – Data for equivalent temperature (K). |
Return type: | float or ndarray |
Notes
References
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: |
|
---|---|
Returns: | thetaes – Data for saturation equivalent temperature (K). |
Return type: | float or ndarray |
Notes
See thetae_from_theta_Tlcl_rv_Bolton for more information.
References
Calculates vertical velocity (m/s) assuming g is constant and hydrostatic balance.
\(w = - \frac{\omega}{\rho g_0}\)
Parameters: |
|
---|---|
Returns: | w – Data for vertical velocity (m/s). |
Return type: | float or ndarray |
Calculates height (m) assuming g is constant.
\(z = \frac{\Phi}{g_0}\)
Parameters: | Phi (float or ndarray) – Data for geopotential (m^2/s^2). |
---|---|
Returns: | z – Data for height (m). |
Return type: | float or ndarray |
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: |
|
---|---|
Returns: | out – A BaseSolver object with the specified assumptions and variables. |
Return type: | 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>
Calculates and returns a requested quantity from quantities stored in this object at initialization.
Parameters: | *args – Name of quantity to be calculated. |
---|---|
Returns: | quantity – Calculated quantity, in units listed under quantity parameters. |
Return type: | 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
Bases: exceptions.Exception
Used in calculating shortest solutions to indicate solutions where all remaining variables to calculated are excluded.
Bases: atmos.solve.BaseSolver
Initializes with the given assumptions enabled, and variables passed as keyword arguments stored.
Parameters: |
|
---|---|
Returns: | out – A FluidSolver object with the specified assumptions and variables. |
Return type: | FluidSolver |
Notes
Quantity kwargs
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
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
Bases: type
Metaclass for BaseSolver to automatically generate docstrings and assumption lists for subclasses of BaseSolver.
Calculates and returns a requested quantity from quantities passed in as keyword arguments.
Parameters: |
|
---|---|
Returns: | quantity – Calculated quantity. Return type is the same as quantity parameter types. If multiple quantities are requested, returns a tuple containing the quantities. |
Return type: | ndarray |
Notes
Calculating multiple quantities at once can avoid re-computing intermediate quantities, but requires more memory.
Quantity kwargs
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
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
Given an interable of input quantity names and a methods dictionary, returns a list of output quantities that can be calculated.
Created on Fri Mar 27 13:11:26 2015
@author: mcgibbon
Calculates the area enclosed by an arbitrary polygon on the sphere.
Parameters: |
|
---|---|
Returns: | area – The desired spherical area in the same units as r_sphere. |
Return type: | 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
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. |
---|
Finds the index value in an iterable closest to a desired value.
Parameters: |
|
---|---|
Returns: | index – The index of the closest value to x in L. |
Return type: | int |
Notes
Assumes x and the entries of L are of comparable types.
Raises: | ValueError – if L is empty |
---|
Calculates a second-order centered finite difference of data along the specified axis.
Parameters: |
|
---|---|
Returns: | derivative – Derivative of the data along the specified axis. |
Return type: | ndarray |
Raises: | 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. |
Calculates a second-order centered finite difference derivative of data along the specified axis.
Parameters: |
|
---|---|
Returns: | derivative – Derivative of the data along the specified axis. |
Return type: | ndarray |
Raises: | 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. |
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.
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.
Returns a quantity specification for docstrings.
Example
>>> quantity_spec_string('Tv')
>>> 'Tv : float or ndarray
Data for virtual temperature.'
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
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.