diff --git a/Snakefile b/Snakefile index 5480074e..8a178290 100644 --- a/Snakefile +++ b/Snakefile @@ -1070,6 +1070,7 @@ rule build_transport_demand: rule prepare_sector_network: + params: RDIR = RDIR input: overrides="data/override_component_attrs", network='resources/' + RDIR + 'networks/elec_s{simpl}_{clusters}_ec_l{ll}_{opts}.nc', @@ -1138,6 +1139,7 @@ rule plot_network: rule copy_config: + params: RDIR = RDIR output: "results/" + RDIR + 'configs/config.yaml' threads: 1 resources: mem_mb=1000 @@ -1154,6 +1156,7 @@ rule copy_conda_env: rule make_summary: + params: RDIR = RDIR input: overrides="data/override_component_attrs", networks=expand( @@ -1188,6 +1191,7 @@ rule make_summary: rule plot_summary: + params: RDIR = RDIR input: costs="results/" + RDIR + 'csvs/costs.csv', energy="results/" + RDIR + 'csvs/energy.csv', diff --git a/scripts/copy_config.py b/scripts/copy_config.py index 0e071b77..8c2e26a9 100644 --- a/scripts/copy_config.py +++ b/scripts/copy_config.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from shutil import copy +from pathlib import Path import yaml @@ -9,7 +10,6 @@ files = { "Snakefile": "Snakefile", "scripts/solve_network.py": "solve_network.py", "scripts/prepare_sector_network.py": "prepare_sector_network.py", - "../pypsa-eur/config.yaml": "config.pypsaeur.yaml", } if __name__ == "__main__": @@ -18,14 +18,12 @@ if __name__ == "__main__": snakemake = mock_snakemake("copy_config") - basepath = ( - snakemake.config["summary_dir"] + "/" + snakemake.config["run"] + "/configs/" - ) + basepath = Path(f"results/{snakemake.params.RDIR}configs/") for f, name in files.items(): - copy(f, basepath + name) + copy(f, basepath / name) - with open(basepath + "config.snakemake.yaml", "w") as yaml_file: + with open(basepath / "config.snakemake.yaml", "w") as yaml_file: yaml.dump( snakemake.config, yaml_file, diff --git a/scripts/make_summary.py b/scripts/make_summary.py index 70e161cc..76f08392 100644 --- a/scripts/make_summary.py +++ b/scripts/make_summary.py @@ -676,10 +676,9 @@ if __name__ == "__main__": logging.basicConfig(level=snakemake.config["logging"]["level"]) networks_dict = { - (cluster, lv, opt + sector_opt, planning_horizon): snakemake.config[ - "results_dir" - ] - + snakemake.config["run"] + (cluster, lv, opt + sector_opt, planning_horizon): + "results/" + + snakemake.params.RDIR + f"/postnetworks/elec_s{simpl}_{cluster}_lv{lv}_{opt}_{sector_opt}_{planning_horizon}.nc" for simpl in snakemake.config["scenario"]["simpl"] for cluster in snakemake.config["scenario"]["clusters"] @@ -706,8 +705,5 @@ if __name__ == "__main__": if snakemake.config["foresight"] == "myopic": cumulative_cost = calculate_cumulative_cost() cumulative_cost.to_csv( - snakemake.config["summary_dir"] - + "/" - + snakemake.config["run"] - + "/csvs/cumulative_cost.csv" + f"results" + snakemake.params.RDIR + "/csvs/cumulative_cost.csv" ) diff --git a/scripts/plot_network.py b/scripts/plot_network.py index fed50b40..33a92b75 100644 --- a/scripts/plot_network.py +++ b/scripts/plot_network.py @@ -892,9 +892,9 @@ def plot_series(network, carrier="AC", name="test"): fig.tight_layout() fig.savefig( - "{}{}/maps/series-{}-{}-{}-{}-{}.pdf".format( - snakemake.config["results_dir"], - snakemake.config["run"], + "{}/{RDIR}maps/series-{}-{}-{}-{}-{}.pdf".format( + "results", + snakemake.params.RDIR, snakemake.wildcards["lv"], carrier, start, diff --git a/scripts/plot_summary.py b/scripts/plot_summary.py index 570f2d32..72b95ff7 100644 --- a/scripts/plot_summary.py +++ b/scripts/plot_summary.py @@ -452,7 +452,7 @@ def plot_carbon_budget_distribution(input_eurostat): ax1.set_ylim([0, 5]) ax1.set_xlim([1990, snakemake.config["scenario"]["planning_horizons"][-1] + 1]) - path_cb = snakemake.config["results_dir"] + snakemake.config["run"] + "/csvs/" + path_cb = "results/" + snakemake.params.RDIR + "/csvs/" countries = pd.read_csv(snakemake.input.country_codes, index_col=1) cts = countries.index.to_list() e_1990 = co2_emissions_year(cts, input_eurostat, opts, year=1990) @@ -532,7 +532,7 @@ def plot_carbon_budget_distribution(input_eurostat): ) path_cb_plot = ( - snakemake.config["results_dir"] + snakemake.config["run"] + "/graphs/" + "results/" + snakemake.params.RDIR + "/graphs/" ) plt.savefig(path_cb_plot + "carbon_budget_plot.pdf", dpi=300) diff --git a/scripts/prepare_sector_network.py b/scripts/prepare_sector_network.py index d2f7af41..0771a765 100644 --- a/scripts/prepare_sector_network.py +++ b/scripts/prepare_sector_network.py @@ -3344,8 +3344,8 @@ if __name__ == "__main__": continue limit_type = "carbon budget" fn = ( - snakemake.config["results_dir"] - + snakemake.config["run"] + "results/" + + snakemake.params.RDIR + "/csvs/carbon_budget_distribution.csv" ) if not os.path.exists(fn):