Source code for models.utils

from colorama import Fore, Style
from typing import Optional
from pathlib import Path
import pickle
import yaml








[docs] def save_pickle(data, file_path): file_path = Path(file_path) # Ensure file_path is not a directory if file_path.is_dir(): file_path = file_path / "default.pkl" # Append a default filename if needed file_path.parent.mkdir(parents=True, exist_ok=True) with open(file_path, 'wb') as file: pickle.dump(data, file)
[docs] def load_config(config_file): ''' This function loads the configuration file for PyPSA_BC config_file: Path + filename of the configuration file. (i.e. ../config/config.yaml) ''' with open(config_file, 'r') as file: cfg = yaml.safe_load(file) return cfg