oemof.tools package

Submodules

oemof.tools.config module

Created on Fri Sep 5 12:26:40 2014

module-author:steffen
filename:config.py

This module provides a highlevel layer for reading and writing config files. There must be a file called “config.ini” in the root-folder of the project. The file has to be of the following structure to be imported correctly.

# this is a comment

# the filestructure is like:

[netCDF]

RootFolder = c://netCDF

FilePrefix = cd2-

[mySQL]

host = localhost

user = guest

password = root

database = znes

[SectionName]

OptionName = value

Option2 = value2

oemof.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.) – the section.
  • key (str.) – the key.
Returns:

the value which will be casted to float, int or boolean. if no cast is successfull, the raw string will be returned.

oemof.tools.config.init()[source]
oemof.tools.config.main()[source]
oemof.tools.config.set(section, key, value)[source]

sets a value to a [section] key - pair. if the section doesn’t exist yet, it will be created.

Parameters:
  • section (str.) – the section.
  • key (str.) – the key.
  • value (float, int, str.) – the value.

oemof.tools.create_components module

oemof.tools.create_components.instant_flow_heater(bus_low, bus_high)[source]

oemof.tools.entities_from_csv module

@author: Simon Hilpert simon.hilpert@fh-flensburg.de

oemof.tools.entities_from_csv.add_bus(row, **kwargs)[source]

Adds bus object ot list of busses. The function is used by apply() method of pandas data frames.

Parameters:
  • row (row of pandas.DataFrame()) –
  • busses (list) – list of existing busses
  • busprices (pandas.DataFrame()) – data frame containting the values for the busprices. Column index is the uid of bus to create.
oemof.tools.entities_from_csv.add_chp(row, **kwargs)[source]

Adds chps objects ot list of transformers. The function is used by apply() method of pandas data frames.

Parameters:
  • row (row of pandas.DataFrame()) –
  • busses (list) – list of existing busses
  • transformers (list) – list of transformers where object are appended
oemof.tools.entities_from_csv.add_sink(row, **kwargs)[source]

Adds sink object ot list of transformers. The function is used by apply() method of pandas data frames.

Parameters:
  • row (row of pandas.DataFrame()) –
  • busses (list) – list of existing busses
  • sink (list) – list of sinks where object are appended
  • sinkvalues (pandas.DataFrame()) – data frame containting the values for the sink column index is uid of sink
oemof.tools.entities_from_csv.add_source(row, **kwargs)[source]

Adds source object ot list of source. The function is used by apply() method of pandas data frames.

Parameters:
  • row (row of pandas.DataFrame()) –
  • busses (list) – list of existing busses
  • sink (list) – list of sources where object are appended
  • sourcevalues (pandas.DataFrame()) – data frame containting the values for the source column index is uid of source to create.
oemof.tools.entities_from_csv.add_storage(row, **kwargs)[source]

Adds storage objects ot list of storages. The function is used by apply() method of pandas data frames.

Parameters:
  • row (row of pandas.DataFrame()) –
  • busses (list) – list of existing busses
  • transformers (list) – list of transformers where object are appended
oemof.tools.entities_from_csv.add_transformer(row, **kwargs)[source]

Adds transformer objects ot list of transformers. The function is used by apply() method of pandas data frames.

Parameters:
  • row (row of pandas.DataFrame()) –
  • busses (list) – list of existing busses
  • transformers (list) – list of transformers where object are appended
oemof.tools.entities_from_csv.add_transport(row, **kwargs)[source]

Adds transpport objects ot list of transports. The function is used by apply() method of pandas data frames.

oemof.tools.entities_from_csv.entities_from_csv(files, entities_dict=None)[source]

Creates ‘oemof-objects’ from csv files by the use of pandas dataframes

Parameters:
  • files (dict) – dictionary containing the paths to files for object creation. Keys are: ‘transformers’,’busses’,’storages’,’chps’, ‘sources’, ‘sourcevalues’, ‘sinks’, ‘sinkvalues’, ‘busprices’
  • entities_dict (dict) – dictionary containing lists of oemof base class objects

oemof.tools.helpers module

Created on Mon Aug 17 11:08:15 2015

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

All special import should be in try/except loops to avoid import errors.

oemof.tools.helpers.abbreviation_of_state(statename)[source]

Get the abbreviation of a german state name or the other way round.

Parameters:statename (string) – Fullname of the state or its abbreviation
Returns:Fullname of the state or its abbreviation, depending on the input.
Return type:string
oemof.tools.helpers.create_basic_dataframe(year, **kwargs)[source]

Giving back a DataFrame containing weekdays and optionally holidays for the given year.

Parameters:
  • year (the year for which dataframe should be created) –
  • Parameters (Optional) –
  • -------------------
  • holidays (array with information for every hour of the year, if holiday or) – not (0: holiday, 1: no holiday)
Returns:

pandas.DataFrame

Return type:

DataFrame with a time index

Notes

Using Pandas > 0.16

oemof.tools.helpers.cut_lists(list_a, list_b)[source]

Returns a list with the values of list_a AND list_b.

oemof.tools.helpers.dict2pickle(dic, filename=None, path=None)[source]

Dumping a python dictionary into a pickle file.

oemof.tools.helpers.dict2textfile(dic, filename=None, path=None)[source]

Writing a dictionary to textfile in a readable and clearly formatted way.

oemof.tools.helpers.download_file(filename, url)[source]

Copy a file from the given url to the given filename.

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

Reverse geocoding using google.

Parameters:coord (array_like) – Geo-coordinates in the order (longitude, latitude)
Returns:Containing the name of the country and the name of the state if available
Return type:list of strings

Examples

>>> fetch_admin_from_coord_google((12.7, 51.8))  
['DE', 'SA']
oemof.tools.helpers.fetch_admin_from_coord_osm(coord)[source]

Reverse geocoding using osm.

Parameters:coord (array_like) – Geo-coordinates in the order (longitude, latitude)
Returns:Containing the name of the country and the name of the state if available
Return type:list of strings

Examples

>>> fetch_admin_from_coord_osm((12.7, 51.8))  
['Deutschland', 'ST']
oemof.tools.helpers.get_basic_path()[source]
oemof.tools.helpers.get_fullpath(path, filename)[source]
oemof.tools.helpers.get_german_holidays(year, place=[None, None, None], scope='legal')[source]

Returns German holiday dates. Use the abbreviations for the german federal states like ‘BY’ for Bayern.

Parameters:
  • year (int) – Year of which the holidays are wanted
  • place (list of strings) – List of names: [country, state, city]
  • scope (string) – Type of holidays. So far only legal is possible.
Returns:

The keys are in the datetime format the values represent the names.

Return type:

dictionary

Notes

So far only the data of german holidays is available. Feel free to add other countries or to implement workalendar. https://github.com/novapost/workalendar

Examples

get_holidays(2015, place=[‘Germany’, ‘BE’, ‘Berlin’])

oemof.tools.helpers.get_polygon_from_shp_file(file)[source]

A one-line summary that does not use variable names or the function name.

Several sentences providing an extended description. Refer to variables using back-ticks, e.g. var.

Parameters:
  • var1 (array_like) – Array_like means all those objects – lists, nested lists, etc. – that can be converted to an array. We can also refer to variables like var1.
  • var2 (int) – The type above can either refer to an actual Python type (e.g. int), or describe the type of the variable in more detail, e.g. (N,) ndarray or array_like.
  • Long_variable_name ({'hi', 'ho'}, optional) – Choices in brackets, default first when optional.
Returns:

  • type – Explanation of anonymous return value of type type.
  • describe (type) – Explanation of return value named describe.
  • out (type) – Explanation of out.

Other Parameters:
 
  • only_seldom_used_keywords (type) – Explanation
  • common_parameters_listed_above (type) – Explanation
Raises:

BadException – Because you shouldn’t have done that.

See also

otherfunc()
relationship (optional)
newfunc()
Relationship (optional), which could be fairly long, in which case the line wraps here.

thirdfunc(), fourthfunc(), fifthfunc()

Notes

Notes about the implementation algorithm (if needed).

This can have multiple paragraphs.

You may include some math:

X(e^{j\omega } ) = x(n)e^{ - j\omega n}

And even use a greek symbol like omega inline.

References

Cite the relevant literature, e.g. [1]. You may also cite these references in the notes section above.

[1]O. McNoleg, “The integration of GIS, remote sensing, expert systems and adaptive co-kriging for environmental habitat modelling of the Highland Haggis using object-oriented, fuzzy-logic and neural-network techniques,” Computers & Geosciences, vol. 22, pp. 585-588, 1996.

Examples

These are written in doctest format, and should illustrate how to use the function.

>>> a=[1,2,3]
>>> print([x + 3 for x in a])
[4, 5, 6]
>>> print("a\nb")
a
b
oemof.tools.helpers.mkdir_if_not_exist(path)[source]

Creates directory if not exist

oemof.tools.helpers.pickle2dict(filename=None, path=None)[source]

Reading a python dictionary from a pickle file.

oemof.tools.helpers.remove_from_list(orig_list, remove_list)[source]

Removes the values inside the remove_list from the orig_list.

oemof.tools.helpers.time_logging(start, text, logging_level='debug')[source]

Logs the time between the given start time and the actual time. A text and the debug level is variable.

Uwe Krien (uwe.krien@rl-institut.de)

Parameters
start : start time : float text : text to describe the log : string
Keyword arguments
logging_level : logging_level [default=’debug’] : string
oemof.tools.helpers.unique_list(seq)[source]

Returns a unique list without preserving the order

oemof.tools.helpers.unlist(val)[source]

Returns single value if a single value in a list is given

oemof.tools.holiday module

Holiday information for Germany.

oemof.tools.holiday.fetch_admin_from_latlon(lat=None, lon=None, coord=None)[source]

Receive reverse geocoded information from lat/lon point :rtype : dict :param lat: latitude :param lon: longitude :param zoom: detail level of information :return: list: [country, state]

oemof.tools.holiday.get_abbreviation_of_state(statename)[source]
oemof.tools.holiday.get_german_holidays(year, place=[None, None, None], scope='legal', _=<class 'str'>)[source]

Returns German holiday dates. Use the s for the german federal states like ‘Germany/BY ‘ for Bayern. : Example: get_holidays(2015, place=[‘Germany’, ‘BE’, ‘Berlin’])

oemof.tools.logger module

Author: Uwe Krien (uwe.krien@rl-institut.de) Changes by: Responsibility: Uwe Krien (uwe.krien@rl-institut.de)

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

Passes the used brance and commit to the logger

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

Returns the actual version number of the used oemof version.

oemof.tools.logger.define_logging(inifile='logging.ini', basicpath=None, subdir='log_files')[source]

Initialise the logger using the logging.conf file in the local path.

Several sentences providing an extended description. Refer to variables using back-ticks, e.g. var.

Parameters:
  • inifile (string, optional (default: logging.ini)) – Name of the configuration file to define the logger. If no ini-file exist a default ini-file will be downloaded from ‘http://vernetzen.uni-flensburg.de/~git/logging_default.ini‘ and used.
  • basicpath (string, optional (default: '.oemof' in HOME)) – The basicpath for different oemof related informations. By default a ”.oemof’ folder is created in your home directory.
  • subdir (string, optional (default: 'log_files')) – The name of the subfolder of the basicpath where the log-files are 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 ini-file. 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 logge 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
>>> logger.define_logging() 
17:56:51-INFO-Path for logging: /HOME/.oemof/log_files
...
>>> logging.debug("Hallo")

Module contents