Data & I/O#
Data formats#
The model is data-driven, with all inputs defined in a collection of CSV files located in a dedicated case directory. These files define the model’s sets (e.g., periods, technologies, nodes) and parameters (e.g., costs, capacities, efficiencies).
CSV File Naming Conventions#
The input CSV files follow a specific naming convention to distinguish between different types of data:
``oM_Dict…``: Files starting with this prefix are used to define the model’s sets and dictionaries. These typically contain lists of technologies, nodes, or other categorical data.
``oM_Data…``: Files starting with this prefix contain the numerical data for the model’s parameters, such as costs, efficiencies, or time series data.
This convention helps in organizing the input data and is used by the data loading functions to correctly process the files.
CSV File Descriptions#
The following sections provide a more detailed description of the oM_Dict...
and oM_Data... CSV files.
oM_Dict Files#
These files define the sets and dictionaries used in the optimization model. Each file corresponds to a specific set, and the rows of the CSV file define the elements of that set.
File |
Description |
|---|---|
|
Defines the nodes in the network. Each row represents a node. The
relevant column is |
|
Defines the technologies available in the model. Each row represents a
technology. The relevant column is |
|
Defines the geographical areas. The relevant column is |
|
Defines the geographical regions. The relevant column is |
|
Defines the geographical zones. The relevant column is |
|
Defines the time periods. The relevant column is |
|
Defines the scenarios. The relevant column is |
|
Defines the load levels. The relevant column is |
|
Defines the storage technologies. The relevant column is |
|
Defines the electrical circuits. The relevant column is |
|
Defines the electricity demand categories. The relevant column is
|
|
Defines the electricity generation categories. The relevant column is
|
|
Defines the electricity retail categories. The relevant column is
|
|
Defines the hydrogen demand categories. The relevant column is
|
|
Defines the hydrogen generation categories. The relevant column is
|
|
Defines the hydrogen retail categories. The relevant column is
|
|
Maps areas to regions. The relevant columns are |
|
Maps zones to areas. The relevant columns are |
|
Maps nodes to zones. The relevant columns are |
oM_Data Files#
These files contain the numerical data for the model’s parameters. This includes time series data, costs, efficiencies, and other parameters that define the behavior of the model.
File |
Description |
|---|---|
|
Specifies the duration of each time step. |
|
Time series data for electricity demand. Columns: |
|
Parameters for electricity generation technologies (e.g., capacity). Columns: |
|
Data for the electricity network, like line capacities. |
|
Data related to electricity retail. |
|
Time series data for hydrogen demand. |
|
Parameters for hydrogen generation technologies. |
|
Data for the hydrogen network. |
|
Data related to hydrogen retail. |
|
Defines the geographical location (e.g., latitude, longitude) of nodes. |
|
Cost or activation data for operating reserves. |
|
Prices for operating reserves. |
|
Requirements for operating reserves. |
|
Contains various modeling options and flags. |
|
Defines global parameters like costs, discount rates, and time steps. |
|
Defines the characteristics of each period, like duration. |
|
Provides scenario-specific data, such as probabilities. |
|
Contains electricity tariff data. |
|
Variable costs associated with energy. |
|
Variable prices for energy. |
|
Upper bounds for consumption variables. |
|
Upper bounds for demand variables. |
|
Upper bounds for emission cost variables. |
|
Upper bounds for energy variables. |
|
Upper bounds for fuel cost variables. |
|
Upper bounds for generation variables. |
|
Upper bounds for inflow variables. |
|
Upper bounds for outflow variables. |
|
Upper bounds for storage variables (e.g., max capacity). Columns: |
|
Lower bounds for consumption variables. |
|
Lower bounds for demand variables. |
|
Lower bounds for emission cost variables. |
|
Lower bounds for energy variables. |
|
Lower bounds for fuel cost variables. |
|
Lower bounds for generation variables. |
|
Lower bounds for inflow variables. |
|
Lower bounds for outflow variables. |
|
Lower bounds for storage variables. |
|
Position data for consumption variables. |
|
Position data for generation variables. |
|
Position data for outflow variables. |
|
Costs or parameters for shutting down units. |
|
Costs or parameters for starting up units. |
Loaders#
- el1xr_opt.Modules.oM_LoadCase.load_case(directory=None, case=None, date=None, solver='highs', rawresults=False, plots=False, indlog=False)[source]
Create and validate a load case configuration.
- Parameters:
dir (str, optional) – Directory where the case is located. Defaults to “../site-packages/el1xr_opt”.
case (str, optional) – Name of the case to load. Defaults to “Grid1”.
date (datetime or str, optional) – Date information. If string, it should follow “%Y-%m-%d %H:%M”. Defaults to current datetime (rounded to minute).
solver (str, optional) – Solver to be used. Defaults to “highs”.
rawresults (bool, optional) – Whether to save raw results. Defaults to False.
plots (bool, optional) – Whether to generate plots. Defaults to False.
indlog (bool, optional) – Whether to enable individual logging. Defaults to False.
directory (str | None)
- Returns:
A dictionary containing the case configuration.
- Return type:
dict
Writers#
- el1xr_opt.Modules.oM_OutputData.save_to_csv(df, path, filename, index=False)[source]
Save a DataFrame to CSV file.
- Parameters:
df (pd.DataFrame) – DataFrame to save
path (str) – Directory path
filename (str) – Filename including extension
index (bool) – Whether to include index in CSV
- el1xr_opt.Modules.oM_OutputData.create_line_chart(df, x_col, y_col, color_col=None, title='', x_title='', y_title='', width=800, height=400, date_format='%a, %b %d, %H:%M', strokeDash=None)[source]
Create a reusable Altair line chart.
- Parameters:
df (pd.DataFrame) – Data to plot
x_col (str) – Column name for x-axis
y_col (str) – Column name for y-axis
color_col (str, optional) – Column name for color encoding
title (str) – Chart title
x_title (str) – X-axis title
y_title (str) – Y-axis title
width (int) – Chart width
height (int) – Chart height
date_format (str) – Format string for date axis
strokeDash (list, optional) – Dash pattern for line [5, 5]
- Returns:
Altair chart object
- Return type:
alt.Chart
- el1xr_opt.Modules.oM_OutputData.create_bar_chart(df, x_col, y_col, color_col, title='', x_title='', y_title='', width=800, height=400, date_format='%a, %b %d, %H:%M')[source]
Create a reusable Altair bar chart.
- Parameters:
df (pd.DataFrame) – Data to plot
x_col (str) – Column name for x-axis
y_col (str) – Column name for y-axis (use ‘sum(…)’ for aggregation)
color_col (str) – Column name for color encoding
title (str) – Chart title
x_title (str) – X-axis title
y_title (str) – Y-axis title
width (int) – Chart width
height (int) – Chart height
date_format (str) – Format string for date axis
- Returns:
Altair chart object
- Return type:
alt.Chart
- el1xr_opt.Modules.oM_OutputData.create_duration_curve(df, value_col, date_col, title, y_label, path, filename)[source]
Create and save a duration curve plot.
- Parameters:
df (pd.DataFrame) – Input dataframe
value_col (str) – Column name containing values to plot
date_col (str) – Column name containing dates
title (str) – Chart title
y_label (str) – Y-axis label
path (str) – Directory path to save chart
filename (str) – Output filename
- Returns:
DataFrame sorted by value (descending) with counter column
- Return type:
pd.DataFrame
- el1xr_opt.Modules.oM_OutputData.save_chart(chart, path, filename, embed_options=None)[source]
Save an Altair chart to HTML file.
- Parameters:
chart – Altair chart object
path (str) – Directory path
filename (str) – Filename including extension
embed_options (dict, optional) – Options for embedding the chart. Defaults to {‘renderer’: ‘svg’}.
- el1xr_opt.Modules.oM_OutputData.create_and_save_duration_curve(series_data, index_tuples, value_col_name, Date, hour_of_year, path, csv_filename, html_filename, title, y_label)[source]
Create and save a duration curve with both CSV and HTML outputs.
- Parameters:
series_data (list) – List of values
index_tuples – Index tuples (e.g., from model.psn)
value_col_name (str) – Name for the value column
Date – Starting date
hour_of_year (str) – Hour of year reference
path (str) – Output directory
csv_filename (str) – CSV filename
html_filename (str) – HTML filename
title (str) – Chart title
y_label (str) – Y-axis label
- Returns:
Processed dataframe with counter
- Return type:
pd.DataFrame
- el1xr_opt.Modules.oM_OutputData.saving_rawdata(DirName, CaseName, SolverName, model, optmodel, indlog)[source]
Save raw optimization model data to CSV files.
This function iterates through all active variables, parameters, and constraints in the optimization model and saves their data to separate CSV files.
Variables are saved with their values, lower bounds, and upper bounds.
Parameters are saved with their values.
Constraints are saved with their dual values.
- Parameters:
DirName (str) – The directory where the result files will be saved.
CaseName (str) – The name of the case, used for subdirectory and file naming.
SolverName (str) – The name of the solver used.
model – The optimization model object.
optmodel – The concrete optimization model instance.
indlog – Logging indicator.
- Returns:
The original optimization model object.
- Return type:
model
- el1xr_opt.Modules.oM_OutputData.saving_results(DirName, CaseName, Date, model, optmodel, indlog)[source]
Save processed optimization results to CSV files and generate plots.
This function processes the results from the optimization model to generate a series of CSV files and Altair plots for analysis. It covers:
Total costs (hourly and general)
Electricity balance (generation, consumption, flows)
Net and original electricity demand
State of energy for storage systems
Fixed availability of assets
A summary of all key output metrics
It also generates Sankey diagrams and duration curves for various metrics.
- Parameters:
DirName (str) – The directory where the result files will be saved.
CaseName (str) – The name of the case, used for subdirectory and file naming.
Date (str or datetime) – The starting date for the results, used to calculate time-series data.
model – The optimization model object.
optmodel – The concrete optimization model instance.
- Returns:
The original optimization model object.
- Return type:
model