Skip to content

Commit

Permalink
Merge branch 'dev' into features/#716-electrolysis-for-redispatch
Browse files Browse the repository at this point in the history
  • Loading branch information
ClaraBuettner committed Nov 4, 2024
2 parents f3d1536 + af4b038 commit 4e84603
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 60 deletions.
8 changes: 5 additions & 3 deletions etrago/analyze/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -841,16 +841,18 @@ def calc_dispatch_per_carrier(network, timesteps, dispatch_type="total"):
]

dist = pd.Series(
index=pd.MultiIndex.from_tuples(index, names=["bus", "carrier"]),
index=pd.MultiIndex.from_tuples(
index, names=["bus", "carrier"]
).unique(),
dtype=float,
)
).sort_index()

for i in dist.index:
gens = network.generators[
(network.generators.bus == i[0])
& (network.generators.carrier == i[1])
].index
dist[i] = (
dist.loc[i] = (
(
network.generators_t.p[gens].transpose()[
network.snapshots[timesteps]
Expand Down
18 changes: 9 additions & 9 deletions etrago/cluster/gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,20 +417,20 @@ def gas_postprocessing(etrago, busmap, medoid_idx=None):
},
one_port_strategies={
"Generator": {
"marginal_cost": np.mean,
"capital_cost": np.mean,
"p_nom_max": np.sum,
"p_nom_min": np.sum,
"e_nom_max": np.sum,
"marginal_cost": "mean",
"capital_cost": "mean",
"p_nom_max": "sum",
"p_nom_min": "sum",
"e_nom_max": "sum",
},
"Store": {
"marginal_cost": np.mean,
"capital_cost": np.mean,
"e_nom": np.sum,
"marginal_cost": "mean",
"capital_cost": "mean",
"e_nom": "sum",
"e_nom_max": sum_with_inf,
},
"Load": {
"p_set": np.sum,
"p_set": "sum",
},
},
)
Expand Down
80 changes: 40 additions & 40 deletions etrago/cluster/spatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,38 +121,38 @@ def strategies_lines():
def strategies_one_ports():
return {
"StorageUnit": {
"marginal_cost": np.mean,
"capital_cost": np.mean,
"efficiency_dispatch": np.mean,
"standing_loss": np.mean,
"efficiency_store": np.mean,
"p_min_pu": np.min,
"marginal_cost": "mean",
"capital_cost": "mean",
"efficiency_dispatch": "mean",
"standing_loss": "mean",
"efficiency_store": "mean",
"p_min_pu": "min",
"p_nom_extendable": ext_storage,
"p_nom_max": sum_with_inf,
},
"Store": {
"marginal_cost": np.mean,
"capital_cost": np.mean,
"standing_loss": np.mean,
"e_nom": np.sum,
"e_nom_min": np.sum,
"marginal_cost": "mean",
"capital_cost": "mean",
"standing_loss": "mean",
"e_nom": "sum",
"e_nom_min": "sum",
"e_nom_max": sum_with_inf,
"e_initial": np.sum,
"e_min_pu": np.mean,
"e_max_pu": np.mean,
"e_initial": "sum",
"e_min_pu": "mean",
"e_max_pu": "mean",
},
}


def strategies_generators():
return {
"p_nom_min": np.min,
"p_nom_min": "min",
"p_nom_max": sum_with_inf,
"weight": np.sum,
"p_nom": np.sum,
"p_nom_opt": np.sum,
"marginal_cost": np.mean,
"capital_cost": np.mean,
"weight": "sum",
"p_nom": "sum",
"p_nom_opt": "sum",
"marginal_cost": "mean",
"capital_cost": "mean",
"e_nom_max": sum_with_inf,
}

Expand All @@ -163,30 +163,30 @@ def strategies_links():
"bus0": _make_consense_links,
"bus1": _make_consense_links,
"carrier": _make_consense_links,
"p_nom": np.sum,
"p_nom": "sum",
"p_nom_extendable": _make_consense_links,
"p_nom_max": sum_with_inf,
"capital_cost": np.mean,
"length": np.mean,
"capital_cost": "mean",
"length": "mean",
"geom": nan_links,
"topo": nan_links,
"type": nan_links,
"efficiency": np.mean,
"p_nom_min": np.sum,
"p_set": np.mean,
"p_min_pu": np.min,
"p_max_pu": np.max,
"marginal_cost": np.mean,
"efficiency": "mean",
"p_nom_min": "sum",
"p_set": "mean",
"p_min_pu": "min",
"p_max_pu": "max",
"marginal_cost": "mean",
"terrain_factor": _make_consense_links,
"p_nom_opt": np.mean,
"p_nom_opt": "mean",
"country": nan_links,
"build_year": np.mean,
"lifetime": np.mean,
"min_up_time": np.mean,
"min_down_time": np.mean,
"up_time_before": np.mean,
"down_time_before": np.mean,
"committable": np.all,
"build_year": "mean",
"lifetime": "mean",
"min_up_time": "mean",
"min_down_time": "mean",
"up_time_before": "mean",
"down_time_before": "mean",
"committable": "all",
}


Expand Down Expand Up @@ -255,7 +255,7 @@ def arrange_dc_bus0_bus1(network):
strategies.pop("topo")
strategies.pop("geom")

new_df = links.groupby(grouper, axis=0).agg(strategies)
new_df = links.groupby(grouper).agg(strategies)
new_df.index = flatten_multiindex(new_df.index).rename("name")
new_df = pd.concat(
[new_df, network.links.loc[~links_agg_b]], axis=0, sort=False
Expand All @@ -275,7 +275,7 @@ def arrange_dc_bus0_bus1(network):
df_agg = df_agg.multiply(
weighting.loc[df_agg.columns], axis=1
)
pnl_df = df_agg.groupby(grouper, axis=1).sum()
pnl_df = df_agg.T.groupby(grouper).sum().T
pnl_df.columns = flatten_multiindex(pnl_df.columns).rename(
"name"
)
Expand Down Expand Up @@ -759,7 +759,7 @@ def kmedoids_dijkstra_clustering(
kmeans.fit(points)

busmap = pd.Series(
data=kmeans.predict(buses.loc[buses_i, ["x", "y"]]),
data=kmeans.predict(buses.loc[buses_i, ["x", "y"]].values),
index=buses_i,
dtype=object,
)
Expand Down
7 changes: 2 additions & 5 deletions etrago/execute/market_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ def optimize_with_rolling_horizon(
n.storage_units.state_of_charge_initial = (
n.storage_units_t.state_of_charge.loc[snapshots[start - 1]]
)
print(i)
# Make sure that state of charge of batteries and pumped hydro
# plants are cyclic over the year by using the state_of_charges
# from the pre_market_model
Expand Down Expand Up @@ -302,7 +301,7 @@ def build_market_model(self):

logger.info("Start market zone specifc clustering")

self.clustering, busmap = postprocessing(
clustering, busmap = postprocessing(
self,
busmap,
busmap_foreign,
Expand All @@ -312,9 +311,7 @@ def build_market_model(self):
apply_on="market_model",
)

self.update_busmap(busmap)

net = self.clustering.network
net = clustering.network
# links_col = net.links.columns
ac = net.lines[net.lines.carrier == "AC"]
str1 = "transshipment_"
Expand Down
27 changes: 24 additions & 3 deletions etrago/tools/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@

from collections.abc import Mapping
from copy import deepcopy
from pathlib import Path
from urllib.request import urlretrieve
import json
import logging
import math
import os
import zipfile

from pyomo.environ import Constraint, PositiveReals, Var
import numpy as np
Expand Down Expand Up @@ -287,9 +290,27 @@ def buses_by_country(self, apply_on="grid_model"):
con = self.engine
germany_sh = gpd.read_postgis(query, con, geom_col="geometry")

path = gpd.datasets.get_path("naturalearth_lowres")
shapes = gpd.read_file(path)
shapes = shapes[shapes.name.isin([*countries])].set_index(keys="name")
# read Europe borders. Original data downloaded from naturalearthdata.com/
# under Public Domain license
path_countries = Path(".") / "data" / "shapes_europe"

if not os.path.exists(path_countries):
path_countries.mkdir(exist_ok=True, parents=True)
url_countries = (
"https://naciscdn.org/naturalearth/110m/cultural/"
+ "ne_110m_admin_0_countries.zip"
)
urlretrieve(url_countries, path_countries / "shape_countries.zip")
with zipfile.ZipFile(
path_countries / "shape_countries.zip", "r"
) as zip_ref:
zip_ref.extractall(path_countries)

shapes = (
gpd.read_file(path_countries)
.rename(columns={"NAME": "name"})
.set_index("name")
)

# Use Germany borders from egon-data if not using the SH test case
if len(germany_sh.gen.unique()) > 1:
Expand Down

0 comments on commit 4e84603

Please sign in to comment.