Working with Cases#
This notebook covers the gpf data model: obtaining a network and navigating
its typed records. A small network is built in memory so that the notebook is
self-contained; in practice a case is parsed from a file with
GpfCase.from_raw, GpfCase.from_rawx, or GpfCase.from_matpower. Editing
a device by identity, validating, and writing the result back are each shown as
a recipe in Recipes.
import tempfile, pathlib
import gpf
from gpf import GpfCase, Bus, Generator, Load, Branch
case = GpfCase(
sbase=100.0,
buses=[
Bus(ibus=1, ide=3, vm=1.02, area=1, baskv=230.0), # slack
Bus(ibus=2, ide=2, vm=1.01, area=1, baskv=230.0), # PV
Bus(ibus=3, ide=1, vm=1.0, area=1, baskv=230.0),
Bus(ibus=4, ide=1, vm=1.0, area=1, baskv=230.0),
],
generators=[
Generator(ibus=1, machid="1", pg=0.0, vs=1.02, qb=-300, qt=300),
Generator(ibus=2, machid="1", pg=80.0, vs=1.01, qb=-150, qt=150),
],
loads=[Load(ibus=3, pl=120, ql=40), Load(ibus=4, pl=60, ql=20)],
branches=[
Branch(ibus=1, jbus=2, r=0.01, x=0.08),
Branch(ibus=2, jbus=3, r=0.01, x=0.08),
Branch(ibus=3, jbus=4, r=0.01, x=0.08),
Branch(ibus=1, jbus=3, r=0.01, x=0.10),
],
)
Editing, validating, and writing back#
Records are mutable and located by power-system identity, so a device is edited in place, the case is validated against the solver's capabilities, and the result is serialized back to a file. Each of these is shown as a recipe in Recipes.