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")
Ejemplo n.º 2
0
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'])
Ejemplo n.º 3
0
def load_data_before_simulation(data, sim_yrs, config, curr_yr):
    # ---------
    # Configuration
    # -----------
    base_yr = config['CONFIG']['base_yr']
    weather_yr_scenario = config['CONFIG']['weather_yr_scenario']
    path_new_scenario = config['PATHS']['path_new_scenario']

    data['data_path'] = os.path.normpath(config['PATHS']['path_local_data'])
    data['processed_path'] = os.path.normpath(
        config['PATHS']['path_processed_data'])
    data['result_path'] = os.path.normpath(config['PATHS']['path_result_data'])
    data['paths'] = config['CONFIG_DATA']

    # Downloaded (FTP) data
    data['local_paths'] = config['DATA_PATHS']

    # ------------------------------------------------
    # Load Inputs
    # ------------------------------------------------
    data['enduses'], data['sectors'], data['fuels'], lookup_enduses, \
        lookup_sector_enduses = data_loader.load_fuels(config['CONFIG_DATA'])

    # ------------------------------------------------
    # Load Assumptions
    # ------------------------------------------------
    data['assumptions'] = general_assumptions.Assumptions(
        lookup_enduses=lookup_enduses,
        lookup_sector_enduses=lookup_sector_enduses,
        base_yr=base_yr,
        weather_by=config['CONFIG']['user_defined_weather_by'],
        simulation_end_yr=config['CONFIG']['user_defined_simulation_end_yr'],
        curr_yr=curr_yr,
        sim_yrs=sim_yrs,
        paths=config['CONFIG_DATA'],
        enduses=data['enduses'],
        sectors=data['sectors'],
        reg_nrs=len(data['regions']))

    # ------------------------------------------
    # Make selection of regions to model
    # ------------------------------------------
    if config['CRITERIA']['reg_selection']:

        region_selection = read_data.get_region_selection(
            os.path.join(config['DATA_PATHS']['local_path_datafolder'],
                         "region_definitions",
                         config['CRITERIA']['reg_selection_csv_name']))
        #region_selection = ['E02003237', 'E02003238']
        setattr(data['assumptions'], 'reg_nrs', len(region_selection))
    else:
        region_selection = data['regions']

    # Create .ini file with simulation parameter
    write_data.write_simulation_inifile(path_new_scenario, data,
                                        region_selection)

    # -------------------------------------------
    # Weather year specific initialisations
    # -------------------------------------------
    path_folder_weather_yr = os.path.join(
        os.path.join(path_new_scenario,
                     str(weather_yr_scenario) + "__" + "all_stations"))

    data['weather_result_paths'] = basic_functions.get_result_paths(
        path_folder_weather_yr)

    folders_to_create = [
        path_folder_weather_yr, data['weather_result_paths']['data_results'],
        data['weather_result_paths']['data_results_PDF'],
        data['weather_result_paths']['data_results_validation'],
        data['weather_result_paths']['data_results_model_run_results_txt']
    ]
    for folder in folders_to_create:
        basic_functions.create_folder(folder)

    # ------------------------------------------------
    # Load load profiles of technologies
    # ------------------------------------------------
    data['tech_lp'] = data_loader.load_data_profiles(
        config['CONFIG_DATA'], config['DATA_PATHS'],
        data['assumptions'].model_yeardays,
        data['assumptions'].model_yeardays_daytype)

    # Obtain population data for disaggregation
    if config['CRITERIA']['msoa_crit']:
        name_population_dataset = config['DATA_PATHS'][
            'path_population_data_for_disaggregation_msoa']
    else:
        name_population_dataset = config['DATA_PATHS'][
            'path_population_data_for_disaggregation_lad']

    data['pop_for_disag'] = data_loader.read_scenario_data(
        name_population_dataset, region_name='region', value_name='value')

    # ------------------------------------------------
    # Load building related data
    # ------------------------------------------------
    if config['CRITERIA']['virtual_building_stock_criteria']:
        data['scenario_data']['floor_area']['rs_floorarea'], data[
            'scenario_data']['floor_area']['ss_floorarea'], data[
                'service_building_count'], rs_regions_without_floorarea, ss_regions_without_floorarea = data_loader.floor_area_virtual_dw(
                    data['regions'],
                    data['sectors'],
                    config['DATA_PATHS'],
                    data['scenario_data']['population'][
                        data['assumptions'].base_yr],
                    base_yr=data['assumptions'].base_yr)

        # Add all areas with no floor area data
        data['assumptions'].update("rs_regions_without_floorarea",
                                   rs_regions_without_floorarea)
        data['assumptions'].update("ss_regions_without_floorarea",
                                   ss_regions_without_floorarea)
    else:
        # ------------------------------------------------
        # Load floor area directly from scenario
        # ------------------------------------------------
        data['scenario_data']['floor_area']['rs_floorarea'] = {}
        data['scenario_data']['floor_area']['rs_floorarea'] = data[
            'scenario_data']['rs_floorarea']
        data['scenario_data']['floor_area']['ss_floorarea'] = data[
            'scenario_data']['ss_floorarea']
        data['scenario_data']['service_building_count'][
            data['assumptions'].base_yr] = {}

    return data
Ejemplo n.º 4
0
    data['regions'] = read_data.get_region_names(name_region_set)
    data['reg_coord'] = basic_functions.get_long_lat_decimal_degrees(read_data.get_region_centroids(name_region_set))

    data['scenario_data']['population'] = data_loader.read_scenario_data(name_population_dataset)
    data['scenario_data']['gva_industry'] = data_loader.read_scenario_data_gva(name_gva_dataset, all_dummy_data=False)
    data['scenario_data']['gva_per_head'] = data_loader.read_scenario_data(name_gva_dataset_per_head)

    # -----------------------------
    # Assumptions
    # -----------------------------
    data['assumptions'] = general_assumptions.Assumptions(
        lookup_enduses=lookup_enduses,
        lookup_sector_enduses=lookup_sector_enduses,
        base_yr=config['CONFIG']['base_yr'],
        weather_by=config['CONFIG']['user_defined_weather_by'],
        simulation_end_yr=config['CONFIG']['user_defined_simulation_end_yr'],
        curr_yr=2015,
        sim_yrs=sim_yrs,
        paths=data['paths'],
        enduses=data['enduses'],
        sectors=data['sectors'],
        reg_nrs=len(data['regions']))

    # -----------------------------------------------------------------------------
    # Calculate population density for base year
    # -----------------------------------------------------------------------------
    region_objects = read_data.get_region_objects(name_region_set)
    data['pop_density'] = {}
    for region in region_objects:
        region_name = region['properties']['name']
        region_area = region['properties']['st_areasha']
        data['pop_density'][region_name] = data['scenario_data']['population'][data['assumptions'].base_yr][region_name] / region_area
Ejemplo n.º 5
0
config.read(os.path.join(path_config, 'wrapperconfig.ini'))

# --------
# Other configuration
# --------
base_yr = 2015
sim_yrs = [2015, 2050]

paths = data_loader.load_paths(path_main)
data_path = os.path.normpath(config['PATHS']['path_local_data'])

local_paths = data_loader.get_local_paths(data_path)

data = {}

data['enduses'], data['sectors'], data['fuels'] = data_loader.load_fuels(paths)

assumptions = general_assumptions.Assumptions(base_yr=user_defined_base_yr,
                                              curr_yr=2015,
                                              sim_yrs=sim_yrs,
                                              paths=paths,
                                              enduses=data['enduses'],
                                              sectors=data['sectors'])

# Write parameters to YAML file
_, _ = strategy_vars_def.load_param_assump(assumptions)

print("==========")
print("Finishged generating YAML file with scenario parameters")
print("==========")
Ejemplo n.º 6
0
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", flush=True)

    path_config_file = args.local_data

    config = data_loader.read_config_file(path_config_file)
    local_data_path = config['PATHS']['path_local_data']

    path_results = resource_filename(Requirement.parse("energy_demand"),
                                     "results")
    local_data_path = args.local_data

    path_config = config['PATHS']['path_energy_demand_config']
    base_yr = config['CONFIG']['base_yr']

    data = {}
    data['paths'] = config['CONFIG_DATA']
    data['local_paths'] = config['DATA_PATHS']
    data['result_paths'] = config['RESULT_DATA']
    data['lookups'] = lookup_tables.basic_lookups()
    data['enduses'], data['sectors'], data['fuels'], lookup_enduses, \
        lookup_sector_enduses = data_loader.load_fuels(data['paths'])

    data['assumptions'] = general_assumptions.Assumptions(
        lookup_enduses=lookup_enduses,
        lookup_sector_enduses=lookup_sector_enduses,
        base_yr=base_yr,
        paths=data['paths'],
        enduses=data['enduses'],
        sectors=data['sectors'])

    # 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'])
    basic_functions.del_previous_setup(
        data['local_paths']['path_post_installation_data'])

    # Create folders and subfolder for data_processed
    folders_to_create = [
        data['local_paths']['data_processed'],
        data['local_paths']['path_post_installation_data'],
        data['local_paths']['load_profiles'],
        data['local_paths']['rs_load_profile_txt'],
        data['local_paths']['ss_load_profile_txt']
    ]

    for folder in folders_to_create:
        basic_functions.create_folder(folder)

    print("... Read in residential submodel load profiles", flush=True)
    s_rs_raw_shapes.run(data['paths'], data['local_paths'], base_yr)

    print("... Read in service submodel load profiles", flush=True)
    s_ss_raw_shapes.run(data['paths'], data['local_paths'], data['lookups'])

    # Input data preparation
    print("Generate additional data", flush=True)

    # Extract NISMOD population data
    path_to_zip_file = os.path.join(
        local_data_path, "population-economic-smif-csv-from-nismod-db.zip")
    path_extraction = os.path.join(local_data_path, 'scenarios',
                                   "MISTRAL_pop_gva")
    zip_ref = zipfile.ZipFile(path_to_zip_file, 'r')
    zip_ref.extractall(path_extraction)
    zip_ref.close()

    # Complete gva and pop data for every sector
    data_pop = os.path.join(local_data_path, "scenarios", "MISTRAL_pop_gva",
                            "data")
    path_geography = os.path.join(
        local_data_path, "scenarios",
        "uk_pop_principal_2015_2050_MSOA_england.csv")
    geography_name = "region"  # "lad_uk_2016"

    script_data_preparation_MISTRAL_pop_gva.run(
        path_to_folder=data_pop,
        path_MSOA_baseline=path_geography,
        MSOA_calculations=False,
        geography_name="region")  # "lad_uk_2016"

    print("... successfully finished setup")
    return