From 9360e76997496c77802ce9657549fed8ac56e532 Mon Sep 17 00:00:00 2001 From: trevorb1 Date: Sun, 13 Oct 2024 21:19:16 -0700 Subject: [PATCH] validation integration --- .../osemosys_global/validation/main.py | 12 ++++++++--- workflow/snakefile | 21 +++++++++++++++++-- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/workflow/scripts/osemosys_global/validation/main.py b/workflow/scripts/osemosys_global/validation/main.py index cbb201d6..fe6ea895 100644 --- a/workflow/scripts/osemosys_global/validation/main.py +++ b/workflow/scripts/osemosys_global/validation/main.py @@ -94,12 +94,18 @@ def get_emission_funcs(datasource: str) -> dict[str, callable]: if __name__ == "__main__": if "snakemake" in globals(): - raise NotImplementedError + datasource = snakemake.wildcards.datasource + variable = snakemake.params.variable + result_dir = snakemake.params.result_dir + validation_data = snakemake.input.validation_data + options = {} + if snakemake.input.get("iso_codes"): + options["iso_codes"] = snakemake.input.iso_codes else: datasource = "climatewatch" variable = "emissions" result_dir = "results/India/results" - data_file = "resources/data/validation/climate-watch-emissions.csv" + validation_data = "resources/data/validation/climate-watch-emissions.csv" options = {} # options = {"iso_codes": "resources/data/validation/iso.csv"} @@ -123,7 +129,7 @@ def get_emission_funcs(datasource: str) -> dict[str, callable]: # perform the validation try: - actual = funcs["getter"](data_file, **options) + actual = funcs["getter"](validation_data, **options) modelled = pd.read_csv(Path(result_dir, f"{og_result}.csv")) modelled = funcs["formatter"](modelled) except KeyError as e: diff --git a/workflow/snakefile b/workflow/snakefile index ab2c20bb..4ad36b7c 100644 --- a/workflow/snakefile +++ b/workflow/snakefile @@ -45,12 +45,15 @@ OTOOLE_YAML = "resources/otoole.yaml" OTOOLE_PARAMS = get_otoole_data(OTOOLE_YAML, "param") OTOOLE_RESULTS = get_otoole_data(OTOOLE_YAML, "result") +COUNTRIES = config["geographic_scope"] + # rules include: "rules/preprocess.smk" include: "rules/model.smk" include: "rules/postprocess.smk" include: "rules/retrieve.smk" +include: "rules/validate.smk" # handlers @@ -71,15 +74,29 @@ if not os.path.isdir(Path('results', 'data')): # target rules +wildcard_constraints: + scenario="[A-Za-z0-9]+" + rule all: message: - 'All rules executed successfully...' + 'Running workflow...' input: + # demand projections expand('results/figs/{demand_figure}.png', demand_figure=["regression", "projection"]), + + # model results expand('results/{scenario}/result_summaries/{result_summary}.csv', scenario=config['scenario'], result_summary=result_summaries), expand('results/{scenario}/figures/{result_figure}.html', - scenario=config['scenario'], result_figure = result_figures) + scenario=config['scenario'], result_figure = result_figures), + + # validation results + expand("results/{scenario}/validation/{country}/capacity/{dataset}.png", + scenario=config['scenario'], country=COUNTRIES, dataset=CAPACITY_VALIDATION), + expand("results/{scenario}/validation/{country}/generation/{dataset}.png", + scenario=config['scenario'], country=COUNTRIES, dataset=GENERATION_VALIDATION), + expand("results/{scenario}/validation/{country}/emissions/{dataset}.png", + scenario=config['scenario'], country=COUNTRIES, dataset=EMISSION_VALIDATION), rule generate_input_data: message: