clustering strats to configurables: move duplicate code to _helpers script & import
This commit is contained in:
parent
5587327be3
commit
a3af137b74
@ -210,6 +210,22 @@ def progress_retrieve(url, file):
|
|||||||
|
|
||||||
urllib.request.urlretrieve(url, file, reporthook=dlProgress)
|
urllib.request.urlretrieve(url, file, reporthook=dlProgress)
|
||||||
|
|
||||||
|
def get_aggregation_strategies(aggregation_strategies):
|
||||||
|
# default aggregation strategies that cannot be defined in .yaml format must be specified within
|
||||||
|
# the function, otherwise (when defaults are passed in the function's definition) they get lost
|
||||||
|
# when custom values are specified in the config.
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
from pypsa.networkclustering import _make_consense
|
||||||
|
|
||||||
|
bus_strategies = dict(country=_make_consense("Bus", "country"))
|
||||||
|
bus_strategies.update(aggregation_strategies.get("buses", {}))
|
||||||
|
|
||||||
|
generator_strategies = {'build_year': lambda x: 0, 'lifetime': lambda x: np.inf}
|
||||||
|
generator_strategies.update(aggregation_strategies.get("generators", {}))
|
||||||
|
|
||||||
|
return bus_strategies, generator_strategies
|
||||||
|
|
||||||
|
|
||||||
def mock_snakemake(rulename, **wildcards):
|
def mock_snakemake(rulename, **wildcards):
|
||||||
"""
|
"""
|
||||||
|
@ -121,7 +121,7 @@ Exemplary unsolved network clustered to 37 nodes:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from _helpers import configure_logging, update_p_nom_max
|
from _helpers import configure_logging, update_p_nom_max, get_aggregation_strategies
|
||||||
|
|
||||||
import pypsa
|
import pypsa
|
||||||
import os
|
import os
|
||||||
@ -261,11 +261,7 @@ def clustering_for_n_clusters(n, n_clusters, custom_busmap=False, aggregate_carr
|
|||||||
line_length_factor=1.25, aggregation_strategies=dict(), solver_name="cbc",
|
line_length_factor=1.25, aggregation_strategies=dict(), solver_name="cbc",
|
||||||
algorithm="kmeans", extended_link_costs=0, focus_weights=None):
|
algorithm="kmeans", extended_link_costs=0, focus_weights=None):
|
||||||
|
|
||||||
bus_strategies = dict(country=_make_consense("Bus", "country"))
|
bus_strategies, generator_strategies = get_aggregation_strategies(aggregation_strategies)
|
||||||
bus_strategies.update(aggregation_strategies.get("buses", {}))
|
|
||||||
|
|
||||||
generator_strategies = {'build_year': lambda x: 0, 'lifetime': lambda x: np.inf}
|
|
||||||
generator_strategies.update(aggregation_strategies.get("generators", {}))
|
|
||||||
|
|
||||||
if not isinstance(custom_busmap, pd.Series):
|
if not isinstance(custom_busmap, pd.Series):
|
||||||
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)
|
||||||
|
@ -83,7 +83,7 @@ The rule :mod:`simplify_network` does up to four things:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from _helpers import configure_logging, update_p_nom_max
|
from _helpers import configure_logging, update_p_nom_max, get_aggregation_strategies
|
||||||
|
|
||||||
from cluster_network import clustering_for_n_clusters, cluster_regions
|
from cluster_network import clustering_for_n_clusters, cluster_regions
|
||||||
from add_electricity import load_costs
|
from add_electricity import load_costs
|
||||||
@ -203,8 +203,7 @@ def _aggregate_and_move_components(n, busmap, connection_costs_to_bus, output,
|
|||||||
|
|
||||||
_adjust_capital_costs_using_connection_costs(n, connection_costs_to_bus, output)
|
_adjust_capital_costs_using_connection_costs(n, connection_costs_to_bus, output)
|
||||||
|
|
||||||
generator_strategies = {'build_year': lambda x: 0, 'lifetime': lambda x: np.inf}
|
_, generator_strategies = get_aggregation_strategies(aggregation_strategies)
|
||||||
generator_strategies.update(aggregation_strategies.get("generators", {}))
|
|
||||||
|
|
||||||
generators, generators_pnl = aggregategenerators(
|
generators, generators_pnl = aggregategenerators(
|
||||||
n, busmap, custom_strategies=generator_strategies
|
n, busmap, custom_strategies=generator_strategies
|
||||||
@ -355,14 +354,7 @@ def aggregate_to_substations(n, aggregation_strategies=dict(), buses_i=None):
|
|||||||
busmap = n.buses.index.to_series()
|
busmap = n.buses.index.to_series()
|
||||||
busmap.loc[buses_i] = dist.idxmin(1)
|
busmap.loc[buses_i] = dist.idxmin(1)
|
||||||
|
|
||||||
# default aggregation strategies that cannot be defined in .yaml format must be specified within
|
bus_strategies, generator_strategies = get_aggregation_strategies(aggregation_strategies)
|
||||||
# the function, otherwise (when defaults are passed in the function's definition) they get lost
|
|
||||||
# in case custom values for different variables are specified in the config.
|
|
||||||
bus_strategies = dict(country=_make_consense("Bus", "country"))
|
|
||||||
bus_strategies.update(aggregation_strategies.get("buses", {}))
|
|
||||||
|
|
||||||
generator_strategies = {'build_year': lambda x: 0, 'lifetime': lambda x: np.inf}
|
|
||||||
generator_strategies.update(aggregation_strategies.get("generators", {}))
|
|
||||||
|
|
||||||
clustering = get_clustering_from_busmap(n, busmap,
|
clustering = get_clustering_from_busmap(n, busmap,
|
||||||
bus_strategies=bus_strategies,
|
bus_strategies=bus_strategies,
|
||||||
|
Loading…
Reference in New Issue
Block a user