def get_all_config(custom_config: Dict[str, Any] = {}): all_config_dict = {} all_cfg_files = [ cstr_cfg, e_c_cfg, es_cfg, geom_cfg, graph_cfg, idf_cfg, mgr_cfg, op_cfg, ret_cfg, sia_cfg, site_cfg, sc_weather_cfg, eplus_cfg, op_fixed_cfg, ret_emb_cfg, ret_ep2050_cfg, ] for cfg_file in all_cfg_files: cfg_entries = config_loader.load_config_full(cfg_file, ignore_metadata=False) all_config_dict = config_loader.merge_config_recursive(all_config_dict, cfg_entries) all_config_file = "all_cesarp_config.yml" with open(all_config_file, "w") as f: yaml.dump(all_config_dict, f) print(f"saved combined configuration to {all_config_file}")
def test_convert_pathes(): config_path = _TEST_CFG_PATH config_dir = os.path.dirname(config_path) config = config_loader.load_config_full(config_path) config_loader.__convert_entries_to_abs_pathes(config, config_dir) assert (config["HELLO"] == __HELLO_expected_test_config ) # entries in HELLO should be unchanged, no pathes assert (config["ABS_PATHES_TEST"] == { "TESTFILE": str(config_dir / Path("../test/test.txt")), "TEST_PATH": str(config_dir / Path("./yapath/subdir")), "SOMETHING": str(config_dir / Path("testfile.idf")) })
def test_config_validation_duplicate_keys(): with pytest.raises(config_loader.DuplicateConfigKeyException): custom_cfg_dict = config_loader.load_config_full( _TEST_DUPLICATES_CONFIG_PATH)
def __init__(self, file_path, ureg: pint.UnitRegistry): self._ureg = ureg self._energy_target_cfg = config_loader.load_config_full(file_path) self.pen_unit = ureg.MJ * ureg.Oileq / ureg.m**2 / ureg.year self.co2_unit = ureg.kg * ureg.CO2eq / ureg.m**2 / ureg.year
def __init__( self, base_output_path: Union[str, Path], main_config: Union[str, Path, Dict[str, Any]], unit_reg: pint.UnitRegistry, load_from_disk: bool = False, fids_to_use: List[int] = None, delete_old_logs=True, ): """ :param base_output_path: full folder path where idf, eplus output and other cesar-p output and intermediate files are stored. :type base_output_path: Union[str, Path] :param main_config: either dict with configuration entries or path to custom config yml file. for details about how the configuration works see class description :type main_config: Union[str, Path, Dict[str, Any]] :param unit_reg: pint Unit Registry application wide instance () :type unit_reg: pint.UnitRegistry :param load_from_disk: True if you want to load existing simulation files into memory. cannot be combined with fids_to_use, defaults to False :type load_from_disk: bool :param fids_to_use: pass list of FID's for which called methods on the manager object should be performed, if not provided all fids defined in the input file are used :type fids_to_use: List[int] :param delete_old_logs: if true old \\*-cesarp-logs folder are deleted when a new worker pool is created :type delete_old_logs: bool """ self.logger = logging.getLogger(__name__) assert not (load_from_disk and (fids_to_use is not None) ), "if load_from_disk is True you cannot pass fids_to_use" self._unit_reg = unit_reg self.delete_old_logs = delete_old_logs if not isinstance(main_config, dict): self._custom_config = config_loader.load_config_full(main_config) else: self._custom_config = main_config self.__validate_custom_config(self._custom_config) self._mgr_config = config_loader.load_config_for_package( _default_config_file, __package__, self._custom_config) self._storage = FileStorageHandler(base_output_path, self._custom_config, reloading=load_from_disk) self.failed_fids: Set[int] = set() self._worker_pool = None if not fids_to_use: fids_to_use = self.get_fids_from_config() self._fids_to_use = fids_to_use self.bldg_containers = self._init_empty_bldg_containers(fids_to_use) self.output_folders: Dict[int, str] = {} self.idf_pathes: Dict[int, str] = {} self.weather_files: Dict[int, str] = {} if load_from_disk: self.bldg_containers = self._storage.load_existing_bldg_containers( ) self.idf_pathes = self._storage.load_existing_idfs() if self.idf_pathes: self.weather_files = self._storage.load_existing_weather_mapping( ) self.output_folders = self._storage.load_existing_result_folders() self._fids_to_use = list( set( list(self.bldg_containers.keys()) + list(self.idf_pathes.keys()) + list(self.output_folders.keys())))