deflex.DeflexGraph.nxgraph¶
-
DeflexGraph.
nxgraph
(**kwargs)[source]¶ Get a networkx.DiGraph() from the deflex results.
Some labels will be added to the edges and nodes.
Node * label: label of the Node as string * bg_color: background color of the node for plots or exports * fg_color: text color of the node for plots or exports * type: name of the node class
Edge * weight: sum of the flow variable * color: color of the edge depending of the weight
Other Parameters: weight_exponent (int) – Shift the decimal point: Examples
>>> import os >>> import deflex as dflx >>> fn = dflx.fetch_test_files("de03_fictive.dflx") >>> my_results = dflx.restore_results(fn) >>> dflx_graph = dflx.DeflexGraph(my_results) >>> type(dflx_graph.nxgraph(weight_exponent=-3)) <class 'networkx.classes.digraph.DiGraph'> >>> edges_data = dflx_graph.nxgraph().edges.data() >>> wind2bus = [e[2] for e in edges_data if ... e[0].subtag == "wind" and ... e[0].region == "DE01" ... ][0] >>> wind2bus["label"] 'source_volatile_wind_DE01 -> electricity_all_all_DE01' >>> wind2bus["weigth"], wind2bus["color"] ('337.0', '#000000') >>> dflx_graph.color_edges_by_weight() >>> edges_data = dflx_graph.nxgraph(weight_exponent=-3).edges.data() >>> wind2bus = [e[2] for e in edges_data if ... e[0].subtag == "wind" and ... e[0].region == "DE01" ... ][0] >>> wind2bus["weigth"], wind2bus["color"] ('337.0', '#09f6ff') >>> nodes_data = dflx_graph.nxgraph().nodes.data() >>> wind_node = [n[1] for n in nodes_data if ... n[0].subtag == "wind" and ... n[0].region == "DE01" ... ][0] >>> wind_node["label"] 'source_volatile_wind_DE01' >>> wind_node['bg_color'] '#6a6a72' >>> wind_node["type"] 'Source' >>> my_colors = {"Source": {"bg": "#996967", "fg": "#000000"}} >>> dflx_graph.color_nodes_by_type(my_colors) >>> nodes_data = dflx_graph.nxgraph().nodes.data() >>> wind_node = [n[1] for n in nodes_data if ... n[0].subtag == "wind" and ... n[0].region == "DE01" ... ][0] >>> wind_node['bg_color'] '#996967'