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.

Module Contents

Classes

Config

Container for all configurations.

Functions

load_config(filename[, config_dir, copy_default_config])

Loads the specified config file.

get(section, key)

Returns the value of a given key of a given section of the main

get_default_config_path()

Returns the basic edisgo config path. If it does not yet exist it creates

make_directory(directory)

Makes directory if it does not exist.

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_gen']
from_cfg(config_path=None)[source]

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)[source]

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)[source]

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

__getitem__(key1, key2=None)[source]
__setitem__(key, value)[source]
__delitem__(key)[source]
__iter__()[source]
__len__()[source]
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.

Parameters
  • section (str) –

  • key (str) –

Returns

The value which will be casted to float, int or boolean. If no cast is successful, the raw string is returned.

Return type

float or int or bool or str

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

str

edisgo.tools.config.make_directory(directory)[source]

Makes directory if it does not exist.

Parameters

directory (str) – Directory path