Result Management
Export to h5
Results obtained from the model (in case it is solved) are exported by default to an h5 file as specified in
Configuration.reporting.save_path. Additionally, a summary is written to an excel file specified in
Configuration.reporting.save_summary_path. In case this excel file exists already, the new summary is appended
as a new row. Documentation on the h5py library and how to handle h5 files can be found
here
- get_summary(model, solution, folder_path: Path, model_info: dict, data) dict
Retrieves all variable values relevant for the summary of an optimization run.
These variables and their values are written to a dictionary.
- Parameters:
model – the model for which you want to obtain the results summary.
solution – Pyomo solver results
folder_path (Path) – folder path of optimization run
model_info (dict) – information of the last solve done by the model
data – Input data of the model
- Returns:
a dictionary containing the most important model results (i.e., summary_dict)
- Return type:
dict
- write_optimization_results_to_h5(model, solution, model_info: dict, data) dict
Collects the results from the model blocks and writes them to an HDF5 file
Saving to HDF5 files is done using the h5py library. The summary results are returned in a dictionary format for exporting to Excel. Overhead (calculation of variables) are placed in the utilities file.
- Parameters:
model (ConcreteModel) – the model for which you want to save the results to an HDF5 file.
solution – Pyomo solver results
model_info (dict) – information of the last solve done by the model
data – DataHandle object containing all data read in by the DataHandle class.
- Returns:
a dictionary containing the most important model results (i.e., summary_dict)
- Return type:
dict
The structure (object tree) of the resulting HDF5 file is as follows:
Root group (top-level, being the .h5-file) [group] - contains:
Summary [group]: Contains one dataset [leaf] for each variable.
Design (for all time-independent results) [group]
Networks [group]
Specific network [group]: For each specific network that is present in your model, a separate group is created. e.g., “ElectricitySimple”.
Arc [group]: For each arc that contains that network, another group is created, e.g., “NodeANodeB”.
Datasets [leaves]: datasets, one for each variable.
Nodes [group]
Specific node [group]: For each specific node that is present in your model, a separate group is created, e.g., “Node A”.
Technology [group]: For each technology that is present at this node, a separate group is created, e.g., “SteamTurbine”.
Datasets [leaves]: datasets, one for each variable.
Operation (for all time-dependent results) [group]
Networks [group]
Specific network [group]: For each specific network that is present in your model, a separate group is created. e.g., “ElectricitySimple”.
Arc [group]: For each arc that contains that network, another group is created, e.g., “NodeANodeB”.
Datasets [leaves]: datasets, one for each variable.
Nodes [group]
Specific node [group]: For each specific node that is present in your model, a separate group is created, e.g., “Node A”.
“energy_balance” [group]: A group for the energy balances of all carriers present at that node.
Carrier [group]: For each carrier, a specific group is made, e.g., “Electricity”.
Datasets [leaves]: datasets of the relevant variables over time.
“technology_operation” [group]: a group for the technology operation of all energy technologies present at that node.
Technology [group]: For each technology, a specific group is made, e.g., “SteamTurbine”.
Datasets [leaves]: datasets of the relevant variables over time.
Note: for the time-independent results, one dataset contains only one value, while for the time-dependent results one dataset contains a value for each timestep in your model run.
Export to Excel
We do not provide a direct export to excel/csv files from the model interface, however, you can read results
from the h5 file previously exported. For this, several functions are provided in src
.result_management.read_results.
- add_values_to_summary(summary_path: Path, component_set: list = None)
Collect values of input cost parameters and relevant variables from HDF5 files and add them to the summary Excel file.
- Args:
summary_path (Path or str): Path to the summary Excel file. component_set (list, optional): List of components to extract parameters and variables from.
Defaults to [“Technologies”, “Networks”, “Import”, “Export”].
- extract_dataset_from_h5(dataset) list
Extracts values from a dataset within a h5 file
Gets all values of a dataset in a h5 file and writes it to a list.
- Parameters:
dataset – dataset within a h5 file
- Returns:
list of all values in a dataset
- Return type:
list
- extract_datasets_from_h5group(group, prefix: tuple = ()) dict
Extracts datasets from a group within a h5 file
Gets all datasets from a group of a h5 file and writes it to a multi-index dataframe using a recursive function
- Parameters:
group – froup of h5 file
prefix (tuple) – required to search through the structure of the h5 tree if there are multiple subgroups in the group you specified, empty by default meaning it starts searching from the group specified.
- Returns:
dataframe containing all datasets in group
- Return type:
pd.DataFrame
- print_h5_tree(file_path: pathlib.Path | str)
Function to print the structure of a h5 file
The structure of a h5 file is a tree structure: the h5 file is the root group, from which all groups stem, and datasets are the leaves contained within a group.
- Parameters:
file_path (Path, str) – Path to H5 File