Skip to content

Commit

Permalink
implemented region class to store building stock
Browse files Browse the repository at this point in the history
  • Loading branch information
eggimasv authored and eggimasv committed Feb 28, 2017
1 parent f87fd78 commit 1f727c7
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 106 deletions.
48 changes: 46 additions & 2 deletions energy_demand/building_stock_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class Dwelling(object):
"""Class of a single dwelling or of a aggregated group of dwelling"""

def __init__(self, coordinates, dwtype, house_id, age, hlc, pop, floor_area, temp):
def __init__(self, coordinates, dwtype, house_id, age, pop, floor_area, temp):
"""Returns a new dwelling object.
Parameters
Expand Down Expand Up @@ -78,4 +78,48 @@ def get_hlc(dw_type, age):
# Get linearly fitted value
hlc = linear_fits_hlc[dw_type][0] * age + linear_fits_hlc[dw_type][1]
return hlc


class BuildingStockRegion(object):
"""Class of the building stock in a region"""

def __init__(self, region_ID, dwelling_list):
"""Returns a new building stock region object.
Parameters
----------
region_ID : float
Region ID of building stock
dwelling_list : list
List containing all dwelling objects
"""
self.region_ID = region_ID
self.dwelling_list = dwelling_list

def get_tot_pop(self):
""" Get total population"""
totpop = 0
for dwelling in self.dwelling_list:
totpop += dwelling.pop()
return totpop

def get_sum_scenario_driver_water_heating(self):
""" Sum all scenario driver for water heating"""
sum_driver = 0
for dwelling in self.dwelling_list:
sum_driver += dwelling.scenario_driver_water_heating()
return sum_driver

def get_sum_scenario_driver_space_heating(self):
""" Sum all scenario driver for space heating"""
sum_driver = 0
for dwelling in self.dwelling_list:
sum_driver += dwelling.scenario_driver_space_heating()
return sum_driver

def get_sum_scenario_driver_lighting(self):
""" Sum all scenario driver for lighting heating"""
sum_driver = 0
for dwelling in self.dwelling_list:
sum_driver += dwelling.scenario_driver_lighting()
return sum_driver

189 changes: 86 additions & 103 deletions energy_demand/building_stock_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ def virtual_building_stock(data):
-----
The header row is always skipped.
"""
uniqueID = 100000
dw_stock_old, dw_stock_new = [], [] # Initialise
uniqueID = 100000 # Initialise
reg_building_stock = {}

#get_assumption_age_distribution
base_year = data['global_variables']['base_year']
base_year = data['global_variables']['base_year'] # Base year

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
Expand All @@ -52,163 +51,176 @@ def virtual_building_stock(data):

# Iterate regions
for reg_id in reg_lu:
dw_stock_old, dw_stock_new = [], [] # Initialise

# Read base data
reg_id_floor_area_by = reg_floor_area[reg_id] # Read in floor area
reg_id_dw_nr = data['reg_dw_nr'][reg_id] # Read in nr of dwellings
print("reg_floor_area: " + str(reg_id_floor_area_by))
print("reg_dw_nr: " + str(reg_id_dw_nr))
# Read base year data
floor_area_by = reg_floor_area[reg_id] # Read in floor area
dw_nr = data['reg_dw_nr'][reg_id] # Read in nr of dwellings

floor_area_p_by = p_floor_area_dwtype(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)
# Percent of floor area of base year (could be changed)
floor_area_p_by = p_floor_area_dwtype(dw_lu, dwtype_distr, dwtype_floor_area, dw_nr) # Sum must be 0

# --Scenario drivers
# base year
reg_id_pop_by = reg_pop[reg_id] # Read in population
reg_id_floor_area_pp_by = reg_id_floor_area_by / reg_id_pop_by # Floor area per person [m2/person]
reg_id_floor_area_by_pd = reg_id_floor_area_by / reg_id_dw_nr # Floor area per dwelling [m2/dwelling]
pop_by = reg_pop[reg_id] # Read in population
floor_area_pp_by = floor_area_by / pop_by # Floor area per person [m2/person]
floor_area_by_pd = floor_area_by / dw_nr # Floor area per dwelling [m2/dwelling]

# current year
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
pop_cy = pop_by * 1.5 ### #TODO: get new population
floor_area_pp_cy = floor_area_pp_by * 1.05 ### #TODO: get new floor_area_pp_by
floor_area_by_pd_cy = floor_area_by_pd * 0.1 ### #TODO:floor area per dwelling get new floor_area_by_pd (if not constant over time, cann't extrapolate for any year)

# Population
#pop_new_dw = reg_id_pop_cy - reg_id_pop_by
pop_new_dw = pop_cy - pop_by

# 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))
# Total new floor area
tot_floor_area_cy = floor_area_pp_cy * pop_cy
tot_new_floor_area = tot_floor_area_cy - floor_area_by # tot new floor area - area base year = New needed floor 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
dw_new = tot_new_floor_area / floor_area_by_pd_cy # Needed new buildings (if not constant, must calculate nr of buildings in every year)
total_nr_dw = dw_nr + dw_new # floor area / buildings

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



# ---- 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_by[dw_type_name] * total_floor_area_cy
print("Floor area of dwelling types: " + str(dw_type_floor_area))
_scrap_pop_old = 0
_scrap_floor_old = 0
_scrap_pop_new = 0
_scrap_floor_new = 0

## 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))
# Iterate dwelling types
for dw in dw_lu:
dw_type_id, dw_type_name = dw, dw_lu[dw]
percent_dw_type = dwtype_distr[dw_type_name] / 100 # Percentage of dwelling type
dw_type_floor_area = floor_area_p_by[dw_type_name] * floor_area_by # Floor areay of existing buildlings

# 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)
#print("dw_type_age_class_floor_area: " + str(dw_type_age_class_floor_area))

# 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))
pop_dwtype_age_class = dw_type_age_class_floor_area / floor_area_pp_cy # Existing floor area is divided by new area us per person. Distribed with floor area..could do better
#print("pop_dwtype_age_class: " + str(pop_dwtype_age_class))
#print("pop gain: " + str(pop_new_dw))
_scrap_pop_old += pop_dwtype_age_class
_scrap_floor_old += dw_type_age_class_floor_area

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

dw_stock_old.append(bf.Dwelling(['X', 'Y'], dw_type_id, uniqueID, float(dwtype_age_id), _hlc, _pop_2015_dwelling_type_age_class, dw_type_age_class_floor_area, 9999))
dw_stock_old.append(bf.Dwelling(['X', 'Y'], dw_type_id, uniqueID, float(dwtype_age_id), pop_dwtype_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)
dw_type_id, dw_type_name = dw, dw_lu[dw]

print("Floor area of new buildings per dwelling types: " + str(total_floor_area_new_area))
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(tot_new_floor_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))
#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))
# Floor area of dwelling type
dw_type_floor_area = tot_new_floor_area * percent_dw_type

# 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))
pop_dwtype_dw_type = dw_type_floor_area / floor_area_pp_cy # Distribed with floor area..could do better

_scrap_pop_new += pop_dwtype_dw_type
_scrap_floor_new += dw_type_floor_area

# 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
dw_stock_new.append(bf.Dwelling(['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))
dw_stock_new.append(bf.Dwelling(['X', 'Y'], dw_type_id, uniqueID, simulation_year, pop_dwtype_dw_type/nr_sim_y, dw_type_floor_area/nr_sim_y, 9999))
uniqueID += 1

print("....")
# Test if disaggregation was good (do some tests # Todo)
print("Population old buildings: " + str(_scrap_pop_old))
print("Population new buildings: " + str(_scrap_pop_new))

print("Floor area old buildings: " + str(_scrap_floor_old))
print("Floor area new buildings: " + str(_scrap_floor_new))
print("---------------------------------------------------------------------------")
print("Total disaggregated Pop: " + str(_scrap_pop_new + _scrap_pop_old))
print("Total disagg. floor area: " + str(_scrap_floor_new + _scrap_floor_old))
print("---")
print("Population of current year: " + str(pop_cy))
print("Floor area of current year: " + str(tot_floor_area_cy))

# Generate region and save it in dictionary
reg_building_stock[reg_id] = bf.BuildingStockRegion(reg_id, dw_stock_old + dw_stock_new)

'''print("....")
for h in dw_stock_old:
print(h.__dict__)
print(".............")
for i in dw_stock_new:
print(i.__dict__)
'''

print(reg_building_stock)
print(reg_building_stock[0].get_sum_scenario_driver_water_heating())
print("oooo")
print(reg_building_stock[0].dwelling_list)
l = reg_building_stock[0].dwelling_list
for i in l:
print(i.__dict__)
prnt("..")

return dw_stock_old, dw_stock_new



# -----------Calculate the share of total floor area beloinging to each dwelling type-----------
def p_floor_area_dwtype(dw_lookup, dw_dist, dw_floor_area, reg_id_dw_nr):
def p_floor_area_dwtype(dw_lookup, dw_dist, dw_floor_area, 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
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
tot_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
nr_dw_typXY = 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
tot_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]
dw_floor_area_p[i] = (1/tot_floor_area_cy)*dw_floor_area_p[i]

return dw_floor_area_p




"""
# (1) Distribution of dwellings per type
# (2) Age distribution of dwellings
Expand Down Expand Up @@ -242,48 +254,19 @@ def p_floor_area_dwtype(dw_lookup, dw_dist, dw_floor_area, reg_id_dw_nr):
# Input from real world
# ---------------------
- nr_dwellings
- total_floor_area_cy
- tot_floor_area_cy
- distribution of dwelling types
- total population
- XY coordinates
- Pop_ID
-
# Generate Real World Building Stock
ID, X, Y,
# Average population per dwelling type
# Average floor area per dwelling type
"""




'''class Town_region(object):
"""Region with dwellings in it

"""

def __init__(self, town_name, nr_houses):
self.town_name = town_name # Town Name
self.nr_houses = nr_houses # Number of houses
self.INPUTARGUMENTSBUILDINGS = INPUTARGUMENTSBUILDINGS
# Create town
building_list = []
for i in range(self.nr_houses):
_house = INPUTARGUMENTSBUILDINGS[i]House([23,23], 2323, 1983, 0.7, 10,)
building_list.append(_house)
self.building_list = building_list
def S_D(self):
SUM_DRIVERS = 0
for _house in self.building_list:
SUM_DRIVERS += _house.scenario_driver()
print("SS: " + str(SUM_DRIVERS))
return SUM_DRIVERS
'''

#
"""
Expand Down
2 changes: 1 addition & 1 deletion energy_demand/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# The docs can be found here: http://ed.readthedocs.io
#"""
5#"""
# pylint: disable=I0011,C0321,C0301,C0103, C0325

#!python3.6
Expand Down

0 comments on commit 1f727c7

Please sign in to comment.