From 4e4de1aba36bf981b9b04dc7b36d06a899c932a9 Mon Sep 17 00:00:00 2001 From: Daniel Huppmann Date: Fri, 1 Mar 2024 10:15:47 +0100 Subject: [PATCH] Allow directional timeseries data (region-to-region) (#6) --- workflow.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/workflow.py b/workflow.py index 2e65188..9b8683a 100644 --- a/workflow.py +++ b/workflow.py @@ -9,11 +9,28 @@ def main(df: pyam.IamDataFrame) -> pyam.IamDataFrame: """Project/instance-specific workflow for scenario processing""" - # Run the validation and region-processing + # initialize the codelists and region-processing dsd = DataStructureDefinition( here / "definitions", dimensions=["scenario", "region", "variable"] ) processor = RegionProcessor.from_directory(path=here / "mappings", dsd=dsd) + + # check if directional data exists in the scenario data, add to region codelist + if any([r for r in df.region if ">" in r]): + for r in df.region: + if r in definition.region: + continue + r_split = r.split(">") + if len(r_split) > 2: + raise ValueError( + f"Directional data other than `origin>destination` not allowed: {r}" + ) + elif len(r_split) == 2: + if all([_r in definition.region for _r in r_split]): + # add the directional-region to the codelist (without attributes) + definition.region[r] = None + + # run the validation and region-processing df = process(df, dsd, processor=processor) # assign meta indicator for scenario "work package" category