Skip to content

Commit

Permalink
Deleted main parts of old model. Goold Version to Fall back....
Browse files Browse the repository at this point in the history
  • Loading branch information
eggimasv authored and eggimasv committed Mar 16, 2017
1 parent 369e21a commit 55fc3ed
Show file tree
Hide file tree
Showing 16 changed files with 184,052 additions and 52,813 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fuel_id,light,cold,wet,consumer_electronics,home_computing,cooking,heating
0,0,0,0,0,0,0,100
1,0,0,0,0,0,0,100
2,1002,1037,1306,1838,549,1138,0
3,0,0,0,0,0,0,100
4,0,0,0,0,0,0,100
5,0,0,0,0,0,0,0
6,0,0,0,0,0,0,0
16 changes: 8 additions & 8 deletions data/residential_model/data_residential_by_fuel_end_uses.csv
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
fuel_id,light,cold,wet,consumer_electronics,home_computing,cooking,heating
0,0,0,0,0,0,0,100
1,0,0,0,0,0,0,100
2,1002,1037,1306,1838,549,1138,0
3,0,0,0,0,0,0,100
4,0,0,0,0,0,0,100
5,0,0,0,0,0,0,0
6,0,0,0,0,0,0,0
fuel_id,light
0,100
1,100
2,1002
3,100
4,100
5,100
6,100
18 changes: 9 additions & 9 deletions energy_demand/building_stock_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,23 @@ def resid_build_stock(data, assumptions, data_ext):
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(reg_building_stock_by[0].get_tot_pop())
#print("Base dwelling")
#print(reg_building_stock_by[0].get_tot_pop())
l = reg_building_stock_by[0].dwellings
for i in l:
print(i.__dict__)
#for i in l:
# print(i.__dict__)

print("Curryear dwelling")
print(reg_building_stock_cur_yr[0].get_tot_pop())
##print("Curryear dwelling")
#print(reg_building_stock_cur_yr[0].get_tot_pop())
l = reg_building_stock_cur_yr[0].dwellings
for i in l:
print(i.__dict__)
#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

print(" -- Virtual Building Stock generated")
#print(" -- Virtual Building Stock generated")
return data

def p_floorarea_dwtype(dw_lookup, dw_floorarea_by, dwtype_distr_sim):
Expand Down
68 changes: 8 additions & 60 deletions energy_demand/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,82 +56,35 @@ def energy_demand_model(data, assumptions, data_ext):
All messy now...needs cleaning
"""

# NEW MODEL HERE
#import energy_demand.main_object_approach as NEWMODEL
#NEWMODEL.new_energy_demand_model(data, data_ext, assumptions)
tech_stock = ts.resid_tech_stock(data_ext['glob_var']['current_year'], data, assumptions, data_ext) #TODO ASSUMPTIONS
data['tech_stock'] = tech_stock

# Iterate REGION AND GENERATE OBJECTS
result_dict = {1: {}, 2: {}} #Number of fueltypes #TODO: Improve
# Iterate regions and generate objects
timesteps, _ = mf.timesteps_full_year() # Create timesteps for full year (wrapper-timesteps)
result_dict = mf.init_dict_energy_supply(data['fuel_type_lu'], data['reg_pop_array'], timesteps)

all_Regions = []

for reg in data['reg_lu']:
reg_dict = {}
print("Region: " + str(reg))

# Residential
a = mm.Region(reg, data, data_ext, assumptions)
hourly_all_fuels = a.tot_all_enduses_h()

gas_final = hourly_all_fuels[1]
elec = hourly_all_fuels[2]

# Convert output into dict
out_dict_gas = dict(enumerate(gas_final)) # Convert array into dict for out_read
for i in out_dict_gas:
new = dict(enumerate(out_dict_gas[i]))
out_dict_gas[i] = new

out_dict_elec = dict(enumerate((elec))) # Convert array into dict for out_read
for i in out_dict_elec:
new = dict(enumerate(out_dict_elec[i]))
out_dict_elec[i] = new
all_Regions.append(a)

result_dict[1][reg] = out_dict_gas
result_dict[2][reg] = out_dict_elec
result_dict = mf.convert_result_to_final_total_format(data, all_Regions)



'''# OLD MODEL BELOW
# Convert population data int array
data_ext = mf.add_to_data(data_ext, data_ext['population']) # Convert to array, store in data
# Run different sub-models (sector models)
# -- Residential model
e_app_bd, g_hd_bd = residential_model.run(data_ext['glob_var'], data['shape_app_elec'], data['reg_pop_array'], data_ext['reg_pop_external_array'], data['timesteps_app_bd'], data['timesteps_hd_bd'])
'''
''' # ---------------------------------------------------------------------------
# Generate the wrapper timesteps and add instert data (from own timeperiod to full year)
print("Generate resutls for wrapper (read into nested dictionary")
# ---------------------------------------------------------------------------
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'], data['reg_pop_array'], timesteps)
# Add electricity data to result dict for wrapper
#result_dict = mf.add_demand_result_dict(0, e_app_bd, data['fuel_type_lu'], data['reg_pop_array'], timesteps, result_dict, data['timesteps_own_selection'])
result_dict = mf.add_demand_result_dict(0, e_app_bd, data['fuel_type_lu'], data['reg_pop_array'], timesteps, result_dict, data['timesteps_own_selection'])
#print(result_dict[0][0])
# Add gas data
#result_dict = mf.add_demand_result_dict(1, g_hd_bd, data['fuel_type_lu'], data['reg_pop_array'], timesteps, result_dict, data['timesteps_own_selection'])
result_dict = mf.add_demand_result_dict(1, g_hd_bd, data['fuel_type_lu'], data['reg_pop_array'], timesteps, result_dict, data['timesteps_own_selection'])
'''
# Write YAML File
#mf.write_YAML(False, 'C:/Users/cenv0553/GIT/NISMODII/TESTYAML.yaml')

# --- Write out functions....scrap to improve
mf.write_to_csv_will(result_dict, data['reg_lu']) #TODO IMprove
mf.write_to_csv_will(data, result_dict, data['reg_lu']) #TODO IMprove

# Write function to also write out results
print("FINAL Fueltype: " + str(len(result_dict)))
print("FINAL region: " + str(len(result_dict[1])))
print("FINAL timesteps: " + str(len(result_dict[1][0])))
print("Finished energy demand model")
#print(result_dict)
return result_dict


Expand All @@ -154,18 +107,13 @@ def energy_demand_model(data, assumptions, data_ext):
# Model calculations outside main function
path_main = r'C:/Users/cenv0553/GIT/NISMODII/data/' # #path_main = '../data'
base_data = mf.load_data(base_data, data_external, path_main) # Load and generate data

base_data = mf.OLDMODEL_load_data(base_data, data_external, path_main) # DELETE SOON


assumptions_model_run = assumpt.load_assumptions(base_data) # Load assumptions
base_data = mf.disaggregate_base_demand_for_reg(base_data, 1) # Disaggregate national data into regional data

# Generate virtual building stock over whole simulatin period
base_data = bg.resid_build_stock(base_data, assumptions_model_run, data_external)



# Generate technological stock over whole simulation period
#base_tech_stock_resid = ts.resid_tech_stock(2015, assumptions_model_run, data_external)

Expand Down
83 changes: 49 additions & 34 deletions energy_demand/main_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
import csv
import traceback
import datetime

from datetime import date
from datetime import timedelta as td
import numpy as np
Expand All @@ -15,6 +15,32 @@
#from datetime import datetime
#import datetime


def convert_result_to_final_total_format(data, all_Regions):
"""Convert into nested citionary with fueltype, region, hour"""

timesteps, _ = timesteps_full_year() # Create timesteps for full year (wrapper-timesteps)
result_dict = init_dict_energy_supply(data['fuel_type_lu'], data['reg_pop_array'], timesteps)

for reg in all_Regions:
print("Reg_NAme " + str(reg))
region_name = reg.reg_name

# Get total fuel fuel
hourly_all_fuels = reg.tot_all_enduses_h()

# Iterate fueltypes
for fueltype in data['fuel_type_lu']:

fuel_total_h_all_end_uses = hourly_all_fuels[fueltype]

# Convert array into dict for out_read
out_dict = dict(enumerate(fuel_total_h_all_end_uses))

result_dict[fueltype][region_name] = out_dict

return result_dict

def load_data(data, data_ext, path_main):
"""All base data no provided externally are loaded
Expand Down Expand Up @@ -48,9 +74,6 @@ def load_data(data, data_ext, path_main):

return data




def init_dict_energy_supply(fuel_type_lu, reg_pop, timesteps):
"""Generates nested dictionary for providing results to smif
Expand Down Expand Up @@ -190,17 +213,8 @@ def read_csv_base_data_resid(path_to_csv):

cnt_fueltype += 1

#import pprint
'''for i in end_uses_dict:
print("Appliances" + str(i))
print(end_uses_dict[i])
print("--")
'''
return end_uses_dict




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.
Expand Down Expand Up @@ -715,11 +729,13 @@ def timesteps_full_year():
Parameters
----------
Returns
-------
timestep : list
List containing all dates according to number of hours
"""
#TODO: improve

full_year_date = [date(2015, 1, 1), date(2015, 12, 31)] # Base Year
start_date, end_date = full_year_date[0], full_year_date[1]
Expand Down Expand Up @@ -856,7 +872,7 @@ def get_own_position(daytype, _season, hour_container, timesteps_own_selection):

return position_own_container

def add_demand_result_dict(fuel_type, e_app_bd, fuel_type_lu, reg_pop, timesteps, result_dict, timesteps_own_selection):
'''def add_demand_result_dict(fuel_type, e_app_bd, fuel_type_lu, reg_pop, timesteps, result_dict, timesteps_own_selection):
"""Add data to wrapper timesteps
"""
Expand Down Expand Up @@ -906,7 +922,7 @@ def add_demand_result_dict(fuel_type, e_app_bd, fuel_type_lu, reg_pop, timesteps
year_hour += 1
return result_dict

'''
def get_own_timesteps(date_list):
"""Create own timesteps. "Generets a list with all dates from a list containing start and end dates.
Expand Down Expand Up @@ -1145,7 +1161,7 @@ def read_data(data, path_main):
app_type_lu = read_csv(path_dict['path_lookup_appliances']) # Appliances types lookup table
#fuel_type_lu = read_csv(path_dict['path_fuel_type_lu']) # Fuel type lookup
fuel_type_lu = read_csv_dict_no_header(path_dict['path_fuel_type_lu']) # Fuel type lookup

day_type_lu = read_csv(path_dict['path_day_type_lu']) # Day type lookup
#season_lookup = read_csv(path_dict[]'path_season's_lookup']) # Season lookup

Expand Down Expand Up @@ -1200,8 +1216,8 @@ def read_data(data, path_main):
data['lu_appliances_HES_matched'] = lu_appliances_HES_matched

# load shapes
data['dict_shapes_end_use_h'] = {}
data['dict_shapes_end_use_d'] = {}
data['dict_shapes_end_use_h'] = {}
data['dict_shapes_end_use_d'] = {}
return data

def disaggregate_base_demand_for_reg(data, reg_data_assump_disaggreg):
Expand Down Expand Up @@ -1271,34 +1287,35 @@ def write_YAML(yaml_write, path_YAML):
return


def write_to_csv_will(reesult_dict, reg_lu):
def write_to_csv_will(data, reesult_dict, reg_lu):
""" Write reults for energy supply model
e.g.
england, P0H, P1H, 139.42, 123.49
"""

path_csvs = ['C:/Users/cenv0553/GIT/NISMODII/model_output/NEU_elec.csv', 'C:/Users/cenv0553/GIT/NISMODII/model_output/NEU_gas.csv']
fueltype = 1
for path in path_csvs:
print("path: " + str(path))
print("--------------------")
#yaml_list = []
with open(path, 'w', newline='') as fp:
for fueltype in data['fuel_type_lu']:

#TODO: Give relative path stored in data[pathdict]
path = 'C:/Users/cenv0553/GIT/NISMODII/model_output/_fueltype_{}_hourly_results'.format(fueltype)

yaml_list = []
with open(path, 'w', newline='') as fp:
a = csv.writer(fp, delimiter=',')
data = []
#for i in range(len(reesult_dict)): # Iterate over fuel type

for reg in reesult_dict[fueltype]:
region_name = reg_lu[reg]


for _day in reesult_dict[fueltype][reg]:
for _hour in reesult_dict[fueltype][reg][_day]:
for _hour in range(24):

start_id = "P{}H".format(_day * 24 + _hour)
end_id = "P{}H".format(_day * 24 + _hour + 1)
#yaml_list.append({'region': region_name, 'start': _start, 'end': _end, 'value': reesult_dict[cnt][reg][_hour], 'units': 'GWh', 'year': 'XXXX'})
yaml_list.append({'region': region_name, 'start': start_id, 'end': end_id, 'value': reesult_dict[fueltype][reg][_day][_hour], 'units': 'CHECK GWH', 'year': 'XXXX'})

data.append([region_name, start_id, end_id, reesult_dict[fueltype][reg][_day][_hour]])

a.writerows(data)
Expand Down Expand Up @@ -1349,14 +1366,12 @@ def calc_daily_load_factor(daily_loads):
'''

def calc_peak_from_average(daily_loads):

#
max_load = average_load / load_factor

return max_load


def OLDMODEL_load_data(data, data_ext, path_main):
'''def OLDMODEL_load_data(data, data_ext, path_main):
# ----------below old model
Expand Down Expand Up @@ -1412,7 +1427,7 @@ def OLDMODEL_load_data(data, data_ext, path_main):
print(" ")
return data

'''

"""A one-line summary that does not use variable names or the
function name.
Expand Down Expand Up @@ -1466,4 +1481,4 @@ def OLDMODEL_load_data(data, data_ext, path_main):
This can have multiple paragraphs.
You may include some math:
"""
"""

0 comments on commit 55fc3ed

Please sign in to comment.