Variables module
Module to define all kind of variables in the models.
Variable definition module
Variables are objects with a name, a symbol and units. They represent any formal quantity in the models.
Description of the classes
Variable: Abstract base class to define variables in the models.VariablesArray: Base class to define array of variables in the models.
- class layercake.variables.variable.Variable(name, symbol, units=None, latex=None, dynamical=False)[source]
Bases:
ABCAbstract base class to define variable object in the models.
- Parameters:
name (str) – Name of the variable.
symbol (Symbol) – A Sympy symbol to represent the variable in symbolic expressions.
units (str, optional) – The units of the variable. Should be specified by joining atoms like ‘[unit^power]’, e.g ‘[m^2][s^-2][Pa^-2]’. Empty by default.
latex (str, optional) – Latex string representing the variable. Empty by default.
dynamical (bool, optional) – Whether the variable can vary over time. Default to False.
- units
The units of the variable specified as atoms like ‘[unit^power]’, e.g ‘[m^2][s^-2][Pa^-2]’.
- Type:
- class layercake.variables.variable.VariablesArray(values, name, symbol, units='', latex=None, dynamical=False)[source]
Bases:
ndarrayBase class of model’s array of variables values.
- Parameters:
values (list(float) or ndarray(float)) – Values of the variables array.
name (str) – General name of the variables.
symbol (str or Symbol) – A Sympy symbol to represent the variables in symbolic expressions.
units (str, optional) – The units of the provided value. Used to compute the conversion between dimensional and nondimensional value. Should be specified by joining atoms like ‘[unit^power]’, e.g ‘[m^2][s^-2][Pa^-2]’. Empty by default.
latex (str, optional) – A latex string representing the variables. Used in plots. Empty by default.
dynamical (bool, optional) – Whether the variables are varying over time. Default to False.
Coordinate definition module
A coordinate is a Variable used to define the models’ domains, i.e. as a part of a CoordinatesSystem,
to uniquely determine and standardize the position of the points of the domain.
- class layercake.variables.coordinate.Coordinate(name, symbol, extent, infinitesimal_length=1, infinitesimal_length_units=None, units=None, latex=None)[source]
Bases:
VariableClass to define a physical coordinate in the system.
- Parameters:
name (str) – Name of the coordinate.
symbol (Symbol) – Sympy symbol of the coordinate
extent (tuple(float or Expr or Symbol)) – 2-tuple giving the natural extent of the coordinate, i.e. the lower and higher bounds of the coordinate’s interval.
units (str, optional) – The units of the coordinate. Used to compute the conversion between dimensional and nondimensional value. Should be specified by joining atoms like ‘[unit^power]’, e.g ‘[m^2][s^-2][Pa^-2]’.
infinitesimal_length (float or Expr or Symbol, optional) – Infinitesimal length associated with the
infinitesimal_length_units (str, optional) – Infinitesimal length units. Should be specified by joining atoms like ‘[unit^power]’, e.g ‘[m^2][s^-2][Pa^-2]’.
latex (str, optional) – Latex string representing the coordinate.
- extent
2-tuple giving the natural extent of the coordinate, i.e. the lower and higher bounds of the coordinate’s interval.
- units
The units of the coordinate. Used to compute the conversion between dimensional and nondimensional value.
- Type:
Warning
Coordinates with infinite extent are not currently supported.
Coordinate systems definition module
Coordinate systems defined on models’ domains.
Description of the classes
CoordinateSystem: Base class to define coordinate systems for the the models.PlanarCartesianCoordinateSystem: Cartesian coordinate system defined on a plane.SphericalCoordinateSystem: Coordinate system defined on a sphere.
- class layercake.variables.systems.CoordinateSystem(coordinates, name='', parameters=None)[source]
Bases:
objectBase class to define a coordinate system.
- Parameters:
- parameters
List of parameters used to define the coordinates infinitesimal length.
- class layercake.variables.systems.PlanarCartesianCoordinateSystem(extent)[source]
Bases:
CoordinateSystemClass to define a planar Cartesian coordinate system. Coordinates are \(x\) and \(y\).
- class layercake.variables.systems.SphericalCoordinateSystem(radius, extent=None)[source]
Bases:
CoordinateSystemClass to define a coordinate system on the sphere. Coordinates are the azimuth angle (longitude) \(\lambda\) and the elevation angle (latitude) \(\varphi\).
- Parameters:
Field definition module
This module defines spatial fields in the models.
Description of the classes
Field: Class defining the spatial fields.ParameterField: Class defining static spatial field that can be viewed as models’ parameters.
- class layercake.variables.field.Field(name, symbol, basis, inner_product_definition=None, units=None, latex=None, state=None, **state_kwargs)[source]
Bases:
VariableClass defining the spatial fields in the models.
- Parameters:
name (str) – Name of the field.
symbol (Symbol) – A Sympy symbol to represent the field in symbolic expressions.
basis (SymbolicBasis) – A symbolic basis of functions on which the Galerkin expansion of the field is performed.
inner_product_definition (InnerProductDefinition) – Inner product definition object used to compute the inner products between the elements of the basis.
units (str, optional) – The units of the variable. Should be specified by joining atoms like ‘[unit^power]’, e.g ‘[m^2][s^-2][Pa^-2]’. Empty by default.
latex (str, optional) – Latex string representing the variable. Empty by default.
state (VariablesArray) – Field state array: array containing the coefficient of the field’s Galerkin expansion.
state_kwargs (dict) – Used to create the field state array if state is not a
VariableArray. Passed to theVariableArrayconstructor.
- basis
The symbolic basis of functions on which the Galerkin expansion of the field is performed.
- Type:
- inner_product_definition
The inner product definition object used to compute the inner products between the elements of the basis.
- Type:
- units
The units of the variable. Should be specified by joining atoms like ‘[unit^power]’, e.g ‘[m^2][s^-2][Pa^-2]’.
- Type:
str, optional
- state
Field state array: array containing the coefficient of the field’s Galerkin expansion.
- Type:
- coordinate_system
Coordinate system on which the basis of functions and the inner product are defined.
- Type:
- class layercake.variables.field.FunctionField(name, symbol, symbolic_expression, basis, expression_parameters=None, inner_product_definition=None, units='', latex=None, extra_substitutions=None, force_substitution=False, force_symbolic_substitution=False, **parameters_array_kwargs)[source]
Bases:
VariableClass defining a static spatial fields in the models, specified as a function of the model’s coordinates.
- Parameters:
name (str) – Name of the field.
symbol (Symbol) – Symbol representing the field.
symbolic_expression (Expr) – A Sympy expression to represent the field mathematical expression in symbolic expressions.
basis (SymbolicBasis) – A symbolic basis of functions on which the Galerkin expansion of the field is performed.
expression_parameters (None or list(Parameter), optional) – List of parameters appearing in the symbolic expression. If None, assumes that no parameters are appearing there.
inner_product_definition (InnerProductDefinition or None, optional) – Inner product definition object used to compute the inner products between the elements of the basis. If None, the Galerkin expansion will not be computed, and then this field can only be used in symbolic expressions.
units (str, optional) – The units of the variable. Should be specified by joining atoms like ‘[unit^power]’, e.g ‘[m^2][s^-2][Pa^-2]’. Empty by default.
latex (str, optional) – Latex string representing the variable. Empty by default.
extra_substitutions (list(tuple), optional) – List of 2-tuples containing extra symbolic substitutions to be made at the end of the integral computation. The 2-tuples contain first a Sympy expression and then the value to substitute.
force_substitution (bool, optional) – Force the substitution by the numerical values of the parameters arrays, even in the symbolic case. Default to False.
force_symbolic_substitution (bool, optional) – Force the substitution by the symbolic expressions resulting from the projection of the function field onto the provided basis. Only relevant when working in the symbolic case. Is superseded by the force_substitution argument, i.e. the latter should be set to False for this parameter to work. Default to False.
**parameters_array_kwargs (dict, optional) – Used to create the field state
ParametersArrayobject. Passed to theParametersArrayclass constructor.
- symbolic_expression
A Sympy expression to represent the field mathematical expression in symbolic expressions.
- Type:
- basis
The symbolic basis of functions on which the Galerkin expansion of the field is performed.
- Type:
- inner_product_definition
The inner product definition object used to compute the inner products between the elements of the basis.
- Type:
- units
The units of the variable. Should be specified by joining atoms like ‘[unit^power]’, e.g ‘[m^2][s^-2][Pa^-2]’.
- Type:
- parameters
Array containing the coefficients of the field Galerkin expansion, computed from the specified basis.
- Type:
- expression_parameters
List of parameters appearing in the symbolic expression. If None, assumes that no parameters are appearing there.
- force_substitution
Force the substitution by the numerical values of the parameters arrays, even in the symbolic case.
- Type:
bool, optional
- force_symbolic_substitution
Force the substitution by the symbolic expressions resulting from the projection of the function field onto the provided basis.
- Type:
bool, optional
- property numerical_expression
The numeric expression of the function, i.e. with parameters replaced by their numerical value.
- Type:
- property symbolic_expressions
Returns the symbolic expressions of the parameters in the array.
- class layercake.variables.field.ParameterField(name, symbol, parameters_array, basis, inner_product_definition=None, units='', latex=None, **parameters_array_kwargs)[source]
Bases:
VariableClass defining a static spatial fields in the models. Can be viewed as a model parameter.
- Parameters:
name (str) – Name of the field.
symbol (Symbol) – A Sympy symbol to represent the field in symbolic expressions.
parameters_array (ParametersArray or ndarray) – Array containing the coefficients of the field Galerkin expansion.
basis (SymbolicBasis) – A symbolic basis of functions on which the Galerkin expansion of the field is performed.
inner_product_definition (InnerProductDefinition) – Inner product definition object used to compute the inner products between the elements of the basis.
units (str, optional) – The units of the variable. Should be specified by joining atoms like ‘[unit^power]’, e.g ‘[m^2][s^-2][Pa^-2]’. Empty by default.
latex (str, optional) – Latex string representing the variable. Empty by default.
parameters_array_kwargs (dict, optional) – Used to create the field state if parameters_array is not a
ParametersArrayobject. Passed to theParametersArrayclass constructor.
- basis
The symbolic basis of functions on which the Galerkin expansion of the field is performed.
- Type:
- inner_product_definition
The inner product definition object used to compute the inner products between the elements of the basis.
- Type:
- units
The units of the variable. Should be specified by joining atoms like ‘[unit^power]’, e.g ‘[m^2][s^-2][Pa^-2]’.
- Type:
- parameters
Array containing the coefficients of the field Galerkin expansion.
- Type:
- property symbolic_expressions
Returns the symbolic expressions of the parameters in the array.
Parameter module
This module contains the basic parameter class to hold model’s parameters values. It allows to manipulate dimensional and nondimensional parameter easily.
Examples
>>> from layercake.variables.parameter import Parameter, ParametersArray
>>> import numpy as np
>>> # creating a parameter initialized with a nondimensional value
>>> sigma = Parameter(0.2e0,
... description="static stability of the atmosphere (nondimensional)")
>>> sigma
0.2
>>> # creating a parameter initialized with a dimensional value
>>> sigma = Parameter(2.1581898457499433e-06,
... units='[m^2][s^-2][Pa^-2]',
... description="static stability of the atmosphere")
>>> sigma
2.1581898457499433e-06
>>> # creating a parameters array initialized with a nondimensional values
>>> s = ParametersArray(np.array([[0.1,0.2],[0.3,0.4]]), units='',
... description="atmosphere bottom friction coefficient (nondimensional")
>>> s
ArrayParameters([[0.1, 0.2],
[0.3, 0.4]], dtype=object)
>>> # you can also ask for the value of one particular value of the array
>>> s[0,0]
0.1
Main classes
- class layercake.variables.parameter.Parameter(value, units='', description='', symbol=None, latex=None, symbolic_expression=None)[source]
Bases:
floatBase class of model’s parameter.
- Parameters:
value (float) – Value of the parameter.
units (str, optional) – The units of the provided value. Should be specified by joining atoms like ‘[unit^power]’, e.g ‘[m^2][s^-2][Pa^-2]’. Empty by default.
description (str, optional) – String describing the parameter.
symbol (Symbol, optional) – A Sympy symbol to represent the parameter in symbolic expressions.
latex (str, optional) – A latex string to define the parameter in the latex equations.
symbolic_expression (Expr, optional) – A Sympy expression to represent a relationship to other parameters.
Notes
Parameter is immutable. Once instantiated, it cannot be altered. To create a new parameter, one must re-instantiate it.
- class layercake.variables.parameter.ParametersArray(values, units='', description='', symbols=None, symbolic_expressions=None)[source]
Bases:
ndarrayBase class of model’s array of parameters.
- Parameters:
values (list(float) or ndarray(float) or list(Parameter) or ndarray(Parameter)) – Values of the parameter array.
units (str, optional) – The units of the provided value. Should be specified by joining atoms like ‘[unit^power]’, e.g ‘[m^2][s^-2][Pa^-2]’. Empty by default.
description (str or list(str) or array(str), optional) – String or an iterable of strings, describing the parameters. If an iterable, should have the same length or shape as values.
~numpy.ndarray(~sympy.core.symbol.Symbol) (symbols ~sympy.core.symbol.Symbol or list(Symbol) or) – A Sympy symbol or an iterable of symbols, to represent the parameters in symbolic expressions. If an iterable, should have the same length or shape as values.
optional – A Sympy symbol or an iterable of symbols, to represent the parameters in symbolic expressions. If an iterable, should have the same length or shape as values.
symbolic_expressions (Expr or list(Expr) or ndarray(Expr), optional) – A Sympy expression or an iterable of expressions, to represent a relationship to other parameters. If an iterable, should have the same length or shape as values.
- property symbolic_expressions
Returns the symbolic expressions of the parameters in the array.
Variables utility module
Defines useful functions.