Skip to content

Commit

Permalink
improving plots
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven Eggimann authored and Sven Eggimann committed May 8, 2018
1 parent e431fb7 commit f077920
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 48 deletions.
43 changes: 34 additions & 9 deletions energy_demand/plotting/plotting_multiple_scenarios.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,9 +596,13 @@ def plot_reg_y_over_time(
# ---------
# Labels
# ---------
font_additional_info = plotting_styles.font_info(size=5)

plt.ylabel("GWh")
plt.xlabel("year")
plt.title("tot y ED all fueltypes")
plt.title(
"tot_y",
fontdict=font_additional_info)

# Tight layout
plt.tight_layout()
Expand All @@ -622,9 +626,12 @@ def plot_tot_fueltype_y_over_time(
"""Plot total demand over simulation period for every
scenario for all regions
"""
diff_elec, diff_gas = [], []

# Set figure size
fig = plt.figure(figsize=plotting_program.cm2inch(9, 8))


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

y_scenario = {}
Expand Down Expand Up @@ -691,6 +698,20 @@ def plot_tot_fueltype_y_over_time(
linestyle=linestyles[cnt_linestyle],
label="{}_{}".format(scenario_name, fueltype_str))

# ---
# Calculate difference in demand from 2015 - 2050
# ---
tot_2015 = fuel_fueltype[0]
tot_2050 = fuel_fueltype[-1]

p_diff_2015_2015 = (100 / tot_2015) * tot_2050
p_diff_2015_2015_round = float(round(p_diff_2015_2015, 1))

if fueltype_str == 'electricity':
diff_elec.append(p_diff_2015_2015_round)
if fueltype_str == 'gas':
diff_gas.append(p_diff_2015_2015_round)

# ----
# Axis
# ----
Expand All @@ -700,20 +721,24 @@ def plot_tot_fueltype_y_over_time(
# Plot legend
# ------------
ax.legend(
ncol=1,
ncol=2,
frameon=False,
loc='bottom left',
loc='upper center',
prop={
'family': 'arial',
'size': 4},
bbox_to_anchor=(1, 0.2))
bbox_to_anchor=(0.5, -0.1))

# ---------
# Labels
# ---------
font_additional_info = plotting_styles.font_info(size=5)

plt.ylabel("TWh")
plt.xlabel("year")
plt.title("tot y ED all fueltypes")
plt.title(
"diff elec: {}, gas:¨{}".format(diff_elec, diff_gas),
fontdict=font_additional_info)

# Tight layout
plt.tight_layout()
Expand Down Expand Up @@ -793,7 +818,7 @@ def plot_tot_y_over_time(
# ------------
plt.legend(
ncol=1,
loc=2,
loc=3,
prop={
'family': 'arial',
'size': 10},
Expand Down Expand Up @@ -851,7 +876,6 @@ def plot_radar_plots_average_peak_day(
all_regs_fueltypes_yh_by = np.sum(scenario_data[scenario]['results_every_year'][base_yr], axis=1)
all_regs_fueltypes_yh_cy = np.sum(scenario_data[scenario]['results_every_year'][year_to_plot], axis=1)

#for fueltype_str, fueltype_int in fueltypes.items():
fueltype_int = fueltypes[fueltype_to_model]

# ---------------------------
Expand All @@ -873,7 +897,8 @@ def plot_radar_plots_average_peak_day(
all_regs_fueltypes_yh_cy = all_regs_fueltypes_yh_cy.reshape(all_regs_fueltypes_yh_cy.shape[0], 365, 24)

diff_max_h = round(((100 / by_max_h) * cy_max_h) - 100, 2)
label_max_h = "scen: {} by: {} cy: {} d: {}".format(scenario, round(by_max_h, 2), round(cy_max_h, 2), round(diff_max_h, 2))
label_max_h = "scen: {} by: {} cy: {} d: {}".format(
scenario, round(by_max_h, 2), round(cy_max_h, 2), round(diff_max_h, 2))
list_diff_max_h.append(label_max_h)
print("Calculation of diff in peak: {} {} {} {}".format(scenario, round(diff_max_h, 2), round(by_max_h, 2), round(cy_max_h, 2)))

Expand All @@ -896,7 +921,7 @@ def plot_radar_plots_average_peak_day(
plotshow=False,
lf_y_by=[],
lf_y_cy=[],
list_diff_max_h=list_diff_max_h) #load_factor_fueltype_y_cy)
list_diff_max_h=list_diff_max_h)

def plot_LAD_comparison_scenarios(
scenario_data,
Expand Down
26 changes: 21 additions & 5 deletions energy_demand/plotting/plotting_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -2028,7 +2028,7 @@ def plot_radar_plot_multiple_lines(
SOURCE: https://python-graph-gallery.com/390-basic-radar-chart/
"""
fig = plt.figure(
figsize=plotting_program.cm2inch(9, 12))
figsize=plotting_program.cm2inch(9, 14))

# Get maximum demand of all lines
max_entry = 0
Expand Down Expand Up @@ -2168,8 +2168,7 @@ def plot_radar_plot_multiple_lines(
color_line,
alpha=0.05)

font_additional_info = plotting_styles.font_info()
font_additional_info['size'] = 5
font_additional_info = plotting_styles.font_info(size=5)

for cnt, entry in enumerate(list_diff_max_h):
plt.text(
Expand Down Expand Up @@ -2198,8 +2197,8 @@ def plot_radar_plot_multiple_lines(
# ------------
plt.legend(
ncol=2,
loc='best',
bbox_to_anchor=(0.5, -0.05),
#loc='best',
bbox_to_anchor=(0.6, -0.1),
prop={
'family': 'arial',
'size': 5},
Expand Down Expand Up @@ -2733,6 +2732,23 @@ def plot_cross_graphs_scenarios(
horizontalalignment="right",
verticalalignment="top",
fontsize=6)

# -------
# Title information
# -------
max_peak_h = max(x_values)
min_peak_h = min(x_values)
min_lf = min(y_values)
max_lf = max(y_values)

plt.title(
"max_peak_h: {} min_peak_h: {}, min_lf: {} max_lf: {}",
max_peak_h,
min_peak_h,
min_lf,
max_lf,
fontsize=10)

# --------
# Legend
# --------
Expand Down
4 changes: 2 additions & 2 deletions energy_demand/plotting/plotting_styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,13 @@ def color_list_scenarios():
'''
return color_list_selection

def font_info():
def font_info(family='arial', color='black', weight='normal', size=8):
"""
"""
font_additional_info = {
'family': 'arial',
'color': 'black',
'weight': 'normal',
'size': 8}
'size': size}

return font_additional_info
2 changes: 1 addition & 1 deletion energy_demand/processing/chart_hp_multiple_scenarios.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,4 @@ def process_scenarios(path_to_scenarios, year_to_model=2015):

# Generate plots across all scenarios
#process_scenarios(os.path.abspath("C:/Users/cenv0553/ED/_MULTI_HP_SCEN"))
process_scenarios(os.path.abspath("C:/Users/cenv0553/ed/results/Fig_08"))
process_scenarios(os.path.abspath("C:/Users/cenv0553/ed/results/Fig_08_09"))
4 changes: 2 additions & 2 deletions energy_demand/processing/multiple_scenarios.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ def process_result_multi_scen(path_to_scenarios, path_shapefile_input):
#os.path.abspath("C:/Users/cenv0553/ED/_multiple_results_hp_example_efficiency_improvement"),
#os.path.abspath("C:/Users/cenv0553/ED/_mutli_results_hp_50__eff_achieved_0.5_pop_scenarios"),
#os.path.abspath("C:/Users/cenv0553/ED/_MULTI"),
os.path.abspath("C:/Users/cenv0553/ED/__STORAGE"),
#"C:/Users/cenv0553/ed/results/Fig_08"
#os.path.abspath("C:/Users/cenv0553/ED/__STORAGE"),
#"C:/Users/cenv0553/ed/results/Fig_08_09",
os.path.abspath('C:/Users/cenv0553/ED/data/_raw_data/C_LAD_geography/same_as_pop_scenario/lad_2016_uk_simplified.shp'))
6 changes: 3 additions & 3 deletions energy_demand/processing/scenario_charts.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def process_scenarios(path_to_scenarios, year_to_model=2015):
scenario_data=scenario_data,
fueltype_int=lookups['fueltypes']['gas'],
fueltype_str='gas',
fig_name=os.path.join(path_result_folder, "cross_chart_SCENAROIS_gas.pdf"),
fig_name=os.path.join(path_result_folder, "cross_chart_gas.pdf"),
label_points=False,
plotshow=False)

Expand Down Expand Up @@ -185,8 +185,8 @@ def process_scenarios(path_to_scenarios, year_to_model=2015):

# Generate plots across all scenarios
#process_scenarios(os.path.abspath("C:/Users/cenv0553/ED/__STORAGE"))
#process_scenarios(os.path.abspath("C:/Users/cenv0553/ed/results/Fig_08"))
process_scenarios(os.path.abspath("C:/Users/cenv0553/ed/results/Fig_12"))
process_scenarios(os.path.abspath("C:/Users/cenv0553/ed/results/Fig_08_09"))
#process_scenarios(os.path.abspath("C:/Users/cenv0553/ed/results/Fig_12"))
#process_scenarios(os.path.abspath("C:/Users/cenv0553/ED/_MULTII"))
#process_scenarios(os.path.abspath("C:/Users/cenv0553/ED/_multi_scen_A"))
#process_scenarios(os.path.abspath("C:/Users/cenv0553/ED/_MULTI"))
16 changes: 4 additions & 12 deletions energy_demand/validation/elec_national_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,6 @@ def compare_results(
x_data_smoothed, y_calculated_list_smoothed = plotting_results.smooth_data(x_data, y_calculated_list, num=40000)

plt.plot(
#x_data,
#y_calculated_list,
x_data_smoothed,
y_calculated_list_smoothed,
label='model',
Expand All @@ -196,7 +194,6 @@ def compare_results(
fillstyle='full',
color='blue')

#Grid
#plt.grid(True)
plt.xlim([0, 8760])
plt.margins(x=0)
Expand All @@ -214,8 +211,7 @@ def compare_results(
# ----------
# Labelling
# ----------
font_additional_info = plotting_styles.font_info()
font_additional_info['size'] = 4
font_additional_info = plotting_styles.font_info(size=4)

plt.title(
'RMSE: {} Std_dev_% {} (+-{} GW) R_2: {}'.format(
Expand Down Expand Up @@ -271,26 +267,22 @@ def compare_peak(
x_smoothed, y_modelled_peak_dh_smoothed = plotting_results.smooth_data(range(24), modelled_peak_dh, num=500)

plt.plot(
#range(24),
#modelled_peak_dh,
x_smoothed,
y_modelled_peak_dh_smoothed,
color='blue',
linestyle='-',
linestyle='--',
linewidth=0.5,
label='model')

x_smoothed, validation_elec_2015_peak_smoothed = plotting_results.smooth_data(range(24), validation_elec_2015_peak, num=500)

plt.plot(
#range(24),
#validation_elec_2015_peak,
x_smoothed,
validation_elec_2015_peak_smoothed,
color='black',
linestyle='--',
linestyle='-',
linewidth=0.5,
label='actual')
label='validation')

# Calculate hourly differences in %
diff_p_h = np.round((100 / validation_elec_2015_peak) * modelled_peak_dh, 1)
Expand Down
22 changes: 8 additions & 14 deletions energy_demand/validation/lad_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,19 +204,18 @@ def spatial_validation_lad_level(
# Total sum modelled
tot_sum_modelled_elec = sum(fuel_elec_regs_yh.values())
tot_sum_modelled_resid_elec = sum(fuel_elec_residential_regs_yh.values())
tot_sum_modelled_gas = sum(fuel_gas_regs_yh.values())
# Total sum real
tot_sum_real_elec = sum(subnational_elec.values())
tot_sum_real_resid_elec = sum(subnational_elec_residential.values())
#logging.info("Spatial electricity validation: modelled: {} real: {}".format(tot_sum_modelled_elec, tot_sum_real_elec))
#logging.info("comparison real: {} modelled: {}".format(100, (100 / tot_sum_real_elec) * tot_sum_modelled_elec))
logging.info("Spatial electricity validation: modelled: {} real: {}".format(tot_sum_modelled_elec, tot_sum_real_elec))
logging.info("comparison real: {} modelled: {}".format(100, (100 / tot_sum_real_elec) * tot_sum_modelled_elec))
tot_sum_real_gas = sum(subnational_gas.values())
#logging.info("Spatial validation: modelled: {} real: {}".format(tot_sum_modelled_gas, tot_sum_real_gas))
#logging.info("comparison real: {} modelled: {}".format(100, (100 / tot_sum_real_gas) * tot_sum_modelled_gas))
logging.info("Spatial gas validation: modelled: {} real: {}".format(tot_sum_modelled_gas, tot_sum_real_gas))
logging.info("comparison real: {} modelled: {}".format(100, (100 / tot_sum_real_gas) * tot_sum_modelled_gas))
# Calculate correction factor
correction_factor_elec = tot_sum_modelled_elec / tot_sum_real_elec
correction_factor_resid_elec = tot_sum_modelled_resid_elec / tot_sum_real_resid_elec
Expand All @@ -240,7 +239,7 @@ def spatial_validation_lad_level(
tot_sum_real_gas = sum(subnational_gas.values())
logging.info("Spatial validation: modelled: {} real: {}".format(tot_sum_modelled_gas, tot_sum_real_gas))
logging.info("comparison real: {} modelled: {}".format(100, (100 / tot_sum_real_gas) * tot_sum_modelled_gas))
'''
#'''
# ----------------------------------------------
# TODO Correct REAL Values that sum is the same
# ----------------------------------------------
Expand Down Expand Up @@ -700,9 +699,7 @@ def spatial_validation(
verticalalignment="top",
fontsize=1)

font_additional_info = plotting_styles.font_info()

font_additional_info['size'] = 4
font_additional_info = plotting_styles.font_info(size=4)

title_info = ('R_2: {}, std_%: {} (GWh {}), av_diff_%: {} median_abs_dev: {}'.format(
round(r_value, 2),
Expand Down Expand Up @@ -924,10 +921,7 @@ def spatial_validation_multiple(
verticalalignment="top",
fontsize=1)

font_additional_info = plotting_styles.font_info()

font_additional_info['size'] = 3
font_additional_info['color'] = color_list[cnt_color]
font_additional_info = plotting_styles.font_info(size=3, color=color_list[cnt_color])

title_info = ('R_2: {}, std_%: {} (GWh {}), av_diff_%: {} median_abs_dev: {}'.format(
round(r_value, 2),
Expand Down

0 comments on commit f077920

Please sign in to comment.