Skip to content

Commit

Permalink
Add snakemake processing to workflow.py
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhuppmann committed Nov 4, 2024
1 parent e5bc163 commit 2dca736
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions workflow.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
from pathlib import Path
from pyam import IamDataFrame
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: IamDataFrame) -> IamDataFrame:
"""Project/instance-specific workflow for scenario processing"""

Expand All @@ -14,5 +28,6 @@ def main(df: IamDataFrame) -> IamDataFrame:
processor = RegionProcessor.from_directory(path=here / "mappings", dsd=dsd)
return process(df, dsd, processor=processor)

def public(df: IamDataFrame) -> IamDataFrame:
return df
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]}")

0 comments on commit 2dca736

Please sign in to comment.