Metadata-Version: 2.4
Name: gridshedwatch
Version: 1.2.0
Summary: A benchmark for early warning of grid load sheds, scored the way forecasters score weather warnings
Author: Sam Heiserman
License: MIT
Project-URL: Homepage, https://gotham29.github.io/gridshedwatch
Project-URL: Repository, https://github.com/gotham29/gridshedwatch
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.22
Requires-Dist: pandas>=1.5
Requires-Dist: pyyaml>=6
Requires-Dist: scipy>=1.9
Provides-Extra: lstm
Requires-Dist: torch>=2.0; extra == "lstm"
Provides-Extra: gbm
Requires-Dist: lightgbm>=4; extra == "gbm"
Provides-Extra: subpca
Requires-Dist: scikit-learn>=1.2; extra == "subpca"
Provides-Extra: chronos
Requires-Dist: torch>=2.0; extra == "chronos"
Requires-Dist: chronos-forecasting>=1.4; extra == "chronos"
Provides-Extra: analysis
Requires-Dist: matplotlib>=3.5; extra == "analysis"
Provides-Extra: test
Requires-Dist: pytest>=7; extra == "test"
Dynamic: license-file

# GridShedWatch

[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.23626223.svg)](https://doi.org/10.5281/zenodo.23626223) [![tests](https://github.com/gotham29/gridshedwatch/actions/workflows/tests.yml/badge.svg)](https://github.com/gotham29/gridshedwatch/actions/workflows/tests.yml)

**A benchmark for early warning of grid load sheds, scored the way forecasters score weather warnings.**

Website: **https://gotham29.github.io/gridshedwatch** (built from this repo by `scripts/build_site.py`).
The story behind it: [Grid emergency warnings don't have a scorecard. So I built one.](https://medium.com/@sheiser1/grid-emergency-warnings-dont-have-a-scorecard-so-i-built-one-0b504dd4e63c) (Medium).
The first results, five methods compared: [Rules, stats, machine learning or a foundation model? Warning of grid blackouts](https://medium.com/@sheiser1/rules-stats-machine-learning-or-a-foundation-model-warning-of-grid-blackouts-e068e8881ab6) (Medium).

Since 2020, US grid operators have had to cut power for lack of supply eight times. The public
was warned beforehand in four of them, and in none of the four during Winter Storm Elliott.
Plenty of methods claim to detect grid trouble early, but there has been no shared test of
whether a warning would actually have come in time. GridShedWatch is that test: every one of
those eight load sheds, public hourly data, and one fixed scoring procedure that any method can
be run through.

**What it shows so far.** The operators' own day-ahead demand forecast, run through the same
scoring, watches all 8 load sheds about 16 hours ahead, but it alerts just as readily on grids that
weathered the same storm without trouble. Telling a coming shortfall from a cold week is the open
problem: four learned methods beat chance and some are more selective, though on few grids. And
speed matters: public net generation arrives the next morning, and with alerts a day late no method
is shown to beat chance. With lag-free data, such as an operator's own real-time feeds, the replay
results are the relevant ones.

The idea behind it isn't new. The National Weather Service has
[scored its warnings for decades](https://doi.org/10.1175/waf-d-18-0120.1) on three numbers read
together: how many events were warned in advance, how much notice people got, and how many
warnings were false alarms. GridShedWatch applies that established framework to grid
emergencies, at the weather service's own two levels: a **watch** (something unusual is
building) and a **warning** (act now).

![What operators announced in the week before each load shed](https://raw.githubusercontent.com/gotham29/gridshedwatch/main/docs/img/operator_notices.png)

Uri and the 2020 California heat wave were forecast days out, and operators climbed a ladder of
notices. Elliott built faster than the forecasts: in all four Elliott events, the public's first
word was the blackout itself. That gap is what an independent warning signal could fill, and
what GridShedWatch measures.

## What's in it

| | |
|---|---|
| **Events** | 8 supply-shortfall load sheds of at least 250 MW, Jan 2020 to Sep 2026, chosen by a stated rule from NERC's annual lists ([docs/events.md](https://github.com/gotham29/gridshedwatch/blob/main/docs/events.md)) |
| **Data** | A frozen snapshot of EIA-930 hourly demand, day-ahead forecast and net generation for 48 balancing authorities, 2019-2026 (the 8 with load sheds, 1 with a Tier 2 case study, and 39 with no qualifying emergency), and the five signals built from it ([gridshedwatch/snapshot_v2.0/](https://github.com/gotham29/gridshedwatch/tree/main/gridshedwatch/snapshot_v2.0)) |
| **Rules** | One shared rule that turns per-signal scores into watches and warnings, so methods differ only in how they score each hour ([gridshedwatch/rules.py](https://github.com/gotham29/gridshedwatch/blob/main/gridshedwatch/rules.py)) |
| **Scoring** | The same alert budget for every method, set on quiet grids without looking at any event; events caught, lead time, and false alarms on quiet grids, with exact intervals and a seasonal chance baseline, fixed in a dated protocol ([docs/protocol_v3.md](https://github.com/gotham29/gridshedwatch/blob/main/docs/protocol_v3.md)) |
| **Status quo** | Every operator notice in the week before each event, with times and sources ([gridshedwatch/operator_notices.yaml](https://github.com/gotham29/gridshedwatch/blob/main/gridshedwatch/operator_notices.yaml)) |
| **Reference methods** | 11: an operator-style rule, a seasonal z-score, CUSUM, critical slowing down, Sub-PCA, LSTM, PatchTST and LightGBM forecasters, Chronos-Bolt (zero-shot), HTM, and random scores, plus two weather controls built on the day-ahead forecast ([gridshedwatch/baselines/](https://github.com/gotham29/gridshedwatch/tree/main/gridshedwatch/baselines/)) |
| **Datasheet** | Motivation, composition, collection, intended uses, known biases and maintenance ([docs/datasheet.md](https://github.com/gotham29/gridshedwatch/blob/main/docs/datasheet.md)) |
| **Talk** | Slides on the benchmark and what it shows ([deck/gridshedwatch-talk.pdf](https://github.com/gotham29/gridshedwatch/blob/main/deck/gridshedwatch-talk.pdf)) |

| Event | Grid | Shed at its worst | Split |
|---|---|---|---|
| Heat wave, Aug 2020 | California (CAISO) | about 1,000 MW | development |
| Winter Storm Uri, Feb 2021 | Texas (ERCOT) | 20,000 MW | development |
| Uri | Southwest Power Pool | 2,700 MW | held-out |
| Uri | MISO (MISO South) | 700 MW | held-out |
| Winter Storm Elliott, Dec 2022 | Tennessee Valley Authority | 3,000 MW | development |
| Elliott | Duke Energy Carolinas | up to 1,000 MW | held-out |
| Elliott | Duke Energy Progress | about 960 MW | held-out |
| Elliott | LG&E and KU (Kentucky) | about 300 MW | held-out |

## Results

<!-- leaderboard:start -->
| method | watches (of 8) | by chance | p | warnings before onset | median watch lead (h) | quiet grids: median / 90th pct / worst | within budget |
|---|---|---|---|---|---|---|---|
| Gradient-boosted forecaster | 7.2 | 2.21 | 0.0055 | 6 | 43 | 16 / 33 / 63 | yes |
| LSTM forecaster | 6.2 | 1.94 | 0.0055 | 4 | 11 | 12 / 32 / 56 | yes |
| Chronos-Bolt (zero-shot) | 6 | 2.6 | 0.1434 | 1 | 30 | 12 / 32 / 49 | yes |
| HTM (htm-monitor, frozen after 2019) | 6 | 1.7 | 0.0055 | 5 | 62 | 14 / 20 / 29 | yes |
| PatchTST forecaster | 6 | 1.83 | 0.0055 | 5.6 | 12 | 12 / 28 / 47 | yes |
| Operator-style rule | 5 | 2.33 | 0.2549 | 2 | 140 | 12 / 19 / 31 | yes |
| Seasonal z-score | 5 | 0.86 | 0.1434 | 3 | 107 | 13 / 16 / 21 | yes |
| CUSUM | 5 | 1.54 | 0.2549 | 4 | 65 | 12 / 20 / 27 | yes |
| Critical slowing down | 4 | 2.26 | 0.4873 | 1 | 114 | 9 / 14 / 21 | yes |
| Sub-PCA | 2 | 0.78 | 0.4873 | 0 | 73 | 11 / 23 / 28 | yes |
| Random scores | 1 | 1.77 | 0.973 | 0.2 | 65 | 12 / 13 / 14 | yes |

Tier 1 load sheds, mean over seeds. *By chance*: the same alerts moved to random times in the same season; *p*: Holm-corrected over the 11 methods. Listed by watches caught; 8 events cannot rank the leading methods. Weather control (how unusual the grid's own day-ahead forecast is for the season): 8 watches, 1.25 by chance, 3 warnings before onset. Weather control (the grid's own day-ahead forecast level): 3 watches, 0.54 by chance, 0 warnings before onset.
<!-- leaderboard:end -->

With data replayed as it happened, four methods catch 6 to 7 of the 8 load sheds with watches,
where their own alerts at random times in the same season catch about 2. But a control built only
on the operators' own day-ahead demand forecast catches all 8, about 16 hours ahead, with no
publication delay; it also alerts on every equally cold grid that did not shed, while the learned
methods are selective. With a day's real-time delay (published net generation arrives the next
morning) no method beats chance. Telling a coming shortfall from a cold week is where methods
differ. Full results, robustness checks and controls: the paper and `results/v3.0/`.

## Quick start

```bash
pip install gridshedwatch                # or, to work on the code:
git clone https://github.com/gotham29/gridshedwatch && cd gridshedwatch
pip install -e ".[test]"
gridshedwatch info                       # the eight events and their timelines
gridshedwatch score --oprule             # score the built-in operator-style rule
python examples/my_method.py             # scores track template: writes my_scores/
gridshedwatch score my_scores --name "My method"
python examples/my_alerts.py             # alerts track template: writes my_alerts.csv
gridshedwatch score-alerts my_alerts.csv --name "My rule"
```

## Add your method

There are two ways in.

**Scores track** (the controlled comparison). Your method says, for every grid, every hour and
each of the five signals, how unusual that signal is now, as a score in [0, 1], using data up to
that hour only. Write the scores in the submission layout (`my_scores/s<seed>/<grid>.csv`, see
[gridshedwatch/submission.py](https://github.com/gotham29/gridshedwatch/blob/main/gridshedwatch/submission.py)) and run `gridshedwatch score`. The
shared rules, the label-free budget step and the scoring are done for you, so your method
cannot be tuned toward the eight events. Template: [examples/my_method.py](https://github.com/gotham29/gridshedwatch/blob/main/examples/my_method.py).

**Alerts track** (any method). If your method decides on its own when to raise a watch or a
warning (a rule, a classifier, a weather-based model, a human forecaster), list when each alert
started and score the list. For example, take a simple rule: raise a watch when demand has run
unusually far above its forecast for three hours, and a warning when it has done so badly for
six ([examples/my_alerts.py](https://github.com/gotham29/gridshedwatch/blob/main/examples/my_alerts.py)).
Running it writes one line per alert (add a `seed` column if your method is random):

```
grid,level,start_utc
tx,watch,2021-02-09 12:00
tx,warning,2021-02-09 21:00
duk,watch,2022-12-24 00:00
...
```

Score it:

```
gridshedwatch score-alerts my_alerts.csv --name "My rule"
```

```
                     method  watches (of 8)  by chance       p  warnings before onset  median watch lead (h)  quiet grids: median / 90th pct / worst  within budget
Gradient-boosted forecaster             7.2       2.21  0.0055                    6.0                   43.0                            16 / 33 / 63           True
...
              Random scores             1.0       1.77  0.9730                    0.2                   65.0                            12 / 13 / 14           True
                    my_rule             3.0       1.40  0.1439                    1.0                  131.0                               4 / 7 / 10           True
```

Your method is printed under the 11 reference methods, scored by the same rules: load sheds
caught with a watch, how many its alerts would catch at random times in the same season, the
chance p-value, warnings before onset, lead, and watches a year on the 20 quiet grids not used to
set thresholds. The rule above watched 3 of the 8 load sheds where chance gives 1.4, not enough to
beat chance. Alerts-track entries must be within the same budget as the scores track (the median
calibration grid at most 12 watches and 2 warnings a year, +5%); list alerts for all 48 grids
(`data.grids("2.0")`), since a grid left out counts as raising none. Full results go to
`gsw_results/methods/<name>/`. Format:
[gridshedwatch/alerts.py](https://github.com/gotham29/gridshedwatch/blob/main/gridshedwatch/alerts.py).
A scores-track run also writes its alerts in this format (`alerts.csv`), and scoring that file
reproduces its results.

![How one method is scored on one grid](https://raw.githubusercontent.com/gotham29/gridshedwatch/main/docs/img/scoring_example.png)

- Scores track: use the five signals provided (and 2019 for calibration). Alerts track: any data
  available at the time of each alert. Methods that use data beyond the five signals are listed
  separately.
- If your method is random, submit several seeds; results are averaged.
- To add a result to the table, open a pull request with your scores or alerts (or a link to
  them), the code that produced them, the output of `--json`, and short answers on the data used
  and, for the alerts track, which events you looked at while developing
  ([docs/scoring.md](https://github.com/gotham29/gridshedwatch/blob/main/docs/scoring.md#listing-a-result)). Every result is added, including ones
  that beat the reference methods.

## Reproducing the results

```bash
python scripts/fetch_reference.py                    # reference scores (release asset)
python scripts/score_v3.py --jobs 4                  # every reference method, under docs/protocol_v3.md
python scripts/score_v3.py --stats                   # summary.csv, Friedman, leave one storm out
python scripts/per_hour_metrics.py --version 3.0     # per-hour metrics (pip install TSB-AD --no-deps)
python scripts/leaderboard_md.py                     # the table above
```

Deterministic methods are recomputed from the data; the neural ones and HTM are read from their
reference scores, since training is not bit-identical across platforms. HTM's scores come from
[htm-monitor](https://github.com/gotham29/htm-monitor), scored here like any other submission.
Earlier releases stay reproducible from their tags.

## Limits

- Eight load sheds, seven from two storms (Uri and Elliott); the five held-out events share those
  storms. One storm of a new kind could change the picture.
- The shared alert rule was developed on three of the events, using HTM's output.
- Reference methods see only five signals from EIA-930: no weather, outage or market data. The
  alerts track is open to methods that use more.
- Published net generation arrives the next morning, so real-time alerts would come 11 to 35 hours
  later than in the replay; results a day late are reported beside the headline.
- The status quo covers operators' public notices, not their operating notices to the industry.

GridShedWatch grows as new events happen: each load shed that meets the rule is added in a new
release and scored by the frozen protocol.

## Citation and license

DOI: [10.5281/zenodo.23626223](https://doi.org/10.5281/zenodo.23626223) (archived on Zenodo with every release). See [CITATION.cff](https://github.com/gotham29/gridshedwatch/blob/main/CITATION.cff). Code: MIT. Event list, timelines, documentation and results:
CC BY 4.0. EIA-930 data: U.S. public domain ([DATA_LICENSE.md](https://github.com/gotham29/gridshedwatch/blob/main/DATA_LICENSE.md)).
