Source code for bc_combined_modelling.attributes_parser

import yaml
from dataclasses import dataclass, field
from pathlib import Path
from typing import Dict
import logging as log

# Logging Configuration
log.basicConfig(level=log.INFO, format='%(asctime)s - %(levelname)s - %(message)s')

[docs] @dataclass class AttributesParser: """ This is the parent class that will extract the core attributes from the User Config file. ## Remarks: - Handles the clews_builder.yaml file creation and updates under-the hood. - The clews_builder.yaml file if not exists will mirror the skeleton file sourced from 'models/BC_Nexus/config/clews_builder_skeleton.yaml' """ # Attributes that are required as Args. combined_model_config_path:str|Path= field(default='config/config.yaml') def __post_init__(self): self.combined_model_config_path=Path(self.combined_model_config_path) # Define the path and filename # self.store = Path("data/store/BC_Combined_Modelling_results_.h5") # self.store.parent.mkdir(parents=True, exist_ok=True) self.data_cfg_path:str|Path=('config/data.yaml') self.clews_builder_config_path:str|Path=Path('config/clews_builder.yaml') # Kept it as under the hood config file build and updated automatically. self.clews_builder_skeleton_source:str|Path=Path('models/BC_Nexus/config/clews_builder_skeleton.yaml') # Load the user configuration master file by using the method # self.data_cfg:Dict[str:dict]=AttributesParser.load_config(self.data_cfg_path) self.cm_config:Dict[str,dict] = AttributesParser.load_config(self.combined_model_config_path) self.clewsb_config:Dict[str,dict] = AttributesParser.load_config(self.clews_builder_config_path) self.clews_cm:Dict= self.cm_config.get('clews','clews') self.log = log.getLogger(__name__)
[docs] @staticmethod def load_config(config_file_path): """ Loads the yaml file as dictionary and extracts the attributes to pass on child classes. """ with open(config_file_path, 'r') as file: data = yaml.safe_load(file) return data
@property def linking_tool_results_path(self): return Path('results/RESource') @property def pypsa_results_path(self): return Path('results/pypsa') @property def bcnexus_scenarios(self, clews_cm:dict=None)->dict: return clews_cm['SCENARIOS'] if clews_cm else self.clews_cm['SCENARIOS']
[docs] def get_data_paths(self): # StorageMaxCapacity = self.clewsb_config['STORAGE']['BATTERY']['storage_max_capacity'] # ResidualStorageCapacity = self.clewsb_config['STORAGE']['BATTERY']['residual_storage_capacity'] # Existing Resources' Data # ext_wind_CF = self.data_cfg['pypsa']['output']['create_ext_wind_ts']['fname'] # Path('data/processed_data/wind/existing/bc_ext_wind_ts.csv') # ext_solar_CF = self.data_cfg['pypsa']['output']['create_ext_solar_ts']['fname'] # Path('data/processed_data/solar/existing/bc_ext_solar_ts.csv') # demand_profile = Path('data/downloaded_data/CODERS/data-pull/demand/BC_provincial_demand_profile.csv') # hydro_res_CF = self.data_cfg['pypsa']['output']['reservoir_inflows']['fname'] # hydro_ror_ts=self.data_cfg['pypsa']['output']['ror_ps']['fname'] # Future Resource Options (Committed/Planned) resource_options_wind=self.linking_tool_results_path / 'resource_options_wind.csv' resource_options_wind_ts=self.linking_tool_results_path / 'resource_options_wind_timeseries.csv' resource_options_solar=self.linking_tool_results_path / 'resource_options_solar.csv' resource_options_solar_ts=self.linking_tool_results_path /'resource_options_solar_timeseries.csv' # Committed Resource Options, contracted but not existing (i.e. we don't have existing profiles for them) committed_wind=self.linking_tool_results_path /'BCH_CFP24_wind.csv' committed_solar=self.linking_tool_results_path /'BCH_CFP24_solar.csv' committed_wind_ts=self.linking_tool_results_path /'BCH_CFP24_wind_ts.csv' committed_solar_ts=self.linking_tool_results_path /'BCH_CFP24_solar_ts.csv' # Profiles (Capacity Factort, Specific Demand) from Existing Resources, formatted in CLEWs schema # clews_CF_csv_file = Path('data/clews_data/inputs_csv_8760/CapacityFactor.csv') # clews_CF_csv_file.parent.mkdir(parents=True, exist_ok=True) # clews_demand_profile = Path('data/clews_data/inputs_csv_8760/SpecifiedDemandProfile.csv') # clews_demand_profile.parent.mkdir(parents=True, exist_ok=True) return ( resource_options_wind, resource_options_solar, committed_wind, committed_solar, resource_options_wind_ts, resource_options_solar_ts, committed_wind_ts, committed_solar_ts, )
[docs] def get_case_input_csvs_path( self, storage_algorithm: str ): case_input_csvs_path= Path(f'data/clews_data/Model_{storage_algorithm}/inputs_csv') case_input_csvs_path.mkdir(parents=True,exist_ok=True) return case_input_csvs_path
[docs] def get_bcnexus_scenario_results_path(self, scenario:str, storage_algorithm:str,): scenario_results_root:Path=Path(f'results/clews/Model_{storage_algorithm}_{scenario}') return scenario_results_root