Postprocess¶
The postprocess package turns a FieldResult into engineering
quantities: potentials and their plots, touch and step voltages with the
EN 50522 limits, the current sharing between electrodes and conductors,
parameter sweeps and convergence studies, and the reduced rho-f models
that are exported to groundinsight. Every function is available at the
top level (gf.touch_voltage) and in the namespaces gf.plot,
gf.safety and gf.fit.
Mathematical and physical context¶
Potentials. After the solve the leakage currents \(I_k\) of the segments are known, and the potential anywhere in or on the soil is the superposition \(\varphi(\mathbf{r}) = \sum_k G(\mathbf{r}, \mathbf{r}_k)\,I_k\) with the Green's function of the soil (homogeneous or two-layer).
Touch and step voltage (EN 50522:2022, IEC 61936-1). A person touches an accessible conductive part at the potential \(U_\text{part}\) of the earthing system it is bonded to and stands on the surface 1 m away from it (EN 50522's conventional position):
touch_voltage_at_part evaluates \(U_T\) at a touch point, an accessible
metal part above ground (a station housing or door, a mast, a fence
post, a service connection box): the feet stand on the circle of radius
\(d\) (default 1 m) around the part, optionally only in given directions
or outside the outlines where nobody can stand, and \(U_\text{part}\) is
the potential of the electrode or junction the part is bonded to — a
PEN junction at a house gives the transferred potential. Where the
parts are not known, touch_voltage and touch_voltage_envelope take
the electrode itself as the touched part, \(U_\text{part} = U_E =
\varphi_\text{cluster}\), with the feet at distance \(d\) from its
footprint, the horizontal projection of its wires; the envelope walks
all around it. It samples nothing inside the footprint by default (there
stands the station, the house, the steel structure or the mast); for
open-air grids such as a substation yard, interior="meshes" adds the
centres of the meshes (the analogue of the IEEE 80 mesh voltage) and of
a ring, interior=True also the inside of closed polylines.
permissible_touch_voltage_en50522(t_f) follows Figure 8 / Table B.4 of
EN 50522:2022 up to 10 s and returns 80 V for every \(t_f > 10\) s,
including an uncleared fault (math.inf), the value the standard allows
for current-flow durations considerably longer than 10 s;
permissible_prospective_touch_voltage_en50522 adds the body and
footwear resistances of Annex B.4. For a fault current with harmonics,
touch_voltage_spectrum returns the true-RMS value
\(U_{T,\text{rms}} = \sqrt{\sum_k \lvert U_{T,k}\rvert^2}\) over the
frequencies of the spectrum.
Current sharing. cluster_current_balance and
electrode_current_table list the current every cluster and electrode
leaks into the soil; split_factor is the share of a source current
that leaves through the soil at the feeding cluster (the rest flows
away through conductors). The inductive reduction factor of cable
screens is not computed here.
Reduced models. The quantity a reduced model describes is selected
with quantity= ("input", the default, "cluster" or "electrode",
see the quickstart). Two families:
- vector fitting (Gustavsen and Semlyen 1999) of a rational function in \(s = j\omega\) at a fixed soil, \(Z(s) \approx R_\infty + sL_\infty + \sum_k r_k/(s - p_k)\), with a passivity check (\(\operatorname{Re}Z \ge 0\)) before export;
- the standard form fitted over a \(\rho\) and \(f\) sweep (for layered soil \(\rho\) is the effective resistivity of each solved soil, see Soil),
$$ Z(\rho, f) = k_0 + k_1\rho + (k_2 + jk_3)\,f + (k_4 + jk_5)\,f\rho , $$
with relative weights by default; max_relative is the quality figure
to check (a fit above 5 % warns with RhoFStandardQualityWarning).
Validity. Quasi-static range \(f < 1\,\mathrm{kHz}\). The image family
assumes a uniform current per unit length on each straight wire of an
electrode (user decision Q30): near grids,
meshes, stars, strip ends and bonded multi-electrode clusters its surface
potentials are impedance-grade, not field-grade, and the safety helpers
warn with UniformCurrentFieldWarning (re-solve with backend="mom" for
field-grade values). FieldResult.potential and everything built on it
support homogeneous and two-layer soil only.
Example¶
A ring earth carrying a fault current of 100 A at 50 Hz, the touch voltage 1 m outside its footprint, checked against a second backend and against the EN 50522 limit for a fault cleared in 0.5 s:
import groundfield as gf
world = gf.create_world(soil=gf.TwoLayerSoil(rho_1=100.0, rho_2=300.0, h_1=2.0))
gf.create_electrode(world, "ring", name="g1", center=(0.0, 0.0, 0.8), radius=3.0)
gf.create_source(world, attached_to="g1", magnitude=100.0)
result = gf.create_engine(frequencies=[50.0]).solve(world)
U_E = result.electrode_potentials["g1"][0] # 1381 V
U_T = gf.touch_voltage(result, world, electrode="g1", distance=1.0) # 525 V
U_S = gf.step_voltage(result, position=(3.0, 0.0, 0.0), direction=(1.0, 0.0, 0.0), world=world)
U_Tp = gf.permissible_touch_voltage_en50522(0.5) # 225 V (Table B.4)
mom = gf.create_engine(backend="mom", frequencies=[50.0]).solve(world)
U_T_mom = gf.touch_voltage(mom, world, electrode="g1", distance=1.0) # 517 V
assert abs(U_E - 1380.9) < 0.5 and abs(U_T - 525.3) < 0.5
assert abs(U_T - U_T_mom) / abs(U_T) < 0.02 # ring: both current ansätze agree
assert U_Tp == 225.0 and abs(U_T) > U_Tp # this earth needs a closer look
assert 0 < U_S.real < U_T.real
The how-to guide Assess touch voltages
and tutorial T08 show the complete assessment (touch points, transferred
potential, envelope, prospective touch voltage, spectrum); tutorial T04
the frequency response and the rho-f fits.
Safety (touch and step voltage)¶
safety ¶
Touch and step voltages for grounding-system safety assessment.
This module turns a groundfield.solver.result.FieldResult into
the engineering quantities used in the grounding-system safety
verification according to EN 50522:2022 (DIN EN 50522 (VDE 0101-2):
2023-10) / IEC 61936-1: the touch voltage \(U_T\) and the
step voltage \(U_S\). It also provides the permissible
values \(U_{Tp}(t_f)\) of EN 50522:2022, Table B.4 (the curve of
Figure 8), the permissible prospective (open-circuit) touch voltage
\(U_{vTp}\) of Annex B.4, and the true-RMS touch voltage over a
fault-current spectrum.
Mathematical / physical content
A grounding cluster at earth potential rise
is connected — through any galvanically bonded metallic part — to whatever a person can touch. Standing on the soil surface 1 m away from the touched part (the conventional position of EN 50522), the person's feet sit at the surface potential \(\varphi(\mathbf{r}_\text{feet})\). The prospective touch voltage is
The touched parts are the accessible metal parts above ground: a
station housing or its door, a mast, a fence, a service connection box.
touch_voltage_at_part() takes such a part as a touch point — its
horizontal position and the electrode or junction it is bonded to — and
puts the feet on the circle of radius distance around it, optionally
only in given directions or outside the outlines where nobody can stand
(the housing or building itself). A part bonded to a node far from the
faulted earth, for example to a PEN junction at a house, carries a
transferred potential.
Where the parts are not known, touch_voltage() and
touch_voltage_envelope() use the electrode itself: since review
pass 10 (10.21) the metre is measured from its footprint — the
horizontal projection of its wires — not from its connection point; the
feet stand distance metres from the nearest wire, on the side given
by direction (seen from the length-weighted centroid of the wires).
The envelope does not sample the inside of the footprint by default,
because there stands the station, the house, the steel structure or the
mast. Over an open-air grid such as a substation yard people do walk
inside the loops, where the surface potential sags:
interior="meshes" adds the mesh centres of grids and the centre of a
ring, the analogue of the IEEE Std 80 mesh voltage, and
interior=True also the inside of a closed polyline.
For a step voltage the body bridges two surface points at the typical step distance \(d_\text{step} = 1\,\mathrm{m}\):
Both quantities are returned as complex phasors per frequency
index — consistent with the rest of groundfield — so that
inductive- and resistive-coupling effects above DC remain
visible.
Validity envelope
- Frequency: quasi-static envelope \(f \le 1\,\mathrm{kHz}\), inherited from the underlying Green's function.
- Current ansatz: the
imagefamily (image,image_2layer,image_nlayer,cim) solves one uniform current per straight wire of an electrode (a wire line of a grid, an arm of a star, a straight run of a polyline, user decision Q30 of 2026.11; a rod, a strip or a ring is one wire). Impedances are fine, but near grids, meshes, stars, strip ends and bonded multi-electrode clusters the surface potential is impedance-grade, not field-grade. Measured against the per-segmentmombackend (homogeneous 100 Ω·m,segment_length0.5 m) with the default line kernel, touch voltage with the feet 1 m outside the footprint and step voltage from 1 m to 2 m outside it: 20 m × 20 m grid with 4 × 4 meshes at the corner, touch +6 %, step −8 % (non-conservative; the step from the point above the corner 1 m outwards is −11 %; one current per grid, up to then, gave +20 % / −21 % / −28 %); 4-arm star (5 m arms) beyond a tip touch +8 %, step −9 %; 10 m strip beyond its end step −6 %; single rings, rods and closed rectangular loops within 2 %. A bonded cluster of a foundation mesh and a bare ring 1 m outside it reads +5 … +16 % with the feet right above the ring (example E02; the warning below fires for it, usemom). The point kernel, whichmomshares, isolates the ansatz: grid +5 % / −8 % (−11 % from above the corner), star +7 % / −10 %, strip −7 %, rings, rods and loops within 1 %. The helpers emitUniformCurrentFieldWarningonce per call when a uniform-current result is evaluated withinNEAR_FIELD_DISTANCE_Mof such an electrode; re-solve withbackend="mom"for field-grade values. - Coordinate convention: the soil surface is at \(z = 0\),
positive \(z\) points downwards into the soil (see
groundfield.geometry.electrodes). The defaultsurface_z = 0.0therefore models bare-foot contact at the ground surface. permissible_touch_voltage_en50522()interpolates EN 50522:2022, Table B.4 (the curve of Figure 8) for fault durations \(50\,\mathrm{ms} \le t_f \le 10\,\mathrm{s}\), clamps to 725 V below 50 ms and returns 80 V for every \(t_f > 10\,\mathrm{s}\) including an uncleared fault (the value the standard allows for current-flow durations considerably longer than 10 s).
References
- EN 50522:2022 — Earthing of power installations exceeding 1 kV a.c., Annex B (Table B.1 body current, Table B.4 permissible touch voltage, B.4 prospective touch voltage). German edition DIN EN 50522 (VDE 0101-2):2023-10.
- IEC 60479-1:2018 — Effects of current on human beings and livestock (curve c2, body impedance).
- IEC 61936-1:2021 — Power installations exceeding 1 kV a.c.
- IEEE Std 80-2013 — Guide for safety in AC substation grounding.
NEAR_FIELD_DISTANCE_M
module-attribute
¶
Distance in m within which the safety helpers warn about uniform currents.
Horizontal distance from a crowding electrode within which the safety
helpers warn about uniform-current results (10.22). At 5 m from
the footprint the measured touch / step deviations of the uniform
ansatz against mom are at most 4 % for strips, bonded clusters and
grids (2.5 % for a 20 m grid with 4 × 4 meshes since user decision Q30,
8 % with one current per grid before) and 6.5 % for a 4-arm star
(default line kernel; with the point kernel 5 % for the star).
UniformCurrentFieldWarning ¶
Bases: UserWarning
Field quantity from a uniform-current backend near a crowding geometry.
The image family assigns one uniform current density to every
straight wire of an electrode (user decision Q30 of 2026.11). Near
grids, meshes, stars, strip ends and bonded
multi-electrode clusters the true current crowds to edges, corners and
tips, so touch and step voltages computed there are impedance-grade
(review pass 10, 10.22; see the module docstring for measured
deviations). Re-solve with backend="mom" for field-grade values,
or silence the category with
warnings.simplefilter("ignore", UniformCurrentFieldWarning).
permissible_prospective_touch_voltage_en50522 ¶
permissible_prospective_touch_voltage_en50522(t_f: float, *, R_H: float = 0.0, R_F1: float = 0.0, rho_s: float | None = None, HF: float = 1.0) -> float
Permissible prospective touch voltage \(U_{vTp}\) (EN 50522:2022, B.4).
The prospective (open-circuit) touch voltage may exceed the permissible touch voltage across the body by the drop of the body current over the additional resistances (equivalent circuit of Figure B.2, Equation (A.3) of the standard):
with \(U_{Tp}\) from permissible_touch_voltage_en50522()
(Table B.4 up to 10 s, 80 V beyond) and the permissible body current
\(I_B(t_f)\) of Table B.1 (0.05 s: 900 mA, 0.1 s: 800 mA,
0.2 s: 600 mA, 0.5 s: 200 mA, 1 s: 80 mA, 2 s: 60 mA, 5 s: 51 mA,
10 s: 50 mA; interpolated log-log, 900 mA below 50 ms, and held at
50 mA beyond 10 s).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t_f
|
float
|
Fault duration in s, |
required |
R_H
|
float
|
Hand resistance (e.g. gloves) in Ω, |
0.0
|
R_F1
|
float
|
Resistance of the footwear in Ω, |
0.0
|
rho_s
|
float | None
|
Resistivity of the surface layer at the standing position in
Ω·m; |
None
|
HF
|
float
|
Heart-current factor of the current path, |
1.0
|
Returns:
| Type | Description |
|---|---|
float
|
Permissible prospective touch voltage \(U_{vTp}\) in V. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a resistance or |
Examples:
Figure B.3 of the standard, 0.5 s, no footwear, 500 Ω·m gravel (\(R_F = 750\,\Omega\)): 225 V + 0.2 A · 750 Ω = 375 V.
An earth fault that is not cleared, 1000 Ω shoes: 80 V + 0.05 A · 1000 Ω = 130 V.
Source code in src/groundfield/postprocess/safety.py
1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 | |
permissible_touch_voltage_en50522 ¶
Permissible touch voltage \(U_{Tp}(t_f)\) per EN 50522:2022.
Returns the maximum admissible touch voltage as a function of the fault duration \(t_f\). Up to 10 s it follows the curve of Figure 8 in its tabulated form, Table B.4 (DIN EN 50522 (VDE 0101-2):2023-10),
in s and V (rounded to 5 V in the standard), interpolated linearly in \(\log t\)–\(\log U\) between the anchors and clamped to 725 V below 50 ms. Beyond the end of the curve,
including an earth fault that is not cleared (math.inf).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t_clear_s
|
float
|
Fault duration \(t_f\) in s, |
required |
Returns:
| Type | Description |
|---|---|
float
|
Permissible touch voltage \(U_{Tp}\) in V. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Notes
Where the values come from in EN 50522:2022:
- 5.4.1, Figure 8: \(U_{Tp}\) as a function of the fault duration; Annex B, B.3, Table B.4: the values of that curve from 0.05 s to 10 s. The curve is not defined beyond 10 s.
- The note to Figure 8 (5.4.1) and the paragraph after Table B.4 (B.3): for a current-flow duration considerably longer than 10 s, 80 V may be used as the permissible touch voltage.
- 5.4.1 assumes that every earth fault is cleared, automatically or by hand, so that no touch voltage of very long or unlimited duration occurs. A resonant-earthed network can carry its earth fault for hours, which is where the 80 V value matters.
The helper uses 80 V for every \(t_f > 10\,\mathrm{s}\) instead
of continuing the 85 V end value of Table B.4: 80 V is below 85 V,
on the safe side where the curve gives no value. Hence the step from
85 V at 10 s to 80 V just above. Up to the 2026.11 development
snapshots an opt-in keyword selected the 80 V and the default
returned 85 V; v0.15.0 returned 85 V and rejected math.inf.
Review pass 10 (10.42) checked the anchors against the standard
text: they are the published values. A secondary reproduction quoted
in the review (716 / 654 / 537 / 220 / 117 / 96 / 86 / 85 V) does not
match EN 50522:2022. Compare the value with touch_voltage(),
touch_voltage_at_part() or touch_voltage_envelope()
(or, with additional resistances, use
permissible_prospective_touch_voltage_en50522()).
Source code in src/groundfield/postprocess/safety.py
1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 | |
step_voltage ¶
step_voltage(result: 'FieldResult', *, position: tuple[float, float, float], direction: tuple[float, float, float] = (1.0, 0.0, 0.0), step: float = 1.0, surface_z: float | None = None, frequency_index: int = 0, world: 'World | None' = None) -> complex
Step voltage between two surface points.
Evaluates \(U_S = \varphi(\mathbf{r}_1) - \varphi(\mathbf{r}_1 + d_\text{step}\,\hat{\mathbf{e}})\) on the soil surface.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
'FieldResult'
|
Solver output. |
required |
position
|
tuple[float, float, float]
|
First foot position \((x, y, z)\) in m. The \(z\)
coordinate is overridden by |
required |
direction
|
tuple[float, float, float]
|
Step direction in world coordinates. The horizontal projection is used (the \(z\) component is ignored — both feet stay on the same surface). |
(1.0, 0.0, 0.0)
|
step
|
float
|
Step length \(d_\text{step}\) in m. EN 50522 uses |
1.0
|
surface_z
|
float | None
|
Optional explicit surface \(z\) in m. |
None
|
frequency_index
|
int
|
Index into |
0
|
world
|
'World | None'
|
Optional companion world. Only used to decide whether to emit
|
None
|
Returns:
| Type | Description |
|---|---|
complex
|
Phasor \(U_S(f)\) in V. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Warns:
| Type | Description |
|---|---|
UniformCurrentFieldWarning
|
Once per call, see the module docstring. At the corner of a 20 m × 20 m grid the uniform-current ansatz under-estimates the step voltage by 21 % (feet 1 m and 2 m outside the corner) to 28 % (feet above the corner and 1 m outside), with either kernel. |
Source code in src/groundfield/postprocess/safety.py
869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 | |
touch_voltage ¶
touch_voltage(result: 'FieldResult', world: 'World', *, electrode: str, distance: float = 1.0, direction: tuple[float, float, float] = (1.0, 0.0, 0.0), surface_z: float = 0.0, frequency_index: int = 0, anchor: Anchor = 'footprint') -> complex
Touch voltage at a single point on the soil surface.
Evaluates \(U_T = U_E - \varphi(\mathbf{r}_\text{feet})\),
where \(U_E\) is the cluster potential of the touched electrode.
With the default anchor="footprint" the feet stand distance
metres (horizontally) from the nearest wire of the electrode, on the
ray that leaves the electrode's footprint in the horizontal
projection of direction: 1 m outside the edge of a grid, 1 m
beyond the tip of a star arm, 1 m outside a ring on either side.
This is a proxy for an unknown touched part; for a known accessible
metal part use touch_voltage_at_part().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
'FieldResult'
|
Solver output from |
required |
world
|
'World'
|
Companion world used to resolve the electrode geometry. |
required |
electrode
|
str
|
Name of the touched electrode. Its cluster potential is the EPR seen by the hand. |
required |
distance
|
float
|
Horizontal distance between the touched part and the feet,
in m. EN 50522 uses |
1.0
|
direction
|
tuple[float, float, float]
|
Side of the electrode on which the person stands, in world
coordinates, seen from the length-weighted centroid of the wires.
Only the horizontal projection is used (the feet stay on the
surface). Defaults to |
(1.0, 0.0, 0.0)
|
surface_z
|
float
|
\(z\) coordinate of the soil surface in m. Default |
0.0
|
frequency_index
|
int
|
Index into |
0
|
anchor
|
Anchor
|
|
'footprint'
|
Returns:
| Type | Description |
|---|---|
complex
|
Phasor \(U_T(f) = U_E(f) - \varphi(\mathbf{r}_\text{feet}, f)\) in V. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If |
ValueError
|
If |
Warns:
| Type | Description |
|---|---|
UniformCurrentFieldWarning
|
Once per call, for a uniform-current result evaluated near a crowding geometry (see the module docstring). |
Notes
Up to v0.15.0 the metre was measured from the connection point, so
for a 20 m × 20 m grid (4 × 4 meshes, 100 A, 100 Ω·m) the feet stood
above the grid and the helper reported 9.92 V where 1 m outside the
edge has 61.3 V (default line kernel; 60.0 V with the point kernel,
61.6 V per segment with mom; 69.6 V with one current over the
whole grid, before user decision Q30; F13 / 10.21).
Source code in src/groundfield/postprocess/safety.py
449 450 451 452 453 454 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 | |
touch_voltage_at_part ¶
touch_voltage_at_part(result: 'FieldResult', world: 'World | None' = None, *, position: Sequence[float], bonded_to: str, distance: float = 1.0, n_angles: int | None = None, directions: 'Sequence[Sequence[float]] | None' = None, exclude: 'Sequence[Sequence[Sequence[float]]] | None' = None, surface_z: float = 0.0, frequency_index: int = 0, return_points: bool = False) -> tuple[np.ndarray, np.ndarray] | tuple[np.ndarray, np.ndarray, np.ndarray]
Touch voltage of an accessible metal part, feet distance around it.
EN 50522 defines the touch voltage between a conductive part that a
person touches and the person's feet, standing 1 m away from the
part. The touch points of an installation are its accessible metal
parts above ground — a station housing or its door, a mast, a fence
post, a cable cabinet, a service connection box — not the buried
electrode. This helper takes one such part: its horizontal position
\(\mathbf p\) and the electrode or junction it is bonded to,
whose potential \(U_\text{part}\) it carries. The feet stand on
the circle of radius \(d\) = distance around the part,
at n_angles equally spaced azimuths
\(\theta_k = 2\pi k / n\), or only in the given directions;
foot positions inside an outline of exclude (the housing or the
building itself, where nobody can stand) are dropped. A part bonded
to a node far from the faulted earth — a service connection box on the
PEN junction of a house, a cable screen led out of a station —
carries a transferred potential; U_T is then most of the earth
potential rise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
'FieldResult'
|
Solver output from |
required |
world
|
'World | None'
|
Optional companion world. Only used to decide whether to emit
|
None
|
position
|
Sequence[float]
|
Horizontal position |
required |
bonded_to
|
str
|
Name of the electrode or junction ( |
required |
distance
|
float
|
Horizontal distance between the part and the feet in m, |
1.0
|
n_angles
|
int | None
|
Number of equally spaced foot positions on the circle, |
None
|
directions
|
'Sequence[Sequence[float]] | None'
|
Only these horizontal directions (2- or 3-vectors, the |
None
|
exclude
|
'Sequence[Sequence[Sequence[float]]] | None'
|
Outlines where nobody can stand, each a polygon of vertices
|
None
|
surface_z
|
float
|
\(z\) coordinate of the soil surface in m. Default |
0.0
|
frequency_index
|
int
|
Index into |
0
|
return_points
|
bool
|
Also return the foot positions. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
angles |
(ndarray, shape(n))
|
Azimuth in radians in \([0, 2\pi)\) of each remaining foot
position, seen from the part and measured from |
voltages |
np.ndarray, shape (n,), dtype complex
|
Touch-voltage phasor \(U_T\) in V at every foot position. |
points |
(ndarray, shape(n, 3))
|
Foot positions in m; only with |
Raises:
| Type | Description |
|---|---|
KeyError
|
If |
IndexError
|
If |
ValueError
|
If |
Warns:
| Type | Description |
|---|---|
UniformCurrentFieldWarning
|
Once per call, for a uniform-current result evaluated near a crowding geometry (see the module docstring). |
Notes
For a part on a wire of the electrode with the feet pointing away
from it, the foot position is the one of touch_voltage() and so
is the value. The voltage is the prospective (open-circuit) touch
voltage; compare its magnitude with
permissible_touch_voltage_en50522(), or with
permissible_prospective_touch_voltage_en50522() when footwear or
a surface layer adds resistance.
Source code in src/groundfield/postprocess/safety.py
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 | |
touch_voltage_envelope ¶
touch_voltage_envelope(result: 'FieldResult', world: 'World', *, electrode: str, distance: float = 1.0, n_angles: int = 24, surface_z: float = 0.0, frequency_index: int = 0, anchor: Anchor = 'footprint', interior: Interior = False, corners: bool = True, return_points: bool = False) -> tuple[np.ndarray, np.ndarray] | tuple[np.ndarray, np.ndarray, np.ndarray]
Touch voltages around an electrode, on request also inside its loops.
Walks n_angles equally spaced directions and places the feet as
in touch_voltage(): with anchor="footprint" this traces
the curve at distance from the electrode's wires (rounded around
corners and arm tips). Equally spaced directions hit the rounded
corners only by chance, and the touch voltage is largest there: the
corners of a 60 m × 40 m grid lie at 33.7° from its centre, between
the 30° and 45° rays of the default 24, and that envelope read 12 …
28 % low in two-layer soil (case study E03). With corners=True
(the default) the feet also stand on the arc around every corner of
the convex hull of the wires, nine per corner. The maximum of |U_T| is the conservative
envelope used in safety verification when the touched parts are not
known; where they are, touch_voltage_at_part() puts the feet
around each part.
By default nothing inside the footprint is sampled: there stands the
station, the house, the steel structure or the mast. Over an open-air
grid such as a substation yard people walk inside the loops, and the
surface potential sags there, so the touch voltage can exceed every
value on the offset curve (a 20 m × 20 m perimeter loop at 0.5 m
depth, 100 Ω·m, 100 A: 158 V in the centre against at most 141 V
1 m outside). For such grids interior="meshes" also evaluates the
centre of every closed mesh, the analogue of the mesh voltage of
IEEE Std 80 (the worst touch voltage inside a mesh of a grid, near
the mesh centre).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
'FieldResult'
|
See |
required |
world
|
'FieldResult'
|
See |
required |
electrode
|
str
|
Name of the touched electrode. |
required |
distance
|
float
|
Horizontal distance from the wires in m (1.0 by EN 50522). |
1.0
|
n_angles
|
int
|
Number of equally spaced directions
\(\theta_k = 2\pi k / n\) with \(k = 0, \dots, n - 1\).
Must be |
24
|
surface_z
|
float
|
See |
0.0
|
frequency_index
|
float
|
See |
0.0
|
anchor
|
float
|
See |
0.0
|
interior
|
Interior
|
Which closed loops are also sampled inside (review pass 10, 10.21).
|
False
|
corners
|
bool
|
With |
True
|
return_points
|
bool
|
Also return the foot positions. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
angles |
(ndarray, shape(n))
|
Azimuth in radians of each foot position, measured from |
voltages |
np.ndarray, shape (n,), dtype complex
|
Touch-voltage phasor \(U_T\) in V at every foot position. |
points |
(ndarray, shape(n, 3))
|
Foot positions in m; only with |
Raises:
| Type | Description |
|---|---|
ValueError
|
For |
Warns:
| Type | Description |
|---|---|
UniformCurrentFieldWarning
|
Once per call, for a uniform-current result evaluated near a crowding geometry (see the module docstring). |
Notes
n = n_angles plus the number of interior points and of corner
points. The rule of
v0.15.0 (circle around the connection point) is
anchor="connection_point"; for a generated rectangular foundation
that connection point is a corner since 2026.11, no longer the centre
(see anchor in touch_voltage()). During the 2026.11 development the
mesh sampling was the default (interior=None); it is now the
explicit interior="meshes".
Source code in src/groundfield/postprocess/safety.py
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 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 | |
touch_voltage_spectrum ¶
touch_voltage_spectrum(result: 'FieldResult | Sequence[FieldResult]', world: 'World', *, electrode: str, currents: 'Sequence[complex] | Mapping[float, complex]', distance: float = 1.0, direction: tuple[float, float, float] = (1.0, 0.0, 0.0), surface_z: float = 0.0, anchor: Anchor = 'footprint', source: str | None = None) -> float
True-RMS touch voltage of a fault-current spectrum at one position.
The field problem is linear, so the touch voltage of harmonic
\(k\) scales with the fault current \(I_k\) of that
harmonic. With \(U_T(f_k)\) from a solve with source current
\(I_\text{src}(f_k)\), the touch voltage at the fixed foot
position of touch_voltage() is
the RMS value of the superposed harmonics (they are orthogonal over a period).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
'FieldResult | Sequence[FieldResult]'
|
One multi-frequency result, or a sequence of results whose frequencies are taken in order (for example one result per harmonic). |
required |
world
|
'World'
|
Companion world (geometry of the touched electrode). |
required |
electrode
|
str
|
Name of the touched electrode. |
required |
currents
|
'Sequence[complex] | Mapping[float, complex]'
|
Fault current per frequency as RMS phasors (or RMS magnitudes)
in A: either a sequence aligned with the frequencies of
|
required |
distance
|
float
|
Foot position, see |
1.0
|
direction
|
float
|
Foot position, see |
1.0
|
surface_z
|
float
|
Foot position, see |
1.0
|
anchor
|
float
|
Foot position, see |
1.0
|
source
|
str | None
|
Name of the current or voltage source the results were solved with (the denominator is its impressed or solved current); may be omitted when there is exactly one. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
RMS touch voltage \(U_{T,\text{rms}}\) in V. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the currents do not match the frequencies, are not finite, a frequency appears in more than one result (it would be counted twice), a result carries no source snapshot or no source current per frequency (a voltage record without its solved current), or the source current is zero at some frequency. |
Notes
EN 50522's permissible touch voltage is a 50 Hz curve; comparing a spectrum RMS with \(U_{Tp}\) ignores the frequency factors of IEC 60479-2 (the body tolerates more current at higher frequencies), which is conservative.
Source code in src/groundfield/postprocess/safety.py
991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 | |
Current sharing¶
current_balance ¶
Current sharing and split-factor analysis for a FieldResult.
This module turns the per-electrode currents stored in
groundfield.solver.result.FieldResult into the engineering
quantities that answer "where does the injected source current
actually return?". In a TN-Ortsnetz with
hundreds of houses, dozens of cable cabinets and one or more
metallic return paths (PEN trunk, measurement leads, cable
shields), the soil-leakage current of every cluster matters and
cannot be read off electrode_currents directly without aggregation.
Quantities
- Per-cluster soil leakage
\(I_{c} = \sum_{e \in c} I_e\). With ideal galvanic
bonds (
cross_section=None) the cluster members share a potential \(U_c\); the cluster impedance is then \(Z_c = U_c / I_c\). Returned as a tabular summary bycluster_current_balance(). - Per-electrode share of cluster current — what fraction of
the cluster's net soil leakage flows through this specific
electrode:
\(s_{e \mid c} = I_e / I_c\) (complex). Returned alongside
the per-electrode potential / impedance by
electrode_current_table(). - Split factor
\(s = I_{c_\text{src}} / I_\text{src} = \sum_{e \in c_\text{src}} I_e / I_\text{src}\),
with \(c_\text{src}\) the cluster of the source's
attached_toelectrode.s = 1means the injected current leaves the source cluster entirely through the soil (no metallic short-cut to the return-path cluster).s < 1means a metallic conductor (PEN trunk, parallel measurement lead, cable shield) carries part of the current as a parallel resistive path.
This is the galvanic current-split between parallel paths.
It is not the Reduktionsfaktor in the German EVU /
Schirmtechnik sense (Oeding & Oswald 2016): that latter
quantity is the additional transformatorische / inductive
coupling correction between a current-carrying conductor and
a parallel grounding / shield conductor. The Reduktionsfaktor
vanishes when the two conductors are perpendicular (no flux
linkage) but the split factor still applies — the current
always splits among parallel resistive paths irrespective of
the geometric angle. A future helper may add the proper
Reduktionsfaktor based on the Neumann mutual-inductance / Carson
/ Sommerfeld backends already present in groundfield.coupling.
Validity envelope
- Frequency: quasi-static envelope \(f \le 1\,\mathrm{kHz}\).
- Conventions:
FieldResult.electrode_currentscarries the per-electrode soil-leakage current in A (complex phasor), with positive sign in the direction electrode → soil. All quantities here are complex perfrequency_index. - Cluster discovery uses
FieldResult.clusters— the same map produced by every backend.
Which impedance (review pass 10, 10.18)
The Z columns of cluster_current_balance() are cluster
impedances — a cluster's potential over its own soil leakage — and
those of electrode_current_table() are electrode impedances
\(U_e / I_e\). Neither is the input impedance a source sees
(FieldResult.input_impedance(), the default quantity of
groundfield.postprocess.sweep.sweep() and of the rho-f exporters).
For one current source returning through remote earth the split factor
links them: \(Z_\text{in} = s\,Z_c\).
cluster_current_balance ¶
Per-cluster soil leakage, potential and impedance.
Returns one row per unique galvanic cluster present in the
result. The cluster impedance is computed as
\(Z_c = U_c / I_c\) with \(I_c = \sum_{e \in c} I_e\)
— the cluster's potential over its own soil leakage, not the
input impedance a source sees when conductors carry current out of
the cluster (see the module docstring). Where \(I_c = 0\)
(purely passive observer cluster) the impedance columns are NaN.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
'FieldResult'
|
Solver output. |
required |
frequency_index
|
int
|
Index into |
0
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Columns
|
Source code in src/groundfield/postprocess/current_balance.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
electrode_current_table ¶
electrode_current_table(result: 'FieldResult', world: 'World | None' = None, *, frequency_index: int = 0) -> pd.DataFrame
Per-electrode potential, current and share of cluster current.
For each electrode in the result the table reports the
potential \(U_e\) (= cluster potential), the soil-leakage
current \(I_e\), the implied two-terminal impedance
\(Z_e = U_e / I_e\) (the electrode's own leakage impedance,
quantity="electrode" in the sweep / rho-f helpers), and the
fractional share of the
cluster total \(s_{e \mid c} = I_e / I_c\). The latter is
the engineering key indicator for "of all the soil current
leaving cluster c, how much physically flows through this
specific electrode" — useful when looking at a single
transformer station with a ring + several rods, or a building
cluster with multiple foundation parts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
'FieldResult'
|
Solver output. |
required |
world
|
'World | None'
|
Optional companion world. When given, the table includes
the electrode kind ( |
None
|
frequency_index
|
int
|
Index into |
0
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Columns
|
Source code in src/groundfield/postprocess/current_balance.py
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 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 | |
plot_current_sharing ¶
plot_current_sharing(result: 'FieldResult', world: 'World | None' = None, *, by: Literal['electrode', 'cluster'] = 'electrode', top_n: int = 15, frequency_index: int = 0, figsize: tuple[float, float] = (8.0, 5.0), title: str | None = None)
Bar chart of the top_n current contributors.
Renders |I| (in A) for either every electrode or every
galvanic cluster, sorted descending. The default by =
"electrode" is the default — which physical electrode
actually carries the test current? The companion option
by = "cluster" aggregates over each cluster.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
'FieldResult'
|
Solver output. |
required |
world
|
'World | None'
|
Optional companion world. Forwarded to
|
None
|
by
|
Literal['electrode', 'cluster']
|
|
'electrode'
|
top_n
|
int
|
Maximum number of bars to render. Smaller contributors are
truncated. Pass |
15
|
frequency_index
|
int
|
Index into |
0
|
figsize
|
tuple[float, float]
|
Matplotlib figure size in inches. |
(8.0, 5.0)
|
title
|
str | None
|
Optional title override. |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/groundfield/postprocess/current_balance.py
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 | |
split_factor ¶
split_factor(result: 'FieldResult', world: 'World', *, source_name: str | None = None, frequency_index: int = 0) -> complex
Split factor \(s = I_{c_\text{src}} / I_\text{src}\).
Computes the galvanic split factor of a current source: the fraction of the injected current that leaves the source cluster through the soil rather than through any metallic parallel path (PEN trunk, parallel measurement lead, cable shield).
Mathematically
with \(c_\text{src}\) the galvanic cluster of the source's
attached_to electrode and \(I_\text{src}\) the complex
phasor of the source. By construction:
- For a stand-alone source on an electrode without metallic parallel paths, KCL forces \(s = 1 + 0\,j\). The injected current leaves the cluster entirely through the soil.
- For a source whose cluster is connected to another grounding cluster (e.g. the auxiliary electrode of a fall-of-potential measurement) by a metallic conductor, \(s < 1\). The smaller the conductor's series impedance, the smaller \(s\).
- The complex argument \(\arg s\) reveals the inductive content of the parallel path — a Carson- or Sommerfeld- corrected lead at frequency >0 produces an imaginary share.
- For a source returning through remote earth it links the input impedance and the cluster impedance of the feeding cluster, \(Z_\text{in} = s\,Z_c\) (review pass 10, 10.18).
The denominator \(I_\text{src}\) is the source current of the
solve, read from the snapshot FieldResult.sources when the
result carries one (since review pass 10); otherwise from the
world's source. For a voltage source it is the solved source current
(since 2026.11).
Not to be confused with the Reduktionsfaktor
In the German EVU / Schirmtechnik literature (Oeding & Oswald 2016), the Reduktionsfaktor refers to the transformatorische / inductive coupling correction between a current-carrying conductor and a parallel grounding / shield conductor. That quantity is angle-dependent: it vanishes when the two conductors are perpendicular (no flux linkage) but is large for collinear runs.
The split factor implemented here is purely galvanic — the resistive division of current across parallel paths. It is present whenever there are multiple parallel paths, regardless of their geometric orientation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
'FieldResult'
|
Solver output. |
required |
world
|
'World'
|
Companion world used to resolve the source object. |
required |
source_name
|
str | None
|
Optional name of the current source. |
None
|
frequency_index
|
int
|
Index into |
0
|
Returns:
| Type | Description |
|---|---|
complex
|
Phasor \(s(f)\) (dimensionless). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the world has no current source, multiple current
sources without explicit |
KeyError
|
If |
Source code in src/groundfield/postprocess/current_balance.py
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 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 | |
Sweeps and convergence studies¶
sweep ¶
Cartesian-product parameter sweeps for parameter axis studies.
This module turns the typical study axes — soil resistivity
\(\rho_1\) / \(\rho_2\), layer thickness \(h_1\),
electrode geometry, frequency — into a single tabular response
that is cheap to plot and easy to feed into vector-fitting,
\(\rho\)-\(f\) regression, or downstream
groundinsight.
API surface
sweep()
Walk the Cartesian product of an arbitrary number of named
axes, build a fresh World (and optionally a fresh
Engine) per combination, solve, and extract a scalar
response per frequency. Returns a long-format
pandas.DataFrame with one row per
(axis values × frequency).
plot_sweep_lines()
Line plot of one response column against a chosen axis,
optionally with one curve per value of a second axis.
plot_sweep_heatmap()
Pivot-table heatmap of one response column over a
(x_axis, y_axis) pair (e.g. \(\rho_1\) vs. \(h_1\)).
Mathematical / physical content
The default response extractor reports one impedance per
frequency, selected by quantity (review pass 10, 10.18):
"input"(default) — the input (driving-point) impedance \(Z_\text{in} = (\varphi_a - \varphi_r) / I_s\) of the current source: what a measurement instrument or a fault sees at the feeding point (FieldResult.input_impedance());"cluster"— the cluster impedance \(Z_c = \varphi_c / \sum_{e \in c} I_e\) of the source's galvanic cluster over its own soil leakage (the default up to v0.15.0);"electrode"— \(\varphi_e / I_e\) of the feeding electrode alone.
As soon as conductors (PEN, shields, leads) carry part of the
injected current away, the cluster impedance describes only the local
electrode: for a station with three houses on a PEN it is 1.79 times
the input impedance (1.26 times with one house, 3.09 times with eight;
review pass 10). The response is the engineering
\(Z(\rho_1, h_1, f)\) curve that
groundfield.postprocess.rho_f_standard and
groundfield.postprocess.vector_fitting consume.
Validity envelope
- Frequency: quasi-static envelope \(f \le 1\,\mathrm{kHz}\).
- Linearity: the sweep does not interpolate between samples — for
a smooth \(Z(\rho, f)\) surface, hand the resulting
DataFrame to
fit_rho_f_standard()/fit_to_sympy_standard(). - Cost: every Cartesian combination triggers one full
Engine.solve(). For 50 ρ-values × 10 h-values × 1 frequency list with N segments each, expect 500 dense system solves; budget accordingly withexpected_segments(). - Parallelism: the combinations are independent, so
sweep(..., n_jobs=k)solves them inkworker processes (review pass 10, 10.64). The dense LU factorisation is only 0.2–1.5 % of a solve (kernel assembly dominates), so a multi-threaded BLAS does not parallelise a solve; separate processes do (measured 1.98× on 2 workers for a 20-house world). Workers run their BLAS on one thread; the result is bit-identical to the serial run when the calling process also runs a single-threaded BLAS (results differ at the 1e-15 level between 1 and 2 BLAS threads).
plot_sweep_heatmap ¶
plot_sweep_heatmap(df: DataFrame, *, x: str, y: str, response: str = 'abs_Z', frequency_Hz: float | None = None, agg: str = 'mean', cmap: str = 'viridis', figsize: tuple[float, float] = (7.5, 5.5), title: str | None = None)
Heatmap of response over the (x, y) axis pair.
Pivot-tables df by y (rows) and x (columns),
aggregating response with the chosen agg (default
"mean" — useful when the sweep contains additional axes
that should collapse). Selects a single frequency slice
when frequency_Hz is given.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Long-format DataFrame from |
required |
x
|
str
|
Column names for the heatmap axes. Both must be numeric. |
required |
y
|
str
|
Column names for the heatmap axes. Both must be numeric. |
required |
response
|
str
|
Column to colour-code. Default |
'abs_Z'
|
frequency_Hz
|
float | None
|
If given and the DataFrame has a |
None
|
agg
|
str
|
Aggregation passed to |
'mean'
|
cmap
|
str
|
Standard matplotlib options. |
'viridis'
|
figsize
|
str
|
Standard matplotlib options. |
'viridis'
|
title
|
str
|
Standard matplotlib options. |
'viridis'
|
Returns:
| Type | Description |
|---|---|
Figure
|
|
Raises:
| Type | Description |
|---|---|
KeyError
|
If |
ValueError
|
If |
Source code in src/groundfield/postprocess/sweep.py
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 | |
plot_sweep_lines ¶
plot_sweep_lines(df: DataFrame, *, x: str, y: str = 'abs_Z', color: str | None = None, figsize: tuple[float, float] = (8.0, 5.0), log_x: bool = False, log_y: bool = False, title: str | None = None)
Line plot of y versus x, one curve per color value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Long-format DataFrame as produced by |
required |
x
|
str
|
Column name to use on the x-axis. |
required |
y
|
str
|
Column name of the response. Default |
'abs_Z'
|
color
|
str | None
|
Optional second column name; one line per distinct value
is drawn. |
None
|
figsize
|
tuple[float, float]
|
Standard matplotlib options. |
(8.0, 5.0)
|
log_x
|
tuple[float, float]
|
Standard matplotlib options. |
(8.0, 5.0)
|
log_y
|
tuple[float, float]
|
Standard matplotlib options. |
(8.0, 5.0)
|
title
|
tuple[float, float]
|
Standard matplotlib options. |
(8.0, 5.0)
|
Returns:
| Type | Description |
|---|---|
Figure
|
|
Raises:
| Type | Description |
|---|---|
KeyError
|
If |
Source code in src/groundfield/postprocess/sweep.py
sweep ¶
sweep(world_factory: Callable[..., 'World'], engine: 'Engine | Callable[..., Engine]', *, axes: dict[str, Sequence[Any]], response: Callable[['FieldResult', 'World', int], dict[str, float]] | None = None, quantity: Quantity = 'input', source: str | None = None, n_jobs: int = 1) -> pd.DataFrame
Cartesian-product parameter sweep across user-defined axes.
For every combination (a_1 = v_1, a_2 = v_2, ...) in the
Cartesian product of axes, the function
- builds a fresh world via
world_factory(**combination), - resolves the engine — either the static
Enginepassed in or a per-combination engine viaengine(**combination)if a callable is given, - solves with
World.solve(), - iterates over every frequency in
FieldResult.frequenciesand extracts a row viaresponse(result, world, frequency_index).
The axis values and frequency_Hz are added to every row
automatically.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
world_factory
|
Callable[..., 'World']
|
Callable that builds a fresh |
required |
engine
|
'Engine | Callable[..., Engine]'
|
Either a static |
required |
axes
|
dict[str, Sequence[Any]]
|
Mapping |
required |
response
|
Callable[['FieldResult', 'World', int], dict[str, float]] | None
|
Optional response extractor. Receives
|
None
|
quantity
|
Quantity
|
Impedance of the default response: |
'input'
|
source
|
str | None
|
Name of the current source the default response refers to; may be omitted when the world has exactly one current source (with several, v0.15.0 silently used the first one; now it raises). |
None
|
n_jobs
|
int
|
Number of worker processes (default 1: serial, in this process).
|
1
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Long-format. Columns are the axis names, |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
TypeError
|
With |
Notes
With n_jobs > 1 the result is bit-identical to n_jobs=1
when the calling process runs a single-threaded BLAS as well
(OPENBLAS_NUM_THREADS=1); otherwise the two agree to round-off.
Process start-up costs about a second per worker, so parallel runs
pay off for solves of a second or more.
Source code in src/groundfield/postprocess/sweep.py
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 | |
convergence ¶
Convergence study over the engine's segment_length.
The PDE / field model in groundfield is a reference
computation (see CLAUDE.md); to honour that role every
non-trivial result should be backed up by a refinement study.
This module turns the canonical "halve the segment length, watch
what happens" experiment into one function call.
Mathematical / physical content
The image-family discretiser splits each electrode into segments of length \(\Delta s\). As \(\Delta s \to 0\) the multi-port grounding matrix approaches the continuous integral operator and the cluster impedance \(Z_c\) converges to the PDE-grade reference. The convergence is monotone in \(\Delta s\) for the average-potential method (cf. Sunde 1968; Tagg 1964). A practical refinement plot therefore answers two questions at once:
- "Has my chosen \(\Delta s\) already converged within X %?" — the curve flattens out.
- "What is the asymptotic (PDE-grade) value?" — extrapolation / Richardson if needed.
Validity envelope
- Frequency: quasi-static envelope \(f \le 1\,\mathrm{kHz}\).
- Backends: any image-family solver (image / image_2layer /
image_nlayer / mom / mom_sommerfeld / cim / bem). FEM is
supported but its mesh is generated independently — the
segment_lengthknob does not directly control its accuracy. - The function copies the engine per step (the original engine is not
mutated) without the validating
Engine.model_copy(), whose warning capture resets every module's "shown once" registry: a warning that a plain loop over the same engines shows once was shown once per step (audit round 2, A2S-08). The segment lengths are validated here instead.
convergence_study ¶
convergence_study(world: 'World', engine: 'Engine', *, segment_lengths: Sequence[float], response: Callable[['FieldResult', 'World', int], dict[str, float]] | None = None, quantity: Quantity = 'input', source: str | None = None) -> pd.DataFrame
Solve the same world repeatedly with refining segment_length.
For every \(\Delta s_k\) in segment_lengths the
function builds a clone of the engine (only segment_length
differs), solves the world, and extracts a scalar response
per frequency. The returned DataFrame is sorted descending
in segment_length_m so finer resolutions land on the right
in the default plot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
world
|
'World'
|
World to solve. Not modified. |
required |
engine
|
'Engine'
|
Base engine. Cloned per refinement step via an internal copy per step; the original is left untouched. |
required |
segment_lengths
|
Sequence[float]
|
Sequence of segment lengths in metres. Must be strictly positive and contain at least two distinct values. |
required |
response
|
Callable[['FieldResult', 'World', int], dict[str, float]] | None
|
Optional response extractor |
None
|
quantity
|
Quantity
|
Impedance of the default response: |
'input'
|
source
|
str | None
|
Current source of the default response; may be omitted with a single current source. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Long-format. Columns |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/groundfield/postprocess/convergence.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
plot_convergence ¶
plot_convergence(df: DataFrame, *, response: str = 'abs_Z', reference: float | None = None, figsize: tuple[float, float] = (7.5, 4.5), title: str | None = None)
Plot response versus segment_length (one line per frequency).
The x-axis is logarithmic and inverted so finer resolutions sit on the right (the convergence "asymptote direction"). When the DataFrame contains a single frequency only, the legend is suppressed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
DataFrame returned by |
required |
response
|
str
|
Column name to plot. Default |
'abs_Z'
|
reference
|
float | None
|
Optional asymptotic value to draw as a horizontal dashed reference line — useful when an analytical reference (Sunde, Dwight, IEEE Std 80) is known. |
None
|
figsize
|
tuple[float, float]
|
Standard matplotlib options. |
(7.5, 4.5)
|
title
|
tuple[float, float]
|
Standard matplotlib options. |
(7.5, 4.5)
|
Returns:
| Type | Description |
|---|---|
Figure
|
|
Raises:
| Type | Description |
|---|---|
KeyError
|
If |
Source code in src/groundfield/postprocess/convergence.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | |
Vector fitting¶
vector_fitting ¶
Vector fitting and SymPy export for the rho-f reduced model.
This module turns a frequency response computed by groundfield
into a closed-form rational impedance expression that
groundinsight can consume as BusType.impedance_formula.
It is the bridge between the field-grade reference computation
(groundfield) and the reduced equivalent-network model
(groundinsight).
Mathematical background
For a passive, linear, time-invariant grounding cluster, the driving-point impedance \(Z(s)\) at the feed-in electrode is a rational function of the Laplace variable \(s = j\omega\). Under the \(f \le 1\,\mathrm{kHz}\) assumption the function is well approximated by a low-order partial-fraction expansion
with poles \(p_k\) on the negative real axis (damped RC modes) and residues \(r_k\). Complex-conjugate pole pairs are admissible too — they produce damped resonant LC-like behaviour. The fit is constructed by the Vector Fitting algorithm of Gustavsen & Semlyen 1999, which iterates pole locations to a stable solution and is the de-facto standard for transmission-line and grounding modelling.
Implementation
This module implements a clean, dependency-free version of vector fitting in NumPy:
- Initial pole guess: linearly spaced on the negative real axis between the smallest and largest sampled frequencies.
- Pole relocation via Sanathanan-Koerner-style least squares with a shared denominator (the canonical Gustavsen iteration).
- Residue solve given the converged poles.
- Stability enforcement: any pole ending up in the right half plane is reflected.
The exported SymPy expression follows the
groundinsight.BusType.impedance_formula convention: a single
free symbol s and arbitrary numeric constants.
References
- Gustavsen, B. & Semlyen, A. (1999). Rational approximation of frequency domain responses by Vector Fitting. IEEE Trans. Power Delivery 14(3), 1052–1061.
- Gustavsen, B. (2006). Improving the pole relocating properties of vector fitting. IEEE Trans. Power Delivery 21(3), 1587–1592.
PassivityReport
dataclass
¶
PassivityReport(passed: bool, min_re_Z: float, f_at_min: float, f_max: float, rho_at_min: float | None = None, rho_range: tuple[float, float] | None = None, n_points: int = 0)
Outcome of check_passivity().
Attributes:
| Name | Type | Description |
|---|---|---|
passed |
bool
|
|
min_re_Z |
float
|
Smallest \(\Re Z\) found, in Ω; |
f_at_min |
float
|
Frequency of |
f_max |
float
|
Upper end of the checked band in Hz (the band starts at 0 Hz). |
rho_at_min |
float | None
|
Soil resistivity of |
rho_range |
tuple[float, float] | None
|
Checked resistivity range |
n_points |
int
|
Number of grid points evaluated (before the refinement). |
as_dict ¶
Strict-JSON summary; the metadata["passivity"] block of an export.
Keys: passed, min_re_Z_Ohm (None when not finite),
f_at_min_Hz, rho_at_min_Ohm_m, f_checked_Hz
([0, f_max]), rho_checked_Ohm_m ([min, max] or
None) and n_points.
Source code in src/groundfield/postprocess/vector_fitting.py
VectorFitConvergenceWarning ¶
Bases: UserWarning
The pole-relocation loop did not converge.
Emitted when the relative pole displacement of the last
relocation step is still above 1 % after n_iter iterations
(audit 2026-07-08, WP-B4 — the historic implementation ran a
fixed number of blind iterations with no convergence check).
Inspect VectorFitResult.pole_shift / n_iter_used and
consider more iterations, a different n_poles, or
weighting="inverse_magnitude" for wide-dynamic-range data.
VectorFitQualityWarning ¶
Bases: UserWarning
The vector fit is poor, or a sample had to be corrected.
Emitted (review pass 10, 10.41) when the relative rms error
rms_error / mean|Z| exceeds rms_tol (default 1 %), and when
the imaginary part of a 0 Hz sample exceeds 0.1 % of its magnitude
(it is discarded: a rational model with real coefficients is real at
\(s = 0\)). Inspect VectorFitResult.rms_relative; try other
n_poles, more samples, or weighting="inverse_magnitude".
VectorFitResult
dataclass
¶
VectorFitResult(poles: ndarray, residues: ndarray, R_inf: float, L_inf: float, rms_error: float, fit_frequencies: ndarray, fit_values: ndarray, n_iter_used: int = 0, pole_shift: float = 0.0, rms_relative: float = math.nan, quantity: str | None = None)
Result of a vector fit.
Attributes:
| Name | Type | Description |
|---|---|---|
poles |
ndarray
|
Complex poles \(p_k\) (1-D array, length \(N_p\)). Stable poles
have |
residues |
ndarray
|
Complex residues \(r_k\) (same shape as |
R_inf |
float
|
Real constant offset \(R_\infty\) (DC residual). |
L_inf |
float
|
Real proportional-to-\(s\) term \(L_\infty\) (high-frequency slope). 0 if the fit was performed without it. |
rms_error |
float
|
Root-mean-square residual fitting error in \(\Omega\), taken over the input frequency points. |
fit_frequencies |
ndarray
|
Frequencies (Hz) used for the fit, kept for diagnostics. |
fit_values |
ndarray
|
\(Z(s)\) values used for the fit (0 Hz samples projected onto their real part). |
n_iter_used, pole_shift |
Iterations of the pole relocation and the last relative pole displacement. |
|
rms_relative |
float
|
|
quantity |
str | None
|
Impedance the samples represent when the fit was built by
|
evaluate ¶
Evaluate the fitted \(Z(s)\) at arbitrary frequencies.
Source code in src/groundfield/postprocess/vector_fitting.py
VectorFitUnderdeterminedWarning ¶
Bases: UserWarning
Vector fit is under- or exactly-determined.
A vector fit with n_poles poles has 2 * n_poles + extras
real unknowns (residues plus optional R_inf / L_inf); the
real-imag stacking of an input of length N gives 2 N
equations. n_poles >= N therefore leads to an under- or
exactly-determined least-squares problem. The fit can succeed
numerically but is effectively an identity interpolation that
carries no information beyond the input samples.
A dedicated warning category lets users opt into / out of the
diagnostic with warnings.simplefilter("once",
VectorFitUnderdeterminedWarning).
check_passivity ¶
check_passivity(fit, f_max: float | None = None, *, n: int = 2001, rho_range: tuple[float, float] | None = None) -> PassivityReport
Check \(\Re Z(j 2\pi f) \ge 0\) of a fitted rho-f model on a band.
A grounding impedance is the driving-point impedance of a passive one-port, so its real part is non-negative at every frequency,
A rational fit can violate this between or beyond its samples: review pass 10 found a 4-pole fit of passive data (rms 4.4 mΩ, no warning) with \(\Re Z = -0.019\,\Omega\) at 5.5 Hz, between the 0 Hz and 50 Hz samples (10.40 / 10.41). This is the one passivity check of the package: the groundinsight exporter runs the same implementation on the formula it writes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fit
|
required | ||
f_max
|
float | None
|
Upper end of the band in Hz (the band starts at 0 Hz). Default: twice the highest fitted frequency, the band of the export check. |
None
|
n
|
int
|
Number of points of the linear frequency grid of a vector fit
( |
2001
|
rho_range
|
tuple[float, float] | None
|
|
None
|
Returns:
| Type | Description |
|---|---|
PassivityReport
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
For an unsupported fit type. |
ValueError
|
For |
Source code in src/groundfield/postprocess/vector_fitting.py
fit_to_sympy ¶
Convert a VectorFitResult to a SymPy expression in s.
The expression is the partial-fraction form of the fit,
with every complex-conjugate pole/residue pair combined into one real second-order term,
so the expression is real for real s. It is built by the renderer
the groundinsight exporter uses (one term per real pole or pole
pair; review pass 10, 10.73) and is not simplified: up to the
calendar release sympy.simplify merged the terms into one rational
function of degree four over three.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fit
|
VectorFitResult
|
The vector fit. |
required |
decimals
|
int
|
Significant digits of every floating-point coefficient (1 to 17;
larger values count as 17). Each coefficient is the full-precision
value correctly rounded once to |
6
|
Returns:
| Type | Description |
|---|---|
Expr
|
Expression in the free symbol |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Warns:
| Type | Description |
|---|---|
UserWarning
|
If the expression does not depend on |
Source code in src/groundfield/postprocess/vector_fitting.py
1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 | |
rho_f_from_field_result ¶
rho_f_from_field_result(result, electrode_name: str | None = None, *, quantity: Quantity = 'input', source: str | None = None, n_poles: int = 4, n_iter: int = 8, include_R_inf: bool = True, include_L_inf: bool = False, complex_poles: bool = True) -> VectorFitResult
Fit \(Z(s)\) to the impedance of a FieldResult.
Reads the impedance selected by quantity at every frequency in
result.frequencies and runs vector_fit() on the series.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
|
required | |
electrode_name
|
str | None
|
Electrode whose impedance is fitted. Required for
|
None
|
quantity
|
Quantity
|
|
'input'
|
source
|
str | None
|
Current source for |
None
|
n_poles
|
int
|
Forwarded to |
4
|
n_iter
|
int
|
Forwarded to |
4
|
include_R_inf
|
int
|
Forwarded to |
4
|
include_L_inf
|
int
|
Forwarded to |
4
|
complex_poles
|
int
|
Forwarded to |
4
|
Returns:
| Type | Description |
|---|---|
VectorFitResult
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
For an unknown |
KeyError
|
If |
Notes
Frequencies at which the denominator current is zero (a passive
electrode, a dead column) are masked with a UserWarning
instead of being entered as \(Z = 0\).
Source code in src/groundfield/postprocess/vector_fitting.py
1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 | |
vector_fit ¶
vector_fit(frequencies: Sequence[float], Z_values: Sequence[complex], *, n_poles: int = 4, n_iter: int = 8, include_R_inf: bool = True, include_L_inf: bool = False, complex_poles: bool = True, weighting: str = 'uniform', rms_tol: float = 0.01) -> VectorFitResult
Fit a rational \(Z(s)\) approximation to a sampled frequency response.
Implements the Vector Fitting algorithm of Gustavsen & Semlyen
1999 in its single-output, equal-weight form. The denominator
polynomial is shared between numerator and denominator
estimation (Sanathanan-Koerner with iterative pole relocation);
after n_iter outer iterations the poles are taken as fixed
and the residues are solved from a final linear system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frequencies
|
Sequence[float]
|
Frequency samples in Hz, length \(N\). |
required |
Z_values
|
Sequence[complex]
|
Complex impedance samples \(Z(j2\pi f_k)\) in \(\Omega\), length \(N\). |
required |
n_poles
|
int
|
Target number of poles. Complex-conjugate pairs count as 2 poles each. |
4
|
n_iter
|
int
|
Number of pole-relocation iterations. |
8
|
include_R_inf
|
bool
|
Whether to fit a constant offset \(R_\infty\) (DC residual). |
True
|
include_L_inf
|
bool
|
Whether to fit a \(s\cdot L_\infty\) proportional term. |
False
|
complex_poles
|
bool
|
|
True
|
weighting
|
str
|
|
'uniform'
|
rms_tol
|
float
|
Warn with |
0.01
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the samples are not finite, no sample has |
Warns:
| Type | Description |
|---|---|
VectorFitQualityWarning
|
Relative rms above |
(VectorFitConvergenceWarning, VectorFitUnderdeterminedWarning)
|
See the warning classes. |
Notes
0 Hz samples (review pass 10, 10.41). The model has real
coefficients, so it is real at \(s = 0\). A 0 Hz sample with an
imaginary part (measured or averaged data) cannot be represented;
up to v0.15.0 the pole relocation then moved a pole onto the origin
and the fit collapsed to \(Z \approx 0\) at every other
frequency (relative rms 0.99, 20 of 20 noisy data sets) or numpy
raised LinAlgError. The 0 Hz samples are now projected onto
their real part before fitting, which is bit-for-bit neutral for
real 0 Hz samples (all solver output).
Since the 2026-07-08 audit (WP-B4) the least-squares systems use
the conjugate-pair real basis (see _pair_basis()):
complex pole pairs carry genuinely complex residues, matching
the cited Gustavsen & Semlyen algorithm. The pole-relocation
loop additionally monitors the relative pole displacement,
breaks early below 1e-8 and warns
(VectorFitConvergenceWarning) when it is still above
1 % after n_iter iterations; the diagnostics are exposed as
VectorFitResult.n_iter_used / pole_shift.
Returns:
| Type | Description |
|---|---|
VectorFitResult
|
|
Source code in src/groundfield/postprocess/vector_fitting.py
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 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 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 | |
Standard rho-f form¶
rho_f_standard ¶
Standard-form rho-f model for the groundinsight bridge.
The reduced grounding-cluster impedance uses the physically-motivated standard form
with \(\rho\) a soil-resistivity parameter (typically the upper-layer \(\rho_1\) in a fixed-structure 2-layer setup) and \(f\) the frequency. The real coefficients have direct physical interpretation:
- \(k_0\) — resistance that does not scale with \(\rho\)
in \(\Omega\): the share of the lower layer in a \(\rho_1\) sweep
(\(R(\rho_1 \to 0)\) stays finite, set by \(\rho_2\)), or the
series resistance of conductors in a network. Optional (
k0=Trueby default since review pass 10, 10.27); real, so that \(Z(f = 0)\) is real. - \(k_1\,\rho\) — DC spreading resistance (Dwight-class scaling with the dominant local soil resistivity).
- \(k_2\,f\) — soil-independent resistive frequency dependence in \(\Omega/\mathrm{Hz}\) (skin/proximity losses of the metallic parts; negligible in most quasi-static typical studies).
- \(k_3\,f\) — soil-independent reactive coupling in \(\Omega/\mathrm{Hz}\), i.e. the loop-inductance term of a metallic path; the equivalent inductance is \(L = k_3 / (2\pi)\) in H.
- \(k_4\,f\,\rho\) — Carson-type earth-return resistance: scales with both frequency and soil resistivity.
- \(k_5\,f\,\rho\) — Carson-type earth-return reactance.
This is not a general rational function — it is a fixed
parametric ansatz that captures the leading orders for production-grade
grounding-cluster impedances. It is fitted from a parametric
family of groundfield runs that span both \(\rho\) and \(f\), and
exported as a SymPy expression with two free symbols \(\rho\)
(rho) and \(f\) (f) — the BusType.impedance_formula
convention used by groundinsight.
Mathematically the fit is a weighted linear least-squares problem:
- Real part: \(\Re Z = k_0 + k_1\rho + k_2 f + k_4 f\rho\) → regression in (\(1\), \(\rho\), \(f\), \(f\rho\)).
- Imaginary part: \(\Im Z = k_3 f + k_5 f\rho\) → regression in (\(f\), \(f\rho\)).
With weights="relative" (default since review pass 10) every
sample is weighted by \(1/|Z_n|\), i.e. the fit minimises the sum of
squared relative errors; with "uniform" it minimises absolute
errors, which concentrates the error on the low-impedance samples
(low \(\rho\)), where the high-\(\rho\) samples dominate the residual.
So \(k_2\) and \(k_4\) live in the real (resistive) half and \(k_3\) and \(k_5\) in the imaginary (reactive) half — the pairing implied by the complex factors \((k_2 + j k_3)\) and \((k_4 + j k_5)\) above.
Both halves are decoupled in the coefficients, so the fit is unique whenever the sample set spans at least two distinct \(\rho\) values and at least two distinct frequencies (and, with \(k_0\), the real design matrix has full rank). The two conditions remove two different collinearities of the design matrix:
- A single \(\rho = R\) makes the columns \(f\) and \(f\rho = R f\) proportional, so only \(k_2 + R\,k_4\) (resp. \(k_3 + R\,k_5\)) is identifiable.
- A single \(f = F\) makes the columns \(\rho\) and \(f\rho = F\rho\) proportional, so only \(k_1 + F\,k_4\) is identifiable.
Fit quality
rms_relative (rms error over the mean \(|Z|\)) is dominated by the
high-impedance samples and hides large relative errors at low
\(\rho\). max_relative = \(\max_n |Z_\text{fit} - Z_n| / |Z_n|\) is
the figure to check; above max_relative_tol (5 %) the fit warns
with RhoFStandardQualityWarning. Review pass 10 measured on a
\(\rho_1\) sweep (30…1000 Ω·m) of a 2 m ring in two-layer soil
(\(\rho_2\) = 100 Ω·m, \(h_1\) = 5 m): v0.15.0 form 27 % worst error at
\(\rho_1\) = 30 (rms_relative 2.6 %), with \(k_0\) and relative weights
3.3 %; an AP1-like station (4 m × 4 m loop with three 4 m rods) 43 %
against 6.2 %.
References
- The rho-f model is the reduced grey-box representation handed to
groundinsight. groundinsight.BusType.impedance_formula: the consumer of the SymPy expression returned byfit_to_sympy_standard().
RhoFStandardFit
dataclass
¶
RhoFStandardFit(k1: float, k2: float, k3: float, k4: float, k5: float, rms_error: float, rms_relative: float, sample_rho: ndarray, sample_f: ndarray, sample_Z: ndarray, k0: float = 0.0, max_relative: float = math.nan, weights: str = 'uniform', quantity: str | None = None)
Result of a standard-form rho-f fit.
Attributes:
| Name | Type | Description |
|---|---|---|
k1, k2, k3, k4, k5 |
Real coefficients of
\(Z = k_0 + k_1\rho + (k_2 + j k_3)f + (k_4 + j k_5)f\rho\).
|
|
rms_error |
float
|
Root-mean-square residual error in \(\Omega\) over the input samples. |
rms_relative |
float
|
|
sample_rho, sample_f, sample_Z |
Original samples used for the fit (1-D arrays of length \(N\)), kept for diagnostics. |
|
k0 |
float
|
Constant term in \(\Omega\) (0 when fitted with |
max_relative |
float
|
Worst pointwise relative error
\(\max_n |Z_\text{fit}(\rho_n, f_n) - Z_n| / |Z_n|\) over the
samples with \(Z_n \ne 0\) (dimensionless); |
weights |
str
|
Weighting used in the fit, |
quantity |
str | None
|
Impedance the samples represent when the fit was built by
|
evaluate ¶
Evaluate the fitted \(Z(\rho, f)\) in Ω at arbitrary points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rho
|
float | ndarray
|
Soil resistivity in Ω·m (scalar or array). |
required |
f
|
float | ndarray
|
Frequency in Hz (scalar or array, broadcast with |
required |
Source code in src/groundfield/postprocess/rho_f_standard.py
RhoFStandardQualityWarning ¶
Bases: UserWarning
The standard-form fit misses a sample by more than max_relative_tol.
The standard form is a fixed ansatz; a large pointwise error means it
cannot represent the sampled \(Z(\rho, f)\) (review pass 10,
10.27). Check RhoFStandardFit.max_relative, restrict the
\(\rho\) range, or fit per \(\rho\) with vector fitting.
fit_rho_f_standard ¶
fit_rho_f_standard(rho_samples: Sequence[float], f_samples: Sequence[float], Z_samples: Sequence[complex], *, k0: bool = True, weights: Weights = 'relative', max_relative_tol: float = 0.05) -> RhoFStandardFit
Fit the standard rho-f form via weighted linear least squares.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rho_samples
|
Sequence[float]
|
Soil-resistivity values \(\rho\) in \(\Omega\,\mathrm{m}\) for each sample (length \(N\)). |
required |
f_samples
|
Sequence[float]
|
Frequencies \(f\) in Hz for each sample (length \(N\)). |
required |
Z_samples
|
Sequence[complex]
|
Complex impedances \(Z\) in \(\Omega\) at each \((\rho, f)\) sample (length \(N\)). |
required |
k0
|
bool
|
Fit the constant term \(k_0\) (default |
True
|
weights
|
Weights
|
|
'relative'
|
max_relative_tol
|
float
|
Warn with |
0.05
|
Returns:
| Type | Description |
|---|---|
RhoFStandardFit
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If sample arrays have inconsistent lengths, there are fewer than
four samples, fewer than two distinct \(\rho\) values or fewer
than two distinct \(f\) values, the design matrix is rank
deficient, |
Warns:
| Type | Description |
|---|---|
RhoFStandardQualityWarning
|
If the worst pointwise relative error exceeds |
Notes
k0=False, weights="uniform" reproduces the v0.15.0 coefficients
bit for bit.
Source code in src/groundfield/postprocess/rho_f_standard.py
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 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 | |
fit_to_sympy_standard ¶
Convert a RhoFStandardFit to a SymPy expression.
Returns a sympy.Expr in two free symbols rho and
f (both real), in the standard form
the constant term only when it is non-zero. The expression is built
term by term by the renderer the groundinsight exporter uses
(review pass 10, 10.73) and is suitable for direct insertion into
groundinsight.BusType.impedance_formula.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fit
|
RhoFStandardFit
|
Standard-form fit. |
required |
decimals
|
int
|
Significant digits of every coefficient (1 to 17; larger values
count as 17). Each coefficient is correctly rounded once, so
its relative error is at most \(\tfrac12\,10^{1-N}\) for
\(N\) = |
6
|
Returns:
| Type | Description |
|---|---|
Expr
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/groundfield/postprocess/rho_f_standard.py
rho_f_standard_from_results ¶
rho_f_standard_from_results(results: Sequence, rhos: Sequence[float], electrode_name: str | None = None, *, quantity: Quantity = 'input', source: str | None = None, k0: bool = True, weights: Weights = 'relative', max_relative_tol: float = 0.05) -> RhoFStandardFit
Build the (ρ, f, Z) sample table from a list of FieldResults and fit.
Use case: parametric soil-resistivity sweep. Run one
Engine.solve per soil resistivity, collect the FieldResults
along with the driving \(\rho\), and pass the lot to this
function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
Sequence
|
List of |
required |
rhos
|
Sequence[float]
|
Soil-resistivity parameter \(\rho\) in Ω·m corresponding to each FieldResult (same length). |
required |
electrode_name
|
str | None
|
Electrode whose impedance is fitted; required for
|
None
|
quantity
|
Quantity
|
|
'input'
|
source
|
str | None
|
Current source for |
None
|
k0
|
bool
|
Forwarded to |
True
|
weights
|
bool
|
Forwarded to |
True
|
max_relative_tol
|
bool
|
Forwarded to |
True
|
Returns:
| Type | Description |
|---|---|
RhoFStandardFit
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
KeyError
|
If |
Notes
Samples at which the denominator current is zero are
masked out rather than entered as \(Z = 0\): a vanishing current
means the impedance is undefined, not zero, and a single injected
zero row pulls the least-squares plane through the origin (a 1-in-7
dead DC column biases \(k_1\) by tens of percent). Masking mirrors
groundfield.postprocess.vector_fitting.rho_f_from_field_result();
a UserWarning reports how many samples were dropped.
Source code in src/groundfield/postprocess/rho_f_standard.py
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 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 | |
Potential plots¶
plotting ¶
Matplotlib plots for potential distributions and profiles.
Functions:
| Name | Description |
|---|---|
plot_potential_contour |
Contour / pseudo-colour plot of the potential in a slice plane
( |
plot_potential_profile |
Line plot of the potential along an arbitrary direction for one or several \(z\) depths. |
plot_potential_radial |
Radial profile \(\varphi(r)\) starting from an electrode for several depths — the standard "how far does the trumpet reach?" plot. |
All functions return the ``matplotlib.figure.Figure`` they produce so |
|
that notebooks can post-process them |
|
The potential is a complex phasor. Every plot takes |
|
``component="real" | "imag" | "abs" | "phase"`` |
|
the part plotted up to v0.15.0) and labels the axis with what it draws |
|
— ``Re φ``, ``Im φ``, ``|φ|`` in V or ``arg φ`` in degrees |
|
pass 10, 10.73). With phase-shifted sources or inductive coupling the |
|
real part is not the magnitude; use ``component="abs"`` for safety |
|
plots. |
|
plot_potential_contour ¶
plot_potential_contour(result: 'FieldResult', *, world: 'World | None' = None, plane: Literal['xy', 'xz'] = 'xy', z: float = 0.0, y: float = 0.0, extent: tuple[float, float, float, float] | None = None, n: int = 120, frequency_index: int = 0, levels: int = 20, log: bool = False, cmap: str = 'viridis', component: Component = 'real')
Contour plot of the potential in a slice plane.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
'FieldResult'
|
Result object from |
required |
world
|
'World | None'
|
Optional companion world; if given, electrodes are drawn into the plot. |
None
|
plane
|
Literal['xy', 'xz']
|
|
'xy'
|
z
|
float
|
Depth or \(y\) value of the slice plane in metres. |
0.0
|
y
|
float
|
Depth or \(y\) value of the slice plane in metres. |
0.0
|
extent
|
tuple[float, float, float, float] | None
|
|
None
|
n
|
int
|
Resolution per axis. |
120
|
frequency_index
|
int
|
Index into |
0
|
levels
|
int
|
Number of contour levels. |
20
|
log
|
bool
|
Logarithmic colour scale (better for fields that span several decades). |
False
|
cmap
|
str
|
Matplotlib colormap name. |
'viridis'
|
component
|
Component
|
Part of the complex potential to draw: |
'real'
|
Returns:
| Name | Type | Description |
|---|---|---|
fig |
Figure
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
For an unknown |
Source code in src/groundfield/postprocess/plotting.py
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 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 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | |
plot_potential_profile ¶
plot_potential_profile(result: 'FieldResult', *, start: tuple[float, float, float], direction: tuple[float, float, float] = (1.0, 0.0, 0.0), distance: float = 30.0, n: int = 200, depths: Iterable[float] | None = None, frequency_index: int = 0, component: Component = 'real')
Potential along an arbitrary line, optionally for several depths.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
'FieldResult'
|
Result object. |
required |
start
|
tuple[float, float, float]
|
Start point |
required |
direction
|
tuple[float, float, float]
|
Direction vector (will be normalised). |
(1.0, 0.0, 0.0)
|
distance
|
float
|
Length of the line in metres. |
30.0
|
n
|
int
|
Number of evaluation points. |
200
|
depths
|
Iterable[float] | None
|
List of depths \(z\) in metres. One curve per depth. |
None
|
frequency_index
|
int
|
Index into |
0
|
component
|
Component
|
|
'real'
|
Returns:
| Name | Type | Description |
|---|---|---|
fig |
Figure
|
|
Source code in src/groundfield/postprocess/plotting.py
plot_potential_radial ¶
plot_potential_radial(result: 'FieldResult', *, around: str | tuple[float, float, float], world: 'World | None' = None, r_max: float = 30.0, n: int = 200, depths: Iterable[float] = (0.0, 0.5, 1.0), frequency_index: int = 0, log_x: bool = False, component: Component = 'real')
Trumpet-shape decay around an electrode (or fixed point).
Evaluates \(\varphi(r)\) along the +x direction starting
at the connection point of the given electrode (or at a fixed
point). Multiple depths produce multiple curves — the typical
"surface vs. deeper soil" comparison.
For a rectangular foundation of the generators the connection point
is a corner, the start of its local \(-y\) side (since 2026.11:
meshes since audit A2G-04, rectangles without cross-braces since user
decision Q38; in 0.15.0 one grid mesh connected at its centre), so the
profile starts there; pass around=(x, y, z) for another start.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
'FieldResult'
|
Solved field (homogeneous or two-layer soil). |
required |
around
|
str | tuple[float, float, float]
|
Electrode name (resolved via |
required |
world
|
'World | None'
|
Required when |
None
|
r_max
|
float
|
Maximum radius in metres. |
30.0
|
n
|
int
|
Number of evaluation points. |
200
|
depths
|
Iterable[float]
|
\(z\) depths for the comparison curves. |
(0.0, 0.5, 1.0)
|
frequency_index
|
int
|
Index into |
0
|
log_x
|
bool
|
If |
False
|
component
|
Component
|
|
'real'
|
Returns:
| Name | Type | Description |
|---|---|---|
fig |
Figure
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/groundfield/postprocess/plotting.py
660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 | |
plot_surface_potential ¶
plot_surface_potential(result: 'FieldResult', world: 'World', *, z: float = 0.0, padding_m: float = 15.0, n: int = 200, extent: tuple[float, float, float, float] | None = None, frequency_index: int = 0, levels: int = 25, log: bool = False, symmetric: bool = False, cmap: str = 'viridis', show_electrodes: bool = True, show_contour_lines: bool = True, figsize: tuple[float, float] = (8.5, 7.0), title: str | None = None, component: Component = 'real')
Surface-potential pseudo-colour plot over the entire world.
Differs from plot_potential_contour() in two ways:
- The default
extentis derived from the world's electrode bounding box (viaworld_bounds_xy()) pluspadding_m, not from the discretised current point sources. This makes the plot naturally cover all buildings, cable cabinets and the substation in a TN network — including the "boundary regions" where the potential decays back to remote earth. - The plot is locked to a horizontal slice (always
plane="xy"); this is what typical calls the surface potential. Useplot_potential_contour()for vertical slices.
Mathematical content
For each grid point \((x_i, y_j, z)\) the function evaluates
via FieldResult.potential(), which dispatches to the
correct Green's function for the soil model the result was
computed with (homogeneous / 2-layer / multi-layer). The
component (default the real part) is plotted; for log=True
the colour scale uses the logarithm of its magnitude so the boundary
decay is visible across several decades.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
'FieldResult'
|
Solver output from |
required |
world
|
'World'
|
Companion world used both to derive the plot extent and (optionally) to overlay electrodes. |
required |
z
|
float
|
Depth of the slice in metres. |
0.0
|
padding_m
|
float
|
Extra space added on each side of the electrode bounding box, in metres. Larger values let you see how the potential decays towards remote earth. |
15.0
|
n
|
int
|
Resolution per axis (the grid is |
200
|
extent
|
tuple[float, float, float, float] | None
|
Optional explicit |
None
|
frequency_index
|
int
|
Index into |
0
|
levels
|
int
|
Number of contour fill levels. |
25
|
log
|
bool
|
Logarithmic colour scale based on |
False
|
symmetric
|
bool
|
Use a symmetric |
False
|
cmap
|
str
|
Matplotlib colormap name. |
'viridis'
|
show_electrodes
|
bool
|
Draw the electrode geometry on top of the contour. |
True
|
show_contour_lines
|
bool
|
Draw black iso-potential lines on top of the fill. |
True
|
figsize
|
tuple[float, float]
|
Matplotlib figure size in inches. |
(8.5, 7.0)
|
title
|
str | None
|
Optional title override; if |
None
|
component
|
Component
|
|
'real'
|
Returns:
| Name | Type | Description |
|---|---|---|
fig |
Figure
|
|
Source code in src/groundfield/postprocess/plotting.py
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 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 | |
world_bounds_xy ¶
Compute the horizontal bounding box of a world's electrodes.
Inspects every electrode in world.electrodes and returns
the smallest axis-aligned rectangle in the \((x, y)\) plane that
contains the geometry. Used by plot_surface_potential() as
the natural "the whole world" extent for a surface contour plot.
The footprint of each electrode kind is treated explicitly:
RodElectrode— point atposition[:2].RingElectrode— square of side \(2r\) around the centre.StripElectrode— bounding box ofstartandend.MeshElectrode/GridMeshElectrode—cornertocorner + size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
world
|
'World'
|
World whose electrodes are inspected. |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
|
Source code in src/groundfield/postprocess/plotting.py
Geometry plots¶
geometry_plot ¶
World-geometry plots (no solve required).
This module provides quick visualisations of the physical world — electrodes, conductors and current sources — before the solver runs. In default setups with several hundred electrodes (200 EFH plus KVS plus substation plus measurement aux/probe) it is very useful to inspect the geometry first to catch typos in positions, accidental clusters, missing conductors, or sources attached to the wrong electrode, without paying the cost of a field solve.
Functions:
| Name | Description |
|---|---|
world_bounds_3d |
Smallest axis-aligned bounding box in \((x, y, z)\) of
the world's electrodes plus conductor endpoints. Extension of
|
plot_world |
2-D top-down ( |
plot_world_3d |
3-D wireframe with the soil-surface plane shown in light grey and the \(z\)-axis pointing downwards (groundfield convention; positive depth is below ground). |
Conductor colour scheme
The conductor colour follows groundfield.conductors.ConductorType:
================== ========================= =====================
conductor_type Colour Default style
================== ========================= =====================
pen #2c7a2c (green) solid
bare_copper #d97300 (orange) solid
cable_shield #888888 (grey) solid
overhead #1f77b4 (steel blue) solid
generic #444444 (dark grey) solid
================== ========================= =====================
The line style flags the soil-coupling mode of the conductor:
coupling_to_soil = "galvanic" is drawn solid, "isolated"
is drawn dashed.
Validity
Pure geometry — no solver result is required. The plot does
not visualise any field quantity; for that, see
groundfield.postprocess.plotting.plot_potential_contour()
and friends. Best used as a debugging step before
world.solve(...).
plot_world ¶
plot_world(world: 'World', *, plane: Literal['xy', 'xz'] = 'xy', extent: tuple[float, float, float, float] | None = None, padding_m: float = 5.0, show_conductors: bool = True, show_sources: bool = True, annotate_electrodes: bool = False, figsize: tuple[float, float] = (8.0, 6.0), ax=None, title: str | None = None)
Top-down or vertical 2-D geometry plot of a World.
Pure-geometry visualisation; no field quantity is evaluated
and no solver is invoked. Useful as a sanity check before
World.solve() on a large typical network.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
world
|
'World'
|
World to draw. |
required |
plane
|
Literal['xy', 'xz']
|
|
'xy'
|
extent
|
tuple[float, float, float, float] | None
|
Optional explicit |
None
|
padding_m
|
float
|
Extra padding on each side of the bounding box in metres
(used only when |
5.0
|
show_conductors
|
bool
|
If |
True
|
show_sources
|
bool
|
If |
True
|
annotate_electrodes
|
bool
|
If |
False
|
figsize
|
tuple[float, float]
|
Matplotlib figure size in inches (used when |
(8.0, 6.0)
|
ax
|
Optional pre-existing |
None
|
|
title
|
str | None
|
Optional title override; default |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/groundfield/postprocess/geometry_plot.py
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 | |
plot_world_3d ¶
plot_world_3d(world: 'World', *, show_conductors: bool = True, show_sources: bool = True, show_surface: bool = True, figsize: tuple[float, float] = (9.0, 7.0), elev: float = 22.0, azim: float = -55.0, title: str | None = None)
3-D wireframe of a World using mpl_toolkits.mplot3d.
The \(z\) axis is inverted so that depth points downwards on screen (groundfield convention: positive \(z\) is into the soil). A faint grey surface plane at \(z = 0\) marks the soil surface.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
world
|
'World'
|
World to draw. |
required |
show_conductors
|
bool
|
See |
True
|
show_sources
|
bool
|
See |
True
|
show_surface
|
bool
|
If |
True
|
figsize
|
tuple[float, float]
|
Matplotlib figure size in inches. |
(9.0, 7.0)
|
elev
|
float
|
Initial viewing angles (passed to
|
22.0
|
azim
|
float
|
Initial viewing angles (passed to
|
22.0
|
title
|
str | None
|
Optional title override. |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
|
Source code in src/groundfield/postprocess/geometry_plot.py
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 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 | |
world_bounds_3d ¶
Smallest axis-aligned \((x, y, z)\) bounding box of the world.
Inspects every electrode in World.electrodes and every
conductor endpoint in World.conductors, returning the
six bounds (x_min, x_max, y_min, y_max, z_min, z_max) in
metres.
The \((x, y)\) portion is consistent with
groundfield.postprocess.plotting.world_bounds_xy() but
additionally includes conductor endpoints — important for
overhead lines or measurement leads that extend well beyond
the electrode footprint. The \(z\) portion uses
RodElectrode:[position[2], position[2] + length](head + foot of the rod).RingElectrode,StripElectrode,PolylineElectrode,MeshElectrode,GridMeshElectrode: the \(z\) coordinate(s) of the electrode (single buried depth).- Conductors:
min/maxover both endpoint \(z\) values (catches overhead \(z<0\) and buried \(z>0\)).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
world
|
'World'
|
World whose electrodes and conductors are inspected. |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
|
Source code in src/groundfield/postprocess/geometry_plot.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |