How energinet-simtools/mtb works
1. What this repository is
MTB is a Python-driven automation harness for running and comparing electrical grid studies across two external simulation platforms: DIgSILENT PowerFactory for RMS/PDT studies and PSCAD for EMT studies. The repo is not the plant model itself; it is the orchestration, data preparation, execution, and post-processing layer around those tools.
2. Top-level architecture
The code splits into three main concerns: case setup, simulation execution, and result visualization/QA. The workflow is driven by a study definition sheet (testcases.xlsx), configuration files (config.ini, plotter/config.ini), and model files for each simulator (.pfd, .pswx, .pscx, plus PSCAD/PowerFactory components).
3. Study definition and run configuration
case_setup.py appears to translate the workbook-based study matrix into executable simulation cases. This is the boundary where a user-defined set of faults, operating points, signals, and comparison scenarios becomes a runnable batch. The repository’s “source of truth” for what to execute is therefore the spreadsheet, not hard-coded Python.
4. PowerFactory execution path
execute_pf.py is the PowerFactory runner, likely using the local PowerFactory Python environment described in the README. It bridges MTB case definitions into PowerFactory study execution, then writes results out for comparison. The sim_interface.py module suggests there is a shared abstraction layer for simulator-specific operations.
5. PSCAD execution path
execute_pscad.py and batch_execute_pscad.py handle PSCAD runs, including batch execution of multiple cases. The repo also includes pscad_synchronize_pgbs.py and pscad_update_ums.py, which indicate model-maintenance automation around PSCAD project contents. The file interface.f is a key boundary artifact: it is the Fortran source for the PSCAD-side MTB interface component embedded in the EMT model.
6. Model integration boundary
The repo assumes MTB components are inserted into the plant models themselves:
- PowerFactory model files: .pfd
- PSCAD project files: .pswx / .pscx
- Example setups are provided in setup_examples/
This means the automation layer does not replace the simulator models; it configures and controls them externally while the model-specific MTB component exposes signals and hooks for studies.
7. Simulation outputs and intermediate formats
PSCAD output handling is a notable subsystem. The plotter/process_psout.py, plotter/psout_to_csv.py, plotter/read_and_write_functions.py, and related helpers imply a pipeline that converts PSCAD output files into tabular data for analysis. The repository also contains reference/recorded outputs under recordings/, which likely serve as comparison baselines or sample signals.
8. Result processing and comparison
The plotter/ package is responsible for turning simulation outputs into comparative plots and analysis artifacts. Its structure shows concerns for:
- result objects (Result.py)
- figure/cursor configuration (Figure.py, Cursor.py, CSV setup files)
- sampling and downsampling (sampling_functions.py, down_sampling_method.py)
- plotting and guide logic (plotter.py, guide_functions.py)
This is the main presentation layer for comparing PowerFactory and PSCAD responses.
9. Quality assurance and model inspection tools
utility_scripts/ contains one-off and diagnostic tools that support model governance rather than simulations:
- extracting component data from PowerFactory
- comparing PSCAD and PowerFactory component data
- getting DSL checksums and relay data
- listing PSCAD output signals
- recovering .psout files
- cleaning project definitions
- checking PowerFactory models
These scripts form a QA/validation subsystem around the two model ecosystems.
10. Repository artifacts and examples
The repo includes example projects and inputs to help users wire MTB into their own models:
- setup_examples/ with sample PowerFactory and PSCAD setups
- recordings/ with example waveforms and measured data
- MTB.pfd / MTB.pslx as likely core project artifacts
- powerfactory.pyi as an interface stub for PowerFactory scripting support
11. End-to-end data flow
The practical flow is: define studies in Excel → generate/configure cases → execute the relevant PowerFactory and PSCAD simulations → collect outputs → convert/normalize outputs where needed → plot and compare results. The important architectural boundary is that execution happens inside external simulators, while MTB manages orchestration and post-processing in Python.
12. Runtime and tooling dependencies that matter architecturally
The repository depends on the simulator runtimes themselves, especially the tested PowerFactory and PSCAD Python environments mentioned in the README. Those external engines are not optional plugins; they are the primary compute backends. The Python code here is an integration layer that depends on the simulators’ APIs and project formats.
Main entry points: case_setup.py Case setup · execute_pscad.py PSCAD runner · execute_pf.py PF runner · process_psout.py PSOUT flow
Components 20
Orchestration
Study definition, case generation, and simulator execution entrypoints.
- Study sheet · Spreadsheet that defines the study matrix and run scenarios.
testcases.xlsx - Main config · Primary repository configuration for orchestration and execution.
config.ini - Case setup · Translates workbook studies into executable cases and parameters.
case_setup.py - Setup examples · Sample PowerFactory and PSCAD project setups.
setup_examples/MTB_Setup_Example.pfd
Simulation Backends
Shared interface and simulator-specific runners.
- PF runner · Runs PowerFactory studies and captures outputs for comparison.
execute_pf.py - PSCAD runner · Runs PSCAD cases for EMT studies.
execute_pscad.py - Batch PSCAD · Coordinates multi-case PSCAD execution.
batch_execute_pscad.py - Sim interface · Shared abstraction for simulator-specific operations.
sim_interface.py - PowerFactory · External RMS/PDT simulation backend.
- PSCAD · External EMT simulation backend.
- MTB interface · Fortran-side interface embedded in the PSCAD model.
interface.f - PF stub · Python interface stub for PowerFactory scripting support.
powerfactory.pyi
Results & Plotting
PSCAD output conversion, result processing, and comparative plotting.
- Plotter · Package that converts outputs into comparative plots and analysis artifacts.
plotter/plotter.py - PSOUT flow · Parses PSCAD output files and prepares tabular data.
plotter/process_psout.py - Results merge · Processes normalized results for comparison and reporting.
plotter/process_results.py - I/O helpers · Shared read/write helpers for plotter workflows.
plotter/read_and_write_functions.py - Recordings · Sample waveforms and measurement files used as references.
recordings/DK1_Voltage.csv
QA Tools
Maintenance and validation scripts for model and project data.
- PF data tools · Extracts and compares PowerFactory and PSCAD component data.
utility_scripts/get_component_data_from_powerfactory.py - Model checks · Validates model contents, checksums, relay data, and project definitions.
utility_scripts/check_powerfactory_model.py - PSOUT tools · Lists and recovers PSCAD output files and signals.
utility_scripts/list_psout_signals.py
Connections 23
- Study sheet → Case setup: defines · Study matrix drives case generation.
- Main config → Case setup: configures · Run settings feed case preparation.
- Case setup → PF runner: builds cases for · Prepared cases are handed to the PowerFactory runner.
- Case setup → PSCAD runner: builds cases for · Prepared cases are handed to the PSCAD runner.
- Case setup → Batch PSCAD: batches for · Case sets can be grouped for batch EMT execution.
- Sim interface → PF runner: adapts · Shared simulator abstraction used by the PF path.
- Sim interface → PSCAD runner: adapts · Shared simulator abstraction used by the PSCAD path.
- PF runner → PowerFactory: runs in · PF studies execute inside the external simulator.
- PSCAD runner → PSCAD: runs in · PSCAD studies execute inside the external simulator.
- Batch PSCAD → PSCAD: orchestrates · Batch execution manages multiple PSCAD runs.
- MTB interface → PSCAD: embedded in · Fortran interface is part of the PSCAD-side model integration.
- PSCAD runner → MTB interface: exposes signals · Runner depends on the model interface boundary.
- PSCAD → PSOUT flow: produces · PSCAD output files feed the conversion pipeline.
- PSOUT flow → I/O helpers: uses · Parsing and serialization share common I/O helpers.
- PSOUT flow → Results merge: feeds · Converted outputs continue into result processing.
- Results merge → Plotter: used by · Result processing supports the plotting workflow.
- Plotter → Recordings: compares with · Reference recordings act as comparison baselines.
- PF data tools → PowerFactory: inspects · Scripts inspect PF component data and project state.
- Model checks → PowerFactory: validates · Checks target PowerFactory models and project definitions.
- PSOUT tools → PSCAD: inspects · Tools inspect PSCAD outputs and recover missing files.
- Setup examples → PF runner: demonstrates · Sample setups illustrate the PF execution path.
- Setup examples → PSCAD runner: demonstrates · Sample setups illustrate the PSCAD execution path.
- PF stub → PF runner: supports · Type stub supports PF scripting integration.