kicad2ems.core.fields.frames

Field-dump viewing: the dumps of a run folder as 2D frames, for the GUI's field
view and for animations.

    srcs = find_dumps(out_dir)           # every dump under
                                         # <out>/<solver>/exc_*/
                                         # (openems, mom25d)
    src = srcs[0]; src.refresh()         # time domain: the .vtr frames written
                                         # so far (a run may be going)
    mesh, data = src.load(i)             # (x/y/z mm, model axes),
                                         # (nx, ny, nz, 3); complex for FD
    sl = plane(mesh, data, axis, index, component='mag', phase=None)
    save_animation(src, 'out.gif', ...)  # .gif (Pillow) or .mp4 (ffmpeg)

Time-domain dumps are VTK rectilinear grids (one .vtr per frame, zlib-compressed
binary as openEMS writes them), read here without VTK. Frequency-domain dumps
are openEMS HDF5 files (dumps.read_fd) or mom25d's surface currents on a grid
per layer (.npz: x, y, z, freqs, data (nf, nx, ny, nz, 3) complex); they are
animated over the phase: Re(F e^(j phi)), one period at one frequency: the
standing waves. A plane dump has one point along its normal; a volume is cut at
any x / y / z mesh line. 2D views are in KiCad axes (y down), components too (Fy
= -Fy model).
class kicad2ems.core.fields.frames.DumpSource(run_path, name, domain)[source]
One field dump of one run: time domain (a growing series of .vtr frames)
or frequency domain (one HDF5 file, frames = frequencies).
frame_label(i, phase=None)[source]
Frame i's label: its timestep and time (time domain), or its
frequency and the phase shown (frequency domain).
load(i)[source]
(mesh, field (nx, ny, nz, 3)) of frame i (cached; float32 /
complex).
newest_complete()[source]
Index of the newest frame that reads (a live run may be writing the
last one), or None.
refresh()[source]
Pick up new frames (time domain: during a run, the newest file may
still be being written).
scale(i)[source]
Frequency domain: factor to a 1 V incident wave at the driven port
(None if unknown).
shape()[source]
Mesh line counts (nx, ny, nz) of the dump, from its first frame.
property spans[source]
Its colours span its own values (dump_info.json's "range": "data": a
temperature), not zero to its largest.
property static[source]
A steady quantity (a DC drop, a temperature): a frequency-domain dump
at 0 Hz alone.
class kicad2ems.core.fields.frames.Plane(u, v, img, names, axis, pos, signed)[source]
A 2D view: u, v axis coordinates (ascending, mm, KiCad axes), img[u, v],
axis names, title.
resample(n=900)[source]
img on a uniform grid (nearest mesh line), for display as an image:
(img, (u0, v0, du, dv)).
kicad2ems.core.fields.frames.default_axis(shape)[source]
The normal of a plane dump (its single-point axis), else z.
kicad2ems.core.fields.frames.ffmpeg_exe()[source]
The ffmpeg program: on PATH, or the one of the imageio-ffmpeg package;
None if neither.
kicad2ems.core.fields.frames.find_dumps(out_dir)[source]
Every field dump in <out>/<solver>/exc_*/, openEMS's first (the
dump_info.json names them before any file exists).
kicad2ems.core.fields.frames.frame_views(src, axis, index, component, frames=None, n_phase=24, log=True)[source]
The views of an animation: time domain -> each frame (default all);
frequency domain -> one period of Re(F e^(j phase)) at frame frames[0].
Returns [(Plane, label)] and the colour range.
kicad2ems.core.fields.frames.layout_patches(ax, geometry, layer, components=True)[source]
A horizontal layout projection in KiCad axes, independent of the sampled
field z.
kicad2ems.core.fields.frames.levels(values, signed, log, decades=3, span=False)[source]
Colour range (lo, hi) of a set of images: symmetric for signed
components, `decades` below the maximum for log magnitude; span
(DumpSource.spans): the values' own smallest to largest.
kicad2ems.core.fields.frames.outlines(geometry, axis, pos, near=0.3)[source]
Copper outlines in a view (KiCad mm): one (us, vs) polyline array pair
per ring or cut segment. z planes: the copper of layers within `near` mm; x
/ y cuts: copper crossing the cut, at its height.
kicad2ems.core.fields.frames.plane(mesh, data, axis, index, component='mag', phase=None)[source]
Cut a field (nx, ny, nz, 3) at mesh line `index` normal to `axis` (0/1/2)
-> Plane. component: 'mag' or 'x'/'y'/'z' (KiCad axes); complex (FD) data:
phase None -> |F| (peak), else Re(F e^(j phase)).
kicad2ems.core.fields.frames.read_vtr(path)[source]
openEMS time-domain dump frame (.vtr) -> (mesh {x, y, z} mm, field (nx,
ny, nz, 3) float32).
kicad2ems.core.fields.frames.render(pl, lo, hi, log, title, geometry=None, cbar='', size=(9, 5), dpi=110, layout=None)[source]
One view as an RGB image (h, w, 3) uint8, drawn with matplotlib (copper
outlined).
kicad2ems.core.fields.frames.save_animation(src, path, axis, index, component='mag', frames=None, fps=12, log=True, n_phase=24, lim=None, progress=None, layout=None)[source]
Write an animation of a dump cut (see frame_views) to .gif (Pillow) or
.mp4 (ffmpeg, H.264), one colour range for all frames (lim = (lo, hi), else
from all the frames). progress(i, n) is called per frame; returns the
path.
kicad2ems.core.fields.frames.save_fd_outputs(src, prefix, animate=None, log=True, n_phase=24)[source]
The files of a frequency-domain plane dump, per frequency:
<prefix>_<GHz>GHz.png (the peak |F|) and, with animate = 'gif' / 'mp4',
<prefix>_<GHz>GHz.<animate>: one period of Re(F e^(j phase)), the standing
waves. Returns [(freq Hz, path)].
kicad2ems.core.fields.frames.write_frames(imgs, path, fps=12)[source]
RGB frames ((h, w, 3) uint8, one size) to .gif (Pillow) or .mp4 (ffmpeg,
H.264); returns the path.