From d3486cac0410b77d73e0a8004c14fbc02782fc49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oscar=20Stenstr=C3=B6m?= Date: Mon, 26 Jun 2023 14:03:20 +0200 Subject: [PATCH] Cleaning up comments --- view.py | 50 +++++++++++++++++++------------------------------- 1 file changed, 19 insertions(+), 31 deletions(-) diff --git a/view.py b/view.py index 2e0e9b0..701695a 100644 --- a/view.py +++ b/view.py @@ -1,15 +1,14 @@ """ROBUST DECISION MAKING (RDM) MODEL FOR BECCS This program was developed to perform a Robust Decision Making (RDM) analysis of the investment -decision of deploying a bioenergy carbon capture and storage deployment (BECCS) facility. The -case studied is the planned BECCS facility of Stockholm Exergi (more info at www.beccs.se). -The program utilizes Rhodium, an open-source Python library for RDM and exploratory modeling: +decision of deploying a bioenergy carbon capture and storage deployment (BECCS) facility. The +program utilizes Rhodium, an open-source Python library for RDM and exploratory modeling: https://github.com/Project-Platypus/Rhodium To run the program, first follow the installation guide provided in the repository. Make sure -this file "BECCS_investment_paper_version.py" is in the root "Rhodium" folder. +the file "controller.py" is in the root "Rhodium" folder before running it in the terminal. """ __author__ = "Oscar Stenström" -__date__ = "2023-06-05" +__date__ = "2023-06-26" from scipy.optimize import brentq as root from rhodium import scatter2d, Cart, pairs, DataSet, Model, joint @@ -22,7 +21,6 @@ def plot_results(model: Model, model_results: DataSet): - ## BELOW IS A MIX OF RESULTS ANALYSIS AND PLOTTING print("-------------BEGIN RESPONSE PLOTTING NOW-------------") fig = scatter2d(model, model_results, x="NPV_wait", y="NPV_invest", c="Regret") fig.savefig("2_NPV_Regret.png", dpi=600) @@ -52,9 +50,11 @@ def plot_results(model: Model, model_results: DataSet): plt.savefig("2_Responses_Pair.png", dpi=600) plt.clf() + # These rows illustrate how to find the density of zero-Regret futures. The price of + # 120 EUR/tCO2 was arbitrarily chosen. n_successful = len(model_results.find("Regret==0 and pNE_supported>120")) n_unsuccessful = len(model_results.find("Regret >0 and pNE_supported>120")) - print( n_successful/(n_successful+n_unsuccessful)*100 , "% of scenarios have Regret = 0 when the NE price is above 120 EUR/t") #94% + print( n_successful/(n_successful+n_unsuccessful)*100 , "% of scenarios have Regret = 0 when the NE price is above 120 EUR/t") def robustness_analysis(model_results: DataSet): """Prints robustness analytics to the terminal""" @@ -77,10 +77,10 @@ def robustness_analysis(model_results: DataSet): for SOW in model_results: invest_regret = ( max(SOW["NPV_invest"], SOW["NPV_wait"]) - SOW["NPV_invest"] - ) # Finding Regret again from model results. + ) wait_regret = ( max(SOW["NPV_invest"], SOW["NPV_wait"]) - SOW["NPV_wait"] - ) # Finding Regret again from model results. + ) invest_regret_vec.append(invest_regret) wait_regret_vec.append(wait_regret) print("Investing has maximum regret ", max(invest_regret_vec), " EUR") @@ -91,18 +91,13 @@ def robustness_analysis(model_results: DataSet): def scenario_discovery(model: Model, model_results: DataSet) -> list: - #NOW I WANT TO FIND THE INTERESTING SCENARIOS. WITH EXACT VALUES! - #1) Find Regret=0. See what pop outs. - - # The scenario discovery produces ranges of uncertainties (i.e. scenarios) where Invest performs well (i.e. have Regret = 0). print("-------------BEGIN SCENARIO DISCOVERY NOW-------------") classification = model_results.apply("'Reliable' if (Regret == 0 and NPV_invest >= 0) else 'Unreliable'") - # Alternative classifications that can be applied depending on what analysis is made: - # Regret == 0 and NPV_invest >= 0 # Drivers are then: yCLAM and pelectricity + # Below are some alternative classifications that can be applied, depending on what analysis is of interest: + # Regret == 0 # pNE_supported-Cost_specific > 0 # Regret != 0 - # Maybe find scenarios based on Exergi adaptation: pelectricity-pheat < 40 MWh. In such scenarios, what are the key drivers? cart_results = Cart( model_results, @@ -114,8 +109,7 @@ def scenario_discovery(model: Model, model_results: DataSet) -> list: cart_results.save("4_CART_tree.png") node_list = cart_results.print_tree( coi="Reliable" - ) # NOTE: in the classification.py file of rhodium, the print_tree() function was edited. - # These edits basically just save the scenario nodes of the CART tree into a list, and return this list. + ) return node_list @@ -175,7 +169,7 @@ def plot_scenario_of_interest(model: Model, model_results: DataSet): # represents a discovered scenario. The drawing is hard coded and can be changed as desired, depending on the scenario of interest. #-----------------The 1st scenario is plotted below---------- - # 2 Reliable 91.54516608426718 39.385508648844805 pelectricity_mean <= 109.776455 yCLAIM <= 2034.040527 (REGRET = 0) + # The classifier Regret = 0 was used. fig = scatter2d(model, model_results, x="yCLAIM", y="pelectricity_mean", c="Regret") scenario_area = mpatches.Rectangle( (2024, 20), @@ -191,7 +185,7 @@ def plot_scenario_of_interest(model: Model, model_results: DataSet): plt.clf() #-----------------The 2nd scenario is plotted below---------- - # 1170 Reliable 75.04733607154301 61.26316790716477 pelectricity_mean > 81.914059 yCLAIM > 2034.032410 (REGRET != 0) + # The classifier Regret != 0 was used. fig = scatter2d(model, model_results, x="yCLAIM", y="pelectricity_mean", c="Regret") scenario_area = mpatches.Rectangle( (2034, 82), @@ -207,7 +201,7 @@ def plot_scenario_of_interest(model: Model, model_results: DataSet): plt.clf() #-----------------The 3rd scenario is plotted below---------- - # 206 Reliable 96.2998361551065 29.347147671951067 pNE_mean > 150.728317 yCLAIM <= 2030.209717 (REGRET = 0 AND Pelec>82) + # The classifier Regret = 0 was used. fig = scatter2d(model, model_results.find("pelectricity_mean>82"), x="yCLAIM", y="pNE_mean", c="Regret") scenario_area = mpatches.Rectangle( (2024, 151), @@ -224,8 +218,7 @@ def plot_scenario_of_interest(model: Model, model_results: DataSet): plt.clf() #-----------------The 4th scenario is plotted below---------- - # 95 Reliable 70.06802721088435 39.56005586592179 pETS_2050 > 232.763702 yBIOban <= 2034.975525 (REGRET = 0, AND Pelec>82 AND yCLAIM>2034) - # 169 Reliable 88.32214765100672 22.97486033519553 pETS_2050 > 232.763702 AUCTION > 0.532030 yBIOban <= 2034.975525 + # The classifier Regret = 0 was used. fig = scatter2d(model, model_results.find("pelectricity_mean>82 and yCLAIM>2034"), x="pETS_2050", y="yBIOban", c="Regret") scenario_area = mpatches.Rectangle( (233, 2030), @@ -242,7 +235,6 @@ def plot_scenario_of_interest(model: Model, model_results: DataSet): plt.clf() #-----------------These rows can be used to combine plots into subplots---------- - # crop the right side of fig2 and fig3 by 5% img1 = Image.open("4_Scenario_1.png") img1_width, img1_height = img1.size img1_cropped = img1.crop((0, img1_width * 0.05, img1_width * 0.95, img1_height)) @@ -263,7 +255,7 @@ def plot_scenario_of_interest(model: Model, model_results: DataSet): img4_cropped = img4.crop((0, img4_width * 0.05, img4_width * 0.95, img4_height)) img4_cropped.save("4_Scenario_4_cropped.png") - # create a new figure and combine fig2 and fig3 + # Creates a new figure and combine fig2 and fig3 fig, axs = plt.subplots(2, 2, figsize=(12,9)) axs[0,0].imshow(img1_cropped) axs[0,0].set_xlabel("(a)", fontsize=12) @@ -278,10 +270,6 @@ def plot_scenario_of_interest(model: Model, model_results: DataSet): axs[1,1].set(xlabel="(d)") axs[1,1].axis("off") - # adjust the layout by reducing the height spacing between subplots - # plt.subplots_adjust(hspace=0) - - # adjust the layout and save the combined figure plt.tight_layout() plt.savefig("4_Scenarios_ALL.png", dpi=600) plt.clf() @@ -289,7 +277,7 @@ def plot_scenario_of_interest(model: Model, model_results: DataSet): def save_sensitivity_analysis( model: Model, sobol_result, RDM_results_excel: openpyxl.Workbook ): - # Save Sobol results to a CART excel sheet: + # Save Sobol results to a separate excel sheet: sheet = RDM_results_excel.create_sheet("Sobol_results") RDM_results_excel.active = RDM_results_excel["Sobol_results"] sheet["A1"] = "Uncertainty" @@ -311,7 +299,7 @@ def save_sensitivity_analysis( def plot_sensitivity_analysis_results(sobol_result): - #NOTE: can comment out the print, if desired. + #NOTE: you can comment out the print, if desired. print(sobol_result) plt.clf() fig = sobol_result.plot_sobol(