# Checking for essm version installed
import pkg_resources
pkg_resources.get_distribution("essm").version

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

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)

import scipy as sc
# Import various functions from sympy
from sympy import Derivative, Eq, exp, log, solve, Symbol

from essm.variables.utils import generate_metadata_table, ListTable

"""
Explanation: 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:
End of explanation
"""


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])

"""
Explanation: General physics variables and equations
Variables
Pre-defined thermodynamics variables can be imported from essm.variables.physics.thermodynamics:
End of explanation
"""


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

"""
Explanation: 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:
End of explanation
"""


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])

"""
Explanation: Variables and equations related to plant leaves
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:
End of explanation
"""


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

"""
Explanation: Equations for leaf energy and water balance
General equations based on the above variables can be imported from essm.equations.physics.thermodynamics:
End of explanation
"""


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])

"""
Explanation: Variables for leaf radiative balance
Variables related to the model by can be imported from essm.variables.leaf.radiation:
End of explanation
"""


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])

"""
Explanation: 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:
End of explanation
"""


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])

"""
Explanation: Leaf chamber mass balance
Variables related to the model by can be imported from essm.variables.chamber.mass:
End of explanation
"""


