Skip to content

Commit

Permalink
CH4_H2_table only used if table exists and if scn_name is inside of t…
Browse files Browse the repository at this point in the history
…he table
  • Loading branch information
lenzim97 committed Jan 27, 2025
1 parent d79eea9 commit bd4cc0a
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions etrago/tools/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -999,18 +999,24 @@ def add_ch4_h2_correspondence(self):
It contains the mapping from H2 buses to their corresponding CH4 buses.
"""

sql = """
SELECT "bus_H2", "bus_CH4", scn_name FROM grid.egon_etrago_ch4_h2;
"""

table = pd.read_sql(sql, self.engine)

self.ch4_h2_mapping = pd.Series(
table.bus_H2.values, index=table.bus_CH4.values.astype(str)
)
self.ch4_h2_mapping.index.name = "CH4_bus"
self.ch4_h2_mapping = self.ch4_h2_mapping.astype(str)
try:
pd.read_sql("SELECT 1 FROM grid.egon_etrago_ch4_h2 LIMIT 1;", self.engine)
table_exists = True
except Exception as e:
table_exists = False

if table_exists:
sql = """
SELECT "bus_H2", "bus_CH4", scn_name FROM grid.egon_etrago_ch4_h2;
"""
table = pd.read_sql(sql, self.engine)

if self.args['scn_name'] in table.scn_name.values:
self.ch4_h2_mapping = pd.Series(
table.bus_H2.values, index=table.bus_CH4.values.astype(str)
)
self.ch4_h2_mapping.index.name = "CH4_bus"
self.ch4_h2_mapping = self.ch4_h2_mapping.astype(str)


if __name__ == "__main__":
Expand Down

0 comments on commit bd4cc0a

Please sign in to comment.