A collection of practical Python tools for electrical power engineering, developed for study, research, and engineering analysis.
The repository currently focuses on:
- LC and LCL filter design for grid-connected converters
- DIgSILENT PowerFactory to pandapower model conversion
- Newton-Raphson Jacobian extraction from pandapower
- Voltage sensitivity calculation using the inverse Jacobian
| Script | Description |
|---|---|
LC_filter_Calc.py |
Designs a three-phase LC output filter from converter rating, voltage, switching frequency, desired resonance frequency, and allowed voltage drop. Calculates the inductor, capacitor, damping resistor, estimated losses, and resonance-frequency checks. |
LCL_filter_Calc.py |
Designs a three-phase LCL filter for a grid-connected voltage-source converter. Calculates converter-side and grid-side inductors, filter capacitance, resonance frequency, damping resistor, losses, and basic design checks. |
PF_to_Pandapower_JSON.py |
Connects to DIgSILENT PowerFactory, runs a load flow, converts the active PowerFactory project to a pandapower network, and exports the converted model. Includes a workaround for ext_grid reactive-power capability handling in the pandapower PowerFactory converter. |
Export_Jacobian.py |
Loads a pandapower network, runs Newton-Raphson power flow, extracts and maps the Jacobian matrix, calculates its inverse, derives voltage sensitivities dV/dP and dV/dQ, and exports matrices and mapping files. |
Core packages:
pip install numpy pandas scipy pandapowerFor PF_to_Pandapower_JSON.py, you additionally need:
- a working DIgSILENT PowerFactory installation
- the PowerFactory Python module compatible with your installation
- correct paths to the PowerFactory installation and Python module
- an accessible PowerFactory project and active study case
Clone the repository:
git clone https://github.com/gordav003/Power-Engineering-Python-Toolkit.git
cd Power-Engineering-Python-ToolkitInstall the Python dependencies:
pip install numpy pandas scipy pandapowerRun:
python LC_filter_Calc.pyThe example at the bottom of the script defines:
- rated apparent power
- line-to-line voltage
- switching frequency
- desired resonance frequency
- grid frequency
- allowed inductor voltage drop
- inductor resistance estimate
- damping resistor factor
The main function is:
design_lc_filter(
S_n_va,
U_ll_v,
f_sw_hz,
f_res_hz,
f_grid_hz=50,
voltage_drop_pu=0.10,
inductor_resistance_percent=1.0,
damping_resistor_factor=1/3,
)It returns a pandas.DataFrame containing the calculated filter parameters and design checks.
Run:
python LCL_filter_Calc.pyThe main function is:
design_lcl_filter(
S_n_va,
U_ll_v,
f_sw_hz,
f_grid_hz=50,
voltage_drop_pu=0.10,
L1_ratio=0.7,
capacitor_reactive_power_pu=0.05,
inductor_resistance_percent=1.0,
damping_resistor_factor=1/3,
)The design procedure:
- Calculates the rated converter current.
- Determines total filter inductance from the allowed voltage drop.
- Splits the inductance into converter-side
L1and grid-sideL2components. - Calculates the filter capacitance from the allowed capacitor reactive power.
- Calculates the LCL resonance frequency.
- Estimates inductor resistances and copper losses.
- Calculates a series damping resistor for the capacitor branch.
- Checks whether the resonance frequency lies between approximately
10 * f_gridand0.5 * f_sw.
Before running PF_to_Pandapower_JSON.py, configure the paths at the top of the script:
PF_DIR = r"..."
PF_PYTHON = r"..."Also set the required PowerFactory project and output path:
project_name = "..."and:
path_dst = r"..."Then run:
python PF_to_Pandapower_JSON.pyThe script:
- loads the PowerFactory Python API
- connects to PowerFactory
- activates the selected project
- executes the active-study-case load flow
- converts the PowerFactory model using pandapower's PowerFactory converter
- prints a summary of the converted network
Note: PowerFactory Python integration depends on the PowerFactory version and its bundled/supported Python environment. Make sure the configured Python interpreter and PowerFactory module are compatible.
Before running Export_Jacobian.py, configure:
json_path = r"..."
output_dir = r"..."Then run:
python Export_Jacobian.pyThe script performs a Newton-Raphson power flow in pandapower and extracts the internal Jacobian:
| dP/dVa dP/dVm |
J = | |
| dQ/dVa dQ/dVm |
It identifies REF, PV, and PQ buses and creates row/column mappings between the internal PYPOWER/pandapower indices and the original pandapower buses.
The inverse Jacobian is then used to calculate voltage sensitivities:
dV/dPin kV/MWdV/dQin kV/MVAr
The configured output directory receives:
Jacobian.npz
Jacobian_column_mapping.csv
Jacobian_row_mapping.csv
Jacobian_bus_sets.npz
Voltage_sensitivities.npz
dV_dP_row_mapping.csv
dV_dP_column_mapping.csv
dV_dQ_row_mapping.csv
dV_dQ_column_mapping.csv
Jacobian.npz stores the sparse Newton-Raphson Jacobian, while Voltage_sensitivities.npz stores the calculated voltage-sensitivity matrices and base quantities.
The filter-design scripts are intended as engineering calculation and initial-design tools. Component values, resonance limits, damping, thermal loading, harmonic performance, converter control interactions, grid impedance variation, and component tolerances should be verified before applying the results to real hardware.
The Jacobian and sensitivity calculations depend on pandapower's internal power-flow representation. When upgrading pandapower, verify that the internal structures used by the script remain compatible.
Power-Engineering-Python-Toolkit/
├── Export_Jacobian.py
├── LCL_filter_Calc.py
├── LC_filter_Calc.py
├── PF_to_Pandapower_JSON.py
└── README.md
Suggestions, corrections, and additional power-engineering utilities are welcome through issues or pull requests.
Power Engineering Python Toolkit is intended to grow as a practical collection of reusable tools for power-system analysis, converter engineering, and research workflows.