oemof.tools package

Submodules

oemof.tools.console_scripts module

This module can be used to check the installation. This is not an illustrated example.

This file is part of project oemof (github.com/oemof/oemof). It’s copyrighted by the contributors recorded in the version control history of the file, available from its original location oemof/tests/test_installation.py

SPDX-License-Identifier: GPL-3.0-or-later

oemof.tools.console_scripts.check_oemof_installation(silent=False)[source]

oemof.tools.datapackage module

oemof.tools.economics module

Module to collect useful functions for economic calculation.

This file is part of project oemof (github.com/oemof/oemof). It’s copyrighted by the contributors recorded in the version control history of the file, available from its original location oemof/oemof/tools/economics.py

SPDX-License-Identifier: GPL-3.0-or-later

oemof.tools.economics.annuity(capex, n, wacc)[source]

Calculate the annuity.

annuity = capex * (wacc * (1 + wacc) ** n) / ((1 + wacc) ** n - 1)

Parameters:
  • capex (float) – Capital expenditure (NPV of investment)
  • n (int) – Number of years that the investment is used (economic lifetime)
  • wacc (float) – Weighted average cost of capital
Returns:

float

Return type:

annuity

oemof.tools.helpers module

This is a collection of helper functions which work on their own and can be used by various classes. If there are too many helper-functions, they will be sorted in different modules.

This file is part of project oemof (github.com/oemof/oemof). It’s copyrighted by the contributors recorded in the version control history of the file, available from its original location oemof/oemof/tools/helpers.py

SPDX-License-Identifier: GPL-3.0-or-later

oemof.tools.helpers.extend_basic_path(subfolder)[source]

Returns a path based on the basic oemof path and creates it if necessary. The subfolder is the name of the path extension.

oemof.tools.helpers.flatten(d, parent_key='', sep='_')[source]

Flatten dictionary by compressing keys.

See: https://stackoverflow.com/questions/6027558/
flatten-nested-python-dictionaries-compressing-keys

d : dictionary sep : separator for flattening keys

Returns:
Return type:dict
oemof.tools.helpers.get_basic_path()[source]

Returns the basic oemof path and creates it if necessary. The basic path is the ‘.oemof’ folder in the $HOME directory.

oemof.tools.logger module

Helpers to log your modeling process with oemof.

This file is part of project oemof (github.com/oemof/oemof). It’s copyrighted by the contributors recorded in the version control history of the file, available from its original location oemof/oemof/tools/logger.py

SPDX-License-Identifier: GPL-3.0-or-later

oemof.tools.logger.check_git_branch()[source]

Passes the used branch and commit to the logger

>>> from oemof.tools import logger
>>> try:
...    v = logger.check_git_branch()
... except FileNotFoundError:
...    v = ('abcdefgh', 'branch')
>>> type(v)
<class 'tuple'>
>>> type(v[0])
<class 'str'>
>>> len(v[0])
8
oemof.tools.logger.check_version()[source]

Returns the actual version number of the used oemof version.

>>> from oemof.tools import logger
>>> v = logger.check_version()
>>> int(v.split('.')[0])
0
oemof.tools.logger.define_logging(logpath=None, logfile='oemof.log', file_format=None, screen_format=None, file_datefmt=None, screen_datefmt=None, screen_level=20, file_level=10, log_version=True, log_path=True, timed_rotating=None)[source]

Initialise customisable logger.

Parameters:
  • logfile (str) – Name of the log file, default: oemof.log
  • logpath (str) – The path for log files. By default a “.oemof’ folder is created in your home directory with subfolder called ‘log_files’.
  • file_format (str) – Format of the file output. Default: “%(asctime)s - %(levelname)s - %(module)s - %(message)s”
  • screen_format (str) – Format of the screen output. Default: “%(asctime)s-%(levelname)s-%(message)s”
  • file_datefmt (str) – Format of the datetime in the file output. Default: None
  • screen_datefmt (str) – Format of the datetime in the screen output. Default: “%H:%M:%S”
  • screen_level (int) – Level of logging to stdout. Default: 20 (logging.INFO)
  • file_level (int) – Level of logging to file. Default: 10 (logging.DEBUG)
  • log_version (boolean) – If True the actual version or commit is logged while initialising the logger.
  • log_path (boolean) – If True the used file path is logged while initialising the logger.
  • timed_rotating (dict) – Option to pass parameters to the TimedRotatingFileHandler.
Returns:

str

Return type:

Place where the log file is stored.

Notes

By default the INFO level is printed on the screen and the DEBUG level in a file, but you can easily configure the logger. Every module that wants to create logging messages has to import the logging module. The oemof logger module has to be imported once to initialise it.

Examples

To define the default logger you have to import the python logging library and this function. The first logging message should be the path where the log file is saved to.

>>> import logging
>>> from oemof.tools import logger
>>> mypath = logger.define_logging(
...     log_path=True, log_version=True, timed_rotating={'backupCount': 4},
...     screen_level=logging.ERROR, screen_datefmt = "no_date")
>>> mypath[-9:]
'oemof.log'
>>> logging.debug("Hallo")
oemof.tools.logger.get_version()[source]

Returns a string part of the used version. If the commit and the branch is available the commit and the branch will be returned otherwise the version number.

>>> from oemof.tools import logger
>>> v = logger.get_version()
>>> type(v)
<class 'str'>

Module contents