verify.core
Conveniently generate verification result data and plots for assessing the proper component bahavior of an energy supply system simulation model. |
|
Tuple of strings representing the verified |
|
Mapping of energy system file names to constraint group strings. Used for verification. At default parameterization this looks like::. |
|
Tuple of strings representing the verified constraint types. |
|
Tuple of the constraints and constraint files subject to verification. |
|
Dictionary holding the Verificier's numerical results. At default parameterization, this dictionary would look like::. |
|
Dictionary holding the Verificier's graphical results. At default parameterization, this dictionary would look like::. |
|
Dictionary holding all of the Verificier's results. At default parameterization, this dictionary would look like::. |
|
Plot the networkx representation of an energy system subject to verification. |
The verify core module holds the Verificer class.
Its main access however is desinged to be via the verify __init__ moduel,
i.e. tessif.verify.Verificer.
- class tessif.verify.core.Verificier(model, parser, path=None, timeframe='primary', components=('connector', 'sink', 'source', 'storage', 'transformer'), constraints={'expansion': ('expansion_costs', 'expansion_limits'), 'linear': ('accumulated_amounts', 'flow_rates', 'flow_costs', 'flow_emissions', 'flow_gradients', 'gradient_costs', 'timeseries'), 'milp': ('initial_status', 'status_inertia', 'number_of_status_changes', 'costs_for_being_active')})[source]
Bases:
objectConveniently generate verification result data and plots for assessing the proper component bahavior of an energy supply system simulation model.
Note
This class assumes, you prepare a singular
tessif energy systemfor eachgroup of constraints. It further more assumes that all relevant results for verification can be extracted from a singlebus objectcarrying thenamecentralbus.- Parameters:
path¶ (str, Path, None, default=None) –
String representing the top level folder of where the tessif energy systems are stored. Verificier expects a singular energy system to be present for each combination of
components,constraintsand the respected group of constraints (e.g. flow rates). Hence the expected folder structure would look like:/top/level/folder |-- source | |-- expansion | | |-- costs.[hdf5/xlsx/cfg/...] | | |-- emissions.[hdf5/xlsx/cfg/...] | |-- linear | | |-- flow_rates.[hdf5/xlsx/cfg/...] | | |-- gradients.[hdf5/xlsx/cfg/...] | |-- milp | | |-- status.[hdf5/xlsx/cfg/...] | | |-- status_changing.[hdf5/xlsx/cfg/...] |-- sink | |-- expansion | | |-- costs.[hdf5/xlsx/cfg/...] | | |-- emissions.[hdf5/xlsx/cfg/...] ...
An example set of verification scenarios is found in the example directory.
If
None(default)application/verificationinsideexample_diris used.model¶ (str) – String specifying one of the
registered_modelsrepresenting the energy system simulation model investigated.parser¶ (
Callable) – Functional used to read in and parse the energy system data. Usually one of the module functions found intessif.parsetimeframe¶ (str, default='primary') – String specifying which of the (potentially multiple) timeframes passed is to be used. One of
'primary','secondary', etc… by convention.components¶ (Iterable, optional) –
Iterable of strings representing the
componentsto be verified. They also represent the first level of folders in which the energy systems are to be found for performing the verification procedure.Default is:
components=('connector', 'sink', 'source', 'storage', 'transformer')
constraints¶ (Mapping, optional) –
Mapping of energy system files to constraint group strings. Used for aggregating different constraints and constraint groups for each
component.Default is:
constraints={ 'expansion': ('costs.xml', 'emissions.xml',), 'linear': ('flow_rates.xml', 'gradients.xml'), 'milp': ('status.xml', 'status_changing.xml')}
Note
A logger.WARNING is triggered in case non existant constraint files are passed.
Example
Minimum working example:
(Optional) Change spellings logging level used by
spellings.get_fromtodebugfor decluttering output:>>> import tessif.frused.configurations as configurations >>> configurations.spellings_logging_level = 'debug'
Name the top level folder where your
tessif energy systemsresides in:>>> import os >>> from tessif.frused.paths import example_dir >>> folder = os.path.join( ... example_dir, 'application', 'verification_scenarios')
Construct the constraint dictionairy according to your needs (make sure the lowest level is an iterable of strings to get expectred results):
>>> chosen_constraints = {'linear': ('flow_rates_max.py', )}
Choose a parser depending on your energy system file formats:
>>> import tessif.parse >>> chosen_parser = tessif.parse.python_mapping
Chose the components and the model you wish to verify:
>>> chosen_components = ('source', ) >>> chosen_model = 'oemof'
Initialize the Verificier:
>>> import tessif.verify >>> verificier = tessif.verify.Verificier( ... path=folder, ... model=chosen_model, ... components=chosen_components, ... constraints=chosen_constraints, ... parser=chosen_parser)
Show the network graph of the analyzed es:
>>> import matplotlib.pyplot as plt >>> es_graph = verificier.plot_energy_system_graph( ... component='source', ... constraint_type='linear', ... constraint_group='flow_rates_max', ... node_color={ ... 'centralbus': '#9999ff', ... 'source_1': '#ff7f0e', ... 'source_2': '#2ca02c', ... 'sink': '#1f77b4' ... }, ... node_size={'centralbus': 5000}, ... ) >>> # es_graph.show() # commented out for simpler doctesting
Show the numerical results:
>>> print(verificier.numerical_results[ ... 'source']['linear']['flow_rates_max']) centralbus source1 source2 sink1 2022-01-01 00:00:00 -15.0 -35.0 50.0 2022-01-01 01:00:00 -15.0 -35.0 50.0 2022-01-01 02:00:00 -15.0 -35.0 50.0 2022-01-01 03:00:00 -15.0 -35.0 50.0 2022-01-01 04:00:00 -15.0 -35.0 50.0 2022-01-01 05:00:00 -15.0 -35.0 50.0 2022-01-01 06:00:00 -15.0 -35.0 50.0 2022-01-01 07:00:00 -15.0 -35.0 50.0 2022-01-01 08:00:00 -15.0 -35.0 50.0 2022-01-01 09:00:00 -15.0 -35.0 50.0
Show the graphical results:
>>> graphical_result_plot = verificier.graphical_results[ ... 'source']['linear']['flow_rates_max'] >>> # graphical_result_plot.show() # commented out for doctesting
- property components
Tuple of strings representing the verified
components.('connector', 'sink', 'source', 'storage', 'transformer',)at default parameterization.
- property constraints
Mapping of energy system file names to constraint group strings. Used for verification. At default parameterization this looks like:
constraints={ 'expansion': ('costs.xml', 'emissions.xml',), 'linear': ('flow_rates.xml', 'gradients.xml'), 'milp': ('status.xml', 'status_changing.xml')}
- property constraint_types
Tuple of strings representing the verified constraint types.
('expansion', 'linear', 'milp')at default parameterization.
- property constraint_groups
Tuple of the constraints and constraint files subject to verification.
At default parameterization this looks like:
('costs.xml', 'emissions.xml', 'flow_rates.xml', 'gradients.xml', 'status.xml', 'status_changing.xml')
- property energy_systems
Triple nested
Mappingoftessif energy systemobjects representing the analyzed energy systems.At default parameterization, this mapping looks like:
results = { 'connector': { 'expansion': { 'costs': Tessif-EnergySystem-Object, 'emissions': Tessif-EnergySystem-Object,}, 'linear': { 'flow_rates': Tessif-EnergySystem-Object, 'gradients': Tessif-EnergySystem-Object,}, 'milp': { 'status': Tessif-EnergySystem-Object, 'status_changing': Tessif-EnergySystem-Object,} } ' sink': ... }
- property graphs
Triple nested
Mappingofnetworkx.DiGraphobjects representing the analyzed energy systems.At default parameterization, this mapping looks like:
results = { 'connector': { 'expansion': { 'costs': networkx.DiGraph-Object, 'emissions': networkx.DiGraph-Object,}, 'linear': { 'flow_rates': networkx.DiGraph-Object, 'gradients': networkx.DiGraph-Object,}, 'milp': { 'status': networkx.DiGraph-Object, 'status_changing': networkx.DiGraph-Object,} } 'sink': ... }
- property graphical_results
Dictionary holding the Verificier’s graphical results. At default parameterization, this dictionary would look like:
results = { 'connector': { 'expansion': { 'costs': matplotlib.figure.Figure, 'emissions': matplotlib.figure.Figure,}, 'linear': { 'flow_rates': matplotlib.figure.Figure, 'gradients': matplotlib.figure.Figure,}, 'milp': { 'status': matplotlib.figure.Figure, 'status_changing': matplotlib.figure.Figure,} } 'sink': ... }
- property numerical_results
Dictionary holding the Verificier’s numerical results. At default parameterization, this dictionary would look like:
results = { 'connector': { 'expansion': { 'costs': DataFrame, 'emissions': DataFrame,}, 'linear': { 'flow_rates': DataFrame, 'gradients': DataFrame,}, 'milp': { 'status': DataFrame, 'status_changing': DataFrame,} } 'sink': ... }
- property results
Dictionary holding all of the Verificier’s results. At default parameterization, this dictionary would look like:
results = { 'connector': { 'expansion': { 'costs': (DataFrame, matplotlib.figure.Figure), 'emissions': (DataFrame, matplotlib.figure.Figure),}, 'linear': { 'flow_rates': (DataFrame, matplotlib.figure.Figure), 'gradients': (DataFrame, matplotlib.figure.Figure),}, 'milp': { 'status': (DataFrame, matplotlib.figure.Figure), 'status_changing': (...),} } 'sink': ... }
- plot_energy_system_graph(component, constraint_type, constraint_group, title='default', **kwargs)[source]
Plot the networkx representation of an energy system subject to verification.
- Parameters:
String specifying a component as in
componentsof which thegraph objectis to be plotted.At default parameterization this would be one of:
{'connector', 'source', 'sink', 'storage', 'transformer'}
String specifying a constraint type as in
constraint_typesof which thegraph objectis to be plotted.At default parameterization this would be one of:
{'expansion', 'linear', 'milp'}
String specifying a constraint group as in
constraint_groupsof which thegraph objectis to be plotted.At default parameterization this would be one of:
{'costs.xml', 'emissions.xml', 'flow_rates.xml', 'gradients.xml', 'status.xml', 'status_changing.xml'}
title¶ (str, None, default='default') –
String specifying the plot title.
Defaults to:
Energy System for Verifying the 'constraint_group' Constraints
- Returns:
nxgraph – Created networkx graph object.
- Return type: