generated from iiasa/scse-workflow-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
workflow.py
63 lines (53 loc) · 1.76 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import logging
import sys
from pathlib import Path
import pyam
from nomenclature import DataStructureDefinition, RegionProcessor, process
try:
from climate_processor import MAGICCProcessor
FOUND_MAGICC = True
except ImportError:
FOUND_MAGICC = False
logging.basicConfig(format="%(asctime)s - %(message)s", level=logging.INFO)
logFormatter = logging.Formatter("%(asctime)s [%(levelname)-5.5s] %(message)s")
log = logging.getLogger()
log.handlers.clear()
consoleHandler = logging.StreamHandler(sys.stdout)
consoleHandler.setFormatter(logFormatter)
log.addHandler(consoleHandler)
here = Path(__file__).absolute().parent
def main(df: pyam.IamDataFrame) -> pyam.IamDataFrame:
"""Project/instance-specific workflow for scenario processing"""
# Run the validation and region-processing
dsd = DataStructureDefinition(here / "definitions")
processed_df = process(
df,
dsd,
processor=RegionProcessor.from_directory(
path=here / "mappings",
dsd=dsd,
),
)
if FOUND_MAGICC:
magicc_processor = MAGICCProcessor(
run_type="complete",
magicc_worker_number=8,
magicc_variables=[
"*Atmospheric Concentrations*",
"*Exceedance Probability*",
"*Effective Radiative Forcing*",
"*Surface Temperature*",
"*Infilled*",
"*Harmonized*",
],
)
try:
return magicc_processor.apply(processed_df)
except Exception as e:
log.warning(
(
"Error with MAGICC processing, repeat processing without MAGICC, "
f"details: {e}"
)
)
return processed_df