High-fidelity inference of power grid frequency distributions
Alessandro Lonardi, Benjamin Schäfer, and Christian Beck
[arXiv]
This repository contains the implementation of the paper's algorithm and links to open-source data deposited in a Zenodo folder.
The code is made available for the public, if you make use of it please cite the associated publication.
Below, we describe the main components of the code. In a Jupyter notebook, we also show how to test it on measured frequency data.
The code was developed using Python 3.12 and can be downloaded and used locally as-is.
To install the necessary packages, you can follow these steps:
- Install Poetry
- Clone this repository to your machine
- Install the dependencies with Poetry using
poetry install --no-rootThe core folder and files implementing the algorithms are the following:
-
model/-
block_descent.pythis is where the upper structure of the block-coordinate descent algorithm is. The file contains the functionfit()wherelinear_regression()andmle()are iteratively called to infer$\mathbf{P}$ and$\boldsymbol{\theta}$ , respectively. -
linear_solver.pysparse direct linear solved to infer$\mathbf{P}$ (we usescipy.sparse.linalg.spsolve()) -
mle_parameters.pyprofile likelihood optimization to infer$\boldsymbol{\theta}$ (we use the L-BFGS-B optimizer) -
control.pyimplementation of the piecewise control function -
interpolation_matrix.pyprecomputed coarsening matrix$\mathbf{B}$
-
main.py
The input parameters accepted by the main.py are:
-
--csv_path: path to the CSV file containing frequency measurements -
--window_size: batch size$T$ (real-world measurements are resolved at one second so this should be in seconds as well. E.g., for 1 minute write window_size = 60) -
--index_batch: index of the batch to run (the measurements are automatically split in non-overlapping windows of size window_size) -
--omega_0: first control threshold -
--omega_1: second control threshold -
--dt: sampling time step (seconds assumed) -
--downsample_factor: downsampling factor$N$ -
--max_iter: upper bound on the number of block-coordinate descent iterations -
--tol: convergence tolerance -
--gamma_1: initial value of$\gamma_1$ -
--gamma_2: initial value of$\gamma_2$ -
--epsilon: initial value of$\epsilon$ -
--output_dir: output directory -
--seed: random seed -
--verbose: verbosity mode (accepts "verbose" or "non_verbose")
We open-source the frequency measurements used in our study, recorded from two PMUs between 28 April 2025 and 31 December 2025. The data are sampled at a 1-second resolution.
Important: Due to their large size, the files are not directly uploaded on GitHub. You can find them deposited in a Zenodo folder.
Once you download the data, add them to the data folder as:
- data/frequency_london.csv
- data/frequency_stellenbosch.csv
Doing so allows running the notebook in notebooks.