Skip to content

Commit

Permalink
Apply black
Browse files Browse the repository at this point in the history
  • Loading branch information
lenzim97 committed Jan 30, 2025
1 parent 229a2bd commit fe6ac89
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 35 deletions.
4 changes: 2 additions & 2 deletions etrago/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
set_random_noise,
set_trafo_costs,
update_busmap,
adjust_PtH2_model
adjust_PtH2_model,
)

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -372,7 +372,7 @@ def __init__(
post_contingency_analysis = post_contingency_analysis_lopf

sclopf = iterate_sclopf

adjust_PtH2_model = adjust_PtH2_model

def dc_lines(self):
Expand Down
103 changes: 70 additions & 33 deletions etrago/tools/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -3202,13 +3202,13 @@ def export_to_shapefile(pypsa_network, shape_files_path=None, srid=4326):

def adjust_PtH2_model(self):
"""
Adjust the modelling of electrolyzer with waste-heat and
O2-utilisation. The method creates a multiple-link-model
out of the single links from the dataset (power_to_H2-,
PtH2_waste_heat-, PtH2_O2-links) for each location where
coupling-product usage is possible. The resulting model
consists of a multiple link, additional buses and stores for
waste_heat and O2-utilisation, and the connection link to the
Adjust the modelling of electrolyzer with waste-heat and
O2-utilisation. The method creates a multiple-link-model
out of the single links from the dataset (power_to_H2-,
PtH2_waste_heat-, PtH2_O2-links) for each location where
coupling-product usage is possible. The resulting model
consists of a multiple link, additional buses and stores for
waste_heat and O2-utilisation, and the connection link to the
final Heat- and O2-Bus.
Parameters
Expand All @@ -3221,41 +3221,66 @@ def adjust_PtH2_model(self):
None.
"""
PtH2_links = self.network.links[self.network.links.carrier == "power_to_H2"].index
PtH2_AC_buses = self.network.buses.loc[self.network.links.loc[PtH2_links, "bus0"]].index.unique()
PtH2_links = self.network.links[
self.network.links.carrier == "power_to_H2"
].index
PtH2_AC_buses = self.network.buses.loc[
self.network.links.loc[PtH2_links, "bus0"]
].index.unique()

from itertools import count

store_ids = self.network.stores.index
numeric_parts = [int(idx.split()[0]) for idx in store_ids]
next_bus_id = max(self.network.buses.index.astype(int)) + 1
next_store_id = max(numeric_parts) + 1
bus_id_counter = count(start=next_bus_id)
store_id_counter = count(start=next_store_id)

for bus in PtH2_AC_buses:
power_to_h2_links = self.network.links[
(self.network.links.carrier == "power_to_H2") & (self.network.links.bus0 == bus)].index
(self.network.links.carrier == "power_to_H2")
& (self.network.links.bus0 == bus)
].index
power_to_heat_links = self.network.links[
(self.network.links.carrier == "PtH2_waste_heat") & (self.network.links.bus0 == bus)].index
(self.network.links.carrier == "PtH2_waste_heat")
& (self.network.links.bus0 == bus)
].index
power_to_o2_links = self.network.links[
(self.network.links.carrier == "PtH2_O2") & (self.network.links.bus0 == bus)].index

(self.network.links.carrier == "PtH2_O2")
& (self.network.links.bus0 == bus)
].index

link_data = []
if len(power_to_heat_links) > 0:
link_data.append({"links": power_to_heat_links, "efficiency": 0.2, "carrier": "waste_heat"})
link_data.append(
{
"links": power_to_heat_links,
"efficiency": 0.2,
"carrier": "waste_heat",
}
)
if len(power_to_o2_links) > 0:
link_data.append({"links": power_to_o2_links, "efficiency": 0.015, "carrier": "O2"})

link_data.append(
{
"links": power_to_o2_links,
"efficiency": 0.015,
"carrier": "O2",
}
)

for idx, data in enumerate(link_data, start=2):
links = data["links"]
efficiency = data["efficiency"]
carrier = data["carrier"]
new_bus_id = next(bus_id_counter)
new_store_id = next(store_id_counter)
store_name = f"{new_store_id} PtH2_{carrier}"

# Add new heat/o2-bus and -store
self.network.add("Bus", name=new_bus_id, carrier=f"PtH2_extra_bus_{carrier}")
self.network.add(
"Bus", name=new_bus_id, carrier=f"PtH2_extra_bus_{carrier}"
)
self.network.add(
"Store",
name=store_name,
Expand All @@ -3266,22 +3291,34 @@ def adjust_PtH2_model(self):
marginal_cost=0,
capital_cost=0,
e_cyclic=False,
standing_loss=1
standing_loss=1,
)

self.network.stores.loc[store_name, "scn_name"] = self.args[
"scn_name"
]
self.network.buses.loc[str(new_bus_id), "scn_name"] = self.args[
"scn_name"
]
self.network.buses.loc[str(new_bus_id), "country"] = "DE"

# set coordinates for new bus for the clustering method
bus0_index = self.network.links.loc[power_to_h2_links, "bus0"]
self.network.buses.loc[str(new_bus_id), "x"] = (
self.network.buses.loc[bus0_index, "x"].values[0]
)
self.network.buses.loc[str(new_bus_id), "y"] = (
self.network.buses.loc[bus0_index, "y"].values[0]
)

# Connect multiple link with new heat/o2-bus
self.network.links.loc[power_to_h2_links, f"bus{idx}"] = str(
new_bus_id
)
self.network.links.loc[power_to_h2_links, f"efficiency{idx}"] = (
efficiency
)

self.network.stores.loc[store_name, "scn_name"] = self.args["scn_name"]
self.network.buses.loc[str(new_bus_id), "scn_name"] = self.args["scn_name"]
self.network.buses.loc[str(new_bus_id), "country"] = 'DE'

#set coordinates for new bus for the clustering method
bus0_index = self.network.links.loc[power_to_h2_links, "bus0"]
self.network.buses.loc[str(new_bus_id), "x"] = self.network.buses.loc[bus0_index, "x"].values[0]
self.network.buses.loc[str(new_bus_id), "y"] = self.network.buses.loc[bus0_index, "y"].values[0]

#Connect multiple link with new heat/o2-bus
self.network.links.loc[power_to_h2_links, f"bus{idx}"] = str(new_bus_id)
self.network.links.loc[power_to_h2_links, f"efficiency{idx}"] = efficiency

# Adjust originals waste_heat- and oxygen-links with new bus0
for link in links:
self.network.links.loc[link, "bus0"] = str(new_bus_id)

0 comments on commit fe6ac89

Please sign in to comment.