Parameter sweeps and statistics¶
A single solve answers one question; a study asks it over a range — the soil
resistivity, the characteristic of an electrode, the harmonic content, the
fault location. This guide runs one fault over such a grid with
gi.run_sweep, stacks the results into one frame and reduces it with
gi.summarize and gi.classify. The script is
sweeps.py; its output is at the
end of the page.
The example is the 20 kV feeder of the
EN 50522 how-to: substation UW and five
stations bonded through the screens of a cable system, earth fault at S3,
1000 A at 50 Hz and 50 A at 250 Hz.
cable_system = gi.BranchType(
name="3x NA2XS(F)2Y 1x300RM/25 12/20 kV, trefoil",
grounding_conductor=True,
self_impedance_formula=(
"(0.727/3 + pi**2*1e-4*f + j*4*pi*1e-4*f*log(658*sqrt(rho/f)/0.03151272))*l"
),
mutual_impedance_formula=(
"(pi**2*1e-4*f + j*4*pi*1e-4*f*log(658*sqrt(rho/f)/0.03151272))*l"
),
)
substation = gi.BusType(name="substation", system_type="Substation", voltage_level=20.0,
impedance_formula="0.5")
station = gi.BusType(name="station", system_type="Station", voltage_level=20.0,
impedance_formula="2*rho/(3*1.13*sqrt(100.0))") # ring electrode
STATIONS = ["S1", "S2", "S3", "S4", "S5"]
FAULT_BUS = "S3"
net = gi.create_network(name="feeder", frequencies=[50.0, 250.0])
gi.create_bus(name="UW", type=substation, specific_earth_resistance=100.0, network=net)
for name in STATIONS:
gi.create_bus(name=name, type=station, specific_earth_resistance=100.0, network=net)
names = ["UW"] + STATIONS
for i, (a, b) in enumerate(zip(names[:-1], names[1:], strict=True), start=1):
gi.create_branch(name=f"K{i}", type=cable_system, from_bus=a, to_bus=b, length=1.2,
specific_earth_resistance=100.0, network=net)
gi.create_source(name="infeed", bus="UW", values={50.0: 1000.0, 250.0: 50.0}, network=net)
gi.create_fault(name="F", bus=FAULT_BUS, scalings={50.0: 1.0, 250.0: 1.0}, network=net)
before = net.model_dump_json()
One point per parameter combination¶
A gi.SweepPoint is a label plus the changes that define it:
| Field | Changes | Use it for |
|---|---|---|
bus_rho |
specific_earth_resistance of the named buses, with their bus-type formula evaluated again |
the soil around the electrodes |
bus_impedance |
the impedance table Bus.impedance of the named buses, written directly — the formula is bypassed |
a measured or fitted characteristic |
fault |
the fault solved at this point | the fault location |
fault_scalings |
the scalings of the fault for this point | the harmonic content |
parameters |
nothing — copied into every result row as columns | plotting against the physical parameter |
bus_rho changes the buses only: the specific_earth_resistance of the branches,
which enters the earth-return terms of a Carson-type cable formula, stays as
it is. To vary the soil along the cables as well, give the points a fault and
network of their own, or build one network per soil value.
RHO_VALUES = [30.0, 100.0, 300.0, 1000.0] # Ohm*m at the station electrodes
soil_points = [
gi.SweepPoint(label=f"rho={rho:g}", bus_rho={name: rho for name in STATIONS},
parameters={"rho_Ohm_m": rho})
for rho in RHO_VALUES
]
soil = gi.run_sweep(net, fault="F", points=soil_points)
gi.run_sweep(network, fault=..., points=...) solves the fault once per
point, undoes the point's changes after the solve, and when it ends — finished,
failed or cancelled — the network is left as it was: same stored results,
same active fault, same paths (the script checks it with model_dump_json()).
on_error decides what a failing point does: with "record" (the default) it is noted in
SweepResult.failures with its message and the sweep goes on; with
"raise" the first failure ends it. progress= and
should_cancel= report and stop a long sweep.
A catalogue of rho-f characteristics¶
gi.rho_f_points turns a catalogue of five-parameter rho-f vectors — the
form \(Z = k_1\rho + (k_2 + jk_3)f + (k_4 + jk_5)\rho f\) that groundfield
exports — into points that set the impedance table of one bus. It refuses a
vector whose real part is not positive at some frequency, naming the label
and the frequency, because the solver would reject it anyway.
K_VECTORS = { # Z = k1*rho + (k2 + j*k3)*f + (k4 + j*k5)*rho*f, illustrative fits
"small electrode": (0.10, 0.0, 2e-4, 0.0, 1e-6),
"ring electrode": (0.059, 0.0, 2e-4, 0.0, 1e-6),
"meshed grid": (0.02, 0.0, 2e-4, 0.0, 1e-6),
}
characteristic = gi.run_sweep(net, fault="F", points=gi.rho_f_points(
bus=FAULT_BUS, k_vectors=K_VECTORS, frequencies=net.frequencies, rho=100.0))
Reading the results¶
SweepResult.buses(), .branches() (only with collect_branches=True),
.impedances() and .cuts() (only with cuts=) stack the frames of the
points: the columns of res_buses, res_branches, res_all_impedances or
CutAnalysis.to_polars, preceded by point (the label) and one column per
key of parameters; rho_f_points adds bus, rho_Ohm_m and k1 … k5.
The RMS rows have is_rms true, as in a single solve. Columns:
Result tables.
Summarise and classify¶
summarize — gi.summarize(frame, value, by=...) — reduces one column to n, n_null,
n_nan, mean, std, min, quantiles (p05, p50, p95 by default) and
max, per group of by=. Read n_nan first: a failed point recorded as NaN
propagates into the mean and the quantiles. classify —
gi.classify(frame, value, edges, labels=...) — adds a column with the band of each row; a null or NaN value gets
no band rather than the highest one.
Neither function knows a limit. The permissible values of EN 50522 depend on the fault duration, the edition and the measures taken, so the edges come from your study — Compare results with EN 50522 limits shows where they come from. The bands below are illustrative.
stacked = pl.concat([soil.buses(), characteristic.buses()], how="diagonal")
fault_bus_rms = stacked.filter((pl.col("bus_name") == FAULT_BUS) & pl.col("is_rms"))
summary = gi.summarize(fault_bus_rms, "EPR_V")
EDGES_V = [300.0, 600.0] # bands of your study -- not limits of a standard
LABELS = ["up to 300 V", "300 V to 600 V", "above 600 V"]
classes = gi.classify(fault_bus_rms, "EPR_V", EDGES_V, labels=LABELS)
Output¶
point U_E RMS / V class
rho=30 200.7 up to 300 V
rho=100 384.6 300 V to 600 V
rho=300 622.8 above 600 V
rho=1000 788.8 above 600 V
small electrode 414.1 300 V to 600 V
ring electrode 384.5 300 V to 600 V
meshed grid 283.1 up to 300 V
n = 7, min = 200.7 V, median = 384.6 V, max = 788.8 V
network unchanged: True
U_E RMS is the total RMS of the earth potential rise of S3 over 50 Hz and
250 Hz. The point rho=100 reproduces the worked example of the EN 50522
how-to (384.6 V); ring electrode describes the same electrode by its rho-f
fit and differs only by the small reactance the fit carries. The test suite
recomputes every point with the independent reference solver of the tests,
with the station impedances evaluated from the formulas.