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)[source]¶
Bases:
objectClass for characteristc lines.
- Parameters:
x (ndarray) – An array for the x-values of the lookup table. Number of x and y values must be identical.
y (ndarray) – The corresponding y-values for the lookup table. Number of x and y values must be identical.
extrapolate (boolean) – If
Truelinear extrapolation is performed when the x value is out of the defined value range.
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].- 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.
- class tespy.tools.characteristics.CharMap(x=array([0, 1]), y=array([[1., 1.], [1., 1.]]), z=array([[1., 1.], [1., 1.]]), extrapolate=False)[source]¶
Bases:
objectClass for characteristic maps.
- Parameters:
x (ndarray) – An array for the first dimension input of the map.
y (ndarray) – A two-dimensional array of the second dimension input of the map.
z (ndarray) – A two-dimensional array of the output of the map.
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.
- 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]¶
Check the CharMap for bound violations.
- Parameters:
x (float) – Input for first dimension of CharMap.
y (float) – Input for second dimension of CharMap.
- get_domain_errors_x(x, c)[source]¶
Prompt error message, 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]¶
Prompt error message, 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.
- 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 DataContainer class and its subclasses are used to store component or connection properties.
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.ComponentCharacteristicMaps(**kwargs)[source]¶
Bases:
_NumEqMixin,DataContainerData container for characteristic maps.
- Parameters:
func (tespy.components.characteristics.characteristics) – Function to be applied for this characteristic map, default: None.
is_set (boolean) – Should this equation be applied?, default: is_set=False.
param (str) – Which parameter should be applied as the x value? default: method=’default’.
- 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 that formerly lived in Component.set_attr / Connection.set_attr.
- Parameters:
value – The value supplied by the user (numeric, string, dict, None, …).
- class tespy.tools.data_containers.ComponentCharacteristics(**kwargs)[source]¶
Bases:
_NumEqMixin,DataContainerData container for component characteristics.
- Parameters:
func (tespy.components.characteristics.characteristics) – Function to be applied for this characteristics, default: None.
is_set (boolean) – Should this equation be applied?, default: is_set=False.
param (str) – Which parameter should be applied as the x value? default: method=’default’.
- 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 that formerly lived in Component.set_attr / Connection.set_attr.
- Parameters:
value – The value supplied by the user (numeric, string, dict, None, …).
- class tespy.tools.data_containers.ComponentMandatoryConstraints(**kwargs)[source]¶
Bases:
_NumEqMixin,DataContainerData container for component mandatory constraints.
- class tespy.tools.data_containers.ComponentProperties(**kwargs)[source]¶
Bases:
FluidProperties- 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 that formerly lived in Component.set_attr / Connection.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:component characteristics
tespy.tools.data_containers.ComponentCharacteristicscomponent characteristic maps
tespy.tools.data_containers.ComponentCharacteristicMapscomponent properties
tespy.tools.data_containers.ComponentPropertiesgrouped component properties
tespy.tools.data_containers.GroupedComponentPropertiesfluid composition
tespy.tools.data_containers.FluidCompositionfluid properties
tespy.tools.data_containers.FluidProperties
Grouped component properties are used, if more than one component property 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 properties, the DataContainer for the group will be created 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 ( ... ComponentCharacteristics, ComponentCharacteristicMaps, ... ComponentProperties, FluidComposition, GroupedComponentProperties, ... FluidProperties, SimpleDataContainer) >>> from tespy.components import Pipe >>> type(ComponentCharacteristicMaps(is_set=True)) <class 'tespy.tools.data_containers.ComponentCharacteristicMaps'> >>> type(ComponentCharacteristics(is_set=True, param='m')) <class 'tespy.tools.data_containers.ComponentCharacteristics'> >>> type(ComponentProperties( ... val=100, is_set=True, is_var=True, max_val=1000, min_val=1 ... )) <class 'tespy.tools.data_containers.ComponentProperties'> >>> pi = Pipe('testpipe', L=100, D=0.5, ks=5e-5) >>> type(GroupedComponentProperties( ... is_set=True, elements=["L", "D", "ks"] ... )) <class 'tespy.tools.data_containers.GroupedComponentProperties'> >>> 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(FluidProperties( ... val=5, val_SI=500000, is_set=True, quantity="pressure" ... )) <class 'tespy.tools.data_containers.FluidProperties'> >>> type(SimpleDataContainer(val=5, is_set=False)) <class 'tespy.tools.data_containers.SimpleDataContainer'>
- 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 that formerly lived in Component.set_attr / Connection.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.
- 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 (dict) – Which fluid mass fractions have been set, default is_set={}. Pattern for dictionary: keys are fluid name, values are True or False.
balance (boolean) – Should the fluid balance equation be applied for this mixture? default: False.
- property J_col¶
- static attr()[source]¶
Return the available attributes for a FluidComposition 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)[source]¶
Bases:
_NumEqMixin,DataContainerData container for fluid properties.
- Parameters:
val (float) – Value in user specified unit (or network unit) if unit is unspecified, default: val=np.nan.
val0 (float) – Starting value in user specified unit (or network unit) if unit is unspecified, default: val0=np.nan.
val_SI (float) – Value in SI_unit, default: val_SI=0.
is_set (boolean) – Has the value for this property been set? default: is_set=False.
unit (str) – Unit for this property, default: ref=None.
unit (boolean) – Has the unit for this property been specified manually by the user? default: unit_set=False.
- 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 that formerly lived in Component.set_attr / Connection.set_attr.
- Parameters:
value – The value supplied by the user (numeric, string, dict, None, …).
- static attr()[source]¶
Return the available attributes for a FluidProperties 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 unit¶
- property val¶
- property val0¶
- property val_SI¶
- property val_with_unit¶
- class tespy.tools.data_containers.GroupedComponentCharacteristics(**kwargs)[source]¶
Bases:
GroupedComponentPropertiesData container for grouped component characteristics.
- Parameters:
is_set (boolean) – Should the equation for this parameter group be applied? default: is_set=False.
elements (list) – Which component properties are part of this component group? default elements=[].
- class tespy.tools.data_containers.GroupedComponentProperties(**kwargs)[source]¶
Bases:
_NumEqMixin,DataContainerData container for grouped component parameters.
- Parameters:
is_set (boolean) – Should the equation for this parameter group be applied? default: is_set=False.
method (str) – Which calculation method for this parameter group should be used? default: method=’default’.
elements (list) – Which component properties are part of this component group? default elements=[].
- 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 that formerly lived in Component.set_attr / Connection.set_attr.
- Parameters:
value – The value supplied by the user (numeric, string, dict, None, …).
- class tespy.tools.data_containers.ReferencedFluidProperties(**kwargs)[source]¶
Bases:
DataContainer
- class tespy.tools.data_containers.ScalarVariable(**kwargs)[source]¶
Bases:
DataContainer- property J_col¶
- static attr()[source]¶
Return the available attributes for a FluidProperties 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)[source]¶
Bases:
_NumEqMixin,DataContainerSimple data container without data type restrictions to val field.
- Parameters:
val (no specific datatype) – Value for the property, no predefined datatype.
is_set (boolean) – Has the value for this property been set? default: is_set=False.
- 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 that formerly lived in Component.set_attr / Connection.set_attr.
- Parameters:
value – The value supplied by the user (numeric, string, dict, None, …).
- static attr()[source]¶
Return the available attributes for a SimpleDataContainer type object.
- Returns:
out (dict) – Dictionary of available attributes (dictionary keys) with default values.
- property val¶
- class tespy.tools.data_containers.VectorVariable(**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 (dict) – Which fluid mass fractions have been set, default is_set={}. Pattern for dictionary: keys are fluid name, values are True or False.
balance (boolean) – Should the fluid balance equation be applied for this mixture? default: False.
- property J_col¶
- static attr()[source]¶
Return the available attributes for a FluidComposition 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 = [], comps: list = [], params: dict = {})[source]¶
Bases:
object- property is_set¶
- 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.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.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]¶
Pass the used branch and commit to the logger.
The following test reacts on a local system different than on Travis-CI. Therefore, a try/except test is created.
Example
>>> from tespy import logger >>> try: ... v = logger.check_git_branch() ... except FileNotFoundError: ... v = 'dsfafasdfsdf' >>> type(v) <class 'str'>
- 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.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 commit and the branch is available the commit and the branch will b 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.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- 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”
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”
- 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¶