Spaces:
Sleeping
Sleeping
Daniel Varga
commited on
Commit
·
ababe23
1
Parent(s):
7f927c0
vis
Browse files- v2/architecture.py +12 -4
- v2/visualization.py +158 -0
v2/architecture.py
CHANGED
|
@@ -10,7 +10,7 @@ from supplier import Supplier, precalculate_supplier
|
|
| 10 |
from data_processing import read_datasets, add_production_field, interpolate_and_join, SolarParameters
|
| 11 |
from bess import BatteryModel
|
| 12 |
from evolution_strategies import evolution_strategies_optimizer
|
| 13 |
-
|
| 14 |
|
| 15 |
DO_VIS = False
|
| 16 |
|
|
@@ -211,8 +211,8 @@ def simulator(battery_model, prod_cons, decider):
|
|
| 211 |
|
| 212 |
|
| 213 |
def optimizer(decider_class, battery_model, all_data_with_predictions, precalculated_supplier):
|
| 214 |
-
number_of_generations =
|
| 215 |
-
population_size =
|
| 216 |
collected_loss_values = []
|
| 217 |
def objective_function(params):
|
| 218 |
print("Simulating with parameters", params)
|
|
@@ -285,7 +285,7 @@ def main():
|
|
| 285 |
time_interval_h = time_interval_min / 60
|
| 286 |
|
| 287 |
# for faster testing:
|
| 288 |
-
DATASET_TRUNCATED_SIZE =
|
| 289 |
if DATASET_TRUNCATED_SIZE is not None:
|
| 290 |
print("Truncating dataset to", DATASET_TRUNCATED_SIZE, "datapoints, that is", DATASET_TRUNCATED_SIZE * time_interval_h / 24, "days")
|
| 291 |
all_data = all_data.iloc[:DATASET_TRUNCATED_SIZE]
|
|
@@ -326,5 +326,13 @@ def main():
|
|
| 326 |
decider = decider_class(best_params, precalculated_supplier)
|
| 327 |
results, total_network_fee = simulator(battery_model, all_data_with_predictions, decider)
|
| 328 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 329 |
if __name__ == '__main__':
|
| 330 |
main()
|
|
|
|
| 10 |
from data_processing import read_datasets, add_production_field, interpolate_and_join, SolarParameters
|
| 11 |
from bess import BatteryModel
|
| 12 |
from evolution_strategies import evolution_strategies_optimizer
|
| 13 |
+
from visualization import plotly_visualize_simulation, plotly_visualize_monthly
|
| 14 |
|
| 15 |
DO_VIS = False
|
| 16 |
|
|
|
|
| 211 |
|
| 212 |
|
| 213 |
def optimizer(decider_class, battery_model, all_data_with_predictions, precalculated_supplier):
|
| 214 |
+
number_of_generations = 1
|
| 215 |
+
population_size = 10
|
| 216 |
collected_loss_values = []
|
| 217 |
def objective_function(params):
|
| 218 |
print("Simulating with parameters", params)
|
|
|
|
| 285 |
time_interval_h = time_interval_min / 60
|
| 286 |
|
| 287 |
# for faster testing:
|
| 288 |
+
DATASET_TRUNCATED_SIZE = None
|
| 289 |
if DATASET_TRUNCATED_SIZE is not None:
|
| 290 |
print("Truncating dataset to", DATASET_TRUNCATED_SIZE, "datapoints, that is", DATASET_TRUNCATED_SIZE * time_interval_h / 24, "days")
|
| 291 |
all_data = all_data.iloc[:DATASET_TRUNCATED_SIZE]
|
|
|
|
| 326 |
decider = decider_class(best_params, precalculated_supplier)
|
| 327 |
results, total_network_fee = simulator(battery_model, all_data_with_predictions, decider)
|
| 328 |
|
| 329 |
+
date_range = ("2021-01-01", "2021-02-01")
|
| 330 |
+
date_range = ("2021-07-01", "2021-08-01")
|
| 331 |
+
plotly_fig = plotly_visualize_simulation(results, date_range=date_range)
|
| 332 |
+
plotly_fig.show()
|
| 333 |
+
|
| 334 |
+
plotly_fig_2 = plotly_visualize_monthly(results)
|
| 335 |
+
plotly_fig_2.show()
|
| 336 |
+
|
| 337 |
if __name__ == '__main__':
|
| 338 |
main()
|
v2/visualization.py
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import plotly
|
| 2 |
+
import plotly.subplots
|
| 3 |
+
import plotly.express as px
|
| 4 |
+
import plotly.graph_objects as go
|
| 5 |
+
|
| 6 |
+
import matplotlib.pyplot as plt
|
| 7 |
+
|
| 8 |
+
import data_processing
|
| 9 |
+
|
| 10 |
+
def visualize_simulation(results, date_range):
|
| 11 |
+
start_date, end_date = date_range
|
| 12 |
+
|
| 13 |
+
fig = plt.figure()
|
| 14 |
+
results = results.loc[start_date: end_date]
|
| 15 |
+
|
| 16 |
+
x = results.index
|
| 17 |
+
y = [results.consumption_from_solar, results.consumption_from_network, results.consumption_from_bess]
|
| 18 |
+
plt.plot(x, y[0], label='Demand served by solar', color='yellow', linewidth=0.5)
|
| 19 |
+
plt.plot(x, y[0]+y[1], label='Demand served by network', color='blue', linewidth=0.5)
|
| 20 |
+
plt.plot(x, y[0]+y[1]+y[2], label='Demand served by BESS', color='green', linewidth=0.5)
|
| 21 |
+
plt.fill_between(x, y[0]+y[1]+y[2], 0, color='green')
|
| 22 |
+
plt.fill_between(x, y[0]+y[1], 0, color='blue')
|
| 23 |
+
plt.fill_between(x, y[0], 0, color='yellow')
|
| 24 |
+
|
| 25 |
+
# plt.xlim(datetime.datetime.fromisoformat(start_date), datetime.datetime.fromisoformat(end_date))
|
| 26 |
+
|
| 27 |
+
plt.legend()
|
| 28 |
+
return fig
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
MARGIN = dict(
|
| 32 |
+
l=0,
|
| 33 |
+
r=0,
|
| 34 |
+
b=0,
|
| 35 |
+
t=0,
|
| 36 |
+
pad=0
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def plotly_visualize_simulation(results, date_range):
|
| 41 |
+
start_date, end_date = date_range
|
| 42 |
+
results = results.loc[start_date: end_date]
|
| 43 |
+
'''
|
| 44 |
+
fig = px.area(results, x=results.index, y="consumption_from_network")
|
| 45 |
+
return fig'''
|
| 46 |
+
|
| 47 |
+
fig = plotly.subplots.make_subplots(specs=[[{"secondary_y": True}]])
|
| 48 |
+
fig.update_layout(yaxis2=dict(range=[0.0, 110]))
|
| 49 |
+
|
| 50 |
+
fig.add_trace(go.Scatter(
|
| 51 |
+
x=results.index, y=results['consumption_from_network'],
|
| 52 |
+
hoverinfo='x+y',
|
| 53 |
+
mode='lines',
|
| 54 |
+
line=dict(width=0.5, color='blue'),
|
| 55 |
+
name='Network',
|
| 56 |
+
stackgroup='one' # define stack group
|
| 57 |
+
))
|
| 58 |
+
fig.add_trace(go.Scatter(
|
| 59 |
+
x=results.index, y=results['consumption_from_solar'],
|
| 60 |
+
hoverinfo='x+y',
|
| 61 |
+
mode='lines',
|
| 62 |
+
line=dict(width=0.5, color='orange'),
|
| 63 |
+
name='Solar',
|
| 64 |
+
stackgroup='one'
|
| 65 |
+
))
|
| 66 |
+
fig.add_trace(go.Scatter(
|
| 67 |
+
x=results.index, y=results['consumption_from_bess'],
|
| 68 |
+
hoverinfo='x+y',
|
| 69 |
+
mode='lines',
|
| 70 |
+
line=dict(width=0.5, color='green'),
|
| 71 |
+
name='BESS',
|
| 72 |
+
stackgroup='one'
|
| 73 |
+
))
|
| 74 |
+
fig.add_trace(go.Scatter(
|
| 75 |
+
x=results.index, y=results['soc_series'] * 100,
|
| 76 |
+
hoverinfo='x+y',
|
| 77 |
+
mode='lines',
|
| 78 |
+
line=dict(width=1.5, color='red'),
|
| 79 |
+
name='State of charge'),
|
| 80 |
+
secondary_y=True
|
| 81 |
+
)
|
| 82 |
+
# could not kill the huge padding this introduces:
|
| 83 |
+
# fig.update_layout(title=f"Simulation for {start_date} - {end_date}")
|
| 84 |
+
fig.update_layout(height=400, yaxis_title="Consumption [kW]", yaxis2_title="State of charge [%]", yaxis2_showgrid=False)
|
| 85 |
+
|
| 86 |
+
return fig
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
def plotly_visualize_monthly(result):
|
| 90 |
+
consumption = data_processing.monthly_analysis(result)
|
| 91 |
+
# months = monthly_results.index
|
| 92 |
+
months = list(range(1, 13))
|
| 93 |
+
fig = go.Figure()
|
| 94 |
+
fig.add_trace(go.Scatter(
|
| 95 |
+
x=months, y=consumption[:, 0], # monthly_results['consumption_from_network'],
|
| 96 |
+
hoverinfo='x+y',
|
| 97 |
+
mode='lines',
|
| 98 |
+
line=dict(width=0.5, color='blue'),
|
| 99 |
+
name='Network',
|
| 100 |
+
stackgroup='one' # define stack group
|
| 101 |
+
))
|
| 102 |
+
fig.add_trace(go.Scatter(
|
| 103 |
+
x=months, y=consumption[:, 1], # y=monthly_results['consumption_from_solar'],
|
| 104 |
+
hoverinfo='x+y',
|
| 105 |
+
mode='lines',
|
| 106 |
+
line=dict(width=0.5, color='orange'),
|
| 107 |
+
name='Solar',
|
| 108 |
+
stackgroup='one'
|
| 109 |
+
))
|
| 110 |
+
fig.add_trace(go.Scatter(
|
| 111 |
+
x=months, y=consumption[:, 2], # y=monthly_results['consumption_from_bess'],
|
| 112 |
+
hoverinfo='x+y',
|
| 113 |
+
mode='lines',
|
| 114 |
+
line=dict(width=0.5, color='green'),
|
| 115 |
+
name='BESS',
|
| 116 |
+
stackgroup='one'
|
| 117 |
+
))
|
| 118 |
+
fig.update_layout(
|
| 119 |
+
yaxis_title="Monthly consumption in [MWh]",
|
| 120 |
+
height=400
|
| 121 |
+
)
|
| 122 |
+
return fig
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
def monthly_visualization(consumptions_in_mwh):
|
| 126 |
+
percentages = consumptions_in_mwh[:, :3] / consumptions_in_mwh.sum(axis=1, keepdims=True) * 100
|
| 127 |
+
bats = 0
|
| 128 |
+
nws = 0
|
| 129 |
+
sols = 0
|
| 130 |
+
|
| 131 |
+
print("[Mwh]")
|
| 132 |
+
print("==========================")
|
| 133 |
+
print("month\tnetwork\tsolar\tbess")
|
| 134 |
+
for month_minus_1 in range(12):
|
| 135 |
+
network, solar, bess = consumptions_in_mwh[month_minus_1]
|
| 136 |
+
print(f"{month_minus_1+1}\t{network:0.2f}\t{solar:0.2f}\t{bess:0.2f}")
|
| 137 |
+
bats += bess
|
| 138 |
+
nws += network
|
| 139 |
+
sols += solar
|
| 140 |
+
print(f"\t{nws:0.2f}\t{sols:0.2f}\t{bats:0.2f}")
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
fig, ax = plt.subplots()
|
| 144 |
+
|
| 145 |
+
ax.stackplot(range(1, 13),
|
| 146 |
+
percentages[:, 0], percentages[:, 1], percentages[:, 2],
|
| 147 |
+
labels=["hálózat", "egyenesen a naptól", "a naptól a BESS-en keresztül"])
|
| 148 |
+
ax.set_ylim(0, 100)
|
| 149 |
+
ax.legend()
|
| 150 |
+
plt.title('A fogyasztás hány százalékát fedezte az adott hónapban?')
|
| 151 |
+
plt.show()
|
| 152 |
+
|
| 153 |
+
plt.stackplot(range(1, 13),
|
| 154 |
+
consumptions_in_mwh[:, 0], consumptions_in_mwh[:, 1], consumptions_in_mwh[:, 2],
|
| 155 |
+
labels=["hálózat", "egyenesen a naptól", "a naptól a BESS-en keresztül"])
|
| 156 |
+
plt.legend()
|
| 157 |
+
plt.title('Mennyi fogyasztást fedezett az adott hónapban? [MWh]')
|
| 158 |
+
plt.show()
|