Add rule create_scenarios that runs config/create_scenarios.py on request
This commit is contained in:
parent
67acbbda8a
commit
83f1b5e41d
@ -93,6 +93,13 @@ rule all:
|
|||||||
default_target: True
|
default_target: True
|
||||||
|
|
||||||
|
|
||||||
|
rule create_scenarios:
|
||||||
|
output:
|
||||||
|
config["run"]["scenarios"]["file"],
|
||||||
|
script:
|
||||||
|
"config/create_scenarios.py"
|
||||||
|
|
||||||
|
|
||||||
rule purge:
|
rule purge:
|
||||||
run:
|
run:
|
||||||
import builtins
|
import builtins
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# SPDX-FileCopyrightText: : 2017-2023 The PyPSA-Eur Authors
|
# SPDX-FileCopyrightText: : 2023-2024 The PyPSA-Eur Authors
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
# This script helps to generate a scenarios.yaml file for PyPSA-Eur.
|
# This script helps to generate a scenarios.yaml file for PyPSA-Eur.
|
||||||
# You can modify the template to your needs and define all possible combinations of config values that should be considered.
|
# You can modify the template to your needs and define all possible combinations of config values that should be considered.
|
||||||
|
|
||||||
|
if "snakemake" in globals():
|
||||||
|
filename = snakemake.output[0]
|
||||||
|
else:
|
||||||
|
filename = "../config/scenarios.yaml"
|
||||||
|
|
||||||
import itertools
|
import itertools
|
||||||
|
|
||||||
@ -14,23 +18,23 @@ import itertools
|
|||||||
template = """
|
template = """
|
||||||
scenario{scenario_number}:
|
scenario{scenario_number}:
|
||||||
config_section:
|
config_section:
|
||||||
config_value: {config_value}
|
config_key: {config_value}
|
||||||
|
|
||||||
config_section2:
|
config_section2:
|
||||||
config_key2: {config_value2}
|
config_key2: {config_value2}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Define all possible combinations of config values.
|
# Define all possible combinations of config values.
|
||||||
# This must define all config values that are used in the template.
|
# This must define all config values that are used in the template.
|
||||||
config_values = dict(config_values=["true", "false"], config_values2=[1, 2, 3, 4, 5])
|
config_values = dict(
|
||||||
|
config_value=["true", "false"],
|
||||||
|
config_value2=[1, 2, 3, 4]
|
||||||
|
)
|
||||||
|
|
||||||
combinations = [
|
combinations = [
|
||||||
dict(zip(config_values.keys(), values))
|
dict(zip(config_values.keys(), values))
|
||||||
for values in itertools.product(*config_values.values())
|
for values in itertools.product(*config_values.values())
|
||||||
]
|
]
|
||||||
|
|
||||||
# write the scenarios to a file
|
|
||||||
filename = "../config/scenarios.yaml"
|
|
||||||
with open(filename, "w") as f:
|
with open(filename, "w") as f:
|
||||||
for i, config in enumerate(combinations):
|
for i, config in enumerate(combinations):
|
||||||
f.write(template.format(scenario_number=i, **config))
|
f.write(template.format(scenario_number=i, **config))
|
||||||
|
Loading…
Reference in New Issue
Block a user