Skip to content

Commit

Permalink
Working on housing stock
Browse files Browse the repository at this point in the history
  • Loading branch information
eggimasv authored and eggimasv committed Feb 23, 2017
1 parent d385d99 commit 6fb8946
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 82 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
7 changes: 3 additions & 4 deletions data/residential_model/lookup_dwelling_type.csv
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
DWELLING_TYPE_NR,DWELLING_TYPE
0,Detached
1,Semi-Detached
2,Mid-Terrace
3,End-Terrace
4,Flat
5,Bungalow
2,Terraced (mid_end)
3,Flat
4,Bungalow
1 change: 1 addition & 0 deletions energy_demand/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__all__ = []
6 changes: 2 additions & 4 deletions energy_demand/building_stock_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,8 @@ def get_hlc(dw_type, age):
0: [-0.0223, 48.292], # Detached
1: [-0.0223, 48.251], # Semi-Detached
2: [-0.0223, 48.063], # Terraced Average
3: [-0.0223, ], # Data but not used
4: [-0.0223, ], # Data but not used
5: [-0.0223, 48.261], # Bungalow
6: [-0.0223, 48.063] # Terraced average
3: [-0.0223, 47.02], # Flats
4: [-0.0223, 48.261], # Bungalow
}

# Get linearly fitted value
Expand Down
153 changes: 147 additions & 6 deletions energy_demand/building_stock_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,163 @@
from pprint import pprint
import building_stock_functions as bf
from main_functions import read_csv

import numpy as np
# pylint: disable=I0011,C0321,C0301,C0103, C0325

# Read in
# Data
# ---------------------------------------------------------------
path_main = r'C:/Users/cenv0553/GIT/NISMODII/data/' # Remove
path_pop_reg_lu = os.path.join(path_main, 'residential_model/energy_fact_file_housing_stock_age.csv')

dw_age_distribution = read_csv(path_pop_reg_lu, float)
print(dw_age_distribution)
print("re")
# Age distribution of building stock for a given year
path_age_dw_types = os.path.join(path_main, 'residential_model/energy_fact_file_housing_stock_age.csv')
#dw_age_distribution = read_csv(path_age_dw_types, float)
dw_dist_age = {2015: {1918: 20.8, 1928: 36.3, 1949: 29.4, 1968: 8.0, 1995: 5.4}} # year, average_age, percent

# Percentages of dwelling types for a given year (%)
dw_dist = {2015: {0: 16.6, 1: 26.0, 2: 28.2, 3: 20.4, 4: 8.8}} # Year, dwellintype, percentage

#Floor Area: The usubale floor area is taken rom (Annex Table 3.1 Housing Supply)
dw_floor_area = {0: 147, 1: 96, 2: 82.5, 3: 61, 4: 77} # Id, average m2 of dw_type

# Dwelling types
dw_lookup = np.array(([0, 'Detached'], [1, 'Semi-Detached'], [2, 'Terraced (mid_end)'], [3, 'Flat'], [4, 'Bungalow']))

# Assumptions
pop2015_by = 100 # [person]
floor_area_by = 2000 # [m2]
nr_dw = 55 # [nr of buildings]
pop2015_new = 200 # [person]

# Factors to calculate
floor_area_per_person_base_year_by = floor_area_by / pop2015_by # [m2/person] Floor area per person
floor_area_per_building_by = floor_area_by / nr_dw # [m2/dw] meter per building
persons_per_build = pop2015_by / nr_dw # [pers/build]



# -----------Calculate the share of total floor area beloinging to each dwelling type-----------
total_floor_area = 0
dw_floor_area_percent = {} # initialise

for row in dw_lookup:
# Get number of building of dwellin type
percent_buildings_dw = (dw_dist[2015][int(row[0])])/100
nr_dw_typXY = nr_dw * percent_buildings_dw

# absolute usable floor area per dwelling type
fl_type = nr_dw_typXY * dw_floor_area[int(row[0])]

# sum total area
total_floor_area += 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]
dw_floor_area_percent[i] = _

print("Percentage of total floor area belonging to each dwelling type: " + str(dw_floor_area_percent))

# -----------Generate building stock
building_stock = []
cnt = 1

# Iterate housing type array
for row in dw_lookup:

# Dwelling type
dw_type_ID = int(row[0])

# Iterate over years
for age in dw_dist_age[2015]:
uniqueID = 555 + cnt

# share of buildings belonging to this age class
dw_are_class_percentage = dw_dist_age[2015][age]/100

# Age class
year = age

# get hcl
_hlc = bf.get_hlc(dw_type_ID, age)

# Settlment type
# --
# Get floor area of this dwelling type
floor_area_share_dw = dw_floor_area_percent[dw_type_ID] # prozent
floor_area_share_dw_of_ttal = floor_area_share_dw * floor_area_by # absolut


# Share of population for this dwelling type (distribute pop according to floor area)
_pop_2015_dwelling_type = floor_area_share_dw_of_ttal / floor_area_per_person_base_year_by

print("_pop_2015_dwelling_type " + str(_pop_2015_dwelling_type))

# Age class (because only comparison within the same dwelling class, we can redistribute buildlings with floor area)
# Get floor area of dwellin type age class
floor_area_dw_age_ttal = floor_area_share_dw_of_ttal * dw_are_class_percentage

_pop_2015_dwelling_type_age_class = floor_area_dw_age_ttal / floor_area_per_person_base_year_by
print("_pop_2015_dwelling_type_age_class:" + str(_pop_2015_dwelling_type_age_class))

# Create House object
dw_type_ID_houses = bf.House(['X', 'Y'], uniqueID, year, _hlc, _pop_2015_dwelling_type_age_class, floor_area_dw_age_ttal, 9999)
building_stock.append(dw_type_ID_houses)

print("Buillding Stock: " + str(len(building_stock)))
for i in building_stock:
print(i.__dict__)

_ = 0
for i in building_stock:
_ += i.pop
print("TOTAL SUM: " + str(_))
prnt("..")



# --------------- calculations with scenario

#print(dw_age_distribution)
#print("re")





print(" BASE YEAR")
print("-------------")
print("pop2015_by: " + str(pop2015_by))
print("floor_area_by " + str(floor_area_by))
print("nr_dw " + str(nr_dw))
print("floor_area_per_person_base_year_by: " + str(floor_area_per_person_base_year_by))
print("floor_area_per_building_by: " + str(floor_area_per_building_by))
print("persons_per_build: " + str(persons_per_build))
print()

# Scenario assumptions: Increase floor area per person by 1% and reduce number of persons per buildin by 1 %
floor_area_per_person_base_scen_year = (floor_area_per_person_base_year_by/100) * (100 + 1)
persons_per_build_scen_year = (persons_per_build/100) * (100 - 1)
floor_area_per_building_new = floor_area_per_building_by # Assume that floor area per building remains constant (houses are not getting bigger then)

print("floor_area_per_person_base_scen_year: " + str(floor_area_per_person_base_scen_year))
#print("persons_per_build_new " + str(persons_per_build_scen_year))

# Calculate new nr of Buildings
new_floor_area = (pop2015_new * floor_area_per_person_base_scen_year)
nr_dw_new = new_floor_area / floor_area_per_building_new

print(" NEw Floor area: " + str(new_floor_area))
print("New number of houses: " + str(nr_dw_new))
print(" New houses to build: " + str(nr_dw_new - nr_dw))



# (1) Distribution of dwellings per type
# (2) Age distribution of dwellings
# (3) Average floor area per type
# (4) Renovations?
# (5) New houses

dwelling_number = 1000
house_id = ""
Expand Down
103 changes: 40 additions & 63 deletions energy_demand/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,25 @@ def load_data():
Returns
-------
load_data_dict : list
data : list
Returns a list where all datas are wrapped together.
Notes
-----
"""
# Global variables
YEAR_SIMULATION = 2015 # Provide year for which to run the simulation
P1_YEAR_BASE = 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


# -------------------
# Local paths to data
# -------------------
#path_main = '../data'

#------Store all paths to data in dict-------------------
#path_main = '../data'
path_main = r'C:/Users/cenv0553/GIT/NISMODII/data/' # Remove
paths_dict = {'path_pop_reg_lu': os.path.join(path_main, 'scenario_and_base_data/lookup_nr_regions.csv'),
'path_pop_reg_base': os.path.join(path_main, 'scenario_and_base_data/population_regions.csv'),
Expand All @@ -65,31 +71,16 @@ def load_data():
'path_base_data_fuel': os.path.join(path_main, 'scenario_and_base_data/base_data_fuel.csv'),
'path_temp_2015': os.path.join(path_main, 'residential_model/CSV_YEAR_2015.csv'),
'path_hourly_gas_shape': os.path.join(path_main, 'residential_model/residential_gas_hourly_shape.csv')
#path_seasons_lookup = os.path.join(path_main, 'scenario_and_base_data/lookup_season.csv')
}

#path_seasons_lookup = os.path.join(path_main, 'scenario_and_base_data/lookup_season.csv')

# Global variables
YEAR_SIMULATION = 2015 # Provide year for which to run the simulation
P1_YEAR_BASE = 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

# ------------------
# Read in all data from csv files
# ------------------
# ------Read in all data from csv files-------------------
data = mf.read_data(paths_dict)

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

# ---------------------------------------------------------------
# Base demand for the base year for all modelled elements
# ---------------------------------------------------------------
# ------Base demand for the base year for all modelled elements-------------------

# Base demand of appliances over a full year (electricity)
bd_app_elec = mf.get_bd_appliances(shape_app_elec, data['reg_lu'], data['fuel_type_lu'], data['fuel_bd_data'])
Expand Down Expand Up @@ -133,35 +124,35 @@ def load_data():
print("Sum heating emand simulation period: " + str(timesteps_hd_bd.sum()))
print(" ")

load_data_dict = {'SIM_PARAM': SIM_PARAM,
'fuel_type_lu': data['fuel_type_lu'],
'dwelling_type_lu': ['dwelling_type_lu'],
'reg_pop': ['reg_pop'],
'fuel_bd_data': ['fuel_bd_data'],
'csv_temp_2015': ['csv_temp_2015'],
'hourly_gas_shape': ['hourly_gas_shape'],
'shape_app_elec': shape_app_elec,
'shape_hd_gas': shape_hd_gas,
'bd_app_elec': bd_app_elec,
'bd_hd_gas': bd_hd_gas,
'timesteps_app_bd': timesteps_app_bd,
'timesteps_hd_bd': timesteps_hd_bd,
'timesteps_own_selection': timesteps_own_selection}
data_dict = {'SIM_PARAM': SIM_PARAM,
'fuel_type_lu': data['fuel_type_lu'],
'dwelling_type_lu': ['dwelling_type_lu'],
'reg_pop': ['reg_pop'],
'fuel_bd_data': ['fuel_bd_data'],
'csv_temp_2015': ['csv_temp_2015'],
'hourly_gas_shape': ['hourly_gas_shape'],
'shape_app_elec': shape_app_elec,
'shape_hd_gas': shape_hd_gas,
'bd_app_elec': bd_app_elec,
'bd_hd_gas': bd_hd_gas,
'timesteps_app_bd': timesteps_app_bd,
'timesteps_hd_bd': timesteps_hd_bd,
'timesteps_own_selection': timesteps_own_selection}

#todo: reduce variables
return load_data_dict
return data_dict

# ---------------------------------------------------------------
# Run Model
# ---------------------------------------------------------------
def energy_demand_model(load_data_dict, pop_data_external):
def energy_demand_model(data, pop_data_external):
"""Main function to run energy demand module
This function is executed in the wrapper.
Parameters
----------
load_data_dict : dict
data : dict
A list containing all data not provided externally
pop_data_external : dict
Expand All @@ -181,7 +172,6 @@ def energy_demand_model(load_data_dict, pop_data_external):
"""


# Get input and convert into necessary formats
# -------------------------------------------------

Expand All @@ -193,28 +183,14 @@ def energy_demand_model(load_data_dict, pop_data_external):
reg_pop = np.array(l, dtype=float)

#print ("Energy Demand Model - Main funtion simulation parameter: " + str(SIM_PARAM))
SIM_PARAM = load_data_dict['SIM_PARAM']
fuel_type_lu = load_data_dict['fuel_type_lu']
#dwelling_type_lu = load_data_dict['dwelling_type_lu']
#reg_pop = load_data_dict['reg_pop']
#fuel_bd_data = load_data_dict['fuel_bd_data']
#csv_temp_2015 = load_data_dict['csv_temp_2015']
#hourly_gas_shape = load_data_dict['hourly_gas_shape']
shape_app_elec = load_data_dict['shape_app_elec']
#shape_hd_gas = load_data_dict['shape_hd_gas']
#bd_app_elec = load_data_dict['bd_app_elec']
#bd_hd_gas = load_data_dict['bd_hd_gas']
timesteps_app_bd = load_data_dict['timesteps_app_bd']
timesteps_hd_bd = load_data_dict['timesteps_hd_bd']
timesteps_own_selection = load_data_dict['timesteps_own_selection']

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

# Run different sub-models (sector models)
e_app_bd, g_hd_bd = residential_model.run(SIM_PARAM, shape_app_elec, reg_pop, timesteps_app_bd, timesteps_hd_bd)
e_app_bd, g_hd_bd = residential_model.run(data['SIM_PARAM'], data['shape_app_elec'], reg_pop, data['timesteps_app_bd'], data['timesteps_hd_bd'])

'''
transportation_model.run(modelrun_id, year, year_base, year_curr, total_yr, cur_yr)
Expand All @@ -229,21 +205,22 @@ def energy_demand_model(load_data_dict, pop_data_external):
# Generate the wrapper timesteps and add instert data (from own timeperiod to full year)
print("Generate resutls for wrapper (read into nested dictionary")
# ---------------------------------------------------------------------------
timesteps, yaml_list = mf.timesteps_full_year() # Create timesteps for full year (wrapper-timesteps)
result_dict = mf.init_dict_energy_supply(fuel_type_lu, reg_pop, timesteps) # Initialise nested Dicionatry for wrapper (Fuel type, region, hour)
timesteps, _ = mf.timesteps_full_year() # Create timesteps for full year (wrapper-timesteps)

# Initialise nested Dicionatry for wrapper (Fuel type, region, hour)
result_dict = mf.init_dict_energy_supply(data['fuel_type_lu'], reg_pop, timesteps)

# Add electricity data to result dict for wrapper
fuel_type = 0 # Elec
result_dict = mf.add_demand_result_dict(e_app_bd, fuel_type_lu, reg_pop, fuel_type, timesteps, result_dict, timesteps_own_selection)
result_dict = mf.add_demand_result_dict(0, e_app_bd, data['fuel_type_lu'], reg_pop, timesteps, result_dict, data['timesteps_own_selection'])

# Add gas data
fuel_type = 1 # gas
result_dict = mf.add_demand_result_dict(g_hd_bd, fuel_type_lu, reg_pop, fuel_type, timesteps, result_dict, timesteps_own_selection)
result_dict = mf.add_demand_result_dict(1, g_hd_bd, data['fuel_type_lu'], reg_pop, timesteps, result_dict, data['timesteps_own_selection'])

# Write YAML file
yaml_write = False
if yaml_write: # == True:
import yaml
_, yaml_list = mf.timesteps_full_year() # Create timesteps for full year (wrapper-timesteps)
path_YAML = 'C:/Users/cenv0553/GIT/NISMODII/TESTYAML.yaml' # l = [{'id': value, 'start': 'p', 'end': 'P2', }
with open(path_YAML, 'w') as outfile:
yaml.dump(yaml_list, outfile, default_flow_style=False)
Expand Down

0 comments on commit 6fb8946

Please sign in to comment.