treatment of outliers and small feature-bugfix
This commit is contained in:
parent
b5dbf4eb32
commit
82a0338e9f
@ -272,6 +272,8 @@ def busmap_for_n_clusters(n, n_clusters, solver_name, focus_weights=None, algori
|
|||||||
algorithm_kwds.setdefault('tol', 1e-6)
|
algorithm_kwds.setdefault('tol', 1e-6)
|
||||||
|
|
||||||
def fix_country_assignment_for_hac(n):
|
def fix_country_assignment_for_hac(n):
|
||||||
|
from scipy.sparse import csgraph
|
||||||
|
|
||||||
# overwrite country of nodes that are disconnected from their country-topology
|
# overwrite country of nodes that are disconnected from their country-topology
|
||||||
for country in n.buses.country.unique():
|
for country in n.buses.country.unique():
|
||||||
m = n.copy()
|
m = n.copy()
|
||||||
@ -288,19 +290,18 @@ def busmap_for_n_clusters(n, n_clusters, solver_name, focus_weights=None, algori
|
|||||||
neighbor_bus = n.lines.query("bus0 in @disconnected_bus or bus1 in @disconnected_bus").iloc[0][['bus0','bus1']]
|
neighbor_bus = n.lines.query("bus0 in @disconnected_bus or bus1 in @disconnected_bus").iloc[0][['bus0','bus1']]
|
||||||
new_country = list(set(n.buses.loc[neighbor_bus].country)-set([country]))[0]
|
new_country = list(set(n.buses.loc[neighbor_bus].country)-set([country]))[0]
|
||||||
|
|
||||||
logger.info(f"overwriting country ``{country}`` of bus ``{disconnected_bus}`` to new country ``{new_country}``, "
|
logger.info(f"overwriting country `{country}` of bus `{disconnected_bus}` to new country `{new_country}`, "
|
||||||
"because it is disconnected from its inital inter-country transmission grid.")
|
"because it is disconnected from its inital inter-country transmission grid.")
|
||||||
n.buses.at[disconnected_bus, "country"] = new_country
|
n.buses.at[disconnected_bus, "country"] = new_country
|
||||||
return n
|
return n
|
||||||
|
|
||||||
if algorithm == "hac":
|
if algorithm == "hac":
|
||||||
from scipy.sparse import csgraph
|
|
||||||
|
|
||||||
feature = get_feature_for_hac(n, buses_i=n.buses.index, feature=feature)
|
feature = get_feature_for_hac(n, buses_i=n.buses.index, feature=feature)
|
||||||
n = fix_country_assignment_for_hac(n)
|
n = fix_country_assignment_for_hac(n)
|
||||||
elif feature is not None:
|
|
||||||
logger.warning(f"Keyword argument feature is only valid for algorithm 'hac'."
|
if (algorithm != "hac") and (feature is not None):
|
||||||
f"given feature ``{feature}`` will be ignored.")
|
logger.warning(f"Keyword argument feature is only valid for algorithm `hac`. "
|
||||||
|
f"Given feature `{feature}` will be ignored.")
|
||||||
|
|
||||||
n.determine_network_topology()
|
n.determine_network_topology()
|
||||||
|
|
||||||
@ -338,7 +339,7 @@ def clustering_for_n_clusters(n, n_clusters, custom_busmap=False, aggregate_carr
|
|||||||
line_length_factor=1.25, potential_mode='simple', solver_name="cbc",
|
line_length_factor=1.25, potential_mode='simple', solver_name="cbc",
|
||||||
algorithm="hac", feature=None, extended_link_costs=0, focus_weights=None):
|
algorithm="hac", feature=None, extended_link_costs=0, focus_weights=None):
|
||||||
|
|
||||||
logger.info(f"Clustering network using algorithm ``{algorithm}`` and feature ``{feature}``...")
|
logger.info(f"Clustering network using algorithm `{algorithm}` and feature `{feature}`...")
|
||||||
|
|
||||||
if potential_mode == 'simple':
|
if potential_mode == 'simple':
|
||||||
p_nom_max_strategy = np.sum
|
p_nom_max_strategy = np.sum
|
||||||
@ -348,7 +349,7 @@ def clustering_for_n_clusters(n, n_clusters, custom_busmap=False, aggregate_carr
|
|||||||
raise AttributeError(f"potential_mode should be one of 'simple' or 'conservative' but is '{potential_mode}'")
|
raise AttributeError(f"potential_mode should be one of 'simple' or 'conservative' but is '{potential_mode}'")
|
||||||
|
|
||||||
if not custom_busmap:
|
if not custom_busmap:
|
||||||
busmap = busmap_for_n_clusters(n, n_clusters, solver_name, focus_weights, algorithm)
|
busmap = busmap_for_n_clusters(n, n_clusters, solver_name, focus_weights, algorithm, feature)
|
||||||
else:
|
else:
|
||||||
busmap = custom_busmap
|
busmap = custom_busmap
|
||||||
|
|
||||||
|
@ -407,7 +407,21 @@ if __name__ == "__main__":
|
|||||||
n, substation_map = aggregate_to_substations(n)
|
n, substation_map = aggregate_to_substations(n)
|
||||||
busmaps.append(substation_map)
|
busmaps.append(substation_map)
|
||||||
|
|
||||||
|
# treatment of outliers (nodes without a profile for considered carrier) for "cluster_network"
|
||||||
|
if snakemake.config.get("clustering", {}).get("cluster_network", {}).get("algorithm", "hac") == "hac":
|
||||||
|
carriers = cluster_config.get("feature", "solar+onwind-time").split('-')[0].split('+')
|
||||||
|
buses_i = list(set(n.buses.index)-set(n.generators.query("carrier in @carriers").bus))
|
||||||
|
n, busmap_hac = aggregate_to_substations(n, buses_i)
|
||||||
|
busmaps.append(busmap_hac)
|
||||||
|
|
||||||
if snakemake.wildcards.simpl:
|
if snakemake.wildcards.simpl:
|
||||||
|
# treatment of outliers (nodes without a profile for a considered carrier) for "simplify"
|
||||||
|
if cluster_config.get("algorithm", "hac") == "hac":
|
||||||
|
carriers = cluster_config.get("feature", "solar+onwind-time").split('-')[0].split('+')
|
||||||
|
buses_i = list(set(n.buses.index)-set(n.generators.query("carrier in @carriers").bus))
|
||||||
|
n, busmap_hac = aggregate_to_substations(n, buses_i)
|
||||||
|
busmaps.append(busmap_hac)
|
||||||
|
# conduct clustering
|
||||||
n, cluster_map = cluster(n, int(snakemake.wildcards.simpl), snakemake.config,
|
n, cluster_map = cluster(n, int(snakemake.wildcards.simpl), snakemake.config,
|
||||||
algorithm=cluster_config.get('algorithm', 'hac'),
|
algorithm=cluster_config.get('algorithm', 'hac'),
|
||||||
feature=cluster_config.get('feature', None))
|
feature=cluster_config.get('feature', None))
|
||||||
|
Loading…
Reference in New Issue
Block a user