diff --git a/energy_demand/geography/weather_region.py b/energy_demand/geography/weather_region.py index d6d4aa4b..3bac3091 100644 --- a/energy_demand/geography/weather_region.py +++ b/energy_demand/geography/weather_region.py @@ -275,55 +275,52 @@ def __init__( shape_y_dh=tech_lp['rs_profile_hp_y_dh'], shape_peak_dh=tech_lp['rs_lp_heating_hp_dh']['peakday']) - - - # flat lp - rs_profile_hp_y_dh = flat_shape_y_dh - - flat_rs_fuel_shape_hp_yh, rs_hp_shape_yd = get_fuel_shape_heating_hp_yh( + rs_fuel_shape_hp_yh, rs_hp_shape_yd = get_fuel_shape_heating_hp_yh( rs_profile_hp_y_dh, self.rs_tech_stock, self.rs_hdd_cy, assumptions.model_yeardays) - #else: - # not flat lp - rs_fuel_shape_hp_yh, rs_hp_shape_yd = get_fuel_shape_heating_hp_yh( - rs_profile_hp_y_dh, + + # Flat lp + flat_rs_fuel_shape_hp_yh, rs_hp_shape_yd = get_fuel_shape_heating_hp_yh( + flat_shape_y_dh, self.rs_tech_stock, self.rs_hdd_cy, assumptions.model_yeardays) + + #TODO Info: Same load for space and water heating for HP if assumptions.strategy_variables['flat_heat_pump_profile_both']['scenario_value']: flat_space_heating = True flat_water_heating = True elif assumptions.strategy_variables['flat_heat_pump_profile_only_water']['scenario_value']: flat_space_heating = False - flat_water_heating = False + flat_water_heating = True else: flat_space_heating = False flat_water_heating = False - if flat_water_heating and flat_space_heating: #Improve + if flat_water_heating and flat_space_heating: + # Flat load profiles for water and space heating self.rs_load_profiles.add_lp( unique_identifier=uuid.uuid4(), technologies=assumptions.tech_list['heating_non_const'], enduses=['rs_space_heating', 'rs_water_heating'], - shape_y_dh=rs_profile_hp_y_dh, + shape_y_dh=flat_shape_y_dh, shape_yd=rs_hp_shape_yd, shape_yh=flat_rs_fuel_shape_hp_yh, model_yeardays=assumptions.model_yeardays) elif flat_water_heating and not flat_space_heating: - + # Flat load profiles for water heating self.rs_load_profiles.add_lp( unique_identifier=uuid.uuid4(), technologies=assumptions.tech_list['heating_non_const'], enduses=['rs_water_heating'], - shape_y_dh=rs_profile_hp_y_dh, + shape_y_dh=flat_shape_y_dh, shape_yd=rs_hp_shape_yd, shape_yh=flat_rs_fuel_shape_hp_yh, model_yeardays=assumptions.model_yeardays) - self.rs_load_profiles.add_lp( unique_identifier=uuid.uuid4(), technologies=assumptions.tech_list['heating_non_const'], @@ -333,6 +330,7 @@ def __init__( shape_yh=rs_fuel_shape_hp_yh, model_yeardays=assumptions.model_yeardays) else: + # No flat load profile self.rs_load_profiles.add_lp( unique_identifier=uuid.uuid4(), technologies=assumptions.tech_list['heating_non_const'], diff --git a/energy_demand/plotting/plotting_multiple_scenarios.py b/energy_demand/plotting/plotting_multiple_scenarios.py index 70fb01eb..9d2efa40 100644 --- a/energy_demand/plotting/plotting_multiple_scenarios.py +++ b/energy_demand/plotting/plotting_multiple_scenarios.py @@ -6,14 +6,10 @@ import collections import numpy as np import matplotlib.pyplot as plt -import logging - from energy_demand.plotting import plotting_styles from energy_demand.plotting import plotting_program from energy_demand.basic import conversions from energy_demand.plotting import plotting_results -from energy_demand.basic import lookup_tables -from energy_demand.technologies import tech_related from energy_demand import enduse_func from energy_demand.profiles import load_factors @@ -848,8 +844,7 @@ def plot_radar_plots_average_peak_day( fueltype_to_model, fueltypes, year_to_plot, - fig_name, - plotshow + fig_name ): """Compare averaged dh profile overall regions for peak day for future year and base year @@ -869,7 +864,7 @@ def plot_radar_plots_average_peak_day( for scenario_cnt, scenario in enumerate(scenario_data): - print("scenario {} {} ".format(scenario, fueltype_to_model)) + print("-------Scenario: {} {}".format(scenario, fueltype_to_model)) base_yr = 2015 # Future year load profile @@ -900,7 +895,9 @@ def plot_radar_plots_average_peak_day( 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))) + + print("Calculation of diff in peak: {} {} {} {}".format( + scenario, round(diff_max_h, 2), round(by_max_h, 2), round(cy_max_h, 2))) # ---------------------------------- # Plot dh for peak day for base year diff --git a/energy_demand/plotting/plotting_results.py b/energy_demand/plotting/plotting_results.py index 27760ee3..ed1b80aa 100644 --- a/energy_demand/plotting/plotting_results.py +++ b/energy_demand/plotting/plotting_results.py @@ -2057,7 +2057,12 @@ def plot_radar_plot_multiple_lines( for i in range(nr_of_plot_steps * 2): minor_ticks.append(minor_tick_interval * i) + # Colors with scenarios color_scenarios = plotting_styles.color_list_scenarios() + + # Colors for plotting Fig. 13 + color_scenarios = plotting_styles.color_list_selection() + color_lines = ['black'] + color_scenarios years = ['2015', '2050'] linewidth_list = [1.0, 0.7] @@ -2123,16 +2128,6 @@ def plot_radar_plot_multiple_lines( # Draw ylabels (numbers) ax.set_rlabel_position(0) - # Remove last and first element - '''if len(axis_plots_inner) == 2: - axis_plots_inner = axis_plots_inner[1:] - axis_plots_innter_position = axis_plots_innter_position[1:] - elif len(axis_plots_inner) > 2: - axis_plots_inner = axis_plots_inner[1:1] - axis_plots_innter_position = axis_plots_innter_position[1:1] - else: - pass''' - # Working alternative plt.yticks( axis_plots_inner, @@ -2155,7 +2150,7 @@ def plot_radar_plot_multiple_lines( # Plot data ax.plot( angles_smoothed, - values_smoothed, + values_smoothed, color=color_line, linestyle=linestyle_list[cnt_year], linewidth=linewidth_list[cnt_year], @@ -2181,12 +2176,7 @@ def plot_radar_plot_multiple_lines( # ------------ # Title # ------------ - font_additional_info = plotting_styles.font_info() - font_additional_info['size'] = 4 - - #title_info = " lf_y_by: {} lf_y_cy: {}".format( - # lf_y_by, - # lf_y_cy) + font_additional_info = plotting_styles.font_info(size=4) #plt.title( # title_info, # loc='left', @@ -2196,12 +2186,11 @@ def plot_radar_plot_multiple_lines( # Legend # ------------ plt.legend( - ncol=2, - #loc='best', - bbox_to_anchor=(0.6, -0.1), + ncol=1, + bbox_to_anchor=(0.5, -0.1), prop={ 'family': 'arial', - 'size': 5}, + 'size': 4}, frameon=False) plt.savefig(fig_name) @@ -2625,6 +2614,8 @@ def plot_cross_graphs_scenarios( 'blue', 'darkolivegreen', 'firebrick']''' + all_x_values = [] + all_y_values = [] for scenario_nr, scenario in enumerate(all_scenarios): @@ -2659,6 +2650,8 @@ def plot_cross_graphs_scenarios( #y_val_national_lf_demand_cy = [national_tot_demand_p] y_val_national_lf_demand_cy = [national_peak_h_p] + all_x_values += x_values + all_y_values += y_values # ------------------------------------- # Plot # ------------------------------------- @@ -2736,18 +2729,20 @@ def plot_cross_graphs_scenarios( # ------- # Title information # ------- - max_peak_h = max(x_values) - min_peak_h = min(x_values) - min_lf = min(y_values) - max_lf = max(y_values) + max_lf = round(max(all_x_values), 2) + min_lf = round(min(all_x_values), 2) + min_peak_h = round(min(all_y_values), 2) + max_peak_h = round(max(all_y_values), 2) + + font_additional_info = plotting_styles.font_info(size=4) plt.title( - "max_peak_h: {} min_peak_h: {}, min_lf: {} max_lf: {}", - max_peak_h, - min_peak_h, - min_lf, - max_lf, - fontsize=10) + "max_peak_h: {} min_peak_h: {}, min_lf: {} max_lf: {}".format( + max_peak_h, + min_peak_h, + min_lf, + max_lf), + fontdict=font_additional_info) # -------- # Legend diff --git a/energy_demand/plotting/result_mapping.py b/energy_demand/plotting/result_mapping.py index a8175d8c..951a3f84 100644 --- a/energy_demand/plotting/result_mapping.py +++ b/energy_demand/plotting/result_mapping.py @@ -585,7 +585,8 @@ def create_geopanda_files( regions, fueltypes_nr, fueltypes, - path_shapefile_input + path_shapefile_input, + plot_crit_dict ): """Create map related files (png) from results. @@ -615,24 +616,135 @@ def create_geopanda_files( # ====================================== # Peak fuel (h) all enduses # ====================================== - for year in results_container['results_every_year'].keys(): + if plot_crit_dict['plot_peak_h']: + for year in results_container['results_every_year'].keys(): + for fueltype in range(fueltypes_nr): + print(" progress.. {}".format(fueltype)) + fueltype_str = tech_related.get_fueltype_str(fueltypes, fueltype) + + # Calculate peak h across all regions + field_name = 'peak_h_{}_{}'.format(year, fueltype_str) + + # Get maxium demand of 8760 h for every region + h_max_gwh_regs = np.max(results_container['results_every_year'][year][fueltype], axis=1) + + print("TOTAL peak fuel across all regs {} {} ".format(np.sum(h_max_gwh_regs), fueltype_str)) + + data_to_plot = basic_functions.array_to_dict(h_max_gwh_regs, regions) + + # Both need to be lists + merge_data = { + str(field_name): list(data_to_plot.values()), + str(unique_merge_id): list(regions)} + + # Merge to shapefile + lad_geopanda_shp = merge_data_to_shp( + lad_geopanda_shp, + merge_data, + unique_merge_id) + + bins = [0.2, 0.4, 0.6, 0.8, 1.0, 1.2] + + color_list, color_prop, user_classification, color_zero = colors_plus_minus_map( + bins=bins, + color_prop='qualitative', + color_order=True, + color_zero='#ffffff', + color_palette='YlGnBu_7') #YlGnBu_9 #8a2be2 'YlGnBu_9' 'PuBu_8' + #''' + + # If user classified, defined bins + plot_lad_national( + lad_geopanda_shp=lad_geopanda_shp, + legend_unit="GWh", + field_to_plot=field_name, + fig_name_part=field_name, + result_path=path_data_results_shapefiles, + color_palette='Dark2_7', + color_prop=color_prop, + user_classification=user_classification, + color_list=color_list, + bins=bins, + color_zero=color_zero) + + # ====================================== + # Load factors (absolute) + # ====================================== + if plot_crit_dict['plot_load_factors']: + for year in results_container['reg_load_factor_y'].keys(): + for fueltype in range(fueltypes_nr): + + fueltype_str = tech_related.get_fueltype_str(fueltypes, fueltype) + field_name = 'lf_{}_{}'.format(year, fueltype_str) + + results = basic_functions.array_to_dict( + results_container['reg_load_factor_y'][year][fueltype], regions) + + # Both need to be lists + merge_data = { + str(field_name): list(results.values()), + str(unique_merge_id): list(regions)} + + # Merge to shapefile + lad_geopanda_shp = merge_data_to_shp( + lad_geopanda_shp, + merge_data, + unique_merge_id) + + # ABSOLUTE + bins = [40, 45, 50, 55, 60, 75, 80] # must be of uneven length containing zero + #bins = [55, 60, 65, 70] # must be of uneven length containing zero + color_list, color_prop, user_classification, color_zero = colors_plus_minus_map( + bins=bins, + color_prop='qualitative', + color_order=True, + color_zero='#ffffff', + color_palette='YlGnBu_9') #8a2be2 'YlGnBu_9' 'PuBu_8' + + # If user classified, defined bins + plot_lad_national( + lad_geopanda_shp=lad_geopanda_shp, + legend_unit="%", + field_to_plot=field_name, + fig_name_part="lf_max_y", + result_path=path_data_results_shapefiles, + color_palette='Dark2_7', + color_prop=color_prop, + user_classification=user_classification, + color_list=color_list, + bins=bins, + color_zero=color_zero) + + # ====================================== + # Spatial maps of difference in load factors + # ====================================== + if plot_crit_dict['plot_load_factors_p']: + simulated_yrs = list(results_container['reg_load_factor_y'].keys()) + + final_yr = simulated_yrs[-1] + base_yr = simulated_yrs[0] + for fueltype in range(fueltypes_nr): - print(" progress.. {}".format(fueltype)) + logging.info("progress.. {}".format(fueltype)) fueltype_str = tech_related.get_fueltype_str(fueltypes, fueltype) + field_name = 'lf_diff_{}-{}_{}_'.format(base_yr, final_yr, fueltype_str) - # Calculate peak h across all regions - field_name = 'peak_h_{}_{}'.format(year, fueltype_str) + lf_end_yr = basic_functions.array_to_dict( + results_container['reg_load_factor_y'][final_yr][fueltype], + regions) - # Get maxium demand of 8760 h for every region - h_max_gwh_regs = np.max(results_container['results_every_year'][year][fueltype], axis=1) + lf_base_yr = basic_functions.array_to_dict( + results_container['reg_load_factor_y'][base_yr][fueltype], + regions) - print("TOTAL peak fuel across all regs {} {} ".format(np.sum(h_max_gwh_regs), fueltype_str)) - - data_to_plot = basic_functions.array_to_dict(h_max_gwh_regs, regions) + # Calculate load factor difference base and final year (100 = 100%) + diff_lf = {} + for reg in regions: + diff_lf[reg] = lf_end_yr[reg] - lf_base_yr[reg] # Both need to be lists merge_data = { - str(field_name): list(data_to_plot.values()), + str(field_name): list(diff_lf.values()), str(unique_merge_id): list(regions)} # Merge to shapefile @@ -641,45 +753,41 @@ def create_geopanda_files( merge_data, unique_merge_id) - bins = [0.2, 0.4, 0.6, 0.8, 1.0, 1.2] + # If user classified, defined bins [x for x in range(0, 1000000, 200000)] + #bins = [-4, -2, 0, 2, 4] # must be of uneven length containing zero + bins = [-15, -10, -5, 0, 5, 10, 15] # must be of uneven length containing zero color_list, color_prop, user_classification, color_zero = colors_plus_minus_map( bins=bins, color_prop='qualitative', color_order=True, color_zero='#ffffff', - color_palette='YlGnBu_7') #YlGnBu_9 #8a2be2 'YlGnBu_9' 'PuBu_8' - #''' + color_palette='Purples_9') - # If user classified, defined bins plot_lad_national( lad_geopanda_shp=lad_geopanda_shp, - legend_unit="GWh", + legend_unit="%", field_to_plot=field_name, - fig_name_part=field_name, + fig_name_part="lf_max_y", result_path=path_data_results_shapefiles, - color_palette='Dark2_7', + color_palette='Purples_9', color_prop=color_prop, user_classification=user_classification, color_list=color_list, - bins=bins, - color_zero=color_zero) + color_zero=color_zero, + bins=bins) # ====================================== - # Load factors (absolute) + # Population # ====================================== - for year in results_container['reg_load_factor_y'].keys(): - for fueltype in range(fueltypes_nr): - - fueltype_str = tech_related.get_fueltype_str(fueltypes, fueltype) - field_name = 'lf_{}_{}'.format(year, fueltype_str) + if plot_crit_dict['plot_population']: + for year in results_container['results_every_year'].keys(): - results = basic_functions.array_to_dict( - results_container['reg_load_factor_y'][year][fueltype], regions) + field_name = 'pop_{}'.format(year) # Both need to be lists merge_data = { - str(field_name): list(results.values()), + str(field_name): data['scenario_data']['population'][year].flatten().tolist(), str(unique_merge_id): list(regions)} # Merge to shapefile @@ -688,124 +796,19 @@ def create_geopanda_files( merge_data, unique_merge_id) - # ABSOLUTE - #''' - bins = [40, 45, 50, 55, 60, 75, 80] # must be of uneven length containing zero - #bins = [55, 60, 65, 70] # must be of uneven length containing zero - color_list, color_prop, user_classification, color_zero = colors_plus_minus_map( - bins=bins, - color_prop='qualitative', - color_order=True, - color_zero='#ffffff', - color_palette='YlGnBu_9') #8a2be2 'YlGnBu_9' 'PuBu_8' - #''' - # If user classified, defined bins + bins = [50000, 300000] + plot_lad_national( lad_geopanda_shp=lad_geopanda_shp, - legend_unit="%", + legend_unit="people", field_to_plot=field_name, - fig_name_part="lf_max_y", + fig_name_part="pop_", result_path=path_data_results_shapefiles, color_palette='Dark2_7', - color_prop=color_prop, - user_classification=user_classification, - color_list=color_list, - bins=bins, - color_zero=color_zero) - - # ====================================== - # Spatial maps of difference in load factors - # ====================================== - simulated_yrs = list(results_container['reg_load_factor_y'].keys()) - - final_yr = simulated_yrs[-1] - base_yr = simulated_yrs[0] - - for fueltype in range(fueltypes_nr): - logging.info("progress.. {}".format(fueltype)) - fueltype_str = tech_related.get_fueltype_str(fueltypes, fueltype) - field_name = 'lf_diff_{}-{}_{}_'.format(base_yr, final_yr, fueltype_str) - - lf_end_yr = basic_functions.array_to_dict( - results_container['reg_load_factor_y'][final_yr][fueltype], - regions) - - lf_base_yr = basic_functions.array_to_dict( - results_container['reg_load_factor_y'][base_yr][fueltype], - regions) - - # Calculate load factor difference base and final year (100 = 100%) - diff_lf = {} - for reg in regions: - diff_lf[reg] = lf_end_yr[reg] - lf_base_yr[reg] - - # Both need to be lists - merge_data = { - str(field_name): list(diff_lf.values()), - str(unique_merge_id): list(regions)} - - # Merge to shapefile - lad_geopanda_shp = merge_data_to_shp( - lad_geopanda_shp, - merge_data, - unique_merge_id) - - # If user classified, defined bins [x for x in range(0, 1000000, 200000)] - #bins = [-4, -2, 0, 2, 4] # must be of uneven length containing zero - bins = [-15, -10, -5, 0, 5, 10, 15] # must be of uneven length containing zero - - color_list, color_prop, user_classification, color_zero = colors_plus_minus_map( - bins=bins, - color_prop='qualitative', - color_order=True, - color_zero='#ffffff', - color_palette='Purples_9') - - plot_lad_national( - lad_geopanda_shp=lad_geopanda_shp, - legend_unit="%", - field_to_plot=field_name, - fig_name_part="lf_max_y", - result_path=path_data_results_shapefiles, - color_palette='Purples_9', - color_prop=color_prop, - user_classification=user_classification, - color_list=color_list, - color_zero=color_zero, - bins=bins) - - # ====================================== - # Population - # ====================================== - for year in results_container['results_every_year'].keys(): - - field_name = 'pop_{}'.format(year) - - # Both need to be lists - merge_data = { - str(field_name): data['scenario_data']['population'][year].flatten().tolist(), - str(unique_merge_id): list(regions)} - - # Merge to shapefile - lad_geopanda_shp = merge_data_to_shp( - lad_geopanda_shp, - merge_data, - unique_merge_id) - - # If user classified, defined bins - bins = [50000, 300000] - - plot_lad_national( - lad_geopanda_shp=lad_geopanda_shp, - legend_unit="people", - field_to_plot=field_name, - fig_name_part="pop_", - result_path=path_data_results_shapefiles, - color_palette='Dark2_7', - color_prop='qualitative', - user_classification=True, - bins=bins) + color_prop='qualitative', + user_classification=True, + bins=bins) # ====================================== # Total fuel (y) all enduses @@ -813,98 +816,101 @@ def create_geopanda_files( base_yr = list(results_container['results_every_year'].keys())[0] for year in results_container['results_every_year'].keys(): for fueltype in range(fueltypes_nr): - logging.info(" progress.. {}".format(fueltype)) - fueltype_str = tech_related.get_fueltype_str(fueltypes, fueltype) - - # --------- - # Sum per enduse and year (y) - # --------- - field_name = 'y_{}_{}'.format(year, fueltype_str) - # Calculate yearly sum across all regions - yearly_sum_gwh = np.sum( - results_container['results_every_year'][year][fueltype], - axis=1) - - data_to_plot = basic_functions.array_to_dict(yearly_sum_gwh, regions) - - # Both need to be lists - merge_data = { - str(field_name): list(data_to_plot.values()), - str(unique_merge_id): list(regions)} - - # Merge to shapefile - lad_geopanda_shp = merge_data_to_shp( - lad_geopanda_shp, - merge_data, - unique_merge_id) + fueltype_str = tech_related.get_fueltype_str(fueltypes, fueltype) - # If user classified, defined bins - plot_lad_national( - lad_geopanda_shp=lad_geopanda_shp, - legend_unit="GWh", - field_to_plot=field_name, - fig_name_part="_tot_all_enduses_y", - result_path=path_data_results_shapefiles, - color_palette='Dark2_7', - color_prop='qualitative', - user_classification=False) + if plot_crit_dict['plot_total_demand_fueltype']: + logging.info(" progress.. {}".format(fueltype)) + + # --------- + # Sum per enduse and year (y) + # --------- + field_name = 'y_{}_{}'.format(year, fueltype_str) + + # Calculate yearly sum across all regions + yearly_sum_gwh = np.sum( + results_container['results_every_year'][year][fueltype], + axis=1) + + data_to_plot = basic_functions.array_to_dict(yearly_sum_gwh, regions) + + # Both need to be lists + merge_data = { + str(field_name): list(data_to_plot.values()), + str(unique_merge_id): list(regions)} + + # Merge to shapefile + lad_geopanda_shp = merge_data_to_shp( + lad_geopanda_shp, + merge_data, + unique_merge_id) + + # If user classified, defined bins + plot_lad_national( + lad_geopanda_shp=lad_geopanda_shp, + legend_unit="GWh", + field_to_plot=field_name, + fig_name_part="_tot_all_enduses_y", + result_path=path_data_results_shapefiles, + color_palette='Dark2_7', + color_prop='qualitative', + user_classification=False) # =============================================== # Differences in percent per enduse and year (y) # =============================================== - field_name = 'y_diff_p_{}-{}_{}'.format(base_yr, year, fueltype_str) - - # Calculate yearly sums - yearly_sum_gwh_by = np.sum( - results_container['results_every_year'][base_yr][fueltype], - axis=1) - - yearly_sum_gwh_cy = np.sum( - results_container['results_every_year'][year][fueltype], - axis=1) - - # Calculate percentual difference - p_diff = ((yearly_sum_gwh_cy / yearly_sum_gwh_by) * 100) - 100 - - data_to_plot = basic_functions.array_to_dict(p_diff, regions) - - # Both need to be lists - merge_data = { - str(field_name): list(data_to_plot.values()), - str(unique_merge_id): list(regions)} - - # Merge to shapefile - lad_geopanda_shp = merge_data_to_shp( - lad_geopanda_shp, - merge_data, - unique_merge_id) - - # If user classified, defined bins [x for x in range(0, 1000000, 200000)] - #bins = get_reasonable_bin_values(list(data_to_plot.values())) - #bins = [-4, -2, 0, 2, 4] # must be of uneven length containing zero - bins = [-20, -10, 0, 10, 20, 30, 40] # must be of uneven length containing zero - - color_list, color_prop, user_classification, color_zero = colors_plus_minus_map( - bins=bins, - color_prop='qualitative', - color_order=True, - color_zero='#ffffff', - color_palette='Purples_9') - - # Plot difference in % per fueltype of total fuel (y) - plot_lad_national( - lad_geopanda_shp=lad_geopanda_shp, - legend_unit="GWh", - field_to_plot=field_name, - fig_name_part="tot_all_enduses_y_", - result_path=path_data_results_shapefiles, - color_palette='Purples_9', #'YlGn_9', #'Purples_9', - color_prop=color_prop, - user_classification=user_classification, - color_list=color_list, - color_zero=color_zero, - bins=bins) + if plot_crit_dict['plot_differences_p']: + field_name = 'y_diff_p_{}-{}_{}'.format( + base_yr, year, fueltype_str) + + # Calculate yearly sums + yearly_sum_gwh_by = np.sum( + results_container['results_every_year'][base_yr][fueltype], + axis=1) + + yearly_sum_gwh_cy = np.sum( + results_container['results_every_year'][year][fueltype], + axis=1) + + # Calculate percentual difference + p_diff = ((yearly_sum_gwh_cy / yearly_sum_gwh_by) * 100) - 100 + + data_to_plot = basic_functions.array_to_dict(p_diff, regions) + + # Both need to be lists + merge_data = { + str(field_name): list(data_to_plot.values()), + str(unique_merge_id): list(regions)} + + # Merge to shapefile + lad_geopanda_shp = merge_data_to_shp( + lad_geopanda_shp, + merge_data, + unique_merge_id) + + # If user classified, defined bins [x for x in range(0, 1000000, 200000)] + #bins = get_reasonable_bin_values(list(data_to_plot.values())) + #bins = [-4, -2, 0, 2, 4] # must be of uneven length containing zero + bins = [-40, -30, -20, -10, 0, 10, 20, 30, 40] # must be of uneven length containing zero + + color_list, color_prop, user_classification, color_zero = colors_plus_minus_map( + bins=bins, + color_prop='qualitative', + color_order=True) + + # Plot difference in % per fueltype of total fuel (y) + plot_lad_national( + lad_geopanda_shp=lad_geopanda_shp, + legend_unit="GWh", + field_to_plot=field_name, + fig_name_part="tot_all_enduses_y_", + result_path=path_data_results_shapefiles, + color_palette='Purples_9', + color_prop=color_prop, + user_classification=user_classification, + color_list=color_list, + color_zero=color_zero, + bins=bins) def colors_plus_minus_map( bins, @@ -949,11 +955,15 @@ def colors_plus_minus_map( # Colors pos and neg if color_order: - color_list_pos = getattr(palettable.colorbrewer.sequential, 'Reds_9').hex_colors - color_list_neg = getattr(palettable.colorbrewer.sequential, 'Greens_9').hex_colors + #color_list_pos = getattr(palettable.colorbrewer.sequential, 'Reds_9').hex_colors + #color_list_neg = getattr(palettable.colorbrewer.sequential, 'Greens_9').hex_colors + color_list_pos = getattr(palettable.colorbrewer.sequential, 'Reds_7').hex_colors + color_list_neg = getattr(palettable.colorbrewer.sequential, 'Greens_7').hex_colors else: - color_list_neg = getattr(palettable.colorbrewer.sequential, 'Reds_9').hex_colors - color_list_pos = getattr(palettable.colorbrewer.sequential, 'Greens_9').hex_colors + #color_list_neg = getattr(palettable.colorbrewer.sequential, 'Reds_9').hex_colors + #color_list_pos = getattr(palettable.colorbrewer.sequential, 'Greens_9').hex_colors + color_list_neg = getattr(palettable.colorbrewer.sequential, 'Reds_7').hex_colors + color_list_pos = getattr(palettable.colorbrewer.sequential, 'Greens_7').hex_colors # Number of categories nr_of_cat_pos_neg = int((len(bins) -1) / 2) diff --git a/energy_demand/processing/multiple_scenarios.py b/energy_demand/processing/multiple_scenarios.py index a6552137..41083e50 100644 --- a/energy_demand/processing/multiple_scenarios.py +++ b/energy_demand/processing/multiple_scenarios.py @@ -33,5 +33,5 @@ def process_result_multi_scen(path_to_scenarios, path_shapefile_input): #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_09", + "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')) diff --git a/energy_demand/processing/scenario_charts.py b/energy_demand/processing/scenario_charts.py index 7035703e..2a8a550e 100644 --- a/energy_demand/processing/scenario_charts.py +++ b/energy_demand/processing/scenario_charts.py @@ -155,16 +155,14 @@ def process_scenarios(path_to_scenarios, year_to_model=2015): fueltype_to_model='electricity', fueltypes=lookups['fueltypes'], year_to_plot=2050, - fig_name=os.path.join(path_result_folder), - plotshow=False) + fig_name=os.path.join(path_result_folder)) plotting_multiple_scenarios.plot_radar_plots_average_peak_day( scenario_data, fueltype_to_model='gas', fueltypes=lookups['fueltypes'], year_to_plot=2050, - fig_name=os.path.join(path_result_folder), - plotshow=False) + fig_name=os.path.join(path_result_folder)) # ---------------------- # Plot peak hour of all fueltypes for different scenario @@ -185,8 +183,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_09")) -#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_13")) #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")) \ No newline at end of file diff --git a/energy_demand/processing/single_scenario.py b/energy_demand/processing/single_scenario.py index 5fea2f1d..4ae35828 100644 --- a/energy_demand/processing/single_scenario.py +++ b/energy_demand/processing/single_scenario.py @@ -22,7 +22,15 @@ def main(path_data_energy_demand, path_shapefile_input): plot_crit_dict = { "write_shapefiles": False, # Write shapefiles - "spatial_results": False, # Spatial geopanda maps + "spatial_results": True, # Spatial geopanda maps + + "plot_differences_p": True, # Spatial maps of percentage difference per fueltype over time + "plot_total_demand_fueltype": False, # Spatial maps of total demand per fueltype over time + "plot_population": False, # Spatial maps of population + "plot_load_factors": False, # Spatial maps of load factor + "plot_load_factors_p": False, # Spatial maps of load factor change + "plot_peak_h": False, # Spatial maps of peak h demand + "plot_stacked_enduses": True, "plot_y_all_enduses": True, "plot_fuels_enduses_y": True, @@ -105,7 +113,8 @@ def main(path_data_energy_demand, path_shapefile_input): data['regions'], data['lookups']['fueltypes_nr'], data['lookups']['fueltypes'], - path_shapefile_input) + path_shapefile_input, + plot_crit_dict) # ---------------- # Write results to CSV files and merge with shapefile