Esempio n. 1
0
def plot():

    dirs = get_experiment_dirs('all_scenarios')

    price_el = pd.read_csv(os.path.join(dirs['raw'],
                                        'price_electricity_spot_2017.csv'),
                           index_col=0)

    price_el.columns = ['electricity']

    plot_load_duration(
        price_el,
        legend=False,
        plot_original=True,
        title='Electricity spot price',
        ylabel='Hourly price [Eur/MWh]',
    )

    filename = os.path.join(dirs['plots'], 'price_el.pdf')

    plt.savefig(filename)

    plt.close()

    print(f"Saved plot to {filename}")
Esempio n. 2
0
def plot():

    dirs = get_experiment_dirs('all_scenarios')

    demand_heat = pd.read_csv(
        os.path.join(dirs['raw'], 'demand_heat_2017.csv'),
        index_col=0
    ).sum(1)

    demand_heat.name = 'heat-demand'

    plot_load_duration(
        demand_heat,
        legend=False,
        plot_original=True,
        title='Heat demand',
        ylabel='Hourly heat demand [MWh]',
    )

    filename = os.path.join(dirs['plots'], 'heat_demand.pdf')

    plt.savefig(filename)

    plt.close()

    print(f"Saved plot to {filename}")
Esempio n. 3
0
def main(**scenario_assumptions):
    logging.info('Optimisation')

    dirs = get_experiment_dirs(scenario_assumptions['scenario'])

    optimize(dirs['preprocessed'],
             dirs['optimised'],
             debug=scenario_assumptions['debug'])
Esempio n. 4
0
def get_scenario_paths(scenario_assumptions):
    scenario_paths = {}

    for scenario in scenario_assumptions['scenario']:
        path = get_experiment_dirs(scenario)['postprocessed']

        scenario_paths.update({scenario: path})

    return scenario_paths
def main(**scenario_assumptions):
    print('Postprocessing')
    dirs = get_experiment_dirs(scenario_assumptions['scenario'])

    subdir = os.path.join(dirs['postprocessed'], 'sequences')
    if not os.path.exists(subdir):
        os.mkdir(subdir)

    # restore EnergySystem with results
    es = EnergySystem()
    es.restore(dirs['optimised'])

    sequences = write_results(es, dirs['postprocessed'])

    capacities = get_capacities(es)

    capacities = cap_el_to_cap_th(capacities)

    capacity_cost = get_capacity_cost(es)

    carrier_cost = get_carrier_cost(es)

    marginal_cost = get_marginal_cost(es)

    yearly_electricity = get_yearly_sum(sequences['electricity'], var_name='yearly_electricity')

    heat_sequences = pd.concat([sequences['heat_central'], sequences['heat_decentral']], 1)
    yearly_heat = get_yearly_sum(heat_sequences, var_name='yearly_heat')

    # full_load_hours = get_flh(capacities, yearly_sum)

    share_el_heat = get_share_el_heat(yearly_heat)

    spec_cost_of_heat = get_spec_cost_of_heat(yearly_heat, capacity_cost, carrier_cost, marginal_cost)

    scalars = pd.concat(
        [capacities, yearly_electricity, yearly_heat, capacity_cost, carrier_cost, marginal_cost,
         share_el_heat, spec_cost_of_heat], 0)

    # some of the rows carry the component classes as index. This maps all index labels to str.
    scalars = multi_index_dtype_to_str(scalars)

    scalars.sort_values(by=['name', 'var_name', 'type', 'carrier', 'tech'], inplace=True)

    scalars.to_csv(os.path.join(dirs['postprocessed'], 'scalars.csv'))
Esempio n. 6
0
def main(scenario_assumptions):
    print("Combining scenario results")

    dirs = get_experiment_dirs('all_scenarios')

    scenario_paths = get_scenario_paths(scenario_assumptions)

    scenario_dfs = get_scenario_dfs(scenario_paths, 'scalars.csv')

    all_scalars = combine_scalars(scenario_dfs)

    all_scalars.drop('heat-distribution', level='name', inplace=True)

    all_scalars.drop('heat-demand', level='name', inplace=True)

    all_scalars.drop('heat_decentral-shortage', level='name', inplace=True)

    file_path = os.path.join(dirs['postprocessed'], 'scalars.csv')

    all_scalars.to_csv(file_path)

    print(f"Saved scenario results to {file_path}")
Esempio n. 7
0
import os

import pandas as pd

from tools.helper import get_experiment_dirs, get_scenario_assumptions


dirs =get_experiment_dirs('all_scenarios')

input_file_path = os.path.join(dirs['postprocessed'], 'scalars.csv')

all_scalars = pd.read_csv(input_file_path)


def filter_and_round(df, filter, scenario_select, decimals):
    _df = df.copy()

    _df = _df.loc[all_scalars['var_name'] == filter]

    _df = _df[['scenario', 'var_value']].set_index('scenario')

    _df = _df.loc[scenario_select, :]

    _df = _df.round(decimals)

    return _df


def filter_assumptions(scenario_assumptions, scenario_select, assumption_select):
    assumptions = scenario_assumptions.loc[
        scenario_assumptions['scenario'].isin(scenario_select)]
Esempio n. 8
0
def plot():

    dirs = get_experiment_dirs('all_scenarios')

    scenarios = {
        'Status quo': [
            'SQ',
            'SQ-CHP',
            'SQ-HP-50',
            'SQ-HP-50-COP-175',
            'SQ-HP-50-COP-200',
            'SQ-Std-200',
         ],
        'Transition to FF': [
            'FF-50',
            'FF-70',
            'FF-80',
            'FF-90',
        ],
        'FF': [
            'FF',
            'FF-COP-75',
            'FF-Mean-150',
            'FF-Std-150',
            'FF-Mean-150-Std-150',
        ],
    }

    all_scalars = pd.read_csv(
        os.path.join(dirs['postprocessed'], 'scalars.csv'),
        index_col=[0,1,2,3,4,5]
    )

    remove_scenario_index_name(all_scalars)

    fig, axs = plt.subplots(1, 3, figsize=(12, 6), sharey=True)

    legend = False

    for i, (title, scenario_bunch) in enumerate(scenarios.items()):

        slicing = idx[scenario_bunch, :, :, :, :, ['capacity', 'invest']]

        select = all_scalars.loc[slicing, :]

        if i == 2:
            legend=True

        plot_stacked_bar(
            select,
            scenario_bunch,
            title,
            'Capacity in MW',
            ax=axs[i],
            legend=legend,
            yticks=np.arange(0, 300, 50),
        )

    filename = os.path.join(dirs['plots'], 'capacities.pdf')

    plt.tight_layout()

    plt.savefig(filename)

    print(f"Saved plot to {filename}")
Esempio n. 9
0
def main(**scenario_assumptions):
    dirs = get_experiment_dirs(scenario_assumptions['scenario'])

    price_el = pd.read_csv(os.path.join(dirs['preprocessed'], 'data',
                                        'sequences',
                                        'carrier_cost_profile.csv'),
                           index_col=0)

    electricity = pd.read_csv(
        os.path.join(dirs['postprocessed'], 'sequences', 'electricity.csv'),
        index_col=0,
    )

    heat_central = pd.read_csv(os.path.join(dirs['postprocessed'], 'sequences',
                                            'heat_central.csv'),
                               index_col=0)

    heat_decentral = pd.read_csv(os.path.join(dirs['postprocessed'],
                                              'sequences',
                                              'heat_decentral.csv'),
                                 index_col=0)

    timeseries = pd.concat([heat_central, heat_decentral], 1)

    timeseries = timeseries.drop('heat-distribution', axis=1)

    timeseries = timeseries.drop('heat_decentral-shortage', axis=1)

    supply = timeseries.drop('heat-demand', axis=1)

    demand = timeseries['heat-demand']

    plot_load_duration(
        price_el,
        legend=False,
        plot_original=True,
        title='Electricity prices (buying)',
        ylabel='Hourly price [Eur/MWh]',
    )
    plt.savefig(os.path.join(dirs['plots'], 'price_el.pdf'))
    plt.close()

    plot_load_duration(
        demand,
        legend=False,
        plot_original=True,
        title='Heat demand',
        ylabel='Hourly heat demand [MWh]',
    )
    plt.savefig(os.path.join(dirs['plots'], 'heat_demand.pdf'))
    plt.close()

    plot_load_duration(
        supply,
        linewidth=10,
    )
    plt.savefig(os.path.join(dirs['plots'], 'heat_supply.pdf'))
    plt.close()

    start = '2017-02-01'
    end = '2017-02-14'

    plot_dispatch(supply[start:end], demand[start:end],
                  os.path.join(dirs['plots'], 'heat_dispatch.pdf'))

    winter_a = '2017-01-10'
    winter_b = '2017-01-24'
    summer_a = '2017-06-01'
    summer_b = '2017-06-14'

    electricity_chp = pd.DataFrame(electricity['gas-chp'])

    multiplot_dispatch((supply[winter_a:winter_b], supply[summer_a:summer_b]),
                       (electricity_chp[winter_a:winter_b],
                        electricity_chp[summer_a:summer_b]),
                       os.path.join(dirs['plots'], 'heat_el_dispatch.pdf'))
Esempio n. 10
0
def plot():

    dirs = get_experiment_dirs('all_scenarios')

    scenarios = {
        'Status quo': [
            'SQ',
            'SQ-CHP',
            'SQ-HP-50',
            'SQ-HP-50-COP-175',
            'SQ-HP-50-COP-200',
            'SQ-Std-200',
        ],
        'Transition to FF': [
            'FF-50',
            'FF-70',
            'FF-80',
            'FF-90',
        ],
        'FF': [
            'FF',
            'FF-COP-75',
            'FF-Mean-150',
            'FF-Std-150',
            'FF-Mean-150-Std-150',
        ],
    }

    all_scalars = pd.read_csv(os.path.join(dirs['postprocessed'],
                                           'scalars.csv'),
                              index_col=[0, 1, 2, 3, 4, 5])

    fig, axs = plt.subplots(1, 3, figsize=(12, 6), sharey=True)

    legend = False

    for i, (title, scenario_bunch) in enumerate(scenarios.items()):

        slicing = idx[scenario_bunch, :, :, :, :,
                      ['capacity_cost', 'carrier_cost', 'marginal_cost']]

        select = all_scalars.loc[slicing, :]

        # select = group_varom_cost(select)

        remove_scenario_index_name(select)

        select = select / 300000  #TODO: Find a better solution than this fix.

        if i == 2:
            legend = True

        plot_stacked_bar(
            select,
            scenario_bunch,
            title,
            ax=axs[i],
            legend=legend,
            yticks=np.arange(-100, 120, 20),
        )

        axs[i].set_ylim(-90, 100)

    filename = os.path.join(dirs['plots'], 'costs.pdf')

    axs[0].set_ylabel('Cost of heat in Eur/MWh')

    plt.tight_layout()

    plt.savefig(filename)

    print(f"Saved plot to {filename}")
Esempio n. 11
0
def main(**scenario_assumptions):
    print('Preprocessing')

    timeindex = TIMEINDEX
    if scenario_assumptions['debug']:
        timeindex = timeindex[:3]

    dirs = get_experiment_dirs(scenario_assumptions['scenario'])
    elements_dir = os.path.join(dirs['preprocessed'], 'data', 'elements')

    copy_base_scenario(os.path.join(dirs['raw'], 'base_scenario'),
                       os.path.join(dirs['preprocessed']))

    sequences_dir = os.path.join(dirs['preprocessed'], 'data', 'sequences')
    if not os.path.exists(sequences_dir):
        os.makedirs(sequences_dir)

    gas_price = scenario_assumptions['market_price_gas']\
                + scenario_assumptions['charges_tax_levies_gas']

    set_gas_price(gas_price, elements_dir)

    constants = get_constants(dirs['raw'])

    params = constants.copy()

    params.loc[
        'electricity-hp',
        'overnight_cost'] = scenario_assumptions['overnight_cost_heat_pump']

    fix_cost_data = calculate_fix_cost(params)

    set_element_params(
        elements_dir,
        'electricity-hp',
        capacity_cost=fix_cost_data.loc['electricity-hp', 'ep_cost'],
        efficiency=scenario_assumptions['cop_heat_pump'],
    )

    set_element_params(elements_dir,
                       'electricity-respth',
                       capacity_cost=fix_cost_data.loc['electricity-respth',
                                                       'ep_cost'])

    set_element_params(elements_dir,
                       'heat-storage',
                       storage_capacity_cost=list(fix_cost_data.loc[
                           ['heat_central-storage', 'heat_decentral-storage'],
                           'ep_cost']))

    prepare_heat_demand_profile(os.path.join(dirs['raw'],
                                             'demand_heat_2017.csv'),
                                os.path.join(dirs['preprocessed'], 'data',
                                             'sequences'),
                                timeindex=timeindex)

    prepare_electricity_price_profiles(
        scenario_assumptions['market_price_el'],
        scenario_assumptions['charges_tax_levies_el'],
        scenario_assumptions['standard_dev_el'],
        scenario_assumptions['chp_surcharge'],
        os.path.join(dirs['raw'], 'price_electricity_spot_2017.csv'),
        os.path.join(dirs['preprocessed'], 'data', 'sequences'),
        timeindex=timeindex)

    infer_metadata('name', dirs['preprocessed'])