Skip to content

Commit

Permalink
added HDG to building stock generator
Browse files Browse the repository at this point in the history
  • Loading branch information
eggimasv authored and eggimasv committed Mar 2, 2017
1 parent 4590db6 commit 9bfe615
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 123 deletions.
21 changes: 16 additions & 5 deletions energy_demand/building_stock_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
class Dwelling(object):
"""Class of a single dwelling or of a aggregated group of dwelling"""

def __init__(self, coordinates, dwtype, house_id, age, pop, floorarea, temp):
def __init__(self, sim_y, coordinates, dwtype, house_id, age, pop, floorarea, HDD, assumptions):
"""Returns a new dwelling object.
Parameters
----------
sim_y : int
Simulation year
coordinates : float
coordinates
dwtype : int
Expand All @@ -21,17 +23,18 @@ def __init__(self, coordinates, dwtype, house_id, age, pop, floorarea, temp):
Dwelling population
floorarea : float
Floor area of dwelling
temp : float
Climate variable...(tbd)
int_temp : float
Internal temperatur
"""
self.sim_y = sim_y
self.house_id = house_id
self.coordinates = coordinates
self.dwtype = dwtype
self.age = age
self.hlc = get_hlc(dwtype, age) # Calculate heat loss coefficient with age and dwelling type
self.pop = pop
self.floorarea = floorarea
self.temp = temp
self.HDD = get_HDD_based_on_int_temp(sim_y, assumptions, HDD) # Get internal temperature depending on assumptions of sim_year

def scenario_driver_water_heating(self):
"""calc scenario driver with population and heat loss coefficient"""
Expand All @@ -43,7 +46,15 @@ def scenario_driver_lighting(self):

def scenario_driver_space_heating(self):
"""calc scenario driver with population and floor area"""
return self.floorarea * self.pop * self.temp * self.hlc
return self.floorarea * self.pop * self.HDD * self.hlc

def get_HDD_based_on_int_temp(sim_y, assumptions, HDD):
""" Get internal temperature based on assumptions"""
t_base_standard = 15 # Degree celsius
HDD = "tbd"
# Recalcuulate heating degree days based on internal temperature change
# Hitchins Formula
return HDD

def get_hlc(dw_type, age):
"""Calculates the linearly derived hlc depending on age and dwelling type
Expand Down
22 changes: 13 additions & 9 deletions energy_demand/building_stock_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,21 @@ def virtual_building_stock(data, assumptions, data_ext):
# Only calculate changing
uniqueID = 000 #TODO: IMProove
if sim_y == base_year:
dw_stock_base = generate_dw_existing(uniqueID, dw_lu, floorarea_p_sy[base_year], floorarea_by, dwtype_age_distr_by, floorarea_pp_by, floorarea_by, pop_by)
dw_stock_base = generate_dw_existing(uniqueID, sim_y, dw_lu, floorarea_p_sy[base_year], floorarea_by, dwtype_age_distr_by, floorarea_pp_by, floorarea_by, pop_by, assumptions)
else:
# - existing dwellings
# The number of people in the existing dwelling stock may change. Therfore calculate alos except for base year. Total floor number is assumed to be identical Here age of buildings could be changed
dw_stock_new_dwellings = generate_dw_existing(uniqueID, dw_lu, floorarea_p_sy[base_year], floorarea_by, dwtype_age_distr_by, floorarea_pp_sy, floorarea_by, floorarea_by/floorarea_pp_sy)
dw_stock_new_dwellings = generate_dw_existing(uniqueID, sim_y, dw_lu, floorarea_p_sy[base_year], floorarea_by, dwtype_age_distr_by, floorarea_pp_sy, floorarea_by, floorarea_by/floorarea_pp_sy, assumptions)

# - new dwellings
if new_floorarea_sim_year > 0: # If new floor area new buildings are necessary
dw_stock_new_dwellings = generate_dw_new(uniqueID, sim_y, dw_lu, floorarea_p_sy[sim_y], floorarea_pp_sy, dw_stock_new_dwellings, new_floorarea_sim_year)
dw_stock_new_dwellings = generate_dw_new(uniqueID, sim_y, dw_lu, floorarea_p_sy[sim_y], floorarea_pp_sy, dw_stock_new_dwellings, new_floorarea_sim_year, assumptions)

# Generate region and save it in dictionary
reg_building_stock_cur_yr[reg_id] = bf.DwStockRegion(reg_id, dw_stock_new_dwellings) # Add old and new buildings to stock
reg_building_stock_by[reg_id] = bf.DwStockRegion(reg_id, dw_stock_base) # Add base year stock

'''print("Base dwelling")
print("Base dwelling")
print(reg_building_stock_by[0].get_tot_pop())
l = reg_building_stock_by[0].dwellings
for i in l:
Expand All @@ -94,7 +94,7 @@ def virtual_building_stock(data, assumptions, data_ext):
l = reg_building_stock_cur_yr[0].dwellings
for i in l:
print(i.__dict__)
'''

# Add to data
data['reg_building_stock_by'] = reg_building_stock_by
data['reg_building_stock_cur_yr'] = reg_building_stock_cur_yr
Expand Down Expand Up @@ -231,7 +231,7 @@ def p_floorarea_dwtype(dw_lookup, dw_floorarea_by, dw_nr_by, dwtype_distr_sim):
return dw_floorarea_p
'''

def generate_dw_existing(uniqueID, dw_lu, floorarea_p, floorarea_by, dwtype_age_distr_by, floorarea_pp_by, tot_floorarea_cy, pop_by):
def generate_dw_existing(uniqueID, sim_y, dw_lu, floorarea_p, floorarea_by, dwtype_age_distr_by, floorarea_pp_by, tot_floorarea_cy, pop_by, assumptions):
"""Generates dwellings according to age, floor area and distribution assumptsion"""

dw_stock_base, control_pop, control_floorarea = [], 0, 0
Expand All @@ -253,8 +253,10 @@ def generate_dw_existing(uniqueID, dw_lu, floorarea_p, floorarea_by, dwtype_age_
pop_dwtype_age_class = dw_type_age_class_floorarea / floorarea_pp_by # Floor area is divided by base area value
control_pop += pop_dwtype_age_class

HDD = 199 #TODO: Get_regional_HDD()

# create building object
dw_stock_base.append(bf.Dwelling(['X', 'Y'], dw_type_id, uniqueID, float(dwtype_age_id), pop_dwtype_age_class, dw_type_age_class_floorarea, 9999))
dw_stock_base.append(bf.Dwelling(sim_y, ['X', 'Y'], dw_type_id, uniqueID, float(dwtype_age_id), pop_dwtype_age_class, dw_type_age_class_floorarea, HDD, assumptions))
uniqueID += 1

# TODO: IF Necessary calculate absolute number of buildings by dividng by the average floor size of a dwelling
Expand All @@ -265,7 +267,7 @@ def generate_dw_existing(uniqueID, dw_lu, floorarea_p, floorarea_by, dwtype_age_

return dw_stock_base

def generate_dw_new(uniqueID, sim_y, dw_lu, floorarea_p_by, floorarea_pp_sy, dw_stock_new_dwellings, new_floorarea_sim_year):
def generate_dw_new(uniqueID, sim_y, dw_lu, floorarea_p_by, floorarea_pp_sy, dw_stock_new_dwellings, new_floorarea_sim_year, assumptions):
"""Generate objects for all new dwellings
All new dwellings are appended to the existing building stock of the region
Expand Down Expand Up @@ -304,7 +306,9 @@ def generate_dw_new(uniqueID, sim_y, dw_lu, floorarea_p_by, floorarea_pp_sy, dw_

# create building object
#Todo: Add climate??/internal heat data
dw_stock_new_dwellings.append(bf.Dwelling(['X', 'Y'], dw_type_id, uniqueID, sim_y, pop_dwtype_sim_year_new_build, dw_type_floorarea_new_build, 9999))
HDD = 199 #get_region_HDD()

dw_stock_new_dwellings.append(bf.Dwelling(sim_y, ['X', 'Y'], dw_type_id, uniqueID, sim_y, pop_dwtype_sim_year_new_build, dw_type_floorarea_new_build, HDD, assumptions))
uniqueID += 1

assert round(new_floorarea_sim_year, 3) == round(control_floorarea, 3) # Test if floor area are the same
Expand Down
118 changes: 9 additions & 109 deletions energy_demand/technological_stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@ def __init__(self, reg, year, assumptions, e_boiler_A, e_boiler_B):
self.assumptions = assumptions

# Residential

#Appliances
## Lighting


## Heating
self.e_boiler_A = e_boiler_A
self.e_boiler_B = e_boiler_B


# Fraction of technologies
# Calculate fraction of technologies
self.e_boiler_A = get_share_sim_year(self.year, assumptions['distr_e_boiler_A']) #, baseyear, assumptions) # Input how the fraction will change over time

# Efficiencies of technologies
Expand All @@ -32,7 +37,7 @@ def __init__(self, reg, year, assumptions, e_boiler_A, e_boiler_B):
def technological_driver_efficiencies_boilers(self):
"""calc scenario driver based on technological efficiencies and sigmoid uptake"""

return self.e_boiler_A * self.eff_e_boiler_A + self.e_boiler_B * self.eff_e_boiler_B
return self.e_boiler_A * self.eff_e_boiler_A + self.e_boiler_B * self.eff_e_boiler_B

'''def get_share_sim_year(year, technology_distr_assump):
Expand All @@ -50,109 +55,4 @@ def technological_driver_efficiencies_boilers(self):
assumptions = { 'distr_e_boiler_A': {'base': 0.8, 'year_step1': 0.9},
'distr_e_boiler_B': {'base': 0.2, 'year_step1': 0.05},
'distr_g_boiler_D': {'base': 0.0, 'year_step1': 0.05},
}


def linearDiffusion(current_year, base_year, fract_by, fract_ey, sim_years):
"""This function assumes a linear technology diffusion.
All necessary data to run energy demand model is loaded.
This data is loaded in the wrapper.
Parameters
----------
current_year : int
The year of the current simulation.
base_year : int
The year of the current simulation.
fract_by : float
Fraction of population served with technology in base year
fract_ey : float
Fraction of population served with technology in end year
sim_years : str
Total number of simulated years.
Returns
-------
fract_sy : float
The fraction of the technology in the simulation year
"""
if current_year == base_year:
fract_sy = fract_by
else:
fract_sy = fract_by + ((fract_ey - fract_by) / sim_years) * (current_year - base_year)

return fract_sy


def sigmoidEfficiencyPos(base_year, year_end, current_year):
"""Calculates a sigmoid diffusion path of a lower to a higher value (saturation is assumed at the endyear)"""

# TODO: READ IN START AND END AND DECIDE IF NEG OR POSITIVE DIFFUSTION
# CREATE POSITIVE AND NEGATIVE DIFFUSION
# Translates simulation year on the sigmoid graph reaching from -6 to +6 (x-value)
y_trans = -6 + (12 /(year_end - base_year) * (current_year - base_year))

# Convert x-value into y value on sigmoid curve reaching from -6 to 6
sigmoidmidpoint = 0 # Can be used to shift curve to the left or right (standard value: 0)
sigmoidsteepness = 1 # The steepness of the sigmoid curve (standard value: 1)

# Get a value between 0 and 1 (sigmoid curve ranging vrom 0 to 1)
val_yr = 1 / (1 + m.exp(-1 * sigmoidsteepness * (y_trans - sigmoidmidpoint)))

return val_yr

def sigmoidTechnologyDiffusion(current_year, saturate_year, year_invention, base_year):
"""This function assumes "S"-Curve technology diffusion (logistic function).
The function reads in the following assumptions about the technology to calculate the
current distribution of the simulated year:
Parameters
----------
current_year : int
The year of the current simulation
saturate_year : int
The year a technology saturaes
year_invention : int
The year where a technology gets on the market
base_year : int
Base year of simulation period
Returns
-------
val_yr : float
The fraction of the technology in the simulation year
"""
# Check how many years technology in the market
if current_year < year_invention:
val_yr = 0
return val_yr
else:
if current_year >= saturate_year:
years_availalbe = saturate_year - base_year
else:
years_availalbe = current_year - year_invention

# Translates simulation year on the sigmoid graph reaching from -6 to +6 (x-value)
year_translated = -6 + (12/(saturate_year - year_invention)) * years_availalbe

# Convert x-value into y value on sigmoid curve reaching from -6 to 6
sigmoidmidpoint = 0 # Can be used to shift curve to the left or right (standard value: 0)
sigmoidsteepness = 1 # The steepness of the sigmoid curve (standard value: 1)

# Get a value between 0 and 1 (sigmoid curve ranging vrom 0 to 1)
val_yr = 1 / (1 + m.exp(-1 * sigmoidsteepness * (year_translated - sigmoidmidpoint)))

return val_yr

for i in range(2015, 2050):
print("year: " + str(i) + " " + str(sigmoidTechnologyDiffusion(i, 2100, 2020, 2015)))
}
106 changes: 106 additions & 0 deletions energy_demand/technological_stock_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
""" Functions for technology stock"""


def linearDiffusion(current_year, base_year, fract_by, fract_ey, sim_years):
"""This function assumes a linear technology diffusion.
All necessary data to run energy demand model is loaded.
This data is loaded in the wrapper.
Parameters
----------
current_year : int
The year of the current simulation.
base_year : int
The year of the current simulation.
fract_by : float
Fraction of population served with technology in base year
fract_ey : float
Fraction of population served with technology in end year
sim_years : str
Total number of simulated years.
Returns
-------
fract_sy : float
The fraction of the technology in the simulation year
"""
if current_year == base_year:
fract_sy = fract_by
else:
fract_sy = fract_by + ((fract_ey - fract_by) / sim_years) * (current_year - base_year)

return fract_sy


def sigmoidEfficiencyPos(base_year, year_end, current_year):
"""Calculates a sigmoid diffusion path of a lower to a higher value (saturation is assumed at the endyear)"""

# TODO: READ IN START AND END AND DECIDE IF NEG OR POSITIVE DIFFUSTION
# CREATE POSITIVE AND NEGATIVE DIFFUSION
# Translates simulation year on the sigmoid graph reaching from -6 to +6 (x-value)
y_trans = -6 + (12 /(year_end - base_year) * (current_year - base_year))

# Convert x-value into y value on sigmoid curve reaching from -6 to 6
sigmoidmidpoint = 0 # Can be used to shift curve to the left or right (standard value: 0)
sigmoidsteepness = 1 # The steepness of the sigmoid curve (standard value: 1)

# Get a value between 0 and 1 (sigmoid curve ranging vrom 0 to 1)
val_yr = 1 / (1 + m.exp(-1 * sigmoidsteepness * (y_trans - sigmoidmidpoint)))

return val_yr

def sigmoidTechnologyDiffusion(current_year, saturate_year, year_invention, base_year):
"""This function assumes "S"-Curve technology diffusion (logistic function).
The function reads in the following assumptions about the technology to calculate the
current distribution of the simulated year:
Parameters
----------
current_year : int
The year of the current simulation
saturate_year : int
The year a technology saturaes
year_invention : int
The year where a technology gets on the market
base_year : int
Base year of simulation period
Returns
-------
val_yr : float
The fraction of the technology in the simulation year
"""
# Check how many years technology in the market
if current_year < year_invention:
val_yr = 0
return val_yr
else:
if current_year >= saturate_year:
years_availalbe = saturate_year - base_year
else:
years_availalbe = current_year - year_invention

# Translates simulation year on the sigmoid graph reaching from -6 to +6 (x-value)
year_translated = -6 + (12/(saturate_year - year_invention)) * years_availalbe

# Convert x-value into y value on sigmoid curve reaching from -6 to 6
sigmoidmidpoint = 0 # Can be used to shift curve to the left or right (standard value: 0)
sigmoidsteepness = 1 # The steepness of the sigmoid curve (standard value: 1)

# Get a value between 0 and 1 (sigmoid curve ranging vrom 0 to 1)
val_yr = 1 / (1 + m.exp(-1 * sigmoidsteepness * (year_translated - sigmoidmidpoint)))

return val_yr

#for i in range(2015, 2050):
# print("year: " + str(i) + " " + str(sigmoidTechnologyDiffusion(i, 2100, 2020, 2015)))

0 comments on commit 9bfe615

Please sign in to comment.