outputter

A script for outputting the results of a PyEHub model.

Outputs can be stored to an excel spreadsheet or printed to the console.

outputter.output_excel(solution: dict, file_name: str, time_steps: int | None = None, sheets: list | None = None)[source]

Output the solution dictionary to an Excel file.

It outputs the time series data in their own sheet with the rest being put into another sheet.

Parameters:
  • solution – A dictionary of the solution part of the response format. This contains the variables and parameters of the solved model.

  • file_name – The name of the Excel file to write to

  • time_steps – Optional. The number of time steps to classify a dataframe as holding time series data.

  • sheets – A list of all the sheets to be contained in the excel file.

outputter.place_in_dict(t, model, dictionary: dict, key: str, value)[source]

Appends an entry in the list corresponding to key if key exists in dictionary. Otherwise creates a single entry in the dictionary as {key: [value]}

outputter.plot_energy_balance(model, results: dict, **kwargs) None[source]

Visualization of energy balance for all the streams, i.e., Plots the energy interactions of all the streams with loads, converters, storages, imports and exports. Plots are dashed and marked with shape markers for visibility in case of overlap. Adjust the properties of the plot by passing arguments from below.

Parameters:
  • model – The object of EHubModel class (or any child class thereof); the energy hub model.

  • results – dictionary; returned by solve() method.

  • size – tuple; (width, height) of the plot [default is (9,5)].

  • lw – float; linewidth of the plots [default is 2].

  • dl – float; length of the dashes constituting the dashed plots [default is 3].

outputter.plot_storages(results: dict, **kwargs) None[source]

Plots various variables related to storages: storage state: The level of energy remaining in the storage. gross charge(charge from stream): Energy sent to storage from stream for charging. gross discharge(discharge to stream): Energy going into stream after discharging. net charge: Energy actually reaching storage(after loss of gross charge due to charging efficiency). net discharge: Energy actually leaving storage(after loss from this due to discharging efficiency, it becomes gross

discharge).

decay loss(standing loss): Energy dissipating due to standing losses. Note: All of the above are plotted as default. You can change this by passing respective arguments.

Parameters:
  • results – dictionary; returned by solve() method.

  • pl_state – boolean value; whether to plot ‘storage state’ or not.

  • pl_gross_ch – boolean value; whether to plot ‘gross charge’ or not.

  • pl_gross_dch – boolean value; whether to plot ‘gross discharge’ or not.

  • pl_net_ch – boolean value; whether to plot ‘net charge’ or not.

  • pl_net_dch – boolean value; whether to plot ‘net discharge’ or not.

  • pl_decay – boolean value; whether to plot ‘decay loss’ or not.

  • size – tuple; (width, height) of the plot [default is (10,5)].

  • percentage – boolean; y-axis units in % or in kWh [default].

outputter.pretty_print(results: dict) None[source]

Print the results in a prettier format.

Parameters:

results – The results dictionary to print

outputter.print_capacities(results)[source]

Prints the capacities of each tech and storage at the end

Parameters:

results – the solved model

outputter.print_section(section_name: str, solution_section: dict) None[source]

Print all the attributes with a heading.

Parameters:
  • section_name – The heading

  • solution_section – The dictionary with all the attributes

outputter.print_warning(results)[source]

Prints an error if the model burns energy, i.e there is energy from storage and energy to storage at same time step.

Parameters:

results – the solved model

outputter.sort_dict(mapping: dict | OrderedDict) OrderedDict[source]

Sorts a dictionary and all its sub-dicionaries as well.

Examples

>>> sort_dict({1: 'a', 3: 'c', 2: 'b'})
OrderedDict([(1, 'a'), (2, 'b'), (3, 'c')])
>>> sort_dict({1: {3: 'c', 2: 'b', 1: 'a'}})
OrderedDict([(1, OrderedDict([(1, 'a'), (2, 'b'), (3, 'c')]))])
Parameters:

mapping – The dictionary to be sorted

Returns:

The sorted dictionary as an OrderedDict

outputter.stream_info(results, output_file)[source]

New output format with the information separated in different sheets for different streams.

Parameters:
  • results – the solved model

  • output_file – the output excel file

outputter.to_dataframe(name: str, value: dict) DataFrame[source]

Convert a dictionary into a dataframe.

Parameters:
  • name – The name for the dataframe

  • value – The dictionary to be converted

Returns:

A Pandas DataFrame.

outputter.to_dataframes(frames: dict) OrderedDict[source]

Convert the values of a dictionary into dataframes if they can be converted.

Parameters:

frames – The dictionary to be converted

Returns:

An ordered dictionary with dataframes as values (if they can be converted).