Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for OptiFlow_MainResults #18

Merged
merged 4 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/pybalmorel/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class MainResults:
def __init__(self, files: Union[str, list, tuple],
paths: Union[str, list, tuple] = '.',
scenario_names: Union[str, list, tuple] = None,
system_directory: str = None):
system_directory: str = None,
result_type: str = 'balmorel'):
"""
Initialises the MainResults class and loads gdx result file(s)

Expand All @@ -40,6 +41,7 @@ def __init__(self, files: Union[str, list, tuple],
paths (str, list, tuple): Path(s) to the gdx result file(s), assumed in same path if only one path given, defaults to working directory
scenario_names (str, list, tuple): Name of scenarios corresponding to each gdx file, defaults to ['SC1', 'SC2', ..., 'SCN'] if None given
system_directory (str, optional): GAMS system directory. Is not used if not specified.
result_type (str, optional): Specifies the type of result to extract. Use 'optiflow' for OptiFlow results. If not specified, it defaults to extracting Balmorel GDX results.
"""

## Loading scenarios
Expand Down Expand Up @@ -83,11 +85,12 @@ def __init__(self, files: Union[str, list, tuple],
if len(files) != len(scenario_names):
# Raise error if not given same amount of scenario_names and files
raise Exception("%d files, but %d scenario names given!\nProvide none or the same amount of scenario names as files"%(len(files), len(scenario_names)))

## Store MainResult databases
self.files = files
self.paths = paths
self.sc = scenario_names
self.type = result_type
self.db = {}

if system_directory != None:
Expand Down Expand Up @@ -116,7 +119,7 @@ def get_result(self, symbol: str, cols: str = 'None') -> pd.DataFrame:
for SC in self.sc:
# Get results from each scenario
try :
temp = symbol_to_df(self.db[SC], symbol, cols)
temp = symbol_to_df(self.db[SC], symbol, cols, result_type=self.type)
temp['Scenario'] = SC
# Put scenario in first column
temp = temp.loc[:, ['Scenario'] + list(temp.columns[:-1])]
Expand Down
172 changes: 111 additions & 61 deletions src/pybalmorel/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,64 +116,114 @@
### 2. Other ###
### ------------------------------- ###

mainresult_symbol_columns = {'F_CONS_YCRA': ['Year','Country','Region','Area','Generation','Fuel','Technology'],
'F_CONS_YCRAST': ['Year','Country','Region','Area','Generation','Fuel','Season','Time','Technology'],
'G_CAP_YCRAF': ['Year','Country','Region','Area','Generation','Fuel','Commodity','Technology','Category'],
'EL_DEMAND_YCR': ['Year','Country','Region','Category'],
'EL_DEMAND_YCRST': ['Year','Country','Region','Season','Time','Category'],
'EL_PRICE_YCR': ['Year','Country','Region'],
'EL_PRICE_YCRST': ['Year','Country','Region','Season','Time'],
'G_STO_YCRAF': ['Year','Country','Region','Area','Generation','Fuel','Commodity','Technology','Category'],
'EL_BALANCE_YCRST':['Year','Country','Region','Technology','Season','Time'],
'H2_DEMAND_YCR': ['Year','Country','Region','Category'],
'H2_DEMAND_YCRST': ['Year','Country','Region','Season','Time','Category'],
'H2_PRICE_YCR': ['Year','Country','Region','Category'],
'H2_DEMAND_YCRST': ['Year','Country','Region','Season','Time','Category'],
'H_BALANCE_YCRAST':['Year','Country','Region','Area','Technology','Season','Time'],
'H_DEMAND_YCRA': ['Year','Country','Region','Area','Category'],
'H_DEMAND_YCRAST': ['Year','Country','Region','Area','Season','Time','Category'],
'H_PRICE_YCRA': ['Year','Country','Region','Area','Category'],
'H_PRICE_YCRAST': ['Year','Country','Region','Area','Season','Time'],
'OBJ_YCR': ['Year','Country','Region','Category'],
'PRO_YCRAGF': ['Year','Country','Region','Area','Generation','Fuel','Commodity','Technology'],
'PRO_YCRAGFST': ['Year','Country','Region','Area','Generation','Fuel','Season','Time','Commodity','Technology'],
'X_CAP_YCR': ['Year','Country','From','To','Category'],
'X_FLOW_YCR': ['Year','Country','From','To'],
'X_FLOW_YCRST': ['Year','Country','From','To','Season','Time'],
'XH2_CAP_YCR': ['Year','Country','From','To','Category'],
'XH2_FLOW_YCR': ['Year','Country','From','To'],
'XH2_FLOW_YCRST': ['Year','Country','From','To','Season','Time'],
'XH_CAP_YCA': ['Year','Country','From','To','Category'],
'XH_FLOW_YCA': ['Year','Country','From','To'],
'XH_FLOW_YCAST': ['Year','Country','From','To','Season','Time']}

mainresults_symbol_columns = {'F_CONS_YCRA': ['Scenario', 'Year','Country','Region','Area','Generation','Fuel','Technology'],
'F_CONS_YCRAST': ['Scenario', 'Year','Country','Region','Area','Generation','Fuel','Season','Time','Technology'],
'G_CAP_YCRAF': ['Scenario', 'Year','Country','Region','Area','Generation','Fuel','Commodity','Technology','Category'],
'G_STO_YCRAF': ['Scenario', 'Year','Country','Region','Area','Generation','Fuel','Commodity','Technology','Category'],
'EL_DEMAND_YCR': ['Scenario', 'Year','Country','Region','Category'],
'EL_DEMAND_YCRST': ['Scenario', 'Year','Country','Region','Season','Time','Category'],
'EL_PRICE_YCR': ['Scenario', 'Year','Country','Region'],
'EL_PRICE_YCRST': ['Scenario', 'Year','Country','Region','Season','Time'],
'EL_BALANCE_YCRST':['Scenario', 'Year','Country','Region','Technology','Season','Time'],
'H2_DEMAND_YCR': ['Scenario', 'Year','Country','Region','Category'],
'H2_DEMAND_YCRST': ['Scenario', 'Year','Country','Region','Season','Time','Category'],
'H2_PRICE_YCR': ['Scenario', 'Year','Country','Region','Category'],
'H2_DEMAND_YCRST': ['Scenario', 'Year','Country','Region','Season','Time','Category'],
'H_BALANCE_YCRAST':['Scenario', 'Year','Country','Region','Area','Technology','Season','Time'],
'H_DEMAND_YCRA': ['Scenario', 'Year','Country','Region','Area','Category'],
'H_DEMAND_YCRAST': ['Scenario', 'Year','Country','Region','Area','Season','Time','Category'],
'H_PRICE_YCRA': ['Scenario', 'Year','Country','Region','Area','Category'],
'H_PRICE_YCRAST': ['Scenario', 'Year','Country','Region','Area','Season','Time'],
'OBJ_YCR': ['Scenario', 'Year','Country','Region','Category'],
'PRO_YCRAGF': ['Scenario', 'Year','Country','Region','Area','Generation','Fuel','Commodity','Technology'],
'PRO_YCRAGFST': ['Scenario', 'Year','Country','Region','Area','Generation','Fuel','Season','Time','Commodity','Technology'],
'X_CAP_YCR': ['Scenario', 'Year','Country','From','To','Category'],
'X_FLOW_YCR': ['Scenario', 'Year','Country','From','To'],
'X_FLOW_YCRST': ['Scenario', 'Year','Country','From','To','Season','Time'],
'XH2_CAP_YCR': ['Scenario', 'Year','Country','From','To','Category'],
'XH2_FLOW_YCR': ['Scenario', 'Year','Country','From','To'],
'XH2_FLOW_YCRST': ['Scenario', 'Year','Country','From','To','Season','Time'],
'XH_CAP_YCA': ['Scenario', 'Year','Country','From','To','Category'],
'XH_FLOW_YCA': ['Scenario', 'Year','Country','From','To'],
'XH_FLOW_YCAST': ['Scenario', 'Year','Country','From','To','Season','Time']}
#Balmorel
balmorel_symbol_columns = {'F_CONS_YCRA': ['Year','Country','Region','Area','Generation','Fuel','Technology'],
'F_CONS_YCRAST': ['Year','Country','Region','Area','Generation','Fuel','Season','Time','Technology'],
'G_CAP_YCRAF': ['Year','Country','Region','Area','Generation','Fuel','Commodity','Technology','Category'],
'EL_DEMAND_YCR': ['Year','Country','Region','Category'],
'EL_DEMAND_YCRST': ['Year','Country','Region','Season','Time','Category'],
'EL_PRICE_YCR': ['Year','Country','Region'],
'EL_PRICE_YCRST': ['Year','Country','Region','Season','Time'],
'G_STO_YCRAF': ['Year','Country','Region','Area','Generation','Fuel','Commodity','Technology','Category'],
'EL_BALANCE_YCRST':['Year','Country','Region','Technology','Season','Time'],
'H2_DEMAND_YCR': ['Year','Country','Region','Category'],
'H2_DEMAND_YCRST': ['Year','Country','Region','Season','Time','Category'],
'H2_PRICE_YCR': ['Year','Country','Region','Category'],
'H2_DEMAND_YCRST': ['Year','Country','Region','Season','Time','Category'],
'H_BALANCE_YCRAST':['Year','Country','Region','Area','Technology','Season','Time'],
'H_DEMAND_YCRA': ['Year','Country','Region','Area','Category'],
'H_DEMAND_YCRAST': ['Year','Country','Region','Area','Season','Time','Category'],
'H_PRICE_YCRA': ['Year','Country','Region','Area','Category'],
'H_PRICE_YCRAST': ['Year','Country','Region','Area','Season','Time'],
'OBJ_YCR': ['Year','Country','Region','Category'],
'PRO_YCRAGF': ['Year','Country','Region','Area','Generation','Fuel','Commodity','Technology'],
'PRO_YCRAGFST': ['Year','Country','Region','Area','Generation','Fuel','Season','Time','Commodity','Technology'],
'X_CAP_YCR': ['Year','Country','From','To','Category'],
'X_FLOW_YCR': ['Year','Country','From','To'],
'X_FLOW_YCRST': ['Year','Country','From','To','Season','Time'],
'XH2_CAP_YCR': ['Year','Country','From','To','Category'],
'XH2_FLOW_YCR': ['Year','Country','From','To'],
'XH2_FLOW_YCRST': ['Year','Country','From','To','Season','Time'],
'XH_CAP_YCA': ['Year','Country','From','To','Category'],
'XH_FLOW_YCA': ['Year','Country','From','To'],
'XH_FLOW_YCAST': ['Year','Country','From','To','Season','Time']
}


balmorel_mainresults_symbol_columns = {'F_CONS_YCRA': ['Scenario', 'Year','Country','Region','Area','Generation','Fuel','Technology'],
'F_CONS_YCRAST': ['Scenario', 'Year','Country','Region','Area','Generation','Fuel','Season','Time','Technology'],
'G_CAP_YCRAF': ['Scenario', 'Year','Country','Region','Area','Generation','Fuel','Commodity','Technology','Category'],
'G_STO_YCRAF': ['Scenario', 'Year','Country','Region','Area','Generation','Fuel','Commodity','Technology','Category'],
'EL_DEMAND_YCR': ['Scenario', 'Year','Country','Region','Category'],
'EL_DEMAND_YCRST': ['Scenario', 'Year','Country','Region','Season','Time','Category'],
'EL_PRICE_YCR': ['Scenario', 'Year','Country','Region'],
'EL_PRICE_YCRST': ['Scenario', 'Year','Country','Region','Season','Time'],
'EL_BALANCE_YCRST':['Scenario', 'Year','Country','Region','Technology','Season','Time'],
'H2_DEMAND_YCR': ['Scenario', 'Year','Country','Region','Category'],
'H2_DEMAND_YCRST': ['Scenario', 'Year','Country','Region','Season','Time','Category'],
'H2_PRICE_YCR': ['Scenario', 'Year','Country','Region','Category'],
'H2_DEMAND_YCRST': ['Scenario', 'Year','Country','Region','Season','Time','Category'],
'H_BALANCE_YCRAST':['Scenario', 'Year','Country','Region','Area','Technology','Season','Time'],
'H_DEMAND_YCRA': ['Scenario', 'Year','Country','Region','Area','Category'],
'H_DEMAND_YCRAST': ['Scenario', 'Year','Country','Region','Area','Season','Time','Category'],
'H_PRICE_YCRA': ['Scenario', 'Year','Country','Region','Area','Category'],
'H_PRICE_YCRAST': ['Scenario', 'Year','Country','Region','Area','Season','Time'],
'OBJ_YCR': ['Scenario', 'Year','Country','Region','Category'],
'PRO_YCRAGF': ['Scenario', 'Year','Country','Region','Area','Generation','Fuel','Commodity','Technology'],
'PRO_YCRAGFST': ['Scenario', 'Year','Country','Region','Area','Generation','Fuel','Season','Time','Commodity','Technology'],
'X_CAP_YCR': ['Scenario', 'Year','Country','From','To','Category'],
'X_FLOW_YCR': ['Scenario', 'Year','Country','From','To'],
'X_FLOW_YCRST': ['Scenario', 'Year','Country','From','To','Season','Time'],
'XH2_CAP_YCR': ['Scenario', 'Year','Country','From','To','Category'],
'XH2_FLOW_YCR': ['Scenario', 'Year','Country','From','To'],
'XH2_FLOW_YCRST': ['Scenario', 'Year','Country','From','To','Season','Time'],
'XH_CAP_YCA': ['Scenario', 'Year','Country','From','To','Category'],
'XH_FLOW_YCA': ['Scenario', 'Year','Country','From','To'],
'XH_FLOW_YCAST': ['Scenario', 'Year','Country','From','To','Season','Time']
}

#Optiflow
optiflow_symbol_columns = {'ECO_INDIC': ['Year','Indicator'],
'ECO_PROC_YCRAP': ['Year','Country','Region','Area','Process','Cost'],
'EMI_PROC': ['Year','Country','Region','Area','Process','Flow'],
'EMI_YCRAG': ['Year','Country','Region','Area','Generation','Fuel','Technology'],
'OBJ_YCR': ['Year','Country','Region','Category'],
'PRO_YCRAGF': ['Year','Country','Region','Area','Generation','Fuel','Commodity','Technology'],
'PRO_YCRAGFST': ['Year','Country','Region','Area','Generation','Fuel','Season','Time','Commodity','Technology'],
'RE_fuel_Price': ['Year','Country','Process','Flow'],
'VFLOW_Opti_A': ['Year','Country','From','To','Flow'],
'VFLOW_Opti_C': ['Year','Country','From','To','Flow'],
'VFLOWBUFFER_Opti_C': ['Year','Buffer','Process','Flow'],
'VFLOTCCU_A': ['Year','Area','Source','Flow'],
'VFLOTCCU_C': ['Year','Country','Source','Flow'],
'VFLOWSOURCE_Opti_A': ['Year','Area','Source','Flow'],
'VFLOWSOURCE_Opti_C': ['Year','Country','Source','Flow'],
'VFLOWSTORAGE_Opti_A': ['Year','Area','Process','Flow'],
'VFLOWSTORAGE_Opti_C': ['Year','Country','Process','Flow'],
'VFLOWTRANS_Opti_A': ['Year','From','To','Process','Flow'],
'VFLOWTRANS_Opti_C': ['Year','From','To','Process','Flow']
}

optiflow_mainresults_symbol_columns = {'ECO_INDIC': ['Scenario','Year','Indicator'],
'ECO_PROC_YCRAP': ['Scenario','Year','Country','Region','Area','Process','Cost'],
'EMI_PROC': ['Scenario','Year','Country','Region','Area','Process','Flow'],
'EMI_YCRAG': ['Scenario','Year','Country','Region','Area','Generation','Fuel','Technology'],
'OBJ_YCR': ['Scenario','Year','Country','Region','Category'],
'PRO_YCRAGF': ['Scenario','Year','Country','Region','Area','Generation','Fuel','Commodity','Technology'],
'PRO_YCRAGFST': ['Scenario','Year','Country','Region','Area','Generation','Fuel','Season','Time','Commodity','Technology'],
'RE_fuel_Price': ['Scenario','Year','Country','Process','Flow'],
'VFLOW_Opti_A': ['Scenario','Year','Country','From','To','Flow'],
'VFLOW_Opti_C': ['Scenario','Year','Country','From','To','Flow'],
'VFLOWBUFFER_Opti_C': ['Scenario','Year','Buffer','Process','Flow'],
'VFLOTCCU_A': ['Scenario','Year','Area','Source','Flow'],
'VFLOTCCU_C': ['Scenario','Year','Country','Source','Flow'],
'VFLOWSOURCE_Opti_A': ['Scenario','Year','Area','Source','Flow'],
'VFLOWSOURCE_Opti_C': ['Scenario','Year','Country','Source','Flow'],
'VFLOWSTORAGE_Opti_A': ['Scenario','Year','Area','Process','Flow'],
'VFLOWSTORAGE_Opti_C': ['Scenario','Year','Country','Process','Flow'],
'VFLOWTRANS_Opti_A': ['Scenario','Year','From','To','Process','Flow'],
'VFLOWTRANS_Opti_C': ['Scenario','Year','From','To','Process','Flow']
}



13 changes: 11 additions & 2 deletions src/pybalmorel/interactive/interactive_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
import ipywidgets as widgets
from ipywidgets import interact, interactive
from ..plotting.plot_functions import plot_bar_chart
from ..formatting import mainresults_symbol_columns

from ..formatting import optiflow_mainresults_symbol_columns, balmorel_mainresults_symbol_columns

#%% ------------------------------- ###
### 1. Bar chart interactive ###
Expand All @@ -35,6 +34,16 @@ def interactive_bar_chart(MainResults_instance):
MainResults_instance (MainResults): Takes an instance of the MainResults class and opens a GUI for plotting
"""

"""Result type definition"""
result_type = MainResults_instance.type.lower()
print(f"Result type: {result_type}")

# Initial selection for plotting
if result_type=='optiflow':
mainresults_symbol_columns=optiflow_mainresults_symbol_columns
elif result_type=='balmorel':
mainresults_symbol_columns=balmorel_mainresults_symbol_columns

""" Buttons definition """

# Initial selection for plotting
Expand Down
Loading