@@ -16,7 +16,8 @@ def fetch_df(tab_name, key, config):
1616 TAB_NAME_GID = {
1717 "constants" : 0 ,
1818 "plants" : 889129113 ,
19- "costs" : 1401952285
19+ "costs" : 1401952285 ,
20+ "minimums" : 1049456965
2021 }
2122 SHEET_ID = "1SJrj039T1T95NLTs964VQnsfZgo2QWCo29x2ireVYcU"
2223
@@ -52,24 +53,24 @@ def cross_join(df1, df2):
5253 ).drop ("key" , axis = 1 )
5354
5455
55- def append_to_csv (filename , to_add , primary_key = None ):
56+ def add_to_csv (filename , to_add , primary_key = None , append = True ):
5657 """
5758 Used to append a dataframe to an input .csv file
5859 """
59- df = pd .read_csv (filename , index_col = False )
60- df = pd .concat ([df , to_add ], ignore_index = True )[df .columns ]
60+ if append :
61+ try :
62+ df = pd .read_csv (filename , index_col = False )
63+ df = pd .concat ([df , to_add ], ignore_index = True )[df .columns ]
64+ except FileNotFoundError :
65+ df = to_add
66+ else :
67+ df = to_add
6168 # Confirm that primary_key is unique
6269 if primary_key is not None :
6370 assert len (df [primary_key ]) == len (df [primary_key ].drop_duplicates ())
6471 df .to_csv (filename , index = False )
6572
6673
67- def get_gen_constants (config ):
68- df = fetch_df ("constants" , "constant_scenario" , config )
69- df = df .set_index ("param_name" )
70- return df .transpose ()
71-
72-
7374def drop_previous_candidate_storage ():
7475 """
7576 Drops all candidate storage from the model
@@ -107,22 +108,25 @@ def main(config):
107108 drop_previous_candidate_storage ()
108109
109110 # Get the generation storage plants from Google Sheet
110- gen_constants = get_gen_constants (config )
111- gen_plants = fetch_df ("plants" , "plants_scenario" , config )
112- gen_plants = cross_join (gen_plants , gen_constants )
111+ gen_projects = fetch_df ("constants" , "constant_scenario" , config ).set_index ("param_name" ).transpose ()
112+ gen_projects = cross_join (gen_projects , fetch_df ("plants" , "plants_scenario" , config ))
113113
114114 # Append the storage plants to the inputs
115- append_to_csv ("generation_projects_info.csv" , gen_plants , primary_key = "GENERATION_PROJECT" )
115+ add_to_csv ("generation_projects_info.csv" , gen_projects , primary_key = "GENERATION_PROJECT" )
116+
117+ # Create min_per_tech.csv
118+ min_projects = fetch_df ("minimums" , "minimums_scenario" , config )
119+ add_to_csv ("min_per_tech.csv" , min_projects , primary_key = ["gen_tech" , "period" ], append = False )
116120
117121 # Get the plant costs from GSheets and append to costs
118122 storage_costs = fetch_df ("costs" , "costs_scenario" , config )
119- append_to_csv ("gen_build_costs.csv" , storage_costs , primary_key = ["GENERATION_PROJECT" , "build_year" ])
123+ add_to_csv ("gen_build_costs.csv" , storage_costs , primary_key = ["GENERATION_PROJECT" , "build_year" ])
120124
121125 # Create add_storage_info.csv
122126 pd .DataFrame ([config ]).transpose ().to_csv ("add_storage_info.csv" , header = False )
123127
124128 # Add the storage types to the graphs
125- gen_type = gen_plants [["gen_tech" , "gen_energy_source" ]].drop_duplicates ()
129+ gen_type = gen_projects [["gen_tech" , "gen_energy_source" ]].drop_duplicates ()
126130 gen_type .columns = ["gen_tech" , "energy_source" ]
127131 gen_type ["map_name" ] = "default"
128132 gen_type ["gen_type" ] = "Storage"
0 commit comments