SimpleHouseRSla notebook example

In this example, the usage of the model “SimpleHouseSlab-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.

[1]:
import energym

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

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

[2]:
inputs = env.get_inputs_names()
print(inputs)
['u']

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.

[3]:
from scipy import signal

steps = 288*10
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.

[4]:
import pandas as pd
out_df = pd.DataFrame(out_list)
[5]:
out_df
[5]:
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 4.845457 10.197181 5000.0 2.422729e+04 -1.922729e+04 306.383478 276.337580 0.0 11709.697791 ... 0.0 299.165850 293.110455 304.431161 0.0 0.0 0.0 198.356554 293.110455 300.0
1 273.050842 4.497996 9.465954 5000.0 2.248998e+04 -1.748998e+04 309.695190 276.978448 0.0 15166.910884 ... 0.0 302.821032 293.214613 307.887631 0.0 0.0 0.0 198.314931 293.214613 600.0
2 273.060017 4.309981 9.070281 5000.0 2.154991e+04 -1.654991e+04 311.686527 277.323036 0.0 17116.428223 ... 0.0 304.992757 293.394047 309.957447 0.0 0.0 0.0 198.276953 293.394047 900.0
3 273.067805 4.200541 8.839966 5000.0 2.100270e+04 -1.600270e+04 312.921007 277.522566 0.0 18209.589180 ... 0.0 306.333322 293.614137 311.237577 0.0 0.0 0.0 198.244444 293.614137 1200.0
4 273.073788 4.132531 8.696839 5000.0 2.066265e+04 -1.566265e+04 313.718667 277.645945 0.0 18812.735306 ... 0.0 307.199889 293.855164 312.063525 0.0 0.0 0.0 198.219227 293.855164 1500.0
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
2875 278.540000 4.120141 8.670766 0.0 2.350989e-38 -2.350989e-38 320.062872 283.150000 0.0 0.000000 ... 0.0 315.810929 297.693424 320.062482 0.0 0.0 0.0 236.600000 297.693424 862800.0
2876 278.540000 4.120141 8.670766 0.0 2.350989e-38 -2.350989e-38 320.062872 283.150000 0.0 0.000000 ... 0.0 315.810929 297.414317 320.062482 0.0 0.0 0.0 236.962500 297.414317 863100.0
2877 278.540000 4.120141 8.670766 0.0 2.350989e-38 -2.350989e-38 320.062872 283.150000 0.0 0.000000 ... 0.0 315.810929 297.139277 320.062482 0.0 0.0 0.0 237.325000 297.139277 863400.0
2878 278.540000 4.120141 8.670766 0.0 2.350989e-38 -2.350989e-38 320.062872 283.150000 0.0 0.000000 ... 0.0 315.810929 296.868245 320.062482 0.0 0.0 0.0 237.687500 296.868245 863700.0
2879 278.540000 4.120141 8.670766 0.0 2.350989e-38 -2.350989e-38 320.062872 283.150000 0.0 0.000000 ... 0.0 315.810929 296.601162 320.062482 0.0 0.0 0.0 238.050000 296.601162 864000.0

2880 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.

[6]:
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['temSup.T']-273.15, 'b--')
ax1.plot(out_df['temRet.T']-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()
[ ]: