cluster_network, simplify_network: Improve debugging facilities for clustering
This commit is contained in:
parent
4247051c3c
commit
6feebedc0d
@ -111,7 +111,11 @@ def distribute_clusters_optim(n, n_clusters, solver_name=None):
|
|||||||
|
|
||||||
return pd.Series(m.n.get_values(), index=L.index).astype(int)
|
return pd.Series(m.n.get_values(), index=L.index).astype(int)
|
||||||
|
|
||||||
def busmap_for_n_clusters(n, n_clusters):
|
def busmap_for_n_clusters(n, n_clusters, **kmeans_kwds):
|
||||||
|
kmeans_kwds.setdefault('n_init', 1000)
|
||||||
|
kmeans_kwds.setdefault('max_iter', 30000)
|
||||||
|
kmeans_kwds.setdefault('tol', 1e-6)
|
||||||
|
|
||||||
n.determine_network_topology()
|
n.determine_network_topology()
|
||||||
|
|
||||||
if 'snakemake' in globals():
|
if 'snakemake' in globals():
|
||||||
@ -123,10 +127,11 @@ def busmap_for_n_clusters(n, n_clusters):
|
|||||||
|
|
||||||
def busmap_for_country(x):
|
def busmap_for_country(x):
|
||||||
prefix = x.name[0] + x.name[1] + ' '
|
prefix = x.name[0] + x.name[1] + ' '
|
||||||
|
logger.debug("Determining busmap for country {}".format(prefix[:-1]))
|
||||||
if len(x) == 1:
|
if len(x) == 1:
|
||||||
return pd.Series(prefix + '0', index=x.index)
|
return pd.Series(prefix + '0', index=x.index)
|
||||||
weight = weighting_for_country(n, x)
|
weight = weighting_for_country(n, x)
|
||||||
return prefix + busmap_by_kmeans(n, weight, n_clusters[x.name], buses_i=x.index, n_init=1000, max_iter=30000, tol=1e-6)
|
return prefix + busmap_by_kmeans(n, weight, n_clusters[x.name], buses_i=x.index, **kmeans_kwds)
|
||||||
return n.buses.groupby(['country', 'sub_network'], group_keys=False).apply(busmap_for_country)
|
return n.buses.groupby(['country', 'sub_network'], group_keys=False).apply(busmap_for_country)
|
||||||
|
|
||||||
def plot_busmap_for_n_clusters(n, n_clusters=50):
|
def plot_busmap_for_n_clusters(n, n_clusters=50):
|
||||||
|
@ -241,16 +241,18 @@ if __name__ == "__main__":
|
|||||||
from vresutils.snakemake import MockSnakemake, Dict
|
from vresutils.snakemake import MockSnakemake, Dict
|
||||||
snakemake = MockSnakemake(
|
snakemake = MockSnakemake(
|
||||||
path='..',
|
path='..',
|
||||||
wildcards=Dict(simpl=''),
|
wildcards=Dict(simpl='1024', network='elec'),
|
||||||
input=Dict(
|
input=Dict(
|
||||||
network='networks/elec.nc',
|
network='networks/{network}.nc',
|
||||||
regions_onshore='resources/regions_onshore.geojson',
|
tech_costs="data/costs.csv",
|
||||||
regions_offshore='resources/regions_offshore.geojson'
|
regions_onshore="resources/regions_onshore.geojson",
|
||||||
|
regions_offshore="resources/regions_offshore.geojson"
|
||||||
),
|
),
|
||||||
output=Dict(
|
output=Dict(
|
||||||
network='networks/elec_s{simpl}.nc',
|
network='networks/{network}_s{simpl}.nc',
|
||||||
regions_onshore='resources/regions_onshore_s{simpl}.geojson',
|
regions_onshore="resources/regions_onshore_{network}_s{simpl}.geojson",
|
||||||
regions_offshore='resources/regions_offshore_s{simpl}.geojson'
|
regions_offshore="resources/regions_offshore_{network}_s{simpl}.geojson",
|
||||||
|
clustermaps='resources/clustermaps_{network}_s{simpl}.h5'
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -268,6 +270,7 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
if snakemake.wildcards.simpl:
|
if snakemake.wildcards.simpl:
|
||||||
n_clusters = int(snakemake.wildcards.simpl)
|
n_clusters = int(snakemake.wildcards.simpl)
|
||||||
|
logger.info("Clustering to {} buses".format(n_clusters))
|
||||||
|
|
||||||
renewable_carriers = pd.Index([tech
|
renewable_carriers = pd.Index([tech
|
||||||
for tech in n.generators.carrier.unique()
|
for tech in n.generators.carrier.unique()
|
||||||
|
Loading…
Reference in New Issue
Block a user