zen_garden.postprocess.results.results¶
This module contains the Results class, which is used to extract and process the results of a model run.
Classes
|
The Results class is used to extract and process the results of a model run. |
- class zen_garden.postprocess.results.results.Results(path: str, enable_cache: bool = True)¶
The Results class is used to extract and process the results of a model run.
- __init__(path: str, enable_cache: bool = True)¶
Initializes the Results class.
- Parameters:
path – Path to the results folder
- calculate_connected_edges(node: str, direction: str, set_nodes_on_edges: dict[str, str])¶
Calculates connected edges going in (direction = ‘in’) or going out (direction = ‘out’).
- Parameters:
node – current node, connected by edges
direction – direction of edges, either in or out. In: node = endnode, out: node = startnode
set_nodes_on_edges – set of nodes on edges
- Returns:
list of connected edges
- Return type:
set_connected_edges
- edit_carrier_flows(data: DataFrame, node: str, direction: str, scenario: str) DataFrame¶
Extracts data of carrier_flow variable as needed for the plot_energy_balance function.
- Parameters:
data – pd.DataFrame containing data to extract
node – node of interest
direction – flow direction with respect to node
scenario – scenario of interest
- Returns:
pd.DataFrame containing carrier_flow data desired
- extract_carrier(dataframe: DataFrame, carrier: str, scenario_name: str) DataFrame¶
Returns a dataframe that only contains the desired carrier. If carrier is not contained in the dataframe, the technologies that have the provided reference carrier are returned.
- Parameters:
dataframe – pd.Dataframe containing the base data
carrier – name of the carrier
scenario_name – name of the scenario
- Returns:
filtered pd.Dataframe containing only the provided carrier
- get_analysis(scenario_name: str | None = None) Analysis¶
Extract analysis configurations from a scenario.
Extracts analysis configurations from the results of a scenario. This ensures the tractability of model configurations. Analysis configurations are those specified under the
analysisobject in theconfig.jsonfile.- Parameters:
scenario_name (str, optional) – The name of the scenario for which to extract the system configuration. If no value is given, then the first scenario is used. Default value:
None.- Returns:
Analysis configuration.
- Return type:
Examples
Basic usage example:
>>> from zen_garden.postprocess.results.results import Results >>> r = Results(path='<result_folder>') >>> r.get_analysis() # analysis config of first scenario >>> r.get_analysis('scenario_name') # analysis config of "scenario_name"
- get_component_names(component_type: str) list[str]¶
Returns the names of all components of a given type.
- Parameters:
component_type – Type of the component
- Returns:
List of component names
- get_coords(scenario_name: str | None = None) DataFrame | None¶
Extracts the coordinates of the nodes of a given Scenario. If no scenario is given, a random one is taken.
- Parameters:
scenario_name – Name of the scenario
- Returns:
The corresponding coordinates
- get_df(component_name: str, scenario_name: str | None = None, data_type: Literal['dataframe', 'units'] = 'dataframe', index: tuple[list[str]] | tuple[str] | dict[str, str | list[str]] | list[str] | str | float | int | None = None) dict[str, pd.DataFrame | pd.Series[Any]] | Series | None¶
Returns the raw results without any further processing.
Transforms a parameter or variable dataframe (compressed) string into an actual pandas dataframe.
- Parameters:
component_name (string) – The string to decode
scenario_name – Which scenario to take. If none is specified, all are returned.
data_type – The type of data to extract. Either ‘dataframe’ or ‘units’
index – slicing index of the resulting dataframe
- Returns:
The corresponding dataframe
- Return type:
DataFrame
- get_doc(component_name: str) str¶
Extracts the documentation of a given Component.
- Parameters:
component_name – Name of the component
- Returns:
The corresponding documentation
- get_dual(component_name: str, scenario_name: str | None = None, year: int | None = None, discount_to_first_step: bool = True, keep_raw: bool | None = False, index: tuple[list[str]] | tuple[str] | dict[str, str | list[str]] | list[str] | str | float | int | None = None) pd.DataFrame | pd.Series[Any] | None¶
Extracts the dual variables of a component.
- Parameters:
component_name – Name of dual
scenario_name – Scenario Name
year – Year
discount_to_first_step – apply annuity to first year of interval or entire interval
keep_raw – Keep the raw values of the rolling horizon optimization
index – slicing index of the resulting dataframe
- Returns:
Duals of the component
- Return type:
DataFrame
- get_energy_balance_dataframes(node: str, carrier: str, year: int, scenario_name: str | None = None) dict[str, pd.Series[Any]]¶
Returns a dictionary with all dataframes that are relevant for the energy balance. The dataframes “flow_transport_in” and “flow_transport_out” contain the data of “flow_transport”, filtered for in / out flow.
- Parameters:
node – Node of interest
carrier – Carrier of interest
year – Year of interest
scenario_name – Scenario name of interest
- Returns:
Dictionary containing the relevant pd.Dataframes
- get_full_ts(component_name: str, scenario_name: str | None = None, discount_to_first_step: bool | None = True, year: int | None = None, keep_raw: bool | None = False, index: tuple[list[str]] | tuple[str] | dict[str, str | list[str]] | list[str] | str | float | int | None = None) pd.DataFrame | pd.Series[Any]¶
Calculates the full timeseries.
- Parameters:
component_name – Name of the component
scenario_name – The scenario for with the component should be extracted (only if needed)
discount_to_first_step – apply annuity to first year of interval or entire interval
year – year of which full time series is selected
keep_raw – Keep the raw values of the rolling horizon optimization
index – slicing index of the resulting dataframe
- Returns:
Full timeseries
- get_full_ts_per_scenario(scenario: Scenario, component: Component, year: int | None = None, discount_to_first_step: bool = True, keep_raw: bool | None = False, index: tuple[str] = None) DataFrame¶
Calculates the full timeseries per scenario.
- Parameters:
scenario – The scenario for with the component should be extracted (only if needed)
component – Component for the Series
discount_to_first_step – apply annuity to first year of interval or entire interval
year – year of which full time series is selected
keep_raw – Keep the raw values of the rolling horizon optimization
index – slicing index of the resulting dataframe
- Returns:
Full timeseries
- get_index_names(component_name: str, scenario_name: str | None = None) list[str]¶
Docstring for get_index_names.
- Parameters:
self – Description
component_name (str) – Description
scenario_name (Optional[str]) – Description
- Returns:
Description
- Return type:
list[str]
- get_solver(scenario_name: str | None = None) Solver¶
Extract solver configurations from a scenario.
Extracts solver configurations from the results of a scenario. This ensures the tractability of model configurations. Solver configurations are those specified under the
solverobject in theconfig.jsonfile.- Parameters:
scenario_name (str, optional) – The name of the scenario for which to extract the system configuration. If no value is given, then the first scenario is used. Default value:
None.- Returns:
Solver configuration.
- Return type:
Examples
Basic usage example:
>>> from zen_garden.postprocess.results.results import Results >>> r = Results(path='<result_folder>') >>> r.get_solver() # solver configurations of first scenario >>> r.get_solver('scenario_name') # solver configuration of "scenario_name"
- get_system(scenario_name: str | None = None) System¶
Extract system configurations from a scenario.
Extracts system configurations from the results of a scenario. This ensures the tractability of model configurations. System configurations are those specified in the
system.jsonfile of a given model.- Parameters:
scenario_name (str, optional) – The name of the scenario for which to extract the system configuration. If no value is given, then the first scenario is used. Default value:
None.- Returns:
System configuration.
- Return type:
Examples
Basic usage example:
>>> from zen_garden.postprocess.results.results import Results >>> r = Results(path='<result_folder>') >>> r.get_system() # system configurations of first scenario >>> r.get_system('scenario_name') # system configuration of "scenario_name"
- get_total(component_name: str, year: int | None = None, scenario_name: str | None = None, keep_raw: bool | None = False, index: tuple[list[str]] | tuple[str] | dict[str, str | list[str]] | list[str] | str | float | int | None = None) pd.DataFrame | pd.Series[Any]¶
Calculates the total values of a component for a all scenarios.
- Parameters:
component_name – Name of the component. Should not be used for dual variables!
year – Filter the results by a given year
scenario_name – Filter the results by a given scenario
keep_raw – Keep the raw values of the rolling horizon optimization
index – slicing index of the resulting dataframe
- Returns:
Total values of the component
- Return type:
DataFrame
- get_total_per_scenario(scenario: Scenario, component: Component, year: int | None = None, keep_raw: bool | None = False, index: tuple[str] = None) pd.DataFrame | pd.Series[Any]¶
Calculates the total values of a component for a specific scenario.
- Parameters:
scenario – Scenario
component – Component
year – Filter the results by a given year
keep_raw – Keep the raw values of the rolling horizon optimization
index – slicing index of the resulting dataframe
- Returns:
Total values of the component
- get_unit(component_name: str, scenario_name: str | None = None, index: tuple[list[str]] | tuple[str] | dict[str, str | list[str]] | list[str] | str | float | int | None = None, droplevel: bool = True, convert_to_yearly_unit: bool = False) None | Series | str¶
Extracts the unit of a given Component. If no scenario is given, a random one is taken.
- Parameters:
component_name – Name of the component
scenario_name – Name of the scenario
index – slicing index of the resulting dataframe
droplevel – Drop the location and time levels of the multiindex
convert_to_yearly_unit – If True, the unit is converted to a yearly unit, i.e., for components with an operational time step type, the unit is multiplied by hours.
- Returns:
The corresponding unit
- Return type:
DataFrame
- get_years(scenario_name: str | None = None) list[int]¶
Extracts the years of a given Scenario. If no scenario is given, a random one is taken.
- Parameters:
scenario_name – Name of the scenario
- Returns:
List of years
- has_MF(scenario_name: str | None = None) bool¶
Extracts the System config of a given Scenario. If no scenario is given, a random one is taken.
- Parameters:
scenario_name – Name of the scenario
- Returns:
The corresponding System config