Skip to content

Commit

Permalink
Tom added magic path variable
Browse files Browse the repository at this point in the history
  • Loading branch information
eggimasv authored and eggimasv committed Mar 24, 2017
1 parent 9e3f878 commit 6095f6e
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 45 deletions.
2 changes: 1 addition & 1 deletion energy_demand/building_stock_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def resid_build_stock(data, assumptions, data_ext):
dwtype_distr_by = 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_by = 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
reg_lu = data['reg_lu'] # Regions
sim_period = range(base_year, glob_var['current_year'] + 1, 1) #base year, current year + 1, iteration step
sim_period = range(base_year, glob_var['current_yr'] + 1, 1) #base year, current year + 1, iteration step

# Get distribution of dwelling types of all simulation years
dwtype_distr_sim = bf.get_dwtype_dist(dwtype_distr_by, assumptions['assump_dwtype_distr_ey'], glob_var) # Calculate distribution of dwelling types over simulation period
Expand Down
6 changes: 5 additions & 1 deletion energy_demand/data_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import energy_demand.main_functions as mf
# pylint: disable=I0011,C0321,C0301,C0103, C0325

def load_data(data, path_main, data_ext):
def load_data(path_main, data_ext):
"""All base data no provided externally are loaded
All necessary data to run energy demand model is loaded.
Expand All @@ -27,6 +27,10 @@ def load_data(data, path_main, data_ext):
Returns a list where storing all data
"""

# Data container
data = {}

path_dict = {

# Residential
Expand Down
20 changes: 12 additions & 8 deletions energy_demand/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
# pylint: disable=I0011,C0321,C0301,C0103, C0325
#!python3.6

import os
import sys
import energy_demand.main_functions as mf
import energy_demand.building_stock_generator as bg
Expand Down Expand Up @@ -118,32 +119,36 @@ def energy_demand_model(data, data_ext):
# Execute only once befure executing energy demand module for a year
# ------------------------------------------------------------------_
# Wheater generater (change base_demand data)

# { 'population': [ obs, obs ] }
# obs.value == 3000000
# obs.region == 1
# obs.interval == 2
# obs.units == 'count'
# External data provided from wrapper
data_external = {'population': {2015: {0: 3000001, 1: 5300001, 2: 53000001},
2016: {0: 3000001, 1: 5300001, 2: 53000001}
},

'glob_var': {'base_year': 2015,
'current_year': 2016,
'current_yr': 2016,
'end_year': 2020
},

'fuel_price': {2015: {0: 10.0, 1: 10.0, 2: 10.0, 3: 10.0, 4: 10.0, 5: 10.0, 6: 10.0, 7: 10.0},
2016: {0: 12.0, 1: 13.0, 2: 14.0, 3: 12.0, 4: 13.0, 5: 14.0, 6: 13.0, 7: 13.0}
},

# Demand of other sectors
'external_enduses': {'waste_water': {0: 0}, #Yearly fuel data
'ICT_model': {}
}
}

# Data container
base_data = {}


# Model calculations outside main function
path_main = r'C:/Users/cenv0553/GIT/NISMODII/data/' #path_main = '../data'
base_data = dl.load_data(base_data, path_main, data_external) # Load and generate data
path_main = os.path.join(os.path.dirname(__file__), '..', 'data')
base_data = dl.load_data(path_main, data_external) # Load and generate data

# Load assumptions
print("Load Assumptions")
Expand All @@ -155,8 +160,7 @@ def energy_demand_model(data, data_ext):
# Generate virtual building stock over whole simulatin period
base_data = bg.resid_build_stock(base_data, base_data['assumptions'], data_external)

# Generate technological stock for base year (Maybe for full simualtion period? TODO)
base_data['tech_stock_by'] = ts.ResidTechStock(base_data, data_external, data_external['glob_var']['base_year'])


# Run main function
energy_demand_model(base_data, data_external)
Expand Down
19 changes: 11 additions & 8 deletions energy_demand/residential_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ def residential_model_main_function(data, data_ext):
fuel_in += np.sum(data['fueldata_disagg'][reg][enduse])
print("TEST MAIN START:" + str(fuel_in))

# Generate technological stock for base year
data['tech_stock_cy'] = ts.ResidTechStock(data, data_ext, data_ext['glob_var']['current_year'])

#data['tech_stock_cy'] = ts.ResidTechStock(data, data_ext, data_ext['glob_var']['current_yr']) # Generate technological stock for base year
# Generate technological stock
data['tech_stock_cy'] = ts.ResidTechStock(data, data_ext, data_ext['glob_var']['current_yr']) # Generate technological stock for current year
data['tech_stock_by'] = ts.ResidTechStock(data, data_ext, data_ext['glob_var']['base_year']) # Generate technological stock for base year

# Add all region instances as an attribute (region name) into a Country class
resid_object = Country_residential_model(data['reg_lu'], data, data_ext)
Expand Down Expand Up @@ -114,7 +117,7 @@ def __init__(self, reg_id, data, data_ext):
self.data = data # data
self.data_ext = data_ext # external data
self.assumptions = data['assumptions']
self.current_year = data_ext['glob_var']['current_year'] # Current year
self.current_yr = data_ext['glob_var']['current_yr'] # Current year
self.reg_fuel = data['fueldata_disagg'][reg_id] # Fuel array of region (used to extract all end_uses)

# Set attributs of all enduses
Expand Down Expand Up @@ -366,7 +369,7 @@ def __init__(self, reg_id, data, data_ext, enduse, reg_fuel):
# --General data, fueldata, technological stock
self.reg_id = reg_id # Region
self.enduse = enduse # EndUse Name
self.current_year = data_ext['glob_var']['current_year'] # from parent class
self.current_yr = data_ext['glob_var']['current_yr'] # from parent class
self.base_year = data_ext['glob_var']['base_year'] # from parent class
self.data = data # from parent class
self.data_ext = data_ext # from parent class
Expand Down Expand Up @@ -433,7 +436,7 @@ def enduse_elasticity(self):
if fuel != 0: # if fuel exists
# Fuel prices
fuelprice_by = self.data_ext['fuel_price'][self.base_year][fueltype]
fuelprice_cy = self.data_ext['fuel_price'][self.current_year][fueltype]
fuelprice_cy = self.data_ext['fuel_price'][self.current_yr][fueltype]

new_fuels[fueltype] = mf.apply_elasticity(fuel, elasticity_enduse, fuelprice_by, fuelprice_cy)

Expand Down Expand Up @@ -548,8 +551,8 @@ def enduse_fuel_switches(self):
#print("fuel_diff: " + str(fuel_diff))

# Calculate sigmoid diffusion of fuel switches
###fuel_p_cy = fuel_diff * tf.sigmoidefficiency(self.data_ext['glob_var']['base_year'], self.current_year, self.data_ext['glob_var']['end_year'])
fuel_p_cy = fuel_p_by * tf.sigmoidefficiency(self.data_ext['glob_var']['base_year'], self.current_year, self.data_ext['glob_var']['end_year'])
###fuel_p_cy = fuel_diff * tf.sigmoidefficiency(self.data_ext['glob_var']['base_year'], self.current_yr, self.data_ext['glob_var']['end_year'])
fuel_p_cy = fuel_p_by * tf.sigmoidefficiency(self.data_ext['glob_var']['base_year'], self.current_yr, self.data_ext['glob_var']['end_year'])
#print("fuel_p_cy:" + str(fuel_p_cy))
#print(fuel_p_ey[:, 1])
#print("fuel_p_ey:" + str(fuel_p_ey))
Expand All @@ -562,7 +565,7 @@ def enduse_fuel_switches(self):
#print("absolute_fuel_diff: " + str(absolute_fuel_diff))
#print("Technology which is installed: " + str(tech_install))
#print("Efficiency of technology to be installed " + str(eff_replacement))
#print("Current Year:" + str(self.current_year))
#print("Current Year:" + str(self.current_yr))

for fuel_type, fuel_diff in enumerate(absolute_fuel_diff):

Expand Down
16 changes: 8 additions & 8 deletions energy_demand/technological_stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ class ResidTechStock(object):
tbd
data_ext : dict
tbd
current_year : int
current_yr : int
Current year
TODO: Improve and replace glob_var
"""
def __init__(self, data, data_ext, current_year):
def __init__(self, data, data_ext, current_yr):
"""Constructor of technologies for residential sector"""
self.base_year = data_ext['glob_var']['base_year']
self.end_year = data_ext['glob_var']['end_year']
self.current_year = current_year #data_ext['glob_var']['current_year']
self.current_yr = current_yr
self.assumptions = data['assumptions']
self.tech_lu = data['tech_lu']

# Execute function to add all technological efficiencies as self argument
self.crate_iteration_efficiency()
self.create_iteration_efficiency()

# get share of technologies of base_year
self.tech_frac_by_assumptions = data['assumptions']['technologies_enduse_by']
Expand All @@ -40,7 +40,7 @@ def __init__(self, data, data_ext, current_year):
# Get share of technology of current year #TODO
self.tech_frac = self.get_sigmoid_tech_diff()

def crate_iteration_efficiency(self):
def create_iteration_efficiency(self):
"""Iterate technologes in 'base_year' dict and add to technology_stock
The efficiency of each technology is added as `self` attribute.
Expand All @@ -63,7 +63,7 @@ def crate_iteration_efficiency(self):
sim_years = self.end_year - self.base_year

# Theoretical maximum efficiency potential if theoretical maximum is linearly calculated TODO: Ev. round
theor_max_eff = tf.lineardiffusion(self.base_year, self.current_year, eff_by, eff_ey, sim_years)
theor_max_eff = tf.lineardiffusion(self.base_year, self.current_yr, eff_by, eff_ey, sim_years)

# Get assmuption how much of efficiency potential is reaped
achieved_eff = self.assumptions['eff_achieved'][technology]
Expand All @@ -79,7 +79,7 @@ def get_sigmoid_tech_diff(self):
With help of assumptions on the fraction of technologies for each
enduse and fueltype for the `base_year` and `end_year` the
fraction of technologies for the `current_year` is calculated.
fraction of technologies for the `current_yr` is calculated.
Also the change in fuel is calculated depending on the relationship
`sigmoid_frac_tech_change`.
Expand All @@ -97,7 +97,7 @@ def get_sigmoid_tech_diff(self):
tech_frac_cy = {}

# Sigmoid efficiency for all technologies (TODO: TECHNOLOGY SPECIFIC DIFFUSION)
sigmoid_frac_tech_change = tf.sigmoidefficiency(self.base_year, self.current_year, self.end_year)
sigmoid_frac_tech_change = tf.sigmoidefficiency(self.base_year, self.current_yr, self.end_year)

for enduse in tech_frac_by:
tech_frac_cy[enduse] = {}
Expand Down
38 changes: 19 additions & 19 deletions energy_demand/technological_stock_functions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
""" Functions for fuel_enduse_switch stock"""
import math as m

'''def eff_sy_lin(base_year, current_year, year_end, assumptions, technology):
'''def eff_sy_lin(base_year, current_yr, year_end, assumptions, technology):
""" Calculates lineare diffusion
Parameters
----------
Expand All @@ -19,18 +19,18 @@
# How far the diffusion is
diffusion = round(lineardiffusion(base_year, current_year, eff_by, eff_ey, sim_years), 2)
diffusion = round(lineardiffusion(base_year, current_yr, eff_by, eff_ey, sim_years), 2)
return diffusion
'''

def frac_sy_sigm(base_year, current_year, year_end, assumptions, fuel_enduse_switch):
def frac_sy_sigm(base_year, current_yr, year_end, assumptions, fuel_enduse_switch):
""" Calculate sigmoid diffusion of a fuel type share of a current year
Parameters
----------
base_year : float
Base year
current_year : float
current_yr : float
Base year
year_end : float
Base year
Expand All @@ -56,20 +56,20 @@ def frac_sy_sigm(base_year, current_year, year_end, assumptions, fuel_enduse_swi
diff_frac = fract_ey -fract_by

# How far the diffusion has progressed
p_of_diffusion = round(sigmoidefficiency(base_year, current_year, year_end), 2)
p_of_diffusion = round(sigmoidefficiency(base_year, current_yr, year_end), 2)

# Fraction of current year
fract_cy = fract_by + (diff_frac * p_of_diffusion)

return fract_cy

def lineardiffusion(base_year, current_year, eff_by, eff_ey, sim_years):
def lineardiffusion(base_year, current_yr, eff_by, eff_ey, sim_years):
"""This function assumes a linear fuel_enduse_switch diffusion.
All necessary data to run energy demand model is loaded.
This data is loaded in the wrapper.
Parameters
----------
current_year : int
current_yr : int
The year of the current simulation.
base_year : int
The year of the current simulation.
Expand All @@ -84,21 +84,21 @@ def lineardiffusion(base_year, current_year, eff_by, eff_ey, sim_years):
fract_sy : float
The fraction of the fuel_enduse_switch in the simulation year
"""
if current_year == base_year:
if current_yr == base_year:
fract_sy = eff_by
else:
fract_sy = eff_by + ((eff_ey - eff_by) / sim_years) * (current_year - base_year)
fract_sy = eff_by + ((eff_ey - eff_by) / sim_years) * (current_yr - base_year)

return fract_sy

def sigmoidefficiency(base_year, current_year, year_end):
def sigmoidefficiency(base_year, current_yr, year_end):
"""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.0 + (12.0 / (year_end - base_year)) * (current_year - base_year)
y_trans = -6.0 + (12.0 / (year_end - base_year)) * (current_yr - base_year)

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) TODO: Make as global ssumption
Expand All @@ -108,13 +108,13 @@ def sigmoidefficiency(base_year, current_year, year_end):

return val_yr

'''def sigmoidfuel_enduse_switchdiffusion(base_year, current_year, saturate_year, year_invention):
'''def sigmoidfuel_enduse_switchdiffusion(base_year, current_yr, saturate_year, year_invention):
"""This function assumes "S"-Curve fuel_enduse_switch diffusion (logistic function).
The function reads in the following assumptions about the fuel_enduse_switch to calculate the
current distribution of the simulated year:
Parameters
----------
current_year : int
current_yr : int
The year of the current simulation
saturate_year : int
The year a fuel_enduse_switch saturaes
Expand All @@ -128,14 +128,14 @@ def sigmoidefficiency(base_year, current_year, year_end):
The fraction of the fuel_enduse_switch in the simulation year
"""
# Check how many years fuel_enduse_switch in the market
if current_year < year_invention:
if current_yr < year_invention:
val_yr = 0
return val_yr
else:
if current_year >= saturate_year:
if current_yr >= saturate_year:
years_availalbe = saturate_year - base_year
else:
years_availalbe = current_year - year_invention
years_availalbe = current_yr - year_invention
# Translates simulation year on the sigmoid graph reaching from -6 to +6 (x-value)
print("years_availalbe: " + str(years_availalbe))
Expand All @@ -151,13 +151,13 @@ def sigmoidefficiency(base_year, current_year, year_end):
return val_yr
'''

'''def frac_sy_sigm_new_fuel_enduse_switch(base_year, current_year, year_end, assumptions, fuel_enduse_switch):
'''def frac_sy_sigm_new_fuel_enduse_switch(base_year, current_yr, year_end, assumptions, fuel_enduse_switch):
""" Calculate share of a fuel_enduse_switch in a year based on assumptions
Parameters
----------
base_year : float
Base year
current_year : float
current_yr : float
Base year
year_end : float
Base year
Expand All @@ -174,7 +174,7 @@ def sigmoidefficiency(base_year, current_year, year_end):
# EV: MAX_SHARE POSSIBLE
#max_possible
# How far the fuel_enduse_switch has diffused
p_of_diffusion = round(sigmoidfuel_enduse_switchdiffusion(base_year, current_year, saturation_year, market_year), 2)
p_of_diffusion = round(sigmoidfuel_enduse_switchdiffusion(base_year, current_yr, saturation_year, market_year), 2)
print("p_of_diffusion: " + str(p_of_diffusion))
#fract_cy = p_of_diffusion * max_possible
return p_of_diffusion
Expand Down

0 comments on commit 6095f6e

Please sign in to comment.