From abd1f96a2dc323ee4c8c02a7c54ec5ae342c7b80 Mon Sep 17 00:00:00 2001 From: Sadam93 Date: Fri, 31 May 2024 10:58:57 -0400 Subject: [PATCH] Update HEMS.py code --- HEMS.py | 121 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 61 insertions(+), 60 deletions(-) diff --git a/HEMS.py b/HEMS.py index 523b26d..3ac9d6e 100644 --- a/HEMS.py +++ b/HEMS.py @@ -16,16 +16,16 @@ from pyomo.core import value, RangeSet # data = pd.ExcelFile('input_new_cluster.xlsx') #it will read the excel one time you do not need to read again and gain # Parse the different tab -sheet_data = pd.read_excel("input_new_cluster_trying.xlsx", sheet_name='data') -sheet_EV = pd.read_excel("input_new_cluster_trying.xlsx", sheet_name='EV') -sheet_EWH = pd.read_excel("input_new_cluster_trying.xlsx", sheet_name='EWH') -sheet_wateruse = pd.read_excel("input_new_cluster_trying.xlsx", sheet_name='Water_Use') -sheet_watertemp = pd.read_excel("input_new_cluster_trying.xlsx", sheet_name='Water_Temp') -sheet_home = pd.read_excel("input_new_cluster_trying.xlsx", sheet_name='Home') -sheet_ESS = pd.read_excel("input_new_cluster_trying.xlsx", sheet_name='ESS') -sheet_PV = pd.read_excel("input_new_cluster_trying.xlsx", sheet_name='PV') -sheet_ambient = pd.read_excel("input_new_cluster_trying.xlsx", sheet_name='Ambient_Temp') -sheet_load = pd.read_excel("input_new_cluster_trying.xlsx", sheet_name='Base_Load') +sheet_data = pd.read_excel("input_new_cluster.xlsx", sheet_name='data') +sheet_EV = pd.read_excel("input_new_cluster.xlsx", sheet_name='EV') +sheet_EWH = pd.read_excel("input_new_cluster.xlsx", sheet_name='EWH') +sheet_wateruse = pd.read_excel("input_new_cluster.xlsx", sheet_name='Water_Use') +sheet_watertemp = pd.read_excel("input_new_cluster.xlsx", sheet_name='Water_Temp') +sheet_home = pd.read_excel("input_new_cluster.xlsx", sheet_name='Home') +sheet_ESS = pd.read_excel("input_new_cluster.xlsx", sheet_name='ESS') +sheet_PV = pd.read_excel("input_new_cluster.xlsx", sheet_name='PV') +sheet_ambient = pd.read_excel("input_new_cluster.xlsx", sheet_name='Ambient_Temp') +sheet_load = pd.read_excel("input_new_cluster.xlsx", sheet_name='Base_Load') # # @@ -860,59 +860,60 @@ for i in model.Sell_price: # plt.show() # code for if you want to plot all the home togathoer -fig, ax = plt.subplots(8, len(model.h), figsize=(10,10)) -for k in range(len(model.h)): - ax[0, k].plot(time, pbuy[k], label='Buying power') - ax[0, k].plot(time, psell[k], label='Selling power') - ax[0, k].plot(time, baseload[k], label='Base load') - ax[0, k].legend(loc='best') - ax[1, k].plot(time, Buyprice, label='Buyprice') - ax[1, k].legend(loc='best') - ax[1, k].plot(time, Sellprice, label='Sellprice') - ax[1, k].legend(loc='best') - ax[2, k].plot(time, PEWH[k], label='EWH Power') - ax[2, k].plot(time, tettaEWHwat[k], label='EWH Temp') - ax[2, k].legend(loc='best') - ax[3, k].plot(time, PESSCharge[k],label='ESS Charging power') - ax[3, k].plot(time, PESSDischHome[k], label='ESS Disch to home') - ax[3, k].plot(time, PESSDischGrid[k], label='ESS Disch to grid') - ax[3, k].legend(loc='best') - ax[4, k].plot(time, PVHome[k], label='PV to Home') - ax[4, k].plot(time, PVGrid[k], label='PV to Grid') - ax[4, k].plot(time, PPV[k], label='All PV Production') - ax[4, k].legend(loc='best') - ax[5, k].plot(time, PEVCharge[k], label='EV Charging power') - ax[5, k].plot(time, PEVDischHome[k], label='EV Disch to home') - ax[5, k].plot(time, PEVDischGrid[k], label='EV Disch to grid') - ax[5, k].legend(loc='best') - ax[6, k].plot(time, EnergyESS[k], label='Energy of ESS') - ax[6, k].legend(loc='best') - ax[7, k].plot(time, EnergyEV[k], label='Energy of EV') - ax[7, k].legend(loc='best') - ax[4, k].set_xlabel('Time (step)') - ax[1, k].set_ylabel('Electricity price ($/W/h)') - ax[0, k].set_ylabel('Power (kW)') - ax[2, k].set_ylabel('Power (kW)') - ax[0, k].set_title(f"Home {k+1}") - -pl.tight_layout() - -plt.show() +# fig, ax = plt.subplots(6, len(model.h), figsize=(10,10)) +# for k in range(len(model.h)): +# ax[0, k].plot(time, pbuy[k], label='Buying power') +# ax[0, k].plot(time, psell[k], label='Selling power') +# # ax[0, k].plot(time, baseload[k], label='Base load') +# ax[0, 0].legend(loc='best') +# ax[1, k].plot(time, Buyprice, label='Buyprice') +# ax[1, 0].legend(loc='best') +# ax[1, k].plot(time, Sellprice, label='Sellprice') +# ax[1, 0].legend(loc='best') +# ax[2, k].plot(time, PEWH[k], label='EWH Power') +# ax[2, k].plot(time, tettaEWHwat[k], label='EWH Temp') +# ax[2, 0].legend(loc='best') +# ax[3, k].plot(time, PESSCharge[k],label='ESS Charging power') +# ax[3, k].plot(time, PESSDischHome[k], label='ESS Disch to home') +# ax[3, k].plot(time, PESSDischGrid[k], label='ESS Disch to grid') +# ax[3, 0].legend(loc='best') +# ax[4, k].plot(time, PVHome[k], label='PV to Home') +# ax[4, k].plot(time, PVGrid[k], label='PV to Grid') +# ax[4, k].plot(time, PPV[k], label='All PV Production') +# ax[4, 0].legend(loc='best') +# ax[5, k].plot(time, PEVCharge[k], label='EV Charging power') +# ax[5, k].plot(time, PEVDischHome[k], label='EV Disch to home') +# ax[5, k].plot(time, PEVDischGrid[k], label='EV Disch to grid') +# ax[5, 0].legend(loc='best') +# # ax[6, k].plot(time, EnergyESS[k], label='Energy of ESS') +# # ax[6, k].legend(loc='best') +# # ax[7, k].plot(time, EnergyEV[k], label='Energy of EV') +# # ax[7, 0].legend(loc='best') +# ax[4, 5].set_xlabel('Time (step)') +# ax[1, 0].set_ylabel('Electricity price ($/W/h)') +# ax[0, 0].set_ylabel('Power (kW)') +# ax[2,0].set_ylabel('Power (kW)') +# ax[0, k].set_title(f"Home {k+1}") +# +# # pl.tight_layout() +# +# plt.show() # if you want to plot each home alone in the figure -# for k in range(len(model.h)): -# fig, ax = plt.subplots(2) -# ax[0].plot(time, pbuy[k], 'b-', label='Base') -# ax[0].plot(time, psell[k], 'g--', label='Controllable Load') -# ax[1].plot(time, Buyprice, label='buying price') -# ax[1].plot(time, Sellprice, 'y-+', label='selling price') -# ax[1].legend(loc='upper left') -# ax[1].set_xlabel('Time (hour)') -# ax[1].set_ylabel('Electricity price ($/W/h)') -# plt.suptitle(f"Home {k+1}") -# pl.tight_layout() -# plt.show() +bar_width =0.4 +time1 = np.array(time) +for k in range(len(model.h)): + fig, ax = plt.subplots(2,constrained_layout=True, ) + ax[0].bar(time1 - bar_width/2 , pbuy[k], width=bar_width, label='Base') + ax[0].bar(time1 + bar_width/2 , psell[k], width=bar_width, label='Controllable Load') + ax[1].plot(time, Buyprice, label='buying price') + ax[1].plot(time, Sellprice, 'y-+', label='selling price') + ax[1].legend(loc='upper left') + ax[1].set_xlabel('Time (hour)') + ax[1].set_ylabel('Electricity price ($/W/h)') + plt.suptitle(f"Home {k+1}") + plt.show() # print('this is the end of code')