annular.tariffs =============== .. py:module:: annular.tariffs Attributes ---------- .. autoapisummary:: annular.tariffs.T Classes ------- .. autoapisummary:: annular.tariffs.TariffManager Functions --------- .. autoapisummary:: annular.tariffs.filter_dataframe annular.tariffs.parse_weekday_weekend annular.tariffs.is_dutch_holiday Module Contents --------------- .. py:data:: T .. py:class:: TariffManager(tariff_data: dict[str, pandas.Series]) 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. :param tariff_data: Dictionary where keys are tariff names and values are series of tariff values and indices. .. py:attribute:: data .. py:method:: from_folder(path: pathlib.Path, preselect: collections.abc.Mapping[str, str | numbers.Real]) -> T :classmethod: Create a TariffManager from csv files in a folder. :param path: Path to the folder with tariff data in csv format. :param 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. .. py:method:: fetch_value(name: str) -> numbers.Real Fetch a single-valued tariff. :param name: Name of the tariff. :returns: Value for a specific tariff. .. py:method:: fetch_timeseries(name: str, timestamps: pandas.DatetimeIndex) -> pandas.Series Fetch tariff value for each given timestamp. :param name: Name of the tariff. :param timestamps: Datetime to use for selecting temporal index levels. :returns: Series of values for the specified tariff, indexed by the given timestamps. .. py:method:: fetch_indexed(name: str, timestamps: pandas.DatetimeIndex) -> pandas.Series Fetch collection of tariff values, relevant to the given timestamps. :param name: Name of the tariff. :param 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 . .. py:function:: filter_dataframe(data: pandas.DataFrame, select: collections.abc.Mapping[str, str | int]) -> pandas.Series | numbers.Real Filter a dataframe by multiple columns. .. rubric:: Example Preselect ``{"A": "high", "B": "old"}`` with data = ==== === === ===== A B C 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: === ===== C value === ===== yes 3 no 4 === ===== :param data: pandas DataFrame to filter. Must have at least one column named 'value'. :param 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. .. py:function:: parse_weekday_weekend(date: datetime.date) -> str Parse the weekday weekend from a date. :param date: Date to parse. :returns: Whether the given date is a weekday or a weekend day. .. py:function:: is_dutch_holiday(date: datetime.date) -> bool 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) :param date: Date to check. :returns: True if the given date is a Dutch holiday, False otherwise.