annular.market.tulipa.utils

Attributes

logger

Functions

strip_timezone(→ pandas.Series | pandas.DatetimeIndex)

Convert an input to pd.Series or pd.Index and strip timezone.

create_tulipa_input_data(→ None)

Creates the Tulipa input from the given arguments.

write_inputs_to_db(→ None)

Write input data to DuckDB tables.

read_outputs_from_db(→ tuple[pandas.DataFrame, ...)

Read output data from DuckDB tables.

convert_data_for_tulipa(→ tuple[pandas.DataFrame, ...)

Convert data so that Tulipa can use them.

Module Contents

annular.market.tulipa.utils.logger[source]
annular.market.tulipa.utils.strip_timezone(timestamp: pandas.Series | pandas.DatetimeIndex | list) pandas.Series | pandas.DatetimeIndex[source]

Convert an input to pd.Series or pd.Index and strip timezone.

Parameters:

timestamp – The input to process.

annular.market.tulipa.utils.create_tulipa_input_data(generator_configs: dict[str, dict], timeseries_data: pandas.DataFrame, db_file: str | None = None, csv_folder: str | pathlib.Path | None = None) None[source]

Creates the Tulipa input from the given arguments.

Populates a duckdb database with the input files for Tulipa. This creates one producer asset per generator in generator_configs plus one consumer asset named bid_manager.

The profiles for the generators is stored in the timeseries_data.

Parameters:
  • generator_configs – dict of configurations defining of all generators.

  • timeseries_data – DataFrame containing all timeseries_data for generators.

  • db_file – A path to duckdb database. By default, an in-memory database is used and not persisted, in which case csv_folder should be specified.

  • csv_folder – If given, all tables are saved as csv files in this location.

Notes

The intended use of this function is to transform supply-side input data for an annular model to a Tulipa model. The bid_manager asset is created because we attach bids later to an (arbitrary) existing consumer asset, but the supply-side data do not have any demand assets.

annular.market.tulipa.utils.write_inputs_to_db(connection: duckdb.DuckDBPyConnection, bids: pandas.DataFrame, timeseries_data: pandas.DataFrame, window_df: pandas.DataFrame) None[source]

Write input data to DuckDB tables.

Parameters:
  • connection – Open DuckDB connection.

  • bids – DataFrame with bids.

  • timeseries_data – DataFrame with timestamp and timestep columns.

  • window_df – DataFrame with timestamp and timestep columns for the window.

annular.market.tulipa.utils.read_outputs_from_db(connection: duckdb.DuckDBPyConnection, snapshots: pandas.DatetimeIndex, bid_idx_cols: list[str], bids: pandas.DataFrame) tuple[pandas.DataFrame, pandas.DataFrame][source]

Read output data from DuckDB tables.

Parameters:
  • connection – Open DuckDB connection

  • snapshots – DatetimeIndex to filter market_price rows (the bidding window)

  • bid_idx_cols – Column names to use for setting the index

  • bids – Dataframe with with submitted bids.

Returns:

Tuple of (market_price, scheduled_bids) DataFrames. scheduled_bids timestamps are localized back to UTC.

annular.market.tulipa.utils.convert_data_for_tulipa(bids: pandas.DataFrame, timeseries_data: pandas.DataFrame, snapshots: pandas.DatetimeIndex, bidding_window: pandas.DatetimeIndex) tuple[pandas.DataFrame, pandas.DataFrame, pandas.DatetimeIndex, pandas.DataFrame][source]

Convert data so that Tulipa can use them.

In particular - Strip timezone from inputs to prepare for database storage - Reset all indexes - Create 1-based time index that is used in Tulipa - Denote sense column with strings “demand” and “supply” instead of numerics

To avoid mutation, input dataframes are copied.

Parameters:
  • bids – MultiIndex DataFrame with a ‘timestamp’ level.

  • timeseries_data – DataFrame with DatetimeIndex.

  • snapshots – Optimization window as a DatetimeIndex of timesteps.

  • bidding_window – timestamps for bidding window.

Returns:

Tuple of (bids, timeseries_data, snapshots, and window_df). window_df is a correspondence between pd.Datetime timestamps in Annular and integer timesteps in Tulipa, subset to the optimization window.