From 9d0b220b54af2bf28781804a8d85e1aeb60cc8c8 Mon Sep 17 00:00:00 2001 From: chenxiaodong Date: Tue, 25 Jun 2024 14:07:04 +0800 Subject: [PATCH] plot --- PPO.py | 4 ++-- plotDRL.py | 37 ++++++++++++++++++------------------- tools.py | 2 +- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/PPO.py b/PPO.py index 2fd8f0e..b166d19 100644 --- a/PPO.py +++ b/PPO.py @@ -331,8 +331,8 @@ if __name__ == '__main__': buffer = list() '''init training parameters''' num_episode = args.num_episode - # args.train = False - # args.save_network = False + args.train = False + args.save_network = False # args.test_network = False # args.save_test_data = False # args.compare_with_gurobi = False diff --git a/plotDRL.py b/plotDRL.py index ba78f88..f4e22c8 100644 --- a/plotDRL.py +++ b/plotDRL.py @@ -62,7 +62,7 @@ def plot_optimization_result(datasource, directory): # data source is dataframe axs[1, 0].plot(T, datasource['netload'], label='Netload', drawstyle='steps-mid', alpha=0.7) axs[1, 0].legend(loc='upper right', fontsize=12, frameon=False, labelspacing=0.3) # axs[1,0].set_xticks([i for i in range(24)],[i for i in range(1,25)]) - # plt.show() + fig.savefig(f"{directory}/optimization_information.svg", format='svg', dpi=600, bbox_inches='tight') print('optimization results have been ploted and saved') @@ -78,9 +78,9 @@ def plot_evaluation_information(datasource, directory): plt.autoscale(tight=True) # prepare data for evaluation the environment here - eval_data = pd.DataFrame(test_data['information']) + eval_data = pd.DataFrame(test_data['system_info']) eval_data.columns = ['time_step', 'price', 'netload', 'action', 'real_action', 'soc', 'battery', 'gen1', 'gen2', - 'gen3', 'unbalance', 'operation_cost'] + 'gen3', 'temperature', 'irradiance', 'unbalance', 'operation_cost'] # plot unbalance in axs[0] axs[0, 0].cla() @@ -90,10 +90,17 @@ def plot_evaluation_information(datasource, directory): axs[0, 0].legend(loc='upper right', fontsize=12, frameon=False, labelspacing=0.5) # axs[0,0].set_xticks([i for i in range(24)],[i for i in range(1,25)]) - # plot reward in axs[1] - axs[1, 1].cla() - axs[1, 1].set_ylabel('Costs') - axs[1, 1].bar(eval_data['time_step'], eval_data['operation_cost']) + # plot energy charge/discharge with price in ax[1] + axs[0, 1].cla() + axs[0, 1].set_ylabel('Price') + axs[0, 1].set_xlabel('Time Steps') + + axs[0, 1].plot(eval_data['time_step'], eval_data['price'], drawstyle='steps-mid', label='Price', color='pink') + axs[0, 1] = axs[0, 1].twinx() + axs[0, 1].set_ylabel('SOC') + # axs[0,1].set_xticks([i for i in range(24)], [i for i in range(1, 25)]) + axs[0, 1].plot(eval_data['time_step'], eval_data['soc'], drawstyle='steps-mid', label='SOC', color='grey') + axs[0, 1].legend(loc='upper right', fontsize=12, frameon=False, labelspacing=0.3) # plot generation and netload in ax[2] axs[1, 0].cla() @@ -121,18 +128,10 @@ def plot_evaluation_information(datasource, directory): axs[1, 0].plot(x, eval_data['netload'], drawstyle='steps-mid', label='Netload') axs[1, 0].legend(loc='upper right', fontsize=12, frameon=False, labelspacing=0.3) - # plot energy charge/discharge with price in ax[3]. - axs[0, 1].cla() - axs[0, 1].set_ylabel('Price') - axs[0, 1].set_xlabel('Time Steps') - - axs[0, 1].plot(eval_data['time_step'], eval_data['price'], drawstyle='steps-mid', label='Price', color='pink') - axs[0, 1] = axs[0, 1].twinx() - axs[0, 1].set_ylabel('SOC') - # axs[0,1].set_xticks([i for i in range(24)], [i for i in range(1, 25)]) - axs[0, 1].plot(eval_data['time_step'], eval_data['soc'], drawstyle='steps-mid', label='SOC', color='grey') - axs[0, 1].legend(loc='upper right', fontsize=12, frameon=False, labelspacing=0.3) - # plt.show() + # plot reward in axs[3] + axs[1, 1].cla() + axs[1, 1].set_ylabel('Costs') + axs[1, 1].bar(eval_data['time_step'], eval_data['operation_cost']) fig.savefig(f"{directory}/Evoluation Information.svg", format='svg', dpi=600, bbox_inches='tight') print('evaluation figure have been plot and saved') diff --git a/tools.py b/tools.py index 7e8c17a..59796be 100644 --- a/tools.py +++ b/tools.py @@ -7,7 +7,7 @@ import torch from gurobipy import GRB -def optimization_base_result(env,month,day,initial_soc): +def optimization_base_result(env, month, day, initial_soc): price = env.data_manager.get_series_price_data(month, day) load = env.data_manager.get_series_load_cons_data(month, day) temperature = env.data_manager.get_series_temperature_data(month, day)