annular.tariffs

Attributes

T

TEMPORAL_INDEXERS

Classes

TariffManager

A manager object for energy network tariffs.

Functions

parse_weekday_weekend(→ str)

Parse the weekday weekend from a date.

filter_dataframe(→ pandas.Series | numbers.Real)

Filter a dataframe by multiple columns.

is_dutch_holiday(→ bool)

Check if date is a Dutch holiday, if not already a weekend by definition.

Module Contents

annular.tariffs.T[source]
annular.tariffs.parse_weekday_weekend(date: datetime.date) str[source]

Parse the weekday weekend from a date.

Parameters:

date – Date to parse.

Returns:

Whether the given date is a weekday or a weekend day.

annular.tariffs.TEMPORAL_INDEXERS: dict[str, Callable][source]
class annular.tariffs.TariffManager(tariff_data: dict[str, pandas.Series | numbers.Real] | None = None)[source]

A manager object for energy network tariffs.

Includes support for intelligently parsing timestamps to various time-based indexing options. Tariffs are retrievable by (case-insensitive) name through various fetch_* methods.

Time related index names can be provided case-insensitive, since any case-sensitivity will be removed from index names using the casefold string method.

Parameters:

tariff_data – Dictionary where keys are tariff names and values are series of tariff values and indices.

data[source]
classmethod from_folder(path: pathlib.Path, preselect: collections.abc.Mapping[str, str | numbers.Real]) T[source]

Create a TariffManager from csv files in a folder.

Parameters:
  • path – Path to the folder with tariff data in csv format.

  • preselect – Dictionary specifying the category within the tariff. Any tariff may be indexed both categorically and temporally. This preselect argument should at least specify a value for each categorical index, i.e., column in the tariff file. E.g.: {“grid level”: “distribution”, “consumer type”: “small”}. If any of the categories given to preselect are not present in the tariff data, they are silently ignored.

__contains__(item: str) bool[source]

Check if a tariff is present in the TariffManager.

fetch_value(name: str) numbers.Real[source]

Fetch a single-valued tariff.

Parameters:

name – Name of the tariff.

Returns:

Value for a specific tariff.

fetch_timeseries(name: str, timestamps: pandas.Index) pandas.Series[source]

Fetch tariff value for each given timestamp.

Parameters:
  • name – Name of the tariff.

  • timestamps – Datetime to use for selecting temporal index levels.

Returns:

Series of values for the specified tariff, indexed by the given timestamps.

fetch_indexed(name: str, timestamps: Iterable[pandas.Timestamp]) pandas.Series[source]

Fetch collection of tariff values, relevant to the given timestamps.

Parameters:
  • name – Name of the tariff.

  • timestamps – Datetime to use for selecting temporal index levels.

Returns:

Series of tariff values, maintaining its original index, pre-selected with only the relevant values .

annular.tariffs.filter_dataframe(data: pandas.DataFrame, select: collections.abc.Mapping[str, str | numbers.Real]) pandas.Series | numbers.Real[source]

Filter a dataframe by multiple columns.

Example

Preselect {"Foo": "high", "Bar": "old"} with data =

Foo

Bar

Baz

value

high

new

yes

1

high

new

no

2

high

old

yes

3

high

old

no

4

low

new

yes

5

low

new

no

6

low

old

yes

7

low

old

no

8

Result:

Baz

value

yes

3

no

4

Note: Column names can be given case-insensitively, but the values to match on are still case-sensitive. So the previous example would work the same if select={"foo": "high", "BAR": "old"} was used, but not select={"Foo": "High", "Bar": "OLD"}.

Parameters:
  • data – pandas DataFrame to filter. Must have at least one column named ‘value’.

  • select – Dictionary where keys are strings or integers, used to select only the desired rows from the given data. If a key is present as a column name, then only those rows are kept where that column matches the matching value from this dictionary.

Returns:

A pd.Series of the value column, where rows are filtered based on matching values in select. Any columns that were filtered on are removed, and any remaining columns are used as a pd.MultiIndex. If the series only consists of a single row, then it only returns the value.

annular.tariffs.is_dutch_holiday(date: datetime.date) bool[source]

Check if date is a Dutch holiday, if not already a weekend by definition.

As of 2013, Dutch holidays are: - New Year’s Day - Good Friday - Easter (Sunday and Monday) - King’s Day - Ascension Day - Pentecost (sunday and Monday) - Christmas (25th and 26th)

Parameters:

date – Date to check.

Returns:

True if the given date is a Dutch holiday, False otherwise.