Skip to content

Commit

Permalink
Merge pull request #159 from nismod/fixing_bug_integration
Browse files Browse the repository at this point in the history
Fixing bug integration
  • Loading branch information
eggimasv committed Feb 25, 2019
2 parents 4b504e3 + 046fbf0 commit 45524c8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
6 changes: 6 additions & 0 deletions energy_demand/enduse_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ def __init__(
enduse,
sector,
curr_yr,
base_yr,
strategy_vars['generic_fuel_switch'],
self.fuel_y)
self.fuel_y = _fuel_new_y
Expand Down Expand Up @@ -1641,6 +1642,7 @@ def generic_fuel_switch(
enduse,
sector,
curr_yr,
base_yr,
fuel_switch,
fuel_y
):
Expand All @@ -1665,6 +1667,9 @@ def generic_fuel_switch(
fuel_y : array
Annual fuel demand per fueltype
"""
if base_yr == curr_yr:
return fuel_y

try:
# Test if switch is defined for sector
fuel_switch = fuel_switch[enduse][sector]
Expand All @@ -1688,6 +1693,7 @@ def generic_fuel_switch(

if switch_defined is True:
for fueltype_new_int in fuel_switch.keys():

if fuel_switch[fueltype_new_int][curr_yr] != 0:

# Get fueltype to switch to (new)
Expand Down
13 changes: 4 additions & 9 deletions energy_demand/scripts/init_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ def switch_calculations(
for enduse in data['enduses'][submodel_name]:
for sector in data['sectors'][submodel_name]:
print("... calculating fuel switches {} {} {}".format(submodel_name, enduse, sector))
#print("======d======= " + str(data['assumptions'].fuel_tech_p_by[enduse][sector]))
print("Z " + str(s_fueltype_by_p[sector][enduse]))
print("======d======= " + str(data['assumptions'].fuel_tech_p_by[enduse][sector]))
#print("Z " + str(s_fueltype_by_p[sector][enduse]))
diffusion_param_tech[enduse][sector] = sig_param_calc_incl_fuel_switch(
narrative_timesteps,
data['assumptions'].base_yr,
Expand Down Expand Up @@ -637,7 +637,7 @@ def sig_param_calc_incl_fuel_switch(
"""
sig_param_tech = {}
if sum(s_tech_by_p.values()) == 0: # no fuel is defined for enduse
#logging.info("no fuel is defined for enduse `{}` and sector `{}`".format(enduse, sector))
logging.info("no fuel is defined for enduse `{}` and sector `{}`".format(enduse, sector))
pass
else:
if share_s_tech_ey_p == {}:
Expand Down Expand Up @@ -689,9 +689,7 @@ def sig_param_calc_incl_fuel_switch(
# ------------------------------------------
if crit_switch_service:
print(".... service switch")
if enduse == 'is_space_heating' and 'E06000001' not in share_s_tech_ey_p.keys():
print(".ttt "+ str(share_s_tech_ey_p))
#print("KK " + str(share_s_tech_ey_p))

# Calculate only from service switch
s_tech_switched_p = share_s_tech_ey_p

Expand Down Expand Up @@ -775,9 +773,6 @@ def sig_param_calc_incl_fuel_switch(
print("---------- switches %s %s %s", enduse, crit_switch_service, crit_fuel_switch)
if crit_all_the_same:
print("... calc parameters of `{}` for year `{}` {}".format(enduse, switch_yr, sector))
print("FF {} {} ".format(switch_yr, s_tech_switched_p[any_region][switch_yr]))
print("---")
print(fuel_tech_p_by)
sig_param_tech_all_regs_value = s_generate_sigmoid.tech_sigmoid_parameters(
switch_yr,
switch_yr_start,
Expand Down
2 changes: 0 additions & 2 deletions energy_demand/scripts/s_fuel_to_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,8 @@ def get_s_fueltype_tech(
s_fueltype_by_p[enduse][sector][fueltype] = 0
else:
s_fueltype_by_p[enduse][sector][fueltype] = s_fueltype_by_p[enduse][sector][fueltype] / total_s

#TODO KAMEL OLD ORIGINAL s_fueltype_by_p[enduse][sector][fueltype] = s_fueltype_by_p[enduse][sector][fueltype] / total_s

#warnings.filterwarnings('ignore') # Ignore warnings
# Test if the energy service for all technologies is 100%
# Test if within fueltype always 100 energy service
for enduse, s_p_techs in s_tech_by_p.items():
Expand Down
13 changes: 12 additions & 1 deletion energy_demand/technologies/fuel_service_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,18 @@ def create_switches_from_s_shares(

# If no fuel is assigned to enduse, do not change switches
if tot_share_not_assigned == 0:

# Add zero share for all technologies not assigned if sums up to 100%
zero_share = 0
for tech in tech_not_assigned_by_p:
switch_new = read_data.ServiceSwitch(
enduse=enduse,
sector=sector,
technology_install=tech,
service_share_ey=zero_share,
switch_yr=switch_yr)
enduse_switches.append(switch_new)

service_switches_out = enduse_switches
else:
for tech, share_by in tech_not_assigned_by_p.items():
Expand Down Expand Up @@ -367,7 +379,6 @@ def autocomplete_switches(

# Execut function for every narrative year
for switch_yr in switch_yrs:

enduse_switches = []
s_tot_defined = 0
switch_technologies = []
Expand Down

0 comments on commit 45524c8

Please sign in to comment.