Creating a MISO2 config
[ ]:
import logging
import os
from datetime import datetime
from util.MISO2_file_manager import get_parameter_filenames
from model.config.MISO2_logger import get_MISO2_logger
from model.config.MISO2_config import MISO2Config
from preprocessing.checks.MISO2_input_data_sanity_check import input_data_sanity_check
Set file paths in relation to the directory where you are executing the code from
[ ]:
main_path = os.path.join(os.getcwd(), os.pardir, os.pardir, os.pardir)
input_path = os.path.join(main_path, "input", "input_usuk")
config_path = os.path.join(main_path, "config")
config_filename = 'MISO2_Config_USUK_v1.xlsx'
classification_filename = 'MISO2_Classifications_Master_USUK_v1.xlsx'
# config and classification need to be manually set. different configs may make use of the same set of input parameter files
Set logging levels. Use a level lower than WARN only for debugging purposes
[ ]:
timestamp = datetime.now().strftime("%Y_%m_%d_%H_%M_%S")
get_MISO2_logger(
log_filename='MISO2_log_' + timestamp + ".txt",
log_pathname=os.path.join(main_path, 'logs'),
file_level=None,
console_level=logging.WARN)
It never hurts to make a sanity data check of the input files. Note that this has a write back option available which you probably do not want to use blindly. The sanity check controls for dimensions and data availability and emits warnings if it encounters a mismatch. Output is omitted here.
[ ]:
filenames = get_parameter_filenames(input_path, config_filename)
input_data_sanity_check(input_path, filenames, write_back=False)
Parsing uses ODYM functionality
[ ]:
miso_config = MISO2Config(data_path=input_path,
config_path=config_path,
timestamp=timestamp)
miso_config.initialise_from_excel(config_filename=config_filename,
classification_filename=classification_filename,
parse_uncertainty=True)
Save the config for later use in a binary format
[ ]:
miso_config.save_to_pickle("selected_countries_config.pickle")