generated from iiasa/scse-workflow-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
workflow.py
33 lines (22 loc) · 1.14 KB
/
workflow.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from pathlib import Path
import pyam
from nomenclature import DataStructureDefinition, RegionProcessor, process
import logging
here = Path(__file__).absolute().parent
logger = logging.getLogger(__name__)
file_handler = logging.FileHandler(snakemake.log[0], mode="a")
file_handler.setLevel(logging.DEBUG)
# Define a logging format (optional)
formatter = logging.Formatter("%(asctime)s %(levelname)s %(message)s", "%Y-%m-%d %H:%M:%S")
file_handler.setFormatter(formatter)
for logger_name in ["ixmp4", "pyam", "nomenclature", logger.name]:
logging.getLogger(logger_name).addHandler(file_handler)
def main(df: pyam.IamDataFrame) -> pyam.IamDataFrame:
"""Project/instance-specific workflow for scenario processing"""
# Run the validation and region-processing
dsd = DataStructureDefinition(here / "definitions")
processor = RegionProcessor.from_directory(path=here / "mappings", dsd=dsd)
return process(df, dsd, processor=processor)
logger.info(f"Starting processing for {snakemake.input[0]}")
main(pyam.IamDataFrame(snakemake.input[0])).to_excel(snakemake.output[0])
logger.info(f"Successfully finished processing for {snakemake.input[0]}")