powergrid_synth.core.comparison
This module conveniently compares the synthetically generated power grid topology with the real power grid topology.
TODO: perhaps also include another module that compares the other parts of the generated data like bus types and so on.
Module Contents
- class powergrid_synth.core.comparison.GraphComparator(synth_graph, ref_graph, synth_label='Synthetic', ref_label='Reference (Real)')[source]
Compares a synthetic power grid against a reference (real-world) graph. Provides tabular metric comparisons and visual distribution overlaps, both globally and per voltage level.
- Parameters:
synth_graph (networkx.Graph)
ref_graph (networkx.Graph)
synth_label (str)
ref_label (str)
- _get_comparison_data(graph1, graph2)[source]
Helper to generate the dataframe for two specific graphs.
- Parameters:
graph1 (networkx.Graph)
graph2 (networkx.Graph)
- Return type:
pandas.DataFrame
- compare_degree_distributions(show_pvalue=False)[source]
Computes Kolmogorov-Smirnov (KS) and Relative Hausdorff (RH) statistics between the degree distributions of the synthetic and reference graphs, per voltage level. Prints and returns the results table.
- Parameters:
show_pvalue (bool) – If True, include the KS p-value column. Default False.
- Returns:
pd.DataFrame with columns Level, KS Statistic, RH Distance (and KS p-value if show_pvalue is True).
- Return type:
pandas.DataFrame
- plot_all_levels_comparison(log_scale=True)[source]
Plots degree comparison for all common voltage levels in a single figure.
- Parameters:
log_scale (bool)
- plot_degree_comparison(synth_graph=None, ref_graph=None, ax=None, log_scale=True, fig_size=(8, 5), show_lines=False, title='Degree Distribution Comparison')[source]
Plots overlaid degree distributions.
- Parameters:
synth_graph (Optional[networkx.Graph]) – Custom synthetic graph (or None for self.synth_graph).
ref_graph (Optional[networkx.Graph]) – Custom reference graph (or None for self.ref_graph).
ax (Optional[matplotlib.pyplot.Axes]) – Matplotlib axis to plot on. If None, creates new figure.
log_scale (bool) – Whether to use log-log scale (default True).
title (str) – Title for the plot.
fig_size (Tuple)
show_lines (bool)
- plot_level_topology_comparison(figsize=(15, 10))[source]
Plots side-by-side bar comparisons for topology metrics per voltage level: Nodes, Edges, Diameter, Avg Path Length, Avg Clustering.
- Parameters:
figsize (Tuple[int, int])
- print_level_metrics()[source]
Iterates through voltage levels found in both graphs and prints metrics. Does NOT plot.