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()

Complete network reduction analysis workflow including:

  1. Data loading and preprocessing
  2. Original network PTDF/TTC analysis
  3. Representative node selection
  4. Kron reduction
  5. Reduced network analysis
  6. Optimization of equivalent capacities
  7. Results comparison and export

Returns

Tuple containing:

  • ttc_results: Original network TTC calculations
  • ptdfreducedresults: Reduced network PTDF calculations
  • equivalentcapacitiesdf: Optimized equivalent capacities

Data Directory

Modify the inputdatadir and outputdatadir variables to change the location.

Output Files

  • BusIDMap_QP.csv: Mapping of bus names to numerical IDs
  • LineDetailsQP.csv: Comprehensive line information
  • RepresentativeNodesQP.csv: Selected representative nodes
  • TTCOriginalNetwork_QP.csv: Original network TTC values
  • PTDFReducedNetwork_QP.csv: Reduced network PTDF values
  • EquivalentCapacitiesQP.csv: Optimized synthetic line capacities
  • TTCComparisonQP.csv: Comparison of original vs equivalent TTC values
source
ElectricityNetworkReduction.rename_busesFunction
rename_buses(nodes_df, generators_df, lines_df, tie_lines_df, Sbase)

Rename buses to uppercase, create numerical mapping, and convert data to per-unit. Returns processed line DataFrames and node information.

source
ElectricityNetworkReduction.select_representative_nodesMethod
select_representative_nodes(Ybus, node_info)

Select a single representative node (RN) from each unique 'Zone' based on the highest interconnection degree.

Arguments

  • Ybus::SparseMatrixCSC{ComplexF64}: Network admittance matrix
  • node_info::DataFrame: Node information DataFrame

Returns

  • rep_nodes::DataFrame: DataFrame with selected representative nodes
  • node_info::DataFrame: Updated nodeinfo with isrepresentative flag set
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.

  • 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(nodes_df, zone) Identifies boundary or representative nodes within each zone based on interconnection degree and network topology.

  • 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.

  • CONFIG Global configuration object containing parameters such as optimization_type, lambda, ptdf_epsilon, base power, and unit settings.

  • reset_config!() Resets all configuration parameters to their default values.


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
kron-reduction.jlMathematical node elimination
main-analysis.jlThe top-level wrapper executing the full pipeline
optimization.jlJuMP models for LP, QP, and MILP formulations [cite: 11]
ptdf-calculations.jlDC power flow sensitivity analysis
representative-nodes.jlGroups buses and identifies the "boundary" nodes to keep based on their connectivity degree
ttc-calculations.jlTransfer capacity evaluation [cite: 10]
ybus-formation.jlPhysical matrix assembly ($Y_{bus}$)