[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
c043100ada
commit
216a02fba1
@ -321,7 +321,9 @@ rule simplify_network:
|
||||
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", []),
|
||||
exclude_carriers=config["clustering"]["simplify_network"].get(
|
||||
"exclude_carriers", []
|
||||
),
|
||||
focus_weights=config.get("focus_weights", None),
|
||||
solver_name=config["solving"]["solver"]["name"],
|
||||
input:
|
||||
|
@ -172,10 +172,18 @@ def _prepare_connection_costs_per_link(n, costs, renewable_param, length_factor_
|
||||
|
||||
|
||||
def _compute_connection_costs_to_bus(
|
||||
n, busmap, costs, renewable_param, length_factor_param, 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:
|
||||
connection_costs_per_link = _prepare_connection_costs_per_link(n, costs, renewable_param, length_factor_param)
|
||||
connection_costs_per_link = _prepare_connection_costs_per_link(
|
||||
n, costs, renewable_param, length_factor_param
|
||||
)
|
||||
|
||||
if buses is None:
|
||||
buses = busmap.index[busmap.index != busmap.values]
|
||||
@ -265,7 +273,16 @@ def _aggregate_and_move_components(
|
||||
n.mremove(c, df.index[df.bus0.isin(buses_to_del) | df.bus1.isin(buses_to_del)])
|
||||
|
||||
|
||||
def simplify_links(n, costs, renewable_param, length_factor_param, p_max_pu_param, exclude_carriers_param, 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
|
||||
logger.info("Simplifying connected link components")
|
||||
|
||||
@ -315,7 +332,9 @@ def simplify_links(n, costs, renewable_param, length_factor_param, p_max_pu_para
|
||||
|
||||
busmap = n.buses.index.to_series()
|
||||
|
||||
connection_costs_per_link = _prepare_connection_costs_per_link(n, costs, renewable_param, length_factor_param)
|
||||
connection_costs_per_link = _prepare_connection_costs_per_link(
|
||||
n, costs, renewable_param, length_factor_param
|
||||
)
|
||||
connection_costs_to_bus = pd.DataFrame(
|
||||
0.0, index=n.buses.index, columns=list(connection_costs_per_link)
|
||||
)
|
||||
@ -333,7 +352,13 @@ def simplify_links(n, costs, renewable_param, length_factor_param, p_max_pu_para
|
||||
)
|
||||
busmap.loc[buses] = b[np.r_[0, m.argmin(axis=0), 1]]
|
||||
connection_costs_to_bus.loc[buses] += _compute_connection_costs_to_bus(
|
||||
n, busmap, costs, renewable_param, length_factor_param, 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, [])]
|
||||
@ -387,7 +412,16 @@ def simplify_links(n, costs, renewable_param, length_factor_param, p_max_pu_para
|
||||
return n, busmap
|
||||
|
||||
|
||||
def remove_stubs(n, costs, renewable_param, length_factor_param, clustering_param, exclude_carriers_param, 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")
|
||||
|
||||
across_borders = clustering_param["simplify_network"].get(
|
||||
@ -396,12 +430,12 @@ def remove_stubs(n, costs, renewable_param, length_factor_param, clustering_para
|
||||
matching_attrs = [] if across_borders else ["country"]
|
||||
busmap = busmap_by_stubs(n, matching_attrs)
|
||||
|
||||
connection_costs_to_bus = _compute_connection_costs_to_bus(n, busmap, costs, renewable_param, length_factor_param)
|
||||
|
||||
exclude_carriers = clustering_param["simplify_network"].get(
|
||||
"exclude_carriers", []
|
||||
connection_costs_to_bus = _compute_connection_costs_to_bus(
|
||||
n, busmap, costs, renewable_param, length_factor_param
|
||||
)
|
||||
|
||||
exclude_carriers = clustering_param["simplify_network"].get("exclude_carriers", [])
|
||||
|
||||
_aggregate_and_move_components(
|
||||
n,
|
||||
busmap,
|
||||
@ -468,7 +502,14 @@ def aggregate_to_substations(n, aggregation_strategies=dict(), buses_i=None):
|
||||
|
||||
|
||||
def cluster(
|
||||
n, n_clusters, focus_weights_param, renewable_param, solver_name_param, 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")
|
||||
|
||||
@ -524,13 +565,14 @@ if __name__ == "__main__":
|
||||
)
|
||||
|
||||
n, simplify_links_map = simplify_links(
|
||||
n, technology_costs,
|
||||
snakemake.params['renewable'],
|
||||
snakemake.params['length_factor'],
|
||||
snakemake.params['p_max_pu'],
|
||||
snakemake.params['exclude_carriers'],
|
||||
n,
|
||||
technology_costs,
|
||||
snakemake.params["renewable"],
|
||||
snakemake.params["length_factor"],
|
||||
snakemake.params["p_max_pu"],
|
||||
snakemake.params["exclude_carriers"],
|
||||
snakemake.output,
|
||||
aggregation_strategies
|
||||
aggregation_strategies,
|
||||
)
|
||||
|
||||
busmaps = [trafo_map, simplify_links_map]
|
||||
@ -540,10 +582,10 @@ if __name__ == "__main__":
|
||||
n, stub_map = remove_stubs(
|
||||
n,
|
||||
technology_costs,
|
||||
snakemake.params['renewable'],
|
||||
snakemake.params['length_factor'],
|
||||
snakemake.params["renewable"],
|
||||
snakemake.params["length_factor"],
|
||||
snakemake.params["clustering"],
|
||||
snakemake.params['exclude_carriers'],
|
||||
snakemake.params["exclude_carriers"],
|
||||
snakemake.output,
|
||||
aggregation_strategies=aggregation_strategies,
|
||||
)
|
||||
@ -579,9 +621,9 @@ if __name__ == "__main__":
|
||||
n, cluster_map = cluster(
|
||||
n,
|
||||
int(snakemake.wildcards.simpl),
|
||||
snakemake.params['focus_weights'],
|
||||
snakemake.params['renewable'],
|
||||
snakemake.params['solver_name'],
|
||||
snakemake.params["focus_weights"],
|
||||
snakemake.params["renewable"],
|
||||
snakemake.params["solver_name"],
|
||||
cluster_param.get("algorithm", "hac"),
|
||||
cluster_param.get("feature", None),
|
||||
aggregation_strategies,
|
||||
|
Loading…
Reference in New Issue
Block a user