Skip to content

Commit

Permalink
adaped residential model to consider external internal data
Browse files Browse the repository at this point in the history
  • Loading branch information
eggimasv authored and eggimasv committed Feb 27, 2017
1 parent a3ec392 commit 40cc3e4
Show file tree
Hide file tree
Showing 9 changed files with 288 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
2009,21.46556448,36.68186156,29.6079356,8.031695795,4.21294257
2010,21.73061688,36.39767665,28.95289978,7.908182763,5.010623934
2011,20.82643491,36.31645864,29.44333304,8.00677683,5.407611848
2015,20.82643491,36.31645864,29.44333304,8.00677683,5.407611848
6 changes: 3 additions & 3 deletions data/residential_model/data_residential_model_floor_area.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
region_nr,floor_area
0,10000
1,200000
2,400000
0,100000
1,2000000
2,4000000
9 changes: 6 additions & 3 deletions energy_demand/building_stock_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
class House(object):
"""Class of a single dwelling or of a aggregated group of dwelling"""

def __init__(self, coordinates, house_id, age, hlc, pop, floor_area, temp):
def __init__(self, coordinates, dwtype, house_id, age, hlc, pop, floor_area, temp):
"""Returns a new dwelling object.
Parameters
----------
coordinates : float
Coordinates
coordinates
dwtype : int
Dwelling type id
age : int
Age of dwelling
hlc : float
Expand All @@ -27,8 +29,9 @@ def __init__(self, coordinates, house_id, age, hlc, pop, floor_area, temp):
"""
self.house_id = house_id
self.coordinates = coordinates
self.dwtype = dwtype
self.age = age
self.hlc = hlc
self.hlc = get_hlc(dwtype, age) #hlc
self.pop = pop
self.floor_area = floor_area
self.temp = temp
Expand Down
189 changes: 171 additions & 18 deletions energy_demand/building_stock_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,189 @@ def virtual_building_stock(data):
""" Virtual Building generator"""

#get_assumption_age_distribution
dwtype_distr = data['dwtype_distr'] # Distribution of dwelling types 2015.0: {'semi_detached': 26.0, 'terraced': 28.3, 'flat': 20.3, 'detached': 16.6, 'bungalow': 8.8}
dwtype_age_distr = data['dwtype_age_distr'] # Age distribution of dwelling types {2015: {1918: 20.8, 1928: 36.3, 1949: 29.4, 1968: 8.0, 1995: 5.4}} # year, average_age, percent
base_year = 2015
dwtype_distr = data['dwtype_distr'][base_year] # Distribution of dwelling types 2015.0: {'semi_detached': 26.0, 'terraced': 28.3, 'flat': 20.3, 'detached': 16.6, 'bungalow': 8.8}
dwtype_age_distr = data['dwtype_age_distr'][base_year] # Age distribution of dwelling types {2015: {1918: 20.8, 1928: 36.3, 1949: 29.4, 1968: 8.0, 1995: 5.4}} # year, average_age, percent
dwtype_floor_area = data['dwtype_floor_area'] # Floor area [m2] {'semi_detached': 96.0, 'terraced': 82.5, 'flat': 61.0, 'detached': 147.0, 'bungalow': 77.0}
reg_floor_area = data['reg_floor_area'] # Floor Area in a region
dw_lu = data['dwtype_lu']
global_variables = data['global_variables']

print(dwtype_distr)
print("---")
print(dwtype_age_distr)
print("---")
print(dwtype_floor_area)
print("---")
reg_lu = data['reg_lu']
print("-tt--")
print(reg_floor_area)
print("oo")
print(dw_lu)


print("fff")
print(data['reg_floor_area'])
reg_lu = data['reg_lu']
uniqueID = 100000
dwelling_stock_old = []
dwelling_stock_new = []

# Iterate regions
for region_id in reg_lu:
print("region: " + str(region_id))
print(region_id)

# Read base data
reg_id_pop = data['reg_pop'][region_id] # Read in population
reg_id_floor_area = data['reg_floor_area'][region_id] # Read in floor area
reg_id_dw_nr = data['reg_dw_nr'][region_id] # Read in nr of dwellings
reg_id_pop_by = data['reg_pop'][region_id] # Read in population
reg_id_floor_area_by = reg_floor_area[region_id] # Read in floor area
reg_id_dw_nr = data['reg_dw_nr'][region_id] # Read in nr of dwellings
print("RegPOP: " + str(reg_id_pop_by))
print("reg_floor_area: " + str(reg_id_floor_area_by))
print("reg_dw_nr: " + str(reg_id_dw_nr))
floor_area_p_base_year = get_percent_floor_area_per_dw_type(dw_lu, dwtype_distr, dwtype_floor_area, reg_id_dw_nr) # Percent of floor area of base year (is the same for all old buildings)

# Calculate floor area per person
reg_id_floor_area_pp_by = reg_id_floor_area_by / reg_id_pop_by # Floor area per person [m2/person]

print("RegPOP: " + str(reg_id_pop))
print("reg_floor_area: " + str(reg_id_floor_area))
print("reg_dw_nr: " + str(reg_id_dw_nr))
# Calculate floor area per dwelling
reg_id_floor_area_by_pd = reg_id_floor_area_by / reg_id_dw_nr # Floor area per dwelling [m2/dwelling]

# --- Assumptions of scenario
reg_id_pop_cy = reg_id_pop_by * 1.5 ### #TODO: get new population
reg_id_floor_area_pp_cy = reg_id_floor_area_pp_by * 1.05 ### #TODO: get new reg_id_floor_area_pp_by
reg_id_floor_area_by_pd_cy = reg_id_floor_area_by_pd * 0.1 ### #TODO: get new reg_id_floor_area_by_pd

# Calculate total floor area
total_floor_area_cy = reg_id_floor_area_pp_cy * reg_id_pop_cy
total_floor_area_new_area = total_floor_area_cy - (reg_id_floor_area_pp_by * reg_id_pop_by) # tot new floor area - area base year = New needed floor area

print(" Current floor area: " + str(total_floor_area_cy))
print(" New needed floor area: " + str(total_floor_area_new_area))

# Calculate total number of dwellings (existing build + need for new ones)
dw_new = total_floor_area_new_area / reg_id_floor_area_by_pd # Needed new buildings
total_nr_dw = reg_id_dw_nr + dw_new # floor area / buildings

print("New buildings: " + str(dw_new))
print("total_nr_dw: " + str(total_nr_dw))

# Population
pop_by = reg_id_pop_by
pop_new_dw = reg_id_pop_cy - pop_by

# ---- old buildings
# Distribute old dwellings according to dwelling distribution
# ITerate dwelling types
for dw in dw_lu:
dw_type_id = dw
dw_type_name = dw_lu[dw]
print("Dwelling type: " + str(dw_type_name))

percent_dw_type = dwtype_distr[dw_type_name] / 100 # Percentage of dwelling type
print("percentage of dwelling type: " + str(percent_dw_type))

dw_type_floor_area = floor_area_p_base_year[dw_type_name] * total_floor_area_cy
print("Floor area of dwelling types: " + str(dw_type_floor_area))

## Get scenario parameter?? TODO:
## percent_dw_type = percent_dw_type??

dw_type_dw_nr = percent_dw_type * reg_id_dw_nr # Nr of existing dwellings dw type
print("Nr of Dwelling of tshi type: " + str(dw_type_dw_nr))

# Distribute according to age
for dwtype_age_id in dwtype_age_distr:
print(" Age class, dwelling type " + str(dwtype_age_id))
age_class_p = dwtype_age_distr[dwtype_age_id] / 100 # Percent of dw of age class

# Floor area of dwelling_class_age
dw_type_age_class_floor_area = dw_type_floor_area * age_class_p # Distribute proportionally floor area
print("dw_type_age_class_floor_area: " + str(dw_type_age_class_floor_area))
print(reg_id_floor_area_pp_by)

# Pop
_pop_2015_dwelling_type_age_class = dw_type_age_class_floor_area / reg_id_floor_area_pp_by # Distribed with floor area..could do better
print("_pop_2015_dwelling_type_age_class: " + str(_pop_2015_dwelling_type_age_class))

# --- create building object
_hlc = bf.get_hlc(dw_type_id, float(dwtype_age_id))

dwelling_stock_old.append(bf.House(['X', 'Y'], dw_type_id, uniqueID, float(dwtype_age_id), _hlc, _pop_2015_dwelling_type_age_class, dw_type_age_class_floor_area, 9999))
uniqueID += 1

# ------------ new buildings
for dw in dw_lu:
dw_type_id = dw
dw_type_name = dw_lu[dw]

percent_dw_type = dwtype_distr[dw_type_name] / 100 # Percentage of dwelling type (TODO: Nimm scneario value)

print("Floor area of new buildings per dwelling types: " + str(total_floor_area_new_area))

dw_type_dw_nr_new = percent_dw_type * dw_new # Nr of existing dwellings dw type new
print("Nr of Dwelling of tshi type: " + str(dw_type_dw_nr_new))

# Floor area of dwelling_class_age
dw_type_age_class_floor_area_new = total_floor_area_new_area * age_class_p # Distribute proportionally floor area
print("dw_type_age_class_floor_area_new: " + str(dw_type_age_class_floor_area_new))

# Pop
_pop_2015_dwelling_type_age_class_new = dw_type_age_class_floor_area_new / reg_id_floor_area_pp_cy # Distribed with floor area..could do better
print("_pop_2015_dwelling_type_age_class: " + str(_pop_2015_dwelling_type_age_class_new))

# Get age of building construction
sim_period = range(global_variables['base_year'], global_variables['current_year'] + 1, 1) #base year, current year + 1, iteration step
nr_sim_y = len(sim_period)
for simulation_year in sim_period:
dw_age = simulation_year
_hlc = bf.get_hlc(dw_type_id, dw_age)

# --- create building object
dwelling_stock_new.append(bf.House(['X', 'Y'], dw_type_id, uniqueID, simulation_year, _hlc, _pop_2015_dwelling_type_age_class_new/nr_sim_y, dw_type_age_class_floor_area/nr_sim_y, 9999))
uniqueID += 1

print("....")
for h in dwelling_stock_old:
print(h.__dict__)
print(".............")
for i in dwelling_stock_new:
print(i.__dict__)

return dwelling_stock_old, dwelling_stock_new



# -----------Calculate the share of total floor area beloinging to each dwelling type-----------
def get_percent_floor_area_per_dw_type(dw_lookup, dw_dist, dw_floor_area, reg_id_dw_nr):
""" Calculates the percentage of floor area belonging to each dwelling type
depending on average floor area per dwelling type
dw_lookup - dwelling types
dw_dist - distribution of dwellin types
dw_floor_area - floor area per type
reg_id_dw_nr - number of total dwlling
returns a dict with percentage of each total floor area for each dwtype (must be 1.0 in tot)
"""

total_floor_area_cy = 0
dw_floor_area_p = {} # Initialise percent of total floor area per dwelling type

for dw_id in dw_lookup:
dw_name = dw_lookup[dw_id]

# Get number of building of dwellin type
percent_buildings_dw = (dw_dist[dw_name])/100
nr_dw_typXY = reg_id_dw_nr * percent_buildings_dw

# absolute usable floor area per dwelling type
fl_type = nr_dw_typXY * dw_floor_area[dw_name]

# sum total area
total_floor_area_cy += fl_type
dw_floor_area_p[dw_name] = fl_type # add absolute are ato dict

# Convert absolute values into percentages
for i in dw_floor_area_p:
dw_floor_area_p[i] = (1/total_floor_area_cy)*dw_floor_area_p[i]

return dw_floor_area_p

return

'''# Data
# ---------------------------------------------------------------
Expand Down Expand Up @@ -72,7 +225,7 @@ def get_percent_floor_area_per_dw_type():
return
total_floor_area = 0
total_floor_area_cy = 0
dw_floor_area_percent = {} # initialise
for row in dw_lookup:
Expand All @@ -84,12 +237,12 @@ def get_percent_floor_area_per_dw_type():
fl_type = nr_dw_typXY * dw_floor_area[int(row[0])]
# sum total area
total_floor_area += fl_type
total_floor_area_cy += fl_type
dw_floor_area_percent[int(row[0])] = fl_type # add absolute are ato dict
# Convert absolute values into percentages
for i in dw_floor_area_percent:
_ = (1/total_floor_area)*dw_floor_area_percent[i]
_ = (1/total_floor_area_cy)*dw_floor_area_percent[i]
dw_floor_area_percent[i] = _
print("Percentage of total floor area belonging to each dwelling type: " + str(dw_floor_area_percent))
Expand Down Expand Up @@ -222,7 +375,7 @@ def get_percent_floor_area_per_dw_type():
# Input from real world
# ---------------------
- nr_dwellings
- total_floor_area
- total_floor_area_cy
- distribution of dwelling types
- total population
- XY coordinates
Expand Down
50 changes: 24 additions & 26 deletions energy_demand/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,23 @@ def load_data():

# Global variables
#YEAR_SIMULATION = 2015 # Provide year for which to run the simulation
P1_YEAR_BASE = 2015 # [int] First year of the simulation period
#global_variables['base_year'] = 2015 # [int] First year of the simulation period
#P2_YEAR_END = 2050 # [int] Last year of the simulation period
#P3_SIM_PERIOD = range(P2_YEAR_END - P1_YEAR_BASE) # List with simulation years
#P0_YEAR_CURR = YEAR_SIMULATION - P1_YEAR_BASE # [int] Current year in current simulation
#SIM_PARAM = [P0_YEAR_CURR, P1_YEAR_BASE, P2_YEAR_END, P3_SIM_PERIOD] # Store all parameters in one list
SIM_PARAM = [0, 2015, 2050, range(50)] # Store all parameters in one list
#P3_SIM_PERIOD = range(P2_YEAR_END - global_variables['base_year']) # List with simulation years
#P0_YEAR_CURR = YEAR_SIMULATION - global_variables['base_year'] # [int] Current year in current simulation
#global_variables = [P0_YEAR_CURR, global_variables['base_year'], P2_YEAR_END, P3_SIM_PERIOD] # Store all parameters in one list
global_variables = {'base_year': 2015, 'current_year': 2015, 'end_year': 2050}

# ------Read in all data from csv files-------------------
data, path_dict = mf.read_data(path_main)
data['SIM_PARAM'] = SIM_PARAM # add to data dict
data['global_variables'] = global_variables # add to data dict

#print(isinstance(reg_floor_area[0], int))
#print(isinstance(reg_floor_area[0], float))


# ------Generate generic load profiles (shapes) [in %]-------------------
shape_app_elec, shape_hd_gas = mf.get_load_curve_shapes(path_dict['path_bd_e_load_profiles'], data['day_type_lu'], data['app_type_lu'], SIM_PARAM, data['csv_temp_2015'], data['hourly_gas_shape'])
shape_app_elec, shape_hd_gas = mf.get_load_curve_shapes(path_dict['path_bd_e_load_profiles'], data['day_type_lu'], data['app_type_lu'], global_variables, data['csv_temp_2015'], data['hourly_gas_shape'])
data['shape_app_elec'] = shape_app_elec # add to data dict

# ------Base demand for the base year for all modelled elements-------------------
Expand All @@ -90,10 +94,10 @@ def load_data():
# Generate simulation timesteps and assing base demand (e.g. 1 week in each season, 24 hours)
# ---------------------------------------------------------------
timesteps_own_selection = (
[date(P1_YEAR_BASE, 1, 12), date(P1_YEAR_BASE, 1, 18)], # Week Spring (Jan) Week 03 range(334 : 364) and 0:58
[date(P1_YEAR_BASE, 4, 13), date(P1_YEAR_BASE, 4, 19)], # Week Summer (April) Week 16 range(59:150)
[date(P1_YEAR_BASE, 7, 13), date(P1_YEAR_BASE, 7, 19)], # Week Fall (July) Week 25 range(151:242)
[date(P1_YEAR_BASE, 10, 12), date(P1_YEAR_BASE, 10, 18)], # Week Winter (October) Week 42 range(243:333)
[date(global_variables['base_year'], 1, 12), date(global_variables['base_year'], 1, 18)], # Week Spring (Jan) Week 03 range(334 : 364) and 0:58
[date(global_variables['base_year'], 4, 13), date(global_variables['base_year'], 4, 19)], # Week Summer (April) Week 16 range(59:150)
[date(global_variables['base_year'], 7, 13), date(global_variables['base_year'], 7, 19)], # Week Fall (July) Week 25 range(151:242)
[date(global_variables['base_year'], 10, 12), date(global_variables['base_year'], 10, 18)], # Week Winter (October) Week 42 range(243:333)
)
data['timesteps_own_selection'] = timesteps_own_selection # add to data dict

Expand All @@ -118,6 +122,9 @@ def load_data():

return data




# ---------------------------------------------------------------
# Run Model
# ---------------------------------------------------------------
Expand Down Expand Up @@ -150,29 +157,20 @@ def energy_demand_model(data, pop_data_external):
# Add external data to data dictionary
# ----

# population data
data = mf.add_to_data(data, pop_data_external) # Convert to array, store in data

# Get input and convert into necessary formats
# -------------------------------------------------
# population data (scrap)
data_external = {}
data_external = mf.add_to_data(data_external, pop_data_external) # Convert to array, store in data

#print ("Energy Demand Model - Main funtion simulation parameter: " + str(global_variables))


#print ("Energy Demand Model - Main funtion simulation parameter: " + str(SIM_PARAM))

# ---------------------------------------------------------------------------
# Run sub modules
print(" Start executing sub models of energy demand module")
# ---------------------------------------------------------------------------

# Build residential building stock
#bg.virtual_building_stock(data)
bg.virtual_building_stock(data)
#prnt(":.")



# Run different sub-models (sector models)
e_app_bd, g_hd_bd = residential_model.run(data['SIM_PARAM'], data['shape_app_elec'], data['reg_pop_array'], data['timesteps_app_bd'], data['timesteps_hd_bd'])
e_app_bd, g_hd_bd = residential_model.run(data['global_variables'], data['shape_app_elec'], data['reg_pop_array'], data_external['reg_pop_external_array'], data['timesteps_app_bd'], data['timesteps_hd_bd'])
#print(e_app_bd[0][0])

'''
Expand Down

0 comments on commit 40cc3e4

Please sign in to comment.