Select Git revision
command_parser.cpp
Plots.py 18.92 KiB
import datetime
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as md
from matplotlib.ticker import MaxNLocator
import matplotlib as mp
# bar plot of sample data in single component
'''
xList = list()
kNum = len(dict_comp.keys())
X_axis = np.arange(5)
barWidth = 0.1
for i in range(6):
xLabel = list(dict_comp.keys())[i]
xList.append(dict_comp[xLabel].index[i]) # index attribute also for series usable
yDF = dict_comp[xLabel]
yValue = yDF[0:5]
# xLabel = list(dict_comp.keys())[i]
plt.bar(X_axis + (i - 2) * barWidth, yValue, barWidth, label=xLabel) # Todo: change x-coordinate
# plt.set_xticks(X_axis)
plt.xticks(X_axis, xList[0:5]) # !!!!!!
plt.xlabel('Betriebskomponente/Messstelle')
plt.ylabel('ele_demand in kWh')
plt.legend()
plt.show()
# plt.savefig('figur1.png')'''
def Barplotting_group(path):
df = pd.read_excel(path, index_col=0) #, header=0
values = df.iloc[0] #pd.series
dmd1 = values['elec_demand']
dmd2 = values['therm_demand']
sup1 = values["('grd', 'elec_cns')"]
sup2 = values["('gas_boi', 'therm_cns')"]
X_axis = ["elec_demand","('grd', 'elec_cns')" ,"therm_dmd", "('gas_boi', 'therm_cns')" ]
y = [dmd1, sup1, dmd2, sup2]
labels = ['elec_demand', 'therm_dmd']
y1 = [dmd1 ,dmd2]
y2 = [sup1 ,sup2]
x = np.arange(len(labels)) ## the label locations
width = 0.35
fig, ax = plt.subplots()
rects1 = ax.bar(x - width/2, y1, width, label='demand') #(0-0.1) (1-0.1)
rects2 = ax.bar(x + width/2, y2, width, label='supplier') #(0+0.1) (1+0.1)
ax.set_ylabel('Energy in kWh')
ax.set_title('Energy demand at 2019/6/1 0:00:00')
ax.set_xticks(x, ['electricity', 'heat']) #matplotlib version >= 3.4
ax.legend(loc = 'upper left')
ax.bar_label(rects1, labels=["elec_demand","therm_dmd"])
ax.bar_label(rects2, labels=["('grd', 'elec_cns')","('gas_boi', 'therm_cns')"])
fig.tight_layout()
plt.show()
def plots():
X_axis = ["2021-01", "2021-07", "2021-09", "2021-12", "2022-01", "2022-05", "2022-07"]
y_val = [6969, 8851, 17411, 24097, 38194, 38212, 38250]
y_val2 = [13.62, 15.66, 12.92, 11.79, 13.34, 12.94, 15.31]
y_val3 = [15.33, 17.90, 15.13, 14.62, 15.05, 15.05, 17.56]
x = np.arange(len(X_axis))
width = 0.3
fig, ax = plt.subplots()
#ax.grid(True)
f1 = ax.bar(x - width, y_val, width, color=[0.1686, 0.3098, 0.5059], label='Arbitrage profit') #
#f2 = ax.bar(x + width / 2, y_val2, width, color=[0.251, 0.498, 0.7176], label='Arbitrage profit'))
# f3 = ax.bar(x + width / 2, y_val2, width, color=[0.251, 0.498, 0.7176])
ax2 = ax.twinx()
f2 = ax2.bar(x, y_val2, width, color=[0.251, 0.498, 0.7176], label='Electric price without investment')
f3 = ax2.bar(x + width, y_val3, width, color=[0.7804, 0.8667, 0.949], label='Electric price with investment')#
ax.set_ylabel('mothly arbitrage profit in €', fontsize = 14)
ax.yaxis.set_major_formatter(mp.ticker.StrMethodFormatter('{x:,.0f}'))
ax2.set_ylabel('Electric price in Cent/kWh ', fontsize = 14)
ax.set_title('Trend of Arbitrage profit and electric price', fontsize = 16)
ax.set_xticks(x,X_axis)
ax.legend(loc = 'upper left')
ax2.legend() #loc = (0.005, 0.85)
ax.bar_label(f1, labels=y_val) #, padding=3
ax2.bar_label(f2, labels=y_val2)
ax2.bar_label(f3, labels=y_val3)
fig.tight_layout()
plt.show()
def Barplots():
#X_axis = ['2019','2020','2021']
#X_axis = ['10% - 90%','15% - 85%','20% - 80%']
X_axis = ['1000kWh','5000kWh','10000kWh']
y_values = [3724.576/1000, 18622.882/5000, 37245.765/10000]
width = 0.5
fig, ax = plt.subplots()
f1 = ax.bar(X_axis, y_values, width, color=['tab:blue','tab:blue', 'tab:orange', 'tab:orange'])
ax.set_ylabel('annual arbitrage resulted cost in €/kWh')
ax.set_title('2021 Arbitrage results per kWh of LiionBatteryStack')
ax.legend()
ax.bar_label(f1) #, padding=3
plt.show()
def Barplotting0(path):
df = pd.read_excel(path, index_col=0) # , header=0
values = df.iloc[0] # pd.series
dmd1 = values['elec_demand']
dmd2 = values['therm_demand']
sup1 = values["('grd', 'elec_cns')"]
sup2 = values["('gas_boi', 'therm_cns')"]
X_axis = ["elec_demand", "('grd', 'elec_cns')", "therm_dmd", "('gas_boi', 'therm_cns')"]
y = [dmd1, sup1, dmd2, sup2]
fig, ax = plt.subplots()
f1 = ax.bar(X_axis, y, color=['tab:blue','tab:blue', 'tab:orange', 'tab:orange'])
ax.set_ylabel('Energy in kWh')
ax.set_title('Energy demand on 2019/6/1 0:00:00')
#ax.legend()
ax.bar_label(f1)
plt.show()
def plotting_BAS1(path):
df = pd.read_excel(path, index_col=0)
t_start = df.index[0]
t_end = df.index[-1]
t_step = df.index[1] - df.index[0]
# sig = df.loc[:, "('z_ArbSignal', 'batterySta')"]
# sig_in = df["('z_Bat_In_Signal', 'batterySta')"]
# sig_out = df["('z_Bat_Out_Signal', 'batterySta')"]
bhkw_inv = df["('bhkw', 'inv_bat')"]
grd_inv = df["('grd', 'inv_bat')"]
E_bat_St = df["('energy_Bat_St', 'batterySta')"]
E_bat_Arb = df["('energy_Bat_Arb', 'batterySta')"]
#e_to_elec = df["('inv_bat', 'elec_cns')"]
E_bat_all = df["('energy', 'batterySta')"]
t = np.arange(t_start - t_step, t_end, t_step)
# Two signals with a coherent part at 10Hz and a random part
#s1 = sig_in
#s2 = sig_out
s1 = bhkw_inv
s2 = grd_inv
e1 = E_bat_St
e2 = E_bat_Arb
e3 = E_bat_all
# subplot in the 1. row
fig, axs = plt.subplots(2, 1)# 2 rows, 1 column
# axs[0].plot(t, s1, label ='input Signals')
# axs[0].set_ylabel('sig_input, sig_output')
#axs[0].plot(t, s1, label ='input Signals')
#axs[0].plot(t, s2, label ='output Signals')
# axs[0].set_ylabel('sig_input, sig_output')
# axs[0].grid(True)
# axs2 = axs[0].twinx() # twin object for two different y-axis on the sample plot
# axs2.plot(t, e2, color = 'red', label='battery energy part for Arbitrage')
# axs2.set_ylabel('battery energy part for Arbitrage')
# axs2.fill_between(t,e2, facecolor='red', alpha=0.1)
# axs2.legend()
axs[0].legend()
#subplot in the 2. row
# axs[1].plot(t, e1, label = 'battery energy part for Storage')
# axs[1].plot(t, e2, label = 'battery energy part for Arbitrage')
axs[1].plot(t, e3, label = 'total battery energy')
axs[1].legend()
#cxy, f = axs[1].cohere(s1, s2, 256, 1. / dt)
axs[1].set_ylabel('energy of battery')
axs[1].set_xlabel('timestamps')
# set datetime format for x axis
axs = plt.gca()
xfmt = md.DateFormatter('%Y-%m-%d')#\%H:%M:%S
axs.xaxis.set_major_formatter(xfmt)
plt.xticks(rotation = 25)
fig.tight_layout()
plt.show()
def plotting_BAS1_2(path):
df = pd.read_excel(path, index_col=0)
t_start = df.index[0]
t_end = df.index[-1]
t_step = df.index[1] - df.index[0]
# sig = df.loc[:, "('z_ArbSignal', 'batterySta')"]
# sig_in = df["('z_Bat_In_Signal', 'batterySta')"]
# sig_out = df["('z_Bat_Out_Signal', 'batterySta')"]
bhkw_inv = df["('bhkw', 'inv_bat')"]
grd_inv = df["('grd', 'inv_bat')"]
pv_inv = df["('inv_pv', 'inv_bat')"]
E_bat_St = df["('energy_Bat_St', 'batterySta')"]
E_bat_Arb = df["('energy_Bat_Arb', 'batterySta')"]
# e_to_elec = df["('inv_bat', 'elec_cns')"]
E_bat_all = df["('energy', 'batterySta')"]
t = np.arange(t_start - t_step, t_end, t_step)
# Two signals with a coherent part at 10Hz and a random part
# s1 = sig_in
# s2 = sig_out
s1 = bhkw_inv
s2 = grd_inv
s3 = pv_inv
e1 = E_bat_St
e2 = E_bat_Arb
e3 = E_bat_all
# subplot in the 1. subplot
fig, axs = plt.subplots(3, 1) # 2 rows, 1 column
l1 = axs[0].plot(t, s1, label='bhkw to inv_bat')
axs[0].set_ylabel('Power flow from elec supplier to inv_bat in kW')
#axs0_2 = axs[0].twinx() # twin object for two different y-axis on the sample plot
l2 = axs[0].plot(t, s2, color = 'green', label='grd to inv_bat')
lpv = axs[0].plot(t, s3, color = 'orange', label='PV to inv_bat')
#axs0_2.set_ylabel ('Power flow from grid to inv_bat in kW')
# axs0_2.fill_between(t,e3, facecolor='red', alpha=0.1)
# added legends
# lns = l1 + l2
# labs = [l.get_label() for l in lns]
# plt.legend(lns, labs, loc= 0 ) # loc =(0, 0.2), bbox_to_anchor=
# subplot in the 2. subplot
l3 = axs[1].plot(t, e1, label='Battery energy part for Storage')
axs[1].set_ylabel('Stored Energy in kWh')
#axs1_2 = axs[1].twinx()
l4 = axs[1].plot(t, e2, color='orange', label='Battery energy part for Arbitrage')
l5 = axs[2].plot(t, e3, color='red', label='Total energy in LiionbatteryStack')
axs[2].fill_between(t, e3, facecolor='red', alpha=0.1)
axs[1].set_ylabel('Stored Energy in kWh')
# added legends
# lns2 = l3 + l4
# labs2 = [l.get_label() for l in lns2]
# plt.legend(lns2, labs2, loc=0)
# set datetime format for x axis
for ax in axs:
ax.xaxis.set_major_formatter(md.DateFormatter('%Y-%m-%d'))# \%H:%M:%S
ax.set_xlabel('Time')
ax.legend(loc = 'upper left')
# for label in ax.get_xticklabels(which='major'):
# label.set(rotation=30)
fig.tight_layout()
plt.show()
def plotting_BAS0(path):
df = pd.read_excel(path, index_col=0)
df.index = pd.to_datetime(df.index)
# df = df.loc[datetime.datetime(2021,7,1,0,0,0) : datetime.datetime(2021,7,31,0,0,0)]
t_start = df.index[0]
t_end = df.index[-1]
t_step = df.index[1] - df.index[0]
# sig_in = df["('z_Bat_In_Signal', 'batterySta')"]
# sig_out = df["('z_Bat_Out_Signal', 'batterySta')"]
sig_all = df["('z_ArbSignal', 'batterySta')"]
price_pf = df['Abitrage_elec_price']
E_bat_all = df["('energy', 'batterySta')"]
t = np.arange(t_start - t_step, t_end, t_step)
# Two signals with a coherent part at 10Hz and a random part
s1 = sig_all
s2 = price_pf
e3 = E_bat_all
# subplot in the 1. subplot
fig, axs = plt.subplots(2, 1) # 2 rows, 1 colu mn
l1 = axs[0].plot(t, s1, label='Signals for charging[1] and discharging[-1]') #input Signals
#axs[0].plot(t, s2, label='Intraday price') #output Signals
axs[0].set_ylabel('Charging/Discharging Signals') #sig_input, sig_output
#axs[0].grid(True)
axs[0].legend(loc='upper left')
axs[0].yaxis.set_major_locator(MaxNLocator(integer=True))
# axs0_2 = axs[0].twinx() # twin object for two different y-axis on the sample plot
# l2 = axs0_2.plot(t, e3, color = 'red', label='Energy of LiionBattery Stack') #battery energy part for Arbitrage
# axs0_2.set_ylabel('Stored Energy in kWh') #battery energy part for Arbitrage
# axs0_2.fill_between(t,e3, facecolor='red', alpha=0.1)
# added legends
# lns = l1 + l2
# labs = [l.get_label() for l in lns]
# plt.legend(lns, labs, loc=(0, 0.2) ) # bbox_to_anchor=
# subplot in the 2. subplot
# axs[1].plot(t, e1, label = 'battery energy part for Storage')
# axs[1].plot(t, e2, label = 'battery energy part for Arbitrage')
l3 = axs[1].plot(t, e3, label='stored Energy in LiionBattery Stack')
axs[1].fill_between(t, e3, facecolor='green', alpha=0.1)
axs[1].set_ylabel('Stored Energy in kWh')
axs[1].set_xlabel('Time')
#axs[1].grid(True)
axs1_2 = axs[1].twinx()
l4 = axs1_2.plot(t, s2, color = 'red', label='Intraday price')
axs1_2.set_ylabel('Intraday price in €/kWh')
# added legends
lns2 = l3 + l4
labs2 = [l.get_label() for l in lns2]
plt.legend(lns2, labs2, loc='upper left')
# set datetime format for x axis
for ax in axs:
ax.xaxis.set_major_formatter(md.DateFormatter('%Y-%m-%d'))# \%H:%M:%S
ax.grid(True)
for label in ax.get_xticklabels(which='major'):
label.set(rotation=30)
fig.tight_layout()
plt.show()
def Subplots_3(path, titles):
fig, axs = plt.subplots(3, 1)
# axs[0] # P=1000kWh
# axs[1] # P=5000kWh
# axs[2]# P=10000kWh
for i in range(len(path)):
df = pd.read_excel(path[i], index_col=0)
t_start = df.index[0]
t_end = df.index[-1]
t_step = df.index[1] - df.index[0]
# sig_in = df["('z_Bat_In_Signal', 'batterySta')"]
# sig_out = df["('z_Bat_Out_Signal', 'batterySta')"]
#sig_all = df["('z_ArbSignal', 'batterySta')"]
price_pf = df['Abitrage_elec_price']
E_bat_all = df["('energy', 'batterySta')"]
t = np.arange(t_start - t_step, t_end, t_step)
# Two signals with a coherent part at 10Hz and a random part
#s1 = sig_all
s2 = price_pf
e3 = E_bat_all
# l1 = axs[i].plot(t, s1, label='Signals for charging[1] and discharging[-1]')
# axs[i].set_ylabel('Charging/Discharging Signals')
# axs[i].yaxis.set_major_locator(MaxNLocator(integer=True))
# axs[i].set_title(titles[i])
# axs[i].legend()
l1 = axs[i].plot(t, s2, color = 'orange', label='Intraday price')
axs[i].set_ylabel('Intraday price in €/kWh')
axs_2 = axs[i].twinx()
l2 = axs_2.plot(t, e3, color = 'red', label='Stored Energy in LiionBatteryStack') #
axs_2.fill_between(t, e3, facecolor='red', alpha=0.1)
axs_2.set_ylabel('Stored Energy in kWh')
axs[i].set_xlabel('Time')
axs[i].grid(True)
lns = l1 + l2
labs = [l.get_label() for l in lns]
plt.legend(lns, labs, title = titles[i], loc='upper left') #
fig.tight_layout()
plt.show()
def stackedBarplot(path):
df = pd.read_excel(path, index_col=0)
alist=[]
olist = []
anu = dict()
oper = dict()
#total annual or monthly cost
# annual cost
# operating cost
# arbitrage profit
col_list = df.columns
for i in range(len(col_list)):
if "('annual_cost'," in col_list[i]:
alist.append(col_list[i])
elif 'operating_cost' in col_list[i]:
olist.append(col_list[i])
tot_cst = df["total_annual_costs"].iloc[0]
arb = df["('arbitrage_cost', 'batterySta')"].iloc[-1]
for i in range(len(alist)):
if df[alist[i]].iloc[0] != 0:
anu[alist[i]] = df[alist[i]].iloc[0]
for y in range(len(olist)):
oper[olist[y]] = df[olist[y]].sum()
# anu1 = df["('annual_cost', 'inv_bat')"].iloc[0]
# anu2 = df["('annual_cost', 'batterySta')"].iloc[0]
# oper1 = df["('operating_cost', 'grd')"].sum()
# oper2 = df["('operating_cost', 'gas_grd')"].sum()
labs = ['total cost', 'fixed cost', 'operation cost', 'arbitrage profit']
ind = np.arange(len(labs))
anu = anu
oper = oper
arb = -arb
width = 0.35 # the width of the bars: can also be len(x) sequence
#bot = 0
#bot += list(anu.values())[i]
fig, ax = plt.subplots()
ax.bar(ind[0], tot_cst, width, label = 'total cost' ) #p1 =
ax.bar(ind[3], arb, width, color=[0.8, 0.0275, 0.1176], label='arbitrage profit') # 'brown' p6 =
anu_vlist = list(anu.values())
for i in range(len(anu_vlist)):
if i ==0:
ax.bar(ind[1], anu_vlist[i], width, label=list(anu.keys())[i]) #, color=[0.9922, 0.8314, 0.5608]
else:
ax.bar(ind[1], anu_vlist[i], width, bottom=anu_vlist[i-1], label=list(anu.keys())[i])
oper_vlist = list(oper.values())
for i in range(len(oper_vlist)):
if i ==0:
ax.bar(ind[2], oper_vlist[i], width, label=list(oper.keys())[i]) #, color=[0.9922, 0.8314, 0.5608]
else:
ax.bar(ind[2], oper_vlist[i], width, bottom=oper_vlist[i-1], label=list(oper.keys())[i])
# p2 = ax.bar(ind[1], anu[0], width, color = [0.9922, 0.8314, 0.5608], label = 'annual_cost of inv_bat' )
# p3 = ax.bar(ind[1], anu[1], width, bottom =anu[0], color = 'orange' , label='annual_cost of batterySta')
# p4 = ax.bar(ind[2], oper[0], width, color = 'green', label='operation cost of grd')
# p5 = ax.bar(ind[2], oper[1], width, color =[0.7216, 0.8392, 0.5961], bottom=oper[0], label='operation cost of gas grd')
ax.axhline(0, color='grey', linewidth=0.8)
ax.set_ylabel('cost in €')
ax.set_title('Distribution of costs')
ax.set_xticks(ind, labels=labs)
ax.legend()
ax.grid(True)
con = ax.containers
for x in range(len(con)):
ax.bar_label(con[x], label_type='center')
# ax.bar_label(p6, label_type='edge')
# ax.bar_label(p2, label_type='center')
# ax.bar_label(p3, label_type='center')
# ax.bar_label(p3)
# ax.bar_label(p4, label_type='center')
# ax.bar_label(p5, label_type='center')
# ax.bar_label(p5)
# ax.bar_label(p6, label_type='edge')
plt.show()
if __name__ == "__main__":
#path = r'C:\Users\10947\sciebo\Scenarios_home\Output_files\SCN1_SG_BHKW_mode2\results_SCN1_SG_BHKW_mode2.xlsx'
#path = r'C:\Users\10947\sciebo\Scenarios_home\Output_files_old\SCN5_SGSD_BAS1_PV\results_SCN1_SGSD_BAS1_ARB_PV.xlsx'
# path = r'C:\Users\10947\sciebo\Scenarios_v3\Output_files\SCN0_BAS0_1000\results_SCN0_BAS0_1000.xlsx'
# # plotting_BAS1_2(path)
# plotting_BAS0(path)
# path1 = r'C:\Users\10947\sciebo\Scenarios_v3\Outputfiles\SCN0_BAS0_10000_10_90\results_SCN0_BAS0_10000.xlsx'
# path2 = r'C:\Users\10947\sciebo\Scenarios_v3\Outputfiles\SCN0_BAS0_10000_15_85\results_SCN0_BAS0_10000.xlsx'
# path3 = r'C:\Users\10947\sciebo\Scenarios_v3\Outputfiles\SCN0_BAS0_10000_20_80\results_SCN0_BAS0_10000.xlsx'
# path_lst = [path1, path2, path3]
# titles = ["price limits: 10% - 90%", "price limits: 15% - 85%", "price limits: 20% - 80%"]
# path3 = r'C:\Users\10947\sciebo\Scenarios_end\Output_files\SCN0_BAS0_1000\results_SCN0_BAS0_1000.xlsx'
# path2 = r'C:\Users\10947\sciebo\Scenarios_end\Output_files\SCN0_BAS0_1000_2020_1000euro\results_SCN0_BAS0_1000_2020.xlsx'
# path1 = r'C:\Users\10947\sciebo\Scenarios_end\Output_files\SCN0_BAS0_1000_2019\results_SCN0_BAS0_1000_2019.xlsx'
# path_lst = [path1, path2, path3]
# titles = ["2019", "2020", "2021"]
# titles = ["1000kWh", "5000kWh", "10000kWh"]
# Subplots_3(path_lst, titles)
#Barplots()
plots()
#path = r'C:\Users\10947\sciebo\Scenarios_v3\Outputfiles\Jan\SCN2_SG_BAS1_BHKW\results_SCN2_SG_BAS1_BHKW.xlsx'
# path = r'C:\Users\10947\sciebo\Scenarios_v3\Outputfiles\July\SCN2_SG_BAS1_BHKW_6_8\results_SCN2_SG_BAS1_BHKW_6_8.xlsx'
#path = r'C:\Users\10947\sciebo\Scenarios_v3\Outputfiles\Jan\SCN3_SG_BAS1_BHKW_PV10MW\results_SCN3_SG_BAS1_BHKW_PV10MW.xlsx'
#path = r'C:\Users\10947\sciebo\Scenarios_v3\Outputfiles\July\SCN3_SG_BAS1_BHKW_PV10MW_6_8\results_SCN3_SG_BAS1_BHKW_PV10MW_6_8.xlsx'
#path = r'C:\Users\10947\sciebo\Scenarios_v3\Outputfiles\July\SCN3_SG_BAS1_BHKW_PV15MW_6_8\results_SCN3_SG_BAS1_BHKW_PV15MW_6_8.xlsx'
#path = r'C:\Users\10947\sciebo\Scenarios_v3\Outputfiles\Jan\SCN3_SG_BAS1_BHKW_PV15MW\results_SCN3_SG_BAS1_BHKW_PV15MW.xlsx'
#path = r'C:\Users\10947\sciebo\Scenarios_v3\Outputfiles\Jan\SCN4_SG_BAS1_BHKW_PV_2030\results_SCN4_SG_BAS1_BHKW_PV_2030.xlsx'
#path = r'C:\Users\10947\sciebo\Scenarios_v3\Outputfiles\Jan\SCN1_SG_BHKW\results_SCN1_SG_BHKW.xlsx'
#path = r'C:\Users\10947\sciebo\Scenarios_v3\Outputfiles\July\SCN1_SG_BHKW_6_8\results_SCN1_SG_BHKW_6_8.xlsx'
#stackedBarplot(path)
a = 1