deflex.DeflexGraph.group_nodes_by_type

DeflexGraph.group_nodes_by_type(use_name=False)[source]

Group all nodes by types returning a dictionary with the types or the name of the types as keys and the list of nodes as value.

The keys of the returning dictionary are the classes (or name of the classes) the values are lists with nodes of the corresponding class.

Parameters:use_name (bool) – Use the name of the class instead of the class as key.
Returns:All nodes sorted by their type
Return type:dict

Examples

>>> from deflex import fetch_test_files
>>> from deflex import restore_results
>>> from deflex import DeflexGraph
>>> fn = fetch_test_files("de03_fictive.dflx")
>>> my_results = restore_results(fn)
>>> dflx_graph = DeflexGraph(my_results)
>>> sorted(dflx_graph.group_nodes_by_type(use_name=True))
['Bus', 'GenericStorage', 'Sink', 'Source', 'Transformer']
>>> list(dflx_graph.group_nodes_by_type(use_name=False))[0].__mro__[-2]
<class 'oemof.network.network.Node'>
>>> sources = dflx_graph.group_nodes_by_type(use_name=True)["Source"]
>>> sorted(sources)[-1].label
Label(cat='source', tag='volatile', subtag='wind', region='DE03')