Esempio n. 1
0
# -------------------------------------------------------------------------------------------------------------------- #
# %% initialize GAMS, GAMS workspace and load model data
# -------------------------------------------------------------------------------------------------------------------- #
# import base data from gdx
ws = GamsWorkspace(system_directory=cfg.GMS_SYS_DIR)
db_input = ws.add_database_from_gdx(
    os.path.join(cfg.MEDEA_ROOT_DIR, 'projects', PROJECT_NAME, 'opt',
                 'medea_main_data.gdx'))

# %% read parameters that change in scenarios (and corresponding sets)
# -------------------------------------------------------------------------------------------------------------------- #
# *** read in all sets over which adjusted parameters are defined ***
dict_r = {rec.keys[0] for rec in db_input['n']}

# *** read in all parameters to be adjusted ***
INITIAL_CAP_G = gdx2df(db_input, 'INITIAL_CAP_G', ['z', 'i'], [])
INITIAL_CAP_R = gdx2df(db_input, 'INITIAL_CAP_R', ['z', 'n'], [])
DEMAND = gdx2df(db_input, 'DEMAND', ['z', 't', 'm'], [])
GEN_PROFILE = gdx2df(db_input, 'GEN_PROFILE', ['z', 't', 'n'], [])

# %% generate 'dynamic' parameter variations (modifications that constitute the scenarios, i.e. that change across runs)
# -------------------------------------------------------------------------------------------------------------------- #
# ensure that we are in the correct model directory
os.chdir(os.path.join(cfg.MEDEA_ROOT_DIR, 'projects', PROJECT_NAME, 'opt'))

# create empty scenario parameter in GAMS database so that it can be modified subsequently
CO2_SCENARIO = df2gdx(db_input, pd.DataFrame(data=[0]), 'CO2_SCENARIO', 'par',
                      0, 'CO2 price scenario')
WIND_ON_LIMIT = df2gdx(db_input, pd.DataFrame(data=[0]), 'WIND_ON_LIMIT',
                       'par', 0, 'max wind_on capacity addition')
PV_CAPEX = df2gdx(db_input, pd.DataFrame(data=[0]), 'PV_CAPEX', 'par', 0,
Esempio n. 2
0
        for wind_limit in dict_camp['wind_on_cap']:
            for price_co2 in dict_camp['carbon_price']:
                for budget_co2 in dict_camp['carbon_limit']:
                    identifier = f'{PROJECT_NAME}_{campaign}_{re_share}_{wind_limit}_{price_co2}_{budget_co2}'
                    FNAME = os.path.join(cfg.MEDEA_ROOT_DIR, 'projects',
                                         PROJECT_NAME, 'opt',
                                         f'medea_out_{identifier}.gdx')

                    db_output = ws.add_database_from_gdx(FNAME)

                    # calculation of air pollution cost
                    # air_pol_cost_by_fuel = gdx2df(db_output, 'cost_air_pol', ['f'], ['z'])

                    df_collect = pd.DataFrame()
                    for symbol, sets in symbols_to_read.items():
                        df = gdx2df(db_output, symbol, sets[0], sets[1])
                        if sets[0]:
                            strix = [f'{symbol}_{ix}' for ix in df.index]
                        else:
                            strix = [symbol]
                        df.index = strix
                        # collect results
                        df_collect = df_collect.append(df, ignore_index=False)

                    df_collect.index = pd.MultiIndex.from_product(
                        [[campaign], [re_share], [wind_limit], [price_co2],
                         [budget_co2], df_collect.index],
                        names=('campaign', 're_share', 'wind_cap',
                               'carb_price', 'carb_limit', 'variable'))
                    # add air pollution cost
                    # df_collect.loc[(campaign, re_share, wind_limit, 'cost_airpol'), :] = air_pol_cost_by_fuel.sum()
Esempio n. 3
0
# -------------------------------------------------------------------------------------------------------------------- #
# *** read in all sets over which adjusted parameters are defined ***
# general example for reading a GAMS set from the gdx-database to a python dictionary:
# dict_set = {rec.keys[0] for rec in db_input['set_name']}
# ---
# read sets for calibration of power plant efficiencies
dict_prd = {rec.keys[0] for rec in db_input['m']}
dict_fuel = {rec.keys[0] for rec in db_input['f']}
dict_tec = {rec.keys[0] for rec in db_input['i']}

# *** read in all parameters to be adjusted ***
# general example for reading parameter 'PARAMETER_NAME' defined over 'set_name' to pandas DataFrame df
# df = gdx2df(db_input, 'PARAMETER_NAME', ['set_name'], [])
# ---
# read power plant efficiency data
df_eff = gdx2df(db_input, 'EFFICIENCY_G', ['i', 'm', 'f'], [])
# read fuel requirement of CHP plants-data
df_fuelreq = gdx2df(db_input, 'FEASIBLE_INPUT', ['i', 'l', 'f'], [])


# %% generate 'static' parameter variations (modifications that remain the same across all scenarios)
# -------------------------------------------------------------------------------------------------------------------- #
# example: calibrate power plant efficiencies -- note: calibration remains the same across all scenarios!
# efficiency -dictionary needs to be imported from settings_{project_name}.py
idx = pd.IndexSlice
fuel_thermal = ['Biomass', 'Coal', 'Gas', 'Lignite', 'Nuclear', 'Oil']

# modify power plant efficiency
df_eff_mod = df_eff.copy()
for fl in fuel_thermal:
    df_eff_mod.loc[idx[:, :, fl], :] = \
Esempio n. 4
0
TS_FILE = os.path.join(cfg.MEDEA_ROOT_DIR, 'data', 'processed',
                       'medea_regional_timeseries.csv')
ts = pd.read_csv(TS_FILE)
ts['DateTime'] = pd.to_datetime(ts['DateTime'])
ts.set_index('DateTime', inplace=True)
# constrain data to scenario year
ts = ts.loc[
    (pd.Timestamp(cfg.year, 1, 1, 0, 0).tz_localize('UTC') <= ts.index)
    & (ts.index <= pd.Timestamp(cfg.year, 12, 31, 23, 0).tz_localize('UTC'))]

# read hourly net imports from gdx output
identifier = f'asparagus_h2stack_30_16_36715'
FNAME = os.path.join('C:/Users', 'Sebastian', 'asparagus_gdx',
                     f'medea_out_{identifier}.gdx')
db_output = ws.add_database_from_gdx(FNAME)
df = gdx2df(db_output, 'x', ['t'], ['z', 'zz'])
df.index = ts.index

nx_at = pd.DataFrame(data=0.0,
                     index=df.index,
                     columns=['X', 'I', 'pv_de', 'wind_at', 'load_at'])
nx_at.loc[df.loc[:, idx['AT', 'DE']] > 0,
          'X'] = df.loc[df.loc[:, idx['AT', 'DE']] > 0, idx['AT', 'DE']]
nx_at.loc[df.loc[:, idx['AT', 'DE']] < 0,
          'I'] = -df.loc[df.loc[:, idx['AT', 'DE']] < 0, idx['AT', 'DE']]
nx_at.index = ts.index

nx_at.loc[:, 'pv_de'] = ts.loc[:, 'DE-pv-profile']
nx_at.loc[:, 'pv_at'] = ts.loc[:, 'AT-pv-profile']
nx_at.loc[:, 'wind_at'] = ts.loc[:, 'AT-wind_on-profile']
nx_at.loc[:, 'load_at'] = ts.loc[:, 'AT-power-load']
Esempio n. 5
0
    dict_camp.update(dict_campaigns[campaign])

    for price_co2 in dict_camp['co2_price']:
        for cap_wind in dict_camp['wind_cap']:
            for pv_cost in dict_camp['pv_cost']:

                identifier = f'{PROJECT_NAME}_{campaign}_{price_co2}_{cap_wind}_{pv_cost}'
                FNAME = os.path.join(cfg.MEDEA_ROOT_DIR, 'projects',
                                     PROJECT_NAME, 'opt',
                                     f'medea_out_{identifier}.gdx')
                # FNAME = os.path.join('C:/Users', 'Sebastian', 'asparagus_gdx', f'medea_out_{identifier}.gdx')

                db_output = ws.add_database_from_gdx(FNAME)

                # calculation of air pollution cost
                air_pol_cost_by_fuel = gdx2df(db_output, 'cost_air_pol', ['f'],
                                              ['z'])

                df_collect = pd.DataFrame()
                for symbol, sets in symbols_to_read.items():
                    df = gdx2df(db_output, symbol, sets[0], sets[1])
                    if sets[0]:
                        strix = [f'{symbol}_{ix}' for ix in df.index]
                    else:
                        strix = [symbol]
                    df.index = strix
                    # collect results
                    df_collect = df_collect.append(df, ignore_index=False)

                df_collect.index = pd.MultiIndex.from_product(
                    [[campaign], [price_co2], [cap_wind], [pv_cost],
                     df_collect.index],