Skip to content

Commit

Permalink
Delete unconnected o2_buses; provide Implementation of multiple o2 lo…
Browse files Browse the repository at this point in the history
…ads to one o2 bus
  • Loading branch information
lenzim97 committed Jan 13, 2025
1 parent 608de61 commit 9222333
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/egon/data/datasets/hydrogen_etrago/power_to_h2.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ def insert_o2_load_points(df):
f"DELETE FROM {schema}.{table_name} WHERE carrier = 'O2' AND scn_name = '{SCENARIO_NAME}'"
)
df = df.copy(deep=True)
df = df[df["carrier"] == "power_to_O2"]
df = df.drop_duplicates(subset='bus1', keep='first')
result = []
for _, row in df.iterrows():
load_id = next(next_load_id)
Expand All @@ -882,6 +882,14 @@ def insert_o2_load_timeseries(df):

base_load_profile = pd.read_sql(query_o2_timeseries, engine)['load_curve'].values
base_load_profile = np.array(base_load_profile[0])

with engine.connect() as conn:
conn.execute(f"""
DELETE FROM {targets["load_timeseries"]["schema"].targets["load_timeseries"]["table"]}
WHERE load_id IN {tuple(df.load_id.values)}
AND scn_name = '{SCENARIO_NAME}'
"""
)

timeseries_list = []

Expand Down Expand Up @@ -924,7 +932,7 @@ def insert_o2_generators(df):
f"DELETE FROM {grid}.{table_name} WHERE carrier = 'O2' AND scn_name = '{SCENARIO_NAME}'"
)
df = df.copy(deep=True)
df = df[df["carrier"] == "power_to_O2"]
df = df.drop_duplicates(subset='bus1', keep='first')
result = []
for _, row in df.iterrows():
generator_id = next(next_generator_id)
Expand Down Expand Up @@ -953,6 +961,7 @@ def adjust_ac_load_timeseries(df, o2_timeseries):
WHERE scn_name = '{SCENARIO_NAME}'
"""
dfs[AC_LOAD] = pd.read_sql(queries[AC_LOAD], engine)
df = df.drop_duplicates(subset='bus1', keep='first')
ac_loads = pd.merge(df, dfs[AC_LOAD], left_on='bus0', right_on='bus')

#reduce each affected ac_load with o2_timeseries
Expand Down Expand Up @@ -987,6 +996,16 @@ def adjust_ac_load_timeseries(df, o2_timeseries):
else:
print(f"No matching o2_timeseries entry for load_id {row['load_id']}")

def delete_unconnected_o2_buses():
with engine.connect() as conn:
conn.execute(f"""
DELETE FROM {targets['buses']['schema']}.{targets['buses']['table']}
WHERE carrier = 'O2' AND scn_name = '{SCENARIO_NAME}'
AND bus_id NOT IN (SELECT bus1 FROM {targets['links']['schema']}.{targets['links']['table']}
WHERE carrier = 'power_to_O2')
"""
)


def execute_PtH2_method():

Expand All @@ -1004,6 +1023,7 @@ def execute_PtH2_method():
o2_timeseries = insert_o2_load_timeseries(o2_loads_df)
insert_o2_generators(power_to_O2)
adjust_ac_load_timeseries(power_to_O2, o2_timeseries)
delete_unconnected_o2_buses()

execute_PtH2_method()

Expand Down

0 comments on commit 9222333

Please sign in to comment.