edisgo.tools.config¶
This file is part of eDisGo, a python package for distribution network analysis and optimization.
It is developed in the project open_eGo: https://openegoproject.wordpress.com
eDisGo lives on github: https://github.com/openego/edisgo/ The documentation is available on RTD: https://edisgo.readthedocs.io/en/dev/
Based on code by oemof developing group
This module provides a highlevel layer for reading and writing config files.
Classes¶
Container for all configurations. |
Functions¶
|
Loads the specified config file. |
|
Returns the value of a given key of a given section of the main |
Returns the basic edisgo config path. If it does not yet exist it creates |
|
|
Makes directory if it does not exist. |
Module Contents¶
- class edisgo.tools.config.Config(**kwargs)[source]¶
Container for all configurations.
- Parameters:
config_path (None or str or :dict) –
Path to the config directory. Options are:
- ’default’ (default)
If config_path is set to ‘default’, the provided default config files are used directly.
- str
If config_path is a string, configs will be loaded from the directory specified by config_path. If the directory does not exist, it is created. If config files don’t exist, the default config files are copied into the directory.
- dict
A dictionary can be used to specify different paths to the different config files. The dictionary must have the following keys:
’config_db_tables’
’config_grid’
’config_grid_expansion’
’config_timeseries’
Values of the dictionary are paths to the corresponding config file. In contrast to the other options, the directories and config files must exist and are not automatically created.
- None
If config_path is None, configs are loaded from the edisgo default config directory ($HOME$/.edisgo). If the directory does not exist, it is created. If config files don’t exist, the default config files are copied into the directory.
Default: “default”.
from_json (bool) – Set to True to load config data from json file. In that case the json file is assumed to be located in path specified through config_path. Per default this is set to False in which case config data is loaded from cfg files. Default: False.
json_filename (str) – Filename of the json file. If None, it is loaded from file with name “configs.json”. Default: None.
from_zip_archive (bool) – Set to True to load json config file from zip archive. Default: False.
Notes
The Config object can be used like a dictionary. See example on how to use it.
Examples
Create Config object from default config files
>>> from edisgo.tools.config import Config >>> config = Config()
Get reactive power factor for generators in the MV network
>>> config['reactive_power_factor']['mv_generator']
- property db_table_mapping¶
- property db_schema_mapping¶
- get_database_alias_dictionaries() tuple[dict[str, str], dict[str, str]] [source]¶
Retrieves the database alias dictionaries for table and schema mappings.
- Returns:
A tuple containing two dictionaries: - name_mapping: A dictionary mapping source table names to target table
names.
- schema_mapping: A dictionary mapping source schema names to target schema
names.
- Return type:
- import_tables_from_oep(engine: sqlalchemy.engine.Engine, table_names: list[str], schema_name: str) list[sqlalchemy.Table] [source]¶
Imports tables from the OEP database based on the provided table names and schema name.
- Parameters:
- Returns:
A list of SQLAlchemy Table objects corresponding to the imported tables.
- Return type:
list of sqlalchemy.Table
- from_cfg(config_path=None)[source]¶
Load config files.
- edisgo.tools.config.load_config(filename, config_dir=None, copy_default_config=True)[source]¶
Loads the specified config file.
- Parameters:
filename (str) – Config file name, e.g. ‘config_grid.cfg’.
config_dir (str, optional) – Path to config file. If None uses default edisgo config directory specified in config file ‘config_system.cfg’ in section ‘user_dirs’ by subsections ‘root_dir’ and ‘config_dir’. Default: None.
copy_default_config (bool) – If True copies a default config file into config_dir if the specified config file does not exist. Default: True.
- edisgo.tools.config.get(section, key)[source]¶
Returns the value of a given key of a given section of the main config file.
- edisgo.tools.config.get_default_config_path()[source]¶
Returns the basic edisgo config path. If it does not yet exist it creates it and copies all default config files into it.
- Returns:
Path to default edisgo config directory specified in config file ‘config_system.cfg’ in section ‘user_dirs’ by subsections ‘root_dir’ and ‘config_dir’.
- Return type: