Skip to content

Commit

Permalink
working on plotting fueltypes over time
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven Eggimann committed Dec 13, 2018
1 parent 5800588 commit bdf5550
Show file tree
Hide file tree
Showing 6 changed files with 216 additions and 19 deletions.
2 changes: 1 addition & 1 deletion energy_demand/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def energy_demand_model(
#name_config_path = 'h_h'
name_config_path = 'l_h' #TODO
#name_config_path = 'l_c'
#name_config_path = 'no_change'
name_config_path = 'no_change'

path_strategy_vars = os.path.join(local_data_path, 'energy_demand', '00_user_defined_variables', 'high_electrification')
path_strategy_vars = os.path.join(local_data_path, 'energy_demand', '00_user_defined_variables', name_config_path)
Expand Down
175 changes: 164 additions & 11 deletions energy_demand/plotting/fig_3_plot_over_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def scenario_over_time(

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

# dataframe with national peak (columns= simulation year, row: Realisation)

Expand All @@ -71,22 +71,22 @@ def scenario_over_time(
print("SCENARIO NAME {} {}".format(scenario_name, color))

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

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

# --------------------
# Try to smooth lines
# --------------------
sim_yrs_smoothed = sim_yrs
try:
sim_yrs_smoothed, mean_ed_reg_tot_y_smoothed = basic_plot_functions.smooth_data(sim_yrs, mean_ed_reg_tot_y, num=40000)
sim_yrs_smoothed, mean_national_peak_smoothed = basic_plot_functions.smooth_data(sim_yrs, mean_national_peak, num=40000)
_, df_q_05_smoothed = basic_plot_functions.smooth_data(sim_yrs, df_q_05, num=40000)
_, df_q_95_smoothed = basic_plot_functions.smooth_data(sim_yrs, df_q_95, num=40000)

mean_ed_reg_tot_y = pd.Series(mean_ed_reg_tot_y_smoothed, sim_yrs_smoothed)
mean_national_peak = pd.Series(mean_national_peak_smoothed, sim_yrs_smoothed)
#sim_yrs = pd.Series(sim_yrs_smoothed, sim_yrs_smoothed)
#sim_yrs = list(sim_yrs_smoothed)
df_q_05 = pd.Series(df_q_05_smoothed, sim_yrs_smoothed)
Expand All @@ -96,7 +96,7 @@ def scenario_over_time(
pass

plt.plot(
mean_ed_reg_tot_y,
mean_national_peak,
label="{} (mean)".format(scenario_name),
color=color)

Expand All @@ -123,12 +123,165 @@ def scenario_over_time(
ax.grid(which='major', color='black', axis='y', linestyle='--')

ax.spines['right'].set_visible(False)
ax.spines['left'].set_visible(False)
#ax.spines['left'].set_visible(False)
ax.spines['top'].set_visible(False)

# Turn off tick labels
#ax.set_yticklabels([])
ax.set_yticks([])
#'''
plt.tick_params(
axis='y', # changes apply to the x-axis
which='both', # both major and minor ticks are affected
bottom=False, # ticks along the bottom edge are off
top=False, # ticks along the top edge are off
labelbottom=False) # labels along the bottom edge are off
#'''
#plt.yticks([], [])

# --------
# Legend
# --------
'''legend = plt.legend(
#title="tt",
ncol=2,
prop={'size': 8},
loc='upper center',
bbox_to_anchor=(0.5, -0.1),
frameon=False)
legend.get_title().set_fontsize(8)'''

# Put a legend to the right of the current axis
ax.legend(
ncol=1,
prop={'size': 8},
loc='center left',
bbox_to_anchor=(1, 0.5),
frameon=False)
#legend.get_title().set_fontsize(8)

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

plt.tight_layout()
plt.show()
plt.savefig(os.path.join(result_path, fig_name))


def fueltypes_over_time(
scenario_result_container,
sim_yrs,
fig_name,
fueltype_str,
result_path
):

colors = {

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

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

'other1': '#C0E4FF',
'other2': '#3DF735',
'other3': '#AD6D70',
'other4': '#EC2504',
'other5': '#8C0B90',
}

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

for cnt, i in enumerate(scenario_result_container):
scenario_name = i['scenario_name']
national_sum = i['national_{}'.format(fueltype_str)]
# dataframe with national peak (columns= simulation year, row: Realisation)

# Calculate quantiles
quantile_95 = 0.95
quantile_05 = 0.05

try:
color = colors[scenario_name]
except KeyError:
color = list(colors.values())[cnt]

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

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

# Standard deviation over all realisations
df_q_05 = national_sum.quantile(quantile_05)
df_q_95 = national_sum.quantile(quantile_95)
print("dd")
print(df_q_05)
# --------------------
# Try to smooth lines
# --------------------
sim_yrs_smoothed = sim_yrs
try:
sim_yrs_smoothed, mean_national_sum_smoothed = basic_plot_functions.smooth_data(sim_yrs, mean_national_sum, num=40000)
_, df_q_05_smoothed = basic_plot_functions.smooth_data(sim_yrs, df_q_05, num=40000)
_, df_q_95_smoothed = basic_plot_functions.smooth_data(sim_yrs, df_q_95, num=40000)

mean_national_sum = pd.Series(mean_national_sum_smoothed, sim_yrs_smoothed)
#sim_yrs = pd.Series(sim_yrs_smoothed, sim_yrs_smoothed)
#sim_yrs = list(sim_yrs_smoothed)
df_q_05 = pd.Series(df_q_05_smoothed, sim_yrs_smoothed)
df_q_95 = pd.Series(df_q_95_smoothed, sim_yrs_smoothed)
except:
sim_yrs_smoothed = sim_yrs
pass

plt.plot(
mean_national_sum,
label="{} (mean)".format(scenario_name),
color=color)

# Plottin qunatilse and average scenario
df_q_05.plot.line(color=color, linestyle='--', linewidth=0.1, label='_nolegend_') #, label="0.05")
df_q_95.plot.line(color=color, linestyle='--', linewidth=0.1, label='_nolegend_') #, label="0.05")

plt.fill_between(
sim_yrs_smoothed,
list(df_q_95), #y1
list(df_q_05), #y2
alpha=0.25,
facecolor=color,
#label="weather uncertainty"
)

#plt.ylim(0, y_lim_val)
plt.xlim(2015, 2050)

# --------
# Different style
# --------
ax = plt.gca()
ax.grid(which='major', color='black', axis='y', linestyle='--')

ax.spines['right'].set_visible(False)
#ax.spines['left'].set_visible(False)
ax.spines['top'].set_visible(False)

#'''
plt.tick_params(
axis='y', # changes apply to the x-axis
which='both', # both major and minor ticks are affected
bottom=False, # ticks along the bottom edge are off
top=False, # ticks along the top edge are off
labelbottom=False) # labels along the bottom edge are off
#'''
#plt.yticks([], [])

# --------
# Legend
Expand Down
6 changes: 6 additions & 0 deletions energy_demand/read_write/read_weather_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ def read_in_weather_results(
results_container['national_peak'] = {}
results_container['regional_share_national_peak'] = {}

results_container['national_all_fueltypes'] = {}

for year in results_container['ed_reg_peakday']:

# Get peak demand of each region
Expand All @@ -70,6 +72,10 @@ def read_in_weather_results(
regional_peak = results_container['ed_reg_peakday'][year][fueltype_int][:, max_hour]
results_container['regional_share_national_peak'][year] = (100 / national_peak) * regional_peak #1 = 1 %

# Sum all regions for each fueltypes
print(results_container['ed_reg_tot_y'][year].shape)
results_container['national_all_fueltypes'][year] = np.sum(results_container['ed_reg_tot_y'][year], axis=1)
print(results_container['national_all_fueltypes'][year].shape)

logging.info("... Reading in results finished")
return results_container
52 changes: 45 additions & 7 deletions energy_demand/result_processing/weather_result_charts.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,14 @@ def main(
####################################################################
# Collect regional simulation data for every realisation
####################################################################
total_regional_demand = pd.DataFrame()
total_regional_demand_electricity = pd.DataFrame()
total_regional_demand_gas = pd.DataFrame()
total_regional_demand_hydrogen = pd.DataFrame()

peak_hour_demand = pd.DataFrame()
national_peak = pd.DataFrame()
regional_share_national_peak = pd.DataFrame()
national_electricity = pd.DataFrame()

for path_result_folder in paths_folders_result:
print("path_result_folder: " + str(path_result_folder))
Expand Down Expand Up @@ -122,8 +126,26 @@ def main(
realisation_data = pd.DataFrame(
[results_container['ed_reg_tot_y'][simulation_yr_to_plot][fueltype_int]],
columns=data['regions'])
total_regional_demand_electricity = total_regional_demand_electricity.append(realisation_data)

total_regional_demand = total_regional_demand.append(realisation_data)
'''realisation_data = pd.DataFrame(
[results_container['ed_reg_tot_y'][simulation_yr_to_plot][tech_related.get_fueltype_int('gas')]],
columns=data['regions'])
total_regional_demand_gas = total_regional_demand_gas.append(realisation_data)
realisation_data = pd.DataFrame(
[results_container['ed_reg_tot_y'][simulation_yr_to_plot][tech_related.get_fueltype_int('hydrogen')]],
columns=data['regions'])
total_regional_demand_hydrogen = total_regional_demand_hydrogen.append(realisation_data)'''
# National per fueltype
#national_all_fueltypes
fueltype_elec_int = tech_related.get_fueltype_int('electricity')
simulation_yrs_result = [results_container['national_all_fueltypes'][year][fueltype_elec_int] for year in results_container['national_all_fueltypes'].keys()]

realisation_data = pd.DataFrame(
[simulation_yrs_result],
columns=data['assumptions']['sim_yrs'])
national_electricity = national_electricity.append(realisation_data)

# --Peak day demand (dataframe with row: realisation, column=region)
realisation_data = pd.DataFrame(
Expand All @@ -150,12 +172,25 @@ def main(
# Add to scenario container
scenario_result_container.append({
'scenario_name': scenario_name,
'total_regional_demand': total_regional_demand,
'peak_hour_demand': peak_hour_demand,
'national_peak': national_peak,
'regional_share_national_peak': regional_share_national_peak
'regional_share_national_peak': regional_share_national_peak,

'total_regional_demand_electricity': total_regional_demand_electricity,
#'total_regional_demand_gas': total_regional_demand_gas,
#'total_regional_demand_hydrogen': total_regional_demand_hydrogen
'national_electricity': national_electricity,
})

# ------------------------------
# Plot national sum over time per fueltype and scenario
# ------------------------------
fig_3_plot_over_time.fueltypes_over_time(
scenario_result_container=scenario_result_container,
sim_yrs=data['assumptions']['sim_yrs'],
fig_name="fueltypes_over_time_{}.pdf".format(fueltype_str),
fueltype_str='electricity',
result_path=result_path)

# ------------------------------
# Plot national peak change over time for each scenario
Expand All @@ -167,19 +202,22 @@ def main(
fig_name="scenarios_peak_over_time_{}.pdf".format(fueltype_str),
result_path=result_path)




# ------------------------------
# Plotting spatial results
# Plotting spatial results for electricity
# ------------------------------
for i in scenario_result_container:
scenario_name = i['scenario_name']
total_regional_demand = i['total_regional_demand']
total_regional_demand_electricity = i['total_regional_demand_electricity']
peak_hour_demand = i['peak_hour_demand']
regional_share_national_peak = i['regional_share_national_peak']

print("... plot spatial map of total annual demand")
field_to_plot = 'std_dev'
fig_3_weather_map.total_annual_demand(
total_regional_demand,
total_regional_demand_electricity,
path_shapefile_input,
data['regions'],
pop_data=pop_data,
Expand Down
Binary file removed v_test__full.zip
Binary file not shown.
Binary file removed v_test__minimum.zip
Binary file not shown.

0 comments on commit bdf5550

Please sign in to comment.