@@ -211,7 +211,9 @@ def write_to_scenario_yaml(input, output, scenarios, df):
211211 yaml = ruamel .yaml .YAML ()
212212 file_path = Path (input )
213213 config = yaml .load (file_path )
214+
214215 for scenario in scenarios :
216+ print ("Writing scenario config for scenario:" , scenario )
215217 if config .get (scenario ) is None :
216218 logger .warning (
217219 f"Found an empty scenario config for { scenario } . Using default config `pypsa.de.yaml`."
@@ -230,13 +232,13 @@ def write_to_scenario_yaml(input, output, scenarios, df):
230232 write_weather_dependent_config (config , scenario , weather_year )
231233
232234 reference_scenario = (
233- config [scenario ]
234- .get ("pypsa-de" , {})
235- .get (
236- "reference_scenario" ,
237- snakemake .config ["pypsa-de" ]["reference_scenario" ],
238- ) # Using the default reference scenario from pypsa.de.yaml
235+ config [scenario ].get ("pypsa-de" , {}).get ("reference_scenario" )
239236 )
237+ if reference_scenario is None :
238+ reference_scenario = snakemake .config ["pypsa-de" ]["reference_scenario" ]
239+ logger .warning (
240+ f"No reference scenario specified for { scenario } . Using default reference scenario { reference_scenario } from pypsa.de.yaml."
241+ )
240242
241243 planning_horizons = [
242244 2020 ,
@@ -326,6 +328,10 @@ def write_to_scenario_yaml(input, output, scenarios, df):
326328 year
327329 ] = target
328330
331+ # remove all other keys that are not in the scenarios list
332+ for key in list (config .keys ()):
333+ if key not in scenarios :
334+ del config [key ]
329335 # write back to yaml file
330336 yaml .dump (config , Path (output ))
331337
0 commit comments