Skip to content

Commit

Permalink
added that if service share does not sum up to one in case of sigmoid…
Browse files Browse the repository at this point in the history
… diffusion that the rest is distributed according to base year shres
  • Loading branch information
Sven Eggimann committed Dec 18, 2018
1 parent b24def7 commit d2a37ea
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 92 deletions.
6 changes: 0 additions & 6 deletions energy_demand/enduse_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -1470,12 +1470,6 @@ def apply_service_switch(
base_yr,
curr_yr)

# TESTING
#_sum = 0
#for tech in annual_tech_diff_params:
# _sum += annual_tech_diff_params[tech][curr_yr]
#
#print("TOTAL SUM " + str(_sum))
# ---------------------------------------
# Calculate switch
# ----------------------------------------
Expand Down
9 changes: 5 additions & 4 deletions energy_demand/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def energy_demand_model(
#sim_yrs = [base_yr, 2030, user_defined_simulation_end_yr]
#sim_yrs = [2015, 2020, 2025, 2030, 2035, 2040, 2045, 2050]
#sim_yrs = [2015, 2020, 2050]
sim_yrs = [2015, 2030] #, 2050]
sim_yrs = [2015, 2020] #, 2050]
weather_yr_scenario = 2015 # Default weather year

if len(sys.argv) > 3: #user defined arguments are provide
Expand All @@ -126,7 +126,8 @@ def energy_demand_model(
print("weather_realisation: " + str(weather_realisation))

# Local path configurations
path_weather_data = "X:/nismod/data/energy_demand/J-MARIUS_data/_weather_realisation"
#path_weather_data = "X:/nismod/data/energy_demand/J-MARIUS_data/_weather_realisation"
path_weather_data = "C:/Users/cenv0553/ED/data/scenarios"
#path_weather_data = "/soge-home/staff/cenv0553/_weather_realisation"

#local_scenario = 'pop-baseline16_econ-c16_fuel-c16' #pop-f_econ-c_fuel-c #pop-b_econ-c_fuel-c
Expand Down Expand Up @@ -307,8 +308,8 @@ def energy_demand_model(
same_base_year_weather=False,
crit_temp_min_max=config['CRITERIA']['crit_temp_min_max'],
load_np=False,
load_parquet=True,
load_csv=False)
load_parquet=False,
load_csv=True)

#print(station_id_253)
# Plot map with weather station
Expand Down
52 changes: 0 additions & 52 deletions energy_demand/plotting/plotting_program.py

This file was deleted.

38 changes: 22 additions & 16 deletions energy_demand/scripts/init_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,27 +267,36 @@ def switch_calculations(

# ------------------------------------------------------
# Test whether the calculated service shares sum up to 1
# and if not, then distribute not assigned demand according to
# base year distribution
# Can happen because multiple sigmoid for different technologies
# ------------------------------------------------------
for region in annual_tech_diff_params:
for enduse in annual_tech_diff_params[region]:
for sector in annual_tech_diff_params[region][enduse]:
#print("TTTTTTTT {} {} {} ".format(region, enduse, sector))
#print(annual_tech_diff_params[region][enduse][sector])

for year in sim_yrs:
if annual_tech_diff_params[region][enduse][sector] != []:
_test_sum = 0
assigned_service_p = 0
for tech in annual_tech_diff_params[region][enduse][sector]:
#print("TECH " + str(tech))
#print("TECH " + str(annual_tech_diff_params[region][enduse][sector][tech]))
_test_sum += annual_tech_diff_params[region][enduse][sector][tech][year]

#print("ff {} {}".format(year, _test_sum))
assert round(_test_sum, 2) == 1
if round(_test_sum, 2) != 1:
print("EEEEEEEROR {} {} {}".format(enduse, year, _test_sum))

raise Exception("FF")
assigned_service_p += annual_tech_diff_params[region][enduse][sector][tech][year]

# Distribute if not sum up to one according to base year distribution
if round(assigned_service_p, 2) != 1:
total_not_assined = 1 - assigned_service_p

for tech in annual_tech_diff_params[region][enduse][sector]:
# Fraction in base year
p_by = annual_tech_diff_params[region][enduse][sector][tech][data['assumptions'].base_yr]
tech_to_add_not_assigned = total_not_assined * p_by
annual_tech_diff_params[region][enduse][sector][tech][year] += tech_to_add_not_assigned

assigned_service_p = 0
for tech in annual_tech_diff_params[region][enduse][sector]:
assigned_service_p += annual_tech_diff_params[region][enduse][sector][tech][year]

assert round(assigned_service_p, 2) == 1

return annual_tech_diff_params

def spatial_explicit_modelling_strategy_vars(
Expand Down Expand Up @@ -525,11 +534,8 @@ def sum_across_all_submodels_regs(
fuel_aggregated_regs = {}

for region in regions:

tot_reg = np.zeros((fueltypes_nr), dtype="float")

for submodel_fuel_disagg in submodels:

for fuel_sector_enduse in submodel_fuel_disagg[region].values():

# Test if fuel for sector
Expand Down
59 changes: 55 additions & 4 deletions energy_demand/scripts/s_generate_sigmoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,59 @@
from collections import defaultdict
import numpy as np
from scipy.optimize import curve_fit
import pylab
import matplotlib.pyplot as plt
import matplotlib
matplotlib.use('Agg') # Used to make it work in linux

from energy_demand.technologies import diffusion_technologies
from energy_demand.plotting import plotting_program


def plotout_sigmoid_tech_diff(
L_value,
technology,
xdata,
ydata,
fit_parameter,
plot_crit=False,
close_window_crit=True
):
"""Plot sigmoid diffusion
"""
def close_event():
"""Timer to close window automatically
"""
plt.close()

x = np.linspace(1990, 2110, 300)
y = diffusion_technologies.sigmoid_function(x, L_value, *fit_parameter)

fig = plt.figure()

#creating a timer object and setting an interval
timer = fig.canvas.new_timer(interval=555)
timer.add_callback(close_event)

fig.set_size_inches(12, 8)
pylab.plot(xdata, ydata, 'o', label='base year and future market share')
pylab.plot(x, y, label='fit')

pylab.ylim(0, 1.05)
pylab.legend(loc='best')

pylab.xlabel('Time')
pylab.ylabel('Market share of technology on energy service')
pylab.title("Sigmoid diffusion of technology {}".format(technology))

if plot_crit:
if close_window_crit:
pylab.show()
else:
timer.start()
pylab.show()
pass
else:
pass

def calc_sigmoid_parameters(
l_value,
Expand Down Expand Up @@ -127,14 +178,14 @@ def calc_sigmoid_parameters(
cnt += 1
else:
successfull = True
plotting_program.plotout_sigmoid_tech_diff(
'''plotout_sigmoid_tech_diff(
l_value,
"FINISHED FITTING",
xdata,
ydata,
fit_parameter,
plot_crit=True,
close_window_crit=True)
close_window_crit=True)'''
except (RuntimeError, IndexError):
cnt += 1

Expand Down Expand Up @@ -556,7 +607,7 @@ def calc_c(m, x1, y1):
if (round(point_y_by, rounding_accuracy) == round(point_y_ey, rounding_accuracy)) and (
point_y_ey != fit_assump_init) and (
point_y_by != fit_assump_init):

#if 1 == 1:
# Linear diffusion (because by and ey share are identical)
sig_params[tech]['midpoint'] = 'linear'
sig_params[tech]['steepness'] = 'linear'
Expand Down
6 changes: 1 addition & 5 deletions energy_demand/scripts/s_scenario_param.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ def generate_annual_param_vals(
reg_param[region][var_name][sub_var_name][sector] = dict(regional_strategy_vary[region])
else:
non_reg_param[var_name][sub_var_name][sector] = regional_strategy_vary

# Single dimensional
else:
param_info = {}
Expand Down Expand Up @@ -328,10 +327,7 @@ def generate_general_parameter(

for sim_yr in sim_yrs:

# -----------------------------------------------
# Set curry_yr to largest year defined narrative if
# sim_yr is larger
# -----------------------------------------------
# Set curry_yr to largest year defined narrative if sim_yr is larger
if sim_yr > latest_narrative_timestep:
curr_yr = latest_narrative_timestep
else:
Expand Down
5 changes: 0 additions & 5 deletions energy_demand/technologies/fuel_service_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,6 @@ def create_switches_from_s_shares(
service_switches_out = enduse_switches
else:
for tech, share_by in tech_not_assigned_by_p.items():

#if tot_share_not_assigned == 0:
# tech_not_assigned_by_p[tech] = 0
#else:
# tech_not_assigned_by_p[tech] = share_by / tot_share_not_assigned
tech_not_assigned_by_p[tech] = share_by / tot_share_not_assigned

# Get all defined technologies in base year
Expand Down

0 comments on commit d2a37ea

Please sign in to comment.