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