Parameter sweeps¶
Solve one fault once per parameter combination and stack the results into
long-format frames that carry the parameters as columns. This is what the
statistics below operate on — until such a frame exists there is nothing to
summarise, because every accessor on Network reports a single solve.
rho_f_points builds the points from a catalogue of five-parameter rho-f
vectors, which is the form groundfield exports.
sweep ¶
Run one fault over a grid of parameter variations and collect it into one frame.
run_outage_study already answers "what changes when an element drops out".
This module answers the other half: what changes when a parameter moves --
the rho-f characteristic of the faulted station, the soil resistivity, the
harmonic content of the source, the fault location itself.
The unit of work is a :class:SweepPoint: a label plus the overrides that
define it. Every point is applied, solved and restored, and the results are
stacked into long-format Polars frames that carry the point's label and its
parameters as ordinary columns. That last part is the point of the module --
until a frame like this exists there is nothing for a statistic to operate on,
which is why :mod:groundinsight.analysis.statistics starts here.
Overrides are applied by writing directly onto Bus.impedance and friends,
which reaches the solver untouched because run_fault does not recompute
impedances (see :class:~groundinsight.electrical_network.ElectricalNetwork).
Every point's overrides are undone in a finally block, and the
network-level state the solves write -- stored results, active fault, path
set, assembled system -- is restored exactly when the sweep ends, however it
ends: a finished sweep, a failing point with on_error="raise", a
cancellation through should_cancel.
Example
Vary the rho-f characteristic of the faulted station over a grid and watch what it does to the potential rise and to the parallel impedances of the two feeder directions::
points = gi.rho_f_points(
bus="Station_7",
k_vectors={f"k1={k1:g}": (k1, 1e-4, 3e-4, 0.0, 0.0)
for k1 in (0.01, 0.02, 0.05, 0.1)},
frequencies=net.frequencies,
rho=100.0,
)
study = gi.run_sweep(
net, fault="F_Station_7", points=points,
cuts=[gi.Cut(name="left", branches=["C6_7"]),
gi.Cut(name="right", branches=["C7_8"])],
)
study.impedances() # Z_G and both reduction factors per point
study.cuts() # Z_left / Z_right / r_left / r_right per point
SweepPoint ¶
Bases: BaseModel
One parameter combination to solve.
Attributes:
| Name | Type | Description |
|---|---|---|
label |
str
|
Identifies the point in every result frame. Must be unique in a sweep. |
bus_impedance |
dict of str to dict of float to complex, optional
|
Impedance tables written straight onto |
bus_rho |
dict of str to float, optional
|
New |
fault |
(str, optional)
|
Solve a different fault at this point. Defaults to the sweep's fault. |
fault_scalings |
dict of float to float, optional
|
Replace the active fault's per-frequency scalings -- the harmonic content of the source. |
parameters |
dict of str to object, optional
|
Free-form values copied into every result row as columns, so a plot can be made against the physical parameter rather than against the label. |
Examples:
>>> import groundinsight as gi
>>> point = gi.SweepPoint(label="wet", bus_rho={"bus2": 30.0},
... parameters={"rho_Ohm_m": 30.0})
>>> point.label, point.bus_rho
('wet', {'bus2': 30.0})
SweepResult ¶
Bases: BaseModel
Everything a sweep collected, as long-format frames.
Attributes:
| Name | Type | Description |
|---|---|---|
fault |
str
|
The fault the sweep was run for (points may override it individually). |
labels |
list of str
|
Point labels in the order they were solved. |
failures |
dict of str to str
|
Points that raised, mapped to the exception text. They are absent from the frames; the sweep does not abort on one bad point. |
Examples:
>>> import groundinsight as gi
>>> from groundinsight.api.examples import build_minimal
>>> study = gi.run_sweep(build_minimal(), fault="fault",
... points=[gi.SweepPoint(label="base")])
>>> study.labels, study.failures
(['base'], {})
>>> study.buses().columns[:3]
['point', 'bus_name', 'fault']
branches ¶
Per-branch results of every point, stacked.
Returns:
| Type | Description |
|---|---|
DataFrame
|
The |
Source code in src/groundinsight/simulation/sweep.py
buses ¶
Per-bus results of every point, stacked.
Returns:
| Type | Description |
|---|---|
DataFrame
|
The |
Source code in src/groundinsight/simulation/sweep.py
cuts ¶
Side impedances and side reduction factors, stacked.
Empty when the sweep was run without cuts.
Returns:
| Type | Description |
|---|---|
DataFrame
|
The :meth: |
Source code in src/groundinsight/simulation/sweep.py
impedances ¶
Z_G and both reduction factors of every point, stacked.
Returns:
| Type | Description |
|---|---|
DataFrame
|
The |
Source code in src/groundinsight/simulation/sweep.py
rho_f_points ¶
rho_f_points(
*,
bus: str,
k_vectors: Dict[str, KVector],
frequencies: Sequence[float],
rho: float,
) -> List[SweepPoint]
Build sweep points from a catalogue of rho-f parameter vectors.
Each vector is evaluated into an impedance table for bus over
frequencies at the given rho, so the study varies the fitted
characteristic of one station while the rest of the network stays put.
k1 ... k5 and rho are copied into parameters, which puts
them in the result frames as plottable columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bus
|
str
|
Name of the bus whose characteristic is varied. |
required |
k_vectors
|
dict of str to tuple
|
Label to |
required |
frequencies
|
sequence of float
|
Frequencies to evaluate the form at -- normally |
required |
rho
|
float
|
Soil resistivity the form is evaluated at. |
required |
Returns:
| Type | Description |
|---|---|
list of SweepPoint
|
One point per catalogue entry, labelled with its key. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a vector produces a non-positive real part at any frequency, which the solver rejects as non-passive. The offending label and frequency are named, because an unconstrained least-squares fit can land there and the failure is otherwise reported far from its cause. |
Examples:
>>> import groundinsight as gi
>>> points = gi.rho_f_points(bus="bus3",
... k_vectors={"dry": (2.0, 0.0, 0.0, 0.0, 0.0)},
... frequencies=[50.0], rho=100.0)
>>> [p.label for p in points], sorted(points[0].bus_impedance)
(['dry'], ['bus3'])
Source code in src/groundinsight/simulation/sweep.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | |
run_sweep ¶
run_sweep(
network: Network,
*,
fault: str,
points: Sequence[SweepPoint],
cuts: Optional[Sequence[Cut]] = None,
phase_current_mode: str = "auto",
collect_branches: bool = False,
on_error: str = "record",
progress: Optional[
Callable[[int, int, str], None]
] = None,
should_cancel: Optional[Callable[[], bool]] = None,
) -> SweepResult
Solve one fault once per parameter point and stack the results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network
|
Network
|
The network. Left exactly as found, whatever happens: the point overrides are undone after every point, and the stored results, active fault, path set and assembled system are the ones it had before the sweep. |
required |
fault
|
str
|
Fault to solve, unless a point names its own. |
required |
points
|
sequence of SweepPoint
|
The parameter grid. Labels must be unique. |
required |
cuts
|
sequence of Cut
|
When given, :func: |
None
|
phase_current_mode
|
('auto', 'paths')
|
Forwarded to :func: |
"auto"
|
collect_branches
|
bool
|
Branch results multiply the row count by the number of branches and are rarely what a parameter study plots, so they are off by default. |
False
|
on_error
|
('record', 'raise')
|
|
"record"
|
progress
|
callable
|
|
None
|
should_cancel
|
callable
|
Asked before every point; a true answer raises
:class: |
None
|
Returns:
| Type | Description |
|---|---|
SweepResult
|
The stacked results of every point and the failures of the points that did not solve. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
TypeError
|
If |
StudyCancelled
|
If |
Examples:
>>> import polars as pl
>>> import groundinsight as gi
>>> from groundinsight.api.examples import build_minimal
>>> points = [gi.SweepPoint(label=f"Z={z}", bus_impedance={"bus3": {50.0: z}},
... parameters={"Z_bus3_Ohm": z}) for z in (0.5, 1.0, 2.0)]
>>> study = gi.run_sweep(build_minimal(), fault="fault", points=points)
>>> frame = study.buses().filter((pl.col("bus_name") == "bus3") & pl.col("is_rms"))
>>> [round(v, 2) for v in frame["EPR_V"]]
[11.73, 18.03, 24.28]
Source code in src/groundinsight/simulation/sweep.py
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 | |