Using calculate()

What does calculate do?

atmos.calculate() takes input variables (like pressure, virtual temperature, water vapor mixing ratio, etc.) and information about what assumptions you’re willing to make (hydrostatic? low water vapor? ignore virtual temperature correction? use an empirical formula for equivalent potential temperature?), and from that calculates any desired output variables that you request and can be calculated.

This function is essentially a wrapper for atmos.FluidSolver, so much or all of its functionality will be the same, and the documentation for the two is very similar.

What can it calculate?

Anything that can be calculated by equations in atmos.equations. If you find that calculate() can’t do a calculation you might expect it to, check the equations it has available and make sure you’re using the right variables, or enabling the right assumptions. A common problem is using T instead of Tv and expecting the ideal gas law to work.

A simple example

By default, a certain set of assumptions are used, such as that we are considering an ideal gas, and so can use ideal gas law. This allows us to do simple calculations that use the default assumptions. For example, to calculate pressure from virtual temperature and density:

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

Or to calculate relative humidity from water vapor mixing ratio and saturation water vapor mixing ratio (which needs no assumptions):

>>> import atmos
>>> atmos.calculate('RH', rv=0.001, rvs=0.002)
50.0

For a full list of default assumptions, see atmos.calculate().

Specifying Units

By default, SI units are assumed. These can be overridden with keyword arguments of the form {quantity name}_unit or {quantity name}_units. Specifying units makes it so that both inputs and outputs of the quantity will be in the specified units.

To get pressure in hPa:

>>> import atmos
>>> atmos.calculate('p', p_units='hPa', Tv=273., rho=1.27)
995.19638400000008

To specify mixing ratio in g/kg:

>>> import atmos
>>> atmos.calculate('RH', rv=1, rvs=0.002, rv_unit='g/kg')
50.0

Note that either “_unit” or “_units” can be used, and that units must be specified for each quantity independently.

Unit names are the same as in the Pint package, with the exception that relative humidity can have units of “percent” or “fraction”. Remember that C in Pint is Coulombs, while degC is degrees Celsius.

Viewing equation functions used

Calculating pressure from virtual temperature and density, also returning a list of functions used:

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

Adding and removing assumptions

If you want to use assumptions that are not enabled by default (such as ignoring the virtual temperature correction), you can use the add_assumptions keyword argument, which takes a tuple of strings specifying assumptions. The exact string to enter for each assumption is detailed in atmos.calculate(). For example, to calculate T instead of Tv, neglecting the virtual temperature correction:

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

Overriding assumptions

If you want to ignore the default assumptions entirely, you could specify your own assumptions:

>>> import atmos
>>> assumptions = ('ideal gas', 'bolton')
>>> atmos.calculate('p', Tv=273., rho=1.27, assumptions=assumptions)
99519.638400000011

Specifying quantities with a dictionary

If you are repeatedly calculating different quantities, you may want to use a dictionary to more easily pass in quantities as keyword arguments. Adding ** to the beginning of a dictionary variable as an argument passes in each of the (key, value) pairs in that dictionary as a separate keyword argument. For example:

>>> import atmos
>>> data = {'Tv': 273., 'rho': 1.27}
>>> data['p'] = atmos.calculate('p', **data)
>>> data['p']
99519.638400000011

Function reference

atmos.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.
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

  • 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