A4 · Lesson 53 · Mini-project
What an hour of grid frequency says about the power system
The frequency of the power grid isn't exactly 50 or 60 Hz. It wanders by a few hundredths of a hertz all day, because generation and demand never match exactly, and when a large power station trips offline it drops sharply and then recovers. Grid operators watch this number second by second. In this project you'll analyze an hour of it, using everything from this course.
Predict
A large generator trips offline and the frequency drops. Why does it drop, rather than rise?
When generation falls short of demand, the difference is supplied from the kinetic energy stored in every synchronous machine on the grid, which all spin in step. Giving up energy slows them down, and their speed is the frequency. Controls then raise the output of other plants, which stops the fall within seconds and brings the frequency back over minutes.
Name it
The data, and the plan
The log for this project is simulated, built to behave like a 50 Hz grid: a slow random wander with a spread of about 0.04 Hz, sampled once a second for an hour, and one event, a generator trip half an hour in. Real logs look much like it, and you'd load one with np.loadtxt exactly as in lesson 45. Each lab starts with the same few lines that build the log; don't change them.
import numpy as np
rng = np.random.default_rng(2024)
t = np.arange(3600) # seconds
dev = np.zeros(3600)
for k in range(1, 3600): # a slow random wander
dev[k] = 0.995 * dev[k - 1] + rng.normal(0, 0.004)
s = np.clip(t - 1800, 0, None) # time since the trip
event = -0.25 * (1 - np.exp(-s / 3)) * np.exp(-s / 120)
f = 50 + dev + event # the frequency, in Hz
The tools you'll use:
- Statistics:
f.mean(),f.std(),f.min()andnp.argmin(f)for when the minimum happened. - Thresholds: a comparison like
f < 49.8gives True or False at every second;np.meanof it is the fraction of time it's true, andnp.argmaxof it is the first second it's true. - Plots: two stacked panels, the full hour and a zoom on the event.
Grid operators work with bands. Here, take the normal operating band as 50 ± 0.2 Hz.
Check
Set f_mean to the hour's average frequency, f_std to its standard deviation, f_min to its lowest value and t_min to the time in seconds when that lowest value happened.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set out_frac to the fraction of the hour that the frequency spends outside the band 50 ± 0.2 Hz, and t_first to the first second at which it drops below 49.8 Hz.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Plot the log in two stacked panels: the full hour on top, and the ten minutes from 1750 s to 2350 s below. Draw the band limits, 49.8 and 50.2 Hz, as dashed lines in both. Label the axes.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Explain why
Looking at your two panels, describe what happens to the grid frequency during the event, and what it tells you about how the grid responds.
Before the trip the frequency wanders by a few hundredths of a hertz around 50 Hz. At the trip it falls quickly, by about a quarter of a hertz within fifteen seconds or so, dipping below the 49.8 Hz band, as the spinning machines give up energy to cover the missing generation. The fall is arrested within seconds, showing that fast automatic controls raised other plants' output, and then the frequency climbs back toward 50 Hz over a couple of minutes as slower controls restore the balance.
Practice
Keep practicing
3 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.