<jupyter_start><jupyter_text>DoE - Validation of dimensioning of Battery systemThe purpose of this notebook is to show you an example of how to apply the DoE technique related to validation of dimensioning of the Home Energy Management System example.In Denmark, any surplus in energy production from PVs and/or WTs can be returned to the grid, but with no monetary gain for the prosumer. That is, Ørsted will not pay you for the extra electricity that you send back to the grid. Thus, it becomes advantageous for the prosumer to store this surplus in energy for later, say, when the Sun has gone down.That's a common HEMS scenario, which can be sketched like this:The purpose of this scenario is to **replicate** a test in order to understand if the sizing of a battery is correct over a series of days.<jupyter_code>import pandas as pd
import HEMS_sim
import matplotlib.pyplot as plt
%matplotlib notebook
# Dictionary with basic configuration of the simulation
''' The Dictionary must contain base values for the following variables
ID: is the id for the specific recipe.
batt_storage_capacity is the storage size of the battery in kWh.
batt_charge_capacity is the charge/discharge rate of the battery in kW.
pv1_scaling is the scaling of the PV production. 1 corresponds to a maximum capacity of about 5 kW.
controller_change_rate is smoothing variable for the controller.
climate_conditions can be "sunny", "intermittent", or "cloudy".
random_weather determines if the climate_conditions are random days. Is a boolean, True or False.
season scales the consumption. Can be "summer", "autumn", "winter", or "spring".
stochastic determines if it's a stochastic or deterministic simulation. Boolean, True (sctochastic) or False (deterministic).
noise_scale scales the noise that the stochastic simulation adds.
'''

basic_conf = {
    'ID':'00',
    'batt_storage_capacity':20,
    'batt_charge_capacity':5,
    'pv1_scaling':1,
    'controller_change_rate':0.5,
    'climate_conditions':'sunny',
    'random_weather':False,
    'season':'autumn',
    'stochastic':True,
    'noise_scale':1}
# Scenario name which determines the name of the files we will be saving with the results
scenario_name = 'test_1'

# Dictionary with the variations we want to introduce
variations = {'run_01': {'ID':'01','batt_storage_capacity':15,'controller_change_rate':0.3},
              'run_02': {'ID':'02','batt_storage_capacity':15,'controller_change_rate':0.7},
              'run_03': {'ID':'03','batt_storage_capacity':25,'controller_change_rate':0.3},
              'run_04': {'ID':'04','batt_storage_capacity':25,'controller_change_rate':0.7}}

# Merging of the basic configuration and the variations
recipes = {key: basic_conf.copy() for key in variations}
recipes = {key: {**recipes[key],**data} for key,data in variations.items()}<jupyter_output><empty_output><jupyter_text>Running and plotting the simulationsThe two code blocks below run the simulations, one for each scenario defined in the variations dictionary defined above. This may take some time, depending on the amount of scenarios and how fast your computer is.<jupyter_code>%%capture --no-stderr
# Suppress output from running scenarios (Prevents massive size of notebooks)
for recipe in recipes:
    HEMS_sim.run_simulation(scenario_name,recipes[recipe])
store = pd.HDFStore('temp_files/{}_data.h5'.format(scenario_name))
#print(store.keys())
df_1 = store[store.keys()[0]]
df_2 = store[store.keys()[1]]
df_3 = store[store.keys()[2]]
df_4 = store[store.keys()[3]]
store.close()

df_1.plot()
df_2.plot()
df_3.plot()
df_4.plot()<jupyter_output><empty_output><jupyter_text>Summary statisticsThe cells below show some summary statistics, as well as two examples of histogram plots of two summary statistics.The *Self-consumption index* is defined as:$$SCI = \frac{\textrm{Total PV generation} - \textrm{Total exported energy}}{\textrm{Total PV generation}}$$I.e. an $SCI$ of 1.0 means all PV generation is consumed locally.In this and the following assays, we will try to examine which factors influence the self-consumption index.<jupyter_code>run_store = pd.HDFStore('temp_files/runs_summary_{}.h5'.format(scenario_name))
run_store.keys()

summary_1 = run_store[run_store.keys()[0]]
summary_2 = run_store[run_store.keys()[1]]
summary_3 = run_store[run_store.keys()[2]]
summary_4 = run_store[run_store.keys()[3]]
summaries = pd.concat([summary_1,summary_2,summary_3,summary_4])
summaries
plt.figure()
plt.hist(summaries['Self consumption index'])
plt.figure()
plt.hist(summaries['Energy Imported [kWh]'])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09962938739917157, 'fraction_numerical': 0.016132548506649226, 'mean_word_length': 5.678311499272198, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '296048', 'license': 'MIT', 'n_tokens_mistral': 1402, 'n_tokens_neox': 1337, 'n_words': 492, 'path': 'DoE-exercises/1_HEMS_base_case.ipynb', 'repo_name': 'ERIGrid/NA4-Summerschool_Aug18', 'size': '4587'}