Skip to content

Commit

Permalink
validation integration
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorb1 committed Oct 14, 2024
1 parent 2a46eb6 commit 9360e76
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
12 changes: 9 additions & 3 deletions workflow/scripts/osemosys_global/validation/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}

Expand All @@ -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:
Expand Down
21 changes: 19 additions & 2 deletions workflow/snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand Down

0 comments on commit 9360e76

Please sign in to comment.