Skip to content

Commit

Permalink
Merge branch 'features/extendable_lines_from_nep' into features/hybit…
Browse files Browse the repository at this point in the history
…_pw_constraints
  • Loading branch information
birgits committed Aug 5, 2024
2 parents 507ff07 + 45c6be8 commit 7b8687d
Showing 1 changed file with 54 additions and 29 deletions.
83 changes: 54 additions & 29 deletions etrago/tools/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -864,39 +864,64 @@ def decommissioning(self, **kwargs):
"""
if self.args["scn_decommissioning"] is not None:
if self.args["gridversion"] is None:
ormclass = getattr(
import_module("egoio.db_tables.model_draft"),
"EgoGridPfHvExtensionLine",
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

0 comments on commit 7b8687d

Please sign in to comment.