SwissHouseRSla notebook example

In this example, the usage of the model “SwissHouseRad-v0” is demonstrated.

First, we import Energym and create the simulation environment by specifying the model, a weather file and the number of simulation days.

[2]:
import energym

weather = "CH_BS_Basel"
env = energym.make("SwissHouseRSlaW2W-v0", weather=weather, simulation_days=20)
the initial variables are {'u': 0}

The control inputs can be inspected using the get_inputs_names() method.

[3]:
inputs = env.get_inputs_names()
outputs = env.get_outputs_names()
print("inputs:", inputs)
print("outputs:", outputs)
inputs: ['u']
outputs: ['TOut.T', 'heaPum.COP', 'heaPum.COPCar', 'heaPum.P', 'heaPum.QCon_flow', 'heaPum.QEva_flow', 'heaPum.TConAct', 'heaPum.TEvaAct', 'preHea.Q_flow', 'sla.QTot', 'sla.heatPortEmb[1].T', 'sla.m_flow', 'sunHea.Q_flow', 'sunRad.y', 'temRet.T', 'temRoo.T', 'temSup.T', 'weaBus.HDifHor', 'weaBus.HDirNor', 'weaBus.HGloHor', 'weaBus.HHorIR', 'y']

To run the simulation, a number of steps is specified (here 288 steps per day for 10 days), a control input is specified and passed to the simulation model with the step() method. To generate some plots later on, we save all the outputs in lists.

[4]:
from scipy import signal

steps = 288*5
out_list = []
outputs = env.get_output()
controls = []
hour = 0
for i in range(steps):
    control = {}
    control['u'] = [0.5*(signal.square(0.1*i)+1.0)]
    controls +=[ {p:control[p][0] for p in control} ]
    outputs = env.step(control)
    _,hour,_,_ = env.get_date()
    out_list.append(outputs)
[OK] %s
[WARNING] %s

Since the outputs are given as dictionaries and are collected in lists, we can simply load them as a pandas.DataFrame.

[5]:
import pandas as pd
out_df = pd.DataFrame(out_list)
[6]:
out_df
[6]:
TOut.T heaPum.COP heaPum.COPCar heaPum.P heaPum.QCon_flow heaPum.QEva_flow heaPum.TConAct heaPum.TEvaAct preHea.Q_flow sla.QTot ... sunRad.y temRet.T temRoo.T temSup.T weaBus.HDifHor weaBus.HDirNor weaBus.HGloHor weaBus.HHorIR y time
0 273.040697 3.872714 13.583432 1000.0 3.872714e+03 -2.872714e+03 297.357658 275.466456 0.0 2937.284209 ... 0.0 293.656276 293.153996 294.775662 0.0 0.0 0.0 198.356554 293.153996 300.0
1 273.050842 3.839777 13.467908 1000.0 3.839777e+03 -2.839777e+03 297.657343 275.556112 0.0 3503.467174 ... 0.0 293.983947 293.163014 295.097367 0.0 0.0 0.0 198.314931 293.163014 600.0
2 273.060017 3.818085 13.391824 1000.0 3.818085e+03 -2.818085e+03 297.856813 275.615122 0.0 3868.495573 ... 0.0 294.201873 293.175391 295.311340 0.0 0.0 0.0 198.276953 293.175391 900.0
3 273.067805 3.803545 13.340826 1000.0 3.803545e+03 -2.803545e+03 297.991447 275.654641 0.0 4103.549728 ... 0.0 294.348908 293.189931 295.455694 0.0 0.0 0.0 198.244444 293.189931 1200.0
4 273.073788 3.793566 13.305825 1000.0 3.793566e+03 -2.793566e+03 298.084275 275.681735 0.0 4254.872673 ... 0.0 294.450276 293.205857 295.555191 0.0 0.0 0.0 198.219227 293.205857 1500.0
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
1435 278.738889 5.361843 18.806509 0.0 2.407412e-35 -2.407412e-35 299.051489 283.150000 0.0 -0.000000 ... 0.0 298.024250 296.434162 299.051481 0.0 0.0 0.0 298.691478 296.434162 430800.0
1436 278.737656 5.361843 18.806509 0.0 2.407412e-35 -2.407412e-35 299.051489 283.150000 0.0 -0.000000 ... 0.0 298.024250 296.421192 299.051481 0.0 0.0 0.0 298.764373 296.421192 431100.0
1437 278.743194 5.361843 18.806509 0.0 2.407412e-35 -2.407412e-35 299.051489 283.150000 0.0 -0.000000 ... 0.0 298.024250 296.408233 299.051481 0.0 0.0 0.0 298.817684 296.408233 431400.0
1438 278.756858 5.361843 18.806509 0.0 2.407412e-35 -2.407412e-35 299.051489 283.150000 0.0 -0.000000 ... 0.0 298.024250 296.395291 299.051481 0.0 0.0 0.0 298.847523 296.395291 431700.0
1439 278.780000 5.361843 18.806509 0.0 2.407412e-35 -2.407412e-35 299.051489 283.150000 0.0 -0.000000 ... 0.0 298.024250 296.382373 299.051481 0.0 0.0 0.0 298.850000 296.382373 432000.0

1440 rows × 23 columns

To generate plots, we can directly get the data from the DataFrames, by using the key names. Displayed are the room temperature, the supply temperature and the return temperature, as well as the external temperature, and the heat pump energy.

[7]:
import matplotlib.pyplot as plt
%matplotlib notebook

f, (ax1,ax2,ax3) = plt.subplots(3,figsize=(10,15))#


ax1.plot(out_df['temRoo.T']-273.15, 'r')
ax1.plot(out_df['sla.heatPortEmb[1].T']-273.15, 'b--')
ax1.plot(out_df['heaPum.TEvaAct']-273.15, 'orange')
ax1.set_ylabel('Temp')
ax1.set_xlabel('Steps')

ax2.plot(out_df['TOut.T']-273.15, 'r')
ax2.set_ylabel('Temp')
ax2.set_xlabel('Steps')

ax3.plot(out_df['heaPum.QCon_flow'], 'g')
ax3.set_ylabel('Energy')
ax3.set_xlabel('Steps')

plt.subplots_adjust(hspace=0.4)

plt.show()

To end the simulation, the close() method is called. It deletes files that were produced during the simulation and stores some information about the simulation in the energym_runs folder.

[ ]:
env.close()
[ ]: