Skip to content

Commit 922e209

Browse files
committed
Add no hydro scenario
1 parent 4fde87c commit 922e209

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
"""
2+
####################
3+
Create a no hydro scenario
4+
5+
Date applied: 2021-07-30
6+
Description:
7+
This script adds a scenario to the database that effectively removes all hydro generation from the model.
8+
#################
9+
"""
10+
import time
11+
12+
from switch_model.utilities import query_yes_no, format_seconds
13+
from switch_model.wecc.utilities import connect
14+
import pandas as pd
15+
16+
all_plants_scenario = 23
17+
18+
new_scenario_id = 25
19+
new_scenario_name = "No Hydro"
20+
new_scenario_description = "All average flows are zero effectively removing all hydro generation from the model." \
21+
" Represents as an extreme edge case of no hydro generation."
22+
23+
24+
def main():
25+
db_conn = connect()
26+
db_cursor = db_conn.cursor()
27+
28+
# 1. Get all the hydro plants
29+
db_cursor.execute(
30+
f"""
31+
SELECT DISTINCT generation_plant_id, year, month, hydro_min_flow_mw, hydro_avg_flow_mw FROM hydro_historical_monthly_capacity_factors
32+
WHERE hydro_simple_scenario_id={all_plants_scenario};
33+
""")
34+
df = pd.DataFrame(db_cursor.fetchall(),
35+
columns=["generation_plant_id", "year", "month", "hydro_min_flow_mw", "hydro_avg_flow_mw"])
36+
37+
# 2. Set all the flows to zero and set the scenario id
38+
df["hydro_min_flow_mw"] = 0
39+
df["hydro_avg_flow_mw"] = 0
40+
df["hydro_simple_scenario_id"] = new_scenario_id
41+
42+
# 3. Add data to database
43+
print(f"hydro_simple_scenario: {new_scenario_id}")
44+
print(f"name: {new_scenario_name}")
45+
print(f"description: {new_scenario_description}")
46+
print(f"Num hydro plants: {df.generation_plant_id.nunique()}")
47+
print(f"Example data:\n{df.head()}")
48+
49+
if not query_yes_no("\nAre you sure you want to add this data to the database?", default="no"):
50+
raise SystemExit
51+
52+
db_cursor.execute(
53+
"INSERT INTO hydro_simple_scenario(hydro_simple_scenario_id, name, description) "
54+
f"VALUES ('{new_scenario_id}','{new_scenario_name}','{new_scenario_description}')"
55+
)
56+
57+
n = len(df)
58+
start_time = time.time()
59+
for i, r in enumerate(df.itertuples(index=False)):
60+
if i != 0 and i % 1000 == 0:
61+
print(
62+
f"{i}/{n} inserts completed. Estimated time remaining {format_seconds((n - i) * (time.time() - start_time) / i)}")
63+
db_cursor.execute(
64+
f"INSERT INTO hydro_historical_monthly_capacity_factors(hydro_simple_scenario_id, generation_plant_id, year, month, hydro_min_flow_mw, hydro_avg_flow_mw) "
65+
f"VALUES ({r.hydro_simple_scenario_id},{r.generation_plant_id},{r.year},{r.month},{r.hydro_min_flow_mw},{r.hydro_avg_flow_mw})"
66+
)
67+
68+
db_conn.commit()
69+
db_cursor.close()
70+
db_conn.close()
71+
print("Done.")
72+
73+
74+
if __name__ == "__main__":
75+
main()

0 commit comments

Comments
 (0)