Skip to content

Commit

Permalink
bug fix main
Browse files Browse the repository at this point in the history
  • Loading branch information
eggimasv authored and eggimasv committed Feb 23, 2017
1 parent 6fb8946 commit 1046a8e
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 49 deletions.
27 changes: 14 additions & 13 deletions energy_demand/building_stock_generator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sys
import os
import sys, os
from pprint import pprint
import building_stock_functions as bf
from main_functions import read_csv
Expand All @@ -25,32 +24,35 @@
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]
pop2015_by = 100 # [person]
floor_area_by = 2000 # [m2]
nr_dw = 55 # [nr of buildings]
pop2015_new = 200 # [person]

# Factors to calculate
# Derived factors
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]

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-----------
def get_percent_floor_area_per_dw_type():

return

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
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
total_floor_area += fl_type
dw_floor_area_percent[int(row[0])] = fl_type # add absolute are ato dict

# Convert absolute values into percentages
Expand Down Expand Up @@ -92,7 +94,6 @@

# 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)
Expand Down
31 changes: 11 additions & 20 deletions energy_demand/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#!python3.6

#TODOs data Different appliances for cold/hot extremes, data Heating fro min_max climate
# NOCHT TUN ata Different appliances for cold/hot extremes, data Heating fro min_max climate

import sys
import os
Expand Down Expand Up @@ -49,13 +49,13 @@ def load_data():
"""
# Global variables
YEAR_SIMULATION = 2015 # Provide year for which to run the simulation
#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

#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


#------Store all paths to data in dict-------------------
Expand Down Expand Up @@ -109,12 +109,10 @@ def load_data():
own_timesteps = mf.own_timesteps(timesteps_own_selection)

# Populate timesteps base year data (appliances, electricity)
fuel_type = 0 # elec
timesteps_app_bd = mf.create_timesteps_app(timesteps_own_selection, fuel_type, bd_app_elec, data['reg_lu'], data['fuel_type_lu'], data['app_type_lu'], own_timesteps) # [GWh]
timesteps_app_bd = mf.create_timesteps_app(0, timesteps_own_selection, bd_app_elec, data['reg_lu'], data['fuel_type_lu'], data['app_type_lu'], own_timesteps) # [GWh]

# Populate timesteps base year data (heating demand, ga)
fuel_type = 1 #gas
timesteps_hd_bd = mf.create_timesteps_hd(timesteps_own_selection, fuel_type, bd_hd_gas, data['reg_lu'], data['fuel_type_lu'], own_timesteps) # [GWh]
timesteps_hd_bd = mf.create_timesteps_hd(1, timesteps_own_selection, bd_hd_gas, data['reg_lu'], data['fuel_type_lu'], own_timesteps) # [GWh]

print("----------------------Statistics--------------------")
print("Number of timesteps appliances: " + str(len(timesteps_app_bd[0][0])))
Expand Down Expand Up @@ -216,17 +214,10 @@ def energy_demand_model(data, pop_data_external):
# Add gas data
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)
# Write YAML File
#mf.write_YAML(False, 'C:/Users/cenv0553/GIT/NISMODII/TESTYAML.yaml')

# Write function to also write out results

print("FINAL Fueltype: " + str(len(result_dict)))
print("FINAL region: " + str(len(result_dict[0])))
print("FINAL timesteps: " + str(len(result_dict[0][0])))
Expand Down
47 changes: 31 additions & 16 deletions energy_demand/main_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,16 @@ def get_dates_datelist(date_list):
timestep_dates.append(j)
return timestep_dates

def create_timesteps_app(date_list, fuel_type, bd_app_elec, reg_lu, fuel_type_lu, app_type_lu, timestep_dates):
def create_timesteps_app(fuel_type, date_list, bd_app_elec, reg_lu, fuel_type_lu, app_type_lu, timestep_dates):
"""Creates the timesteps for which the energy demand of the appliances is calculated.
Then base energy demand is added for each timestep read in from yearly demand aray.
Parameters
----------
date_list : list
Contaings lists with start and end dates
fuel_type : int
Fuel type
date_list : list
Contaings lists with start and end dates
bd_app_elec : list
Base demand applications (electricity)
reg_lu : list
Expand Down Expand Up @@ -235,7 +235,7 @@ def create_timesteps_app(date_list, fuel_type, bd_app_elec, reg_lu, fuel_type_lu

return data_timesteps_elec

def create_timesteps_hd(date_list, fuel_type, bd_hd_gas, reg_lu, fuel_type_lu, timestep_dates): # TODO: HIER GIBTS NOCH ERROR
def create_timesteps_hd(fuel_type, date_list, bd_hd_gas, reg_lu, fuel_type_lu, timestep_dates): # TODO: HIER GIBTS NOCH ERROR
'''
This function creates the simulation time steps for which the heating energy is calculated.
Then it selects energy demand from the yearl list for the simulation period.
Expand Down Expand Up @@ -627,27 +627,28 @@ def get_bd_hd_gas(shape_hd_gas, reg_lu, fuel_type_lu, fuel_bd_data):
return fuel_type_per_region_hourly

def conversion_ktoe_gwh(data_ktoe):
""" Conversion of ktoe to gwh according to
https://www.iea.org/statistics/resources/unitconverter/
Arguments
=========
-data_ktoe [float] Energy demand in ktoe
"""Conversion of ktoe to gwh
Parameters
----------
data_ktoe : float
Energy demand in ktoe
Returns
=========
-data_gwh [float] Energy demand in GWh
-------
data_gwh : float
Energy demand in GWh
Notes
-----
https://www.iea.org/statistics/resources/unitconverter/
"""

data_gwh = data_ktoe * 11.6300000

return data_gwh


# ------------------------- New Code



def timesteps_full_year():
'''Creates list with every date of the base year
Expand Down Expand Up @@ -898,3 +899,17 @@ def read_data(paths_dict):
data['hourly_gas_shape'] = hourly_gas_shape

return data

def write_YAML(yaml_write, path_YAML):
""" Creates a YAML file with the timesteps IDs
l = [{'id': value, 'start': 'p', 'end': 'P2', }
"""
if yaml_write:
import yaml
_, yaml_list = mf.timesteps_full_year() # Create timesteps for full year (wrapper-timesteps)

with open(path_YAML, 'w') as outfile:
yaml.dump(yaml_list, outfile, default_flow_style=False)
return

0 comments on commit 1046a8e

Please sign in to comment.