In [1]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import matplotlib.pyplot as plt
pd.options.display.float_format = '{:.4g}'.format
import enlopy as el
Create random monthly and daily loads
In [2]:
ML = (np.cos(2 * np.pi/12 * np.linspace(0,11,12)) * 50 + 100 ) * 1000 # monthly load
ML = el.make_timeseries(ML) #convenience wrapper around pd.DataFrame with pd.DateTimeindex
ML.plot()
Out[2]:
Create normalized random daily load for a working and non-working day
In [3]:
DWL = el.gen_daily_stoch_el() #daily load working
DNWL = el.gen_daily_stoch_el() #daily load non working
plt.plot(DNWL)
plt.plot(DWL)
Out[3]:
In [4]:
#Define the weighting factor of energy during working and non-working days.
Weight = .55 # i.e energy will be split 55% in working day 45% non working day
Load1 = el.gen_load_from_daily_monthly(ML, DWL, DNWL, Weight)
Load1.name = 'House1'
Load1.plot(figsize=(17,3), linewidth =.2, grid = False);
Check if the total sum of energy is the same
In [5]:
print ('error = {:.2f}'.format(Load1.sum() - ML.sum()))
In [6]:
el.reshape_timeseries(Load1, x='month', y='hour')
Out[6]:
In [7]:
el.plot_heatmap(Load1, edgecolors='none')
In [8]:
el.plot_heatmap(Load1, x='hour', y='week',bins=10, aggfunc='mean', cmap='Blues' ,edgecolors='w')
In [9]:
el.plot_percentiles(Load1, x='week', zz='hour')
In [10]:
el.plot_percentiles(Load1, x='hour', zz='dayofyear', perc_list=[[1,99], [25,75], 50],color='green')
In [11]:
el.plot_3d(Load1, bins=50, cmap='inferno')
In [12]:
el.plot_3d(Load1, x='hour', y='month', aggfunc='mean', cmap='Blues')
In [13]:
el.plot_boxplot(Load1, by='day')
In [14]:
el.plot_rug(Load1, on_off=False, cmap='Greys')
It can accept a dataframe of timeseries and optionally normalize by the maximum value of the whole DataFrame
In [15]:
# Generate dummy dataframe of load profiles
df_many = pd.concat([Load1, 3 * Load1, Load1['Jun 2015':'Nov 2015']], axis=1)
df_many.columns = ['House1', 'House2', 'House3']
In [16]:
el.plot_rug(df_many, cmap='Greens', fig_title='Many houses', normalized=True)
In [17]:
el.get_LDC(Load1)
Out[17]:
In [18]:
el.plot_LDC(Load1, x_norm=False)
In [19]:
el.plot_LDC(Load1, y_norm=True, color='Orange')
In [20]:
el.plot_LDC(Load1, zoom_peak=True)
In [21]:
#Works also for 2-D
el.plot_LDC(df_many[['House1', 'House2']])
In [22]:
el.plot_LDC(df_many[['House1', 'House2']],zoom_peak=True)
In [23]:
el.plot_LDC(df_many[['House1', 'House2']],stacked=False)
In [24]:
plt.plot(el.get_load_archetypes(Load1,2));
In [25]:
el.get_load_archetypes(Load1, 5, plot_diagnostics=True);
In [26]:
Load1_noise = el.add_noise(Load1, 3, 100) # Gauss Markov noise
fig = plt.figure(figsize=(14,3))
#plt.plot(Load1_noise,linewidth =.3)
Load1_noise.plot(figsize=(17,3), linewidth =.2, grid = False)
Load1_noise.name='Noisy'
In [27]:
Load1_noise.iloc[0:100].plot()
Load1.iloc[0:100].plot()
Out[27]:
In [28]:
el.plot_LDC(Load1_noise)
el.plot_LDC(Load1, color='g')
In [29]:
el.get_load_stats(Load1)
Out[29]:
We can also check the statistics per defined time period. Example for month ('m'):
In [30]:
el.get_load_stats(Load1, per='m')
Out[30]:
The following function performs load shifting (or peak shaving) from peak to off-peak timesteps based on given specifications, percentage of peak reduction and percentage of hours per month to peak.
In [31]:
Load1_DR = el.gen_demand_response(Load1, 0.15, 0.30)
In [32]:
Load1[0:100].plot()
Load1_DR[0:100].plot()
Out[32]:
In [33]:
el.get_load_stats(Load1)
Out[33]:
As shown below it is less peaky as expected
In [34]:
el.get_load_stats(Load1_DR)
Out[34]:
In [35]:
el.plot_LDC(Load1_DR, color='g')
el.plot_LDC(Load1, ax=plt.gca())
In [36]:
Load1a = el.gen_load_from_LDC(el.get_LDC(Load1))
fig = plt.figure(figsize=(14,3))
plt.plot(Load1a, linewidth =.3)
Out[36]:
Check whether they have the same distribution
In [37]:
el.plot_LDC(Load1a)
el.plot_LDC(Load1, color='red', ax=plt.gca())
In [ ]: