Skip to content

Commit

Permalink
Added plot function to plot stacked end-uses
Browse files Browse the repository at this point in the history
  • Loading branch information
eggimasv authored and eggimasv committed Mar 20, 2017
1 parent 798bf92 commit ca604f1
Show file tree
Hide file tree
Showing 16 changed files with 157,802 additions and 157,742 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
0.324165148,0.242081993,0.235291247,0.247121803,0.449886154,1.0524659,1.996454351,2.960973492,2.550991999,1.935409798,1.646425392,1.445955613,1.499672576,1.465622279,1.64895767,2.138635797,2.586991342,2.92111233,3.041061223,2.922288612,2.499211394,1.965780442,1.348506963,0.718933986
0.31130047,0.228049794,0.214258449,0.231862357,0.475644402,1.132311607,2.185429091,3.11326744,2.439908289,1.743192597,1.583259403,1.396992889,1.496813179,1.481353766,1.653440453,2.160328591,2.599554363,2.919720209,3.088836926,2.977139045,2.527249428,1.999918409,1.360436874,0.702586273
0.356326843,0.277162489,0.287873242,0.285270418,0.385490537,0.852851634,1.524017499,2.58023862,2.828701275,2.415952799,1.804340365,1.568362423,1.506821068,1.426293562,1.637750712,2.084403813,2.555583789,2.924592632,2.921621967,2.78516253,2.42911631,1.880435523,1.318682187,0.759803269
0.54884742,0.54884742,0.54884742,0.54884742,0.658616905,2.195389682,4.610318332,6.586169045,9.659714599,3.293084523,5.049396268,5.488474204,4.171240395,4.390779363,4.610318332,5.159165752,4.720087816,7.24478595,7.464324918,7.135016465,6.476399561,5.488474204,2.195389682,1.207464325
Binary file not shown.
14 changes: 7 additions & 7 deletions data/residential_model/data_residential_by_fuel_end_uses.csv
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
fuel_id,light
0,100
1,100
2,1159
3,100
4,100
5,100
fuel_id,light,cold,wet,consumer_electronics,home_computing,cooking
0,0,0,0,0,0,0
1,0,0,0,0,0,0
2,1159,1037,1306,1838,549,1138
3,0,0,0,0,0,0
4,0,0,0,0,0,0
5,0,0,0,0,0,0
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'alabaster'
html_theme = 'default' #classic, alabaster

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
Expand Down
46 changes: 46 additions & 0 deletions energy_demand/_scrap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

import numpy as np
import matplotlib.pyplot as plt


def fnx():
return np.random.randint(5, 50, 10)

y = np.row_stack((fnx(), fnx(), fnx()))
x = np.arange(10)

y1, y2, y3 = fnx(), fnx(), fnx()
'''
fig, ax = plt.subplots()
ax.stackplot(x, y)
plt.show()
'''
fig, ax = plt.subplots()

ax.stackplot(x, y1, y2, y3)
plt.show()


'''import numpy as NP
from matplotlib import pyplot as PLT
# just create some random data
fnx = lambda : NP.random.randint(3, 10, 10)
y = NP.row_stack([fnx(), fnx(), fnx()])
# this call to 'cumsum' (cumulative sum), passing in your y data,
# is necessary to avoid having to manually order the datasets
x = NP.arange(10)
y_stack = NP.cumsum(y, axis=0) # a 3x10 array
fig = PLT.figure()
ax1 = fig.add_subplot(111)
ax1.fill_between(x, 0, y_stack[0,:], facecolor="green", alpha=1)
ax1.fill_between(x, y_stack[0,:], y_stack[1,:], facecolor="red", alpha=.4)
ax1.fill_between(x, y_stack[1,:], y_stack[2,:], facecolor="#6E5160")
PLT.show()
'''
4 changes: 1 addition & 3 deletions energy_demand/data_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def generate_data(data, run_data_collection):

if run_data_collection is False:
# TODO
# Read in dumped csv files
# Read in individual CSV files of load shapes
return data

# --------------
Expand Down Expand Up @@ -51,6 +51,4 @@ def generate_data(data, run_data_collection):
folder_path = r'C:\Users\cenv0553\Dropbox\00-Office_oxford\07-Data\09_Carbon_Trust_advanced_metering_trial_(owen)\__OWN_SEWAGE' #Community _OWN_SEWAGE
out_dict_av, out_dict_not_av, hourly_shape_of_maximum_days = df.read_raw_carbon_trust_data(data, folder_path)



return data
43 changes: 20 additions & 23 deletions energy_demand/data_loader_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,37 +159,32 @@ def get_hes_end_uses_shape(data, hes_data, year_raw_values, hes_y_peak, hes_y_wa

# CWV WEATER GAS SAMSON-----------------------------------
def shape_residential_heating_gas(data, end_use):
"""
This function creates the shape of the base year heating demand over the full year
#Todo: Different shapes depending on workingday/holiday
"""Creates the shape of the base year heating demand over the full year
Input:
-csv_temp_2015 SNCWV temperatures for every gas-year day
-hourly_gas_shape Shape of hourly gas for Day, weekday, weekend (Data from Robert Sansom)
#TODO: THIS CAN BE USED TO DERIVED temp_2015_non_residential_gas data
"""
# Initilaise array to store all values for a year
year_days, hours = 365, 24
hourly_hd = np.zeros((1, hours), dtype=float)
hd_data = np.zeros((year_days, hours), dtype=float)


# Read in temperatures for base year
csv_temp_2015 = mf.read_csv(data['path_dict']['path_temp_2015'])
hourly_gas_shape = mf.read_csv_float(data['path_dict']['path_hourly_gas_shape']) / 100 #Because given in percentages (division no inlfuence on results as relative anyway)
#print("hourly_gas_shape " + str(hourly_gas_shape))

data['csv_temp_2015'] = csv_temp_2015
#add hourly data

# Initilaise array to store all values for a year
year_days, hours = 365, 24
hourly_hd = np.zeros((1, hours), dtype=float)
hd_data = np.zeros((year_days, hours), dtype=float)
#shape_hd = np.zeros((year_days, hours), dtype=float)
hourly_gas_shape = mf.read_csv_float(data['path_dict']['path_hourly_gas_shape']) / 100 # Because given in percentages (division no inlfuence on results as relative anyway)


# Get hourly distribution (Sansom Data)
#hourly_gas_shape_day = hourly_gas_shape[0] # Hourly gas shape
#hourly_gas_shape_day = hourly_gas_shape[0] # Hourly gas shape
hourly_gas_shape_wkday = hourly_gas_shape[1] # Hourly gas shape
hourly_gas_shape_wkend = hourly_gas_shape[2] # Hourly gas shape

peak_h_shape = hourly_gas_shape[3] # Manually derived peak from Robert Sansom

# Read in SNCWV and calculate heating demand for every yearday
for row in csv_temp_2015:
Expand Down Expand Up @@ -247,20 +242,22 @@ def shape_residential_heating_gas(data, end_use):
cnt += 1

# PEAK-----------------------------------------------------------------------------


# TODO: GET PEAK OF HEATING
#print("TEST:")
#print(shape_d_non_peak.shape)
#prnt("..")

# Get maximum daily demand
_list = []
for demand in csv_temp_2015:
_list.append(float(demand[1]))

max_day_demand = max(_list) #maximum demand

# Factor to calc maximum daily peak #TODO: INclude uncertainty?
peak_d_shape = max_day_demand / total_y_hd

# Add to hourly shape
data['dict_shapes_end_use_h'][end_use] = {'peak_h_shape': shape_h_non_peak, 'shape_h_non_peak': shape_h_non_peak} # TODO: no peak for gas
data['dict_shapes_end_use_h'][end_use] = {'peak_h_shape': peak_h_shape, 'shape_h_non_peak': shape_h_non_peak} # TODO: no peak for gas

# Add to daily shape
data['dict_shapes_end_use_d'][end_use] = {'peak_d_shape': shape_d_non_peak, 'shape_d_non_peak': shape_d_non_peak} # No peak
data['dict_shapes_end_use_d'][end_use] = {'peak_d_shape': peak_d_shape, 'shape_d_non_peak': shape_d_non_peak} # No peak

return data

Expand Down
7 changes: 0 additions & 7 deletions energy_demand/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
- Read out individal load shapes
- HEating Degree DAys
- Plot Yearly data
- efficiencies
- leasitciies
Expand Down Expand Up @@ -55,9 +54,6 @@ def energy_demand_model(data, data_ext):
A nested dictionary containing all data for energy
supply model with timesteps for every hour in a year.
Notes
-----
"""
# Initialisation
all_regions = [] # List to store all regions
Expand All @@ -68,7 +64,6 @@ def energy_demand_model(data, data_ext):
# Residential model
# --------------------------


# Generate technological stock
data['tech_stock'] = ts.ResidTechStock(data, data_ext)

Expand Down Expand Up @@ -119,8 +114,6 @@ def energy_demand_model(data, data_ext):
# Plot REgion 0 for half a year
#pf.plot_x_days(result_dict[2], 0, 12)



return result_dict

# Run
Expand Down
5 changes: 5 additions & 0 deletions energy_demand/plot_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
import matplotlib.pyplot as plt
import numpy as np






def plot_x_days(all_hours_year, region, days):
"""With input 2 dim array plot daily load"""

Expand Down
62 changes: 41 additions & 21 deletions energy_demand/residential_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl

import energy_demand.technological_stock as ts
import energy_demand.technological_stock_functions as tf
Expand Down Expand Up @@ -50,7 +51,7 @@ def __init__(self, reg_id, data, data_ext):
self.reg_load_factor_h = self.load_factor_h()

# Plot stacked end_uses
#self.plot_stacked_regional_end_use()
#self.plot_stacked_regional_end_use(1, 2) #days, fueltype

def create_end_use_objects(self):
"""Initialises all defined end uses. Adds an object for each end use to the Region class"""
Expand Down Expand Up @@ -180,39 +181,58 @@ def __getattr__subclass__(self, attr_main_class, attr_sub_class):
object_subclass = getattr(object_class, attr_sub_class)
return object_subclass

def plot_stacked_regional_end_use(self, nr_of_day_to_plot, fueltype):
""" Plots stacked end_use for a region
#TODO: Make that end_uses can be sorted, improve legend...
"""

'''def plot_stacked_regional_end_use(self):
""" PLot End Uses of Region """
fig, ax = plt.subplots()
nr_hours_to_plot = nr_of_day_to_plot * 24

nr_of_day_to_plot = 10
fueltype = 2
x = np.arange(nr_hours_to_plot)
legend_entries = []

x_values = range(nr_of_day_to_plot * 24)
# Initialise (number of enduses, number of hours to plot)
Y_init = np.zeros((len(self.reg_fuel), nr_hours_to_plot))

# Iterate End_uses
for enduse in self.reg_fuel:
y_values = []
# Iterate enduse
for k, enduse in enumerate(self.reg_fuel):
legend_entries.append(enduse)
sum_fuels_h = self.__getattr__subclass__(enduse, 'enduse_fuel_h') #np.around(fuel_end_use_h,10)
data_fueltype_enduse = np.zeros((nr_hours_to_plot, ))
list_all_h = []

#Get data of a fueltype
for j, fuel_data in enumerate(sum_fuels_h[fueltype][:nr_of_day_to_plot]):

for h in fuel_data:
list_all_h.append(h)

print(" ENDUSE: " + str(enduse))
day_all_fuels = self.__getattr__subclass__(enduse, 'enduse_fuel_h')
Y_init[k] = list_all_h

for day, d_value in enumerate(day_all_fuels[fueltype]):
color_list = ["green", "red", "#6E5160"]

# ONLY PLOT HALF A YEAR
if day < nr_of_day_to_plot:
sp = ax.stackplot(x,Y_init)
proxy = [mpl.patches.Rectangle((0,0), 0,0, facecolor=pol.get_facecolor()[0]) for pol in sp]

for h in d_value:
y_values.append(h)
ax.legend(proxy, legend_entries)

plt.plot(x_values, y_values)
plt.axis('tight')

plt.xlabel("Hours")
plt.ylabel("Energy demand in kWh")
plt.title("Energy Demand")
plt.legend()
plt.title("Stacked energy demand")

#from matplotlib.patches import Rectangle

#legend_boxes = []
#for i in color_list:
# box = Rectangle((0, 0), 1, 1, fc=i)
# legend_boxes.append(box)
#ax.legend(legend_boxes, legend_entries)

#ax.stackplot(x, Y_init)
plt.show()
'''


class EndUseClassResid(Region):
Expand Down

0 comments on commit ca604f1

Please sign in to comment.