add more params in simplify_network.py
This commit is contained in:
parent
d97a543463
commit
c043100ada
@ -318,6 +318,12 @@ rule simplify_network:
|
|||||||
clustering=config["clustering"],
|
clustering=config["clustering"],
|
||||||
electricity=config["electricity"],
|
electricity=config["electricity"],
|
||||||
costs=config["costs"],
|
costs=config["costs"],
|
||||||
|
renewable=config["renewable"],
|
||||||
|
length_factor=config["lines"]["length_factor"],
|
||||||
|
p_max_pu=config["links"].get("p_max_pu", 1.0),
|
||||||
|
exclude_carriers=config["clustering"]["simplify_network"].get("exclude_carriers", []),
|
||||||
|
focus_weights=config.get("focus_weights", None),
|
||||||
|
solver_name=config["solving"]["solver"]["name"],
|
||||||
input:
|
input:
|
||||||
network=RESOURCES + "networks/elec.nc",
|
network=RESOURCES + "networks/elec.nc",
|
||||||
tech_costs=COSTS,
|
tech_costs=COSTS,
|
||||||
@ -350,7 +356,7 @@ rule cluster_network:
|
|||||||
lines=config["lines"],
|
lines=config["lines"],
|
||||||
renewable=config["renewable"],
|
renewable=config["renewable"],
|
||||||
clustering=config["clustering"],
|
clustering=config["clustering"],
|
||||||
enable=config["enable"].get("custom_busmap", False),
|
custom_busmap=config["enable"].get("custom_busmap", False),
|
||||||
input:
|
input:
|
||||||
network=RESOURCES + "networks/elec_s{simpl}.nc",
|
network=RESOURCES + "networks/elec_s{simpl}.nc",
|
||||||
regions_onshore=RESOURCES + "regions_onshore_elec_s{simpl}.geojson",
|
regions_onshore=RESOURCES + "regions_onshore_elec_s{simpl}.geojson",
|
||||||
|
@ -756,7 +756,7 @@ if __name__ == "__main__":
|
|||||||
ppl,
|
ppl,
|
||||||
conventional_carriers,
|
conventional_carriers,
|
||||||
extendable_carriers,
|
extendable_carriers,
|
||||||
snakemake.params.get("conventional", {}),
|
snakemake.params["conventional"],
|
||||||
conventional_inputs,
|
conventional_inputs,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -521,7 +521,7 @@ if __name__ == "__main__":
|
|||||||
for p in aggregation_strategies.keys()
|
for p in aggregation_strategies.keys()
|
||||||
}
|
}
|
||||||
|
|
||||||
custom_busmap = snakemake.params["enable"].get("custom_busmap", False)
|
custom_busmap = snakemake.params["custom_busmap"]
|
||||||
if custom_busmap:
|
if custom_busmap:
|
||||||
custom_busmap = pd.read_csv(
|
custom_busmap = pd.read_csv(
|
||||||
snakemake.input.custom_busmap, index_col=0, squeeze=True
|
snakemake.input.custom_busmap, index_col=0, squeeze=True
|
||||||
|
@ -149,17 +149,17 @@ def simplify_network_to_380(n):
|
|||||||
return n, trafo_map
|
return n, trafo_map
|
||||||
|
|
||||||
|
|
||||||
def _prepare_connection_costs_per_link(n, costs, config):
|
def _prepare_connection_costs_per_link(n, costs, renewable_param, length_factor_param):
|
||||||
if n.links.empty:
|
if n.links.empty:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
connection_costs_per_link = {}
|
connection_costs_per_link = {}
|
||||||
|
|
||||||
for tech in config["renewable"]:
|
for tech in renewable_param:
|
||||||
if tech.startswith("offwind"):
|
if tech.startswith("offwind"):
|
||||||
connection_costs_per_link[tech] = (
|
connection_costs_per_link[tech] = (
|
||||||
n.links.length
|
n.links.length
|
||||||
* config["lines"]["length_factor"]
|
* length_factor_param
|
||||||
* (
|
* (
|
||||||
n.links.underwater_fraction
|
n.links.underwater_fraction
|
||||||
* costs.at[tech + "-connection-submarine", "capital_cost"]
|
* costs.at[tech + "-connection-submarine", "capital_cost"]
|
||||||
@ -172,10 +172,10 @@ def _prepare_connection_costs_per_link(n, costs, config):
|
|||||||
|
|
||||||
|
|
||||||
def _compute_connection_costs_to_bus(
|
def _compute_connection_costs_to_bus(
|
||||||
n, busmap, costs, config, connection_costs_per_link=None, buses=None
|
n, busmap, costs, renewable_param, length_factor_param, connection_costs_per_link=None, buses=None
|
||||||
):
|
):
|
||||||
if connection_costs_per_link is None:
|
if connection_costs_per_link is None:
|
||||||
connection_costs_per_link = _prepare_connection_costs_per_link(n, costs, config)
|
connection_costs_per_link = _prepare_connection_costs_per_link(n, costs, renewable_param, length_factor_param)
|
||||||
|
|
||||||
if buses is None:
|
if buses is None:
|
||||||
buses = busmap.index[busmap.index != busmap.values]
|
buses = busmap.index[busmap.index != busmap.values]
|
||||||
@ -265,7 +265,7 @@ def _aggregate_and_move_components(
|
|||||||
n.mremove(c, df.index[df.bus0.isin(buses_to_del) | df.bus1.isin(buses_to_del)])
|
n.mremove(c, df.index[df.bus0.isin(buses_to_del) | df.bus1.isin(buses_to_del)])
|
||||||
|
|
||||||
|
|
||||||
def simplify_links(n, costs, config, output, aggregation_strategies=dict()):
|
def simplify_links(n, costs, renewable_param, length_factor_param, p_max_pu_param, exclude_carriers_param, output, aggregation_strategies=dict()):
|
||||||
## Complex multi-node links are folded into end-points
|
## Complex multi-node links are folded into end-points
|
||||||
logger.info("Simplifying connected link components")
|
logger.info("Simplifying connected link components")
|
||||||
|
|
||||||
@ -315,7 +315,7 @@ def simplify_links(n, costs, config, output, aggregation_strategies=dict()):
|
|||||||
|
|
||||||
busmap = n.buses.index.to_series()
|
busmap = n.buses.index.to_series()
|
||||||
|
|
||||||
connection_costs_per_link = _prepare_connection_costs_per_link(n, costs, config)
|
connection_costs_per_link = _prepare_connection_costs_per_link(n, costs, renewable_param, length_factor_param)
|
||||||
connection_costs_to_bus = pd.DataFrame(
|
connection_costs_to_bus = pd.DataFrame(
|
||||||
0.0, index=n.buses.index, columns=list(connection_costs_per_link)
|
0.0, index=n.buses.index, columns=list(connection_costs_per_link)
|
||||||
)
|
)
|
||||||
@ -333,12 +333,11 @@ def simplify_links(n, costs, config, output, aggregation_strategies=dict()):
|
|||||||
)
|
)
|
||||||
busmap.loc[buses] = b[np.r_[0, m.argmin(axis=0), 1]]
|
busmap.loc[buses] = b[np.r_[0, m.argmin(axis=0), 1]]
|
||||||
connection_costs_to_bus.loc[buses] += _compute_connection_costs_to_bus(
|
connection_costs_to_bus.loc[buses] += _compute_connection_costs_to_bus(
|
||||||
n, busmap, costs, config, connection_costs_per_link, buses
|
n, busmap, costs, renewable_param, length_factor_param, connection_costs_per_link, buses
|
||||||
)
|
)
|
||||||
|
|
||||||
all_links = [i for _, i in sum(links, [])]
|
all_links = [i for _, i in sum(links, [])]
|
||||||
|
|
||||||
p_max_pu = config["links"].get("p_max_pu", 1.0)
|
|
||||||
lengths = n.links.loc[all_links, "length"]
|
lengths = n.links.loc[all_links, "length"]
|
||||||
name = lengths.idxmax() + "+{}".format(len(links) - 1)
|
name = lengths.idxmax() + "+{}".format(len(links) - 1)
|
||||||
params = dict(
|
params = dict(
|
||||||
@ -354,8 +353,8 @@ def simplify_links(n, costs, config, output, aggregation_strategies=dict()):
|
|||||||
/ lengths.sum()
|
/ lengths.sum()
|
||||||
* n.links.loc[all_links, "underwater_fraction"]
|
* n.links.loc[all_links, "underwater_fraction"]
|
||||||
),
|
),
|
||||||
p_max_pu=p_max_pu,
|
p_max_pu=p_max_pu_param,
|
||||||
p_min_pu=-p_max_pu,
|
p_min_pu=-p_max_pu_param,
|
||||||
underground=False,
|
underground=False,
|
||||||
under_construction=False,
|
under_construction=False,
|
||||||
)
|
)
|
||||||
@ -377,33 +376,29 @@ def simplify_links(n, costs, config, output, aggregation_strategies=dict()):
|
|||||||
|
|
||||||
logger.debug("Collecting all components using the busmap")
|
logger.debug("Collecting all components using the busmap")
|
||||||
|
|
||||||
exclude_carriers = config["clustering"]["simplify_network"].get(
|
|
||||||
"exclude_carriers", []
|
|
||||||
)
|
|
||||||
|
|
||||||
_aggregate_and_move_components(
|
_aggregate_and_move_components(
|
||||||
n,
|
n,
|
||||||
busmap,
|
busmap,
|
||||||
connection_costs_to_bus,
|
connection_costs_to_bus,
|
||||||
output,
|
output,
|
||||||
aggregation_strategies=aggregation_strategies,
|
aggregation_strategies=aggregation_strategies,
|
||||||
exclude_carriers=exclude_carriers,
|
exclude_carriers=exclude_carriers_param,
|
||||||
)
|
)
|
||||||
return n, busmap
|
return n, busmap
|
||||||
|
|
||||||
|
|
||||||
def remove_stubs(n, costs, config, output, aggregation_strategies=dict()):
|
def remove_stubs(n, costs, renewable_param, length_factor_param, clustering_param, exclude_carriers_param, output, aggregation_strategies=dict()):
|
||||||
logger.info("Removing stubs")
|
logger.info("Removing stubs")
|
||||||
|
|
||||||
across_borders = config["clustering"]["simplify_network"].get(
|
across_borders = clustering_param["simplify_network"].get(
|
||||||
"remove_stubs_across_borders", True
|
"remove_stubs_across_borders", True
|
||||||
)
|
)
|
||||||
matching_attrs = [] if across_borders else ["country"]
|
matching_attrs = [] if across_borders else ["country"]
|
||||||
busmap = busmap_by_stubs(n, matching_attrs)
|
busmap = busmap_by_stubs(n, matching_attrs)
|
||||||
|
|
||||||
connection_costs_to_bus = _compute_connection_costs_to_bus(n, busmap, costs, config)
|
connection_costs_to_bus = _compute_connection_costs_to_bus(n, busmap, costs, renewable_param, length_factor_param)
|
||||||
|
|
||||||
exclude_carriers = config["clustering"]["simplify_network"].get(
|
exclude_carriers = clustering_param["simplify_network"].get(
|
||||||
"exclude_carriers", []
|
"exclude_carriers", []
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -473,17 +468,15 @@ def aggregate_to_substations(n, aggregation_strategies=dict(), buses_i=None):
|
|||||||
|
|
||||||
|
|
||||||
def cluster(
|
def cluster(
|
||||||
n, n_clusters, config, algorithm="hac", feature=None, aggregation_strategies=dict()
|
n, n_clusters, focus_weights_param, renewable_param, solver_name_param, algorithm="hac", feature=None, aggregation_strategies=dict()
|
||||||
):
|
):
|
||||||
logger.info(f"Clustering to {n_clusters} buses")
|
logger.info(f"Clustering to {n_clusters} buses")
|
||||||
|
|
||||||
focus_weights = config.get("focus_weights", None)
|
|
||||||
|
|
||||||
renewable_carriers = pd.Index(
|
renewable_carriers = pd.Index(
|
||||||
[
|
[
|
||||||
tech
|
tech
|
||||||
for tech in n.generators.carrier.unique()
|
for tech in n.generators.carrier.unique()
|
||||||
if tech.split("-", 2)[0] in config["renewable"]
|
if tech.split("-", 2)[0] in renewable_param
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -492,10 +485,10 @@ def cluster(
|
|||||||
n_clusters,
|
n_clusters,
|
||||||
custom_busmap=False,
|
custom_busmap=False,
|
||||||
aggregation_strategies=aggregation_strategies,
|
aggregation_strategies=aggregation_strategies,
|
||||||
solver_name=config["solving"]["solver"]["name"],
|
solver_name=solver_name_param,
|
||||||
algorithm=algorithm,
|
algorithm=algorithm,
|
||||||
feature=feature,
|
feature=feature,
|
||||||
focus_weights=focus_weights,
|
focus_weights=focus_weights_param,
|
||||||
)
|
)
|
||||||
|
|
||||||
return clustering.network, clustering.busmap
|
return clustering.network, clustering.busmap
|
||||||
@ -531,23 +524,32 @@ if __name__ == "__main__":
|
|||||||
)
|
)
|
||||||
|
|
||||||
n, simplify_links_map = simplify_links(
|
n, simplify_links_map = simplify_links(
|
||||||
n, technology_costs, snakemake.config, snakemake.output, aggregation_strategies
|
n, technology_costs,
|
||||||
|
snakemake.params['renewable'],
|
||||||
|
snakemake.params['length_factor'],
|
||||||
|
snakemake.params['p_max_pu'],
|
||||||
|
snakemake.params['exclude_carriers'],
|
||||||
|
snakemake.output,
|
||||||
|
aggregation_strategies
|
||||||
)
|
)
|
||||||
|
|
||||||
busmaps = [trafo_map, simplify_links_map]
|
busmaps = [trafo_map, simplify_links_map]
|
||||||
|
|
||||||
cluster_config = snakemake.params["clustering"]["simplify_network"]
|
cluster_param = snakemake.params["clustering"]["simplify_network"]
|
||||||
if cluster_config.get("remove_stubs", True):
|
if cluster_param.get("remove_stubs", True):
|
||||||
n, stub_map = remove_stubs(
|
n, stub_map = remove_stubs(
|
||||||
n,
|
n,
|
||||||
technology_costs,
|
technology_costs,
|
||||||
snakemake.config,
|
snakemake.params['renewable'],
|
||||||
|
snakemake.params['length_factor'],
|
||||||
|
snakemake.params["clustering"],
|
||||||
|
snakemake.params['exclude_carriers'],
|
||||||
snakemake.output,
|
snakemake.output,
|
||||||
aggregation_strategies=aggregation_strategies,
|
aggregation_strategies=aggregation_strategies,
|
||||||
)
|
)
|
||||||
busmaps.append(stub_map)
|
busmaps.append(stub_map)
|
||||||
|
|
||||||
if cluster_config.get("to_substations", False):
|
if cluster_param.get("to_substations", False):
|
||||||
n, substation_map = aggregate_to_substations(n, aggregation_strategies)
|
n, substation_map = aggregate_to_substations(n, aggregation_strategies)
|
||||||
busmaps.append(substation_map)
|
busmaps.append(substation_map)
|
||||||
|
|
||||||
@ -558,10 +560,10 @@ if __name__ == "__main__":
|
|||||||
.get("cluster_network", {})
|
.get("cluster_network", {})
|
||||||
.get("algorithm", "hac")
|
.get("algorithm", "hac")
|
||||||
== "hac"
|
== "hac"
|
||||||
or cluster_config.get("algorithm", "hac") == "hac"
|
or cluster_param.get("algorithm", "hac") == "hac"
|
||||||
):
|
):
|
||||||
carriers = (
|
carriers = (
|
||||||
cluster_config.get("feature", "solar+onwind-time").split("-")[0].split("+")
|
cluster_param.get("feature", "solar+onwind-time").split("-")[0].split("+")
|
||||||
)
|
)
|
||||||
for carrier in carriers:
|
for carrier in carriers:
|
||||||
buses_i = list(
|
buses_i = list(
|
||||||
@ -577,9 +579,11 @@ if __name__ == "__main__":
|
|||||||
n, cluster_map = cluster(
|
n, cluster_map = cluster(
|
||||||
n,
|
n,
|
||||||
int(snakemake.wildcards.simpl),
|
int(snakemake.wildcards.simpl),
|
||||||
snakemake.config,
|
snakemake.params['focus_weights'],
|
||||||
cluster_config.get("algorithm", "hac"),
|
snakemake.params['renewable'],
|
||||||
cluster_config.get("feature", None),
|
snakemake.params['solver_name'],
|
||||||
|
cluster_param.get("algorithm", "hac"),
|
||||||
|
cluster_param.get("feature", None),
|
||||||
aggregation_strategies,
|
aggregation_strategies,
|
||||||
)
|
)
|
||||||
busmaps.append(cluster_map)
|
busmaps.append(cluster_map)
|
||||||
|
Loading…
Reference in New Issue
Block a user