kicad2ems.ipc.model¶
The KiCad plugin's model (no Qt here: testable without a display): the board as
kicad2ems sees it, its impedance map, the region and ports the user picks, and
the run they make.
plan = Plan(text, path)
# the board's text from KiCad's API (ipc.Live.board_text)
for done, total, nets in plan.map_steps(cache=path): ...
# the impedance map, a net (or pair) at a time, over worker
# processes, kept in a cache file: plan.lines
s = Session.load(path) or Session()
# region (KiCad mm, y down), ports, band, solvers
s.ports.append(plan.port_at(x, y, layer, tol, s))
# a port where the user clicked (model mm, y up)
s.use(plan.setup_for_nets(['D_P']))
# or: a run of a net / pair / set of nets (region, ports, parts)
values = run_values(s, plan, text, folder)
# the board snapshot and the settings of a kicad2ems run
res = results(out, stem)
# after the run: its S-parameters; comparison(res): against the
# line model
Coordinates: the plan view and the line model are in model mm (y up); KiCad, the
region and the port specs in KiCad mm (y down): y_kicad = -y_model.
- class kicad2ems.ipc.model.MapCache(path, plan, refcu, field=False)[source]¶
Map sections kept between sessions (a gzipped JSON file): per net (a pair: both legs), under a hash of the net's own copper (tracks, vias, pads, zones) and of the board's reference copper, stack and outline. An edit re-maps the nets it touches; a change of the planes or the stack re-maps everything. Classes and targets are applied afresh: they are not part of a net's sections.
- class kicad2ems.ipc.model.NetSetup(**kw)[source]¶
A run of a set of nets (Plan.setup_for_nets): nets (as picked, with pair partners), run_nets (those and the nets beyond series parts), region (KiCad mm), ports (port dicts, as Session.ports), parts ([dict(ref, kind, value, role 'series' | 'shunt', nets)]), board_ports (the board's own ports on the nets), grounds, notes.
- class kicad2ems.ipc.model.Plan(text, path='', classes=None)[source]¶
A board read from KiCad: raw (the importer's form), m (board.Board with every net, no ports needed, no parts), board (m.to_dict(): what the plan view draws), nc (the net classes and their impedance targets, netclass.NetClasses), signal (the routed nets that are neither ground nor #PWR), disabled (the #PWR ones), lines (the impedance map so far: the line model's drawing, each section with its class and target). classes: {net: [class names]} as KiCad reports them (ipc.Live.net_classes); None: the project file next to the board (<board>.kicad_pro).- map_steps(nets=None, stop=<function Plan.<lambda>>, jobs=None, cache=None, field=False)[source]¶
Build the impedance map of `nets` (default: every signal net; #PWR nets never); yields (nets done, nets in all, the nets just done) as it goes, the sections in self.lines. The reference copper excludes every signal net, so a trace is referenced to the planes and grounds, never to its neighbours. Nets the cache (a file: MapCache) holds for this copper come first, at once. The rest are mapped a unit at a time (a net, or a pair's two legs: only a pair couples, so the map does not depend on how nets are grouped), over `jobs` worker processes (default: one per performance core; 1: here, in this process). A unit at a time was also the fastest: 4.9 s for KiCad's CM5 demo, against 5.8 s in groups of 24 nets. field: every section by the field solver on the board's cut across it, not the formulas (slower).
- port_at(x, y, layer, tol, session, elements=None)[source]¶
A port where the user clicked (model mm): on the pad under the point (P<n>=REF.PAD), else on the centre line of the nearest trace section of `layer` within `tol` (P<n>@x,y,layer: KiCad mm, pointing along the trace; elements: the map's sections, default plan.lines). Returns the port dict (name, spec, net, layer, x, y model mm, what) or raises ValueError with why not.
- section_track(e)[source]¶
(layer, net, KiCad mm start, end) of a map section, to find its track in KiCad.
- setup_for_nets(nets, margin=2.0)[source]¶
The set-up of a run of `nets` (a net, a pair, a set of nets; a pair's other leg comes along): the region (KiCad mm) around their copper, `margin` mm beyond; the parts on them; ports at their other components. Returns NetSetup. Raises ValueError when there is nothing to simulate. Components: a two-pad R / L / C (a value kicad2ems reads, not DNP) from a net to ground stays in as a shunt part; one in series takes the net on its far side in too (and so on, up to MAX_EXTEND nets), a lumped part in the run. Every other footprint (ICs, connectors, other two-pad parts) gets a port on each of its pads on the nets: one leg of a differential port where it has pads on both legs of a pair. A track end that reaches nothing (no pad, via or track) gets a port too. Nets the board's own port footprints sit on keep those ports instead.
- class kicad2ems.ipc.model.Session(**kw)[source]¶
region (x0, y0, x1, y1 KiCad mm, or None), ports ([dict(name, spec, ...)]), cut_ports, fmin / fmax (GHz), solvers, classes (the net classes the map shows; None: the window's default), nets (the nets picked for a net run, [] for none), run_nets (those and the nets beyond their series parts: the run's nets with the grounds; [] for kicad2ems's auto), margin (mm around them), lines_field (the map's sections by the field solver), saved as <project>/kicad2ems/<board>/<board>_plugin.json.
- kicad2ems.ipc.model.analysis_command(name, values, board, out)[source]¶
(argv, missing [str]) of kicad2ems's analysis `name` (pcbqs's pdn or thermal) on the board, `values` beside its defaults: argv None and what it still needs where something is missing (its form in the window has the rest).
- kicad2ems.ipc.model.board_marks(session, elements, worst=12, off=0.1, size=0.6)[source]¶
What "Put on the board" draws (R-E26), in KiCad mm: [('line', (x0, y0), (x1, y1)) | ('text', (x, y), text, size)]: the region's outline, each port as a cross and its name, and a marker at the `worst` map sections whose Z0 is more than `off` from their class's target (Z0 and the target, at the section's middle).
- kicad2ems.ipc.model.comparison(res, floor=-20.0)[source]¶
[(term, max |S| difference in dB where the full-wave |S| is above `floor` dB (None: nowhere), at GHz, max |dS| (the complex difference, linear))] of each full-wave solver against the line model. Below the floor (a stop band, a well-matched reflection) a dB difference says little; |dS| covers it.
- kicad2ems.ipc.model.gpu_offer()[source]¶
'slangpy>=0.43' where gfdtd could run on a Vulkan GPU here but slangpy is not installed (the plugin's own environment has gfdtd on the CPU, ~15x slower: R-C16), else None. slangpy has wheels for Linux (glibc 2.34 and later), Windows and Apple-silicon macOS, so it is offered, not required.
- kicad2ems.ipc.model.legend(lines)[source]¶
(reference ohm, half span ohm, low, high) of the map's colours.
- kicad2ems.ipc.model.map_bands(path, bands=6)[source]¶
(levels, [(band, outer ring, [holes])] in KiCad mm) of a plane map: its value on the copper (0 or NaN off it) in `bands` equal steps between its least and most, each step's region as polygons (matplotlib's contours).
- kicad2ems.ipc.model.map_marks(levels, polys, label, unit, x0, y0, layers=('User.1', 'User.2', 'User.3', 'User.4', 'User.5', 'User.6', 'User.7', 'User.8'), size=0.8)[source]¶
What "Map on the board" draws: each band's polygons on its own user layer (filled, its colour too, where KiCad keeps an item's), and a legend at (x0, y0) on the last layer: [('poly', layer, outer, holes, colour) | ('text', (x, y), text, size, layer)].
- kicad2ems.ipc.model.map_sources(folder)[source]¶
[(label, path, unit)] of the plane maps a result folder holds (its viewer's dumps: a DC drop's mV, a temperature's C), each a scalar on a layer's grid; the current densities left out.
- kicad2ems.ipc.model.outside(session, port)[source]¶
Is a port (model mm) outside the session's region? (kicad2ems leaves such ports out of the run.)
- kicad2ems.ipc.model.region_of_box(x0, y0, x1, y1, margin=1.0)[source]¶
A region (KiCad mm) from two corners, grown by `margin` mm on every side.
- kicad2ems.ipc.model.results(out_dir, stem)[source]¶
The S-parameters of a finished run (<out>/<stem>_run.json and its Touchstone files), or None: dict(freq Hz, solved [dict(key, label, names, S, line: is it the line model)], reference (the first solver's key), compare {key: the run's table of it against the reference}, warnings).
- kicad2ems.ipc.model.run_values(session, plan, text, folder, stem)[source]¶
The settings of a kicad2ems run of the session: the board as KiCad has it now (unsaved edits included), written to <folder>/<stem>.kicad_pcb; results in <folder>/out. Nets: the session's run_nets with the ground nets, else auto (those under the ports + ground). A net run also solves the line model, as a reference (fast = auto: compared in the report and the window; a warning, not a failure, when it cannot run).