bronx.meteo.thermo

This modules implements constants and conversions used in thermodynamics.

A brief description of the equations can be found in this document: thermo.pdf

Classes

class bronx.meteo.thermo.Thermo(hydrometeors=None, data=None)[source]

Bases: object

This class aims at containing states parameter.

Values are retrieved by special method which can compute derived parameters. One can put anything inside this class but derived parameter computation uses defined name for some thermodynamic parameters. These names are available in the thermo.N_* constants and comments are in C_*. Values must be all scalars or all numpy.arrays of the same shape.

Example:

>>> data = Thermo()
>>> print(C_T)
Temperature (K)
>>> data.set(N_T, 280)   # in K
>>> data.set(N_P, 75000) # in Pa
>>> print('{:.2f}'.format(data.get(N_Theta)))
303.99

>>> import numpy as np
>>> data2 = Thermo(hydrometeors=['v', ])
>>> data2.set(N_T, np.array([280, 300]))       # in K
>>> data2.set(N_P, np.array([75000, 101300]))  # in Pa
>>> data2.set(N_rv, np.array([0.05, 0.1]))     # in kg/kg
>>> print(' '.join(['{:.2f}'.format(r) for r in data2.get(N_rt)]))
0.05 0.10
>>> print(' '.join(['{:.2f}'.format(t) for t in data2.get(N_ThetaV)]))
312.78 315.41
Parameters:
  • hydrometeors – lists the hydrometeors to consider. If None, only a subset of computations can be done. ‘v’, ‘c’, ‘r’, ‘i’, ‘s’, ‘g’ and ‘h’ are allowed.

  • data – A dictionary. Alternatively, data can be omited and the set`() method can be used.

Example:

>>> data = Thermo()
>>> data.set(N_T, 280)
>>> data.set(N_P, 75000)

# Is equivalent to...
>>> data2 = Thermo(data={N_T:280, N_P:75000})

# Let's check...
>>> data.get(N_T) == data2.get(N_T)
True
>>> data.get(N_P) == data2.get(N_P)
True
static Hui_esati2e(Hui, esati)[source]

Computes e from Hui and esati

static Huw_esatw2e(Huw, esatw)[source]

Computes e from Huw and esatw

static R_T_P2rho(R, T, P)[source]

Computes the volumic mass of wet air (rho) from R, T and P or the volumic mass of dry air (rhod) from Rstar, T and P.

static T2esati(T)[source]

Computes the water vapor pressure at saturation with respect to ice from T

static T2esatw(T)[source]

Computes the water vapor pressure at saturation with respect to liquid water from T

static T_P2Theta(T, P)[source]

Computes Theta from T and P.

static T_phase2esat(T, phase)[source]

Computes the water vapor pressure at saturation from T and phase. Phase is given by:

  • ‘L’, ‘E’ or ‘W’ for liquid water

  • ‘S’, ‘G’ or ‘I’ for ice

static Td2e(Td)[source]

Computes e from Td

static Theta_P2T(Theta, P)[source]

Computes T from Theta and P.

static Theta_qv_qt2ThetaV(Theta, qv, qt)[source]

Computes Theta v from Theta, qv and qt.

static Theta_rv_rt2ThetaV(Theta, rv, rt)[source]

Computes Theta v from Theta, rv and rt.

adjust(species, mix_rule=None, iteration=1, extra_variables=(), precision='full')[source]

This method returns a Thermo instance in which species are adjusted with respect to water vapour (others are kept untouched).

species can only contain ‘c’ and/or ‘i’:

  • if species == ['c'], we adjust with respect to liquid water (mix_rule must be None)

  • if species == ['i'], we adjust with respect to ice (mix_rule must be None)

  • if c and i are in species, mix_rule cannot be None, we have to choose an adjustment way:

    • same, we keep the same partition between liquid and ice (entirely liquid if no previous cloud)

    • 0T-20, we use a linear partition between liquid and ice according to temperature between 0 and -20

Liquid/ice fraction is used to compute a weight-averaged saturation mixing ratio. Adjustment is an iterative process, iteration gives the number of iteration we must perform.

Only T and mixing ratios are set in the new object unless extra_variables is set. extra_variables is a list of variables to get from the current object and to set in the new one. If extra_variables contains thermodynamic variables, they can be in contradiction with the adjusted state; this variable is only useful for variables not impacted by adjustment (P, wind…) precision can be:

  • full: Cp and Lv values are evolving during the evaporation. Species are evaporated in the order given by species. Normally, the order does not matter.

  • standard: Cp and Lv are computed from the initial state and kept constant during evaporation

changeOrder(parameter, increasing=True)[source]

Modify the order of all parameters to sort according to parameter.

static e_P2rv(e, P)[source]

Computes rv from water e and P.

static e_P_qliquid_qice2qv(e, P, qliquid, qice)[source]

Computes qv from e and P.

static e_esati2Hui(e, esati)[source]

Computes Hui from e and esati.

static e_esatw2Huw(e, esatw)[source]

Computes Huw from e and esatw.

evaporate(species, extra_variables=(), precision='full')[source]

This method returns a Thermo instance in which species are evaporated (others are kept untouched).

Only T and mixing ratios are set in the new object unless extra_variables is set. extra_variables is a list of variables to get from the current object and to set in the new one. If extra_variables contain thermodynamic variables, they can be in contradiction with the evaporated state; this variable is only useful for variables not impacted by evaporation (P, wind…) precision can be:

  • full: Cp and Lv values are evolving during the evaporation. Species are evaporated in the order given by species. Normally, the order does not matter.

  • standard: Cp and Lv are computed from the initial state and kept constant during evaporation

get(parameter, methods=None)[source]

Gets or computes a value for parameter

property hydrometeors

The list of hydrometeors.

list()[source]

Iterator over all already known parameters

q2qice(*q)[source]

Computes qice from specific contents

q2qliquid(*q)[source]

Computes qliquid from specific contents

static qc_qi2qci(qc, qi)[source]

Computes specific total cloud condensate from qc and qi.

static qv_qliquid_qice2Cp(qv, qliquid, qice)[source]

Computes the heat capacity at constant pressure from specific contents.

static qv_qliquid_qice2R(qv, qliquid, qice)[source]

Computes R from specific contents

static qv_qliquid_qice2qt(qv, qliquid, qice)[source]

Computes qt from qv, qliquid and qice.

static qv_qliquid_qice_T2TV(qv, qliquid, qice, T)[source]

Computes the virtual temperature from qv, qliquid, qice and T.

static qv_qt_P2e(qv, qt, P)[source]

Computes e from qv, qt and P.

static qx_qt2rx(qx, qt)[source]

Computes mixing ratio from specific content and total specific content.

r2rice(*r)[source]

Computes rice from mixing ratios

r2rliquid(*r)[source]

Computes rliquid from mixing ratios

static rho_qv2rhov(rho, qv)[source]

Computes rhov from rho and qv.

static rv2Rstar(rv)[source]

Computes Rstar from water vaport mixing ratio

static rv_P2e(rv, P)[source]

Computes e from rv and P.

static rv_rliquid_rice2Cph(rv, rliquid, rice)[source]

Computes the specific heat capacity at constant pressure from mixing-ratios.

static rv_rliquid_rice2rt(rv, rliquid, rice)[source]

Computes rt from rv, rliquid and rice.

static rx_rt2qx(rx, rt)[source]

Computes specifc content from mixing ratio and total mixing ratio.

set(parameter, value)[source]

Sets or updates a value for parameter.

static u_v2dd(u, v)[source]

Computes wind direction (in degrees) from zonal and meridional wind speed.

static u_v2ff(u, v)[source]

Computes wind force (in m/s) from zonal and meridional wind speed.

Exceptions

exception bronx.meteo.thermo.ThermoError[source]

Bases: Exception

Errors in thermo.