Importable variables and equations

This jupyter notebook can be found at: https://github.com/environmentalscience/essm/blob/master/docs/examples/importable_variables_equations.ipynb

Below, we will import some generic python packages that are used in this notebook:


In [1]:
# Checking for essm version installed
import pkg_resources
pkg_resources.get_distribution("essm").version


Out[1]:
'0.4.2.dev5'

In [14]:
from IPython.core.display import display, HTML
display(HTML("<style>.container { width:150% !important; }</style>"))



In [4]:
from IPython.display import display
from sympy import init_printing, latex
init_printing() 
from sympy.printing import StrPrinter
StrPrinter._print_Quantity = lambda self, expr: str(expr.abbrev)    # displays short units (m instead of meter)

In [5]:
import scipy as sc
# Import various functions from sympy
from sympy import Derivative, Eq, exp, log, solve, Symbol

In [6]:
from essm.variables.utils import generate_metadata_table, ListTable

General physics variables and equations

Variables

Pre-defined thermodynamics variables can be imported from essm.variables.physics.thermodynamics:


In [7]:
import essm.variables.physics.thermodynamics as physics_vars
vars = ['physics_vars.' + name for name in physics_vars.__all__]
generate_metadata_table([eval(name) for name in vars])


Out[7]:
SymbolNameDescriptionDefinitionDefault valueUnits
$\alpha_a$alpha_aThermal diffusivity of dry air.-m$^{2}$ s$^{-1}$
$\lambda_E$lambda_ELatent heat of evaporation.2450000.0J kg$^{-1}$
$\nu_a$nu_aKinematic viscosity of dry air.-m$^{2}$ s$^{-1}$
$\rho_a$rho_aDensity of dry air.-kg m$^{-3}$
$\sigma$sigmStefan-Boltzmann constant.5.67e-08J s$^{-1}$ m$^{-2}$ K$^{-4}$
$c_{pa,mol}$c_pamolMolar specific heat of dry air. https://en.wikipedia.org/wiki/Heat_capacity#Specific_heat_capacity 29.19J K$^{-1}$ mol$^{-1}$
$c_{pa}$c_paSpecific heat of dry air.1010.0J K$^{-1}$ kg$^{-1}$
$c_{pv}$c_pvSpecific heat of water vapour at 300 K. http://www.engineeringtoolbox.com/water-vapor-d_979.html 1864J K$^{-1}$ kg$^{-1}$
$C_{wa}$C_waConcentration of water in air.-mol m$^{-3}$
$D_{va}$D_vaBinary diffusion coefficient of water vapour in air.-m$^{2}$ s$^{-1}$
$g$gGravitational acceleration.9.81m s$^{-2}$
$h_c$h_cAverage 1-sided convective heat transfer coefficient.-J K$^{-1}$ s$^{-1}$ m$^{-2}$
$k_a$k_aThermal conductivity of dry air.-J K$^{-1}$ m$^{-1}$ s$^{-1}$
$M_w$M_wMolar mass of water.0.018kg mol$^{-1}$
$M_{air}$M_airMolar mass of air. http://www.engineeringtoolbox.com/molecular-mass-air-d_679.html 0.02897kg mol$^{-1}$
$M_{N_2}$M_N2Molar mass of nitrogen.0.028kg mol$^{-1}$
$M_{O_2}$M_O2Molar mass of oxygen.0.032kg mol$^{-1}$
$N_{Gr_L}$GrGrashof number.-1
$N_{Le}$LeLewis number.-1
$N_{Nu_L}$NuAverage Nusselt number over given length.-1
$N_{Pr}$PrPrandtl number (0.71 for air).-1
$N_{Re_c}$Re_cCritical Reynolds number for the onset of turbulence.-1
$N_{Re_L}$ReAverage Reynolds number over given length.-1
$P_a$P_aAir pressure.-Pa
$P_{N2}$P_N2Partial pressure of nitrogen.-Pa
$P_{O2}$P_O2Partial pressure of oxygen.-Pa
$P_{was}$P_wasSaturation water vapour pressure at air temperature.-Pa
$P_{wa}$P_waWater vapour pressure in the atmosphere.-Pa
$R_d$R_dDownwelling global radiation.-W m$^{-2}$
$R_s$R_sSolar shortwave flux per area.-J s$^{-1}$ m$^{-2}$
$R_u$R_uUpwelling global radiation.-W m$^{-2}$
$R_{mol}$R_molMolar gas constant.8.314472J K$^{-1}$ mol$^{-1}$
$T_0$T0Freezing point in Kelvin.273.15K
$T_a$T_aAir temperature.-K
$v_w$v_wWind velocity.-m s$^{-1}$
$x_{N2}$x_N2Mole fraction of nitrogen in dry air.0.791
$x_{O2}$x_O2Mole fraction of oxygen in dry air.0.211

Each of the above can also be imported one-by-one, using its Name, e.g.:

from essm.variables.physics.thermodynamics import R_mol

Equations

General equations based on the above variables can be imported from essm.equations.physics.thermodynamics:


In [8]:
import essm.equations.physics.thermodynamics as physics_eqs
modstr = 'physics_eqs.'
eqs = [name for name in physics_eqs.__all__]
table = ListTable()
#table.append(('Name', 'Description', 'Equation'))
for name in eqs:
    table.append((name, eval(modstr+name).__doc__, latex('$'+latex(eval(modstr+name))+'$')))
table


Out[8]:
eq_LeLe as function of alpha_a and D_va. (Eq. B3 in :cite:`schymanski_leaf-scale_2017`) $N_{Le} = \frac{\alpha_a}{D_{va}}$
eq_CwaC_wa as a function of P_wa and T_a. (Eq. B9 in :cite:`schymanski_leaf-scale_2017`) $C_{wa} = \frac{P_{wa}}{R_{mol} T_a}$
eq_Nu_forced_allNu as function of Re and Re_c under forced conditions. (Eqs. B13--B15 in :cite:`schymanski_leaf-scale_2017`) $N_{Nu_L} = - \frac{\sqrt[3]{N_{Pr}} \left(- 37 N_{Re_L}^{\frac{4}{5}} + 37 \left(N_{Re_L} + N_{Re_c} - \frac{\left|{N_{Re_L} - N_{Re_c}}\right|}{2}\right)^{\frac{4}{5}} - 664 \sqrt{N_{Re_L} + N_{Re_c} - \frac{\left|{N_{Re_L} - N_{Re_c}}\right|}{2}}\right)}{1000}$
eq_DvaD_va as a function of air temperature. (Table A.3 in :cite:`monteith_principles_2007`) $D_{va} = T_a p_1 - p_2$
eq_alphaaalpha_a as a function of air temperature. (Table A.3 in :cite:`monteith_principles_2007`) $\alpha_a = T_a p_1 - p_2$
eq_kak_a as a function of air temperature. (Table A.3 in :cite:`monteith_principles_2007`) $k_a = T_a p_1 + p_2$
eq_nuanu_a as a function of air temperature. (Table A.3 in :cite:`monteith_principles_2007`) $\nu_a = T_a p_1 - p_2$
eq_rhoa_Pwa_Tarho_a as a function of P_wa and T_a. (Eq. B20 in :cite:`schymanski_leaf-scale_2017`) $\rho_a = \frac{M_{N_2} P_{N2} + M_{O_2} P_{O2} + M_w P_{wa}}{R_{mol} T_a}$
eq_PaCalculate air pressure. From partial pressures of N2, O2 and H2O, following Dalton's law of partial pressures. $P_a = P_{N2} + P_{O2} + P_{wa}$
eq_PN2_PO2Calculate P_N2 as a function of P_O2. It follows Dalton's law of partial pressures. $P_{N2} = \frac{P_{O2} x_{N2}}{x_{O2}}$
eq_PO2Calculate P_O2 as a function of P_a, P_N2 and P_wa.$P_{O2} = \frac{P_a x_{O2} - P_{wa} x_{O2}}{x_{N2} + x_{O2}}$
eq_PN2Calculate P_N2 as a function of P_a, P_O2 and P_wa.$P_{N2} = \frac{P_a x_{N2} - P_{wa} x_{N2}}{x_{N2} + x_{O2}}$
eq_rhoaCalculate rho_a from T_a, P_a and P_wa.$\rho_a = \frac{x_{N2} \left(M_{N_2} P_a - P_{wa} \left(M_{N_2} - M_w\right)\right) + x_{O2} \left(M_{O_2} P_a - P_{wa} \left(M_{O_2} - M_w\right)\right)}{R_{mol} T_a x_{N2} + R_{mol} T_a x_{O2}}$

These refer to the model by Schymanski & Or (2017).

Variables for leaf energy and water balance

Variables related to the model by can be imported from essm.variables.leaf.energy_water:


In [9]:
import essm.variables.leaf.energy_water as leaf_energy
vars = ['leaf_energy.' + name for name in leaf_energy.__all__]
generate_metadata_table([eval(name) for name in vars])


/home/stan/Programs/essm/essm/variables/_core.py:89: UserWarning: "essm.variables.physics.thermodynamics:Gr" will be overridden by "essm.variables.leaf.energy_water:<class 'essm.variables.leaf.energy_water.Gr'>"
  instance[expr] = instance
/home/stan/Programs/essm/essm/variables/_core.py:89: UserWarning: "essm.variables.physics.thermodynamics:h_c" will be overridden by "essm.variables.leaf.energy_water:<class 'essm.variables.leaf.energy_water.h_c'>"
  instance[expr] = instance
Out[9]:
SymbolNameDescriptionDefinitionDefault valueUnits
$\alpha_l$alpha_lLeaf albedo, fraction of shortwave radiation reflected by the leaf.-1
$\epsilon_l$epsilon_lLongwave emmissivity of the leaf surface.1.01
$\rho_{al}$rho_alDensity of air at the leaf surface.-kg m$^{-3}$
$a_s$a_sFraction of one-sided leaf area covered by stomata. (1 if stomata are on one side only, 2 if they are on both sides). -1
$a_{sh}$a_shFraction of projected area exchanging sensible heat with the air.2.01
$C_{wl}$C_wlConcentration of water in the leaf air space.-mol m$^{-3}$
$E_l$E_lLatent heat flux from leaf.-J s$^{-1}$ m$^{-2}$
$E_{l,mol}$E_lmolTranspiration rate in molar units.-mol s$^{-1}$ m$^{-2}$
$g_{bw,mol}$g_bwmolBoundary layer conductance to water vapour.-mol s$^{-1}$ m$^{-2}$
$g_{bw}$g_bwBoundary layer conductance to water vapour.-m s$^{-1}$
$g_{sw,mol}$g_swmolStomatal conductance to water vapour.-mol s$^{-1}$ m$^{-2}$
$g_{sw}$g_swStomatal conductance to water vapour.-m s$^{-1}$
$g_{tw,mol}$g_twmolTotal leaf layer conductance to water vapour.-mol s$^{-1}$ m$^{-2}$
$g_{tw}$g_twTotal leaf conductance to water vapour.-m s$^{-1}$
$h_c$h_cAverage 1-sided convective heat transfer coefficient.-J K$^{-1}$ s$^{-1}$ m$^{-2}$
$H_l$H_lSensible heat flux from leaf.-J s$^{-1}$ m$^{-2}$
$L_A$L_ALeaf area.-m$^{2}$
$L_l$L_lLeaf width as characteristic length scale for convection.-m
$N_{Gr_L}$GrGrashof number.-1
$P_{wl}$P_wlWater vapour pressure inside the leaf.-Pa
$r_{bw}$r_bwBoundary layer resistance to water vapour, inverse of $g_{bw}$.-s m$^{-1}$
$R_{la}$R_laLongwave radiation absorbed by leaf.-W m$^{-2}$
$R_{ld}$R_ldDownwards emitted/reflected global radiation from leaf.-W m$^{-2}$
$R_{ll}$R_llLongwave radiation away from leaf.-W m$^{-2}$
$R_{lu}$R_luUpwards emitted/reflected global radiation from leaf.-W m$^{-2}$
$r_{sw}$r_swStomatal resistance to water vapour, inverse of $g_{sw}$.-s m$^{-1}$
$r_{tw}$r_twTotal leaf resistance to water vapour, $r_{bv} + r_{sv}$.-s m$^{-1}$
$T_l$T_lLeaf temperature.-K
$T_w$T_wRadiative temperature of objects surrounding the leaf.-K

Equations for leaf energy and water balance

General equations based on the above variables can be imported from essm.equations.physics.thermodynamics:


In [10]:
import essm.equations.leaf.energy_water as leaf_energy
modstr = 'leaf_energy.'
eqs = [name for name in leaf_energy.__all__]
table = ListTable()
#table.append(('Name', 'Description', 'Equation'))
for name in eqs:
    table.append((name, eval(modstr+name).__doc__, latex('$'+latex(eval(modstr+name))+'$')))
table


Out[10]:
eq_Rs_enbalCalculate R_s from energy balance. (Eq. 1 in :cite:`schymanski_leaf-scale_2017`) $R_s = E_l + H_l + R_{ll}$
eq_RllR_ll as function of T_l and T_w. (Eq. 2 in :cite:`schymanski_leaf-scale_2017`) $R_{ll} = a_{sh} \epsilon_l \sigma \left(T_l^{4} - T_w^{4}\right)$
eq_HlH_l as function of T_l. (Eq. 3 in :cite:`schymanski_leaf-scale_2017`) $H_l = a_{sh} h_c \left(- T_a + T_l\right)$
eq_ElE_l as function of E_lmol. (Eq. 4 in :cite:`schymanski_leaf-scale_2017`) $E_l = E_{l,mol} M_w \lambda_E$
eq_ElmolE_lmol as functino of g_tw and C_wl. (Eq. 5 in :cite:`schymanski_leaf-scale_2017`) $E_{l,mol} = g_{tw} \left(- C_{wa} + C_{wl}\right)$
eq_gtwg_tw from g_sw and g_bw. (Eq. 6 in :cite:`schymanski_leaf-scale_2017`) $g_{tw} = \frac{1}{\frac{1}{g_{sw}} + \frac{1}{g_{bw}}}$
eq_gbw_hcg_bw as function of h_c. (Eq. B2 in :cite:`schymanski_leaf-scale_2017`) $g_{bw} = \frac{a_s h_c}{N_{Le}^{\frac{2}{3}} c_{pa} \rho_a}$
eq_CwlC_wl as function of P_wl and T_l. (Eq. B4 in :cite:`schymanski_leaf-scale_2017`) $C_{wl} = \frac{P_{wl}}{R_{mol} T_l}$
eq_PwlClausius-Clapeyron P_wl as function of T_l. (Eq. B3 in :cite:`hartmann_global_1994`) $P_{wl} = p_1 e^{- \frac{M_w \lambda_E \left(- \frac{1}{p_2} + \frac{1}{T_l}\right)}{R_{mol}}}$
eq_Elmol_convE_lmol as function of g_twmol and P_wl. (Eq. B6 in :cite:`schymanski_leaf-scale_2017`) $E_{l,mol} = \frac{g_{tw,mol} \left(- P_{wa} + P_{wl}\right)}{P_a}$
eq_gtwmol_gtwg_twmol as a function of g_tw. It uses eq_Elmol, eq_Cwl and eq_Elmol_conv. $g_{tw,mol} = \frac{g_{tw} \left(P_a P_{wa} T_l - P_a P_{wl} T_a\right)}{R_{mol} T_a T_l \left(P_{wa} - P_{wl}\right)}$
eq_gtwmol_gtw_isog_twmol as a function of g_tw at isothermal conditions.$g_{tw,mol} = \frac{P_a g_{tw}}{R_{mol} T_a}$
eq_hch_c as a function of Nu and L_l. (Eq. B10 in :cite:`schymanski_leaf-scale_2017`) $h_c = \frac{N_{Nu_L} k_a}{L_l}$
eq_ReRe as a function of v_w and L_l. (Eq. B11 in :cite:`schymanski_leaf-scale_2017`) $N_{Re_L} = \frac{L_l v_w}{\nu_a}$
eq_GrGr as function of air density within and outside of leaf. (Eq. B12 in :cite:`schymanski_leaf-scale_2017`) $N_{Gr_L} = \frac{L_l^{3} g \left(\rho_a - \rho_{al}\right)}{\nu_a^{2} \rho_{al}}$

Variables for leaf radiative balance

Variables related to the model by can be imported from essm.variables.leaf.radiation:


In [11]:
import essm.variables.leaf.radiation as leaf_radiation
vars = ['leaf_radiation.' + name for name in leaf_radiation.__all__]
generate_metadata_table([eval(name) for name in vars])


/home/stan/Programs/essm/essm/variables/_core.py:89: UserWarning: "essm.variables.leaf.energy_water:alpha_l" will be overridden by "essm.variables.leaf.radiation:<class 'essm.variables.leaf.radiation.alpha_l'>"
  instance[expr] = instance
/home/stan/Programs/essm/essm/variables/_core.py:89: UserWarning: "essm.variables.physics.thermodynamics:R_d" will be overridden by "essm.variables.leaf.radiation:<class 'essm.variables.leaf.radiation.R_d'>"
  instance[expr] = instance
/home/stan/Programs/essm/essm/variables/_core.py:89: UserWarning: "essm.variables.leaf.energy_water:R_la" will be overridden by "essm.variables.leaf.radiation:<class 'essm.variables.leaf.radiation.R_la'>"
  instance[expr] = instance
/home/stan/Programs/essm/essm/variables/_core.py:89: UserWarning: "essm.variables.leaf.energy_water:R_ld" will be overridden by "essm.variables.leaf.radiation:<class 'essm.variables.leaf.radiation.R_ld'>"
  instance[expr] = instance
/home/stan/Programs/essm/essm/variables/_core.py:89: UserWarning: "essm.variables.leaf.energy_water:R_lu" will be overridden by "essm.variables.leaf.radiation:<class 'essm.variables.leaf.radiation.R_lu'>"
  instance[expr] = instance
/home/stan/Programs/essm/essm/variables/_core.py:89: UserWarning: "essm.variables.physics.thermodynamics:R_u" will be overridden by "essm.variables.leaf.radiation:<class 'essm.variables.leaf.radiation.R_u'>"
  instance[expr] = instance
Out[11]:
SymbolNameDescriptionDefinitionDefault valueUnits
$alpha_l$alpha_lLeaf albedo, fraction of shortwave radiation reflected by the leaf.-1
$R_d$R_dDownwelling global radiation.-J s$^{-1}$ m$^{-2}$
$R_u$R_uUpwelling global radiation.-J s$^{-1}$ m$^{-2}$
$R_{la}$R_laLongwave radiation absorbed by leaf.-J s$^{-1}$ m$^{-2}$
$R_{ld}$R_ldDownwards emitted/reflected global radiation from leaf.-J s$^{-1}$ m$^{-2}$
$R_{lu}$R_luUpwards emitted/reflected global radiation from leaf.-J s$^{-1}$ m$^{-2}$
$S_a$S_aRadiation sensor above leaf reading.-J s$^{-1}$ m$^{-2}$
$S_b$S_bRadiation sensor below leaf reading.-J s$^{-1}$ m$^{-2}$
$S_s$S_sRadiation sensor beside leaf reading.-J s$^{-1}$ m$^{-2}$

Variables for leaf chamber model

These refer to the model by Schymanski & Or (2017) and ongoing work.

Leaf chamber insulation

Variables related to the model by can be imported from essm.variables.chamber.insulation:


In [12]:
import essm.variables.chamber.insulation as chamber_ins
vars = ['chamber_ins.' + name for name in chamber_ins.__all__]
generate_metadata_table([eval(name) for name in vars])


Out[12]:
SymbolNameDescriptionDefinitionDefault valueUnits
$A_i$A_iConducting area of insulation material.-m$^{2}$
$c_{pi}$c_piHeat capacity of insulation material.-J K$^{-1}$ kg$^{-1}$
$dT_i$dT_iTemperature increment of insulation material.-K
$L_i$L_iThickness of insulation material.-m
$lambda_i$lambda_iHeat conductivity of insulation material.-J K$^{-1}$ m$^{-1}$ s$^{-1}$
$Q_i$Q_iHeat conduction through insulation material.-J s$^{-1}$
$rho_i$rho_iDensity of insulation material.-kg m$^{-3}$

Leaf chamber mass balance

Variables related to the model by can be imported from essm.variables.chamber.mass:


In [13]:
import essm.variables.chamber.mass as chamber_mass
vars = ['chamber_mass.' + name for name in chamber_mass.__all__]
generate_metadata_table([eval(name) for name in vars])


/home/stan/Programs/essm/essm/variables/_core.py:89: UserWarning: "essm.variables.leaf.energy_water:L_A" will be overridden by "essm.variables.chamber.mass:<class 'essm.variables.chamber.mass.L_A'>"
  instance[expr] = instance
Out[13]:
SymbolNameDescriptionDefinitionDefault valueUnits
$F_{in,mol,a}$F_in_molaMolar flow rate of dry air into chamber.-mol s$^{-1}$
$F_{in,mol,w}$F_in_molwMolar flow rate of water vapour into chamber.-mol s$^{-1}$
$F_{in,v}$F_in_vVolumetric flow rate into chamber.-m$^{3}$ s$^{-1}$
$F_{out,mol,a}$F_out_molaMolar flow rate of dry air out of chamber.-mol s$^{-1}$
$F_{out,mol,w}$F_out_molwMolar flow rate of water vapour out of chamber.-mol s$^{-1}$
$F_{out,v}$F_out_vVolumetric flow rate out of chamber.-m$^{3}$ s$^{-1}$
$H_c$H_cChamber height.-m
$L_A$L_ALeaf area.-m$^{2}$
$L_c$L_cChamber length.-m
$n_c$n_cmolar mass of gas in chamber.-mol
$P_{w,in}$P_w_inVapour pressure of incoming air.-Pa
$P_{w,out}$P_w_outVapour pressure of outgoing air.-Pa
$R_{H,in}$R_H_inRelative humidity of incoming air.-1
$T_d$T_dDew point temperature of incoming air.-K
$T_{in}$T_inTemperature of incoming air.-K
$T_{out}$T_outTemperature of outgoing air (= chamber T_a).-K
$T_{room}$T_roomLab air temperature.-K
$V_c$V_cChamber volume.-m$^{3}$
$W_c$W_cChamber width.-m

In [ ]: