Skip to content

Commit

Permalink
before merging nismod2 into main master
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven Eggimann committed Dec 19, 2018
1 parent bfa7f16 commit 715cc78
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 82 deletions.
7 changes: 4 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ Research Consortium <http://www.itrc.org.uk/>`_.

More information on the model can be found in:

Eggimann, Hall and Eyre (2018): A high-resolution spatio-temporal energy demand
simulation to explore the potential of heating demand side management
with large-scale heat pump diffusion. Applied Energy. LINK
Eggimann, S., Hall, W.J., Eyre, N. (2019): A high-resolution spatio-temporal
energy demand simulation of large-scale heat pump diffusion to explore the
potential of heating demand side management. Applied Energy ,236, 997–1010.
`https://doi.org/10.1016/j.apenergy.2018.12.052 <https://doi.org/10.1016/j.apenergy.2018.12.052>`_.

1. Download input data
=============================================
Expand Down
14 changes: 7 additions & 7 deletions energy_demand/enduse_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def __init__(
self.fuel_y = fuel
self.flat_profile_crit = flat_profile_crit
self.techs_fuel_yh = None

#If enduse has no fuel return empty shapes
if np.sum(fuel) == 0:
self.flat_profile_crit = True
Expand All @@ -125,8 +125,8 @@ def __init__(
#print("------INFO {} {} {} {}".format(self.enduse, sector, region, curr_yr))
#print("FUEL TRAIN A0: " + str(np.sum(self.fuel_y)))

if curr_yr > 2015 and enduse == 'rs_lighting':
print("tt")
#if curr_yr > 2015 and enduse == 'rs_lighting':
# print("tt")
# Get technologies of enduse
self.enduse_techs = get_enduse_techs(fuel_tech_p_by)

Expand Down Expand Up @@ -226,7 +226,7 @@ def __init__(

#print("FUEL TRAIN X " + str(np.sum(fuel_yh)))
# Demand management for non-technology enduse
self.fuel_yh = demand_management(
self.fuel_yh = load_shifting(
enduse,
curr_yr,
strategy_vars['dm_improvement'],
Expand Down Expand Up @@ -335,7 +335,7 @@ def __init__(
self.techs_fuel_yh = {}

for tech in fuel_yh:
self.techs_fuel_yh[tech] = demand_management(
self.techs_fuel_yh[tech] = load_shifting(
enduse,
curr_yr,
strategy_vars['dm_improvement'],
Expand All @@ -345,15 +345,15 @@ def __init__(

self.fuel_yh = None
else:
self.fuel_yh = demand_management(
self.fuel_yh = load_shifting(
enduse,
curr_yr,
strategy_vars['dm_improvement'],
fuel_yh,
mode_constrained=False,
make_all_flat=make_all_flat)

def demand_management(
def load_shifting(
enduse,
curr_yr,
dm_improvement,
Expand Down
30 changes: 14 additions & 16 deletions energy_demand/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,41 +106,39 @@ def energy_demand_model(
user_defined_weather_by = config['CONFIG']['user_defined_weather_by']
user_defined_simulation_end_yr = config['CONFIG']['user_defined_simulation_end_yr']

# Simulated yrs
#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, 2020] #, 2050]
weather_yr_scenario = 2015 # Default weather year

sim_yrs = [2015, 2020, 2025, 2030, 2035, 2040, 2045, 2050]
#sim_yrs = [2015, 2020, 2050] #, 2050]
sim_yrs = [2015, 2020]
if len(sys.argv) > 3: #user defined arguments are provide
scenario_name = str(sys.argv[2])
weather_realisation = str(sys.argv[3]) # Weather realisation
else:
scenario_name = "_run_"
scenario_name = "_dm_0_"
weather_realisation = 'NF1'

print("-------------------------------------")
print("Information")
print("-------------------------------------")
print("weather_yr_scenario: " + str(weather_yr_scenario))
print("weather_realisation: " + str(weather_realisation))
print("Simulated yrs " + str(sim_yrs))
print("local_data_path " + str(local_data_path))

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

#name_config_path = 'h_c'
#name_config_path = 'l_c'
name_config_path = 'h_h'
#name_config_path = 'h_l'
#name_config_path = 'l_h'
#name_config_path = 'l_l'
name_config_path = 'h_max'
#name_config_path = 'h_min'
#name_config_path = 'l_max'
name_config_path = 'l_min'

if name_config_path == 'h_h' or name_config_path == 'l_h':
if name_config_path == 'h_max' or name_config_path == 'l_max':
local_scenario = 'pop-b_econ-c_fuel-c' #high
elif name_config_path == 'h_c' or name_config_path == 'l_c':
local_scenario = 'pop-baseline16_econ-c16_fuel-c16' #middle
elif name_config_path == 'h_l' or name_config_path == 'l_l':
elif name_config_path == 'h_min' or name_config_path == 'l_min':
local_scenario = 'pop-f_econ-c_fuel-c' #low

path_strategy_vars = os.path.join(local_data_path, 'energy_demand', '00_user_defined_variables', name_config_path)
Expand Down Expand Up @@ -312,7 +310,7 @@ def energy_demand_model(
'''if config['CRITERIA']['cluster_calc'] != True:
data_loader.create_weather_station_map(
data['weather_stations'],
os.path.join(data['path_new_scenario'], 'weatherst_distr_weathyr_{}.pdf'.format(weather_yr_scenario)),
os.path.join(data['path_new_scenario'], 'weatherst_distr_weathyr.pdf'),
path_shapefile=data['local_paths']['lad_shapefile'])'''

# ------------------------------------------------------------
Expand Down
107 changes: 68 additions & 39 deletions energy_demand/plotting/fig_3_plot_over_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@
from energy_demand.plotting import basic_plot_functions
from energy_demand.basic import conversions
from energy_demand.plotting import plotting_styles
from energy_demand.read_write import write_data

colors = {

# High elec
'h_l': '#004529',
'h_min': '#004529',
'h_c': '#238443',
'h_h': '#78c679',
'h_max': '#78c679',

# Low elec
'l_l': '#800026',
'l_min': '#800026',
'l_c': '#e31a1c',
'l_h': '#fd8d3c',
'l_max': '#fd8d3c',

'other1': '#C044FF',
'other2': '#3DF735',
Expand All @@ -32,10 +33,10 @@
marker_list = plotting_styles.marker_list()

marker_styles = {
'h_h': marker_list[0],
'h_l': marker_list[1],
'l_l': marker_list[2],
'l_h': marker_list[6],
'h_max': marker_list[0],
'h_min': marker_list[1],
'l_min': marker_list[2],
'l_max': marker_list[6],
}

def scenario_over_time(
Expand All @@ -44,16 +45,19 @@ def scenario_over_time(
fig_name,
result_path,
plot_points,
crit_smooth_line=True
crit_smooth_line=True,
seperate_legend=False
):
"""Plot peak over time
"""
statistics_to_print = []

fig = plt.figure(
figsize=basic_plot_functions.cm2inch(10, 10)) #width, height

ax = fig.add_subplot(1, 1, 1)

for cnt, i in enumerate(scenario_result_container):
for cnt_scenario, i in enumerate(scenario_result_container):
scenario_name = i['scenario_name']
national_peak = i['national_peak']

Expand All @@ -67,18 +71,28 @@ def scenario_over_time(
color = colors[scenario_name]
marker = marker_styles[scenario_name]
except KeyError:
color = list(colors.values())[cnt]
color = list(colors.values())[cnt_scenario]

try:
marker = marker_styles[scenario_name]
except KeyError:
marker = list(marker_styles.values())[cnt_scenario]

print("SCENARIO NAME {} {}".format(scenario_name, color))

# Calculate average across all weather scenarios
mean_national_peak = national_peak.mean(axis=0)
mean_national_peak_sim_yrs = copy.copy(mean_national_peak)

statistics_to_print.append("scenario: {} values over years: {}".format(scenario_name, mean_national_peak_sim_yrs))

# Standard deviation over all realisations
df_q_05 = national_peak.quantile(quantile_05)
df_q_95 = national_peak.quantile(quantile_95)

statistics_to_print.append("scenario: {} df_q_05: {}".format(scenario_name, df_q_05))
statistics_to_print.append("scenario: {} df_q_95: {}".format(scenario_name, df_q_95))

# --------------------
# Try to smooth lines
# --------------------
Expand Down Expand Up @@ -129,11 +143,11 @@ def scenario_over_time(
list(df_q_05), #y2
alpha=0.25,
facecolor=color,
#label="weather uncertainty"
)

plt.xlim(2015, 2050)

plt.ylim(0)

# --------
# Different style
# --------
Expand Down Expand Up @@ -168,23 +182,29 @@ def scenario_over_time(
frameon=False)
legend.get_title().set_fontsize(8)

basic_plot_functions.export_legend(
legend,
os.path.join(result_path, "legend_{}.pdf".format(fig_name)))
legend.remove()
if seperate_legend:
basic_plot_functions.export_legend(
legend,
os.path.join(result_path, "{}__legend.pdf".format(fig_name)))
legend.remove()

# --------
# Labeling
# --------
plt.ylabel("national peak demand in GW")
plt.ylabel("national peak demand (GW)")
#plt.xlabel("year")
#plt.title("Title")

plt.tight_layout()
#plt.show()

plt.savefig(os.path.join(result_path, fig_name))
plt.close()

# Write info to txt
write_data.write_list_to_txt(
os.path.join(result_path, fig_name).replace(".pdf", ".txt"),
statistics_to_print)

def fueltypes_over_time(
scenario_result_container,
sim_yrs,
Expand All @@ -193,28 +213,31 @@ def fueltypes_over_time(
result_path,
plot_points=False,
unit='TWh',
crit_smooth_line=True
crit_smooth_line=True,
seperate_legend=False
):
"""Plot fueltypes over time
"""
statistics_to_print = []

fig = plt.figure(
figsize=basic_plot_functions.cm2inch(10, 10)) #width, height
ax = fig.add_subplot(1, 1, 1)

colors = {
# Low elec
'electricity': '#001871',
'gas': '#ffb743',
'hydrogen': '#138d90',
'electricity': '#3e3838',
'gas': '#ae7c7c',
'hydrogen': '#6cbbb3',
}

line_styles_default = plotting_styles.linestyles()

linestyles = {
'h_h': line_styles_default[0],
'h_l': line_styles_default[6],
'l_l': line_styles_default[8],
'l_h': line_styles_default[9],
'h_max': line_styles_default[0],
'h_min': line_styles_default[6],
'l_min': line_styles_default[8],
'l_max': line_styles_default[9],
}

for cnt_scenario, i in enumerate(scenario_result_container):
Expand All @@ -223,8 +246,6 @@ def fueltypes_over_time(
for cnt_linestyle, fueltype_str in enumerate(fueltypes):
national_sum = i['national_{}'.format(fueltype_str)]



if unit == 'TWh':
unit_factor = conversions.gwh_to_twh(1)
elif unit == 'GWh':
Expand All @@ -246,21 +267,25 @@ def fueltypes_over_time(

try:
linestyle = linestyles[scenario_name]
marker = marker_styles[scenario_name]
except KeyError:
linestyle = list(linestyles.values())[cnt_scenario]
try:
marker = marker_styles[scenario_name]
except KeyError:
marker = list(marker_styles.values())[cnt_scenario]

# Calculate average across all weather scenarios
mean_national_sum = national_sum.mean(axis=0)
mean_national_sum_sim_yrs = copy.copy(mean_national_sum)

if fueltype_str == 'hydrogen':
print("..")
print(mean_national_sum.values)
statistics_to_print.append("{} fueltype_str: {} mean_national_sum_sim_yrs: {}".format(scenario_name, fueltype_str, mean_national_sum_sim_yrs))

# Standard deviation over all realisations
df_q_05 = national_sum.quantile(quantile_05)
df_q_95 = national_sum.quantile(quantile_95)

statistics_to_print.append("{} fueltype_str: {} df_q_05: {}".format(scenario_name, fueltype_str, df_q_05))
statistics_to_print.append("{} fueltype_str: {} df_q_95: {}".format(scenario_name, fueltype_str, df_q_95))
# --------------------
# Try to smooth lines
# --------------------
Expand Down Expand Up @@ -314,7 +339,6 @@ def fueltypes_over_time(
list(df_q_05), #y2
alpha=0.25,
facecolor=color,
#label="weather uncertainty"
)

plt.xlim(2015, 2050)
Expand Down Expand Up @@ -370,11 +394,12 @@ def fueltypes_over_time(
bbox_to_anchor=(0.5, -0.1),
frameon=False)
legend.get_title().set_fontsize(8)

basic_plot_functions.export_legend(
legend,
os.path.join(result_path, "legend_{}.pdf".format(fig_name)))
legend.remove()

if seperate_legend:
basic_plot_functions.export_legend(
legend,
os.path.join(result_path, "{}__legend.pdf".format(fig_name)))
legend.remove()

# --------
# Labeling
Expand All @@ -387,3 +412,7 @@ def fueltypes_over_time(
#plt.show()
plt.savefig(os.path.join(result_path, fig_name))
plt.close()

write_data.write_list_to_txt(
os.path.join(result_path, fig_name).replace(".pdf", ".txt"),
statistics_to_print)

0 comments on commit 715cc78

Please sign in to comment.