Home#

NPAP NPAP

A Python library for partitioning and aggregation of spatial network graphs, with a special focus in electrical power systems

Get Started

GitHub Repository

Quick Start ✨
import npap
from npap import AggregationMode

# 1. Initialize the main manager
manager = npap.PartitionAggregatorManager()

# 2. Load data
manager.load_data(strategy="networkx_direct", graph=your_graph)

# 2.1. Aggregate parallel edges (if applicable)
manager.aggregate_parallel_edges(
    edge_properties={"p_max": "average", "x": "equivalent_reactance"},
    default_strategy="average",
    warn_on_defaults=False,
)

# 3. Create partition result
partition_result = manager.partition(strategy="geographical_kmeans", n_clusters=250)

# 3.1. Plot the partitioned network
manager.plot_network(style="clustered", title="Partitioned Network")

# 4. Aggregate the network based on a given AggregationMode
aggregated_network = manager.aggregate(mode=AggregationMode.GEOGRAPHICAL)