edisgo.tools.config.Config

class edisgo.tools.config.Config(**kwargs)

Container for all configurations.

Parameters:
  • config_path (None or str or dict) –

    Path to the config directory. Options are:

    • ’default’ (default): The provided default config files are used directly.

    • str: 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. Keys are ‘config_db_tables’, ‘config_grid’, ‘config_grid_expansion’, and ‘config_timeseries’. Values are paths to the corresponding config file. The directories and config files must exist and are not automatically created.

    • None: Configs are loaded from the edisgo default config directory (~/.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()

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:

tuple

import_tables_from_oep(engine, table_names, schema_name)

Imports tables from the OEP database based on the provided table names and schema name.

Parameters:
  • engine (sqlalchemy.engine.Engine) – The SQLAlchemy engine to use for database connection.

  • table_names (list of str) – List of table names to import.

  • schema_name (str) – The schema name to use for importing tables.

Returns:

A list of SQLAlchemy Table objects corresponding to the imported tables.

Return type:

list of sqlalchemy.Table

from_cfg(config_path=None)

Load config files.

Parameters:

config_path (None or str or dict) – See class definition for more information.

Returns:

eDisGo configuration data from config files.

Return type:

collections.OrderedDict

to_json(directory, filename=None)

Saves config data to json file.

Parameters:
  • directory (str) – Directory, the json file is saved to.

  • filename (str or None) – Filename the json file is saved under. If None, it is saved under the filename “configs.json”. Default: None.

from_json(directory, filename=None, from_zip_archive=False)

Imports config data from json file as dictionary.

Parameters:
  • directory (str) – Directory, the json file is loaded from.

  • filename (str or None) – 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 if data is archived in a zip archive. Default: False.

Returns:

Dictionary with config data loaded from json file.

Return type:

dict