tespy.tools package¶
tespy.tools.characteristics module¶
Module for characteristic functions.
The characteristics module provides the integration of characteristic lines and characteristic maps. The user can create custom characteristic lines or maps with individual data.
This file is part of project TESPy (github.com/oemof/tespy). It’s copyrighted by the contributors recorded in the version control history of the file, available from its original location tespy/tools/characteristics.py
SPDX-License-Identifier: MIT
- class tespy.tools.characteristics.CharLine(x=array([0, 1]), y=array([1., 1.]), extrapolate=False, x_unit=None, y_unit=None)[source]¶
Bases:
objectClass for characteristc lines.
- Parameters:
x (ndarray, pint.Quantity) – An array for the x-values of the lookup table. Number of x and y values must be identical. A quantity array carries the unit of the axis.
y (ndarray, pint.Quantity) – The corresponding y-values for the lookup table. Number of x and y values must be identical. A quantity array carries the unit of the axis.
extrapolate (boolean) – If
Truelinear extrapolation is performed when the x value is out of the defined value range.x_unit (str) – Unit of the x-values, e.g.
"m3/h", default:None.y_unit (str) – Unit of the y-values, e.g.
"bar", default:None.
Note
This class generates a lookup table from the given input data x and y, then performs linear interpolation. The x and y values may be specified by the user. There are some default characteristic lines for different components, see the tespy.data module. If you neither specify the method to use from the defaults nor specify x and y values, the characteristic line generated will be
x = [0, 1], y = [1, 1].- axes = ('x', 'y')¶
- domain_violations(x, rtol=1e-06)[source]¶
Check the input against the range of the x-values.
- Parameters:
x (float) – Input value for linear interpolation.
rtol (float) – Relative tolerance of the check.
- Returns:
list –
DomainViolationentries, empty inside the range.
- evaluate(x)[source]¶
Return characteristic line evaluation at x.
- Parameters:
x (float) – Input value for linear interpolation.
- Returns:
y (float) – Evaluation of characteristic line at x.
Note
This methods checks for the value range first. If
extrapolateisFalse(default) and the x-value is outside of the specified range, the function will return the values at the corresponding boundary. IfextrapolateisTruethe y-value is calculated by linear extrapolation.\[y = y_0 + \frac{x-x_0}{x_1-x_0} \cdot \left(y_1-y_0 \right)\]where the index \(x_0\) represents the lower and \(x_1\) the upper adjacent x-value. \(y_0\) and \(y_1\) are the corresponding y-values. On extrapolation the two smallest or the two largest value pairs are used respectively.
- get_attr(key)[source]¶
Get the value of an attribute.
- Parameters:
key (str) – Object attribute to get value of.
- Returns:
value (object) – Value of object attribute key.
- get_domain_errors(x, c)[source]¶
Log a warning, if the x value is out of bounds.
- Parameters:
x (float) – Input value for linear interpolation.
c (str) – Label of the component the characteristic is applied on.
- num_inputs = 1¶
- class tespy.tools.characteristics.CharMap(x=array([0, 1]), y=array([[1., 1.], [1., 1.]]), z=array([[1., 1.], [1., 1.]]), extrapolate=False, x_unit=None, y_unit=None, z_unit=None)[source]¶
Bases:
objectClass for characteristic maps.
- Parameters:
x (ndarray, pint.Quantity) – An array for the first dimension input of the map.
y (ndarray, pint.Quantity) – A two-dimensional array of the second dimension input of the map.
z (ndarray, pint.Quantity) – A two-dimensional array of the output of the map.
x_unit, y_unit, z_unit (str) – Units of the x-, y- and z-values, default:
None. Quantity arrays carry their units.
Note
This class generates a lookup table from the given input data x, y and z, then performs linear interpolation. The output parameter is z to be calculated as functions from x and y.
- axes = ('x', 'y', 'z')¶
- domain_violations(x, y, rtol=1e-06)[source]¶
Check the inputs against the range of the map.
The first dimension is checked against the x-values, the second against the y-values interpolated at x; outside the x-values the y-values of the nearest boundary row apply.
- Parameters:
x (float) – Input for first dimension of CharMap.
y (float) – Input for second dimension of CharMap.
rtol (float) – Relative tolerance of the check.
- Returns:
list –
DomainViolationentries, empty inside the range.
- evaluate(x, y)[source]¶
Evaluate CharMap for x and y inputs.
- Parameters:
x (float) – Input for first dimension of CharMap.
y (float) – Input for second dimension of CharMap.
- Returns:
z (float) – Resulting z value.
Note
\[\begin{split}\vec{y} = \vec{y_0} + \frac{x-x_0}{x_1-x_0} \cdot \left(\vec{y_1}-\vec{y_0} \right)\\ \vec{z} = \vec{z1_0} + \frac{x-x_0}{x_1-x_0} \cdot \left(\vec{z_1}-\vec{z_0} \right)\end{split}\]The index
0represents the lower and1the upper adjacent x-value. Using the y-value as second input dimension the corresponding z-values are calculated, again using linear interpolation.\[z = z_0 + \frac{y-y_0}{y_1-y_0} \cdot \left(z_1-z_0 \right)\]
- evaluate_x(x)[source]¶
Evaluate CharMap for x inputs.
- Parameters:
x (float) – Input for first dimension of CharMap.
- Returns:
yarr (ndarray) – Second dimension input array of CharMap calculated from first dimension input.
zarr (ndarray) – Output array of CharMap calculated from first dimension input.
- evaluate_y(y, yarr, zarr)[source]¶
Evaluate CharMap for y inputs.
- Parameters:
y (float) – Input for second dimension of CharMap.
yarr (ndarray) – Second dimension array of CharMap calculated from first dimension input.
zarr (ndarray) – Output array of CharMap calculated from first dimension input.
- get_attr(key)[source]¶
Get the value of an attribute.
- Parameters:
key (str) – Object attribute to get value of.
- Returns:
value (object) – Value of object attribute key.
- get_domain_errors(x, y, c)[source]¶
Log warnings for bound violations of the CharMap.
- Parameters:
x (float) – Input for first dimension of CharMap.
y (float) – Input for second dimension of CharMap.
c (str) – Label of the component, the CharMap is applied on.
- get_domain_errors_x(x, c)[source]¶
Log a warning, if operation is out bounds in first dimension.
- Parameters:
x (float) – Input for first dimension of CharMap.
c (str) – Label of the component, the CharMap is applied on.
- Returns:
yarr (ndarray) – Second dimension input array of CharMap calculated from first dimension input.
- get_domain_errors_y(y, yarr, c)[source]¶
Log a warning, if operation is out bounds in second dimension.
- Parameters:
y (float) – Input for second dimension of CharMap.
yarr (ndarray) – Second dimension input array of CharMap calculated from first dimension input.
c (str) – Label of the component, the CharMap is applied on.
- input_bounds(index=0)[source]¶
Lower and upper bound of the data on the first (x) or second (y) input axis.
- num_inputs = 2¶
- class tespy.tools.characteristics.DomainViolation(axis: str, value: float, bound: float, side: str)[source]¶
Bases:
NamedTupleAn input of a characteristic outside the range of its data.
axisnames the input axis,valueis the input,boundthe violated bound of the data,sideis"above"or"below", all in the units of the data.- axis: str¶
Alias for field number 0
- bound: float¶
Alias for field number 2
- message(name, label, unit=None)[source]¶
Describe the violation of characteristic
nameat componentlabel.
- side: str¶
Alias for field number 3
- value: float¶
Alias for field number 1
- class tespy.tools.characteristics.EN12900Polynomial(coefficients, exponents=None, value_unit=None)[source]¶
Bases:
PolynomialClass for the 10-coefficient polynomial of EN 12900 in two inputs.
- Parameters:
coefficients (list) – The ten coefficients \(c_0\) to \(c_9\), a
pintquantity array carries the unit of the value.value_unit (str) – Unit of the polynomial value, e.g.
"kW", default:None. The inputs are °C as defined by the standard.
Note
With the evaporation temperature \(t_\text{e}\) and the condensation temperature \(t_\text{c}\) as inputs the polynomial reads
\[f = c_0 + c_1 t_\text{e} + c_2 t_\text{c} + c_3 t_\text{e}^2 + c_4 t_\text{e} t_\text{c} + c_5 t_\text{c}^2 + c_6 t_\text{e}^3 + c_7 t_\text{e}^2 t_\text{c} + c_8 t_\text{e} t_\text{c}^2 + c_9 t_\text{c}^3\]Example
>>> from tespy.tools.characteristics import EN12900Polynomial >>> poly = EN12900Polynomial([1, 2, 3, 0, 0, 0, 0, 0, 0, 0]) >>> poly.num_inputs 2 >>> poly.evaluate(1, 1) 6.0
- T_cond_unit = 'degC'¶
- T_evap_unit = 'degC'¶
- axes = ('T_evap', 'T_cond', 'value')¶
- exponents_EN12900 = [(0, 0), (1, 0), (0, 1), (2, 0), (1, 1), (0, 2), (3, 0), (2, 1), (1, 2), (0, 3)]¶
- num_inputs = 2¶
- class tespy.tools.characteristics.Polynomial(coefficients, exponents)[source]¶
Bases:
objectClass for polynomial characteristics in one or more inputs.
- Parameters:
coefficients (list) – Coefficients of the polynomial terms.
exponents (list) – One tuple of exponents per coefficient, one exponent per input.
Note
The polynomial is evaluated as
\[f\left(x_1, \ldots, x_n\right) = \sum_i c_i \prod_j x_j^{e_{ij}}\]A polynomial has no bounded domain, the domain check never warns. For the 10-coefficient form of EN 12900 see
EN12900Polynomial.Example
>>> from tespy.tools.characteristics import Polynomial >>> linear = Polynomial([1, 0.5], exponents=[(0,), (1,)]) >>> linear.num_inputs 1 >>> linear.evaluate(4) 3.0
- axes = None¶
- domain_violations(*inputs, rtol=1e-06)[source]¶
A polynomial has no range of its data, nothing is ever violated.
- evaluate(*inputs)[source]¶
Return the polynomial evaluation at the inputs.
- Parameters:
*inputs (float) – One value per input of the polynomial.
- Returns:
y (float) – Evaluation of the polynomial.
- property num_inputs¶
- tespy.tools.characteristics.characteristic_from_dict(data)[source]¶
Reconstruct a characteristic from its serialized form. Files written before the type was recorded are told apart by their keys.
- tespy.tools.characteristics.load_custom_char(name, char_type)[source]¶
Load a characteristic line of map.
- Parameters:
name (str) – Name of the characteristics.
char_type (class) – Class to be generate the object of.
- Returns:
obj (object) – The characteristics (CharLine, CharMap) object.
- tespy.tools.characteristics.load_default_char(component, parameter, function_name, char_type)[source]¶
Load a characteristic line of map.
- Parameters:
component (str) – Type of component.
parameter (str) – Component parameter using the characteristics.
function_name (str) – Name of the characteristics.
char_type (class) – Class to generate an instance of.
- Returns:
obj (object) – The characteristics (CharLine, CharMap) object.
tespy.tools.data_containers module¶
Module for data container classes.
The data containers hold the parameters of components and connections. Every container answers two independent questions: what kind of value it stores and whether it can put an equation into the system of equations.
ConnectionParameterandComponentParameterhold a scalar with a physical quantity. They can be system variables and can carry an equation.ArrayParameterholds an array with a physical quantity, as input or as result, and can carry an equation.ConfigParameterholds a typed configuration value without unit and without equation.OptionalEquationis an equation the user switches on,ParameterGroupone that activates when all of its element parameters are specified.CharacteristicDataholds a characteristic function with a physical quantity per axis,CharacteristicEquationadditionally activates an equation.MandatoryConstraintis an always active equation of a component.ReferenceEquationties a connection parameter to the parameter of another connection.FluidCompositionholds the mass fractions of a mixture.
This file is part of project TESPy (github.com/oemof/tespy). It’s copyrighted by the contributors recorded in the version control history of the file, available from its original location tespy/tools/data_containers.py
SPDX-License-Identifier: MIT
- class tespy.tools.data_containers.ArrayParameter(**kwargs)[source]¶
Bases:
_EquationMixin,DataContainerData container for array valued component parameters.
All entries of the array share one physical quantity. An array is an input when a declared consumer reads it, an equation of its own or a group listing it, otherwise it is a result filled by the component after convergence.
- Parameters:
val (numpy.ndarray) – Values in the unit of the parameter.
val_SI (numpy.ndarray) – Values in SI units.
quantity (str) – Physical quantity of the entries, e.g.
"heat".calc (callable) – Method calculating the SI values after convergence.
calc_params (dict) – Keyword arguments for
calc.calc_deps (list) – Names of parameters
calcdepends on, evaluated first.description (str) – Description of the parameter for documentation and schema.
- accept(value)[source]¶
Interpret a user-supplied value and update this container’s state.
Each subclass implements this to encapsulate the validation and assignment logic of
Component.set_attrandConnection.set_attr.- Parameters:
value – The value supplied by the user (numeric, string, dict, None, …).
- static attr()[source]¶
Return the available attributes for a DataContainer type object.
- Returns:
out (dict) – Dictionary of available attributes (dictionary keys) with default values.
- property result_only¶
Can the user not specify this parameter?
- class tespy.tools.data_containers.CharacteristicData(**kwargs)[source]¶
Bases:
DataContainerData container for a characteristic function.
The container holds a characteristic function object, e.g. a
tespy.tools.characteristics.CharLine,tespy.tools.characteristics.CharMaportespy.tools.characteristics.Polynomial, and knows the physical quantity of every axis. Equations evaluate the characteristic throughevaluate()with SI inputs and receive SI outputs, the conversion to the units of the characteristic data is handled here. The unit of an axis is the one the characteristic function carries, e.g.CharLine(x, y, x_unit="m3/h", y_unit="bar")or the °C of antespy.tools.characteristics.EN12900Polynomial, otherwise the default unit of the network, like a plain number of a scalar parameter. The default characteristics shipped with tespy are SI data.A characteristic function matches the container when it is an instance of the declared
char_type. The type names its axes, e.g.("x", "y")for aCharLineand("x", "y", "z")for aCharMap, the last axis is the output. Quantities are declared by these names and the units of the data are read by them, e.g.x_unit.- Parameters:
char_func (CharLine, CharMap, Polynomial) – The characteristic function, default:
None.char_type (type, tuple) – Accepted class or classes of the characteristic function, default:
tespy.tools.characteristics.CharLine.quantities (dict) – Physical quantity per axis name, e.g.
{"x": "volumetric_flow", "y": "pressure_difference"}. Axes without entry are dimensionless, default:{}.param (str) – Connection parameter used as first input, e.g.
"m", default:None.char_params (dict) – Evaluation of the first input:
typeis"rel"for the ratio to the design point and"abs"for the absolute value,inconnandoutconnselect the connections.is_set (boolean) – Has the characteristic been specified? default:
False. Providing a characteristic function sets it.description (str) – Description of the parameter for documentation and schema.
- accept(value)[source]¶
Interpret a user-supplied value and update this container’s state.
Each subclass implements this to encapsulate the validation and assignment logic of
Component.set_attrandConnection.set_attr.- Parameters:
value – The value supplied by the user (numeric, string, dict, None, …).
- static attr()[source]¶
Return the available attributes for a DataContainer type object.
- Returns:
out (dict) – Dictionary of available attributes (dictionary keys) with default values.
- property axes¶
Axis names of the characteristic type, the declared quantities name them for a type without fixed axes, the last axis is the output.
- domain_violations(*inputs)[source]¶
Violations of the range of the data at SI inputs, as
tespy.tools.characteristics.DomainViolationentries with values in the units of the data.
- evaluate_x(x)[source]¶
First step of a two step map evaluation at SI input, returns the second axis and the output arrays in SI units.
- evaluate_y(y, yarr, zarr)[source]¶
Second step of a two step map evaluation with SI arrays from
evaluate_x(), returns the SI output.
- property extrapolate¶
Does the characteristic extrapolate outside the range of its data? Characteristics without the option evaluate at the boundary.
- input_bounds(index=0)[source]¶
Lower and upper bound of the data on an input axis in SI units,
Noneif the characteristic has no bounded data.
- property num_inputs¶
- set_attr(**kwargs)[source]¶
Sets, resets or unsets attributes of a DataContainer type object.
- Parameters:
**kwargs – See the class documentation of desired DataContainer for available keywords.
- set_default(char_func)[source]¶
Assign a default characteristic shipped with tespy, its data are SI regardless of the network’s default units.
- property val¶
- class tespy.tools.data_containers.CharacteristicEquation(**kwargs)[source]¶
Bases:
_EquationMixin,CharacteristicDataData container for a characteristic function that activates an equation.
Takes the parameters of
CharacteristicData.is_setactivates the equation, therefore providing a characteristic function does not change it: a custom characteristic can be supplied for the offdesign calculation while the equation stays inactive in design mode.- accept(value)[source]¶
Interpret a user-supplied value and update this container’s state.
Each subclass implements this to encapsulate the validation and assignment logic of
Component.set_attrandConnection.set_attr.- Parameters:
value – The value supplied by the user (numeric, string, dict, None, …).
- class tespy.tools.data_containers.ComponentArrayProperties(**kwargs)¶
Bases:
ArrayParameterDeprecated, use
ArrayParameterinstead.
- class tespy.tools.data_containers.ComponentCharacteristicMaps(**kwargs)¶
Bases:
CharacteristicEquationDeprecated, use
CharacteristicEquationinstead.
- class tespy.tools.data_containers.ComponentCharacteristics(**kwargs)¶
Bases:
CharacteristicEquationDeprecated, use
CharacteristicEquationinstead.
- class tespy.tools.data_containers.ComponentMandatoryConstraints(**kwargs)¶
Bases:
MandatoryConstraintDeprecated, use
MandatoryConstraintinstead.
- class tespy.tools.data_containers.ComponentParameter(**kwargs)[source]¶
Bases:
ScalarParameterData container for scalar component parameters.
Extends
ScalarParameterwith the specification as system variable through"var"and with bound scaling, the variable role counts as consumer of a specification.- Parameters:
is_var (boolean) – Is the parameter a system variable? default:
False.limit_scale (str) – Name of a parameter whose magnitude scales the bound tolerance.
- accept(value)[source]¶
Interpret a user-supplied value and update this container’s state.
Each subclass implements this to encapsulate the validation and assignment logic of
Component.set_attrandConnection.set_attr.- Parameters:
value – The value supplied by the user (numeric, string, dict, None, …).
- class tespy.tools.data_containers.ComponentProperties(**kwargs)¶
Bases:
ComponentParameterDeprecated, use
ComponentParameterinstead.
- class tespy.tools.data_containers.ConfigParameter(**kwargs)[source]¶
Bases:
DataContainerData container for configuration values.
A configuration value has no physical unit and no equation, e.g. the number of outlets of a splitter or the flow arrangement of a heat exchanger.
- Parameters:
val (int, float, bool, str, dict, list) – The value, default:
np.nan.dtype (str) – Expected type of the value:
"int","float","bool","str","dict"or"list". Default:None, any type is accepted.options (list) – Values the parameter can take, e.g. the materials of a pipe wall. Default:
None, any value ofdtypeis accepted.is_set (boolean) – Has the value been set? default:
False.
Example
>>> from tespy.tools.data_containers import ConfigParameter >>> material = ConfigParameter(dtype="str", options=["Steel", "PVC"]) >>> material.accept("PVC") >>> material.val 'PVC' >>> material.accept("Wood") Traceback (most recent call last): ... ValueError: The value 'Wood' is not available, select from 'Steel', 'PVC'.
- descriptionstr
Description of the parameter for documentation and schema.
- accept(value)[source]¶
Interpret a user-supplied value and update this container’s state.
Each subclass implements this to encapsulate the validation and assignment logic of
Component.set_attrandConnection.set_attr.- Parameters:
value – The value supplied by the user (numeric, string, dict, None, …).
- static attr()[source]¶
Return the available attributes for a DataContainer type object.
- Returns:
out (dict) – Dictionary of available attributes (dictionary keys) with default values.
- set_attr(**kwargs)[source]¶
Sets, resets or unsets attributes of a DataContainer type object.
- Parameters:
**kwargs – See the class documentation of desired DataContainer for available keywords.
- property val¶
- class tespy.tools.data_containers.ConnectionParameter(**kwargs)[source]¶
Bases:
ScalarParameterData container for scalar connection parameters.
Takes the parameters of
ScalarParameter.Takes the parameters of
ScalarParameter, a reference to another connection counts as consumer as well.- Parameters:
reference (ReferenceEquation) – The equation applied when the parameter is specified as reference to the same parameter of another connection, default:
None, the parameter cannot be referenced.
- accept(value)[source]¶
Interpret a user-supplied value and update this container’s state.
Each subclass implements this to encapsulate the validation and assignment logic of
Component.set_attrandConnection.set_attr.- Parameters:
value – The value supplied by the user (numeric, string, dict, None, …).
- class tespy.tools.data_containers.DataContainer(**kwargs)[source]¶
Bases:
objectThe DataContainer is parent class for all data containers.
- Parameters:
**kwargs – See the class documentation of desired DataContainer for available keywords.
Note
The initialisation method (
__init__), setter method (set_attr) and getter method (get_attr) are used for instances of class DataContainer and its children. TESPy uses differentDataContainerclasses for specific objectives:scalar connection parameters
tespy.tools.data_containers.ConnectionParameterscalar component parameters
tespy.tools.data_containers.ComponentParameterarray valued component parameters
tespy.tools.data_containers.ArrayParameterconfiguration values
tespy.tools.data_containers.ConfigParameterequations switched on by the user
tespy.tools.data_containers.OptionalEquationparameter groups
tespy.tools.data_containers.ParameterGroupcharacteristic functions as data
tespy.tools.data_containers.CharacteristicDatacharacteristic functions with an equation
tespy.tools.data_containers.CharacteristicEquationmandatory equations of components
tespy.tools.data_containers.MandatoryConstraintreferences between connections
tespy.tools.data_containers.ReferenceEquationfluid composition
tespy.tools.data_containers.FluidComposition
A
ParameterGroupis used when more than one component parameter has to be specified in order to apply one equation, e.g. pressure drop in pipes by specified length, diameter and roughness. If you specify all three of these parameters, the group is activated automatically.For the full list of available parameters for each data container, see its documentation.
Example
The examples below show the different (sub-)classes of DataContainers available.
>>> from tespy.tools.data_containers import ( ... CharacteristicData, CharacteristicEquation, ComponentParameter, ... ConfigParameter, ConnectionParameter, FluidComposition, ... ParameterGroup) >>> type(CharacteristicData()) <class 'tespy.tools.data_containers.CharacteristicData'> >>> type(CharacteristicEquation(is_set=True, param='m')) <class 'tespy.tools.data_containers.CharacteristicEquation'> >>> type(ComponentParameter( ... val=100, is_set=True, is_var=True, max_val=1000, min_val=1 ... )) <class 'tespy.tools.data_containers.ComponentParameter'> >>> type(ParameterGroup(is_set=True, elements=["L", "D", "ks"])) <class 'tespy.tools.data_containers.ParameterGroup'> >>> type(FluidComposition( ... _val={'CO2': 0.1, 'H2O': 0.11, 'N2': 0.75, 'O2': 0.03}, _is_set={'O2'} ... )) <class 'tespy.tools.data_containers.FluidComposition'> >>> type(ConnectionParameter( ... val=5, val_SI=500000, is_set=True, quantity="pressure" ... )) <class 'tespy.tools.data_containers.ConnectionParameter'> >>> type(ConfigParameter(val=5, dtype="int", is_set=False)) <class 'tespy.tools.data_containers.ConfigParameter'>
- accept(value)[source]¶
Interpret a user-supplied value and update this container’s state.
Each subclass implements this to encapsulate the validation and assignment logic of
Component.set_attrandConnection.set_attr.- Parameters:
value – The value supplied by the user (numeric, string, dict, None, …).
- static attr()[source]¶
Return the available attributes for a DataContainer type object.
- Returns:
out (dict) – Dictionary of available attributes (dictionary keys) with default values.
- func = None¶
- get_attr(key)[source]¶
Get the value of a DataContainer’s attribute.
- Parameters:
key (str) – The attribute you want to retrieve.
- Returns:
out – Specified attribute.
- property result_only¶
Can the user not specify this parameter?
- set_attr(**kwargs)[source]¶
Sets, resets or unsets attributes of a DataContainer type object.
- Parameters:
**kwargs – See the class documentation of desired DataContainer for available keywords.
- structure_matrix = None¶
- class tespy.tools.data_containers.FluidComposition(**kwargs)[source]¶
Bases:
DataContainerData container for fluid composition.
- Parameters:
val (dict) – Mass fractions of the fluids in a mixture, default: val={}. Pattern for dictionary: keys are fluid name, values are mass fractions.
val0 (dict) – Starting values for mass fractions of the fluids in a mixture, default: val0={}. Pattern for dictionary: keys are fluid name, values are mass fractions.
is_set (set) – Which fluid mass fractions have been set, default is_set=set().
- property J_col¶
- static attr()[source]¶
Return the available attributes for a DataContainer type object.
- Returns:
out (dict) – Dictionary of available attributes (dictionary keys) with default values.
- property is_set¶
- property is_var¶
- property val¶
- class tespy.tools.data_containers.FluidProperties(**kwargs)¶
Bases:
ConnectionParameterDeprecated, use
ConnectionParameterinstead.
- class tespy.tools.data_containers.GroupedComponentCharacteristics(**kwargs)¶
Bases:
OptionalEquationDeprecated, use
OptionalEquationinstead.
- class tespy.tools.data_containers.GroupedComponentProperties(**kwargs)¶
Bases:
ParameterGroupDeprecated, use
ParameterGroupinstead.
- class tespy.tools.data_containers.MandatoryConstraint(**kwargs)[source]¶
Bases:
_EquationMixin,DataContainerData container for the mandatory equations of a component.
Mandatory constraints are always active and never specified by the user.
- Parameters:
elements (list) – Names of the parameters the equation reads, default:
[].description (str) – Description of the equation for documentation and schema.
- class tespy.tools.data_containers.OptionalEquation(**kwargs)[source]¶
Bases:
_EquationMixin,DataContainerData container for an equation the user switches on and off.
The equation is applied when
is_setisTrue, e.g. aftercomponent.set_attr(cone=True)or through the offdesign parameter list.elementsname the parameters the equation reads, they do not activate it.- Parameters:
is_set (boolean) – Should the equation be applied? default:
False.elements (list) – Names of the parameters the equation reads, default:
[].description (str) – Description of the equation for documentation and schema.
- accept(value)[source]¶
Interpret a user-supplied value and update this container’s state.
Each subclass implements this to encapsulate the validation and assignment logic of
Component.set_attrandConnection.set_attr.- Parameters:
value – The value supplied by the user (numeric, string, dict, None, …).
- static attr()[source]¶
Return the available attributes for a DataContainer type object.
- Returns:
out (dict) – Dictionary of available attributes (dictionary keys) with default values.
- property val¶
- class tespy.tools.data_containers.OptionalResult(**kwargs)[source]¶
Bases:
ScalarParameterData container for a scalar result that is calculated on request only.
The value has a physical quantity and units like any other scalar parameter, e.g. the exergy of a connection after an evaluation with an ambient state. It is never specified by the user and not part of the equation system, it is reported in the results once it has been calculated.
Takes the parameters of
ScalarParameter.- accept(value)[source]¶
Interpret a user-supplied value and update this container’s state.
Each subclass implements this to encapsulate the validation and assignment logic of
Component.set_attrandConnection.set_attr.- Parameters:
value – The value supplied by the user (numeric, string, dict, None, …).
- property is_calculated¶
- class tespy.tools.data_containers.ParameterGroup(**kwargs)[source]¶
Bases:
OptionalEquationData container for a group of parameters that jointly activate one equation.
The group is active when all of its
elementsare specified, e.g. the pressure drop of a pipe from length, diameter and roughness. The equation can read furtheroptional_elements, which have a default or an alternative and do not take part in the activation, e.g. the wall material of a pipe or a wall conductivity overriding it.- Parameters:
is_set (boolean) – Is the equation of this group applied? Derived from the elements in the preprocessing, default:
False.elements (list) – Names of the parameters that belong to this group, default:
[].optional_elements (list) – Names of the parameters the equation reads without requiring them, default:
[].description (str) – Description of the equation for documentation and schema.
- accept(value)[source]¶
Interpret a user-supplied value and update this container’s state.
Each subclass implements this to encapsulate the validation and assignment logic of
Component.set_attrandConnection.set_attr.- Parameters:
value – The value supplied by the user (numeric, string, dict, None, …).
- class tespy.tools.data_containers.ReferenceEquation(**kwargs)[source]¶
Bases:
_EquationMixin,DataContainerData container for a reference of a connection parameter to the same parameter of another connection.
- Parameters:
ref (tespy.connections.connection.Ref) – The reference object with target connection, factor and delta.
is_set (boolean) – Should the equation be applied? default:
False.quantity (str) – Physical quantity of
delta.
- accept(value)[source]¶
Interpret a user-supplied value and update this container’s state.
Each subclass implements this to encapsulate the validation and assignment logic of
Component.set_attrandConnection.set_attr.- Parameters:
value – The value supplied by the user (numeric, string, dict, None, …).
- class tespy.tools.data_containers.ReferencedFluidProperties(**kwargs)¶
Bases:
ReferenceEquationDeprecated, use
ReferenceEquationinstead.
- class tespy.tools.data_containers.ScalarParameter(**kwargs)[source]¶
Bases:
_EquationMixin,DataContainerBase class for scalar parameters with a physical quantity.
The value is stored in the unit of the parameter (
val) and in SI units (val_SI). A parameter can be a system variable of the solver and can carry an equation. The solver groups variables with an affine relation and lets all of them read their value through a shared reference container.- Parameters:
val (float, pint.Quantity) – Value in the unit of the parameter. A plain number takes the default unit of the network for the quantity, a
pint.Quantitypins its own unit, default:np.nan.val_SI (float) – Value in SI units, default:
np.nan.unit (str) – Unit of
val, default:None(network default).is_set (boolean) – Has the value been specified? default:
False.quantity (str) – Physical quantity of the parameter, e.g.
"pressure".min_val, max_val (float) – Bounds of the value when it is a system variable, default:
-1e12and1e12.d (float) – Increment for numerical derivatives, default:
1e-4.val0 (float, pint.Quantity) – Starting value for the solver in the unit of the parameter, default:
np.nan.calc (callable) – Method calculating the SI value after convergence. A parameter with a
calcmethod is reported in the results in every case.calc_params (dict) – Keyword arguments for
calc.calc_deps (list) – Names of parameters
calcdepends on, evaluated first.description (str) – Description of the parameter for documentation and schema.
Note
A parameter accepts a specification when a declared consumer reads it: an equation of its own, a group, optional equation or mandatory constraint listing it in its
elements, the variable role or the presolving of a connection. The owner marks the containers its declarations consume at construction. A parameter without consumer is result-only.- property J_col¶
- accept(value)[source]¶
Interpret a user-supplied value and update this container’s state.
Each subclass implements this to encapsulate the validation and assignment logic of
Component.set_attrandConnection.set_attr.- Parameters:
value – The value supplied by the user (numeric, string, dict, None, …).
- static attr()[source]¶
Return the available attributes for a DataContainer type object.
- Returns:
out (dict) – Dictionary of available attributes (dictionary keys) with default values.
- get_reference_val_SI()[source]¶
Get value of the reference corresponding to own value
- Returns:
float – Value of reference container corresponding to this data container’s value.
- property is_var¶
- property result_only¶
Can the user not specify this parameter?
- property unit¶
- property val¶
- property val0¶
- property val0_unit¶
- property val0_with_unit¶
- property val_SI¶
- property val_with_unit¶
- class tespy.tools.data_containers.ScalarVariable(**kwargs)[source]¶
Bases:
DataContainerReference container of a group of affinely related scalar variables.
- property J_col¶
- static attr()[source]¶
Return the available attributes for a DataContainer type object.
- Returns:
out (dict) – Dictionary of available attributes (dictionary keys) with default values.
- property d¶
- property is_var¶
- property val_SI¶
- class tespy.tools.data_containers.SimpleDataContainer(**kwargs)¶
Bases:
ConfigParameterDeprecated, use
ConfigParameterinstead.
- class tespy.tools.data_containers.VectorVariable(**kwargs)[source]¶
Bases:
DataContainerReference container of a group of affinely related fluid compositions.
- property J_col¶
- static attr()[source]¶
Return the available attributes for a DataContainer type object.
- Returns:
out (dict) – Dictionary of available attributes (dictionary keys) with default values.
- property d¶
- property is_var¶
- property val¶
tespy.tools.global_vars module¶
Module for global variables used by other modules of the tespy package.
This file is part of project TESPy (github.com/oemof/tespy). It’s copyrighted by the contributors recorded in the version control history of the file, available from its original location tespy/tools/global_vars.py
SPDX-License-Identifier: MIT
- class tespy.tools.global_vars.CombustionGases[source]¶
Bases:
object- add_fluid(fluid, hf=None, LHV=None)[source]¶
Add a new fluid to the possible combustion gases.
- Parameters:
fluid (str) – name of the fluid. Must be a valid fluid within the fluid property backend.
hf (float) – specific enthalpy of formation at standard conditions in kJ/mol
LHV (float) – lower heating value of the fuel in J/kg
tespy.tools.helpers module¶
Module for helper functions used by several other modules.
This file is part of project TESPy (github.com/oemof/tespy). It’s copyrighted by the contributors recorded in the version control history of the file, available from its original location tespy/tools/helpers.py
SPDX-License-Identifier: MIT
- exception tespy.tools.helpers.TESPyComponentError[source]¶
Bases:
ExceptionCustom message for component related errors.
- exception tespy.tools.helpers.TESPyConnectionError[source]¶
Bases:
ExceptionCustom message for connection related errors.
- exception tespy.tools.helpers.TESPyNetworkError[source]¶
Bases:
ExceptionCustom message for network related errors.
- class tespy.tools.helpers.UserDefinedEquation(label: str, func: callable, dependents: callable, deriv: callable = None, conns: list = None, comps: list = None, params: dict = None, infer_composition: bool = True)[source]¶
Bases:
object- property is_set¶
- class tespy.tools.helpers.UserDefinedVariable(label: str, val0: float, min_val: float = None, max_val: float = None, d: float = 0.0001)[source]¶
Bases:
objectA UserDefinedVariable adds a standalone variable to the solver.
The variable is not attached to any connection or component. It is referenced from the function and dependents of a
UserDefinedEquation, which closes the degree of freedom the variable adds - a typical use case is solving for an unknown parameter of a user specified relation instead of specifying it.- Parameters:
label (str) – Label of the variable, must be unique within a network.
val0 (float) – Starting value in SI units.
min_val (float, optional) – Lower limit for the value during solving.
max_val (float, optional) – Upper limit for the value during solving.
d (float, optional) – Step size for the numeric derivatives, by default 1e-4.
Note
The value is accessed in SI units through
val_SI, e.g. from within the function of aUserDefinedEquation. The dependents of the equation reference the underlying container through thevariableattribute. Withset_attr(is_var=False)the variable turns into a plain constant read by the equation, removing it from the variable space of the solver.- property is_var¶
- property val_SI¶
- tespy.tools.helpers.central_difference(function=None, parameter=None, delta=None, **kwargs)[source]¶
- tespy.tools.helpers.extend_basic_path(subfolder)[source]¶
Return a path based on the basic tespy path and creates it if necessary.
The subfolder is the name of the path extension.
- tespy.tools.helpers.get_basic_path()[source]¶
Return the basic tespy path and creates it if necessary.
The basic path is the ‘.tespy’ folder in the $HOME directory.
- tespy.tools.helpers.get_variable_value(data)[source]¶
Current value of a variable entry of
Problem.variables_dict.
- tespy.tools.helpers.merge_dicts(dict1, dict2)[source]¶
Return a new dictionary by merging two dictionaries recursively.
- tespy.tools.helpers.newton_with_kwargs(derivative, target_value, val0=300, valmin=70, valmax=3000, max_iter=10, tol_rel=1e-06, tol_abs=0.001, tol_mode='rel', **function_kwargs)[source]¶
- tespy.tools.helpers.seeded_random(seed_value: str | bytes | int) float[source]¶
Generate a reproducible random number between 0 and 1 based on a seed value.
- tespy.tools.helpers.seeded_random_generator(seed_value: str | bytes | int) Generator[source]¶
Generate a reproducible random number generator based on a seed value.
- tespy.tools.helpers.set_variable_value(data, value)[source]¶
Set the value of a variable entry of
Problem.variables_dict.
- tespy.tools.helpers.solve(obj, increment_filter, composition_derivatives=False)[source]¶
Solve equations and calculate partial derivatives of a component.
- Parameters:
increment_filter (ndarray) – Matrix for filtering non-changing variables.
composition_derivatives (bool) – Calculate the derivatives to the mass fractions the dependence was inferred for in addition to the declared ones.
tespy.tools.logger module¶
Module for logging specification.
This file is part of project TESPy (github.com/oemof/tespy). It’s copyrighted by the contributors recorded in the version control history of the file, available from its original location tespy/tools/logger.py
SPDX-License-Identifier: MIT
- tespy.tools.logger.add_console_logging(logformat=None, logdatefmt='%H:%M:%S', loglevel=20, log_the_version=True)[source]¶
Initialise customizable console logger.
- Parameters:
logformat (str) – Format of the screen output. Default: “%(asctime)s-%(levelname)s-%(message)s”
logdatefmt (str) – Format of the datetime in the screen output. Default: “%H:%M:%S”
loglevel (int) – Level of logging to stdout. Default: 20 (logging.INFO)
log_the_version (boolean) – If True, version information is logged while initialising the logger.
- tespy.tools.logger.add_file_logging(logpath=None, logfile=None, logrotation=None, logformat=None, logdatefmt=None, loglevel=10, log_the_version=True, log_the_path=True)[source]¶
Initialise customisable file logger.
- Parameters:
logpath (str) – The path for log files. By default a “.tespy’ folder is created in your home directory with subfolder called ‘log_files’.
logfile (str) – Name of the log file, default: tespy.log
logrotation (dict) – Option to pass parameters to the TimedRotatingFileHandler.
logformat (str) – Format of the file output. Default: “%(asctime)s - %(levelname)s - %(module)s - %(message)s”
logdatefmt (str) – Format of the datetime in the file output. Default: None
loglevel (int) – Level of logging to file. Default: 10 (logging.DEBUG)
log_the_version (boolean) – If True, version information is logged while initialising the logger.
log_the_path (boolean) – If True, the used file path is logged while initialising the logger.
- Returns:
file (str) – Place where the log file is stored.
- tespy.tools.logger.check_git_branch()[source]¶
Return the git commit of the installed tespy, if it can be determined.
The commit is taken from the installation metadata for installations from a git repository, e.g.
pip install git+https://.... For editable installations it is read from the.gitfolder of the repository.- Returns:
str, None – Commit hash or
Nonefor regular installations, e.g. from PyPI.
Example
>>> from tespy.tools import logger >>> v = logger.check_git_branch() >>> v is None or isinstance(v, str) True
- tespy.tools.logger.check_version()[source]¶
Return the actual version number of the used TESPy version.
Example
>>> from tespy.tools import logger >>> v = logger.check_version() >>> int(v.split('.')[0]) 0
- tespy.tools.logger.console_logging_enabled(level=21)[source]¶
Check whether a console handler emits messages of the given level.
Used to avoid double console output where messages are both printed and logged.
- Returns:
boolean – True in case a stream handler writing to stdout or stderr is attached to the logger with a level at or below the given level.
- tespy.tools.logger.critical(msg, *args, **kwargs)[source]¶
Log ‘msg % args’ with severity ‘CRITICAL’.
To pass exception information, use the keyword argument exc_info with a true value, e.g.
critical(“Houston, we have a %s”, “major disaster”, exc_info=1)
- tespy.tools.logger.debug(msg, *args, **kwargs)[source]¶
Log ‘msg % args’ with severity ‘DEBUG’.
To pass exception information, use the keyword argument exc_info with a true value, e.g.
debug(“Houston, we have a %s”, “thorny problem”, exc_info=1)
- tespy.tools.logger.define_logging(logpath=None, logfile='tespy.log', file_format=None, screen_format=None, file_datefmt=None, screen_datefmt=None, screen_level=20, file_level=10, log_the_version=True, log_the_path=True, timed_rotating=None)[source]¶
Initialise customisable logger.
- Parameters:
logpath (str) – The path for log files. By default a “.tespy’ folder is created in your home directory with subfolder called ‘log_files’.
logfile (str) – Name of the log file, default: tespy.log
file_format (str) – Format of the file output. Default: “%(asctime)s - %(levelname)s - %(module)s - %(message)s”
screen_format (str) – Format of the screen output. Default: “%(asctime)s-%(levelname)s-%(message)s”
file_datefmt (str) – Format of the datetime in the file output. Default: None
screen_datefmt (str) – Format of the datetime in the screen output. Default: “%H:%M:%S”
screen_level (int) – Level of logging to stdout. Default: 20 (logging.INFO)
file_level (int) – Level of logging to file. Default: 10 (logging.DEBUG)
log_the_version (boolean) – If True the actual version or commit is logged while initialising the logger.
log_the_path (boolean) – If True the used file path is logged while initialising the logger.
timed_rotating (dict) – Option to pass parameters to the TimedRotatingFileHandler.
- Returns:
file (str) – Place where the log file is stored.
Notes
By default the INFO level is printed on the screen and the DEBUG level in a file, but you can easily configure the logger. Every module that wants to create logging messages has to import the logger.
Examples
To define the default logger you have to import the python logging library and this function. The first logging message should be the path where the log file is saved to.
>>> import logging >>> from tespy.tools import logger >>> mypath = logger.define_logging( ... log_the_path=True, log_the_version=True, timed_rotating={'backupCount': 4}, ... screen_level=logging.ERROR, screen_datefmt = "no_date" ... ) >>> mypath[-9:] 'tespy.log' >>> logger.debug('Hi')
- tespy.tools.logger.error(msg, *args, **kwargs)[source]¶
Log ‘msg % args’ with severity ‘ERROR’.
To pass exception information, use the keyword argument exc_info with a true value, e.g.
error(“Houston, we have a %s”, “major problem”, exc_info=1)
- tespy.tools.logger.exception(msg, *args, exc_info=True, **kwargs)[source]¶
Convenience method for logging an ERROR with exception information.
- tespy.tools.logger.get_version()[source]¶
Return a string part of the used version.
If the git commit is available it is returned, otherwise the version number.
Example
>>> from tespy.tools import logger >>> v = logger.get_version() >>> type(v) <class 'str'>
- tespy.tools.logger.increment_stacklevel(kwargs)[source]¶
“Method to force the logging framework to trace past this file
- tespy.tools.logger.info(msg, *args, **kwargs)[source]¶
Log ‘msg % args’ with severity ‘INFO’.
To pass exception information, use the keyword argument exc_info with a true value, e.g.
info(“Houston, we have a %s”, “interesting problem”, exc_info=1)
- tespy.tools.logger.log(level, msg, *args, **kwargs)[source]¶
Log ‘msg % args’ with the integer severity ‘level’.
To pass exception information, use the keyword argument exc_info with a true value, e.g.
log(level, “We have a %s”, “mysterious problem”, exc_info=1)
- tespy.tools.logger.progress(value, msg, *args, **kwargs)[source]¶
Report progress values between 0 and 100, you can also use the extra dict to modify the progress limits. Additionally, log ‘msg % args’ with severity ‘TESPY_PROGRESS_LOG_LEVEL’.
progress(51, “Houston, we have completed step %d of 100.”, 51) progress(0.51, “Houston, we have completed %f percent of the mission.”, 0.51*100, extra=dict(progress_min=0.0, progress_max=1.0))
tespy.tools.optimization module¶
Module for OptimizationProblem class.
This file is part of project TESPy (github.com/oemof/tespy). It’s copyrighted by the contributors recorded in the version control history of the file, available from its original location tespy/tools/optimization.py
SPDX-License-Identifier: MIT
- class tespy.tools.optimization.OptimizationProblem(model, variables=None, constraints=None, objective=None, minimize=None, kpi=None, penalty_instead_of_constraints=False)[source]¶
Bases:
ElementwiseProblemThe OptimizationProblem handles the optimization.
- Parameters:
model (tespy.models.ModelTemplate) – Model instance providing
set_parameters,get_parameter,get_objectivesandsolve_model.variables (dict) – Flat dictionary of decision variables and their bounds, e.g.
{ "extraction pressure 1": {"min": 1, "max": 40}, "extraction pressure 2": {"min": 1, "max": 40}, }
constraints (dict) – Flat dictionary of parameter constraints. Values are numeric bounds or a parameter name string for cross-parameter references, e.g.
{ "extraction pressure 1": {"min": "extraction pressure 2"}, "some temperature": {"min": 20, "max": 200}, }
objective (list) – Names of the objective parameters as defined in the model’s
_parameter_lookup.minimize (list) –
Trueto minimize,Falseto maximize. One entry per objective, in the same order.kpi (list) – Parameter names to log at each evaluation in addition to the objectives, e.g.
["hpt power", "hpt pressure ratio"].penalty_instead_of_constraints (bool) – If
True, constraints are passed tomodel.penalizeinstead of being enforced directly. DefaultFalse.
Example
For an example please check out this section in the docs.
tespy.tools.plotting module¶
Module for cycle plotting data extraction.
This file is part of project TESPy (github.com/oemof/tespy). It’s copyrighted by the contributors recorded in the version control history of the file, available from its original location tespy/tools/plotting.py
SPDX-License-Identifier: MIT
- tespy.tools.plotting.get_heatexchanger_secondary_Ts(nw, connection_label)[source]¶
Get the fake process lines and points to visualize heat exchange to secondary fluids of a cycle.
Temperature values are taken from the secondary side and they are matched to the entropy values of the primary side (the branch the connection label) was specified for.
- Parameters:
nw (tespy.networks.network.Network) – Network object.
connection_label (str) – Label of any connection in the desired part of the network.
- Returns:
tuple – Tuple with dictionary of process line data of the secondary sides of heat exchangers and process points dictionary with the state information to plot the secondary sides in a Ts diagram
- tespy.tools.plotting.get_plotting_data(nw, connection_label)[source]¶
Retrieve the process information and all state points of the fluid in a given part of the network identified by a connection label.
- Parameters:
nw (tespy.networks.network.Network) – Network object.
connection_label (str) – Label of any connection in the desired part of the network.
- Returns:
tuple – Tuple with dictionary of process line data that are passed to the
calc_individual_isolinemethod offluprodiaand process points dictionary with the state information.
tespy.tools.schema module¶
Utility for generating a JSON schema description of TESPy components and connections, listing each parameter with its data-container type, physical quantity and description.
- tespy.tools.schema.generate_component_schema(exclude_base_classes=('Component',), as_json=True, indent=2)[source]¶
Return a serialized description of all registered TESPy component classes.
For every class in the component registry (except those listed in exclude_base_classes) the function collects every parameter returned by
get_parameters()and records:the parameter name
the data-container type (e.g.
ComponentParameter,CharacteristicEquation)the physical quantity (e.g.
"pressure","efficiency") when availablethe human-readable description
- Parameters:
exclude_base_classes (tuple[str], optional) – Names of registry entries to skip. Defaults to
("Component",).as_json (bool, optional) – When True (default) return a JSON string; when False return the raw nested dict.
indent (int, optional) – JSON indentation level (only used when as_json is True).
- Returns:
str | dict – JSON string or dict depending on as_json.
- tespy.tools.schema.generate_connection_schema(exclude_base_classes=(), as_json=True, indent=2)[source]¶
Return a serialized description of all registered TESPy connection classes.
- Parameters:
exclude_base_classes (tuple[str], optional) – Names of registry entries to skip. Defaults to
("Connection", "PowerConnection").as_json (bool, optional) – When True (default) return a JSON string; when False return the raw nested dict.
indent (int, optional) – JSON indentation level (only used when as_json is True).
- Returns:
str | dict – JSON string or dict depending on as_json.
tespy.tools.units module¶
Module for Units class.
This file is part of project TESPy (github.com/oemof/tespy). It’s copyrighted by the contributors recorded in the version control history of the file, available from its original location tespy/tools/units.py
SPDX-License-Identifier: MIT
- class tespy.tools.units.Units[source]¶
Bases:
object- canonical(unit)[source]¶
Return the canonical name of a unit string, e.g. degC becomes degree_Celsius. The names are parsed once and then cached.
- convert(value, from_unit, to_unit)[source]¶
Convert a magnitude from one unit to another.
Unit conversions are affine, so factor and offset are computed once per unit pair and cached, bypassing the pint conversion machinery for every subsequent value. The cache is keyed by the unit strings, pint objects of any registry are accepted.
- parsed_unit(unit)[source]¶
Return the pint Unit for a unit string.
The units are parsed once and then cached.
- set_defaults(**kwargs)[source]¶
Set the default units
- Parameters:
temperature (str) – Default unit: “kelvin”
temperature_difference (str) – Default unit: “delta_degC”
enthalpy (str) – Default unit: “J/kg”
specific_energy (str) – Default unit: “J/kg”
entropy (str) – Default unit: “J/kg/K”
pressure (str) – Default unit: “Pa”. For backwards compatibility, setting this also sets
pressure_differenceto the same unit unlesspressure_differenceis explicitly provided as well.pressure_difference (str) – Default unit: “Pa”
mass_flow (str) – Default unit: “kg/s”
volumetric_flow (str) – Default unit: “m3/s”
specific_volume (str) – Default unit: “m3/kg”
volume (str) – Default unit: “m3”
power (str) – Default unit: “W”
heat (str) – Default unit: “W”
quality (str) – Default unit: “1”
efficiency (str) – Default unit: “1”
ratio (str) – Default unit: “1”
length (str) – Default unit: “m”
speed (str) – Default unit: “m/s”
area (str) – Default unit: “m2”
thermal_conductivity (str) – Default unit: “W/m/K”
heat_transfer_coefficient (str) – Default unit: “W/K”
heat_transfer_coefficient_per_area (str) – Default unit: “W/m**2/K”
thermal_resistance (str) – Default unit: “K/W”
- set_ureg(ureg)[source]¶
Replace default ureg with a custom one
- Parameters:
ureg (pint.UnitRegistry) – Change the pint.UnitRegistry to a custom one
- property ureg¶
- tespy.tools.units.is_compatible(quantity, unit)[source]¶
Check a unit string against the dimension of a quantity.
A parse only registry is created on first use: the check needs no network, e.g. for units read from a file. Units the registry does not know are not rejected, their conversion fails on the unit system of the network instead.