API Reference

ElectricityNetworkReduction.convert_line_to_pu!Method
convert_line_to_pu!(lines_df::DataFrame, Sbase::Float64; in_pu::Bool=false)

Convert line parameters to per-unit values based on system base power. If in_pu is true, assumes R, X, B are already in per-unit and only converts capacity.

source
ElectricityNetworkReduction.create_ttc_results_from_optimizationMethod
create_ttc_results_from_optimization(
ttc_vals::Vector{Float64},
ttc_canonical::DataFrame;
model=model,
Type = CONFIG.optimization_type,
synth_lines::Vector{Tuple{Int,Int}} = Tuple{Int,Int}[],
binding_dict::Union{Dict,Nothing} = nothing
)

Create TTC results directly from optimization variables.

source
ElectricityNetworkReduction.export_bus_id_mapMethod
export_bus_id_map(node_info, export_path)

Export a CSV file containing the mapping between old bus names and new numerical IDs.

Arguments

  • node_info::DataFrame: Node information with oldname and newid columns
  • export_path::String: Path where the CSV file will be saved

Output CSV Format

  • old_name: Original bus names from input data
  • new_id: Numerical IDs assigned during processing
source
ElectricityNetworkReduction.export_detailed_line_infoMethod
export_detailed_line_info(lines_df, tielines_df, export_path)

Export comprehensive line information including both original names and numerical IDs.

Arguments

  • lines_df::DataFrame: Regular transmission lines data
  • tielines_df::DataFrame: Tie lines data
  • export_path::String: Path where the CSV file will be saved

Output CSV Columns

  • EIC_Code: European Identification Code for the line
  • Fromnode, Tonode: Original bus names
  • NewIDFrom, NewIDTo: Numerical bus IDs
  • Voltage_level: Operating voltage level
  • Length_km: Line length in kilometers
  • CapacityMW, Capacitypu: Line capacity in MW and per-unit
  • Rpu, Xpu, B_pu: Line parameters in per-unit
  • IsTieLine: Boolean flag indicating if this is a tie line
source
ElectricityNetworkReduction.kron_reduce_ybusMethod
kron_reduce_ybus(Ybus, rep_node_ids)

Perform Kron reduction on the original Ybus matrix to eliminate non-representative nodes.

The Kron reduction technique eliminates internal nodes while preserving the electrical relationships between the representative nodes. This creates an equivalent network with fewer nodes but equivalent transfer characteristics.

Arguments

  • Ybus::SparseMatrixCSC{ComplexF64}: Original network admittance matrix
  • rep_node_ids::Vector{Int}: Indices of representative nodes to retain

Returns

  • Y_kron::SparseMatrixCSC{ComplexF64}: Reduced admittance matrix

Mathematical Background

The Kron reduction partitions the admittance matrix as:

Y = [K   L_T]
    [L   M  ]

where K connects representative nodes, M connects eliminated nodes, and L connects representative to eliminated nodes.

The reduced matrix is: Ykron = K - LT * M^(-1) * L

source
ElectricityNetworkReduction.main_full_analysisMethod
main_full_analysis(input_data_dir, output_data_dir)

Complete network reduction analysis workflow including:

  1. Data loading and preprocessing
  2. Island detection (optional, when CONFIG.enable_plots = true)
  3. Original network Y-bus and TTC/PTDF analysis
  4. Representative node selection
  5. Kron reduction
  6. Virtual line filtering (when CONFIG.allow_virtual_lines = false)
  7. Reduced network PTDF analysis
  8. Optimization of equivalent capacities
  9. Results comparison and export

Returns

Nothing. All results are written to CSV files in output_data_dir.

Output Files

All filenames use CONFIG.suffix as a postfix:

  • Bus_ID_Map_<suffix>.csv: Mapping of original bus names to sequential integer IDs
  • Line_Details_<suffix>.csv: Comprehensive line information
  • Representative_Nodes_<suffix>.csv: Selected representative nodes per zone
  • TTC_Original_Network_<suffix>.csv: Original network TTC values
  • PTDF_Reduced_Network_<suffix>.csv: Reduced network PTDF values
  • Equivalent_Capacities_<suffix>.csv: Optimized synthetic line capacities and reactances
  • TTC_Comparison_<suffix>.csv: Comparison of original vs equivalent TTC values
  • Network_Original_<suffix>.png: Original network plot (only when enable_plots = true)
  • Network_Reduced_<suffix>.png: Reduced network plot (only when enable_plots = true)
  • Network_Original_vs_Reduced_<suffix>.png: Side-by-side comparison plot (only when enable_plots = true)
source
ElectricityNetworkReduction.plot_networkMethod
plot_network(g, node_info, lines_df; title, n_size, f_size, show_names)

Plot a network graph with nodes coloured by island (connected component). Only called when CONFIG.enable_plots = true. Uses Latitude/Longitude columns for geo-layout if present in node_info, otherwise uses a spring layout.

source
ElectricityNetworkReduction.plot_original_vs_reducedMethod
plot_original_vs_reduced(g_orig, nodes_orig, lines_orig, g_red, nodes_red, lines_red, output_path)

Plot original and reduced networks side-by-side (1400×700 px) and save to output_path. Only called when CONFIG.enable_plots = true.

source
ElectricityNetworkReduction.rename_busesFunction
rename_buses(nodes_df, generators_df, lines_df, tie_lines_df, Sbase)

Rename buses, create numerical mapping, convert to per-unit, and preserve the IsRepresentative column from Excel.

source
ElectricityNetworkReduction.select_representative_nodesMethod
select_representative_nodes(Ybus::SparseMatrixCSC{ComplexF64}, node_info::DataFrame)

Select representative nodes using one of two modes controlled by CONFIG.repnodemode:

  • "auto" (default): Select top CONFIG.rep_node_k_per_zone highest-degree nodes per zone
  • "manual_excel": Use nodes marked in column IsRepresentative in the Nodes sheet

If manual mode is selected but the column is missing, falls back to auto mode with a warning. Always ensures :isrepresentative column exists in nodeinfo.

source

Exported Functions

This section provides an overview of the main exported functions in ElectricityNetworkReduction.jl, grouped by their role in the overall workflow. These functions are designed to support data ingestion, physical modeling, network reduction, optimization, and result export.


1. Data Loading and Cleaning

These functions handle the initial stage of reading input data from Excel or CSV files and preparing it for mathematical modeling.

  • load_excel_data(file_path) Reads the mandatory Lines, Tielines, Nodes, and Generators sheets from an Excel input file and returns structured data frames.

  • clean_line_data(lines_df) Cleans branch data by removing self-loops and assigning unique identifiers to missing or incomplete EIC codes.

  • process_tielines(tielines_df) Processes inter-zonal transmission lines to ensure consistent representation of connections across zone boundaries.

  • rename_buses(nodes_df, lines_df, tielines_df) Assigns sequential integer IDs to all buses and returns updated data frames alongside a mapping from original to new IDs. Used internally to normalise bus identifiers before matrix construction.

  • convert_line_to_pu!(df, baseMVA) Converts line parameters from physical units (Ohms) to per-unit values using Voltage (kV) and Current (A), if required. This function modifies the data frame in place.


2. Network Physics and Matrix Construction

These functions construct the mathematical representation of the electrical network.

  • form_ybus_with_shunt(nodes, lines) Assembles the bus admittance matrix ($Y_{bus}$), including the contribution of line shunt susceptances.

  • calculate_ptdfs_dc_power_flow(ybus) Computes Power Transfer Distribution Factors (PTDFs) using DC power flow assumptions.

  • calculate_ttc_from_ptdfs(ptdfs, capacities) Calculates the original Total Transfer Capacities (TTCs) for a set of transactions based on PTDFs and line limits.


3. Network Reduction Logic

These functions implement the core algorithms used to reduce the size of the network while preserving its physical behavior.

  • select_representative_nodes(ybus, node_info, numbered_lines, numbered_tielines) Identifies representative nodes within each zone. Supports two modes controlled by CONFIG.rep_node_mode:

    • "auto": selects the top CONFIG.rep_node_k_per_zone nodes per zone ranked by interconnection degree (line capacity as tiebreaker).
    • "manual_excel": reads the IsRepresentative column from the Nodes sheet.
  • kron_reduce_ybus(ybus, representative_nodes) Applies Kron reduction to eliminate internal nodes while preserving sensitivity relationships between representative nodes.


4. Capacity Optimization

These functions use mathematical programming to determine synthetic line capacities for the reduced network.

  • optimize_equivalent_capacities(ttc_orig, ptdf_red) Primary interface for solving the capacity fitting problem using LP, QP, or MIQP formulations.

5. Workflow and Configuration

These functions and objects control the full end-to-end execution of the model.

  • main_full_analysis(input_dir, output_dir) High-level wrapper that executes the complete network reduction pipeline, from data loading to result export. Returns nothing; all results are written to CSV files in output_dir.

  • CONFIG Global configuration object. Key parameters: optimization_type, lambda, ptdf_epsilon, base, bus_names_as_int, in_pu, allow_virtual_lines, rep_node_mode, rep_node_k_per_zone, enable_plots. See the Model Usage guide for details.

  • reset_config!() Resets all configuration parameters to their default values. Always call this between case studies in batch runs.


6. Visualisation (optional)

Network plots are generated when CONFIG.enable_plots = true. The plotting functions use Plots and GraphRecipes, which are regular dependencies installed with the package.

  • plot_network(g, node_info, lines_df; title, n_size, f_size, show_names) Plots a single network. Nodes are coloured by connected component (island). Uses Latitude/Longitude columns for geo-layout if present in the Nodes sheet, otherwise uses a spring layout.

  • plot_original_vs_reduced(g_orig, nodes_orig, lines_orig, g_red, nodes_red, lines_red, output_path) Produces a side-by-side 1400×700 px comparison plot of the original and reduced networks, saved to output_path.


Internal Module Structure

The package follows a modular architecture, with each file responsible for a specific component of the workflow.

FileResponsibility
config.jlCentralized settings and global constants
data-loading.jlExcel/CSV ingestion and per-unit normalization
export-functions.jlCSV export and reporting utilities
island-detection.jlConnected-component detection (used when enable_plots = true)
kron-reduction.jlMathematical node elimination
main-analysis.jlThe top-level wrapper executing the full pipeline
network-visualisation.jlNetwork plot functions (only called when enable_plots = true)
optimization.jlJuMP models for LP, QP, and MILP formulations
ptdf-calculations.jlDC power flow sensitivity analysis
representative-nodes.jlGroups buses and identifies boundary nodes per zone
ttc-calculations.jlTransfer capacity evaluation
ybus-formation.jlPhysical matrix assembly ($Y_{bus}$)