oemof.outputlib package¶
Submodules¶
oemof.outputlib.processing module¶
Modules for providing a convenient data structure for solph results.
Information about the possible usage is provided within the examples.
This file is part of project oemof (github.com/oemof/oemof). It’s copyrighted by the contributors recorded in the version control history of the file, available from its original location oemof/oemof/outputlib/processing.py
SPDX-License-Identifier: MIT
-
oemof.outputlib.processing.
convert_keys_to_strings
(result, keep_none_type=False)[source]¶ Convert the dictionary keys to strings.
All (tuple) keys of the result object e.g. results[(pp1, bus1)] are converted into strings that represent the object labels e.g. results[(‘pp1’,’bus1’)].
-
oemof.outputlib.processing.
create_dataframe
(om)[source]¶ Create a result dataframe with all optimization data.
Results from Pyomo are written into pandas DataFrame where separate columns are created for the variable index e.g. for tuples of the flows and components or the timesteps.
-
oemof.outputlib.processing.
get_timestep
(x)[source]¶ Get the timestep from oemof tuples.
The timestep from tuples (n, n, int), (n, n), (n, int) and (n,) is fetched as the last element. For time-independent data (scalars) zero ist returned.
-
oemof.outputlib.processing.
get_tuple
(x)[source]¶ Get oemof tuple within iterable or create it.
Tuples from Pyomo are of type (n, n, int), (n, n) and (n, int). For single nodes n a tuple with one object (n,) is created.
-
oemof.outputlib.processing.
meta_results
(om, undefined=False)[source]¶ Fetch some meta data from the Solver. Feel free to add more keys.
Valid keys of the resulting dictionary are: ‘objective’, ‘problem’, ‘solver’.
- om : oemof.solph.Model
- A solved Model.
- undefined : bool
- By default (False) only defined keys can be found in the dictionary. Set to True to get also the undefined keys.
Returns: Return type: dict
-
oemof.outputlib.processing.
parameter_as_dict
(system, exclude_none=True)[source]¶ Create a result dictionary containing node parameters.
Results are written into a dictionary of pandas objects where a Series holds all scalar values and a dataframe all sequences for nodes and flows. The dictionary is keyed by flows (n, n) and nodes (n, None), e.g. parameter[(n, n)][‘sequences’] or parameter[(n, n)][‘scalars’].
Parameters: - system (energy_system.EnergySystem) – A populated energy system.
- exclude_none (bool) – If True, all scalars and sequences containing None values are excluded
Returns: dict
Return type: Parameters for all nodes and flows
-
oemof.outputlib.processing.
remove_timestep
(x)[source]¶ Remove the timestep from oemof tuples.
The timestep is removed from tuples of type (n, n, int) and (n, int).
-
oemof.outputlib.processing.
results
(om)[source]¶ Create a result dictionary from the result DataFrame.
Results from Pyomo are written into a dictionary of pandas objects where a Series holds all scalar values and a dataframe all sequences for nodes and flows. The dictionary is keyed by the nodes e.g. results[idx][‘scalars’] and flows e.g. results[n, n][‘sequences’].
oemof.outputlib.views module¶
Modules for providing convenient views for solph results.
Information about the possible usage is provided within the examples.
This file is part of project oemof (github.com/oemof/oemof). It’s copyrighted by the contributors recorded in the version control history of the file, available from its original location oemof/oemof/outputlib/views.py
SPDX-License-Identifier: MIT
-
class
oemof.outputlib.views.
NodeOption
[source]¶ Bases:
str
,enum.Enum
An enumeration.
-
All
= 'all'¶
-
HasInputs
= 'has_inputs'¶
-
HasOnlyInputs
= 'has_only_inputs'¶
-
HasOnlyOutputs
= 'has_only_outputs'¶
-
HasOutputs
= 'has_outputs'¶
-
-
oemof.outputlib.views.
convert_to_multiindex
(group, index_names=None, droplevel=None)[source]¶ Convert dict to pandas DataFrame with multiindex
Parameters: - group (dict) – Sequences of the oemof.solph.Model.results dictionary
- index_names (arraylike) – Array with names of the MultiIndex
- droplevel (arraylike) – List containing levels to be dropped from the dataframe
-
oemof.outputlib.views.
filter_nodes
(results, option=<NodeOption.All: 'all'>, exclude_busses=False)[source]¶ Get set of nodes from results-dict for given node option.
This function filters nodes from results for special needs. At the moment, the following options are available:
NodeOption.All
/’all’
:- Returns all nodes
NodeOption.HasOutputs
/’has_outputs’
:- Returns nodes with an output flow (eg. Transformer, Source)
NodeOption.HasInputs
/’has_inputs’
:- Returns nodes with an input flow (eg. Transformer, Sink)
NodeOption.HasOnlyOutputs
/’has_only_outputs’
:- Returns nodes having only output flows (eg. Source)
NodeOption.HasOnlyInputs
/’has_only_inputs’
:- Returns nodes having only input flows (eg. Sink)
Additionally, busses can be excluded by setting exclude_busses to
True
.Parameters: - results (dict) –
- option (NodeOption) –
- exclude_busses (bool) – If set, all bus nodes are excluded from the resulting node set.
Returns: A set of Nodes.
Return type: set
-
oemof.outputlib.views.
get_node_by_name
(results, *names)[source]¶ Searches results for nodes
Names are looked up in nodes from results and either returned single node (in case only one name is given) or as list of nodes. If name is not found, None is returned.
-
oemof.outputlib.views.
net_storage_flow
(results, node_type)[source]¶ Calculates the net storage flow for storage models that have one input edge and one output edge both with flows within the domain of non-negative reals.
- results: dict
- A result dictionary from a solved oemof.solph.Model object
- node_type: oemof.solph class
- Specifies the type for which (storage) type net flows are calculated
Returns: - pandas.DataFrame object with multiindex colums. Names of levels of columns
- are (from, to, net_flow.)
Examples
import oemof.solph as solph from oemof.outputlib import views
# solve oemof solph model ‘m’ # Then collect node weights views.net_storage_flow(m.results(), node_type=solph.GenericStorage)
-
oemof.outputlib.views.
node
(results, node, multiindex=False, keep_none_type=False)[source]¶ Obtain results for a single node e.g. a Bus or Component.
Either a node or its label string can be passed. Results are written into a dictionary which is keyed by ‘scalars’ and ‘sequences’ holding respective data in a pandas Series and DataFrame.
-
oemof.outputlib.views.
node_input_by_type
(results, node_type, droplevel=None)[source]¶ Gets all inputs for all nodes of the type node_type and returns a dataframe.
- results: dict
- A result dictionary from a solved oemof.solph.Model object
- node_type: oemof.solph class
- Specifies the type of the node for that inputs are selected
import oemof.solph as solph from oemof.outputlib import views
# solve oemof solph model ‘m’ # Then collect node weights views.node_input_by_type(m.results(), node_type=solph.Sink)
-
oemof.outputlib.views.
node_output_by_type
(results, node_type, droplevel=None)[source]¶ Gets all outputs for all nodes of the type node_type and returns a dataframe.
- results: dict
- A result dictionary from a solved oemof.solph.Model object
- node_type: oemof.solph class
- Specifies the type of the node for that outputs are selected
import oemof.solph as solph from oemof.outputlib import views
# solve oemof solph model ‘m’ # Then collect node weights views.node_output_by_type(m.results(), node_type=solph.Transformer)
-
oemof.outputlib.views.
node_weight_by_type
(results, node_type)[source]¶ Extracts node weights (if exist) of all components of the specified node_type.
Node weight are endogenous optimzation variables associated with the node and not the edge between two node, foxample the variable representing the storage level.
Parameters: - results (dict) – A result dictionary from a solved oemof.solph.Model object
- node_type (oemof.solph class) – Specifies the type for which node weights should be collected
Example
from oemof.outputlib import views
# solve oemof model ‘m’ # Then collect node weights views.node_weight_by_type(m.results(), node_type=solph.GenericStorage)