Skip to content

Commit

Permalink
Merge branch 'master' into validation
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianHofmann committed Jul 17, 2023
2 parents 65d9036 + 7ff7a7e commit fcce233
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 32 deletions.
2 changes: 1 addition & 1 deletion envs/environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dependencies:
- python>=3.8
- pip

- pypsa>=0.23
# - pypsa>=0.23
- atlite>=0.2.9
- dask

Expand Down
17 changes: 0 additions & 17 deletions scripts/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,23 +277,6 @@ def update_to(b=1, bsize=1, tsize=None):
urllib.request.urlretrieve(url, file, reporthook=update_to)


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.clustering.spatial 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, configfiles=[], **wildcards):
"""
This function is expected to be executed from the 'scripts'-directory of '
Expand Down
13 changes: 7 additions & 6 deletions scripts/cluster_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
import pyomo.environ as po
import pypsa
import seaborn as sns
from _helpers import configure_logging, get_aggregation_strategies, update_p_nom_max
from _helpers import configure_logging, update_p_nom_max
from pypsa.clustering.spatial import (
busmap_by_greedy_modularity,
busmap_by_hac,
Expand Down Expand Up @@ -395,26 +395,27 @@ def clustering_for_n_clusters(
extended_link_costs=0,
focus_weights=None,
):
bus_strategies, generator_strategies = get_aggregation_strategies(
aggregation_strategies
)

if not isinstance(custom_busmap, pd.Series):
busmap = busmap_for_n_clusters(
n, n_clusters, solver_name, focus_weights, algorithm, feature
)
else:
busmap = custom_busmap

line_strategies = aggregation_strategies.get("lines", dict())
generator_strategies = aggregation_strategies.get("generators", dict())
one_port_strategies = aggregation_strategies.get("one_ports", dict())

clustering = get_clustering_from_busmap(
n,
busmap,
bus_strategies=bus_strategies,
aggregate_generators_weighted=True,
aggregate_generators_carriers=aggregate_carriers,
aggregate_one_ports=["Load", "StorageUnit"],
line_length_factor=line_length_factor,
line_strategies=line_strategies,
generator_strategies=generator_strategies,
one_port_strategies=one_port_strategies,
scale_link_capital_costs=False,
)

Expand Down
16 changes: 8 additions & 8 deletions scripts/simplify_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,16 @@
"""

import logging
from functools import reduce
from functools import partial, reduce

import numpy as np
import pandas as pd
import pypsa
import scipy as sp
from _helpers import configure_logging, get_aggregation_strategies, update_p_nom_max
from _helpers import configure_logging, update_p_nom_max
from add_electricity import load_costs
from cluster_network import cluster_regions, clustering_for_n_clusters
from pypsa.clustering.spatial import (
aggregategenerators,
aggregateoneport,
busmap_by_stubs,
get_clustering_from_busmap,
Expand Down Expand Up @@ -253,7 +252,7 @@ def replace_components(n, c, df, pnl):

_adjust_capital_costs_using_connection_costs(n, connection_costs_to_bus, output)

_, generator_strategies = get_aggregation_strategies(aggregation_strategies)
generator_strategies = aggregation_strategies["generators"]

carriers = set(n.generators.carrier) - set(exclude_carriers)
generators, generators_pnl = aggregateoneport(
Expand Down Expand Up @@ -482,19 +481,20 @@ def aggregate_to_substations(n, aggregation_strategies=dict(), buses_i=None):
busmap = n.buses.index.to_series()
busmap.loc[buses_i] = dist.idxmin(1)

bus_strategies, generator_strategies = get_aggregation_strategies(
aggregation_strategies
)
line_strategies = aggregation_strategies.get("lines", dict())
generator_strategies = aggregation_strategies.get("generators", dict())
one_port_strategies = aggregation_strategies.get("one_ports", dict())

clustering = get_clustering_from_busmap(
n,
busmap,
bus_strategies=bus_strategies,
aggregate_generators_weighted=True,
aggregate_generators_carriers=None,
aggregate_one_ports=["Load", "StorageUnit"],
line_length_factor=1.0,
line_strategies=line_strategies,
generator_strategies=generator_strategies,
one_port_strategies=one_port_strategies,
scale_link_capital_costs=False,
)
return clustering.network, busmap
Expand Down

0 comments on commit fcce233

Please sign in to comment.