Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 16 additions & 37 deletions etrago/appl.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,9 @@
"BarHomogeneous": 1,
},
"model_formulation": "kirchhoff", # angles or kirchhoff
"scn_name": "eGon100RE", # scenario: eGon2035, eGon100RE or status2019
"scn_name": "eGon2035", # scenario: eGon2035, eGon100RE or status2019
# Scenario variations:
"scn_extension": None, # None or array of extension scenarios
"scn_decommissioning": None, # None or decommissioning scenario
# Export options:
"lpfile": False, # save pyomo's lp file: False or /path/to/lpfile.lp
"csv_export": "results", # save results as csv: False or /path/tofolder
Expand Down Expand Up @@ -149,15 +148,15 @@
"strategy": "simultaneous", # select strategy to cluster other sectors
},
"rural_heat": {
"base": ["CH4", "AC"],
"strategy": "simultaneous", # select strategy to cluster other sectors
"base": ["AC"],
"strategy": "consecutive", # select strategy to cluster other sectors
},
"H2": {
"H2_grid": {
"base": ["CH4"],
"strategy": "consecutive", # select strategy to cluster other sectors
},
"H2_saltcavern": {
"base": ["H2_grid"],
"base": ["AC"],
"strategy": "consecutive", # select strategy to cluster other sectors
},
"Li_ion": {
Expand Down Expand Up @@ -280,40 +279,20 @@ def run_etrago(args, json_path):
scn_name : str
Choose your scenario. Currently, there are two different
scenarios: "eGon2035", "eGon100RE". Default: "eGon2035".
scn_extension : None or str
This option does currently not work!
scn_extension : None or list of str

Choose extension-scenarios which will be added to the existing
network container. Data of the extension scenarios are located in
extension-tables (e.g. model_draft.ego_grid_pf_hv_extension_bus)
with the prefix 'extension\_'.
There are three overlay networks:

* 'nep2035_confirmed' includes all planed new lines confirmed by the
Bundesnetzagentur
* 'nep2035_b2' includes all new lines planned by the
Netzentwicklungsplan 2025 in scenario 2035 B2
* 'BE_NO_NEP 2035' includes planned lines to Belgium and Norway and
adds BE and NO as electrical neighbours

network container. In case new lines replace existing ones, these are
dropped from the network. Data of the extension scenarios is located in
extension-tables (e.g. grid.egon_etrago_extension_line)
There are two overlay networks:

* 'nep2021_confirmed' includes all planed new lines confirmed by the
Bundesnetzagentur included in the NEP version 2021
* 'nep2021_c2035' includes all new lines planned by the
Netzentwicklungsplan 2021 in scenario 2035 C
Default: None.
scn_decommissioning : NoneType or str
This option does currently not work!

Choose an extra scenario which includes lines you want to decommission
from the existing network. Data of the decommissioning scenarios are
located in extension-tables
(e.g. model_draft.ego_grid_pf_hv_extension_bus) with the prefix
'decommissioning\_'.
Currently, there are two decommissioning_scenarios which are linked to
extension-scenarios:

* 'nep2035_confirmed' includes all lines that will be replaced in
confirmed projects
* 'nep2035_b2' includes all lines that will be replaced in
NEP-scenario 2035 B2

Default: None.
lpfile : bool or str
State if and where you want to save pyomo's lp file. Options:
False or '/path/tofile.lp'. Default: False.
Expand Down Expand Up @@ -700,7 +679,7 @@ def run_etrago(args, json_path):

# adjust network regarding eTraGo setting
etrago.adjust_network()

# ehv network clustering
etrago.ehv_clustering()

Expand Down
1 change: 0 additions & 1 deletion etrago/args.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"model_formulation": "kirchhoff",
"scn_name": "eGon2035",
"scn_extension": null,
"scn_decommissioning": null,
"lpfile": false,
"csv_export": "results",
"extendable": {
Expand Down
107 changes: 68 additions & 39 deletions etrago/tools/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
__license__ = "GNU Affero General Public License Version 3 (AGPL-3.0)"
__author__ = "ulfmueller, mariusves, pieterhexen, ClaraBuettner"

from importlib import import_module
import os

import numpy as np
Expand Down Expand Up @@ -112,12 +111,14 @@ def __init__(
start_snapshot=1,
end_snapshot=20,
temp_id=1,
scenario_extension=False,
**kwargs,
):
self.scn_name = scn_name
self.start_snapshot = start_snapshot
self.end_snapshot = end_snapshot
self.temp_id = temp_id
self.scenario_extension = scenario_extension

super().__init__(engine, session, **kwargs)

Expand Down Expand Up @@ -207,6 +208,14 @@ def fetch_by_relname(self, name):
egon_etrago_transformer,
)

if self.scenario_extension:
from saio.grid import ( # noqa: F401,F811
egon_etrago_extension_bus as egon_etrago_bus,
egon_etrago_extension_line as egon_etrago_line,
egon_etrago_extension_link as egon_etrago_link,
egon_etrago_extension_transformer as egon_etrago_transformer,
)

index = f"{name.lower()}_id"

if name == "Transformer":
Expand Down Expand Up @@ -796,22 +805,17 @@ def extension(self, **kwargs):

"""
if self.args["scn_extension"] is not None:
if self.args["gridversion"] is None:
ormcls_prefix = "EgoGridPfHvExtension"
else:
ormcls_prefix = "EgoPfHvExtension"

for i in range(len(self.args["scn_extension"])):
scn_extension = self.args["scn_extension"][i]
# Adding overlay-network to existing network
scenario = NetworkScenario(
self.engine,
self.session,
version=self.args["gridversion"],
prefix=ormcls_prefix,
method=kwargs.get("method", "lopf"),
start_snapshot=self.args["start_snapshot"],
end_snapshot=self.args["end_snapshot"],
scn_name="extension_" + scn_extension,
scn_name=scn_extension,
scenario_extension=True,
)

self.network = scenario.build_network(self.network)
Expand Down Expand Up @@ -847,40 +851,65 @@ def decommissioning(self, **kwargs):
Network container including decommissioning

"""
if self.args["scn_decommissioning"] is not None:
if self.args["gridversion"] is None:
ormclass = getattr(
import_module("egoio.db_tables.model_draft"),
"EgoGridPfHvExtensionLine",
if self.args["scn_extension"] is not None:
for i in range(len(self.args["scn_extension"])):
scn_decom = self.args["scn_extension"][i]

df_decommisionning = pd.read_sql(
f"""
SELECT * FROM
grid.egon_etrago_extension_line
WHERE scn_name = 'decomissioining_{scn_decom}'
""",
self.session.bind,
)
else:
ormclass = getattr(
import_module("egoio.db_tables.grid"), "EgoPfHvExtensionLine"

self.network.mremove(
"Line",
df_decommisionning.line_id.astype(str).values,
)

query = self.session.query(ormclass).filter(
ormclass.scn_name
== "decommissioning_" + self.args["scn_decommissioning"]
)
# buses only between removed lines
candidates = pd.concat(
[df_decommisionning.bus0, df_decommisionning.bus1]
)
candidates.drop_duplicates(inplace=True, keep="first")
candidates = candidates.astype(str)

df_decommisionning = pd.read_sql(
query.statement, self.session.bind, index_col="line_id"
)
df_decommisionning.index = df_decommisionning.index.astype(str)

for idx, row in self.network.lines.iterrows():
if (row["s_nom_min"] != 0) & (
row["scn_name"]
== "extension_" + self.args["scn_decommissioning"]
):
self.network.lines.s_nom_min[
self.network.lines.index == idx
] = self.network.lines.s_nom_min

# Drop decommissioning-lines from existing network
self.network.lines = self.network.lines[
~self.network.lines.index.isin(df_decommisionning.index)
]
# Drop buses that are connecting other lines
candidates = candidates[~candidates.isin(self.network.lines.bus0)]
candidates = candidates[~candidates.isin(self.network.lines.bus1)]

# Drop buses that are connection other DC-lines
candidates = candidates[~candidates.isin(self.dc_lines().bus0)]
candidates = candidates[~candidates.isin(self.dc_lines().bus1)]

drop_buses = self.network.buses[
(self.network.buses.index.isin(candidates.values))
& (self.network.buses.country == "DE")
]

drop_links = self.network.links[
(self.network.links.bus0.isin(drop_buses.index))
| (self.network.links.bus1.isin(drop_buses.index))
].index

drop_trafos = self.network.transformers[
(self.network.transformers.bus0.isin(drop_buses.index))
| (self.network.transformers.bus1.isin(drop_buses.index))
].index

drop_su = self.network.storage_units[
self.network.storage_units.bus.isin(candidates.values)
].index

self.network.mremove("StorageUnit", drop_su)

self.network.mremove("Transformer", drop_trafos)

self.network.mremove("Link", drop_links)

self.network.mremove("Bus", drop_buses.index)


def distance(x0, x1, y0, y1):
Expand Down
Loading