Skip to content

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Code for: High-fidelity inference of power grid frequency distributions

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.

Code installation

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:

  1. Install Poetry
  2. Clone this repository to your machine
  3. Install the dependencies with Poetry using
poetry install --no-root

Numerical methods

The core folder and files implementing the algorithms are the following:

  • model/
    • block_descent.py this is where the upper structure of the block-coordinate descent algorithm is. The file contains the function fit() where linear_regression() and mle() are iteratively called to infer $\mathbf{P}$ and $\boldsymbol{\theta}$, respectively.
    • linear_solver.py sparse direct linear solved to infer $\mathbf{P}$ (we use scipy.sparse.linalg.spsolve() )
    • mle_parameters.py profile likelihood optimization to infer $\boldsymbol{\theta}$ (we use the L-BFGS-B optimizer)
    • control.py implementation of the piecewise control function
    • interpolation_matrix.py precomputed 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")

Open-source data

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.

About

Code supporting the publication "High-fidelity inference of power grid frequency distributions"

Resources

Stars

2 stars

Watchers

0 watching

Forks

Contributors

Languages