def test_assign_by_fuel_tech_p(): """ """ path_main = resource_filename(Requirement.parse("energy_demand"), 'config_data') # Load data data = {} data['paths'] = data_loader.load_paths(path_main) data['lookups'] = lookup_tables.basic_lookups() data['enduses'], data['sectors'], data['fuels'] = data_loader.load_fuels( data['paths'], data['lookups']) data['local_paths'] = data_loader.load_local_paths(path_main) #Load assumptions base_yr = 2015 data['assumptions'] = non_param_assumptions.Assumptions( base_yr=base_yr, curr_yr=None, simulated_yrs=None, paths=data['paths'], enduses=data['enduses'], sectors=data['sectors'], fueltypes=data['lookups']['fueltypes'], fueltypes_nr=data['lookups']['fueltypes_nr']) param_assumptions.load_param_assump(data['paths'], data['local_paths'], data['assumptions']) rs_fuel_tech_p_by, ss_fuel_tech_p_by, is_fuel_tech_p_by = assumptions_fuel_shares.assign_by_fuel_tech_p( data['enduses'], data['sectors'], data['lookups']['fueltypes'], data['lookups']['fueltypes_nr'])
def test_assign_by_fuel_tech_p(config_file): """ """ config = data_loader.read_config_file(config_file) # Load data data = {} data['paths'] = config['CONFIG_DATA'] data['lookups'] = lookup_tables.basic_lookups() data['enduses'], data['sectors'], data[ 'fuels'], _, _ = data_loader.load_fuels(data['paths']) data['local_paths'] = data_loader.get_local_paths(path_main) #Load assumptions base_yr = 2015 data['assumptions'] = general_assumptions.Assumptions( submodels_names=['a'], base_yr=base_yr, curr_yr=None, sim_yrs=None, paths=data['paths'], enduses=data['enduses'], sectors=data['sectors'], fueltypes=data['lookups']['fueltypes'], fueltypes_nr=data['lookups']['fueltypes_nr']) strategy_vars_def.load_param_assump(data['paths'], data['local_paths'], data['assumptions']) fuel_tech_p_by = fuel_shares.assign_by_fuel_tech_p( data['enduses'], data['sectors'], data['lookups']['fueltypes'], data['lookups']['fueltypes_nr'])
def write_only_peak(sim_yr, name_new_folder, path_result, model_results, file_name_peak_day): """Write only peak demand and total regional demand for a region """ path_result_sub_folder = os.path.join(path_result, name_new_folder) basic_functions.create_folder(path_result_sub_folder) path_file_peak_day = os.path.join( path_result_sub_folder, "{}__{}__{}".format(file_name_peak_day, sim_yr, ".npy")) # ------------------------------------ # Write out peak electricity day demands # ------------------------------------ # Get peak day electricity lookups = lookup_tables.basic_lookups() fueltype_int = lookups['fueltypes']['electricity'] national_hourly_demand = np.sum(model_results[fueltype_int], axis=0) peak_day_electricity, _ = enduse_func.get_peak_day_single_fueltype( national_hourly_demand) selected_hours = date_prop.convert_yearday_to_8760h_selection( peak_day_electricity) selected_demand = model_results[:, :, selected_hours] np.save(path_file_peak_day, selected_demand)
def post_install_setup_minimum(args): """If not all data are available, this scripts allows to create dummy datas (temperature and service sector load profiles) """ path_config_file = args.config_file config = data_loader.read_config_file(path_config_file) path_local_data = config['PATHS']['path_local_data'] # ========================================== # Post installation setup witout access to non publicy available data # ========================================== print( "... running initialisation scripts with only publicly available data") local_paths = data_loader.get_local_paths(path_config_file) # Create folders to input data raw_folder = os.path.join(path_local_data, '_raw_data') basic_functions.create_folder(raw_folder) basic_functions.create_folder(config['PATHS']['path_processed_data']) basic_functions.create_folder(local_paths['path_post_installation_data']) basic_functions.create_folder(local_paths['load_profiles']) basic_functions.create_folder(local_paths['rs_load_profile_txt']) basic_functions.create_folder(local_paths['ss_load_profile_txt']) # Load data data = {} data['paths'] = data_loader.load_paths(path_config_file) data['lookups'] = lookup_tables.basic_lookups() data['enduses'], data['sectors'], data[ 'fuels'], lookup_enduses, lookup_sector_enduses = data_loader.load_fuels( data['paths']) # Assumptions data['assumptions'] = general_assumptions.Assumptions( lookup_enduses=lookup_enduses, lookup_sector_enduses=lookup_sector_enduses, base_yr=2015, weather_by=config['CONFIG']['user_defined_weather_by'], simulation_end_yr=config['CONFIG']['user_defined_simulation_end_yr'], paths=data['paths'], enduses=data['enduses'], sectors=data['sectors']) # Read in residential submodel shapes run(data['paths'], local_paths, config['CONFIG']['base_yr']) # -------- # Dummy service sector load profiles # -------- dummy_sectoral_load_profiles(local_paths, path_config_file) print( "Successfully finished post installation setup with open source data")
def dummy_sectoral_load_profiles(local_paths, path_main): """ """ create_folders_to_file(os.path.join(local_paths['ss_load_profile_txt'], "dumm"), "_processed_data") paths = data_loader.load_paths(path_main) lu = lookup_tables.basic_lookups() dict_enduses, dict_sectors, dict_fuels = data_loader.load_fuels(paths, lu) for enduse in dict_enduses['ss_enduses']: for sector in dict_sectors['ss_sectors']: joint_string_name = str(sector) + "__" + str(enduse) # Flat profiles load_peak_shape_dh = np.full((24), 1) shape_non_peak_y_dh = np.full((365, 24), 1/24) shape_peak_yd_factor = 1.0 shape_non_peak_yd = np.full((365), 1/365) write_data.create_txt_shapes( joint_string_name, local_paths['ss_load_profile_txt'], load_peak_shape_dh, shape_non_peak_y_dh, shape_peak_yd_factor, shape_non_peak_yd)
def create_virtual_dwelling_stocks(regions, curr_yr, data, criterias): """Create virtual dwelling stocks for residential and service sector. If no floor area is avilable, calculate average floor area with population information Arguments --------- """ rs_dw_stock = defaultdict(dict) ss_dw_stock = defaultdict(dict) for region in regions: # ------------- # Residential dwelling stocks # ------------- dwtype = lookup_tables.basic_lookups()['dwtype'] # Base year rs_dw_stock[region][ data['assumptions'].base_yr] = dw_stock.rs_dw_stock( region, data['assumptions'], data['scenario_data'], data['assumptions'].sim_yrs, dwtype, data['enduses']['residential'], data['reg_coord'], data['assumptions'].scenario_drivers, data['assumptions'].base_yr, data['assumptions'].base_yr, criterias['virtual_building_stock_criteria']) # Current year rs_dw_stock[region][curr_yr] = dw_stock.rs_dw_stock( region, data['assumptions'], data['scenario_data'], data['assumptions'].sim_yrs, dwtype, data['enduses']['residential'], data['reg_coord'], data['assumptions'].scenario_drivers, curr_yr, data['assumptions'].base_yr, criterias['virtual_building_stock_criteria']) # ------------- # Service dwelling stocks # ------------- # base year ss_dw_stock[region][ data['assumptions'].base_yr] = dw_stock.ss_dw_stock( region, data['enduses']['service'], data['sectors']['service'], data['scenario_data'], data['reg_coord'], data['assumptions'], data['assumptions'].base_yr, data['assumptions'].base_yr, criterias['virtual_building_stock_criteria']) # current year ss_dw_stock[region][curr_yr] = dw_stock.ss_dw_stock( region, data['enduses']['service'], data['sectors']['service'], data['scenario_data'], data['reg_coord'], data['assumptions'], curr_yr, data['assumptions'].base_yr, criterias['virtual_building_stock_criteria']) return dict(rs_dw_stock), dict(ss_dw_stock)
def __init__(self, regions, data, criterias, assumptions, weather_yr, weather_by): """Constructor """ self.curr_yr = assumptions.curr_yr # ------------------------ # Create Dwelling Stock # ------------------------ logging.debug("... generating dwelling stocks") lookups = lookup_tables.basic_lookups() rs_dw_stock, ss_dw_stock = create_virtual_dwelling_stocks( regions, assumptions.curr_yr, data, criterias) data['dw_stocks'] = { lookups['submodels_names'][0]: rs_dw_stock, lookups['submodels_names'][1]: ss_dw_stock, lookups['submodels_names'][2]: None } # Initialise result container to aggregate results aggr_results = initialise_result_container(assumptions.fueltypes_nr, assumptions.reg_nrs, assumptions.lookup_enduses, assumptions.nr_of_submodels) # ------------------------------------------- # Simulate regions # ------------------------------------------- for reg_array_nr, region in enumerate(tqdm(regions)): #print("... Simulate: region %s, simulation year: %s, percent: (%s)", # region, assumptions.curr_yr, round((100/assumptions.reg_nrs)*reg_array_nr, 2), flush=True) #logging.info("... Simulate: region %s, simulation year: %s, percent: (%s)", # region, assumptions.curr_yr, round((100/assumptions.reg_nrs)*reg_array_nr, 2)) all_submodels = simulate_region(region, data, criterias, assumptions, weather_yr, weather_by) # --------------------------------------------- # Aggregate results specifically over regions # --------------------------------------------- aggr_results = aggregate_single_region( assumptions.reg_nrs, assumptions.lookup_enduses, aggr_results, reg_array_nr, all_submodels, criterias['mode_constrained'], assumptions.fueltypes_nr, assumptions.enduse_space_heating, assumptions.technologies) # --------------------------------------------------- # Aggregate results for all regions # --------------------------------------------------- aggr_results = aggregate_across_all_regs( aggr_results, assumptions.fueltypes_nr, data['assumptions'].reg_nrs, data['enduses'], data['assumptions'], criterias, assumptions.technologies) # Set all keys of aggr_results as self.attributes for key_attribute_name, value in aggr_results.items(): setattr(self, key_attribute_name, value)
def unconstrained_results( results_unconstrained, submodels_names ): """Prepare results for energy supply model for unconstrained model running mode (heat is provided). The results for the supply model are provided aggregated for every submodel, fueltype, region, timestep Note ----- Because SMIF only takes results in the form of {key: np.aray(regions, timesteps)}, the key needs to contain information about submodel and fueltype Also these key must be defined in the `submodel_model` configuration file Arguments ---------- results_unconstrained : array Results of unconstrained mode np.array((sector, regions, fueltype, timestep)) submodels_names : list Names of sectors for supply model Returns ------- supply_results : dict No technology specific delivery (heat is provided in form of a fueltype) {submodel_fueltype: np.array((region, intervals))} """ supply_results = {} fueltypes = lookup_tables.basic_lookups()['fueltypes'] for submodel_nr, submodel in enumerate(submodels_names): for fueltype_str, fueltype_int in fueltypes.items(): # Generate key name (must be defined in `sector_models`) key_name = "{}_{}".format(submodel, fueltype_str) # Add fueltype specific demand for all regions supply_results[key_name] = results_unconstrained[submodel_nr][:, fueltype_int, :] assert not testing_functions.test_if_minus_value_in_array(supply_results[key_name]) logging.info("... Prepared results for energy supply model in unconstrained mode") return supply_results
def test_load_param_assump(): """ """ path_main = resource_filename(Requirement.parse("energy_demand"), "config_data") # Load data data = {} data['paths'] = data_loader.load_paths(path_main) data['lookups'] = lookup_tables.basic_lookups() data['enduses'], data['sectors'], data['fuels'] = data_loader.load_fuels(data['paths'], data['lookups']) sim_param_expected = {} sim_param_expected['base_yr'] = 2015 # Dummy test assert sim_param_expected['base_yr'] == 2015 return
def get_fueltype_int(fueltype_str): """Read from dict the fueltype string based on fueltype KeyError Arguments --------- fueltype_str : int Key which is to be found in lookup dict Returns ------- fueltype_in_string : str Fueltype string """ fueltype_lu = lookup_tables.basic_lookups()['fueltypes'] if not fueltype_str: return None else: return fueltype_lu[fueltype_str]
def get_fueltype_str(fueltype_lu, fueltype_nr): """Read from dict the fueltype string based on fueltype KeyError Arguments --------- fueltype : dict Fueltype lookup dictionary fueltype_nr : int Key which is to be found in lookup dict Returns ------- fueltype_in_string : str Fueltype string """ fueltype_lu = lookup_tables.basic_lookups()['fueltypes'] for fueltype_str in fueltype_lu: if fueltype_lu[fueltype_str] == fueltype_nr: return fueltype_str
def test_load_non_param_assump(): """ """ path_main = resource_filename(Requirement.parse("energy_demand"), "config_data") # Load data data = {} paths = data_loader.load_paths(path_main) lu = lookup_tables.basic_lookups() enduses, sectors, _ = data_loader.load_fuels(paths, lu) non_param_assumptions.Assumptions( base_yr=2015, curr_yr=None, simulated_yrs=None, paths=paths, enduses=enduses, sectors=sectors, fueltypes=lu['fueltypes'], fueltypes_nr=lu['fueltypes_nr'])
def sum_across_all_submodels_regs(regions, submodels): """Calculate total sum of fuel per region """ fueltypes_nr = lookup_tables.basic_lookups()['fueltypes_nr'] fuel_aggregated_regs = {} for region in regions: tot_reg = np.zeros((fueltypes_nr), dtype="float") for submodel_fuel_disagg in submodels: for fuel_sector_enduse in submodel_fuel_disagg[region].values(): # Test if fuel for sector if isinstance(fuel_sector_enduse, dict): for sector_fuel in fuel_sector_enduse.values(): tot_reg += sector_fuel else: tot_reg += fuel_sector_enduse fuel_aggregated_regs[region] = tot_reg return fuel_aggregated_regs
def constrained_results( results_constrained, results_unconstrained_no_heating, submodels_names, technologies, ): """Prepare results for energy supply model for constrained model running mode (no heat is provided but technology specific fuel use). The results for the supply model are provided aggregated as follows: { "submodel_fueltype_tech": np.array(regions, timesteps)} Because SMIF only takes results in the form of {key: np.array(regions, timesteps)}, the key needs to contain information about submodel, fueltype, and technology. Also these key must be defined in the `submodel_model` configuration file. Arguments ---------- results_constrained : dict Aggregated results in form {technology: np.array((sector, region, fueltype, timestep))} results_unconstrained_no_heating : dict Aggregated results without heating {technology: np.array((sector, region, fueltype, timestep))} submodels_names : list Names of sectors fur supply model technologies : dict Technologies Returns ------- supply_results : dict No technology specific delivery (heat is provided in form of a fueltype) {submodel_fueltype: np.array((region, intervals))} Note ----- For the fuel demand for CHP plants, the co-generated electricity is not included in the demand model. Additional electricity supply generated from CHP plants need to be calculated in the supply model based on the fuel demand for CHP. For CHP efficiency therefore not the overall efficiency is used but only the thermal efficiency """ supply_results = {} fueltypes = lookup_tables.basic_lookups()['fueltypes'] # ---------------------------------------- # Add all constrained results (technology specific results) # Aggregate according to submodel, fueltype, technology, region, timestep # ---------------------------------------- for submodel_nr, submodel in enumerate(submodels_names): for tech, fuel_tech in results_constrained.items(): # Technological simplifications because of different technology definition and because not all technologies are used in supply model tech_simplified = model_tech_simplification(tech) fueltype_str = technologies[tech_simplified].fueltype_str fueltype_int = technologies[tech_simplified].fueltype_int key_name = "{}_{}_{}".format(submodel, fueltype_str, tech_simplified) supply_results[key_name] = fuel_tech[submodel_nr][:, fueltype_int, :] assert not testing_functions.test_if_minus_value_in_array(results_unconstrained_no_heating) # --------------------------------- # Add non_heating for all fueltypes # --------------------------------- for submodel_nr, submodel in enumerate(submodels_names): for fueltype_str, fueltype_int in fueltypes.items(): if fueltype_str == 'heat': pass #Do not add non_heating demand for fueltype heat else: key_name = "{}_{}_{}".format(submodel, fueltype_str, "non_heating") # Add fuel for all regions for specific fueltype supply_results[key_name] = results_unconstrained_no_heating[submodel_nr][:, fueltype_int, :] # -------------------------------------------- # Check whether any entry is smaller than zero # -------------------------------------------- for key_name, values in supply_results.items(): if testing_functions.test_if_minus_value_in_array(values): raise Exception("Error d: Negative entry in results {} {}".format(key_name, np.sum(values))) return supply_results
def read_user_defined_param(df, simulation_base_yr, simulation_end_yr, default_streategy_var, var_name): """Read in user defined narrative parameters """ parameter_narratives = {} single_param_narratives = {} lookups = lookup_tables.basic_lookups() # End uses columns = list(df.columns) if 'enduses' in columns: sub_param_crit = True else: sub_param_crit = False if len(list(df.columns)) == 1: single_dim_param = True else: single_dim_param = False if single_dim_param: # Read single dimension param and create single step narrative single_step_narrative = {} single_step_narrative['sector'] = 'dummy_sector' single_step_narrative['default_value'] = default_streategy_var[ 'default_value'] single_step_narrative['value_ey'] = float(df[var_name][0]) single_step_narrative['end_yr'] = simulation_end_yr single_step_narrative['base_yr'] = simulation_base_yr single_step_narrative['value_by'] = default_streategy_var[ 'default_value'] single_step_narrative['regional_specific'] = default_streategy_var[ 'regional_specific'] single_step_narrative['diffusion_choice'] = 'linear' single_param_narratives = [single_step_narrative] return single_param_narratives else: # Read multidmensional param if sub_param_crit: enduses = set(df['enduses'].values) for enduse in enduses: parameter_narratives[enduse] = {} # All rows of enduse df_enduse = df.loc[df['enduses'] == enduse] # Get all sectors and years sectors = set() end_yrs = set() for i in df_enduse.index: try: sector = df_enduse.at[i, 'sector'] sectors.add(sector) except: pass try: end_yr = int(df_enduse.at[i, 'end_yr']) end_yrs.add(end_yr) except: pass if list(sectors) == []: for end_yr in end_yrs: try: _ = default_streategy_var[enduse] defined_in_model = True except KeyError: #print("... not defined in model") defined_in_model = False # All entries of this year df_enduse and this fueltype df_enduse_sim_yr = df_enduse.loc[df_enduse['end_yr'] == end_yr] if defined_in_model: narrative = {} narrative['sector'] = 'dummy_sector' narrative['end_yr'] = end_yr narrative['sig_midpoint'] = 0 narrative['sig_steepness'] = 1 narrative[ 'regional_specific'] = default_streategy_var[ enduse]['regional_specific'] narrative['default_by'] = default_streategy_var[ enduse]['default_value'] # Check if more than one entry for _index, row in df_enduse_sim_yr.iterrows(): try: interpolation_params = row[ 'interpolation_params'] except KeyError: # Generic fuel switch interpolation_params = row[ 'param_generic_fuel_switch'] # If more than one switch per enduse if interpolation_params in narrative: # Add narrative and start new one try: parameter_narratives[enduse][narrative[ 'sector']].append(narrative) except KeyError: parameter_narratives[enduse][ narrative['sector']] = [narrative] narrative = {} narrative['sector'] = 'dummy_sector' narrative['end_yr'] = end_yr narrative['sig_midpoint'] = 0 narrative['sig_steepness'] = 1 narrative[ 'regional_specific'] = default_streategy_var[ enduse]['regional_specific'] narrative[ 'default_by'] = default_streategy_var[ enduse]['default_value'] if interpolation_params == 'diffusion_choice': int_diffusion_choice = float( row[var_name]) narrative[ 'diffusion_choice'] = lookups[ 'diffusion_type'][ int_diffusion_choice] else: narrative[ interpolation_params] = float( row[var_name]) else: if interpolation_params == 'diffusion_choice': int_diffusion_choice = float( row[var_name]) narrative[ 'diffusion_choice'] = lookups[ 'diffusion_type'][ int_diffusion_choice] else: narrative[ interpolation_params] = float( row[var_name]) # Add narrative try: parameter_narratives[enduse][ narrative['sector']].append(narrative) except KeyError: parameter_narratives[enduse][ narrative['sector']] = [narrative] else: # If setctor specific, this needs to be implemented pass else: sectors = set() end_yrs = set() for i in df.index: try: sector = df.at[i, 'sector'] sectors.add(sector) except: pass try: end_yr = int(df.at[i, 'end_yr']) end_yrs.add(end_yr) except: pass if list(sectors) == []: parameter_narratives['dummy_single_param'] = {} for end_yr in end_yrs: narrative = {} narrative['sector'] = 'dummy_sector' narrative['end_yr'] = end_yr narrative['sig_midpoint'] = 0 narrative['sig_steepness'] = 1 narrative['regional_specific'] = default_streategy_var[ 'regional_specific'] narrative['default_by'] = default_streategy_var[ 'default_value'] for _index, row in df.iterrows(): interpolation_params = row['interpolation_params'] if interpolation_params == 'diffusion_choice': lookups = lookup_tables.basic_lookups() int_diffusion_choice = int(row[var_name]) narrative['diffusion_choice'] = lookups[ 'diffusion_type'][int_diffusion_choice] else: narrative[interpolation_params] = float( row[var_name]) # Add narrative try: parameter_narratives['dummy_single_param'][ narrative['sector']].append(narrative) except (KeyError, AttributeError): parameter_narratives['dummy_single_param'][ narrative['sector']] = [narrative] else: # Needs to be implemented in case sector specific pass # ------------ # Autocomplete # ------------ print("... autocomplete") parameter_narratives = autocomplete(parameter_narratives, simulation_base_yr, sub_param_crit) return parameter_narratives
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 logg_info(modelrun, fuels_in, data): """Logg information """ lookups = lookup_tables.basic_lookups() logging.info("=====================================================") logging.info("Simulation year: %s", str(modelrun.curr_yr)) logging.info("Nr of regions: %s", str(data['assumptions'].reg_nrs)) logging.info("Total ktoe: %s", str(conversions.gwh_to_ktoe(fuels_in["fuel_in"]))) logging.info("-----------------------------------------------------") logging.info("[GWh] Total input: %s", str(fuels_in["fuel_in"])) logging.info("[GWh] Total output: %s", str(np.sum(modelrun.ed_fueltype_national_yh))) logging.info( "[GWh] Total difference: %s", str( round((np.sum(modelrun.ed_fueltype_national_yh) - fuels_in["fuel_in"]), 4))) logging.info("-----------------------------------------------------") logging.info("[GWh] oil input: %s", str(fuels_in["fuel_in_oil"])) logging.info( "[GWh] oil output: %s", str( np.sum(modelrun.ed_fueltype_national_yh[lookups['fueltypes'] ['oil']]))) logging.info( "[GWh] oil diff: %s", str( round( np.sum(modelrun.ed_fueltype_national_yh[ lookups['fueltypes']['oil']]) - fuels_in["fuel_in_oil"], 4))) logging.info("-----------------------------------------------------") logging.info("[GWh] biomass output: %s", str(fuels_in["fuel_in_biomass"])) logging.info( "[GWh] biomass output: %s", str( np.sum(modelrun.ed_fueltype_national_yh[lookups['fueltypes'] ['biomass']]))) logging.info( "[GWh] biomass diff: %s", str( round( np.sum(modelrun.ed_fueltype_national_yh[lookups['fueltypes'] ['biomass']]) - fuels_in["fuel_in_biomass"], 4))) logging.info("-----------------------------------------------------") logging.info("[GWh] solid_fuel output: %s", str(fuels_in["fuel_in_solid_fuel"])) logging.info( "[GWh] solid_fuel output: %s", str( np.sum(modelrun.ed_fueltype_national_yh[lookups['fueltypes'] ['solid_fuel']]))) logging.info( "[GWh] solid_fuel diff: %s", str( round( np.sum(modelrun.ed_fueltype_national_yh[lookups['fueltypes'] ['solid_fuel']]) - fuels_in["fuel_in_solid_fuel"], 4))) logging.info("-----------------------------------------------------") logging.info("[GWh] elec output: %s", str(fuels_in["fuel_in_elec"])) logging.info( "[GWh] elec output: %s", str( np.sum(modelrun.ed_fueltype_national_yh[lookups['fueltypes'] ['electricity']]))) logging.info( "[GWh] ele fuel diff: %s", str( round( np.sum(modelrun.ed_fueltype_national_yh[lookups['fueltypes'] ['electricity']]) - fuels_in["fuel_in_elec"], 4))) logging.info("-----------------------------------------------------") logging.info("[GWh] gas output: %s", str(fuels_in["fuel_in_gas"])) logging.info( "[GWh] gas output: %s", str( np.sum(modelrun.ed_fueltype_national_yh[lookups['fueltypes'] ['gas']]))) logging.info( "[GWh] gas diff: %s", str( round( np.sum(modelrun.ed_fueltype_national_yh[ lookups['fueltypes']['gas']]) - fuels_in["fuel_in_gas"], 4))) logging.info("-----------------------------------------------------") logging.info("[GWh] hydro output: %s", str(fuels_in["fuel_in_hydrogen"])) logging.info( "[GWh] hydro output: %s", str( np.sum(modelrun.ed_fueltype_national_yh[lookups['fueltypes'] ['hydrogen']]))) logging.info( "[GWh] hydro diff: %s", str( round( np.sum(modelrun.ed_fueltype_national_yh[lookups['fueltypes'] ['hydrogen']]) - fuels_in["fuel_in_hydrogen"], 4))) logging.info("-----------------------------------------------------") logging.info("TOTAL HEATING %s", str(fuels_in["tot_heating"])) logging.info("[GWh] heat input: %s", str(fuels_in["fuel_in_heat"])) logging.info( "[GWh] heat output: %s", str( np.sum(modelrun.ed_fueltype_national_yh[lookups['fueltypes'] ['heat']]))) logging.info( "[GWh] heat diff: %s", str( round( np.sum(modelrun.ed_fueltype_national_yh[ lookups['fueltypes']['heat']]) - fuels_in["fuel_in_heat"], 4))) logging.info("-----------------------------------------------------") logging.info( "Diff elec p: %s", str( round((np.sum(modelrun.ed_fueltype_national_yh[lookups['fueltypes'] ['electricity']]) / fuels_in["fuel_in_elec"]), 4))) logging.info( "Diff gas p: %s", str( round((np.sum( modelrun.ed_fueltype_national_yh[lookups['fueltypes']['gas']]) / fuels_in["fuel_in_gas"]), 4))) logging.info( "Diff oil p: %s", str( round((np.sum( modelrun.ed_fueltype_national_yh[lookups['fueltypes']['oil']]) / fuels_in["fuel_in_oil"]), 4))) logging.info( "Diff solid_fuel p: %s", str( round((np.sum(modelrun.ed_fueltype_national_yh[lookups['fueltypes'] ['solid_fuel']]) / fuels_in["fuel_in_solid_fuel"]), 4))) logging.info( "Diff hydrogen p: %s", str( round((np.sum(modelrun.ed_fueltype_national_yh[lookups['fueltypes'] ['hydrogen']]) / fuels_in["fuel_in_hydrogen"]), 4))) logging.info( "Diff biomass p: %s", str( round((np.sum(modelrun.ed_fueltype_national_yh[lookups['fueltypes'] ['biomass']]) / fuels_in["fuel_in_biomass"]), 4))) logging.info("=====================================================")
def __init__( self, name, assumptions, technologies, enduses, temp_by, temp_cy, tech_lp, sectors, crit_temp_min_max ): """Constructor of weather region """ self.name = name fueltypes = lookup_tables.basic_lookups()['fueltypes'] # Base temperatures of current year rs_t_base_heating_cy = assumptions.non_regional_vars['rs_t_base_heating'][assumptions.curr_yr] ss_t_base_heating_cy = assumptions.non_regional_vars['ss_t_base_heating'][assumptions.curr_yr] ss_t_base_cooling_cy = assumptions.non_regional_vars['ss_t_base_cooling'][assumptions.curr_yr] is_t_base_heating_cy = assumptions.non_regional_vars['is_t_base_heating'][assumptions.curr_yr] # ================================================================== # Technology stocks # ================================================================== rs_tech_stock = technological_stock.TechStock( 'rs_tech_stock', technologies, assumptions.base_yr, assumptions.curr_yr, fueltypes, temp_by, temp_cy, assumptions.t_bases.rs_t_heating, enduses['residential'], rs_t_base_heating_cy, assumptions.specified_tech_enduse_by) ss_tech_stock = technological_stock.TechStock( 'ss_tech_stock', technologies, assumptions.base_yr, assumptions.curr_yr, fueltypes, temp_by, temp_cy, assumptions.t_bases.ss_t_heating, enduses['service'], ss_t_base_heating_cy, assumptions.specified_tech_enduse_by) is_tech_stock = technological_stock.TechStock( 'is_tech_stock', technologies, assumptions.base_yr, assumptions.curr_yr, fueltypes, temp_by, temp_cy, assumptions.t_bases.is_t_heating, enduses['industry'], ss_t_base_heating_cy, assumptions.specified_tech_enduse_by) self.tech_stock = { 'residential': rs_tech_stock, 'service': ss_tech_stock, 'industry': is_tech_stock} # ================================================================== # Load profiles # ================================================================== flat_shape_yd, _, flat_shape_y_dh = generic_shapes.flat_shape() # ================================================================== # Residential submodel load profiles # ================================================================== load_profiles = load_profile.LoadProfileStock("load_profiles") dummy_sector = None # --------Calculate HDD/CDD of used weather year self.rs_hdd_by, _ = hdd_cdd.calc_reg_hdd( temp_by, assumptions.t_bases.rs_t_heating, assumptions.model_yeardays, crit_temp_min_max) self.rs_hdd_cy, rs_fuel_shape_heating_yd = hdd_cdd.calc_reg_hdd( temp_cy, rs_t_base_heating_cy, assumptions.model_yeardays, crit_temp_min_max) # --------Calculate HDD/CDD of base year weather year #self.rs_cdd_by, _ = hdd_cdd.calc_reg_cdd( # temp_by, assumptions.t_bases.rs_t_cooling_by, assumptions.model_yeardays) #self.rs_cdd_cy, rs_fuel_shape_cooling_yd = hdd_cdd.calc_reg_cdd( # temp_cy, rs_t_base_cooling_cy, assumptions.model_yeardays) # -------Calculate climate change correction factors try: f_heat_rs_y = np.nan_to_num( 1.0 / float(np.sum(self.rs_hdd_by))) * np.sum(self.rs_hdd_cy) #self.f_cooling_rs_y = np.nan_to_num( # 1.0 / float(np.sum(self.rs_cdd_by))) * np.sum(self.rs_cdd_cy) f_cooling_rs_y = 1 except ZeroDivisionError: f_heat_rs_y = 1 f_cooling_rs_y = 1 # Calculate rs peak day rs_peak_day = enduse_func.get_peak_day(self.rs_hdd_cy) # ======== # Enduse specific profiles # ======== # -- Apply enduse sepcific shapes for enduses with not technologies with own defined shapes for enduse in enduses['residential']: # Enduses where technology specific load profiles are defined for yh if enduse in ['rs_space_heating']: pass else: # Get all technologies of enduse tech_list = helpers.get_nested_dict_key( assumptions.fuel_tech_p_by[enduse][dummy_sector]) # Remove heat pumps from rs_water_heating tech_list = basic_functions.remove_element_from_list(tech_list, 'heat_pumps_electricity') shape_y_dh = insert_peak_dh_shape( peak_day=rs_peak_day, shape_y_dh=tech_lp['rs_shapes_dh'][enduse]['shape_non_peak_y_dh'], shape_peak_dh=tech_lp['rs_shapes_dh'][enduse]['shape_peak_dh']) load_profiles.add_lp( unique_identifier=uuid.uuid4(), technologies=tech_list, enduses=[enduse], shape_yd=tech_lp['rs_shapes_yd'][enduse]['shape_non_peak_yd'], shape_y_dh=shape_y_dh, sectors=[dummy_sector], model_yeardays=assumptions.model_yeardays) # ========== # Technology specific profiles for residential heating # =========== # ------Heating boiler load_profiles.add_lp( unique_identifier=uuid.uuid4(), technologies=assumptions.tech_list['heating_const'], enduses=['rs_space_heating'], shape_yd=rs_fuel_shape_heating_yd, shape_y_dh=tech_lp['rs_profile_boilers_y_dh'], sectors=[dummy_sector], model_yeardays=assumptions.model_yeardays) # ------Heating CHP rs_profile_chp_y_dh = insert_peak_dh_shape( peak_day=rs_peak_day, shape_y_dh=tech_lp['rs_profile_chp_y_dh'], shape_peak_dh=tech_lp['rs_lp_heating_CHP_dh']['peakday']) load_profiles.add_lp( unique_identifier=uuid.uuid4(), technologies=assumptions.tech_list['tech_CHP'], enduses=['rs_space_heating'], shape_yd=rs_fuel_shape_heating_yd, shape_y_dh=rs_profile_chp_y_dh, sectors=[dummy_sector], model_yeardays=assumptions.model_yeardays) # ------Electric heating, storage heating (primary) load_profiles.add_lp( unique_identifier=uuid.uuid4(), technologies=assumptions.tech_list['storage_heating_electricity'], enduses=['rs_space_heating'], shape_yd=rs_fuel_shape_heating_yd, shape_y_dh=tech_lp['rs_profile_storage_heater_y_dh'], sectors=[dummy_sector], model_yeardays=assumptions.model_yeardays) # ------Electric heating secondary (direct elec heating) load_profiles.add_lp( unique_identifier=uuid.uuid4(), technologies=assumptions.tech_list['secondary_heating_electricity'], enduses=['rs_space_heating'], shape_yd=rs_fuel_shape_heating_yd, shape_y_dh=tech_lp['rs_profile_elec_heater_y_dh'], sectors=[dummy_sector], model_yeardays=assumptions.model_yeardays) # ------Heat pump heating rs_profile_hp_y_dh = insert_peak_dh_shape( peak_day=rs_peak_day, shape_y_dh=tech_lp['rs_profile_hp_y_dh'], shape_peak_dh=tech_lp['rs_lp_heating_hp_dh']['peakday']) rs_fuel_shape_hp_yh, rs_hp_shape_yd = get_fuel_shape_heating_hp_yh( tech_lp_y_dh=rs_profile_hp_y_dh, tech_stock=rs_tech_stock, rs_hdd_cy=self.rs_hdd_cy, model_yeardays=assumptions.model_yeardays) 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_yd=rs_hp_shape_yd, shape_yh=rs_fuel_shape_hp_yh, sectors=[dummy_sector], model_yeardays=assumptions.model_yeardays) # ------District_heating_electricity. Assumption made that same curve as CHP load_profiles.add_lp( unique_identifier=uuid.uuid4(), technologies=assumptions.tech_list['tech_district_heating'], enduses=['rs_space_heating'], shape_yd=rs_fuel_shape_heating_yd, shape_y_dh=rs_profile_hp_y_dh, sectors=[dummy_sector], model_yeardays=assumptions.model_yeardays) # ================================================================== # Service Submodel load profiles # ================================================================== # --------HDD/CDD # current weather_yr self.ss_hdd_by, _ = hdd_cdd.calc_reg_hdd( temp_by, assumptions.t_bases.ss_t_heating, assumptions.model_yeardays, crit_temp_min_max) ss_hdd_cy, ss_fuel_shape_heating_yd = hdd_cdd.calc_reg_hdd( temp_cy, ss_t_base_heating_cy, assumptions.model_yeardays, crit_temp_min_max) self.ss_cdd_by, _ = hdd_cdd.calc_reg_cdd( temp_by, assumptions.t_bases.ss_t_cooling, assumptions.model_yeardays, crit_temp_min_max) ss_cdd_cy, ss_lp_cooling_yd = hdd_cdd.calc_reg_cdd( temp_cy, ss_t_base_cooling_cy, assumptions.model_yeardays, crit_temp_min_max) try: f_heat_ss_y = np.nan_to_num( 1.0 / float(np.sum(self.ss_hdd_by))) * np.sum(ss_hdd_cy) f_cooling_ss_y = np.nan_to_num( 1.0 / float(np.sum(self.ss_cdd_by))) * np.sum(ss_cdd_cy) except ZeroDivisionError: f_heat_ss_y = 1 f_cooling_ss_y = 1 # ======== # Enduse specific profiles # ======== # - Assign to each enduse the carbon fuel trust dataset for enduse in enduses['service']: # Skip temperature dependent end uses (regional) because load profile in regional load profile stock if enduse in assumptions.enduse_space_heating or enduse in assumptions.ss_enduse_space_cooling: pass else: for sector in sectors['service']: # Get technologies with assigned fuel shares tech_list = helpers.get_nested_dict_key( assumptions.fuel_tech_p_by[enduse][sector]) # Apply correction factor for weekend_effect shape_non_peak_yd_weighted = load_profile.abs_to_rel( tech_lp['ss_shapes_yd'][enduse][sector]['shape_non_peak_yd'] * assumptions.ss_weekend_f) load_profiles.add_lp( unique_identifier=uuid.uuid4(), technologies=tech_list, enduses=[enduse], shape_yd=shape_non_peak_yd_weighted, shape_y_dh=tech_lp['ss_shapes_dh'][enduse][sector]['shape_non_peak_y_dh'], model_yeardays=assumptions.model_yeardays, sectors=[sector]) # Apply correction factor for weekend_effect for space heating ss_fuel_shape_heating_yd_weighted = load_profile.abs_to_rel( ss_fuel_shape_heating_yd * assumptions.ss_weekend_f) # ======== # Technology specific profiles # ======== # Flatten list of all potential technologies ss_space_heating_tech_lists = list(assumptions.tech_list.values()) all_techs_ss_space_heating = [item for sublist in ss_space_heating_tech_lists for item in sublist] # -----Heat pump (RESIDENTIAL HEAT PUMP PROFILE FOR SERVICE SECTOR) all_techs_ss_space_heating = basic_functions.remove_element_from_list( all_techs_ss_space_heating, 'heat_pumps_electricity') ss_fuel_shape_hp_yh, ss_hp_shape_yd = get_fuel_shape_heating_hp_yh( tech_lp_y_dh=rs_profile_hp_y_dh, tech_stock=rs_tech_stock, rs_hdd_cy=ss_hdd_cy, model_yeardays=assumptions.model_yeardays) load_profiles.add_lp( unique_identifier=uuid.uuid4(), technologies=assumptions.tech_list['heating_non_const'], enduses=['ss_space_heating', 'ss_water_heating'], sectors=sectors['service'], shape_y_dh=rs_profile_hp_y_dh, shape_yd=ss_hp_shape_yd, shape_yh=ss_fuel_shape_hp_yh, model_yeardays=assumptions.model_yeardays) # ---secondary_heater_electricity Info: The residential direct heating load profile is used all_techs_ss_space_heating = basic_functions.remove_element_from_list( all_techs_ss_space_heating, 'secondary_heater_electricity') # Get aggregated electricity load profile #ALTERNATIVE :tech_lp['ss_all_tech_shapes_dh']['ss_other_electricity']['shape_non_peak_y_dh'] load_profiles.add_lp( unique_identifier=uuid.uuid4(), technologies=assumptions.tech_list['secondary_heating_electricity'], enduses=['ss_space_heating'], sectors=sectors['service'], shape_yd=ss_fuel_shape_heating_yd_weighted, shape_y_dh=tech_lp['rs_profile_elec_heater_y_dh'], model_yeardays=assumptions.model_yeardays) # ELEC CURVE ss_fuel_shape_electricity # DIRECT HEATING ss_profile_elec_heater_yh # ---Heating technologies (all other) # (the heating shape follows the gas shape of aggregated sectors) # meaning that for all technologies, the load profile is the same load_profiles.add_lp( unique_identifier=uuid.uuid4(), technologies=all_techs_ss_space_heating, enduses=['ss_space_heating'], sectors=sectors['service'], shape_yd=ss_fuel_shape_heating_yd_weighted, shape_y_dh=tech_lp['ss_all_tech_shapes_dh']['ss_space_heating']['shape_non_peak_y_dh'], model_yeardays=assumptions.model_yeardays) # --Add cooling technologies for service sector coolings_techs = assumptions.tech_list['cooling_const'] for cooling_enduse in assumptions.ss_enduse_space_cooling: for sector in sectors['service']: # Apply correction factor for weekend_effect 'cdd_weekend_cfactors' ss_lp_cooling_yd_weighted = load_profile.abs_to_rel( ss_lp_cooling_yd * assumptions.cdd_weekend_cfactors) load_profiles.add_lp( unique_identifier=uuid.uuid4(), technologies=coolings_techs, enduses=[cooling_enduse], sectors=[sector], shape_yd=ss_lp_cooling_yd_weighted, shape_y_dh=tech_lp['ss_profile_cooling_y_dh'], model_yeardays=assumptions.model_yeardays) # ================================================================== # Industry submodel load profiles # ================================================================== # --------HDD/CDD # Current weather_yr self.is_hdd_by, _ = hdd_cdd.calc_reg_hdd( temp_by, assumptions.t_bases.is_t_heating, assumptions.model_yeardays, crit_temp_min_max) #is_cdd_by, _ = hdd_cdd.calc_reg_cdd( # temp_by, assumptions.t_bases.is_t_cooling, assumptions.model_yeardays) # Take same base temperature as for service sector is_hdd_cy, is_fuel_shape_heating_yd = hdd_cdd.calc_reg_hdd( temp_cy, is_t_base_heating_cy, assumptions.model_yeardays, crit_temp_min_max) #is_cdd_cy, _ = hdd_cdd.calc_reg_cdd( # temp_cy, ss_t_base_cooling_cy, assumptions.model_yeardays) try: f_heat_is_y = np.nan_to_num(1.0 / float(np.sum(self.is_hdd_by))) * np.sum(is_hdd_cy) #self.f_cooling_is_y = np.nan_to_num(1.0 / float(np.sum(is_cdd_by))) * np.sum(is_cdd_cy) f_cooling_is_y = 1 except ZeroDivisionError: f_heat_is_y = 1 f_cooling_is_y = 1 # ======== # Technology specific profiles # ======== # --Heating technologies # Flatten list of all potential heating technologies is_space_heating_tech_lists = list(assumptions.tech_list.values()) all_techs_is_space_heating = [item for sublist in is_space_heating_tech_lists for item in sublist] # Apply correction factor for weekend_effect for space heating load profile is_fuel_shape_heating_yd_weighted = load_profile.abs_to_rel( is_fuel_shape_heating_yd * assumptions.is_weekend_f) # - Direct electric heating # Remove tech from all space heating techs all_techs_is_space_heating = basic_functions.remove_element_from_list( all_techs_is_space_heating, 'secondary_heater_electricity') load_profiles.add_lp( unique_identifier=uuid.uuid4(), technologies=assumptions.tech_list['secondary_heating_electricity'], enduses=['is_space_heating'], sectors=sectors['industry'], shape_yd=is_fuel_shape_heating_yd_weighted, shape_y_dh=tech_lp['rs_profile_elec_heater_y_dh'], model_yeardays=assumptions.model_yeardays) # Add flat load profiles for non-electric heating technologies load_profiles.add_lp( unique_identifier=uuid.uuid4(), technologies=all_techs_is_space_heating, enduses=['is_space_heating'], sectors=sectors['industry'], shape_yd=is_fuel_shape_heating_yd_weighted, shape_y_dh=flat_shape_y_dh, model_yeardays=assumptions.model_yeardays) # Apply correction factor for weekend_effect to flat load profile for industry flat_shape_yd = flat_shape_yd * assumptions.is_weekend_f flat_shape_yd_weighted = load_profile.abs_to_rel(flat_shape_yd) # ======== # Enduse specific profiles # ======== for enduse in enduses['industry']: if enduse == "is_space_heating": pass # Do not create non regional stock because temp dependent else: for sector in sectors['industry']: tech_list = helpers.get_nested_dict_key( assumptions.fuel_tech_p_by[enduse][sector]) load_profiles.add_lp( unique_identifier=uuid.uuid4(), technologies=tech_list, enduses=[enduse], shape_yd=flat_shape_yd_weighted, shape_y_dh=flat_shape_y_dh, model_yeardays=assumptions.model_yeardays, sectors=[sector]) # --------------- # Load profiles # --------------- self.load_profiles = load_profiles self.f_heat = { 'residential': f_heat_rs_y, 'service': f_heat_ss_y, 'industry': f_heat_is_y} self.f_colling = { 'residential': f_cooling_rs_y, 'service': f_cooling_ss_y, 'industry': f_cooling_is_y}
def read_in_results( path_result, seasons, model_yeardays_daytype ): """Read and post calculate results from txt files and store into container Arguments --------- path_result : str Paths seasons : dict seasons model_yeardays_daytype : dict Daytype of modelled yeardays """ logging.info("... Reading in results") lookups = lookup_tables.basic_lookups() results_container = {} # ----------------- # Read in demands # ----------------- try: results_container['results_enduse_every_year'] = read_enduse_specific_results( path_result) except: pass try: print("path_result " + str(path_result)) results_container['ed_fueltype_regs_yh'] = read_results_yh( path_result, 'ed_fueltype_regs_yh') except: pass # Read in residential demands try: results_container['residential_results'] = read_results_yh( path_result, 'residential_results') except: pass # Calculate total demand per fueltype for every hour try: tot_fueltype_yh = {} for year in results_container['ed_fueltype_regs_yh']: nr_of_fueltypes = results_container['ed_fueltype_regs_yh'][year].shape[0] tot_fueltype_yh[year] = np.zeros((nr_of_fueltypes, 8760)) for year, ed_regs_yh in results_container['ed_fueltype_regs_yh'].items(): fuel_yh = np.sum(ed_regs_yh, axis=1) #Sum across all regions tot_fueltype_yh[year] += fuel_yh results_container['tot_fueltype_yh'] = tot_fueltype_yh except: pass # ----------------- # Peak calculations # ----------------- try: results_container['ed_peak_h'] = {} results_container['ed_peak_regs_h'] = {} for year, ed_fueltype_reg_yh in results_container['ed_fueltype_regs_yh'].items(): results_container['ed_peak_h'][year] = {} results_container['ed_peak_regs_h'][year] = {} for fueltype_int, ed_reg_yh in enumerate(ed_fueltype_reg_yh): fueltype_str = tech_related.get_fueltype_str(lookups['fueltypes'], fueltype_int) # Calculate peak per fueltype for all regions (ed_reg_yh= np.array(fueltype, reg, yh)) all_regs_yh = np.sum(ed_reg_yh, axis=0) # sum regs peak_h = np.max(all_regs_yh) # select max of 8760 h results_container['ed_peak_h'][year][fueltype_str] = peak_h results_container['ed_peak_regs_h'][year][fueltype_str] = np.max(ed_reg_yh, axis=1) # ------------- # Load factors # ------------- results_container['reg_load_factor_y'] = read_lf_y( os.path.join(path_result, "result_reg_load_factor_y")) results_container['reg_load_factor_yd'] = read_lf_y( os.path.join(path_result, "result_reg_load_factor_yd")) # ------------- # Post-calculations # ------------- # Calculate average per season and fueltype for every fueltype results_container['av_season_daytype_cy'], results_container['season_daytype_cy'] = calc_av_per_season_fueltype( results_container['ed_fueltype_regs_yh'], seasons, model_yeardays_daytype) '''results_container['load_factor_seasons'] = {} results_container['load_factor_seasons']['winter'] = read_lf_y( os.path.join(path_result, "result_reg_load_factor_winter")) results_container['load_factor_seasons']['spring'] = read_lf_y( os.path.join(path_result, "result_reg_load_factor_spring")) results_container['load_factor_seasons']['summer'] = read_lf_y( os.path.join(path_result, "result_reg_load_factor_summer")) results_container['load_factor_seasons']['autumn'] = read_lf_y( os.path.join(path_result, "result_reg_load_factor_autumn"))''' except: pass logging.info("... Reading in results finished") return results_container
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 __init__(self, lookup_enduses=None, lookup_sector_enduses=None, base_yr=None, weather_by=None, simulation_end_yr=None, curr_yr=None, sim_yrs=None, paths=None, enduses=None, sectors=None, reg_nrs=None): """Constructor """ self.lookup_enduses = lookup_enduses self.lookup_sector_enduses = lookup_sector_enduses self.submodels_names = lookup_tables.basic_lookups()['submodels_names'] self.nr_of_submodels = len(self.submodels_names) self.fueltypes = lookup_tables.basic_lookups()['fueltypes'] self.fueltypes_nr = lookup_tables.basic_lookups()['fueltypes_nr'] self.base_yr = base_yr self.weather_by = weather_by self.reg_nrs = reg_nrs self.simulation_end_yr = simulation_end_yr self.curr_yr = curr_yr self.sim_yrs = sim_yrs # ============================================================ # Spatially modelled variables # # If spatial explicit diffusion is modelled, all parameters # or technologies having a spatial explicit diffusion need # to be defined. # ============================================================ self.spatial_explicit_diffusion = 0 #0: False, 1: True # Define all variables which are affected by regional diffusion self.spatially_modelled_vars = [] # ['smart_meter_p'] # Define technologies which are affected by spatial explicit diffusion self.techs_affected_spatial_f = ['heat_pumps_electricity'] # Max penetration speed self.speed_con_max = 1 #1.5 # 1: uniform distribution >1: regional differences # ============================================================ # Model calibration factors # ============================================================ # # These calibration factors are used to match the modelled # electrictiy demand better with the validation data. # # Weekend effects are used to distribut energy demands # between working and weekend days. With help of these # factors, the demand on weekends and holidays can be # be lowered compared to working days. # This factor can be applied either directly to an enduse # or to the hdd or cdd calculations (to correct cooling # or heating demand) # # f_ss_cooling_weekend : float # Weekend effect for cooling enduses # f_ss_weekend : float # WWeekend effect for service submodel enduses # f_is_weekend : float # Weekend effect for industry submodel enduses # f_mixed_floorarea : float # Share of floor_area which is assigned to either # residential or non_residential floor area # ------------------------------------------------------------ self.f_ss_cooling_weekend = 0.45 # Temporal calibration factor self.f_ss_weekend = 0.8 # Temporal calibration factor self.f_is_weekend = 0.45 # Temporal calibration factor # ============================================================ # Modelled day related factors # ============================================================ # model_yeardays_date : dict # Contains for the base year for each days # the information wheter this is a working or holiday # ------------------------------------------------------------ self.model_yeardays = list(range(365)) # Calculate dates self.model_yeardays_date = [] for yearday in self.model_yeardays: self.model_yeardays_date.append( date_prop.yearday_to_date(base_yr, yearday)) # ============================================================ # Dwelling stock related assumptions # ============================================================ # # Assumptions to generate a virtual dwelling stock # # assump_diff_floorarea_pp : float # Change in floor area per person (%, 1=100%) # assump_diff_floorarea_pp_yr_until_changed : int # Year until this change in floor area happens # dwtype_distr_by : dict # Housing Stock Distribution by Type # Source: UK Housing Energy Fact File, Table 4c # dwtype_distr_fy : dict # welling type distribution end year # Source: UK Housing Energy Fact File, Table 4c # dwtype_floorarea_by : dict # Floor area per dwelling type (Annex Table 3.1) # Source: UK Housing Energy Fact File, Table 4c # dwtype_floorarea_fy : dict # Floor area per dwelling type # Source: UK Housing Energy Fact File, Table 4c # dwtype_age_distr : dict # Floor area per dwelling type # Source: Housing Energy Fact Sheet) # yr_until_changed : int # Year until change is realised # # https://www.gov.uk/government/statistics/english-housing-survey-2014-to-2015-housing-stock-report # ------------------------------------------------------------ yr_until_changed_all_things = 2050 self.dwtype_distr_by = { 'semi_detached': 0.26, 'terraced': 0.283, 'flat': 0.203, 'detached': 0.166, 'bungalow': 0.088 } self.dwtype_distr_fy = { 'yr_until_changed': yr_until_changed_all_things, 'semi_detached': 0.26, 'terraced': 0.283, 'flat': 0.203, 'detached': 0.166, 'bungalow': 0.088 } self.dwtype_floorarea_by = { 'semi_detached': 96, 'terraced': 82.5, 'flat': 61, 'detached': 147, 'bungalow': 77 } self.dwtype_floorarea_fy = { 'yr_until_changed': yr_until_changed_all_things, 'semi_detached': 96, 'terraced': 82.5, 'flat': 61, 'detached': 147, 'bungalow': 77 } # (Average builing age within age class, fraction) # The newest category of 2015 is added to implement change in refurbishing rate # For the base year, this is set to zero (if e.g. with future scenario set to 5%, then # proportionally to base year distribution number of houses are refurbished) self.dwtype_age_distr = { 2015: { '1918': 0.21, '1941': 0.36, '1977.5': 0.3, '1996.5': 0.08, '2002': 0.05 } } # ============================================================ # Scenario drivers # ============================================================ # # For every enduse the relevant factors which affect enduse # consumption can be added in a list. # # Note: If e.g. floorarea and population are added, the # effects will be overestimates (i.e. no multi- # collinearity are considered). # # scenario_drivers : dict # Scenario drivers per enduse # ------------------------------------------------------------ self.scenario_drivers = { # --Residential 'rs_space_heating': ['floorarea', 'hlc'], # Do not use HDD or pop because otherweise double count 'rs_water_heating': ['population'], 'rs_lighting': ['population', 'floorarea'], 'rs_cooking': ['population'], 'rs_cold': ['population'], 'rs_wet': ['population'], 'rs_consumer_electronics': ['population', 'gva'], 'rs_home_computing': ['population'], # --Service 'ss_space_heating': ['floorarea'], 'ss_water_heating': ['population'], 'ss_lighting': ['floorarea'], 'ss_catering': ['population'], 'ss_ICT_equipment': ['population'], 'ss_cooling_humidification': ['floorarea', 'population'], 'ss_fans': ['floorarea', 'population'], 'ss_small_power': ['population'], 'ss_cooled_storage': ['population'], 'ss_other_gas': ['population'], 'ss_other_electricity': ['population'], # Industry 'is_high_temp_process': ['gva'], 'is_low_temp_process': ['gva'], 'is_drying_separation': ['gva'], 'is_motors': ['gva'], 'is_compressed_air': ['gva'], 'is_lighting': ['gva'], 'is_space_heating': ['gva'], 'is_other': ['gva'], 'is_refrigeration': ['gva'] } # ============================================================ # Cooling related assumptions # ============================================================ # assump_cooling_floorarea : int # The percentage of cooled floor space in the base year # # Literature # ---------- # Abela, A. et al. (2016). Study on Energy Use by Air # Conditioning. Bre, (June), 31. Retrieved from # https://www.bre.co.uk/filelibrary/pdf/projects/aircon-energy-use/StudyOnEnergyUseByAirConditioningFinalReport.pdf # ------------------------------------------------------------ # See Abela et al. (2016) & Carbon Trust. (2012). Air conditioning. Maximising comfort, minimising energy consumption self.cooled_ss_floorarea_by = 0.35 # ============================================================ # Smart meter related base year assumptions # ============================================================ # smart_meter_p_by : int # The percentage of households with smart meters in by # ------------------------------------------------------------ self.smart_meter_assump = {} # Currently in 2017 8.6 mio smart meter installed of 27.2 mio households --> 31.6% # https://assets.publishing.service.gov.uk/government/uploads/system/uploads/attachment_data/file/671930/Smart_Meters_2017_update.pdf) # In 2015, 5.8 % percent of all househods had one: https://assets.publishing.service.gov.uk/government/uploads/system/uploads/attachment_data/file/533060/2016_Q1_Smart_Meters_Report.pdf self.smart_meter_assump['smart_meter_p_by'] = 0.05 # Long term smart meter induced general savings, purley as # a result of having a smart meter (e.g. 0.03 --> 3% savings) # DECC 2015: Smart Metering Early Learning Project: Synthesis report # https://www.gov.uk/government/publications/smart-metering-early-learning-project-and-small-scale-behaviour-trials # Reasonable assumption is between 0.03 and 0.01 (DECC 2015) self.smart_meter_assump['savings_smart_meter'] = { # Residential 'rs_cold': 0.03, 'rs_cooking': 0.03, 'rs_lighting': 0.03, 'rs_wet': 0.03, 'rs_consumer_electronics': 0.03, 'rs_home_computing': 0.03, 'rs_space_heating': 0.03, 'rs_water_heating': 0.03, # Service 'ss_space_heating': 0.03, 'ss_water_heating': 0.03, 'ss_cooling_humidification': 0.03, 'ss_fans': 0.03, 'ss_lighting': 0.03, 'ss_catering': 0.03, 'ss_small_power': 0.03, 'ss_ICT_equipment': 0.03, 'ss_cooled_storage': 0.03, 'ss_other_gas': 0.03, 'ss_other_electricity': 0.03, # Industry submodule 'is_high_temp_process': 0, 'is_low_temp_process': 0, 'is_drying_separation': 0, 'is_motors': 0, 'is_compressed_air': 0, 'is_lighting': 0, 'is_space_heating': 0, 'is_other': 0, 'is_refrigeration': 0 } # ============================================================ # Base temperature assumptions # ============================================================ # # Parameters related to smart metering # # rs_t_heating : int # Residential submodel base temp of heating of base year # rs_t_cooling_by : int # Residential submodel base temp of cooling of base year # ... # # Note # ---- # Because demand for cooling cannot directly be linked to # calculated cdd, the paramters 'ss_t_base_cooling' is used # as a calibration factor. By artifiallcy lowering this # parameter, the energy demand assignement over the days # in a year is improved. # ------------------------------------------------------------ t_bases = { 'rs_t_heating': 15.5, 'ss_t_heating': 15.5, 'ss_t_cooling': 5, 'is_t_heating': 15.5 } self.t_bases = DummyClass(t_bases) # ============================================================ # Enduses lists affed by hdd/cdd # ============================================================ # # These lists show for which enduses temperature related # calculations are performed. # # enduse_space_heating : list # All enduses for which hdd are used for yd calculations # ss_enduse_space_cooling : list # All service submodel enduses for which cdd are used for # yd calculations # ------------------------------------------------------------ self.enduse_space_heating = [ 'rs_space_heating', 'ss_space_heating', 'is_space_heating' ] self.ss_enduse_space_cooling = ['ss_cooling_humidification'] # ============================================================ # Industry related # # High temperature processing (high_temp_ process) dominates # energy consumption in the iron and steel # # ---- Steel production - Enduse: is_high_temp_process, Sector: basic_metals # With industry service switch, the future shares of 'is_temp_high_process' # in sector 'basic_metals' can be set for 'basic_oxygen_furnace', # 'electric_arc_furnace', and 'SNG_furnace' can be specified # # ---- Cement production - Enduse: is_high_temp_process, Sector: non_metallic_mineral_products # Dry kilns, semidry kilns can be set # ============================================================ # Share of cold rolling in steel manufacturing self.p_cold_rolling_steel_by = 0.2 # Estimated based on https://aceroplatea.es/docs/EuropeanSteelFigures_2015.pdf self.eff_cold_rolling_process = 1.8 # 80% more efficient than hot rolling Fruehan et al. (2002) self.eff_hot_rolling_process = 1.0 # 100% assumed efficiency # ============================================================ # Assumption related to heat pump technologies # ============================================================ # # Assumptions related to technologies # # gshp_fraction : list # Fraction of installed gshp_fraction heat pumps in base year # ASHP = 1 - gshp_fraction # ------------------------------------------------------------ self.gshp_fraction = 0.1 # Load defined technologies self.technologies, self.tech_list = read_data.read_technologies( paths['path_technologies']) self.installed_heat_pump_by = tech_related.generate_ashp_gshp_split( self.gshp_fraction) # Add heat pumps to technologies self.technologies, self.tech_list[ 'heating_non_const'], self.heat_pumps = tech_related.generate_heat_pump_from_split( self.technologies, self.installed_heat_pump_by, self.fueltypes) # ============================================================ # Fuel Stock Definition # Provide for every fueltype of an enduse the share of fuel # which is used by technologies in the base year # ============================================================$ fuel_tech_p_by = fuel_shares.assign_by_fuel_tech_p( enduses, sectors, self.fueltypes, self.fueltypes_nr) # ======================================== # Get technologies of an enduse and sector # ======================================== self.specified_tech_enduse_by = helpers.get_def_techs(fuel_tech_p_by) _specified_tech_enduse_by = helpers.add_undef_techs( self.heat_pumps, self.specified_tech_enduse_by, self.enduse_space_heating) self.specified_tech_enduse_by = _specified_tech_enduse_by # ======================================== # General other info # ======================================== self.seasons = date_prop.get_season(year_to_model=base_yr) self.model_yeardays_daytype, self.yeardays_month, self.yeardays_month_days = date_prop.get_yeardays_daytype( year_to_model=base_yr) # ======================================== # Helper functions # ======================================== self.fuel_tech_p_by, self.specified_tech_enduse_by, self.technologies = tech_related.insert_placholder_techs( self.technologies, fuel_tech_p_by, self.specified_tech_enduse_by) # ======================================== # Calculations with assumptions # ======================================== self.cdd_weekend_cfactors = hdd_cdd.calc_weekend_corr_f( self.model_yeardays_daytype, self.f_ss_cooling_weekend) self.ss_weekend_f = hdd_cdd.calc_weekend_corr_f( self.model_yeardays_daytype, self.f_ss_weekend) self.is_weekend_f = hdd_cdd.calc_weekend_corr_f( self.model_yeardays_daytype, self.f_is_weekend) # ======================================== # Testing # ======================================== testing_functions.testing_fuel_tech_shares(self.fuel_tech_p_by) testing_functions.testing_tech_defined(self.technologies, self.specified_tech_enduse_by)
def spatio_temporal_val(ed_fueltype_national_yh, ed_fueltype_regs_yh, result_paths, paths, regions, seasons, model_yeardays_daytype, plot_crit): """Validate spatial and temporal energy demands Info ----- Because the floor area is only availabe for LADs from 2001, the LADs are converted to 2015 LADs. """ logging.info("... temporal validation") fueltypes = lookup_tables.basic_lookups()['fueltypes'] # ------------------------------------------- # Spatial validation after calculations # ------------------------------------------- subnational_elec = data_loader.read_lad_demands( paths['val_subnational_elec']) subnational_gas = data_loader.read_lad_demands( paths['val_subnational_gas']) # Create fueltype secific dict fuel_elec_regs_yh = {} for region_array_nr, region in enumerate(regions): fuel_elec_regs_yh[region] = np.sum( ed_fueltype_regs_yh[fueltypes['electricity']][region_array_nr]) # Create fueltype secific dict fuel_gas_regs_yh = {} for region_array_nr, region in enumerate(regions): fuel_gas_regs_yh[region] = np.sum( ed_fueltype_regs_yh[fueltypes['gas']][region_array_nr]) # ---------------------------------------- # Remap demands between 2011 and 2015 LADs # ---------------------------------------- subnational_elec = map_LAD_2011_2015(subnational_elec) subnational_gas = map_LAD_2011_2015(subnational_gas) fuel_elec_regs_yh = map_LAD_2011_2015(fuel_elec_regs_yh) fuel_gas_regs_yh = map_LAD_2011_2015(fuel_gas_regs_yh) spatial_validation(fuel_elec_regs_yh, subnational_elec, regions, 'elec', fig_name=os.path.join( result_paths['data_results_validation'], 'validation_spatial_elec_post_calcualtion.pdf'), label_points=False, plotshow=plot_crit) spatial_validation(fuel_gas_regs_yh, subnational_gas, regions, 'gas', fig_name=os.path.join( result_paths['data_results_validation'], 'validation_spatial_gas_post_calcualtion.pdf'), label_points=False, plotshow=plot_crit) # ------------------------------------------- # Temporal validation (hourly for national) # ------------------------------------------- # Read validation data elec_2015_indo, elec_2015_itsdo = elec_national_data.read_raw_elec_2015( paths['val_nat_elec_data']) f_diff_elec = np.sum(ed_fueltype_national_yh[ fueltypes['electricity']]) / np.sum(elec_2015_indo) logging.info("... ed diff modellend and real [p] %s: ", (1 - f_diff_elec) * 100) elec_factored_yh = f_diff_elec * elec_2015_indo temporal_validation(result_paths, ed_fueltype_national_yh[fueltypes['electricity']], elec_factored_yh, plot_crit) # --------------------------------------------------- # Calculate average season and daytypes and plot # --------------------------------------------------- logging.info("...calculate average data and plot per season and fueltype") calc_av_lp_modelled, calc_lp_modelled = load_profile.calc_av_lp( ed_fueltype_national_yh[fueltypes['electricity']], seasons, model_yeardays_daytype) calc_av_lp_real, calc_lp_real = load_profile.calc_av_lp( elec_factored_yh, seasons, model_yeardays_daytype) # Plot average daily loads fig_load_profile_dh_multiple.run( path_fig_folder=result_paths['data_results_validation'], path_plot_fig=os.path.join(result_paths['data_results_validation'], 'validation_all_season_daytypes.pdf'), calc_av_lp_modelled=calc_av_lp_modelled, calc_av_lp_real=calc_av_lp_real, calc_lp_modelled=calc_lp_modelled, calc_lp_real=calc_lp_real, plot_peak=True, plot_radar=False, plot_all_entries=False, plot_max_min_polygon=True, plotshow=False, max_y_to_plot=60, fueltype_str=False, year=False) # --------------------------------------------------- # Validation of national electrictiy demand for peak # --------------------------------------------------- logging.debug("...validation of peak data: compare peak with data") # Because the coldest day is not the same for every region, # the coldest day needs to be defined manually or defined # by getting the hours with maximum electricity demand # Peak across all fueltypes WARNING: Fueltype specific peak_day_all_fueltypes = enduse_func.get_peak_day_all_fueltypes( ed_fueltype_national_yh) logging.info("Peak day 'peak_day_all_fueltypes': " + str(peak_day_all_fueltypes)) fueltype = fueltypes['electricity'] peak_day_electricity, _ = enduse_func.get_peak_day_single_fueltype( ed_fueltype_national_yh[fueltype]) logging.info("Peak day 'peak_day_electricity': " + str(peak_day_electricity)) elec_national_data.compare_peak( "validation_peak_elec_day_all_fueltypes.pdf", result_paths['data_results_validation'], elec_2015_indo[peak_day_all_fueltypes], ed_fueltype_national_yh[ fueltypes['electricity']][peak_day_all_fueltypes], peak_day_all_fueltypes) elec_national_data.compare_peak( "validation_peak_elec_day_only_electricity.pdf", result_paths['data_results_validation'], elec_2015_indo[peak_day_electricity], ed_fueltype_national_yh[ fueltypes['electricity']][peak_day_electricity], peak_day_electricity) # Manual peak day peak_day = 19 elec_national_data.compare_peak( "validation_elec_peak_day_{}.pdf".format(peak_day), result_paths['data_results_validation'], elec_factored_yh[peak_day], ed_fueltype_national_yh[fueltypes['electricity']][peak_day], peak_day) peak_day = 33 elec_national_data.compare_peak( "validation_elec_peak_day_{}.pdf".format(peak_day), result_paths['data_results_validation'], elec_factored_yh[peak_day], ed_fueltype_national_yh[fueltypes['electricity']][peak_day], peak_day) peak_day_real_electricity, _ = enduse_func.get_peak_day_single_fueltype( elec_2015_indo) logging.info("Peak day 'peak_day_electricity': " + str(peak_day_real_electricity)) #raise Exception elec_national_data.compare_peak( "validation_elec_peak_day_{}.pdf".format(peak_day_real_electricity), result_paths['data_results_validation'], elec_factored_yh[peak_day], ed_fueltype_national_yh[fueltypes['electricity']] [peak_day_real_electricity], peak_day_real_electricity) # --------------------------------------------------- # Validate boxplots for every hour (temporal validation) # --------------------------------------------------- elec_national_data.compare_results_hour_boxplots( "validation_hourly_boxplots_electricity_01.pdf", result_paths['data_results_validation'], elec_2015_indo, ed_fueltype_national_yh[fueltypes['electricity']]) return
def spatial_validation_lad_level(disaggregated_fuel, data_results_validation, paths, regions, reg_coord, plot_crit): """Spatial validation """ fuel_elec_regs_yh = {} fuel_gas_regs_yh = {} fuel_gas_residential_regs_yh = {} fuel_gas_non_residential_regs_yh = {} fuel_elec_residential_regs_yh = {} fuel_elec_non_residential_regs_yh = {} lookups = lookup_tables.basic_lookups() # ------------------------------------------- # Spatial validation # ------------------------------------------- subnational_elec = data_loader.read_lad_demands( paths['val_subnational_elec']) subnational_elec_residential = data_loader.read_lad_demands( paths['val_subnational_elec_residential']) subnational_elec_non_residential = data_loader.read_lad_demands( paths['val_subnational_elec_non_residential']) subnational_gas = data_loader.read_lad_demands( paths['val_subnational_gas']) subnational_gas_residential = data_loader.read_lad_demands( paths['val_subnational_gas_residential']) subnational_gas_non_residential = data_loader.read_lad_demands( paths['val_subnational_gas_non_residential']) logging.info("compare total II {} {}".format( sum(subnational_gas.values()), sum(subnational_gas_residential.values()))) # Create fueltype secific dict for region in regions: fuel_elec_regs_yh[region] = disaggregated_fuel[ 'tot_disaggregated_regs'][region][lookups['fueltypes'] ['electricity']] fuel_elec_residential_regs_yh[region] = disaggregated_fuel[ 'tot_disaggregated_regs_residenital'][region][lookups['fueltypes'] ['electricity']] fuel_elec_non_residential_regs_yh[region] = disaggregated_fuel[ 'tot_disaggregated_regs_non_residential'][region][ lookups['fueltypes']['electricity']] fuel_gas_regs_yh[region] = disaggregated_fuel[ 'tot_disaggregated_regs'][region][lookups['fueltypes']['gas']] fuel_gas_residential_regs_yh[region] = disaggregated_fuel[ 'tot_disaggregated_regs_residenital'][region][lookups['fueltypes'] ['gas']] fuel_gas_non_residential_regs_yh[region] = disaggregated_fuel[ 'tot_disaggregated_regs_non_residential'][region][ lookups['fueltypes']['gas']] # ---------------------------------------- # Remap demands between 2011 and 2015 LADs # ---------------------------------------- subnational_elec = map_LAD_2011_2015(subnational_elec) subnational_elec_residential = map_LAD_2011_2015( subnational_elec_residential) subnational_elec_non_residential = map_LAD_2011_2015( subnational_elec_non_residential) subnational_gas = map_LAD_2011_2015(subnational_gas) subnational_gas_residential = map_LAD_2011_2015( subnational_gas_residential) subnational_gas_non_residential = map_LAD_2011_2015( subnational_gas_non_residential) fuel_elec_regs_yh = map_LAD_2011_2015(fuel_elec_regs_yh) fuel_elec_residential_regs_yh = map_LAD_2011_2015( fuel_elec_residential_regs_yh) fuel_elec_non_residential_regs_yh = map_LAD_2011_2015( fuel_elec_non_residential_regs_yh) fuel_gas_regs_yh = map_LAD_2011_2015(fuel_gas_regs_yh) fuel_gas_residential_regs_yh = map_LAD_2011_2015( fuel_gas_residential_regs_yh) fuel_gas_non_residential_regs_yh = map_LAD_2011_2015( fuel_gas_non_residential_regs_yh) logging.info("compare total {} {}".format( sum(fuel_gas_residential_regs_yh.values()), sum(fuel_gas_regs_yh.values()))) # -------------------------------------------- # Correct REAL Values that sum is the same # ---------------------------------------------- data_inputlist = [ (fuel_elec_residential_regs_yh, subnational_elec_residential), # domestic (fuel_elec_non_residential_regs_yh, subnational_elec_non_residential) ] # nondomestics spatial_validation_multiple(reg_coord=reg_coord, input_data=data_inputlist, regions=regions, fueltype_str='elec', fig_name=os.path.join( data_results_validation, 'validation_multiple_elec.pdf'), label_points=False, plotshow=plot_crit) data_inputlist = [ (fuel_gas_residential_regs_yh, subnational_gas_residential), # domestic (fuel_gas_non_residential_regs_yh, subnational_gas_non_residential) ] # nondomestics spatial_validation_multiple(reg_coord=reg_coord, input_data=data_inputlist, regions=regions, fueltype_str='gas', fig_name=os.path.join( data_results_validation, 'validation_multiple_gas.pdf'), label_points=False, plotshow=plot_crit) logging.info("... Validation of electricity") spatial_validation(fuel_elec_regs_yh, subnational_elec, regions, 'elec', os.path.join(data_results_validation, 'validation_spatial_elec.pdf'), label_points=True, plotshow=plot_crit) logging.info("... Validation of residential electricity") spatial_validation(fuel_elec_residential_regs_yh, subnational_elec_residential, regions, 'elec', os.path.join(data_results_validation, 'validation_spatial_residential_elec.pdf'), label_points=True, plotshow=plot_crit) logging.info("... Validation of non-residential electricity") spatial_validation(fuel_elec_non_residential_regs_yh, subnational_elec_non_residential, regions, 'elec', os.path.join( data_results_validation, 'validation_spatial_non_residential_elec.pdf'), label_points=True, plotshow=plot_crit) logging.info("... Validation of gas") spatial_validation(fuel_gas_regs_yh, subnational_gas, regions, 'gas', os.path.join(data_results_validation, 'validation_spatial_gas.pdf'), label_points=True, plotshow=plot_crit) logging.info("... Validation of residential gas") spatial_validation(fuel_gas_residential_regs_yh, subnational_gas_residential, regions, 'gas', os.path.join(data_results_validation, 'validation_spatial_residential_gas.pdf'), label_points=True, plotshow=plot_crit) logging.info("... Validation of non residential gas") spatial_validation(fuel_gas_non_residential_regs_yh, subnational_gas_non_residential, regions, 'gas', os.path.join( data_results_validation, 'validation_spatial_non_residential_gas.pdf'), label_points=True, plotshow=plot_crit) return
def test_function_fuel_sum( data, fuel_disagg, mode_constrained, space_heating_enduses ): """ Sum raw disaggregated fuel data """ lookups = lookup_tables.basic_lookups() fuel_in = 0 fuel_in_solid_fuel = 0 fuel_in_gas = 0 fuel_in_elec = 0 fuel_in_oil = 0 fuel_in_heat = 0 fuel_in_hydrogen = 0 fuel_in_biomass = 0 tot_heating = 0 dummy_sector = None for region in fuel_disagg['residential']: for enduse in fuel_disagg['residential'][region]: fuel_in += np.sum(fuel_disagg['residential'][region][enduse][dummy_sector]) fuel_in_heat += np.sum(fuel_disagg['residential'][region][enduse][dummy_sector][lookups['fueltypes']['heat']]) if mode_constrained == False and enduse in space_heating_enduses: #Exclude inputs for heating tot_heating += np.sum(fuel_disagg['residential'][region][enduse][dummy_sector]) else: fuel_in_elec += np.sum(fuel_disagg['residential'][region][enduse][dummy_sector][lookups['fueltypes']['electricity']]) fuel_in_gas += np.sum(fuel_disagg['residential'][region][enduse][dummy_sector][lookups['fueltypes']['gas']]) fuel_in_hydrogen += np.sum(fuel_disagg['residential'][region][enduse][dummy_sector][lookups['fueltypes']['hydrogen']]) fuel_in_oil += np.sum(fuel_disagg['residential'][region][enduse][dummy_sector][lookups['fueltypes']['oil']]) fuel_in_solid_fuel += np.sum(fuel_disagg['residential'][region][enduse][dummy_sector][lookups['fueltypes']['solid_fuel']]) fuel_in_biomass += np.sum(fuel_disagg['residential'][region][enduse][dummy_sector][lookups['fueltypes']['biomass']]) for region in fuel_disagg['service']: for enduse in fuel_disagg['service'][region]: for sector in fuel_disagg['service'][region][enduse]: fuel_in += np.sum(fuel_disagg['service'][region][enduse][sector]) fuel_in_heat += np.sum(fuel_disagg['service'][region][enduse][sector][lookups['fueltypes']['heat']]) if mode_constrained == False and enduse in space_heating_enduses: tot_heating += np.sum(fuel_disagg['service'][region][enduse][sector]) else: fuel_in_elec += np.sum(fuel_disagg['service'][region][enduse][sector][lookups['fueltypes']['electricity']]) fuel_in_gas += np.sum(fuel_disagg['service'][region][enduse][sector][lookups['fueltypes']['gas']]) fuel_in_hydrogen += np.sum(fuel_disagg['service'][region][enduse][sector][lookups['fueltypes']['hydrogen']]) fuel_in_oil += np.sum(fuel_disagg['service'][region][enduse][sector][lookups['fueltypes']['oil']]) fuel_in_solid_fuel += np.sum(fuel_disagg['service'][region][enduse][sector][lookups['fueltypes']['solid_fuel']]) fuel_in_biomass += np.sum(fuel_disagg['service'][region][enduse][sector][lookups['fueltypes']['biomass']]) for region in fuel_disagg['industry']: for enduse in fuel_disagg['industry'][region]: for sector in fuel_disagg['industry'][region][enduse]: fuel_in += np.sum(fuel_disagg['industry'][region][enduse][sector]) fuel_in_heat += np.sum(fuel_disagg['industry'][region][enduse][sector][lookups['fueltypes']['heat']]) if mode_constrained == False and enduse in space_heating_enduses: tot_heating += np.sum(fuel_disagg['industry'][region][enduse][sector]) else: fuel_in_elec += np.sum(fuel_disagg['industry'][region][enduse][sector][lookups['fueltypes']['electricity']]) fuel_in_gas += np.sum(fuel_disagg['industry'][region][enduse][sector][lookups['fueltypes']['gas']]) fuel_in_hydrogen += np.sum(fuel_disagg['industry'][region][enduse][sector][lookups['fueltypes']['hydrogen']]) fuel_in_oil += np.sum(fuel_disagg['industry'][region][enduse][sector][lookups['fueltypes']['oil']]) fuel_in_solid_fuel += np.sum(fuel_disagg['industry'][region][enduse][sector][lookups['fueltypes']['solid_fuel']]) fuel_in_biomass += np.sum(fuel_disagg['industry'][region][enduse][sector][lookups['fueltypes']['biomass']]) out_dict = { "fuel_in": fuel_in, "fuel_in_biomass": fuel_in_biomass, "fuel_in_elec": fuel_in_elec, "fuel_in_gas": fuel_in_gas, "fuel_in_heat": fuel_in_heat, "fuel_in_hydrogen": fuel_in_hydrogen, "fuel_in_solid_fuel": fuel_in_solid_fuel, "fuel_in_oil": fuel_in_oil, "tot_heating": tot_heating} return out_dict
data['assumptions'].submodels_names) # -------------------------- # Write out all calculations # -------------------------- if config['CRITERIA']['write_txt_additional_results']: if config['CRITERIA']['crit_plot_enduse_lp']: # Maybe move to result folder in a later step path_folder_lp = os.path.join(data['weather_yr_result_paths']['data_results'], 'individual_enduse_lp') basic_functions.delete_folder(path_folder_lp) basic_functions.create_folder(path_folder_lp) winter_week, _, _, _ = date_prop.get_seasonal_weeks() # Plot electricity fueltype_int_elec = lookup_tables.basic_lookups()['fueltypes']['electricity'] for enduse, ed_yh in sim_obj.tot_fuel_y_enduse_specific_yh.items(): fig_enduse_yh.run( name_fig="individ__electricity_{}_{}".format(enduse, sim_yr), path_result=path_folder_lp, ed_yh=ed_yh[fueltype_int_elec], days_to_plot=winter_week) # ------------------------------------------- # Write annual results to txt files # ------------------------------------------- path_runs = data['weather_yr_result_paths']['data_results_model_runs'] print("... Start writing results to file: " + str(path_runs)) plot_only_selection = True if plot_only_selection:
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_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 post_install_setup(args): """Run this function after installing the energy_demand model with smif and putting the data folder with all necessary data into a local drive. This scripts only needs to be executed once after the energy_demand model has been installed Arguments ---------- args : object Arguments defined in ``./cli/__init__.py`` """ print("... start running initialisation scripts") # Paths path_main = resource_filename(Requirement.parse("energy_demand"), "config_data") path_results = resource_filename(Requirement.parse("energy_demand"), "results") local_data_path = args.local_data # Initialise logger logger_setup.set_up_logger( os.path.join(local_data_path, "logging_post_install_setup.log")) logging.info("... start local energy demand calculations") # Load data base_yr = 2015 data = {} data['paths'] = data_loader.load_paths(path_main) data['local_paths'] = data_loader.load_local_paths(local_data_path) data['result_paths'] = data_loader.load_result_paths(path_results) data['lookups'] = lookup_tables.basic_lookups() data['enduses'], data['sectors'], data['fuels'] = data_loader.load_fuels( data['paths'], data['lookups']) # Assumptions data['assumptions'] = non_param_assumptions.Assumptions( base_yr=base_yr, paths=data['paths'], enduses=data['enduses'], sectors=data['sectors'], fueltypes=data['lookups']['fueltypes'], fueltypes_nr=data['lookups']['fueltypes_nr']) # Delete all previous data from previous model runs basic_functions.del_previous_setup(data['local_paths']['data_processed']) basic_functions.del_previous_setup(data['result_paths']['data_results']) # Create folders and subfolder for data_processed basic_functions.create_folder(data['local_paths']['data_processed']) basic_functions.create_folder(data['local_paths']['path_post_installation_data']) basic_functions.create_folder(data['local_paths']['dir_raw_weather_data']) basic_functions.create_folder(data['local_paths']['dir_changed_weather_station_data']) basic_functions.create_folder(data['local_paths']['load_profiles']) basic_functions.create_folder(data['local_paths']['rs_load_profile_txt']) basic_functions.create_folder(data['local_paths']['ss_load_profile_txt']) basic_functions.create_folder(data['local_paths']['dir_disaggregated']) print("... Read in temperature data from raw files") s_raw_weather_data.run( data['local_paths']) print("... Read in service submodel load profiles") s_ss_raw_shapes.run( data['paths'], data['local_paths'], data['lookups']) print("... Read in residential submodel load profiles") s_rs_raw_shapes.run( data['paths'], data['local_paths'], base_yr) print("... successfully finished setup") return
def read_fuel_ss(path_to_csv, fueltypes_nr): """This function reads in base_data_CSV all fuel types Arguments ---------- path_to_csv : str Path to csv file fueltypes_nr : str Nr of fueltypes Returns ------- fuels : dict Fuels per enduse sectors : list Service sectors enduses : list Service enduses Info of categories ------------------ https://assets.publishing.service.gov.uk/government/uploads/system/uploads/attachment_data/file/565748/BEES_overarching_report_FINAL.pdf """ lookups = lookup_tables.basic_lookups() fueltypes_lu = lookups['fueltypes'] rows_list = [] fuels = {} try: with open(path_to_csv, 'r') as csvfile: rows = csv.reader(csvfile, delimiter=',') headings = next(rows) # Skip row _secondline = next(rows) # Skip row # All sectors sectors = set([]) for sector in _secondline[1:]: #skip fuel ID: sectors.add(sector) # All enduses enduses = set([]) for enduse in headings[1:]: #skip fuel ID: enduses.add(enduse) # Initialise dict for enduse in enduses: fuels[enduse] = {} for sector in sectors: fuels[enduse][sector] = np.zeros((fueltypes_nr), dtype="float") for row in rows: rows_list.append(row) for row in rows_list: fueltype_str = row[0] fueltype_int = fueltypes_lu[fueltype_str] for cnt, entry in enumerate(row[1:], 1): enduse = headings[cnt] sector = _secondline[cnt] fuels[enduse][sector][fueltype_int] += float(entry) except ValueError: raise Exception( "The service sector fuel could not be loaded. Check if empty cells.") return fuels, sorted(sectors), sorted(enduses)
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("===================================")