deflex.DeflexGraph

class deflex.DeflexGraph(results, **kwargs)[source]

The deflex model graph with a networkx representation.

The sum of the variables are addedcan be used as weight

Parameters:

results (dict) – Deflex results dictionary.

Other Parameters:
 
  • default_node_color (str) – The default color as a dictionary with the keys “fg” for the foreground color (font color) and “bg” for the background color (fill color). The color has to be a hexadecimal string. The default color is used if no other color is set. (default: {“bg”: “#6a6a72”, “fg”: “#000000”}”)
  • default_edge_color (str) – The default edge color as a hexadecimal string. The default color is used if no other color is set. (default: “#000000””)
nodes

All nodes of the deflex energy system graph.

Type:list
edges

All edges of the deflex energy system graph.

Type:list
default_node_color

The default color for nodes with the keys bg for the background color and fg for text color (foreground).

Type:dict
default_edge_color

The default color for edges with the keys bg for the background color and fg for text color (foreground).

Type:dict

Examples

>>> import os
>>> 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)
>>> len(dflx_graph.nodes)
226
>>> sorted(dflx_graph.nodes)[5].label
Label(cat='chp plant', tag='other', subtag='other', region='DE01')
>>> len(dflx_graph.edges)
323
>>> dflx_graph.edges[5].label
'chp-plant_lignite_lignite_DE01 -> heat_district_all_DE01'
>>> type(dflx_graph.edges[5])
<class 'deflex.postprocessing.graph.Edge'>
>>> dflx_graph.edges[5].weight
136524.0
>>> nx_graph = dflx_graph.nxgraph()
>>> nx.number_of_nodes(nx_graph)
226
>>> nx.number_weakly_connected_components(nx_graph)
1
__init__(results, **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__(results, **kwargs) Initialize self.
color_edges_by_weight([cmap, max_weight]) Color all edges by their weight using a matplotlib color map (cmap).
color_nodes_by_substring(colors) Color all nodes in a specific color according to a given substring.
color_nodes_by_type(colors[, use_name]) Color all nodes in a specific color according to their class.
group_nodes_by_type([use_name]) 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.
nxgraph(**kwargs) Get a networkx.DiGraph() from the deflex results.
write(filename, **kwargs) Write the graph into a .graphml file.