Thermodynamic Calculations

Contains a collection of thermodynamic calculations.

metpy.calc.thermo.potential_temperature(pressure, temperature)

Calculate the potential temperature.

Uses the Poisson equation to calculation the potential temperature given pressure and temperature.

Parameters:
  • pressure (pint.Quantity) – The total atmospheric pressure
  • temperature (pint.Quantity) – The temperature
Returns:

pint.Quantity – The potential temperature corresponding to the the temperature and pressure.

See also

dry_lapse()

Notes

Formula:

\[\Theta = T (P_0 / P)^\kappa\]

Examples

>>> from metpy.units import units
>>> metpy.calc.potential_temperature(800. * units.mbar, 273. * units.kelvin)
290.9814150577374
metpy.calc.thermo.dry_lapse(pressure, temperature)

Calculate the temperature at a level assuming only dry processes.

This function lifts a parcel starting at temperature, conserving potential temperature. The starting pressure should be the first item in the pressure array.

Parameters:
  • pressure (pint.Quantity) – The atmospheric pressure level(s) of interest
  • temperature (pint.Quantity) – The starting temperature
Returns:

pint.Quantity – The resulting parcel temperature at levels given by pressure

See also

moist_lapse()
Calculate parcel temperature assuming liquid saturation processes
parcel_profile()
Calculate complete parcel profile

potential_temperature()

metpy.calc.thermo.moist_lapse(pressure, temperature)

Calculate the temperature at a level assuming liquid saturation processes.

This function lifts a parcel starting at temperature. The starting pressure should be the first item in the pressure array. Essentially, this function is calculating moist pseudo-adiabats.

Parameters:
  • pressure (pint.Quantity) – The atmospheric pressure level(s) of interest
  • temperature (pint.Quantity) – The starting temperature
Returns:

pint.Quantity – The temperature corresponding to the the starting temperature and pressure levels.

See also

dry_lapse()
Calculate parcel temperature assuming dry adiabatic processes
parcel_profile()
Calculate complete parcel profile

Notes

This function is implemented by integrating the following differential equation:

\[\frac{dT}{dP} = \frac{1}{P} \frac{R_d T + L_v r_s} {C_{pd} + \frac{L_v^2 r_s \epsilon}{R_d T^2}}\]

This equation comes from [1].

References

[1]Bakhshaii, A. and R. Stull, 2013: Saturated Pseudoadiabats–A Noniterative Approximation. J. Appl. Meteor. Clim., 52, 5-15.
metpy.calc.thermo.lcl(pressure, temperature, dewpt, max_iters=50, eps=0.01)

Calculate the lifted condensation level (LCL) using from the starting point.

The starting state for the parcel is defined by temperature, dewpt, and pressure.

Parameters:
  • pressure (pint.Quantity) – The starting atmospheric pressure
  • temperature (pint.Quantity) – The starting temperature
  • dewpt (pint.Quantity) – The starting dew point
Returns:

pint.Quantity – The LCL

Other Parameters:
 
  • max_iters (int, optional) – The maximum number of iterations to use in calculation, defaults to 50.
  • eps (float, optional) – The desired absolute error in the calculated value, defaults to 1e-2.

See also

parcel_profile()

Notes

This function is implemented using an iterative approach to solve for the LCL. The basic algorithm is:

  1. Find the dew point from the LCL pressure and starting mixing ratio
  2. Find the LCL pressure from the starting temperature and dewpoint
  3. Iterate until convergence

The function is guaranteed to finish by virtue of the max_iters counter.

metpy.calc.thermo.lfc(pressure, temperature, dewpt)

Calculate the level of free convection (LFC).

This works by finding the first intersection of the ideal parcel path and the measured parcel temperature.

Parameters:
  • pressure (pint.Quantity) – The atmospheric pressure
  • temperature (pint.Quantity) – The temperature at the levels given by pressure
  • dewpt (pint.Quantity) – The dew point at the levels given by pressure
Returns:

pint.Quantity – The LFC

See also

parcel_profile()

metpy.calc.thermo.parcel_profile(pressure, temperature, dewpt)

Calculate the profile a parcel takes through the atmosphere.

The parcel starts at temperature, and dewpt, lifted up dry adiabatically to the LCL, and then moist adiabatically from there. pressure specifies the pressure levels for the profile.

Parameters:
  • pressure (pint.Quantity) – The atmospheric pressure level(s) of interest. The first entry should be the starting point pressure.
  • temperature (pint.Quantity) – The starting temperature
  • dewpt (pint.Quantity) – The starting dew point
Returns:

pint.Quantity – The parcel temperatures at the specified pressure levels.

metpy.calc.thermo.vapor_pressure(pressure, mixing)

Calculate water vapor (partial) pressure.

Given total pressure and water vapor mixing ratio, calculates the partial pressure of water vapor.

Parameters:
  • pressure (pint.Quantity) – total atmospheric pressure
  • mixing (pint.Quantity) – dimensionless mass mixing ratio
Returns:

pint.Quantity – The ambient water vapor (partial) pressure in the same units as pressure.

Notes

This function is a straightforward implementation of the equation given in many places, such as [2]:

\[e = p \frac{r}{r + \epsilon}\]

References

[2]Hobbs, Peter V. and Wallace, John M., 1977: Atmospheric Science, an Introductory Survey. 71.
metpy.calc.thermo.saturation_vapor_pressure(temperature)

Calculate the saturation water vapor (partial) pressure.

Parameters:temperature (pint.Quantity) – The temperature
Returns:pint.Quantity – The saturation water vapor (partial) pressure

Notes

Instead of temperature, dewpoint may be used in order to calculate the actual (ambient) water vapor (partial) pressure.

The formula used is that from Bolton 1980 [3] for T in degrees Celsius:

\[6.112 e^\frac{17.67T}{T + 243.5}\]

References

[3]Bolton, D., 1980: The Computation of Equivalent Potential Temperature. Mon. Wea. Rev., 108, 1046-1053.
metpy.calc.thermo.dewpoint_rh(temperature, rh)

Calculate the ambient dewpoint given air temperature and relative humidity.

Parameters:
  • temperature (pint.Quantity) – Air temperature
  • rh (pint.Quantity) – Relative humidity expressed as a ratio in the range [0, 1]
Returns:

pint.Quantity – The dew point temperature

metpy.calc.thermo.dewpoint(e)

Calculate the ambient dewpoint given the vapor pressure.

Parameters:e (pint.Quantity) – Water vapor partial pressure
Returns:pint.Quantity – Dew point temperature

Notes

This function inverts the Bolton 1980 [4] formula for saturation vapor pressure to instead calculate the temperature. This yield the following formula for dewpoint in degrees Celsius:

\[T = \frac{243.5 log(e / 6.112)}{17.67 - log(e / 6.112)}\]

References

[4]Bolton, D., 1980: The Computation of Equivalent Potential Temperature. Mon. Wea. Rev., 108, 1046-1053.
metpy.calc.thermo.mixing_ratio(part_press, tot_press, molecular_weight_ratio=<Quantity(0.6219800858985514, 'dimensionless')>)

Calculate the mixing ratio of a gas.

This calculates mixing ratio given its partial pressure and the total pressure of the air. There are no required units for the input arrays, other than that they have the same units.

Parameters:
  • part_press (pint.Quantity) – Partial pressure of the constituent gas
  • tot_press (pint.Quantity) – Total air pressure
  • molecular_weight_ratio (pint.Quantity or float, optional) – The ratio of the molecular weight of the constituent gas to that assumed for air. Defaults to the ratio for water vapor to dry air (\(\epsilon\approx0.622\)).
Returns:

pint.Quantity – The (mass) mixing ratio, dimensionless (e.g. Kg/Kg or g/g)

Notes

This function is a straightforward implementation of the equation given in many places, such as [5]:

\[r = \epsilon \frac{e}{p - e}\]

References

[5]Hobbs, Peter V. and Wallace, John M., 1977: Atmospheric Science, an Introductory Survey. 73.
metpy.calc.thermo.saturation_mixing_ratio(tot_press, temperature)

Calculate the saturation mixing ratio of water vapor.

This calculation is given total pressure and the temperature. The implementation uses the formula outlined in [6].

Parameters:
  • tot_press (pint.Quantity) – Total atmospheric pressure
  • temperature (pint.Quantity) – The temperature
Returns:

pint.Quantity – The saturation mixing ratio, dimensionless

References

[6]Hobbs, Peter V. and Wallace, John M., 1977: Atmospheric Science, an Introductory Survey. 73.
metpy.calc.thermo.equivalent_potential_temperature(pressure, temperature)

Calculate equivalent potential temperature.

This calculation must be given an air parcel’s pressure and temperature. The implementation uses the formula outlined in [7].

Parameters:
  • pressure (pint.Quantity) – Total atmospheric pressure
  • temperature (pint.Quantity) – The temperature
Returns:

pint.Quantity – The corresponding equivalent potential temperature of the parcel

Notes

\[\Theta_e = \Theta e^\frac{L_v r_s}{C_{pd} T}\]

References

[7]Hobbs, Peter V. and Wallace, John M., 1977: Atmospheric Science, an Introductory Survey. 78-79.