def main(path_data_ed, path_shapefile_input, path_out_plots, plot_crit_dict): """Figure II plots """ # --------------------------------------------------------- # Iterate folders and read out all weather years and stations # --------------------------------------------------------- all_result_folders = os.listdir(path_data_ed) paths_folders_result = [] weather_yrs = [] weather_station_per_y = {} all_calculated_yrs_paths = [] for result_folder in all_result_folders: try: split_path_name = result_folder.split("__") weather_yr = int(split_path_name[0]) weather_yrs.append(weather_yr) try: weather_station = int(split_path_name[1]) except: weather_station = "all_stations" try: weather_station_per_y[weather_yr].append(weather_station) except: weather_station_per_y[weather_yr] = [weather_station] # Collect all paths to simulation result folders paths_folders_result.append( os.path.join(path_data_ed, result_folder)) tupyle_yr_path = (weather_yr, os.path.join(path_data_ed, result_folder)) all_calculated_yrs_paths.append(tupyle_yr_path) except ValueError: pass # ----------- # Used across different plots # ----------- data = {} data['lookups'] = lookup_tables.basic_lookups() data['enduses'], data['assumptions'], data[ 'regions'] = data_loader.load_ini_param(os.path.join(path_data_ed)) data['assumptions']['seasons'] = date_prop.get_season(year_to_model=2015) data['assumptions']['model_yeardays_daytype'], data['assumptions'][ 'yeardays_month'], data['assumptions'][ 'yeardays_month_days'] = date_prop.get_yeardays_daytype( year_to_model=2015) population_data = read_data.read_scenaric_population_data( os.path.join(path_data_ed, 'model_run_pop')) #################################################################### # Plotting weather variability results for all weather stations (Fig 2b) #################################################################### weather_yr_container = defaultdict(dict) for weather_yr, result_folder in all_calculated_yrs_paths: results_container = read_data.read_in_results( os.path.join(result_folder, 'model_run_results_txt'), data['assumptions']['seasons'], data['assumptions']['model_yeardays_daytype']) weather_yr_container['tot_fueltype_yh'][ weather_yr] = results_container[ 'tot_fueltype_yh'] #tot_fueltype_yh weather_yr_container['results_enduse_every_year'][ weather_yr] = results_container['ed_fueltype_regs_yh'] # #################################################################### # Create plot with regional and non-regional plots for second paper # Compare hdd calculations and disaggregation of regional and local # #################################################################### if plot_crit_dict['plot_scenarios_sorted']: fig_p2_annual_hours_sorted.run( data_input=weather_yr_container['results_enduse_every_year'], regions=data['regions'], simulation_yrs_to_plot=[2015], # Simulation year to plot fueltype_str='electricity', path_shapefile=path_shapefile_input, fig_name=os.path.join(path_out_plots, "fig_paper_IIb_weather_var_map.pdf"))
def process_scenarios(path_to_scenarios, year_to_model=2015): """Iterate folder with scenario results and plot charts Arguments ---------- path_to_scenarios : str Path to folders with stored results year_to_model : int, default=2015 Year of base year """ # ----------- # Charts to plot # ----------- heat_pump_range_plot = True # Plot of changing scenario values stored in scenario name # Delete folder results if existing path_result_folder = os.path.join( path_to_scenarios, "__results_hp_chart") basic_functions.delete_folder(path_result_folder) seasons = date_prop.get_season( year_to_model=year_to_model) model_yeardays_daytype, _, _ = date_prop.get_yeardays_daytype( year_to_model=year_to_model) lookups = lookup_tables.basic_lookups() # Get all folders with scenario run results (name of folder is scenario) scenarios_hp = os.listdir(path_to_scenarios) scenario_data = {} for scenario_hp in scenarios_hp: print("HP SCENARIO " + str(scenario_hp)) print(path_to_scenarios) scenario_data[scenario_hp] = {} # Simulation information is read in from .ini file for results path_fist_scenario = os.path.join(path_to_scenarios, scenario_hp) # ------------------------------- # Iterate folders and get results # ------------------------------- scenarios = os.listdir(path_fist_scenario) for scenario in scenarios: enduses, assumptions, reg_nrs, regions = data_loader.load_ini_param( os.path.join(path_fist_scenario, scenario)) # Add scenario name to folder scenario_data[scenario_hp][scenario] = {} path_to_result_files = os.path.join( path_fist_scenario, scenario, 'model_run_results_txt') scenario_data[scenario_hp][scenario] = read_data.read_in_results( path_result=path_to_result_files, seasons=seasons, model_yeardays_daytype=model_yeardays_daytype) # ----------------------- # Generate result folder # ----------------------- basic_functions.create_folder(path_result_folder) # ------------------------------- # Generate plot with heat pump ranges # ------------------------------- if heat_pump_range_plot: plotting_multiple_scenarios.plot_heat_pump_chart_multiple( lookups, regions, hp_scenario_data=scenario_data, fig_name=os.path.join(path_result_folder, "comparison_hp_share_peak_h.pdf"), txt_name=os.path.join(path_result_folder, "comparison_hp_share_peak_h.txt"), fueltype_str_input='electricity', plotshow=True) return
def plot_fig_spatio_temporal_validation(path_regional_calculations, path_rolling_elec_demand, path_temporal_elec_validation, path_temporal_gas_validation, path_non_regional_elec_2015, path_out_plots, plot_show=False): """ Create plot with regional and non-regional plots for second paper Compare hdd calculations and disaggregation of regional and local """ # --------------------------------------------------------- # Iterate folders and read out all weather years and stations # --------------------------------------------------------- all_result_folders = os.listdir(path_regional_calculations) paths_folders_result = [] data_container = defaultdict(dict) ed_fueltype_regs_yh = defaultdict(dict) weather_yr_station_tot_fueltype_yh = defaultdict(dict) residential_results = defaultdict(dict) for scenario_folder in all_result_folders: result_folders = os.listdir( os.path.join(path_regional_calculations, scenario_folder)) for result_folder in result_folders: try: split_path_name = result_folder.split("__") weather_yr = int(split_path_name[0]) try: weather_station = int(split_path_name[1]) except: weather_station = "all_stations" paths_folders_result.append( os.path.join(path_regional_calculations, result_folder)) data = {} data['lookups'] = lookup_tables.basic_lookups() data['enduses'], data['assumptions'], data[ 'regions'] = data_loader.load_ini_param( os.path.join( path_regional_calculations, all_result_folders[0])) # last result folder data['assumptions']['seasons'] = date_prop.get_season( year_to_model=2015) data['assumptions']['model_yeardays_daytype'], data[ 'assumptions']['yeardays_month'], data['assumptions'][ 'yeardays_month_days'] = date_prop.get_yeardays_daytype( year_to_model=2015) results_container = read_data.read_in_results( os.path.join(path_regional_calculations, scenario_folder, "{}__{}".format(weather_yr, weather_station), 'model_run_results_txt'), data['assumptions']['seasons'], data['assumptions']['model_yeardays_daytype']) weather_yr_station_tot_fueltype_yh[weather_yr][ weather_station] = results_container['tot_fueltype_yh'] ed_fueltype_regs_yh[weather_yr][ weather_station] = results_container['ed_fueltype_regs_yh'] residential_results[weather_yr][ weather_station] = results_container['residential_results'] except ValueError: pass data_container['ed_fueltype_regs_yh'] = ed_fueltype_regs_yh data_container['tot_fueltype_yh'] = weather_yr_station_tot_fueltype_yh data_container['residential_results'] = residential_results data_container = dict(data_container) # ------------------------------------------------- # Collect non regional 2015 elec data # Calculated with all regional weather stations # ------------------------------------------------- year_non_regional = 2015 path_with_txt = os.path.join( path_non_regional_elec_2015, "{}__{}".format(str(year_non_regional), "all_stations"), 'model_run_results_txt') demand_year_non_regional = read_data.read_in_results( path_with_txt, data['assumptions']['seasons'], data['assumptions']['model_yeardays_daytype']) tot_fueltype_yh = demand_year_non_regional['tot_fueltype_yh'] fueltype_int = tech_related.get_fueltype_int('electricity') non_regional_elec_2015 = tot_fueltype_yh[year_non_regional][fueltype_int] # ---Collect real electricity data of year 2015 elec_2015_indo, _ = elec_national_data.read_raw_elec_2015( path_rolling_elec_demand) # Factor data as total sum is not identical f_diff_elec = np.sum(non_regional_elec_2015) / np.sum(elec_2015_indo) elec_factored_yh = f_diff_elec * elec_2015_indo # ***************************************************************** # Temporal validation # Compare regional and non regional and actual demand over time # ***************************************************************** simulation_yr_to_plot = 2015 winter_week, spring_week, summer_week, autumn_week = date_prop.get_seasonal_weeks( ) # Peak day peak_day, _ = enduse_func.get_peak_day_single_fueltype(elec_factored_yh) # Convert days to hours period_to_plot = list(range(0, 400)) period_to_plot = date_prop.get_8760_hrs_from_yeardays(winter_week) period_to_plot = date_prop.get_8760_hrs_from_yeardays([peak_day]) period_to_plot_winter = date_prop.get_8760_hrs_from_yeardays(winter_week) period_to_plot_spring = date_prop.get_8760_hrs_from_yeardays(spring_week) fig_p2_temporal_validation.run_fig_p2_temporal_validation( data_input=data_container['tot_fueltype_yh'], weather_yr=2015, fueltype_str='electricity', simulation_yr_to_plot=simulation_yr_to_plot, # Simulation year to plot period_h=period_to_plot, validation_elec_2015=elec_factored_yh, non_regional_elec_2015=non_regional_elec_2015, fig_name=os.path.join(path_out_plots, "temporal_validation_elec.pdf"), titel="yearday: {}".format(peak_day), y_lim_val=55, plot_validation=False, plot_show=plot_show) fueltype_gas = tech_related.get_fueltype_int('gas') fig_p2_temporal_validation.run_fig_p2_temporal_validation( data_input=data_container['tot_fueltype_yh'], weather_yr=2015, fueltype_str='gas', simulation_yr_to_plot=simulation_yr_to_plot, # Simulation year to plot period_h=period_to_plot, validation_elec_2015=None, non_regional_elec_2015=tot_fueltype_yh[year_non_regional] [fueltype_gas], fig_name=os.path.join(path_out_plots, "temporal_validation_gas.pdf"), titel="yearday: {}".format(peak_day), y_lim_val=250, plot_validation=False, plot_show=plot_show) # ------------------- # Spatial validation (not with maps) # ------------------- # non_regional: All weather station, spatially disaggregated TODO Give BETTER NAMES # regional: Only one weather station for whole countr but still data for every region weather_yr = 2015 fig_p2_spatial_val.run( simulation_yr_to_plot=simulation_yr_to_plot, demand_year_non_regional=demand_year_non_regional[ 'residential_results'][weather_yr], demand_year_regional=data_container['residential_results'][weather_yr], fueltypes=data['lookups']['fueltypes'], fig_path=path_out_plots, path_temporal_elec_validation=path_temporal_elec_validation, path_temporal_gas_validation=path_temporal_gas_validation, regions=data['regions'], plot_crit=plot_show)
def process_scenarios(path_to_scenarios, year_to_model=2015): """Iterate folder with scenario results and plot charts Arguments ---------- path_to_scenarios : str Path to folders with stored results year_to_model : int, default=2015 Year of base year """ # ----------- # Charts to plot # ----------- heat_pump_range_plot = False # Plot of changing scenario values stored in scenario name plot_multiple_cross_charts = True # Compare cross charts of different scenario comparison_year = 2050 year_to_plot = 2050 # Delete folder results if existing path_result_folder = os.path.join( path_to_scenarios, "__results_multiple_scenarios") basic_functions.delete_folder(path_result_folder) seasons = date_prop.get_season( year_to_model=year_to_model) model_yeardays_daytype, _, _ = date_prop.get_yeardays_daytype( year_to_model=year_to_model) lookups = lookup_tables.basic_lookups() # Get all folders with scenario run results (name of folder is scenario) scenarios = os.listdir(path_to_scenarios) # Simulation information is read in from .ini file for results path_fist_scenario = os.path.join(path_to_scenarios, scenarios[0]) enduses, assumptions, regions = data_loader.load_ini_param( path_fist_scenario) # ------------------------------- # Iterate folders and get results # ------------------------------- scenario_data = {} for scenario in scenarios: scenario_data[scenario] = {} all_stations = os.listdir( os.path.join(path_to_scenarios, scenario)) _to_igore = [ 'infoparam.txt', 'model_run_pop', 'PDF_validation', 'model_run_sim_param.ini'] for station in all_stations: if station not in _to_igore: path_to_result_files = os.path.join( path_to_scenarios, scenario, station, 'model_run_results_txt') scenario_data[scenario] = read_data.read_in_results( path_result=path_to_result_files, seasons=seasons, model_yeardays_daytype=model_yeardays_daytype) else: pass # Create result folder basic_functions.create_folder(path_result_folder) # ------------------------------- # Generate plot with heat pump ranges # ------------------------------- if heat_pump_range_plot: plotting_multiple_scenarios.plot_heat_pump_chart( lookups, regions, scenario_data, fig_name=os.path.join(path_result_folder, "comparison_hp_service_switch_and_lf.pdf"), fueltype_str_input='electricity', plotshow=True) # ------------------------------- # Compare cross charts for different scenario # Ideally only compare two scenario # ------------------------------- if plot_multiple_cross_charts: fig_cross_graphs.plot_cross_graphs_scenarios( base_yr=2015, comparison_year=comparison_year, regions=regions, scenario_data=scenario_data, fueltype_int=lookups['fueltypes']['electricity'], fueltype_str='electricity', fig_name=os.path.join(path_result_folder, "cross_chart_electricity.pdf"), label_points=False, plotshow=False) fig_cross_graphs.plot_cross_graphs_scenarios( base_yr=2015, comparison_year=comparison_year, regions=regions, scenario_data=scenario_data, fueltype_int=lookups['fueltypes']['gas'], fueltype_str='gas', fig_name=os.path.join(path_result_folder, "cross_chart_gas.pdf"), label_points=False, plotshow=False) # ------------------------------- # Plot total demand for every year in line plot # ------------------------------- plotting_multiple_scenarios.plot_tot_fueltype_y_over_time( scenario_data, lookups['fueltypes'], fueltypes_to_plot=['electricity', 'gas'], fig_name=os.path.join(path_result_folder, "tot_y_multiple_fueltypes.pdf"), txt_name=os.path.join(path_result_folder, "tot_y_multiple_fueltypes.txt"), plotshow=False) plotting_multiple_scenarios.plot_tot_y_over_time( scenario_data, fig_name=os.path.join(path_result_folder, "tot_y_multiple.pdf"), plotshow=False) # ------------------------------- # Plot for all regions demand for every year in line plot # ------------------------------- plotting_multiple_scenarios.plot_reg_y_over_time( scenario_data, fig_name=os.path.join(path_result_folder, "reg_y_multiple.pdf"), plotshow=False) # ------------------------------- # Plot comparison of total demand for a year for all LADs (scatter plot) # ------------------------------- plotting_multiple_scenarios.plot_LAD_comparison_scenarios( scenario_data, year_to_plot=year_to_plot, fig_name=os.path.join(path_result_folder, "LAD_multiple.pdf"), plotshow=False) # ------------------------------- # Plot different profiles in radar plot (spider plot) # ------------------------------- plotting_multiple_scenarios.plot_radar_plots_average_peak_day( scenario_data, fueltype_to_model='electricity', fueltypes=lookups['fueltypes'], year_to_plot=year_to_plot, 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=year_to_plot, fig_name=os.path.join(path_result_folder)) # ---------------------- # Plot peak hour of all fueltypes for different scenario # ---------------------- plotting_multiple_scenarios.plot_tot_y_peak_hour( scenario_data, fig_name=os.path.join(path_result_folder, "tot_y_peak_h_electricity.pdf"), fueltype_str_input='electricity', plotshow=False) plotting_multiple_scenarios.plot_tot_y_peak_hour( scenario_data, fig_name=os.path.join(path_result_folder, "tot_y_peak_h_gas.pdf"), fueltype_str_input='gas', plotshow=False) print("Finished processing multiple scenario") return
def main(path_data_energy_demand, path_shapefile_input): """Read in all results and plot PDFs Arguments ---------- path_data_energy_demand : str Path to results path_shapefile_input : str Path to shapefile """ print("Start processing") # --------- # Criterias # --------- write_shapefiles = False # Write shapefiles spatial_results = True # Spatial geopanda maps # Set up logger logger_setup.set_up_logger( os.path.join(path_data_energy_demand, "plotting.log")) # ------------------ # Load necessary inputs for read in # ------------------ data = {} data['local_paths'] = data_loader.load_local_paths(path_data_energy_demand) data['result_paths'] = data_loader.load_result_paths( os.path.join(path_data_energy_demand, '_result_data')) data['lookups'] = lookup_tables.basic_lookups() # --------------- # Folder cleaning # --------------- basic_functions.del_previous_setup( data['result_paths']['data_results_PDF']) basic_functions.del_previous_setup( data['result_paths']['data_results_shapefiles']) basic_functions.create_folder(data['result_paths']['data_results_PDF']) basic_functions.create_folder( data['result_paths']['data_results_shapefiles']) # Simulation information is read in from .ini file for results data['enduses'], data['assumptions'], data['reg_nrs'], data[ 'regions'] = data_loader.load_ini_param( os.path.join(path_data_energy_demand, '_result_data')) # Other information is read in data['assumptions']['seasons'] = date_prop.get_season(year_to_model=2015) data['assumptions']['model_yeardays_daytype'], data['assumptions'][ 'yeardays_month'], data['assumptions'][ 'yeardays_month_days'] = date_prop.get_model_yeardays_daytype( year_to_model=2015) # Read scenario data data['scenario_data'] = {} data['scenario_data'][ 'population'] = read_data.read_scenaric_population_data( data['result_paths']['model_run_pop']) # -------------------------------------------- # Reading in results from different model runs # Read in and plot in same step if memory is a problem # -------------------------------------------- results_container = read_data.read_in_results( data['result_paths']['data_results_model_runs'], data['assumptions']['seasons'], data['assumptions']['model_yeardays_daytype']) # ---------------- # Write results to CSV files and merge with shapefile # ---------------- if write_shapefiles: write_data.create_shp_results(data, results_container, data['local_paths'], data['lookups'], data['regions']) # ------------------------------ # Plotting other results # ------------------------------ plotting_results.run_all_plot_functions(results_container, data['reg_nrs'], data['regions'], data['lookups'], data['result_paths'], data['assumptions'], data['enduses']) # ------------------------------ # Plotting spatial results # ------------------------------ print("... plotting spatial results") if spatial_results: logging.info("Create spatial geopanda files") result_mapping.create_geopanda_files( data, results_container, data['result_paths']['data_results_shapefiles'], data['regions'], data['lookups']['fueltypes_nr'], data['lookups']['fueltypes'], path_shapefile_input) print("===================================") print("... finished reading and plotting results") print("===================================")
def run_fig_spatial_distribution_of_peak( scenarios, path_to_folder_with_scenarios, path_shapefile, sim_yrs, field_to_plot, unit, fig_path, fueltype_str='electricity' ): """ """ weather_yrs = [] calculated_yrs_paths = [] fueltype_int = tech_related.get_fueltype_int(fueltype_str) for scenario in scenarios: path_scenario = os.path.join(path_to_folder_with_scenarios, scenario) all_result_folders = os.listdir(path_scenario) for result_folder in all_result_folders: try: split_path_name = result_folder.split("__") weather_yr = int(split_path_name[0]) weather_yrs.append(weather_yr) tupyle_yr_path = (weather_yr, os.path.join(path_scenario)) calculated_yrs_paths.append(tupyle_yr_path) except ValueError: pass for simulation_yr in sim_yrs: container = {} container['abs_demand_in_peak_h_pp'] = {} container['abs_demand_in_peak_h'] = {} container['p_demand_in_peak_h'] = {} for weather_yr, path_data_ed in calculated_yrs_paths: print("... prepare data {} {}".format(weather_yr, path_data_ed)) path_to_weather_yr = os.path.join(path_data_ed, "{}__{}".format(weather_yr, 'all_stations')) data = {} data['lookups'] = lookup_tables.basic_lookups() data['enduses'], data['assumptions'], regions = data_loader.load_ini_param(os.path.join(path_data_ed)) data['assumptions']['seasons'] = date_prop.get_season(year_to_model=2015) data['assumptions']['model_yeardays_daytype'], data['assumptions']['yeardays_month'], data['assumptions']['yeardays_month_days'] = date_prop.get_yeardays_daytype(year_to_model=2015) # Population population_data = read_data.read_scenaric_population_data(os.path.join(path_data_ed, 'model_run_pop')) results_container = read_data.read_in_results( os.path.join(path_to_weather_yr, 'model_run_results_txt'), data['assumptions']['seasons'], data['assumptions']['model_yeardays_daytype']) # --------------------------------------------------- # Calculate hour with national peak demand # This may be different depending on the weather yr # --------------------------------------------------- ele_regions_8760 = results_container['ed_fueltype_regs_yh'][simulation_yr][fueltype_int] sum_all_regs_fueltype_8760 = np.sum(ele_regions_8760, axis=0) # Sum for every hour max_day = int(basic_functions.round_down((np.argmax(sum_all_regs_fueltype_8760) / 24), 1)) max_h = np.argmax(sum_all_regs_fueltype_8760) max_demand = np.max(sum_all_regs_fueltype_8760) # Calculate the national peak demand in GW national_peak_GW = np.max(sum_all_regs_fueltype_8760) # ------------------------------------------------------ # Calculate the contribution of the regional peak demand # ------------------------------------------------------ demand_in_peak_h = ele_regions_8760[:, max_h] if unit == 'GW': container['abs_demand_in_peak_h'][weather_yr] = demand_in_peak_h elif unit == 'kW': container['abs_demand_in_peak_h'][weather_yr] = demand_in_peak_h * 1000000 # Convert to KWh else: # Use GW as default container['abs_demand_in_peak_h'][weather_yr] = demand_in_peak_h container['abs_demand_in_peak_h_pp'][weather_yr] = demand_in_peak_h / population_data[simulation_yr] # Relative fraction of regional demand in relation to peak container['p_demand_in_peak_h'][weather_yr] = (demand_in_peak_h / national_peak_GW ) * 100 # given as percent print("=================================") print("{} {} {} {}".format( simulation_yr, weather_yr, np.sum(ele_regions_8760), national_peak_GW)) # -------------- # Create dataframe with all weather yrs calculatiosn for every region # region1, region2, region3 # weather yr1 # weather yr2 # -------------- # Convert regional data to dataframe abs_demand_in_peak_h_pp = np.array(list(container['abs_demand_in_peak_h_pp'].values())) abs_demand_peak_h = np.array(list(container['abs_demand_in_peak_h'].values())) p_demand_peak_h = np.array(list(container['p_demand_in_peak_h'].values())) # Absolute demand df_abs_peak_demand = pd.DataFrame( abs_demand_peak_h, columns=regions, index=list(container['abs_demand_in_peak_h'].keys())) # Relative demand df_p_peak_demand = pd.DataFrame( p_demand_peak_h, columns=regions, index=list(container['p_demand_in_peak_h'].keys())) df_abs_demand_in_peak_h_pp = pd.DataFrame( abs_demand_in_peak_h_pp, columns=regions, index=list(container['abs_demand_in_peak_h_pp'].keys())) # Absolute peak value - mean max_peak_h_across_weather_yrs = df_abs_peak_demand.max() average_across_weather_yrs = df_abs_peak_demand.mean() diff_peak_h_minus_mean = max_peak_h_across_weather_yrs - average_across_weather_yrs for index, row in df_p_peak_demand.iterrows(): print("Weather yr: {} Total p: {}".format(index, np.sum(row))) assert round(np.sum(row), 4) == 100.0 # ---------------------------- # Calculate standard deviation # ---------------------------- std_deviation_df_abs_demand_in_peak_h_pp = df_abs_demand_in_peak_h_pp.std() std_deviation_abs_demand_peak_h = df_abs_peak_demand.std() std_deviation_p_demand_peak_h = df_p_peak_demand.std() print("=========") print("National stats") print("=========") print("Sum of std of absolut peak demand: " + str(np.sum(std_deviation_abs_demand_peak_h))) # -------------------- # Create map # -------------------- regional_statistics_columns = [ 'name', 'std_deviation_p_demand_peak_h', 'std_deviation_abs_demand_peak_h', 'std_deviation_df_abs_demand_in_peak_h_pp', 'diff_peak_h_minus_mean'] df_stats = pd.DataFrame(columns=regional_statistics_columns) for region_name in regions: # 'name', 'absolute_GW', 'p_GW_peak' line_entry = [[ region_name, std_deviation_p_demand_peak_h[region_name], std_deviation_abs_demand_peak_h[region_name], std_deviation_df_abs_demand_in_peak_h_pp[region_name], diff_peak_h_minus_mean[region_name], ]] line_df = pd.DataFrame(line_entry, columns=regional_statistics_columns) df_stats = df_stats.append(line_df) # Load uk shapefile uk_shapefile = gpd.read_file(path_shapefile) # Merge stats to geopanda shp_gdp_merged = uk_shapefile.merge( df_stats, on='name') # Assign projection crs = {'init': 'epsg:27700'} #27700: OSGB_1936_British_National_Grid uk_gdf = gpd.GeoDataFrame(shp_gdp_merged, crs=crs) ax = uk_gdf.plot( figsize=basic_plot_functions.cm2inch(25, 20)) nr_of_intervals = 6 bin_values = result_mapping.get_reasonable_bin_values_II( data_to_plot=list(uk_gdf[field_to_plot]), nr_of_intervals=nr_of_intervals) # Maual bins #bin_values = [0, 0.005, 0.01, 0.015, 0.02, 0.025, 0.03] print(float(uk_gdf[field_to_plot].max())) print("BINS " + str(bin_values)) uk_gdf, cmap_rgb_colors, color_zero, min_value, max_value = fig_p2_weather_val.user_defined_bin_classification( uk_gdf, field_to_plot, bin_values=bin_values) # plot with face color attribute uk_gdf.plot( ax=ax, facecolor=uk_gdf['bin_color'], edgecolor='black', linewidth=0.5) legend_handles = result_mapping.add_simple_legend( bin_values, cmap_rgb_colors, color_zero) plt.legend( handles=legend_handles, title="{} [{}]".format(field_to_plot, unit), prop={'size': 8}, #loc='upper center', bbox_to_anchor=(0.5, -0.05), loc='center left', bbox_to_anchor=(1, 0.5), frameon=False) # PLot bins on plot '''plt.text( -20, -20, bin_values[:-1], #leave away maximum value fontsize=8)''' plt.tight_layout() fig_out_path = os.path.join(fig_path, str(field_to_plot) + "__" + str(simulation_yr) + ".pdf") plt.savefig(fig_out_path)
def main(scenarios_path, path_shapefile_input, base_yr, simulation_yrs_to_plot): """Read in all results and plot PDFs Arguments ---------- scenarios_path : str Path to results path_shapefile_input : str Path to shapefile plot_crit_dict : dict Criteria to select plots to plot base_yr : int Base year comparison_year : int Year to generate comparison plots """ print("Start creating plots") # ------------------- # Create result folder # ------------------- result_path = os.path.join(scenarios_path, '_results_weather_plots') basic_functions.del_previous_setup(result_path) basic_functions.create_folder(result_path) for simulation_yr_to_plot in simulation_yrs_to_plot: print("-----------") print("...simulation_yr_to_plot: " + str(simulation_yr_to_plot)) print("-----------") data = {} # --------------------------------------------------------- # Iterate folders and read out all weather years and stations # --------------------------------------------------------- to_ignores = [ 'model_run_pop', 'PDF_validation', '_results_weather_plots' ] endings_to_ignore = ['.pdf', '.txt', '.ini'] all_scenarios_incl_ignored = os.listdir(scenarios_path) all_scenarios = [] for scenario in all_scenarios_incl_ignored: if scenario not in to_ignores: all_scenarios.append(scenario) scenario_result_container = [] for scenario_nr, scenario_name in enumerate(all_scenarios): print(" ") print("Scenario: {}".format(scenario_name)) print(" ") scenario_path = os.path.join(scenarios_path, scenario_name) all_result_folders = os.listdir(scenario_path) paths_folders_result = [] for result_folder in all_result_folders: if result_folder not in to_ignores and result_folder[ -4:] not in endings_to_ignore: paths_folders_result.append( os.path.join(scenario_path, result_folder)) fueltype_str_to_create_maps = ['electricity'] fueltype_str = 'electricity' fueltype_int = tech_related.get_fueltype_int(fueltype_str) #################################################################### # Collect regional simulation data for every realisation #################################################################### total_regional_demand_electricity = pd.DataFrame() peak_hour_demand = pd.DataFrame() national_peak = pd.DataFrame() regional_share_national_peak = pd.DataFrame() national_electricity = pd.DataFrame() national_gas = pd.DataFrame() national_hydrogen = pd.DataFrame() for path_result_folder in paths_folders_result: data = {} # Simulation information is read in from .ini file for results data['enduses'], data['assumptions'], data[ 'regions'] = data_loader.load_ini_param( os.path.join(path_result_folder)) pop_data = read_data.read_scenaric_population_data( os.path.join(path_result_folder, 'model_run_pop')) path_result_folder = os.path.join(path_result_folder, 'simulation_results') path_result_folder_model_runs = os.path.join( path_result_folder, 'model_run_results_txt') data['lookups'] = lookup_tables.basic_lookups() # Other information is read in data['assumptions']['seasons'] = date_prop.get_season( year_to_model=2015) data['assumptions']['model_yeardays_daytype'], data[ 'assumptions']['yeardays_month'], data['assumptions'][ 'yeardays_month_days'] = date_prop.get_yeardays_daytype( year_to_model=2015) # -------------------------------------------- # Reading in results from different model runs # -------------------------------------------- results_container = read_weather_results.read_in_weather_results( path_result_folder_model_runs, data['assumptions']['seasons'], data['assumptions']['model_yeardays_daytype'], fueltype_str='electricity') # --Total demand (dataframe with row: realisation, column=region) 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) # National per fueltype electricity 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) # National per fueltype gas fueltype_elec_int = tech_related.get_fueltype_int('gas') 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_gas = national_gas.append(realisation_data) # National per fueltype hydrogen fueltype_elec_int = tech_related.get_fueltype_int('hydrogen') 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_hydrogen = national_hydrogen.append(realisation_data) # --Peak day demand (dataframe with row: realisation, column=region) realisation_data = pd.DataFrame([ results_container['ed_reg_peakday_peak_hour'] [simulation_yr_to_plot][fueltype_int] ], columns=data['regions']) peak_hour_demand = peak_hour_demand.append(realisation_data) # --National peak simulation_yrs_result = [ results_container['national_peak'][year][fueltype_int] for year in results_container['national_peak'].keys() ] realisation_data = pd.DataFrame( [simulation_yrs_result], columns=data['assumptions']['sim_yrs']) national_peak = national_peak.append(realisation_data) # --Regional percentage of national peak demand realisation_data = pd.DataFrame([ results_container['regional_share_national_peak'] [simulation_yr_to_plot] ], columns=data['regions']) regional_share_national_peak = regional_share_national_peak.append( realisation_data) # Add to scenario container scenario_result_container.append({ 'scenario_name': scenario_name, 'peak_hour_demand': peak_hour_demand, 'national_peak': national_peak, 'regional_share_national_peak': regional_share_national_peak, 'total_regional_demand_electricity': total_regional_demand_electricity, 'national_electricity': national_electricity, 'national_gas': national_gas, 'national_hydrogen': national_hydrogen, }) # ------------------------------ # Plot national sum over time per fueltype and scenario # ------------------------------ print("... plotting national sum of fueltype over time ") 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( simulation_yr_to_plot, fueltype_str), fueltypes=['electricity', 'gas', 'hydrogen'], result_path=result_path, unit='TWh', plot_points=True, crit_smooth_line=True, seperate_legend=False) # ------------------------------ # Plot national peak change over time for each scenario including weather variability # ------------------------------ fig_3_plot_over_time.scenario_over_time( scenario_result_container=scenario_result_container, sim_yrs=data['assumptions']['sim_yrs'], fig_name="scenarios_peak_over_time__{}__{}.pdf".format( simulation_yr_to_plot, fueltype_str), plot_points=True, result_path=result_path, crit_smooth_line=True, seperate_legend=False) # ------------------------------ # Plotting spatial results for electricity # ------------------------------ for i in scenario_result_container: scenario_name = i['scenario_name'] 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_electricity, path_shapefile_input, data['regions'], pop_data=pop_data, simulation_yr_to_plot=simulation_yr_to_plot, result_path=result_path, fig_name="{}__tot_demand__{}_{}_{}.pdf".format( scenario_name, field_to_plot, fueltype_str, simulation_yr_to_plot), field_to_plot=field_to_plot, unit='GW', seperate_legend=False) print("... plot spatial map of peak hour demand") field_to_plot = 'std_dev' fig_3_weather_map.total_annual_demand( peak_hour_demand, path_shapefile_input, data['regions'], pop_data=pop_data, simulation_yr_to_plot=simulation_yr_to_plot, result_path=result_path, fig_name="{}__peak_h_demand_{}_{}_{}.pdf".format( scenario_name, field_to_plot, fueltype_str, simulation_yr_to_plot), field_to_plot=field_to_plot, unit='GW', seperate_legend=False) print( "... plot spatial map of percentage of regional peak hour demand" ) field_to_plot = 'mean' fig_3_weather_map.total_annual_demand( regional_share_national_peak, path_shapefile_input, data['regions'], pop_data=pop_data, simulation_yr_to_plot=simulation_yr_to_plot, result_path=result_path, fig_name="{}__regional_share_national_peak_{}_{}_{}.pdf". format(scenario_name, field_to_plot, fueltype_str, simulation_yr_to_plot), field_to_plot=field_to_plot, unit='percentage', seperate_legend=False, bins=[0.000001, 0.25, 0.5, 0.75, 1, 1.25, 1.5]) field_to_plot = 'std_dev' fig_3_weather_map.total_annual_demand( regional_share_national_peak, path_shapefile_input, data['regions'], pop_data=pop_data, simulation_yr_to_plot=simulation_yr_to_plot, result_path=result_path, fig_name="{}__regional_share_national_peak_{}_{}_{}.pdf". format(scenario_name, field_to_plot, fueltype_str, simulation_yr_to_plot), field_to_plot=field_to_plot, unit='percentage', seperate_legend=False) print("===================================") print("... finished reading and plotting results") print("===================================")
national_hourly_demand) selected_hours = date_prop.convert_yearday_to_8760h_selection( peak_day_electricity) print("PEAK electricity: " + str(np.max(national_hourly_demand[selected_hours]))) for fueltype_str in fueltypes: print(" ...fueltype {}".format(fueltype_str), flush=True) fueltype_int = tech_related.get_fueltype_int(fueltype_str) # -------- # Calculate # -------- path_ini_file = os.path.join(path_results, scenario, all_realizations[0]) _, _, regions = data_loader.load_ini_param(path_ini_file) hours = range(8760) df_result_final_mean = pd.DataFrame(index=hours, columns=regions) df_result_pos_two_sigma = pd.DataFrame(index=hours, columns=regions) df_result_neg_two_sigma = pd.DataFrame(index=hours, columns=regions) df_result_region_empty = pd.DataFrame(columns=hours) for region_nr, reg_name in enumerate(regions): #print(" ...calculating region {}".format(reg_name), flush=True) #df_result_region = pd.DataFrame(columns=hours) df_result_region = copy.copy(df_result_region_empty)
def main(path_data_ed, path_shapefile_input, plot_crit_dict, base_yr, comparison_year): """Read in all results and plot PDFs Arguments ---------- path_data_ed : str Path to results path_shapefile_input : str Path to shapefile plot_crit_dict : dict Criteria to select plots to plot base_yr : int Base year comparison_year : int Year to generate comparison plots """ print("...Start creating plots") data = {} # --------------------------------------------------------- # Iterate folders and read out all weather years and stations # --------------------------------------------------------- to_ignores = ['model_run_pop', 'PDF_validation'] endings_to_ignore = ['.pdf', '.txt', '.ini'] all_result_folders = os.listdir(path_data_ed) paths_folders_result = [] for result_folder in all_result_folders: if result_folder not in to_ignores and result_folder[ -4:] not in endings_to_ignore: paths_folders_result.append( os.path.join(path_data_ed, result_folder)) #################################################################### # Calculate results for every weather year #################################################################### for path_result_folder in paths_folders_result: print("-----------------------") print("path_result_folder: " + str(path_result_folder)) print("-----------------------") # Simulation information is read in from .ini file for results data['enduses'], data['assumptions'], data[ 'regions'] = data_loader.load_ini_param(os.path.join(path_data_ed)) # ------------------ # Load necessary inputs for read in # ------------------ data = {} data['local_paths'] = data_loader.get_local_paths(path_result_folder) data['result_paths'] = basic_functions.get_result_paths( os.path.join(path_result_folder)) data['lookups'] = lookup_tables.basic_lookups() # --------------- # Folder cleaning # --------------- basic_functions.del_previous_setup( data['result_paths']['data_results_PDF']) basic_functions.del_previous_setup( data['result_paths']['data_results_shapefiles']) basic_functions.create_folder(data['result_paths']['data_results_PDF']) basic_functions.create_folder( data['result_paths']['data_results_shapefiles']) basic_functions.create_folder( data['result_paths']['individual_enduse_lp']) # Simulation information is read in from .ini file for results data['enduses'], data['assumptions'], data[ 'regions'] = data_loader.load_ini_param(os.path.join(path_data_ed)) # Other information is read in data['assumptions']['seasons'] = date_prop.get_season( year_to_model=2015) data['assumptions']['model_yeardays_daytype'], data['assumptions'][ 'yeardays_month'], data['assumptions'][ 'yeardays_month_days'] = date_prop.get_yeardays_daytype( year_to_model=2015) data['scenario_data'] = {} data['scenario_data'][ 'population'] = read_data.read_scenaric_population_data( os.path.join(path_data_ed, 'model_run_pop')) # -------------------------------------------- # Reading in results from different model runs # -------------------------------------------- results_container = read_data.read_in_results( data['result_paths']['data_results_model_run_results_txt'], data['assumptions']['seasons'], data['assumptions']['model_yeardays_daytype']) # ------------------------------ # Plotting other results # ------------------------------ plotting_results.run_all_plot_functions( results_container, data['assumptions']['reg_nrs'], data['regions'], data['lookups'], data['result_paths'], data['assumptions'], data['enduses'], plot_crit=plot_crit_dict, base_yr=base_yr, comparison_year=comparison_year) # ------------------------------ # Plotting spatial results # ------------------------------ if plot_crit_dict['spatial_results']: result_mapping.spatial_maps( data, results_container, data['result_paths']['data_results_shapefiles'], data['regions'], data['lookups']['fueltypes_nr'], data['lookups']['fueltypes'], path_shapefile_input, plot_crit_dict, base_yr=base_yr) print("===================================") print("... finished reading and plotting results") print("===================================")
def main( scenarios_path, path_shapefile_input, base_yr, simulation_yrs_to_plot ): """Read in all results and plot PDFs Arguments ---------- scenarios_path : str Path to results path_shapefile_input : str Path to shapefile plot_crit_dict : dict Criteria to select plots to plot base_yr : int Base year comparison_year : int Year to generate comparison plots """ print("Start creating plots") # ------------------- # Create temperatuere figur plot # ------------------- plot_weather_chart = False if plot_weather_chart: from energy_demand.plotting import fig3_weather_at_home_plot path_weather_data = "//linux-filestore.ouce.ox.ac.uk/mistral/nismod/data/energy_demand/J-MARIUS_data/_weather_realisation" fig3_weather_at_home_plot.plotting_weather_data(path_weather_data) # ------------------- # Create result folder # ------------------- result_path = os.path.join(scenarios_path, '_results_weather_plots') basic_functions.del_previous_setup(result_path) basic_functions.create_folder(result_path) x_chart_yrs_storage = {} for simulation_yr_to_plot in simulation_yrs_to_plot: print("=================") print("...simulation_yr_to_plot: " + str(simulation_yr_to_plot)) print("=================") data = {} x_chart_yrs_storage[simulation_yr_to_plot] = {} # --------------------------------------------------------- # Iterate folders and read out all weather years and stations # --------------------------------------------------------- to_ignores = [ 'model_run_pop', 'PDF_validation', '_results_weather_plots'] endings_to_ignore = [ '.pdf', '.txt', '.ini'] all_scenarios_incl_ignored = os.listdir(scenarios_path) all_scenarios = [] for scenario in all_scenarios_incl_ignored: if scenario not in to_ignores: all_scenarios.append(scenario) scenario_result_container = [] for scenario_nr, scenario_name in enumerate(all_scenarios): print(" ") print("Scenario: {}".format(scenario_name)) print(" ") scenario_path = os.path.join(scenarios_path, scenario_name) all_result_folders = os.listdir(scenario_path) paths_folders_result = [] for result_folder in all_result_folders: if result_folder not in to_ignores and result_folder[-4:] not in endings_to_ignore: paths_folders_result.append( os.path.join(scenario_path, result_folder)) fueltype_str_to_create_maps = ['electricity'] fueltype_str ='electricity' fueltype_elec_int = tech_related.get_fueltype_int('electricity') #################################################################### # Collect regional simulation data for every realisation #################################################################### total_regional_demand_electricity = pd.DataFrame() peak_hour_demand = pd.DataFrame() peak_hour_demand_per_person = pd.DataFrame() national_peak = pd.DataFrame() regional_share_national_peak = pd.DataFrame() regional_share_national_peak_pp = pd.DataFrame() national_electricity = pd.DataFrame() national_gas = pd.DataFrame() national_hydrogen = pd.DataFrame() national_heating_peak = pd.DataFrame() daily_mean_peak_day = pd.DataFrame() for path_result_folder in paths_folders_result: print("... path_result_folder: {}".format(path_result_folder)) data = {} ed_national_heating_peak = {} try: # ================================ # Loading in only heating peak demands (seperate calculations) # ================================ # Simulation information is read in from .ini file for results data['enduses'], data['assumptions'], data['regions'] = data_loader.load_ini_param(os.path.join(path_result_folder)) pop_data = read_data.read_scenaric_population_data(os.path.join(path_result_folder, 'model_run_pop')) path_result_folder_heating = os.path.join(path_result_folder, 'simulation_results') path_result_folder_model_runs = os.path.join(path_result_folder_heating, 'model_run_results_txt') data['lookups'] = lookup_tables.basic_lookups() # Read in heating deamnds path_heating_demands = os.path.join(path_result_folder_model_runs, 'enduse_specific_results') all_files = os.listdir(path_heating_demands) for file_name in all_files: ending = file_name[-4:] if ending == ".npy": year = int(file_name.split("__")[2][:-4]) file_path = os.path.join(path_heating_demands, file_name) heating_demand = np.load(file_path) maximum_hour_of_peak_day = heating_demand[fueltype_elec_int].argmax() #get maxim hour of peak day ed_national_heating_peak[year] = heating_demand[fueltype_elec_int][maximum_hour_of_peak_day] simulation_yrs_result = [ed_national_heating_peak[year] for year in simulation_yrs_to_plot] realisation_data = pd.DataFrame( [simulation_yrs_result], columns=data['assumptions']['sim_yrs']) national_heating_peak = national_heating_peak.append(realisation_data) except: raise Exception("... no heating peak data available " + str(path_result_folder)) try: # Simulation information is read in from .ini file for results data['enduses'], data['assumptions'], data['regions'] = data_loader.load_ini_param(os.path.join(path_result_folder)) pop_data = read_data.read_scenaric_population_data(os.path.join(path_result_folder, 'model_run_pop')) path_result_folder = os.path.join(path_result_folder, 'simulation_results') path_result_folder_model_runs = os.path.join(path_result_folder, 'model_run_results_txt') data['lookups'] = lookup_tables.basic_lookups() # Other information is read in data['assumptions']['seasons'] = date_prop.get_season(year_to_model=2015) data['assumptions']['model_yeardays_daytype'], data['assumptions']['yeardays_month'], data['assumptions']['yeardays_month_days'] = date_prop.get_yeardays_daytype(year_to_model=2015) # -------------------------------------------- # Reading in results from different model runs # -------------------------------------------- results_container = read_weather_results.read_in_weather_results( path_result_folder_model_runs, data['assumptions']['seasons'], data['assumptions']['model_yeardays_daytype'], pop_data, fueltype_str='electricity') # --Total demand (dataframe with row: realisation, column=region) realisation_data = pd.DataFrame( [results_container['ed_reg_tot_y'][simulation_yr_to_plot][fueltype_elec_int]], columns=data['regions']) total_regional_demand_electricity = total_regional_demand_electricity.append(realisation_data) # National per fueltype electricity simulation_yrs_result = [results_container['national_all_fueltypes'][year][fueltype_elec_int] for year in simulation_yrs_to_plot] realisation_data = pd.DataFrame( [simulation_yrs_result], columns=data['assumptions']['sim_yrs']) national_electricity = national_electricity.append(realisation_data) # National per fueltype gas fueltype_gas_int = tech_related.get_fueltype_int('gas') simulation_yrs_result = [results_container['national_all_fueltypes'][year][fueltype_gas_int] for year in simulation_yrs_to_plot] realisation_data = pd.DataFrame( [simulation_yrs_result], columns=data['assumptions']['sim_yrs']) national_gas = national_gas.append(realisation_data) # National per fueltype hydrogen fueltype_hydrogen_int = tech_related.get_fueltype_int('hydrogen') simulation_yrs_result = [results_container['national_all_fueltypes'][year][fueltype_hydrogen_int] for year in simulation_yrs_to_plot] realisation_data = pd.DataFrame( [simulation_yrs_result], columns=data['assumptions']['sim_yrs']) national_hydrogen = national_hydrogen.append(realisation_data) # --Peak hour demand per region (dataframe with row: realisation, column=region) realisation_data = pd.DataFrame( [results_container['ed_reg_peakday_peak_hour'][simulation_yr_to_plot][fueltype_elec_int]], columns=data['regions']) peak_hour_demand = peak_hour_demand.append(realisation_data) # --Peak hour demand / pop per region (dataframe with row: realisation, column=region) realisation_data = pd.DataFrame( [results_container['ed_reg_peakday_peak_hour_per_pop'][simulation_yr_to_plot][fueltype_elec_int]], columns=data['regions']) peak_hour_demand_per_person = peak_hour_demand_per_person.append(realisation_data) # --National peak simulation_yrs_result = [results_container['national_peak'][year][fueltype_elec_int] for year in simulation_yrs_to_plot] realisation_data = pd.DataFrame( [simulation_yrs_result], columns=data['assumptions']['sim_yrs']) national_peak = national_peak.append(realisation_data) # --Regional percentage of national peak demand realisation_data = pd.DataFrame( [results_container['regional_share_national_peak'][simulation_yr_to_plot]], columns=data['regions']) regional_share_national_peak = regional_share_national_peak.append(realisation_data) # --Regional percentage of national peak demand per person realisation_data = pd.DataFrame( [results_container['regional_share_national_peak_pp'][simulation_yr_to_plot]], columns=data['regions']) regional_share_national_peak_pp = regional_share_national_peak_pp.append(realisation_data) # Mean demand of peak day simulation_yrs_result = [results_container['mean_peak_day_demand'][year][fueltype_elec_int] for year in simulation_yrs_to_plot] realisation_data = pd.DataFrame( [simulation_yrs_result], columns=data['assumptions']['sim_yrs']) daily_mean_peak_day = daily_mean_peak_day.append(realisation_data) except: raise Exception("The run '{}' is corrupted".format(path_result_folder)) # Add to scenario container result_entry = { 'national_heating_peak': national_heating_peak, 'scenario_name': scenario_name, 'peak_hour_demand': peak_hour_demand, 'peak_hour_demand_per_person': peak_hour_demand_per_person, 'national_peak': national_peak, 'regional_share_national_peak': regional_share_national_peak, 'regional_share_national_peak_pp': regional_share_national_peak_pp, 'total_regional_demand_electricity': total_regional_demand_electricity, 'national_electricity': national_electricity, 'national_gas': national_gas, 'national_hydrogen': national_hydrogen, 'daily_mean_peak_day': daily_mean_peak_day} scenario_result_container.append(result_entry) # --------------------------------------------------------------- # TEST PLOT X-axis: Contribution to peak y-axis: Std: deviation # --------------------------------------------------------------- x_chart_yrs_storage[simulation_yr_to_plot][scenario_name] = result_entry # ------------------------------ # Plot national sum over time per fueltype and scenario # ------------------------------ crit_smooth_line = False seperate_legend = True try: print("... plotting national sum of fueltype over time ") 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(simulation_yr_to_plot, fueltype_str), fueltypes=['electricity', 'gas', 'hydrogen'], result_path=result_path, unit='TWh', plot_points=True, crit_smooth_line=crit_smooth_line, seperate_legend=seperate_legend) except: raise Exception("FAILS national sum") # ------------------------------ # Plot national peak change over time for each scenario including weather variability # ------------------------------ try: fig_3_plot_over_time.scenario_over_time( scenario_result_container=scenario_result_container, field_name='national_peak', sim_yrs=data['assumptions']['sim_yrs'], fig_name="scenarios_peak_over_time__{}__{}.pdf".format(simulation_yr_to_plot, fueltype_str), plot_points=True, result_path=result_path, crit_smooth_line=crit_smooth_line, seperate_legend=seperate_legend) except: raise Exception("FAILED") pass # ------------------------------ # Plot heating peak change over time for each scenario including weather variability # ------------------------------ try: fig_3_plot_over_time.scenario_over_time( scenario_result_container=scenario_result_container, field_name='national_heating_peak', sim_yrs=data['assumptions']['sim_yrs'], fig_name="scenarios_heating_peak_over_time__{}__{}.pdf".format(simulation_yr_to_plot, fueltype_str), plot_points=True, result_path=result_path, crit_smooth_line=crit_smooth_line, seperate_legend=seperate_legend) except: raise Exception("FAILED") pass # ------------------------------ # plot PEAK DAY mean # ------------------------------ try: fig_3_plot_over_time.scenario_over_time( scenario_result_container=scenario_result_container, field_name='daily_mean_peak_day', sim_yrs=data['assumptions']['sim_yrs'], fig_name="mean_demand_of_peak_day{}__{}.pdf".format(simulation_yr_to_plot, fueltype_str), plot_points=True, result_path=result_path, crit_smooth_line=crit_smooth_line, seperate_legend=seperate_legend) except: raise Exception("FAILED") pass ## ------------------------------ ## Plotting x-chart ## ------------------------------ fig_3_plot_over_time.plot_std_dev_vs_contribution( scenario_result_container=x_chart_yrs_storage, sim_yrs=data['assumptions']['sim_yrs'], fig_name="_scenarios_4_chart_absolute.pdf", fueltypes=['electricity'], result_path=result_path, path_shapefile_input=path_shapefile_input, unit='TWh', plot_points=True) print("===================================") print("... finished reading and plotting results") print("===================================")