Skip to content

ClusteringAccessor

ClusteringAccessor(n: Network)

Clustering accessor for clustering a network spatially and temporally.

Clustering

Methods:

pypsa.Network.cluster.busmap_by_greedy_modularity

busmap_by_greedy_modularity(
    *args: Any, **kwargs: Any
) -> Series

Create a busmap according to Clauset-Newman-Moore greedy modularity maximization.

See [CNM2004_1]_ for more details.

Parameters:

  • n_clusters (int) –

    Final number of clusters desired.

  • buses_i

    Subset of buses to cluster. If None, all buses are considered.

Returns:

  • busmap ( Series ) –

    Mapping of n.buses to clusters (indexed by non-negative integers).

References

[CNM2004_1] Clauset, A., Newman, M. E., & Moore, C. "Finding community structure in very large networks." Physical Review E 70(6), 2004.

pypsa.Network.cluster.busmap_by_hac

busmap_by_hac(*args: Any, **kwargs: Any) -> Series

Create a busmap according to Hierarchical Agglomerative Clustering.

Parameters:

  • n (Network) –

    Network instance.

  • n_clusters (int) –

    Final number of clusters desired.

  • buses_i

    Subset of buses to cluster. If None, all buses are considered.

  • branch_components

    Subset of all branch_components in the network. If None, all branch_components are considered.

  • feature

    Feature to be considered for the clustering. The DataFrame must be indexed with buses_i. If None, all buses have the same similarity.

  • affinity

    Metric used to compute the linkage. Can be “euclidean”, “l1”, “l2”, “manhattan”, “cosine”, or “precomputed”. If linkage is “ward”, only “euclidean” is accepted. If “precomputed”, a distance matrix (instead of a similarity matrix) is needed as input for the fit method.

  • linkage

    Which linkage criterion to use. The linkage criterion determines which distance to use between sets of observation. The algorithm will merge the pairs of cluster that minimize this criterion. - ‘ward’ minimizes the variance of the clusters being merged. - ‘average’ uses the average of the distances of each observation of the two sets. - ‘complete’ or ‘maximum’ linkage uses the maximum distances between all observations of the two sets. - ‘single’ uses the minimum of the distances between all observations of the two sets.

  • kwargs (Any, default: {} ) –

    Any remaining arguments to be passed to Hierarchical Clustering (e.g. memory, connectivity).

Returns:

  • busmap ( Series ) –

    Mapping of n.buses to clusters (indexed by non-negative integers).

pypsa.Network.cluster.busmap_by_kmeans

busmap_by_kmeans(*args: Any, **kwargs: Any) -> Series

Create a bus map from the clustering of buses in space with a weighting.

Parameters:

  • n (Network) –

    The buses must have coordinates x, y.

  • bus_weightings (Series) –

    Series of integer weights for buses, indexed by bus names.

  • n_clusters (int) –

    Final number of clusters desired.

  • buses_i (None | Index) –

    If not None (default), subset of buses to cluster.

  • kwargs (Any, default: {} ) –

    Any remaining arguments to be passed to KMeans (e.g. n_init, n_jobs).

Returns:

  • busmap ( Series ) –

    Mapping of n.buses to k-means clusters (indexed by non-negative integers).

pypsa.Network.cluster.cluster_by_busmap

cluster_by_busmap(*args: Any, **kwargs: Any) -> Clustering

Cluster the network spatially by busmap.

This function calls pypsa.Network.cluster.get_clustering_from_busmap internally. For more information, see the documentation of that function.

Returns:

pypsa.Network.cluster.cluster_spatially_by_greedy_modularity

cluster_spatially_by_greedy_modularity(
    *args: Any, **kwargs: Any
) -> Clustering

Create a busmap according to Clauset-Newman-Moore greedy modularity maximization.

See [CNM2004_2]_ for more details.

Parameters:

  • n_clusters (int) –

    Final number of clusters desired.

  • buses_i

    Subset of buses to cluster. If None, all buses are considered.

  • line_length_factor

    Factor to multiply the spherical distance between two new buses to get new line lengths.

Returns:

  • Clustering ( named tuple ) –

    A named tuple containing network, busmap and linemap.

References

[CNM2004_2] Clauset, A., Newman, M. E., & Moore, C. "Finding community structure in very large networks." Physical Review E 70(6), 2004.

pypsa.Network.cluster.cluster_spatially_by_hac

cluster_spatially_by_hac(
    *args: Any, **kwargs: Any
) -> Clustering

Cluster the network using Hierarchical Agglomerative Clustering.

Parameters:

  • n_clusters (int) –

    Final number of clusters desired.

  • buses_i

    Subset of buses to cluster. If None, all buses are considered.

  • branch_components

    Subset of all branch_components in the network.

  • feature

    Feature to be considered for the clustering. The DataFrame must be indexed with buses_i. If None, all buses have the same similarity.

  • affinity

    Metric used to compute the linkage. Can be “euclidean”, “l1”, “l2”, “manhattan”, “cosine”, or “precomputed”. If linkage is “ward”, only “euclidean” is accepted. If “precomputed”, a distance matrix (instead of a similarity matrix) is needed as input for the fit method.

  • linkage

    Which linkage criterion to use. The linkage criterion determines which distance to use between sets of observation. The algorithm will merge the pairs of cluster that minimize this criterion. - ‘ward’ minimizes the variance of the clusters being merged. - ‘average’ uses the average of the distances of each observation of the two sets. - ‘complete’ or ‘maximum’ linkage uses the maximum distances between all observations of the two sets. - ‘single’ uses the minimum of the distances between all observations of the two sets.

  • line_length_factor

    Factor to multiply the spherical distance between two new buses in order to get new line lengths.

  • kwargs (Any, default: {} ) –

    Any remaining arguments to be passed to Hierarchical Clustering (e.g. memory, connectivity).

Returns:

  • Clustering ( named tuple ) –

    A named tuple containing network, busmap and linemap

pypsa.Network.cluster.cluster_spatially_by_kmeans

cluster_spatially_by_kmeans(
    *args: Any, **kwargs: Any
) -> Clustering

Cluster the network according to k-means clustering of the buses.

Buses can be weighted by an integer in the series bus_weightings.

Note that this clustering method completely ignores the branches of the network.

Parameters:

  • n (Network) –

    The buses must have coordinates x, y.

  • bus_weightings (Series) –

    Series of integer weights for buses, indexed by bus names.

  • n_clusters (int) –

    Final number of clusters desired.

  • line_length_factor (float) –

    Factor to multiply the spherical distance between new buses in order to get new line lengths.

  • kwargs (Any, default: {} ) –

    Any remaining arguments to be passed to KMeans (e.g. n_init, n_jobs)

Returns:

  • Clustering ( named tuple ) –

    A named tuple containing network, busmap and linemap

pypsa.Network.cluster.get_clustering_from_busmap

get_clustering_from_busmap(
    *args: Any, **kwargs: Any
) -> Clustering

Get a clustering result from a busmap.