pypsa.clustering.ClusteringAccessor.cluster_spatially_by_hac

pypsa.clustering.ClusteringAccessor.cluster_spatially_by_hac#

ClusteringAccessor.cluster_spatially_by_hac(n_clusters: int, buses_i: pd.Index | None = None, branch_components: Collection[str] | None = None, feature: pd.DataFrame | None = None, affinity: str | Callable = 'euclidean', linkage: str = 'ward', line_length_factor: float = 1.0, **kwargs: Any) Clustering#

Cluster the network using Hierarchical Agglomerative Clustering.

Parameters:
  • n (pypsa.Network) – The buses must have coordinates x, y.

  • buses_i (None | pandas.Index, default=None) – Subset of buses to cluster. If None, all buses are considered.

  • branch_components (List, default=["Line", "Link"]) – Subset of all branch_components in the network.

  • feature (None | pandas.DataFrame, default=None) – Feature to be considered for the clustering. The DataFrame must be indexed with buses_i. If None, all buses have the same similarity.

  • affinity (str or Callable, default=’euclidean’) – 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 (‘ward’, ‘complete’, ‘average’ or ‘single’, default=’ward’) – 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 (float, default=1.0) – Factor to multiply the spherical distance between two new buses in order to get new line lengths.

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

Returns:

Clustering – A named tuple containing network, busmap and linemap

Return type:

named tuple